     1                                  ; ****************************************************************************
     2                                  ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.9
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; Last Update: 29/12/2024 (Previous: 23/06/2024)
     5                                  ; ----------------------------------------------------------------------------
     6                                  ; Beginning: 04/01/2016
     7                                  ; ----------------------------------------------------------------------------
     8                                  ; Assembler: NASM version 2.15 (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                                  KLOAD	equ 10000h ; Kernel loading address
    24                                  	; NOTE: Retro UNIX 8086 v1 boot code loads kernel at 1000h:0000h 
    25                                  KCODE	equ 08h	; Code segment descriptor (ring 0)
    26                                  KDATA	equ 10h	; Data segment descriptor (ring 0)
    27                                  ; 19/03/2015
    28                                  UCODE	equ 1Bh ; 18h + 3h  (ring 3)
    29                                  UDATA	equ 23h ; 20h + 3h  (ring 3)
    30                                  ; 24/03/2015
    31                                  TSS	equ 28h	; Task state segment descriptor (ring 0)
    32                                  ; 19/03/2015
    33                                  CORE	equ 400000h  ; Start of USER's virtual/linear address space 
    34                                  		     ; (at the end of the 1st 4MB)
    35                                  ECORE	equ 0FFC00000h ; End of USER's virtual address space (4GB - 4MB)
    36                                  		     ; ULIMIT = (ECORE/4096) - 1 = 0FFBFFh (in GDT)
    37                                  ;; 27/12/2013
    38                                  ;KEND	equ KLOAD + 65536 ; (28/12/2013) (end of kernel space)
    39                                  ; 04/07/2016
    40                                  KEND    equ KERNELFSIZE + KLOAD
    41                                  
    42                                  ; IBM PC/AT BIOS ----- 10/06/85 (postequ.inc)
    43                                  ;--------- CMOS TABLE LOCATION ADDRESS'S -------------------------------------
    44                                  CMOS_SECONDS	EQU	00H		; SECONDS (BCD)
    45                                  CMOS_SEC_ALARM	EQU	01H		; SECONDS ALARM (BCD)
    46                                  CMOS_MINUTES	EQU	02H		; MINUTES (BCD)
    47                                  CMOS_MIN_ALARM	EQU	03H		; MINUTES ALARM (BCD) 	
    48                                  CMOS_HOURS	EQU	04H		; HOURS (BCD
    49                                  CMOS_HR_ALARM	EQU	05H		; HOURS ALARM   (BCD)
    50                                  CMOS_DAY_WEEK	EQU	06H		; DAY OF THE WEEK  (BCD)
    51                                  CMOS_DAY_MONTH	EQU	07H		; DAY OF THE MONTH (BCD) 
    52                                  CMOS_MONTH	EQU	08H		; MONTH (BCD)
    53                                  CMOS_YEAR	EQU	09H		; YEAR (TWO DIGITS) (BCD)
    54                                  CMOS_CENTURY	EQU	32H		; DATE CENTURY BYTE (BCD)
    55                                  CMOS_REG_A	EQU	0AH		; STATUS REGISTER A
    56                                  CMOS_REG_B	EQU	0BH		; STATUS REGISTER B  ALARM
    57                                  CMOS_REG_C	EQU	0CH		; STATUS REGISTER C  FLAGS
    58                                  CMOS_REG_D	EQU	0DH		; STATUS REGISTER D  BATTERY
    59                                  CMOS_SHUT_DOWN	EQU	0FH		; SHUTDOWN STATUS COMMAND BYTE
    60                                  ;----------------------------------------
    61                                  ;	CMOS EQUATES FOR THIS SYSTEM	;
    62                                  ;-----------------------------------------------------------------------------
    63                                  CMOS_PORT	EQU	070H		; I/O ADDRESS OF CMOS ADDRESS PORT
    64                                  CMOS_DATA	EQU	071H		; I/O ADDRESS OF CMOS DATA PORT
    65                                  NMI		EQU	10000000B	; DISABLE NMI INTERRUPTS MASK -
    66                                  					; HIGH BIT OF CMOS LOCATION ADDRESS
    67                                  
    68                                  ; Memory Allocation Table Address
    69                                  ; 05/11/2014
    70                                  ; 31/10/2014
    71                                  MEM_ALLOC_TBL	equ	100000h		; Memory Allocation Table at the end of
    72                                  					; the 1st 1 MB memory space.
    73                                  					; (This address must be aligned
    74                                  					;  on 128 KB boundary, if it will be
    75                                  					;  changed later.)
    76                                  					; ((lower 17 bits of 32 bit M.A.T.
    77                                  					;   address must be ZERO)).
    78                                  					; ((((Reason: 32 bit allocation 
    79                                  					;     instructions, dword steps)))
    80                                  					; (((byte >> 12 --> page >> 5)))  
    81                                  ;04/11/2014	
    82                                  PDE_A_PRESENT	equ	1		; Present flag for PDE
    83                                  PDE_A_WRITE	equ 	2		; Writable (write permission) flag
    84                                  PDE_A_USER	equ	4		; User (non-system/kernel) page flag
    85                                  ;
    86                                  PTE_A_PRESENT	equ	1		; Present flag for PTE (bit 0)
    87                                  PTE_A_WRITE	equ 	2		; Writable (write permission) flag (bit 1)
    88                                  PTE_A_USER	equ	4		; User (non-system/kernel) page flag (bit 2)
    89                                  PTE_A_ACCESS    equ	32		; Accessed flag (bit 5) ; 09/03/2015
    90                                  
    91                                  ; 17/02/2015 (unix386.s)
    92                                  ; 10/12/2014 - 30/12/2014 (0B000h -> 9000h) (dsectrm2.s)
    93                                  DPT_SEGM equ 09000h  ; FDPT segment (EDD v1.1, EDD v3)
    94                                  ;
    95                                  HD0_DPT	 equ 0	    ; Disk parameter table address for hd0
    96                                  HD1_DPT	 equ 32	    ; Disk parameter table address for hd1
    97                                  HD2_DPT	 equ 64	    ; Disk parameter table address for hd2
    98                                  HD3_DPT	 equ 96	    ; Disk parameter table address for hd3
    99                                  
   100                                  ; 15/11/2020
   101                                  VBE3INFOSEG equ 97E0h ; 512 bytes before Video_Pg_Backup
   102                                  ; 15/12/2020
   103                                  VBE3MODEINFOSEG equ 97C0h ; 512 bytes before VBE3INFOBLOCK 
   104                                  
   105                                  ; 29/11/2020
   106                                  VBE3INFOBLOCK equ 97E00h ; linear address (512 bytes)
   107                                  VBE3MODEINFOBLOCK equ 97C00h ; linear address (256 bytes)
   108                                  VBE3SAVERESTOREBLOCK equ 97600h ; linear address (2048 bytes)
   109                                  VBE3CRTCINFOBLOCK equ 97D80h ; linear address (64 bytes) ; 17/01/2021 
   110                                  VBE3BIOSDATABLOCK equ 97000h ; linear address (1536 bytes)
   111                                  VBE3STACKADDR equ 96000h ; linear address (1024 bytes)
   112                                  ; VBE3 32 bit Protected Mode Interface (16 bit) Selectors (in GDT)
   113                                  VBE3CS equ 30h ; _vbe3_CS:
   114                                  VBE3BDS equ 38h ; _vbe3_BDS:
   115                                  VBE3A000 equ 40h ; _A0000Sel:
   116                                  VBE3B000 equ 48h ; _B0000Sel:
   117                                  VBE3B800 equ 50h ; _B8000Sel:
   118                                  VBE3DS equ 58h ; _vbe3_DS:
   119                                  VBE3SS equ 60h ; _vbe3_SS:
   120                                  VBE3ES equ 68h ; _vbe3_ES:
   121                                  KCODE16 equ 70h ; _16bit_CS:
   122                                  ; 14/01/2021
   123                                  ; 06/12/2020
   124                                  VBE3VIDEOSTATE equ 95800h ; 2048 bytes
   125                                  ; 05/01/2021
   126                                  VGAFONT16USER equ 94000h ; 8x16 pixels user font (256 chars)	
   127                                  			 ; (reserved/allocated font space: 4096 bytes) 
   128                                  
   129                                  VGAFONT8USER equ 95000h	; 8x8 pixels user font (256 chars)	
   130                                  			; (reserved/allocated font space: 2048 bytes)
   131                                  ; 17/01/2021
   132                                  ; temporary (initial) location for EDID information
   133                                  VBE3EDIDINFOBLOCK equ 97D00h ; linear address (128 bytes)
   134                                   
   135                                  ; FDPT (Phoenix, Enhanced Disk Drive Specification v1.1, v3.0)
   136                                  ;      (HDPT: Programmer's Guide to the AMIBIOS, 1993)
   137                                  ;
   138                                  FDPT_CYLS	equ 0 ; 1 word, number of cylinders
   139                                  FDPT_HDS	equ 2 ; 1 byte, number of heads
   140                                  FDPT_TT		equ 3 ; 1 byte, A0h = translated FDPT with logical values
   141                                  		      ; otherwise it is standard FDPT with physical values 	
   142                                  FDPT_PCMP	equ 5 ; 1 word, starting write precompensation cylinder
   143                                  		      ; (obsolete for IDE/ATA drives)
   144                                  FDPT_CB		equ 8 ; 1 byte, drive control byte
   145                                  			; Bits 7-6 : Enable or disable retries (00h = enable)
   146                                  			; Bit 5	: 1 = Defect map is located at last cyl. + 1
   147                                  			; Bit 4 : Reserved. Always 0
   148                                  			; Bit 3 : Set to 1 if more than 8 heads
   149                                  			; Bit 2-0 : Reserved. Always 0
   150                                  FDPT_LZ		equ 12 ; 1 word, landing zone (obsolete for IDE/ATA drives)
   151                                  FDPT_SPT	equ 14 ; 1 byte, sectors per track
   152                                  
   153                                  ; Floppy Drive Parameters Table (Programmer's Guide to the AMIBIOS, 1993)
   154                                  ; (11 bytes long) will be used by diskette handler/bios
   155                                  ; which is derived from IBM PC-AT BIOS (DISKETTE.ASM, 21/04/1986).
   156                                  
   157                                  ; 01/02/2016
   158                                  Logical_DOSDisks equ 90000h + 100h ; 26*256 = 6656 bytes
   159                                  Directory_Buffer equ 80000h ; max = 64K Bytes
   160                                  FAT_Buffer	 equ 91C00h ; 1536 bytes (3 sectors)
   161                                  ; 15/02/2016
   162                                  Cluster_Buffer	 equ 70000h ; max = 64K Bytes ; buffer for file read & write
   163                                  ; 11/04/2016
   164                                  Env_Page:	 equ 93000h ; 512 bytes (4096 bytes)
   165                                  Env_Page_Size	 equ 512    ; (4096 bytes)
   166                                  ; 30/07/2016
   167                                  Video_Pg_Backup	 equ 98000h ; Mode 3h, video page backup (32K, 8 pages)
   168                                  
   169                                  ; 29/11/2020
   170                                  ; Free/Reserved memory blocks (in 1st 1MB): 93200h to 96000h (available)
   171                                  ; 06/12/2020
   172                                  ; Free/Reserved memory blocks (in 1st 1MB): 93200h to 95800h (available)
   173                                  
   174                                  ; 15/12/2020
   175                                  LFB_ADDR	equ LFB_Info+LFBINFO.LFB_addr
   176                                  LFB_SIZE	equ LFB_Info+LFBINFO.LFB_size
   177                                  
   178                                  ; 04/12/2023 - TRDOS 386 v2.0.7
   179                                  SYSTEMSTACK_ADDR  equ 97000h	; max. 3072 bytes (96400h-97000h)
   180                                  VBE3BIOSCODE_ADDR equ 60000h	; Protected Mode Video Bios (64KB)
   181                                  ;AC97DMABUFFR_ADDR equ 40000h	; AC97 & VIA VT8233 DMA Buffer (128KB)
   182                                  SB16DMABUFFR_ADDR equ 50000h	; Sound Blaster 16 DMA Buffer (64KB)
   183                                  sb16_dma_buffer equ SB16DMABUFFR_ADDR
   184                                  
   185                                  ; 29/08/2023 - TRDOS 386 v2.0.6
   186                                  	; 30/11/2020
   187                                  	; 29/11/2020 - TRDOS 386 v2.0.3
   188                                  
   189                                  struc PMInfo  ;  VESA VBE3 PMInfoBlock ('PMID' block)
   190                                  
   191 00000000 ????????                 .Signature:	resb 4  ; db 'PMID' ; PM Info Block Signature
   192 00000004 ????                     .EntryPoint:	resw 1	; Offset of PM entry point within BIOS
   193 00000006 ????                     .PMInitialize: resw 1	; Offset of PM initialization entry point
   194 00000008 ????                     .BIOSDataSel:	resw 1 	; Selector to BIOS data area emulation block
   195 0000000A ????                     .A0000Sel:	resw 1	; Selector to access A0000h physical mem
   196 0000000C ????                     .B0000Sel:	resw 1  ; Selector to access B0000h physical mem
   197 0000000E ????                     .B8000Sel:	resw 1	; Selector to access B8000h physical mem
   198 00000010 ????                     .CodeSegSel:	resw 1	; Selector to access code segment as data
   199 00000012 ??                       .InProtectMode: resb 1 ; Set to 1 when in protected mode
   200 00000013 ??                       .Checksum:	resb 1	; Checksum byte for structure
   201                                   .size:
   202                                  
   203                                  endstruc
   204                                   
   205                                  [BITS 16]       ; We need 16-bit intructions for Real mode
   206                                  
   207                                  [ORG 0] 
   208                                  	; 12/11/2014
   209                                  	; Save boot drive number (that is default root drive)
   210 00000000 8816[3866]              	mov	[boot_drv], dl ; physical drv number
   211                                  
   212                                  	; Determine installed memory
   213                                  	; 31/10/2014
   214                                  	;
   215 00000004 B801E8                  	mov	ax, 0E801h ; Get memory size 
   216 00000007 CD15                    	int	15h	   ; for large configurations
   217 00000009 7308                    	jnc	short chk_ms
   218 0000000B B488                    	mov	ah, 88h    ; Get extended memory size 
   219 0000000D CD15                    	int	15h
   220                                  	;	   
   221                                  	;mov	al, 17h	; Extended memory (1K blocks) low byte
   222                                  	;out	70h, al ; select CMOS register
   223                                  	;in	al, 71h ; read data (1 byte)
   224                                  	;mov	cl, al
   225                                  	;mov	al, 18h ; Extended memory (1K blocks) high byte
   226                                  	;out	70h, al ; select CMOS register
   227                                  	;in	al, 71h ; read data (1 byte)
   228                                  	;mov	ch, al
   229                                   	;      
   230 0000000F 89C1                    	mov	cx, ax
   231 00000011 31D2                    	xor	dx, dx
   232                                  chk_ms:
   233 00000013 890E[3466]              	mov	[mem_1m_1k], cx
   234 00000017 8916[3666]              	mov	[mem_16m_64k], dx
   235                                  	; 24/11/2023
   236 0000001B 8916[180F]              	mov	[real_mem_16m_64k], dx
   237                                  
   238                                  	; 05/11/2014
   239                                  	;and	dx, dx
   240                                  	;jz	short L2
   241 0000001F 81F90004                        cmp     cx, 1024
   242                                  	;jnb	short L0
   243 00000023 7351                    	jnb	short V0 ; 14/11/2020
   244                                  		 ; insufficient memory_error	
   245                                  		 ; Minimum 2 MB memory is needed... 
   246                                  	; 05/11/2014
   247                                  	; (real mode error printing)
   248 00000025 FB                      	sti
   249 00000026 BE[3A00]                	mov	si, msg_out_of_memory
   250 00000029 BB0700                  	mov	bx, 7
   251 0000002C B40E                    	mov	ah, 0Eh	; write tty
   252                                  oom_1:
   253 0000002E AC                      	lodsb
   254 0000002F 08C0                    	or	al, al
   255 00000031 7404                    	jz	short oom_2
   256 00000033 CD10                    	int	10h
   257 00000035 EBF7                    	jmp	short oom_1
   258                                  oom_2:
   259 00000037 F4                              hlt
   260 00000038 EBFD                    	jmp	short oom_2
   261                                  
   262                                  ; 20/02/2017
   263                                  ; 05/11/2014
   264                                  msg_out_of_memory:
   265 0000003A 070D0A                  	db 	07h, 0Dh, 0Ah
   266 0000003D 496E73756666696369-             db      'Insufficient memory !'
   266 00000046 656E74206D656D6F72-
   266 0000004F 792021             
   267 00000052 0D0A                    	db	0Dh, 0Ah
   268                                  _int13h_48h_buffer: ; 07/07/2016
   269 00000054 284D696E696D756D20-     	db	'(Minimum 2MB memory is needed.)'
   269 0000005D 324D42206D656D6F72-
   269 00000066 79206973206E656564-
   269 0000006F 65642E29           
   270 00000073 0D0A00                   	db	0Dh, 0Ah, 0
   271                                  V0:
   272                                  	; 18/10/2023 - TRDOS 386 v2.0.7
   273                                  	; set video mode to 03h again 
   274                                  	; (to reset video bios data in ROMBIOS DATA AREA)
   275 00000076 B80300                  	mov	ax, 3
   276 00000079 CD10                    	int	10h
   277                                  	; copy IVT and ROMBIOS DATA AREA to VBE3 BIOS data area
   278 0000007B BF0097                  	mov	di, VBE3BIOSDATABLOCK>>4
   279 0000007E 8EC7                    	mov	es, di
   280 00000080 31F6                    	xor	si, si
   281 00000082 31FF                    	xor	di, di
   282 00000084 8EDE                    	mov	ds, si ; 0
   283 00000086 B90003                  	mov	cx, 300h ; 600h / 2
   284 00000089 F3A5                    	rep	movsw
   285 0000008B 0E                      	push	cs
   286 0000008C 1F                      	pop	ds
   287                                  	
   288                                  	; 24/11/2023
   289                                  	; 15/12/2020
   290                                  	;mov	si, [mem_16m_64k]
   291                                  	;mov	[real_mem_16m_64k], si
   292                                  	
   293                                  	; 15/11/2020
   294                                  	; 14/11/2020 (TRDOS 386 v2.0.3)
   295                                  	; check VESA (VBE) VIDEO BIOS version
   296                                  
   297 0000008D B8034F                  	mov	ax, 4F03h  ; Return current VBE mode
   298 00000090 CD10                    	int	10h
   299 00000092 83F84F                  	cmp	ax, 004Fh  ; successful (vbe) function call
   300                                  	;jne	short L0   ; not a VESA VBE compatible bios	
   301                                  	; 18/10/2023
   302 00000095 7561                    	jne	short V1   ; restore es
   303                                  
   304                                  	; 27/11/2023
   305                                  	; 24/11/2023 - temporary
   306                                  	;jmp	short V1
   307                                  
   308                                  	;mov	ah, 3
   309                                  	;;jmp	short V1	
   310                                  	
   311                                  	; 15/11/2020
   312 00000097 BBE097                  	mov	bx, VBE3INFOSEG  ; 97E0h for current version 
   313 0000009A 8EC3                    	mov	es, bx
   314 0000009C 31FF                    	xor	di, di
   315 0000009E 2666C70556424532        	mov	dword [es:di], 'VBE2' ; request VESA VBE3 info
   316                                  		; es:di = buffer address (512 bytes)
   317                                  	;mov	ax, 4F00h ; Return VBE controller information
   318 000000A6 86E0                    	xchg	al, ah
   319 000000A8 CD10                    	int	10h
   320                                  	
   321                                  	; dx = cs
   322                                  	; es = VBE3INFOSEG (97E0h)
   323                                  	; di = 0
   324                                  	; ss = (endofkernelfile/16)+16
   325                                  	; sp = 0FFFEh
   326                                  
   327 000000AA 83F84F                  	cmp	ax, 004Fh
   328 000000AD 7549                    	jne	short V1 ; old vga bios (not VESA compatible)
   329                                  
   330                                  	; 15/11/2020
   331 000000AF 2666813D56455341        	cmp	dword [es:di], 'VESA'
   332 000000B7 753F                    	jne	short V1
   333                                  	
   334                                  	;mov	ax, [es:di+4]
   335                                  	;	; ax = vbe version in BCD format (0200h or 0300h)
   336                                  	;mov	[vbe3], ah ; version number (major) 	
   337                                  
   338                                  	; 15/11/2020
   339 000000B9 268A4505                	mov	al, [es:di+5]
   340                                  		; al = high byte of VBE version number (02h or 03h)
   341                                  
   342 000000BD A2[8609]                	mov	[vbe3], al ; version number (major) 	
   343                                  			   ; 02h or 03h is expected
   344                                  	; 17/01/2021
   345                                  	; Read EDID
   346 000000C0 B301                    	mov	bl, 01h	; Read EDID
   347 000000C2 31C9                    	xor	cx, cx	; Controller unit number
   348                                  			; (00 = primary controller)
   349 000000C4 31D2                    	xor	dx, dx	; EDID block number = 0
   350 000000C6 B8C097                  	mov	ax, VBE3MODEINFOSEG  ; 97C0h for current version
   351 000000C9 8EC0                    	mov	es, ax
   352 000000CB BF0001                  	mov	di, VBE3EDIDINFOBLOCK - VBE3MODEINFOBLOCK
   353                                  	; es:di = temporary address of 128 bytes EDID information 
   354 000000CE B8154F                  	mov	ax, 4F15h ; VBE/DDC Services 
   355 000000D1 CD10                    	int	10h
   356                                  	;cmp	ax, 4Fh
   357                                  	;jne	short v2
   358 000000D3 A2[D341]                	mov	[edid], al ; 4Fh > 0
   359                                  ;V2:
   360                                  	; 17/01/2021
   361 000000D6 31FF                    	xor	di, di
   362                                  	; 15/12/2020
   363                                  	; Get linear frame buffer info (for VESA VBE mode 118h)
   364                                  	;mov	si, VBE3MODEINFOSEG  ; 97C0h for current version
   365                                  	;mov	es, si
   366                                   	; di = 0
   367 000000D8 B91841                  	mov	cx, 04118h  ; 1024*768, 24 bpp, LFB
   368 000000DB B8014F                  	mov	ax, 4F01h ; Return VBE mode information
   369 000000DE CD10                    	int	10h
   370                                  	;cmp	ax, 4Fh
   371                                  	;jne	short V1
   372                                  	; 19/12/2020
   373                                  	;mov	si, [es:di+MODEINFO.PhysBasePtr+2]
   374                                  			; hw of LFB base address
   375                                  	; MODEINFO structure starts from offset -2
   376 000000E0 268B752A                	mov	si, [es:di+MODEINFO.PhysBasePtr] ; hw of LFB addr
   377 000000E4 8936[1A0F]              	mov	[def_LFB_addr], si ; k_LFB_size = 3145728 bytes
   378 000000E8 81EE0001                	sub	si, 256
   379                                  	
   380                                  	; 15/12/2020
   381                                  	; check memory and decrease it to 3.5 GB if it is 4GB
   382                                  	; (reserve upper memory for LFB)
   383 000000EC 8B3E[3666]              	mov	di, [mem_16m_64k]
   384                                  	; 24/11/2023
   385                                  	;mov	[real_mem_16m_64k], di
   386                                  
   387 000000F0 39F7                    	cmp	di, si
   388 000000F2 7604                    	jna	short V1
   389                                  
   390 000000F4 8936[3666]              	mov	[mem_16m_64k], si
   391                                  
   392                                  	; VESA VBE3 video hardware 
   393                                  	; (example: NVIDIA GEFORCE FX550, 256 MB)
   394                                  	; uses upper memory from 0D0000000h to 0DFFFFFFFh
   395                                  	
   396                                  	;;cmp	di, 0CF00h ; 3328 MB - 16MB
   397                                  	;jna	short V1  ; <= 3328 MB memory, it is not required
   398                                  			  ; decrease
   399                                  	;cmp	al, 3 
   400                                  	;jb	short V2 
   401                                  	; VESA VBE 3
   402                                  	;mov	word [mem_16m_64k], 0CF00h ; 3328 MB - 16MB
   403                                  	;jmp	short V1 	
   404                                  ;V2:
   405                                  	; VESA VBE 2
   406                                  	; Check Bochs/Qemu/VirtualBox Emulator
   407                                  	; LFB base address: 0E0000000h
   408                                  	;sub	ax, ax ; 0
   409                                  	;mov	dx, 1CEh ; VBE_DISPI_IOPORT_INDEX
   410                                  	;out	dx, ax ; VBE_DISPI_INDEX_ID register
   411                                  	;inc	dx
   412                                  	;in	ax, dx
   413                                  	;and	al, 0F0h
   414                                  	;cmp	ax, 0B0C0h
   415                                  	;jne	short V1
   416                                  	;
   417                                  	; BOCHS/QEMU/VIRTUALBOX
   418                                  	;mov	word [mem_16m_64k], 0DF00h ; 3584 MB - 16MB	
   419                                  V1:
   420 000000F8 1E                      	push	ds
   421 000000F9 07                      	pop	es ; restore extra data segment	
   422                                  L0:
   423                                  
   424                                  %include 'diskinit.s' ; 07/03/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.5 - diskinit.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 09/08/2022 (Previous: 29/08/2020 - Kernel v2.0.4)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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: 12/07/2022 (Previous: 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> 	; 09/08/2022
    27                              <1> 	; 08/08/2022
    28                              <1> 	; 14/07/2022 (TRDOS 386 v2.0.5)
    29                              <1> 	; 12/07/2022 (Retro UNIX 386 v1.2)
    30                              <1> 	; 29/08/2020
    31                              <1> 	; 17/07/2020
    32                              <1> 	; 14/07/2020 (TRDOS 386 v2.0.2)
    33                              <1> 	; 10/12/2014 - 02/02/2015 - dsectrm2.s
    34                              <1> ;L0:
    35                              <1> 	; 12/11/2014 (Retro UNIX 386 v1 - beginning)
    36                              <1> 	; Detecting disk drives... (by help of ROM-BIOS)
    37 000000FA BA7F00              <1> 	mov	dx, 7Fh
    38                              <1> L1:	
    39 000000FD FEC2                <1> 	inc	dl
    40 000000FF B441                <1> 	mov	ah, 41h ; Check extensions present
    41                              <1> 			; Phoenix EDD v1.1 - EDD v3
    42 00000101 BBAA55              <1> 	mov	bx, 55AAh
    43 00000104 CD13                <1> 	int 	13h
    44 00000106 721A                <1> 	jc	short L2
    45                              <1> 
    46 00000108 81FB55AA            <1> 	cmp	bx, 0AA55h
    47 0000010C 7514                <1> 	jne	short L2
    48 0000010E FE06[3B66]          <1> 	inc	byte [hdc]	; count of hard disks (EDD present)
    49 00000112 8816[3A66]          <1>         mov     [last_drv], dl  ; last hard disk number
    50 00000116 BB[BE65]            <1> 	mov	bx, hd0_type - 80h
    51 00000119 01D3                <1> 	add	bx, dx	 
    52 0000011B 880F                <1> 	mov	[bx], cl ; Interface support bit map in CX
    53                              <1> 			 ; Bit 0 - 1, Fixed disk access subset ready
    54                              <1> 			 ; Bit 1 - 1, Drv locking and ejecting ready
    55                              <1> 			 ; Bit 2 - 1, Enhanced Disk Drive Support
    56                              <1>                          ;            (EDD) ready (DPTE ready)
    57                              <1> 			 ; Bit 3 - 1, 64bit extensions are present
    58                              <1>                          ;            (EDD-3)
    59                              <1> 			 ; Bit 4 to 15 - 0, Reserved
    60 0000011D 80FA83              <1> 	cmp	dl, 83h	 ; drive number < 83h
    61 00000120 72DB                <1> 	jb	short L1
    62                              <1> L2:
    63                              <1> 	; 23/11/2014
    64                              <1> 	; 19/11/2014
    65 00000122 30D2                <1> 	xor	dl, dl  ; 0
    66                              <1> 	; 04/02/2016 (esi -> si)
    67 00000124 BE[3C66]            <1> 	mov	si, fd0_type
    68                              <1> L3:
    69                              <1> 	; 14/01/2015
    70 00000127 8816[3966]          <1> 	mov	[drv], dl
    71                              <1> 	;
    72 0000012B B408                <1> 	mov 	ah, 08h ; Return drive parameters
    73 0000012D CD13                <1> 	int	13h	
    74 0000012F 7210                <1> 	jc	short L4
    75                              <1> 		; BL = drive type (for floppy drives)
    76                              <1> 		; DL = number of floppy drives
    77                              <1> 		;		
    78                              <1> 		; ES:DI = Address of DPT from BIOS
    79                              <1> 		;
    80 00000131 881C                <1> 	mov	[si], bl ;  Drive type
    81                              <1> 			; 4 = 1.44 MB, 80 track, 3 1/2"
    82                              <1> 	; 14/01/2015
    83 00000133 E8DD01              <1> 	call	set_disk_parms
    84                              <1> 	; 10/12/2014
    85 00000136 81FE[3C66]          <1> 	cmp	si, fd0_type
    86 0000013A 7705                <1> 	ja	short L4
    87 0000013C 46                  <1> 	inc	si ; fd1_type
    88 0000013D B201                <1> 	mov	dl, 1
    89 0000013F EBE6                <1> 	jmp	short L3
    90                              <1> L4:
    91 00000141 B27F                <1> 	mov	dl, 7Fh
    92                              <1> 	; 24/12/2014
    93 00000143 803E[3B66]00        <1> 	cmp	byte [hdc], 0 ; EDD present or not ?	
    94                              <1> 	;ja	L10	  ; yes, all fixed disk operations
    95                              <1> 			  ; will be performed according to
    96                              <1> 			  ; present EDD specification
    97                              <1> 	; 14/07/2022
    98 00000148 7603                <1> 	jna	short L5
    99 0000014A E98B00              <1> 	jmp	L10
   100                              <1> 
   101                              <1> L5:
   102                              <1> 	; 17/07/2020
   103                              <1> 	; Note: Virtual CPU will not come here while 
   104                              <1> 	; running in QEMU, Bochs, VirtualBox emulators !!!
   105                              <1> 	
   106                              <1> 	; 17/07/2020
   107                              <1> 	; Older BIOS (INT 13h, AH = 48h is not available)
   108                              <1> 
   109 0000014D FEC2                <1> 	inc 	dl
   110 0000014F 8816[3966]          <1>         mov     [drv], dl
   111 00000153 8816[3A66]          <1>         mov     [last_drv], dl ; 14/01/2015
   112 00000157 B408                <1> 	mov 	ah, 08h ; Return drive parameters
   113 00000159 CD13                <1> 	int	13h	; (conventional function)
   114                              <1> 	;jc	L13	; fixed disk drive not ready
   115                              <1> 	; 14/07/2022
   116 0000015B 7303                <1> 	jnc	short L6
   117 0000015D E9A501              <1> 	jmp	L13
   118                              <1> L6:
   119 00000160 8816[3B66]          <1>         mov     [hdc], dl ; number of drives
   120                              <1> 	;; 14/01/2013
   121                              <1> 	;;push	cx
   122 00000164 E8AC01              <1> 	call	set_disk_parms
   123                              <1> 	;;pop	cx
   124                              <1> 	;
   125                              <1> 	;;and	cl, 3Fh	 ; sectors per track (bits 0-6)
   126 00000167 8A16[3966]          <1>         mov     dl, [drv]
   127 0000016B BB0401              <1> 	mov	bx, 65*4 ; hd0 parameters table (INT 41h)	
   128 0000016E 80FA80              <1> 	cmp	dl, 80h
   129 00000171 7603                <1> 	jna	short L7
   130 00000173 83C314              <1> 	add	bx, 5*4	 ; hd1 parameters table (INT 46h)
   131                              <1> L7:	
   132 00000176 31C0                <1> 	xor	ax, ax
   133 00000178 8ED8                <1> 	mov	ds, ax
   134 0000017A 8B37                <1>         mov     si, [bx]
   135 0000017C 8B4702              <1>         mov     ax, [bx+2] 
   136 0000017F 8ED8                <1> 	mov	ds, ax
   137 00000181 3A4C0E              <1>         cmp     cl, [si+FDPT_SPT] ; sectors per track 
   138                              <1> 	;jne	L12 ; invalid FDPT
   139                              <1> 	; 14/07/2022
   140 00000184 7403                <1> 	je	short L7_8
   141 00000186 E97801              <1> 	jmp	L12
   142                              <1> L7_8:
   143 00000189 BF0000              <1> 	mov	di, HD0_DPT
   144 0000018C 80FA80              <1> 	cmp	dl, 80h
   145 0000018F 7603                <1> 	jna	short L8
   146 00000191 BF2000              <1> 	mov	di, HD1_DPT 
   147                              <1> L8:
   148                              <1> 	; 30/12/2014
   149 00000194 B80090              <1> 	mov	ax, DPT_SEGM
   150 00000197 8EC0                <1> 	mov	es, ax
   151                              <1> 	; 24/12/2014
   152 00000199 B90800              <1> 	mov	cx, 8
   153 0000019C F3A5                <1> 	rep	movsw  ; copy 16 bytes to the kernel's DPT location
   154 0000019E 8CC8                <1> 	mov	ax, cs
   155 000001A0 8ED8                <1> 	mov	ds, ax
   156                              <1> 
   157                              <1> 	; 02/02/2015
   158                              <1> 	;mov	cl, [drv]
   159                              <1> 	;mov	bl, cl
   160                              <1> 	;mov	ax, 1F0h
   161                              <1> 	;and	bl, 1
   162                              <1> 	;jz	short L9
   163                              <1> 	;shl	bl, 4
   164                              <1> 	;sub	ax, 1F0h-170h
   165                              <1> 
   166                              <1> 	; 17/07/2020 
   167                              <1> 	; (Only 1F0h port address must be valid for old ROM BIOSes)
   168 000001A2 B8F001              <1> 	mov	ax, 1F0h
   169 000001A5 B3A0                <1> 	mov	bl, 0A0h
   170 000001A7 80FA80              <1> 	cmp	dl, 80h
   171 000001AA 7603                <1> 	jna	short L9
   172                              <1> 	; dl = 81h
   173 000001AC 80C310              <1> 	add	bl, 10h  ; slave disk
   174                              <1> 	;sub	ax, 1F0h-170h
   175                              <1> L9:
   176 000001AF AB                  <1> 	stosw	; I/O PORT Base Address (1F0h, 170h)
   177 000001B0 050602              <1> 	add	ax, 206h
   178 000001B3 AB                  <1> 	stosw	; CONTROL PORT Address (3F6h, 376h)	
   179 000001B4 88D8                <1> 	mov	al, bl  ; bit 4, master/slave disk bit
   180                              <1> 	;add	al, 0A0h ; 17/07/2020
   181 000001B6 AA                  <1> 	stosb	; Device/Head Register upper nibble
   182                              <1> 	;
   183 000001B7 FE06[3966]          <1> 	inc	byte [drv]
   184                              <1> 	;mov	bx, hd0_type - 80h
   185                              <1> 	;add	bx, cx
   186                              <1> 	; 09/08/2022 - BugFix
   187 000001BB 30FF                <1> 	xor	bh, bh
   188 000001BD 88D3                <1> 	mov	bl, dl
   189 000001BF 81C3[BE65]          <1> 	add	bx, hd0_type - 80h
   190 000001C3 800F80              <1> 	or      byte [bx], 80h  ; present sign (when lower nibble is 0)
   191 000001C6 A0[3B66]            <1> 	mov	al, [hdc]
   192 000001C9 FEC8                <1> 	dec	al
   193                              <1> 	;jz	L13
   194                              <1> 	; 14/07/2022
   195 000001CB 7408                <1> 	jz	short L9_10
   196 000001CD 80FA80              <1> 	cmp	dl, 80h
   197                              <1>         ;jna	L5 ; Max. 2 hard disks  ; 17/07/2020
   198                              <1> 	; 14/07/2022
   199 000001D0 7703                <1> 	ja	short L9_10
   200 000001D2 E978FF              <1> 	jmp	L5
   201                              <1> L9_10:
   202 000001D5 E92D01              <1>         jmp     L13
   203                              <1> L10:
   204 000001D8 FEC2                <1> 	inc 	dl
   205                              <1> 	; 25/12/2014
   206 000001DA 8816[3966]          <1> 	mov	[drv], dl
   207 000001DE B408                <1> 	mov 	ah, 08h ; Return drive parameters
   208 000001E0 CD13                <1> 	int	13h	; (conventional function)
   209                              <1> 	;jc	L13
   210                              <1> 	; 14/07/2022
   211 000001E2 72F1                <1> 	jc	short L9_10
   212                              <1> 	; 14/01/2015
   213                              <1> 	;mov	dl, [drv]
   214                              <1> 	; 09/08/2022
   215                              <1> 	;push	dx
   216 000001E4 51                  <1> 	push	cx
   217 000001E5 E82B01              <1> 	call	set_disk_parms
   218 000001E8 59                  <1> 	pop	cx
   219                              <1> 	;pop	dx
   220                              <1> 	; 09/08/2022
   221 000001E9 8A16[3966]          <1> 	mov	dl, [drv]	
   222                              <1> 	; 06/07/2016 (BugFix for >64K kernel files)
   223                              <1> 	; 04/02/2016 (esi -> si)
   224                              <1> 	;mov	si, _end ; 30 byte temporary buffer address 	
   225                              <1> 	;		 ; at the '_end' of kernel.
   226                              <1> 	;mov	word [si], 30
   227                              <1> 	; 06/07/2016
   228 000001ED BE[5400]            <1> 	mov	si, _int13h_48h_buffer
   229                              <1> 	; 09/07/2016
   230 000001F0 B81E00              <1> 	mov	ax, 001Eh
   231 000001F3 8824                <1> 	mov	[si], ah ; 0
   232 000001F5 46                  <1> 	inc	si
   233 000001F6 8904                <1> 	mov	[si], ax
   234                              <1>  	; word [si] = 30
   235                              <1> 	;
   236 000001F8 B448                <1> 	mov	ah, 48h	 ; Get drive parameters (EDD function)
   237 000001FA CD13                <1> 	int	13h
   238                              <1> 	;jc	L13
   239                              <1> 	; 14/07/2022
   240 000001FC 72D7                <1> 	jc	short L9_10
   241                              <1> 
   242                              <1> 	; 29/08/2020
   243                              <1> 	; 04/02/2016 (ebx -> bx)
   244                              <1> 	; 14/01/2015
   245 000001FE 28FF                <1> 	sub	bh, bh
   246 00000200 88D3                <1> 	mov	bl, dl
   247                              <1> 	;sub	bl, 80h
   248                              <1> 	; 29/08/2020
   249 00000202 81C3[BE65]          <1> 	add	bx, (hd0_type - 80h)
   250                              <1> 	;mov 	al, [bx]
   251 00000206 8A07                <1> 	mov	al, [bx]
   252 00000208 0C80                <1> 	or	al, 80h
   253 0000020A 8807                <1> 	mov 	[bx], al	
   254 0000020C 81EB[3C66]          <1> 	sub	bx, hd0_type - 2 ; 15/01/2015
   255                              <1> 	;add	bx, drv.status
   256                              <1> 	;mov	[bx], al
   257                              <1> 	; 29/08/2020
   258 00000210 8887[5E66]          <1> 	mov	[bx+drv.status], al
   259                              <1> 	; 04/02/2016 (eax -> ax)
   260                              <1> 	;mov	ax, [si+16]
   261                              <1> 	; 14/07/2020
   262                              <1> 	;mov	di, [si+18] 
   263                              <1> 	;;test	ax, [si+18]
   264                              <1> 	;test	ax, di ; 14/07/2020
   265                              <1> 	;jz	short L10_A0h ; (!) ; 17/07/2020
   266                              <1> 			; 'CHS only' disks on EDD system 
   267                              <1> 			;  are reported with ZERO disk size
   268                              <1> 			; (if so, we must not overwrite
   269                              <1> 			; calculated disk size in 'set_disk_parms')
   270                              <1> 	; 29/08/2020
   271 00000214 8B4410              <1> 	mov	ax, [si+16]
   272 00000217 8B7C12              <1> 	mov	di, [si+18]
   273 0000021A 09C0                <1> 	or	ax, ax
   274 0000021C 7504                <1> 	jnz	short L10_LBA
   275 0000021E 09FF                <1> 	or	di, di
   276 00000220 740B                <1> 	jz	short L10_A0h
   277                              <1> L10_LBA:
   278                              <1> 	;sub	bx, drv.status
   279 00000222 C1E302              <1> 	shl	bx, 2
   280                              <1> 	;add	bx, drv.size ; disk size (in sectors)
   281                              <1> 	;mov	[bx], ax
   282                              <1> 	; 29/08/2020
   283 00000225 8987[4266]          <1> 	mov	[bx+drv.size], ax
   284                              <1> 	;mov	ax, [si+18]
   285                              <1> 	;;mov	[bx], ax
   286                              <1> 	;mov	[bx+2], ax ; BugFix ; 15/07/2020
   287                              <1> 	; 14/07/2020
   288                              <1> 	;mov	[bx+2], di ; 15/07/2020
   289                              <1> 	; 29/08/2020
   290 00000229 89BF[4466]          <1> 	mov	[bx+drv.size+2], di
   291                              <1> L10_A0h: 
   292                              <1> 	; 17/07/2020
   293                              <1> 	; Note: Virtual CPU will jump here from above (!) test
   294                              <1> 	;	while running in QEMU
   295                              <1> 
   296                              <1> 	; Jump here to fix a ZERO (LBA) disk size problem 
   297                              <1> 	; for CHS disks (28/02/2015)
   298                              <1> 	
   299                              <1> 	; 30/12/2014
   300 0000022D BF0000              <1> 	mov	di, HD0_DPT
   301 00000230 88D0                <1> 	mov	al, dl
   302 00000232 83E003              <1> 	and 	ax, 3
   303 00000235 C0E005              <1> 	shl	al, 5 ; * 32
   304 00000238 01C7                <1> 	add 	di, ax
   305 0000023A B80090              <1> 	mov	ax, DPT_SEGM
   306 0000023D 8EC0                <1> 	mov	es, ax
   307                              <1> 	;
   308 0000023F 88E8                <1> 	mov	al, ch	; max. cylinder number (bits 0-7)
   309 00000241 88CC                <1> 	mov	ah, cl	
   310 00000243 C0EC06              <1> 	shr	ah, 6	; max. cylinder number (bits 8-9)
   311 00000246 40                  <1>  	inc	ax	; logical cylinders (limit 1024)
   312 00000247 AB                  <1> 	stosw		
   313 00000248 88F0                <1> 	mov	al, dh	; max. head number
   314                              <1> 	;
   315 0000024A 30F6                <1> 	xor	dh, dh  ; 29/08/2020 (dh = 0 is needed here)
   316                              <1> 	;
   317 0000024C FEC0                <1> 	inc	al
   318 0000024E AA                  <1> 	stosb		; logical heads (limits 256)
   319 0000024F B0A0                <1> 	mov	al, 0A0h ; Indicates translated table
   320 00000251 AA                  <1> 	stosb
   321 00000252 8A440C              <1> 	mov	al, [si+12]
   322 00000255 AA                  <1> 	stosb		 ; physical sectors per track
   323 00000256 31C0                <1>  	xor	ax, ax
   324                              <1> 	;dec	ax	 ; 02/01/2015 
   325 00000258 AB                  <1> 	stosw		 ; precompensation (obsolete)
   326                              <1> 	;xor	al, al	 ; 02/01/2015	
   327 00000259 AA                  <1> 	stosb		 ; reserved
   328 0000025A B008                <1> 	mov	al, 8	 ; drive control byte
   329                              <1> 		         ; (do not disable retries, 
   330                              <1> 			 ; more than 8 heads)
   331 0000025C AA                  <1> 	stosb
   332 0000025D 8B4404              <1> 	mov	ax, [si+4]
   333 00000260 AB                  <1> 	stosw		 ; physical number of cylinders	
   334                              <1> 	;push	ax	 ; 02/01/2015
   335 00000261 8A4408              <1> 	mov	al, [si+8]
   336 00000264 AA                  <1> 	stosb		 ; physical num. of heads (limit 16)
   337 00000265 29C0                <1> 	sub 	ax, ax
   338                              <1> 	;pop	ax	 ; 02/01/2015	
   339 00000267 AB                  <1> 	stosw		 ; landing zone (obsolete)
   340 00000268 88C8                <1> 	mov	al, cl	 ; logical sectors per track (limit 63)
   341 0000026A 243F                <1> 	and 	al, 3Fh	
   342 0000026C AA                  <1> 	stosb
   343                              <1> 	;sub	al, al	 ; checksum
   344                              <1> 	;stosb
   345                              <1> 	;
   346 0000026D 83C61A              <1> 	add	si, 26   ; (BIOS) DPTE address pointer
   347 00000270 AD                  <1> 	lodsw
   348 00000271 50                  <1> 	push	ax ; *	 ; (BIOS) DPTE offset
   349 00000272 AD                  <1> 	lodsw
   350 00000273 50                  <1> 	push	ax ; **	 ; (BIOS) DPTE segment
   351                              <1> 	;
   352                              <1> 	; checksum calculation
   353 00000274 89FE                <1> 	mov	si, di
   354 00000276 06                  <1> 	push	es
   355 00000277 1F                  <1> 	pop	ds
   356                              <1> 	;mov	cx, 16
   357 00000278 B90F00              <1> 	mov 	cx, 15
   358 0000027B 29CE                <1> 	sub	si, cx
   359 0000027D 30E4                <1> 	xor	ah, ah
   360                              <1> 	;del	cl
   361                              <1> L11:		
   362 0000027F AC                  <1> 	lodsb
   363 00000280 00C4                <1> 	add	ah, al
   364 00000282 E2FB                <1> 	loop	L11
   365                              <1> 	;
   366 00000284 88E0                <1> 	mov	al, ah
   367 00000286 F6D8                <1> 	neg	al	; -x+x = 0
   368 00000288 AA                  <1> 	stosb		; put checksum in byte 15 of the tbl
   369                              <1> 	;
   370 00000289 1F                  <1> 	pop	ds ; **	; (BIOS) DPTE segment
   371 0000028A 5E                  <1> 	pop	si ; *	; (BIOS) DPTE offset	
   372                              <1> 
   373                              <1> 	; 08/08/2022 (TRDOS 386 v2.0.5)
   374                              <1> 	; (Recent version of Retro UNIX 386 v1 'diskinit.s' file
   375                              <1> 	; -12/07/2022- does not contain following 2020 code) (*)
   376                              <1> 
   377                              <1> 	; 14/07/2020 (TRDOS 386 v2.0.2)
   378                              <1> 	; 0FFFFh:0FFFFh = invalid DPTE address
   379 0000028B 8B0C                <1> 	mov	cx, [si]
   380 0000028D 8B4402              <1> 	mov	ax, [si+2]
   381 00000290 21C1                <1> 	and	cx, ax
   382 00000292 41                  <1> 	inc	cx 
   383 00000293 7404                <1> 	jz	short L11c ; 0FFFFh:0FFFFh
   384 00000295 0B04                <1> 	or	ax, [si]
   385 00000297 752A                <1> 	jnz	short L11e ; <> 0
   386                              <1> L11c:
   387                              <1> 	; 17/07/2020
   388                              <1> 	; TRDOS 386 v2 DRVINIT assumptions:
   389                              <1> 	; (also by regarding QEMU, Bochs and VirtualBox settings)
   390                              <1> 	;	Hard disk 0 port address: 1F0h
   391                              <1> 	;	Hard disk 1 port address: 1F0h
   392                              <1> 	;	Hard disk 2 port address: 170h
   393                              <1> 	;	Hard disk 3 port address: 170h
   394                              <1> 
   395                              <1> 	; in QEMU, hda=hd0 (1F0h) and hdb=hd1 (1F0h) -IRQ14-
   396                              <1> 	;      and hdc=hd2 (170h) and hdd=hd3 (170h) -IRQ15-
   397                              <1> 
   398 00000299 B8F001              <1> 	mov	ax, 1F0h
   399                              <1> 
   400                              <1> 	; 15/07/2020
   401                              <1> 	; 14/07/2020
   402                              <1> 	; Invalid DPTE address...
   403                              <1> 	; Default DPTE parms must be set for DISK_IO_CONT
   404                              <1> 	; (diskio.s)
   405                              <1> 	; 17/07/2020
   406                              <1> 
   407                              <1> 	;mov	bl, dl
   408                              <1> 	;and	bl, 1
   409                              <1> 	;jz	short L11d
   410                              <1> 
   411 0000029C B3A0                <1> 	mov	bl, 0A0h
   412                              <1> 
   413 0000029E F6C201              <1> 	test	dl, 1
   414 000002A1 7403                <1> 	jz	short L11g  ; Master (as default, for 80h & 82h))
   415                              <1> 	;shl	bl, 4 ; bl = 16 (bit 4 = 1 -> slave)
   416 000002A3 80C310              <1> 	add	bl, 10h  ; Slave (as default, for 81h & 83h)
   417                              <1> L11g:
   418                              <1> 	; 17/07/2020
   419 000002A6 80FA82              <1> 	cmp	dl, 82h	; Hard disk 3 or 4 ?
   420 000002A9 7203                <1> 	jb	short L11d ; Primary ATA channel (hd0, hd1)
   421                              <1> 			   ; (port address = 1F0h)
   422                              <1> 	
   423                              <1> 	; Secondary ATA channel (hd2, hd3)
   424                              <1> 	; (port address = 170h)
   425                              <1> 
   426 000002AB 2D8000              <1> 	sub	ax, 1F0h-170h
   427                              <1> L11d:
   428                              <1> 	; 14/07/2020
   429 000002AE AB                  <1> 	stosw	; I/O PORT Base Address (1F0h, 170h)
   430 000002AF 050602              <1> 	add	ax, 206h
   431 000002B2 AB                  <1> 	stosw	; CONTROL PORT Address (3F6h, 376h)	
   432 000002B3 88D8                <1> 	mov	al, bl  ; Master/Slave bit (0 = Master)
   433                              <1> 	; 17/07/2020
   434                              <1> 	;or	al, 0A0h ; CHS (LBA enable bit = 0)
   435                              <1> 			 ; (Bits 5&7, reserved bits  =  1)
   436 000002B5 30E4                <1> 	xor	ah, ah
   437                              <1> 	;stosb	; Device/Head Register upper nibble
   438 000002B7 AB                  <1> 	stosw
   439 000002B8 30C0                <1> 	xor	al, al
   440 000002BA B90500              <1> 	mov	cx, 5
   441 000002BD F3AB                <1> 	rep	stosw ; clear remain part of the (fake) DPTE
   442 000002BF 0E                  <1> 	push	cs
   443 000002C0 1F                  <1> 	pop	ds
   444 000002C1 EB2E                <1> 	jmp	short L11f
   445                              <1> 
   446                              <1> 	; 08/08/2022 (TRDOS 386 v2.0.5)
   447                              <1> 	; (Recent version of Retro UNIX 386 v1 'diskinit.s' file
   448                              <1> 	; -12/07/2022- does not contain above 2020 code) (*)
   449                              <1> L11e:
   450                              <1> 	; 23/02/2015
   451 000002C3 57                  <1> 	push	di
   452                              <1> 	; ES:DI points to DPTE (FDPTE) location
   453                              <1> 	;;mov	cx, 8
   454                              <1> 	;mov	cl, 8
   455 000002C4 B90800              <1> 	mov	cx, 8 ; 14/07/2020
   456 000002C7 F3A5                <1> 	rep	movsw	
   457                              <1> 	;
   458                              <1> 	; 23/02/2015
   459                              <1> 	; (P)ATA drive and LBA validation
   460                              <1> 	; (invalidating SATA drives and setting
   461                              <1> 	; CHS type I/O for old type fixed disks)
   462 000002C9 5B                  <1> 	pop	bx
   463 000002CA 8CC8                <1> 	mov	ax, cs
   464 000002CC 8ED8                <1> 	mov	ds, ax
   465 000002CE 268B07              <1> 	mov	ax, [es:bx]
   466 000002D1 3DF001              <1> 	cmp	ax, 1F0h
   467 000002D4 7413                <1> 	je	short L11a
   468 000002D6 3D7001              <1> 	cmp	ax, 170h
   469 000002D9 740E                <1> 	je	short L11a
   470                              <1> 	; invalidation 
   471                              <1> 	; (because base port address is not 1F0h or 170h)
   472                              <1> 	;xor	bh, bh
   473                              <1> 	;mov	bl, dl
   474                              <1> 	; 29/08/2020
   475                              <1> 	;xor	dh, dh ; 0
   476 000002DB 89D3                <1> 	mov	bx, dx
   477                              <1> 	;sub	bl, 80h
   478                              <1> 	;mov	byte [bx+hd0_type], 0 ; not a valid disk drive !		
   479                              <1>         ;or	byte [bx+drv.status+2], 0F0h ; (failure sign)
   480                              <1> 	; 29/08/2020
   481 000002DD C687[BE65]00        <1> 	mov	byte [bx+hd0_type-80h], 0
   482 000002E2 808F[E065]F0        <1> 	or	byte [bx+drv.status-7Eh], 0F0h
   483 000002E7 EB0F                <1> 	jmp	short L11b
   484                              <1> L11a:	
   485                              <1> 	; LBA validation
   486 000002E9 268A4704            <1> 	mov	al, [es:bx+4] ; Head register upper nibble
   487 000002ED A840                <1> 	test	al, 40h ; LBA bit (bit 6)
   488 000002EF 7507                <1> 	jnz	short L11b ; LBA type I/O is OK! (E0h or F0h)
   489                              <1> L11f:
   490                              <1> 	; force CHS type I/O for this drive (A0h or B0h)
   491                              <1> 	;sub	bh, bh
   492                              <1> 	;mov	bl, dl
   493                              <1> 	; 29/08/2020
   494                              <1> 	;xor	dh, dh ; 0
   495 000002F1 89D3                <1> 	mov	bx, dx
   496                              <1> 	;sub	bl, 80h ; 26/02/2015
   497                              <1>         ;and	byte [bx+drv.status+2], 0FEh ; clear bit 0
   498                              <1> 				; bit 0 = LBA ready bit
   499                              <1> 	; 29/08/2020
   500 000002F3 80A7[E065]FE        <1> 	and	byte [bx+drv.status-7Eh], 0FEh
   501                              <1> 	; 'diskio' procedure will check this bit !
   502                              <1> L11b:
   503 000002F8 3A16[3A66]          <1> 	cmp	dl, [last_drv] ; 25/12/2014
   504 000002FC 7307                <1>         jnb     short L13
   505 000002FE E9D7FE              <1>         jmp     L10
   506                              <1> 
   507                              <1> L12:
   508                              <1> 	; Restore data registers
   509 00000301 8CC8                <1> 	mov	ax, cs
   510 00000303 8ED8                <1> 	mov	ds, ax	
   511                              <1> L13:
   512                              <1> 	; 13/12/2014
   513 00000305 0E                  <1> 	push	cs
   514 00000306 07                  <1> 	pop	es
   515                              <1> L14:
   516                              <1> 	; clear keyboard buffer
   517 00000307 B411                <1> 	mov 	ah, 11h
   518 00000309 CD16                <1> 	int 	16h
   519 0000030B 7440                <1> 	jz 	short L16 ; no keys in keyboard buffer
   520 0000030D B010                <1> 	mov	al, 10h
   521 0000030F CD16                <1> 	int 	16h
   522 00000311 EBF4                <1> 	jmp 	short L14
   523                              <1> 
   524                              <1> set_disk_parms:
   525                              <1> 	; 08/08/2022 - TRDOS 386 v2.0.5
   526                              <1> 	; 09/05/2022 - Retro UNIX 386 v1.2
   527                              <1> 	; 29/08/2020 - TRDOS 386 v2.0.2
   528                              <1> 	; 04/02/2016 (ebx -> bx)
   529                              <1> 	; 10/07/2015
   530                              <1> 	; 14/01/2015
   531                              <1> 	;push	bx
   532 00000313 28FF                <1> 	sub	bh, bh
   533 00000315 8A1E[3966]          <1> 	mov	bl, [drv]
   534 00000319 80FB80              <1> 	cmp	bl, 80h
   535 0000031C 7203                <1> 	jb	short sdp0
   536 0000031E 80EB7E              <1> 	sub	bl, 7Eh
   537                              <1> sdp0:	
   538                              <1> 	;add	bx, drv.status
   539                              <1>   	;mov	byte [bx], 80h ; 'Present' flag
   540                              <1> 	; 29/08/2020
   541 00000321 C687[5E66]80        <1> 	mov	byte [bx+drv.status], 80h
   542                              <1> 	;
   543 00000326 88E8                <1> 	mov	al, ch ; last cylinder (bits 0-7)
   544 00000328 88CC                <1> 	mov	ah, cl ; 
   545 0000032A C0EC06              <1> 	shr	ah, 6  ; last cylinder (bits 8-9)
   546                              <1> 	;sub	bx, drv.status
   547 0000032D D0E3                <1> 	shl	bl, 1
   548                              <1> 	;add	bx, drv.cylinders
   549 0000032F 40                  <1> 	inc	ax  ; convert max. cyl number to cyl count
   550                              <1> 	;mov	[bx], ax
   551                              <1> 	; 08/08/2022
   552                              <1> 	; 29/08/2020
   553                              <1> 	;mov	[bx+drv.cylinders], ax
   554                              <1> 	;
   555 00000330 50                  <1> 	push	ax ; ** cylinders
   556                              <1> 	;sub	bx, drv.cylinders
   557                              <1> 	;add	bx, drv.heads
   558 00000331 30E4                <1> 	xor	ah, ah
   559 00000333 88F0                <1> 	mov	al, dh ; heads
   560 00000335 40                  <1> 	inc	ax
   561                              <1> 	;mov	[bx], ax
   562                              <1> 	; 08/08/2022
   563                              <1> 	; 29/08/2020
   564                              <1> 	;mov	[bx+drv.heads], ax
   565                              <1> 	;sub	bx, drv.heads
   566                              <1>         ;add	bx, drv.spt
   567 00000336 30ED                <1> 	xor	ch, ch
   568 00000338 80E13F              <1> 	and	cl, 3Fh	; sectors (bits 0-6)
   569                              <1> 	;mov	[bx], cx
   570                              <1>         ; 08/08/2022
   571                              <1> 	; 29/08/2020
   572                              <1> 	;mov	[bx+drv.spt], cx
   573                              <1> 	;sub	bx, drv.spt
   574 0000033B D1E3                <1> 	shl	bx, 1
   575                              <1> 	;add	bx, drv.size ; disk size (in sectors)
   576                              <1> 	; LBA size = cylinders * heads * secpertrack
   577 0000033D F7E1                <1> 	mul	cx 
   578 0000033F 89C2                <1> 	mov	dx, ax	; heads*spt
   579 00000341 58                  <1> 	pop	ax ; ** cylinders
   580                              <1> 	; 09/05/2022 (fd0&fd1 drv.size = cyls*spt*heads)
   581                              <1> 	;dec	ax ; 1 cylinder reserved (!?) ; (*)
   582 00000342 F7E2                <1> 	mul	dx ; cylinders * (heads*spt)
   583                              <1> 	;mov	[bx], ax
   584                              <1> 	;mov	[bx+2], dx
   585                              <1> 	; 29/08/2020
   586 00000344 8987[4266]          <1> 	mov	[bx+drv.size], ax
   587 00000348 8997[4466]          <1> 	mov	[bx+drv.size+2], dx
   588                              <1> 	;
   589                              <1> 	;pop	bx
   590 0000034C C3                  <1> 	retn
   591                              <1> 
   592                              <1> L16:	; 28/05/2016
   425                                  
   426                                  	; 10/11/2014
   427 0000034D FA                           	cli	; Disable interrupts (clear interrupt flag)
   428                                  		; Reset Interrupt MASK Registers (Master&Slave)
   429                                  	;mov	al, 0FFh	; mask off all interrupts
   430                                  	;out	21h, al		; on master PIC (8259)
   431                                  	;jmp 	$+2  ; (delay)
   432                                  	;out	0A1h, al	; on slave PIC (8259)
   433                                  	;
   434                                  	; Disable NMI 
   435 0000034E B080                    	mov   	al, 80h 
   436 00000350 E670                    	out   	70h, al		; set bit 7 to 1 for disabling NMI
   437                                  	;23/02/2015
   438                                  	;nop			;
   439                                  	;in	al, 71h		; read in 71h just after writing out to 70h
   440                                  				; for preventing unknown state (!?)
   441                                  	;
   442                                   	; 20/08/2014
   443                                  	; Moving the kernel 64 KB back (to physical address 0)
   444                                  	; DS = CS = 1000h
   445                                  	; 05/11/2014
   446 00000352 31C0                    	xor	ax, ax
   447 00000354 8EC0                    	mov	es, ax ; ES = 0
   448                                  	;
   449                                  	; 04/07/2016 - TRDOS 386 (64K - 128K kernel)
   450 00000356 31F6                          	xor	si, si
   451 00000358 31FF                    	xor	di, di
   452                                  	;mov	cx, 16384
   453                                  	;rep	movsd
   454                                  	; 02/12/2023
   455 0000035A B90080                  	mov	cx, 32768
   456 0000035D F3A5                    	rep	movsw
   457                                  	;
   458 0000035F 06                      	push	es ; 0
   459 00000360 68[6403]                	push	L17
   460 00000363 CB                      	retf
   461                                  L17:
   462 00000364 B90010                  	mov	cx, 1000h
   463 00000367 8EC1                    	mov	es, cx  ; 1000h 
   464 00000369 01C9                    	add	cx, cx
   465 0000036B 8ED9                    	mov	ds, cx  ; 2000h
   466                                  	;sub	si, si
   467                                  	;sub	di, di
   468                                  	;mov	cx, 16384
   469                                  	;rep	movsd
   470                                  	; 02/12/2023
   471                                  	; si = di = 0
   472 0000036D B90080                  	mov	cx, 32768
   473 00000370 F3A5                    	rep	movsw	
   474                                  
   475                                  	; Turn off the floppy drive motor
   476 00000372 BAF203                          mov     dx, 3F2h
   477 00000375 EE                              out     dx, al ; 0 ; 31/12/2013
   478                                  
   479                                  	; Enable access to memory above one megabyte
   480                                  L18:
   481 00000376 E464                    	in	al, 64h
   482 00000378 A802                    	test	al, 2
   483 0000037A 75FA                            jnz     short L18
   484 0000037C B0D1                    	mov	al, 0D1h	; Write output port
   485 0000037E E664                    	out	64h, al
   486                                  L19:
   487 00000380 E464                    	in	al, 64h
   488 00000382 A802                    	test	al, 2
   489 00000384 75FA                            jnz     short L19
   490 00000386 B0DF                    	mov	al, 0DFh	; Enable A20 line
   491 00000388 E660                    	out	60h, al
   492                                  ;L20:
   493                                  	;
   494                                  	; Load global descriptor table register
   495                                  
   496                                          ;mov     ax, cs
   497                                          ;mov     ds, ax
   498                                  
   499 0000038A 2E0F0116[A865]                  lgdt    [cs:gdtd]
   500                                  
   501 00000390 0F20C0                          mov     eax, cr0
   502                                  	;or 	al, 1	; 24/07/2023
   503 00000393 40                      	inc     ax
   504 00000394 0F22C0                  	mov     cr0, eax
   505                                  
   506                                  	; Jump to 32 bit code
   507                                  	
   508 00000397 66                      	db 66h 			; Prefix for 32-bit
   509 00000398 EA                      	db 0EAh 		; Opcode for far jump
   510 00000399 [9F030000]              	dd StartPM 		; Offset to start, 32-bit
   511                                  				; (1000h:StartPM = StartPM + 10000h)
   512 0000039D 0800                    	dw KCODE		; This is the selector for CODE32_DESCRIPTOR,
   513                                  				; assuming that StartPM resides in code32
   514                                  
   515                                  ; 20/02/2017
   516                                  
   517                                  
   518                                  [BITS 32] 
   519                                  
   520                                  StartPM:
   521                                  	; Kernel Base Address = 0 ; 30/12/2013
   522 0000039F 66B81000                	mov ax, KDATA           ; Save data segment identifier
   523 000003A3 8ED8                            mov ds, ax              ; Move a valid data segment into DS register
   524 000003A5 8EC0                           	mov es, ax              ; Move data segment into ES register
   525 000003A7 8EE0                           	mov fs, ax              ; Move data segment into FS register
   526 000003A9 8EE8                          	mov gs, ax              ; Move data segment into GS register
   527 000003AB 8ED0                            mov ss, ax              ; Move data segment into SS register
   528                                  	;mov esp, 90000h        ; Move the stack pointer to 090000h
   529                                  	; 04/12/2023 - TRDOS 386 v2.0.7
   530                                  	;mov esp, 97000h	; 3072 bytes system stack (96400h-97000h)
   531 000003AD BC00700900              	mov esp, SYSTEMSTACK_ADDR ; 97000h (max. 3072 bytes)
   532                                  
   533                                  clear_bss: ; Clear uninitialized data area
   534                                  	; 11/03/2015
   535 000003B2 31C0                    	xor	eax, eax ; 0
   536 000003B4 B9790A0000              	mov	ecx, (bss_end - bss_start)/4
   537                                  	;shr	ecx, 2 ; bss section is already aligned for double words
   538 000003B9 BF[D6790100]            	mov	edi, bss_start	
   539 000003BE F3AB                    	rep	stosd  		
   540                                  
   541                                  memory_init:
   542                                  	; Initialize memory allocation table and page tables
   543                                  	; 04/12/2023
   544                                  	; 29/11/2023
   545                                  	; 27/11/2023
   546                                  	; 23/11/2023 (TRDOS 386 v2.0.7)
   547                                  	; 24/07/2022 (TRDOS 386 v2.0.5)
   548                                  	; 18/04/2021 (TRDOS 386 v2.0.4)
   549                                  	; 16/11/2014
   550                                  	; 15/11/2014
   551                                  	; 07/11/2014
   552                                  	; 06/11/2014
   553                                  	; 05/11/2014
   554                                  	; 04/11/2014
   555                                  	; 31/10/2014 (Retro UNIX 386 v1 - Beginning) 
   556                                  	;
   557                                  ;	xor	eax, eax
   558                                  ;	xor 	ecx, ecx
   559 000003C0 B108                    	mov	cl, 8
   560 000003C2 BF00001000              	mov	edi, MEM_ALLOC_TBL	
   561 000003C7 F3AB                    	rep	stosd		   ; clear Memory Allocation Table
   562                                  				   ; for the first 1 MB memory
   563                                  	;
   564 000003C9 668B0D[34660000]        	mov	cx, [mem_1m_1k]	   ; Number of contiguous KB between
   565                                  				   ; 1 and 16 MB, max. 3C00h = 15 MB.
   566                                  	;shr	cx, 2		   ; convert 1 KB count to 4 KB count
   567                                  	; 24/07/2022
   568 000003D0 C1E902                  	shr	ecx, 2
   569 000003D3 890D[C87C0100]          	mov	[free_pages], ecx
   570 000003D9 668B15[36660000]        	mov	dx, [mem_16m_64k]  ; Number of contiguous 64 KB blocks
   571                                  				   ; between 16 MB and 4 GB.	
   572 000003E0 6609D2                  	or	dx, dx
   573 000003E3 7425                    	jz	short mi_0
   574                                  
   575                                  ; 04/12/2023
   576                                  %if 1
   577                                  	; 02/12/2023 - temporary (2816MB limit)
   578                                  	;cmp	dx, 44800 ; 0AF00h	
   579 000003E5 6681FA009F              	cmp	dx, 40704	; (2560MB limit)
   580 000003EA 7604                    	jna	short mi_x
   581                                  	;mov	dx, 44800
   582 000003EC 66BA009F                	mov	dx, 40704
   583                                  mi_x:
   584                                  %endif
   585                                  	; 23/11/2023 - temporary
   586                                  	;and	dx, 3FFFh
   587                                  
   588 000003F0 668915[36660000]        	mov	[mem_16m_64k], dx
   589                                  
   590 000003F7 6689D0                  	mov	ax, dx
   591 000003FA C1E004                  	shl	eax, 4		   ; 64 KB -> 4 KB (page count)
   592 000003FD 0105[C87C0100]          	add	[free_pages], eax
   593 00000403 0500100000              	add	eax, 4096	   ; 16 MB = 4096 pages
   594 00000408 EB06                    	jmp	short mi_1
   595                                  mi_0:
   596                                  	;mov	ax, cx
   597                                  	; 24/07/2022
   598 0000040A 89C8                    	mov	eax, ecx
   599 0000040C 66050001                	add	ax, 256		   ; add 256 pages for the first 1 MB
   600                                  	;add	eax, 256
   601                                  mi_1:			 
   602 00000410 A3[C47C0100]            	mov	[memory_size], eax ; Total available memory in pages
   603                                  				   ; 1 alloc. tbl. bit = 1 memory page
   604                                  				   ; 32 allocation bits = 32 mem. pages   
   605                                  	;
   606 00000415 05FF7F0000              	add	eax, 32767	   ; 32768 memory pages per 1 M.A.T. page 	
   607 0000041A C1E80F                  	shr	eax, 15		   ; ((32768 * x) + y) pages (y < 32768)
   608                                  				   ;  --> x + 1 M.A.T. pages, if y > 0
   609                                  				   ;  --> x M.A.T. pages, if y = 0
   610 0000041D 66A3[D87C0100]          	mov	[mat_size], ax	   ; Memory Alloc. Table Size in pages		
   611 00000423 C1E00C                  	shl	eax, 12		   ; 1 M.A.T. page = 4096 bytes
   612                                  	;			   ; Max. 32 M.A.T. pages (4 GB memory)
   613 00000426 89C3                    	mov	ebx, eax	   ; M.A.T. size in bytes
   614                                  	; Set/Calculate Kernel's Page Directory Address
   615 00000428 81C300001000            	add	ebx, MEM_ALLOC_TBL
   616 0000042E 891D[C07C0100]          	mov	[k_page_dir], ebx  ; Kernel's Page Directory address
   617                                  				   ; just after the last M.A.T. page
   618                                  	;
   619 00000434 83E804                  	sub	eax, 4		   ; convert M.A.T. size to offset value
   620 00000437 A3[D07C0100]            	mov	[last_page], eax   ; last page offset in the M.A.T.
   621                                  	;			   ; (allocation status search must be 
   622                                  				   ; stopped after here)	
   623 0000043C 31C0                    	xor	eax, eax
   624 0000043E 48                      	dec	eax		   ; FFFFFFFFh (set all bits to 1)	
   625                                  	;push	cx
   626                                  	; 18/04/2021
   627 0000043F 51                      	push	ecx
   628                                  	; ecx = 3840 ; 27/11/2023
   629                                  	; (Note: ecx < 3840 if the total memory is less than 16 MB)
   630 00000440 C1E905                  	shr	ecx, 5		   ; convert 1 - 16 MB page count to 
   631                                  				   ; count of 32 allocation bits
   632                                  	; ecx = 120 ; 27/11/2023
   633 00000443 F3AB                    	rep	stosd
   634                                  	;pop	cx
   635                                  	; 18/04/2021
   636 00000445 59                      	pop	ecx
   637 00000446 40                      	inc	eax		   ; 0	
   638 00000447 80E11F                  	and	cl, 31		   ; remain bits
   639 0000044A 7412                    	jz	short mi_4
   640 0000044C 8907                    	mov	[edi], eax	   ; reset	
   641                                  mi_2:
   642 0000044E 0FAB07                  	bts	[edi], eax	   ; 06/11/2014		
   643 00000451 FEC9                    	dec	cl
   644 00000453 7404                    	jz	short mi_3
   645 00000455 FEC0                    	inc	al
   646 00000457 EBF5                    	jmp	short mi_2
   647                                  mi_3:
   648 00000459 28C0                    	sub	al, al	   	   ; 0
   649 0000045B 83C704                  	add	edi, 4		   ; 15/11/2014
   650                                  mi_4:
   651 0000045E 6609D2                  	or	dx, dx		  ; check 16 MB to 4 GB memory space	
   652 00000461 7421                    	jz	short mi_6	  ; max. 16 MB memory, no more...
   653                                  	;	
   654 00000463 B900021000              	mov	ecx, MEM_ALLOC_TBL + 512 ; End of first 16 MB memory
   655                                  	;	
   656 00000468 29F9                    	sub	ecx, edi	  ; displacement (to end of 16 MB)
   657 0000046A 7406                    	jz	short mi_5	  ; jump if EDI points to 
   658                                  				  ;         end of first 16 MB	
   659 0000046C D1E9                    	shr	ecx, 1		  ; convert to dword count
   660 0000046E D1E9                    	shr	ecx, 1		  ; (shift 2 bits right) 
   661 00000470 F3AB                    	rep 	stosd		  ; reset all bits for reserved pages
   662                                  				  ; (memory hole under 16 MB)
   663                                  mi_5:
   664 00000472 6689D1                  	mov	cx, dx		  ; count of 64 KB memory blocks
   665 00000475 D1E9                    	shr	ecx, 1		  ; 1 alloc. dword per 128 KB memory
   666 00000477 9C                      	pushf			  ; 16/11/2014		
   667 00000478 48                      	dec	eax		  ; FFFFFFFFh (set all bits to 1)
   668 00000479 F3AB                    	rep	stosd
   669 0000047B 40                      	inc	eax		  ; 0
   670 0000047C 9D                      	popf			  ; 16/11/2014
   671 0000047D 7305                    	jnc	short mi_6
   672 0000047F 6648                    	dec	ax		  ; eax = 0000FFFFh
   673 00000481 AB                      	stosd
   674 00000482 6640                    	inc	ax		  ; 0		
   675                                  mi_6:
   676 00000484 39DF                    	cmp	edi, ebx	  ; check if EDI points to 	
   677 00000486 730A                    	jnb	short mi_7	  ; end of memory allocation table
   678                                  	;			  ; (>= MEM_ALLOC_TBL + 4906) 
   679 00000488 89D9                    	mov	ecx, ebx	  ; end of memory allocation table
   680 0000048A 29F9                    	sub	ecx, edi	  ; convert displacement/offset
   681 0000048C D1E9                    	shr	ecx, 1		  ; to dword count 	 		
   682 0000048E D1E9                    	shr	ecx, 1		  ; (shift 2 bits right) 
   683 00000490 F3AB                    	rep 	stosd		  ; reset all remain M.A.T. bits
   684                                  mi_7:
   685                                  	; Reset M.A.T. bits in M.A.T. (allocate M.A.T. pages)
   686 00000492 BA00001000              	mov	edx, MEM_ALLOC_TBL
   687                                  	;sub	ebx, edx	  ; Mem. Alloc. Tbl. size in bytes
   688                                  	;shr	ebx, 12		  ; Mem. Alloc. Tbl. size in pages	
   689 00000497 668B0D[D87C0100]        	mov	cx, [mat_size]	  ; Mem. Alloc. Tbl. size in pages
   690 0000049E 89D7                    	mov	edi, edx
   691 000004A0 C1EF0F                  	shr	edi, 15		  ; convert M.A.T. address to
   692                                  				  ; byte offset in M.A.T.
   693                                  				  ; (1 M.A.T. byte points to 
   694                                  				  ;	      32768 bytes)
   695                                  				  ; Note: MEM_ALLOC_TBL address 
   696                                  				  ; must be aligned on 128 KB 
   697                                  				  ; boundary!
   698 000004A3 01D7                    	add	edi, edx	  ; points to M.A.T.'s itself	
   699                                  	; eax = 0
   700 000004A5 290D[C87C0100]          	sub	[free_pages], ecx ; 07/11/2014
   701                                  mi_8:
   702 000004AB 0FB307                  	btr	[edi], eax	  ; clear bit 0 to bit x (1 to 31)
   703                                  	;dec	bl
   704 000004AE FEC9                    	dec	cl
   705 000004B0 7404                    	jz	short mi_9
   706 000004B2 FEC0                    	inc	al
   707 000004B4 EBF5                    	jmp	short mi_8
   708                                  mi_9:
   709                                  	;
   710                                  	; Reset Kernel's Page Dir. and Page Table bits in M.A.T.
   711                                  	;		(allocate pages for system page tables)
   712                                  
   713                                  	; edx = MEM_ALLOC_TBL
   714 000004B6 8B0D[C47C0100]          	mov	ecx, [memory_size] ; memory size in pages (PTEs)
   715 000004BC 81C1FF030000            	add	ecx, 1023	 ; round up (1024 PTEs per table)	 	
   716 000004C2 C1E90A                  	shr	ecx, 10		 ; convert memory page count to 
   717                                  				 ; page table count (PDE count)
   718                                  	;
   719 000004C5 51                      	push	ecx		 ; (**) PDE count (<= 1024)
   720                                  	;
   721 000004C6 41                      	inc	ecx		 ; +1 for kernel page directory
   722                                  	;
   723 000004C7 290D[C87C0100]          	sub	[free_pages], ecx ; 07/11/2014
   724                                  	;
   725 000004CD 8B35[C07C0100]          	mov	esi, [k_page_dir] ; Kernel's Page Directory address
   726 000004D3 C1EE0C                  	shr	esi, 12		 ; convert to page number
   727                                  mi_10:
   728 000004D6 89F0                    	mov	eax, esi	 ; allocation bit offset
   729 000004D8 89C3                    	mov	ebx, eax
   730 000004DA C1EB03                  	shr	ebx, 3		 ; convert to alloc. byte offset
   731 000004DD 80E3FC                  	and	bl, 0FCh	 ; clear bit 0 and bit 1
   732                                  				 ;   to align on dword boundary
   733 000004E0 83E01F                  	and	eax, 31		 ; set allocation bit position 
   734                                  				 ;  (bit 0 to bit 31)
   735                                  	;
   736 000004E3 01D3                    	add	ebx, edx	 ; offset in M.A.T. + M.A.T. address
   737                                  	;
   738 000004E5 0FB303                  	btr 	[ebx], eax	 ; reset relevant bit (0 to 31)
   739                                  	;
   740 000004E8 46                      	inc	esi		 ; next page table
   741 000004E9 E2EB                    	loop	mi_10		 ; allocate next kernel page table
   742                                  				 ; (ecx = page table count + 1)
   743                                  	;
   744 000004EB 59                      	pop	ecx		 ; (**) PDE count (= pg. tbl. count)
   745                                  	;
   746                                  	; Initialize Kernel Page Directory and Kernel Page Tables
   747                                  	;
   748                                  	; Initialize Kernel's Page Directory
   749 000004EC 8B3D[C07C0100]          	mov	edi, [k_page_dir]
   750 000004F2 89F8                    	mov	eax, edi
   751 000004F4 0C03                    	or	al, PDE_A_PRESENT + PDE_A_WRITE
   752                                  				; supervisor + read&write + present
   753 000004F6 89CA                    	mov	edx, ecx 	; (**) PDE count (= pg. tbl. count)	
   754                                  mi_11:
   755 000004F8 0500100000              	add	eax, 4096	; Add page size (PGSZ)
   756                                  			        ; EAX points to next page table
   757 000004FD AB                      	stosd
   758 000004FE E2F8                    	loop	mi_11
   759 00000500 29C0                    	sub	eax, eax	; Empty PDE
   760                                  	;mov	cx, 1024	; Entry count (PGSZ/4)
   761                                  	; 29/11/2023
   762 00000502 B504                    	mov	ch, 4 ; cx = 4*256 = 1024
   763 00000504 29D1                    	sub	ecx, edx
   764 00000506 7402                    	jz	short mi_12
   765 00000508 F3AB                    	rep	stosd 		; clear remain (empty) PDEs
   766                                  	;
   767                                  	; Initialization of Kernel's Page Directory is OK, here.
   768                                  mi_12:
   769                                  	; Initialize Kernel's Page Tables
   770                                  	;
   771                                  	; (EDI points to address of page table 0)
   772                                  	; eax = 0
   773 0000050A 8B0D[C47C0100]          	mov	ecx, [memory_size] ; memory size in pages
   774 00000510 89CA                    	mov	edx, ecx	; (***)
   775 00000512 B003                    	mov	al, PTE_A_PRESENT + PTE_A_WRITE
   776                                  			     ; supervisor + read&write + present 	
   777                                  mi_13:
   778 00000514 AB                      	stosd
   779 00000515 0500100000              	add	eax, 4096	
   780 0000051A E2F8                    	loop	mi_13	
   781                                  	;and	dx, 1023	; (***)
   782                                  	; 30/08/2023
   783 0000051C 81E2FF030000            	and	edx, 1023
   784 00000522 7408                    	jz	short mi_14
   785                                  	;mov	cx, 1024	
   786                                  	; 30/08/2023
   787 00000524 B504                    	mov	ch, 4 ; 4*256 = 1024
   788                                  	;sub	cx, dx		; from dx (<= 1023) to 1024
   789                                  	; 24/07/2022
   790 00000526 29D1                    	sub	ecx, edx
   791 00000528 31C0                    	xor	eax, eax
   792 0000052A F3AB                    	rep	stosd		; clear remain (empty) PTEs 
   793                                  				; of the last page table
   794                                  mi_14:
   795                                  	;  Initialization of Kernel's Page Tables is OK, here.
   796                                  	;
   797 0000052C 89F8                    	mov	eax, edi	; end of the last page table page
   798                                  			        ; (beginging of user space pages)
   799                                  
   800 0000052E C1E80F                  	shr	eax, 15		; convert to M.A.T. byte offset
   801 00000531 24FC                    	and	al, 0FCh	; clear bit 0 and bit 1 for
   802                                  				; aligning on dword boundary	
   803 00000533 A3[D47C0100]            	mov	[first_page], eax
   804 00000538 A3[CC7C0100]            	mov	[next_page], eax ; The first free page pointer
   805                                  				 ; for user programs
   806                                  				 ; (Offset in Mem. Alloc. Tbl.)	
   807                                  	;
   808                                  	; Linear/FLAT (1 to 1) memory paging for the kernel is OK, here.
   809                                  	;
   810                                  	
   811                                  	; Enable paging
   812                                  	;
   813 0000053D A1[C07C0100]                    mov     eax, [k_page_dir]
   814 00000542 0F22D8                  	mov	cr3, eax
   815 00000545 0F20C0                  	mov	eax, cr0
   816 00000548 0D00000080              	or	eax, 80000000h	; set paging bit (bit 31)
   817 0000054D 0F22C0                  	mov	cr0, eax
   818                                          ;jmp    KCODE:StartPMP
   819                                  
   820 00000550 EA                      	db 0EAh 		; Opcode for far jump
   821 00000551 [57050000]                      dd StartPMP		; 32 bit offset
   822 00000555 0800                    	dw KCODE		; kernel code segment descriptor
   823                                  
   824                                  StartPMP:
   825                                  	; 06/11//2014
   826                                  	; Clear video page 0
   827                                  	;
   828                                  	; Temporary Code
   829                                  	;
   830 00000557 B9E8030000              	mov	ecx, 80*25/2
   831 0000055C BF00800B00              	mov	edi, 0B8000h
   832                                  	; 30/01/2016
   833                                  	;xor	eax, eax	; black background, black fore color
   834 00000561 B800070007              	mov	eax, 07000700h  ; black background, light gray fore color
   835 00000566 F3AB                    	rep	stosd
   836                                  	
   837                                  	; 19/08/2014
   838                                  	; Kernel Base Address = 0
   839                                  	; It is mapped to (physically) 0 in the page table.
   840                                  	; So, here is exactly 'StartPMP' address.
   841                                  
   842                                   	; 29/01/2016 (TRDOS 386 = TRDOS v2.0)
   843 00000568 BE[6A3F0100]            	mov	esi, starting_msg
   844                                  	;; 14/08/2015 (kernel version message will appear
   845                                  	;;	       when protected mode and paging is enabled)
   846 0000056D BF00800B00              	mov	edi, 0B8000h ; 27/08/2014
   847                                  	
   848                                  	; 30/11/2020
   849                                  	; 14/11/2020 (TRDOS 386 v2.0.3)
   850                                  	;cmp	byte [vbe3], 3 ; 03h
   851                                  	;jne	short pkv_1
   852                                  	;;mov	ah, 0Bh ; Black background, light cyan forecolor
   853                                  	;; Light red TRDOS 386 version text shows VBE3 is ready !
   854                                  	;mov	ah, 0Ch ; Black background, light red forecolor
   855                                  	;jmp	short pkv_2
   856                                  ;pkv_1:
   857 00000572 B40A                    	mov	ah, 0Ah ; Black background, light green forecolor
   858                                  ;pkv_2:
   859                                  	; 20/08/2014
   860 00000574 E8BE030000              	call	printk
   861                                  
   862                                  	; 'UNIX v7/x86' source code by Robert Nordier (1999)
   863                                  	; // Set IRQ offsets
   864                                  	;
   865                                  	;  Linux (v0.12) source code by Linus Torvalds (1991)
   866                                  	;
   867                                  					;; ICW1
   868 00000579 B011                    	mov	al, 11h			; Initialization sequence
   869 0000057B E620                    	out	20h, al			; 	8259A-1
   870                                  	; jmp 	$+2
   871 0000057D E6A0                    	out	0A0h, al		; 	8259A-2
   872                                  					;; ICW2
   873 0000057F B020                    	mov	al, 20h			; Start of hardware ints (20h)
   874 00000581 E621                    	out	21h, al			;	for 8259A-1
   875                                  	; jmp 	$+2
   876 00000583 B028                    	mov	al, 28h			; Start of hardware ints (28h)
   877 00000585 E6A1                    	out	0A1h, al		; 	for 8259A-2
   878                                  					;
   879 00000587 B004                    	mov	al, 04h			;; ICW3
   880 00000589 E621                    	out	21h, al			; 	IRQ2 of 8259A-1 (master)
   881                                  	; jmp 	$+2
   882 0000058B B002                    	mov	al, 02h			; 	is 8259A-2 (slave)
   883 0000058D E6A1                    	out	0A1h, al		;
   884                                  					;; ICW4
   885 0000058F B001                    	mov	al, 01h	 		;
   886 00000591 E621                    	out	21h, al			; 	8086 mode, normal EOI	
   887                                  	; jmp 	$+2
   888 00000593 E6A1                    	out	0A1h, al		;	for both chips.
   889                                  
   890                                  	;mov	al, 0FFh	; mask off all interrupts for now
   891                                  	;out	21h, al
   892                                  	;; jmp 	$+2
   893                                  	;out	0A1h, al
   894                                  
   895                                  	; 02/04/2015
   896                                  	; 26/03/2015 System call (INT 30h) modification
   897                                  	;  DPL = 3 (Interrupt service routine can be called from user mode)			
   898                                  	;
   899                                  	;; Linux (v0.12) source code by Linus Torvalds (1991)
   900                                  	;  setup_idt:
   901                                  	;
   902                                          ;; 16/02/2015
   903                                  	;;mov     dword [DISKETTE_INT], fdc_int ; IRQ 6 handler
   904                                  	; 21/08/2014 (timer_int)
   905 00000595 BE[083C0100]            	mov	esi, ilist
   906 0000059A 8D3D[D8790100]          	lea	edi, [idt]
   907                                  	; 26/03/2015
   908 000005A0 B930000000              	mov	ecx, 48		; 48 hardware interrupts (INT 0 to INT 2Fh)
   909                                  	; 02/04/2015
   910 000005A5 BB00000800              	mov	ebx, 80000h
   911                                  rp_sidt1:
   912 000005AA AD                      	lodsd
   913 000005AB 89C2                    	mov	edx, eax
   914 000005AD 66BA008E                	mov	dx, 8E00h
   915 000005B1 6689C3                  	mov	bx, ax
   916 000005B4 89D8                    	mov	eax, ebx	; /* selector = 0x0008 = cs */
   917                                         			        ; /* interrupt gate - dpl=0, present */
   918 000005B6 AB                      	stosd	; selector & offset bits 0-15 	
   919 000005B7 89D0                    	mov	eax, edx
   920 000005B9 AB                      	stosd	; attributes & offset bits 16-23
   921 000005BA E2EE                    	loop	rp_sidt1
   922                                  	; 15/04/2016
   923                                  	; TRDOS 386 (TRDOS v2.0) /// 32 sofware interrupts ///
   924                                  	;mov	cl, 16        ; 16 software interrupts (INT 30h to INT 3Fh)
   925 000005BC B120                    	mov	cl, 32	      ; 32 software interrupts (INT 30h to INT 4Fh)	
   926                                  rp_sidt2:
   927 000005BE AD                      	lodsd
   928 000005BF 21C0                    	and	eax, eax
   929 000005C1 7413                    	jz	short rp_sidt3
   930 000005C3 89C2                    	mov	edx, eax
   931 000005C5 66BA00EE                	mov	dx, 0EE00h	; P=1b/DPL=11b/01110b
   932 000005C9 6689C3                  	mov	bx, ax
   933 000005CC 89D8                    	mov	eax, ebx	; selector & offset bits 0-15 	
   934 000005CE AB                      	stosd
   935 000005CF 89D0                    	mov	eax, edx
   936 000005D1 AB                      	stosd
   937 000005D2 E2EA                    	loop	rp_sidt2
   938 000005D4 EB16                    	jmp	short sidt_OK
   939                                  rp_sidt3:
   940 000005D6 B8[AE0D0000]            	mov	eax, ignore_int
   941 000005DB 89C2                    	mov	edx, eax
   942 000005DD 66BA00EE                	mov	dx, 0EE00h	; P=1b/DPL=11b/01110b
   943 000005E1 6689C3                  	mov	bx, ax
   944 000005E4 89D8                    	mov	eax, ebx	; selector & offset bits 0-15 	
   945                                  rp_sidt4:
   946 000005E6 AB                      	stosd
   947 000005E7 92                      	xchg	eax, edx
   948 000005E8 AB                      	stosd
   949 000005E9 92                      	xchg	edx, eax
   950 000005EA E2FA                    	loop	rp_sidt4
   951                                  sidt_OK: 
   952 000005EC 0F011D[AE650000]        	lidt 	[idtd]
   953                                  	;
   954                                  	; TSS descriptor setup ; 24/03/2015
   955 000005F3 B8[587C0100]            	mov	eax, task_state_segment
   956 000005F8 66A3[5A650000]          	mov	[gdt_tss0], ax
   957 000005FE C1C010                  	rol	eax, 16
   958 00000601 A2[5C650000]            	mov	[gdt_tss1], al
   959 00000606 8825[5F650000]          	mov	[gdt_tss2], ah
   960 0000060C 66C705[BE7C0100]68-     	mov	word [tss.IOPB], tss_end - task_state_segment
   960 00000614 00                 
   961                                  		; 
   962                                  		; IO Map Base address (When this address points
   963                                  		; to end of the TSS, CPU does not use IO port 
   964                                  		; permission bit map for RING 3 IO permissions, 
   965                                  		; access to any IO ports in ring 3 will be forbidden.)
   966                                   		;
   967                                  	;mov	[tss.esp0], esp ; TSS offset 4
   968                                  	;mov	word [tss.ss0], KDATA ; TSS offset 8 (SS)
   969 00000615 66B82800                   	mov	ax, TSS  ; It is needed when an interrupt 
   970                                  			 ; occurs (or a system call -software INT- is requested)
   971                                  			 ; while cpu running in ring 3 (in user mode).				
   972                                  			 ; (Kernel stack pointer and segment will be loaded
   973                                  			 ; from offset 4 and 8 of the TSS, by the CPU.)	 
   974 00000619 0F00D8                  	ltr	ax  ; Load task register
   975                                  	;
   976                                  esp0_set0:
   977                                  
   978                                  ; 29/11/2023 - Erdogan Tan
   979                                  ; ------------------------
   980                                  ; If we read following -disabled- stack page setting code...
   981                                  ; When the memory size >= 3GB, one of page tables conflicts with the stack page
   982                                  ; at 4MB-4096 address. So, to leave stack pointer at 90000h is better/default.
   983                                  ; (Problem may not appears for <= 2.5GB main memory but following code is also
   984                                  ; defective because kernel stack page would be seen as unallocated in the M.A.T.
   985                                  ; without by adding a memory allocation code.)
   986                                  ;
   987                                  ; 1st 4MB layout: 1MB kernel -base- reserved + max. 128 KB M.A.T. (at 100000h)
   988                                  ;                 + Kernel's page directory (4KB) -just after the M.A.T.-
   989                                  ;		  + Kernel's page tables (main memory size / 1024)
   990                                  ; Note:
   991                                  ; 1 or 2 additional kernel page table(s) may be needed for Linear Frame Buffer
   992                                  ; .. but, it/they will not have to be contiguous with other kernel page tables.
   993                                  ; ------------------------ 	 
   994                                  
   995                                  ; 27/11/2023 - TRDOS 386 v2.0.7
   996                                  %if 0
   997                                  	; 30/07/2015
   998                                  	mov 	ecx, [memory_size] ; memory size in pages
   999                                  	shl 	ecx, 12 ; convert page count to byte count
  1000                                  	cmp	ecx, CORE ; beginning of user's memory space (400000h)
  1001                                  			  ; (kernel mode virtual address)
  1002                                  	jna	short esp0_set1
  1003                                  	;
  1004                                  	; If available memory > CORE (end of the 1st 4 MB)
  1005                                  	; set stack pointer to CORE
  1006                                  	;(Because, PDE 0 is reserved for kernel space in user's page directory)
  1007                                  	;(PDE 0 points to page table of the 1st 4 MB virtual address space)
  1008                                  	mov	ecx, CORE
  1009                                  esp0_set1:
  1010                                  	mov	esp, ecx ; top of kernel stack (**tss.esp0**)
  1011                                  %endif
  1012                                  
  1013                                  esp0_set_ok:
  1014                                  	; 30/07/2015 (**tss.esp0**) 
  1015 0000061C 8925[5C7C0100]          	mov	[tss.esp0], esp	; 90000h ; 29/11/2023
  1016                                  				; <-- 97000h ; 04/12/2023 (max. 3072 bytes)
  1017 00000622 66C705[607C0100]10-             mov     word [tss.ss0], KDATA
  1017 0000062A 00                 
  1018                                  	; 14/08/2015
  1019                                  	; 10/11/2014 (Retro UNIX 386 v1 - Erdogan Tan)
  1020                                  	;
  1021                                  	;cli	; Disable interrupts (for CPU)
  1022                                  	;    (CPU will not handle hardware interrupts, except NMI!)
  1023                                  	;
  1024 0000062B 30C0                    	xor	al, al		; Enable all hardware interrupts!
  1025 0000062D E621                    	out	21h, al		; (IBM PC-AT compatibility)
  1026 0000062F EB00                    	jmp 	$+2		; (All conventional PC-AT hardware
  1027 00000631 E6A1                    	out	0A1h, al	;  interrupts will be in use.)	
  1028                                  				; (Even if related hardware component
  1029                                  				;  does not exist!)
  1030                                  	; Enable NMI 
  1031 00000633 B07F                    	mov	al, 7Fh		; Clear bit 7 to enable NMI (again)
  1032 00000635 E670                    	out  	70h, al
  1033                                  	; 23/02/2015
  1034 00000637 90                      	nop
  1035 00000638 E471                    	in	al, 71h		; read in 71h just after writing out to 70h
  1036                                  				; for preventing unknown state (!?)
  1037                                  	;
  1038                                  	; Only a NMI can occur here... (Before a 'STI' instruction)
  1039                                  	;
  1040                                  	; 02/09/2014
  1041                                  	;xor	bx, bx
  1042                                  	; 24/07/2022
  1043 0000063A 31DB                    	xor	ebx, ebx
  1044 0000063C 66BA0002                	mov	dx, 0200h	; Row 2, column 0  ; 07/03/2015
  1045 00000640 E8E81C0000              	call	_set_cpos	; 24/01/2016
  1046                                  
  1047                                  	; 14/11/2020 (TRDOS 386 v2.0.3)
  1048                                  	; Check VBE3 protected mode interface/feature(s)
  1049                                  
  1050                                  	;cmp	byte [vbe3], 3 ; 03h
  1051                                  	;jne	short display_mem_info
  1052                                  
  1053                                  	; 20/11/2020
  1054 00000645 803D[86090000]02        	cmp	byte [vbe3], 2 ; 02h
  1055 0000064C 7707                    	ja	short vbe3_pmid_chk
  1056                                  	;;jb	short display_mem_info
  1057                                  	;jb	display_mem_info ; 02/12/2020
  1058 0000064E 7220                    	jb	short jmp_display_mem_info ; 24/07/2022
  1059 00000650 E9EE010000              	jmp	check_boch_plex86_vbe
  1060                                  
  1061                                  vbe3_pmid_chk:	
  1062 00000655 B9EA7F0000              	mov	ecx, 32768 - (20+2) ; 32766 - PMInfoBlockSize
  1063 0000065A BE02000C00              	mov	esi, 0C0002h ; 1st word of the video bios rom is 0AA55h
  1064                                  	
  1065                                  chk_pmi_sign:
  1066                                  	;mov	eax, [esi] 
  1067                                  	;cmp	eax, 'PMID'
  1068                                  	; 30/11/2020
  1069                                  	;cmp	al, 'P'
  1070                                  	;jne	short chk_pmi_sign_next
  1071 0000065F 813E504D4944            	cmp	dword [esi], 'PMID'
  1072                                  	;je	short display_vbios_product_name
  1073 00000665 740E                    	je	short verify_pmib_chksum ; 15/11/2020
  1074                                  ;chk_pmi_sign_next:
  1075 00000667 46                      	inc	esi  ; inc si
  1076 00000668 E2F5                    	loop	chk_pmi_sign
  1077                                  
  1078                                  not_valid_pmib:
  1079 0000066A FE0D[86090000]          	dec	byte [vbe3] ; 2 = VBE2 compatible 
  1080                                  			    ; (vbe3 feature is defective in this vbios)
  1081                                  	;jmp	short display_mem_info
  1082                                  jmp_display_mem_info:	; 24/07/2022
  1083                                  	; 02/12/2020
  1084 00000670 E987010000              	jmp	display_mem_info
  1085                                  
  1086                                  verify_pmib_chksum:
  1087                                  	; 18/10/2023
  1088                                  	; (ATI RV370 video bios contains ZERO at Checksum offset.)
  1089 00000675 31C0                    	xor	eax, eax
  1090 00000677 384613                  	cmp	byte [esi+19], al ; 0 ; Checksum byte
  1091 0000067A 7611                    	jna	short skip_verify_pmib_chksum ; may be ATI video bios
  1092                                  	;cmp	dword [esi+16], 0C000h
  1093                                  	;	; CodeSegSel = 0C000h, InProtectMode = 0, Checksum = 0
  1094                                  	;je	short skip_verify_pmib_chksum ; may be ATI video bios
  1095                                  	; 18/10/2023
  1096                                  	; 15/11/2020
  1097                                  	;xor	eax, eax
  1098                                  	;;mov	ecx, eax 
  1099                                  	;mov	cl, 20
  1100 0000067C 66B91400                	mov	cx, 20 ; 30/11/2020
  1101 00000680 56                      	push	esi
  1102                                  pmib_sum_bytes:
  1103 00000681 AC                      	lodsb
  1104 00000682 00C4                    	add	ah, al
  1105 00000684 E2FB                    	loop	pmib_sum_bytes
  1106 00000686 5E                      	pop	esi
  1107 00000687 08E4                    	or	ah, ah
  1108 00000689 75DF                    	jnz	short not_valid_pmib ; AH must be 0
  1109                                  
  1110                                  	; 18/10/2023
  1111 0000068B 30C0                    	xor	al, al  ; eax = 0
  1112                                  
  1113                                  	; 28/02/2021
  1114                                  	; Set default (initial) truecolor bpp value to 32
  1115                                  	; (for VBE3 video bios.. because vbe3 video bioses
  1116                                  	;  use 32bpp -for truecolor modes- instead of 24bpp)
  1117                                  	; (This setting may be changed via 'sysvideo' bx=0908h)
  1118                                  
  1119                                  skip_verify_pmib_chksum: ; 18/10/2023
  1120                                  		
  1121 0000068D C605[87790100]20        	mov	byte [truecolor], 32 ; (RGB: 00RRGGBBh)
  1122                                  
  1123                                  display_vbios_product_name: ; 14/11/2020
  1124                                  
  1125                                  	; ESI points to 'PMID' (0C0000h + 'PMID' offset)
  1126                                  
  1127                                  	; 15/11/2020
  1128                                  	;mov	[pmid_addr], si	; PMInfoBlock offset
  1129                                  	;		; (in VGA bios, 0C0000h + offset)
  1130                                  	; 02/12/2020
  1131                                  	;push	esi ; * pmid_addr
  1132 00000694 89F7                    	mov	edi, esi
  1133                                  
  1134                                  	;mov	esi, [VBE3INFOBLOCK+22] ; 097E00h + 16h
  1135                                  	;		; OemVendorNamePtr (seg16:off16)
  1136 00000696 8B35067E0900            	mov	esi, [VBE3INFOBLOCK+6] ; 097E00h + 06h
  1137                                  			; OemStringPtr (seg16:off16)
  1138                                  	; 18/10/2023
  1139                                  	;xor	al, al  ; eax = 0
  1140 0000069C 6696                    	xchg	ax, si	; ax = offset, si = 0
  1141 0000069E C1EE0C                  	shr	esi, 12 ; (to convert segment to base addr)
  1142 000006A1 6601C6                  	add	si, ax  ; esi has an address < 1 MB limit
  1143                                  			; (OemVendorName is in VBE3INFOBLOCK)
  1144                                  			; Example: 
  1145                                  			; TRDOS 386 v2.0.3 VESA VBE3 protected mode
  1146                                  			; interface development reference is ...
  1147                                  			; NVIDIA GeForce FX5500 VGA BIOS -C000h:029Ch-
  1148                                  			; Version 4.34.20.54.00 -C000h:02EDh- 	  
  1149                                  			; ((OemString is 'NVIDIA'))
  1150                                  			; ((OemVendorName is 'NVIDIA Corporation'))
  1151                                  			; ((OemProductName is 'NV34 Board - p162-1nz))
  1152                                  
  1153                                  	;mov	ah, 0Eh ; Black background, yellow forecolor
  1154                                  	; 30/11/2020
  1155 000006A4 B40C                    	mov	ah, 0Ch ; Black background, light red forecolor
  1156                                  
  1157 000006A6 E8903A0000              	call	print_kmsg
  1158                                  
  1159                                  	;mov	ah, 07h
  1160                                  
  1161 000006AB BE[69790100]            	mov	esi, vesa_vbe3_bios_msg
  1162                                  	;call	print_kmsg
  1163 000006B0 E88C3A0000              	call	pkmsg_loop ; 30/11/2020
  1164                                  
  1165                                  	; 02/12/2020
  1166                                  	;pop	edi ; * pmid_addr
  1167                                  
  1168                                  ; 04/12/2023 - TRDOS 386 v2.0.7
  1169                                  %if 0
  1170                                  	; 24/07/2022
  1171                                  	; 29/11/2020
  1172                                  vbe3pminit:
  1173                                  	; 30/11/2020
  1174                                  	;cmp	byte [vbe3], 3 ; is VESA VBE3 PMI ready ?
  1175                                  	;jne	short di4
  1176                                  
  1177                                  	; Allocate 64KB contiguous (kernel) memory block
  1178                                  	xor	eax, eax
  1179                                  	mov	ecx, 65536
  1180                                  	call	allocate_memory_block
  1181                                  	;jc	short di4
  1182                                  	;jc	di0 ; 30/11/2020
  1183                                  	; 24/07/2022
  1184                                  	jnc	short vbe3pminit0
  1185                                  	jmp	di0
  1186                                  
  1187                                  vbe3pminit0:
  1188                                  	; of course this block must be in the 1st 16MB
  1189                                  	; because vbe3 pmi segments will be 16 bit segments
  1190                                  	; (80286 type segment descriptors in GDT)
  1191                                  
  1192                                  	mov	[vbe3bios_addr], eax
  1193                                  %endif
  1194                                  
  1195                                  	; 04/12/2023 - TRDOS 386 v2.0.7	; (+!*!+)
  1196                                  	; fixed PM-VBIOS address (no need to add a memory block)
  1197                                  	; in the reserved -and already allocated- area under 1MB
  1198                                  	; (purpose: to prevent page faults if memory size > 2.5GB)
  1199                                  	; ((User's page dir contains only the 1st 4MB of system mem
  1200                                  	; as PDE. So, this causes to page faults during an interrupt
  1201                                  	; in user mode, because if memory size > 2.5GB, kernel
  1202                                  	; page tables overs/passes 4MB limit and PM-VBIOS
  1203                                  	; is located after kernel page tables.))
  1204                                  vbe3pminit:
  1205 000006B5 B800000600              	mov	eax, VBE3BIOSCODE_ADDR ; 60000h	; (+!*!+)
  1206                                  
  1207                                  	; set [pmid_addr] to the new location
  1208 000006BA BE00000C00              	mov	esi, 0C0000h
  1209                                  
  1210                                  	; 30/11/2020
  1211 000006BF 29F7                    	sub	edi, esi ; izolate offset
  1212 000006C1 01C7                    	add	edi, eax ; new address
  1213 000006C3 893D[34A30100]          	mov	[pmid_addr], edi ; new 'PMID' location	
  1214                                  
  1215                                  	; Move VIDEO BIOS from 0C0000h to EAX
  1216 000006C9 B900400000              	mov	ecx, 65536/4
  1217 000006CE 89C7                    	mov	edi, eax ; 30/11/2020
  1218 000006D0 F3A5                    	rep	movsd
  1219                                  
  1220                                  	; 02/12/2020
  1221                                  	; 30/11/2020
  1222                                  	; set vbe3 segment selectors
  1223                                  
  1224                                  ; 04/12/2023 - TRDOS 386 v2.0.7	; (+!*!+)
  1225                                  %if 0
  1226                                  	; VBE3CS (VESA VBE3 video bios code segment)
  1227                                  	mov	edi, _vbe3_CS+2 ; base address bits 0..15
  1228                                  	stosw	; edi = _vbe3_CS+4
  1229                                  	ror	eax, 16
  1230                                  	mov	[edi], al ; base address, bits 16..23
  1231                                  
  1232                                  	; VBE3DS ('CodeSegSel' in PMInfoBlock)
  1233                                  	mov	edi, _vbe3_DS+4 ; base addr bits 16..23
  1234                                  	mov	[edi], al 
  1235                                  	rol	eax, 16
  1236                                  	mov	[edi-2], ax ; base address, bits 0..15
  1237                                  %endif
  1238                                  	; VBE3BDS (BIOSDataSel in PMInfoBlock)
  1239 000006D2 BF[6A650000]            	mov	edi, _vbe3_BDS+2 ; base addr bits 0..15
  1240 000006D7 B800700900              	mov	eax, VBE3BIOSDATABLOCK ; 1536 bytes
  1241 000006DC 66AB                    	stosw	; edi = _vbe3_BDS+4
  1242 000006DE C1E810                  	shr	eax, 16
  1243 000006E1 8807                    	mov	[edi], al ; base address, bits 16..23
  1244                                  
  1245                                  	; VBE3SS (1024 bytes)
  1246 000006E3 BF[92650000]            	mov	edi, _vbe3_SS+2 ; base addr bits 0..15
  1247 000006E8 B800600900              	mov	eax, VBE3STACKADDR ; size = 1024 bytes
  1248 000006ED 66AB                    	stosw	; edi = _vbe3_SS+4
  1249 000006EF C1E810                  	shr	eax, 16
  1250 000006F2 8807                    	mov	[edi], al ; base address, bits 16..23
  1251                                  
  1252                                  	; stack pointer (esp) will be set to 1020
  1253                                  	; (before VBE3 PMI call)
  1254                                  
  1255                                  	; VBE3ES (max: 2048 bytes)
  1256 000006F4 BF[9A650000]            	mov	edi, _vbe3_ES+2 ; base addr bits 0..15
  1257 000006F9 B800760900              	mov	eax, VBE3SAVERESTOREBLOCK
  1258 000006FE 66AB                    	stosw	; edi = _vbe3_ES+4
  1259 00000700 C1E810                  	shr	eax, 16
  1260 00000703 8807                    	mov	[edi], al ; base address, bits 16..23 	
  1261                                  
  1262                                  	;Note: low word of _VBE3_ES base address will be
  1263                                  	;      set -again- by VBE3 PMI caller routine 
  1264                                  
  1265                                  	; 09/12/2020
  1266                                  	;; set pmi32 (as VBE3 PMI is ready)
  1267                                  	;inc	byte [pmi32] ; = 1 
  1268                                  
  1269                                  	; KCODE16 (set PMI far return segment)
  1270 00000705 BF[A2650000]            	mov	edi, _16bit_CS+2 ; base addr bits 0..15
  1271 0000070A B8[92070000]            	mov	eax, pminit_return_addr16
  1272 0000070F 66AB                    	stosw	; edi = _16bit_CS+4
  1273 00000711 C1E810                  	shr	eax, 16
  1274 00000714 8807                    	mov	[edi], al ; base address, bits 16..23 
  1275                                  
  1276                                  	; 30/11/2020
  1277                                  	; clear mem from VBE3 BIOS data area emu block
  1278                                  	; to end of vbe3 buffers
  1279                                  
  1280                                  	; 18/10/2023 - TRDOS v2.0.7
  1281                                  	; (VBE3BIOSDATABLOCK contains a copy of the 1st
  1282                                  	; 1536 bytes of the memory, IVT, ROMBIOS DATA etc.)
  1283                                  	; ((it must not be cleared here))
  1284                                  %if 0	
  1285                                  	; 01/12/2020
  1286                                  	mov	edi, VBE3BIOSDATABLOCK ; 97000h
  1287                                  	;mov	cx, (VBE3INFOBLOCK-VBE3BIOSDATABLOCK)/4
  1288                                  	;	; ecx = 3584/4 double words
  1289                                  	; 21/12/2020
  1290                                  	mov	cx, (VBE3MODEINFOBLOCK-VBE3BIOSDATABLOCK)/4
  1291                                  		; ecx = 3072/4 double words
  1292                                  	;xor	eax, eax
  1293                                  	xor	al, al
  1294                                  	rep	stosd
  1295                                  %endif
  1296                                  	; 18/10/2023 - TRDOS v2.0.7
  1297                                  	; (VBE3BIOSDATABLOCK contains a copy of the 1st
  1298                                  	; 1536 bytes of the memory, IVT, ROMBIOS DATA etc.)
  1299                                  	; ((it must not be cleared here))
  1300 00000716 BF00760900              	mov	edi, VBE3SAVERESTOREBLOCK ; 97600h
  1301 0000071B 66B98001                	mov	cx, (VBE3MODEINFOBLOCK-VBE3SAVERESTOREBLOCK)/4
  1302                                  		 ; ecx = 1536/4 = 384 double words
  1303                                  	;xor	eax, eax
  1304 0000071F 30C0                    	xor	al, al
  1305 00000721 F3AB                    	rep	stosd	
  1306                                  
  1307                                  	; Filling PMInfoBlock selector fields
  1308 00000723 8B3D[34A30100]          	mov	edi, [pmid_addr]
  1309 00000729 66C747083800            	mov	word [edi+PMInfo.BIOSDataSel], VBE3BDS
  1310 0000072F 66C7470A4000            	mov	word [edi+PMInfo.A0000Sel], VBE3A000
  1311 00000735 66C7470C4800            	mov	word [edi+PMInfo.B0000Sel], VBE3B000
  1312 0000073B 66C7470E5000            	mov	word [edi+PMInfo.B8000Sel], VBE3B800	
  1313 00000741 66C747105800            	mov	word [edi+PMInfo.CodeSegSel], VBE3DS
  1314 00000747 C6471201                	mov	byte [edi+PMInfo.InProtectMode], 1
  1315                                  
  1316                                  	; Calculate and write checksum byte
  1317 0000074B 89FE                    	mov	esi, edi
  1318 0000074D B113                    	mov	cl, PMInfo.size - 1
  1319                                  	;xor	ah, ah
  1320                                  pmid_chksum:
  1321 0000074F AC                      	lodsb	
  1322 00000750 00C4                    	add	ah, al
  1323 00000752 E2FB                    	loop	pmid_chksum
  1324 00000754 F6DC                    	neg	ah ; 1 -> 255, 255 -> 1
  1325 00000756 8826                    	mov	[esi], ah  ; checksum
  1326                                  
  1327                                  	; far call PM initialization
  1328                                  	; (VBE3 video bios will return via 'retf')
  1329                                  
  1330 00000758 668B4706                	mov	ax, [edi+PMInfo.PMInitialize]
  1331                                  	; 30/11/2020
  1332 0000075C C1E010                  	shl	eax, 16 ; save entry address in hw
  1333                                  	; ax = 0 
  1334                                  
  1335                                  	; 02/12/2020
  1336 0000075F 68[B6070000]            	push	pminit_ok ; normal, near return address
  1337                                  
  1338                                  	; 30/11/2020
  1339                                  _VBE3PMI_fcall:
  1340                                  	; ax = function, hw of eax = entry address
  1341 00000764 9C                      	pushf	; save 32 bit flags
  1342 00000765 56                      	push	esi ; *
  1343 00000766 55                      	push	ebp ; **
  1344                                  
  1345 00000767 89E5                    	mov	ebp, esp ; save 32 bit stack pointer
  1346                                  	
  1347 00000769 89C6                    	mov	esi, eax
  1348                                  
  1349 0000076B FA                      	cli
  1350                                  
  1351                                  	; Disable interrupts (clear interrupt flag)
  1352                                  	; Reset Interrupt MASK Registers (Master&Slave)
  1353 0000076C B0FF                    	mov	al, 0FFh	; mask off all interrupts
  1354 0000076E E621                    	out	21h, al		; on master PIC (8259)
  1355 00000770 EB00                    	jmp 	$+2  ; (delay)
  1356 00000772 E6A1                    	out	0A1h, al	; on slave PIC (8259)
  1357                                  
  1358                                  	; 02/12/2020
  1359 00000774 66B86000                	mov	ax, VBE3SS
  1360 00000778 8ED0                    	mov	ss, ax
  1361                                  	
  1362 0000077A BCFC030000              	mov	esp, 1020 ; 30/11/2020
  1363                                  
  1364                                  	; 01/12/2020
  1365                                  	;lss	esp, [stack16]
  1366                                  
  1367 0000077F C1E810                  	shr	eax, 16	; now, entry address is in lw
  1368                                  
  1369                                  	; 30/11/2020 - 16 bit pm selector test (OK)
  1370                                  	; (32 bit stack push/pop & retf with 32 bit code segment)
  1371                                  	; (16 bit stack push/pop with 16 bit code segment)
  1372                                  	
  1373                                  	; return
  1374                                  	;push	KCODE16
  1375                                  	;push	0 ; 30/11/2020 (pminit_return_addr16)
  1376                                  
  1377                                  	; 30/11/2020 (16 bit stack during retf from video bios)
  1378 00000782 C7042400007000          	mov	dword [esp], KCODE16 << 16
  1379                                  				; ip = 0, cs = KCODE16 
  1380                                  	; 01/12/2020
  1381                                  	;mov	dword [VBE3STACKADDR+1020], KCODE16*65536
  1382                                  
  1383                                  	;mov	[jumpfar16], eax
  1384                                  
  1385                                  	; 02/12/2020
  1386                                  	; 30/11/2020 (32 bit stack during retf from kernel)
  1387                                  	; far jump/call via retf
  1388 00000789 6A30                    	push	VBE3CS ; VBE3 video bios's code segment
  1389 0000078B 50                      	push	eax ; PMInitialize or EntryPoint
  1390                                  
  1391                                  	;mov	ax, si ; restore function
  1392                                  	; 24/07/2022
  1393 0000078C 89F0                    	mov	eax, esi
  1394                                  
  1395                                  	; 02/12/2020
  1396 0000078E 31F6                    	xor	esi, esi ; (not necessary, it is not used)
  1397                                  	
  1398 00000790 CB                      	retf 	; far return (to 16 bit code segment)
  1399                                  
  1400                                  	; 01/12/2020
  1401                                  	;db	0EAh  ; far jump to 16 bit code segment
  1402                                  ;jumpfar16:
  1403                                  	;dd	0		
  1404                                  	;dw	VBE3CS
  1405                                  
  1406                                  ;stack16:
  1407                                  	;dd	1020
  1408                                  	;dw	VBE3SS
  1409                                  
  1410 00000791 90                      	align 2	
  1411                                  
  1412                                  pminit_return_addr16:
  1413                                  	; 02/12/2020
  1414                                  	; 30/11/2020
  1415                                  	;;db	66h 		     ; Prefix for 32-bit
  1416                                  	;db	0EAh 		     ; Opcode for far jump
  1417                                  	;dd	pminit_return_addr32 ; 32 bit Offset
  1418                                  	;dw	KCODE		     ; 32 bit code segment
  1419                                  	; 01/12/2020
  1420 00000792 EA[99070000]0800        	jmp	KCODE:pminit_return_addr32
  1421                                  
  1422                                  pminit_return_addr32:
  1423                                  	; restore 32 bit kernel selectors and 32 bit stack addr
  1424 00000799 BE10000000              	mov	esi, KDATA
  1425 0000079E 8EDE                    	mov	ds, si
  1426 000007A0 8EC6                    	mov	es, si
  1427 000007A2 8ED6                    	mov	ss, si
  1428 000007A4 89EC                    	mov	esp, ebp  ; top of stack = iretd return addr
  1429                                  
  1430 000007A6 5D                      	pop	ebp ; **
  1431 000007A7 5E                      	pop	esi ; *
  1432 000007A8 9D                      	popf	; restore 32 bit flags
  1433                                  
  1434                                  	; enable interrupts
  1435                                  
  1436 000007A9 FA                      	cli
  1437                                  
  1438                                  	; 21/12/2020
  1439 000007AA 50                      	push	eax
  1440                                  
  1441 000007AB 30C0                    	xor	al, al	   ; Enable all hardware interrupts!
  1442 000007AD E621                    	out	21h, al	   ; (IBM PC-AT compatibility)
  1443 000007AF EB00                    	jmp 	$+2	   ; (All conventional PC-AT hardware
  1444 000007B1 E6A1                    	out	0A1h, al   ;  interrupts will be in use.)	
  1445                                  			   ; (Even if related hardware component
  1446                                  			   ;  does not exist!)
  1447 000007B3 58                      	pop	eax
  1448                                  	
  1449 000007B4 FB                      	sti
  1450                                  
  1451                                  	; top of stack = return address 
  1452                                  	; ('pminit_ok' for PMinit)
  1453                                  
  1454 000007B5 C3                      	retn
  1455                                  
  1456                                  pminit_ok:
  1457                                  	; 03/12/2020
  1458                                  	; (set [pmid_addr] to PMI entry point for next calls)
  1459 000007B6 8305[34A30100]04        	add	dword [pmid_addr], PMInfo.EntryPoint ; + 4
  1460                                  
  1461                                  	; 17/01/2021
  1462                                  	; copy EDID data from temporary location to final address
  1463 000007BD 803D[D3410000]4F        	cmp	byte [edid], 4Fh
  1464 000007C4 7510                    	jne	short vbe3h_chcl
  1465                                  	;mov	ecx, 32 ; 128 bytes, 32 dwords
  1466                                  	; 24/07/2022
  1467 000007C6 31C9                    	xor	ecx, ecx
  1468 000007C8 B120                    	mov	cl, 32
  1469 000007CA BE007D0900              	mov	esi, VBE3EDIDINFOBLOCK ; 97D00h
  1470 000007CF BF[ACA20100]            	mov	edi, edid_info
  1471 000007D4 F3A5                    	rep	movsd
  1472                                  	; 17/01/2021
  1473                                  vbe3h_chcl:
  1474                                  	; 16/01/2021
  1475                                  	;; 06/12/2020
  1476                                  	;; Save video mode 03h regs/dac/bios state
  1477                                  	;
  1478                                  	;mov	ax, 4F04h ; VESA VBE Function 04h
  1479                                  	;		  ; Save/Restore State
  1480                                  	;sub	dl, dl	; 0 = return buffer size
  1481                                  	;mov	cx, 0Fh  ; ctrl/bios/dac/regs
  1482                                  	;
  1483                                  	;call	int10h_32bit_pmi
  1484                                   	;; bx = number of 64-byte blocks to hold the state buff
  1485                                  	;	
  1486                                  	;;mov	[vbe3stbufsize], bx
  1487                                  	;; 16/01/2021
  1488                                  	;or	word [vbe3stbsflags], 32768  ; set bit 15
  1489                                  	;mov	ax, bx
  1490                                  	;shl	ax, 6  ; * 64
  1491                                  	;mov	[vbestatebufsize+30], ax
  1492                                  	;
  1493                                  	;; 06/12/2020	
  1494                                  	;; check 'vbe3stbufsize' (it must be <= 32)
  1495                                  	;
  1496                                  	;cmp	bx, 32
  1497                                  	;ja	short display_mem_info ; light red forecolor
  1498                                  	;
  1499                                  	;; 16/01/2021
  1500                                  	;or	byte [vbe3stbsflags], 1 ; set bit 0
  1501                                  
  1502                                  	; 30/11/2020
  1503                                  	; Change VESA VBE3 BIOS text color in order to give
  1504                                  	; "VBE3 PMI initialization has been successed" meaning 	
  1505                                  
  1506 000007D6 BE40810B00              	mov	esi, 0B8000h + 160*2 ; row 2
  1507 000007DB 89F7                    	mov	edi, esi
  1508                                  vbe3h_chcl_next:
  1509 000007DD 66AD                    	lodsw
  1510 000007DF 80FC0C                  	cmp	ah, 0Ch	; light red forecolor
  1511 000007E2 7518                    	jne	short display_mem_info
  1512 000007E4 B40E                    	mov	ah, 0Eh ; yellow forecolor
  1513 000007E6 66AB                    	stosw
  1514 000007E8 EBF3                    	jmp	short vbe3h_chcl_next
  1515                                  
  1516                                  di5:
  1517                                  	; 18/10/2023 - TRDOS 386 v2.0.7
  1518                                  	; ATI RV370 Video BIOS (VESA VBE2)
  1519                                  	; has PMI. (as described in VESA VBE3 specification)
  1520                                  	;
  1521 000007EA FE05[86090000]          	inc	byte [vbe3]  ; [vbe3] = 2 -> 3
  1522                                  			; will be decreased to 2 again if 'PMID'
  1523                                  			; signature will not be found. 	
  1524 000007F0 E960FEFFFF              	jmp	vbe3_pmid_chk ; check for ATI Video BIOS
  1525                                  
  1526                                  di0:
  1527                                  	; 30/11/2020
  1528                                  	; Memory allocation error !
  1529 000007F5 C605[86090000]00        	mov	byte [vbe3], 0 ; disable VBE3
  1530                                  
  1531                                  display_mem_info:
  1532                                  	; 19/12/2020
  1533                                  	; temporary
  1534                                  	; 24/11/2023
  1535 000007FC 803D[86090000]02        	cmp	byte [vbe3], 2
  1536 00000803 7205                    	jb	short dmi
  1537 00000805 E84D390000              	call	default_lfb_info
  1538                                  dmi:
  1539                                  	; 06/11/2014
  1540 0000080A E8D3380000              	call	memory_info
  1541                                  	; 14/08/2015
  1542                                  	;call	getch ; 28/02/2015
  1543                                  
  1544                                  	; 07/12/2023
  1545                                  	; check EDID info for LCD monitor -screen resolution-
  1546                                  	;	for modifying VGA mode 13h CRTC parameters
  1547                                  	;	(if it is needed or not)
  1548                                  
  1549 0000080F E82D010000              	call	video_mode_13h_parms
  1550                                  
  1551                                  drv_init:
  1552 00000814 FB                      	sti	; Enable Interrupts 
  1553                                  	; 06/02/2015
  1554 00000815 8B15[3E660000]          	mov	edx, [hd0_type] ; hd0, hd1, hd2, hd3
  1555 0000081B 668B1D[3C660000]        	mov	bx, [fd0_type] ; fd0, fd1
  1556                                  	; 22/02/2015
  1557 00000822 6621DB                  	and	bx, bx
  1558 00000825 756C                    	jnz	short di1
  1559                                  	;
  1560 00000827 09D2                    	or 	edx, edx
  1561 00000829 757A                    	jnz	short di2
  1562                                  	;
  1563                                  setup_error:
  1564 0000082B BE[0E3F0100]            	mov 	esi, setup_error_msg
  1565                                  psem:	
  1566 00000830 AC                      	lodsb
  1567 00000831 08C0                    	or	al, al
  1568                                  	;jz	short haltx ; 22/02/2015
  1569 00000833 747C                    	jz	short di3
  1570 00000835 56                      	push	esi
  1571                                  	; 13/05/2016
  1572 00000836 BB07000000              	mov	ebx, 7	; Black background, 
  1573                                  			; light gray forecolor
  1574                                  			; Video page 0 (BH=0)
  1575 0000083B E8551A0000              	call	_write_tty
  1576 00000840 5E                      	pop	esi
  1577 00000841 EBED                    	jmp	short psem
  1578                                  
  1579                                  check_boch_plex86_vbe:
  1580                                  	; 20/10/2023
  1581                                  	; 18/10/2023
  1582                                  	; 20/11/2020
  1583                                  	; check Bochs/Plex86 VGABios VBE extension
  1584                                  	; (check if TRDOS 386 v2 is running on emulators)
  1585                                  	; BOCHS/QEMU/VIRTUALBOX
  1586                                  	;
  1587                                  	; ref: vbe_display_api.txt
  1588                                  
  1589                                  	; bochs/plex86 VGAbios VBE source code
  1590                                  	;  by Jeroen Janssen (2002)
  1591                                  	;  and Volker Ruppert (2003-2020)
  1592                                  
  1593                                  	; 20/10/2023
  1594                                  	; (ATI RV370 video bios has PMI support but
  1595                                  	; it is a VESA VBE2 bios. So, even if [vbe3] is set
  1596                                  	; to 3 for PMI functionality, it is better to display
  1597                                  	; VESA VBE number as it is declared by the video bios.)
  1598                                  
  1599 00000843 C605[72790100]32        	mov	byte [vbe_vnumber], "2" ; 20/10/2023
  1600                                  
  1601 0000084A 29C0                    	sub	eax, eax ; 0
  1602 0000084C 66BACE01                	mov	dx, 1CEh ; VBE_DISPI_IOPORT_INDEX
  1603 00000850 66EF                    	out	dx, ax ; VBE_DISPI_INDEX_ID register
  1604                                  	;mov	ax, 0B0C0h ; VBE_DISPI_ID0
  1605                                  	;mov	dx, 1CFh ; VBE_DISPI_IOPORT_DATA
  1606 00000852 6642                    	inc	dx
  1607                                  	;out	dx, ax
  1608                                  	;nop
  1609 00000854 66ED                    	in	ax, dx
  1610 00000856 80FCB0                  	cmp	ah, 0B0h
  1611                                  	;jne	short not_boch_qemu_vbe
  1612                                  	; 18/10/2023
  1613                                  	;jne	short display_mem_info
  1614 00000859 758F                    	jne	short di5  ; ATI VESA VBE2 bios or another
  1615                                  
  1616 0000085B 3CC5                    	cmp	al, 0C5h ; it must be 0B0C4h or 0B0C5h ..
  1617                                  	;ja	short not_boch_qemu_vbe
  1618 0000085D 779D                    	ja	short display_mem_info
  1619 0000085F 3CC0                    	cmp	al, 0C0h ; 0B0C0h to 0B0C5h .. ; Qemu
  1620                                  	;cmp	al, 0C4h ; 0BC04h or 0B0C5h is OK ; Bochs
  1621                                  	;jb	short not_boch_qemu_vbe
  1622 00000861 7299                    	jb	short display_mem_info
  1623                                  
  1624                                  	; save VESA VBE2 bios (bochs/qemu) signature
  1625                                  	; for enabling VBE2 functions in TRDOS 386 v2 kernel
  1626 00000863 A2[87090000]            	mov	[vbe2bios], al ; 0C4h or 0C5h (for BOCHS) 
  1627                                  			       ; (0C0h-0C5h for QEMU)
  1628                                  	; 20/10/2023
  1629                                  	;mov	byte [vbe_vnumber], "2"
  1630                                  
  1631                                  	; 26/11/2020
  1632                                  	; "BOCHS/QEMU/VIRTUALBOX VBE2 Video BIOS ..".
  1633 00000868 BE[54790100]            	mov	esi, vbe2_bochs_vbios ; BOCH/QEMU vbios msg
  1634 0000086D B40E                    	mov	ah, 0Eh  ; Yellow font
  1635 0000086F E8C7380000              	call	print_kmsg
  1636                                  	
  1637                                  	; this is not necessary ! (20/11/2020)
  1638 00000874 803D[87090000]C4        	cmp	byte [vbe2bios], 0C4h 
  1639                                  	;jb	display_mem_info	; (QEMU)
  1640                                  	; 02/12/2023
  1641 0000087B 720E                    	jb	short not_boch_qemu_vbe
  1642                                  
  1643                                  	; Display kernel version message if 0E9h hack port
  1644                                  	; is enabled (bochs emulator feature)
  1645 0000087D 66BAE900                	mov	dx, 0E9h ; hack port for BOCHS
  1646 00000881 BE[AD790100]            	mov	esi, kernel_version_msg
  1647                                  kvmsg_next_char:
  1648 00000886 AC                      	lodsb	
  1649 00000887 08C0                    	or	al, al
  1650 00000889 7505                    	jnz	short put_kvmsg_in_hack_port
  1651                                  not_boch_qemu_vbe:
  1652 0000088B E96CFFFFFF               	jmp	display_mem_info
  1653                                  put_kvmsg_in_hack_port:	
  1654 00000890 EE                      	out	dx, al
  1655 00000891 EBF3                    	jmp	short kvmsg_next_char
  1656                                  
  1657                                  di1:
  1658                                  	; supress 'jmp short T6'
  1659                                  	;  (activate fdc motor control code)
  1660 00000893 66C705[E8090000]90-     	mov	word [T5], 9090h ; nop
  1660 0000089B 90                 
  1661                                  	;
  1662                                  	;mov	ax, int_0Eh	; IRQ 6 handler
  1663                                  	;mov	di, 0Eh*4	; IRQ 6 vector
  1664                                  	;stosw
  1665                                  	;mov 	ax, cs
  1666                                  	;stosw
  1667                                  	;; 16/02/2015
  1668                                          ;;mov     dword [DISKETTE_INT], fdc_int ; IRQ 6 handler
  1669                                  	;
  1670 0000089C E8CF450000              	CALL	DSKETTE_SETUP	; Initialize Floppy Disks
  1671                                  	;
  1672 000008A1 09D2                    	or	edx, edx
  1673 000008A3 740C                            jz      short di3
  1674                                  di2:
  1675 000008A5 E8FC450000              	call   	DISK_SETUP	; Initialize Fixed Disks
  1676                                          ;jc	setup_error
  1677                                  	; 24/07/2022
  1678 000008AA 7305                    	jnc	short di3
  1679 000008AC E97AFFFFFF              	jmp	setup_error
  1680                                  di3:
  1681 000008B1 E800380000              	call	setup_rtc_int	; 22/05/2015 (dsectrpm.s)
  1682                                  	;
  1683 000008B6 E8E9340100              	call	display_disks ; 07/03/2015  (Temporary)
  1684                                  ;haltx:
  1685                                  	; 14/08/2015
  1686                                  	;call	getch ; 22/02/2015
  1687                                  	;sti	; Enable interrupts (for CPU)
  1688                                  ;	; 29/01/2016
  1689                                  ;	sub	ah, ah ;  read time count
  1690                                  ;	call	int1Ah
  1691                                  ;	mov	edx, ecx ; 18.2 * seconds
  1692                                  ;md_info_msg_wait1:
  1693                                  ;	; 29/01/2016
  1694                                  ;	mov	ah, 1
  1695                                  ;	call	int16h
  1696                                  ;	jz	short md_info_msg_wait2
  1697                                  ;	xor	ah, ah ; 0
  1698                                  ;       call    int16h
  1699                                  ;	jmp 	short md_info_msg_ok
  1700                                  ;md_info_msg_wait2:
  1701                                  ;	sub	ah, ah  ; read time count
  1702                                  ;	call	int1Ah
  1703                                  ;	cmp	edx, ecx ; ; 18.2 * seconds
  1704                                  ;	jna	short md_info_msg_wait3
  1705                                  ;	xchg 	edx, ecx	
  1706                                  ;md_info_msg_wait3:
  1707                                  ;	sub	ecx, edx
  1708                                  ;	cmp	ecx, 127 ; 7 seconds (18.2 * 7)
  1709                                  ;	jb	short md_info_msg_wait1		
  1710                                  ;md_info_msg_ok:
  1711                                  
  1712                                  	; 15/12/2020
  1713                                  	; set initial values of LFB parameters
  1714                                  
  1715 000008BB 803D[86090000]02        	cmp	byte [vbe3], 2
  1716 000008C2 7225                    	jb	short di4
  1717                                  
  1718                                  	;mov	ax, [def_LFB_addr]
  1719                                  	;shl	eax, 16
  1720                                  	;mov	[LFB_ADDR], eax
  1721                                  	;mov	eax, 1024*768*3
  1722                                  	;mov	[LFB_SIZE], eax
  1723                                  
  1724 000008C4 BEFE7B0900              	mov	esi, VBE3MODEINFOBLOCK - 2
  1725 000008C9 66C7061801              	mov	word [esi], 0118h ; default vbe mode
  1726                                  				  ; 1024*768, 24bpp
  1727 000008CE E88E300000              	call	set_lfbinfo_table
  1728                                  
  1729                                  	;;;
  1730                                  	; 28/11/2023
  1731                                  	; 20/10/2023 - TRDOS 386 v2.0.7
  1732 000008D3 8B35[3CA30100]          	mov	esi, [LFB_ADDR] ; LFB base address (in bytes)
  1733                                  	;mov	edx, [LFB_SIZE] ; 28/11/2023
  1734                                  	;add	edx, 4095
  1735                                  	;;;
  1736                                  	;mov	edx, ((1024*768*4)+4095)>>12 ; 28/11/2023
  1737 000008D9 BAE9070000              	mov	edx, ((1920*1080*4)+4095)>>12 ; 28/11/2023
  1738                                  	; edx = LFB size in pages
  1739                                  
  1740                                  	; 29/11/2023
  1741                                  	;mov	ebx, esi
  1742                                  	;;add	ebx, 4095 ; LFB start addr is always in page boundary
  1743                                  	;shr	ebx, 12	; convert byte address to page address
  1744 000008DE 8B0D[C47C0100]          	mov	ecx, [memory_size]
  1745                                  	;cmp	ebx, ecx
  1746                                  	;jnb	short di4 ; LFB addr >= main memory size	
  1747                                  	
  1748                                  	; (set the overlapped pages as allocated for kernel)
  1749                                  	;;;
  1750                                  	; 28/11/2023
  1751                                  	; (and set all of LFB pages in the kernel's page tables)
  1752                                  
  1753 000008E4 E850590000              	call	allocate_lfb_pages_for_kernel
  1754                                  di4:
  1755                                  	; 08/09/2016
  1756 000008E9 0F20C0                  	mov	eax, cr0
  1757 000008EC A810                    	test	al, 10h  ; Bit 4, ET (Extension Type)
  1758 000008EE 7408                    	jz	short sysinit
  1759                                  	; 27/02/2017
  1760 000008F0 FE05[7C890100]          	inc	byte [fpready]
  1761                                  	; 80387 (FPU) is ready
  1762 000008F6 DBE3                    	fninit ; Initialize Floating-Point Unit
  1763                                  sysinit:
  1764                                  	; 30/06/2015
  1765 000008F8 E84D630000              	call	sys_init
  1766                                  	;
  1767                                  	;jmp 	cpu_reset ; 22/02/2015
  1768                                  hang:  
  1769                                  	; 23/02/2015
  1770                                  	;sti			; Enable interrupts
  1771 000008FD F4                      	hlt
  1772                                  	;
  1773                                  	;nop
  1774                                  	;; 03/12/2014
  1775                                  	;; 28/08/2014
  1776                                  	;mov	ah, 11h
  1777                                  	;call	getc
  1778                                  	;jz      _c8
  1779                                  	;
  1780                                  	; 23/02/2015
  1781                                  	; 06/02/2015
  1782                                  	; 07/09/2014
  1783 000008FE 31DB                    	xor	ebx, ebx
  1784 00000900 8A1D[EE7C0100]          	mov	bl, [ptty]	; active_page
  1785 00000906 89DE                    	mov	esi, ebx
  1786                                  	;shl 	si, 1
  1787                                  	; 24/07/2022
  1788 00000908 D1E6                    	shl	esi, 1
  1789 0000090A 81C6[F07C0100]          	add	esi, ttychr
  1790 00000910 668B06                  	mov	ax, [esi]
  1791 00000913 6621C0                  	and	ax, ax
  1792                                  	;jz	short _c8
  1793 00000916 74E5                    	jz	short hang
  1794 00000918 66C7060000              	mov	word [esi], 0
  1795 0000091D 80FB03                  	cmp	bl, 3		; Video page 3
  1796                                  	;jb	short _c8
  1797 00000920 72DB                    	jb	short hang
  1798                                  	;	
  1799                                  	; 13/05/2016
  1800                                  	; 07/09/2014
  1801                                  nxtl:
  1802                                  	;push	bx
  1803                                  	; 18/04/2021
  1804 00000922 53                      	push	ebx
  1805 00000923 66BB0E00                	mov	bx, 0Eh 	; Yellow character 
  1806                                  				; on black background
  1807                                  				; bh = 0 (video page 0)
  1808                                  				; Retro UNIX 386 v1 - Video Mode 0
  1809                                  				; (PC/AT Video Mode 3 - 80x25 Alpha.)
  1810                                  	;push	ax
  1811                                  	; 18/04/2021
  1812 00000927 50                      	push	eax
  1813 00000928 E868190000              	call 	_write_tty
  1814                                  	;pop	ax
  1815                                  	; 18/04/2021
  1816 0000092D 58                      	pop	eax
  1817                                  	;pop	bx
  1818 0000092E 5B                      	pop	ebx
  1819 0000092F 3C0D                    	cmp	al, 0Dh		; carriage return (enter)
  1820                                  	;jne	short _c8
  1821 00000931 75CA                    	jne	short hang
  1822 00000933 B00A                    	mov	al, 0Ah		; next line
  1823 00000935 EBEB                    	jmp	short nxtl
  1824                                  	
  1825                                  ;_c8:
  1826                                  ;	; 25/08/2014
  1827                                  ;	cli			; Disable interrupts
  1828                                  ;	mov	al, [scounter + 1]
  1829                                  ;	and	al, al
  1830                                  ;	jnz	hang
  1831                                  ;	call	rtc_p
  1832                                  ;	jmp     hang
  1833                                  
  1834                                  	; 27/08/2014
  1835                                  	; 20/08/2014
  1836                                  printk:
  1837                                          ;mov    edi, [scr_row]
  1838                                  pkl:
  1839 00000937 AC                      	lodsb
  1840 00000938 08C0                    	or 	al, al
  1841 0000093A 7404                    	jz	short pkr
  1842 0000093C 66AB                    	stosw
  1843 0000093E EBF7                    	jmp	short pkl
  1844                                  pkr:
  1845 00000940 C3                      	retn
  1846                                  
  1847                                  ; *************************************
  1848                                  video_mode_13h_parms:
  1849                                  	; 07/12/2023 - TRDOS 386 v2.0.7
  1850                                  	; Check EDID information for LCD monitors
  1851                                  	; and change mode 13h parameters if it is required
  1852                                  	; (if resolution > 1280x1024, it is LCD/panel monitor
  1853                                  	; and Video Mode 13h parameters will be modified for 60HZ
  1854                                  	; because LCD monitors does/can not display 320x200 70HZ
  1855                                  	; standard VGA mode)
  1856                                  
  1857 00000941 803D[D3410000]4F        	cmp	byte [edid], 4Fh
  1858 00000948 753B                    	jne	short CRT_monitor	
  1859                                  
  1860 0000094A BE[ACA20100]            	mov	esi, edid_info
  1861 0000094F 83C626                  	add	esi, 26h ; EDID Standard Timing Identification
  1862 00000952 B908000000              	mov	ecx, 8
  1863                                  chk_edid:
  1864 00000957 66AD                    	lodsw
  1865 00000959 3C81                    	cmp	al, 129	; (1280/8)-31
  1866 0000095B 770E                    	ja	short LCD_monitor ; 16:9
  1867 0000095D 3C01                    	cmp	al, 1
  1868 0000095F 7624                    	jna	short CRT_monitor
  1869 00000961 E2F4                    	loop	chk_edid
  1870                                  	;jmp	short CRT_monitor
  1871 00000963 C3                      	retn
  1872                                  mode13h_crtc_60hz:
  1873 00000964 0B3EB9858FB8E2          	db	0Bh, 3Eh, 0B9h, 85h, 8Fh, 0B8h, 0E2h
  1874                                  LCD_monitor:
  1875                                  	; modify default (CRTC register) parameters for 60HZ
  1876                                  	; (320x200 letterbox type screen will appear on LCD screen)
  1877                                  	;
  1878                                  	; Note: When/While [PMI32] -protected mode video bios-
  1879                                  	;	feature is enabled -by user- for MODE 13h, internal
  1880                                  	;	(TRDOS 386) VGA -video mode setting- parameters
  1881                                  	;	will not be used (will be bypassed)
  1882                                  	;	by TRDOS 386 kernel for all standard VGA modes.
  1883                                  	;	((NVIDIA/ATI Video Bios PMI will be used.))
  1884                                  	;
  1885                                  	; 	ref: github, juj/60hz.cpp
  1886                                  	;	     https://gist.github.com/juj/
  1887                                  	;
  1888 0000096B B107                    	mov	cl, 7
  1889 0000096D BE[64090000]            	mov	esi, mode13h_crtc_60hz
  1890 00000972 BF[7A690000]            	mov	edi, vga_mode_13h+10+6 ; CRTC Registers (index: 6)
  1891 00000977 A4                      	movsb		; Vertical Total Register
  1892 00000978 A4                      	movsb		; Overflow Register
  1893 00000979 BF[84690000]            	mov	edi, vga_mode_13h+10+16 ; CRTC Regs (index: 16)
  1894 0000097E A4                      	movsb		; Vertical Retrace Start Register
  1895 0000097F A4                      	movsb		; Vertical Retrace End Register
  1896 00000980 A4                      	movsb		; Vertical Display Enable/End Register
  1897 00000981 47                      	inc	edi
  1898 00000982 47                      	inc	edi
  1899 00000983 A4                      	movsb		; Vertical Blanking Start Register
  1900 00000984 A4                      	movsb		; Vertical Blanking End Register		
  1901                                  CRT_monitor:
  1902 00000985 C3                      	retn
  1903                                  ; *************************************
  1904                                  
  1905                                  ; 14/11/2020 (TRDOS 386 v2.0.3)
  1906 00000986 00                      vbe3:	db 0  ; VESA VBE version (must be 03h)
  1907                                  	      ; for using video bios calls in protected mode
  1908                                  vbe2bios:
  1909 00000987 B0                      	db 0B0h ; 
  1910                                  ;pmid_addr: 		
  1911                                  	;dw 0  ; > 0 if 'PMID' sign is found 
  1912                                  	;     ;	('pmid' offset addr in VGA bios seg, 0C000h)
  1913                                  	;; 02/12/2020
  1914                                  	;dw 0	; 32 bit address in pmid_addr
  1915                                  		
  1916                                  ; 28/02/2017
  1917                                  ; 22/01/2017
  1918                                  ; 15/01/2017
  1919                                  ; 14/01/2017
  1920                                  ; 02/01/2017
  1921                                  ; 25/12/2016
  1922                                  ; 19/12/2016
  1923                                  ; 10/12/2016 (callback)
  1924                                  ; 06/06/2016
  1925                                  ; 23/05/2016
  1926                                  ; 22/05/2016 - TRDOS 386 (TRDOS v2.0) Timer Event Modifications
  1927                                  ; 25/07/2015
  1928                                  ; 14/05/2015 (multi tasking -time sharing- 'clock', x_timer)
  1929                                  ; 17/02/2015
  1930                                  ; 06/02/2015 (unix386.s)
  1931                                  ; 11/12/2014 - 22/12/2014 (dsectrm2.s) 
  1932                                  ;
  1933                                  ; IBM PC-XT Model 286 Source Code - BIOS2.ASM (06/10/85)
  1934                                  ;
  1935                                  ;-- HARDWARE INT  08 H - ( IRQ LEVEL 0 ) ---------------------------------------
  1936                                  ;	THIS ROUTINE HANDLES THE TIMER INTERRUPT FROM FROM CHANNEL 0 OF        :
  1937                                  ;	THE 8254 TIMER.  INPUT FREQUENCY IS 1.19318 MHZ AND THE DIVISOR        :
  1938                                  ;	IS 65536, RESULTING IN APPROXIMATELY 18.2 INTERRUPTS EVERY SECOND.     :
  1939                                  ;									       :
  1940                                  ;	THE INTERRUPT HANDLER MAINTAINS A COUNT (40:6C) OF INTERRUPTS SINCE    :
  1941                                  ;	POWER ON TIME, WHICH MAY BE USED TO ESTABLISH TIME OF DAY.	       :
  1942                                  ;	THE INTERRUPT HANDLER ALSO DECREMENTS THE MOTOR CONTROL COUNT (40:40)  :
  1943                                  ;	OF THE DISKETTE, AND WHEN IT EXPIRES, WILL TURN OFF THE 	       :
  1944                                  ;	DISKETTE MOTOR(s), AND RESET THE MOTOR RUNNING FLAGS.		       :
  1945                                  ;	THE INTERRUPT HANDLER WILL ALSO INVOKE A USER ROUTINE THROUGH	       :
  1946                                  ;	INTERRUPT 1CH AT EVERY TIME TICK.  THE USER MUST CODE A 	       :
  1947                                  ;	ROUTINE AND PLACE THE CORRECT ADDRESS IN THE VECTOR TABLE.	       :
  1948                                  ;-------------------------------------------------------------------------------
  1949                                  ;
  1950                                  
  1951                                  timer_int:	; IRQ 0
  1952                                  ;int_08h:	; Timer
  1953                                  	; 14/10/2015
  1954                                  	; Here, we are simulating system call entry (for task switch)
  1955                                  	; (If multitasking is enabled, 
  1956                                  	; 'clock' procedure may jump to 'sysrelease')
  1957                                  
  1958 00000988 1E                      	push	ds
  1959 00000989 06                      	push	es
  1960 0000098A 0FA0                    	push	fs
  1961 0000098C 0FA8                    	push	gs
  1962                                  
  1963 0000098E 60                      	pushad	; eax, ecx, edx, ebx, esp -before pushad-, ebp, esi, edi
  1964 0000098F 66B91000                	mov     cx, KDATA
  1965 00000993 8ED9                            mov     ds, cx
  1966 00000995 8EC1                            mov     es, cx
  1967 00000997 8EE1                            mov     fs, cx
  1968 00000999 8EE9                            mov     gs, cx
  1969                                  
  1970 0000099B 0F20D9                  	mov	ecx, cr3
  1971 0000099E 890D[84950100]          	mov	[cr3reg], ecx ; save current cr3 register value/content
  1972                                  
  1973                                  	; 14/01/2017
  1974 000009A4 3B0D[C07C0100]          	cmp 	ecx, [k_page_dir]
  1975 000009AA 7409                    	je	short T3
  1976                                  
  1977 000009AC 8B0D[C07C0100]          	mov	ecx, [k_page_dir]
  1978 000009B2 0F22D9                  	mov	cr3, ecx
  1979                                  T3:
  1980                                  	;sti				; INTERRUPTS BACK ON
  1981 000009B5 66FF05[407D0100]        	INC	word [TIMER_LOW]	; INCREMENT TIME
  1982 000009BC 7507                    	JNZ	short T4		; GO TO TEST_DAY
  1983 000009BE 66FF05[427D0100]        	INC	word [TIMER_HIGH]	; INCREMENT HIGH WORD OF TIME
  1984                                  T4:					; TEST_DAY
  1985 000009C5 66833D[427D0100]18      	CMP	word [TIMER_HIGH],018H	; TEST FOR COUNT EQUALING 24 HOURS
  1986 000009CD 7519                    	JNZ	short T5		; GO TO DISKETTE_CTL
  1987 000009CF 66813D[407D0100]B0-     	CMP	word [TIMER_LOW],0B0H
  1987 000009D7 00                 
  1988 000009D8 750E                    	JNZ	short T5		; GO TO DISKETTE_CTL
  1989                                  
  1990                                  ;-----	TIMER HAS GONE 24 HOURS
  1991                                  	;;SUB	AX,AX
  1992                                  	;MOV	[TIMER_HIGH],AX
  1993                                  	;MOV	[TIMER_LOW],AX
  1994 000009DA 29C0                    	sub	eax, eax
  1995 000009DC A3[407D0100]            	mov	[TIMER_LH], eax
  1996                                  	;	
  1997 000009E1 C605[447D0100]01        	MOV	byte [TIMER_OFL],1
  1998                                  
  1999                                  ;-----	TEST FOR DISKETTE TIME OUT
  2000                                  
  2001                                  T5:
  2002                                  	; 23/12/2014
  2003 000009E8 EB1D                    	jmp	short T6		; will be replaced with nop, nop
  2004                                  					; (9090h) if a floppy disk
  2005                                  					; is detected.
  2006                                  	;mov	al,[CS:MOTOR_COUNT]
  2007 000009EA A0[477D0100]            	mov	al, [MOTOR_COUNT]
  2008 000009EF FEC8                    	dec	al
  2009                                  	;mov	[CS:MOTOR_COUNT], al	; DECREMENT DISKETTE MOTOR CONTROL
  2010 000009F1 A2[477D0100]            	mov	[MOTOR_COUNT], al
  2011                                  	;mov	[ORG_MOTOR_COUNT], al
  2012 000009F6 750F                    	JNZ	short T6		; RETURN IF COUNT NOT OUT
  2013 000009F8 B0F0                    	mov 	al,0F0h
  2014                                  	;AND	[CS:MOTOR_STATUS],al 	; TURN OFF MOTOR RUNNING BITS
  2015 000009FA 2005[467D0100]          	and	[MOTOR_STATUS], al
  2016                                  	;and	[ORG_MOTOR_STATUS], al
  2017 00000A00 B00C                    	MOV	AL,0CH			; bit 3 = enable IRQ & DMA, 
  2018                                  					; bit 2 = enable controller
  2019                                  					;	1 = normal operation
  2020                                  					;	0 = reset	
  2021                                  					; bit 0, 1 = drive select
  2022                                  					; bit 4-7 = motor running bits 
  2023 00000A02 66BAF203                	MOV	DX,03F2H		; FDC CTL PORT
  2024 00000A06 EE                      	OUT	DX,AL			; TURN OFF THE MOTOR
  2025                                  T6:	
  2026                                  	;inc	word [CS:wait_count]	; 22/12/2014 (byte -> word)
  2027                                  					; TIMER TICK INTERRUPT
  2028                                  	;;inc	word [wait_count] ;;27/02/2015
  2029                                  	;INT	1CH			; TRANSFER CONTROL TO A USER ROUTINE
  2030                                  	;cli
  2031 00000A07 E85E040000              	call 	u_timer			; TRANSFER CONTROL TO A USER ROUTINE
  2032                                  	; 23/05/2016
  2033 00000A0C E842170100              	call	clock			; Multi Tasking control procedure
  2034                                  T7:
  2035                                  	; 14/10/2015
  2036 00000A11 B020                    	MOV	AL,EOI			; GET END OF INTERRUPT MASK
  2037 00000A13 FA                      	CLI				; DISABLE INTERRUPTS TILL STACK CLEARED
  2038 00000A14 E620                    	OUT	INTA00,AL		; END OF INTERRUPT TO 8259 - 1	
  2039                                  	;
  2040                                  	;;;
  2041                                  	; 21/08/2024
  2042 00000A16 803D[4D890100]FF        	cmp	byte [p_change], 0FFh ; CTRL+BREAK signature
  2043 00000A1D 7424                    	je	short T9 ; current program will be forced to sysrelease
  2044                                  	;;;
  2045                                  rtc_int_2:
  2046                                  	; 26/12/2016
  2047                                  	;mov	ecx, [cr3reg]
  2048                                  	; 13/01/2017
  2049 00000A1F 803D[EC940100]00        	cmp	byte [u.t_lock], 0  	; T_LOCK
  2050 00000A26 7730                    	ja	short timer_int_return  ; Timer Lock : 'sysrele' is needed !
  2051                                  	; 28/02/2017
  2052                                  	; We need to exit if the user's IRQ callback service is in progress!
  2053                                  	; (To prevent a conflict!)
  2054 00000A28 803D[F0940100]00        	cmp	byte [u.r_lock], 0	; R_LOCK, IRQ callback service lock !
  2055 00000A2F 7727                    	ja	short timer_int_return  ; Timer Lock : 'sysrele' is needed !	
  2056                                  	; 15/01/2017
  2057 00000A31 803D[4C890100]02        	cmp	byte [priority], 2
  2058 00000A38 733A                    	jnb	short T8  ; current process has a timer event (15/01/2017)
  2059                                  	; 22/05/2016
  2060 00000A3A 803D[4D890100]00        	cmp	byte [p_change], 0 ; in 'set_run_sequence', in 'rtc_p'
  2061 00000A41 7615                    	jna	short timer_int_return ; 23/05/2016
  2062                                  
  2063                                  	; 15/01/2017
  2064                                  	; present process must be changed with high priority process	
  2065                                  T9:		; 21/08/2024
  2066                                  	;xor	al, al
  2067 00000A43 31C0                    	xor	eax, eax ; 26/12/2016
  2068 00000A45 A2[4D890100]            	mov	[p_change], al ; 0
  2069                                  	;mov	byte [priority], 2 ; 15/01/2017 (there is a timer event)
  2070                                  
  2071 00000A4A 803D[68940100]FF        	cmp     byte [sysflg], 0FFh ; user or system space ?
  2072 00000A51 7416                    	je	short rtc_int_3     ; user space ([sysflg]= 0FFh)
  2073                                  
  2074                                  	; system space, wait for 'sysret'
  2075                                  	; to change running process 	
  2076                                  	; with high priority (event) process
  2077                                  
  2078 00000A53 A2[BC940100]            	mov	[u.quant], al ; 0
  2079                                  
  2080                                  timer_int_return: ; 23/05/2016 - jump from 'rtc_int' ('rtc_int_2')
  2081 00000A58 8B0D[84950100]          	mov 	ecx, [cr3reg] 	; previous value/content of cr3 register
  2082 00000A5E 0F22D9                   	mov	cr3, ecx	; restore cr3 register content
  2083                                  	;
  2084 00000A61 61                      	popad ; edi, esi, ebp, temp (icrement esp by 4), ebx, edx, ecx, eax
  2085                                  	;
  2086 00000A62 0FA9                    	pop	gs
  2087 00000A64 0FA1                    	pop	fs
  2088 00000A66 07                      	pop	es
  2089 00000A67 1F                      	pop	ds
  2090                                  	;
  2091 00000A68 CF                      	iretd	; return from interrupt
  2092                                  
  2093                                  rtc_int_3:
  2094 00000A69 FE05[68940100]          	inc	byte [sysflg] 	; now, we are in system space
  2095                                  	;
  2096 00000A6F E901C40000                      jmp     sysrelease ; change running process immediatelly 
  2097                                  
  2098                                  T8:
  2099                                  	; 13/01/2017 (eax -> ebx)
  2100                                  	; callback checking... (19/12/2016)
  2101 00000A74 31DB                    	xor	ebx, ebx
  2102 00000A76 871D[E8940100]          	xchg	ebx, [u.tcb] ; callback address (0 = normal return)
  2103 00000A7C 09DB                    	or	ebx, ebx
  2104 00000A7E 74D8                    	jz	short timer_int_return
  2105                                  
  2106                                  	; Set user's callback routine as return address from this interrupt
  2107                                  	; and set normal return address as return address from callback
  2108                                  	; routine!!! (19/12/2016)
  2109                                  	
  2110                                  	; 14/01/2017
  2111                                  	; 13/01/2017 - Timer Lock (T_LOCK)
  2112 00000A80 FE05[EC940100]          	inc	byte [u.t_lock]
  2113 00000A86 8A0D[68940100]          	mov	cl, [sysflg]
  2114 00000A8C 880D[ED940100]          	mov	[u.t_mode], cl 
  2115                                  
  2116 00000A92 8B2D[5C7C0100]          	mov	ebp, [tss.esp0] ; kernel stack address (for ring 0)
  2117 00000A98 83ED14                  	sub	ebp, 20		; eip, cs, eflags, esp, ss
  2118 00000A9B 892D[6C940100]           	mov	[u.sp], ebp
  2119 00000AA1 8925[70940100]          	mov	[u.usp], esp
  2120                                  
  2121                                  	;or	word [ebp+8], 200h ; 22/01/2017, force enabling interrupts
  2122                                  
  2123 00000AA7 8B44241C                	mov	eax, [esp+28] ; pushed eax
  2124 00000AAB A3[74940100]            	mov	[u.r0], eax
  2125                                  
  2126 00000AB0 E897030100              	call	wswap ; save user's registers & status
  2127                                  
  2128                                  	; software int is in ring 0 but timer int must return to ring 3
  2129                                  	; so, ring 3 return address and stack registers
  2130                                  	; (eip, cs, eflags, esp, ss) 
  2131                                  	; must be copied to timer int return
  2132                                  	; eip will be replaced by callback service routine address
  2133                                  
  2134 00000AB5 C605[68940100]FF        	mov	byte [sysflg], 0FFh ; user mode
  2135                                  
  2136                                  	; system mode (system call)
  2137                                  	;mov	ebp, [u.sp] ; EIP (u), CS (UCODE), EFLAGS (u),
  2138                                  			    ; ESP (u), SS (UDATA)
  2139                                  
  2140 00000ABC 8B4510                  	mov	eax, [ebp+16]	; SS (UDATA
  2141 00000ABF 89E6                    	mov	esi, esp
  2142 00000AC1 50                      	push	eax
  2143 00000AC2 50                      	push	eax
  2144 00000AC3 89E7                    	mov	edi, esp
  2145 00000AC5 893D[70940100]          	mov	[u.usp], edi
  2146 00000ACB B908000000              	mov	ecx, ((ESPACE/4) - 4) ; except DS, ES, FS, GS
  2147 00000AD0 F3A5                    	rep	movsd
  2148 00000AD2 B104                    	mov	cl, 4	
  2149 00000AD4 F3AB                    	rep	stosd
  2150 00000AD6 893D[6C940100]          	mov	[u.sp], edi
  2151 00000ADC 89EE                    	mov	esi, ebp
  2152 00000ADE B105                    	mov	cl, 5 ; EIP (u), CS (UCODE), EFLAGS (u), ESP (u), SS (UDATA)
  2153 00000AE0 F3A5                    	rep	movsd
  2154                                  
  2155 00000AE2 8B0D[CC940100]          	mov	ecx, [u.pgdir]
  2156 00000AE8 890D[84950100]          	mov	[cr3reg], ecx
  2157                                  
  2158                                  	; 13/01/207 (eax -> ebx)
  2159                                  	; EBX = callback routine address (virtual, not physical address!)
  2160                                  
  2161                                  	; 09/01/2017
  2162                                  	; !!! CALLBACK ROUTINE MUST BE ENDED/RETURNED WITH 'sysrele'
  2163                                  	;     system call !!!	
  2164                                  	; 25/12/2016
  2165                                  	; Callback Note: (19/12/2016)
  2166                                  	; !!! CALLBACK ROUTINE MUST BE ENDED/RETURNED WITH 'RETN' !!!
  2167                                  	;	pushf ; save flags	
  2168                                  	; 	<callback service code>
  2169                                  	; 	popf  ; restore flags
  2170                                  	; 	retn ; return to normal running address
  2171                                  	;
  2172                                  
  2173                                  	; 15/01/2017
  2174                                  	; 14/01/2017
  2175                                  	; 13/01/2017 (eax -> ebx)
  2176                                  	; 10/01/2017
  2177                                  set_callback_addr:
  2178                                  	; 09/01/2017 (**)
  2179                                  	; 02/01/2017 (*)
  2180                                  	; 25/12/2016 (*)
  2181                                  	; 19/12/2016 (TRDOS 386 feature only!)
  2182                                  	;
  2183                                  	; This routine sets return address
  2184                                  	; to start of user's interrupt
  2185                                  	; service (callback) address
  2186                                  	;; and sets callback 'retn' address to normal
  2187                                  	;; return address of user's running code! 
  2188                                  	;
  2189                                  	; INPUT:
  2190                                  	;	EBX = callback routine/service address
  2191                                  	;	      (virtual, not physical address!)	
  2192                                  	;	[u.sp] = kernel stack, points to
  2193                                  	;		 user's EIP,CS,EFLAGS,ESP,SS
  2194                                  	;		 registers.
  2195                                  	; OUTPUT:
  2196                                  	;	EIP (user) = callback (service) address
  2197                                  	;	CS (user) = UCODE
  2198                                  	;	EFLAGS (user) = flags before callback 	 
  2199                                  	;       ESP (user) = ESP-4 (user, before callback) 
  2200                                  	;	[ESP](user) = EIP (user) before callback
  2201                                  	;
  2202                                  	; Note: If CPU was in user mode while entering 
  2203                                  	;	the timer interrupt service routine,
  2204                                  	;	'IRET' will get return to callback routine
  2205                                  	;	immediately. If CPU was in system/kernel mode  
  2206                                  	;	'iret' will get return to system call and
  2207                                  	;	then, callback routine will be return address
  2208                                  	;	from system call. (User's callback/service code
  2209                                  	;	will be able to return to normal return address
  2210                                  	;	via an 'retn' at the end.) 
  2211                                  	;
  2212                                  	; Note(**): User's callback service code must be ended
  2213                                  	;	with a 'sysrele' sytstem call ! (09/01/2017)
  2214                                  	;
  2215                                  	;	For example:
  2216                                  	;
  2217                                  	;	timer_callback:
  2218                                  	;	    ...	 
  2219                                    	;	    inc	dword [time_counter]
  2220                                  	;	    ...
  2221                                  	;	    mov eax, 39 ; 'sysrele'
  2222                                  	;	    int 40h ; TRDOS 386 system call (interrupt)		
  2223                                  	;
  2224                                  	;
  2225                                  	;; Note(*): User's callback service code must preserve cpu 
  2226                                  	;;	flags if it has any instructions which changes
  2227                                  	;;	flags in the service code. (25/12/2016)
  2228                                  	;;
  2229                                  	;;	For example:
  2230                                  	;;
  2231                                  	;;	timer_callback:
  2232                                  	;;	    pushf ; save flags
  2233                                  	;;	    ; this instruction changes zero flag
  2234                                    	;;	    inc	dword [time_counter]
  2235                                  	;;	    popf ; restore flags
  2236                                  	;;	    retn ; return to normal user code
  2237                                  	;;		  (which is interrupted by the 
  2238                                  	;;		   timer interput) 	
  2239                                  	;;
  2240                                  
  2241                                  	; 15/01/2017
  2242 00000AEE 8B2D[6C940100]          	mov	ebp, [u.sp]; kernel's stack, points to EIP (user)
  2243 00000AF4 895D00                  	mov	[ebp], ebx
  2244 00000AF7 E95CFFFFFF              	jmp	timer_int_return
  2245                                  
  2246                                  	; 15/01/2017
  2247                                  	; 13/01/2017
  2248                                  	; 19/12/2016
  2249                                  	; 06/06/2016
  2250                                  	; 23/05/2016
  2251                                  	; 22/05/2016
  2252                                  	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
  2253                                  	; 26/02/2015
  2254                                  	; 07/09/2014
  2255                                  	; 25/08/2014
  2256                                  rtc_int:       ; Real Time Clock Interrupt (IRQ 8)
  2257                                  	; 22/05/2016
  2258 00000AFC 1E                      	push	ds ; ** ; 23/05/2016
  2259 00000AFD 50                      	push	eax ; *
  2260 00000AFE 66B81000                	mov	ax, KDATA
  2261 00000B02 8ED8                    	mov	ds, ax
  2262                                  	;
  2263 00000B04 8A25[3E7D0100]          	mov	ah, [RTC_2Hz] ;  2 Hz interrupt to 1 Hz function
  2264 00000B0A 80F401                  	xor	ah, 1
  2265 00000B0D 8825[3E7D0100]          	mov	[RTC_2Hz], ah ; 1 = 0.5 second, 0 = 1 second
  2266 00000B13 753B                    	jnz	short rtc_int_return ; half second
  2267                                  	; 1 second
  2268                                  rtc_int_0:
  2269                                  	; 22/05/2016
  2270 00000B15 58                      	pop	eax ; *
  2271                                  	;
  2272                                  	; 14/10/2015 ('timer_int')
  2273                                  	; Here, we are simulating system call entry (for task switch)
  2274                                  	; (If multitasking is enabled, 
  2275                                  	; 'clock' procedure may jump to 'sysrelease')
  2276                                  	;push	ds ; ** ; 23/05/2016
  2277 00000B16 06                      	push	es
  2278 00000B17 0FA0                    	push	fs
  2279 00000B19 0FA8                    	push	gs
  2280 00000B1B 60                      	pushad  ; eax, ecx, edx, ebx, esp -before pushad-, ebp, esi, edi
  2281 00000B1C 66B91000                	mov     cx, KDATA
  2282                                          ;mov    ds, cx ; 06/06/2016
  2283 00000B20 8EC1                            mov     es, cx
  2284 00000B22 8EE1                            mov     fs, cx
  2285 00000B24 8EE9                            mov     gs, cx
  2286                                  	;
  2287 00000B26 0F20D9                  	mov	ecx, cr3
  2288 00000B29 890D[84950100]          	mov	[cr3reg], ecx ; save current cr3 register value/content
  2289                                  	;
  2290 00000B2F 803D[EC940100]00        	cmp	byte [u.t_lock], 0 ; timer lock (callback) status ?
  2291 00000B36 7711                    	ja	short rtc_int_1	   ; yes
  2292                                  
  2293                                  	; 15/01/2017
  2294 00000B38 3B0D[C07C0100]          	cmp 	ecx, [k_page_dir]
  2295 00000B3E 7409                    	je	short rtc_int_1
  2296                                  
  2297 00000B40 8B0D[C07C0100]          	mov	ecx, [k_page_dir]
  2298 00000B46 0F22D9                  	mov	cr3, ecx
  2299                                  rtc_int_1:
  2300                                  	; Timer event (kernel) functions must be performed with
  2301                                  	; 1 second intervals - TRDOS 386 (TRDOS v2.0) feature ! -
  2302                                   	;	
  2303                                  	; 25/08/2014
  2304 00000B49 E818030000              	call	rtc_p  ; 19/05/2016 - major modification 
  2305                                  	
  2306                                  	; 23/05/2016
  2307 00000B4E 28E4                    	sub	ah, ah ; 0
  2308                                  	; 22/05/2016 - TRDOS 386 timer event modifications
  2309                                  rtc_int_return: ; 19/05/2016
  2310                                  	; 22/02/2015 - dsectpm.s
  2311                                  	; [ source: http://wiki.osdev.org/RTC ]
  2312                                  	; read status register C to complete procedure
  2313                                  	;(it is needed to get a next IRQ 8) 
  2314 00000B50 B00C                    	mov	al, 0Ch ; 
  2315 00000B52 E670                    	out	70h, al ; select register C
  2316 00000B54 90                      	nop
  2317 00000B55 E471                    	in	al, 71h ; just throw away contents
  2318                                  	; 22/02/2015
  2319 00000B57 B020                    	MOV	AL,EOI		; END OF INTERRUPT
  2320                                  	;CLI			; DISABLE INTERRUPTS TILL STACK CLEARED
  2321 00000B59 E6A0                    	OUT	INTB00,AL	; FOR CONTROLLER #2
  2322                                  
  2323                                  	; 23/05/2016
  2324 00000B5B B020                    	MOV	AL,EOI		; GET END OF INTERRUPT MASK
  2325 00000B5D FA                      	CLI			; DISABLE INTERRUPTS TILL STACK CLEARED
  2326 00000B5E E620                    	OUT	INTA00,AL	; END OF INTERRUPT TO 8259 - 1	
  2327                                  	;
  2328                                  	; 23/05/2016
  2329 00000B60 20E4                    	and	ah, ah
  2330                                  	;jz	rtc_int_2
  2331                                  	; 24/07/2022
  2332 00000B62 7505                    	jnz	short rtc_int_4
  2333 00000B64 E9B6FEFFFF              	jmp	rtc_int_2
  2334                                  rtc_int_4:
  2335                                  	; ah = 1 (half second)
  2336 00000B69 58                      	pop	eax ; *
  2337 00000B6A 1F                      	pop	ds  ; **
  2338 00000B6B CF                      	iretd
  2339                                  
  2340                                  ; ////////////////
  2341                                  
  2342                                  	; 28/08/2014
  2343                                  irq0:
  2344 00000B6C 6A00                            push 	dword 0
  2345 00000B6E EB48                    	jmp	short which_irq
  2346                                  irq1:
  2347 00000B70 6A01                            push 	dword 1
  2348 00000B72 EB44                    	jmp	short which_irq
  2349                                  irq2:
  2350 00000B74 6A02                            push 	dword 2
  2351 00000B76 EB40                    	jmp	short which_irq
  2352                                  irq3:
  2353                                  	; 20/11/2015
  2354                                  	; 24/10/2015
  2355 00000B78 2EFF15[DD220100]        	call	dword [cs:com2_irq3]
  2356 00000B7F 6A03                    	push 	dword 3
  2357 00000B81 EB35                    	jmp	short which_irq
  2358                                  irq4:
  2359                                  	; 20/11/2015
  2360                                  	; 24/10/2015
  2361 00000B83 2EFF15[D9220100]        	call	dword [cs:com1_irq4]
  2362 00000B8A 6A04                            push 	dword 4
  2363 00000B8C EB2A                    	jmp	short which_irq
  2364                                  irq5:
  2365 00000B8E 6A05                            push 	dword 5
  2366 00000B90 EB26                    	jmp	short which_irq
  2367                                  irq6:
  2368 00000B92 6A06                            push 	dword 6
  2369 00000B94 EB22                    	jmp	short which_irq
  2370                                  irq7:
  2371 00000B96 6A07                            push 	dword 7
  2372 00000B98 EB1E                    	jmp	short which_irq
  2373                                  irq8:
  2374 00000B9A 6A08                            push 	dword 8
  2375 00000B9C EB1A                    	jmp	short which_irq
  2376                                  irq9:
  2377 00000B9E 6A09                            push 	dword 9
  2378 00000BA0 EB16                    	jmp	short which_irq
  2379                                  irq10:
  2380 00000BA2 6A0A                            push 	dword 10
  2381 00000BA4 EB12                    	jmp	short which_irq
  2382                                  irq11:
  2383 00000BA6 6A0B                            push 	dword 11
  2384 00000BA8 EB0E                    	jmp	short which_irq
  2385                                  irq12:
  2386 00000BAA 6A0C                            push 	dword 12
  2387 00000BAC EB0A                    	jmp	short which_irq
  2388                                  irq13:
  2389 00000BAE 6A0D                            push 	dword 13
  2390 00000BB0 EB06                    	jmp	short which_irq
  2391                                  irq14:
  2392 00000BB2 6A0E                            push 	dword 14
  2393 00000BB4 EB02                    	jmp	short which_irq
  2394                                  irq15:
  2395 00000BB6 6A0F                            push 	dword 15
  2396                                  	;jmp	short which_irq
  2397                                  
  2398                                  	; 22/01/2017
  2399                                  	; 19/10/2015
  2400                                  	; 29/08/2014
  2401                                  	; 21/08/2014
  2402                                  which_irq:
  2403 00000BB8 870424                  	xchg	eax, [esp]  ; 28/08/2014
  2404 00000BBB 53                      	push	ebx
  2405 00000BBC 56                      	push	esi
  2406 00000BBD 57                      	push	edi
  2407 00000BBE 1E                      	push 	ds
  2408 00000BBF 06                      	push 	es
  2409                                  	;
  2410 00000BC0 88C3                    	mov	bl, al
  2411                                  	;
  2412 00000BC2 B810000000              	mov	eax, KDATA
  2413 00000BC7 8ED8                    	mov	ds, ax
  2414 00000BC9 8EC0                    	mov	es, ax
  2415                                  	; 19/10/2015
  2416 00000BCB FC                      	cld
  2417                                          ; 27/08/2014
  2418 00000BCC 8105[FE3B0100]A000-             add     dword [scr_row], 0A0h
  2418 00000BD4 0000               
  2419                                  	;
  2420 00000BD6 B417                    	mov	ah, 17h	; blue (1) background, 
  2421                                  			; light gray (7) forecolor
  2422 00000BD8 8B3D[FE3B0100]                  mov     edi, [scr_row]
  2423 00000BDE B049                    	mov	al, 'I'
  2424 00000BE0 66AB                    	stosw
  2425 00000BE2 B052                    	mov	al, 'R'
  2426 00000BE4 66AB                    	stosw
  2427 00000BE6 B051                    	mov	al, 'Q'
  2428 00000BE8 66AB                    	stosw
  2429 00000BEA B020                    	mov	al, ' '
  2430 00000BEC 66AB                    	stosw
  2431 00000BEE 88D8                    	mov	al, bl
  2432 00000BF0 3C0A                    	cmp	al, 10
  2433 00000BF2 7208                    	jb	short ii1
  2434 00000BF4 B031                    	mov	al, '1'
  2435 00000BF6 66AB                    	stosw
  2436 00000BF8 88D8                    	mov	al, bl
  2437 00000BFA 2C0A                    	sub	al, 10
  2438                                  ii1:
  2439 00000BFC 0430                    	add	al, '0'
  2440 00000BFE 66AB                    	stosw
  2441 00000C00 B020                    	mov	al, ' '
  2442 00000C02 66AB                    	stosw
  2443 00000C04 B021                    	mov	al, '!'
  2444 00000C06 66AB                    	stosw
  2445 00000C08 B020                    	mov	al, ' '
  2446 00000C0A 66AB                    	stosw
  2447                                  	; 23/02/2015
  2448 00000C0C 80FB07                  	cmp	bl, 7 ; check for IRQ 8 to IRQ 15 
  2449 00000C0F 7604                    	jna	ii2
  2450                                  	; 22/01/2017
  2451 00000C11 B020                    	mov	al, 20h  ; END OF INTERRUPT COMMAND TO
  2452 00000C13 E6A0                    	out	0A0h, al ; the 2nd 8259
  2453                                  ii2:
  2454 00000C15 B020                    	mov	al, 20h  ; END OF INTERRUPT COMMAND TO
  2455 00000C17 E620                    	out	20h, al ; the 2nd 8259
  2456 00000C19 E9CA010000              	jmp     iiret
  2457                                  	;
  2458                                  	; 22/08/2014
  2459                                  	;mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  2460                                  	;out	20h, al	; 8259 PORT
  2461                                  	;
  2462                                  	;pop	es
  2463                                  	;pop	ds
  2464                                  	;pop	edi
  2465                                  	;pop	esi
  2466                                  	;pop	ebx
  2467                                  	;pop 	eax
  2468                                  	;iret
  2469                                  
  2470                                  	; 02/04/2015
  2471                                  	; 25/08/2014
  2472                                  exc0:
  2473 00000C1E 6A00                            push 	dword 0
  2474 00000C20 E990000000                      jmp     cpu_except
  2475                                  exc1:
  2476 00000C25 6A01                            push 	dword 1
  2477 00000C27 E989000000                      jmp     cpu_except
  2478                                  exc2:
  2479 00000C2C 6A02                            push 	dword 2
  2480 00000C2E E982000000                      jmp     cpu_except
  2481                                  exc3:
  2482 00000C33 6A03                            push 	dword 3
  2483 00000C35 EB7E                            jmp     cpu_except
  2484                                  exc4:
  2485 00000C37 6A04                            push 	dword 4
  2486 00000C39 EB7A                            jmp     cpu_except
  2487                                  exc5:
  2488 00000C3B 6A05                            push 	dword 5
  2489 00000C3D EB76                            jmp     cpu_except
  2490                                  exc6:
  2491 00000C3F 6A06                            push 	dword 6
  2492 00000C41 EB72                            jmp     cpu_except
  2493                                  exc7:
  2494 00000C43 6A07                            push 	dword 7
  2495 00000C45 EB6E                            jmp     cpu_except
  2496                                  exc8:
  2497                                  	; [esp] = Error code
  2498 00000C47 6A08                            push 	dword 8
  2499 00000C49 EB5C                            jmp     cpu_except_en
  2500                                  exc9:
  2501 00000C4B 6A09                            push 	dword 9
  2502 00000C4D EB66                            jmp     cpu_except
  2503                                  exc10:
  2504                                  	; [esp] = Error code
  2505 00000C4F 6A0A                            push 	dword 10
  2506 00000C51 EB54                            jmp     cpu_except_en
  2507                                  exc11:
  2508                                  	; [esp] = Error code
  2509 00000C53 6A0B                            push 	dword 11
  2510 00000C55 EB50                            jmp     cpu_except_en
  2511                                  exc12:
  2512                                  	; [esp] = Error code
  2513 00000C57 6A0C                            push 	dword 12
  2514 00000C59 EB4C                            jmp     cpu_except_en
  2515                                  exc13:
  2516                                  	; [esp] = Error code
  2517 00000C5B 6A0D                            push 	dword 13
  2518 00000C5D EB48                            jmp     cpu_except_en
  2519                                  exc14:
  2520                                  	; [esp] = Error code
  2521 00000C5F 6A0E                            push 	dword 14
  2522 00000C61 EB44                    	jmp	short cpu_except_en
  2523                                  exc15:
  2524 00000C63 6A0F                            push 	dword 15
  2525 00000C65 EB4E                            jmp     cpu_except
  2526                                  exc16:
  2527 00000C67 6A10                            push 	dword 16
  2528 00000C69 EB4A                            jmp     cpu_except
  2529                                  exc17:
  2530                                  	; [esp] = Error code
  2531 00000C6B 6A11                            push 	dword 17
  2532 00000C6D EB38                    	jmp	short cpu_except_en
  2533                                  exc18:
  2534 00000C6F 6A12                            push 	dword 18
  2535 00000C71 EB42                    	jmp	short cpu_except
  2536                                  exc19:
  2537 00000C73 6A13                            push 	dword 19
  2538 00000C75 EB3E                    	jmp	short cpu_except
  2539                                  exc20:
  2540 00000C77 6A14                            push 	dword 20
  2541 00000C79 EB3A                    	jmp	short cpu_except
  2542                                  exc21:
  2543 00000C7B 6A15                            push 	dword 21
  2544 00000C7D EB36                    	jmp	short cpu_except
  2545                                  exc22:
  2546 00000C7F 6A16                            push 	dword 22
  2547 00000C81 EB32                    	jmp	short cpu_except
  2548                                  exc23:
  2549 00000C83 6A17                            push 	dword 23
  2550 00000C85 EB2E                    	jmp	short cpu_except
  2551                                  exc24:
  2552 00000C87 6A18                            push 	dword 24
  2553 00000C89 EB2A                    	jmp	short cpu_except
  2554                                  exc25:
  2555 00000C8B 6A19                            push 	dword 25
  2556 00000C8D EB26                    	jmp	short cpu_except
  2557                                  exc26:
  2558 00000C8F 6A1A                            push 	dword 26
  2559 00000C91 EB22                    	jmp	short cpu_except
  2560                                  exc27:
  2561 00000C93 6A1B                            push 	dword 27
  2562 00000C95 EB1E                    	jmp	short cpu_except
  2563                                  exc28:
  2564 00000C97 6A1C                            push 	dword 28
  2565 00000C99 EB1A                    	jmp	short cpu_except
  2566                                  exc29:
  2567 00000C9B 6A1D                            push 	dword 29
  2568 00000C9D EB16                    	jmp	short cpu_except
  2569                                  exc30:
  2570 00000C9F 6A1E                            push 	dword 30
  2571 00000CA1 EB04                    	jmp	short cpu_except_en
  2572                                  exc31:
  2573 00000CA3 6A1F                            push 	dword 31
  2574 00000CA5 EB0E                            jmp     short cpu_except
  2575                                  
  2576                                  	; 19/10/2015
  2577                                  	; 19/09/2015
  2578                                  	; 01/09/2015
  2579                                  	; 28/08/2015
  2580                                  	; 28/08/2014
  2581                                  cpu_except_en:
  2582 00000CA7 87442404                	xchg	eax, [esp+4] ; Error code
  2583 00000CAB 36A3[88960100]          	mov	[ss:error_code], eax
  2584 00000CB1 58                      	pop	eax  ; Exception number
  2585 00000CB2 870424                  	xchg	eax, [esp]
  2586                                  		; eax = eax before exception
  2587                                  		; [esp] -> exception number
  2588                                  		; [esp+4] -> EIP to return
  2589                                  	; 22/01/2017
  2590                                  	; 19/10/2015
  2591                                  	; 19/09/2015
  2592                                  	; 01/09/2015
  2593                                  	; 28/08/2015
  2594                                  	; 29/08/2014
  2595                                  	; 28/08/2014
  2596                                  	; 25/08/2014
  2597                                  	; 21/08/2014
  2598                                  cpu_except:	; CPU Exceptions
  2599 00000CB5 FC                      	cld
  2600 00000CB6 870424                  	xchg	eax, [esp] 
  2601                                  		; eax = Exception number
  2602                                  		; [esp] = eax (before exception)	
  2603 00000CB9 53                      	push	ebx
  2604 00000CBA 56                      	push	esi
  2605 00000CBB 57                      	push	edi
  2606 00000CBC 1E                      	push 	ds
  2607 00000CBD 06                      	push 	es
  2608                                  	; 28/08/2015
  2609 00000CBE 66BB1000                	mov	bx, KDATA
  2610 00000CC2 8EDB                    	mov	ds, bx
  2611 00000CC4 8EC3                    	mov	es, bx
  2612 00000CC6 0F20DB                  	mov	ebx, cr3
  2613 00000CC9 53                      	push	ebx ; (*) page directory
  2614                                  	; 19/10/2015
  2615 00000CCA FC                      	cld
  2616                                  	; 25/03/2015
  2617 00000CCB 8B1D[C07C0100]          	mov	ebx, [k_page_dir]
  2618 00000CD1 0F22DB                  	mov	cr3, ebx
  2619                                  	; 28/08/2015
  2620 00000CD4 83F80E                  	cmp	eax, 0Eh ; 14, PAGE FAULT	
  2621 00000CD7 7510                    	jne	short cpu_except_nfp
  2622 00000CD9 E8A94D0000              	call	page_fault_handler
  2623 00000CDE 21C0                    	and 	eax, eax
  2624                                  	;jz	iiretp ; 01/09/2015
  2625                                  	; 24/07/2022
  2626 00000CE0 7505                    	jnz	short cpu_except_pf
  2627 00000CE2 E9FD000000              	jmp	iiretp
  2628                                  cpu_except_pf:	; 24/07/2022
  2629 00000CE7 B00E                    	mov	al, 0Eh ; 14
  2630                                  cpu_except_nfp:
  2631                                  	; 23/08/2016
  2632 00000CE9 803D[DE670000]03        	cmp	byte [CRT_MODE], 3
  2633 00000CF0 7409                    	je	short cpu_except_mode_3
  2634 00000CF2 50                      	push	eax
  2635 00000CF3 B003                    	mov	al, 3
  2636 00000CF5 E8490E0000              	call	_set_mode
  2637 00000CFA 58                      	pop	eax
  2638                                  cpu_except_mode_3:
  2639                                  	; 02/04/2015
  2640 00000CFB BB[FD080000]            	mov	ebx, hang
  2641 00000D00 875C241C                	xchg	ebx, [esp+28]
  2642                                  		; EIP (points to instruction which faults)
  2643                                  	  	; New EIP (hang)
  2644 00000D04 891D[8C960100]          	mov	[FaultOffset], ebx
  2645 00000D0A C744242008000000        	mov	dword [esp+32], KCODE ; kernel's code segment
  2646 00000D12 814C242400020000        	or	dword [esp+36], 200h ; enable interrupts (set IF)
  2647                                  	;
  2648 00000D1A 88C4                    	mov	ah, al
  2649 00000D1C 240F                    	and	al, 0Fh
  2650 00000D1E 3C09                    	cmp	al, 9
  2651 00000D20 7602                    	jna	short h1ok
  2652 00000D22 0407                    	add	al, 'A'-':'
  2653                                  h1ok:
  2654 00000D24 C0EC04                  	shr	ah, 4
  2655 00000D27 80FC09                  	cmp	ah, 9
  2656 00000D2A 7603                    	jna	short h2ok
  2657 00000D2C 80C407                  	add	ah, 'A'-':'
  2658                                  h2ok:	
  2659 00000D2F 86C4                    	xchg 	ah, al	
  2660 00000D31 66053030                	add	ax, '00'
  2661 00000D35 66A3[583E0100]          	mov	[excnstr], ax
  2662                                  	;
  2663                                  	; 29/08/2014
  2664 00000D3B A1[8C960100]            	mov	eax, [FaultOffset]
  2665 00000D40 51                      	push	ecx
  2666 00000D41 52                      	push	edx
  2667 00000D42 89E3                    	mov	ebx, esp
  2668                                  	; 28/08/2015
  2669 00000D44 B910000000              	mov	ecx, 16	  ; divisor value to convert binary number
  2670                                  			  ; to hexadecimal string
  2671                                  	;mov	ecx, 10	    ; divisor to convert	
  2672                                  			    ; binary number to decimal string
  2673                                  b2d1:
  2674 00000D49 31D2                    	xor	edx, edx
  2675 00000D4B F7F1                    	div	ecx
  2676                                  	;push	dx
  2677                                  	; 18/04/2021
  2678 00000D4D 52                      	push	edx
  2679 00000D4E 39C8                    	cmp	eax, ecx
  2680 00000D50 73F7                    	jnb	short b2d1
  2681 00000D52 BF[633E0100]            	mov	edi, EIPstr ; EIP value
  2682                                  			    ; points to instruction which faults	
  2683                                  	; 28/08/2015
  2684 00000D57 89C2                    	mov	edx, eax
  2685                                  b2d2:
  2686                                  	;add	al, '0'
  2687 00000D59 8A82[C3410000]          	mov	al, [edx+hexchrs]
  2688 00000D5F AA                      	stosb		    ; write hexadecimal digit to its place	
  2689 00000D60 39E3                    	cmp	ebx, esp
  2690 00000D62 7605                    	jna	short b2d3
  2691                                  	;pop	ax
  2692                                  	; 18/04/2021
  2693 00000D64 58                      	pop	eax
  2694 00000D65 88C2                    	mov	dl, al
  2695 00000D67 EBF0                    	jmp	short b2d2
  2696                                  b2d3:
  2697 00000D69 B068                    	mov 	al, 'h' ; 28/08/2015
  2698 00000D6B AA                      	stosb
  2699 00000D6C B020                    	mov	al, 20h	    ; space
  2700 00000D6E AA                      	stosb
  2701 00000D6F 30C0                    	xor	al, al	    ; to do it an ASCIIZ string	
  2702 00000D71 AA                      	stosb
  2703                                  	;
  2704 00000D72 5A                      	pop	edx
  2705 00000D73 59                      	pop	ecx
  2706                                  	;
  2707 00000D74 B44F                    	mov	ah, 4Fh	; red (4) background, 
  2708                                  			; white (F) forecolor
  2709 00000D76 BE[483E0100]            	mov	esi, exc_msg ; message offset
  2710                                  	;
  2711                                  	; 20/01/2017 (!cpu exception!)
  2712                                  	;
  2713 00000D7B 8105[FE3B0100]A000-             add	dword [scr_row], 0A0h
  2713 00000D83 0000               
  2714 00000D85 8B3D[FE3B0100]                  mov	edi, [scr_row]
  2715                                  	;	
  2716 00000D8B C605[68940100]00        	mov	byte [sysflg], 0  ; system mode
  2717 00000D92 FB                              sti
  2718                                  	;
  2719 00000D93 E89FFBFFFF              	call 	printk
  2720                                  	;
  2721 00000D98 B410                    	mov	ah, 10h
  2722 00000D9A E87D010000              	call	int16h ; getc
  2723                                  	;
  2724 00000D9F B003                    	mov	al, 3
  2725 00000DA1 E89D0D0000              	call	_set_mode
  2726                                  	;
  2727                                  	;mov	eax, 1
  2728                                  	; 30/11/2023
  2729 00000DA6 31C0                    	xor	eax, eax
  2730 00000DA8 40                      	inc	eax
  2731                                  	; eax = 1	
  2732 00000DA9 E9E4C10000              	jmp	sysexit ; terminate process !!!
  2733                                  	
  2734                                  	; 22/01/2017
  2735                                  	; 18/04/2016
  2736                                  	; 28/08/2015
  2737                                  	; 23/02/2015
  2738                                  	; 20/08/2014
  2739                                  ignore_int:
  2740 00000DAE 50                      	push	eax
  2741 00000DAF 53                      	push	ebx ; 23/02/2015
  2742 00000DB0 56                      	push	esi
  2743 00000DB1 57                      	push	edi
  2744 00000DB2 1E                      	push 	ds
  2745 00000DB3 06                      	push 	es
  2746                                  	; 18/04/2016
  2747 00000DB4 66B81000                	mov	ax, KDATA
  2748 00000DB8 8ED8                    	mov	ds, ax
  2749 00000DBA 8EC0                    	mov	es, ax
  2750                                  	; 28/08/2015
  2751 00000DBC 0F20D8                  	mov	eax, cr3
  2752 00000DBF 50                      	push	eax ; (*) page directory
  2753                                  	;
  2754 00000DC0 B467                    	mov	ah, 67h	; brown (6) background, 
  2755                                  			; light gray (7) forecolor
  2756 00000DC2 BE[103D0100]            	mov	esi, int_msg ; message offset
  2757                                  piemsg:
  2758                                          ; 27/08/2014
  2759 00000DC7 8105[FE3B0100]A000-             add     dword [scr_row], 0A0h
  2759 00000DCF 0000               
  2760 00000DD1 8B3D[FE3B0100]                  mov     edi, [scr_row]
  2761                                          ;
  2762 00000DD7 E85BFBFFFF              	call 	printk
  2763                                  	;
  2764                                  	; 23/02/2015
  2765 00000DDC B020                    	mov	al, 20h  ; END OF INTERRUPT COMMAND TO
  2766 00000DDE E6A0                    	out	0A0h, al ; the 2nd 8259
  2767                                  	; 22/08/2014
  2768 00000DE0 B020                    	mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
  2769 00000DE2 E620                    	out	20h, al	; 8259 PORT
  2770                                  iiretp: 
  2771                                  	; 22/01/2017
  2772                                  	; 01/09/2015
  2773                                  	; 28/08/2015
  2774 00000DE4 58                      	pop	eax ; (*) page directory
  2775 00000DE5 0F22D8                  	mov	cr3, eax
  2776                                  iiret:
  2777 00000DE8 07                      	pop	es
  2778 00000DE9 1F                      	pop	ds
  2779 00000DEA 5F                      	pop	edi
  2780 00000DEB 5E                      	pop	esi
  2781 00000DEC 5B                      	pop	ebx ; 29/08/2014
  2782 00000DED 58                      	pop 	eax
  2783 00000DEE CF                      	iretd
  2784                                  
  2785                                  	; 23/05/2016
  2786                                  	; 22/08/2014
  2787                                  	; IBM PC/AT BIOS source code ----- 10/06/85 (bios.asm)
  2788                                  	; (INT 1Ah)
  2789                                  	;; Linux (v0.12) source code (main.c) by Linus Torvalds (1991)
  2790                                  time_of_day:
  2791 00000DEF E8E3560000              	call	UPD_IPR			; WAIT TILL UPDATE NOT IN PROGRESS
  2792 00000DF4 726F                            jc      short time_of_day_retn ; 23/05/2016
  2793 00000DF6 B000                    	mov	al, CMOS_SECONDS
  2794 00000DF8 E810570000              	call	CMOS_READ
  2795 00000DFD A2[307D0100]            	mov	[time_seconds], al 
  2796 00000E02 B002                    	mov	al, CMOS_MINUTES
  2797 00000E04 E804570000              	call	CMOS_READ
  2798 00000E09 A2[317D0100]            	mov	[time_minutes], al 
  2799 00000E0E B004                    	mov	al, CMOS_HOURS
  2800 00000E10 E8F8560000              	call	CMOS_READ
  2801 00000E15 A2[327D0100]                    mov     [time_hours], al
  2802 00000E1A B006                    	mov	al, CMOS_DAY_WEEK 
  2803 00000E1C E8EC560000              	call	CMOS_READ
  2804 00000E21 A2[337D0100]            	mov	[date_wday], al
  2805 00000E26 B007                     	mov	al, CMOS_DAY_MONTH
  2806 00000E28 E8E0560000              	call	CMOS_READ
  2807 00000E2D A2[347D0100]            	mov	[date_day], al
  2808 00000E32 B008                    	mov	al, CMOS_MONTH
  2809 00000E34 E8D4560000              	call	CMOS_READ
  2810 00000E39 A2[357D0100]            	mov	[date_month], al
  2811 00000E3E B009                    	mov	al, CMOS_YEAR
  2812 00000E40 E8C8560000              	call	CMOS_READ
  2813 00000E45 A2[367D0100]            	mov	[date_year], al
  2814 00000E4A B032                    	mov	al, CMOS_CENTURY
  2815 00000E4C E8BC560000              	call	CMOS_READ
  2816 00000E51 A2[377D0100]            	mov	[date_century], al
  2817                                  	;
  2818 00000E56 B000                    	mov	al, CMOS_SECONDS
  2819 00000E58 E8B0560000              	call 	CMOS_READ
  2820 00000E5D 3A05[307D0100]          	cmp	al, [time_seconds]
  2821 00000E63 758A                    	jne	short time_of_day
  2822                                  
  2823                                  time_of_day_retn:
  2824 00000E65 C3                      	retn
  2825                                  
  2826                                  	; 15/01/2017
  2827                                  	; 10/06/2016
  2828                                  	; 07/06/2016
  2829                                  	; 06/06/2016
  2830                                  	; 23/05/2016
  2831                                  rtc_p:
  2832 00000E66 B101                    	mov	cl, 1 ; 15/01/2017
  2833 00000E68 EB02                    	jmp	short rtc_p0
  2834                                  u_timer: 
  2835                                  	; Timer Events with 18.2 Hz Timer Ticks
  2836                                  	; (and also timer events with RTC seconds)
  2837 00000E6A 28C9                    	sub	cl, cl ; mov cl, 0 ; 15/01/2017
  2838                                  rtc_p0:
  2839                                  	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
  2840                                  	; Major Modification:
  2841                                  	; Check and Perform Timer Events (for RTC)
  2842                                  	; 25/08/2014 - 07/09/2014
  2843                                  	; Retro UNIX 386 v1:
  2844                                   	; Print Real Time Clock content
  2845                                  	
  2846                                  	; 15/01/2017
  2847 00000E6C 880D[4C890100]          	mov	byte [priority], cl ; 0 or 1 (not 2)
  2848 00000E72 8A2D[4F890100]          	mov	ch, [timer_events]
  2849 00000E78 20ED                    	and	ch, ch
  2850 00000E7A 7420                    	jz	short rtc_p3
  2851                                  
  2852 00000E7C BE[88950100]            	mov	esi, timer_set  ; beginning address of
  2853                                  				; timer events space
  2854                                  rtc_p1:
  2855 00000E81 8B06                    	mov	eax, [esi]	
  2856 00000E83 20C0                    	and	al, al ; 0 = free, >0 = process no.
  2857 00000E85 7416                    	jz	short rtc_p4
  2858                                  	;
  2859 00000E87 C1C810                  	ror	eax, 16
  2860                                  	; ah = response value, al = interrupt type
  2861                                  	; 15/01/2017
  2862                                  	; cl = interrupt source
  2863                                  	;       1 = RTC, 0 = PIT  	 	
  2864 00000E8A 38C8                    	cmp	al, cl 
  2865 00000E8C 750A                    	jne	short rtc_p2 ; not as requested or undefined !
  2866 00000E8E 3C01                    	cmp	al, 1 ; 1 ; RTC interrupt ?
  2867 00000E90 7410                    	je	short rtc_p5 ; yes, check for response
  2868                                  	; 06/06/2016 - 18.2 Hz Timer Ticks
  2869 00000E92 836E080A                	sub	dword [esi+8], 10 ; 1 tick = 10
  2870 00000E96 7613                    	jna	short rtc_p6  ; continue for responding
  2871                                  rtc_p2:
  2872                                  	; 15/01/2017 (cl -> ch)
  2873                                  	; 07/06/2016
  2874 00000E98 FECD                    	dec	ch    ; remain count of timer events	
  2875 00000E9A 7501                    	jnz	short rtc_p4
  2876                                  rtc_p3:	 
  2877 00000E9C C3                      	retn
  2878                                  rtc_p4:	
  2879                                  	;cmp	esi, timer_set + 240 ; 15*16 (last event)
  2880                                  	;jnb	short rtc_p3 ; end of timer event space
  2881 00000E9D 83C610                  	add	esi, 16 ; next timer event
  2882 00000EA0 EBDF                    	jmp	short rtc_p1
  2883                                  rtc_p5:	 
  2884                                  	; current timer count ; 06/06/2016 (182)
  2885 00000EA2 816E08B6000000          	sub	dword [esi+8], 182 ; 1 second (10*18.2)
  2886 00000EA9 77ED                    	ja	short rtc_p2  ; check for the next 
  2887                                  rtc_p6:	
  2888                                  	; it is the time of response! 
  2889 00000EAB 8B5E04                  	mov	ebx, [esi+4] ; set (count limit) value
  2890 00000EAE 895E08                  	mov	[esi+8], ebx ; reset count down value
  2891                                  			     ; to count limit
  2892                                  	; 19/12/2016
  2893                                  	; 10/12/2016 - timer callback modification
  2894 00000EB1 8B7E0C                  	mov	edi, [esi+12] ; response (or callback) address	
  2895 00000EB4 807E0100                	cmp	byte [esi+1], 0 ; >0 = callback
  2896 00000EB8 762A                    	jna	short rtc_p8
  2897                                  
  2898                                  	; timer callback !
  2899 00000EBA 0FB61E                  	movzx	ebx, byte [esi] ; process number (>0)
  2900 00000EBD 89D8                    	mov	eax, ebx
  2901 00000EBF C0E302                  	shl	bl, 2 ; *4
  2902 00000EC2 89BB[04940100]          	mov	[ebx+p.tcb-4], edi ; user's callback service addr
  2903 00000EC8 3A05[C5940100]          	cmp	al, [u.uno]
  2904 00000ECE 7521                    	jne	short rtc_p9
  2905 00000ED0 893D[E8940100]          	mov	[u.tcb], edi
  2906                                  rtc_p7:
  2907                                  	; 15/01/2017
  2908 00000ED6 B002                    	mov	al, 2
  2909 00000ED8 A2[4C890100]            	mov	[priority], al ; 2
  2910                                  	; 10/01/2017
  2911                                  	;mov	byte [u.pri], 2
  2912 00000EDD A2[BE940100]            	mov	[u.pri], al ; 2
  2913 00000EE2 EBB4                    	jmp	short rtc_p2
  2914                                  rtc_p8:
  2915                                  	; response address is physical address of
  2916                                  	; the program's response (signal return) byte
  2917                                  	; 06/06/2016
  2918                                  	;mov	edi, [esi+12] ; response address
  2919 00000EE4 8827                    	mov	[edi], ah     ; response value 
  2920                                  	;
  2921 00000EE6 C1C010                  	rol	eax, 16
  2922                                  	; 15/01/2017
  2923 00000EE9 3A05[C5940100]          	cmp	al, [u.uno] ; running process ?
  2924 00000EEF 74E5                    	je	short rtc_p7
  2925                                  rtc_p9:
  2926                                  	; al = process number  ; 10/06/2016
  2927 00000EF1 B202                    	mov	dl, 2 ; priority, 2 = event (high)	
  2928 00000EF3 E810120100              	call	set_run_sequence ; 19/05/2016
  2929 00000EF8 EB9E                    	jmp	short rtc_p2 ; 10/06/2016
  2930                                  
  2931                                  ; Default IRQ 7 handler against spurious IRQs (from master PIC)
  2932                                  ; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
  2933                                  default_irq7:
  2934                                  	;push	ax
  2935                                  	; 18/04/2021
  2936 00000EFA 50                      	push	eax
  2937 00000EFB B00B                    	mov	al, 0Bh  ; In-Service register
  2938 00000EFD E620                    	out	20h, al
  2939 00000EFF EB00                            jmp short $+2
  2940 00000F01 EB00                    	jmp short $+2
  2941 00000F03 E420                    	in	al, 20h
  2942 00000F05 2480                    	and 	al, 80h ; bit 7 (is it real IRQ 7 or fake?)
  2943 00000F07 7404                            jz      short irq7_iret ; Fake (spurious) IRQ, do not send EOI 
  2944 00000F09 B020                            mov     al, 20h ; EOI
  2945 00000F0B E620                    	out	20h, al 
  2946                                  irq7_iret:
  2947                                  	;pop	ax
  2948                                  	; 18/04/2021
  2949 00000F0D 58                      	pop	eax
  2950 00000F0E CF                      	iretd
  2951                                  	
  2952                                  bcd_to_ascii:
  2953                                  	; 25/08/2014
  2954                                  	; INPUT ->
  2955                                  	;	al = Packed BCD number
  2956                                  	; OUTPUT ->
  2957                                  	;	ax  = ASCII word/number
  2958                                  	;
  2959                                  	; Erdogan Tan - 1998 (proc_hex) - TRDOS.ASM (2004-2011)
  2960                                  	;
  2961 00000F0F D410                    	db	0D4h, 10h	; Undocumented inst. AAM
  2962                                  				; AH = AL / 10h
  2963                                  				; AL = AL MOD 10h
  2964 00000F11 660D3030                	or	ax, '00'	; Make it ASCII based
  2965                                  
  2966 00000F15 86C4                            xchg	ah, al 
  2967                                  	
  2968 00000F17 C3                      	retn
  2969                                  
  2970                                  ; 15/12/2020
  2971                                  real_mem_16m_64k: 
  2972 00000F18 0000                    	dw	0	; Real size of system memory (if > 16MB)
  2973                                  			; as number of 64K blocks - 256
  2974                                  			; (This is for saving real system memory
  2975                                  			; because if system memory is larger than
  2976                                  			; 3 GB and if a VESA VBE video bios
  2977                                  			; is detected, 'mem_16m_64K' may be
  2978                                  			; decreased to reserve LFB space 
  2979                                  			; at the end of system memory.)
  2980                                  			; Upper memory space from LFB base address
  2981                                  			; to 4GB will not be included by M.A.T.
  2982                                  def_LFB_addr:	
  2983 00000F1A 0000                    	dw	0 	; HW of default LFB addr (for mode 118h)	
  2984                                  	
  2985                                  
  2986                                  %include 'keyboard.s' ; 07/03/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.5 - keyboard.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 07/08/2022 (Previous: 12/04/2021)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 17/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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> ; Ref: Retro UNIX 386 v1.2 - keyboard.s - 11/06/2022
    20                              <1> 
    21                              <1> ; Retro UNIX 386 v1 Kernel - KEYBOARD.INC
    22                              <1> ; Last Modification: 17/10/2015
    23                              <1> ;		    (Keyboard Data is in 'KYBDATA.INC')	
    24                              <1> ;
    25                              <1> ; ///////// KEYBOARD FUNCTIONS (PROCEDURES) ///////////////
    26                              <1> 
    27                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
    28                              <1> 
    29                              <1> ; 03/12/2014
    30                              <1> ; 26/08/2014
    31                              <1> ; KEYBOARD I/O
    32                              <1> ; (INT_16h - Retro UNIX 8086 v1 - U9.ASM, 30/06/2014)
    33                              <1> 
    34                              <1> ;NOTE: 'k0' to 'k7' are name of OPMASK registers.
    35                              <1> ;	(The reason of using '_k' labels!!!) (27/08/2014)    
    36                              <1> ;NOTE: 'NOT' keyword is '~' unary operator in NASM.
    37                              <1> ;	('NOT LC_HC' --> '~LC_HC') (bit reversing operator)
    38                              <1> 
    39                              <1> int16h:	; 30/06/2015
    40                              <1> ;getc:
    41 00000F1C 9C                  <1> 	pushfd	; 28/08/2014
    42 00000F1D 0E                  <1> 	push 	cs
    43 00000F1E E826000000          <1> 	call 	KEYBOARD_IO_1 ; getc_int
    44 00000F23 C3                  <1> 	retn	
    45                              <1> 
    46                              <1> ; 24/07/2022 - TRDOS 386 v2.0.5
    47                              <1> 
    48                              <1> 	;-----	SHIFT STATUS
    49                              <1> _K3E:                                   ; GET THE EXTENDED SHIFT STATUS FLAGS
    50 00000F24 8A25[AA670000]      <1> 	mov	ah, [KB_FLAG_1]		; GET SYSTEM SHIFT KEY STATUS
    51 00000F2A 80E404              <1> 	and	ah, SYS_SHIFT		; MASK ALL BUT SYS KEY BIT
    52                              <1> 	;mov	cl, 5			; SHIFT THEW SYSTEMKEY BIT OVER TO
    53                              <1> 	;shl	ah, cl			; BIT 7 POSITION
    54 00000F2D C0E405              <1>         shl	ah, 5
    55 00000F30 A0[AA670000]        <1> 	mov	al, [KB_FLAG_1]		; GET SYSTEM SHIFT STATES BACK
    56 00000F35 2473                <1> 	and	al, 01110011b		; ELIMINATE SYS SHIFT, HOLD_STATE AND INS_SHIFT
    57 00000F37 08C4                <1> 	or	ah, al                  ; MERGE REMAINING BITS INTO AH
    58 00000F39 A0[AC670000]        <1> 	mov	al, [KB_FLAG_3]		; GET RIGHT CTL AND ALT
    59 00000F3E 240C                <1> 	and	al, 00001100b		; ELIMINATE LC_E0 AND LC_E1
    60 00000F40 08C4                <1> 	or	ah, al			; OR THE SHIFT FLAGS TOGETHER
    61                              <1> _K3:
    62 00000F42 A0[A9670000]        <1> 	mov	al, [KB_FLAG]		; GET THE SHIFT STATUS FLAGS
    63                              <1> 	; 24/07/2022
    64 00000F47 EB38                <1> 	jmp	short _KIO_EXIT		; RETURN TO CALLER
    65                              <1> 
    66                              <1> getc_int:
    67                              <1> 	; 28/02/2015
    68                              <1> 	; 03/12/2014 (derivation from pc-xt-286 bios source code -1986-, 
    69                              <1> 	;	      instead of pc-at bios - 1985-)
    70                              <1> 	; 28/08/2014 (_k1d)
    71                              <1> 	; 30/06/2014
    72                              <1> 	; 03/03/2014
    73                              <1> 	; 28/02/2014
    74                              <1> 	; Derived from "KEYBOARD_IO_1" procedure of IBM "pc-xt-286" 
    75                              <1> 	; rombios source code (21/04/1986)
    76                              <1> 	;	 'keybd.asm', INT 16H, KEYBOARD_IO
    77                              <1> 	;
    78                              <1> 	; KYBD --- 03/06/86  KEYBOARD BIOS
    79                              <1> 	;
    80                              <1> 	;--- INT 16 H -----------------------------------------------------------------
    81                              <1> 	; KEYBOARD I/O								      :
    82                              <1> 	;	THESE ROUTINES PROVIDE READ KEYBOARD SUPPORT			      :
    83                              <1> 	; INPUT									      :
    84                              <1> 	;	(AH)= 00H  READ THE NEXT ASCII CHARACTER ENTERED FROM THE KEYBOARD,   :
    85                              <1> 	;		   RETURN THE RESULT IN (AL), SCAN CODE IN (AH).              :
    86                              <1> 	;		   THIS IS THE COMPATIBLE READ INTERFACE, EQUIVALENT TO THE   :
    87                              <1> 	;                  STANDARD PC OR PCAT KEYBOARD				      :	
    88                              <1> 	;-----------------------------------------------------------------------------:
    89                              <1> 	;	(AH)= 01H  SET THE ZERO FLAG TO INDICATE IF AN ASCII CHARACTER IS     :
    90                              <1> 	;		   AVAILABLE TO BE READ FROM THE KEYBOARD BUFFER.	      :
    91                              <1> 	;		   (ZF)= 1 -- NO CODE AVAILABLE			              :
    92                              <1> 	;		   (ZF)= 0 -- CODE IS AVAILABLE  (AX)= CHARACTER              :
    93                              <1> 	;		   IF (ZF)= 0, THE NEXT CHARACTER IN THE BUFFER TO BE READ IS :
    94                              <1> 	;		   IN (AX), AND THE ENTRY REMAINS IN THE BUFFER.              :
    95                              <1> 	;		   THIS WILL RETURN ONLY PC/PCAT KEYBOARD COMPATIBLE CODES    :
    96                              <1> 	;-----------------------------------------------------------------------------:	
    97                              <1> 	;	(AH)= 02H  RETURN THE CURRENT SHIFT STATUS IN AL REGISTER             :
    98                              <1> 	;		   THE BIT SETTINGS FOR THIS CODE ARE INDICATED IN THE        :
    99                              <1> 	;		   EQUATES FOR @KB_FLAG		                              :
   100                              <1> 	;-----------------------------------------------------------------------------:	
   101                              <1> 	;	(AH)= 03H  SET TYPAMATIC RATE AND DELAY                               :
   102                              <1> 	;	      (AL) = 05H                                                      :
   103                              <1> 	;	      (BL) = TYPAMATIC RATE (BITS 5 - 7 MUST BE RESET TO 0)           :
   104                              <1> 	;		       							      :
   105                              <1> 	;                     REGISTER     RATE      REGISTER     RATE                :
   106                              <1> 	;                      VALUE     SELECTED     VALUE     SELECTED              :
   107                              <1> 	;                     --------------------------------------------            :
   108                              <1> 	;			00H        30.0        10H        7.5                 :
   109                              <1> 	;			01H        26.7        11H        6.7                 :
   110                              <1> 	;			02H        24.0        12H        6.0                 :
   111                              <1> 	;			03H        21.8        13H        5.5                 :
   112                              <1> 	;			04H        20.0        14H        5.0                 :
   113                              <1> 	;			05H        18.5        15H        4.6                 :
   114                              <1> 	;			06H        17.1        16H        4.3                 :
   115                              <1> 	;			07H        16.0        17H        4.0                 :
   116                              <1> 	;			08H        15.0        18H        3.7                 :
   117                              <1> 	;			09H        13.3        19H        3.3                 :
   118                              <1> 	;			0AH        12.0        1AH        3.0                 :
   119                              <1> 	;			0BH        10.9        1BH        2.7                 :
   120                              <1>         ;			0CH        10.0        1CH        2.5                 :
   121                              <1> 	;			0DH         9.2        1DH        2.3                 :
   122                              <1> 	;			0EH         8.6        1EH        2.1                 :
   123                              <1> 	;			0FH         8.0        1FH        2.0                 :
   124                              <1> 	;									      :
   125                              <1> 	;	      (BH) = TYPAMATIC DELAY  (BITS 2 - 7 MUST BE RESET TO 0)         :
   126                              <1> 	;		       							      :
   127                              <1> 	;                     REGISTER     DELAY                                      :
   128                              <1> 	;                      VALUE       VALUE                                      :
   129                              <1> 	;                     ------------------                                      :
   130                              <1> 	;			00H        250 ms                                     :
   131                              <1> 	;			01H        500 ms                                     :
   132                              <1> 	;			02H        750 ms                                     :
   133                              <1> 	;			03H       1000 ms                                     :
   134                              <1> 	;-----------------------------------------------------------------------------:
   135                              <1> 	;	(AH)= 05H  PLACE ASCII CHARACTER/SCAN CODE COMBINATION IN KEYBOARD    :
   136                              <1> 	;		   BUFFER AS IF STRUCK FROM KEYBOARD                          :
   137                              <1> 	;		   ENTRY:  (CL) = ASCII CHARACTER		              :
   138                              <1> 	;		           (CH) = SCAN CODE                                   :
   139                              <1> 	;		   EXIT:   (AH) = 00H = SUCCESSFUL OPERATION                  :
   140                              <1> 	;		           (AL) = 01H = UNSUCCESSFUL - BUFFER FULL            :
   141                              <1> 	;		   FLAGS:  CARRY IF ERROR                                     :
   142                              <1> 	;-----------------------------------------------------------------------------:		
   143                              <1> 	;	(AH)= 10H  EXTENDED READ INTERFACE FOR THE ENHANCED KEYBOARD,         :
   144                              <1> 	;		   OTHERWISE SAME AS FUNCTION AH=0                            :
   145                              <1> 	;-----------------------------------------------------------------------------:
   146                              <1> 	;	(AH)= 11H  EXTENDED ASCII STATUS FOR THE ENHANCED KEYBOARD,           :
   147                              <1> 	;		   OTHERWISE SAME AS FUNCTION AH=1                            :
   148                              <1> 	;-----------------------------------------------------------------------------:	
   149                              <1> 	;	(AH)= 12H  RETURN THE EXTENDED SHIFT STATUS IN AX REGISTER            :
   150                              <1> 	;		   AL = BITS FROM KB_FLAG, AH = BITS FOR LEFT AND RIGHT       :
   151                              <1> 	;		   CTL AND ALT KEYS FROM KB_FLAG_1 AND KB_FLAG_3              :
   152                              <1> 	; OUTPUT					                              :
   153                              <1> 	;	AS NOTED ABOVE, ONLY (AX) AND FLAGS CHANGED	                      :
   154                              <1> 	;	ALL REGISTERS RETAINED		                                      :
   155                              <1> 	;------------------------------------------------------------------------------
   156                              <1> 
   157                              <1> ; 07/08/2022
   158                              <1> ; 24/07/2022 - TRDOS 386 v2.0.5
   159                              <1> ; 12/04/2021 - TRDOS 386 v2.0.3 (32 bit push/pop)
   160                              <1> ; 15/01/2017
   161                              <1> ; 14/01/2017
   162                              <1> ; 02/01/2017
   163                              <1> ; 29/05/2016
   164                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   165                              <1> int32h:  ; Keyboard BIOS
   166                              <1> 
   167                              <1> KEYBOARD_IO_1:	
   168                              <1> 	;sti				; INTERRUPTS BACK ON
   169                              <1> 	; 29/05/2016
   170 00000F49 80642408BE          <1>         and     byte [esp+8], 10111110b ; clear zero flag and cary flag
   171                              <1> 	;
   172 00000F4E 1E                  <1> 	push	ds			; SAVE CURRENT DS
   173 00000F4F 53                  <1> 	push	ebx			; SAVE BX TEMPORARILY
   174                              <1> 	;push	ecx			; SAVE CX TEMPORARILY
   175 00000F50 66BB1000            <1>         mov     bx, KDATA
   176 00000F54 8EDB                <1> 	mov	ds, bx			; PUT SEGMENT VALUE OF DATA AREA INTO DS
   177                              <1> 	; 14/01/2017
   178 00000F56 8B1C24              <1> 	mov	ebx, [esp]
   179                              <1> 	;; 15/01/2017
   180                              <1> 	; 02/01/2017
   181                              <1> 	;;mov	byte [intflg], 32h	; keyboard interrupt 
   182 00000F59 FB                  <1> 	sti
   183                              <1> 	;
   184 00000F5A 08E4                <1> 	or	ah, ah			; CHECK FOR (AH)= 00H
   185 00000F5C 7433                <1> 	jz	short _K1		; ASCII_READ
   186 00000F5E FECC                <1> 	dec	ah                      ; CHECK FOR (AH)= 01H
   187 00000F60 744C                <1>         jz      short _K2               ; ASCII_STATUS
   188 00000F62 FECC                <1> 	dec	ah			; CHECK FOR (AH)= 02H
   189 00000F64 74DC                <1>         jz	short _K3		; SHIFT STATUS
   190 00000F66 FECC                <1> 	dec	ah			; CHECK FOR (AH)= 03H	
   191 00000F68 746F                <1>         jz      short _K300		; SET TYPAMATIC RATE/DELAY
   192 00000F6A 80EC02              <1> 	sub	ah, 2			; CHECK FOR (AH)= 05H	
   193                              <1>         ;jz	short _K500		; KEYBOARD WRITE
   194                              <1> 	; 07/08/2022
   195 00000F6D 7505                <1> 	jnz	short _KIO1
   196 00000F6F E988000000          <1> 	jmp	_K500         
   197                              <1> _KIO1:	
   198 00000F74 80EC0B              <1> 	sub	ah, 11			; AH =  10H
   199 00000F77 740C                <1> 	jz	short _K1E		; EXTENDED ASCII READ
   200 00000F79 FECC                <1> 	dec	ah			; CHECK FOR (AH)= 11H
   201 00000F7B 7422                <1> 	jz	short _K2E		; EXTENDED_ASCII_STATUS
   202 00000F7D FECC                <1> 	dec	ah			; CHECK FOR (AH)= 12H
   203 00000F7F 74A3                <1> 	jz	short _K3E		; EXTENDED_SHIFT_STATUS
   204                              <1> _KIO_EXIT:
   205                              <1> 	; 02/01/2017
   206 00000F81 FA                  <1> 	cli
   207                              <1> 	;;mov	byte [intflg], 0 ;; 15/01/2017
   208                              <1> 	;
   209                              <1> 	;pop	ecx			; RECOVER REGISTER
   210 00000F82 5B                  <1> 	pop	ebx			; RECOVER REGISTER
   211 00000F83 1F                  <1> 	pop	ds			; RECOVER SEGMENT
   212 00000F84 CF                  <1> 	iretd				; INVALID COMMAND, EXIT
   213                              <1> 
   214                              <1> ; 24/07/2022
   215                              <1> ;
   216                              <1> ;	;-----	SHIFT STATUS
   217                              <1> ;_K3E:					; GET THE EXTENDED SHIFT STATUS FLAGS
   218                              <1> ;	mov	ah, [KB_FLAG_1]		; GET SYSTEM SHIFT KEY STATUS
   219                              <1> ;	and	ah, SYS_SHIFT		; MASK ALL BUT SYS KEY BIT
   220                              <1> ;	;mov	cl, 5			; SHIFT THEW SYSTEMKEY BIT OVER TO
   221                              <1> ;	;shl	ah, cl			; BIT 7 POSITION
   222                              <1> ;       shl	ah, 5
   223                              <1> ;	mov	al, [KB_FLAG_1]		; GET SYSTEM SHIFT STATES BACK
   224                              <1> ;	and	al, 01110011b		; ELIMINATE SYS SHIFT, HOLD_STATE AND INS_SHIFT
   225                              <1> ;	or	ah, al                  ; MERGE REMAINING BITS INTO AH
   226                              <1> ;	mov	al, [KB_FLAG_3]		; GET RIGHT CTL AND ALT
   227                              <1> ;	and	al, 00001100b		; ELIMINATE LC_E0 AND LC_E1
   228                              <1> ;	or	ah, al			; OR THE SHIFT FLAGS TOGETHER
   229                              <1> ;_K3:
   230                              <1> ;	mov	al, [KB_FLAG]		; GET THE SHIFT STATUS FLAGS
   231                              <1> ;	; 24/07/2022
   232                              <1> ;	jmp	short _KIO_EXIT		; RETURN TO CALLER
   233                              <1> 
   234                              <1> 	;-----	ASCII CHARACTER
   235                              <1> _K1E:	
   236 00000F85 E89F000000          <1> 	call	_K1S			; GET A CHARACTER FROM THE BUFFER (EXTENDED)
   237 00000F8A E812010000          <1> 	call	_KIO_E_XLAT		; ROUTINE TO XLATE FOR EXTENDED CALLS
   238 00000F8F EBF0                <1> 	jmp	short _KIO_EXIT         ; GIVE IT TO THE CALLER
   239                              <1> _K1:	
   240 00000F91 E893000000          <1> 	call	_K1S			; GET A CHARACTER FROM THE BUFFER
   241 00000F96 E811010000          <1> 	call	_KIO_S_XLAT		; ROUTINE TO XLATE FOR STANDARD CALLS
   242 00000F9B 72F4                <1> 	jc	short _K1		; CARRY SET MEANS TROW CODE AWAY
   243                              <1> _K1A:
   244 00000F9D EBE2                <1> 	jmp	short _KIO_EXIT         ; RETURN TO CALLER
   245                              <1> 
   246                              <1> 	;-----	ASCII STATUS
   247                              <1> _K2E:	
   248 00000F9F E8D0000000          <1> 	call	_K2S			; TEST FOR CHARACTER IN BUFFER (EXTENDED)
   249 00000FA4 7420                <1> 	jz	short _K2B		; RETURN IF BUFFER EMPTY
   250 00000FA6 9C                  <1> 	pushf				; SAVE ZF FROM TEST
   251 00000FA7 E8F5000000          <1> 	call	_KIO_E_XLAT		; ROUTINE TO XLATE FOR EXTENDED CALLS
   252 00000FAC EB17                <1> 	jmp	short _K2A	        ; GIVE IT TO THE CALLER
   253                              <1> _K2:	
   254 00000FAE E8C1000000          <1> 	call	_K2S			; TEST FOR CHARACTER IN BUFFER
   255 00000FB3 7411                <1> 	jz	short _K2B		; RETURN IF BUFFER EMPTY
   256 00000FB5 9C                  <1> 	pushf				; SAVE ZF FROM TEST
   257 00000FB6 E8F1000000          <1> 	call	_KIO_S_XLAT		; ROUTINE TO XLATE FOR STANDARD CALLS
   258 00000FBB 7308                <1> 	jnc	short _K2A	        ; CARRY CLEAR MEANS PASS VALID CODE
   259 00000FBD 9D                  <1> 	popf				; INVALID CODE FOR THIS TYPE OF CALL
   260 00000FBE E866000000          <1> 	call	_K1S			; THROW THE CHARACTER AWAY
   261 00000FC3 EBE9                <1> 	jmp	short _K2		; GO LOOK FOR NEXT CHAR, IF ANY
   262                              <1> _K2A:
   263 00000FC5 9D                  <1> 	popf				; RESTORE ZF FROM TEST
   264                              <1> _K2B:
   265                              <1> 	; 02/01/2017
   266 00000FC6 FA                  <1> 	cli
   267                              <1> 	;; mov	byte [intflg], 0 ;; 15/01/2017
   268                              <1> 	;
   269                              <1> 	;pop	ecx			; RECOVER REGISTER
   270 00000FC7 5B                  <1> 	pop	ebx			; RECOVER REGISTER
   271 00000FC8 1F                  <1> 	pop	ds			; RECOVER SEGMENT
   272                              <1> 	; (*) 29/05/2016
   273                              <1> 	; (*) retf 4			; THROW AWAY (e)FLAGS
   274 00000FC9 7208                <1> 	jc	short _k2d
   275 00000FCB 7505                <1> 	jnz	short _k2c
   276 00000FCD 804C240840          <1> 	or	byte [esp+8], 01000000b	; set zero flag bit of eflags register
   277                              <1> _k2c:
   278 00000FD2 CF                  <1> 	iretd
   279                              <1> _k2d:
   280                              <1> 	; 29/05/2016 -set carry flag on stack-
   281                              <1> 	; [esp] = EIP
   282                              <1> 	; [esp+4] = CS
   283                              <1> 	; [esp+8] = E-FLAGS
   284 00000FD3 804C240801          <1> 	or	byte [esp+8], 1  ; set carry bit of eflags register
   285                              <1> 	; [esp+12] = ESP (user)
   286                              <1> 	; [esp+16] = SS (User)
   287 00000FD8 CF                  <1> 	iretd
   288                              <1> 	
   289                              <1> 	; (*) 29/05/2016 - 'retf 4' intruction causes to stack fault
   290                              <1> 	; (OUTER-PRIVILEGE-LEVEL)
   291                              <1> 	; INTEL 80386 PROGRAMMER'S REFERENCE MANUAL 1986
   292                              <1> 	; // RETF instruction:
   293                              <1> 	;
   294                              <1> 	; IF OperandMode=32 THEN
   295                              <1>  	;    Load CS:EIP from stack;
   296                              <1>  	;    Set CS RPL to CPL;
   297                              <1>  	;    Increment ESP by 8 plus the immediate offset if it exists;
   298                              <1>  	;    Load SS:ESP from stack;
   299                              <1>  	; ELSE (* OperandMode=16 *)
   300                              <1>  	;    Load CS:IP from stack;
   301                              <1>  	;    Set CS RPL to CPL;
   302                              <1>  	;    Increment SP by 4 plus the immediate offset if it exists;
   303                              <1> 	;    Load SS:SP from stack;
   304                              <1>  	; FI;
   305                              <1> 	;
   306                              <1> 	; //
   307                              <1> 
   308                              <1> 	; 24/07/2022
   309                              <1> 	;-----	SET TYPAMATIC RATE AND DELAY
   310                              <1> _K300:
   311 00000FD9 3C05                <1> 	cmp	al, 5			; CORRECT FUNCTION CALL?
   312 00000FDB 75A4                <1> 	jne	short _KIO_EXIT		; NO, RETURN
   313 00000FDD F6C3E0              <1> 	test	bl, 0E0h		; TEST FOR OUT-OF-RANGE RATE
   314 00000FE0 759F                <1> 	jnz	short _KIO_EXIT		; RETURN IF SO
   315 00000FE2 F6C7FC              <1> 	test	bh, 0FCh		; TEST FOR OUT-OF-RANGE DELAY
   316 00000FE5 759A                <1> 	jnz	short _KIO_EXIT		; RETURN IF SO
   317 00000FE7 B0F3                <1> 	mov	al, KB_TYPA_RD		; COMMAND FOR TYPAMATIC RATE/DELAY		
   318 00000FE9 E875060000          <1> 	call	SND_DATA		; SEND TO KEYBOARD	
   319                              <1> 	;mov	cx, 5			; SHIFT COUNT
   320                              <1> 	;shl	bh, cl			; SHIFT DELAY OVER
   321 00000FEE C0E705              <1> 	shl	bh, 5
   322 00000FF1 88D8                <1> 	mov	al, bl			; PUT IN RATE
   323 00000FF3 08F8                <1> 	or	al, bh			; AND DELAY
   324 00000FF5 E869060000          <1> 	call	SND_DATA		; SEND TO KEYBOARD	
   325 00000FFA EB85                <1>         jmp     _KIO_EXIT               ; RETURN TO CALLER
   326                              <1> 
   327                              <1> 	;-----	WRITE TO KEYBOARD BUFFER
   328                              <1> _K500:
   329 00000FFC 56                  <1> 	push	esi			; SAVE SI (esi)
   330 00000FFD FA                  <1> 	cli				; 
   331 00000FFE 8B1D[BA670000]      <1>      	mov	ebx, [BUFFER_TAIL]	; GET THE 'IN TO' POINTER TO THE BUFFER
   332 00001004 89DE                <1> 	mov	esi, ebx		; SAVE A COPY IN CASE BUFFER NOT FULL
   333 00001006 E8D1000000          <1> 	call	_K4			; BUMP THE POINTER TO SEE IF BUFFER IS FULL
   334 0000100B 3B1D[B6670000]      <1> 	cmp	ebx, [BUFFER_HEAD]	; WILL THE BUFFER OVERRUN IF WE STORE THIS?
   335 00001011 740D                <1> 	je	short _K502		; YES - INFORM CALLER OF ERROR		
   336 00001013 66890E              <1> 	mov	[esi], cx		; NO - PUT ASCII/SCAN CODE INTO BUFFER	
   337 00001016 891D[BA670000]      <1> 	mov	[BUFFER_TAIL], ebx	; ADJUST 'IN TO' POINTER TO REFLECT CHANGE
   338 0000101C 28C0                <1> 	sub	al, al			; TELL CALLER THAT OPERATION WAS SUCCESSFUL
   339 0000101E EB02                <1> 	jmp	short _K504		; SUB INSTRUCTION ALSO RESETS CARRY FLAG
   340                              <1> _K502:
   341 00001020 B001                <1> 	mov	al, 01h			; BUFFER FULL INDICATION
   342                              <1> _K504:
   343 00001022 FB                  <1> 	sti				
   344 00001023 5E                  <1> 	pop	esi			; RECOVER SI (esi)
   345 00001024 E958FFFFFF          <1>         jmp     _KIO_EXIT               ; RETURN TO CALLER WITH STATUS IN AL
   346                              <1> 
   347                              <1> 	;-----	READ THE KEY TO FIGURE OUT WHAT TO DO -----
   348                              <1> _K1S:
   349 00001029 FA                  <1> 	cli	; 03/12/2014
   350 0000102A 8B1D[B6670000]      <1>         mov     ebx, [BUFFER_HEAD] 	; GET POINTER TO HEAD OF BUFFER
   351 00001030 3B1D[BA670000]      <1>         cmp     ebx, [BUFFER_TAIL] 	; TEST END OF BUFFER
   352                              <1> 	;jne	short _K1U		; IF ANYTHING IN BUFFER SKIP INTERRUPT
   353 00001036 750F                <1> 	jne	short _k1x ; 03/12/2014
   354                              <1> 	;
   355                              <1> 	; 03/12/2014
   356                              <1> 	; 28/08/2014
   357                              <1> 	; PERFORM OTHER FUNCTION ?? here !
   358                              <1> 	;; MOV	AX, 9002h		; MOVE IN WAIT CODE & TYPE
   359                              <1> 	;; INT 	15H			; PERFORM OTHER FUNCTION
   360                              <1> _K1T:                                   ; ASCII READ
   361 00001038 FB                  <1> 	sti				; INTERRUPTS BACK ON DURING LOOP
   362 00001039 90                  <1> 	nop				; ALLOW AN INTERRUPT TO OCCUR
   363                              <1> _K1U:	
   364 0000103A FA                  <1> 	cli				; INTERRUPTS BACK OFF
   365 0000103B 8B1D[B6670000]      <1>         mov    	ebx, [BUFFER_HEAD] 	; GET POINTER TO HEAD OF BUFFER
   366 00001041 3B1D[BA670000]      <1>         cmp     ebx, [BUFFER_TAIL] 	; TEST END OF BUFFER
   367                              <1> _k1x:
   368 00001047 53                  <1> 	push	ebx			; SAVE ADDRESS		
   369 00001048 9C                  <1> 	pushf				; SAVE FLAGS
   370 00001049 E8C9060000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
   371 0000104E 8A1D[AB670000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
   372 00001054 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
   373 00001056 80E307              <1> 	and	bl, 07h	; KB_LEDS	; ISOLATE INDICATOR BITS
   374 00001059 7406                <1> 	jz	short _K1V		; IF NO CHANGE BYPASS UPDATE
   375 0000105B E863060000          <1> 	call	SND_LED1
   376 00001060 FA                  <1> 	cli				; DISABLE INTERRUPTS
   377                              <1> _K1V:
   378 00001061 9D                  <1> 	popf				; RESTORE FLAGS
   379 00001062 5B                  <1> 	pop	ebx			; RESTORE ADDRESS
   380 00001063 74D3                <1>         je      short _K1T              ; LOOP UNTIL SOMETHING IN BUFFER
   381                              <1> 	;
   382 00001065 668B03              <1> 	mov	ax, [ebx] 		; GET SCAN CODE AND ASCII CODE
   383 00001068 E86F000000          <1>         call    _K4                     ; MOVE POINTER TO NEXT POSITION
   384 0000106D 891D[B6670000]      <1>         mov     [BUFFER_HEAD], ebx      ; STORE VALUE IN VARIABLE
   385 00001073 C3                  <1> 	retn				; RETURN
   386                              <1> 
   387                              <1> 	;-----	READ THE KEY TO SEE IF ONE IS PRESENT -----
   388                              <1> _K2S:
   389 00001074 FA                  <1> 	cli				; INTERRUPTS OFF
   390 00001075 8B1D[B6670000]      <1>         mov     ebx, [BUFFER_HEAD]      ; GET HEAD POINTER
   391 0000107B 3B1D[BA670000]      <1>         cmp     ebx, [BUFFER_TAIL]      ; IF EQUAL (Z=1) THEN NOTHING THERE
   392 00001081 668B03              <1> 	mov	ax, [ebx]
   393 00001084 9C                  <1> 	pushf				; SAVE FLAGS
   394                              <1> 	;push	ax			; SAVE CODE
   395                              <1> 	; 12/04/2021
   396 00001085 50                  <1> 	push	eax
   397 00001086 E88C060000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
   398 0000108B 8A1D[AB670000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
   399 00001091 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
   400 00001093 80E307              <1> 	and	bl, 07h ; KB_LEDS	; ISOLATE INDICATOR BITS
   401 00001096 7405                <1> 	jz	short _K2T		; IF NO CHANGE BYPASS UPDATE
   402 00001098 E80F060000          <1> 	call	SND_LED			; GO TURN ON MODE INDICATORS
   403                              <1> _K2T:
   404                              <1> 	;pop	ax			; RESTORE CODE
   405                              <1> 	; 12/04/2021
   406 0000109D 58                  <1> 	pop	eax
   407 0000109E 9D                  <1> 	popf				; RESTORE FLAGS
   408 0000109F FB                  <1> 	sti				; INTERRUPTS BACK ON
   409 000010A0 C3                  <1> 	retn				; RETURN
   410                              <1> 
   411                              <1> 	;-----	ROUTINE TO TRANSLATE SCAN CODE PAIRS FOR EXTENDED CALLS -----
   412                              <1> _KIO_E_XLAT:
   413 000010A1 3CF0                <1> 	cmp	al, 0F0h		; IS IT ONE OF THE FILL-INs?
   414 000010A3 7506                <1> 	jne	short _KIO_E_RET	; NO, PASS IT ON
   415 000010A5 08E4                <1>         or 	ah, ah			; AH = 0 IS SPECIAL CASE
   416 000010A7 7402                <1>         jz	short _KIO_E_RET        ; PASS THIS ON UNCHANGED
   417 000010A9 30C0                <1> 	xor	al, al			; OTHERWISE SET AL = 0
   418                              <1> _KIO_E_RET:				
   419 000010AB C3                  <1> 	retn				; GO BACK
   420                              <1> 
   421                              <1> 	;-----	ROUTINE TO TRANSLATE SCAN CODE PAIRS FOR STANDARD CALLS -----
   422                              <1> _KIO_S_XLAT:
   423 000010AC 80FCE0              <1> 	cmp	ah, 0E0h		; IS IT KEYPAD ENTER OR / ?
   424 000010AF 750F                <1> 	jne	short _KIO_S2		; NO, CONTINUE
   425 000010B1 3C0D                <1> 	cmp	al, 0Dh			; KEYPAD ENTER CODE?
   426 000010B3 7408                <1>         je	short _KIO_S1		; YES, MASSAGE A BIT
   427 000010B5 3C0A                <1> 	cmp	al, 0Ah			; CTRL KEYPAD ENTER CODE?
   428 000010B7 7404                <1>         je	short _KIO_S1		; YES, MASSAGE THE SAME
   429 000010B9 B435                <1> 	mov	ah, 35h			; NO, MUST BE KEYPAD /
   430                              <1> _kio_ret: ; 03/12/2014
   431 000010BB F8                  <1> 	clc
   432 000010BC C3                  <1> 	retn
   433                              <1> 	;jmp	short _KIO_USE		; GIVE TO CALLER
   434                              <1> _KIO_S1:				
   435 000010BD B41C                <1> 	mov	ah, 1Ch			; CONVERT TO COMPATIBLE OUTPUT
   436                              <1> 	;jmp	short _KIO_USE		; GIVE TO CALLER
   437 000010BF C3                  <1> 	retn
   438                              <1> _KIO_S2:		
   439 000010C0 80FC84              <1> 	cmp	ah, 84h			; IS IT ONE OF EXTENDED ONES?
   440 000010C3 7715                <1> 	ja	short _KIO_DIS		; YES, THROW AWAY AND GET ANOTHER CHAR
   441 000010C5 3CF0                <1> 	cmp	al, 0F0h		; IS IT ONE OF THE FILL-INs?
   442 000010C7 7506                <1>         jne	short _KIO_S3		; NO, TRY LAST TEST
   443 000010C9 08E4                <1> 	or	ah, ah			; AH = 0 IS SPECIAL CASE
   444 000010CB 740C                <1>         jz	short _KIO_USE		; PASS THIS ON UNCHANGED
   445 000010CD EB0B                <1> 	jmp	short _KIO_DIS		; THROW AWAY THE REST
   446                              <1> _KIO_S3:
   447 000010CF 3CE0                <1> 	cmp	al, 0E0h		; IS IT AN EXTENSION OF A PREVIOUS ONE?
   448                              <1> 	;jne	short _KIO_USE		; NO, MUST BE A STANDARD CODE
   449 000010D1 75E8                <1> 	jne	short _kio_ret
   450 000010D3 08E4                <1> 	or	ah, ah			; AH = 0 IS SPECIAL CASE
   451 000010D5 7402                <1>         jz	short _KIO_USE		; JUMP IF AH = 0
   452 000010D7 30C0                <1> 	xor	al, al			; CONVERT TO COMPATIBLE OUTPUT
   453                              <1> 	;jmp	short _KIO_USE		; PASS IT ON TO CALLER
   454                              <1> _KIO_USE:
   455                              <1> 	;clc				; CLEAR CARRY TO INDICATE GOOD CODE
   456 000010D9 C3                  <1> 	retn				; RETURN	
   457                              <1> _KIO_DIS:
   458 000010DA F9                  <1> 	stc				; SET CARRY TO INDICATE DISCARD CODE
   459 000010DB C3                  <1> 	retn				; RETURN
   460                              <1> 
   461                              <1> 	;-----	INCREMENT BUFFER POINTER ROUTINE -----
   462                              <1> _K4:    
   463 000010DC 43                  <1> 	inc     ebx
   464 000010DD 43                  <1> 	inc	ebx			; MOVE TO NEXT WORD IN LIST
   465 000010DE 3B1D[B2670000]      <1>         cmp     ebx, [BUFFER_END] 	; AT END OF BUFFER?
   466                              <1>         ;jne    short _K5               ; NO, CONTINUE
   467 000010E4 7206                <1> 	jb	short _K5
   468 000010E6 8B1D[AE670000]      <1>         mov     ebx, [BUFFER_START]     ; YES, RESET TO BUFFER BEGINNING
   469                              <1> _K5:
   470 000010EC C3                  <1> 	retn
   471                              <1> 
   472                              <1> ; 20/02/2015
   473                              <1> ; 05/12/2014
   474                              <1> ; 26/08/2014
   475                              <1> ; KEYBOARD (HARDWARE) INTERRUPT -  IRQ LEVEL 1
   476                              <1> ; (INT_09h - Retro UNIX 8086 v1 - U9.ASM, 07/03/2014)
   477                              <1> ;
   478                              <1> ; Derived from "KB_INT_1" procedure of IBM "pc-at" 
   479                              <1> ; rombios source code (06/10/1985)
   480                              <1> ; 'keybd.asm', HARDWARE INT 09h - (IRQ Level 1)
   481                              <1> 
   482                              <1> ; EQUATES (IBM PC-XT-286 BIOS, 1986, 'POSQEQU.INC')
   483                              <1> 
   484                              <1> ;--------- 8042 COMMANDS -------------------------------------------------------
   485                              <1> ENA_KBD		equ	0AEh		; ENABLE KEYBOARD COMMAND
   486                              <1> DIS_KBD		equ	0ADh		; DISABLE KEYBOARD COMMAND
   487                              <1> SHUT_CMD	equ	0FEh		; CAUSE A SHUTDOWN COMMAND
   488                              <1> ;--------- 8042 KEYBOARD INTERFACE AND DIAGNOSTIC CONTROL REGISTERS ------------
   489                              <1> STATUS_PORT	equ	064h		; 8042 STATUS PORT
   490                              <1> INPT_BUF_FULL	equ	00000010b 	; 1 = +INPUT BUFFER FULL
   491                              <1> PORT_A		equ	060h		; 8042 KEYBOARD SCAN CODE/CONTROL PORT
   492                              <1> ;---------- 8042 KEYBOARD RESPONSE ---------------------------------------------
   493                              <1> KB_ACK		equ	0FAh		; ACKNOWLEDGE PROM TRANSMISSION
   494                              <1> KB_RESEND	equ	0FEh		; RESEND REQUEST
   495                              <1> KB_OVER_RUN	equ	0FFh		; OVER RUN SCAN CODE
   496                              <1> ;---------- KEYBOARD/LED COMMANDS ----------------------------------------------
   497                              <1> KB_ENABLE	equ	0F4h		; KEYBOARD ENABLE
   498                              <1> LED_CMD		equ	0EDh		; LED WRITE COMMAND
   499                              <1> KB_TYPA_RD	equ	0F3h		; TYPAMATIC RATE/DELAY COMMAND
   500                              <1> ;---------- KEYBOARD SCAN CODES ------------------------------------------------
   501                              <1> NUM_KEY		equ	69		; SCAN CODE FOR	 NUMBER LOCK KEY
   502                              <1> SCROLL_KEY	equ	70		; SCAN CODE FOR	 SCROLL LOCK KEY
   503                              <1> ALT_KEY		equ	56		; SCAN CODE FOR	 ALTERNATE SHIFT KEY
   504                              <1> CTL_KEY		equ	29		; SCAN CODE FOR	 CONTROL KEY
   505                              <1> CAPS_KEY	equ	58		; SCAN CODE FOR	 SHIFT LOCK KEY
   506                              <1> DEL_KEY		equ	83		; SCAN CODE FOR	 DELETE KEY
   507                              <1> INS_KEY		equ	82		; SCAN CODE FOR	 INSERT KEY
   508                              <1> LEFT_KEY	equ	42		; SCAN CODE FOR	 LEFT SHIFT
   509                              <1> RIGHT_KEY	equ	54		; SCAN CODE FOR	 RIGHT SHIFT
   510                              <1> SYS_KEY		equ	84		; SCAN CODE FOR	 SYSTEM KEY
   511                              <1> ;---------- ENHANCED KEYBOARD SCAN CODES ---------------------------------------
   512                              <1> ID_1		equ	0ABh		; 1ST ID CHARACTER FOR KBX
   513                              <1> ID_2		equ	041h		; 2ND ID CHARACTER FOR KBX
   514                              <1> ID_2A		equ	054h		; ALTERNATE 2ND ID CHARACTER FOR KBX
   515                              <1> F11_M		equ	87		; F11 KEY MAKE
   516                              <1> F12_M		equ	88		; F12 KEY MAKE
   517                              <1> MC_E0		equ	224		; GENERAL MARKER CODE
   518                              <1> MC_E1		equ	225		; PAUSE KEY MARKER CODE
   519                              <1> ;---------- FLAG EQUATES WITHIN @KB_FLAG----------------------------------------
   520                              <1> RIGHT_SHIFT	equ	00000001b	; RIGHT SHIFT KEY DEPRESSED
   521                              <1> LEFT_SHIFT	equ	00000010b	; LEFT SHIFT KEY DEPRESSED
   522                              <1> CTL_SHIFT	equ	00000100b	; CONTROL SHIFT KEY DEPRESSED
   523                              <1> ALT_SHIFT	equ	00001000b	; ALTERNATE SHIFT KEY DEPRESSED
   524                              <1> SCROLL_STATE	equ	00010000b	; SCROLL LOCK STATE IS ACTIVE
   525                              <1> NUM_STATE	equ	00100000b	; NUM LOCK STATE IS ACTIVE
   526                              <1> CAPS_STATE	equ	01000000b	; CAPS LOCK STATE IS ACTIVE
   527                              <1> INS_STATE	equ	10000000b	; INSERT STATE IS ACTIVE
   528                              <1> ;---------- FLAG EQUATES WITHIN	@KB_FLAG_1 -------------------------------------
   529                              <1> L_CTL_SHIFT	equ	00000001b	; LEFT CTL KEY DOWN
   530                              <1> L_ALT_SHIFT	equ	00000010b	; LEFT ALT KEY DOWN
   531                              <1> SYS_SHIFT	equ	00000100b	; SYSTEM KEY DEPRESSED AND HELD
   532                              <1> HOLD_STATE	equ	00001000b	; SUSPEND KEY HAS BEEN TOGGLED
   533                              <1> SCROLL_SHIFT	equ	00010000b	; SCROLL LOCK KEY IS DEPRESSED
   534                              <1> NUM_SHIFT	equ	00100000b	; NUM LOCK KEY IS DEPRESSED
   535                              <1> CAPS_SHIFT	equ	01000000b	; CAPS LOCK KEY IS DEPRE55ED
   536                              <1> INS_SHIFT	equ	10000000b	; INSERT KEY IS DEPRESSED
   537                              <1> ;---------- FLAGS EQUATES WITHIN @KB_FLAG_2 -----------------------------------
   538                              <1> KB_LEDS		equ	00000111b	; KEYBOARD LED STATE BITS
   539                              <1> ;		equ	00000001b	; SCROLL LOCK INDICATOR
   540                              <1> ;		equ	00000010b	; NUM LOCK INDICATOR
   541                              <1> ;		equ	00000100b	; CAPS LOCK INDICATOR
   542                              <1> ;		equ	00001000b	; RESERVED (MUST BE ZERO)
   543                              <1> KB_FA		equ	00010000b	; ACKNOWLEDGMENT RECEIVED
   544                              <1> KB_FE		equ	00100000b	; RESEND RECEIVED FLAG
   545                              <1> KB_PR_LED	equ	01000000b	; MODE INDICATOR UPDATE
   546                              <1> KB_ERR		equ	10000000b	; KEYBOARD TRANSMIT ERROR FLAG
   547                              <1> ;----------- FLAGS EQUATES WITHIN @KB_FLAG_3 -----------------------------------
   548                              <1> LC_E1		equ	00000001b	; LAST CODE WAS THE E1 HIDDEN CODE
   549                              <1> LC_E0		equ	00000010b	; LAST CODE WAS THE E0 HIDDEN CODE
   550                              <1> R_CTL_SHIFT	equ	00000100b	; RIGHT CTL KEY DOWN
   551                              <1> R_ALT_SHIFT	equ	00001000b	; RIGHT ALT KEY DOWN
   552                              <1> GRAPH_ON	equ	00001000b	; ALT GRAPHICS KEY DOWN (WT ONLY)	
   553                              <1> KBX		equ	00010000b	; ENHANCED KEYBOARD INSTALLED
   554                              <1> SET_NUM_LK	equ	00100000b	; FORCE NUM LOCK IF READ ID AND KBX
   555                              <1> LC_AB		equ	01000000b	; LAST CHARACTER WAS FIRST ID CHARACTER
   556                              <1> RD_ID		equ	10000000b	; DOING A READ ID (MUST BE BIT0)
   557                              <1> ;
   558                              <1> ;----------- INTERRUPT EQUATES -------------------------------------------------
   559                              <1> EOI		equ	020h		; END OF INTERRUPT COMMAND TO 8259
   560                              <1> INTA00		equ	020h		; 8259 PORT
   561                              <1> 
   562                              <1> 
   563                              <1> kb_int:
   564                              <1> 
   565                              <1> ; 24/07/2022 - TRDOS 386 v2.0.5
   566                              <1> ; 12/04/2021 - TRDOS 386 v2.0.3 (32 bit push/pop)
   567                              <1> ; 17/10/2015 ('ctrlbrk') 
   568                              <1> ; 05/12/2014
   569                              <1> ; 04/12/2014 (derived from pc-xt-286 bios source code -1986-)
   570                              <1> ; 26/08/2014
   571                              <1> ;
   572                              <1> ; 03/06/86  KEYBOARD BIOS
   573                              <1> ;
   574                              <1> ;--- HARDWARE INT 09H -- (IRQ LEVEL 1) ------------------------------------------
   575                              <1> ;										;
   576                              <1> ;	KEYBOARD INTERRUPT ROUTINE						;
   577                              <1> ;										;
   578                              <1> ;--------------------------------------------------------------------------------
   579                              <1> 
   580                              <1> KB_INT_1:
   581 000010ED FB                  <1> 	sti				; ENABLE INTERRUPTS
   582                              <1> 	;push	ebp
   583 000010EE 50                  <1> 	push	eax
   584 000010EF 53                  <1> 	push	ebx
   585 000010F0 51                  <1> 	push	ecx
   586 000010F1 52                  <1> 	push	edx
   587 000010F2 56                  <1> 	push	esi
   588 000010F3 57                  <1> 	push	edi
   589 000010F4 1E                  <1> 	push	ds
   590 000010F5 06                  <1> 	push	es
   591 000010F6 FC                  <1> 	cld				; FORWARD DIRECTION
   592 000010F7 66B81000            <1> 	mov	ax, KDATA
   593 000010FB 8ED8                <1> 	mov	ds, ax
   594 000010FD 8EC0                <1> 	mov	es, ax
   595                              <1> 	;
   596                              <1> 	;-----	WAIT FOR KEYBOARD DISABLE COMMAND TO BE ACCEPTED
   597 000010FF B0AD                <1> 	mov	al, DIS_KBD		; DISABLE THE KEYBOARD COMMAND
   598 00001101 E84B050000          <1> 	call	SHIP_IT			; EXECUTE DISABLE
   599 00001106 FA                  <1> 	cli				; DISABLE INTERRUPTS
   600 00001107 B900000100          <1> 	mov	ecx, 10000h		; SET MAXIMUM TIMEOUT
   601                              <1> KB_INT_01:
   602 0000110C E464                <1> 	in	al, STATUS_PORT		; READ ADAPTER STATUS
   603 0000110E A802                <1> 	test	al, INPT_BUF_FULL	; CHECK INPUT BUFFER FULL STATUS BIT
   604 00001110 E0FA                <1> 	loopnz	KB_INT_01		; WAIT FOR COMMAND TO BE ACCEPTED
   605                              <1> 	;
   606                              <1> 	;-----	READ CHARACTER FROM KEYBOARD INTERFACE
   607 00001112 E460                <1> 	in	al, PORT_A		; READ IN THE CHARACTER
   608                              <1> 	;
   609                              <1> 	;-----	SYSTEM HOOK INT 15H - FUNCTION 4FH (ON HARDWARE INT LEVEL 9H) 	
   610                              <1> 	;mov	ah, 04Fh		; SYSTEM INTERCEPT - KEY CODE FUNCTION
   611                              <1> 	;stc				; SET CY=1 (IN CASE OF IRET)
   612                              <1> 	;int	15h			; CASETTE CALL (AL)=KEY SCAN CODE
   613                              <1> 	;				; RETURNS CY=1 FOR INVALID FUNCTION
   614                              <1> 	;jc	KB_INT_02		; CONTINUE IF CARRY FLAG SET ((AL)=CODE)
   615                              <1> 	;jmp	K26			; EXIT IF SYSTEM HANDLES SCAN CODE
   616                              <1> 	;				; EXT HANDLES HARDWARE EOI AND ENABLE		
   617                              <1> 	;
   618                              <1> 	;-----	CHECK FOR A RESEND COMMAND TO KEYBOARD
   619                              <1> KB_INT_02:				; 	  (AL)= SCAN CODE
   620 00001114 FB                  <1> 	sti				; ENABLE INTERRUPTS AGAIN
   621 00001115 3CFE                <1> 	cmp	al, KB_RESEND		; IS THE INPUT A RESEND
   622 00001117 740E                <1>         je      short KB_INT_4          ; GO IF RESEND
   623                              <1> 	;
   624                              <1> 	;-----	CHECK FOR RESPONSE TO A COMMAND TO KEYBOARD
   625 00001119 3CFA                <1> 	cmp	al, KB_ACK		; IS THE INPUT AN ACKNOWLEDGE
   626 0000111B 7514                <1>         jne     short KB_INT_2          ; GO IF NOT
   627                              <1> 	;
   628                              <1> 	;-----	A COMMAND TO THE KEYBOARD WAS ISSUED
   629 0000111D FA                  <1> 	cli				; DISABLE INTERRUPTS
   630 0000111E 800D[AB670000]10    <1> 	or	byte [KB_FLAG_2], KB_FA ; INDICATE ACK RECEIVED
   631                              <1>         ;jmp	K26                     ; RETURN IF NOT ACK RETURNED FOR DATA)
   632                              <1> 	; 12/04/2021
   633 00001125 EB76                <1> 	jmp	short ID_EX  ; K26
   634                              <1> 	;
   635                              <1> 	;-----	RESEND THE LAST BYTE
   636                              <1> KB_INT_4:
   637 00001127 FA                  <1> 	cli				; DISABLE INTERRUPTS
   638 00001128 800D[AB670000]20    <1> 	or	byte [KB_FLAG_2], KB_FE ; INDICATE RESEND RECEIVED
   639                              <1>         ;jmp	K26                     ; RETURN IF NOT ACK RETURNED FOR DATA)
   640                              <1> 	; 12/04/2021
   641 0000112F EB6C                <1> 	jmp	short ID_EX  ; K26
   642                              <1> 	;
   643                              <1> ;-----	UPDATE MODE INDICATORS IF CHANGE IN STATE
   644                              <1> KB_INT_2:
   645                              <1> 	;push 	ax			; SAVE DATA IN
   646                              <1> 	; 12/04/2021
   647 00001131 50                  <1> 	push	eax
   648 00001132 E8E0050000          <1> 	call	MAKE_LED		; GO GET MODE INDICATOR DATA BYTE
   649 00001137 8A1D[AB670000]      <1> 	mov	bl, [KB_FLAG_2] 	; GET PREVIOUS BITS
   650 0000113D 30C3                <1> 	xor	bl, al			; SEE IF ANY DIFFERENT
   651 0000113F 80E307              <1> 	and	bl, KB_LEDS		; ISOLATE INDICATOR BITS
   652 00001142 7405                <1> 	jz	short UP0		; IF NO CHANGE BYPASS UPDATE
   653 00001144 E863050000          <1> 	call	SND_LED			; GO TURN ON MODE INDICATORS
   654                              <1> UP0:
   655                              <1> 	;pop	ax			; RESTORE DATA IN
   656                              <1> 	; 12/04/2021
   657 00001149 58                  <1> 	pop	eax
   658                              <1> ;------------------------------------------------------------------------
   659                              <1> ;	START OF KEY PROCESSING						;
   660                              <1> ;------------------------------------------------------------------------
   661 0000114A 88C4                <1> 	mov	ah, al			; SAVE SCAN CODE IN AH ALSO
   662                              <1> 	;
   663                              <1> 	;-----	TEST FOR OVERRUN SCAN CODE FROM KEYBOARD
   664 0000114C 3CFF                <1> 	cmp	al, KB_OVER_RUN		; IS THIS AN OVERRUN CHAR
   665                              <1>         ;je	K62			; BUFFER_FULL_BEEP
   666                              <1> 	; 12/04/2021
   667 0000114E 7505                <1> 	jne	short K16
   668 00001150 E9E8040000          <1> 	jmp	K62
   669                              <1> K16:	
   670 00001155 8A3D[AC670000]      <1> 	mov	bh, [KB_FLAG_3]		; LOAD FLAGS FOR TESTING
   671                              <1> 	;
   672                              <1> 	;-----	TEST TO SEE IF A READ_ID IS IN PROGRESS
   673 0000115B F6C7C0              <1> 	test 	bh, RD_ID+LC_AB 	; ARE WE DOING A READ ID?
   674 0000115E 7442                <1> 	jz	short NOT_ID		; CONTINUE IF NOT
   675 00001160 7914                <1> 	jns	short TST_ID_2		; IS THE RD_ID FLAG ON?
   676 00001162 3CAB                <1> 	cmp	al, ID_1		; IS THIS THE 1ST ID CHARACTER?
   677 00001164 7507                <1> 	jne	short RST_RD_ID
   678 00001166 800D[AC670000]40    <1> 	or	byte [KB_FLAG_3], LC_AB ; INDICATE 1ST ID WAS OK
   679                              <1> RST_RD_ID:
   680 0000116D 8025[AC670000]7F    <1> 	and	byte [KB_FLAG_3], ~RD_ID ; RESET THE READ ID FLAG
   681 00001174 EB27                <1>         jmp	short ID_EX		; AND EXIT
   682                              <1> 	; 12/04/2021
   683                              <1> 	;jmp	K26
   684                              <1> 	;
   685                              <1> TST_ID_2:
   686 00001176 8025[AC670000]BF    <1> 	and	byte [KB_FLAG_3], ~LC_AB ; RESET FLAG
   687 0000117D 3C54                <1> 	cmp	al, ID_2A		; IS THIS THE 2ND ID CHARACTER?
   688 0000117F 7415                <1>         je	short KX_BIT		; JUMP IF SO
   689 00001181 3C41                <1> 	cmp	al, ID_2		; IS THIS THE 2ND ID CHARACTER?
   690 00001183 7518                <1>         jne	short ID_EX		; LEAVE IF NOT
   691                              <1> 	; 12/04/2021
   692                              <1> 	;jne	K26
   693                              <1> 	;
   694                              <1> 	;-----	A READ ID SAID THAT IT WAS ENHANCED KEYBOARD
   695 00001185 F6C720              <1> 	test	bh, SET_NUM_LK 		; SHOULD WE SET NUM LOCK?
   696 00001188 740C                <1>         jz      short KX_BIT		; EXIT IF NOT
   697 0000118A 800D[A9670000]20    <1> 	or	byte [KB_FLAG], NUM_STATE ; FORCE NUM LOCK ON
   698 00001191 E816050000          <1> 	call	SND_LED			; GO SET THE NUM LOCK INDICATOR
   699                              <1> KX_BIT:
   700 00001196 800D[AC670000]10    <1> 	or	byte [KB_FLAG_3], KBX	; INDICATE ENHANCED KEYBOARD WAS FOUND
   701 0000119D E9CB010000          <1> ID_EX:	jmp     K26			; EXIT
   702                              <1> 	;
   703                              <1> NOT_ID:
   704 000011A2 3CE0                <1> 	cmp	al, MC_E0		; IS THIS THE GENERAL MARKER CODE?
   705 000011A4 7509                <1> 	jne	short TEST_E1
   706 000011A6 800D[AC670000]12    <1> 	or	byte [KB_FLAG_3], LC_E0+KBX ; SET FLAG BIT, SET KBX, AND
   707 000011AD EB0B                <1> 	jmp	short EXIT		; THROW AWAY THIS CODE
   708                              <1> 	; 12/04/2021
   709                              <1> 	;jmp	K26A	
   710                              <1> TEST_E1:	
   711 000011AF 3CE1                <1> 	cmp	al, MC_E1		; IS THIS THE PAUSE KEY?
   712 000011B1 750C                <1> 	jne	short NOT_HC
   713 000011B3 800D[AC670000]11    <1> 	or	byte [KB_FLAG_3], LC_E1+KBX ; SET FLAG BIT, SET KBX, AND
   714 000011BA E9B5010000          <1> EXIT:	jmp	K26A			; THROW AWAY THIS CODE
   715                              <1> 	;
   716                              <1> NOT_HC:
   717 000011BF 247F                <1> 	and	al, 07Fh		; TURN OFF THE BREAK BIT
   718 000011C1 F6C702              <1> 	test	bh, LC_E0		; LAST CODE THE E0 MARKER CODE
   719 000011C4 7410                <1> 	jz	short NOT_LC_E0		; JUMP IF NOT
   720                              <1> 	;
   721 000011C6 BF[96660000]        <1> 	mov	edi, _K6+6		; IS THIS A SHIFT KEY?
   722 000011CB AE                  <1> 	scasb
   723                              <1> 	;je	K26 ; K16B              ; YES, THROW AWAY & RESET FLAG
   724                              <1> 	; 12/04/2021
   725 000011CC 745B                <1> 	je	short K16B ; K26
   726 000011CE AE                  <1> 	scasb
   727 000011CF 756D                <1> 	jne	short K16A		; NO, CONTINUE KEY PROCESSING
   728                              <1> 	;jmp	short K16B		; YES, THROW AWAY & RESET FLAG
   729 000011D1 E997010000          <1> 	jmp	K26
   730                              <1> 	;
   731                              <1> NOT_LC_E0:
   732 000011D6 F6C701              <1> 	test	bh, LC_E1		; LAST CODE THE E1 MARKER CODE?
   733 000011D9 7425                <1> 	jz	short T_SYS_KEY		; JUMP IF NOT
   734 000011DB B904000000          <1> 	mov	ecx, 4			; LENGHT OF SEARCH
   735 000011E0 BF[94660000]        <1> 	mov	edi, _K6+4		; IS THIS AN ALT, CTL, OR SHIFT?
   736 000011E5 F2AE                <1> 	repne	scasb			; CHECK IT
   737 000011E7 74D1                <1> 	je	short EXIT		; THROW AWAY IF SO
   738                              <1> 	; 12/04/2021
   739                              <1> 	;je	K26A			
   740                              <1> 	;
   741 000011E9 3C45                <1> 	cmp	al, NUM_KEY		; IS IT THE PAUSE KEY?
   742 000011EB 753C                <1> 	jne	short K16B		; NO, THROW AWAY & RESET FLAG
   743                              <1> 	; 12/04/2021
   744                              <1> 	;jne	K26
   745 000011ED F6C480              <1> 	test	ah, 80h			; YES, IS IT THE BREAK OF THE KEY?
   746 000011F0 7537                <1> 	jnz	short K16B		; YES, THROW THIS AWAY, TOO	
   747                              <1> 	; 24/07/2022
   748                              <1> 	;jnz	K26
   749                              <1>         ; 20/02/2015 
   750 000011F2 F605[AA670000]08    <1> 	test	byte [KB_FLAG_1],HOLD_STATE ; NO, ARE WE PAUSED ALREADY?
   751 000011F9 752E                <1> 	jnz	short K16B		; YES, THROW AWAY
   752                              <1> 	; 12/04/2021
   753                              <1> 	;jnz	K26
   754 000011FB E9B1020000          <1> 	jmp     K39P                    ; NO, THIS IS THE REAL PAUSE STATE
   755                              <1> 	;
   756                              <1> 	;-----	TEST FOR SYSTEM KEY
   757                              <1> T_SYS_KEY:
   758 00001200 3C54                <1> 	cmp	al, SYS_KEY		; IS IT THE SYSTEM KEY?
   759 00001202 753A                <1> 	jnz	short K16A		; CONTINUE IF NOT
   760                              <1> 	;
   761 00001204 F6C480              <1> 	test	ah, 80h			; CHECK IF THIS A BREAK CODE
   762 00001207 7525                <1> 	jnz	short K16C		; DO NOT TOUCH SYSTEM INDICATOR IF TRUE
   763                              <1> 	;
   764 00001209 F605[AA670000]04    <1> 	test	byte [KB_FLAG_1], SYS_SHIFT ; SEE IF IN SYSTEM KEY HELD DOWN 
   765 00001210 7517                <1> 	jnz	short K16B		; IF YES, DO NOT PROCESS SYSTEM INDICATOR	
   766                              <1> 	; 12/04/2021
   767                              <1> 	;jnz	K26		
   768                              <1> 	;
   769 00001212 800D[AA670000]04    <1> 	or	byte [KB_FLAG_1], SYS_SHIFT ; INDICATE SYSTEM KEY DEPRESSED
   770 00001219 B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
   771 0000121B E620                <1> 	out	20h, al ;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
   772                              <1> 					; INTERRUPT-RETURN-NO-EOI
   773 0000121D B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
   774 0000121F E82D040000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
   775                              <1> 	; !!! SYSREQ !!! function/system call (INTERRUPT) must be here !!!
   776                              <1> 	;MOV	AL, 8500H		; FUNCTION VALUE FOR MAKE OF SYSTEM KEY
   777                              <1> 	;STI				; MAKE SURE INTERRUPTS ENABLED
   778                              <1> 	;INT	15H			; USER INTERRUPT	
   779 00001224 E957010000          <1>         jmp     K27A                    ; END PROCESSING
   780                              <1> 	;
   781 00001229 E93F010000          <1> K16B:	jmp	K26			; IGNORE SYSTEM KEY
   782                              <1> 	;
   783                              <1> K16C:
   784 0000122E 8025[AA670000]FB    <1> 	and	byte [KB_FLAG_1], ~SYS_SHIFT ; TURN OFF SHIFT KEY HELD DOWN
   785 00001235 B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
   786 00001237 E620                <1> 	out	20h, al ;out INTA00, al ; SEND COMMAND TO INTERRUPT CONTROL PORT
   787                              <1> 					; INTERRUPT-RETURN-NO-EOI
   788                              <1> 	;MOV	AL, ENA_KBD		; INSURE KEYBOARD IS ENABLED
   789                              <1> 	;CALL	SHIP_IT			; EXECUTE ENABLE
   790                              <1> 	;
   791                              <1> 	;MOV	AX, 8501H		; FUNCTION VALUE FOR BREAK OF SYSTEM KEY
   792                              <1> 	;STI				; MAKE SURE INTERRUPTS ENABLED
   793                              <1> 	;INT	15H			; USER INTERRUPT
   794                              <1> 	;JMP	K27A			; INGONRE SYSTEM KEY				
   795                              <1> 	;
   796 00001239 E93B010000          <1> 	jmp     K27			; IGNORE SYSTEM KEY
   797                              <1> 	;
   798                              <1> 	;-----	TEST FOR SHIFT KEYS
   799                              <1> K16A:
   800 0000123E 8A1D[A9670000]      <1> 	mov	bl, [KB_FLAG]		; PUT STATE FLAGS IN BL
   801 00001244 BF[90660000]        <1> 	mov	edi, _K6		; SHIFT KEY TABLE offset
   802 00001249 B908000000          <1> 	mov	ecx, _K6L		; LENGTH
   803 0000124E F2AE                <1> 	repne	scasb			; LOOK THROUGH THE TABLE FOR A MATCH
   804 00001250 88E0                <1> 	mov	al, ah			; RECOVER SCAN CODE
   805                              <1>         ;jne	K25                     ; IF NO MATCH, THEN SHIFT NOT FOUND
   806                              <1> 	; 12/04/2021
   807 00001252 7405                <1> 	je	short K17
   808 00001254 E9FC000000          <1> 	jmp	K25
   809                              <1> 	;
   810                              <1> 	;------	SHIFT KEY FOUND
   811                              <1> K17:
   812 00001259 81EF[91660000]      <1>         sub     edi, _K6+1              ; ADJUST PTR TO SCAN CODE MATCH
   813 0000125F 8AA7[98660000]      <1>        	mov     ah, [edi+_K7]       	; GET MASK INTO AH
   814 00001265 B102                <1> 	mov	cl, 2			; SETUP COUNT FOR FLAG SHIFTS
   815 00001267 A880                <1> 	test	al, 80h			; TEST FOR BREAK KEY
   816                              <1> 	;jnz	short K23		; JUMP OF BREAK
   817                              <1> 	; 12/04/2021
   818 00001269 7405                <1> 	jz	short K17C
   819 0000126B E981000000          <1> 	jmp	K23
   820                              <1> 	;
   821                              <1> 	;-----	SHIFT MAKE FOUND, DETERMINE SET OR TOGGLE
   822                              <1> K17C:
   823 00001270 80FC10              <1> 	cmp	ah, SCROLL_SHIFT
   824 00001273 7324                <1> 	jae	short K18		; IF SCROLL SHIFT OR ABOVE, TOGGLE KEY
   825                              <1> 	;
   826                              <1> 	;-----	PLAIN SHIFT KEY, SET SHIFT ON
   827 00001275 0825[A9670000]      <1> 	or	[KB_FLAG], ah		; TURN ON SHIFT BIT
   828 0000127B A80C                <1>         test	al, CTL_SHIFT+ALT_SHIFT ; IS IT ALT OR CTRL?
   829                              <1> 	;;jnz	short K17D		; YES, MORE FLAGS TO SET
   830                              <1> 	;jz	K26			; NO, INTERRUPT RETURN
   831                              <1> 	; 12/04/2021
   832 0000127D 7415                <1> 	jz	short k17f
   833                              <1> K17D:
   834 0000127F F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OF NEW KEYS?
   835 00001282 7408                <1> 	jz 	short K17E		; NO, JUMP
   836 00001284 0825[AC670000]      <1> 	or	[KB_FLAG_3], ah		; SET BITS FOR RIGHT CTRL, ALT
   837                              <1> 	;jmp	K26			; INTERRUPT RETURN
   838                              <1> 	; 12/04/2021
   839 0000128A EB08                <1> 	jmp	short k17f
   840                              <1> K17E:
   841 0000128C D2EC                <1> 	shr	ah, cl			; MOVE FLAG BITS TWO POSITIONS
   842 0000128E 0825[AA670000]      <1> 	or	[KB_FLAG_1], ah		; SET BITS FOR LEFT CTRL, ALT
   843                              <1> k17f:	; 12/04/2021
   844 00001294 E9D4000000          <1> 	jmp	K26
   845                              <1> 	;
   846                              <1> 	;-----	TOGGLED SHIFT KEY, TEST FOR 1ST MAKE OR NOT
   847                              <1> K18:					; SHIFT-TOGGLE
   848 00001299 F6C304              <1> 	test	bl, CTL_SHIFT 		; CHECK CTL SHIFT STATE
   849 0000129C 7402                <1> 	jz	short K18A              ; JUMP IF NOT CTL STATE
   850                              <1>         ;jnz	K25                     ; JUMP IF CTL STATE
   851                              <1> 	; 12/04/2021
   852 0000129E EB1C                <1> 	jmp	short k20a ; K25
   853                              <1> K18A:
   854 000012A0 3C52                <1> 	cmp	al, INS_KEY		; CHECK FOR INSERT KEY
   855 000012A2 7522                <1> 	jne	short K22		; JUMP IF NOT INSERT KEY
   856 000012A4 F6C308              <1> 	test	bl, ALT_SHIFT 		; CHECK FOR ALTERNATE SHIFT
   857 000012A7 7402                <1>       	jz	short K18B		; JUMP IF NOT ALTERNATE SHIFT	
   858                              <1>         ;jnz	K25			; JUMP IF ALTERNATE SHIFT
   859                              <1> 	; 12/04/2021
   860 000012A9 EB11                <1> 	jmp	short k20a ; K25
   861                              <1> K18B:
   862 000012AB F6C702              <1> 	test	bh, LC_E0 ;20/02/2015	; IS THIS NEW INSERT KEY?
   863 000012AE 7516                <1> 	jnz	short K22		; YES, THIS ONE'S NEVER A '0'
   864                              <1> K19:	
   865 000012B0 F6C320              <1> 	test	bl, NUM_STATE 		; CHECK FOR BASE STATE
   866 000012B3 750C                <1> 	jnz	short K21		; JUMP IF NUM LOCK IS ON
   867 000012B5 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; TEST FOR SHIFT STATE
   868 000012B8 740C                <1> 	jz	short K22		; JUMP IF BASE STATE
   869                              <1> K20:					; NUMERIC ZERO, NOT INSERT KEY
   870 000012BA 88C4                <1> 	mov	ah, al			; PUT SCAN CODE BACK IN AH
   871                              <1> k20a:	; 12/04/2021
   872 000012BC E994000000          <1>         jmp     K25                     ; NUMERAL '0', STNDRD. PROCESSING
   873                              <1> K21:					; MIGHT BE NUMERIC
   874 000012C1 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT
   875 000012C4 74F4                <1> 	jz	short K20		; IS NUMERIC, STD. PROC.
   876                              <1> 	;
   877                              <1> K22:					; SHIFT TOGGLE KEY HIT; PROCESS IT
   878 000012C6 8425[AA670000]      <1> 	test	ah, [KB_FLAG_1] 	; IS KEY ALREADY DEPRESSED
   879                              <1>         ;jnz	short K26		; JUMP IF KEY ALREADY DEPRESSED
   880                              <1> 	; 12/04/2021
   881 000012CC 75C6                <1> 	jnz	short k17f ; K26
   882                              <1> K22A:
   883 000012CE 0825[AA670000]      <1>         or      [KB_FLAG_1], ah 	; INDICATE THAT THE KEY IS DEPRESSED
   884 000012D4 3025[A9670000]      <1> 	xor	[KB_FLAG], ah		; TOGGLE THE SHIFT STATE
   885                              <1> 	;
   886                              <1> 	;-----	TOGGLE LED IF CAPS, NUM  OR SCROLL KEY DEPRESSED
   887 000012DA F6C470              <1> 	test	ah, CAPS_SHIFT+NUM_SHIFT+SCROLL_SHIFT ; SHIFT TOGGLE?
   888 000012DD 7407                <1> 	jz	short K22B		; GO IF NOT
   889                              <1> 	;
   890                              <1> 	; 12/04/2021 (32 bit push/pop)
   891 000012DF 50                  <1> 	push	eax ; push ax		; SAVE SCAN CODE AND SHIFT MASK
   892 000012E0 E8C7030000          <1> 	call	SND_LED			; GO TURN MODE INDICATORS ON
   893 000012E5 58                  <1> 	pop	eax ; pop ax		; RESTORE SCAN CODE
   894                              <1> K22B:
   895 000012E6 3C52                <1> 	cmp	al, INS_KEY		; TEST FOR 1ST MAKE OF INSERT KEY
   896                              <1>         ;jne	short K26		; JUMP IF NOT INSERT KEY
   897                              <1> 	; 12/04/2021
   898 000012E8 75AA                <1> 	jne	short k17f ; K26
   899 000012EA 88C4                <1> 	mov	ah, al		        ; SCAN CODE IN BOTH HALVES OF AX
   900 000012EC E999000000          <1>         jmp	K28                     ; FLAGS UPDATED, PROC. FOR BUFFER
   901                              <1> 	;
   902                              <1> 	;-----	BREAK SHIFT FOUND
   903                              <1> K23:					; BREAK-SHIFT-FOUND
   904 000012F1 80FC10              <1> 	cmp	ah, SCROLL_SHIFT	; IS THIS A TOGGLE KEY
   905 000012F4 F6D4                <1> 	not	ah			; INVERT MASK
   906 000012F6 7355                <1> 	jae	short K24		; YES, HANDLE BREAK TOGGLE
   907 000012F8 2025[A9670000]      <1> 	and	[KB_FLAG], ah		; TURN OFF SHIFT BIT
   908 000012FE 80FCFB              <1> 	cmp	ah, ~CTL_SHIFT		; IS THIS ALT OR CTL?
   909 00001301 7730                <1> 	ja	short K23D		; NO, ALL DONE
   910                              <1> 	;
   911 00001303 F6C702              <1> 	test	bh, LC_E0		; 2ND ALT OR CTL?
   912 00001306 7408                <1> 	jz	short K23A		; NO, HANSLE NORMALLY
   913 00001308 2025[AC670000]      <1> 	and 	[KB_FLAG_3], ah		; RESET BIT FOR RIGHT ALT OR CTL
   914 0000130E EB08                <1> 	jmp	short K23B		; CONTINUE
   915                              <1> K23A:
   916 00001310 D2FC                <1> 	sar	ah, cl			; MOVE THE MASK BIT TWO POSITIONS
   917 00001312 2025[AA670000]      <1> 	and	[KB_FLAG_1], ah		; RESET BIT FOR LEFT ALT AND CTL
   918                              <1> K23B:
   919 00001318 88C4                <1> 	mov	ah, al			; SAVE SCAN CODE
   920 0000131A A0[AC670000]        <1> 	mov	al, [KB_FLAG_3]		; GET RIGHT ALT & CTRL FLAGS
   921 0000131F D2E8                <1> 	shr	al, cl			; MOVE TO BITS 1 & 0
   922 00001321 0A05[AA670000]      <1> 	or	al, [KB_FLAG_1]		; PUT IN LEFT ALT & CTL FLAGS
   923 00001327 D2E0                <1> 	shl	al, cl			; MOVE BACK TO BITS 3 & 2
   924 00001329 240C                <1> 	and	al, ALT_SHIFT+CTL_SHIFT ; FILTER OUT OTHER GARBAGE
   925 0000132B 0805[A9670000]      <1> 	or	[KB_FLAG], al		; PUT RESULT IN THE REAL FLAGS	
   926 00001331 88E0                <1> 	mov	al, ah
   927                              <1> K23D:
   928 00001333 3CB8                <1> 	cmp	al, ALT_KEY+80h		; IS THIS ALTERNATE SHIFT RELEASE
   929 00001335 7536                <1> 	jne	short K26		; INTERRUPT RETURN
   930                              <1> 	;	
   931                              <1> 	;-----	ALTERNATE SHIFT KEY RELEASED, GET THE VALUE INTO BUFFER
   932 00001337 A0[AD670000]        <1> 	mov	al, [ALT_INPUT]
   933 0000133C B400                <1> 	mov	ah, 0			; SCAN CODE OF 0
   934 0000133E 8825[AD670000]      <1> 	mov	[ALT_INPUT], ah 	; ZERO OUT THE FIELD
   935 00001344 3C00                <1> 	cmp	al, 0			; WAS THE INPUT = 0?
   936 00001346 7425                <1> 	je	short K26		; INTERRUPT_RETURN
   937                              <1>         ; 29/01/2016
   938                              <1> 	;jmp	K61			; IT WASN'T, SO PUT IN BUFFER
   939 00001348 E9AB020000          <1> 	jmp	_K60
   940                              <1> 	;
   941                              <1> K24:					; BREAK-TOGGLE
   942 0000134D 2025[AA670000]      <1> 	and	[KB_FLAG_1], ah 	; INDICATE NO LONGER DEPRESSED
   943 00001353 EB18                <1> 	jmp	short K26		; INTERRUPT_RETURN
   944                              <1> 	;
   945                              <1> 	;-----	TEST FOR HOLD STATE
   946                              <1> 					; AL, AH = SCAN CODE
   947                              <1> K25:					; NO-SHIFT-FOUND
   948 00001355 3C80                <1> 	cmp	al, 80h			; TEST FOR BREAK KEY
   949 00001357 7314                <1> 	jae	short K26		; NOTHING FOR BREAK CHARS FROM HERE ON
   950 00001359 F605[AA670000]08    <1> 	test	byte [KB_FLAG_1], HOLD_STATE ; ARE WE IN HOLD STATE
   951 00001360 7428                <1> 	jz	short K28		; BRANCH AROUND TEST IF NOT
   952 00001362 3C45                <1> 	cmp	al, NUM_KEY
   953 00001364 7407                <1> 	je	short K26		; CAN'T END HOLD ON NUM_LOCK
   954 00001366 8025[AA670000]F7    <1> 	and	byte [KB_FLAG_1], ~HOLD_STATE ; TURN OFF THE HOLD STATE BIT
   955                              <1> K26:
   956 0000136D 8025[AC670000]FC    <1> 	and	byte [KB_FLAG_3], ~(LC_E0+LC_E1) ; RESET LAST CHAR H.C. FLAG
   957                              <1> K26A:					; INTERRUPT-RETURN
   958 00001374 FA                  <1> 	cli				; TURN OFF INTERRUPTS
   959 00001375 B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
   960 00001377 E620                <1> 	out	20h, al	;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
   961                              <1> K27:					; INTERRUPT-RETURN-NO-EOI
   962 00001379 B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
   963 0000137B E8D1020000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
   964                              <1> K27A:
   965 00001380 FA                  <1> 	cli				; DISABLE INTERRUPTS
   966                              <1> 	;;mov	byte [intflg], 0 ; 07/01/2017 ;; 15/01/2017
   967 00001381 07                  <1> 	pop	es			; RESTORE REGISTERS
   968 00001382 1F                  <1> 	pop	ds
   969 00001383 5F                  <1> 	pop	edi
   970 00001384 5E                  <1> 	pop	esi
   971 00001385 5A                  <1> 	pop	edx
   972 00001386 59                  <1> 	pop	ecx
   973 00001387 5B                  <1> 	pop	ebx
   974 00001388 58                  <1> 	pop	eax
   975                              <1> 	;pop	ebp
   976 00001389 CF                  <1> 	iretd				; RETURN
   977                              <1> 
   978                              <1> 	;-----	NOT IN	HOLD STATE
   979                              <1> K28:					; NO-HOLD-STATE
   980 0000138A 3C58                <1> 	cmp	al, 88			; TEST FOR OUT-OF-RANGE SCAN CODES
   981 0000138C 77DF                <1> 	ja	short K26		; IGNORE IF OUT-OF-RANGE	
   982                              <1> 	;
   983 0000138E F6C308              <1> 	test	bl, ALT_SHIFT 		; ARE WE IN ALTERNATE SHIFT
   984 00001391 740E                <1>         jz	short K28A		; IF NOT ALTERNATE
   985                              <1>         ; 12/04/2021
   986                              <1> 	;jz	K38
   987                              <1> 	;
   988 00001393 F6C710              <1> 	test	bh, KBX			; IS THIS THE ENCHANCED KEYBOARD?
   989 00001396 740E                <1> 	jz	short K29		; NO, ALT STATE IS REAL
   990                              <1> 	 ;28/02/2015
   991 00001398 F605[AA670000]04    <1> 	test	byte [KB_FLAG_1], SYS_SHIFT ; YES, IS SYSREQ KEY DOWN?
   992 0000139F 7405                <1> 	jz	short K29		;  NO, ALT STATE IS REAL
   993                              <1> 	; 12/04/2021
   994                              <1> 	;jnz	K38			; YES, THIS IS PHONY ALT STATE 
   995                              <1>         ;				; DUE TO PRESSING SYSREQ	
   996 000013A1 E9C4000000          <1> K28A:	jmp	K38
   997                              <1> 	;
   998                              <1> 	;-----	TEST FOR RESET KEY SEQUENCE (CTL ALT DEL)
   999                              <1> K29:					; TEST-RESET
  1000 000013A6 F6C304              <1> 	test	bl, CTL_SHIFT 		; ARE WE IN CONTROL SHIFT ALSO?
  1001 000013A9 740B                <1> 	jz	short K31		; NO_RESET
  1002 000013AB 3C53                <1> 	cmp	al, DEL_KEY		; CTL-ALT STATE, TEST FOR DELETE KEY
  1003 000013AD 7507                <1> 	jne	short K31		; NO_RESET, IGNORE
  1004                              <1> 	;
  1005                              <1> 	;-----	CTL-ALT-DEL HAS BEEN FOUND
  1006                              <1>  	; 26/08/2014
  1007                              <1> cpu_reset:
  1008                              <1> 	; IBM PC/AT ROM BIOS source code - 10/06/85 (TEST4.ASM - PROC_SHUTDOWN)
  1009                              <1> 	; Send FEh (system reset command) to the keyboard controller.
  1010 000013AF B0FE                <1> 	mov	al, SHUT_CMD		; SHUTDOWN COMMAND
  1011 000013B1 E664                <1> 	out	STATUS_PORT, al		; SEND TO KEYBOARD CONTROL PORT
  1012                              <1> khere:
  1013 000013B3 F4                  <1> 	hlt				; WAIT FOR 80286 RESET
  1014 000013B4 EBFD                <1> 	jmp 	short khere		; INSURE HALT
  1015                              <1> 	;
  1016                              <1> 	;-----	IN ALTERNATE SHIFT, RESET NOT FOUND
  1017                              <1> K31:					; NO-RESET
  1018 000013B6 3C39                <1> 	cmp	al, 57			; TEST FOR SPACE KEY
  1019 000013B8 7507                <1> 	jne	short K311		; NOT THERE
  1020 000013BA B020                <1> 	mov	al, ' '			; SET SPACE CHAR
  1021                              <1> k31a:	; 12/04/2021
  1022 000013BC E929020000          <1>         jmp     K57                     ; BUFFER_FILL
  1023                              <1> K311:
  1024 000013C1 3C0F                <1> 	cmp	al, 15			; TEST FOR TAB KEY
  1025 000013C3 7506                <1> 	jne	short K312		; NOT THERE
  1026 000013C5 66B800A5            <1> 	mov	ax, 0A500h		; SET SPECIAL CODE FOR ALT-TAB
  1027                              <1>         ;jmp	K57			; BUFFER_FILL
  1028                              <1> 	; 12/04/2021
  1029 000013C9 EBF1                <1> 	jmp	short k31a
  1030                              <1> K312:
  1031 000013CB 3C4A                <1> 	cmp	al, 74			; TEST FOR KEY PAD -
  1032                              <1>         ;je	short K37B		; GO PROCESS
  1033                              <1> 	; 12/04/2021
  1034 000013CD 7404                <1> 	je	short k312a
  1035 000013CF 3C4E                <1> 	cmp	al, 78			; TEST FOR KEY PAD +
  1036                              <1>         ;je	short K37B		; GO PROCESS
  1037                              <1> 	; 12/04/2021
  1038 000013D1 7505                <1> 	jne	short K32
  1039                              <1> k312a:
  1040 000013D3 E988000000          <1> 	jmp	K37B	
  1041                              <1> 	;
  1042                              <1> 	;-----	LOOK FOR KEY PAD ENTRY
  1043                              <1> K32:					; ALT-KEY-PAD
  1044 000013D8 BF[6C660000]        <1> 	mov	edi, K30		; ALT-INPUT-TABLE offset
  1045 000013DD B90A000000          <1> 	mov	ecx, 10			; LOOK FOR ENTRY USING KEYPAD
  1046 000013E2 F2AE                <1> 	repne	scasb			; LOOK FOR MATCH
  1047 000013E4 7521                <1> 	jne	short K33		; NO_ALT_KEYPAD
  1048 000013E6 F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OF THE NEW KEYS?
  1049 000013E9 7579                <1>         jnz	short K37C		; YES, JUMP, NOT NUMPAD KEY
  1050 000013EB 81EF[6D660000]      <1> 	sub	edi, K30+1		; DI NOW HAS ENTRY VALUE
  1051 000013F1 A0[AD670000]        <1> 	mov	al, [ALT_INPUT] 	; GET THE CURRENT BYTE
  1052 000013F6 B40A                <1> 	mov	ah, 10			; MULTIPLY BY 10
  1053 000013F8 F6E4                <1> 	mul	ah
  1054 000013FA 6601F8              <1> 	add	ax, di			; ADD IN THE LATEST ENTRY
  1055 000013FD A2[AD670000]        <1> 	mov	[ALT_INPUT], al 	; STORE IT AWAY
  1056                              <1> K32A:
  1057 00001402 E966FFFFFF          <1>         jmp     K26                     ; THROW AWAY THAT KEYSTROKE
  1058                              <1> 	;
  1059                              <1> 	;-----	LOOK FOR SUPERSHIFT ENTRY
  1060                              <1> K33:					; NO-ALT-KEYPAD
  1061 00001407 C605[AD670000]00    <1>         mov     byte [ALT_INPUT], 0     ; ZERO ANY PREVIOUS ENTRY INTO INPUT
  1062 0000140E B91A000000          <1> 	mov	ecx, 26			; (DI),(ES) ALREADY POINTING
  1063 00001413 F2AE                <1> 	repne	scasb			; LOOK FOR MATCH IN ALPHABET
  1064 00001415 7445                <1> 	je	short K37A		; MATCH FOUND, GO FILLL THE BUFFER
  1065                              <1> 	;
  1066                              <1> 	;-----	LOOK FOR TOP ROW OF ALTERNATE SHIFT
  1067                              <1> K34:					; ALT-TOP-ROW
  1068 00001417 3C02                <1> 	cmp	al, 2			; KEY WITH '1' ON IT
  1069 00001419 7245                <1> 	jb	short K37B		; MUST BE ESCAPE
  1070 0000141B 3C0D                <1> 	cmp	al, 13			; IS IT IN THE REGION
  1071 0000141D 7705                <1> 	ja	short K35		; NO, ALT SOMETHING ELSE
  1072 0000141F 80C476              <1> 	add	ah, 118			; CONVERT PSEUDO SCAN CODE TO RANGE
  1073 00001422 EB38                <1> 	jmp	short K37A		; GO FILL THE BUFFER
  1074                              <1> 	;
  1075                              <1> 	;-----	TRANSLATE ALTERNATE SHIFT PSEUDO SCAN CODES
  1076                              <1> K35:					; ALT-FUNCTION
  1077 00001424 3C57                <1> 	cmp	al, F11_M		; IS IT F11?	
  1078 00001426 7209                <1> 	jb	short K35A ; 20/02/2015	; NO, BRANCH
  1079 00001428 3C58                <1> 	cmp	al, F12_M		; IS IT F12?
  1080 0000142A 7705                <1> 	ja	short K35A ; 20/02/2015	; NO, BRANCH
  1081 0000142C 80C434              <1> 	add	ah, 52			; CONVERT TO PSEUDO SCAN CODE
  1082 0000142F EB2B                <1> 	jmp	short K37A		; GO FILL THE BUFFER
  1083                              <1> K35A:
  1084 00001431 F6C702              <1> 	test	bh, LC_E0		; DO WE HAVE ONE OF THE NEW KEYS?
  1085 00001434 741B                <1> 	jz	short K37		; NO, JUMP
  1086 00001436 3C1C                <1> 	cmp	al, 28			; TEST FOR KEYPAD ENTER
  1087 00001438 7506                <1>         jne     short K35B              ; NOT THERE
  1088 0000143A 66B800A6            <1> 	mov	ax, 0A600h		; SPECIAL CODE
  1089                              <1> 	;jmp	K57			; BUFFER FILL
  1090                              <1> 	; 12/04/2021
  1091 0000143E EB0C                <1> 	jmp	short k35c
  1092                              <1> K35B:
  1093 00001440 3C53                <1> 	cmp	al, 83			; TEST FOR DELETE KEY
  1094 00001442 7420                <1> 	je	short K37C		; HANDLE WITH OTHER EDIT KEYS
  1095 00001444 3C35                <1> 	cmp	al, 53			; TEST FOR KEYPAD /
  1096 00001446 75BA                <1> 	jne	short K32A		; NOT THERE, NO OTHER E0 SPECIALS
  1097                              <1>         ; 12/04/2021
  1098                              <1> 	;jne	K26
  1099 00001448 66B800A4            <1> 	mov	ax, 0A400h		; SPECIAL CODE1
  1100                              <1> k35c:	; 12/04/2021
  1101 0000144C E999010000          <1> 	jmp	K57			; BUFFER FILL
  1102                              <1> K37:
  1103 00001451 3C3B                <1> 	cmp	al, 59			; TEST FOR FUNCTION KEYS (F1)
  1104 00001453 720B                <1>         jb      short K37B		; NO FN, HANDLE W/OTHER EXTENDED
  1105 00001455 3C44                <1> 	cmp	al, 68			; IN KEYPAD REGION?
  1106 00001457 77A9                <1> 	ja	short K32A		; IF SO, IGNORE
  1107                              <1> 	; 12/04/2021
  1108                              <1> 	;ja	K26
  1109 00001459 80C42D              <1> 	add	ah, 45			; CONVERT TO PSEUDO SCAN CODE
  1110                              <1> K37A:
  1111 0000145C B000                <1> 	mov	al, 0			; ASCII CODE OF ZERO
  1112                              <1> 	;jmp	K57			; PUT IT IN THE BUFFER
  1113                              <1> 	; 12/04/2021
  1114 0000145E EBEC                <1> 	jmp	short k35c
  1115                              <1> K37B:
  1116 00001460 B0F0                <1> 	mov	al, 0F0h		; USE SPECIAL ASCII CODE
  1117                              <1> 	;jmp	K57			; PUT IT IN THE BUFFER
  1118                              <1> 	; 12/04/2021
  1119 00001462 EBE8                <1> 	jmp	short k35c
  1120                              <1> K37C:
  1121 00001464 0450                <1> 	add	al, 80			; CONVERT SCAN CODE (EDIT KEYS)
  1122 00001466 88C4                <1> 	mov	ah, al			; (SCAN CODE NOT IN AH FOR INSERT)
  1123 00001468 EBF2                <1> 	jmp     short K37A              ; PUT IT IN THE BUFFER
  1124                              <1> 	;
  1125                              <1> 	;-----	NOT IN ALTERNATE SHIFT
  1126                              <1> K38:					; NOT-ALT-SHIFT
  1127                              <1> 					; BL STILL HAS SHIFT FLAGS
  1128 0000146A F6C304              <1> 	test	bl, CTL_SHIFT 		; ARE WE IN CONTROL SHIFT?
  1129                              <1> 	;;jnz	short K38A		; YES, START PROCESSING	
  1130                              <1>         ;jz	K44			; NOT-CTL-SHIFT
  1131                              <1> 	; 12/04/2021
  1132 0000146D 7505                <1> 	jnz	short K38A		; YES, START PROCESSING	
  1133 0000146F E9AB000000          <1> 	jmp	K44			; NOT-CTL-SHIFT
  1134                              <1> 	;
  1135                              <1> 	;-----	CONTROL SHIFT, TEST SPECIAL CHARACTERS
  1136                              <1> 	;-----	TEST FOR BREAK
  1137                              <1> K38A:
  1138 00001474 3C46                <1> 	cmp	al, SCROLL_KEY		; TEST FOR BREAK
  1139 00001476 7530                <1> 	jne	short K39		; JUMP, NO-BREAK
  1140 00001478 F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  1141 0000147B 7405                <1> 	jz	short K38B		; NO, BREAK IS VALID	
  1142 0000147D F6C702              <1> 	test	bh, LC_E0		; YES, WAS LAST CODE AN E0?
  1143 00001480 7426                <1> 	jz	short K39		; NO-BREAK, TEST FOR PAUSE	
  1144                              <1> K38B:
  1145 00001482 8B1D[B6670000]      <1> 	mov	ebx, [BUFFER_HEAD] 	; RESET BUFFER TO EMPTY
  1146 00001488 891D[BA670000]      <1> 	mov	[BUFFER_TAIL], ebx
  1147 0000148E C605[A8670000]80    <1> 	mov	byte [BIOS_BREAK], 80h  ; TURN ON BIOS_BREAK BIT
  1148                              <1> 	;
  1149                              <1> 	;-----	ENABLE KEYBOARD
  1150 00001495 B0AE                <1> 	mov	al, ENA_KBD		; ENABLE KEYBOARD
  1151 00001497 E8B5010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  1152                              <1> 	;
  1153                              <1> 	; CTRL+BREAK code here !!!
  1154                              <1> 	;INT	1BH			; BREAK INTERRUPT VECTOR
  1155                              <1> 	; 17/10/2015	
  1156 0000149C E84D590000          <1> 	call	ctrlbrk ; control+break subroutine
  1157                              <1> 	;
  1158                              <1> 	;sub	ax, ax			; PUT OUT DUMMY CHARACTER
  1159                              <1>         ; 12/04/2021
  1160 000014A1 29C0                <1> 	sub	eax, eax
  1161 000014A3 E942010000          <1>         jmp     K57                     ; BUFFER_FILL
  1162                              <1> 	;
  1163                              <1> 	;-----	TEST FOR PAUSE
  1164                              <1> K39:					; NO_BREAK
  1165 000014A8 F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  1166 000014AB 7537                <1> 	jnz	short K41		; YES, THEN THIS CAN'T BE PAUSE	
  1167 000014AD 3C45                <1> 	cmp	al, NUM_KEY		; LOOK FOR PAUSE KEY
  1168 000014AF 7533                <1> 	jne	short K41		; NO-PAUSE
  1169                              <1> K39P:
  1170 000014B1 800D[AA670000]08    <1> 	or	byte [KB_FLAG_1], HOLD_STATE ; TURN ON THE HOLD FLAG
  1171                              <1> 	;
  1172                              <1> 	;-----	ENABLE KEYBOARD
  1173 000014B8 B0AE                <1> 	mov	al, ENA_KBD		; ENABLE KEYBOARD
  1174 000014BA E892010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  1175                              <1> K39A:
  1176 000014BF B020                <1> 	mov	al, EOI			; END OF INTERRUPT TO CONTROL PORT
  1177 000014C1 E620                <1> 	out	20h, al ;out INTA00, al	; ALLOW FURTHER KEYSTROKE INTERRUPTS
  1178                              <1> 	;
  1179                              <1> 	;-----	DURING PAUSE INTERVAL, TURN COLOR CRT BACK ON
  1180 000014C3 803D[DE670000]07    <1>         cmp     byte [CRT_MODE], 7      ; IS THIS BLACK AND WHITE CARD
  1181 000014CA 740A                <1>         je      short K40              	; YES, NOTHING TO DO
  1182 000014CC 66BAD803            <1> 	mov	dx, 03D8h		; PORT FOR COLOR CARD
  1183 000014D0 A0[DF670000]        <1>         mov     al, [CRT_MODE_SET] 	; GET THE VALUE OF THE CURRENT MODE
  1184 000014D5 EE                  <1> 	out	dx, al			; SET THE CRT MODE, SO THAT CRT IS ON
  1185                              <1> 	;
  1186                              <1> K40:					; PAUSE-LOOP
  1187 000014D6 F605[AA670000]08    <1>         test    byte [KB_FLAG_1], HOLD_STATE ; CHECK HOLD STATE FLAG
  1188 000014DD 75F7                <1> 	jnz	short K40		; LOOP UNTIL FLAG TURNED OFF
  1189                              <1> 	;
  1190 000014DF E995FEFFFF          <1>         jmp     K27                     ; INTERRUPT_RETURN_NO_EOI
  1191                              <1>         ;
  1192                              <1> 	;-----	TEST SPECIAL CASE KEY 55
  1193                              <1> K41:					; NO-PAUSE
  1194 000014E4 3C37                <1> 	cmp	al, 55			; TEST FOR */PRTSC KEY
  1195 000014E6 7513                <1> 	jne	short K42		; NOT-KEY-55
  1196 000014E8 F6C710              <1> 	test	bh, KBX			; IS THIS THE ENHANCED KEYBOARD?
  1197 000014EB 7405                <1> 	jz	short K41A		; NO, CTL-PRTSC IS VALID	
  1198 000014ED F6C702              <1> 	test	bh, LC_E0		; YES, WAS LAST CODE AN E0?
  1199 000014F0 7421                <1> 	jz	short K42B		; NO, TRANSLATE TO A FUNCTION
  1200                              <1> K41A:	
  1201 000014F2 66B80072            <1> 	mov	ax, 114*256		; START/STOP PRINTING SWITCH
  1202 000014F6 E9EF000000          <1>         jmp     K57                     ; BUFFER_FILL
  1203                              <1> 	;
  1204                              <1> 	;-----	SET UP TO TRANSLATE CONTROL SHIFT
  1205                              <1> K42:					; NOT-KEY-55
  1206 000014FB 3C0F                <1> 	cmp	al, 15			; IS IT THE TAB KEY?
  1207 000014FD 7414                <1> 	je	short K42B		; YES, XLATE TO FUNCTION CODE
  1208 000014FF 3C35                <1> 	cmp	al, 53			; IS IT THE / KEY?
  1209 00001501 750E                <1> 	jne	short K42A		; NO, NO MORE SPECIAL CASES	
  1210 00001503 F6C702              <1> 	test	bh, LC_E0		; YES, IS IT FROM THE KEY PAD?
  1211 00001506 7409                <1> 	jz	short K42A		; NO, JUST TRANSLATE
  1212 00001508 66B80095            <1> 	mov	ax, 9500h		; YES, SPECIAL CODE FOR THIS ONE
  1213 0000150C E9D9000000          <1> 	jmp	K57			; BUFFER FILL	
  1214                              <1> K42A: 
  1215                              <1> 	;;mov	ebx, _K8		; SET UP TO TRANSLATE CTL
  1216 00001511 3C3B                <1> 	cmp	al, 59			; IS IT IN CHARACTER TABLE?
  1217                              <1>         ;jb	short K45F              ; YES, GO TRANSLATE CHAR
  1218                              <1> 	;;jb	K56 ; 20/02/2015
  1219                              <1> 	;;jmp	K64 ; 20/02/2015
  1220                              <1> K42B:
  1221 00001513 BB[A0660000]        <1> 	mov	ebx, _K8		; SET UP TO TRANSLATE CTL
  1222                              <1> 	;jb	K56 ;; 20/02/2015
  1223                              <1> 	; 12/04/2021
  1224 00001518 7267                <1> 	jb	short K45F	
  1225 0000151A E9B9000000          <1> 	jmp	K64	
  1226                              <1>         ;
  1227                              <1> 	;-----	NOT IN CONTROL SHIFT
  1228                              <1> K44:					; NOT-CTL-SHIFT
  1229 0000151F 3C37                <1> 	cmp	al, 55			; PRINT SCREEN KEY?
  1230 00001521 7528                <1> 	jne	short K45		; NOT PRINT SCREEN
  1231 00001523 F6C710              <1> 	test	bh, KBX			; IS THIS ENHANCED KEYBOARD?
  1232 00001526 7407                <1> 	jz	short K44A		; NO, TEST FOR SHIFT STATE	
  1233 00001528 F6C702              <1> 	test	bh, LC_E0		; YES, LAST CODE A MARKER?
  1234 0000152B 7507                <1> 	jnz	short K44B		; YES, IS PRINT SCREEN
  1235 0000152D EB41                <1> 	jmp	short K45C		; NO, TRANSLATE TO '*' CHARACTER
  1236                              <1> K44A:
  1237 0000152F F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; NOT 101 KBD, SHIFT KEY DOWN?
  1238 00001532 743C                <1> 	jz	short K45C		; NO, TRANSLATE TO '*' CHARACTER
  1239                              <1> 	;
  1240                              <1> 	;-----	ISSUE INTERRUPT TO INDICATE PRINT SCREEN FUNCTION
  1241                              <1> K44B:
  1242 00001534 B0AE                <1> 	mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  1243 00001536 E816010000          <1> 	call	SHIP_IT			; EXECUTE ENABLE
  1244 0000153B B020                <1> 	mov	al, EOI			; END OF CURRENT INTERRUPT
  1245 0000153D E620                <1> 	out	20h, al ;out INTA00, al	; SO FURTHER THINGS CAN HAPPEN
  1246                              <1> 	; Print Screen !!!		; ISSUE PRINT SCREEN INTERRUPT (INT 05h)
  1247                              <1> 	;PUSH 	BP			; SAVE POINTER
  1248                              <1> 	;INT 	5H			; ISSUE PRINT SCREEN INTERRUPT
  1249                              <1> 	;POP	BP			; RESTORE POINTER
  1250 0000153F 8025[AC670000]FC    <1>         and     byte [KB_FLAG_3], ~(LC_E0+LC_E1) ; ZERO OUT THESE FLAGS
  1251 00001546 E92EFEFFFF          <1>         jmp     K27                     ; GO BACK WITHOUT EOI OCCURRING
  1252                              <1> 	;
  1253                              <1> 	;-----	HANDLE IN-CORE KEYS
  1254                              <1> K45:					; NOT-PRINT-SCREEN
  1255 0000154B 3C3A                <1> 	cmp	al, 58			; TEST FOR IN-CORE AREA
  1256 0000154D 7734                <1> 	ja	short K46		; JUMP IF NOT
  1257 0000154F 3C35                <1> 	cmp	al, 53			; IS THIS THE '/' KEY?
  1258 00001551 7505                <1> 	jne	short K45A		; NO, JUMP
  1259 00001553 F6C702              <1> 	test	bh, LC_E0		; WAS THE LAST CODE THE MARKER?
  1260 00001556 7518                <1> 	jnz	short K45C		; YES, TRANSLATE TO CHARACTER
  1261                              <1> K45A:
  1262 00001558 B91A000000          <1> 	mov	ecx, 26			; LENGHT OF SEARCH
  1263 0000155D BF[76660000]        <1> 	mov	edi, K30+10		; POINT TO TABLE OF A-Z CHARS
  1264 00001562 F2AE                <1> 	repne	scasb			; IS THIS A LETTER KEY?
  1265                              <1> 		; 20/02/2015
  1266 00001564 7505                <1> 	jne	short K45B              ; NO, SYMBOL KEY
  1267                              <1> 	;
  1268 00001566 F6C340              <1> 	test	bl, CAPS_STATE		; ARE WE IN CAPS_LOCK?
  1269 00001569 750C                <1> 	jnz	short K45D		; TEST FOR SURE
  1270                              <1> K45B:
  1271 0000156B F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; ARE WE IN SHIFT STATE?
  1272 0000156E 750C                <1> 	jnz	short K45E		; YES, UPPERCASE
  1273                              <1> 					; NO, LOWERCASE
  1274                              <1> K45C:
  1275 00001570 BB[F8660000]        <1> 	mov	ebx, K10		; TRANSLATE TO LOWERCASE LETTERS
  1276 00001575 EB51                <1> 	jmp	short K56	
  1277                              <1> K45D:					; ALMOST-CAPS-STATE
  1278 00001577 F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; CL ON. IS SHIFT ON, TOO?
  1279 0000157A 75F4                <1> 	jnz	short K45C		; SHIFTED TEMP OUT OF CAPS STATE
  1280                              <1> K45E:
  1281 0000157C BB[50670000]        <1> 	mov	ebx, K11		; TRANSLATE TO UPPER CASE LETTERS
  1282 00001581 EB45                <1> K45F:	jmp	short K56
  1283                              <1> 	;
  1284                              <1> 	;-----	TEST FOR KEYS F1 - F10
  1285                              <1> K46:					; NOT IN-CORE AREA
  1286 00001583 3C44                <1> 	cmp	al, 68			; TEST FOR F1 - F10
  1287                              <1> 	;ja	short K47		; JUMP IF NOT
  1288                              <1> 	;jmp	short K53		; YES, GO DO FN KEY PROCESS			
  1289 00001585 7635                <1> 	jna	short K53		
  1290                              <1> 	;
  1291                              <1> 	;-----	HANDLE THE NUMERIC PAD KEYS
  1292                              <1> K47:					; NOT F1 - F10
  1293 00001587 3C53                <1> 	cmp	al, 83			; TEST NUMPAD KEYS
  1294 00001589 772D                <1> 	ja	short K52		; JUMP IF NOT
  1295                              <1> 	;
  1296                              <1> 	;-----	KEYPAD KEYS, MUST TEST NUM LOCK FOR DETERMINATION
  1297                              <1> K48:
  1298 0000158B 3C4A                <1> 	cmp	al, 74			; SPECIAL CASE FOR MINUS
  1299 0000158D 74ED                <1> 	je	short K45E		; GO TRANSLATE
  1300 0000158F 3C4E                <1> 	cmp	al, 78			; SPECIAL CASE FOR PLUS
  1301 00001591 74E9                <1> 	je	short K45E		; GO TRANSLATE
  1302 00001593 F6C702              <1> 	test	bh, LC_E0		; IS THIS ONE OFTHE NEW KEYS?
  1303 00001596 750A                <1> 	jnz	short K49		; YES, TRANSLATE TO BASE STATE
  1304                              <1> 	;		
  1305 00001598 F6C320              <1> 	test 	bl, NUM_STATE		; ARE WE IN NUM LOCK
  1306 0000159B 7514                <1> 	jnz	short K50		; TEST FOR SURE
  1307 0000159D F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; ARE WE IN SHIFT STATE?
  1308                              <1> 	;jnz	short K51		; IF SHIFTED, REALLY NUM STATE
  1309 000015A0 75DA                <1> 	jnz	short K45E
  1310                              <1> 	;
  1311                              <1> 	;-----	BASE CASE FOR KEYPAD
  1312                              <1> K49:					
  1313 000015A2 3C4C                <1> 	cmp	al, 76			; SPECIAL CASE FOR BASE STATE 5
  1314 000015A4 7504                <1> 	jne	short K49A		; CONTINUE IF NOT KEYPAD 5
  1315 000015A6 B0F0                <1> 	mov	al, 0F0h		; SPECIAL ASCII CODE	
  1316 000015A8 EB40                <1> 	jmp	short K57		; BUFFER FILL
  1317                              <1> K49A:
  1318 000015AA BB[F8660000]        <1> 	mov	ebx, K10		; BASE CASE TABLE	
  1319 000015AF EB27                <1> 	jmp	short K64		; CONVERT TO PSEUDO SCAN
  1320                              <1> 	;
  1321                              <1> 	;-----	MIGHT BE NUM LOCK, TEST SHIFT STATUS
  1322                              <1> K50:					; ALMOST-NUM-STATE
  1323 000015B1 F6C303              <1>         test    bl, LEFT_SHIFT+RIGHT_SHIFT
  1324 000015B4 75EC                <1> 	jnz 	short K49		; SHIFTED TEMP OUT OF NUM STATE
  1325 000015B6 EBC4                <1> K51:	jmp	short K45E		; REALLY NUM STATE
  1326                              <1> 	;
  1327                              <1> 	;-----	TEST FOR THE NEW KEYS ON WT KEYBOARDS 
  1328                              <1> K52:					; NOT A NUMPAD KEY
  1329 000015B8 3C56                <1> 	cmp	al, 86			; IS IT THE NEW WT KEY?
  1330                              <1> 	;jne	short K53		; JUMP IF NOT
  1331                              <1> 	;jmp	short K45B		; HANDLE WITH REST OF LETTER KEYS
  1332 000015BA 74AF                <1> 	je	short K45B		
  1333                              <1> 	;
  1334                              <1> 	;-----	MUST BE F11 OR F12 
  1335                              <1> K53:					; F1 - F10 COME HERE, TOO
  1336 000015BC F6C303              <1> 	test	bl, LEFT_SHIFT+RIGHT_SHIFT ; TEST SHIFT STATE
  1337 000015BF 74E1                <1> 	jz	short K49		; JUMP, LOWER CASE PSEUDO SC'S
  1338                              <1> 		; 20/02/2015 
  1339 000015C1 BB[50670000]        <1> 	mov	ebx, K11		; UPPER CASE PSEUDO SCAN CODES
  1340 000015C6 EB10                <1> 	jmp	short K64		; TRANSLATE SCAN
  1341                              <1> 	;
  1342                              <1> 	;-----	TRANSLATE THE CHARACTER
  1343                              <1> K56:					; TRANSLATE-CHAR
  1344 000015C8 FEC8                <1> 	dec	al			; CONVERT ORIGIN
  1345 000015CA D7                  <1> 	xlat    			; CONVERT THE SCAN CODE TO ASCII
  1346 000015CB F605[AC670000]02    <1> 	test	byte [KB_FLAG_3], LC_E0	; IS THIS A NEW KEY?
  1347 000015D2 7416                <1> 	jz	short K57		; NO, GO FILL BUFFER
  1348 000015D4 B4E0                <1> 	mov	ah, MC_E0		; YES, PUT SPECIAL MARKER IN AH
  1349 000015D6 EB12                <1> 	jmp	short K57		; PUT IT INTO THE BUFFER	
  1350                              <1> 	;
  1351                              <1> 	;-----	TRANSLATE SCAN FOR PSEUDO SCAN CODES
  1352                              <1> K64:					; TRANSLATE-SCAN-ORGD
  1353 000015D8 FEC8                <1> 	dec	al			; CONVERT ORIGIN
  1354 000015DA D7                  <1>        	xlat    	                ; CTL TABLE SCAN
  1355 000015DB 88C4                <1> 	mov	ah, al			; PUT VALUE INTO AH
  1356 000015DD B000                <1> 	mov	al, 0			; ZERO ASCII CODE
  1357 000015DF F605[AC670000]02    <1> 	test	byte [KB_FLAG_3], LC_E0	; IS THIS A NEW KEY?
  1358 000015E6 7402                <1> 	jz	short K57		; NO, GO FILL BUFFER
  1359 000015E8 B0E0                <1> 	mov	al, MC_E0		; YES, PUT SPECIAL MARKER IN AL
  1360                              <1> 	;
  1361                              <1> 	;-----	PUT CHARACTER INTO BUFFER
  1362                              <1> K57:					; BUFFER_FILL
  1363 000015EA 3CFF                <1> 	cmp	al, -1			; IS THIS AN IGNORE CHAR
  1364 000015EC 7405                <1> 	je	short K59		; YES, DO NOTHING WITH IT
  1365                              <1> 	;je	K26			; YES, DO NOTHING WITH IT
  1366 000015EE 80FCFF              <1> 	cmp	ah, -1			; LOOK FOR -1 PSEUDO SCAN
  1367                              <1>         ;;jne	short K61		; NEAR_INTERRUPT_RETURN
  1368                              <1> 	;je	K26			; INTERRUPT_RETURN
  1369                              <1> 	; 12/04/2021
  1370 000015F1 7505                <1>         jne	short _K60		; NEAR_INTERRUPT_RETURN
  1371                              <1> K59:					; NEAR_INTERRUPT_RETURN
  1372 000015F3 E975FDFFFF          <1> 	jmp	K26			; INTERRUPT_RETURN
  1373                              <1> 
  1374                              <1> _K60: ; 29/01/2016
  1375 000015F8 80FC68              <1> 	cmp	ah, 68h	; ALT + F1 key
  1376 000015FB 721D                <1> 	jb	short K61
  1377 000015FD 80FC6F              <1> 	cmp	ah, 6Fh ; ALT + F8 key	
  1378 00001600 7718                <1> 	ja	short K61
  1379                              <1> 	;
  1380 00001602 8A1D[EE7C0100]      <1> 	mov	bl, [ACTIVE_PAGE]
  1381 00001608 80C368              <1> 	add	bl, 68h
  1382 0000160B 38E3                <1> 	cmp	bl, ah
  1383 0000160D 740B                <1> 	je	short K61
  1384                              <1> 	; 24/07/2022
  1385                              <1> 	;push	ax
  1386 0000160F 50                  <1> 	push	eax
  1387 00001610 88E0                <1> 	mov	al, ah
  1388 00001612 2C68                <1> 	sub	al, 68h
  1389 00001614 E850090000          <1> 	call	set_active_page
  1390 00001619 58                  <1> 	pop	eax
  1391                              <1> 	;pop	ax
  1392                              <1> K61:					; NOT-CAPS-STATE
  1393 0000161A 8B1D[BA670000]      <1> 	mov	ebx, [BUFFER_TAIL] 	; GET THE END POINTER TO THE BUFFER
  1394 00001620 89DE                <1> 	mov	esi, ebx		; SAVE THE VALUE
  1395 00001622 E8B5FAFFFF          <1> 	call	_K4			; ADVANCE THE TAIL
  1396 00001627 3B1D[B6670000]      <1> 	cmp	ebx, [BUFFER_HEAD] 	; HAS THE BUFFER WRAPPED AROUND
  1397 0000162D 740E                <1> 	je	short K62		; BUFFER_FULL_BEEP
  1398 0000162F 668906              <1> 	mov	[esi], ax		; STORE THE VALUE
  1399 00001632 891D[BA670000]      <1> 	mov	[BUFFER_TAIL], ebx 	; MOVE THE POINTER UP
  1400 00001638 E930FDFFFF          <1> 	jmp	K26
  1401                              <1> 	;;cli				; TURN OFF INTERRUPTS
  1402                              <1> 	;;mov	al, EOI			; END OF INTERRUPT COMMAND
  1403                              <1> 	;;out	INTA00, al		; SEND COMMAND TO INTERRUPT CONTROL PORT
  1404                              <1> 	;mov	al, ENA_KBD		; INSURE KEYBOARD IS ENABLED
  1405                              <1> 	;call	SHIP_IT			; EXECUTE ENABLE
  1406                              <1> 	;mov	ax, 9102h		; MOVE IN POST CODE & TYPE
  1407                              <1> 	;int	15h			; PERFORM OTHER FUNCTION
  1408                              <1> 	;;and	byte [KB_FLAG_3],~(LC_E0+LC_E1) ; RESET LAST CHAR H.C. FLAG
  1409                              <1> 	;jmp	K27A			; INTERRUPT_RETURN
  1410                              <1> 	;;jmp   K27                    
  1411                              <1> 	;
  1412                              <1> 	;-----	BUFFER IS FULL SOUND THE BEEPER
  1413                              <1> K62:
  1414 0000163D B020                <1> 	mov	al, EOI			; ENABLE INTERRUPT CONTROLLER CHIP
  1415 0000163F E620                <1> 	out	INTA00, al
  1416 00001641 66B9A602            <1> 	mov	cx, 678			; DIVISOR FOR 1760 HZ
  1417 00001645 B304                <1> 	mov	bl, 4			; SHORT BEEP COUNT (1/16 + 1/64 DELAY)
  1418 00001647 E8420D0000          <1> 	call	beep			; GO TO COMMON BEEP HANDLER
  1419 0000164C E928FDFFFF          <1> 	jmp     K27			; EXIT   
  1420                              <1> 
  1421                              <1> SHIP_IT:
  1422                              <1> 	;---------------------------------------------------------------------------------
  1423                              <1> 	; SHIP_IT
  1424                              <1> 	;	THIS ROUTINES HANDLES TRANSMISSION OF COMMAND AND DATA BYTES
  1425                              <1> 	;	TO THE KEYBOARD CONTROLLER.
  1426                              <1> 	;---------------------------------------------------------------------------------
  1427                              <1> 	;
  1428                              <1> 	
  1429                              <1> 	;push	ax			; SAVE DATA TO SEND
  1430                              <1> 	; 12/04/2021
  1431 00001651 50                  <1> 	push	eax
  1432                              <1> 
  1433                              <1> 	;-----	WAIT FOR COMMAND TO ACCEPTED
  1434 00001652 FA                  <1> 	cli				; DISABLE INTERRUPTS TILL DATA SENT
  1435                              <1> 	; xor	ecx, ecx		; CLEAR TIMEOUT COUNTER
  1436 00001653 B900000100          <1> 	mov	ecx, 10000h			
  1437                              <1> S10:
  1438 00001658 E464                <1> 	in	al, STATUS_PORT		; READ KEYBOARD CONTROLLER STATUS
  1439 0000165A A802                <1> 	test	al, INPT_BUF_FULL	; CHECK FOR ITS INPUT BUFFER BUSY
  1440 0000165C E0FA                <1> 	loopnz	S10			; WAIT FOR COMMAND TO BE ACCEPTED
  1441                              <1> 
  1442                              <1> 	;pop	ax			; GET DATA TO SEND
  1443                              <1> 	; 12/04/2021
  1444 0000165E 58                  <1> 	pop	eax
  1445                              <1> 
  1446 0000165F E664                <1> 	out	STATUS_PORT, al		; SEND TO KEYBOARD CONTROLLER
  1447 00001661 FB                  <1> 	sti				; ENABLE INTERRUPTS AGAIN
  1448 00001662 C3                  <1> 	retn				; RETURN TO CALLER
  1449                              <1> 
  1450                              <1> 	; 12/04/2021 (32 bit push/pop)
  1451                              <1> SND_DATA:
  1452                              <1> 	; ---------------------------------------------------------------------------------
  1453                              <1> 	; SND_DATA
  1454                              <1> 	;	THIS ROUTINES HANDLES TRANSMISSION OF COMMAND AND DATA BYTES
  1455                              <1> 	;	TO THE KEYBOARD AND RECEIPT OF ACKNOWLEDGEMENTS. IT ALSO
  1456                              <1> 	;	HANDLES ANY RETRIES IF REQUIRED
  1457                              <1> 	; ---------------------------------------------------------------------------------
  1458                              <1> 	;
  1459 00001663 50                  <1> 	push	eax ; push ax		; SAVE REGISTERS
  1460 00001664 53                  <1> 	push	ebx ; push bx
  1461 00001665 51                  <1> 	push	ecx
  1462 00001666 88C7                <1> 	mov	bh, al			; SAVE TRANSMITTED BYTE FOR RETRIES
  1463 00001668 B303                <1> 	mov	bl, 3			; LOAD RETRY COUNT
  1464                              <1> SD0:
  1465 0000166A FA                  <1> 	cli				; DISABLE INTERRUPTS
  1466 0000166B 8025[AB670000]CF    <1> 	and	byte [KB_FLAG_2], ~(KB_FE+KB_FA) ; CLEAR ACK AND RESEND FLAGS
  1467                              <1> 	;
  1468                              <1> 	;-----	WAIT FOR COMMAND TO BE ACCEPTED
  1469 00001672 B900000100          <1> 	mov	ecx, 10000h		; MAXIMUM WAIT COUNT
  1470                              <1> SD5:
  1471 00001677 E464                <1> 	in	al, STATUS_PORT		; READ KEYBOARD PROCESSOR STATUS PORT
  1472 00001679 A802                <1> 	test	al, INPT_BUF_FULL	; CHECK FOR ANY PENDING COMMAND
  1473 0000167B E0FA                <1> 	loopnz	SD5			; WAIT FOR COMMAND TO BE ACCEPTED
  1474                              <1> 	;
  1475 0000167D 88F8                <1> 	mov	al, bh			; REESTABLISH BYTE TO TRANSMIT
  1476 0000167F E660                <1> 	out	PORT_A, al		; SEND BYTE
  1477 00001681 FB                  <1> 	sti				; ENABLE INTERRUPTS
  1478                              <1> 	;mov	cx, 01A00h		; LOAD COUNT FOR 10 ms+
  1479 00001682 B9FFFF0000          <1> 	mov	ecx, 0FFFFh
  1480                              <1> SD1:
  1481 00001687 F605[AB670000]30    <1> 	test	byte [KB_FLAG_2], KB_FE+KB_FA ; SEE IF EITHER BIT SET
  1482 0000168E 750F                <1> 	jnz	short SD3		; IF SET, SOMETHING RECEIVED GO PROCESS
  1483 00001690 E2F5                <1> 	loop	SD1			; OTHERWISE WAIT
  1484                              <1> SD2:
  1485 00001692 FECB                <1> 	dec	bl			; DECREMENT RETRY COUNT
  1486 00001694 75D4                <1> 	jnz	short SD0		; RETRY TRANSMISSION
  1487 00001696 800D[AB670000]80    <1> 	or	byte [KB_FLAG_2], KB_ERR ; TURN ON TRANSMIT ERROR FLAG
  1488 0000169D EB09                <1> 	jmp	short SD4		; RETRIES EXHAUSTED FORGET TRANSMISSION
  1489                              <1> SD3:
  1490 0000169F F605[AB670000]10    <1> 	test	byte [KB_FLAG_2], KB_FA ; SEE IF THIS IS AN ACKNOWLEDGE
  1491 000016A6 74EA                <1> 	jz	short SD2		; IF NOT, GO RESEND
  1492                              <1> SD4:	
  1493 000016A8 59                  <1> 	pop	ecx			; RESTORE REGISTERS
  1494 000016A9 5B                  <1> 	pop	ebx ; pop bx
  1495 000016AA 58                  <1> 	pop	eax ; pop ax
  1496 000016AB C3                  <1> 	retn				; RETURN, GOOD TRANSMISSION
  1497                              <1> 
  1498                              <1> SND_LED:
  1499                              <1> 	; ---------------------------------------------------------------------------------
  1500                              <1> 	; SND_LED
  1501                              <1> 	;	THIS ROUTINES TURNS ON THE MODE INDICATORS.
  1502                              <1> 	;
  1503                              <1> 	;----------------------------------------------------------------------------------
  1504                              <1> 	;
  1505 000016AC FA                  <1> 	cli				; TURN OFF INTERRUPTS
  1506 000016AD F605[AB670000]40    <1> 	test	byte [KB_FLAG_2], KB_PR_LED ; CHECK FOR MODE INDICATOR UPDATE
  1507 000016B4 755F                <1> 	jnz 	short SL1		; DON'T UPDATE AGAIN IF UPDATE UNDERWAY
  1508                              <1> 	;
  1509 000016B6 800D[AB670000]40    <1> 	or	byte [KB_FLAG_2], KB_PR_LED ; TURN ON UPDATE IN PROCESS
  1510 000016BD B020                <1> 	mov	al, EOI			; END OF INTERRUPT COMMAND
  1511 000016BF E620                <1> 	out	20h, al ;out INTA00, al	; SEND COMMAND TO INTERRUPT CONTROL PORT
  1512 000016C1 EB11                <1> 	jmp	short SL0		; GO SEND MODE INDICATOR COMMAND
  1513                              <1> SND_LED1:
  1514 000016C3 FA                  <1> 	cli				; TURN OFF INTERRUPTS
  1515 000016C4 F605[AB670000]40    <1> 	test	byte [KB_FLAG_2], KB_PR_LED ; CHECK FOR MODE INDICATOR UPDATE
  1516 000016CB 7548                <1> 	jnz	short SL1		; DON'T UPDATE AGAIN IF UPDATE UNDERWAY
  1517                              <1> 	;
  1518 000016CD 800D[AB670000]40    <1> 	or	byte [KB_FLAG_2], KB_PR_LED ; TURN ON UPDATE IN PROCESS
  1519                              <1> SL0:
  1520 000016D4 B0ED                <1> 	mov	al, LED_CMD		; LED CMD BYTE
  1521 000016D6 E888FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  1522 000016DB FA                  <1> 	cli
  1523 000016DC E836000000          <1> 	call	MAKE_LED		; GO FORM INDICATOR DATA BYTE
  1524 000016E1 8025[AB670000]F8    <1> 	and	byte [KB_FLAG_2], 0F8h	; ~KB_LEDS ; CLEAR MODE INDICATOR BITS
  1525 000016E8 0805[AB670000]      <1> 	or	[KB_FLAG_2], al 	; SAVE PRESENT INDICATORS FOR NEXT TIME
  1526 000016EE F605[AB670000]80    <1> 	test	byte [KB_FLAG_2], KB_ERR ; TRANSMIT ERROR DETECTED
  1527 000016F5 750F                <1> 	jnz	short SL2		; IF SO, BYPASS SECOND BYTE TRANSMISSION
  1528                              <1> 	;
  1529 000016F7 E867FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  1530 000016FC FA                  <1> 	cli				; TURN OFF INTERRUPTS
  1531 000016FD F605[AB670000]80    <1> 	test	byte [KB_FLAG_2], KB_ERR ; TRANSMIT ERROR DETECTED
  1532 00001704 7408                <1> 	jz	short SL3		; IF NOT, DON'T SEND AN ENABLE COMMAND
  1533                              <1> SL2:
  1534 00001706 B0F4                <1> 	mov	al, KB_ENABLE		; GET KEYBOARD CSA ENABLE COMMAND
  1535 00001708 E856FFFFFF          <1> 	call	SND_DATA		; SEND DATA TO KEYBOARD
  1536 0000170D FA                  <1> 	cli				; TURN OFF INTERRUPTS
  1537                              <1> SL3:
  1538 0000170E 8025[AB670000]3F    <1> 	and	byte [KB_FLAG_2], ~(KB_PR_LED+KB_ERR) ; TURN OFF MODE INDICATOR
  1539                              <1> SL1:					; UPDATE AND TRANSMIT ERROR FLAG
  1540 00001715 FB                  <1> 	sti				; ENABLE INTERRUPTS
  1541 00001716 C3                  <1> 	retn				; RETURN TO CALLER
  1542                              <1> 
  1543                              <1> MAKE_LED:
  1544                              <1> 	;---------------------------------------------------------------------------------
  1545                              <1> 	; MAKE_LED
  1546                              <1> 	;	THIS ROUTINES FORMS THE DATA BYTE NECESSARY TO TURN ON/OFF
  1547                              <1> 	;	THE MODE INDICATORS.
  1548                              <1> 	;---------------------------------------------------------------------------------
  1549                              <1> 	;
  1550                              <1> 	;push 	cx			; SAVE CX
  1551 00001717 A0[A9670000]        <1> 	mov	al, [KB_FLAG]		; GET CAPS & NUM LOCK INDICATORS
  1552 0000171C 2470                <1> 	and	al, CAPS_STATE+NUM_STATE+SCROLL_STATE ; ISOLATE INDICATORS
  1553                              <1> 	;mov	cl, 4			; SHIFT COUNT
  1554                              <1> 	;rol	al, cl			; SHIFT BITS OVER TO TURN ON INDICATORS
  1555 0000171E C0C004              <1> 	rol	al, 4 ; 20/02/2015
  1556 00001721 2407                <1> 	and	al, 07h			; MAKE SURE ONLY MODE BITS ON
  1557                              <1> 	;pop	cx
  1558 00001723 C3                  <1> 	retn				; RETURN TO CALLER
  1559                              <1> 
  1560                              <1> ; % include 'kybdata.s'   ; KEYBOARD DATA
  1561                              <1> 
  1562                              <1> 
  1563                              <1> ; /// End Of KEYBOARD FUNCTIONS ///
  2987                                  
  2988                                  %include 'video.s' ; 07/03/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.7 - video.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 29/11/2023 (Previous: 07/08/2022 - Kernel v2.0.5)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 16/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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 00001724 9C                  <1> 	pushfd
    35 00001725 0E                  <1> 	push	cs
    36 00001726 E851000000          <1> 	call	VIDEO_IO_1
    37 0000172B 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 0000172C [FD1A0000]          <1> M1:	dd	SET_MODE	; TABLE OF ROUTINES WITHIN VIDEO I/O
   191 00001730 [B31E0000]          <1> 	dd	SET_CTYPE
   192 00001734 [E11E0000]          <1> 	dd	SET_CPOS
   193 00001738 [051F0000]          <1> 	dd	READ_CURSOR
   194                              <1> 	;dd	VIDEO_RETURN	; READ_LPEN
   195 0000173C [FB1A0000]          <1> 	dd	set_mode_ncm	; Set mode without clearing video memory
   196 00001740 [4B1F0000]          <1> 	dd	ACT_DISP_PAGE
   197 00001744 [D51F0000]          <1> 	dd	SCROLL_UP
   198 00001748 [EC200000]          <1> 	dd	SCROLL_DOWN
   199 0000174C [6B210000]          <1> 	dd	READ_AC_CURRENT
   200 00001750 [C8210000]          <1> 	dd	WRITE_AC_CURRENT
   201 00001754 [EE210000]          <1> 	dd	WRITE_C_CURRENT
   202 00001758 [F62A0000]          <1> 	dd	SET_COLOR
   203 0000175C [5E2B0000]          <1> 	dd	WRITE_DOT
   204 00001760 [2D2B0000]          <1> 	dd	READ_DOT
   205 00001764 [78220000]          <1> 	dd	WRITE_TTY
   206 00001768 [E31A0000]          <1> 	dd	VIDEO_STATE
   207 0000176C [2B360000]          <1> 	dd	vga_pal_funcs	; 10/08/2016 (TRDOS 386)
   208 00001770 [43300000]          <1> 	dd	font_setup	; 10/07/2016 (TRDOS 386)
   209 00001774 [321B0000]          <1> 	dd	VIDEO_RETURN	; RESERVED
   210 00001778 [EE230000]          <1> 	dd	WRITE_STRING	; 23/06/2016 (TRDOS 386)
   211                              <1> M1L	EQU	$ - M1
   212                              <1> 
   213                              <1> ; 29/11/2023 - TRDOS 386 v2.0.7
   214                              <1> ;	[VESA VBE3-PMI functions]
   215                              <1> ;	(fixing page table problems for LFB/PMI for >2.5GB main memory)
   216                              <1> ;	((Addresses of kernel page tables and PMI videobios address
   217                              <1> ;	  must be < 4MB or cr3 register must contain kernel's page dir
   218                              <1> ;	  during video interrupt. Save-change-restore cr3 register
   219                              <1> ;	  content here is a bugfix method to prevent page faults 
   220                              <1> ;	  for -real- computers with >2.5GB main memory.))
   221                              <1> ;	 {INT 31h was not changing cr3 while it contains user's
   222                              <1> ;	  page directory addr and accessing beyond of the 1st 4MB was
   223                              <1> ;	  causing to page faults.. because, after the 1st 4MB, user's
   224                              <1> ;	  page tables contain non-linear/virtual memory pages.}
   225                              <1> ;
   226                              <1> ; 02/08/2022 - TRDOS 386 v2.0.5
   227                              <1> ; 06/12/2020
   228                              <1> ; 05/12/2020
   229                              <1> ; 03/12/2020
   230                              <1> ; 27/11/2020 - TRDOS 386 v2.0.3
   231                              <1> ; 14/01/2017
   232                              <1> ; 02/01/2017
   233                              <1> ; 04/07/2016
   234                              <1> ; 12/05/2016
   235                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   236                              <1> int31h:  ; Video BIOS
   237                              <1> 
   238                              <1> ; BH = Video page number
   239                              <1> ; BL = Color/Attribute
   240                              <1> ; AH = Function number
   241                              <1> ; AL = Character
   242                              <1> 
   243                              <1> VIDEO_IO_1:
   244                              <1> 	;sti				; INTERRUPTS BACK ON
   245 0000177C FC                  <1> 	cld				; SET DIRECTION FORWARD
   246                              <1> 	
   247                              <1> 	;cmp	ah, M1L/4		; TEST FOR WITHIN TABLE RANGE
   248                              <1> 	;jnb	short M4		; BRANCH TO EXIT IF NOT A VALID COMMAND
   249                              <1> 
   250                              <1> 	; 26/11/2020
   251 0000177D 80FC14              <1> 	cmp	ah, M1L/4
   252 00001780 7205                <1> 	jb	short VGA_func
   253                              <1> 
   254 00001782 80FC4F              <1> 	cmp	ah, 4Fh
   255 00001785 7532                <1> 	jne	short M4 ; invalid !
   256                              <1> 
   257                              <1> VGA_func: ; 26/11/2020
   258 00001787 06                  <1> 	push	es ; *
   259 00001788 1E                  <1> 	push	ds ; **			; SAVE WORK AND PARAMETER REGISTERS
   260                              <1> 
   261                              <1> 	; 26/11/2020
   262 00001789 50                  <1> 	push	eax ; -
   263                              <1> 	
   264 0000178A 66B81000            <1> 	mov	ax, KDATA 		; POINT DS: TO DATA SEGMENT
   265 0000178E 8ED8                <1> 	mov	ds, ax
   266 00001790 8EC0                <1> 	mov	es, ax
   267                              <1> 
   268                              <1> 	; 26/11/2020
   269 00001792 58                  <1> 	pop	eax ; +
   270                              <1> 	;
   271 00001793 FB                  <1> 	sti
   272 00001794 80FC4F              <1> 	cmp	ah, 4Fh
   273 00001797 747A                <1> 	je	short VBE_func
   274                              <1> 
   275                              <1> 	; 04/12/2020
   276 00001799 A3[44890100]        <1> 	mov	[video_eax], eax
   277                              <1> 
   278                              <1> 	; 21/12/2020
   279 0000179E 803D[DE670000]FF    <1> 	cmp	byte [CRT_MODE], 0FFh	; Current mode is a VESA VBE mode ?
   280 000017A5 7213                <1> 	jb	short VGA_func_std
   281                              <1> 
   282 000017A7 08E4                <1> 	or	ah, ah			; set mode ?
   283 000017A9 750F                <1> 	jnz	short VGA_func_std	; no
   284                              <1> 
   285 000017AB 803D[86090000]03    <1> 	cmp	byte [vbe3], 3		; (real) VESA VBE 3 video bios ?
   286 000017B2 7506                <1> 	jne	short VGA_func_std	; no
   287                              <1> 
   288 000017B4 E995010000          <1> 	jmp	vesa_vbe3_pmi
   289                              <1> 
   290                              <1> 	; 21/12/2020
   291                              <1> M4:					; COMMAND NOT VALID
   292 000017B9 CF                  <1> 	iretd				; DO NOTHING IF NOT IN VALID RANGE
   293                              <1> 
   294                              <1> VGA_func_std:
   295                              <1> 	; 06/12/2020
   296                              <1> 	; 03/12/2020
   297 000017BA 80FC0F              <1> 	cmp	ah, 0Fh
   298 000017BD 773D                <1> 	ja	short VGA_funcs_0	; only CGA funcs will be handled by	
   299                              <1> 	; 06/12/2020			; vga bios firmware
   300                              <1> 	; 03/12/2020			
   301                              <1> 	;test	ah, 7Fh ; set mode ?
   302                              <1> 	;;or	ah, ah			; only 'set mode' will be handled by
   303                              <1> 	;jnz	short VGA_funcs_0	; vga bios firmware	
   304                              <1> 	;jz	short vbe_pmi32_0
   305                              <1> 
   306                              <1> 	; 28/11/2020
   307 000017BF 803D[2CA30100]00    <1> 	cmp	byte [pmi32], 0		; 32 bit protected mode interface for
   308 000017C6 7634                <1> 	jna	short VGA_funcs_0	; video hardware's vga bios firmware
   309                              <1> 					; ([pmi32] > 0 if it is activated)
   310                              <1> 					; note:
   311                              <1> 					; [vbe3] = 3 is required to activate
   312                              <1> 	; 07/12/2020
   313 000017C8 20E4                <1> 	and	ah, ah ; is this set mode ?
   314 000017CA 7413                <1> 	jz	short vbe_pmi32_2 ; yes
   315                              <1> 
   316 000017CC 80FC04              <1> 	cmp	ah, 04h	 ; set mode ('no clear memory' option)
   317 000017CF 742B                <1> 	je	short VGA_funcs_0
   318                              <1> 
   319                              <1> 	; 07/12/2020
   320 000017D1 803D[DE670000]07    <1> 	cmp	byte [CRT_MODE], 7 ; current mode > 7 ?
   321 000017D8 7622                <1> 	jna	short VGA_funcs_0  ; no	
   322                              <1> 
   323                              <1> 	; when mode 3 is active, 
   324                              <1> 	; video bios functions are not redirected
   325                              <1> 	; to VESA VBE3 PMI except 'set mode' function
   326                              <1> 
   327                              <1> vbe_pmi32_0:
   328                              <1> 	; 06/12/2020
   329                              <1> 	;or	ah, ah
   330                              <1> 	;jnz	short vbe_pmi32_2
   331                              <1> 	; ah = 0 ; 'set mode'
   332                              <1> 	;cmp	al, 3 ; 80x25 text mode, 16 colors, default mode for MainProg
   333                              <1> 	;jne	short vbe_pmi32_1
   334                              <1> 	;cmp	byte [CRT_MODE], 3 ; If current video mode <> 3 and requested
   335                              <1> 	;			; video mode is 3, use internal 'set mode';
   336                              <1> 	;			; otherwise, use vesa vbe 3 bios's 'set mode'.
   337                              <1> 	;jne	short VGA_funcs_0
   338                              <1> vbe_pmi32_1:
   339 000017DA E96F010000          <1> 	jmp	vesa_vbe3_pmi
   340                              <1> ;vbe_pmi32_2:
   341                              <1> 	;cmp	ah, 04h ; set mode (no clear mem option)
   342                              <1> 	;jne	short vbe_pmi32_1
   343                              <1> 
   344                              <1> vbe_pmi32_2:
   345                              <1> 	; 07/12/2020
   346 000017DF 803D[DE670000]07    <1> 	cmp	byte [CRT_MODE], 7 ; current mode > 7 ?
   347 000017E6 77F2                <1> 	ja	short vbe_pmi32_1  ; yes
   348                              <1> 
   349 000017E8 3C07                <1> 	cmp	al, 7	; requested mode > 7 ?
   350 000017EA 7610                <1> 	jna	short VGA_funcs_0  ; no (CGA)
   351                              <1> 
   352 000017EC 3C13                <1> 	cmp	al, 13h
   353 000017EE 76EA                <1> 	jna	short vbe_pmi32_1
   354                              <1> 
   355 000017F0 A880                <1> 	test	al, 80h
   356 000017F2 7408                <1> 	jz	short VGA_funcs_0  ; unknown or special
   357                              <1> 
   358 000017F4 3C87                <1> 	cmp	al, 87h	; requested mode > 7 ? 
   359                              <1> 			; (with no clear mem ops)
   360 000017F6 7604                <1> 	jna	short VGA_funcs_0  ; no (CGA)
   361                              <1> 
   362 000017F8 3C93                <1> 	cmp	al, 93h
   363 000017FA 76DE                <1> 	jna	short vbe_pmi32_1
   364                              <1> 
   365                              <1> 	; > 13h video modes are unknown or special
   366                              <1>  	; they must be handled by kernel	
   367                              <1> 
   368                              <1> 	; CGA video modes will be handled by kernel
   369                              <1> 
   370                              <1> VGA_funcs_0:
   371 000017FC 52                  <1> 	push	edx ; ***
   372 000017FD 51                  <1> 	push	ecx ; ****
   373 000017FE 53                  <1> 	push	ebx ; *****
   374 000017FF 56                  <1> 	push	esi ; ******
   375 00001800 57                  <1> 	push	edi ; *******
   376 00001801 55                  <1> 	push	ebp ; ********
   377                              <1> 
   378                              <1> 	;mov	[video_eax], eax ; 12/05/2016 
   379 00001802 BF00800B00          <1> 	mov	edi, 0B8000h		; GET offset FOR COLOR CARD
   380                              <1> 
   381                              <1> 	; 23/03/2016
   382 00001807 C0E402              <1> 	shl	ah, 2  ; dword		; TIMES 2 FOR WORD TABLE LOOKUP
   383 0000180A 0FB6F4              <1> 	movzx	esi, ah			; MOVE OFFSET INTO LOOK UP REGISTER (SI)
   384                              <1> 	;mov	ah, [CRT_MODE]		; MOVE CURRENT MODE INTO (AH) REGISTER
   385                              <1> 
   386                              <1> 	;;15/01/2017
   387                              <1> 	; 14/01/2017
   388                              <1> 	; 02/01/2017
   389                              <1> 	;;mov	byte [intflg], 31h  ; video interrupt
   390                              <1> 	;sti ; 26/11/2020
   391                              <1> 	;
   392                              <1> 
   393 0000180D FFA6[2C170000]      <1> 	jmp	dword [esi+M1]		; GO TO SELECTED FUNCTION
   394                              <1> 
   395                              <1> VBE_func:
   396                              <1> 	; 26/11/2020
   397                              <1> 	;sti
   398 00001813 55                  <1> 	push	ebp ; *** ; 27/11/2020	
   399 00001814 56                  <1> 	push	esi ; **** 
   400                              <1> 	
   401                              <1> 	; Note:
   402                              <1> 	; ebx, ecx, edx, edi, ebp registers
   403                              <1> 	; must be saved by VBE functions and
   404                              <1> 	; eax register must be set
   405                              <1> 	; (according to VBE 3 standard)
   406                              <1> 	; before return from this interrupt
   407                              <1> 	; (every function must restore and set
   408                              <1> 	; registers except esp, esi, es, ds)
   409                              <1> 
   410                              <1> 	; 29/11/2023 - TRDOS 386 v2.0.7
   411 00001815 0F20DE              <1> 	mov	esi, cr3
   412 00001818 56                  <1> 	push	esi ; *****
   413                              <1> 	;cmp	esi, [k_page_dir]
   414                              <1> 	;je	short VBE_func_x
   415 00001819 8B35[C07C0100]      <1> 	mov	esi, [k_page_dir]
   416 0000181F 0F22DE              <1> 	mov	cr3, esi
   417                              <1> ;VBE_func_x:
   418 00001822 803D[86090000]02    <1> 	cmp	byte [vbe3], 2
   419 00001829 7744                <1> 	ja	short VESA_VBE3_PMI_CALL ; VBE3 video bios ('PMID')
   420                              <1> 	;je	short VBE_func_0  ; Bochs/Qemu/VirtualBox emulator
   421 0000182B 726C                <1> 	jb	short VBE_unknown ; invalid ([vbe3] = 0)
   422                              <1> 
   423                              <1> 	;jmp	VESA_VBE3_PMI_CALL
   424                              <1> 
   425                              <1> VBE_func_0:	
   426                              <1> 	; Bochs/Plex86 VGAbios VBE extension
   427                              <1> 	; (TRDOS 386 v2.0.3 can use VBE graphics modes on emulators)
   428                              <1> 	; BOCHS/QEMU/VIRTUALBOX
   429                              <1>  
   430 0000182D 8A25[87090000]      <1> 	mov	ah, [vbe2bios]
   431 00001833 80FCC0              <1> 	cmp	ah, 0C0h		
   432 00001836 7261                <1> 	jb	short VBE_unknown 	
   433 00001838 80FCC5              <1> 	cmp	ah, 0C5h
   434 0000183B 775C                <1> 	ja	short VBE_unknown
   435                              <1> 
   436                              <1> 	; TRDOS 386 is running on BOCHS or QEMU
   437 0000183D B44F                <1> 	mov	ah, 4Fh
   438                              <1> VBE_func_1:
   439 0000183F 0FB6F0              <1> 	movzx	esi, al ; VESA VBE function number
   440                              <1> 	;shl	si, 2 ; dword
   441                              <1> 	; 02/08/2022
   442 00001842 C1E602              <1> 	shl	esi, 2
   443 00001845 6683FE14            <1> 	cmp	si, N1L
   444 00001849 734E                <1> 	jnb	short VBE_unknown
   445                              <1> 	;sti
   446                              <1> 	
   447 0000184B FF96[5B180000]      <1> 	call	dword [esi+N1] ; call VBE function
   448                              <1> 		
   449                              <1> 	;jmp	short VBE_bios_return
   450                              <1> 
   451                              <1> VBE_bios_return:
   452 00001851 FA                  <1> 	cli
   453                              <1> 	; 29/11/2023 - TRDOS 386 v2.0.7
   454 00001852 5E                  <1> 	pop	esi ; *****
   455                              <1> 	;cmp	esi, [k_page_dir]
   456                              <1> 	;je	short VBE_bios_return_x
   457 00001853 0F22DE              <1> 	mov	cr3, esi
   458                              <1> ;VBE_bios_return_x:	
   459 00001856 5E                  <1> 	pop	esi ; ****
   460 00001857 5D                  <1> 	pop	ebp ; *** ; 27/11/2020
   461 00001858 07                  <1> 	pop	es  ; **
   462 00001859 1F                  <1> 	pop	ds  ; *
   463 0000185A CF                  <1> 	iretd
   464                              <1> 
   465                              <1> 	; 26/11/2020
   466                              <1> N1:
   467 0000185B [BC180000]          <1> 	dd	vbe_biosfn_return_ctrl_info
   468 0000185F [E3380000]          <1> 	dd	vbe_biosfn_return_mode_info
   469 00001863 [9D390000]          <1> 	dd	vbe_biosfn_set_mode
   470 00001867 [6D3A0000]          <1> 	dd	vbe_biosfn_return_current_mode
   471 0000186B [8C3A0000]          <1> 	dd	vbe_biosfn_save_restore_state
   472                              <1> 	;dd	vbe_biosfn_display_window_ctrl
   473                              <1> 	;dd	vbe_biosfn_set_get_log_scanline
   474                              <1> 	;dd	vbe_biosfn_set_get_disp_start
   475                              <1> 	;dd	vbe_biosfn_set_get_dac_pal_frm
   476                              <1> 	;dd	vbe_biosfn_set_get_palette_data
   477                              <1> 	
   478                              <1> N1L	EQU	$ - N1
   479                              <1> 
   480                              <1> 
   481                              <1> VESA_VBE3_PMI_CALL: ; VESA VBE video bios (firmware) functions
   482                              <1> 		    ; by using VESA VBE3 Protected Mode Interface
   483                              <1> 	
   484                              <1> 	; 02/08/2022 - TRDOS 386 v2.0.5
   485                              <1> 	; 29/11/2020
   486                              <1> 	; 26/11/2020 - TRDOS 386 v2.0.3 video.s
   487                              <1> 
   488                              <1> 	; We are here because..
   489                              <1> 	; 'PMID' has been verified by TRDOS 386 v2.0.3 kernel.
   490                              <1> 	; (Otherwise bochs/plex86 compatible VBE functions and
   491                              <1> 	;  modes would be used on BOCHS/QEMU/VIRTUALBOX emulators
   492                              <1> 	;  or only standard/old VGA graphics modes would be used.)
   493                              <1> 
   494                              <1> 	; (TRDOS 386 v2.0.3 can use VESA VBE graphics modes if
   495                              <1> 	;  the video bios is full compatible with VBE3 standard) 
   496                              <1> 
   497                              <1> 	; 29/11/2020
   498                              <1> 
   499 0000186F 0FB6F0              <1> 	movzx	esi, al ; VESA VBE 3 function number
   500                              <1> 	;shl	si, 2 ; dword
   501                              <1> 	; 02/08/2022
   502 00001872 C1E602              <1> 	shl	esi, 2
   503 00001875 6683FE14            <1> 	cmp	si, P1L
   504 00001879 731E                <1> 	jnb	short VBE_unknown
   505                              <1> 	;sti
   506                              <1> 
   507 0000187B 57                  <1> 	push	edi ; *****
   508                              <1> 
   509 0000187C FF96[85180000]      <1> 	call	dword [esi+P1] ; call VBE 3 function
   510                              <1> 
   511 00001882 5F                  <1> 	pop	edi ; *****
   512                              <1> 		
   513 00001883 EBCC                <1> 	jmp	short VBE_bios_return
   514                              <1> 
   515                              <1> P1:
   516 00001885 [9F180000]          <1> 	dd	vbe3_pmfn_return_ctrl_info
   517 00001889 [C2180000]          <1> 	dd	vbe3_pmfn_return_mode_info
   518 0000188D [FE180000]          <1> 	dd	vbe3_pmfn_set_mode
   519 00001891 [F9180000]          <1> 	dd	vbe3_pmfn_return_current_mode
   520 00001895 [071A0000]          <1> 	dd	vbe3_pmfn_save_restore_state
   521                              <1> 	;dd	vbe3_pmfn_display_window_ctrl
   522                              <1> 	;dd	vbe3_pmfn_set_get_log_scanline
   523                              <1> 	;dd	vbe3_pmfn_set_get_disp_start
   524                              <1> 	;dd	vbe3_pmfn_set_get_dac_pal_frm
   525                              <1> 	;dd	vbe3_pmfn_set_get_palette_data
   526                              <1> 	;dd	vbe3_pmfn_return_pmi ; invalid for TRDOS 386 v2
   527                              <1> 	;dd	vbe3_pmfn_set_get_pixel_clock
   528                              <1> 	
   529                              <1> P1L	EQU	$ - P1
   530                              <1> 
   531                              <1> ;	; 29/11/2020
   532                              <1> ;	mov	edi, VBE3MODEINFOBLOCK >> 4 ; / 16
   533                              <1> ;	
   534                              <1> ;	cmp	al, 04h
   535                              <1> ;	jb	short vbe3_pm_f ; function: 4F00h to 4F03h
   536                              <1> ;	ja	short vbe3_pmi_f5B ; function: 4F05h to 4F0Bh
   537                              <1> ;
   538                              <1> ;	; check buffer length (must be <= 2048 bytes)
   539                              <1> ;
   540                              <1> ;	and	dl, dl ; 0
   541                              <1> ;	jz	short vbe3_pm_f 
   542                              <1> ;		       ; Return Save/Restore State buffer size
   543                              <1> ;
   544                              <1> ;	push	ebx  ; buffer address
   545                              <1> ;	push	edx  ; function: save (01h) or restore (02h)
   546                              <1> ;	call	
   547                              <1> ;
   548                              <1> ;vbe3_pm_f03:
   549                              <1> ;	cmp	al, 2
   550                              <1> ;	ja	short vbe3_pm_f ; function 4F03h
   551                              <1> ;	jb	short vbe3_pm_f1
   552                              <1> ;
   553                              <1> ;
   554                              <1> ;vbe3_pm_f1:
   555                              <1> ;	
   556                              <1> ;
   557                              <1> ;vbe3_pmi_f5B:
   558                              <1> ;	cmp	al, 09h
   559                              <1> ;	jna	short vbe3_pm_f ; funcs 05h to 09h are usable 
   560                              <1> ;	
   561                              <1> ;	cmp	al, 0Bh ; Get/Set pixel clock, last function
   562                              <1> ;	jne	short VBE_unknown 
   563                              <1> ;			; (do not use 'uncertain' functions
   564                              <1> ;			; because of system-user buff transfers)
   565                              <1> ;vbe3_pm_f:
   566                              <1> ;	mov	byte [vbe3_pm_fn], al	; set
   567                              <1> ;	; prepare 16 bit pm segments & registers for pmi call 
   568                              <1> ;	call	VESA_VBE3_PM_FUNCTION
   569                              <1> ;
   570                              <1> ;
   571                              <1> 
   572                              <1> 	; 26/11/2020
   573                              <1> VBE_unknown:
   574 00001899 66B80001            <1> 	mov	ax, 0100h  ; ah = 1 : Function call failed	
   575                              <1> 			   ; al = 0 : Function is not supported	
   576                              <1> 	
   577 0000189D EBB2                <1> 	jmp	short VBE_bios_return
   578                              <1> 
   579                              <1> vbe3_pmfn_return_ctrl_info:
   580                              <1> 	; 02/08/2022 (TRDOS 386 Kernel v2.0.5)
   581                              <1> 	; 12/12/2020
   582                              <1> 	;
   583                              <1> 	; VBE function 4F00h - Return VBE Controller Information
   584                              <1> 	;
   585                              <1> 	; Input:
   586                              <1> 	;      EDI = Pointer to buffer in which to place
   587                              <1> 	;	     VbeInfoBlock structure
   588                              <1> 	;
   589                              <1> 	;	AX = 4F00h
   590                              <1> 	; Output:
   591                              <1> 	;	AX = VBE return status
   592                              <1> 	;	     AX = 004Fh -> succeeded
   593                              <1> 	;	     AX <> 004Fh -> failed
   594                              <1> 	; 
   595                              <1> 	; Modified registers: eax (+ edi for kernel's own call)
   596                              <1> 
   597                              <1> 	; NOTE: TRDOS 386 v2 (v2.0.3) kernel calls this function
   598                              <1> 	; during startup while cpu is in real mode
   599                              <1> 	; (by using int 10h, 4F02h) and saves VbeInfoBlock at
   600                              <1> 	; VBE3INFOBLOCK address (97E00h for TRDOS 386 v2.0.3).
   601                              <1> 	;	
   602                              <1> 	; So...
   603                              <1> 	; This VBE function is adjusted to return/move same info
   604                              <1> 	; from VBE3INFOBLOCK to user's buffer in EDI.
   605                              <1> 
   606                              <1> 	; int 31h (int 10h) entrance
   607                              <1> 
   608 0000189F 21FF                <1> 	and	edi, edi
   609 000018A1 7423                <1> 	jz	short vbe3_func_fail ; invalid buffer address !
   610                              <1> 
   611                              <1> ;_vbe3_pmfn_return_ctrl_info:		
   612                              <1> 	;or	edi, edi
   613                              <1> 	;jnz	short _vbe_biosfn_return_ctrl_info
   614                              <1> 	;
   615                              <1> 	;; this option may not be necessary - 12/12/2020
   616                              <1> 	;
   617                              <1> 	;; edi = 0, kernel forces to get ctrl info again
   618                              <1> 	;;	   by using VESA VBE3 video bios's pmi
   619                              <1> 	;
   620                              <1> 	;;push	edi
   621                              <1> 	;; far call to VESA VBE3 PMI 
   622                              <1> 	;;mov	ax, 4F00h ; Return VBE Controller Info
   623                              <1> 	;mov	edi, VBE3INFOBLOCK-VBE3SAVERESTOREBLOCK
   624                              <1> 	;; ES selector base address = VBE3SAVERESTOREBLOCK 
   625                              <1> 	;call	int10h_32bit_pmi
   626                              <1> 	;;pop	edi
   627                              <1> 	;mov	edi, VBE3INFOBLOCK ; retn to the kernel sub
   628                              <1> 	;cmp	ax, 004Fh
   629                              <1> 	;je	short vbe_ctrl_info_retn
   630                              <1> 	;stc	
   631                              <1> 	;retn
   632                              <1> 
   633                              <1> _vbe_biosfn_return_ctrl_info:
   634 000018A3 57                  <1> 	push	edi
   635 000018A4 51                  <1> 	push	ecx
   636 000018A5 BE007E0900          <1> 	mov	esi, VBE3INFOBLOCK
   637                              <1> 	;mov	ecx, 512
   638                              <1> 	; 02/08/2022
   639 000018AA 29C9                <1> 	sub	ecx, ecx
   640 000018AC B502                <1> 	mov	ch, 2
   641                              <1> 	; ecx = 512
   642 000018AE E8DDF60000          <1> 	call	transfer_to_user_buffer
   643 000018B3 59                  <1> 	pop	ecx
   644 000018B4 5F                  <1> 	pop	edi
   645 000018B5 720F                <1> 	jc	short vbe3_func_fail
   646                              <1> 
   647 000018B7 31C0                <1> 	xor	eax, eax
   648 000018B9 B04F                <1> 	mov	al, 4Fh ; successful
   649                              <1> ;vbe_ctrl_info_retn:
   650 000018BB C3                  <1> 	retn
   651                              <1> 
   652                              <1> vbe_biosfn_return_ctrl_info:
   653                              <1> 	; 12/12/2020
   654                              <1> 	;
   655                              <1> 	; VBE function 4F00h - Return VBE Controller Information
   656                              <1> 	;
   657                              <1> 	; Input:
   658                              <1> 	;      EDI = Pointer to buffer in which to place
   659                              <1> 	;	     VbeInfoBlock structure
   660                              <1> 	;
   661                              <1> 	;	AX = 4F00h
   662                              <1> 	; Output:
   663                              <1> 	;	AX = VBE return status
   664                              <1> 	;	     AX = 004Fh -> succeeded
   665                              <1> 	;	     AX <> 004Fh -> failed   
   666                              <1> 	; 
   667                              <1> 	; Modified registers: eax
   668                              <1> 
   669 000018BC 21FF                <1> 	and	edi, edi
   670 000018BE 7406                <1> 	jz	short vbe3_func_fail ; invalid buffer addr !
   671 000018C0 EBE1                <1> 	jmp	short _vbe_biosfn_return_ctrl_info 
   672                              <1> 
   673                              <1> vbe3_pmfn_return_mode_info:
   674                              <1> 	; 02/08/2022 (TRDOS 386 Kernel v2.0.5)	
   675                              <1> 	; 21/12/2020
   676                              <1> 	; 12/12/2020
   677                              <1> 	;
   678                              <1> 	; VBE function 4F01h - Return VBE Mode Information
   679                              <1> 	;
   680                              <1> 	; Input:
   681                              <1> 	;	CX = Mode number (VESA VBE mode number)
   682                              <1> 	;      EDI = Pointer to ModeInfoBlock structure
   683                              <1> 	;	     (256 bytes) -User's buffer address-
   684                              <1> 	;      EDI = 0 -> kernel call
   685                              <1> 	;		  (do not transfer ModeInfoBlock
   686                              <1> 	;		  to user's buffer address)
   687                              <1> 	;	AX = 4F01h	
   688                              <1> 	; Output:
   689                              <1> 	;	AX = VBE return status
   690                              <1> 	;	     AX = 004Fh -> succeeded
   691                              <1> 	;	     AX <> 004Fh -> failed   
   692                              <1> 	; 
   693                              <1> 	; Modified registers: eax, esi, edi
   694                              <1> 
   695                              <1> 	; int 31h (int 10h) entrance
   696                              <1> 	
   697 000018C2 09FF                <1> 	or	edi, edi
   698 000018C4 7506                <1> 	jnz	short _vbe3_pmfn_return_mode_info
   699                              <1> 
   700                              <1> vbe3_func_fail:
   701 000018C6 B84F010000          <1> 	mov	eax, 014Fh ; ah = 1 : Function call failed
   702                              <1> 			   ; al = 4Fh : Function is supported
   703 000018CB C3                  <1> 	retn
   704                              <1> 	
   705                              <1> 	; jump from '_vbe_biosfn_return_mode_info' 
   706                              <1> _vbe3_pmfn_return_mode_info:
   707 000018CC 57                  <1> 	push	edi
   708                              <1> 
   709                              <1> 	;; clear vbe3 'mode info block' buffer
   710                              <1> 	;push	ecx
   711                              <1> 	;xor	eax, eax
   712                              <1> 	;mov	ecx, 256/4
   713                              <1> 	;mov	edi, VBE3MODEINFOBLOCK
   714                              <1> 	;rep	stosd
   715                              <1> 	;pop	ecx
   716                              <1> 
   717                              <1> 	; far call to VESA VBE3 PMI 
   718                              <1> 	;mov	ax, 4F01h ; Return VBE Mode Information
   719 000018CD BF00060000          <1> 	mov	edi, VBE3MODEINFOBLOCK-VBE3SAVERESTOREBLOCK
   720                              <1> 	; ES selector base address = VBE3SAVERESTOREBLOCK 
   721 000018D2 E812010000          <1> 	call	int10h_32bit_pmi
   722                              <1> 
   723 000018D7 5F                  <1> 	pop	edi
   724                              <1> 
   725                              <1> 	;cmp	ax, 004Fh
   726                              <1> 	;jne	short vbe3_func_retn  ; failed !
   727                              <1> 
   728 000018D8 21FF                <1> 	and	edi, edi
   729                              <1> 	;jz	short vbe3_func_success
   730                              <1> 	; 21/12/2020
   731 000018DA 741C                <1> 	jz	short vbe3_func_retn
   732                              <1> 
   733 000018DC 6683F84F            <1> 	cmp	ax, 004Fh
   734 000018E0 7516                <1> 	jne	short vbe3_func_retn  ; failed !
   735                              <1> 
   736 000018E2 51                  <1> 	push	ecx
   737 000018E3 BE007C0900          <1> 	mov	esi, VBE3MODEINFOBLOCK		
   738                              <1> 	;mov	ecx, 256
   739                              <1> 	; 02/08/2022
   740 000018E8 29C9                <1> 	sub	ecx, ecx
   741 000018EA FEC5                <1> 	inc	ch
   742                              <1> 	; ecx = 256
   743 000018EC E89FF60000          <1> 	call	transfer_to_user_buffer
   744 000018F1 59                  <1> 	pop	ecx
   745 000018F2 72D2                <1> 	jc	short vbe3_func_fail
   746                              <1> 
   747 000018F4 31C0                <1> 	xor	eax, eax
   748 000018F6 B04F                <1> 	mov	al, 4Fh ; successful
   749                              <1> vbe3_func_success:
   750                              <1> vbe3_func_retn:	
   751 000018F8 C3                  <1> 	retn
   752                              <1> 
   753                              <1> vbe3_pmfn_return_current_mode:
   754                              <1> 	; 12/12/2020
   755                              <1> 	;
   756                              <1> 	; VBE function 4F03h - Return Current VBE Mode
   757                              <1> 	;
   758                              <1> 	; Input:
   759                              <1> 	;	none (AX = 4F03h)
   760                              <1> 	; Output:
   761                              <1> 	;	AX = VBE return status
   762                              <1> 	;	     AX = 004Fh -> succeeded
   763                              <1> 	;	     AX <> 004Fh -> failed
   764                              <1> 	;	BX = Current VBE mode
   765                              <1> 	;	  bit 0-13 = Mode number
   766                              <1> 	;	  bit 14 = 0 Windowed frame buffer model
   767                              <1> 	;	         = 1 Linear frame buffer model
   768                              <1> 	;	  bit 15 
   769                              <1> 	;	      = 0 Memory cleared at last mode set
   770                              <1> 	;	      = 1 Memory not cleared at last mode set
   771                              <1> 	; 
   772                              <1> 	; Modified registers: eax, ebx
   773                              <1> 
   774                              <1> 	; int 31h (int 10h) entrance
   775                              <1> 	
   776                              <1> 	; far call to VESA VBE3 PMI 
   777                              <1> 
   778                              <1> 	;mov	eax, 4F03h ; Return Current VBE Mode
   779                              <1> vbe3_pmfn_far_call:
   780                              <1> 	; ES selector base address = VBE3SAVERESTOREBLOCK 
   781                              <1> 	;call	int10h_32bit_pmi
   782                              <1> 	;retn
   783 000018F9 E9EB000000          <1> 	jmp	int10h_32bit_pmi
   784                              <1> 
   785                              <1> vbe3_pmfn_set_mode:
   786                              <1> 	; 02/08/2022 (TRDOS 386 Kernel v2.0.5)
   787                              <1> 	; 22/12/2020
   788                              <1> 	; 21/12/2020
   789                              <1> 	; 12/12/2020
   790                              <1> 	;
   791                              <1> 	; VBE function 4F02h - Set VBE Mode
   792                              <1> 	;
   793                              <1> 	; Input:
   794                              <1> 	;	BX = Desired Mode to set
   795                              <1> 	;	  bit 0-13 = Mode number
   796                              <1> 	;	  bit 14 = 0 Windowed frame buffer model
   797                              <1> 	;	         = 1 Linear frame buffer model
   798                              <1> 	;	  bit 15 
   799                              <1> 	;	      = 0 Memory cleared at last mode set
   800                              <1> 	;	      = 1 Memory not cleared at last mode set
   801                              <1> 	; Output:
   802                              <1> 	;	AX = VBE return status
   803                              <1> 	;	     AX = 004Fh -> succeeded
   804                              <1> 	;	     AX <> 004Fh -> failed
   805                              <1> 	; 
   806                              <1> 	; Modified registers: eax, ebx, esi (21/12/2020)
   807                              <1> 
   808                              <1> 	; int 31h (int 10h) entrance
   809                              <1> 
   810                              <1> 	; 22/12/2020 (VESA VBE3 feature)
   811                              <1> 	; BX bit 11 is flag for
   812                              <1> 	;	user specified CRTC values for refresh rate
   813                              <1> 	; 'test bh, 8'
   814                              <1> 	; if bit 11 is set, EDI points to 'CRTCInfoBlock'
   815                              <1> 
   816                              <1> 	; 22/12/2020
   817                              <1> 	;; test bx for VBE video mode
   818                              <1> 	;test	bh, 1
   819                              <1> 	;jnz	short vbe3_sm_0
   820                              <1> 
   821                              <1> 	;; use internal VBE mode set procedure
   822                              <1> 	;; for non-vbe (std VGA/CGA) modes
   823                              <1> 	;
   824                              <1> 	;; (it is useful -as 4F02h function- 
   825                              <1> 	;;  to jump 'vbe_biosfn_set_mode'
   826                              <1> 	;;  instead of direct jump to '_set_mode')
   827                              <1> 	;; ((eliminates additional push-pops and settings))
   828                              <1>  
   829                              <1> 	;jmp	vbe_biosfn_set_mode	
   830                              <1> 
   831                              <1> vbe3_sm_0: 
   832                              <1> 	;;push	ds  ; *
   833                              <1> 	;;push	es  ; **
   834                              <1> 	;;push	ebp ; ***
   835                              <1> 	;;push	esi ; **** 
   836                              <1> 	
   837                              <1> 	; Fit bx to VESA VBE2 type mode setting
   838                              <1> 	; (bx bit 11 is used for custom CRTC values in VBE3)
   839                              <1> 	; clear bit 9 to 11 (clear bh bit 1 to bit 3)
   840                              <1> 
   841                              <1> 	; 22/12/2020
   842 000018FE 57                  <1> 	push	edi ; *****
   843 000018FF F6C708              <1> 	test	bh, 8	; Use user specified CRTC values
   844 00001902 7530                <1> 	jnz	short vbe3_sm_3  ; for refresh rate
   845                              <1> vbe3_sm_4:
   846 00001904 80E7C1              <1> 	and	bh, 0C1h ; use bit 15, 14, 8 only (for bh)
   847                              <1> 	;mov	[vbe_mode_x], bh
   848                              <1> 
   849 00001907 803D[DE670000]03    <1> 	cmp	byte [CRT_MODE], 3 ; is current mode 03h ?
   850 0000190E 7509                <1> 	jne	short vbe3_sm_1    ; no
   851                              <1> 
   852                              <1> 	; save mode 03h video pages and cursor positions
   853 00001910 57                  <1> 	push	edi ; **!***	
   854 00001911 51                  <1> 	push	ecx ; ******
   855                              <1> 	;push	esi
   856                              <1> 	
   857 00001912 E8CE040000          <1> 	call	save_mode3_multiscreen
   858                              <1> 	
   859                              <1> 	;pop	esi
   860 00001917 59                  <1> 	pop	ecx ; ******
   861 00001918 5F                  <1> 	pop	edi ; **!***
   862                              <1> vbe3_sm_1:
   863                              <1> 	; ax = 4F02h
   864                              <1> 	; bx = video mode number (vbe2 type)
   865 00001919 E8CB000000          <1> 	call	int10h_32bit_pmi 
   866                              <1> 			; call to far call to VBE3 PMI
   867                              <1> 
   868 0000191E 6683F84F            <1> 	cmp	ax, 004Fh ; succeeded ?
   869 00001922 750E                <1> 	jne	short vbe3_sm_2
   870                              <1> 	; set current mode byte/sign to extended (SVGA) mode
   871 00001924 C605[DE670000]FF    <1> 	mov	byte [CRT_MODE], 0FFh ; VESA VBE mode
   872                              <1> 	; set current VBE mode word to bx input
   873 0000192B 66891D[2EA30100]    <1> 	mov	[video_mode], bx
   874                              <1> vbe3_sm_2:
   875                              <1> 	; 22/12/2020
   876 00001932 5F                  <1> 	pop	edi ; ***** 
   877 00001933 C3                  <1> 	retn
   878                              <1> 
   879                              <1> vbe3_sm_3:
   880                              <1> 	; 22/12/2020
   881                              <1> 	; copy user's CRTCInfoBlock to the buffer
   882 00001934 51                  <1> 	push	ecx
   883 00001935 89FE                <1> 	mov	esi, edi
   884 00001937 BF807D0900          <1> 	mov	edi, VBE3CRTCINFOBLOCK
   885                              <1> 	;mov	ecx, 64
   886                              <1> 	; 02/08/2022
   887 0000193C 29C9                <1> 	sub	ecx, ecx
   888 0000193E B140                <1> 	mov	cl, 64
   889 00001940 E895F60000          <1> 	call	transfer_from_user_buffer
   890 00001945 59                  <1> 	pop	ecx
   891                              <1> 	; set offset (es base addr is VBE3SAVERESTOREBLOCK) 
   892 00001946 81EF00760900        <1> 	sub	edi, VBE3SAVERESTOREBLOCK
   893 0000194C EBB6                <1> 	jmp	short vbe3_sm_4
   894                              <1> 	
   895                              <1> vesa_vbe3_pmi:
   896                              <1> 	; 29/11/2023 - TRDOS 386 v2.0.7
   897                              <1> 	; 12/12/2020
   898                              <1> 	; 08/12/2020
   899                              <1> 	; 07/12/2020
   900                              <1> 	; 05/12/2020, 06/12/2020
   901                              <1> 	; 03/12/2020, 04/12/2020
   902                              <1> 	; 28/11/2020 (TRDOS 386 v2.0.3)
   903                              <1> 	; VGA BIOS functions via
   904                              <1> 	; VESA VBE3 Protected Mode Inface
   905                              <1> 	; [vbe3] = 3 and [pmi32] > 0
   906                              <1> 
   907                              <1> 	; 04/12/2020
   908                              <1> 	; Only 'set mode' will be redirected to vbe3 video bios
   909                              <1> 	; (by setting mode 3 multiscreen parameters before and after) 
   910                              <1> 
   911                              <1> 	; 29/11/2023 - TRDOS 386 v2.0.7
   912 0000194E 50                  <1> 	push	eax
   913 0000194F 0F20D8              <1> 	mov	eax, cr3
   914 00001952 870424              <1> 	xchg	eax, [esp] ; **!**
   915 00001955 50                  <1> 	push	eax
   916                              <1> 	;cmp	esi, [k_page_dir]
   917                              <1> 	;je	short vesa_vbe3_pmi_x
   918 00001956 A1[C07C0100]        <1> 	mov	eax, [k_page_dir]
   919 0000195B 0F22D8              <1> 	mov	cr3, eax
   920                              <1> ;vesa_vbe3_pmi_x:
   921 0000195E 58                  <1> 	pop	eax
   922                              <1> 
   923                              <1> 	; 06/12/2020
   924 0000195F 20E4                <1> 	and	ah, ah	; 0 = set mode function
   925 00001961 7402                <1> 	jz	short vbe3_pmi_0
   926 00001963 EB7D                <1> 	jmp	vbe3_pmi_9 
   927                              <1> 
   928                              <1> vbe3_pmi_0:
   929                              <1> 	; 07/12/2020
   930 00001965 88C4                <1> 	mov	ah, al
   931 00001967 80E480              <1> 	and	ah, 80h ; 0 or 80h
   932 0000196A 30E0                <1> 	xor	al, ah ; 8?h -> 0?h
   933                              <1> 
   934                              <1> 	;cmp	al, 13h ; mode number above 13h is returned
   935                              <1> 	;jna	short vbe3_pmi_1
   936                              <1> 	;		; back to default code due to uncertainty
   937                              <1> 	; 		; (>13h is not std for all svga bioses)
   938                              <1> 	;jmp	VGA_funcs_0
   939                              <1> vbe3_pmi_1:
   940                              <1> 	; 07/12/2020
   941                              <1> 	; Possible cases for VBE3 (PMI, ah=0) set mode:
   942                              <1> 	; current mode > 07h and requested mode: any 
   943                              <1> 	; current mode <= 07h and requested mode > 07h
   944                              <1> 
   945                              <1> 	; 06/12/2020
   946 0000196C 8825[53890100]      <1> 	mov	byte [noclearmem], ah ; 0 or 80h
   947                              <1> 	; check current video mode if it is 03h
   948 00001972 803D[DE670000]03    <1> 	cmp	byte [CRT_MODE], 3 ; current mode
   949 00001979 750B                <1> 	jne	short vbe3_pmi_3
   950                              <1> 	; 07/12/2020
   951                              <1> 	; check new video mode if it is 03h also
   952                              <1> 	;cmp	al, 3
   953                              <1> 	;jne	short vbe3_pmi_2
   954                              <1> 	;mov	byte [p_crt_mode], 80h 	; clear video memory
   955                              <1> 	;jmp	short vbe3_pmi_5
   956                              <1> vbe3_pmi_2:
   957                              <1> 	; case 1:
   958                              <1> 	; Current mode is 03h and new mode is not 03h
   959                              <1> 
   960                              <1> 	; save video pages and cursor positions
   961 0000197B 56                  <1> 	push	esi
   962 0000197C 57                  <1> 	push	edi
   963 0000197D 51                  <1> 	push	ecx
   964                              <1> 
   965                              <1> 	; 12/12/2020
   966                              <1> 	;mov	esi, 0B8000h ; mode 3 video memory
   967                              <1> 	;mov	edi, 98000h  ; backup location
   968                              <1> 	;mov	ecx, (0B8000h-0B0000h)/4
   969                              <1> 	;rep	movsd
   970                              <1> 	;
   971                              <1> 	;mov	byte [p_crt_mode], 3 ; previous mode, backup sign
   972                              <1> 	;xchg	cl, [ACTIVE_PAGE]
   973                              <1> 	;mov	[p_crt_page], cl  ; save as previous active page
   974                              <1> 	;
   975                              <1> 	;; save cursor positions
   976                              <1> 	;mov	esi, CURSOR_POSN
   977                              <1> 	;mov	edi, cursor_pposn ; cursor positions backup
   978                              <1> 	;mov	cl, 4
   979                              <1> 	;rep	movsd
   980                              <1> 
   981                              <1> 	; 12/12/2020
   982 0000197E E862040000          <1> 	call	save_mode3_multiscreen
   983                              <1> 
   984 00001983 59                  <1> 	pop	ecx
   985 00001984 5F                  <1> 	pop	edi
   986 00001985 5E                  <1> 	pop	esi
   987                              <1> vbe3_pmi_3:
   988                              <1> 	; 08/12/2020
   989                              <1> 	; 07/12/2020
   990                              <1> 	; case 3 or case 4
   991 00001986 A2[DE670000]        <1> 	mov	[CRT_MODE], al
   992 0000198B 3C03                <1> 	cmp	al, 3
   993 0000198D 7407                <1> 	je	short vbe3_pmi_4
   994                              <1> 	; case 4:
   995                              <1> 	; Current mode is not 03h and also new mode is not 03h
   996 0000198F 800D[51890100]80    <1> 	or	byte [p_crt_mode], 80h  ; 83h (case 1 -> case 4)
   997                              <1> 	;jmp	short vbe3_pmi_5
   998                              <1> vbe3_pmi_4:
   999                              <1> 	; case 3:
  1000                              <1> 	;
  1001                              <1> 	; Current mode is not 03h and new mode is 03h
  1002                              <1> 
  1003                              <1> ;vbe3_pmi_5:
  1004                              <1> 	;mov	[CRT_MODE], al
  1005                              <1> 
  1006 00001996 E84E000000          <1> 	call	int10h_32bit_pmi	
  1007                              <1> 
  1008 0000199B 803D[DE670000]03    <1> 	cmp	byte [CRT_MODE], 3  ; new video mode
  1009                              <1> 	;jne	vbe3_pmi_8	; video mode <> 03h
  1010 000019A2 7532                <1> 	jne	short vbe3_pmi_8	
  1011                              <1> 
  1012                              <1> 	;push	eax ; 04/12/2020
  1013 000019A4 53                  <1> 	push	ebx
  1014 000019A5 51                  <1> 	push	ecx
  1015 000019A6 52                  <1> 	push	edx
  1016 000019A7 57                  <1> 	push	edi ; 03/12/2020
  1017                              <1> 
  1018                              <1> 	; 12/12/2020
  1019 000019A8 56                  <1> 	push	esi
  1020 000019A9 E869040000          <1> 	call	restore_mode3_multiscreen
  1021 000019AE 5E                  <1> 	pop	esi
  1022                              <1> 	; AL = active video page
  1023                              <1> 
  1024                              <1> 	; 12/12/2020
  1025                              <1> 	;mov	al, [p_crt_page] ; previous mode 3 active page
  1026                              <1> 	;
  1027                              <1> 	;;test	byte [p_crt_mode], 7Fh ; 83h or 80h or 03h
  1028                              <1> 	;;jz	short vbe3_pmi_6 ; do not restore video pages
  1029                              <1> 	;			 ; clear current video page
  1030                              <1> 	;; case 3
  1031                              <1> 	;
  1032                              <1> 	;; ([p_crt_mode] = 03h)
  1033                              <1> 	;
  1034                              <1> 	;; New video mode is 3 while current video mode is not 3
  1035                              <1> 	;; (multi screen) video pages will be restored from 098000h
  1036                              <1> 	;
  1037                              <1> 	;; restore video pages and cursor positions
  1038                              <1> 	;
  1039                              <1> 	;mov	[ACTIVE_PAGE], al ; current mode 3 active page
  1040                              <1> 	;
  1041                              <1> 	;push	esi
  1042                              <1> 	;
  1043                              <1> 	;; restore video pages
  1044                              <1> 	;mov	esi, 98000h
  1045                              <1> 	;mov	edi, 0B8000h
  1046                              <1> 	;;mov	ecx, 2000h
  1047                              <1> 	;mov	cx, 2000h ; 8K dwords (32K)
  1048                              <1> 	;rep	movsd
  1049                              <1> 	;
  1050                              <1> 	;mov	[p_crt_mode], cl ; reset ('case 3' end condition)
  1051                              <1> 	;
  1052                              <1> 	;; restore cursor positions
  1053                              <1> 	;mov	esi, cursor_pposn
  1054                              <1> 	;mov	edi, CURSOR_POSN
  1055                              <1> 	;;mov	ecx, 4	; restore all cursor positions (16 bytes)
  1056                              <1> 	;mov	cl, 4
  1057                              <1> 	;rep 	movsd
  1058                              <1> 	;
  1059                              <1> 	;pop	esi
  1060                              <1> 	;
  1061                              <1> 	;; 07/12/2020
  1062                              <1> 	;; restore CRT_START according to ACTIVE_PAGE
  1063                              <1> 	;mov	[CRT_START], cx ; 0
  1064                              <1> 	;
  1065                              <1> 	;; check active page and set it again if it is not 0
  1066                              <1> 	;or	al, al
  1067                              <1> 	;jz	short vbe3_pmi_7
  1068                              <1> 	;
  1069                              <1> 	;mov	cl, al
  1070                              <1> ;vbe3_pmi_5:
  1071                              <1> 	;add	word [CRT_START], 4096
  1072                              <1> 	;dec	cl
  1073                              <1> 	;jnz	short vbe3_pmi_5
  1074                              <1> 
  1075 000019AF B405                <1> 	mov	ah, 05h ; set current video page
  1076                              <1> 	;al = video page
  1077 000019B1 E833000000          <1> 	call	int10h_32bit_pmi
  1078                              <1> 	
  1079                              <1> 	; check current cursor position & set it again if not 0,0
  1080                              <1> 	;movzx	ebx, byte [ACTIVE_PAGE]
  1081 000019B6 0FB6D8              <1> 	movzx	ebx, al
  1082 000019B9 D0E3                <1> 	shl	bl, 1
  1083 000019BB 81C3[DE7C0100]      <1> 	add	ebx, CURSOR_POSN
  1084 000019C1 668B13              <1> 	mov	dx, [ebx]
  1085 000019C4 6621D2              <1> 	and	dx, dx		
  1086 000019C7 7409                <1> 	jz	short vbe3_pmi_7
  1087                              <1> 	
  1088                              <1> 	;dx = cursor position (dl = column, dh = row)
  1089                              <1> 	;mov	bh, [ACTIVE_PAGE] ; 06/12/2020
  1090 000019C9 88C7                <1> 	mov	bh, al
  1091 000019CB B402                <1> 	mov	ah, 02h ; set cursor position
  1092 000019CD E817000000          <1> 	call	int10h_32bit_pmi
  1093                              <1> 	
  1094                              <1> 	;jmp	short vbe3_pmi_7
  1095                              <1> 
  1096                              <1> ;vbe3_pmi_6:
  1097                              <1> ;	; 07/12/2020
  1098                              <1> ;	; case 1, previous mode is 03h, current mode is 03h
  1099                              <1> ;	; 03/12/2020
  1100                              <1> ;	cmp	byte [noclearmem], 0
  1101                              <1> ;	jna	short vbe3_pmi_7 ; do not clear memory
  1102                              <1> ;	; clear video page
  1103                              <1> ;	mov	ecx, 1024 ; 4096/4
  1104                              <1> ;	mov	eax, 07200720h
  1105                              <1> ;	mov	edi, 0B8000h ; [crt_base]
  1106                              <1> ;	add	di, [CRT_START]
  1107                              <1> ;	rep	stosd	; FILL THE REGEN BUFFER WITH BLANKS
  1108                              <1> 
  1109                              <1> vbe3_pmi_7:
  1110 000019D2 5F                  <1> 	pop	edi
  1111 000019D3 5A                  <1> 	pop	edx
  1112 000019D4 59                  <1> 	pop	ecx
  1113 000019D5 5B                  <1> 	pop	ebx
  1114                              <1> 	;pop	eax ; 04/12/2020
  1115                              <1> vbe3_pmi_8:
  1116                              <1> 	; 04/12/2020
  1117                              <1> 	;(TRDOS 386 v2.0.3, INT 31h, ah=0 return)
  1118 000019D6 31C0                <1> 	xor	eax, eax  ; eax = 0 -> succesful
  1119                              <1> vesa_vbe3_pmi_retn:
  1120                              <1> 	; 29/11/2023 - TRDOS 386 v2.0.7
  1121 000019D8 870424              <1> 	xchg	eax, [esp] ; **!**
  1122                              <1> 	;cmp	eax, [k_page_dir]
  1123                              <1> 	;je	short vesa_vbe3_pmi_retn_x
  1124 000019DB 0F22D8              <1> 	mov	cr3, eax
  1125                              <1> ;vesa_vbe3_pmi_retn_x:
  1126 000019DE 58                  <1> 	pop	eax
  1127                              <1> 	;
  1128 000019DF 07                  <1> 	pop	es  ; **
  1129 000019E0 1F                  <1> 	pop	ds  ; *
  1130 000019E1 CF                  <1> 	iretd
  1131                              <1> 
  1132                              <1> vbe3_pmi_9:
  1133                              <1> 	; 06/12/2020 
  1134                              <1> 	;cmp	ah, 10h ; Set/Get Palette Registers
  1135                              <1> 	;jnb	short vbe3_pmi_10
  1136                              <1> 	; 05/12/2020
  1137 000019E2 E802000000          <1> 	call	int10h_32bit_pmi
  1138 000019E7 EBEF                <1> 	jmp	short vesa_vbe3_pmi_retn
  1139                              <1> 
  1140                              <1> ;vbe3_pmi_10:
  1141                              <1> 	; 06/12/2020
  1142                              <1> 	;jmp	VGA_funcs_0
  1143                              <1> 
  1144                              <1> int10h_32bit_pmi:
  1145                              <1> 	; 03/12/2020
  1146                              <1> 	; 28/11/2020
  1147                              <1> 	; calling standard VGA Bios (INT 10h) functions
  1148                              <1> 	; by using 32 bit protected mode interface of
  1149                              <1> 	; VESA VBE3 Video Bios (with 'PMID' signature)
  1150                              <1> 
  1151                              <1> 	; 03/12/2020
  1152                              <1> 	; eax, ebx, ecx, edx, edi will be used by vbios pmi
  1153                              <1> 	; (esi and ebp will not be used) 
  1154                              <1> 
  1155                              <1> 	; 03/12/2020
  1156 000019E9 56                  <1> 	push	esi
  1157 000019EA C1E010              <1> 	shl	eax, 16  ; move function number (ax) to hw
  1158 000019ED 8B35[34A30100]      <1> 	mov	esi, [pmid_addr] ; linear address of
  1159                              <1> 				 ; PMInfo.Entrypoint pointer
  1160                              <1> 	;mov	ax, [esi+PMInfo.EntryPoint]	
  1161 000019F3 668B06              <1> 	mov	ax, [esi]	 
  1162 000019F6 C1C010              <1> 	rol	eax, 16 ; move PM entry address to hw
  1163                              <1> 			; and move function number to lw (ax)
  1164 000019F9 5E                  <1> 	pop	esi
  1165                              <1> 
  1166                              <1> 	; top of stack: ; (*)
  1167                              <1> 	; return (the caller) address of "int10h_32bit_pmi"
  1168                              <1> 
  1169 000019FA E965EDFFFF          <1> 	jmp	_VBE3PMI_fcall ; will return to the caller (*)
  1170                              <1> 
  1171                              <1> _vbe3_pmfn_srs_8:
  1172                              <1> 	; 17/01/2021
  1173 000019FF 31DB                <1> 	xor 	ebx, ebx ; points to VBE3SAVERESTOREBLOCK
  1174                              <1> _vbe3_pmfn_srs_9: ; 24/01/2021
  1175 00001A01 66B8044F            <1> 	mov	ax, 4F04h
  1176 00001A05 EBE2                <1> 	jmp	short int10h_32bit_pmi
  1177                              <1> 
  1178                              <1> vbe3_pmfn_save_restore_state:
  1179                              <1> 	; 02/08/2022 (TRDOS 386 Kernel v2.0.5)
  1180                              <1> 	; 24/01/2021
  1181                              <1> 	; 23/01/2021
  1182                              <1> 	; 16/01/2021 - 17/01/2021
  1183                              <1> 	; 14/01/2021
  1184                              <1> 	;
  1185                              <1> 	; VBE function 4F04h - Save/Restore Video State
  1186                              <1> 	;
  1187                              <1> 	; Input:
  1188                              <1> 	;	DL = sub function
  1189                              <1> 	;	CL = requested state
  1190                              <1> 	;      EBX = pointer to buffer (if DL<>00h)
  1191                              <1> 	;	AX = 4F04h 
  1192                              <1> 	; Output:
  1193                              <1> 	;	AX = 004Fh (successful)
  1194                              <1> 	;	AH > 0 -> error
  1195                              <1> 	;	BX = Number of 64-byte blocks 
  1196                              <1> 	;	     to hold the state buffer (if DL=00h)
  1197                              <1> 
  1198                              <1> 	; Modified registers: eax, ebx, esi, edi
  1199                              <1> 	
  1200 00001A07 21DB                <1> 	and	ebx, ebx ; user's buffer address
  1201 00001A09 750A                <1> 	jnz	short _vbe3_pmfn_save_restore_state
  1202                              <1> 
  1203 00001A0B 08D2                <1> 	or	dl, dl
  1204 00001A0D 740C                <1> 	jz	short _vbe3_pmfn_srs_0
  1205                              <1> 
  1206                              <1> 	; function failed
  1207                              <1> 	;;mov	eax, 0100h
  1208                              <1> 	;sub	eax, eax
  1209                              <1> 	;inc	ah  ; eax = 0100h
  1210                              <1> 	;retn
  1211                              <1> 	; 16/01/2021
  1212                              <1> _vbe3_pmfn_srs_fail:
  1213 00001A0F B84F010000          <1> 	mov	eax, 014Fh ; ah = 1 : Function call failed
  1214                              <1> 			   ; al = 4Fh : Function is supported
  1215                              <1> _vbe3_srs_retn:
  1216 00001A14 C3                  <1> 	retn
  1217                              <1> 
  1218                              <1> _vbe3_pmfn_save_restore_state:
  1219 00001A15 20D2                <1> 	and	dl, dl
  1220 00001A17 7555                <1> 	jnz	short _vbe3_pmfn_srs_2
  1221                              <1> _vbe3_pmfn_srs:
  1222 00001A19 31DB                <1> 	xor	ebx, ebx
  1223                              <1> _vbe3_pmfn_srs_0:
  1224                              <1> 	; 24/01/2021
  1225 00001A1B 83F90F              <1> 	cmp	ecx, 0Fh
  1226                              <1> 	;ja	short _vbe3_pmfn_srs_1
  1227 00001A1E 77EF                <1> 	ja	short _vbe3_pmfn_srs_fail 
  1228                              <1> 
  1229                              <1> 	; !!! CLEAR CL BIT 2 !!! 
  1230                              <1> 	; (when bit 2 is set, function causes cpu exception)
  1231                              <1> 	; BIOS data will not be saved and restored
  1232                              <1> 	; (to prevent protected mode page fault error)
  1233 00001A20 80E1FD              <1> 	and	cl, ~2 ; and cl, not 2
  1234                              <1> 	
  1235                              <1> 	; 24/01/2021
  1236                              <1> 	;mov	bl, 1
  1237 00001A23 FEC3                <1> 	inc	bl ; = 1
  1238                              <1> 	;shl	bx, cl 
  1239                              <1> 	; 02/08/2022
  1240 00001A25 D3E3                <1> 	shl	ebx, cl
  1241 00001A27 66231D[38A30100]    <1> 	and	bx, [vbe3stbsflags]
  1242 00001A2E 7415                <1> 	jz	short _vbe3_pmfn_srs_1
  1243                              <1> 	;mov	bx, cx
  1244 00001A30 89CB                <1> 	mov	ebx, ecx ; <= 15
  1245 00001A32 D0E3                <1> 	shl	bl, 1 ; 0, 2, 8 .. 30
  1246 00001A34 668B9B[3D3B0000]    <1> 	mov	bx, [vbestatebufsize+ebx]
  1247 00001A3B 89DF                <1> 	mov	edi, ebx
  1248                              <1> 	; edi = state buffer size in bytes
  1249                              <1> 	;shr	bx, 6 ; / 64
  1250                              <1> 	; 02/08/2022
  1251 00001A3D C1EB06              <1> 	shr	ebx, 6
  1252                              <1> 	;mov	ax, 4Fh
  1253 00001A40 28E4                <1> 	sub	ah, ah
  1254 00001A42 B04F                <1> 	mov	al, 4Fh
  1255 00001A44 C3                  <1> 	retn
  1256                              <1> _vbe3_pmfn_srs_1:
  1257                              <1> 	; ax = 4F04h
  1258                              <1> 	;call	int10h_32bit_pmi
  1259                              <1> 	; 24/01/2021
  1260                              <1> 	;call	_vbe3_pmfn_srs_8
  1261                              <1> 	; ebx = 0
  1262 00001A45 E8B7FFFFFF          <1> 	call	_vbe3_pmfn_srs_9	
  1263 00001A4A 6683F84F            <1> 	cmp	ax, 004Fh
  1264 00001A4E 75C4                <1> 	jne	short _vbe3_srs_retn
  1265                              <1> 	; 24/01/2021
  1266                              <1> 	;cmp	ecx, 0Fh
  1267                              <1> 	;ja	short _vbe3_srs_retn
  1268                              <1> 	; 24/01/2021
  1269                              <1> 	;mov	ax, 1
  1270 00001A50 B001                <1> 	mov	al, 1
  1271                              <1> 	;shl	ax, cl		
  1272                              <1> 	; 02/08/2022
  1273 00001A52 D3E0                <1> 	shl	eax, cl
  1274 00001A54 660905[38A30100]    <1> 	or	[vbe3stbsflags], ax ; set flag for state option
  1275                              <1> 	; 23/01/2021
  1276 00001A5B 89DF                <1> 	mov	edi, ebx
  1277 00001A5D 89C8                <1> 	mov	eax, ecx
  1278 00001A5F D0E0                <1> 	shl	al, 1
  1279                              <1> 	;shl	di, 6 ; * 64
  1280                              <1> 	; 02/08/2022
  1281 00001A61 C1E706              <1> 	shl	edi, 6
  1282 00001A64 6689B8[3D3B0000]    <1> 	mov	[vbestatebufsize+eax], di
  1283                              <1> 				; save buf size for option 
  1284                              <1> 	;xchg	edi, ebx
  1285                              <1> 	; edi = state buffer size in bytes
  1286 00001A6B B04F                <1> 	mov	al, 4Fh
  1287 00001A6D C3                  <1> 	retn
  1288                              <1> 
  1289                              <1> _vbe3_pmfn_srs_2:
  1290                              <1> 	; 24/01/2021
  1291                              <1> 	; !!! CLEAR CL BIT 2 !!! 
  1292                              <1> 	; (when bit 2 is set, function causes cpu exception)
  1293                              <1> 	; BIOS data will not be saved and restored
  1294                              <1> 	; (to prevent protected mode page fault error)
  1295                              <1> 
  1296 00001A6E F6C1FD              <1> 	test	cl, ~2 ; test cl, not 2
  1297 00001A71 749C                <1> 	jz	short _vbe3_pmfn_srs_fail
  1298                              <1> 
  1299 00001A73 80FA02              <1> 	cmp	dl, 2
  1300 00001A76 7748                <1> 	ja	short _vbe3_pmfn_srs_5
  1301                              <1> 
  1302                              <1> 	;and	cl, ~2 ; and cl, not 2
  1303                              <1> 
  1304 00001A78 53                  <1> 	push	ebx ; * ; buffer address
  1305                              <1> 	; save or restore state
  1306                              <1> 	; (get required buffer size at first)
  1307 00001A79 52                  <1> 	push	edx ; **
  1308 00001A7A 28D2                <1> 	sub	dl, dl ; 0
  1309 00001A7C E898FFFFFF          <1> 	call	_vbe3_pmfn_srs
  1310 00001A81 5A                  <1> 	pop	edx ; **
  1311                              <1> 	; 24/01/2021
  1312 00001A82 5B                  <1> 	pop	ebx ; *
  1313 00001A83 08E4                <1> 	or	ah, ah
  1314 00001A85 7538                <1> 	jnz	short _vbe3_pmfn_srs_4 ; error
  1315                              <1> 
  1316                              <1> 	; edi = buffer size in bytes
  1317 00001A87 81FF00080000        <1> 	cmp	edi, 2048
  1318 00001A8D 772B                <1> 	ja	short _vbe3_pmfn_srs_3
  1319                              <1> 
  1320 00001A8F 80FA01              <1> 	cmp	dl, 1
  1321 00001A92 7531                <1> 	jne	short _vbe3_pmfn_srs_6 ; restore state
  1322                              <1> 	
  1323                              <1> 	; save video state
  1324                              <1> 	;xor 	ebx, ebx ; points to VBE3SAVERESTOREBLOCK
  1325                              <1> 	;mov	ax, 4F04h
  1326                              <1> 	;call	int10h_32bit_pmi
  1327                              <1> 
  1328                              <1> 	; 24/01/2021
  1329 00001A94 E842000000          <1> 	call	_vbe3_pmfn_srs_7
  1330                              <1> 	
  1331 00001A99 6683F84F            <1> 	cmp	ax, 004Fh
  1332 00001A9D 7520                <1> 	jne	short _vbe3_pmfn_srs_4
  1333                              <1> 
  1334 00001A9F 09DB                <1> 	or	ebx, ebx  ; kernel ('sysvideo') ?
  1335 00001AA1 741C                <1> 	jz	short _vbe3_pmfn_srs_4 ; yes
  1336                              <1> 
  1337                              <1> 	; the caller is user
  1338 00001AA3 51                  <1> 	push	ecx ; *
  1339 00001AA4 89F9                <1> 	mov	ecx, edi ; state buffer size
  1340 00001AA6 BE00760900          <1> 	mov	esi, VBE3SAVERESTOREBLOCK ; source
  1341                              <1> 					; (vbe3 pmi buff)
  1342 00001AAB 89DF                <1> 	mov	edi, ebx	; destination (user buff)
  1343 00001AAD E8DEF40000          <1> 	call	transfer_to_user_buffer
  1344 00001AB2 59                  <1> 	pop	ecx ; *
  1345 00001AB3 7205                <1> 	jc	short _vbe3_pmfn_srs_3
  1346                              <1> 
  1347 00001AB5 29C0                <1> 	sub	eax, eax
  1348 00001AB7 B04F                <1> 	mov	al, 4Fh
  1349 00001AB9 C3                  <1> 	retn
  1350                              <1> 
  1351                              <1> 	; 24/01/2021
  1352                              <1> _vbe3_pmfn_srs_3:
  1353 00001ABA B84F010000          <1> 	mov	eax, 014Fh
  1354                              <1> _vbe3_pmfn_srs_4:
  1355 00001ABF C3                  <1> 	retn
  1356                              <1> _vbe3_pmfn_srs_5:
  1357 00001AC0 31C0                <1> 	xor	eax, eax
  1358 00001AC2 FEC4                <1> 	inc	ah
  1359                              <1> 	; eax = 0100h, function is not supported
  1360 00001AC4 C3                  <1> 	retn
  1361                              <1> 
  1362                              <1> _vbe3_pmfn_srs_6:
  1363                              <1> 	; restore video state
  1364                              <1> 	; 24/01/2021
  1365                              <1> 	;pop	ebx ; *
  1366                              <1> 	; 23/01/2021
  1367 00001AC5 09DB                <1> 	or	ebx, ebx ; 0 ?	
  1368 00001AC7 7412                <1> 	jz	short _vbe3_pmfn_srs_7 ; 'sysvideo' call
  1369                              <1> 	; 24/01/2021
  1370                              <1> 	;jz	_vbe3_pmfn_srs_8
  1371 00001AC9 89DE                <1> 	mov	esi, ebx
  1372                              <1> 	; esi = user's video state buffer
  1373 00001ACB 51                  <1> 	push	ecx ; *
  1374 00001ACC 89F9                <1> 	mov	ecx, edi ; state buffer size
  1375 00001ACE BF00760900          <1> 	mov	edi, VBE3SAVERESTOREBLOCK ; destination
  1376                              <1> 					; (vbe3 pmi buff)
  1377                              <1> 	;mov	esi, ebx	; source (user buff)
  1378 00001AD3 E802F50000          <1> 	call	transfer_from_user_buffer
  1379 00001AD8 59                  <1> 	pop	ecx ; *
  1380 00001AD9 72DF                <1> 	jc	short _vbe3_pmfn_srs_3
  1381                              <1> _vbe3_pmfn_srs_7:
  1382 00001ADB 53                  <1> 	push	ebx ; *
  1383                              <1> 	; restore video state
  1384                              <1> 	;xor 	ebx, ebx ; points to VBE3SAVERESTOREBLOCK
  1385                              <1> 	;mov	ax, 4F04h
  1386                              <1> 	;call	int10h_32bit_pmi
  1387                              <1> 	; 17/01/2021
  1388 00001ADC E81EFFFFFF          <1> 	call	_vbe3_pmfn_srs_8
  1389 00001AE1 5B                  <1> 	pop	ebx ; *
  1390 00001AE2 C3                  <1> 	retn
  1391                              <1> 
  1392                              <1> VIDEO_STATE:
  1393                              <1> 	; 26/06/2016
  1394                              <1> 	; 12/05/2016
  1395                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1396                              <1> 
  1397                              <1> ;---------------------------------------------------
  1398                              <1> ; VIDEO STATE
  1399                              <1> ;  RETURNS THE CURRENT VIDEO STATE IN AX
  1400                              <1> ;  AH = NUMBER OF COLUMNS ON THE SCREEN
  1401                              <1> ;  AL = CURRENT VIDEO MODE
  1402                              <1> ;  BH = CURRENT ACTIVE PAGE
  1403                              <1> ;---------------------------------------------------
  1404                              <1> 
  1405 00001AE3 8A25[E0670000]      <1> 	mov	ah, [CRT_COLS]	; GET NUMBER OF COLUMNS
  1406 00001AE9 A0[DE670000]        <1> 	mov	al, [CRT_MODE]	; CURRENT MODE
  1407                              <1> 	;movzx	esi, al
  1408                              <1> 	;mov	ah, [esi+M6] 
  1409                              <1> 	; BH = active page
  1410 00001AEE 8A3D[EE7C0100]      <1> 	mov	bh, [ACTIVE_PAGE] ; GET CURRENT ACTIVE PAGE
  1411 00001AF4 FA                  <1> 	cli	; 02/01/2017
  1412 00001AF5 5D                  <1> 	pop	ebp		; RECOVER REGISTERS
  1413 00001AF6 5F                  <1> 	pop	edi
  1414 00001AF7 5E                  <1> 	pop	esi
  1415 00001AF8 59                  <1> 	pop	ecx		; DISCARD SAVED BX
  1416 00001AF9 EB41                <1> 	jmp	short M15	; RETURN TO CALLER
  1417                              <1> 
  1418                              <1> set_mode_ncm:
  1419                              <1> 	; 17/11/2020 (TRDOS 386 v2.0.3)
  1420                              <1> 	; 04/07/2016 - TRDOS 386 (TRDOS v2.0)
  1421                              <1> 	; set mode without clearing the video memory
  1422                              <1> 	; (ony for graphics modes)
  1423                              <1> 
  1424                              <1> 	;cmp	al, 7 ; IBM PC CGA modes
  1425                              <1> 	;jna	short SET_MODE ; normal function (clear)
  1426                              <1> 	;; do not clear memory
  1427                              <1> 	;;mov	[noclearmem], al ; > 0
  1428                              <1> 	;mov	byte [noclearmem], 80h ; 17/11/2020
  1429                              <1> 	;call	_set_mode
  1430                              <1> 	;mov	byte [noclearmem], 0
  1431                              <1>         ;jmp     short VIDEO_RETURN
  1432                              <1> 
  1433                              <1> 	; 17/11/2020 (TRDOS v2.0.3)
  1434 00001AFB 0C80                <1> 	or	al, 80h ; not clear memory option
  1435                              <1> 
  1436                              <1> 	; 05/12/2020
  1437                              <1> 	; 27/11/2020
  1438                              <1> 	; 17/11/2020
  1439                              <1> 	; 08/08/2016, 10/08/2016
  1440                              <1> 	; 29/07/2016, 30/07/2016
  1441                              <1> 	; 25/07/2016, 26/07/2016, 27/07/2016
  1442                              <1> 	; 02/07/2016, 18/07/2016, 23/07/2016
  1443                              <1> 	; 24/06/2016, 26/06/2016
  1444                              <1> 	; 29/05/2016 - TRDOS 386 (TRDOS v2.0)
  1445                              <1> SET_MODE:
  1446                              <1> 	; For 32 bit TRDOS and Retro UNIX 386:
  1447                              <1> 	;	valid video mode: 03h only!
  1448                              <1> 	;	(VGA modes will be selected with another routine)
  1449                              <1> 	;
  1450                              <1> 	; set_txt_mode ; 80*25 (16 fore colors, 8 back colors)
  1451                              <1> 
  1452                              <1> 	; 27/11/2020
  1453                              <1> 	
  1454                              <1> 	; Check if current mode is 
  1455                              <1> 	; Bochs/Plex86 VBE graphics mode
  1456 00001AFD 803D[DE670000]FF    <1> 	cmp	byte [CRT_MODE], 0FFh ; VESA VBE graphics mode
  1457 00001B04 7220                <1> 	jb	short _set_mode_      ; signature  	
  1458                              <1> 				      ; VBE mode number is in	 
  1459                              <1> 				      ; [video_mode] bit 0to8
  1460 00001B06 88C3                <1> 	mov	bl, al ; save video mode
  1461 00001B08 E87C230000          <1> 	call	dispi_get_enable
  1462 00001B0D 50                  <1> 	push	eax ; save current VBE dispi status 
  1463                              <1> 	; Disable Bochs/Plex86 VBE dispi
  1464                              <1> 	;mov	ax, 0 ; VBE_DISPI_DISABLED 
  1465 00001B0E 31C0                <1> 	xor	eax, eax ; 0 
  1466 00001B10 E849230000          <1> 	call	dispi_set_enable
  1467 00001B15 88D8                <1> 	mov	al, bl ; restore video mode
  1468 00001B17 E827000000          <1> 	call	_set_mode
  1469 00001B1C 58                  <1> 	pop	eax ; restore current VBE dispi status 
  1470 00001B1D 7313                <1> 	jnc	short VIDEO_RETURN
  1471                              <1> 	; ! unimplemented or invalid video mode number !
  1472                              <1> 	; VBE dispi must be enabled again
  1473                              <1> 	; (return to run on current VBE graphics mode)
  1474                              <1> 	;;mov	al, [video_mode+1] ; bit 8 to 15
  1475                              <1> 	;;and	al, 0C0h ; isolate bit 14 and bit 15 
  1476                              <1> 	;;or	al, 1 ; VBE_DISPI_ENABLED
  1477 00001B1F E83A230000          <1> 	call	dispi_set_enable
  1478 00001B24 EB07                <1> 	jmp	short _video_func_err
  1479                              <1> 
  1480                              <1> _set_mode_:
  1481                              <1> 	; VGA bios (non-VBE) 'setmode' procedure
  1482                              <1> 
  1483                              <1> 	; 26/11/2020 (TRDOS v2.0.3)
  1484                              <1> 	
  1485                              <1> ;------------------------------------------------------
  1486                              <1> ; SET MODE					      :
  1487                              <1> ;	THIS ROUTINE INITIALIZES THE ATTACHMENT TO    :
  1488                              <1> ;	THE SELECTED MODE, THE SCREEN IS BLANKED.     :
  1489                              <1> ; INPUT						      :
  1490                              <1> ;	(AL) - MODE SELECTED (RANGE 0-7)	      :
  1491                              <1> ; OUTPUT					      :
  1492                              <1> ;	NONE					      :
  1493                              <1> ;------------------------------------------------------
  1494                              <1> 
  1495 00001B26 E818000000          <1> 	call	_set_mode ; 24/06/2016 (set_txt_mode)
  1496                              <1> 	; 26/11/2020
  1497 00001B2B 7305                <1> 	jnc	short VIDEO_RETURN
  1498                              <1> 
  1499                              <1> 	; 26/11/2020
  1500                              <1> _video_func_err:
  1501 00001B2D 31C0                <1> 	xor	eax, eax ; function call failed
  1502 00001B2F 48                  <1> 	dec	eax  ; 0FFFFFFFFh ; - 1	
  1503 00001B30 EB05                <1> 	jmp	short _video_return	
  1504                              <1> 
  1505                              <1> ; 12/05/2016
  1506                              <1> ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1507                              <1> 
  1508                              <1> ;-----	NORMAL RETURN FROM ALL VIDEO RETURNS
  1509                              <1> 
  1510                              <1> VIDEO_RETURN:
  1511 00001B32 A1[44890100]        <1> 	mov	eax, [video_eax] ; 12/05/2016
  1512                              <1> _video_return:
  1513 00001B37 FA                  <1> 	cli ; 02/01/2017
  1514 00001B38 5D                  <1> 	pop	ebp ; ******** ; 26/11/2020
  1515 00001B39 5F                  <1> 	pop	edi ; *******
  1516 00001B3A 5E                  <1> 	pop	esi ; ******
  1517 00001B3B 5B                  <1> 	pop	ebx ; *****
  1518                              <1> M15:	; VIDEO_RETURN_C
  1519                              <1> 	;;15/01/2017
  1520                              <1> 	; 02/01/2017
  1521                              <1> 	;;mov	byte [intflg], 0
  1522                              <1> 	;
  1523 00001B3C 59                  <1> 	pop	ecx ; **** ; 26/11/2020
  1524 00001B3D 5A                  <1> 	pop	edx ; ***
  1525 00001B3E 1F                  <1> 	pop	ds  ; **
  1526 00001B3F 07                  <1> 	pop	es  ; *	; RECOVER SEGMENTS
  1527 00001B40 CF                  <1> 	iretd		; ALL DONE
  1528                              <1> 
  1529                              <1> set_txt_mode:
  1530                              <1> 	
  1531                              <1> 	; 29/07/2016
  1532                              <1> 	; 27/06/2016
  1533 00001B41 B003                <1> 	mov	al, 3 ; 26/11/2020 (bit 7 = 0)
  1534                              <1> 
  1535                              <1> 	; 17/11/2020 (TRDOS v2.0.3)
  1536                              <1> 	;mov	byte [noclearmem], 0
  1537                              <1> 
  1538                              <1> ; 04/08/2022
  1539                              <1> ; 02/08/2022 (TRDOS 386 Kernel v2.0.5)
  1540                              <1> ; 12/04/2021
  1541                              <1> ; 10/08/2016
  1542                              <1> ; 08/08/2016
  1543                              <1> ; 30/07/2016
  1544                              <1> ; 29/07/2016
  1545                              <1> ; 25/07/2016 - 26/07/2016 - 27/07/2016
  1546                              <1> ; 07/07/2016 - 18/07/2016 - 23/07/2016
  1547                              <1> ; 02/07/2016 - 03/07/2016 - 04/07/2016
  1548                              <1> ; 26/06/2016
  1549                              <1> ; 24/06/2016 (set_txt_mode -> _set_mode)
  1550                              <1> ; 17/06/2016
  1551                              <1> ; 29/05/2016
  1552                              <1> ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  1553                              <1> 
  1554                              <1> _set_mode:
  1555                              <1> 	; 12/12/2020
  1556                              <1> 	; 26/11/2020
  1557                              <1> 	; call from 'biosfn_set_video_mode'
  1558                              <1> 	;	(bochs/plex86 video bios code)
  1559                              <1> 	; call from 'SET_MODE'
  1560                              <1> 	;	(TRDOS 386 v2 default, IBM PC/AT rom bios code)
  1561                              <1> 	; continue from 'set_txt_mode'	
  1562                              <1> 
  1563                              <1> 	; INPUT:
  1564                              <1> 	;	al = VGA video mode
  1565                              <1> 	; RETURN:
  1566                              <1> 	;	cf = 1 -> video mode not implemented
  1567                              <1> 	;	cf = 0 -> OK
  1568                              <1> 	;
  1569                              <1> 	; Modified registers: eax, bx, ecx, esi, edi, (ebp)
  1570                              <1> 
  1571                              <1> 	; 17/11/2020 (TRDOS v2.0.3)
  1572                              <1> 	; no clear memory option 
  1573                              <1> 	; (from mode number byte bit 7)
  1574 00001B43 88C4                <1> 	mov	ah, al
  1575 00001B45 80E480              <1> 	and	ah, 80h
  1576                              <1> 	;mov	[noclearmem], al
  1577 00001B48 8825[53890100]      <1> 	mov	[noclearmem], ah
  1578                              <1> 	;and	al, 7Fh ; clear bit 7
  1579                              <1> 	;;xor	[noclearmem], al ; clear bit 0 to 6
  1580                              <1> 	; 26/11/2020
  1581 00001B4E 30E0                <1> 	xor	al, ah ; and al, 7Fh
  1582                              <1> 
  1583                              <1> 	; 19/11/2020
  1584                              <1> 
  1585                              <1> 	; Video mode 03h action principle:
  1586                              <1> 	;
  1587                              <1> 	; for case 1:
  1588                              <1> 	; Current mode is 03h and next/requested mode is not 03h
  1589                              <1> 	;	- save mode (set mode 03h flag)
  1590                              <1> 	;	- save 8 video pages (which are will be restored)	
  1591                              <1> 	;	- save active page number (which will be reactivated)
  1592                              <1> 	;	- set active page to 0 always (no multi screen)
  1593                              <1> 	;	- save 8 cursor positions (which will be restored)
  1594                              <1> 	; 	- use 'noclearmem' option
  1595                              <1> 	;	[p_crt_mode] = 0 -> 03h 
  1596                              <1> 	;
  1597                              <1> 	; for case 2:
  1598                              <1> 	; Current mode is 03h and next/requested mode is also 03h
  1599                              <1> 	;	- clear active video page if 'noclearmem' is not set
  1600                              <1> 	;	[p_crt_mode] = 0 -> 80h -> 0
  1601                              <1> 	;
  1602                              <1> 	; for case 3:
  1603                              <1> 	; Current mode is not 03h and next/requested mode is 03h
  1604                              <1> 	;	- restore video pages (8 video pages were saved)	
  1605                              <1> 	;	- restore active page number (which were saved)
  1606                              <1> 	;	- restore 8 cursor positions (which were saved)
  1607                              <1> 	;	- reset/clear mode 03h flag
  1608                              <1> 	;	[p_crt_mode] = 03h -> 0
  1609                              <1> 	;
  1610                              <1> 	; for case 4:
  1611                              <1> 	; Current mode is not 03h and next/requested mode is not 03h
  1612                              <1> 	; 	- use 'noclearmem' option
  1613                              <1> 	;	- set active page to 0 always
  1614                              <1> 	;	[p_crt_mode] = 03h -> 83h -> 03h
  1615                              <1> 	;
  1616                              <1> 	; initial (boot time) values:
  1617                              <1> 	;	[p_crt_mode] = 0 ("there isn't a page backup, yet")
  1618                              <1> 	;	  [CRT_MODE] = 3 (kernel's starting mode)
  1619                              <1> 
  1620                              <1> 	; 26/11/2020
  1621 00001B50 3C03                <1> 	cmp	al, 03h	    ; mode 3, 80x25 text, 16 colors
  1622 00001B52 7515                <1> 	jne	short _sm_0 ; (default mode for TRDOS 386 mainprog)
  1623                              <1> 
  1624                              <1> 	; case 2 or case 3
  1625                              <1> 
  1626                              <1> 	; check current video mode if it is 03h
  1627 00001B54 08E4                <1> 	or	ah, ah ; 80h or 0 ('noclearmem' option)
  1628 00001B56 7521                <1> 	jnz	short _sm_1 ; do not clear display page
  1629                              <1>  	
  1630                              <1> 	; 26/11/2020
  1631                              <1> 	; Note:
  1632                              <1> 	; [CRT_MODE] = 0FFh for VESA VBE video modes
  1633                              <1> 	; [video_mode] = standard VGA and VESA VBE video modes
  1634                              <1> 	
  1635 00001B58 3805[DE670000]      <1> 	cmp	[CRT_MODE], al	; 03h
  1636 00001B5E 7520                <1> 	jne	short _sm_2	; case 3 ([p_crt_mode] = 03h)
  1637                              <1> 
  1638                              <1> 	; case 2
  1639                              <1> 
  1640                              <1> 	; [p_crt_mode] = 0
  1641                              <1> 
  1642                              <1> 	; 19/11/2020
  1643                              <1> 	; If '_set_mode' procedure is called for video mode 3
  1644                              <1> 	;     while video mode is 3, video page will be cleared
  1645                              <1> 	;     and cursor position of video page will be reset.	 
  1646                              <1> 
  1647                              <1> 	; clear display page
  1648 00001B60 C605[51890100]80    <1> 	mov	byte [p_crt_mode], 80h ; clear page sign
  1649 00001B67 EB1C                <1> 	jmp	short _sm_3	; bypass save video page routine
  1650                              <1> _sm_0:
  1651                              <1> 	; case 1 or case 4
  1652                              <1> 
  1653                              <1> 	; 05/12/2020
  1654 00001B69 803D[DE670000]03    <1> 	cmp	byte [CRT_MODE], 3 ; is current mode 03h?
  1655 00001B70 7507                <1> 	jne	short _sm_1	; case 4 ; [p_crt_mode] = 03h
  1656                              <1> 	
  1657                              <1> 	; case 1
  1658                              <1> 	; [p_crt_mode] = 0
  1659                              <1> 
  1660                              <1> 	; 19/11/2020
  1661                              <1> 	; If '_set_mode' procedure is called for a video mode
  1662                              <1> 	;     except video mode 3 while current video mode
  1663                              <1> 	;     is 3, all video pages of mode 3 will be copied 
  1664                              <1> 	;     to 98000h address as backup, before mode change.
  1665                              <1> 	
  1666                              <1> _sm_save_pm:
  1667                              <1> 	; 12/12/2020
  1668                              <1> 	;; 03/07/2016
  1669                              <1> 	;; save video pages
  1670                              <1> 	;mov	esi, 0B8000h
  1671                              <1> 	;mov	edi, 98000h ; 30/07/2016
  1672                              <1> 	;mov	ecx, (0B8000h-0B0000h)/4
  1673                              <1> 	;rep	movsd
  1674                              <1> 
  1675                              <1> 	;mov	byte [p_crt_mode], 3 ; previous mode, backup sign
  1676                              <1> 	;; 26/11/2020
  1677                              <1> 	;xchg	cl, [ACTIVE_PAGE]
  1678                              <1> 	;mov	[p_crt_page], cl  ; save as previous active page
  1679                              <1> 	;
  1680                              <1> 	;; save cursor positions
  1681                              <1> 	;mov	esi, CURSOR_POSN
  1682                              <1> 	;mov	edi, cursor_pposn ; cursor positions backup
  1683                              <1> 	;mov	cl, 4
  1684                              <1> 	;rep	movsd
  1685                              <1> 
  1686                              <1> 	; 12/12/2020
  1687 00001B72 E86E020000          <1> 	call	save_mode3_multiscreen
  1688                              <1> 
  1689                              <1> 	; 29/07/2016
  1690                              <1> 	;;mov	[ACTIVE_PAGE], cl ; 0
  1691                              <1> 	;xchg	cl, [ACTIVE_PAGE]
  1692                              <1> 	;mov	[p_crt_page], cl  ; previous page (for mode 3)
  1693                              <1> 	
  1694                              <1> 	; [ACTIVE_PAGE] = 0 
  1695                              <1> 	
  1696 00001B77 EB07                <1> 	jmp	short _sm_2	; case 1 - 19/11/2020
  1697                              <1> _sm_1:
  1698                              <1> 	; 26/11/2020
  1699                              <1> 	; 19/11/2020
  1700                              <1> 	
  1701                              <1> 	; case 4
  1702 00001B79 800D[51890100]80    <1> 	or	byte [p_crt_mode], 80h 
  1703                              <1> 				; here [p_crt_mode] must be 83h
  1704                              <1> 				;	  (for case 4)
  1705                              <1> 				; (because video mode 03h
  1706                              <1> 				; was changed before as in case 1)
  1707                              <1> 
  1708                              <1> _sm_2:	; case 4 (jump to _sm_2) - 19/11/2020 
  1709                              <1> 
  1710                              <1> 	; 19/11/2020
  1711                              <1> 	; case 3
  1712                              <1> 	; If '_set_mode' procedure is called for video mode 3
  1713                              <1> 	;     while video mode is not 3 and if there is video
  1714                              <1> 	;     page backup for video mode 3, all (of 8) mode 3
  1715                              <1> 	;     video pages will be restored from 98000h.
  1716                              <1> 
  1717 00001B80 A2[DE670000]        <1> 	mov	[CRT_MODE], al  ; save mode in global variable
  1718                              <1> _sm_3:
  1719                              <1> 	; 04/08/2022 (TRDOS 386 v2.0.5)
  1720                              <1> 	; 30/07/2016
  1721                              <1> 	; 26/07/2016
  1722                              <1> 	; 25/07/2016
  1723                              <1> 	; set_mode_vga:
  1724                              <1> 	; 18/07/2016
  1725                              <1> 	; 14/07/2016
  1726                              <1> 	; 09/07/2016
  1727                              <1> 	; 04/07/2016
  1728                              <1> 	; 03/07/2016 (TRDOS 386 = TRDOS v2.0)
  1729                              <1> 	; /// video mode 13h ///
  1730                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  1731                              <1> 	; vgabios-0.7a (2011)
  1732                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  1733                              <1> 	; 'vgabios.c', 'vgatables.h'
  1734                              <1> 	;
  1735                              <1> 	; Oracle VirtualBox 5.0.24 VGABios Source Code
  1736                              <1> 	; ('vgabios.c', 'vgatables.h', 'vgafonts.h', 'vgarom.asm')
  1737                              <1> 	;
  1738 00001B85 88C4                <1> 	mov	ah, al
  1739 00001B87 B910000000          <1> 	mov	ecx, vga_mode_count
  1740 00001B8C BE[FA670000]        <1> 	mov	esi, vga_modes
  1741 00001B91 31DB                <1> 	xor	ebx, ebx
  1742                              <1> _sm_4:
  1743 00001B93 AC                  <1> 	lodsb
  1744 00001B94 38C4                <1> 	cmp	ah, al
  1745 00001B96 7406                <1> 	je	short _sm_5
  1746 00001B98 FEC3                <1> 	inc	bl
  1747 00001B9A E2F7                <1> 	loop	_sm_4
  1748                              <1> 
  1749                              <1> 	; UNIMPLEMENTED VIDEO MODE !
  1750                              <1> 	;xor	eax, eax
  1751                              <1>         ;mov	[video_eax], eax ; 0
  1752                              <1> 
  1753                              <1> 	; 26/11/2020
  1754 00001B9C F9                  <1> 	stc	; unimplemented video mode ! (cf=1)
  1755                              <1> 
  1756 00001B9D C3                  <1> 	retn
  1757                              <1> 
  1758                              <1> ;-----	EBX POINTS TO CORRECT ROW OF INITIALIZATION TABLE
  1759                              <1> 
  1760                              <1> _sm_5: 	; 25/07/2016
  1761                              <1> 	;mov	esi, ebx
  1762                              <1> 	;add	esi, vga_memmodel
  1763                              <1> 	;mov	al, [esi]
  1764                              <1> 	; 19/11/2020
  1765 00001B9E 8A83[4A680000]      <1> 	mov	al, [ebx+vga_memmodel]
  1766 00001BA4 A2[6A890100]        <1> 	mov	[VGA_MTYPE], al
  1767                              <1> 
  1768 00001BA9 89DF                <1> 	mov	edi, ebx
  1769 00001BAB 81C7[5A680000]      <1> 	add	edi, vga_dac_s 	
  1770 00001BB1 C0E302              <1> 	shl	bl, 2 ; byte -> dword
  1771 00001BB4 81C3[0A680000]      <1> 	add	ebx, vga_mode_tbl_ptr
  1772                              <1> 
  1773                              <1> 	;mov	dword [VGA_BASE], 0B8000h
  1774                              <1> 	;cmp	ah, 0Dh ; [CRT_MODE]
  1775                              <1> 	;jb	short M9 
  1776                              <1> 	;mov	dword [VGA_BASE], 0A0000h
  1777                              <1> ;M9:
  1778 00001BBA 8B33                <1> 	mov	esi, [ebx]
  1779 00001BBC 89F3                <1> 	mov	ebx, esi
  1780 00001BBE 83C614              <1> 	add	esi, vga_p_cm_pos ; ebx + 20
  1781 00001BC1 668B06              <1> 	mov	ax, [esi]       ; get the cursor mode from the table
  1782 00001BC4 66A3[F7670000]      <1> 	mov	[CURSOR_MODE], ax ; save cursor mode (initial value)
  1783                              <1> 	; al = 6, ah = 7
  1784                              <1> 	; al = 0Dh, ah = 0Eh ; 25/07/2016
  1785 00001BCA E893020000          <1> 	call	cursor_shape_fix
  1786                              <1> 	; al = 14, ah = 15 (If [CHAR_HEIGHT] = 16)
  1787 00001BCF 668906              <1> 	mov	[esi], ax
  1788                              <1> 
  1789 00001BD2 56                  <1> 	push	esi ; *	
  1790                              <1> 
  1791                              <1> 	; 17/04/2021
  1792 00001BD3 B603                <1> 	mov	dh, 03h
  1793                              <1> 	;
  1794 00001BD5 8A25[E5670000]      <1> 	mov	ah, [VGA_MODESET_CTL]
  1795 00001BDB 80E408              <1> 	and	ah, 8 ; default palette loading ?
  1796 00001BDE 7520                <1> 	jnz	short _sm_6
  1797                              <1> 	;mov	dx, 3C6h ; VGAREG_PEL_MASK (DAC mask register)
  1798                              <1> 	; 17/04/2021
  1799 00001BE0 B2C6                <1> 	mov	dl, 0C6h
  1800 00001BE2 B0FF                <1> 	mov	al, 0FFh ; PEL mask
  1801 00001BE4 EE                  <1> 	out	dx, al
  1802 00001BE5 8A27                <1> 	mov	ah, [edi] ; DAC model (selection number)
  1803 00001BE7 E8F80F0000          <1> 	call	load_dac_palette
  1804                              <1> 	; ecx = 0
  1805 00001BEC F605[E5670000]02    <1> 	test	byte [VGA_MODESET_CTL], 2 ; gray scale summing
  1806 00001BF3 740B                <1> 	jz	short _sm_6
  1807 00001BF5 53                  <1> 	push	ebx
  1808 00001BF6 29DB                <1> 	sub	ebx, ebx ; sub bl, bl
  1809                              <1> 	;mov	cx, 256
  1810                              <1> 	; 02/08/2022
  1811                              <1> 	;sub	ecx, ecx
  1812                              <1> 	; ecx = 0
  1813 00001BF8 FEC5                <1> 	inc	ch
  1814                              <1> 	; ecx = 256
  1815 00001BFA E837100000          <1> 	call	gray_scale_summing
  1816 00001BFF 5B                  <1> 	pop	ebx	
  1817                              <1> _sm_6:
  1818                              <1> 	; Reset Attribute Ctl flip-flop
  1819                              <1> 	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
  1820                              <1>  	; 17/03/2021
  1821 00001C00 B2DA                <1> 	mov	dl, 0DAh ; dx = 3DAh
  1822 00001C02 EC                  <1> 	in	al, dx
  1823                              <1> 	; Set Attribute Ctl
  1824 00001C03 89DE                <1> 	mov	esi, ebx ; addr of params tbl for selected mode
  1825 00001C05 83C623              <1> 	add	esi, 35  ; actl regs
  1826 00001C08 30E4                <1> 	xor	ah, ah ; 0
  1827                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  1828                              <1> 	; 17/04/2021
  1829 00001C0A B2C0                <1> 	mov	dl, 0C0h
  1830                              <1> _sm_7:
  1831 00001C0C 88E0                <1> 	mov	al, ah
  1832 00001C0E EE                  <1> 	out	dx, al ; index
  1833 00001C0F AC                  <1> 	lodsb
  1834                              <1> 	; DX = 3C0h = VGAREG_ACTL_WRITE_DATA
  1835 00001C10 EE                  <1> 	out	dx, al ; value
  1836 00001C11 FEC4                <1> 	inc	ah
  1837 00001C13 80FC14              <1> 	cmp	ah, 20 ; number of actl registers
  1838 00001C16 72F4                <1> 	jb	short _sm_7
  1839                              <1> 	;
  1840 00001C18 88E0                <1> 	mov	al, ah ; 20
  1841 00001C1A EE                  <1> 	out	dx, al ; index
  1842 00001C1B 28C0                <1> 	sub	al, al ; 0
  1843 00001C1D EE                  <1> 	out	dx, al ; value
  1844                              <1> 	;
  1845                              <1> 	; Set Sequencer Ctl
  1846 00001C1E 89DE                <1> 	mov	esi, ebx ; addr of params tbl for selected mode
  1847 00001C20 83C605              <1> 	add	esi, 5 ; sequ regs
  1848                              <1> 	;
  1849                              <1> 	;mov	dx, 3C4h  ; VGAREG_SEQU_ADDRESS
  1850                              <1> 	; 17/04/2021
  1851 00001C23 B2C4                <1> 	mov	dl, 0C4h
  1852 00001C25 EE                  <1> 	out	dx, al ; 0
  1853                              <1> 	;inc	dx ; 3C5h ; VGAREG_SEQU_DATA
  1854                              <1> 	; 17/04/2021
  1855 00001C26 FEC2                <1> 	inc	dl ; dx = 3C5h	
  1856 00001C28 B003                <1> 	mov	al, 3
  1857 00001C2A EE                  <1> 	out	dx, al
  1858 00001C2B B401                <1> 	mov	ah, 1	
  1859                              <1> _sm_8:
  1860 00001C2D 88E0                <1> 	mov	al, ah
  1861                              <1> 	;mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  1862                              <1> 	;dec	dx
  1863                              <1> 	; 17/04/2021
  1864 00001C2F FECA                <1> 	dec	dl ; dx = 3C4h
  1865 00001C31 EE                  <1> 	out	dx, al ; index
  1866 00001C32 AC                  <1> 	lodsb
  1867                              <1> 	;inc	dx ; 3C5h ; VGAREG_SEQU_DATA
  1868                              <1> 	; 17/04/2021
  1869 00001C33 FEC2                <1> 	inc	dl
  1870 00001C35 EE                  <1> 	out	dx, al
  1871 00001C36 80FC04              <1> 	cmp	ah, 4 ; number of sequ regs
  1872 00001C39 7304                <1> 	jnb	short _sm_9		
  1873 00001C3B FEC4                <1> 	inc	ah 
  1874 00001C3D EBEE                <1> 	jmp	short _sm_8
  1875                              <1> _sm_9:
  1876                              <1> 	; Set Grafx Ctl
  1877 00001C3F 89DE                <1> 	mov	esi, ebx ; addr of params tbl for selected mode
  1878 00001C41 83C637              <1> 	add	esi, 55 ; grdc regs
  1879 00001C44 30E4                <1> 	xor	ah, ah ; 0
  1880                              <1> _sm_10:
  1881 00001C46 88E0                <1> 	mov	al, ah
  1882                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  1883                              <1> 	; 17/04/2021
  1884 00001C48 B2CE                <1> 	mov	dl, 0CEh
  1885 00001C4A EE                  <1> 	out	dx, al	
  1886 00001C4B AC                  <1> 	lodsb
  1887                              <1> 	;inc	dx ; 3CFh ; VGAREG_GRDC_DATA
  1888                              <1> 	; 17/04/2021
  1889 00001C4C FEC2                <1> 	inc	dl ; 3CFh
  1890 00001C4E EE                  <1> 	out	dx, al
  1891 00001C4F FEC4                <1> 	inc	ah
  1892 00001C51 80FC09              <1> 	cmp	ah, 9 ; number of grdc regs
  1893 00001C54 72F0                <1> 	jb	short _sm_10
  1894                              <1> 	;
  1895                              <1> 	; Disable CRTC write protection
  1896                              <1> 	;mov	dx, 3D4h  ; VGAREG_VGA_CRTC_ADDRESS
  1897                              <1> 	; 17/04/2021
  1898 00001C56 B2D4                <1> 	mov	dl, 0D4h
  1899                              <1> 	;mov	al, 11h
  1900                              <1> 	;out	dx, al
  1901                              <1> 	;inc	dx
  1902                              <1> 	;sub	al, al
  1903                              <1> 	;out	dx, al
  1904 00001C58 66B81100            <1> 	mov	ax, 11h
  1905 00001C5C 66EF                <1> 	out	dx, ax
  1906 00001C5E 89DE                <1> 	mov	esi, ebx ; addr of params tbl for selected mode
  1907 00001C60 83C60A              <1> 	add	esi, 10 ; crtc regs
  1908                              <1> 	; ah = 0
  1909                              <1> _sm_11:
  1910 00001C63 88E0                <1> 	mov	al, ah
  1911                              <1> 	; dx = 3D4h = VGAREG_VGA_CRTC_ADDRESS
  1912 00001C65 EE                  <1> 	out	dx, al ; index
  1913 00001C66 AC                  <1> 	lodsb
  1914                              <1> 	;inc	dx  ; VGAREG_VGA_CRTC_ADDRESS + 1
  1915                              <1> 	; 17/04/2021
  1916 00001C67 FEC2                <1> 	inc	dl
  1917 00001C69 EE                  <1> 	out	dx, al ; value
  1918 00001C6A 80FC18              <1> 	cmp	ah, 24 ; number of crtc registers - 1
  1919 00001C6D 7306                <1> 	jnb	short _sm_12
  1920 00001C6F FEC4                <1> 	inc	ah
  1921                              <1> 	;dec	dx ; 3D4h
  1922                              <1> 	; 17/04/2021
  1923 00001C71 FECA                <1> 	dec	dl
  1924 00001C73 EBEE                <1> 	jmp	short _sm_11
  1925                              <1> _sm_12:
  1926                              <1> 	; Set the misc register
  1927                              <1> 	;mov	dx, 3CCh ; VGAREG_READ_MISC_OUTPUT
  1928                              <1> 	; 17/04/2021
  1929 00001C75 B2CC                <1> 	mov	dl, 0CCh
  1930 00001C77 8A4309              <1> 	mov	al, [ebx+9] ; misc reg
  1931 00001C7A EE                  <1> 	out	dx, al
  1932                              <1> 	;
  1933                              <1> 	; Enable video
  1934                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  1935                              <1> 	; 17/04/2021
  1936 00001C7B B2C0                <1> 	mov	dl, 0C0h
  1937 00001C7D B020                <1> 	mov	al, 20h  
  1938 00001C7F EE                  <1>         out     dx, al   ; set bit 5 to 1
  1939                              <1> 	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
  1940                              <1> 	; 17/04/2021
  1941 00001C80 B2DA                <1> 	mov	dl, 0DAh
  1942 00001C82 EC                  <1> 	in	al, dx
  1943                              <1> 	;
  1944                              <1> 	; 17/11/2020
  1945                              <1> 	;cmp	byte [noclearmem], 0
  1946                              <1>         ;ja	short _sm_15
  1947                              <1> 
  1948 00001C83 F605[53890100]80    <1> 	test	byte [noclearmem], 80h
  1949 00001C8A 753B                <1> 	jnz	short _sm_15	
  1950                              <1> 
  1951                              <1> 	; 29/07/2016
  1952 00001C8C 31C0                <1> 	xor	eax, eax
  1953                              <1> 	;mov	ecx, 4000h ; 16K words (32K)
  1954                              <1> 	; 02/08/2022
  1955 00001C8E 29C9                <1> 	sub	ecx, ecx
  1956 00001C90 B540                <1> 	mov	ch, 40h
  1957                              <1> 	; ecx = 4000h 
  1958 00001C92 803D[6A890100]02    <1> 	cmp     byte [VGA_MTYPE], 2  ; CTEXT, MTEXT, CGA
  1959 00001C99 7715                <1> 	ja	short _sm_14    ; no ? (0A0000h)
  1960 00001C9B BF00800B00          <1> 	mov	edi, 0B8000h
  1961 00001CA0 7409                <1> 	je	short _sm_13	; CGA graphics mode
  1962                              <1> 	; 08/08/2016
  1963 00001CA2 A3[66890100]        <1> 	mov	[VGA_INT43H], eax ; 0 ; default font 
  1964 00001CA7 66B82007            <1> 	mov	ax, 0720h	; CGA text mode
  1965                              <1> _sm_13:
  1966 00001CAB F366AB              <1> 	rep	stosw
  1967 00001CAE EB17                <1> 	jmp	short _sm_15
  1968                              <1> 
  1969                              <1> _sm_14:
  1970 00001CB0 BF00000A00          <1> 	mov	edi, 0A0000h
  1971                              <1> 	; ecx = 16384 dwords (64K)
  1972                              <1> 	;mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  1973                              <1> 	; 17/04/2021
  1974 00001CB5 B2C4                <1> 	mov	dl, 0C4h
  1975 00001CB7 B002                <1> 	mov	al, 2
  1976 00001CB9 EE                  <1> 	out	dx, al
  1977                              <1> 	;mov	dx, 3C5h ; VGAREG_SEQU_DATA
  1978                              <1> 	;inc	dx
  1979                              <1> 	; 17/04/2021
  1980 00001CBA FEC2                <1> 	inc	dl ; 3C5h
  1981 00001CBC EC                  <1> 	in	al, dx ; mmask
  1982                              <1> 	;push	ax
  1983                              <1> 	; 12/04/2021
  1984 00001CBD 50                  <1> 	push	eax
  1985 00001CBE B00F                <1> 	mov	al, 0Fh ; all planes
  1986 00001CC0 EE                  <1> 	out	dx, al
  1987 00001CC1 30C0                <1> 	xor	al, al ; 0
  1988 00001CC3 F3AB                <1> 	rep	stosd	; ecx = 163684 (64K)
  1989                              <1> 	;pop	ax
  1990                              <1> 	; 12/04/2021
  1991 00001CC5 58                  <1> 	pop	eax
  1992 00001CC6 EE                  <1> 	out	dx, al  ; mmask
  1993                              <1> _sm_15:
  1994                              <1> 	; ebx = addr of params tbl for selected mode
  1995                              <1> 	; 10/08/2016
  1996 00001CC7 668B03              <1> 	mov	ax, [ebx] ; num of columns, 'twidth'
  1997 00001CCA A2[E0670000]        <1> 	mov	[CRT_COLS], al
  1998                              <1> 	;; 26/07/2016
  1999                              <1> 	;; CRTC_ADDRESS = 3D4h (always)
  2000                              <1> 	;mov	ah, [ebx+1] ; num of rows, 'theightm1'
  2001 00001CCF FEC4                <1> 	inc	ah ; 09/07/2016
  2002 00001CD1 8825[E6670000]      <1> 	mov	[VGA_ROWS], ah
  2003                              <1> 	; 10/08/2016
  2004 00001CD7 8A4302              <1> 	mov	al, [ebx+2]
  2005 00001CDA A2[E2670000]        <1> 	mov	[CHAR_HEIGHT], al 
  2006                              <1> 	; 29/07/2016
  2007                              <1> 	; length of regen buffer in bytes
  2008 00001CDF 668B4B03            <1> 	mov	cx, [ebx+3] ; 'slength_l'
  2009 00001CE3 66890D[54890100]    <1> 	mov	[CRT_LEN], cx
  2010                              <1> 	;
  2011                              <1> 	; 27/07/2016
  2012 00001CEA 30E4                <1> 	xor	ah, ah
  2013 00001CEC A0[EE7C0100]        <1> 	mov	al, [ACTIVE_PAGE] ; may be > 0 for mode 3
  2014                              <1> 	;mul	word [CRT_LEN] ; 4096 for mode 3
  2015 00001CF1 66F7E1              <1> 	mul	cx ; 29/07/2016
  2016 00001CF4 66A3[DC7C0100]      <1> 	mov	[CRT_START], ax
  2017                              <1> 	;
  2018 00001CFA B060                <1> 	mov	al, 60h
  2019                              <1> 	;cmp	byte [noclearmem], 0
  2020                              <1> 	;jna	short _sm_16
  2021                              <1> 	;add	al, 80h
  2022 00001CFC 0A05[53890100]      <1> 	or	al, [noclearmem] ; 17/11/2020
  2023                              <1> _sm_16:
  2024 00001D02 A2[E3670000]        <1> 	mov	[VGA_VIDEO_CTL], al
  2025 00001D07 C605[E4670000]F9    <1> 	mov	byte [VGA_SWITCHES], 0F9h
  2026 00001D0E 8025[E5670000]7F    <1> 	and	byte [VGA_MODESET_CTL], 7Fh
  2027                              <1> 
  2028 00001D15 5E                  <1> 	pop	esi ; *
  2029                              <1> 
  2030                              <1> 	; 26/07/2016
  2031                              <1> 	; 07/07/2016
  2032 00001D16 668B0D[F7670000]    <1> 	mov	cx, [CURSOR_MODE] ; restore cursor mode (initial value)
  2033 00001D1D 66870E              <1> 	xchg	cx, [esi] ; cl = start line, ch = end line
  2034                              <1> 			  ; reset to initial value
  2035 00001D20 86CD                <1> 	xchg 	ch, cl  ; ch = start line, cl = end line  
  2036 00001D22 66890D[F7670000]    <1> 	mov	[CURSOR_MODE], cx ; save (fixed) cursor mode
  2037                              <1> 
  2038                              <1> 	; 27/07/2016
  2039 00001D29 803D[6A890100]02    <1> 	cmp	byte [VGA_MTYPE], 2 ; CTEXT, MTEXT
  2040 00001D30 7317                <1> 	jnb	short _sm_17
  2041                              <1> 
  2042                              <1> 	; Set cursor shape
  2043                              <1> 	;mov	cx, 0607h
  2044                              <1> 	;call	_set_ctype
  2045                              <1> 
  2046                              <1> 	; 29/07/2016
  2047 00001D32 B40A                <1> 	mov	ah, 10	; 6845 register for cursor set
  2048 00001D34 E81F060000          <1> 	call	m16	; output cx register
  2049                              <1> 	
  2050                              <1> 	; 25/07/2016
  2051 00001D39 803D[DE670000]03    <1>         cmp     byte [CRT_MODE], 03h
  2052 00001D40 7507                <1> 	jne	short _sm_17
  2053                              <1> 	; 26/07/2016
  2054                              <1> 
  2055 00001D42 A0[EE7C0100]        <1> 	mov	al, [ACTIVE_PAGE]
  2056 00001D47 EB0B                <1> 	jmp	short _sm_18
  2057                              <1> _sm_17:
  2058                              <1> 	; Set cursor pos for page 0..7
  2059                              <1> 	;sub	ax, ax ; eax = 0
  2060 00001D49 29C0                <1> 	sub	eax, eax ; 17/11/2020
  2061 00001D4B BF[DE7C0100]        <1> 	mov	edi, CURSOR_POSN
  2062 00001D50 AB                  <1> 	stosd	
  2063 00001D51 AB                  <1> 	stosd
  2064 00001D52 AB                  <1> 	stosd
  2065 00001D53 AB                  <1> 	stosd
  2066                              <1> 	;; Set active page 0
  2067                              <1> 	;mov	[ACTIVE_PAGE], al ; 0
  2068                              <1> _sm_18:
  2069                              <1> 	; 29/07/2016
  2070 00001D54 803D[6A890100]02    <1> 	cmp	byte [VGA_MTYPE], 2 ; CTEXT, MTEXT
  2071                              <1> 	;jnb	_sm_23
  2072                              <1> 	; 04/08/2022
  2073 00001D5B 7205                <1> 	jb	short _sm_24
  2074 00001D5D E90C020000          <1> 	jmp	_set_active_page
  2075                              <1> _sm_24:
  2076                              <1> 	;cmp	byte [CHAR_HEIGHT], 16
  2077                              <1> 	;je	short _sm_19
  2078                              <1> 
  2079                              <1>  	;; copy and activate 8x16 font
  2080                              <1> 	
  2081                              <1> 	; 26/07/2016
  2082 00001D62 B004                <1> 	mov	al, 04h
  2083                              <1> 	;sub	bl, bl
  2084                              <1> 	; AX = 1104H ; Load ROM 8x16 Character Set
  2085                              <1> 	; (BL = font block to load (EGA: 0-3; VGA: 0-7))
  2086 00001D64 E844160000          <1> 	call	load_text_8_16_pat
  2087                              <1> 
  2088                              <1> 	; video_func_1103h:
  2089                              <1> 	; biosfn_set_text_block_specifier:
  2090                              <1> 	; BL = font block selector code	
  2091                              <1> 	; NOTE: TRDOS 386 only uses and sets font block 0
  2092                              <1> 	; (It is as BL = 0 for TRDOS 386)
  2093 00001D69 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  2094                              <1> 	;;mov	ah, bl
  2095                              <1> 	;sub	ah, ah ; 0
  2096                              <1> 	;mov	al, 03h
  2097                              <1> 	; 19/11/2020
  2098 00001D6D 66B80300            <1> 	mov	ax, 03h
  2099 00001D71 66EF                <1> 	out	dx, ax
  2100                              <1> _sm_19:
  2101                              <1> 	; 29/07/2016
  2102                              <1> 	; 26/07/2016
  2103                              <1> 	; 24/06/2016
  2104                              <1> 	;mov	edi, 0B8000h
  2105                              <1> 	;mov	cx, 4000h ; 16K words (32K)
  2106                              <1> 	;
  2107 00001D73 30C0                <1> 	xor	al, al
  2108 00001D75 3805[51890100]      <1>         cmp     [p_crt_mode], al ; 0 
  2109 00001D7B 7705                <1>         ja      short _sm_20 ; 03h, 80h or 83h
  2110                              <1> 
  2111                              <1> 	; case 1 - 19/11/2020
  2112                              <1> 	;
  2113                              <1> 	; If [pc_crt_mode] = 0, that means, previous mode is 03h
  2114                              <1> 	; and current mode is not 03h (case 1)
  2115                              <1> 
  2116                              <1> 	; 30/07/2016
  2117                              <1> 	; 24/06/2016
  2118                              <1> 	; TRDOS 386 (TRDOS v2) 'set mode' modification
  2119                              <1> 	; (for multiscreen feature):
  2120                              <1> 	; If '_set_mode' procedure is called for video mode 3
  2121                              <1> 	;     while video mode is 3, video page will be cleared
  2122                              <1> 	;     and cursor position of video page will be reset.
  2123                              <1> 	; If '_set_mode' procedure is called for a video mode
  2124                              <1> 	;     except video mode 3, while current video mode
  2125                              <1> 	;     is 3, all video pages of mode 3 will be copied 
  2126                              <1> 	;     to 98000h address as backup, before mode change.
  2127                              <1> 	; If '_set_mode' procedure is called for video mode 3
  2128                              <1> 	;     while video mode is not 3 and if there is video
  2129                              <1> 	;     page backup for video mode 3, all (of 8) mode 3
  2130                              <1> 	;     video pages will be restored from 98000h.
  2131                              <1> 
  2132                              <1> 	; 19/11/2020
  2133                              <1> 	;mov	[ACTIVE_PAGE], al ; 0
  2134                              <1> 
  2135                              <1> 	; Here,
  2136                              <1> 	; video memory already cleared if [noclearmem] <> 80h
  2137                              <1> 	
  2138                              <1> 	;mov	ax, 0720h
  2139                              <1> 	;mov	cx, 4000h ; 16K words (32K)
  2140                              <1> 	;mov	edi, 0B8000h
  2141                              <1> 	;rep	stosw
  2142                              <1> 	;sub	al, al
  2143                              <1> 	
  2144                              <1> 	;jmp	short _sm_23
  2145                              <1> 
  2146                              <1> 	; Set hardware side for the new active video page
  2147                              <1>  
  2148 00001D7D E9EC010000          <1> 	jmp	_set_active_page ; 19/11/2020	
  2149                              <1> 
  2150                              <1> _sm_20:
  2151                              <1> 	; 19/11/2020
  2152                              <1> 	; case 2 or case 3 or case 4 - 19/11/2020
  2153                              <1> 	
  2154                              <1> 	; 19/11/2020
  2155 00001D82 803D[DE670000]03    <1> 	cmp	byte [CRT_MODE], 3  ; new video mode
  2156 00001D89 754E                <1> 	jne	short _sm_22 ; al = 0 (& video mode <> 03h)
  2157                              <1> 			     ; case 4 - 19/11/2020
  2158                              <1> 			     ; ([p_crt_mode] = 83h)
  2159                              <1> 
  2160                              <1> 	; case 2 or case 3 - 19/11/2020	
  2161                              <1> 
  2162                              <1> 	;movzx	ebx, byte [ACTIVE_PAGE]
  2163                              <1> 	; 19/11/2020
  2164 00001D8B A0[52890100]        <1> 	mov	al, [p_crt_page] ; previous mode 3 active page
  2165                              <1> 	;movzx	ebx, al
  2166                              <1> 	;shl	bl, 1 ; * 2
  2167                              <1> 	;add	ebx, CURSOR_POSN
  2168                              <1> 
  2169                              <1> 	; 29/07/2016
  2170 00001D90 F605[51890100]7F    <1> 	test    byte [p_crt_mode], 7Fh ; 83h or 80h or 03h
  2171 00001D97 740F                <1> 	jz	short _sm_21	; do not restore video pages
  2172                              <1> 				; case 2 - 19/11/2020 
  2173                              <1> 	; case 3 - 19/11/2020
  2174                              <1> 
  2175                              <1> 	; ([p_crt_mode] = 03h)
  2176                              <1> 
  2177                              <1> 	; New video mode is 3 while current video mode is not 3
  2178                              <1> 	; (multi screen) video pages will be restored from 098000h
  2179                              <1> 
  2180                              <1> 	; 19/11/2020
  2181 00001D99 A2[EE7C0100]        <1> 	mov	[ACTIVE_PAGE], al ; current mode 3 active page
  2182                              <1> 
  2183                              <1> 	; 12/12/2020
  2184                              <1> 	;; restore video pages
  2185                              <1> 	;mov	esi, 98000h ; 30/07/2016 
  2186                              <1> 	;mov	edi, 0B8000h
  2187                              <1> 	;mov	cx, 2000h ; 8K dwords (32K)
  2188                              <1> 	;rep	movsd
  2189                              <1> 	;
  2190                              <1> 	;; 19/11/2020
  2191                              <1> 	;mov	[p_crt_mode], cl ; reset ('case 3' end condition)
  2192                              <1> 	;
  2193                              <1> 	;; restore cursor positions
  2194                              <1> 	;mov	esi, cursor_pposn
  2195                              <1> 	;mov	edi, CURSOR_POSN
  2196                              <1> 	;;mov	ecx, 4	; restore all cursor positions (16 bytes)
  2197                              <1> 	;mov	cl, 4
  2198                              <1> 	;rep 	movsd
  2199                              <1> 	
  2200                              <1> 	; 12/12/2020
  2201 00001D9E E89A000000          <1> 	call	_restore_mode3_multiscreen
  2202                              <1> 
  2203                              <1> 	;jmp	short _sm_23 ; do not clear current video pages
  2204                              <1> 
  2205                              <1> 	; 19/11/2020
  2206 00001DA3 E9C6010000          <1> 	jmp	_set_active_page
  2207                              <1> 
  2208                              <1> _sm_21:
  2209                              <1> 	; 19/11/2020
  2210                              <1> 	; case 2 
  2211                              <1> 	;
  2212                              <1> 	; ([p_crt_mode] = 80h)
  2213                              <1> 	;
  2214                              <1> 	; User has requested to set video mode 3 again while
  2215                              <1> 	; current video mode is 3.. that means, set mode 03h
  2216                              <1> 	; parameters again and clear video page.
  2217                              <1> 	; ('noclearmem' option effects the result) 
  2218                              <1> 	
  2219                              <1> 	; 19/11/2020
  2220 00001DA8 F605[53890100]80    <1> 	test	byte [noclearmem], 80h
  2221 00001DAF 7528                <1> 	jnz	short _sm_22	; 'do not clear video memory'
  2222                              <1> 				; continue with current text
  2223                              <1> 				; (user's option/choice) 
  2224                              <1> 	; clear video page
  2225                              <1> 	;mov	cx, [CRT_LEN] ; 4096
  2226                              <1> 	;shr	cx, 1 ; 2048 ; 16/11/2020
  2227 00001DB1 66B82007            <1> 	mov	ax, 0720h
  2228                              <1> 	; 26/11/2020
  2229                              <1> 	;mov	ecx, 2048 ; 4096/2
  2230                              <1> 	; 02/08/2022
  2231 00001DB5 29C9                <1> 	sub	ecx, ecx
  2232 00001DB7 B508                <1> 	mov	ch, 08h
  2233                              <1> 	; ecx = 0800h
  2234 00001DB9 BF00800B00          <1> 	mov	edi, 0B8000h ; [crt_base]
  2235 00001DBE 66033D[DC7C0100]    <1> 	add	di, [CRT_START]
  2236 00001DC5 F366AB              <1> 	rep	stosw	; FILL THE REGEN BUFFER WITH BLANKS
  2237                              <1> 	;
  2238                              <1> 	; 19/11/2020
  2239 00001DC8 A0[EE7C0100]        <1> 	mov	al, [ACTIVE_PAGE] ; 0 to 7 (for video mode 3)
  2240 00001DCD 0FB6D8              <1> 	movzx	ebx, al
  2241 00001DD0 D0E3                <1> 	shl	bl, 1
  2242 00001DD2 66898B[DE7C0100]    <1> 	mov	[ebx+CURSOR_POSN], cx ; reset cursor position
  2243                              <1> _sm_22:
  2244                              <1> 	;mov	[p_crt_mode], al ; 0 ; reset
  2245                              <1> 	; 19/11/2020
  2246                              <1> 	;and	byte [p_crt_mode], 3 ; 83h -> 3, 80h -> 0  
  2247 00001DD9 8025[51890100]7F    <1> 	and	byte [p_crt_mode], 7Fh ; 83h -> 3, 80h -> 0
  2248                              <1> _sm_23:
  2249                              <1> 	; al = video page number
  2250                              <1> 	; [CRT_LEN] = length of regen buffer in bytes
  2251                              <1> 	;call	_set_active_page
  2252                              <1> 	; 16/11/2020
  2253 00001DE0 E989010000          <1> 	jmp	_set_active_page
  2254                              <1> 
  2255                              <1> ;-----	NORMAL RETURN FROM ALL VIDEO RETURNS
  2256                              <1> 	;retn
  2257                              <1> 
  2258                              <1> save_mode3_multiscreen:
  2259                              <1> 	; 02/08/2022 (TRDOS v2.0.5)
  2260                              <1> 	; 12/12/2020 (TRDOS v2.0.3)
  2261                              <1> 	; save mode 03h video pages and cursor positions
  2262                              <1> 	;
  2263                              <1> 	; Modified registers: ecx (=0), esi, edi
  2264                              <1> 	
  2265                              <1> 	; 12/12/2020
  2266                              <1> 	; moved here from '_set_mode'	
  2267                              <1> 	; 03/07/2016
  2268                              <1> 	; save video pages
  2269 00001DE5 BE00800B00          <1> 	mov	esi, 0B8000h
  2270 00001DEA BF00800900          <1> 	mov	edi, 98000h ; 30/07/2016
  2271                              <1> 	;mov	ecx, (0B8000h-0B0000h)/4
  2272                              <1> 	; 02/08/2022
  2273 00001DEF 29C9                <1> 	sub	ecx, ecx
  2274 00001DF1 B520                <1> 	mov	ch, 20h
  2275                              <1> 	; ecx = 2000h 
  2276 00001DF3 F3A5                <1> 	rep	movsd
  2277                              <1> 	
  2278 00001DF5 C605[51890100]03    <1> 	mov	byte [p_crt_mode], 3 ; previous mode, backup sign
  2279                              <1> 	; 26/11/2020
  2280 00001DFC 860D[EE7C0100]      <1> 	xchg	cl, [ACTIVE_PAGE]
  2281 00001E02 880D[52890100]      <1> 	mov	[p_crt_page], cl  ; save as previous active page
  2282                              <1> 	
  2283                              <1> 	; save cursor positions
  2284 00001E08 BE[DE7C0100]        <1> 	mov	esi, CURSOR_POSN
  2285 00001E0D BF[56890100]        <1> 	mov	edi, cursor_pposn ; cursor positions backup
  2286 00001E12 B104                <1> 	mov	cl, 4
  2287 00001E14 F3A5                <1> 	rep	movsd
  2288 00001E16 C3                  <1> 	retn
  2289                              <1> 
  2290                              <1> restore_mode3_multiscreen:
  2291                              <1> 	; 02/08/2022 (TRDOS v2.0.5)
  2292                              <1> 	; 12/12/2020 (TRDOS v2.0.3)
  2293                              <1> 	; restore mode 03h video pages and cursor positions
  2294                              <1> 	;
  2295                              <1> 	; Input:
  2296                              <1> 	;    settings from the last 'save_mode3_multiscreen'
  2297                              <1> 	;
  2298                              <1> 	; Output: 
  2299                              <1> 	;    AL = active video page = [ACTIVE_PAGE]
  2300                              <1> 	;
  2301                              <1> 	; Modified registers: al, ecx (=0), esi, edi
  2302                              <1> 
  2303 00001E17 A0[52890100]        <1> 	mov	al, [p_crt_page] ; previous mode 3 active page
  2304 00001E1C A2[EE7C0100]        <1> 	mov	[ACTIVE_PAGE], al ; current mode 3 active page
  2305                              <1> 
  2306                              <1> 	; 12/12/2020
  2307                              <1> 	; moved here from 'vesa_vbe3_pmi'	
  2308                              <1> 
  2309                              <1> 	; 07/12/2020
  2310                              <1> 	; restore CRT_START according to ACTIVE_PAGE
  2311                              <1> 	;mov	[CRT_START], cx ; 0
  2312                              <1> 	; 12/12/2020
  2313 00001E21 66C705[DC7C0100]00- <1> 	mov	word [CRT_START], 0
  2313 00001E29 00                  <1>
  2314                              <1> 
  2315                              <1> 	; check active page and set it again if it is not 0
  2316 00001E2A 08C0                <1> 	or	al, al
  2317                              <1> 	;;jz	short vbe3_pmi_7
  2318                              <1> 	;jz	short _restore_mode3_multiscreen
  2319 00001E2C 740F                <1> 	jz	short r_m3_ms_1
  2320 00001E2E 88C1                <1> 	mov	cl, al
  2321                              <1> ;vbe3_pmi_5:
  2322                              <1> r_m3_ms_0:
  2323 00001E30 668105[DC7C0100]00- <1> 	add	word [CRT_START], 4096
  2323 00001E38 10                  <1>
  2324 00001E39 FEC9                <1> 	dec	cl
  2325                              <1> 	;jnz	short vbe3_pmi_5
  2326 00001E3B 75F3                <1> 	jnz	short r_m3_ms_0
  2327                              <1> r_m3_ms_1:
  2328                              <1> 	; 12/12/2020
  2329                              <1> 	; moved here from '_set_mode'	
  2330                              <1> _restore_mode3_multiscreen:
  2331                              <1> 	; Modified registers: ecx, esi, edi
  2332                              <1> 
  2333                              <1> 	; restore video pages
  2334 00001E3D BE00800900          <1> 	mov	esi, 98000h ; 30/07/2016 
  2335 00001E42 BF00800B00          <1> 	mov	edi, 0B8000h
  2336                              <1> 	;mov	cx, 2000h ; 8K dwords (32K)
  2337                              <1> 	;mov	ecx, 2000h
  2338                              <1> 	; 02/08/2022
  2339 00001E47 29C9                <1> 	sub	ecx, ecx
  2340 00001E49 B520                <1> 	mov	ch, 20h
  2341                              <1> 	; ecx = 2000h 
  2342 00001E4B F3A5                <1> 	rep	movsd
  2343                              <1> 
  2344                              <1> 	; 19/11/2020
  2345 00001E4D 880D[51890100]      <1> 	mov	[p_crt_mode], cl ; reset ('case 3' end condition)
  2346                              <1> 
  2347                              <1> 	; restore cursor positions
  2348 00001E53 BE[56890100]        <1> 	mov	esi, cursor_pposn
  2349 00001E58 BF[DE7C0100]        <1> 	mov	edi, CURSOR_POSN
  2350                              <1> 	;mov	ecx, 4	; restore all cursor positions (16 bytes)
  2351 00001E5D B104                <1> 	mov	cl, 4
  2352 00001E5F F3A5                <1> 	rep 	movsd
  2353 00001E61 C3                  <1> 	retn
  2354                              <1> 
  2355                              <1> cursor_shape_fix:
  2356                              <1> 	; 12/04/2021
  2357                              <1> 	; 07/07/2016
  2358                              <1> 	; (Cursor start and cursor end line values -6,7-
  2359                              <1> 	; will be fixed depending on character height)
  2360                              <1> 	;
  2361                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  2362                              <1> 	; vgabios-0.7a (2011)
  2363                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  2364                              <1> 	; 'vgabios.c', ' biosfn_set_cursor_shape (CH,CL)'
  2365                              <1> 	;
  2366                              <1> 	; INPUT ->
  2367                              <1> 	;	AL = cursor start line (=6)
  2368                              <1> 	;	AH = cursor end line (=7)
  2369                              <1> 	; OUTPUT ->
  2370                              <1> 	;	AL = cursor start line (=14)
  2371                              <1> 	;	AH = cursor end line (=15)
  2372                              <1> 	;
  2373                              <1> 	;; if((modeset_ctl&0x01)&&(cheight>8)&&(CL<8)&&(CH<0x20))
  2374                              <1> 
  2375                              <1> 	;test	byte [VGA_MODESET_CTL], 1 ; VGA active
  2376                              <1> 	;jz	short csf_3
  2377 00001E62 803D[E2670000]08    <1> 	cmp	byte [CHAR_HEIGHT], 8
  2378 00001E69 7647                <1> 	jna	short csf_3
  2379 00001E6B 80FC08              <1> 	cmp	ah, 8
  2380 00001E6E 7342                <1> 	jnb	short csf_3
  2381 00001E70 3C20                <1> 	cmp	al, 20h
  2382 00001E72 733E                <1> 	jnb	short csf_3
  2383                              <1> 	;
  2384                              <1> 	;push	ax
  2385                              <1> 	; 12/04/2021
  2386 00001E74 50                  <1> 	push	eax
  2387                              <1> 	; {
  2388                              <1>    	; if(CL!=(CH+1))	
  2389 00001E75 FEC0                <1> 	inc	al
  2390 00001E77 38C4                <1> 	cmp	ah, al   ; ah != al + 1
  2391 00001E79 740F                <1>         je      short csf_1
  2392                              <1> 	; CH = ((CH+1) * cheight / 8) -1;
  2393 00001E7B 8A25[E2670000]      <1> 	mov	ah, [CHAR_HEIGHT]
  2394 00001E81 F6E4                <1> 	mul	ah
  2395 00001E83 C0E803              <1> 	shr	al, 3 ; / 8
  2396 00001E86 FEC8                <1> 	dec	al ; - 1
  2397 00001E88 EB0E                <1> 	jmp	short csf_2 
  2398                              <1> csf_1: 	
  2399                              <1>  	; }
  2400                              <1>    	; else		; ah = al + 1
  2401                              <1>     	; {
  2402 00001E8A FEC4                <1> 	inc	ah	; ah = ah + 1   
  2403                              <1> 	; CH = ((CL+1) * cheight / 8) - 2;
  2404 00001E8C A0[E2670000]        <1> 	mov	al, [CHAR_HEIGHT]
  2405 00001E91 F6E4                <1> 	mul	ah
  2406 00001E93 C0E803              <1> 	shr	al, 3 ; / 8
  2407 00001E96 2C02                <1> 	sub	al, 2 ; - 2
  2408                              <1> 	; al = 14 (if [CHAR_HEIGHT] = 16)
  2409                              <1> csf_2:
  2410 00001E98 880424              <1> 	mov	[esp], al
  2411 00001E9B 8A642401            <1> 	mov	ah, [esp+1]
  2412                              <1> 	; CL = ((CL+1) * cheight / 8) - 1;
  2413 00001E9F FEC4                <1> 	inc	ah 
  2414 00001EA1 A0[E2670000]        <1> 	mov	al, [CHAR_HEIGHT]
  2415 00001EA6 F6E4                <1> 	mul	ah
  2416 00001EA8 C0E803              <1> 	shr	al, 3 ; / 8
  2417 00001EAB FEC8                <1> 	dec	al ; - 1
  2418 00001EAD 88442401            <1> 	mov	[esp+1], al
  2419                              <1> 	; ah = 15 (if [CHAR_HEIGHT] = 16)
  2420                              <1> 	;
  2421                              <1> 	;pop	ax
  2422                              <1> 	; 12/04/2021
  2423 00001EB1 58                  <1> 	pop	eax
  2424                              <1> csf_3:
  2425 00001EB2 C3                  <1> 	retn
  2426                              <1> 
  2427                              <1> SET_CTYPE:
  2428                              <1> 	; 04/08/2022 (TRDOS 386 v2.0.5)
  2429                              <1> 	; 12/09/2016
  2430                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  2431 00001EB3 803D[DE670000]07    <1> 	cmp	byte [CRT_MODE], 7
  2432                              <1> 	;ja	VIDEO_RETURN ; 12/09/2016
  2433                              <1> 	; 04/08/2022
  2434 00001EBA 7738                <1> 	ja	short set_cpos_inv_vp
  2435 00001EBC E805000000          <1> 	call	_set_ctype
  2436 00001EC1 E96CFCFFFF          <1>         jmp     VIDEO_RETURN
  2437                              <1> 
  2438                              <1> _set_ctype:
  2439                              <1> 	; 02/09/2014 (Retro UNIX 386 v1)
  2440                              <1> 	;
  2441                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  2442                              <1> 
  2443                              <1> 	; (CH) = BITS 4-0 = START LINE FOR CURSOR
  2444                              <1> 	;  ** HARDWARE WILL ALWAYS CAUSE BLINK
  2445                              <1> 	;  ** SETTING BIT 5 OR 6 WILL CAUSE ERRATIC BLINKING
  2446                              <1> 	;     OR NO CURSOR AT ALL
  2447                              <1> 	; (CL) = BITS 4-0 = END LINE FOR CURSOR
  2448                              <1> 
  2449                              <1> ;------------------------------------------------
  2450                              <1> ; SET_CTYPE
  2451                              <1> ;	THIS ROUTINE SETS THE CURSOR VALUE
  2452                              <1> ; INPUT
  2453                              <1> ;	(CX) HAS CURSOR VALUE CH-START LINE, CL-STOP LINE
  2454                              <1> ; OUTPUT	
  2455                              <1> ;	NONE
  2456                              <1> ;------------------------------------------------
  2457                              <1> 	
  2458                              <1> 	; 02/08/2022 (TRDOS 386 Kernel v2.0.5)
  2459                              <1> 	;
  2460                              <1> 	; 07/07/2016
  2461                              <1> 	; Fixing cursor start and stop line depending on
  2462                              <1> 	; current character height (=16)
  2463                              <1> 	; (Note: Default/initial values are 6 and 7.
  2464                              <1> 	; If set values are 6 (start) & 7 (stop) and 
  2465                              <1> 	; [CHAR_HEIGHT] = 16 :
  2466                              <1> 	; After fixing, start line will be 14, stop line
  2467                              <1> 	; will be 15.)
  2468                              <1> 
  2469                              <1> 	;mov	ax, cx
  2470                              <1> 	; 02/08/2022
  2471 00001EC6 89C8                <1> 	mov	eax, ecx
  2472                              <1> 
  2473 00001EC8 86E0                <1> 	xchg	al, ah
  2474                              <1> 	; AL = start line, AH = stop line
  2475 00001ECA E893FFFFFF          <1> 	call	cursor_shape_fix
  2476                              <1> 	; AL = start line (fixed), AH = stop line (fixed)
  2477                              <1> 	;mov	cx, ax
  2478                              <1> 	; 02/08/2022
  2479 00001ECF 89C1                <1> 	mov	ecx, eax
  2480 00001ED1 86CD                <1> 	xchg	ch, cl
  2481                              <1> 	; CH = start line (fixed), CL = stop line (fixed)
  2482                              <1> 	;
  2483 00001ED3 B40A                <1> 	mov	ah, 10	; 6845 register for cursor set
  2484 00001ED5 66890D[F7670000]    <1> 	mov	[CURSOR_MODE], cx ; save in data area
  2485                              <1> 	;call	m16	; output cx register
  2486                              <1> 	;retn
  2487 00001EDC E977040000          <1>         jmp     m16
  2488                              <1> 
  2489                              <1> SET_CPOS:
  2490                              <1> 	; 02/08/2022 (TRDOS 386 Kernel v2.0.5)
  2491                              <1> 	; 12/09/2016
  2492                              <1> 	; 07/07/2016
  2493                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  2494 00001EE1 80FF07              <1> 	cmp	bh, 7 ; video page > 7 ; 07/07/2016
  2495                              <1> 	;ja	VIDEO_RETURN
  2496                              <1> 	; 02/08/2022
  2497 00001EE4 770E                <1> 	ja	short set_cpos_inv_vp
  2498                              <1> 	;
  2499 00001EE6 803D[DE670000]07    <1> 	cmp	byte [CRT_MODE], 7
  2500 00001EED 770A                <1> 	ja	short vga_set_cpos ; 12/09/2016	
  2501 00001EEF E839040000          <1> 	call	_set_cpos
  2502                              <1> set_cpos_inv_vp:   ; 02/08/2022
  2503 00001EF4 E939FCFFFF          <1>         jmp     VIDEO_RETURN
  2504                              <1> 
  2505                              <1> vga_set_cpos:
  2506                              <1> 	; 12/09/2016
  2507                              <1> 	; 09/07/2016
  2508                              <1> 	; set cursor position
  2509                              <1> 	; NOTE: Hardware cursor position will not be set
  2510                              <1> 	;   in any VGA modes (>7)
  2511                              <1> 	;   But, cursor position will be saved into
  2512                              <1> 	;   [CURSOR_POSN].
  2513                              <1> 	;   TRDOS 386 (TRDOS v2.0) uses only one page
  2514                              <1> 	;   (page 0) for all graphics modes.
  2515                              <1> 
  2516 00001EF9 668915[DE7C0100]    <1> 	mov	[CURSOR_POSN], dx ; save cursor pos for pg 0
  2517                              <1> 	; 04/08/2016
  2518                              <1> 	;mov	bh, [ACTIVE_PAGE] ; = 0
  2519                              <1> 	;call	_set_cpos
  2520 00001F00 E92DFCFFFF          <1> 	jmp     VIDEO_RETURN
  2521                              <1> 
  2522                              <1> READ_CURSOR:
  2523                              <1> 	; 12/09/2016
  2524                              <1> 	; 07/07/2016
  2525                              <1> 	; 12/05/2016
  2526                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  2527                              <1> 	;
  2528                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  2529                              <1> 
  2530                              <1> ;------------------------------------------------------
  2531                              <1> ; READ_CURSOR
  2532                              <1> ;	THIS ROUTINE READS THE CURRENT CURSOR VALUE FROM THE
  2533                              <1> ;	845, FORMATS IT, AND SENDS IT BACK TO THE CALLER
  2534                              <1> ; INPUT
  2535                              <1> ;	BH - PAGE OF CURSOR
  2536                              <1> ; OUTPUT
  2537                              <1> ;	DX - ROW, COLUMN OF THE CURRENT CURSOR POSITION
  2538                              <1> ;	CX - CURRENT CURSOR MODE
  2539                              <1> ;------------------------------------------------------
  2540                              <1> 
  2541                              <1> 	; BH = Video page number (0 to 7)
  2542                              <1> 
  2543                              <1> 	; 07/07/2016
  2544 00001F05 80FF07              <1> 	cmp	bh, 7 ; video page > 7 (invalid)
  2545 00001F08 7606                <1> 	jna	short read_cursor_1
  2546                              <1> 	; invalid video page (input) 
  2547 00001F0A 31C9                <1> 	xor	ecx, ecx ; 0
  2548 00001F0C 31D2                <1> 	xor	edx, edx ; 0
  2549 00001F0E EB15                <1> 	jmp	short read_cursor_2
  2550                              <1> read_cursor_1:
  2551                              <1> 	; 12/09/2016
  2552 00001F10 803D[DE670000]07    <1> 	cmp	byte [CRT_MODE], 7 ; vga mode
  2553 00001F17 7727                <1> 	ja	short vga_get_cpos
  2554                              <1> 	;
  2555 00001F19 E815000000          <1> 	call	get_cpos
  2556 00001F1E 0FB70D[F7670000]    <1> 	movzx	ecx, word [CURSOR_MODE]
  2557                              <1> read_cursor_2:
  2558 00001F25 5D                  <1> 	pop	ebp
  2559 00001F26 5F                  <1> 	pop	edi
  2560 00001F27 5E                  <1> 	pop	esi
  2561 00001F28 5B                  <1> 	pop	ebx
  2562 00001F29 58                  <1> 	pop	eax  ; DISCARD SAVED CX AND DX
  2563 00001F2A 58                  <1> 	pop	eax
  2564 00001F2B A1[44890100]        <1> 	mov	eax, [video_eax] ; 12/05/2016
  2565                              <1> 	;;15/01/2017
  2566                              <1> 	;;mov	byte [intflg], 0 ; 07/01/2017
  2567 00001F30 1F                  <1> 	pop	ds
  2568 00001F31 07                  <1> 	pop	es
  2569 00001F32 CF                  <1> 	iretd
  2570                              <1> 
  2571                              <1> get_cpos:
  2572                              <1> 	; 12/05/2016
  2573                              <1> 	; 16/01/2016
  2574                              <1> 	; BH = Video page number (0 to 7)
  2575                              <1> 	;
  2576 00001F33 D0E7                <1> 	shl	bh, 1 ; WORD OFFSET
  2577 00001F35 0FB6F7              <1> 	movzx	esi, bh 
  2578 00001F38 0FB796[DE7C0100]    <1> 	movzx	edx, word [esi+CURSOR_POSN]
  2579 00001F3F C3                  <1> 	retn
  2580                              <1> 
  2581                              <1> vga_get_cpos:
  2582                              <1> 	; 12/09/2016
  2583                              <1> 	; get cursor position (vga)
  2584 00001F40 0FB715[DE7C0100]    <1> 	movzx	edx, word [CURSOR_POSN] ; cursor pos for pg 0
  2585 00001F47 31C9                <1> 	xor	ecx, ecx ; Cursor Mode = 0 (invalid)
  2586 00001F49 EBDA                <1> 	jmp     short read_cursor_2
  2587                              <1> 
  2588                              <1> ACT_DISP_PAGE:
  2589                              <1> 	; 07/07/2016
  2590                              <1> 	; 26/06/2016
  2591                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  2592                              <1> 	;
  2593                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  2594                              <1> 	;
  2595                              <1> ;-----------------------------------------------------
  2596                              <1> ; ACT_DISP_PAGE
  2597                              <1> ;	THIS ROUTINE SETS THE ACTIVE DISPLAY PAGE, ALLOWING
  2598                              <1> ;	THE FULL USE OF THE MEMORY SET ASIDE FOR THE VIDEO ATTACHMENT
  2599                              <1> ; INPUT
  2600                              <1> ;	AL HAS THE NEW ACTIVE DISPLAY PAGE
  2601                              <1> ; OUTPUT
  2602                              <1> ;	THE 6845 IS RESET TO DISPLAY THAT PAGE
  2603                              <1> ;-----------------------------------------------------
  2604                              <1> 	; 07/07/2016
  2605 00001F4B 3C07                <1> 	cmp	al, 7	; > 7 = invalid video page number
  2606                              <1> 	;ja	VIDEO_RETURN
  2607 00001F4D 7715                <1>         ja	short adp_2 ; 18/11/2020
  2608                              <1> 	;cmp	byte [CRT_MODE], 3
  2609                              <1> 	;je	short adp_1
  2610                              <1> 	; 18/11/2020
  2611 00001F4F 8A25[DE670000]      <1> 	mov	ah, [CRT_MODE]
  2612 00001F55 80FC03              <1> 	cmp	ah, 3
  2613 00001F58 7605                <1> 	jna	short adp_1 ; mode 01h, 00h (01h), 02h (03h), 03h
  2614 00001F5A 80FC07              <1> 	cmp	ah, 7	    ; mode 07h (03h)
  2615 00001F5D 7505                <1> 	jne	short adp_2
  2616                              <1> 	;and 	al, al
  2617                              <1>         ;jnz	VIDEO_RETURN
  2618                              <1> 	;;sub	al, al ; 0 ; force to page 0
  2619                              <1> adp_1:	
  2620 00001F5F E805000000          <1> 	call	set_active_page
  2621                              <1> adp_2:
  2622 00001F64 E9C9FBFFFF          <1>         jmp     VIDEO_RETURN
  2623                              <1> 
  2624                              <1> set_active_page:   ; tty_sw
  2625                              <1> 	; 02/08/2022 (TRDOS 386 Kernel v2.0.5)
  2626                              <1> 	; 09/12/2017
  2627                              <1> 	; 26/07/2016
  2628                              <1> 	; 26/06/2016
  2629                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  2630                              <1> 	; 30/06/2015
  2631                              <1> 	; 04/03/2014  (act_disp_page --> tty_sw)
  2632                              <1> 	; 10/12/2013
  2633                              <1> 	; 04/12/2013
  2634                              <1> 	;
  2635 00001F69 A2[EE7C0100]        <1> 	mov	[ACTIVE_PAGE], al ; save active page value ; [ptty]
  2636                              <1> _set_active_page:
  2637                              <1> 	; 27/06/2015
  2638                              <1> 	;movzx	ebx, al
  2639                              <1> 	; 02/08/2022
  2640 00001F6E 0FB6C0              <1> 	movzx	eax, al
  2641 00001F71 89C3                <1> 	mov	ebx, eax
  2642                              <1> 	;
  2643                              <1> 	;cbw	; 07/09/2014 (ah=0)
  2644                              <1> 	; 02/08/2022
  2645                              <1> 	;sub	ah, ah ; 09/12/2017
  2646 00001F73 66F725[54890100]    <1> 	mul	word [CRT_LEN]  ; get saved length of regen buffer
  2647                              <1> 				; display page times regen length
  2648                              <1> 	; 10/12/2013
  2649 00001F7A 66A3[DC7C0100]      <1> 	mov	[CRT_START], ax ; save start address for later
  2650                              <1> 	;mov	cx, ax ; start address to cx
  2651                              <1> 	; 02/08/2022
  2652 00001F80 89C1                <1> 	mov	ecx, eax
  2653                              <1> _M16:
  2654                              <1> 	;;sar	cx, 1
  2655                              <1> 	;shr	cx, 1	; divide by 2 for 6845 handling
  2656                              <1> 	; 02/08/2022
  2657 00001F82 D1E9                <1> 	shr	ecx, 1
  2658 00001F84 B40C                <1> 	mov	ah, 12	; 6845 register for start address
  2659 00001F86 E8CD030000          <1> 	call	m16
  2660                              <1> 	;sal	bx, 1
  2661                              <1> 	; 01/09/2014
  2662 00001F8B D0E3                <1> 	shl	bl, 1	; *2 for word offset
  2663 00001F8D 81C3[DE7C0100]      <1> 	add	ebx, CURSOR_POSN
  2664 00001F93 668B13              <1> 	mov	dx, [ebx] ; get cursor for this page
  2665                              <1> 	; 16/01/2016
  2666                              <1> 	;call	m18
  2667                              <1> 	;retn
  2668 00001F96 E9A9030000          <1> 	jmp	m18
  2669                              <1> 
  2670                              <1> position:
  2671                              <1> 	; 02/08/2022 - TRDOS 386 v2.0.5
  2672                              <1> 	; 17/04/2021 - TRDOS 386 v2.0.4
  2673                              <1> 	; 24/06/2016
  2674                              <1> 	; 12/05/2016 - TRDOS 386 (TRDOS v2.0)
  2675                              <1> 	; 27/06/2015
  2676                              <1> 	; 02/09/2014
  2677                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  2678                              <1> 	; 04/12/2013 (Retro UNIX 8086 v1)
  2679                              <1> 	;
  2680                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  2681                              <1> 	;
  2682                              <1> ;-----------------------------------------
  2683                              <1> ; POSITION
  2684                              <1> ;	THIS SERVICE ROUTINE CALCULATES THE REGEN BUFFER ADDRESS
  2685                              <1> ;	OF A CHARACTER IN THE ALPHA MODE
  2686                              <1> ; INPUT
  2687                              <1> ;	AX = ROW, COLUMN POSITION
  2688                              <1> ; OUTPUT
  2689                              <1> ;	AX = OFFSET OF CHAR POSITION IN REGEN BUFFER
  2690                              <1> ;-----------------------------------------
  2691                              <1> 
  2692                              <1> 	; DX = ROW, COLUMN POSITION
  2693                              <1> 	;movzx	eax, byte [CRT_COLS] ; 27/06/2015
  2694 00001F9B 31C0                <1> 	xor	eax, eax ; 02/09/2014
  2695 00001F9D B050                <1> 	mov	al, 80   ; determine bytes to row	
  2696 00001F9F F6E6                <1> 	mul	dh	 ; row value
  2697                              <1> 	;xor	dh, dh   ; 0	
  2698                              <1> 	;add	ax, dx	 ; add column value to the result
  2699                              <1> 	; 16/04/2021
  2700 00001FA1 00D0                <1> 	add	al, dl
  2701 00001FA3 80D400              <1> 	adc	ah, 0
  2702                              <1> 	; 02/08/2022
  2703 00001FA6 D1E0                <1> 	shl	eax, 1
  2704                              <1> 	;shl	ax, 1	; * 2 for attribute bytes
  2705                              <1> 		; EAX = AX = OFFSET OF CHAR POSITION IN REGEN BUFFER 
  2706 00001FA8 C3                  <1> 	retn
  2707                              <1> 
  2708                              <1> find_position:
  2709                              <1> 	; 17/04/2021 - TRDOS 386 v2.0.4
  2710                              <1> 	; 24/06/2016
  2711                              <1> 	; 12/05/2016 - TRDOS 386 (TRDOS v2.0)
  2712                              <1> 	; 27/06/2015
  2713                              <1> 	; 07/09/2014
  2714                              <1> 	; 02/09/2014
  2715                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  2716                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  2717                              <1> 
  2718 00001FA9 0FB6CF              <1> 	movzx	ecx, bh ; video page number
  2719                              <1> 	; 17/04/2021
  2720                              <1> 	;mov	esi, ecx
  2721                              <1> 	;shl	si, 1
  2722                              <1> 	;mov	dx, [esi+CURSOR_POSN]
  2723                              <1> 	;jz	short p21
  2724                              <1> 	;xor	si, si
  2725                              <1> 	; 17/04/2021
  2726 00001FAC 31F6                <1> 	xor	esi, esi
  2727 00001FAE D0E1                <1> 	shl	cl, 1
  2728 00001FB0 668B91[DE7C0100]    <1> 	mov	dx, [ecx+CURSOR_POSN]
  2729 00001FB7 740B                <1> 	jz	short p21
  2730 00001FB9 D0E9                <1> 	shr	cl, 1
  2731                              <1> p20:
  2732 00001FBB 660335[54890100]    <1> 	add	si, [CRT_LEN] ; 24/06/2016
  2733                              <1> 	;add	si, 80*25*2 ; add length of buffer for one page
  2734 00001FC2 E2F7                <1> 	loop	p20
  2735                              <1> p21:
  2736 00001FC4 6621D2              <1> 	and	dx, dx
  2737 00001FC7 7407                <1> 	jz	short p22
  2738 00001FC9 E8CDFFFFFF          <1> 	call 	position ; determine location in regen in page
  2739 00001FCE 01C6                <1> 	add	esi, eax ; add location to start of regen page
  2740                              <1> p22:	
  2741                              <1> 	;mov	dx, [addr_6845] ; get base address of active display
  2742                              <1> 	;mov	dx, 03D4h ; I/O address of color card
  2743                              <1> 	;add	dx, 6	; point at status port
  2744 00001FD0 66BADA03            <1> 	mov	dx, 03DAh ; status port
  2745                              <1> 	; cx = 0
  2746 00001FD4 C3                  <1> 	retn
  2747                              <1> 
  2748                              <1> SCROLL_UP:
  2749                              <1> 	; 04/08/2022 (TRDOS 386 v2.0.5)
  2750                              <1> 	; 07/07/2016
  2751                              <1> 	; 26/06/2016
  2752                              <1> 	; 12/05/2016
  2753                              <1> 	; 30/01/2016
  2754                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  2755                              <1> 	; 07/09/2014
  2756                              <1> 	; 02/09/2014
  2757                              <1> 	; 01/09/2014 (Retro UNIX 386 v1 - beginning)
  2758                              <1> 	; 04/04/2014
  2759                              <1> 	; 04/12/2013
  2760                              <1> 	;
  2761                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  2762                              <1> 	;
  2763                              <1> ;----------------------------------------------
  2764                              <1> ; SCROLL UP
  2765                              <1> ;	THIS ROUTINE MOVES A BLOCK OF CHARACTERS UP
  2766                              <1> ;	ON THE SCREEN
  2767                              <1> ; INPUT
  2768                              <1> ;	(AH) = CURRENT CRT MODE
  2769                              <1> ;	(AL) = NUMBER OF ROWS TO SCROLL
  2770                              <1> ;	(CX) = ROW/COLUMN OF UPPER LEFT CORNER
  2771                              <1> ;	(DX) = ROW/COLUMN OF LOWER RIGHT CORNER
  2772                              <1> ;	(BH) = ATTRIBUTE TO BE USED ON BLANKED LINE
  2773                              <1> ;	(DS) = DATA SEGMENT
  2774                              <1> ;	(ES) = REGEN BUFFER SEGMENT
  2775                              <1> ; OUTPUT
  2776                              <1> ;	NONE -- THE REGEN BUFFER IS MODIFIED
  2777                              <1> ;--------------------------------------------
  2778                              <1> 
  2779                              <1> 	; 07/07/2016
  2780 00001FD5 38F5                <1> 	cmp	ch, dh
  2781                              <1> 	;ja	VIDEO_RETURN
  2782                              <1> 	; 04/08/2022
  2783 00001FD7 7709                <1> 	ja	short _s_u_retn
  2784                              <1> 
  2785 00001FD9 38D1                <1> 	cmp	cl, dl
  2786                              <1> 	;ja	VIDEO_RETURN
  2787                              <1> 	; 04/08/2022
  2788 00001FDB 7705                <1> 	ja	short _s_u_retn
  2789                              <1> 	;
  2790 00001FDD E805000000          <1> 	call	_scroll_up
  2791                              <1> _s_u_retn:
  2792 00001FE2 E94BFBFFFF          <1>         jmp     VIDEO_RETURN
  2793                              <1> 
  2794                              <1> _scroll_up:  ; from 'write_tty'
  2795                              <1> 	;
  2796                              <1> 	; cl = left upper column
  2797                              <1> 	; ch = left upper row
  2798                              <1> 	; dl = right lower column
  2799                              <1> 	; dh = right lower row
  2800                              <1> 	;
  2801                              <1> 	; al = line count 
  2802                              <1> 	; bl = attribute to be used on blanked line
  2803                              <1> 	; bh = video page number (0 to 7)
  2804                              <1> 
  2805 00001FE7 E89B000000          <1> 	call	test_line_count ; 16/01/2016
  2806                              <1> 
  2807 00001FEC 8A25[DE670000]      <1> 	mov	ah, [CRT_MODE] ; current video mode
  2808                              <1> 	;;cmp	byte [CRT_MODE], 4
  2809                              <1> 	;cmp	ah, 4 ; 07/07/2016
  2810                              <1> 	;jnb	GRAPHICS_UP ; 26/06/2016
  2811                              <1> 	; 18/11/2020
  2812 00001FF2 80FC04              <1> 	cmp	ah, 4
  2813 00001FF5 720A                <1>  	jb	short n0	
  2814 00001FF7 80FC07              <1> 	cmp	ah, 7 ; TEST FOR BW CARD 
  2815                              <1> 		      ;	(80x25 text, mono)
  2816 00001FFA 7405                <1> 	je	short n0 ; same with mode 3 for TRDOS 386
  2817 00001FFC E91B050000          <1> 	jmp	GRAPHICS_UP
  2818                              <1> n0:
  2819                              <1> 	; 07/07/2016
  2820 00002001 80FF07              <1> 	cmp	bh, 7 ; video page number
  2821 00002004 7606                <1> 	jna	short n1
  2822 00002006 8A3D[EE7C0100]      <1> 	mov	bh, [ACTIVE_PAGE]
  2823                              <1> n1:
  2824 0000200C 88DC                <1> 	mov	ah, bl ; attribute
  2825                              <1> 	;push	ax ; *
  2826                              <1> 	; 12/04/2021
  2827 0000200E 50                  <1> 	push	eax ; *
  2828                              <1> 	;mov 	esi, [CRT_BASE]
  2829 0000200F BE00800B00          <1>         mov     esi, 0B8000h  
  2830 00002014 3A3D[EE7C0100]      <1>         cmp     bh, [ACTIVE_PAGE]
  2831 0000201A 750B                <1> 	jne	short n2
  2832                              <1> 	;
  2833 0000201C 66A1[DC7C0100]      <1>         mov     ax, [CRT_START]
  2834 00002022 6601C6              <1>         add     si, ax
  2835 00002025 EB11                <1>         jmp     short n4
  2836                              <1> n2:
  2837 00002027 20FF                <1>         and     bh, bh
  2838 00002029 740D                <1> 	jz	short n4
  2839 0000202B 88F8                <1> 	mov	al, bh
  2840                              <1> n3:
  2841 0000202D 660335[54890100]    <1>         add	si, [CRT_LEN]
  2842 00002034 FEC8                <1>         dec	al
  2843 00002036 75F5                <1> 	jnz	short n3
  2844                              <1> n4:	
  2845 00002038 E85B000000          <1> 	call	scroll_position ; 16/01/2016
  2846 0000203D 7420                <1>         jz      short n6 
  2847                              <1> 
  2848 0000203F 01CE                <1>         add     esi, ecx ; from address for scroll
  2849 00002041 88F5                <1> 	mov	ch, dh  ; #rows in block
  2850 00002043 28C5                <1> 	sub	ch, al	; #rows to be moved
  2851                              <1> n5:
  2852 00002045 E88A000000          <1> 	call	n10 ; 16/01/2016
  2853                              <1> 	
  2854 0000204A 51                  <1>         push	ecx
  2855 0000204B 0FB60D[E0670000]    <1> 	movzx	ecx, byte [CRT_COLS] 
  2856 00002052 00C9                <1> 	add	cl, cl
  2857 00002054 01CE                <1>         add	esi, ecx  ; next line
  2858 00002056 01CF                <1>         add	edi, ecx
  2859 00002058 59                  <1> 	pop	ecx
  2860                              <1> 
  2861 00002059 FECD                <1> 	dec	ch	 ; count of lines to move
  2862 0000205B 75E8                <1> 	jnz	short n5 ; row loop
  2863                              <1> 	; ch = 0
  2864 0000205D 88C6                <1> 	mov	dh, al	 ; #rows
  2865                              <1> n6:
  2866                              <1> 	; attribute in ah
  2867 0000205F B020                <1> 	mov	al, ' '	 ; fill with blanks
  2868                              <1> n7:
  2869 00002061 E87B000000          <1> 	call	n11 ; 16/01/2016
  2870                              <1> 
  2871 00002066 8A0D[E0670000]      <1> 	mov	cl, [CRT_COLS]
  2872 0000206C 00C9                <1> 	add	cl, cl
  2873 0000206E 01CF                <1>         add	edi, ecx
  2874                              <1> 
  2875 00002070 FECE                <1> 	dec	dh
  2876 00002072 75ED                <1> 	jnz	short n7
  2877                              <1> n16:
  2878 00002074 3A3D[EE7C0100]      <1> 	cmp	bh, [ACTIVE_PAGE]
  2879 0000207A 750A                <1> 	jne	short n8
  2880                              <1> 	
  2881                              <1> 	;cmp	byte [CRT_MODE], 7 ; is this the black and white card
  2882                              <1> 	;je	short n8	   ; if so, skip the mode reset
  2883                              <1> 
  2884 0000207C A0[DF670000]        <1> 	mov	al, [CRT_MODE_SET] ; get the value of mode set
  2885 00002081 66BAD803            <1> 	mov	dx, 03D8h ; always set color card port
  2886 00002085 EE                  <1> 	out	dx, al
  2887                              <1> n8:
  2888 00002086 C3                  <1> 	retn
  2889                              <1> 
  2890                              <1> test_line_count:
  2891                              <1> 	; 12/04/2021
  2892                              <1> 	; 12/05/2016
  2893                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  2894                              <1> 	; 07/09/2014 (scroll_up)
  2895 00002087 08C0                <1> 	or	al, al
  2896 00002089 740C                <1> 	jz	short al_set2
  2897                              <1> 	;push	dx
  2898                              <1> 	; 12/04/2021
  2899 0000208B 52                  <1> 	push	edx
  2900 0000208C 28EE                <1> 	sub	dh, ch  ; subtract upper row from lower row number
  2901 0000208E FEC6                <1> 	inc	dh	; adjust difference by 1
  2902 00002090 38C6                <1> 	cmp	dh, al 	; line count = amount of rows in window?
  2903 00002092 7502                <1> 	jne	short al_set1 ; if not the we're all set
  2904 00002094 30C0                <1> 	xor	al, al	; otherwise set al to zero
  2905                              <1> al_set1:
  2906                              <1> 	;pop	dx
  2907                              <1> 	; 12/04/2021
  2908 00002096 5A                  <1> 	pop	edx
  2909                              <1> al_set2:
  2910 00002097 C3                  <1> 	retn
  2911                              <1> 
  2912                              <1> scroll_position:
  2913                              <1> 	; 12/04/2021
  2914                              <1> 	; 26/06/2016
  2915                              <1> 	; 30/01/2016
  2916                              <1>         ; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  2917                              <1> 	; 07/09/2014 (scroll_up)
  2918                              <1> 
  2919                              <1> 	; (*) [esp+4] = ax (al = line count, ah = attribute)
  2920                              <1> 
  2921                              <1> 	;push	dx
  2922                              <1> 	; 12/04/2021
  2923 00002098 52                  <1> 	push	edx
  2924 00002099 6689CA              <1> 	mov	dx, cx	; now, upper left position in DX
  2925 0000209C E8FAFEFFFF          <1> 	call	position
  2926 000020A1 01C6                <1> 	add	esi, eax
  2927 000020A3 89F7                <1> 	mov	edi, esi
  2928                              <1> 	;pop	dx	; lower right position in DX
  2929                              <1> 	; 12/04/2021
  2930 000020A5 5A                  <1> 	pop	edx
  2931 000020A6 6629CA              <1> 	sub	dx, cx
  2932 000020A9 FEC6                <1> 	inc	dh	; dh = #rows 
  2933 000020AB FEC2                <1> 	inc	dl	; dl = #cols in block
  2934 000020AD 59                  <1> 	pop	ecx 	; return address
  2935                              <1> 	;pop	ax	; * ; al = line count, ah = attribute
  2936                              <1> 	; 12/04/2021
  2937 000020AE 58                  <1> 	pop	eax ; (*)
  2938 000020AF 51                  <1> 	push	ecx	; return address
  2939 000020B0 0FB7C8              <1> 	movzx	ecx, ax
  2940 000020B3 8A25[E0670000]      <1> 	mov	ah, [CRT_COLS]
  2941 000020B9 F6E4                <1> 	mul	ah	; determine offset to from address
  2942                              <1> 	;add	ax, ax  ; *2 for attribute byte
  2943                              <1> 	; 02/08/2022
  2944                              <1> 	;shl	eax, 1
  2945 000020BB 01C0                <1> 	add	eax, eax
  2946                              <1> 	;
  2947                              <1> 	;push	ax	; offset 
  2948                              <1> 	;push	dx
  2949                              <1> 	; 12/04/2021
  2950 000020BD 50                  <1> 	push	eax	; offset 
  2951 000020BE 52                  <1> 	push	edx
  2952                              <1> 	;
  2953                              <1> 	; 04/04/2014
  2954 000020BF 66BADA03            <1> 	mov	dx, 3DAh ; guaranteed to be color card here	
  2955                              <1> n9:                      ; wait_display_enable
  2956 000020C3 EC                  <1>         in      al, dx   ; get port
  2957 000020C4 A808                <1> 	test	al, RVRT ; wait for vertical retrace	
  2958 000020C6 74FB                <1> 	jz	short n9 ; wait_display_enable
  2959 000020C8 B025                <1> 	mov	al, 25h
  2960 000020CA B2D8                <1> 	mov	dl, 0D8h ; address control port
  2961 000020CC EE                  <1> 	out	dx, al	; turn off video during vertical retrace
  2962                              <1> 	;pop	dx	; #rows, #cols
  2963                              <1>        	;pop	ax	; offset
  2964                              <1> 	; 12/04/2021
  2965 000020CD 5A                  <1> 	pop	edx	; #rows, #cols
  2966 000020CE 58                  <1>        	pop	eax	; offset
  2967 000020CF 6691                <1> 	xchg	ax, cx	; 
  2968                              <1> 	; ecx = offset, al = line count, ah = attribute
  2969                              <1> 	;
  2970 000020D1 08C0                <1> 	or	al, al
  2971 000020D3 C3                  <1> 	retn
  2972                              <1> n10:
  2973                              <1> 	; Move rows
  2974 000020D4 88D1                <1> 	mov	cl, dl	; get # of cols to move
  2975 000020D6 56                  <1> 	push	esi
  2976 000020D7 57                  <1> 	push	edi	; save start address
  2977                              <1> n10r:
  2978 000020D8 66A5                <1> 	movsw		; move that line on screen
  2979 000020DA FEC9                <1> 	dec	cl
  2980 000020DC 75FA                <1>         jnz     short n10r
  2981 000020DE 5F                  <1> 	pop	edi
  2982 000020DF 5E                  <1> 	pop	esi	; recover addresses
  2983 000020E0 C3                  <1> 	retn
  2984                              <1> n11:
  2985                              <1> 	; Clear rows
  2986                              <1>                 	; dh =  #rows
  2987 000020E1 88D1                <1>         mov	cl, dl	; get # of cols to clear
  2988 000020E3 57                  <1>         push    edi     ; save address
  2989                              <1> n11r:
  2990 000020E4 66AB                <1>         stosw           ; store fill character
  2991 000020E6 FEC9                <1> 	dec	cl
  2992 000020E8 75FA                <1>         jnz     short n11r
  2993 000020EA 5F                  <1>         pop     edi     ; recover address
  2994 000020EB C3                  <1> 	retn
  2995                              <1> 
  2996                              <1> SCROLL_DOWN:
  2997                              <1> 	; 12/04/2021
  2998                              <1> 	; 07/07/2016
  2999                              <1> 	; 27/06/2016
  3000                              <1> 	; 26/06/2016
  3001                              <1> 	; 12/05/2016
  3002                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3003                              <1> 	;
  3004                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  3005                              <1> 
  3006                              <1> ;------------------------------------------
  3007                              <1> ; SCROLL DOWN
  3008                              <1> ;	THIS ROUTINE MOVES THE CHARACTERS WITHIN A DEFINED
  3009                              <1> ;	BLOCK DOWN ON THE SCREEN, FILLING THE TOP LINES
  3010                              <1> ;	WITH A DEFINED CHARACTER
  3011                              <1> ; INPUT
  3012                              <1> ;	(AH) = CURRENT CRT MODE
  3013                              <1> ;	(AL) = NUMBER OF LINES TO SCROLL
  3014                              <1> ;	(CX) = UPPER LEFT CORNER OF RECION
  3015                              <1> ;	(DX) = LOWER RIGHT CORNER OF REGION
  3016                              <1> ;	(BH) = FILL CHARACTER
  3017                              <1> ;	(DS) = DATA SEGMENT
  3018                              <1> ;	(ES) = REGEN SEGMENT
  3019                              <1> ; OUTPUT
  3020                              <1> ;	NONE -- SCREEN IS SCROLLED
  3021                              <1> ;------------------------------------------
  3022                              <1> 
  3023                              <1> 	; 07/07/2016
  3024 000020EC 38F5                <1> 	cmp	ch, dh
  3025                              <1> 	;ja	VIDEO_RETURN
  3026 000020EE 7709                <1> 	ja	short _s_d_retn ; 18/11/2020
  3027 000020F0 38D1                <1> 	cmp	cl, dl
  3028                              <1> 	;ja	VIDEO_RETURN
  3029 000020F2 7705                <1> 	ja	short _s_d_retn ; 18/11/2020
  3030                              <1> 	;
  3031 000020F4 E805000000          <1> 	call	_scroll_down
  3032                              <1> _s_d_retn:
  3033 000020F9 E934FAFFFF          <1>         jmp     VIDEO_RETURN
  3034                              <1> 
  3035                              <1> _scroll_down: ; 27/06/2016
  3036                              <1> 
  3037                              <1> 	; cl = left upper column
  3038                              <1> 	; ch = left upper row
  3039                              <1> 	; dl = right lower column
  3040                              <1> 	; dh = right lower row
  3041                              <1> 	;
  3042                              <1> 	; al = line count 
  3043                              <1> 	; bl = attribute to be used on blanked line
  3044                              <1> 	; bh = video page number (0 to 7)
  3045                              <1> 
  3046                              <1> 	; !!!!
  3047 000020FE FD                  <1> 	std		; DIRECTION FOR SCROLL DOWN
  3048                              <1> 	; !!!!
  3049 000020FF E883FFFFFF          <1> 	call	test_line_count ; 16/01/2016
  3050                              <1> 	
  3051 00002104 8A25[DE670000]      <1> 	mov	ah, [CRT_MODE] ; current video mode
  3052                              <1> 	;;cmp	byte [CRT_MODE], 4
  3053                              <1> 	;cmp	ah, 4 ; 07/07/2016
  3054                              <1> 	;jnb	GRAPHICS_DOWN ; 26/06/2016
  3055                              <1> 	; 18/11/2020
  3056 0000210A 80FC04              <1> 	cmp	ah, 4
  3057 0000210D 720A                <1>  	jb	short _n0	
  3058 0000210F 80FC07              <1> 	cmp	ah, 7 ; TEST FOR BW CARD 
  3059                              <1> 		      ;	(80x25 text, mono)
  3060 00002112 7405                <1> 	je	short _n0 ; same with mode 3 for TRDOS 386
  3061 00002114 E9D5060000          <1> 	jmp	GRAPHICS_DOWN
  3062                              <1> _n0:
  3063                              <1> 	; 07/07/2016
  3064 00002119 80FF07              <1> 	cmp	bh, 7 ; video page number
  3065 0000211C 7606                <1> 	jna	short n12
  3066 0000211E 8A3D[EE7C0100]      <1> 	mov	bh, [ACTIVE_PAGE]
  3067                              <1> 	;
  3068                              <1> n12:			; CONTINUE_DOWN
  3069 00002124 88DC                <1> 	mov	ah, bl
  3070                              <1> 	;push	ax	; * ; save attribute in ah
  3071                              <1> 	; 12/04/2021
  3072 00002126 50                  <1> 	push	eax
  3073 00002127 6689D0              <1> 	mov	ax, dx	; LOWER RIGHT CORNER
  3074 0000212A E869FFFFFF          <1> 	call	scroll_position	; GET REGEN LOCATION
  3075 0000212F 741F                <1> 	jz	short n14
  3076 00002131 29CE                <1> 	sub	esi, ecx  ; SI IS FROM ADDRESS
  3077 00002133 88F5                <1> 	mov	ch, dh  ; #rows in block
  3078 00002135 28C5                <1> 	sub	ch, al	; #rows to be moved
  3079                              <1> n13:
  3080 00002137 E898FFFFFF          <1> 	call	n10	; MOVE ONE ROW
  3081                              <1> 
  3082 0000213C 51                  <1> 	push	ecx
  3083 0000213D 8A0D[E0670000]      <1> 	mov	cl, [CRT_COLS] 
  3084 00002143 00C9                <1> 	add	cl, cl
  3085 00002145 29CE                <1>         sub	esi, ecx  ; next line
  3086 00002147 29CF                <1>         sub	edi, ecx
  3087 00002149 59                  <1>         pop	ecx
  3088                              <1> 	
  3089 0000214A FECD                <1> 	dec	ch	 ; count of lines to move
  3090 0000214C 75E9                <1> 	jnz	short n13 ; row loop
  3091                              <1> 	; ch = 0
  3092 0000214E 88C6                <1> 	mov	dh, al	 ; #rows
  3093                              <1> n14:
  3094                              <1> 	; attribute in ah
  3095 00002150 B020                <1> 	mov	al, ' '	 ; fill with blanks
  3096                              <1> n15:
  3097 00002152 E88AFFFFFF          <1> 	call	n11 ; 16/01/2016
  3098                              <1> 
  3099 00002157 8A0D[E0670000]      <1> 	mov	cl, [CRT_COLS]
  3100 0000215D 00C9                <1> 	add	cl, cl
  3101 0000215F 29CF                <1>         sub	edi, ecx
  3102                              <1>         
  3103 00002161 FECE                <1> 	dec	dh
  3104 00002163 75ED                <1> 	jnz	short n15
  3105                              <1> 	;
  3106                              <1> 	; 18/11/2020
  3107 00002165 FC                  <1> 	cld	; clear direction flag	
  3108                              <1> 	;
  3109 00002166 E909FFFFFF          <1> 	jmp	n16 ; 27/06/2016
  3110                              <1> 
  3111                              <1> ;	cmp	bh, [ACTIVE_PAGE]
  3112                              <1> ;	jne	short n16
  3113                              <1> ;
  3114                              <1> ;	;cmp	byte [CRT_MODE], 7	; is this the black and white card
  3115                              <1> ;	;je	short n16		; if so, skip the mode reset
  3116                              <1> ;
  3117                              <1> ;	mov	al, [CRT_MODE_SET] ; get the value of mode set
  3118                              <1> ;	mov	dx, 03D8h ; always set color card port
  3119                              <1> ;	out	dx, al
  3120                              <1> ;n16:
  3121                              <1> ;	; !!!!
  3122                              <1> ;	cld		; Clear direction flag !
  3123                              <1> ;	; !!!!
  3124                              <1> ;	retn
  3125                              <1> 
  3126                              <1> READ_AC_CURRENT:
  3127                              <1> 	; 08/07/2016
  3128                              <1> 	; 26/06/2016
  3129                              <1> 	; 12/05/2016
  3130                              <1> 	; 18/01/2016
  3131                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3132                              <1> 	;
  3133                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  3134                              <1> 	;
  3135                              <1> 	; 08/07/2016
  3136 0000216B 803D[DE670000]07    <1>         cmp     byte [CRT_MODE], 7 ; 6!?
  3137 00002172 7607                <1> 	jna	short read_ac_c
  3138 00002174 31C0                <1> 	xor	eax, eax
  3139 00002176 E9BCF9FFFF          <1>         jmp     _video_return 
  3140                              <1> read_ac_c:
  3141 0000217B E805000000          <1> 	call	_read_ac_current
  3142                              <1> 	; 12/05/2016
  3143                              <1>         ;jmp     VIDEO_RETURN
  3144 00002180 E9B2F9FFFF          <1> 	jmp	_video_return
  3145                              <1> 
  3146                              <1> ;------------------------------------------------------------------------
  3147                              <1> ; READ_AC_CURRENT							:
  3148                              <1> ;	THIS ROUTINE READS THE ATTRIBUTE AND CHARACTER AT THE CURRENT	:
  3149                              <1> ;	CURSOR POSITION AND RETURNS THEM TO THE CALLER			:
  3150                              <1> ; INPUT									:
  3151                              <1> ;	(AH) = CURRENT CRT MODE						:
  3152                              <1> ;	(BH) = DISPLAY PAGE ( ALPHA MODES ONLY )			:
  3153                              <1> ;	(DS) = DATA SEGMENT						:
  3154                              <1> ;	(ES) = REGEN SEGMENT						:
  3155                              <1> ; OUTPUT								:
  3156                              <1> ;	(AL) = CHARACTER READ						:
  3157                              <1> ;	(AH) = ATTRIBUTE READ						:
  3158                              <1> ;------------------------------------------------------------------------
  3159                              <1> 
  3160                              <1> _read_ac_current:
  3161                              <1> 	; 26/06/2016
  3162                              <1> 	; 12/05/2016 
  3163                              <1> 	; 18/01/2016
  3164                              <1> 
  3165 00002185 8A25[DE670000]      <1> 	mov	ah, [CRT_MODE] ; current video mode	
  3166 0000218B 80FC04              <1> 	cmp	ah, 4
  3167 0000218E 720A                <1>  	jb	short p10
  3168                              <1> 	; 18/11/2020
  3169                              <1> 	;cmp	byte [CRT_MODE], 4
  3170                              <1> 	;jnb	GRAPHICS_READ ; 26/06/2016
  3171                              <1> 
  3172 00002190 80FC07              <1> 	cmp	ah, 7 ; TEST FOR BW CARD (80x25 monochrome text)
  3173 00002193 7405                <1> 	je	short p10	 ; same with mode 3 in TRDOS 386
  3174 00002195 E9A0080000          <1> 	jmp	GRAPHICS_READ
  3175                              <1> p10:
  3176 0000219A E80AFEFFFF          <1> 	call	find_position	; GET REGEN LOCATION AND PORT ADDRESS
  3177                              <1> 	;
  3178                              <1> 	; esi = regen location
  3179                              <1> 	; dx = status port
  3180                              <1> 	;
  3181                              <1> 
  3182                              <1> 	; 18/11/2020
  3183                              <1> 	; convert display mode to a zero value 
  3184                              <1> 	; for 80 column color mode
  3185                              <1> 	;mov	ah, [CRT_MODE]	
  3186                              <1> 	;sub	ah, 2
  3187                              <1> 	;shr	ah, 1
  3188                              <1> 	;jnz	short p13
  3189                              <1> 
  3190                              <1> 	; 05/12/2020
  3191                              <1> 	; 18/11/2020 (TRDOS 386 v2.0.3)
  3192                              <1> 	;xor	bl, bl	; 0
  3193 0000219F 803D[DE670000]03    <1> 	cmp	byte [CRT_MODE], 03h ; 80x25 color text
  3194                              <1> 	;je	short p11    ; Note: Only mode 03h and mode 01h are
  3195                              <1> 	;inc	bl	; 1  ;       in use by TRDOS 386 as text modes	
  3196                              <1> 	;jmp	short p14    ;       (07h, 00h and 02h are redirected)		
  3197 000021A6 7516                <1> 	jne	short p13
  3198                              <1> 
  3199                              <1> 	; 05/12/2020
  3200 000021A8 3A3D[EE7C0100]      <1> 	cmp     bh, [ACTIVE_PAGE]
  3201 000021AE 750E                <1> 	jne	short p13 
  3202                              <1> 
  3203                              <1> 	; WAIT FOR HORIZONTAL RETRACE OR VERTICAL RETRACE IF COLOR 80
  3204                              <1> p11:
  3205 000021B0 FB                  <1> 	sti		; enable interrupts first
  3206                              <1> 	; 05/12/2020
  3207 000021B1 90                  <1> 	nop
  3208                              <1> 	; 18/11/2020
  3209                              <1> 	;or	bl, bl
  3210                              <1> 	;jnz	short p13 ; mode 01h (and mode 00h) - 40x25 color text
  3211 000021B2 FA                  <1> 	cli 		; block interrupts for single loop
  3212 000021B3 EC                  <1> 	in	al, dx	; get status from the adapter
  3213 000021B4 A801                <1> 	test	al, RHRZ ; is horizontal retrace low
  3214 000021B6 75F8                <1> 	jnz	short p11 ; wait until it is
  3215                              <1> p12:			;  wait for either retrace high
  3216 000021B8 EC                  <1> 	in	al, dx ; get status again
  3217 000021B9 A809                <1> 	test	al, RVRT+RHRZ ; is horizontal or vertical retrace high
  3218 000021BB 74FB                <1> 	jz	short p12 ; wait until either retrace active
  3219                              <1> ;p14:
  3220 000021BD FB                  <1> 	sti
  3221                              <1> p13:
  3222 000021BE 81C600800B00        <1> 	add	esi, 0B8000h 
  3223 000021C4 668B06              <1> 	mov	ax, [esi]
  3224                              <1> 
  3225 000021C7 C3                  <1> 	retn	; 18/01/2016
  3226                              <1> 
  3227                              <1> WRITE_AC_CURRENT:
  3228                              <1> 	; 08/07/2016
  3229                              <1> 	; 26/06/2016
  3230                              <1> 	; 24/06/2016
  3231                              <1> 	; 12/05/2016
  3232                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3233                              <1> 	;
  3234                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  3235                              <1> 	;
  3236                              <1> ;----------------------------------------------------------------
  3237                              <1> ; WRITE_AC_CURRENT						:
  3238                              <1> ;	THTS ROUTINE WRITES THE ATTRIBUTE AND CHARACTER		:
  3239                              <1> ;	AT THE CURRENT CURSOR POSITION				:
  3240                              <1> ; INPUT								:
  3241                              <1> ;	(AH) = CURRENT CRT MODE					:
  3242                              <1> ;	(BH) = DISPLAY PAGE					:
  3243                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE			:
  3244                              <1> ;	(AL) = CHAR TO WRITE					:
  3245                              <1> ;	(BL) = ATTRIBUTE OF CHAR TO WRITE			:
  3246                              <1> ;	(DS) = DATA SEGMENT					:
  3247                              <1> ;	(ES) = REGEN SEGMENT					:
  3248                              <1> ; OUTPUT							:
  3249                              <1> ;	DISPLAY REGEN BUFFER UPDATED				:
  3250                              <1> ;----------------------------------------------------------------
  3251                              <1> 
  3252                              <1> 	; 08/07/2016
  3253 000021C8 803D[DE670000]07    <1> 	cmp	byte [CRT_MODE], 7 ; 6!?
  3254 000021CF 760A                <1> 	jna	short write_ac_c
  3255                              <1> 
  3256 000021D1 E8B60A0000          <1> 	call	vga_write_char_attr
  3257 000021D6 E957F9FFFF          <1> 	jmp     VIDEO_RETURN	
  3258                              <1> 
  3259                              <1> write_ac_c:
  3260 000021DB E834000000          <1> 	call	_write_c_current
  3261                              <1> 
  3262 000021E0 0FB6F7              <1> 	movzx	esi, bh ; video page number (0 to 7)	
  3263 000021E3 889E[E7670000]      <1> 	mov	[esi+chr_attrib], bl ; color/attribute
  3264                              <1> 
  3265 000021E9 E944F9FFFF          <1>         jmp     VIDEO_RETURN
  3266                              <1> 
  3267                              <1> WRITE_C_CURRENT:
  3268                              <1> 	; 08/07/2016
  3269                              <1> 	; 26/06/2016
  3270                              <1> 	; 12/05/2016
  3271                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3272                              <1> 	;
  3273                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  3274                              <1> 	;
  3275                              <1> ;----------------------------------------------------------------
  3276                              <1> ; WRITE_C_CURRENT						:
  3277                              <1> ;	THIS ROUTINE WRITES THE CHARACTER AT			:
  3278                              <1> ;	THE CURRENT CURSOR POSITION, ATTRIBUTE UNCHANGED	:
  3279                              <1> ; INPUT								:
  3280                              <1> ;	(AH) = CURRENT CRT MODE					:
  3281                              <1> ;	(BH) = DISPLAY PAGE					:
  3282                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE			:
  3283                              <1> ;	(AL) = CHAR TO WRITE					:
  3284                              <1> ;	(DS) = DATA SEGMENT					:
  3285                              <1> ;	(ES) = REGEN SEGMENT					:
  3286                              <1> ; OUTPUT							:
  3287                              <1> ;	DISPLAY REGEN BUFFER UPDATED				:
  3288                              <1> ;----------------------------------------------------------------
  3289                              <1> 
  3290                              <1> 	; 08/07/2016
  3291 000021EE 803D[DE670000]07    <1> 	cmp	byte [CRT_MODE], 7 ; 6!?
  3292 000021F5 760A                <1> 	jna	short write_c_c
  3293                              <1> 
  3294 000021F7 E8900A0000          <1> 	call	vga_write_char_only
  3295 000021FC E931F9FFFF          <1> 	jmp     VIDEO_RETURN	
  3296                              <1> 
  3297                              <1> write_c_c:
  3298                              <1> 	;and	bh, 7 ; video page number (<= 7)
  3299 00002201 0FB6F7              <1> 	movzx	esi, bh	
  3300 00002204 8A9E[E7670000]      <1> 	mov	bl, [esi+chr_attrib]
  3301                              <1> 
  3302 0000220A E805000000          <1> 	call	_write_c_current
  3303 0000220F E91EF9FFFF          <1>         jmp     VIDEO_RETURN
  3304                              <1> 
  3305                              <1> _write_c_current:  ; from 'write_tty'
  3306                              <1> 	; 12/04/2021
  3307                              <1> 	; 18/11/2020
  3308                              <1> 	; 26/06/2016
  3309                              <1> 	; 24/06/2016
  3310                              <1> 	; 12/05/2016
  3311                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3312                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  3313                              <1> 	; 18/01/2014
  3314                              <1> 	; 04/12/2013
  3315                              <1> 	;
  3316                              <1> 	; VIDEO.ASM - 06/10/85 VIDEO DISPLAY BIOS
  3317                              <1> 
  3318                              <1> 	; 18/11/2020
  3319 00002214 8A25[DE670000]      <1> 	mov	ah, [CRT_MODE] ; current video mode	
  3320 0000221A 80FC04              <1> 	cmp	ah, 4
  3321 0000221D 720A                <1>  	jb	short p40
  3322                              <1> 	
  3323                              <1> 	;cmp	byte [CRT_MODE], 4
  3324                              <1>         ;jnb	GRAPHICS_WRITE ; 26/06/2016
  3325                              <1> 
  3326 0000221F 80FC07              <1> 	cmp	ah, 7 ; TEST FOR BW CARD
  3327 00002222 7405                <1> 	je	short p40
  3328 00002224 E963070000          <1> 	jmp	GRAPHICS_WRITE
  3329                              <1> p40:
  3330                              <1> 	; al = character
  3331                              <1> 	; bl = color/attribute
  3332                              <1> 	; bh = video page
  3333                              <1> 	; cx = count of characters to write
  3334                              <1> 	;push	dx
  3335                              <1> 	; 12/04/2021
  3336 00002229 52                  <1> 	push	edx ; *
  3337 0000222A 88DC                <1> 	mov	ah, bl  ; color/attribute (12/05/2016)
  3338                              <1> 	;push	ax	; save character & attribute/color
  3339                              <1> 	;push	cx
  3340                              <1> 	; 12/04/2021
  3341 0000222C 50                  <1> 	push	eax ; ** ; save character & attribute/color
  3342 0000222D 51                  <1> 	push	ecx ; ***
  3343 0000222E E876FDFFFF          <1> 	call 	find_position  ; get regen location and port address
  3344                              <1> 	;pop	cx
  3345                              <1> 	; 12/04/2021
  3346 00002233 59                  <1> 	pop	ecx ; ***
  3347                              <1> 	; esi = regen location
  3348                              <1> 	; dx = status port
  3349                              <1> 	;
  3350 00002234 81C600800B00        <1> 	add	esi, 0B8000h ; 30/08/2014 (crt_base) 
  3351                              <1> 	;
  3352                              <1> 	; 18/11/2020
  3353                              <1> 	; convert display mode to a zero value 
  3354                              <1> 	; for 80 column color mode
  3355                              <1> 	;mov	ah, [CRT_MODE]	
  3356                              <1> 	;sub	ah, 2
  3357                              <1> 	;shr	ah, 1
  3358                              <1> 	;jnz	short p44    ; 26/06/2016
  3359                              <1> 
  3360                              <1> 	; 05/12/2020
  3361                              <1> 	; 18/11/2020 (TRDOS 386 v2.0.3)
  3362                              <1> 	;xor	bl, bl	; 0
  3363 0000223A 803D[DE670000]03    <1> 	cmp	byte [CRT_MODE], 03h ; 80x25 color text
  3364                              <1> 	;je	short p41    ; Note: Only mode 03h and mode 01h are
  3365                              <1> 	;inc	bl	; 1  ;       in use by TRDOS 386 as text modes	
  3366                              <1> 	;jmp	short p43    ;       (07h, 00h and 02h are redirected)			
  3367                              <1> 	; 05/12/2020
  3368 00002241 751A                <1> 	jne	short p44
  3369                              <1> p46:
  3370                              <1> 	; 05/12/2020
  3371 00002243 3A3D[EE7C0100]      <1> 	cmp     bh, [ACTIVE_PAGE]
  3372 00002249 7512                <1> 	jne	short p44
  3373                              <1> 
  3374                              <1> 	; WAIT FOR HORIZONTAL RETRACE OR VERTICAL RETRACE IF COLOR 80
  3375                              <1> p41:
  3376                              <1> 	; 05/12/2020
  3377 0000224B FB                  <1> 	sti		; enable interrupts first
  3378 0000224C 90                  <1> 	nop
  3379                              <1> 	; 18/11/2020
  3380                              <1> 	;or	bl, bl
  3381                              <1> 	;jnz	short p44 ; mode 01h (and mode 00h) - 40x25 color text
  3382 0000224D FA                  <1> 	cli 		; block interrupts for single loop
  3383 0000224E EC                  <1> 	in	al, dx	; get status from the adapter
  3384 0000224F A808                <1> 	test	al, RVRT ; check for vertical retrace first
  3385 00002251 7509                <1> 	jnz	short p43 ; Do fast write now if vertical retrace
  3386 00002253 A801                <1> 	test	al, RHRZ ; is horizontal retrace low
  3387 00002255 75F4                <1> 	jnz	short p41 ; wait until it is
  3388                              <1> p42:			;  wait for either retrace high
  3389 00002257 EC                  <1> 	in	al, dx ; get status again
  3390 00002258 A809                <1> 	test	al, RVRT+RHRZ ; is horizontal or vertical retrace high
  3391 0000225A 74FB                <1> 	jz	short p42 ; wait until either retrace active
  3392                              <1> p43:	
  3393 0000225C FB                  <1> 	sti
  3394                              <1> p44:
  3395 0000225D 668B0424            <1> 	mov	ax, [esp] ; restore the character (al) & attribute (ah)
  3396 00002261 668906              <1> 	mov	[esi], ax
  3397                              <1> 
  3398 00002264 6649                <1> 	dec	cx
  3399 00002266 740D                <1> 	jz	short p45
  3400                              <1> 
  3401 00002268 46                  <1> 	inc	esi
  3402 00002269 46                  <1> 	inc	esi
  3403                              <1> 
  3404                              <1> 	; 05/12/2020
  3405 0000226A 803D[DE670000]03    <1> 	cmp	byte [CRT_MODE], 03h
  3406 00002271 75EA                <1> 	jne	short p44
  3407                              <1> 	;jmp	short p41
  3408 00002273 EBCE                <1> 	jmp	short p46
  3409                              <1> p45:	
  3410                              <1> 	;pop	ax
  3411                              <1> 	;pop	dx
  3412                              <1> 	; 12/04/2021
  3413 00002275 58                  <1> 	pop	eax ; **
  3414 00002276 5A                  <1> 	pop	edx ; *
  3415 00002277 C3                  <1> 	retn
  3416                              <1> 
  3417                              <1> ; 09/07/2016
  3418                              <1> ; 26/06/2016
  3419                              <1> ; 24/06/2016
  3420                              <1> ; 12/05/2016
  3421                              <1> ; 18/01/2016
  3422                              <1> ; 16/01/2016 - TRDOS 386 (TRDOS v2.0)
  3423                              <1> ; 30/06/2015
  3424                              <1> ; 27/06/2015
  3425                              <1> ; 11/03/2015
  3426                              <1> ; 02/09/2014
  3427                              <1> ; 30/08/2014
  3428                              <1> ; VIDEO FUNCTIONS
  3429                              <1> ; (write_tty - Retro UNIX 8086 v1 - U9.ASM, 01/02/2014)
  3430                              <1> 
  3431                              <1> WRITE_TTY:
  3432                              <1> 	; 09/12/2017
  3433                              <1> 	; 09/07/2016
  3434                              <1> 	; 01/07/2016
  3435                              <1> 	; 26/06/2016
  3436                              <1> 	; 24/06/2016
  3437                              <1> 	; 13/05/2016
  3438                              <1> 	; 12/05/2016
  3439                              <1> 	; 30/01/2016
  3440                              <1> 	; 18/01/2016
  3441                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
  3442                              <1> 	; 13/08/2015
  3443                              <1> 	; 02/09/2014
  3444                              <1> 	; 30/08/2014 (Retro UNIX 386 v1 - beginning)
  3445                              <1> 	; 01/02/2014 (Retro UNIX 8086 v1 - last update)
  3446                              <1> 	; 03/12/2013 (Retro UNIX 8086 v1 - beginning)	
  3447                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI, EDI)
  3448                              <1> 	;
  3449                              <1> 	; INPUT -> AL = Character to be written
  3450                              <1> 	;	   BL = Color (Forecolor, Backcolor)
  3451                              <1> 	;	   BH = Video Page (0 to 7)
  3452                              <1> 
  3453                              <1> 	; 09/07/2016
  3454 00002278 803D[DE670000]07    <1>         cmp     byte [CRT_MODE], 7
  3455 0000227F 760A                <1> 	jna 	short write_tty_cga
  3456                              <1> 
  3457 00002281 E8EB0C0000          <1> 	call	vga_write_teletype
  3458 00002286 E9A7F8FFFF          <1> 	jmp	VIDEO_RETURN
  3459                              <1> 
  3460                              <1> write_tty_cga:
  3461                              <1> 	; 13/05/2016
  3462                              <1> 	;call	_write_tty
  3463                              <1> 	; 01/07/2016
  3464 0000228B E818000000          <1> 	call	_write_tty_m3
  3465 00002290 E99DF8FFFF          <1> 	jmp	VIDEO_RETURN
  3466                              <1> 
  3467                              <1> RVRT	equ	00001000b	; VIDEO VERTICAL RETRACE BIT
  3468                              <1> RHRZ	equ	00000001b	; VIDEO HORIZONTAL RETRACE BIT
  3469                              <1> 
  3470                              <1> ; Derived from "WRITE_TTY" procedure of IBM "pc-at" rombios source code
  3471                              <1> ; (06/10/1985), 'video.asm', INT 10H, VIDEO_IO
  3472                              <1> ;
  3473                              <1> ; 06/10/85  VIDEO DISPLAY BIOS
  3474                              <1> ;
  3475                              <1> ;--- WRITE_TTY ------------------------------------------------------------------
  3476                              <1> ;										:
  3477                              <1> ;   THIS INTERFACE PROVIDES A TELETYPE LIKE INTERFACE TO THE			:
  3478                              <1> ;   VIDEO CARDS. THE INPUT CHARACTER IS WRITTEN TO THE CURRENT			:
  3479                              <1> ;   CURSOR POSITION, AND THE CURSOR IS MOVED TO THE NEXT POSITION.		:
  3480                              <1> ;   IF THE CURSOR LEAVES THE LAST COLUMN OF THE FIELD, THE COLUMN		:
  3481                              <1> ;   IS SET TO ZERO, AND THE ROW VALUE IS INCREMENTED. IF THE ROW		:
  3482                              <1> ;   ROW VALUE LEAVES THE FIELD, THE CURSOR IS PLACED ON THE LAST ROW,		:
  3483                              <1> ;   FIRST COLUMN, AND THE ENTIRE SCREEN IS SCROLLED UP ONE LINE.		:
  3484                              <1> ;   WHEN THE SCREEN IS SCROLLED UP, THE ATTRIBUTE FOR FILLING THE		:
  3485                              <1> ;   NEWLY BLANKED LINE IS READ FROM THE CURSOR POSITION ON THE PREVIOUS		:
  3486                              <1> ;   LINE BEFORE THE SCROLL, IN CHARACTER MODE. IN GRAPHICS MODE,		:
  3487                              <1> ;   THE 0 COLOR IS USED.							:
  3488                              <1> ;   ENTRY --									:
  3489                              <1> ;     (AH) = CURRENT CRT MODE							:
  3490                              <1> ;     (AL) = CHARACTER TO BE WRITTEN						:
  3491                              <1> ;	    NOTE THAT BACK SPACE, CARRIAGE RETURN, BELL AND LINE FEED ARE	:
  3492                              <1> ;	    HANDLED AS COMMANDS RATHER THAN AS DISPLAY GRAPHICS CHARACTERS	:
  3493                              <1> ;     (BL) = FOREGROUND COLOR FOR CHAR WRITE IF CURRENTLY IN A GRAPHICS MODE	:
  3494                              <1> ;   EXIT -- 									:
  3495                              <1> ;     ALL REGISTERS SAVED							:
  3496                              <1> ;--------------------------------------------------------------------------------
  3497                              <1> 
  3498                              <1> ; 02/08/2022 (TRDOS 386 v2.0.5)
  3499                              <1> ; 18/11/2020 (TRDOS 386 v2.0.3)
  3500                              <1> ; 09/12/2017
  3501                              <1> ; 08/07/2016
  3502                              <1> ; 26/06/2016
  3503                              <1> ; 24/06/2016
  3504                              <1> _write_tty:
  3505                              <1> 	; 13/05/2016
  3506                              <1> 	; --- 18/11/2020 ---
  3507                              <1> 	; NOTE:
  3508                              <1> 	; Only kernel calls "_write_tty" procedure...
  3509                              <1> 	; TRDOS 386 v2 kernel uses video mode 3 for displaying
  3510                              <1> 	; (some error) messages and also mainprog command interpreter
  3511                              <1> 	; (in kernel) uses "_write_tty".
  3512                              <1> 	; So, here video mode must be set to 3 if it is not 3.
  3513                              <1>  
  3514 00002295 FA                  <1> 	cli	; disable interrupts
  3515                              <1> 	;
  3516                              <1> 	; 01/09/2014
  3517 00002296 803D[DE670000]03    <1> 	cmp	byte [CRT_MODE], 3
  3518 0000229D 7409                <1> 	je	short _write_tty_m3
  3519                              <1> 	;
  3520                              <1> set_mode_3:
  3521 0000229F 53                  <1> 	push	ebx
  3522 000022A0 50                  <1> 	push	eax
  3523                              <1> 	;call	_set_mode
  3524                              <1> 	; 18/11/2020 
  3525 000022A1 E89BF8FFFF          <1> 	call	set_txt_mode  ; set video mode to 03h 
  3526 000022A6 58                  <1> 	pop	eax
  3527 000022A7 5B                  <1> 	pop	ebx
  3528                              <1> 	;
  3529                              <1> _write_tty_m3: ; 24/06/2016 (m3 -> _write_tty_m3)
  3530 000022A8 0FB6F7              <1> 	movzx 	esi, bh ; 12/05/2016
  3531                              <1> 	;shl	si, 1
  3532                              <1> 	; 02/08/2022
  3533 000022AB D1E6                <1> 	shl	esi, 1
  3534 000022AD 81C6[DE7C0100]      <1> 	add	esi, CURSOR_POSN
  3535 000022B3 668B16              <1> 	mov	dx, [esi]
  3536                              <1> 	;
  3537                              <1> 	; dx now has the current cursor position
  3538                              <1> 	;
  3539 000022B6 3C0D                <1> 	cmp	al, 0Dh	; CR	; is it carriage return or control character
  3540                              <1> 	;jbe	short u8
  3541                              <1> 	; 17/04/2021
  3542 000022B8 7241                <1> 	jb	short u8
  3543 000022BA 746F                <1> 	je	short u9
  3544                              <1> 	;
  3545                              <1> 	; write the char to the screen
  3546                              <1> u0:	
  3547                              <1> 	; al = character
  3548                              <1> 	; bl = attribute/color
  3549                              <1> 	; bh = video page number (0 to 7)
  3550                              <1> 	;
  3551                              <1> 	;mov	cx, 1  ; 24/06/2016
  3552                              <1> 	; 02/08/2022
  3553 000022BC 29C9                <1> 	sub	ecx, ecx
  3554 000022BE FEC1                <1> 	inc	cl ; ecx = 1
  3555                              <1> 	; cx = count of characters to write
  3556                              <1> 	;
  3557 000022C0 E84FFFFFFF          <1> 	call	_write_c_current ; 16/01/2015
  3558                              <1> 	;
  3559                              <1> 	; position the cursor for next char
  3560 000022C5 FEC2                <1> 	inc	dl		; next column
  3561 000022C7 3A15[E0670000]      <1> 	cmp	dl, [CRT_COLS]  ; test for column overflow 
  3562                              <1> 	;jne	_set_cpos
  3563                              <1> 	; 02/08/2022
  3564 000022CD 7402                <1> 	je	short u13
  3565 000022CF EB5C                <1> 	jmp	_set_cpos
  3566                              <1> u13:
  3567 000022D1 B200                <1> 	mov	dl, 0		; column = 0
  3568                              <1> u10:				; (line feed found)
  3569 000022D3 80FE18              <1> 	cmp	dh, 25-1 	; check for last row
  3570 000022D6 721F                <1> 	jb 	short u6
  3571                              <1> 	;
  3572                              <1> 	; scroll required
  3573                              <1> u1:	
  3574                              <1> 	; SET CURSOR POSITION (04/12/2013)
  3575 000022D8 E850000000          <1> 	call	_set_cpos
  3576                              <1> 	;
  3577                              <1> 	; determine value to fill with during scroll
  3578                              <1> u2:
  3579                              <1> 	; bh = video page number
  3580                              <1> 	;
  3581 000022DD E8A3FEFFFF          <1> 	call	_read_ac_current ; 18/01/2016
  3582                              <1> 	;
  3583                              <1> 	; al = character, ah = attribute
  3584                              <1> 	; bh = video page number
  3585                              <1> 	; 18/11/2020
  3586 000022E2 88E3                <1> 	mov	bl, ah ; color/attribute 	
  3587                              <1> u3:
  3588                              <1> 	;;mov	ax, 0601h 	; scroll one line
  3589                              <1> 	;;sub	cx, cx		; upper left corner
  3590                              <1> 	;;mov	dh, 25-1 	; lower right row
  3591                              <1> 	;;;mov	dl, [CRT_COLS]
  3592                              <1> 	;mov	dl, 80		; lower right column	
  3593                              <1> 	;;dec	dl
  3594                              <1> 	;;mov	dl, 79
  3595                              <1> 
  3596                              <1> 	;;call	scroll_up	; 04/12/2013
  3597                              <1> 	;;; 11/03/2015
  3598                              <1> 	; 02/09/2014
  3599                              <1> 	;;;mov	cx, [crt_ulc] ; Upper left corner  (0000h)
  3600                              <1> 	;;;mov	dx, [crt_lrc] ; Lower right corner (184Fh)
  3601                              <1> 	; 11/03/2015
  3602                              <1> 	;sub	cx, cx
  3603                              <1> 	; 17/04/2021
  3604 000022E4 29C9                <1> 	sub	ecx, ecx
  3605                              <1> 	;mov	dx, 184Fh ; dl = 79 (column), dh = 24 (row)
  3606                              <1> 	; 18/11/2020
  3607 000022E6 B618                <1> 	mov	dh, 25-1
  3608 000022E8 8A15[E0670000]      <1> 	mov	dl, [CRT_COLS]
  3609 000022EE FECA                <1> 	dec	dl
  3610                              <1> 	;
  3611 000022F0 B001                <1> 	mov	al, 1		; scroll 1 line up
  3612                              <1> 		; ah = attribute
  3613                              <1> 	;mov	bl, al ; 12/05/2016
  3614 000022F2 E9F0FCFFFF          <1> 	jmp	_scroll_up	; 16/01/2016
  3615                              <1> ;u4:
  3616                              <1> 	;;int	10h		; video-call return
  3617                              <1> 				; scroll up the screen
  3618                              <1> 				; tty return
  3619                              <1> ;u5:
  3620                              <1> 	;retn			; return to the caller
  3621                              <1> 
  3622                              <1> u6:				; set-cursor-inc
  3623 000022F7 FEC6                <1> 	inc	dh		; next row
  3624                              <1> 				; set cursor
  3625                              <1> ;u7:					
  3626                              <1> 	;;mov	ah, 02h
  3627                              <1> 	;;jmp	short u4 	; establish the new cursor
  3628                              <1> 	;call	_set_cpos
  3629                              <1> 	;jmp 	short u5
  3630 000022F9 EB32                <1> 	jmp     _set_cpos
  3631                              <1> 
  3632                              <1> 	; check for control characters
  3633                              <1> u8:
  3634                              <1> 	;je	short u9 ; 17/04/2021
  3635 000022FB 3C0A                <1> 	cmp	al, 0Ah		; is it a line feed (0Ah)
  3636 000022FD 74D4                <1> 	je	short u10
  3637 000022FF 3C07                <1> 	cmp	al, 07h 	; is it a bell
  3638 00002301 747C                <1> 	je	short u11
  3639 00002303 3C08                <1> 	cmp	al, 08h		; is it a backspace
  3640                              <1> 	;jne	short u0
  3641 00002305 741C                <1> 	je	short bs	; 12/12/2013
  3642                              <1> 	; 12/12/2013 (tab stop)
  3643 00002307 3C09                <1> 	cmp	al, 09h		; is it a tab stop
  3644 00002309 75B1                <1> 	jne	short u0
  3645 0000230B 88D0                <1> 	mov	al, dl
  3646                              <1> 	;cbw
  3647 0000230D 30E4                <1> 	xor	ah, ah ; 09/12/2017
  3648 0000230F B108                <1> 	mov	cl, 8
  3649 00002311 F6F1                <1> 	div	cl
  3650 00002313 28E1                <1> 	sub	cl, ah
  3651                              <1> ts:
  3652                              <1> 	; 02/09/2014
  3653                              <1> 	; 01/09/2014
  3654                              <1> 	;mov	al, 20h
  3655                              <1> tsloop:
  3656                              <1> 	;push	cx
  3657                              <1> 	; 12/04/2021
  3658 00002315 51                  <1> 	push	ecx ; *
  3659                              <1> 	; 18/11/2020
  3660                              <1> 	;push	ax
  3661                              <1> 	;;mov	bh, [ACTIVE_PAGE]
  3662                              <1> 	; 05/12/2020
  3663                              <1> 	;push	bx
  3664 00002316 B020                <1> 	mov	al, 20h ; al = space (blank) 
  3665                              <1> 			; bl = color/attribute
  3666 00002318 E88BFFFFFF          <1> 	call	_write_tty_m3 ; 24/06/2016 (m3 -> _write_tty_m3)
  3667                              <1> 	; 05/12/2020
  3668                              <1> 	; bx is preserved in '_write_tty_m3'
  3669                              <1> 	; 18/11/2020
  3670                              <1> 	;pop	bx  ; BL = color/attribute, Bh = video page 
  3671                              <1> 	;pop	ax  ; AL = character
  3672                              <1> 	; 12/04/2021
  3673                              <1> 	;pop	cx
  3674 0000231D 59                  <1> 	pop	ecx ; *
  3675 0000231E FEC9                <1> 	dec	cl
  3676 00002320 75F3                <1> 	jnz	short tsloop
  3677 00002322 C3                  <1> 	retn
  3678                              <1> bs:	
  3679                              <1> 	; back space found
  3680                              <1> 
  3681 00002323 08D2                <1> 	or	dl, dl 		; is it already at start of line
  3682                              <1> 	;je	short u7 	; set_cursor
  3683 00002325 7406                <1> 	jz	short _set_cpos
  3684                              <1> 	;dec	dx     		; no -- just move it back
  3685                              <1> 	; 17/04/2021
  3686 00002327 FECA                <1> 	dec	dl		; move to 1 column back
  3687                              <1> 	;jmp	short u7
  3688 00002329 EB02                <1> 	jmp	short _set_cpos
  3689                              <1> 
  3690                              <1> 	; carriage return found
  3691                              <1> u9:
  3692 0000232B B200                <1> 	mov	dl, 0 		; move to first column
  3693                              <1> 	;jmp	short u7
  3694                              <1> 	;jmp	short _set_cpos ; 30/01/2016
  3695                              <1> 
  3696                              <1> 	; line feed found
  3697                              <1> ;u10:
  3698                              <1> ;	cmp	dh, 25-1 	; bottom of screen
  3699                              <1> ;	jne	short u6 	; no, just set the cursor
  3700                              <1> ;       jmp     u1              ; yes, scroll the screen
  3701                              <1> 
  3702                              <1> _set_cpos:
  3703                              <1> 	; 02/08/2022 - TRDOS 386 v2.0.5
  3704                              <1> 	; 17/04/2021 - TRDOS 386 v2.0.4
  3705                              <1> 	; 12/05/2016 - TRDOS 386 (TRDOS v2.0)
  3706                              <1> 	; 27/06/2015
  3707                              <1> 	; 01/09/2014
  3708                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  3709                              <1> 	;
  3710                              <1> 	; 04/12/2013 - 12/12/2013 (Retro UNIX 8086 v1) 
  3711                              <1> 	;
  3712                              <1> 	; VIDEO.ASM - 06/10/85  VIDEO DISPLAY BIOS
  3713                              <1> 	;
  3714                              <1> ;----------------------------------------------
  3715                              <1> ; SET_CPOS
  3716                              <1> ;	THIS ROUTINE SETS THE CURRENT CURSOR POSITION TO THE
  3717                              <1> ;	NEW X-Y VALUES PASSED
  3718                              <1> ; INPUT
  3719                              <1> ;	DX - ROW,COLUMN OF NEW CURSOR
  3720                              <1> ;	BH - DISPLAY PAGE OF CURSOR
  3721                              <1> ; OUTPUT
  3722                              <1> ;	CURSOR ID SET AT 6845 IF DISPLAY PAGE IS CURRENT DISPLAY
  3723                              <1> ;----------------------------------------------
  3724                              <1> 	;
  3725 0000232D BE[DE7C0100]        <1> 	mov	esi, CURSOR_POSN
  3726 00002332 0FB6C7              <1>         movzx   eax, bh	; BH = video page number
  3727                              <1> ;	or	al, al
  3728                              <1> ;	jz	short _set_cpos_0
  3729 00002335 D0E0                <1>         shl     al, 1   ; word offset
  3730 00002337 01C6                <1>         add     esi, eax
  3731                              <1> ;_set_cpos_0:
  3732 00002339 668916              <1> 	mov	[esi], dx ; save the pointer
  3733 0000233C 383D[EE7C0100]      <1> 	cmp	[ACTIVE_PAGE], bh
  3734 00002342 7532                <1> 	jne	short m17
  3735                              <1> 	;call	m18	; CURSOR SET
  3736                              <1> ;m17:			; SET_CPOS_RETURN
  3737                              <1> 	; 01/09/2014
  3738                              <1> ;	retn
  3739                              <1> 		; DX = row/column
  3740                              <1> m18:
  3741 00002344 E852FCFFFF          <1> 	call	position ; determine location in regen buffer	
  3742 00002349 668B0D[DC7C0100]    <1> 	mov	cx, [CRT_START]
  3743 00002350 6601C1              <1> 	add	cx, ax  ; add char position in regen buffer
  3744                              <1> 			; to the start address (offset) for this page
  3745 00002353 66D1E9              <1> 	shr	cx, 1	; divide by 2 for char only count
  3746 00002356 B40E                <1> 	mov	ah, 14	; register number for cursor
  3747                              <1> 	;call	m16	; output value to the 6845	
  3748                              <1> 	;retn
  3749                              <1> 
  3750                              <1> 	;-----	THIS ROUTINE OUTPUTS THE CX REGISTER
  3751                              <1> 	;	TO THE 6845 REGISTERS NAMED IN (AH)
  3752                              <1> m16:
  3753 00002358 FA                  <1> 	cli
  3754                              <1> 	;mov	dx, [addr_6845] ; address register
  3755 00002359 66BAD403            <1> 	mov 	dx, 03D4h ; I/O address of color card
  3756 0000235D 88E0                <1> 	mov	al, ah	; get value
  3757 0000235F EE                  <1> 	out	dx, al	; register set
  3758                              <1> 	;inc	dx	; data register
  3759                              <1> 	; 17/04/2021
  3760 00002360 FEC2                <1> 	inc	dl
  3761 00002362 EB00                <1> 	jmp	$+2	; i/o delay
  3762 00002364 88E8                <1> 	mov	al, ch	; data
  3763 00002366 EE                  <1> 	out	dx, al	
  3764                              <1> 	;dec	dx	
  3765                              <1> 	; 17/04/2021
  3766 00002367 FECA                <1> 	dec	dl
  3767 00002369 88E0                <1> 	mov	al, ah
  3768 0000236B FEC0                <1> 	inc	al	; point to other data register
  3769 0000236D EE                  <1> 	out	dx, al	; set for second register
  3770                              <1> 	;inc	dx
  3771                              <1> 	; 17/04/2021
  3772 0000236E FEC2                <1> 	inc	dl
  3773 00002370 EB00                <1> 	jmp	$+2	; i/o delay
  3774 00002372 88C8                <1> 	mov	al, cl	; second data value
  3775 00002374 EE                  <1> 	out	dx, al
  3776 00002375 FB                  <1> 	sti
  3777                              <1> m17:
  3778 00002376 C3                  <1> 	retn
  3779                              <1> 
  3780                              <1> _beep:
  3781                              <1> 	; 12/02/2021 (TRDOS v2.0.3)
  3782 00002377 FA                  <1> 	cli
  3783 00002378 E811000000          <1> 	call	beep
  3784 0000237D FB                  <1> 	sti
  3785 0000237E C3                  <1> 	retn
  3786                              <1> 
  3787                              <1> beeper: 
  3788                              <1> 	; 04/08/2016
  3789                              <1> 	; 12/05/2016 - TRDOS 386 (TRDOS v2.0)
  3790                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  3791                              <1> 	; 18/01/2014
  3792                              <1> 	; 03/12/2013
  3793                              <1> 	; bell found
  3794                              <1> u11:
  3795 0000237F FB                  <1> 	sti
  3796 00002380 3A3D[EE7C0100]      <1> 	cmp	bh, [ACTIVE_PAGE]
  3797 00002386 7552                <1> 	jne	short u12	; Do not sound the beep 
  3798                              <1> 				; if it is not written on the active page
  3799                              <1> beeper_gfx: ; 04/08/2016
  3800 00002388 66B93305            <1> 	mov	cx, 1331 	; divisor for 896 hz tone
  3801 0000238C B31F                <1> 	mov	bl, 31		; set count for 31/64 second for beep
  3802                              <1> 	;call	beep		; sound the pod bell
  3803                              <1> 	;jmp	short u5 	; tty_return
  3804                              <1> 	;retn
  3805                              <1> 	
  3806                              <1> TIMER	equ 	040h   		; 8254 TIMER - BASE ADDRESS
  3807                              <1> PORT_B	equ	061h		; PORT B READ/WRITE DIAGNOSTIC REGISTER
  3808                              <1> GATE2	equ	00000001b	; TIMER 2 INPUT CATE CLOCK BIT
  3809                              <1> SPK2	equ	00000010b	; SPEAKER OUTPUT DATA ENABLE BIT
  3810                              <1> 
  3811                              <1> beep:
  3812                              <1> 	; 12/02/2021
  3813                              <1> 	; 07/02/2015
  3814                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  3815                              <1> 	; 18/01/2014
  3816                              <1> 	; 03/12/2013
  3817                              <1> 	;
  3818                              <1> 	; TEST4.ASM - 06/10/85  POST AND BIOS UTILITY ROUTINES
  3819                              <1> 	;
  3820                              <1> 	; ROUTINE TO SOUND THE BEEPER USING TIMER 2 FOR TONE
  3821                              <1> 	;
  3822                              <1> 	; ENTRY:
  3823                              <1> 	;    (BL) = DURATION COUNTER ( 1 FOR 1/64 SECOND )
  3824                              <1> 	;    (CX) = FREQUENCY DIVISOR (1193180/FREQUENCY) (1331 FOR 886 HZ)
  3825                              <1> 	; EXIT:				:
  3826                              <1> 	;    (AX),(BL),(CX) MODIFIED.
  3827                              <1> 
  3828 0000238E 9C                  <1> 	pushfd  ; 18/01/2014	; save interrupt status
  3829 0000238F FA                  <1> 	cli			; block interrupts during update
  3830 00002390 B0B6                <1> 	mov	al, 10110110b	; select timer 2, lsb, msb binary
  3831 00002392 E643                <1> 	out	TIMER+3, al 	; write timer mode register
  3832 00002394 EB00                <1> 	jmp	$+2		; I/O delay
  3833 00002396 88C8                <1> 	mov	al, cl		; divisor for hz (low)
  3834 00002398 E642                <1> 	out	TIMER+2,AL	; write timer 2 count - lsb
  3835 0000239A EB00                <1> 	jmp	$+2		; I/O delay
  3836 0000239C 88E8                <1> 	mov	al, ch		; divisor for hz (high)
  3837 0000239E E642                <1> 	out	TIMER+2, al	; write timer 2 count - msb
  3838 000023A0 E461                <1> 	in	al, PORT_B	; get current setting of port
  3839 000023A2 88C4                <1> 	mov	ah, al		; save that setting
  3840 000023A4 0C03                <1> 	or	al, GATE2+SPK2	; gate timer 2 and turn speaker on
  3841 000023A6 E661                <1> 	out	PORT_B, al	; and restore interrupt status
  3842                              <1> 	; 12/02/2021
  3843 000023A8 9D                  <1> 	popfd	; 18/01/2014
  3844                              <1> 	;sti
  3845                              <1> g7:				; 1/64 second per count (bl)
  3846 000023A9 B90B040000          <1> 	mov	ecx, 1035	; delay count for 1/64 of a second
  3847 000023AE E828000000          <1> 	call	waitf		; go to beep delay 1/64 count
  3848 000023B3 FECB                <1> 	dec	bl		; (bl) length count expired?
  3849 000023B5 75F2                <1> 	jnz	short g7	; no - continue beeping speaker
  3850                              <1> 	;
  3851 000023B7 9C                  <1> 	pushfd	; 12/02/2021	; save interrupt status
  3852 000023B8 FA                  <1> 	cli  	; 18/01/2014	; block interrupts during update
  3853 000023B9 E461                <1> 	in	al, PORT_B	; get current port value
  3854                              <1>         ;or	al, not (GATE2+SPK2) ; isolate current speaker bits in case
  3855 000023BB 0CFC                <1>         or      al, ~(GATE2+SPK2)
  3856 000023BD 20C4                <1>         and	ah, al		; someone turned them off during beep
  3857 000023BF 88E0                <1> 	mov	al, ah		; recover value of port
  3858                              <1>         ;or	al, not (GATE2+SPK2) ; force speaker data off
  3859 000023C1 0CFC                <1> 	or 	al, ~(GATE2+SPK2) ; isolate current speaker bits in case
  3860 000023C3 E661                <1> 	out	PORT_B, al	; and stop speaker timer
  3861 000023C5 9D                  <1> 	popfd	; 12/02/2021		; restore interrupt flag state
  3862                              <1> 	;sti
  3863                              <1> 	;mov	ecx, 1035	; force 1/64 second delay (short)
  3864                              <1> 	; 17/04/2021
  3865 000023C6 66B90B04            <1> 	mov	cx, 1035
  3866 000023CA E80C000000          <1> 	call	waitf		; minimum delay between all beeps
  3867 000023CF 9C                  <1> 	pushfd			; save interrupt status
  3868 000023D0 FA                  <1> 	cli			; block interrupts during update
  3869 000023D1 E461                <1> 	in	al, PORT_B	; get current port value in case
  3870 000023D3 2403                <1> 	and	al, GATE2+SPK2	; someone turned them on
  3871 000023D5 08E0                <1> 	or	al, ah		; recover value of port_b
  3872 000023D7 E661                <1> 	out	PORT_B, al	; restore speaker status
  3873 000023D9 9D                  <1> 	popfd			; restore interrupt flag state
  3874                              <1> u12:	
  3875 000023DA C3                  <1> 	retn
  3876                              <1> 
  3877                              <1> REFRESH_BIT equ	00010000b 	; REFRESH TEST BIT
  3878                              <1> 
  3879                              <1> WAITF:
  3880                              <1> waitf:
  3881                              <1> 	; 30/08/2014 (Retro UNIX 386 v1)
  3882                              <1> 	; 03/12/2013
  3883                              <1> 	;
  3884                              <1> ;	push	ax		; save work register (ah)
  3885                              <1> ;waitf1:
  3886                              <1> 				; use timer 1 output bits
  3887                              <1> ;	in	al, PORT_B	; read current counter output status
  3888                              <1> ;	and	al, REFRESH_BIT	; mask for refresh determine bit
  3889                              <1> ;	cmp	al, ah		; did it just change
  3890                              <1> ;	je	short waitf1	; wait for a change in output line
  3891                              <1> ;	;
  3892                              <1> ;	mov	ah, al		; save new lflag state
  3893                              <1> ;	loop	waitf1		; decrement half cycles till count end
  3894                              <1> ;	;
  3895                              <1> ;	pop	ax		; restore (ah)
  3896                              <1> ;	retn			; return (cx)=0
  3897                              <1> 
  3898                              <1> ; 06/02/2015 (unix386.s <-- dsectrm2.s)
  3899                              <1> ; 17/12/2014 (dsectrm2.s)
  3900                              <1> ; WAITF
  3901                              <1> ; /// IBM PC-XT Model 286 System BIOS Source Code - Test 4 - 06/10/85 ///
  3902                              <1> ;
  3903                              <1> ;---WAITF-----------------------------------------------------------------------
  3904                              <1> ;	FIXED TIME WAIT ROUTINE (HARDWARE CONTROLLED - NOT PROCESSOR)
  3905                              <1> ; ENTRY:
  3906                              <1> ;	(CX) =	COUNT OF 15.085737 MICROSECOND INTERVALS TO WAIT
  3907                              <1> ;	      	MEMORY REFRESH TIMER 1 OUTPUT USED AS REFERENCE
  3908                              <1> ; EXIT:
  3909                              <1> ;	       	AFTER (CX) TIME COUNT (PLUS OR MINUS 16 MICROSECONDS)
  3910                              <1> ;	(CX) = 0	
  3911                              <1> ;-------------------------------------------------------------------------------
  3912                              <1> 
  3913                              <1> ; Refresh period: 30 micro seconds (15-80 us)
  3914                              <1> ; (16/12/2014 - AWARDBIOS 1999 - ATORGS.ASM, WAIT_REFRESH)
  3915                              <1> 
  3916                              <1> ;WAITF:					; DELAY FOR (CX)*15.085737 US
  3917                              <1> 	;push	AX			; SAVE WORK REGISTER (AH)
  3918                              <1> 	; 11/04/2021
  3919 000023DB 50                  <1> 	push	eax
  3920                              <1> 	; 16/12/2014
  3921                              <1> 	;shr	cx, 1			; convert to count of 30 micro seconds
  3922 000023DC D1E9                <1> 	shr	ecx, 1	; 21/02/2015
  3923                              <1> ;17/12/2014	
  3924                              <1> ;WAITF1:
  3925                              <1> ;	in	al, PORT_B   ;061h	; READ CURRENT COUNTER OUTPUT STATUS
  3926                              <1> ;	and	al, REFRESH_BIT	;00010000b ; MASK FOR REFRESH DETERMINE BIT
  3927                              <1> ;	cmp	al, ah			; DID IT JUST CHANGE
  3928                              <1> ;	je	short WAITF1		; WAIT FOR A CHANGE IN OUTPUT LINE
  3929                              <1> ;	mov	ah, al			; SAVE NEW FLAG STATE
  3930                              <1> ;	loop	WAITF1			; DECREMENT HALF CYCLES TILL COUNT END		
  3931                              <1> 	;
  3932                              <1> 	; 17/12/2014
  3933                              <1> 	;
  3934                              <1> 	; Modification from 'WAIT_REFRESH' procedure of AWARD BIOS - 1999
  3935                              <1> 	;
  3936                              <1> ;WAIT_REFRESH:  Uses port 61, bit 4 to have CPU speed independent waiting.
  3937                              <1> ;   	INPUT:  CX = number of refresh periods to wait
  3938                              <1> ;     	       (refresh periods = 1 per 30 microseconds on most machines)
  3939                              <1> WR_STATE_0:
  3940 000023DE E461                <1> 	in	al, PORT_B		; IN AL,SYS1
  3941 000023E0 A810                <1> 	test	al, 010h
  3942 000023E2 74FA                <1> 	JZ	short WR_STATE_0
  3943                              <1> WR_STATE_1:
  3944 000023E4 E461                <1> 	in	al, PORT_B		; IN AL,SYS1
  3945 000023E6 A810                <1> 	test	al, 010h
  3946 000023E8 75FA                <1> 	jnz	short WR_STATE_1
  3947 000023EA E2F2                <1>         loop    WR_STATE_0
  3948                              <1> 	;
  3949                              <1> 	;pop	ax			; RESTORE (AH)
  3950                              <1> 	; 11/04/2021
  3951 000023EC 58                  <1> 	pop	eax
  3952 000023ED C3                  <1> 	retn				; (CX) = 0
  3953                              <1> 
  3954                              <1> ; 03/08/2022
  3955                              <1> ; 02/08/2022 - TRDOS 386 Kernel v2.0.5
  3956                              <1> ; 09/07/2016
  3957                              <1> ; 01/07/2016
  3958                              <1> ; 24/06/2016
  3959                              <1> ; 23/06/2016 - TRDOS 386 (TRDOS v2.0)
  3960                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  3961                              <1> ;-------------------------------------------------------------------------------
  3962                              <1> ; WRITE_STRING								       :
  3963                              <1> ;	THIS ROUTINE WRITES A STRING OF CHARACTERS TO THE CRT.		       :
  3964                              <1> ; INPUT 								       :
  3965                              <1> ;	(AL) = WRITE STRING COMMAND  0 - 3				       :
  3966                              <1> ;	(BH) = DISPLAY PAGE (ACTIVE PAGE)				       :
  3967                              <1> ;	(CX) = COUNT OF CHARACTERS TO WRITE, IF (CX) = 0 THEN RETURN	       :
  3968                              <1> ;	(DX) = CURSOR POSITION FOR START OF STRING WRITE		       :
  3969                              <1> ;	(BL) = ATTRIBUTE OF CHARACTER TO WRITE IF (AL) = 0  OR	(AL) = 1       :
  3970                              <1> ;	(EBP) = SOURCE STRING OFFSET					       :
  3971                              <1> ; OUTPUT								       :
  3972                              <1> ;	NONE								       :
  3973                              <1> ;-------------------------------------------------------------------------------
  3974                              <1> 
  3975                              <1> ; AL = 00h: Assign all characters the attribute in BL; do not update cursor
  3976                              <1> ; AL = 01h: Assign all characters the attribute in BL; update cursor
  3977                              <1> ; AL = 02h: Use attributes in string; do not update cursor
  3978                              <1> ; AL = 03h: Use attributes in string; update cursor
  3979                              <1> 
  3980                              <1> WRITE_STRING:
  3981                              <1> 	; 03/08/2022
  3982                              <1> 	; 02/08/2022
  3983                              <1> 	; 12/09/2016
  3984                              <1> 	; 09/07/2016
  3985                              <1> 	;cmp	byte [CRT_MODE], 7 ; 6?!
  3986                              <1> 	;ja	VIDEO_RETURN		; not a valid function for VGA modes
  3987                              <1> 	;
  3988 000023EE A2[50890100]        <1> 	mov	[w_str_cmd], al		; save (AL) command
  3989 000023F3 3C04                <1> 	cmp	al, 4			; TEST FOR INVALID WRITE STRING OPTION
  3990                              <1> 	;jnb	VIDEO_RETURN		; IF OPTION INVALID THEN RETURN
  3991                              <1> 	; 02/08/2022
  3992 000023F5 7361                <1> 	jnb	short P55
  3993                              <1> 
  3994                              <1>         ;jcxz	VIDEO_RETURN		; IF ZERO LENGTH STRING THEN RETURN
  3995                              <1> 
  3996 000023F7 67E35E              <1>         jcxz    P55			; 01/07/2016
  3997                              <1> 
  3998                              <1> 	; 01/07/2016
  3999                              <1> 	;and	ecx, 0FFFFh
  4000                              <1> 	; ecx = byte count
  4001                              <1> 	;push	ecx
  4002 000023FA 89EE                <1> 	mov	esi, ebp ; user buffer
  4003 000023FC BF00000700          <1> 	mov	edi, Cluster_Buffer  ; system buffer
  4004 00002401 E8D4EB0000          <1> 	call	transfer_from_user_buffer
  4005                              <1> 	;pop	ecx
  4006                              <1> 	;jc	VIDEO_RETURN
  4007                              <1> 	; 02/08/2022
  4008 00002406 7250                <1> 	jc	short P55
  4009                              <1> 	; ecx = transfer (byte) count = character count
  4010 00002408 BD00000700          <1> 	mov	ebp, Cluster_Buffer
  4011                              <1> 	; 12/09/2016
  4012 0000240D 803D[DE670000]07    <1> 	cmp	byte [CRT_MODE], 7 ; 6?!
  4013                              <1> 	;ja	vga_write_string
  4014                              <1> 	; 02/08/2022
  4015 00002414 7605                <1> 	jna	short P57
  4016 00002416 E99C000000          <1> 	jmp	vga_write_string
  4017                              <1> P57:
  4018 0000241B 0FB6F7              <1> 	movzx	esi, bh			; GET CURRENT CURSOR PAGE
  4019                              <1> 	;sal	si, 1			; CONVERT TO PAGE OFFSET (SI = PAGE)
  4020                              <1> 	; 02/08/2022
  4021 0000241E D1E6                <1> 	sal	esi, 1
  4022                              <1> 	; *****
  4023 00002420 66FFB6[DE7C0100]    <1> 	push	word [esi+CURSOR_POSN]	; SAVE CURRENT CURSOR POSITION IN STACK
  4024                              <1> 
  4025                              <1> 	;mov	ax, 0200h		; SET NEW CURSOR POSITION
  4026                              <1> 	;int	10h
  4027                              <1> P50next:	
  4028 00002427 51                  <1> 	push	ecx ; ****
  4029 00002428 53                  <1> 	push	ebx ; *** ; 18/11/2020
  4030 00002429 56                  <1> 	push	esi ; **
  4031 0000242A 52                  <1> 	push	edx ; *
  4032 0000242B E8FDFEFFFF          <1> 	call	_set_cpos
  4033                              <1> P50:
  4034 00002430 8A4500              <1> 	mov	al, [ebp]		; GET CHARACTER FROM INPUT STRING
  4035 00002433 45                  <1> 	inc	ebp			; BUMP POINTER TO CHARACTER
  4036                              <1> 
  4037                              <1> ;-----	TEST FOR SPECIAL CHARACTER'S
  4038                              <1> 
  4039 00002434 3C08                <1> 	cmp	al, 08h			; IS IT A BACKSPACE
  4040 00002436 7410                <1> 	je	short P51		; BACK_SPACE
  4041 00002438 3C0D                <1> 	cmp	al, 0Dh ; CR		; IS IT CARRIAGE RETURN
  4042 0000243A 740C                <1> 	je	short P51		; CAR_RET
  4043 0000243C 3C0A                <1> 	cmp	al, 0Ah ; LF		; IS IT A LINE FEED
  4044 0000243E 7408                <1> 	je	short P51		; LINE_FEED
  4045                              <1> 	; 18/11/2020
  4046 00002440 3C09                <1> 	cmp	al, 09h			; is it a tab stop
  4047 00002442 7404                <1> 	je	short P51
  4048                              <1> 	;
  4049 00002444 3C07                <1> 	cmp	al, 07h			; IS IT A BELL
  4050 00002446 7515                <1> 	jne	short P52		; IF NOT THEN DO WRITE CHARACTER
  4051                              <1> P51:
  4052                              <1> 	;mov	ah, 0Eh			; TTY_CHARACTER_WRITE
  4053                              <1> 	;int	10h			; WRITE TTY CHARACTER TO THE CRT
  4054                              <1> 	
  4055 00002448 E85BFEFFFF          <1> 	call	_write_tty_m3
  4056                              <1> 
  4057 0000244D 5A                  <1> 	pop	edx ; *
  4058 0000244E 5E                  <1> 	pop	esi ; **
  4059                              <1> 
  4060 0000244F 668B96[DE7C0100]    <1> 	mov	dx, [esi+CURSOR_POSN]	; GET CURRENT CURSOR POSITION
  4061 00002456 EB44                <1> 	jmp	short P54		; SET CURSOR POSITION AND CONTINUE
  4062                              <1> P55:
  4063 00002458 E9D5F6FFFF          <1> 	jmp	VIDEO_RETURN
  4064                              <1> P52:
  4065                              <1> 	;mov	cx, 1			; SET CHARACTER WRITE AMOUNT TO ONE
  4066                              <1> 	; 02/08/2022
  4067 0000245D 29C9                <1> 	sub	ecx, ecx
  4068 0000245F FEC1                <1> 	inc	cl
  4069                              <1> 	; ecx = 1
  4070 00002461 803D[50890100]02    <1> 	cmp	byte [w_str_cmd], 2	; IS THE ATTRIBUTE IN THE STRING
  4071 00002468 7204                <1> 	jb	short P53		; IF NOT THEN SKIP
  4072 0000246A 8A5D00              <1> 	mov	bl, [ebp]		; ELSE GET NEW ATTRIBUTE
  4073 0000246D 45                  <1> 	inc	ebp			; BUMP STRING POINTER
  4074                              <1> P53:
  4075                              <1> 	;mov	ah, 09h			; GOT_CHARACTER
  4076                              <1> 	;int	10h			; WRITE CHARACTER TO THE CRT
  4077                              <1> 
  4078 0000246E E8A1FDFFFF          <1> 	call	_write_c_current
  4079                              <1> 	
  4080 00002473 5A                  <1> 	pop	edx ; *	
  4081                              <1> 
  4082                              <1> 	; 05/12/2020
  4083                              <1> 	; bx is preserved in '_write_c_current'
  4084                              <1> 	; 18/11/2020
  4085                              <1> 	;mov	ebx, [esp+4]	; ***
  4086                              <1> 
  4087 00002474 0FB6F7              <1> 	movzx	esi, bh ; video page number (0 to 7)	
  4088 00002477 889E[E7670000]      <1> 	mov	[esi+chr_attrib], bl ; color/attribute
  4089                              <1> 
  4090 0000247D FEC2                <1> 	inc	dl			; INCREMENT COLUMN COUNTER
  4091 0000247F 3A15[E0670000]      <1> 	cmp	dl, [CRT_COLS]		; IF COLS ARE WITHIN RANGE FOR THIS MODE
  4092                              <1> 	;jb	short P54		;    THEN GO TO COLUMNS SET
  4093 00002485 7214                <1> 	jb	short P56 ; 05/12/2020
  4094 00002487 FEC6                <1> 	inc	dh			; BUMP ROW COUNTER BY ONE
  4095 00002489 28D2                <1> 	sub	dl, dl			; SET COLUMN COUNTER TO ZERO
  4096 0000248B 80FE19              <1> 	cmp	dh, 25			; IF ROWS ARE LESS THAN 25 THEN
  4097                              <1> 	;jb	short P54		; GO TO ROWS_COLUMNS_SET
  4098 0000248E 720B                <1> 	jb	short P56 ; 05/12/2020
  4099                              <1> 
  4100                              <1> 	; 18/11/2020
  4101                              <1> 	;mov	ax, 0E0Ah		; ELSE SCROLL SCREEN
  4102                              <1> 	;int	10h			; RESET ROW COUNTER TO 24
  4103                              <1> 
  4104                              <1> 	; 18/11/2020
  4105 00002490 B00A                <1> 	mov	al, 0Ah	; line feed
  4106                              <1> 
  4107 00002492 E811FEFFFF          <1> 	call	_write_tty_m3
  4108                              <1> 	
  4109 00002497 66BA0018            <1> 	mov	dx, 1800h		; Column = 0, Row = 24
  4110                              <1> P56:	
  4111                              <1> 	; 05/12/2020
  4112                              <1> 	; 18/11/2020
  4113 0000249B 5E                  <1> 	pop	esi ; **
  4114                              <1> P54:					; ROW_COLUMNS_SET
  4115                              <1> 	;mov	ax, 0200h		; SET NEW CURSOR POSITION COMMAND
  4116                              <1> 	;int	10h			; ESTABLISH NEW CURSOR POSITION
  4117                              <1> 
  4118                              <1> 	; 18/11/2020
  4119 0000249C 5B                  <1> 	pop	ebx ; ***
  4120 0000249D 59                  <1> 	pop	ecx ; ****
  4121                              <1> 
  4122                              <1> 	;loop	P50			; DO IT ONCE MORE UNTIL (CX) = ZERO
  4123 0000249E 6649                <1> 	dec	cx
  4124 000024A0 7585                <1> 	jnz	short P50next
  4125                              <1> 
  4126 000024A2 665A                <1> 	pop	dx  ; *****		; RESTORE OLD CURSOR COORDINATES
  4127                              <1> 	
  4128 000024A4 F605[50890100]01    <1> 	test	byte [w_str_cmd], 1	; IF CURSOR WAS NOT TO BE MOVED
  4129                              <1> 	;jnz	VIDEO_RETURN		; THEN EXIT WITHOUT RESETTING OLD VALUE
  4130                              <1> 	; 03/08/2022
  4131 000024AB 7505                <1> 	jnz	short P58
  4132                              <1> 	
  4133                              <1> 	;mov	ax, 0200h		; ELSE RESTORE OLD CURSOR POSITION
  4134                              <1> 	;int	10h
  4135                              <1> 					; DONE - EXIT WRITE STRING
  4136 000024AD E87BFEFFFF          <1> 	call	_set_cpos
  4137                              <1> P58:
  4138 000024B2 E97BF6FFFF          <1> 	jmp	VIDEO_RETURN		; RETURN TO CALLER
  4139                              <1> 
  4140                              <1> vga_write_string:
  4141                              <1> 	; 04/08/2022 - TRDOS 386 Kernel v2.0.5
  4142                              <1> 	; 12/09/2016 - TRDOS 386 (TRDOS v2.0)
  4143                              <1> 	;
  4144                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4145                              <1> 	; vgabios-0.7a (2011)
  4146                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4147                              <1> 	; 'vgabios.c', ' biosfn_write_string'
  4148                              <1> 
  4149                              <1> 	; INPUT 								  :
  4150                              <1> 	;	(AL) = WRITE STRING COMMAND  0 - 3				  :
  4151                              <1> 	;	(BH) = DISPLAY PAGE (ACTIVE PAGE)				  :
  4152                              <1> 	;	(CX) = COUNT OF CHARACTERS TO WRITE, IF (CX) = 0 THEN RETURN	  :
  4153                              <1> 	;	(DX) = CURSOR POSITION FOR START OF STRING WRITE		  :
  4154                              <1> 	;	(BL) = ATTRIBUTE OF CHARACTER TO WRITE IF (AL) = 0  OR	(AL) = 1  :
  4155                              <1> 	;	(EBP) = SOURCE STRING OFFSET					  :
  4156                              <1> 	; OUTPUT								  :
  4157                              <1> 	;	NONE								  :
  4158                              <1> 	;-------------------------------------------------------------------------;
  4159                              <1> 
  4160                              <1> 	; AL = 00h: Assign all characters the attribute in BL; do not update cursor
  4161                              <1> 	; AL = 01h: Assign all characters the attribute in BL; update cursor
  4162                              <1> 	; AL = 02h: Use attributes in string; do not update cursor
  4163                              <1> 	; AL = 03h: Use attributes in string; update cursor
  4164                              <1> 	
  4165                              <1> 	; biosfn_write_string(GET_AL(),GET_BH(),GET_BL(),CX,GET_DH(),GET_DL(),ES,BP);
  4166                              <1> 	; static void biosfn_write_string (flag,page,attr,count,row,col,seg,offset) 
  4167                              <1> 
  4168                              <1> 	; // Read curs info for the page
  4169                              <1>  	; biosfn_get_cursor_pos(page,&dummy,&oldcurs);
  4170                              <1> 	; bh = video page = 0
  4171                              <1> 	;movzx	esi, word [CURSOR_POSN] ; current cursor position for video page 0
  4172                              <1> 	
  4173                              <1> 	; // if row=0xff special case : use current cursor position
  4174                              <1> 	; if(row==0xff)
  4175                              <1> 	;  {col=oldcurs&0x00ff;
  4176                              <1> 	;   row=(oldcurs&0xff00)>>8;
  4177                              <1> 	;  }
  4178                              <1> 
  4179                              <1> 	;mov	al, [w_str_cmd]
  4180                              <1> 
  4181 000024B7 80FEFF              <1> 	cmp	dh, 0FFh
  4182 000024BA 7407                <1> 	je	short vga_wstr_1 ; user current cursor position
  4183                              <1> vga_wstr_0:
  4184                              <1> 	; set cursor position
  4185 000024BC 668915[DE7C0100]    <1> 	mov	[CURSOR_POSN], dx ; save cursor pos for pg 0
  4186                              <1> vga_wstr_1:
  4187 000024C3 66FF35[DE7C0100]    <1> 	push	word [CURSOR_POSN] ; *
  4188                              <1> 
  4189                              <1> 	; ebp = string offset in system buffer (user buffer was copied to)
  4190                              <1> 	
  4191                              <1> 	; while(count--!=0)
  4192                              <1> 	;  {
  4193                              <1> 	;   car=read_byte(seg,offset++);
  4194                              <1> 	;   if((flag&0x02)!=0)
  4195                              <1> 	;    attr=read_byte(seg,offset++);
  4196                              <1> 	;    biosfn_write_teletype(car,page,attr,WITH_ATTR);
  4197                              <1> 	;  }
  4198                              <1> 
  4199                              <1> 	;push	eax ; **
  4200                              <1> 	;test	al, 2
  4201 000024CA F605[50890100]02    <1> 	test	byte [w_str_cmd], 2
  4202 000024D1 751D                <1> 	jnz	short vga_wstr_3
  4203 000024D3 881D[EF7C0100]      <1> 	mov	[ccolor], bl
  4204                              <1> vga_wstr_2:
  4205 000024D9 51                  <1> 	push	ecx
  4206 000024DA 8A4500              <1> 	mov	al, [ebp]
  4207 000024DD E88F0A0000          <1> 	call	vga_write_teletype
  4208 000024E2 59                  <1> 	pop	ecx
  4209 000024E3 6649                <1> 	dec	cx
  4210 000024E5 741E                <1> 	jz	short vga_wstr_4
  4211 000024E7 45                  <1> 	inc	ebp
  4212 000024E8 8A1D[EF7C0100]      <1> 	mov	bl, [ccolor]
  4213 000024EE EBE9                <1> 	jmp	short vga_wstr_2
  4214                              <1> vga_wstr_3:
  4215 000024F0 51                  <1> 	push	ecx
  4216 000024F1 8A4500              <1> 	mov	al, [ebp]
  4217 000024F4 45                  <1> 	inc	ebp
  4218 000024F5 8A5D00              <1> 	mov	bl, [ebp]
  4219 000024F8 E8740A0000          <1> 	call	vga_write_teletype
  4220 000024FD 59                  <1> 	pop	ecx
  4221 000024FE 6649                <1> 	dec	cx
  4222 00002500 7403                <1> 	jz	short vga_wstr_4
  4223 00002502 45                  <1> 	inc	ebp
  4224 00002503 EBEB                <1> 	jmp	short vga_wstr_3
  4225                              <1> vga_wstr_4:
  4226                              <1> 	; // Set back curs pos 
  4227                              <1> 	; if((flag&0x01)==0)
  4228                              <1> 	;  biosfn_set_cursor_pos(page,oldcurs);
  4229                              <1> 	; }
  4230                              <1> 	;pop	eax ; **
  4231 00002505 665A                <1> 	pop	dx ; word [CURSOR_POSN] ; *
  4232                              <1> 	;test	al, 1
  4233 00002507 F605[50890100]01    <1> 	test	byte [w_str_cmd], 1
  4234                              <1> 	;jnz	VIDEO_RETURN
  4235                              <1> 	; 04/08/2022
  4236 0000250E 7507                <1> 	jnz	short vga_wstr_5
  4237 00002510 668915[DE7C0100]    <1> 	mov 	[CURSOR_POSN], dx
  4238                              <1> vga_wstr_5:
  4239 00002517 E916F6FFFF          <1> 	jmp	VIDEO_RETURN
  4240                              <1> 
  4241                              <1> ; 03/08/2022 - TRDOS 386 Kernel v2.0.5
  4242                              <1> ; 07/07/2016
  4243                              <1> ; 27/06/2016 - TRDOS 386 (TRDOS v2.0)
  4244                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  4245                              <1> ;------------------------------------------------------
  4246                              <1> ;  SCROLL UP
  4247                              <1> ;   THIS ROUTINE SCROLLS UP THE INFORMATION ON THE CRT
  4248                              <1> ; ENTRY ---
  4249                              <1> ;  CH,CL = UPPER LEFT CORNER OF REGION TO SCROLL
  4250                              <1> ;  DH,DL = LOWER RIGHT CORNER OF REGION TO SCROLL
  4251                              <1> ;   BOTH OF THE ABOVE ARE IN CHARACTER POSITIONS
  4252                              <1> ;  BH = FILL VALUE FOR BLANKED LINES
  4253                              <1> ;  AL = # LINES TO SCROLL (AL=0 MEANS BLANK THE ENTIRE FIELD)
  4254                              <1> ;  DS = DATA SEGMENT
  4255                              <1> ;  ES = REGEN SEGMENT
  4256                              <1> ; EXIT --
  4257                              <1> ;  NOTHING, THE SCREEN IS SCROLLED
  4258                              <1> ;--------------------------------------------------------
  4259                              <1> 
  4260                              <1> 	; cl = upper left column
  4261                              <1> 	; ch = upper left row
  4262                              <1> 	; dl = lower rigth column
  4263                              <1> 	; dh = lower right row
  4264                              <1> 	;
  4265                              <1> 	; al = line count (AL=0 means blank entire fields)
  4266                              <1> 	; bl = fill value for blanked lines	
  4267                              <1> 	; bh = unused
  4268                              <1> 
  4269                              <1> GRAPHICS_UP:
  4270                              <1> 	; 07/07/2016
  4271                              <1> 	; AH = Current video mode, [CRT_MODE]
  4272 0000251C 80FC07              <1> 	cmp	ah, 7
  4273 0000251F 7762                <1> 	ja	short vga_graphics_up
  4274                              <1> 	;je	n0
  4275                              <1> 
  4276 00002521 88C7                <1> 	mov	bh, al			; save line count in BH
  4277                              <1> 	;mov	ax, cx			; GET UPPER LEFT POSITION INTO AX REG
  4278                              <1> 	; 03/08/2022
  4279 00002523 89C8                <1> 	mov	eax, ecx
  4280                              <1> 
  4281                              <1> ;-----	USE CHARACTER SUBROUTINE FOR POSITIONING
  4282                              <1> ;-----	ADDRESS RETURNED IS MULTIPLIED BY 2 FROM CORRECT VALUE
  4283                              <1> 
  4284 00002525 E8BA050000          <1> 	call	GRAPH_POSN
  4285                              <1> 	;movzx	edi, ax			; SAVE RESULT AS DESTINATION ADDRESS
  4286                              <1> 	; 03/08/2022
  4287 0000252A 89C7                <1> 	mov	edi, eax
  4288                              <1> 
  4289                              <1> ;-----	DETERMINE SIZE OF WINDOW
  4290                              <1> 
  4291 0000252C 6629CA              <1> 	sub	dx, cx
  4292 0000252F 6681C20101          <1>         add     dx, 101h                ; ADJUST VALUES
  4293 00002534 C0E602              <1> 	sal	dh, 2			; MULTIPLY ROWS BY 4 AT 8 VERT DOTS/CHAR
  4294                              <1> 					; AND EVEN/ODD ROWS
  4295                              <1> ;-----	DETERMINE CRT MODE
  4296                              <1> 
  4297 00002537 803D[DE670000]06    <1> 	cmp	byte [CRT_MODE], 6	; TEST FOR MEDIUM RES
  4298 0000253E 7304                <1>         jnc	short _R7_              ; FIND_SOURCE
  4299                              <1> 
  4300                              <1> ;-----	MEDIUM RES UP
  4301 00002540 D0E2                <1> 	sal	dl, 1			; # COLUMNS * 2, SINCE 2 BYTES/CHAR
  4302                              <1> 	;sal	di, 1			; OFFSET *2 SINCE 2 BYTES/CHAR
  4303                              <1> 	; 03/08/2022
  4304 00002542 D1E7                <1> 	sal	edi, 1
  4305                              <1> 
  4306                              <1> ;-----	DETERMINE THE SOURCE ADDRESS IN THE BUFFER
  4307                              <1> _R7_:                                   ; FIND_SOURCE
  4308 00002544 81C700800B00        <1> 	add	edi, 0B8000h
  4309 0000254A C0E702              <1> 	sal	bh, 2			; multiply number of lines by 4
  4310 0000254D 7430                <1>         jz	short _R11              ; IF ZERO, THEN BLANK ENTIRE FIELD
  4311 0000254F B050                <1> 	mov	al, 80			; 80 BYTES/ROW
  4312 00002551 F6E7                <1> 	mul	bh			; determine offset to source
  4313                              <1> 	;movzx	esi, ax			; offset to source
  4314                              <1> 	; 03/08/2022
  4315 00002553 89C6                <1> 	mov	esi, eax
  4316 00002555 01FE                <1> 	add	esi, edi		; SET UP SOURCE
  4317 00002557 88F4                <1> 	mov	ah, dh			; NUMBER OF ROWS IN FIELD
  4318 00002559 28FC                <1> 	sub	ah, bh			; determine number to move
  4319                              <1> 
  4320                              <1> ;-----	LOOP THROUGH, MOVING ONE ROW AT A TIME, BOTH EVEN AND ODD FIELDS
  4321                              <1> _R8:                                    ; ROW_LOOP
  4322 0000255B E8FD030000          <1>         call    _R17                    ; MOVE ONE ROW
  4323 00002560 6681EEB01F          <1> 	sub	si, 2000h-80		; MOVE TO NEXT ROW
  4324 00002565 6681EFB01F          <1> 	sub	di, 2000h-80
  4325 0000256A FECC                <1> 	dec	ah			; NUMBER OF ROWS TO MOVE
  4326 0000256C 75ED                <1>         jnz     short _R8               ; CONTINUE TILL ALL MOVED
  4327                              <1> 
  4328                              <1> ;-----	FILL IN THE VACATED LINE(S)
  4329                              <1> _R9:                                    ; CLEAR ENTRY
  4330 0000256E 88D8                <1> 	mov	al, bl			; attribute to fill with
  4331                              <1> _R10_:
  4332 00002570 E804040000          <1>         call    _R18                    ; CLEAR THAT ROW
  4333 00002575 6681EFB01F          <1> 	sub	di, 2000h-80		; POINT TO NEXT LINE
  4334 0000257A FECF                <1> 	dec	bh			; number of lines to fill
  4335 0000257C 75F2                <1> 	jnz	short _R10_             ; CLEAR LOOP
  4336 0000257E C3                  <1> 	retn				; EVERYYHING DONE
  4337                              <1> 
  4338                              <1> _R11:                                   ; BLANK_FIELD
  4339 0000257F 88F7                <1> 	mov	bh, dh			; set blank count to everything in field
  4340 00002581 EBEB                <1>         jmp     short _R9               ; CLEAR THE FIELD
  4341                              <1> 
  4342                              <1> vga_graphics_up:
  4343                              <1> 	; 03/08/2022 - TRDOS 386 Kertnel v2.0.5
  4344                              <1> 	; 12/04/2021
  4345                              <1> 	; 08/08/2016
  4346                              <1> 	; 07/08/2016
  4347                              <1> 	; 04/08/2016
  4348                              <1> 	; 01/08/2016
  4349                              <1> 	; 31/07/2016
  4350                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  4351                              <1> 	;
  4352                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4353                              <1> 	; vgabios-0.7a (2011)
  4354                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4355                              <1> 	; 'vgabios.c', 'biosfn_scroll'
  4356                              <1> 	;
  4357                              <1> 
  4358                              <1> 	; cl = upper left column
  4359                              <1> 	; ch = upper left row
  4360                              <1> 	; dl = lower rigth column
  4361                              <1> 	; dh = lower right row
  4362                              <1> 	;
  4363                              <1> 	; al = line count (AL=0 means blank entire fields)
  4364                              <1> 	; bl = fill value for blanked lines	
  4365                              <1> 	; bh = unused
  4366                              <1> 	;
  4367                              <1> 	; ah = [CRT_MODE], current video mode	
  4368                              <1> 
  4369 00002583 88C7                <1> 	mov	bh, al ; 31/07/2016
  4370 00002585 BE[02680000]        <1> 	mov	esi, vga_g_modes
  4371 0000258A 89F7                <1> 	mov	edi, esi
  4372 0000258C 83C708              <1> 	add	edi, vga_g_mode_count
  4373                              <1> vga_g_up_0:
  4374 0000258F AC                  <1> 	lodsb
  4375 00002590 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  4376 00002592 7405                <1> 	je	short vga_g_up_1
  4377 00002594 39FE                <1> 	cmp	esi, edi
  4378 00002596 72F7                <1> 	jb	short vga_g_up_0
  4379                              <1> 	;xor	bh, bh ; 31/07/2016)
  4380 00002598 C3                  <1> 	retn	; nothing to do
  4381                              <1> vga_g_up_1:
  4382 00002599 88F8                <1> 	mov	al, bh ; 31/07/2016
  4383 0000259B 83C64F              <1> 	add	esi, vga_g_memmodel - (vga_g_modes + 1)  
  4384                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  4385                              <1> 	
  4386                              <1> 	; if(rlr>=nbrows)rlr=nbrows-1;
  4387                              <1>  	; if(clr>=nbcols)clr=nbcols-1;
  4388                              <1>  	; if(nblines>nbrows)nblines=0;
  4389                              <1>  	; cols=clr-cul+1;
  4390                              <1> 
  4391 0000259E 3A35[E6670000]      <1> 	cmp	dh, [VGA_ROWS]
  4392 000025A4 7208                <1> 	jb	short vga_g_up_2
  4393 000025A6 8A35[E6670000]      <1> 	mov	dh, [VGA_ROWS]
  4394 000025AC FECE                <1> 	dec	dh
  4395                              <1> vga_g_up_2:
  4396 000025AE 3A15[E0670000]      <1> 	cmp	dl, [CRT_COLS]  ; = [VGA_COLS]
  4397 000025B4 7208                <1> 	jb	short vga_g_up_3
  4398 000025B6 8A15[E0670000]      <1> 	mov	dl, [CRT_COLS]
  4399 000025BC FECA                <1> 	dec	dl
  4400                              <1> vga_g_up_3:	
  4401 000025BE 3A05[E6670000]      <1> 	cmp	al, [VGA_ROWS]
  4402 000025C4 7602                <1> 	jna	short vga_g_up_4
  4403 000025C6 28C0                <1> 	sub	al, al ; 0
  4404                              <1> vga_g_up_4:
  4405 000025C8 88D7                <1> 	mov	bh, dl ; clr
  4406 000025CA 28CF                <1> 	sub	bh, cl ; cul
  4407 000025CC FEC7                <1> 	inc	bh ; cols = clr-cul+1
  4408                              <1> 
  4409 000025CE 20C0                <1> 	and	al, al ; nblines = 0
  4410 000025D0 7559                <1> 	jnz	short vga_g_up_6
  4411 000025D2 20ED                <1> 	and	ch, ch ; rul = 0
  4412 000025D4 7555                <1> 	jnz	short vga_g_up_6
  4413 000025D6 20C9                <1> 	and	cl, cl ; cul = 0
  4414 000025D8 7551                <1> 	jnz	short vga_g_up_6
  4415                              <1> 
  4416                              <1> 	;push	ax
  4417                              <1> 	; 12/04/2021
  4418 000025DA 50                  <1> 	push	eax
  4419 000025DB A0[E6670000]        <1> 	mov	al, [VGA_ROWS]
  4420 000025E0 FEC8                <1> 	dec	al  
  4421 000025E2 38C6                <1> 	cmp	dh, al ; rlr = nbrows-1
  4422 000025E4 7545                <1> 	jne	short vga_g_up_5
  4423 000025E6 A0[E0670000]        <1>         mov     al, [CRT_COLS]  ; = VGA_COLS
  4424 000025EB FEC8                <1> 	dec	al 
  4425 000025ED 38C2                <1>  	cmp	dl, al ; clr = nbcols-1
  4426                              <1> 	;jne	short vga_g_up_5
  4427                              <1> 	;;pop	ax
  4428                              <1> 	; 12/04/2021
  4429 000025EF 58                  <1> 	pop	eax
  4430 000025F0 7539                <1> 	jne	short vga_g_up_5
  4431                              <1> 
  4432 000025F2 66B80502            <1> 	mov	ax, 0205h
  4433 000025F6 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4434 000025FA 66EF                <1> 	out	dx, ax
  4435 000025FC A0[E6670000]        <1> 	mov	al, [VGA_ROWS]
  4436 00002601 8A25[E0670000]      <1> 	mov	ah, [CRT_COLS] ; = [VGA_COLS]
  4437 00002607 F6E4                <1> 	mul	ah
  4438 00002609 0FB7D0              <1> 	movzx	edx, ax
  4439                              <1> 	; 08/08/2016
  4440 0000260C 0FB605[E2670000]    <1> 	movzx	eax, byte [CHAR_HEIGHT]
  4441 00002613 F7E2                <1> 	mul	edx
  4442                              <1> 	; eax = byte count	
  4443 00002615 89C1                <1> 	mov	ecx, eax
  4444                              <1> 	;; 07/08/2016
  4445                              <1> 	;shl	dx, 3 ; * 8 ; * [CHAR_HEIGHT]
  4446                              <1> 	;mov	ecx, edx
  4447 00002617 88D8                <1> 	mov	al, bl ; fill value for blanked lines
  4448 00002619 BF00000A00          <1> 	mov	edi, 0A0000h
  4449 0000261E F3AA                <1> 	rep	stosb		
  4450                              <1> 	
  4451                              <1> 	;mov	ax, 5
  4452                              <1> 	; 03/08/2022
  4453 00002620 30E4                <1> 	xor	ah, ah
  4454 00002622 B005                <1> 	mov	al, 5
  4455                              <1> 
  4456 00002624 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4457 00002628 66EF                <1> 	out	dx, ax ; 0005h	
  4458                              <1> 
  4459 0000262A C3                  <1> 	retn
  4460                              <1> 
  4461                              <1> vga_g_up_5:
  4462                              <1> 	;;pop	ax
  4463                              <1> 	; 12/04/2021
  4464                              <1> 	;pop	eax
  4465                              <1> 
  4466                              <1> vga_g_up_6:
  4467                              <1> 	; [ESI] = VGA memory model number for current video mode
  4468                              <1>         ;
  4469                              <1>         ; LINEAR8 equ 5
  4470                              <1>         ; PLANAR4 equ 4
  4471                              <1>         ; PLANAR1 equ 3
  4472                              <1> 
  4473 0000262B 803E04              <1> 	cmp	byte [esi], PLANAR4
  4474 0000262E 7424                <1> 	je	short vga_g_up_planar
  4475 00002630 803E03              <1> 	cmp	byte [esi], PLANAR1
  4476 00002633 741F                <1> 	je	short vga_g_up_planar
  4477                              <1> vga_g_up_linear8:
  4478                              <1> 	; 07/07/2016 (TEMPORARY)
  4479                              <1> 	;
  4480                              <1> 	; cl = upper left column ; cul
  4481                              <1> 	; ch = upper left row ; rul
  4482                              <1> 	; dl = lower rigth column ; clr
  4483                              <1> 	; dh = lower right row ; rlr
  4484                              <1> 
  4485                              <1> vga_g_up_l0:
  4486                              <1>  	;{for(i=rul;i<=rlr;i++)
  4487                              <1>   	; if((i+nblines>rlr)||(nblines==0))
  4488 00002635 08C0                <1> 	or	al, al
  4489 00002637 7414                <1> 	jz	short vga_g_up_l2
  4490 00002639 88C4                <1> 	mov	ah, al
  4491 0000263B 00EC                <1> 	add	ah, ch ; i+nblines
  4492                              <1> 	;jc	short vga_g_up_l2	
  4493 0000263D 38F4                <1> 	cmp	ah, dh
  4494 0000263F 770C                <1> 	ja	short vga_g_up_l2
  4495                              <1> 	; else
  4496                              <1> 	;  vgamem_copy_pl4(cul,i+nblines,i,cols,nbcols,cheight);
  4497 00002641 E8F2000000          <1> 	call	vgamem_copy_l8
  4498                              <1> vga_g_up_l1:
  4499 00002646 FEC5                <1> 	inc	ch
  4500 00002648 38F5                <1> 	cmp	ch, dh
  4501 0000264A 76E9                <1> 	jna	short vga_g_up_l0
  4502 0000264C C3                  <1> 	retn
  4503                              <1> vga_g_up_l2:
  4504                              <1> 	; vgamem_fill_pl4(cul,i,cols,nbcols,cheight,attr);
  4505 0000264D E84C010000          <1> 	call	vgamem_fill_l8
  4506 00002652 EBF2                <1> 	jmp	short vga_g_up_l1
  4507                              <1> 
  4508                              <1> vga_g_up_planar:
  4509                              <1> 	; cl = upper left column ; cul
  4510                              <1> 	; ch = upper left row ; rul
  4511                              <1> 	; dl = lower rigth column ; clr
  4512                              <1> 	; dh = lower right row ; rlr
  4513                              <1> vga_g_up_pl0:
  4514                              <1>  	;{for(i=rul;i<=rlr;i++)
  4515                              <1>   	; if((i+nblines>rlr)||(nblines==0))
  4516 00002654 20C0                <1> 	and	al, al
  4517 00002656 7414                <1> 	jz	short vga_g_up_pl2	
  4518 00002658 88C4                <1> 	mov	ah, al
  4519 0000265A 00EC                <1> 	add	ah, ch ; i+nblines
  4520                              <1> 	;jc	short vga_g_up_pl2
  4521 0000265C 38F4                <1> 	cmp	ah, dh
  4522 0000265E 770C                <1> 	ja	short vga_g_up_pl2
  4523                              <1> 	; else
  4524                              <1> 	;  vgamem_copy_pl4(cul,i+nblines,i,cols,nbcols,cheight);
  4525 00002660 E80E000000          <1> 	call	vgamem_copy_pl4
  4526                              <1> vga_g_up_pl1:
  4527 00002665 FEC5                <1> 	inc	ch 
  4528 00002667 38F5                <1> 	cmp	ch, dh
  4529 00002669 76E9                <1> 	jna	short vga_g_up_pl0
  4530 0000266B C3                  <1> 	retn
  4531                              <1> vga_g_up_pl2:
  4532                              <1> 	; vgamem_fill_pl4(cul,i,cols,nbcols,cheight,attr);
  4533 0000266C E870000000          <1> 	call	vgamem_fill_pl4
  4534 00002671 EBF2                <1> 	jmp	short vga_g_up_pl1
  4535                              <1> 
  4536                              <1> vgamem_copy_pl4:
  4537                              <1> 	; 08/08/2016
  4538                              <1> 	; 07/08/2016
  4539                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  4540                              <1> 	;
  4541                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4542                              <1> 	; vgabios-0.7a (2011)
  4543                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4544                              <1> 	; 'vgabios.c', 'vgamem_copy_pl4'
  4545                              <1> 	;
  4546                              <1> 	; vgamem_copy_pl4(xstart,ysrc,ydest,cols,nbcols,cheight)
  4547                              <1> 	; cl = xstart, ah = ysrc (i+nblines), ch = ydest (i),
  4548                              <1> 	; bh = cols, [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight
  4549                              <1> 
  4550                              <1> 	; src=ysrc*cheight*nbcols+xstart;
  4551                              <1> 	; dest=ydest*cheight*nbcols+xstart;
  4552                              <1> 
  4553 00002673 52                  <1> 	push	edx
  4554 00002674 50                  <1> 	push	eax
  4555                              <1> 
  4556                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0105)
  4557 00002675 66B80501            <1> 	mov	ax, 0105h
  4558 00002679 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4559 0000267D 66EF                <1> 	out	dx, ax
  4560                              <1> 
  4561                              <1> 	; 07/08/2016
  4562                              <1>  	;mov     ah, [esp+1]
  4563                              <1> 	;movzx	edx, ah ; ysrc
  4564 0000267F 0FB6542401          <1> 	movzx	edx, byte [esp+1]
  4565                              <1> 	; 08/08/2016
  4566 00002684 0FB605[E2670000]    <1> 	movzx	eax, byte [CHAR_HEIGHT]
  4567 0000268B 8A25[E0670000]      <1> 	mov	ah, [CRT_COLS] ; nbcols
  4568 00002691 F6E4                <1> 	mul	ah 
  4569                              <1> 	;; 07/08/2016
  4570                              <1> 	;movzx	eax, byte [CRT_COLS]
  4571                              <1> 	;shl	ax, 3 ; * 8 ; * [CHAR_HEIGHT]
  4572 00002693 50                  <1> 	push	eax ; cheight * nbcols
  4573 00002694 F7E2                <1> 	mul	edx ; * ysrc
  4574                              <1> 	; eax = ysrc * cheight * nbcols
  4575                              <1> 	; edx = 0
  4576 00002696 88CA                <1> 	mov	dl, cl ; edx = xstart	
  4577 00002698 01D0                <1>  	add	eax, edx
  4578 0000269A 89C6                <1> 	mov	esi, eax ; src
  4579 0000269C 88EA                <1> 	mov	dl, ch ; ydest
  4580 0000269E 58                  <1> 	pop	eax ; cheight * nbcols
  4581 0000269F F7E2                <1> 	mul	edx
  4582                              <1> 	; eax = ydest * cheight * nbcols
  4583 000026A1 88CA                <1> 	mov	dl, cl ; edx = xstart	
  4584 000026A3 01D0                <1>  	add	eax, edx
  4585 000026A5 89C7                <1> 	mov	edi, eax ; dest
  4586                              <1> 	; esi = src
  4587                              <1> 	; edi = dest
  4588                              <1> 	; for(i=0;i<cheight;i++)
  4589                              <1>   	; {
  4590                              <1>    	;  memcpyb(0xa000,dest+i*nbcols,0xa000,src+i*nbcols,cols);
  4591                              <1>   	; }
  4592 000026A7 51                  <1> 	push	ecx
  4593 000026A8 B900000A00          <1> 	mov	ecx, 0A0000h
  4594 000026AD 01CE                <1> 	add	esi, ecx
  4595 000026AF 01CF                <1> 	add	edi, ecx
  4596                              <1> 	; 08/08/2016
  4597 000026B1 8A35[E2670000]      <1> 	mov	dh, [CHAR_HEIGHT]
  4598                              <1> 	;; 07/08/2016
  4599                              <1> 	;mov	dh, 8 ; 07/08/2016
  4600 000026B7 28D2                <1> 	sub	dl, dl ; i
  4601                              <1> vgamem_copy_pl4_0:
  4602 000026B9 56                  <1> 	push	esi
  4603 000026BA 57                  <1> 	push	edi
  4604 000026BB 0FB605[E0670000]    <1> 	movzx	eax, byte [CRT_COLS]
  4605 000026C2 F6E2                <1> 	mul	dl
  4606                              <1> 	; eax = i * nbcols
  4607 000026C4 01C7                <1> 	add	edi, eax ; dest+i*nbcols
  4608 000026C6 01C6                <1> 	add	esi, eax
  4609 000026C8 0FB6CF              <1> 	movzx	ecx, bh ; cols
  4610 000026CB F3A4                <1> 	rep	movsb
  4611 000026CD 5F                  <1> 	pop	edi
  4612 000026CE 5E                  <1> 	pop	esi
  4613 000026CF FECE                <1> 	dec	dh
  4614 000026D1 75E6                <1> 	jnz	short vgamem_copy_pl4_0
  4615                              <1> vgamem_copy_pl4_1:
  4616 000026D3 59                  <1> 	pop	ecx
  4617                              <1> 
  4618                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0005);
  4619 000026D4 66B80500            <1> 	mov	ax, 0005h
  4620 000026D8 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4621 000026DC 66EF                <1> 	out	dx, ax
  4622                              <1> 
  4623 000026DE 58                  <1> 	pop	eax
  4624 000026DF 5A                  <1> 	pop	edx
  4625                              <1> 
  4626 000026E0 C3                  <1> 	retn	
  4627                              <1> 
  4628                              <1> vgamem_fill_pl4:
  4629                              <1> 	; 08/08/2016
  4630                              <1> 	; 07/08/2016
  4631                              <1> 	; 04/08/2016
  4632                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  4633                              <1> 	;
  4634                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4635                              <1> 	; vgabios-0.7a (2011)
  4636                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4637                              <1> 	; 'vgabios.c', 'vgamem_fill_pl4'
  4638                              <1> 	;
  4639                              <1> 	; vgamem_fill_pl4(xstart,ystart,cols,nbcols,cheight,attr)
  4640                              <1> 	; cl = xstart, edi = ch = ystart, bh = cols,
  4641                              <1> 	; [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight, attr = 0
  4642                              <1> 
  4643                              <1> 	; dest=ystart*cheight*nbcols+xstart;
  4644 000026E1 52                  <1> 	push	edx
  4645 000026E2 50                  <1> 	push	eax
  4646                              <1> 
  4647                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0205)
  4648 000026E3 66B80502            <1> 	mov	ax, 0205h
  4649 000026E7 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4650 000026EB 66EF                <1> 	out	dx, ax
  4651                              <1> 
  4652                              <1>       	; 08/08/2016
  4653 000026ED 0FB605[E2670000]    <1> 	movzx   eax, byte [CHAR_HEIGHT]
  4654 000026F4 F6E5                <1> 	mul	ch
  4655                              <1> 	;; 07/08/2016
  4656                              <1> 	;movzx	eax, ch
  4657                              <1> 	;shl	ax, 3 ; * 8 ; * [CHAR_HEIGHT]
  4658 000026F6 0FB615[E0670000]    <1> 	movzx	edx, byte [CRT_COLS] ; = [VGA_COLS]
  4659 000026FD F7E2                <1> 	mul	edx
  4660                              <1> 	; edx  = 0
  4661 000026FF 88CA                <1> 	mov	dl, cl 
  4662 00002701 01D0                <1> 	add	eax, edx
  4663 00002703 89C7                <1> 	mov	edi, eax
  4664                              <1> 	; edi = dest
  4665                              <1> 	; for(i=0;i<cheight;i++)
  4666                              <1>   	; {
  4667                              <1>    	;  memsetb(0xa000,dest+i*nbcols,attr,cols);
  4668                              <1>   	; }
  4669 00002705 81C700000A00        <1> 	add	edi, 0A0000h
  4670 0000270B 51                  <1> 	push	ecx
  4671                              <1> 	; 08/08/2016
  4672 0000270C 8A35[E2670000]      <1> 	mov	dh, [CHAR_HEIGHT]
  4673                              <1> 	;; 07/08/2016
  4674                              <1> 	;mov	dh, 8 ; 07/08/2016
  4675 00002712 28D2                <1> 	sub	dl, dl ; i
  4676                              <1> vgamem_fill_pl4_0:
  4677 00002714 57                  <1> 	push	edi
  4678 00002715 0FB605[E0670000]    <1> 	movzx	eax, byte [CRT_COLS]
  4679 0000271C F6E2                <1> 	mul	dl
  4680                              <1> 	; eax = i * nbcols
  4681 0000271E 01C7                <1> 	add	edi, eax ; dest+i*nbcols
  4682 00002720 88D8                <1> 	mov	al, bl ; attr ; 04/08/2016
  4683 00002722 0FB6CF              <1> 	movzx	ecx, bh ; cols
  4684 00002725 F3AA                <1>  	rep	stosb
  4685 00002727 5F                  <1> 	pop	edi
  4686 00002728 75EA                <1> 	jnz	short vgamem_fill_pl4_0
  4687                              <1> vgamem_fill_pl4_1:
  4688 0000272A 59                  <1> 	pop	ecx
  4689                              <1> 
  4690                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0005);
  4691 0000272B 66B80500            <1> 	mov	ax, 0005h
  4692 0000272F 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4693 00002733 66EF                <1> 	out	dx, ax
  4694                              <1> 
  4695 00002735 58                  <1> 	pop	eax
  4696 00002736 5A                  <1> 	pop	edx 
  4697                              <1> 	
  4698 00002737 C3                  <1> 	retn
  4699                              <1> 
  4700                              <1> vgamem_copy_l8:
  4701                              <1> 	; 02/08/2022 - TRDOS 386 Kernel v2.0.5
  4702                              <1> 	; 08/08/2016
  4703                              <1> 	; 07/08/2016
  4704                              <1> 	; 06/08/2016
  4705                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  4706                              <1> 	;
  4707                              <1> 	; TEMPORARY
  4708                              <1> 	;
  4709                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4710                              <1> 	; vgabios-0.7a (2011)
  4711                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4712                              <1> 	; 'vgabios.c', 'vgamem_copy_pl4'
  4713                              <1> 	;
  4714                              <1> 	; vgamem_copy_pl4(xstart,ysrc,ydest,cols,nbcols,cheight)
  4715                              <1> 	; cl = xstart, ah = ysrc (i+nblines), ch = ydest (i),
  4716                              <1> 	; bh = cols, [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight
  4717                              <1> 
  4718                              <1> 	; src=ysrc*cheight*nbcols+xstart;
  4719                              <1> 	; dest=ydest*cheight*nbcols+xstart;
  4720                              <1> 
  4721 00002738 52                  <1> 	push	edx
  4722 00002739 50                  <1> 	push	eax
  4723                              <1> 
  4724                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0105)
  4725                              <1> 	;mov	ax, 0105h
  4726                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4727                              <1> 	;out	dx, ax
  4728                              <1> 
  4729                              <1> 	;mov	ah, [esp+1]
  4730                              <1> 
  4731 0000273A 0FB6D4              <1> 	movzx	edx, ah ; ysrc
  4732                              <1> 	; 08/08/2016
  4733 0000273D 0FB605[E2670000]    <1> 	movzx	eax, byte [CHAR_HEIGHT]
  4734 00002744 8A25[E0670000]      <1> 	mov	ah, [CRT_COLS] ; nbcols
  4735 0000274A F6E4                <1> 	mul	ah 
  4736                              <1> 	;; 07/08/2016
  4737                              <1> 	;movzx	eax, byte [CRT_COLS]
  4738                              <1> 	;shl	ax, 3 ; * 8 ; * [CHAR_HEIGHT]
  4739 0000274C 50                  <1> 	push	eax ; cheight * nbcols
  4740 0000274D F7E2                <1> 	mul	edx ; * ysrc
  4741                              <1> 	; eax = ysrc * cheight * nbcols
  4742                              <1> 	; edx = 0
  4743 0000274F 88CA                <1> 	mov	dl, cl ; edx = xstart
  4744 00002751 01D0                <1>  	add	eax, edx
  4745 00002753 89C6                <1> 	mov	esi, eax ; src
  4746                              <1> 	;shl	si, 3 ; * 8 ; 06/08/2016
  4747                              <1> 	; 02/08/2022
  4748 00002755 C1E603              <1> 	shl	esi, 3
  4749 00002758 88EA                <1> 	mov	dl, ch ; ydest
  4750 0000275A 58                  <1> 	pop	eax ; cheight * nbcols
  4751 0000275B F7E2                <1> 	mul	edx
  4752                              <1> 	; eax = ydest * cheight * nbcols
  4753 0000275D 88CA                <1> 	mov	dl, cl ; edx = xstart	
  4754 0000275F 01D0                <1>  	add	eax, edx
  4755 00002761 89C7                <1> 	mov	edi, eax ; dest
  4756                              <1> 	;shl	di, 3 ; * 8 ; 06/08/2016
  4757                              <1> 	; 02/08/2022
  4758 00002763 C1E703              <1> 	shl	edi, 3
  4759                              <1> 	; esi = src
  4760                              <1> 	; edi = dest
  4761                              <1> 	; for(i=0;i<cheight;i++)
  4762                              <1>   	; {
  4763                              <1>    	;  memcpyb(0xa000,dest+i*nbcols,0xa000,src+i*nbcols,cols);
  4764                              <1>   	; }
  4765 00002766 51                  <1> 	push	ecx
  4766 00002767 B900000A00          <1> 	mov	ecx, 0A0000h
  4767 0000276C 01CE                <1> 	add	esi, ecx
  4768 0000276E 01CF                <1> 	add	edi, ecx
  4769                              <1> 	; 08/08/2016
  4770 00002770 8A35[E2670000]      <1> 	mov	dh, [CHAR_HEIGHT]
  4771                              <1> 	;; 07/08/2016
  4772                              <1> 	;mov	dh, 8 ; 07/08/2016
  4773 00002776 28D2                <1> 	sub	dl, dl ; i
  4774                              <1> vgamem_copy_l8_0:
  4775 00002778 56                  <1> 	push	esi
  4776 00002779 57                  <1> 	push	edi
  4777 0000277A 0FB605[E0670000]    <1> 	movzx	eax, byte [CRT_COLS]
  4778 00002781 F6E2                <1> 	mul	dl
  4779                              <1> 	; eax = i * nbcols
  4780                              <1> 	;shl	ax, 3 ; * 8 ; 06/08/2016
  4781                              <1> 	; 02/08/2022
  4782 00002783 C1E003              <1> 	shl	eax, 3
  4783 00002786 01C7                <1> 	add	edi, eax ; dest+i*nbcols
  4784 00002788 01C6                <1> 	add	esi, eax
  4785 0000278A 0FB6CF              <1> 	movzx	ecx, bh ; cols
  4786                              <1> 	;shl	cx, 3 ; * 8 ; 06/08/2016
  4787                              <1> 	; 02/08/2022
  4788 0000278D C1E103              <1> 	shl	ecx, 3
  4789 00002790 F3A4                <1> 	rep	movsb
  4790 00002792 5F                  <1> 	pop	edi
  4791 00002793 5E                  <1> 	pop	esi
  4792 00002794 FEC2                <1> 	inc	dl ; 06/08/2016
  4793 00002796 FECE                <1> 	dec	dh
  4794 00002798 75DE                <1> 	jnz	short vgamem_copy_l8_0
  4795                              <1> vgamem_copy_l8_1:
  4796 0000279A 59                  <1> 	pop	ecx
  4797                              <1> 
  4798                              <1> 	;; outw(VGAREG_GRDC_ADDRESS, 0x0005);
  4799                              <1> 	;mov	ax, 0005h
  4800                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4801                              <1> 	;out	dx, ax
  4802                              <1> 
  4803 0000279B 58                  <1> 	pop	eax
  4804 0000279C 5A                  <1> 	pop	edx
  4805                              <1> 
  4806 0000279D C3                  <1> 	retn
  4807                              <1> 
  4808                              <1> vgamem_fill_l8:
  4809                              <1> 	; 02/08/2022 - TRDOS 386 Kernel v2.0.5
  4810                              <1> 	; 08/08/2016
  4811                              <1> 	; 07/08/2016
  4812                              <1> 	; 06/08/2016
  4813                              <1> 	; 04/08/2016
  4814                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  4815                              <1> 	;
  4816                              <1> 	; TEMPORARY
  4817                              <1> 	;
  4818                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  4819                              <1> 	; vgabios-0.7a (2011)
  4820                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  4821                              <1> 	; 'vgabios.c', 'vgamem_fill_pl4'
  4822                              <1> 	;
  4823                              <1> 	; vgamem_fill_pl4(xstart,ystart,cols,nbcols,cheight,attr)
  4824                              <1> 	; cl = xstart, edi = ch = ystart, bh = cols,
  4825                              <1> 	; [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight, attr = 0
  4826                              <1> 
  4827                              <1> 	; dest=ystart*cheight*nbcols+xstart;
  4828 0000279E 52                  <1> 	push	edx
  4829 0000279F 50                  <1> 	push	eax
  4830                              <1> 
  4831                              <1> 	;; outw(VGAREG_GRDC_ADDRESS, 0x0205)
  4832                              <1> 	;mov	ax, 0205h
  4833                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4834                              <1> 	;out	dx, ax
  4835                              <1> 
  4836                              <1>         ; 08/08/2016
  4837 000027A0 0FB605[E2670000]    <1> 	movzx   eax, byte [CHAR_HEIGHT]
  4838 000027A7 F6E5                <1> 	mul	ch
  4839                              <1> 	;; 07/08/2016
  4840                              <1> 	;movzx	eax, ch
  4841                              <1> 	;shl	ax, 3 ; * 8 ; * [CHAR_HEIGHT]
  4842 000027A9 0FB615[E0670000]    <1> 	movzx	edx, byte [CRT_COLS] ; = [VGA_COLS]
  4843 000027B0 F7E2                <1> 	mul	edx
  4844                              <1> 	; edx  = 0
  4845 000027B2 88CA                <1> 	mov	dl, cl 
  4846 000027B4 01D0                <1> 	add	eax, edx
  4847 000027B6 89C7                <1> 	mov	edi, eax
  4848                              <1> 	;shl	di, 3 ; * 8 ; 06/08/2016
  4849                              <1> 	; 02/08/2022
  4850 000027B8 C1E703              <1> 	shl	edi, 3
  4851                              <1> 	; edi = dest
  4852                              <1> 	; for(i=0;i<cheight;i++)
  4853                              <1>   	; {
  4854                              <1>    	;  memsetb(0xa000,dest+i*nbcols,attr,cols);
  4855                              <1>   	; }
  4856 000027BB 81C700000A00        <1> 	add	edi, 0A0000h
  4857 000027C1 51                  <1> 	push	ecx
  4858                              <1> 	; 08/08/2016
  4859 000027C2 8A35[E2670000]      <1> 	mov	dh, [CHAR_HEIGHT]
  4860                              <1> 	;; 07/08/2016
  4861                              <1> 	;mov	dh, 8 ; 07/08/2016
  4862 000027C8 28D2                <1> 	sub	dl, dl ; i
  4863                              <1> vgamem_fill_l8_0:
  4864 000027CA 57                  <1> 	push	edi
  4865 000027CB 0FB605[E0670000]    <1> 	movzx	eax, byte [CRT_COLS]
  4866 000027D2 F6E2                <1> 	mul	dl
  4867                              <1> 	; eax = i * nbcols
  4868                              <1> 	;shl	ax, 3 ; * 8 ; 06/08/2016
  4869                              <1> 	; 02/08/2022
  4870 000027D4 C1E003              <1> 	shl	eax, 3
  4871 000027D7 01C7                <1> 	add	edi, eax ; dest+i*nbcols
  4872 000027D9 88D8                <1> 	mov	al, bl ; attr ; 04/08/2016
  4873 000027DB 0FB6CF              <1> 	movzx	ecx, bh ; cols
  4874                              <1> 	;shl	cx, 3 ; * 8 ; 06/08/2016
  4875                              <1>  	; 02/08/2022
  4876 000027DE C1E103              <1> 	shl	ecx, 3
  4877 000027E1 F3AA                <1> 	rep	stosb
  4878 000027E3 5F                  <1> 	pop	edi
  4879 000027E4 FEC2                <1> 	inc	dl ; 06/08/2016
  4880 000027E6 FECE                <1> 	dec	dh
  4881 000027E8 75E0                <1> 	jnz	short vgamem_fill_l8_0
  4882                              <1> vgamem_fill_l8_1:
  4883 000027EA 59                  <1> 	pop	ecx
  4884                              <1> 
  4885                              <1> 	;; outw(VGAREG_GRDC_ADDRESS, 0x0005);
  4886                              <1> 	;mov	ax, 0005h
  4887                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  4888                              <1> 	;out	dx, ax
  4889                              <1> 
  4890 000027EB 58                  <1> 	pop	eax
  4891 000027EC 5A                  <1> 	pop	edx 
  4892                              <1> 
  4893 000027ED C3                  <1> 	retn
  4894                              <1> 
  4895                              <1> ; 03/08/2022 - TRDOS 386 Kernel V2.0.5
  4896                              <1> ; 07/07/2016
  4897                              <1> ; 27/06/2016 - TRDOS 386 (TRDOS v2.0)
  4898                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  4899                              <1> ;------------------------------------------------------
  4900                              <1> ; SCROLL DOWN
  4901                              <1> ;  THIS ROUTINE SCROLLS DOWN THE INFORMATION ON THE CRT
  4902                              <1> ; ENTRY --
  4903                              <1> ;  CH,CL = UPPER LEFT CORNER OF REGION TO SCROLL
  4904                              <1> ;  DH,DL = LOWER RIGHT CORNER OF REGION TO SCROLL
  4905                              <1> ;   BOTH OF THE ABOVE ARE IN CHARACTER POSITIONS
  4906                              <1> ;  BH = FILL VALUE FOR BLANKED LINES
  4907                              <1> ;  AL = # LINES TO SCROLL (AL=0 MEANS BLANK THE ENTIRE FIELD)
  4908                              <1> ;  DS = DATA SEGMENT
  4909                              <1> ;  ES = REGEN SEGMENT
  4910                              <1> ; EXIT --
  4911                              <1> ;  NOTHING, THE SCREEN IS SCROLLED
  4912                              <1> ;--------------------------------------------------------
  4913                              <1> 
  4914                              <1> 	; cl = upper left column
  4915                              <1> 	; ch = upper left row
  4916                              <1> 	; dl = lower rigth column
  4917                              <1> 	; dh = lower right row
  4918                              <1> 	;
  4919                              <1> 	; al = line count (AL=0 means blank entire fields)
  4920                              <1> 	; bl = fill value for blanked lines	
  4921                              <1> 	; bh = unused
  4922                              <1> 
  4923                              <1> GRAPHICS_DOWN:
  4924                              <1> 	; 07/07/2016
  4925                              <1> 	; ah = Current video mode, [CRT_MODE]
  4926                              <1> 	; std				; SET DIRECTION
  4927 000027EE 80FC07              <1> 	cmp	ah, 7
  4928 000027F1 7769                <1>         ja	short vga_graphics_down ; 03/08/2022
  4929                              <1> 	;je	_n0
  4930                              <1> 
  4931 000027F3 88C7                <1> 	mov	bh, al			; save line count in BH
  4932                              <1> 	;mov	ax, dx			; GET LOWER RIGHT POSITION INTO AX REG
  4933                              <1> 	; 03/08/2022
  4934 000027F5 89D0                <1> 	mov	eax, edx
  4935                              <1> 
  4936                              <1> ;-----	USE CHARACTER SUBROUTINE FOR POSITIONING
  4937                              <1> ;-----	ADDRESS RETURNED IS MULTIPLIED BY 2 FROM CORRECT VALUE
  4938                              <1> 
  4939 000027F7 E8E8020000          <1> 	call	GRAPH_POSN
  4940                              <1> 	;movzx	edi, ax			; SAVE RESULT AS DESTINATION ADDRESS
  4941                              <1> 	; 03/08/2022
  4942 000027FC 89C7                <1> 	mov	edi, eax
  4943                              <1> 
  4944                              <1> ;-----	DETERMINE SIZE OF WINDOW
  4945                              <1> 
  4946 000027FE 6629CA              <1> 	sub	dx, cx
  4947 00002801 6681C20101          <1>         add     dx, 101h                ; ADJUST VALUES
  4948 00002806 C0E602              <1> 	sal	dh, 2			; MULTIPLY ROWS BY 4 AT 8 VERT DOTS/CHAR
  4949                              <1> 					; AND EVEN/ODD ROWS
  4950                              <1> ;-----	DETERMINE CRT MODE
  4951                              <1> 
  4952 00002809 803D[DE670000]06    <1> 	cmp	byte [CRT_MODE], 6	; TEST FOR MEDIUM RES
  4953 00002810 7305                <1> 	jnc	short _R12              ; FIND_SOURCE_DOWN
  4954                              <1> 
  4955                              <1> ;-----	MEDIUM RES DOWN
  4956 00002812 D0E2                <1> 	sal	dl, 1			; # COLUMNS * 2, SINCE 2 BYTES/CHAR
  4957                              <1> 	;sal	di, 1			; OFFSET *2 SINCE 2 BYTES/CHAR
  4958                              <1> 	; 03/08/2022
  4959 00002814 D1E7                <1> 	sal	edi, 1
  4960                              <1> 	;inc	di			; POINT TO LAST BYTE
  4961                              <1> 	; 03/08/2022
  4962 00002816 47                  <1> 	inc	edi
  4963                              <1> 
  4964                              <1> ;-----	DETERMINE THE SOURCE ADDRESS IN THE BUFFER
  4965                              <1> 
  4966                              <1> _R12:                                   ; FIND_SOURCE_DOWN
  4967 00002817 81C700800B00        <1> 	add	edi, 0B8000h		
  4968 0000281D 6681C7F000          <1> 	add	di, 240			; POINT TO LAST ROW OF PIXELS
  4969 00002822 C0E702              <1> 	sal	bh, 2			; multiply number of lines by 4
  4970 00002825 74(06)              <1> 	jz	short 6			; IF ZERO, THEN BLANK ENTIRE FIELD
  4971 00002827 B050                <1> 	mov	al, 80			; 80 BYTES/ROW
  4972 00002829 F6E7                <1> 	mul	bh			; determine offset to source
  4973 0000282B 89FE                <1> 	mov	esi, edi		; SET UP SOURCE
  4974                              <1> 	;sub	si, ax			; SUBTRACT THE OFFSET
  4975                              <1> 	; 03/08/2022
  4976 0000282D 29C6                <1> 	sub	esi, eax
  4977 0000282F 88F4                <1> 	mov	ah, dh			; NUMBER OF ROWS IN FIELD
  4978 00002831 28FC                <1> 	sub	ah, bh			; determine number to move
  4979                              <1> 
  4980                              <1> ;-----	LOOP THROUGH, MOVING ONE ROW AT A TIME, BOTH EVEN AND ODD FIELDS
  4981                              <1> 
  4982                              <1> _R13:                                   ; ROW_LOOP_DOWN
  4983 00002833 E825010000          <1>         call    _R17                    ; MOVE ONE ROW
  4984 00002838 6681EE5020          <1> 	sub	si, 2000h+80		; MOVE TO NEXT ROW
  4985 0000283D 6681EF5020          <1> 	sub	di, 2000h+80
  4986 00002842 FECC                <1> 	dec	ah			; NUMBER OF ROWS TO MOVE
  4987 00002844 75ED                <1> 	jnz	short _R13              ; CONTINUE TILL ALL MOVED
  4988                              <1> 
  4989                              <1> ;-----	FILL IN THE VACATED LINE(S)
  4990                              <1> _R14:                                   ; CLEAR_ENTRY_DOWN
  4991 00002846 88D8                <1> 	mov	al, bl			; attribute to fill with
  4992                              <1> _R15_:                                  ; CLEAR_LOOP_DOWN
  4993 00002848 E82C010000          <1> 	call	_R18			; CLEAR A ROW
  4994 0000284D 6681EF5020          <1> 	sub	di, 2000h+80		; POINT TO NEXT LINE
  4995 00002852 FECF                <1> 	dec	bh			; number of lines to fill
  4996 00002854 75F2                <1>         jnz	short _R15_             ; CLEAR_LOOP_DOWN
  4997                              <1> 	; 18/11/2020
  4998 00002856 FC                  <1> 	cld				; RESET THE DIRECTION FLAG
  4999                              <1> 	
  5000 00002857 C3                  <1> 	retn				; EVERYTHING DONE
  5001                              <1> 
  5002                              <1> _R16:                                   ; BLANK_FIELD_DOWN
  5003 00002858 88F7                <1> 	mov	bh, dh			; set blank count to everything in field
  5004 0000285A EBEA                <1>         jmp     short _R14              ; CLEAR THE FIELD
  5005                              <1> 
  5006                              <1> vga_graphics_down:
  5007                              <1> 	; 03/08/2022 - TRDOS 386 Kertnel v2.0.5
  5008                              <1> 	; 12/04/2021
  5009                              <1> 	; 08/08/2016
  5010                              <1> 	; 07/08/2016
  5011                              <1> 	; 31/07/2016
  5012                              <1> 	; 07/07/2016 - TRDOS 386 (TRDOS v2.0)
  5013                              <1> 	;
  5014                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5015                              <1> 	; vgabios-0.7a (2011)
  5016                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5017                              <1> 	; 'vgabios.c', 'biosfn_scroll'
  5018                              <1> 	;
  5019                              <1> 
  5020                              <1> 	; cl = upper left column
  5021                              <1> 	; ch = upper left row
  5022                              <1> 	; dl = lower rigth column
  5023                              <1> 	; dh = lower right row
  5024                              <1> 	;
  5025                              <1> 	; al = line count (AL=0 means blank entire fields)
  5026                              <1> 	; bl = fill value for blanked lines	
  5027                              <1> 	; bh = unused
  5028                              <1> 	;
  5029                              <1> 	; ah = [CRT_MODE], current video mode	
  5030                              <1> 
  5031 0000285C FC                  <1>         cld     ; !!! Clear direction flag !!! 
  5032                              <1> 
  5033 0000285D 88C7                <1> 	mov	bh, al ; 31/07/2016
  5034                              <1> 
  5035 0000285F BE[FA670000]        <1> 	mov	esi, vga_modes
  5036 00002864 89F7                <1> 	mov	edi, esi
  5037 00002866 83C710              <1> 	add	edi, vga_mode_count
  5038                              <1> vga_g_down_0:
  5039 00002869 AC                  <1> 	lodsb
  5040 0000286A 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  5041 0000286C 7405                <1> 	je	short vga_g_down_1
  5042 0000286E 39FE                <1> 	cmp	esi, edi
  5043 00002870 72F7                <1> 	jb	short vga_g_down_0
  5044                              <1> 	; xor 	bh, bh	; 31/07/2016
  5045 00002872 C3                  <1> 	retn	; nothing to do
  5046                              <1> vga_g_down_1:
  5047 00002873 88F8                <1> 	mov	al, bh ; 31/07/2016
  5048 00002875 83C64F              <1> 	add	esi, vga_memmodel - (vga_modes + 1)  
  5049                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  5050                              <1> 	
  5051                              <1> 	; if(rlr>=nbrows)rlr=nbrows-1;
  5052                              <1>  	; if(clr>=nbcols)clr=nbcols-1;
  5053                              <1>  	; if(nblines>nbrows)nblines=0;
  5054                              <1>  	; cols=clr-cul+1;
  5055                              <1> 
  5056 00002878 3A35[E6670000]      <1> 	cmp	dh, [VGA_ROWS]
  5057 0000287E 7208                <1> 	jb	short vga_g_down_2
  5058 00002880 8A35[E6670000]      <1> 	mov	dh, [VGA_ROWS]
  5059 00002886 FECE                <1> 	dec	dh
  5060                              <1> vga_g_down_2:
  5061 00002888 3A15[E0670000]      <1> 	cmp	dl, [CRT_COLS]  ; = [VGA_COLS]
  5062 0000288E 7208                <1> 	jb	short vga_g_down_3
  5063 00002890 8A15[E0670000]      <1> 	mov	dl, [CRT_COLS]
  5064 00002896 FECA                <1> 	dec	dl
  5065                              <1> vga_g_down_3:	
  5066 00002898 3A05[E6670000]      <1> 	cmp	al, [VGA_ROWS]
  5067 0000289E 7602                <1> 	jna	short vga_g_down_4
  5068 000028A0 28C0                <1> 	sub	al, al ; 0
  5069                              <1> vga_g_down_4:
  5070 000028A2 88F7                <1> 	mov	bh, dh ; clr
  5071 000028A4 28CF                <1> 	sub	bh, cl ; cul
  5072 000028A6 FEC7                <1> 	inc	bh ; cols = clr-cul+1
  5073                              <1> 
  5074 000028A8 20C0                <1> 	and	al, al ; nblines = 0
  5075 000028AA 7559                <1> 	jnz	short vga_g_down_6
  5076 000028AC 20ED                <1> 	and	ch, ch ; rul = 0
  5077 000028AE 7555                <1> 	jnz	short vga_g_down_6
  5078 000028B0 20C9                <1> 	and	cl, cl ; cul = 0
  5079 000028B2 7551                <1> 	jnz	short vga_g_down_6
  5080                              <1> 
  5081 000028B4 50                  <1> 	push	eax ; push ax ; 12/04/2021
  5082 000028B5 A0[E6670000]        <1> 	mov	al, [VGA_ROWS]
  5083 000028BA FEC8                <1> 	dec	al  
  5084 000028BC 38C6                <1> 	cmp	dh, al ; rlr = nbrows-1
  5085 000028BE 7545                <1> 	jne	short vga_g_down_5
  5086 000028C0 A0[E0670000]        <1>         mov     al, [CRT_COLS]  ; = VGA_COLS
  5087 000028C5 FEC8                <1> 	dec	al 
  5088 000028C7 38C2                <1>  	cmp	dl, al ; clr = nbcols-1
  5089                              <1> 	;jne	short vga_g_down_5
  5090                              <1>  	; 12/04/2021
  5091 000028C9 58                  <1> 	pop	eax ; pop ax
  5092 000028CA 7539                <1> 	jne	short vga_g_down_5
  5093                              <1> 
  5094 000028CC 66B80502            <1> 	mov	ax, 0205h
  5095 000028D0 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  5096 000028D4 66EF                <1> 	out	dx, ax
  5097 000028D6 A0[E6670000]        <1> 	mov	al, [VGA_ROWS]
  5098 000028DB 8A25[E0670000]      <1> 	mov	ah, [CRT_COLS] ; = [VGA_COLS]
  5099 000028E1 F6E4                <1> 	mul	ah
  5100 000028E3 0FB7D0              <1> 	movzx	edx, ax
  5101                              <1> 	; 08/08/2016
  5102 000028E6 0FB605[E2670000]    <1> 	movzx	eax, byte [CHAR_HEIGHT]
  5103 000028ED F7E2                <1> 	mul	edx
  5104                              <1> 	; eax = byte count	
  5105 000028EF 89C1                <1> 	mov	ecx, eax
  5106                              <1> 	;; 07/08/2016
  5107                              <1> 	;shl	dx, 3 ; * 8 ; * [CHAR_HEIGHT]
  5108                              <1> 	;mov	ecx, edx
  5109 000028F1 88D8                <1> 	mov	al, bl ; fill value for blanked lines
  5110 000028F3 BF00000A00          <1> 	mov	edi, 0A0000h
  5111 000028F8 F3AA                <1> 	rep	stosb			
  5112                              <1> 	
  5113                              <1> 	; 03/08/2022
  5114 000028FA 30E4                <1> 	xor	ah, ah ; 0 
  5115                              <1> 	
  5116 000028FC B005                <1> 	mov	al, 5
  5117 000028FE 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  5118 00002902 66EF                <1> 	out	dx, ax ; 0005h	
  5119                              <1> 
  5120 00002904 C3                  <1> 	retn
  5121                              <1> 
  5122                              <1> vga_g_down_5:
  5123                              <1> 	; 12/04/2021
  5124                              <1> 	;pop	eax  ; pop ax
  5125                              <1> 
  5126                              <1> vga_g_down_6:
  5127                              <1> 	; [ESI] = VGA memory model number for current video mode
  5128                              <1>         ;
  5129                              <1>         ; LINEAR8 equ 5
  5130                              <1>         ; PLANAR4 equ 4
  5131                              <1>         ; PLANAR1 equ 3
  5132                              <1> 
  5133 00002905 803E04              <1> 	cmp	byte [esi], PLANAR4
  5134 00002908 742C                <1> 	je	short vga_g_down_planar
  5135 0000290A 803E03              <1> 	cmp	byte [esi], PLANAR1
  5136 0000290D 7427                <1> 	je	short vga_g_down_planar
  5137                              <1> vga_g_down_linear8:
  5138                              <1> 	; 07/07/2016 (TEMPORARY)
  5139                              <1> 	;
  5140                              <1> 	; cl = upper left column ; cul
  5141                              <1> 	; ch = upper left row ; rul
  5142                              <1> 	; dl = lower rigth column ; clr
  5143                              <1> 	; dh = lower right row ; rlr
  5144                              <1> 
  5145                              <1> vga_g_down_l0:
  5146                              <1> 	;{for(i=rlr;i>=rul;i--)
  5147                              <1>         ; if((i<rul+nblines)||(nblines==0))
  5148 0000290F 08C0                <1> 	or	al, al
  5149 00002911 741C                <1> 	jz	short vga_g_down_l2
  5150 00002913 88C4                <1> 	mov	ah, al
  5151 00002915 00EC                <1> 	add	ah, ch
  5152                              <1> 	;jc	short vga_g_down_l2	
  5153 00002917 86F5                <1> 	xchg	ch, dh
  5154 00002919 38E5                <1> 	cmp	ch, ah
  5155 0000291B 7212                <1> 	jb	short vga_g_down_l2
  5156 0000291D 88EC                <1> 	mov	ah, ch
  5157 0000291F 28C4                <1> 	sub	ah, al ; ah = i - nblines
  5158                              <1> 	; else
  5159                              <1> 	; vgamem_copy_pl4(cul,i,i-nblines,cols,nbcols,cheight);
  5160 00002921 E812FEFFFF          <1> 	call	vgamem_copy_l8
  5161                              <1> vga_g_down_l1:
  5162 00002926 86EE                <1> 	xchg	dh, ch
  5163 00002928 FECE                <1> 	dec	dh 
  5164 0000292A 38EE                <1> 	cmp	dh, ch
  5165 0000292C 73E1                <1> 	jnb	short vga_g_down_l0
  5166 0000292E C3                  <1> 	retn
  5167                              <1> 
  5168                              <1> vga_g_down_l2:
  5169                              <1> 	; vgamem_fill_pl4(cul,i,cols,nbcols,cheight,attr);
  5170 0000292F E86AFEFFFF          <1> 	call	vgamem_fill_l8
  5171 00002934 EBF0                <1> 	jmp	short vga_g_down_l1
  5172                              <1> 		 
  5173                              <1> vga_g_down_planar:
  5174                              <1> 	; cl = upper left column ; cul
  5175                              <1> 	; ch = upper left row ; rul
  5176                              <1> 	; dl = lower rigth column ; clr
  5177                              <1> 	; dh = lower right row ; rlr
  5178                              <1> vga_g_down_pl0:
  5179                              <1>  	;{for(i=rlr;i>=rul;i--)
  5180                              <1>         ; if((i<rul+nblines)||(nblines==0))
  5181 00002936 08C0                <1> 	or	al, al
  5182 00002938 741C                <1> 	jz	short vga_g_down_pl2
  5183 0000293A 88C4                <1> 	mov	ah, al
  5184 0000293C 00EC                <1> 	add	ah, ch
  5185                              <1> 	;jc	short vga_g_down_pl2	
  5186 0000293E 86F5                <1> 	xchg	ch, dh
  5187 00002940 38E5                <1> 	cmp	ch, ah
  5188 00002942 7212                <1> 	jb	short vga_g_down_pl2
  5189 00002944 88EC                <1> 	mov	ah, ch
  5190 00002946 28C4                <1> 	sub	ah, al ; ah = i - nblines
  5191                              <1> 	; else
  5192                              <1> 	; vgamem_copy_pl4(cul,i,i-nblines,cols,nbcols,cheight);
  5193 00002948 E826FDFFFF          <1> 	call	vgamem_copy_pl4
  5194                              <1> vga_g_down_pl1:
  5195 0000294D 86EE                <1> 	xchg	dh, ch
  5196 0000294F FECE                <1> 	dec	dh 
  5197 00002951 38EE                <1> 	cmp	dh, ch
  5198 00002953 73E1                <1> 	jnb	short vga_g_down_pl0
  5199 00002955 C3                  <1> 	retn
  5200                              <1> 
  5201                              <1> vga_g_down_pl2:
  5202                              <1> 	; vgamem_fill_pl4(cul,i,cols,nbcols,cheight,attr);
  5203 00002956 E886FDFFFF          <1> 	call	vgamem_fill_pl4
  5204 0000295B EBF0                <1> 	jmp	short vga_g_down_pl1
  5205                              <1> 
  5206                              <1> 
  5207                              <1> 
  5208                              <1> ; 27/06/2016 - TRDOS 386 (TRDOS v2.0)
  5209                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  5210                              <1> 
  5211                              <1> ;-----	ROUTINE TO MOVE ONE ROW OF INFORMATION
  5212                              <1> 
  5213                              <1> _R17:
  5214 0000295D 0FB6CA              <1> 	movzx	ecx, dl			; NUMBER OF BYTES IN THE ROW
  5215 00002960 56                  <1> 	push	esi
  5216 00002961 57                  <1> 	push	edi			; SAVE POINTERS
  5217 00002962 F3A4                <1> 	rep	movsb			; MOVE THE EVEN FIELD
  5218 00002964 5F                  <1> 	pop	edi
  5219 00002965 5E                  <1> 	pop	esi
  5220 00002966 6681C60020          <1> 	add	si, 2000h
  5221 0000296B 6681C70020          <1> 	add	di, 2000h		; POINT TO THE ODD FIELD
  5222 00002970 56                  <1> 	push	esi
  5223 00002971 57                  <1> 	push	edi			; SAVE THE POINTERS
  5224 00002972 88D1                <1> 	mov	cl, dl			; COUNT BACK
  5225 00002974 F3A4                <1> 	rep	movsb			; MOVE THE ODD FIELD
  5226 00002976 5F                  <1> 	pop	edi
  5227 00002977 5E                  <1> 	pop	esi			; POINTERS BACK
  5228 00002978 C3                  <1> 	retn				; RETURN TO CALLER
  5229                              <1> 
  5230                              <1> ;-----	CLEAR A SINGLE ROW
  5231                              <1> 
  5232                              <1> _R18:
  5233 00002979 0FB6CA              <1> 	movzx	ecx, dl			; NUMBER OF BYTES IN FIELD
  5234 0000297C 57                  <1> 	push	edi			; SAVE POINTER
  5235 0000297D F3AA                <1> 	rep	stosb			; STORE THE NEW VALUE
  5236 0000297F 5F                  <1> 	pop	edi			; POINTER BACK
  5237 00002980 6681C70020          <1> 	add	di, 2000h		; POINT TO ODD FIELD
  5238 00002985 57                  <1> 	push	edi
  5239 00002986 88D1                <1> 	mov	cl, dl
  5240 00002988 F3AA                <1> 	rep	stosb			; FILL THE ODD FIELD
  5241 0000298A 5F                  <1> 	pop	edi
  5242 0000298B C3                  <1> 	retn				; RETURN TO CALLER
  5243                              <1> 
  5244                              <1> ; 03/08/2022 - TRDOS 386 Kernel v2.0.5
  5245                              <1> ; 04/07/2016
  5246                              <1> ; 01/07/2016
  5247                              <1> ; 30/06/2016 - TRDOS 386 (TRDOS v2.0)
  5248                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  5249                              <1> ;--------------------------------------------------
  5250                              <1> ; GRAPHICS WRITE
  5251                              <1> ;  THIS ROUTINE WRITES THE ASCII CHARACTER TO THE CURRENT
  5252                              <1> ;  POSITION ON THE SCREEN.
  5253                              <1> ; ENTRY --
  5254                              <1> ;  AL = CHARACTER TO WRITE
  5255                              <1> ;  BL = COLOR ATTRIBUTE TO BE USED FOR FOREGROUND COLOR
  5256                              <1> ;	IF BIT 7 IS SET, THE CHAR IS XOR'D INTO THE REGEN BUFFER
  5257                              <1> ;	(0 IS USED FOR THE BACKGROUND COLOR)
  5258                              <1> ;  CX = NUMBER OF CHARS TO WRITE
  5259                              <1> ;  DS = DATA SEGMENT
  5260                              <1> ;  ES = REGEN SEGMENT
  5261                              <1> ; EXIT --
  5262                              <1> ;  NOTHING IS RETURNED
  5263                              <1> ;
  5264                              <1> ; GRAPHICS READ
  5265                              <1> ;  THIS ROUTINE READS THE ASCII CHARACTER AT THE CURRENT CURSOR
  5266                              <1> ;  POSITION ON THE SCREEN BY MATCHING THE DOTS ON THE SCREEN TO THE
  5267                              <1> ;  CHARACTER GENERATOR CODE POINTS
  5268                              <1> ; ENTRY --
  5269                              <1> ;  NONE (0 IS ASSUMED AS THE BACKGROUND COLOR)
  5270                              <1> ; EXIT --
  5271                              <1> ;  AL = CHARACTER READ AT THAT POSITION (0 RETURNED IF NONE FOUND)
  5272                              <1> ;
  5273                              <1> ; FOR BOTH ROUTINES, THE IMAGES USED TO FORM CHARS ARE CONTAINED IN ROM
  5274                              <1> ;  FOR THE 1ST 128 CHARS.  TO ACCESS CHARS IN THE SECOND HALF, THE USER
  5275                              <1> ;  MUST INITIALIZE THE VECTOR AT INTERRUPT 1FH (LOCATION 0007CH) TO
  5276                              <1> ;  POINT TO THE USER SUPPLIED TABLE OF GRAPHIC IMAGES (8X8 BOXES).
  5277                              <1> ;  FAILURE TO DO SO WILL CAUSE IN STRANGE RESULTS
  5278                              <1> ;-----------------------------------------------------
  5279                              <1> 
  5280                              <1> GRAPHICS_WRITE:
  5281 0000298C 25FF000000          <1> 	and 	eax, 0FFh		; ZERO TO HIGH OF CODE POINT
  5282 00002991 50                  <1> 	push	eax			; SAVE CODE POINT VALUE
  5283                              <1> 
  5284                              <1> ;-----	DETERMINE POSITION IN REGEN BUFFER TO PUT CODE POINTS
  5285                              <1> 
  5286 00002992 E846010000          <1> 	call	S26			; FIND LOCATION IN REGEN BUFFER
  5287 00002997 89C7                <1> 	mov	edi, eax		; REGEN POINTER IN DI
  5288                              <1> 
  5289                              <1> ;-----	DETERMINE REGION TO GET CODE POINTS FROM
  5290                              <1> 
  5291 00002999 58                  <1> 	pop	eax			; RECOVER CODE POINT
  5292                              <1> 
  5293 0000299A BE[54530100]        <1> 	mov	esi, CRT_CHAR_GEN	; OFFSET OF IMAGES
  5294                              <1> 
  5295                              <1> ;-----	DETERMINE GRAPHICS MODE IN OPERATION
  5296                              <1> 					; DETERMINE_MODE
  5297                              <1> 	;sal	ax, 3			; MULTIPLY CODE POINT VALUE BY 8
  5298                              <1> 	; 03/08/2022
  5299 0000299F C1E003              <1> 	sal	eax, 3
  5300 000029A2 01C6                <1> 	add	esi, eax		; SI HAS OFFSET OF DESIRED CODES
  5301                              <1> 	
  5302 000029A4 803D[DE670000]06    <1> 	cmp	byte [CRT_MODE], 6
  5303 000029AB 7231                <1> 	jc	short S6		; TEST FOR MEDIUM RESOLUTION MODE
  5304                              <1> 
  5305                              <1> ;-----	HIGH RESOLUTION MODE
  5306                              <1> 
  5307 000029AD 81C700800B00        <1> 	add	edi, 0B8000h
  5308                              <1> S1:					; HIGH_CHAR
  5309 000029B3 57                  <1> 	push	edi			; SAVE REGEN POINTER
  5310 000029B4 56                  <1> 	push	esi			; SAVE CODE POINTER
  5311 000029B5 B604                <1> 	mov	dh, 4			; NUMBER OF TIMES THROUGH LOOP
  5312                              <1> S2:
  5313 000029B7 AC                  <1> 	lodsb				; GET BYTE FROM CODE POINTS
  5314 000029B8 F6C380              <1> 	test	bl, 80h			; SHOULD WE USE THE FUNCTION
  5315 000029BB 7515                <1> 	jnz	short S5		; TO PUT CHAR IN
  5316 000029BD AA                  <1> 	stosb				; STORE IN REGEN BUFFER
  5317 000029BE AC                  <1> 	lodsb
  5318                              <1> S4:
  5319 000029BF 8887FF1F0000        <1> 	mov	[edi+2000h-1], al	; STORE IN SECOND HALF
  5320 000029C5 83C74F              <1> 	add	edi, 79			; MOVE TO NEXT ROW IN REGEN
  5321 000029C8 FECE                <1> 	dec	dh			; DONE WITH LOOP
  5322 000029CA 75EB                <1> 	jnz	short S2
  5323 000029CC 5E                  <1> 	pop	esi
  5324 000029CD 5F                  <1> 	pop	edi			; RECOVER REGEN POINTER
  5325 000029CE 47                  <1> 	inc	edi			; POINT TO NEXT CHAR POSITION
  5326 000029CF E2E2                <1> 	loop	S1			; MORE CHARS TO WRITE
  5327 000029D1 C3                  <1> 	retn
  5328                              <1> 
  5329                              <1> S5:
  5330 000029D2 3207                <1> 	xor	al, [edi]		; EXCLUSIVE OR WITH CURRENT
  5331 000029D4 AA                  <1> 	stosb				; STORE THE CODE POINT
  5332 000029D5 AC                  <1> 	lodsb				; AGAIN FOR ODD FIELD
  5333 000029D6 3287FF1F0000        <1> 	xor	al, [edi+2000h-1]
  5334 000029DC EBE1                <1> 	jmp	short S4		; BACK TO MAINSTREAM
  5335                              <1> 
  5336                              <1> ;-----	MEDIUM RESOLUTION WRITE
  5337                              <1> S6:					; MED_RES_WRITE
  5338 000029DE 88DA                <1> 	mov	dl, bl			; SAVE HIGH COLOR BIT
  5339                              <1> 	; 03/08/2022
  5340 000029E0 D1E7                <1> 	sal	edi, 1
  5341                              <1> 	;sal	di, 1			; OFFSET*2 SINCE 2 BYTES/CHAR
  5342                              <1> 					; EXPAND BL TO FULL WORD OF COLOR
  5343 000029E2 80E303              <1> 	and	bl, 3			; ISOLATE THE COLOR BITS ( LOW 2 BITS )
  5344 000029E5 B055                <1> 	mov	al, 055h		; GET BIT CONVERSION MULTIPLIER
  5345 000029E7 F6E3                <1> 	mul	bl			; EXPAND 2 COLOR BITS TO 4 REPLICATIONS
  5346 000029E9 88C3                <1> 	mov	bl, al			; PLACE BACK IN WORK REGISTER
  5347 000029EB 88C7                <1> 	mov	bh, al			; EXPAND TO 8 REPLICATIONS OF COLOR BITS
  5348 000029ED 81C700800B00        <1> 	add	edi, 0B8000h
  5349                              <1> S7:                                     ; MED_CHAR
  5350 000029F3 57                  <1> 	push	edi			; SAVE REGEN POINTER
  5351 000029F4 56                  <1> 	push	esi			; SAVE THE CODE POINTER
  5352 000029F5 B604                <1> 	mov	dh, 4			; NUMBER OF LOOPS
  5353                              <1> S8:
  5354 000029F7 AC                  <1> 	lodsb				; GET CODE POINT
  5355 000029F8 E8B1000000          <1> 	call	S21			; DOUBLE UP ALL THE BITS
  5356 000029FD 6621D8              <1> 	and	ax, bx			; CONVERT TO FOREGROUND COLOR ( 0 BACK )
  5357 00002A00 86C4                <1> 	xchg	ah, al			; SWAP HIGH/LOW BYTES FOR WORD MOVE
  5358 00002A02 F6C280              <1> 	test	dl, 80h			; IS THIS XOR FUNCTION
  5359 00002A05 7403                <1> 	jz	short S9		; NO, STORE IT IN AS IS
  5360 00002A07 663307              <1> 	xor	ax, [edi]		; DO FUNCTION WITH LOW/HIGH
  5361                              <1> S9:
  5362 00002A0A 668907              <1> 	mov	[edi], ax		; STORE FIRST BYTE HIGH, SECOND LOW
  5363 00002A0D AC                  <1> 	lodsb				; GET CODE POINT
  5364 00002A0E E89B000000          <1> 	call	S21
  5365 00002A13 6621D8              <1> 	and	ax, bx			; CONVERT TO COLOR
  5366 00002A16 86C4                <1> 	xchg	ah, al			; SWAP HIGH/LOW BYTES FOR WORD MOVE
  5367 00002A18 F6C280              <1> 	test	dl, 80h			; AGAIN, IS THIS XOR FUNCTION
  5368 00002A1B 7407                <1> 	jz	short _S10		; NO, JUST STORE THE VALUES
  5369 00002A1D 66338700200000      <1> 	xor	ax, [edi+2000h]		; FUNCTION WITH FIRST HALF LOW
  5370                              <1> _S10:
  5371 00002A24 66898700200000      <1> 	mov	[edi+2000h], ax		; STORE SECOND PORTION HIGH
  5372 00002A2B 6683C750            <1> 	add	di, 80			; POINT TO NEXT LOCATION
  5373 00002A2F FECE                <1> 	dec	dh
  5374 00002A31 75C4                <1> 	jnz	short S8		; KEEP GOING
  5375 00002A33 5E                  <1> 	pop	esi			; RECOVER CODE POINTER
  5376 00002A34 5F                  <1> 	pop	edi			; RECOVER REGEN POINTER
  5377 00002A35 47                  <1> 	inc	edi			; POINT TO NEXT CHAR POSITION
  5378 00002A36 47                  <1> 	inc	edi
  5379 00002A37 E2BA                <1> 	loop	S7			; MORE TO WRITE
  5380 00002A39 C3                  <1> 	retn
  5381                              <1> 
  5382                              <1> ; 03/08/2022 - TRDOS 386 Kernel v2.0.5
  5383                              <1> ; 04/07/2016
  5384                              <1> ; 01/07/2016
  5385                              <1> ; 30/06/2016 - TRDOS 386 (TRDOS v2.0)
  5386                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  5387                              <1> ;----------------------------------------
  5388                              <1> ; GRAPHICS READ
  5389                              <1> ;----------------------------------------
  5390                              <1> GRAPHICS_READ:
  5391 00002A3A E89E000000          <1> 	call	S26			; CONVERTED TO OFFSET IN REGEN
  5392 00002A3F 89C6                <1> 	mov	esi, eax		; SAVE IN SI
  5393 00002A41 81C600800B00        <1> 	add	esi, 0B8000h		; 01/07/2016
  5394 00002A47 83EC08              <1> 	sub	esp, 8			; ALLOCATE SPACE FOR THE READ CODE POINT
  5395 00002A4A 89E5                <1> 	mov	ebp, esp		; POINTER TO SAVE AREA
  5396                              <1> 
  5397                              <1> ;-----	DETERMINE GRAPHICS MODES
  5398 00002A4C B604                <1> 	mov	dh, 4			; number of passes ; 01/07/2016
  5399 00002A4E 803D[DE670000]06    <1> 	cmp	byte [CRT_MODE], 6
  5400 00002A55 7219                <1> 	jc	short S12		; MEDIUM RESOLUTION
  5401                              <1> 
  5402                              <1> ;-----	HIGH RESOLUTION READ
  5403                              <1> ;-----	GET VALUES FROM REGEN BUFFER AND CONVERT TO CODE POINT
  5404                              <1> 	;mov	dh,4			; NUMBER OF PASSES
  5405                              <1> S11:
  5406 00002A57 8A06                <1> 	mov	al, [esi] 		; GET FIRST BYTE
  5407 00002A59 884500              <1> 	mov	[ebp], al 		; SAVE IN STORAGE AREA
  5408 00002A5C 45                  <1> 	inc	ebp			; NEXT LOCATION
  5409 00002A5D 8A8600200000        <1> 	mov	al, [esi+2000h]		; GET LOWER REGION BYTE
  5410 00002A63 884500              <1> 	mov	[ebp], al 		; ADJUST AND STORE
  5411 00002A66 45                  <1> 	inc	ebp
  5412 00002A67 83C650              <1> 	add	esi, 80			; POINTER INTO REGEN
  5413 00002A6A FECE                <1> 	dec	dh			; LOOP CONTROL
  5414 00002A6C 75E9                <1> 	jnz	short S11		; DO IT SOME MORE
  5415 00002A6E EB1C                <1> 	jmp	short S14		; GO MATCH THE SAVED CODE POINTS
  5416                              <1> 
  5417                              <1> ;-----	MEDIUM RESOLUTION READ
  5418                              <1> S12:	
  5419                              <1> 	;sal	si, 1			; OFFSET*2 SINCE 2 BYTES/CHAR
  5420                              <1> 	; 03/08/2022
  5421 00002A70 D1E6                <1> 	sal	esi, 1
  5422                              <1> 	;mov	dh, 4			; NUMBER OF PASSES
  5423                              <1> S13:
  5424 00002A72 E84B000000          <1> 	call	S23			; GET BYTES FROM REGEN INTO SINGLE SAVE
  5425 00002A77 81C6FE1F0000        <1> 	add	esi, 2000h-2		; GO TO LOWER REGION
  5426 00002A7D E840000000          <1> 	call	S23			; GET THIS PAIR INTO SAVE
  5427 00002A82 81EEB21F0000        <1> 	sub	esi, 2000h-80+2		; ADJUST POINTER BACK INTO UPPER
  5428 00002A88 FECE                <1> 	dec	dh
  5429 00002A8A 75E6                <1> 	jnz	short S13		; KEEP GOING UNTIL ALL 8 DONE
  5430                              <1> 
  5431                              <1> ;-----	SAVE AREA HAS CHARACTER IN IT, MATCH IT
  5432                              <1> S14:					; FIND_CHAR
  5433 00002A8C BF[54530100]        <1> 	mov	edi, CRT_CHAR_GEN	; ESTABLISH ADDRESSING
  5434 00002A91 83ED08              <1> 	sub	ebp, 8			; ADJUST POINTER TO START OF SAVE AREA
  5435 00002A94 89EE                <1> 	mov	esi, ebp
  5436                              <1> S15:
  5437                              <1> 	;mov	ax, 256			; NUMBER TO TEST AGAINST
  5438                              <1> 	; 03/08/2022
  5439 00002A96 29C0                <1> 	sub	eax, eax
  5440 00002A98 FEC4                <1> 	inc	ah
  5441                              <1> 	; eax = 256
  5442                              <1> S16:
  5443 00002A9A 56                  <1> 	push	esi			; SAVE SAVE AREA POINTER
  5444 00002A9B 57                  <1> 	push	edi			; SAVE CODE POINTER
  5445                              <1> 	;mov	ecx, 4			; NUMBER OF WORDS TO MATCH
  5446                              <1> 	;repe	cmpsw			; COMPARE THE 8 BYTES AS WORDS
  5447 00002A9C A7                  <1> 	cmpsd				; compare first 4 bytes 
  5448 00002A9D 7501                <1> 	jne	short S17		; 
  5449 00002A9F A7                  <1> 	cmpsd				; compare last 4 bytes
  5450                              <1> S17:
  5451 00002AA0 5F                  <1> 	pop	edi			; RECOVER THE POINTERS
  5452 00002AA1 5E                  <1> 	pop	esi
  5453                              <1> 	;jz	short S18		; IF ZERO FLAG SET, THEN MATCH OCCURRED
  5454 00002AA2 7406                <1> 	je	short S18
  5455                              <1> 	;				; NO MATCH, MOVE ON TO NEXT
  5456 00002AA4 83C708              <1> 	add	edi, 8			; NEXT CODE POINT
  5457                              <1> 	;dec	ax			; LOOP CONTROL
  5458                              <1> 	; 03/08/2022
  5459 00002AA7 48                  <1> 	dec	eax
  5460 00002AA8 75F0                <1> 	jnz	short S16		; DO ALL OF THEM
  5461                              <1> 
  5462                              <1> ;-----	CHARACTER IS FOUND ( AL=0 IF NOT FOUND )
  5463                              <1> S18:	
  5464 00002AAA 83C408              <1> 	add	esp, 8			; READJUST THE STACK, THROW AWAY SAVE
  5465 00002AAD C3                  <1> 	retn				; ALL DONE
  5466                              <1> 
  5467                              <1> ; 12/04/2021
  5468                              <1> ; 30/06/2016 - TRDOS 386 (TRDOS v2.0)
  5469                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  5470                              <1> ;--------------------------------------------
  5471                              <1> ; EXPAND BYTE
  5472                              <1> ;  THIS ROUTINE TAKES THE BYTE IN AL AND DOUBLES ALL
  5473                              <1> ;  OF THE BITS, TURNING THE 8 BITS INTO 16 BITS.
  5474                              <1> ;  THE RESULT IS LEFT IN AX
  5475                              <1> ;--------------------------------------------
  5476                              <1> S21:
  5477                              <1> 	; 03/08/2022
  5478                              <1> 	;push	cx			; SAVE REGISTER
  5479                              <1> 	; 12/04/2021
  5480 00002AAE 51                  <1> 	push	ecx
  5481                              <1> 	;;mov	cx, 8			; SHIFT COUNT REGISTER FOR ONE BYTE
  5482                              <1> 	;mov	cl, 8
  5483 00002AAF B408                <1> 	mov	ah, 8
  5484                              <1> S22:
  5485 00002AB1 D0C8                <1> 	ror	al, 1			; SHIFT BITS, LOW BIT INTO CARRY FLAG
  5486                              <1> 	;rcr	bp, 1			; MOVE CARRY FLAG (LOW BIT INTO RESULTS
  5487                              <1> 	;sar	bp, 1			; SIGN EXTEND HIGH BIT (DOUBLE IT)
  5488                              <1> 	; 03/08/2022
  5489 00002AB3 66D1D9              <1> 	rcr	cx, 1
  5490 00002AB6 66D1F9              <1> 	sar	cx, 1
  5491                              <1> 
  5492                              <1> 	;;loop	S22			; REPEAT FOR ALL 8 BITS
  5493                              <1> 	;dec	cl
  5494                              <1> 	;jnz	short S22
  5495                              <1> 	;xchg	ax, bp			; MOVE RESULTS TO PARAMETER REGISTER
  5496                              <1> 	; 03/08/5022
  5497 00002AB9 FECC                <1> 	dec	ah
  5498 00002ABB 75F4                <1> 	jnz	short S22
  5499 00002ABD 6689C8              <1> 	mov	ax, cx
  5500                              <1> 	;pop	cx			; RECOVER REGISTER
  5501                              <1> 	; 12/04/2021
  5502 00002AC0 59                  <1> 	pop	ecx
  5503 00002AC1 C3                  <1> 	retn				; ALL DONE
  5504                              <1> 
  5505                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  5506                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  5507                              <1> ;--------------------------------------------------
  5508                              <1> ; MED_READ_BYTE
  5509                              <1> ; THIS ROUTINE WILL TAKE 2 BYTES FROM THE REGEN BUFFER,
  5510                              <1> ;  COMPARE AGAINST THE CURRENT FOREGROUND COLOR, AND PLACE
  5511                              <1> ;  THE CORRESPONDING ON/OFF BIT PATTERN INTO THE CURRENT
  5512                              <1> ;  POSITION IN THE SAVE AREA
  5513                              <1> ; ENTRY --
  5514                              <1> ;  SI,DS = POINTER TO REGEN AREA OF INTEREST
  5515                              <1> ;  BX = EXPANDED FOREGROUND COLOR
  5516                              <1> ;  BP = POINTER TO SAVE AREA
  5517                              <1> ; EXIT --
  5518                              <1> ;  SI AND BP ARE INCREMENTED
  5519                              <1> ;----------------------------------------------------
  5520                              <1> S23:
  5521 00002AC2 66AD                <1> 	lodsw				; GET FIRST BYTE AND SECOND BYTES
  5522 00002AC4 86E0                <1> 	xchg	al, ah			; SWAP FOR COMPARE
  5523                              <1> 	;mov	cx, 0C000h		; 2 BIT MASK TO TEST THE ENTRIES
  5524                              <1> 	; 02/08/2022
  5525 00002AC6 29C9                <1> 	sub	ecx, ecx
  5526 00002AC8 B5C0                <1> 	mov	ch, 0C0h
  5527                              <1> 	; ecx = 0C000h
  5528                              <1> 	;mov	dl, 0			; RESULT REGISTER
  5529                              <1> 	; 03/08/2022
  5530 00002ACA 28D2                <1> 	sub	dl, dl
  5531                              <1> S24:
  5532                              <1> 	;test	ax, cx			; IS THIS SECTION BACKCROUND?
  5533                              <1>         ; 03/08/2022
  5534 00002ACC 85C8                <1> 	test	eax, ecx
  5535 00002ACE 7401                <1> 	jz	short S25               ; IF ZERO, IT IS BACKGROUND (CARRY=0)
  5536 00002AD0 F9                  <1> 	stc				; WASN'T, SO SET CARRY
  5537                              <1> S25:
  5538 00002AD1 D0D2                <1> 	rcl	dl, 1			; MOVE THAT BIT INTO THE RESULT
  5539                              <1> 	;shr	cx, 2			; MOVE THE MASK TO THE RIGHT BY 2 BITS
  5540                              <1> 	; 02/08/2022
  5541 00002AD3 C1E902              <1> 	shr	ecx, 2
  5542 00002AD6 73F4                <1> 	jnc	short S24		; DO IT AGAIN IF MASK DIDN'T FALL OUT
  5543 00002AD8 885500              <1> 	mov	[ebp], dl 		; STORE RESULT IN SAVE AREA
  5544 00002ADB 45                  <1> 	inc	ebp			; ADJUST POINTER
  5545 00002ADC C3                  <1> 	retn				; ALL DONE
  5546                              <1> 
  5547                              <1> ; 02/08/2022 - TRDOS 386 Kernel v2.0.5
  5548                              <1> ; 30/06/2016 - TRDOS 386 (TRDOS v2.0)
  5549                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  5550                              <1> ;-----------------------------------------
  5551                              <1> ; V4_POSITION
  5552                              <1> ;  THIS ROUTINE TAKES THE CURSOR POSITION CONTAINED IN
  5553                              <1> ;  THE MEMORY LOCATION, AND CONVERTS IT INTO AN OFFSET
  5554                              <1> ;  INTO THE REGEN BUFFER, ASSUMING ONE BYTE/CHAR.
  5555                              <1> ;  FOR MEDIUM RESOLUTION GRAPHICS, THE NUMBER MUST
  5556                              <1> ;  BE DOUBLED.
  5557                              <1> ; ENTRY -- NO REGISTERS,MEMORY LOCATION @CURSOR_POSN IS USED
  5558                              <1> ; EXIT--
  5559                              <1> ;  AX CONTAINS OFFSET INTO REGEN BUFFER
  5560                              <1> ;-----------------------------------------
  5561                              <1> S26:
  5562 00002ADD 0FB705[DE7C0100]    <1> 	movzx	eax, word [CURSOR_POSN]	; GET CURRENT CURSOR
  5563                              <1> GRAPH_POSN:
  5564 00002AE4 53                  <1> 	push	ebx			; SAVE REGISTER
  5565 00002AE5 0FB6D8              <1> 	movzx	ebx, al			; SAVE A COPY OF CURRENT CURSOR
  5566 00002AE8 A0[E0670000]        <1> 	mov	al, [CRT_COLS]		; GET BYTES PER COLUMN
  5567 00002AED F6E4                <1> 	mul	ah			; MULTIPLY BY ROWS
  5568                              <1> 	;shl	ax, 2			; MULTIPLY * 4 SINCE 4 ROWS/BYTE
  5569                              <1> 	; 02/08/2022
  5570 00002AEF C1E002              <1> 	shl	eax, 2
  5571 00002AF2 01D8                <1> 	add	eax, ebx		; DETERMINE OFFSET
  5572 00002AF4 5B                  <1> 	pop	ebx			; RECOVER POINTER
  5573 00002AF5 C3                  <1> 	retn				; ALL DONE
  5574                              <1> 
  5575                              <1> ; 03/08/2022 - TRDOS 386 Kernel v2.0.5
  5576                              <1> ; 09/07/2016
  5577                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  5578                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  5579                              <1> ;---------------------------------------------
  5580                              <1> ; SET_COLOR
  5581                              <1> ;	THIS ROUTINE WILL ESTABLISH THE BACKGROUND COLOR, THE OVERSCAN COLOR,
  5582                              <1> ;	AND THE FOREGROUND COLOR SET FOR MEDIUM RESOLUTION GRAPHICS
  5583                              <1> ; INPUT
  5584                              <1> ;	(BH) HAS COLOR ID
  5585                              <1> ;		IF BH=0, THE BACKGROUND COLOR VALUE IS SET
  5586                              <1> ;			FROM THE LOW BITS OF BL (0-31)
  5587                              <1> ;		IF BH=1, THE PALETTE SELECTION IS MADE
  5588                              <1> ;			BASED ON THE LOW BIT OF BL:
  5589                              <1> ;				0 = GREEN, RED, YELLOW FOR COLORS 1,2,3
  5590                              <1> ;				1 = BLUE, CYAN, MAGENTA FOR COLORS 1,2,3
  5591                              <1> ;	(BL) HAS THE COLOR VALUE TO BE USED
  5592                              <1> ; OUTPUT
  5593                              <1> ;	THE COLOR SELECTION IS UPDATED
  5594                              <1> ;----------------------------------------------
  5595                              <1> SET_COLOR:
  5596 00002AF6 803D[DE670000]07    <1>         cmp     byte [CRT_MODE], 7      ; 09/07/2016
  5597                              <1> 	;ja	VIDEO_RETURN		; nothing to do for VGA modes
  5598                              <1> 	; 03/08/2022
  5599 00002AFD 7605                <1> 	jna	short M21
  5600 00002AFF E92EF0FFFF          <1> 	jmp	VIDEO_RETURN
  5601                              <1> M21:
  5602                              <1> 	;mov	dx, [ADDR_6845]		; I/O PORT FOR PALETTE
  5603                              <1> 	;mov	dx, 3D4h
  5604                              <1> 	;add	dx, 5			; OVERSCAN PORT
  5605 00002B04 66BAD903            <1> 	mov	dx, 3D9h
  5606 00002B08 A0[E1670000]        <1> 	mov	al, [CRT_PALETTE] 	; GET THE CURRENT PALETTE VALUE
  5607 00002B0D 08FF                <1> 	or	bh, bh			; IS THIS COLOR 0?
  5608 00002B0F 7512                <1> 	jnz	short M20		; OUTPUT COLOR 1
  5609                              <1> 
  5610                              <1> ;-----	HANDLE COLOR 0 BY SETTING THE BACKGROUND COLOR
  5611                              <1> 
  5612 00002B11 24E0                <1> 	and	al, 0E0h 		; TURN OFF LOW 5 BITS OF CURRENT
  5613 00002B13 80E31F              <1> 	and	bl, 01Fh 		; TURN OFF HIGH 3 BITS OF INPUT VALUE
  5614 00002B16 08D8                <1> 	or	al, bl			; PUT VALUE INTO REGISTER
  5615                              <1> M19:					; OUTPUT THE PALETTE
  5616 00002B18 EE                  <1> 	out	dx, al			; OUTPUT COLOR SELECTION TO 3D9 PORT
  5617 00002B19 A2[E1670000]        <1> 	mov	[CRT_PALETTE], al 	; SAVE THE COLOR VALUE
  5618 00002B1E E90FF0FFFF          <1> 	jmp	VIDEO_RETURN
  5619                              <1> 
  5620                              <1> ;-----	HANDLE COLOR 1 BY SELECTING THE PALETTE TO BE USED
  5621                              <1> 
  5622                              <1> M20:
  5623 00002B23 24DF                <1> 	and	al, 0DFH 		; TURN OFF PALETTE SELECT BIT
  5624 00002B25 D0EB                <1> 	shr	bl, 1			; TEST THE LOW ORDER BIT OF BL
  5625 00002B27 73EF                <1> 	jnc	short M19		; ALREADY DONE
  5626 00002B29 0C20                <1> 	or	al, 20H			; TURN ON PALETTE SELECT BIT
  5627 00002B2B EBEB                <1> 	jmp	short M19		; GO DO IT
  5628                              <1> 
  5629                              <1> ; 03/08/2022 - TRDOS 386 Kernel v2.0.5
  5630                              <1> ; 09/07/2016
  5631                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  5632                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  5633                              <1> ;--------------------------------------------
  5634                              <1> ; READ DOT -- WRITE DOT
  5635                              <1> ; THESE ROUTINES WILL WRITE A DOT, OR READ THE
  5636                              <1> ;  DOT AT THE INDICATED LOCATION
  5637                              <1> ; ENTRY --
  5638                              <1> ;   DX = ROW (0-199)	(THE ACTUAL VALUE DEPENDS ON THE MODE)
  5639                              <1> ;   CX = COLUMN ( 0-639) ( THE VALUES ARE NOT RANGE CHECKED )
  5640                              <1> ;   AL = DOT VALUE TO WRITE (1,2 OR 4 BITS DEPENDING ON MODE,
  5641                              <1> ;	REQUIRED FOR WRITE DOT ONLY, RIGHT JUSTIFIED)
  5642                              <1> ;	BIT 7 OF AL = 1 INDICATES XOR THE VALUE INTO THE LOCATION
  5643                              <1> ;   DS = DATA SEGMENT
  5644                              <1> ;   ES = REGEN SEGMENT
  5645                              <1> ;
  5646                              <1> ; EXIT
  5647                              <1> ;	AL = DOT VALUE READ, RIGHT JUSTIFIED, READ ONLY
  5648                              <1> ;----------------------------------------------
  5649                              <1> 
  5650                              <1> READ_DOT:
  5651                              <1> 	; 09/07/2016
  5652 00002B2D 8A25[DE670000]      <1> 	mov	ah,  [CRT_MODE]
  5653 00002B33 80FC07              <1> 	cmp	ah, 7 ; 6!?
  5654 00002B36 760A                <1> 	jna	short read_dot_cga
  5655                              <1> 
  5656 00002B38 E8B3030000          <1> 	call	vga_read_pixel
  5657                              <1> 	; al = pixel value
  5658                              <1> read_dot_retn:	; 03/08/2022
  5659 00002B3D E9F5EFFFFF          <1> 	jmp	_video_return
  5660                              <1> 
  5661                              <1> read_dot_cga:
  5662                              <1> 	;je	VIDEO_RETURN ; 7	
  5663 00002B42 80FC04              <1> 	cmp	ah, 4 ; graphics ? 
  5664                              <1> 	;jb	VIDEO_RETURN ; no, text mode, nothing to do
  5665                              <1> 	; 03/08/2022
  5666 00002B45 72F6                <1> 	jb	short read_dot_retn
  5667                              <1> 
  5668 00002B47 E84F000000          <1> 	call	R3			; DETERMINE BYTE POSITION OF DOT
  5669 00002B4C 8A06                <1> 	mov	al, [esi]		; GET THE BYTE
  5670 00002B4E 20E0                <1> 	and	al, ah			; MASK OFF THE OTHER BITS IN THE BYTE
  5671 00002B50 D2E0                <1> 	shl	al, cl			; LEFT JUSTIFY THE VALUE
  5672 00002B52 88F1                <1> 	mov	cl, dh			; GET NUMBER OF BITS IN RESULT
  5673 00002B54 D2C0                <1> 	rol	al, cl			; RIGHT JUSTIFY THE RESULT
  5674                              <1> 	;jmp	VIDEO_RETURN		; RETURN FROM VIDEO I/O
  5675 00002B56 0FB6C0              <1> 	movzx	eax, al
  5676 00002B59 E9D9EFFFFF          <1> 	jmp	_video_return
  5677                              <1> 
  5678                              <1> ; 03/08/2022
  5679                              <1> ; 02/08/2022 - TRDOS 386 Kernel v2.0.5
  5680                              <1> ; 12/04/2021
  5681                              <1> ; 09/07/2016
  5682                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  5683                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  5684                              <1> 
  5685                              <1> WRITE_DOT:
  5686                              <1> 	; 09/07/2016
  5687 00002B5E 8A25[DE670000]      <1> 	mov	ah, [CRT_MODE]
  5688 00002B64 80FC07              <1> 	cmp	ah, 7 ; 6!?
  5689 00002B67 760A                <1> 	jna	short write_dot_cga
  5690                              <1> 	
  5691 00002B69 E8F2020000          <1> 	call	vga_write_pixel
  5692                              <1> write_dot_retn:	; 03/08/2022
  5693 00002B6E E9BFEFFFFF          <1> 	jmp	VIDEO_RETURN
  5694                              <1> 
  5695                              <1> write_dot_cga:
  5696                              <1> 	;je	VIDEO_RETURN ; 7	
  5697 00002B73 80FC04              <1> 	cmp	ah, 4 ; graphics ? 
  5698                              <1> 	;jb	VIDEO_RETURN ; no, text mode, nothing to do
  5699                              <1> 	; 03/08/2022
  5700 00002B76 72F6                <1> 	jb	short write_dot_retn
  5701                              <1> 
  5702                              <1> 	;;push	ax			; SAVE DOT VALUE
  5703                              <1> 	;push	ax			; TWICE
  5704                              <1> 	; 12/04/2021
  5705 00002B78 50                  <1> 	push	eax
  5706 00002B79 E81D000000          <1> 	call	R3			; DETERMINE BYTE POSITION OF THE DOT
  5707 00002B7E D2E8                <1> 	shr	al, cl			; SHIFT TO SET UP THE BITS FOR OUTPUT
  5708 00002B80 20E0                <1> 	and	al, ah			; STRIP OFF THE OTHER BITS
  5709 00002B82 8A0E                <1> 	mov	cl, [esi]		; GET THE CURRENT BYTE
  5710                              <1> 	;pop	bx			; RECOVER XOR FLAG
  5711                              <1> 	; 12/04/2021
  5712 00002B84 5B                  <1> 	pop	ebx
  5713 00002B85 F6C380              <1> 	test	bl, 80h			; IS IT ON
  5714 00002B88 750D                <1> 	jnz	short R2		; YES, XOR THE DOT
  5715 00002B8A F6D4                <1> 	not	ah			; SET MASK TO REMOVE THE INDICATED BITS
  5716 00002B8C 20E1                <1> 	and	cl, ah
  5717 00002B8E 08C8                <1> 	or	al, cl			; OR IN THE NEW VALUE OF THOSE BITS
  5718                              <1> R1:					; FINISH_DOT
  5719 00002B90 8806                <1> 	mov	[esi], al		; RESTORE THE BYTE IN MEMORY
  5720                              <1> 	;;pop	AX
  5721 00002B92 E99BEFFFFF          <1> 	jmp	VIDEO_RETURN		; RETURN FROM VIDEO I/O
  5722                              <1> R2:					; XOR_DOT
  5723 00002B97 30C8                <1> 	xor	al, cl			; EXCLUSIVE OR THE DOTS
  5724 00002B99 EBF5                <1> 	jmp	short R1		; FINISH UP THE WRITING
  5725                              <1> 
  5726                              <1> ; 02/08/2022 - TRDOS 386 Kernel v2.0.5
  5727                              <1> ; 01/07/2016 - TRDOS 386 (TRDOS v2.0)
  5728                              <1> ; VIDEO1.ASM - 24/03/1985 (IBM PC-AT BIOS source code)
  5729                              <1> 
  5730                              <1> ;----------------------------------------------
  5731                              <1> ; THIS SUBROUTINE DETERMINES THE REGEN BYTE LOCATION OF THE
  5732                              <1> ; INDICATED ROW COLUMN VALUE IN GRAPHICS MODE.
  5733                              <1> ; ENTRY --
  5734                              <1> ;  DX = ROW VALUE (0-199)
  5735                              <1> ;  CX = COLUMN VALUE (0-639)
  5736                              <1> ; EXIT --
  5737                              <1> ;  SI = OFFSET INTO REGEN BUFFER FOR BYTE OF INTEREST
  5738                              <1> ;  AH = MASK TO STRIP OFF THE BITS OF INTEREST
  5739                              <1> ;  CL = BITS TO SHIFT TO RIGHT JUSTIFY THE MASK IN AH
  5740                              <1> ;  DH = # BITS IN RESULT
  5741                              <1> ;  BX = MODIFIED
  5742                              <1> ;-----------------------------------------------
  5743                              <1> R3:
  5744                              <1> 
  5745                              <1> ;-----	DETERMINE 1ST BYTE IN INDICATED ROW BY MULTIPLYING ROW VALUE BY 40
  5746                              <1> ;-----	 ( LOW BIT OF ROW DETERMINES EVEN/ODD, 80 BYTES/ROW )
  5747                              <1> 
  5748 00002B9B 0FB7F0              <1> 	movzx	esi, ax			; WILL SAVE AL AND AH DURING OPERATION
  5749 00002B9E B028                <1> 	mov	al, 40
  5750 00002BA0 F6E2                <1> 	mul	dl			; AX= ADDRESS OF START OF INDICATED ROW
  5751 00002BA2 A808                <1> 	test	al, 08H 		; TEST FOR EVEN/ODD ROW CALCULATED
  5752 00002BA4 7404                <1> 	JZ	short R4		; JUMP IF EVEN ROW
  5753 00002BA6 6605D81F            <1> 	add	ax, 2000h-40		; OFFSET TO LOCATION OF ODD ROWS ADJUST
  5754                              <1> R4:					; EVEN_ROW
  5755                              <1> 	;xchg	si, ax			; MOVE POINTER TO (SI) AND RECOVER (AX)
  5756                              <1> 	; 02/08/2022
  5757 00002BAA 96                  <1> 	xchg	esi, eax
  5758 00002BAB 81C600800B00        <1> 	add	esi, 0B8000h
  5759                              <1> 	;mov	dx, cx			; COLUMN VALUE TO DX
  5760 00002BB1 0FB7D1              <1> 	movzx	edx, cx
  5761                              <1> 
  5762                              <1> ;-----	DETERMINE GRAPHICS MODE CURRENTLY IN EFFECT
  5763                              <1> 
  5764                              <1> ; SET UP THE REGISTERS ACCORDING TO THE MODE
  5765                              <1> ; CH = MASK FOR LOW OF COLUMN ADDRESS ( 7/3 FOR HIGH/MED RES )
  5766                              <1> ; CL = # OF ADDRESS BITS IN COLUMN VALUE ( 3/2 FOR H/M )
  5767                              <1> ; BL = MASK TO SELECT BITS FROM POINTED BYTE ( 80H/C0H FOR H/M )
  5768                              <1> ; BH = NUMBER OF VALID BITS IN POINTED BYTE ( 1/2 FOR H/M )
  5769                              <1> 
  5770 00002BB4 66BBC002            <1> 	mov	bx, 2C0h
  5771 00002BB8 66B90203            <1> 	mov	cx, 302h 		; SET PARMS FOR MED RES
  5772 00002BBC 803D[DE670000]06    <1> 	cmp	byte [CRT_MODE], 6
  5773 00002BC3 7208                <1> 	jc	short R5		; HANDLE IF MED RES
  5774 00002BC5 66BB8001            <1> 	mov	bx, 180h
  5775 00002BC9 66B90307            <1> 	mov	cx, 703h 		; SET PARMS FOR HIGH RES
  5776                              <1> 
  5777                              <1> ;-----	DETERMINE BIT OFFSET IN BYTE FROM COLUMN MASK
  5778                              <1> R5:
  5779 00002BCD 20D5                <1> 	and	ch, dl			; ADDRESS OF PEL WITHIN BYTE TO CH
  5780                              <1> 
  5781                              <1> ;-----	DETERMINE BYTE OFFSET FOR THIS LOCATION IN COLUMN
  5782                              <1> 
  5783                              <1> 	;shr	dx, cl			; SHIFT BY CORRECT AMOUNT
  5784                              <1> 	;add	si, dx			; INCREMENT THE POINTER
  5785                              <1> 	; 02/08/2022
  5786 00002BCF D3EA                <1> 	shr	edx, cl
  5787 00002BD1 01D6                <1> 	add	esi, edx
  5788 00002BD3 88FE                <1> 	mov	dh, bh			; GET THE # OF BITS IN RESULT TO DH
  5789                              <1> 
  5790                              <1> ;-----	MULTIPLY BH (VALID BITS IN BYTE) BY CH (BIT OFFSET)
  5791                              <1> 
  5792 00002BD5 28C9                <1> 	sub	cl, cl			; ZERO INTO STORAGE LOCATION
  5793                              <1> R6:
  5794 00002BD7 D0C8                <1> 	ror	al, 1			; LEFT JUSTIFY VALUE IN AL (FOR WRITE)
  5795 00002BD9 00E9                <1> 	add	cl, ch			; ADD IN THE BIT OFFSET VALUE
  5796 00002BDB FECF                <1> 	dec	bh			; LOOP CONTROL
  5797 00002BDD 75F8                <1> 	jnz	short R6		; ON EXIT, CL HAS COUNT TO RESTORE BITS
  5798 00002BDF 88DC                <1> 	mov	ah, bl			;  GET MASK TO AH
  5799 00002BE1 D2EC                <1> 	shr	ah, cl			;  MOVE THE MASK TO CORRECT LOCATION
  5800 00002BE3 C3                  <1> 	retn				;  RETURN WITH EVERYTHING SET UP
  5801                              <1> 
  5802                              <1> load_dac_palette:
  5803                              <1> 	; 02/08/2022 (TRDOS 386 Kernel v2.0.5)
  5804                              <1> 	; 29/07/2016
  5805                              <1> 	; 23/07/2016
  5806                              <1> 	; 03/07/2016 (TRDOS 386 = TRDOS v2.0)
  5807                              <1> 	; (set_mode_vga)
  5808                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5809                              <1> 	; vgabios-0.7a (2011)
  5810                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5811                              <1> 	; 'vgabios.c', 'load_dac_palette'
  5812                              <1> 	;
  5813                              <1> 	; Oracle VirtualBox 5.0.24 VGABios Source Code
  5814                              <1> 	; ('vgabios.c', 'vgatables.h', 'vgafonts.h', 'vgarom.asm')
  5815                              <1> 	;
  5816                              <1> 	; INPUT -> AH = DAC selection number (3, 2 or 1)
  5817                              <1> 	; OUTPUT -> ECX = 0, AX = 0
  5818                              <1> 	; (Modifed registers: EAX, ECX, EDX, ESI)
  5819                              <1> 	;
  5820 00002BE4 66BAC803            <1> 	mov	dx, 3C8h  ; VGAREG_DAC_WRITE_ADDRESS
  5821 00002BE8 28C0                <1> 	sub	al, al ; 0
  5822 00002BEA EE                  <1> 	out	dx, al ; 0 ; color index, always 0 at the beginning
  5823                              <1> 	;inc	dx   ; 3C9h ; VGAREG_DAC_DATA
  5824                              <1> 	; 02/08/2022
  5825 00002BEB FEC2                <1> 	inc	dl ; dx = 3C9h
  5826                              <1> 	;mov	ecx, 256   ; always 256*3 values
  5827                              <1> 	; 02/08/2022
  5828 00002BED 31C9                <1> 	xor	ecx, ecx
  5829 00002BEF FEC5                <1> 	inc	ch	
  5830                              <1> 	; ecx = 256
  5831                              <1> 
  5832                              <1> 	;push	esi
  5833 00002BF1 88E0                <1> 	mov	al, ah
  5834 00002BF3 B43F                <1> 	mov	ah, 3Fh	; 3Fh except DAC selection number 3
  5835 00002BF5 3C02                <1> 	cmp 	al, 2
  5836 00002BF7 7414                <1> 	je	short l_dac_p_2
  5837 00002BF9 7719                <1> 	ja	short l_dac_p_3
  5838 00002BFB 20C0                <1> 	and	al, al
  5839 00002BFD 7507                <1> 	jnz	short l_dac_p_1
  5840                              <1> l_dac_p_0:
  5841 00002BFF BE[144E0100]        <1> 	mov	esi, palette0
  5842 00002C04 EB15                <1> 	jmp	short l_dac_p_4	
  5843                              <1> l_dac_p_1:
  5844 00002C06 BE[D44E0100]        <1> 	mov	esi, palette1
  5845 00002C0B EB0E                <1> 	jmp	short l_dac_p_4
  5846                              <1> l_dac_p_2:
  5847 00002C0D BE[944F0100]        <1> 	mov	esi, palette2
  5848 00002C12 EB07                <1> 	jmp	short l_dac_p_4
  5849                              <1> l_dac_p_3:
  5850 00002C14 B4FF                <1> 	mov	ah, 0FFh ; dac registers
  5851 00002C16 BE[54500100]        <1> 	mov	esi, palette3
  5852                              <1> l_dac_p_4:
  5853 00002C1B AC                  <1> 	lodsb
  5854 00002C1C EE                  <1> 	out	dx, al  ; Red
  5855 00002C1D AC                  <1> 	lodsb
  5856 00002C1E EE                  <1> 	out	dx, al	; Green
  5857 00002C1F AC                  <1> 	lodsb
  5858 00002C20 EE                  <1> 	out	dx, al	; Blue
  5859 00002C21 20E4                <1> 	and	ah, ah
  5860 00002C23 7405                <1> 	jz	short l_dac_p_5	
  5861 00002C25 FECC                <1> 	dec	ah
  5862 00002C27 E2F2                <1> 	loop	l_dac_p_4
  5863                              <1> 	;pop	esi
  5864 00002C29 C3                  <1> 	retn
  5865                              <1> l_dac_p_5:
  5866                              <1> 	; 29/07/2016
  5867 00002C2A FEC9                <1> 	dec	cl
  5868 00002C2C 7407                <1> 	jz	short l_dac_p_7
  5869                              <1> 	;
  5870 00002C2E 28C0                <1> 	sub	al, al ; 0
  5871                              <1> l_dac_p_6:
  5872 00002C30 EE                  <1> 	out	dx, al ; outb(VGAREG_DAC_DATA,0);
  5873 00002C31 EE                  <1> 	out	dx, al
  5874 00002C32 EE                  <1> 	out	dx, al
  5875 00002C33 E2FB                <1> 	loop	l_dac_p_6
  5876                              <1> l_dac_p_7:
  5877                              <1> 	;pop	esi
  5878 00002C35 C3                  <1> 	retn
  5879                              <1> 
  5880                              <1> gray_scale_summing:
  5881                              <1> 	; 03/08/2022 (TRDOS 386 v2.0.5)
  5882                              <1> 	; 12/04/2021
  5883                              <1> 	; 03/07/2016 (TRDOS 386 = TRDOS v2.0)
  5884                              <1> 	; (set_mode_vga)
  5885                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5886                              <1> 	; vgabios-0.7a (2011)
  5887                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5888                              <1> 	; 'vgabios.c', 'biosfn_perform_gray_scale_summing'
  5889                              <1> 	;
  5890                              <1> 	; Oracle VirtualBox 5.0.24 VGABios Source Code
  5891                              <1> 	; ('vgabios.c', 'vgatables.h', 'vgafonts.h', 'vgarom.asm')
  5892                              <1> 	;
  5893                              <1> 
  5894                              <1> 	; INPUT -> EBX = Start address (color index <= 255)
  5895                              <1> 	;	   ECX = Count (<= 256)
  5896                              <1> 	; OUTPUT -> (E)CX = 0
  5897                              <1> 	; (Modifed registers: EAX, ECX, EDX, EBX)
  5898                              <1> 
  5899 00002C36 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5900 00002C3A EC                  <1> 	in	al, dx
  5901 00002C3B 30C0                <1> 	xor	al, al ; 0
  5902                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  5903                              <1> 	; 03/08/2022
  5904 00002C3D B2C0                <1> 	mov	dl, 0C0h
  5905 00002C3F EE                  <1> 	out	dx, al	; clear bit 5
  5906                              <1> 			; (while loading palette registers)
  5907                              <1> 	; set read address and switch to read mode
  5908                              <1> g_s_s_1:
  5909                              <1> 	;mov	dx, 3C7h ; VGAREG_DAC_READ_ADDRESS
  5910                              <1> 	; 03/08/2022
  5911 00002C40 B2C7                <1> 	mov	dl, 0C7h
  5912 00002C42 88D8                <1> 	mov	al, bl
  5913 00002C44 EE                  <1> 	out	dx, al
  5914                              <1> 	; get 6-bit wide RGB data values
  5915                              <1>  	; intensity = (0.3*Red)+(0.59*Green)+(0.11*Blue)
  5916                              <1> 	; i = ( ( 77*r + 151*g + 28*b ) + 0x80 ) >> 8;
  5917                              <1> 	;mov	dx, 3C9h ; VGAREG_DAC_DATA
  5918                              <1> 	; 03/08/2022
  5919 00002C45 B2C9                <1> 	mov	dl, 0C9h
  5920 00002C47 EC                  <1> 	in	al, dx ; red
  5921 00002C48 B44D                <1> 	mov	ah, 77 ; 0.3* Red
  5922 00002C4A F6E4                <1> 	mul	ah
  5923                              <1> 	;push	ax
  5924                              <1> 	; 12/04/2021
  5925 00002C4C 50                  <1> 	push	eax
  5926 00002C4D EC                  <1> 	in	al, dx ; green
  5927 00002C4E B497                <1> 	mov	ah, 151  ; 0.59 * Green
  5928 00002C50 F6E4                <1> 	mul	ah
  5929                              <1> 	;push	ax
  5930                              <1> 	; 12/04/2021
  5931 00002C52 50                  <1> 	push	eax
  5932 00002C53 EC                  <1> 	in	al, dx ; blue
  5933 00002C54 B41C                <1> 	mov	ah, 28 ; 0.11 * Blue
  5934 00002C56 F6E4                <1> 	mul	ah
  5935                              <1> 	;pop	dx
  5936                              <1> 	; 12/04/2021
  5937 00002C58 5A                  <1> 	pop	edx
  5938 00002C59 6601D0              <1> 	add	ax, dx
  5939                              <1> 	;pop	dx
  5940                              <1> 	; 12/04/2021
  5941 00002C5C 5A                  <1> 	pop	edx
  5942 00002C5D 6601D0              <1> 	add	ax, dx
  5943 00002C60 66058000            <1> 	add	ax, 80h  
  5944 00002C64 B03F                <1> 	mov	al, 3Fh
  5945 00002C66 38C4                <1> 	cmp	ah, al	; if(i>0x3f)i=0x3f
  5946 00002C68 7602                <1> 	jna	short g_s_s_2
  5947 00002C6A 88C4                <1> 	mov	ah, al
  5948                              <1> g_s_s_2:
  5949                              <1> 	;mov	dx, 3C8h  ; VGAREG_DAC_WRITE_ADDRESS
  5950                              <1> 	; 03/08/2022
  5951 00002C6C B2C8                <1> 	mov	dl, 0C8h
  5952 00002C6E 88D8                <1> 	mov	al, bl ; color index
  5953 00002C70 EE                  <1> 	out	dx, al
  5954 00002C71 88E0                <1> 	mov	al, ah ; intensity
  5955                              <1> 	;inc	dx ; 3C9h ; VGAREG_DAC_DATA
  5956                              <1> 	; 03/08/2022
  5957 00002C73 FEC2                <1> 	inc	dl
  5958 00002C75 EE                  <1> 	out	dx, al ; R (R=G=B)
  5959 00002C76 88E0                <1> 	mov	al, ah ; intensity
  5960 00002C78 EE                  <1> 	out	dx, al ; G (R=G=B)
  5961 00002C79 88E0                <1>  	mov	al, ah ; intensity
  5962 00002C7B EE                  <1> 	out	dx, al ; B (R=G=B)
  5963                              <1> 	;dec	cx
  5964                              <1> 	; 03/08/2022
  5965 00002C7C 49                  <1> 	dec	ecx
  5966 00002C7D 7404                <1> 	jz	short g_s_s_3
  5967 00002C7F FEC3                <1> 	inc	bl    ; next color index value
  5968 00002C81 EBBD                <1> 	jmp	short g_s_s_1
  5969                              <1> g_s_s_3:
  5970                              <1> 	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
  5971                              <1> 	; 03/08/2022
  5972 00002C83 B2DA                <1> 	mov	dl, 0DAh
  5973 00002C85 EC                  <1> 	in	al, dx
  5974 00002C86 B020                <1> 	mov	al, 20h
  5975                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  5976                              <1> 	; 03/08/2022
  5977 00002C88 B2C0                <1> 	mov	dl, 0C0h 
  5978 00002C8A EE                  <1> 	out	dx, al ; 20h -> set bit 5
  5979                              <1> 		        ; (after loading palette regs)
  5980 00002C8B C3                  <1> 	retn
  5981                              <1> 
  5982                              <1> vga_write_char_attr:
  5983                              <1> vga_write_char_only: 
  5984                              <1> 	; 08/07/2016 (TRDOS 386 = TRDOS v2.0)
  5985                              <1> 	;
  5986                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  5987                              <1> 	; vgabios-0.7a (2011)
  5988                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  5989                              <1> 	; 'vgabios.c', 'biosfn_write_char_attr'
  5990                              <1> 	; 'biosfn_write_char_only'
  5991                              <1> 
  5992                              <1> 	; INPUT ->
  5993                              <1> 	; [CRT_MODE] = current video mode (>7)
  5994                              <1> 	; CX = Count of characters to write
  5995                              <1> 	; AL = Character to write
  5996                              <1> 	; BL = Color of character
  5997                              <1> 	; OUTPUT ->
  5998                              <1> 	; Regen buffer updated
  5999                              <1>  
  6000 00002C8C 8A25[DE670000]      <1> 	mov 	ah, [CRT_MODE]
  6001 00002C92 668B15[DE7C0100]    <1> 	mov	dx, [CURSOR_POSN] ; cursor pos for page 0
  6002                              <1> 
  6003 00002C99 BE[FA670000]        <1> 	mov	esi, vga_modes
  6004 00002C9E 89F7                <1> 	mov	edi, esi
  6005 00002CA0 83C710              <1> 	add	edi, vga_mode_count
  6006                              <1> vga_wca_0:
  6007 00002CA3 AC                  <1> 	lodsb
  6008 00002CA4 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  6009 00002CA6 7405                <1> 	je	short vga_wca_2
  6010 00002CA8 39FE                <1> 	cmp	esi, edi
  6011 00002CAA 72F7                <1> 	jb	short vga_wca_0
  6012                              <1> vga_wca_1:
  6013 00002CAC C3                  <1> 	retn	; nothing to do
  6014                              <1> vga_wca_2:
  6015 00002CAD 83C64F              <1> 	add	esi, vga_memmodel - (vga_modes + 1)  
  6016                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  6017                              <1> 
  6018                              <1> 	; biosfn_write_char_attr (car,page,attr,count) 
  6019                              <1> 	; AL = car, page = 0, BL = attr, CX = count
  6020 00002CB0 803E04              <1> 	cmp	byte [esi], PLANAR4
  6021 00002CB3 741D                <1> 	je	short vga_wca_planar
  6022 00002CB5 803E03              <1> 	cmp	byte [esi], PLANAR1
  6023 00002CB8 7418                <1> 	je	short vga_wca_planar
  6024                              <1> vga_wca_linear8:
  6025                              <1> 	; while((count-->0) && (xcurs<nbcols))
  6026                              <1> 	; CX = count
  6027 00002CBA 6621C9              <1> 	and	cx, cx
  6028 00002CBD 74ED                <1> 	jz	short vga_wca_1
  6029 00002CBF 3A15[E0670000]      <1> 	cmp	dl, [CRT_COLS]
  6030 00002CC5 73E5                <1> 	jnb	short vga_wca_1
  6031                              <1> 	; write_gfx_char_lin(car,attr,xcurs,ycurs,nbcols);
  6032                              <1> 	; AL = car, BL = attr, DL = xcurs, DH = ycurs, 
  6033                              <1> 	; [CRT_COLS] = nbcols
  6034 00002CC7 E81E000000          <1> 	call	write_gfx_char_lin	 
  6035 00002CCC 6649                <1> 	dec	cx ; count
  6036 00002CCE FEC2                <1> 	inc	dl ; xcurs
  6037 00002CD0 EBE8                <1> 	jmp	short vga_wca_linear8
  6038                              <1> vga_wca_planar:
  6039                              <1> 	; while((count-->0) && (xcurs<nbcols))
  6040                              <1> 	; CX = count
  6041 00002CD2 6621C9              <1> 	and	cx, cx
  6042 00002CD5 74D5                <1> 	jz	short vga_wca_1
  6043 00002CD7 3A15[E0670000]      <1> 	cmp	dl, [CRT_COLS]
  6044 00002CDD 73CD                <1> 	jnb	short vga_wca_1
  6045                              <1> 	; write_gfx_char_pl4(car,attr,xcurs,ycurs,nbcols,cheight);
  6046                              <1> 	; AL = car, BL = attr, DL = xcurs, DH = ycurs, 
  6047                              <1> 	; [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight
  6048 00002CDF E8A7000000          <1> 	call	write_gfx_char_pl4
  6049 00002CE4 6649                <1> 	dec	cx ; count
  6050 00002CE6 FEC2                <1> 	inc	dl ; xcurs
  6051 00002CE8 EBE8                <1> 	jmp	short vga_wca_planar
  6052                              <1> 
  6053                              <1> write_gfx_char_lin:
  6054                              <1> 	; 02/08/2022 (TRDOS 386 v2.0.5)
  6055                              <1> 	; 08/01/2021
  6056                              <1> 	; 05/01/2021 (TRDOS 386 v2.0.3)
  6057                              <1> 	; 08/08/2016
  6058                              <1> 	; 31/07/2016
  6059                              <1> 	; 08/07/2016 (TRDOS 386 = TRDOS v2.0)
  6060                              <1> 	;
  6061                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  6062                              <1> 	; vgabios-0.7a (2011)
  6063                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  6064                              <1> 	; 'vgabios.c', 'write_gfx_char_lin'
  6065                              <1> 
  6066                              <1> 	; write_gfx_char_lin(car,attr,xcurs,ycurs,nbcols)
  6067                              <1> 	; INPUT ->
  6068                              <1> 	; AL = car, BL = attr, DL = xcurs, DH = ycurs, 
  6069                              <1> 	; [CRT_COLS] = nbcols
  6070                              <1> 	; OUTPUT ->
  6071                              <1> 	; Regen buffer updated
  6072                              <1> 
  6073 00002CEA 51                  <1> 	push	ecx
  6074 00002CEB 53                  <1> 	push	ebx
  6075 00002CEC 52                  <1> 	push	edx
  6076 00002CED 50                  <1> 	push	eax
  6077                              <1> 	; addr=xcurs*8+ycurs*nbcols*64;
  6078                              <1> 	; 08/08/2016
  6079 00002CEE 0FB6F0              <1> 	movzx	esi, al ; car
  6080                              <1> 	; 08/01/2021
  6081                              <1> 	;movzx	eax, dh ; ycurs
  6082                              <1> 	;mov	ah, [CRT_COLS] ; nbcols
  6083                              <1> 	;mul	ah
  6084 00002CF1 A0[E0670000]        <1> 	mov	al, [CRT_COLS]
  6085 00002CF6 F6E6                <1> 	mul	dh
  6086                              <1> 	;shl	ax, 6 ; * 64
  6087                              <1> 	;shl	ax, 3 ; 8 * ycurs * [CRT_COLS]
  6088                              <1> 	; 02/08/2022
  6089 00002CF8 C1E003              <1> 	shl	eax, 3
  6090                              <1> 	;sub	dh, dh
  6091                              <1> 	;shl	dx, 3 ; xcurs * 8
  6092                              <1> 	;movzx	edi, dx
  6093 00002CFB BF00000A00          <1> 	mov	edi, 0A0000h
  6094 00002D00 30F6                <1> 	xor	dh, dh
  6095 00002D02 6689D7              <1> 	mov	di, dx
  6096                              <1> 	;movzx	edi, dl
  6097 00002D05 66C1E703            <1> 	shl	di, 3 ; xcurs * 8
  6098                              <1> 	;xor	dh, dh
  6099 00002D09 8A15[E2670000]      <1> 	mov	dl, [CHAR_HEIGHT]
  6100 00002D0F 66F7E2              <1> 	mul	dx
  6101                              <1> 	; eax = ycurs*nbcols*8*[CHAR_HEIGHT]
  6102                              <1> 	;add	edi, eax ; addr
  6103                              <1> 	;add	edi, 0A0000h
  6104 00002D12 6601C7              <1> 	add	di, ax
  6105                              <1> 	;shl	si, 3 ; car * 8
  6106 00002D15 30E4                <1> 	xor	ah, ah
  6107 00002D17 A0[E2670000]        <1> 	mov	al, [CHAR_HEIGHT]
  6108 00002D1C 66F7E6              <1> 	mul	si
  6109 00002D1F 6689C6              <1> 	mov	si, ax
  6110                              <1> 	;; esi = src = car * 8
  6111                              <1> 	; esi = src = car * [CHAR_HEIGHT]
  6112                              <1> 	; i = 0
  6113                              <1> 	;add	esi, vgafont8 ; fdata [src+i]
  6114                              <1> 	; 08/08/2016
  6115 00002D22 A1[66890100]        <1> 	mov	eax, [VGA_INT43H]
  6116 00002D27 09C0                <1> 	or	eax, eax ; 0 ?
  6117 00002D29 743E                <1> 	jz	short wfxl_7 ; yes, default font
  6118                              <1> 	;cmp	eax, vgafont16
  6119                              <1>         ;je	short wgfxl_0
  6120                              <1> 	;cmp	eax, vgafont14
  6121                              <1> 	;je	short wgfxl_0
  6122                              <1> 	;cmp	eax, vgafont8
  6123                              <1> 	;je	short wgfxl_0
  6124                              <1> 	;; 05/01/2021 (TRDOS 386 v2.0.3)
  6125                              <1> 	;; user font  
  6126                              <1> 	;mov	eax, VGAFONTUSR ; 8x16 or 8x8 or 8x14 font
  6127                              <1> 	;			; (256 characters)
  6128                              <1> wgfxl_0:
  6129 00002D2B 01C6                <1> 	add	esi, eax
  6130                              <1> wgfxl_1:
  6131 00002D2D 28FF                <1> 	sub	bh, bh ; i = 0
  6132                              <1> wgfxl_2:
  6133                              <1> 	; for(i=0;i<8;i++)
  6134 00002D2F 57                  <1> 	push	edi ; addr
  6135 00002D30 0FB605[E0670000]    <1> 	movzx	eax, byte [CRT_COLS] ; nbcols
  6136 00002D37 F6E7                <1> 	mul	bh ; nbcols*i
  6137                              <1> 	;shl	ax, 3 ; i*nbcols*8
  6138                              <1>  	; 02/08/2022
  6139 00002D39 C1E003              <1> 	shl	eax, 3
  6140                              <1> 	; dest=addr+i*nbcols*8;
  6141 00002D3C 01C7                <1> 	add	edi, eax ; dest + j ; j = 0
  6142 00002D3E B180                <1> 	mov	cl, 80h ; mask = 0x80;
  6143                              <1> 	; esi = fdata + src + i
  6144                              <1> 	; for(j=0;j<8;j++)
  6145 00002D40 29D2                <1> 	sub	edx, edx ; j = 0
  6146                              <1> wgfxl_3:
  6147 00002D42 8A06                <1> 	mov	al, [esi] ; al = fdata[src+i]
  6148 00002D44 20C8                <1> 	and	al, cl ; if (fdata[src+i] & mask)
  6149 00002D46 7402                <1> 	jz	short wgfxl_4  ; data = 0, zf = 1
  6150 00002D48 88D8                <1> 	mov	al, bl ; data = attr;
  6151                              <1> wgfxl_4:
  6152                              <1> 	; write_byte(0xa000,dest+j,data);		
  6153 00002D4A AA                  <1> 	stosb  ; dest + j (+ 0A0000h)
  6154                              <1> 	;inc	dl ; j++
  6155                              <1> 	;cmp	dl, 8
  6156 00002D4B 80FA07              <1> 	cmp	dl, 7
  6157 00002D4E 720E                <1> 	jb	short wgfxl_5
  6158 00002D50 5F                  <1> 	pop	edi
  6159                              <1> 	; 08/08/2016
  6160                              <1> 	;cmp	bh, 7
  6161                              <1> 	;jnb	short wgfxl_6
  6162 00002D51 FEC7                <1> 	inc	bh ; i++
  6163 00002D53 3A3D[E2670000]      <1> 	cmp	bh, [CHAR_HEIGHT]
  6164 00002D59 7309                <1> 	jnb	short wgfxl_6
  6165 00002D5B 46                  <1> 	inc	esi
  6166 00002D5C EBD1                <1> 	jmp	short wgfxl_2
  6167                              <1> wgfxl_5:
  6168 00002D5E D0E9                <1> 	shr	cl, 1 ; mask >>= 1;
  6169 00002D60 FEC2                <1> 	inc	dl ; j++
  6170 00002D62 EBDE                <1>         jmp     short wgfxl_3
  6171                              <1> wgfxl_6:
  6172 00002D64 58                  <1> 	pop	eax
  6173 00002D65 5A                  <1> 	pop	edx
  6174 00002D66 5B                  <1> 	pop	ebx
  6175 00002D67 59                  <1> 	pop	ecx
  6176 00002D68 C3                  <1> 	retn
  6177                              <1> wfxl_7:
  6178                              <1> 	; 08/01/2021
  6179                              <1> 	; 05/01/2021
  6180                              <1> 	; Default font (8x8 or 8x14 or 8x16)
  6181 00002D69 A0[E2670000]        <1> 	mov	al, [CHAR_HEIGHT]
  6182 00002D6E 3C08                <1> 	cmp	al, 8
  6183 00002D70 7507                <1> 	jne	short wfxl_8
  6184 00002D72 B8[54530100]        <1> 	mov	eax, vgafont8
  6185 00002D77 EBB2                <1> 	jmp	short wgfxl_0
  6186                              <1> wfxl_8:
  6187 00002D79 3C0E                <1> 	cmp	al, 14
  6188 00002D7B 7507                <1> 	jne	short wfxl_9
  6189 00002D7D B8[545B0100]        <1> 	mov	eax, vgafont14
  6190 00002D82 EBA7                <1> 	jmp	short wgfxl_0
  6191                              <1> wfxl_9:
  6192 00002D84 B8[54690100]        <1> 	mov	eax, vgafont16
  6193 00002D89 EBA0                <1> 	jmp	short wgfxl_0
  6194                              <1> 
  6195                              <1> write_gfx_char_pl4:
  6196                              <1> 	; 02/08/2022 (TRDOS 386 Kernel v2.0.5)
  6197                              <1> 	; 08/08/2016
  6198                              <1> 	; 08/07/2016 (TRDOS 386 = TRDOS v2.0)
  6199                              <1> 	;
  6200                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  6201                              <1> 	; vgabios-0.7a (2011)
  6202                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  6203                              <1> 	; 'vgabios.c', 'write_gfx_char_pl4'
  6204                              <1> 
  6205                              <1> 	; write_gfx_char_pl4(car,attr,xcurs,ycurs,nbcols,cheight)
  6206                              <1> 	; INPUT ->
  6207                              <1> 	; AL = car, BL = attr, DL = xcurs, DH = ycurs, 
  6208                              <1> 	; [CRT_COLS] = nbcols, [CHAR_HEIGHT] = cheight
  6209                              <1> 	; OUTPUT ->
  6210                              <1> 	; Regen buffer updated
  6211                              <1> 
  6212 00002D8B 51                  <1> 	push	ecx
  6213 00002D8C 53                  <1> 	push	ebx
  6214 00002D8D 52                  <1> 	push	edx
  6215 00002D8E 50                  <1> 	push	eax
  6216                              <1> wgfxpl_f0:
  6217                              <1> 	; switch(cheight)
  6218 00002D8F 8A25[E2670000]      <1> 	mov	ah, [CHAR_HEIGHT]
  6219 00002D95 80FC10              <1> 	cmp	ah, 16 ; case 16:
  6220 00002D98 7507                <1> 	jne	short wgfxpl_f1
  6221                              <1> 	; fdata = &vgafont16;
  6222 00002D9A BE[54690100]        <1> 	mov	esi, vgafont16
  6223 00002D9F EB13                <1> 	jmp	short wgfxpl_f3
  6224                              <1> wgfxpl_f1:
  6225 00002DA1 80FC0E              <1> 	cmp	ah, 14 ; case 14:
  6226 00002DA4 7507                <1> 	jne	short wgfxpl_f2
  6227 00002DA6 BE[545B0100]        <1> 	mov	esi, vgafont14
  6228 00002DAB EB07                <1> 	jmp	short wgfxpl_f3
  6229                              <1> wgfxpl_f2:
  6230                              <1> 	; default:
  6231                              <1> 	;  fdata = &vgafont8;
  6232 00002DAD BE[54530100]        <1> 	mov	esi, vgafont8
  6233 00002DB2 B408                <1> 	mov	ah, 8	
  6234                              <1> wgfxpl_f3:
  6235                              <1> 	; al = car
  6236 00002DB4 F6E4                <1> 	mul	ah ; ah = cheight
  6237 00002DB6 25FFFF0000          <1> 	and	eax, 0FFFFh ; car * cheight
  6238                              <1> 	; src = car * cheight;
  6239 00002DBB 01C6                <1> 	add	esi, eax ; esi = fdata[src+i]
  6240                              <1> 	; addr=xcurs*8+ycurs*nbcols*64;
  6241 00002DBD 88F0                <1> 	mov	al, dh ; ycurs
  6242 00002DBF 8A25[E0670000]      <1> 	mov	ah, [CRT_COLS] ; nbcols
  6243 00002DC5 F6E4                <1> 	mul	ah
  6244                              <1> 	; 08/08/2016
  6245                              <1> 	;shl	ax, 6 ; * 64
  6246                              <1> 	;shl	ax, 3 ; * 8
  6247                              <1> 	; 02/08/2022
  6248 00002DC7 C1E003              <1> 	shl	eax, 3
  6249                              <1> 	;sub	dh, dh ; 0
  6250                              <1> 	;shl	dx, 3 ; xcurs * 8
  6251                              <1> 	;movzx	edi, dx
  6252 00002DCA 0FB6FA              <1> 	movzx	edi, dl
  6253                              <1> 	;shl	di, 3 ; xcurs * 8
  6254                              <1> 	; 02/08/2022
  6255 00002DCD C1E703              <1> 	shl	edi, 3
  6256 00002DD0 30F6                <1> 	xor	dh, dh
  6257 00002DD2 8A15[E2670000]      <1> 	mov	dl, [CHAR_HEIGHT]
  6258 00002DD8 66F7E2              <1> 	mul	dx
  6259                              <1> 	; eax = ycurs*nbcols*8*[CHAR_HEIGHT]
  6260 00002DDB 01C7                <1> 	add	edi, eax ; addr
  6261 00002DDD 81C700000A00        <1> 	add	edi, 0A0000h
  6262                              <1> 	;
  6263                              <1> 	; outw(VGAREG_SEQU_ADDRESS, 0x0f02);
  6264                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0205);
  6265 00002DE3 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  6266 00002DE7 66B8020F            <1> 	mov	ax, 0F02h
  6267 00002DEB 66EF                <1> 	out	dx, ax
  6268 00002DED 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  6269 00002DF1 66B80502            <1> 	mov	ax, 0205h
  6270 00002DF5 66EF                <1> 	out	dx, ax
  6271                              <1> 	;
  6272 00002DF7 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  6273 00002DFB F6C380              <1> 	test	bl, 80h ; if(attr&0x80)
  6274 00002DFE 7406                <1> 	jz	short wgfxpl_f4 ; else
  6275                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x1803);
  6276 00002E00 66B80318            <1> 	mov	ax, 1803h
  6277 00002E04 EB04                <1> 	jmp	short wgfxpl_f5
  6278                              <1> wgfxpl_f4:
  6279                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0003);
  6280 00002E06 66B80300            <1> 	mov	ax, 0003h	
  6281                              <1> wgfxpl_f5:
  6282 00002E0A 66EF                <1> 	out	dx, ax
  6283                              <1> 	;	
  6284 00002E0C 28FF                <1> 	sub	bh, bh ; i = 0
  6285                              <1> wgfxpl_0:
  6286                              <1> 	; for(i=0;i<cheight;i++)
  6287 00002E0E 57                  <1> 	push	edi ; addr
  6288 00002E0F 0FB605[E0670000]    <1> 	movzx	eax, byte [CRT_COLS] ; nbcols
  6289 00002E16 F6E7                <1> 	mul	bh ; nbcols*i
  6290                              <1> 	; dest=addr+i*nbcols
  6291 00002E18 01C7                <1> 	add	edi, eax ; dest
  6292 00002E1A B580                <1> 	mov	ch, 80h ; mask = 0x80;
  6293                              <1> 	; for(j=0;j<8;j++)
  6294 00002E1C 28C9                <1> 	sub	cl, cl ; j = 0
  6295                              <1> wgfxpl_1:
  6296 00002E1E D2ED                <1> 	shr	ch, cl ; mask=0x80>>j;
  6297                              <1> 	;
  6298                              <1> 	; outw(VGAREG_GRDC_ADDRESS, (mask << 8) | 0x08);
  6299                              <1>      	; read_byte(0xa000,dest);
  6300                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  6301 00002E20 88EC                <1> 	mov	ah, ch
  6302 00002E22 B008                <1> 	mov	al, 8
  6303 00002E24 66EF                <1> 	out	dx, ax
  6304 00002E26 8A07                <1> 	mov	al, [edi] ; ? (io delay?)
  6305                              <1> 	;
  6306 00002E28 28C0                <1> 	sub	al, al ; attr = 0
  6307                              <1> 	; if (fdata[src+i] & mask)
  6308 00002E2A 842E                <1> 	test	byte [esi], ch
  6309 00002E2C 7404                <1> 	jz	short wgfxpl_2  ; zf = 1
  6310                              <1> 	; write_byte(0xa000,dest,attr&0x0f);
  6311 00002E2E 88D8                <1> 	mov	al, bl ; attr;
  6312 00002E30 240F                <1> 	and	al, 0Fh	; attr&0x0f
  6313                              <1> wgfxpl_2:
  6314                              <1> 	; write_byte(0xa000,dest,0x00);		
  6315 00002E32 8807                <1> 	mov	[edi], al ; dest (+ 0A0000h)
  6316 00002E34 FEC1                <1> 	inc	cl ; j++
  6317 00002E36 80F908              <1> 	cmp	cl, 8
  6318 00002E39 72E3                <1> 	jb	short wgfxpl_1
  6319 00002E3B 5F                  <1> 	pop	edi
  6320                              <1> 	; 08/08/2016
  6321                              <1> 	;cmp	bh, 7
  6322                              <1> 	;jnb	short wgfxpl_3
  6323 00002E3C FEC7                <1> 	inc	bh ; i++
  6324 00002E3E 3A3D[E2670000]      <1> 	cmp	bh, [CHAR_HEIGHT]
  6325 00002E44 7303                <1> 	jnb	short wgfxpl_3
  6326 00002E46 46                  <1> 	inc	esi
  6327 00002E47 EBC5                <1> 	jmp	short wgfxpl_0
  6328                              <1> wgfxpl_3:
  6329                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  6330 00002E49 66B808FF            <1>   	mov	ax, 0FF08h
  6331 00002E4D 66EF                <1> 	out	dx, ax
  6332 00002E4F 66B80500            <1> 	mov	ax, 0005h
  6333 00002E53 66EF                <1> 	out	dx, ax
  6334 00002E55 66B80300            <1> 	mov	ax, 0003h
  6335 00002E59 66EF                <1> 	out	dx, ax
  6336                              <1> 	;
  6337 00002E5B 58                  <1> 	pop	eax
  6338 00002E5C 5A                  <1> 	pop	edx
  6339 00002E5D 5B                  <1> 	pop	ebx
  6340 00002E5E 59                  <1> 	pop	ecx
  6341 00002E5F C3                  <1> 	retn
  6342                              <1> 
  6343                              <1> vga_write_pixel:
  6344                              <1> 	; 02/08/2022 (TRDOS 386 Kerbel v2.0.5)
  6345                              <1> 	; 09/07/2016 (TRDOS 386 = TRDOS v2.0)
  6346                              <1> 	;
  6347                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  6348                              <1> 	; vgabios-0.7a (2011)
  6349                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  6350                              <1> 	; 'vgabios.c', 'biosfn_write_pixel'
  6351                              <1> 
  6352                              <1> 	; INPUT ->
  6353                              <1> 	; 	DX = row (0-239)
  6354                              <1> 	; 	CX = column (0-799)
  6355                              <1> 	; 	AL = pixel value
  6356                              <1> 	;	(AH = [CRT_MODE])
  6357                              <1> 	; OUTPUT ->
  6358                              <1> 	; 	none
  6359                              <1>  
  6360 00002E60 88C3                <1> 	mov	bl, al ; pixel value
  6361                              <1> 	;mov 	ah, [CRT_MODE]
  6362 00002E62 BE[FA670000]        <1> 	mov	esi, vga_modes
  6363 00002E67 89F7                <1> 	mov	edi, esi
  6364 00002E69 83C710              <1> 	add	edi, vga_mode_count
  6365                              <1> vga_wp_0:
  6366 00002E6C AC                  <1> 	lodsb
  6367 00002E6D 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  6368 00002E6F 7405                <1> 	je	short vga_wp_1
  6369 00002E71 39FE                <1> 	cmp	esi, edi
  6370 00002E73 72F7                <1> 	jb	short vga_wp_0
  6371 00002E75 C3                  <1> 	retn	; nothing to do
  6372                              <1> vga_wp_1:
  6373 00002E76 83C64F              <1> 	add	esi, vga_memmodel - (vga_modes + 1)  
  6374                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  6375 00002E79 BF00000A00          <1> 	mov	edi, 0A0000h
  6376                              <1> 	;
  6377 00002E7E 803E04              <1> 	cmp	byte [esi], PLANAR4
  6378 00002E81 741C                <1> 	je	short vga_wp_planar
  6379 00002E83 803E03              <1> 	cmp	byte [esi], PLANAR1
  6380 00002E86 7417                <1> 	je	short vga_wp_planar
  6381                              <1> vga_wp_linear8:
  6382                              <1> 	; addr=CX+DX*(read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8);
  6383 00002E88 0FB605[E0670000]    <1> 	movzx	eax, byte [CRT_COLS] ; = [VGA_COLS] ; nbcols
  6384                              <1>      	;shl	ax, 3 ; * 8
  6385                              <1> 	; 02/08/2022
  6386 00002E8F C1E003              <1> 	shl	eax, 3
  6387 00002E92 66F7E2              <1> 	mul	dx
  6388 00002E95 50                  <1> 	push	eax
  6389                              <1> 	;mov	edi, 0A0000h
  6390 00002E96 6601CF              <1> 	add	di, cx
  6391 00002E99 58                  <1> 	pop	eax
  6392 00002E9A 01C7                <1> 	add	edi, eax ; addr
  6393                              <1> 	; write_byte(0xa000,addr,AL);
  6394 00002E9C 881F                <1> 	mov	[edi], bl
  6395 00002E9E C3                  <1> 	retn    
  6396                              <1> vga_wp_planar:
  6397                              <1> 	; addr = CX/8+DX*read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
  6398 00002E9F 0FB7C1              <1> 	movzx	eax, cx
  6399 00002EA2 66C1E803            <1> 	shr	ax, 3 ; CX/8
  6400 00002EA6 50                  <1> 	push	eax
  6401 00002EA7 28E4                <1> 	sub	ah, ah ; 0
  6402 00002EA9 A0[E0670000]        <1> 	mov	al, [CRT_COLS] ; = [VGA_COLS] ; nbcols
  6403 00002EAE 66F7E2              <1> 	mul	dx
  6404                              <1> 	;mov	edi, 0A0000h
  6405 00002EB1 6601C7              <1>         add     di, ax
  6406 00002EB4 58                  <1> 	pop	eax
  6407 00002EB5 01C7                <1> 	add	edi, eax ; addr
  6408 00002EB7 80E107              <1> 	and	cl, 7
  6409 00002EBA B580                <1> 	mov	ch, 80h ; mask
  6410 00002EBC D2ED                <1> 	shr	ch, cl 	; mask = 0x80 >> (CX & 0x07);
  6411                              <1> 	
  6412                              <1> 	; outw(VGAREG_GRDC_ADDRESS, (mask << 8) | 0x08);
  6413 00002EBE 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  6414 00002EC2 88EC                <1> 	mov	ah, ch
  6415 00002EC4 B008                <1> 	mov	al, 8
  6416 00002EC6 66EF                <1> 	out	dx, ax
  6417                              <1> 	; outw(VGAREG_GRDC_ADDRESS, 0x0205);
  6418 00002EC8 66B80502            <1> 	mov	ax, 0205h
  6419 00002ECC 66EF                <1> 	out	dx, ax
  6420                              <1> 	; data = read_byte(0xa000,addr);
  6421 00002ECE 8A07                <1> 	mov	al, [edi] ; (delay?)	
  6422                              <1> 	; if (AL & 0x80)
  6423                              <1> 	; {
  6424                              <1> 	;  outw(VGAREG_GRDC_ADDRESS, 0x1803);
  6425                              <1> 	; }
  6426 00002ED0 F6C380              <1> 	test	bl, 80h
  6427 00002ED3 7406                <1> 	jz	short vga_wp_2
  6428 00002ED5 66B80318            <1> 	mov	ax, 1803h
  6429 00002ED9 66EF                <1> 	out	dx, ax
  6430                              <1> vga_wp_2:	
  6431                              <1> 	; write_byte(0xa000,addr,AL);
  6432 00002EDB 881F                <1> 	mov	[edi], bl
  6433                              <1> 	;
  6434                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  6435 00002EDD 66B808FF            <1>   	mov	ax, 0FF08h
  6436 00002EE1 66EF                <1> 	out	dx, ax
  6437 00002EE3 66B80500            <1> 	mov	ax, 0005h
  6438 00002EE7 66EF                <1> 	out	dx, ax
  6439 00002EE9 66B80300            <1> 	mov	ax, 0003h
  6440 00002EED 66EF                <1> 	out	dx, ax
  6441                              <1> 	;
  6442 00002EEF C3                  <1> 	retn
  6443                              <1> 
  6444                              <1> vga_read_pixel: 
  6445                              <1> 	; 02/08/2022 (TRDOS 386 Kernel v2.0.5)
  6446                              <1> 	; 09/07/2016 (TRDOS 386 = TRDOS v2.0)
  6447                              <1> 	;
  6448                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  6449                              <1> 	; vgabios-0.7a (2011)
  6450                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  6451                              <1> 	; 'vgabios.c', 'biosfn_read_pixel'
  6452                              <1> 
  6453                              <1> 	; INPUT ->
  6454                              <1> 	; 	DX = row (0-239)
  6455                              <1> 	; 	CX = column (0-799)
  6456                              <1> 	;	(AH = [CRT_MODE])
  6457                              <1> 	; OUTPUT ->
  6458                              <1> 	; 	AL = pixel value
  6459                              <1> 	 
  6460                              <1> 	;mov 	ah, [CRT_MODE]
  6461 00002EF0 BE[FA670000]        <1> 	mov	esi, vga_modes
  6462 00002EF5 89F7                <1> 	mov	edi, esi
  6463 00002EF7 83C710              <1> 	add	edi, vga_mode_count
  6464                              <1> vga_rp_0:
  6465 00002EFA AC                  <1> 	lodsb
  6466 00002EFB 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  6467 00002EFD 7405                <1> 	je	short vga_rp_1
  6468 00002EFF 39FE                <1> 	cmp	esi, edi
  6469 00002F01 72F7                <1> 	jb	short vga_rp_0
  6470 00002F03 C3                  <1> 	retn	; nothing to do
  6471                              <1> vga_rp_1:
  6472 00002F04 83C64F              <1> 	add	esi, vga_memmodel - (vga_modes + 1)  
  6473                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  6474 00002F07 BF00000A00          <1> 	mov	edi, 0A0000h
  6475                              <1> 	;
  6476 00002F0C 803E04              <1> 	cmp	byte [esi], PLANAR4
  6477 00002F0F 741C                <1> 	je	short vga_rp_planar
  6478 00002F11 803E03              <1> 	cmp	byte [esi], PLANAR1
  6479 00002F14 7417                <1> 	je	short vga_rp_planar
  6480                              <1> vga_rp_linear8:
  6481                              <1> 	; addr=CX+DX*(read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8);
  6482 00002F16 0FB605[E0670000]    <1> 	movzx	eax, byte [CRT_COLS] ; = [VGA_COLS] ; nbcols
  6483                              <1>      	;shl	ax, 3 ; * 8
  6484                              <1> 	; 02/08/2022
  6485 00002F1D C1E003              <1> 	shl	eax, 3
  6486 00002F20 66F7E2              <1> 	mul	dx
  6487 00002F23 50                  <1> 	push	eax
  6488                              <1> 	;mov	edi, 0A0000h
  6489 00002F24 6601CF              <1> 	add	di, cx
  6490 00002F27 58                  <1> 	pop	eax
  6491 00002F28 01C7                <1> 	add	edi, eax ; addr
  6492                              <1> 	; attr=read_byte(0xa000,addr);
  6493 00002F2A 8A07                <1> 	mov	al, [edi] ; pixel value
  6494 00002F2C C3                  <1> 	retn    
  6495                              <1> vga_rp_planar:
  6496                              <1> 	; addr = CX/8+DX*read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
  6497 00002F2D 0FB7C1              <1> 	movzx	eax, cx
  6498 00002F30 66C1E803            <1> 	shr	ax, 3 ; CX/8
  6499 00002F34 50                  <1> 	push	eax
  6500 00002F35 28E4                <1> 	sub	ah, ah ; 0
  6501 00002F37 A0[E0670000]        <1> 	mov	al, [CRT_COLS] ; = [VGA_COLS] ; nbcols
  6502 00002F3C 66F7E2              <1> 	mul	dx
  6503                              <1> 	;mov	edi, 0A0000h
  6504 00002F3F 6601C7              <1>         add     di, ax
  6505 00002F42 58                  <1> 	pop	eax
  6506 00002F43 01C7                <1> 	add	edi, eax ; addr
  6507 00002F45 80E107              <1> 	and	cl, 7
  6508 00002F48 B580                <1> 	mov	ch, 80h ; mask
  6509 00002F4A D2ED                <1> 	shr	ch, cl 	; mask = 0x80 >> (CX & 0x07);
  6510                              <1> 	; attr = 0x00;
  6511 00002F4C 30DB                <1> 	xor	bl, bl ; attr = bl = 0, 
  6512 00002F4E 30C9                <1> 	xor	cl, cl ; i = cl = 0
  6513                              <1> 	; for(i=0;i<4;i++)
  6514                              <1>       	; {
  6515                              <1>        	;  outw(VGAREG_GRDC_ADDRESS, (i << 8) | 0x04);
  6516                              <1>        	;  data = read_byte(0xa000,addr) & mask;
  6517                              <1>        	;  if (data > 0) attr |= (0x01 << i);
  6518                              <1>       	; }
  6519                              <1> vga_rp_2:
  6520 00002F50 88CC                <1> 	mov	ah, cl ; i << 8
  6521 00002F52 B004                <1> 	mov	al, 4  ; | 0x04
  6522 00002F54 66BACE03            <1> 	mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  6523 00002F58 66EF                <1> 	out	dx, ax
  6524                              <1> 	; data = read_byte(0xa000,addr) & mask;
  6525 00002F5A 8A07                <1> 	mov	al, [edi]
  6526 00002F5C 20E8                <1> 	and	al, ch ; & mask
  6527                              <1> 	; if (data > 0) attr |= (0x01 << i);
  6528 00002F5E 08C0                <1> 	or	al, al
  6529 00002F60 7408                <1> 	jz	short vga_rp_3 ; al = 0 
  6530 00002F62 B701                <1> 	mov	bh, 1
  6531 00002F64 D2E7                <1> 	shl	bh, cl ; (0x01 << i)
  6532 00002F66 08FB                <1> 	or	bl, bh ; attr |= (0x01 << i)
  6533 00002F68 88D8                <1> 	mov	al, bl ; pixel value	
  6534                              <1> vga_rp_3:	
  6535 00002F6A C3                  <1> 	retn
  6536                              <1> 
  6537                              <1> vga_beeper:
  6538                              <1> 	; 04/08/2016  (TRDOS 386 = TRDOS v2.0)
  6539 00002F6B FB                  <1> 	sti
  6540                              <1> 	;mov	bh, [ACTIVE_PAGE]
  6541 00002F6C E917F4FFFF          <1>         jmp     beeper_gfx
  6542                              <1> 
  6543                              <1> vga_write_teletype:
  6544                              <1> 	; 03/08/2022 (TRDOS 386 Kernel v2.0.5)
  6545                              <1> 	; 12/04/2021 (TRDOS 386 v2.0.3, 32 bit push/pop)
  6546                              <1> 	; 09/12/2017
  6547                              <1> 	; 06/08/2016
  6548                              <1> 	; 04/08/2016
  6549                              <1> 	; 01/08/2016
  6550                              <1> 	; 31/07/2016
  6551                              <1> 	; 09/07/2016 (TRDOS 386 = TRDOS v2.0)
  6552                              <1> 	;
  6553                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  6554                              <1> 	; vgabios-0.7a (2011)
  6555                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  6556                              <1> 	; 'vgabios.c', 'biosfn_write_teletype'
  6557                              <1> 	; 'biosfn_write_char_only'
  6558                              <1> 
  6559                              <1> 	; INPUT ->
  6560                              <1> 	; [CRT_MODE] = current video mode (>7)
  6561                              <1> 	; AL = Character to write
  6562                              <1> 	; BL = Color of character
  6563                              <1> 	; OUTPUT ->
  6564                              <1> 	; Regen buffer updated
  6565                              <1> 
  6566                              <1> 	; biosfn_write_teletype (car, page, attr, flag) 
  6567                              <1> 	; car = character (AL)
  6568                              <1> 	; page = 0
  6569                              <1> 	; attr = color (BL)
  6570                              <1> 	; 'flag' not used
  6571                              <1> 
  6572 00002F71 8A25[DE670000]      <1> 	mov 	ah, [CRT_MODE]
  6573 00002F77 88C7                <1> 	mov	bh, al ; character
  6574 00002F79 668B15[DE7C0100]    <1> 	mov	dx, [CURSOR_POSN] ; cursor pos for page 0
  6575                              <1> 
  6576 00002F80 BE[02680000]        <1> 	mov	esi, vga_g_modes
  6577 00002F85 89F7                <1> 	mov	edi, esi
  6578 00002F87 83C708              <1> 	add	edi, vga_g_mode_count
  6579                              <1> vga_wtty_0:
  6580 00002F8A AC                  <1> 	lodsb
  6581 00002F8B 38E0                <1> 	cmp	al, ah ; [CRT_MODE]
  6582 00002F8D 7405                <1> 	je	short vga_wtty_2
  6583 00002F8F 39FE                <1> 	cmp	esi, edi
  6584 00002F91 72F7                <1> 	jb	short vga_wtty_0
  6585                              <1> vga_wtty_1:
  6586 00002F93 C3                  <1> 	retn	; nothing to do
  6587                              <1> vga_wtty_2:
  6588 00002F94 80FF07              <1> 	cmp	bh, 07h ; bell (beep)
  6589 00002F97 74D2                <1> 	je	short vga_beeper  ; u11
  6590 00002F99 80FF08              <1> 	cmp	bh, 08h ; backspace
  6591 00002F9C 7508                <1> 	jne	short vga_wtty_3
  6592                              <1> 	; if(xcurs>0)xcurs--;
  6593 00002F9E 08D2                <1> 	or	dl, dl ; xcurs (column)
  6594 00002FA0 74F1                <1> 	jz	short vga_wtty_1
  6595 00002FA2 FECA                <1> 	dec	dl ; xcurs--;
  6596 00002FA4 EB55                <1>         jmp     short vga_wtty_12 
  6597                              <1> vga_wtty_3:			
  6598 00002FA6 80FF0D              <1> 	cmp	bh, 0Dh ; carriage return (\r)
  6599 00002FA9 7504                <1> 	jne	short vga_wtty_4
  6600                              <1> 	; xcurs=0;
  6601 00002FAB 28D2                <1> 	sub	dl, dl ; 0
  6602 00002FAD EB4C                <1>         jmp     short vga_wtty_12 
  6603                              <1> vga_wtty_4:	
  6604 00002FAF 80FF0A              <1> 	cmp	bh, 0Ah ; new line (\n)
  6605 00002FB2 7504                <1> 	jne	short vga_wtty_5
  6606                              <1> 	; ycurs++;
  6607 00002FB4 FEC6                <1> 	inc	dh ; next row
  6608 00002FB6 EB5E                <1>         jmp     short vga_wtty_11
  6609                              <1> vga_wtty_5:
  6610 00002FB8 80FF09              <1> 	cmp 	bh, 09h ; tab stop
  6611 00002FBB 7523                <1> 	jne	short vga_wtty_8
  6612 00002FBD 88D0                <1> 	mov	al, dl
  6613                              <1> 	;cbw
  6614 00002FBF 30E4                <1> 	xor	ah, ah ; 09/12/2017
  6615 00002FC1 B108                <1> 	mov	cl, 8
  6616 00002FC3 F6F1                <1> 	div	cl
  6617 00002FC5 28E1                <1> 	sub	cl, ah
  6618                              <1> 	;
  6619 00002FC7 B720                <1> 	mov	bh, 20h ; space
  6620                              <1> vga_wtty_6: ; tab stop loop
  6621                              <1> 	;push	cx
  6622                              <1> 	;push	bx
  6623                              <1> 	; 12/04/2021
  6624 00002FC9 51                  <1> 	push	ecx
  6625 00002FCA 53                  <1> 	push	ebx
  6626 00002FCB E810000000          <1> 	call	vga_wtty_8
  6627                              <1> 	;pop	bx  ; bh = character, bl = color
  6628                              <1> 	;pop	cx
  6629                              <1> 	; 12/04/2021
  6630 00002FD0 5B                  <1> 	pop	ebx  ; bh = character, bl = color
  6631 00002FD1 59                  <1> 	pop	ecx
  6632 00002FD2 FEC9                <1> 	dec	cl
  6633 00002FD4 7409                <1> 	jz	short vga_wtty_7
  6634 00002FD6 668B15[DE7C0100]    <1> 	mov	dx, [CURSOR_POSN] ; new cursor position (pg 0)
  6635 00002FDD EBEA                <1> 	jmp	short vga_wtty_6
  6636                              <1> vga_wtty_7:
  6637 00002FDF C3                  <1> 	retn
  6638                              <1> 	;
  6639                              <1> vga_wtty_8:
  6640 00002FE0 83C64F              <1> 	add	esi, vga_g_memmodel - (vga_g_modes + 1)  
  6641                              <1> 	; [ESI] = VGA memory model number (LINEAR8, PLANAR4, PLANAR1)
  6642 00002FE3 BF00000A00          <1> 	mov	edi, 0A0000h
  6643                              <1> 	;
  6644 00002FE8 88F8                <1> 	mov	al, bh ; character
  6645                              <1> 	;
  6646 00002FEA 803E04              <1> 	cmp	byte [esi], PLANAR4
  6647 00002FED 7414                <1> 	je	short vga_wtty_planar
  6648 00002FEF 803E03              <1> 	cmp	byte [esi], PLANAR1
  6649 00002FF2 740F                <1> 	je	short vga_wtty_planar
  6650                              <1> vga_wtty_linear8:
  6651                              <1> 	; write_gfx_char_lin(car,attr,xcurs,ycurs,nbcols);
  6652                              <1> 	; AL = car, BL = attr (color), DL = xcurs, DH = ycurs, 
  6653                              <1> 	; [CRT_COLS] = nbcols
  6654 00002FF4 E8F1FCFFFF          <1> 	call	write_gfx_char_lin
  6655 00002FF9 EB0D                <1> 	jmp	short vga_wtty_9
  6656                              <1> 
  6657                              <1> vga_wtty_12:
  6658                              <1> 	; 09/07/2016
  6659                              <1> 	; set cursor position
  6660                              <1> 	; NOTE: Hardware cursor position will not be set
  6661                              <1> 	;   in any VGA modes (>7)
  6662                              <1> 	;   But, cursor position will be saved into
  6663                              <1> 	;   [CURSOR_POSN].
  6664                              <1> 	;   TRDOS 386 (TRDOS v2.0) uses only one page
  6665                              <1> 	;   (page 0) for all graphics modes.
  6666                              <1> 
  6667 00002FFB 668915[DE7C0100]    <1> 	mov	[CURSOR_POSN], dx ; save cursor pos for pg 0
  6668                              <1> 	; 04/08/2016
  6669                              <1> 	;mov	bh, [ACTIVE_PAGE] ; = 0
  6670                              <1> 	;call	_set_cpos
  6671 00003002 C3                  <1> 	retn
  6672                              <1> 
  6673                              <1> vga_wtty_planar:
  6674                              <1> 	; write_gfx_char_pl4(car,attr,xcurs,ycurs,nbcols,cheight);
  6675                              <1> 	; AL = car, BL = attr (color), DL = xcurs, DH = ycurs, 
  6676                              <1> 	; [CRT_COLS]= nbcols, [CHAR_HEIGHT] = cheight
  6677 00003003 E883FDFFFF          <1> 	call	write_gfx_char_pl4
  6678                              <1> vga_wtty_9:
  6679 00003008 FEC2                <1> 	inc	dl ; xcurs++;
  6680                              <1> vga_wtty_10:
  6681                              <1> 	; Do we need to wrap ?
  6682                              <1> 	; if(xcurs==nbcols)
  6683 0000300A 3A15[E0670000]      <1> 	cmp	dl, [CRT_COLS] ; [VGA_COLS]
  6684 00003010 7204                <1> 	jb	short vga_wtty_11 ; no
  6685 00003012 28D2                <1> 	sub	dl, dl ; xcurs=0;
  6686 00003014 FEC6                <1> 	inc	dh ;  ycurs++;
  6687                              <1> vga_wtty_11:
  6688                              <1> 	; Do we need to scroll ?
  6689                              <1> 	; if(ycurs==nbrows)
  6690 00003016 3A35[E6670000]      <1> 	cmp	dh, [VGA_ROWS]
  6691 0000301C 72DD                <1> 	jb	short vga_wtty_12 ; no
  6692                              <1> 	;
  6693                              <1> 	; biosfn_scroll (nblines,attr,rul,cul,rlr,clr,page,dir)
  6694                              <1> 	; al = nblines = 1, bl = attr (color) = 0
  6695                              <1> 	; ch = rul, cl = cul, dh = rlr, dl = clr, page = 0
  6696                              <1> 	; dir = SCROLL_UP
  6697                              <1> 	
  6698 0000301E B001                <1> 	mov	al, 1
  6699 00003020 28DB                <1> 	sub	bl, bl ; 0 ; blank/black line (attr=0) will be used
  6700                              <1> 	;sub	cx, cx ; 0,0
  6701                              <1> 	; 03/08/2022
  6702 00003022 29C9                <1> 	sub	ecx, ecx
  6703                              <1> 
  6704                              <1> 	; 06/08/2016
  6705 00003024 8A35[E6670000]      <1> 	mov	dh, [VGA_ROWS]
  6706 0000302A FECE                <1> 	dec	dh ; nbrows -1
  6707                              <1> 
  6708                              <1> 	;push	dx ; 04/08/2016
  6709                              <1> 	; 12/04/2021
  6710 0000302C 52                  <1> 	push	edx
  6711 0000302D 8A15[E0670000]      <1> 	mov	dl, [CRT_COLS]
  6712 00003033 FECA                <1> 	dec	dl ; nbcols -1
  6713                              <1> 	
  6714 00003035 8A25[DE670000]      <1> 	mov	ah, [CRT_MODE]
  6715                              <1> 	
  6716                              <1> 	; biosfn_scroll(0x01,0x00,0,0,nbrows-1,nbcols-1,page,SCROLL_UP);
  6717 0000303B E843F5FFFF          <1> 	call	vga_graphics_up
  6718                              <1> 	; 04/08/2016
  6719                              <1> 	;pop	dx
  6720                              <1> 	; 12/04/2021
  6721 00003040 5A                  <1> 	pop	edx
  6722                              <1> 
  6723                              <1> 	;dec	dh ; ycurs-=1
  6724 00003041 EBB8                <1> 	jmp	short vga_wtty_12 
  6725                              <1> 
  6726                              <1> font_setup:
  6727                              <1> 	; 03/08/2022 (TRDOS 386 v2.0.5)
  6728                              <1> 	; 09/01/2021 (TRDOS 386 v2.0.3)
  6729                              <1> 	; 09/07/2016
  6730                              <1> 	; character generator (font loading) functions
  6731                              <1> 	;
  6732                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  6733                              <1> 	; vgabios-0.7a (2011)
  6734                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  6735                              <1> 	; 'vgabios.c', 'int10_func'
  6736                              <1> 
  6737                              <1> 	; AX = 1100H ; Load User-Defined Font (EGA/VGA)
  6738                              <1> 	;
  6739                              <1>         ; BH =  height of each character (bytes per character definition)
  6740                              <1>         ; (BL = font block to load (EGA: 0-3; VGA: 0-7))
  6741                              <1> 	; CX =  number of characters to redefine (<=256)
  6742                              <1>         ; DX =  ASCII code of the first character defined at ES:BP
  6743                              <1>         ; EBP =	address of font-definition information
  6744                              <1> 	;	(in user's memory space)
  6745                              <1> 
  6746                              <1> 	; case 0x11:
  6747                              <1>      	; switch(GET_AL())
  6748                              <1>       	; {
  6749                              <1> 	; case 0x00:
  6750                              <1>         ; case 0x10:
  6751                              <1>         ; biosfn_load_text_user_pat(GET_AL(),ES,BP,CX,DX,GET_BL(),GET_BH());
  6752                              <1>         ; break;
  6753                              <1> 
  6754                              <1> 	; AX = 1110H ; Load and Activate User-Defined Font (EGA/VGA)
  6755 00003043 08C0                <1> 	or	al, al ; 0
  6756 00003045 7404                <1> 	jz	short font_setup_0
  6757 00003047 3C10                <1> 	cmp	al, 10h
  6758 00003049 7511                <1> 	jne	short font_setup_1	
  6759                              <1> font_setup_0:
  6760 0000304B E8CE000000          <1> 	call	transfer_user_fonts
  6761 00003050 721C                <1> 	jc	short font_setup_error
  6762 00003052 E8AD010000          <1> 	call	load_text_user_pat
  6763 00003057 E9D6EAFFFF          <1>         jmp     VIDEO_RETURN 
  6764                              <1> font_setup_1:
  6765                              <1> 	; AX = 1101H ; Load ROM 8x14 Character Set (EGA/VGA)
  6766                              <1> 	; case 0x01:
  6767                              <1>         ; case 0x11:
  6768                              <1>         ; biosfn_load_text_8_14_pat(GET_AL(),GET_BL());
  6769                              <1>         ; break;
  6770 0000305C 3C01                <1> 	cmp	al, 1
  6771 0000305E 7404                <1> 	je	short font_setup_2
  6772 00003060 3C11                <1> 	cmp	al, 11h
  6773 00003062 7511                <1> 	jne	short font_setup_3	
  6774                              <1> font_setup_2:
  6775                              <1> 	; AX = 1111H ; Load and Activate ROM 8x14 Character Set (EGA/VGA)
  6776                              <1> 	; (BL = font block to load (EGA: 0-3; VGA: 0-7))
  6777 00003064 E8C9020000          <1> 	call	load_text_8_14_pat
  6778 00003069 E9C4EAFFFF          <1>         jmp     VIDEO_RETURN
  6779                              <1> font_setup_error:
  6780 0000306E 29C0                <1> 	sub	eax, eax ; 0 -> fonts could not be loaded
  6781 00003070 E9C2EAFFFF          <1> 	jmp	_video_return
  6782                              <1> font_setup_3:
  6783                              <1> 	; AX = 1102H ; Load ROM 8x8 Character Set (EGA/VGA)
  6784                              <1> 	; case 0x02:
  6785                              <1>         ; case 0x12:
  6786                              <1>         ; biosfn_load_text_8_8_pat(GET_AL(),GET_BL());
  6787                              <1>         ; break;
  6788 00003075 3C02                <1> 	cmp	al, 2
  6789 00003077 7404                <1> 	je	short font_setup_4
  6790 00003079 3C12                <1> 	cmp	al, 12h
  6791 0000307B 750A                <1> 	jne	short font_setup_5	
  6792                              <1> font_setup_4:
  6793                              <1> 	; AX = 1112H ; Load and Activate ROM 8x8 Character Set (EGA/VGA)
  6794                              <1> 	; (BL = font block to load (EGA: 0-3; VGA: 0-7))
  6795 0000307D E8E1020000          <1> 	call	load_text_8_8_pat
  6796 00003082 E9ABEAFFFF          <1>         jmp     VIDEO_RETURN
  6797                              <1> font_setup_5:
  6798                              <1> 	; AX = 1104H ; Load ROM 8x16 Character Set (EGA/VGA)
  6799                              <1> 	; case 0x04:
  6800                              <1>         ; case 0x14:
  6801                              <1>         ; biosfn_load_text_8_16_pat(GET_AL(),GET_BL());
  6802                              <1>         ; break;
  6803 00003087 3C04                <1> 	cmp	al, 4
  6804 00003089 7404                <1> 	je	short font_setup_6
  6805 0000308B 3C14                <1> 	cmp	al, 14h
  6806 0000308D 750A                <1> 	jne	short font_setup_7	
  6807                              <1> font_setup_6:
  6808                              <1> 	; AX = 1114H ; Load and Activate ROM 8x16 Character Set (EGA/VGA)
  6809                              <1> 	; (BL = font block to load (EGA: 0-3; VGA: 0-7))
  6810 0000308F E819030000          <1> 	call	load_text_8_16_pat
  6811 00003094 E999EAFFFF          <1>         jmp     VIDEO_RETURN
  6812                              <1> font_setup_7:
  6813                              <1> 	; Note: AX=1120h (Setup INT 1Fh, EXT_PTR) is not needed
  6814                              <1> 	; for TRDOS 386 (TRDOS v2.0) video functionality;
  6815                              <1> 	; because, originally EXT_PTR (font address) was used for
  6816                              <1> 	; chars 80h to 0FFh (after the first 128 ASCII char fonts), for
  6817                              <1> 	; CGA graphics mode; currenty, 'vgafont8' address has 256 chars!
  6818                              <1> 	; 
  6819                              <1> 	; case 0x20:
  6820                              <1>         ; biosfn_load_gfx_8_8_chars(ES,BP);
  6821                              <1>         ; break; 
  6822                              <1> 	; case 0x21:
  6823                              <1>         ; biosfn_load_gfx_user_chars(ES,BP,CX,GET_BL(),GET_DL());
  6824                              <1>         ; break;
  6825                              <1> 	; AX = 1121H ; Setup User-Defined Font for Graphics Mode (VGA)
  6826                              <1> 	; BL   screen rows code: 00H = user-specified (in DL)
  6827                              <1>         ;                        01H = 14 rows
  6828                              <1>         ;                        02H = 25 rows
  6829                              <1>         ;                        03H = 43 rows
  6830                              <1>         ; CX   bytes per character definition
  6831                              <1>         ; DL   (when BL=0) custom number of character rows on screen
  6832                              <1>         ; EBP  address of font-definition information (user's mem space)
  6833                              <1> 
  6834 00003099 3C21                <1> 	cmp	al, 21h
  6835 0000309B 7531                <1> 	jne	short font_setup_9
  6836                              <1> 
  6837                              <1> 	; TRDOS 386 modification !
  6838                              <1> 	; dh = 0 -> 256 characters
  6839                              <1> 	; dh = 80h -> second 128 characters
  6840                              <1> 	; dh = 0FFh -> first 128 characters
  6841                              <1> 
  6842                              <1> 	; 09/01/2021 (TRDOS 386 v2.0.3)
  6843                              <1> 	;push	ebx
  6844 0000309D 51                  <1> 	push	ecx
  6845 0000309E 52                  <1> 	push	edx
  6846 0000309F 30D2                <1> 	xor	dl, dl
  6847 000030A1 88CF                <1> 	mov	bh, cl ; character height
  6848                              <1> 	;mov	cx, 100h ; 256
  6849                              <1> 	; 03/08/2022
  6850 000030A3 31C9                <1> 	xor 	ecx, ecx
  6851 000030A5 FEC5                <1> 	inc	ch
  6852                              <1> 	; ecx = 100h
  6853 000030A7 08F6                <1> 	or	dh, dh ; 0
  6854 000030A9 7410                <1> 	jz	short  font_setup_8
  6855 000030AB FECD                <1> 	dec	ch ; cx = 0
  6856 000030AD 80FEFF              <1> 	cmp	dh, 0FFh
  6857 000030B0 7409                <1> 	je	short font_setup_8 ; 1st 128 chars
  6858                              <1> 	; 2nd 128 chars
  6859 000030B2 80FE80              <1> 	cmp	dh, 80h
  6860 000030B5 75B7                <1> 	jne	short font_setup_error ; invalid !
  6861 000030B7 88F1                <1> 	mov	cl, dh
  6862 000030B9 86F2                <1> 	xchg	dl, dh
  6863                              <1> 	; number of chars, cx = 80h 
  6864                              <1> 	; start char, dl = 80h
  6865                              <1> font_setup_8:	
  6866 000030BB E85E000000          <1> 	call	transfer_user_fonts
  6867 000030C0 5A                  <1> 	pop	edx
  6868 000030C1 59                  <1> 	pop	ecx
  6869                              <1> 	;pop	ebx
  6870 000030C2 72AA                <1> 	jc	short font_setup_error
  6871                              <1> 	; ebp = user's font data address in system's memory space
  6872 000030C4 E82F030000          <1> 	call	load_gfx_user_chars
  6873 000030C9 E964EAFFFF          <1>         jmp     VIDEO_RETURN 
  6874                              <1> font_setup_9:
  6875                              <1> 	; case 0x22:
  6876                              <1>         ; biosfn_load_gfx_8_14_chars(GET_BL());
  6877                              <1>         ; break;
  6878 000030CE 3C22                <1> 	cmp	al, 22h
  6879 000030D0 750A                <1> 	jne	short font_setup_10
  6880 000030D2 E85D030000          <1> 	call	load_gfx_8_14_chars	
  6881 000030D7 E956EAFFFF          <1>         jmp     VIDEO_RETURN 
  6882                              <1> font_setup_10:	
  6883                              <1> 	; case 0x23:
  6884                              <1>         ; biosfn_load_gfx_8_8_dd_chars(GET_BL());
  6885                              <1>         ; break;
  6886 000030DC 3C23                <1> 	cmp	al, 23h
  6887 000030DE 750A                <1> 	jne	short font_setup_11
  6888 000030E0 E890030000          <1> 	call	load_gfx_8_8_chars	
  6889 000030E5 E948EAFFFF          <1>         jmp     VIDEO_RETURN 
  6890                              <1> font_setup_11:	
  6891                              <1> 	; case 0x24:
  6892                              <1>         ; biosfn_load_gfx_8_16_chars(GET_BL());
  6893                              <1>         ; break;
  6894 000030EA 3C24                <1> 	cmp	al, 24h
  6895 000030EC 750A                <1> 	jne	short font_setup_12
  6896 000030EE E8C3030000          <1> 	call	load_gfx_8_16_chars	
  6897 000030F3 E93AEAFFFF          <1>         jmp     VIDEO_RETURN 
  6898                              <1> font_setup_12:
  6899                              <1>  	; case 0x30:
  6900                              <1>         ; biosfn_get_font_info(GET_BH(),&ES,&BP,&CX,&DX);
  6901                              <1>         ; break;
  6902 000030F8 3C30                <1> 	cmp	al, 30h
  6903 000030FA 750A                <1> 	jne	short font_setup_13			
  6904 000030FC E8F6030000          <1> 	call	get_font_info
  6905                              <1> 	; eax = return value (info: 4 bytes for 4 parms)
  6906                              <1> 	; eax = 0 -> invalid function (input)
  6907 00003101 E931EAFFFF          <1>         jmp     _video_return
  6908                              <1> font_setup_13:
  6909 00003106 3C03                <1> 	cmp	al, 03h ; AX = 1103h	
  6910 00003108 750D                <1> 	jne	short font_setup_14
  6911                              <1> 	; biosfn_set_text_block_specifier:
  6912                              <1> 	; BL = font block selector code	
  6913                              <1> 	; NOTE: TRDOS 386 only uses and sets font block 0
  6914                              <1> 	; (It is as BL = 0 for TRDOS 386)
  6915 0000310A 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  6916                              <1> 	;mov	ah, bl
  6917 0000310E 28E4                <1> 	sub	ah, ah ; 0
  6918                              <1> 	;mov	al, 03h
  6919 00003110 66EF                <1> 	out	dx, ax
  6920 00003112 E91BEAFFFF          <1> 	jmp     VIDEO_RETURN 
  6921                              <1> 	
  6922                              <1> font_setup_14:
  6923 00003117 29C0                <1> 	sub	eax, eax ; 0 = invalid function
  6924 00003119 E919EAFFFF          <1>         jmp     _video_return
  6925                              <1> 
  6926                              <1> transfer_user_fonts:
  6927                              <1> 	; 02/08/2022 (TRDOS 386 Kernel v2.0.5)
  6928                              <1> 	; 19/01/2021
  6929                              <1> 	; 09/01/2021
  6930                              <1> 	; 05/01/2021 (TRDOS 386 v2.0.3)
  6931                              <1> 
  6932                              <1> 	; BH =  height of each character (bytes per character)
  6933                              <1> 	; CX =  number of characters to redefine (<=256)
  6934                              <1>         ; DX =  ASCII code of the first character defined at EBP
  6935                              <1>         ; EBP =	address of font-definition information
  6936                              <1> 	;	(in user's memory space)
  6937                              <1> 
  6938                              <1> 	; Modified registers: eax, edx, ecx, esi, edi, ebp
  6939                              <1> 	;
  6940                              <1> 	; output:
  6941                              <1> 	;	ebp = user font data address in system memory
  6942                              <1> 
  6943 0000311E 81E2FFFF0000        <1> 	and	edx, 0FFFFh
  6944 00003124 81E1FFFF0000        <1> 	and	ecx, 0FFFFh
  6945 0000312A 7537                <1> 	jnz	short transfer_user_fonts_5
  6946                              <1> 
  6947 0000312C 09D2                <1> 	or	edx, edx
  6948 0000312E 7531                <1> 	jnz	short transfer_user_fonts_4
  6949 00003130 09ED                <1> 	or	ebp, ebp
  6950 00003132 752D                <1> 	jnz	short transfer_user_fonts_4
  6951                              <1> 
  6952                              <1> 	; cx = 0, dx = 0, ebp = 0
  6953                              <1> 	; copy system font to user font
  6954                              <1> 
  6955 00003134 B140                <1> 	mov	cl, 64 ; 64 dwords
  6956                              <1> 	
  6957 00003136 80FF10              <1> 	cmp	bh, 16
  6958 00003139 7417                <1> 	je	short transfer_user_fonts_2
  6959 0000313B 80FF08              <1> 	cmp	bh, 8
  6960 0000313E 7406                <1> 	je	short transfer_user_fonts_1
  6961                              <1> 
  6962 00003140 BD[545B0100]        <1> 	mov	ebp, vgafont14
  6963 00003145 C3                  <1> 	retn 
  6964                              <1> 
  6965                              <1> transfer_user_fonts_1:
  6966 00003146 BF00500900          <1> 	mov	edi, VGAFONT8USER
  6967 0000314B BE[54530100]        <1> 	mov	esi, vgafont8
  6968 00003150 EB0A                <1> 	jmp	short transfer_user_fonts_3
  6969                              <1> 
  6970                              <1> transfer_user_fonts_2:
  6971 00003152 BF00400900          <1> 	mov	edi, VGAFONT16USER
  6972 00003157 BE[54690100]        <1> 	mov	esi, vgafont16
  6973                              <1> transfer_user_fonts_3:
  6974 0000315C 89FD                <1> 	mov	ebp, edi
  6975 0000315E F3A5                <1> 	rep	movsd
  6976 00003160 C3                  <1> 	retn
  6977                              <1> 
  6978                              <1> transfer_user_fonts_4:
  6979 00003161 F9                  <1> 	stc	
  6980 00003162 C3                  <1> 	retn
  6981                              <1> 	
  6982                              <1> transfer_user_fonts_5:
  6983 00003163 09ED                <1> 	or	ebp, ebp
  6984 00003165 74FA                <1> 	jz	short transfer_user_fonts_4 ; invalid address !
  6985                              <1> 
  6986 00003167 6681F90001          <1> 	cmp	cx, 256
  6987 0000316C 77F3                <1> 	ja	short transfer_user_fonts_4
  6988 0000316E 29D1                <1> 	sub	ecx, edx
  6989 00003170 76EF                <1> 	jna	short transfer_user_fonts_4
  6990                              <1> 
  6991 00003172 80FF0E              <1> 	cmp	bh, 14 ; 8x14 font
  6992                              <1> 		       ; (there is not an alternative buffer)
  6993 00003175 7524                <1> 	jne	short transfer_user_fonts_6
  6994                              <1> 	
  6995                              <1> 	; use system's 8x14 font space if permission flag is 1
  6996 00003177 F605[8EA30100]80    <1> 	test	byte [ufont], 80h
  6997 0000317E 74E1                <1> 	jz	short transfer_user_fonts_4 ; not allowed
  6998                              <1> 
  6999                              <1> 	; permission is given (for vgafont14 location etc.)
  7000                              <1> 	; (for permanent font modification)
  7001                              <1> 	;
  7002                              <1> 	; 19/01/2021
  7003                              <1> 	; Note: Permission flag can be set by 'root' while
  7004                              <1> 	;	system is not in multi tasking/user mode
  7005                              <1> 	;	while [multi_tasking] = 0 and [u.uid] = 0
  7006                              <1> 
  7007                              <1> 	;push	edx	
  7008                              <1> 	; 02/08/2022
  7009 00003180 87CA                <1> 	xchg	edx, ecx
  7010                              <1> 	;xor	ah, ah
  7011                              <1> 	; 02/08/2022
  7012 00003182 31C0                <1> 	xor	eax, eax
  7013 00003184 88F8                <1> 	mov	al, bh ; mov al, 14 
  7014                              <1> 	;mul	cx 
  7015                              <1> 	; 02/08/2022
  7016 00003186 F7E2                <1> 	mul	edx  ; char count * 14	
  7017                              <1> 	; 02/08/2022
  7018 00003188 89CA                <1> 	mov	edx, ecx ; ascii code
  7019 0000318A 89C1                <1> 	mov	ecx, eax
  7020                              <1> 		; ecx = byte count 
  7021                              <1> 	;pop	edx
  7022                              <1> 	; 02/08/2022
  7023                              <1> 	;xor	eax, eax	
  7024 0000318C 30E4                <1> 	xor	ah, ah
  7025 0000318E 88F8                <1> 	mov	al, bh ; mov ax, 14 ; bytes per character
  7026                              <1> 	;mul	dx
  7027                              <1> 	;mov	dx, ax ; char offset
  7028                              <1> 	; 02/08/2022
  7029 00003190 F7E2                <1> 	mul	edx
  7030 00003192 89C2                <1> 	mov	edx, eax ; char offset
  7031 00003194 BF[545B0100]        <1> 	mov	edi, vgafont14
  7032 00003199 EB48                <1> 	jmp	short transfer_user_fonts_8			
  7033                              <1> transfer_user_fonts_6:
  7034 0000319B 80FF08              <1> 	cmp	bh, 8 ; 8x8 font
  7035 0000319E 7520                <1> 	jne	short transfer_user_fonts_7 ; 8x16 font
  7036                              <1> 	;shl	dx, 3 ; * 8
  7037                              <1> 	;shl	cx, 3 ; * 8
  7038                              <1> 	; 02/08/2022
  7039 000031A0 C1E203              <1> 	shl	edx, 3 ; byte offset
  7040 000031A3 C1E103              <1> 	shl	ecx, 3 ; byte count
  7041                              <1> 	; 09/01/2021
  7042 000031A6 BF00500900          <1> 	mov	edi, VGAFONT8USER
  7043 000031AB F605[8EA30100]08    <1> 	test	byte [ufont], 8  ; already loaded ?	
  7044 000031B2 752F                <1> 	jnz	short transfer_user_fonts_8 ; yes
  7045 000031B4 BE[54530100]        <1> 	mov	esi, vgafont8
  7046 000031B9 E839000000          <1> 	call	transfer_user_fonts_10
  7047 000031BE EB23                <1> 	jmp	short transfer_user_fonts_8
  7048                              <1> transfer_user_fonts_7:
  7049 000031C0 80FF10              <1> 	cmp	bh, 16 ; 8x16 font
  7050 000031C3 759C                <1> 	jne	short transfer_user_fonts_4  ; invalid !
  7051                              <1> 	;shl	dx, 4 ; * 16
  7052                              <1> 	;shl	cx, 4 ; * 16
  7053                              <1> 	; 02/08/2022
  7054 000031C5 C1E204              <1> 	shl	edx, 4 ; byte offset
  7055 000031C8 C1E104              <1> 	shl	ecx, 4 ; byte count
  7056 000031CB BF00400900          <1>  	mov	edi, VGAFONT16USER
  7057 000031D0 F605[8EA30100]10    <1> 	test	byte [ufont], 16  ; already loaded ?	
  7058 000031D7 750A                <1> 	jnz	short transfer_user_fonts_8 ; yes
  7059 000031D9 BE[54690100]        <1> 	mov	esi, vgafont16
  7060 000031DE E814000000          <1> 	call	transfer_user_fonts_10
  7061                              <1> transfer_user_fonts_8:
  7062 000031E3 01D7                <1> 	add	edi, edx ; char offset
  7063                              <1> 	; 09/07/2016
  7064                              <1> 	;and	ecx, 0FFFFh
  7065                              <1> 	; ECX = byte count
  7066                              <1> 	;push	ecx
  7067 000031E5 89EE                <1> 	mov	esi, ebp ; user's font buffer
  7068                              <1> 	; 09/01/2021
  7069 000031E7 89FD                <1> 	mov	ebp, edi ; system addr for user's font
  7070                              <1> 	; 05/01/2021
  7071                              <1> 	;mov	edi, Cluster_Buffer  ; system buffer
  7072 000031E9 E8ECDD0000          <1> 	call	transfer_from_user_buffer
  7073                              <1> 	;pop	ecx
  7074                              <1> 	; ecx = transfer (byte) count = character count
  7075 000031EE 7206                <1> 	jc	short transfer_user_fonts_9
  7076                              <1> 	; 05/01/2021
  7077                              <1> 	;mov	ebp, Cluster_Buffer
  7078                              <1> 	
  7079 000031F0 083D[8EA30100]      <1> 	or	byte [ufont], bh 
  7080                              <1> 			; 8x8 or 8x16 user font ready 
  7081                              <1> transfer_user_fonts_9:
  7082 000031F6 C3                  <1> 	retn
  7083                              <1> 
  7084                              <1> transfer_user_fonts_10:
  7085                              <1> 	; 02/08/2022
  7086                              <1> 	; 09/01/2021
  7087 000031F7 56                  <1> 	push	esi
  7088 000031F8 57                  <1> 	push	edi
  7089 000031F9 51                  <1> 	push	ecx
  7090                              <1> 	;mov	cx, 64
  7091                              <1> 	; 02/08/2022
  7092 000031FA 31C9                <1> 	xor	ecx, ecx
  7093 000031FC B140                <1> 	mov	cl, 64
  7094 000031FE F3A5                <1> 	rep	movsd
  7095 00003200 59                  <1> 	pop	ecx
  7096 00003201 5F                  <1> 	pop	edi
  7097 00003202 5E                  <1> 	pop	esi
  7098 00003203 C3                  <1> 	retn
  7099                              <1> 
  7100                              <1> load_text_user_pat:
  7101                              <1> 	; 02/08/2022 (TRDOS 3386 v2.0.5)
  7102                              <1> 	; 26/07/2016
  7103                              <1> 	; 09/07/2016
  7104                              <1> 	; load user defined (EGA/VGA) text fonts
  7105                              <1> 	;
  7106                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  7107                              <1> 	; vgabios-0.7a (2011)
  7108                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  7109                              <1> 	; 'vgabios.c', 'biosfn_load_text_user_pat'
  7110                              <1> 
  7111                              <1> 	; biosfn_load_text_user_pat (AL,ES,BP,CX,DX,BL,BH)
  7112                              <1> 
  7113                              <1> 	; get_font_access();
  7114                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  7115                              <1> 	; for(i=0;i<CX;i++)
  7116                              <1> 	; {
  7117                              <1> 	;  src = BP + i * BH;
  7118                              <1> 	;  dest = blockaddr + (DX + i) * 32;
  7119                              <1> 	;  memcpyb(0xA000, dest, ES, src, BH);
  7120                              <1> 	; }
  7121                              <1> 	; release_font_access();
  7122                              <1> 	; if(AL>=0x10)
  7123                              <1> 	; {
  7124                              <1> 	; set_scan_lines(BH);
  7125                              <1> 	; }
  7126                              <1> 
  7127 00003204 50                  <1> 	push	eax
  7128 00003205 E839000000          <1> 	call	get_font_access
  7129 0000320A 28DB                <1> 	sub	bl, bl ; i = 0
  7130                              <1> 	; 02/08/2022
  7131                              <1> 	; ecx <= 256
  7132 0000320C 30ED                <1> 	xor	ch, ch
  7133                              <1> ltup_1:
  7134 0000320E 88D8                <1> 	mov	al, bl
  7135 00003210 F6E7                <1> 	mul	bh	
  7136                              <1> 	;movzx	esi, ax
  7137                              <1> 	; 02/08/2022
  7138 00003212 89C6                <1> 	mov	esi, eax
  7139 00003214 01EE                <1> 	add	esi, ebp
  7140 00003216 88D8                <1> 	mov	al, bl
  7141 00003218 28E4                <1> 	sub	ah, ah
  7142                              <1> 	;add	ax, dx ; (DX + i)
  7143                              <1> 	;shl	ax, 5  ; * 32
  7144                              <1> 	; 02/08/2022
  7145 0000321A 01D0                <1> 	add	eax, edx
  7146 0000321C C1E005              <1> 	shl	eax, 5
  7147                              <1> 	;movzx	edi, ax
  7148                              <1> 	; 02/08/2022
  7149 0000321F 89C7                <1> 	mov	edi, eax
  7150 00003221 81C700000A00        <1> 	add	edi, 0A0000h
  7151 00003227 51                  <1> 	push	ecx
  7152                              <1> 	;movzx	ecx, bh
  7153                              <1> 	; 02/08/2022
  7154 00003228 88F9                <1> 	mov	cl, bh
  7155 0000322A F3A4                <1> 	rep	movsb
  7156 0000322C 59                  <1> 	pop	ecx
  7157 0000322D FEC3                <1> 	inc	bl
  7158 0000322F 38CB                <1> 	cmp	bl, cl
  7159 00003231 75DB                <1> 	jne	short ltup_1
  7160                              <1> 	;
  7161 00003233 E83E000000          <1> 	call	release_font_access
  7162                              <1> 	;
  7163 00003238 58                  <1> 	pop	eax
  7164                              <1> 	; if(AL>=0x10)
  7165 00003239 3C10                <1> 	cmp	al, 10h
  7166 0000323B 7205                <1> 	jb	short ltup_2
  7167                              <1>    	; set_scan_lines(BH);
  7168 0000323D E86F000000          <1> 	call	set_scan_lines
  7169                              <1> ltup_2:
  7170 00003242 C3                  <1> 	retn
  7171                              <1> 
  7172                              <1> get_font_access:
  7173                              <1> 	; 02/08/2022
  7174                              <1> 	; 09/07/2016
  7175                              <1> 	;
  7176                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  7177                              <1> 	; vgabios-0.7a (2011)
  7178                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  7179                              <1> 	; 'vgabios.c', 'get_font_access'
  7180                              <1> 
  7181                              <1> 	; get_font_access()
  7182 00003243 52                  <1> 	push	edx
  7183 00003244 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  7184                              <1> 	; 02/08/2022
  7185 00003248 31C0                <1>  	xor	eax, eax
  7186                              <1> 	;mov	ax, 0100h
  7187 0000324A B401                <1> 	mov	ah, 1
  7188                              <1> 	; ax = 0100h
  7189 0000324C 66EF                <1> 	out	dx, ax
  7190 0000324E 66B80204            <1> 	mov	ax, 0402h
  7191 00003252 66EF                <1> 	out	dx, ax
  7192 00003254 66B80407            <1> 	mov	ax, 0704h
  7193 00003258 66EF                <1> 	out	dx, ax
  7194 0000325A 66B80003            <1> 	mov	ax, 0300h
  7195 0000325E 66EF                <1> 	out	dx, ax
  7196                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  7197                              <1> 	; 02/08/2022
  7198 00003260 B2CE                <1> 	mov	dl, 0CEh
  7199 00003262 66B80402            <1> 	mov	ax, 0204h
  7200 00003266 66EF                <1> 	out	dx, ax
  7201 00003268 66B80500            <1> 	mov	ax, 0005h
  7202 0000326C 66EF                <1> 	out	dx, ax
  7203 0000326E 66B80604            <1> 	mov	ax, 0406h
  7204 00003272 66EF                <1> 	out	dx, ax
  7205 00003274 5A                  <1> 	pop	edx
  7206 00003275 C3                  <1> 	retn
  7207                              <1> 
  7208                              <1> release_font_access:
  7209                              <1> 	; 02/08/2022
  7210                              <1> 	; 29/07/2016
  7211                              <1> 	; 09/07/2016
  7212                              <1> 	;
  7213                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  7214                              <1> 	; vgabios-0.7a (2011)
  7215                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  7216                              <1> 	; 'vgabios.c', 'release_font_access'
  7217                              <1> 
  7218 00003276 66BAC403            <1> 	mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
  7219                              <1> 	;mov	ax, 0100h
  7220                              <1> 	; 02/08/2022
  7221 0000327A 29C0                <1> 	sub	eax, eax
  7222 0000327C B401                <1> 	mov	ah, 1
  7223                              <1> 	; ax = 0100h
  7224 0000327E 66EF                <1> 	out	dx, ax
  7225 00003280 66B80203            <1> 	mov	ax, 0302h
  7226 00003284 66EF                <1> 	out	dx, ax
  7227 00003286 66B80403            <1> 	mov	ax, 0304h
  7228 0000328A 66EF                <1> 	out	dx, ax
  7229 0000328C 66B80003            <1> 	mov	ax, 0300h
  7230 00003290 66EF                <1> 	out	dx, ax
  7231                              <1> 	;mov	dx, 3CCh ; VGAREG_READ_MISC_OUTPUT
  7232                              <1>  	; 02/08/2022
  7233 00003292 B2CC                <1> 	mov	dl, 0CCh
  7234 00003294 EC                  <1> 	in	al, dx
  7235 00003295 2401                <1> 	and	al, 01h
  7236 00003297 C0E002              <1> 	shl	al, 2
  7237 0000329A 0C0A                <1> 	or	al, 0Ah
  7238 0000329C 88C4                <1> 	mov	ah, al
  7239 0000329E B006                <1> 	mov	al, 06h
  7240                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
  7241                              <1> 	; 02/08/2022
  7242 000032A0 B2CE                <1> 	mov	dl, 0CEh
  7243 000032A2 66EF                <1> 	out	dx, ax
  7244 000032A4 66B80400            <1> 	mov	ax, 0004h
  7245 000032A8 66EF                <1> 	out	dx, ax
  7246 000032AA 66B80510            <1> 	mov	ax, 1005h
  7247 000032AE 66EF                <1> 	out	dx, ax
  7248 000032B0 C3                  <1> 	retn
  7249                              <1> 
  7250                              <1> set_scan_lines:
  7251                              <1> 	; 02/08/2022
  7252                              <1> 	; 09/07/2016
  7253                              <1> 	;
  7254                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  7255                              <1> 	; vgabios-0.7a (2011)
  7256                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  7257                              <1> 	; 'vgabios.c', 'set_scan_lines'
  7258                              <1> 
  7259                              <1> 	; set_scan_lines(lines)
  7260                              <1> 	; BH = lines
  7261                              <1> 
  7262                              <1> 	; outb(crtc_addr, 0x09);
  7263 000032B1 66BAD403            <1> 	mov	dx, 3D4h ; CRTC_ADDRESS = 3D4h (always)
  7264 000032B5 B009                <1> 	mov	al, 09h
  7265 000032B7 EE                  <1> 	out	dx, al
  7266                              <1> 	; crtc_r9 = inb(crtc_addr+1);
  7267                              <1> 	;inc	dx ; 3D5h
  7268                              <1> 	; 02/08/2022
  7269 000032B8 FEC2                <1> 	inc	dl
  7270 000032BA EC                  <1> 	in	al, dx
  7271                              <1> 	; crtc_r9 = (crtc_r9 & 0xe0) | (lines - 1);
  7272 000032BB 24E0                <1> 	and	al, 0E0h
  7273 000032BD FECF                <1> 	dec	bh ; lines - 1
  7274 000032BF 08F8                <1> 	or	al, bh
  7275                              <1> 	; outb(crtc_addr+1, crtc_r9);
  7276 000032C1 EE                  <1> 	out	dx, al
  7277                              <1> 	;inc	bh 
  7278                              <1> 	; if(lines==8)
  7279                              <1> 	;cmp	bh, 8
  7280 000032C2 80FF07              <1> 	cmp	bh, 7
  7281 000032C5 7506                <1> 	jne	short ssl_1
  7282                              <1> 	; biosfn_set_cursor_shape(0x06,0x07);
  7283 000032C7 66B90706            <1> 	mov	cx, 0607h
  7284 000032CB EB06                <1> 	jmp	short ssl_2
  7285                              <1> ssl_1:
  7286                              <1> 	; biosfn_set_cursor_shape(lines-4,lines-3);
  7287 000032CD 88F9                <1> 	mov	cl, bh ; lines - 1
  7288 000032CF 88CD                <1> 	mov	ch, cl ; lines - 1 (16 -> 15)
  7289 000032D1 FECD                <1> 	dec	ch  ; lines - 2 (16 -> 14)
  7290                              <1> ssl_2:
  7291                              <1> 	; CH = start line, CL = stop line
  7292 000032D3 B40A                <1> 	mov	ah, 10	; 6845 register for cursor set
  7293 000032D5 66890D[F7670000]    <1> 	mov	[CURSOR_MODE], cx ; save in data area
  7294 000032DC E877F0FFFF          <1> 	call	m16	; output cx register
  7295                              <1> 	; write_word(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT, lines);
  7296 000032E1 FEC7                <1> 	inc	bh ; lines
  7297 000032E3 883D[E2670000]      <1> 	mov	[CHAR_HEIGHT], bh
  7298                              <1> 	;  outb(crtc_addr, 0x12);
  7299 000032E9 66BAD403            <1> 	mov	dx, 3D4h ; CRTC_ADDRESS
  7300 000032ED B012                <1> 	mov	al, 12h
  7301 000032EF EE                  <1> 	out	dx, al
  7302                              <1> 	; vde = inb(crtc_addr+1);
  7303                              <1> 	;inc	dx
  7304                              <1> 	; 02/08/2022
  7305 000032F0 FEC2                <1> 	inc	dl
  7306 000032F2 EC                  <1> 	in	al, dx
  7307 000032F3 88C4                <1> 	mov	ah, al
  7308                              <1> 	; outb(crtc_addr, 0x07);
  7309                              <1> 	;dec	dx
  7310                              <1> 	; 02/08/2022
  7311 000032F5 FECA                <1> 	dec	dl
  7312 000032F7 B007                <1> 	mov	al, 07h
  7313 000032F9 EE                  <1> 	out	dx, al
  7314                              <1> 	; ovl = inb(crtc_addr+1);
  7315                              <1> 	;inc	dx
  7316                              <1> 	; 02/08/2022
  7317 000032FA FEC2                <1> 	inc	dl
  7318 000032FC EC                  <1> 	in	al, dx
  7319                              <1> 	; vde += (((ovl & 0x02) << 7) + ((ovl & 0x40) << 3) + 1);
  7320 000032FD 88E2                <1> 	mov	dl, ah ; vde
  7321 000032FF 88C6                <1> 	mov	dh, al ; ovl
  7322                              <1> 	;and	ax, 02h
  7323                              <1> 	;shl	ax, 7
  7324                              <1> 	; 02/08/2022
  7325 00003301 31C0                <1> 	xor	eax, eax
  7326 00003303 88F0                <1> 	mov	al, dh
  7327 00003305 2402                <1> 	and	al, 2
  7328 00003307 C1E007              <1> 	shl	eax, 7
  7329                              <1> 	;mov	cx, ax ; (ovl & 0x02) << 7)	
  7330                              <1> 	; 02/08/2022
  7331 0000330A 89C1                <1> 	mov	ecx, eax
  7332 0000330C 28E4                <1> 	sub	ah, ah
  7333 0000330E 88F0                <1> 	mov	al, dh ; ovl
  7334                              <1> 	;and	ax, 40h			
  7335                              <1> 	;shl	ax, 3  ; (ovl & 0x40) << 3)
  7336                              <1> 	;inc	ax ; + 1 
  7337                              <1> 	;add	ax, cx
  7338                              <1> 	; 02/08/2022	
  7339 00003310 2440                <1> 	and	al, 40h
  7340 00003312 C1E003              <1> 	shl	eax, 3
  7341 00003315 40                  <1> 	inc	eax
  7342 00003316 01C8                <1> 	add	eax, ecx
  7343 00003318 30F6                <1> 	xor	dh, dh
  7344                              <1> 	;add	ax, dx ; + vde
  7345                              <1> 	; 02/08/2022
  7346 0000331A 01D0                <1> 	add	eax, edx
  7347                              <1> 	; rows = vde / lines;
  7348 0000331C F6F7                <1> 	div	bh
  7349                              <1> 	;dec	al ; rows -1
  7350                              <1> 	; write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, rows-1);
  7351 0000331E A2[E6670000]        <1> 	mov	[VGA_ROWS], al ; rows (not 'rows-1' !)
  7352                              <1> 	; write_word(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE, rows * cols * 2);
  7353                              <1> 	;mov	ah, [CRT_COLS]
  7354                              <1> 	;mul	ah
  7355                              <1> 	; 17/11/2020
  7356 00003323 F625[E0670000]      <1> 	mul	byte [CRT_COLS]
  7357                              <1> 	;shl	ax, 1
  7358                              <1> 	; 02/08/2022
  7359 00003329 D1E0                <1> 	shl	eax, 1
  7360 0000332B 66A3[54890100]      <1> 	mov 	[CRT_LEN], ax	
  7361 00003331 C3                  <1> 	retn
  7362                              <1> 
  7363                              <1> load_text_8_14_pat:
  7364                              <1> 	; 02/08/2022 (TRDOS 3386 v2.0.5)
  7365                              <1> 	; 26/07/2016
  7366                              <1> 	; 25/07/2016
  7367                              <1> 	; 23/07/2016
  7368                              <1> 	; 09/07/2016
  7369                              <1> 	; load user defined (EGA/VGA) text fonts
  7370                              <1> 	;
  7371                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  7372                              <1> 	; vgabios-0.7a (2011)
  7373                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  7374                              <1> 	; 'vgabios.c', 'biosfn_load_text_8_14_pat'
  7375                              <1> 
  7376                              <1> 	; biosfn_load_text_8_14_pat (AL,BL)
  7377                              <1> 
  7378                              <1> 	; get_font_access();
  7379                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  7380                              <1> 	; for(i=0;i<0x100;i++)
  7381                              <1> 	; {
  7382                              <1> 	;  src = i * 14;
  7383                              <1> 	;  dest = blockaddr + i * 32;
  7384                              <1> 	;  memcpyb(0xA000, dest, 0xC000, vgafont14+src, 14);
  7385                              <1> 	; }
  7386                              <1> 	; release_font_access();
  7387                              <1> 	; if(AL>=0x10)
  7388                              <1> 	; {
  7389                              <1> 	; set_scan_lines(14);
  7390                              <1> 	; }
  7391                              <1> 
  7392 00003332 50                  <1> 	push	eax
  7393 00003333 E80BFFFFFF          <1> 	call	get_font_access
  7394                              <1> 
  7395                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  7396                              <1> 	;mov	dl, bl
  7397                              <1> 	;and	dl, 3
  7398                              <1> 	;shl	dx, 14
  7399                              <1> 	;xchg	dx, bx
  7400                              <1> 	;and	dl, 4
  7401                              <1> 	;shl	dx, 11
  7402                              <1> 	;add	dx, bx 	
  7403                              <1>  
  7404                              <1> 	;xor	dx, dx  ; blockaddr = 0
  7405                              <1> 	; Always block 0 for TRDOS 386 ! (blockaddr=0)
  7406                              <1> 
  7407 00003338 28DB                <1> 	sub	bl, bl ; i = 0
  7408 0000333A B70E                <1> 	mov	bh, 14
  7409 0000333C BE[545B0100]        <1> 	mov	esi, vgafont14
  7410 00003341 BF00000A00          <1> 	mov	edi, 0A0000h
  7411                              <1> 	; 02/08/2022
  7412 00003346 29C9                <1> 	sub	ecx, ecx		
  7413                              <1> lt8_14_1:
  7414                              <1> 	;mov	al, bl
  7415                              <1> 	;mul	bh
  7416                              <1> 	;movzx	esi, ax
  7417                              <1> 	;add	esi, vgafont14
  7418                              <1> 	;mov	al, bl
  7419                              <1> 	;sub	ah, ah
  7420                              <1> 	;shl	ax, 5 ; * 32
  7421                              <1> 	;;add	ax, dx ; blockaddr + i * 32;
  7422                              <1> 	;movzx	edi, ax ; dest
  7423                              <1> 	;add	edi, 0A0000h
  7424                              <1> 	;02/08/2022
  7425                              <1> 	;movzx	ecx, bh
  7426 00003348 88F9                <1> 	mov	cl, bh
  7427 0000334A F3A4                <1> 	rep	movsb
  7428 0000334C 83C712              <1> 	add	edi, 18 ; 32 - 14
  7429 0000334F FEC3                <1> 	inc	bl
  7430 00003351 75F5                <1> 	jnz	short lt8_14_1	
  7431                              <1> 	;
  7432 00003353 E81EFFFFFF          <1> 	call	release_font_access
  7433                              <1> 	;
  7434 00003358 58                  <1> 	pop	eax
  7435                              <1> 	; if(AL>=0x10)
  7436 00003359 3C10                <1> 	cmp	al, 10h
  7437 0000335B 7205                <1> 	jb	short lt8_14_4
  7438                              <1> 	; BH = 14
  7439                              <1>    	; set_scan_lines(14);
  7440 0000335D E84FFFFFFF          <1> 	call	set_scan_lines
  7441                              <1> lt8_14_4:
  7442 00003362 C3                  <1> 	retn
  7443                              <1> 
  7444                              <1> load_text_8_8_pat:
  7445                              <1> 	; 02/08/2022 (TRDOS 3386 v2.0.5)
  7446                              <1> 	; 05/01/2021 (TRDOS 386 v2.0.3)
  7447                              <1> 	; 26/07/2016
  7448                              <1> 	; 25/07/2016
  7449                              <1> 	; 23/07/2016
  7450                              <1> 	; 09/07/2016
  7451                              <1> 	; load user defined (EGA/VGA) text fonts
  7452                              <1> 	;
  7453                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  7454                              <1> 	; vgabios-0.7a (2011)
  7455                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  7456                              <1> 	; 'vgabios.c', 'biosfn_load_text_8_8_pat'
  7457                              <1> 
  7458                              <1> 	; biosfn_load_text_8_8_pat (AL,BL)
  7459                              <1> 
  7460                              <1> 	; get_font_access();
  7461                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  7462                              <1> 	; for(i=0;i<0x100;i++)
  7463                              <1> 	; {
  7464                              <1> 	;  src = i * 8;
  7465                              <1> 	;  dest = blockaddr + i * 32;
  7466                              <1> 	;  memcpyb(0xA000, dest, 0xC000, vgafont8+src, 8);
  7467                              <1> 	; }
  7468                              <1> 	; release_font_access();
  7469                              <1> 	; if(AL>=0x10)
  7470                              <1> 	; {
  7471                              <1> 	; set_scan_lines(8);
  7472                              <1> 	; }
  7473                              <1> 
  7474 00003363 50                  <1> 	push	eax
  7475 00003364 E8DAFEFFFF          <1> 	call	get_font_access
  7476                              <1> 
  7477                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  7478                              <1> 	;mov	dl, bl
  7479                              <1> 	;and	dl, 3
  7480                              <1> 	;shl	dx, 14
  7481                              <1> 	;xchg	dx, bx
  7482                              <1> 	;and	dl, 4
  7483                              <1> 	;shl	dx, 11
  7484                              <1> 	;add	dx, bx 	
  7485                              <1>  
  7486                              <1> 	;xor	dx, dx  ; blockaddr = 0
  7487                              <1> 	; Always block 0 for TRDOS 386 ! (blockaddr=0)
  7488                              <1> 
  7489 00003369 28DB                <1> 	sub	bl, bl ; i = 0
  7490 0000336B B708                <1> 	mov	bh, 8
  7491                              <1> 	;mov	esi, vgafont8
  7492 0000336D BF00000A00          <1> 	mov	edi, 0A0000h
  7493                              <1> 
  7494                              <1> 	; 02/08/2022
  7495 00003372 29C9                <1> 	sub	ecx, ecx
  7496                              <1> 
  7497                              <1> 	; 05/01/2021
  7498 00003374 F605[8EA30100]80    <1> 	test	byte [ufont], 80h
  7499 0000337B 7410                <1> 	jz	short lt8_8_0
  7500                              <1> 		; user font permission (after set mode)
  7501 0000337D F605[8EA30100]08    <1>  	test	byte [ufont], 8
  7502 00003384 7407                <1> 	jz	short lt8_8_0
  7503 00003386 BE00500900          <1> 	mov	esi, VGAFONT8USER
  7504 0000338B EB05                <1> 	jmp	short lt8_8_1
  7505                              <1> lt8_8_0:
  7506 0000338D BE[54530100]        <1> 	mov	esi, vgafont8	
  7507                              <1> lt8_8_1:
  7508                              <1> 	;mov	al, bl
  7509                              <1> 	;mul	bh
  7510                              <1> 	;movzx	esi, ax
  7511                              <1> 	;add	esi, vgafont8
  7512                              <1> 	;mov	al, bl
  7513                              <1> 	;sub	ah, ah
  7514                              <1> 	;shl	ax, 5 ; * 32
  7515                              <1> 	;;add	ax, dx ; blockaddr + i * 32;
  7516                              <1> 	;movzx	edi, ax ; dest
  7517                              <1> 	;add	edi, 0A0000h
  7518                              <1> 	; 02/08/2022
  7519                              <1> 	;movzx	ecx, bh 		
  7520 00003392 88F9                <1> 	mov	cl, bh
  7521 00003394 F3A4                <1> 	rep	movsb
  7522 00003396 83C718              <1> 	add	edi, 24 ; 32 - 8
  7523 00003399 FEC3                <1> 	inc	bl
  7524 0000339B 75F5                <1> 	jnz	short lt8_8_1
  7525                              <1> 	;
  7526 0000339D E8D4FEFFFF          <1> 	call	release_font_access
  7527                              <1> 	;
  7528 000033A2 58                  <1> 	pop	eax
  7529                              <1> 	; if(AL>=0x10)
  7530 000033A3 3C10                <1> 	cmp	al, 10h
  7531 000033A5 7205                <1> 	jb	short lt8_8_2
  7532                              <1> 	; BH = 8
  7533                              <1>    	; set_scan_lines(8);
  7534 000033A7 E805FFFFFF          <1> 	call	set_scan_lines
  7535                              <1> lt8_8_2:
  7536 000033AC C3                  <1> 	retn
  7537                              <1> 
  7538                              <1> load_text_8_16_pat:
  7539                              <1> 	; 02/08/2022 (TRDOS 3386 v2.0.5)
  7540                              <1> 	; 05/01/2021 (TRDOS 386 v2.0.3)
  7541                              <1> 	; 26/07/2016
  7542                              <1> 	; 25/07/2016
  7543                              <1> 	; 23/07/2016
  7544                              <1> 	; 09/07/2016
  7545                              <1> 	; load user defined (EGA/VGA) text fonts
  7546                              <1> 	;
  7547                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  7548                              <1> 	; vgabios-0.7a (2011)
  7549                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  7550                              <1> 	; 'vgabios.c', 'biosfn_load_text_8_16_pat'
  7551                              <1> 
  7552                              <1> 	; biosfn_load_text_8_16_pat (AL,BL)
  7553                              <1> 
  7554                              <1> 	; get_font_access();
  7555                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  7556                              <1> 	; for(i=0;i<0x100;i++)
  7557                              <1> 	; {
  7558                              <1> 	;  src = i * 16;
  7559                              <1> 	;  dest = blockaddr + i * 32;
  7560                              <1> 	;  memcpyb(0xA000, dest, 0xC000, vgafont16+src, 16);
  7561                              <1> 	; }
  7562                              <1> 	; release_font_access();
  7563                              <1> 	; if(AL>=0x10)
  7564                              <1> 	; {
  7565                              <1> 	; set_scan_lines(16);
  7566                              <1> 	; }
  7567                              <1> 
  7568 000033AD 50                  <1> 	push	eax
  7569 000033AE E890FEFFFF          <1> 	call	get_font_access
  7570                              <1> 
  7571                              <1> 	; blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
  7572                              <1> 	;mov	dl, bl
  7573                              <1> 	;and	dl, 3
  7574                              <1> 	;shl	dx, 14
  7575                              <1> 	;xchg	dx, bx
  7576                              <1> 	;and	dl, 4
  7577                              <1> 	;shl	dx, 11
  7578                              <1> 	;add	dx, bx 	
  7579                              <1>  
  7580                              <1> 	;xor	dx, dx  ; blockaddr = 0
  7581                              <1> 	; Always block 0 for TRDOS 386 ! (blockaddr=0)
  7582                              <1> 
  7583 000033B3 28DB                <1> 	sub	bl, bl ; i = 0
  7584 000033B5 B710                <1> 	mov	bh, 16
  7585                              <1> 	;mov	esi, vgafont16
  7586 000033B7 BF00000A00          <1> 	mov	edi, 0A0000h
  7587                              <1> 	;movzx	eax, bh
  7588                              <1> 	; 02/08/2022
  7589 000033BC 29C0                <1> 	sub	eax, eax
  7590 000033BE 88F8                <1> 	mov	al, bh
  7591                              <1> 
  7592                              <1> 	; 05/01/2021
  7593 000033C0 F605[8EA30100]80    <1> 	test	byte [ufont], 80h
  7594 000033C7 7410                <1> 	jz	short lt8_16_0
  7595                              <1> 		; user font permission (after set mode)
  7596 000033C9 F605[8EA30100]10    <1>  	test	byte [ufont], 16
  7597 000033D0 7407                <1> 	jz	short lt8_16_0
  7598 000033D2 BE00400900          <1> 	mov	esi, VGAFONT16USER
  7599 000033D7 EB05                <1> 	jmp	short lt8_16_1
  7600                              <1> lt8_16_0:
  7601 000033D9 BE[54690100]        <1> 	mov	esi, vgafont16
  7602                              <1> lt8_16_1:
  7603                              <1> 	;mov	al, bl
  7604                              <1> 	;mul	bh
  7605                              <1> 	;movzx	esi, ax
  7606                              <1> 	;add	esi, vgafont16
  7607                              <1> 	;mov	al, bl ; i
  7608                              <1> 	;sub	ah, ah
  7609                              <1> 	;shl	ax, 5 ; * 32
  7610                              <1> 	;;add	ax, dx ; blockaddr + i * 32;
  7611                              <1> 	;movzx	edi, ax ; dest
  7612                              <1> 	;add	edi, 0A0000h
  7613                              <1> 	;movzx	ecx, bh
  7614 000033DE 89C1                <1> 	mov	ecx, eax ; 16	
  7615 000033E0 F3A4                <1> 	rep	movsb
  7616 000033E2 01C7                <1> 	add	edi, eax ; add edi, 16
  7617 000033E4 FEC3                <1> 	inc	bl
  7618 000033E6 75F6                <1> 	jnz	short lt8_16_1
  7619                              <1> 	;
  7620 000033E8 E889FEFFFF          <1> 	call	release_font_access
  7621                              <1> 	;
  7622 000033ED 58                  <1> 	pop	eax
  7623                              <1> 	; if(AL>=0x10)
  7624 000033EE 3C10                <1> 	cmp	al, 10h
  7625 000033F0 7205                <1> 	jb	short lt8_16_2
  7626                              <1> 	; BH = 16
  7627                              <1>    	; set_scan_lines(16);
  7628 000033F2 E8BAFEFFFF          <1> 	call	set_scan_lines
  7629                              <1> lt8_16_2:
  7630 000033F7 C3                  <1> 	retn
  7631                              <1> 
  7632                              <1> load_gfx_user_chars:
  7633                              <1> 	; 08/01/2021
  7634                              <1> 	; 05/01/2021 (TRDOS 386 v2.0.3)
  7635                              <1> 	; 08/08/2016
  7636                              <1> 	; 10/07/2016
  7637                              <1> 	; Setup User-Defined Font for Graphics Mode (VGA)
  7638                              <1> 	;
  7639                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  7640                              <1> 	; vgabios-0.7a (2011)
  7641                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  7642                              <1> 	; 'vgabios.c', 'biosfn_load_gfx_user_chars'
  7643                              <1> 
  7644                              <1> 	; biosfn_load_gfx_user_chars (ES,BP,CX,BL,DL)
  7645                              <1> 	; /* set 0x43 INT pointer */
  7646                              <1>     	; write_word(0x0, 0x43*4, BP);
  7647                              <1>     	; write_word(0x0, 0x43*4+2, ES);
  7648                              <1> 	
  7649                              <1> 	; 08/01/2021
  7650                              <1> 		
  7651                              <1> 	; BL   screen rows code: 00H = user-specified (in DL)
  7652                              <1>         ;                        01H = 14 rows
  7653                              <1>         ;                        02H = 25 rows
  7654                              <1>         ;                        03H = 43 rows
  7655                              <1>         ; CX   bytes per character definition
  7656                              <1>         ; DL   (when BL=0) custom number of character rows on screen
  7657                              <1>         ; EBP  address of font-definition information (user's mem space)
  7658                              <1> 
  7659                              <1> 	; 05/01/2021
  7660                              <1> 	;xor	eax, eax
  7661                              <1> 	;dec	eax ; 0FFFFFFFFh (user defined fonts)
  7662                              <1> 	;mov	[VGA_INT43H], eax
  7663                              <1> 
  7664                              <1> 	; 08/01/2021
  7665                              <1> 	; ebp = video font data (buffer) address
  7666 000033F8 892D[66890100]      <1> 	mov	[VGA_INT43H], ebp
  7667                              <1> 
  7668                              <1> 	; switch (BL) {
  7669                              <1> 	; case 0:
  7670                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, DL-1);
  7671                              <1> 	;    break;
  7672 000033FE 20DB                <1> 	and	bl, bl
  7673 00003400 7508                <1> 	jnz	short l_gfx_uc_1
  7674 00003402 8815[E6670000]      <1> 	mov	[VGA_ROWS], dl  ; not DL-1 !
  7675 00003408 EB23                <1> 	jmp	short l_gfx_uc_4
  7676                              <1> l_gfx_uc_1:
  7677                              <1> 	; case 1:
  7678                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 13);
  7679                              <1> 	;    break;
  7680 0000340A FECB                <1> 	dec	bl
  7681 0000340C 7509                <1> 	jnz	short l_gfx_uc_2
  7682                              <1> 	; bl = 1
  7683 0000340E C605[E6670000]0E    <1> 	mov	byte [VGA_ROWS], 14  ; not 13 !
  7684 00003415 EB16                <1> 	jmp	short l_gfx_uc_4
  7685                              <1> l_gfx_uc_2:
  7686 00003417 FECB                <1> 	dec	bl
  7687 00003419 740B                <1> 	jz	short l_gfx_uc_3 ; bl = 2
  7688 0000341B FECB                <1> 	dec	bl
  7689 0000341D 750E                <1> 	jnz	short l_gfx_uc_4 ; bl > 3
  7690                              <1> 	; bl = 3
  7691                              <1> 	; case 3:
  7692                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 42);
  7693                              <1> 	;    break;
  7694 0000341F C605[E6670000]2B    <1> 	mov	byte [VGA_ROWS], 43  ; not 42 !
  7695                              <1> l_gfx_uc_3:
  7696                              <1>     	; case 2:
  7697                              <1>     	; default:
  7698                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 24);
  7699                              <1> 	;    break;
  7700                              <1> 	; bl = 2 or bl > 3
  7701 00003426 C605[E6670000]19    <1> 	mov	byte [VGA_ROWS], 25  ; not 24 !	
  7702                              <1>     	; }
  7703                              <1> l_gfx_uc_4:
  7704                              <1>     	; write_byte(BIOSMEM_SEG, BIOSMEM_CHAR_HEIGHT, CX);
  7705 0000342D 880D[E2670000]      <1> 	mov	[CHAR_HEIGHT], cl
  7706                              <1> 	; }
  7707 00003433 C3                  <1> 	retn
  7708                              <1> 
  7709                              <1> load_gfx_8_14_chars:
  7710                              <1> 	; 08/08/2016
  7711                              <1> 	; 10/07/2016
  7712                              <1> 	; Setup ROM 8x14 Font for Graphics Mode (VGA)
  7713                              <1> 	;
  7714                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  7715                              <1> 	; vgabios-0.7a (2011)
  7716                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  7717                              <1> 	; 'vgabios.c', 'biosfn_load_gfx_8_14_chars'
  7718                              <1> 
  7719                              <1> 	; biosfn_load_gfx_8_14_chars (BL)
  7720                              <1> 	; /* set 0x43 INT pointer */
  7721                              <1>     	; write_word(0x0, 0x43*4, &vgafont14);
  7722                              <1>     	; write_word(0x0, 0x43*4+2, 0xC000);
  7723 00003434 C705[66890100]-     <1> 	mov	dword [VGA_INT43H], vgafont14
  7723 0000343A [545B0100]          <1>
  7724                              <1> 		
  7725                              <1> 	; BL    screen rows code: 00H = user-specified (in DL)
  7726                              <1>         ;                         01H = 14 rows
  7727                              <1>         ;                         02H = 25 rows
  7728                              <1>         ;                         03H = 43 rows
  7729                              <1>         ; DL    (when BL=0) custom number of char rows on screen
  7730                              <1> 
  7731                              <1> 	; switch (BL) {
  7732                              <1> 	; case 0:
  7733                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, DL-1);
  7734                              <1> 	;    break;
  7735 0000343E 20DB                <1> 	and	bl, bl
  7736 00003440 7508                <1> 	jnz	short l_gfx_8_14c_1
  7737 00003442 8815[E6670000]      <1> 	mov	[VGA_ROWS], dl  ; not DL-1 !
  7738 00003448 EB23                <1> 	jmp	short l_gfx_8_14c_4
  7739                              <1> l_gfx_8_14c_1:
  7740                              <1> 	; case 1:
  7741                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 13);
  7742                              <1> 	;    break;
  7743 0000344A FECB                <1> 	dec	bl
  7744 0000344C 7509                <1> 	jnz	short l_gfx_8_14c_2
  7745                              <1> 	; bl = 1
  7746 0000344E C605[E6670000]0E    <1> 	mov	byte [VGA_ROWS], 14  ; not 13 !
  7747 00003455 EB16                <1> 	jmp	short l_gfx_8_14c_4
  7748                              <1> l_gfx_8_14c_2:
  7749 00003457 FECB                <1> 	dec	bl
  7750 00003459 740B                <1> 	jz	short l_gfx_8_14c_3 ; bl = 2
  7751 0000345B FECB                <1> 	dec	bl
  7752 0000345D 750E                <1> 	jnz	short l_gfx_8_14c_4 ; bl > 3
  7753                              <1> 	; bl = 3
  7754                              <1> 	; case 3:
  7755                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 42);
  7756                              <1> 	;    break;
  7757 0000345F C605[E6670000]2B    <1> 	mov	byte [VGA_ROWS], 43  ; not 42 !
  7758                              <1> l_gfx_8_14c_3:
  7759                              <1>     	; case 2:
  7760                              <1>     	; default:
  7761                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 24);
  7762                              <1> 	;    break;
  7763                              <1> 	; bl = 2 or bl > 3
  7764 00003466 C605[E6670000]19    <1> 	mov	byte [VGA_ROWS], 25  ; not 24 !
  7765                              <1>     	; }
  7766                              <1> l_gfx_8_14c_4:
  7767                              <1>     	; write_byte(BIOSMEM_SEG, BIOSMEM_CHAR_HEIGHT, 14);
  7768 0000346D C605[E2670000]0E    <1>         mov     byte [CHAR_HEIGHT], 14
  7769                              <1> 	; }
  7770 00003474 C3                  <1> 	retn	
  7771                              <1> 
  7772                              <1> load_gfx_8_8_chars:
  7773                              <1> 	; 08/08/2016
  7774                              <1> 	; 10/07/2016
  7775                              <1> 	; Setup ROM 8x14 Font for Graphics Mode (VGA)
  7776                              <1> 	;
  7777                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  7778                              <1> 	; vgabios-0.7a (2011)
  7779                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  7780                              <1> 	; 'vgabios.c', 'biosfn_load_gfx_8_8_dd_chars'
  7781                              <1> 
  7782                              <1> 	; biosfn_load_gfx_8_8_dd_chars (BL)
  7783                              <1> 	; /* set 0x43 INT pointer */
  7784                              <1>     	; write_word(0x0, 0x43*4, &vgafont8);
  7785                              <1>     	; write_word(0x0, 0x43*4+2, 0xC000);
  7786 00003475 C705[66890100]-     <1> 	mov	dword [VGA_INT43H], vgafont8
  7786 0000347B [54530100]          <1>
  7787                              <1> 		
  7788                              <1> 	; BL    screen rows code: 00H = user-specified (in DL)
  7789                              <1>         ;                         01H = 14 rows
  7790                              <1>         ;                         02H = 25 rows
  7791                              <1>         ;                         03H = 43 rows
  7792                              <1>         ; DL    (when BL=0) custom number of char rows on screen
  7793                              <1> 
  7794                              <1> 	; switch (BL) {
  7795                              <1> 	; case 0:
  7796                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, DL-1);
  7797                              <1> 	;    break;
  7798 0000347F 20DB                <1> 	and	bl, bl
  7799 00003481 7508                <1> 	jnz	short l_gfx_8_8c_1
  7800 00003483 8815[E6670000]      <1> 	mov	[VGA_ROWS], dl  ; not DL-1 !
  7801 00003489 EB23                <1> 	jmp	short l_gfx_8_8c_4 	
  7802                              <1> l_gfx_8_8c_1:
  7803                              <1> 	; case 1:
  7804                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 13);
  7805                              <1> 	;    break;
  7806 0000348B FECB                <1> 	dec	bl
  7807 0000348D 7509                <1> 	jnz	short l_gfx_8_8c_2
  7808                              <1> 	; bl = 1
  7809 0000348F C605[E6670000]0E    <1> 	mov	byte [VGA_ROWS], 14  ; not 13 !
  7810 00003496 EB16                <1> 	jmp	short l_gfx_8_8c_4 	
  7811                              <1> l_gfx_8_8c_2:
  7812 00003498 FECB                <1> 	dec	bl
  7813 0000349A 740B                <1> 	jz	short l_gfx_8_8c_3 ; bl = 2
  7814 0000349C FECB                <1> 	dec	bl
  7815 0000349E 750E                <1> 	jnz	short l_gfx_8_8c_4 ; bl > 3
  7816                              <1> 	; bl = 3
  7817                              <1> 	; case 3:
  7818                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 42);
  7819                              <1> 	;    break;
  7820 000034A0 C605[E6670000]2B    <1> 	mov	byte [VGA_ROWS], 43  ; not 42 !
  7821                              <1> l_gfx_8_8c_3:
  7822                              <1>     	; case 2:
  7823                              <1>     	; default:
  7824                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 24);
  7825                              <1> 	;    break;
  7826                              <1> 	; bl = 2 or bl > 3
  7827 000034A7 C605[E6670000]19    <1> 	mov	byte [VGA_ROWS], 25  ; not 24 !	
  7828                              <1>     	; }
  7829                              <1> l_gfx_8_8c_4:
  7830                              <1>     	; write_byte(BIOSMEM_SEG, BIOSMEM_CHAR_HEIGHT, 8);
  7831 000034AE C605[E2670000]08    <1>         mov     byte [CHAR_HEIGHT], 8
  7832                              <1> 	; }
  7833 000034B5 C3                  <1> 	retn
  7834                              <1> 
  7835                              <1> load_gfx_8_16_chars:
  7836                              <1> 	; 08/08/2016
  7837                              <1> 	; 10/07/2016
  7838                              <1> 	; Setup ROM 8x14 Font for Graphics Mode (VGA)
  7839                              <1> 	;
  7840                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  7841                              <1> 	; vgabios-0.7a (2011)
  7842                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  7843                              <1> 	; 'vgabios.c', 'biosfn_load_gfx_8_16_chars'
  7844                              <1> 
  7845                              <1> 	; biosfn_load_gfx_8_16_chars (BL)
  7846                              <1> 	; /* set 0x43 INT pointer */
  7847                              <1>     	; write_word(0x0, 0x43*4, &vgafont16);
  7848                              <1>     	; write_word(0x0, 0x43*4+2, 0xC000);
  7849 000034B6 C705[66890100]-     <1> 	mov	dword [VGA_INT43H], vgafont16
  7849 000034BC [54690100]          <1>
  7850                              <1> 		
  7851                              <1> 	; BL    screen rows code: 00H = user-specified (in DL)
  7852                              <1>         ;                         01H = 14 rows
  7853                              <1>         ;                         02H = 25 rows
  7854                              <1>         ;                         03H = 43 rows
  7855                              <1>         ; DL    (when BL=0) custom number of char rows on screen
  7856                              <1> 
  7857                              <1> 	; switch (BL) {
  7858                              <1> 	; case 0:
  7859                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, DL-1);
  7860                              <1> 	;    break;
  7861 000034C0 20DB                <1> 	and	bl, bl
  7862 000034C2 7508                <1> 	jnz	short l_gfx_8_16c_1
  7863 000034C4 8815[E6670000]      <1> 	mov	[VGA_ROWS], dl  ; not DL-1 !
  7864 000034CA EB23                <1> 	jmp	short l_gfx_8_16c_4 	
  7865                              <1> l_gfx_8_16c_1:
  7866                              <1> 	; case 1:
  7867                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 13);
  7868                              <1> 	;    break;
  7869 000034CC FECB                <1> 	dec	bl
  7870 000034CE 7509                <1> 	jnz	short l_gfx_8_16c_2
  7871                              <1> 	; bl = 1
  7872 000034D0 C605[E6670000]0E    <1> 	mov	byte [VGA_ROWS], 14  ; not 13 !
  7873 000034D7 EB16                <1> 	jmp	short l_gfx_8_16c_4
  7874                              <1> l_gfx_8_16c_2:
  7875 000034D9 FECB                <1> 	dec	bl
  7876 000034DB 740B                <1> 	jz	short l_gfx_8_16c_3 ; bl = 2
  7877 000034DD FECB                <1> 	dec	bl
  7878 000034DF 750E                <1> 	jnz	short l_gfx_8_16c_4 ; bl > 3
  7879                              <1> 	; bl = 3
  7880                              <1> 	; case 3:
  7881                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 42);
  7882                              <1> 	;    break;
  7883 000034E1 C605[E6670000]2B    <1> 	mov	byte [VGA_ROWS], 43  ; not 42 !
  7884                              <1> l_gfx_8_16c_3:
  7885                              <1>     	; case 2:
  7886                              <1>     	; default:
  7887                              <1> 	;    write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, 24);
  7888                              <1> 	;    break;
  7889                              <1> 	; bl = 2 or bl > 3
  7890 000034E8 C605[E6670000]19    <1> 	mov	byte [VGA_ROWS], 25  ; not 24 !	
  7891                              <1>     	; }
  7892                              <1> l_gfx_8_16c_4:
  7893                              <1>     	; write_byte(BIOSMEM_SEG, BIOSMEM_CHAR_HEIGHT, 16);
  7894 000034EF C605[E2670000]10    <1>         mov     byte [CHAR_HEIGHT], 16
  7895                              <1> 	; }
  7896 000034F6 C3                  <1> 	retn
  7897                              <1> 			
  7898                              <1> get_font_info:
  7899                              <1> 	; 03/08/2022 (TRDOS 386 v2.0.5)
  7900                              <1> 	; 08/01/2021 (TRDOS 386 v2.0.3)
  7901                              <1> 	; 19/09/2016
  7902                              <1> 	; 08/08/2016
  7903                              <1> 	; 10/07/2016
  7904                              <1> 	; Get Current Character Generator Info (VGA)
  7905                              <1> 	;
  7906                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  7907                              <1> 	; vgabios-0.7a (2011)
  7908                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  7909                              <1> 	; 'vgabios.c', 'biosfn_get_font_info'
  7910                              <1> 
  7911                              <1> 	; Modified for TRDOS 386 !
  7912                              <1> 	;
  7913                              <1> 	; INPUT ->
  7914                              <1> 	;    AX = 1130h
  7915                              <1> 	;    BL = 0 -> Get info for current VGA font
  7916                              <1> 	;	       (BH = unused)
  7917                              <1> 	;    19/09/2016
  7918                              <1> 	;    BL > 0 -> Get requested character font data
  7919                              <1> 	;	 BL = 1 -> vgafont8
  7920                              <1> 	;        BL = 2 -> vgafont14
  7921                              <1> 	;	 BL = 3 -> vgafont16   
  7922                              <1> 	;	;08/01/2021
  7923                              <1> 	;	 BL = 4 -> user defined 8x8 font
  7924                              <1> 	;	 BL = 5 -> user defined 8x14 font
  7925                              <1> 	;	 BL = 6 -> user defined 8x16 font
  7926                              <1> 	;	 BL > 6 -> Invalid function (for now!)
  7927                              <1> 	;	 BH = ASCII code of the first character
  7928                              <1> 	;	 ECX = Number of characters from the 1st char
  7929                              <1> 	;	 ECX >= 256 -> All (256-BH) characters
  7930                              <1> 	;	 ECX = 0 -> All characters (BH = unused)
  7931                              <1> 	;        EDX = User's Buffer Address	
  7932                              <1> 	; OUTPUT ->
  7933                              <1> 	;    AL = height (scanlines), bytes per character
  7934                              <1> 	;    AH = screen rows
  7935                              <1> 	;    Byte 16-23 of EAX = number of columns
  7936                              <1> 	;    Byte 24-31 of EAX = 
  7937                              <1> 	;	  0 -> default font (not configured yet)
  7938                              <1> 	;	  0FFh -> user defined font
  7939                              <1> 	;	  14 = vgafont14
  7940                              <1> 	;	   8 = vgafont8
  7941                              <1> 	;	  16 = vgafont16
  7942                              <1> 	;   If BL input > 0 -> 
  7943                              <1> 	;       EAX = Actual transfer count
  7944                              <1> 	;
  7945 000034F7 20DB                <1> 	and	bl, bl
  7946 000034F9 740F                <1> 	jz	short gfi_1
  7947                              <1> 	; invalid function (input)
  7948                              <1> 	; 08/01/2021
  7949 000034FB 80FB04              <1> 	cmp	bl, 4
  7950 000034FE 7263                <1> 	jb	short gfi_5
  7951 00003500 7441                <1> 	je	short gfi_3	
  7952 00003502 80FB06              <1> 	cmp	bl, 6
  7953 00003505 744C                <1> 	je	short gfi_4
  7954                              <1> 	; bh = 5 or bh > 6
  7955                              <1> gfi_0:
  7956 00003507 31C0                <1> 	xor	eax, eax ; 0
  7957 00003509 C3                  <1> 	retn
  7958                              <1> gfi_1:
  7959 0000350A A0[E2670000]        <1> 	mov	al, [CHAR_HEIGHT]
  7960 0000350F 8A25[E6670000]      <1> 	mov	ah, [VGA_ROWS]
  7961 00003515 C1E010              <1> 	shl	eax, 16
  7962 00003518 A0[E0670000]        <1> 	mov	al, [CRT_COLS]
  7963 0000351D 8B0D[66890100]      <1> 	mov	ecx, [VGA_INT43H]
  7964 00003523 21C9                <1> 	and	ecx, ecx
  7965 00003525 7418                <1> 	jz	short gfi_2 ; 0 = default font
  7966                              <1> 	; 08/01/2021
  7967 00003527 FECC                <1> 	dec	ah ; 0FFh
  7968 00003529 81F900400900        <1> 	cmp	ecx, VGAFONT16USER
  7969 0000352F 740E                <1> 	je	short gfi_2
  7970 00003531 81F900500900        <1> 	cmp	ecx, VGAFONT8USER
  7971 00003537 7406                <1> 	je	short gfi_2	
  7972 00003539 8A25[E2670000]      <1> 	mov	ah, [CHAR_HEIGHT] ; font size = height
  7973                              <1> gfi_2:
  7974 0000353F C1C010              <1> 	rol	eax, 16
  7975 00003542 C3                  <1> 	retn
  7976                              <1> gfi_3:
  7977                              <1> 	; 08/01/2021
  7978 00003543 F605[8EA30100]08    <1> 	test	byte [ufont], 08h ; 8x8 user font
  7979 0000354A 74BB                <1> 	jz	short gfi_0 ; not loaded !
  7980 0000354C BE00500900          <1> 	mov	esi, VGAFONT8USER ; *
  7981                              <1> 	;mov	bl, 8
  7982                              <1> 	;jmp	short gfi_8
  7983 00003551 EB4A                <1> 	jmp	short gfi_10
  7984                              <1> gfi_4:
  7985                              <1> 	; 08/01/2021
  7986 00003553 F605[8EA30100]10    <1> 	test	byte [ufont], 10h ; 8x16 user font
  7987 0000355A 74AB                <1> 	jz	short gfi_0 ; not loaded !
  7988 0000355C BE00400900          <1> 	mov	esi, VGAFONT16USER ; *
  7989 00003561 EB15                <1> 	jmp	short gfi_7
  7990                              <1> gfi_5:
  7991 00003563 80FB02              <1> 	cmp	bl, 2
  7992 00003566 7230                <1> 	jb	short gfi_9
  7993 00003568 7709                <1> 	ja	short gfi_6
  7994                              <1> 	; BL = 2 -> vgafont14
  7995 0000356A BE[545B0100]        <1> 	mov	esi, vgafont14 ; *
  7996 0000356F B30E                <1> 	mov	bl, 14
  7997 00003571 EB07                <1> 	jmp	short gfi_8 
  7998                              <1> gfi_6:
  7999                              <1> 	; BL = 3 -> vgafont16
  8000 00003573 BE[54690100]        <1> 	mov	esi, vgafont16 ; *
  8001                              <1> gfi_7:
  8002 00003578 B310                <1> 	mov	bl, 16
  8003                              <1> gfi_8:
  8004 0000357A 89D7                <1> 	mov	edi, edx ; **
  8005 0000357C 09C9                <1> 	or	ecx, ecx
  8006 0000357E 7421                <1> 	jz	short gfi_11 ; all chars from the 00h
  8007                              <1> 	;mov	al, bh ; character index
  8008                              <1> 	; 03/08/2022
  8009 00003580 0FB6C7              <1> 	movzx	eax, bh
  8010 00003583 F6E3                <1> 	mul	bl ; char index * char height/size
  8011                              <1> 	;movzx	edx, ax
  8012                              <1> 	; 03/08/2022
  8013                              <1> 	;add	esi, edx ; *
  8014 00003585 01C6                <1> 	add	esi, eax
  8015 00003587 31D2                <1> 	xor	edx, edx
  8016 00003589 FECA                <1> 	dec	dl 
  8017                              <1> 	; edx = 0FFh = 255
  8018                              <1> 	;mov	dx, 255
  8019 0000358B 28FA                <1> 	sub	dl, bh
  8020                              <1> 	;inc	dx	
  8021                              <1> 	; 03/08/2022
  8022 0000358D 42                  <1> 	inc	edx
  8023 0000358E 39D1                <1> 	cmp	ecx, edx
  8024 00003590 770F                <1> 	ja	short gfi_11
  8025 00003592 7411                <1> 	je	short gfi_12
  8026 00003594 89D1                <1> 	mov	ecx, edx
  8027 00003596 EB0D                <1> 	jmp	short gfi_12
  8028                              <1> gfi_9:
  8029                              <1> 	;BL = 1 -> vgafont8
  8030 00003598 BE[54530100]        <1> 	mov	esi, vgafont8 ; *
  8031                              <1> gfi_10:
  8032 0000359D B308                <1> 	mov	bl, 8
  8033 0000359F EBD9                <1> 	jmp	short gfi_8
  8034                              <1> gfi_11:
  8035                              <1> 	;mov	ecx, 256
  8036                              <1> 	; 03/08/2022
  8037 000035A1 29C9                <1> 	sub	ecx, ecx
  8038 000035A3 FEC5                <1> 	inc	ch
  8039                              <1> 	; ecx = 100h 
  8040                              <1> gfi_12:
  8041                              <1> 	; 08/01/2021
  8042 000035A5 89C8                <1> 	mov	eax, ecx ; character count
  8043 000035A7 30FF                <1> 	xor	bh, bh
  8044 000035A9 66F7E3              <1> 	mul	bx ; char count * char height/size
  8045 000035AC 89C1                <1>  	mov	ecx, eax
  8046                              <1> 
  8047                              <1> 	; ESI = source address in system space
  8048                              <1> 	; EDI = user's buffer address
  8049                              <1> 	; ECX = transfer (byte) count
  8050 000035AE E8DDD90000          <1> 	call	transfer_to_user_buffer
  8051 000035B3 89C8                <1> 	mov	eax, ecx ; actual transfer count
  8052 000035B5 C3                  <1> 	retn
  8053                              <1> 
  8054                              <1> set_all_palette_reg:
  8055                              <1> 	; 03/08/2022
  8056                              <1> 	; 10/08/2016
  8057                              <1> 	; Set All Palette Registers and Overscan
  8058                              <1> 	; EDX = Address of 17 bytes; 
  8059                              <1> 	; an rgbRGB value for each of 16 palette
  8060                              <1> 	; registers plus one for the border.
  8061                              <1> 
  8062 000035B6 89D6                <1> 	mov	esi, edx ; user buffer
  8063                              <1> 	;mov	ecx, 17
  8064                              <1> 	; 03/08/2022
  8065 000035B8 29C9                <1> 	sub	ecx, ecx
  8066 000035BA B111                <1> 	mov	cl, 17
  8067 000035BC 89E7                <1> 	mov	edi, esp
  8068 000035BE 83EC14              <1> 	sub	esp, 20	 	 
  8069 000035C1 E814DA0000          <1> 	call	transfer_from_user_buffer
  8070                              <1> 	;jc	VIDEO_RETURN
  8071                              <1> 
  8072 000035C6 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8073 000035CA EC                  <1> 	in	al, dx
  8074                              <1> 	;mov	cl, 0
  8075                              <1> 	; 03/08/2022
  8076 000035CB 28C9                <1> 	sub	cl, cl
  8077                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8078                              <1> 	; 03/08/2022
  8079 000035CD B2C0                <1> 	mov	dl, 0C0h
  8080                              <1> set_palette_loop:
  8081 000035CF 88C8                <1> 	mov	al, cl
  8082 000035D1 EE                  <1> 	out	dx, al
  8083 000035D2 8A07                <1> 	mov	al, [edi]
  8084 000035D4 EE                  <1> 	out	dx, al
  8085 000035D5 47                  <1> 	inc	edi
  8086 000035D6 FEC1                <1> 	inc	cl
  8087 000035D8 80F910              <1> 	cmp	cl, 10h
  8088 000035DB 75F2                <1> 	jne	short set_palette_loop
  8089 000035DD B011                <1> 	mov	al, 11h
  8090 000035DF EE                  <1> 	out	dx, al
  8091 000035E0 8A07                <1> 	mov	al, [edi]
  8092 000035E2 EE                  <1> 	out	dx, al
  8093 000035E3 B020                <1> 	mov	al, 20h
  8094 000035E5 EE                  <1> 	out	dx, al
  8095                              <1> 	; ifdef VBOX
  8096                              <1> 	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8097                              <1> 	; 03/08/2022
  8098 000035E6 B2DA                <1> 	mov	dl, 0DAh
  8099 000035E8 EC                  <1> 	in	al, dx
  8100                              <1> 	; endif ; VBOX
  8101 000035E9 83C414              <1> 	add	esp, 20
  8102 000035EC E941E5FFFF          <1> 	jmp	VIDEO_RETURN
  8103                              <1> 	
  8104                              <1> 	; 07/08/2022
  8105                              <1> toggle_intensity:
  8106                              <1> 	; 03/08/2022
  8107                              <1> 	; 10/08/2016
  8108                              <1> 	; Select Foreground Blink or Bold Background
  8109                              <1> 	; BL = 00h = enable bold backgrounds
  8110                              <1> 	;	    (16 background colors)
  8111                              <1>         ;      01h = enable blinking foreground
  8112                              <1> 	;	    (8 background colors)
  8113                              <1> 
  8114 000035F1 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8115 000035F5 EC                  <1> 	in	al, dx
  8116                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8117                              <1> 	; 03/08/2022
  8118 000035F6 B2C0                <1> 	mov	dl, 0C0h
  8119 000035F8 B010                <1> 	mov	al, 10h
  8120 000035FA EE                  <1> 	out	dx, al
  8121                              <1> 	;mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
  8122                              <1> 	; 03/08/2022
  8123 000035FB FEC2                <1> 	inc	dl ; dx = 3C1h
  8124 000035FD EC                  <1> 	in	al, dx
  8125 000035FE 24F7                <1> 	and	al, 0F7h
  8126 00003600 80E301              <1> 	and	bl, 01h
  8127 00003603 C0E303              <1> 	shl	bl, 3
  8128 00003606 08D8                <1> 	or	al, bl
  8129                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8130                              <1> 	; 03/08/2022
  8131 00003608 FECA                <1> 	dec	dl ; dx = 3C0h
  8132 0000360A EE                  <1> 	out	dx, al
  8133 0000360B B020                <1> 	mov	al, 20h
  8134 0000360D EE                  <1> 	out	dx, al
  8135                              <1> 	; ifdef VBOX
  8136                              <1> 	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8137                              <1> 	; 03/08/2022
  8138 0000360E B2DA                <1> 	mov	dl, 0DAh
  8139 00003610 EC                  <1> 	in	al, dx
  8140                              <1> 	; endif ; VBOX
  8141 00003611 E91CE5FFFF          <1> 	jmp	VIDEO_RETURN
  8142                              <1> 
  8143                              <1> 	; 07/08/2022
  8144                              <1> vga_palf_unknown:
  8145 00003616 29C0                <1> 	sub	eax, eax ; 0 = invalid function
  8146 00003618 E91AE5FFFF          <1>         jmp     _video_return
  8147                              <1> 
  8148                              <1> 	; 07/08/2022
  8149                              <1> vga_palf_101B:
  8150 0000361D 3C1B                <1> 	cmp	al, 1Bh
  8151                              <1> 	;jne	short vga_palf_unknown
  8152 0000361F 77F5                <1> 	ja	short vga_palf_unknown
  8153                              <1>  
  8154 00003621 E810F6FFFF          <1> 	call	gray_scale_summing
  8155 00003626 E907E5FFFF          <1>         jmp     VIDEO_RETURN 
  8156                              <1> 	
  8157                              <1> vga_pal_funcs:
  8158                              <1> 	; 07/08/2022
  8159                              <1> 	; 10/08/2016
  8160                              <1> 	; VGA Palette functions
  8161                              <1> 	;
  8162                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
  8163                              <1> 	; vgabios-0.7a (2011)
  8164                              <1> 	; by the LGPL VGABios developers Team (2001-2008)
  8165                              <1> 	; 'vgabios.c', 'vgarom.asm'
  8166                              <1> 
  8167 0000362B 3C00                <1> 	cmp	al, 0
  8168 0000362D 7467                <1>         je      short set_single_palette_reg
  8169                              <1> vga_palf_1002:
  8170 0000362F 3C02                <1> 	cmp	al, 2
  8171 00003631 7483                <1>         je      short set_all_palette_reg
  8172                              <1> 	; 07/08/2022
  8173 00003633 7702                <1> 	ja	short vga_palf_1003
  8174 00003635 EB5D                <1> 	jmp	short set_overscan_border_color 
  8175                              <1> 	; 07/08/2022
  8176                              <1> ;vga_palf_1001:
  8177                              <1> ;	cmp	al, 1
  8178                              <1> ;	je	short set_overscan_border_color
  8179                              <1> vga_palf_1003:
  8180 00003637 3C03                <1> 	cmp	al, 3
  8181 00003639 74B6                <1> 	je	short toggle_intensity
  8182                              <1> vga_palf_1007:
  8183 0000363B 3C07                <1> 	cmp	al, 7
  8184 0000363D 747F                <1>         je      short get_single_palette_reg
  8185 0000363F 72D5                <1> 	jb	short vga_palf_unknown
  8186                              <1> vga_palf_1008:
  8187 00003641 3C08                <1> 	cmp	al, 8
  8188 00003643 7477                <1>         je      short read_overscan_border_color
  8189                              <1> vga_palf_1009:
  8190 00003645 3C09                <1> 	cmp	al, 9
  8191                              <1> 	;je	short get_all_palette_reg
  8192                              <1> 	; 07/08/2022
  8193 00003647 7505                <1> 	jne	short vga_palf_1010
  8194 00003649 E966010000          <1> 	jmp	get_all_palette_reg
  8195                              <1> vga_palf_1010:
  8196 0000364E 3C10                <1> 	cmp	al, 10h
  8197                              <1> 	;je 	short set_single_dac_reg
  8198                              <1> 	; 07/08/2022
  8199 00003650 7707                <1> 	ja	short vga_palf_1012
  8200 00003652 72C2                <1> 	jb	short vga_palf_unknown
  8201 00003654 E908010000          <1> 	jmp	set_single_dac_reg
  8202                              <1> vga_palf_1012:
  8203 00003659 3C12                <1> 	cmp	al, 12h
  8204                              <1> 	;je	short set_all_dac_reg
  8205                              <1> 	; 07/08/2022
  8206 0000365B 7707                <1> 	ja	short vga_palf_1013
  8207 0000365D 72B7                <1> 	jb	short vga_palf_unknown
  8208 0000365F E916010000          <1> 	jmp	set_all_dac_reg	
  8209                              <1> vga_palf_1013:
  8210 00003664 3C13                <1> 	cmp	al, 13h
  8211                              <1> 	;je	short select_video_dac_color_page
  8212                              <1> 	; 07/08/2022
  8213 00003666 7505                <1> 	jne	short vga_palf_1015
  8214 00003668 E992010000          <1> 	jmp	select_video_dac_color_page
  8215                              <1> vga_palf_1015:
  8216 0000366D 3C15                <1> 	cmp	al, 15h
  8217                              <1> 	;je	short read_single_dac_reg
  8218                              <1> 	; 07/08/2022
  8219 0000366F 7707                <1> 	ja	short vga_palf_1017
  8220 00003671 72A3                <1> 	jb	short vga_palf_unknown
  8221 00003673 E98D000000          <1> 	jmp	read_single_dac_reg
  8222                              <1> vga_palf_1017:
  8223 00003678 3C17                <1> 	cmp	al, 17h
  8224                              <1> 	;je	short read_all_dac_reg
  8225                              <1> 	; 07/08/2022
  8226 0000367A 7707                <1> 	ja	short vga_palf_1018
  8227 0000367C 7298                <1> 	jb	short vga_palf_unknown
  8228 0000367E E9A0000000          <1> 	jmp	read_all_dac_reg
  8229                              <1> vga_palf_1018:
  8230 00003683 3C18                <1> 	cmp	al, 18h
  8231 00003685 7464                <1>         je	short set_pel_mask
  8232                              <1> vga_palf_1019:
  8233 00003687 3C19                <1> 	cmp	al, 19h
  8234 00003689 746C                <1>         je	short read_pel_mask
  8235                              <1> vga_palf_101A:
  8236 0000368B 3C1A                <1> 	cmp	al, 1Ah
  8237                              <1>         ;je	short read_video_dac_state
  8238                              <1> 	; 07/08/2022
  8239 0000368D 758E                <1> 	jne	short vga_palf_101B
  8240 0000368F E9AD010000          <1> 	jmp	read_video_dac_state
  8241                              <1> 
  8242                              <1> 	; 07/08/2022
  8243                              <1> set_overscan_border_color:
  8244                              <1> 	; 10/08/2016
  8245                              <1> 	; Set Overscan/Border Color Register
  8246                              <1> 	; BH = 6-bit RGB color to display 
  8247                              <1> 	;      for that attribute
  8248                              <1> 	
  8249 00003694 B311                <1> 	mov	bl, 11h
  8250                              <1>   	; 07/08/2022
  8251                              <1> 	;jmp	short set_single_palette_reg
  8252                              <1> 
  8253                              <1> set_single_palette_reg:
  8254                              <1> 	; 03/08/2022 (TRDOS 386 v2.0.5)
  8255                              <1> 	; 12/04/2021 (TRDOS 386 v2.0.3, 32 bit push/pop)
  8256                              <1> 	; 10/08/2016
  8257                              <1> 	; Set One Palette Register
  8258                              <1> 	; BL = register number to set
  8259                              <1> 	;     (a 4-bit attribute nibble: 00h-0Fh)
  8260                              <1> 	; BH = 6-bit RGB color to display 
  8261                              <1> 	;      for that attribute
  8262                              <1> 
  8263 00003696 80FB14              <1> 	cmp	bl, 14h
  8264                              <1> 	;;ja	short no_actl_reg1
  8265                              <1> 	;ja	VIDEO_RETURN
  8266                              <1> 	; 03/08/2022
  8267 00003699 7605                <1> 	jna	short sspr_1
  8268 0000369B E992E4FFFF          <1> 	jmp	VIDEO_RETURN
  8269                              <1> sspr_1:
  8270                              <1> 	;push	ax
  8271                              <1> 	;push	dx
  8272                              <1> 	; 12/04/2021
  8273 000036A0 50                  <1> 	push	eax
  8274 000036A1 52                  <1> 	push	edx
  8275 000036A2 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8276 000036A6 EC                  <1> 	in	al, dx
  8277                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8278                              <1> 	; 03/08/2022
  8279 000036A7 B2C0                <1> 	mov	dl, 0C0h
  8280 000036A9 88D8                <1> 	mov	al, bl
  8281 000036AB EE                  <1> 	out	dx, al
  8282 000036AC 88F8                <1> 	mov	al, bh
  8283 000036AE EE                  <1> 	out	dx, al
  8284 000036AF B020                <1> 	mov	al, 20h
  8285 000036B1 EE                  <1> 	out	dx, al
  8286                              <1> 	; ifdef VBOX
  8287                              <1> 	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8288                              <1> 	; 03/08/2022
  8289 000036B2 B2DA                <1> 	mov	dl, 0DAh
  8290 000036B4 EC                  <1> 	in	al, dx
  8291                              <1> 	; endif ; VBOX
  8292                              <1> 	;pop	dx
  8293                              <1> 	;pop	ax
  8294                              <1> 	; 12/04/2021
  8295 000036B5 5A                  <1> 	pop	edx
  8296 000036B6 58                  <1> 	pop	eax
  8297                              <1> ;no_actl_reg1:
  8298 000036B7 E976E4FFFF          <1> 	jmp	VIDEO_RETURN
  8299                              <1> 
  8300                              <1> 	; 07/08/2022
  8301                              <1> read_overscan_border_color:
  8302                              <1> 	; 10/08/2016
  8303                              <1> 	; Read Overscan Register
  8304                              <1> 	; OUTPUT:
  8305                              <1> 	; BH = current rgbRGB value 
  8306                              <1> 	;      of the overscan/border register
  8307                              <1> 
  8308 000036BC B311                <1> 	mov	bl, 11h
  8309                              <1> 	; 07/08/2022
  8310                              <1> 	;jmp	short get_single_palette_reg
  8311                              <1> 
  8312                              <1> get_single_palette_reg:
  8313                              <1> 	; 03/08/2022
  8314                              <1> 	; 10/08/2016
  8315                              <1> 	; Read One Palette Register
  8316                              <1>         ; INPUT:
  8317                              <1> 	; BL = Palette register to read (00h-0Fh)
  8318                              <1> 	; OUTPUT:
  8319                              <1> 	; BH = Current rgbRGB value of specified register
  8320                              <1> 	;      for that attribute
  8321                              <1> 
  8322 000036BE 80FB14              <1> 	cmp	bl, 14h
  8323                              <1> 	;;ja	short no_actl_reg2
  8324                              <1> 	;ja	VIDEO_RETURN
  8325                              <1> 	; 03/08/2022
  8326 000036C1 7605                <1> 	jna	short gspr_1
  8327 000036C3 E96AE4FFFF          <1> 	jmp	VIDEO_RETURN
  8328                              <1> gspr_1:
  8329 000036C8 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8330                              <1> 	; 03/08/2022
  8331 000036CC B2DA                <1> 	mov	dl, 0DAh
  8332 000036CE EC                  <1> 	in	al, dx
  8333                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8334                              <1> 	; 03/08/2022
  8335 000036CF B2C0                <1> 	mov	dl, 0C0h
  8336 000036D1 88D8                <1> 	mov	al, bl
  8337 000036D3 EE                  <1> 	out	dx, al
  8338                              <1> 	;mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
  8339                              <1> 	; 03/08/2022
  8340 000036D4 FEC2                <1> 	inc	dl ; dx = 3C1h
  8341 000036D6 EC                  <1> 	in	al, dx
  8342 000036D7 8844240D            <1> 	mov	[esp+13], al ; bh
  8343                              <1> 	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8344                              <1> 	; 03/08/2022
  8345 000036DB B2DA                <1> 	mov	dl, 0DAh
  8346 000036DD EC                  <1> 	in	al, dx
  8347                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8348                              <1> 	; 03/08/2022
  8349 000036DE B2C0                <1> 	mov	dl, 0C0h
  8350 000036E0 B020                <1> 	mov	al, 20h
  8351 000036E2 EE                  <1> 	out	dx, al
  8352                              <1> 	; ifdef VBOX
  8353                              <1> 	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8354                              <1> 	; 03/08/2022
  8355 000036E3 B2DA                <1> 	mov	dl, 0DAh
  8356 000036E5 EC                  <1> 	in	al, dx
  8357                              <1> 	; endif ; VBOX
  8358 000036E6 E947E4FFFF          <1> 	jmp	VIDEO_RETURN
  8359                              <1> 
  8360                              <1> set_pel_mask:
  8361                              <1> 	; 10/08/2016
  8362                              <1> 	; BL = mask value
  8363 000036EB 66BAC603            <1> 	mov	dx, 3C6h ; VGAREG_PEL_MASK
  8364 000036EF 88D8                <1> 	mov	al, bl
  8365 000036F1 EE                  <1> 	out	dx, al
  8366 000036F2 E93BE4FFFF          <1> 	jmp	VIDEO_RETURN
  8367                              <1> 
  8368                              <1> read_pel_mask:
  8369                              <1> 	; 10/08/2016
  8370                              <1> 	; Output: BL = mask value 
  8371 000036F7 66BAC603            <1> 	mov	dx, 3C6h ; VGAREG_PEL_MASK
  8372 000036FB EC                  <1> 	in	al, dx
  8373 000036FC 8844240C            <1> 	mov	[esp+12], al ; bl
  8374 00003700 E92DE4FFFF          <1> 	jmp	VIDEO_RETURN
  8375                              <1> 
  8376                              <1> read_single_dac_reg:
  8377                              <1> 	; 02/08/2022
  8378                              <1> 	; 10/08/2016
  8379                              <1> 	; Read One DAC Color Register
  8380                              <1> 	; INPUT:
  8381                              <1> 	; BX = color register to read (0-255)
  8382                              <1> 	; OUTPUT:
  8383                              <1> 	; CH = green value (00h-3Fh)
  8384                              <1>         ; CL = blue value  (00h-3Fh)
  8385                              <1>         ; DH = red value   (00h-3Fh)
  8386                              <1> 
  8387 00003705 66BAC703            <1> 	mov	dx, 3C7h ; VGAREG_DAC_READ_ADDRESS
  8388 00003709 88D8                <1> 	mov	al, bl
  8389 0000370B EE                  <1> 	out	dx, al
  8390                              <1> 	;mov	dx, 3C9h ; VGAREG_DAC_DATA
  8391                              <1> 	; 02/08/2022
  8392 0000370C B2C9                <1> 	mov	dl, 0C9h
  8393 0000370E EC                  <1> 	in	al, dx
  8394 0000370F 88442415            <1> 	mov	[esp+21], al ; dh
  8395 00003713 EC                  <1> 	in	al, dx
  8396 00003714 88C5                <1> 	mov	ch, al
  8397 00003716 EC                  <1> 	in	al, dx
  8398 00003717 88C1                <1> 	mov	cl, al
  8399 00003719 66894C2410          <1> 	mov	[esp+16], cx ; cx
  8400 0000371E E90FE4FFFF          <1> 	jmp	VIDEO_RETURN
  8401                              <1> 
  8402                              <1> read_all_dac_reg:
  8403                              <1> 	; 02/08/2022
  8404                              <1> 	; 12/08/2016
  8405                              <1> 	; 11/08/2016
  8406                              <1> 	; 10/08/2016
  8407                              <1> 	; Read a Block of DAC Color Registers
  8408                              <1>         ; BX = first DAC register to read (0-00FFh)
  8409                              <1>         ; ECX = number of registers to read (0-00FFh)
  8410                              <1>         ; EDX = addr of a buffer to hold R,G,B values
  8411                              <1> 	;	(CX*3 bytes long)
  8412                              <1> 
  8413 00003723 89D7                <1> 	mov	edi, edx ; user buffer
  8414 00003725 89CA                <1> 	mov	edx, ecx
  8415                              <1> 	;shl	dx, 1 ; *2
  8416                              <1> 	; 02/08/2022
  8417 00003727 D1E2                <1> 	shl	edx, 1
  8418 00003729 01CA                <1> 	add	edx, ecx ; edx = 3*ecx
  8419 0000372B 89E5                <1> 	mov	ebp, esp
  8420 0000372D 89EE                <1> 	mov	esi, ebp
  8421 0000372F 29D6                <1> 	sub	esi, edx
  8422 00003731 6683E6FC            <1> 	and	si, 0FFFCh ; (dword alignment)
  8423 00003735 89F4                <1> 	mov	esp, esi
  8424 00003737 52                  <1> 	push	edx ; 3*ecx
  8425 00003738 66BAC703            <1> 	mov	dx, 3C7h ; VGAREG_DAC_READ_ADDRESS
  8426 0000373C 88D8                <1> 	mov	al, bl
  8427 0000373E EE                  <1> 	out	dx, al
  8428 0000373F 66BAC903            <1> 	mov	dx, 3C9h ; VGAREG_DAC_DATA
  8429 00003743 89F3                <1> 	mov	ebx, esi
  8430                              <1> read_dac_loop:
  8431 00003745 EC                  <1> 	in	al, dx
  8432 00003746 8803                <1> 	mov	[ebx], al
  8433 00003748 43                  <1> 	inc	ebx
  8434 00003749 EC                  <1> 	in	al, dx
  8435 0000374A 8803                <1> 	mov	[ebx], al
  8436 0000374C 43                  <1> 	inc	ebx
  8437 0000374D EC                  <1> 	in	al, dx
  8438 0000374E 8803                <1> 	mov	[ebx], al
  8439 00003750 43                  <1> 	inc	ebx
  8440                              <1> 	;dec	cx
  8441                              <1> 	; 02/08/2022
  8442 00003751 49                  <1> 	dec	ecx
  8443 00003752 75F1                <1> 	jnz	short read_dac_loop
  8444 00003754 59                  <1> 	pop	ecx ; 3*ecx
  8445                              <1> 	; ECX = transfer (byte) count
  8446                              <1> 	; ESI = source address in system space
  8447                              <1> 	; EDI = user's buffer address
  8448 00003755 E836D80000          <1> 	call	transfer_to_user_buffer
  8449 0000375A 89EC                <1> 	mov	esp, ebp
  8450 0000375C E9D1E3FFFF          <1> 	jmp	VIDEO_RETURN
  8451                              <1> 
  8452                              <1> set_single_dac_reg:
  8453                              <1> 	; 03/08/2022 (TRDOS 386 v2.0.5)
  8454                              <1> 	; 12/04/2021 (TRDOS 386 v2.0.3, 32 bit push/pop)
  8455                              <1> 	; 10/08/2016
  8456                              <1> 	; Set One DAC Color Register
  8457                              <1> 	; BX = color register to set (0-255)
  8458                              <1>         ; CH = green value (00h-3Fh)
  8459                              <1>         ; CL = blue value  (00h-3Fh)
  8460                              <1>         ; DH = red value   (00h-3Fh)
  8461                              <1> 
  8462                              <1> 	;push	dx
  8463                              <1> 	; 12/04/2021
  8464 00003761 52                  <1> 	push	edx
  8465 00003762 66BAC803            <1> 	mov	dx, 3C8h ; VGAREG_DAC_WRITE_ADDRESS
  8466 00003766 88D8                <1> 	mov	al, bl
  8467 00003768 EE                  <1> 	out	dx, al
  8468                              <1> 	;;mov	dx, 3C9h ; VGAREG_DAC_DATA
  8469                              <1> 	;inc	dx
  8470                              <1> 	; 03/08/2022
  8471 00003769 FEC2                <1> 	inc	dl
  8472                              <1> 	;pop	ax
  8473                              <1> 	; 12/04/2021
  8474 0000376B 58                  <1> 	pop	eax
  8475 0000376C 88E0                <1> 	mov	al, ah
  8476 0000376E EE                  <1> 	out	dx, al
  8477 0000376F 88E8                <1> 	mov	al, ch
  8478 00003771 EE                  <1> 	out	dx, al
  8479 00003772 88C8                <1> 	mov	al, cl
  8480 00003774 EE                  <1> 	out	dx, al
  8481 00003775 E9B8E3FFFF          <1> 	jmp	VIDEO_RETURN
  8482                              <1> 
  8483                              <1> set_all_dac_reg:
  8484                              <1> 	; 02/08/2022 
  8485                              <1> 	; 12/08/2016
  8486                              <1> 	; 11/08/2016
  8487                              <1> 	; 10/08/2016
  8488                              <1> 	; Set a Block of DAC Color Register
  8489                              <1> 	; BX = first DAC register to set (0-00FFh)
  8490                              <1> 	; ECX = number of registers to set (0-00FFh)
  8491                              <1> 	; EDX = addr of a table of R,G,B values 
  8492                              <1> 	;	(it will be CX*3 bytes long)
  8493                              <1> 
  8494 0000377A 89D6                <1> 	mov	esi, edx ; user buffer
  8495 0000377C 89CA                <1> 	mov	edx, ecx
  8496                              <1> 	;shl	cx, 1 ; *2
  8497                              <1> 	; 02/08/2022
  8498 0000377E D1E1                <1> 	shl	ecx, 1
  8499 00003780 01D1                <1> 	add	ecx, edx ; ecx = 3*ecx
  8500 00003782 89E5                <1> 	mov	ebp, esp
  8501 00003784 89EF                <1> 	mov	edi, ebp
  8502 00003786 29CF                <1> 	sub	edi, ecx
  8503 00003788 6683E7FC            <1> 	and	di, 0FFFCh ; (dword alignment)
  8504 0000378C 89FC                <1> 	mov	esp, edi
  8505 0000378E E847D80000          <1> 	call	transfer_from_user_buffer
  8506                              <1> 	;jc	VIDEO_RETURN
  8507                              <1> 
  8508 00003793 89D1                <1> 	mov	ecx, edx
  8509 00003795 66BAC803            <1> 	mov	dx, 3C8h ; VGAREG_DAC_WRITE_ADDRESS
  8510 00003799 88D8                <1> 	mov	al, bl
  8511 0000379B EE                  <1> 	out	dx, al
  8512                              <1> 	;mov	dx, 3C9h ; VGAREG_DAC_DATA
  8513                              <1> 	; 02/08/2022
  8514 0000379C FEC2                <1> 	inc	dl
  8515                              <1> set_dac_loop:
  8516 0000379E 8A07                <1> 	mov	al, [edi]
  8517 000037A0 EE                  <1> 	out	dx, al
  8518 000037A1 47                  <1> 	inc	edi
  8519 000037A2 8A07                <1> 	mov	al, [edi]
  8520 000037A4 EE                  <1> 	out	dx, al
  8521 000037A5 47                  <1> 	inc	edi
  8522 000037A6 8A07                <1> 	mov	al, [edi]
  8523 000037A8 EE                  <1> 	out	dx, al
  8524 000037A9 47                  <1> 	inc	edi
  8525                              <1> 	;dec	cx
  8526                              <1> 	; 02/08/2022
  8527 000037AA 49                  <1> 	dec	ecx
  8528 000037AB 75F1                <1> 	jnz	short set_dac_loop
  8529 000037AD 89EC                <1> 	mov	esp, ebp
  8530 000037AF E97EE3FFFF          <1> 	jmp	VIDEO_RETURN
  8531                              <1> 
  8532                              <1> get_all_palette_reg:
  8533                              <1> 	; 03/08/2022
  8534                              <1> 	; 10/08/2016
  8535                              <1> 	; Read All Palette Registers
  8536                              <1> 	; EDX = Address of 17-byte buffer 
  8537                              <1> 	;	to receive data
  8538                              <1> 	
  8539 000037B4 89D7                <1> 	mov	edi, edx
  8540 000037B6 89E3                <1> 	mov	ebx, esp
  8541 000037B8 89DE                <1> 	mov	esi, ebx
  8542 000037BA 83EC14              <1> 	sub	esp, 20	 
  8543                              <1> 
  8544 000037BD B100                <1> 	mov	cl, 0
  8545                              <1> get_palette_loop:
  8546 000037BF 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8547 000037C3 EC                  <1> 	in	al, dx
  8548                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8549                              <1> 	; 03/08/2022
  8550 000037C4 B2C0                <1> 	mov	dl, 0C0h
  8551 000037C6 88C8                <1> 	mov	al, cl
  8552 000037C8 EE                  <1> 	out	dx, al
  8553                              <1> 	;mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
  8554                              <1> 	; 03/08/2022
  8555                              <1> 	;mov	dl, 0C1h
  8556 000037C9 FEC2                <1> 	inc	dl
  8557 000037CB EC                  <1> 	in	al, dx
  8558 000037CC 8803                <1> 	mov	[ebx], al
  8559 000037CE 43                  <1> 	inc	ebx
  8560 000037CF FEC1                <1> 	inc	cl
  8561 000037D1 80F910              <1> 	cmp	cl, 10h
  8562 000037D4 75E9                <1> 	jne	short get_palette_loop
  8563                              <1> 	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8564                              <1> 	; 03/08/2022
  8565 000037D6 B2DA                <1> 	mov	dl, 0DAh
  8566 000037D8 EC                  <1> 	in	al, dx
  8567                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8568                              <1> 	; 03/08/2022
  8569 000037D9 B2C0                <1> 	mov	dl, 0C0h
  8570 000037DB B011                <1> 	mov	al, 11h
  8571 000037DD EE                  <1> 	out	dx, al
  8572                              <1> 	;mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
  8573                              <1> 	; 03/08/2022
  8574 000037DE FEC2                <1> 	inc	dl ; dx = 3C1h
  8575 000037E0 EC                  <1> 	in	al, dx
  8576 000037E1 8803                <1> 	mov	[ebx], al
  8577                              <1> 	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8578                              <1> 	; 03/08/2022
  8579 000037E3 B2DA                <1> 	mov	dl, 0DAh
  8580 000037E5 EC                  <1> 	in	al, dx
  8581                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8582                              <1> 	; 03/08/2022
  8583 000037E6 B2C0                <1> 	mov	dl, 0C0h
  8584 000037E8 B020                <1> 	mov	al, 20h
  8585 000037EA EE                  <1> 	out	dx, al
  8586                              <1> 	; ifdef VBOX
  8587                              <1> 	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8588                              <1> 	; 03/08/2022
  8589 000037EB B2DA                <1> 	mov	dl, 0DAh
  8590 000037ED EC                  <1> 	in	al, dx
  8591                              <1> 	; endif ; VBOX
  8592                              <1> 
  8593                              <1> 	;mov	ecx, 17 ; transfer (byte) count
  8594                              <1> 	; 03/08/2022
  8595 000037EE 29C9                <1> 	sub	ecx, ecx
  8596 000037F0 B111                <1> 	mov	cl, 17	
  8597                              <1> 
  8598                              <1> 	; ESI = source address in system space
  8599                              <1> 	; EDI = user's buffer address
  8600 000037F2 E899D70000          <1> 	call	transfer_to_user_buffer
  8601                              <1> 
  8602 000037F7 83C414              <1> 	add	esp, 20
  8603 000037FA E933E3FFFF          <1> 	jmp	VIDEO_RETURN
  8604                              <1> 
  8605                              <1> select_video_dac_color_page:
  8606                              <1> 	; 02/08/2022 (TRDOS 386 v2.0.5, code optimization)
  8607                              <1> 	; 12/04/2021 (TRDOS 386 v2.0.3, 32 bit push/pop)
  8608                              <1> 	; 10/08/2016
  8609                              <1> 	; DAC Color Paging Functions
  8610                              <1> 	; BL = 00H = select color paging mode
  8611                              <1>         ;       BH = paging mode
  8612                              <1>         ;            00h = 4 blocks of 64 registers
  8613                              <1>         ;            01h = 16 blocks of 16 registers
  8614                              <1> 	; BL = 01H = activate color page
  8615                              <1>         ;       BH = DAC color page number
  8616                              <1>         ;            00h-03h (4-page/64-reg mode)
  8617                              <1>         ;            00h-0Fh (16-page/16-reg mode)
  8618                              <1> 
  8619 000037FF 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8620 00003803 EC                  <1> 	in	al, dx
  8621                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8622                              <1> 	; 02/08/2022
  8623 00003804 B240                <1> 	mov	dl, 40h
  8624 00003806 B010                <1> 	mov	al, 10h
  8625 00003808 EE                  <1> 	out	dx, al
  8626                              <1> 	;mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
  8627                              <1> 	; 02/08/2022
  8628 00003809 FEC2                <1> 	inc	dl ; mov dl, 0C1h
  8629 0000380B EC                  <1> 	in	al, dx
  8630 0000380C 80E301              <1> 	and	bl, 01h
  8631 0000380F 750C                <1> 	jnz	short set_dac_page
  8632 00003811 247F                <1> 	and	al, 07Fh
  8633 00003813 C0E707              <1> 	shl	bh, 7
  8634 00003816 08F8                <1> 	or	al, bh
  8635                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8636                              <1> 	; 02/08/2022
  8637 00003818 FECA                <1> 	dec	dl ; mov dl, 0C0h
  8638 0000381A EE                  <1> 	out	dx, al
  8639 0000381B EB19                <1> 	jmp	short set_actl_normal
  8640                              <1> set_dac_page:
  8641                              <1> 	;push	ax
  8642                              <1> 	; 12/04/2021
  8643 0000381D 50                  <1> 	push	eax
  8644 0000381E 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8645 00003822 EC                  <1> 	in	al, dx
  8646                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8647                              <1> 	; 02/08/2022
  8648 00003823 B2C0                <1> 	mov	dl, 0C0h
  8649 00003825 B014                <1> 	mov	al, 14h
  8650 00003827 EE                  <1> 	out	dx, al
  8651                              <1> 	;pop	ax
  8652                              <1> 	; 12/04/2021
  8653 00003828 58                  <1> 	pop	eax
  8654 00003829 2480                <1> 	and	al, 80h
  8655 0000382B 7503                <1> 	jnz	short set_dac_16_page
  8656 0000382D C0E702              <1> 	shl	bh, 2
  8657                              <1> set_dac_16_page:
  8658 00003830 80E70F              <1> 	and	bh, 0Fh
  8659 00003833 88F8                <1> 	mov	al, bh
  8660 00003835 EE                  <1> 	out	dx, al
  8661                              <1> set_actl_normal:
  8662 00003836 B020                <1> 	mov	al, 20h
  8663 00003838 EE                  <1> 	out	dx, al
  8664                              <1> 	; ifdef VBOX
  8665                              <1> 	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8666                              <1> 	; 02/08/2022
  8667 00003839 B2DA                <1> 	mov	dl, 0DAh
  8668 0000383B EC                  <1> 	in	al, dx
  8669                              <1> 	; endif ; VBOX
  8670 0000383C E9F1E2FFFF          <1> 	jmp	VIDEO_RETURN
  8671                              <1> 
  8672                              <1> read_video_dac_state:
  8673                              <1> 	; 10/08/2016
  8674                              <1> 	; Query DAC Color Paging State
  8675                              <1> 	; Output:
  8676                              <1> 	; BH = current active DAC color page
  8677                              <1>         ; BL = current active DAC paging mode
  8678                              <1> 
  8679 00003841 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8680 00003845 EC                  <1> 	in	al, dx
  8681 00003846 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8682 0000384A B010                <1> 	mov	al, 10h
  8683 0000384C EE                  <1> 	out	dx, al
  8684 0000384D 66BAC103            <1> 	mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
  8685 00003851 EC                  <1> 	in	al, dx
  8686 00003852 88C3                <1> 	mov	bl, al
  8687 00003854 C0EB07              <1> 	shr	bl, 7
  8688 00003857 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8689 0000385B EC                  <1> 	in	al, dx
  8690 0000385C 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8691 00003860 B014                <1> 	mov	al, 14h
  8692 00003862 EE                  <1> 	out	dx, al
  8693 00003863 66BAC103            <1> 	mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
  8694 00003867 EC                  <1> 	in	al, dx
  8695 00003868 88C7                <1> 	mov	bh, al
  8696 0000386A 80E70F              <1> 	and	bh, 0Fh
  8697 0000386D F6C301              <1> 	test	bl, 01
  8698 00003870 7503                <1> 	jnz	short get_dac_16_page
  8699 00003872 C0EF02              <1> 	shr	bh, 2
  8700                              <1> get_dac_16_page:
  8701 00003875 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8702 00003879 EC                  <1> 	in	al, dx
  8703 0000387A 66BAC003            <1> 	mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
  8704 0000387E B020                <1> 	mov	al, 20h
  8705 00003880 EE                  <1> 	out	dx, al
  8706                              <1> 	; ifdef VBOX
  8707 00003881 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
  8708 00003885 EC                  <1> 	in	al, dx
  8709                              <1> 	; endif ; VBOX 
  8710 00003886 66895C240C          <1> 	mov	[esp+12], bx ; bx
  8711 0000388B E9A2E2FFFF          <1> 	jmp	VIDEO_RETURN
  8712                              <1> 
  8713                              <1> ; 23/11/2020 - TRDOS 386 v2.0.3
  8714                              <1> ; VBE 2 BOCHS/QEMU emulator extensions 
  8715                              <1> ;	for TRDOS 386 v2 kernel (video bios)
  8716                              <1> 
  8717                              <1> ; BOCH/QEMU VBE2 VGA BIOS code 
  8718                              <1> ;	by Jeroen Janssen (2002)
  8719                              <1> ;	by Volker Rupper (2003-2020)
  8720                              <1> ; vbe.c (02/01/2020) 
  8721                              <1> 
  8722                              <1> ; vbe.h (02/01/2020)
  8723                              <1> 
  8724                              <1> VBE_DISPI_BANK_ADDRESS	equ	0A0000h
  8725                              <1> VBE_DISPI_BANK_SIZE_KB	equ	64
  8726                              <1> 
  8727                              <1> VBE_DISPI_MAX_XRES	equ	2560
  8728                              <1> VBE_DISPI_MAX_YRES	equ	1600
  8729                              <1> 
  8730                              <1> VBE_DISPI_IOPORT_INDEX	equ	01CEh
  8731                              <1> VBE_DISPI_IOPORT_DATA	equ	01CFh
  8732                              <1> 
  8733                              <1> VBE_DISPI_INDEX_ID	equ	00h
  8734                              <1> VBE_DISPI_INDEX_XRES	equ	01h
  8735                              <1> VBE_DISPI_INDEX_YRES	equ	02h
  8736                              <1> VBE_DISPI_INDEX_BPP	equ	03h
  8737                              <1> VBE_DISPI_INDEX_ENABLE	equ	04h
  8738                              <1> VBE_DISPI_INDEX_BANK	equ	05h
  8739                              <1> VBE_DISPI_INDEX_VIRT_WIDTH equ	06h
  8740                              <1> VBE_DISPI_INDEX_VIRT_HEIGHT equ	07h
  8741                              <1> VBE_DISPI_INDEX_X_OFFSET equ	08h
  8742                              <1> VBE_DISPI_INDEX_Y_OFFSET equ	09h
  8743                              <1> VBE_DISPI_INDEX_VIDEO_MEMORY_64K equ 0Ah
  8744                              <1> VBE_DISPI_INDEX_DDC	equ	0Bh
  8745                              <1> 
  8746                              <1> VBE_DISPI_ID0		equ	0B0C0h
  8747                              <1> VBE_DISPI_ID1		equ	0B0C1h
  8748                              <1> VBE_DISPI_ID2		equ	0B0C2h
  8749                              <1> VBE_DISPI_ID3		equ	0B0C3h
  8750                              <1> VBE_DISPI_ID4		equ	0B0C4h
  8751                              <1> VBE_DISPI_ID5		equ	0B0C5h
  8752                              <1> 
  8753                              <1> VBE_DISPI_DISABLED	equ	00h
  8754                              <1> VBE_DISPI_ENABLED	equ	01h
  8755                              <1> VBE_DISPI_GETCAPS	equ	02h
  8756                              <1> VBE_DISPI_8BIT_DAC	equ	20h
  8757                              <1> VBE_DISPI_LFB_ENABLED	equ	40h
  8758                              <1> VBE_DISPI_NOCLEARMEM	equ	80h
  8759                              <1> 
  8760                              <1> VBE_DISPI_LFB_PHYSICAL_ADDRESS equ 0E0000000h
  8761                              <1> 
  8762                              <1> ; ***
  8763                              <1> 
  8764                              <1> ;// VBE Return Status Info
  8765                              <1> ;// AL
  8766                              <1> VBE_RETURN_STATUS_SUPPORTED	equ	4Fh
  8767                              <1> VBE_RETURN_STATUS_UNSUPPORTED	equ	00h
  8768                              <1> ;// AH
  8769                              <1> VBE_RETURN_STATUS_SUCCESSFULL	equ	00h
  8770                              <1> VBE_RETURN_STATUS_FAILED	equ	01h
  8771                              <1> VBE_RETURN_STATUS_NOT_SUPPORTED	equ	02h
  8772                              <1> VBE_RETURN_STATUS_INVALID	equ	03h
  8773                              <1> 
  8774                              <1> ;// VBE Mode Numbers
  8775                              <1> 
  8776                              <1> VBE_MODE_VESA_DEFINED		equ	0100h
  8777                              <1> VBE_MODE_REFRESH_RATE_USE_CRTC	equ	0800h
  8778                              <1> VBE_MODE_LINEAR_FRAME_BUFFER	equ	4000h
  8779                              <1> VBE_MODE_PRESERVE_DISPLAY_MEMORY equ	8000h
  8780                              <1> 
  8781                              <1> ;// Mode Attributes
  8782                              <1> 
  8783                              <1> VBE_MODE_ATTRIBUTE_SUPPORTED		   equ	0001h
  8784                              <1> VBE_MODE_ATTRIBUTE_EXTENDED_INFO_AVAILABLE equ	0002h
  8785                              <1> VBE_MODE_ATTRIBUTE_COLOR_MODE		   equ	0008h
  8786                              <1> VBE_MODE_ATTRIBUTE_GRAPHICS_MODE	   equ	0010h
  8787                              <1> VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE equ	0080h
  8788                              <1> VBE_MODE_ATTRIBUTE_DOUBLE_SCAN_MODE	   equ	0100h
  8789                              <1> VBE_MODE_ATTRIBUTE_INTERLACE_MODE	   equ	0200h
  8790                              <1> 
  8791                              <1> ;// Window attributes
  8792                              <1> 
  8793                              <1> VBE_WINDOW_ATTRIBUTE_RELOCATABLE equ	01h
  8794                              <1> VBE_WINDOW_ATTRIBUTE_READABLE	 equ	02h
  8795                              <1> VBE_WINDOW_ATTRIBUTE_WRITEABLE	 equ	04h
  8796                              <1> 
  8797                              <1> ;/* Video memory */
  8798                              <1> VGAMEM_GRAPH equ 0A000h
  8799                              <1> VGAMEM_CTEXT equ 0B800h
  8800                              <1> ;VGAMEM_MTEXT equ 0B000h
  8801                              <1> 
  8802                              <1> ;// Memory model
  8803                              <1> 
  8804                              <1> ;VBE_MEMORYMODEL_TEXT_MODE	equ	00h
  8805                              <1> ;VBE_MEMORYMODEL_CGA_GRAPHICS	equ	01h
  8806                              <1> ;VBE_MEMORYMODEL_PLANAR		equ	03h
  8807                              <1> VBE_MEMORYMODEL_PACKED_PIXEL	equ	04h
  8808                              <1> ;VBE_MEMORYMODEL_NON_CHAIN_4_256 equ	05h
  8809                              <1> VBE_MEMORYMODEL_DIRECT_COLOR	equ	06h
  8810                              <1> ;VBE_MEMORYMODEL_YUV		equ	07h
  8811                              <1> 
  8812                              <1> ;// DirectColorModeInfo
  8813                              <1> 
  8814                              <1> ;VBE_DIRECTCOLOR_COLOR_RAMP_PROGRAMMABLE equ 01h
  8815                              <1> VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE equ 02h
  8816                              <1> 
  8817                              <1> VBE_DISPI_TOTAL_VIDEO_MEMORY_MB	equ 16
  8818                              <1> 
  8819                              <1> ; 24/11/2020
  8820                              <1> ; vbe.c
  8821                              <1> 
  8822                              <1> %if 1
  8823                              <1> 
  8824                              <1> _vbe_biosfn_return_mode_info:
  8825                              <1> 	; 15/12/2020
  8826                              <1> 	; 12/12/2020
  8827                              <1> 	; Return VBE Mode Information	
  8828                              <1> 	; (call from 'sysvideo')
  8829                              <1> 	;
  8830                              <1> 	; Input:
  8831                              <1> 	;	cx = video (bios) mode
  8832                              <1> 	; Output:
  8833                              <1> 	;	cf = 0 -> (successful)
  8834                              <1> 	;	   MODE_INFO_LIST addr contains MODEINFO
  8835                              <1> 	;	cf = 1 -> error
  8836                              <1> 	;
  8837                              <1> 	; Modified registers: eax, edx, edi
  8838                              <1> 	;
  8839                              <1> 
  8840                              <1> 	; pushes for subroutine stack pops compatibility
  8841                              <1> 	
  8842                              <1> 	;push	ds  ; *
  8843                              <1> 	;push	es  ; **
  8844                              <1> 
  8845 00003890 55                  <1> 	push	ebp ; ***
  8846 00003891 56                  <1> 	push	esi ; **** 
  8847                              <1> 	
  8848 00003892 31FF                <1> 	xor	edi, edi  ; mov edi, 0
  8849                              <1> 
  8850 00003894 803D[86090000]03    <1> 	cmp	byte [vbe3], 3
  8851 0000389B 7221                <1> 	jb	short _vbe_rmi_1
  8852                              <1> 
  8853                              <1> 	;sub	edi, edi  ; 0 = kernel call (sign)
  8854                              <1> 	;	; no transfer to user's buffer
  8855                              <1> 	
  8856                              <1> 	; cx = Video mode (for 4F01h, with LFB flag)
  8857                              <1> 
  8858 0000389D 66B8014F            <1> 	mov	ax, 4F01h
  8859                              <1> 
  8860 000038A1 E826E0FFFF          <1> 	call	_vbe3_pmfn_return_mode_info
  8861                              <1> 
  8862 000038A6 6683F84F            <1> 	cmp	ax, 004Fh
  8863 000038AA 7533                <1> 	jne	short _vbe_rmi_2 ; fail
  8864                              <1> 
  8865                              <1> 	; 15/12/2020
  8866                              <1> 	; cx = vbe video mode
  8867 000038AC 80E501              <1> 	and	ch, 01h ; clear LFB flag
  8868 000038AF BEFE7B0900          <1> 	mov	esi, VBE3MODEINFOBLOCK - 2
  8869 000038B4 66890E              <1> 	mov	[esi], cx ; MODEINFO.mode
  8870 000038B7 E8A5000000          <1> 	call	set_lfbinfo_table
  8871 000038BC EB22                <1> 	jmp	short _vbe_rmi_3  ; cf = 0 
  8872                              <1> _vbe_rmi_1:
  8873 000038BE 803D[86090000]02    <1> 	cmp	byte [vbe3], 2
  8874 000038C5 7219                <1> 	jb	short _vbe_rmi_3 ; cf = 1
  8875 000038C7 A0[87090000]        <1> 	mov	al, [vbe2bios] ; 0C0h-0C5h for emu (*)
  8876 000038CC 3CC0                <1> 	cmp	al, 0C0h ; BOCHS/QEMU/VIRTUALBOX (*) ? 
  8877 000038CE 7210                <1> 	jb	short _vbe_rmi_3  ; cf = 1
  8878 000038D0 3CC5                <1> 	cmp	al, 0C5h ; (*)
  8879 000038D2 770B                <1> 	ja	short _vbe_rmi_2 ; unknown vbios !? 
  8880                              <1> 	
  8881                              <1> 	;xor	edi, edi  ; 0 = kernel call (sign)
  8882                              <1> 	;	; no transfer to user's buffer
  8883                              <1> 
  8884                              <1> 	;mov	ax, 4F01h
  8885                              <1> 
  8886                              <1> 	; cx = Video mode (for 4F01h, with LFB flag)
  8887                              <1> 
  8888 000038D4 E80A000000          <1> 	call	vbe_biosfn_return_mode_info
  8889 000038D9 6683F84F            <1> 	cmp	ax, 004Fh ; successful ?
  8890 000038DD 7401                <1> 	je	short _vbe_rmi_3  ; cf = 0
  8891                              <1> _vbe_rmi_2:
  8892 000038DF F9                  <1> 	stc
  8893                              <1> 	; cf = 1	
  8894                              <1> _vbe_rmi_3:
  8895 000038E0 5E                  <1> 	pop	esi ; ****
  8896 000038E1 5D                  <1> 	pop	ebp ; ***
  8897                              <1> 	
  8898                              <1> 	;pop	es  ; **
  8899                              <1> 	;pop	ss  ; *
  8900                              <1> 	
  8901 000038E2 C3                  <1> 	retn
  8902                              <1> 
  8903                              <1> 
  8904                              <1> ; * (TRDOS 386, INT 31h, VESA Video Bios functions) 
  8905                              <1> ; * ---------------------------------------------------------
  8906                              <1> ; * Function 01h - Return VBE Mode Information
  8907                              <1> ; * ---------------------------------------------------------
  8908                              <1> ; * Input:
  8909                              <1> ; *		AX = 4F01h
  8910                              <1> ; *		CX = Mode number
  8911                              <1> ; *    (ES:DI) EDI = Pointer to ModeInfoBlock structure	
  8912                              <1> ; * Output:
  8913                              <1> ; *		AX = VBE Return Status
  8914                              <1> ; * 
  8915                              <1> ; *----------------------------------------------------------
  8916                              <1> ; *
  8917                              <1> 
  8918                              <1> vbe_biosfn_return_mode_info:
  8919                              <1> 	; 03/08/2022 (TRDOS 386 v2.0.5)
  8920                              <1> 	; 15/12/2020 
  8921                              <1> 	; 14/12/2020
  8922                              <1> 	; 12/12/2020
  8923                              <1> 	; 11/12/2020 (TRDOS 386 v2.0.3)
  8924                              <1> 	;
  8925                              <1> 	; Input:
  8926                              <1> 	;	cx = video (bios) mode
  8927                              <1> 	;      edi = ModeInfoBlock buffer address
  8928                              <1> 	;	     (in user's memory space)
  8929                              <1> 	;      (ax = 4F01h)
  8930                              <1> 	; Output:
  8931                              <1> 	;	ax = 004Fh (successful)
  8932                              <1> 	;	ah > 0 -> error
  8933                              <1> 	;
  8934                              <1> 	; Modified registers: esi
  8935                              <1> 
  8936                              <1> 	;;push	ds  ; *
  8937                              <1> 	;;push	es  ; **
  8938                              <1> 	;;push	ebp ; ***
  8939                              <1> 	;;push	esi ; **** 
  8940                              <1> 
  8941 000038E3 F6C501              <1> 	test	ch, 1
  8942 000038E6 7505                <1> 	jnz	short vbe_rmi_1
  8943                              <1> 
  8944                              <1> 	; mode number < 100h
  8945                              <1> 	; CGA/VGA mode is not proper this VBE function 
  8946                              <1> 
  8947 000038E8 29C0                <1> 	sub	eax, eax
  8948                              <1> vbe_rmi_0:	
  8949                              <1> 	;mov	ax, 0100h  ; Function is not supported
  8950 000038EA B401                <1> 	mov	ah, 1
  8951 000038EC C3                  <1> 	retn
  8952                              <1> vbe_rmi_1:
  8953 000038ED 52                  <1> 	push	edx ; *****
  8954 000038EE 51                  <1> 	push	ecx ; ******
  8955 000038EF 53                  <1> 	push	ebx ; *******	
  8956 000038F0 57                  <1> 	push	edi ; ********
  8957                              <1> 	
  8958                              <1> 	; 14/12/2020
  8959 000038F1 89CB                <1> 	mov	ebx, ecx
  8960                              <1>  			
  8961                              <1> 	;xor	eax, eax
  8962 000038F3 80E7C1              <1> 	and	bh, 0C1h ; use bit 15, 14, 8 only (for bh)
  8963 000038F6 883D[2DA30100]      <1> 	mov	[vbe_mode_x], bh
  8964                              <1> 	;and	bx, 1FFh
  8965 000038FC 80E701              <1> 	and	bh, 1
  8966                              <1> 	;mov	bh, 1
  8967                              <1> 
  8968                              <1> 	; Alternative 2 (instead of 'Mode_info_find_mode')
  8969 000038FF E86A060000          <1> 	call	set_mode_info_list ; (alternative 2)
  8970                              <1> 
  8971                              <1> 	; eax = 0	
  8972                              <1> 
  8973                              <1> 	;mov	bx, [esi] ; mode
  8974                              <1> 
  8975                              <1> 	; Alternative 1 (instead of 'set_mode_info_list')
  8976                              <1> 	;call	mode_info_find_mode ; (alternative 1)
  8977                              <1> 
  8978 00003904 09F6                <1> 	or	esi, esi
  8979                              <1> 	; 14/12/2020
  8980 00003906 744C                <1> 	jz	short vbe_rmi_4	; VBE mode number is wrong
  8981                              <1> 				; or it is not supported
  8982                              <1> 
  8983                              <1> 	; 15/12/2020
  8984                              <1> 	;mov	bx, [esi] ; mode
  8985                              <1> 
  8986                              <1> 	; 12/12/2020
  8987                              <1> 	;call	set_lfbinfo_table
  8988                              <1> 
  8989 00003908 F605[2DA30100]40    <1> 	test	byte [vbe_mode_x], 40h ; LFB model ?
  8990 0000390F 7404                <1> 	jz	short vbe_rmi_2
  8991                              <1> 	
  8992 00003911 C6461C01            <1> 	mov	byte [esi+MODEINFO.NumberOfBanks], 1
  8993                              <1> vbe_rmi_2:
  8994                              <1> 	; (vbe.c, 02/01/2020, vruppert)
  8995                              <1> 	; 11/12/2020 (Erdogan Tan, video.s) 
  8996                              <1> 	; Bochs Graphics Adapter
  8997                              <1> 	; vendor_id: 1111h, device id: 1234h
  8998                              <1> 
  8999 00003915 E835070000          <1> 	call	pci_get_lfb_addr
  9000                              <1> 	;or	eax, eax
  9001 0000391A 7404                <1> 	jz	short vbe_rmi_3
  9002                              <1> 	; zf = 0, ax > 0 (high word of LFB address)
  9003                              <1> 	; set/change LFB address in MODEINFO structure
  9004 0000391C 6689462C            <1> 	mov	[esi+MODEINFO.PhysBasePtr+2], ax
  9005                              <1> 	; 12/12/2020
  9006                              <1> 	;mov	[edi+LFBINFO.LFB_addr+2], ax
  9007                              <1> vbe_rmi_3:
  9008                              <1> 	;test	byte [esi+MODEINFO.WinAAttributes], 1 
  9009                              <1> 	;		; VBE_WINDOW_ATTRIBUTE_RELOCATABLE = 1
  9010                              <1>         ;jz	short vbe_rmi_4
  9011                              <1> 	;; 11/12/2020
  9012                              <1> 	;; In fact, this is far call address in (Bochs/BGA) Video Bios
  9013                              <1> 	;; Direct user access to kernel subroutines is not possible 
  9014                              <1> 	;; in TRDOS 386. Also, TRDOS 386 kernel will support only LFB.
  9015                              <1> 	;; Bank select may be a seperate sysvideo function in future
  9016                              <1> 	;; (if it will be required).
  9017                              <1> 	;mov	dword [esi+MODEINFO.WinFuncPtr], dispi_set_bank_farcall
  9018                              <1> ;vbe_rmi_4:
  9019                              <1> 	; 12/12/2020
  9020 00003920 E83C000000          <1> 	call	set_lfbinfo_table
  9021                              <1> 
  9022                              <1> 	; 11/12/2020
  9023                              <1> 	; copy 68 bytes of MODE_INFO_LIST to user
  9024                              <1> 
  9025 00003925 8B3C24              <1> 	mov	edi, [esp]  ; user's buffer address
  9026                              <1> 	; 12/12/2020
  9027 00003928 09FF                <1> 	or	edi, edi ; 0 = kernel call 
  9028                              <1> 			 ; (call from '_vbe_biosfn_return_mode_info')
  9029 0000392A 7431                <1> 	jz	short vbe_rmi_6
  9030                              <1> 
  9031                              <1> 	; 15/12/2020
  9032                              <1> 	; prepare 256 bytes MODEINFO buffer at VBE3MODEINFOBLOCK
  9033                              <1> 	; and then, copy buffer conttent to user's buffer
  9034 0000392C 57                  <1> 	push	edi
  9035 0000392D BE[4CA30100]        <1> 	mov	esi, MODE_INFO_LIST + 2	; MODEINFO.ModeAttributes
  9036 00003932 BF007C0900          <1> 	mov	edi, VBE3MODEINFOBLOCK
  9037                              <1> 	;mov	ecx, 66/4  ; 66 bytes
  9038                              <1> 	; 03/08/2022
  9039 00003937 29C9                <1> 	sub	ecx, ecx
  9040 00003939 B110                <1> 	mov	cl, 66/4
  9041 0000393B F3A5                <1> 	rep	movsd
  9042 0000393D 31C0                <1> 	xor	eax, eax
  9043 0000393F B12F                <1> 	mov	cl, (256-68)/4 ; 188 bytes
  9044 00003941 F3AB                <1> 	rep	stosd
  9045 00003943 66AB                <1> 	stosw	; 2 bytes
  9046 00003945 5F                  <1> 	pop	edi
  9047 00003946 BE007C0900          <1> 	mov	esi, VBE3MODEINFOBLOCK
  9048                              <1> 	;mov	cx, 256 
  9049 0000394B FEC5                <1> 	inc	ch ; cx = 256
  9050 0000394D E83ED60000          <1> 	call	transfer_to_user_buffer
  9051 00003952 7309                <1> 	jnc	short vbe_rmi_5
  9052                              <1> vbe_rmi_4:
  9053                              <1> 	;mov	eax, 014Fh ; fail/error
  9054 00003954 31C0                <1> 	xor	eax, eax
  9055 00003956 B401                <1> 	mov	ah, 01h
  9056                              <1> 	;jmp	short vbe_rmi_6
  9057 00003958 E981000000          <1> 	jmp	vbe_sm_ret1 ; 11/12/2020
  9058                              <1> vbe_rmi_5:
  9059                              <1> 	; 256 bytes of MODEINFO have been transferred to user
  9060                              <1> 	;mov	eax, 4Fh ; succesfull
  9061                              <1> vbe_rmi_6: ; 12/12/2020
  9062 0000395D 31C0                <1> 	xor	eax, eax
  9063                              <1> ;vbe_rmi_6:
  9064 0000395F EB7D                <1> 	jmp	vbe_sm_ret1 ; 11/12/2020
  9065                              <1> 
  9066                              <1> 	;pop	edi ; ********
  9067                              <1> 	;pop	ebx ; *******
  9068                              <1> 	;pop	ecx ; ******
  9069                              <1> 	;pop	edx ; *****	
  9070                              <1> 	
  9071                              <1> 	;;pop	esi ; ****
  9072                              <1> 	;;pop	ebp ; ***
  9073                              <1> 	;;pop	es  ; **
  9074                              <1> 	;;pop	ds  ; * 
  9075                              <1> 
  9076                              <1> 	;retn
  9077                              <1> 
  9078                              <1> set_lfbinfo_table:
  9079                              <1> 	; 19/12/2020
  9080                              <1> 	; 11/12/2020
  9081                              <1> 	; Set/Fill LFBINFO structure/table
  9082                              <1> 	;
  9083                              <1> 	; Input:
  9084                              <1> 	;	esi = Mode info list address 
  9085                              <1> 	; Output:
  9086                              <1> 	;	LFB_Info address is filled with LFBINFO
  9087                              <1> 	;	edi = LFB_Info address
  9088                              <1> 	;
  9089                              <1> 	; Modified registers: eax, edx (=0), edi
  9090                              <1> 
  9091 00003961 BF[3AA30100]        <1> 	mov	edi, LFB_Info
  9092 00003966 8B462A              <1> 	mov	eax, [esi+MODEINFO.PhysBasePtr]
  9093 00003969 894702              <1> 	mov	[edi+LFBINFO.LFB_addr], eax ; LFB address
  9094                              <1> 	;mov	ax, [esi+MODEINFO.mode]
  9095 0000396C 668B06              <1> 	mov	ax, [esi]
  9096 0000396F 668907              <1> 	mov	[edi+LFBINFO.mode],ax
  9097 00003972 8A461B              <1> 	mov	al, [esi+MODEINFO.BitsPerPixel]
  9098 00003975 88470E              <1> 	mov	[edi+LFBINFO.bpp], al
  9099 00003978 29C0                <1> 	sub	eax, eax
  9100 0000397A 668B4614            <1> 	mov	ax, [esi+MODEINFO.XResolution]
  9101 0000397E 6689470A            <1> 	mov	[edi+LFBINFO.X_res], ax
  9102 00003982 89C2                <1> 	mov	edx, eax ; 19/12/2020
  9103 00003984 668B4616            <1> 	mov	ax, [esi+MODEINFO.YResolution]
  9104 00003988 6689470C            <1> 	mov	[edi+LFBINFO.Y_res], ax
  9105                              <1> 	; eax = Y_res ; screen height
  9106                              <1> 	; 19/12/2020	
  9107 0000398C F7E2                <1> 	mul	edx ; X_res*Y_res
  9108                              <1> 	; edx = 0
  9109 0000398E 8A570E              <1> 	mov	dl, [edi+LFBINFO.bpp]
  9110                              <1> 	; Note:
  9111                              <1> 	; Bits per pixel may be 8,16,24,32 for TRDOS 386 v2.
  9112                              <1> 	; (4 bits for pixel is not used for VESA modes here)
  9113 00003991 C0EA03              <1> 	shr	dl, 3 ; convert bits to byte
  9114 00003994 F7E2                <1> 	mul	edx
  9115                              <1> 	; eax = screen/page/buffer size in bytes
  9116 00003996 894706              <1> 	mov	[edi+LFBINFO.LFB_size], eax
  9117                              <1> 	; edx = 0
  9118                              <1> 	; clear reserved byte in LFBINFO structure/table
  9119 00003999 88570F              <1> 	mov	[edi+LFBINFO.reserved], dl ; not necessary
  9120 0000399C C3                  <1> 	retn
  9121                              <1> 
  9122                              <1> ; * (TRDOS 386, INT 31h, VESA Video Bios functions) 
  9123                              <1> ; * ---------------------------------------------------------
  9124                              <1> ; * Function 02h - Set VBE Mode
  9125                              <1> ; * ---------------------------------------------------------
  9126                              <1> ; * Input:
  9127                              <1> ; *		AX = 4F02h
  9128                              <1> ; *		BX = Desired Mode to set
  9129                              <1> ; * Output:
  9130                              <1> ; *		AX = VBE Return Status
  9131                              <1> ; * 
  9132                              <1> ; *----------------------------------------------------------
  9133                              <1> ; *
  9134                              <1> 
  9135                              <1> vbe_biosfn_set_mode:
  9136                              <1> 	; 07/03/2021
  9137                              <1> 	; 12/12/2020
  9138                              <1> 	; 11/12/2020 (LFBINFO table for VESA VBE modes)
  9139                              <1> 	; 27/11/2020
  9140                              <1> 	; 25/11/2020
  9141                              <1> 	; 23/11/2020 (TRDOS 386 v2.0.3)
  9142                              <1> 	; (ref: vbe.c, 02/01/2020, vruppert)
  9143                              <1> 	;
  9144                              <1> 	; Input:
  9145                              <1> 	;	bx = video (bios) mode
  9146                              <1> 	;	ax = 4F02h
  9147                              <1> 	; Output:
  9148                              <1> 	;	ax = 004Fh (successful)
  9149                              <1> 	;	ah > 0 -> error
  9150                              <1> 	;
  9151                              <1> 	; Modified registers: esi
  9152                              <1> 
  9153                              <1> 	; 27/11/2020
  9154                              <1> 
  9155                              <1> 	;;push	ds  ; *
  9156                              <1> 	;;push	es  ; **
  9157                              <1> 	;;push	ebp ; ***
  9158                              <1> 	;;push	esi ; **** 
  9159                              <1> 	
  9160                              <1> 	; 11/12/2020 			
  9161 0000399D 52                  <1> 	push	edx ; *****
  9162 0000399E 51                  <1> 	push	ecx ; ******
  9163 0000399F 53                  <1> 	push	ebx ; *******	
  9164 000039A0 57                  <1> 	push	edi ; ********
  9165                              <1> 
  9166                              <1> 	;xor	eax, eax
  9167 000039A1 80E7C1              <1> 	and	bh, 0C1h ; use bit 15, 14, 8 only (for bh)
  9168 000039A4 883D[2DA30100]      <1> 	mov	[vbe_mode_x], bh
  9169 000039AA 80E701              <1> 	and	bh, 1
  9170 000039AD 753C                <1> 	jnz	short vbe_sm_3  ; VESA VBE mode
  9171                              <1> 
  9172                              <1>  	;;test	bx, 4000h ; VBE_MODE_LINEAR_FRAME_BUFFER
  9173                              <1> 	;test	bh, 40h
  9174                              <1> 	;jz	short vbe_sm_0
  9175                              <1> 	;; lfb_flag
  9176                              <1> 	;mov	al, 40h	; VBE_DISPI_LFB_ENABLED
  9177                              <1> vbe_sm_0:
  9178                              <1> 	; 27/11/2020
  9179 000039AF B080                <1> 	mov	al, 80h
  9180                              <1> 	;test	bh, 80h ; VBE_MODE_PRESERVE_DISPLAY_MEMORY 	
  9181                              <1> 	;jnz	short vbe_sm_1 ; no_clear
  9182                              <1> 	;; clear
  9183                              <1> 	;sub	al, al ; 0
  9184 000039B1 8405[2DA30100]      <1> 	test	[vbe_mode_x], al ; 80h
  9185 000039B7 7402                <1> 	jz	short vbe_sm_1 ; clear display memory
  9186                              <1> 	; no_clear
  9187 000039B9 08C3                <1> 	or	bl, al ; VBE_MODE_PRESERVE_DISPLAY_MEMORY
  9188                              <1> vbe_sm_1:
  9189                              <1> 	; check non vesa mode
  9190                              <1> 	;;cmp	bx, 100h ; VBE_MODE_VESA_DEFINED
  9191                              <1> 	;;jna	short vbe_sm_2
  9192                              <1> 	;and	bh, 1
  9193                              <1> 	;jnz	short vbe_sm_3 
  9194                              <1> 
  9195                              <1> 	; BX <= 1FFh
  9196                              <1> 
  9197                              <1> 	; 27/11/2020
  9198                              <1> 	;or	bl, al	; al = 80h if no_clear option is set 
  9199                              <1> 	;		; al = 0 if no_clear option is not set 
  9200                              <1> 
  9201                              <1> 	; 25/11/2020
  9202                              <1> 	; VBE DISPI will be disabled in 'biosfn_set_video_mode'
  9203                              <1>  
  9204                              <1> 	;xor	al, al ; 0 ; VBE_DISPI_DISABLED
  9205                              <1> 	;call	dispi_set_enable
  9206                              <1> 
  9207                              <1> 	; call the vgabios in order to set the video mode
  9208                              <1> 	; this allows for going back to textmode with a VBE call
  9209                              <1> 	; (some applications expect that to work)
  9210                              <1> 
  9211                              <1> 	;and	bx, 0FFh
  9212                              <1> 	
  9213                              <1> 	; 27/11/2020
  9214                              <1> biosfn_set_video_mode:
  9215                              <1> 	; _call: call subroutine
  9216                              <1> 	; 26/11/2020 (TRDOS 386 v2.0.3)
  9217                              <1> 	; (ref: vgabios.c, 02/01/2020, vruppert)
  9218                              <1> 	; Input:
  9219                              <1> 	;	bl = VGA video (bios) mode
  9220                              <1> 	; Output:
  9221                              <1> 	;	cf = 1 -> error
  9222                              <1> 	;	cf = 0 -> ok
  9223                              <1> 	;
  9224                              <1> 	; Modified registers: esi
  9225                              <1> 
  9226                              <1> 	; 'dispi_set_enable(VBE_DISPI_DISABLED);'
  9227                              <1> 	
  9228                              <1> 	;mov	ax, 0 ; VBE_DISPI_DISABLED 
  9229 000039BB 31C0                <1> 	xor	eax, eax ; 0 
  9230 000039BD E89C040000          <1> 	call	dispi_set_enable
  9231                              <1> 	
  9232 000039C2 88D8                <1> 	mov	al, bl
  9233                              <1> 	;jmp	_set_mode ; (in 'biosfn_set_video_mode' sub)
  9234 000039C4 E87AE1FFFF          <1> 	call	_set_mode ; will return with cf=1 only if
  9235                              <1> 			; desired mode is not implemented
  9236                              <1> 	; _retn: return from subroutine
  9237 000039C9 721A                <1> 	jc	short vbe_sm_2 ; 25/11/2020
  9238                              <1> 
  9239                              <1> 	; 26/11/2020
  9240 000039CB 31C0                <1> 	xor	eax, eax 
  9241 000039CD A0[DE670000]        <1> 	mov	al, [CRT_MODE]
  9242                              <1> 	; 27/11/2020
  9243 000039D2 8A25[53890100]      <1> 	mov	ah, [noclearmem] ; 80h or 0
  9244                              <1> 	;and	ah 80h
  9245 000039D8 66A3[2EA30100]      <1> 	mov	[video_mode], ax ; bit 15 = no_clear flag
  9246                              <1> 				 ; bit 14 = 0 (not LFB model)
  9247                              <1> vbe_sm_ret1:
  9248                              <1> 	; 11/12/2020
  9249                              <1> 	; (vbe_rmi_4 and vbe_rmi_6 jump here)
  9250                              <1> 	; 27/11/2020
  9251 000039DE B04F                <1> 	mov	al, 4Fh ; Function call successful
  9252                              <1> 	; eax = 004Fh
  9253                              <1> vbe_sm_ret2:
  9254                              <1> 	; 11/12/2020
  9255 000039E0 5F                  <1> 	pop	edi ; ********
  9256 000039E1 5B                  <1> 	pop	ebx ; *******
  9257 000039E2 59                  <1> 	pop	ecx ; ******
  9258 000039E3 5A                  <1> 	pop	edx ; *****
  9259                              <1> 
  9260                              <1> 	;;pop	esi ; ****
  9261                              <1> 	;;pop	ebp ; ***
  9262                              <1> 	;;pop	es  ; **
  9263                              <1> 	;;pop	ds  ; * 
  9264                              <1> 
  9265 000039E4 C3                  <1> 	retn
  9266                              <1> 
  9267                              <1> vbe_sm_2:
  9268                              <1> 	;mov	ax, 0100h ; Function is not supported
  9269                              <1> 	; 27/11/2020
  9270 000039E5 31C0                <1> 	xor	eax, eax
  9271 000039E7 B401                <1> 	mov	ah, 01h
  9272                              <1> 	; eax = 0100h
  9273                              <1> 	;retn
  9274 000039E9 EBF5                <1> 	jmp	short vbe_sm_ret2
  9275                              <1> 
  9276                              <1> vbe_sm_3:
  9277                              <1> 	; 12/12/2020
  9278                              <1> 	; check current mode, if it is 03h
  9279                              <1> 	; save page contents and cursor positions
  9280 000039EB 803D[DE670000]03    <1> 	cmp	byte [CRT_MODE], 03h
  9281                              <1> 	;jne	short vbe_sm_0
  9282 000039F2 7505                <1> 	jne	short vbe_sm_4 ; 07/03/2021
  9283 000039F4 E8ECE3FFFF          <1> 	call	save_mode3_multiscreen
  9284                              <1> 	; set current mode to extended (SVGA) mode
  9285                              <1> 	;mov	byte [CRT_MODE], 0FFh ; VESA VBE mode
  9286                              <1> vbe_sm_4:
  9287                              <1> 	; 27/11/2020
  9288                              <1> 	; bx = mode (bit 0 to 8)
  9289                              <1> 
  9290                              <1> 	; 25/11/2020
  9291                              <1> 
  9292                              <1> 	; Alternative 2 (instead of 'Mode_info_find_mode')
  9293                              <1> 	;push	edi
  9294 000039F9 E870050000          <1> 	call	set_mode_info_list ; (alternative 2)
  9295                              <1> 	;pop	edi
  9296                              <1> 
  9297                              <1> 	;mov	bx, [esi] ; mode
  9298                              <1> 
  9299                              <1> 	; Alternative 1 (instead of 'set_mode_info_list')
  9300                              <1> 	;call	mode_info_find_mode ; (alternative 1)
  9301                              <1> 
  9302 000039FE 09F6                <1> 	or	esi, esi
  9303 00003A00 74E3                <1> 	jz	short vbe_sm_2 ; VBE mode number is wrong
  9304                              <1> 			       ; or it is not supported
  9305                              <1> 
  9306                              <1> 	; 11/12/2020
  9307 00003A02 668B1E              <1> 	mov	bx, [esi] ; mode
  9308                              <1> 
  9309                              <1> 	; 27/11/2020
  9310 00003A05 0A3D[2DA30100]      <1> 	or	bh, [vbe_mode_x]
  9311                              <1> 
  9312                              <1> 	; save VESA VBE mode
  9313 00003A0B 66891D[2EA30100]    <1> 	mov	[video_mode], bx
  9314                              <1> 		; 27/11/2020
  9315                              <1> 		; bit 0 to 8 = VESA VBE mode
  9316                              <1> 		; bit 9 to 13 = 0 (bit 0 to 13 = mode)
  9317                              <1> 		; bit 14 = Linear/Flat Frame Buffer flag
  9318                              <1> 		; bit 15 = 'memory not cleared
  9319                              <1> 		;	   at last mode set' flag
  9320                              <1> 
  9321                              <1> 	; first disable current mode
  9322                              <1> 	; (when switching between vesa modes)
  9323                              <1> 	; 'dispi_set_enable(VBE_DISPI_DISABLED);'
  9324                              <1> 
  9325                              <1> 	;mov	ax, VBE_DISPI_DISABLED ; 0
  9326 00003A12 29C0                <1> 	sub	eax, eax ; 0
  9327                              <1> 
  9328 00003A14 E845040000          <1> 	call	dispi_set_enable
  9329                              <1> 
  9330                              <1> 	; 11/12/2020
  9331 00003A19 8A461B              <1> 	mov	al, [esi+MODEINFO.BitsPerPixel]
  9332                              <1> 	; ah = 0
  9333                              <1> 
  9334                              <1> 	;cmp	byte [esi+MODEINFO.BitsPerPixel], 8
  9335 00003A1C 3C08                <1> 	cmp	al, 8
  9336 00003A1E 750B                <1> 	jne	short vbe_sm_5
  9337                              <1> 
  9338                              <1> 	; 11/12/2020
  9339                              <1> 	;push	edi
  9340 00003A20 50                  <1> 	push	eax
  9341                              <1> 	; 'load_dac_palette(3);'
  9342 00003A21 56                  <1> 	push	esi
  9343 00003A22 B403                <1> 	mov	ah, 3  ; palette3, 256 colors
  9344 00003A24 E8BBF1FFFF          <1> 	call	load_dac_palette
  9345 00003A29 5E                  <1> 	pop	esi
  9346                              <1> 	; 11/12/2020
  9347 00003A2A 58                  <1> 	pop	eax
  9348                              <1> 	;pop	edi
  9349                              <1> vbe_sm_5:	
  9350                              <1>   	;'dispi_set_bpp(cur_info->info.BitsPerPixel);'
  9351                              <1> 	; 11/12/2020 (al = bits per pixel, ah = 0)
  9352                              <1> 	;xor	ah, ah
  9353                              <1> 	;mov	al, [esi+MODEINFO.BitsPerPixel]
  9354 00003A2B E841040000          <1> 	call	dispi_set_bpp
  9355                              <1>         ;'dispi_set_xres(cur_info->info.XResolution);'
  9356 00003A30 668B4614            <1> 	mov	ax, [esi+MODEINFO.XResolution]
  9357 00003A34 E83E040000          <1> 	call	dispi_set_xres
  9358                              <1>         ;'dispi_set_yres(cur_info->info.YResolution);'
  9359 00003A39 668B4616            <1> 	mov	ax, [esi+MODEINFO.YResolution]
  9360 00003A3D E83B040000          <1> 	call	dispi_set_yres
  9361                              <1> 
  9362                              <1> 	;'dispi_set_bank(0);'
  9363                              <1> 	;xor	ax, ax
  9364 00003A42 31C0                <1> 	xor	eax, eax ; 0
  9365 00003A44 E83A040000          <1> 	call	dispi_set_bank
  9366                              <1>         ;'dispi_set_enable(VBE_DISPI_ENABLED|no_clear|lfb_flag);'
  9367                              <1> 	;mov	ax, di
  9368                              <1> 	; ah = 0 ; 27/11/2020
  9369 00003A49 A0[2DA30100]        <1> 	mov	al, [vbe_mode_x] ; restore VBE mode bit 14 & 15
  9370 00003A4E 0C01                <1> 	or	al, 1 ; VBE_DISPI_ENABLED
  9371 00003A50 E809040000          <1> 	call	dispi_set_enable
  9372                              <1> 
  9373                              <1>         ; 'vga_compat_setup();'
  9374 00003A55 E83E040000          <1> 	call	vga_compat_setup
  9375                              <1> 
  9376                              <1> 	; 11/12/2020
  9377 00003A5A E802FFFFFF          <1> 	call	set_lfbinfo_table
  9378                              <1> 
  9379                              <1> 	; 26/11/2020
  9380 00003A5F 31C0                <1> 	xor	eax, eax
  9381 00003A61 FEC8                <1> 	dec	al 
  9382 00003A63 A2[DE670000]        <1> 	mov	[CRT_MODE], al ; 0FFh = VESA VBE mode sign
  9383                              <1> 
  9384                              <1> 	; 27/11/2020
  9385 00003A68 E971FFFFFF          <1> 	jmp	vbe_sm_ret1 ; Function call successful
  9386                              <1> 	
  9387                              <1> 	; 27/11/2020
  9388                              <1> 	;mov	al, 4Fh
  9389                              <1> 	;	; eax = 004Fh = Function call successful
  9390                              <1> 	;jmp	short vbe_sm_ret2
  9391                              <1> 
  9392                              <1> ; * (TRDOS 386, INT 31h, VESA Video Bios functions)
  9393                              <1> ; * ---------------------------------------------------------
  9394                              <1> ; * Function 03h - Return Current VBE Mode
  9395                              <1> ; * ---------------------------------------------------------
  9396                              <1> ; * Input:
  9397                              <1> ; *		AX = 4F03h
  9398                              <1> ; * Output:
  9399                              <1> ; *		AX = VBE Return Status
  9400                              <1> ; *		BX = Current VBE Mode
  9401                              <1> ; * 
  9402                              <1> ; *----------------------------------------------------------
  9403                              <1> ; *
  9404                              <1> 
  9405                              <1> vbe_biosfn_return_current_mode:
  9406                              <1> 	; 11/12/2020
  9407                              <1> 	; 27/11/2020 (TRDOS 386 v2.0.3)
  9408                              <1> 	; (ref: vbe.c, 02/01/2020, vruppert)
  9409                              <1> 	;
  9410                              <1> 	; Input:
  9411                              <1> 	;	none
  9412                              <1> 	; Output:
  9413                              <1> 	;	ax = 004Fh (successful)
  9414                              <1> 	;	ah > 0 -> error
  9415                              <1> 	;	bx = current video (bios) mode (if ah = 0)
  9416                              <1> 	;
  9417                              <1> 	; Modified registers: eax, ebx
  9418                              <1> 
  9419                              <1> 	; 27/11/2020
  9420                              <1> 
  9421                              <1> 	;;push	ds  ; *
  9422                              <1> 	;;push	es  ; **
  9423                              <1> 	;;push	ebp ; ***
  9424                              <1> 	;;push	esi ; **** 
  9425                              <1> 	 			
  9426                              <1> 	;push	edx ; *****
  9427                              <1> 
  9428                              <1> 	; (vbe.c)
  9429                              <1> 	;call	dispi_get_enable
  9430                              <1> 	;	; ax = vbe display interface status
  9431                              <1> 	;and	al, 1 ; VBE_DISPI_ENABLED
  9432                              <1> 	;jnz	short vbe_gm_1  ; VBE graphics mode
  9433                              <1> 
  9434 00003A6D A0[DE670000]        <1> 	mov	al, [CRT_MODE] ; current cga/vga mode
  9435 00003A72 3CFF                <1> 	cmp	al, 0FFh ; VBE extension signature
  9436 00003A74 720E                <1> 	jb	short vbe_gm_1 ; get CGA/VGA mode
  9437                              <1> 
  9438                              <1> 	; get VBE mode
  9439                              <1> vbe_gm_0:
  9440 00003A76 66A1[2EA30100]      <1> 	mov	ax, [video_mode]
  9441                              <1> 		; BX bits:
  9442                              <1> 		; bit 0 to 8 = VESA VBE video mode
  9443                              <1> 		; bit 9 to 13 = 0 
  9444                              <1> 		; bit 14 = last mode set LFB option
  9445                              <1> 		;	   1 - linear/flat frame buffer
  9446                              <1> 		;	   0 - windowed frame buffer
  9447                              <1> 		; bit 15 = last mode set no_clear option
  9448                              <1> 		;	   0 - video memory cleared
  9449                              <1> 		;	   1 - video memory not cleared
  9450                              <1> 	
  9451                              <1> vbe_gm_return:
  9452                              <1> 	;pop	edx ; ******
  9453 00003A7C 0FB7D8              <1> 	movzx	ebx, ax
  9454                              <1> ;vbe_srs_retn:
  9455 00003A7F 31C0                <1> 	xor	eax, eax ; 0
  9456 00003A81 B04F                <1> 	mov	al, 4Fh ; ax = 004Fh (successful)
  9457 00003A83 C3                  <1> 	retn	
  9458                              <1> 
  9459                              <1> vbe_gm_1:
  9460                              <1> 	; legacy (old, standard) CGA/VGA bios video mode
  9461 00003A84 8A25[53890100]      <1> 	mov	ah, [noclearmem] ; 80h or 0
  9462                              <1> 		; BX bits: 
  9463                              <1> 		; bit 0 to 7 = video mode
  9464                              <1> 		; bit 8 to 13 = 0 
  9465                              <1> 		; bit 14 = 0 (not LFB mode) CGA/VGA
  9466                              <1> 		; bit 15 = 1 if [noclearmem] = 80h
  9467                              <1> 		;	   0 if [noclearmem] = 0
  9468 00003A8A EBF0                <1> 	jmp	short vbe_gm_return
  9469                              <1> 
  9470                              <1> ; * (TRDOS 386, INT 31h, VESA Video Bios functions) 
  9471                              <1> ; * ---------------------------------------------------------
  9472                              <1> ; * Function 04h - Save/Restore State
  9473                              <1> ; * ---------------------------------------------------------
  9474                              <1> ; * Input:
  9475                              <1> ; *		AX = 4F04h
  9476                              <1> ; *             DL = 00h Return Save/Restore State buff size
  9477                              <1> ; *                  01h Save State
  9478                              <1> ; *                  02h Restore State
  9479                              <1> ; *             CX = Requested states
  9480                              <1> ; *		     bit 0 - controller hardware state
  9481                              <1> ; *		     bit 1 - BIOS data state
  9482                              <1> ; *		     bit 2 - DAC state
  9483                              <1> ; *		     bit 3 - register state
  9484                              <1> ; *    (ES:BX) EBX = Pointer to buffer (if DL <> 00h)
  9485                              <1> ; * Output:
  9486                              <1> ; *		AX = VBE Return Status
  9487                              <1> ; *		BX = Number of 64-byte blocks 
  9488                              <1> ; *		     to hold the state buffer (if DL=00h)
  9489                              <1> ; * 
  9490                              <1> ; *----------------------------------------------------------
  9491                              <1> ; *
  9492                              <1> 
  9493                              <1> vbe_biosfn_save_restore_state:
  9494                              <1> 	; 23/01/2021
  9495                              <1> 	; 16/01/2021
  9496                              <1> 	; 14/01/2021
  9497                              <1> 	; 13/01/2021
  9498                              <1> 	; 12/01/2021
  9499                              <1> 	; 11/01/2021 (TRDOS 386 v2.0.3)
  9500                              <1> 	; (ref: vbe.c, 02/01/2020, vruppert)
  9501                              <1> 	;
  9502                              <1> 	; Input:
  9503                              <1> 	;	dl = sub function
  9504                              <1> 	;	cl = requested state
  9505                              <1> 	;      ebx = pointer to buffer (if dl<>00h) 
  9506                              <1> 	; Output:
  9507                              <1> 	;	ax = 004Fh (successful)
  9508                              <1> 	;	ah > 0 -> error
  9509                              <1> 	;	bx = Number of 64-byte blocks 
  9510                              <1> 	;	     to hold the state buffer (if DL=00h)
  9511                              <1> 
  9512                              <1> 	; Modified registers: eax, ebx, edi
  9513                              <1> 	
  9514                              <1> 	; 14/01/2021
  9515 00003A8C 09DB                <1> 	or	ebx, ebx ; user's buffer address
  9516 00003A8E 750A                <1> 	jnz	short _vbe_biosfn_save_restore_state
  9517                              <1> 
  9518 00003A90 20D2                <1> 	and	dl, dl
  9519 00003A92 7406                <1> 	jz	short _vbe_biosfn_save_restore_state
  9520                              <1> 
  9521                              <1> 	; function failed
  9522                              <1> 	;mov	eax, 0100h
  9523                              <1> 	;xor	eax, eax
  9524                              <1> 	;inc	ah  ; eax = 0100h
  9525                              <1> 	; 16/01/2021
  9526 00003A94 B84F010000          <1> 	mov	eax, 014Fh
  9527 00003A99 C3                  <1> 	retn
  9528                              <1> 
  9529                              <1> _vbe_biosfn_save_restore_state:
  9530                              <1> 	; 23/01/2021
  9531                              <1> 	; 14/01/2021
  9532                              <1> 	; ebx = 0 if the caller is kernel ('sysvideo')
  9533                              <1> 
  9534                              <1> 	; 13/01/2021
  9535 00003A9A 57                  <1> 	push	edi
  9536 00003A9B 52                  <1> 	push	edx
  9537 00003A9C 51                  <1> 	push	ecx
  9538                              <1> 
  9539                              <1> 	; 23/01/2021
  9540                              <1> 	; 12/01/2021
  9541 00003A9D 80FA02              <1> 	cmp	dl, 2
  9542 00003AA0 7757                <1> 	ja	short vbe_srs_7 ; 23/01/2021
  9543                              <1> 			; invalid sub function
  9544 00003AA2 83F90F              <1> 	cmp	ecx, 0Fh
  9545 00003AA5 7752                <1> 	ja	short vbe_srs_7 ; invalid !
  9546                              <1> 	
  9547 00003AA7 20D2                <1> 	and	dl, dl
  9548 00003AA9 7515                <1> 	jnz	short vbe_srs_4
  9549                              <1> 
  9550                              <1> 	; DL = 0
  9551                              <1> 	; Return Save/Restore State buffer size
  9552                              <1> 
  9553                              <1> 	;mov	ebx, ecx
  9554                              <1> 	;shl	bl, 1
  9555                              <1> 	;mov	bx, [ebx+vbestatebufsize]
  9556 00003AAB E881000000          <1> 	call	vbe_srs_gbs
  9557                              <1> 
  9558                              <1> ;	; 11/01/2021
  9559                              <1> ;	test	cl, 8
  9560                              <1> ;	jz	short vbe_srs_3
  9561                              <1> ;	; vbe_biosfn_read_video_state_size();
  9562                              <1> ;	; return 9 * 2;
  9563                              <1> ;	mov	bl, 18 ; register state size
  9564                              <1> ;vbe_srs_0:
  9565                              <1> ;	test	cl, 1
  9566                              <1> ;	jz	short vbe_srs_1
  9567                              <1> ;	; size += 0x46;
  9568                              <1> ;	add	bl, 70	; controller state size
  9569                              <1> ;vbe_srs_1:
  9570                              <1> ;	test	cl, 2
  9571                              <1> ;	jz	short vbe_srs_2
  9572                              <1> ;	; size += (5 + 8 + 5) * 2 + 6;
  9573                              <1> ;	;add	bl, 42 ; BIOS data state size ; Bochs/Plex86
  9574                              <1> ;	; 12/01/2021
  9575                              <1> ;	add	bl, 40 ; TRDOS 386 v2 VBIOS data state size
  9576                              <1> ;vbe_srs_2:
  9577                              <1> ;	test	cl, 4
  9578                              <1> ;	jz	short vbe_srs_3
  9579                              <1> ;	; size += 3 + 256 * 3 + 1;
  9580                              <1> ;	add	bx, 772 ; DAC state size
  9581                              <1> 
  9582                              <1> vbe_srs_3:
  9583 00003AB0 6683C33F            <1> 	add	bx, 63
  9584 00003AB4 66C1EB06            <1> 	shr	bx, 6 ; / 64
  9585                              <1> 
  9586                              <1> vbe_srs_retn:
  9587 00003AB8 31C0                <1> 	xor	eax, eax ; 0
  9588                              <1> vbe_srs_0:  ; 16/01/2021
  9589 00003ABA B04F                <1> 	mov	al, 4Fh ; ax = 004Fh (successful)
  9590                              <1> ;vbe_srs_0:
  9591                              <1> 	; 13/01/2021
  9592 00003ABC 59                  <1> 	pop	ecx
  9593 00003ABD 5A                  <1> 	pop	edx
  9594 00003ABE 5F                  <1> 	pop	edi	
  9595                              <1> 
  9596 00003ABF C3                  <1> 	retn
  9597                              <1> 
  9598                              <1> 	; 23/01/2021
  9599                              <1> ;vbe_srs_10:
  9600                              <1> 	;; 14/01/2021
  9601                              <1> 	; return to 'sysvideo'
  9602                              <1> 	;mov	ebx, ecx ; transfer count
  9603                              <1> 	;	; (byte count for saving current video state)
  9604                              <1> 	;jmp	short vbe_srs_retn 
  9605                              <1> 
  9606                              <1> vbe_srs_4:
  9607                              <1> 	; 23/01/2021
  9608 00003AC0 80E10F              <1> 	and	cl, 0Fh ; 8, 4, 2, 1
  9609 00003AC3 7434                <1> 	jz	short vbe_srs_7 ; cx = 0 -> invalid !
  9610                              <1> 
  9611 00003AC5 BF00760900          <1> 	mov	edi, VBE3SAVERESTOREBLOCK
  9612                              <1> 
  9613 00003ACA 80FA01              <1> 	cmp	dl, 1
  9614 00003ACD 7730                <1> 	ja	short vbe_srs_8
  9615                              <1> 
  9616                              <1> 	; save video state
  9617                              <1> 
  9618 00003ACF F6C107              <1> 	test	cl, 07h ; 4, 2, 1
  9619 00003AD2 740A                <1> 	jz	short vbe_srs_5  ; vbe dispi regs state
  9620                              <1> 
  9621 00003AD4 E884000000          <1> 	call	biosfn_save_video_state
  9622                              <1> 	; edi = current position
  9623                              <1> 	;	in VBE3SAVERESTOREBLOCK
  9624                              <1> 	; 	(VGA save_state offset)
  9625                              <1> 	; modified regs: edi, eax, edx, ch
  9626 00003AD9 F6C108              <1> 	test	cl, 8
  9627 00003ADC 7405                <1> 	jz	short vbe_srs_6
  9628                              <1> vbe_srs_5:
  9629 00003ADE E8AB010000          <1> 	call	vbe_biosfn_save_video_state
  9630                              <1> 	; edi = end position
  9631                              <1> 	;	in VBE3SAVERESTOREBLOCK
  9632                              <1> 	; 	(VGA save_state offset)
  9633                              <1> 	; modified regs: edi, eax, edx, ch
  9634                              <1> vbe_srs_6:
  9635                              <1> 	; 23/01/2021
  9636 00003AE3 21DB                <1> 	and	ebx, ebx 
  9637 00003AE5 74D1                <1> 	jz	short vbe_srs_retn ; the caller is kernel
  9638                              <1> 	
  9639 00003AE7 BE00760900          <1> 	mov	esi, VBE3SAVERESTOREBLOCK
  9640 00003AEC 29F7                <1> 	sub	edi, esi
  9641 00003AEE 89F9                <1> 	mov	ecx, edi ; transfer count in bytes
  9642                              <1> 
  9643                              <1> 	;; 14/01/2021
  9644                              <1> 	;and	ebx, ebx 
  9645                              <1> 	;jz	short vbe_srs_10 ; the caller is kernel
  9646                              <1> 
  9647 00003AF0 89DF                <1> 	mov	edi, ebx ; user's buffer address
  9648 00003AF2 E899D40000          <1> 	call	transfer_to_user_buffer
  9649 00003AF7 73BF                <1> 	jnc	short vbe_srs_retn
  9650                              <1> vbe_srs_7:
  9651                              <1> 	; // function failed
  9652                              <1> 	;mov	eax, 0100h
  9653 00003AF9 31C0                <1> 	xor	eax, eax
  9654 00003AFB FEC4                <1> 	inc	ah  ; eax = 0100h
  9655                              <1> 	; 16/01/2021
  9656                              <1> 	; ax = 0014Fh
  9657                              <1> 	;retn
  9658                              <1> 	; 13/01/2021
  9659 00003AFD EBBB                <1> 	jmp	short vbe_srs_0
  9660                              <1> vbe_srs_8:
  9661                              <1> 	;cmp	dl, 2
  9662                              <1> 	;jne	short vbe_srs_7
  9663                              <1> 	;		; invalid sub function
  9664                              <1> 
  9665                              <1> 	; 14/01/2021
  9666 00003AFF 09DB                <1> 	or	ebx, ebx ; user's buffer address
  9667                              <1> 	;jnz	short vbe_srs_11
  9668                              <1> 
  9669                              <1> 	; the caller is kernel ('sysvideo')
  9670                              <1> 	;jmp	short vbe_srs_12
  9671                              <1> 	; 23/01/2021
  9672 00003B01 7414                <1> 	jz	short vbe_srs_12 ; 'sysvideo' call
  9673                              <1> vbe_srs_11:
  9674 00003B03 89DE                <1> 	mov	esi, ebx ; user's buffer address
  9675                              <1> 	; 23/01/2021
  9676                              <1> 	;push	ebx
  9677                              <1> 	
  9678 00003B05 E827000000          <1> 	call	vbe_srs_gbs
  9679                              <1> 	
  9680                              <1> 	; restore video state
  9681                              <1> 
  9682                              <1> 	;mov	edi, VBE3SAVERESTOREBLOCK
  9683 00003B0A 51                  <1> 	push	ecx
  9684 00003B0B 89D9                <1> 	mov	ecx, ebx ; transfer count in bytes
  9685 00003B0D E8C8D40000          <1> 	call	transfer_from_user_buffer
  9686 00003B12 59                  <1> 	pop	ecx
  9687                              <1> 	; 23/01/2021
  9688                              <1> 	;pop	ebx
  9689 00003B13 89F3                <1> 	mov	ebx, esi
  9690 00003B15 72E2                <1> 	jc	short vbe_srs_7
  9691                              <1> 
  9692                              <1> vbe_srs_12:
  9693                              <1> 	;mov	esi, VBE3SAVERESTOREBLOCK
  9694 00003B17 89FE                <1> 	mov	esi, edi
  9695                              <1> 
  9696 00003B19 F6C107              <1> 	test	cl, 07h ; 4, 2, 1
  9697 00003B1C 740C                <1> 	jz	short vbe_srs_9	; vbe dispi regs state
  9698                              <1> 
  9699 00003B1E E8A2010000          <1> 	call	biosfn_restore_video_state
  9700 00003B23 72D4                <1> 	jc	short vbe_srs_7 ; invalid buffer content !
  9701                              <1> 	; esi = current position
  9702                              <1> 	;	in VBE3SAVERESTOREBLOCK
  9703                              <1> 	; 	(VGA save_state offset)
  9704                              <1> 	; modified regs: esi, eax, edx, ch
  9705 00003B25 F6C108              <1> 	test	cl, 8
  9706                              <1> 	;jz	short vbe_srs_10
  9707                              <1> 	; 23/01/2020
  9708 00003B28 EB8E                <1> 	jmp	short vbe_srs_retn
  9709                              <1> vbe_srs_9:
  9710 00003B2A E8F1020000          <1> 	call	vbe_biosfn_restore_video_state
  9711                              <1> 
  9712                              <1> 	; modified regs: esi, eax, edx, ch
  9713                              <1> 
  9714 00003B2F EB87                <1> 	jmp	short vbe_srs_retn
  9715                              <1> 
  9716                              <1> ;vbe_srs_10:
  9717                              <1> ;	; successful
  9718                              <1> ;	xor	eax, eax ; 0
  9719                              <1> ;	mov	al, 4Fh ; ax = 004Fh (successful)
  9720                              <1> ;	retn
  9721                              <1> 
  9722                              <1> vbe_srs_gbs:
  9723                              <1> 	; return buffer size according to flags
  9724 00003B31 89CB                <1> 	mov	ebx, ecx ; options/flags
  9725 00003B33 D0E3                <1> 	shl	bl, 1
  9726 00003B35 668B9B[3D3B0000]    <1> 	mov	bx, [ebx+vbestatebufsize]
  9727 00003B3C C3                  <1> 	retn
  9728                              <1> 
  9729                              <1> vbestatebufsize:
  9730                              <1> 	; ----------------------------------------
  9731                              <1> 	; CL =	0  1   2    3    4    5    6    7
  9732                              <1> 	; ----------------------------------------
  9733 00003B3D 0000460028006E0004- <1> 	dw	0, 70, 40, 110, 772, 842, 812, 882
  9733 00003B46 034A032C037203      <1>
  9734                              <1> 	; ----------------------------------------
  9735                              <1> 	; CL =	8   9   10  11   12   13   14   15
  9736                              <1> 	; ----------------------------------------
  9737 00003B4D 120058003A00800016- <1> 	dw	18, 88, 58, 128, 790, 860, 830, 900
  9737 00003B56 035C033E038403      <1>
  9738                              <1> 
  9739                              <1> ; 11/01/2021
  9740                              <1> VGAREG_ACTL_ADDRESS	equ 3C0h
  9741                              <1> VGAREG_ACTL_WRITE_DATA	equ 3C0h
  9742                              <1> VGAREG_ACTL_READ_DATA	equ 3C1h
  9743                              <1> 
  9744                              <1> VGAREG_INPUT_STATUS	equ 3C2h
  9745                              <1> VGAREG_WRITE_MISC_OUTPUT equ 3C2h
  9746                              <1> VGAREG_VIDEO_ENABLE	equ 3C3h
  9747                              <1> VGAREG_SEQU_ADDRESS	equ 3C4h
  9748                              <1> VGAREG_SEQU_DATA	equ 3C5h
  9749                              <1> 
  9750                              <1> VGAREG_PEL_MASK		equ 3C6h
  9751                              <1> VGAREG_DAC_STATE	equ 3C7h
  9752                              <1> VGAREG_DAC_READ_ADDRESS	equ 3C7h
  9753                              <1> VGAREG_DAC_WRITE_ADDRESS equ 3C8h
  9754                              <1> VGAREG_DAC_DATA		equ 3C9h
  9755                              <1> 
  9756                              <1> VGAREG_READ_FEATURE_CTL	equ 3CAh
  9757                              <1> VGAREG_READ_MISC_OUTPUT	equ 3CCh
  9758                              <1> 
  9759                              <1> VGAREG_GRDC_ADDRESS	equ 3CEh
  9760                              <1> VGAREG_GRDC_DATA	equ 3CFh
  9761                              <1> 
  9762                              <1> ;VGAREG_MDA_CRTC_ADDRESS equ 3B4h
  9763                              <1> ;VGAREG_MDA_CRTC_DATA	equ 3B5h
  9764                              <1> VGAREG_VGA_CRTC_ADDRESS	equ 3D4h
  9765                              <1> VGAREG_VGA_CRTC_DATA	equ 3D5h
  9766                              <1> 
  9767                              <1> ;VGAREG_MDA_WRITE_FEATURE_CTL equ 3BAh
  9768                              <1> VGAREG_VGA_WRITE_FEATURE_CTL equ 3DAh
  9769                              <1> VGAREG_ACTL_RESET	equ 3DAh
  9770                              <1> 
  9771                              <1> ;VGAREG_MDA_MODECTL	equ 3B8h
  9772                              <1> VGAREG_CGA_MODECTL	equ 3D8h
  9773                              <1> VGAREG_CGA_PALETTE	equ 3D9h
  9774                              <1> 
  9775                              <1> biosfn_save_video_state:
  9776                              <1> 	; 03/08/2022 (TRDOS 386 v2.0.5)
  9777                              <1> 	; 22/01/2021
  9778                              <1> 	; 12/01/2021
  9779                              <1> 	; 11/01/2021 (TRDOS 386 v2.0.3)
  9780                              <1> 	; (vgabios.c)
  9781                              <1> 
  9782                              <1> 	; modified registers: eax, edx, edi, ch
  9783                              <1> 
  9784                              <1> 	;mov	edi, VBE3SAVERESTOREBLOCK
  9785                              <1> 
  9786                              <1> 	; input: edi = state buffer address
  9787                              <1> 
  9788 00003B5D F6C101              <1> 	test	cl, 1
  9789 00003B60 0F8485000000        <1> 	jz	bfn_svs_4
  9790                              <1> 
  9791 00003B66 66BAC403            <1> 	mov	dx, VGAREG_SEQU_ADDRESS ; 3C7h
  9792 00003B6A EC                  <1> 	in	al, dx
  9793 00003B6B AA                  <1> 	stosb
  9794                              <1> 	;mov	dx, VGAREG_VGA_CRTC_ADDRESS ; 3D4h
  9795 00003B6C B2D4                <1> 	mov	dl, 0D4h
  9796 00003B6E EC                  <1> 	in	al, dx
  9797 00003B6F AA                  <1> 	stosb
  9798                              <1>   	;mov	dx, VGAREG_GRDC_ADDRESS ; 3CEh 
  9799 00003B70 B2CE                <1>         mov	dl, 0CEh
  9800 00003B72 EC                  <1> 	in	al, dx
  9801 00003B73 AA                  <1> 	stosb
  9802                              <1> 	;mov	dx, VGAREG_ACTL_RESET ; 3DAh
  9803 00003B74 B2DA                <1> 	mov	dl, 0DAh
  9804 00003B76 EC                  <1> 	in	al, dx
  9805                              <1> 	;mov	dx, VGAREG_ACTL_ADDRESS ; 3C0h
  9806 00003B77 B2C0                <1> 	mov	dl, 0C0h
  9807 00003B79 EC                  <1> 	in	al, dx
  9808 00003B7A AA                  <1> 	stosb
  9809 00003B7B 88C4                <1> 	mov	ah, al ; ar_index
  9810                              <1> 	;mov	dx, VGAREG_READ_FEATURE_CTL ; 3CAh
  9811 00003B7D B2CA                <1> 	mov	dl, 0CAh
  9812 00003B7F EC                  <1> 	in	al, dx
  9813 00003B80 AA                  <1> 	stosb
  9814                              <1> 	; (5 bytes are writen above)
  9815                              <1> 
  9816                              <1> 	; for(i=1;i<=4;i++){
  9817 00003B81 B001                <1> 	mov	al, 1
  9818                              <1> 	;;mov	dx, VGAREG_SEQU_ADDRESS ; 3C4h
  9819                              <1> 	;mov	dl, 0C4h
  9820 00003B83 B504                <1> 	mov	ch, 4
  9821                              <1> bfn_svs_0:
  9822                              <1> 	; outb(VGAREG_SEQU_ADDRESS, i);
  9823                              <1> 	;mov	dx, VGAREG_SEQU_ADDRESS ; 3C4h
  9824 00003B85 B2C4                <1> 	mov	dl, 0C4h
  9825 00003B87 EE                  <1> 	out	dx, al
  9826                              <1> 	;mov	dx, VGAREG_SEQU_DATA  ; 3C5h
  9827 00003B88 FEC2                <1> 	inc	dl  ; dx = 3C5h
  9828                              <1> 	; inb(VGAREG_SEQU_DATA)
  9829 00003B8A 50                  <1> 	push	eax
  9830 00003B8B EC                  <1> 	in	al, dx
  9831 00003B8C AA                  <1> 	stosb	; (4 bytes in loop)
  9832 00003B8D 58                  <1> 	pop	eax
  9833                              <1> 	;mov	dx, VGAREG_SEQU_ADDRESS ; 3C4h
  9834                              <1> 	;dec	dl	
  9835 00003B8E FEC0                <1> 	inc	al  ; i++
  9836 00003B90 FECD                <1> 	dec	ch
  9837 00003B92 75F1                <1> 	jnz	short bfn_svs_0
  9838                              <1> 
  9839                              <1> 	; outb(VGAREG_SEQU_ADDRESS, 0);
  9840 00003B94 28C0                <1> 	sub	al, al ; 0
  9841 00003B96 EE                  <1> 	out	dx, al
  9842                              <1> 	; inb(VGAREG_SEQU_DATA)
  9843                              <1> 	;mov	dx, VGAREG_SEQU_DATA ; 3C5h
  9844 00003B97 FEC2                <1> 	inc	dl  ; dx = 3C5h
  9845 00003B99 EC                  <1> 	in	al, dx
  9846 00003B9A AA                  <1> 	stosb	; (+1 byte)
  9847                              <1> 
  9848                              <1>         ; for(i=0;i<=0x18;i++) {
  9849 00003B9B 28C0                <1> 	sub	al, al ; 0
  9850                              <1> 	;;mov	dx, VGAREG_VGA_CRTC_ADDRESS ; 3D4h
  9851                              <1> 	;mov	dl, 0D4h
  9852 00003B9D B519                <1> 	mov	ch, 25
  9853                              <1> bfn_svs_1:
  9854                              <1>         ; outb(crtc_addr,i);
  9855                              <1> 	;mov	dx, VGAREG_VGA_CRTC_ADDRESS ; 3D4h
  9856 00003B9F B2D4                <1> 	mov	dl, 0D4h
  9857 00003BA1 EE                  <1> 	out	dx, al
  9858                              <1> 	;mov	dx, VGAREG_VGA_CRTC_DATA ; 3D5h
  9859 00003BA2 FEC2                <1> 	inc	dl  ; dx = 3D5h
  9860                              <1> 	; inb(crtc_addr+1)
  9861 00003BA4 50                  <1> 	push	eax
  9862 00003BA5 EC                  <1> 	in	al, dx
  9863 00003BA6 AA                  <1> 	stosb	; (25 bytes in loop)
  9864 00003BA7 58                  <1> 	pop	eax
  9865                              <1> 	;mov	dx, VGAREG_VGA_CRTC_ADDRESS ; 3D4h
  9866                              <1> 	;dec	dl	
  9867 00003BA8 FEC0                <1> 	inc	al  ; i++
  9868 00003BAA FECD                <1> 	dec	ch
  9869 00003BAC 75F1                <1> 	jnz	short bfn_svs_1
  9870                              <1> 
  9871 00003BAE 80E420              <1> 	and	ah, 20h  ; (ar_index & 0x20)
  9872                              <1>         ; for(i=0;i<=0x13;i++) {
  9873 00003BB1 28C0                <1> 	sub	al, al ; 0
  9874 00003BB3 B514                <1> 	mov	ch, 20
  9875                              <1> bfn_svs_2:
  9876                              <1> 	; inb(VGAREG_ACTL_RESET);
  9877                              <1> 	;mov	dx, VGAREG_ACTL_RESET ; 3DAh
  9878 00003BB5 B2DA                <1> 	mov	dl, 0DAh
  9879 00003BB7 50                  <1> 	push	eax
  9880 00003BB8 EC                  <1> 	in	al, dx
  9881 00003BB9 8A0424              <1> 	mov	al, [esp]
  9882                              <1>  	; outb(VGAREG_ACTL_ADDRESS, i | (ar_index & 0x20));
  9883 00003BBC 08E0                <1> 	or	al, ah
  9884                              <1> 	;mov	dx, VGAREG_ACTL_ADDRESS ; 3C0h
  9885 00003BBE B2C0                <1> 	mov	dl, 0C0h
  9886 00003BC0 EE                  <1> 	out	dx, al
  9887                              <1> 	;mov	dx, VGAREG_ACTL_READ_DATA ; 3C1h
  9888                              <1> 	;mov	dl, 0C1h
  9889 00003BC1 FEC2                <1> 	inc	dl
  9890 00003BC3 EC                  <1> 	in	al, dx
  9891 00003BC4 AA                  <1> 	stosb	; (20 bytes in loop)
  9892 00003BC5 58                  <1> 	pop	eax
  9893 00003BC6 FEC0                <1> 	inc	al  ; i++
  9894 00003BC8 FECD                <1> 	dec	ch
  9895 00003BCA 75E9                <1> 	jnz	short bfn_svs_2
  9896                              <1> 
  9897                              <1> 	; inb(VGAREG_ACTL_RESET);
  9898                              <1> 	;mov	dx, VGAREG_ACTL_RESET ; 3DAh
  9899 00003BCC B2DA                <1> 	mov	dl, 0DAh
  9900 00003BCE EC                  <1> 	in	al, dx
  9901                              <1> 
  9902                              <1>         ; for(i=0;i<=8;i++) {
  9903 00003BCF 28C0                <1> 	sub	al, al ; 0
  9904                              <1> 	;;mov	dx, VGAREG_GRDC_ADDRESS ; 3CEh
  9905                              <1> 	;mov	dl, 0CEh
  9906 00003BD1 B509                <1> 	mov	ch, 9
  9907                              <1> bfn_svs_3:
  9908                              <1> 	; outb(VGAREG_GRDC_ADDRESS,i)
  9909                              <1> 	;mov	dx, VGAREG_GRDC_ADDRESS ; 3CEh
  9910 00003BD3 B2CE                <1> 	mov	dl, 0CEh
  9911 00003BD5 EE                  <1> 	out	dx, al
  9912                              <1> 	; inb(VGAREG_ACTL_READ_DATA)
  9913 00003BD6 50                  <1> 	push	eax
  9914                              <1> 	;mov	dx, VGAREG_GRDC_DATA ; 3CFh
  9915                              <1> 	;mov	dl, 0CFh
  9916 00003BD7 FEC2                <1> 	inc	dl
  9917 00003BD9 EC                  <1> 	in	al, dx
  9918 00003BDA AA                  <1> 	stosb	; (9 bytes in loop)
  9919 00003BDB 58                  <1> 	pop	eax
  9920                              <1> 	;dec	dl
  9921 00003BDC FEC0                <1> 	inc	al  ; i++
  9922 00003BDE FECD                <1> 	dec	ch
  9923 00003BE0 75F1                <1> 	jnz	short bfn_svs_3
  9924                              <1> 
  9925                              <1> 	; write_word(ES, BX, crtc_addr); BX+= 2;
  9926                              <1> 	; (offset 64)
  9927 00003BE2 66B8D403            <1> 	mov	ax, 3D4h ; VGAREG_VGA_CRTC_ADDRESS
  9928 00003BE6 66AB                <1> 	stosw	; (2 bytes (1 word))
  9929                              <1> 
  9930                              <1>         ; /* XXX: read plane latches */
  9931 00003BE8 31C0                <1> 	xor	eax, eax  ; 0
  9932 00003BEA AB                  <1>        	stosd	; (4 bytes)
  9933                              <1> 
  9934                              <1> 	; (total 70 bytes are written above as controller hardware state)
  9935                              <1> 
  9936                              <1> bfn_svs_4:		
  9937                              <1> 	; 12/01/2021 (TRDOS 386 v2.0.3)
  9938 00003BEB F6C102              <1> 	test	cl, 2
  9939 00003BEE 7476                <1> 	jz	short bfn_svs_6
  9940                              <1> 
  9941                              <1> 	; VIDEO BIOS DATA
  9942                              <1> 	; !!! this data is valid for TRDOS 386 v2 kernel only !!!
  9943                              <1> 	; (this is not same with BOCHS/PLEX86 video bios, BIOS data)  
  9944                              <1>   
  9945                              <1>     	; if (CX & 2) {
  9946                              <1>         ;write_byte(ES, BX, read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE)); BX++;
  9947                              <1>         ;write_word(ES, BX, read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS)); BX += 2;
  9948                              <1>         ;write_word(ES, BX, read_word(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE)); BX += 2;
  9949                              <1>         ;write_word(ES, BX, read_word(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS)); BX += 2;
  9950                              <1>         ;write_byte(ES, BX, read_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS)); BX++;
  9951                              <1>         ;write_word(ES, BX, read_word(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT)); BX += 2;
  9952                              <1>         ;write_byte(ES, BX, read_byte(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL)); BX++;
  9953                              <1>         ;write_byte(ES, BX, read_byte(BIOSMEM_SEG,BIOSMEM_SWITCHES)); BX++;
  9954                              <1>         ;write_byte(ES, BX, read_byte(BIOSMEM_SEG,BIOSMEM_MODESET_CTL)); BX++;
  9955                              <1>         ;write_word(ES, BX, read_word(BIOSMEM_SEG,BIOSMEM_CURSOR_TYPE)); BX += 2;
  9956                              <1>         ;for(i=0;i<8;i++) {
  9957                              <1>         ;   write_word(ES, BX, read_word(BIOSMEM_SEG, BIOSMEM_CURSOR_POS+2*i));
  9958                              <1>         ;   BX += 2;
  9959                              <1>         ;}
  9960                              <1>         ;write_word(ES, BX, read_word(BIOSMEM_SEG,BIOSMEM_CURRENT_START)); BX += 2;
  9961                              <1>         ;write_byte(ES, BX, read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_PAGE)); BX++;
  9962                              <1>         ;/* current font */
  9963                              <1>         ;write_word(ES, BX, read_word(0, 0x1f * 4)); BX += 2;
  9964                              <1>         ;write_word(ES, BX, read_word(0, 0x1f * 4 + 2)); BX += 2;
  9965                              <1>         ;write_word(ES, BX, read_word(0, 0x43 * 4)); BX += 2;
  9966                              <1>         ;write_word(ES, BX, read_word(0, 0x43 * 4 + 2)); BX += 2;
  9967                              <1> 
  9968                              <1> 	; !!! save TRDOS 386 v2 kernel spesific video bios data !!!
  9969                              <1> 	; (which is/are used by 'SET_MODE' function and/or it's sub functions)
  9970                              <1> 
  9971 00003BF0 66B8D403            <1> 	mov	ax, 3D4h ; CRTC_ADDR, always 3D4h (color VGA) for TRDOS 386 v2
  9972 00003BF4 66AB                <1> 	stosw
  9973 00003BF6 A0[DE670000]        <1> 	mov	al, [CRT_MODE] ; Current video mode (0FFh for VESA VBE modes) 
  9974 00003BFB AA                  <1> 	stosb
  9975 00003BFC A0[DF670000]        <1> 	mov	al, [CRT_MODE_SET] ; 29h for mode 03h ; TRDOS 386 feature only !
  9976 00003C01 AA                  <1> 	stosb	
  9977 00003C02 66A1[2EA30100]      <1>  	mov	ax, [video_mode] ; Current VESA VBE (SVGA, extended VGA) mode 
  9978 00003C08 66AB                <1> 	stosw			 ; (valid if [CRT_MODE] = 0FFh)	
  9979 00003C0A 66A1[54890100]      <1> 	mov	ax, [CRT_LEN] ; page size (in bytes)
  9980 00003C10 66AB                <1> 	stosw
  9981 00003C12 66A1[DC7C0100]      <1> 	mov	ax, [CRT_START] ; video page start offset
  9982 00003C18 66AB                <1>  	stosw
  9983 00003C1A A0[E0670000]        <1> 	mov	al, [CRT_COLS] ; nbcols, characters per row	
  9984 00003C1F AA                  <1> 	stosb
  9985 00003C20 A0[E6670000]        <1> 	mov	al, [VGA_ROWS] ; nbrows, (character) rows per page (not rows-1)
  9986 00003C25 AA                  <1> 	stosb
  9987 00003C26 A0[E2670000]        <1> 	mov	al, [CHAR_HEIGHT] ; character font height (8 or 16 or 14)
  9988 00003C2B AA                  <1> 	stosb
  9989 00003C2C A0[E3670000]        <1> 	mov	al, [VGA_VIDEO_CTL] ; ROM BIOS DATA AREA Offset 87h
  9990 00003C31 AA                  <1> 	stosb
  9991 00003C32 A0[E4670000]        <1> 	mov	al, [VGA_SWITCHES] ; feature bit switches
  9992 00003C37 AA                  <1> 	stosb
  9993 00003C38 A0[E5670000]        <1> 	mov	al, [VGA_MODESET_CTL] ; basic mode set options
  9994 00003C3D AA                  <1> 	stosb
  9995                              <1> 	; followings are only used by TRDOS 386 v2 (IBM PC/AT ROMBIOS) code 
  9996                              <1> 	; (bochs/plex86 does not use and return those)
  9997 00003C3E A0[E1670000]        <1> 	mov	al, [CRT_PALETTE] ; current color palette ; TRDOS 386 feature only !
  9998 00003C43 AA                  <1> 	stosb
  9999 00003C44 A0[EE7C0100]        <1> 	mov	al, [ACTIVE_PAGE] ; current video page 
 10000 00003C49 AA                  <1> 	stosb
 10001 00003C4A 66A1[F7670000]      <1> 	mov	ax, [CURSOR_MODE] ; cursor type
 10002 00003C50 66AB                <1> 	stosw
 10003                              <1> 	;mov	eax, [CURSOR_POSN] ; cursor position for video page 0 and 1 
 10004                              <1> 	;stosd
 10005                              <1> 	;mov	eax, [CURSOR_POSN+4] ; cursor position for video page 2 and 3 
 10006                              <1> 	;stosd
 10007                              <1> 	;mov	eax, [CURSOR_POSN+8] ; cursor position for video page 4 and 5 
 10008                              <1> 	;stosd
 10009                              <1> 	;mov	eax, [CURSOR_POSN+12] ; cursor position for video page 6 and 7 
 10010                              <1> 	;stosd
 10011 00003C52 56                  <1> 	push	esi
 10012 00003C53 B504                <1> 	mov	ch, 4
 10013 00003C55 BE[DE7C0100]        <1> 	mov	esi, CURSOR_POSN
 10014                              <1> bfn_svs_5:
 10015 00003C5A A5                  <1> 	movsd
 10016 00003C5B FECD                <1> 	dec	ch
 10017 00003C5D 75FB                <1> 	jnz	short bfn_svs_5
 10018 00003C5F 5E                  <1> 	pop	esi
 10019                              <1> 	; (font addr) protected mode address in kernel's/system memory space 
 10020                              <1> 	; (not accessable/meaningful address value by user)
 10021 00003C60 A1[66890100]        <1> 	mov	eax, [VGA_INT43H] ; VGA current (default) font address
 10022 00003C65 AB                  <1> 	stosd
 10023                              <1> 	
 10024                              <1> 	; (total 40 bytes are written above as BIOS data state)
 10025                              <1> 
 10026                              <1> bfn_svs_6:
 10027                              <1> 	; 12/01/2021
 10028 00003C66 F6C104              <1> 	test	cl, 4
 10029 00003C69 7422                <1> 	jz	short bfn_svs_8
 10030                              <1> 
 10031                              <1>   	;/* XXX: check this */
 10032                              <1> 		; /* read/write mode dac */
 10033                              <1>         ;write_byte(ES, BX, inb(VGAREG_DAC_STATE)); BX++;
 10034                              <1> 	;	; /* pix address */
 10035                              <1>         ;write_byte(ES, BX, inb(VGAREG_DAC_WRITE_ADDRESS)); BX++;
 10036                              <1>         ;write_byte(ES, BX, inb(VGAREG_PEL_MASK)); BX++;
 10037                              <1>         ;// Set the whole dac always, from 0
 10038                              <1>         ;outb(VGAREG_DAC_WRITE_ADDRESS,0x00);
 10039                              <1>         ;for(i=0;i<256*3;i++) {
 10040                              <1>         ;   write_byte(ES, BX, inb(VGAREG_DAC_DATA)); BX++;
 10041                              <1>         ;}
 10042                              <1>         ;write_byte(ES, BX, 0); BX++; /* color select register */
 10043                              <1> 
 10044                              <1> 	; /* read/write mode dac */
 10045 00003C6B 66BAC703            <1>     	mov	dx, 3C7h ; VGAREG_DAC_STATE
 10046 00003C6F EC                  <1> 	in	al, dx
 10047 00003C70 AA                  <1> 	stosb
 10048                              <1> 	; /* pix address */
 10049                              <1>     	;mov	dx, VGAREG_DAC_WRITE_ADDRESS ; 3C8h
 10050                              <1> 	;mov	dl, 0C8h
 10051 00003C71 FEC2                <1> 	inc	dl
 10052 00003C73 EC                  <1> 	in	al, dx
 10053 00003C74 AA                  <1> 	stosb
 10054                              <1>     	;mov	dx, VGAREG_PEL_MASK  ; 3C6h
 10055 00003C75 B2C6                <1> 	mov	dl, 0C6h
 10056 00003C77 EC                  <1> 	in	al, dx
 10057 00003C78 AA                  <1> 	stosb
 10058                              <1> 	;// Set the whole dac always, from 0
 10059 00003C79 30C0                <1> 	xor	al, al ; 0
 10060                              <1> 	;mov	dx, VGAREG_DAC_WRITE_ADDRESS ; 3C8h
 10061 00003C7B B2C8                <1> 	mov	dl, 0C8h
 10062 00003C7D EE                  <1> 	out	dx, al
 10063                              <1> 
 10064 00003C7E 51                  <1> 	push	ecx ; 22/01/2021
 10065                              <1> 	;for(i=0;i<256*3;i++) {
 10066                              <1> 	;mov	ecx, 256*3 ; 768 bytes
 10067                              <1> 	; 03/08/2022
 10068 00003C7F 29C9                <1> 	sub	ecx, ecx
 10069 00003C81 B503                <1> 	mov	ch, 3
 10070                              <1> 	; ecx = 300h = 768
 10071                              <1> 	;mov	dx, VGAREG_DAC_DATA ; 3C9h
 10072                              <1> 	;mov	dl, 0C9h
 10073 00003C83 FEC2                <1> 	inc	dl ; dx = 3C9h
 10074                              <1> bfn_svs_7:
 10075 00003C85 EC                  <1> 	in	al, dx
 10076 00003C86 AA                  <1> 	stosb
 10077 00003C87 E2FC                <1> 	loop	bfn_svs_7
 10078 00003C89 59                  <1> 	pop	ecx ; 22/01/2021
 10079                              <1> 
 10080                              <1> 	; /* color select register */
 10081 00003C8A 28C0                <1> 	sub	al, al ; 0
 10082 00003C8C AA                  <1> 	stosb
 10083                              <1> 
 10084                              <1> 	; (total 772 bytes are written above as DAC state)
 10085                              <1> bfn_svs_8:
 10086 00003C8D C3                  <1> 	retn
 10087                              <1> 
 10088                              <1> vbe_biosfn_save_video_state:
 10089                              <1> 	; 23/01/2021
 10090                              <1> 	; 13/01/2021
 10091                              <1> 	; 12/01/2021 (TRDOS 386 v2.0.3)
 10092                              <1> 	; (vbe.c)
 10093                              <1> 
 10094                              <1> 	; modified registers: eax, edx, edi, ch
 10095                              <1> 	
 10096                              <1> 	; input: edi = state buffer address
 10097                              <1> 	; output: 
 10098                              <1> 	;	 VBE DISPI register contents will be saved
 10099                              <1> 	;	 (18 bytes, 9 words)
 10100                              <1> 
 10101                              <1> 	; outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
 10102                              <1> 	; enable = inw(VBE_DISPI_IOPORT_DATA);
 10103                              <1>   	; write_word(ES, BX, enable);
 10104                              <1>  	; BX += 2;
 10105                              <1> 	; if (!(enable & VBE_DISPI_ENABLED)) 
 10106                              <1> 	;	return;
 10107                              <1> 	; for(i = VBE_DISPI_INDEX_XRES;
 10108                              <1> 	;		 i <= VBE_DISPI_INDEX_Y_OFFSET; i++) {
 10109                              <1> 	;    if (i != VBE_DISPI_INDEX_ENABLE) {
 10110                              <1> 	;        outw(VBE_DISPI_IOPORT_INDEX, i);
 10111                              <1> 	;        write_word(ES, BX, inw(VBE_DISPI_IOPORT_DATA));
 10112                              <1>         ;    BX += 2;
 10113                              <1> 	;        }
 10114                              <1> 	; }
 10115                              <1> 
 10116 00003C8E 66BACE01            <1> 	mov	dx, 01CEh ; VBE_DISPI_IOPORT_INDEX
 10117                              <1> 	;mov	eax, 04h  ; VBE_DISPI_INDEX_ENABLE
 10118                              <1> 	 ;03/08/2022
 10119 00003C92 66EF                <1> 	out	dx, ax
 10120                              <1> 	;mov	dx, 01CFh ; VBE_DISPI_IOPORT_DATA	
 10121 00003C94 FEC2                <1> 	inc	dl
 10122 00003C96 66ED                <1> 	in	ax, dx ; enable (status)
 10123 00003C98 66AB                <1> 	stosw 
 10124 00003C9A 6683E001            <1> 	and	ax, 1 ; VBE_DISPI_ENABLED
 10125 00003C9E 7505                <1> 	jnz	short vbe_bfn_svs_0
 10126                              <1> 	; 23/01/2021
 10127                              <1> 	; ax = 0
 10128                              <1> 	; VBE_DISPI_DISABLED
 10129                              <1> 	; 13/01/2021
 10130                              <1> 	; clear remain 8 bytes 
 10131                              <1> 	;xor	eax, eax
 10132 00003CA0 AB                  <1> 	stosd	; 2
 10133 00003CA1 AB                  <1> 	stosd	; 2
 10134 00003CA2 AB                  <1> 	stosd	; 2
 10135 00003CA3 AB                  <1> 	stosd	; 2
 10136 00003CA4 C3                  <1> 	retn
 10137                              <1> vbe_bfn_svs_0:
 10138                              <1> 	; VBE_DISPI_ENABLED
 10139                              <1> 
 10140                              <1> 	;sub	eax, eax
 10141 00003CA5 28C0                <1> 	sub	al, al ; eax = 0
 10142                              <1> 	
 10143                              <1> 	; from VBE_DISPI_INDEX_XRES
 10144                              <1> 	;   to VBE_DISPI_INDEX_BPP	
 10145                              <1> 
 10146 00003CA7 B503                <1>  	mov	ch, 3
 10147                              <1> 	; al = 0 ; VBE_DISPI_INDEX_XRES - 1
 10148                              <1> 
 10149 00003CA9 E804000000          <1> 	call	vbe_bfn_svs_1
 10150                              <1> 
 10151                              <1> 	; from VBE_DISPI_INDEX_BANK
 10152                              <1> 	;   to VBE_DISPI_INDEX_Y_OFFSET
 10153                              <1> 
 10154 00003CAE FEC0                <1> 	inc	al 
 10155                              <1> 	; al = 4 ; VBE_DISPI_INDEX_BANK - 1
 10156                              <1> 
 10157 00003CB0 B505                <1> 	mov	ch, 5
 10158                              <1> vbe_bfn_svs_1:
 10159 00003CB2 FEC0                <1> 	inc	al ; from VBE_DISPI_INDEX_XRES
 10160                              <1> 		   ;   to VBE_DISPI_INDEX_BPP	
 10161                              <1> 	;mov	dx, 01CEh ; VBE_DISPI_IOPORT_INDEX
 10162 00003CB4 FECA                <1> 	dec	dl ; 1CEh
 10163 00003CB6 66EF                <1> 	out	dx, ax
 10164 00003CB8 50                  <1> 	push	eax
 10165                              <1> 	;mov	dx, 01CFh ; VBE_DISPI_IOPORT_DATA
 10166 00003CB9 FEC2                <1> 	inc	dl ; 1CFh
 10167 00003CBB 66ED                <1> 	in	ax, dx
 10168 00003CBD 66AB                <1> 	stosw
 10169 00003CBF 58                  <1> 	pop	eax
 10170 00003CC0 FECD                <1> 	dec	ch
 10171 00003CC2 75EE                <1> 	jnz	short vbe_bfn_svs_1		
 10172 00003CC4 C3                  <1> 	retn
 10173                              <1> 
 10174                              <1> biosfn_restore_video_state:
 10175                              <1> 	; 22/01/2021
 10176                              <1> 	; 13/01/2021
 10177                              <1> 	; 12/01/2021 (TRDOS 386 v2.0.3)
 10178                              <1> 	; (vgabios.c)
 10179                              <1> 
 10180                              <1> 	; modified registers: eax, edx, esi, edi, ch
 10181                              <1> 
 10182                              <1> 	;mov	esi, VBE3SAVERESTOREBLOCK
 10183                              <1> 
 10184                              <1> 	; input: esi = state buffer address
 10185                              <1> 
 10186 00003CC5 F6C101              <1> 	test	cl, 1
 10187 00003CC8 0F84A9000000        <1> 	jz	bfn_rvs_6
 10188                              <1> 
 10189 00003CCE 66817E40D403        <1> 	cmp	word [esi+64], 3D4h ; must be 3D4h
 10190 00003CD4 7402                <1> 	je	short bfn_rvs_0  
 10191                              <1> 			; it is seen as valid buffer
 10192 00003CD6 F9                  <1> 	stc
 10193 00003CD7 C3                  <1> 	retn
 10194                              <1> 
 10195                              <1> bfn_rvs_0:
 10196 00003CD8 89F7                <1> 	mov	edi, esi ; addr1
 10197 00003CDA 83C605              <1> 	add	esi, 5 ; skip 1st 5 bytes for now
 10198                              <1> 
 10199                              <1> 	; // Reset Attribute Ctl flip-flop
 10200                              <1>         ; inb(VGAREG_ACTL_RESET);
 10201 00003CDD 66BADA03            <1> 	mov	dx, 3DAh ; VGAREG_ACTL_RESET
 10202 00003CE1 EC                  <1> 	in	al, dx
 10203                              <1> 
 10204                              <1> 	; for(i=1;i<=4;i++){
 10205 00003CE2 B001                <1> 	mov	al, 1
 10206                              <1> 	;;mov	dx, VGAREG_SEQU_ADDRESS ; 3C4h
 10207                              <1> 	;mov	dl, 0C4h
 10208 00003CE4 B504                <1> 	mov	ch, 4
 10209                              <1> bfn_rvs_1:
 10210                              <1> 	; outb(VGAREG_SEQU_ADDRESS, i);
 10211                              <1> 	;mov	dx, VGAREG_SEQU_ADDRESS ; 3C4h
 10212 00003CE6 B2C4                <1> 	mov	dl, 0C4h
 10213 00003CE8 EE                  <1> 	out	dx, al
 10214                              <1> 	;mov	dx, VGAREG_SEQU_DATA  ; 3C5h
 10215 00003CE9 FEC2                <1> 	inc	dl  ; dx = 3C5h
 10216                              <1> 	; outb(VGAREG_SEQU_DATA)
 10217 00003CEB 50                  <1> 	push	eax
 10218 00003CEC AC                  <1> 	lodsb	; (4 bytes in loop)
 10219 00003CED EE                  <1> 	out	dx, al
 10220 00003CEE 58                  <1> 	pop	eax
 10221                              <1> 	;mov	dx, VGAREG_SEQU_ADDRESS ; 3C4h
 10222                              <1> 	;dec	dl	
 10223 00003CEF FEC0                <1> 	inc	al  ; i++
 10224 00003CF1 FECD                <1> 	dec	ch
 10225 00003CF3 75F1                <1> 	jnz	short bfn_rvs_1
 10226                              <1> 
 10227                              <1> 	; outb(VGAREG_SEQU_ADDRESS, 0);
 10228 00003CF5 28C0                <1> 	sub	al, al ; 0
 10229 00003CF7 EE                  <1> 	out	dx, al
 10230                              <1> 	; outb(VGAREG_SEQU_DATA)
 10231                              <1> 	;mov	dx, VGAREG_SEQU_DATA ; 3C5h
 10232 00003CF8 FEC2                <1> 	inc	dl  ; dx = 3C5h
 10233 00003CFA AC                  <1> 	lodsb	; (+1 byte)
 10234 00003CFB EE                  <1> 	out	dx, al
 10235                              <1> 
 10236                              <1> 	; // Disable CRTC write protection
 10237                              <1> 	; outw(crtc_addr,0x0011);
 10238                              <1> 	;mov	dx, VGAREG_VGA_CRTC_ADDRESS ; 3D4h
 10239 00003CFC B2D4                <1> 	mov	dl, 0D4h
 10240 00003CFE 66B81100            <1> 	mov	ax, 11h
 10241 00003D02 66EF                <1> 	out	dx, ax
 10242                              <1> 
 10243                              <1> 	; // Set CRTC regs
 10244                              <1>        
 10245                              <1> 	; for(i=0;i<=0x18;i++) {
 10246                              <1>         ;   if (i != 0x11) {
 10247 00003D04 28C0                <1> 	sub	al, al ; 0
 10248                              <1> 	;;mov	dx, VGAREG_VGA_CRTC_ADDRESS ; 3D4h
 10249                              <1> 	;mov	dl, 0D4h
 10250 00003D06 B519                <1> 	mov	ch, 25
 10251                              <1> bfn_rvs_2:
 10252                              <1>         ; outb(crtc_addr,i);
 10253                              <1> 	;mov	dx, VGAREG_VGA_CRTC_ADDRESS ; 3D4h
 10254 00003D08 B2D4                <1> 	mov	dl, 0D4h
 10255 00003D0A EE                  <1> 	out	dx, al
 10256                              <1> 	;mov	dx, VGAREG_VGA_CRTC_DATA ; 3D5h
 10257 00003D0B FEC2                <1> 	inc	dl  ; dx = 3D5h
 10258                              <1> 	; inb(crtc_addr+1)
 10259 00003D0D 50                  <1> 	push	eax
 10260 00003D0E AC                  <1> 	lodsb	; (25 bytes in loop)
 10261 00003D0F EE                  <1> 	out	dx, al
 10262 00003D10 58                  <1> 	pop	eax
 10263                              <1> 	;mov	dx, VGAREG_VGA_CRTC_ADDRESS ; 3D4h
 10264                              <1> 	;dec	dl
 10265 00003D11 FEC0                <1> 	inc	al  ; i++
 10266 00003D13 3C11                <1> 	cmp	al, 17 ; 11h
 10267 00003D15 7505                <1> 	jne	short bfn_rvs_3
 10268 00003D17 AC                  <1> 	lodsb
 10269 00003D18 88C4                <1> 	mov	ah, al ; *
 10270 00003D1A B012                <1> 	mov	al, 18 
 10271                              <1> bfn_rvs_3:
 10272 00003D1C FECD                <1> 	dec	ch
 10273 00003D1E 75E8                <1> 	jnz	short bfn_rvs_2
 10274                              <1> 
 10275                              <1> 	; // select crtc base address
 10276                              <1>         ; v = inb(VGAREG_READ_MISC_OUTPUT) & ~0x01;
 10277                              <1> 	;if (crtc_addr = 0x3d4)
 10278                              <1> 	;   v |= 0x01;
 10279                              <1> 	; outb(VGAREG_WRITE_MISC_OUTPUT, v);
 10280                              <1> 
 10281                              <1> 	;;mov	dx, VGAREG_READ_MISC_OUTPUT ; 3CCh
 10282                              <1> 	;mov	dl, 0CCh
 10283                              <1> 	;in	al, dl
 10284                              <1> 	;and	al, 1
 10285                              <1> 	;;mov	dx, VGAREG_WRITE_MISC_OUTPUT ; 3C2h
 10286                              <1> 	;mov	dl, 0C2h
 10287                              <1> 	;or	al, 1
 10288                              <1> 	;out	dx, al
 10289                              <1> 
 10290                              <1> 	; // enable write protection if needed
 10291                              <1> 	;outb(crtc_addr, 0x11);
 10292                              <1>         ;outb(crtc_addr+1, read_byte(ES, BX - 0x18 + 0x11));
 10293                              <1> 	;mov	dx, VGAREG_VGA_CRTC_ADDRESS ; 3D4h
 10294 00003D20 B2D4                <1> 	mov	dl, 0D4h
 10295 00003D22 B011                <1> 	mov	al, 11h
 10296 00003D24 EE                  <1> 	out	dx, al
 10297 00003D25 88E0                <1> 	mov	al, ah ; *
 10298 00003D27 FEC2                <1> 	inc	dl ; dx = 3D5h
 10299 00003D29 EE                  <1> 	out	dx, al
 10300                              <1> 
 10301                              <1> 	; // Set Attribute Ctl
 10302 00003D2A 8A6703              <1> 	mov	ah, [edi+3] ; addr1+3, ah = ar_index
 10303 00003D2D 80E420              <1> 	and	ah, 20h  ; (ar_index & 0x20)
 10304                              <1> 
 10305                              <1>         ; inb(VGAREG_ACTL_RESET);
 10306                              <1> 	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
 10307 00003D30 B2DA                <1> 	mov	dl, 0DAh
 10308 00003D32 EC                  <1> 	in	al, dx
 10309                              <1> 
 10310                              <1>         ; for(i=0;i<=0x13;i++) {
 10311 00003D33 28C0                <1> 	sub	al, al ; 0
 10312 00003D35 B514                <1> 	mov	ch, 20
 10313                              <1> bfn_rvs_4:
 10314                              <1>  	; outb(VGAREG_ACTL_ADDRESS, i | (ar_index & 0x20));
 10315 00003D37 50                  <1> 	push	eax
 10316 00003D38 08E0                <1> 	or	al, ah
 10317                              <1> 	;mov	dx, VGAREG_ACTL_ADDRESS ; 3C0h
 10318 00003D3A B2C0                <1> 	mov	dl, 0C0h
 10319 00003D3C EE                  <1> 	out	dx, al
 10320                              <1> 	;mov	dx, VGAREG_ACTL_WRITE_DATA ; 3C0h
 10321                              <1> 	;mov	dl, 0C0h
 10322 00003D3D AC                  <1> 	lodsb	; (20 bytes in loop)
 10323 00003D3E EE                  <1> 	out	dx, al
 10324 00003D3F 58                  <1> 	pop	eax
 10325 00003D40 FEC0                <1> 	inc	al  ; i++
 10326 00003D42 FECD                <1> 	dec	ch
 10327 00003D44 75F1                <1> 	jnz	short bfn_rvs_4
 10328                              <1> 
 10329                              <1> 	; outb(VGAREG_ACTL_ADDRESS, ar_index);
 10330                              <1> 	;mov	dx, VGAREG_ACTL_ADDRESS ; 3C0h
 10331                              <1> 	;mov	dl, 0C0h
 10332 00003D46 88E0                <1> 	mov	al, ah ; ar_index
 10333 00003D48 EE                  <1> 	out	dx, al
 10334                              <1> 
 10335                              <1> 	; inb(VGAREG_ACTL_RESET);
 10336                              <1> 	;mov	dx, VGAREG_ACTL_RESET ; 3DAh
 10337 00003D49 B2DA                <1> 	mov	dl, 0DAh
 10338 00003D4B EC                  <1> 	in	al, dx
 10339                              <1> 
 10340                              <1>         ; for(i=0;i<=8;i++) {
 10341 00003D4C 28C0                <1> 	sub	al, al ; 0
 10342                              <1> 	;;mov	dx, VGAREG_GRDC_ADDRESS ; 3CEh
 10343                              <1> 	;mov	dl, 0CEh
 10344 00003D4E B509                <1> 	mov	ch, 9
 10345                              <1> bfn_rvs_5:
 10346                              <1> 	; outb(VGAREG_GRDC_ADDRESS,i)
 10347                              <1> 	;mov	dx, VGAREG_GRDC_ADDRESS ; 3CEh
 10348 00003D50 B2CE                <1> 	mov	dl, 0CEh
 10349 00003D52 EE                  <1> 	out	dx, al
 10350                              <1> 	; outb(VGAREG_ACTL_READ_DATA)
 10351 00003D53 50                  <1> 	push	eax
 10352                              <1> 	;mov	dx, VGAREG_GRDC_DATA ; 3CFh
 10353                              <1> 	;mov	dl, 0CFh
 10354 00003D54 FEC2                <1> 	inc	dl
 10355 00003D56 AC                  <1> 	lodsb	; (9 bytes in loop)
 10356 00003D57 EE                  <1> 	out	dx, al
 10357 00003D58 58                  <1> 	pop	eax
 10358                              <1> 	;dec	dl
 10359 00003D59 FEC0                <1> 	inc	al  ; i++
 10360 00003D5B FECD                <1> 	dec	ch
 10361 00003D5D 75F1                <1> 	jnz	short bfn_rvs_5
 10362                              <1> 
 10363                              <1> 	; BX += 2; /* crtc_addr */     ; 3D4h
 10364                              <1>         ; BX += 4; /* plane latches */ ; 0
 10365 00003D5F 83C606              <1> 	add	esi, 6	      
 10366 00003D62 56                  <1> 	push	esi ; *	
 10367                              <1> 
 10368                              <1> 	;outb(VGAREG_SEQU_ADDRESS, read_byte(ES, addr1)); addr1++;
 10369                              <1>         ;outb(crtc_addr, read_byte(ES, addr1)); addr1++;
 10370                              <1>         ;outb(VGAREG_GRDC_ADDRESS, read_byte(ES, addr1)); addr1++;
 10371                              <1>         ;addr1++;
 10372                              <1>         ;outb(crtc_addr - 0x4 + 0xa, read_byte(ES, addr1)); addr1++;
 10373                              <1> 
 10374 00003D63 89FE                <1> 	mov	esi, edi ; start of state buffer
 10375                              <1> 
 10376                              <1> 	;mov	dx, VGAREG_SEQU_ADDRESS ; 3C7h
 10377 00003D65 B2C7                <1> 	mov	dl, 0C7h 
 10378 00003D67 AC                  <1> 	lodsb
 10379 00003D68 EE                  <1> 	out	dx, al
 10380                              <1> 	;mov	dx, VGAREG_VGA_CRTC_ADDRESS ; 3D4h
 10381 00003D69 B2D4                <1> 	mov	dl, 0D4h
 10382 00003D6B AC                  <1> 	lodsb
 10383 00003D6C EE                  <1> 	out	dx, al
 10384                              <1> 	;mov	dx, VGAREG_GRDC_ADDRESS ; 3CEh 
 10385 00003D6D B2CE                <1>         mov	dl, 0CEh
 10386 00003D6F AC                  <1> 	lodsb
 10387 00003D70 EE                  <1> 	out	dx, al
 10388 00003D71 AC                  <1> 	lodsb	; addr1++
 10389                              <1> 	;mov	dx, VGAREG_VGA_WRITE_FEATURE_CTL ; 3DAh
 10390 00003D72 B2DA                <1> 	mov	dl, 0DAh
 10391 00003D74 AC                  <1> 	lodsb
 10392 00003D75 EE                  <1> 	out	dx, al
 10393                              <1> 
 10394 00003D76 5E                  <1> 	pop	esi ; *
 10395                              <1> 
 10396                              <1> 	; (total 70 bytes are read above as controller hardware state)
 10397                              <1> 
 10398                              <1> bfn_rvs_6:		
 10399                              <1> 	; 13/01/2021
 10400 00003D77 F6C102              <1> 	test	cl, 2
 10401 00003D7A 747D                <1> 	jz	short bfn_rvs_9
 10402                              <1> 
 10403                              <1> 	; VIDEO BIOS DATA
 10404                              <1> 	; !!! this data is valid for TRDOS 386 v2 kernel only !!!
 10405                              <1> 	; (this is not same with BOCHS/PLEX86 video bios, BIOS data)  
 10406                              <1>   
 10407                              <1>     	; if (CX & 2) {
 10408                              <1> 	;write_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE, read_byte(ES, BX)); BX++;
 10409                              <1>         ;write_word(BIOSMEM_SEG,BIOSMEM_NB_COLS, read_word(ES, BX)); BX += 2;
 10410                              <1>         ;write_word(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE, read_word(ES, BX)); BX += 2;
 10411                              <1>         ;write_word(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS, read_word(ES, BX)); BX += 2;
 10412                              <1>         ;write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, read_byte(ES, BX)); BX++;
 10413                              <1>         ;write_word(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT, read_word(ES, BX)); BX += 2;
 10414                              <1>         ;write_byte(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL, read_byte(ES, BX)); BX++;
 10415                              <1>         ;write_byte(BIOSMEM_SEG,BIOSMEM_SWITCHES, read_byte(ES, BX)); BX++;
 10416                              <1>         ;write_byte(BIOSMEM_SEG,BIOSMEM_MODESET_CTL, read_byte(ES, BX)); BX++;
 10417                              <1>         ;write_word(BIOSMEM_SEG,BIOSMEM_CURSOR_TYPE, read_word(ES, BX)); BX += 2;
 10418                              <1>         ;for(i=0;i<8;i++) {
 10419                              <1>         ;   write_word(BIOSMEM_SEG, BIOSMEM_CURSOR_POS+2*i, read_word(ES, BX));
 10420                              <1>         ;   BX += 2;
 10421                              <1>         ;}
 10422                              <1>         ;write_word(BIOSMEM_SEG,BIOSMEM_CURRENT_START, read_word(ES, BX)); BX += 2;
 10423                              <1>         ;write_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_PAGE, read_byte(ES, BX)); BX++;
 10424                              <1>         ;/* current font */
 10425                              <1>         ;write_word(0, 0x1f * 4, read_word(ES, BX)); BX += 2;
 10426                              <1>         ;write_word(0, 0x1f * 4 + 2, read_word(ES, BX)); BX += 2;
 10427                              <1>         ;write_word(0, 0x43 * 4, read_word(ES, BX)); BX += 2;
 10428                              <1>         ;write_word(0, 0x43 * 4 + 2, read_word(ES, BX)); BX += 2;
 10429                              <1> 
 10430                              <1> 	; !!! save TRDOS 386 v2 kernel spesific video bios data !!!
 10431                              <1> 	; (which is/are used by 'SET_MODE' function and/or it's sub functions)
 10432                              <1> 
 10433 00003D7C 66AD                <1> 	lodsw	 ; CRTC_ADDR, always 3D4h (color VGA) for TRDOS 386 v2
 10434                              <1> 	; skip 3D4h check if it is already checked
 10435 00003D7E F6C101              <1> 	test	cl, 1
 10436 00003D81 7508                <1> 	jnz	short bfn_rvs_7
 10437 00003D83 663DD403            <1> 	cmp	ax, 3D4h
 10438 00003D87 7402                <1> 	je	short bfn_rvs_7
 10439 00003D89 F9                  <1> 	stc
 10440 00003D8A C3                  <1> 	retn
 10441                              <1> bfn_rvs_7:
 10442 00003D8B AC                  <1> 	lodsb
 10443 00003D8C A2[DE670000]        <1> 	mov	[CRT_MODE], al ; Current video mode (0FFh for VESA VBE modes) 
 10444 00003D91 AC                  <1> 	lodsb
 10445 00003D92 A2[DF670000]        <1> 	mov	[CRT_MODE_SET], al ; 29h for mode 03h ; TRDOS 386 feature only !
 10446 00003D97 66AD                <1> 	lodsw	
 10447 00003D99 66A3[2EA30100]      <1>  	mov	[video_mode], ax ; Current VESA VBE (SVGA, extended VGA) mode 
 10448 00003D9F 66AD                <1> 	lodsw		 ; (valid if [CRT_MODE] = 0FFh)	
 10449 00003DA1 66A3[54890100]      <1> 	mov	[CRT_LEN], ax ; page size (in bytes)
 10450 00003DA7 66AD                <1> 	lodsw
 10451 00003DA9 66A3[DC7C0100]      <1> 	mov	[CRT_START], ax ; video page start offset
 10452 00003DAF AC                  <1>  	lodsb
 10453 00003DB0 A2[E0670000]        <1> 	mov	[CRT_COLS], al ; nbcols, characters per row
 10454 00003DB5 AC                  <1> 	lodsb
 10455 00003DB6 A2[E6670000]        <1> 	mov	[VGA_ROWS], al ; nbrows, (character) rows per page (not rows-1)
 10456 00003DBB AC                  <1> 	lodsb
 10457 00003DBC A2[E2670000]        <1> 	mov	[CHAR_HEIGHT], al ; character font height (8 or 16 or 14)
 10458 00003DC1 AC                  <1> 	lodsb
 10459 00003DC2 A2[E3670000]        <1> 	mov	[VGA_VIDEO_CTL], al ; ROM BIOS DATA AREA Offset 87h
 10460 00003DC7 AC                  <1> 	lodsb
 10461 00003DC8 A2[E4670000]        <1> 	mov	[VGA_SWITCHES], al ; feature bit switches
 10462 00003DCD AC                  <1> 	lodsb
 10463 00003DCE A2[E5670000]        <1> 	mov	[VGA_MODESET_CTL], al ; basic mode set options
 10464                              <1> 	; followings are only used by TRDOS 386 v2 (IBM PC/AT ROMBIOS) code 
 10465                              <1> 	; (bochs/plex86 does not use and return those)
 10466 00003DD3 AC                  <1> 	lodsb
 10467 00003DD4 A2[E1670000]        <1> 	mov	[CRT_PALETTE], al ; current color palette ; TRDOS 386 feature only !
 10468 00003DD9 AC                  <1> 	lodsb
 10469 00003DDA A2[EE7C0100]        <1> 	mov	[ACTIVE_PAGE], al ; current video page 
 10470 00003DDF 66AD                <1> 	lodsw
 10471 00003DE1 66A3[F7670000]      <1> 	mov	[CURSOR_MODE], ax ; cursor type
 10472                              <1> 	;lodsd
 10473                              <1> 	;mov	[CURSOR_POSN], eax ; cursor position for video page 0 and 1 
 10474                              <1> 	;lodsd
 10475                              <1> 	;mov	[CURSOR_POSN+4], eax ; cursor position for video page 2 and 3 
 10476                              <1> 	;lodsd
 10477                              <1> 	;mov	[CURSOR_POSN+8], eax ; cursor position for video page 4 and 5 
 10478                              <1> 	;lodsd
 10479                              <1> 	;mov	[CURSOR_POSN+12], eax ; cursor position for video page 6 and 7 
 10480 00003DE7 B504                <1> 	mov	ch, 4
 10481 00003DE9 BF[DE7C0100]        <1> 	mov	edi, CURSOR_POSN
 10482                              <1> bfn_rvs_8:
 10483 00003DEE A5                  <1> 	movsd
 10484 00003DEF FECD                <1> 	dec	ch
 10485 00003DF1 75FB                <1> 	jnz	short bfn_rvs_8
 10486                              <1> 	; (font addr) protected mode address in kernel's/system memory space 
 10487                              <1> 	; (not accessable/meaningful address value by user)
 10488 00003DF3 AD                  <1> 	lodsd
 10489 00003DF4 A3[66890100]        <1> 	mov	[VGA_INT43H], eax ; VGA current (default) font address
 10490                              <1> 
 10491                              <1> 	; (total 40 bytes are read&written above as BIOS data state)
 10492                              <1> bfn_rvs_9:
 10493                              <1> 	; 13/01/2021
 10494 00003DF9 F6C104              <1> 	test	cl, 4
 10495 00003DFC 7421                <1> 	jz	short bfn_rvs_11
 10496                              <1> 
 10497                              <1> 	;BX++;
 10498                              <1>         ;v = read_byte(ES, BX); BX++;
 10499                              <1>         ;outb(VGAREG_PEL_MASK, read_byte(ES, BX)); BX++;
 10500                              <1>         ;// Set the whole dac always, from 0
 10501                              <1>         ;outb(VGAREG_DAC_WRITE_ADDRESS,0x00);
 10502                              <1>         ;for(i=0;i<256*3;i++) {
 10503                              <1>         ;   outb(VGAREG_DAC_DATA, read_byte(ES, BX)); BX++;
 10504                              <1>         ;}
 10505                              <1>         ;BX++;
 10506                              <1>         ;outb(VGAREG_DAC_WRITE_ADDRESS, v);
 10507                              <1> 
 10508                              <1> 	; /* read/write mode dac */
 10509 00003DFE AC                  <1> 	lodsb	; skip ; VGAREG_DAC_STATE
 10510 00003DFF AC                  <1> 	lodsb
 10511 00003E00 88C4                <1> 	mov	ah, al ; * ; v
 10512 00003E02 AC                  <1> 	lodsb
 10513 00003E03 66BAC603            <1> 	mov	dx, VGAREG_PEL_MASK  ; 3C6h
 10514 00003E07 EE                  <1> 	out	dx, al
 10515                              <1> 	;// Set the whole dac always, from 0
 10516 00003E08 30C0                <1> 	xor	al, al ; 0
 10517                              <1> 	;mov	dx, VGAREG_DAC_WRITE_ADDRESS ; 3C8h
 10518 00003E0A B2C8                <1> 	mov	dl, 0C8h
 10519 00003E0C EE                  <1> 	out	dx, al
 10520                              <1> 
 10521 00003E0D 51                  <1> 	push	ecx ; 22/01/2021
 10522                              <1> 	;for(i=0;i<256*3;i++) {
 10523                              <1> 	;mov	ecx, 256*3 ; 768 bytes
 10524                              <1> 	; 03/08/2022
 10525 00003E0E 29C9                <1> 	sub	ecx, ecx
 10526 00003E10 B503                <1> 	mov	ch, 3
 10527                              <1> 	; ecx = 300h = 768
 10528                              <1> 	;mov	dx, VGAREG_DAC_DATA ; 3C9h
 10529                              <1> 	;mov	dl, 0C9h
 10530 00003E12 FEC2                <1> 	inc	dl ; dx = 3C9h
 10531                              <1> bfn_rvs_10:
 10532 00003E14 AC                  <1> 	lodsb
 10533 00003E15 EE                  <1> 	out	dx, al
 10534 00003E16 E2FC                <1> 	loop	bfn_rvs_10
 10535 00003E18 59                  <1> 	pop	ecx ; 22/01/2021
 10536                              <1> 
 10537                              <1> 	; /* color select register */
 10538 00003E19 AC                  <1> 	lodsb	 ; skip 
 10539                              <1> 	
 10540 00003E1A 88E0                <1> 	mov	al, ah ; * ; v
 10541                              <1> 
 10542                              <1> 	;mov	dx, VGAREG_DAC_WRITE_ADDRESS ; 3C8h
 10543                              <1> 	;mov	dl, 0C8h
 10544 00003E1C FECA                <1> 	dec	dl ; dx  = 3C8h
 10545 00003E1E EE                  <1> 	out	dx, al ; * ; v
 10546                              <1> 	
 10547                              <1> 	; (total 772 bytes are read above as DAC state)
 10548                              <1> bfn_rvs_11:
 10549 00003E1F C3                  <1> 	retn
 10550                              <1> 
 10551                              <1> vbe_biosfn_restore_video_state:
 10552                              <1> 	; 23/01/2021
 10553                              <1> 	; 13/01/2021 (TRDOS 386 v2.0.3)
 10554                              <1> 	; (vbe.c)
 10555                              <1> 
 10556                              <1> 	; modified registers: eax, edx, esi, ch
 10557                              <1> 	
 10558                              <1> 	; input: esi = state buffer address
 10559                              <1> 	; output: 
 10560                              <1> 	;	 VBE DISPI register contents will be restored
 10561                              <1> 	;	 (18 bytes, 9 words)
 10562                              <1> 
 10563                              <1>  	; enable = read_word(ES, BX);
 10564                              <1> 	; BX += 2;
 10565                              <1> 	;
 10566                              <1> 	; if (!(enable & VBE_DISPI_ENABLED)) {
 10567                              <1>         ;   outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
 10568                              <1>         ;   outw(VBE_DISPI_IOPORT_DATA, enable);
 10569                              <1> 	; } else {
 10570                              <1>         ;   outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_XRES);
 10571                              <1>         ;   outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
 10572                              <1>         ;   BX += 2;
 10573                              <1>         ;   outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_YRES);
 10574                              <1>         ;   outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
 10575                              <1>         ;   BX += 2;
 10576                              <1>         ;   outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_BPP);
 10577                              <1>         ;   outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
 10578                              <1>         ;   BX += 2;
 10579                              <1>         ;   outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
 10580                              <1>         ;   outw(VBE_DISPI_IOPORT_DATA, enable);
 10581                              <1> 	;
 10582                              <1>         ;  for(i = VBE_DISPI_INDEX_BANK; i <= VBE_DISPI_INDEX_Y_OFFSET; i++)
 10583                              <1> 	;    {
 10584                              <1>         ;     outw(VBE_DISPI_IOPORT_INDEX, i);
 10585                              <1>         ;     outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
 10586                              <1>         ;     BX += 2;
 10587                              <1>         ;    }
 10588                              <1>         ; }
 10589                              <1> 
 10590 00003E20 66AD                <1> 	lodsw	; enable (status, enabled=1, disabled=0)
 10591 00003E22 66BACE01            <1> 	mov	dx, 01CEh ; VBE_DISPI_IOPORT_INDEX
 10592                              <1> 	; 23/01/2021
 10593 00003E26 6683E001            <1> 	and	ax, 1 ; VBE_DISPI_ENABLED
 10594 00003E2A 750B                <1> 	jnz	short vbe_bfn_rvs_1
 10595                              <1> 	; ax = 0
 10596                              <1> 	; VBE_DISPI_DISABLED
 10597                              <1> vbe_bfn_rvs_0:
 10598                              <1> 	; enable (disable) dispi
 10599                              <1> 	; dx = 01CEh ; VBE_DISPI_IOPORT_INDEX
 10600                              <1> 	; ah = 0
 10601 00003E2C 50                  <1> 	push	eax
 10602 00003E2D B004                <1> 	mov	al, 04h	; VBE_DISPI_INDEX_ENABLE
 10603 00003E2F 66EF                <1> 	out	dx, ax
 10604                              <1> 	;mov	dx, 01CFh ; VBE_DISPI_IOPORT_DATA
 10605 00003E31 FEC2                <1> 	inc	dl
 10606 00003E33 58                  <1> 	pop	eax
 10607 00003E34 66EF                <1> 	out	dx, ax ; enable (or disable)
 10608 00003E36 C3                  <1> 	retn
 10609                              <1> vbe_bfn_rvs_1:
 10610                              <1> 	; VBE_DISPI_ENABLED
 10611                              <1> 
 10612                              <1> 	; from VBE_DISPI_INDEX_XRES
 10613                              <1> 	;   to VBE_DISPI_INDEX_BPP	
 10614                              <1> 
 10615 00003E37 B503                <1>  	mov	ch, 3
 10616 00003E39 28C0                <1> 	sub	al, al ; 0 ; VBE_DISPI_INDEX_XRES - 1
 10617                              <1> 	; ax = 0
 10618                              <1> 
 10619 00003E3B E80B000000          <1> 	call	vbe_bfn_rvs_2
 10620                              <1> 
 10621                              <1>         ;outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
 10622                              <1> 	;outw(VBE_DISPI_IOPORT_DATA, enable);
 10623                              <1> 
 10624                              <1> 	; 23/01/2021
 10625 00003E40 B001                <1> 	mov	al, 1 ; VBE_DISPI_ENABLED
 10626                              <1> 	; ax = 1
 10627 00003E42 E8E5FFFFFF          <1> 	call	vbe_bfn_rvs_0
 10628                              <1> 
 10629                              <1> 	; from VBE_DISPI_INDEX_BANK
 10630                              <1> 	;   to VBE_DISPI_INDEX_Y_OFFSET
 10631                              <1> 
 10632 00003E47 B505                <1> 	mov	ch, 5
 10633                              <1> 	; 23/01/2021
 10634 00003E49 B004                <1> 	mov	al, 4  ; VBE_DISPI_INDEX_BANK - 1
 10635                              <1> 	; ax = 4
 10636                              <1> vbe_bfn_rvs_2:
 10637 00003E4B FEC0                <1> 	inc	al ; from VBE_DISPI_INDEX_XRES
 10638                              <1> 		     ; to VBE_DISPI_INDEX_BPP	
 10639                              <1> 	;mov	dx, 01CEh ; VBE_DISPI_IOPORT_INDEX
 10640                              <1> 	;mov	dl, 0CEh
 10641 00003E4D 66EF                <1> 	out	dx, ax
 10642 00003E4F 50                  <1> 	push	eax
 10643                              <1> 	;mov	dx, 01CFh ; VBE_DISPI_IOPORT_DATA
 10644 00003E50 FEC2                <1> 	inc	dl ; 1CFh
 10645 00003E52 66AD                <1> 	lodsw
 10646 00003E54 66EF                <1> 	out	dx, ax
 10647 00003E56 58                  <1> 	pop	eax
 10648 00003E57 FECA                <1> 	dec	dl ; 1CEh
 10649 00003E59 FECD                <1> 	dec	ch
 10650 00003E5B 75EE                <1> 	jnz	short vbe_bfn_rvs_2		
 10651 00003E5D C3                  <1> 	retn
 10652                              <1> 
 10653                              <1> ; ---------------------------------------------------------
 10654                              <1>  
 10655                              <1> dispi_set_enable:
 10656                              <1> 	; 03/08/2022
 10657                              <1> 	; 23/11/2020
 10658                              <1> 	; Input:
 10659                              <1> 	;	ax = VBE_DISPI_ENABLED = 1
 10660                              <1> 	;	     or VBE_DISPI_DISABLED = 0
 10661                              <1> 	;
 10662                              <1> 	; Modified registers: none
 10663                              <1> 	
 10664                              <1> 	;push	edx
 10665                              <1> 	;push	eax
 10666                              <1> 	;mov	dx, 01CEh ; VBE_DISPI_IOPORT_INDEX
 10667                              <1> 	;mov	ax, 04h	  ; VBE_DISPI_INDEX_ENABLE
 10668                              <1> 	;out	dx, ax
 10669                              <1> 	;pop	eax
 10670                              <1> 	;;mov	dx, 01CFh ; VBE_DISPI_IOPORT_DATA
 10671                              <1> 	;;mov	dl, 0CFh
 10672                              <1> 	;inc	dl
 10673                              <1> 	;out	dx, ax
 10674                              <1> 	;pop	edx
 10675                              <1> 	;retn
 10676                              <1> 
 10677                              <1> 	; 25/11/2020
 10678                              <1> 	; Modified registers: edx
 10679                              <1> 	;;push	edx
 10680                              <1> 	;mov	dx, 04h ; VBE_DISPI_INDEX_ENABLE
 10681                              <1> 	; 03/08/2022
 10682 00003E5E 28F6                <1> 	sub	dh, dh
 10683 00003E60 B204                <1> 	mov	dl, 04h ; VBE_DISPI_INDEX_ENABLE
 10684                              <1> 
 10685                              <1> 	;;call	dispi_set_parms
 10686                              <1> 	;;pop	edx
 10687                              <1> 	;;retn
 10688                              <1> 	;jmp	short dispi_set_parms
 10689                              <1> 
 10690                              <1> dispi_set_parms:
 10691                              <1> 	; 03/08/2022
 10692                              <1> 	; 25/11/2020
 10693                              <1> 	; Input:
 10694                              <1> 	;	ax = data
 10695                              <1> 	;	dx = vbe dispi register index
 10696                              <1> 	;
 10697                              <1> 	; Modified registers: edx
 10698                              <1> 
 10699 00003E62 50                  <1> 	push	eax
 10700                              <1> 	;mov	ax, dx
 10701                              <1> 	; 03/08/2022
 10702 00003E63 89D0                <1> 	mov	eax, edx
 10703 00003E65 66BACE01            <1> 	mov	dx, 01CEh ; VBE_DISPI_IOPORT_INDEX
 10704 00003E69 66EF                <1> 	out	dx, ax
 10705 00003E6B 58                  <1> 	pop	eax
 10706                              <1> 	;mov	dx, 01CFh ; VBE_DISPI_IOPORT_DATA
 10707                              <1> 	;mov	dl, 0CFh
 10708 00003E6C FEC2                <1> 	inc	dl
 10709 00003E6E 66EF                <1> 	out	dx, ax
 10710 00003E70 C3                  <1> 	retn
 10711                              <1> 
 10712                              <1> dispi_set_bpp:
 10713                              <1> 	; 03/08/2022
 10714                              <1> 	; 25/11/2020
 10715                              <1> 	; Input:
 10716                              <1> 	;	ax = Bits per pixel value
 10717                              <1> 	;	     (8,16,24,32)
 10718                              <1> 	;
 10719                              <1> 	; Modified registers: none
 10720                              <1> 
 10721                              <1> 	;push	edx
 10722                              <1> 	;push	eax
 10723                              <1> 	;mov	dx, 01CEh ; VBE_DISPI_IOPORT_INDEX
 10724                              <1> 	;mov	ax, 03h	  ; VBE_DISPI_INDEX_BPP
 10725                              <1> 	;out	dx, ax
 10726                              <1> 	;pop	eax
 10727                              <1> 	;;mov	dx, 01CFh ; VBE_DISPI_IOPORT_DATA
 10728                              <1> 	;;mov	dl, 0CFh
 10729                              <1> 	;inc	dl
 10730                              <1> 	;out	dx, ax
 10731                              <1> 	;pop	edx
 10732                              <1> 	;retn
 10733                              <1> 
 10734                              <1> 	; 25/11/2020
 10735                              <1> 	; Modified registers: edx
 10736                              <1> 	;;push	edx
 10737                              <1> 	;mov	dx, 03h ; VBE_DISPI_INDEX_BPP
 10738                              <1> 	; 03/08/2022
 10739 00003E71 28F6                <1> 	sub	dh, dh
 10740 00003E73 B203                <1> 	mov	dl, 03h ; VBE_DISPI_INDEX_BPP	
 10741                              <1> 
 10742                              <1> 	;;call	dispi_set_parms
 10743                              <1> 	;;pop	edx
 10744                              <1> 	;;retn
 10745 00003E75 EBEB                <1> 	jmp	short dispi_set_parms
 10746                              <1> 
 10747                              <1> dispi_set_xres:
 10748                              <1> 	; 03/08/2022
 10749                              <1> 	; 25/11/2020
 10750                              <1> 	; Input:
 10751                              <1> 	;	ax = X resolution (screen witdh)
 10752                              <1> 	;	     (320,640,800,1024,1280,1920)
 10753                              <1> 	;
 10754                              <1> 	; Modified registers: none
 10755                              <1> 
 10756                              <1> 	;push	edx
 10757                              <1> 	;push	eax
 10758                              <1> 	;mov	dx, 01CEh ; VBE_DISPI_IOPORT_INDEX
 10759                              <1> 	;mov	ax, 01h	  ; VBE_DISPI_INDEX_XRES
 10760                              <1> 	;out	dx, ax
 10761                              <1> 	;pop	eax
 10762                              <1> 	;;mov	dx, 01CFh ; VBE_DISPI_IOPORT_DATA
 10763                              <1> 	;;mov	dl, 0CFh
 10764                              <1> 	;inc	dl
 10765                              <1> 	;out	dx, ax
 10766                              <1> 	;pop	edx
 10767                              <1> 	;retn
 10768                              <1> 
 10769                              <1> 	; 25/11/2020
 10770                              <1> 	; Modified registers: edx
 10771                              <1> 	;;push	edx
 10772                              <1> 	;mov	dx, 01h ; VBE_DISPI_INDEX_XRES
 10773                              <1> 	; 03/08/2022
 10774 00003E77 28F6                <1> 	sub	dh, dh
 10775 00003E79 B201                <1> 	mov	dl, 01h ; VBE_DISPI_INDEX_XRES
 10776                              <1> 	;;call	dispi_set_parms
 10777                              <1> 	;;pop	edx
 10778                              <1> 	;;retn
 10779 00003E7B EBE5                <1> 	jmp	short dispi_set_parms
 10780                              <1> 
 10781                              <1> dispi_set_yres:
 10782                              <1> 	; 03/08/2022
 10783                              <1> 	; 25/11/2020
 10784                              <1> 	; Input:
 10785                              <1> 	;	ax = Y resolution (screen height)
 10786                              <1> 	;	     (200,400,600,720,768,1080)
 10787                              <1> 	;
 10788                              <1> 	; Modified registers: none
 10789                              <1> 
 10790                              <1> 	;push	edx
 10791                              <1> 	;push	eax
 10792                              <1> 	;mov	dx, 01CEh ; VBE_DISPI_IOPORT_INDEX
 10793                              <1> 	;mov	ax, 02h	  ; VBE_DISPI_INDEX_YRES
 10794                              <1> 	;out	dx, ax
 10795                              <1> 	;pop	eax
 10796                              <1> 	;;mov	dx, 01CFh ; VBE_DISPI_IOPORT_DATA
 10797                              <1> 	;;mov	dl, 0CFh
 10798                              <1> 	;inc	dl
 10799                              <1> 	;out	dx, ax
 10800                              <1> 	;pop	edx
 10801                              <1> 	;retn
 10802                              <1> 
 10803                              <1> 	; 25/11/2020
 10804                              <1> 	; Modified registers: edx
 10805                              <1> 	;;push	edx
 10806                              <1> 	;mov	dx, 02h ; VBE_DISPI_INDEX_YRES
 10807                              <1> 	; 03/08/2022
 10808 00003E7D 28F6                <1> 	sub	dh, dh
 10809 00003E7F B202                <1> 	mov	dl, 02h ; VBE_DISPI_INDEX_YRES
 10810                              <1> 	;;call	dispi_set_parms
 10811                              <1> 	;;pop	edx
 10812                              <1> 	;;retn
 10813 00003E81 EBDF                <1> 	jmp	short dispi_set_parms
 10814                              <1> 
 10815                              <1> dispi_set_bank:
 10816                              <1> 	; 03/08/2022
 10817                              <1> 	; 25/11/2020
 10818                              <1> 	; Input:
 10819                              <1> 	;	ax = video memory bank number
 10820                              <1> 	;
 10821                              <1> 	; Modified registers: none
 10822                              <1> 
 10823                              <1> 	;push	edx
 10824                              <1> 	;push	eax
 10825                              <1> 	;mov	dx, 01CEh ; VBE_DISPI_IOPORT_INDEX
 10826                              <1> 	;mov	ax, 05h	  ; VBE_DISPI_INDEX_BANK
 10827                              <1> 	;out	dx, ax
 10828                              <1> 	;pop	eax
 10829                              <1> 	;;mov	dx, 01CFh ; VBE_DISPI_IOPORT_DATA
 10830                              <1> 	;;mov	dl, 0CFh
 10831                              <1> 	;inc	dl
 10832                              <1> 	;out	dx, ax
 10833                              <1> 	;pop	edx
 10834                              <1> 	;retn
 10835                              <1> 	
 10836                              <1> 	; 25/11/2020
 10837                              <1> 	; Modified registers: edx
 10838                              <1> 	;;push	edx
 10839                              <1> 	;mov	dx, 05h	; VBE_DISPI_INDEX_BANK
 10840                              <1> 	; 03/08/2022
 10841 00003E83 28F6                <1> 	sub	dh, dh
 10842 00003E85 B205                <1> 	mov	dl, 05h	; VBE_DISPI_INDEX_BANK
 10843                              <1> 	;;call	dispi_set_parms
 10844                              <1> 	;;pop	edx
 10845                              <1> 	;;retn
 10846 00003E87 EBD9                <1> 	jmp	short dispi_set_parms
 10847                              <1> 
 10848                              <1> dispi_get_enable:
 10849                              <1> 	; 03/08/2022
 10850                              <1> 	; 27/11/2020
 10851                              <1> 	; Input:
 10852                              <1> 	;	none
 10853                              <1> 	; Output:
 10854                              <1> 	;	ax = vbe dispi status
 10855                              <1> 	;
 10856                              <1> 	; Modified registers: eax
 10857                              <1> 	
 10858                              <1> 	;push	edx
 10859                              <1> 	;mov	dx, 01CEh ; VBE_DISPI_IOPORT_INDEX
 10860                              <1> 	;mov	ax, 04h	  ; VBE_DISPI_INDEX_ENABLE
 10861                              <1> 	;out	dx, ax
 10862                              <1> 	;;mov	dx, 01CFh ; VBE_DISPI_IOPORT_DATA
 10863                              <1> 	;;mov	dl, 0CFh
 10864                              <1> 	;inc	dl
 10865                              <1> 	;in	ax, dx
 10866                              <1> 	;pop	edx
 10867                              <1> 	;retn
 10868                              <1> 
 10869                              <1> 	; 27/11/2020
 10870                              <1> 	; Modified registers: eax, edx
 10871                              <1> 	;;push	edx
 10872                              <1> 	;mov	ax, 04h ; VBE_DISPI_INDEX_ENABLE
 10873                              <1> 	; 03/08/2022
 10874 00003E89 28E4                <1> 	sub	ah, ah
 10875 00003E8B B004                <1> 	mov	al, 04h ; VBE_DISPI_INDEX_ENABLE
 10876                              <1> 
 10877                              <1> 	;;call	dispi_get_parms
 10878                              <1> 	;;pop	edx
 10879                              <1> 	;;retn
 10880                              <1> 	;jmp	short dispi_get_parms
 10881                              <1> 
 10882                              <1> dispi_get_parms:
 10883                              <1> 	; 25/11/2020
 10884                              <1> 	; Input:
 10885                              <1> 	;	ax = vbe dispi register index
 10886                              <1> 	; output:
 10887                              <1> 	;	ax = data
 10888                              <1> 	;
 10889                              <1> 	; Modified registers: eax, edx
 10890                              <1> 
 10891 00003E8D 66BACE01            <1> 	mov	dx, 01CEh ; VBE_DISPI_IOPORT_INDEX
 10892 00003E91 66EF                <1> 	out	dx, ax
 10893                              <1> 	;mov	dx, 01CFh ; VBE_DISPI_IOPORT_DATA
 10894                              <1> 	;mov	dl, 0CFh
 10895 00003E93 FEC2                <1> 	inc	dl
 10896 00003E95 66ED                <1> 	in	ax, dx
 10897 00003E97 C3                  <1> 	retn
 10898                              <1> 
 10899                              <1> vga_compat_setup:
 10900                              <1> 	; 03/08/2022
 10901                              <1> 	; 26/11/2020
 10902                              <1> 	; 25/11/2020
 10903                              <1> 	; VGA compatibility setup
 10904                              <1> 	; (vbe.c, 02/01/2020, vruppert)
 10905                              <1> 	;
 10906                              <1> 	; Input:
 10907                              <1> 	;	none
 10908                              <1> 	;
 10909                              <1> 	; Modified registers: eax, edx
 10910                              <1> 	
 10911                              <1> 	; 26/11/2020
 10912                              <1>   	;push	eax
 10913                              <1>   	;push	edx
 10914                              <1> 
 10915                              <1>   	; set CRT X resolution
 10916 00003E98 66BACE01            <1>   	mov	dx, 1CEh ; VBE_DISPI_IOPORT_INDEX
 10917                              <1>   	;mov	ax, 01h  ; VBE_DISPI_INDEX_XRES
 10918                              <1>   	; 03/08/2022
 10919 00003E9C 31C0                <1> 	xor	eax, eax
 10920 00003E9E FEC0                <1> 	inc	al
 10921                              <1> 	; eax = 1
 10922 00003EA0 66EF                <1> 	out	dx, ax
 10923                              <1>   	;mov	dx, 1CFh ; VBE_DISPI_IOPORT_DATA
 10924 00003EA2 FEC2                <1>   	inc	dl
 10925 00003EA4 66ED                <1> 	in	ax, dx
 10926 00003EA6 50                  <1> 	push	eax
 10927 00003EA7 66BAD403            <1> 	mov	dx, 3D4h ; VGAREG_VGA_CRTC_ADDRESS
 10928 00003EAB 66B81100            <1> 	mov	ax, 0011h ; Vertical retrace end register
 10929 00003EAF 66EF                <1>   	out	dx, ax
 10930                              <1>   	;pop	eax
 10931                              <1>   	;push	eax
 10932 00003EB1 8B0424              <1>   	mov	eax, [esp]
 10933                              <1> 	;shr	ax, 3 ; / 8 for pixel to character
 10934                              <1> 	;dec	ax  ; - 1 (EGA or VGA?)
 10935                              <1>   	; 03/08/2022
 10936 00003EB4 C1E803              <1> 	shr	eax, 3
 10937 00003EB7 48                  <1>   	dec	eax
 10938 00003EB8 88C4                <1> 	mov	ah, al
 10939 00003EBA B001                <1>   	mov	al, 01h ; Horizontal display end register
 10940 00003EBC 66EF                <1>   	out	dx, ax
 10941 00003EBE 58                  <1>   	pop	eax
 10942                              <1> 
 10943 00003EBF E89C000000          <1> 	call	vga_set_virt_width
 10944                              <1> 
 10945                              <1>   	; set CRT Y resolution
 10946                              <1> 	; 03/08/2022
 10947 00003EC4 66BACE01            <1>   	mov	dx, 1CEh ; VBE_DISPI_IOPORT_INDEX
 10948 00003EC8 66B80200            <1>   	mov	ax, 02h  ; VBE_DISPI_INDEX_YRES
 10949 00003ECC 66EF                <1>   	out	dx, ax
 10950                              <1>   	;mov	dx, 1CFh ; VBE_DISPI_IOPORT_DATA
 10951                              <1> 	; 03/08/2022
 10952 00003ECE FEC2                <1>   	inc	dl
 10953 00003ED0 66ED                <1> 	in	ax, dx
 10954 00003ED2 50                  <1> 	push	eax
 10955 00003ED3 66BAD403            <1> 	mov	dx, 3D4h ; VGAREG_VGA_CRTC_ADDRESS
 10956 00003ED7 88C4                <1>   	mov	ah, al
 10957 00003ED9 B012                <1> 	mov	al, 12h ; Vertical display end register
 10958 00003EDB 66EF                <1>   	out	dx, ax
 10959 00003EDD 58                  <1>   	pop	eax
 10960 00003EDE B007                <1>   	mov	al, 07h	; Overflow register
 10961 00003EE0 EE                  <1>   	out	dx, al
 10962                              <1>   	;inc	dx
 10963                              <1>   	; 03/08/2022
 10964 00003EE1 FEC2                <1> 	inc	dl
 10965 00003EE3 EC                  <1> 	in	al, dx ; read overflow register
 10966 00003EE4 24BD                <1>   	and	al, 0BDh ; clear VDE 9th and 10th bits	
 10967 00003EE6 F6C401              <1>   	test	ah, 01h
 10968 00003EE9 7402                <1>   	jz	short bit8_clear
 10969 00003EEB 0C02                <1>   	or	al, 02h ; VDE 9th bit (bit 8) in bit 1
 10970                              <1> bit8_clear:
 10971 00003EED F6C402              <1>   	test	ah, 02h
 10972 00003EF0 7402                <1>   	jz	short bit9_clear
 10973 00003EF2 0C40                <1>   	or	al, 40h ; VDE 10th bit (bit 9) in bit 6
 10974                              <1> bit9_clear:
 10975 00003EF4 EE                  <1>   	out	dx, al
 10976                              <1> 
 10977                              <1>   	; other settings
 10978                              <1>  	;mov	dx, 3D4h ; VGAREG_VGA_CRTC_ADDRESS
 10979                              <1>   	; 03/08/2022
 10980 00003EF5 B2D4                <1> 	mov	dl, 0D4h
 10981 00003EF7 66B80900            <1> 	mov	ax, 0009h ; Maximum scan line register
 10982 00003EFB 66EF                <1>   	out	dx, ax	; Reset
 10983 00003EFD B017                <1>   	mov	al, 17h ; Mode control register		
 10984 00003EFF EE                  <1>   	out	dx, al
 10985                              <1>  	;mov	dx, 3D5h ; VGAREG_VGA_CRTC_DATA
 10986 00003F00 FEC2                <1>   	inc	dl
 10987 00003F02 EC                  <1> 	in	al, dx	; Read mode control register
 10988 00003F03 0C03                <1>   	or	al, 03h ; Set SRS and CMS bits
 10989 00003F05 EE                  <1>   	out	dx, al 
 10990                              <1>   	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
 10991                              <1>   	; 03/08/2022
 10992 00003F06 B2DA                <1> 	mov	dl, 0DAh
 10993 00003F08 EC                  <1> 	in	al, dx	 ; clear flip-flop
 10994                              <1>   	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
 10995                              <1>   	; 03/08/2022
 10996 00003F09 B2C0                <1> 	mov	dl, 0C0h
 10997 00003F0B B010                <1> 	mov	al, 10h	; Mode control register
 10998 00003F0D EE                  <1>   	out	dx, al
 10999                              <1> 	;mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
 11000 00003F0E FEC2                <1> 	inc	dl
 11001 00003F10 EC                  <1> 	in	al, dx
 11002 00003F11 0C01                <1> 	or	al, 01h ; select graphics mode
 11003                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
 11004 00003F13 FECA                <1> 	dec	dl
 11005 00003F15 EE                  <1> 	out	dx, al ; Write to mode control register
 11006 00003F16 B020                <1> 	mov	al, 20h ; Palette RAM <-> display memory
 11007 00003F18 EE                  <1> 	out	dx, al ; Write to attribute addr register
 11008                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
 11009                              <1> 	; 03/08/2022
 11010 00003F19 B2CE                <1> 	mov	dl, 0CEh 
 11011 00003F1B 66B80605            <1> 	mov	ax, 0506h ; Misc. register, graph, mm 1
 11012 00003F1F 66EF                <1> 	out	dx, ax
 11013                              <1> 	;mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
 11014                              <1> 	; 03/08/2022
 11015 00003F21 B2C4                <1> 	mov	dl, 0C4h 
 11016 00003F23 66B8020F            <1> 	mov	ax, 0F02h ; Map mask register, all planes
 11017 00003F27 66EF                <1> 	out	dx, ax
 11018                              <1> 
 11019                              <1>   	; settings for >= 8bpp
 11020                              <1> 
 11021                              <1> 	;mov	dx, 1CEh ; VBE_DISPI_IOPORT_INDEX
 11022                              <1> 	;mov	ax, 03h ; VBE_DISPI_INDEX_BPP
 11023                              <1> 	;out	dx, ax
 11024                              <1> 	;;mov	dx, 1CFh ; VBE_DISPI_IOPORT_DATA
 11025                              <1> 	;inc	dl
 11026                              <1> 	;in	ax, dx
 11027                              <1> 	;cmp	al, 08h  ; < 8 bits per pixel
 11028                              <1> 	;jb	short vga_compat_end
 11029                              <1> 
 11030                              <1> 	;mov	dx, 3D4h ; VGAREG_VGA_CRTC_ADDRESS
 11031                              <1> 	; 03/08/2022
 11032 00003F29 B2D4                <1> 	mov	dl, 0D4h
 11033 00003F2B B014                <1> 	mov	al, 14h  ; Underline location register
 11034 00003F2D EE                  <1> 	out	dx, al
 11035                              <1> 	;mov	dx, 3D5h ; VGAREG_VGA_CRTC_DATA
 11036 00003F2E FEC2                <1> 	inc	dl
 11037 00003F30 EC                  <1> 	in	al, dx	
 11038 00003F31 0C40                <1> 	or	al, 40h	 ; enable double word mode
 11039 00003F33 EE                  <1> 	out	dx, al
 11040                              <1> 	;mov	dx, 3DAh ; VGAREG_ACTL_RESET
 11041                              <1> 	; 03/08/2022
 11042 00003F34 B2DA                <1> 	mov	dl, 0DAh
 11043 00003F36 EC                  <1> 	in	al, dx	 ; clear flip-flop
 11044                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
 11045                              <1> 	; 03/08/2022
 11046 00003F37 B2C0                <1> 	mov	dl, 0C0h
 11047 00003F39 B010                <1> 	mov	al, 10h	 ; Mode control register
 11048 00003F3B EE                  <1> 	out	dx, al
 11049                              <1> 	;mov	dx, 3C1h ; VGAREG_ACTL_READ_DATA
 11050 00003F3C FEC2                <1> 	inc	dl
 11051 00003F3E EC                  <1> 	in	al, dx
 11052 00003F3F 0C40                <1> 	or	al, 40h  ; Pixel clock select is 1
 11053                              <1> 	;mov	dx, 3C0h ; VGAREG_ACTL_ADDRESS
 11054 00003F41 FECA                <1> 	dec	dl
 11055 00003F43 EE                  <1> 	out	dx, al	 ; update mode control reggister
 11056 00003F44 B020                <1> 	mov	al, 20h	 ; select display memory as PAS	
 11057 00003F46 EE                  <1> 	out	dx, al
 11058                              <1> 	;mov	dx, 3C4h ; VGAREG_SEQU_ADDRESS
 11059                              <1> 	; 03/08/2022
 11060 00003F47 B2C4                <1> 	mov	dl, 0C4h
 11061 00003F49 B004                <1> 	mov	al, 04h	; Memory mode register
 11062 00003F4B EE                  <1> 	out	dx, al
 11063                              <1> 	;mov	dx, 3C5h ; VGAREG_SEQU_DATA
 11064 00003F4C FEC2                <1> 	inc	dl
 11065 00003F4E EC                  <1> 	in	al, dx
 11066 00003F4F 0C08                <1> 	or	al, 08h	; enable chain four
 11067 00003F51 EE                  <1> 	out	dx, al
 11068                              <1> 	;mov	dx, 3CEh ; VGAREG_GRDC_ADDRESS
 11069                              <1> 	; 03/08/2022
 11070 00003F52 B2CE                <1> 	mov	dl, 0CEh
 11071 00003F54 B005                <1> 	mov	al, 05h	 ; Mode register	
 11072 00003F56 EE                  <1> 	out	dx, al
 11073                              <1> 	;mov	dx, 3CFh ; VGAREG_GRDC_DATA
 11074 00003F57 FEC2                <1> 	inc	dl
 11075 00003F59 EC                  <1> 	in	al, dx	
 11076 00003F5A 249F                <1> 	and	al, 9Fh	 ; clear shift register 
 11077 00003F5C 0C40                <1> 	or	al, 40h  ; set shift register to 2
 11078 00003F5E EE                  <1> 	out	dx, al
 11079                              <1> 
 11080                              <1> vga_compat_end:
 11081                              <1>   	;pop	edx
 11082                              <1>   	;pop	eax
 11083 00003F5F C3                  <1> 	retn
 11084                              <1> 
 11085                              <1> vga_set_virt_width:
 11086                              <1> 	; 03/08/2022
 11087                              <1> 	; 27/11/2020
 11088                              <1> 	; 25/11/2020
 11089                              <1> 	; (vbe.c, 02/01/2020, vruppert)
 11090                              <1> 	;
 11091                              <1> 	; Input:
 11092                              <1> 	;	AX = resolution (screen width)
 11093                              <1> 	;
 11094                              <1> 	; Modified registers: eax, edx
 11095                              <1> 
 11096                              <1>   	;;push	ebx
 11097                              <1>   	;push	edx
 11098                              <1> 	;push	eax
 11099                              <1>   	;mov	ebx, eax
 11100                              <1>   	;call	dispi_get_bpp ; bits per pixel
 11101                              <1> 	;cmp	al, 4
 11102                              <1> 	;ja	short set_width_svga  ; 8, 16, 24, 32 
 11103                              <1> 	;shr	bx, 1
 11104                              <1> ;set_width_svga:
 11105                              <1> 	;shr	bx, 3
 11106                              <1> 	;mov	eax, [esp]
 11107                              <1> 	;shr	ax, 3	; / 8, bytes per row
 11108                              <1> 	; 03/08/2022
 11109 00003F60 C1E803              <1> 	shr	eax, 3
 11110 00003F63 66BAD403            <1> 	mov	dx, 3D4h ; VGAREG_VGA_CRTC_ADDRESS
 11111                              <1> 	;mov	ah, bl	; 
 11112 00003F67 88C4                <1> 	mov	ah, al	; width in bytes
 11113 00003F69 B013                <1> 	mov	al, 13h	; offset register
 11114 00003F6B 66EF                <1> 	out	dx, ax	; index (3D4h) and data (3D5h)
 11115                              <1> 	;pop	eax
 11116                              <1> 	;pop  	edx
 11117                              <1> 	;;pop	ebx
 11118 00003F6D C3                  <1> 	retn
 11119                              <1> 
 11120                              <1> ; 24/11/2020
 11121                              <1> 
 11122                              <1> struc bmi ; BOCHS/PLEX86 MODE INFO structure/table 
 11123 00000000 ????                <1>  .mode:	  resw 1
 11124 00000002 ????                <1>  .width:  resw 1
 11125 00000004 ????                <1>  .height: resw 1
 11126 00000006 ????                <1>  .depth:  resw 1
 11127                              <1>  .size:	
 11128                              <1> endstruc
 11129                              <1> 
 11130                              <1> ; 24/11/2020
 11131                              <1> struc MODEINFO
 11132 00000000 ????                <1>  .mode:			resw 1  ; 1XXh
 11133 00000002 ????                <1>  .ModeAttributes:	resw 1
 11134 00000004 ??                  <1>  .WinAAttributes:	resb 1
 11135 00000005 ??                  <1>  .WinBAttributes:	resb 1	; = 0
 11136 00000006 ????                <1>  .WinGranularity:	resw 1
 11137 00000008 ????                <1>  .WinSize:		resw 1
 11138 0000000A ????                <1>  .WinASegment:		resw 1
 11139 0000000C ????                <1>  .WinBSegment:		resw 1	; = 0
 11140 0000000E ????????            <1>  .WinFuncPtr:		resd 1	; = 0
 11141 00000012 ????                <1>  .BytesPerScanLine:	resw 1
 11142 00000014 ????                <1>  .XResolution:		resw 1
 11143 00000016 ????                <1>  .YResolution:		resw 1
 11144 00000018 ??                  <1>  .XCharSize:		resb 1
 11145 00000019 ??                  <1>  .YCharSize:		resb 1
 11146 0000001A ??                  <1>  .NumberOfPlanes: 	resb 1
 11147 0000001B ??                  <1>  .BitsPerPixel:		resb 1
 11148 0000001C ??                  <1>  .NumberOfBanks:	resb 1
 11149 0000001D ??                  <1>  .MemoryModel:		resb 1
 11150 0000001E ??                  <1>  .BankSize:		resb 1	; = 0
 11151 0000001F ??                  <1>  .NumberOfImagePages: 	resb 1
 11152 00000020 ??                  <1>  .Reserved_page:	resb 1	; = 0
 11153 00000021 ??                  <1>  .RedMaskSize:		resb 1
 11154 00000022 ??                  <1>  .RedFieldPosition: 	resb 1
 11155 00000023 ??                  <1>  .GreenMaskSize:	resb 1
 11156 00000024 ??                  <1>  .GreenFieldPosition: 	resb 1
 11157 00000025 ??                  <1>  .BlueMaskSize:		resb 1
 11158 00000026 ??                  <1>  .BlueFieldPosition: 	resb 1
 11159 00000027 ??                  <1>  .RsvdMaskSize:		resb 1
 11160 00000028 ??                  <1>  .RsvdFieldPosition: 	resb 1
 11161 00000029 ??                  <1>  .DirectColorModeInfo: 	resb 1
 11162 0000002A ????????            <1>  .PhysBasePtr:		resd 1
 11163 0000002E ????????            <1>  .OffScreenMemOffset: 	resd 1	; = 0
 11164 00000032 ????                <1>  .OffScreenMemSize: 	resw 1	; = 0
 11165 00000034 ????                <1>  .LinBytesPerScanLine: 	resw 1
 11166 00000036 ??                  <1>  .BnkNumberOfPages: 	resb 1
 11167 00000037 ??                  <1>  .LinNumberOfPages: 	resb 1
 11168 00000038 ??                  <1>  .LinRedMaskSize:	resb 1
 11169 00000039 ??                  <1>  .LinRedFieldPosition1: resb 1
 11170 0000003A ??                  <1>  .LinGreenMaskSize1: 	resb 1
 11171 0000003B ??                  <1>  .LinGreenFieldPosition:resb 1
 11172 0000003C ??                  <1>  .LinBlueMaskSize: 	resb 1
 11173 0000003D ??                  <1>  .LinBlueFieldPosition:	resb 1
 11174 0000003E ??                  <1>  .LinRsvdMaskSize: 	resb 1
 11175 0000003F ??                  <1>  .LinRsvdFieldPosition:	resb 1
 11176 00000040 ????????            <1>  .MaxPixelClock:	resd 1	; = 0
 11177                              <1> .size:
 11178                              <1> endstruc
 11179                              <1> 
 11180                              <1> ; 10/12/2020
 11181                              <1> struc LFBINFO
 11182 00000000 ????                <1>  .mode:			resw 1  ; 1XXh
 11183 00000002 ????????            <1>  .LFB_addr:		resd 1
 11184 00000006 ????????            <1>  .LFB_size:		resd 1
 11185 0000000A ????                <1>  .X_res:		resw 1
 11186 0000000C ????                <1>  .Y_res:		resw 1
 11187 0000000E ??                  <1>  .bpp:			resb 1
 11188 0000000F ??                  <1>  .reserved:		resb 1
 11189                              <1> .size:	; 16 bytes
 11190                              <1> endstruc
 11191                              <1> 
 11192                              <1> set_mode_info_list:
 11193                              <1> 	; 14/12/2020
 11194                              <1> 	; 11/12/2020
 11195                              <1> 	; 24/11/2020
 11196                              <1> 	; (vbetables-gen.c)
 11197                              <1> 	; Input:
 11198                              <1> 	;	BX = VBE mode (including bochs special modes) 
 11199                              <1> 	; Output:
 11200                              <1> 	;	;;EAX = MODE_INFO_LIST address
 11201                              <1> 	;	EAX = 0 ; 11/12/2020
 11202                              <1> 	;	ESI = MODE_INFO_LIST address ; 11/12/2020
 11203                              <1> 	;	(if mode is not found, ESI = 0)
 11204                              <1> 	;
 11205                              <1> 	; Modified registers: eax, ebx, ecx, edx, esi, edi 
 11206                              <1> 
 11207 00003F6E BE[6A6B0000]        <1> 	mov	esi, b_vbe_modes ; bochs mode info base table
 11208 00003F73 BF[4AA30100]        <1> 	mov	edi, MODE_INFO_LIST ; mode info list (4F01h)
 11209                              <1> sml_0:
 11210 00003F78 66AD                <1> 	lodsw	
 11211 00003F7A 6639D8              <1> 	cmp	ax, bx ; is mode number same ?
 11212 00003F7D 7410                <1> 	je	short sml_1 ; yes
 11213 00003F7F AD                  <1> 	lodsd
 11214 00003F80 66AD                <1> 	lodsw	
 11215 00003F82 81FE[2A6C0000]      <1> 	cmp	esi, end_of_b_vbe_modes
 11216 00003F88 72EE                <1> 	jb	short sml_0
 11217                              <1> 	; not found
 11218 00003F8A 31C0                <1> 	xor	eax, eax ; 0
 11219                              <1> 	; 11/12/2020
 11220 00003F8C 31F6                <1> 	xor	esi, esi
 11221 00003F8E C3                  <1> 	retn
 11222                              <1> sml_1:
 11223 00003F8F 66AB                <1> 	stosw	; mode
 11224 00003F91 AD                  <1> 	lodsd	; width, height
 11225                              <1> 	; 14/12/2020
 11226 00003F92 89C1                <1> 	mov	ecx, eax
 11227 00003F94 50                  <1> 	push	eax ; ***
 11228 00003F95 29C0                <1> 	sub	eax, eax ; clear high word of eax
 11229 00003F97 66AD                <1> 	lodsw	; depth
 11230 00003F99 50                  <1> 	push	eax ; **
 11231                              <1> 
 11232                              <1> 	;add	al, 7 ; only for 15 bit colors (not used here)
 11233 00003F9A C0E803              <1> 	shr	al, 3 ; / 8
 11234                              <1> 	; 14/12/2020
 11235 00003F9D 66F7E1              <1> 	mul	cx  ; pitch = width * ((depth+7)/8)
 11236                              <1> 		; ax = pitch
 11237 00003FA0 50                  <1> 	push	eax ; * ; high word of eax = 0
 11238 00003FA1 C1E910              <1> 	shr	ecx, 16
 11239                              <1> 	;mul	cx
 11240                              <1> 	;mov	cx, ax
 11241 00003FA4 31D2                <1> 	xor	edx, edx  ; clear high word of edx
 11242 00003FA6 F7E1                <1> 	mul	ecx ; height * pitch
 11243 00003FA8 89C1                <1> 	mov	ecx, eax
 11244 00003FAA B800000001          <1> 	mov	eax, VBE_DISPI_TOTAL_VIDEO_MEMORY_MB * 1024 * 1024
 11245 00003FAF F7F1                <1> 	div	ecx
 11246                              <1> 		; eax = pages = vram_size / (height*pitch)
 11247                              <1> 	
 11248                              <1> 	;mov	cx, ax
 11249 00003FB1 89C1                <1> 	mov	ecx, eax ; pages 
 11250                              <1> 		
 11251 00003FB3 66B89B00            <1> 	mov	ax, MODE_ATTRIBUTES
 11252 00003FB7 66AB                <1> 	stosw	; ModeAttributes
 11253 00003FB9 B007                <1> 	mov	al, WINA_ATTRIBUTES
 11254 00003FBB AA                  <1> 	stosb	; WinAAttributes
 11255 00003FBC 30C0                <1> 	xor	al, al ; WinBAttributes = 0
 11256 00003FBE AA                  <1> 	stosb
 11257 00003FBF 66B84000            <1> 	mov	ax, VBE_DISPI_BANK_SIZE_KB
 11258 00003FC3 66AB                <1> 	stosw	; WinGranularity
 11259 00003FC5 66AB                <1> 	stosw	; WinSize
 11260 00003FC7 66B800A0            <1> 	mov	ax, VGAMEM_GRAPH
 11261 00003FCB 66AB                <1> 	stosw	; WinASegment
 11262 00003FCD 29C0                <1> 	sub	eax, eax
 11263 00003FCF 66AB                <1> 	stosw	; WinBSegment = 0
 11264 00003FD1 AB                  <1> 	stosd	; WinFuncPtr = 0
 11265                              <1> 
 11266 00003FD2 58                  <1> 	pop	eax ; * ; pitch
 11267 00003FD3 89C3                <1> 	mov	ebx, eax  ; high word of ebx = 0 ; 14/12/2020
 11268 00003FD5 66AB                <1> 	stosw	; BytesPerScanLine
 11269                              <1> 
 11270 00003FD7 5A                  <1> 	pop	edx ; ** ; depth (bits per pixel)
 11271 00003FD8 58                  <1> 	pop	eax ; *** width, height
 11272                              <1> 
 11273                              <1>  	; // Mandatory information for VBE 1.2 and above
 11274                              <1> 
 11275 00003FD9 66AB                <1> 	stosw	; XResolution (width)
 11276 00003FDB C1E810              <1> 	shr	eax, 16
 11277 00003FDE 50                  <1> 	push	eax ; **** height
 11278 00003FDF 66AB                <1> 	stosw	; YResolution (height)
 11279 00003FE1 B008                <1> 	mov	al, 8
 11280 00003FE3 AA                  <1>  	stosb	; XCharSize  ; char width
 11281 00003FE4 B010                <1> 	mov	al, 16
 11282 00003FE6 AA                  <1> 	stosb	; YCharSize  ; char height
 11283 00003FE7 B001                <1> 	mov	al, 1
 11284 00003FE9 AA                  <1> 	stosb	; NumberOfPlanes
 11285                              <1> 	;movzx	eax, dl
 11286 00003FEA 88D0                <1> 	mov	al, dl ; eax <= 32
 11287 00003FEC AA                  <1> 	stosb	; BitsPerPixel
 11288                              <1> 	; Number of banks = (height * pitch + 65535) / 65536
 11289 00003FED 58                  <1> 	pop	eax ; **** ; height
 11290                              <1> 	; 14/12/2020
 11291 00003FEE 52                  <1> 	push	edx ; ***** ; depth ; edx <= 32
 11292 00003FEF F7E3                <1> 	mul	ebx  ; pitch (ebx) * height (eax)
 11293                              <1> 	;mov	edx, [esp] ; *****
 11294                              <1> 	;mov	dl, [esp] ; *****
 11295 00003FF1 05FFFF0000          <1> 	add	eax, 65535
 11296 00003FF6 C1E810              <1> 	shr	eax, 16 ; / 65536 ; <= 127 ; 14/12/2020
 11297 00003FF9 AA                  <1> 	stosb	; NumberOfBanks
 11298                              <1> 	; 14/12/2020
 11299                              <1> 	;cmp	dl, 8 ; 8 bits per pixel
 11300 00003FFA 803C2408            <1> 	cmp	byte [esp], 8
 11301 00003FFE 7704                <1> 	ja	short sml_2
 11302 00004000 B004                <1> 	mov	al, VBE_MEMORYMODEL_PACKED_PIXEL
 11303 00004002 EB02                <1> 	jmp	short sml_3
 11304                              <1> sml_2:
 11305                              <1> 	; 16, 24, 32 bits per pixel
 11306 00004004 B006                <1> 	mov	al, VBE_MEMORYMODEL_DIRECT_COLOR
 11307                              <1> sml_3:
 11308 00004006 AA                  <1> 	stosb
 11309 00004007 30C0                <1> 	xor	al, al ; 0
 11310 00004009 AA                  <1> 	stosb	; BankSize = 0
 11311 0000400A 49                  <1> 	dec	ecx ; pages - 1
 11312                              <1> 	; NumberOfImagePages = 262 for 320x200x8 mode
 11313                              <1> 	;;mov	ax, 255
 11314                              <1> 	; 14/12/2020
 11315                              <1> 	;mov	al, 255
 11316 0000400B FEC8                <1> 	dec	al ; 255
 11317 0000400D 39C1                <1> 	cmp	ecx, eax ; ecx <= 261, eax = 255 
 11318                              <1> 	;cmp	cx, ax
 11319 0000400F 7302                <1> 	jnb	short sml_4
 11320 00004011 88C8                <1> 	mov	al, cl	 
 11321                              <1> sml_4:
 11322 00004013 AA                  <1> 	stosb	; NumberOfImagePages (1 byte)
 11323 00004014 28C0                <1> 	sub	al, al
 11324 00004016 AA                  <1> 	stosb	; Reserved_page = 0
 11325 00004017 58                  <1> 	pop	eax ; ***** ; depth
 11326 00004018 88C1                <1> 	mov	cl, al
 11327                              <1> 	; eax < = 32
 11328 0000401A 2C08                <1> 	sub	al, 8 ; 8->0, 16->8, 24->16, 32->24
 11329 0000401C BE[2A6C0000]        <1> 	mov	esi, direct_color_fields
 11330 00004021 01C6                <1> 	add	esi, eax
 11331 00004023 56                  <1> 	push	esi ; ******
 11332 00004024 AD                  <1> 	lodsd	; RedMaskSize (AL), RedFieldPosition (AH)
 11333                              <1> 	     	; GreenMaskSize (16), GreenFieldPosition (24)
 11334 00004025 AB                  <1> 	stosd
 11335 00004026 AD                  <1> 	lodsd	; BlueMaskSize (AL), BlueFieldPosition (AH)
 11336                              <1> 	     	; RsvdMaskSize (16), RsvdFieldPosition (24)
 11337 00004027 AB                  <1> 	stosd
 11338 00004028 5E                  <1> 	pop	esi ; ******
 11339                              <1> 
 11340 00004029 30C0                <1> 	xor	al, al ; 0
 11341 0000402B 80F920              <1> 	cmp	cl, 32
 11342 0000402E 7202                <1> 	jb	short sml_5
 11343 00004030 B002                <1> 	mov	al, VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE
 11344                              <1> sml_5: 
 11345 00004032 AA                  <1> 	stosb	; DirectColorModeInfo
 11346                              <1> 
 11347                              <1> 	; // Mandatory information for VBE 2.0 and above
 11348                              <1> 
 11349 00004033 B8000000E0          <1> 	mov	eax, VBE_DISPI_LFB_PHYSICAL_ADDRESS
 11350 00004038 AB                  <1> 	stosd	; PhysBasePtr
 11351 00004039 29C0                <1> 	sub	eax, eax
 11352 0000403B AB                  <1> 	stosd	; OffScreenMemOffset = 0
 11353 0000403C 66AB                <1> 	stosw	; OffScreenMemSize = 0
 11354                              <1> 
 11355                              <1> 	;// Mandatory information for VBE 3.0 and above
 11356                              <1> 
 11357                              <1> 	; ebx = pitch
 11358 0000403E 6689D8              <1> 	mov	ax, bx
 11359                              <1> 	;stosw
 11360                              <1> 
 11361                              <1> 	;xor	al, al
 11362                              <1>      	;stosb	; BnkNumberOfPages = 0
 11363                              <1>      	;stosb	; LinNumberOfPages = 0
 11364                              <1> 
 11365 00004041 AB                  <1> 	stosd	; pitch (word), 0 (byte), 0 (byte)  
 11366                              <1> 
 11367 00004042 AD                  <1> 	lodsd	; LinRedMaskSize (AL), LinRedFieldPosition (AH)
 11368                              <1> 	     	; LinGreenMaskSize (16), LinGreenFieldPosition (24)
 11369 00004043 AB                  <1> 	stosd
 11370 00004044 AD                  <1> 	lodsd	; LinBlueMaskSize (AL), LinBlueFieldPosition (AH)
 11371                              <1> 	     	; LinRsvdMaskSize (16), LinRsvdFieldPosition (24)
 11372 00004045 AB                  <1> 	stosd
 11373                              <1> 
 11374 00004046 29C0                <1> 	sub	eax, eax
 11375 00004048 AB                  <1> 	stosd	; MaxPixelClock = 0
 11376                              <1> 
 11377                              <1> 	;mov	eax, MODE_INFO_LIST
 11378                              <1> 	; 11/12/2020
 11379 00004049 BE[4AA30100]        <1> 	mov	esi, MODE_INFO_LIST
 11380                              <1> 	
 11381 0000404E C3                  <1> 	retn	
 11382                              <1> 
 11383                              <1> ; end of set_mode_info_list ; edi = set_mode_info_list + 68
 11384                              <1> 
 11385                              <1> pci_get_lfb_addr:
 11386                              <1> 	; 11/12/2020
 11387                              <1> 	; Get linear frame buffer base from PCI
 11388                              <1> 	; (vgabios.c, 02/01/2020, vruppert)
 11389                              <1> 	;
 11390                              <1> 	; Input:
 11391                              <1> 	;	ax = PCI device vendor id
 11392                              <1> 	; Output:
 11393                              <1> 	;	ax  = LFB address (high 16 bit) (zf=0)
 11394                              <1> 	;	eax = 0 -> not found (error) (zf=1)
 11395                              <1> 	;
 11396                              <1> 	; Modified registers: eax
 11397                              <1> 
 11398 0000404F 53                  <1> 	push	ebx
 11399 00004050 51                  <1> 	push	ecx
 11400 00004051 52                  <1> 	push	edx
 11401                              <1> 	;
 11402 00004052 89C3                <1> 	mov	ebx, eax
 11403 00004054 31C9                <1> 	xor	ecx, ecx
 11404 00004056 28D2                <1> 	sub	dl, dl	; mov dl, 0
 11405 00004058 E842000000          <1> 	call	pci_read_reg
 11406 0000405D 6683F8FF            <1> 	cmp	ax, 0FFFFh
 11407 00004061 7417                <1> 	je	short pci_get_lfb_addr_fail
 11408                              <1> pci_get_lfb_addr_next_dev:
 11409 00004063 28D2                <1> 	sub	dl, dl ; mov dl, 0
 11410 00004065 E835000000          <1> 	call	pci_read_reg
 11411 0000406A 6639D8              <1> 	cmp	ax, bx	; check vendor
 11412 0000406D 740F                <1> 	je	short pci_get_lfb_addr_found
 11413 0000406F 6683C108            <1> 	add	cx, 08h
 11414 00004073 6681F90002          <1> 	cmp	cx, 200h ; search bus 0 and 1
 11415 00004078 72E9                <1> 	jb	short pci_get_lfb_addr_next_dev
 11416                              <1> pci_get_lfb_addr_fail:
 11417 0000407A 31C0                <1> 	xor	eax, eax ; no LFB
 11418                              <1> 	; zf = 1
 11419 0000407C EB1D                <1> 	jmp	short pci_get_lfb_addr_return
 11420                              <1> pci_get_lfb_addr_found:
 11421 0000407E B210                <1> 	mov	dl, 10h	; I/O space 0
 11422 00004080 E81A000000          <1> 	call	pci_read_reg
 11423 00004085 66A9F1FF            <1> 	test	ax, 0FFF1h
 11424 00004089 740D                <1> 	jz	short pci_get_lfb_addr_success
 11425 0000408B B214                <1> 	mov	dl, 14h ; I/O space 1
 11426 0000408D E80D000000          <1> 	call	pci_read_reg
 11427 00004092 66A9F1FF            <1> 	test	ax, 0FFF1h
 11428 00004096 75E2                <1> 	jnz	short pci_get_lfb_addr_fail
 11429                              <1> pci_get_lfb_addr_success:
 11430 00004098 C1E810              <1> 	shr	eax, 16 ; LFB address (hw)
 11431                              <1> 	; zf = 0
 11432                              <1> pci_get_lfb_addr_return:
 11433 0000409B 5A                  <1> 	pop	edx
 11434 0000409C 59                  <1> 	pop	ecx
 11435 0000409D 5B                  <1> 	pop	ebx
 11436 0000409E C3                  <1> 	retn
 11437                              <1> 
 11438                              <1> pci_read_reg:
 11439                              <1> 	; 11/12/2020
 11440                              <1> 	; Read PCI register
 11441                              <1> 	; (vgabios.c, 02/01/2020, vruppert)
 11442                              <1> 	;
 11443                              <1> 	; Input:
 11444                              <1> 	;	cx = device/function
 11445                              <1> 	;	dl = register
 11446                              <1> 	; Output:
 11447                              <1> 	;	eax = value
 11448                              <1> 	;
 11449                              <1> 	; Modified registers: eax, edx
 11450                              <1> 
 11451 0000409F B800008000          <1> 	mov	eax, 00800000h 
 11452 000040A4 6689C8              <1> 	mov	ax, cx
 11453 000040A7 C1E008              <1> 	shl	eax, 8
 11454 000040AA 88D0                <1> 	mov	al, dl
 11455 000040AC 66BAF80C            <1> 	mov	dx, 0CF8h
 11456 000040B0 EF                  <1>  	out	dx, eax
 11457 000040B1 80C204              <1> 	add	dl, 4 ; mov dx, 0CFCh
 11458 000040B4 ED                  <1> 	in	eax, dx
 11459 000040B5 C3                  <1> 	retn
 11460                              <1> 
 11461                              <1> %endif
 11462                              <1> 
 11463                              <1> ; -----------
 11464                              <1> 
 11465                              <1> %if 0
 11466                              <1> 
 11467                              <1> mode_info_find_mode:
 11468                              <1> 	; 25/11/2020
 11469                              <1> 	; Input:
 11470                              <1> 	;	bx = VESA VBE2 video mode (+ bochs extensions)
 11471                              <1> 	; Output:
 11472                              <1> 	;	esi = mode info address (for BX input)
 11473                              <1> 	;	esi = 0 -> not found
 11474                              <1> 	;
 11475                              <1> 	; Modified registers: eax, esi
 11476                              <1> 
 11477                              <1> 	xor	eax, eax
 11478                              <1> 	mov	esi, MODE_INFO_LIST
 11479                              <1> mifm_1:
 11480                              <1> 	mov	ax, [esi]
 11481                              <1> 	cmp	ax, bx
 11482                              <1> 	je	short mifm_2
 11483                              <1> 	add	esi, MODEINFO.size ; add esi, 68
 11484                              <1> 	cmp	esi, VBE_VESA_MODE_END_OF_LIST
 11485                              <1> 	jb	short mifm_1
 11486                              <1> 	; not found
 11487                              <1> 	sub	esi, esi ; 0
 11488                              <1> mifm_2
 11489                              <1> 	retn
 11490                              <1> 
 11491                              <1> dispi_get_bpp:
 11492                              <1> 	; 28/11/2020
 11493                              <1> 	; Input:
 11494                              <1> 	;	none
 11495                              <1> 	; Output:
 11496                              <1> 	;	al = Bits per pixel
 11497                              <1> 	;	     (8,16,24,32)
 11498                              <1> 	;	ah = Bytes per pixel
 11499                              <1> 	;	     (1,2,3,4)	
 11500                              <1> 	;
 11501                              <1> 	; Modified registers: none
 11502                              <1> 
 11503                              <1> 	;push	edx
 11504                              <1> 	;mov	dx, 01CEh ; VBE_DISPI_IOPORT_INDEX
 11505                              <1> 	;mov	ax, 03h	  ; VBE_DISPI_INDEX_BPP
 11506                              <1> 	;out	dx, ax
 11507                              <1> 	;;mov	dx, 01CFh ; VBE_DISPI_IOPORT_DATA
 11508                              <1> 	;;mov	dl, 0CFh
 11509                              <1> 	;inc	dl
 11510                              <1> 	;in	ax, dx
 11511                              <1> 	;mov	ah, al
 11512                              <1> 	;shr	ah, 3 ; / 8
 11513                              <1> 	;;test	al, 7 ; 15 bit graphics mode
 11514                              <1>  	;;jz	short get_bpp_noinc
 11515                              <1> 	;;inc	ah
 11516                              <1> ;;get_bpp_noinc:
 11517                              <1> 	;pop	edx
 11518                              <1> 	;retn
 11519                              <1> 
 11520                              <1> 	; 28/11/2020
 11521                              <1> 	; Modified registers: edx
 11522                              <1> 	;push	edx
 11523                              <1> 	mov	dx, 03h ; VBE_DISPI_INDEX_BPP
 11524                              <1> 	call	dispi_get_parms
 11525                              <1> 	;pop	edx
 11526                              <1> 	;retn
 11527                              <1> 	mov	ah, al
 11528                              <1> 	shr	ah, 3 ; / 8
 11529                              <1> 	;test	al, 7 ; 15 bit graphips mode
 11530                              <1>  	;jz	short get_bpp_noinc
 11531                              <1> 	;inc	ah
 11532                              <1> ;get_bpp_noinc:
 11533                              <1> 	;pop	edx
 11534                              <1> 	retn
 11535                              <1> 
 11536                              <1> restore_vesa_video_state:
 11537                              <1> 	; 02/08/2022 (TRDOS 386 v2.0.5)
 11538                              <1> 	; 14/01/2021
 11539                              <1> 	; 06/12/2020
 11540                              <1> 	; Input:
 11541                              <1> 	;	[vbe3stbufsize] <= 32 ; <= 32*64 bytes
 11542                              <1> 	; Output:
 11543                              <1> 	;	AX = 004Fh (successed)
 11544                              <1> 	;
 11545                              <1> 	;	eax = 0 -> buffer size problem
 11546                              <1> 	;	eax > 0 and ax <> 004Fh -> failed
 11547                              <1> 	;
 11548                              <1> 	; Modified regs: eax, ebx, ecx, edx, esi, edi 
 11549                              <1> 
 11550                              <1> 	;movzx	ecx, word [vbe3stbufsize]  
 11551                              <1> 	;cmp	cx, 32 ; 32 * 64 bytes
 11552                              <1> 	;ja	short r_v_b_s_fail
 11553                              <1> 
 11554                              <1> 	movzx	ecx, byte [vbe3stbufsize]; <=32	
 11555                              <1> 	;shl	cx, 4 ; dword count for movsd
 11556                              <1> 	; 02/08/2022
 11557                              <1> 	shl	ecx, 4 ; <= 32*16 dwords (32*64 bytes)
 11558                              <1> 	mov	edi, VBE3SAVERESTOREBLOCK ; destination
 11559                              <1> 					; (vbe3 pmi buff)
 11560                              <1> 	mov	esi, VBE3VIDEOSTATE ; source (kernel buff)
 11561                              <1> 	rep	movsd
 11562                              <1> 
 11563                              <1> 	mov	ax, 4F04h
 11564                              <1> 	mov	dl, 02h ; restore
 11565                              <1> 	;mov	cx, 0Fh
 11566                              <1> 	mov	cl, 0Fh
 11567                              <1> 	xor 	ebx, ebx ; points to VBE3SAVERESTOREBLOCK
 11568                              <1> 	jmp	short int10h_32bit_pmi
 11569                              <1> 
 11570                              <1> ;s_v_b_s_fail:
 11571                              <1> ;r_v_b_s_fail:
 11572                              <1> ;	xor	eax, eax
 11573                              <1> ;	retn
 11574                              <1> 
 11575                              <1> save_vesa_video_state:
 11576                              <1> 	; 02/08/2022 (TRDOS 386 v2.0.5)
 11577                              <1> 	; 14/01/2021
 11578                              <1> 	; 06/12/2020
 11579                              <1> 	; Input:
 11580                              <1> 	;	[vbe3stbufsize] <= 32 ; <= 32*64 bytes
 11581                              <1> 	; Output:
 11582                              <1> 	;	AX = 004Fh (successed)
 11583                              <1> 	;
 11584                              <1> 	;	eax = 0 -> buffer size problem
 11585                              <1> 	;	eax > 0 and ax <> 004Fh -> failed
 11586                              <1> 	;
 11587                              <1> 	; Modified regs: eax, ebx, ecx, edx, esi, edi 
 11588                              <1> 
 11589                              <1> 	;cmp	word [vbe33stbufsize], 32  
 11590                              <1> 	;			; 32 * 64 bytes
 11591                              <1> 	;ja	short s_v_b_s_fail
 11592                              <1> 
 11593                              <1> 	mov	ax, 4F04h
 11594                              <1> 	mov	dl, 01h ; save
 11595                              <1> 	;mov	cx, 0Fh
 11596                              <1> 	mov	cl, 0Fh
 11597                              <1> 	xor 	ebx, ebx ; points to VBE3SAVERESTOREBLOCK
 11598                              <1> 
 11599                              <1> 	call	int10h_32bit_pmi
 11600                              <1> 
 11601                              <1> 	movzx	ecx, byte [vbe3stbufsize]; <=32	
 11602                              <1> 	;shl	cx, 4 ; dword count for movsd
 11603                              <1> 	; 02/08/2022
 11604                              <1> 	shl	ecx, 4 ; <= 32*16 dwords (32*64 bytes)
 11605                              <1> 	mov	esi, VBE3SAVERESTOREBLOCK ; destination
 11606                              <1> 					; (vbe3 pmi buff)
 11607                              <1> 	mov	edi, VBE3VIDEOSTATE ; source (kernel buff)
 11608                              <1> 	rep	movsd	
 11609                              <1> 	retn
 11610                              <1> 
 11611                              <1> dispi_set_bank_farcall:
 11612                              <1> 	; 03/08/2022
 11613                              <1> 	; 12/04/2021 (32 bit push/pop)
 11614                              <1> 	; 11/12/2020
 11615                              <1> 	; (This may be 'sysvideo' function, later)
 11616                              <1> 	;
 11617                              <1> 	; Input: 
 11618                              <1> 	;	bx = 0000h, set bank number
 11619                              <1> 	;	   = 0100h, get bank number
 11620                              <1> 	;	dx = bank number (if bx = 0)	
 11621                              <1> 	; Output:
 11622                              <1> 	;	dx = bank number
 11623                              <1> 		 	
 11624                              <1> 	cmp	bx, 0100h
 11625                              <1> 	je	short dispi_set_bank_farcall_get
 11626                              <1> 	or	bx, bx
 11627                              <1> 	;jnz	dispi_set_bank_farcall_error
 11628                              <1> 	; 03/08/2022
 11629                              <1> 	jz	short dsbfcall_1
 11630                              <1> 	jmp	dispi_set_bank_farcall_error
 11631                              <1> dsbfcall_1:
 11632                              <1> 	mov	ax, dx
 11633                              <1> 	;push	dx
 11634                              <1> 	;push	ax
 11635                              <1> 	; 12/04/2021
 11636                              <1> 	push	edx
 11637                              <1> 	push	eax
 11638                              <1> 	mov	ax, VBE_DISPI_INDEX_BANK
 11639                              <1> 	mov	dx, 1CEh ; VBE_DISPI_IOPORT_INDEX
 11640                              <1> 	out	dx, ax
 11641                              <1> 	;pop	ax
 11642                              <1> 	; 12/04/2021
 11643                              <1> 	pop	eax
 11644                              <1> 	;;mov	dx, VBE_DISPI_IOPORT_DATA
 11645                              <1> 	;mov	dl, 0CFh
 11646                              <1> 	inc	dl ; 1CFh = VBE_DISPI_IOPORT_DATA
 11647                              <1> 	out	dx, ax
 11648                              <1> 	in	ax, dx
 11649                              <1> 	;pop	dx
 11650                              <1> 	; 12/04/2021
 11651                              <1> 	pop	edx
 11652                              <1> 	cmp	dx, ax
 11653                              <1> 	jne	short dispi_set_bank_farcall_error
 11654                              <1> 	mov	ax, 004Fh
 11655                              <1> 	retn	; retf for real mode far call
 11656                              <1> dispi_set_bank_farcall_get:
 11657                              <1> 	mov	ax, VBE_DISPI_INDEX_BANK
 11658                              <1> 	; 03/08/2022
 11659                              <1> 	mov	dx, 1CEh ; VBE_DISPI_IOPORT_INDEX
 11660                              <1> 	out	dx, ax
 11661                              <1> 	;;mov	dx, VBE_DISPI_IOPORT_DATA
 11662                              <1> 	;mov	dl, 0CFh
 11663                              <1> 	; 03/08/2022
 11664                              <1> 	inc	dl ; 1CFh = VBE_DISPI_IOPORT_DATA
 11665                              <1> 	in	ax, dx
 11666                              <1> 	mov	dx, ax
 11667                              <1> 	retn	; retf for real mode far call
 11668                              <1> dispi_set_bank_farcall_error:
 11669                              <1> 	mov	ax, 014Fh
 11670                              <1> 	retn	; retf for real mode far call
 11671                              <1> 
 11672                              <1> %endif
 11673                              <1> 
 11674                              <1> ; % include 'vidata.s' ; VIDEO DATA
 11675                              <1> 
 11676                              <1> ; /// End Of VIDEO FUNCTIONS ///
  2989                                  
  2990                                  setup_rtc_int:
  2991                                  ; source: http://wiki.osdev.org/RTC
  2992 000040B6 FA                      	cli		; disable interrupts
  2993                                  	; default int frequency is 1024 Hz (Lower 4 bits of register A is 0110b or 6)
  2994                                  	; in order to change this ...
  2995                                  	; frequency  = 32768 >> (rate-1) --> 32768 >> 5 = 1024
  2996                                  	; (rate must be above 2 and not over 15)
  2997                                  	; new rate = 15 --> 32768 >> (15-1) = 2 Hz
  2998 000040B7 B08A                    	mov	al, 8Ah 
  2999 000040B9 E670                    	out	70h, al ; set index to register A, disable NMI
  3000 000040BB 90                      	nop
  3001 000040BC E471                    	in	al, 71h ; get initial value of register A
  3002 000040BE 88C4                    	mov 	ah, al
  3003 000040C0 80E4F0                  	and	ah, 0F0h
  3004 000040C3 B08A                    	mov	al, 8Ah 
  3005 000040C5 E670                    	out	70h, al ; reset index to register A
  3006 000040C7 88E0                    	mov	al, ah
  3007 000040C9 0C0F                    	or	al, 0Fh	; new rate (0Fh -> 15)
  3008 000040CB E671                    	out	71h, al ; write only our rate to A. Note, rate is the bottom 4 bits. 
  3009                                  	; enable RTC interrupt
  3010 000040CD B08B                    	mov	al, 8Bh ;
  3011 000040CF E670                    	out	70h, al ; select register B and disable NMI
  3012 000040D1 90                      	nop
  3013 000040D2 E471                    	in	al, 71h ; read the current value of register B
  3014 000040D4 88C4                    	mov	ah, al  ;
  3015 000040D6 B08B                    	mov 	al, 8Bh ;
  3016 000040D8 E670                    	out	70h, al ; set the index again (a read will reset the index to register B)	
  3017 000040DA 88E0                    	mov	al, ah  ;
  3018 000040DC 0C40                    	or	al, 40h ;
  3019 000040DE E671                    	out	71h, al ; write the previous value ORed with 0x40. This turns on bit 6 of register B
  3020 000040E0 FB                      	sti
  3021 000040E1 C3                      	retn
  3022                                  
  3023                                  ; Write memory information
  3024                                  ; 29/01/2016
  3025                                  ; 06/11/2014
  3026                                  ; 14/08/2015 
  3027                                  memory_info:	
  3028 000040E2 A1[C47C0100]            	mov	eax, [memory_size] ; in pages
  3029 000040E7 50                      	push	eax
  3030 000040E8 C1E00C                  	shl	eax, 12		   ; in bytes
  3031 000040EB BB0A000000              	mov	ebx, 10
  3032 000040F0 89D9                    	mov	ecx, ebx	   ; 10
  3033 000040F2 BE[813E0100]            	mov	esi, mem_total_b_str	
  3034 000040F7 E8D8000000              	call	bintdstr
  3035 000040FC 58                      	pop	eax
  3036 000040FD B107                    	mov	cl, 7
  3037 000040FF BE[A53E0100]            	mov	esi, mem_total_p_str
  3038 00004104 E8CB000000              	call	bintdstr	
  3039                                  	; 14/08/2015
  3040 00004109 E8E3000000              	call	calc_free_mem
  3041                                  	; edx = calculated free pages
  3042                                  	; ecx = 0
  3043 0000410E A1[C87C0100]            	mov 	eax, [free_pages]
  3044 00004113 39D0                    	cmp	eax, edx ; calculated free mem value 
  3045                                  		; and initial free mem value are same or not?
  3046 00004115 751D                    	jne 	short pmim ; print mem info with '?' if not
  3047 00004117 52                      	push 	edx ; free memory in pages	
  3048                                  	;mov 	eax, edx
  3049 00004118 C1E00C                  	shl	eax, 12 ; convert page count
  3050                                  			; to byte count
  3051 0000411B B10A                    	mov	cl, 10
  3052 0000411D BE[C53E0100]            	mov	esi, free_mem_b_str
  3053 00004122 E8AD000000              	call	bintdstr
  3054 00004127 58                      	pop	eax
  3055 00004128 B107                    	mov	cl, 7
  3056 0000412A BE[E93E0100]            	mov	esi, free_mem_p_str
  3057 0000412F E8A0000000              	call	bintdstr
  3058                                  pmim:
  3059 00004134 BE[6F3E0100]            	mov	esi, msg_memory_info
  3060                                  	;
  3061 00004139 B407                    	mov	ah, 07h ; Black background, 
  3062                                  			; light gray forecolor
  3063                                  print_kmsg: ; 29/01/2016
  3064 0000413B 8825[EF7C0100]          	mov	[ccolor], ah
  3065                                  pkmsg_loop:
  3066 00004141 AC                      	lodsb
  3067 00004142 08C0                    	or	al, al
  3068 00004144 7410                    	jz	short pkmsg_ok
  3069 00004146 56                      	push	esi
  3070                                  	; 13/05/2016
  3071 00004147 0FB61D[EF7C0100]        	movzx	ebx, byte [ccolor]
  3072                                  			; Video page 0 (bh=0)
  3073 0000414E E842E1FFFF              	call	_write_tty
  3074 00004153 5E                      	pop	esi
  3075 00004154 EBEB                    	jmp	short pkmsg_loop
  3076                                  pkmsg_ok:
  3077 00004156 C3                      	retn
  3078                                  
  3079                                  ; 19/12/2020
  3080                                  ; temporary
  3081                                  ; Write default liner frame buffer address
  3082                                  ;
  3083                                  default_lfb_info:	
  3084 00004157 66A1[1A0F0000]          	mov	ax, [def_LFB_addr] ; high word
  3085                                  	; 24/11/2023 - temporary
  3086 0000415D 6609C0                  	or	ax, ax
  3087 00004160 74F4                    	jz	short pkmsg_ok
  3088 00004162 E829000000              	call	wordtohex
  3089 00004167 A3[413F0100]            	mov	dword [lfb_addr_str], eax
  3090 0000416C BE[2A3F0100]            	mov	esi, msg_lfb_addr
  3091 00004171 B40F                    	mov	ah, 0Fh ; Black background, 
  3092                                  			; white forecolor
  3093 00004173 EBC6                    	jmp	short print_kmsg
  3094                                  
  3095                                  ; Convert binary number to hexadecimal string
  3096                                  ; 10/05/2015  
  3097                                  ; dsectpm.s (28/02/2015)
  3098                                  ; Retro UNIX 386 v1 - Kernel v0.2.0.6  
  3099                                  ; 01/12/2014
  3100                                  ; 25/11/2014
  3101                                  ;
  3102                                  bytetohex:
  3103                                  	; INPUT ->
  3104                                  	; 	AL = byte (binary number)
  3105                                  	; OUTPUT ->
  3106                                  	;	AX = hexadecimal string
  3107                                  	;
  3108 00004175 53                      	push	ebx
  3109 00004176 31DB                    	xor	ebx, ebx
  3110 00004178 88C3                    	mov	bl, al
  3111 0000417A C0EB04                  	shr	bl, 4
  3112 0000417D 8A9B[C3410000]          	mov	bl, [ebx+hexchrs] 	 	
  3113 00004183 86C3                    	xchg	bl, al
  3114 00004185 80E30F                  	and	bl, 0Fh
  3115 00004188 8AA3[C3410000]          	mov	ah, [ebx+hexchrs] 
  3116 0000418E 5B                      	pop	ebx	
  3117 0000418F C3                      	retn
  3118                                  
  3119                                  wordtohex:
  3120                                  	; INPUT ->
  3121                                  	; 	AX = word (binary number)
  3122                                  	; OUTPUT ->
  3123                                  	;	EAX = hexadecimal string
  3124                                  	;
  3125 00004190 53                      	push	ebx
  3126 00004191 31DB                    	xor	ebx, ebx
  3127 00004193 86C4                    	xchg	ah, al
  3128 00004195 6650                    	push	ax ; * save ax
  3129 00004197 88E3                    	mov	bl, ah
  3130 00004199 C0EB04                  	shr	bl, 4
  3131 0000419C 8A83[C3410000]          	mov	al, [ebx+hexchrs]
  3132 000041A2 88E3                    	mov	bl, ah
  3133 000041A4 80E30F                  	and	bl, 0Fh
  3134 000041A7 8AA3[C3410000]          	mov	ah, [ebx+hexchrs]
  3135 000041AD C1E010                  	shl	eax, 16 ; ax -> hw of eax
  3136 000041B0 6658                    	pop	ax ; * restore ax 
  3137 000041B2 5B                      	pop	ebx
  3138 000041B3 EBC0                    	jmp	short bytetohex
  3139                                  	;mov	bl, al
  3140                                  	;shr	bl, 4
  3141                                  	;mov	bl, [ebx+hexchrs]
  3142                                  	;xchg	bl, al	 	
  3143                                  	;and	bl, 0Fh
  3144                                  	;mov	ah, [ebx+hexchrs] 
  3145                                  	;pop	ebx	
  3146                                  	;retn
  3147                                  
  3148                                  dwordtohex:
  3149                                  	; INPUT ->
  3150                                  	; 	EAX = dword (binary number)
  3151                                  	; OUTPUT ->
  3152                                  	;	EDX:EAX = hexadecimal string
  3153                                  	;
  3154 000041B5 50                      	push	eax
  3155 000041B6 C1E810                  	shr	eax, 16
  3156 000041B9 E8D2FFFFFF              	call	wordtohex
  3157 000041BE 89C2                    	mov	edx, eax
  3158 000041C0 58                      	pop	eax
  3159                                  	;call	wordtohex
  3160                                  	;retn
  3161                                  	; 18/04/2021
  3162 000041C1 EBCD                    	jmp	short wordtohex
  3163                                  
  3164                                  ; 10/05/2015
  3165                                  hex_digits:
  3166                                  hexchrs:
  3167 000041C3 303132333435363738-     	db '0123456789ABCDEF'
  3167 000041CC 39414243444546     
  3168                                  ; 19/01/2021 - VESA EDID ready flag (4Fh)
  3169 000041D3 00                      edid:	db 0
  3170                                  
  3171                                  ; Convert binary number to decimal/numeric string
  3172                                  ; 06/11/2014
  3173                                  ; Temporary Code
  3174                                  ;
  3175                                  
  3176                                  bintdstr:
  3177                                  	; EAX = binary number
  3178                                  	; ESI = decimal/numeric string address
  3179                                  	; EBX = divisor (10)
  3180                                  	; ECX = string length (<=10)
  3181 000041D4 01CE                    	add	esi, ecx
  3182                                  btdstr0:
  3183 000041D6 4E                      	dec	esi
  3184 000041D7 31D2                    	xor	edx, edx
  3185 000041D9 F7F3                    	div	ebx
  3186 000041DB 80C230                  	add	dl, 30h
  3187 000041DE 8816                    	mov	[esi], dl
  3188 000041E0 FEC9                    	dec	cl
  3189 000041E2 740C                    	jz	short btdstr2 ; 08/09/2016
  3190 000041E4 09C0                    	or	eax, eax
  3191 000041E6 75EE                    	jnz	short btdstr0
  3192                                  btdstr1:
  3193 000041E8 4E                      	dec	esi
  3194 000041E9 C60620                          mov     byte [esi], 20h ; blank space
  3195 000041EC FEC9                    	dec	cl
  3196 000041EE 75F8                    	jnz	short btdstr1
  3197                                  btdstr2:
  3198 000041F0 C3                      	retn
  3199                                  
  3200                                  ; Calculate free memory pages on M.A.T.
  3201                                  ; 06/11/2014
  3202                                  ; Temporary Code
  3203                                  ;
  3204                                  
  3205                                  calc_free_mem:
  3206 000041F1 31D2                    	xor	edx, edx
  3207                                  	;xor	ecx, ecx
  3208 000041F3 668B0D[D87C0100]        	mov	cx, [mat_size] ; in pages
  3209 000041FA C1E10A                  	shl	ecx, 10	; 1024 dwords per page
  3210 000041FD BE00001000              	mov	esi, MEM_ALLOC_TBL
  3211                                  cfm0:
  3212 00004202 AD                      	lodsd
  3213 00004203 51                      	push	ecx
  3214 00004204 B920000000              	mov	ecx, 32
  3215                                  cfm1:
  3216 00004209 D1E8                    	shr	eax, 1
  3217 0000420B 7301                    	jnc	short cfm2
  3218 0000420D 42                      	inc	edx
  3219                                  cfm2:
  3220 0000420E E2F9                    	loop	cfm1
  3221 00004210 59                      	pop	ecx
  3222 00004211 E2EF                    	loop	cfm0
  3223 00004213 C3                      	retn
  3224                                  
  3225                                  %include 'diskio.s'  ; 07/03/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.8 - diskio.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 23/06/2024 (Previous: 02/12/2023 - Kernel v2.0.7)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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> ; Ref: Retro UNIX 386 v1.1 (Kernel v0.2.1.5) 'diskio' modification: 12/07/2022
    19                              <1> 
    20                              <1> ; Retro UNIX 386 v1 Kernel - DISKIO.INC
    21                              <1> ; Last Modification: 22/08/2015
    22                              <1> ; 	(Initialized Disk Parameters Data is in 'DISKDATA.INC') 
    23                              <1> ; 	(Uninitialized Disk Parameters Data is in 'DISKBSS.INC') 
    24                              <1> 
    25                              <1> ; DISK I/O SYSTEM - Erdogan Tan (Retro UNIX 386 v1 project)
    26                              <1> 
    27                              <1> ; ///////// DISK I/O SYSTEM ///////////////
    28                              <1> 
    29                              <1> ; 11/04/2021
    30                              <1> ;; 06/02/2015
    31                              <1> ;diskette_io:
    32                              <1> 	;clc ; 20/07/2020
    33                              <1> 	;pushfd
    34                              <1> 	;push 	cs
    35                              <1> 	;;call 	DISKETTE_IO_1
    36                              <1> 	;;retn
    37                              <1> 	
    38                              <1> ;;;;;; DISKETTE I/O ;;;;;;;;;;;;;;;;;;;; 06/02/2015 ;;;
    39                              <1> ;//////////////////////////////////////////////////////
    40                              <1> 
    41                              <1> ; DISKETTE I/O - Erdogan Tan (Retro UNIX 386 v1 project)
    42                              <1> ; 20/02/2015
    43                              <1> ; 06/02/2015 (unix386.s)
    44                              <1> ; 16/12/2014 - 02/01/2015 (dsectrm2.s)
    45                              <1> ;
    46                              <1> ; Code (DELAY) modifications - AWARD BIOS 1999 (ADISK.EQU, COMMON.MAC)
    47                              <1> ;
    48                              <1> ; ADISK.EQU
    49                              <1> 
    50                              <1> ;----- Wait control constants 
    51                              <1> 
    52                              <1> ;amount of time to wait while RESET is active.
    53                              <1> 
    54                              <1> WAITCPU_RESET_ON	EQU	21		;Reset on must last at least 14us
    55                              <1> 						;at 250 KBS xfer rate.
    56                              <1> 						;see INTEL MCS, 1985, pg. 5-456
    57                              <1> 
    58                              <1> WAITCPU_FOR_STATUS	EQU	100		;allow 30 microseconds for
    59                              <1> 						;status register to become valid
    60                              <1> 						;before re-reading.
    61                              <1> 
    62                              <1> ;After sending a byte to NEC, status register may remain
    63                              <1> ;incorrectly set for 24 us.
    64                              <1> 
    65                              <1> WAITCPU_RQM_LOW		EQU	24		;number of loops to check for
    66                              <1> 						;RQM low.
    67                              <1> 
    68                              <1> ; COMMON.MAC
    69                              <1> ;
    70                              <1> ;	Timing macros
    71                              <1> ;
    72                              <1> 
    73                              <1> %macro 		SIODELAY 0 			; SHORT IODELAY
    74                              <1> 		jmp short $+2
    75                              <1> %endmacro		
    76                              <1> 
    77                              <1> %macro		IODELAY  0			; NORMAL IODELAY
    78                              <1> 		jmp short $+2
    79                              <1> 		jmp short $+2
    80                              <1> %endmacro
    81                              <1> 
    82                              <1> %macro		NEWIODELAY 0
    83                              <1> 		out 0EBh, al
    84                              <1> %endmacro 
    85                              <1> 
    86                              <1> ; (According to) AWARD BIOS 1999 - ATORGS.ASM (dw -> equ, db -> equ)
    87                              <1> ;;; WAIT_FOR_MEM
    88                              <1> ;WAIT_FDU_INT_LO	equ	017798		; 2.5 secs in 30 micro units.
    89                              <1> ;WAIT_FDU_INT_HI	equ	1
    90                              <1> WAIT_FDU_INT_LH		equ	83334		; 27/02/2015 (2.5 seconds waiting)
    91                              <1> ;;; WAIT_FOR_PORT
    92                              <1> ;WAIT_FDU_SEND_LO	equ	16667		; .5 secons in 30 us units.
    93                              <1> ;WAIT_FDU_SEND_HI	equ	0
    94                              <1> WAIT_FDU_SEND_LH	equ 	16667		; 27/02/2015	
    95                              <1> ;Time to wait while waiting for each byte of NEC results = .5
    96                              <1> ;seconds.  .5 seconds = 500,000 micros.  500,000/30 = 16,667.
    97                              <1> ;WAIT_FDU_RESULTS_LO	equ	16667		; .5 seconds in 30 micro units.
    98                              <1> ;WAIT_FDU_RESULTS_HI	equ	0
    99                              <1> WAIT_FDU_RESULTS_LH	equ	16667  ; 27/02/2015
   100                              <1> ;;; WAIT_REFRESH
   101                              <1> ;amount of time to wait for head settle, per unit in parameter
   102                              <1> ;table = 1 ms.
   103                              <1> WAIT_FDU_HEAD_SETTLE	equ	33		; 1 ms in 30 micro units.
   104                              <1> 
   105                              <1> 
   106                              <1> ; //////////////// DISKETTE I/O ////////////////
   107                              <1> 
   108                              <1> ; 11/12/2014 (copy from IBM PC-XT Model 286 BIOS - POSTEQU.INC)
   109                              <1> 
   110                              <1> ;----------------------------------------
   111                              <1> ;	EQUATES USED BY POST AND BIOS	:
   112                              <1> ;----------------------------------------
   113                              <1> 
   114                              <1> ;--------- 8042 KEYBOARD INTERFACE AND DIAGNOSTIC CONTROL REGISTERS ------------
   115                              <1> ;PORT_A		EQU	060H		; 8042 KEYBOARD SCAN CODE/CONTROL PORT
   116                              <1> ;PORT_B		EQU	061H		; PORT B READ/WRITE DIAGNOSTIC REGISTER
   117                              <1> ;REFRESH_BIT	EQU	00010000B	; REFRESH TEST BIT
   118                              <1> 
   119                              <1> ;----------------------------------------
   120                              <1> ;	CMOS EQUATES FOR THIS SYSTEM	:
   121                              <1> ;-------------------------------------------------------------------------------
   122                              <1> ;CMOS_PORT	EQU	070H		; I/O ADDRESS OF CMOS ADDRESS PORT
   123                              <1> ;CMOS_DATA	EQU	071H		; I/O ADDRESS OF CMOS DATA PORT
   124                              <1> ;NMI		EQU	10000000B	; DISABLE NMI INTERRUPTS MASK -
   125                              <1> 					;  HIGH BIT OF CMOS LOCATION ADDRESS
   126                              <1> 
   127                              <1> ;---------- CMOS TABLE LOCATION ADDRESS'S ## -----------------------------------
   128                              <1> CMOS_DISKETTE	EQU	010H		; DISKETTE DRIVE TYPE BYTE	      ;
   129                              <1> ;		EQU	011H		; - RESERVED			      ;C
   130                              <1> CMOS_DISK	EQU	012H		; FIXED DISK TYPE BYTE		      ;H
   131                              <1> ;		EQU	013H		; - RESERVED			      ;E
   132                              <1> CMOS_EQUIP	EQU	014H		; EQUIPMENT WORD LOW BYTE	      ;C
   133                              <1> 
   134                              <1> ;---------- DISKETTE EQUATES ---------------------------------------------------
   135                              <1> INT_FLAG	EQU	10000000B	; INTERRUPT OCCURRENCE FLAG
   136                              <1> DSK_CHG 	EQU	10000000B	; DISKETTE CHANGE FLAG MASK BIT
   137                              <1> DETERMINED	EQU	00010000B	; SET STATE DETERMINED IN STATE BITS
   138                              <1> HOME		EQU	00010000B	; TRACK 0 MASK
   139                              <1> SENSE_DRV_ST	EQU	00000100B	; SENSE DRIVE STATUS COMMAND
   140                              <1> TRK_SLAP	EQU	030H		; CRASH STOP (48 TPI DRIVES)
   141                              <1> QUIET_SEEK	EQU	00AH		; SEEK TO TRACK 10
   142                              <1> ;MAX_DRV 	EQU	2		; MAX NUMBER OF DRIVES
   143                              <1> HD12_SETTLE	EQU	15		; 1.2 M HEAD SETTLE TIME
   144                              <1> HD320_SETTLE	EQU	20		; 320 K HEAD SETTLE TIME
   145                              <1> MOTOR_WAIT	EQU	37		; 2 SECONDS OF COUNTS FOR MOTOR TURN OFF
   146                              <1> 
   147                              <1> ;---------- DISKETTE ERRORS ----------------------------------------------------
   148                              <1> ;TIME_OUT	EQU	080H		; ATTACHMENT FAILED TO RESPOND
   149                              <1> ;BAD_SEEK	EQU	040H		; SEEK OPERATION FAILED
   150                              <1> BAD_NEC 	EQU	020H		; DISKETTE CONTROLLER HAS FAILED
   151                              <1> BAD_CRC 	EQU	010H		; BAD CRC ON DISKETTE READ
   152                              <1> MED_NOT_FND	EQU	00CH		; MEDIA TYPE NOT FOUND
   153                              <1> DMA_BOUNDARY	EQU	009H		; ATTEMPT TO DMA ACROSS 64K BOUNDARY
   154                              <1> BAD_DMA 	EQU	008H		; DMA OVERRUN ON OPERATION
   155                              <1> MEDIA_CHANGE	EQU	006H		; MEDIA REMOVED ON DUAL ATTACH CARD
   156                              <1> RECORD_NOT_FND	EQU	004H		; REQUESTED SECTOR NOT FOUND
   157                              <1> WRITE_PROTECT	EQU	003H		; WRITE ATTEMPTED ON WRITE PROTECT DISK
   158                              <1> BAD_ADDR_MARK	EQU	002H		; ADDRESS MARK NOT FOUND
   159                              <1> BAD_CMD 	EQU	001H		; BAD COMMAND PASSED TO DISKETTE I/O
   160                              <1> 
   161                              <1> ;---------- DISK CHANGE LINE EQUATES -------------------------------------------
   162                              <1> NOCHGLN 	EQU	001H		; NO DISK CHANGE LINE AVAILABLE
   163                              <1> CHGLN		EQU	002H		; DISK CHANGE LINE AVAILABLE
   164                              <1> 
   165                              <1> ;---------- MEDIA/DRIVE STATE INDICATORS ---------------------------------------
   166                              <1> TRK_CAPA	EQU	00000001B	; 80 TRACK CAPABILITY
   167                              <1> FMT_CAPA	EQU	00000010B	; MULTIPLE FORMAT CAPABILITY (1.2M)
   168                              <1> DRV_DET 	EQU	00000100B	; DRIVE DETERMINED
   169                              <1> MED_DET 	EQU	00010000B	; MEDIA DETERMINED BIT
   170                              <1> DBL_STEP	EQU	00100000B	; DOUBLE STEP BIT
   171                              <1> RATE_MSK	EQU	11000000B	; MASK FOR CLEARING ALL BUT RATE
   172                              <1> RATE_500	EQU	00000000B	; 500 KBS DATA RATE
   173                              <1> RATE_300	EQU	01000000B	; 300 KBS DATA RATE
   174                              <1> RATE_250	EQU	10000000B	; 250 KBS DATA RATE
   175                              <1> STRT_MSK	EQU	00001100B	; OPERATION START RATE MASK
   176                              <1> SEND_MSK	EQU	11000000B	; MASK FOR SEND RATE BITS
   177                              <1> 
   178                              <1> ;---------- MEDIA/DRIVE STATE INDICATORS COMPATIBILITY -------------------------
   179                              <1> M3D3U		EQU	00000000B	; 360 MEDIA/DRIVE NOT ESTABLISHED
   180                              <1> M3D1U		EQU	00000001B	; 360 MEDIA,1.2DRIVE NOT ESTABLISHED
   181                              <1> M1D1U		EQU	00000010B	; 1.2 MEDIA/DRIVE NOT ESTABLISHED
   182                              <1> MED_UNK 	EQU	00000111B	; NONE OF THE ABOVE
   183                              <1> 
   184                              <1> ;---------- INTERRUPT EQUATES --------------------------------------------------
   185                              <1> ;EOI		EQU	020H		; END OF INTERRUPT COMMAND TO 8259
   186                              <1> ;INTA00		EQU	020H		; 8259 PORT
   187                              <1> INTA01		EQU	021H		; 8259 PORT
   188                              <1> INTB00		EQU	0A0H		; 2ND 8259
   189                              <1> INTB01		EQU	0A1H		;
   190                              <1> 
   191                              <1> ;-------------------------------------------------------------------------------
   192                              <1> DMA08		EQU	008H		; DMA STATUS REGISTER PORT ADDRESS
   193                              <1> DMA		EQU	000H		; DMA CH.0 ADDRESS REGISTER PORT ADDRESS
   194                              <1> DMA18		EQU	0D0H		; 2ND DMA STATUS PORT ADDRESS
   195                              <1> DMA1		EQU	0C0H		; 2ND DMA CH.0 ADDRESS REGISTER ADDRESS
   196                              <1> ;-------------------------------------------------------------------------------
   197                              <1> ;TIMER		EQU	040H		; 8254 TIMER - BASE ADDRESS
   198                              <1> 
   199                              <1> ;-------------------------------------------------------------------------------
   200                              <1> DMA_PAGE	EQU	081H		; START OF DMA PAGE REGISTERS
   201                              <1> 
   202                              <1> ; 06/02/2015 (unix386.s, protected mode modifications)
   203                              <1> ; (unix386.s <-- dsectrm2.s)
   204                              <1> ; 11/12/2014 (copy from IBM PC-XT Model 286 BIOS - DSEG.INC)
   205                              <1> 
   206                              <1> ; 27/05/2016 - TRDOS 386 (TRDOS v2.0)
   207                              <1> ; 10/12/2014
   208                              <1> ;
   209                              <1> ;int40h:
   210                              <1> ;	pushf
   211                              <1> ;	push 	cs
   212                              <1> ;	;cli
   213                              <1> ;	call 	DISKETTE_IO_1
   214                              <1> ;	retn
   215                              <1> 
   216                              <1> ; DSKETTE ----- 04/21/86 DISKETTE BIOS
   217                              <1> ; (IBM PC XT Model 286 System BIOS Source Code, 04-21-86)
   218                              <1> ;
   219                              <1> 
   220                              <1> ;-- INT13H ---------------------------------------------------------------------
   221                              <1> ; DISKETTE I/O
   222                              <1> ;	THIS INTERFACE PROVIDES ACCESS TO THE 5 1/4 INCH 360 KB,
   223                              <1> ;	1.2 MB, 720 KB AND 1.44 MB DISKETTE DRIVES.
   224                              <1> ; INPUT
   225                              <1> ;	(AH) =  00H RESET DISKETTE SYSTEM
   226                              <1> ;		HARD RESET TO NEC, PREPARE COMMAND, RECALIBRATE REQUIRED
   227                              <1> ;		ON ALL DRIVES
   228                              <1> ;------------------------------------------------------------------------------- 
   229                              <1> ;	(AH)= 01H  READ THE STATUS OF THE SYSTEM INTO (AH)
   230                              <1> ;		@DISKETTE_STATUS FROM LAST OPERATION IS USED
   231                              <1> ;-------------------------------------------------------------------------------
   232                              <1> ;	REGISTERS FOR READ/WRITE/VERIFY/FORMAT
   233                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
   234                              <1> ;	(DH) - HEAD NUMBER (0-1 ALLOWED, NOT VALUE CHECKED)
   235                              <1> ;	(CH) - TRACK NUMBER (NOT VALUE CHECKED)
   236                              <1> ;		MEDIA	DRIVE	TRACK NUMBER
   237                              <1> ;		320/360	320/360	    0-39
   238                              <1> ;		320/360	1.2M	    0-39
   239                              <1> ;		1.2M	1.2M	    0-79
   240                              <1> ;		720K	720K	    0-79
   241                              <1> ;		1.44M	1.44M	    0-79	
   242                              <1> ;	(CL) - 	SECTOR NUMBER (NOT VALUE CHECKED, NOT USED FOR FORMAT)
   243                              <1> ;		MEDIA	DRIVE	SECTOR NUMBER
   244                              <1> ;		320/360	320/360	     1-8/9
   245                              <1> ;		320/360	1.2M	     1-8/9
   246                              <1> ;		1.2M	1.2M	     1-15
   247                              <1> ;		720K	720K	     1-9
   248                              <1> ;		1.44M	1.44M	     1-18		
   249                              <1> ;	(AL)	NUMBER OF SECTORS (NOT VALUE CHECKED)
   250                              <1> ;		MEDIA	DRIVE	MAX NUMBER OF SECTORS
   251                              <1> ;		320/360	320/360	     8/9
   252                              <1> ;		320/360	1.2M	     8/9
   253                              <1> ;		1.2M	1.2M	     15
   254                              <1> ;		720K	720K	      9
   255                              <1> ;		1.44M	1.44M	     18
   256                              <1> ;
   257                              <1> ;	(ES:BX) - ADDRESS OF BUFFER (NOT REQUIRED FOR VERIFY)
   258                              <1> ;
   259                              <1> ;-------------------------------------------------------------------------------
   260                              <1> ;	(AH)= 02H  READ THE DESIRED SECTORS INTO MEMORY
   261                              <1> ;-------------------------------------------------------------------------------
   262                              <1> ;	(AH)= 03H  WRITE THE DESIRED SECTORS FROM MEMORY
   263                              <1> ;-------------------------------------------------------------------------------
   264                              <1> ;	(AH)= 04H  VERIFY THE DESIRED SECTORS
   265                              <1> ;-------------------------------------------------------------------------------
   266                              <1> ;	(AH)= 05H  FORMAT THE DESIRED TRACK
   267                              <1> ;		(ES,BX) MUST POINT TO THE COLLECTION OF DESIRED ADDRESS FIELDS
   268                              <1> ;		FOR THE	TRACK. EACH FIELD IS COMPOSED OF 4 BYTES, (C,H,R,N),
   269                              <1> ;		WHERE C = TRACK NUMBER, H=HEAD NUMBER, R = SECTOR NUMBER, 
   270                              <1> ;		N= NUMBER OF BYTES PER SECTOR (00=128,01=256,02=512,03=1024),
   271                              <1> ;		THERE MUST BE ONE ENTRY FOR EVERY SECTOR ON THE TRACK.
   272                              <1> ;		THIS INFORMATION IS USED TO FIND THE REQUESTED SECTOR DURING 
   273                              <1> ;		READ/WRITE ACCESS.
   274                              <1> ;		PRIOR TO FORMATTING A DISKETTE, IF THERE EXISTS MORE THAN
   275                              <1> ;		ONE SUPPORTED MEDIA FORMAT TYPE WITHIN THE DRIVE IN QUESTION,
   276                              <1> ;		THEN "SET DASD TYPE" (INT 13H, AH = 17H) OR 'SET MEDIA TYPE'
   277                              <1> ;		(INT 13H, AH =  18H) MUST BE CALLED TO SET THE DISKETTE TYPE
   278                              <1> ;		THAT IS TO BE FORMATTED. IF "SET DASD TYPE" OR "SET MEDIA TYPE"
   279                              <1> ;		IS NOT CALLED, THE FORMAT ROUTINE WILL ASSUME THE 
   280                              <1> ;		MEDIA FORMAT TO BE THE MAXIMUM CAPACITY OF THE DRIVE.
   281                              <1> ;
   282                              <1> ;		THESE PARAMETERS OF DISK BASE MUST BE CHANGED IN ORDER TO
   283                              <1> ;		FORMAT THE FOLLOWING MEDIAS:
   284                              <1> ;		---------------------------------------------
   285                              <1> ;		: MEDIA  :     DRIVE      : PARM 1 : PARM 2 :
   286                              <1> ;		---------------------------------------------
   287                              <1> ;		: 320K	 : 320K/360K/1.2M :  50H   :   8    :
   288                              <1> ;		: 360K	 : 320K/360K/1.2M :  50H   :   9    :
   289                              <1> ;		: 1.2M	 : 1.2M           :  54H   :  15    :
   290                              <1> ;		: 720K	 : 720K/1.44M     :  50H   :   9    :
   291                              <1> ;		: 1.44M	 : 1.44M          :  6CH   :  18    :		  	
   292                              <1> ;		---------------------------------------------
   293                              <1> ;		NOTES: - PARM 1 = GAP LENGTH FOR FORMAT
   294                              <1> ;		       - PARM 2 = EOT (LAST SECTOR ON TRACK)
   295                              <1> ;		       - DISK BASE IS POINTED BY DISK POINTER LOCATED
   296                              <1> ;			 AT ABSOLUTE ADDRESS 0:78.
   297                              <1> ;		       - WHEN FORMAT OPERATIONS ARE COMPLETE, THE PARAMETERS
   298                              <1> ;			 SHOULD BE RESTORED TO THEIR RESPECTIVE INITIAL VALUES.			
   299                              <1> ;-------------------------------------------------------------------------------
   300                              <1> ;	(AH) = 08H READ DRIVE PARAMETERS
   301                              <1> ;	REGISTERS
   302                              <1> ;	  INPUT
   303                              <1> ;	    (DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
   304                              <1> ;	     ** 27/05/2016 - TRDOS 386 (TRDOS v2.0) **	
   305                              <1> ;            ** EBX = Buffer address for floppy disk parameters table **
   306                              <1> ;	  OUTPUT
   307                              <1> ;	    (ES:DI) POINTS TO DRIVE PARAMETER TABLE
   308                              <1> ; 	    *** TRDOS 386 note: floppy disk parameter table (16 bytes)
   309                              <1> ;	    will be returned to user in EBX, buffer address *** 27/05/2016 ***		
   310                              <1> ;					
   311                              <1> ;	    (CH) - LOW ORDER 8 OF 10 BITS MAXIMUM NUMBER OF TRACKS
   312                              <1> ;	    (CL) - BITS 7 & 6 - HIGH ORDER TWO BITS OF MAXIMUM TRACKS
   313                              <1> ;	           BITS 5 THRU 0 - MAXIMUM SECTORS PER TRACK
   314                              <1> ;	    (DH) - MAXIMUM HEAD NUMBER
   315                              <1> ;	    (DL) - NUMBER OF DISKETTE DRIVES INSTALLED
   316                              <1> ;	    (BH) - 0
   317                              <1> ;	    (BL) - BITS 7 THRU 4 - 0
   318                              <1> ;	           BITS 3 THRU 0 - VALID DRIVE TYPE VALUE IN CMOS
   319                              <1> ;	    (AX) - 0
   320                              <1> ;	 UNDER THE FOLLOWING CIRCUMSTANCES:
   321                              <1> ;	    (1) THE DRIVE NUMBER IS INVALID,
   322                              <1> ;	    (2) THE DRIVE TYPE IS UNKNOWN AND CMOS IS NOT PRESENT, 
   323                              <1> ;	    (3) THE DRIVE TYPE IS UNKNOWN AND CMOS IS BAD,
   324                              <1> ;	    (4) OR THE DRIVE TYPE IS UNKNOWN AND THE CMOS DRIVE TYPE IS INVALID
   325                              <1> ;	    THEN ES,AX,BX,CX,DH,DI=0 ; DL=NUMBER OF DRIVES. 
   326                              <1> ;	    IF NO DRIVES ARE PRESENT THEN: ES,AX,BX,CX,DX,DI=0.
   327                              <1> ;	    @DISKETTE_STATUS = 0 AND CY IS RESET.
   328                              <1> ;-------------------------------------------------------------------------------
   329                              <1> ;	(AH)= 15H  READ DASD TYPE
   330                              <1> ;	OUTPUT REGISTERS
   331                              <1> ;	(AH) - ON RETURN IF CARRY FLAG NOT SET, OTHERWISE ERROR	
   332                              <1> ;		00 - DRIVE NOT PRESENT	
   333                              <1> ;		01 - DISKETTE, NO CHANGE LINE AVAILABLE
   334                              <1> ;		02 - DISKETTE, CHANGE LINE AVAILABLE	
   335                              <1> ;		03 - RESERVED (FIXED DISK)
   336                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
   337                              <1> ;-------------------------------------------------------------------------------
   338                              <1> ;	(AH)= 16H  DISK CHANGE LINE STATUS
   339                              <1> ;	OUTPUT REGISTERS
   340                              <1> ;	(AH) - 00 - DISK CHANGE LINE NOT ACTIVE	
   341                              <1> ;	       06 - DISK CHANGE LINE ACTIVE & CARRY BIT ON
   342                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED)
   343                              <1> ;-------------------------------------------------------------------------------
   344                              <1> ;	(AH)= 17H  SET DASD TYPE FOR FORMAT
   345                              <1> ;	INPUT REGISTERS
   346                              <1> ;	(AL) -	00 - NOT USED	
   347                              <1> ;		01 - DISKETTE 320/360K IN 360K DRIVE	
   348                              <1> ;		02 - DISKETTE 360K IN 1.2M DRIVE
   349                              <1> ;		03 - DISKETTE 1.2M IN 1.2M DRIVE
   350                              <1> ;		04 - DISKETTE 720K IN 720K DRIVE
   351                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHECKED:
   352                              <1> ;	       (DO NOT USE WHEN DISKETTE ATTACH CARD USED)
   353                              <1> ;-------------------------------------------------------------------------------
   354                              <1> ;	(AH)= 18H  SET MEDIA TYPE FOR FORMAT
   355                              <1> ;	INPUT REGISTERS
   356                              <1> ;	(CH) - LOW ORDER 8 OF 10 BITS MAXIMUM TRACKS
   357                              <1> ;	(CL) - BITS 7 & 6 - HIGH ORDER TWO BITS OF MAXIMUM TRACKS
   358                              <1> ;	       BITS 5 THRU 0 - MAXIMUM SECTORS PER TRACK
   359                              <1> ;	(DL) - DRIVE NUMBER (0-1 ALLOWED, VALUE CHACKED)
   360                              <1> ;	OUTPUT REGISTERS:
   361                              <1> ;	(ES:DI) - POINTER TO DRIVE PARAMETERS TABLE FOR THIS MEDIA TYPE,
   362                              <1> ;		  UNCHANGED IF (AH) IS NON-ZERO
   363                              <1> ;	(AH) - 00H, CY = 0, TRACK AND SECTORS/TRACK COMBINATION IS SUPPORTED
   364                              <1> ;	     - 01H, CY = 1, FUNCTION IS NOT AVAILABLE
   365                              <1> ;	     - 0CH, CY = 1, TRACK AND SECTORS/TRACK COMBINATION IS NOT SUPPORTED
   366                              <1> ;	     - 80H, CY = 1, TIME OUT (DISKETTE NOT PRESENT)		
   367                              <1> ;-------------------------------------------------------------------------------
   368                              <1> ;	DISK CHANGE STATUS IS ONLY CHECKED WHEN A MEDIA SPECIFIED IS OTHER
   369                              <1> ;	THAN 360 KB DRIVE. IF THE DISK CHANGE LINE IS FOUND TO BE
   370                              <1> ;	ACTIVE THE FOLLOWING ACTIONS TAKE PLACE:
   371                              <1> ;		ATTEMPT TO RESET DISK CHANGE LINE TO INACTIVE STATE. 
   372                              <1> ;		IF ATTEMPT SUCCEEDS SET DASD TYPE FOR FORMAT AND RETURN DISK 
   373                              <1> ;		CHANGE ERROR CODE
   374                              <1> ;		IF ATTEMPT FAILS RETURN TIMEOUT ERROR CODE AND SET DASD TYPE 
   375                              <1> ;		TO A PREDETERMINED STATE INDICATING MEDIA TYPE UNKNOWN.
   376                              <1> ;	IF THE DISK CHANGE LINE IN INACTIVE PERFORM SET DASD TYPE FOR FORMAT.
   377                              <1> ;
   378                              <1> ; DATA VARIABLE -- @DISK_POINTER
   379                              <1> ;	DOUBLE WORD POINTER TO THE CURRENT SET OF DISKETTE PARAMETERS
   380                              <1> ;-------------------------------------------------------------------------------
   381                              <1> ; OUTPUT FOR ALL FUNCTIONS
   382                              <1> ;	AH = STATUS OF OPERATION
   383                              <1> ;		STATUS BITS ARE DEFINED IN THE EQUATES FOR @DISKETTE_STATUS
   384                              <1> ;		VARIABLE IN THE DATA SEGMENT OF THIS MODULE
   385                              <1> ;	CY = 0	SUCCESSFUL OPERATION (AH=0 ON RETURN, EXCEPT FOR READ DASD
   386                              <1> ;		TYPE AH=(15)).
   387                              <1> ;	CY = 1	FAILED OPERATION (AH HAS ERROR REASON)
   388                              <1> ;	FOR READ/WRITE/VERIFY
   389                              <1> ;		DS,BX,DX,CX PRESERVED
   390                              <1> ;	NOTE: IF AN ERROR IS REPORTED BY THE DISKETTE CODE, THE APPROPRIATE 
   391                              <1> ;		ACTION IS TO RESET THE DISKETTE, THEN RETRY THE OPERATION.
   392                              <1> ;		ON READ ACCESSES, NO MOTOR START DELAY IS TAKEN, SO THAT 
   393                              <1> ;		THREE RETRIES ARE REQUIRED ON READS TO ENSURE THAT THE 
   394                              <1> ;		PROBLEM IS NOT DUE TO MOTOR START-UP.
   395                              <1> ;-------------------------------------------------------------------------------
   396                              <1> ;
   397                              <1> ; DISKETTE STATE MACHINE - ABSOLUTE ADDRESS 40:90 (DRIVE A) & 91 (DRIVE B)
   398                              <1> ;
   399                              <1> ;   -----------------------------------------------------------------
   400                              <1> ;   |       |       |       |       |       |       |       |       |
   401                              <1> ;   |   7   |   6   |   5   |   4   |   3   |   2   |   1   |   0   |
   402                              <1> ;   |       |       |       |       |       |       |       |       |
   403                              <1> ;   -----------------------------------------------------------------
   404                              <1> ;	|	|	|	|	|	|	|	|
   405                              <1> ;	|	|	|	|	|	-----------------
   406                              <1> ;	|	|	|	|	|		|
   407                              <1> ;	|	|	|	|    RESERVED		|
   408                              <1> ;	|	|	|	|		  PRESENT STATE
   409                              <1> ;	|	|	|	|	000: 360K IN 360K DRIVE UNESTABLISHED
   410                              <1> ;	|	|	|	|	001: 360K IN 1.2M DRIVE UNESTABLISHED
   411                              <1> ;	|	|	|	|	010: 1.2M IN 1.2M DRIVE UNESTABLISHED
   412                              <1> ;	|	|	|	|	011: 360K IN 360K DRIVE ESTABLISHED
   413                              <1> ;	|	|	|	|	100: 360K IN 1.2M DRIVE ESTABLISHED
   414                              <1> ;	|	|	|	|	101: 1.2M IN 1.2M DRIVE ESTABLISHED
   415                              <1> ;	|	|	|	|	110: RESERVED
   416                              <1> ;	|	|	|	|	111: NONE OF THE ABOVE
   417                              <1> ;	|	|	|	|
   418                              <1> ;	|	|	|	------>	MEDIA/DRIVE ESTABLISHED
   419                              <1> ;	|	|	|
   420                              <1> ;	|	|	-------------->	DOUBLE STEPPING REQUIRED (360K IN 1.2M
   421                              <1> ;	|	|			DRIVE)
   422                              <1> ;	|	|
   423                              <1> ;	------------------------------>	DATA TRANSFER RATE FOR THIS DRIVE:
   424                              <1> ;
   425                              <1> ;						00: 500 KBS
   426                              <1> ;						01: 300 KBS
   427                              <1> ;						10: 250 KBS
   428                              <1> ;						11: RESERVED
   429                              <1> ;
   430                              <1> ;
   431                              <1> ;-------------------------------------------------------------------------------
   432                              <1> ; STATE OPERATION STARTED - ABSOLUTE ADDRESS 40:92 (DRIVE A) & 93 (DRIVE B)
   433                              <1> ;-------------------------------------------------------------------------------
   434                              <1> ; PRESENT CYLINDER NUMBER - ABSOLUTE ADDRESS 40:94 (DRIVE A) & 95 (DRIVE B)
   435                              <1> ;-------------------------------------------------------------------------------
   436                              <1> 
   437                              <1> struc MD
   438 00000000 ??                  <1> 	.SPEC1		resb	1	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   439 00000001 ??                  <1> 	.SPEC2		resb	1	; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   440 00000002 ??                  <1> 	.OFF_TIM	resb	1	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   441 00000003 ??                  <1> 	.BYT_SEC	resb	1	; 512 BYTES/SECTOR
   442 00000004 ??                  <1> 	.SEC_TRK	resb	1	; EOT (LAST SECTOR ON TRACK)
   443 00000005 ??                  <1> 	.GAP		resb	1	; GAP LENGTH
   444 00000006 ??                  <1> 	.DTL		resb	1	; DTL
   445 00000007 ??                  <1> 	.GAP3		resb	1	; GAP LENGTH FOR FORMAT
   446 00000008 ??                  <1> 	.FIL_BYT	resb	1	; FILL BYTE FOR FORMAT
   447 00000009 ??                  <1> 	.HD_TIM		resb	1	; HEAD SETTLE TIME (MILLISECONDS)
   448 0000000A ??                  <1> 	.STR_TIM	resb	1	; MOTOR START TIME (1/8 SECONDS)
   449 0000000B ??                  <1> 	.MAX_TRK	resb	1	; MAX. TRACK NUMBER
   450 0000000C ??                  <1> 	.RATE		resb	1	; DATA TRANSFER RATE
   451                              <1> endstruc
   452                              <1> 
   453                              <1> BIT7OFF	EQU	7FH
   454                              <1> BIT7ON	EQU	80H
   455                              <1> 
   456                              <1> ; 30/08/2020 - TRDOS 386 v2
   457                              <1> 
   458                              <1> ;;int13h: ; 16/02/2015
   459                              <1> ;; 16/02/2015 - 21/02/2015
   460                              <1> ; 17/07/2022 - TRDOS 386 v2.0.5
   461                              <1> ;int40h:
   462                              <1> ;; 11/04/2021
   463                              <1> ;diskette_io:
   464                              <1> ;	clc ; 20/07/2020
   465                              <1> ;	pushfd
   466                              <1> ;	push 	cs
   467                              <1> ;	call 	DISKETTE_IO_1
   468                              <1> ;	retn
   469                              <1> 
   470                              <1> 	; 09/08/2022
   471                              <1> 	; 06/08/2022
   472                              <1> 	; 17/07/2022 - TRDOS 386 v2.0.5
   473                              <1> 	; (jump from DISK_IO)
   474                              <1> DISKETTE_IO_1:
   475                              <1> 	;sti ; 17/07/2022		; INTERRUPTS BACK ON
   476                              <1> 	
   477                              <1> 	;push	ebp			; USER REGISTER
   478                              <1> 	;push	edi			; USER REGISTER
   479                              <1> 	;push	edx			; HEAD #, DRIVE # OR USER REGISTER
   480                              <1> 	;push	ebx			; BUFFER OFFSET PARAMETER OR REGISTER
   481                              <1> 	;push	ecx			; TRACK #-SECTOR # OR USER REGISTER
   482                              <1> 	;mov	ebp, esp		; BP     => PARAMETER LIST DEP. ON AH
   483                              <1> 					; [BP]   = SECTOR #
   484                              <1> 					; [BP+1] = TRACK #
   485                              <1> 					; [BP+2] = BUFFER OFFSET
   486                              <1> 					; FOR RETURN OF DRIVE PARAMETERS:
   487                              <1> 					; CL/[BP] = BITS 7&6 HI BITS OF MAX CYL
   488                              <1> 					; 	    BITS 0-5 MAX SECTORS/TRACK
   489                              <1> 					; CH/[BP+1] = LOW 8 BITS OF MAX CYL.
   490                              <1> 					; BL/[BP+2] = BITS 7-4 = 0
   491                              <1> 					;	      BITS 3-0 = VALID CMOS TYPE
   492                              <1> 					; BH/[BP+3] = 0
   493                              <1> 					; DL/[BP+4] = # DRIVES INSTALLED
   494                              <1> 					; DH/[BP+5] = MAX HEAD #
   495                              <1> 					; DI/[BP+6] = OFFSET TO DISK BASE
   496                              <1> 	;push	es ; 06/02/2015	
   497                              <1> 	;push	ds			; BUFFER SEGMENT PARM OR USER REGISTER
   498                              <1> 	;push	esi			; USER REGISTERS
   499                              <1> 	;;call	DDS			; SEGMENT OF BIOS DATA AREA TO DS
   500                              <1> 	;;mov	cx, cs
   501                              <1> 	;;mov	ds, cx
   502                              <1> 	;mov	cx, KDATA
   503                              <1> 	;mov	ds, cx
   504                              <1> 	;mov	es, cx
   505                              <1> 
   506                              <1> 	; 17/07/2022
   507                              <1> 	; Registers are also on stack 
   508                              <1> 	; (with same contents) 
   509                              <1> 	; in following order:
   510                              <1> 	;
   511                              <1> 	;    ebx = esp+20
   512                              <1> 	;    ecx = esp+16
   513                              <1> 	;    edx = esp+12
   514                              <1> 	;    esi = esp+8
   515                              <1> 	;    edi = esp+4
   516                              <1> 	;
   517                              <1> 	; [esp] = caller's return address (from 'DISK_IO')	
   518                              <1> 	;
   519                              <1> 	; cs = KCODE == KDATA
   520                              <1> 	; ds = es = ss = KDATA
   521                              <1> 
   522                              <1> 	; 17/07/2022
   523 00004214 55                  <1> 	push	ebp
   524 00004215 89DD                <1> 	mov	ebp, ebx
   525                              <1> 
   526                              <1> 	;cmp	ah, (FNC_TAE-FNC_TAB)/2	; CHECK FOR > LARGEST FUNCTION
   527 00004217 80FC19              <1> 	cmp	ah, (FNC_TAE-FNC_TAB)/4	; 18/02/2015
   528                              <1> 	;jb	short OK_FUNC		; FUNCTION OK
   529                              <1> 	;mov	ah, 14h			; REPLACE WITH KNOWN INVALID FUNCTION
   530                              <1> 	; 09/08/2022
   531 0000421A 730F                <1> 	jnb	short INV_FUNC
   532                              <1> OK_FUNC:
   533 0000421C 80FC01              <1> 	cmp	ah, 1			; RESET OR STATUS ?
   534 0000421F 760C                <1> 	jbe	short OK_DRV		; IF RESET OR STATUS DRIVE ALWAYS OK
   535 00004221 80FC08              <1> 	cmp	ah, 8			; READ DRIVE PARMS ?
   536 00004224 7407                <1> 	je	short OK_DRV		; IF SO DRIVE CHECKED LATER
   537 00004226 80FA01              <1> 	cmp	dl, 1			; DRIVES 0 AND 1 OK
   538 00004229 7602                <1> 	jbe	short OK_DRV		; IF 0 OR 1 THEN JUMP
   539                              <1> INV_FUNC:
   540 0000422B B414                <1> 	mov	ah, 14h			; REPLACE WITH KNOWN INVALID FUNCTION
   541                              <1> OK_DRV:
   542                              <1> 	; 17/07/2022
   543                              <1> 	;xor	ecx, ecx
   544                              <1> 	;;mov	esi, ecx ; 08/02/2015
   545                              <1> 	;mov	edi, ecx ; 08/02/2015
   546                              <1> 	;mov	cl, ah			; CL = FUNCTION
   547                              <1> 	;;xor	ch, ch			; CX = FUNCTION
   548                              <1> 	;;shl	cl, 1			; FUNCTION TIMES 2
   549                              <1> 	;shl	cl, 2 ; 20/02/2015	; FUNCTION TIMES 4 (for 32 bit offset)
   550                              <1> 	;mov	ebx, FNC_TAB		; LOAD START OF FUNCTION TABLE
   551                              <1> 	;add	ebx, ecx		; ADD OFFSET INTO TABLE => ROUTINE
   552                              <1> 
   553                              <1> 	; 17/07/2022	
   554 0000422D 29DB                <1> 	sub	ebx, ebx
   555 0000422F 88E3                <1> 	mov	bl, ah			; BL = FUNCTION	
   556 00004231 C0E302              <1> 	shl	bl, 2 ; * 4
   557 00004234 81C3[53420000]      <1> 	add	ebx, FNC_TAB		; [EBX] = FUNCTION ADDRESS
   558                              <1> 	
   559 0000423A 88F4                <1> 	mov	ah, dh			; AX = HEAD #,# OF SECTORS OR DASD TYPE
   560                              <1> 	;xor	dh, dh			; DX = DRIVE #
   561                              <1> 	;mov	si, ax			; SI = HEAD #,# OF SECTORS OR DASD TYPE
   562                              <1> 	;mov	di, dx			; DI = DRIVE #
   563                              <1> 	
   564 0000423C 0FB7F0              <1> 	movzx	esi, ax			; ESI = HEAD #,# OF SECTORS OR DASD TYPE
   565 0000423F 0FB6FA              <1> 	movzx	edi, dl			; EDI = DRIVE # 
   566                              <1> 
   567                              <1> 	; CH = cylinder number (low 8 bit)
   568                              <1> 	; CL = sector number (and high 2 bits of cylinder number)
   569                              <1> 
   570                              <1> 	; 06/08/2022
   571                              <1> 	; 11/12/2014
   572                              <1>         ;mov	[cfd], dl               ; current floppy drive (for 'GET_PARM')        
   573                              <1> 	; 06/08/2022
   574                              <1> 	; EDI = (current) DRIVE #
   575                              <1> 	;
   576 00004242 8A25[487D0100]      <1> 	mov	ah, [DSKETTE_STATUS]	; LOAD STATUS TO AH FOR STATUS FUNCTION
   577 00004248 C605[487D0100]00    <1> 	mov	byte [DSKETTE_STATUS], 0 ; INITIALIZE FOR ALL OTHERS
   578                              <1> 
   579                              <1> ;	THROUGHOUT THE DISKETTE BIOS, THE FOLLOWING INFORMATION IS CONTAINED IN
   580                              <1> ;	THE FOLLOWING MEMORY LOCATIONS AND REGISTERS. NOT ALL DISKETTE BIOS
   581                              <1> ;	FUNCTIONS REQUIRE ALL OF THESE PARAMETERS.
   582                              <1> ;
   583                              <1> ;		DI	: DRIVE #
   584                              <1> ;		SI-HI	: HEAD #
   585                              <1> ;		SI-LOW	: # OF SECTORS OR DASD TYPE FOR FORMAT
   586                              <1> ;		ES	: BUFFER SEGMENT
   587                              <1> ;		[BP]	: SECTOR #
   588                              <1> ;		[BP+1]	: TRACK #
   589                              <1> ;		[BP+2]	: BUFFER OFFSET
   590                              <1> ;
   591                              <1> ;	ACROSS CALLS TO SUBROUTINES THE CARRY FLAG (CY=1), WHERE INDICATED IN 
   592                              <1> ;	SUBROUTINE PROLOGUES, REPRESENTS AN EXCEPTION RETURN (NORMALLY AN ERROR 
   593                              <1> ;	CONDITION). IN MOST CASES, WHEN CY = 1, @DSKETTE_STATUS CONTAINS THE 
   594                              <1> ;	SPECIFIC ERROR CODE.
   595                              <1> 
   596                              <1> 	; 17/07/2022
   597                              <1> 	; EBX = pointer to function address
   598                              <1> 	; EBP = buffer address
   599                              <1> 	; EDI = drive number (0 or 1)
   600                              <1> 	; ESI = head number (byte 1) and sector count or disk type (byte 0)
   601                              <1> 	; CH = cylinder number (low 8 bit)
   602                              <1> 	; CL = sector number (and high 2 bits of cylinder number)
   603                              <1> 
   604                              <1> 					; (AH) = @DSKETTE_STATUS
   605 0000424F FF13                <1> 	call	dword [ebx]		; CALL THE REQUESTED FUNCTION
   606                              <1> 	
   607                              <1> 	;pop	esi			; RESTORE ALL REGISTERS
   608                              <1> 	;pop	ds
   609                              <1> 	;pop	es	; 06/02/2015
   610                              <1> 	;pop	ecx
   611                              <1> 	;pop	ebx
   612                              <1> 	;pop	edx
   613                              <1> 	;pop	edi
   614                              <1> 	;mov	ebp, esp
   615                              <1> 	;push	eax
   616                              <1> 	;pushfd
   617                              <1> 	;pop	eax
   618                              <1> 	;;mov	[bp+6], ax
   619                              <1> 	;mov	[ebp+12], eax  ; 18/02/2015, flags
   620                              <1> 	;pop	eax
   621                              <1> 	;pop	ebp
   622                              <1> 	;iretd
   623                              <1> 
   624                              <1> 	; 17/07/2022
   625 00004251 5D                  <1> 	pop	ebp
   626                              <1> 
   627                              <1> 	; 17/07/2022
   628                              <1> 	; Stack order:
   629                              <1> 	;    ebx = esp+20
   630                              <1> 	;    ecx = esp+16
   631                              <1> 	;    edx = esp+12
   632                              <1> 	;    esi = esp+8
   633                              <1> 	;    edi = esp+4
   634                              <1> 	;
   635                              <1> 	; [esp] = caller's return address (from 'DISK_IO')
   636                              <1> 
   637                              <1> 	; CF = disk i/o status (1 = error)
   638                              <1> 	; AH = error code (if > 0 and cf = 1)
   639                              <1> 
   640                              <1> 	; 17/07/2022
   641 00004252 C3                  <1> 	retn	; return to the caller of 'DISK_IO' 
   642                              <1> 
   643                              <1> ;-------------------------------------------------------------------------------
   644                              <1> ; DW --> dd (06/02/2015)
   645 00004253 [B7420000]          <1> FNC_TAB	dd	DSK_RESET		; AH = 00H; RESET
   646 00004257 [22430000]          <1> 	dd	DSK_STATUS		; AH = 01H; STATUS
   647 0000425B [32430000]          <1> 	dd	DSK_READ		; AH = 02H; READ
   648 0000425F [3F430000]          <1> 	dd	DSK_WRITE		; AH = 03H; WRITE
   649 00004263 [53440000]          <1> 	dd	DSK_VERF		; AH = 04H; VERIFY
   650 00004267 [63440000]          <1> 	dd	DSK_FORMAT		; AH = 05H; FORMAT
   651 0000426B [E1440000]          <1> 	dd	FNC_ERR			; AH = 06H; INVALID
   652 0000426F [E1440000]          <1> 	dd	FNC_ERR			; AH = 07H; INVALID
   653 00004273 [ED440000]          <1> 	dd	DSK_PARMS		; AH = 08H; READ DRIVE PARAMETERS
   654 00004277 [E1440000]          <1> 	dd	FNC_ERR			; AH = 09H; INVALID
   655 0000427B [E1440000]          <1> 	dd	FNC_ERR			; AH = 0AH; INVALID
   656 0000427F [E1440000]          <1> 	dd	FNC_ERR			; AH = 0BH; INVALID
   657 00004283 [E1440000]          <1> 	dd	FNC_ERR			; AH = 0CH; INVALID
   658 00004287 [E1440000]          <1> 	dd	FNC_ERR			; AH = 0DH; INVALID
   659 0000428B [E1440000]          <1> 	dd	FNC_ERR			; AH = 0EH; INVALID
   660 0000428F [E1440000]          <1> 	dd	FNC_ERR			; AH = 0FH; INVALID
   661 00004293 [E1440000]          <1> 	dd	FNC_ERR			; AH = 10H; INVALID
   662 00004297 [E1440000]          <1> 	dd	FNC_ERR			; AH = 11H; INVALID
   663 0000429B [E1440000]          <1> 	dd	FNC_ERR			; AH = 12H; INVALID
   664 0000429F [E1440000]          <1> 	dd	FNC_ERR			; AH = 13H; INVALID
   665 000042A3 [E1440000]          <1> 	dd	FNC_ERR			; AH = 14H; INVALID
   666 000042A7 [AA450000]          <1> 	dd	DSK_TYPE		; AH = 15H; READ DASD TYPE
   667 000042AB [CA450000]          <1> 	dd	DSK_CHANGE		; AH = 16H; CHANGE STATUS
   668 000042AF [F9450000]          <1> 	dd	FORMAT_SET		; AH = 17H; SET DASD TYPE
   669 000042B3 [6E460000]          <1> 	dd	SET_MEDIA		; AH = 18H; SET MEDIA TYPE	
   670                              <1> FNC_TAE EQU     $                       ; END
   671                              <1> 
   672                              <1> 	; 17/07/2022 - TRDOS 386 v2.0.5
   673                              <1> ;-------------------------------------------------------------------------------
   674                              <1> ; DISK_RESET	(AH = 00H)	
   675                              <1> ;		RESET THE DISKETTE SYSTEM.
   676                              <1> ;
   677                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   678                              <1> ;-------------------------------------------------------------------------------
   679                              <1> DSK_RESET:
   680                              <1> 	; 17/07/2022
   681 000042B7 66BAF203            <1> 	mov	dx, 03F2h		; ADAPTER CONTROL PORT
   682 000042BB FA                  <1> 	cli				; NO INTERRUPTS
   683 000042BC A0[467D0100]        <1> 	mov	al, [MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
   684 000042C1 243F                <1> 	and	al, 00111111b		; KEEP SELECTED AND MOTOR ON BITS
   685 000042C3 C0C004              <1> 	rol	al, 4			; MOTOR VALUE TO HIGH NIBBLE
   686                              <1> 					; DRIVE SELECT TO LOW NIBBLE
   687 000042C6 0C08                <1> 	or	al, 00001000b		; TURN ON INTERRUPT ENABLE
   688 000042C8 EE                  <1> 	out	dx, al			; RESET THE ADAPTER
   689 000042C9 C605[457D0100]00    <1> 	mov	byte [SEEK_STATUS], 0	; SET RECALIBRATE REQUIRED ON ALL DRIVES
   690                              <1> 	;jmp	$+2			; WAIT FOR I/O
   691                              <1> 	;jmp	$+2			; WAIT FOR I/O (TO INSURE MINIMUM
   692                              <1> 					;      PULSE WIDTH)
   693                              <1> 	; 19/12/2014
   694                              <1> 	NEWIODELAY
    83 000042D0 E6EB                <2>  out 0EBh, al
   695                              <1> 
   696                              <1> 	; 17/12/2014 
   697                              <1> 	; AWARD BIOS 1999 - RESETDRIVES (ADISK.ASM)
   698 000042D2 B915000000          <1> 	mov	ecx, WAITCPU_RESET_ON	; cx = 21 -- Min. 14 micro seconds !?
   699                              <1> wdw1:
   700                              <1> 	NEWIODELAY   ; 27/02/2015
    83 000042D7 E6EB                <2>  out 0EBh, al
   701 000042D9 E2FC                <1> 	loop	wdw1
   702                              <1> 	;
   703 000042DB 0C04                <1> 	or	al, 00000100b		; TURN OFF RESET BIT
   704 000042DD EE                  <1> 	out	dx, al			; RESET THE ADAPTER
   705                              <1> 	; 16/12/2014
   706                              <1> 	IODELAY
    78 000042DE EB00                <2>  jmp short $+2
    79 000042E0 EB00                <2>  jmp short $+2
   707                              <1> 	;
   708                              <1> 	;sti				; ENABLE THE INTERRUPTS
   709 000042E2 E8DD0A0000          <1> 	call	WAIT_INT		; WAIT FOR THE INTERRUPT
   710 000042E7 7230                <1> 	jc	short DR_ERR		; IF ERROR, RETURN IT
   711                              <1> 	;mov	cx, 11000000b		; CL = EXPECTED @NEC_STATUS
   712                              <1> 	; 17/07/2022
   713                              <1> 	;xor	ch, ch
   714 000042E9 B1C0                <1> 	mov	cl, 11000000b
   715                              <1> NXT_DRV:
   716                              <1> 	;push	cx			; SAVE FOR CALL
   717                              <1> 	; 11/04/2021
   718 000042EB 51                  <1> 	push	ecx
   719 000042EC B8[18430000]        <1> 	mov	eax, DR_POP_ERR 	; LOAD NEC_OUTPUT ERROR ADDRESS
   720 000042F1 50                  <1> 	push	eax			; "
   721 000042F2 B408                <1> 	mov	ah, 08h			; SENSE INTERRUPT STATUS COMMAND
   722 000042F4 E8C3090000          <1> 	call	NEC_OUTPUT
   723 000042F9 58                  <1> 	pop	eax			; THROW AWAY ERROR RETURN
   724 000042FA E8F40A0000          <1> 	call	RESULTS			; READ IN THE RESULTS
   725                              <1> 	;pop	cx			; RESTORE AFTER CALL
   726                              <1> 	; 11/04/2021
   727 000042FF 59                  <1> 	pop	ecx
   728 00004300 7217                <1> 	jc	short DR_ERR		; ERROR RETURN
   729 00004302 3A0D[497D0100]      <1> 	cmp	cl, [NEC_STATUS]	; TEST FOR DRIVE READY TRANSITION
   730 00004308 750F                <1> 	jnz	short DR_ERR		; EVERYTHING OK
   731 0000430A FEC1                <1> 	inc	cl			; NEXT EXPECTED @NEC_STATUS
   732 0000430C 80F9C3              <1> 	cmp	cl, 11000011b		; ALL POSSIBLE DRIVES CLEARED
   733 0000430F 76DA                <1> 	jbe	short NXT_DRV		; FALL THRU IF 11000100B OR >
   734                              <1> 	;
   735 00004311 E800040000          <1> 	call	SEND_SPEC		; SEND SPECIFY COMMAND TO NEC
   736                              <1> RESBAC:
   737                              <1> 	; 06/08/2022
   738 00004316 EB10                <1> 	jmp	short SETUP_END_X
   739                              <1> 	;call	SETUP_END		; VARIOUS CLEANUPS
   740                              <1> 	;;mov	bx, si			; GET SAVED AL TO BL
   741                              <1> 	;; 17/07/2022
   742                              <1> 	;mov	ebx, esi		
   743                              <1> 	;mov	al, bl			; PUT BACK FOR RETURN
   744                              <1> 	;retn		
   745                              <1> 
   746                              <1> DR_POP_ERR:
   747                              <1> 	;pop	cx			; CLEAR STACK
   748                              <1> 	; 11/04/2021
   749 00004318 59                  <1> 	pop	ecx
   750                              <1> DR_ERR:
   751 00004319 800D[487D0100]20    <1> 	or	byte [DSKETTE_STATUS], BAD_NEC ; SET ERROR CODE
   752                              <1> 	;jmp	short RESBAC		; RETURN FROM RESET
   753                              <1> 	; 06/08/2022
   754 00004320 EB06                <1> 	jmp	short SETUP_END_X
   755                              <1> 
   756                              <1> ;-------------------------------------------------------------------------------
   757                              <1> ; DISK_STATUS	(AH = 01H)
   758                              <1> ;	DISKETTE STATUS.
   759                              <1> ;
   760                              <1> ; ON ENTRY:	AH : STATUS OF PREVIOUS OPERATION
   761                              <1> ;
   762                              <1> ; ON EXIT:	AH, @DSKETTE_STATUS, CY REFLECT STATUS OF PREVIOUS OPERATION.
   763                              <1> ;-------------------------------------------------------------------------------
   764                              <1> DSK_STATUS:
   765 00004322 8825[487D0100]      <1> 	mov	[DSKETTE_STATUS], ah	; PUT BACK FOR SETUP END
   766                              <1> SETUP_END_X:	; 06/08/2022
   767 00004328 E809010000          <1> 	call	SETUP_END		; VARIOUS CLEANUPS
   768                              <1> 	;mov	bx, si			; GET SAVED AL TO BL
   769                              <1> 	;mov	al, bl			; PUT BACK FOR RETURN
   770                              <1> 	; 06/08/2022
   771 0000432D 89F3                <1> 	mov	ebx, esi
   772 0000432F 88D8                <1> 	mov	al, bl
   773 00004331 C3                  <1> 	retn		
   774                              <1> 
   775                              <1> ;-------------------------------------------------------------------------------
   776                              <1> ; DISK_READ	(AH = 02H)	
   777                              <1> ;	DISKETTE READ.
   778                              <1> ;
   779                              <1> ; ON ENTRY:	DI	: DRIVE #
   780                              <1> ;		SI-HI	: HEAD #
   781                              <1> ;		SI-LOW	: # OF SECTORS
   782                              <1> ;		ES	: BUFFER SEGMENT
   783                              <1> ;		[BP]	: SECTOR #
   784                              <1> ;		[BP+1]	: TRACK #
   785                              <1> ;		[BP+2]	: BUFFER OFFSET
   786                              <1> ;
   787                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   788                              <1> ;-------------------------------------------------------------------------------
   789                              <1> 
   790                              <1> ; 06/02/2015, ES:BX -> EBX (unix386.s)
   791                              <1> 
   792                              <1> DSK_READ:
   793 00004332 8025[467D0100]7F    <1> 	and	byte [MOTOR_STATUS], 01111111b ; INDICATE A READ OPERATION
   794 00004339 66B846E6            <1> 	mov	ax, 0E646h		; AX = NEC COMMAND, DMA COMMAND
   795                              <1> 	;call	RD_WR_VF		; COMMON READ/WRITE/VERIFY
   796                              <1> 	;retn
   797                              <1> 	; 06/08/2022
   798 0000433D EB0B                <1> 	jmp	short RD_WR_VF
   799                              <1> 
   800                              <1> ;-------------------------------------------------------------------------------
   801                              <1> ; DISK_WRITE	(AH = 03H)
   802                              <1> ;	DISKETTE WRITE.
   803                              <1> ;
   804                              <1> ; ON ENTRY:	DI	: DRIVE #
   805                              <1> ;		SI-HI	: HEAD #
   806                              <1> ;		SI-LOW	: # OF SECTORS
   807                              <1> ;		ES	: BUFFER SEGMENT
   808                              <1> ;		[BP]	: SECTOR #
   809                              <1> ;		[BP+1]	: TRACK #
   810                              <1> ;		[BP+2]	: BUFFER OFFSET
   811                              <1> ;
   812                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   813                              <1> ;-------------------------------------------------------------------------------
   814                              <1> 
   815                              <1> ; 06/02/2015, ES:BX -> EBX (unix386.s)
   816                              <1> 
   817                              <1> DSK_WRITE:
   818 0000433F 66B84AC5            <1> 	mov	ax, 0C54Ah		; AX = NEC COMMAND, DMA COMMAND
   819 00004343 800D[467D0100]80    <1> 	or	byte [MOTOR_STATUS], 10000000b ; INDICATE WRITE OPERATION
   820                              <1> 	;call	RD_WR_VF		; COMMON READ/WRITE/VERIFY
   821                              <1> 	;retn
   822                              <1> 	; 06/08/2022
   823                              <1> 	;jmp	short RD_WR_VF
   824                              <1> 
   825                              <1> 	; 09/08/2022
   826                              <1> 	; 06/08/2022 - TRDOS 386 Kernel v2.0.5
   827                              <1> ;-------------------------------------------------------------------------------
   828                              <1> ; RD_WR_VF
   829                              <1> ;	COMMON READ, WRITE AND VERIFY: 
   830                              <1> ;	MAIN LOOP FOR STATE RETRIES.
   831                              <1> ;
   832                              <1> ; ON ENTRY:	AH = READ/WRITE/VERIFY NEC PARAMETER
   833                              <1> ;		AL = READ/WRITE/VERIFY DMA PARAMETER
   834                              <1> ;
   835                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   836                              <1> ;-------------------------------------------------------------------------------
   837                              <1> RD_WR_VF:
   838                              <1> 	; 02/12/2023
   839                              <1> 	; 11/08/2022
   840                              <1> 	; 09/08/2022
   841                              <1> 	; 07/08/2022
   842                              <1> 	; 06/08/2022
   843                              <1> 	; 11/04/2021 (32 bit push/pop, AX -> EAX)
   844                              <1> 	
   845 0000434A 50                  <1> 	push	eax			; SAVE DMA, NEC PARAMETERS
   846                              <1> 	
   847                              <1> 	; 02/12/2023
   848                              <1> 	; (diskette change check for 'dir', 28 seconds)
   849 0000434B A0[417D0100]        <1> 	mov	al, [TIMER_LOW+1]
   850 00004350 D0E8                <1> 	shr	al, 1
   851 00004352 A2[A6840100]        <1> 	mov	[P_TIMER], al
   852                              <1> 
   853 00004357 E803040000          <1> 	call	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
   854 0000435C E86A040000          <1> 	call	SETUP_STATE		; INITIALIZE START AND END RATE
   855 00004361 58                  <1> 	pop	eax			; RESTORE READ/WRITE/VERIFY
   856                              <1> DO_AGAIN:
   857 00004362 50                  <1> 	push	eax			; SAVE READ/WRITE/VERIFY PARAMETER
   858 00004363 E8F8040000          <1> 	call	MED_CHANGE		; MEDIA CHANGE AND RESET IF CHANGED
   859 00004368 58                  <1> 	pop	eax			; RESTORE READ/WRITE/VERIFY
   860                              <1> 	;jc	short RWV_END		; MEDIA CHANGE ERROR OR TIME-OUT
   861                              <1> 	; 07/08/2022
   862 00004369 7305                <1> 	jnc	short RWV
   863 0000436B E9BC000000          <1> 	jmp	RWV_END
   864                              <1> RWV:
   865 00004370 50                  <1> 	push	eax			; SAVE READ/WRITE/VERIFY PARAMETER
   866 00004371 8AB7[537D0100]      <1> 	mov	dh, [DSK_STATE+edi]	; GET RATE STATE OF THIS DRIVE
   867 00004377 80E6C0              <1> 	and	dh, RATE_MSK		; KEEP ONLY RATE
   868 0000437A E83E080000          <1> 	call	CMOS_TYPE		; RETURN DRIVE TYPE IN AL (AL)
   869                              <1> 	;;20/02/2015
   870                              <1> 	;;jc	short RWV_ASSUME	; ERROR IN CMOS
   871 0000437F 7447                <1> 	jz	short RWV_ASSUME ; 20/02/2015
   872 00004381 3C01                <1> 	cmp	al, 1			; 40 TRACK DRIVE?
   873 00004383 750D                <1> 	jne	short RWV_1		; NO, BYPASS CMOS VALIDITY CHECK
   874 00004385 F687[537D0100]01    <1> 	test	byte [DSK_STATE+edi], TRK_CAPA ; CHECK FOR 40 TRACK DRIVE
   875 0000438C 7411                <1> 	jz	short RWV_2		; YES, CMOS IS CORRECT
   876                              <1> 	;mov	al, 2			; CHANGE TO 1.2M
   877                              <1> 	; 06/08/2022
   878 0000438E FEC0                <1> 	inc	al ; al = 2
   879 00004390 EB0D                <1> 	jmp	short RWV_2
   880                              <1> RWV_1:
   881                              <1> 	; 09/08/2022
   882                              <1> 	;jb	short RWV_2		; NO DRIVE SPECIFIED, CONTINUE
   883 00004392 F687[537D0100]01    <1> 	test    byte [DSK_STATE+edi], TRK_CAPA ; IS IT REALLY 40 TRACK?
   884 00004399 7504                <1> 	jnz	short RWV_2		; NO, 80 TRACK
   885 0000439B B001                <1> 	mov	al, 1			; IT IS 40 TRACK, FIX CMOS VALUE
   886 0000439D EB00                <1> 	jmp	short rwv_3
   887                              <1> RWV_2:
   888                              <1> 	; 09/08/2022
   889                              <1> 	;or	al, al			; TEST FOR NO DRIVE
   890                              <1> 	;jz	short RWV_ASSUME	; ASSUME TYPE, USE MAX TRACK
   891                              <1> rwv_3:
   892 0000439F E855030000          <1> 	call	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL.
   893 000043A4 7222                <1> 	jc	short RWV_ASSUME	; TYPE NOT IN TABLE (BAD CMOS)
   894                              <1> 
   895                              <1> ;-----	SEARCH FOR MEDIA/DRIVE PARAMETER TABLE
   896                              <1> 
   897 000043A6 57                  <1> 	push	edi			; SAVE DRIVE #
   898                              <1> 	; 09/08/2022
   899                              <1> 	;xor	ebx, ebx		; EBX = INDEX TO DR_TYPE TABLE
   900 000043A7 BB[B8650000]        <1> 	mov	ebx, DR_TYPE
   901                              <1> 	;mov	ecx, DR_CNT		; ECX = LOOP COUNT
   902 000043AC B106                <1> 	mov	cl, DR_CNT
   903                              <1> RWV_DR_SEARCH:
   904                              <1> 	;mov	ah, [DR_TYPE+ebx]	; GET DRIVE TYPE
   905 000043AE 8A23                <1> 	mov	ah, [ebx]
   906 000043B0 80E47F              <1> 	and	ah, BIT7OFF		; MASK OUT MSB
   907 000043B3 38E0                <1> 	cmp	al, ah			; DRIVE TYPE MATCH?
   908                              <1> 	; 09/08/2022
   909                              <1> 	;cmp	dl, ah
   910 000043B5 7509                <1> 	jne	short RWV_NXT_MD	; NO, CHECK NEXT DRIVE TYPE
   911                              <1> RWV_DR_FND:
   912                              <1> 	;mov	edi, [DR_TYPE+ebx+1] 	; EDI = MEDIA/DRIVE PARAMETER TABLE
   913 000043B7 43                  <1> 	inc	ebx
   914 000043B8 8B3B                <1> 	mov	edi, [ebx]
   915 000043BA 4B                  <1> 	dec	ebx
   916                              <1> RWV_MD_SEARH:
   917 000043BB 3A770C              <1>         cmp	dh, [edi+MD.RATE]       ; MATCH?
   918 000043BE 741D                <1> 	je	short RWV_MD_FND	; YES, GO GET 1ST SPECIFY BYTE
   919                              <1> RWV_NXT_MD:
   920 000043C0 83C305              <1> 	add	ebx, 5			; CHECK NEXT DRIVE TYPE
   921                              <1> 	;loop	RWV_DR_SEARCH
   922 000043C3 FEC9                <1> 	dec	cl
   923 000043C5 75E7                <1> 	jnz	short RWV_DR_SEARCH 
   924 000043C7 5F                  <1> 	pop	edi			; RESTORE DRIVE #
   925                              <1> 
   926                              <1> ;-----	ASSUME PRIMARY DRIVE IS INSTALLED AS SHIPPED
   927                              <1> 
   928                              <1> RWV_ASSUME:
   929 000043C8 BB[D6650000]        <1> 	mov	ebx, MD_TBL1		; POINT TO 40 TRACK 250 KBS
   930 000043CD F687[537D0100]01    <1> 	test 	byte [DSK_STATE+edi], TRK_CAPA ; TEST FOR 80 TRACK
   931 000043D4 740A                <1> 	jz	short RWV_MD_FND1	; MUST BE 40 TRACK
   932 000043D6 BB[F0650000]        <1> 	mov	ebx, MD_TBL3		; POINT TO 80 TRACK 500 KBS
   933 000043DB EB03                <1> 	jmp	short RWV_MD_FND1	; GO SPECIFY PARAMTERS
   934                              <1> 
   935                              <1> ;-----	CS:BX POINTS TO MEDIA/DRIVE PARAMETER TABLE
   936                              <1> 	 			
   937                              <1> RWV_MD_FND:
   938 000043DD 89FB                <1> 	mov	ebx, edi		; BX = MEDIA/DRIVE PARAMETER TABLE
   939 000043DF 5F                  <1> 	pop	edi			; RESTORE DRIVE #
   940                              <1> 	
   941                              <1> ;-----	SEND THE SPECIFY COMMAND TO THE CONTROLLER
   942                              <1> 
   943                              <1> RWV_MD_FND1:
   944 000043E0 E85A030000          <1> 	call	SEND_SPEC_MD
   945 000043E5 E8E3040000          <1> 	call	CHK_LASTRATE		; ZF=1 ATTEMP RATE IS SAME AS LAST RATE
   946 000043EA 7405                <1> 	jz	short RWV_DBL		; YES,SKIP SEND RATE COMMAND
   947 000043EC E8BC040000          <1> 	call	SEND_RATE		; SEND DATA RATE TO NEC
   948                              <1> RWV_DBL:
   949 000043F1 53                  <1> 	push	ebx			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
   950 000043F2 E825070000          <1> 	call	SETUP_DBL		; CHECK FOR DOUBLE STEP
   951 000043F7 5B                  <1> 	pop	ebx			; RESTORE ADDRESS
   952 000043F8 7225                <1> 	jc	short CHK_RET		; ERROR FROM READ ID, POSSIBLE RETRY
   953                              <1> 	;pop	eax			; RESTORE NEC COMMAND
   954                              <1> 	;push	eax			; SAVE NEC COMMAND
   955                              <1> 	; 09/08/2022
   956 000043FA 8B0424              <1> 	mov	eax, [esp]
   957                              <1> 	;push	ebx			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
   958 000043FD E8E0040000          <1> 	call	DMA_SETUP		; SET UP THE DMA
   959                              <1> 	;pop	ebx
   960 00004402 58                  <1> 	pop	eax			; RESTORE NEC COMMAND
   961 00004403 7231                <1> 	jc	short RWV_BAC		; CHECK FOR DMA BOUNDARY ERROR
   962 00004405 50                  <1> 	push	eax			; SAVE NEC COMMAND
   963 00004406 53                  <1> 	push	ebx			; SAVE MEDIA/DRIVE PARAM TBL ADDRESS
   964                              <1> 	; 11/08/2022
   965 00004407 8B5C2420            <1> 	mov	ebx, [esp+32] ; ECX
   966 0000440B E866050000          <1> 	call	NEC_INIT		; INITIALIZE NEC
   967 00004410 5B                  <1> 	pop	ebx			; RESTORE ADDRESS
   968 00004411 720C                <1> 	jc	short CHK_RET		; ERROR - EXIT
   969 00004413 E88C050000          <1> 	call	RWV_COM			; OP CODE COMMON TO READ/WRITE
   970 00004418 7205                <1> 	jc	short CHK_RET		; ERROR - EXIT
   971 0000441A E8D2050000          <1> 	call	NEC_TERM		; TERMINATE, GET STATUS, ETC.
   972                              <1> CHK_RET:
   973 0000441F E871060000          <1> 	call	RETRY			; CHECK FOR, SETUP RETRY
   974 00004424 58                  <1> 	pop	eax			; RESTORE READ/WRITE PARAMETER
   975 00004425 7305                <1> 	jnc	short RWV_END		; CY = 0 NO RETRY
   976 00004427 E936FFFFFF          <1>         jmp	DO_AGAIN                ; CY = 1 MEANS RETRY
   977                              <1> RWV_END:
   978 0000442C E81C060000          <1> 	call	DSTATE			; ESTABLISH STATE IF SUCCESSFUL
   979 00004431 E8AE060000          <1> 	call	NUM_TRANS		; AL = NUMBER TRANSFERRED
   980                              <1> RWV_BAC:				; BAD DMA ERROR ENTRY
   981                              <1> 	; 06/08/2022
   982                              <1> 	;push	eax			; SAVE NUMBER TRANSFERRED
   983                              <1> 	;call	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
   984                              <1> 	;pop	eax			; RESTORE NUMBER TRANSFERRED
   985                              <1> 	;call	SETUP_END		; VARIOUS CLEANUPS
   986                              <1> 	;retn
   987                              <1> 
   988                              <1> ;-------------------------------------------------------------------------------
   989                              <1> ; SETUP_END
   990                              <1> ;	RESTORES @MOTOR_COUNT TO PARAMETER PROVIDED IN TABLE 
   991                              <1> ;	AND LOADS @DSKETTE_STATUS TO AH, AND SETS CY.
   992                              <1> ;
   993                              <1> ; ON EXIT:
   994                              <1> ;	AH, @DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
   995                              <1> ;-------------------------------------------------------------------------------
   996                              <1> SETUP_END:
   997                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
   998                              <1> 	;mov	dl, 2			; GET THE MOTOR WAIT PARAMETER
   999                              <1> 	;push	ax			; SAVE NUMBER TRANSFERRED
  1000                              <1> 	; 11/04/2021
  1001 00004436 50                  <1> 	push	eax
  1002                              <1> 	; 06/08/2022
  1003 00004437 B002                <1> 	mov	al, 2			; GET THE MOTOR WAIT PARAMETER		
  1004 00004439 E888070000          <1> 	call	GET_PARM
  1005 0000443E 8825[477D0100]      <1> 	mov	[MOTOR_COUNT], ah	; STORE UPON RETURN
  1006                              <1> 	;pop	ax			; RESTORE NUMBER TRANSFERRED
  1007                              <1> 	; 11/04/2021
  1008 00004444 58                  <1> 	pop	eax
  1009 00004445 8A25[487D0100]      <1> 	mov	ah, [DSKETTE_STATUS]	; GET STATUS OF OPERATION
  1010 0000444B 08E4                <1> 	or	ah, ah			; CHECK FOR ERROR
  1011 0000444D 7403                <1> 	jz	short NUN_ERR		; NO ERROR
  1012 0000444F 30C0                <1> 	xor	al, al			; CLEAR NUMBER RETURNED
  1013                              <1> 	; 06/08/2022
  1014 00004451 F9                  <1> 	stc
  1015                              <1> NUN_ERR: 
  1016                              <1> 	;cmp	ah, 1			; SET THE CARRY FLAG TO INDICATE
  1017                              <1> 	;cmc				; SUCCESS OR FAILURE
  1018 00004452 C3                  <1> 	retn
  1019                              <1> 
  1020                              <1> ;-------------------------------------------------------------------------------
  1021                              <1> ; DISK_VERF	(AH = 04H)
  1022                              <1> ;	DISKETTE VERIFY.
  1023                              <1> ;
  1024                              <1> ; ON ENTRY:	DI	: DRIVE #
  1025                              <1> ;		SI-HI	: HEAD #
  1026                              <1> ;		SI-LOW	: # OF SECTORS
  1027                              <1> ;		ES	: BUFFER SEGMENT
  1028                              <1> ;		[BP]	: SECTOR #
  1029                              <1> ;		[BP+1]	: TRACK #
  1030                              <1> ;		[BP+2]	: BUFFER OFFSET
  1031                              <1> ;
  1032                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1033                              <1> ;-------------------------------------------------------------------------------
  1034                              <1> DSK_VERF:
  1035 00004453 8025[467D0100]7F    <1> 	and	byte [MOTOR_STATUS], 01111111b ; INDICATE A READ OPERATION
  1036 0000445A 66B842E6            <1> 	mov	ax, 0E642h		; AX = NEC COMMAND, DMA COMMAND
  1037                              <1> 	;call	RD_WR_VF		; COMMON READ/WRITE/VERIFY
  1038                              <1> 	;retn
  1039                              <1> 	; 06/08/2022
  1040 0000445E E9E7FEFFFF          <1> 	jmp	RD_WR_VF
  1041                              <1> 
  1042                              <1> ;-------------------------------------------------------------------------------
  1043                              <1> ; DISK_FORMAT	(AH = 05H)
  1044                              <1> ;	DISKETTE FORMAT.
  1045                              <1> ;
  1046                              <1> ; ON ENTRY:	DI	: DRIVE #
  1047                              <1> ;		SI-HI	: HEAD #
  1048                              <1> ;		SI-LOW	: # OF SECTORS
  1049                              <1> ;		ES	: BUFFER SEGMENT
  1050                              <1> ;		[BP]	: SECTOR #
  1051                              <1> ;		[BP+1]	: TRACK #
  1052                              <1> ;		[BP+2]	: BUFFER OFFSET
  1053                              <1> ;		@DISK_POINTER POINTS TO THE PARAMETER TABLE OF THIS DRIVE
  1054                              <1> ;
  1055                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1056                              <1> ;-------------------------------------------------------------------------------
  1057                              <1> DSK_FORMAT:
  1058                              <1> 	; 11/08/2022
  1059                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  1060 00004463 E8F7020000          <1> 	call	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  1061 00004468 E89F030000          <1> 	call	FMT_INIT		; ESTABLISH STATE IF UNESTABLISHED
  1062 0000446D 800D[467D0100]80    <1> 	or	byte [MOTOR_STATUS], 10000000b ; INDICATE WRITE OPERATION
  1063 00004474 E8E7030000          <1> 	call	MED_CHANGE		; CHECK MEDIA CHANGE AND RESET IF SO
  1064 00004479 7261                <1>         jc      short FM_DON            ; MEDIA CHANGED, SKIP
  1065 0000447B E896020000          <1> 	call	SEND_SPEC		; SEND SPECIFY COMMAND TO NEC
  1066 00004480 E848040000          <1> 	call	CHK_LASTRATE		; ZF=1 ATTEMPT RATE IS SAME AS LAST RATE
  1067 00004485 7405                <1>         jz      short FM_WR             ; YES, SKIP SPECIFY COMMAND
  1068 00004487 E821040000          <1> 	call	SEND_RATE		; SEND DATA RATE TO CONTROLLER
  1069                              <1> FM_WR:
  1070 0000448C E8C8040000          <1> 	call	FMTDMA_SET		; SET UP THE DMA FOR FORMAT
  1071 00004491 7249                <1>         jc      short FM_DON            ; RETURN WITH ERROR
  1072 00004493 B44D                <1> 	mov	ah, 04Dh		; ESTABLISH THE FORMAT COMMAND
  1073                              <1> 	; 11/08/2022
  1074 00004495 8B5C2418            <1> 	mov	ebx, [esp+24] ; ECX
  1075 00004499 E8D8040000          <1> 	call	NEC_INIT		; INITIALIZE THE NEC
  1076 0000449E 723C                <1> 	jc	short FM_DON            ; ERROR - EXIT
  1077 000044A0 B8[DC440000]        <1>         mov     eax, FM_DON             ; LOAD ERROR ADDRESS
  1078 000044A5 50                  <1> 	push	eax			; PUSH NEC_OUT ERROR RETURN
  1079                              <1> 	;mov	dl, 3			; BYTES/SECTOR VALUE TO NEC
  1080                              <1> 	; 06/08/2022
  1081 000044A6 B003                <1> 	mov	al, 3
  1082 000044A8 E819070000          <1> 	call	GET_PARM
  1083 000044AD E80A080000          <1> 	call	NEC_OUTPUT
  1084                              <1> 	;mov	dl, 4			; SECTORS/TRACK VALUE TO NEC
  1085                              <1> 	; 06/08/2022
  1086 000044B2 B004                <1> 	mov	al, 4
  1087 000044B4 E80D070000          <1> 	call	GET_PARM
  1088 000044B9 E8FE070000          <1> 	call	NEC_OUTPUT
  1089                              <1> 	;mov	dl, 7			; GAP LENGTH VALUE TO NEC
  1090                              <1> 	; 06/08/2022
  1091 000044BE B007                <1> 	mov	al, 7
  1092 000044C0 E801070000          <1> 	call	GET_PARM
  1093 000044C5 E8F2070000          <1> 	call	NEC_OUTPUT
  1094                              <1> 	;mov	dl, 8			; FILLER BYTE TO NEC
  1095                              <1> 	; 06/08/2022
  1096 000044CA B008                <1> 	mov	al, 8
  1097 000044CC E8F5060000          <1> 	call	GET_PARM
  1098 000044D1 E8E6070000          <1> 	call	NEC_OUTPUT
  1099 000044D6 58                  <1> 	pop	eax			; THROW AWAY ERROR
  1100 000044D7 E815050000          <1> 	call	NEC_TERM		; TERMINATE, RECEIVE STATUS, ETC,
  1101                              <1> FM_DON:
  1102                              <1> 	; 06/08/2022
  1103                              <1> 	;call	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  1104                              <1> 	; 06/08/2022
  1105 000044DC E947FEFFFF          <1> 	jmp	SETUP_END_X
  1106                              <1> 	;call	SETUP_END		; VARIOUS CLEANUPS
  1107                              <1> 	;; 06/08/2022
  1108                              <1> 	;mov	ebx, esi		; GET SAVED AL TO BL
  1109                              <1> 	;mov	al, bl			; PUT BACK FOR RETURN
  1110                              <1> 	;retn
  1111                              <1> 
  1112                              <1> ;-------------------------------------------------------------------------------
  1113                              <1> ; FNC_ERR
  1114                              <1> ;	INVALID FUNCTION REQUESTED OR INVALID DRIVE: 
  1115                              <1> ;	SET BAD COMMAND IN STATUS.
  1116                              <1> ;
  1117                              <1> ; ON EXIT: 	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  1118                              <1> ;-------------------------------------------------------------------------------
  1119                              <1> FNC_ERR:				; INVALID FUNCTION REQUEST
  1120                              <1> 	;mov	ax, si
  1121                              <1> 	; 06/08/2022
  1122 000044E1 89F0                <1> 	mov	eax, esi		; RESTORE AL
  1123 000044E3 B401                <1> 	mov	ah, BAD_CMD		; SET BAD COMMAND ERROR
  1124 000044E5 8825[487D0100]      <1> 	mov	[DSKETTE_STATUS], ah	; STORE IN DATA AREA
  1125 000044EB F9                  <1> 	stc				; SET CARRY INDICATING ERROR
  1126 000044EC C3                  <1> 	retn
  1127                              <1> 
  1128                              <1> ; 06/08/2022 - TRDOS 386 Kernel v2.0.5
  1129                              <1> ; 30/08/2020
  1130                              <1> ; 29/08/2020
  1131                              <1> ; 01/06/2016
  1132                              <1> ; 28/05/2016
  1133                              <1> ; 27/05/2016 - TRDOS 386 (TRDOS v.2.0)
  1134                              <1> ;-------------------------------------------------------------------------------
  1135                              <1> ; DISK_PARMS	(AH = 08H)	
  1136                              <1> ;	READ DRIVE PARAMETERS.
  1137                              <1> ;
  1138                              <1> ; ON ENTRY:	DI : DRIVE #
  1139                              <1> ;		; 27/05/2016
  1140                              <1> ;		EBX = Buffer Address for floppy disk parameters table (16 bytes)
  1141                              <1> ;
  1142                              <1> ; ON EXIT:	CL/[BP]   = BITS 7 & 6 HI 2 BITS OF MAX CYLINDER
  1143                              <1> ;		            BITS 0-5 MAX SECTORS/TRACK
  1144                              <1> ;		CH/[BP+1] = LOW 8 BITS OF MAX CYLINDER
  1145                              <1> ;		BL/[BP+2] = BITS 7-4 = 0
  1146                              <1> ;		            BITS 3-0 = VALID CMOS DRIVE TYPE
  1147                              <1> ;		BH/[BP+3] = 0
  1148                              <1> ;		DL/[BP+4] = # DRIVES INSTALLED (VALUE CHECKED)
  1149                              <1> ;		DH/[BP+5] = MAX HEAD #
  1150                              <1> ;	     ** 27/05/2016 - TRDOS 386 (TRDOS v2.0) **	
  1151                              <1> ;            ** EBX = Buffer address for floppy disk parameters table **
  1152                              <1> ;		;DI/[BP+6] = OFFSET TO DISK_BASE
  1153                              <1> ;		;ES        = SEGMENT OF DISK_BASE
  1154                              <1> ;
  1155                              <1> ;		AX        = 0
  1156                              <1> ;
  1157                              <1> ;		NOTE : THE ABOVE INFORMATION IS STORED IN THE USERS STACK AT
  1158                              <1> ;		       THE LOCATIONS WHERE THE MAIN ROUTINE WILL POP THEM
  1159                              <1> ;		       INTO THE APPROPRIATE REGISTERS BEFORE RETURNING TO THE
  1160                              <1> ;		       CALLER.
  1161                              <1> ;-------------------------------------------------------------------------------
  1162                              <1> DSK_PARMS:
  1163                              <1> 	; 09/08/2022
  1164                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  1165                              <1> 	;
  1166                              <1> 	; Registers on stack:
  1167                              <1> 	;    ebx = esp+28
  1168                              <1> 	;    ecx = esp+24
  1169                              <1> 	;    edx = esp+20
  1170                              <1> 	;    esi = esp+16
  1171                              <1> 	;    edi = esp+12
  1172                              <1> 	;    return address from DSKETTE_IO_1 = esp+8
  1173                              <1> 	;    ebp = esp+4
  1174                              <1> 	;    return address from DSK_PARMS = esp
  1175                              <1> 	;
  1176                              <1> 	; INPUT:
  1177                              <1> 	;   ebp = buffer address
  1178                              <1> 	;   edi = drive number (0 or 1)
  1179                              <1> 	
  1180                              <1> 	; OUTPUT:
  1181                              <1> 	;   ebx = [esp+28] ((BL = cmos type, BH = 0))
  1182                              <1> 	;   ecx = [esp+24] ((CL = sectors per track, CH = tracks - 1))
  1183                              <1> 	;   edx = [esp+20] ((DL = floppy drive count, DH = heads - 1))
  1184                              <1> 	;   user's buffer = FDPT table
  1185                              <1> 			 
  1186 000044ED E86D020000          <1> 	call	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH,
  1187                              <1>      	
  1188                              <1> 	;;mov	word [bp+2], 0		; DRIVE TYPE = 0
  1189                              <1>      	;;mov	ax, [EQUIP_FLAG]	; LOAD EQUIPMENT FLAG FOR # DISKETTES
  1190                              <1>      	;;and	al, 11000001b		; KEEP DISKETTE DRIVE BITS
  1191                              <1>      	;;mov	dl, 2			; DISKETTE DRIVES = 2
  1192                              <1>      	;;cmp	al, 01000001b		; 2 DRIVES INSTALLED ?
  1193                              <1>      	;;jz	short STO_DL		; IF YES JUMP
  1194                              <1>      	;;dec	dl			; DISKETTE DRIVES = 1
  1195                              <1>      	;;cmp	al, 00000001b		; 1 DRIVE INSTALLED ?
  1196                              <1>      	;;jnz	short NON_DRV		; IF NO JUMP
  1197                              <1> 	
  1198 000044F2 29D2                <1> 	sub	edx, edx
  1199 000044F4 66A1[3C660000]      <1> 	mov     ax, [fd0_type]
  1200 000044FA 6621C0              <1> 	and     ax, ax
  1201 000044FD 747C                <1>         jz      short NON_DRV
  1202 000044FF FEC2                <1> 	inc     dl
  1203 00004501 20E4                <1> 	and     ah, ah
  1204 00004503 7402                <1> 	jz      short STO_DL
  1205 00004505 FEC2                <1> 	inc     dl
  1206                              <1> STO_DL:
  1207                              <1> 	; 30/08/2020
  1208                              <1> 	;cmp	dx, di
  1209                              <1> 	; 06/08/2022
  1210 00004507 39FA                <1> 	cmp	edx, edi
  1211 00004509 7670                <1> 	jna	short NON_DRV
  1212                              <1> 	;
  1213                              <1> 	;;mov	[bp+4], dl		; STORE NUMBER OF DRIVES
  1214                              <1> 	;mov	[ebp+8], edx ; 20/02/2015	 	
  1215                              <1> 
  1216                              <1> 	; 06/08/2022
  1217 0000450B FEC6                <1> 	inc	dh ; number of heads - 1 
  1218                              <1> 	; dh = 1
  1219                              <1> 	; dl = number of floppy/diskette drives (DL)
  1220 0000450D 89542414            <1> 	mov	[esp+20], edx
  1221                              <1> 
  1222                              <1> 	; 11/04/2021
  1223                              <1> 	;cmp	di, 1			; CHECK FOR VALID DRIVE
  1224                              <1> 	;;ja	short NON_DRV1		; DRIVE INVALID
  1225                              <1> 	;ja	NON_DRV1 ; 29/08/2020
  1226                              <1> 	;	
  1227                              <1> 	;;mov	byte [bp+5], 1		; MAXIMUM HEAD NUMBER =	1
  1228                              <1> 	; 06/08/2022
  1229                              <1> 	;mov	byte [ebp+9], 1 ; 20/02/2015	
  1230                              <1> 	
  1231 00004511 E8A7060000          <1> 	call	CMOS_TYPE		; RETURN DRIVE TYPE IN AL
  1232                              <1> 	;;20/02/2015
  1233                              <1> 	;;jc	short CHK_EST		; IF CMOS BAD CHECKSUM ESTABLISHED
  1234                              <1> 	;;or	al, al			; TEST FOR NO DRIVE TYPE
  1235 00004516 740F                <1> 	jz	short CHK_EST		; JUMP IF SO
  1236 00004518 E8DC010000          <1> 	call	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  1237 0000451D 7208                <1> 	jc	short CHK_EST		; TYPE NOT IN TABLE (POSSIBLE BAD CMOS)
  1238                              <1> 	;mov	[bp+2], al		; STORE VALID CMOS DRIVE TYPE
  1239                              <1>         ;mov	[ebp+4], al ; 06/02/2015
  1240 0000451F 8A4B04              <1> 	mov	cl, [ebx+MD.SEC_TRK]	; GET SECTOR/TRACK
  1241 00004522 8A6B0B              <1>         mov	ch, [ebx+MD.MAX_TRK]	; GET MAX. TRACK NUMBER
  1242 00004525 EB36                <1> 	jmp	short STO_CX		; CMOS GOOD, USE CMOS
  1243                              <1> CHK_EST:
  1244 00004527 8AA7[537D0100]      <1> 	mov	ah, [DSK_STATE+edi]	; LOAD STATE FOR THIS DRIVE
  1245 0000452D F6C410              <1> 	test	ah, MED_DET		; CHECK FOR ESTABLISHED STATE
  1246 00004530 744D                <1> 	jz	short NON_DRV1		; CMOS BAD/INVALID OR UNESTABLISHED
  1247                              <1> USE_EST:
  1248 00004532 80E4C0              <1> 	and	ah, RATE_MSK		; ISOLATE STATE
  1249 00004535 80FC80              <1> 	cmp	ah, RATE_250		; RATE 250 ?
  1250 00004538 755C                <1> 	jne	short USE_EST2		; NO, GO CHECK OTHER RATE
  1251                              <1> 
  1252                              <1> ;-----	DATA RATE IS 250 KBS, TRY 360 KB TABLE FIRST
  1253                              <1> 
  1254 0000453A B001                <1> 	mov	al, 1			; DRIVE TYPE 1 (360KB)
  1255 0000453C E8B8010000          <1> 	call	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  1256 00004541 8A4B04              <1>         mov	cl, [ebx+MD.SEC_TRK]	; GET SECTOR/TRACK
  1257 00004544 8A6B0B              <1>         mov	ch, [ebx+MD.MAX_TRK]	; GET MAX. TRACK NUMBER
  1258 00004547 F687[537D0100]01    <1> 	test	byte [DSK_STATE+edi], TRK_CAPA ; 80 TRACK ?
  1259 0000454E 740D                <1> 	jz	short STO_CX		; MUST BE 360KB DRIVE 
  1260                              <1> 
  1261                              <1> ;-----	IT IS 1.44 MB DRIVE
  1262                              <1> 
  1263                              <1> PARM144:
  1264 00004550 B004                <1> 	mov	al, 4			; DRIVE TYPE 4 (1.44MB)
  1265 00004552 E8A2010000          <1> 	call	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  1266 00004557 8A4B04              <1> 	mov	cl, [ebx+MD.SEC_TRK]	; GET SECTOR/TRACK
  1267 0000455A 8A6B0B              <1> 	mov	ch, [ebx+MD.MAX_TRK]	; GET MAX. TRACK NUMBER
  1268                              <1> STO_CX:
  1269                              <1> 	;mov	[ebp], ecx		; SAVE POINTER IN STACK FOR RETURN
  1270                              <1> 	; 06/08/2022
  1271 0000455D 894C2418            <1> 	mov	[esp+24], ecx ; spt (cl), tracks - 1 (ch)
  1272                              <1> ES_DI:
  1273                              <1> 	;mov	[bp+6], bx		; ADDRESS OF MEDIA/DRIVE PARM TABLE 
  1274                              <1> 	;mov	[ebp+12], ebx ; 06/02/2015
  1275                              <1> 	;mov	ax, cs			; SEGMENT MEDIA/DRIVE PARAMETER TABLE
  1276                              <1> 	;mov	es, ax			; ES IS SEGMENT OF TABLE
  1277                              <1> 	;
  1278                              <1> 	; 28/05/2016
  1279                              <1> 	; 27/05/2016
  1280                              <1> 	; return floppy disk parameters table to user
  1281                              <1> 	; in user's buffer, which is pointed by EBX
  1282                              <1> 	
  1283                              <1> 	; 09/08/2022
  1284                              <1> 	;movzx	eax, al
  1285 00004561 29C9                <1> 	sub	ecx, ecx
  1286 00004563 88C1                <1> 	mov	cl, al
  1287                              <1> 	;;mov	[ebp+4], eax  ; ebx	; drive type (for floppy drives)
  1288                              <1> 	; 06/08/2022
  1289                              <1> 	;mov	[esp+28], eax ; drive type	
  1290                              <1> 	; 09/08/2022
  1291 00004565 894C241C            <1> 	mov	[esp+28], ecx ; drive type
  1292                              <1> 
  1293                              <1> 	; 06/08/2022
  1294                              <1> 	;push	edi
  1295                              <1> 	
  1296                              <1> 	;mov	edi, [ebp+4]  		; ebx (input), user's buffer address
  1297                              <1> 	; 06/08/2022
  1298                              <1> 	;mov	edi, ebp ; [esp+28] ; user's buffer address
  1299                              <1> 	;
  1300                              <1> 	;; 29/08/2020
  1301                              <1> 	;or	edi, edi
  1302                              <1> 	;jz	short no_copy_fdpt
  1303                              <1> 	; 06/08/2022
  1304 00004569 09ED                <1> 	or	ebp, ebp ; [esp+28] = ebx ; user's buffer address if > 0
  1305 0000456B 740B                <1> 	jz	short DP_OUT
  1306                              <1> 	; 06/08/2022
  1307                              <1> 	;push	edi
  1308 0000456D 89EF                <1> 	mov	edi, ebp
  1309                              <1> 	;
  1310                              <1> 	; 06/08/2022
  1311                              <1> 	; 01/06/2016 (Int 33h, disk type return for floppy disks, in BL)
  1312                              <1> 	;mov	[user_buffer], eax	; 01/06/2016 (overwrite ebx return value)
  1313                              <1> 	
  1314                              <1> 	;(Int 33h, Function 08h will replace user's buffer addr with disk type!)
  1315                              <1> 	;
  1316 0000456F 89DE                <1> 	mov	esi, ebx 		; floppy disk parameter table (16 bytes)
  1317                              <1> 	;mov	ecx, 16 ; 16 bytes
  1318                              <1>         ; 09/08/2022
  1319                              <1> 	; ecx < 256
  1320                              <1> 	; 06/08/2022
  1321                              <1> 	;sub	ecx, ecx
  1322 00004571 B110                <1> 	mov	cl, 16
  1323 00004573 E818CA0000          <1> 	call    transfer_to_user_buffer ; trdosk6.s (16/05/2016)
  1324                              <1> no_copy_fdpt:
  1325                              <1> 	; 06/08/2022
  1326                              <1> 	;pop	edi	
  1327                              <1> DP_OUT:
  1328                              <1> 	; 06/08/2022
  1329                              <1> 	;call	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  1330                              <1> 	;xor	ax, ax			; CLEAR
  1331                              <1> 	; 06/08/2022
  1332 00004578 31C0                <1> 	xor	eax, eax
  1333                              <1> 	;clc
  1334 0000457A C3                  <1> 	retn
  1335                              <1> 
  1336                              <1> ;-----	NO DRIVE PRESENT HANDLER
  1337                              <1> 
  1338                              <1> NON_DRV:
  1339                              <1> 	;;mov	byte [bp+4], 0		; CLEAR NUMBER OF DRIVES
  1340                              <1> 	;mov	[ebp+8], edx ; 0 ; 20/02/2015
  1341                              <1> 	; 06/08/2022
  1342 0000457B 89542414            <1> 	mov	[esp+20], edx ; 0 ; number of floppy drives and heads are 0
  1343                              <1> NON_DRV1:
  1344 0000457F 6681FF8000          <1> 	cmp	di, 80h			; CHECK FOR FIXED MEDIA TYPE REQUEST
  1345 00004584 7206                <1> 	jb	short NON_DRV2		; CONTINUE IF NOT REQUEST FALL THROUGH
  1346                              <1> 
  1347                              <1> ;-----	FIXED DISK REQUEST FALL THROUGH ERROR
  1348                              <1> 	
  1349                              <1> 	; 06/08/2022
  1350                              <1> 	;call	XLAT_OLD		; ELSE TRANSLATE TO COMPATIBLE MODE
  1351                              <1> 	;mov	ax, si			; RESTORE AL
  1352                              <1> 	; 06/08/2022
  1353 00004586 89F0                <1> 	mov	eax, esi
  1354 00004588 B401                <1> 	mov	ah, BAD_CMD		; SET BAD COMMAND ERROR
  1355 0000458A F9                  <1> 	stc
  1356 0000458B C3                  <1> 	retn
  1357                              <1> 
  1358                              <1> NON_DRV2:
  1359                              <1> 	;xor	ax, ax			; CLEAR PARMS IF NO DRIVES OR CMOS BAD
  1360 0000458C 31C0                <1> 	xor	eax, eax	
  1361                              <1> 	;mov	[ebp], ax		; TRACKS, SECTORS/TRACK = 0
  1362                              <1> 	; 06/08/2022
  1363 0000458E 89442418            <1> 	mov	[esp+24], eax ; spt and max. track number is 0
  1364                              <1> 
  1365                              <1> 	;;mov	[bp+5], ah		; HEAD = 0
  1366                              <1> 	; 06/08/2022
  1367                              <1> 	;mov	[ebp+9], ah ; 06/02/2015
  1368                              <1> 	; 06/08/2022
  1369                              <1> 	;mov	[esp+21], ah ; 0	
  1370                              <1> 
  1371                              <1> 	;;mov	[bp+6], ax		; OFFSET TO DISK_BASE = 0
  1372                              <1> 	; 06/08/2022
  1373                              <1> 	;mov	[ebp+12], eax
  1374                              <1> 	
  1375                              <1> 	;;mov	es, ax			; ES IS SEGMENT OF TABLE
  1376                              <1> 	;jmp	short DP_OUT
  1377                              <1> 
  1378                              <1> 	; 06/08/2022
  1379                              <1> 	; 30/08/2020
  1380                              <1> 	;call	XLAT_OLD
  1381                              <1> 	;;mov	ah, NOT_RDY ; drive not ready
  1382 00004592 B407                <1> 	mov	ah, INIT_FAIL ; DRIVE PARAMETER ACTIVITY FAILED 
  1383 00004594 F9                  <1> 	stc	; cf -> 1, ah = 'drive not ready' error code
  1384 00004595 C3                  <1> 	retn		
  1385                              <1> 
  1386                              <1> ;-----	DATA RATE IS EITHER 300 KBS OR 500 KBS, TRY 1.2 MB TABLE FIRST
  1387                              <1> 
  1388                              <1> USE_EST2:
  1389 00004596 B002                <1> 	mov	al, 2			; DRIVE TYPE 2 (1.2MB)
  1390 00004598 E85C010000          <1> 	call	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  1391 0000459D 8A4B04              <1>         mov     cl, [ebx+MD.SEC_TRK]    ; GET SECTOR/TRACK
  1392 000045A0 8A6B0B              <1>         mov     ch, [ebx+MD.MAX_TRK]    ; GET MAX. TRACK NUMBER
  1393 000045A3 80FC40              <1> 	cmp	ah, RATE_300		; RATE 300 ?
  1394 000045A6 74B5                <1> 	jz	short STO_CX		; MUST BE 1.2MB DRIVE
  1395 000045A8 EBA6                <1> 	jmp	short PARM144		; ELSE, IT IS 1.44MB DRIVE 
  1396                              <1> 
  1397                              <1> ; 30/08/2020
  1398                              <1> 
  1399                              <1> ;-------------------------------------------------------------------------------
  1400                              <1> ; DISK_TYPE (AH = 15H)	
  1401                              <1> ;	THIS ROUTINE RETURNS THE TYPE OF MEDIA INSTALLED.
  1402                              <1> ;
  1403                              <1> ;  ON ENTRY:	DI = DRIVE #
  1404                              <1> ;
  1405                              <1> ;  ON EXIT:	AH = DRIVE TYPE, CY=0
  1406                              <1> ;-------------------------------------------------------------------------------
  1407                              <1> DSK_TYPE:
  1408                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  1409 000045AA E8B0010000          <1> 	call	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  1410 000045AF 8A87[537D0100]      <1> 	mov	al, [DSK_STATE+edi]	; GET PRESENT STATE INFORMATION
  1411 000045B5 08C0                <1> 	or	al, al			; CHECK FOR NO DRIVE
  1412 000045B7 740D                <1> 	jz	short NO_DRV
  1413 000045B9 B401                <1> 	mov	ah, NOCHGLN		; NO CHANGE LINE FOR 40 TRACK DRIVE
  1414 000045BB A801                <1> 	test	al, TRK_CAPA		; IS THIS DRIVE AN 80 TRACK DRIVE?
  1415 000045BD 7402                <1> 	jz	short DT_BACK		; IF NO JUMP
  1416 000045BF B402                <1> 	mov	ah, CHGLN		; CHANGE LINE FOR 80 TRACK DRIVE
  1417                              <1> DT_BACK:
  1418                              <1> 	; 06/08/2022
  1419                              <1> 	;;push	ax			; SAVE RETURN VALUE
  1420                              <1> 	; 11/04/2021
  1421                              <1> 	;push	eax
  1422                              <1> 	;call	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  1423                              <1> 	;; 11/04/2021
  1424                              <1> 	;pop	eax
  1425                              <1> 	;; pop	ax
  1426                              <1> 	;clc				; NO ERROR
  1427                              <1> 	;mov	bx, si			; GET SAVED AL TO BL
  1428                              <1> 	; 06/08/2022
  1429 000045C1 89F3                <1> 	mov	ebx, esi
  1430 000045C3 88D8                <1> 	mov	al, bl			; PUT BACK FOR RETURN
  1431 000045C5 C3                  <1> 	retn
  1432                              <1> NO_DRV:	
  1433                              <1> 	;xor	ah, ah			; NO DRIVE PRESENT OR UNKNOWN
  1434                              <1> 	;jmp	short DT_BACK
  1435                              <1> 	
  1436                              <1> 	; 06/08/2022
  1437                              <1> 	; 30/08/2020
  1438                              <1> 	;call	XLAT_OLD
  1439 000045C6 29C0                <1> 	sub	eax, eax
  1440 000045C8 F9                  <1> 	stc	; cf = 1 -> drive not ready, ah = 0 (disk type = 0)
  1441 000045C9 C3                  <1> 	retn
  1442                              <1> 
  1443                              <1> ;-------------------------------------------------------------------------------
  1444                              <1> ; DISK_CHANGE	(AH = 16H)
  1445                              <1> ;	THIS ROUTINE RETURNS THE STATE OF THE DISK CHANGE LINE.
  1446                              <1> ;
  1447                              <1> ; ON ENTRY:	DI = DRIVE #
  1448                              <1> ;
  1449                              <1> ; ON EXIT:	AH = @DSKETTE_STATUS
  1450                              <1> ;		     00 - DISK CHANGE LINE INACTIVE, CY = 0
  1451                              <1> ;		     06 - DISK CHANGE LINE ACTIVE, CY = 1
  1452                              <1> ;-------------------------------------------------------------------------------
  1453                              <1> DSK_CHANGE:
  1454                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  1455 000045CA E890010000          <1> 	call	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  1456 000045CF 8A87[537D0100]      <1> 	mov	al, [DSK_STATE+edi]	; GET MEDIA STATE INFORMATION
  1457 000045D5 08C0                <1> 	or	al, al			; DRIVE PRESENT ?
  1458 000045D7 7417                <1> 	jz	short DC_NON		; JUMP IF NO DRIVE
  1459 000045D9 A801                <1> 	test	al, TRK_CAPA		; 80 TRACK DRIVE ?
  1460 000045DB 7407                <1> 	jz	short SETIT		; IF SO , CHECK CHANGE LINE
  1461                              <1> DC0:
  1462 000045DD E86B080000          <1>         call    READ_DSKCHNG            ; GO CHECK STATE OF DISK CHANGE LINE
  1463 000045E2 7407                <1> 	jz	short FINIS		; CHANGE LINE NOT ACTIVE
  1464                              <1> SETIT:	
  1465 000045E4 C605[487D0100]06    <1> 	mov	byte [DSKETTE_STATUS], MEDIA_CHANGE ; INDICATE MEDIA REMOVED
  1466                              <1> 
  1467                              <1> FINIS:	; 06/08/2022
  1468                              <1> 	;call	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  1469                              <1> 	; 06/08/2022
  1470 000045EB E938FDFFFF          <1> 	jmp	SETUP_END_X
  1471                              <1> 	;call	SETUP_END		; VARIOUS CLEANUPS
  1472                              <1> 	;; 06/08/2022
  1473                              <1> 	;mov	ebx, esi		; GET SAVED AL TO BL
  1474                              <1> 	;mov	al, bl			; PUT BACK FOR RETURN
  1475                              <1> 	;retn
  1476                              <1> DC_NON:
  1477 000045F0 800D[487D0100]80    <1> 	or	byte [DSKETTE_STATUS], TIME_OUT ; SET TIMEOUT, NO DRIVE
  1478 000045F7 EBF2                <1> 	jmp	short FINIS
  1479                              <1> 
  1480                              <1> ;-------------------------------------------------------------------------------
  1481                              <1> ; FORMAT_SET	(AH = 17H)
  1482                              <1> ;	THIS ROUTINE IS USED TO ESTABLISH THE TYPE OF MEDIA TO BE USED
  1483                              <1> ;	FOR THE FOLLOWING FORMAT OPERATION.
  1484                              <1> ;
  1485                              <1> ; ON ENTRY:	SI LOW = DASD TYPE FOR FORMAT
  1486                              <1> ;		DI     = DRIVE #
  1487                              <1> ;
  1488                              <1> ; ON EXIT:	@DSKETTE_STATUS REFLECTS STATUS
  1489                              <1> ;		AH = @DSKETTE_STATUS
  1490                              <1> ;		CY = 1 IF ERROR
  1491                              <1> ;-------------------------------------------------------------------------------
  1492                              <1> FORMAT_SET:
  1493 000045F9 E861010000          <1> 	call	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  1494                              <1> 	;push	si			; SAVE DASD TYPE
  1495                              <1> 	; 11/04/2021
  1496 000045FE 56                  <1> 	push	esi
  1497                              <1> 	;mov	ax, si			; AH = ? , AL = DASD TYPE
  1498                              <1> 	;xor	ah, ah			; AH = 0 , AL = DASD TYPE
  1499                              <1> 	;mov	si, ax			; SI = DASD TYPE
  1500                              <1> 	; 11/04/2021
  1501 000045FF 89F0                <1> 	mov	eax, esi
  1502 00004601 0FB6F0              <1> 	movzx	esi, al	
  1503 00004604 80A7[537D0100]0F    <1> 	and	byte [DSK_STATE+edi], ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR STATE
  1504                              <1> 	;dec	si			; CHECK FOR 320/360K MEDIA & DRIVE
  1505                              <1> 	; 11/04/2021
  1506 0000460B 4E                  <1> 	dec	esi
  1507 0000460C 7509                <1> 	jnz	short NOT_320		; BYPASS IF NOT
  1508 0000460E 808F[537D0100]90    <1> 	or	byte [DSK_STATE+edi], MED_DET+RATE_250 ; SET TO 320/360
  1509 00004615 EB45                <1> 	jmp	short S0
  1510                              <1> 
  1511                              <1> NOT_320:
  1512 00004617 E844020000          <1> 	call	MED_CHANGE		; CHECK FOR TIME_OUT
  1513 0000461C 803D[487D0100]80    <1> 	cmp	byte [DSKETTE_STATUS], TIME_OUT
  1514 00004623 7437                <1> 	jz	short S0		; IF TIME OUT TELL CALLER
  1515                              <1> S3:
  1516                              <1> 	;dec	si			; CHECK FOR 320/360K IN 1.2M DRIVE
  1517                              <1> 	; 11/04/2021
  1518 00004625 4E                  <1> 	dec	esi
  1519 00004626 7509                <1> 	jnz	short NOT_320_12	; BYPASS IF NOT
  1520 00004628 808F[537D0100]70    <1> 	OR	byte [DSK_STATE+edi], MED_DET+DBL_STEP+RATE_300 ; SET STATE
  1521 0000462F EB2B                <1> 	jmp	short S0
  1522                              <1> 
  1523                              <1> NOT_320_12:
  1524                              <1> 	;dec	si			; CHECK FOR 1.2M MEDIA IN 1.2M DRIVE
  1525                              <1> 	; 11/04/2021
  1526 00004631 4E                  <1> 	dec	esi
  1527 00004632 7509                <1> 	jnz	short NOT_12		; BYPASS IF NOT
  1528 00004634 808F[537D0100]10    <1> 	or	byte [DSK_STATE+edi], MED_DET+RATE_500 ; SET STATE VARIABLE
  1529 0000463B EB1F                <1> 	jmp	short S0		; RETURN TO CALLER
  1530                              <1> 
  1531                              <1> NOT_12:	
  1532                              <1> 	;dec	si			; CHECK FOR SET DASD TYPE 04
  1533                              <1> 	; 11/04/2021
  1534 0000463D 4E                  <1> 	dec	esi
  1535 0000463E 7525                <1> 	jnz	short FS_ERR		; BAD COMMAND EXIT IF NOT VALID TYPE
  1536                              <1> 
  1537 00004640 F687[537D0100]04    <1> 	test	byte [DSK_STATE+edi], DRV_DET ; DRIVE DETERMINED ?
  1538 00004647 740B                <1> 	jz	short ASSUME		; IF STILL NOT DETERMINED ASSUME
  1539 00004649 B050                <1> 	mov	al, MED_DET+RATE_300
  1540 0000464B F687[537D0100]02    <1>         test    byte [DSK_STATE+edi], FMT_CAPA ; MULTIPLE FORMAT CAPABILITY ?
  1541 00004652 7502                <1> 	jnz	short OR_IT_IN		; IF 1.2 M THEN DATA RATE 300
  1542                              <1> 
  1543                              <1> ASSUME:
  1544 00004654 B090                <1> 	mov	al, MED_DET+RATE_250	; SET UP
  1545                              <1> 
  1546                              <1> OR_IT_IN:
  1547 00004656 0887[537D0100]      <1> 	or	[DSK_STATE+edi], al	; OR IN THE CORRECT STATE
  1548                              <1> S0:
  1549                              <1> 	; 06/08/2022
  1550                              <1> 	;call	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  1551 0000465C E8D5FDFFFF          <1> 	call	SETUP_END		; VARIOUS CLEANUPS
  1552                              <1> 	;pop	BX			; GET SAVED AL TO BL
  1553                              <1> 	; 11/04/2021
  1554 00004661 5B                  <1> 	pop	ebx
  1555 00004662 88D8                <1> 	mov	al, bl			; PUT BACK FOR RETURN
  1556 00004664 C3                  <1> 	retn
  1557                              <1> 
  1558                              <1> FS_ERR:
  1559 00004665 C605[487D0100]01    <1> 	mov	byte [DSKETTE_STATUS], BAD_CMD ; UNKNOWN STATE,BAD COMMAND
  1560 0000466C EBEE                <1> 	jmp	short S0
  1561                              <1> 
  1562                              <1> ;-------------------------------------------------------------------------------
  1563                              <1> ; SET_MEDIA	(AH = 18H)
  1564                              <1> ;	THIS ROUTINE SETS THE TYPE OF MEDIA AND DATA RATE 
  1565                              <1> ;	TO BE USED FOR THE FOLLOWING FORMAT OPERATION.
  1566                              <1> ;
  1567                              <1> ; ON ENTRY:
  1568                              <1> ;	[BP]	= SECTOR PER TRACK
  1569                              <1> ;	[BP+1]	= TRACK #
  1570                              <1> ;	DI	= DRIVE #
  1571                              <1> ;
  1572                              <1> ; ON EXIT:
  1573                              <1> ;	@DSKETTE_STATUS REFLECTS STATUS
  1574                              <1> ;	IF NO ERROR:
  1575                              <1> ;		AH = 0
  1576                              <1> ;		CY = 0
  1577                              <1> ;		ES = SEGMENT OF MEDIA/DRIVE PARAMETER TABLE
  1578                              <1> ;		DI/[BP+6] = OFFSET OF MEDIA/DRIVE PARAMETER TABLE
  1579                              <1> ;	IF ERROR:	
  1580                              <1> ;		AH = @DSKETTE_STATUS
  1581                              <1> ;		CY = 1
  1582                              <1> ;-------------------------------------------------------------------------------
  1583                              <1> SET_MEDIA:
  1584                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  1585 0000466E E8EC000000          <1> 	call	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH.
  1586 00004673 F687[537D0100]01    <1>         test    byte [DSK_STATE+edi], TRK_CAPA ; CHECK FOR CHANGE LINE AVAILABLE
  1587 0000467A 7415                <1> 	jz	short SM_CMOS		; JUMP IF 40 TRACK DRIVE
  1588 0000467C E8DF010000          <1> 	call	MED_CHANGE		; RESET CHANGE LINE
  1589 00004681 803D[487D0100]80    <1> 	cmp	byte [DSKETTE_STATUS], TIME_OUT ; IF TIME OUT TELL CALLER
  1590 00004688 746A                <1> 	je	short SM_RTN
  1591 0000468A C605[487D0100]00    <1> 	mov	byte [DSKETTE_STATUS], 0 ; CLEAR STATUS
  1592                              <1> SM_CMOS:
  1593 00004691 E827050000          <1> 	call	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  1594                              <1> 	;;20/02/2015
  1595                              <1> 	;;jc	short MD_NOT_FND	; ERROR IN CMOS
  1596                              <1> 	;;or	al, al			; TEST FOR NO DRIVE
  1597 00004696 745C                <1> 	jz	short SM_RTN		; RETURN IF SO
  1598 00004698 E85C000000          <1> 	call	DR_TYPE_CHECK		; RTN CS:BX = MEDIA/DRIVE PARAM TBL
  1599 0000469D 7233                <1> 	jc	short MD_NOT_FND	; TYPE NOT IN TABLE (BAD CMOS)
  1600 0000469F 57                  <1> 	push	edi			; SAVE REG.
  1601 000046A0 31DB                <1> 	xor	ebx, ebx		; BX = INDEX TO DR. TYPE TABLE
  1602 000046A2 B906000000          <1> 	mov	ecx, DR_CNT		; CX = LOOP COUNT
  1603                              <1> DR_SEARCH:
  1604 000046A7 8AA3[B8650000]      <1> 	mov	ah, [DR_TYPE+ebx]	; GET DRIVE TYPE
  1605 000046AD 80E47F              <1> 	and	ah, BIT7OFF		; MASK OUT MSB
  1606 000046B0 38E0                <1> 	cmp	al, ah			; DRIVE TYPE MATCH ?
  1607 000046B2 7518                <1> 	jne	short NXT_MD		; NO, CHECK NEXT DRIVE TYPE
  1608                              <1> DR_FND:
  1609 000046B4 8BBB[B9650000]      <1> 	mov	edi, [DR_TYPE+ebx+1] 	; DI = MEDIA/DRIVE PARAM TABLE
  1610                              <1> MD_SEARCH:
  1611 000046BA 8A6704              <1>         mov	ah, [edi+MD.SEC_TRK]    ; GET SECTOR/TRACK
  1612                              <1> 	;cmp	[ebp], ah		; MATCH?
  1613                              <1> 	; 06/08/2022
  1614 000046BD 38642418            <1> 	cmp	[esp+24], ah  ; CL ; spt	
  1615 000046C1 7509                <1> 	jne	short NXT_MD		; NO, CHECK NEXT MEDIA
  1616 000046C3 8A670B              <1>         mov     ah, [edi+MD.MAX_TRK]    ; GET MAX. TRACK #
  1617                              <1> 	;cmp 	[ebp+1], ah		; MATCH?
  1618                              <1> 	; 06/08/2022
  1619 000046C6 38642419            <1> 	cmp	[esp+25], ah  ; CH ; heads - 1
  1620 000046CA 740F                <1> 	je	short MD_FND		; YES, GO GET RATE
  1621                              <1> NXT_MD:
  1622                              <1> 	;add	bx, 3			; CHECK NEXT DRIVE TYPE
  1623 000046CC 83C305              <1>         add	ebx, 5 ; 18/02/2015
  1624 000046CF E2D6                <1> 	loop	DR_SEARCH
  1625 000046D1 5F                  <1> 	pop	edi			; RESTORE REG.
  1626                              <1> MD_NOT_FND:
  1627 000046D2 C605[487D0100]0C    <1> 	mov	byte [DSKETTE_STATUS], MED_NOT_FND ; ERROR, MEDIA TYPE NOT FOUND
  1628 000046D9 EB19                <1> 	jmp	short SM_RTN		; RETURN
  1629                              <1> MD_FND:
  1630 000046DB 8A470C              <1>         mov	al, [edi+MD.RATE]       ; GET RATE
  1631 000046DE 3C40                <1> 	cmp	al, RATE_300		; DOUBLE STEP REQUIRED FOR RATE 300
  1632 000046E0 7502                <1> 	jne	short MD_SET
  1633 000046E2 0C20                <1> 	or	al, DBL_STEP
  1634                              <1> MD_SET:
  1635                              <1> 	;;mov	[bp+6], di		; SAVE TABLE POINTER IN STACK
  1636                              <1> 	; 06/08/2022
  1637                              <1> 	;mov	[ebp+12], edi ; 18/02/2015
  1638                              <1> 	
  1639 000046E4 0C10                <1> 	or	al, MED_DET		; SET MEDIA ESTABLISHED
  1640 000046E6 5F                  <1> 	pop	edi
  1641 000046E7 80A7[537D0100]0F    <1> 	and	byte [DSK_STATE+edi], ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR STATE
  1642 000046EE 0887[537D0100]      <1> 	or	[DSK_STATE+edi], al
  1643                              <1> 	;mov	ax, cs			; SEGMENT OF MEDIA/DRIVE PARAMETER TABLE
  1644                              <1> 	;mov	es, ax			; ES IS SEGMENT OF TABLE
  1645                              <1> SM_RTN:
  1646                              <1> 	; 06/08/2022
  1647                              <1> 	;call	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  1648                              <1> 	;call	SETUP_END		; VARIOUS CLEANUPS
  1649                              <1> 	;retn
  1650                              <1> 	; 06/08/2022
  1651 000046F4 E93DFDFFFF          <1> 	jmp	SETUP_END
  1652                              <1> 
  1653                              <1> ;----------------------------------------------------------------
  1654                              <1> ; DR_TYPE_CHECK							:
  1655                              <1> ;	CHECK IF THE GIVEN DRIVE TYPE IN REGISTER (AL)		:
  1656                              <1> ;	IS SUPPORTED IN BIOS DRIVE TYPE TABLE			:
  1657                              <1> ; ON ENTRY:							:
  1658                              <1> ;	AL = DRIVE TYPE						:
  1659                              <1> ; ON EXIT:							:
  1660                              <1> ;	CY = 0 	DRIVE TYPE SUPPORTED				:
  1661                              <1> ;	     EBX = OFFSET TO MEDIA/DRIVE PARAMETER TABLE	:
  1662                              <1> ;	CY = 1	DRIVE TYPE NOT SUPPORTED 			:
  1663                              <1> ; REGISTERS ALTERED: EBX, AH ; 11/07/2022 			:
  1664                              <1> ;----------------------------------------------------------------
  1665                              <1> DR_TYPE_CHECK:
  1666                              <1> 	; 09/08/2022 - TRDOS 386 Kernel v2.0.5 
  1667                              <1> 	; 12/07/2022
  1668                              <1> 	; 11/07/2022
  1669                              <1> 	; 08/07/2022 - Retro UNIX 386 v1.1 (Kernel v0.2.1.5)
  1670                              <1> 	; 24/12/2021
  1671                              <1> 	;push	eax ; 11/07/2022
  1672                              <1> 	;push	ecx ; 08/07/2022
  1673                              <1> 	;xor	ebx,ebx			; EBX = INDEX TO DR_TYPE TABLE
  1674 000046F9 BB[B8650000]        <1> 	mov	ebx, DR_TYPE
  1675                              <1> 	;;mov	ecx, DR_CNT		; ECX = LOOP COUNT
  1676                              <1> 	;mov	cl, DR_CNT
  1677 000046FE B406                <1> 	mov	ah, DR_CNT ; 11/07/2022
  1678                              <1> TYPE_CHK:	
  1679                              <1> 	;;mov	ah, [DR_TYPE+ebx]	; GET DRIVE TYPE
  1680                              <1> 	;mov	ah, [ebx]
  1681                              <1> 	;cmp	al, ah			; DRIVE TYPE MATCH?
  1682 00004700 3A03                <1> 	cmp	al, [ebx] ; 11/07/2022
  1683 00004702 740E                <1> 	je	short DR_TYPE_VALID	; YES, RETURN WITH CARRY RESET
  1684                              <1> 	; 16/02/2015 (32 bit address modification)
  1685 00004704 83C305              <1> 	add	ebx, 5			; CHECK NEXT DRIVE TYPE
  1686                              <1> 	;loop	TYPE_CHK
  1687                              <1> 	;dec	cl
  1688 00004707 FECC                <1> 	dec	ah ; 11/07/2022
  1689 00004709 75F5                <1> 	jnz	short TYPE_CHK
  1690                              <1> 	;
  1691 0000470B BB[17660000]        <1> 	mov	ebx, MD_TBL6		; 1.44MB fd parameter table
  1692                              <1> 					; Default for GET_PARM (11/12/2014)
  1693                              <1> 	;
  1694 00004710 F9                  <1> 	stc				; DRIVE TYPE NOT FOUND IN TABLE
  1695                              <1> 	;jmp	short TYPE_RTN
  1696                              <1> 	; 12/07/2022
  1697 00004711 C3                  <1> 	retn
  1698                              <1> DR_TYPE_VALID:
  1699                              <1> 	;mov	ebx, [DR_TYPE+ebx+1] 	; EBX = MEDIA TABLE
  1700 00004712 43                  <1> 	inc	ebx
  1701 00004713 8B1B                <1> 	mov	ebx, [ebx]
  1702                              <1> TYPE_RTN:
  1703                              <1> 	;pop	ecx ; 08/07/2022
  1704                              <1> 	; 24/12/2021
  1705                              <1> 	;pop	eax ; 11/07/2022
  1706 00004715 C3                  <1> 	retn	
  1707                              <1> 		
  1708                              <1> ;----------------------------------------------------------------
  1709                              <1> ; SEND_SPEC							:
  1710                              <1> ;	SEND THE SPECIFY COMMAND TO CONTROLLER USING DATA FROM	:
  1711                              <1> ;	THE DRIVE PARAMETER TABLE POINTED BY @DISK_POINTER	:
  1712                              <1> ; ON ENTRY:	@DISK_POINTER = DRIVE PARAMETER TABLE		:
  1713                              <1> ; ON EXIT:	NONE						:	
  1714                              <1> ; REGISTERS ALTERED: CX, DX					:
  1715                              <1> ;----------------------------------------------------------------		
  1716                              <1> SEND_SPEC:
  1717                              <1> 	; 06/08/2022
  1718 00004716 50                  <1> 	push	eax			; SAVE AX
  1719 00004717 B8[3D470000]        <1> 	mov	eax, SPECBAC		; LOAD ERROR ADDRESS
  1720 0000471C 50                  <1> 	push	eax			; PUSH NEC_OUT ERROR RETURN
  1721 0000471D B403                <1> 	mov	ah, 03h			; SPECIFY COMMAND
  1722 0000471F E898050000          <1> 	call	NEC_OUTPUT		; OUTPUT THE COMMAND
  1723                              <1> 	;sub	dl, dl			; FIRST SPECIFY BYTE
  1724                              <1> 	; 06/08/2022
  1725 00004724 28C0                <1> 	sub	al, al ; 0 
  1726 00004726 E89B040000          <1> 	call	GET_PARM		; GET PARAMETER TO AH
  1727 0000472B E88C050000          <1> 	call	NEC_OUTPUT		; OUTPUT THE COMMAND
  1728                              <1> 	;mov	dl, 1			; SECOND SPECIFY BYTE
  1729                              <1> 	; 06/08/2022
  1730 00004730 B001                <1> 	mov	al, 1
  1731 00004732 E88F040000          <1> 	call	GET_PARM		; GET PARAMETER TO AH
  1732 00004737 E880050000          <1> 	call	NEC_OUTPUT		; OUTPUT THE COMMAND
  1733 0000473C 58                  <1> 	pop	eax			; POP ERROR RETURN
  1734                              <1> SPECBAC:
  1735 0000473D 58                  <1> 	pop	eax			; RESTORE ORIGINAL AX VALUE
  1736 0000473E C3                  <1> 	retn
  1737                              <1> 
  1738                              <1> ;----------------------------------------------------------------
  1739                              <1> ; SEND_SPEC_MD							:
  1740                              <1> ;	SEND THE SPECIFY COMMAND TO CONTROLLER USING DATA FROM	:
  1741                              <1> ;	THE MEDIA/DRIVE PARAMETER TABLE POINTED BY (CS:BX)	:
  1742                              <1> ; ON ENTRY:	CS:BX = MEDIA/DRIVE PARAMETER TABLE		:
  1743                              <1> ; ON EXIT:	NONE						:	
  1744                              <1> ; REGISTERS ALTERED: AX						:
  1745                              <1> ;----------------------------------------------------------------		
  1746                              <1> SEND_SPEC_MD:
  1747 0000473F 50                  <1> 	push	eax			; SAVE RATE DATA
  1748 00004740 B8[5D470000]        <1> 	mov	eax, SPEC_ESBAC		; LOAD ERROR ADDRESS
  1749 00004745 50                  <1> 	push	eax			; PUSH NEC_OUT ERROR RETURN
  1750 00004746 B403                <1> 	mov	ah, 03h			; SPECIFY COMMAND
  1751 00004748 E86F050000          <1> 	call	NEC_OUTPUT		; OUTPUT THE COMMAND
  1752 0000474D 8A23                <1>         mov     ah, [ebx+MD.SPEC1]      ; GET 1ST SPECIFY BYTE
  1753 0000474F E868050000          <1> 	call	NEC_OUTPUT		; OUTPUT THE COMMAND
  1754 00004754 8A6301              <1>         mov     ah, [ebx+MD.SPEC2]      ; GET SECOND SPECIFY BYTE
  1755 00004757 E860050000          <1> 	call	NEC_OUTPUT		; OUTPUT THE COMMAND
  1756 0000475C 58                  <1> 	pop	eax			; POP ERROR RETURN
  1757                              <1> SPEC_ESBAC:
  1758 0000475D 58                  <1> 	pop	eax			; RESTORE ORIGINAL AX VALUE
  1759 0000475E C3                  <1> 	retn
  1760                              <1> 
  1761                              <1> ;-------------------------------------------------------------------------------
  1762                              <1> ; XLAT_NEW  
  1763                              <1> ;	TRANSLATES DISKETTE STATE LOCATIONS FROM COMPATIBLE
  1764                              <1> ;	MODE TO NEW ARCHITECTURE.
  1765                              <1> ;
  1766                              <1> ; ON ENTRY:	DI = DRIVE #
  1767                              <1> ;-------------------------------------------------------------------------------
  1768                              <1> XLAT_NEW:
  1769                              <1> 	; 06/08/2022 - TRDOS 386 Kernel v2.0.5
  1770                              <1> 	; 11/07/2022 - Retro UNIX 386 v1.1 (Kernel v0.2.1.5)
  1771 0000475F 83FF01              <1> 	cmp	edi, 1			; VALID DRIVE
  1772 00004762 7709                <1> 	ja	short XN_OUT		; IF INVALID BACK
  1773 00004764 80BF[537D0100]00    <1> 	cmp	byte [DSK_STATE+edi], 0	; NO DRIVE ?
  1774 0000476B 7401                <1> 	jz	short DO_DET		; IF NO DRIVE ATTEMPT DETERMINE
  1775                              <1> 	
  1776                              <1> 	;;mov	cx, di			; CX = DRIVE NUMBER
  1777                              <1> 	;mov	ecx, edi
  1778                              <1> 	;or	cl, cl
  1779                              <1> 	;jz	short XN_0
  1780                              <1> 	;shl	cl, 2			; CL = SHIFT COUNT, A=0, B=4
  1781                              <1> 	;mov	al, [HF_CNTRL]		; DRIVE INFORMATION
  1782                              <1> 	;ror	al, cl			; TO LOW NIBBLE
  1783                              <1> ;XN_0:	
  1784                              <1> 	;and	al, DRV_DET+FMT_CAPA+TRK_CAPA ; KEEP DRIVE BITS
  1785                              <1>         ;and	byte [DSK_STATE+edi], ~(DRV_DET+FMT_CAPA+TRK_CAPA)
  1786                              <1> 	;or	[DSK_STATE+edi], al	; UPDATE DRIVE STATE
  1787                              <1> XN_OUT:
  1788 0000476D C3                  <1> 	retn
  1789                              <1> 
  1790                              <1> DO_DET:
  1791                              <1> 	;call	DRIVE_DET		; TRY TO DETERMINE
  1792                              <1> 	;retn
  1793                              <1> 	;jmp	DRIVE_DET
  1794                              <1> 
  1795                              <1> ;-------------------------------------------------------------------------------
  1796                              <1> ; DRIVE_DET
  1797                              <1> ;	DETERMINES WHETHER DRIVE IS 80 OR 40 TRACKS AND
  1798                              <1> ;	UPDATES STATE INFORMATION ACCORDINGLY.
  1799                              <1> ; ON ENTRY:	DI = DRIVE #
  1800                              <1> ;-------------------------------------------------------------------------------
  1801                              <1> DRIVE_DET:
  1802                              <1> 	; 06/08/2022 - TRDOS 386 Kernel v2.0.5
  1803                              <1> 	; 08/07/2022 - Retro UNIX 386 v1.1 (Kernel v0.2.1.5)
  1804 0000476E E88E040000          <1> 	call	MOTOR_ON		; TURN ON MOTOR IF NOT ALREADY ON
  1805 00004773 E8FA050000          <1> 	call	RECAL			; RECALIBRATE DRIVE
  1806 00004778 724E                <1> 	jc	short DD_BAC		; ASSUME NO DRIVE PRESENT
  1807 0000477A B530                <1> 	mov	ch, TRK_SLAP		; SEEK TO TRACK 48
  1808 0000477C E872050000          <1> 	call	SEEK
  1809 00004781 7245                <1> 	jc	short DD_BAC		; ERROR NO DRIVE
  1810 00004783 B50B                <1> 	mov	ch, QUIET_SEEK+1	; SEEK TO TRACK 10
  1811                              <1> SK_GIN:
  1812 00004785 FECD                <1> 	dec	ch			; DECREMENT TO NEXT TRACK
  1813                              <1> 	;push	cx			; SAVE TRACK
  1814                              <1> 	; 11/04/2021
  1815 00004787 51                  <1> 	push	ecx
  1816 00004788 E866050000          <1> 	call	SEEK
  1817 0000478D 723A                <1> 	jc	short POP_BAC		; POP AND RETURN
  1818 0000478F B8[C9470000]        <1> 	mov	eax, POP_BAC		; LOAD NEC OUTPUT ERROR ADDRESS
  1819 00004794 50                  <1> 	push	eax
  1820 00004795 B404                <1> 	mov	ah, SENSE_DRV_ST	; SENSE DRIVE STATUS COMMAND BYTE
  1821 00004797 E820050000          <1> 	call	NEC_OUTPUT		; OUTPUT TO NEC
  1822                              <1> 	;mov	ax, di			; AL = DRIVE
  1823                              <1> 	; 06/08/2022
  1824 0000479C 89F8                <1> 	mov	eax, edi
  1825 0000479E 88C4                <1> 	mov	ah, al			; AH = DRIVE
  1826 000047A0 E817050000          <1> 	call	NEC_OUTPUT		; OUTPUT TO NEC
  1827 000047A5 E849060000          <1> 	call	RESULTS			; GO GET STATUS
  1828 000047AA 58                  <1> 	pop	eax			; THROW AWAY ERROR ADDRESS
  1829                              <1> 	;pop	cx			; RESTORE TRACK
  1830                              <1> 	; 11/04/2021
  1831 000047AB 59                  <1> 	pop	ecx
  1832 000047AC F605[497D0100]10    <1> 	test	byte [NEC_STATUS], HOME	; TRACK 0 ?
  1833 000047B3 74D0                <1> 	jz	short SK_GIN		; GO TILL TRACK 0
  1834 000047B5 08ED                <1> 	or	ch, ch			; IS HOME AT TRACK 0
  1835 000047B7 7408                <1> 	jz	short IS_80		; MUST BE 80 TRACK DRIVE
  1836                              <1> 
  1837                              <1> ;	DRIVE IS A 360; SET DRIVE TO DETERMINED;
  1838                              <1> ;	SET MEDIA TO DETERMINED AT RATE 250.
  1839                              <1> 
  1840 000047B9 808F[537D0100]94    <1> 	or	byte [DSK_STATE+edi], DRV_DET+MED_DET+RATE_250
  1841 000047C0 C3                  <1> 	retn				; ALL INFORMATION SET
  1842                              <1> IS_80:
  1843 000047C1 808F[537D0100]01    <1> 	or	byte [DSK_STATE+edi], TRK_CAPA ; SETUP 80 TRACK CAPABILITY
  1844                              <1> DD_BAC:
  1845 000047C8 C3                  <1> 	retn
  1846                              <1> POP_BAC:
  1847                              <1> 	;pop	cx			; THROW AWAY
  1848                              <1> 	; 11/04/2021
  1849 000047C9 59                  <1> 	pop	ecx
  1850 000047CA C3                  <1> 	retn
  1851                              <1> 
  1852                              <1> 
  1853                              <1> 	; 06/08/2022 - TRDOS 386 Kernel v2.0.5
  1854                              <1> 
  1855                              <1> %if 0
  1856                              <1> 
  1857                              <1> ;-------------------------------------------------------------------------------
  1858                              <1> ; XLAT_OLD 
  1859                              <1> ;	TRANSLATES DISKETTE STATE LOCATIONS FROM NEW
  1860                              <1> ;	ARCHITECTURE TO COMPATIBLE MODE.
  1861                              <1> ;
  1862                              <1> ; ON ENTRY:	DI = DRIVE
  1863                              <1> ;-------------------------------------------------------------------------------
  1864                              <1> XLAT_OLD:
  1865                              <1> 	cmp	edi, 1			; VALID DRIVE ?
  1866                              <1> 	ja	short XO_OUT            ; IF INVALID BACK
  1867                              <1>         cmp	byte [DSK_STATE+edi], 0	; NO DRIVE ?
  1868                              <1> 	jz	short XO_OUT		; IF NO DRIVE TRANSLATE DONE
  1869                              <1> 
  1870                              <1> ;-----	TEST FOR SAVED DRIVE INFORMATION ALREADY SET
  1871                              <1> 
  1872                              <1> 	;mov	cx, di			; CX = DRIVE NUMBER
  1873                              <1> 	; 06/08/2022
  1874                              <1> 	mov	ecx, edi
  1875                              <1> 	shl	cl, 2			; CL = SHIFT COUNT, A=0, B=4
  1876                              <1> 	mov	ah, FMT_CAPA		; LOAD MULTIPLE DATA RATE BIT MASK
  1877                              <1> 	ror	ah, cl			; ROTATE BY MASK
  1878                              <1> 	test	[HF_CNTRL], ah		; MULTIPLE-DATA RATE DETERMINED ?
  1879                              <1> 	jnz	short SAVE_SET		; IF SO, NO NEED TO RE-SAVE
  1880                              <1> 
  1881                              <1> ;-----	ERASE DRIVE BITS IN @HF_CNTRL FOR THIS DRIVE
  1882                              <1> 
  1883                              <1> 	mov	ah, DRV_DET+FMT_CAPA+TRK_CAPA ; MASK TO KEEP
  1884                              <1> 	ror	ah, cl			; FIX MASK TO KEEP
  1885                              <1> 	not	ah			; TRANSLATE MASK
  1886                              <1> 	and	[HF_CNTRL], ah		; KEEP BITS FROM OTHER DRIVE INTACT
  1887                              <1> 
  1888                              <1> ;-----	ACCESS CURRENT DRIVE BITS AND STORE IN @HF_CNTRL
  1889                              <1> 
  1890                              <1> 	mov	al, [DSK_STATE+edi]	; ACCESS STATE
  1891                              <1> 	and	al, DRV_DET+FMT_CAPA+TRK_CAPA ; KEEP DRIVE BITS
  1892                              <1> 	ror	al, cl			; FIX FOR THIS DRIVE
  1893                              <1> 	or	[HF_CNTRL], al		; UPDATE SAVED DRIVE STATE
  1894                              <1> 
  1895                              <1> ;-----	TRANSLATE TO COMPATIBILITY MODE
  1896                              <1> 
  1897                              <1> SAVE_SET:
  1898                              <1> 	mov	ah, [DSK_STATE+edi]	; ACCESS STATE
  1899                              <1> 	mov	bh, ah			; TO BH FOR LATER
  1900                              <1> 	and	ah, RATE_MSK		; KEEP ONLY RATE
  1901                              <1> 	cmp	ah, RATE_500		; RATE 500 ?
  1902                              <1> 	jz	short CHK_144		; YES 1.2/1.2 OR 1.44/1.44
  1903                              <1> 	mov	al, M3D1U		; AL = 360 IN 1.2 UNESTABLISHED
  1904                              <1> 	cmp	ah, RATE_300		; RATE 300 ?
  1905                              <1> 	jnz	short CHK_250		; NO, 360/360, 720/720 OR 720/1.44
  1906                              <1> 	test	bh, DBL_STEP		; CHECK FOR DOUBLE STEP
  1907                              <1> 	jnz	short TST_DET		; MUST BE 360 IN 1.2
  1908                              <1> UNKNO:
  1909                              <1> 	mov	al, MED_UNK		; NONE OF THE ABOVE
  1910                              <1> 	jmp	short AL_SET		; PROCESS COMPLETE
  1911                              <1> CHK_144:
  1912                              <1> 	call	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  1913                              <1> 	;;20/02/2015
  1914                              <1> 	;;jc	short UNKNO		; ERROR, SET 'NONE OF ABOVE'
  1915                              <1> 	jz	short UNKNO ;; 20/02/2015
  1916                              <1> 	cmp	al, 2			; 1.2MB DRIVE ?
  1917                              <1> 	jne	short UNKNO		; NO, GO SET 'NONE OF ABOVE'
  1918                              <1> 	mov	al, M1D1U		; AL = 1.2 IN 1.2 UNESTABLISHED
  1919                              <1> 	jmp	short TST_DET
  1920                              <1> CHK_250:
  1921                              <1> 	mov	al, M3D3U		; AL = 360 IN 360 UNESTABLISHED
  1922                              <1> 	cmp	ah, RATE_250		; RATE 250 ?
  1923                              <1> 	jnz	short UNKNO		; IF SO FALL IHRU
  1924                              <1> 	test	bh, TRK_CAPA		; 80 TRACK CAPABILITY ?
  1925                              <1> 	jnz	short UNKNO		; IF SO JUMP, FALL THRU TEST DET
  1926                              <1> TST_DET:
  1927                              <1> 	test	bh, MED_DET		; DETERMINED ?
  1928                              <1> 	jz	short AL_SET		; IF NOT THEN SET
  1929                              <1> 	add	al, 3			; MAKE DETERMINED/ESTABLISHED
  1930                              <1> AL_SET:
  1931                              <1> 	and	byte [DSK_STATE+edi], ~(DRV_DET+FMT_CAPA+TRK_CAPA) ; CLEAR DRIVE
  1932                              <1> 	or	[DSK_STATE+edi], al	; REPLACE WITH COMPATIBLE MODE
  1933                              <1> XO_OUT:
  1934                              <1> 	retn
  1935                              <1> 
  1936                              <1> %endif
  1937                              <1> 
  1938                              <1> ;-------------------------------------------------------------------------------
  1939                              <1> ; SETUP_STATE:	INITIALIZES START AND END RATES.
  1940                              <1> ;-------------------------------------------------------------------------------
  1941                              <1> SETUP_STATE:
  1942 000047CB F687[537D0100]10    <1> 	test	byte [DSK_STATE+edi], MED_DET ; MEDIA DETERMINED ?
  1943 000047D2 7537                <1> 	jnz	short J1C		; NO STATES IF DETERMINED
  1944 000047D4 66B84000            <1>         mov     ax, (RATE_500*256)+RATE_300 ; AH = START RATE, AL = END RATE
  1945 000047D8 F687[537D0100]04    <1> 	test	byte [DSK_STATE+edi], DRV_DET ; DRIVE ?
  1946 000047DF 740D                <1> 	jz	short AX_SET		; DO NOT KNOW DRIVE
  1947 000047E1 F687[537D0100]02    <1> 	test	byte [DSK_STATE+edi], FMT_CAPA ; MULTI-RATE?
  1948 000047E8 7504                <1> 	jnz	short AX_SET		; JUMP IF YES
  1949 000047EA 66B88080            <1>         mov     ax, RATE_250*257	; START A END RATE 250 FOR 360 DRIVE
  1950                              <1> AX_SET:	
  1951 000047EE 80A7[537D0100]1F    <1> 	and	byte [DSK_STATE+edi], ~(RATE_MSK+DBL_STEP) ; TURN OFF THE RATE
  1952 000047F5 08A7[537D0100]      <1> 	or	[DSK_STATE+edi], ah	; RATE FIRST TO TRY
  1953 000047FB 8025[507D0100]F3    <1> 	and	byte [LASTRATE], ~STRT_MSK ; ERASE LAST TO TRY RATE BITS
  1954 00004802 C0C804              <1> 	ror	al, 4			; TO OPERATION LAST RATE LOCATION
  1955 00004805 0805[507D0100]      <1> 	or	[LASTRATE], al		; LAST RATE
  1956                              <1> J1C:	
  1957 0000480B C3                  <1> 	retn
  1958                              <1> 
  1959                              <1> ;-------------------------------------------------------------------------------
  1960                              <1> ;  FMT_INIT: ESTABLISH STATE IF UNESTABLISHED AT FORMAT TIME.
  1961                              <1> ;-------------------------------------------------------------------------------
  1962                              <1> FMT_INIT:
  1963 0000480C F687[537D0100]10    <1> 	test	byte [DSK_STATE+edi], MED_DET ; IS MEDIA ESTABLISHED
  1964 00004813 7546                <1> 	jnz	short F1_OUT		; IF SO RETURN
  1965 00004815 E8A3030000          <1> 	call	CMOS_TYPE		; RETURN DRIVE TYPE IN AL
  1966                              <1> 	;; 20/02/2015
  1967                              <1> 	;;jc	short CL_DRV		; ERROR IN CMOS ASSUME NO DRIVE
  1968 0000481A 7440                <1> 	jz	short CL_DRV ;; 20/02/2015
  1969 0000481C FEC8                <1> 	dec	al			; MAKE ZERO ORIGIN
  1970                              <1> 	;;JS	short CL_DRV		; NO DRIVE IF AL 0
  1971 0000481E 8AA7[537D0100]      <1> 	mov	ah, [DSK_STATE+edi]	; AH = CURRENT STATE
  1972 00004824 80E40F              <1> 	and	ah, ~(MED_DET+DBL_STEP+RATE_MSK) ; CLEAR
  1973 00004827 08C0                <1> 	or	al, al			; CHECK FOR 360
  1974 00004829 7505                <1> 	jnz	short N_360		; IF 360 WILL BE 0
  1975 0000482B 80CC90              <1> 	or	ah, MED_DET+RATE_250	; ESTABLISH MEDIA
  1976 0000482E EB25                <1> 	jmp	short SKP_STATE		; SKIP OTHER STATE PROCESSING
  1977                              <1> N_360:	
  1978 00004830 FEC8                <1> 	dec	al			; 1.2 M DRIVE
  1979 00004832 7505                <1> 	jnz	short N_12		; JUMP IF NOT
  1980                              <1> F1_RATE:
  1981 00004834 80CC10              <1> 	or	ah, MED_DET+RATE_500	; SET FORMAT RATE
  1982 00004837 EB1C                <1> 	jmp	short SKP_STATE		; SKIP OTHER STATE PROCESSING
  1983                              <1> N_12:	
  1984 00004839 FEC8                <1> 	dec	al			; CHECK FOR TYPE 3
  1985 0000483B 750F                <1> 	jnz	short N_720		; JUMP IF NOT
  1986 0000483D F6C404              <1> 	test	ah, DRV_DET		; IS DRIVE DETERMINED
  1987 00004840 7410                <1> 	jz	short ISNT_12		; TREAT AS NON 1.2 DRIVE
  1988 00004842 F6C402              <1> 	test	ah, FMT_CAPA		; IS 1.2M
  1989 00004845 740B                <1> 	jz	short ISNT_12		; JUMP IF NOT
  1990 00004847 80CC50              <1> 	or	ah, MED_DET+RATE_300	; RATE 300
  1991 0000484A EB09                <1> 	jmp	short SKP_STATE		; CONTINUE
  1992                              <1> N_720:
  1993 0000484C FEC8                <1> 	dec	al			; CHECK FOR TYPE 4
  1994 0000484E 750C                <1> 	jnz	short CL_DRV		; NO DRIVE, CMOS BAD
  1995 00004850 EBE2                <1> 	jmp	SHORT F1_RATE
  1996                              <1> ISNT_12: 
  1997 00004852 80CC90              <1> 	or	ah, MED_DET+RATE_250	; MUST BE RATE 250
  1998                              <1> SKP_STATE:
  1999 00004855 88A7[537D0100]      <1> 	mov	[DSK_STATE+edi], ah	; STORE AWAY
  2000                              <1> F1_OUT:
  2001 0000485B C3                  <1> 	retn
  2002                              <1> CL_DRV:	
  2003 0000485C 30E4                <1> 	xor	ah, ah			; CLEAR STATE
  2004 0000485E EBF5                <1> 	jmp	short SKP_STATE		; SAVE IT
  2005                              <1> 
  2006                              <1> ;-------------------------------------------------------------------------------
  2007                              <1> ; MED_CHANGE	
  2008                              <1> ;	CHECKS FOR MEDIA CHANGE, RESETS MEDIA CHANGE, 
  2009                              <1> ;	CHECKS MEDIA CHANGE AGAIN.
  2010                              <1> ;
  2011                              <1> ; ON EXIT:	CY = 1 MEANS MEDIA CHANGE OR TIMEOUT
  2012                              <1> ;		@DSKETTE_STATUS = ERROR CODE
  2013                              <1> ;-------------------------------------------------------------------------------
  2014                              <1> MED_CHANGE:
  2015                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  2016 00004860 E8E8050000          <1> 	call	READ_DSKCHNG		; READ DISK CHANCE LINE STATE
  2017 00004865 7445                <1> 	jz	short MC_OUT		; BYPASS HANDLING DISK CHANGE LINE
  2018 00004867 80A7[537D0100]EF    <1> 	and	byte [DSK_STATE+edi], ~MED_DET ; CLEAR STATE FOR THIS DRIVE
  2019                              <1> 
  2020                              <1> ;	THIS SEQUENCE ENSURES WHENEVER A DISKETTE IS CHANGED THAT
  2021                              <1> ;	ON THE NEXT OPERATION THE REQUIRED MOTOR START UP TIME WILL
  2022                              <1> ;	BE WAITED. (DRIVE MOTOR MAY GO OFF UPON DOOR OPENING).
  2023                              <1> 
  2024                              <1> 	;mov	cx, di			; CL = DRIVE 0
  2025                              <1> 	; 06/08/2022
  2026 0000486E 89F9                <1> 	mov	ecx, edi
  2027 00004870 B001                <1> 	mov	al, 1			; MOTOR ON BIT MASK
  2028 00004872 D2E0                <1> 	shl	al, cl			; TO APPROPRIATE POSITION
  2029 00004874 F6D0                <1> 	not	al			; KEEP ALL BUT MOTOR ON
  2030 00004876 FA                  <1> 	cli				; NO INTERRUPTS
  2031 00004877 2005[467D0100]      <1> 	and	[MOTOR_STATUS], al	; TURN MOTOR OFF INDICATOR
  2032 0000487D FB                  <1> 	sti				; INTERRUPTS ENABLED
  2033 0000487E E87E030000          <1> 	call	MOTOR_ON		; TURN MOTOR ON
  2034                              <1> 
  2035                              <1> ;-----	THIS SEQUENCE OF SEEKS IS USED TO RESET DISKETTE CHANGE SIGNAL
  2036                              <1> 
  2037 00004883 E82FFAFFFF          <1> 	call	DSK_RESET		; RESET NEC
  2038 00004888 B501                <1> 	mov	ch, 1			; MOVE TO CYLINDER 1
  2039 0000488A E864040000          <1> 	call	SEEK			; ISSUE SEEK
  2040 0000488F 30ED                <1> 	xor	ch, ch			; MOVE TO CYLINDER 0
  2041 00004891 E85D040000          <1> 	call	SEEK			; ISSUE SEEK
  2042 00004896 C605[487D0100]06    <1> 	mov	byte [DSKETTE_STATUS], MEDIA_CHANGE ; STORE IN STATUS
  2043                              <1> OK1:
  2044 0000489D E8AB050000          <1> 	call	READ_DSKCHNG		; CHECK MEDIA CHANGED AGAIN
  2045 000048A2 7407                <1> 	jz	short OK2		; IF ACTIVE, NO DISKETTE, TIMEOUT
  2046                              <1> OK4:
  2047 000048A4 C605[487D0100]80    <1> 	mov	byte [DSKETTE_STATUS], TIME_OUT ; TIMEOUT IF DRIVE EMPTY
  2048                              <1> OK2:		
  2049 000048AB F9                  <1> 	stc				; MEDIA CHANGED, SET CY
  2050                              <1> MC_OUT:	; 06/08/2022 (cf = 0)
  2051 000048AC C3                  <1> 	retn
  2052                              <1> ;MC_OUT:
  2053                              <1> 	;clc				; NO MEDIA CHANGED, CLEAR CY
  2054                              <1> 	;retn
  2055                              <1> 
  2056                              <1> ;-------------------------------------------------------------------------------
  2057                              <1> ; SEND_RATE
  2058                              <1> ;	SENDS DATA RATE COMMAND TO NEC
  2059                              <1> ; ON ENTRY:	DI = DRIVE #
  2060                              <1> ; ON EXIT:	NONE
  2061                              <1> ; REGISTERS ALTERED: DX
  2062                              <1> ;-------------------------------------------------------------------------------
  2063                              <1> SEND_RATE:
  2064                              <1> 	;push	ax			; SAVE REG.
  2065                              <1> 	; 11/04/2021
  2066 000048AD 50                  <1> 	push	eax
  2067 000048AE 8025[507D0100]3F    <1> 	and	byte [LASTRATE], ~SEND_MSK ; ELSE CLEAR LAST RATE ATTEMPTED
  2068 000048B5 8A87[537D0100]      <1> 	mov	al, [DSK_STATE+edi]	; GET RATE STATE OF THIS DRIVE
  2069 000048BB 24C0                <1> 	and	al, SEND_MSK		; KEEP ONLY RATE BITS
  2070 000048BD 0805[507D0100]      <1> 	or	[LASTRATE], al		; SAVE NEW RATE FOR NEXT CHECK
  2071 000048C3 C0C002              <1> 	rol	al, 2			; MOVE TO BIT OUTPUT POSITIONS
  2072 000048C6 66BAF703            <1> 	mov	dx, 03F7h		; OUTPUT NEW DATA RATE
  2073 000048CA EE                  <1> 	out	dx, al
  2074                              <1> 	;pop	ax			; RESTORE REG.
  2075                              <1> 	; 11/04/2021
  2076 000048CB 58                  <1> 	pop	eax
  2077 000048CC C3                  <1> 	retn
  2078                              <1> 
  2079                              <1> ;-------------------------------------------------------------------------------
  2080                              <1> ; CHK_LASTRATE
  2081                              <1> ;	CHECK PREVIOUS DATE RATE SNT TO THE CONTROLLER.
  2082                              <1> ; ON ENTRY:
  2083                              <1> ;	DI = DRIVE #
  2084                              <1> ; ON EXIT:
  2085                              <1> ;	ZF =  1 DATA RATE IS THE SAME AS THE LAST RATE SENT TO NEC
  2086                              <1> ;	ZF =  0 DATA RATE IS DIFFERENT FROM LAST RATE
  2087                              <1> ; REGISTERS ALTERED: DX
  2088                              <1> ;-------------------------------------------------------------------------------
  2089                              <1> CHK_LASTRATE:
  2090                              <1> 	; 13/07/2022 - TRDOS 386 v2.0.5
  2091                              <1> 	;push	ax			; SAVE REG.
  2092                              <1> 	; 11/04/2021
  2093 000048CD 50                  <1> 	push	eax
  2094                              <1> 	; 13/07/2022 (BugFix)
  2095 000048CE 8A25[507D0100]      <1> 	mov	ah, [LASTRATE] 		; GET LAST DATA RATE SELECTED
  2096 000048D4 8A87[537D0100]      <1> 	mov	al, [DSK_STATE+edi]	; GET RATE STATE OF THIS DRIVE
  2097 000048DA 6625C0C0            <1>         and	ax, SEND_MSK*257        ; KEEP ONLY RATE BITS OF BOTH
  2098 000048DE 38E0                <1> 	cmp	al, ah			; COMPARE TO PREVIOUSLY TRIED
  2099                              <1> 					; ZF = 1 RATE IS THE SAME
  2100                              <1> 	;pop	ax			; RESTORE REG.
  2101                              <1> 	; 11/04/2021
  2102 000048E0 58                  <1> 	pop	eax
  2103 000048E1 C3                  <1> 	retn
  2104                              <1> 
  2105                              <1> ;-------------------------------------------------------------------------------
  2106                              <1> ; DMA_SETUP
  2107                              <1> ;	THIS ROUTINE SETS UP THE DMA FOR READ/WRITE/VERIFY OPERATIONS.
  2108                              <1> ;
  2109                              <1> ; ON ENTRY:	AL = DMA COMMAND
  2110                              <1> ;
  2111                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  2112                              <1> ;-------------------------------------------------------------------------------
  2113                              <1> 
  2114                              <1> ; SI = Head #, # of Sectors or DASD Type
  2115                              <1> 
  2116                              <1> ; 22/08/2015
  2117                              <1> ; 08/02/2015 - Protected Mode Modification
  2118                              <1> ; 06/02/2015 - 07/02/2015
  2119                              <1> ; NOTE: Buffer address must be in 1st 16MB of Physical Memory (24 bit limit).
  2120                              <1> ; (DMA Addres = Physical Address)
  2121                              <1> ; (Retro UNIX 386 v1 Kernel/System Mode Virtual Address = Physical Address)
  2122                              <1> ;
  2123                              <1> ; 09/08/2022
  2124                              <1> ; 06/08/2022
  2125                              <1> ; 04/02/2016 (clc)
  2126                              <1> ; 20/02/2015 modification (source: AWARD BIOS 1999, DMA_SETUP)
  2127                              <1> ; 16/12/2014 (IODELAY)
  2128                              <1> 
  2129                              <1> DMA_SETUP:
  2130                              <1> 	; 09/08/2022
  2131                              <1> 	; 06/08/2022 - TRDOS 386 Kernel v2.0.5
  2132                              <1> 	;; 20/02/2015
  2133                              <1> 	;;mov	edx, [ebp+4] 		; Buffer address
  2134                              <1> 	; 06/08/2022
  2135                              <1> 	;mov	edx, ebp ; buffer address
  2136                              <1> 	;test	edx, 0FF000000h		; 16 MB limit (22/08/2015, bugfix)
  2137 000048E2 F7C5000000FF        <1> 	test	ebp, 0FF000000h
  2138 000048E8 7566                <1> 	jnz	short dma_bnd_err_stc
  2139                              <1> 	; 09/08/2022
  2140 000048EA 89EA                <1> 	mov	edx, ebp
  2141                              <1> 	;
  2142                              <1> 	;;push	ax			; DMA command
  2143                              <1> 	; 11/04/2021
  2144 000048EC 50                  <1> 	push	eax
  2145                              <1> 	; 06/08/2022
  2146                              <1> 	;push	edx			; *
  2147                              <1> 	;mov	dl, 3			; GET BYTES/SECTOR PARAMETER
  2148                              <1> 	; 06/08/2022
  2149 000048ED B003                <1> 	mov	al, 3			; GET BYTES/SECTOR PARAMETER
  2150 000048EF E8D2020000          <1> 	call	GET_PARM		; 
  2151 000048F4 88E1                <1> 	mov	cl, ah 			; SHIFT COUNT (0=128, 1=256, 2=512 ETC)
  2152                              <1> 	;mov	ax, si			; Sector count
  2153                              <1> 	; 06/08/2022
  2154 000048F6 89F0                <1> 	mov	eax, esi
  2155 000048F8 88C4                <1> 	mov	ah, al			; AH = # OF SECTORS
  2156 000048FA 28C0                <1> 	sub	al, al			; AL = 0, AX = # SECTORS * 256
  2157                              <1> 	;shr	ax, 1			; AX = # SECTORS * 128
  2158                              <1> 	; 06/08/2022
  2159 000048FC D1E8                <1> 	shr	eax, 1
  2160                              <1> 	;shl	ax, cl			; SHIFT BY PARAMETER VALUE
  2161                              <1> 	;dec	ax			; -1 FOR DMA VALUE
  2162                              <1> 	;mov	cx, ax
  2163 000048FE D3E0                <1> 	shl	eax, cl
  2164 00004900 48                  <1> 	dec	eax
  2165 00004901 89C1                <1> 	mov	ecx, eax
  2166                              <1> 	; 06/08/2022
  2167                              <1> 	;pop	edx			; *
  2168                              <1> 	;;pop	ax
  2169                              <1> 	; 11/04/2021
  2170 00004903 58                  <1> 	pop	eax
  2171 00004904 3C42                <1> 	cmp	al, 42h
  2172 00004906 7507                <1>         jne     short NOT_VERF
  2173                              <1> 	; 09/08/2022
  2174 00004908 BA0000FF00          <1> 	mov	edx, 0FF0000h
  2175                              <1> 	; 06/08/2022
  2176                              <1> 	;mov	ebp, 0FF0000h
  2177 0000490D EB08                <1> 	jmp	short J33
  2178                              <1> NOT_VERF:
  2179 0000490F 6601CA              <1> 	add	dx, cx			; check for overflow
  2180 00004912 723D                <1> 	jc	short dma_bnd_err
  2181                              <1> 	;
  2182 00004914 6629CA              <1> 	sub	dx, cx			; Restore start address
  2183                              <1> J33:
  2184 00004917 FA                  <1> 	cli				; DISABLE INTERRUPTS DURING DMA SET-UP
  2185 00004918 E60C                <1> 	out	DMA+12, al		; SET THE FIRST/LA5T F/F
  2186                              <1> 	IODELAY				; WAIT FOR I/O
    78 0000491A EB00                <2>  jmp short $+2
    79 0000491C EB00                <2>  jmp short $+2
  2187 0000491E E60B                <1> 	out	DMA+11, al		; OUTPUT THE MODE BYTE
  2188                              <1> 	;mov	eax, edx		; Buffer address
  2189                              <1> 	; 06/08/2022
  2190                              <1> 	;mov	eax, ebp
  2191                              <1> 	; 09/08/2022
  2192 00004920 89D0                <1> 	mov	eax, edx
  2193 00004922 E604                <1> 	out	DMA+4, al		; OUTPUT LOW ADDRESS
  2194                              <1> 	IODELAY				; WAIT FOR I/O
    78 00004924 EB00                <2>  jmp short $+2
    79 00004926 EB00                <2>  jmp short $+2
  2195 00004928 88E0                <1> 	mov	al, ah
  2196 0000492A E604                <1> 	out	DMA+4, al		; OUTPUT HIGH ADDRESS
  2197 0000492C C1E810              <1> 	shr	eax, 16
  2198                              <1> 	IODELAY				; I/O WAIT STATE
    78 0000492F EB00                <2>  jmp short $+2
    79 00004931 EB00                <2>  jmp short $+2
  2199 00004933 E681                <1> 	out	081h, al		; OUTPUT HIGHEST BITS TO PAGE REGISTER
  2200                              <1> 	IODELAY
    78 00004935 EB00                <2>  jmp short $+2
    79 00004937 EB00                <2>  jmp short $+2
  2201                              <1> 	;mov	ax, cx			; Byte count - 1
  2202                              <1> 	; 06/08/2022
  2203 00004939 89C8                <1> 	mov	eax, ecx
  2204 0000493B E605                <1> 	out	DMA+5, al		; LOW BYTE OF COUNT
  2205                              <1> 	IODELAY				; WAIT FOR I/O
    78 0000493D EB00                <2>  jmp short $+2
    79 0000493F EB00                <2>  jmp short $+2
  2206 00004941 88E0                <1> 	mov	al, ah
  2207 00004943 E605                <1> 	out	DMA+5, al		; HIGH BYTE OF COUNT
  2208                              <1> 	IODELAY
    78 00004945 EB00                <2>  jmp short $+2
    79 00004947 EB00                <2>  jmp short $+2
  2209 00004949 FB                  <1> 	sti				; RE-ENABLE INTERRUPTS
  2210 0000494A B002                <1> 	mov	al, 2			; MODE FOR 8237
  2211 0000494C E60A                <1> 	out	DMA+10, al		; INITIALIZE THE DISKETTE CHANNEL
  2212                              <1> 
  2213 0000494E F8                  <1> 	clc	; 04/02/2016
  2214 0000494F C3                  <1> 	retn
  2215                              <1> 
  2216                              <1> dma_bnd_err_stc:
  2217 00004950 F9                  <1> 	stc
  2218                              <1> dma_bnd_err:
  2219 00004951 C605[487D0100]09    <1> 	mov	byte [DSKETTE_STATUS], DMA_BOUNDARY ; SET ERROR
  2220 00004958 C3                  <1> 	retn				; CY SET BY ABOVE IF ERROR
  2221                              <1> 
  2222                              <1> ;; 16/12/2014
  2223                              <1> ;;	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  2224                              <1> ;;	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  2225                              <1> ;;	;jmp	$+2			; WAIT FOR I/O
  2226                              <1> ;;	IODELAY
  2227                              <1> ;; 	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  2228                              <1> ;;	;SIODELAY
  2229                              <1> ;;      ;cmp	AL,42H			; DMA VERIFY COMMAND
  2230                              <1> ;;      ;JNE	short NOT_VERF		; NO
  2231                              <1> ;;      ;xor	AX,AX			; START ADDRESS
  2232                              <1> ;;      ;jmp	SHORT J33
  2233                              <1> ;;;NOT_VERF:	
  2234                              <1> ;;	;mov	AX,ES			; GET THE ES VALUE
  2235                              <1> ;;	;ROL	AX,4			; ROTATE LEFT
  2236                              <1> ;;	;mov	CH,AL			; GET HIGHEST NIBBLE OF ES TO CH
  2237                              <1> ;;	;and	AL,11110000B		; ZERO THE LOW NIBBLE FROM SEGMENT
  2238                              <1> ;;	;add	AX,[BP+2]		; TEST FOR CARRY FROM ADDITION
  2239                              <1> ;;	mov	eax,[ebp+4] ; 06/02/2015	
  2240                              <1> ;;	;jnc	short J33
  2241                              <1> ;;	;inc	CH			; CARRY MEANS HIGH 4 BITS MUST BE INC
  2242                              <1> ;;;J33:
  2243                              <1> ;;	push	eax			; SAVE START ADDRESS
  2244                              <1> ;;	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  2245                              <1> ;;	;jmp	$+2			; WAIT FOR I/O
  2246                              <1> ;;	IODELAY
  2247                              <1> ;;	mov	AL,AH
  2248                              <1> ;;	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  2249                              <1> ;;	shr	eax, 16	     ; 07/02/2015
  2250                              <1> ;;	;mov	AL,CH			; GET HIGH 4 BITS
  2251                              <1> ;;	;jmp	$+2			; I/O WAIT STATE
  2252                              <1> ;;	IODELAY
  2253                              <1> ;;	;and	AL,00001111B
  2254                              <1> ;;	OUT	081H,AL			; OUTPUT HIGH 4 BITS TO PAGE REGISTER
  2255                              <1> ;;	;SIODELAY
  2256                              <1> ;;
  2257                              <1> ;;;----- DETERMINE COUNT
  2258                              <1> ;;	sub	eax, eax ; 08/02/2015
  2259                              <1> ;;	mov	AX,SI			; AL =  # OF SECTORS
  2260                              <1> ;;	xchg	AL,AH			; AH =  # OF SECTORS
  2261                              <1> ;;	sub	AL,AL			; AL = 0, AX = # SECTORS * 256
  2262                              <1> ;;	SHR	AX,1			; AX = # SECTORS * 128
  2263                              <1> ;;	push	AX			; SAVE # OF SECTORS * 128
  2264                              <1> ;;	mov	DL,3			; GET BYTES/SECTOR PARAMETER
  2265                              <1> ;;	call	GET_PARM		; "
  2266                              <1> ;;	mov	CL,AH			; SHIFT COUNT (0=128, 1=256, 2=512 ETC)
  2267                              <1> ;;	pop	AX			; AX = # SECTORS * 128
  2268                              <1> ;;	SHL	AX,CL			; SHIFT BY PARAMETER VALUE
  2269                              <1> ;;	dec	AX			; -1 FOR DMA VALUE
  2270                              <1> ;;	push	eax  ; 08/02/2015	; SAVE COUNT VALUE
  2271                              <1> ;;	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  2272                              <1> ;;	;jmp	$+2			; WAIT FOR I/O
  2273                              <1> ;;	IODELAY
  2274                              <1> ;;	mov	AL,AH
  2275                              <1> ;;	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  2276                              <1> ;;	;IODELAY
  2277                              <1> ;;	STI				; RE-ENABLE INTERRUPTS
  2278                              <1> ;;	pop	ecx  ; 08/02/2015 	; RECOVER COUNT VALUE
  2279                              <1> ;;	pop	eax  ; 08/02/2015	; RECOVER ADDRESS VALUE
  2280                              <1> ;;	;add	AX, CX			; ADD, TEST FOR 64K OVERFLOW
  2281                              <1> ;;	add	ecx,eax ; 08/02/2015
  2282                              <1> ;;	mov	AL, 2			; MODE FOR 8237
  2283                              <1> ;;	;jmp	$+2			; WAIT FOR I/O
  2284                              <1> ;;	SIODELAY
  2285                              <1> ;;	OUT	DMA+10,AL		; INITIALIZE THE DISKETTE CHANNEL
  2286                              <1> ;;	;jnc	short NO_BAD		; CHECK FOR ERROR
  2287                              <1> ;;	jc	short dma_bnd_err ; 08/02/2015
  2288                              <1> ;;	and	ecx,0FFF00000h	; 16 MB limit
  2289                              <1> ;;	jz	short NO_BAD
  2290                              <1> ;;dma_bnd_err:
  2291                              <1> ;;	mov	byte [DSKETTE_STATUS],DMA_BOUNDARY ; SET ERROR
  2292                              <1> ;;NO_BAD:
  2293                              <1> ;;	retn				; CY SET BY ABOVE IF ERROR
  2294                              <1> 
  2295                              <1> ;-------------------------------------------------------------------------------
  2296                              <1> ; FMTDMA_SET
  2297                              <1> ;	THIS ROUTINE SETS UP THE DMA CONTROLLER FOR A FORMAT OPERATION.
  2298                              <1> ;
  2299                              <1> ; ON ENTRY:	NOTHING REQUIRED
  2300                              <1> ;
  2301                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  2302                              <1> ;-------------------------------------------------------------------------------
  2303                              <1> 
  2304                              <1> FMTDMA_SET:
  2305                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  2306                              <1> 	;; 20/02/2015 modification	
  2307                              <1> 	;;mov	edx, [ebp+4] 		; Buffer address
  2308                              <1> 	; 06/08/2022
  2309                              <1> 	;mov	edx, ebp ; buffer address
  2310                              <1> 	; 06/08/2022
  2311                              <1> 	;test	edx, 0FF000000h		; 16 MB limit
  2312 00004959 F7C5000000FF        <1> 	test	ebp, 0FF000000h
  2313 0000495F 75EF                <1> 	jnz	short dma_bnd_err_stc
  2314                              <1> 	;
  2315                              <1> 	;;push	dx			; *
  2316                              <1> 	;; 11/04/2021
  2317                              <1> 	; 06/08/2022
  2318                              <1> 	;push	edx
  2319                              <1> 	;mov	dl, 4			; SECTORS/TRACK VALUE IN PARM TABLE
  2320                              <1> 	; 06/08/2022
  2321 00004961 B004                <1> 	mov	al, 4			; SECTORS/TRACK VALUE IN PARM TABLE				
  2322 00004963 E85E020000          <1> 	call	GET_PARM		; "
  2323 00004968 88E0                <1> 	mov	al, ah			; AL = SECTORS/TRACK VALUE
  2324 0000496A 28E4                <1> 	sub	ah, ah			; AX = SECTORS/TRACK VALUE
  2325                              <1> 	;shl	ax, 2			; AX = SEC/TRK * 4 (OFFSET C,H,R,N)
  2326                              <1> 	; 06/08/2022
  2327 0000496C C1E002              <1> 	shl	eax, 2
  2328                              <1> 	;dec	ax			; -1 FOR DMA VALUE
  2329 0000496F 48                  <1> 	dec	eax
  2330                              <1> 	;mov	cx, ax
  2331 00004970 89C1                <1> 	mov	ecx, eax
  2332                              <1> 	;;pop	dx			; *
  2333                              <1> 	;; 11/04/2021
  2334                              <1> 	; 06/08/2022
  2335                              <1> 	;pop	edx
  2336                              <1> 	; 06/08/2022
  2337 00004972 B04A                <1> 	mov	al, 04Ah
  2338                              <1> 	;
  2339 00004974 EB99                <1> 	jmp	short NOT_VERF ; 06/08/2022	
  2340                              <1> 
  2341                              <1> ;; 06/08/2022	
  2342                              <1> ;	add	dx, cx			; check for overflow
  2343                              <1> ;	jc	short dma_bnd_err
  2344                              <1> ;	;
  2345                              <1> ;	sub	dx, cx			; Restore start address
  2346                              <1> ;	;
  2347                              <1> ;	;mov	al, 04Ah		; WILL WRITE TO THE DISKETTE
  2348                              <1> ;	cli				; DISABLE INTERRUPTS DURING DMA SET-UP
  2349                              <1> ;	out	DMA+12, al		; SET THE FIRST/LA5T F/F
  2350                              <1> ;	IODELAY				; WAIT FOR I/O
  2351                              <1> ;	out	DMA+11, al		; OUTPUT THE MODE BYTE
  2352                              <1> ;	mov	eax, edx		; Buffer address
  2353                              <1> ;	out	DMA+4, al		; OUTPUT LOW ADDRESS
  2354                              <1> ;	IODELAY				; WAIT FOR I/O
  2355                              <1> ;	mov	al, ah
  2356                              <1> ;	out	DMA+4, al		; OUTPUT HIGH ADDRESS
  2357                              <1> ;	shr	eax, 16
  2358                              <1> ;	IODELAY				; I/O WAIT STATE
  2359                              <1> ;	out	081h, al		; OUTPUT HIGHEST BITS TO PAGE REGISTER
  2360                              <1> ;	IODELAY
  2361                              <1> ;	;mov	ax, cx			; Byte count - 1
  2362                              <1> ;	; 06/08/2022
  2363                              <1> ;	mov	eax, ecx
  2364                              <1> ;	out	DMA+5, al		; LOW BYTE OF COUNT
  2365                              <1> ;	IODELAY				; WAIT FOR I/O
  2366                              <1> ;	mov	al, ah
  2367                              <1> ;	out	DMA+5, al		; HIGH BYTE OF COUNT
  2368                              <1> ;	IODELAY
  2369                              <1> ;	sti				; RE-ENABLE INTERRUPTS
  2370                              <1> ;	mov	al, 2			; MODE FOR 8237
  2371                              <1> ;	out	DMA+10, al		; INITIALIZE THE DISKETTE CHANNEL
  2372                              <1> ;
  2373                              <1> ;	; 06/08/2022
  2374                              <1> ;	clc
  2375                              <1> ;	retn
  2376                              <1> 
  2377                              <1> ;; 08/02/2015 - Protected Mode Modification
  2378                              <1> ;;	mov	AL,04AH			; WILL WRITE TO THE DISKETTE
  2379                              <1> ;;	CLI				; DISABLE INTERRUPTS DURING DMA SET-UP
  2380                              <1> ;;	OUT	DMA+12,AL		; SET THE FIRST/LA5T F/F
  2381                              <1> ;;	;jmp	$+2			; WAIT FOR I/O
  2382                              <1> ;;	IODELAY
  2383                              <1> ;;	OUT	DMA+11,AL		; OUTPUT THE MODE BYTE
  2384                              <1> ;;	;mov	AX,ES			; GET THE ES VALUE
  2385                              <1> ;;	;ROL	AX,4			; ROTATE LEFT
  2386                              <1> ;;	;mov	CH,AL			; GET HIGHEST NIBBLE OF ES TO CH
  2387                              <1> ;;	;and	AL,11110000B		; ZERO THE LOW NIBBLE FROM SEGMENT
  2388                              <1> ;;	;add	AX,[BP+2]		; TEST FOR CARRY FROM ADDITION
  2389                              <1> ;;	;jnc	short J33A
  2390                              <1> ;;	;inc	CH			; CARRY MEANS HIGH 4 BITS MUST BE INC
  2391                              <1> ;;	mov	eax,[ebp+4] ; 08/02/2015
  2392                              <1> ;;;J33A:
  2393                              <1> ;;	push	eax ; 08/02/2015	; SAVE START ADDRESS
  2394                              <1> ;;	OUT	DMA+4,AL		; OUTPUT LOW ADDRESS
  2395                              <1> ;;	;jmp	$+2			; WAIT FOR I/O
  2396                              <1> ;;	IODELAY
  2397                              <1> ;;	mov	AL,AH
  2398                              <1> ;;	OUT	DMA+4,AL		; OUTPUT HIGH ADDRESS
  2399                              <1> ;;	shr 	eax,16 ; 08/02/2015
  2400                              <1> ;;	;mov	AL,CH			; GET HIGH 4 BITS
  2401                              <1> ;;	;jmp	$+2			; I/O WAIT STATE
  2402                              <1> ;;	IODELAY
  2403                              <1> ;;	;and	AL,00001111B
  2404                              <1> ;;	OUT	081H,AL			; OUTPUT HIGH 4 BITS TO PAGE REGISTER
  2405                              <1> ;;
  2406                              <1> ;;;----- DETERMINE COUNT
  2407                              <1> ;;	sub	eax,eax ; 08/02/2015
  2408                              <1> ;;	mov	DL,4			; SECTORS/TRACK VALUE IN PARM TABLE
  2409                              <1> ;;	call	GET_PARM		; "
  2410                              <1> ;;	xchg	AL,AH			; AL = SECTORS/TRACK VALUE
  2411                              <1> ;;	sub	AH,AH			; AX = SECTORS/TRACK VALUE
  2412                              <1> ;;	SHL	AX,2			; AX = SEC/TRK * 4 (OFFSET C,H,R,N)
  2413                              <1> ;;	dec	AX			; -1 FOR DMA VALUE
  2414                              <1> ;;	push	eax 	; 08/02/2015	; SAVE # OF BYTES TO BE TRANSFERED
  2415                              <1> ;;	OUT	DMA+5,AL		; LOW BYTE OF COUNT
  2416                              <1> ;;	;jmp	$+2			; WAIT FOR I/O
  2417                              <1> ;;	IODELAY
  2418                              <1> ;;	mov	AL,AH
  2419                              <1> ;;	OUT	DMA+5,AL		; HIGH BYTE OF COUNT
  2420                              <1> ;;	STI				; RE-ENABLE INTERRUPTS
  2421                              <1> ;;	pop	ecx	; 08/02/2015	; RECOVER COUNT VALUE
  2422                              <1> ;;	pop	eax	; 08/02/2015	; RECOVER ADDRESS VALUE
  2423                              <1> ;;	;add	AX,CX			; ADD, TEST FOR 64K OVERFLOW
  2424                              <1> ;;	add	ecx,eax ; 08/02/2015
  2425                              <1> ;;	mov	AL,2			; MODE FOR 8237
  2426                              <1> ;;	;jmp	$+2			; WAIT FOR I/O
  2427                              <1> ;;	SIODELAY
  2428                              <1> ;;	OUT	DMA+10,AL		; INITIALIZE THE DISKETTE CHANNEL
  2429                              <1> ;;	;jnc	short FMTDMA_OK		; CHECK FOR ERROR
  2430                              <1> ;;	jc	short fmtdma_bnd_err ; 08/02/2015
  2431                              <1> ;;	and	ecx,0FFF00000h	; 16 MB limit
  2432                              <1> ;;	jz	short FMTDMA_OK
  2433                              <1> ;;	stc	; 20/02/2015
  2434                              <1> ;;fmtdma_bnd_err:
  2435                              <1> ;;	mov	byte [DSKETTE_STATUS],DMA_BOUNDARY ; SET ERROR
  2436                              <1> ;;FMTDMA_OK:
  2437                              <1> ;;	retn				; CY SET BY ABOVE IF ERROR
  2438                              <1> 
  2439                              <1> ;-------------------------------------------------------------------------------
  2440                              <1> ; NEC_INIT	
  2441                              <1> ;	THIS ROUTINE SEEKS TO THE REQUESTED TRACK AND INITIALIZES
  2442                              <1> ;	THE NEC FOR THE READ/WRITE/VERIFY/FORMAT OPERATION.
  2443                              <1> ;
  2444                              <1> ; ON ENTRY:	AH = NEC COMMAND TO BE PERFORMED
  2445                              <1> ;
  2446                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  2447                              <1> ;-------------------------------------------------------------------------------
  2448                              <1> NEC_INIT:
  2449                              <1> 	; 11/08/2022
  2450                              <1> 	; EBX = user's ECX register content (on stack)
  2451                              <1> 	; 10/08/2022
  2452                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  2453                              <1> 	;push	ax			; SAVE NEC COMMAND
  2454                              <1> 	; 11/04/2021
  2455 00004976 50                  <1> 	push	eax
  2456 00004977 E885020000          <1> 	call	MOTOR_ON		; TURN MOTOR ON FOR SPECIFIC DRIVE
  2457                              <1> 
  2458                              <1> ;-----	DO THE SEEK OPERATION
  2459                              <1> 
  2460                              <1> 	;mov	ch, [ebp+1]		; CH = TRACK #
  2461                              <1> 	; 10/08/2022
  2462 0000497C 88FD                <1> 	mov	ch, bh ; CH = TRACK #
  2463 0000497E E870030000          <1> 	call	SEEK			; MOVE TO CORRECT TRACK
  2464                              <1> 	;pop	ax			; RECOVER COMMAND
  2465                              <1> 	; 11/04/2021
  2466 00004983 58                  <1> 	pop	eax
  2467 00004984 721D                <1> 	jc	short ER_1		; ERROR ON SEEK
  2468 00004986 BB[A3490000]        <1> 	mov	ebx, ER_1		; LOAD ERROR ADDRESS
  2469 0000498B 53                  <1> 	push	ebx			; PUSH NEC_OUT ERROR RETURN
  2470                              <1> 
  2471                              <1> ;-----	SEND OUT THE PARAMETERS TO THE CONTROLLER
  2472                              <1> 
  2473 0000498C E82B030000          <1> 	call	NEC_OUTPUT		; OUTPUT THE OPERATION COMMAND
  2474                              <1> 	;mov	ax, si			; AH = HEAD #
  2475                              <1> 	; 06/08/2022
  2476 00004991 89F0                <1> 	mov	eax, esi
  2477 00004993 89FB                <1> 	mov	ebx, edi		; BL = DRIVE #
  2478 00004995 C0E402              <1> 	sal	ah, 2			; MOVE IT TO BIT 2
  2479 00004998 80E404              <1> 	and	ah, 00000100b		; ISOLATE THAT BIT
  2480 0000499B 08DC                <1> 	or	ah, bl			; OR IN THE DRIVE NUMBER
  2481 0000499D E81A030000          <1> 	call	NEC_OUTPUT		; FALL THRU CY SET IF ERROR
  2482 000049A2 5B                  <1> 	pop	ebx			; THROW AWAY ERROR RETURN
  2483                              <1> ER_1:
  2484 000049A3 C3                  <1> 	retn
  2485                              <1> 
  2486                              <1> ;-------------------------------------------------------------------------------
  2487                              <1> ; RWV_COM
  2488                              <1> ;	THIS ROUTINE SENDS PARAMETERS TO THE NEC SPECIFIC TO THE 
  2489                              <1> ;	READ/WRITE/VERIFY OPERATIONS.
  2490                              <1> ;
  2491                              <1> ; ON ENTRY:	CS:BX = ADDRESS OF MEDIA/DRIVE PARAMETER TABLE
  2492                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  2493                              <1> ;-------------------------------------------------------------------------------
  2494                              <1> RWV_COM:
  2495                              <1> 	; 11/08/2022
  2496                              <1> 	; 10/08/2022
  2497                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  2498 000049A4 B8[F0490000]        <1> 	mov	eax, ER_2		; LOAD ERROR ADDRESS
  2499 000049A9 50                  <1> 	push	eax			; PUSH NEC_OUT ERROR RETURN
  2500                              <1> 	;mov	ah, [ebp+1]		; OUTPUT TRACK #
  2501                              <1> 	; 11/08/2022
  2502 000049AA 8A642425            <1> 	mov	ah, [esp+37] ; CH = OUTPUT TRACK #
  2503 000049AE E809030000          <1> 	call	NEC_OUTPUT
  2504                              <1> 	;mov	ax, si			; OUTPUT HEAD #
  2505                              <1> 	; 06/08/2022
  2506 000049B3 89F0                <1> 	mov	eax, esi
  2507 000049B5 E802030000          <1> 	call	NEC_OUTPUT
  2508                              <1> 	;mov	ah, [ebp]		; OUTPUT SECTOR #
  2509                              <1> 	; 11/08/2022
  2510 000049BA 8A642424            <1> 	mov	ah, [esp+36] ; CL = OUTPUT SECTOR #
  2511 000049BE E8F9020000          <1> 	call	NEC_OUTPUT
  2512                              <1> 	;mov	dl, 3			; BYTES/SECTOR PARAMETER FROM BLOCK
  2513                              <1> 	; 06/08/2022
  2514 000049C3 B003                <1> 	mov	al, 3
  2515 000049C5 E8FC010000          <1> 	call	GET_PARM 		; ... TO THE NEC
  2516 000049CA E8ED020000          <1> 	call	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  2517                              <1> 	;mov	dl, 4			; EOT PARAMETER FROM BLOCK
  2518                              <1> 	; 06/08/2022
  2519 000049CF B004                <1> 	mov	al, 4
  2520 000049D1 E8F0010000          <1> 	call	GET_PARM 		; ... TO THE NEC
  2521 000049D6 E8E1020000          <1> 	call	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  2522 000049DB 8A6305              <1> 	mov	ah, [ebx+MD.GAP]        ; GET GAP LENGTH
  2523                              <1> _R15:
  2524 000049DE E8D9020000          <1> 	call	NEC_OUTPUT
  2525                              <1> 	;mov	dl, 6			; DTL PARAMETER PROM BLOCK
  2526                              <1> 	; 06/08/2022
  2527 000049E3 B006                <1> 	mov	al, 6
  2528 000049E5 E8DC010000          <1> 	call	GET_PARM		; ... TO THE NEC
  2529 000049EA E8CD020000          <1> 	call	NEC_OUTPUT		; OUTPUT TO CONTROLLER
  2530 000049EF 58                  <1> 	pop	eax			; THROW AWAY ERROR EXIT
  2531                              <1> ER_2:
  2532 000049F0 C3                  <1> 	retn
  2533                              <1> 
  2534                              <1> ;-------------------------------------------------------------------------------
  2535                              <1> ; NEC_TERM
  2536                              <1> ;	THIS ROUTINE WAITS FOR THE OPERATION THEN ACCEPTS THE STATUS 
  2537                              <1> ;	FROM THE NEC FOR THE READ/WRITE/VERIFY/FORWAT OPERATION.
  2538                              <1> ;
  2539                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  2540                              <1> ;-------------------------------------------------------------------------------
  2541                              <1> NEC_TERM:
  2542                              <1> 
  2543                              <1> ;-----	LET THE OPERATION HAPPEN
  2544                              <1> 
  2545 000049F1 56                  <1> 	push	esi			; SAVE HEAD #, # OF SECTORS
  2546 000049F2 E8CD030000          <1> 	call	WAIT_INT		; WAIT FOR THE INTERRUPT
  2547 000049F7 9C                  <1> 	pushf
  2548 000049F8 E8F6030000          <1> 	call	RESULTS			; GET THE NEC STATUS
  2549 000049FD 724B                <1> 	jc	short SET_END_POP
  2550 000049FF 9D                  <1> 	popf
  2551 00004A00 723E                <1> 	jc	short SET_END		; LOOK FOR ERROR
  2552                              <1> 
  2553                              <1> ;-----	CHECK THE RESULTS RETURNED BY THE CONTROLLER
  2554                              <1> 
  2555 00004A02 FC                  <1> 	cld				; SET THE CORRECT DIRECTION
  2556 00004A03 BE[497D0100]        <1> 	mov	esi, NEC_STATUS		; POINT TO STATUS FIELD
  2557 00004A08 AC                  <1> 	lodsb				; GET ST0
  2558 00004A09 24C0                <1> 	and	AL, 11000000B		; TEST FOR NORMAL TERMINATION
  2559 00004A0B 7433                <1> 	jz	short SET_END
  2560 00004A0D 3C40                <1> 	cmp	AL,01000000B		; TEST FOR ABNORMAL TERMINATION
  2561 00004A0F 7527                <1> 	jnz	short J18		; NOT ABNORMAL, BAD NEC
  2562                              <1> 
  2563                              <1> ;-----	ABNORMAL TERMINATION, FIND OUT WHY
  2564                              <1> 
  2565 00004A11 AC                  <1> 	lodsb				; GET ST1
  2566 00004A12 D0E0                <1> 	sal	al, 1			; TEST FOR EDT FOUND
  2567 00004A14 B404                <1> 	mov	ah, RECORD_NOT_FND
  2568 00004A16 7222                <1> 	jc	short J19
  2569 00004A18 C0E002              <1> 	sal	al, 2
  2570 00004A1B B410                <1> 	mov	ah, BAD_CRC
  2571 00004A1D 721B                <1> 	jc	short J19
  2572 00004A1F D0E0                <1> 	sal	al, 1			; TEST FOR DMA OVERRUN
  2573 00004A21 B408                <1> 	mov	ah, BAD_DMA
  2574 00004A23 7215                <1> 	jc	short J19
  2575 00004A25 C0E002              <1> 	sal	al, 2			; TEST FOR RECORD NOT FOUND
  2576 00004A28 B404                <1> 	mov	ah, RECORD_NOT_FND
  2577 00004A2A 720E                <1> 	jc	short J19
  2578 00004A2C D0E0                <1> 	sal	al, 1
  2579 00004A2E B403                <1> 	mov	ah, WRITE_PROTECT	; TEST FOR WRITE_PROTECT
  2580 00004A30 7208                <1> 	jc	short J19
  2581 00004A32 D0E0                <1> 	sal	al, 1			; TEST MISSING ADDRESS MARK
  2582 00004A34 B402                <1> 	mov	ah, BAD_ADDR_MARK
  2583 00004A36 7202                <1> 	jc	short J19
  2584                              <1> 
  2585                              <1> ;----- 	NEC MUST HAVE FAILED
  2586                              <1> J18:
  2587 00004A38 B420                <1> 	mov	ah, BAD_NEC
  2588                              <1> J19:
  2589 00004A3A 0825[487D0100]      <1> 	or	[DSKETTE_STATUS], ah
  2590                              <1> SET_END:
  2591 00004A40 803D[487D0100]01    <1> 	cmp	byte [DSKETTE_STATUS], 1 ; SET ERROR CONDITION
  2592 00004A47 F5                  <1> 	cmc
  2593 00004A48 5E                  <1> 	pop	esi
  2594 00004A49 C3                  <1> 	retn				; RESTORE HEAD #, # OF SECTORS
  2595                              <1> 
  2596                              <1> SET_END_POP:
  2597 00004A4A 9D                  <1> 	popf
  2598 00004A4B EBF3                <1> 	jmp	short SET_END
  2599                              <1> 
  2600                              <1> ;-------------------------------------------------------------------------------
  2601                              <1> ; DSTATE:	ESTABLISH STATE UPON SUCCESSFUL OPERATION.
  2602                              <1> ;-------------------------------------------------------------------------------
  2603                              <1> DSTATE:
  2604 00004A4D 803D[487D0100]00    <1> 	cmp	byte [DSKETTE_STATUS], 0 ; CHECK FOR ERROR
  2605 00004A54 753E                <1> 	jnz	short SETBAC		; IF ERROR JUMP
  2606 00004A56 808F[537D0100]10    <1> 	or	byte [DSK_STATE+edi], MED_DET
  2607                              <1> 					; NO ERROR, MARK MEDIA AS DETERMINED
  2608 00004A5D F687[537D0100]04    <1> 	test	byte [DSK_STATE+edi], DRV_DET ; DRIVE DETERMINED ?
  2609 00004A64 752E                <1> 	jnz	short SETBAC		; IF DETERMINED NO TRY TO DETERMINE
  2610 00004A66 8A87[537D0100]      <1> 	mov	al, [DSK_STATE+edi]	; LOAD STATE
  2611 00004A6C 24C0                <1> 	and	al, RATE_MSK		; KEEP ONLY RATE
  2612 00004A6E 3C80                <1> 	cmp	al, RATE_250		; RATE 250 ?
  2613 00004A70 751B                <1> 	jne	short M_12		; NO, MUST BE 1.2M OR 1.44M DRIVE
  2614                              <1> 
  2615                              <1> ;----- 	CHECK IF IT IS 1.44M
  2616                              <1> 
  2617 00004A72 E846010000          <1> 	call	CMOS_TYPE		; RETURN DRIVE TYPE IN (AL)
  2618                              <1> 	;;20/02/2015
  2619                              <1> 	;;jc	short M_12		; CMOS BAD
  2620 00004A77 7414                <1> 	jz	short M_12 ;; 20/02/2015
  2621 00004A79 3C04                <1> 	cmp	al, 4			; 1.44MB DRIVE ?
  2622 00004A7B 7410                <1> 	je	short M_12		; YES
  2623                              <1> M_720:
  2624 00004A7D 80A7[537D0100]FD    <1> 	and	byte [DSK_STATE+edi], ~FMT_CAPA ; TURN OFF FORMAT CAPABILITY
  2625 00004A84 808F[537D0100]04    <1> 	or	byte [DSK_STATE+edi], DRV_DET ; MARK DRIVE DETERMINED
  2626 00004A8B EB07                <1> 	jmp	short SETBAC		; BACK
  2627                              <1> M_12:	
  2628 00004A8D 808F[537D0100]06    <1> 	or	byte [DSK_STATE+edi], DRV_DET+FMT_CAPA 
  2629                              <1> 					; TURN ON DETERMINED & FMT CAPA
  2630                              <1> SETBAC:
  2631 00004A94 C3                  <1> 	retn
  2632                              <1> 
  2633                              <1> ;-------------------------------------------------------------------------------
  2634                              <1> ; RETRY	
  2635                              <1> ;	DETERMINES WHETHER A RETRY IS NECESSARY. 
  2636                              <1> ;	IF RETRY IS REQUIRED THEN STATE INFORMATION IS UPDATED FOR RETRY.
  2637                              <1> ;
  2638                              <1> ; ON EXIT:	CY = 1 FOR RETRY, CY = 0 FOR NO RETRY
  2639                              <1> ;-------------------------------------------------------------------------------
  2640                              <1> RETRY:
  2641                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  2642 00004A95 803D[487D0100]00    <1> 	cmp	byte [DSKETTE_STATUS], 0 ; GET STATUS OF OPERATION
  2643 00004A9C 7445                <1> 	jz	short NO_RETRY		; SUCCESSFUL OPERATION
  2644 00004A9E 803D[487D0100]80    <1> 	cmp	byte [DSKETTE_STATUS], TIME_OUT ; IF TIME OUT NO RETRY
  2645 00004AA5 743C                <1> 	jz	short NO_RETRY
  2646 00004AA7 8AA7[537D0100]      <1> 	mov	ah, [DSK_STATE+edi]	; GET MEDIA STATE OF DRIVE
  2647 00004AAD F6C410              <1> 	test	ah, MED_DET		; ESTABLISHED/DETERMINED ?
  2648 00004AB0 7531                <1> 	jnz	short NO_RETRY		; IF ESTABLISHED STATE THEN TRUE ERROR
  2649 00004AB2 80E4C0              <1> 	and	ah, RATE_MSK		; ISOLATE RATE
  2650 00004AB5 8A2D[507D0100]      <1> 	mov	ch, [LASTRATE]		; GET START OPERATION STATE
  2651 00004ABB C0C504              <1> 	rol	ch, 4			; TO CORRESPONDING BITS
  2652 00004ABE 80E5C0              <1> 	and	ch, RATE_MSK		; ISOLATE RATE BITS
  2653 00004AC1 38E5                <1> 	cmp	ch, ah			; ALL RATES TRIED
  2654 00004AC3 741E                <1> 	je	short NO_RETRY		; IF YES, THEN TRUE ERROR
  2655                              <1> 
  2656                              <1> ;	SETUP STATE INDICATOR FOR RETRY ATTEMPT TO NEXT RATE
  2657                              <1> ;	 00000000B (500) -> 10000000B	(250)
  2658                              <1> ;	 10000000B (250) -> 01000000B	(300)
  2659                              <1> ;	 01000000B (300) -> 00000000B	(500)
  2660                              <1> 
  2661 00004AC5 80FC01              <1> 	cmp	ah, RATE_500+1		; SET CY FOR RATE 500
  2662 00004AC8 D0DC                <1> 	rcr	ah, 1			; TO NEXT STATE
  2663 00004ACA 80E4C0              <1> 	and	ah, RATE_MSK		; KEEP ONLY RATE BITS
  2664 00004ACD 80A7[537D0100]1F    <1> 	and	byte [DSK_STATE+edi], ~(RATE_MSK+DBL_STEP)
  2665                              <1> 					; RATE, DBL STEP OFF
  2666 00004AD4 08A7[537D0100]      <1> 	or	[DSK_STATE+edi], ah	; TURN ON NEW RATE
  2667 00004ADA C605[487D0100]00    <1> 	mov	byte [DSKETTE_STATUS], 0  ; RESET STATUS FOR RETRY
  2668 00004AE1 F9                  <1> 	stc				; SET CARRY FOR RETRY
  2669 00004AE2 C3                  <1> 	retn				; RETRY RETURN
  2670                              <1> 
  2671                              <1> NO_RETRY:
  2672                              <1> 	; 06/08/2022
  2673                              <1> 	;clc				; CLEAR CARRY NO RETRY
  2674 00004AE3 C3                  <1> 	retn				; NO RETRY RETURN
  2675                              <1> 
  2676                              <1> ;-------------------------------------------------------------------------------
  2677                              <1> ; NUM_TRANS
  2678                              <1> ;	THIS ROUTINE CALCULATES THE NUMBER OF SECTORS THAT WERE
  2679                              <1> ;	ACTUALLY TRANSFERRED TO/FROM THE DISKETTE.
  2680                              <1> ;
  2681                              <1> ; ON ENTRY:	[BP+1] = TRACK
  2682                              <1> ;		SI-HI  = HEAD
  2683                              <1> ;		[BP]   = START SECTOR
  2684                              <1> ;
  2685                              <1> ; ON EXIT:	AL = NUMBER ACTUALLY TRANSFERRED
  2686                              <1> ;-------------------------------------------------------------------------------
  2687                              <1> NUM_TRANS:
  2688                              <1> 	; 10/08/2022
  2689                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  2690 00004AE4 30C0                <1> 	xor	al, al			; CLEAR FOR ERROR
  2691                              <1> 	;cmp	byte [DSKETTE_STATUS], 0
  2692 00004AE6 3805[487D0100]      <1> 	cmp	[DSKETTE_STATUS], al ; 0 ; CHECK FOR ERROR
  2693 00004AEC 752D                <1> 	jnz	short NT_OUT		; IF ERROR 0 TRANSFERRED
  2694                              <1> 	;mov	dl, 4			; SECTORS/TRACK OFFSET TO DL
  2695                              <1> 	; 06/08/2022
  2696 00004AEE B004                <1> 	mov	al, 4
  2697 00004AF0 E8D1000000          <1> 	call	GET_PARM		; AH = SECTORS/TRACK
  2698 00004AF5 8A1D[4E7D0100]      <1> 	mov	bl, [NEC_STATUS+5]	; GET ENDING SECTOR
  2699                              <1> 	;mov	cx, si			; CH = HEAD # STARTED
  2700                              <1> 	; 06/08/2022
  2701 00004AFB 89F1                <1> 	mov	ecx, esi
  2702 00004AFD 3A2D[4D7D0100]      <1> 	cmp	ch, [NEC_STATUS+4]	; GET HEAD ENDED UP ON
  2703 00004B03 750E                <1> 	jnz	short DIF_HD		; IF ON SAME HEAD, THEN NO ADJUST
  2704 00004B05 8A2D[4C7D0100]      <1> 	mov	ch, [NEC_STATUS+3]	; GET TRACK ENDED UP ON
  2705                              <1> 	;cmp	ch, [ebp+1]		; IS IT ASKED FOR TRACK
  2706                              <1> 	; 10/08/2022
  2707 00004B0B 3A6C241D            <1> 	cmp	ch, [esp+29] ; CH = TRACK #
  2708 00004B0F 7404                <1> 	jz	short SAME_TRK		; IF SAME TRACK NO INCREASE
  2709 00004B11 00E3                <1> 	add	bl, ah			; ADD SECTORS/TRACK
  2710                              <1> DIF_HD:
  2711 00004B13 00E3                <1> 	add	bl, ah			; ADD SECTORS/TRACK
  2712                              <1> SAME_TRK:
  2713                              <1> 	;sub	bl, [ebp]		; SUBTRACT START FROM END
  2714                              <1> 	; 10/08/2022
  2715 00004B15 2A5C241C            <1> 	sub	bl, [esp+28] ; CL = SECTOR #	
  2716 00004B19 88D8                <1> 	mov	al, bl			; TO AL
  2717                              <1> NT_OUT:
  2718 00004B1B C3                  <1> 	retn
  2719                              <1> 
  2720                              <1> ;-------------------------------------------------------------------------------
  2721                              <1> ; SETUP_DBL
  2722                              <1> ;	CHECK DOUBLE STEP.
  2723                              <1> ;
  2724                              <1> ; ON ENTRY :	DI = DRIVE
  2725                              <1> ;
  2726                              <1> ; ON EXIT :	CY = 1 MEANS ERROR
  2727                              <1> ;-------------------------------------------------------------------------------
  2728                              <1> SETUP_DBL:
  2729                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  2730 00004B1C 8AA7[537D0100]      <1> 	mov	ah, [DSK_STATE+edi]	; ACCESS STATE
  2731 00004B22 F6C410              <1> 	test	ah, MED_DET		; ESTABLISHED STATE ?
  2732 00004B25 7578                <1> 	jnz	short NO_DBL		; IF ESTABLISHED THEN DOUBLE DONE
  2733                              <1> 
  2734                              <1> ;-----	CHECK FOR TRACK 0 TO SPEED UP ACKNOWLEDGE OF UNFORMATTED DISKETTE
  2735                              <1> 
  2736 00004B27 C605[457D0100]00    <1> 	mov	byte [SEEK_STATUS], 0	; SET RECALIBRATE REQUIRED ON ALL DRIVES
  2737 00004B2E E8CE000000          <1> 	call	MOTOR_ON		; ENSURE MOTOR STAY ON
  2738 00004B33 B500                <1> 	mov	ch, 0			; LOAD TRACK 0
  2739 00004B35 E8B9010000          <1> 	call	SEEK			; SEEK TO TRACK 0
  2740 00004B3A E861000000          <1> 	call	READ_ID			; READ ID FUNCTION
  2741 00004B3F 7243                <1> 	jc	short SD_ERR		; IF ERROR NO TRACK 0
  2742                              <1> 
  2743                              <1> ;-----	INITIALIZE START AND MAX TRACKS (TIMES 2 FOR BOTH HEADS)
  2744                              <1> 
  2745 00004B41 66B95004            <1> 	mov	cx, 0450h 		; START, MAX TRACKS
  2746 00004B45 F687[537D0100]01    <1> 	test	byte [DSK_STATE+edi], TRK_CAPA ; TEST FOR 80 TRACK CAPABILITY
  2747 00004B4C 7402                <1> 	jz	short CNT_OK		; IF NOT COUNT IS SETUP
  2748 00004B4E B1A0                <1> 	mov	cl, 0A0h		; MAXIMUM TRACK 1.2 MB
  2749                              <1> 
  2750                              <1> ;	ATTEMPT READ ID OF ALL TRACKS, ALL HEADS UNTIL SUCCESS; UPON SUCCESS,
  2751                              <1> ;	MUST SEE IF ASKED FOR TRACK IN SINGLE STEP MODE = TRACK ID READ; IF NOT
  2752                              <1> ;	THEN SET DOUBLE STEP ON.
  2753                              <1> 
  2754                              <1> CNT_OK:
  2755                              <1> 	; 11/04/2021 (32 bit push/pop)
  2756 00004B50 C605[477D0100]FF    <1>         mov     byte [MOTOR_COUNT], 0FFh ; ENSURE MOTOR STAYS ON FOR OPERATION
  2757 00004B57 51                  <1> 	push	ecx			; SAVE TRACK, COUNT
  2758 00004B58 C605[487D0100]00    <1> 	mov	byte [DSKETTE_STATUS], 0 ; CLEAR STATUS, EXPECT ERRORS
  2759                              <1> 	;xor	ax, ax			; CLEAR AX
  2760                              <1> 	; 06/08/2022
  2761 00004B5F 31C0                <1> 	xor	eax, eax
  2762 00004B61 D0ED                <1> 	shr	ch, 1			; HALVE TRACK, CY = HEAD
  2763 00004B63 C0D003              <1> 	rcl	al, 3			; AX = HEAD IN CORRECT BIT
  2764 00004B66 50                  <1> 	push	eax			; SAVE HEAD
  2765 00004B67 E887010000          <1> 	call	SEEK			; SEEK TO TRACK
  2766 00004B6C 58                  <1> 	pop	eax			; RESTORE HEAD
  2767                              <1> 	;or	di, ax			; DI = HEAD OR'ED DRIVE
  2768                              <1> 	; 06/08/2022
  2769 00004B6D 09C7                <1> 	or	edi, eax
  2770 00004B6F E82C000000          <1> 	call	READ_ID			; READ ID HEAD 0
  2771 00004B74 9C                  <1> 	pushf				; SAVE RETURN FROM READ_ID
  2772 00004B75 6681E7FB00          <1> 	and	di, 11111011b		; TURN OFF HEAD 1 BIT
  2773 00004B7A 9D                  <1> 	popf				; RESTORE ERROR RETURN
  2774 00004B7B 59                  <1> 	pop	ecx			; RESTORE COUNT
  2775 00004B7C 7308                <1> 	jnc	short DO_CHK		; IF OK, ASKED = RETURNED TRACK ?
  2776 00004B7E FEC5                <1> 	inc	ch			; INC FOR NEXT TRACK
  2777 00004B80 38CD                <1> 	cmp	ch, cl			; REACHED MAXIMUM YET
  2778 00004B82 75CC                <1> 	jnz	short CNT_OK		; CONTINUE TILL ALL TRIED
  2779                              <1> 
  2780                              <1> ;-----	FALL THRU, READ ID FAILED FOR ALL TRACKS
  2781                              <1> 
  2782                              <1> SD_ERR:	
  2783 00004B84 F9                  <1> 	stc				; SET CARRY FOR ERROR
  2784 00004B85 C3                  <1> 	retn				; SETUP_DBL ERROR EXIT
  2785                              <1> 
  2786                              <1> DO_CHK:
  2787 00004B86 8A0D[4C7D0100]      <1> 	mov	cl, [NEC_STATUS+3]	; LOAD RETURNED TRACK
  2788 00004B8C 888F[557D0100]      <1> 	mov	[DSK_TRK+edi], cl	; STORE TRACK NUMBER
  2789 00004B92 D0ED                <1> 	shr	ch, 1			; HALVE TRACK
  2790 00004B94 38CD                <1> 	cmp	ch, cl			; IS IT THE SAME AS ASKED FOR TRACK
  2791 00004B96 7407                <1> 	jz	short NO_DBL		; IF SAME THEN NO DOUBLE STEP
  2792 00004B98 808F[537D0100]20    <1> 	or	byte [DSK_STATE+edi], DBL_STEP ; TURN ON DOUBLE STEP REQUIRED
  2793                              <1> NO_DBL:
  2794                              <1> 	; 06/08/2022
  2795                              <1> 	;clc				; CLEAR ERROR FLAG
  2796 00004B9F C3                  <1> 	retn
  2797                              <1> 
  2798                              <1> ;-------------------------------------------------------------------------------
  2799                              <1> ; READ_ID
  2800                              <1> ;	READ ID FUNCTION.
  2801                              <1> ;
  2802                              <1> ; ON ENTRY:	DI : BIT 2 = HEAD; BITS 1,0 = DRIVE
  2803                              <1> ;
  2804                              <1> ; ON EXIT: 	DI : BIT 2 IS RESET, BITS 1,0 = DRIVE
  2805                              <1> ;		@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION
  2806                              <1> ;-------------------------------------------------------------------------------
  2807                              <1> READ_ID:
  2808                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  2809 00004BA0 B8[BC4B0000]        <1> 	mov	eax, ER_3		; MOVE NEC OUTPUT ERROR ADDRESS
  2810 00004BA5 50                  <1> 	push	eax
  2811 00004BA6 B44A                <1> 	mov	ah, 4Ah			; READ ID COMMAND
  2812 00004BA8 E80F010000          <1> 	call	NEC_OUTPUT		; TO CONTROLLER
  2813                              <1> 	;mov	ax, di			; DRIVE # TO AH, HEAD 0
  2814                              <1> 	; 06/08/2022
  2815 00004BAD 89F8                <1> 	mov	eax, edi
  2816 00004BAF 88C4                <1> 	mov	ah, al
  2817 00004BB1 E806010000          <1> 	call	NEC_OUTPUT		; TO CONTROLLER
  2818 00004BB6 E836FEFFFF          <1> 	call	NEC_TERM		; WAIT FOR OPERATION, GET STATUS
  2819 00004BBB 58                  <1> 	pop	eax			; THROW AWAY ERROR ADDRESS
  2820                              <1> ER_3:
  2821 00004BBC C3                  <1> 	retn
  2822                              <1> 
  2823                              <1> ;-------------------------------------------------------------------------------
  2824                              <1> ; CMOS_TYPE
  2825                              <1> ;	RETURNS DISKETTE TYPE FROM CMOS
  2826                              <1> ;
  2827                              <1> ; ON ENTRY:	DI = DRIVE #
  2828                              <1> ;
  2829                              <1> ; ON EXIT:	AL = TYPE; CY REFLECTS STATUS
  2830                              <1> ;-------------------------------------------------------------------------------
  2831                              <1> 
  2832                              <1> CMOS_TYPE: ; 11/12/2014
  2833 00004BBD 8A87[3C660000]      <1> 	mov	al, [edi+fd0_type]
  2834 00004BC3 20C0                <1> 	and 	al, al ; 18/12/2014
  2835 00004BC5 C3                  <1> 	retn
  2836                              <1> 
  2837                              <1> ;CMOS_TYPE:
  2838                              <1> ;	mov	al, CMOS_DIAG		; CMOS DIAGNOSTIC STATUS BYTE ADDRESS
  2839                              <1> ;	call	CMOS_READ		; GET CMOS STATUS
  2840                              <1> ;	test	al, BAD_BAT+BAD_CKSUM	; BATTERY GOOD AND CHECKSUM VALID
  2841                              <1> ;	stc				; SET CY = 1 INDICATING ERROR FOR RETURN
  2842                              <1> ;	jnz	short BAD_CM		; ERROR IF EITHER BIT ON
  2843                              <1> ;	mov	al, CMOS_DISKETTE	; ADDRESS OF DISKETTE BYTE IN CMOS
  2844                              <1> ;	call	CMOS_READ		; GET DISKETTE BYTE
  2845                              <1> ;	or	di, di			; SEE WHICH DRIVE IN QUESTION
  2846                              <1> ;	jnz	short TB		; IF DRIVE 1, DATA IN LOW NIBBLE
  2847                              <1> ;	ror	al, 4			; EXCHANGE NIBBLES IF SECOND DRIVE
  2848                              <1> ;TB:
  2849                              <1> ;	and	al, 0Fh			; KEEP ONLY DRIVE DATA, RESET CY, 0
  2850                              <1> ;BAD_CM:
  2851                              <1> ;	retn				; CY, STATUS OF READ
  2852                              <1> 
  2853                              <1> ;-------------------------------------------------------------------------------
  2854                              <1> ; GET_PARM
  2855                              <1> ;	THIS ROUTINE FETCHES THE INDEXED POINTER FROM THE DISK_BASE
  2856                              <1> ;	BLOCK POINTED TO BY THE DATA VARIABLE @DISK_POINTER. A BYTE FROM
  2857                              <1> ;	THAT TABLE IS THEN MOVED INTO AH, THE INDEX OF THAT BYTE BEING
  2858                              <1> ;	THE PARAMETER IN DL.
  2859                              <1> ;
  2860                              <1> ; ON ENTRY:	DL = INDEX OF BYTE TO BE FETCHED
  2861                              <1> ;
  2862                              <1> ; ON EXIT:	AH = THAT BYTE FROM BLOCK
  2863                              <1> ;		AL, DH DESTROYED
  2864                              <1> ;-------------------------------------------------------------------------------
  2865                              <1> GET_PARM:
  2866                              <1> 	; 09/08/2022
  2867                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  2868                              <1> 	; AL = INDEX
  2869                              <1> 	; EDI = (current) DRIVE #
  2870                              <1> 	;;push	ds
  2871                              <1> 	;push	esi
  2872                              <1>     	;;sub	ax, ax			; DS = 0, BIOS DATA AREA
  2873                              <1>     	;;mov	ds, ax
  2874                              <1> 	;;mov	ax, cs
  2875                              <1> 	;;mov	ds, ax
  2876                              <1> 	; 08/02/2015 (protected mode modifications, bx -> ebx)
  2877                              <1> 	;xchg	edx, ebx		; BL = INDEX
  2878                              <1> 	; 06/08/2022
  2879 00004BC6 53                  <1> 	push	ebx			; SAVE EBX	
  2880                              <1> 	;movzx	ebx, dl			; EBX = INDEX
  2881 00004BC7 0FB6D8              <1> 	movzx	ebx, al ; 06/08/2022
  2882                              <1> 	;;sub	bh, bh			; BX = INDEX
  2883                              <1> 	;and	ebx, 0FFh
  2884                              <1>     	;;lds	si, [DISK_POINTER]	; POINT TO BLOCK
  2885                              <1> 	;
  2886                              <1> 	; 17/12/2014
  2887                              <1> 	;mov	ax, [cfd]		; current (AL) and previous fd (AH)
  2888                              <1> 	; 06/08/2022
  2889 00004BCA 89F8                <1> 	mov	eax, edi		; EDI = DRIVE #
  2890                              <1> 	;cmp	al, ah
  2891 00004BCC 3A05[2D660000]      <1> 	cmp	al, [pfd]	
  2892 00004BD2 7423                <1> 	je	short gpndc
  2893 00004BD4 A2[2D660000]        <1> 	mov	[pfd], al		; current drive -> previous drive
  2894 00004BD9 53                  <1> 	push	ebx ; 08/02/2015
  2895                              <1> 	;mov	bl, al 
  2896                              <1> 	;; 11/12/2014
  2897                              <1> 	;mov	al, [ebx+fd0_type]	; Drive type (0,1,2,3,4)
  2898                              <1> 	; 09/08/2022
  2899 00004BDA 8A87[3C660000]      <1> 	mov	al, [edi+fd0_type]	; Drive type (0,1,2,3,4)
  2900                              <1> 	; 18/12/2014
  2901 00004BE0 20C0                <1> 	and	al, al
  2902 00004BE2 7507                <1> 	jnz	short gpdtc
  2903 00004BE4 BB[17660000]        <1> 	mov	ebx, MD_TBL6		; 1.44 MB param. tbl. (default)
  2904 00004BE9 EB05                <1>         jmp     short gpdpu
  2905                              <1> gpdtc:	
  2906 00004BEB E809FBFFFF          <1> 	call	DR_TYPE_CHECK
  2907                              <1> 	; cf = 1 -> ebx points to 1.44MB fd parameter table (default)
  2908                              <1> gpdpu:
  2909 00004BF0 891D[B4650000]      <1> 	mov	[DISK_POINTER], ebx
  2910 00004BF6 5B                  <1> 	pop	ebx
  2911                              <1> gpndc:
  2912                              <1> 	;mov	esi, [DISK_POINTER] ; 08/02/2015, si -> esi
  2913                              <1> 	; 06/08/2022
  2914 00004BF7 031D[B4650000]      <1> 	add	ebx, [DISK_POINTER]
  2915                              <1> 	;mov	ah, [esi+ebx]		; GET THE WORD
  2916 00004BFD 8A23                <1> 	mov	ah, [ebx]
  2917                              <1> 	;xchg	edx, ebx		; RESTORE BX
  2918                              <1> 	; 06/08/2022
  2919 00004BFF 5B                  <1> 	pop	ebx			; RESTORE EBX
  2920                              <1> 	;pop	esi
  2921                              <1> 	;;pop	ds
  2922 00004C00 C3                  <1> 	retn
  2923                              <1> 
  2924                              <1> ;-------------------------------------------------------------------------------
  2925                              <1> ; MOTOR_ON
  2926                              <1> ;	TURN MOTOR ON AND WAIT FOR MOTOR START UP TIME. THE @MOTOR_COUNT
  2927                              <1> ;	IS REPLACED WITH A SUFFICIENTLY HIGH NUMBER (0FFH) TO ENSURE
  2928                              <1> ;	THAT THE MOTOR DOES NOT GO OFF DURING THE OPERATION. IF THE
  2929                              <1> ;	MOTOR NEEDED TO BE TURNED ON, THE MULTI-TASKING HOOK FUNCTION
  2930                              <1> ;	(AX=90FDH, INT 15) IS CALLED TELLING THE OPERATING SYSTEM
  2931                              <1> ;	THAT THE BIOS IS ABOUT TO WAIT FOR MOTOR START UP. IF THIS
  2932                              <1> ;	FUNCTION RETURNS WITH CY = 1, IT MEANS THAT THE MINIMUM WAIT
  2933                              <1> ;	HAS BEEN COMPLETED. AT THIS POINT A CHECK IS MADE TO ENSURE
  2934                              <1> ;	THAT THE MOTOR WASN'T TURNED OFF BY THE TIMER. IF THE HOOK DID
  2935                              <1> ;	NOT WAIT, THE WAIT FUNCTION (AH=086H) IS CALLED TO WAIT THE
  2936                              <1> ;	PRESCRIBED AMOUNT OF TIME. IF THE CARRY FLAG IS SET ON RETURN,
  2937                              <1> ;	IT MEANS THAT THE FUNCTION IS IN USE AND DID NOT PERFORM THE
  2938                              <1> ;	WAIT. A TIMER 1 WAIT LOOP WILL THEN DO THE WAIT.
  2939                              <1> ;
  2940                              <1> ; ON ENTRY:	DI = DRIVE #
  2941                              <1> ; ON EXIT:	AX,CX,DX DESTROYED
  2942                              <1> ;-------------------------------------------------------------------------------
  2943                              <1> MOTOR_ON:
  2944                              <1> 	; 06/08/2022 - TRDOS 386 Kernel v2.0.5
  2945 00004C01 53                  <1> 	push	ebx			; SAVE REG.
  2946 00004C02 E825000000          <1> 	call	TURN_ON			; TURN ON MOTOR
  2947 00004C07 7221                <1> 	jc	short MOT_IS_ON		; IF CY=1 NO WAIT
  2948                              <1> 	; 06/08/2022
  2949                              <1> 	;call	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  2950 00004C09 E851FBFFFF          <1> 	call	XLAT_NEW		; TRANSLATE STATE TO PRESENT ARCH,
  2951                              <1> 	;call	TURN_ON 		; CHECK AGAIN IF MOTOR ON
  2952                              <1> 	;jc	short MOT_IS_ON		; IF NO WAIT MEANS IT IS ON
  2953                              <1> M_WAIT:
  2954                              <1> 	;mov	dl, 10			; GET THE MOTOR WAIT PARAMETER
  2955                              <1> 	; 06/08/2022
  2956 00004C0E B00A                <1> 	mov	al, 10
  2957 00004C10 E8B1FFFFFF          <1> 	call	GET_PARM
  2958                              <1> 	;mov	al, ah			; AL = MOTOR WAIT PARAMETER
  2959                              <1> 	;xor	ah, ah			; AX = MOTOR WAIT PARAMETER
  2960                              <1> 	;cmp	al, 8			; SEE IF AT LEAST A SECOND IS SPECIFIED
  2961 00004C15 80FC08              <1> 	cmp	ah, 8
  2962                              <1> 	;jae	short GP2		; IF YES, CONTINUE
  2963 00004C18 7702                <1> 	ja	short J13
  2964                              <1> 	;mov	al, 8			; ONE SECOND WAIT FOR MOTOR START UP
  2965 00004C1A B408                <1> 	mov	ah, 8
  2966                              <1> 
  2967                              <1> ;-----	AS CONTAINS NUMBER OF 1/8 SECONDS (125000 MICROSECONDS) TO WAIT
  2968                              <1> GP2:	
  2969                              <1> ;----- 	FOLLOWING LOOPS REQUIRED WHEN RTC WAIT FUNCTION IS ALREADY IN USE
  2970                              <1> J13:					; WAIT FOR 1/8 SECOND PER (AL)
  2971                              <1> 	;mov	ecx, 8286		; COUNT FOR 1/8 SECOND AT 15.085737 US
  2972                              <1> 	; 11/04/2021
  2973 00004C1C B947100000          <1> 	mov	ecx, 4167 ; count of 30 micro seconds * (1/8) 
  2974 00004C21 E8B5D7FFFF          <1> 	call	WAITF			; GO TO FIXED WAIT ROUTINE
  2975                              <1> 	;dec	al			; DECREMENT TIME VALUE
  2976 00004C26 FECC                <1> 	dec	ah
  2977 00004C28 75F2                <1> 	jnz	short J13		; ARE WE DONE YET
  2978                              <1> MOT_IS_ON:
  2979 00004C2A 5B                  <1> 	pop	ebx			; RESTORE REG.
  2980 00004C2B C3                  <1> 	retn
  2981                              <1> 
  2982                              <1> ;-------------------------------------------------------------------------------
  2983                              <1> ; TURN_ON
  2984                              <1> ;	TURN MOTOR ON AND RETURN WAIT STATE.
  2985                              <1> ;
  2986                              <1> ; ON ENTRY:	DI = DRIVE #
  2987                              <1> ;
  2988                              <1> ; ON EXIT:	CY = 0 MEANS WAIT REQUIRED
  2989                              <1> ;		CY = 1 MEANS NO WAIT REQUIRED
  2990                              <1> ;		AX,BX,CX,DX DESTROYED
  2991                              <1> ;-------------------------------------------------------------------------------
  2992                              <1> TURN_ON:
  2993 00004C2C 89FB                <1> 	mov	ebx, edi		; BX = DRIVE #
  2994 00004C2E 88D9                <1> 	mov	cl, bl			; CL = DRIVE #
  2995 00004C30 C0C304              <1> 	rol	bl, 4			; BL = DRIVE SELECT
  2996 00004C33 FA                  <1> 	cli				; NO INTERRUPTS WHILE DETERMINING STATUS
  2997 00004C34 C605[477D0100]FF    <1> 	mov	byte [MOTOR_COUNT], 0FFh ; ENSURE MOTOR STAYS ON FOR OPERATION
  2998 00004C3B A0[467D0100]        <1> 	mov	al, [MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  2999 00004C40 2430                <1> 	and	al, 00110000b		; KEEP ONLY DRIVE SELECT BITS
  3000 00004C42 B401                <1> 	mov	ah, 1			; MASK FOR DETERMINING MOTOR BIT
  3001 00004C44 D2E4                <1> 	shl	ah, cl			; AH = MOTOR ON, A=00000001, B=00000010
  3002                              <1> 
  3003                              <1> ;  AL = DRIVE SELECT FROM @MOTOR_STATUS
  3004                              <1> ;  BL = DRIVE SELECT DESIRED
  3005                              <1> ;  AH = MOTOR ON MASK DESIRED
  3006                              <1> 
  3007 00004C46 38D8                <1> 	cmp	al, bl			; REQUESTED DRIVE ALREADY SELECTED ?
  3008 00004C48 7508                <1> 	jnz	short TURN_IT_ON	; IF NOT SELECTED JUMP
  3009 00004C4A 8425[467D0100]      <1> 	test	ah, [MOTOR_STATUS]	; TEST MOTOR ON BIT
  3010 00004C50 7535                <1> 	jnz	short NO_MOT_WAIT	; JUMP IF MOTOR ON AND SELECTED
  3011                              <1> 
  3012                              <1> TURN_IT_ON:
  3013 00004C52 08DC                <1> 	or	ah, bl			; AH = DRIVE SELECT AND MOTOR ON
  3014 00004C54 8A3D[467D0100]      <1> 	mov	bh, [MOTOR_STATUS]	; SAVE COPY OF @MOTOR_STATUS BEFORE
  3015 00004C5A 80E70F              <1> 	and	bh, 00001111b		; KEEP ONLY MOTOR BITS
  3016 00004C5D 8025[467D0100]CF    <1> 	and	byte [MOTOR_STATUS], 11001111b ; CLEAR OUT DRIVE SELECT
  3017 00004C64 0825[467D0100]      <1> 	or	[MOTOR_STATUS], ah	; OR IN DRIVE SELECTED AND MOTOR ON
  3018 00004C6A A0[467D0100]        <1> 	mov	al, [MOTOR_STATUS]	; GET DIGITAL OUTPUT REGISTER REFLECTION
  3019 00004C6F 88C3                <1> 	mov	bl, al			; BL=@MOTOR_STATUS AFTER, BH=BEFORE
  3020 00004C71 80E30F              <1> 	and	bl, 00001111b		; KEEP ONLY MOTOR BITS
  3021 00004C74 FB                  <1> 	sti				; ENABLE INTERRUPTS AGAIN
  3022 00004C75 243F                <1> 	and	al, 00111111b		; STRIP AWAY UNWANTED BITS
  3023 00004C77 C0C004              <1> 	rol	al, 4			; PUT BITS IN DESIRED POSITIONS
  3024 00004C7A 0C0C                <1> 	or	al, 00001100b		; NO RESET, ENABLE DMA/INTERRUPT
  3025 00004C7C 66BAF203            <1> 	mov	dx, 03F2h		; SELECT DRIVE AND TURN ON MOTOR
  3026 00004C80 EE                  <1> 	out	dx, al
  3027 00004C81 38FB                <1> 	cmp	bl, bh			; NEW MOTOR TURNED ON ?
  3028                              <1> 	;jz	short NO_MOT_WAIT	; NO WAIT REQUIRED IF JUST SELECT
  3029 00004C83 7403                <1> 	je	short no_mot_w1 ; 27/02/2015 
  3030 00004C85 F8                  <1> 	clc				; (re)SET CARRY MEANING WAIT
  3031 00004C86 C3                  <1> 	retn
  3032                              <1> 
  3033                              <1> NO_MOT_WAIT:
  3034 00004C87 FB                  <1> 	sti
  3035                              <1> no_mot_w1: ; 27/02/2015
  3036 00004C88 F9                  <1> 	stc				; SET NO WAIT REQUIRED
  3037                              <1> 	;sti				; INTERRUPTS BACK ON
  3038 00004C89 C3                  <1> 	retn
  3039                              <1> 
  3040                              <1> ;-------------------------------------------------------------------------------
  3041                              <1> ; HD_WAIT
  3042                              <1> ;	WAIT FOR HEAD SETTLE TIME.
  3043                              <1> ;
  3044                              <1> ; ON ENTRY:	DI = DRIVE #
  3045                              <1> ;
  3046                              <1> ; ON EXIT:	AX,BX,CX,DX DESTROYED
  3047                              <1> ;-------------------------------------------------------------------------------
  3048                              <1> HD_WAIT:
  3049                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  3050                              <1> 	;mov	dl,9			; GET HEAD SETTLE PARAMETER
  3051                              <1> 	; 06/08/2022
  3052 00004C8A B009                <1> 	mov	al, 9
  3053 00004C8C E835FFFFFF          <1> 	call	GET_PARM
  3054 00004C91 08E4                <1> 	or	ah, ah	; 17/12/2014
  3055 00004C93 7519                <1> 	jnz	short DO_WAT
  3056 00004C95 F605[467D0100]80    <1>         test    byte [MOTOR_STATUS], 10000000b ; SEE IF A WRITE OPERATION
  3057                              <1> 	;jz	short ISNT_WRITE	; IF NOT, DO NOT ENFORCE ANY VALUES
  3058                              <1> 	;or	ah, ah			; CHECK FOR ANY WAIT?
  3059                              <1> 	;jnz	short DO_WAT		; IF THERE DO NOT ENFORCE
  3060 00004C9C 741D                <1> 	jz	short HW_DONE
  3061 00004C9E B40F                <1> 	mov	ah, HD12_SETTLE		; LOAD 1.2M HEAD SETTLE MINIMUM
  3062 00004CA0 8A87[537D0100]      <1> 	mov	al, [DSK_STATE+edi]	; LOAD STATE
  3063 00004CA6 24C0                <1> 	and	al, RATE_MSK		; KEEP ONLY RATE
  3064 00004CA8 3C80                <1> 	cmp	al, RATE_250		; 1.2 M DRIVE ?
  3065 00004CAA 7502                <1> 	jnz	short DO_WAT		; DEFAULT HEAD SETTLE LOADED
  3066                              <1> ;GP3:
  3067 00004CAC B414                <1> 	mov	ah, HD320_SETTLE	; USE 320/360 HEAD SETTLE
  3068                              <1> ;	jmp	short DO_WAT
  3069                              <1> 
  3070                              <1> ;ISNT_WRITE:
  3071                              <1> ;	or	ah, ah			; CHECK FOR NO WAIT
  3072                              <1> ;	jz	short HW_DONE		; IF NOT WRITE AND 0 ITS OK
  3073                              <1> 
  3074                              <1> ;-----	AH CONTAINS NUMBER OF MILLISECONDS TO WAIT
  3075                              <1> DO_WAT:
  3076                              <1> ;	mov	al, ah			; AL = # MILLISECONDS
  3077                              <1> ;	;xor	ah, ah			; AX = # MILLISECONDS
  3078                              <1> J29:					; 	1 MILLISECOND LOOP
  3079                              <1> 	;;mov	cx, WAIT_FDU_HEAD_SETTLE ; 33 ; 1 ms in 30 micro units.
  3080                              <1> 	;mov	ecx, 66			; COUNT AT 15.085737 US PER COUNT
  3081                              <1> 	; 11/04/2021
  3082                              <1> 	;mov	ecx, WAIT_FDU_HEAD_SETTLE ; 33
  3083                              <1> 	; 06/08/2022
  3084 00004CAE 29C9                <1> 	sub	ecx, ecx
  3085 00004CB0 B121                <1> 	mov	cl, WAIT_FDU_HEAD_SETTLE ; 33
  3086 00004CB2 E824D7FFFF          <1> 	call	WAITF			; DELAY FOR 1 MILLISECOND
  3087                              <1> 	;dec	al			; DECREMENT THE COUNT
  3088 00004CB7 FECC                <1> 	dec	ah
  3089 00004CB9 75F3                <1> 	jnz	short J29		; DO AL MILLISECOND # OF TIMES
  3090                              <1> HW_DONE:
  3091 00004CBB C3                  <1> 	retn
  3092                              <1> 
  3093                              <1> ;-------------------------------------------------------------------------------
  3094                              <1> ; NEC_OUTPUT
  3095                              <1> ;	THIS ROUTINE SENDS A BYTE TO THE NEC CONTROLLER AFTER TESTING
  3096                              <1> ;	FOR CORRECT DIRECTION AND CONTROLLER READY THIS ROUTINE WILL
  3097                              <1> ;	TIME OUT IF THE BYTE IS NOT ACCEPTED WITHIN A REASONABLE AMOUNT
  3098                              <1> ;	OF TIME, SETTING THE DISKETTE STATUS ON COMPLETION.
  3099                              <1> ; 
  3100                              <1> ; ON ENTRY: 	AH = BYTE TO BE OUTPUT
  3101                              <1> ;
  3102                              <1> ; ON EXIT:	CY = 0  SUCCESS
  3103                              <1> ;		CY = 1  FAILURE -- DISKETTE STATUS UPDATED
  3104                              <1> ;		        IF A FAILURE HAS OCCURRED, THE RETURN IS MADE ONE LEVEL
  3105                              <1> ;		        HIGHER THAN THE CALLER OF NEC OUTPUT. THIS REMOVES THE
  3106                              <1> ;		        REQUIREMENT OF TESTING AFTER EVERY CALL OF NEC_OUTPUT.
  3107                              <1> ;		AX,CX,DX DESTROYED
  3108                              <1> ;-------------------------------------------------------------------------------
  3109                              <1> 
  3110                              <1> ; 09/12/2014 [Erdogan Tan] 
  3111                              <1> ;	(from 'PS2 Hardware Interface Tech. Ref. May 88', Page 09-05.)
  3112                              <1> ; Diskette Drive Controller Status Register (3F4h)
  3113                              <1> ;	This read only register facilitates the transfer of data between
  3114                              <1> ;	the system microprocessor and the controller.
  3115                              <1> ; Bit 7 - When set to 1, the Data register is ready to transfer data 
  3116                              <1> ;	  with the system micrprocessor.
  3117                              <1> ; Bit 6 - The direction of data transfer. If this bit is set to 0,
  3118                              <1> ;	  the transfer is to the controller.
  3119                              <1> ; Bit 5 - When this bit is set to 1, the controller is in the non-DMA mode.
  3120                              <1> ; Bit 4 - When this bit is set to 1, a Read or Write command is being executed.
  3121                              <1> ; Bit 3 - Reserved.
  3122                              <1> ; Bit 2 - Reserved.
  3123                              <1> ; Bit 1 - When this bit is set to 1, dskette drive 1 is in the seek mode.
  3124                              <1> ; Bit 0 - When this bit is set to 1, dskette drive 1 is in the seek mode.
  3125                              <1> 
  3126                              <1> ; Data Register (3F5h)
  3127                              <1> ; This read/write register passes data, commands and parameters, and provides
  3128                              <1> ; diskette status information.
  3129                              <1>   		
  3130                              <1> NEC_OUTPUT:
  3131                              <1> 	; 09/08/2022
  3132                              <1> 	; 06/08/2022 - TRDOS 386 Kernel v2.0.5
  3133                              <1> 	;
  3134                              <1> 	;push	bx			; SAVE REG.
  3135 00004CBC 66BAF403            <1> 	mov	dx, 03F4h		; STATUS PORT
  3136                              <1> 	;mov	bl,2			; HIGH ORDER COUNTER
  3137                              <1> 	;xor	cx, cx			; COUNT FOR TIME OUT
  3138                              <1> 	; 16/12/2014
  3139                              <1> 	; waiting for (max.) 0.5 seconds
  3140                              <1>         ;;mov	byte [wait_count], 0 ;; 27/02/2015
  3141                              <1> 	;
  3142                              <1> 	; 17/12/2014
  3143                              <1> 	; Modified from AWARD BIOS 1999 - ADISK.ASM - SEND_COMMAND
  3144                              <1> 	;
  3145                              <1> 	;WAIT_FOR_PORT:	Waits for a bit at a port pointed to by DX to
  3146                              <1> 	;		go on.
  3147                              <1> 	;INPUT:
  3148                              <1> 	;	AH=Mask for isolation bits.
  3149                              <1> 	;	AL=pattern to look for.
  3150                              <1> 	;	DX=Port to test for
  3151                              <1> 	;	BH:CX=Number of memory refresh periods to delay.
  3152                              <1> 	;	     (normally 30 microseconds per period.)
  3153                              <1> 	;
  3154                              <1> 	;WFP_SHORT:  
  3155                              <1> 	;	Wait for port if refresh cycle is short (15-80 Us range).
  3156                              <1> 	;
  3157                              <1> 
  3158                              <1> ;	mov	bl, WAIT_FDU_SEND_HI+1	; 0+1
  3159                              <1> ;	mov	cx, WAIT_FDU_SEND_LO	; 16667
  3160 00004CC0 B91B410000          <1> 	mov	ecx, WAIT_FDU_SEND_LH   ; 16667 (27/02/2015)
  3161                              <1> ;
  3162                              <1> ;WFPS_OUTER_LP:
  3163                              <1> ;	;
  3164                              <1> ;WFPS_CHECK_PORT:
  3165                              <1> J23:
  3166 00004CC5 EC                  <1> 	in	al, dx			; GET STATUS
  3167 00004CC6 24C0                <1> 	and	al, 11000000b		; KEEP STATUS AND DIRECTION
  3168 00004CC8 3C80                <1> 	cmp	al, 10000000b		; STATUS 1 AND DIRECTION 0 ?
  3169 00004CCA 7418                <1> 	jz	short J27		; STATUS AND DIRECTION OK
  3170                              <1> WFPS_HI:
  3171 00004CCC E461                <1> 	in	al, PORT_B  ; 061h	; SYS1	; wait for hi to lo
  3172 00004CCE A810                <1> 	test	al, 010h		; transition on memory
  3173 00004CD0 75FA                <1> 	jnz	short WFPS_HI		; refresh.
  3174                              <1> WFPS_LO:
  3175 00004CD2 E461                <1> 	in	al, PORT_B		; SYS1
  3176 00004CD4 A810                <1> 	test	al, 010h
  3177 00004CD6 74FA                <1> 	jz	short WFPS_LO
  3178                              <1> 	;loop	short WFPS_CHECK_PORT
  3179 00004CD8 E2EB                <1> 	loop	J23	; 27/02/2015
  3180                              <1> ;	;
  3181                              <1> ;	dec	bl
  3182                              <1> ;	jnz	short WFPS_OUTER_LP
  3183                              <1> ;	jmp	short WFPS_TIMEOUT	; fail
  3184                              <1> ;J23:
  3185                              <1> ;	in	al, dx			; GET STATUS
  3186                              <1> ;	and	al, 11000000b		; KEEP STATUS AND DIRECTION
  3187                              <1> ;	cmp	al, 10000000b		; STATUS 1 AND DIRECTION 0 ?
  3188                              <1> ;	jz	short J27		; STATUS AND DIRECTION OK
  3189                              <1> 	;loop	J23			; CONTINUE TILL CX EXHAUSTED
  3190                              <1> 	;dec	bl			; DECREMENT COUNTER
  3191                              <1> 	;jnz	short J23		; REPEAT TILL DELAY FINISHED, CX = 0
  3192                              <1>    
  3193                              <1> 	;;27/02/2015
  3194                              <1> 	;16/12/2014
  3195                              <1>         ;;cmp	byte [wait_count], 10   ; (10/18.2 seconds)
  3196                              <1> 	;;jb	short J23
  3197                              <1> 
  3198                              <1> ;WFPS_TIMEOUT:
  3199                              <1> 
  3200                              <1> ;-----	FALL THRU TO ERROR RETURN
  3201                              <1> 
  3202 00004CDA 800D[487D0100]80    <1> 	or	byte [DSKETTE_STATUS], TIME_OUT
  3203                              <1> 	;pop	bx			; RESTORE REG.
  3204 00004CE1 58                  <1> 	pop	eax ; 08/02/2015	; DISCARD THE RETURN ADDRESS
  3205 00004CE2 F9                  <1> 	stc				; INDICATE ERROR TO CALLER
  3206 00004CE3 C3                  <1> 	retn
  3207                              <1> 
  3208                              <1> ;-----	DIRECTION AND STATUS OK; OUTPUT BYTE
  3209                              <1> 
  3210                              <1> J27:	
  3211 00004CE4 88E0                <1> 	mov	al, ah			; GET BYTE TO OUTPUT
  3212                              <1> 	;inc	dx			; DATA PORT = STATUS PORT + 1
  3213                              <1> 	; 06/08/2022
  3214 00004CE6 FEC2                <1> 	inc	dl
  3215 00004CE8 EE                  <1> 	out	dx, al			; OUTPUT THE BYTE
  3216                              <1> 	;;NEWIODELAY  ;; 27/02/2015
  3217                              <1> 	; 27/02/2015
  3218                              <1> 	;pushf				; SAVE FLAGS
  3219                              <1> 	; 09/08/2022
  3220                              <1> 	; cf = 0, zf = 1
  3221                              <1> 	;mov	ecx, 3			; 30 TO 45 MICROSECONDS WAIT FOR
  3222                              <1> 	; 11/04/2021
  3223                              <1> 	;mov	ecx, 2 
  3224                              <1> 	; 06/08/2022
  3225 00004CE9 29C9                <1> 	sub	ecx, ecx
  3226 00004CEB B102                <1> 	mov	cl, 2
  3227 00004CED E8E9D6FFFF          <1> 	call 	WAITF			; NEC FLAGS UPDATE CYCLE
  3228                              <1> 	; 09/08/2022
  3229                              <1> 	; cf = 0, zf = 1
  3230                              <1> 	;popf				; RESTORE FLAGS FOR EXIT
  3231                              <1> 	;pop	bx			; RESTORE REG
  3232 00004CF2 C3                  <1> 	retn				; CY = 0 FROM TEST INSTRUCTION
  3233                              <1> 
  3234                              <1> ;-------------------------------------------------------------------------------
  3235                              <1> ; SEEK
  3236                              <1> ;	THIS ROUTINE WILL MOVE THE HEAD ON THE NAMED DRIVE TO THE NAMED
  3237                              <1> ;	TRACK. IF THE DRIVE HAS NOT BEEN ACCESSED SINCE THE DRIVE
  3238                              <1> ;	RESET COMMAND WAS ISSUED, THE DRIVE WILL BE RECALIBRATED.
  3239                              <1> ;
  3240                              <1> ; ON ENTRY:	DI = DRIVE #
  3241                              <1> ;		CH = TRACK #
  3242                              <1> ;
  3243                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  3244                              <1> ;		AX,BX,CX DX DESTROYED
  3245                              <1> ;-------------------------------------------------------------------------------
  3246                              <1> SEEK:
  3247 00004CF3 89FB                <1> 	mov	ebx, edi		; BX = DRIVE #
  3248 00004CF5 B001                <1> 	mov	al, 1			; ESTABLISH MASK FOR RECALIBRATE TEST
  3249                              <1> 	; 06/08/2022
  3250                              <1> 	;xchg	cl, bl			; SET DRIVE VALUE INTO CL
  3251                              <1> 	;rol	al, cl			; SHIFT MASK BY THE DRIVE VALUE
  3252                              <1> 	;xchg	cl, bl			; RECOVER TRACK VALUE
  3253                              <1> 	; 06/08/2022
  3254 00004CF7 84C3                <1> 	test	bl, al ; test bl, 1
  3255 00004CF9 7402                <1> 	jz	short seek_0
  3256 00004CFB FEC0                <1> 	inc	al ; shl al, 1
  3257                              <1> seek_0:
  3258 00004CFD 8405[457D0100]      <1> 	test	al, [SEEK_STATUS]	; TEST FOR RECALIBRATE REQUIRED
  3259 00004D03 7526                <1> 	jnz	short J28A		; JUMP IF RECALIBRATE NOT REQUIRED
  3260                              <1> 
  3261 00004D05 0805[457D0100]      <1> 	or	[SEEK_STATUS], al	; TURN ON THE NO RECALIBRATE BIT IN FLAG
  3262 00004D0B E862000000          <1> 	call	RECAL			; RECALIBRATE DRIVE
  3263 00004D10 730E                <1> 	jnc	short AFT_RECAL		; RECALIBRATE DONE
  3264                              <1> 
  3265                              <1> ;-----	ISSUE RECALIBRATE FOR 80 TRACK DISKETTES
  3266                              <1> 
  3267 00004D12 C605[487D0100]00    <1> 	mov	byte [DSKETTE_STATUS], 0 ; CLEAR OUT INVALID STATUS
  3268 00004D19 E854000000          <1> 	call	RECAL			; RECALIBRATE DRIVE
  3269 00004D1E 7251                <1> 	jc	short RB		; IF RECALIBRATE FAILS TWICE THEN ERROR
  3270                              <1> 
  3271                              <1> AFT_RECAL:
  3272 00004D20 C687[557D0100]00    <1>         mov     byte [DSK_TRK+edi], 0	; SAVE NEW CYLINDER AS PRESENT POSITION
  3273 00004D27 08ED                <1> 	or	ch, ch			; CHECK FOR SEEK TO TRACK 0
  3274 00004D29 743F                <1> 	jz	short DO_WAIT		; HEAD SETTLE, CY = 0 IF JUMP
  3275                              <1> 
  3276                              <1> ;-----	DRIVE IS IN SYNCHRONIZATION WITH CONTROLLER, SEEK TO TRACK
  3277                              <1> 
  3278 00004D2B F687[537D0100]20    <1> J28A:	test	byte [DSK_STATE+edi], DBL_STEP ; CHECK FOR DOUBLE STEP REQUIRED
  3279 00004D32 7402                <1> 	jz	short _R7		; SINGLE STEP REQUIRED BYPASS DOUBLE
  3280 00004D34 D0E5                <1> 	shl	ch, 1			; DOUBLE NUMBER OF STEP TO TAKE
  3281                              <1> 
  3282 00004D36 3AAF[557D0100]      <1> _R7:	cmp	ch, [DSK_TRK+edi]	; SEE IF ALREADY AT THE DESIRED TRACK
  3283 00004D3C 7433                <1> 	je	short RB		; IF YES, DO NOT NEED TO SEEK
  3284                              <1> 
  3285 00004D3E BA[714D0000]        <1> 	mov	edx, NEC_ERR		; LOAD RETURN ADDRESS
  3286 00004D43 52                  <1> 	push	edx ; (*)		; ON STACK FOR NEC OUTPUT ERROR
  3287 00004D44 88AF[557D0100]      <1> 	mov	[DSK_TRK+edi], ch	; SAVE NEW CYLINDER AS PRESENT POSITION
  3288 00004D4A B40F                <1> 	mov	ah, 0Fh			; SEEK COMMAND TO NEC
  3289 00004D4C E86BFFFFFF          <1> 	call	NEC_OUTPUT
  3290 00004D51 89FB                <1> 	mov	ebx, edi		; BX = DRIVE #
  3291 00004D53 88DC                <1> 	mov	ah, bl			; OUTPUT DRIVE NUMBER
  3292 00004D55 E862FFFFFF          <1> 	call	NEC_OUTPUT
  3293 00004D5A 8AA7[557D0100]      <1> 	mov	ah, [DSK_TRK+edi]	; GET CYLINDER NUMBER
  3294 00004D60 E857FFFFFF          <1> 	call	NEC_OUTPUT
  3295 00004D65 E827000000          <1> 	call	CHK_STAT_2		; ENDING INTERRUPT AND SENSE STATUS
  3296                              <1> 
  3297                              <1> ;-----	WAIT FOR HEAD SETTLE
  3298                              <1> 
  3299                              <1> DO_WAIT:
  3300 00004D6A 9C                  <1> 	pushf				; SAVE STATUS
  3301 00004D6B E81AFFFFFF          <1> 	call	HD_WAIT			; WAIT FOR HEAD SETTLE TIME
  3302 00004D70 9D                  <1> 	popf				; RESTORE STATUS
  3303                              <1> RB:
  3304                              <1> NEC_ERR:
  3305                              <1> 	; 08/02/2015 (code trick here from original IBM PC/AT DISKETTE.ASM)
  3306                              <1> 	; (*) nec_err -> retn (push edx -> pop edx) -> nec_err -> retn
  3307 00004D71 C3                  <1> 	retn				; RETURN TO CALLER
  3308                              <1> 
  3309                              <1> ;-------------------------------------------------------------------------------
  3310                              <1> ; RECAL
  3311                              <1> ;	RECALIBRATE DRIVE
  3312                              <1> ;
  3313                              <1> ; ON ENTRY:	DI = DRIVE #
  3314                              <1> ;
  3315                              <1> ; ON EXIT:	CY REFLECTS STATUS OF OPERATION.
  3316                              <1> ;-------------------------------------------------------------------------------
  3317                              <1> RECAL:
  3318                              <1> 	;push	cx
  3319                              <1> 	; 11/04/2021
  3320 00004D72 51                  <1> 	push	ecx
  3321 00004D73 B8[8F4D0000]        <1> 	mov	eax, RC_BACK		; LOAD NEC_OUTPUT ERROR
  3322 00004D78 50                  <1> 	push	eax
  3323 00004D79 B407                <1> 	mov	ah, 07h			; RECALIBRATE COMMAND
  3324 00004D7B E83CFFFFFF          <1> 	call	NEC_OUTPUT
  3325 00004D80 89FB                <1> 	mov	ebx, edi		; BX = DRIVE #
  3326 00004D82 88DC                <1> 	mov	ah, bl
  3327 00004D84 E833FFFFFF          <1> 	call	NEC_OUTPUT		; OUTPUT THE DRIVE NUMBER
  3328 00004D89 E803000000          <1> 	call	CHK_STAT_2		; GET THE INTERRUPT AND SENSE INT STATUS
  3329 00004D8E 58                  <1> 	pop	eax			; THROW AWAY ERROR
  3330                              <1> RC_BACK:
  3331                              <1> 	;pop	cx
  3332                              <1> 	; 11/04/2021
  3333 00004D8F 59                  <1> 	pop	ecx
  3334 00004D90 C3                  <1> 	retn
  3335                              <1> 
  3336                              <1> ;-------------------------------------------------------------------------------
  3337                              <1> ; CHK_STAT_2
  3338                              <1> ;	THIS ROUTINE HANDLES THE INTERRUPT RECEIVED AFTER RECALIBRATE,
  3339                              <1> ;	OR SEEK TO THE ADAPTER. THE INTERRUPT IS WAITED FOR, THE
  3340                              <1> ;	INTERRUPT STATUS SENSED, AND THE RESULT RETURNED TO THE CALLER.
  3341                              <1> ;
  3342                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  3343                              <1> ;-------------------------------------------------------------------------------
  3344                              <1> CHK_STAT_2:
  3345 00004D91 B8[B94D0000]        <1>         mov     eax, CS_BACK            ; LOAD NEC_OUTPUT ERROR ADDRESS
  3346 00004D96 50                  <1> 	push	eax
  3347 00004D97 E828000000          <1> 	call	WAIT_INT		; WAIT FOR THE INTERRUPT
  3348 00004D9C 721A                <1> 	jc	short J34		; IF ERROR, RETURN IT
  3349 00004D9E B408                <1> 	mov	ah, 08h			; SENSE INTERRUPT STATUS COMMAND
  3350 00004DA0 E817FFFFFF          <1> 	call	NEC_OUTPUT
  3351 00004DA5 E849000000          <1> 	call	RESULTS			; READ IN THE RESULTS
  3352 00004DAA 720C                <1> 	jc	short J34
  3353 00004DAC A0[497D0100]        <1> 	mov	al, [NEC_STATUS]	; GET THE FIRST STATUS BYTE
  3354 00004DB1 2460                <1> 	and	al, 01100000B		; ISOLATE THE BITS
  3355 00004DB3 3C60                <1> 	cmp	al, 01100000B		; TEST FOR CORRECT VALUE
  3356 00004DB5 7403                <1> 	jz	short J35		; IF ERROR, GO MARK IT
  3357 00004DB7 F8                  <1> 	clc				; GOOD RETURN
  3358                              <1> J34:
  3359 00004DB8 58                  <1> 	pop	eax			; THROW AWAY ERROR RETURN
  3360                              <1> CS_BACK:
  3361 00004DB9 C3                  <1> 	retn
  3362                              <1> J35:
  3363 00004DBA 800D[487D0100]40    <1> 	or	byte [DSKETTE_STATUS], BAD_SEEK
  3364 00004DC1 F9                  <1> 	stc				; ERROR RETURN CODE
  3365 00004DC2 EBF4                <1> 	jmp	short J34
  3366                              <1> 
  3367                              <1> ;-------------------------------------------------------------------------------
  3368                              <1> ; WAIT_INT
  3369                              <1> ;	THIS ROUTINE WAITS FOR AN INTERRUPT TO OCCUR A TIME OUT ROUTINE
  3370                              <1> ;	TAKES PLACE DURING THE WAIT, SO THAT AN ERROR MAY BE RETURNED
  3371                              <1> ;	IF THE DRIVE IS NOT READY.
  3372                              <1> ;
  3373                              <1> ; ON EXIT: 	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  3374                              <1> ;-------------------------------------------------------------------------------
  3375                              <1> 
  3376                              <1> ; 17/12/2014
  3377                              <1> ; 2.5 seconds waiting !
  3378                              <1> ;(AWARD BIOS - 1999, WAIT_FDU_INT_LOW, WAIT_FDU_INT_HI)
  3379                              <1> ; amount of time to wait for completion interrupt from NEC.
  3380                              <1> 
  3381                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  3382                              <1> WAIT_INT:
  3383 00004DC4 FB                  <1> 	sti				; TURN ON INTERRUPTS, JUST IN CASE
  3384                              <1> 	; 06/08/2022
  3385                              <1> 	;clc				; CLEAR TIMEOUT INDICATOR
  3386                              <1> 	;
  3387                              <1> 	;mov	bl, 10			; CLEAR THE COUNTERS
  3388                              <1> 	;xor	cx, cx			; FOR 2 SECOND WAIT
  3389                              <1> 
  3390                              <1> 	; Modification from AWARD BIOS - 1999 (ATORGS.ASM, WAIT
  3391                              <1> 	;
  3392                              <1> 	;WAIT_FOR_MEM:	
  3393                              <1> 	;	Waits for a bit at a specified memory location pointed
  3394                              <1> 	;	to by ES:[DI] to become set.
  3395                              <1> 	;INPUT:
  3396                              <1> 	;	AH= Mask to test with.
  3397                              <1> 	;	ES:[DI] = memory location to watch.
  3398                              <1> 	;	BH:CX= Number of memory refresh periods to delay.
  3399                              <1> 	;	     (normally 30 microseconds per period.)
  3400                              <1> 
  3401                              <1> 	; waiting for (max.) 2.5 secs in 30 micro units.
  3402                              <1> ;	mov 	cx, WAIT_FDU_INT_LO		; 017798
  3403                              <1> ;;	mov 	bl, WAIT_FDU_INT_HI
  3404                              <1> ;	mov 	bl, WAIT_FDU_INT_HI + 1
  3405                              <1> 	; 27/02/2015
  3406 00004DC5 B986450100          <1> 	mov 	ecx, WAIT_FDU_INT_LH	; 83334 (2.5 seconds)		
  3407                              <1> WFMS_CHECK_MEM:
  3408 00004DCA F605[457D0100]80    <1> 	test	byte [SEEK_STATUS], INT_FLAG
  3409                              <1> 					; TEST FOR INTERRUPT OCCURRING
  3410 00004DD1 7516                <1>         jnz     short J37
  3411                              <1> WFMS_HI:
  3412 00004DD3 E461                <1> 	in	al, PORT_B  ; 061h	; SYS1, wait for lo to hi
  3413 00004DD5 A810                <1> 	test	al, 010h		; transition on memory
  3414 00004DD7 75FA                <1> 	jnz	short WFMS_HI		; refresh.
  3415                              <1> WFMS_LO:
  3416 00004DD9 E461                <1> 	in	al, PORT_B		; SYS1
  3417 00004DDB A810                <1> 	test	al, 010h
  3418 00004DDD 74FA                <1> 	jz	short WFMS_LO
  3419 00004DDF E2E9                <1>         loop	WFMS_CHECK_MEM
  3420                              <1> 
  3421                              <1> ;WFMS_OUTER_LP:
  3422                              <1> ;;	or	bl, bl			; check outer counter
  3423                              <1> ;;	jz	short J36A		; WFMS_TIMEOUT
  3424                              <1> ;	dec	bl
  3425                              <1> ;	jz	short J36A	
  3426                              <1> ;	jmp	short WFMS_CHECK_MEM
  3427                              <1> 
  3428                              <1> 	; 17/12/2014
  3429                              <1> 	; 16/12/2014
  3430                              <1> ;	mov	byte [wait_count], 0	; Reset (INT 08H) counter
  3431                              <1> ;J36:
  3432                              <1> ;	test	byte [SEEK_STATUS], INT_FLAG
  3433                              <1> ;					; TEST FOR INTERRUPT OCCURRING
  3434                              <1> ;	jnz	short J37
  3435                              <1> 
  3436                              <1> 	; 16/12/2014
  3437                              <1> 	;loop	J36			; COUNT DOWN WHILE WAITING
  3438                              <1> 	;dec	bl			; SECOND LEVEL COUNTER
  3439                              <1> 	;jnz	short J36
  3440                              <1> ;       cmp     byte [wait_count], 46   ; (46/18.2 seconds)
  3441                              <1> ;	jb	short J36
  3442                              <1> 
  3443                              <1> ;WFMS_TIMEOUT:
  3444                              <1> ;J36A:
  3445 00004DE1 800D[487D0100]80    <1> 	or	byte [DSKETTE_STATUS], TIME_OUT ; NOTHING HAPPENED
  3446 00004DE8 F9                  <1> 	stc				; ERROR RETURN
  3447                              <1> J37:
  3448 00004DE9 9C                  <1> 	pushf				; SAVE CURRENT CARRY
  3449 00004DEA 8025[457D0100]7F    <1> 	and	byte [SEEK_STATUS], ~INT_FLAG ; TURN OFF INTERRUPT FLAG
  3450 00004DF1 9D                  <1> 	popf				; RECOVER CARRY
  3451 00004DF2 C3                  <1> 	retn				; GOOD RETURN CODE
  3452                              <1> 
  3453                              <1> ;-------------------------------------------------------------------------------
  3454                              <1> ; RESULTS
  3455                              <1> ;	THIS ROUTINE WILL READ ANYTHING THAT THE NEC CONTROLLER RETURNS 
  3456                              <1> ;	FOLLOWING AN INTERRUPT.
  3457                              <1> ;
  3458                              <1> ; ON EXIT:	@DSKETTE_STATUS, CY REFLECT STATUS OF OPERATION.
  3459                              <1> ;		AX,BX,CX,DX DESTROYED
  3460                              <1> ;-------------------------------------------------------------------------------
  3461                              <1> RESULTS:
  3462                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  3463 00004DF3 57                  <1> 	push	edi
  3464 00004DF4 BF[497D0100]        <1> 	mov	edi, NEC_STATUS		; POINTER TO DATA AREA
  3465 00004DF9 B307                <1> 	mov	bl, 7			; MAX STATUS BYTES
  3466 00004DFB 66BAF403            <1> 	mov	dx, 03F4h		; STATUS PORT
  3467                              <1> 
  3468                              <1> ;-----	WAIT FOR REQUEST FOR MASTER
  3469                              <1> 
  3470                              <1> _R10: 
  3471                              <1> 	; 16/12/2014
  3472                              <1> 	; wait for (max) 0.5 seconds
  3473                              <1> 	;mov	bh, 2			; HIGH ORDER COUNTER
  3474                              <1> 	;xor	cx, cx			; COUNTER
  3475                              <1> 
  3476                              <1> 	;Time to wait while waiting for each byte of NEC results = .5
  3477                              <1> 	;seconds.  .5 seconds = 500,000 micros.  500,000/30 = 16,667.
  3478                              <1> 	; 27/02/2015
  3479 00004DFF B91B410000          <1> 	mov 	ecx, WAIT_FDU_RESULTS_LH ; 16667  
  3480                              <1> 	;mov	cx, WAIT_FDU_RESULTS_LO  ; 16667
  3481                              <1> 	;mov	bh, WAIT_FDU_RESULTS_HI+1 ; 0+1
  3482                              <1> 
  3483                              <1> WFPSR_OUTER_LP:
  3484                              <1> 	;
  3485                              <1> WFPSR_CHECK_PORT:
  3486                              <1> J39:					; WAIT FOR MASTER
  3487 00004E04 EC                  <1> 	in	al, dx			; GET STATUS
  3488 00004E05 24C0                <1> 	and	al, 11000000b		; KEEP ONLY STATUS AND DIRECTION
  3489 00004E07 3CC0                <1> 	cmp	al, 11000000b		; STATUS 1 AND DIRECTION 1 ?
  3490 00004E09 7418                <1> 	jz	short J42		; STATUS AND DIRECTION OK
  3491                              <1> WFPSR_HI:
  3492 00004E0B E461                <1> 	in	al, PORT_B	; 061h	; SYS1	; wait for hi to lo
  3493 00004E0D A810                <1> 	test	al, 010h		; transition on memory
  3494 00004E0F 75FA                <1> 	jnz	short WFPSR_HI		; refresh.
  3495                              <1> WFPSR_LO:
  3496 00004E11 E461                <1> 	in	al, PORT_B		; SYS1
  3497 00004E13 A810                <1> 	test	al, 010h
  3498 00004E15 74FA                <1> 	jz	SHORT WFPSR_LO
  3499 00004E17 E2EB                <1> 	loop	WFPSR_CHECK_PORT
  3500                              <1> 
  3501                              <1> 	;; 27/02/2015
  3502                              <1> 	;;dec	bh
  3503                              <1> 	;;jnz	short WFPSR_OUTER_LP
  3504                              <1> 	;jmp	short WFPSR_TIMEOUT	; fail
  3505                              <1> 
  3506                              <1> 	;;mov	byte [wait_count], 0
  3507                              <1> ;J39:					; WAIT FOR MASTER
  3508                              <1> ;	in	al, dx			; GET STATUS
  3509                              <1> ;	and	al, 11000000b		; KEEP ONLY STATUS AND DIRECTION
  3510                              <1> ;	cmp	al, 11000000b		; STATUS 1 AND DIRECTION 1 ?
  3511                              <1> ;	jz	short J42		; STATUS AND DIRECTION OK
  3512                              <1> 	;loop	J39			; LOOP TILL TIMEOUT
  3513                              <1> 	;dec	bh			; DECREMENT HIGH ORDER COUNTER
  3514                              <1> 	;jnz	short J39		; REPEAT TILL DELAY DONE
  3515                              <1> 	;
  3516                              <1> 	;;cmp	byte [wait_count], 10  ; (10/18.2 seconds)
  3517                              <1> 	;;jb	short J39	
  3518                              <1> 
  3519                              <1> ;WFPSR_TIMEOUT:
  3520 00004E19 800D[487D0100]80    <1> 	or	byte [DSKETTE_STATUS], TIME_OUT
  3521 00004E20 F9                  <1> 	stc				; SET ERROR RETURN
  3522 00004E21 EB28                <1> 	jmp	short POPRES		; POP REGISTERS AND RETURN
  3523                              <1> 
  3524                              <1> ;-----	READ IN THE STATUS
  3525                              <1> 
  3526                              <1> J42:
  3527 00004E23 EB00                <1> 	jmp	$+2			; I/O DELAY
  3528                              <1> 	;inc	dx			; POINT AT DATA PORT
  3529                              <1> 	; 06/08/2022
  3530 00004E25 FEC2                <1> 	inc	dl
  3531 00004E27 EC                  <1> 	in	al, dx			; GET THE DATA
  3532                              <1> 	; 16/12/2014
  3533                              <1> 	NEWIODELAY
    83 00004E28 E6EB                <2>  out 0EBh, al
  3534 00004E2A 8807                <1>         mov     [edi], al		; STORE THE BYTE
  3535 00004E2C 47                  <1> 	inc	edi			; INCREMENT THE POINTER
  3536                              <1> 
  3537                              <1> 	; 16/12/2014
  3538                              <1> ;	push	cx
  3539                              <1> ;	mov	cx, 30
  3540                              <1> ;wdw2:
  3541                              <1> ;	NEWIODELAY
  3542                              <1> ;	loop	wdw2
  3543                              <1> ;	pop	cx
  3544                              <1> 
  3545                              <1> 	;;mov	ecx, 3			; MINIMUM 24 MICROSECONDS FOR NEC
  3546                              <1> 	; 11/04/2021
  3547                              <1> 	;mov	ecx, 2
  3548                              <1> 	; 06/08/2022
  3549 00004E2D 29C9                <1> 	sub	ecx, ecx
  3550 00004E2F B102                <1> 	mov	cl, 2
  3551 00004E31 E8A5D5FFFF          <1> 	call	WAITF			; WAIT 30 TO 45 MICROSECONDS
  3552                              <1> 	;dec	dx			; POINT AT STATUS PORT
  3553                              <1> 	; 06/08/2022
  3554 00004E36 FECA                <1> 	dec	dl
  3555 00004E38 EC                  <1> 	in	al, dx			; GET STATUS
  3556                              <1> 	; 16/12/2014
  3557                              <1> 	NEWIODELAY
    83 00004E39 E6EB                <2>  out 0EBh, al
  3558                              <1> 	;
  3559 00004E3B A810                <1> 	test	al, 00010000b		; TEST FOR NEC STILL BUSY
  3560 00004E3D 740C                <1> 	jz	short POPRES		; RESULTS DONE ?
  3561                              <1> 
  3562 00004E3F FECB                <1> 	dec	bl			; DECREMENT THE STATUS COUNTER
  3563 00004E41 75BC                <1>         jnz     short _R10              ; GO BACK FOR MORE
  3564 00004E43 800D[487D0100]20    <1> 	or	byte [DSKETTE_STATUS], BAD_NEC ; TOO MANY STATUS BYTES
  3565 00004E4A F9                  <1> 	stc				; SET ERROR FLAG
  3566                              <1> 
  3567                              <1> ;-----	RESULT OPERATION IS DONE
  3568                              <1> POPRES:
  3569 00004E4B 5F                  <1> 	pop	edi
  3570 00004E4C C3                  <1> 	retn				; RETURN WITH CARRY SET
  3571                              <1> 
  3572                              <1> ;-------------------------------------------------------------------------------
  3573                              <1> ; READ_DSKCHNG
  3574                              <1> ;	READS THE STATE OF THE DISK CHANGE LINE.
  3575                              <1> ;
  3576                              <1> ; ON ENTRY:	DI = DRIVE #
  3577                              <1> ;
  3578                              <1> ; ON EXIT:	DI = DRIVE #
  3579                              <1> ;		ZF = 0 : DISK CHANGE LINE INACTIVE
  3580                              <1> ;		ZF = 1 : DISK CHANGE LINE ACTIVE
  3581                              <1> ;		AX,CX,DX DESTROYED
  3582                              <1> ;-------------------------------------------------------------------------------
  3583                              <1> READ_DSKCHNG:
  3584 00004E4D E8AFFDFFFF          <1> 	call	MOTOR_ON		; TURN ON THE MOTOR IF OFF
  3585 00004E52 66BAF703            <1> 	mov	dx, 03F7h		; ADDRESS DIGITAL INPUT REGISTER
  3586 00004E56 EC                  <1> 	in	al, dx			; INPUT DIGITAL INPUT REGISTER
  3587 00004E57 A880                <1> 	test	al, DSK_CHG		; CHECK FOR DISK CHANGE LINE ACTIVE
  3588 00004E59 C3                  <1> 	retn				; RETURN TO CALLER WITH ZERO FLAG SET
  3589                              <1> 
  3590                              <1> fdc_int:  
  3591                              <1> 	  ; 30/07/2015	
  3592                              <1> 	  ; 16/02/2015
  3593                              <1> ;int_0Eh: ; 11/12/2014
  3594                              <1> 
  3595                              <1> ;--- HARDWARE INT 0EH -- ( IRQ LEVEL 6 ) ---------------------------------------
  3596                              <1> ; DISK_INT
  3597                              <1> ;	THIS ROUTINE HANDLES THE DISKETTE INTERRUPT.
  3598                              <1> ;
  3599                              <1> ; ON EXIT:	THE INTERRUPT FLAG IS SET IN @SEEK_STATUS.
  3600                              <1> ;-------------------------------------------------------------------------------
  3601                              <1> DISK_INT_1:
  3602                              <1> 	;push	AX			; SAVE WORK REGISTER
  3603                              <1> 	; 11/04/2021
  3604 00004E5A 50                  <1> 	push	eax
  3605 00004E5B 1E                  <1> 	push	ds
  3606 00004E5C 66B81000            <1> 	mov	ax, KDATA
  3607 00004E60 8ED8                <1> 	mov 	ds, ax
  3608 00004E62 800D[457D0100]80    <1>         or	byte [SEEK_STATUS], INT_FLAG ; TURN ON INTERRUPT OCCURRED
  3609 00004E69 B020                <1> 	mov     al, EOI			; END OF INTERRUPT MARKER
  3610 00004E6B E620                <1> 	out	INTA00, al		; INTERRUPT CONTROL PORT
  3611 00004E6D 1F                  <1> 	pop	ds
  3612                              <1> 	;pop	ax			; RECOVER REGISTER
  3613                              <1> 	; 11/04/2021
  3614 00004E6E 58                  <1> 	pop	eax
  3615 00004E6F CF                  <1> 	iretd				; RETURN FROM INTERRUPT
  3616                              <1> 
  3617                              <1> ;-------------------------------------------------------------------------------
  3618                              <1> ; DSKETTE_SETUP
  3619                              <1> ;	THIS ROUTINE DOES A PRELIMINARY CHECK TO SEE WHAT TYPE OF
  3620                              <1> ;	DISKETTE DRIVES ARE ATTACH TO THE SYSTEM.
  3621                              <1> ;-------------------------------------------------------------------------------
  3622                              <1> 
  3623                              <1> ; 09/08/2022 - TRDOS 386 Kernel v2.0.5
  3624                              <1> ; 29/05/2016 - TRDOS 386 (TRDOS v2.0)
  3625                              <1> 
  3626                              <1> DSKETTE_SETUP:
  3627                              <1> 	;push	ax			; SAVE REGISTERS
  3628                              <1> 	;push	bx
  3629                              <1> 	;push	cx
  3630 00004E70 52                  <1> 	push	edx
  3631                              <1> 	;push	di
  3632                              <1> 	;;push	ds
  3633                              <1> 	; 14/12/2014
  3634                              <1> 	;mov	word [DISK_POINTER], MD_TBL6
  3635                              <1> 	;mov	[DISK_POINTER+2], cs
  3636                              <1> 	;
  3637                              <1> 	;or	byte [RTC_WAIT_FLAG], 1	; NO RTC WAIT, FORCE USE OF LOOP
  3638 00004E71 31FF                <1> 	xor	edi, edi		; INITIALIZE DRIVE POINTER
  3639                              <1> 	; 09/08/2022
  3640                              <1> 	;mov	esi, eax
  3641 00004E73 31C0                <1> 	xor	eax, eax ; eax = 0
  3642 00004E75 66A3[537D0100]      <1> 	mov	[DSK_STATE], ax		; INITIALIZE STATES
  3643 00004E7B 8025[507D0100]33    <1> 	and	byte [LASTRATE], ~(STRT_MSK+SEND_MSK) ; CLEAR START & SEND
  3644 00004E82 800D[507D0100]C0    <1> 	or	byte [LASTRATE], SEND_MSK ; INITIALIZE SENT TO IMPOSSIBLE
  3645 00004E89 A2[457D0100]        <1> 	mov	[SEEK_STATUS], al	; INDICATE RECALIBRATE NEEDED
  3646 00004E8E A2[477D0100]        <1> 	mov	[MOTOR_COUNT], al	; INITIALIZE MOTOR COUNT
  3647 00004E93 A2[467D0100]        <1> 	mov	[MOTOR_STATUS], al	; INITIALIZE DRIVES TO OFF STATE
  3648 00004E98 A2[487D0100]        <1> 	mov	[DSKETTE_STATUS], al	; NO ERRORS
  3649                              <1> 	;
  3650                              <1> 	; 28/02/2015
  3651                              <1> 	;mov	word [cfd], 100h 
  3652 00004E9D E815F4FFFF          <1> 	call	DSK_RESET
  3653 00004EA2 5A                  <1> 	pop	edx
  3654 00004EA3 F8                  <1> 	clc	; 29/05/2016
  3655 00004EA4 C3                  <1> 	retn
  3656                              <1> 
  3657                              <1> ;SUP0:
  3658                              <1> ;	call	DRIVE_DET		; DETERMINE DRIVE
  3659                              <1> ;	call	XLAT_OLD		; TRANSLATE STATE TO COMPATIBLE MODE
  3660                              <1> ;	; 02/01/2015
  3661                              <1> ;	;inc	di			; POINT TO NEXT DRIVE
  3662                              <1> ;	;cmp	di, MAX_DRV		; SEE IF DONE
  3663                              <1> ;	;jnz	short SUP0		; REPEAT FOR EACH ORIVE
  3664                              <1> ;       cmp     byte [fd1_type], 0	
  3665                              <1> ;	jna	short sup1
  3666                              <1> ;	or	di, di
  3667                              <1> ;	jnz	short sup1
  3668                              <1> ;	inc	di
  3669                              <1> ;       jmp     short SUP0
  3670                              <1> ;sup1:
  3671                              <1> ;	mov	byte [SEEK_STATUS], 0	; FORCE RECALIBRATE
  3672                              <1> ;	;and	byte [RTC_WAIT_FLAG], 0FEh ; ALLOW FOR RTC WAIT
  3673                              <1> ;	call	SETUP_END		; VARIOUS CLEANUPS
  3674                              <1> ;	;;pop	ds			; RESTORE CALLERS REGISTERS
  3675                              <1> ;	;pop	di
  3676                              <1> ;	pop	edx
  3677                              <1> ;	;pop	cx
  3678                              <1> ;	;pop	bx
  3679                              <1> ;	;pop	ax
  3680                              <1> ;	retn
  3681                              <1> 
  3682                              <1> ;//////////////////////////////////////////////////////
  3683                              <1> ;; END OF DISKETTE I/O ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3684                              <1> 
  3685                              <1> ; 17/04/2021 (TRDOS 386 v2.0.4) 
  3686                              <1> 
  3687                              <1> ; 11/04/2021
  3688                              <1> ;int13h: ; 21/02/2015
  3689                              <1> 	;pushfd
  3690                              <1> 	;push 	cs
  3691                              <1> 	;;call 	DISK_IO
  3692                              <1> 	;;retn
  3693                              <1> 
  3694                              <1> ;;;;;; DISK I/O ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 21/02/2015 ;;;
  3695                              <1> ;/////////////////////////////////////////////////////////////////////
  3696                              <1> 
  3697                              <1> ; DISK I/O - Erdogan Tan (Retro UNIX 386 v1 project)
  3698                              <1> ; 18/02/2016
  3699                              <1> ; 17/02/2016
  3700                              <1> ; 23/02/2015
  3701                              <1> ; 21/02/2015 (unix386.s)
  3702                              <1> ; 22/12/2014 - 14/02/2015 (dsectrm2.s)
  3703                              <1> ;
  3704                              <1> ; Original Source Code:
  3705                              <1> ; DISK ----- 09/25/85 FIXED DISK BIOS
  3706                              <1> ; (IBM PC XT Model 286 System BIOS Source Code, 04-21-86)
  3707                              <1> ;
  3708                              <1> ; Modifications: by reference of AWARD BIOS 1999 (D1A0622) 
  3709                              <1> ;		 Source Code - ATORGS.ASM, AHDSK.ASM
  3710                              <1> ;
  3711                              <1> 
  3712                              <1> ;The wait for controller to be not busy is 10 seconds.
  3713                              <1> ;10,000,000 / 30 = 333,333. 333,333 decimal = 051615h
  3714                              <1> ;;WAIT_HDU_CTLR_BUSY_LO	equ 1615h		
  3715                              <1> ;;WAIT_HDU_CTLR_BUSY_HI	equ 05h
  3716                              <1> WAIT_HDU_CTRL_BUSY_LH	equ 51615h	; 21/02/2015		
  3717                              <1> 
  3718                              <1> ;The wait for controller to issue completion interrupt is 10 seconds.
  3719                              <1> ;10,000,000 / 30 = 333,333.  333,333 decimal = 051615h
  3720                              <1> ;;WAIT_HDU_INT_LO	equ 1615h
  3721                              <1> ;;WAIT_HDU_INT_HI	equ 05h
  3722                              <1> WAIT_HDU_INT_LH		equ 51615h	; 21/02/2015
  3723                              <1> 
  3724                              <1> ;The wait for Data request on read and write longs is
  3725                              <1> ;2000 us. (?)
  3726                              <1> ;;WAIT_HDU_DRQ_LO	equ 1000	; 03E8h
  3727                              <1> ;;WAIT_HDU_DRQ_HI	equ 0
  3728                              <1> WAIT_HDU_DRQ_LH		equ 1000	; 21/02/2015
  3729                              <1> 
  3730                              <1> ; Port 61h (PORT_B)
  3731                              <1> SYS1	equ 61h		; PORT_B  (diskette.inc)
  3732                              <1> 
  3733                              <1> ; 23/12/2014
  3734                              <1> %define CMD_BLOCK       ebp-8  ; 21/02/2015
  3735                              <1> 
  3736                              <1> ;--- INT 13H -------------------------------------------------------------------
  3737                              <1> ;									       :
  3738                              <1> ; FIXED DISK I/O INTERFACE						       :
  3739                              <1> ;									       :
  3740                              <1> ;	THIS INTERFACE PROVIDES ACCESS TO 5 1/4" FIXED DISKS THROUGH           :
  3741                              <1> ;	THE IBM FIXED DISK CONTROLLER.					       :
  3742                              <1> ;									       :
  3743                              <1> ;	THE  BIOS  ROUTINES  ARE  MEANT  TO  BE  ACCESSED  THROUGH	       :
  3744                              <1> ;	SOFTWARE  INTERRUPTS  ONLY.    ANY  ADDRESSES  PRESENT	IN	       :
  3745                              <1> ;	THESE  LISTINGS  ARE  INCLUDED	 ONLY	FOR  COMPLETENESS,	       :
  3746                              <1> ;	NOT  FOR  REFERENCE.  APPLICATIONS   WHICH  REFERENCE  ANY	       :
  3747                              <1> ;	ABSOLUTE  ADDRESSES  WITHIN  THE  CODE	SEGMENTS  OF  BIOS	       :
  3748                              <1> ;	VIOLATE  THE  STRUCTURE  AND  DESIGN  OF  BIOS. 		       :
  3749                              <1> ;									       :
  3750                              <1> ;------------------------------------------------------------------------------:
  3751                              <1> ;									       :
  3752                              <1> ; INPUT  (AH)= HEX COMMAND VALUE					       :
  3753                              <1> ;									       :
  3754                              <1> ;	(AH)= 00H  RESET DISK (DL = 80H,81H) / DISKETTE 		       :
  3755                              <1> ;	(AH)= 01H  READ THE STATUS OF THE LAST DISK OPERATION INTO (AL)        :
  3756                              <1> ;		    NOTE: DL < 80H - DISKETTE				       :
  3757                              <1> ;			  DL > 80H - DISK				       :
  3758                              <1> ;	(AH)= 02H  READ THE DESIRED SECTORS INTO MEMORY 		       :
  3759                              <1> ;	(AH)= 03H  WRITE THE DESIRED SECTORS FROM MEMORY		       :
  3760                              <1> ;	(AH)= 04H  VERIFY THE DESIRED SECTORS				       :
  3761                              <1> ;	(AH)= 05H  FORMAT THE DESIRED TRACK				       :
  3762                              <1> ;	(AH)= 06H  UNUSED						       :
  3763                              <1> ;	(AH)= 07H  UNUSED						       :
  3764                              <1> ;	(AH)= 08H  RETURN THE CURRENT DRIVE PARAMETERS			       :
  3765                              <1> ;	(AH)= 09H  INITIALIZE DRIVE PAIR CHARACTERISTICS		       :
  3766                              <1> ;		    INTERRUPT 41 POINTS TO DATA BLOCK FOR DRIVE 0	       :
  3767                              <1> ;		    INTERRUPT 46 POINTS TO DATA BLOCK FOR DRIVE 1	       :
  3768                              <1> ;	(AH)= 0AH  READ LONG						       :
  3769                              <1> ;	(AH)= 0BH  WRITE LONG  (READ & WRITE LONG ENCOMPASS 512 + 4 BYTES ECC) :
  3770                              <1> ;	(AH)= 0CH  SEEK 						       :
  3771                              <1> ;	(AH)= 0DH  ALTERNATE DISK RESET (SEE DL)			       :
  3772                              <1> ;	(AH)= 0EH  UNUSED						       :
  3773                              <1> ;	(AH)= 0FH  UNUSED						       :
  3774                              <1> ;	(AH)= 10H  TEST DRIVE READY					       :
  3775                              <1> ;	(AH)= 11H  RECALIBRATE						       :
  3776                              <1> ;	(AH)= 12H  UNUSED						       :
  3777                              <1> ;	(AH)= 13H  UNUSED						       :
  3778                              <1> ;	(AH)= 14H  CONTROLLER INTERNAL DIAGNOSTIC			       :
  3779                              <1> ;	(AH)= 15H  READ DASD TYPE					       :
  3780                              <1> ;									       :
  3781                              <1> ;-------------------------------------------------------------------------------
  3782                              <1> ;									       :
  3783                              <1> ;	REGISTERS USED FOR FIXED DISK OPERATIONS			       :
  3784                              <1> ;									       :
  3785                              <1> ;		(DL)	-  DRIVE NUMBER     (80H-81H FOR DISK. VALUE CHECKED)  :
  3786                              <1> ;		(DH)	-  HEAD NUMBER	    (0-15 ALLOWED, NOT VALUE CHECKED)  :
  3787                              <1> ;		(CH)	-  CYLINDER NUMBER  (0-1023, NOT VALUE CHECKED)(SEE CL):
  3788                              <1> ;		(CL)	-  SECTOR NUMBER    (1-17, NOT VALUE CHECKED)	       :
  3789                              <1> ;									       :
  3790                              <1> ;			   NOTE: HIGH 2 BITS OF CYLINDER NUMBER ARE PLACED     :
  3791                              <1> ;				 IN THE HIGH 2 BITS OF THE CL REGISTER	       :
  3792                              <1> ;				 (10 BITS TOTAL)			       :
  3793                              <1> ;									       :
  3794                              <1> ;		(AL)	-  NUMBER OF SECTORS (MAXIMUM POSSIBLE RANGE 1-80H,    :
  3795                              <1> ;					      FOR READ/WRITE LONG 1-79H)       :
  3796                              <1> ;									       :
  3797                              <1> ;		(ES:BX) -  ADDRESS OF BUFFER FOR READS AND WRITES,	       :
  3798                              <1> ;			   (NOT REQUIRED FOR VERIFY)			       :
  3799                              <1> ;									       :
  3800                              <1> ;		FORMAT (AH=5) ES:BX POINTS TO A 512 BYTE BUFFER. THE FIRST     :
  3801                              <1> ;			   2*(SECTORS/TRACK) BYTES CONTAIN F,N FOR EACH SECTOR.:
  3802                              <1> ;			   F = 00H FOR A GOOD SECTOR			       :
  3803                              <1> ;			       80H FOR A BAD SECTOR			       :
  3804                              <1> ;			   N = SECTOR NUMBER				       :
  3805                              <1> ;			   FOR AN INTERLEAVE OF 2 AND 17 SECTORS/TRACK	       :
  3806                              <1> ;			   THE TABLE SHOULD BE: 			       :
  3807                              <1> ;									       :
  3808                              <1> ;		   DB	   00H,01H,00H,0AH,00H,02H,00H,0BH,00H,03H,00H,0CH     :
  3809                              <1> ;		   DB	   00H,04H,00H,0DH,00H,05H,00H,0EH,00H,06H,00H,0FH     :
  3810                              <1> ;		   DB	   00H,07H,00H,10H,00H,08H,00H,11H,00H,09H	       :
  3811                              <1> ;									       :
  3812                              <1> ;-------------------------------------------------------------------------------
  3813                              <1> 
  3814                              <1> ;-------------------------------------------------------------------------------
  3815                              <1> ; OUTPUT								       :
  3816                              <1> ;	AH = STATUS OF CURRENT OPERATION				       :
  3817                              <1> ;	     STATUS BITS ARE DEFINED IN THE EQUATES BELOW		       :
  3818                              <1> ;	CY = 0	SUCCESSFUL OPERATION (AH=0 ON RETURN)			       :
  3819                              <1> ;	CY = 1	FAILED OPERATION (AH HAS ERROR REASON)			       :
  3820                              <1> ;									       :
  3821                              <1> ;	NOTE:	ERROR 11H  INDICATES THAT THE DATA READ HAD A RECOVERABLE      :
  3822                              <1> ;		ERROR WHICH WAS CORRECTED BY THE ECC ALGORITHM.  THE DATA      :
  3823                              <1> ;		IS PROBABLY GOOD,   HOWEVER THE BIOS ROUTINE INDICATES AN      :
  3824                              <1> ;		ERROR TO ALLOW THE CONTROLLING PROGRAM A CHANCE TO DECIDE      :
  3825                              <1> ;		FOR ITSELF.  THE  ERROR  MAY  NOT  RECUR  IF  THE DATA IS      :
  3826                              <1> ;		REWRITTEN.						       :
  3827                              <1> ;									       :
  3828                              <1> ;	IF DRIVE PARAMETERS WERE REQUESTED (DL >= 80H), 		       :
  3829                              <1> ;	   INPUT:							       :
  3830                              <1> ;	     (DL) = DRIVE NUMBER					       :	
  3831                              <1> ;	     ; 27/05/2016 - TRDOS 386 (TRDOS v2.0)						       :	 	
  3832                              <1> ;	     EBX = Buffer address for fixed disk parameters table (32 bytes)   :
  3833                              <1> ;	   OUTPUT:							       :
  3834                              <1> ;	     (DL) = NUMBER OF CONSECUTIVE ACKNOWLEDGING DRIVES ATTACHED (1-2)  :
  3835                              <1> ;		    (CONTROLLER CARD ZERO TALLY ONLY)			       :
  3836                              <1> ;	     (DH) = MAXIMUM USEABLE VALUE FOR HEAD NUMBER		       :
  3837                              <1> ;	     (CH) = MAXIMUM USEABLE VALUE FOR CYLINDER NUMBER		       :
  3838                              <1> ;	     (CL) = MAXIMUM USEABLE VALUE FOR SECTOR NUMBER		       :
  3839                              <1> ;		    AND CYLINDER NUMBER HIGH BITS			       :
  3840                              <1> ;									       :
  3841                              <1> ;	IF READ DASD TYPE WAS REQUESTED,				       :
  3842                              <1> ;									       :
  3843                              <1> ;	AH = 0 - NOT PRESENT						       :
  3844                              <1> ;	     1 - DISKETTE - NO CHANGE LINE AVAILABLE			       :
  3845                              <1> ;	     2 - DISKETTE - CHANGE LINE AVAILABLE			       :
  3846                              <1> ;	     3 - FIXED DISK						       :
  3847                              <1> ;									       :
  3848                              <1> ;	CX,DX = NUMBER OF 512 BYTE BLOCKS WHEN AH = 3			       :
  3849                              <1> ;									       :
  3850                              <1> ;	REGISTERS WILL BE PRESERVED EXCEPT WHEN THEY ARE USED TO RETURN        :
  3851                              <1> ;	INFORMATION.							       :
  3852                              <1> ;									       :
  3853                              <1> ;	NOTE: IF AN ERROR IS REPORTED BY THE DISK CODE, THE APPROPRIATE        :
  3854                              <1> ;		ACTION IS TO RESET THE DISK, THEN RETRY THE OPERATION.	       :
  3855                              <1> ;									       :
  3856                              <1> ;-------------------------------------------------------------------------------
  3857                              <1> 
  3858                              <1> SENSE_FAIL	EQU	0FFH		; NOT IMPLEMENTED
  3859                              <1> NO_ERR		EQU	0E0H		; STATUS ERROR/ERROR REGISTER=0
  3860                              <1> WRITE_FAULT	EQU	0CCH		; WRITE FAULT ON SELECTED DRIVE
  3861                              <1> UNDEF_ERR	EQU	0BBH		; UNDEFINED ERROR OCCURRED
  3862                              <1> NOT_RDY 	EQU	0AAH		; DRIVE NOT READY
  3863                              <1> TIME_OUT	EQU	80H		; ATTACHMENT FAILED TO RESPOND
  3864                              <1> BAD_SEEK	EQU	40H		; SEEK OPERATION FAILED
  3865                              <1> BAD_CNTLR	EQU	20H		; CONTROLLER HAS FAILED
  3866                              <1> DATA_CORRECTED	EQU	11H		; ECC CORRECTED DATA ERROR
  3867                              <1> BAD_ECC 	EQU	10H		; BAD ECC ON DISK READ
  3868                              <1> BAD_TRACK	EQU	0BH		; NOT IMPLEMENTED
  3869                              <1> BAD_SECTOR	EQU	0AH		; BAD SECTOR FLAG DETECTED
  3870                              <1> ;DMA_BOUNDARY	EQU	09H		; DATA EXTENDS TOO FAR
  3871                              <1> INIT_FAIL	EQU	07H		; DRIVE PARAMETER ACTIVITY FAILED
  3872                              <1> BAD_RESET	EQU	05H		; RESET FAILED
  3873                              <1> ;RECORD_NOT_FND	EQU	04H		; REQUESTED SECTOR NOT FOUND
  3874                              <1> ;BAD_ADDR_MARK	EQU	02H		; ADDRESS MARK NOT FOUND
  3875                              <1> ;BAD_CMD 	EQU	01H		; BAD COMMAND PASSED TO DISK I/O
  3876                              <1> 
  3877                              <1> ;--------------------------------------------------------
  3878                              <1> ;							:
  3879                              <1> ; FIXED DISK PARAMETER TABLE				:
  3880                              <1> ;  -  THE TABLE IS COMPOSED OF A BLOCK DEFINED AS:	:
  3881                              <1> ;							:
  3882                              <1> ;  +0	(1 WORD) - MAXIMUM NUMBER OF CYLINDERS		:
  3883                              <1> ;  +2	(1 BYTE) - MAXIMUM NUMBER OF HEADS		:
  3884                              <1> ;  +3	(1 WORD) - NOT USED/SEE PC-XT			:
  3885                              <1> ;  +5	(1 WORD) - STARTING WRITE PRECOMPENSATION CYL	:
  3886                              <1> ;  +7	(1 BYTE) - MAXIMUM ECC DATA BURST LENGTH	:
  3887                              <1> ;  +8	(1 BYTE) - CONTROL BYTE 			:
  3888                              <1> ;		   BIT	  7 DISABLE RETRIES -OR-	:
  3889                              <1> ;		   BIT	  6 DISABLE RETRIES		:
  3890                              <1> ;		   BIT	  3 MORE THAN 8 HEADS		:
  3891                              <1> ;  +9	(3 BYTES)- NOT USED/SEE PC-XT			:
  3892                              <1> ; +12	(1 WORD) - LANDING ZONE 			:
  3893                              <1> ; +14	(1 BYTE) - NUMBER OF SECTORS/TRACK		:
  3894                              <1> ; +15	(1 BYTE) - RESERVED FOR FUTURE USE		:
  3895                              <1> ;							:
  3896                              <1> ;	 - TO DYNAMICALLY DEFINE A SET OF PARAMETERS	:
  3897                              <1> ;	   BUILD A TABLE FOR UP TO 15 TYPES AND PLACE	:
  3898                              <1> ;	   THE CORRESPONDING VECTOR INTO INTERRUPT 41	:
  3899                              <1> ;	   FOR DRIVE 0 AND INTERRUPT 46 FOR DRIVE 1.	:
  3900                              <1> ;							:
  3901                              <1> ;--------------------------------------------------------
  3902                              <1> 
  3903                              <1> ;--------------------------------------------------------
  3904                              <1> ;							:
  3905                              <1> ; HARDWARE SPECIFIC VALUES				:
  3906                              <1> ;							:
  3907                              <1> ;  -  CONTROLLER I/O PORT				:
  3908                              <1> ;							:
  3909                              <1> ;     > WHEN READ FROM: 				:
  3910                              <1> ;	HF_PORT+0 - READ DATA (FROM CONTROLLER TO CPU)	:
  3911                              <1> ;	HF_PORT+1 - GET ERROR REGISTER			:
  3912                              <1> ;	HF_PORT+2 - GET SECTOR COUNT			:
  3913                              <1> ;	HF_PORT+3 - GET SECTOR NUMBER			:
  3914                              <1> ;	HF_PORT+4 - GET CYLINDER LOW			:
  3915                              <1> ;	HF_PORT+5 - GET CYLINDER HIGH (2 BITS)		:
  3916                              <1> ;	HF_PORT+6 - GET SIZE/DRIVE/HEAD 		:
  3917                              <1> ;	HF_PORT+7 - GET STATUS REGISTER 		:
  3918                              <1> ;							:
  3919                              <1> ;     > WHEN WRITTEN TO:				:
  3920                              <1> ;	HF_PORT+0 - WRITE DATA (FROM CPU TO CONTROLLER) :
  3921                              <1> ;	HF_PORT+1 - SET PRECOMPENSATION CYLINDER	:
  3922                              <1> ;	HF_PORT+2 - SET SECTOR COUNT			:
  3923                              <1> ;	HF_PORT+3 - SET SECTOR NUMBER			:
  3924                              <1> ;	HF_PORT+4 - SET CYLINDER LOW			:
  3925                              <1> ;	HF_PORT+5 - SET CYLINDER HIGH (2 BITS)		:
  3926                              <1> ;	HF_PORT+6 - SET SIZE/DRIVE/HEAD 		:
  3927                              <1> ;	HF_PORT+7 - SET COMMAND REGISTER		:
  3928                              <1> ;							:
  3929                              <1> ;--------------------------------------------------------
  3930                              <1> 
  3931                              <1> ;HF_PORT 	EQU	01F0H	; DISK PORT
  3932                              <1> ;HF1_PORT	equ	0170h	
  3933                              <1> ;HF_REG_PORT	EQU	03F6H
  3934                              <1> ;HF1_REG_PORT	equ	0376h
  3935                              <1> 
  3936                              <1> HDC1_BASEPORT	equ	1F0h
  3937                              <1> HDC2_BASEPORT	equ	170h		
  3938                              <1> 
  3939 00004EA5 90                  <1> align 2
  3940                              <1> 
  3941                              <1> ;-----		STATUS REGISTER
  3942                              <1> 
  3943                              <1> ST_ERROR	EQU	00000001B	;
  3944                              <1> ST_INDEX	EQU	00000010B	;
  3945                              <1> ST_CORRCTD	EQU	00000100B	; ECC CORRECTION SUCCESSFUL
  3946                              <1> ST_DRQ		EQU	00001000B	;
  3947                              <1> ST_SEEK_COMPL	EQU	00010000B	; SEEK COMPLETE
  3948                              <1> ST_WRT_FLT	EQU	00100000B	; WRITE FAULT
  3949                              <1> ST_READY	EQU	01000000B	;
  3950                              <1> ST_BUSY 	EQU	10000000B	;
  3951                              <1> 
  3952                              <1> ;-----		ERROR REGISTER
  3953                              <1> 
  3954                              <1> ERR_DAM 	EQU	00000001B	; DATA ADDRESS MARK NOT FOUND
  3955                              <1> ERR_TRK_0	EQU	00000010B	; TRACK 0 NOT FOUND ON RECAL
  3956                              <1> ERR_ABORT	EQU	00000100B	; ABORTED COMMAND
  3957                              <1> ;		EQU	00001000B	; NOT USED
  3958                              <1> ERR_ID		EQU	00010000B	; ID NOT FOUND
  3959                              <1> ;		EQU	00100000B	; NOT USED
  3960                              <1> ERR_DATA_ECC	EQU	01000000B
  3961                              <1> ERR_BAD_BLOCK	EQU	10000000B
  3962                              <1> 
  3963                              <1> 
  3964                              <1> RECAL_CMD	EQU	00010000B	; DRIVE RECAL	(10H)
  3965                              <1> READ_CMD	EQU	00100000B	;	READ	(20H)
  3966                              <1> WRITE_CMD	EQU	00110000B	;	WRITE	(30H)
  3967                              <1> VERIFY_CMD	EQU	01000000B	;	VERIFY	(40H)
  3968                              <1> FMTTRK_CMD	EQU	01010000B	; FORMAT TRACK	(50H)
  3969                              <1> INIT_CMD	EQU	01100000B	;   INITIALIZE	(60H)
  3970                              <1> SEEK_CMD	EQU	01110000B	;	SEEK	(70H)
  3971                              <1> DIAG_CMD	EQU	10010000B	; DIAGNOSTIC	(90H)
  3972                              <1> SET_PARM_CMD	EQU	10010001B	; DRIVE PARMS	(91H)
  3973                              <1> NO_RETRIES	EQU	00000001B	; CHD MODIFIER	(01H)
  3974                              <1> ECC_MODE	EQU	00000010B	; CMD MODIFIER	(02H)
  3975                              <1> BUFFER_MODE	EQU	00001000B	; CMD MODIFIER	(08H)
  3976                              <1> 
  3977                              <1> ;MAX_FILE	EQU	2
  3978                              <1> ;S_MAX_FILE	EQU	2
  3979                              <1> MAX_FILE	equ	4		; 22/12/2014
  3980                              <1> S_MAX_FILE	equ	4		; 22/12/2014
  3981                              <1> 
  3982                              <1> DELAY_1 	EQU	25H		; DELAY FOR OPERATION COMPLETE
  3983                              <1> DELAY_2 	EQU	0600H		; DELAY FOR READY
  3984                              <1> DELAY_3 	EQU	0100H		; DELAY FOR DATA REQUEST
  3985                              <1> 
  3986                              <1> HF_FAIL 	EQU	08H		; CMOS FLAG IN BYTE 0EH
  3987                              <1> 
  3988                              <1> ;-----		COMMAND BLOCK REFERENCE
  3989                              <1> 
  3990                              <1> ;CMD_BLOCK      EQU     BP-8            ; @CMD_BLOCK REFERENCES BLOCK HEAD IN SS
  3991                              <1> 					;  (BP) POINTS TO COMMAND BLOCK TAIL
  3992                              <1> 					;	AS DEFINED BY THE "ENTER" PARMS
  3993                              <1> ; 19/12/2014
  3994                              <1> ORG_VECTOR	equ	4*13h		; INT 13h vector
  3995                              <1> DISK_VECTOR	equ	4*40h		; INT 40h vector (for floppy disks)
  3996                              <1> ;HDISK_INT	equ	4*76h		; Primary HDC - Hardware interrupt (IRQ14)
  3997                              <1> ;HDISK_INT1	equ	4*76h		; Primary HDC - Hardware interrupt (IRQ14)
  3998                              <1> ;HDISK_INT2	equ	4*77h		; Secondary HDC - Hardware interrupt (IRQ15)
  3999                              <1> ;HF_TBL_VEC	equ	4*41h		; Pointer to 1st fixed disk parameter table
  4000                              <1> ;HF1_TBL_VEC	equ	4*46h		; Pointer to 2nd fixed disk parameter table
  4001                              <1> 
  4002                              <1> align 2
  4003                              <1> 
  4004                              <1> ;----------------------------------------------------------------
  4005                              <1> ; FIXED DISK I/O SETUP						:
  4006                              <1> ;								:
  4007                              <1> ;  -  ESTABLISH TRANSFER VECTORS FOR THE FIXED DISK		:
  4008                              <1> ;  -  PERFORM POWER ON DIAGNOSTICS				:
  4009                              <1> ;     SHOULD AN ERROR OCCUR A "1701" MESSAGE IS DISPLAYED       :
  4010                              <1> ;								:
  4011                              <1> ;----------------------------------------------------------------
  4012                              <1> 
  4013                              <1> ; 09/08/2022
  4014                              <1> ; 06/08/2022 - TRDOS 386 Kernel v2.0.5
  4015                              <1> ; 29/05/2016 - TRDOS 386 (TRDOS v2.0)
  4016                              <1> 
  4017                              <1> DISK_SETUP:
  4018                              <1> 	;CLI
  4019                              <1> 	;;mov	ax, ABS0 		; GET ABSOLUTE SEGMENT
  4020                              <1> 	;xor	ax, ax
  4021                              <1> 	;mov	ds, ax			; SET SEGMENT REGISTER
  4022                              <1> 	;mov	ax, [ORG_VECTOR] 	; GET DISKETTE VECTOR
  4023                              <1> 	;mov	[DISK_VECTOR], ax	;  INTO INT 40H
  4024                              <1> 	;mov	ax, [ORG_VECTOR+2]
  4025                              <1> 	;mov	[DISK_VECTOR+2], ax
  4026                              <1> 	;mov	word [ORG_VECTOR], DISK_IO ; FIXED DISK HANDLER
  4027                              <1> 	;mov	[ORG_VECTOR+2], cs
  4028                              <1> 	; 1st controller (primary master, slave)   - IRQ 14
  4029                              <1> 	;;mov	word [HDISK_INT], HD_INT   ; FIXED DISK INTERRUPT
  4030                              <1> 	;mov	word [HDISK_INT1], HD_INT  ;
  4031                              <1> 	;;mov	[HDISK_INT+2], cs
  4032                              <1> 	;mov	[HDISK_INT1+2], cs
  4033                              <1> 	; 2nd controller (secondary master, slave) - IRQ 15
  4034                              <1> 	;mov	word [HDISK_INT2], HD1_INT ;
  4035                              <1> 	;mov	[HDISK_INT2+2], cs
  4036                              <1> 	;
  4037                              <1> 	;;mov	word [HF_TBL_VEC], HD0_DPT	; PARM TABLE DRIVE 80
  4038                              <1> 	;;mov	word [HF_TBL_VEC+2], DPT_SEGM
  4039                              <1> 	;;mov	word [HF1_TBL_VEC], HD1_DPT	; PARM TABLE DRIVE 81
  4040                              <1> 	;;mov	word [HF1_TBL_VEC+2], DPT_SEGM
  4041                              <1> 	;push	cs
  4042                              <1> 	;pop	ds
  4043                              <1> 	;mov	word [HDPM_TBL_VEC], HD0_DPT	; PARM TABLE DRIVE 80h
  4044                              <1> 	;mov	word [HDPM_TBL_VEC+2], DPT_SEGM
  4045 00004EA6 C705[5C7D0100]0000- <1> 	mov 	dword [HDPM_TBL_VEC], (DPT_SEGM*16)+HD0_DPT
  4045 00004EAE 0900                <1>
  4046                              <1> 	;mov	word [HDPS_TBL_VEC], HD1_DPT	; PARM TABLE DRIVE 81h
  4047                              <1> 	;mov	word [HDPS_TBL_VEC+2], DPT_SEGM
  4048 00004EB0 C705[607D0100]2000- <1> 	mov 	dword [HDPS_TBL_VEC], (DPT_SEGM*16)+HD1_DPT
  4048 00004EB8 0900                <1>
  4049                              <1> 	;mov	word [HDSM_TBL_VEC], HD2_DPT	; PARM TABLE DRIVE 82h
  4050                              <1> 	;mov	word [HDSM_TBL_VEC+2], DPT_SEGM
  4051 00004EBA C705[647D0100]4000- <1> 	mov 	dword [HDSM_TBL_VEC], (DPT_SEGM*16)+HD2_DPT
  4051 00004EC2 0900                <1>
  4052                              <1> 	;mov	word [HDSS_TBL_VEC], HD3_DPT	; PARM TABLE DRIVE 83h
  4053                              <1> 	;mov	word [HDSS_TBL_VEC+2], DPT_SEGM
  4054 00004EC4 C705[687D0100]6000- <1> 	mov 	dword [HDSS_TBL_VEC], (DPT_SEGM*16)+HD3_DPT
  4054 00004ECC 0900                <1>
  4055                              <1> 	;
  4056                              <1> 	;;in	al, INTB01		; TURN ON SECOND INTERRUPT CHIP
  4057                              <1> 	;;;and	al, 0BFh
  4058                              <1> 	;;and	al, 3Fh			; enable IRQ 14 and IRQ 15
  4059                              <1> 	;;;jmp	$+2
  4060                              <1> 	;;IODELAY
  4061                              <1> 	;;out	INTB01, al
  4062                              <1> 	;;IODELAY
  4063                              <1> 	;;in	al, INTA01		; LET INTERRUPTS PASS THRU TO
  4064                              <1> 	;;and	al, 0FBh 		;  SECOND CHIP
  4065                              <1> 	;;;jmp	$+2
  4066                              <1> 	;;IODELAY
  4067                              <1> 	;;out	INTA01, al
  4068                              <1> 	;
  4069                              <1> 	;sti
  4070                              <1> 	;;push	ds			; MOVE ABS0 POINTER TO
  4071                              <1> 	;;pop	es			; EXTRA SEGMENT POINTER
  4072                              <1> 	;;;call	DDS			; ESTABLISH DATA SEGMENT
  4073                              <1> 	;;mov	byte [DISK_STATUS1], 0 	; RESET THE STATUS INDICATOR
  4074                              <1> 	;;mov	byte [HF_NUM], 0	; ZERO NUMBER OF FIXED DISKS
  4075                              <1> 	;;mov	byte [CONTROL_BYTE], 0
  4076                              <1> 	;;mov	byte [PORT_OFF], 0	; ZERO CARD OFFSET
  4077                              <1> 	; 20/12/2014 - private code by Erdogan Tan
  4078                              <1> 		      ; (out of original PC-AT, PC-XT BIOS code)
  4079                              <1> 	;mov	si, hd0_type
  4080 00004ECE BE[3E660000]        <1> 	mov	esi, hd0_type
  4081                              <1> 	;;mov	cx, 4
  4082                              <1> 	;mov	ecx, 4
  4083                              <1> 	; 06/08/2022
  4084 00004ED3 29C9                <1> 	sub	ecx, ecx
  4085 00004ED5 B104                <1> 	mov	cl, 4
  4086                              <1> hde_l:
  4087 00004ED7 AC                  <1> 	lodsb
  4088 00004ED8 3C80                <1> 	cmp	al, 80h			; 8?h = existing
  4089 00004EDA 7206                <1> 	jb	short _L4
  4090 00004EDC FE05[587D0100]      <1> 	inc	byte [HF_NUM]		; + 1 hard (fixed) disk drives
  4091                              <1> _L4: ; 26/02/2015
  4092 00004EE2 E2F3                <1> 	loop	hde_l	
  4093                              <1> ;_L4:					; 0 <= [HF_NUM] =< 4
  4094                              <1> ;L4:
  4095                              <1> 	;; 31/12/2014 - cancel controller diagnostics here
  4096                              <1> 	;;;mov 	cx, 3  ; 26/12/2014 (Award BIOS 1999)
  4097                              <1> 	;;mov 	cl, 3
  4098                              <1> 	;;
  4099                              <1> 	;;mov	DL, 80H			; CHECK THE CONTROLLER
  4100                              <1> ;;hdc_dl:
  4101                              <1> 	;;mov	AH, 14H			; USE CONTROLLER DIAGNOSTIC COMMAND
  4102                              <1> 	;;INT	13H			; CALL BIOS WITH DIAGNOSTIC COMMAND
  4103                              <1> 	;;;jc	short CTL_ERRX		; DISPLAY ERROR MESSAGE IF BAD RETURN
  4104                              <1> 	;;;jc	short POD_DONE ;22/12/2014
  4105                              <1> 	;;jnc	short hdc_reset0
  4106                              <1> 	;;loop	hdc_dl
  4107                              <1> 	;;; 27/12/2014
  4108                              <1> 	;;stc
  4109                              <1> 	;;retn
  4110                              <1> 	;
  4111                              <1> ;;hdc_reset0:
  4112                              <1> 	; 18/01/2015
  4113 00004EE4 8A0D[587D0100]      <1> 	mov	cl, [HF_NUM]
  4114 00004EEA 20C9                <1> 	and	cl, cl
  4115 00004EEC 740D                <1> 	jz	short POD_DONE
  4116                              <1> 	;
  4117 00004EEE B27F                <1> 	mov	dl, 7Fh
  4118                              <1> hdc_reset1:
  4119 00004EF0 FEC2                <1> 	inc	dl
  4120                              <1> 	;; 31/12/2015
  4121                              <1> 	;;push	dx
  4122                              <1> 	;;push	cx
  4123                              <1> 	;;push	ds
  4124                              <1> 	;;sub	ax, ax
  4125                              <1> 	;;mov	ds, ax
  4126                              <1> 	;;mov	ax, [TIMER_LOW]		; GET START TIMER COUNTS
  4127                              <1> 	;;pop	ds
  4128                              <1> 	;;mov	bx, ax
  4129                              <1> 	;;add	ax, 6*182		; 60 SECONDS* 18.2
  4130                              <1> 	;;mov	cx, ax
  4131                              <1> 	;;mov	word [wait_count], 0	; 22/12/2014 (reset wait counter)
  4132                              <1> 	;;
  4133                              <1> 	;; 31/12/2014 - cancel HD_RESET_1
  4134                              <1> 	;;call	HD_RESET_1		; SET UP DRIVE 0, (1,2,3)
  4135                              <1> 	;;pop	cx
  4136                              <1> 	;;pop	dx
  4137                              <1> 	;;
  4138                              <1> 	; 18/01/2015
  4139 00004EF2 B40D                <1> 	mov	ah, 0Dh ; ALTERNATE RESET
  4140                              <1> 	;int	13h
  4141 00004EF4 E8CC000000          <1> 	call	int13h
  4142 00004EF9 E2F5                <1> 	loop	hdc_reset1
  4143                              <1> 	;clc 	; 29/05/2016
  4144                              <1> POD_DONE:
  4145 00004EFB C3                  <1> 	retn
  4146                              <1> 
  4147                              <1> ;;-----	POD_ERROR
  4148                              <1> 
  4149                              <1> ;;CTL_ERRX:
  4150                              <1> ;	;mov	SI,OFFSET F1782 	; CONTROLLER ERROR
  4151                              <1> ;	;call	SET_FAIL		; DO NOT IPL FROM DISK
  4152                              <1> ;	;call	E_MSG			; DISPLAY ERROR AND SET (BP) ERROR FLAG
  4153                              <1> ;	;jmp	short POD_DONE
  4154                              <1> 
  4155                              <1> ;;HD_RESET_1:
  4156                              <1> ;;	;push	BX			; SAVE TIMER LIMITS
  4157                              <1> ;;	;push	CX
  4158                              <1> ;;RES_1: mov	AH,09H			; SET DRIVE PARAMETERS
  4159                              <1> ;;	INT	13H
  4160                              <1> ;;	jc	short RES_2
  4161                              <1> ;;	mov	AH,11h			; RECALIBRATE DRIVE
  4162                              <1> ;;	INT	13H
  4163                              <1> ;;	jnc	short RES_CK		; DRIVE OK
  4164                              <1> ;;RES_2: ;call	POD_TCHK		; CHECK TIME OUT
  4165                              <1> ;;	cmp	word [wait_count], 6*182 ; waiting time (in timer ticks)
  4166                              <1> ;;					; (30 seconds)		
  4167                              <1> ;;	;cmc
  4168                              <1> ;;	;jnc	short RES_1
  4169                              <1> ;;	jb	short RES_1
  4170                              <1> ;;;RES_FL: ;mov	SI,OFFSET F1781 	; INDICATE DISK 1 FAILURE;
  4171                              <1> ;;	;test	DL,1
  4172                              <1> ;;	;jnz	short RES_E1
  4173                              <1> ;;	;mov	SI,OFFSET F1780 	; INDICATE DISK 0 FAILURE
  4174                              <1> ;;	;call	SET_FAIL		; DO NOT TRY TO IPL DISK 0
  4175                              <1> ;;	;jmp	SHORT RES_E1
  4176                              <1> ;;RES_ER: ; 22/12/2014
  4177                              <1> ;;RES_OK:
  4178                              <1> ;;	;pop	CX			; RESTORE TIMER LIMITS
  4179                              <1> ;;	;pop	BX
  4180                              <1> ;;	retn
  4181                              <1> ;;
  4182                              <1> ;;RES_RS: mov	AH,00H			; RESET THE DRIVE
  4183                              <1> ;;	INT	13H
  4184                              <1> ;;RES_CK: mov	AH,08H			; GET MAX CYLINDER,HEAD,SECTOR
  4185                              <1> ;;	mov	BL,DL			; SAVE DRIVE CODE
  4186                              <1> ;;	INT	13H
  4187                              <1> ;;	jc	short RES_ER
  4188                              <1> ;;	mov	[NEC_STATUS],CX 	; SAVE MAX CYLINDER, SECTOR
  4189                              <1> ;;	mov	DL,BL			; RESTORE DRIVE CODE
  4190                              <1> ;;RES_3: mov	AX,0401H		; VERIFY THE LAST SECTOR
  4191                              <1> ;;	INT	13H
  4192                              <1> ;;	jnc	short RES_OK		; VERIFY OK
  4193                              <1> ;;	cmp	AH,BAD_SECTOR		; OK ALSO IF JUST ID READ
  4194                              <1> ;;	JE	short RES_OK
  4195                              <1> ;;	cmp	AH,DATA_CORRECTED
  4196                              <1> ;;	JE	short RES_OK
  4197                              <1> ;;	cmp	AH,BAD_ECC
  4198                              <1> ;;	JE	short RES_OK
  4199                              <1> ;;	;call	POD_TCHK		; CHECK FOR TIME OUT
  4200                              <1> ;;	cmp	word [wait_count], 6*182 ; waiting time (in timer ticks)
  4201                              <1> ;;					; (60 seconds)		
  4202                              <1> ;;	cmc
  4203                              <1> ;;	jc	short RES_ER		; FAILED
  4204                              <1> ;;	mov	CX,[NEC_STATUS] 	; GET SECTOR ADDRESS, AND CYLINDER
  4205                              <1> ;;	mov	AL,CL			; SEPARATE OUT SECTOR NUMBER
  4206                              <1> ;;	and	AL,3FH
  4207                              <1> ;;	dec	AL			; TRY PREVIOUS ONE
  4208                              <1> ;;	jz	short RES_RS		; WE'VE TRIED ALL SECTORS ON TRACK
  4209                              <1> ;;	and	CL,0C0H 		; KEEP CYLINDER BITS
  4210                              <1> ;;	OR	CL,AL			; MERGE SECTOR WITH CYLINDER BITS
  4211                              <1> ;;	mov	[NEC_STATUS],CX 	; SAVE CYLINDER, NEW SECTOR NUMBER
  4212                              <1> ;;	jmp	short RES_3		; TRY AGAIN
  4213                              <1> ;;;RES_ER: mov	SI,OFFSET F1791 	; INDICATE DISK 1 ERROR
  4214                              <1> ;;	;test	DL,1
  4215                              <1> ;;	;jnz	short RES_E1
  4216                              <1> ;;	;mov	SI,OFFSET F1790 	; INDICATE DISK 0 ERROR
  4217                              <1> ;;;RES_E1:
  4218                              <1> ;;	;call	E_MSG			; DISPLAY ERROR AND SET (BP) ERROR FLAG
  4219                              <1> ;;;RES_OK:
  4220                              <1> ;;	;pop	CX			; RESTORE TIMER LIMITS
  4221                              <1> ;;	;pop	BX
  4222                              <1> ;;	;retn
  4223                              <1> ;
  4224                              <1> ;;SET_FAIL:
  4225                              <1> ;	;mov	AX,X*(CMOS_DIAG+NMI)	; GET CMOS ERROR BYTE
  4226                              <1> ;	;call	CMOS_READ
  4227                              <1> ;	;OR	AL,HF_FAIL		; SET DO NOT IPL FROM DISK FLAG
  4228                              <1> ;	;xchg	AH,AL			; SAVE IT
  4229                              <1> ;	;call	CMOS_WRITE		; PUT IT OUT
  4230                              <1> ;	;retn
  4231                              <1> ;
  4232                              <1> ;;POD_TCHK:				; CHECK FOR 30 SECOND TIME OUT
  4233                              <1> ;	;pop	AX			; SAVE RETURN
  4234                              <1> ;	;pop	CX			; GET TIME OUT LIMITS
  4235                              <1> ;	;pop	BX
  4236                              <1> ;	;push	BX			; AND SAVE THEM AGAIN
  4237                              <1> ;	;push	CX
  4238                              <1> ;	;push	AX
  4239                              <1> ;	;push	ds
  4240                              <1> ;	;xor	ax, ax
  4241                              <1> ;	;mov	ds, ax			; RESTORE RETURN
  4242                              <1> ;	;mov	AX, [TIMER_LOW]		; AX = CURRENT TIME
  4243                              <1> ;	;				; BX = START TIME
  4244                              <1> ;	;				; CX = END TIME
  4245                              <1> ;	;pop	ds
  4246                              <1> ;	;cmp	BX,CX
  4247                              <1> ;	;JB	short TCHK1		; START < END
  4248                              <1> ;	;cmp	BX,AX
  4249                              <1> ;	;JB	short TCHKG		; END < START < CURRENT
  4250                              <1> ;	;jmp	SHORT TCHK2		; END, CURRENT < START
  4251                              <1> ;;TCHK1: cmp	AX,BX
  4252                              <1> ;;	JB	short TCHKNG		; CURRENT < START < END
  4253                              <1> ;;TCHK2: cmp	AX,CX
  4254                              <1> ;;	JB	short TCHKG		; START < CURRENT < END
  4255                              <1> ;;					; OR CURRENT < END < START
  4256                              <1> ;;TCHKNG: STC				; CARRY SET INDICATES TIME OUT
  4257                              <1> ;;	retn
  4258                              <1> ;;TCHKG: CLC				; INDICATE STILL TIME
  4259                              <1> ;;	retn
  4260                              <1> ;;
  4261                              <1> ;;int_13h:
  4262                              <1> 
  4263                              <1> ;----------------------------------------
  4264                              <1> ;	FIXED DISK BIOS ENTRY POINT	:
  4265                              <1> ;----------------------------------------
  4266                              <1> 
  4267                              <1> ; 17/07/2022
  4268                              <1> ; 16/07/2022
  4269                              <1> ; 13/07/2022 - TRDOS 386 v2.0.5
  4270                              <1> ; 15/01/2017
  4271                              <1> ; 14/01/2017
  4272                              <1> ; 07/01/2017
  4273                              <1> ; 02/01/2017
  4274                              <1> ; 01/06/2016
  4275                              <1> ; 16/05/2016, 27/05/2016, 28/05/2016, 29/05/2016
  4276                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
  4277                              <1> int33h: ; DISK I/O
  4278                              <1> 	; 29/05/2016
  4279 00004EFC 80642408FE          <1> 	and	byte [esp+8], 11111110b  ; clear carry bit of eflags register
  4280                              <1> 
  4281                              <1> 	; 13/07/2022
  4282 00004F01 06                  <1> 	push	es
  4283                              <1> 	; 16/05/2016
  4284 00004F02 1E                  <1> 	push	ds
  4285 00004F03 53                  <1> 	push	ebx ; user's buffer address (virtual)
  4286                              <1> 	; 13/07/2022
  4287 00004F04 51                  <1> 	push	ecx
  4288 00004F05 52                  <1> 	push	edx
  4289 00004F06 56                  <1> 	push	esi
  4290 00004F07 57                  <1> 	push	edi
  4291                              <1> 
  4292                              <1> 	;mov	bx, KDATA ; System (Kernel's) data segment
  4293                              <1> 	;mov	ds, bx
  4294                              <1> 	; 13/07/2022
  4295 00004F08 66BF1000            <1> 	mov	di, KDATA
  4296 00004F0C 8EDF                <1> 	mov	ds, di
  4297 00004F0E 8EC7                <1> 	mov	es, di
  4298                              <1> 
  4299                              <1> 	;;15/01/2017
  4300                              <1> 	; 14/01/2017
  4301                              <1> 	; 02/01/2017
  4302                              <1> 	;;mov	byte [intflg], 33h  ; disk io interrupt 
  4303                              <1> 	;pop	ebx
  4304                              <1> 
  4305                              <1> 	; 13/07/2022
  4306                              <1> 	;pop	dword [user_buffer] ; 01/06/2016
  4307 00004F10 891D[48890100]      <1> 	mov	[user_buffer], ebx		
  4308                              <1> 
  4309 00004F16 C605[86820100]00    <1> 	mov	byte [scount], 0 ; sector count for transfer
  4310 00004F1D 80FC03              <1> 	cmp	ah, 03h ; chs write
  4311 00004F20 773C                <1> 	ja	short int33h_2
  4312 00004F22 7407                <1> 	je	short int33h_0
  4313 00004F24 80FC02              <1> 	cmp	ah, 02h ; chs read
  4314 00004F27 7267                <1> 	jb	short int33h_5
  4315 00004F29 EB5A                <1> 	jmp	short int33h_4
  4316                              <1> int33h_0:
  4317                              <1> 	;; 17/07/2022 - 64K r/w buffer limit check ?
  4318                              <1> 	;cmp	al, 80h ; 128	
  4319                              <1> 	;ja	short int33h_8 ; error
  4320                              <1> 	;; 17/07/2022 - zero r/w count check ?
  4321                              <1> 	;or	al, al
  4322                              <1> 	;jz	short int33h_8 ; error
  4323                              <1> 	
  4324                              <1> 	; 17/07/2022 (buffer limit and zero count check)
  4325 00004F2B FEC8                <1> 	dec	al
  4326 00004F2D 781A                <1> 	js	short int33h_8 ; error
  4327 00004F2F FEC0                <1> 	inc	al	
  4328                              <1> 
  4329                              <1> 	; transfer user's buffer content to sector buffer
  4330 00004F31 51                  <1> 	push	ecx
  4331 00004F32 0FB6C8              <1> 	movzx	ecx, al
  4332                              <1> int33h_1:
  4333                              <1> 	; 13/07/2022
  4334                              <1> 	;push	esi
  4335                              <1> 	;mov	esi, [user_buffer]
  4336 00004F35 89DE                <1> 	mov	esi, ebx
  4337                              <1> 	; esi = user's buffer address (virtual, ebx)
  4338                              <1> 	;push	edi
  4339                              <1> 	;push	es
  4340 00004F37 50                  <1> 	push	eax
  4341                              <1> 	;mov	ax, KDATA
  4342                              <1> 	;mov	es, ax
  4343 00004F38 BF00000700          <1> 	mov	edi, Cluster_Buffer
  4344 00004F3D C1E109              <1> 	shl	ecx, 9 ; * 512
  4345 00004F40 E895C00000          <1> 	call	transfer_from_user_buffer
  4346                              <1> 		; (ecx and eax will be modified)
  4347 00004F45 58                  <1> 	pop	eax
  4348                              <1> 	; 13/07/2022
  4349                              <1> 	;pop	es
  4350                              <1> 	;pop	edi
  4351                              <1> 	;pop	esi
  4352 00004F46 59                  <1> 	pop	ecx
  4353 00004F47 7347                <1> 	jnc	short int33h_5
  4354                              <1> 
  4355                              <1> 	;mov	ebx, [user_buffer] ; 01/06/2016
  4356                              <1> 	;pop	ds
  4357                              <1> 
  4358                              <1> int33h_8:
  4359                              <1> 	; 13/07/2022
  4360 00004F49 B8FF000000          <1> 	mov	eax, 0FFh ; Unknown error !?
  4361                              <1> int33h_9:
  4362 00004F4E 5F                  <1> 	pop	edi
  4363 00004F4F 5E                  <1> 	pop	esi
  4364 00004F50 5A                  <1> 	pop	edx
  4365 00004F51 59                  <1> 	pop	ecx
  4366 00004F52 5B                  <1> 	pop	ebx
  4367 00004F53 1F                  <1> 	pop	ds
  4368 00004F54 07                  <1> 	pop	es
  4369                              <1> 
  4370                              <1> 	; 13/07/2022
  4371 00004F55 7305                <1> 	jnc	short int33h_7
  4372                              <1> 
  4373                              <1> 	;;15/01/2017
  4374                              <1> 	; 02/01/2017
  4375                              <1> 	;cli
  4376                              <1> 	;;mov	byte [ss:intflg], 0 ; 07/01/2017
  4377                              <1> 	;
  4378                              <1> 	; (*) 29/05/2016
  4379                              <1> 	; (*) retf 4 ; skip eflags on stack
  4380                              <1> 
  4381                              <1> 	; 29/05/2016 -set carry flag on stack-
  4382                              <1> 	; [esp] = EIP
  4383                              <1> 	; [esp+4] = CS
  4384                              <1> 	; [esp+8] = E-FLAGS
  4385 00004F57 804C240801          <1> 	or	byte [esp+8], 1  ; set carry bit of eflags register
  4386                              <1> 	; [esp+12] = ESP (user)
  4387                              <1> 	; [esp+16] = SS (User)
  4388                              <1> 	;
  4389                              <1> 	; 13/07/2022
  4390                              <1> int33h_7:	
  4391 00004F5C FA                  <1> 	cli
  4392                              <1> 	;;15/01/2017
  4393                              <1> 	;;mov	byte [ss:intflg], 0 ; 07/01/2017
  4394                              <1> 	; cf = 0  ; use eflags which is in stack
  4395 00004F5D CF                  <1> 	iretd	
  4396                              <1> 
  4397                              <1> 	; (*) 29/05/2016 - 'retf 4' intruction causes to stack fault
  4398                              <1> 	; (OUTER-PRIVILEGE-LEVEL)
  4399                              <1> 	; INTEL 80386 PROGRAMMER'S REFERENCE MANUAL 1986
  4400                              <1> 	; // RETF instruction:
  4401                              <1> 	;
  4402                              <1> 	; IF OperandMode=32 THEN
  4403                              <1>  	;    Load CS:EIP from stack;
  4404                              <1>  	;    Set CS RPL to CPL;
  4405                              <1>  	;    Increment ESP by 8 plus the immediate offset if it exists;
  4406                              <1>  	;    Load SS:ESP from stack;
  4407                              <1>  	; ELSE (* OperandMode=16 *)
  4408                              <1>  	;    Load CS:IP from stack;
  4409                              <1>  	;    Set CS RPL to CPL;
  4410                              <1>  	;    Increment ESP by 4 plus the immediate offset if it exists;
  4411                              <1> 	;    Load SS:ESP from stack;
  4412                              <1>  	; FI;
  4413                              <1> 	;
  4414                              <1> 	; //
  4415                              <1> 
  4416                              <1> int33h_2:
  4417 00004F5E 80FC05              <1> 	cmp	ah, 05h ; format track
  4418 00004F61 7709                <1> 	ja	short int33h_3
  4419 00004F63 722B                <1> 	jb	short int33h_5
  4420 00004F65 51                  <1> 	push	ecx
  4421                              <1> 	;mov	ecx, 1
  4422                              <1> 	; 17/07/2022
  4423 00004F66 31C9                <1> 	xor	ecx, ecx
  4424 00004F68 FEC1                <1> 	inc	cl
  4425                              <1> 	; ecx = 1
  4426 00004F6A EBC9                <1> 	jmp	short int33h_1
  4427                              <1> int33h_3:
  4428 00004F6C 80FC1C              <1> 	cmp	ah, 1Ch ; LBA write
  4429 00004F6F 771F                <1> 	ja	short int33h_5
  4430 00004F71 74B8                <1> 	je	short int33h_0
  4431 00004F73 80FC1B              <1> 	cmp	ah, 1Bh ; LBA read
  4432 00004F76 740D                <1> 	je	short int33h_4
  4433 00004F78 80FC08              <1> 	cmp	ah, 08h ; get disk parameters
  4434 00004F7B 7513                <1> 	jne	short int33h_5
  4435                              <1> 	; 01/06/2016
  4436 00004F7D 8B1D[48890100]      <1> 	mov	ebx, [user_buffer] ; user's buffer address
  4437 00004F83 EB10                <1> 	jmp	short int33h_6
  4438                              <1> int33h_4:
  4439                              <1> 	;; 17/07/2022 - 64K r/w buffer limit check ?
  4440                              <1> 	;cmp	al, 80h ; 128	
  4441                              <1> 	;ja	short int33h_8 ; error
  4442                              <1> 	;; 17/07/2022 - zero r/w count check ?
  4443                              <1> 	;or	al, al
  4444                              <1> 	;jz	short int33h_8 ; error
  4445                              <1> 
  4446                              <1> 	; 17/07/2022 (buffer limit and zero count check)
  4447 00004F85 FEC8                <1> 	dec	al
  4448 00004F87 78C0                <1> 	js	short int33h_8 ; error
  4449 00004F89 FEC0                <1> 	inc	al
  4450                              <1> 
  4451 00004F8B A2[86820100]        <1> 	mov	byte [scount], al ; <= 128 sectors
  4452                              <1> int33h_5:
  4453 00004F90 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; max. 65536 bytes
  4454                              <1> 				    ; buf. addr: 70000h	
  4455                              <1> 	;mov	byte [ClusterBuffer_Valid], 0
  4456                              <1> int33h_6:
  4457                              <1> 	; 13/07/2022
  4458                              <1> 	;pop	ds
  4459                              <1> 	;pushfd
  4460                              <1> 	;push 	cs
  4461                              <1> 	
  4462 00004F95 E83B000000          <1> 	call 	DISK_IO
  4463                              <1> 	
  4464                              <1> 	;;mov	ebx, [cs:user_buffer] ; 01/06/2016
  4465                              <1> 	;mov	ebx, [user_buffer] ; 13/07/2022 
  4466 00004F9A 72B2                <1> 	jc	short int33h_9
  4467                              <1> 	;
  4468                              <1> 	;cmp	byte [cs:scount], 0
  4469                              <1> 	;jna	short int33h_7	
  4470 00004F9C 803D[86820100]00    <1> 	cmp	byte [scount], 0 ; 13/07/2022
  4471 00004FA3 76A9                <1> 	jna	short int33h_9
  4472                              <1> 
  4473                              <1> 	; 13/07/2022
  4474                              <1> 
  4475                              <1> 	; transfer sector buffer content to user's buffer
  4476                              <1> 	;push	es
  4477                              <1> 	;push	ds
  4478                              <1> 	;push	eax
  4479                              <1> 	;mov	ax, KDATA
  4480                              <1> 	;mov	ds, ax
  4481                              <1> 	;mov	es, ax
  4482                              <1> 	;push	ecx
  4483                              <1> 	;push	esi
  4484                              <1> 	;push	edi
  4485                              <1> 	
  4486                              <1> 	; 13/07/2022
  4487 00004FA5 50                  <1> 	push	eax
  4488 00004FA6 0FB60D[86820100]    <1> 	movzx	ecx, byte [scount]
  4489 00004FAD C1E109              <1> 	shl	ecx, 9 ; * 512 bytes
  4490                              <1> 	;mov	edi, ebx ; user's buffer address
  4491 00004FB0 8B3D[48890100]      <1> 	mov	edi, [user_buffer] ; 13/07/2022
  4492 00004FB6 BE00000700          <1> 	mov	esi, Cluster_Buffer
  4493 00004FBB E8D0BF0000          <1> 	call	transfer_to_user_buffer 
  4494                              <1> 		; (ecx and eax will be modified)
  4495 00004FC0 58                  <1> 	pop	eax
  4496                              <1> 
  4497                              <1> 	; 13/07/2022
  4498 00004FC1 7286                <1> 	jc	short int33h_8 ; eax = 0FFh
  4499 00004FC3 EB89                <1> 	jmp	short int33h_9 ; cf = 0
  4500                              <1> 
  4501                              <1> 	;pop	edi
  4502                              <1> 	;pop	esi
  4503                              <1> 	;pop	ecx
  4504                              <1> 	;pop	eax
  4505                              <1> 	;pop	ds
  4506                              <1> 	;pop	es
  4507                              <1> 	;jc	short int33h_8
  4508                              <1> ;int33h_7:
  4509                              <1> 	;cli
  4510                              <1> 	;;;15/01/2017
  4511                              <1> 	;;;mov	byte [ss:intflg], 0 ; 07/01/2017
  4512                              <1> 	;; cf = 0  ; use eflags which is in stack
  4513                              <1> 	;iretd	
  4514                              <1> ;int33h_8:
  4515                              <1> 	;mov	eax, 0FFh ; Unknown error !?
  4516                              <1> 	; 13/07/2022
  4517                              <1> 	;xor	eax, eax
  4518                              <1> 	;dec	al  ; eax = 0FFh	
  4519                              <1> 	;jmp	short int33h_9
  4520                              <1> 	 
  4521                              <1> ;int33h_9:
  4522                              <1> 	;; cf = 1
  4523                              <1> 	;
  4524                              <1> 	;; (*) 29/05/2016	
  4525                              <1> 	;; (*) retf 4 ; skip eflags on stack
  4526                              <1> 	;; Note: This 'retf 4' was wrong, -it was causing
  4527                              <1> 	;;       to stack errors in ring 3-
  4528                              <1> 	;;	POP sequence of 'retf 4' is as
  4529                              <1> 	;;       "eip, cs, eflags, esp, ss, +4 bytes" 
  4530                              <1>         ;;       it is not as "eip, cs, +4 bytes, esp, ss" ! 
  4531                              <1> 	;
  4532                              <1> 	;; 29/05/2016 -set carry flag on stack-
  4533                              <1> 	;or	byte [esp+8], 1  ; set carry bit of eflags register
  4534                              <1> 	;;iretd
  4535                              <1> 	;jmp	short int33h_7 ; 07/01/2017
  4536                              <1> 
  4537                              <1> ;; 11/04/2021
  4538                              <1> ;int13h: ; 21/02/2015
  4539                              <1> ;	clc ; 11/04/2021
  4540                              <1> ;	pushfd
  4541                              <1> ;	push 	cs
  4542                              <1> ;	call 	DISK_IO
  4543                              <1> ;	retn
  4544                              <1> 
  4545                              <1> int13h:
  4546                              <1> 	; 13/07/2022 - TRDOS 386 v2.0.5
  4547                              <1> 	; Note: DISK_IO sets registers on stack
  4548                              <1> 	; 	as return parameters. So,
  4549                              <1> 	;	stack order (at the entry of 'DISK_IO')
  4550                              <1> 	;	must be same with 'int33h:' as above.
  4551                              <1> 		
  4552                              <1> 	;push	es ; not necessary
  4553                              <1> 	;push	ds ; not necessary
  4554                              <1> 	;
  4555                              <1> 	; following pushes are necessary
  4556                              <1> 	; for setting registers -return values- in DISK_IO
  4557 00004FC5 53                  <1> 	push	ebx
  4558 00004FC6 51                  <1> 	push	ecx
  4559 00004FC7 52                  <1> 	push	edx
  4560 00004FC8 56                  <1> 	push	esi
  4561 00004FC9 57                  <1> 	push	edi
  4562                              <1> 	;push	ebp
  4563                              <1> 	;mov	ebp, esp
  4564                              <1> 	; edi = ebp+4
  4565                              <1> 	; esi = ebp+8
  4566                              <1> 	; edx = ebp+12
  4567                              <1> 	; ecx = ebp+16
  4568                              <1> 	; ebx = ebp+20
  4569                              <1> 	;
  4570 00004FCA E806000000          <1> 	call	DISK_IO
  4571                              <1> 	;
  4572 00004FCF 5F                  <1> 	pop	edi
  4573 00004FD0 5E                  <1> 	pop	esi
  4574 00004FD1 5A                  <1> 	pop	edx
  4575 00004FD2 59                  <1> 	pop	ecx
  4576 00004FD3 5B                  <1> 	pop	ebx	
  4577                              <1> 	;
  4578                              <1> 	;pop	ds
  4579                              <1> 	;pop	es
  4580                              <1> 	;
  4581 00004FD4 C3                  <1> 	retn
  4582                              <1> 
  4583                              <1> ; 10/08/2022
  4584                              <1> ; 07/08/2022
  4585                              <1> ; 17/07/2022
  4586                              <1> ; 13/07/2022 - TRDOS 386 v2.0.5
  4587                              <1> ; 18/04/2021 - TRDOS 386 v2.0.4
  4588                              <1> ; 11/04/2021 - TRDOS 386 v2.0.3
  4589                              <1> ; 30/08/2020
  4590                              <1> ; 09/12/2017
  4591                              <1> ; 29/05/2016
  4592                              <1> ; 27/05/2016 - TRDOS 386 (TRDOS v2.0)
  4593                              <1> 
  4594                              <1> DISK_IO:
  4595                              <1> 	; 10/08/2022
  4596                              <1> 	; 17/07/2022
  4597                              <1> 	; 13/07/2022
  4598                              <1> 	; Registers are also on stack 
  4599                              <1> 	; (with same contents) 
  4600                              <1> 	; in following order:
  4601                              <1> 	;
  4602                              <1> 	;    ebx = esp+20
  4603                              <1> 	;    ecx = esp+16
  4604                              <1> 	;    edx = esp+12
  4605                              <1> 	;    esi = esp+8
  4606                              <1> 	;    edi = esp+4
  4607                              <1> 
  4608                              <1> 	; cs = KCODE (== KDATA base address)
  4609                              <1> 	; ss = KDATA
  4610                              <1> 	; ds = KDATA
  4611                              <1> 	; es = KDATA
  4612                              <1> 
  4613                              <1> 	; 17/07/2022
  4614 00004FD5 FB                  <1> 	sti				; ENABLE INTERRUPTS
  4615                              <1> 
  4616 00004FD6 80FA80              <1> 	cmp	dl, 80h			; TEST FOR FIXED DISK DRIVE
  4617                              <1> 	;jae	short A1		; YES, HANDLE HERE
  4618                              <1> 	;;;int	40h			; DISKETTE HANDLER
  4619                              <1> 	;;call	int40h
  4620                              <1> 	;jb	DISKETTE_IO_1
  4621                              <1> ;RET_2:
  4622                              <1> 	;;retf	2			; BACK TO CALLER
  4623                              <1> 	;retf	4
  4624                              <1> 	; 11/04/2021
  4625 00004FD9 7305                <1> 	jnb	short A1
  4626 00004FDB E934F2FFFF          <1> 	jmp	DISKETTE_IO_1
  4627                              <1> A1:
  4628                              <1> 	;sti	 ; 17/07/2022		; ENABLE INTERRUPTS
  4629                              <1> 	
  4630                              <1> 	;; 04/01/2015
  4631                              <1> 	;;or	ah, ah
  4632                              <1> 	;;jnz	short A2
  4633                              <1> 	;;int	40h			; RESET NEC WHEN AH=0
  4634                              <1> 	;;sub	ah, ah
  4635                              <1> 	
  4636 00004FE0 80FA83              <1> 	cmp	dl, (80h + S_MAX_FILE - 1)
  4637                              <1> 	;ja	short RET_2
  4638 00004FE3 760A                <1> 	jna	short _A0
  4639                              <1> 	
  4640                              <1> 	; 13/07/2022
  4641                              <1> 	; (here, DS is KDATA segment already) 
  4642                              <1> 	;
  4643                              <1> 	; 29/05/2016
  4644                              <1> 	;push	ds
  4645                              <1> 	; 11/04/2021
  4646                              <1> 	;push	eax
  4647                              <1> 	;mov	ax, KDATA
  4648                              <1> 	;mov	ds, ax
  4649                              <1> 	; 11/04/2021
  4650                              <1> 	;pop	eax
  4651                              <1> 	
  4652 00004FE5 B4AA                <1> 	mov     ah, 0AAh        ; Hard disk drive not ready !
  4653                              <1> 				; (Programmer's guide to AMIBIOS, 1992)
  4654 00004FE7 8825[577D0100]      <1> 	mov     byte [DISK_STATUS1], ah
  4655                              <1> 	; 13/07/2022
  4656                              <1> 	;pop	ds
  4657                              <1> 	;jmp	short RET_2
  4658 00004FED F9                  <1> 	stc
  4659 00004FEE C3                  <1> 	retn
  4660                              <1> _A0:
  4661                              <1> 	; 18/01/2015
  4662 00004FEF 08E4                <1> 	or	ah, ah
  4663 00004FF1 742C                <1> 	jz	short A4
  4664 00004FF3 80FC0D              <1> 	cmp	ah, 0Dh	; Alternate reset
  4665 00004FF6 7504                <1> 	jne	short A2
  4666 00004FF8 28E4                <1> 	sub	ah, ah	; Reset
  4667 00004FFA EB23                <1> 	jmp	short A4
  4668                              <1> A2:
  4669                              <1> 	; 13/07/2022
  4670 00004FFC 80FC08              <1> 	cmp	ah, 08h			; GET PARAMETERS IS A SPECIAL CASE
  4671 00004FFF 7505                <1> 	jne	short A3
  4672 00005001 E911040000          <1>         jmp	GET_PARM_N
  4673                              <1> A3:	
  4674                              <1> 	; 13/07/2022
  4675 00005006 80FC15              <1> 	cmp	ah, 15h			; READ DASD TYPE IS ALSO
  4676 00005009 7514                <1> 	jne	short A4
  4677 0000500B E9AC030000          <1>         jmp	READ_DASD_TYPE	; Return Drive Type
  4678                              <1> 				; (Programmer's guide to AMIBIOS, 1992)
  4679                              <1> 	; 13/07/2022
  4680                              <1> int33h_bad_cmd:
  4681                              <1> 	; 16/05/2016
  4682                              <1> 	; 30/01/2015
  4683                              <1> 	; 29/05/2016
  4684                              <1> 	;push	ds
  4685                              <1> 	;push	eax
  4686                              <1> 	;mov	ax, KDATA
  4687                              <1> 	;mov	ds, ax
  4688                              <1> 	;pop	eax
  4689                              <1> 
  4690 00005010 B401                <1> 	mov	ah, BAD_CMD
  4691 00005012 8825[577D0100]      <1> 	mov     [DISK_STATUS1], ah ; BAD_CMD  ; COMMAND ERROR
  4692                              <1>         ;jmp	short RET_2
  4693                              <1> 	; 13/07/2022
  4694                              <1> ;RET_2:
  4695                              <1> 	; (*) 29/05/2016
  4696                              <1> 	; (*) retf 4
  4697                              <1> 	;or	byte [esp+8], 1 ; set carry bit of eflags register
  4698                              <1> 	;iretd
  4699                              <1> 	
  4700                              <1> 	; 13/07/2022
  4701 00005018 F9                  <1> 	stc
  4702                              <1> 	; cf = 1, ah = BAD_CMD
  4703 00005019 C3                  <1> 	retn
  4704                              <1> _A4:
  4705                              <1> 	; 13/07/2022
  4706                              <1> 	; 02/02/2015
  4707 0000501A 80FC1D              <1> 	cmp	ah, 1Dh			; (Temporary for Retro UNIX 386 v1)
  4708                              <1> 	; 12/01/2015
  4709                              <1> 	;cmc
  4710                              <1> 	;jnc	short A4
  4711                              <1> 	; 13/07/2022
  4712 0000501D 73F1                <1> 	jnb	short int33h_bad_cmd	
  4713                              <1> A4:					; SAVE REGISTERS DURING OPERATION
  4714 0000501F C8080000            <1> 	enter	8, 0			; SAVE (BP) AND MAKE ROOM FOR @CMD_BLOCK
  4715                              <1> 	
  4716                              <1> 	; 13/07/2022
  4717                              <1> 	; ENTER 8, 0
  4718                              <1> 	;;push	ebp
  4719                              <1> 	;;mov	ebp, esp
  4720                              <1> 	;;sub	esp, 8
  4721                              <1> 	;
  4722                              <1> 	;push	ebx			;  IN THE STACK, THE COMMAND BLOCK IS:
  4723                              <1> 	;push	ecx			;   @CMD_BLOCK == BYTE PTR [BP]-8
  4724                              <1> 	;push	edx
  4725                              <1> 	;push	esi
  4726                              <1> 	;push	edi
  4727                              <1> 
  4728                              <1> 	; 13/07/2022
  4729                              <1> 	; edi = ebp+8
  4730                              <1> 	; esi = ebp+12
  4731                              <1> 	; edx = ebp+16
  4732                              <1> 	; ecx = ebp+20
  4733                              <1> 	; ebx = ebp+24
  4734                              <1> 
  4735                              <1> 	;;04/01/2015
  4736                              <1> 	;;or	ah, ah			; CHECK FOR RESET
  4737                              <1> 	;;jnz	short A5
  4738                              <1> 	;;mov	dl, 80h			; FORCE DRIVE 80 FOR RESET
  4739                              <1> ;;A5:	
  4740                              <1> 	; 13/07/2022
  4741 00005023 E880000000          <1> 	call	DISK_IO_CONT		; PERFORM THE OPERATION
  4742                              <1> 	;;call	DDS			; ESTABLISH SEGMENT
  4743 00005028 8A25[577D0100]      <1> 	mov	ah, [DISK_STATUS1]	; GET STATUS FROM OPERATION
  4744                              <1> 	;(*) cmp ah, 1			; SET THE CARRY FLAG TO INDICATE
  4745                              <1> 					; SUCCESS OR FAILURE
  4746                              <1> 	;pop	edi			; RESTORE REGISTERS
  4747                              <1> 	;pop	esi
  4748                              <1> 	;pop	edx
  4749                              <1> 	;pop	ecx
  4750                              <1> 	;pop	ebx
  4751                              <1> 	
  4752 0000502E C9                  <1> 	leave				; ADJUST (SP) AND RESTORE (BP)
  4753                              <1> 	
  4754                              <1> 	;retf	2			; THROW AWAY SAVED FLAGS
  4755                              <1> 	; (*) 29/05/2016
  4756                              <1> 	; (*) retf 4
  4757                              <1> 	
  4758                              <1> 	; 13/07/2022
  4759 0000502F 80FC01              <1> 	cmp	ah, 1
  4760                              <1> 	;jc	short _A5 
  4761                              <1> 	;or	byte [esp+8], 1 ; set carry bit of eflags register
  4762                              <1> ;_A5:
  4763                              <1> 	;iretd
  4764                              <1> 	; 10/08/2022
  4765 00005032 F5                  <1> 	cmc
  4766                              <1> 	; 13/07/2022
  4767 00005033 C3                  <1> 	retn
  4768                              <1> 
  4769                              <1> ; 21/02/2015
  4770                              <1> ;       dw --> dd
  4771                              <1> 	; 13/07/2022
  4772                              <1> D1:					; FUNCTION TRANSFER TABLE
  4773 00005034 [4B520000]          <1> 	dd	DISK_RESET		; 00h
  4774 00005038 [AB520000]          <1> 	dd	RETURN_STATUS		; 01h
  4775 0000503C [BE520000]          <1> 	dd	DISK_READ		; 02h
  4776 00005040 [1A530000]          <1> 	dd	DISK_WRITE		; 03h
  4777 00005044 [A4530000]          <1> 	dd	DISK_VERF		; 04h
  4778 00005048 [8E530000]          <1> 	dd	FMT_TRK 		; 05h
  4779 0000504C [E1510000]          <1> 	dd	BAD_COMMAND		; 06h	FORMAT BAD SECTORS
  4780 00005050 [E1510000]          <1> 	dd	BAD_COMMAND		; 07h	FORMAT DRIVE
  4781 00005054 [E1510000]          <1> 	dd	BAD_COMMAND		; 08h	RETURN PARAMETERS
  4782 00005058 [97540000]          <1> 	dd	INIT_DRV		; 09h
  4783 0000505C [B8520000]          <1> 	dd	RD_LONG 		; 0Ah
  4784 00005060 [14530000]          <1> 	dd	WR_LONG 		; 0Bh
  4785 00005064 [08550000]          <1> 	dd	DISK_SEEK		; 0Ch
  4786 00005068 [4B520000]          <1> 	dd	DISK_RESET		; 0Dh
  4787 0000506C [E1510000]          <1> 	dd	BAD_COMMAND		; 0Eh	READ BUFFER
  4788 00005070 [E1510000]          <1> 	dd	BAD_COMMAND		; 0Fh	WRITE BUFFER
  4789 00005074 [30550000]          <1> 	dd	TST_RDY 		; 10h
  4790 00005078 [64550000]          <1> 	dd	HDISK_RECAL		; 11h
  4791 0000507C [E1510000]          <1> 	dd	BAD_COMMAND		; 12h	MEMORY DIAGNOSTIC
  4792 00005080 [E1510000]          <1> 	dd	BAD_COMMAND		; 13h	DRIVE DIAGNOSTIC
  4793 00005084 [9A550000]          <1> 	dd	CTLR_DIAGNOSTIC 	; 14h	CONTROLLER DIAGNOSTIC
  4794                              <1> 	;; 02/02/2015 (Temporary - Retro UNIX 386 v1 - DISK I/O test)
  4795 00005088 [E1510000]          <1> 	dd	BAD_COMMAND		; 15h
  4796 0000508C [E1510000]          <1> 	dd	BAD_COMMAND		; 16h
  4797 00005090 [E1510000]          <1> 	dd	BAD_COMMAND		; 17h
  4798 00005094 [E1510000]          <1> 	dd	BAD_COMMAND		; 18h
  4799 00005098 [E1510000]          <1> 	dd	BAD_COMMAND		; 19h
  4800 0000509C [E1510000]          <1> 	dd	BAD_COMMAND		; 1Ah
  4801 000050A0 [BE520000]          <1> 	dd	DISK_READ		; 1Bh ; LBA read
  4802 000050A4 [1A530000]          <1> 	dd	DISK_WRITE		; 1Ch ; LBA write
  4803                              <1> D1L     EQU    $ - D1
  4804                              <1> 
  4805                              <1> 	; 02/12/2023
  4806                              <1> 	; 01/12/2023 - TRDOS 386 v2.0.7 
  4807                              <1> 	; 07/08/2022
  4808                              <1> 	; 17/07/2022 - TRDOS 386 v2.0.5
  4809                              <1> DISK_IO_CONT:
  4810                              <1> 	;;call	DDS			; ESTABLISH SEGMENT
  4811                              <1> 	; 11/04/2021
  4812 000050A8 80FC01              <1> 	cmp	ah, 01h			; RETURN STATUS
  4813 000050AB 7505                <1> 	jne	short SU0
  4814 000050AD E9F9010000          <1> 	jmp	RETURN_STATUS
  4815                              <1> SU0:
  4816 000050B2 C605[577D0100]00    <1> 	mov	byte [DISK_STATUS1], 0 	; RESET THE STATUS INDICATOR
  4817                              <1> 	; 13/07/2022
  4818 000050B9 89DE                <1> 	mov	esi, ebx ; 21/02/2015	; SAVE DATA ADDRESS
  4819 000050BB 8A1D[587D0100]      <1> 	mov	bl, [HF_NUM]		; GET NUMBER OF DRIVES
  4820 000050C1 80E27F              <1> 	and	dl, 7Fh			; GET DRIVE AS 0 OR 1
  4821                              <1> 					; (get drive number as 0 to 3)
  4822                              <1> 	; 14/02/2015 
  4823 000050C4 38D3                <1> 	cmp	bl, dl
  4824                              <1> 	;jbe	short BAD_COMMAND	; INVALID DRIVE
  4825                              <1> 	; 07/08/2022
  4826 000050C6 7705                <1> 	ja	short SU0X
  4827 000050C8 E914010000          <1> 	jmp	BAD_COMMAND
  4828                              <1> SU0X:
  4829                              <1> 	;;03/01/2015
  4830 000050CD 29DB                <1> 	sub	ebx, ebx
  4831 000050CF 88D3                <1> 	mov	bl, dl
  4832 000050D1 883D[6C7D0100]      <1> 	mov	[LBAMode], bh 	; 0
  4833                              <1> 	
  4834                              <1> 	;test	byte [ebx+hd0_type], 1 	; LBA ready ?
  4835                              <1> 	;jz	short su1		; no
  4836                              <1> 	;inc	byte [LBAMode]
  4837                              <1> ;su1:
  4838                              <1> 	; 11/04/2021 (32 bit push/pop)
  4839                              <1> 	; 21/02/2015 (32 bit modification)
  4840                              <1> 	; 04/01/2015
  4841 000050D7 50                  <1> 	push	eax ; ***
  4842                              <1> 	;push	es  ; **
  4843 000050D8 52                  <1> 	push	edx ; *
  4844 000050D9 50                  <1> 	push	eax ; ****
  4845 000050DA E8AA060000          <1> 	call	GET_VEC 		; GET DISK PARAMETERS
  4846                              <1> 	; 02/02/2015
  4847                              <1> 	;mov	ax, [ES:BX+16] ; I/O port base address (1F0h, 170h)
  4848 000050DF 668B4310            <1> 	mov	ax, [ebx+16]
  4849 000050E3 66A3[2E660000]      <1> 	mov	[HF_PORT], ax
  4850                              <1> 	;mov	dx, [ES:BX+18] ; control port address (3F6h, 376h)
  4851 000050E9 668B5312            <1> 	mov	dx, [ebx+18]
  4852 000050ED 668915[30660000]    <1> 	mov	[HF_REG_PORT], dx
  4853                              <1> 	;mov	al, [ES:BX+20] ; head register upper nibble (A0h,B0h,E0h,F0h)
  4854 000050F4 8A4314              <1> 	mov	al, [ebx+20]
  4855                              <1> 	; 23/02/2015
  4856 000050F7 A840                <1> 	test	al, 40h	 ; LBA bit (bit 6)
  4857 000050F9 7406                <1> 	jz 	short su1
  4858 000050FB FE05[6C7D0100]      <1> 	inc	byte [LBAMode] ; 1 
  4859                              <1> su1: 	 
  4860 00005101 C0E804              <1> 	shr 	al, 4
  4861 00005104 2401                <1> 	and	al, 1			
  4862 00005106 A2[32660000]        <1> 	mov	[hf_m_s], al 
  4863                              <1> 	;
  4864                              <1> 	; 03/01/2015
  4865                              <1> 	;mov	al, [ES:BX+8]		; GET CONTROL BYTE MODIFIER
  4866 0000510B 8A4308              <1> 	mov	al, [ebx+8]
  4867                              <1> 	;mov	dx, [HF_REG_PORT]	; Device Control register
  4868 0000510E EE                  <1> 	out	dx, al			; SET EXTRA HEAD OPTION
  4869                              <1> 					; -here-
  4870                              <1> 					; Control Byte: (= 08h)
  4871                              <1> 					;  bit 0 - 0
  4872                              <1> 					;  bit 1 - nIEN (1 = disable irq)
  4873                              <1> 					;  bit 2 - SRST (software RESET)
  4874                              <1> 					;  bit 3 - use extra heads (8 to 15)
  4875                              <1> 					;          -always set to 1-	
  4876                              <1> 					;  (bits 3 to 7 are reserved
  4877                              <1> 					;          for ATA devices)
  4878 0000510F 8A25[597D0100]      <1> 	mov	ah, [CONTROL_BYTE]	; SET EXTRA HEAD OPTION IN
  4879 00005115 80E4C0              <1> 	and	ah, 0C0h 		; CONTROL BYTE
  4880 00005118 08C4                <1> 	or	ah, al
  4881 0000511A 8825[597D0100]      <1> 	mov	[CONTROL_BYTE], ah
  4882                              <1> 	
  4883                              <1> 	; 11/04/2021 (32 bit push/pop)
  4884                              <1> 	; 04/01/2015
  4885 00005120 58                  <1> 	pop	eax ; ****
  4886 00005121 5A                  <1> 	pop	edx ; * ; 14/02/2015
  4887 00005122 20E4                <1> 	and	ah, ah	; Reset function ?
  4888 00005124 7506                <1> 	jnz	short su2
  4889                              <1> 	;pop	es ; **
  4890 00005126 58                  <1> 	pop	eax ; ***
  4891 00005127 E91F010000          <1>         jmp     DISK_RESET
  4892                              <1> su2:
  4893 0000512C 803D[6C7D0100]00    <1> 	cmp	byte [LBAMode], 0
  4894 00005133 765E                <1> 	jna	short su3
  4895                              <1> 	;
  4896                              <1> 	; 02/02/2015 (LBA read/write function calls)
  4897 00005135 80FC1B              <1> 	cmp	ah, 1Bh
  4898 00005138 720A                <1> 	jb	short lbarw1
  4899 0000513A 80FC1C              <1> 	cmp	ah, 1Ch
  4900 0000513D 7759                <1> 	ja 	short invldfnc
  4901                              <1> 	;;pop	edx ; * ; 14/02/2015
  4902                              <1> 	;mov	ax, cx ; Lower word of LBA address (bits 0-15)
  4903                              <1> 
  4904                              <1> 	; 01/12/2023 (48 bit LBA rw) 
  4905 0000513F E9AD000000          <1> 	jmp	lba_read_write
  4906                              <1> 
  4907                              <1> lbarw1:
  4908                              <1> 	; convert CHS to LBA
  4909                              <1> 	;
  4910                              <1> 	; LBA calculation - AWARD BIOS - 1999 - AHDSK.ASM
  4911                              <1> 	; LBA = "# of Heads" * Sectors/Track * Cylinder + Head * Sectors/Track
  4912                              <1> 	;	+ Sector - 1
  4913                              <1> 	; 11/04/2021 (32 bit push/pop)
  4914 00005144 52                  <1> 	push	edx ; * ;; 14/02/2015
  4915                              <1> 	;xor	dh, dh
  4916 00005145 31D2                <1> 	xor	edx, edx
  4917                              <1> 	;mov	dl, [ES:BX+14]	; sectors per track (logical)
  4918 00005147 8A530E              <1> 	mov	dl, [ebx+14]
  4919                              <1> 	;xor	ah, ah
  4920 0000514A 31C0                <1> 	xor	eax, eax
  4921                              <1> 	;mov	al, [ES:BX+2]	; heads (logical) 	
  4922 0000514C 8A4302              <1> 	mov	al, [ebx+2]
  4923 0000514F FEC8                <1> 	dec	al
  4924 00005151 6640                <1> 	inc	ax		; 0 = 256
  4925 00005153 66F7E2              <1> 	mul 	dx
  4926                              <1> 		; AX = # of Heads * Sectors/Track
  4927 00005156 6689CA              <1> 	mov	dx, cx
  4928                              <1> 	;and	cx, 3Fh	 ; sector  (1 to 63)
  4929 00005159 83E13F              <1> 	and	ecx, 3Fh
  4930 0000515C 86F2                <1> 	xchg	dl, dh
  4931 0000515E C0EE06              <1> 	shr	dh, 6
  4932                              <1> 		; DX = cylinder (0 to 1023)
  4933                              <1> 	;mul 	dx
  4934                              <1> 		; DX:AX = # of Heads" * Sectors/Track * Cylinder
  4935 00005161 F7E2                <1> 	mul	edx
  4936 00005163 FEC9                <1> 	dec	cl ; sector - 1
  4937                              <1> 	;add	ax, cx
  4938                              <1> 	;adc	dx, 0
  4939                              <1> 		; DX:AX = # of Heads" * Sectors/Track * Cylinder + Sector - 1
  4940 00005165 01C8                <1> 	add	eax, ecx
  4941                              <1> 	; 11/04/2021 (32 bit push/pop)
  4942 00005167 59                  <1> 	pop	ecx ; * ; ch = head, cl = drive number (zero based)
  4943                              <1> 	;push	dx
  4944                              <1> 	;push	ax
  4945 00005168 50                  <1> 	push	eax
  4946                              <1> 	; 13/07/2022
  4947 00005169 29C0                <1> 	sub	eax, eax
  4948                              <1> 	;mov	al, [ES:BX+14]	; sectors per track (logical)	
  4949 0000516B 8A430E              <1> 	mov	al, [ebx+14]
  4950 0000516E F6E5                <1> 	mul	ch
  4951                              <1> 		; AX = Head * Sectors/Track
  4952                              <1>         ; 13/07/2022
  4953                              <1> 	;movzx	eax, ax ; 09/12/2017
  4954                              <1> 	;pop	dx
  4955 00005170 5A                  <1> 	pop	edx
  4956                              <1> 	;add	ax, dx
  4957                              <1> 	;pop	dx
  4958                              <1> 	;adc	dx, 0 ; add carry bit
  4959 00005171 01D0                <1> 	add	eax, edx
  4960                              <1> lbarw2:
  4961 00005173 29D2                <1> 	sub	edx, edx ; 21/02/2015
  4962 00005175 88CA                <1> 	mov	dl, cl ; 21/02/2015
  4963 00005177 C645F800            <1>         mov     byte [CMD_BLOCK], 0 ; Features Register
  4964                              <1> 				; NOTE: Features register (1F1h, 171h)
  4965                              <1> 				; is not used for ATA device R/W functions. 
  4966                              <1> 				; It is old/obsolete 'write precompensation'
  4967                              <1> 				; register and error register
  4968                              <1> 				; for old ATA/IDE devices.
  4969                              <1> 	; 18/01/2014
  4970                              <1> 	;mov	ch, [hf_m_s]	; Drive 0 (master) or 1 (slave)
  4971 0000517B 8A0D[32660000]      <1> 	mov	cl, [hf_m_s]
  4972                              <1> 	;shl	ch, 4		; bit 4 (drive bit)
  4973                              <1> 	;or	ch, 0E0h	; bit 5 = 1
  4974                              <1> 				; bit 6 = 1 = LBA mode
  4975                              <1> 				; bit 7 = 1
  4976 00005181 80C90E              <1> 	or	cl, 0Eh ; 1110b
  4977                              <1> 	;and	dh, 0Fh		; LBA byte 4 (bits 24 to 27)
  4978 00005184 25FFFFFF0F          <1> 	and	eax, 0FFFFFFFh
  4979 00005189 C1E11C              <1> 	shl	ecx, 28 ; 21/02/2015
  4980                              <1> 	;or	dh, ch
  4981 0000518C 09C8                <1> 	or	eax, ecx	
  4982                              <1> 	;;mov	[CMD_BLOCK+2], al ; LBA byte 1 (bits 0 to 7)
  4983                              <1> 				  ; (Sector Number Register)
  4984                              <1> 	;;mov	[CMD_BLOCK+3], ah ; LBA byte 2 (bits 8 to 15)
  4985                              <1> 				  ; (Cylinder Low Register)
  4986                              <1> 	;mov	[CMD_BLOCK+2], ax ; LBA byte 1, 2
  4987                              <1> 	;mov	[CMD_BLOCK+4], dl ; LBA byte 3 (bits 16 to 23)
  4988                              <1> 				  ; (Cylinder High Register)
  4989                              <1> 	;;mov	[CMD_BLOCK+5], dh ; LBA byte 4 (bits 24 to 27)
  4990                              <1> 				  ; (Drive/Head Register)
  4991                              <1> 	
  4992                              <1> 	;mov	[CMD_BLOCK+4], dx ; LBA byte 4, LBA & DEV select bits
  4993 0000518E 8945FA              <1> 	mov	[CMD_BLOCK+2], eax ; 21/02/2015
  4994                              <1> 	; 14/02/2015
  4995                              <1> 	;mov	dl, cl ; Drive number (INIT_DRV)		
  4996 00005191 EB36                <1> 	jmp	short su4
  4997                              <1> su3:
  4998                              <1> 	; 07/08/2022
  4999                              <1> 	; 13/07/2022
  5000                              <1> 	; 02/02/2015 
  5001                              <1> 	; (1Bh & 1Ch functions are not valid for CHS mode) 
  5002 00005193 80FC14              <1> 	cmp 	ah, 14h
  5003 00005196 7603                <1> 	jna 	short chsfnc
  5004                              <1> invldfnc:
  5005                              <1>         ; 14/02/2015  
  5006                              <1> 	;pop	es ; **
  5007                              <1> 	; 11/04/2021
  5008 00005198 58                  <1> 	pop	eax ; *** 
  5009 00005199 EB46                <1>         jmp     short BAD_COMMAND
  5010                              <1> chsfnc:	
  5011                              <1> 	;mov	ax, [ES:BX+5]		; GET WRITE PRE-COMPENSATION CYLINDER
  5012 0000519B 668B4305            <1> 	mov	ax, [ebx+5]
  5013                              <1> 	;shr	ax, 2
  5014                              <1> 	; 07/08/2022
  5015 0000519F C1E802              <1> 	shr	eax, 2
  5016 000051A2 8845F8              <1> 	mov	[CMD_BLOCK], al
  5017                              <1> 	
  5018                              <1> 	;;mov	al, [ES:BX+8]		; GET CONTROL BYTE MODIFIER
  5019                              <1> 	;;push	edx ; *
  5020                              <1> 	;;mov	dx, [HF_REG_PORT]
  5021                              <1> 	;;out	dx, al			; SET EXTRA HEAD OPTION
  5022                              <1> 	;;pop	edx ; * 
  5023                              <1> 	;;pop	es  ; **
  5024                              <1> 	;;mov	ah, [CONTROL_BYTE]	; SET EXTRA HEAD OPTION IN
  5025                              <1> 	;;and	ah, 0C0h 		; CONTROL BYTE	
  5026                              <1> 	;;or	ah, al
  5027                              <1> 	;;mov	[CONTROL_BYTE], ah
  5028                              <1> 	
  5029 000051A5 88C8                <1> 	mov	al, cl			; GET SECTOR NUMBER
  5030 000051A7 243F                <1> 	and	al, 3Fh
  5031 000051A9 8845FA              <1> 	mov	[CMD_BLOCK+2], al
  5032 000051AC 886DFB              <1> 	mov	[CMD_BLOCK+3], ch 	; GET CYLINDER NUMBER
  5033 000051AF 88C8                <1> 	mov	al, cl
  5034 000051B1 C0E806              <1> 	shr	al, 6
  5035 000051B4 8845FC              <1> 	mov	[CMD_BLOCK+4], al 	; CYLINDER HIGH ORDER 2 BITS
  5036                              <1> 	
  5037                              <1> 	;;05/01/2015
  5038                              <1> 	;;mov	al, dl			; DRIVE NUMBER
  5039 000051B7 A0[32660000]        <1> 	mov	al, [hf_m_s]
  5040 000051BC C0E004              <1> 	shl	al, 4
  5041 000051BF 80E60F              <1> 	and	dh, 0Fh			; HEAD NUMBER
  5042 000051C2 08F0                <1> 	or	al, dh
  5043                              <1> 	;or	al, 80h or 20h
  5044 000051C4 0CA0                <1> 	or	al, 80h+20h		; ECC AND 512 BYTE SECTORS
  5045 000051C6 8845FD              <1> 	mov	[CMD_BLOCK+5], al 	; ECC/SIZE/DRIVE/HEAD
  5046                              <1> su4:
  5047                              <1> 	;pop	es ; **
  5048                              <1>         ;; 14/02/2015
  5049                              <1>         ;;pop	ax
  5050                              <1>         ;;mov	[CMD_BLOCK+1], al	; SECTOR COUNT
  5051                              <1>         ;;push	ax
  5052                              <1>         ;;mov	al, ah			; GET INTO LOW BYTE
  5053                              <1>         ;;xor	ah, ah			; ZERO HIGH BYTE
  5054                              <1>         ;;sal	ax, 1			; *2 FOR TABLE LOOKUP
  5055                              <1>         ; 11/04/2021
  5056 000051C9 58                  <1> 	pop	eax ; *** 
  5057 000051CA 8845F9              <1>         mov     [CMD_BLOCK+1], al
  5058 000051CD 29DB                <1>         sub	ebx, ebx
  5059                              <1> 	;xor	bh, bh
  5060 000051CF 88E3                <1> 	mov     bl, ah
  5061                              <1>         ;sal	bx, 1
  5062                              <1>         ; 17/07/2022
  5063 000051D1 C1E302              <1> 	sal	ebx, 2	; 32 bit offset (21/02/2015)
  5064                              <1> 	;mov	si, ax			; PUT INTO SI FOR BRANCH
  5065                              <1>         ; 13/07/2022
  5066                              <1> 	;cmp	bx, D1L			; TEST WITHIN RANGE
  5067                              <1> 	;jnb	short BAD_COMMAND_POP
  5068 000051D4 83FB74              <1> 	cmp	ebx, D1L		; TEST WITHIN RANGE
  5069 000051D7 7308                <1> 	jnb	short BAD_COMMAND
  5070                              <1>         ;xchg	bx, si
  5071 000051D9 87F3                <1>         xchg	ebx, esi
  5072                              <1> 	;;;pop	ax			; RESTORE AX
  5073                              <1> 	;;;pop	bx			; AND DATA ADDRESS
  5074                              <1> 	
  5075                              <1> 	;;push	cx
  5076                              <1> 	;;push	ax			; ADJUST ES:BX
  5077                              <1> 	;mov	cx, bx			; GET 3 HIGH ORDER NIBBLES OF BX
  5078                              <1> 	;shr	cx, 4
  5079                              <1> 	;mov	ax, es
  5080                              <1> 	;add	ax, cx
  5081                              <1> 	;mov	es, ax
  5082                              <1> 	;and	bx, 000Fh		; ES:BX CHANGED TO ES:000X
  5083                              <1> 	;;pop	ax
  5084                              <1> 	;;pop	cx
  5085                              <1> 	;;jmp	word [CS:SI+D1]
  5086                              <1> 	;jmp	word [SI+D1]
  5087                              <1> 	
  5088 000051DB FFA6[34500000]      <1> 	jmp	dword [esi+D1]
  5089                              <1> 
  5090                              <1> 	; 07/08/2022
  5091                              <1> 	; 13/07/2022
  5092                              <1> BAD_COMMAND:
  5093 000051E1 C605[577D0100]01    <1>         mov	byte [DISK_STATUS1], BAD_CMD ; COMMAND ERROR
  5094 000051E8 B000                <1> 	mov	al, 0
  5095 000051EA C3                  <1> 	retn
  5096                              <1> 
  5097                              <1> ; -----------------------------------------------------
  5098                              <1> ; 48 bit LBA read/write
  5099                              <1> ; -----------------------------------------------------
  5100                              <1> 
  5101                              <1> su10:	; 01/12/2023 ; 28 bit LBA r/w
  5102 000051EB 89C8                <1> 	mov	eax, ecx ; LBA address (21/02/2015)
  5103                              <1> 	; 13/07/2022
  5104 000051ED 88D1                <1> 	mov	cl, dl ; 14/02/2015
  5105 000051EF EB82                <1> 	jmp	short lbarw2
  5106                              <1> 
  5107                              <1> lba_read_write:
  5108                              <1> 	; 02/12/2023
  5109                              <1> 	; 01/12/2023 - TRDOS 386 v2.0.7 (48 bit LBA rw)
  5110 000051F1 81F9FFFFFF0F        <1> 	cmp	ecx, 0FFFFFFFh
  5111 000051F7 731B                <1> 	jnb	short su6
  5112                              <1> 	;movzx	eax, byte [esp] ; ***
  5113 000051F9 31C0                <1> 	xor	eax, eax
  5114 000051FB 8A0424              <1> 	mov	al, [esp] ; *** ; sector count
  5115 000051FE 01C8                <1> 	add	eax, ecx
  5116 00005200 730B                <1> 	jnc	short su5
  5117 00005202 C605[577D0100]17    <1> 	mov	byte [DISK_STATUS1], ERR_INV_PARAMETER
  5118                              <1> 	;jmp	short su7
  5119                              <1> 	; 20/06/2024
  5120 00005209 58                  <1> 	pop	eax ; ***
  5121 0000520A B000                <1> 	mov	al, 0
  5122 0000520C C3                  <1> 	retn
  5123                              <1> su5:	
  5124 0000520D 3DFFFFFF0F          <1> 	cmp	eax, 0FFFFFFFh ; 28 bit limit
  5125 00005212 76D7                <1> 	jna	short su10
  5126                              <1> su6:
  5127                              <1> 
  5128                              <1> ; 20/06/2024 (TRDOS 386 v2.0.8)
  5129                              <1> %if 0
  5130                              <1> 	; 48 bit LBA r/w
  5131                              <1> 	mov	al, [hf_m_s]	; (+!+) ; 02/12/2023
  5132                              <1> 	shl	al, 4
  5133                              <1> 	; 02/12/2023
  5134                              <1> 	;add	al, 0E0h
  5135                              <1> 	add	al, 40h
  5136                              <1> 	;;add	al, 0Eh
  5137                              <1> 	;add	al, 04h
  5138                              <1> 	;shl	al, 4
  5139                              <1> 	mov	dx, [HF_PORT]
  5140                              <1> 	add	dl, 6	; hd base port + 6
  5141                              <1> 	out	dx, al
  5142                              <1> 	; 02/12/2023
  5143                              <1> 	mov	[CMD_BLOCK+6], al
  5144                              <1> 	inc	edx	; hd base port + 7
  5145                              <1> 	in	al, dx
  5146                              <1> 	NEWIODELAY
  5147                              <1> 	;test	al, 128		; READY ?
  5148                              <1> 	and	al, 128
  5149                              <1> 	jz	short su8
  5150                              <1> 	in	al, dx
  5151                              <1> 	;test	al, 128
  5152                              <1> 	and	al, 128
  5153                              <1> 	jz	short su8
  5154                              <1> 	mov	byte [DISK_STATUS1], TIME_OUT
  5155                              <1> su7:
  5156                              <1> 	pop	eax ; ***
  5157                              <1> 	mov	al, 0
  5158                              <1> 	retn
  5159                              <1> su8:
  5160                              <1> 	;mov	dx, [HF_PORT]
  5161                              <1> 	;inc	edx
  5162                              <1> 	;inc	edx	; hd base port + 2
  5163                              <1> 	sub	dl, 5	; hd base port + 2
  5164                              <1> 	;xor	al, al
  5165                              <1> 	out	dx, al	; sector count hb (bits 8 to 15) = 0
  5166                              <1> 	inc	edx	; hd base port + 3
  5167                              <1> 	mov	eax, ecx ; LBA disk sector address
  5168                              <1> 	rol	eax, 8 
  5169                              <1> 	out	dx, al	; LBA byte 4 (bits 24 to 31)
  5170                              <1> 	inc	edx	; hd base port + 4
  5171                              <1> 	xor	al, al
  5172                              <1> 	out	dx, al	; LBA byte 5 (bits 32 to 39) = 0
  5173                              <1> 	inc	edx	; hd base port + 5
  5174                              <1> 	;sub	al, al
  5175                              <1> 	out	dx, al	; LBA byte 6 (bits 40 to 47) = 0
  5176                              <1> 
  5177                              <1> 	mov	al, [esp] ; ***
  5178                              <1> 	; 02/12/2023
  5179                              <1> 	mov	[CMD_BLOCK+1], al
  5180                              <1> 
  5181                              <1> 	sub	dl, 3	; hd base port + 2
  5182                              <1> 	out	dx, al	; sector count lb (bits 0 to 7)
  5183                              <1> 	inc	edx	; hd base port + 3
  5184                              <1> 	mov	eax, ecx ; LBA disk sector address
  5185                              <1> 	out	dx, al	; LBA byte 1 (bits 0 to 7)
  5186                              <1> 	inc	edx	; hd base port + 4
  5187                              <1> 	shr	eax, 8
  5188                              <1> 	out	dx, al	; LBA byte 2 (bits 8 to 15)
  5189                              <1> 	inc	edx	; hd base port + 5
  5190                              <1> 	shr	eax, 8
  5191                              <1> 	out	dx, al	; LBA byte 3 (bits 16 to 23)
  5192                              <1> 
  5193                              <1>  	inc     edx	; hd base port + 6
  5194                              <1> 
  5195                              <1> 	; 02/12/2023 (not necessary) (+!+)
  5196                              <1> 	;mov	al, [hf_m_s]
  5197                              <1> 	;shl	al, 4
  5198                              <1> 	;add	al, 40h
  5199                              <1> 	;out	dx, al
  5200                              <1> 
  5201                              <1> 	pop	eax	; ***
  5202                              <1> 
  5203                              <1> 	inc	edx	; dx = hd base port + 7 
  5204                              <1> 			;      command/status port
  5205                              <1> 	;xchg	esi, ebx
  5206                              <1> 	;mov	edi, ebx
  5207                              <1> 	mov	edi, esi ; sector buffer 
  5208                              <1> 	cmp	ah, 1Ch
  5209                              <1> 	jne	short su9
  5210                              <1> 	mov	al, 34h ; WRITE SECTOR(S) EXT
  5211                              <1> 	out	dx, al
  5212                              <1> 	jmp	CMD_WX
  5213                              <1> su9:
  5214                              <1> 	mov	al, 24h	; READ SECTOR(S) EXT
  5215                              <1> 	out	dx, al
  5216                              <1> 	jmp	CMD_RX
  5217                              <1> %else
  5218                              <1> 	; 20/06/2024
  5219 00005214 58                  <1> 	pop	eax	; ***
  5220 00005215 C645F800            <1> 	mov	byte [CMD_BLOCK], 0
  5221 00005219 8845F9              <1> 	mov	[CMD_BLOCK+1], al ; sector count to r/w
  5222 0000521C 894DFA              <1> 	mov	[CMD_BLOCK+2], ecx ; LBA disk sector address
  5223                              <1> 	
  5224                              <1> 	;;;
  5225                              <1> 	; 23/06/2024
  5226 0000521F C605[6C7D0100]FF    <1> 	mov	byte [LBAMode], 0FFh
  5227                              <1> 	;
  5228 00005226 A0[32660000]        <1> 	mov	al, [hf_m_s]
  5229 0000522B C0E004              <1> 	shl	al, 4
  5230                              <1> 	;add	al, 40h
  5231 0000522E 0C40                <1> 	or	al, 40h	
  5232                              <1> 	; al = 40h (for master), 50h (for slave)
  5233 00005230 A2[32660000]        <1> 	mov	[hf_m_s], al	
  5234                              <1> 	;;;
  5235                              <1> 
  5236 00005235 80FC1C              <1> 	cmp	ah, 1Ch
  5237 00005238 7509                <1> 	jne	short su7
  5238                              <1> 	; AH = 1Ch ; TRDOS 386 v2 - INT 33h - LBA WRITE
  5239                              <1> 	; esi = sector buffer
  5240                              <1> 	; 48 bit LBA write
  5241 0000523A C645FE34            <1> 	mov	byte [CMD_BLOCK+6], 34h ; WRITE SECTOR(S) EXT
  5242 0000523E E9DD000000          <1> 	jmp	CMD_WX
  5243                              <1> su7:
  5244                              <1> 	; AH = 1Bh ; TRDOS 386 v2 - INT 33h - LBA READ
  5245 00005243 89F7                <1> 	mov	edi, esi ; sector buffer
  5246                              <1> 	; 48 bit LBA read
  5247 00005245 C645FE24            <1> 	mov	byte [CMD_BLOCK+6], 24h ; READ SECTOR(S) EXT
  5248 00005249 EB79                <1> 	jmp	CMD_RX
  5249                              <1> 	
  5250                              <1> %endif
  5251                              <1> 
  5252                              <1> ; -----------------------------------------------------
  5253                              <1> 
  5254                              <1> ; 09/08/2022
  5255                              <1> ; 07/08/2022
  5256                              <1> ; 17/07/2022
  5257                              <1> ; 16/07/2022 - TRDOS 386 v2.0.5
  5258                              <1> ; 10/07/2022 - Retro UNIX 386 v1.1 (Kernel v0.2.1.5)
  5259                              <1> 
  5260                              <1> ;----------------------------------------
  5261                              <1> ;	RESET THE DISK SYSTEM  (AH=00H) :
  5262                              <1> ;----------------------------------------
  5263                              <1> 
  5264                              <1> ; 18-1-2015 : one controller reset (not other one)
  5265                              <1> 
  5266                              <1> DISK_RESET:
  5267 0000524B FA                  <1> 	cli
  5268 0000524C E4A1                <1> 	in	al, INTB01		; GET THE MASK REGISTER
  5269                              <1> 	;jmp	$+2
  5270                              <1> 	IODELAY
    78 0000524E EB00                <2>  jmp short $+2
    79 00005250 EB00                <2>  jmp short $+2
  5271                              <1> 	;and	al, 0BFh 		; ENABLE FIXED DISK INTERRUPT
  5272 00005252 243F                <1> 	and	al, 3Fh			; 22/12/2014 (IRQ 14 & IRQ 15)
  5273 00005254 E6A1                <1> 	out	INTB01, al
  5274 00005256 FB                  <1> 	sti				; START INTERRUPTS
  5275                              <1> 	; 14/02/2015
  5276                              <1> 	;mov	di, dx
  5277                              <1> 	; 24/12/2021
  5278 00005257 89D7                <1> 	mov	edi, edx	
  5279                              <1> 	; 04/01/2015
  5280                              <1> 	;xor	di,di
  5281                              <1> drst0:
  5282 00005259 B004                <1> 	mov	al, 04h  ; bit 2 - SRST 
  5283                              <1> 	;mov	dx, HF_REG_PORT
  5284 0000525B 668B15[30660000]    <1> 	mov	dx, [HF_REG_PORT]
  5285 00005262 EE                  <1> 	out	dx, al			; RESET
  5286                              <1> ;	mov	cx, 10			; DELAY COUNT
  5287                              <1> ;DRD:	dec	cx
  5288                              <1> ;	jnz	short DRD		; WAIT 4.8 MICRO-SEC
  5289                              <1> 	;mov	cx, 2			; wait for 30 micro seconds	
  5290                              <1>         ;mov	ecx, 2 ; 21/02/2015
  5291                              <1> 	; 10/07/2022
  5292 00005263 29C9                <1> 	sub	ecx, ecx
  5293 00005265 B102                <1> 	mov	cl, 2
  5294 00005267 E86FD1FFFF          <1> 	call    WAITF                   ; (Award Bios 1999 - WAIT_REFRESH,
  5295                              <1>                                         ; 40 micro seconds)
  5296 0000526C A0[597D0100]        <1> 	mov	al, [CONTROL_BYTE]
  5297 00005271 240F                <1> 	and	al, 0Fh			; SET HEAD OPTION
  5298 00005273 EE                  <1> 	out	dx, al			; TURN RESET OFF
  5299 00005274 E85B040000          <1> 	call	NOT_BUSY
  5300 00005279 7514                <1> 	jnz	short DRERR		; TIME OUT ON RESET
  5301 0000527B 668B15[2E660000]    <1> 	mov	dx, [HF_PORT]
  5302 00005282 FEC2                <1> 	inc	dl  ; HF_PORT+1
  5303                              <1> 	; 02/01/2015 - Award BIOS 1999 - AHDSK.ASM
  5304                              <1>         ;mov	cl, 10
  5305                              <1>         ;mov	ecx, 10 ; 21/02/2015
  5306                              <1> 	; 17/07/2022
  5307                              <1> 	;xor	ecx, ecx
  5308 00005284 B10A                <1> 	mov	cl, 10
  5309                              <1> drst1:
  5310 00005286 EC                  <1> 	in	al, dx			; GET RESET STATUS
  5311 00005287 3C01                <1> 	cmp	al, 1
  5312                              <1> 	; 04/01/2015
  5313 00005289 740C                <1> 	jz	short drst2
  5314                              <1> 	;jnz	short DRERR		; BAD RESET STATUS
  5315                              <1>         	; Drive/Head Register - bit 4
  5316                              <1> 	;loop	drst1
  5317                              <1> 	; 17/07/2022
  5318 0000528B FEC9                <1> 	dec	cl
  5319 0000528D 75F7                <1> 	jnz	short drst1
  5320                              <1> DRERR:	
  5321 0000528F C605[577D0100]05    <1> 	mov	byte [DISK_STATUS1], BAD_RESET ; CARD FAILED
  5322 00005296 C3                  <1> 	retn
  5323                              <1> drst2:
  5324                              <1> 	; 14/02/2015
  5325                              <1> 	;mov	dx, di
  5326                              <1> 	; 07/08/2022
  5327 00005297 89FA                <1> 	mov	edx, edi
  5328                              <1> ;drst3:
  5329                              <1> ;	; 05/01/2015
  5330                              <1> ;	shl 	di, 1
  5331                              <1> ;	; 04/01/2015
  5332                              <1> ;	mov	ax, [di+hd_cports]
  5333                              <1> ;	cmp	ax, [HF_REG_PORT]
  5334                              <1> ;	je	short drst4
  5335                              <1> ;	mov	[HF_REG_PORT], ax
  5336                              <1> ;	; 03/01/2015
  5337                              <1> ;	mov	ax, [di+hd_ports]
  5338                              <1> ;       mov     [HF_PORT], ax
  5339                              <1> ;	; 05/01/2014
  5340                              <1> ;	shr	di, 1
  5341                              <1> ;	; 04/01/2015
  5342                              <1> ;	jmp	short drst0	; reset other controller
  5343                              <1> ;drst4:
  5344                              <1> ;	; 05/01/2015
  5345                              <1> ;	shr	di, 1
  5346                              <1> ;	mov	al, [di+hd_dregs]
  5347                              <1> ;	and	al, 10h ; bit 4 only
  5348                              <1> ;	shr	al, 4 ; bit 4  -> bit 0
  5349                              <1> ;	mov	[hf_m_s], al ; (0 = master, 1 = slave)
  5350                              <1> 	;
  5351                              <1> ; 09/08/2022
  5352                              <1> ; (('INIT_DRV' prodedure sets [CMD_BLOCKS+5] value))
  5353                              <1> ;
  5354                              <1> ;	mov	al, [hf_m_s] ; 18/01/2015
  5355                              <1> ;	test	al, 1
  5356                              <1> ;	;jnz	short drst6
  5357                              <1> ;       jnz     short drst4
  5358                              <1> ;	and	byte [CMD_BLOCK+5], 0EFh ; SET TO DRIVE 0
  5359                              <1> ;drst5:
  5360                              <1> drst3:
  5361 00005299 E8F9010000          <1> 	call	INIT_DRV		; SET MAX HEADS
  5362                              <1> 	;mov	dx, di
  5363 0000529E E8C1020000          <1> 	call	HDISK_RECAL		; RECAL TO RESET SEEK SPEED
  5364                              <1> 	; 04/01/2014
  5365                              <1> ;	inc	di
  5366                              <1> ;	mov	dx, di
  5367                              <1> ;	cmp	dl, [HF_NUM]
  5368                              <1> ;	jb	short drst3
  5369                              <1> ;DRE:
  5370 000052A3 C605[577D0100]00    <1> 	mov	byte [DISK_STATUS1], 0 	; IGNORE ANY SET UP ERRORS
  5371 000052AA C3                  <1> 	retn
  5372                              <1> ;drst6:
  5373                              <1> drst4:		; Drive/Head Register - bit 4
  5374                              <1> ;	or	byte [CMD_BLOCK+5], 010h ; SET TO DRIVE 1
  5375                              <1> ;       ;jmp    short drst5
  5376                              <1> ;       jmp     short drst3
  5377                              <1> 
  5378                              <1> ;----------------------------------------
  5379                              <1> ;	DISK STATUS ROUTINE  (AH = 01H) :
  5380                              <1> ;----------------------------------------
  5381                              <1> 
  5382                              <1> RETURN_STATUS:
  5383 000052AB A0[577D0100]        <1> 	mov	al, [DISK_STATUS1]	; OBTAIN PREVIOUS STATUS
  5384 000052B0 C605[577D0100]00    <1> 	mov	byte [DISK_STATUS1], 0	; RESET STATUS
  5385 000052B7 C3                  <1> 	retn
  5386                              <1> 
  5387                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  5388                              <1> 
  5389                              <1> ;----------------------------------------
  5390                              <1> ;	READ LONG	     (AH = 0AH) :
  5391                              <1> ;----------------------------------------
  5392                              <1> 
  5393                              <1> RD_LONG:
  5394                              <1> 	;mov	@CMD_BLOCK+6, READ_CMD OR ECC_MODE
  5395 000052B8 C645FE22            <1> 	mov     byte [CMD_BLOCK+6], READ_CMD + ECC_MODE 
  5396 000052BC EB04                <1> 	jmp	short COMMANDI
  5397                              <1> 
  5398                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  5399                              <1> 
  5400                              <1> ;----------------------------------------
  5401                              <1> ;	DISK READ ROUTINE    (AH = 02H) :
  5402                              <1> ;----------------------------------------
  5403                              <1> 
  5404                              <1> DISK_READ:
  5405 000052BE C645FE20            <1> 	mov	byte [CMD_BLOCK+6], READ_CMD
  5406                              <1>         ;jmp	COMMANDI
  5407                              <1> 
  5408                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  5409                              <1> 
  5410                              <1> ;----------------------------------------
  5411                              <1> ; COMMANDI				:
  5412                              <1> ;	REPEATEDLY INPUTS DATA TILL	:
  5413                              <1> ;	NSECTOR RETURNS ZERO		:
  5414                              <1> ;----------------------------------------
  5415                              <1> COMMANDI:
  5416                              <1> 	; 16/07/2022 
  5417                              <1> 	;	(check 64K boundary is not needed)
  5418                              <1> 	;call	CHECK_DMA		; CHECK 64K BOUNDARY ERROR
  5419                              <1> 	;jc	short CMD_ABORT
  5420                              <1> 
  5421                              <1> 	;mov	di, bx
  5422 000052C2 89DF                <1> 	mov	edi, ebx ; 21/02/2015
  5423                              <1> CMD_RX:
  5424                              <1> 	; 20/06/2024 (48 bit LBA r/w modification)
  5425 000052C4 E821030000          <1> 	call	COMMAND 		; OUTPUT COMMAND
  5426 000052C9 7548                <1> 	jnz	short CMD_ABORT
  5427                              <1> ;CMD_RX: ; 01/12/2023 (48 bit LBA read)
  5428                              <1> CMD_I1:
  5429 000052CB E8D4030000          <1> 	call	_WAIT			; WAIT FOR DATA REQUEST INTERRUPT
  5430 000052D0 7541                <1> 	jnz	short TM_OUT		; TIME OUT
  5431                              <1> cmd_i1x:
  5432                              <1> 	; 18/02/2016
  5433                              <1> 	;;mov	cx, 256			; SECTOR SIZE IN WORDS
  5434                              <1> 	;mov	ecx, 256 ; 21/02/2015	
  5435                              <1> 	; 16/07/2022
  5436 000052D2 29C9                <1> 	sub	ecx, ecx
  5437 000052D4 FEC5                <1> 	inc	ch  ; ecx = 256
  5438                              <1> 	;mov	dh, HF_PORT
  5439 000052D6 668B15[2E660000]    <1> 	mov	dx, [HF_PORT]
  5440 000052DD FA                  <1> 	cli
  5441 000052DE FC                  <1> 	cld
  5442 000052DF F3666D              <1> 	rep	insw			; GET THE SECTOR
  5443 000052E2 FB                  <1> 	sti
  5444                              <1> 
  5445 000052E3 F645FE02            <1> 	test	byte [CMD_BLOCK+6], ECC_MODE ; CHECK FOR NORMAL INPUT
  5446 000052E7 7418                <1> 	jz	short CMD_I3
  5447 000052E9 E80D040000          <1> 	call	WAIT_DRQ		; WAIT FOR DATA REQUEST
  5448 000052EE 7223                <1> 	jc	short TM_OUT
  5449                              <1> 	;mov	dx, HF_PORT
  5450 000052F0 668B15[2E660000]    <1> 	mov	dx, [HF_PORT]
  5451                              <1> 	;;mov	cx, 4			; GET ECC BYTES
  5452                              <1> 	;mov 	ecx, 4 ; mov cx, 4
  5453                              <1> 	; 16/07/2022
  5454 000052F7 31C9                <1>  	xor	ecx, ecx
  5455 000052F9 B104                <1> 	mov	cl, 4
  5456                              <1> CMD_I2:
  5457 000052FB EC                  <1> 	in	al, dx
  5458 000052FC 8807                <1> 	mov 	[edi], al ; 21/02/2015	; GO SLOW FOR BOARD
  5459 000052FE 47                  <1> 	inc	edi
  5460 000052FF E2FA                <1> 	loop	CMD_I2
  5461                              <1> CMD_I3: 
  5462                              <1> 	; wait for 400 ns
  5463 00005301 80C207              <1> 	add 	dl, 7
  5464 00005304 EC                  <1> 	in	al, dx
  5465 00005305 EC                  <1> 	in	al, dx
  5466 00005306 EC                  <1> 	in	al, dx
  5467                              <1> 	;
  5468 00005307 E8E4010000          <1> 	call	CHECK_STATUS
  5469 0000530C 7505                <1> 	jnz	short CMD_ABORT		; ERROR RETURNED
  5470 0000530E FE4DF9              <1> 	dec	byte [CMD_BLOCK+1]	; CHECK FOR MORE
  5471                              <1> 	;jnz	short CMD_I1
  5472 00005311 75BF                <1> 	jnz	short cmd_i1x ; 18/02/2016
  5473                              <1> CMD_ABORT:
  5474                              <1> TM_OUT: 
  5475 00005313 C3                  <1> 	retn
  5476                              <1> 
  5477                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  5478                              <1> 
  5479                              <1> ;----------------------------------------
  5480                              <1> ;	WRITE LONG	     (AH = 0BH) :
  5481                              <1> ;----------------------------------------
  5482                              <1> 
  5483                              <1> WR_LONG:
  5484                              <1> 	;mov	@CMD_BLOCK+6, WRITE_CMD OR ECC_MODE
  5485 00005314 C645FE32            <1> 	mov	byte [CMD_BLOCK+6], WRITE_CMD + ECC_MODE
  5486 00005318 EB04                <1> 	jmp	short COMMANDO
  5487                              <1> 
  5488                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  5489                              <1> 	
  5490                              <1> ;----------------------------------------
  5491                              <1> ;	DISK WRITE ROUTINE   (AH = 03H) :
  5492                              <1> ;----------------------------------------
  5493                              <1> 
  5494                              <1> DISK_WRITE:
  5495 0000531A C645FE30            <1> 	mov	byte [CMD_BLOCK+6], WRITE_CMD
  5496                              <1> 	;jmp	COMMANDO
  5497                              <1> 
  5498                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  5499                              <1> 
  5500                              <1> ;----------------------------------------
  5501                              <1> ; COMMANDO				:
  5502                              <1> ;	REPEATEDLY OUTPUTS DATA TILL	:
  5503                              <1> ;	NSECTOR RETURNS ZERO		:
  5504                              <1> ;----------------------------------------
  5505                              <1> COMMANDO:
  5506                              <1> 	; 16/07/2022 
  5507                              <1> 	;	(check 64K boundary is not needed)
  5508                              <1> 	;call	CHECK_DMA		; CHECK 64K BOUNDARY ERROR
  5509                              <1> 	;jc	short CMD_ABORT
  5510                              <1> CMD_OF: 
  5511 0000531E 89DE                <1> 	mov	esi, ebx ; 21/02/2015
  5512                              <1> CMD_WX:
  5513                              <1> 	; 20/06/2024 (48 bit LBA r/w modification)
  5514 00005320 E8C5020000          <1> 	call	COMMAND 		; OUTPUT COMMAND
  5515 00005325 75EC                <1> 	jnz	short CMD_ABORT
  5516                              <1> ;CMD_WX:	; 01/12/2023 (48 bit LBA write)
  5517 00005327 E8CF030000          <1> 	call	WAIT_DRQ		; WAIT FOR DATA REQUEST
  5518 0000532C 72E5                <1> 	jc	short TM_OUT		; TOO LONG
  5519                              <1> CMD_O1: 
  5520                              <1> 	; 16/07/2022
  5521 0000532E 668B15[2E660000]    <1> 	mov	dx, [HF_PORT]
  5522                              <1> 
  5523                              <1> 	;mov	ecx, 256 ; 21/02/2015
  5524 00005335 31C9                <1> 	xor	ecx, ecx
  5525 00005337 FEC5                <1> 	inc	ch
  5526                              <1> 	; ecx = 256
  5527 00005339 FA                  <1> 	cli
  5528 0000533A FC                  <1> 	cld
  5529                              <1> 	;rep	outsw
  5530                              <1> 	; 01/12/2023 - TRDOS 386 v2.0.7
  5531                              <1> CMD_01_L:	
  5532 0000533B 666F                <1> 	outsw
  5533 0000533D EB00                <1> 	jmp	$+2
  5534 0000533F E2FA                <1> 	loop	CMD_01_L
  5535                              <1> 
  5536 00005341 FB                  <1> 	sti
  5537                              <1> 
  5538 00005342 F645FE02            <1> 	test	byte [CMD_BLOCK+6], ECC_MODE ; CHECK FOR NORMAL OUTPUT
  5539 00005346 7418                <1> 	jz	short CMD_O3
  5540 00005348 E8AE030000          <1> 	call	WAIT_DRQ		; WAIT FOR DATA REQUEST
  5541 0000534D 72C4                <1> 	jc	short TM_OUT
  5542                              <1> 	;mov	dx, HF_PORT
  5543 0000534F 668B15[2E660000]    <1> 	mov	dx, [HF_PORT]
  5544                              <1> 					; OUTPUT THE ECC BYTES
  5545                              <1> 	;mov	ecx, 4  ; mov cx, 4
  5546                              <1> 	; 16/07/2022
  5547 00005356 29C9                <1> 	sub	ecx, ecx
  5548 00005358 B104                <1> 	mov	cl, 4
  5549                              <1> CMD_O2:
  5550 0000535A 8A06                <1> 	mov	al, [esi]
  5551 0000535C EE                  <1> 	out	dx, al
  5552 0000535D 46                  <1> 	inc	esi
  5553 0000535E E2FA                <1> 	loop	CMD_O2
  5554                              <1> CMD_O3:
  5555 00005360 E83F030000          <1> 	call	_WAIT			; WAIT FOR SECTOR COMPLETE INTERRUPT
  5556 00005365 75AC                <1> 	jnz	short TM_OUT		; ERROR RETURNED
  5557 00005367 E884010000          <1> 	call	CHECK_STATUS
  5558 0000536C 75A5                <1> 	jnz	short CMD_ABORT
  5559 0000536E F605[517D0100]08    <1> 	test	byte [HF_STATUS], ST_DRQ ; CHECK FOR MORE
  5560 00005375 75B7                <1> 	jnz	short CMD_O1
  5561                              <1> 	;mov	dx, HF_PORT+2		; CHECK RESIDUAL SECTOR COUNT
  5562 00005377 668B15[2E660000]    <1> 	mov	dx, [HF_PORT]
  5563 0000537E 80C202              <1> 	add	dl, 2
  5564                              <1> 	;inc	dl
  5565                              <1> 	;inc	dl
  5566 00005381 EC                  <1> 	in	al, dx			;
  5567 00005382 A8FF                <1> 	test	al, 0FFh 		;
  5568 00005384 7407                <1> 	jz	short CMD_O4		; COUNT = 0 OK
  5569 00005386 C605[577D0100]BB    <1> 	mov	byte [DISK_STATUS1], UNDEF_ERR 
  5570                              <1> 					; OPERATION ABORTED - PARTIAL TRANSFER
  5571                              <1> CMD_O4:
  5572 0000538D C3                  <1> 	retn
  5573                              <1> 
  5574                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  5575                              <1> 
  5576                              <1> ;----------------------------------------
  5577                              <1> ;	FORMATTING	     (AH = 05H) :
  5578                              <1> ;----------------------------------------
  5579                              <1> 
  5580                              <1> FMT_TRK:				; FORMAT TRACK (AH = 005H)
  5581 0000538E C645FE50            <1> 	mov	byte [CMD_BLOCK+6], FMTTRK_CMD
  5582                              <1> 	;push	es
  5583                              <1> 	;push	bx
  5584 00005392 53                  <1> 	push	ebx
  5585 00005393 E8F1030000          <1> 	call	GET_VEC 		; GET DISK PARAMETERS ADDRESS
  5586                              <1> 	;mov	al, [ES:BX+14]		; GET SECTORS/TRACK
  5587 00005398 8A430E              <1> 	mov	al, [ebx+14]
  5588 0000539B 8845F9              <1> 	mov	[CMD_BLOCK+1], al	; SET SECTOR COUNT IN COMMAND
  5589 0000539E 5B                  <1> 	pop	ebx
  5590                              <1> 	;pop	bx
  5591                              <1> 	;pop	es
  5592                              <1> 	;jmp	short CMD_OF		; GO EXECUTE THE COMMAND
  5593                              <1> 	; 01/12/2023
  5594 0000539F E97AFFFFFF          <1> 	jmp	CMD_OF
  5595                              <1> 
  5596                              <1> ;----------------------------------------
  5597                              <1> ;	DISK VERIFY	     (AH = 04H) :
  5598                              <1> ;----------------------------------------
  5599                              <1> 
  5600                              <1> DISK_VERF:
  5601 000053A4 C645FE40            <1> 	mov	byte [CMD_BLOCK+6], VERIFY_CMD
  5602 000053A8 E83D020000          <1> 	call	COMMAND
  5603 000053AD 750C                <1> 	jnz	short VERF_EXIT		; CONTROLLER STILL BUSY
  5604 000053AF E8F0020000          <1> 	call	_WAIT			; (Original: CALL WAIT)	
  5605 000053B4 7505                <1> 	jnz	short VERF_EXIT		; TIME OUT
  5606 000053B6 E835010000          <1> 	call	CHECK_STATUS
  5607                              <1> VERF_EXIT:
  5608 000053BB C3                  <1> 	retn
  5609                              <1> 
  5610                              <1> ;----------------------------------------
  5611                              <1> ;	READ DASD TYPE	     (AH = 15H) :
  5612                              <1> ;----------------------------------------
  5613                              <1> 
  5614                              <1> RETURN_DRIVE_TYPE:
  5615                              <1> 	; 10/08/2022
  5616                              <1> 	; 13/07/2022
  5617                              <1> 	; (Ref: Programmer's Guide to the AMIBIOS -Page 214-, 1992)
  5618                              <1> 	;
  5619                              <1> 	; INPUT:
  5620                              <1> 	;	DL = Disk number (>= 80h)
  5621                              <1> 	;   TRDOS 386 v2.0.5 Feature:
  5622                              <1> 	;	If AL = 0FFh, return disk size in ECX
  5623                              <1> 	;		otherwise in CX:DX
  5624                              <1> 	; OUTPUT:
  5625                              <1> 	;	AH = 00h - No drive present
  5626                              <1> 	;	   = 03h - Hard disk drive
  5627                              <1> 	;	CF = 0 - No error
  5628                              <1> 	;	   = 1 - Error  	 
  5629                              <1> 	;   TRDOS 386 v2.0.5 Feature:
  5630                              <1> 	;	AL = 00h - LBA not ready !	
  5631                              <1> 	;	   = 01h - LBA ready 
  5632                              <1> 	;		(28 bit or 48 bit LBA r/w depending
  5633                              <1> 	;		on disk size in CX:DX)
  5634                              <1> 	;	CX:DX = Number of 512 byte sectors
  5635                              <1> 	;
  5636                              <1> 	; (Note: High words of ECX and EDX will be zero at return)
  5637                              <1> 	; ((If AL input is 0FFh, disk size will be in ECX only))
  5638                              <1> 
  5639                              <1> READ_DASD_TYPE:
  5640                              <1> READ_D_T:				; GET DRIVE PARAMETERS
  5641                              <1> 	;push	ds			; SAVE REGISTERS
  5642                              <1> 	
  5643                              <1> 	;;push	es
  5644                              <1> 	; 18/04/2021
  5645                              <1> 	;push	ebx
  5646                              <1> 	;;call	DDS			; ESTABLISH ADDRESSING
  5647                              <1> 	;;push	cs
  5648                              <1> 	;;pop	ds
  5649                              <1>         
  5650                              <1> 	; 18/04/2021
  5651                              <1> 	;mov	bx, KDATA
  5652                              <1> 	;mov	ds, bx
  5653                              <1> 	;;mov	es, bx
  5654                              <1> 	;mov	byte [DISK_STATUS1], 0
  5655                              <1> 	;mov	bl, [HF_NUM]		; GET NUMBER OF DRIVES
  5656                              <1> 	;and	dl, 7Fh			; GET DRIVE NUMBER
  5657                              <1> 	;cmp	bl, dl
  5658                              <1> 	;jbe	short RDT_NOT_PRESENT 	; RETURN DRIVE NOT PRESENT
  5659                              <1> 	
  5660                              <1> 	;mov	ax, KDATA
  5661                              <1> 	;mov	ds, ax
  5662                              <1> 	
  5663 000053BC C605[577D0100]00    <1> 	mov	byte [DISK_STATUS1], 0
  5664 000053C3 8A0D[587D0100]      <1> 	mov	cl, [HF_NUM]
  5665 000053C9 80E27F              <1> 	and	dl, 7Fh
  5666 000053CC 38D1                <1> 	cmp	cl, dl
  5667 000053CE 7631                <1> 	jbe	short RDT_NOT_PRESENT
  5668                              <1> 
  5669                              <1> 	; 18/04/2021 - TRDOS 386 v2.0.4
  5670                              <1> 	
  5671                              <1> 	;call	GET_VEC 		; GET DISK PARAMETER ADDRESS
  5672                              <1> 	;
  5673                              <1> 	;;mov	al, [ES:BX+2]		; HEADS
  5674                              <1> 	;mov	al, [ebx+2]  ; heads (logical)
  5675                              <1> 	;;;mov	cl, [ES:BX+14]
  5676                              <1> 	;;mov	cl, [ebx+14]
  5677                              <1> 	;; 17/04/2021
  5678                              <1> 	;mov	ah, [ebx+14] ; sectors per track (logical)
  5679                              <1> 	;;imul	cl			; * NUMBER OF SECTORS
  5680                              <1> 	;;mov	cx, [ES:BX]		; MAX NUMBER OF CYLINDERS
  5681                              <1> 	;mov	cx, [ebx]    ; cylinders (logical)
  5682                              <1> 	;; 02/01/2015 
  5683                              <1> 	;; ** leave the last cylinder as reserved for diagnostics **
  5684                              <1> 	;; (Also in Award BIOS - 1999, AHDSK.ASM, FUN15 -> sub ax, 1)
  5685                              <1> 	;dec	cx			; LEAVE ONE FOR DIAGNOSTICS
  5686                              <1> 	;;imul	cx			; NUMBER OF SECTORS	 	
  5687                              <1> 	;; 17/04/2021
  5688                              <1> 	;mul	ah
  5689                              <1> 	;; ax = spt*heads
  5690                              <1> 	;mul	cx	 
  5691                              <1> 	;; dx:ax = number of sectors
  5692                              <1> 	;
  5693                              <1> 	;mov	cx, dx			; HIGH ORDER HALF
  5694                              <1> 	;mov	dx, ax			; LOW ORDER HALF
  5695                              <1> 
  5696                              <1> 	; 18/04/2021
  5697 000053D0 B102                <1> 	mov	cl, 2
  5698 000053D2 00CA                <1> 	add	dl, cl ; hd0 = 2
  5699                              <1> 
  5700                              <1> 	; 13/07/2022
  5701 000053D4 0FB6D2              <1> 	movzx	edx, dl
  5702 000053D7 8A9A[5E660000]      <1> 	mov	bl, [edx+drv.status]
  5703 000053DD 80E301              <1> 	and	bl, 1 ; LBA ready bit (bit 0) 
  5704                              <1> 
  5705 000053E0 D2E2                <1> 	shl	dl, cl ; * 4
  5706                              <1> 	
  5707                              <1> 	;mov	eax, [edx+drv.size]
  5708                              <1> 	;mov	dx, ax
  5709                              <1> 	;shr	eax, 16
  5710                              <1> 	;mov	cx, ax
  5711                              <1> 
  5712 000053E2 8B8A[42660000]      <1> 	mov	ecx, [edx+drv.size]
  5713                              <1> 
  5714                              <1> 	; 13/07/2022
  5715                              <1> 	;cmp	al, 0FFh   ; return disk size in ecx ?
  5716                              <1> 	;je	short RDT1 ; yes
  5717 000053E8 FEC0                <1> 	inc	al  ; 0FFh -> 0
  5718 000053EA 740A                <1> 	jz	short RDT1
  5719                              <1> 
  5720 000053EC 6689CA              <1> 	mov	dx, cx
  5721 000053EF C1E910              <1> 	shr	ecx, 16
  5722                              <1> 
  5723                              <1> 	; 13/07/2022
  5724                              <1> 	; ebx = esp+20
  5725                              <1> 	; ecx = esp+16
  5726                              <1> 	; edx = esp+12
  5727                              <1> 	; esi = esp+8
  5728                              <1> 	; edi = esp+4
  5729                              <1> 
  5730                              <1> 	; return disk size in user's registers
  5731 000053F2 8954240C            <1> 	mov	[esp+12], edx
  5732                              <1> 	; cx:dx = disk size
  5733                              <1> RDT1:
  5734                              <1> 	;mov	[esp+16], ecx
  5735                              <1> 
  5736                              <1> 	;;sub	al, al
  5737 000053F6 29C0                <1> 	sub	eax, eax
  5738 000053F8 B403                <1> 	mov	ah, 03h			; INDICATE FIXED DISK
  5739 000053FA 88D8                <1> 	mov	al, bl
  5740                              <1> 	; al = 1 -> LBA r/w ready/applicable
  5741                              <1> 	;    = 0 -> LBA r/w not ready/applicable	 
  5742                              <1> 	; cf = 0
  5743                              <1> RDT2:
  5744 000053FC 894C2410            <1> 	mov	[esp+16], ecx	
  5745                              <1> ;RDT2:
  5746                              <1> 	; 13/07/2022
  5747                              <1> 	; 18/04/2021
  5748                              <1> 	;pop	ebx			; RESTORE REGISTERS
  5749                              <1> 	;;pop	es
  5750                              <1> 	;pop	ds
  5751                              <1> 	; (*) clc			; CLEAR CARRY
  5752                              <1> 	;retf	2
  5753                              <1> 	; (*) 29/05/2016
  5754                              <1> 	; (*) retf 4
  5755                              <1> 	;and	byte [esp+8], 0FEh ; clear carry bit of eflags register
  5756                              <1> 	;iretd
  5757                              <1> 
  5758                              <1> 	; 13/07/2022
  5759                              <1> 	; [DISK_STATUS1] = 0
  5760                              <1> 	; ah = 3
  5761                              <1> 	; al = 0 or 1 (LBA ready)
  5762                              <1> 	; cf = 0	
  5763                              <1> 	
  5764 00005400 C3                  <1> 	retn
  5765                              <1> 
  5766                              <1> RDT_NOT_PRESENT:
  5767                              <1> 	;;sub	ax, ax			; DRIVE NOT PRESENT RETURN
  5768                              <1> 	;; 18/04/2021
  5769                              <1> 	;sub	eax, eax
  5770                              <1> 	;;mov	cx, ax			; ZERO BLOCK COUNT
  5771                              <1> 	;;mov	dx, ax
  5772                              <1> 	;mov	ecx, eax
  5773                              <1> 	;mov	edx, eax
  5774                              <1> 	;jmp	short RDT2
  5775                              <1> 	; 13/07/2022
  5776 00005401 29C9                <1> 	sub	ecx, ecx
  5777 00005403 88C1                <1> 	mov	cl, al ; if AL = 0FFh, disk size will be in ECX
  5778                              <1> 		       ; if not, disk size will be in CX:DX 
  5779 00005405 29C0                <1> 	sub	eax, eax
  5780 00005407 FEC1                <1> 	inc	cl ; 0FFh -> 0
  5781 00005409 80F901              <1> 	cmp	cl, 1
  5782 0000540C 72EE                <1> 	jb	short RDT2 ; ecx = 0
  5783                              <1> 	; 10/08/2022
  5784 0000540E 28C9                <1> 	sub	cl, cl
  5785                              <1> 	; ecx = 0
  5786 00005410 8944240C            <1> 	mov	[esp+12], eax ; edx = 0
  5787 00005414 F9                  <1> 	stc
  5788 00005415 EBE5                <1> 	jmp	short RDT2 ; cf = 1, eax = 0	
  5789                              <1> 
  5790                              <1> ; 10/08/2022
  5791                              <1> ; 07/08/2022
  5792                              <1> ; 13/07/2022 - TRDOS 386 v2.0.5
  5793                              <1> ; 28/05/2016
  5794                              <1> ; 27/05/2016 - TRDOS 386 (TRDOS v2.0)
  5795                              <1> 
  5796                              <1> ;----------------------------------------
  5797                              <1> ;	GET PARAMETERS	     (AH = 08H) :
  5798                              <1> ;----------------------------------------
  5799                              <1> 
  5800                              <1> GET_PARM_N:
  5801                              <1> 	; ebx = user's buffer address for parameters table
  5802                              <1> 	; 10/08/2022
  5803                              <1> 	; 13/07/2022
  5804                              <1> 	; (if ebx = 0, HDPT will not be returned to user)
  5805                              <1> 	;	
  5806                              <1> ;GET_PARM:				; GET DRIVE PARAMETERS
  5807                              <1> 	;push	ds			; SAVE REGISTERS
  5808                              <1> 	;push	es
  5809                              <1> 	
  5810                              <1> 	;push	ebx
  5811 00005417 89DF                <1> 	mov	edi, ebx ; 13/07/2022 	
  5812                              <1> 
  5813                              <1> 	; 13/07/2022
  5814                              <1> 	; ((IBM PC XT-286 ROM BIOS source code remainders))
  5815                              <1> 	;;mov	ax, ABS0 		; ESTABLISH ADDRESSING
  5816                              <1> 	;;mov	ds, ax
  5817                              <1> 	
  5818                              <1> 	;;test	dl, 1			; CHECK FOR DRIVE 1
  5819                              <1> 	;;jz	short G0
  5820                              <1> 	;;les	bx, @HF1_TBL_VEC
  5821                              <1> 	;;jmp	short G1
  5822                              <1> ;;G0:	
  5823                              <1> 	;les	bx, @HF_TBL_VEC
  5824                              <1> ;;G1:
  5825                              <1> 	;;call	DDS			; ESTABLISH SEGMENT
  5826                              <1> 	
  5827                              <1> 	; 13/07/2022
  5828                              <1> 	; 22/12/2014
  5829                              <1> 	;;push	cs
  5830                              <1> 	;;pop	ds
  5831                              <1> 	;mov	bx, KDATA
  5832                              <1> 	;mov	ds, bx
  5833                              <1> 	;mov	es, bx	; 27/05/2016
  5834                              <1> 	;
  5835                              <1> 	; 18/04/2021
  5836 00005419 29C9                <1> 	sub	ecx, ecx
  5837                              <1> 	;
  5838 0000541B 80EA80              <1> 	sub	dl, 80h
  5839 0000541E 80FA04              <1> 	cmp	dl, MAX_FILE		; TEST WITHIN RANGE
  5840 00005421 7344                <1> 	jae	short G2 ; 13/07/2022
  5841                              <1> 	;
  5842                              <1>  	; 21/02/2015
  5843 00005423 31DB                <1> 	xor	ebx, ebx
  5844                              <1> 	; 18/04/2021
  5845                              <1> 	;sub	ecx, ecx
  5846                              <1> 	; 22/12/2014
  5847 00005425 88D3                <1> 	mov	bl, dl
  5848                              <1> 	;xor	bh, bh  
  5849 00005427 C0E302              <1> 	shl	bl, 2			; convert index to offset
  5850                              <1> 	;add	bx, HF_TBL_VEC
  5851 0000542A 81C3[5C7D0100]      <1> 	add	ebx, HF_TBL_VEC
  5852                              <1> 	;mov	ax, [bx+2]
  5853                              <1> 	;mov	es, ax			; dpt segment
  5854                              <1> 	;mov	bx, [bx]		; dpt offset
  5855 00005430 8B1B                <1> 	mov	ebx, [ebx] ; 32 bit offset	
  5856                              <1> 	; 18/04/2021
  5857 00005432 29D2                <1> 	sub	edx, edx
  5858 00005434 8815[577D0100]      <1>  	mov	[DISK_STATUS1], dl ; 0
  5859                              <1> 
  5860                              <1> 	;mov	byte [DISK_STATUS1], 0
  5861                              <1>         ;mov	ax, [ES:BX]		; MAX NUMBER OF CYLINDERS
  5862 0000543A 668B03              <1> 	mov	ax, [ebx]
  5863                              <1> 	;;sub	ax, 2			; ADJUST FOR 0-N
  5864 0000543D 6648                <1> 	dec	ax			; max. cylinder number
  5865 0000543F 88C5                <1> 	mov	ch, al
  5866 00005441 66250003            <1> 	and	ax, 0300h		; HIGH TWO BITS OF CYLINDER
  5867                              <1> 	;shr	ax, 1
  5868                              <1> 	;shr	ax, 1
  5869                              <1> 	; 13/07/2022
  5870                              <1> 	;shr	ax, 2
  5871                              <1> 	; 07/08/2022
  5872 00005445 C1E802              <1> 	shr	eax, 2
  5873                              <1> 	;or	al, [ES:BX+14]		; SECTORS
  5874 00005448 0A430E              <1> 	or	al, [ebx+14]
  5875 0000544B 88C1                <1> 	mov	cl, al
  5876                              <1> 	;mov	dh, [ES:BX+2]		; HEADS
  5877 0000544D 8A7302              <1> 	mov	dh, [ebx+2]
  5878 00005450 FECE                <1> 	dec	dh			; 0-N RANGE
  5879 00005452 8A15[587D0100]      <1> 	mov	dl, [HF_NUM]		; DRIVE COUNT
  5880                              <1> 	;;sub	ax, ax
  5881                              <1> 	; 18/04/2021
  5882                              <1> 	;sub	eax, eax
  5883                              <1> 
  5884                              <1> 	; 27/12/2014 
  5885                              <1> 	;mov	di, bx			; HDPT offset
  5886                              <1> 
  5887                              <1> 	; 13/07/2022
  5888                              <1> 	; ebx = esp+20
  5889                              <1> 	; ecx = esp+16
  5890                              <1> 	; edx = esp+12
  5891                              <1> 	; esi = esp+8
  5892                              <1> 	; edi = esp+4
  5893                              <1> 
  5894                              <1> 	; 13/07/2022
  5895                              <1> 	; set return register contents/values
  5896 00005458 894C2410            <1> 	mov	[esp+16], ecx
  5897 0000545C 8954240C            <1> 	mov	[esp+12], edx
  5898                              <1> 
  5899                              <1> 	; is hard disk parameters table requested ?
  5900 00005460 09FF                <1> 	or	edi, edi ; (edi = [ebp+24] = ebx)
  5901 00005462 751B                <1> 	jnz	short G3 ; yes
  5902                              <1> 
  5903 00005464 29C0                <1> 	sub	eax, eax	
  5904                              <1> 
  5905                              <1> 	; [DISK_STATUS1] = 0
  5906                              <1> 	; eax = 0
  5907                              <1> 	; cf = 0
  5908                              <1> 
  5909 00005466 C3                  <1> 	retn
  5910                              <1> 
  5911                              <1> G2:
  5912                              <1> 	;mov	ah, INIT_FAIL
  5913                              <1> 	;mov	byte [DISK_STATUS1], ah ; (INIT_FAIL)
  5914                              <1> 	;				; OPERATION FAILED
  5915                              <1> 	;sub	al, al
  5916                              <1> 	;sub	dx, dx
  5917                              <1> 	;sub	cx, cx
  5918                              <1> 	; 18/04/2021
  5919 00005467 29C0                <1> 	sub	eax, eax
  5920 00005469 B407                <1> 	mov	ah, INIT_FAIL
  5921 0000546B 8825[577D0100]      <1> 	mov     [DISK_STATUS1], ah	; OPERATION FAILED
  5922                              <1> 
  5923                              <1> 	; 13/07/2022
  5924                              <1> 	;sub	edx, edx
  5925                              <1> 	;sub	ecx, ecx
  5926                              <1> 	; ecx = 0
  5927 00005471 894C240C            <1> 	mov	[esp+12], ecx ; 0 ; edx (heads-1, drive count)
  5928 00005475 894C2410            <1> 	mov	[esp+16], ecx ; 0 ; ecx (cylinders-1, sectors)
  5929 00005479 894C2414            <1> 	mov	[esp+20], ecx ; 0 ; ebx (HDPT address)
  5930                              <1> 
  5931 0000547D F9                  <1> 	stc
  5932 0000547E C3                  <1> 	retn
  5933                              <1> 
  5934                              <1> 	; 13/07/2022
  5935                              <1> 	; 29/05/2016 (*)
  5936                              <1> 	;;stc				; SET ERROR FLAG
  5937                              <1> 	;;jmp	short G5
  5938                              <1> 	;jmp	short _G6
  5939                              <1> 
  5940                              <1> G3:	
  5941                              <1> 	; 27/05/2016
  5942                              <1> 	; return fixed disk parameters table to user
  5943                              <1> 	; in user's buffer, which is pointed by EBX
  5944                              <1> 	
  5945                              <1> 	;xchg	edi, [esp]		; ebx (input)-> edi, edi -> [esp]
  5946                              <1> 	; 13/07/2022
  5947                              <1> 	;pop	edi
  5948                              <1> 	; edi = user's buffer address
  5949                              <1> 	;push	esi
  5950 0000547F 89DE                <1> 	mov	esi, ebx		; hard disk parameter table (32 bytes)	
  5951                              <1> 	;mov	ebx, edi		; ebx = user's buffer address
  5952 00005481 51                  <1> 	push	ecx
  5953                              <1> 	;push	eax
  5954                              <1> 	;mov	ecx, 32 ; 32 bytes
  5955 00005482 30ED                <1> 	xor	ch, ch
  5956 00005484 B120                <1> 	mov	cl, 32
  5957                              <1> 	; ecx = 32
  5958 00005486 E805BB0000          <1> 	call	transfer_to_user_buffer ; trdosk6.s (16/05/2016)
  5959                              <1> 	;pop	eax
  5960 0000548B 59                  <1> 	pop	ecx
  5961                              <1> 	; 10/08/2022
  5962                              <1> 	;pop	esi
  5963                              <1> 	;pop	edi
  5964 0000548C 7306                <1> 	jnc	short G4
  5965                              <1> 	; 29/05/2016 (*)
  5966 0000548E B8FF000000          <1> 	mov	eax, 0FFh ; unknown error !
  5967                              <1> 	; [DISK_STATUS1] = 0
  5968                              <1> 	; ah = 0, al = 0FFh
  5969                              <1> 	; cf = 1
  5970                              <1> 	
  5971 00005493 C3                  <1> 	retn
  5972                              <1> ;_G6:
  5973                              <1> 	;or	byte [esp+16], 1 ; set carry bit of eflags register
  5974                              <1> ;G5:
  5975                              <1> 	; 27/05/2016
  5976                              <1> 	;pop	ebx			; RESTORE REGISTERS
  5977                              <1> 	;pop	es
  5978                              <1> 	;pop	ds
  5979                              <1> 	;;retf	2
  5980                              <1> 	; (*) 29/05/2016
  5981                              <1> 	; (*) retf 4
  5982                              <1> 	; (*) or byte [esp+8], 1 ; set carry bit of eflags register
  5983                              <1> 	;iretd
  5984                              <1> 
  5985                              <1> G4:
  5986                              <1> 	; 13/07/2022
  5987 00005494 31C0                <1> 	xor	eax, eax
  5988                              <1> 
  5989                              <1> 	; [user_buffer] = [ebp+24] = HDPT
  5990                              <1> 	; [DISK_STATUS1] = 0
  5991                              <1> 	; eax = 0
  5992                              <1> 	; cf = 0
  5993                              <1> 
  5994 00005496 C3                  <1> 	retn
  5995                              <1> 
  5996                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  5997                              <1> 	
  5998                              <1> ;----------------------------------------
  5999                              <1> ;	INITIALIZE DRIVE     (AH = 09H) :
  6000                              <1> ;----------------------------------------
  6001                              <1> 	; 03/01/2015
  6002                              <1> 	; According to ATA-ATAPI specification v2.0 to v5.0
  6003                              <1> 	; logical sector per logical track
  6004                              <1> 	; and logical heads - 1 would be set but
  6005                              <1> 	; it is seen as it will be good
  6006                              <1> 	; if physical parameters will be set here
  6007                              <1> 	; because, number of heads <= 16.
  6008                              <1> 	; (logical heads usually more than 16)
  6009                              <1> 	; NOTE: ATA logical parameters (software C, H, S)
  6010                              <1> 	;	== INT 13h physical parameters
  6011                              <1> 
  6012                              <1> ;INIT_DRV:
  6013                              <1> ;	mov	byte [CMD_BLOCK+6], SET_PARM_CMD
  6014                              <1> ;	call	GET_VEC 		; ES:BX -> PARAMETER BLOCK
  6015                              <1> ;	mov	al, [es:bx+2]		; GET NUMBER OF HEADS
  6016                              <1> ;	dec	al			; CONVERT TO 0-INDEX
  6017                              <1> ;	mov	ah, [CMD_BLOCK+5] 	; GET SDH REGISTER
  6018                              <1> ;	and	ah, 0F0h 		; CHANGE HEAD NUMBER
  6019                              <1> ;	or	ah, al			; TO MAX HEAD
  6020                              <1> ;	mov	[CMD_BLOCK+5], ah
  6021                              <1> ;	mov	al, [es:bx+14]		; MAX SECTOR NUMBER
  6022                              <1> ;	mov	[CMD_BLOCK+1], al
  6023                              <1> ;	sub	ax, ax
  6024                              <1> ;	mov	[CMD_BLOCK+3], al 	; ZERO FLAGS
  6025                              <1> ;	call	COMMAND 		; TELL CONTROLLER
  6026                              <1> ;	jnz	short INIT_EXIT		; CONTROLLER BUSY ERROR
  6027                              <1> ;	call	NOT_BUSY		; WAIT FOR IT TO BE DONE
  6028                              <1> ;	jnz	short INIT_EXIT		; TIME OUT
  6029                              <1> ;	call	CHECK_STATUS
  6030                              <1> ;INIT_EXIT:
  6031                              <1> ;	retn
  6032                              <1> 
  6033                              <1> ; 16/07/2022 - TRDOS 386 v2.0.5
  6034                              <1> 
  6035                              <1> ; 04/01/2015
  6036                              <1> ; 02/01/2015 - Derived from from AWARD BIOS 1999
  6037                              <1> ;				 AHDSK.ASM - INIT_DRIVE
  6038                              <1> INIT_DRV:
  6039                              <1> 	;xor	ah,ah
  6040 00005497 31C0                <1> 	xor	eax, eax ; 21/02/2015
  6041 00005499 B00B                <1> 	mov	al, 11 ; Physical heads from translated HDPT
  6042 0000549B 3825[6C7D0100]      <1>         cmp     [LBAMode], ah   ; 0
  6043 000054A1 7702                <1> 	ja	short idrv0
  6044 000054A3 B002                <1> 	mov	al, 2  ; Physical heads from standard HDPT
  6045                              <1> idrv0:
  6046                              <1> 	; DL = drive number (0 based)
  6047 000054A5 E8DF020000          <1> 	call	GET_VEC
  6048                              <1> 	;push	bx
  6049 000054AA 53                  <1> 	push	ebx ; 21/02/2015
  6050                              <1> 	;add	bx, ax
  6051 000054AB 01C3                <1> 	add	ebx, eax
  6052                              <1> 	;; 05/01/2015
  6053 000054AD 8A25[32660000]      <1> 	mov	ah, [hf_m_s] ; drive number (0= master, 1= slave)
  6054                              <1> 	;;and 	ah, 1 
  6055 000054B3 C0E404              <1> 	shl	ah, 4
  6056 000054B6 80CCA0              <1> 	or	ah, 0A0h  ; Drive/Head register - 10100000b (A0h)	
  6057                              <1> 	;mov	al, [es:bx]
  6058 000054B9 8A03                <1> 	mov	al, [ebx] ; 21/02/2015
  6059 000054BB FEC8                <1> 	dec	al	 ; last head number 
  6060                              <1> 	;and	al, 0Fh
  6061 000054BD 08E0                <1> 	or	al, ah	 ; lower 4 bits for head number
  6062                              <1> 	;
  6063 000054BF C645FE91            <1> 	mov	byte [CMD_BLOCK+6], SET_PARM_CMD
  6064 000054C3 8845FD              <1> 	mov	[CMD_BLOCK+5], al
  6065                              <1> 	;pop	bx
  6066 000054C6 5B                  <1> 	pop	ebx
  6067 000054C7 29C0                <1> 	sub	eax, eax ; 21/02/2015
  6068 000054C9 B004                <1> 	mov	al, 4	; Physical sec per track from translated HDPT
  6069 000054CB 803D[6C7D0100]00    <1> 	cmp	byte [LBAMode], 0
  6070 000054D2 7702                <1> 	ja	short idrv1
  6071 000054D4 B00E                <1> 	mov	al, 14	; Physical sec per track from standard HDPT
  6072                              <1> idrv1:
  6073                              <1> 	;xor	ah, ah
  6074                              <1> 	;add	bx, ax
  6075 000054D6 01C3                <1> 	add	ebx, eax ; 21/02/2015
  6076                              <1> 	;mov	al, [es:bx]
  6077                              <1> 			; sector number
  6078 000054D8 8A03                <1> 	mov	al, [ebx]
  6079 000054DA 8845F9              <1> 	mov	[CMD_BLOCK+1], al
  6080 000054DD 28C0                <1> 	sub	al, al
  6081 000054DF 8845FB              <1> 	mov	[CMD_BLOCK+3], al ; ZERO FLAGS
  6082 000054E2 E803010000          <1> 	call	COMMAND 	  ; TELL CONTROLLER
  6083 000054E7 751E                <1> 	jnz	short INIT_EXIT	  ; CONTROLLER BUSY ERROR
  6084 000054E9 E8E6010000          <1> 	call	NOT_BUSY	  ; WAIT FOR IT TO BE DONE
  6085 000054EE 7517                <1> 	jnz	short INIT_EXIT	  ; TIME OUT
  6086                              <1> 	; 16/07/2022
  6087                              <1> 	;call	CHECK_STATUS
  6088                              <1> 	;jmp	short CHECK_STATUS
  6089                              <1> ;INIT_EXIT:
  6090                              <1> 	;retn
  6091                              <1> 
  6092                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  6093                              <1> 	; 10/07/2022 - Retro UNIX 386 v1.1 (Kernel v0.2.1.5)
  6094                              <1> 
  6095                              <1> ;----------------------------------------
  6096                              <1> ;	CHECK FIXED DISK STATUS 	:
  6097                              <1> ;----------------------------------------
  6098                              <1> CHECK_STATUS:
  6099 000054F0 E831020000          <1> 	call	CHECK_ST		; CHECK THE STATUS BYTE
  6100                              <1> 	;jnz	short CHECK_S1		; AN ERROR WAS FOUND
  6101                              <1> 	; 10/07/2022
  6102 000054F5 7510                <1> 	jnz	short CHECK_S2
  6103 000054F7 A801                <1> 	test	al, ST_ERROR		; WERE THERE ANY OTHER ERRORS
  6104 000054F9 7405                <1> 	jz	short CHECK_S1		; NO ERROR REPORTED
  6105 000054FB E866020000          <1> 	call	CHECK_ER		; ERROR REPORTED
  6106                              <1> CHECK_S1:
  6107 00005500 803D[577D0100]00    <1> 	cmp	byte [DISK_STATUS1], 0 	; SET STATUS FOR CALLER
  6108                              <1> CHECK_S2:
  6109                              <1> INIT_EXIT:	; 10/07/2022
  6110 00005507 C3                  <1> 	retn
  6111                              <1> 
  6112                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  6113                              <1> 
  6114                              <1> ;----------------------------------------
  6115                              <1> ;	SEEK		     (AH = 0CH) :
  6116                              <1> ;----------------------------------------
  6117                              <1> 
  6118                              <1> DISK_SEEK:
  6119 00005508 C645FE70            <1>         mov	byte [CMD_BLOCK+6], SEEK_CMD
  6120 0000550C E8D9000000          <1> 	call	COMMAND
  6121 00005511 751C                <1> 	jnz	short DS_EXIT		; CONTROLLER BUSY ERROR
  6122 00005513 E88C010000          <1> 	call	_WAIT
  6123 00005518 7515                <1>         jnz	short DS_EXIT		; TIME OUT ON SEEK
  6124 0000551A E8D1FFFFFF          <1> 	call	CHECK_STATUS
  6125 0000551F 803D[577D0100]40    <1>         cmp	byte [DISK_STATUS1], BAD_SEEK
  6126 00005526 7507                <1> 	jne	short DS_EXIT
  6127 00005528 C605[577D0100]00    <1>         mov	byte [DISK_STATUS1], 0
  6128                              <1> DS_EXIT:
  6129 0000552F C3                  <1> 	retn
  6130                              <1> 
  6131                              <1> ;----------------------------------------
  6132                              <1> ;	TEST DISK READY      (AH = 10H) :
  6133                              <1> ;----------------------------------------
  6134                              <1> 
  6135                              <1> TST_RDY:				; WAIT FOR CONTROLLER
  6136 00005530 E89F010000          <1> 	call	NOT_BUSY
  6137 00005535 752C                <1> 	jnz	short TR_EX
  6138                              <1> 	;;;
  6139                              <1> 	; 23/06/2024
  6140 00005537 803D[6C7D0100]FF    <1> 	cmp	byte [LBAMode], 0FFh
  6141 0000553E 7507                <1> 	jne	short tst_28bit_rdy
  6142 00005540 A0[32660000]        <1> 	mov	al, [hf_m_s]
  6143 00005545 EB03                <1> 	jmp	short tst_48bit_rdy
  6144                              <1> tst_28bit_rdy:
  6145                              <1> 	;;;
  6146 00005547 8A45FD              <1> 	mov	al, [CMD_BLOCK+5] 	; SELECT DRIVE
  6147                              <1> tst_48bit_rdy:
  6148 0000554A 668B15[2E660000]    <1> 	mov	dx, [HF_PORT]
  6149 00005551 80C206              <1> 	add	dl, 6
  6150 00005554 EE                  <1> 	out	dx, al
  6151 00005555 E8CC010000          <1> 	call	CHECK_ST		; CHECK STATUS ONLY
  6152 0000555A 7507                <1> 	jnz	short TR_EX
  6153 0000555C C605[577D0100]00    <1> 	mov	byte [DISK_STATUS1], 0 	; WIPE OUT DATA CORRECTED ERROR
  6154                              <1> TR_EX:	
  6155 00005563 C3                  <1> 	retn
  6156                              <1> 
  6157                              <1> ;----------------------------------------
  6158                              <1> ;	RECALIBRATE	     (AH = 11H) :
  6159                              <1> ;----------------------------------------
  6160                              <1> 
  6161                              <1> HDISK_RECAL:
  6162 00005564 C645FE10            <1>         mov	byte [CMD_BLOCK+6], RECAL_CMD ; 10h, 16
  6163 00005568 E87D000000          <1> 	call	COMMAND 		; START THE OPERATION
  6164 0000556D 7523                <1> 	jnz	short RECAL_EXIT	; ERROR
  6165 0000556F E830010000          <1> 	call	_WAIT			; WAIT FOR COMPLETION
  6166 00005574 7407                <1> 	jz	short RECAL_X 		; TIME OUT ONE OK ?
  6167 00005576 E829010000          <1> 	call	_WAIT			; WAIT FOR COMPLETION LONGER
  6168 0000557B 7515                <1> 	jnz	short RECAL_EXIT	; TIME OUT TWO TIMES IS ERROR
  6169                              <1> RECAL_X:
  6170 0000557D E86EFFFFFF          <1> 	call	CHECK_STATUS
  6171 00005582 803D[577D0100]40    <1> 	cmp	byte [DISK_STATUS1], BAD_SEEK ; SEEK NOT COMPLETE
  6172 00005589 7507                <1> 	jne	short RECAL_EXIT	; IS OK
  6173 0000558B C605[577D0100]00    <1> 	mov	byte [DISK_STATUS1], 0
  6174                              <1> RECAL_EXIT:
  6175 00005592 803D[577D0100]00    <1>         cmp	byte [DISK_STATUS1], 0
  6176 00005599 C3                  <1> 	retn
  6177                              <1> 
  6178                              <1> ;----------------------------------------
  6179                              <1> ;      CONTROLLER DIAGNOSTIC (AH = 14H) :
  6180                              <1> ;----------------------------------------
  6181                              <1> 
  6182                              <1> CTLR_DIAGNOSTIC:
  6183                              <1> 	; 07/08/2022 - TRDOS 386 v2.0.5
  6184 0000559A FA                  <1> 	cli				; DISABLE INTERRUPTS WHILE CHANGING MASK
  6185 0000559B E4A1                <1> 	in	al, INTB01		; TURN ON SECOND INTERRUPT CHIP
  6186                              <1> 	;and	al, 0BFH
  6187 0000559D 243F                <1> 	and	al, 3Fh			; enable IRQ 14 & IRQ 15
  6188                              <1> 	;jmp	$+2
  6189                              <1> 	IODELAY
    78 0000559F EB00                <2>  jmp short $+2
    79 000055A1 EB00                <2>  jmp short $+2
  6190 000055A3 E6A1                <1> 	out	INTB01, al
  6191                              <1> 	IODELAY
    78 000055A5 EB00                <2>  jmp short $+2
    79 000055A7 EB00                <2>  jmp short $+2
  6192 000055A9 E421                <1> 	in	al, INTA01		; LET INTERRUPTS PASS THRU TO
  6193 000055AB 24FB                <1> 	and	al, 0FBh 		;  SECOND CHIP
  6194                              <1> 	;jmp	$+2
  6195                              <1> 	IODELAY
    78 000055AD EB00                <2>  jmp short $+2
    79 000055AF EB00                <2>  jmp short $+2
  6196 000055B1 E621                <1> 	out	INTA01, al
  6197 000055B3 FB                  <1> 	sti
  6198 000055B4 E81B010000          <1> 	call	NOT_BUSY		; WAIT FOR CARD
  6199 000055B9 7526                <1> 	jnz	short CD_ERR		; BAD CARD
  6200                              <1> 	;mov	dx, PORT+7
  6201 000055BB 668B15[2E660000]    <1> 	mov	dx, [HF_PORT]
  6202 000055C2 80C207              <1> 	add	dl, 7
  6203 000055C5 B090                <1> 	mov	al, DIAG_CMD		; START DIAGNOSE
  6204 000055C7 EE                  <1> 	out	dx, al
  6205 000055C8 E807010000          <1> 	call	NOT_BUSY		; WAIT FOR IT TO COMPLETE
  6206 000055CD B480                <1> 	mov	ah, TIME_OUT
  6207 000055CF 7512                <1> 	jnz	short CD_EXIT 		; TIME OUT ON DIAGNOSTIC
  6208                              <1> 	;mov	dx, HF_PORT+1		; GET ERROR REGISTER
  6209 000055D1 668B15[2E660000]    <1> 	mov	dx, [HF_PORT]
  6210 000055D8 FEC2                <1> 	inc	dl
  6211 000055DA EC                  <1> 	in	al, dx
  6212                              <1> 	; 07/08/2022
  6213                              <1> 	;mov	[HF_ERROR], al		; SAVE IT
  6214 000055DB B400                <1> 	mov	ah, 0
  6215 000055DD 3C01                <1> 	cmp	al, 1			; CHECK FOR ALL OK
  6216 000055DF 7402                <1> 	je	short CD_EXIT
  6217                              <1> CD_ERR:
  6218 000055E1 B420                <1> 	mov	ah, BAD_CNTLR
  6219                              <1> CD_EXIT:
  6220 000055E3 8825[577D0100]      <1> 	mov	[DISK_STATUS1], ah
  6221 000055E9 C3                  <1> 	retn
  6222                              <1> 
  6223                              <1> 	; 20/06/2024 - TRDOS 386 v2.0.8
  6224                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  6225                              <1> 	; 10/07/2022 - Retro UNIX 386 v1.1 (Kernel v0.2.1.5)
  6226                              <1> 
  6227                              <1> ;--------------------------------------------------------
  6228                              <1> ; COMMAND						:
  6229                              <1> ;	THIS ROUTINE OUTPUTS THE COMMAND BLOCK		:
  6230                              <1> ; OUTPUT						:
  6231                              <1> ;	BL = STATUS					:
  6232                              <1> ;	BH = ERROR REGISTER				:
  6233                              <1> ;--------------------------------------------------------
  6234                              <1> 
  6235                              <1> COMMAND:
  6236                              <1> 	;push	ebx ; 10/07/2022	; WAIT FOR SEEK COMPLETE AND READY
  6237                              <1> 	;;mov	ecx, DELAY_2		; SET INITIAL DELAY BEFORE TEST
  6238                              <1> COMMAND1:
  6239                              <1> 	;;push	ecx			; SAVE LOOP COUNT
  6240 000055EA E841FFFFFF          <1> 	call	TST_RDY 		; CHECK DRIVE READY
  6241                              <1> 	;;pop	ecx
  6242                              <1> 	;pop	ebx ; 10/07/2022
  6243 000055EF 7418                <1> 	jz	short COMMAND2		; DRIVE IS READY
  6244 000055F1 803D[577D0100]80    <1>         cmp	byte [DISK_STATUS1], TIME_OUT ; TST_RDY TIMED OUT--GIVE UP
  6245                              <1> 	;jz	short CMD_TIMEOUT
  6246                              <1> 	;;loop	COMMAND1		; KEEP TRYING FOR A WHILE
  6247                              <1> 	;jmp	short COMMAND4		; ITS NOT GOING TO GET READY
  6248 000055F8 7507                <1> 	jne	short COMMAND4
  6249                              <1> CMD_TIMEOUT:
  6250 000055FA C605[577D0100]20    <1> 	mov	byte [DISK_STATUS1], BAD_CNTLR
  6251                              <1> COMMAND4:
  6252                              <1> 	;;pop	ebx ; 10/07/2022
  6253 00005601 803D[577D0100]00    <1>         cmp	byte [DISK_STATUS1], 0	; SET CONDITION CODE FOR CALLER
  6254 00005608 C3                  <1> 	retn
  6255                              <1> COMMAND2:
  6256                              <1> 	;;pop	ebx ; 10/07/2022
  6257                              <1> 	;push	edi ; 10/07/2022
  6258 00005609 C605[527D0100]00    <1> 	mov	byte [HF_INT_FLAG], 0	; RESET INTERRUPT FLAG
  6259 00005610 FA                  <1> 	cli				; INHIBIT INTERRUPTS WHILE CHANGING MASK
  6260 00005611 E4A1                <1> 	in	al, INTB01		; TURN ON SECOND INTERRUPT CHIP
  6261                              <1> 	;and	al, 0BFh
  6262 00005613 243F                <1> 	and	al, 3Fh			; Enable IRQ 14 & 15
  6263                              <1> 	;jmp	$+2
  6264                              <1> 	IODELAY
    78 00005615 EB00                <2>  jmp short $+2
    79 00005617 EB00                <2>  jmp short $+2
  6265 00005619 E6A1                <1> 	out	INTB01, al
  6266 0000561B E421                <1> 	in	al, INTA01		; LET INTERRUPTS PASS THRU TO
  6267 0000561D 24FB                <1> 	and	al, 0FBh 		; SECOND CHIP
  6268                              <1> 	;jmp	$+2
  6269                              <1> 	IODELAY
    78 0000561F EB00                <2>  jmp short $+2
    79 00005621 EB00                <2>  jmp short $+2
  6270 00005623 E621                <1> 	out	INTA01, al
  6271 00005625 FB                  <1> 	sti
  6272                              <1> 	;xor	edi, edi		; INDEX THE COMMAND TABLE
  6273                              <1> 	; 10/07/2022
  6274 00005626 31C9                <1> 	xor	ecx, ecx
  6275                              <1> 	
  6276                              <1> 	;mov	dx, HF_PORT+1		; DISK ADDRESS
  6277 00005628 668B15[2E660000]    <1> 	mov	dx, [HF_PORT]
  6278 0000562F FEC2                <1> 	inc	dl	
  6279                              <1> 
  6280                              <1> 	; 20/06/2024
  6281                              <1> 	;mov	al, [CMD_BLOCK+6]
  6282                              <1> 	;cmp	al, 24h ; READ SECTOR(S) EXT
  6283                              <1> 	;je	short COMMAND5
  6284                              <1> 	;cmp	al, 34h ; WRITE SECTOR(S) EXT
  6285                              <1> 	;je	short COMMAND5
  6286                              <1> 	; 23/06/2024
  6287 00005631 803D[6C7D0100]FF    <1> 	cmp	byte [LBAMode], 0FFh
  6288 00005638 7428                <1> 	je	short COMMAND5	; 48 bit LBA read/write
  6289                              <1> 
  6290                              <1> 	; 20/06/2024
  6291                              <1> 	; dx = hd base port + 1 ; 1F1h or 171h
  6292                              <1> 
  6293 0000563A F605[597D0100]C0    <1> 	test	byte [CONTROL_BYTE], 0C0h ; CHECK FOR RETRY SUPPRESSION
  6294 00005641 740E                <1> 	jz	short COMMAND3
  6295                              <1> 	; 20/06/2024
  6296                              <1> 	;mov	al, [CMD_BLOCK+6] 	; YES-GET OPERATION CODE
  6297 00005643 24F0                <1> 	and	al, 0F0h 		; GET RID OF MODIFIERS
  6298 00005645 3C20                <1> 	cmp	al, 20h			; 20H-40H IS READ, WRITE, VERIFY
  6299 00005647 7208                <1> 	jb	short COMMAND3
  6300 00005649 3C40                <1> 	cmp	al, 40h
  6301 0000564B 7704                <1> 	ja	short COMMAND3
  6302 0000564D 804DFE01            <1> 	or	byte [CMD_BLOCK+6], NO_RETRIES 
  6303                              <1> 					; VALID OPERATION FOR RETRY SUPPRESS
  6304                              <1> COMMAND3:
  6305                              <1> 	;mov	al, [CMD_BLOCK+edi]	; GET THE COMMAND STRING BYTE
  6306                              <1> 	; 10/07/2022
  6307 00005651 8A440DF8            <1> 	mov	al, [CMD_BLOCK+ecx]
  6308 00005655 EE                  <1> 	out	dx, al			; GIVE IT TO CONTROLLER
  6309                              <1> 	IODELAY
    78 00005656 EB00                <2>  jmp short $+2
    79 00005658 EB00                <2>  jmp short $+2
  6310                              <1> 	;inc	edi			; NEXT BYTE IN COMMAND BLOCK
  6311                              <1> 	; 10/07/2022
  6312 0000565A 41                  <1> 	inc	ecx
  6313                              <1> 	;inc	dx			; NEXT DISK ADAPTER REGISTER
  6314 0000565B 42                  <1> 	inc	edx   ; 10/07/2022	
  6315                              <1> 	;cmp	di, 7 ; 01/01/2015	; ALL DONE?
  6316                              <1> 	;jne	short COMMAND3		; NO--GO DO NEXT ONE
  6317 0000565C 80F907              <1> 	cmp	cl, 7 ; 10/07/2022
  6318 0000565F 72F0                <1> 	jb	short COMMAND3
  6319                              <1> 	;pop	edi ; 10/07/2022
  6320 00005661 C3                  <1> 	retn				; ZERO FLAG IS SET
  6321                              <1> 
  6322                              <1> 	; 20/06/2024
  6323                              <1> COMMAND5:
  6324                              <1> 	; 48 bit LBA r/w
  6325 00005662 8A45F8              <1> 	mov	al, [CMD_BLOCK] ; 0
  6326 00005665 EE                  <1> 	out	dx, al	; hd base port + 1
  6327                              <1> 	;
  6328 00005666 80C205              <1> 	add	dl, 5	; hd base port + 6 ; 1F6h or 176h
  6329 00005669 A0[32660000]        <1> 	mov	al, [hf_m_s]
  6330                              <1> 	; 23/06/2024
  6331                              <1> 	;shl	al, 4
  6332                              <1> 	;;add	al, 40h
  6333                              <1> 	;or	al, 40h	
  6334                              <1> 	;; al = 40h (for master), 50h (for slave)
  6335                              <1> 	;
  6336 0000566E EE                  <1> 	out	dx, al
  6337 0000566F 80EA04              <1> 	sub	dl, 4	; hd base port + 2 ; 1F2h or 172h
  6338 00005672 30C0                <1> 	xor	al, al	; 0
  6339 00005674 EE                  <1> 	out	dx, al	; sector count hb (bits 8 to 15) = 0
  6340 00005675 42                  <1> 	inc	edx	; hd base port + 3
  6341 00005676 8B45FA              <1> 	mov	eax, [CMD_BLOCK+2]
  6342 00005679 C1C008              <1> 	rol	eax, 8
  6343 0000567C EE                  <1> 	out	dx, al	; LBA byte 4 (bits 24 to 31)
  6344 0000567D 42                  <1> 	inc	edx	; hd base port + 4
  6345 0000567E 30C0                <1> 	xor	al, al
  6346 00005680 EE                  <1> 	out	dx, al	; LBA byte 5 (bits 32 to 39) = 0
  6347 00005681 42                  <1> 	inc	edx	; hd base port + 5
  6348 00005682 28C0                <1> 	sub	al, al
  6349 00005684 EE                  <1> 	out	dx, al	; LBA byte 6 (bits 40 to 47) = 0
  6350 00005685 8A45F9              <1> 	mov	al, [CMD_BLOCK+1] ; sector count
  6351 00005688 80EA03              <1> 	sub	dl, 3	; hd base port + 2
  6352 0000568B EE                  <1> 	out	dx, al	; sector count lb (bits 0 to 7)
  6353 0000568C C1E808              <1> 	shr	eax, 8
  6354 0000568F 42                  <1> 	inc	edx	; hd base port + 3 ; 1F3h or 173h
  6355 00005690 EE                  <1> 	out	dx, al	; LBA byte 1 (bits 0 to 7)
  6356 00005691 C1E808              <1> 	shr	eax, 8
  6357 00005694 42                  <1> 	inc	edx	; hd base port + 4
  6358 00005695 EE                  <1> 	out	dx, al	; LBA byte 2 (bits 8 to 15)
  6359 00005696 C1E808              <1> 	shr	eax, 8
  6360 00005699 42                  <1> 	inc	edx	; hd base port + 5
  6361 0000569A EE                  <1> 	out	dx, al	; LBA byte 3 (bits 16 to 23
  6362 0000569B 42                  <1> 	inc	edx	; hd base port + 6
  6363 0000569C 8A45FE              <1> 	mov	al, [CMD_BLOCK+6] ; 48 bit read or write command
  6364                              <1> 	; al = 24h or 34h
  6365 0000569F 42                  <1> 	inc	edx	; hd base port + 7 ; 1F7h or 177h
  6366 000056A0 EE                  <1> 	out	dx, al
  6367 000056A1 31C0                <1> 	xor	eax, eax ; 0
  6368                              <1> 	; zf = 1
  6369 000056A3 C3                  <1> 	retn
  6370                              <1> 
  6371                              <1> ;CMD_TIMEOUT:
  6372                              <1> ;	mov	byte [DISK_STATUS1], BAD_CNTLR
  6373                              <1> ;COMMAND4:
  6374                              <1> ;	pop	ebx
  6375                              <1> ;	cmp	byte [DISK_STATUS1], 0 	; SET CONDITION CODE FOR CALLER
  6376                              <1> ;	retn
  6377                              <1> 
  6378                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  6379                              <1> 	; 10/07/2022 - Retro UNIX 386 v1.1 (Kernel v0.2.1.5)
  6380                              <1> 
  6381                              <1> ;----------------------------------------
  6382                              <1> ;	WAIT FOR INTERRUPT		:
  6383                              <1> ;----------------------------------------
  6384                              <1> ;WAIT:
  6385                              <1> _WAIT:
  6386 000056A4 FB                  <1> 	sti				; MAKE SURE INTERRUPTS ARE ON
  6387                              <1> 	;sub	cx, cx			; SET INITIAL DELAY BEFORE TEST
  6388                              <1> 	;clc
  6389                              <1> 	;mov	ax, 9000h		; DEVICE WAIT INTERRUPT
  6390                              <1> 	;int	15h
  6391                              <1> 	;jc	short WT2		; DEVICE TIMED OUT
  6392                              <1> 	;mov	bl, DELAY_1		; SET DELAY COUNT
  6393                              <1> 
  6394                              <1> 	;mov	bl, WAIT_HDU_INT_HI
  6395                              <1> 	;; 21/02/2015
  6396                              <1> 	;;mov	bl, WAIT_HDU_INT_HI + 1
  6397                              <1> 	;;mov	cx, WAIT_HDU_INT_LO
  6398 000056A5 B915160500          <1> 	mov	ecx, WAIT_HDU_INT_LH
  6399                              <1> 					; (AWARD BIOS -> WAIT_FOR_MEM)
  6400                              <1> ;-----	WAIT LOOP
  6401                              <1> 
  6402                              <1> WT1:	
  6403                              <1> 	;test	byte [HF_INT_FLAG], 80h	; TEST FOR INTERRUPT
  6404 000056AA F605[527D0100]C0    <1> 	test 	byte [HF_INT_FLAG], 0C0h
  6405                              <1> 	;loopz	WT1
  6406 000056B1 7512                <1> 	jnz	short WT3		; INTERRUPT--LETS GO
  6407                              <1> 	;dec	bl
  6408                              <1> 	;jnz	short WT1		; KEEP TRYING FOR A WHILE
  6409                              <1> 
  6410                              <1> WT1_hi:
  6411 000056B3 E461                <1> 	in	al, SYS1 ; 61h (PORT_B)	; wait for lo to hi
  6412 000056B5 A810                <1> 	test	al, 10h			; transition on memory
  6413 000056B7 75FA                <1> 	jnz	short WT1_hi		; refresh.
  6414                              <1> WT1_lo:
  6415 000056B9 E461                <1> 	in	al, SYS1 		; 061h (PORT_B)	
  6416 000056BB A810                <1> 	test	al, 10h			
  6417 000056BD 74FA                <1> 	jz	short WT1_lo
  6418 000056BF E2E9                <1> 	loop	WT1
  6419                              <1> 	;;or	bl, bl
  6420                              <1> 	;;jz	short WT2	
  6421                              <1> 	;;dec	bl
  6422                              <1> 	;;jmp	short WT1
  6423                              <1> 	;dec	bl
  6424                              <1> 	;jnz	short WT1	
  6425                              <1> WT2:	
  6426                              <1> 	; 10/07/2022
  6427                              <1> 	;mov	byte [DISK_STATUS1], TIME_OUT ; REPORT TIME OUT ERROR
  6428 000056C1 B080                <1> 	mov	al, TIME_OUT
  6429 000056C3 EB07                <1> 	jmp	short WT4
  6430                              <1> WT3:
  6431                              <1> 	;mov	byte [DISK_STATUS1], 0
  6432                              <1> 	;mov	byte [HF_INT_FLAG], 0
  6433 000056C5 28C0                <1> 	sub	al, al ; 0
  6434 000056C7 A2[527D0100]        <1> 	mov	byte [HF_INT_FLAG], al
  6435                              <1> WT4:
  6436                              <1> NB2:	
  6437 000056CC A2[577D0100]        <1> 	mov	byte [DISK_STATUS1], al
  6438                              <1> 
  6439                              <1> 	;cmp	byte [DISK_STATUS1], 0 	; SET CONDITION CODE FOR CALLER
  6440 000056D1 20C0                <1> 	and	al, al
  6441                              <1> 	; zf = 0 -> time out, zf = 1 -> ok
  6442 000056D3 C3                  <1> 	retn
  6443                              <1> 
  6444                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  6445                              <1> 	; 10/07/2022 - Retro UNIX 386 v1.1 (Kernel v0.2.1.5)
  6446                              <1> 
  6447                              <1> ;----------------------------------------
  6448                              <1> ;	WAIT FOR CONTROLLER NOT BUSY	:
  6449                              <1> ;----------------------------------------
  6450                              <1> NOT_BUSY:
  6451 000056D4 FB                  <1> 	sti				; MAKE SURE INTERRUPTS ARE ON
  6452                              <1> 	;push	ebx
  6453                              <1> 	;sub	cx, cx			; SET INITIAL DELAY BEFORE TEST
  6454 000056D5 668B15[2E660000]    <1> 	mov	dx, [HF_PORT]
  6455 000056DC 80C207              <1> 	add	dl, 7			; Status port (HF_PORT+7)
  6456                              <1> 	;mov	bl, DELAY_1
  6457                              <1> 					; wait for 10 seconds
  6458                              <1> 	;mov 	cx, WAIT_HDU_INT_LO	; 1615h
  6459                              <1> 	;;mov 	bl, WAIT_HDU_INT_HI	;   05h
  6460                              <1> 	;mov	bl, WAIT_HDU_INT_HI + 1
  6461 000056DF B915160500          <1> 	mov	ecx, WAIT_HDU_INT_LH  ; 21/02/2015
  6462                              <1> 	;
  6463                              <1> 	;;mov	byte [wait_count], 0    ; Reset wait counter
  6464                              <1> NB1:	
  6465 000056E4 EC                  <1> 	in	al, dx			; CHECK STATUS
  6466                              <1> 	;test	al, ST_BUSY
  6467 000056E5 2480                <1> 	and	al, ST_BUSY
  6468                              <1> 	;loopnz NB1
  6469 000056E7 74E3                <1> 	jz	short NB2 ; al = 0	; NOT BUSY--LETS GO
  6470                              <1> 	;dec	bl			
  6471                              <1> 	;jnz	short NB1		; KEEP TRYING FOR A WHILE
  6472                              <1> 
  6473                              <1> NB1_hi: 
  6474 000056E9 E461                <1> 	in	al, SYS1		; wait for hi to lo
  6475 000056EB A810                <1> 	test	al, 010h		; transition on memory
  6476 000056ED 75FA                <1> 	jnz	short NB1_hi		; refresh.
  6477                              <1> NB1_lo: 
  6478 000056EF E461                <1> 	in	al, SYS1
  6479 000056F1 A810                <1> 	test	al, 010h
  6480 000056F3 74FA                <1> 	jz	short NB1_lo
  6481 000056F5 E2ED                <1> 	loop	NB1
  6482                              <1> 	;dec	bl
  6483                              <1> 	;jnz	short NB1
  6484                              <1> 	;
  6485                              <1> 	;;cmp	byte [wait_count], 182  ; 10 seconds (182 timer ticks)
  6486                              <1> 	;;jb	short NB1
  6487                              <1> 	;
  6488                              <1> 	;mov	byte [DISK_STATUS1], TIME_OUT ; REPORT TIME OUT ERROR
  6489                              <1> 	;jmp	short NB3
  6490 000056F7 B080                <1> 	mov	al, TIME_OUT
  6491                              <1> ;NB2:	
  6492 000056F9 EBD1                <1> 	jmp	short NB2 ; 10/07/2022
  6493                              <1> 
  6494                              <1> ;	;mov	byte [DISK_STATUS1], 0
  6495                              <1> ;;NB3:	
  6496                              <1> ;	;pop	ebx
  6497                              <1> ;	mov	[DISK_STATUS1], al	;;; will be set after return
  6498                              <1> ;	;cmp	byte [DISK_STATUS1], 0 	; SET CONDITION CODE FOR CALLER
  6499                              <1> ;	or	al, al			; (zf = 0 --> timeout)
  6500                              <1> ;	retn
  6501                              <1> 
  6502                              <1> ;----------------------------------------
  6503                              <1> ;	WAIT FOR DATA REQUEST		:
  6504                              <1> ;----------------------------------------
  6505                              <1> WAIT_DRQ:
  6506                              <1> 	;mov	cx, DELAY_3
  6507                              <1> 	;mov	dx, HF_PORT+7
  6508 000056FB 668B15[2E660000]    <1> 	mov	dx, [HF_PORT]
  6509 00005702 80C207              <1> 	add	dl, 7
  6510                              <1> 	;;mov	bl, WAIT_HDU_DRQ_HI	; 0
  6511                              <1> 	;mov	cx, WAIT_HDU_DRQ_LO	; 1000 (30 milli seconds)
  6512                              <1> 					; (but it is written as 2000
  6513                              <1> 					; micro seconds in ATORGS.ASM file
  6514                              <1> 					; of Award Bios - 1999, D1A0622)
  6515 00005705 B9E8030000          <1> 	mov 	ecx, WAIT_HDU_DRQ_LH ; 21/02/2015 
  6516                              <1> WQ_1:
  6517 0000570A EC                  <1> 	in	al, dx			; GET STATUS
  6518 0000570B A808                <1> 	test	al, ST_DRQ		; WAIT FOR DRQ
  6519 0000570D 7516                <1> 	jnz	short WQ_OK
  6520                              <1> 	;loop	WQ_1			; KEEP TRYING FOR A SHORT WHILE
  6521                              <1> WQ_hi:	
  6522 0000570F E461                <1> 	in	al, SYS1		; wait for hi to lo
  6523 00005711 A810                <1> 	test	al, 010h		; transition on memory
  6524 00005713 75FA                <1> 	jnz	short WQ_hi		; refresh.
  6525                              <1> WQ_lo:  
  6526 00005715 E461                <1> 	in	al, SYS1
  6527 00005717 A810                <1> 	test	al, 010h
  6528 00005719 74FA                <1> 	jz	short WQ_lo
  6529 0000571B E2ED                <1> 	loop	WQ_1
  6530                              <1> 
  6531 0000571D C605[577D0100]80    <1> 	mov	byte [DISK_STATUS1], TIME_OUT ; ERROR
  6532 00005724 F9                  <1> 	stc
  6533                              <1> WQ_OK:
  6534 00005725 C3                  <1> 	retn
  6535                              <1> ;WQ_OK:
  6536                              <1> 	;clc
  6537                              <1> 	;ret
  6538                              <1> 
  6539                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  6540                              <1> 
  6541                              <1> ;----------------------------------------
  6542                              <1> ;	CHECK FIXED DISK STATUS BYTE	:
  6543                              <1> ;----------------------------------------
  6544                              <1> CHECK_ST:
  6545                              <1> 	;mov	dx, HF_PORT+7		; GET THE STATUS
  6546 00005726 668B15[2E660000]    <1> 	mov	dx, [HF_PORT]
  6547 0000572D 80C207              <1> 	add	dl, 7
  6548                              <1> 	
  6549                              <1> 	; 17/02/2016
  6550                              <1> 	;(http://wiki.osdev.org/ATA_PIO_Mode)
  6551                              <1> 	;"delay 400ns to allow drive to set new values of BSY and DRQ"
  6552 00005730 EC                  <1> 	in	al, dx
  6553                              <1> 	;in	al, dx ; 100ns
  6554                              <1> 	;in	al, dx ; 100ns
  6555                              <1>  	;in	al, dx ; 100ns
  6556                              <1> 	NEWIODELAY ; 18/02/2016 (AWARD BIOS - 1999, 'CKST' in AHSDK.ASM)
    83 00005731 E6EB                <2>  out 0EBh, al
  6557                              <1> 	;
  6558                              <1> 
  6559                              <1> 	; 16/07/2022
  6560 00005733 A2[517D0100]        <1> 	mov	[HF_STATUS], al
  6561                              <1> 	;mov	ah, 0
  6562 00005738 28E4                <1> 	sub	ah, ah ; 0
  6563 0000573A A880                <1> 	test	al, ST_BUSY		; IF STILL BUSY
  6564 0000573C 751A                <1> 	jnz	short CKST_EXIT		; REPORT OK
  6565 0000573E B4CC                <1> 	mov	ah, WRITE_FAULT
  6566 00005740 A820                <1> 	test 	al, ST_WRT_FLT		; CHECK FOR WRITE FAULT
  6567 00005742 7514                <1> 	jnz	short CKST_EXIT
  6568 00005744 B4AA                <1> 	mov	ah, NOT_RDY
  6569 00005746 A840                <1> 	test	al, ST_READY		; CHECK FOR NOT READY
  6570 00005748 740E                <1> 	jz	short CKST_EXIT
  6571 0000574A B440                <1> 	mov	ah, BAD_SEEK
  6572 0000574C A810                <1> 	test	al, ST_SEEK_COMPL	; CHECK FOR SEEK NOT COMPLETE
  6573 0000574E 7408                <1> 	jz	short CKST_EXIT
  6574 00005750 B411                <1> 	mov	ah, DATA_CORRECTED
  6575 00005752 A804                <1> 	test	al, ST_CORRCTD		; CHECK FOR CORRECTED ECC
  6576 00005754 7502                <1> 	jnz	short CKST_EXIT
  6577                              <1> 	;mov	ah, 0
  6578 00005756 30E4                <1> 	xor	ah, ah ; 0
  6579                              <1> CKST_EXIT:
  6580 00005758 8825[577D0100]      <1> 	mov	[DISK_STATUS1], ah	; SET ERROR FLAG
  6581 0000575E 80FC11              <1> 	cmp	ah, DATA_CORRECTED	; KEEP GOING WITH DATA CORRECTED
  6582 00005761 7402                <1> 	je	short CKST_EX1
  6583                              <1> 	;cmp	ah, 0
  6584 00005763 20E4                <1> 	and	ah, ah
  6585                              <1> CKST_EX1:
  6586 00005765 C3                  <1> 	retn
  6587                              <1> 
  6588                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  6589                              <1> 
  6590                              <1> ;----------------------------------------
  6591                              <1> ;	CHECK FIXED DISK ERROR REGISTER :
  6592                              <1> ;----------------------------------------
  6593                              <1> CHECK_ER:
  6594                              <1> 	;mov	dx, HF_PORT+1		; GET THE ERROR REGISTER
  6595 00005766 668B15[2E660000]    <1> 	mov	dx, [HF_PORT]		;
  6596 0000576D FEC2                <1> 	inc	dl
  6597 0000576F EC                  <1> 	in	al, dx
  6598                              <1> 	; 16/07/2022
  6599                              <1> 	;mov	[HF_ERROR], al
  6600                              <1> 	;push	ebx  ; 21/02/2015
  6601 00005770 29C9                <1> 	sub	ecx, ecx
  6602                              <1> 	;mov	ecx, 8			; TEST ALL 8 BITS
  6603 00005772 B108                <1> 	mov	cl, 8
  6604                              <1> CK1:	
  6605 00005774 D0E0                <1> 	shl	al, 1			; MOVE NEXT ERROR BIT TO CARRY
  6606 00005776 7202                <1> 	jc	short CK2		; FOUND THE ERROR
  6607 00005778 E2FA                <1> 	loop	CK1			; KEEP TRYING
  6608                              <1> CK2:
  6609                              <1> 	;mov	ebx, ERR_TBL		; COMPUTE ADDRESS OF
  6610                              <1> 	;add	ebx, ecx		; ERROR CODE
  6611 0000577A 81C1[24660000]      <1> 	add	ecx, ERR_TBL ; 16/07/2022	
  6612                              <1> 
  6613                              <1> 	;;;mov	ah, byte [cs:bx]	; GET ERROR CODE
  6614                              <1> 	;;mov	ah, [bx]
  6615                              <1> 	;mov	ah, [ebx] ; 21/02/2015
  6616 00005780 8A21                <1> 	mov	ah, [ecx]	
  6617                              <1> CKEX:
  6618 00005782 8825[577D0100]      <1> 	mov	[DISK_STATUS1], ah	; SAVE ERROR CODE
  6619                              <1> 	; 16/07/2022
  6620                              <1> 	;pop	ebx
  6621                              <1> 	;;cmp	ah, 0
  6622                              <1> 	;and	ah, ah
  6623 00005788 C3                  <1> 	retn
  6624                              <1> 
  6625                              <1> ;--------------------------------------------------------
  6626                              <1> ; CHECK_DMA						:
  6627                              <1> ;  -CHECK ES:BX AND # SECTORS TO MAKE SURE THAT IT WILL :
  6628                              <1> ;   FIT WITHOUT SEGMENT OVERFLOW.			:
  6629                              <1> ;  -ES:BX HAS BEEN REVISED TO THE FORMAT SSSS:000X	:
  6630                              <1> ;  -OK IF # SECTORS < 80H (7FH IF LONG READ OR WRITE)	:
  6631                              <1> ;  -OK IF # SECTORS = 80H (7FH) AND BX <= 00H (04H)	:
  6632                              <1> ;  -ERROR OTHERWISE					:
  6633                              <1> ;--------------------------------------------------------
  6634                              <1> 
  6635                              <1> 	; 16/07/2022 - TRDOS 386 v2.0.5
  6636                              <1> 	; (not needed for hard disks and 32 bit OS)
  6637                              <1> 
  6638                              <1> ;CHECK_DMA:
  6639                              <1> ;	; 11/04/2021 (32 bit push/pop)
  6640                              <1> ;	push	eax			; SAVE REGISTERS
  6641                              <1> ;	mov	ax, 8000h		; AH = MAX # SECTORS
  6642                              <1> ;					; AL = MAX OFFSET
  6643                              <1> ;	test	byte [CMD_BLOCK+6], ECC_MODE
  6644                              <1> ;	jz	short CKD1
  6645                              <1> ;	mov	ah, 7F04h		; ECC IS 4 MORE BYTES
  6646                              <1> ;CKD1:	
  6647                              <1> ;	cmp	ah, [CMD_BLOCK+1] 	; NUMBER OF SECTORS
  6648                              <1> ;	ja	short CKDOK		; IT WILL FIT
  6649                              <1> ;	jb	short CKDERR		; TOO MANY
  6650                              <1> ;	cmp	al, bl			; CHECK OFFSET ON MAX SECTORS
  6651                              <1> ;	;jb	short CKDERR		; ERROR
  6652                              <1> ;	jnb	short CKDOK ; 16/07/2022
  6653                              <1> ;;CKDOK:	
  6654                              <1> ;	;clc				; CLEAR CARRY
  6655                              <1> ;	;pop	eax
  6656                              <1> ;	;retn				; NORMAL RETURN
  6657                              <1> ;CKDERR:
  6658                              <1> ;	;stc				; INDICATE ERROR
  6659                              <1> ;	mov	byte [DISK_STATUS1], DMA_BOUNDARY
  6660                              <1> ;CKDOK:
  6661                              <1> ;	pop	eax
  6662                              <1> ;	retn
  6663                              <1> 
  6664                              <1> ;----------------------------------------
  6665                              <1> ;	SET UP EBX-> DISK PARMS		:
  6666                              <1> ;----------------------------------------
  6667                              <1> 					
  6668                              <1> ; INPUT -> DL = 0 based drive number
  6669                              <1> ; OUTPUT -> EBX = disk parameter table address
  6670                              <1> 
  6671                              <1> GET_VEC:
  6672                              <1> 	;sub	ax, ax			; GET DISK PARAMETER ADDRESS
  6673                              <1> 	;mov	es, ax
  6674                              <1> 	;test	dl, 1
  6675                              <1> 	;jz	short GV_0
  6676                              <1> ;	les	bx, [HF1_TBL_VEC] 	; ES:BX -> DRIVE PARAMETERS
  6677                              <1> ;	jmp	short GV_EXIT
  6678                              <1> ;GV_0:
  6679                              <1> ;	les 	bx,[HF_TBL_VEC]		; ES:BX -> DRIVE PARAMETERS
  6680                              <1> ;
  6681 00005789 31DB                <1> 	xor	ebx, ebx
  6682 0000578B 88D3                <1> 	mov	bl, dl
  6683                              <1> 	;02/01/2015
  6684                              <1> 	;xor	bh, bh
  6685                              <1> 	;shl	bl, 1			; port address offset
  6686                              <1> 	;mov	ax, [bx+hd_ports]	; Base port address (1F0h, 170h)
  6687                              <1> 	;shl	bl, 1			; dpt pointer offset
  6688 0000578D C0E302              <1> 	shl	bl, 2
  6689                              <1> 	;add	bx, HF_TBL_VEC		; Disk parameter table pointer
  6690 00005790 81C3[5C7D0100]      <1> 	add	ebx, HF_TBL_VEC ; 21/02/2015
  6691                              <1> 	;push	word [bx+2]		; dpt segment
  6692                              <1> 	;pop	es
  6693                              <1> 	;mov	bx, [bx]		; dpt offset
  6694 00005796 8B1B                <1> 	mov	ebx, [ebx]		
  6695                              <1> ;GV_EXIT:
  6696 00005798 C3                  <1> 	retn
  6697                              <1> 
  6698                              <1> hdc1_int: ; 21/02/2015
  6699                              <1> ;--- HARDWARE INT 76H -- ( IRQ LEVEL 14 ) -----------------------
  6700                              <1> ;								:
  6701                              <1> ;	FIXED DISK INTERRUPT ROUTINE				:
  6702                              <1> ;								:
  6703                              <1> ;----------------------------------------------------------------
  6704                              <1> 
  6705                              <1> ; 22/12/2014
  6706                              <1> ; IBM PC-XT Model 286 System BIOS Source Code - DISK.ASM (HD_INT)
  6707                              <1> ;	 '11/15/85'
  6708                              <1> ; AWARD BIOS 1999 (D1A0622) 
  6709                              <1> ;	Source Code - ATORGS.ASM (INT_HDISK, INT_HDISK1)
  6710                              <1> 
  6711                              <1> ;int_76h:
  6712                              <1> HD_INT:
  6713                              <1> 	; 11/04/2021 (32 bit push/pop)
  6714 00005799 50                  <1> 	push	eax
  6715 0000579A 1E                  <1> 	push	ds
  6716                              <1> 	;call	DDS
  6717                              <1> 	; 21/02/2015 (32 bit, 386 pm modification)
  6718 0000579B 66B81000            <1> 	mov	ax, KDATA
  6719 0000579F 8ED8                <1> 	mov 	ds, ax
  6720                              <1> 	;
  6721                              <1> 	;;mov	@HF_INT_FLAG,0FFH	; ALL DONE
  6722                              <1>         ;mov	byte [CS:HF_INT_FLAG], 0FFh
  6723 000057A1 C605[527D0100]FF    <1> 	mov	byte [HF_INT_FLAG], 0FFh
  6724                              <1> 	;
  6725 000057A8 52                  <1> 	push	edx
  6726 000057A9 66BAF701            <1> 	mov	dx, HDC1_BASEPORT+7	; Status Register (1F7h)
  6727                              <1> 					; Clear Controller
  6728                              <1> Clear_IRQ1415:				; (Award BIOS - 1999)
  6729 000057AD EC                  <1> 	in	al, dx			;
  6730 000057AE 5A                  <1> 	pop	edx
  6731                              <1> 	NEWIODELAY
    83 000057AF E6EB                <2>  out 0EBh, al
  6732                              <1> 	;
  6733 000057B1 B020                <1> 	mov	al, EOI			; NON-SPECIFIC END OF INTERRUPT
  6734 000057B3 E6A0                <1> 	out	INTB00, al		; FOR CONTROLLER #2
  6735                              <1> 	;jmp	$+2			; WAIT
  6736                              <1> 	NEWIODELAY
    83 000057B5 E6EB                <2>  out 0EBh, al
  6737 000057B7 E620                <1> 	out	INTA00, al		; FOR CONTROLLER #1
  6738 000057B9 1F                  <1> 	pop	ds
  6739                              <1> 	;sti				; RE-ENABLE INTERRUPTS
  6740                              <1> 	;mov	ax, 9100h		; DEVICE POST
  6741                              <1> 	;int	15h			;  INTERRUPT
  6742                              <1> irq15_iret: ; 25/02/2015
  6743 000057BA 58                  <1> 	pop	eax
  6744 000057BB CF                  <1> 	iretd				; RETURN FROM INTERRUPT
  6745                              <1> 
  6746                              <1> hdc2_int: ; 21/02/2015
  6747                              <1> ;--- HARDWARE INT 77H -- ( IRQ LEVEL 15 ) -----------------------
  6748                              <1> ;								:
  6749                              <1> ;	FIXED DISK INTERRUPT ROUTINE				:
  6750                              <1> ;								:
  6751                              <1> ;----------------------------------------------------------------
  6752                              <1> 
  6753                              <1> ;int_77h:
  6754                              <1> HD1_INT:
  6755                              <1> 	; 11/04/2021 (32 bit push/pop)
  6756 000057BC 50                  <1> 	push	eax
  6757                              <1> 	; Check if that is a spurious IRQ (from slave PIC)
  6758                              <1> 	; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
  6759 000057BD B00B                <1> 	mov	al, 0Bh  ; In-Service Register
  6760 000057BF E6A0                <1> 	out	0A0h, al
  6761 000057C1 EB00                <1>         jmp short $+2
  6762 000057C3 EB00                <1> 	jmp short $+2
  6763 000057C5 E4A0                <1> 	in	al, 0A0h
  6764 000057C7 2480                <1> 	and 	al, 80h ; bit 7 (is it real IRQ 15 or fake?)
  6765 000057C9 74EF                <1> 	jz	short irq15_iret ; Fake (spurious) IRQ, do not send EOI)
  6766                              <1> 	;
  6767 000057CB 1E                  <1> 	push	ds
  6768                              <1> 	;call	DDS
  6769                              <1> 	; 21/02/2015 (32 bit, 386 pm modification)
  6770 000057CC 66B81000            <1> 	mov	ax, KDATA
  6771 000057D0 8ED8                <1> 	mov 	ds, ax
  6772                              <1> 	;
  6773                              <1> 	;;mov	@HF_INT_FLAG,0FFH	; ALL DONE
  6774                              <1>         ;or	byte [CS:HF_INT_FLAG],0C0h 
  6775 000057D2 800D[527D0100]C0    <1> 	or	byte [HF_INT_FLAG], 0C0h
  6776                              <1> 	;
  6777 000057D9 52                  <1> 	push	edx
  6778 000057DA 66BA7701            <1> 	mov	dx, HDC2_BASEPORT+7	; Status Register (177h)
  6779                              <1> 					; Clear Controller (Award BIOS 1999)
  6780 000057DE EBCD                <1> 	jmp	short Clear_IRQ1415
  6781                              <1> 
  6782                              <1> ;%include 'diskdata.inc' ; 11/03/2015
  6783                              <1> ;%include 'diskbss.inc' ; 11/03/2015
  6784                              <1> 
  6785                              <1> ;////////////////////////////////////////////////////////////////////
  6786                              <1> ;; END OF DISK I/O SYTEM ///
  3226                                  %include 'memory.s'  ; 09/03/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.8 - memory.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 04/06/2024  (Previous: 02/12/2023 - Kernel v2.0.7)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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> ; 14/12/2020
    61                              <1> ; (Linear Frame Buffer - video memory mark : AVL bit 1, outside M.A.T.)
    62                              <1> PDE_EXTERNAL	equ 400h	; Page directory entry for external memory blocks
    63                              <1> PTE_EXTERNAL	equ 400h	; Allocated kernel pages for Linear Frame Buffer
    64                              <1> 				; (Out of memory allocation table)	
    65                              <1> 
    66                              <1> ;
    67                              <1> ;; Retro Unix 386 v1 - paging method/principles
    68                              <1> ;;
    69                              <1> ;; 10/10/2014
    70                              <1> ;; RETRO UNIX 386 v1 - PAGING METHOD/PRINCIPLES
    71                              <1> ;;
    72                              <1> ;; KERNEL PAGE MAP: 1 to 1 physical memory page map
    73                              <1> ;;	(virtual address = physical address)
    74                              <1> ;; KERNEL PAGE TABLES:
    75                              <1> ;;	Kernel page directory and all page tables are
    76                              <1> ;;	on memory as initialized, as equal to physical memory
    77                              <1> ;;	layout. Kernel pages can/must not be swapped out/in.
    78                              <1> ;;
    79                              <1> ;;	what for: User pages may be swapped out, when accessing
    80                              <1> ;;	a page in kernel/system mode, if it would be swapped out,
    81                              <1> ;;	kernel would have to swap it in! But it is also may be
    82                              <1> ;;	in use by a user process. (In system/kernel mode
    83                              <1> ;;	kernel can access all memory pages even if they are
    84                              <1> ;;	reserved/allocated for user processes. Swap out/in would
    85                              <1> ;;	cause conflicts.) 
    86                              <1> ;;	
    87                              <1> ;;	As result of these conditions,
    88                              <1> ;;	all kernel pages must be initialized as equal to 
    89                              <1> ;;	physical layout for preventing page faults. 
    90                              <1> ;;	Also, calling "allocate page" procedure after
    91                              <1> ;;	a page fault can cause another page fault (double fault)
    92                              <1> ;;	if all kernel page tables would not be initialized.
    93                              <1> ;;
    94                              <1> ;;	[first_page] = Beginning of users space, as offset to 
    95                              <1> ;;	memory allocation table. (double word aligned)
    96                              <1> ;;
    97                              <1> ;;	[next_page] = first/next free space to be searched
    98                              <1> ;;	as offset to memory allocation table. (dw aligned)
    99                              <1> ;;
   100                              <1> ;;	[last_page] = End of memory (users space), as offset
   101                              <1> ;;	to memory allocation table. (double word aligned)
   102                              <1> ;;
   103                              <1> ;; USER PAGE TABLES:
   104                              <1> ;;	Demand paging (& 'copy on write' allocation method) ...
   105                              <1> ;;		'ready only' marked copies of the 
   106                              <1> ;;		parent process's page table entries (for
   107                              <1> ;;		same physical memory).
   108                              <1> ;;		(A page will be copied to a new page after
   109                              <1> ;;		 if it causes R/W page fault.)
   110                              <1> ;;
   111                              <1> ;;	Every user process has own (different)
   112                              <1> ;;	page directory and page tables.	
   113                              <1> ;;
   114                              <1> ;;	Code starts at virtual address 0, always.
   115                              <1> ;;	(Initial value of EIP is 0 in user mode.)
   116                              <1> ;;	(Programs can be written/developed as simple
   117                              <1> ;;	 flat memory programs.)
   118                              <1> ;;
   119                              <1> ;; MEMORY ALLOCATION STRATEGY:
   120                              <1> ;;	Memory page will be allocated by kernel only 
   121                              <1> ;;		(in kernel/system mode only).
   122                              <1> ;;	* After a
   123                              <1> ;;	  - 'not present' page fault
   124                              <1> ;;	  - 'writing attempt on read only page' page fault 	 	
   125                              <1> ;;	* For loading (opening, reading) a file or disk/drive
   126                              <1> ;;	* As responce to 'allocate additional memory blocks' 
   127                              <1> ;;	  request by running process.
   128                              <1> ;;	* While creating a process, allocating a new buffer,
   129                              <1> ;;	  new page tables etc.
   130                              <1> ;;
   131                              <1> ;;	At first,
   132                              <1> ;;	- 'allocate page' procedure will be called;
   133                              <1> ;,	   if it will return with a valid (>0) physical address
   134                              <1> ;;	   (that means the relevant M.A.T. bit has been RESET)	
   135                              <1> ;;	   relevant memory page/block will be cleared (zeroed).
   136                              <1> ;;	- 'allocate page' will be called for allocating page
   137                              <1> ;;	   directory, page table and running space (data/code).
   138                              <1> ;;	- every successful 'allocate page' call will decrease
   139                              <1> ;;	  'free_pages' count (pointer).
   140                              <1> ;;	- 'out of (insufficient) memory error' will be returned
   141                              <1> ;;	  if 'free_pages' points to a ZERO.
   142                              <1> ;;	- swapping out and swapping in (if it is not a new page)
   143                              <1> ;;	  procedures will be called as responce to 'out of memory'
   144                              <1> ;;	  error except errors caused by attribute conflicts.
   145                              <1> ;;	 (swapper functions)	 
   146                              <1> ;;					
   147                              <1> ;;	At second,
   148                              <1> ;;	- page directory entry will be updated then page table
   149                              <1> ;;	  entry will be updated.		
   150                              <1> ;;
   151                              <1> ;; MEMORY ALLOCATION TABLE FORMAT:
   152                              <1> ;;	- M.A.T. has a size according to available memory as
   153                              <1> ;;	  follows:
   154                              <1> ;;		  - 1 (allocation) bit per 1 page (4096 bytes)
   155                              <1> ;;		  - a bit with value of 0 means allocated page
   156                              <1> ;;		  - a bit with value of 1 means a free page
   157                              <1> ;,	- 'free_pages' pointer holds count of free pages
   158                              <1> ;;	  depending on M.A.T.
   159                              <1> ;;		(NOTE: Free page count will not be checked
   160                              <1> ;;		again -on M.A.T.- after initialization. 
   161                              <1> ;;		Kernel will trust on initial count.)
   162                              <1> ;,	- 'free_pages' count will be decreased by allocation
   163                              <1> ;;	  and it will be increased by deallocation procedures.
   164                              <1> ;;	
   165                              <1> ;;	- Available memory will be calculated during
   166                              <1> ;;	  the kernel's initialization stage (in real mode).
   167                              <1> ;;	  Memory allocation table and kernel page tables 
   168                              <1> ;;	  will be formatted/sized as result of available
   169                              <1> ;;	  memory calculation before paging is enabled.
   170                              <1> ;;
   171                              <1> ;; For 4GB Available/Present Memory: (max. possible memory size)
   172                              <1> ;;	- Memory Allocation Table size will be 128 KB.
   173                              <1> ;;	- Memory allocation for kernel page directory size 
   174                              <1> ;;	  is always 4 KB. (in addition to total allocation size
   175                              <1> ;;	  for page tables)
   176                              <1> ;;	- Memory allocation for kernel page tables (1024 tables)
   177                              <1> ;;	  is 4 MB (1024*4*1024 bytes).
   178                              <1> ;;	- User (available) space will be started 
   179                              <1> ;;	  at 6th MB of the memory (after 1MB+4MB).
   180                              <1> ;;	- The first 640 KB is for kernel's itself plus
   181                              <1> ;;	  memory allocation table and kernel's page directory
   182                              <1> ;;	  (D0000h-EFFFFh may be used as kernel space...)	
   183                              <1> ;;	- B0000h to B7FFFh address space (32 KB) will be used
   184                              <1> ;; 	  for buffers.
   185                              <1> ;;	- ROMBIOS, VIDEO BUFFER and VIDEO ROM space are reserved.
   186                              <1> ;,	  (A0000h-AFFFFh, C0000h-CFFFFh, F0000h-FFFFFh)
   187                              <1> ;;	- Kernel page tables start at 100000h (2nd MB)
   188                              <1> ;;
   189                              <1> ;; For 1GB Available Memory:
   190                              <1> ;;	- Memory Allocation Table size will be 32 KB.
   191                              <1> ;;	- Memory allocation for kernel page directory size 
   192                              <1> ;;	  is always 4 KB. (in addition to total allocation size
   193                              <1> ;;	  for page tables)
   194                              <1> ;;	- Memory allocation for kernel page tables (256 tables)
   195                              <1> ;;	  is 1 MB (256*4*1024 bytes).
   196                              <1> ;;	- User (available) space will be started 
   197                              <1> ;;	  at 3th MB of the memory (after 1MB+1MB).
   198                              <1> ;;	- The first 640 KB is for kernel's itself plus
   199                              <1> ;;	  memory allocation table and kernel's page directory
   200                              <1> ;;	  (D0000h-EFFFFh may be used as kernel space...)	
   201                              <1> ;;	- B0000h to B7FFFh address space (32 KB) will be used
   202                              <1> ;; 	  for buffers.
   203                              <1> ;;	- ROMBIOS, VIDEO BUFFER and VIDEO ROM space are reserved.
   204                              <1> ;,	  (A0000h-AFFFFh, C0000h-CFFFFh, F0000h-FFFFFh)
   205                              <1> ;;	- Kernel page tables start at 100000h (2nd MB).	
   206                              <1> ;;
   207                              <1> ;;
   208                              <1> 
   209                              <1> 
   210                              <1> ;;************************************************************************************
   211                              <1> ;; 
   212                              <1> ;; RETRO UNIX 386 v1 - Paging (Method for Copy On Write paging principle)
   213                              <1> ;; DEMAND PAGING - PARENT&CHILD PAGE TABLE DUPLICATION PRINCIPLES (23/04/2015)
   214                              <1> 
   215                              <1> ;; Main factor: "sys fork" system call 
   216                              <1> ;;	
   217                              <1> ;; 		FORK
   218                              <1> ;;                      |----> parent - duplicated PTEs, read only pages
   219                              <1> ;;  writable pages ---->|
   220                              <1> ;;                      |----> child - duplicated PTEs, read only pages
   221                              <1> ;; 
   222                              <1> ;; AVL bit (0) of Page Table Entry is used as duplication sign 
   223                              <1> ;; 
   224                              <1> ;; AVL Bit 0 [PTE Bit 9] = 'Duplicated PTE belongs to child' sign/flag (if it is set)
   225                              <1> ;; Note: Dirty bit (PTE bit 6) may be used instead of AVL bit 0 (PTE bit 9)
   226                              <1> ;;       -while R/W bit is 0-. 
   227                              <1> ;; 
   228                              <1> ;; Duplicate page tables with writable pages (the 1st sys fork in the process):
   229                              <1> ;; # Parent's Page Table Entries are updated to point same pages as read only, 
   230                              <1> ;;   as duplicated PTE bit  -AVL bit 0, PTE bit 9- are reset/clear.
   231                              <1> ;; # Then Parent's Page Table is copied to Child's Page Table.
   232                              <1> ;; # Child's Page Table Entries are updated as duplicated child bit
   233                              <1> ;;   -AVL bit 0, PTE bit 9- is set.	  
   234                              <1> ;; 
   235                              <1> ;; Duplicate page tables with read only pages (several sys fork system calls):
   236                              <1> ;; # Parent's read only pages are copied to new child pages. 
   237                              <1> ;;   Parent's PTE attributes are not changed.
   238                              <1> ;;   (Because, there is another parent-child fork before this fork! We must not
   239                              <1> ;;    destroy/mix previous fork result).
   240                              <1> ;; # Child's Page Table Entries (which are corresponding to Parent's 
   241                              <1> ;;   read only pages) are set as writable (while duplicated PTE bit is clear). 
   242                              <1> ;; # Parent's PTEs with writable page attribute are updated to point same pages 
   243                              <1> ;;   as read only, (while) duplicated PTE bit is reset (clear).
   244                              <1> ;; # Parent's Page Table Entries (with writable page attribute) are duplicated 
   245                              <1> ;;   as Child's Page Table Entries without copying actual page.
   246                              <1> ;; # Child 's Page Table Entries (which are corresponding to Parent's writable 
   247                              <1> ;;   pages) are updated as duplicated PTE bit (AVL bit 0, PTE bit 9- is set.
   248                              <1> ;; 
   249                              <1> ;; !? WHAT FOR (duplication after duplication):
   250                              <1> ;; In UNIX method for sys fork (a typical 'fork' application in /etc/init)
   251                              <1> ;; program/executable code continues from specified location as child process, 
   252                              <1> ;; returns back previous code location as parent process, every child after 
   253                              <1> ;; every sys fork uses last image of code and data just prior the fork.
   254                              <1> ;; Even if the parent code changes data, the child will not see the changed data 
   255                              <1> ;; after the fork. In Retro UNIX 8086 v1, parent's process segment (32KB)
   256                              <1> ;; was copied to child's process segment (all of code and data) according to
   257                              <1> ;; original UNIX v1 which copies all of parent process code and data -core- 
   258                              <1> ;; to child space -core- but swaps that core image -of child- on to disk.
   259                              <1> ;; If I (Erdogan Tan) would use a method of to copy parent's core
   260                              <1> ;; (complete running image of parent process) to the child process; 
   261                              <1> ;; for big sizes, i would force Retro UNIX 386 v1 to spend many memory pages 
   262                              <1> ;; and times only for a sys fork. (It would excessive reservation for sys fork,
   263                              <1> ;; because sys fork usually is prior to sys exec; sys exec always establishes
   264                              <1> ;; a new/fresh core -running space-, by clearing all code/data content). 
   265                              <1> ;; 'Read Only' page flag ensures page fault handler is needed only for a few write
   266                              <1> ;; attempts between sys fork and sys exec, not more... (I say so by thinking 
   267                              <1> ;; of "/etc/init" content, specially.) sys exec will clear page tables and
   268                              <1> ;; new/fresh pages will be used to load and run new executable/program.
   269                              <1> ;; That is what for i have preferred "copy on write", "duplication" method
   270                              <1> ;; for sharing same read only pages between parent and child processes.
   271                              <1> ;; That is a pitty i have to use new private flag (AVL bit 0, "duplicated PTE 
   272                              <1> ;; belongs to child" sign) for cooperation on duplicated pages between a parent 
   273                              <1> ;; and it's child processes; otherwise parent process would destroy data belongs
   274                              <1> ;; to its child or vice versa; or some pages would remain unclaimed 
   275                              <1> ;; -deallocation problem-.
   276                              <1> ;; Note: to prevent conflicts, read only pages must not be swapped out... 
   277                              <1> ;; 
   278                              <1> ;; WHEN PARENT TRIES TO WRITE IT'S READ ONLY (DUPLICATED) PAGE:
   279                              <1> ;; # Page fault handler will do those:
   280                              <1> ;;   - 'Duplicated PTE' flag (PTE bit 9) is checked (on the failed PTE).
   281                              <1> ;;   - If it is reset/clear, there is a child uses same page.
   282                              <1> ;;   - Parent's read only page -previous page- is copied to a new writable page. 
   283                              <1> ;;   - Parent's PTE is updated as writable page, as unique page (AVL=0)
   284                              <1> ;;   - (Page fault handler whill check this PTE later, if child process causes to
   285                              <1> ;;     page fault due to write attempt on read only page. Of course, the previous 
   286                              <1> ;;     read only page will be converted to writable and unique page which belongs
   287                              <1> ;;     to child process.)	
   288                              <1> ;; WHEN CHILD TRIES TO WRITE IT'S READ ONLY (DUPLICATED) PAGE:
   289                              <1> ;; # Page fault handler will do those:
   290                              <1> ;;   - 'Duplicated PTE' flag (PTE bit 9) is checked (on the failed PTE).
   291                              <1> ;;   - If it is set, there is a parent uses -or was using- same page.
   292                              <1> ;;   - Same PTE address within parent's page table is checked if it has same page
   293                              <1> ;;     address or not. 
   294                              <1> ;;   - If parent's PTE has same address, child will continue with a new writable page.
   295                              <1> ;;     Parent's PTE will point to same (previous) page as writable, unique (AVL=0).	
   296                              <1> ;;   - If parent's PTE has different address, child will continue with it's 
   297                              <1> ;;     own/same page but read only flag (0) will be changed to writable flag (1) and
   298                              <1> ;;     'duplicated PTE (belongs to child)' flag/sign will be cleared/reset. 	  	
   299                              <1> ;; 
   300                              <1> ;; NOTE: When a child process is terminated, read only flags of parent's page tables
   301                              <1> ;;       will be set as writable (and unique) in case of child process was using 
   302                              <1> ;;       same pages with duplicated child PTE sign... Depending on sys fork and 
   303                              <1> ;;       duplication method details, it is not possible multiple child processes
   304                              <1> ;;       were using same page with duplicated PTEs.
   305                              <1> ;; 
   306                              <1> ;;************************************************************************************   
   307                              <1> 
   308                              <1> ;; 08/10/2014
   309                              <1> ;; 11/09/2014 - Retro UNIX 386 v1 PAGING (further) draft
   310                              <1> ;;		by Erdogan Tan (Based on KolibriOS 'memory.inc')
   311                              <1> 
   312                              <1> ;; 'allocate_page' code is derived and modified from KolibriOS
   313                              <1> ;; 'alloc_page' procedure in 'memory.inc' 
   314                              <1> ;; (25/08/2014, Revision: 5057) file 
   315                              <1> ;; by KolibriOS Team (2004-2012)
   316                              <1> 
   317                              <1> allocate_page:
   318                              <1> 	; 17/04/2021 - TRDOS 386 v2.0.4
   319                              <1> 	;	 (temporary modifications)
   320                              <1> 	; 01/07/2015
   321                              <1> 	; 05/05/2015
   322                              <1> 	; 30/04/2015
   323                              <1> 	; 16/10/2014
   324                              <1> 	; 08/10/2014
   325                              <1> 	; 09/09/2014 (Retro UNIX 386 v1 - beginning)
   326                              <1> 	;
   327                              <1> 	; INPUT -> none
   328                              <1> 	;
   329                              <1> 	; OUTPUT ->
   330                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
   331                              <1> 	;	(corresponding MEMORY ALLOCATION TABLE bit is RESET)
   332                              <1> 	;
   333                              <1> 	;	CF = 1 and EAX = 0 
   334                              <1> 	; 		   if there is not a free page to be allocated	
   335                              <1> 	;
   336                              <1> 	; Modified Registers -> none (except EAX)
   337                              <1> 	;
   338 000057E0 A1[C87C0100]        <1> 	mov	eax, [free_pages]
   339 000057E5 21C0                <1> 	and	eax, eax
   340 000057E7 7438                <1> 	jz	short out_of_memory
   341                              <1> 	;
   342 000057E9 53                  <1> 	push	ebx
   343 000057EA 51                  <1> 	push	ecx
   344                              <1> 	;
   345 000057EB BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table offset
   346 000057F0 89D9                <1> 	mov	ecx, ebx
   347                              <1>  				     ; NOTE: 32 (first_page) is initial
   348                              <1> 				     ; value of [next_page].
   349                              <1> 				     ; It points to the first available
   350                              <1> 				     ; page block for users (ring 3) ...	
   351                              <1> 				     ; (MAT offset 32 = 1024/32)	
   352                              <1> 				     ; (at the of the first 4 MB)		
   353 000057F2 031D[CC7C0100]      <1> 	add	ebx, [next_page] ; Free page searching starts from here
   354                              <1> 				 ; next_free_page >> 5
   355 000057F8 030D[D07C0100]      <1> 	add	ecx, [last_page] ; Free page searching ends here
   356                              <1> 				 ; (total_pages - 1) >> 5
   357                              <1> al_p_scan:
   358 000057FE 39CB                <1> 	cmp	ebx, ecx
   359 00005800 770A                <1> 	ja	short al_p_notfound
   360                              <1> 	;
   361                              <1> 	; 01/07/2015
   362                              <1> 	; AMD64 Architecture Programmers Manual
   363                              <1> 	; Volume 3:
   364                              <1> 	; General-Purpose and System Instructions
   365                              <1> 	;
   366                              <1> 	; BSF - Bit Scan Forward
   367                              <1> 	;
   368                              <1> 	;   Searches the value in a register or a memory location
   369                              <1> 	;   (second operand) for the least-significant set bit. 
   370                              <1> 	;   If a set bit is found, the instruction clears the zero flag (ZF)
   371                              <1> 	;   and stores the index of the least-significant set bit in a destination
   372                              <1> 	;   register (first operand). If the second operand contains 0, 
   373                              <1> 	;   the instruction sets ZF to 1 and does not change the contents of the 
   374                              <1> 	;   destination register. The bit index is an unsigned offset from bit 0 
   375                              <1> 	;   of the searched value
   376                              <1> 	;
   377 00005802 0FBC03              <1> 	bsf	eax, [ebx] ; Scans source operand for first bit set (1).
   378                              <1> 			   ; Clear ZF if a bit is found set (1) and 
   379                              <1> 			   ; loads the destination with an index to
   380                              <1> 			   ; first set bit. (0 -> 31) 
   381                              <1> 			   ; Sets ZF to 1 if no bits are found set.
   382 00005805 751C                <1> 	jnz	short al_p_found ; ZF = 0 -> a free page has been found
   383                              <1> 			 ;
   384                              <1> 			 ; NOTE: a Memory Allocation Table bit 
   385                              <1> 			 ;	 with value of 1 means 
   386                              <1> 			 ;	 the corresponding page is free 
   387                              <1> 			 ;	 (Retro UNIX 386 v1 feature only!)
   388 00005807 83C304              <1> 	add	ebx, 4
   389                              <1> 			 ; We return back for searching next page block
   390                              <1> 			 ; NOTE: [free_pages] is not ZERO; so, 
   391                              <1> 			 ;	 we always will find at least 1 free page here.
   392 0000580A EBF2                <1>         jmp     short al_p_scan
   393                              <1> 	;
   394                              <1> al_p_notfound:
   395 0000580C 81E900001000        <1> 	sub	ecx, MEM_ALLOC_TBL
   396 00005812 890D[CC7C0100]      <1> 	mov	[next_page], ecx ; next/first free page = last page 
   397                              <1> 				 ; (deallocate_page procedure will change it)
   398 00005818 31C0                <1> 	xor	eax, eax
   399 0000581A A3[C87C0100]        <1> 	mov	[free_pages], eax ; 0
   400 0000581F 59                  <1> 	pop	ecx
   401 00005820 5B                  <1> 	pop	ebx
   402                              <1> 	;
   403                              <1> ; 17/04/2021
   404                              <1> ; ('swap_out' procedure call is disabled as temporary)
   405                              <1> 
   406                              <1> out_of_memory:
   407                              <1> ;	call	swap_out
   408                              <1> ;	jnc	short al_p_ok  ; [free_pages] = 0, re-allocation by swap_out
   409                              <1> ;	;
   410                              <1> ;	sub 	eax, eax ; 0
   411 00005821 F9                  <1> 	stc
   412 00005822 C3                  <1> 	retn
   413                              <1> 
   414                              <1> al_p_found:
   415 00005823 89D9                <1> 	mov	ecx, ebx
   416 00005825 81E900001000        <1> 	sub	ecx, MEM_ALLOC_TBL
   417 0000582B 890D[CC7C0100]      <1> 	mov	[next_page], ecx ; Set first free page searching start
   418                              <1> 				 ; address/offset (to the next)
   419 00005831 FF0D[C87C0100]      <1>         dec     dword [free_pages] ; 1 page has been allocated (X = X-1) 
   420                              <1> 	;
   421 00005837 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
   422                              <1> 				 ; is copied into the Carry Flag and then cleared
   423                              <1> 				 ; in the destination.
   424                              <1> 				 ;
   425                              <1> 				 ; Reset the bit which is corresponding to the 
   426                              <1> 				 ; (just) allocated page.
   427                              <1> 	; 01/07/2015 (4*8 = 32, 1 allocation byte = 8 pages)	
   428 0000583A C1E103              <1> 	shl	ecx, 3		 ; (page block offset * 32) + page index
   429 0000583D 01C8                <1> 	add	eax, ecx	 ; = page number
   430 0000583F C1E00C              <1> 	shl	eax, 12		 ; physical address of the page (flat/real value)
   431                              <1> 	; EAX = physical address of memory page
   432                              <1> 	;
   433                              <1> 	; NOTE: The relevant page directory and page table entry will be updated
   434                              <1> 	;       according to this EAX value...
   435 00005842 59                  <1> 	pop	ecx
   436 00005843 5B                  <1> 	pop	ebx
   437                              <1> al_p_ok:
   438 00005844 C3                  <1> 	retn
   439                              <1> 
   440                              <1> make_page_dir:
   441                              <1> 	; 18/04/2015
   442                              <1> 	; 12/04/2015
   443                              <1> 	; 23/10/2014
   444                              <1> 	; 16/10/2014
   445                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
   446                              <1> 	;
   447                              <1> 	; INPUT ->
   448                              <1> 	;	none
   449                              <1> 	; OUTPUT ->
   450                              <1> 	;	(EAX = 0)
   451                              <1> 	;	cf = 1 -> insufficient (out of) memory error
   452                              <1> 	;	cf = 0 ->
   453                              <1> 	;	u.pgdir = page directory (physical) address of the current
   454                              <1> 	;		  process/user.
   455                              <1> 	;
   456                              <1> 	; Modified Registers -> EAX
   457                              <1> 	;
   458 00005845 E896FFFFFF          <1> 	call	allocate_page
   459 0000584A 7216                <1> 	jc	short mkpd_error
   460                              <1> 	;
   461 0000584C A3[CC940100]        <1> 	mov	[u.pgdir], eax    ; Page dir address for current user/process
   462                              <1> 				  ; (Physical address)
   463                              <1> clear_page:
   464                              <1> 	; 18/04/2015
   465                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
   466                              <1> 	;
   467                              <1> 	; INPUT ->
   468                              <1> 	;	EAX = physical address of the page
   469                              <1> 	; OUTPUT ->
   470                              <1> 	;	all bytes of the page will be cleared
   471                              <1> 	;
   472                              <1> 	; Modified Registers -> none
   473                              <1> 	;
   474 00005851 57                  <1> 	push	edi
   475 00005852 51                  <1> 	push	ecx
   476 00005853 50                  <1> 	push	eax
   477 00005854 B900040000          <1> 	mov	ecx, PAGE_SIZE / 4
   478 00005859 89C7                <1> 	mov	edi, eax
   479 0000585B 31C0                <1> 	xor	eax, eax
   480 0000585D F3AB                <1> 	rep	stosd
   481 0000585F 58                  <1> 	pop	eax
   482 00005860 59                  <1> 	pop	ecx
   483 00005861 5F                  <1> 	pop	edi
   484                              <1> mkpd_error:
   485                              <1> mkpt_error:
   486 00005862 C3                  <1> 	retn
   487                              <1> 
   488                              <1> make_page_table:
   489                              <1> 	; 23/06/2015
   490                              <1> 	; 18/04/2015
   491                              <1> 	; 12/04/2015
   492                              <1> 	; 16/10/2014
   493                              <1> 	; 09/10/2014 ; (Retro UNIX 386 v1 - beginning)
   494                              <1> 	;
   495                              <1> 	; INPUT ->
   496                              <1> 	;	EBX = virtual (linear) address
   497                              <1> 	;	ECX = page table attributes (lower 12 bits)
   498                              <1> 	;	      (higher 20 bits must be ZERO)
   499                              <1> 	;	      (bit 0 must be 1)	 
   500                              <1> 	;	u.pgdir = page directory (physical) address
   501                              <1> 	; OUTPUT ->
   502                              <1> 	;	EDX = Page directory entry address
   503                              <1> 	;	EAX = Page table address
   504                              <1> 	;	cf = 1 -> insufficient (out of) memory error
   505                              <1> 	;	cf = 0 -> page table address in the PDE (EDX)
   506                              <1> 	;
   507                              <1> 	; Modified Registers -> EAX, EDX
   508                              <1> 	;
   509 00005863 E878FFFFFF          <1> 	call	allocate_page
   510 00005868 72F8                <1> 	jc	short mkpt_error
   511 0000586A E811000000          <1> 	call	set_pde	
   512 0000586F EBE0                <1> 	jmp	short clear_page
   513                              <1> 
   514                              <1> make_page:
   515                              <1> 	; 24/07/2015
   516                              <1> 	; 23/06/2015 ; (Retro UNIX 386 v1 - beginning)
   517                              <1> 	;
   518                              <1> 	; INPUT ->
   519                              <1> 	;	EBX = virtual (linear) address
   520                              <1> 	;	ECX = page attributes (lower 12 bits)
   521                              <1> 	;	      (higher 20 bits must be ZERO)
   522                              <1> 	;	      (bit 0 must be 1)	 
   523                              <1> 	;	u.pgdir = page directory (physical) address
   524                              <1> 	; OUTPUT ->
   525                              <1> 	;	EBX = Virtual address
   526                              <1> 	;	(EDX = PTE value)
   527                              <1> 	;	EAX = Physical address
   528                              <1> 	;	cf = 1 -> insufficient (out of) memory error
   529                              <1> 	;
   530                              <1> 	; Modified Registers -> EAX, EDX
   531                              <1> 	;
   532 00005871 E86AFFFFFF          <1> 	call	allocate_page
   533 00005876 7207                <1> 	jc	short mkp_err
   534 00005878 E821000000          <1> 	call	set_pte	
   535 0000587D 73D2                <1> 	jnc	short clear_page ; 18/04/2015
   536                              <1> mkp_err:
   537 0000587F C3                  <1> 	retn
   538                              <1> 
   539                              <1> 
   540                              <1> set_pde:	; Set page directory entry (PDE)
   541                              <1> 	; 20/07/2015
   542                              <1> 	; 18/04/2015
   543                              <1> 	; 12/04/2015
   544                              <1> 	; 23/10/2014
   545                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
   546                              <1> 	;
   547                              <1> 	; INPUT ->
   548                              <1> 	;	EAX = physical address
   549                              <1> 	;	      (use present value if EAX = 0)
   550                              <1> 	;	EBX = virtual (linear) address
   551                              <1> 	;	ECX = page table attributes (lower 12 bits)
   552                              <1> 	;	      (higher 20 bits must be ZERO)
   553                              <1> 	;	      (bit 0 must be 1)	 
   554                              <1> 	;	u.pgdir = page directory (physical) address
   555                              <1> 	; OUTPUT ->
   556                              <1> 	;	EDX = PDE address
   557                              <1> 	;	EAX = page table address (physical)
   558                              <1> 	;	;(CF=1 -> Invalid page address)
   559                              <1> 	;
   560                              <1> 	; Modified Registers -> EDX
   561                              <1> 	;
   562 00005880 89DA                <1> 	mov	edx, ebx
   563 00005882 C1EA16              <1> 	shr	edx, PAGE_D_SHIFT ; 22
   564 00005885 C1E202              <1> 	shl	edx, 2 ; offset to page directory (1024*4)
   565 00005888 0315[CC940100]      <1> 	add	edx, [u.pgdir]
   566                              <1> 	;
   567 0000588E 21C0                <1> 	and	eax, eax
   568 00005890 7506                <1> 	jnz	short spde_1
   569                              <1> 	;
   570 00005892 8B02                <1> 	mov	eax, [edx]  ; old PDE value
   571                              <1> 	;test	al, 1
   572                              <1> 	;jz	short spde_2
   573 00005894 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h  ; clear lower 12 bits
   574                              <1> spde_1:
   575                              <1> 	;and	cx, 0FFFh
   576 00005898 8902                <1> 	mov	[edx], eax
   577 0000589A 66090A              <1> 	or	[edx], cx
   578 0000589D C3                  <1> 	retn
   579                              <1> ;spde_2: ; error
   580                              <1> ;	stc
   581                              <1> ;	retn
   582                              <1> 
   583                              <1> set_pte:	; Set page table entry (PTE)
   584                              <1> 	; 24/07/2015
   585                              <1> 	; 20/07/2015
   586                              <1> 	; 23/06/2015
   587                              <1> 	; 18/04/2015
   588                              <1> 	; 12/04/2015
   589                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
   590                              <1> 	;
   591                              <1> 	; INPUT ->
   592                              <1> 	;	EAX = physical page address
   593                              <1> 	;	      (use present value if EAX = 0)
   594                              <1> 	;	EBX = virtual (linear) address
   595                              <1> 	;	ECX = page attributes (lower 12 bits)
   596                              <1> 	;	      (higher 20 bits must be ZERO)
   597                              <1> 	;	      (bit 0 must be 1)	 
   598                              <1> 	;	u.pgdir = page directory (physical) address
   599                              <1> 	; OUTPUT ->
   600                              <1> 	;	EAX = physical page address
   601                              <1> 	;	(EDX = PTE value)
   602                              <1> 	;	EBX = virtual address
   603                              <1> 	;
   604                              <1> 	;	CF = 1 -> error
   605                              <1> 	;
   606                              <1> 	; Modified Registers -> EAX, EDX
   607                              <1> 	;
   608 0000589E 50                  <1> 	push	eax
   609 0000589F A1[CC940100]        <1> 	mov	eax, [u.pgdir] ; 20/07/2015
   610 000058A4 E837000000          <1> 	call 	get_pde
   611                              <1> 		; EDX = PDE address
   612                              <1> 		; EAX = PDE value
   613 000058A9 5A                  <1> 	pop	edx ; physical page address
   614 000058AA 722A                <1> 	jc	short spte_err ; PDE not present
   615                              <1> 	;
   616 000058AC 53                  <1> 	push	ebx ; 24/07/2015
   617 000058AD 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 bits
   618                              <1> 			    ; EDX = PT address (physical)	
   619 000058B1 C1EB0C              <1> 	shr	ebx, PAGE_SHIFT ; 12
   620 000058B4 81E3FF030000        <1> 	and	ebx, PTE_MASK	; 03FFh
   621                              <1> 			 ; clear higher 10 bits (PD bits)
   622 000058BA C1E302              <1> 	shl	ebx, 2   ; offset to page table (1024*4)
   623 000058BD 01C3                <1> 	add	ebx, eax
   624                              <1> 	;
   625 000058BF 8B03                <1> 	mov	eax, [ebx] ; Old PTE value
   626 000058C1 A801                <1> 	test	al, 1
   627 000058C3 740C                <1> 	jz	short spte_0
   628 000058C5 09D2                <1> 	or	edx, edx
   629 000058C7 750F                <1> 	jnz	short spte_1
   630 000058C9 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 bits
   631 000058CD 89C2                <1> 	mov	edx, eax
   632 000058CF EB09                <1> 	jmp	short spte_2	
   633                              <1> spte_0:
   634                              <1> 	; If this PTE contains a swap (disk) address,
   635                              <1> 	; it can be updated by using 'swap_in' procedure
   636                              <1> 	; only!
   637 000058D1 21C0                <1> 	and	eax, eax
   638 000058D3 7403                <1> 	jz	short spte_1
   639                              <1> 	; 24/07/2015
   640                              <1> 	; swapped page ! (on disk)
   641 000058D5 5B                  <1> 	pop	ebx
   642                              <1> spte_err:
   643 000058D6 F9                  <1> 	stc
   644 000058D7 C3                  <1> 	retn
   645                              <1> spte_1: 
   646 000058D8 89D0                <1> 	mov	eax, edx
   647                              <1> spte_2:
   648 000058DA 09CA                <1> 	or	edx, ecx
   649                              <1> 	; 23/06/2015
   650 000058DC 8913                <1> 	mov	[ebx], edx ; PTE value in EDX
   651                              <1> 	; 24/07/2015
   652 000058DE 5B                  <1> 	pop	ebx
   653 000058DF C3                  <1> 	retn
   654                              <1> 
   655                              <1> get_pde:	; Get present value of the relevant PDE
   656                              <1> 	; 20/07/2015
   657                              <1> 	; 18/04/2015
   658                              <1> 	; 12/04/2015
   659                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
   660                              <1> 	;
   661                              <1> 	; INPUT ->
   662                              <1> 	;	EBX = virtual (linear) address
   663                              <1> 	;	EAX = page directory (physical) address
   664                              <1> 	; OUTPUT ->
   665                              <1> 	;	EDX = Page directory entry address
   666                              <1> 	;	EAX = Page directory entry value
   667                              <1> 	;	CF = 1 -> PDE not present or invalid ? 
   668                              <1> 	; Modified Registers -> EDX, EAX
   669                              <1> 	;
   670 000058E0 89DA                <1> 	mov	edx, ebx
   671 000058E2 C1EA16              <1> 	shr	edx, PAGE_D_SHIFT ; 22  (12+10)
   672 000058E5 C1E202              <1> 	shl 	edx, 2 ; offset to page directory (1024*4)
   673 000058E8 01C2                <1> 	add	edx, eax ; page directory address (physical)
   674 000058EA 8B02                <1> 	mov	eax, [edx]
   675 000058EC A801                <1> 	test	al, PDE_A_PRESENT ; page table is present or not !
   676 000058EE 751F                <1> 	jnz	short gpte_retn
   677 000058F0 F9                  <1> 	stc
   678                              <1> gpde_retn:	
   679 000058F1 C3                  <1> 	retn
   680                              <1> 
   681                              <1> get_pte:
   682                              <1> 		; Get present value of the relevant PTE
   683                              <1> 	; 29/07/2015
   684                              <1> 	; 20/07/2015
   685                              <1> 	; 18/04/2015
   686                              <1> 	; 12/04/2015
   687                              <1> 	; 10/10/2014 ; (Retro UNIX 386 v1 - beginning)
   688                              <1> 	;
   689                              <1> 	; INPUT ->
   690                              <1> 	;	EBX = virtual (linear) address
   691                              <1> 	;	EAX = page directory (physical) address
   692                              <1> 	; OUTPUT ->
   693                              <1> 	;	EDX = Page table entry address (if CF=0)
   694                              <1> 	;	      Page directory entry address (if CF=1)
   695                              <1> 	;            (Bit 0 value is 0 if PT is not present)
   696                              <1> 	;	EAX = Page table entry value (page address)
   697                              <1> 	;	CF = 1 -> PDE not present or invalid ? 
   698                              <1> 	; Modified Registers -> EAX, EDX
   699                              <1> 	;
   700 000058F2 E8E9FFFFFF          <1> 	call 	get_pde
   701 000058F7 72F8                <1> 	jc	short gpde_retn	; page table is not present
   702                              <1> 	;jnc	short gpte_1
   703                              <1> 	;retn
   704                              <1> ;gpte_1:
   705 000058F9 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 bits
   706 000058FD 89DA                <1> 	mov	edx, ebx
   707 000058FF C1EA0C              <1> 	shr	edx, PAGE_SHIFT ; 12
   708 00005902 81E2FF030000        <1> 	and	edx, PTE_MASK	; 03FFh
   709                              <1> 			 ; clear higher 10 bits (PD bits)
   710 00005908 C1E202              <1> 	shl	edx, 2 ; offset from start of page table (1024*4)
   711 0000590B 01C2                <1> 	add	edx, eax
   712 0000590D 8B02                <1> 	mov	eax, [edx]
   713                              <1> gpte_retn:
   714 0000590F C3                  <1> 	retn
   715                              <1> 
   716                              <1> deallocate_page_dir:
   717                              <1> 	; 15/09/2015
   718                              <1> 	; 05/08/2015
   719                              <1> 	; 30/04/2015
   720                              <1> 	; 28/04/2015
   721                              <1> 	; 17/10/2014
   722                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
   723                              <1> 	;
   724                              <1> 	; INPUT ->
   725                              <1> 	;	EAX = PHYSICAL ADDRESS OF THE PAGE DIRECTORY (CHILD)
   726                              <1> 	;	EBX = PHYSICAL ADDRESS OF THE PARENT'S PAGE DIRECTORY
   727                              <1> 	; OUTPUT ->
   728                              <1> 	;	All of page tables in the page directory
   729                              <1> 	;	and page dir's itself will be deallocated
   730                              <1> 	;	except 'read only' duplicated pages (will be converted
   731                              <1> 	;	to writable pages).
   732                              <1> 	;
   733                              <1> 	; Modified Registers -> EAX
   734                              <1> 	;
   735                              <1> 	;
   736 00005910 56                  <1> 	push	esi
   737 00005911 51                  <1> 	push	ecx
   738 00005912 50                  <1> 	push	eax
   739 00005913 89C6                <1> 	mov	esi, eax 
   740 00005915 31C9                <1> 	xor	ecx, ecx
   741                              <1> 	; The 1st PDE points to Kernel Page Table 0 (the 1st 4MB),
   742                              <1> 	; it must not be deallocated
   743 00005917 890E                <1> 	mov	[esi], ecx ; 0 ; clear PDE 0
   744                              <1> dapd_0:
   745 00005919 AD                  <1> 	lodsd
   746 0000591A A801                <1> 	test	al, PDE_A_PRESENT ; bit 0, present flag (must be 1)
   747 0000591C 7409                <1> 	jz	short dapd_1	
   748 0000591E 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
   749 00005922 E812000000          <1> 	call	deallocate_page_table			
   750                              <1> dapd_1:
   751 00005927 41                  <1> 	inc	ecx ; page directory entry index
   752 00005928 81F900040000        <1> 	cmp	ecx, PAGE_SIZE / 4 ; 1024
   753 0000592E 72E9                <1> 	jb	short dapd_0
   754                              <1> dapd_2:
   755 00005930 58                  <1> 	pop	eax
   756 00005931 E869000000          <1> 	call	deallocate_page	; deallocate the page dir's itself
   757 00005936 59                  <1> 	pop	ecx
   758 00005937 5E                  <1> 	pop	esi
   759 00005938 C3                  <1> 	retn
   760                              <1> 
   761                              <1> deallocate_page_table:
   762                              <1> 	; 29/08/2023 - TRDOS 386 v2.0.6
   763                              <1> 	; 17/04/2021 - TRDOS 386 v2.0.4
   764                              <1> 	;	 (temporary modifications)
   765                              <1> 	; 12/07/2016
   766                              <1> 	; 19/09/2015
   767                              <1> 	; 15/09/2015
   768                              <1> 	; 05/08/2015
   769                              <1> 	; 30/04/2015
   770                              <1> 	; 28/04/2015
   771                              <1> 	; 24/10/2014
   772                              <1> 	; 23/10/2014
   773                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
   774                              <1> 	;
   775                              <1> 	; INPUT ->
   776                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE PAGE TABLE
   777                              <1> 	;	EBX = PHYSICAL ADDRESS OF THE PARENT'S PAGE DIRECTORY
   778                              <1> 	;	(ECX = page directory entry index)
   779                              <1> 	; OUTPUT ->
   780                              <1> 	;	All of pages in the page table and page table's itself
   781                              <1> 	;	will be deallocated except 'read only' duplicated pages
   782                              <1> 	;	(will be converted to writable pages).
   783                              <1> 	;
   784                              <1> 	; Modified Registers -> EAX
   785                              <1> 	;
   786 00005939 56                  <1> 	push	esi
   787 0000593A 57                  <1> 	push	edi
   788 0000593B 52                  <1> 	push	edx
   789 0000593C 50                  <1> 	push	eax ; *
   790 0000593D 89C6                <1> 	mov	esi, eax 
   791 0000593F 31FF                <1> 	xor	edi, edi ; 0
   792                              <1> dapt_0:
   793 00005941 AD                  <1> 	lodsd
   794 00005942 A801                <1> 	test	al, PTE_A_PRESENT ; bit 0, present flag (must be 1)
   795 00005944 744C                <1> 	jz	short dapt_1
   796                              <1> 	;
   797 00005946 A802                <1> 	test	al, PTE_A_WRITE   ; bit 1, writable (r/w) flag
   798                              <1> 				  ; (must be 1)
   799 00005948 753D                <1> 	jnz	short dapt_3
   800                              <1> 	; Read only -duplicated- page (belongs to a parent or a child)
   801 0000594A 66A90002            <1>         test    ax, PTE_DUPLICATED ; Was this page duplicated 
   802                              <1> 				   ; as child's page ?
   803 0000594E 7442                <1> 	jz	short dapt_4 ; Clear PTE but don't deallocate the page!
   804                              <1> 	; check the parent's PTE value is read only & same page or not.. 
   805                              <1> 	; ECX = page directory entry index (0-1023)
   806 00005950 53                  <1> 	push	ebx
   807 00005951 51                  <1> 	push	ecx
   808                              <1> 	;shl	cx, 2 ; *4
   809                              <1> 	; 29/08/2023
   810 00005952 C1E102              <1> 	shl	ecx, 2
   811 00005955 01CB                <1> 	add	ebx, ecx ; PDE offset (for the parent)
   812 00005957 8B0B                <1> 	mov	ecx, [ebx]
   813 00005959 F6C101              <1> 	test	cl, PDE_A_PRESENT ; present (valid) or not ?
   814 0000595C 7427                <1> 	jz	short dapt_2	; parent process does not use this page
   815 0000595E 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
   816                              <1> 	; EDI = page table entry index (0-1023)
   817 00005963 89FA                <1> 	mov	edx, edi 
   818                              <1> 	;shl	dx, 2 ; *4
   819                              <1> 	; 29/08/2023
   820 00005965 C1E202              <1> 	shl	edx, 2
   821 00005968 01CA                <1> 	add	edx, ecx ; PTE offset (for the parent)
   822 0000596A 8B1A                <1> 	mov	ebx, [edx]
   823 0000596C F6C301              <1> 	test	bl, PTE_A_PRESENT ; present or not ?
   824 0000596F 7414                <1> 	jz	short dapt_2	; parent process does not use this page
   825 00005971 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; Clear attribute bits 
   826 00005975 6681E300F0          <1> 	and	bx, PTE_A_CLEAR ; 0F000h ; Clear attribute bits
   827 0000597A 39D8                <1> 	cmp	eax, ebx	; parent's and child's pages are same ?
   828 0000597C 7507                <1> 	jne	short dapt_2	; not same page
   829                              <1> 				; deallocate the child's page
   830 0000597E 800A02              <1>         or      byte [edx], PTE_A_WRITE ; convert to writable page (parent)
   831 00005981 59                  <1> 	pop	ecx
   832 00005982 5B                  <1> 	pop	ebx
   833 00005983 EB0D                <1> 	jmp	short dapt_4
   834                              <1> 
   835                              <1> ; 17/04/2021
   836                              <1> ; ('dapt_1' is disabled as temporary)
   837                              <1> ;
   838                              <1> ;dapt_1:
   839                              <1> ;	or	eax, eax	; swapped page ?
   840                              <1> ;	jz	short dapt_5	; no
   841                              <1> ;				; yes
   842                              <1> ;	shr	eax, 1
   843                              <1> ;	call	unlink_swap_block ; Deallocate swapped page block
   844                              <1> ;				  ; on the swap disk (or in file)
   845                              <1> ;	jmp	short dapt_5
   846                              <1> dapt_2:
   847 00005985 59                  <1> 	pop	ecx
   848 00005986 5B                  <1> 	pop	ebx
   849                              <1> dapt_3:	
   850                              <1> 	; 12/07/2016
   851 00005987 66A90004            <1> 	test	ax, PTE_SHARED ; shared or direct memory access indicator
   852 0000598B 7505                <1> 	jnz	short dapt_4   ; AVL bit 1 = 1, do not deallocate this page!
   853                              <1> 	;
   854                              <1> 	;and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
   855 0000598D E80D000000          <1> 	call	deallocate_page ; set the mem allocation bit of this page
   856                              <1> dapt_4:
   857                              <1> 	; 20/10/2023
   858                              <1> 	; PTE clearing here was/is not necessary
   859                              <1> 	; because this page table is being deallocated
   860                              <1> 	; and it's PTEs will be ineffective.
   861                              <1> 
   862                              <1> 	;mov	dword [esi-4], 0 ; clear/reset PTE (child, dupl. as parent)
   863                              <1> 
   864                              <1> dapt_1:	; 17/04/2021 (temporary)
   865                              <1> dapt_5:
   866 00005992 47                  <1> 	inc	edi ; page table entry index
   867 00005993 81FF00040000        <1> 	cmp	edi, PAGE_SIZE / 4 ; 1024
   868 00005999 72A6                <1> 	jb	short dapt_0
   869                              <1> 	;
   870 0000599B 58                  <1> 	pop	eax ; *
   871 0000599C 5A                  <1> 	pop	edx
   872 0000599D 5F                  <1> 	pop	edi	
   873 0000599E 5E                  <1> 	pop	esi
   874                              <1> 	;
   875                              <1> 	;call	deallocate_page	; deallocate the page table's itself
   876                              <1> 	;retn
   877                              <1> 
   878                              <1> deallocate_page:
   879                              <1> 	; 15/09/2015
   880                              <1> 	; 28/04/2015
   881                              <1> 	; 10/03/2015
   882                              <1> 	; 17/10/2014
   883                              <1> 	; 12/10/2014 (Retro UNIX 386 v1 - beginning)
   884                              <1> 	;
   885                              <1> 	; INPUT -> 
   886                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
   887                              <1> 	; OUTPUT ->
   888                              <1> 	;	[free_pages] is increased
   889                              <1> 	;	(corresponding MEMORY ALLOCATION TABLE bit is SET)
   890                              <1> 	;	CF = 1 if the page is already deallocated
   891                              <1> 	; 	       (or not allocated) before.  
   892                              <1> 	;
   893                              <1> 	; Modified Registers -> EAX
   894                              <1> 	;
   895 0000599F 53                  <1> 	push	ebx
   896 000059A0 52                  <1> 	push	edx
   897                              <1> 	;
   898 000059A1 C1E80C              <1> 	shr	eax, PAGE_SHIFT      ; shift physical address to 
   899                              <1> 				     ; 12 bits right
   900                              <1> 				     ; to get page number
   901 000059A4 89C2                <1> 	mov	edx, eax
   902                              <1> 	; 15/09/2015
   903 000059A6 C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
   904                              <1> 				     ; (1 allocation bit = 1 page)
   905                              <1> 				     ; (1 allocation bytes = 8 pages)
   906 000059A9 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
   907                              <1> 				     ; (to get 32 bit position)			
   908                              <1> 	;
   909 000059AC BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table address
   910 000059B1 01D3                <1> 	add	ebx, edx
   911 000059B3 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only
   912                              <1> 				     ; (allocation bit position)	 
   913 000059B6 3B15[CC7C0100]      <1> 	cmp 	edx, [next_page]     ; is the new free page address lower
   914                              <1> 				     ; than the address in 'next_page' ?
   915                              <1> 				     ; (next/first free page value)		
   916 000059BC 7306                <1> 	jnb	short dap_1	     ; no	
   917 000059BE 8915[CC7C0100]      <1> 	mov	[next_page], edx     ; yes
   918                              <1> dap_1:
   919 000059C4 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate page
   920                              <1> 				     ; set relevant bit to 1.
   921                              <1> 				     ; set CF to the previous bit value	
   922                              <1> 	;cmc			     ; complement carry flag	
   923                              <1> 	;jc	short dap_2	     ; do not increase free_pages count
   924                              <1> 				     ; if the page is already deallocated
   925                              <1> 				     ; before.	
   926 000059C7 FF05[C87C0100]      <1>         inc     dword [free_pages]
   927                              <1> dap_2:
   928 000059CD 5A                  <1> 	pop	edx
   929 000059CE 5B                  <1> 	pop	ebx
   930 000059CF C3                  <1> 	retn
   931                              <1> 
   932                              <1> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   933                              <1> ;;                                                              ;;
   934                              <1> ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
   935                              <1> ;; Distributed under terms of the GNU General Public License    ;;
   936                              <1> ;;                                                              ;;
   937                              <1> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   938                              <1> 
   939                              <1> ;;$Revision: 5057 $
   940                              <1> 
   941                              <1> 
   942                              <1> ;;align 4
   943                              <1> ;;proc alloc_page
   944                              <1> 
   945                              <1> ;;        pushfd
   946                              <1> ;;        cli
   947                              <1> ;;        push    ebx
   948                              <1> ;;;//-
   949                              <1> ;;        cmp     [pg_data.pages_free], 1
   950                              <1> ;;        jle     .out_of_memory
   951                              <1> ;;;//-
   952                              <1> ;;
   953                              <1> ;;        mov     ebx, [page_start]
   954                              <1> ;;        mov     ecx, [page_end]
   955                              <1> ;;.l1:
   956                              <1> ;;        bsf     eax, [ebx];
   957                              <1> ;;        jnz     .found
   958                              <1> ;;        add     ebx, 4
   959                              <1> ;;        cmp     ebx, ecx
   960                              <1> ;;        jb      .l1
   961                              <1> ;;        pop     ebx
   962                              <1> ;;        popfd
   963                              <1> ;;        xor     eax, eax
   964                              <1> ;;        ret
   965                              <1> ;;.found:
   966                              <1> ;;;//-
   967                              <1> ;;        dec     [pg_data.pages_free]
   968                              <1> ;;        jz      .out_of_memory
   969                              <1> ;;;//-
   970                              <1> ;;        btr     [ebx], eax
   971                              <1> ;;        mov     [page_start], ebx
   972                              <1> ;;        sub     ebx, sys_pgmap
   973                              <1> ;;        lea     eax, [eax+ebx*8]
   974                              <1> ;;        shl     eax, 12
   975                              <1> ;;;//-       dec [pg_data.pages_free]
   976                              <1> ;;        pop     ebx
   977                              <1> ;;        popfd
   978                              <1> ;;        ret
   979                              <1> ;;;//-
   980                              <1> ;;.out_of_memory:
   981                              <1> ;;        mov     [pg_data.pages_free], 1
   982                              <1> ;;        xor     eax, eax
   983                              <1> ;;        pop     ebx
   984                              <1> ;;        popfd
   985                              <1> ;;        ret
   986                              <1> ;;;//-
   987                              <1> ;;endp
   988                              <1> 
   989                              <1> duplicate_page_dir:
   990                              <1> 	; 21/09/2015
   991                              <1> 	; 31/08/2015
   992                              <1> 	; 20/07/2015
   993                              <1> 	; 28/04/2015
   994                              <1> 	; 27/04/2015
   995                              <1> 	; 18/04/2015
   996                              <1> 	; 12/04/2015
   997                              <1> 	; 18/10/2014
   998                              <1> 	; 16/10/2014 (Retro UNIX 386 v1 - beginning)
   999                              <1> 	;
  1000                              <1> 	; INPUT -> 
  1001                              <1> 	;	[u.pgdir] = PHYSICAL (real/flat) ADDRESS of the parent's
  1002                              <1> 	;		    page directory.
  1003                              <1> 	; OUTPUT ->
  1004                              <1> 	;	EAX =  PHYSICAL (real/flat) ADDRESS of the child's
  1005                              <1> 	;	       page directory.
  1006                              <1> 	;	(New page directory with new page table entries.)
  1007                              <1> 	;	(New page tables with read only copies of the parent's
  1008                              <1> 	;	pages.)
  1009                              <1> 	;	EAX = 0 -> Error (CF = 1)
  1010                              <1> 	;
  1011                              <1> 	; Modified Registers -> none (except EAX)
  1012                              <1> 	;
  1013 000059D0 E80BFEFFFF          <1> 	call	allocate_page
  1014 000059D5 723E                <1> 	jc	short dpd_err
  1015                              <1> 	;
  1016 000059D7 55                  <1> 	push	ebp ; 20/07/2015
  1017 000059D8 56                  <1> 	push	esi
  1018 000059D9 57                  <1> 	push	edi
  1019 000059DA 53                  <1> 	push	ebx
  1020 000059DB 51                  <1> 	push	ecx
  1021 000059DC 8B35[CC940100]      <1> 	mov	esi, [u.pgdir]
  1022 000059E2 89C7                <1> 	mov	edi, eax
  1023 000059E4 50                  <1> 	push	eax ; save child's page directory address
  1024                              <1> 	; 31/08/2015
  1025                              <1> 	; copy PDE 0 from the parent's page dir to the child's page dir
  1026                              <1> 	; (use same system space for all user page tables) 
  1027 000059E5 A5                  <1> 	movsd
  1028 000059E6 BD00004000          <1> 	mov	ebp, 1024*4096 ; pass the 1st 4MB (system space)
  1029 000059EB B9FF030000          <1> 	mov	ecx, (PAGE_SIZE / 4) - 1 ; 1023
  1030                              <1> dpd_0:	
  1031 000059F0 AD                  <1> 	lodsd
  1032                              <1> 	;or	eax, eax
  1033                              <1>         ;jnz     short dpd_1
  1034 000059F1 A801                <1> 	test	al, PDE_A_PRESENT ;  bit 0 =  1
  1035 000059F3 7508                <1> 	jnz	short dpd_1
  1036                              <1>  	; 20/07/2015 (virtual address at the end of the page table)	
  1037 000059F5 81C500004000        <1> 	add	ebp, 1024*4096 ; page size * PTE count
  1038 000059FB EB0F                <1> 	jmp	short dpd_2
  1039                              <1> dpd_1:	
  1040 000059FD 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear attribute bits
  1041 00005A01 89C3                <1> 	mov	ebx, eax
  1042                              <1> 	; EBX = Parent's page table address
  1043 00005A03 E81F000000          <1> 	call	duplicate_page_table
  1044 00005A08 720C                <1> 	jc	short dpd_p_err
  1045                              <1> 	; EAX = Child's page table address
  1046 00005A0A 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER
  1047                              <1> 			 ; set bit 0, bit 1 and bit 2 to 1
  1048                              <1> 			 ; (present, writable, user)
  1049                              <1> dpd_2:
  1050 00005A0C AB                  <1> 	stosd
  1051 00005A0D E2E1                <1> 	loop	dpd_0
  1052                              <1> 	;
  1053 00005A0F 58                  <1> 	pop	eax  ; restore child's page directory address
  1054                              <1> dpd_3:
  1055 00005A10 59                  <1> 	pop	ecx
  1056 00005A11 5B                  <1> 	pop	ebx
  1057 00005A12 5F                  <1> 	pop	edi
  1058 00005A13 5E                  <1> 	pop	esi
  1059 00005A14 5D                  <1> 	pop	ebp ; 20/07/2015
  1060                              <1> dpd_err:
  1061 00005A15 C3                  <1> 	retn
  1062                              <1> dpd_p_err:
  1063                              <1> 	; release the allocated pages missing (recover free space)
  1064 00005A16 58                  <1> 	pop	eax  ; the new page directory address (physical)
  1065 00005A17 8B1D[CC940100]      <1> 	mov	ebx, [u.pgdir] ; parent's page directory address 
  1066 00005A1D E8EEFEFFFF          <1> 	call 	deallocate_page_dir
  1067 00005A22 29C0                <1> 	sub	eax, eax ; 0
  1068 00005A24 F9                  <1> 	stc
  1069 00005A25 EBE9                <1> 	jmp	short dpd_3	
  1070                              <1> 
  1071                              <1> duplicate_page_table:
  1072                              <1> 	; 17/04/2021 - TRDOS 386 v2.0.4
  1073                              <1> 	;	 (temporary modifications)
  1074                              <1> 	; 20/02/2017
  1075                              <1> 	; 21/09/2015
  1076                              <1> 	; 20/07/2015
  1077                              <1> 	; 05/05/2015
  1078                              <1> 	; 28/04/2015
  1079                              <1> 	; 27/04/2015
  1080                              <1> 	; 18/04/2015
  1081                              <1> 	; 18/10/2014
  1082                              <1> 	; 16/10/2014 (Retro UNIX 386 v1 - beginning)
  1083                              <1> 	;
  1084                              <1> 	; INPUT -> 
  1085                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS of the parent's page table.
  1086                              <1> 	;       20/02/2017		 
  1087                              <1> 	;	EBP = Linear address of the page (from 'duplicate_page_dir')
  1088                              <1> 	;	      (Linear address = CORE + user's virtual address) 	
  1089                              <1> 	; OUTPUT ->
  1090                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS of the child's page table.
  1091                              <1> 	;	      (with 'read only' attribute of page table entries)
  1092                              <1> 	;	20/02/2017
  1093                              <1> 	;	EBP = Next linear page address (for 'duplicate_page_dir')
  1094                              <1> 	;	
  1095                              <1> 	;	CF = 1 -> error 
  1096                              <1> 	;
  1097                              <1> 	; Modified Registers -> EBP (except EAX)
  1098                              <1> 	;
  1099 00005A27 E8B4FDFFFF          <1> 	call	allocate_page
  1100 00005A2C 7258                <1> 	jc	short dpt_err
  1101                              <1> 	;
  1102 00005A2E 50                  <1> 	push	eax ; *
  1103 00005A2F 56                  <1> 	push	esi
  1104 00005A30 57                  <1> 	push	edi
  1105 00005A31 52                  <1> 	push	edx
  1106 00005A32 51                  <1> 	push	ecx
  1107                              <1> 	;
  1108 00005A33 89DE                <1> 	mov	esi, ebx
  1109 00005A35 89C7                <1> 	mov	edi, eax
  1110 00005A37 89C2                <1> 	mov	edx, eax
  1111 00005A39 81C200100000        <1> 	add	edx, PAGE_SIZE 	
  1112                              <1> dpt_0:
  1113 00005A3F AD                  <1> 	lodsd
  1114 00005A40 21C0                <1> 	and	eax, eax
  1115 00005A42 7432                <1> 	jz	short dpt_3
  1116 00005A44 A801                <1> 	test	al, PTE_A_PRESENT ;  bit 0 =  1
  1117                              <1> 	; 17/04/2021 (temporary)
  1118                              <1> 	;jnz	short dpt_1
  1119 00005A46 7439                <1> 	jz	short dpt_p_err
  1120                              <1> 
  1121                              <1> ; 17/04/2021
  1122                              <1> ; ('reload_page' procedure call is disabled as temporary)
  1123                              <1> ;
  1124                              <1> ;	; 20/07/2015
  1125                              <1> ;	; ebp = virtual (linear) address of the memory page
  1126                              <1> ;	call	reload_page ; 28/04/2015
  1127                              <1> ;	jc	short dpt_p_err
  1128                              <1> dpt_1:
  1129                              <1> 	; 21/09/2015
  1130 00005A48 89C1                <1> 	mov	ecx, eax
  1131 00005A4A 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
  1132 00005A4E F6C102              <1> 	test	cl, PTE_A_WRITE ; writable page ?
  1133 00005A51 751A                <1> 	jnz	short dpt_2
  1134                              <1> 	; Read only (parent) page
  1135                              <1> 	; 	- there is a third process which uses this page -
  1136                              <1> 	; Allocate a new page for the child process
  1137 00005A53 E888FDFFFF          <1> 	call	allocate_page
  1138 00005A58 7227                <1> 	jc	short dpt_p_err
  1139 00005A5A 57                  <1> 	push	edi
  1140 00005A5B 56                  <1> 	push	esi
  1141 00005A5C 89CE                <1> 	mov	esi, ecx
  1142 00005A5E 89C7                <1> 	mov	edi, eax
  1143 00005A60 B900040000          <1> 	mov	ecx, PAGE_SIZE/4
  1144 00005A65 F3A5                <1> 	rep	movsd	; copy page (4096 bytes)
  1145 00005A67 5E                  <1> 	pop	esi
  1146 00005A68 5F                  <1> 	pop	edi
  1147                              <1> 	;
  1148                              <1> 
  1149                              <1> ; 17/04/2021
  1150                              <1> ; ('add_to_swap_queue' procedure call is disabled as temporary)
  1151                              <1> ; 
  1152                              <1> ;	push	ebx
  1153                              <1> ;	push	eax
  1154                              <1> ;	; 20/07/2015
  1155                              <1> ;	mov	ebx, ebp
  1156                              <1> ;	; ebx = virtual (linear) address of the memory page
  1157                              <1> ;	call	add_to_swap_queue
  1158                              <1> ;	pop	eax
  1159                              <1> ;	pop	ebx
  1160                              <1> 
  1161                              <1> 	; 21/09/2015
  1162 00005A69 0C07                <1> 	or	al, PTE_A_USER+PTE_A_WRITE+PTE_A_PRESENT 
  1163                              <1> 		; user + writable + present page
  1164 00005A6B EB09                <1> 	jmp	short dpt_3
  1165                              <1> dpt_2:
  1166                              <1> 	;or	ax, PTE_A_USER+PTE_A_PRESENT 
  1167 00005A6D 0C05                <1> 	or	al, PTE_A_USER+PTE_A_PRESENT 
  1168                              <1> 		    ; (read only page!)
  1169 00005A6F 8946FC              <1> 	mov	[esi-4], eax ; update parent's PTE
  1170 00005A72 660D0002            <1> 	or      ax, PTE_DUPLICATED  ; (read only page & duplicated PTE!)
  1171                              <1> dpt_3:
  1172 00005A76 AB                  <1> 	stosd  ; EDI points to child's PTE  	 
  1173                              <1> 	;
  1174 00005A77 81C500100000        <1> 	add	ebp, 4096 ; 20/07/2015 (next page)
  1175                              <1> 	;
  1176 00005A7D 39D7                <1> 	cmp	edi, edx
  1177 00005A7F 72BE                <1> 	jb	short dpt_0
  1178                              <1> dpt_p_err:
  1179 00005A81 59                  <1> 	pop	ecx
  1180 00005A82 5A                  <1> 	pop	edx
  1181 00005A83 5F                  <1> 	pop	edi
  1182 00005A84 5E                  <1> 	pop	esi
  1183 00005A85 58                  <1> 	pop	eax ; *
  1184                              <1> dpt_err:
  1185 00005A86 C3                  <1> 	retn
  1186                              <1> 
  1187                              <1> page_fault_handler:	; CPU EXCEPTION 0Eh (14) : Page Fault !
  1188                              <1> 	; 29/11/2023 - TRDOS 386 v2.0.7
  1189                              <1> 	; 17/04/2021 - TRDOS 386 v2.0.4
  1190                              <1> 	;	 (temporary modifications)
  1191                              <1> 	; 21/09/2015
  1192                              <1> 	; 19/09/2015
  1193                              <1> 	; 17/09/2015
  1194                              <1> 	; 28/08/2015
  1195                              <1> 	; 20/07/2015
  1196                              <1> 	; 28/06/2015
  1197                              <1> 	; 03/05/2015
  1198                              <1> 	; 30/04/2015
  1199                              <1> 	; 18/04/2015
  1200                              <1> 	; 12/04/2015
  1201                              <1> 	; 30/10/2014
  1202                              <1> 	; 11/09/2014
  1203                              <1> 	; 10/09/2014 (Retro UNIX 386 v1 - beginning)
  1204                              <1> 	;
  1205                              <1> 	; Note: This is not an interrupt/exception handler.
  1206                              <1> 	;	This is a 'page fault remedy' subroutine 
  1207                              <1> 	;	which will be called by standard/uniform
  1208                              <1> 	;	exception handler.
  1209                              <1> 	;
  1210                              <1> 	; INPUT -> 
  1211                              <1> 	;	[error_code] = 32 bit ERROR CODE (lower 5 bits are valid)
  1212                              <1> 	;
  1213                              <1> 	;	cr2 = the virtual (linear) address 
  1214                              <1> 	;	      which has caused to page fault (19/09/2015)
  1215                              <1> 	;
  1216                              <1> 	; OUTPUT ->
  1217                              <1> 	;	(corresponding PAGE TABLE ENTRY is mapped/set)
  1218                              <1> 	;	EAX = 0 -> no error
  1219                              <1> 	;	EAX > 0 -> error code in EAX (also CF = 1)
  1220                              <1> 	;
  1221                              <1> 	; Modified Registers -> none (except EAX)
  1222                              <1> 	;	
  1223                              <1>         ;
  1224                              <1>         ; ERROR CODE:
  1225                              <1> 	;	 31  .....	4   3	2   1	0
  1226                              <1> 	;	+---+-- --+---+---+---+---+---+---+
  1227                              <1> 	;	|   Reserved  | I | R | U | W | P |
  1228                              <1> 	;	+---+-- --+---+---+---+---+---+---+
  1229                              <1> 	;
  1230                              <1> 	; P : PRESENT -	When set, the page fault was caused by 
  1231                              <1>     	;		a page-protection violation. When not set,
  1232                              <1> 	;		it was caused by a non-present page.
  1233                              <1> 	; W : WRITE   -	When set, the page fault was caused by
  1234                              <1> 	;		a page write. When not set, it was caused
  1235                              <1> 	;		by a page read.
  1236                              <1> 	; U : USER    -	When set, the page fault was caused 
  1237                              <1> 	;		while CPL = 3. 
  1238                              <1> 	;		This does not necessarily mean that
  1239                              <1> 	;		the page fault was a privilege violation.
  1240                              <1> 	; R : RESERVD -	When set, the page fault was caused by
  1241                              <1> 	;     WRITE	reading a 1 in a reserved field.
  1242                              <1> 	; I : INSTRUC -	When set, the page fault was caused by
  1243                              <1> 	;     FETCH	an instruction fetch
  1244                              <1> 	;
  1245                              <1> 	;; x86 (32 bit) VIRTUAL ADDRESS TRANSLATION
  1246                              <1> 	;  31               22                  12 11                    0
  1247                              <1> 	; +-------------------+-------------------+-----------------------+
  1248                              <1>        	; | PAGE DIR. ENTRY # | PAGE TAB. ENTRY # |        OFFSET         |
  1249                              <1>        	; +-------------------+-------------------+-----------------------+
  1250                              <1> 	;
  1251                              <1> 
  1252                              <1> 	;; CR3 REGISTER (Control Register 3)
  1253                              <1> 	;  31                                   12             5 4 3 2   0
  1254                              <1> 	; +---------------------------------------+-------------+---+-----+
  1255                              <1>       	; |                                       |  		|P|P|     |
  1256                              <1>       	; |   PAGE DIRECTORY TABLE BASE ADDRESS   |  reserved	|C|W|rsvrd|
  1257                              <1>       	; |                                       | 		|D|T|     |
  1258                              <1>    	; +---------------------------------------+-------------+---+-----+
  1259                              <1> 	;
  1260                              <1> 	;	PWT    - WRITE THROUGH
  1261                              <1> 	;	PCD    - CACHE DISABLE		
  1262                              <1> 	;
  1263                              <1> 	;
  1264                              <1> 	;; x86 PAGE DIRECTORY ENTRY (4 KByte Page)
  1265                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
  1266                              <1> 	; +---------------------------------------+-----+---+-+-+---+-+-+-+
  1267                              <1>       	; |                                       |     | | | | |P|P|U|R| |
  1268                              <1>       	; |     PAGE TABLE BASE ADDRESS 31..12    | AVL |G|0|D|A|C|W|/|/|P|
  1269                              <1>       	; |                                       |     | | | | |D|T|S|W| |
  1270                              <1>    	; +---------------------------------------+-----+---+-+-+---+-+-+-+
  1271                              <1> 	;
  1272                              <1>         ;       P      - PRESENT
  1273                              <1>         ;       R/W    - READ/WRITE
  1274                              <1>         ;       U/S    - USER/SUPERVISOR
  1275                              <1> 	;	PWT    - WRITE THROUGH
  1276                              <1> 	;	PCD    - CACHE DISABLE	
  1277                              <1> 	;	A      - ACCESSED	
  1278                              <1>         ;       D      - DIRTY (IGNORED)
  1279                              <1> 	;	PAT    - PAGE ATTRIBUTE TABLE INDEX (CACHE BEHAVIOR)
  1280                              <1> 	;	G      - GLOBAL	(IGNORED) 
  1281                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
  1282                              <1> 	;
  1283                              <1> 	;
  1284                              <1> 	;; x86 PAGE TABLE ENTRY (4 KByte Page)
  1285                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
  1286                              <1> 	; +---------------------------------------+-----+---+-+-+---+-+-+-+
  1287                              <1>       	; |                                       |     | |P| | |P|P|U|R| |
  1288                              <1>       	; |     PAGE FRAME BASE ADDRESS 31..12    | AVL |G|A|D|A|C|W|/|/|P|
  1289                              <1>       	; |                                       |     | |T| | |D|T|S|W| |
  1290                              <1>    	; +---------------------------------------+-----+---+-+-+---+-+-+-+
  1291                              <1> 	;
  1292                              <1>         ;       P      - PRESENT
  1293                              <1>         ;       R/W    - READ/WRITE
  1294                              <1>         ;       U/S    - USER/SUPERVISOR
  1295                              <1> 	;	PWT    - WRITE THROUGH
  1296                              <1> 	;	PCD    - CACHE DISABLE	
  1297                              <1> 	;	A      - ACCESSED	
  1298                              <1>         ;       D      - DIRTY
  1299                              <1> 	;	PAT    - PAGE ATTRIBUTE TABLE INDEX (CACHE BEHAVIOR)
  1300                              <1> 	;	G      - GLOBAL	 
  1301                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
  1302                              <1> 	;
  1303                              <1> 	;
  1304                              <1> 	;; 80386 PAGE TABLE ENTRY (4 KByte Page)
  1305                              <1> 	;  31                                   12 11  9 8 7 6 5 4 3 2 1 0
  1306                              <1> 	; +---------------------------------------+-----+-+-+-+-+---+-+-+-+
  1307                              <1>       	; |                                       |     | | | | | | |U|R| |
  1308                              <1>       	; |     PAGE FRAME BASE ADDRESS 31..12    | AVL |0|0|D|A|0|0|/|/|P|
  1309                              <1>       	; |                                       |     | | | | | | |S|W| |
  1310                              <1>       	; +---------------------------------------+-----+-+-+-+-+---+-+-+-+
  1311                              <1> 	;
  1312                              <1>         ;       P      - PRESENT
  1313                              <1>         ;       R/W    - READ/WRITE
  1314                              <1>         ;       U/S    - USER/SUPERVISOR
  1315                              <1>         ;       D      - DIRTY
  1316                              <1>         ;       AVL    - AVAILABLE FOR SYSTEMS PROGRAMMER USE
  1317                              <1> 	;
  1318                              <1>         ;       NOTE: 0 INDICATES INTEL RESERVED. DO NOT DEFINE.
  1319                              <1> 	;
  1320                              <1> 	;
  1321                              <1> 	;; Invalid Page Table Entry
  1322                              <1> 	; 31                                                           1 0
  1323                              <1>       	; +-------------------------------------------------------------+-+
  1324                              <1>       	; |                                                             | |
  1325                              <1>       	; |                          AVAILABLE                          |0|
  1326                              <1>       	; |                                                             | |
  1327                              <1>       	; +-------------------------------------------------------------+-+
  1328                              <1> 	;
  1329                              <1> 
  1330 00005A87 53                  <1> 	push	ebx
  1331 00005A88 52                  <1> 	push	edx
  1332 00005A89 51                  <1> 	push	ecx
  1333                              <1> 	;
  1334                              <1> 	; 21/09/2015 (debugging)
  1335 00005A8A FF05[E4940100]      <1> 	inc	dword [u.pfcount] ; page fault count for running process
  1336 00005A90 FF05[90960100]      <1> 	inc	dword [PF_Count] ; total page fault count	
  1337                              <1> 	; 28/06/2015
  1338                              <1> 	;mov	edx, [error_code] ; Lower 5 bits are valid
  1339 00005A96 8A15[88960100]      <1> 	mov	dl, [error_code]
  1340                              <1> 	;
  1341 00005A9C F6C201              <1> 	test	dl, 1	; page fault was caused by a non-present page
  1342                              <1> 			; sign
  1343 00005A9F 7425                <1> 	jz	short pfh_alloc_np
  1344                              <1> 	; 
  1345                              <1> 	; If it is not a 'write on read only page' type page fault
  1346                              <1> 	; major page fault error with minor reason must be returned without 
  1347                              <1> 	; fixing the problem. 'sys_exit with error' will be needed
  1348                              <1> 	; after return here!
  1349                              <1> 	; Page fault will be remedied, by copying page contents
  1350                              <1> 	; to newly allocated page with write permission;
  1351                              <1> 	; sys_fork -> sys_exec -> copy on write, demand paging method is 
  1352                              <1> 	; used for working with minimum possible memory usage. 
  1353                              <1> 	; sys_fork will duplicate page directory and tables of parent  
  1354                              <1> 	; process with 'read only' flag. If the child process attempts to
  1355                              <1> 	; write on these read only pages, page fault will be directed here
  1356                              <1> 	; for allocating a new page with same data/content. 
  1357                              <1> 	;
  1358                              <1> 	; IMPORTANT : Retro UNIX 386 v1 (and SINGLIX and TR-DOS)
  1359                              <1> 	; will not force to separate CODE and DATA space 
  1360                              <1> 	; in a process/program... 
  1361                              <1> 	; CODE segment/section may contain DATA!
  1362                              <1> 	; It is flat, smoth and simplest programming method already as in 
  1363                              <1> 	; Retro UNIX 8086 v1 and MS-DOS programs.
  1364                              <1> 	;	
  1365 00005AA1 F6C202              <1> 	test	dl, 2	; page fault was caused by a page write
  1366                              <1> 			; sign
  1367 00005AA4 7418                <1>         jz      short pfh_p_err
  1368                              <1> 	; 31/08/2015
  1369 00005AA6 F6C204              <1> 	test	dl, 4	; page fault was caused while CPL = 3 (user mode)
  1370                              <1> 			; sign.  (U+W+P = 4+2+1 = 7)
  1371 00005AA9 7413                <1>         jz	short pfh_pv_err
  1372                              <1> 	;
  1373                              <1> 	; make a new page and copy the parent's page content
  1374                              <1> 	; as the child's new page content
  1375                              <1> 	;
  1376 00005AAB 0F20D3              <1> 	mov	ebx, cr2 ; CR2 contains the linear address 
  1377                              <1> 			 ; which has caused to page fault
  1378 00005AAE E87C000000          <1> 	call 	copy_page
  1379 00005AB3 7202                <1>         jc	short pfh_im_err ; insufficient memory
  1380                              <1> 	;
  1381 00005AB5 EB72                <1>         jmp     pfh_cpp_ok
  1382                              <1> 
  1383                              <1> 	; 29/11/2023
  1384                              <1> pfh_im_err:
  1385 00005AB7 B8E4000000          <1> 	mov	eax, ERR_MAJOR_PF + ERR_MINOR_IM ; Error code in AX
  1386                              <1> 			; Major (Primary) Error: Page Fault
  1387                              <1> 			; Minor (Secondary) Error: Insufficient Memory !
  1388 00005ABC EB6D                <1> 	jmp	short pfh_err_retn
  1389                              <1> 
  1390                              <1> 	; 29/11/2023
  1391                              <1> pfh_p_err: ; 09/03/2015
  1392                              <1> pfh_pv_err:
  1393                              <1> 	; Page fault was caused by a protection-violation
  1394 00005ABE B8E6000000          <1> 	mov	eax, ERR_MAJOR_PF + ERR_MINOR_PV ; Error code in AX
  1395                              <1> 			; Major (Primary) Error: Page Fault
  1396                              <1> 			; Minor (Secondary) Error: Protection violation !
  1397 00005AC3 F9                  <1> 	stc
  1398 00005AC4 EB65                <1> 	jmp	short pfh_err_retn
  1399                              <1> 
  1400                              <1> pfh_alloc_np:
  1401 00005AC6 E815FDFFFF          <1> 	call	allocate_page	; (allocate a new page)
  1402 00005ACB 72EA                <1>         jc      pfh_im_err	; 'insufficient memory' error
  1403                              <1> pfh_chk_cpl:
  1404                              <1> 	; EAX = Physical (base) address of the allocated (new) page
  1405                              <1> 		; (Lower 12 bits are ZERO, because 
  1406                              <1> 		;	the address is on a page boundary)
  1407 00005ACD 80E204              <1> 	and	dl, 4	; CPL = 3 ?
  1408 00005AD0 7505                <1> 	jnz	short pfh_um
  1409                              <1> 			; Page fault handler for kernel/system mode (CPL=0)		
  1410 00005AD2 0F20DB              <1> 	mov	ebx, cr3 ; CR3 (Control Register 3) contains physical address
  1411                              <1> 			 ; of the current/active page directory
  1412                              <1> 			 ; (Always kernel/system mode page directory, here!)
  1413                              <1> 			 ; Note: Lower 12 bits are 0. (page boundary)
  1414 00005AD5 EB06                <1> 	jmp	short pfh_get_pde
  1415                              <1> 	;
  1416                              <1> pfh_um:			; Page fault handler for user/appl. mode (CPL=3)
  1417 00005AD7 8B1D[CC940100]      <1>  	mov	ebx, [u.pgdir] ; Page directory of current/active process
  1418                              <1> 			; Physical address of the USER's page directory
  1419                              <1> 			; Note: Lower 12 bits are 0. (page boundary)
  1420                              <1> pfh_get_pde:
  1421 00005ADD 80CA03              <1> 	or	dl, 3	; USER + WRITE + PRESENT or SYSTEM + WRITE + PRESENT
  1422 00005AE0 0F20D1              <1> 	mov	ecx, cr2 ; CR2 contains the virtual address 
  1423                              <1> 			 ; which has been caused to page fault
  1424                              <1> 			 ;
  1425 00005AE3 C1E914              <1> 	shr	ecx, 20	 ; shift 20 bits right
  1426 00005AE6 80E1FC              <1> 	and	cl, 0FCh ; mask lower 2 bits to get PDE offset		
  1427                              <1> 	;
  1428 00005AE9 01CB                <1> 	add	ebx, ecx ; now, EBX points to the relevant page dir entry 
  1429 00005AEB 8B0B                <1> 	mov	ecx, [ebx] ; physical (base) address of the page table 	
  1430 00005AED F6C101              <1> 	test	cl, 1	 ; check bit 0 is set (1) or not (0).
  1431 00005AF0 740B                <1> 	jz	short pfh_set_pde ; Page directory entry is not valid,
  1432                              <1> 			  	  ; set/validate page directory entry
  1433 00005AF2 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
  1434 00005AF7 89CB                <1> 	mov	ebx, ecx ; Physical address of the page table
  1435 00005AF9 89C1                <1> 	mov	ecx, eax ; new page address (physical) 	
  1436 00005AFB EB16                <1> 	jmp	short pfh_get_pte
  1437                              <1> pfh_set_pde:
  1438                              <1> 	;; NOTE: Page directories and page tables never be swapped out!
  1439                              <1> 	;;	 (So, we know this PDE is empty or invalid)
  1440                              <1> 	;
  1441 00005AFD 08D0                <1> 	or	al, dl	 ; lower 3 bits are used as U/S, R/W, P flags
  1442 00005AFF 8903                <1> 	mov	[ebx], eax ; Let's put the new page directory entry here !
  1443 00005B01 30C0                <1> 	xor	al, al	 ; clear lower (3..8) bits
  1444 00005B03 89C3                <1> 	mov	ebx, eax
  1445 00005B05 E8D6FCFFFF          <1> 	call	allocate_page	 ; (allocate a new page)
  1446 00005B0A 72AB                <1> 	jc	short pfh_im_err   ; 'insufficient memory' error
  1447                              <1> pfh_spde_1:
  1448                              <1> 	; EAX = Physical (base) address of the allocated (new) page
  1449 00005B0C 89C1                <1> 	mov	ecx, eax
  1450 00005B0E E83EFDFFFF          <1> 	call	clear_page ; Clear page content
  1451                              <1> pfh_get_pte:
  1452 00005B13 0F20D0              <1> 	mov	eax, cr2 ; virtual address
  1453                              <1> 			 ; which has been caused to page fault
  1454 00005B16 89C7                <1> 	mov	edi, eax ; 20/07/2015
  1455 00005B18 C1E80C              <1> 	shr	eax, 12	 ; shift 12 bit right to get 
  1456                              <1> 			 ; higher 20 bits of the page fault address 
  1457 00005B1B 25FF030000          <1> 	and	eax, 3FFh ; mask PDE# bits, the result is PTE# (0 to 1023)
  1458 00005B20 C1E002              <1> 	shl	eax, 2	; shift 2 bits left to get PTE offset
  1459 00005B23 01C3                <1> 	add	ebx, eax ; now, EBX points to the relevant page table entry 
  1460                              <1> ; 17/04/2021 temporary
  1461                              <1> ;	mov	eax, [ebx] ; get previous value of pte
  1462                              <1> ;		; bit 0 of EAX is always 0 (otherwise we would not be here)
  1463                              <1> 
  1464                              <1> ; 17/04/2021
  1465                              <1> ; ('swap_in' procedure call has been disabled as temporary)
  1466                              <1> ;
  1467                              <1> ;	and	eax, eax
  1468                              <1> ;	jz	short pfh_gpte_1
  1469                              <1> ;	; 20/07/2015
  1470                              <1> ;	xchg	ebx, ecx ; new page address (physical)
  1471                              <1> ;	push	ebp ; 20/07/2015
  1472                              <1> ;	mov	ebp, cr2
  1473                              <1> ;		; ECX = physical address of the page table entry
  1474                              <1> ;		; EBX = Memory page address (physical!)
  1475                              <1> ;		; EAX = Swap disk (offset) address
  1476                              <1> ;		; EBP = virtual address (page fault address)
  1477                              <1> ;	call	swap_in
  1478                              <1> ;	pop	ebp
  1479                              <1> ;	jc      short pfh_err_retn
  1480                              <1> ;	xchg	ecx, ebx
  1481                              <1> ;		; EBX = physical address of the page table entry
  1482                              <1> ;		; ECX = new page
  1483                              <1> pfh_gpte_1:
  1484 00005B25 08D1                <1> 	or	cl, dl	; lower 3 bits are used as U/S, R/W, P flags
  1485 00005B27 890B                <1> 	mov	[ebx], ecx ; Let's put the new page table entry here !
  1486                              <1> pfh_cpp_ok:
  1487                              <1> ; 17/04/2021
  1488                              <1> ; ('add_to_swap_queue' procedure call has been disabled as temporary)
  1489                              <1> ;
  1490                              <1> ;	; 20/07/2015
  1491                              <1> ;	mov	ebx, cr2
  1492                              <1> ;	call 	add_to_swap_queue
  1493                              <1> 	;
  1494                              <1> 	; The new PTE (which contains the new page) will be added to 
  1495                              <1> 	; the swap queue, here. 
  1496                              <1> 	; (Later, if memory will become insufficient, 
  1497                              <1> 	; one page will be swapped out which is at the head of 
  1498                              <1> 	; the swap queue by using FIFO and access check methods.)
  1499                              <1> 	;
  1500 00005B29 31C0                <1> 	xor	eax, eax  ; 0
  1501                              <1> 	;
  1502                              <1> pfh_err_retn:
  1503 00005B2B 59                  <1> 	pop	ecx
  1504 00005B2C 5A                  <1> 	pop	edx
  1505 00005B2D 5B                  <1> 	pop	ebx
  1506 00005B2E C3                  <1> 	retn 
  1507                              <1> 	
  1508                              <1> copy_page:
  1509                              <1> 	; 29/08/2023 (TRDOS 386 v2.0.6)
  1510                              <1> 	; 22/09/2015
  1511                              <1> 	; 21/09/2015
  1512                              <1> 	; 19/09/2015
  1513                              <1> 	; 07/09/2015
  1514                              <1> 	; 31/08/2015
  1515                              <1> 	; 20/07/2015
  1516                              <1> 	; 05/05/2015
  1517                              <1> 	; 03/05/2015
  1518                              <1> 	; 18/04/2015
  1519                              <1> 	; 12/04/2015
  1520                              <1> 	; 30/10/2014
  1521                              <1> 	; 18/10/2014 (Retro UNIX 386 v1 - beginning)
  1522                              <1> 	;
  1523                              <1> 	; INPUT -> 
  1524                              <1> 	;	EBX = Virtual (linear) address of source page
  1525                              <1> 	;	     (Page fault address)
  1526                              <1> 	; OUTPUT ->
  1527                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF THE ALLOCATED PAGE
  1528                              <1> 	;	(corresponding PAGE TABLE ENTRY is mapped/set)
  1529                              <1> 	;	EAX = 0 (CF = 1) 
  1530                              <1> 	;		if there is not a free page to be allocated
  1531                              <1> 	;	(page content of the source page will be copied
  1532                              <1> 	;	onto the target/new page) 	
  1533                              <1> 	;
  1534                              <1> 	; Modified Registers -> ecx, ebx (except EAX)
  1535                              <1> 	;	
  1536 00005B2F 56                  <1> 	push	esi
  1537 00005B30 57                  <1> 	push	edi
  1538                              <1> 	;push	ebx
  1539                              <1> 	;push	ecx
  1540 00005B31 31F6                <1> 	xor 	esi, esi
  1541 00005B33 C1EB0C              <1> 	shr	ebx, 12 ; shift 12 bits right to get PDE & PTE numbers
  1542 00005B36 89D9                <1> 	mov	ecx, ebx ; save page fault address (as 12 bit shifted)
  1543 00005B38 C1EB08              <1> 	shr	ebx, 8	 ; shift 8 bits right and then
  1544 00005B3B 80E3FC              <1> 	and	bl, 0FCh ; mask lower 2 bits to get PDE offset	
  1545 00005B3E 89DF                <1> 	mov 	edi, ebx ; save it for the parent of current process
  1546 00005B40 031D[CC940100]      <1> 	add	ebx, [u.pgdir] ; EBX points to the relevant page dir entry 
  1547 00005B46 8B03                <1> 	mov	eax, [ebx] ; physical (base) address of the page table
  1548 00005B48 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits 	
  1549 00005B4C 89CB                <1> 	mov	ebx, ecx   ; (restore higher 20 bits of page fault address)
  1550 00005B4E 81E3FF030000        <1> 	and	ebx, 3FFh  ; mask PDE# bits, the result is PTE# (0 to 1023)
  1551                              <1> 	;shl	bx, 2	   ; shift 2 bits left to get PTE offset
  1552                              <1> 	; 29/08/2023
  1553 00005B54 C1E302              <1> 	shl	ebx, 2
  1554 00005B57 01C3                <1> 	add	ebx, eax   ; EBX points to the relevant page table entry 
  1555                              <1> 	; 07/09/2015
  1556 00005B59 66F7030002          <1>         test    word [ebx], PTE_DUPLICATED ; (Does current process share this
  1557                              <1> 				     ; read only page as a child process?)	
  1558 00005B5E 7509                <1> 	jnz	short cpp_0 ; yes
  1559 00005B60 8B0B                <1> 	mov	ecx, [ebx] ; PTE value
  1560 00005B62 6681E100F0          <1> 	and	cx, PTE_A_CLEAR ; 0F000h  ; clear page attributes
  1561 00005B67 EB31                <1> 	jmp	short cpp_1
  1562                              <1> cpp_0:
  1563 00005B69 89FE                <1> 	mov	esi, edi
  1564 00005B6B 0335[D0940100]      <1> 	add	esi, [u.ppgdir] ; the parent's page directory entry
  1565 00005B71 8B06                <1> 	mov	eax, [esi] ; physical (base) address of the page table
  1566 00005B73 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
  1567 00005B77 89CE                <1> 	mov	esi, ecx   ; (restore higher 20 bits of page fault address)	
  1568 00005B79 81E6FF030000        <1> 	and	esi, 3FFh  ; mask PDE# bits, the result is PTE# (0 to 1023)
  1569                              <1> 	;shl	si, 2	   ; shift 2 bits left to get PTE offset
  1570                              <1> 	; 29/08/2023
  1571 00005B7F C1E602              <1> 	shl	esi, 2
  1572 00005B82 01C6                <1> 	add	esi, eax   ; EDX points to the relevant page table entry  	
  1573 00005B84 8B0E                <1> 	mov	ecx, [esi] ; PTE value of the parent process
  1574                              <1> 	; 21/09/2015
  1575 00005B86 8B03                <1> 	mov	eax, [ebx] ; PTE value of the child process
  1576 00005B88 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear page attributes	
  1577                              <1> 	;
  1578 00005B8C F6C101              <1> 	test	cl, PTE_A_PRESENT ; is it a present/valid page ?
  1579 00005B8F 7424                <1> 	jz	short cpp_3 ; the parent's page is not same page  	
  1580                              <1> 	;
  1581 00005B91 6681E100F0          <1> 	and	cx, PTE_A_CLEAR ; 0F000h ; clear page attributes
  1582 00005B96 39C8                <1> 	cmp	eax, ecx   ; Same page?	
  1583 00005B98 751B                <1> 	jne	short cpp_3 ; Parent page and child page are not same 
  1584                              <1> 			    ; Convert child's page to writable page
  1585                              <1> cpp_1:
  1586 00005B9A E841FCFFFF          <1> 	call	allocate_page
  1587 00005B9F 721A                <1> 	jc	short cpp_4 ; 'insufficient memory' error
  1588 00005BA1 21F6                <1> 	and	esi, esi    ; check ESI is valid or not
  1589 00005BA3 7405                <1> 	jz	short cpp_2
  1590                              <1> 		; Convert read only page to writable page 
  1591                              <1> 		;(for the parent of the current process)
  1592                              <1> 	;and	word [esi], PTE_A_CLEAR ; 0F000h
  1593                              <1> 	; 22/09/2015
  1594 00005BA5 890E                <1> 	mov	[esi], ecx
  1595 00005BA7 800E07              <1> 	or	byte [esi], PTE_A_PRESENT + PTE_A_WRITE + PTE_A_USER
  1596                              <1> 				 ; 1+2+4 = 7
  1597                              <1> cpp_2:
  1598 00005BAA 89C7                <1> 	mov	edi, eax ; new page address of the child process
  1599                              <1> 	; 07/09/2015
  1600 00005BAC 89CE                <1> 	mov	esi, ecx ; the page address of the parent process
  1601 00005BAE B900040000          <1> 	mov	ecx, PAGE_SIZE / 4
  1602 00005BB3 F3A5                <1> 	rep	movsd ; 31/08/2015
  1603                              <1> cpp_3:		
  1604 00005BB5 0C07                <1> 	or	al, PTE_A_PRESENT + PTE_A_WRITE + PTE_A_USER ; 1+2+4 = 7
  1605 00005BB7 8903                <1> 	mov	[ebx], eax ; Update PTE
  1606 00005BB9 28C0                <1> 	sub	al, al ; clear attributes
  1607                              <1> cpp_4:
  1608                              <1> 	;pop	ecx
  1609                              <1> 	;pop	ebx
  1610 00005BBB 5F                  <1> 	pop	edi
  1611 00005BBC 5E                  <1> 	pop	esi
  1612 00005BBD C3                  <1> 	retn
  1613                              <1> 
  1614                              <1> ;; 28/04/2015
  1615                              <1> ;; 24/10/2014
  1616                              <1> ;; 21/10/2014 (Retro UNIX 386 v1 - beginning)
  1617                              <1> ;; SWAP_PAGE_QUEUE (4096 bytes)
  1618                              <1> ;;
  1619                              <1> ;;   0000   0001   0002   0003   ....   1020   1021   1022   1023	
  1620                              <1> ;; +------+------+------+------+-    -+------+------+------+------+
  1621                              <1> ;; |  pg1 |  pg2 |  pg3 |  pg4 | .... |pg1021|pg1022|pg1023|pg1024|
  1622                              <1> ;; +------+------+------+------+-    -+------+------+------+------+    
  1623                              <1> ;;
  1624                              <1> ;; [swpq_last] = 0 to 4096 (step 4) -> the last position on the queue
  1625                              <1> ;;
  1626                              <1> ;; Method:
  1627                              <1> ;;	Swap page queue is a list of allocated pages with physical
  1628                              <1> ;;	addresses (system mode virtual adresses = physical addresses).
  1629                              <1> ;;	It is used for 'swap_in' and 'swap_out' procedures.
  1630                              <1> ;;	When a new page is being allocated, swap queue is updated
  1631                              <1> ;;	by 'swap_queue_shift' procedure, header of the queue (offset 0)
  1632                              <1> ;;	is checked for 'accessed' flag. If the 1st page on the queue
  1633                              <1> ;;	is 'accessed' or 'read only', it is dropped from the list;
  1634                              <1> ;;	other pages from the 2nd to the last (in [swpq_last]) shifted
  1635                              <1> ;; 	to head then the 2nd page becomes the 1st and '[swpq_last]' 
  1636                              <1> ;;	offset value becomes it's previous offset value - 4.
  1637                              <1> ;;	If the 1st page of the swap page queue is not 'accessed'	
  1638                              <1> ;;	the queue/list is not shifted.
  1639                              <1> ;;	After the queue/list shift, newly allocated page is added
  1640                              <1> ;;	to the tail of the queue at the [swpq_count*4] position.
  1641                              <1> ;;	But, if [swpq_count] > 1023, the newly allocated page
  1642                              <1> ;;	will not be added to the tail of swap page queue.  		 
  1643                              <1> ;;	
  1644                              <1> ;;	During 'swap_out' procedure, swap page queue is checked for
  1645                              <1> ;;	the first non-accessed, writable page in the list, 
  1646                              <1> ;;	from the head to the tail. The list is shifted to left 
  1647                              <1> ;;	(to the head) till a non-accessed page will be found in the list.
  1648                              <1> ;;	Then, this page	is swapped out (to disk) and then it is dropped
  1649                              <1> ;;	from the list by a final swap queue shift. [swpq_count] value
  1650                              <1> ;;	is changed. If all pages on the queue' are 'accessed', 
  1651                              <1> ;;	'insufficient memory' error will be returned ('swap_out' 
  1652                              <1> ;;	procedure will be failed)...
  1653                              <1> ;;
  1654                              <1> ;;	Note: If the 1st page of the queue is an 'accessed' page,
  1655                              <1> ;;	'accessed' flag of the page will be reset (0) and that page
  1656                              <1> ;;	(PTE) will be added to the tail of the queue after
  1657                              <1> ;;	the check, if [swpq_count] < 1023. If [swpq_count] = 1024
  1658                              <1> ;;	the queue will be rotated and the PTE in the head will be
  1659                              <1> ;;	added to the tail after resetting 'accessed' bit. 
  1660                              <1> ;;
  1661                              <1> ;;
  1662                              <1> ;;	
  1663                              <1> ;; SWAP DISK/FILE (with 4096 bytes swapped page blocks)
  1664                              <1> ;;
  1665                              <1> ;;  00000000  00000004  00000008  0000000C   ...   size-8    size-4
  1666                              <1> ;; +---------+---------+---------+---------+-- --+---------+---------+
  1667                              <1> ;; |descriptr| page(1) | page(2) | page(3) | ... |page(n-1)| page(n) |
  1668                              <1> ;; +---------+---------+---------+---------+-- --+---------+---------+    
  1669                              <1> ;;
  1670                              <1> ;; [swpd_next] = the first free block address in swapped page records
  1671                              <1> ;;    		 for next free block search by 'swap_out' procedure.
  1672                              <1> ;; [swpd_size] = swap disk/file size in sectors (512 bytes)
  1673                              <1> ;;		 NOTE: max. possible swap disk size is 1024 GB
  1674                              <1> ;; 		 (entire swap space must be accessed by using
  1675                              <1> ;;		 31 bit offset address) 
  1676                              <1> ;; [swpd_free] = free block (4096 bytes) count in swap disk/file space
  1677                              <1> ;; [swpd_start] = absolute/start address of the swap disk/file
  1678                              <1> ;;		  0 for file, or beginning sector of the swap partition
  1679                              <1> ;; [swp_drv] = logical drive description table addr. of swap disk/file
  1680                              <1> ;;
  1681                              <1> ;; 					
  1682                              <1> ;; Method:
  1683                              <1> ;;	When the memory (ram) becomes insufficient, page allocation
  1684                              <1> ;;	procedure swaps out a page from memory to the swap disk 
  1685                              <1> ;;	(partition) or swap file to get a new free page at the memory.
  1686                              <1> ;;	Swapping out is performed by using swap page queue.
  1687                              <1> ;;
  1688                              <1> ;; 	Allocation block size of swap disk/file is equal to page size
  1689                              <1> ;;	(4096 bytes). Swapping address (in sectors) is recorded
  1690                              <1> ;;	into relevant page file entry as 31 bit physical (logical)
  1691                              <1> ;;	offset address as 1 bit shifted to left for present flag (0).
  1692                              <1> ;;	Swapped page address is between 1 and swap disk/file size - 4.	  
  1693                              <1> ;;	Absolute physical (logical) address of the swapped page is 
  1694                              <1> ;;	calculated by adding offset value to the swap partition's 
  1695                              <1> ;;	start address. If the swap device (disk) is a virtual disk 
  1696                              <1> ;;	or it is a file, start address of the swap disk/volume is 0, 
  1697                              <1> ;;	and offset value is equal to absolute (physical or logical)
  1698                              <1> ;;	address/position. (It has not to be ZERO if the swap partition 
  1699                              <1> ;;	is in a partitioned virtual hard disk.) 
  1700                              <1> ;;
  1701                              <1> ;;	Note: Swap addresses are always specified/declared in sectors, 
  1702                              <1> ;;	not in bytes or	in blocks/zones/clusters (4096 bytes) as unit.
  1703                              <1> ;;
  1704                              <1> ;;	Swap disk/file allocation is mapped via 'Swap Allocation Table'
  1705                              <1> ;;	at memory as similar to 'Memory Allocation Table'.
  1706                              <1> ;;
  1707                              <1> ;;	Every bit of Swap Allocation Table repsesents one swap block
  1708                              <1> ;;	(equal to page size) respectively. Bit 0 of the S.A.T. byte 0
  1709                              <1> ;;	is reserved for swap disk/file block 0 as descriptor block
  1710                              <1> ;;	(also for compatibility with PTE). If bit value is ZERO,
  1711                              <1> ;;	it means relevant (respective) block is in use, and, 
  1712                              <1> ;;	of course, if bit value is 1, it means relevant (respective)
  1713                              <1> ;;      swap disk/file block is free.
  1714                              <1> ;;	For example: bit 1 of the byte 128 repsesents block 1025 
  1715                              <1> ;;	(128*8+1) or sector (offset) 8200 on the swap disk or
  1716                              <1> ;;	byte (offset/position) 4198400 in the swap file. 
  1717                              <1> ;;	4GB swap space is represented via 128KB Swap Allocation Table.
  1718                              <1> ;;	Initial layout of Swap Allocation Table is as follows:
  1719                              <1> ;;	------------------------------------------------------------
  1720                              <1> ;;	0111111111111111111111111 .... 11111111111111111111111111111
  1721                              <1> ;;	------------------------------------------------------------
  1722                              <1> ;;	(0 is reserved block, 1s represent free blocks respectively.)
  1723                              <1> ;;	(Note: Allocation cell/unit of the table is bit, not byte)
  1724                              <1> ;;
  1725                              <1> ;;	..............................................................
  1726                              <1> ;;
  1727                              <1> ;;	'swap_out' procedure checks 'free_swap_blocks' count at first,
  1728                              <1> ;;	then it searches Swap Allocation Table if free count is not
  1729                              <1> ;;	zero. From begining the [swpd_next] dword value, the first bit 
  1730                              <1> ;;	position with value of 1 on the table is converted to swap
  1731                              <1> ;;	disk/file offset address, in sectors (not 4096 bytes block).
  1732                              <1> ;;	'ldrv_write' procedure is called with ldrv (logical drive
  1733                              <1> ;;	number of physical swap disk or virtual swap disk)
  1734                              <1> ;;	number, sector offset (not absolute sector -LBA- number),
  1735                              <1> ;;	and sector count (8, 512*8 = 4096) and buffer adress
  1736                              <1> ;;	(memory page). That will be a direct disk write procedure.
  1737                              <1> ;;	(for preventing late memory allocation, significant waiting). 
  1738                              <1> ;;	If disk write procedure returns with error or free count of 
  1739                              <1> ;;	swap blocks is ZERO, 'swap_out' procedure will return with
  1740                              <1> ;;	'insufficient memory error' (cf=1). 
  1741                              <1> ;;
  1742                              <1> ;;	(Note: Even if free swap disk/file blocks was not zero,
  1743                              <1> ;;	any disk write error will not be fixed by 'swap_out' procedure,
  1744                              <1> ;;	in other words, 'swap_out' will not check the table for other
  1745                              <1> ;;	free blocks after a disk write error. It will return to 
  1746                              <1> ;;	the caller with error (CF=1) which means swapping is failed. 
  1747                              <1> ;;
  1748                              <1> ;;	After writing the page on to swap disk/file address/sector,
  1749                              <1> ;;	'swap_out' procesure returns with that swap (offset) sector
  1750                              <1> ;;	address (cf=0). 
  1751                              <1> ;;
  1752                              <1> ;;	..............................................................
  1753                              <1> ;;
  1754                              <1> ;;	'swap_in' procedure loads addressed (relevant) swap disk or
  1755                              <1> ;;	file sectors at specified memory page. Then page allocation
  1756                              <1> ;;	procedure updates relevant page table entry with 'present' 
  1757                              <1> ;;	attribute. If swap disk or file reading fails there is nothing
  1758                              <1> ;;	to do, except to terminate the process which is the owner of
  1759                              <1> ;;	the swapped page.
  1760                              <1> ;;
  1761                              <1> ;;	'swap_in' procedure sets the relevant/respective bit value
  1762                              <1> ;;	in the Swap Allocation Table (as free block). 'swap_in' also
  1763                              <1> ;;	updates [swpd_first] pointer if it is required.
  1764                              <1> ;;
  1765                              <1> ;;	..............................................................	 
  1766                              <1> ;;
  1767                              <1> ;;	Note: If [swap_enabled] value is ZERO, that means there is not
  1768                              <1> ;;	a swap disk or swap file in use... 'swap_in' and 'swap_out'
  1769                              <1> ;;	procedures ans 'swap page que' procedures will not be active...
  1770                              <1> ;;	'Insufficient memory' error will be returned by 'swap_out'
  1771                              <1> ;;	and 'general protection fault' will be returned by 'swap_in'
  1772                              <1> ;;	procedure, if it is called mistakenly (a wrong value in a PTE).		
  1773                              <1> ;;
  1774                              <1> 
  1775                              <1> ; 17/04/2021
  1776                              <1> ; ('swap_in' procedure call is disabled as temporary)
  1777                              <1> 
  1778                              <1> swap_in:
  1779                              <1> 	; 31/08/2015
  1780                              <1> 	; 20/07/2015
  1781                              <1> 	; 28/04/2015
  1782                              <1> 	; 18/04/2015
  1783                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
  1784                              <1> 	;
  1785                              <1> 	; INPUT -> 
  1786                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS OF THE MEMORY PAGE
  1787                              <1> 	;	EBP = VIRTUAL (LINEAR) ADDRESS (page fault address)
  1788                              <1> 	;	EAX = Offset Address for the swapped page on the
  1789                              <1> 	;	      swap disk or in the swap file.
  1790                              <1> 	;
  1791                              <1> 	; OUTPUT ->
  1792                              <1> 	;	EAX = 0 if loading at memory has been successful
  1793                              <1> 	;
  1794                              <1> 	;	CF = 1 -> swap disk reading error (disk/file not present
  1795                              <1> 	;		  or sector not present or drive not ready
  1796                              <1> 	;	     EAX = Error code
  1797                              <1> 	;	     [u.error] = EAX 
  1798                              <1> 	;		       = The last error code for the process
  1799                              <1> 	;		         (will be reset after returning to user)	  
  1800                              <1> 	;
  1801                              <1> 	; Modified Registers -> EAX
  1802                              <1> 	;
  1803                              <1> 
  1804                              <1> ;       cmp     dword [swp_drv], 0
  1805                              <1> ;	jna	short swpin_dnp_err
  1806                              <1> ;
  1807                              <1> ;	cmp	eax, [swpd_size]
  1808                              <1> ;	jnb	short swpin_snp_err
  1809                              <1> ;
  1810                              <1> ;	push	esi
  1811                              <1> ;	push	ebx
  1812                              <1> ;	push	ecx
  1813                              <1> ;	mov	esi, [swp_drv]	
  1814                              <1> ;	mov	ecx, PAGE_SIZE / LOGIC_SECT_SIZE  ; 8 !
  1815                              <1> ;		; Note: Even if corresponding physical disk's sector 
  1816                              <1> ;		; size different than 512 bytes, logical disk sector
  1817                              <1> ;		; size is 512 bytes and disk reading procedure
  1818                              <1> ;		; will be performed for reading 4096 bytes
  1819                              <1> ;		; (2*2048, 8*512). 
  1820                              <1> ;	; ESI = Logical disk description table address
  1821                              <1> ;	; EBX = Memory page (buffer) address (physical!)
  1822                              <1> ;	; EAX = Sector adress (offset address, logical sector number)
  1823                              <1> ;	; ECX = Sector count ; 8 sectors
  1824                              <1> ;	push	eax
  1825                              <1> ;	call	logical_disk_read
  1826                              <1> ;	pop	eax
  1827                              <1> ;	jnc	short swpin_read_ok
  1828                              <1> ;	;
  1829                              <1> ;	mov	eax, SWP_DISK_READ_ERR ; drive not ready or read error
  1830                              <1> ;	mov	[u.error], eax
  1831                              <1> ;	jmp	short swpin_retn
  1832                              <1> ;	;
  1833                              <1> ;swpin_read_ok:
  1834                              <1> ;	; EAX = Offset address (logical sector number)
  1835                              <1> ;	call	unlink_swap_block  ; Deallocate swap block	
  1836                              <1> ;	;
  1837                              <1> ;	; EBX = Memory page (buffer) address (physical!)
  1838                              <1> ;	; 20/07/2015
  1839                              <1> ;	mov	ebx, ebp ; virtual address (page fault address)
  1840                              <1> ;       and     bx, ~PAGE_OFF ; ~0FFFh ; reset bits, 0 to 11
  1841                              <1> ;	mov	bl, [u.uno] ; current process number
  1842                              <1> ;	; EBX = Virtual (Linear) address & process number combination
  1843                              <1> ;	call	swap_queue_shift
  1844                              <1> ;	; eax = 0 ; 10/06/2016 (if ebx input > 0, eax output = 0)
  1845                              <1> ;	;sub	eax, eax  ; 0 ; Error Code = 0  (no error)
  1846                              <1> ;	; zf = 1
  1847                              <1> ;swpin_retn:
  1848                              <1> ;	pop	ecx
  1849                              <1> ;	pop	ebx
  1850                              <1> ;	pop	esi
  1851                              <1> ;	retn
  1852                              <1> ;
  1853                              <1> ;swpin_dnp_err:
  1854                              <1> ;	mov	eax, SWP_DISK_NOT_PRESENT_ERR
  1855                              <1> ;swpin_err_retn:
  1856                              <1> ;	mov	[u.error], eax
  1857                              <1> ;	stc
  1858                              <1> ;	retn
  1859                              <1> ;
  1860                              <1> ;swpin_snp_err:
  1861                              <1> ;	mov	eax, SWP_SECTOR_NOT_PRESENT_ERR
  1862                              <1> ;	jmp	short swpin_err_retn
  1863                              <1> 
  1864                              <1> ; 17/04/2021
  1865                              <1> ; ('swap_out' procedure call is disabled as temporary)
  1866                              <1> 
  1867                              <1> swap_out:
  1868                              <1> 	; 10/06/2016
  1869                              <1> 	; 07/06/2016
  1870                              <1>         ; 23/05/2016
  1871                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
  1872                              <1> 	; 24/10/2014 - 31/08/2015 (Retro UNIX 386 v1)
  1873                              <1> 	;
  1874                              <1> 	; INPUT -> 
  1875                              <1> 	;	none
  1876                              <1> 	;
  1877                              <1> 	; OUTPUT ->
  1878                              <1> 	;	EAX = Physical page address (which is swapped out
  1879                              <1> 	;	      for allocating a new page)
  1880                              <1> 	;	CF = 1 -> swap disk writing error (disk/file not present
  1881                              <1> 	;		  or sector not present or drive not ready
  1882                              <1> 	;	     EAX = Error code
  1883                              <1> 	;	     [u.error] = EAX 
  1884                              <1> 	;		       = The last error code for the process
  1885                              <1> 	;		         (will be reset after returning to user)	  
  1886                              <1> 	;
  1887                              <1> 	; Modified Registers -> none (except EAX)
  1888                              <1> 	;
  1889                              <1> 
  1890                              <1> ;	cmp 	word [swpq_count], 1
  1891                              <1> ;       jc      swpout_im_err ; 'insufficient memory'
  1892                              <1> ;
  1893                              <1> ;       ;cmp    dword [swp_drv], 1
  1894                              <1> ;	;jc	short swpout_dnp_err ; 'swap disk/file not present'
  1895                              <1> ;
  1896                              <1> ;       cmp     dword [swpd_free], 1
  1897                              <1> ;       jc      swpout_nfspc_err ; 'no free space on swap disk'
  1898                              <1> ;
  1899                              <1> ;	push	ebx ; *
  1900                              <1> ;swpout_1:
  1901                              <1> ;	; 10/06/2016
  1902                              <1> ;	xor	ebx, ebx ; shift the queue and return a PTE value
  1903                              <1> ;	call	swap_queue_shift
  1904                              <1> ;	and	eax, eax	; 0 = empty queue (improper entries)
  1905                              <1> ;       jz      swpout_npts_err        ; There is not any proper PTE
  1906                              <1> ;				       ; pointer in the swap queue
  1907                              <1> ;	; EAX = PTE value of the page
  1908                              <1> ;	; EBX = PTE address of the page
  1909                              <1> ;	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
  1910                              <1> ;	;
  1911                              <1> ;	; 07/06/2016
  1912                              <1> ;	; 19/05/2016
  1913                              <1> ;	; check this page is in timer events or not
  1914                              <1> ;	
  1915                              <1> ;swpout_timer_page_0:
  1916                              <1> ;	push	edx ; **
  1917                              <1> ;
  1918                              <1> ;	; 07/06/2016
  1919                              <1> ;	cmp	byte [timer_events], 0 
  1920                              <1> ;	jna	short swpout_2
  1921                              <1> ;	;
  1922                              <1> ;	mov	dl, [timer_events]
  1923                              <1> ;
  1924                              <1> ;	push	ecx ; ***
  1925                              <1> ;	push	ebx ; ****
  1926                              <1> ;	mov	ebx, timer_set ; beginning address of timer event
  1927                              <1> ;			       ; structures 
  1928                              <1> ;swpout_timer_page_1:
  1929                              <1> ;	mov	cl, [ebx]
  1930                              <1> ;	or	cl, cl ; 0 = free, >0 = process number
  1931                              <1> ;	jz	short swpout_timer_page_3
  1932                              <1> ;	mov	ecx, [ebx+12] ; response (signal return) address
  1933                              <1> ;	and	cx, PTE_A_CLEAR ; clear offset part (right 12 bits)
  1934                              <1> ;				; of the response byte address, to
  1935                              <1> ;				; get beginning of the page address)
  1936                              <1> ;	cmp	eax, ecx
  1937                              <1> ;	jne	short swpout_timer_page_2 ; not same page
  1938                              <1> ;	
  1939                              <1> ;	; !same page!
  1940                              <1> ;	;
  1941                              <1> ;	; NOTE: // 19/05/2016 // - TRDOS 386 feature only ! -
  1942                              <1> ;	; This page will be used by the kernel to put timer event
  1943                              <1> ;	; response (signal return) byte at the requested address;
  1944                              <1> ;	; in order to prevent a possible wrong write (while
  1945                              <1> ;	; this page is swapped out) on physical memory,
  1946                              <1> ;	; we must protect this page against to be swapped out!
  1947                              <1> ;	;
  1948                              <1> ;	pop	ebx ; ****
  1949                              <1> ;	pop	ecx ; ***
  1950                              <1> ;	pop	edx ; **
  1951                              <1> ;	jmp	short swpout_1	; do not swap out this page !
  1952                              <1> ; 
  1953                              <1> ;swpout_timer_page_2:
  1954                              <1> ;	; 07/06/2016
  1955                              <1> ;	dec	dl
  1956                              <1> ;	jz	short swpout_timer_page_4
  1957                              <1> ;swpout_timer_page_3:
  1958                              <1> ;	;cmp	ebx, timer_set + 240 ; last timer event (15*16) 
  1959                              <1> ;	;jnb	short swpout_timer_page_4
  1960                              <1> ;	add	ebx, 16
  1961                              <1> ;	jmp	short swpout_timer_page_1	
  1962                              <1> ;
  1963                              <1> ;swpout_timer_page_4:
  1964                              <1> ;	pop	ebx ; ****
  1965                              <1> ;	pop	ecx ; ***
  1966                              <1> ;swpout_2:
  1967                              <1> ;	mov	edx, ebx	       ; Page table entry address	
  1968                              <1> ;	mov	ebx, eax	       ; Buffer (Page) Address				
  1969                              <1> ;	;
  1970                              <1> ;	call	link_swap_block
  1971                              <1> ;	jnc	short swpout_3	       ; It may not be needed here	
  1972                              <1> ;				       ; because [swpd_free] value
  1973                              <1> ;				       ; was checked at the beginging. 	
  1974                              <1> ;	pop	edx ; **
  1975                              <1> ;	pop	ebx ; *
  1976                              <1> ;	jmp	short swpout_nfspc_err 
  1977                              <1> ;swpout_3:
  1978                              <1> ;	test	eax, 80000000h ; test bit 31 (this may not be needed!)
  1979                              <1> ;	jnz	short swpout_nfspc_err  ; 10/06/2016 (bit 31 = 1 !)
  1980                              <1> ;	;	
  1981                              <1> ;	push	esi ; **
  1982                              <1> ;	push	ecx ; ***
  1983                              <1> ;	push	eax ; sector address ; (31 bit !, bit 31 = 0)
  1984                              <1> ;	mov	esi, [swp_drv]	
  1985                              <1> ;	mov	ecx, PAGE_SIZE / LOGIC_SECT_SIZE  ; 8 !
  1986                              <1> ;		; Note: Even if corresponding physical disk's sector 
  1987                              <1> ;		; size different than 512 bytes, logical disk sector
  1988                              <1> ;		; size is 512 bytes and disk writing procedure
  1989                              <1> ;		; will be performed for writing 4096 bytes
  1990                              <1> ;		; (2*2048, 8*512). 
  1991                              <1> ;	; ESI = Logical disk description table address
  1992                              <1> ;	; EBX = Buffer (Page) address
  1993                              <1> ;	; EAX = Sector adress (offset address, logical sector number)
  1994                              <1> ;	; ECX = Sector count ; 8 sectors
  1995                              <1> ;	; edx = PTE address
  1996                              <1> ;	call	logical_disk_write
  1997                              <1> ;	; edx = PTE address
  1998                              <1> ;	pop	ecx ; sector address	
  1999                              <1> ;	jnc	short swpout_write_ok
  2000                              <1> ;	;
  2001                              <1> ;	;; call	unlink_swap_block ; this block must be left as 'in use'
  2002                              <1> ;swpout_dw_err:
  2003                              <1> ;	mov	eax, SWP_DISK_WRITE_ERR ; drive not ready or write error
  2004                              <1> ;	mov	[u.error], eax
  2005                              <1> ;	jmp	short swpout_retn
  2006                              <1> ;	;
  2007                              <1> ;swpout_write_ok:
  2008                              <1> ;	; EBX = Buffer (page) address
  2009                              <1> ;	; EDX = Page Table Entry address
  2010                              <1> ;	; ECX = Swap disk sector (file block) address (31 bit)
  2011                              <1> ;	shl 	ecx, 1  ; 31 bit sector address from bit 1 to bit 31 
  2012                              <1> ;	mov 	[edx], ecx 
  2013                              <1> ;		; bit 0 = 0 (swapped page)
  2014                              <1> ;	mov	eax, ebx
  2015                              <1> ;swpout_retn:
  2016                              <1> ;	pop	ecx ; ***
  2017                              <1> ;	pop	esi ; **
  2018                              <1> ;	pop	ebx ; *
  2019                              <1> ;	retn
  2020                              <1> ;
  2021                              <1> ;;swpout_dnp_err:
  2022                              <1> ;;	mov	eax, SWP_DISK_NOT_PRESENT_ERR ; disk not present
  2023                              <1> ;;	jmp	short swpout_err_retn
  2024                              <1> ;swpout_nfspc_err:
  2025                              <1> ;	mov	eax, SWP_NO_FREE_SPACE_ERR ; no free space
  2026                              <1> ;swpout_err_retn:
  2027                              <1> ;	mov	[u.error], eax
  2028                              <1> ;	;stc
  2029                              <1> ;	retn
  2030                              <1> ;swpout_npts_err:
  2031                              <1> ;	mov	eax, SWP_NO_PAGE_TO_SWAP_ERR
  2032                              <1> ;	pop	ebx
  2033                              <1> ;	jmp	short swpout_err_retn
  2034                              <1> ;swpout_im_err:
  2035                              <1> ;	mov	eax, ERR_MINOR_IM ; insufficient (out of) memory
  2036                              <1> ;	jmp	short swpout_err_retn
  2037                              <1> 
  2038                              <1> ; 17/04/2021
  2039                              <1> ; ('swap_queue_shift' procedure call is disabled as temporary)
  2040                              <1> 
  2041                              <1> swap_queue_shift:
  2042                              <1> 	; 26/03/2017
  2043                              <1> 	; 10/06/2016
  2044                              <1> 	; 09/06/2016 - TRDOS 386 (TRDOS v2.0)
  2045                              <1> 	; 23/10/2014 - 20/07/2015 (Retro UNIX 386 v1)
  2046                              <1> 	;
  2047                              <1> 	; INPUT ->
  2048                              <1> 	;	EBX = Virtual (linear) address (bit 12 to 31) 
  2049                              <1> 	;	      and process number combination (bit 0 to 11)
  2050                              <1> 	;	EBX = 0 -> shift/drop from the head (offset 0)
  2051                              <1> 	;	
  2052                              <1> 	; OUTPUT ->
  2053                              <1> 	;	If EBX input > 0 
  2054                              <1> 	;	   the queue will be shifted 4 bytes (dword),
  2055                              <1> 	; 	   from the tail to the head, up to entry offset
  2056                              <1> 	; 	   which points to EBX input value or nothing
  2057                              <1> 	;	   to do if EBX value is not found on the queue.
  2058                              <1> 	;	   (The entry -with EBX value- will be removed
  2059                              <1> 	;	   from the queue if it is found.)
  2060                              <1> 	;
  2061                              <1> 	;	   EAX = 0		
  2062                              <1> 	;
  2063                              <1> 	;	If EBX input = 0
  2064                              <1> 	;	   the queue will be shifted 4 bytes (dword),
  2065                              <1> 	; 	   from the tail to the head, if the PTE address
  2066                              <1> 	;	   which is pointed in head of the queue is marked
  2067                              <1> 	;	   as "accessed" or it is marked as "non present".
  2068                              <1> 	;	   (If "accessed" flag of the PTE -which is pointed
  2069                              <1> 	;	   in the head- is set -to 1-, it will be reset
  2070                              <1> 	;	   -to 0- and then, the queue will be rotated 
  2071                              <1> 	;	   -without dropping pointer of the PTE from 
  2072                              <1> 	;	   the queue- for 4 bytes on head to tail direction.
  2073                              <1> 	;	   Pointer in the head will be moved into the tail,
  2074                              <1> 	;	   other PTEs will be shifted on head direction.)
  2075                              <1> 	;
  2076                              <1> 	;	   Swap queue will be shifted up to the first
  2077                              <1> 	;	   'present' or 'non accessed' page will be found
  2078                              <1> 	;	   (as pointed) on the queue head (then it will be
  2079                              <1>         ;          removed/dropped from the queue).
  2080                              <1> 	;
  2081                              <1> 	;	   EAX (> 0) = PTE value of the page which is
  2082                              <1> 	;		 (it's pointer -virtual address-) dropped
  2083                              <1> 	;		 (removed) from swap queue.
  2084                              <1> 	;	   EBX = PTE address of the page (if EAX > 0)
  2085                              <1> 	;	         which is (it's pointer -virtual address-)
  2086                              <1> 	;		 dropped (removed) from swap queue.
  2087                              <1> 	;
  2088                              <1> 	;	   EAX = 0 -> empty swap queue ! 
  2089                              <1> 	;
  2090                              <1> 	; Modified Registers -> EAX, EBX
  2091                              <1> 	;
  2092                              <1> ;	movzx   eax, word [swpq_count]  ; Max. 1024
  2093                              <1> ;	and	ax, ax
  2094                              <1> ;	jz	short swpqs_retn
  2095                              <1> ;	push	edi
  2096                              <1> ;	push	esi
  2097                              <1> ;	push	ecx
  2098                              <1> ;	mov	esi, swap_queue
  2099                              <1> ;	mov	ecx, eax
  2100                              <1> ;	or	ebx, ebx
  2101                              <1> ;	jz	short swpqs_7
  2102                              <1> ;swpqs_1:
  2103                              <1> ;	lodsd
  2104                              <1> ;	cmp	eax, ebx
  2105                              <1> ;	je	short swpqs_2
  2106                              <1> ;	loop	swpqs_1
  2107                              <1> ;	; 10/06/2016
  2108                              <1> ;	sub	eax, eax 
  2109                              <1> ;	jmp	short swpqs_6
  2110                              <1> ;swpqs_2:
  2111                              <1> ;	mov	edi, esi
  2112                              <1> ;	sub 	edi, 4
  2113                              <1> ;swpqs_3:
  2114                              <1> ;	dec	word [swpq_count]
  2115                              <1> ;	jz	short swpqs_5
  2116                              <1> ;swpqs_4:
  2117                              <1> ;	dec 	ecx
  2118                              <1> ;	rep	movsd	; shift up (to the head)
  2119                              <1> ;swpqs_5:
  2120                              <1> ;	xor	eax, eax
  2121                              <1> ;	mov	[edi], eax
  2122                              <1> ;swpqs_6:
  2123                              <1> ;	pop	ecx
  2124                              <1> ;	pop	esi
  2125                              <1> ;	pop	edi
  2126                              <1> ;swpqs_retn:
  2127                              <1> ;	retn		
  2128                              <1> ;swpqs_7:
  2129                              <1> ;	mov	edi, esi ; head
  2130                              <1> ;	lodsd
  2131                              <1> ;	; 20/07/2015
  2132                              <1> ;	mov	ebx, eax
  2133                              <1> ;	and	ebx, ~PAGE_OFF ; ~0FFFh 
  2134                              <1> ;		      ; ebx = virtual address (at page boundary)	
  2135                              <1> ;	and	eax, PAGE_OFF ; 0FFFh
  2136                              <1> ;		      ; ax = process number (1 to 4095)
  2137                              <1> ;	cmp	al, [u.uno]
  2138                              <1> ;		; Max. 16 (nproc) processes for Retro UNIX 386 v1
  2139                              <1> ;	jne	short swpqs_8
  2140                              <1> ;	mov	eax, [u.pgdir]
  2141                              <1> ;	jmp	short swpqs_9
  2142                              <1> ;swpqs_8:
  2143                              <1> ;	; 09/06/2016
  2144                              <1> ;	cmp	byte [eax+p.stat-1], 0
  2145                              <1> ;	jna	short swpqs_3     ; free (or terminated) process
  2146                              <1> ;	cmp	byte [eax+p.stat-1], 2 ; waiting
  2147                              <1> ;	ja	short swpqs_3 	  ; zombie (3) or undefined ?	
  2148                              <1> ;
  2149                              <1> ;	;shl	ax, 2
  2150                              <1> ;	shl	al, 2
  2151                              <1> ;	mov 	eax, [eax+p.upage-4]
  2152                              <1> ;	or	eax, eax
  2153                              <1> ;	jz	short swpqs_3 ; invalid upage
  2154                              <1> ;	add	eax, u.pgdir - user
  2155                              <1> ;			 ; u.pgdir value for the process
  2156                              <1> ;			 ; is in [eax]
  2157                              <1> ;	mov	eax, [eax]
  2158                              <1> ;	and	eax, eax
  2159                              <1> ;	jz	short swpqs_3 ; invalid page directory
  2160                              <1> ;swpqs_9:
  2161                              <1> ;	push	edx
  2162                              <1> ;	; eax = page directory
  2163                              <1> ;	; ebx = virtual address
  2164                              <1> ;	call	get_pte
  2165                              <1> ;	mov	ebx, edx	; PTE address
  2166                              <1> ;	pop	edx
  2167                              <1> ;	; 10/06/2016
  2168                              <1> ;	jc	short swpqs_13 ; empty PDE
  2169                              <1> ;	; EAX = PTE value
  2170                              <1> ;	test	al, PTE_A_PRESENT ; bit 0 = 1
  2171                              <1> ;	jz	short swpqs_13  ; Drop non-present page
  2172                              <1> ;			        ; from the queue (head)
  2173                              <1> ;	test	al, PTE_A_WRITE	; bit 1 = 0 (read only)
  2174                              <1> ;	jz	short swpqs_13  ; Drop read only page
  2175                              <1> ;			        ; from the queue (head) 	
  2176                              <1> ;	;test	al, PTE_A_ACCESS ; bit 5 = 1 (Accessed)
  2177                              <1> ;	;jnz	short swpqs_11  ; present
  2178                              <1> ;			        ; accessed page
  2179                              <1> ;       btr     eax, PTE_A_ACCESS_BIT ; reset 'accessed' bit
  2180                              <1> ;	jc	short swpqs_11  ; accessed page
  2181                              <1> ;
  2182                              <1> ;	dec	ecx
  2183                              <1> ;	mov	[swpq_count], cx
  2184                              <1> ;       jz      short swpqs_10
  2185                              <1> ;		; esi = head + 4
  2186                              <1> ;		; edi = head
  2187                              <1> ;	rep	movsd	 ; n = 1 to k-1, [n - 1] = [n]
  2188                              <1> ;swpqs_10:
  2189                              <1> ;	mov	[edi], ecx ; 0
  2190                              <1> ;	jmp	short swpqs_6 ; 26/03/2017
  2191                              <1> ;
  2192                              <1> ;swpqs_11:
  2193                              <1> ;	mov	[ebx], eax     ; save changed attribute
  2194                              <1> ;	; Rotation (head -> tail)
  2195                              <1> ;	dec	ecx     ; entry count -> last entry number		
  2196                              <1> ;	jz	short swpqs_10
  2197                              <1> ;		; esi = head + 4
  2198                              <1> ;		; edi = head
  2199                              <1> ;	mov	eax, [edi] ; 20/07/2015
  2200                              <1> ;	rep	movsd	 ; n = 1 to k-1, [n - 1] = [n]
  2201                              <1> ;	mov	[edi], eax ; head -> tail ; [k] = [1]
  2202                              <1> ;
  2203                              <1> ;	mov	cx, [swpq_count]
  2204                              <1> ;
  2205                              <1> ;swpqs_12:
  2206                              <1> ;	mov	esi, swap_queue ; head
  2207                              <1> ;       jmp     swpqs_7
  2208                              <1> ;
  2209                              <1> ;swpqs_13:
  2210                              <1> ;	dec	ecx
  2211                              <1> ;	mov	[swpq_count], cx
  2212                              <1> ;       jz      swpqs_5
  2213                              <1> ;	jmp	short swpqs_12
  2214                              <1> 
  2215                              <1> ; 17/04/2021
  2216                              <1> ; ('add_to_swp_queue' procedure call is disabled as temporary)
  2217                              <1> 
  2218                              <1> add_to_swap_queue:
  2219                              <1> 	; 20/02/2017
  2220                              <1> 	; 20/07/2015
  2221                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
  2222                              <1> 	;
  2223                              <1> 	; Adds new page to swap queue
  2224                              <1> 	; (page directories and page tables must not be added
  2225                              <1> 	; to swap queue)	
  2226                              <1> 	;
  2227                              <1> 	; INPUT ->
  2228                              <1> 	;	EBX = Linear (Virtual) addr for current process
  2229                              <1> 	;	[u.uno]
  2230                              <1> 	;	20/02/2017
  2231                              <1> 	;	(Linear address = CORE + user's virtual address)
  2232                              <1> 	;
  2233                              <1> 	; OUTPUT ->
  2234                              <1> 	;	EAX = [swpq_count]
  2235                              <1> 	;	      (after the PTE has been added)
  2236                              <1> 	;	EAX = 0 -> Swap queue is full, (1024 entries)
  2237                              <1> 	;	      the PTE could not be added.
  2238                              <1> 	;
  2239                              <1> 	; Modified Registers -> EAX
  2240                              <1> 	;
  2241                              <1> ;	push	ebx
  2242                              <1> ;       and     bx, ~PAGE_OFF ; ~0FFFh ; reset bits, 0 to 11
  2243                              <1> ;	mov	bl, [u.uno] ; current process number
  2244                              <1> ;	call	swap_queue_shift ; drop from the queue if
  2245                              <1> ;				 ; it is already on the queue
  2246                              <1> ;		; then add it to the tail of the queue
  2247                              <1> ;	movzx	eax, word [swpq_count]
  2248                              <1> ;	cmp	ax, 1024
  2249                              <1> ;	jb	short atsq_1
  2250                              <1> ;	sub	ax, ax
  2251                              <1> ;	pop	ebx
  2252                              <1> ;	retn
  2253                              <1> ;atsq_1:
  2254                              <1> ;	push	esi
  2255                              <1> ;	mov	esi, swap_queue
  2256                              <1> ;	and	ax, ax
  2257                              <1> ;	jz	short atsq_2
  2258                              <1> ;	shl	ax, 2	; convert to offset
  2259                              <1> ;	add	esi, eax
  2260                              <1> ;	shr	ax, 2
  2261                              <1> ;atsq_2:
  2262                              <1> ;	inc	ax
  2263                              <1> ;	mov	[esi], ebx ; Virtual address + [u.uno] combination
  2264                              <1> ;	mov	[swpq_count], ax
  2265                              <1> ;	pop	esi
  2266                              <1> ;	pop	ebx
  2267                              <1> ;	retn
  2268                              <1> 
  2269                              <1> ; 17/04/2021
  2270                              <1> ; ('unlink_swap_block' procedure call is disabled as temporary)
  2271                              <1> 
  2272                              <1> unlink_swap_block:
  2273                              <1> 	; 15/09/2015
  2274                              <1> 	; 30/04/2015
  2275                              <1> 	; 18/04/2015
  2276                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
  2277                              <1> 	;
  2278                              <1> 	; INPUT -> 
  2279                              <1> 	;	EAX = swap disk/file offset address
  2280                              <1> 	;	      (bit 1 to bit 31)
  2281                              <1> 	; OUTPUT ->
  2282                              <1> 	;	[swpd_free] is increased
  2283                              <1> 	;	(corresponding SWAP DISK ALLOC. TABLE bit is SET)
  2284                              <1> 	;
  2285                              <1> 	; Modified Registers -> EAX
  2286                              <1> 	;
  2287                              <1> ;	push	ebx
  2288                              <1> ;	push	edx
  2289                              <1> ;	;
  2290                              <1> ;	shr	eax, SECTOR_SHIFT+1  ;3+1 ; shift sector address to 
  2291                              <1> ;				     ; 3 bits right
  2292                              <1> ;				     ; to get swap block/page number
  2293                              <1> ;	mov	edx, eax
  2294                              <1> ;	; 15/09/2015
  2295                              <1> ;	shr	edx, 3		     ; to get offset to S.A.T.
  2296                              <1> ;				     ; (1 allocation bit = 1 page)
  2297                              <1> ;				     ; (1 allocation bytes = 8 pages)
  2298                              <1> ;	and	dl, 0FCh 	     ; clear lower 2 bits
  2299                              <1> ;				     ; (to get 32 bit position)			
  2300                              <1> ;	;
  2301                              <1> ;	mov	ebx, swap_alloc_table ; Swap Allocation Table address
  2302                              <1> ;	add	ebx, edx
  2303                              <1> ;	and	eax, 1Fh	     ; lower 5 bits only
  2304                              <1> ;				     ; (allocation bit position)	 
  2305                              <1> ;	cmp 	eax, [swpd_next]     ; is the new free block addr. lower
  2306                              <1> ;				     ; than the address in 'swpd_next' ?
  2307                              <1> ;				     ; (next/first free block value)		
  2308                              <1> ;	jnb	short uswpbl_1	     ; no	
  2309                              <1> ;	mov	[swpd_next], eax     ; yes	
  2310                              <1> ;uswpbl_1:
  2311                              <1> ;	bts	[ebx], eax	     ; unlink/release/deallocate block
  2312                              <1> ;				     ; set relevant bit to 1.
  2313                              <1> ;				     ; set CF to the previous bit value	
  2314                              <1> ;	cmc			     ; complement carry flag	
  2315                              <1> ;	jc	short uswpbl_2	     ; do not increase swfd_free count
  2316                              <1> ;				     ; if the block is already deallocated
  2317                              <1> ;				     ; before.	
  2318                              <1> ;       inc     dword [swpd_free]
  2319                              <1> ;uswpbl_2:
  2320                              <1> ;	pop	edx
  2321                              <1> ;	pop	ebx
  2322                              <1> ;	retn
  2323                              <1> 
  2324                              <1> ; 17/04/2021
  2325                              <1> ; ('ink_swap_block' procedure call is disabled as temporary)
  2326                              <1> 
  2327                              <1> link_swap_block:
  2328                              <1> 	; 01/07/2015
  2329                              <1> 	; 18/04/2015
  2330                              <1> 	; 24/10/2014 (Retro UNIX 386 v1 - beginning)
  2331                              <1> 	;
  2332                              <1> 	; INPUT -> none
  2333                              <1> 	;
  2334                              <1> 	; OUTPUT ->
  2335                              <1> 	;	EAX = OFFSET ADDRESS OF THE ALLOCATED BLOCK (4096 bytes)
  2336                              <1> 	;	      in sectors (corresponding 
  2337                              <1> 	;	      SWAP DISK ALLOCATION TABLE bit is RESET)
  2338                              <1> 	;
  2339                              <1> 	;	CF = 1 and EAX = 0 
  2340                              <1> 	; 		   if there is not a free block to be allocated	
  2341                              <1> 	;
  2342                              <1> 	; Modified Registers -> none (except EAX)
  2343                              <1> 	;
  2344                              <1> 
  2345                              <1> ;	;mov	eax, [swpd_free]
  2346                              <1> ;	;and	eax, eax
  2347                              <1> ;	;jz	short out_of_swpspc
  2348                              <1> ;	;
  2349                              <1> ;	push	ebx
  2350                              <1> ;	push	ecx
  2351                              <1> ;	;
  2352                              <1> ;	mov	ebx, swap_alloc_table ; Swap Allocation Table offset
  2353                              <1> ;	mov	ecx, ebx
  2354                              <1> ;	add	ebx, [swpd_next] ; Free block searching starts from here
  2355                              <1> ;				 ; next_free_swap_block >> 5
  2356                              <1> ;	add	ecx, [swpd_last] ; Free block searching ends here
  2357                              <1> ;				 ; (total_swap_blocks - 1) >> 5
  2358                              <1> ;lswbl_scan:
  2359                              <1> ;	cmp	ebx, ecx
  2360                              <1> ;	ja	short lswbl_notfound
  2361                              <1> ;	;
  2362                              <1> ;	bsf	eax, [ebx] ; Scans source operand for first bit set (1).
  2363                              <1> ;			   ; Clears ZF if a bit is found set (1) and 
  2364                              <1> ;			   ; loads the destination with an index to
  2365                              <1> ;			   ; first set bit. (0 -> 31) 
  2366                              <1> ;			   ; Sets ZF to 1 if no bits are found set.
  2367                              <1> ;	; 01/07/2015
  2368                              <1> ;	jnz	short lswbl_found ; ZF = 0 -> a free block has been found
  2369                              <1> ;			 ;
  2370                              <1> ;			 ; NOTE:  a Swap Disk Allocation Table bit 
  2371                              <1> ;			 ;	  with value of 1 means 
  2372                              <1> ;			 ;	  the corresponding page is free 
  2373                              <1> ;			 ;	  (Retro UNIX 386 v1 feaure only!)
  2374                              <1> ;	add	ebx, 4
  2375                              <1> ;			 ; We return back for searching next page block
  2376                              <1> ;			 ; NOTE: [swpd_free] is not ZERO; so, 
  2377                              <1> ;			 ;	 we always will find at least 1 free block here.
  2378                              <1> ;	jmp    	short lswbl_scan
  2379                              <1> ;	;
  2380                              <1> ;lswbl_notfound:	
  2381                              <1> ;	sub	ecx, swap_alloc_table
  2382                              <1> ;	mov	[swpd_next], ecx ; next/first free page = last page 
  2383                              <1> ;				 ; (unlink_swap_block procedure will change it)
  2384                              <1> ;	xor	eax, eax
  2385                              <1> ;	mov	[swpd_free], eax
  2386                              <1> ;	stc
  2387                              <1> ;lswbl_ok:
  2388                              <1> ;	pop	ecx
  2389                              <1> ;	pop	ebx
  2390                              <1> ;	retn
  2391                              <1> ;	;
  2392                              <1> ;;out_of_swpspc:
  2393                              <1> ;;	stc
  2394                              <1> ;;	retn
  2395                              <1> ;
  2396                              <1> ;lswbl_found:
  2397                              <1> ;	mov	ecx, ebx
  2398                              <1> ;	sub	ecx, swap_alloc_table
  2399                              <1> ;	mov	[swpd_next], ecx ; Set first free block searching start
  2400                              <1> ;				 ; address/offset (to the next)
  2401                              <1> ;       dec     dword [swpd_free] ; 1 block has been allocated (X = X-1) 
  2402                              <1> ;	;
  2403                              <1> ;	btr	[ebx], eax	 ; The destination bit indexed by the source value
  2404                              <1> ;				 ; is copied into the Carry Flag and then cleared
  2405                              <1> ;				 ; in the destination.
  2406                              <1> ;				 ;
  2407                              <1> ;				 ; Reset the bit which is corresponding to the 
  2408                              <1> ;				 ; (just) allocated block.
  2409                              <1> ;	shl	ecx, 5		 ; (block offset * 32) + block index
  2410                              <1> ;	add	eax, ecx	 ; = block number
  2411                              <1> ;	shl	eax, SECTOR_SHIFT ; 3, sector (offset) address of the block
  2412                              <1> ;				 ; 1 block =  8 sectors
  2413                              <1> ;	;
  2414                              <1> ;	; EAX = offset address of swap disk/file sector (beginning of the block)
  2415                              <1> ;	;
  2416                              <1> ;	; NOTE: The relevant page table entry will be updated
  2417                              <1> ;	;       according to this EAX value...
  2418                              <1> ;	;
  2419                              <1> ;	jmp	short lswbl_ok
  2420                              <1> 
  2421                              <1> ; 17/04/2021
  2422                              <1> ; ('logical_disk_read' procedure call is disabled as temporary)
  2423                              <1> 
  2424                              <1> logical_disk_read:
  2425                              <1> 	; 20/07/2015
  2426                              <1> 	; 09/03/2015 (temporary code here)
  2427                              <1> 	;
  2428                              <1> 	; INPUT ->
  2429                              <1> 	; 	ESI = Logical disk description table address
  2430                              <1> 	; 	EBX = Memory page (buffer) address (physical!)
  2431                              <1> 	; 	EAX = Sector adress (offset address, logical sector number)
  2432                              <1> 	; 	ECX = Sector count
  2433                              <1> 	;
  2434                              <1> 	;
  2435                              <1> ;	retn
  2436                              <1> 
  2437                              <1> ; 17/04/2021
  2438                              <1> ; ('logical_disk_write' procedure call is disabled as temporary)
  2439                              <1> 
  2440                              <1> logical_disk_write:
  2441                              <1> 	; 20/07/2015
  2442                              <1> 	; 09/03/2015 (temporary code here)
  2443                              <1> 	;
  2444                              <1> 	; INPUT ->
  2445                              <1> 	; 	ESI = Logical disk description table address
  2446                              <1> 	; 	EBX = Memory page (buffer) address (physical!)
  2447                              <1> 	; 	EAX = Sector adress (offset address, logical sector number)
  2448                              <1> 	; 	ECX = Sector count
  2449                              <1> 	;
  2450                              <1> ;	retn
  2451                              <1> 
  2452                              <1> get_physical_addr:
  2453                              <1> 	; 17/04/2021 - TRDOS 386 v2.0.4
  2454                              <1> 	;	(temporary modifications)
  2455                              <1> 	;
  2456                              <1> 	; 26/03/2017
  2457                              <1> 	; 20/02/2017
  2458                              <1> 	; 27/05/2016 - TRDOS 386 (TRDOS v2.0)
  2459                              <1> 	; 18/10/2015
  2460                              <1> 	; 29/07/2015
  2461                              <1> 	; 20/07/2015
  2462                              <1> 	; 04/06/2015
  2463                              <1> 	; 20/05/2015
  2464                              <1> 	; 28/04/2015
  2465                              <1> 	; 18/04/2015
  2466                              <1> 	; Get physical address
  2467                              <1> 	;     (allocates a new page for user if it is not present)
  2468                              <1> 	;	
  2469                              <1> 	; (This subroutine is needed for mapping user's virtual 
  2470                              <1> 	; (buffer) address to physical address (of the buffer).)
  2471                              <1> 	; ('sys write', 'sys read' system calls...)
  2472                              <1> 	;
  2473                              <1> 	; INPUT ->
  2474                              <1> 	;	EBX = virtual address
  2475                              <1> 	;	u.pgdir = page directory (physical) address
  2476                              <1> 	;
  2477                              <1> 	; OUTPUT ->
  2478                              <1> 	;	EAX = physical address 
  2479                              <1> 	;	EBX = linear address	
  2480                              <1> 	;	EDX = physical address of the page frame
  2481                              <1> 	;	      (with attribute bits)
  2482                              <1> 	;	ECX = byte count within the page frame
  2483                              <1> 	;
  2484                              <1> 	; Modified Registers -> EAX, EBX, ECX, EDX
  2485                              <1> 	;
  2486 00005BBE 81C300004000        <1> 	add	ebx, CORE ; 18/10/2015
  2487                              <1> get_physical_addr_x: ; 27/05/2016
  2488 00005BC4 A1[CC940100]        <1> 	mov	eax, [u.pgdir]
  2489 00005BC9 E824FDFFFF          <1> 	call	get_pte
  2490                              <1> 		; EDX = Page table entry address (if CF=0)
  2491                              <1> 	        ;       Page directory entry address (if CF=1)
  2492                              <1> 		;       (Bit 0 value is 0 if PT is not present)
  2493                              <1> 		; EAX = Page table entry value (page address)
  2494                              <1> 		;	CF = 1 -> PDE not present or invalid ? 
  2495 00005BCE 731C                <1> 	jnc	short gpa_1
  2496                              <1> 	;
  2497 00005BD0 E80BFCFFFF          <1> 	call	allocate_page
  2498 00005BD5 723F                <1> 	jc	short gpa_im_err  ; 'insufficient memory' error
  2499                              <1> gpa_0:
  2500 00005BD7 E875FCFFFF          <1> 	call 	clear_page
  2501                              <1> 	; EAX = Physical (base) address of the allocated (new) page
  2502 00005BDC 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER ; 4+2+1 = 7
  2503                              <1> 			   ; lower 3 bits are used as U/S, R/W, P flags
  2504                              <1> 			   ; (user, writable, present page)	
  2505 00005BDE 8902                <1> 	mov	[edx], eax ; Let's put the new page directory entry here !
  2506 00005BE0 A1[CC940100]        <1> 	mov	eax, [u.pgdir]	
  2507 00005BE5 E808FDFFFF          <1> 	call	get_pte
  2508 00005BEA 722A                <1> 	jc	short gpa_im_err ; 'insufficient memory' error
  2509                              <1> gpa_1:
  2510                              <1> 	; EAX = PTE value, EDX = PTE address
  2511 00005BEC A801                <1> 	test 	al, PTE_A_PRESENT
  2512 00005BEE 7516                <1> 	jnz	short gpa_3 ; 26/03/2017
  2513 00005BF0 09C0                <1> 	or	eax, eax
  2514 00005BF2 7446                <1> 	jz	short gpa_7  ; Allocate a new page
  2515                              <1> 
  2516                              <1> ; 17/04/2021 (TRDOS 386 v2.0.4)
  2517                              <1> ; ('reload_page' procedure call is disabled as temporary)
  2518 00005BF4 EB20                <1> 	jmp	short gpa_im_err  ; temporary !
  2519                              <1> 
  2520                              <1> 	; 20/07/2015
  2521                              <1> ;	push	ebp
  2522                              <1> ;	mov	ebp, ebx ; virtual (linear) address
  2523                              <1> ;	; reload swapped page
  2524                              <1> ;	call	reload_page ; 28/04/2015
  2525                              <1> ;	pop	ebp
  2526                              <1> ;	jc	short gpa_retn
  2527                              <1> gpa_2:
  2528                              <1> 	; 26/03/2017
  2529                              <1> 	; 20/02/2017
  2530                              <1> 	; If a page will contain a Signal Response Byte
  2531                              <1> 	; it must not be swapped out, because
  2532                              <1> 	; timer service or irq callback service
  2533                              <1> 	; will write a signal return/response byte 
  2534                              <1> 	; directly by using physical address of Signal
  2535                              <1> 	; Response Byte.(Even if process is not running,
  2536                              <1> 	; or it is running with swapped out pages.)
  2537                              <1> 	;
  2538                              <1> 	; 'no_page_swap' will be set by 'systimer' or
  2539                              <1> 	; 'syscalbac' sistem functions/calls. (*)
  2540                              <1> 	;
  2541 00005BF6 803D[5A8E0100]00    <1> 	cmp	byte [no_page_swap], 0
  2542 00005BFD 761D                <1> 	jna	short gpa_4 ; this page can be swapped out
  2543                              <1> 	; this page must not be swapped out
  2544                              <1> 	; but 'no_page_swap' must be reset here
  2545                              <1> 	; immediately for other callers (*)
  2546                              <1> 	; (otherwise, swap queue would not be long enough) 
  2547 00005BFF E844000000          <1> 	call	gpa_8 ; 26/03/2017
  2548 00005C04 EB16                <1> 	jmp	short gpa_5
  2549                              <1> gpa_3: 
  2550                              <1> 	; 26/03/2017
  2551 00005C06 803D[5A8E0100]00    <1> 	cmp	byte [no_page_swap], 0
  2552 00005C0D 7611                <1> 	jna	short gpa_6 ; this page can be swapped out
  2553 00005C0F E834000000          <1> 	call	gpa_8
  2554 00005C14 EB0A                <1> 	jmp	short gpa_6
  2555                              <1> 
  2556                              <1> gpa_im_err:	
  2557 00005C16 B804000000          <1> 	mov	eax, ERR_MINOR_IM ; Insufficient memory (minor) error!
  2558                              <1> 				  ; Major error = 0 (No protection fault)	
  2559 00005C1B C3                  <1> 	retn
  2560                              <1> gpa_4:
  2561                              <1> ; 17/04/2021 (TRDOS 386 v2.0.4)
  2562                              <1> ; ('add_to_swap_queue' procedure call is disabled as temporary)
  2563                              <1> 
  2564                              <1> 	; 20/07/2015
  2565                              <1> 	; 20/05/2015
  2566                              <1> 	; add this page to swap queue
  2567                              <1> ;	push	eax 
  2568                              <1> ;	; EBX = Linear (CORE+virtual) address ; 20/02/2017 
  2569                              <1> ;	call 	add_to_swap_queue
  2570                              <1> ;	pop	eax
  2571                              <1> gpa_5:
  2572                              <1> 		; PTE address in EDX
  2573                              <1> 		; virtual address in EBX
  2574                              <1> 	; EAX = memory page address
  2575 00005C1C 0C07                <1> 	or	al, PTE_A_PRESENT + PTE_A_USER + PTE_A_WRITE
  2576                              <1> 				  ; present flag, bit 0 = 1
  2577                              <1> 				  ; user flag, bit 2 = 1	
  2578                              <1> 				  ; writable flag, bit 1 = 1
  2579 00005C1E 8902                <1> 	mov	[edx], eax  ; Update PTE value
  2580                              <1> gpa_6:
  2581                              <1> 	; 18/10/2015
  2582 00005C20 89D9                <1> 	mov	ecx, ebx
  2583 00005C22 81E1FF0F0000        <1> 	and	ecx, PAGE_OFF
  2584 00005C28 89C2                <1> 	mov 	edx, eax
  2585 00005C2A 662500F0            <1> 	and	ax, PTE_A_CLEAR
  2586 00005C2E 01C8                <1> 	add	eax, ecx
  2587 00005C30 F7D9                <1> 	neg	ecx ; 1 -> -1 (0FFFFFFFFh), 4095 (0FFFh) -> -4095
  2588 00005C32 81C100100000        <1> 	add	ecx, PAGE_SIZE
  2589 00005C38 F8                  <1> 	clc
  2590                              <1> gpa_retn:
  2591 00005C39 C3                  <1> 	retn
  2592                              <1> gpa_7:	
  2593 00005C3A E8A1FBFFFF          <1> 	call	allocate_page
  2594 00005C3F 72D5                <1> 	jc	short gpa_im_err ; 'insufficient memory' error
  2595 00005C41 E80BFCFFFF          <1> 	call	clear_page
  2596 00005C46 EBAE                <1> 	jmp	short gpa_2
  2597                              <1> 
  2598                              <1> gpa_8: ; 26/03/2017
  2599 00005C48 C605[5A8E0100]00    <1> 	mov	byte [no_page_swap], 0
  2600                              <1> 
  2601 00005C4F C3                  <1> 	retn	; 17/04/2021 (temporary)
  2602                              <1> 
  2603                              <1> ; 17/04/2021 (TRDOS 386 v2.0.4)
  2604                              <1> ; ('swap_queue_shift' procedure call is disabled as temporary)
  2605                              <1> ;	
  2606                              <1> ;	push	ebx
  2607                              <1> ;	push	eax ; 26/03/2017
  2608                              <1> ;       and     bx, ~PAGE_OFF ; ~0FFFh ; reset bits, 0 to 11
  2609                              <1> ;	mov	bl, [u.uno] ; current process number
  2610                              <1> ;	call	swap_queue_shift ; drop from the queue if
  2611                              <1> ;				 ; it is already on the queue
  2612                              <1> ;	pop	eax ; 26/03/2017
  2613                              <1> ;	pop	ebx
  2614                              <1> ;
  2615                              <1> ;	retn
  2616                              <1> 
  2617                              <1> ; 17/04/2021
  2618                              <1> ; ('reload_page' procedure call is disabled as temporary)
  2619                              <1> 
  2620                              <1> reload_page:
  2621                              <1> 	; 20/07/2015
  2622                              <1> 	; 28/04/2015 (Retro UNIX 386 v1 - beginning)
  2623                              <1> 	;
  2624                              <1> 	; Reload (Restore) swapped page at memory
  2625                              <1> 	;
  2626                              <1> 	; INPUT -> 
  2627                              <1> 	;	EBP = Virtual (linear) memory address
  2628                              <1> 	;	EAX = PTE value (swap disk sector address)
  2629                              <1> 	;	(Swap disk sector address = bit 1 to bit 31 of EAX)	
  2630                              <1> 	; OUTPUT ->
  2631                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS OF RELOADED PAGE
  2632                              <1> 	;
  2633                              <1> 	;	CF = 1 and EAX = error code
  2634                              <1> 	;
  2635                              <1> 	; Modified Registers -> none (except EAX)
  2636                              <1> 	;
  2637                              <1> ;	shr	eax, 1   ; Convert PTE value to swap disk address 
  2638                              <1> ;	push	ebx      ;
  2639                              <1> ;	mov	ebx, eax ; Swap disk (offset) address	
  2640                              <1> ;	call	allocate_page
  2641                              <1> ;	jc	short rlp_im_err
  2642                              <1> ;	xchg 	eax, ebx	
  2643                              <1> ;	; EBX = Physical memory (page) address
  2644                              <1> ;	; EAX = Swap disk (offset) address
  2645                              <1> ;	; EBP = Virtual (linear) memory address
  2646                              <1> ;	call	swap_in
  2647                              <1> ;	jc	short rlp_swp_err  ; (swap disk/file read error)
  2648                              <1> ;	mov	eax, ebx	
  2649                              <1> ;rlp_retn:
  2650                              <1> ;	pop	ebx
  2651                              <1> ;	retn
  2652                              <1> ;	
  2653                              <1> ;rlp_im_err:	
  2654                              <1> ;	mov	eax, ERR_MINOR_IM ; Insufficient memory (minor) error!
  2655                              <1> ;				  ; Major error = 0 (No protection fault)	
  2656                              <1> ;	jmp	short rlp_retn
  2657                              <1> ;
  2658                              <1> ;rlp_swp_err:
  2659                              <1> ;	mov 	eax, SWP_DISK_READ_ERR ; Swap disk read error !
  2660                              <1> ;	jmp	short rlp_retn
  2661                              <1> 
  2662                              <1> copy_page_dir:
  2663                              <1> 	; 17/04/2021 (temporary modifications)
  2664                              <1> 	; 19/09/2015
  2665                              <1> 	; temporary - 07/09/2015
  2666                              <1> 	; 07/09/2015 (Retro UNIX 386 v1 - beginning)
  2667                              <1> 	;
  2668                              <1> 	; INPUT -> 
  2669                              <1> 	;	[u.pgdir] = PHYSICAL (real/flat) ADDRESS of the parent's
  2670                              <1> 	;		    page directory.
  2671                              <1> 	; OUTPUT ->
  2672                              <1> 	;	EAX =  PHYSICAL (real/flat) ADDRESS of the child's
  2673                              <1> 	;	       page directory.
  2674                              <1> 	;	(New page directory with new page table entries.)
  2675                              <1> 	;	(New page tables with read only copies of the parent's
  2676                              <1> 	;	pages.)
  2677                              <1> 	;	EAX = 0 -> Error (CF = 1)
  2678                              <1> 	;
  2679                              <1> 	; Modified Registers -> none (except EAX)
  2680                              <1> 	;
  2681 00005C50 E88BFBFFFF          <1> 	call	allocate_page
  2682 00005C55 723E                <1> 	jc	short cpd_err
  2683                              <1> 	;
  2684 00005C57 55                  <1> 	push	ebp ; 20/07/2015
  2685 00005C58 56                  <1> 	push	esi
  2686 00005C59 57                  <1> 	push	edi
  2687 00005C5A 53                  <1> 	push	ebx
  2688 00005C5B 51                  <1> 	push	ecx
  2689 00005C5C 8B35[CC940100]      <1> 	mov	esi, [u.pgdir]
  2690 00005C62 89C7                <1> 	mov	edi, eax
  2691 00005C64 50                  <1> 	push	eax ; save child's page directory address
  2692                              <1> 	; copy PDE 0 from the parent's page dir to the child's page dir
  2693                              <1> 	; (use same system space for all user page tables) 
  2694 00005C65 A5                  <1> 	movsd
  2695 00005C66 BD00004000          <1> 	mov	ebp, 1024*4096 ; pass the 1st 4MB (system space)
  2696 00005C6B B9FF030000          <1> 	mov	ecx, (PAGE_SIZE / 4) - 1 ; 1023
  2697                              <1> cpd_0:	
  2698 00005C70 AD                  <1> 	lodsd
  2699                              <1> 	;or	eax, eax
  2700                              <1>         ;jnz     short cpd_1
  2701 00005C71 A801                <1> 	test	al, PDE_A_PRESENT ;  bit 0 =  1
  2702 00005C73 7508                <1> 	jnz	short cpd_1
  2703                              <1>  	; (virtual address at the end of the page table)	
  2704 00005C75 81C500004000        <1> 	add	ebp, 1024*4096 ; page size * PTE count
  2705 00005C7B EB0F                <1> 	jmp	short cpd_2
  2706                              <1> cpd_1:	
  2707 00005C7D 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear attribute bits
  2708 00005C81 89C3                <1> 	mov	ebx, eax
  2709                              <1> 	; EBX = Parent's page table address
  2710 00005C83 E81F000000          <1> 	call	copy_page_table
  2711 00005C88 720C                <1> 	jc	short cpd_p_err
  2712                              <1> 	; EAX = Child's page table address
  2713 00005C8A 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER
  2714                              <1> 			 ; set bit 0, bit 1 and bit 2 to 1
  2715                              <1> 			 ; (present, writable, user)
  2716                              <1> cpd_2:
  2717 00005C8C AB                  <1> 	stosd
  2718 00005C8D E2E1                <1> 	loop	cpd_0
  2719                              <1> 	;
  2720 00005C8F 58                  <1> 	pop	eax  ; restore child's page directory address
  2721                              <1> cpd_3:
  2722 00005C90 59                  <1> 	pop	ecx
  2723 00005C91 5B                  <1> 	pop	ebx
  2724 00005C92 5F                  <1> 	pop	edi
  2725 00005C93 5E                  <1> 	pop	esi
  2726 00005C94 5D                  <1> 	pop	ebp
  2727                              <1> cpd_err:
  2728 00005C95 C3                  <1> 	retn
  2729                              <1> cpd_p_err:
  2730                              <1> 	; release the allocated pages missing (recover free space)
  2731 00005C96 58                  <1> 	pop	eax  ; the new page directory address (physical)
  2732 00005C97 8B1D[CC940100]      <1> 	mov	ebx, [u.pgdir] ; parent's page directory address 
  2733 00005C9D E86EFCFFFF          <1> 	call 	deallocate_page_dir
  2734 00005CA2 29C0                <1> 	sub	eax, eax ; 0
  2735 00005CA4 F9                  <1> 	stc
  2736 00005CA5 EBE9                <1> 	jmp	short cpd_3	
  2737                              <1> 
  2738                              <1> copy_page_table:
  2739                              <1> 	; 17/04/2021 (temporary modifications)
  2740                              <1> 	; 19/09/2015
  2741                              <1> 	; temporary - 07/09/2015
  2742                              <1> 	; 07/09/2015 (Retro UNIX 386 v1 - beginning)
  2743                              <1> 	;
  2744                              <1> 	; INPUT -> 
  2745                              <1> 	;	EBX = PHYSICAL (real/flat) ADDRESS of the parent's page table.
  2746                              <1> 	;	EBP = page table entry index (from 'copy_page_dir')
  2747                              <1> 	; OUTPUT ->
  2748                              <1> 	;	EAX = PHYSICAL (real/flat) ADDRESS of the child's page table.
  2749                              <1> 	;	EBP = (recent) page table index (for 'add_to_swap_queue')	
  2750                              <1> 	;	CF = 1 -> error 
  2751                              <1> 	;
  2752                              <1> 	; Modified Registers -> EBP (except EAX)
  2753                              <1> 	;
  2754 00005CA7 E834FBFFFF          <1> 	call	allocate_page
  2755 00005CAC 7244                <1> 	jc	short cpt_err
  2756                              <1> 	;
  2757 00005CAE 50                  <1> 	push	eax ; *
  2758                              <1> 	;push 	ebx
  2759 00005CAF 56                  <1> 	push	esi
  2760 00005CB0 57                  <1> 	push	edi
  2761 00005CB1 52                  <1> 	push	edx
  2762 00005CB2 51                  <1> 	push	ecx
  2763                              <1> 	;
  2764 00005CB3 89DE                <1> 	mov	esi, ebx
  2765 00005CB5 89C7                <1> 	mov	edi, eax
  2766 00005CB7 89C2                <1> 	mov	edx, eax
  2767 00005CB9 81C200100000        <1> 	add	edx, PAGE_SIZE 	
  2768                              <1> cpt_0:
  2769 00005CBF AD                  <1> 	lodsd
  2770 00005CC0 A801                <1> 	test	al, PTE_A_PRESENT ;  bit 0 = 1
  2771                              <1> 	;jnz	short cpt_1 (*)
  2772                              <1> 	; 17/04/2021 (temporary (*)
  2773                              <1> 	;and	eax, eax (*)
  2774 00005CC2 741E                <1> 	jz	short cpt_2  ; 17/04/2021
  2775                              <1> 	
  2776                              <1> ; 17/04/2021
  2777                              <1> ; ('reload_page' procedure call is disabled as temporary)
  2778                              <1> ;
  2779                              <1> ;	; ebp = virtual (linear) address of the memory page
  2780                              <1> ;	call	reload_page ; 28/04/2015
  2781                              <1> ;	jc	short cpt_p_err
  2782                              <1> cpt_1:
  2783 00005CC4 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; clear attribute bits
  2784 00005CC8 89C1                <1> 	mov	ecx, eax
  2785                              <1> 	; Allocate a new page for the child process
  2786 00005CCA E811FBFFFF          <1> 	call	allocate_page
  2787 00005CCF 721C                <1> 	jc	short cpt_p_err
  2788 00005CD1 57                  <1> 	push	edi
  2789 00005CD2 56                  <1> 	push	esi
  2790 00005CD3 89CE                <1> 	mov	esi, ecx
  2791 00005CD5 89C7                <1> 	mov	edi, eax
  2792 00005CD7 B900040000          <1> 	mov	ecx, PAGE_SIZE/4
  2793 00005CDC F3A5                <1> 	rep	movsd	; copy page (4096 bytes)
  2794 00005CDE 5E                  <1> 	pop	esi
  2795 00005CDF 5F                  <1> 	pop	edi
  2796                              <1> 	; 
  2797                              <1> 
  2798                              <1> ; 17/04/2021
  2799                              <1> ; ('add_to_swap_queue' procedure call is disabled as temporary)	
  2800                              <1> ;
  2801                              <1> ;	push	ebx
  2802                              <1> ;	push	eax
  2803                              <1> ;	mov	ebx, ebp
  2804                              <1> ;	; ebx = virtual address of the memory page
  2805                              <1> ;	call	add_to_swap_queue
  2806                              <1> ;	pop	eax
  2807                              <1> ;	pop	ebx
  2808                              <1> 	;
  2809                              <1> 	;or	ax, PTE_A_USER+PTE_A_PRESENT 
  2810 00005CE0 0C07                <1> 	or	al, PTE_A_USER+PTE_A_WRITE+PTE_A_PRESENT 
  2811                              <1> cpt_2:
  2812 00005CE2 AB                  <1> 	stosd  ; EDI points to child's PTE  	 
  2813                              <1> 	;
  2814 00005CE3 81C500100000        <1> 	add	ebp, 4096 ; 20/07/2015 (next page)
  2815                              <1> 	;
  2816 00005CE9 39D7                <1> 	cmp	edi, edx
  2817 00005CEB 72D2                <1> 	jb	short cpt_0
  2818                              <1> cpt_p_err:
  2819 00005CED 59                  <1> 	pop	ecx
  2820 00005CEE 5A                  <1> 	pop	edx
  2821 00005CEF 5F                  <1> 	pop	edi
  2822 00005CF0 5E                  <1> 	pop	esi
  2823                              <1> 	;pop	ebx
  2824 00005CF1 58                  <1> 	pop	eax ; *
  2825                              <1> cpt_err:
  2826 00005CF2 C3                  <1> 	retn
  2827                              <1> 
  2828                              <1> allocate_memory_block:
  2829                              <1> 	; 01/05/2017
  2830                              <1> 	; 28/04/2017
  2831                              <1> 	; 25/04/2017
  2832                              <1> 	; 01/04/2016, 02/04/2016, 03/04/2016
  2833                              <1> 	; 13/03/2016, 14/03/2016
  2834                              <1> 	; 12/03/2016 (TRDOS 386 = TRDOS v2.0)
  2835                              <1> 	; Allocating contiguous memory pages (in the kernel's memory space)
  2836                              <1> 	;
  2837                              <1> 	; INPUT -> 
  2838                              <1> 	;	EAX = Beginning address (physical)
  2839                              <1> 	;	EAX = 0 -> Allocate memory block from the first proper aperture	
  2840                              <1> 	;	ECX = Number of bytes to be allocated
  2841                              <1> 	;
  2842                              <1> 	; OUTPUT ->
  2843                              <1> 	; 	1) cf = 0 -> successful
  2844                              <1> 	;	EAX = Beginning (physical) address of the allocated memory block
  2845                              <1> 	;	ECX = Number of allocated bytes (rounded up to page borders) 
  2846                              <1> 	;	2) cf = 1 -> unsuccessful
  2847                              <1> 	;	 2.1) If EAX > 0 -> 
  2848                              <1> 	;	      (Number of requested pages is more than # of free pages
  2849                              <1> 	;	       but contiguous free pages -the aperture- is not enough!)	   	
  2850                              <1> 	;	      EAX = Beginning address of available aperture
  2851                              <1> 	;		    (one of all aperture with max. aperture size/length)		
  2852                              <1> 	;	      ECX = Size of available aperture (memory block) in bytes
  2853                              <1> 	;	 2.2) If EAX = 0 -> Out of memory error 
  2854                              <1> 	;	            (number of free pages is less than requested number)
  2855                              <1> 	;	      ECX = Total number of free bytes (free pages * 4096) 
  2856                              <1> 	;		    (It is not number of contiguous free bytes)	
  2857                              <1> 	;
  2858                              <1> 	; (Modified Registers -> EAX, ECX)
  2859                              <1> 	;
  2860                              <1> 	; PURPOSE: Loading a file at memory for copying or running etc.
  2861                              <1> 	; If this procedure returns with cf is set, ECX contains maximum
  2862                              <1> 	; available space and EAX contains the beginning address of it.
  2863                              <1> 	; If EAX has zero, ECX contains total number of free bytes.
  2864                              <1> 	; If requested block has been successfully allocated (by rounding up to
  2865                              <1> 	; the last page border), it must be deallocated later by using
  2866                              <1> 	; 'deallocate_memory_block' procedure.    
  2867                              <1> 
  2868 00005CF3 52                  <1> 	push	edx ; *
  2869 00005CF4 BAFF0F0000          <1> 	mov	edx, PAGE_SIZE - 1   ; 4095
  2870 00005CF9 01D0                <1> 	add	eax, edx
  2871 00005CFB 01D1                <1> 	add	ecx, edx
  2872 00005CFD C1E90C              <1> 	shr	ecx, PAGE_SHIFT	     ; 12
  2873                              <1> 
  2874                              <1> 	; ECX = number of contiguous pages to be allocated
  2875 00005D00 8B15[C87C0100]      <1> 	mov	edx, [free_pages]
  2876                              <1> 	; 01/05/2017
  2877                              <1> 	;or	ecx, ecx
  2878                              <1> 	;jz	short amb3
  2879                              <1> 	; If ECX=0, set cf to 1 and return with max. available mem block size
  2880                              <1> 
  2881 00005D06 39D1                <1> 	cmp	ecx, edx
  2882 00005D08 7760                <1> 	ja	short amb_3
  2883                              <1> 
  2884 00005D0A C1E80C              <1> 	shr	eax, PAGE_SHIFT      ; 12
  2885                              <1> 
  2886 00005D0D 89C2                <1> 	mov	edx, eax 	     ; page number
  2887 00005D0F C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
  2888                              <1> 				     ; (1 allocation bit = 1 page)
  2889                              <1> 				     ; (1 allocation bytes = 8 pages)
  2890 00005D12 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
  2891                              <1> 				     ; (to get 32 bit position)	
  2892 00005D15 53                  <1> 	push	ebx ; **
  2893                              <1> amb_0:
  2894 00005D16 890D[78880100]      <1> 	mov	[mem_ipg_count], ecx ; initial (reset) value of page count
  2895 00005D1C 890D[7C880100]      <1> 	mov	[mem_pg_count], ecx
  2896 00005D22 31C9                <1> 	xor	ecx, ecx ; 0
  2897 00005D24 890D[80880100]      <1> 	mov	[mem_aperture], ecx ; 0
  2898 00005D2A 890D[84880100]      <1> 	mov	[mem_max_aperture], ecx ; 0
  2899                              <1> 	
  2900 00005D30 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL   ; Memory Allocation Table address.
  2901 00005D35 3B15[CC7C0100]      <1> 	cmp	edx, [next_page]     ; Is the beginning page address lower
  2902                              <1> 				     ; than the address in 'next_page' ?
  2903                              <1> 				     ; (the first/next free page of user space)		
  2904 00005D3B 7208                <1> 	jb	short amb_1
  2905 00005D3D 3B15[D07C0100]      <1> 	cmp 	edx, [last_page]     ; is the beginning page address higher
  2906                              <1> 				     ; than the address in 'last_page' ?
  2907                              <1> 				     ; (end of the memory)		
  2908 00005D43 7606                <1> 	jna	short amb_2	     ; no	
  2909                              <1> amb_1:
  2910 00005D45 8B15[CC7C0100]      <1> 	mov	edx, [next_page]     ; M.A.T. offset (1 M.A.T. byte = 8 pages)
  2911                              <1> amb_2:
  2912 00005D4B 01D3                <1> 	add	ebx, edx
  2913                              <1> 
  2914                              <1> 	; 28/04/2017
  2915                              <1> 	;xor	ecx, ecx
  2916 00005D4D 0FBC0B              <1> 	bsf	ecx, [ebx]	     ; 0 to 31
  2917 00005D50 89D0                <1> 	mov	eax, edx
  2918 00005D52 C1E003              <1> 	shl	eax, 3		     ; *8	
  2919 00005D55 01C8                <1> 	add	eax, ecx	     ; beginning page number
  2920                              <1> 
  2921 00005D57 A3[88880100]        <1> 	mov	[mem_pg_pos], eax    ; beginning page no (for curr. mem. aperture)
  2922 00005D5C A3[8C880100]        <1>  	mov	[mem_max_pg_pos], eax ; beginning page no for max. mem. aperture
  2923                              <1> 
  2924 00005D61 83E01F              <1> 	and	eax, 1Fh	     ; lower 5 bits only (0 to 31)
  2925                              <1> 				     ; (allocation bit position)	 
  2926 00005D64 750E                <1> 	jnz	short amb_4	     ; 0
  2927 00005D66 B120                <1> 	mov	cl, 32
  2928 00005D68 EB4B                <1> 	jmp	short amb_10
  2929                              <1> 
  2930                              <1> amb_3:	; out_of_memory
  2931 00005D6A 31C0                <1> 	xor	eax, eax ; 0
  2932 00005D6C 89D1                <1> 	mov	ecx, edx ; free pages
  2933 00005D6E C1E10C              <1> 	shl	ecx, PAGE_SHIFT
  2934 00005D71 5A                  <1> 	pop	edx ; *
  2935 00005D72 F9                  <1> 	stc
  2936 00005D73 C3                  <1> 	retn	
  2937                              <1> amb_4:
  2938 00005D74 8B13                <1> 	mov	edx, [ebx]
  2939 00005D76 88C1                <1> 	mov	cl, al ; 1 to 31
  2940 00005D78 D3EA                <1> 	shr	edx, cl
  2941 00005D7A 89D0                <1> 	mov	eax, edx
  2942                              <1> amb_5:
  2943 00005D7C D1E8                <1> 	shr	eax, 1 ; (***)
  2944 00005D7E 7317                <1> 	jnc	short amb_7
  2945 00005D80 FF05[80880100]      <1> 	inc	dword [mem_aperture]
  2946 00005D86 FF0D[7C880100]      <1> 	dec	dword [mem_pg_count]
  2947 00005D8C 747F                <1> 	jz	short amb_15
  2948                              <1> amb_6:
  2949                              <1> 	; 28/04/2017
  2950 00005D8E FEC1                <1> 	inc	cl
  2951 00005D90 80F920              <1> 	cmp	cl, 32
  2952 00005D93 730D                <1> 	jnb	short amb_9
  2953 00005D95 EBE5                <1> 	jmp	short amb_5
  2954                              <1> amb_7:
  2955 00005D97 50                  <1> 	push	eax ; (***) allocation bits (in shifted status)
  2956 00005D98 E828010000          <1> 	call	amb_26 ; set maximum memory aperture (free memory block size)
  2957 00005D9D 58                  <1> 	pop	eax ; (***)
  2958 00005D9E EBEE                <1> 	jmp	short amb_6
  2959                              <1> amb_8:
  2960                              <1> 	; 28/04/2017
  2961 00005DA0 B120                <1> 	mov	cl, 32
  2962                              <1> amb_9:
  2963 00005DA2 89DA                <1> 	mov	edx, ebx
  2964 00005DA4 81EA00001000        <1> 	sub	edx, MEM_ALLOC_TBL
  2965 00005DAA 3B15[D07C0100]      <1> 	cmp	edx, [last_page]
  2966 00005DB0 7336                <1> 	jnb	short amb_14 ; contiguous pages not enough
  2967 00005DB2 83C304              <1> 	add	ebx, 4
  2968                              <1> amb_10:
  2969 00005DB5 8B03                <1> 	mov	eax, [ebx]
  2970 00005DB7 21C0                <1> 	and 	eax, eax
  2971 00005DB9 7408                <1>         jz      short amb_11 ; there is not a free page bit in this alloc dword
  2972 00005DBB 40                  <1> 	inc	eax ; 0FFFFFFFFh -> 0
  2973 00005DBC 740C                <1> 	jz	short amb_12 ; all of bits are set (32 free pages)
  2974 00005DBE 48                  <1> 	dec	eax
  2975 00005DBF 28C9                <1> 	sub	cl, cl ; 0
  2976 00005DC1 EBB9                <1> 	jmp	short amb_5
  2977                              <1> amb_11:
  2978 00005DC3 E8FD000000          <1> 	call	amb_26 ; set maximum memory aperture (free memory block size)
  2979 00005DC8 EBD8                <1> 	jmp	short amb_9	
  2980                              <1> amb_12:
  2981 00005DCA 390D[7C880100]      <1> 	cmp	[mem_pg_count], ecx ; 32
  2982 00005DD0 7306                <1> 	jnb	short amb_13
  2983 00005DD2 8B0D[7C880100]      <1> 	mov	ecx, [mem_pg_count]
  2984                              <1> amb_13:
  2985 00005DD8 010D[80880100]      <1> 	add	[mem_aperture], ecx
  2986 00005DDE 290D[7C880100]      <1> 	sub	[mem_pg_count], ecx
  2987 00005DE4 7627                <1> 	jna	short amb_15
  2988 00005DE6 EBBA                <1> 	jmp	short amb_9 ; 01/05/2017
  2989                              <1> amb_14:
  2990 00005DE8 E8D8000000          <1> 	call	amb_26 ; 28/04/2017
  2991 00005DED A1[8C880100]        <1> 	mov	eax, [mem_max_pg_pos] ; begin address of max. mem aperture	
  2992 00005DF2 8B0D[84880100]      <1> 	mov	ecx, [mem_max_aperture] ; max. (largest) memory aperture
  2993 00005DF8 F9                  <1> 	stc
  2994 00005DF9 E9BC000000          <1>         jmp     amb_25
  2995                              <1> 
  2996                              <1> allocate_lfb_memory_block:
  2997                              <1> 	; 28/11/2023
  2998                              <1> 	; 20/10/2023 - TRDOS 386 v2.0.7
  2999                              <1> 	; (short way to set the LFB page bits on the M.A.T.)
  3000                              <1> 	; called from 'allocate_lfb_pages_for_kernel' 
  3001 00005DFE A3[88880100]        <1> 	mov	[mem_pg_pos], eax    ; LFB start/base address as page number
  3002 00005E03 890D[80880100]      <1> 	mov	[mem_aperture], ecx  ; number of LFB pages
  3003                              <1> 				     ; (!which overlapping main memory!)
  3004 00005E09 52                  <1> 	push	edx ; *
  3005 00005E0A 53                  <1> 	push	ebx ; **
  3006 00005E0B EB0B                <1> 	jmp	short amb_16
  3007                              <1> 
  3008                              <1> amb_15: ; OK !
  3009 00005E0D A1[88880100]        <1> 	mov	eax, [mem_pg_pos]    ; Beginning address as page number
  3010 00005E12 8B0D[80880100]      <1> 	mov	ecx, [mem_aperture]  ; Free contiguous page count (>=1)
  3011                              <1> amb_16:
  3012                              <1> 	; allocate contiguous memory pages (via memory allocation table bits)
  3013 00005E18 89C2                <1> 	mov	edx, eax
  3014                              <1> 	; 25/04/2017
  3015 00005E1A C1EA03              <1> 	shr	edx, 3		 ; 8 pages in one allocation byte
  3016 00005E1D 80E2FC              <1> 	and	dl, 0FCh	 ; clear lower 2 bits
  3017                              <1> 				 ; (for dword/32bit positioning)
  3018                              <1> 
  3019 00005E20 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL
  3020 00005E25 01D3                <1> 	add	ebx, edx
  3021 00005E27 83E01F              <1> 	and	eax, 1Fh ; 31
  3022                              <1> 	; 03/04/2016
  3023 00005E2A BA20000000          <1> 	mov	edx, 32
  3024 00005E2F 28C2                <1> 	sub	dl, al
  3025 00005E31 39CA                <1> 	cmp	edx, ecx	 ; ecx >= 1
  3026 00005E33 7602                <1> 	jna	short amb_17
  3027 00005E35 89CA                <1> 	mov	edx, ecx
  3028                              <1> amb_17:
  3029 00005E37 29D1                <1> 	sub	ecx, edx
  3030 00005E39 51                  <1> 	push	ecx ; ***
  3031 00005E3A 89D1                <1> 	mov	ecx, edx
  3032                              <1> amb_18:		
  3033 00005E3C 0FB303              <1> 	btr	[ebx], eax	 ; The destination bit indexed by the source value
  3034                              <1> 				 ; is copied into the Carry Flag and then cleared
  3035                              <1> 				 ; in the destination.
  3036                              <1> 	; 20/10/2023
  3037                              <1> 	; (for LFB page allocation.. 
  3038                              <1> 	;  -here, to prevent using LFB pages for another allocation later-
  3039                              <1> 	;  /// the destination bit must be 0 -already- ..
  3040                              <1> 	;  so, following 'jnc' is not necessary but i am not removing it
  3041                              <1> 	;  for understanding why free page count is decreased here.) 
  3042                              <1> 	;   
  3043                              <1> 	;jnc	short amb_28 ; requested page is already allocated 
  3044                              <1> 
  3045 00005E3F FF0D[C87C0100]      <1> 	dec     dword [free_pages] ; 1 page has been allocated (X = X-1) 
  3046                              <1> ;amb_28:	; 20/10/2023
  3047 00005E45 49                  <1> 	dec	ecx
  3048 00005E46 7404                <1> 	jz	short amb_19
  3049 00005E48 FEC0                <1> 	inc	al
  3050 00005E4A EBF0                <1> 	jmp	short amb_18
  3051                              <1> amb_19:	
  3052 00005E4C 59                  <1> 	pop	ecx ; ***
  3053                              <1> 	;and	ecx, ecx ; 0 ?
  3054                              <1> 	;jz	short amb_22	
  3055                              <1> 	; 28/11/2023
  3056 00005E4D E31E                <1> 	jecxz	amb_22
  3057                              <1> 	; 01/04/2016
  3058 00005E4F B020                <1> 	mov	al, 32
  3059                              <1> amb_20:
  3060 00005E51 83C304              <1> 	add	ebx, 4
  3061 00005E54 39C1                <1> 	cmp	ecx, eax ; 32
  3062 00005E56 7305                <1> 	jnb	short amb_21
  3063                              <1> 	; ECX < 32
  3064 00005E58 28C0                <1> 	sub	al, al ; 0
  3065 00005E5A 50                  <1> 	push	eax ; 0 ***
  3066 00005E5B EBDF                <1> 	jmp	short amb_18
  3067                              <1> amb_21:
  3068 00005E5D 2905[C87C0100]      <1> 	sub	[free_pages], eax   ; [free_pages] = [free_pages] - 32
  3069 00005E63 C70300000000        <1> 	mov	dword [ebx], 0	    ; reset 32 bits
  3070 00005E69 29C1                <1> 	sub	ecx, eax ; 32
  3071 00005E6B 75E4                <1> 	jnz	short amb_20
  3072                              <1> amb_22:
  3073 00005E6D A1[88880100]        <1> 	mov	eax, [mem_pg_pos]   ; Beginning address as page number
  3074 00005E72 8B0D[80880100]      <1> 	mov	ecx, [mem_aperture] ; Free contiguous page count
  3075                              <1> 	; [next_page] update
  3076 00005E78 89C2                <1> 	mov	edx, eax
  3077                              <1> 	; 03/04/2016
  3078 00005E7A C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
  3079                              <1> 				     ; (1 allocation bit = 1 page)
  3080                              <1> 				     ; (1 allocation bytes = 8 pages)
  3081 00005E7D 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
  3082                              <1> 				     ; (to get 32 bit position)	
  3083 00005E80 3B15[CC7C0100]      <1> 	cmp	edx, [next_page] ; first free page pointer offset
  3084 00005E86 7732                <1> 	ja	short amb_25
  3085 00005E88 BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL
  3086 00005E8D 833C1300            <1> 	cmp	dword [ebx+edx], 0
  3087 00005E91 7721                <1> 	ja	short amb_24
  3088 00005E93 89C2                <1> 	mov	edx, eax
  3089 00005E95 01CA                <1> 	add	edx, ecx
  3090 00005E97 C1EA03              <1> 	shr	edx, 3
  3091 00005E9A 80E2FC              <1> 	and	dl, 0FCh
  3092                              <1> amb_23:
  3093 00005E9D 833C1300            <1> 	cmp	dword [ebx+edx], 0
  3094 00005EA1 7711                <1> 	ja	short amb_24
  3095 00005EA3 83C204              <1> 	add	edx, 4
  3096 00005EA6 3B15[D07C0100]      <1> 	cmp	edx, [last_page]    ; last page pointer offset
  3097 00005EAC 76EF                <1> 	jna	short amb_23
  3098 00005EAE 8B15[D47C0100]      <1> 	mov	edx, [first_page]   ; (for) beginning of user's space
  3099                              <1> amb_24:
  3100 00005EB4 8915[CC7C0100]      <1> 	mov	[next_page], edx
  3101                              <1> amb_25:
  3102 00005EBA 9C                  <1> 	pushf
  3103 00005EBB C1E00C              <1> 	shl	eax, PAGE_SHIFT	     ; convert to phy. address in bytes
  3104 00005EBE C1E10C              <1> 	shl	ecx, PAGE_SHIFT	     ; convert to byte counts
  3105 00005EC1 9D                  <1> 	popf
  3106 00005EC2 5B                  <1> 	pop	ebx ; **
  3107 00005EC3 5A                  <1> 	pop	edx ; *
  3108 00005EC4 C3                  <1> 	retn
  3109                              <1> 
  3110                              <1> amb_26:	; set maximum free memory aperture (free memory block size) 
  3111 00005EC5 89DA                <1> 	mov	edx, ebx ; current address
  3112 00005EC7 81EA00001000        <1> 	sub	edx, MEM_ALLOC_TBL ; MAT beginning address
  3113                              <1> 	; 02/04/2016 
  3114 00005ECD C1E203              <1> 	shl	edx, 3 ; MAT byte offset * 8 = page number base
  3115 00005ED0 01CA                <1> 	add	edx, ecx ; current page number (ecx = 0 to 32)
  3116                              <1> 	;
  3117 00005ED2 A1[80880100]        <1> 	mov	eax, [mem_aperture]
  3118 00005ED7 21C0                <1> 	and	eax, eax
  3119 00005ED9 7421                <1>         jz      short amb_27
  3120 00005EDB C705[80880100]0000- <1>         mov     dword [mem_aperture], 0
  3120 00005EE3 0000                <1>
  3121 00005EE5 3B05[84880100]      <1> 	cmp	eax, [mem_max_aperture]
  3122 00005EEB 760F                <1> 	jna	short amb_27
  3123 00005EED A3[84880100]        <1> 	mov	[mem_max_aperture], eax
  3124                              <1> 	; 25/04/2017
  3125 00005EF2 A1[88880100]        <1> 	mov	eax, [mem_pg_pos]
  3126                              <1> 	; EAX = Beginning page number of the max. aperture 
  3127 00005EF7 A3[8C880100]        <1> 	mov	[mem_max_pg_pos], eax
  3128                              <1> amb_27: 
  3129 00005EFC 8915[88880100]      <1> 	mov	[mem_pg_pos], edx ; current page
  3130                              <1> 
  3131 00005F02 A1[78880100]        <1> 	mov	eax, [mem_ipg_count] ; initial (reset) value of page count
  3132 00005F07 A3[7C880100]        <1> 	mov	[mem_pg_count], eax
  3133                              <1> 
  3134 00005F0C C3                  <1> 	retn
  3135                              <1> 
  3136                              <1> ; 04/06/2024
  3137                              <1> %if 0
  3138                              <1> deallocate_memory_block_x:
  3139                              <1> 	; 26/11/2023 - TRDOS 386 v2.0.7
  3140                              <1> 	; deallocate pages after rounding up
  3141                              <1> 	; ((audio buffer size etc. may not be rounded up to page boundary)) 
  3142                              <1> 	add	ecx, PAGE_SIZE - 1   ; 4095
  3143                              <1> %endif
  3144                              <1> 
  3145                              <1> deallocate_memory_block:
  3146                              <1> 	; 03/04/2016
  3147                              <1> 	; 14/03/2016 (TRDOS 386 = TRDOS v2.0)
  3148                              <1> 	; Deallocating contiguous memory pages (in the kernel's memory space)
  3149                              <1> 	;
  3150                              <1> 	; INPUT -> 
  3151                              <1> 	;	EAX = Beginning address (physical)
  3152                              <1> 	;	ECX = Number of bytes to be deallocated
  3153                              <1> 	;
  3154                              <1> 	; OUTPUT ->
  3155                              <1> 	;	Memory Allocation Table bits will be updated
  3156                              <1> 	;	[free_pages] will be changed (increased)
  3157                              <1> 	;
  3158                              <1> 	; (Modified Registers -> EAX, ECX)
  3159                              <1> 	;
  3160                              <1> 	; PURPOSE: Unloading/Freeing a file -or an allocated memory block- 
  3161                              <1> 	; at memory after copying, running, saving, reading, writing etc.
  3162                              <1> 	;
  3163                              <1> 
  3164 00005F0D 52                  <1> 	push	edx ; *
  3165 00005F0E 53                  <1> 	push	ebx ; **
  3166                              <1> 
  3167 00005F0F C1E80C              <1> 	shr	eax, PAGE_SHIFT	     ; 12
  3168 00005F12 C1E90C              <1> 	shr	ecx, PAGE_SHIFT	     ; 12
  3169                              <1> 
  3170                              <1> 	; EAX = Beginning page number
  3171                              <1> 	; ECX = Number of contiguous pages to be deallocated
  3172                              <1> damb_0:
  3173                              <1> 	; deallocate contiguous memory pages (via memory allocation table bits)
  3174 00005F15 89C2                <1> 	mov	edx, eax
  3175 00005F17 C1EA03              <1> 	shr	edx, 3		     ; to get offset to M.A.T.
  3176                              <1> 				     ; (1 allocation bit = 1 page)
  3177                              <1> 				     ; (1 allocation bytes = 8 pages)
  3178 00005F1A 80E2FC              <1> 	and	dl, 0FCh 	     ; clear lower 2 bits
  3179                              <1> 				     ; (to get 32 bit position)	
  3180 00005F1D 3B15[CC7C0100]      <1> 	cmp	edx, [next_page] ; next free page
  3181 00005F23 7306                <1> 	jnb	short damb_1
  3182 00005F25 8915[CC7C0100]      <1> 	mov	[next_page], edx
  3183                              <1> damb_1:
  3184 00005F2B BB00001000          <1> 	mov	ebx, MEM_ALLOC_TBL
  3185 00005F30 01D3                <1> 	add	ebx, edx
  3186 00005F32 83E01F              <1> 	and	eax, 1Fh ; 31
  3187                              <1> 
  3188                              <1> 	; 03/04/2016
  3189 00005F35 BA20000000          <1> 	mov	edx, 32
  3190 00005F3A 28C2                <1> 	sub	dl, al
  3191 00005F3C 39CA                <1> 	cmp	edx, ecx
  3192 00005F3E 7602                <1> 	jna	short damb_2
  3193 00005F40 89CA                <1> 	mov	edx, ecx
  3194                              <1> damb_2:
  3195 00005F42 29D1                <1> 	sub	ecx, edx
  3196 00005F44 51                  <1> 	push	ecx ; ***
  3197 00005F45 89D1                <1> 	mov	ecx, edx
  3198                              <1> damb_3:		
  3199 00005F47 0FAB03              <1> 	bts	[ebx], eax	     ; unlink/release/deallocate page
  3200                              <1> 				     ; set relevant bit to 1.
  3201                              <1> 				     ; set CF to the previous bit value	
  3202 00005F4A FF05[C87C0100]      <1> 	inc     dword [free_pages]   ; 1 page has been deallocated (X = X+1) 
  3203 00005F50 49                  <1> 	dec	ecx
  3204 00005F51 7404                <1> 	jz	short damb_4
  3205 00005F53 FEC0                <1> 	inc	al
  3206 00005F55 EBF0                <1> 	jmp	short damb_3
  3207                              <1> damb_4:	
  3208 00005F57 59                  <1> 	pop	ecx ; ***
  3209 00005F58 21C9                <1> 	and	ecx, ecx ; 0 ?
  3210 00005F5A 741E                <1> 	jz	short damb_7
  3211                              <1> 	; 03/04/2016
  3212 00005F5C B020                <1> 	mov	al, 32
  3213                              <1> damb_5:
  3214 00005F5E 83C304              <1> 	add	ebx, 4
  3215 00005F61 39C1                <1> 	cmp	ecx, eax ; 32
  3216 00005F63 7305                <1> 	jnb	short damb_6
  3217                              <1> 	; ECX < 32
  3218 00005F65 28C0                <1> 	sub	al, al ; 0
  3219 00005F67 50                  <1> 	push	eax ; 0 ***
  3220 00005F68 EBDD                <1> 	jmp	short damb_3
  3221                              <1> damb_6:
  3222 00005F6A 0105[C87C0100]      <1> 	add	[free_pages], eax ; [free_pages] = [free_pages] + 32
  3223 00005F70 C703FFFFFFFF        <1> 	mov	dword [ebx], 0FFFFFFFFh ; set 32 bits
  3224 00005F76 29C1                <1> 	sub	ecx, eax ; 32
  3225 00005F78 75E4                <1> 	jnz	short damb_5
  3226                              <1> damb_7:
  3227 00005F7A 5B                  <1> 	pop	ebx ; **
  3228 00005F7B 5A                  <1> 	pop	edx ; *
  3229 00005F7C C3                  <1> 	retn
  3230                              <1> 
  3231                              <1> direct_memory_access:
  3232                              <1> 	; 20/10/2023
  3233                              <1> 	; 17/04/2021 (temporary modifications)
  3234                              <1> 	; 22/07/2017
  3235                              <1> 	; 12/05/2017
  3236                              <1> 	; 16/07/2016
  3237                              <1> 	; 12/07/2016 (TRDOS 386 = TRDOS v2.0)
  3238                              <1> 	; This processure will be called to map
  3239                              <1> 	; user's (ring 3) page tables to access phsical
  3240                              <1> 	; (flat/linear) memory addresses, directly (without
  3241                              <1> 	;  kernel's data transfer functions).
  3242                              <1> 	; 
  3243                              <1> 	; Purpose: Video memory access and shared memory access.
  3244                              <1> 	;
  3245                              <1> 	; INPUT -> 
  3246                              <1> 	;	EAX = Beginning address (physical).
  3247                              <1> 	;	EBX = User's buffer address ; 12/05/2017
  3248                              <1> 	;	ECX = Number of contiguous pages to be mapped.
  3249                              <1> 	; OUTPUT ->
  3250                              <1> 	;	User's page directory and pages tables
  3251                              <1> 	;	will be updated.
  3252                              <1> 	;	
  3253                              <1> 	;	If an old page table entry has valid page address, 
  3254                              <1> 	;	that page will be deallocated just before PTE will
  3255                              <1> 	;	be changed for direct (1 to 1) memory page access.
  3256                              <1> 	;
  3257                              <1> 	;	If old PTE value points to a swapped page,
  3258                              <1>         ;       that page (block) will be unlinked on swap disk. 
  3259                              <1> 	;
  3260                              <1> 	;	Newly allocated pages (except page tables) will not
  3261                              <1> 	;	be applied to Memory Allocation Table.
  3262                              <1> 	;	AVL bit 1 (PTE bit 10) of page table entry will be
  3263                              <1> 	;	used to indicate shared (direct) memory page; then,
  3264                              <1> 	;	this page will not be deallocated later during
  3265                              <1> 	;	process termination. (Memory Allocation Table and
  3266                              <1> 	;	free memory count will not be affected.
  3267                              <1> 	;	(Except deallocating page table's itself.)
  3268                              <1> 	;	
  3269                              <1> 	;      CF = 1 -> error (EAX = error code)
  3270                              <1> 	;      CF = 0 -> success (EAX = beginning address)
  3271                              <1> 	;
  3272                              <1> 	;; (Modified Registers -> none)
  3273                              <1> 	; Modified registers: ebp, edx, ecx, ebx, esi, edi	
  3274                              <1> 	;
  3275                              <1> 
  3276                              <1> 	;push	ebp
  3277                              <1> 	;push	ebx
  3278                              <1> 	;push	ecx
  3279                              <1> 	;push	edx
  3280 00005F7D 662500F0            <1> 	and	ax, PTE_A_CLEAR ; clear page offset
  3281 00005F81 50                  <1> 	push	eax
  3282                              <1> 	;and	ecx, ecx ; page count
  3283                              <1> 	;jz	dmem_acc_7  ; 'insufficient memory' error
  3284 00005F82 89C5                <1> 	mov	ebp, eax
  3285 00005F84 81C300004000        <1> 	add	ebx, CORE ; 12/05/2017
  3286                              <1> dmem_acc_0: 
  3287 00005F8A 891D[30930100]      <1> 	mov	[base_addr], ebx ; 12/05/2017
  3288 00005F90 A1[CC940100]        <1> 	mov	eax, [u.pgdir] ; page dir address (physical)
  3289 00005F95 E858F9FFFF          <1> 	call	get_pte
  3290                              <1> 		; EDX = Page table entry address (if CF=0)
  3291                              <1> 	        ;       Page directory entry address (if CF=1)
  3292                              <1> 		;       (Bit 0 value is 0 if PT is not present)
  3293                              <1> 		; EAX = Page table entry value (page address)
  3294                              <1> 		;	CF = 1 -> PDE not present or invalid ? 	
  3295 00005F9A 7321                <1> 	jnc	short dmem_acc_1
  3296                              <1> 	; 20/10/2023
  3297                              <1> 	; Allocate a page as a new page table
  3298 00005F9C E83FF8FFFF          <1> 	call	allocate_page
  3299                              <1> 	;jc	dmem_acc_7  ; 'insufficient memory' error
  3300                              <1> 	; 17/04/2021
  3301 00005FA1 7215                <1> 	jc	short _dmem_acc_7
  3302                              <1> 	;
  3303 00005FA3 E8A9F8FFFF          <1> 	call 	clear_page
  3304                              <1> 	; EAX = Physical (base) address of the allocated (new) page
  3305 00005FA8 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER ; 4+2+1 = 7
  3306                              <1> 			   ; lower 3 bits are used as U/S, R/W, P flags
  3307                              <1> 			   ; (user, writable, present page)	
  3308 00005FAA 8902                <1> 	mov	[edx], eax ; Let's put the new page directory entry here !
  3309 00005FAC A1[CC940100]        <1> 	mov	eax, [u.pgdir]	
  3310 00005FB1 E83CF9FFFF          <1> 	call	get_pte
  3311                              <1>         ;jc	dmem_acc_7 ; 'insufficient memory' error
  3312                              <1> 	; 17/04/2021
  3313 00005FB6 7305                <1> 	jnc	short dmem_acc_1
  3314                              <1> _dmem_acc_7:
  3315 00005FB8 E985000000          <1> 	jmp	dmem_acc_7
  3316                              <1> dmem_acc_1:
  3317                              <1> 	; EAX = PTE value, EDX = PTE address
  3318 00005FBD A801                <1> 	test 	al, PTE_A_PRESENT
  3319                              <1> 	;jnz	short dmem_acc_2   ; 17/04/2021 (*)
  3320                              <1> 	; 17/04/2021 (temporary)
  3321 00005FBF 745F                <1> 	jz	short short dmem_acc_6  ; ! temporary ! (*)	
  3322                              <1> 	; 20/10/2023
  3323                              <1> 	; If the page table entry is zero or invalid -not present-
  3324                              <1> 	; it will be directy allocated for the physical memory section
  3325                              <1> 	; without using the M.A.T. (Specially for LFB access -generally-
  3326                              <1> 	; is at the beyod of the physical main memory end.)
  3327                              <1> 	; (M.A.T bits are not used for direct memory access. To cancel
  3328                              <1> 	; direct memory access also is out of the M.A.T scope because
  3329                              <1> 	; direct accessed physical pages are marked as SHARED on their
  3330                              <1> 	; PTE. Shared pages are not dealloaced.)
  3331                              <1> 
  3332                              <1> ; 17/04/2021
  3333                              <1> ; (following code is disabled as temporary)
  3334                              <1> ;
  3335                              <1> ;	or	eax, eax
  3336                              <1> ;	jz	short dmem_acc_6   ; Change PTE
  3337                              <1> ;	shr	eax, 1		; swap disk block (8 sectors) address
  3338                              <1> ;	; unlink swap disk block
  3339                              <1> ;	call	unlink_swap_block
  3340                              <1> ;	jmp	short dmem_acc_6
  3341                              <1> 
  3342                              <1> dmem_acc_2:
  3343 00005FC1 A802                <1> 	test	al, PTE_A_WRITE   ; bit 1, writable (r/w) flag
  3344                              <1> 				  ; (must be 1)
  3345 00005FC3 7550                <1> 	jnz	short dmem_acc_4
  3346                              <1> 	; Read only -duplicated- page (belongs to a parent or a child)
  3347 00005FC5 66A90002            <1>         test    ax, PTE_DUPLICATED ; Was this page duplicated 
  3348                              <1> 				   ; as child's page ?
  3349 00005FC9 7455                <1> 	jz	short dmem_acc_5 ; Change PTE but don't deallocate the page!
  3350                              <1> 
  3351                              <1> 	;push	edi
  3352                              <1> 	;push	esi
  3353                              <1> 
  3354 00005FCB 51                  <1> 	push	ecx
  3355                              <1> 	;push	ebx
  3356 00005FCC 8B1D[D0940100]      <1> 	mov	ebx, [u.ppgdir] ; parent's page dir address (physical)
  3357                              <1> 	
  3358                              <1> 	; check the parent's PTE value is read only & same page or not.. 
  3359 00005FD2 89EF                <1> 	mov	edi, ebp
  3360 00005FD4 C1EF16              <1> 	shr	edi, PAGE_D_SHIFT ; 22
  3361                              <1> 	; EDI = page directory entry index (0-1023)
  3362 00005FD7 89EE                <1> 	mov	esi, ebp
  3363 00005FD9 C1EE0C              <1> 	shr	esi, PAGE_SHIFT ; 12	
  3364 00005FDC 81E6FF030000        <1> 	and	esi, PTE_MASK
  3365                              <1> 	; ESI = page table entry index (0-1023)
  3366                              <1> 
  3367 00005FE2 66C1E702            <1> 	shl	di, 2 ; * 4
  3368 00005FE6 01FB                <1> 	add	ebx, edi ; PDE offset (for the parent)
  3369 00005FE8 8B0F                <1> 	mov	ecx, [edi]
  3370 00005FEA F6C101              <1> 	test	cl, PDE_A_PRESENT ; present (valid) or not ?
  3371 00005FED 7425                <1> 	jz	short dmem_acc_3	; parent process does not use this page
  3372 00005FEF 6681E100F0          <1> 	and	cx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
  3373 00005FF4 66C1E602            <1> 	shl	si, 2 ; *4 
  3374 00005FF8 01CE                <1> 	add	esi, ecx ; PTE offset (for the parent)
  3375 00005FFA 8B1E                <1> 	mov	ebx, [esi]
  3376 00005FFC F6C301              <1> 	test	bl, PTE_A_PRESENT ; present or not ?
  3377 00005FFF 7413                <1> 	jz	short dmem_acc_3	; parent process does not use this page
  3378 00006001 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; Clear attribute bits 
  3379 00006005 6681E300F0          <1> 	and	bx, PTE_A_CLEAR ; 0F000h ; Clear attribute bits
  3380 0000600A 39D8                <1> 	cmp	eax, ebx	; parent's and child's pages are same ?
  3381 0000600C 7506                <1> 	jne	short dmem_acc_3	; not same page
  3382                              <1> 				; deallocate the child's page
  3383 0000600E 800E02              <1>         or      byte [esi], PTE_A_WRITE ; convert to writable page (parent)
  3384                              <1> 	;pop	ebx
  3385 00006011 59                  <1> 	pop	ecx
  3386 00006012 EB0C                <1> 	jmp	short dmem_acc_5
  3387                              <1> dmem_acc_3:
  3388                              <1> 	;pop	ebx
  3389 00006014 59                  <1> 	pop	ecx
  3390                              <1> dmem_acc_4:	
  3391 00006015 66A90004            <1> 	test	ax, PTE_SHARED ; shared or direct memory access indicator
  3392 00006019 7505                <1> 	jnz	short dmem_acc_5   ; AVL bit 1 = 1, do not deallocate this page!
  3393                              <1> 	;
  3394                              <1> 	;and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
  3395 0000601B E87FF9FFFF          <1> 	call	deallocate_page
  3396                              <1> dmem_acc_5:
  3397                              <1> 	;pop	esi
  3398                              <1> 	;pop	edi
  3399                              <1> dmem_acc_6:
  3400 00006020 89E8                <1> 	mov	eax, ebp ; physical page (offset=0) address
  3401                              <1> 	; EAX = memory page address
  3402                              <1> 	; EDX = PTE entry address (physical)
  3403 00006022 660D0704            <1> 	or	ax, PTE_A_PRESENT+PTE_A_USER+PTE_A_WRITE+PTE_SHARED
  3404                              <1> 			; present flag, bit 0 = 1
  3405                              <1> 			; user flag, bit 2 = 1	
  3406                              <1> 			; writable flag, bit 1 = 1
  3407                              <1> 			; direct memory access flag, bit 10 = 1
  3408                              <1> 			; (This page must not be deallocated!)
  3409 00006026 8902                <1> 	mov	[edx], eax  ; Update PTE value
  3410 00006028 49                  <1> 	dec	ecx ; remain count of contiguous pages
  3411 00006029 741E                <1> 	jz	short dmem_acc_8
  3412 0000602B 81C500100000        <1> 	add	ebp, PAGE_SIZE ; next physical page address
  3413                              <1> 	; 22/07/2017
  3414                              <1> 	;mov	eax, ebp
  3415                              <1> 	; 12/05/2017
  3416 00006031 8B1D[30930100]      <1> 	mov	ebx, [base_addr] ; linear address (virtual+CORE)
  3417 00006037 81C300100000        <1> 	add	ebx, PAGE_SIZE	; next linear address
  3418 0000603D E948FFFFFF          <1>         jmp     dmem_acc_0
  3419                              <1> dmem_acc_7:  ; ERROR ! 
  3420 00006042 C7042404000000      <1> 	mov	dword [esp], ERR_MINOR_IM 
  3421                              <1> 		; Insufficient memory (minor) error!
  3422                              <1> 		; Major error = 0 (No protection fault)	
  3423                              <1> 	; cf = 1
  3424                              <1> dmem_acc_8:
  3425 00006049 58                  <1> 	pop	eax
  3426                              <1> 	;pop	edx
  3427                              <1> 	;pop	ecx
  3428                              <1> 	;pop	ebx
  3429                              <1> 	;pop	ebp
  3430 0000604A C3                  <1> 	retn
  3431                              <1> 
  3432                              <1> deallocate_user_pages:
  3433                              <1> 	; 20/05/2017
  3434                              <1> 	; 15/05/2017
  3435                              <1> 	; 20/02/2017
  3436                              <1> 	; 19/02/2017 (TRDOS 386 = TRDOS v2.0)
  3437                              <1> 	;
  3438                              <1> 	; Deallocate virtually contiguous user pages (memory block)
  3439                              <1> 	; (caller: 'sysdalloc' system call)
  3440                              <1> 	;
  3441                              <1> 	; INPUT ->
  3442                              <1> 	;	EBX = VIRTUAL ADDRESS (beginning address)
  3443                              <1> 	;	ECX = byte count
  3444                              <1> 	;	[u.pgdir] = user's page directory
  3445                              <1> 	;	[u.ppdir] = parent's page directory
  3446                              <1> 	;
  3447                              <1> 	; OUTPUT ->
  3448                              <1> 	;    If CF = 0 	
  3449                              <1> 	;	EAX = Deallocated memory bytes
  3450                              <1> 	;	  (Even if shared or read only pages will not be
  3451                              <1> 	;	   deallocated on M.A.T., this byte count will be
  3452                              <1> 	;	   returned as virtually deallocated bytes; in fact
  3453                              <1> 	;	   virtually deallocated user pages * 4096.) 
  3454                              <1> 	;	EBX = Virtual address (as rounded up)
  3455                              <1> 	;    If CF = 1    	
  3456                              <1> 	;	EAX = 0 (there is not any deallocated pages)
  3457                              <1> 	;
  3458                              <1> 	; Note: Empty page tables will not be deallocated!!!
  3459                              <1> 	;     (they will be deallocated at process termination stage)
  3460                              <1> 	;
  3461                              <1> 	; Modified Registers -> EAX, EDX, ESI, EDI, EBX, ECX, EBP
  3462                              <1> 	;
  3463 0000604B 89DE                <1> 	mov	esi, ebx
  3464 0000604D 89F7                <1> 	mov	edi, esi
  3465 0000604F 01CF                <1> 	add	edi, ecx
  3466 00006051 81C6FF0F0000        <1> 	add	esi, PAGE_SIZE - 1  ; 4095 (round up)	
  3467 00006057 C1EE0C              <1> 	shr	esi, PAGE_SHIFT
  3468 0000605A C1EF0C              <1> 	shr	edi, PAGE_SHIFT
  3469 0000605D 89F8                <1> 	mov	eax, edi ; end page
  3470 0000605F 29F0                <1> 	sub	eax, esi ; end page - start page
  3471 00006061 0F86C8000000        <1> 	jna	da_u_pd_err  ; < 1
  3472 00006067 89F3                <1> 	mov	ebx, esi
  3473 00006069 C1E30C              <1> 	shl	ebx, PAGE_SHIFT ; virtual address (as rounded up)
  3474 0000606C 53                  <1> 	push	ebx ; *
  3475 0000606D 89C1                <1> 	mov	ecx, eax ; page count
  3476 0000606F C1E00C              <1> 	shl	eax, PAGE_SHIFT ; byte count as adjusted
  3477 00006072 50                  <1> 	push	eax ; **
  3478 00006073 8B1D[CC940100]      <1> 	mov	ebx, [u.pgdir] ; physical addr of user's page dir
  3479 00006079 81C600040000        <1>  	add	esi, CORE/PAGE_SIZE 
  3480 0000607F 89F7                <1> 	mov	edi, esi
  3481 00006081 81E7FF030000        <1> 	and	edi, PTE_MASK ; PTE entry in the page table
  3482 00006087 57                  <1> 	push	edi ; *** ; PTE index (of page directory)
  3483 00006088 C1EE0A              <1> 	shr	esi, PAGE_D_SHIFT - PAGE_SHIFT ; 22-12=10
  3484 0000608B 89F2                <1> 	mov	edx, esi 
  3485                              <1> 	; EDX = PDE index
  3486 0000608D C1E602              <1> 	shl	esi, 2 ; convert PDE index to dword offset
  3487 00006090 01DE                <1> 	add	esi, ebx ; add page directory address
  3488                              <1> da_u_pd_1:
  3489 00006092 AD                  <1> 	lodsd
  3490                              <1> 	;
  3491 00006093 89F5                <1> 	mov	ebp, esi ; 20/02/2017
  3492                              <1> 	; EBP = next PDE address
  3493                              <1> 	;
  3494 00006095 A801                <1> 	test	al, PDE_A_PRESENT ; bit 0, present flag (must be 1)
  3495 00006097 0F8487000000        <1> 	jz	da_u_pd_3 ; 20/05/2017	
  3496 0000609D 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
  3497                              <1> 	; EAX = PHYSICAL (flat) ADDRESS OF THE PAGE TABLE
  3498 000060A1 8B3C24              <1> 	mov	edi, [esp] ; ***
  3499                              <1> 	; EDI = PTE index (of complete page directory)
  3500                              <1> 	;and	edi, PTE_MASK ; PTE entry in the page table
  3501 000060A4 C1E702              <1> 	shl	edi, 2 ; convert PTE index to dword offset
  3502 000060A7 89FE                <1> 	mov	esi, edi ; PTE offset in page table (0-4092)
  3503 000060A9 01C6                <1> 	add	esi, eax ; now, esi points to requested PTE
  3504                              <1> da_u_pt_0:
  3505 000060AB AD                  <1> 	lodsd
  3506 000060AC A801                <1> 	test	al, PTE_A_PRESENT ; bit 0, present flag (must be 1)
  3507 000060AE 7452                <1> 	jz	short da_u_pt_1
  3508                              <1> 	;
  3509 000060B0 A802                <1> 	test	al, PTE_A_WRITE   ; bit 1, writable (r/w) flag
  3510                              <1> 				  ; (must be 1)
  3511 000060B2 753C                <1> 	jnz	short da_u_pt_3
  3512                              <1> 	; Read only -duplicated- page (belongs to a parent or a child)
  3513 000060B4 66A90002            <1>         test    ax, PTE_DUPLICATED ; Was this page duplicated 
  3514                              <1> 				   ; as child's page ?
  3515 000060B8 7441                <1> 	jz	short da_u_pt_4 ; Clear PTE but don't deallocate the page!
  3516                              <1> 	;
  3517                              <1> 	; check the parent's PTE value is read only & same page or not.. 
  3518                              <1> 	; EDX = page directory entry index (0-1023)
  3519 000060BA 52                  <1> 	push	edx ; ****
  3520                              <1> 	; EDI = page table entry offset (0-4092)
  3521 000060BB 8B1D[D0940100]      <1> 	mov	ebx, [u.ppgdir] ; page directory of the parent process
  3522 000060C1 66C1E202            <1> 	shl	dx, 2 ; *4 
  3523 000060C5 01D3                <1> 	add	ebx, edx ; PDE address (for the parent)
  3524 000060C7 8B13                <1> 	mov	edx, [ebx] ; page table address
  3525 000060C9 F6C201              <1> 	test	dl, PDE_A_PRESENT ; present (valid) or not ?
  3526 000060CC 7421                <1> 	jz	short da_u_pt_2	; parent process does not use this page
  3527 000060CE 6681E200F0          <1> 	and	dx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
  3528                              <1> 	; EDI = page table entry offset (0-4092)
  3529 000060D3 01D7                <1> 	add	edi, edx	; PTE address (for the parent)
  3530 000060D5 8B1F                <1> 	mov	ebx, [edi]
  3531 000060D7 F6C301              <1> 	test	bl, PTE_A_PRESENT ; present or not ?
  3532 000060DA 7413                <1> 	jz	short da_u_pt_2	; parent process does not use this page
  3533 000060DC 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; Clear attribute bits 
  3534 000060E0 6681E300F0          <1> 	and	bx, PTE_A_CLEAR ; 0F000h ; Clear attribute bits
  3535 000060E5 39D8                <1> 	cmp	eax, ebx	; parent's and child's pages are same ?
  3536 000060E7 7506                <1> 	jne	short da_u_pt_2	; not same page
  3537                              <1> 				; deallocate the child's page
  3538 000060E9 800F02              <1>         or      byte [edi], PTE_A_WRITE ; convert to writable page (parent)
  3539 000060EC 5A                  <1> 	pop	edx ; ****
  3540 000060ED EB0C                <1> 	jmp	short da_u_pt_4
  3541                              <1> 
  3542                              <1> ; 17/04/2021
  3543                              <1> ; ('da_u_pt_1' is disabled as temporary)
  3544                              <1> 
  3545                              <1> ;da_u_pt_1:
  3546                              <1> ;	or	eax, eax	; swapped page ?
  3547                              <1> ;	jz	short da_u_pt_5	; no
  3548                              <1> ;				; yes
  3549                              <1> ;	shr	eax, 1
  3550                              <1> ;	call	unlink_swap_block ; Deallocate swapped page block
  3551                              <1> ;				  ; on the swap disk (or in file)
  3552                              <1> ;	jmp	short da_u_pt_5
  3553                              <1> da_u_pt_2:
  3554 000060EF 5A                  <1> 	pop	edx ; ****
  3555                              <1> da_u_pt_3:
  3556 000060F0 66A90004            <1> 	test	ax, PTE_SHARED	; shared or direct memory access indicator
  3557 000060F4 7505                <1> 	jnz	short da_u_pt_4	; AVL bit 1 = 1, do not deallocate this page!
  3558                              <1> 	;
  3559                              <1> 	;and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
  3560 000060F6 E8A4F8FFFF          <1> 	call	deallocate_page ; set the mem allocation bit of this page
  3561                              <1> da_u_pt_4:
  3562 000060FB C746FC00000000      <1> 	mov	dword [esi-4], 0 ; clear/reset PTE (child, dupl. as parent)
  3563                              <1> ; 17/04/2021 (temporary)
  3564                              <1> da_u_pt_1:
  3565                              <1> da_u_pt_5:
  3566                              <1> 	; 20/05/2017
  3567 00006102 58                  <1> 	pop	eax ; *** PTE index (of page directory)
  3568 00006103 49                  <1> 	dec	ecx ; remain page count
  3569 00006104 7426                <1> 	jz	short da_u_pd_4
  3570 00006106 40                  <1> 	inc	eax ; next PTE
  3571 00006107 6625FF03            <1> 	and	ax, PTE_MASK ; PTE entry index in the page table
  3572 0000610B 50                  <1> 	push	eax ; *** (save again)
  3573                              <1> 	;mov	edi, eax
  3574                              <1> 	;and 	di, PTE_MASK
  3575                              <1> 	;cmp	edi, PAGE_SIZE / 4 ; 1024
  3576                              <1> 	;jnb	short da_u_pd_2
  3577 0000610C 89C7                <1> 	mov	edi, eax
  3578 0000610E C1E702              <1> 	shl	edi, 2 ; convert index to dword offset
  3579                              <1> 	;test	ax, PTE_MASK ; 3FFh
  3580 00006111 09C0                <1> 	or	eax, eax
  3581 00006113 7596                <1> 	jnz	short da_u_pt_0 ; 1-1023
  3582                              <1> da_u_pd_2:
  3583 00006115 42                  <1> 	inc	edx
  3584                              <1> 	; 20/05/2017
  3585 00006116 6681E2FF03          <1> 	and	dx, PTE_MASK  ; 3FFh
  3586 0000611B 740F                <1> 	jz	short da_u_pd_4  ; 0 (1024)
  3587                              <1> 	;cmp	edx, 1024
  3588                              <1> 	;jnb	short da_u_pd_4
  3589 0000611D 89EE                <1> 	mov	esi, ebp ; 20/02/2017
  3590 0000611F E96EFFFFFF          <1> 	jmp	da_u_pd_1
  3591                              <1> da_u_pd_3:
  3592                              <1> 	; 15/05/2017 (empty page directory entry)
  3593 00006124 81E900040000        <1> 	sub	ecx, 1024
  3594 0000612A 77E9                <1> 	ja	short da_u_pd_2 ; 20/05/2017
  3595                              <1> da_u_pd_4:
  3596 0000612C 58                  <1> 	pop	eax ; **
  3597 0000612D 5B                  <1> 	pop	ebx ; *
  3598 0000612E C3                  <1> 	retn
  3599                              <1> 
  3600                              <1> da_u_pd_err:
  3601 0000612F 31C0                <1> 	xor	eax, eax
  3602 00006131 F9                  <1> 	stc	
  3603 00006132 C3                  <1> 	retn
  3604                              <1> 
  3605                              <1> allocate_user_pages:
  3606                              <1> 	; 20/05/2017
  3607                              <1> 	; 01/05/2017, 02/05/2017, 15/05/2017
  3608                              <1> 	; 04/03/2017
  3609                              <1> 	; 20/02/2017 (TRDOS 386 = TRDOS v2.0)
  3610                              <1> 	;
  3611                              <1> 	; Allocate physically contiguous user pages (memory block)
  3612                              <1> 	; (caller: 'sysalloc' system call)
  3613                              <1> 	;
  3614                              <1> 	; Note: This procedure does not alloc a page's itself
  3615                              <1> 	;	(page bits) on Memory Allocation Table.
  3616                              <1> 	;	(allocate_memory_block is needed before this proc)
  3617                              <1> 	;
  3618                              <1> 	; INPUT ->
  3619                              <1> 	;	EAX = PHYSICAL ADDRESS (beginning address)
  3620                              <1> 	;	EBX = VIRTUAL ADDRESS (beginning address)
  3621                              <1> 	;	ECX = byte count (>=4096)
  3622                              <1> 	;	[u.pgdir] = user's page directory
  3623                              <1> 	;	
  3624                              <1> 	;	Note: All addresses are (must be) already adjusted
  3625                              <1> 	;	to page	borders, otherwise, lower 12bits of addresses
  3626                              <1> 	;	and byte count would be truncated.
  3627                              <1> 	;
  3628                              <1> 	; OUTPUT ->
  3629                              <1> 	;	none
  3630                              <1> 	;
  3631                              <1> 	;	CF = 1 -> insufficient memory error
  3632                              <1> 	;
  3633                              <1> 	; Note: All pages will be allocated in physical page order 
  3634                              <1> 	;	from the beginning page address. 
  3635                              <1> 	;	* A new page table will be added to the page dir
  3636                              <1> 	;	  when the requested PDE is invalid.
  3637                              <1> 	;	* Those pages will not be added to swap queue
  3638                              <1> 	;	  because main purpose of this allocation is to
  3639                              <1> 	;	  set a direct memory access (DMA controller) buffer.
  3640                              <1> 	;	 (Swapping out a page in a DMA buffer would be wrong!)
  3641                              <1> 	;	* Previous content of page tables (PTEs) would be
  3642                              <1> 	;	  (should be) deallocated before entering this
  3643                              <1> 	;	  procedure. So, new page table entries (PTEs)
  3644                              <1> 	;	  directly will be written without checking
  3645                              <1> 	;	  their previous content.	
  3646                              <1> 	;	* Only solution to increase free memory by removing
  3647                              <1> 	;	  that non-swappable memory block is to terminate
  3648                              <1> 	;	  the process or to wait until the process will 
  3649                              <1> 	;	  deallocate that memory block as itself. ('sysdalloc')
  3650                              <1> 	;	  (No problem, if the process does not grab all of
  3651                              <1> 	;	  -very big amount of- free memory by using
  3652                              <1> 	;	  'sysalloc' system call!?)
  3653                              <1> 	;	  (Even if the process has grabbed all of free memory, 
  3654                              <1> 	;	  no problem if the process is not running in 
  3655                              <1> 	;	  multitasking mode. No problem in multitasking
  3656                              <1> 	;	  mode if there is not another process which is running
  3657                              <1> 	;	  or waiting or sleeping for an event as it's pages
  3658                              <1> 	;	  are swapped-out. But a new process can not start to
  3659                              <1> 	;	  run if all of free memory has beeen allocated 
  3660                              <1> 	;	  by running processes. Deallocation -'sysdalloc'- 
  3661                              <1> 	;	  or terminate a running process is needed 
  3662                              <1> 	;	  in order to run a new process.) 
  3663                              <1> 	;
  3664                              <1> 	; Modified Registers -> EAX, EDX, ESI, EDI, EBX, ECX, EBP
  3665                              <1> 	;
  3666                              <1> 
  3667                              <1> 	; 01/05/2017
  3668 00006133 662500F0            <1> 	and	ax, ~PAGE_OFF
  3669 00006137 6681E300F0          <1> 	and	bx, ~PAGE_OFF
  3670                              <1> 	; 02/05/2017 
  3671 0000613C BD00F0FFFF          <1> 	mov	ebp, 0FFFFF000h ; 4 Giga Bytes - 4096 Bytes (for Stack)
  3672 00006141 C1E90C              <1> 	shr	ecx, PAGE_SHIFT ; page count
  3673 00006144 83F901              <1> 	cmp	ecx, 1
  3674 00006147 7251                <1> 	jb	short a_u_im_retn
  3675 00006149 89C2                <1> 	mov	edx, eax
  3676 0000614B 01CA                <1> 	add	edx, ecx
  3677 0000614D 724B                <1> 	jc	short a_u_im_retn
  3678 0000614F 39D5                <1> 	cmp	ebp, edx
  3679 00006151 7247                <1> 	jb	short a_u_im_retn
  3680 00006153 89DA                <1> 	mov	edx, ebx
  3681 00006155 81C200004000        <1> 	add	edx, CORE
  3682 0000615B 723D                <1> 	jc	short a_u_im_retn	
  3683 0000615D 01CA                <1> 	add	edx, ecx
  3684 0000615F 7239                <1> 	jc	short a_u_im_retn
  3685 00006161 39D5                <1> 	cmp	ebp, edx
  3686 00006163 7235                <1> 	jb	short a_u_im_retn
  3687                              <1> 	;
  3688 00006165 89C5                <1> 	mov	ebp, eax ; physical address
  3689 00006167 89DE                <1> 	mov	esi, ebx
  3690 00006169 81C600004000        <1> 	add	esi, CORE ; start of user's memory (4M) 
  3691 0000616F C1EE0C              <1> 	shr	esi, PAGE_SHIFT ; higher 20 bits of the linear address
  3692                              <1> 	;shr	ecx, PAGE_SHIFT ; page count
  3693 00006172 8B1D[CC940100]      <1> 	mov	ebx, [u.pgdir] ; physical addr of user's page dir
  3694 00006178 89F7                <1> 	mov	edi, esi
  3695 0000617A 81E7FF030000        <1> 	and	edi, PTE_MASK ; PTE entry index in the page table
  3696 00006180 57                  <1> 	push	edi  ; * ; PTE index (in page directory)
  3697 00006181 C1EE0A              <1> 	shr	esi, PAGE_D_SHIFT - PAGE_SHIFT ; 22-12=10
  3698 00006184 89F2                <1> 	mov	edx, esi 
  3699                              <1> 	; EDX = PDE index
  3700 00006186 C1E602              <1> 	shl	esi, 2 ; convert PDE index to dword offset
  3701 00006189 01DE                <1> 	add	esi, ebx ; add page directory address
  3702                              <1> a_u_pd_0:
  3703 0000618B AD                  <1> 	lodsd
  3704                              <1> 	;
  3705 0000618C 89F3                <1> 	mov	ebx, esi ; next PDE address
  3706                              <1> 	;
  3707 0000618E A801                <1> 	test	al, PDE_A_PRESENT ; bit 0, present flag (must be 1)
  3708 00006190 7513                <1> 	jnz	short a_u_pd_2
  3709                              <1> 	;
  3710                              <1> 	; empty PDE (it does not point to valid page table address)
  3711 00006192 E849F6FFFF          <1> 	call	allocate_page  ; (allocate a new page table)
  3712 00006197 7302                <1> 	jnc	short a_u_pd_1 ; OK... now, we have a new page table.
  3713                              <1> 	; cf = 1
  3714                              <1> 	; There is not a free memory page to allocate a new page table !!!
  3715 00006199 5E                  <1> 	pop	esi ; *
  3716                              <1> a_u_im_retn:
  3717 0000619A C3                  <1> 	retn	; return to 'sysalloc' with 'insufficient memory' error
  3718                              <1> 	;
  3719                              <1> a_u_pd_1: ; clear the new page table content 
  3720                              <1> 	; EAX = Physical (base) address of the new page table
  3721 0000619B E8B1F6FFFF          <1> 	call	clear_page ; Clear page content
  3722                              <1> 	;
  3723 000061A0 0C07                <1> 	or	al, PDE_A_PRESENT + PDE_A_WRITE + PDE_A_USER
  3724                              <1> 		 ; set bit 0, bit 1 and bit 2 to 1
  3725                              <1> 		 ; (present, writable, user)
  3726 000061A2 8946FC              <1> 	mov	[esi-4], eax
  3727                              <1> a_u_pd_2:
  3728 000061A5 662500F0            <1> 	and	ax, PDE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
  3729                              <1> 	; EAX = PHYSICAL (flat) ADDRESS OF THE PAGE TABLE
  3730 000061A9 8B3C24              <1> 	mov	edi, [esp] ; *
  3731                              <1> 	; EDI = PTE index (of page directory)
  3732                              <1> 	;and	edi, PTE_MASK ; PTE entry index in the page table	
  3733                              <1> 	; EBX = next PDE address
  3734 000061AC 89FE                <1> 	mov	esi, edi ; PTE index in page table (0-1023)
  3735 000061AE C1E702              <1> 	shl	edi, 2 ; convert PTE index to dword offset
  3736 000061B1 01C7                <1> 	add	edi, eax ; now, edi points to requested PTE
  3737                              <1> a_u_pt_0:
  3738                              <1> 	; 02/05/2017
  3739 000061B3 8B07                <1> 	mov	eax, [edi]
  3740                              <1> 	;
  3741 000061B5 A801                <1> 	test	al, PTE_A_PRESENT ; bit 0, present flag (must be 1)
  3742 000061B7 7445                <1> 	jz	short a_u_pt_1
  3743                              <1> 	;
  3744 000061B9 A802                <1> 	test	al, PTE_A_WRITE   ; bit 1, writable (r/w) flag
  3745                              <1> 				  ; (must be 1)
  3746 000061BB 7550                <1> 	jnz	short a_u_pt_3
  3747                              <1> 	; Read only -duplicated- page (belongs to a parent or a child)
  3748 000061BD 66A90002            <1>         test    ax, PTE_DUPLICATED ; Was this page duplicated 
  3749                              <1> 				   ; as child's page ?
  3750 000061C1 7455                <1> 	jz	short a_u_pt_4	; Clear PTE but don't deallocate the page!
  3751                              <1> 	;
  3752                              <1> 	; check the parent's PTE value is read only & same page or not.. 
  3753                              <1> 	; EDX = page directory entry index (0-1023)
  3754 000061C3 52                  <1> 	push	edx ; **
  3755 000061C4 53                  <1> 	push	ebx ; ***
  3756                              <1> 	; ESI = page table entry index (0-1023)
  3757                              <1> 	;push	esi ; **** ; 20/05/2017
  3758 000061C5 8B1D[D0940100]      <1> 	mov	ebx, [u.ppgdir] ; page directory of the parent process
  3759 000061CB 66C1E202            <1> 	shl	dx, 2 ; *4 
  3760 000061CF 01D3                <1> 	add	ebx, edx ; PTE address,0 (for the parent)
  3761 000061D1 8B13                <1> 	mov	edx, [ebx] ; page table address
  3762 000061D3 F6C201              <1> 	test	dl, PDE_A_PRESENT ; present (valid) or not ?
  3763 000061D6 7433                <1> 	jz	short a_u_pt_2	; parent process does not use this page
  3764 000061D8 6681E200F0          <1> 	and	dx, PDE_A_CLEAR ; 0F000h ; Clear attribute bits
  3765 000061DD 66C1E602            <1> 	shl	si, 2 ; *4
  3766                              <1> 	; ESI = page table entry offset (0-4092)
  3767 000061E1 01D6                <1> 	add	esi, edx	; PTE address (for the parent)
  3768 000061E3 8B1E                <1> 	mov	ebx, [esi]
  3769 000061E5 F6C301              <1> 	test	bl, PTE_A_PRESENT ; present or not ?
  3770 000061E8 7421                <1> 	jz	short a_u_pt_2	; parent process does not use this page
  3771 000061EA 662500F0            <1> 	and	ax, PTE_A_CLEAR ; 0F000h ; Clear attribute bits 
  3772 000061EE 6681E300F0          <1> 	and	bx, PTE_A_CLEAR ; 0F000h ; Clear attribute bits
  3773 000061F3 39D8                <1> 	cmp	eax, ebx	; parent's and child's pages are same ?
  3774 000061F5 7514                <1> 	jne	short a_u_pt_2	; not same page
  3775                              <1> 				; deallocate the child's page
  3776 000061F7 800E02              <1>         or      byte [esi], PTE_A_WRITE ; convert to writable page (parent)
  3777                              <1> 	;pop	esi ; **** ; 20/05/2017
  3778 000061FA 5B                  <1> 	pop	ebx ; ***
  3779 000061FB 5A                  <1> 	pop	edx ; **
  3780 000061FC EB1A                <1> 	jmp	short a_u_pt_4
  3781                              <1> a_u_pt_1:
  3782 000061FE 09C0                <1> 	or	eax, eax	; swapped page ?
  3783 00006200 7416                <1> 	jz	short a_u_pt_4	; no
  3784                              <1> 				; yes
  3785 00006202 D1E8                <1> 	shr	eax, 1
  3786 00006204 E8B5F9FFFF          <1> 	call	unlink_swap_block ; Deallocate swapped page block
  3787                              <1> 				  ; on the swap disk (or in file)
  3788 00006209 EB0D                <1> 	jmp	short a_u_pt_4
  3789                              <1> a_u_pt_2:
  3790                              <1> 	;pop	esi ; **** ; 20/05/2017
  3791 0000620B 5B                  <1> 	pop	ebx ; ***
  3792 0000620C 5A                  <1> 	pop	edx ; **
  3793                              <1> a_u_pt_3:
  3794 0000620D 66A90004            <1> 	test	ax, PTE_SHARED	; shared or direct memory access indicator
  3795 00006211 7505                <1> 	jnz	short a_u_pt_4	; AVL bit 1 = 1, do not deallocate this page!
  3796                              <1> 	;
  3797                              <1> 	;and	ax, PTE_A_CLEAR ; 0F000h ; clear lower 12 (attribute) bits
  3798 00006213 E887F7FFFF          <1> 	call	deallocate_page ; set the mem allocation bit of this page
  3799                              <1> 	;
  3800                              <1> a_u_pt_4:
  3801 00006218 89E8                <1> 	mov	eax, ebp ; physical address
  3802 0000621A 0C07                <1> 	or	al, PTE_A_PRESENT + PTE_A_WRITE + PTE_A_USER ; 04/03/2017
  3803 0000621C AB                  <1> 	stosd
  3804 0000621D 5E                  <1> 	pop	esi ; * ; 20/05/2017
  3805 0000621E 49                  <1> 	dec	ecx ; remain page count
  3806 0000621F 7417                <1> 	jz	short a_u_pd_5
  3807 00006221 81C500100000        <1> 	add	ebp, PAGE_SIZE
  3808 00006227 46                  <1> 	inc	esi ; next PTE (index)
  3809                              <1> 	; 20/05/2017
  3810                              <1> 	;cmp	esi, PAGE_SIZE/4 ; 1024
  3811                              <1> 	;jb	short a_u_pt_0
  3812 00006228 6681E6FF03          <1> 	and	si, PTE_MASK ; 3FFh (0 to 1023)
  3813 0000622D 56                  <1> 	push	esi ; *
  3814 0000622E 7583                <1> 	jnz	short a_u_pt_0 ; > 0 (<1024)
  3815                              <1> a_u_pd_3:
  3816 00006230 42                  <1> 	inc	edx
  3817                              <1> ;	cmp	edx, 1024
  3818                              <1> ;	jnb	short a_u_pd_4 ; 02/05/2017 (error!, ecx > 0)
  3819 00006231 89DE                <1> 	mov	esi, ebx ; the next PDE address
  3820 00006233 E953FFFFFF          <1> 	jmp	a_u_pd_0
  3821                              <1> a_u_pd_4:
  3822                              <1> 	; 02/05/2017
  3823                              <1> ;	stc
  3824                              <1> a_u_pd_5:
  3825                              <1> 	; 20/05/2017
  3826                              <1> 	;pop	edi ; *
  3827 00006238 C3                  <1> 	retn
  3828                              <1> 
  3829                              <1> 	; 28/11/2023
  3830                              <1> ;a_lfb_k__err:
  3831                              <1> 	;retn
  3832                              <1> 
  3833                              <1> allocate_lfb_pages_for_kernel:
  3834                              <1> 	; 02/12/2023
  3835                              <1> 	; 29/11/2023
  3836                              <1> 	; 28/11/2023
  3837                              <1> 	; 20/10/2023 - TRDOS 386 v2.0.7
  3838                              <1> 	; (only the overlapped main memory pages will be allocated)
  3839                              <1> 	; 28/11/2023
  3840                              <1> 	; (but all LFB pages will be added to the kernel's page tables)
  3841                              <1> 	; (NOTE: LFB size -which will be used- is the size of the max.
  3842                              <1> 	;  recognized screen resolution. For example: 1024*768*4 bytes)
  3843                              <1> 	; 15/12/2020
  3844                              <1> 	; 14/12/2020 - TRDOS 386 v2.0.3
  3845                              <1> 	; Set kernel page tables for linear frame buffer 
  3846                              <1> 	;
  3847                              <1> 	; Input:
  3848                              <1> 	;	;[LFB_ADDR] = linear frame buffer base address
  3849                              <1> 	;	;[LFB_SIZE] = linear frame buffer size in bytes
  3850                              <1> 	;	; 29/11/2023
  3851                              <1> 	;	;ebx = Linear frame buffer base address as page num
  3852                              <1> 	;	; 20/10/2023
  3853                              <1> 	;	esi = linear frame buffer base address
  3854                              <1> 	;	ecx = memory size in pages = [memory_size]
  3855                              <1> 	;	; 28/11/2023
  3856                              <1> 	;	edx = linear frame buffer size in pages
  3857                              <1> 	; Output:
  3858                              <1> 	;	none
  3859                              <1> 	;	cf = 1 -> error
  3860                              <1> 	;
  3861                              <1> 	; Modified registers: eax, ebx, ecx, edx, esi, edi, ebp
  3862                              <1> 
  3863                              <1> 
  3864                              <1> ; 02/12/2023 ; (!**!)
  3865                              <1> ; ('memory size' -for M.A.T.- is always <= LFB stat/base address) 
  3866                              <1> %if 0
  3867                              <1> 
  3868                              <1> 	; 29/11/2023
  3869                              <1> 	; allocate LFB blocks which < memory size at first
  3870                              <1> 	
  3871                              <1> 	;mov	eax, edx
  3872                              <1> 	;shl	eax, 12
  3873                              <1> 	;add	eax, esi
  3874                              <1> 	;jc	short a_lfb_k__err ; > 4GB limit
  3875                              <1> 	;
  3876                              <1> 	;;mov	eax, 1048576 ; page count of (full) 4GB memory
  3877                              <1> 	;;sub	eax, edx
  3878                              <1> 	;;cmp	eax, esi
  3879                              <1> 	;jb	short a_lfb_k__err ; > 4GB limit
  3880                              <1> 
  3881                              <1> 	mov	ebx, esi ; LFB base/start address
  3882                              <1> 	shr	ebx, 12	 ; convert byte address to page address
  3883                              <1> 	; ebx = LFB start/base page number 
  3884                              <1> 
  3885                              <1> 	sub	ecx, ebx
  3886                              <1> 	jna	short a_lfb_k_2 ; skip M.A.T. bit allocation 
  3887                              <1> 	cmp	ecx, edx
  3888                              <1> 	jna	short a_lfb_k_0
  3889                              <1> 	mov	ecx, edx
  3890                              <1> a_lfb_k_0:
  3891                              <1> 	sub	edx, ecx
  3892                              <1> 	jna	short a_lfb_k_1
  3893                              <1> 
  3894                              <1> 	; edx = remain count of LFB pages which are out of the M.A.T. 
  3895                              <1> 	; ebx = LFB start/base page number
  3896                              <1> 	; ecx = page allocation count in the M.A.T.
  3897                              <1> 
  3898                              <1> 	;mov	eax, 4096
  3899                              <1> 	;mul	ecx
  3900                              <1> 	mov	eax, ecx
  3901                              <1> 	shl	eax, 12 ; * 4096
  3902                              <1> 
  3903                              <1> 	add	esi, eax
  3904                              <1> 	; esi = LFB address just after the main memory if there is	
  3905                              <1> a_lfb_k_1:
  3906                              <1> 	mov	eax, ebx ; LFB start/base page number
  3907                              <1> 	call	allocate_lfb_memory_block
  3908                              <1> 
  3909                              <1> 	; here if there is, remain (the 2nd) part of the LFB 
  3910                              <1> 	; will be allocated by using new kernel page table(s)
  3911                              <1> 	; (but M.A.T. bits will not be cleared because 
  3912                              <1> 	;  the 2nd LFB part is out of the M.A.T.)	
  3913                              <1> 	
  3914                              <1> 	and	edx, edx
  3915                              <1> 	jz	short a_lfb_k_6  ; all LFB pages have been allocated
  3916                              <1> 
  3917                              <1> %endif
  3918                              <1> 
  3919                              <1> a_lfb_k_2:
  3920                              <1> 	; 29/11/2023
  3921 00006239 C1EE0C              <1> 	shr	esi, 12	; convert LFB address to page number
  3922                              <1> 	; edx = count of pages to be added (in kernel page tables)
  3923                              <1> 	; 28/11/2023
  3924 0000623C 89D5                <1> 	mov	ebp, edx
  3925 0000623E 81C2FF030000        <1> 	add	edx, 1023 ; round up
  3926 00006244 C1EA0A              <1> 	shr	edx, 10	  ; / 1024
  3927                              <1> 	; edx = count of kernel page tables to be added
  3928                              <1> 	; (edx = 1 or edx = 2)
  3929                              <1> 	; ((1024*768*4 = 3145728 bytes, 768 PTEs, 1 page table))
  3930                              <1> 	; ((1920*1080*4 = 8294400 bytes, 2025 PTEs, 2 page tables)) 
  3931 00006247 E894F5FFFF          <1> 	call	allocate_page
  3932                              <1> 	;jc	short a_lfb_k__err
  3933                              <1> 	; (mem alloc error is not expected at this startup stage)
  3934                              <1> 	; eax = physical address of the new page table
  3935 0000624C 89F7                <1> 	mov	edi, esi  ; LFB start/base page number
  3936 0000624E C1EF0A              <1> 	shr	edi, 10
  3937                              <1> 	; edi = PDE entry number of the Linear Frame Buffer addr
  3938                              <1> 	; (edi = 832 for 0D0000000h, edi = 896 for 0E0000000h)
  3939 00006251 C1E702              <1> 	shl	edi, 2
  3940                              <1> 	; edi = PDE offset
  3941 00006254 033D[C07C0100]      <1> 	add	edi, [k_page_dir] ; Kernel's Page Dir Address
  3942 0000625A 50                  <1> 	push	eax ; +
  3943 0000625B 660D0304            <1> 	or	ax, PDE_A_PRESENT + PDE_A_WRITE + PDE_EXTERNAL
  3944                              <1> 				; supervisor + read&write + present
  3945                              <1> 				; + external memory block (LFB)
  3946 0000625F AB                  <1> 	stosd
  3947                              <1> 
  3948 00006260 4A                  <1> 	dec	edx
  3949 00006261 740C                <1> 	jz	short a_lfb_k_3	; only 1 new page table
  3950                              <1> 
  3951                              <1> 	; the 2nd page table
  3952 00006263 E878F5FFFF          <1> 	call	allocate_page
  3953                              <1> 	;jc	short a_lfb_k__err
  3954                              <1> 	; (mem alloc error is not expected at this startup stage)
  3955                              <1> 	; eax = physical address of the new page table
  3956 00006268 89C3                <1> 	mov	ebx, eax
  3957 0000626A 660D0304            <1> 	or	ax, PDE_A_PRESENT + PDE_A_WRITE + PDE_EXTERNAL
  3958                              <1> 				; supervisor + read&write + present
  3959                              <1> 				; + external memory block (LFB)
  3960 0000626E AB                  <1> 	stosd
  3961                              <1> 
  3962                              <1> a_lfb_k_3:
  3963                              <1> 	; set new PTEs
  3964                              <1> 	;
  3965                              <1> 	; ebp = count of pages (PTEs) to be allocated
  3966 0000626F 5F                  <1> 	pop	edi ; +	 ; 1st page table address	
  3967                              <1> 	; 29/11/2023
  3968 00006270 B900040000          <1> 	mov	ecx, 1024	; number of PTEs in a page table
  3969 00006275 89F0                <1> 	mov	eax, esi	; LFB base/start page number
  3970                              <1> 			 	; (may be the 2nd part of the LFB)
  3971 00006277 C1E00C              <1> 	shl	eax, 12
  3972 0000627A 660D0304            <1> 	or	ax, PTE_A_PRESENT + PTE_A_WRITE + PTE_EXTERNAL
  3973                              <1> 				; supervisor + read&write + present
  3974                              <1> 				; + external memory block (LFB)
  3975                              <1> a_lfb_k_4:
  3976 0000627E AB                  <1> 	stosd			; save as PTE
  3977 0000627F 4D                  <1> 	dec	ebp
  3978 00006280 740D                <1> 	jz	short a_lfb_k_5
  3979 00006282 0500100000          <1> 	add	eax, 4096	; the next page address
  3980 00006287 E2F5                <1> 	loop	a_lfb_k_4
  3981                              <1> 	
  3982                              <1> 	;and	ebx, ebx
  3983                              <1> 	;jz	short a_lfb_k_6
  3984 00006289 89DF                <1> 	mov	edi, ebx	; the 2nd page table address
  3985                              <1> 	;xor	ebx, ebx
  3986                              <1> 	;mov	ecx, 1024
  3987 0000628B B504                <1> 	mov	ch, 4 ; cx = 4*256 = 1024
  3988 0000628D EBEF                <1> 	jmp	short a_lfb_k_4 ; only 1 more loop (no the 3rd pt)
  3989                              <1> 				; (ebp <= 1024 here)
  3990                              <1> a_lfb_k_5:
  3991 0000628F 49                  <1> 	dec	ecx
  3992 00006290 7404                <1> 	jz	short a_lfb_k_6
  3993 00006292 31C0                <1> 	xor	eax, eax	; clear page table entry (empty)
  3994 00006294 F3AB                <1> 	rep	stosd
  3995                              <1> a_lfb_k_6:
  3996                              <1> 	; 29/11/2023
  3997 00006296 C3                  <1> 	retn
  3998                              <1> 
  3999                              <1> ; 28/11/2023
  4000                              <1> %if 0 
  4001                              <1> 
  4002                              <1> allocate_lfb_pages_for_kernel:
  4003                              <1> 	; 20/10/2023 - TRDOS 386 v2.0.7
  4004                              <1> 	; (only the overlapped main memory pages will be allocated)
  4005                              <1> 	; ((if LFB base/start address is greater than -or equal to-
  4006                              <1> 	;      main memory size, this procedure is not called/used)) 
  4007                              <1> 	; 15/12/2020
  4008                              <1> 	; 14/12/2020 - TRDOS 386 v2.0.3
  4009                              <1> 	; Set kernel page tables for linear frame buffer 
  4010                              <1> 	;
  4011                              <1> 	; Input:
  4012                              <1> 	;	;[LFB_ADDR] = linear frame buffer base address
  4013                              <1> 	;	;[LFB_SIZE] = linear frame buffer size in bytes
  4014                              <1> 	;	; 20/10/2023
  4015                              <1> 	;	eax = Linear frame buffer base address as page num
  4016                              <1> 	;	      (eax < memory size)
  4017                              <1> 	;	esi = linear frame buffer base address
  4018                              <1> 	;	ecx = memory size in pages = [memory_size]
  4019                              <1> 	; Output:
  4020                              <1> 	;	none
  4021                              <1> 	;	cf = 1 -> error
  4022                              <1> 	;
  4023                              <1> 	; Modified registers: eax, ecx, edx, edi
  4024                              <1> 
  4025                              <1> 	; 20/10/2023
  4026                              <1> 	;mov	edi, [LFB_ADDR]
  4027                              <1> 	;mov	edx, [LFB_SIZE]
  4028                              <1> 
  4029                              <1> 	;;;
  4030                              <1> 	; 20/10/2023
  4031                              <1> 	mov	edi, eax ; LFB base/start page number
  4032                              <1> 	;mov	ecx, [memory_size]
  4033                              <1> 	sub	ecx, eax	
  4034                              <1> 
  4035                              <1> 	; ecx = number of pages to be set as (already) allocated 
  4036                              <1> 	;;;
  4037                              <1> 
  4038                              <1> 	; 20/10/2023
  4039                              <1> 	shr	edi, 10 ; convert page number to PDE entry number
  4040                              <1> 			; (1024 pages per page table -the shift
  4041                              <1> 			; result is a page table index number
  4042                              <1> 			; or page directory entry number <= 1023)
  4043                              <1> 	;shr	edi, 22	; convert address to page number
  4044                              <1> 			; and then convert it to PDE entry offset
  4045                              <1> 			; (1 PDE is for 4MB, 22 bit shift)
  4046                              <1> 
  4047                              <1> 	shl	di, 2	; * 4 to obtain the PDE offset
  4048                              <1> 
  4049                              <1> 	; 20/10/2023
  4050                              <1> 	;;add	edx, 4095
  4051                              <1> 	;shr	edx, 12	; convert LFB size to LFB page count
  4052                              <1> 	
  4053                              <1> 	;mov	ecx, edx ; * ; LFB page count
  4054                              <1> 	; 20/10/2023
  4055                              <1> 	mov	edx, ecx ; *
  4056                              <1> 			; 20/10/2023
  4057                              <1> 			; edx = page count (to be set as allocated)
  4058                              <1> 			; 	from the LFB start page
  4059                              <1> 			; (it may be <= linear frame buffer size) 
  4060                              <1> 
  4061                              <1> 	add	ecx, 1023 ; page count + 1023
  4062                              <1> 	shr	ecx, 10 ; convert to page directory entry count	
  4063                              <1> 			; (page table count)
  4064                              <1> 	push	ecx ; **
  4065                              <1> 	shl	ecx, 12 ; convert to byte count
  4066                              <1> 
  4067                              <1> 	; 20/10/2023
  4068                              <1> 	; (absolute allocation is needed instead of the first fit)
  4069                              <1> 	;xor	eax, eax ; first available pages
  4070                              <1> 	
  4071                              <1> 	; 20/10/2023
  4072                              <1> 	;mov	esi, [LFB_ADDR]
  4073                              <1> 	mov	eax, esi ; linear frame buffer's base/start address	
  4074                              <1> 
  4075                              <1> 	; allocate contiguous memory block for these kernel pages
  4076                              <1> 	
  4077                              <1> 	;call	allocate_memory_block
  4078                              <1> 	; 20/10/2023 
  4079                              <1> 	; (short way to set LFB page bits on the 'M.A.T.)
  4080                              <1> 	call	allocate_lfb_memory_block ; in 'allocate_memory_block'	
  4081                              <1> 
  4082                              <1> 	; eax = start address of (contiguous) memory block
  4083                              <1> 	pop	ecx ; ** ; PDE count
  4084                              <1> 	jnc	short a_lfb_k_1
  4085                              <1> 	; error (cf=1)
  4086                              <1> 	retn
  4087                              <1> a_lfb_k_1:
  4088                              <1> 	; Allocate (new) page tables in kernel's page directory
  4089                              <1> 	push	ecx ; PDE (page table) count
  4090                              <1> 	push	eax ; start address of contiguous memory pages
  4091                              <1> 		    ; (at page boundary)	
  4092                              <1> 	; edi = 1st page directory entry offset
  4093                              <1> 	add	edi, [k_page_dir] ; Kernel's Page Dir Address
  4094                              <1> a_lfb_k_2:
  4095                              <1> 	or	ax, PDE_A_PRESENT + PDE_A_WRITE + PDE_EXTERNAL
  4096                              <1> 				; supervisor + read&write + present 	
  4097                              <1> 				; + external memory block (LFB)
  4098                              <1> 	stosd
  4099                              <1> 	add	eax, 4096
  4100                              <1> 	loop	a_lfb_k_2
  4101                              <1> 	
  4102                              <1> 	pop	edi ; start addr of contiguous memory pages
  4103                              <1> 	pop	ecx ; page table (PDE) count
  4104                              <1> 
  4105                              <1> 	; Allocate pages in (new) kernel page tables
  4106                              <1> 	
  4107                              <1> 	; (Note: page tables are contiguous in pyhsical memory)
  4108                              <1> 	shl	ecx, 10 ; * 1024, convert to (total) PTE count 
  4109                              <1> 	
  4110                              <1> 	mov	eax, [LFB_ADDR]
  4111                              <1> 	; edx = LFB page count
  4112                              <1> 	;and	ax, ~4095  ; lw of LFB address is 0
  4113                              <1> a_lfb_k_3:	
  4114                              <1> 	or	ax, PTE_A_PRESENT + PTE_A_WRITE + PTE_EXTERNAL
  4115                              <1> 				; supervisor + read&write + present 	
  4116                              <1> 				; + external memory block (LFB)
  4117                              <1> 	stosd
  4118                              <1> 	dec	edx
  4119                              <1> 	jz	short a_lfb_k_4 ; LFB size has been completed (!?)
  4120                              <1> 	add	eax, 4096	
  4121                              <1> 	loop	a_lfb_k_3
  4122                              <1> 
  4123                              <1> 	retn
  4124                              <1> 	
  4125                              <1> a_lfb_k_4:
  4126                              <1> 	; clear PTEs for empty/free pages 
  4127                              <1> 	; 	(if there are after LFB !?)
  4128                              <1> 	xor	eax, eax ; clear page table entry (empty)
  4129                              <1> 	rep	stosd
  4130                              <1> 	retn
  4131                              <1> 
  4132                              <1> %endif
  4133                              <1> 
  4134                              <1> ;deallocate_lfb_pages_for_kernel:
  4135                              <1> 	; 15/12/2020
  4136                              <1> 	; 14/12/2020 - TRDOS 386 v2.0.3
  4137                              <1> 	; Reset/Release kernel page tables
  4138                              <1> 	;	 which are used for linear frame buffer 
  4139                              <1> 	; (this procedure will be called by kernel only)
  4140                              <1> 	;
  4141                              <1> 	; Input:
  4142                              <1> 	;	[LFB_ADDR] = linear frame buffer base address
  4143                              <1>  	;	[FFB_SIZE] = linear frame buffer size in bytes
  4144                              <1> 	; Output:
  4145                              <1> 	;	none
  4146                              <1> 	;
  4147                              <1> 	; Modified registers: eax, ecx, edi
  4148                              <1> 
  4149                              <1> 	;mov	edi, [LFB_ADDR]
  4150                              <1> 	;mov	ecx, [LFB_SIZE]
  4151                              <1> 	;
  4152                              <1> 	;shr	edi, 22	; convert address to page number
  4153                              <1> 	;		; and then convert it to PDE entry offset
  4154                              <1> 	;		; (1 PDE is for 4MB, 22 bit shift)
  4155                              <1> 	;
  4156                              <1> 	;shl	di, 2	; * 4 for offset 
  4157                              <1> 	;
  4158                              <1> 	;;add	ecx, 4095
  4159                              <1> 	;shr	ecx, 12	; convert LFB size to page count  
  4160                              <1> 	;
  4161                              <1> 	;add	ecx, 1023 ; page count + 1023
  4162                              <1> 	;shr	ecx, 10 ; convert to page directory entry count	
  4163                              <1> 	;		; (page table count)
  4164                              <1> 	;push	ecx ; *
  4165                              <1> 	;shl	ecx, 12 ; convert to byte count
  4166                              <1> 	;
  4167                              <1> 	;xor	eax, eax ; first available pages
  4168                              <1> 	;
  4169                              <1> 	;; deallocate contiguous memory block for kernel pages
  4170                              <1> 	;
  4171                              <1> 	;call	deallocate_memory_block
  4172                              <1> 	;
  4173                              <1> 	;pop	ecx ; * ; PDE count
  4174                              <1> 	;
  4175                              <1> 	;; Release/Free PDEs (page tables) in kernel's page dir
  4176                              <1> 	;; edi = 1st page directory entry offset
  4177                              <1> 	;add	edi, [k_page_dir] ; Kernel's Page Dir Address
  4178                              <1> 	;sub	eax, eax ; clear (also invalidate)
  4179                              <1> 	;rep	stosd
  4180                              <1> 	;
  4181                              <1> 	;retn
  4182                              <1> 
  4183                              <1> ; /// End Of MEMORY MANAGEMENT FUNCTIONS ///
  4184                              <1> 
  4185                              <1> ;; Data:
  4186                              <1> 
  4187                              <1> ; 09/03/2015
  4188                              <1> ;swpq_count: dw 0 ; count of pages on the swap que
  4189                              <1> ;swp_drv:    dd 0 ; logical drive description table address of the swap drive/disk
  4190                              <1> ;swpd_size:  dd 0 ; size of swap drive/disk (volume) in sectors (512 bytes). 		  				
  4191                              <1> ;swpd_free:  dd 0 ; free page blocks (4096 bytes) on swap disk/drive (logical)
  4192                              <1> ;swpd_next:  dd 0 ; next free page block
  4193                              <1> ;swpd_last:  dd 0 ; last swap page block
  3227                                  %include 'timer.s'   ; 17/01/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.5 - timer.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 08/08/2022  (Previous: 18/04/2021)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 17/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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> ;
    25                              <1> ; ///////// TIMER (& REAL TIME CLOCK) FUNCTIONS ///////////////
    26                              <1> 
    27                              <1> int1Ah:
    28                              <1> 	; 29/01/2016
    29                              <1> 	; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
    30 00006297 9C                  <1> 	pushfd
    31 00006298 0E                  <1> 	push 	cs
    32 00006299 E801000000          <1> 	call 	TIME_OF_DAY_1
    33 0000629E C3                  <1> 	retn
    34                              <1> 
    35                              <1> ;-------------------------------------------------------------------------------
    36                              <1> 
    37                              <1> ;--- INT 1A H -- (TIME OF DAY) --------------------------------------------------
    38                              <1> ;       THIS BIOS ROUTINE ALLOWS THE CLOCKS TO BE SET OR READ			:
    39                              <1> ;										:
    40                              <1> ; PARAMETERS:									:
    41                              <1> ;     (AH) = 00H  READ THE CURRENT SETTING AND RETURN WITH,			:
    42                              <1> ;                      (CX) = HIGH PORTION OF COUNT				:
    43                              <1> ;                      (DX) = LOW PORTION OF COUNT				:
    44                              <1> ;                      (AL) = 0 TIMER HAS NOT PASSED 24 HOURS SINCE LAST READ	:
    45                              <1> ;                             1 IF ON ANOTHER DAY. (RESET TO ZERO AFTER READ)	:
    46                              <1> ;										:
    47                              <1> ;     (AH) = 01H  SET THE CURRENT CLOCK USING,					:
    48                              <1> ;		     (CX) = HIGH PORTION OF COUNT				:
    49                              <1> ;		     (DX) = LOW PORTION OF COUNT.				:
    50                              <1> ;										:
    51                              <1> ;             NOTE: COUNTS OCCUR AT THE RATE OF 1193180/65536 COUNTS/SECOND	:
    52                              <1> ;                   (OR ABOUT 18.2 PER SECOND -- SEE EQUATES)			:
    53                              <1> ;										:
    54                              <1> ;     (AH) = 02H  READ THE REAL TIME CLOCK AND RETURN WITH,			:
    55                              <1> ;                      (CH) = HOURS IN BCD (00-23)				:
    56                              <1> ;                      (CL) = MINUTES IN BCD (00-59)				:
    57                              <1> ;                      (DH) = SECONDS IN BCD (00-59)				:
    58                              <1> ;                      (DL) = DAYLIGHT SAVINGS ENABLE (00-01)			:
    59                              <1> ;										:
    60                              <1> ;     (AH) = 03H  SET THE REAL TIME CLOCK USING,				:
    61                              <1> ;                     (CH) = HOURS IN BCD (00-23)				:
    62                              <1> ;                     (CL) = MINUTES IN BCD (00-59)				:
    63                              <1> ;                     (DH) = SECONDS IN BCD (00-59)				:
    64                              <1> ;                     (DL) = 01 IF DAYLIGHT SAVINGS ENABLE OPTION, ELSE 00.	:
    65                              <1> ;										:
    66                              <1> ;             NOTE: (DL) = 00 IF DAYLIGHT SAVINGS TIME ENABLE IS NOT ENABLED.	:
    67                              <1> ;                   (DL) = 01 ENABLES TWO SPECIAL UPDATES THE LAST SUNDAY IN	:
    68                              <1> ;	            APRIL   (1:59:59 --> 3:00:00 AM) AND THE LAST SUNDAY IN	:
    69                              <1> ;                   OCTOBER (1:59:59 --> 1:00:00 AM) THE FIRST TIME.		:
    70                              <1> ;										:
    71                              <1> ;     (AH) = 04H  READ THE DATE FROM THE REAL TIME CLOCK AND RETURN WITH,	:
    72                              <1> ;                      (CH) = CENTURY IN BCD (19 OR 20)				:
    73                              <1> ;                      (CL) = YEAR IN BCD (00-99)				:
    74                              <1> ;                      (DH) = MONTH IN BCD (01-12)				:
    75                              <1> ;                      (DL) = DAY IN BCD (01-31).				:
    76                              <1> ;										:
    77                              <1> ;     (AH) = 05H  SET THE DATE INTO THE REAL TIME CLOCK USING,			:
    78                              <1> ;                     (CH) = CENTURY IN BCD (19 OR 20)				:
    79                              <1> ;                     (CL) = YEAR IN BCD (00-99)				:
    80                              <1> ;                     (DH) = MONTH IN BCD (01-12)				:
    81                              <1> ;                     (DL) = DAY IN BCD (01-31).				:
    82                              <1> ;										:
    83                              <1> ;     (AH) = 06H  SET THE ALARM TO INTERRUPT AT SPECIFIED TIME,			:
    84                              <1> ;                     (CH) = HOURS IN BCD (00-23 (OR FFH))			:
    85                              <1> ;                     (CL) = MINUTES IN BCD (00-59 (OR FFH))			:
    86                              <1> ;                     (DH) = SECONDS IN BCD (00-59 (OR FFH))			:
    87                              <1> ;										:
    88                              <1> ;     (AH) = 07H  RESET THE ALARM INTERRUPT FUNCTION.				:
    89                              <1> ;										:
    90                              <1> ; NOTES: FOR ALL RETURNS CY= 0 FOR SUCCESSFUL OPERATION.			:
    91                              <1> ;        FOR (AH)= 2, 4, 6 - CARRY FLAG SET IF REAL TIME CLOCK NOT OPERATING.	:
    92                              <1> ;        FOR (AH)= 6 - CARRY FLAG SET IF ALARM ALREADY ENABLED. 		:
    93                              <1> ;        FOR THE ALARM FUNCTION (AH = 6) THE USER MUST SUPPLY A ROUTINE AND	:
    94                              <1> ;         INTERCEPT THE CORRECT ADDRESS IN THE VECTOR TABLE FOR INTERRUPT 4AH.	:
    95                              <1> ;         USE 0FFH FOR ANY "DO NOT CARE" POSITION FOR INTERVAL INTERRUPTS.	:
    96                              <1> ;        INTERRUPTS ARE DISABLED DURING DATA MODIFICATION. 			:
    97                              <1> ;        AH & AL ARE RETURNED MODIFIED AND NOT DEFINED EXCEPT WHERE INDICATED.	:
    98                              <1> ;--------------------------------------------------------------------------------
    99                              <1> 
   100                              <1> ; 29/07/2022
   101                              <1> ; 15/01/2017
   102                              <1> ; 14/01/2017
   103                              <1> ; 07/01/2017
   104                              <1> ; 02/01/2017
   105                              <1> ; 29/05/2016
   106                              <1> ; 29/01/2016
   107                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
   108                              <1> 
   109                              <1> ; 29/05/2016
   110                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   111                              <1> int35h:  ; Date/Time functions
   112                              <1> 
   113                              <1> TIME_OF_DAY_1:
   114                              <1> 	; 07/08/5022
   115                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
   116                              <1> 	;sti				; INTERRUPTS BACK ON
   117                              <1> 	; 29/05/2016
   118 0000629F 80642408FE          <1> 	and	byte [esp+8], 11111110b	; clear carry bit of eflags register
   119                              <1> 	;
   120 000062A4 80FC08              <1> 	cmp	ah, (RTC_TBE-RTC_TB)/4	; CHECK IF COMMAND IN VALID RANGE (0-7)
   121 000062A7 F5                  <1> 	cmc				; COMPLEMENT CARRY FOR ERROR EXIT
   122                              <1> 	; (*) jc short TIME_9		; EXIT WITH CARRY = 1 IF NOT VALID
   123 000062A8 721A                <1> 	jc	short _TIME_9 ; 29/05/2016
   124                              <1> 
   125 000062AA 1E                  <1> 	push	ds
   126 000062AB 56                  <1> 	push	esi
   127 000062AC 66BE1000            <1> 	mov	si, KDATA		; kernel data segment
   128 000062B0 8EDE                <1> 	mov	ds, si
   129                              <1> 
   130                              <1> 	;;15/01/2017
   131                              <1> 	; 14/01/2017
   132                              <1> 	; 02/01/2017
   133                              <1> 	;;mov	byte [intflg], 35h	; date & time interrupt 
   134                              <1> 	;sti
   135                              <1> 	;
   136 000062B2 C0E402              <1> 	shl	ah, 2			; convert function to dword offset
   137 000062B5 0FB6F4              <1> 	movzx	esi, ah			; PLACE INTO ADDRESSING REGISTER
   138                              <1> 	;cli				; NO INTERRUPTS DURING TIME FUNCTIONS
   139 000062B8 FF96[CA620000]      <1> 	call	[esi+RTC_TB]		; VECTOR TO FUNCTION REQUESTED WITH CY=0
   140                              <1> 					; RETURN WITH CARRY FLAG SET FOR RESULT
   141                              <1> 	;sti				; INTERRUPTS BACK ON
   142 000062BE B400                <1> 	mov	ah, 0			; CLEAR (AH) TO ZERO
   143 000062C0 5E                  <1> 	pop	esi			; RECOVER USERS REGISTER
   144 000062C1 1F                  <1> 	pop	ds			; RECOVER USERS SEGMENT SELECTOR
   145                              <1> 
   146                              <1> 	;;15/01/2017
   147                              <1> 	; 02/01/2017
   148                              <1> 	;;mov	byte [ss:intflg], 0 ; 07/01/2017
   149                              <1> 
   150                              <1> ;TIME_9:
   151                              <1> 					; RETURN WITH CY= 0 IF NO ERROR
   152                              <1> 	; (*) 29/05/2016
   153                              <1> 	; (*) retf 4 ; skip eflags on stack
   154 000062C2 7305                <1> 	jnc	short _TIME_10
   155                              <1> _TIME_9:
   156                              <1> 	; 29/05/2016 -set carry flag on stack-
   157                              <1> 	; [esp] = EIP
   158                              <1> 	; [esp+4] = CS
   159                              <1> 	; [esp+8] = E-FLAGS
   160 000062C4 804C240801          <1> 	or	byte [esp+8], 1	 ; set carry bit of eflags register
   161                              <1> 	; [esp+12] = ESP (user)
   162                              <1> 	; [esp+16] = SS (User)
   163                              <1> _TIME_10:
   164 000062C9 CF                  <1> 	iretd
   165                              <1> 	
   166                              <1> 	; (*) 29/05/2016 - 'ref 4' intruction causes to stack fault
   167                              <1> 	; (OUTER-PRIVILEGE-LEVEL)
   168                              <1> 	; INTEL 80386 PROGRAMMER'S REFERENCE MANUAL 1986
   169                              <1> 	; // RETF instruction:
   170                              <1> 	;
   171                              <1> 	; IF OperandMode=32 THEN
   172                              <1>  	;    Load CS:EIP from stack;
   173                              <1>  	;    Set CS RPL to CPL;
   174                              <1>  	;    Increment eSP by 8 plus the immediate offset if it exists;
   175                              <1>  	;    Load SS:eSP from stack;
   176                              <1>  	; ELSE (* OperandMode=16 *)
   177                              <1>  	;    Load CS:IP from stack;
   178                              <1>  	;    Set CS RPL to CPL;
   179                              <1>  	;    Increment eSP by 4 plus the immediate offset if it exists;
   180                              <1> 	;    Load SS:eSP from stack;
   181                              <1>  	; FI;
   182                              <1> 	;
   183                              <1> 	; //					
   184                              <1> 					; ROUTINE VECTOR TABLE (AH)=
   185                              <1> RTC_TB:
   186 000062CA [EA620000]          <1> 	dd	RTC_00			; 0 = READ CURRENT CLOCK COUNT
   187 000062CE [FD620000]          <1> 	dd	RTC_10			; 1 = SET CLOCK COUNT
   188 000062D2 [0B630000]          <1> 	dd	RTC_20			; 2 = READ THE REAL TIME CLOCK TIME
   189 000062D6 [39630000]          <1> 	dd	RTC_30			; 3 = SET REAL TIME CLOCK TIME
   190 000062DA [76630000]          <1> 	dd	RTC_40			; 4 = READ THE REAL TIME CLOCK DATE
   191 000062DE [9C630000]          <1> 	dd	RTC_50			; 5 = SET REAL TIME CLOCK DATE
   192 000062E2 [FB630000]          <1> 	dd	RTC_60			; 6 = SET THE REAL TIME CLOCK ALARM
   193 000062E6 [4D640000]          <1> 	dd	RTC_70			; 7 = RESET ALARM
   194                              <1> 
   195                              <1> RTC_TBE	equ	$
   196                              <1> 
   197                              <1> RTC_00:				; READ TIME COUNT
   198 000062EA A0[447D0100]        <1> 	mov	al, [TIMER_OFL]		; GET THE OVERFLOW FLAG
   199 000062EF C605[447D0100]00    <1> 	mov	byte [TIMER_OFL], 0	; AND THEN RESET THE OVERFLOW FLAG
   200 000062F6 8B0D[407D0100]      <1>         mov     ecx, [TIMER_LH]         ; GET COUNT OF TIME
   201 000062FC C3                  <1> 	retn
   202                              <1> 
   203                              <1> RTC_10:				; SET TIME COUNT
   204 000062FD 890D[407D0100]      <1>         mov     [TIMER_LH], ecx         ; SET TIME COUNT
   205 00006303 C605[447D0100]00    <1> 	mov	byte [TIMER_OFL], 0	; RESET OVERFLOW FLAG
   206 0000630A C3                  <1> 	retn				; RETURN WITH NO CARRY
   207                              <1> 
   208                              <1> RTC_20:				; GET RTC TIME
   209 0000630B E8C7010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   210 00006310 7226                <1> 	jc	short RTC_29		; EXIT IF ERROR (CY= 1)
   211                              <1> 
   212 00006312 B000                <1> 	mov	al, CMOS_SECONDS	; SET ADDRESS OF SECONDS
   213 00006314 E8F4010000          <1> 	call	CMOS_READ		; GET SECONDS
   214 00006319 88C6                <1> 	mov	dh, al			; SAVE
   215 0000631B B00B                <1> 	mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   216 0000631D E8EB010000          <1> 	call	CMOS_READ		; READ CURRENT VALUE OF DSE BIT
   217 00006322 2401                <1> 	and	al, 00000001b		; MASK FOR VALID DSE BIT
   218 00006324 88C2                <1> 	mov	dl, al			; SET [DL] TO ZERO FOR NO DSE BIT
   219 00006326 B002                <1> 	mov	al, CMOS_MINUTES	; SET ADDRESS OF MINUTES
   220 00006328 E8E0010000          <1> 	call	CMOS_READ		; GET MINUTES
   221 0000632D 88C1                <1> 	mov	cl, al			; SAVE
   222 0000632F B004                <1>         mov     al, CMOS_HOURS          ; SET ADDRESS OF HOURS
   223                              <1> RTC_41:		; 29/07/2022
   224 00006331 E8D7010000          <1> 	call	CMOS_READ		; GET HOURS
   225 00006336 88C5                <1> 	mov	ch, al			; SAVE
   226                              <1> 	; 29/07/2022
   227                              <1> 	;clc				; SET CY= 0
   228                              <1> RTC_29:
   229 00006338 C3                  <1> 	retn				; RETURN WITH RESULT IN CARRY FLAG
   230                              <1> 
   231                              <1> RTC_30:				; SET RTC TIME
   232 00006339 E899010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   233 0000633E 7305                <1> 	jnc	short RTC_35		; GO AROUND IF CLOCK OPERATING
   234 00006340 E8AD010000          <1> 	call	RTC_STA			; ELSE TRY INITIALIZING CLOCK
   235                              <1> RTC_35:
   236 00006345 88F4                <1> 	mov	ah, dh			; GET TIME BYTE - SECONDS
   237 00006347 B000                <1> 	mov	al, CMOS_SECONDS	; ADDRESS SECONDS
   238 00006349 E894000000          <1> 	call	CMOS_WRITE		; UPDATE SECONDS
   239 0000634E 88CC                <1> 	mov	ah, cl			; GET TIME BYTE - MINUTES
   240 00006350 B002                <1> 	mov	al, CMOS_MINUTES	; ADDRESS MINUTES
   241 00006352 E88B000000          <1> 	call	CMOS_WRITE		; UPDATE MINUTES
   242 00006357 88EC                <1> 	mov	ah, ch			; GET TIME BYTE - HOURS
   243 00006359 B004                <1> 	mov	al, CMOS_HOURS		; ADDRESS HOURS
   244 0000635B E882000000          <1> 	call	CMOS_WRITE		; UPDATE ADDRESS
   245                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   246                              <1> 	;mov	ah, al
   247 00006360 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
   248 00006364 E8A4010000          <1> 	call	CMOS_READ		; READ CURRENT TIME
   249 00006369 2462                <1> 	and	al, 01100010b		; MASK FOR VALID BIT POSITIONS
   250 0000636B 0C02                <1> 	or	al, 00000010b		; TURN ON 24 HOUR MODE
   251 0000636D 80E201              <1> 	and	dl, 00000001b		; USE ONLY THE DSE BIT
   252 00006370 08D0                <1> 	or	al, dl			; GET DAY LIGHT SAVINGS TIME BIT (OSE)
   253 00006372 86C4                <1> 	xchg	ah, al			; PLACE IN WORK REGISTER AND GET ADDRESS
   254                              <1> 	;call	CMOS_WRITE		; SET NEW ALARM SITS
   255                              <1> 	;clc				; SET CY= 0
   256                              <1> 	;retn				; RETURN WITH CY= 0
   257                              <1> 	; 29/07/2022
   258 00006374 EB6C                <1> 	jmp	short CMOS_WRITE
   259                              <1> 
   260                              <1> RTC_40:				; GET RTC DATE
   261 00006376 E85C010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   262                              <1> 	;jc	short RTC_49		; EXIT IF ERROR (CY= 1)
   263                              <1> 	; 07/08/2022
   264 0000637B 72BB                <1> 	jc	short RTC_29
   265                              <1> 
   266 0000637D B007                <1> 	mov	al, CMOS_DAY_MONTH	; ADDRESS DAY OF MONTH
   267 0000637F E889010000          <1> 	call	CMOS_READ		; READ DAY OF MONTH
   268 00006384 88C2                <1> 	mov	dl, al			; SAVE
   269 00006386 B008                <1> 	mov	al, CMOS_MONTH		; ADDRESS MONTH
   270 00006388 E880010000          <1> 	call	CMOS_READ		; READ MONTH
   271 0000638D 88C6                <1> 	mov	dh, al			; SAVE
   272 0000638F B009                <1> 	mov	al, CMOS_YEAR		; ADDRESS YEAR
   273 00006391 E877010000          <1> 	call	CMOS_READ		; READ YEAR
   274 00006396 88C1                <1> 	mov	cl, al			; SAVE
   275 00006398 B032                <1> 	mov	al, CMOS_CENTURY	; ADDRESS CENTURY LOCATION
   276                              <1> ; 29/07/2022
   277                              <1> ;	call	CMOS_READ		; GET CENTURY BYTE
   278                              <1> ;	mov	ch, al			; SAVE
   279                              <1> ;	; 29/07/2022
   280                              <1> ;	;clc				; SET CY=0
   281                              <1> ;RTC_49:
   282                              <1> ;	retn				; RETURN WITH RESULTS IN CARRY FLAG
   283                              <1> 
   284                              <1> 	; 29/07/2022
   285 0000639A EB95                <1> 	jmp	short RTC_41
   286                              <1> 
   287                              <1> 
   288                              <1> RTC_50:				; SET RTC DATE
   289 0000639C E836010000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   290 000063A1 7305                <1> 	jnc	short RTC_55		; GO AROUND IF NO ERROR
   291 000063A3 E84A010000          <1> 	call	RTC_STA			; ELSE INITIALIZE CLOCK
   292                              <1> RTC_55:
   293 000063A8 66B80600            <1> 	mov	ax, CMOS_DAY_WEEK	; ADDRESS OF DAY OF WEEK BYTE
   294 000063AC E831000000          <1> 	call	CMOS_WRITE		; LOAD ZEROS TO DAY OF WEEK
   295 000063B1 88D4                <1> 	mov	ah, dl			; GET DAY OF MONTH BYTE
   296 000063B3 B007                <1> 	mov	al, CMOS_DAY_MONTH	; ADDRESS DAY OF MONTH BYTE
   297 000063B5 E828000000          <1> 	call	CMOS_WRITE		; WRITE OF DAY OF MONTH REGISTER
   298 000063BA 88F4                <1> 	mov	ah, dh			; GET MONTH
   299 000063BC B008                <1> 	mov	al, CMOS_MONTH		; ADDRESS MONTH BYTE
   300 000063BE E81F000000          <1> 	call	CMOS_WRITE		; WRITE MONTH REGISTER
   301 000063C3 88CC                <1> 	mov	ah, cl			; GET YEAR BYTE
   302 000063C5 B009                <1> 	mov	al, CMOS_YEAR		; ADDRESS YEAR REGISTER
   303 000063C7 E816000000          <1> 	call	CMOS_WRITE		; WRITE YEAR REGISTER
   304 000063CC 88EC                <1> 	mov	ah, ch			; GET CENTURY BYTE
   305 000063CE B032                <1> 	mov	al, CMOS_CENTURY	; ADDRESS CENTURY BYTE
   306 000063D0 E80D000000          <1> 	call	CMOS_WRITE		; WRITE CENTURY LOCATION
   307                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   308                              <1> 	;mov	ah, al
   309 000063D5 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
   310 000063D9 E82F010000          <1> 	call	CMOS_READ		; READ CURRENT SETTINGS
   311 000063DE 247F                <1> 	and	al, 07Fh		; CLEAR 'SET BIT'
   312 000063E0 86C4                <1> 	xchg	ah, al			; MOVE TO WORK REGISTER
   313                              <1> 	;call	CMOS_WRITE		; AND START CLOCK UPDATING
   314                              <1> 	;clc				; SET CY= 0
   315                              <1> 	;retn				; RETURN CY=0
   316                              <1> 	; 29/07/2022
   317                              <1> 	;jmp	short CMOS_WRITE
   318                              <1> 
   319                              <1> ;-------------------------------------------------------------------------------
   320                              <1> 
   321                              <1> ; 08/08/2022
   322                              <1> ; 29/07/2022 (TRDOS 386 v2.0.5)
   323                              <1> ; 18/04/2021 (TRDOS 386 v2.0.4)
   324                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
   325                              <1> 
   326                              <1> ;--- CMOS_WRITE ----------------------------------------------------------------
   327                              <1> ;	WRITE BYTE TO CMOS SYSTEM CLOCK CONFIGURATION TABLE		       :
   328                              <1> ;									       :
   329                              <1> ; INPUT: (AL)=	CMOS TABLE ADDRESS TO BE WRITTEN TO			       :
   330                              <1> ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
   331                              <1> ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO WRITE		       :
   332                              <1> ;	 (AH)=	NEW VALUE TO BE PLACED IN THE ADDRESSED TABLE LOCATION	       :
   333                              <1> ;									       :
   334                              <1> ; OUTPUT:	VALUE IN (AH) PLACED IN LOCATION (AL) WITH NMI LEFT DISABLED   :
   335                              <1> ;		IF BIT 7 OF (AL) IS ON, DURING THE CMOS UPDATE BOTH NMI AND    :
   336                              <1> ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
   337                              <1> ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
   338                              <1> ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
   339                              <1> ;		ONLY THE CMOS LOCATION AND THE NMI STATE IS CHANGED.	       :
   340                              <1> ;-------------------------------------------------------------------------------
   341                              <1> 
   342                              <1> 	; 08/08/2022
   343                              <1> CMOS_WRITE:				; WRITE (AH) TO LOCATION (AL)
   344                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
   345                              <1> 	;pushf				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
   346                              <1> 	;;push	ax			; SAVE WORK REGISTER VALUES
   347                              <1> 	; 18/04/2021
   348                              <1> 	;push	eax
   349 000063E2 D0C0                <1> 	rol	al, 1			; MOVE NMI BIT TO LOW POSITION
   350 000063E4 F9                  <1> 	stc				; FORCE NMI BIT ON IN CARRY FLAG
   351 000063E5 D0D8                <1> 	rcr	al, 1			; HIGH BIT ON TO DISABLE NMI - OLD IN CY
   352 000063E7 FA                  <1> 	cli				; DISABLE INTERRUPTS
   353 000063E8 E670                <1> 	out	CMOS_PORT, al		; ADDRESS LOCATION AND DISABLE NMI
   354 000063EA 88E0                <1> 	mov	al, ah			; GET THE DATA BYTE TO WRITE
   355 000063EC E671                <1> 	out	CMOS_DATA, al		; PLACE IN REQUESTED CMOS LOCATION
   356 000063EE B01E                <1> 	mov	al, CMOS_SHUT_DOWN*2	; GET ADDRESS OF DEFAULT LOCATION
   357                              <1> 	;mov	al, CMOS_REG_D*2 	; GET ADDRESS OF DEFAULT LOCATION
   358 000063F0 D0D8                <1> 	rcr	al, 1			; PUT ORIGINAL NMI MASK BIT INTO ADDRESS
   359 000063F2 E670                <1> 	out	CMOS_PORT, al		; SET DEFAULT TO READ ONLY REGISTER
   360                              <1> 	;nop				; I/O DELAY
   361                              <1> 	; 29/07/2022
   362 000063F4 E6EB                <1> 	out	0EBh, al ; NEWIODELAY ; AWARD BIOS 1999, ATIME.ASM
   363 000063F6 E471                <1> 	in	al, CMOS_DATA		; OPEN STANDBY LATCH
   364                              <1> 	;;pop	ax			; RESTORE WORK REGISTERS
   365                              <1> 	; 18/04/2021
   366                              <1> 	;pop	eax
   367                              <1> 	;popf
   368                              <1> 	; 29/07/2022
   369                              <1> 	;clc
   370                              <1> 	; 08/08/2022
   371 000063F8 30C0                <1> 	xor	al, al
   372 000063FA C3                  <1> 	retn
   373                              <1> 
   374                              <1> ;-------------------------------------------------------------------------------
   375                              <1> 
   376                              <1> RTC_60:				; SET RTC ALARM
   377 000063FB B00B                <1> 	mov	al, CMOS_REG_B		; ADDRESS ALARM
   378 000063FD E80B010000          <1> 	call	CMOS_READ		; READ ALARM REGISTER
   379 00006402 A820                <1> 	test	al, 20h			; CHECK FOR ALARM ALREADY ENABLED
   380 00006404 F9                  <1> 	stc				; SET CARRY IN CASE OF ERROR
   381 00006405 7541                <1> 	jnz	short RTC_69		; ERROR EXIT IF ALARM SET
   382 00006407 E8CB000000          <1> 	call	UPD_IPR			; CHECK FOR UPDATE IN PROCESS
   383 0000640C 7305                <1> 	jnc	short RTC_65		; SKIP INITIALIZATION IF NO ERROR
   384 0000640E E8DF000000          <1> 	call	RTC_STA			; ELSE INITIALIZE CLOCK
   385                              <1> RTC_65:	
   386 00006413 88F4                <1> 	mov	ah, dh			; GET SECONDS BYTE
   387 00006415 B001                <1> 	mov	al, CMOS_SEC_ALARM	; ADDRESS THE SECONDS ALARM REGISTER
   388 00006417 E8C6FFFFFF          <1> 	call	CMOS_WRITE		; INSERT SECONDS
   389 0000641C 88CC                <1> 	mov	ah, cl			; GET MINUTES PARAMETER
   390 0000641E B003                <1> 	mov	al, CMOS_MIN_ALARM	; ADDRESS MINUTES ALARM REGISTER
   391 00006420 E8BDFFFFFF          <1> 	call	CMOS_WRITE		; INSERT MINUTES
   392 00006425 88EC                <1> 	mov	ah, ch			; GET HOURS PARAMETER
   393 00006427 B005                <1> 	mov	al, CMOS_HR_ALARM	; ADDRESS HOUR ALARM REGISTER
   394 00006429 E8B4FFFFFF          <1> 	call	CMOS_WRITE		; INSERT HOURS
   395 0000642E E4A1                <1> 	in	al, INTB01		; READ SECOND INTERRUPT MASK REGISTER
   396 00006430 24FE                <1> 	and	al, 0FEh		; ENABLE ALARM TIMER BIT (CY= 0)
   397 00006432 E6A1                <1> 	out	INTB01, al		; WRITE UPDATED MASK
   398                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   399                              <1> 	;mov	ah, al
   400 00006434 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257
   401 00006438 E8D0000000          <1> 	call	CMOS_READ		; READ CURRENT ALARM REGISTER
   402 0000643D 247F                <1> 	and	al, 07Fh		; ENSURE SET BIT TURNED OFF
   403 0000643F 0C20                <1> 	or	al, 20h			; TURN ON ALARM ENABLE
   404 00006441 86C4                <1> 	xchg	ah, al			; MOVE MASK TO OUTPUT REGISTER
   405 00006443 E89AFFFFFF          <1> 	call	CMOS_WRITE		; WRITE NEW ALARM MASK
   406                              <1> 	; 29/07/2022
   407                              <1> 	;clc				; SET CY= 0
   408                              <1> RTC_69:
   409 00006448 66B80000            <1> 	mov	ax, 0			; CLEAR AX REGISTER
   410 0000644C C3                  <1> 	retn				; RETURN WITH RESULTS IN CARRY FLAC
   411                              <1> 
   412                              <1> RTC_70:				; RESET ALARM
   413                              <1> 	;mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   414                              <1> 	;mov	ah, al
   415 0000644D 66B80B0B            <1> 	mov	ax, CMOS_REG_B * 257	; ADDRESS ALARM REGISTER (TO BOTH AH,AL)
   416 00006451 E8B7000000          <1> 	call	CMOS_READ		; READ ALARM REGISTER
   417 00006456 2457                <1> 	and	al, 57h			; TURN OFF ALARM ENABLE
   418 00006458 86C4                <1> 	xchg	ah, al			; SAVE DATA AND RECOVER ADDRESS
   419                              <1> 	;call	CMOS_WRITE		; RESTORE NEW VALUE
   420                              <1> 	;clc				; SET CY= 0
   421                              <1> 	;retn				; RETURN WITH NO CARRY
   422                              <1> 	; 29/07/2022
   423 0000645A EB86                <1> 	jmp	short CMOS_WRITE
   424                              <1> 
   425                              <1> ;-------------------------------------------------------------------------------
   426                              <1> 
   427                              <1> ; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
   428                              <1> 
   429                              <1> ;--- HARDWARE INT 70 H -- ( IRQ LEVEL 8) ----------------------------------------
   430                              <1> ; ALARM INTERRUPT HANDLER (RTC)							:
   431                              <1> ;       THIS ROUTINE HANDLES THE PERIODIC AND ALARM INTERRUPTS FROM THE CMOS	:
   432                              <1> ;       TIMER. INPUT FREQUENCY IS 1.024 KHZ OR APPROXIMATELY 1024 INTERRUPTS	:
   433                              <1> ;       EVERY SECOND FOR THE PERIODIC INTERRUPT. FOR THE ALARM FUNCTION,	:
   434                              <1> ;       THE INTERRUPT WILL OCCUR AT THE DESIGNATED TIME.			:
   435                              <1> ;										:
   436                              <1> ;       INTERRUPTS ARE ENABLED WHEN THE EVENT OR ALARM FUNCTION IS ACTIVATED.	:
   437                              <1> ;       FOR THE EVENT INTERRUPT, THE HANDLER WILL DECREMENT THE WAIT COUNTER	:
   438                              <1> ;       AND WHEN IT EXPIRES WILL SET THE DESIGNATED LOCATION TO 80H. FOR	:
   439                              <1> ;       THE ALARM INTERRUPT. THE USER MUST PROVIDE A ROUTINE TO INTERCEPT	:
   440                              <1> ;       THE CORRECT ADDRESS FROM THE VECTOR TABLE INVOKED BY INTERRUPT 4AH	:
   441                              <1> ;       PRIOR TO SETTING THE REAL TIME CLOCK ALARM (INT 1AH, AH= 06H).		:
   442                              <1> ;--------------------------------------------------------------------------------
   443                              <1> 
   444                              <1> RTC_A_INT: ; 07/01/2017
   445                              <1> ;RTC_INT:				; ALARM INTERRUPT
   446 0000645C 1E                  <1> 	push	ds			; LEAVE INTERRUPTS DISABLED
   447 0000645D 50                  <1> 	push	eax			; SAVE REGISTERS
   448 0000645E 57                  <1> 	push	edi
   449                              <1> RTC_I_1:				; CHECK FOR SECOND INTERRUPT
   450 0000645F 66B88C8B            <1> 	mov	ax, 256*(CMOS_REG_B+NMI)+CMOS_REG_C+NMI ; ALARM AND STATUS
   451 00006463 E670                <1> 	out	CMOS_PORT, al		; WRITE ALARM FLAG MASK ADDRESS
   452 00006465 90                  <1> 	nop				; I/O DELAY
   453 00006466 EB00                <1> 	jmp	short $+2
   454 00006468 E471                <1> 	in	al, CMOS_DATA		; READ AND RESET INTERRUPT REQUEST FLAGS
   455 0000646A A860                <1> 	test	al, 01100000b		; CHECK FOR EITHER INTERRUPT PENDING
   456 0000646C 745B                <1> 	jz	short	RTC_I_9		; EXIT IF NOT A VALID RTC INTERRUPT
   457                              <1> 
   458 0000646E 86C4                <1> 	xchg	ah, al			; SAVE FLAGS AND GET ENABLE ADDRESS
   459 00006470 E670                <1> 	out	CMOS_PORT, al		; WRITE ALARM ENABLE MASK ADDRESS
   460 00006472 90                  <1> 	nop				; I/O DELAY
   461 00006473 EB00                <1> 	jmp	short $+2	
   462 00006475 E471                <1> 	in	al, CMOS_DATA		; READ CURRENT ALARM ENABLE MASK
   463 00006477 20E0                <1> 	and	al, ah			; ALLOW ONLY SOURCES THAT ARE ENABLED
   464 00006479 A840                <1> 	test	al, 01000000b		; CHECK FOR PERIODIC INTERRUPT
   465 0000647B 7439                <1> 	jz	short RTC_I_5		; SKIP IF NOT A PERIODIC INTERRUPT
   466                              <1> 
   467                              <1> ;-----	DECREMENT WAIT COUNT BY INTERRUPT INTERVAL
   468                              <1> 
   469 0000647D 66BF1000            <1> 	mov	di, KDATA		; kernel data segment
   470 00006481 8EDF                <1> 	mov	ds, di
   471                              <1> 	
   472 00006483 812D[387D0100]D003- <1> 	sub	dword [RTC_LH], 976	; DECREMENT COUNT BY 1/1024
   472 0000648B 0000                <1>
   473 0000648D 7327                <1> 	jnc	short RTC_I_5		; SKIP TILL 32 BIT WORD LESS THAN ZERO
   474                              <1> 
   475                              <1> ;-----	TURN OFF PERIODIC INTERRUPT ENABLE
   476                              <1> 
   477                              <1> 	;push	ax			; SAVE INTERRUPT FLAG MASK
   478                              <1> 	; 18/04/2021
   479 0000648F 50                  <1> 	push	eax
   480 00006490 66B88B8B            <1> 	mov	ax, 257*(CMOS_REG_B+NMI) ; INTERRUPT ENABLE REGISTER
   481 00006494 E670                <1> 	out	CMOS_PORT, al		; WRITE ADDRESS TO CMOS CLOCK
   482 00006496 90                  <1> 	nop				; I/O DELAY
   483 00006497 EB00                <1> 	jmp	short $+2
   484 00006499 E471                <1> 	in	al, CMOS_DATA		; READ CURRENT ENABLES
   485 0000649B 24BF                <1> 	and	al, 0BFh		; TURN OFF PIE
   486 0000649D 86E0                <1> 	xchg	al, ah			; GET CMOS ADDRESS AND SAVE VALUE
   487 0000649F E670                <1> 	out	CMOS_PORT, al		; ADDRESS REGISTER B
   488 000064A1 86E0                <1> 	xchg	al, ah			; GET NEW INTERRUPT ENABLE MASK
   489 000064A3 E671                <1> 	out	CMOS_DATA, al		; SET MASK IN INTERRUPT ENABLE REGISTER
   490 000064A5 C605[3C7D0100]00    <1> 	mov	byte [RTC_WAIT_FLAG], 0	; SET FUNCTION ACTIVE FLAG OFF
   491 000064AC 8B3D[3D7D0100]      <1> 	mov	edi, [USER_FLAG]	; SET UP (DS:DI) TO POINT TO USER FLAG
   492 000064B2 C60780              <1> 	mov	byte [edi], 80h		; TURN ON USERS FLAG
   493                              <1> 	;pop	ax			; GET INTERRUPT SOURCE BACK
   494                              <1> 	; 18/04/2021
   495 000064B5 58                  <1> 	pop	eax
   496                              <1> RTC_I_5:
   497 000064B6 A820                <1> 	test	al, 00100000b		; TEST FOR ALARM INTERRUPT
   498 000064B8 740D                <1> 	jz	short RTC_I_7		; SKIP USER INTERRUPT CALL IF NOT ALARM
   499                              <1> 
   500 000064BA B00D                <1> 	mov	al, CMOS_REG_D		; POINT TO DEFAULT READ ONLY REGISTER
   501 000064BC E670                <1> 	out	CMOS_PORT, al		; ENABLE NMI AND CMOS ADDRESS TO DEFAULT
   502 000064BE FB                  <1> 	sti				; INTERRUPTS BACK ON NOW
   503 000064BF 52                  <1> 	push	edx
   504 000064C0 E846BD0000          <1> 	call	INT4Ah			; TRANSFER TO USER ROUTINE
   505 000064C5 5A                  <1> 	pop	edx
   506 000064C6 FA                  <1> 	cli				; BLOCK INTERRUPT FOR RETRY
   507                              <1> RTC_I_7:				; RESTART ROUTINE TO HANDLE DELAYED
   508 000064C7 EB96                <1> 	jmp	short RTC_I_1		;  ENTRY AND SECOND EVENT BEFORE DONE
   509                              <1> 
   510                              <1> RTC_I_9:				; EXIT - NO PENDING INTERRUPTS
   511 000064C9 B00D                <1> 	mov	al, CMOS_REG_D		; POINT TO DEFAULT READ ONLY REGISTER
   512 000064CB E670                <1> 	out	CMOS_PORT, al		; ENABLE NMI AND CMOS ADDRESS TO DEFAULT
   513 000064CD B020                <1> 	mov	al, EOI			; END OF INTERRUPT MASK TO 8259 - 2
   514 000064CF E6A0                <1> 	out	INTB00, al		; TO 8259 - 2
   515 000064D1 E620                <1> 	out	INTA00,	al		; TO 8259 - 1
   516 000064D3 5F                  <1> 	pop	edi			; RESTORE REGISTERS
   517 000064D4 58                  <1> 	pop	eax
   518 000064D5 1F                  <1> 	pop	ds
   519 000064D6 CF                  <1> 	iretd				; END OF INTERRUPT
   520                              <1> 
   521                              <1> ;-------------------------------------------------------------------------------
   522                              <1> 
   523                              <1> 	; 29/05/2016 - TRDOS 386 (TRDOS v2.0)
   524                              <1> 	; 22/08/2014 (Retro UNIX 386 v1)
   525                              <1> 	; IBM PC/AT BIOS source code ----- 10/06/85 (bios2.asm)
   526                              <1> UPD_IPR:				; WAIT TILL UPDATE NOT IN PROGRESS
   527 000064D7 51                  <1> 	push	ecx
   528                              <1> 
   529                              <1> 	; 29/05/2016
   530 000064D8 B968110000          <1> 	mov	ecx, ((1984+244)*4)/2	; AWARD BIOS 1999, ATIME.ASM		
   531                              <1> 					; 'WAITCPU_CK_UD_STAT'
   532                              <1> 					; (244Us + 1984Us)
   533                              <1> 					; (assume each read takes
   534                              <1> 					;  2 microseconds).
   535                              <1> 	;mov	ecx, 65535		
   536                              <1> 		;mov cx, 800		; SET TIMEOUT LOOP COUNT (= 800)	
   537                              <1> UPD_10:
   538 000064DD B00A                <1> 	mov	al, CMOS_REG_A		; ADDRESS STATUS REGISTER A
   539 000064DF FA                  <1> 	cli				; NO TIMER INTERRUPTS DURING UPDATES
   540 000064E0 E828000000          <1> 	call	CMOS_READ		; READ UPDATE IN PROCESS FLAG
   541 000064E5 A880                <1> 	test	al, 80h			; IF UIP BIT IS ON ( CANNOT READ TIME )
   542 000064E7 7406                <1> 	jz	short UPD_90		; EXIT WITH CY= 0 IF CAN READ CLOCK NOW
   543 000064E9 FB                  <1> 	sti				; ALLOW INTERRUPTS WHILE WAITING
   544 000064EA E2F1                <1> 	loop	UPD_10			; LOOP TILL READY OR TIMEOUT
   545 000064EC 31C0                <1> 	xor	eax, eax ; xor ax, ax	; CLEAR RESULTS IF ERROR
   546 000064EE F9                  <1> 	stc				; SET CARRY FOR ERROR
   547                              <1> UPD_90:
   548 000064EF 59                  <1> 	pop	ecx			; RESTORE CALLERS REGISTER
   549 000064F0 FA                  <1> 	cli				; INTERRUPTS OFF DURING SET
   550 000064F1 C3                  <1> 	retn				; RETURN WITH CY FLAG SET
   551                              <1> 
   552                              <1> 	; 18/04/2021
   553                              <1> RTC_STA:			; INITIALIZE REAL TIME CLOCK
   554                              <1> 	;mov	al, CMOS_REG_A		; ADDRESS REGISTER A AND LOAD DATA MASK		
   555                              <1> 	;mov	ah, 26h
   556 000064F2 66B80A26            <1> 	mov	ax, (26h*100h)+CMOS_REG_A
   557 000064F6 E8E7FEFFFF          <1> 	call	CMOS_WRITE		; INITIALIZE STATUS REGISTER A
   558                              <1> 	;mov	al, CMOS_REG_B		; SET "SET BIT" FOR CLOCK INITIALIZATION	
   559                              <1> 	;mov	ah, 82h
   560 000064FB 66B80B82            <1> 	mov	ax, (82h*100h)+CMOS_REG_B
   561 000064FF E8DEFEFFFF          <1> 	call	CMOS_WRITE		; AND 24 HOUR MODE TO REGISTER B
   562 00006504 B00C                <1> 	mov	al, CMOS_REG_C		; ADDRESS REGISTER C
   563 00006506 E802000000          <1> 	call	CMOS_READ		; READ REGISTER C TO INITIALIZE
   564 0000650B B00D                <1> 	mov	al, CMOS_REG_D		; ADDRESS REGISTER D
   565                              <1> 	; 18/04/2021
   566                              <1> 	;call	CMOS_READ		; READ REGISTER D TO INITIALIZE
   567                              <1> 	;retn
   568                              <1> 	;jmp	short CMOS_READ ; 18/04/2021
   569                              <1> 
   570                              <1> ;-------------------------------------------------------------------------------
   571                              <1> 
   572                              <1> 	; 29/07/2022 - TRDOS 386 v2.0.5
   573                              <1> 	; 18/04/2021 - TRDOS 386 v2.0.4
   574                              <1> 	; 29/05/2016 - TRDOS 386 (TRDOS v2.0) 
   575                              <1> 	; 22/08/2014 (Retro UNIX 386 v1)
   576                              <1> 	; IBM PC/AT BIOS source code ----- 10/06/85 (test4.asm)
   577                              <1> 
   578                              <1> ;--- CMOS_READ -----------------------------------------------------------------
   579                              <1> ;		READ BYTE FROM CMOS_SYSTEM CLOCK CONFIGURATION TABLE	       :
   580                              <1> ;									       :
   581                              <1> ; INPUT: (AL)=	CMOS_TABLE ADDRESS TO BE READ				       :
   582                              <1> ;		BIT    7 = 0 FOR NMI ENABLED AND 1 FOR NMI DISABLED ON EXIT    :
   583                              <1> ;		BITS 6-0 = ADDRESS OF TABLE LOCATION TO READ		       :
   584                              <1> ;									       :
   585                              <1> ; OUTPUT: (AL)	VALUE AT LOCATION (AL) MOVED INTO (AL). IF BIT 7 OF (AL) WAS   :
   586                              <1> ;		ON THEN NMI LEFT DISABLED, DURING THE CMOS READ BOTH NMI AND   :
   587                              <1> ;		NORMAL INTERRUPTS ARE DISABLED TO PROTECT CMOS DATA INTEGRITY. :
   588                              <1> ;		THE CMOS ADDRESS REGISTER IS POINTED TO A DEFAULT VALUE AND    :
   589                              <1> ;		THE INTERRUPT FLAG RESTORED TO THE ENTRY STATE ON RETURN.      :
   590                              <1> ;		ONLY THE (AL) REGISTER AND THE NMI STATE IS CHANGED.	       :
   591                              <1> ;-------------------------------------------------------------------------------
   592                              <1> 
   593                              <1> CMOS_READ:
   594                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
   595                              <1> 	;pushf				; SAVE INTERRUPT ENABLE STATUS AND FLAGS
   596 0000650D D0C0                <1> 	rol	al, 1			; MOVE NMI BIT TO LOW POSITION
   597 0000650F F9                  <1> 	stc				; FORCE NMI BIT ON IN CARRY FLAG
   598 00006510 D0D8                <1> 	rcr	al, 1			; HIGH BIT ON TO DISABLE NMI - OLD IN CY
   599 00006512 FA                  <1> 	cli				; DISABLE INTERRUPTS
   600 00006513 E670                <1> 	out	CMOS_PORT, al		; ADDRESS LOCATION AND DISABLE NMI
   601                              <1> 	; 29/05/2016
   602                              <1> 	;nop				; I/O DELAY
   603 00006515 E6EB                <1> 	out	0EBh, al ; NEWIODELAY ; AWARD BIOS 1999, ATIME.ASM
   604                              <1> 	;
   605 00006517 E471                <1> 	in	al, CMOS_DATA		; READ THE REQUESTED CMOS LOCATION
   606                              <1> 	;push	ax	; SAVE (AH) REGISTER VALUE AND CMOS BYTE
   607                              <1> 	; 18/04/2021
   608 00006519 50                  <1> 	push	eax
   609                              <1> 	; 15/03/2015 ; IBM PC/XT Model 286 BIOS source code 
   610                              <1> 		     ; ----- 10/06/85 (test4.asm)
   611 0000651A B01E                <1> 	mov	al, CMOS_SHUT_DOWN*2 	; GET ADDRESS OF DEFAULT LOCATION
   612                              <1> 	;mov	al, CMOS_REG_D*2 	; GET ADDRESS OF DEFAULT LOCATION
   613 0000651C D0D8                <1> 	rcr	al, 1			; PUT ORIGINAL NMI MASK BIT INTO ADDRESS
   614 0000651E E670                <1> 	out	CMOS_PORT, al		; SET DEFAULT TO READ ONLY REGISTER
   615                              <1> 	;pop	ax			; RESTORE (AH) AND (AL), CMOS BYTE
   616                              <1> 	; 18/04/2021
   617 00006520 58                  <1> 	pop	eax
   618                              <1> 	; 29/07/2022
   619                              <1> 	;popf
   620 00006521 F8                  <1> 	clc	; 29/07/2022	
   621 00006522 C3                  <1> 	retn				; RETURN WITH FLAGS RESTORED
   622                              <1> 
   623                              <1> ;-------------------------------------------------------------------------------
   624                              <1> 
   625                              <1> ; /// End Of TIMER FUNCTIONS ///
  3228                                  
  3229 00006523 90<rep Dh>              Align 16
  3230                                  
  3231                                  gdt:	; Global Descriptor Table
  3232                                  	; 02/12/2020
  3233                                  	; (30/07/2015, conforming cs)
  3234                                  	; (26/03/2015)
  3235                                  	; (24/03/2015, tss)
  3236                                  	; (19/03/2015)
  3237                                  	; (29/12/2013)
  3238                                  	;
  3239 00006530 0000000000000000        	dw 0, 0, 0, 0		; NULL descriptor
  3240                                  gdt_kcode:
  3241                                  	; 18/08/2014
  3242                                  			; 8h kernel code segment, base = 00000000h		
  3243                                  	;dw 0FFFFh, 0, 9E00h, 00CFh	; KCODE  ; 30/12/2016	 
  3244 00006538 FFFF0000009ACF00        	dw 0FFFFh, 0, 9A00h, 00CFh	; KCODE
  3245                                  gdt_kdata:
  3246                                  			; 10h kernel data segment, base = 00000000h	
  3247 00006540 FFFF00000092CF00        	dw 0FFFFh, 0, 9200h, 00CFh	; KDATA
  3248                                  gdt_ucode:
  3249                                  			; 1Bh user code segment, base address = 400000h ; CORE
  3250                                  	;dw 0FBFFh, 0, 0FE40h, 00CFh	; UCODE  ; 30/12/2016	
  3251 00006548 FFFB000040FACF00        	dw 0FBFFh, 0, 0FA40h, 00CFh	; UCODE
  3252                                  gdt_udata: 
  3253                                  			; 23h user data segment, base address = 400000h ; CORE
  3254 00006550 FFFB000040F2CF00        	dw 0FBFFh, 0, 0F240h, 00CFh	; UDATA
  3255                                  gdt_tss:
  3256                                  			; Task State Segment
  3257 00006558 6700                    	dw 0067h ; Limit = 103 ; (104-1, tss size = 104 byte, 
  3258                                  			       ;  no IO permission in ring 3)
  3259                                  gdt_tss0:
  3260 0000655A 0000                    	dw 0  ; TSS base address, bits 0-15 
  3261                                  gdt_tss1:
  3262 0000655C 00                      	db 0  ; TSS base address, bits 16-23 
  3263                                  	      		; 49h	
  3264 0000655D E9                      	db 11101001b ; 0E9h => P=1/DPL=11/0/1/0/B/1 --> B = Task is busy (1)
  3265 0000655E 00                      	db 0 ; G/0/0/AVL/LIMIT=0000 ; (Limit bits 16-19 = 0000) (G=0, 1 byte)
  3266                                  gdt_tss2:
  3267 0000655F 00                      	db 0  ; TSS base address, bits 24-31 
  3268                                  
  3269                                  	; 04/12/2023 - TRDOS v2.0.7
  3270                                  	; 30/11/2020
  3271                                  	; 29/11/2020 - TRDOS v2.0.3
  3272                                  	; VESA VBE3 VIDE BIOS 32 BIT PMI SEGMENTS (16 bit segments)
  3273                                  			; 30h ; VBE3CS
  3274                                  _vbe3_CS:  ; vesa vbe3 bios uses this as code seg (same addr with _vbe3_DS)
  3275                                  	; limit = 65536, base addr = 0, P/DPL/1/Type/C/R/A = 9Ah, 16 bit
  3276                                  	;dw 0FFFFh, 0, 9A00h, 0 ; Note: base addr will be initialized
  3277                                  	; 04/12/2023 - TRDOS 386 v2.0.7	; (+!*!+)
  3278 00006560 FFFF0000069A0000        	dw 0FFFFh, 0, 9A06h, 0	; VBE3BIOSCODE_ADDR = 60000h
  3279                                  			; 38h ; VBE3BDS
  3280                                  _vbe3_BDS: ; vesa vbe3 bios uses this as equivalent of rombios data segment
  3281                                  	; limit = 1536, base addr = 0, P/DPL/1/Type/E/W/A = 92h, 16 bit
  3282 00006568 FF05000000920000        	dw 05FFh, 0, 9200h, 0 ; Note: base addr will be initialized	
  3283                                  			; 40h ; VBE3A000 
  3284                                  _A0000Sel: ; VGA default video memory address
  3285                                  	; limit = 65536, base addr = 0A0000h, 16 bit
  3286 00006570 FFFF00000A920000        	dw 0FFFFh, 0, 920Ah, 0
  3287                                  			; 48h ; VBE3B000 
  3288                                  _B0000Sel: ; MDA (monochrome) video memory address
  3289                                  	; limit = 65536, base addr = 0B0000h, 16 bit
  3290 00006578 FFFF00000B920000        	dw 0FFFFh, 0, 920Bh, 0
  3291                                  			; 50h ; VBE3B800 
  3292                                  _B8000Sel: ; CGA video memory address
  3293                                  	; limit = 32768, base addr = 0B8000h, 16 bit
  3294 00006580 FF7F00800B920000        	dw 07FFFh, 8000h, 920Bh, 0
  3295                                  			; 58h ; VBE3DS 
  3296                                  _vbe3_DS: ; vesa vbe3 bios uses this as data seg (CodeSegSel in PMInfoBlock)
  3297                                  	; limit = 65536, base addr = 0, P/DPL/1/Type/E/W/A = 92h, 16 bit
  3298                                  	;dw 0FFFFh, 0, 9200h, 0 ; Note: base addr will be initialized
  3299                                  	; 04/12/2023 - TRDOS 386 v2.0.7	; (+!*!+)
  3300 00006588 FFFF000006920000        	dw 0FFFFh, 0, 9206h, 0	; VBE3BIOSCODE_ADDR = 60000h
  3301                                  			; 60h ; VBE3SS   
  3302                                  _vbe3_SS: ; kernel's stack segment but 16 bit version (same stack addr)
  3303                                  	; limit = 1024, base addr = 0, P/DPL/1/Type/E/W/A = 92h, 16 bit
  3304 00006590 FF03000000920000        	dw 03FFh, 0, 9200h, 0 ; Note: base addr will be initialized
  3305                                  			; 68h ; VBE3ES 	
  3306                                  _vbe3_ES: ; extra 16 bit segment points to buffers in kernel's mem space
  3307                                  	; limit = 2048, base addr = 0, P/DPL/1/Type/E/W/A = 92h, 16 bit
  3308 00006598 FF07000000920000        	dw 07FFh, 0, 9200h,0 ; Note: base addr will be initialized
  3309                                  			; 70h ; KODE16	
  3310                                  _16bit_CS: ; 16 bit code segment points to kernel's far return addr
  3311                                  	; limit = 16M, base addr = 0, P/DPL/1/Type/E/W/A = 92h, 16 bit
  3312 000065A0 FFFF0000009AFF00        	dw 0FFFFh, 0, 9A00h, 00FFh ; Note: base addr will be initialized
  3313                                  
  3314                                  gdt_end:
  3315                                  	;; 9Eh = 1001 1110b (GDT byte 5) P=1/DPL=00/1/TYPE=1110, 
  3316                                  					;; Type= 1 (code)/C=1/R=1/A=0
  3317                                  		; P= Present, DPL=0=ring 0,  1= user (0= system)
  3318                                  		; 1= Code C= Conforming, R= Readable, A= Accessed
  3319                                  
  3320                                  	;; 9Ah = 1001 1010b (GDT byte 5) P=1/DPL=00/1/TYPE=1010, 
  3321                                  					;; Type= 1 (code)/C=0/R=1/A=0
  3322                                  		; P= Present, DPL=0=ring 0,  1= user (0= system)
  3323                                  		; 1= Code C= non-Conforming, R= Readable, A= Accessed
  3324                                  
  3325                                  	;; 92h = 1001 0010b (GDT byte 5) P=1/DPL=00/1/TYPE=1010, 
  3326                                  					;; Type= 0 (data)/E=0/W=1/A=0
  3327                                  		; P= Present, DPL=0=ring 0,  1= user (0= system)
  3328                                  		; 0= Data E= Expansion direction (1= down, 0= up)
  3329                                  		; W= Writeable, A= Accessed
  3330                                  
  3331                                  	;; FEh = 1111 1110b (GDT byte 5) P=1/DPL=11/1/TYPE=1110, 
  3332                                  					;; Type= 1 (code)/C=1/R=1/A=0
  3333                                  		; P= Present, DPL=3=ring 3,  1= user (0= system)
  3334                                  		; 1= Code C= Conforming, R= Readable, A= Accessed
  3335                                  	
  3336                                  	;; FAh = 1111 1010b (GDT byte 5) P=1/DPL=11/1/TYPE=1010, 
  3337                                  					;; Type= 1 (code)/C=0/R=1/A=0
  3338                                  		; P= Present, DPL=3=ring 3,  1= user (0= system)
  3339                                  		; 1= Code C= non-Conforming, R= Readable, A= Accessed
  3340                                  
  3341                                  	;; F2h = 1111 0010b (GDT byte 5) P=1/DPL=11/1/TYPE=0010, 
  3342                                  					;; Type= 0 (data)/E=0/W=1/A=0
  3343                                  		; P= Present, DPL=3=ring 3,  1= user (0= system)
  3344                                  		; 0= Data E= Expansion direction (1= down, 0= up)
  3345                                  	
  3346                                  	;; CFh = 1100 1111b (GDT byte 6) G=1/B=1/0/AVL=0, Limit=1111b (3)
  3347                                  
  3348                                  		;; Limit = FFFFFh (=> FFFFFh+1= 100000h) // bits 0-15, 48-51 //
  3349                                  		;	 = 100000h * 1000h (G=1) = 4GB
  3350                                  		;; Limit = FFBFFh (=> FFBFFh+1= FFC00h) // bits 0-15, 48-51 //
  3351                                  		;	 = FFC00h * 1000h (G=1) = 4GB - 4MB
  3352                                  		; G= Granularity (1= 4KB), B= Big (32 bit), 
  3353                                  		; AVL= Available to programmers	
  3354                                  
  3355                                  gdtd:
  3356 000065A8 7700                            dw gdt_end - gdt - 1    ; Limit (size)
  3357 000065AA [30650000]                      dd gdt			; Address of the GDT
  3358                                  
  3359                                  	; 20/08/2014
  3360                                  idtd:
  3361 000065AE 7F02                            dw idt_end - idt - 1    ; Limit (size)
  3362 000065B0 [D8790100]                      dd idt			; Address of the IDT
  3363                                  
  3364                                  ; 20/02/2017
  3365                                  ;;; 11/03/2015
  3366                                  %include 'diskdata.s'	; DISK (BIOS) DATA (initialized)
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.5 - diskdata.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 06/08/2022 (Previous: 24/01/2016)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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 000065B4 [17660000]          <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 000065B8 01                  <1> 		DB	01		; DRIVE TYPE, MEDIA TABLE
   113                              <1>                 ;DW	MD_TBL1
   114 000065B9 [D6650000]          <1> 		dd	MD_TBL1
   115 000065BD 82                  <1> 		DB	02+BIT7ON
   116                              <1> 		;DW	MD_TBL2
   117 000065BE [E3650000]          <1>                 dd      MD_TBL2
   118 000065C2 02                  <1> DR_DEFAULT:	DB	02
   119                              <1>                 ;DW	MD_TBL3
   120 000065C3 [F0650000]          <1> 		dd      MD_TBL3
   121 000065C7 03                  <1> 		DB	03
   122                              <1>                 ;DW	MD_TBL4
   123 000065C8 [FD650000]          <1> 		dd      MD_TBL4
   124 000065CC 84                  <1> 		DB	04+BIT7ON
   125                              <1>                 ;DW	MD_TBL5
   126 000065CD [0A660000]          <1> 		dd      MD_TBL5
   127 000065D1 04                  <1> 		DB	04
   128                              <1>                 ;DW	MD_TBL6
   129 000065D2 [17660000]          <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 000065D6 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   141 000065D7 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   142 000065D8 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   143 000065D9 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   144 000065DA 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
   145 000065DB 2A                  <1> 	DB	02AH		; GAP LENGTH
   146 000065DC FF                  <1> 	DB	0FFH		; DTL
   147 000065DD 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
   148 000065DE F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   149 000065DF 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   150 000065E0 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   151 000065E1 27                  <1> 	DB	39		; MAX. TRACK NUMBER
   152 000065E2 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 000065E3 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   158 000065E4 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   159 000065E5 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   160 000065E6 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   161 000065E7 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
   162 000065E8 2A                  <1> 	DB	02AH		; GAP LENGTH
   163 000065E9 FF                  <1> 	DB	0FFH		; DTL
   164 000065EA 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
   165 000065EB F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   166 000065EC 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   167 000065ED 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   168 000065EE 27                  <1> 	DB	39		; MAX. TRACK NUMBER
   169 000065EF 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 000065F0 DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   175 000065F1 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   176 000065F2 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   177 000065F3 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   178 000065F4 0F                  <1> 	DB	15		; EOT (LAST SECTOR ON TRACK)
   179 000065F5 1B                  <1> 	DB	01BH		; GAP LENGTH
   180 000065F6 FF                  <1> 	DB	0FFH		; DTL
   181 000065F7 54                  <1> 	DB	054H		; GAP LENGTH FOR FORMAT
   182 000065F8 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   183 000065F9 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   184 000065FA 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   185 000065FB 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
   186 000065FC 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 000065FD DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   192 000065FE 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   193 000065FF 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   194 00006600 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   195 00006601 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
   196 00006602 2A                  <1> 	DB	02AH		; GAP LENGTH
   197 00006603 FF                  <1> 	DB	0FFH		; DTL
   198 00006604 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
   199 00006605 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   200 00006606 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   201 00006607 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   202 00006608 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
   203 00006609 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 0000660A DF                  <1> 	DB	11011111B	; SRT=D, HD UNLOAD=0F - 1ST SPECIFY BYTE
   209 0000660B 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   210 0000660C 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   211 0000660D 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   212 0000660E 09                  <1> 	DB	09		; EOT (LAST SECTOR ON TRACK)
   213 0000660F 2A                  <1> 	DB	02AH		; GAP LENGTH
   214 00006610 FF                  <1> 	DB	0FFH		; DTL
   215 00006611 50                  <1> 	DB	050H		; GAP LENGTH FOR FORMAT
   216 00006612 F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   217 00006613 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   218 00006614 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   219 00006615 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
   220 00006616 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 00006617 AF                  <1> 	DB	10101111B	; SRT=A, HD UNLOAD=0F - 1ST SPECIFY BYTE
   226 00006618 02                  <1> 	DB	2		; HD LOAD=1, MODE=DMA - 2ND SPECIFY BYTE
   227 00006619 25                  <1> 	DB	MOTOR_WAIT	; WAIT TIME AFTER OPERATION TILL MOTOR OFF
   228 0000661A 02                  <1> 	DB	2		; 512 BYTES/SECTOR
   229 0000661B 12                  <1> 	DB	18		; EOT (LAST SECTOR ON TRACK)
   230 0000661C 1B                  <1> 	DB	01BH		; GAP LENGTH
   231 0000661D FF                  <1> 	DB	0FFH		; DTL
   232 0000661E 6C                  <1> 	DB	06CH		; GAP LENGTH FOR FORMAT
   233 0000661F F6                  <1> 	DB	0F6H		; FILL BYTE FOR FORMAT
   234 00006620 0F                  <1> 	DB	15		; HEAD SETTLE TIME (MILLISECONDS)
   235 00006621 08                  <1> 	DB	8		; MOTOR START TIME (1/8 SECONDS)
   236 00006622 4F                  <1> 	DB	79		; MAX. TRACK NUMBER
   237 00006623 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 00006624 E0                  <1> 	db	NO_ERR
   280 00006625 024001BB            <1> 	db	BAD_ADDR_MARK,BAD_SEEK,BAD_CMD,UNDEF_ERR
   281 00006629 04BB100A            <1> 	db	RECORD_NOT_FND,UNDEF_ERR,BAD_ECC,BAD_SECTOR
   282                              <1> 
   283                              <1> ; 06/08/2022
   284                              <1> ; 17/12/2014 (mov ax, [cfd])
   285                              <1> ; 11/12/2014
   286                              <1> ;cfd:		db	0		; current floppy drive (for GET_PARM)
   287                              <1> ; 17/12/2014				; instead of 'DISK_POINTER'
   288                              <1> ;pfd:		db	1		; previous floppy drive (for GET_PARM)
   289                              <1> 					; (initial value of 'pfd 
   290                              <1> 					; must be different then 'cfd' value
   291                              <1> 					; to force updating/initializing
   292                              <1> 					; current drive parameters) 
   293                              <1> ; 06/08/2022 - TRDOS 386 Kernel v2.0.5
   294                              <1> ; 11/07/2022 - Retro UNIX 386 v1.1 (Kernel v0.2.1.5)
   295 0000662D FF                  <1> pfd:		db	0FFh
   296                              <1> 
   297                              <1> align 2
   298                              <1> 
   299 0000662E F001                <1> HF_PORT:	dw 	1F0h  ; Default = 1F0h
   300                              <1> 			      ; (170h)
   301 00006630 F603                <1> HF_REG_PORT:	dw	3F6h  ; HF_PORT + 206h
   302                              <1> 
   303                              <1> ; 05/01/2015 
   304 00006632 00                  <1> hf_m_s:         db      0     ; (0 = Master, 1 = Slave)
   305                              <1> 
   306                              <1> ; *****************************************************************************
  3367                                  
  3368 00006633 90                      Align 2
  3369                                  
  3370                                  ; 04/11/2014 (Retro UNIX 386 v1)
  3371 00006634 0000                    mem_1m_1k:   dw 0  ; Number of contiguous KB between
  3372                                                       ; 1 and 16 MB, max. 3C00h = 15 MB.
  3373 00006636 0000                    mem_16m_64k: dw 0  ; Number of contiguous 64 KB blocks
  3374                                  		   ; between 16 MB and 4 GB.
  3375                                  
  3376                                  ; 12/11/2014 (Retro UNIX 386 v1)
  3377 00006638 00                      boot_drv:    db 0 ; boot drive number (physical)
  3378                                  ; 24/11/2014
  3379 00006639 00                      drv:	     db 0 
  3380 0000663A 00                      last_drv:    db 0 ; last hdd
  3381 0000663B 00                      hdc:         db 0  ; number of hard disk drives
  3382                                  		     ; (present/detected)
  3383                                  
  3384                                  ; 24/11/2014 (Retro UNIX 386 v1)
  3385                                  ; Physical drive type & flags
  3386 0000663C 00                      fd0_type:    db 0  ; floppy drive type
  3387 0000663D 00                      fd1_type:    db 0  ; 4 = 1.44 Mb, 80 track, 3.5" (18 spt)
  3388                                  		     ; 6 = 2.88 Mb, 80 track, 3.5" (36 spt)
  3389                                  		     ; 3 = 720 Kb, 80 track, 3.5" (9 spt)
  3390                                  		     ; 2 = 1.2 Mb, 80 track, 5.25" (15 spt)
  3391                                  		     ; 1 = 360 Kb, 40 track, 5.25" (9 spt)		
  3392 0000663E 00                      hd0_type:    db 0  ; EDD status for hd0 (bit 7 = present flag)
  3393 0000663F 00                      hd1_type:    db 0  ; EDD status for hd1 (bit 7 = present flag)
  3394 00006640 00                      hd2_type:    db 0  ; EDD status for hd2 (bit 7 = present flag)
  3395 00006641 00                      hd3_type:    db 0  ; EDD status for hd3 (bit 7 = present flag)
  3396                                  		     ; bit 0 - Fixed disk access subset supported
  3397                                  		     ; bit 1 - Drive locking and ejecting
  3398                                  		     ; bit 2 - Enhanced disk drive support
  3399                                  		     ; bit 3 = Reserved (64 bit EDD support)
  3400                                  		     ; (If bit 0 is '1' Retro UNIX 386 v1
  3401                                  		     ; will interpret it as 'LBA ready'!)
  3402                                  
  3403                                  ; 08/08/2022
  3404                                  ; (drv.cylinders, drv.spt, drv.spt will not be used now on)
  3405                                  ; ('diskio.inc')
  3406                                  ; ((spt and heads and cylinder counts will be taken from DPT))
  3407                                  
  3408                                  ;; 11/03/2015 - 10/07/2015
  3409                                  ;drv.cylinders: dw 0,0,0,0,0,0,0
  3410                                  ;drv.heads:     dw 0,0,0,0,0,0,0
  3411                                  ;drv.spt:       dw 0,0,0,0,0,0,0
  3412                                  ; 12/07/2022 - 11/03/2015
  3413 00006642 000000000000000000-     drv.size:      dd 0,0,0,0,0,0,0
  3413 0000664B 000000000000000000-
  3413 00006654 000000000000000000-
  3413 0000665D 00                 
  3414 0000665E 00000000000000          drv.status:    db 0,0,0,0,0,0,0
  3415 00006665 00000000000000          drv.error:     db 0,0,0,0,0,0,0
  3416                                  ;
  3417                                  
  3418                                  Align 2
  3419                                  
  3420                                  ;;; 11/03/2015
  3421                                  %include 'kybdata.s'	; KEYBOARD (BIOS) DATA
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.5 - kybdata.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 24/07/2022 (Previous: 17/01/2016)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 17/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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> ; 24/07/2022 - TRDOS 386 Kernel v2.0.5
    26                              <1> ; 05/12/2014
    27                              <1> ; 04/12/2014 (derived from pc-xt-286 bios source code -1986-) 
    28                              <1> ; 03/06/86  KEYBOARD BIOS
    29                              <1> 
    30                              <1> ;---------------------------------------------------------------------------------
    31                              <1> ;	KEY IDENTIFICATION SCAN TABLES
    32                              <1> ;---------------------------------------------------------------------------------
    33                              <1> 
    34                              <1> ;-----	TABLES FOR ALT CASE ------------
    35                              <1> ;-----	ALT-INPUT-TABLE 
    36 0000666C 524F50514B          <1> K30:	db	82,79,80,81,75
    37 00006671 4C4D474849          <1> 	db	76,77,71,72,73		; 10 NUMBER ON KEYPAD
    38                              <1> ;-----	SUPER-SHIFT-TABLE 
    39 00006676 101112131415        <1> 	db	16,17,18,19,20,21	; A-Z TYPEWRITER CHARS
    40 0000667C 161718191E1F        <1> 	db	22,23,24,25,30,31
    41 00006682 202122232425        <1> 	db	32,33,34,35,36,37
    42 00006688 262C2D2E2F30        <1> 	db	38,44,45,46,47,48
    43 0000668E 3132                <1> 	db	49,50
    44                              <1> 
    45                              <1> ;-----	TABLE OF SHIFT KEYS AND MASK VALUES
    46                              <1> ;-----	KEY_TABLE 
    47 00006690 52                  <1> _K6:    db      INS_KEY                 ; INSERT KEY
    48 00006691 3A4546381D          <1> 	db	CAPS_KEY,NUM_KEY,SCROLL_KEY,ALT_KEY,CTL_KEY
    49 00006696 2A36                <1>         db      LEFT_KEY,RIGHT_KEY
    50                              <1> _K6L    equ     $-_K6
    51                              <1> 
    52                              <1> ;-----	MASK_TABLE
    53 00006698 80                  <1> _K7:    db      INS_SHIFT               ; INSERT MODE SHIFT
    54 00006699 4020100804          <1> 	db	CAPS_SHIFT,NUM_SHIFT,SCROLL_SHIFT,ALT_SHIFT,CTL_SHIFT
    55 0000669E 0201                <1> 	db	LEFT_SHIFT,RIGHT_SHIFT
    56                              <1> 
    57                              <1> ;-----	TABLES FOR CTRL CASE		;---- CHARACTERS ------
    58 000066A0 1BFF00FFFFFF        <1> _K8:	db	27,-1,0,-1,-1,-1	; Esc, 1, 2, 3, 4, 5
    59 000066A6 1EFFFFFFFF1F        <1> 	db 	30,-1,-1,-1,-1,31	; 6, 7, 8, 9, 0, -
    60                              <1> 	;db	-1,127,-1,17,23,5	; =, Bksp, Tab, Q, W, E
    61 000066AC FF7F94111705        <1> 	db	-1,127,148,17,23,5 ; 24/07/2022
    62 000066B2 12141915090F        <1> 	db	18,20,25,21,9,15	; R, T, Y, U, I, O
    63 000066B8 101B1D0AFF01        <1> 	db	16,27,29,10,-1,1	; P, [, ], Enter, Ctrl, A
    64 000066BE 13040607080A        <1> 	db	19,4,6,7,8,10		; S, D, F, G, H, J
    65 000066C4 0B0CFFFFFFFF        <1> 	db	11,12,-1,-1,-1,-1	; K, L, :, ', `, LShift
    66 000066CA 1C1A18031602        <1> 	db	28,26,24,3,22,2		; Bkslash, Z, X, C, V, B
    67 000066D0 0E0DFFFFFFFF        <1> 	db	14,13,-1,-1,-1,-1	; N, M, ,, ., /, RShift
    68 000066D6 96FF20FF            <1> 	db	150,-1,' ',-1		; *, ALT, Spc, CL
    69                              <1> 	;				;----- FUNCTIONS ------		
    70 000066DA 5E5F60616263        <1> 	db 	94,95,96,97,98,99	; F1 - F6
    71 000066E0 64656667FFFF        <1> 	db	100,101,102,103,-1,-1	; F7 - F10, NL, SL
    72 000066E6 778D848E738F        <1> 	db	119,141,132,142,115,143	; Home, Up, PgUp, -, Left, Pad5
    73 000066EC 749075917692        <1> 	db 	116,144,117,145,118,146 ; Right, +, End, Down, PgDn, Ins
    74 000066F2 93FFFFFF898A        <1> 	db	147,-1,-1,-1,137,138	; Del, SysReq, Undef, WT, F11, F12
    75                              <1> 
    76                              <1> ;-----	TABLES FOR LOWER CASE ----------
    77 000066F8 1B3132333435363738- <1> K10:	db 	27,'1234567890-=',8,9
    77 00006701 39302D3D0809        <1>
    78 00006707 71776572747975696F- <1> 	db 	'qwertyuiop[]',13,-1,'asdfghjkl;',39
    78 00006710 705B5D0DFF61736466- <1>
    78 00006719 67686A6B6C3B27      <1>
    79 00006720 60FF5C7A786376626E- <1> 	db	96,-1,92,'zxcvbnm,./',-1,'*',-1,' ',-1
    79 00006729 6D2C2E2FFF2AFF20FF  <1>
    80                              <1> ;-----	LC TABLE SCAN
    81 00006732 3B3C3D3E3F          <1> 	db	59,60,61,62,63		; BASE STATE OF F1 - F10
    82 00006737 4041424344          <1> 	db	64,65,66,67,68
    83 0000673C FFFF                <1> 	db	-1,-1			; NL, SL
    84                              <1> 
    85                              <1> ;-----	KEYPAD TABLE
    86 0000673E 474849FF4BFF        <1> K15:	db	71,72,73,-1,75,-1	; BASE STATE OF KEYPAD KEYS
    87 00006744 4DFF4F50515253      <1> 	db	77,-1,79,80,81,82,83
    88 0000674B FFFF5C8586          <1> 	db	-1,-1,92,133,134	; SysRq, Undef, WT, F11, F12
    89                              <1> 
    90                              <1> ;-----	TABLES FOR UPPER CASE ----------
    91 00006750 1B21402324255E262A- <1> K11:	db 	27,'!@#$%',94,'&*()_+',8,0
    91 00006759 28295F2B0800        <1>
    92 0000675F 51574552545955494F- <1> 	db 	'QWERTYUIOP{}',13,-1,'ASDFGHJKL:"'
    92 00006768 507B7D0DFF41534446- <1>
    92 00006771 47484A4B4C3A22      <1>
    93 00006778 7EFF7C5A584356424E- <1> 	db	126,-1,'|ZXCVBNM<>?',-1,'*',-1,' ',-1
    93 00006781 4D3C3E3FFF2AFF20FF  <1>
    94                              <1> ;-----	UC TABLE SCAN
    95 0000678A 5455565758          <1> K12:	db	84,85,86,87,88		; SHIFTED STATE OF F1 - F10
    96 0000678F 595A5B5C5D          <1> 	db	89,90,91,92,93
    97 00006794 FFFF                <1> 	db	-1,-1			; NL, SL
    98                              <1> 
    99                              <1> ;-----	NUM STATE TABLE
   100 00006796 3738392D3435362B31- <1> K14:	db 	'789-456+1230.'		; NUMLOCK STATE OF KEYPAD KEYS
   100 0000679F 3233302E            <1>
   101                              <1> 	;
   102 000067A3 FFFF7C8788          <1> 	db	-1,-1,124,135,136	; SysRq, Undef, WT, F11, F12
   103                              <1> 
   104                              <1> ; 26/08/2014
   105                              <1> ; Retro UNIX 8086 v1 - UNIX.ASM (03/03/2014)
   106                              <1> ; Derived from IBM "pc-at" 
   107                              <1> ; rombios source code (06/10/1985)
   108                              <1> ; 'dseg.inc'
   109                              <1> 
   110                              <1> ;---------------------------------------;
   111                              <1> ;	SYSTEM DATA AREA		;
   112                              <1> ;----------------------------------------
   113 000067A8 00                  <1> BIOS_BREAK	db	0		; BIT 7=1 IF BREAK KEY HAS BEEN PRESSED
   114                              <1> 
   115                              <1> ;----------------------------------------
   116                              <1> ;	KEYBOARD DATA AREAS		;
   117                              <1> ;----------------------------------------
   118                              <1> 
   119 000067A9 00                  <1> KB_FLAG		db	0		; KEYBOARD SHIFT STATE AND STATUS FLAGS
   120 000067AA 00                  <1> KB_FLAG_1	db	0		; SECOND BYTE OF KEYBOARD STATUS
   121 000067AB 00                  <1> KB_FLAG_2	db	0		; KEYBOARD LED FLAGS
   122 000067AC 00                  <1> KB_FLAG_3	db	0		; KEYBOARD MODE STATE AND TYPE FLAGS
   123 000067AD 00                  <1> ALT_INPUT	db	0		; STORAGE FOR ALTERNATE KEY PAD ENTRY
   124 000067AE [BE670000]          <1> BUFFER_START	dd	KB_BUFFER 	; OFFSET OF KEYBOARD BUFFER START
   125 000067B2 [DE670000]          <1> BUFFER_END	dd	KB_BUFFER + 32	; OFFSET OF END OF BUFFER
   126 000067B6 [BE670000]          <1> BUFFER_HEAD	dd	KB_BUFFER 	; POINTER TO HEAD OF KEYBOARD BUFFER
   127 000067BA [BE670000]          <1> BUFFER_TAIL	dd	KB_BUFFER 	; POINTER TO TAIL OF KEYBOARD BUFFER
   128                              <1> ; ------	HEAD = TAIL INDICATES THAT THE BUFFER IS EMPTY
   129 000067BE 0000<rep 10h>       <1> KB_BUFFER	times	16 dw 0		; ROOM FOR 16 SCAN CODE ENTRIES
   130                              <1> 
   131                              <1> ; /// End Of KEYBOARD DATA ///
  3422                                  %include 'vidata.s'	; VIDEO (BIOS) DATA
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.7 - vidata.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 17/10/2023 (Previous: 24/11/2020)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 16/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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 000067DE 03                  <1> CRT_MODE:	db	3	; CURRENT DISPLAY MODE (TYPE)
    29 000067DF 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 000067E0 50                  <1> CRT_COLS:	db	80	; Number of columns
    52                              <1> 
    53                              <1> ; 01/07/2016
    54 000067E1 00                  <1> CRT_PALETTE:	db 	0	; Current palette setting
    55                              <1> 
    56                              <1> ; 03/07/2016
    57 000067E2 10                  <1> CHAR_HEIGHT:	db	16	; Default character height
    58 000067E3 60                  <1> VGA_VIDEO_CTL:	db	60h	; ROM BIOS DATA AREA Offset 87h
    59 000067E4 F9                  <1> VGA_SWITCHES:	db 	0F9h	; Feature Bit Switches (the basic screen)
    60 000067E5 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 000067E6 19                  <1> VGA_ROWS:	db	25
    73                              <1> 
    74                              <1> ; 16/01/2016
    75                              <1> chr_attrib:  ; Character color/attributes for video pages (0 to 7)
    76 000067E7 0707070707070707    <1> 	db	07h, 07h, 07h, 07h, 07h, 07h, 07h, 07h
    77                              <1> ; 30/01/2016
    78                              <1> vmode:
    79 000067EF 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 000067F7 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 000067F9 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 000067FA 0302010007040506    <1> 	db 	03h, 02h, 01h, 00h, 07h, 04h, 05h, 06h
    96                              <1> vga_g_modes: ; 31/07/2016
    97 00006802 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 0000680A [6A680000]          <1> 	dd	vga_mode_03h
   104 0000680E [6A680000]          <1> 	dd	vga_mode_03h ; mode 02h -> mode 03h 
   105 00006812 [AA680000]          <1> 	dd	vga_mode_01h
   106 00006816 [AA680000]          <1> 	dd	vga_mode_01h ; mode 00h -> mode 01h
   107                              <1> 	;dd	vga_mode_07h
   108 0000681A [6A680000]          <1> 	dd	vga_mode_03h ; mode 07h -> mode 03h
   109 0000681E [EA680000]          <1> 	dd	vga_mode_04h
   110 00006822 [EA680000]          <1> 	dd	vga_mode_04h ; mode 05h -> mode 04h	
   111 00006826 [2A690000]          <1> 	dd	vga_mode_06h
   112 0000682A [6A690000]          <1> 	dd	vga_mode_13h
   113 0000682E [AA690000]          <1> 	dd	vga_mode_F0h
   114 00006832 [EA690000]          <1> 	dd	vga_mode_12h
   115 00006836 [2A6A0000]          <1> 	dd	vga_mode_6Ah
   116 0000683A [6A6A0000]          <1> 	dd	vga_mode_0Dh
   117 0000683E [AA6A0000]          <1> 	dd	vga_mode_0Eh
   118 00006842 [EA6A0000]          <1> 	dd	vga_mode_10h
   119 00006846 [2A6B0000]          <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 0000684A 0000000000020202    <1> 	db	CTEXT, CTEXT, CTEXT, CTEXT, MTEXT, CGA, CGA, CGA
   132                              <1> vga_g_memmodel: ; 31/07/2016
   133 00006852 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 0000685A 020202020001010103- <1> 	db	2, 2, 2, 2, 0, 1, 1, 1, 3, 3, 2, 2, 1, 1, 2, 2  
   139 00006863 03020201010202      <1>
   140                              <1> 						; (vgatables.h, VGAMODES, dac) 
   141                              <1> 						; 17/11/2020
   142                              <1> vga_params:
   143                              <1> 	; 23/11/2020
   144                              <1> 	; 16/11/2020
   145                              <1> 	; 09/11/2020, 10/11/2020, 11/11/2020 (TRDOS 386 v2.0.3)
   146                              <1> 	; 25/07/2016 
   147                              <1> 	; 19/07/2016
   148                              <1> 	; 03/07/2016
   149                              <1> 	; derived from 'Plex86/Bochs VGABios' source code
   150                              <1> 	; vgabios-0.7a (2011)
   151                              <1> 	; by the LGPL VGABios Developers Team (2001-2008)
   152                              <1> 	; 'vgatables.h'
   153                              <1> 	; Oracle VirtualBox 5.0.24 VGABios Source Code
   154                              <1> 	; ('vgabios.c', 'vgatables.h', 'vgafonts.h', 'vgarom.asm')
   155                              <1> 
   156                              <1> 	; 09/11/2020
   157                              <1> 	; Block Structure of Video Parameter Table
   158                              <1> 	;
   159                              <1> 	; Offset	# Bytes		Contents
   160                              <1> 	;
   161                              <1> 	;  0		1		# columns
   162                              <1> 	;  1		1  		# rows - 1 
   163                              <1> 	;  2		1		Pixels/character
   164                              <1> 	;  3-4		2		Page length		
   165                              <1> 	;  5-8		4		Sequencer Registers
   166                              <1> 	;  9		1		Miscellaneous Register	
   167                              <1> 	;  10-34	25		CRTC Registers
   168                              <1> 	;  35-54	20		Attribute Registers
   169                              <1> 	;  55-63	9		Graphics Controller Registers
   170                              <1> 	;
   171                              <1> 	; Ref: Programmer's Guide to EGA, VGA, and Super VGA cards
   172                              <1> 	; (Richard F. Ferraro, 1994)  
   173                              <1> 
   174                              <1> 	;
   175                              <1> vga_mode_03h:  ; mode 03h, 80*25 text, CGA colors
   176                              <1> 	; 11/11/2020
   177 0000686A 5018100010          <1>  	db	80, 24, 16, 00h, 10h ; tw, th-1, ch, slength (5)
   178 0000686F 00030002            <1>  	db	00h, 03h, 00h, 02h ; sequ regs (4)
   179 00006873 67                  <1>  	db	67h	; misc reg (1)
   180 00006874 5F4F50825581BF1F    <1>  	db	5Fh, 4Fh, 50h, 82h, 55h, 81h, 0BFh, 1Fh
   181                              <1>  	; 09/11/2020
   182                              <1> 	;db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh
   183 0000687C 004F                <1> 	db	00h, 4Fh
   184                              <1> vga_p_cm_pos equ $ - vga_mode_03h
   185 0000687E 0D0E00000000        <1> 	db	0Dh, 0Eh, 00h, 00h, 00h, 00h
   186 00006884 9C8E8F281F96B9A3    <1>  	db	9Ch, 8Eh, 8Fh, 28h, 1Fh, 96h, 0B9h, 0A3h
   187 0000688C FF                  <1> 	db	0FFh	; crtc_regs (25)
   188 0000688D 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   189 00006895 38393A3B3C3D3E3F    <1>  	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   190                              <1>  	; 17/10/2023
   191 0000689D 0C000F08            <1> 	db	0Ch, 00h, 0Fh, 08h  ; actl regs (20)
   192                              <1> 	;db	0Ch, 00h, 0Fh, 00h  ; 19/11/2020
   193 000068A1 0000000000100E0FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 10h, 0Eh, 0Fh, 0FFh ; grdc regs (9)
   194                              <1> 	; 09/11/2020
   195                              <1> 	;db	00h, 00h, 00h, 00h, 00h, 10h, 0Eh, 00h, 0FFh ; grdc regs (9)
   196                              <1> vga_mode_01h:	; mode 01h, 40*25 text, CGA colors
   197 000068AA 2818100008          <1> 	db	40, 24, 16, 00h, 08h ; tw, th-1, ch, slength
   198 000068AF 08030002            <1> 	db	08h, 03h, 00h, 02h  ; sequ regs
   199 000068B3 67                  <1> 	db	67h	; misc reg
   200 000068B4 2D2728902BA0BF1F    <1> 	db	2Dh, 27h, 28h, 90h, 2Bh, 0A0h, 0BFh, 1Fh
   201 000068BC 004F0D0E00000000    <1> 	db	00h, 4Fh, 0Dh, 0Eh, 00h, 00h, 00h, 00h
   202 000068C4 9C8E8F141F96B9A3    <1> 	db	9Ch, 8Eh, 8Fh, 14h, 1Fh, 96h, 0B9h, 0A3h
   203 000068CC FF                  <1> 	db	0FFh	; crtc_regs
   204 000068CD 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   205 000068D5 38393A3B3C3D3E3F    <1> 	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   206                              <1>  	;db	0Ch, 00h, 0Fh, 08h  ; actl regs (20)
   207 000068DD 0C000F00            <1> 	db	0Ch, 00h, 0Fh, 00h  ; 19/11/2020
   208 000068E1 0000000000100E0FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 10h, 0Eh, 0Fh, 0FFh ; grdc regs
   209                              <1> ;vga_mode_07h:	; mode 07h, 80*25 text, mono color
   210                              <1> ;	db	80, 24, 16, 00h, 10h  ; tw, th-1, ch, slength
   211                              <1> ;	db	00h, 03h, 00h, 02h ; sequ regs
   212                              <1> ;	db	66h	; misc reg
   213                              <1> ;	db	5Fh, 4Fh, 50h, 82h, 55h, 81h, 0BFh, 1Fh
   214                              <1> ;	db	00h, 4Fh, 0Dh, 0Eh, 00h, 00h, 00h, 00h
   215                              <1> ;	db	9Ch, 8Eh, 8Fh, 28h, 0Fh, 96h, 0B9h, 0A3h
   216                              <1> ;	db	0FFh	; crtc regs
   217                              <1> ;	db	00h, 08h, 08h, 08h, 08h, 08h, 08h, 08h
   218                              <1> ;	db	10h, 18h, 18h, 18h, 18h, 18h, 18h, 18h
   219                              <1> ;	db	0Eh, 00h, 0Fh, 08h  ; actl regs
   220                              <1> ;	db	00h, 00h, 00h, 00h, 00h, 10h, 0Ah, 0Fh, 0FFh ; grdc regs
   221                              <1> vga_mode_04h:	; 320*200 graphics, 4 colors, CGA
   222                              <1> 	; 11/11/2020
   223 000068EA 2818080040          <1> 	db	40, 24, 8, 00h, 40h ; tw, th-1, ch, slength
   224 000068EF 09030002            <1> 	db	09h, 03h, 00h, 02h ; sequ regs
   225 000068F3 63                  <1> 	db	63h	; misc reg
   226 000068F4 2D2728902B80BF1F    <1> 	db	2Dh, 27h, 28h, 90h, 2Bh, 80h, 0BFh, 1Fh
   227 000068FC 00C1000000000000    <1> 	db	00h, 0C1h, 00h, 00h, 00h, 00h, 00h, 00h
   228 00006904 9C8E8F140096B9A2    <1> 	db	9Ch, 8Eh, 8Fh, 14h, 00h, 96h, 0B9h, 0A2h
   229 0000690C FF                  <1> 	db	0FFh	; crtc_regs
   230 0000690D 0013151702040607    <1> 	db	00h, 13h, 15h, 17h, 02h, 04h, 06h, 07h
   231 00006915 1011121314151617    <1> 	db	10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h
   232 0000691D 01000300            <1> 	db	01h, 00h, 03h, 00h ; actl regs
   233 00006921 0000000000300F0FFF  <1> 	db 	00h, 00h, 00h, 00h, 00h, 30h, 0Fh, 0Fh, 0FFh ; grdc regs
   234                              <1> vga_mode_06h:	; 640*200 graphics, 2 colors, CGA
   235                              <1> 	; 11/11/2020
   236 0000692A 5018080040          <1> 	db	80, 24, 8, 00h, 40h   ;	tw, th-1, ch, slength
   237 0000692F 01010006            <1> 	db	01h, 01h, 00h, 06h ; sequ regs
   238 00006933 63                  <1> 	db	63h	; misc reg
   239 00006934 5F4F50825480BF1F    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh
   240 0000693C 00C1000000000000    <1> 	db	00h, 0C1h, 00h, 00h, 00h, 00h, 00h, 00h
   241 00006944 9C8E8F280096B9C2    <1> 	db	9Ch, 8Eh, 8Fh, 28h, 00h, 96h, 0B9h, 0C2h
   242 0000694C FF                  <1> 	db	0FFh	; crtc regs
   243 0000694D 0017171717171717    <1> 	db	00h, 17h, 17h, 17h, 17h, 17h, 17h, 17h
   244 00006955 1717171717171717    <1> 	db	17h, 17h, 17h, 17h, 17h, 17h, 17h, 17h
   245 0000695D 01000100            <1> 	db	01h, 00h, 01, 00h  ; actl regs
   246 00006961 0000000000000D0FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 00h, 0Dh, 0Fh, 0FFh ; grdc regs
   247                              <1> vga_mode_13h:  ; mode 13h, 300*200, 256 colors, linear
   248                              <1> 	; 11/11/2020
   249                              <1> 	;db 	40, 24, 8, 00h, 20h ; tw, th-1, ch, slength (5)
   250                              <1> 	; 23/11/2020 - 10/11/2020
   251 0000696A 28180800FA          <1> 	db 	40, 24, 8, 00h, 0FAh ; tw, th-1, ch, slength (5)
   252 0000696F 010F000E            <1> 	db	01h, 0Fh, 00h, 0Eh ; sequ regs (4)
   253 00006973 63                  <1> 	db	63h	; misc reg (1)
   254 00006974 5F4F50825480BF1F    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh 
   255 0000697C 0041000000000000    <1> 	db 	00h, 041h, 00h, 00h, 00h, 00h, 00h, 00h
   256 00006984 9C8E8F284096B9A3    <1> 	db	9Ch, 8Eh, 8Fh, 28h, 40h, 96h, 0B9h, 0A3h
   257                              <1> 	;db	9Ch, 0Eh, 8Fh, 28h, 40h, 96h, 0B9h, 0A3h ; 17/10/2023
   258 0000698C FF                  <1> 	db	0FFh	; crtc regs (25)
   259 0000698D 0001020304050607    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
   260 00006995 08090A0B0C0D0E0F    <1>  	db	08h, 09h, 0Ah, 0Bh, 0Ch, 0Dh, 0Eh, 0Fh
   261 0000699D 41000F00            <1>  	db	41h, 00h, 0Fh, 00h  ; actl regs (20)
   262                              <1> 	; 10/11/2020
   263                              <1>  	;db	41h, 01h, 0Fh, 13h  ; actl regs (20) 
   264 000069A1 000000000040050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 40h, 05h, 0Fh, 0FFh ; grdc regs (9)
   265                              <1> vga_mode_setl equ $ - vga_mode_13h  ; = 64
   266                              <1> vga_mode_F0h:  ; mode X ; 320*240, 256 colors, planar
   267 000069AA 2818080000          <1> 	db 	40, 24, 8, 00h, 00h ; tw, th-1, ch, slength
   268 000069AF 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   269 000069B3 E3                  <1> 	db	0E3h	; misc reg
   270 000069B4 5F4F508254800D3E    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0Dh, 3Eh 
   271 000069BC 0041000000000000    <1>  	db 	00h, 41h, 00h, 00h, 00h, 00h, 00h, 00h
   272 000069C4 EAACDF2800E706E3    <1> 	db	0EAh, 0ACh, 0DFh, 28h, 00h, 0E7h, 06h, 0E3h
   273 000069CC FF                  <1> 	db	0FFh	; crtc regs (25)
   274 000069CD 0001020304050607    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
   275 000069D5 08090A0B0C0D0E0F    <1>  	db	08h, 09h, 0Ah, 0Bh, 0Ch, 0Dh, 0Eh, 0Fh
   276 000069DD 41000F00            <1>  	db	41h, 00h, 0Fh, 00h  ; actl regs
   277 000069E1 000000000040050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 40h, 05h, 0Fh, 0FFh ; grdc regs
   278                              <1> vga_mode_12h:  ; mode 12h, 640*480, 16 colors, planar
   279                              <1> 	; 11/11/2020
   280                              <1>  	;db 	80, 29, 16, 0, 0 ; tw, th-1, ch, slength
   281                              <1> 	; 09/11/2020
   282 000069EA 501D1000A0          <1>  	db 	80, 29, 16, 00h, 0A0h ; tw, th-1, ch, slength
   283 000069EF 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   284 000069F3 E3                  <1> 	db 	0E3h	; misc reg
   285 000069F4 5F4F508254800B3E    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0Bh, 3Eh
   286                              <1> 	; 09/11/2020
   287                              <1> 	;db	5Fh, 4Fh, 50h, 82h, 53h, 9Fh, 0Bh, 3Eh
   288 000069FC 0040000000000000    <1> 	db	00h, 40h, 00h, 00h, 00h, 00h, 00h, 00h
   289 00006A04 EA8CDF2800E704E3    <1>  	db	0EAh, 8Ch, 0DFh, 28h, 00h, 0E7h, 04h, 0E3h
   290                              <1> 	; 09/11/2020
   291                              <1>  	;db	0E9h, 8Bh, 0DFh, 28h, 00h, 0E7h, 04h, 0E3h
   292 00006A0C FF                  <1> 	db	0FFh	; crtc regs
   293 00006A0D 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   294 00006A15 38393A3B3C3D3E3F    <1> 	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   295 00006A1D 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   296 00006A21 000000000000050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
   297                              <1> vga_mode_6Ah:  ; mode 6Ah, 800*600, 16 colors, planar
   298                              <1> 	; 11/11/2020
   299 00006A2A 6424100000          <1>  	db 	100, 36, 16, 00h, 00h ; tw, th-1, ch, slength
   300 00006A2F 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   301 00006A33 E3                  <1> 	db 	0E3h	; misc reg
   302 00006A34 7F6363836B1B72F0    <1> 	db	7Fh, 63h, 63h, 83h, 6Bh, 1Bh, 72h, 0F0h
   303 00006A3C 0060000000000000    <1> 	db	00h, 60h, 00h, 00h, 00h, 00h, 00h, 00h
   304 00006A44 598D5732005773E3    <1>  	db	59h, 8Dh, 57h, 32h, 00h, 57h, 73h, 0E3h
   305 00006A4C FF                  <1> 	db	0FFh	; crtc regs
   306 00006A4D 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   307 00006A55 38393A3B3C3D3E3F    <1> 	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   308 00006A5D 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   309 00006A61 000000000000050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
   310                              <1> vga_mode_0Dh:  ; mode 0Dh, 320*200, 16 colors, planar
   311 00006A6A 2818080020          <1>  	db 	40, 24, 8, 00h, 20h ; tw, th-1, ch, slength
   312 00006A6F 090F0006            <1> 	db	09h, 0Fh, 00h, 06h ; sequ regs
   313 00006A73 63                  <1> 	db 	63h	; misc reg
   314 00006A74 2D2728902B80BF1F    <1> 	db	2Dh, 27h, 28h, 90h, 2Bh, 80h, 0BFh, 1Fh
   315 00006A7C 00C0000000000000    <1> 	db	00h, 0C0h, 00h, 00h, 00h, 00h, 00h, 00h
   316 00006A84 9C8E8F140096B9E3    <1>  	db	9Ch, 8Eh, 8Fh, 14h, 00h, 96h, 0B9h, 0E3h
   317 00006A8C FF                  <1> 	db	0FFh	; crtc regs
   318 00006A8D 0001020304050607    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
   319 00006A95 1011121314151617    <1> 	db	10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h
   320 00006A9D 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   321 00006AA1 000000000000050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
   322                              <1> vga_mode_0Eh:  ; mode 0Eh, 640*200, 16 colors, planar
   323 00006AAA 5018080040          <1>  	db 	80, 24, 8, 00h, 40h ; tw, th-1, ch, slength
   324 00006AAF 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   325 00006AB3 63                  <1> 	db 	63h	; misc reg
   326 00006AB4 5F4F50825480BF1F    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh
   327 00006ABC 00C0000000000000    <1> 	db	00h, 0C0h, 00h, 00h, 00h, 00h, 00h, 00h
   328 00006AC4 9C8E8F280096B9E3    <1>  	db	9Ch, 8Eh, 8Fh, 28h, 00h, 96h, 0B9h, 0E3h
   329 00006ACC FF                  <1> 	db	0FFh	; crtc regs
   330 00006ACD 0001020304050607    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h
   331 00006AD5 1011121314151617    <1> 	db	10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h
   332 00006ADD 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   333 00006AE1 000000000000050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
   334                              <1> vga_mode_10h: ; mode 10h, 640*350, 16 colors, planar
   335 00006AEA 50180E0080          <1>  	db 	80, 24, 14, 00h, 80h ; tw, th-1, ch, slength
   336 00006AEF 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   337 00006AF3 A3                  <1> 	db 	0A3h	; misc reg
   338 00006AF4 5F4F50825480BF1F    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0BFh, 1Fh
   339 00006AFC 0040000000000000    <1> 	db	00h, 40h, 00h, 00h, 00h, 00h, 00h, 00h
   340 00006B04 83855D280F63BAE3    <1>  	db	83h, 85h, 5Dh, 28h, 0Fh, 63h, 0BAh, 0E3h
   341 00006B0C FF                  <1> 	db	0FFh	; crtc regs
   342 00006B0D 0001020304051407    <1> 	db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h
   343 00006B15 38393A3B3C3D3E3F    <1> 	db	38h, 39h, 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh
   344 00006B1D 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   345 00006B21 000000000000050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
   346                              <1> vga_mode_11h: ; mode 11h, 640*480, mono color, planar
   347                              <1>  	; 11/11/2020
   348 00006B2A 501D1000A0          <1> 	db 	80, 29, 16, 00h, 0A0h ; tw, th-1, ch, slength
   349 00006B2F 010F0006            <1> 	db	01h, 0Fh, 00h, 06h ; sequ regs
   350 00006B33 E3                  <1> 	db 	0E3h	; misc reg
   351 00006B34 5F4F508254800B3E    <1> 	db	5Fh, 4Fh, 50h, 82h, 54h, 80h, 0Bh, 3Eh
   352 00006B3C 0040000000000000    <1> 	db	00h, 40h, 00h, 00h, 00h, 00h, 00h, 00h
   353 00006B44 EA8CDF2800E704C3    <1>  	db	0EAh, 8Ch, 0DFh, 28h, 00h, 0E7h, 04h, 0C3h ; 11/11/2020
   354 00006B4C FF                  <1> 	db	0FFh	; crtc regs
   355 00006B4D 003F003F003F003F    <1> 	db	00h, 3Fh, 00h, 3Fh, 00h, 3Fh, 00h, 3Fh
   356 00006B55 003F003F003F003F    <1> 	db	00h, 3Fh, 00h, 3Fh, 00h, 3Fh, 00h, 3Fh
   357 00006B5D 01000F00            <1> 	db	01h, 00h, 0Fh, 00h  ; actl regs
   358 00006B61 000000000000050FFF  <1> 	db	00h, 00h, 00h, 00h, 00h, 00h, 05h, 0Fh, 0FFh ; grdc regs
   359                              <1> end_of_vga_params:
   360                              <1> 
   361                              <1> ; /// End Of VIDEO DATA ///
   362                              <1> 
   363                              <1> ; 23/11/2020
   364                              <1> ; VBE 2 BOCHS/QEMU emulator extensions 
   365                              <1> ;	for TRDOS 386 v2 kernel (video bios)  
   366                              <1> 
   367                              <1> ; vbetables.h by Volker Rupper (02/01/2020)
   368                              <1> 
   369                              <1> b_vbe_modes:
   370                              <1> 	;/* standard VESA modes */	
   371 00006B6A 0001800290010800    <1> 	dw 100h,  640, 400,  8
   372 00006B72 01018002E0010800    <1> 	dw 101h,  640, 480,  8
   373 00006B7A 0301200358020800    <1> 	dw 103h,  800, 600,  8
   374 00006B82 0501000400030800    <1> 	dw 105h, 1024, 768,  8
   375 00006B8A 0E014001C8001000    <1> 	dw 10Eh,  320, 200, 16
   376 00006B92 0F014001C8001800    <1> 	dw 10Fh,  320, 200, 24
   377 00006B9A 11018002E0011000    <1> 	dw 111h,  640, 480, 16
   378 00006BA2 12018002E0011800    <1> 	dw 112h,  640, 480, 24
   379 00006BAA 1401200358021000    <1> 	dw 114h,  800, 600, 16
   380 00006BB2 1501200358021800    <1> 	dw 115h,  800, 600, 24
   381 00006BBA 1701000400031000    <1> 	dw 117h, 1024, 768, 16
   382 00006BC2 1801000400031800    <1> 	dw 118h, 1024, 768, 24
   383                              <1> 
   384                              <1> ;/* BOCHS/PLEX86 'own' mode numbers */
   385 00006BCA 40014001C8002000    <1> 	dw 140h,  320,  200, 32
   386 00006BD2 4101800290012000    <1> 	dw 141h,  640,  400, 32
   387 00006BDA 42018002E0012000    <1> 	dw 142h,  640,  480, 32
   388 00006BE2 4301200358022000    <1> 	dw 143h,  800,  600, 32
   389 00006BEA 4401000400032000    <1> 	dw 144h, 1024,  768, 32
   390 00006BF2 46014001C8000800    <1> 	dw 146h,  320,  200,  8
   391 00006BFA 8D010005D0021000    <1> 	dw 18Dh, 1280,  720, 16
   392 00006C02 8E010005D0021800    <1> 	dw 18Eh, 1280,  720, 24
   393 00006C0A 8F010005D0022000    <1> 	dw 18Fh, 1280,  720, 32
   394 00006C12 9001800738041000    <1> 	dw 190h, 1920, 1080, 16
   395 00006C1A 9101800738041800    <1> 	dw 191h, 1920, 1080, 24
   396 00006C22 9201800738042000    <1> 	dw 192h, 1920, 1080, 32
   397                              <1> 
   398                              <1> end_of_b_vbe_modes:
   399                              <1> 
   400                              <1> MA1 equ VBE_MODE_ATTRIBUTE_SUPPORTED
   401                              <1> MA2 equ VBE_MODE_ATTRIBUTE_EXTENDED_INFO_AVAILABLE
   402                              <1> MA3 equ VBE_MODE_ATTRIBUTE_COLOR_MODE
   403                              <1> MA4 equ VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE
   404                              <1> MA5 equ	VBE_MODE_ATTRIBUTE_GRAPHICS_MODE
   405                              <1> 
   406                              <1> MODE_ATTRIBUTES equ MA1|MA2|MA3|MA4|MA5
   407                              <1> 
   408                              <1> WA1 equ VBE_WINDOW_ATTRIBUTE_RELOCATABLE
   409                              <1> WA2 equ	VBE_WINDOW_ATTRIBUTE_READABLE
   410                              <1> WA3 equ VBE_WINDOW_ATTRIBUTE_WRITEABLE
   411                              <1> 
   412                              <1> WINA_ATTRIBUTES equ WA1|WA2|WA3
   413                              <1> 
   414                              <1> ; 24/11/2020
   415                              <1> 
   416                              <1> %if 0
   417                              <1> 
   418                              <1> MODE_INFO_LIST: 
   419                              <1> 
   420                              <1> ; 24/11/2020
   421                              <1> ; '%if 0' disables 24 mode info tables here, until %endif 
   422                              <1> ; ('set_mode_info_list' will set only 1 list for selected mode)
   423                              <1> ; (Purpose: To save about 1 KB kernel size by removing fixed data)
   424                              <1> 
   425                              <1> 			dw	0100h ; 640x400x8 
   426                              <1> ModeAttributes1: 	dw	MODE_ATTRIBUTES
   427                              <1> WinAAttributes1: 	db	WINA_ATTRIBUTES
   428                              <1> WinBAttributes1: 	db	0
   429                              <1> WinGranularity1: 	dw	VBE_DISPI_BANK_SIZE_KB
   430                              <1> WinSize1: 		dw	VBE_DISPI_BANK_SIZE_KB
   431                              <1> WinASegment1:		dw	VGAMEM_GRAPH
   432                              <1> WinBSegment1:		dw	0000h
   433                              <1> WinFuncPtr1:		dd	0
   434                              <1> BytesPerScanLine1: 	dw	640
   435                              <1> XResolution1:		dw	640
   436                              <1> YResolution1:		dw	400
   437                              <1> XCharSize1:		db	8
   438                              <1> YCharSize1:		db	16
   439                              <1> NumberOfPlanes1: 	db	1
   440                              <1> BitsPerPixel1:		db	8
   441                              <1> NumberOfBanks1:		db	4
   442                              <1> MemoryModel1:		db	VBE_MEMORYMODEL_PACKED_PIXEL
   443                              <1> BankSize1:		db	0
   444                              <1> NumberOfImagePages1: 	db	64
   445                              <1> Reserved_page1:		db	0
   446                              <1> RedMaskSize1:		db	0
   447                              <1> RedFieldPosition1: 	db	0
   448                              <1> GreenMaskSize1:		db	0
   449                              <1> GreenFieldPosition1: 	db	0
   450                              <1> BlueMaskSize1:		db	0
   451                              <1> BlueFieldPosition1: 	db	0
   452                              <1> RsvdMaskSize1: 		db	0
   453                              <1> RsvdFieldPosition1: 	db	0
   454                              <1> DirectColorModeInfo1: 	db	0
   455                              <1> PhysBasePtr1:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
   456                              <1> OffScreenMemOffset1: 	dd	0
   457                              <1> OffScreenMemSize1: 	dw	0
   458                              <1> LinBytesPerScanLine1: 	dw	640
   459                              <1> BnkNumberOfPages1: 	db	0
   460                              <1> LinNumberOfPages1: 	db	0
   461                              <1> LinRedMaskSize1:	db	0
   462                              <1> LinRedFieldPosition1: 	db	0
   463                              <1> LinGreenMaskSize1: 	db	0
   464                              <1> LinGreenFieldPosition1: db	0
   465                              <1> LinBlueMaskSize1: 	db	0
   466                              <1> LinBlueFieldPosition1: 	db	0
   467                              <1> LinRsvdMaskSize1: 	db	0
   468                              <1> LinRsvdFieldPosition1: 	db	0
   469                              <1> MaxPixelClock1:		dd	0
   470                              <1> 
   471                              <1> 			dw	0101h ; 640x480x8
   472                              <1> ModeAttributes2: 	dw	MODE_ATTRIBUTES
   473                              <1> WinAAttributes2: 	db	WINA_ATTRIBUTES
   474                              <1> WinBAttributes2: 	db	0
   475                              <1> WinGranularity2: 	dw	VBE_DISPI_BANK_SIZE_KB
   476                              <1> WinSize2: 		dw	VBE_DISPI_BANK_SIZE_KB
   477                              <1> WinASegment2:		dw	VGAMEM_GRAPH
   478                              <1> WinBSegment2:		dw	0000h
   479                              <1> WinFuncPtr2:		dd	0
   480                              <1> BytesPerScanLine2:	dw	640
   481                              <1> XResolution2:		dw	640
   482                              <1> YResolution2:		dw	480
   483                              <1> XCharSize2:		db	8
   484                              <1> YCharSize2:		db	16
   485                              <1> NumberOfPlanes2:	db	1
   486                              <1> BitsPerPixel2:		db	8
   487                              <1> NumberOfBanks2:		db	5
   488                              <1> MemoryModel2:		db	VBE_MEMORYMODEL_PACKED_PIXEL
   489                              <1> BankSize2:		db	0
   490                              <1> NumberOfImagePages2:	db	53
   491                              <1> Reserved_page2:		db	0
   492                              <1> RedMaskSize2:		db	0
   493                              <1> RedFieldPosition2:	db	0
   494                              <1> GreenMaskSize2:		db	0
   495                              <1> GreenFieldPosition2:	db	0
   496                              <1> BlueMaskSize2:		db	0
   497                              <1> BlueFieldPosition2:	db	0
   498                              <1> RsvdMaskSize2:		db	0
   499                              <1> RsvdFieldPosition2:	db	0
   500                              <1> DirectColorModeInfo2:	db	0
   501                              <1> PhysBasePtr2:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
   502                              <1> OffScreenMemOffset2:	dd	0
   503                              <1> OffScreenMemSize2:	dw	0
   504                              <1> LinBytesPerScanLine2:	dw	640
   505                              <1> BnkNumberOfPages2: 	db	0
   506                              <1> LinNumberOfPages2: 	db	0
   507                              <1> LinRedMaskSize2:	db	0
   508                              <1> LinRedFieldPosition2: 	db	0
   509                              <1> LinGreenMaskSize2: 	db	0
   510                              <1> LinGreenFieldPosition2: db	0
   511                              <1> LinBlueMaskSize2: 	db	0
   512                              <1> LinBlueFieldPosition2: 	db	0
   513                              <1> LinRsvdMaskSize2: 	db	0
   514                              <1> LinRsvdFieldPosition2: 	db	0
   515                              <1> MaxPixelClock2:		dd	0
   516                              <1> 			
   517                              <1> 			dw	0103h ; 800x600x8
   518                              <1> ModeAttributes3: 	dw	MODE_ATTRIBUTES
   519                              <1> WinAAttributes3: 	db	WINA_ATTRIBUTES
   520                              <1> WinBAttributes3: 	db	0
   521                              <1> WinGranularity3: 	dw	VBE_DISPI_BANK_SIZE_KB
   522                              <1> WinSize3: 		dw	VBE_DISPI_BANK_SIZE_KB
   523                              <1> WinASegment3:		dw	VGAMEM_GRAPH
   524                              <1> WinBSegment3:		dw	0000h
   525                              <1> WinFuncPtr3:		dd	0
   526                              <1> BytesPerScanLine3:	dw	800
   527                              <1> XResolution3:		dw	800
   528                              <1> YResolution3:		dw	600
   529                              <1> XCharSize3:		db	8
   530                              <1> YCharSize3:		db	16
   531                              <1> NumberOfPlanes3:	db	1
   532                              <1> BitsPerPixel3:		db	8
   533                              <1> NumberOfBanks3:		db	8
   534                              <1> MemoryModel3:		db	VBE_MEMORYMODEL_PACKED_PIXEL
   535                              <1> BankSize3:		db	0
   536                              <1> NumberOfImagePages3:	db	33
   537                              <1> Reserved_page3:		db	0
   538                              <1> RedMaskSize3:		db	0
   539                              <1> RedFieldPosition3:	db	0
   540                              <1> GreenMaskSize3:		db	0
   541                              <1> GreenFieldPosition3:	db	0
   542                              <1> BlueMaskSize3:		db	0
   543                              <1> BlueFieldPosition3:	db	0
   544                              <1> RsvdMaskSize3:		db	0
   545                              <1> RsvdFieldPosition3:	db	0
   546                              <1> DirectColorModeInfo3:	db	0
   547                              <1> PhysBasePtr3:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
   548                              <1> OffScreenMemOffset3:	dd	0
   549                              <1> OffScreenMemSize3:	dw	0
   550                              <1> LinBytesPerScanLine3:	dw	800
   551                              <1> BnkNumberOfPages3: 	db	0
   552                              <1> LinNumberOfPages3: 	db	0
   553                              <1> LinRedMaskSize3:	db	0
   554                              <1> LinRedFieldPosition3: 	db	0
   555                              <1> LinGreenMaskSize3: 	db	0
   556                              <1> LinGreenFieldPosition: 	db	0
   557                              <1> LinBlueMaskSize: 	db	0
   558                              <1> LinBlueFieldPosition: 	db	0
   559                              <1> LinRsvdMaskSize: 	db	0
   560                              <1> LinRsvdFieldPosition: 	db	0
   561                              <1> MaxPixelClock:		dd	0
   562                              <1> 			
   563                              <1> 			dw	0105h ; 1024x768x8
   564                              <1> ModeAttributes4: 	dw	MODE_ATTRIBUTES
   565                              <1> WinAAttributes4: 	db	WINA_ATTRIBUTES
   566                              <1> WinBAttributes4: 	db	0
   567                              <1> WinGranularity4: 	dw	VBE_DISPI_BANK_SIZE_KB
   568                              <1> WinSize4: 		dw	VBE_DISPI_BANK_SIZE_KB
   569                              <1> WinASegment4:		dw	VGAMEM_GRAPH
   570                              <1> WinBSegment4:		dw	0000h
   571                              <1> WinFuncPtr4:		dd	0
   572                              <1> BytesPerScanLine4:	dw	1024
   573                              <1> XResolution4:		dw	1024
   574                              <1> YResolution4:		dw	768
   575                              <1> XCharSize4:		db	8
   576                              <1> YCharSize4:		db	16
   577                              <1> NumberOfPlanes4:	db	1
   578                              <1> BitsPerPixel4:		db	8
   579                              <1> NumberOfBanks4:		db	12
   580                              <1> MemoryModel4:		db	VBE_MEMORYMODEL_PACKED_PIXEL
   581                              <1> BankSize4:		db	0
   582                              <1> NumberOfImagePages4:	db	20
   583                              <1> Reserved_page4:		db	0
   584                              <1> RedMaskSize4:		db	0
   585                              <1> RedFieldPosition4:	db	0
   586                              <1> GreenMaskSize4:		db	0
   587                              <1> GreenFieldPosition4:	db	0
   588                              <1> BlueMaskSize4:		db	0
   589                              <1> BlueFieldPosition4:	db	0
   590                              <1> RsvdMaskSize4:		db	0
   591                              <1> RsvdFieldPosition4:	db	0
   592                              <1> DirectColorModeInfo4:	db	0
   593                              <1> PhysBasePtr4:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
   594                              <1> OffScreenMemOffset4:	dd	0
   595                              <1> OffScreenMemSize4:	dw	0
   596                              <1> LinBytesPerScanLine4:	dw	1024
   597                              <1> BnkNumberOfPages4: 	db	0
   598                              <1> LinNumberOfPages4: 	db	0
   599                              <1> LinRedMaskSize4:	db	0
   600                              <1> LinRedFieldPosition4: 	db	0
   601                              <1> LinGreenMaskSize4: 	db	0
   602                              <1> LinGreenFieldPosition4: db	0
   603                              <1> LinBlueMaskSize4: 	db	0
   604                              <1> LinBlueFieldPosition4: 	db	0
   605                              <1> LinRsvdMaskSize4: 	db	0
   606                              <1> LinRsvdFieldPosition4: 	db	0
   607                              <1> MaxPixelClock4:		dd	0
   608                              <1> 
   609                              <1> 			dw	010Eh ; 320x200x16
   610                              <1> ModeAttributes5: 	dw	MODE_ATTRIBUTES
   611                              <1> WinAAttributes5: 	db	WINA_ATTRIBUTES
   612                              <1> WinBAttributes5: 	db	0
   613                              <1> WinGranularity5: 	dw	VBE_DISPI_BANK_SIZE_KB
   614                              <1> WinSize5: 		dw	VBE_DISPI_BANK_SIZE_KB
   615                              <1> WinASegment5:		dw	VGAMEM_GRAPH
   616                              <1> WinBSegment5:		dw	0000h
   617                              <1> WinFuncPtr5:		dd	0
   618                              <1> BytesPerScanLine5:	dw	640
   619                              <1> XResolution5:		dw	320
   620                              <1> YResolution5:		dw	200
   621                              <1> XCharSize5:		db	8
   622                              <1> YCharSize5:		db	16
   623                              <1> NumberOfPlanes5:	db	1
   624                              <1> BitsPerPixel5:		db	16
   625                              <1> NumberOfBanks5:		db	2
   626                              <1> MemoryModel5:		db	VBE_MEMORYMODEL_DIRECT_COLOR
   627                              <1> BankSize5:		db	0
   628                              <1> NumberOfImagePages5:	db	130
   629                              <1> Reserved_page5:		db	0
   630                              <1> RedMaskSize5:		db	5
   631                              <1> RedFieldPosition5:	db	11
   632                              <1> GreenMaskSize5:		db	6
   633                              <1> GreenFieldPosition5:	db	5
   634                              <1> BlueMaskSize5:		db	5
   635                              <1> BlueFieldPosition5:	db	0
   636                              <1> RsvdMaskSize5:		db	0
   637                              <1> RsvdFieldPosition5:	db	0
   638                              <1> DirectColorModeInfo5:	db	0
   639                              <1> PhysBasePtr5:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
   640                              <1> OffScreenMemOffset5:	dd	0
   641                              <1> OffScreenMemSize5:	dw	0
   642                              <1> LinBytesPerScanLine5:	dw	640
   643                              <1> BnkNumberOfPages5: 	db	0
   644                              <1> LinNumberOfPages5: 	db	0
   645                              <1> LinRedMaskSize5:	db	5
   646                              <1> LinRedFieldPosition5:	db	11
   647                              <1> LinGreenMaskSize5:	db	6
   648                              <1> LinGreenFieldPosition5:	db	5
   649                              <1> LinBlueMaskSize5:	db	5
   650                              <1> LinBlueFieldPosition5:	db	0
   651                              <1> LinRsvdMaskSize5:	db	0
   652                              <1> LinRsvdFieldPosition5:	db	0
   653                              <1> MaxPixelClock5:		dd	0
   654                              <1> 	
   655                              <1> 			dw	010Fh ; 320x200x24
   656                              <1> ModeAttributes6: 	dw	MODE_ATTRIBUTES
   657                              <1> WinAAttributes6: 	db	WINA_ATTRIBUTES
   658                              <1> WinBAttributes6: 	db	0
   659                              <1> WinGranularity6: 	dw	VBE_DISPI_BANK_SIZE_KB
   660                              <1> WinSize6: 		dw	VBE_DISPI_BANK_SIZE_KB
   661                              <1> WinASegment6:		dw	VGAMEM_GRAPH
   662                              <1> WinBSegment6:		dw	0000h
   663                              <1> WinFuncPtr6:		dd	0
   664                              <1> BytesPerScanLine6:	dw	960
   665                              <1> XResolution6:		dw	320
   666                              <1> YResolution6:		dw	200
   667                              <1> XCharSize6:		db	8
   668                              <1> YCharSize6:		db	16
   669                              <1> NumberOfPlanes6:	db	1
   670                              <1> BitsPerPixel6:		db	24
   671                              <1> NumberOfBanks6:		db	3
   672                              <1> MemoryModel6:		db	VBE_MEMORYMODEL_DIRECT_COLOR
   673                              <1> BankSize6:		db	0
   674                              <1> NumberOfImagePages6:	db	86
   675                              <1> Reserved_page6:		db	0
   676                              <1> RedMaskSize6:		db	8
   677                              <1> RedFieldPosition6:	db	16
   678                              <1> GreenMaskSize6:		db	8
   679                              <1> GreenFieldPosition6:	db	8
   680                              <1> BlueMaskSize6:		db	8
   681                              <1> BlueFieldPosition6:	db	0
   682                              <1> RsvdMaskSize6:		db	0
   683                              <1> RsvdFieldPosition6:	db	0
   684                              <1> DirectColorModeInfo6:	db	0
   685                              <1> PhysBasePtr6:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
   686                              <1> OffScreenMemOffset6:	dd	0
   687                              <1> OffScreenMemSize6:	dw	0
   688                              <1> LinBytesPerScanLine6:	dw	960
   689                              <1> BnkNumberOfPages6: 	db	0
   690                              <1> LinNumberOfPages6: 	db	0
   691                              <1> LinRedMaskSize6:	db	8
   692                              <1> LinRedFieldPosition6:	db	16
   693                              <1> LinGreenMaskSize6:	db	8
   694                              <1> LinGreenFieldPosition6:	db	8
   695                              <1> LinBlueMaskSize6:	db	8
   696                              <1> LinBlueFieldPosition6:	db	0
   697                              <1> LinRsvdMaskSize6:	db	0
   698                              <1> LinRsvdFieldPosition6:	db	0
   699                              <1> MaxPixelClock6:		dd	0
   700                              <1> 	
   701                              <1> 			dw	0111h ; 640x480x16
   702                              <1> ModeAttributes7: 	dw	MODE_ATTRIBUTES
   703                              <1> WinAAttributes7: 	db	WINA_ATTRIBUTES
   704                              <1> WinBAttributes7: 	db	0
   705                              <1> WinGranularity7: 	dw	VBE_DISPI_BANK_SIZE_KB
   706                              <1> WinSize7: 		dw	VBE_DISPI_BANK_SIZE_KB
   707                              <1> WinASegment7:		dw	VGAMEM_GRAPH
   708                              <1> WinBSegment7:		dw	0000h
   709                              <1> WinFuncPtr7:		dd	0
   710                              <1> BytesPerScanLine7:	dw	1280
   711                              <1> XResolution7:		dw	640
   712                              <1> YResolution7:		dw	480
   713                              <1> XCharSize7:		db	8
   714                              <1> YCharSize7:		db	16
   715                              <1> NumberOfPlanes7:	db	1
   716                              <1> BitsPerPixel7:		db	16
   717                              <1> NumberOfBanks7:		db	10
   718                              <1> MemoryModel7:		db	VBE_MEMORYMODEL_DIRECT_COLOR
   719                              <1> BankSize7:		db	0
   720                              <1> NumberOfImagePages7:	db	26
   721                              <1> Reserved_page7:		db	0
   722                              <1> RedMaskSize7:		db	5
   723                              <1> RedFieldPosition7:	db	11
   724                              <1> GreenMaskSize7:		db	6
   725                              <1> GreenFieldPosition7:	db	5
   726                              <1> BlueMaskSize7:		db	5
   727                              <1> BlueFieldPosition7:	db	0
   728                              <1> RsvdMaskSize7:		db	0
   729                              <1> RsvdFieldPosition7:	db	0
   730                              <1> DirectColorModeInfo7:	db	0
   731                              <1> PhysBasePtr7:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS,
   732                              <1> OffScreenMemOffset7:	dd	0
   733                              <1> OffScreenMemSize7:	dw	0
   734                              <1> LinBytesPerScanLine7:	dw	1280
   735                              <1> BnkNumberOfPages7: 	db	0
   736                              <1> LinNumberOfPages7: 	db	0
   737                              <1> LinRedMaskSize7:	db	5
   738                              <1> LinRedFieldPosition7:	db	11
   739                              <1> LinGreenMaskSize7:	db	6
   740                              <1> LinGreenFieldPosition7:	db	5
   741                              <1> LinBlueMaskSize7:	db	5
   742                              <1> LinBlueFieldPosition7:	db	0
   743                              <1> LinRsvdMaskSize7:	db	0
   744                              <1> LinRsvdFieldPosition7:	db	0
   745                              <1> MaxPixelClock7:		dd	0
   746                              <1> 
   747                              <1> 			dw	0112h ; 640x480x24
   748                              <1> ModeAttributes8: 	dw	MODE_ATTRIBUTES
   749                              <1> WinAAttributes8: 	db	WINA_ATTRIBUTES
   750                              <1> WinBAttributes8: 	db	0
   751                              <1> WinGranularity8: 	dw	VBE_DISPI_BANK_SIZE_KB
   752                              <1> WinSize8: 		dw	VBE_DISPI_BANK_SIZE_KB
   753                              <1> WinASegment8:		dw	VGAMEM_GRAPH
   754                              <1> WinBSegment8:		dw	0000h
   755                              <1> WinFuncPtr8:		dd	0
   756                              <1> BytesPerScanLine8:	dw	1920
   757                              <1> XResolution8:		dw	640
   758                              <1> YResolution8:		dw	480
   759                              <1> XCharSize8:		db	8
   760                              <1> YCharSize8:		db	16
   761                              <1> NumberOfPlanes8:	db	1
   762                              <1> BitsPerPixel8:		db	24
   763                              <1> NumberOfBanks8:		db	15
   764                              <1> MemoryModel8:		db	VBE_MEMORYMODEL_DIRECT_COLOR
   765                              <1> BankSize8:		db	0
   766                              <1> NumberOfImagePages8:	db	17
   767                              <1> Reserved_page8:		db	0
   768                              <1> RedMaskSize8:		db	8
   769                              <1> RedFieldPosition8:	db	16
   770                              <1> GreenMaskSize8:		db	8
   771                              <1> GreenFieldPosition8:	db	8
   772                              <1> BlueMaskSize8:		db	8
   773                              <1> BlueFieldPosition8:	db	0
   774                              <1> RsvdMaskSize8:		db	0
   775                              <1> RsvdFieldPosition8:	db	0
   776                              <1> DirectColorModeInfo8:	db	0
   777                              <1> PhysBasePtr8:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
   778                              <1> OffScreenMemOffset8:	dd	0
   779                              <1> OffScreenMemSize8:	dw	0
   780                              <1> LinBytesPerScanLine8:	dw	1920
   781                              <1> BnkNumberOfPages8: 	db	0
   782                              <1> LinNumberOfPages8: 	db	0
   783                              <1> LinRedMaskSize8:	db	8
   784                              <1> LinRedFieldPosition8:	db	16
   785                              <1> LinGreenMaskSize8:	db	8
   786                              <1> LinGreenFieldPosition8:	db	8
   787                              <1> LinBlueMaskSize8:	db	8
   788                              <1> LinBlueFieldPosition8:	db	0
   789                              <1> LinRsvdMaskSize8:	db	0
   790                              <1> LinRsvdFieldPosition8:	db	0
   791                              <1> MaxPixelClock8:		dd	0
   792                              <1> 
   793                              <1> 			dw	0114h ; 800x600x16
   794                              <1> ModeAttributes9: 	dw	MODE_ATTRIBUTES
   795                              <1> WinAAttributes9: 	db	WINA_ATTRIBUTES
   796                              <1> WinBAttributes9: 	db	0
   797                              <1> WinGranularity9: 	dw	VBE_DISPI_BANK_SIZE_KB
   798                              <1> WinSize9: 		dw	VBE_DISPI_BANK_SIZE_KB
   799                              <1> WinASegment9:		dw	VGAMEM_GRAPH
   800                              <1> WinBSegment9:		dw	0000h
   801                              <1> WinFuncPtr9:		dd	0
   802                              <1> BytesPerScanLine9:	dw	1600
   803                              <1> XResolution9:		dw	800
   804                              <1> YResolution9:		dw	600
   805                              <1> XCharSize9:		db	8
   806                              <1> YCharSize9:		db	16
   807                              <1> NumberOfPlanes9:	db	1
   808                              <1> BitsPerPixel9:		db	16
   809                              <1> NumberOfBanks9:		db	15
   810                              <1> MemoryModel9:		db	VBE_MEMORYMODEL_DIRECT_COLOR
   811                              <1> BankSize9:		db	0
   812                              <1> NumberOfImagePages9:	db	16
   813                              <1> Reserved_page9:		db	0
   814                              <1> RedMaskSize9:		db	5
   815                              <1> RedFieldPosition9:	db	11
   816                              <1> GreenMaskSize9:		db	6
   817                              <1> GreenFieldPosition9:	db	5
   818                              <1> BlueMaskSize9:		db	5
   819                              <1> BlueFieldPosition9:	db	0
   820                              <1> RsvdMaskSize9:		db	0
   821                              <1> RsvdFieldPosition9:	db	0
   822                              <1> DirectColorModeInfo9:	db	0
   823                              <1> PhysBasePtr9:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
   824                              <1> OffScreenMemOffset9:	dd	0
   825                              <1> OffScreenMemSize9:	dw	0
   826                              <1> LinBytesPerScanLine9:	dw	1600
   827                              <1> BnkNumberOfPages9: 	db	0
   828                              <1> LinNumberOfPages9: 	db	0
   829                              <1> LinRedMaskSize9:	db	5
   830                              <1> LinRedFieldPosition9:	db	11
   831                              <1> LinGreenMaskSize9:	db	6
   832                              <1> LinGreenFieldPosition9:	db	5
   833                              <1> LinBlueMaskSize9:	db	5
   834                              <1> LinBlueFieldPosition9:	db	0
   835                              <1> LinRsvdMaskSize9:	db	0
   836                              <1> LinRsvdFieldPosition9:	db	0
   837                              <1> MaxPixelClock9:		dd	0
   838                              <1> 	
   839                              <1> 			dw	0115h ; 800x600x24
   840                              <1> ModeAttributes10: 	dw	MODE_ATTRIBUTES
   841                              <1> WinAAttributes10: 	db	WINA_ATTRIBUTES
   842                              <1> WinBAttributes10: 	db	0
   843                              <1> WinGranularity10: 	dw	VBE_DISPI_BANK_SIZE_KB
   844                              <1> WinSize10: 		dw	VBE_DISPI_BANK_SIZE_KB
   845                              <1> WinASegment10:		dw	VGAMEM_GRAPH
   846                              <1> WinBSegment10:		dw	0000h
   847                              <1> WinFuncPtr10:		dd	0
   848                              <1> BytesPerScanLine10:	dw	2400
   849                              <1> XResolution10:		dw	800
   850                              <1> YResolution10:		dw	600
   851                              <1> XCharSize10:		db	8
   852                              <1> YCharSize10:		db	16
   853                              <1> NumberOfPlanes10:	db	1
   854                              <1> BitsPerPixel10:		db	24
   855                              <1> NumberOfBanks10:	db	22
   856                              <1> MemoryModel10:		db	VBE_MEMORYMODEL_DIRECT_COLOR
   857                              <1> BankSize10:		db	0
   858                              <1> NumberOfImagePages10:	db	10
   859                              <1> Reserved_page10:	db	0
   860                              <1> RedMaskSize10:		db	8
   861                              <1> RedFieldPosition10:	db	16
   862                              <1> GreenMaskSize10:	db	8
   863                              <1> GreenFieldPosition10:	db	8
   864                              <1> BlueMaskSize10:		db	8
   865                              <1> BlueFieldPosition10:	db	0
   866                              <1> RsvdMaskSize10:		db	0
   867                              <1> RsvdFieldPosition10:	db	0
   868                              <1> DirectColorModeInfo10:	db	0
   869                              <1> PhysBasePtr10:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
   870                              <1> OffScreenMemOffset10:	dd	0
   871                              <1> OffScreenMemSize10:	dw	0
   872                              <1> LinBytesPerScanLine10:	dw	2400
   873                              <1> BnkNumberOfPages10: 	db	0
   874                              <1> LinNumberOfPages10: 	db	0
   875                              <1> LinRedMaskSize10:	db	8
   876                              <1> LinRedFieldPosition10:	db	16
   877                              <1> LinGreenMaskSize10:	db	8
   878                              <1> LinGreenFieldPosition10:db	8
   879                              <1> LinBlueMaskSize10:	db	8
   880                              <1> LinBlueFieldPosition10:	db	0
   881                              <1> LinRsvdMaskSize10:	db	0
   882                              <1> LinRsvdFieldPosition10:	db	0
   883                              <1> MaxPixelClock10:	dd	0
   884                              <1> 
   885                              <1> 			dw	0117h ; 1024x768x16
   886                              <1> ModeAttributes11: 	dw	MODE_ATTRIBUTES
   887                              <1> WinAAttributes11: 	db	WINA_ATTRIBUTES
   888                              <1> WinBAttributes11: 	db	0
   889                              <1> WinGranularity11: 	dw	VBE_DISPI_BANK_SIZE_KB
   890                              <1> WinSize11: 		dw	VBE_DISPI_BANK_SIZE_KB
   891                              <1> WinASegment11:		dw	VGAMEM_GRAPH
   892                              <1> WinBSegment11:		dw	0000h
   893                              <1> WinFuncPtr11:		dd	0
   894                              <1> BytesPerScanLine11:	dw	2048
   895                              <1> XResolution11:		dw	1024
   896                              <1> YResolution11:		dw	768
   897                              <1> XCharSize11:		db	8
   898                              <1> YCharSize11:		db	16
   899                              <1> NumberOfPlanes11:	db	1
   900                              <1> BitsPerPixel11:		db	16
   901                              <1> NumberOfBanks11:	db	24
   902                              <1> MemoryModel11:		db	VBE_MEMORYMODEL_DIRECT_COLOR
   903                              <1> BankSize11:		db	0
   904                              <1> NumberOfImagePages11:	db	9
   905                              <1> Reserved_page11:	db	0
   906                              <1> RedMaskSize11:		db	5
   907                              <1> RedFieldPosition11:	db	11
   908                              <1> GreenMaskSize11:	db	6
   909                              <1> GreenFieldPosition11:	db	5
   910                              <1> BlueMaskSize11:		db	5
   911                              <1> BlueFieldPosition11:	db	0
   912                              <1> RsvdMaskSize11:		db	0
   913                              <1> RsvdFieldPosition11:	db	0
   914                              <1> DirectColorModeInfo11:	db	0
   915                              <1> PhysBasePtr11:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS,
   916                              <1> OffScreenMemOffset11:	dd	0
   917                              <1> OffScreenMemSize11:	dw	0
   918                              <1> LinBytesPerScanLine11:	dw	2048
   919                              <1> BnkNumberOfPages11: 	db	0
   920                              <1> LinNumberOfPages11: 	db	0
   921                              <1> LinRedMaskSize11:	db	5
   922                              <1> LinRedFieldPosition11:	db	11
   923                              <1> LinGreenMaskSize11:	db	6
   924                              <1> LinGreenFieldPosition11:db	5
   925                              <1> LinBlueMaskSize11:	db	5
   926                              <1> LinBlueFieldPosition11:	db	0
   927                              <1> LinRsvdMaskSize11:	db	0
   928                              <1> LinRsvdFieldPosition11:	db	0
   929                              <1> MaxPixelClock11:	dd	0
   930                              <1> 
   931                              <1> 			dw	0118h ; 1024x768x24
   932                              <1> ModeAttributes12: 	dw	MODE_ATTRIBUTES
   933                              <1> WinAAttributes12: 	db	WINA_ATTRIBUTES
   934                              <1> WinBAttributes12: 	db	0
   935                              <1> WinGranularity12: 	dw	VBE_DISPI_BANK_SIZE_KB
   936                              <1> WinSize12: 		dw	VBE_DISPI_BANK_SIZE_KB
   937                              <1> WinASegment12:		dw	VGAMEM_GRAPH
   938                              <1> WinBSegment12:		dw	0000h
   939                              <1> WinFuncPtr12:		dd	0
   940                              <1> BytesPerScanLine12:	dw	3072
   941                              <1> XResolution12:		dw	1024
   942                              <1> YResolution12:		dw	768
   943                              <1> XCharSize12:		db	8
   944                              <1> YCharSize12:		db	16
   945                              <1> NumberOfPlanes12:	db	1
   946                              <1> BitsPerPixel12:		db	24
   947                              <1> NumberOfBanks12:	db	36
   948                              <1> MemoryModel12:		db	VBE_MEMORYMODEL_DIRECT_COLOR
   949                              <1> BankSize12:		db	0
   950                              <1> NumberOfImagePages12:	db	6
   951                              <1> Reserved_page12:	db	0
   952                              <1> RedMaskSize12:		db	8
   953                              <1> RedFieldPosition12:	db	16
   954                              <1> GreenMaskSize12:	db	8
   955                              <1> GreenFieldPosition12:	db	8
   956                              <1> BlueMaskSize12:		db	8
   957                              <1> BlueFieldPosition12:	db	0
   958                              <1> RsvdMaskSize12:		db	0
   959                              <1> RsvdFieldPosition12:	db	0
   960                              <1> DirectColorModeInfo12:	db	0
   961                              <1> PhysBasePtr12:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
   962                              <1> OffScreenMemOffset12:	dd	0
   963                              <1> OffScreenMemSize12:	dw	0
   964                              <1> LinBytesPerScanLine12:	dw	3072
   965                              <1> BnkNumberOfPages12: 	db	0
   966                              <1> LinNumberOfPages12: 	db	0
   967                              <1> LinRedMaskSize12:	db	8
   968                              <1> LinRedFieldPosition12:	db	16
   969                              <1> LinGreenMaskSize12:	db	8
   970                              <1> LinGreenFieldPosition12:db	8
   971                              <1> LinBlueMaskSize12:	db	8
   972                              <1> LinBlueFieldPosition12:	db	0
   973                              <1> LinRsvdMaskSize12:	db	0
   974                              <1> LinRsvdFieldPosition12:	db	0
   975                              <1> MaxPixelClock12:	dd	0
   976                              <1> 
   977                              <1> 			dw	0140h ; 320x200x32
   978                              <1> ModeAttributes13: 	dw	MODE_ATTRIBUTES
   979                              <1> WinAAttributes13: 	db	WINA_ATTRIBUTES
   980                              <1> WinBAttributes13: 	db	0
   981                              <1> WinGranularity13: 	dw	VBE_DISPI_BANK_SIZE_KB
   982                              <1> WinSize13: 		dw	VBE_DISPI_BANK_SIZE_KB
   983                              <1> WinASegment13:		dw	VGAMEM_GRAPH
   984                              <1> WinBSegment13:		dw	0000h
   985                              <1> WinFuncPtr13:		dd	0
   986                              <1> BytesPerScanLine13:	dw	1280
   987                              <1> XResolution13:		dw	320
   988                              <1> YResolution13:		dw	200
   989                              <1> XCharSize13:		db	8
   990                              <1> YCharSize13:		db	16
   991                              <1> NumberOfPlanes13:	db	1
   992                              <1> BitsPerPixel13:		db	32
   993                              <1> NumberOfBanks13:	db	4
   994                              <1> MemoryModel13:		db	VBE_MEMORYMODEL_DIRECT_COLOR
   995                              <1> BankSize13:		db	0
   996                              <1> NumberOfImagePages13:	db	64
   997                              <1> Reserved_page13:	db	0
   998                              <1> RedMaskSize13:		db	8
   999                              <1> RedFieldPosition13:	db	16
  1000                              <1> GreenMaskSize13:	db	8
  1001                              <1> GreenFieldPosition13:	db	8
  1002                              <1> BlueMaskSize13:		db	8
  1003                              <1> BlueFieldPosition13:	db	0
  1004                              <1> RsvdMaskSize13:		db	8
  1005                              <1> RsvdFieldPosition13:	db	24
  1006                              <1> DirectColorModeInfo13:	db	VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE
  1007                              <1> PhysBasePtr13:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
  1008                              <1> OffScreenMemOffset13:	dd	0
  1009                              <1> OffScreenMemSize13:	dw	0
  1010                              <1> LinBytesPerScanLine13:	dw	1280
  1011                              <1> BnkNumberOfPages13: 	db	0
  1012                              <1> LinNumberOfPages13: 	db	0
  1013                              <1> LinRedMaskSize13:	db	8
  1014                              <1> LinRedFieldPosition13:	db	16
  1015                              <1> LinGreenMaskSize13:	db	8
  1016                              <1> LinGreenFieldPosition13:db	8
  1017                              <1> LinBlueMaskSize13:	db	8
  1018                              <1> LinBlueFieldPosition13:	db	0
  1019                              <1> LinRsvdMaskSize13:	db	8
  1020                              <1> LinRsvdFieldPosition13:	db	24
  1021                              <1> MaxPixelClock13:	dd	0
  1022                              <1> 
  1023                              <1> 			dw	0141h ; 640x400x32
  1024                              <1> ModeAttributes14: 	dw	MODE_ATTRIBUTES
  1025                              <1> WinAAttributes14: 	db	WINA_ATTRIBUTES
  1026                              <1> WinBAttributes14: 	db	0
  1027                              <1> WinGranularity14: 	dw	VBE_DISPI_BANK_SIZE_KB
  1028                              <1> WinSize14: 		dw	VBE_DISPI_BANK_SIZE_KB
  1029                              <1> WinASegment14:		dw	VGAMEM_GRAPH
  1030                              <1> WinBSegment14:		dw	0000h
  1031                              <1> WinFuncPtr14:		dd	0
  1032                              <1> BytesPerScanLine14:	dw	2560
  1033                              <1> XResolution14:		dw	640
  1034                              <1> YResolution14:		dw	400
  1035                              <1> XCharSize14:		db	8
  1036                              <1> YCharSize14:		db	16
  1037                              <1> NumberOfPlanes14:	db	1
  1038                              <1> BitsPerPixel14:		db	32
  1039                              <1> NumberOfBanks14:	db	16
  1040                              <1> MemoryModel14:		db	VBE_MEMORYMODEL_DIRECT_COLOR
  1041                              <1> BankSize14:		db	0
  1042                              <1> NumberOfImagePages14:	db	15
  1043                              <1> Reserved_page14:	db	0
  1044                              <1> RedMaskSize14:		db	8
  1045                              <1> RedFieldPosition14:	db	16
  1046                              <1> GreenMaskSize14:	db	8
  1047                              <1> GreenFieldPosition14:	db	8
  1048                              <1> BlueMaskSize14:		db	8
  1049                              <1> BlueFieldPosition14:	db	0
  1050                              <1> RsvdMaskSize14:		db	8
  1051                              <1> RsvdFieldPosition14:	db	24
  1052                              <1> DirectColorModeInfo14:	db	VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE
  1053                              <1> PhysBasePtr14:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
  1054                              <1> OffScreenMemOffset14:	dd  	0
  1055                              <1> OffScreenMemSize14:	dw	0
  1056                              <1> LinBytesPerScanLine14:	dw	2560
  1057                              <1> BnkNumberOfPages14: 	db	0
  1058                              <1> LinNumberOfPages14: 	db	0
  1059                              <1> LinRedMaskSize14:	db	8
  1060                              <1> LinRedFieldPosition14:	db	16
  1061                              <1> LinGreenMaskSize14:	db	8
  1062                              <1> LinGreenFieldPosition14:db	8
  1063                              <1> LinBlueMaskSize14:	db	8
  1064                              <1> LinBlueFieldPosition14:	db	0
  1065                              <1> LinRsvdMaskSize14:	db	8
  1066                              <1> LinRsvdFieldPosition14:	db	24
  1067                              <1> MaxPixelClock14:	dd	0
  1068                              <1> 
  1069                              <1> 			dw	0142 ; 640x480x32
  1070                              <1> ModeAttributes15: 	dw	MODE_ATTRIBUTES
  1071                              <1> WinAAttributes15: 	db	WINA_ATTRIBUTES
  1072                              <1> WinBAttributes15: 	db	0
  1073                              <1> WinGranularity15: 	dw	VBE_DISPI_BANK_SIZE_KB
  1074                              <1> WinSize15: 		dw	VBE_DISPI_BANK_SIZE_KB
  1075                              <1> WinASegment15:		dw	VGAMEM_GRAPH
  1076                              <1> WinBSegment15:		dw	0000h
  1077                              <1> WinFuncPtr15:		dd	0
  1078                              <1> BytesPerScanLine15:	dw	2560
  1079                              <1> XResolution15:		dw	640
  1080                              <1> YResolution15:		dw	480
  1081                              <1> XCharSize15:		db	8
  1082                              <1> YCharSize15:		db	16
  1083                              <1> NumberOfPlanes15:	db	1
  1084                              <1> BitsPerPixel15:		db	32
  1085                              <1> NumberOfBanks15:	db	19
  1086                              <1> MemoryModel15:		db	VBE_MEMORYMODEL_DIRECT_COLOR
  1087                              <1> BankSize15:		db	0
  1088                              <1> NumberOfImagePages15:	db	12
  1089                              <1> Reserved_page15:	db	0
  1090                              <1> RedMaskSize15:		db	8
  1091                              <1> RedFieldPosition15:	db	16
  1092                              <1> GreenMaskSize15:	db	8
  1093                              <1> GreenFieldPosition15:	db	8
  1094                              <1> BlueMaskSize15:		db	8
  1095                              <1> BlueFieldPosition15:	db	0
  1096                              <1> RsvdMaskSize15:		db	8
  1097                              <1> RsvdFieldPosition15:	db	24
  1098                              <1> DirectColorModeInfo15:	db	VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE,
  1099                              <1> PhysBasePtr15:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS,
  1100                              <1> OffScreenMemOffset15:	dd	0
  1101                              <1> OffScreenMemSize15:	dw	0
  1102                              <1> LinBytesPerScanLine15:	dw	2560
  1103                              <1> BnkNumberOfPages15: 	db	0
  1104                              <1> LinNumberOfPages15: 	db	0
  1105                              <1> LinRedMaskSize15:	db	8
  1106                              <1> LinRedFieldPosition15:	db	16
  1107                              <1> LinGreenMaskSize15:	db	8
  1108                              <1> LinGreenFieldPosition15:db	8
  1109                              <1> LinBlueMaskSize15:	db	8
  1110                              <1> LinBlueFieldPosition15:	db	0
  1111                              <1> LinRsvdMaskSize15:	db	8
  1112                              <1> LinRsvdFieldPosition15:	db	24
  1113                              <1> MaxPixelClock15:	dd	0
  1114                              <1> 
  1115                              <1> 			dw	0143h ; 800x600x32
  1116                              <1> ModeAttributes16: 	dw	MODE_ATTRIBUTES
  1117                              <1> WinAAttributes16: 	db	WINA_ATTRIBUTES
  1118                              <1> WinBAttributes16: 	db	0
  1119                              <1> WinGranularity16: 	dw	VBE_DISPI_BANK_SIZE_KB
  1120                              <1> WinSize16: 		dw	VBE_DISPI_BANK_SIZE_KB
  1121                              <1> WinASegment16:		dw	VGAMEM_GRAPH
  1122                              <1> WinBSegment16:		dw	0000h
  1123                              <1> WinFuncPtr16:		dd	0
  1124                              <1> BytesPerScanLine16:	dw	3200
  1125                              <1> XResolution16:		dw	800
  1126                              <1> YResolution16:		dw	600
  1127                              <1> XCharSize16:		db	8
  1128                              <1> YCharSize16:		db	16
  1129                              <1> NumberOfPlanes16:	db	1
  1130                              <1> BitsPerPixel16:		db	32
  1131                              <1> NumberOfBanks16:	db	30
  1132                              <1> MemoryModel16:		db	VBE_MEMORYMODEL_DIRECT_COLOR
  1133                              <1> BankSize16:		db	0
  1134                              <1> NumberOfImagePages16:	db	7
  1135                              <1> Reserved_page16:	db	0
  1136                              <1> RedMaskSize16:		db	8
  1137                              <1> RedFieldPosition16:	db	16
  1138                              <1> GreenMaskSize16:	db	8
  1139                              <1> GreenFieldPosition16:	db	8
  1140                              <1> BlueMaskSize16:		db	8
  1141                              <1> BlueFieldPosition16:	db	0
  1142                              <1> RsvdMaskSize16:		db	8
  1143                              <1> RsvdFieldPosition16:	db	24
  1144                              <1> DirectColorModeInfo16:	db	VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE,
  1145                              <1> PhysBasePtr16:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS,
  1146                              <1> OffScreenMemOffset16:	dd	0
  1147                              <1> OffScreenMemSize16:	dw	0
  1148                              <1> LinBytesPerScanLine16:	dw	3200
  1149                              <1> BnkNumberOfPages16: 	db	0
  1150                              <1> LinNumberOfPages16: 	db	0
  1151                              <1> LinRedMaskSize16:	db	8
  1152                              <1> LinRedFieldPosition16:	db	16
  1153                              <1> LinGreenMaskSize16:	db	8
  1154                              <1> LinGreenFieldPosition16:db	8
  1155                              <1> LinBlueMaskSize16:	db	8
  1156                              <1> LinBlueFieldPosition16:	db	0
  1157                              <1> LinRsvdMaskSize16:	db	8
  1158                              <1> LinRsvdFieldPosition16:	db	24
  1159                              <1> MaxPixelClock16:	dd	0
  1160                              <1> 	
  1161                              <1> 			dw	0144h ; 1024x768x32
  1162                              <1> ModeAttributes17: 	dw	MODE_ATTRIBUTES
  1163                              <1> WinAAttributes17: 	db	WINA_ATTRIBUTES
  1164                              <1> WinBAttributes17: 	db	0
  1165                              <1> WinGranularity17: 	dw	VBE_DISPI_BANK_SIZE_KB
  1166                              <1> WinSize17: 		dw	VBE_DISPI_BANK_SIZE_KB
  1167                              <1> WinASegment17:		dw	VGAMEM_GRAPH
  1168                              <1> WinBSegment17:		dw	0000h
  1169                              <1> WinFuncPtr17:		dd	0
  1170                              <1> BytesPerScanLine17:	dw	4096
  1171                              <1> XResolution17:		dw	1024
  1172                              <1> YResolution17:		dw	768
  1173                              <1> XCharSize17:		db	8
  1174                              <1> YCharSize17:		db	16
  1175                              <1> NumberOfPlanes17:	db	1
  1176                              <1> BitsPerPixel17:		db	32
  1177                              <1> NumberOfBanks17:	db	48
  1178                              <1> MemoryModel17:		db	VBE_MEMORYMODEL_DIRECT_COLOR
  1179                              <1> BankSize17:		db	0
  1180                              <1> NumberOfImagePages17:	db	4
  1181                              <1> Reserved_page17:	db	0
  1182                              <1> RedMaskSize17:		db	8
  1183                              <1> RedFieldPosition17:	db	16
  1184                              <1> GreenMaskSize17:	db	8
  1185                              <1> GreenFieldPosition17:	db	8
  1186                              <1> BlueMaskSize17:		db	8
  1187                              <1> BlueFieldPosition17:	db	0
  1188                              <1> RsvdMaskSize17:		db	8
  1189                              <1> RsvdFieldPosition17:	db	24
  1190                              <1> DirectColorModeInfo17:	db	VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE
  1191                              <1> PhysBasePtr17:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
  1192                              <1> OffScreenMemOffset17:	dd	0
  1193                              <1> OffScreenMemSize17:	dw	0
  1194                              <1> LinBytesPerScanLine17:	dw	4096
  1195                              <1> BnkNumberOfPages17: 	db	0
  1196                              <1> LinNumberOfPages17: 	db	0
  1197                              <1> LinRedMaskSize17:	db	8
  1198                              <1> LinRedFieldPosition17:	db	16
  1199                              <1> LinGreenMaskSize17:	db	8
  1200                              <1> LinGreenFieldPosition17:db	8
  1201                              <1> LinBlueMaskSize17:	db	8
  1202                              <1> LinBlueFieldPosition17:	db	0
  1203                              <1> LinRsvdMaskSize17:	db	8
  1204                              <1> LinRsvdFieldPosition17:	db	24
  1205                              <1> MaxPixelClock17:	dd	0
  1206                              <1> 	
  1207                              <1> 			dw	0146h ; 320x200x8
  1208                              <1> ModeAttributes18: 	dw	MODE_ATTRIBUTES
  1209                              <1> WinAAttributes18: 	db	WINA_ATTRIBUTES
  1210                              <1> WinBAttributes18: 	db	0
  1211                              <1> WinGranularity18: 	dw	VBE_DISPI_BANK_SIZE_KB
  1212                              <1> WinSize18: 		dw	VBE_DISPI_BANK_SIZE_KB
  1213                              <1> WinASegment18:		dw	VGAMEM_GRAPH
  1214                              <1> WinBSegment18:		dw	0000h
  1215                              <1> WinFuncPtr18:		dd	0
  1216                              <1> BytesPerScanLine18:	dw	320
  1217                              <1> XResolution18:		dw	320
  1218                              <1> YResolution18:		dw	200
  1219                              <1> XCharSize18:		db	8
  1220                              <1> YCharSize18:		db	16
  1221                              <1> NumberOfPlanes18:	db	1
  1222                              <1> BitsPerPixel18:		db	8
  1223                              <1> NumberOfBanks18:	db	1
  1224                              <1> MemoryModel18:		db	VBE_MEMORYMODEL_PACKED_PIXEL
  1225                              <1> BankSize18:		db	0
  1226                              <1> NumberOfImagePages18:	db	255 ; 261 in vbetables.h (03/01/2020) !
  1227                              <1> Reserved_page18:	db	0
  1228                              <1> RedMaskSize18:		db	0
  1229                              <1> RedFieldPosition18:	db	0
  1230                              <1> GreenMaskSize18:	db	0
  1231                              <1> GreenFieldPosition18:	db	0
  1232                              <1> BlueMaskSize18:		db	0
  1233                              <1> BlueFieldPosition18:	db	0
  1234                              <1> RsvdMaskSize18:		db	0
  1235                              <1> RsvdFieldPosition18:	db	0
  1236                              <1> DirectColorModeInfo18:	db	0
  1237                              <1> PhysBasePtr18:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
  1238                              <1> OffScreenMemOffset18:	dd	0
  1239                              <1> OffScreenMemSize18:	dw	0
  1240                              <1> LinBytesPerScanLine18:	dw	320
  1241                              <1> BnkNumberOfPages18: 	db	0
  1242                              <1> LinNumberOfPages18: 	db	0
  1243                              <1> LinRedMaskSize18:	db	0
  1244                              <1> LinRedFieldPosition18: 	db	0
  1245                              <1> LinGreenMaskSize18: 	db	0
  1246                              <1> LinGreenFieldPosition18:db	0
  1247                              <1> LinBlueMaskSize18: 	db	0
  1248                              <1> LinBlueFieldPosition18: db	0
  1249                              <1> LinRsvdMaskSize18: 	db	0
  1250                              <1> LinRsvdFieldPosition18: db	0
  1251                              <1> MaxPixelClock18:	dd	0
  1252                              <1> 
  1253                              <1> 			dw	018Dh ; 1280x720x16
  1254                              <1> ModeAttributes19: 	dw	MODE_ATTRIBUTES
  1255                              <1> WinAAttributes19: 	db	WINA_ATTRIBUTES
  1256                              <1> WinBAttributes19: 	db	0
  1257                              <1> WinGranularity19: 	dw	VBE_DISPI_BANK_SIZE_KB
  1258                              <1> WinSize19: 		dw	VBE_DISPI_BANK_SIZE_KB
  1259                              <1> WinASegment19:		dw	VGAMEM_GRAPH
  1260                              <1> WinBSegment19:		dw	0000h
  1261                              <1> WinFuncPtr19:		dd	0
  1262                              <1> BytesPerScanLine19:	dw	2560
  1263                              <1> XResolution19:		dw	1280
  1264                              <1> YResolution19:		dw	720
  1265                              <1> XCharSize19:		db	8
  1266                              <1> YCharSize19:		db	16
  1267                              <1> NumberOfPlanes19:	db	1
  1268                              <1> BitsPerPixel19:		db	16
  1269                              <1> NumberOfBanks19:	db	29
  1270                              <1> MemoryModel19:		db	VBE_MEMORYMODEL_DIRECT_COLOR
  1271                              <1> BankSize19:		db	0
  1272                              <1> NumberOfImagePages19:	db	8
  1273                              <1> Reserved_page19:	db	0
  1274                              <1> RedMaskSize19:		db	5
  1275                              <1> RedFieldPosition19:	db	11
  1276                              <1> GreenMaskSize19:	db	6
  1277                              <1> GreenFieldPosition19:	db	5
  1278                              <1> BlueMaskSize19:		db	5
  1279                              <1> BlueFieldPosition19:	db	0
  1280                              <1> RsvdMaskSize19:		db	0
  1281                              <1> RsvdFieldPosition19:	db	0
  1282                              <1> DirectColorModeInfo19:	db	0
  1283                              <1> PhysBasePtr19:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
  1284                              <1> OffScreenMemOffset19:	dd	0
  1285                              <1> OffScreenMemSize19:	dw	0
  1286                              <1> LinBytesPerScanLine19:	dw	2560
  1287                              <1> BnkNumberOfPages19: 	db	0
  1288                              <1> LinNumberOfPages19: 	db	0
  1289                              <1> LinRedMaskSize19:	db	5
  1290                              <1> LinRedFieldPosition19:	db	11
  1291                              <1> LinGreenMaskSize19:	db	6
  1292                              <1> LinGreenFieldPosition19:db	5
  1293                              <1> LinBlueMaskSize19:	db	5
  1294                              <1> LinBlueFieldPosition19:	db	0
  1295                              <1> LinRsvdMaskSize19:	db	0
  1296                              <1> LinRsvdFieldPosition19:	db	0
  1297                              <1> MaxPixelClock19:	dd	0
  1298                              <1> 
  1299                              <1> 			dw	018Eh ; 1280x720x24
  1300                              <1> ModeAttributes20: 	dw	MODE_ATTRIBUTES
  1301                              <1> WinAAttributes20: 	db	WINA_ATTRIBUTES
  1302                              <1> WinBAttributes20: 	db	0
  1303                              <1> WinGranularity20: 	dw	VBE_DISPI_BANK_SIZE_KB
  1304                              <1> WinSize20: 		dw	VBE_DISPI_BANK_SIZE_KB
  1305                              <1> WinASegment20:		dw	VGAMEM_GRAPH
  1306                              <1> WinBSegment20:		dw	0000h
  1307                              <1> WinFuncPtr20:		dd	0
  1308                              <1> BytesPerScanLine20:	dw	3840
  1309                              <1> XResolution20:		dw	1280
  1310                              <1> YResolution20:		dw	720
  1311                              <1> XCharSize20:		db	8
  1312                              <1> YCharSize20:		db	16
  1313                              <1> NumberOfPlanes20:	db	1
  1314                              <1> BitsPerPixel20:		db	24
  1315                              <1> NumberOfBanks20:	db	43
  1316                              <1> MemoryModel20:		db	VBE_MEMORYMODEL_DIRECT_COLOR
  1317                              <1> BankSize20:		db	0
  1318                              <1> NumberOfImagePages20:	db	5
  1319                              <1> Reserved_page20:	db	0
  1320                              <1> RedMaskSize20:		db	8
  1321                              <1> RedFieldPosition20:	db	16
  1322                              <1> GreenMaskSize20:	db	8
  1323                              <1> GreenFieldPosition20:	db	8
  1324                              <1> BlueMaskSize20:		db	8
  1325                              <1> BlueFieldPosition20:	db	0
  1326                              <1> RsvdMaskSize20:		db	0
  1327                              <1> RsvdFieldPosition20:	db	0
  1328                              <1> DirectColorModeInfo20:	db	0
  1329                              <1> PhysBasePtr20:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
  1330                              <1> OffScreenMemOffset20:	dd	0
  1331                              <1> OffScreenMemSize20:	dw	0
  1332                              <1> LinBytesPerScanLine20:	dw	3840
  1333                              <1> BnkNumberOfPages20: 	db	0
  1334                              <1> LinNumberOfPages20: 	db	0
  1335                              <1> LinRedMaskSize20:	db	8
  1336                              <1> LinRedFieldPosition20:	db	16
  1337                              <1> LinGreenMaskSize20:	db	8
  1338                              <1> LinGreenFieldPosition20:db	8
  1339                              <1> LinBlueMaskSize20:	db	8
  1340                              <1> LinBlueFieldPosition20:	db	0
  1341                              <1> LinRsvdMaskSize20:	db	0
  1342                              <1> LinRsvdFieldPosition20:	db	0
  1343                              <1> MaxPixelClock20:	dd	0
  1344                              <1> 	
  1345                              <1> 			dw	018Fh ; 1280x720x32
  1346                              <1> ModeAttributes21: 	dw	MODE_ATTRIBUTES
  1347                              <1> WinAAttributes21: 	db	WINA_ATTRIBUTES
  1348                              <1> WinBAttributes21: 	db	0
  1349                              <1> WinGranularity21: 	dw	VBE_DISPI_BANK_SIZE_KB
  1350                              <1> WinSize21: 		dw	VBE_DISPI_BANK_SIZE_KB
  1351                              <1> WinASegment21:		dw	VGAMEM_GRAPH
  1352                              <1> WinBSegment21:		dw	0000h
  1353                              <1> WinFuncPtr21:		dd	0
  1354                              <1> BytesPerScanLine21:	dw	5120
  1355                              <1> XResolution21:		dw	1280
  1356                              <1> YResolution21:		dw	720
  1357                              <1> XCharSize21:		db	8
  1358                              <1> YCharSize21:		db	16
  1359                              <1> NumberOfPlanes21:	db	1
  1360                              <1> BitsPerPixel21:		db	32
  1361                              <1> NumberOfBanks21:	db	57
  1362                              <1> MemoryModel21:		db	VBE_MEMORYMODEL_DIRECT_COLOR
  1363                              <1> BankSize21:		db	0
  1364                              <1> NumberOfImagePages21:	db	3
  1365                              <1> Reserved_page21:	db	0
  1366                              <1> RedMaskSize21:		db	8
  1367                              <1> RedFieldPosition21:	db	16
  1368                              <1> GreenMaskSize21:	db	8
  1369                              <1> GreenFieldPosition21:	db	8
  1370                              <1> BlueMaskSize21:		db	8
  1371                              <1> BlueFieldPosition21:	db	0
  1372                              <1> RsvdMaskSize21:		db	8
  1373                              <1> RsvdFieldPosition21:	db	24
  1374                              <1> DirectColorModeInfo21:	db	VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE
  1375                              <1> PhysBasePtr21:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
  1376                              <1> OffScreenMemOffset21:	dd	0
  1377                              <1> OffScreenMemSize21:	dw	0
  1378                              <1> LinBytesPerScanLine21:	dw	5120
  1379                              <1> BnkNumberOfPages21: 	db	0
  1380                              <1> LinNumberOfPages21: 	db	0
  1381                              <1> LinRedMaskSize21:	db	8
  1382                              <1> LinRedFieldPosition21:	db	16
  1383                              <1> LinGreenMaskSize21:	db	8
  1384                              <1> LinGreenFieldPosition21:db	8
  1385                              <1> LinBlueMaskSize21:	db	8
  1386                              <1> LinBlueFieldPosition21:	db	0
  1387                              <1> LinRsvdMaskSize21:	db	8
  1388                              <1> LinRsvdFieldPosition21:	db	24
  1389                              <1> MaxPixelClock21:	dd	0
  1390                              <1> 			
  1391                              <1> 			dw	0190h ; 1920x1080x16
  1392                              <1> ModeAttributes22: 	dw	MODE_ATTRIBUTES
  1393                              <1> WinAAttributes22: 	db	WINA_ATTRIBUTES
  1394                              <1> WinBAttributes22: 	db	0
  1395                              <1> WinGranularity22: 	dw	VBE_DISPI_BANK_SIZE_KB
  1396                              <1> WinSize22: 		dw	VBE_DISPI_BANK_SIZE_KB
  1397                              <1> WinASegment22:		dw	VGAMEM_GRAPH
  1398                              <1> WinBSegment22:		dw	0000h
  1399                              <1> WinFuncPtr22:		dd	0
  1400                              <1> BytesPerScanLine22:	dw	3840
  1401                              <1> XResolution22:		dw	1920
  1402                              <1> YResolution22:		dw	1080
  1403                              <1> XCharSize22:		db	8
  1404                              <1> YCharSize22:		db	16
  1405                              <1> NumberOfPlanes22:	db	1
  1406                              <1> BitsPerPixel22:		db	16
  1407                              <1> NumberOfBanks22:	db	64
  1408                              <1> MemoryModel22:		db	VBE_MEMORYMODEL_DIRECT_COLOR,
  1409                              <1> BankSize22:		db	0
  1410                              <1> NumberOfImagePages22:	db	3
  1411                              <1> Reserved_page22:	db	0
  1412                              <1> RedMaskSize22:		db	5
  1413                              <1> RedFieldPosition22:	db	11
  1414                              <1> GreenMaskSize22:	db	6
  1415                              <1> GreenFieldPosition22:	db	5
  1416                              <1> BlueMaskSize22:		db	5
  1417                              <1> BlueFieldPosition22:	db	0
  1418                              <1> RsvdMaskSize22:		db	0
  1419                              <1> RsvdFieldPosition22:	db	0
  1420                              <1> DirectColorModeInfo22:	db	0
  1421                              <1> PhysBasePtr22:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
  1422                              <1> OffScreenMemOffset22:	dd	0
  1423                              <1> OffScreenMemSize22:	dw	0
  1424                              <1> LinBytesPerScanLine22:	dw	3840
  1425                              <1> BnkNumberOfPages22: 	db	0
  1426                              <1> LinNumberOfPages22: 	db	0
  1427                              <1> LinRedMaskSize22:	db	5
  1428                              <1> LinRedFieldPosition22:	db	11
  1429                              <1> LinGreenMaskSize22:	db	6
  1430                              <1> LinGreenFieldPosition22:db	5
  1431                              <1> LinBlueMaskSize22:	db	5
  1432                              <1> LinBlueFieldPosition22:	db	0
  1433                              <1> LinRsvdMaskSize22:	db	0
  1434                              <1> LinRsvdFieldPosition22:	db	0
  1435                              <1> MaxPixelClock22:	dd	0
  1436                              <1> 			
  1437                              <1> 			dw	0191h ; 1920x1080x24
  1438                              <1> ModeAttributes23: 	dw	MODE_ATTRIBUTES
  1439                              <1> WinAAttributes23: 	db	WINA_ATTRIBUTES
  1440                              <1> WinBAttributes23: 	db	0
  1441                              <1> WinGranularity23: 	dw	VBE_DISPI_BANK_SIZE_KB
  1442                              <1> WinSize23: 		dw	VBE_DISPI_BANK_SIZE_KB
  1443                              <1> WinASegment23:		dw	VGAMEM_GRAPH
  1444                              <1> WinBSegment23:		dw	0000h
  1445                              <1> WinFuncPtr23:		dd	0
  1446                              <1> BytesPerScanLine23:	dw	5760
  1447                              <1> XResolution23:		dw	1920
  1448                              <1> YResolution23:		dw	1080
  1449                              <1> XCharSize23:		db	8
  1450                              <1> YCharSize23:		db	16
  1451                              <1> NumberOfPlanes23:	db	1
  1452                              <1> BitsPerPixel23:		db	24
  1453                              <1> NumberOfBanks23:	db	95
  1454                              <1> MemoryModel23:		db	VBE_MEMORYMODEL_DIRECT_COLOR
  1455                              <1> BankSize23:		db	0
  1456                              <1> NumberOfImagePages23:	db	1
  1457                              <1> Reserved_page23:	db	0
  1458                              <1> RedMaskSize23:		db	8
  1459                              <1> RedFieldPosition23:	db	16
  1460                              <1> GreenMaskSize23:	db	8
  1461                              <1> GreenFieldPosition23:	db	8
  1462                              <1> BlueMaskSize23:		db	8
  1463                              <1> BlueFieldPosition23:	db	0
  1464                              <1> RsvdMaskSize23:		db	0
  1465                              <1> RsvdFieldPosition23:	db	0
  1466                              <1> DirectColorModeInfo23:	db	0
  1467                              <1> PhysBasePtr23:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
  1468                              <1> OffScreenMemOffset23:	dd	0
  1469                              <1> OffScreenMemSize23:	dw	0
  1470                              <1> LinBytesPerScanLine23:	dw	5760
  1471                              <1> BnkNumberOfPages23: 	db	0
  1472                              <1> LinNumberOfPages23: 	db	0
  1473                              <1> LinRedMaskSize23:	db	8
  1474                              <1> LinRedFieldPosition23:	db	16
  1475                              <1> LinGreenMaskSize23:	db	8
  1476                              <1> LinGreenFieldPosition23:db	8
  1477                              <1> LinBlueMaskSize23:	db	8
  1478                              <1> LinBlueFieldPosition23:	db	0
  1479                              <1> LinRsvdMaskSize23:	db	0
  1480                              <1> LinRsvdFieldPosition23:	db	0
  1481                              <1> MaxPixelClock23:	dd	0
  1482                              <1> 
  1483                              <1> 			dw	0192h ; 1920x1080x32
  1484                              <1> ModeAttributes24: 	dw	MODE_ATTRIBUTES
  1485                              <1> WinAAttributes24: 	db	WINA_ATTRIBUTES
  1486                              <1> WinBAttributes24: 	db	0
  1487                              <1> WinGranularity24: 	dw	VBE_DISPI_BANK_SIZE_KB
  1488                              <1> WinSize24: 		dw	VBE_DISPI_BANK_SIZE_KB
  1489                              <1> WinASegment24:		dw	VGAMEM_GRAPH
  1490                              <1> WinBSegment24:		dw	0000h
  1491                              <1> WinFuncPtr24:		dd	0
  1492                              <1> BytesPerScanLine24:	dw	7680
  1493                              <1> XResolution24:		dw	1920
  1494                              <1> YResolution24:		dw	1080
  1495                              <1> XCharSize24:		db	8
  1496                              <1> YCharSize24:		db	16
  1497                              <1> NumberOfPlanes24:	db	1
  1498                              <1> BitsPerPixel24:		db	32
  1499                              <1> NumberOfBanks24:	db	127
  1500                              <1> MemoryModel24:		db	VBE_MEMORYMODEL_DIRECT_COLOR
  1501                              <1> BankSize24:		db	0
  1502                              <1> NumberOfImagePages24:	db	1
  1503                              <1> Reserved_page24:	db	0
  1504                              <1> RedMaskSize24:		db	8
  1505                              <1> RedFieldPosition24:	db	16
  1506                              <1> GreenMaskSize24:	db	8
  1507                              <1> GreenFieldPosition24:	db	8
  1508                              <1> BlueMaskSize24:		db	8
  1509                              <1> BlueFieldPosition24:	db	0
  1510                              <1> RsvdMaskSize24:		db	8
  1511                              <1> RsvdFieldPosition24:	db	24
  1512                              <1> DirectColorModeInfo24:	db	VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE
  1513                              <1> PhysBasePtr24:		dd	VBE_DISPI_LFB_PHYSICAL_ADDRESS
  1514                              <1> OffScreenMemOffset24:	dd	0
  1515                              <1> OffScreenMemSize24:	dw	0
  1516                              <1> LinBytesPerScanLine24:	dw 	7680
  1517                              <1> BnkNumberOfPages24: 	db	0
  1518                              <1> LinNumberOfPages24: 	db	0
  1519                              <1> LinRedMaskSize24:	db	8
  1520                              <1> LinRedFieldPosition24:	db	16
  1521                              <1> LinGreenMaskSize24:	db	8
  1522                              <1> LinGreenFieldPosition24:db	8
  1523                              <1> LinBlueMaskSize24:	db	8
  1524                              <1> LinBlueFieldPosition24:	db	0
  1525                              <1> LinRsvdMaskSize24:	db	8
  1526                              <1> LinRsvdFieldPosition24:	db	24
  1527                              <1> MaxPixelClock24:	dd	0
  1528                              <1> 
  1529                              <1> VBE_VESA_MODE_END_OF_LIST: dw	0
  1530                              <1> 
  1531                              <1> %endif
  1532                              <1> 
  1533                              <1> ; 24/11/2020
  1534                              <1> 
  1535                              <1> direct_color_fields:
  1536                              <1> 	; 24/11/2020
  1537                              <1> 
  1538                              <1> ; (vbetables-gen.c)
  1539                              <1> ; // Direct Color fields 
  1540                              <1> ; (required for direct/6 and YUV/7 memory models)
  1541                              <1> ; switch(pm->depth) {
  1542                              <1>     
  1543                              <1> ;case 8:
  1544 00006C2A 00                  <1> r_size_8:  db 0
  1545 00006C2B 00                  <1> r_pos_8:   db 0
  1546 00006C2C 00                  <1> g_size_8:  db 0
  1547 00006C2D 00                  <1> g_pos_8:   db 0
  1548 00006C2E 00                  <1> b_size_8:  db 0
  1549 00006C2F 00                  <1> b_pos_8:   db 0
  1550 00006C30 00                  <1> a_size_8:  db 0
  1551 00006C31 00                  <1> a_pos_8:   db 0
  1552                              <1> 
  1553                              <1> ;case 16:
  1554 00006C32 05                  <1> r_size_16:  db 5
  1555 00006C33 0B                  <1> r_pos_16:   db 11
  1556 00006C34 06                  <1> g_size_16:  db 6
  1557 00006C35 05                  <1> g_pos_16:   db 5
  1558 00006C36 05                  <1> b_size_16:  db 5
  1559 00006C37 00                  <1> b_pos_16:   db 0
  1560 00006C38 00                  <1> a_size_16:  db 0
  1561 00006C39 00                  <1> a_pos_16:   db 0
  1562                              <1> 
  1563                              <1> ;case 24:
  1564 00006C3A 08                  <1> r_size_24:  db 8
  1565 00006C3B 10                  <1> r_pos_24:   db 16
  1566 00006C3C 08                  <1> g_size_24:  db 8
  1567 00006C3D 08                  <1> g_pos_24:   db 8
  1568 00006C3E 08                  <1> b_size_24:  db 8
  1569 00006C3F 00                  <1> b_pos_24:   db 0
  1570 00006C40 00                  <1> a_size_24:  db 0
  1571 00006C41 00                  <1> a_pos_24:   db 0
  1572                              <1> 
  1573                              <1> ;case 32:
  1574 00006C42 08                  <1> r_size_32:  db 8
  1575 00006C43 10                  <1> r_pos_32:   db 16
  1576 00006C44 08                  <1> g_size_32:  db 8
  1577 00006C45 08                  <1> g_pos_32:   db 8
  1578 00006C46 08                  <1> b_size_32:  db 8
  1579 00006C47 00                  <1> b_pos_32:   db 0
  1580 00006C48 08                  <1> a_size_32:  db 8
  1581 00006C49 18                  <1> a_pos_32:   db 24
  3423                                  ;%include 'diskdata.s'	; DISK (BIOS) DATA (initialized)
  3424                                  ;;;
  3425                                  
  3426                                  Align 2
  3427                                  
  3428                                  %include 'sysdefs.s' ; 24/01/2015
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.5) - SYSTEM DEFINITIONS : sysdefs.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 23/07/2022  (Previous: 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> ; 23/07/2022
   255                              <1> OPENFILES	   equ 32  ; max. number of open files (system)
   256                              <1> ; 07/10/2016
   257                              <1> ;NUMOFDEVICES	   equ 20  ; max. num of available devices (sys)
   258                              <1> 			 		
  3429                                  %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
  3430                                  %include 'trdosk1.s' ; 04/01/2016 
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.9) - SYS INIT : trdosk1.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 26/09/2024 (Previous: 25/07/2022)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 04/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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> 	; 26/09/2024 (TRDOS v2.0.9)
    18                              <1> 	; 18/04/2021 (TRDOS 386 v2.0.4)
    19                              <1> 	; 20/01/2018  (v2.0.1)
    20                              <1> 	; 23/01/2017  (v2.0.0)
    21                              <1> 	; 07/05/2016
    22                              <1> 	; 02/05/2016
    23                              <1> 	; 24/04/2016
    24                              <1> 	; 14/04/2016
    25                              <1> 	; 13/04/2016
    26                              <1> 	; 30/03/2016
    27                              <1> 	; 24/01/2016
    28                              <1> 	; 06/01/2016
    29                              <1> 	; 04/01/2016 (TRDOS 386 v2.0 - Beginning)
    30                              <1> 
    31                              <1> 	; 23/01/2017 - reset timer frequency (to 18.2Hz)
    32 00006C4A B036                <1> 	mov	al, 00110110b ; 36h
    33 00006C4C E643                <1>  	out	43h, al
    34 00006C4E 31C0                <1> 	xor	eax, eax  ; sub	al, al ; 0
    35 00006C50 E640                <1> 	out	40h, al ; LB
    36 00006C52 E640                <1> 	out	40h, al ; HB
    37                              <1>  	;
    38                              <1> 	; 30/03/2016
    39                              <1> 	; Clear Logical DOS Disk Description Tables Area
    40                              <1> 	;xor	eax, eax
    41 00006C54 BF00010900          <1> 	mov	edi, Logical_DOSDisks
    42 00006C59 B980060000          <1> 	mov	ecx, 6656/4 ; 26*256 = 6656 bytes
    43 00006C5E F3AB                <1> 	rep	stosd ; 1664 times 4 bytes
    44                              <1> 
    45 00006C60 B83F3A2F00          <1> 	mov	eax, '?:/'
    46 00006C65 A3[837D0100]        <1> 	mov	[Current_Dir_Drv], eax
    47                              <1> 
    48                              <1> 	; Logical DRV INIT (only for hard disks)
    49 00006C6A E8C3030000          <1> 	call 	ldrv_init  ; trdosk2.s
    50                              <1> 
    51                              <1> 	; When floppy_drv_init call is disabled
    52                              <1> 	; media changed sign is needed
    53                              <1> 	; for proper drive initialization
    54                              <1> 
    55 00006C6F BE00010900          <1> 	mov 	esi, Logical_DOSDisks
    56 00006C74 B001                <1> 	mov 	al, 1 ; Initialization sign (invalid_fd_parameter)
    57 00006C76 83C67E              <1> 	add 	esi, LD_MediaChanged ; Media Change Status = 1 (init needed)
    58 00006C79 8806                <1> 	mov 	[esi], al ; A:
    59                              <1> 	; Temporary - 26/09/2024
    60                              <1> 	;;mov	dword [esi+LD_Clusters], -1 ; *
    61                              <1> 	;dec	dword [esi+LD_Clusters]
    62 00006C7B 81C600010000        <1> 	add 	esi, 100h 
    63 00006C81 8806                <1> 	mov 	[esi], al ; B:
    64                              <1> 	;;mov	dword [esi+LD_Clusters], -1 ; *
    65                              <1> 	;dec	dword [esi+LD_Clusters]
    66                              <1> 
    67                              <1> _current_drive_bootdisk:
    68 00006C83 8A15[38660000]      <1> 	mov 	dl, [boot_drv] ; physical drive number
    69 00006C89 80FAFF              <1> 	cmp 	dl, 0FFh
    70 00006C8C 740A                <1> 	je 	short _last_dos_diskno_check
    71                              <1> _boot_drive_check:
    72 00006C8E 80FA80              <1> 	cmp 	dl, 80h
    73 00006C91 7218                <1> 	jb 	short _current_drive_a
    74 00006C93 80EA7E              <1> 	sub 	dl, 7Eh ; C = 2 , D = 3
    75 00006C96 EB13                <1> 	jmp 	short _current_drive_a
    76                              <1> 
    77                              <1> _last_dos_diskno_check:
    78 00006C98 8A15[9A340100]      <1> 	mov 	dl, [Last_DOS_DiskNo]
    79 00006C9E 80FA02              <1> 	cmp 	dl, 2
    80 00006CA1 7706                <1> 	ja 	short _current_drive_c
    81 00006CA3 7406                <1> 	je 	short _current_drive_a
    82 00006CA5 30D2                <1> 	xor 	dl, dl ; A:
    83 00006CA7 EB02                <1> 	jmp 	short _current_drive_a
    84                              <1> 
    85                              <1> _current_drive_c:
    86 00006CA9 B202                <1> 	mov 	dl, 2 ; C:
    87                              <1> 
    88                              <1> _current_drive_a:
    89 00006CAB 8815[39660000]      <1> 	mov	[drv], dl
    90 00006CB1 BE[9C340100]        <1>         mov     esi, msg_CRLF_temp
    91 00006CB6 E8AF000000          <1> 	call 	print_msg
    92                              <1> 
    93 00006CBB 8A15[39660000]      <1> 	mov	dl, [drv]
    94                              <1> _default_drive_c:
    95 00006CC1 E8B70B0000          <1> 	call 	change_current_drive
    96 00006CC6 731C                <1> 	jnc 	short _start_mainprog
    97                              <1> 
    98                              <1> _drv_not_ready_error: 
    99 00006CC8 BE[5F370100]        <1> 	mov 	esi, msgl_drv_not_ready
   100 00006CCD E898000000          <1> 	call 	print_msg
   101                              <1>         ;jmp	_end_of_mainprog
   102                              <1> 
   103                              <1> 	; 20/01/2018
   104 00006CD2 B202                <1> 	mov	dl, 2
   105 00006CD4 3815[39660000]      <1> 	cmp	[drv], dl
   106 00006CDA 736C                <1> 	jnb	short _end_of_mainprog
   107 00006CDC 8815[39660000]      <1> 	mov	[drv], dl
   108 00006CE2 EBDD                <1> 	jmp	short _default_drive_c
   109                              <1> 
   110                              <1> _start_mainprog:
   111                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   112                              <1> 	; 18/04/2021 (TRDOS 386 v2.0.4 - Beginning)
   113                              <1> 	; 07/01/2017
   114                              <1> 	; 07/05/2016
   115                              <1> 	; 02/05/2016
   116                              <1> 	; 24/04/2016 (TRDOS 386 v2)
   117                              <1> 	; Retro UNIX 386 v1, 'sys_init' (u0.s)
   118                              <1> 	; 23/06/2015
   119                              <1> 
   120                              <1> 	; 02/05/2016
   121                              <1> 	; 24/04/2016
   122                              <1> 	;mov	ax, 1
   123                              <1> 	; 18/04/2021 - TRDOS 386 v2.0.4
   124 00006CE4 31C0                <1> 	xor	eax, eax
   125 00006CE6 FEC0                <1> 	inc	al  ; eax = 1
   126 00006CE8 A2[C5940100]        <1> 	mov	[u.uno], al
   127 00006CED 66A3[5C940100]      <1> 	mov	[mpid], ax
   128 00006CF3 66A3[48930100]      <1> 	mov	[p.pid], ax
   129 00006CF9 A2[A8930100]        <1> 	mov	[p.stat], al
   130 00006CFE C605[BC940100]04    <1> 	mov	byte [u.quant], time_count  ; 07/01/2017
   131                              <1> 	;
   132 00006D05 A1[C07C0100]        <1> 	mov	eax, [k_page_dir]
   133 00006D0A A3[CC940100]        <1> 	mov	[u.pgdir], eax ; reset
   134                              <1> 	;
   135 00006D0F E8CCEAFFFF          <1> 	call	allocate_page
   136                              <1> 	;jc	panic
   137                              <1> 	; 25/07/2022
   138 00006D14 7305                <1> 	jnc	short _start_mainprog_1
   139 00006D16 E9AE000000          <1> 	jmp	panic
   140                              <1> 
   141                              <1> _start_mainprog_1:
   142 00006D1B A3[C8940100]        <1> 	mov	[u.upage], eax ; user structure page
   143 00006D20 A3[B8930100]        <1> 	mov	[p.upage], eax
   144 00006D25 E827EBFFFF          <1> 	call	clear_page
   145                              <1> 	;
   146                              <1> 	; 24/08/2015
   147 00006D2A FE0D[68940100]      <1> 	dec 	byte [sysflg] ; FFh = ready for system call
   148                              <1> 			      ; 0 = executing a system call
   149                              <1> 	; 13/04/2016
   150                              <1> 	; Clear Environment Variables Page/Area
   151 00006D30 BF00300900          <1> 	mov	edi, Env_Page ; 93000h
   152 00006D35 B980000000          <1> 	mov	ecx, Env_Page_Size / 4	; 512/4  (4096/4)
   153 00006D3A 31C0                <1> 	xor	eax, eax
   154 00006D3C F3AB                <1> 	rep	stosd
   155                              <1> 
   156                              <1> 	; 14/04/2016
   157 00006D3E E817330000          <1>  	call	mainprog_startup_configuration
   158                              <1> 
   159 00006D43 E8720C0000          <1>         call    dos_prompt
   160                              <1> 
   161                              <1> _end_of_mainprog:
   162 00006D48 BE[9C340100]        <1>         mov     esi, msg_CRLF_temp
   163 00006D4D E818000000          <1> 	call 	print_msg
   164 00006D52 BE[A2340100]        <1> 	mov 	esi, mainprog_Version
   165 00006D57 E80E000000          <1> 	call 	print_msg
   166                              <1> 	; 24/01/2016
   167 00006D5C 28E4                <1> 	sub	ah, ah
   168 00006D5E E8B9A1FFFF          <1> 	call	int16h ; call getch
   169 00006D63 E947A6FFFF          <1> 	jmp	cpu_reset
   170                              <1> 
   171 00006D68 EBFE                <1> infinitiveloop: jmp short infinitiveloop
   172                              <1> 
   173                              <1> print_msg:
   174                              <1> 	; 13/05/2016
   175                              <1> 	; 04/01/2016
   176                              <1> 	; 01/07/2015
   177                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
   178                              <1> 	; 07/03/2014 (Retro UNIX 8086 v1)
   179                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI, EDI)
   180                              <1> 	;
   181 00006D6A 8A3D[EE7C0100]      <1> 	mov	bh, [ACTIVE_PAGE] ; 04/01/2016 (ptty)
   182                              <1> 	;mov	bl, 07h ; Black background, light gray forecolor
   183                              <1> 
   184 00006D70 AC                  <1> 	lodsb
   185                              <1> pmsg1:
   186 00006D71 56                  <1> 	push 	esi
   187                              <1> 	;mov	bh, [ACTIVE_PAGE] ; 04/01/2016 (ptty)
   188 00006D72 B307                <1> 	mov	bl, 07h ; Black background, light gray forecolor
   189 00006D74 E81CB5FFFF          <1> 	call 	_write_tty
   190 00006D79 5E                  <1> 	pop	esi
   191 00006D7A AC                  <1> 	lodsb
   192 00006D7B 20C0                <1> 	and 	al, al
   193 00006D7D 75F2                <1> 	jnz 	short pmsg1
   194 00006D7F C3                  <1> 	retn
   195                              <1> 
   196                              <1> clear_screen:
   197                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   198                              <1> 	; 06/12/2020 
   199                              <1> 	; 03/12/2020 (TRDOS 386 v2.0.3)
   200                              <1> 	; 13/05/2016
   201                              <1> 	; 30/01/2016
   202                              <1> 	; 24/01/2016
   203                              <1> 	; 04/01/2016
   204 00006D80 0FB61D[EE7C0100]    <1> 	movzx	ebx, byte [ACTIVE_PAGE] ; video page number (0 to 7)
   205                              <1> 	; 25/07/2022
   206                              <1> 	;sub	al, al
   207                              <1> 	; al = 0
   208 00006D87 8AA3[EF670000]      <1> 	mov 	ah, [ebx+vmode] ; default = 03h (80x25 text)
   209 00006D8D 80FC04              <1> 	cmp	ah, 4
   210 00006D90 7205                <1> 	jb	short cls1
   211 00006D92 80FC07              <1> 	cmp	ah, 7
   212 00006D95 752B                <1> 	jne	short vga_clear
   213                              <1> cls1:
   214                              <1> 	;mov	bh, bl
   215                              <1> 	;mov	bl, 7
   216 00006D97 3A25[DE670000]      <1> 	cmp	ah, [CRT_MODE] ; current video mode ? 
   217 00006D9D 740D                <1> 	je	short cls2 ; yes (current video mode = 3)
   218                              <1> 	;;call	set_mode_3 ; set video mode to 3 (& clear screen)
   219                              <1> 	;;retn
   220                              <1> 	; 06/12/2020
   221                              <1> 	;cmp	byte [pmi32], 0
   222                              <1> 	; 25/07/2022
   223 00006D9F 383D[2CA30100]      <1> 	cmp	[pmi32], bh ; 0
   224 00006DA5 771B                <1> 	ja	short vga_clear
   225 00006DA7 E9F3B4FFFF          <1> 	jmp	set_mode_3
   226                              <1> cls2:
   227 00006DAC 88DF                <1> 	mov	bh, bl ; video page (0 to 7)
   228 00006DAE B307                <1> 	mov	bl, 07h ; attribute to be used on blanked line
   229                              <1> 	; 25/07/2022
   230                              <1> 	;sub 	al, al ; 0 = entire window
   231                              <1> 	;xor 	cx, cx
   232                              <1> 	; 25/07/2022
   233                              <1> 	; al = 0
   234 00006DB0 31C9                <1> 	xor	ecx, ecx
   235 00006DB2 66BA4F18            <1> 	mov 	dx, 184Fh
   236 00006DB6 E82CB2FFFF          <1> 	call	_scroll_up ; 24/01/2016
   237                              <1> 	;
   238                              <1> 	;mov	bh, [ACTIVE_PAGE] ; video page number (0 to 7)
   239                              <1> 	;xor 	dx, dx
   240                              <1> 	; 25/07/2022
   241 00006DBB 31D2                <1> 	xor	edx, edx
   242                              <1> 	;call	_set_cpos ; 24/01/2016 
   243                              <1> 	;;retn
   244                              <1> 	; 03/12/2020
   245 00006DBD E96BB5FFFF          <1> 	jmp	_set_cpos ; returns to the caller of this proc
   246                              <1> ;cls3:
   247                              <1> ;	retn
   248                              <1> 
   249                              <1> 	; 06/12/2020
   250                              <1> vga_clear:
   251                              <1> 	; 03/12/2020
   252                              <1> 	; set mode by using _int10h
   253                              <1> 	; (also clears screen)
   254                              <1> 	;mov	al, ah
   255                              <1> 	;sub	ah, ah  ; set current video mode
   256                              <1> 	; 25/07/2022
   257 00006DC2 86C4                <1> 	xchg	ah, al
   258                              <1> 	; ah = 0
   259                              <1> 	; al = video mode
   260                              <1> 	;call	_int10h ; simulates int 10h in TRDOS 386 kernel
   261                              <1> 	;jmp	short cls3
   262 00006DC4 E95BA9FFFF          <1> 	jmp	_int10h ; returns to the caller of this proc
   263                              <1> 
   264                              <1> panic:
   265                              <1> 	; 13/05/2016 (TRDOS 386 = TRDOS v2)
   266                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
   267                              <1> 	; 07/03/2014 (Retro UNIX 8086 v1)
   268 00006DC9 BE[4F3F0100]        <1> 	mov 	esi, panic_msg
   269 00006DCE E897FFFFFF          <1> 	call 	print_msg
   270                              <1> key_to_reboot:
   271                              <1>         ; 24/01/2016
   272 00006DD3 28E4                <1>         sub     ah, ah
   273 00006DD5 E842A1FFFF          <1>         call    int16h	; call getch
   274                              <1>         ; wait for a character from the current tty
   275                              <1> 	;
   276 00006DDA B00A                <1> 	mov	al, 0Ah
   277 00006DDC 8A3D[EE7C0100]      <1> 	mov	bh, [ptty] ; [ACTIVE_PAGE]
   278 00006DE2 B307                <1> 	mov	bl, 07h ; Black background, 
   279                              <1> 			; light gray forecolor
   280 00006DE4 E8ACB4FFFF          <1> 	call 	_write_tty
   281 00006DE9 E9C1A5FFFF          <1> 	jmp	cpu_reset
   282                              <1> 
   283                              <1> ctrlbrk:
   284                              <1> 	; 21/08/2024 (TRDOS 386 Kernel v2.0.9)
   285                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   286                              <1> 	; 12/11/2015
   287                              <1> 	; 13/03/2015 (Retro UNIX 386 v1)
   288                              <1> 	; 06/12/2013 (Retro UNIX 8086 v1)
   289                              <1> 	;
   290                              <1> 	; INT 1Bh (control+break) handler
   291                              <1> 	;
   292                              <1>       	; Retro Unix 8086 v1 feature only!
   293                              <1>       	;
   294                              <1> 
   295                              <1> 	; 25/07/2022
   296 00006DEE 52                  <1> 	push	edx
   297 00006DEF 31D2                <1> 	xor	edx, edx
   298                              <1> 
   299                              <1> ; 21/08/2024 - TRDOS 386 v2.0.9
   300                              <1> %if 0
   301                              <1> 	;cmp 	word [u.intr], 0
   302                              <1> 	cmp	[u.intr], dx ; 0
   303                              <1> 	jna 	short cbrk4
   304                              <1> cbrk0:
   305                              <1> 	; 12/11/2015
   306                              <1> 	; 06/12/2013
   307                              <1> 	;cmp 	word [u.quit], 0
   308                              <1> 	cmp	[u.quit], dx ; 0 ; 25/07/2022
   309                              <1> 	jz	short cbrk4
   310                              <1> %endif
   311                              <1> 	; 20/09/2013
   312                              <1> 	;push 	ax
   313 00006DF1 50                  <1> 	push	eax ; 25/07/2022
   314 00006DF2 A0[EE7C0100]        <1> 	mov	al, [ptty]
   315                              <1> 
   316                              <1> ; 21/08/2024 - TRDOS 386 v2.0.9
   317                              <1> %if 1
   318 00006DF7 3A05[AA940100]      <1> 	cmp	al, [u.ttyn]
   319 00006DFD 7509                <1> 	jne	short cbrk3
   320                              <1> %else
   321                              <1> 	; 12/11/2015
   322                              <1> 	;
   323                              <1> 	; ctrl+break (EOT, CTRL+D) from serial port
   324                              <1> 	; or ctrl+break from console (pseudo) tty
   325                              <1> 	; (!redirection!)
   326                              <1> 
   327                              <1> 	cmp	al, 8 ; serial port tty nums > 7
   328                              <1>         jb      short cbrk1 ; console (pseudo) tty
   329                              <1> 
   330                              <1> 	; Serial port interrupt handler sets [ptty]
   331                              <1> 	; to the port's tty number (as temporary).
   332                              <1> 	;
   333                              <1> 	; If active process is using a stdin or
   334                              <1> 	; stdout redirection (by the shell),
   335                              <1>         ; console tty keyboard must be available
   336                              <1> 	; to terminate running process,
   337                              <1> 	; in order to prevent a deadlock.
   338                              <1> 
   339                              <1> 	; 25/07/2022
   340                              <1> 	;push	edx
   341                              <1> 	;movzx	edx, byte [u.uno]
   342                              <1> 	mov	dl, [u.uno]
   343                              <1> 	cmp     al, [edx+p.ttyc-1] ; console tty (rw)
   344                              <1> 	;pop	edx
   345                              <1> 	je	short cbrk2
   346                              <1> cbrk1:
   347                              <1> 	inc 	al  ; [u.ttyp] : 1 based tty number
   348                              <1> 	; 06/12/2013
   349                              <1> 	cmp	al, [u.ttyp]   ; recent open tty (r)
   350                              <1> 	je	short cbrk2
   351                              <1>         cmp     al, [u.ttyp+1] ; recent open tty (w)
   352                              <1> 	jne	short cbrk3
   353                              <1> cbrk2:
   354                              <1> 	;; 06/12/2013
   355                              <1> 	;mov	ax, [u.quit]
   356                              <1> 	;and	ax, ax
   357                              <1> 	;jz	short cbrk3
   358                              <1> %endif
   359                              <1> 	;xor	ax, ax ; 0
   360                              <1> 	;dec	ax
   361                              <1> 	; 0FFFFh = 'ctrl+brk' keystroke
   362                              <1> 	; 25/07/2022
   363                              <1> 	;xor	eax, eax ; 0
   364                              <1> 	;dec	eax ; -1 ; 0FFFFFFFFh
   365                              <1> 	;mov	[u.quit], ax
   366                              <1> 	; 21/08/2024
   367                              <1> 	; set CTRL+BREAK flag (even if it is not activated)
   368                              <1> 	; (u.intr is it's activation flag, 0 = disabled))
   369 00006DFF 66C705[C2940100]FF- <1> 	mov	word [u.quit], -1 ; 0FFFFh
   369 00006E07 FF                  <1>
   370                              <1> cbrk3:
   371                              <1> 	;pop	ax
   372 00006E08 58                  <1> 	pop	eax ; 25/07/2022
   373                              <1> cbrk4:
   374                              <1> 	; 25/07/2022
   375 00006E09 5A                  <1> 	pop	edx
   376 00006E0A C3                  <1> 	retn
   377                              <1> 
   378                              <1> ; 31/12/2017
   379                              <1> ; TRDOS 386 - 30/12/2017
   380                              <1> %define get_rtc_date RTC_40
   381                              <1> %define get_rtc_time RTC_20
   382                              <1> %define	set_rtc_date RTC_50
   383                              <1> %define set_rtc_time RTC_30
   384                              <1> get_rtc_date_time:
   385                              <1> ; Retro UNIX 8086 v1 - UNIX.ASM (01/09/2014)
   386                              <1> ;epoch:
   387                              <1> 	; 18/04/2021 (TRDOS 386 v2.0.3)
   388                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0)
   389                              <1> 	; 15/03/2015 (Retro UNIX 386 v1 - 32 bit version)
   390                              <1> 	; 09/04/2013 (Retro UNIX 8086 v1 - UNIX.ASM)
   391                              <1> 	; 'epoch' procedure prototype: 
   392                              <1> 	; 	            UNIXCOPY.ASM, 10/03/2013
   393                              <1> 	; 14/11/2012
   394                              <1> 	; unixboot.asm (boot file configuration)
   395                              <1> 	; version of "epoch" procedure in "unixproc.asm"
   396                              <1> 	; 21/7/2012
   397                              <1> 	; 15/7/2012
   398                              <1> 	; 14/7/2012
   399                              <1> 	; Erdogan Tan - RETRO UNIX v0.1
   400                              <1> 	; compute current date and time as UNIX Epoch/Time
   401                              <1> 	; UNIX Epoch: seconds since 1/1/1970 00:00:00
   402                              <1> 	;
   403                              <1>         ;  ((Modified registers: EAX, EDX, ECX, EBX))
   404                              <1> 	;
   405                              <1> 
   406                              <1> 	; 18/04/2021
   407                              <1> 	; INPUT:
   408                              <1> 	;	none (real time clock)
   409                              <1> 	; OUTPUT:
   410                              <1> 	;	eax = unix epoch time value
   411                              <1> 	;	    (seconds since 1/1/1970 00:00:00)
   412                              <1> 
   413 00006E0B E8FBF4FFFF          <1> 	call 	get_rtc_time		; Return Current Time
   414                              <1>         ;xchg 	ch, cl ; 18/04/2021
   415 00006E10 66890D[8E790100]    <1>         mov 	[hour], cx    ; BCD, cl = minute, ch = hour
   416                              <1>         ;xchg 	dh, dl ; 18/04/2021
   417                              <1> 	;mov 	[second], dx  ; BCD, dh = second, dl = dse
   418                              <1> 	; 18/04/2021
   419 00006E17 8835[92790100]      <1> 	mov	[second], dh  ; second
   420                              <1> 	;
   421 00006E1D E854F5FFFF          <1>         call 	get_rtc_date		; Return Current Date
   422                              <1>         ;xchg 	ch, cl ; 18/04/2021
   423 00006E22 66890D[88790100]    <1>         mov 	[year], cx    ; BCD, cl = year, ch = century
   424                              <1>         ;xchg 	dh, dl ; 18/04/2021
   425 00006E29 668915[8A790100]    <1>         mov 	[month], dx   ; BCD, dl = day, dh = month
   426                              <1> 	;
   427                              <1> 	;mov 	al, [hour]    ; Hour
   428                              <1>         ; 18/04/2021
   429 00006E30 A0[8F790100]        <1> 	mov	al, [hour+1]  ; Hour
   430                              <1> 	   	; AL <-- BCD number
   431 00006E35 D410                <1>         db 	0D4h, 10h		; Undocumented inst. AAM
   432                              <1> 					; AH = AL / 10h
   433                              <1> 					; AL = AL MOD 10h
   434 00006E37 D50A                <1>         aad 	; AX= AH*10+AL
   435                              <1> 	;mov 	[hour], al
   436                              <1> 	;mov 	al, [hour+1]  ; Minute
   437 00006E39 8605[8E790100]      <1> 	xchg	al, [hour]    ; [hour] = hour, al = minute
   438                              <1> 	   	; AL <-- BCD number
   439 00006E3F D410                <1>         db 	0D4h, 10h		; Undocumented inst. AAM
   440                              <1> 					; AH = AL / 10h
   441                              <1> 					; AL = AL MOD 10h
   442 00006E41 D50A                <1>         aad 	; AX= AH*10+AL
   443 00006E43 A2[90790100]        <1> 	mov 	[minute], al
   444 00006E48 A0[92790100]        <1> 	mov 	al, [second]  ; Second
   445                              <1> 	   	; AL <-- BCD number
   446 00006E4D D410                <1>         db 	0D4h, 10h		; Undocumented inst. AAM
   447                              <1> 					; AH = AL / 10h
   448                              <1> 					; AL = AL MOD 10h
   449 00006E4F D50A                <1>         aad 	; AX= AH*10+AL
   450 00006E51 A2[92790100]        <1> 	mov 	[second], al
   451 00006E56 66A1[88790100]      <1> 	mov 	ax, [year]    ; Year (century)
   452                              <1> 	; 18/04/2021
   453                              <1> 	;push 	eax ; puhs ax
   454                              <1> 	;mov	al, ah ; century ; 18/04/2021
   455                              <1> 	   	; AL <-- BCD number
   456 00006E5C D410                <1>         db 	0D4h, 10h		; Undocumented inst. AAM
   457                              <1> 					; AH = AL / 10h
   458                              <1> 					; AL = AL MOD 10h
   459 00006E5E D50A                <1>         aad 	; AX= AH*10+AL
   460                              <1> 	;mov 	ah, 100
   461                              <1> 	;mul 	ah
   462                              <1> 	;mov 	[year], ax
   463                              <1> 	; 18/04/2021
   464                              <1> 	; ax = al = year (0 to 99)
   465 00006E60 668705[88790100]    <1> 	xchg	ax, [year]    ; [year+1] = century -> ah
   466                              <1> 	;pop	eax ; pop ax
   467 00006E67 88E0                <1> 	mov	al, ah  ; century
   468                              <1> 	   	; AL <-- BCD number
   469 00006E69 D410                <1>         db 	0D4h, 10h		; Undocumented inst. AAM
   470                              <1> 					; AH = AL / 10h
   471                              <1> 					; AL = AL MOD 10h
   472 00006E6B D50A                <1>         aad 	; AX= AH*10+AL
   473                              <1> 	; 18/04/2021
   474 00006E6D B464                <1> 	mov	ah, 100	      ; 100*(century byte of year)
   475 00006E6F F6E4                <1> 	mul	ah
   476                              <1> 	;
   477 00006E71 660105[88790100]    <1> 	add 	[year], ax
   478                              <1> 	;mov 	al, [month]   ; Month
   479                              <1> 	; 18/04/2021
   480 00006E78 A0[8B790100]        <1> 	mov	al, [month+1] ; Month
   481                              <1> 	   	; AL <-- BCD number
   482 00006E7D D410                <1>         db 	0D4h, 10h		; Undocumented inst. AAM
   483                              <1> 					; AH = AL / 10h
   484                              <1> 					; AL = AL MOD 10h
   485 00006E7F D50A                <1>         aad 	; AX= AH*10+AL
   486                              <1> 	;mov 	[month], al
   487                              <1>         ;mov	al, [month+1] ; Day
   488                              <1> 	; 18/04/2021
   489 00006E81 8605[8A790100]      <1> 	xchg	al, [month]   ; [month] = month, al = day
   490                              <1> 	   	; AL <-- BCD number
   491 00006E87 D410                <1>         db 	0D4h, 10h		; Undocumented inst. AAM
   492                              <1> 					; AH = AL / 10h
   493                              <1> 					; AL = AL MOD 10h
   494 00006E89 D50A                <1>         aad 	; AX= AH*10+AL
   495 00006E8B A2[8C790100]        <1>         mov     [day], al
   496                              <1> 
   497 00006E90 C3                  <1> 	retn	; 30/12/2017
   498                              <1> 
   499                              <1> epoch:
   500 00006E91 E875FFFFFF          <1> 	call	get_rtc_date_time ; TRDOS 386 - 30/12/2017
   501                              <1> 
   502                              <1> convert_to_epoch:
   503                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   504                              <1> 	; 31/12/2017 (TRDOS 386 = TRDOS v2.0)
   505                              <1> 	; 15/03/2015 (Retro UNIX 386 v1 - 32 bit modification)
   506                              <1> 	; 09/04/2013 (Retro UNIX 8086 v1)
   507                              <1> 	;
   508                              <1> 	; ((Modified registers: EAX, EDX, EBX))
   509                              <1> 	;
   510                              <1> 	; Derived from DALLAS Semiconductor
   511                              <1> 	; Application Note 31 (DS1602/DS1603)
   512                              <1> 	; 6 May 1998
   513 00006E96 29C0                <1> 	sub 	eax, eax
   514 00006E98 66A1[88790100]      <1> 	mov 	ax, [year]
   515 00006E9E 662DB207            <1> 	sub 	ax, 1970
   516 00006EA2 BA6D010000          <1> 	mov 	edx, 365
   517 00006EA7 F7E2                <1> 	mul 	edx
   518 00006EA9 31DB                <1> 	xor 	ebx, ebx
   519 00006EAB 8A1D[8A790100]      <1> 	mov 	bl, [month]
   520 00006EB1 FECB                <1> 	dec 	bl
   521 00006EB3 D0E3                <1> 	shl 	bl, 1
   522                              <1> 	;sub	edx, edx
   523 00006EB5 668B93[94790100]    <1> 	mov 	dx, [EBX+DMonth]
   524 00006EBC 8A1D[8C790100]      <1>         mov     bl, [day]
   525 00006EC2 FECB                <1> 	dec 	bl
   526 00006EC4 01D0                <1> 	add 	eax, edx
   527 00006EC6 01D8                <1> 	add 	eax, ebx
   528                              <1> 			; EAX = days since 1/1/1970
   529 00006EC8 668B15[88790100]    <1> 	mov 	dx, [year]
   530 00006ECF 6681EAB107          <1> 	sub 	dx, 1969
   531                              <1> 	;shr 	dx, 1
   532                              <1> 	;shr 	dx, 1
   533                              <1> 	; 25/07/2022
   534 00006ED4 C1EA02              <1> 	shr	edx, 2
   535                              <1> 		; (year-1969)/4
   536 00006ED7 01D0                <1> 	add 	eax, edx
   537                              <1> 			; + leap days since 1/1/1970
   538 00006ED9 803D[8A790100]02    <1> 	cmp 	byte [month], 2	; if past february
   539 00006EE0 760E                <1> 	jna 	short cte1
   540 00006EE2 668B15[88790100]    <1> 	mov 	dx, [year]
   541 00006EE9 6683E203            <1> 	and 	dx, 3 ; year mod 4
   542 00006EED 7501                <1> 	jnz 	short cte1
   543                              <1> 			; and if leap year
   544                              <1> 	;add 	eax, 1 	; add this year's leap day (february 29)
   545                              <1> 	; 25/07/2022
   546 00006EEF 40                  <1> 	inc	eax
   547                              <1> cte1: 			; compute seconds since 1/1/1970
   548 00006EF0 BA18000000          <1> 	mov 	edx, 24
   549 00006EF5 F7E2                <1> 	mul	edx
   550 00006EF7 8A15[8E790100]      <1> 	mov 	dl, [hour]
   551 00006EFD 01D0                <1> 	add 	eax, edx
   552                              <1> 		; EAX = hours since 1/1/1970 00:00:00
   553                              <1> 	;mov	ebx, 60
   554 00006EFF B33C                <1> 	mov	bl, 60
   555 00006F01 F7E3                <1> 	mul	ebx
   556 00006F03 8A15[90790100]      <1> 	mov 	dl, [minute]
   557 00006F09 01D0                <1> 	add 	eax, edx
   558                              <1> 		; EAX = minutes since 1/1/1970 00:00:00
   559                              <1> 	;mov 	ebx, 60
   560 00006F0B F7E3                <1> 	mul	ebx
   561 00006F0D 8A15[92790100]      <1> 	mov 	dl, [second]
   562 00006F13 01D0                <1> 	add 	eax, edx
   563                              <1>  		; EAX -> seconds since 1/1/1970 00:00:00
   564 00006F15 C3                  <1> 	retn
   565                              <1> 
   566                              <1> ;set_date_time:
   567                              <1> convert_from_epoch:
   568                              <1> 	; 25/07/2022 (v2.0.5)
   569                              <1> 	; 18/04/2021 (v2.0.4)
   570                              <1> 	; 31/12/2017 (v2.0.0)
   571                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0)
   572                              <1> 	; 15/03/2015 (Retro UNIX 386 v1 - 32 bit version)
   573                              <1> 	; 20/06/2013 (Retro UNIX 8086 v1)
   574                              <1> 	; 'convert_from_epoch' procedure prototype:
   575                              <1> 	; 	            UNIXCOPY.ASM, 10/03/2013
   576                              <1> 	;
   577                              <1> 	; ((Modified registers: EAX, EDX, ECX, EBX))
   578                              <1> 	;
   579                              <1> 	; Derived from DALLAS Semiconductor
   580                              <1> 	; Application Note 31 (DS1602/DS1603)
   581                              <1> 	; 6 May 1998
   582                              <1> 	;
   583                              <1> 	; INPUT:
   584                              <1> 	; EAX = Unix (Epoch) Time
   585                              <1> 	;
   586 00006F16 31D2                <1> 	xor 	edx, edx
   587                              <1> 	;mov 	ecx, 60
   588                              <1> 	; 25/07/2022
   589 00006F18 29C9                <1> 	sub	ecx, ecx
   590 00006F1A B13C                <1> 	mov	cl, 60
   591 00006F1C F7F1                <1> 	div	ecx
   592                              <1> 	;mov 	[imin], eax   ; whole minutes
   593                              <1> 			  ; since 1/1/1970
   594 00006F1E 668915[92790100]    <1> 	mov 	[second], dx  ; leftover seconds
   595 00006F25 29D2                <1> 	sub 	edx, edx
   596 00006F27 F7F1                <1> 	div	ecx
   597                              <1> 	;mov 	[ihrs], eax   ; whole hours
   598                              <1> 	;		      ; since 1/1/1970
   599 00006F29 668915[90790100]    <1> 	mov 	[minute], dx  ; leftover minutes
   600 00006F30 31D2                <1> 	xor	edx, edx
   601                              <1> 	;mov 	cx, 24
   602 00006F32 B118                <1> 	mov 	cl, 24
   603 00006F34 F7F1                <1> 	div	ecx
   604                              <1> 	;mov 	[iday], ax   ; whole days
   605                              <1> 			     ; since 1/1/1970
   606 00006F36 668915[8E790100]    <1> 	mov 	[hour], dx   ; leftover hours
   607 00006F3D 05DB020000          <1> 	add 	eax, 365+366 ; whole day since
   608                              <1> 			     ; 1/1/1968
   609                              <1> 	;mov 	[iday], ax
   610 00006F42 50                  <1> 	push 	eax
   611 00006F43 29D2                <1> 	sub	edx, edx
   612                              <1> 	;mov 	ecx, (4*365)+1 ; 4 years = 1461 days
   613                              <1> 	; 25/07/2022
   614 00006F45 66B9B505            <1> 	mov	cx, (4*365)+1
   615 00006F49 F7F1                <1> 	div	ecx
   616 00006F4B 59                  <1> 	pop 	ecx
   617                              <1> 	;mov 	[lday], ax   ; count of quadyrs (4 years)
   618                              <1> 	;push 	dx
   619                              <1> 	; 18/04/2021
   620 00006F4C 52                  <1> 	push	edx
   621                              <1> 	;mov 	[qday], dx   ; days since quadyr began
   622 00006F4D 6683FA3C            <1> 	cmp 	dx, 31+29    ; if past feb 29 then
   623 00006F51 F5                  <1> 	cmc		     ; add this quadyr's leap day
   624 00006F52 83D000              <1> 	adc 	eax, 0	     ; to # of qadyrs (leap days)
   625                              <1> 	;mov 	[lday], ax   ; since 1968
   626                              <1> 	;mov 	cx, [iday]
   627 00006F55 91                  <1> 	xchg 	ecx, eax     ; ECX = lday, EAX = iday
   628 00006F56 29C8                <1> 	sub 	eax, ecx     ; iday - lday
   629                              <1> 	;mov 	ecx, 365
   630                              <1> 	; 25/07/2022
   631 00006F58 66B96D01            <1> 	mov	cx, 365
   632 00006F5C 31D2                <1> 	xor	edx, edx
   633                              <1> 	; EAX = iday-lday, EDX = 0
   634 00006F5E F7F1                <1> 	div	ecx
   635                              <1> 	;mov 	[iyrs], ax   ; whole years since 1968
   636                              <1> 	;jday = iday - (iyrs*365) - lday
   637                              <1> 	;mov	[jday], dx   ; days since 1/1 of current year
   638                              <1> 	;add	eax, 1968
   639 00006F60 6605B007            <1> 	add 	ax, 1968     ; compute year
   640 00006F64 66A3[88790100]      <1> 	mov 	[year], ax
   641                              <1> 	;mov 	cx, dx
   642                              <1> 	; 25/07/2022
   643 00006F6A 89D1                <1> 	mov	ecx, edx
   644                              <1> 	;;mov 	dx, [qday]
   645                              <1> 	;pop 	dx
   646                              <1> 	; 18/04/2021
   647 00006F6C 5A                  <1> 	pop	edx
   648 00006F6D 6681FA6D01          <1> 	cmp 	dx, 365	     ; if qday <= 365 and qday >= 60
   649 00006F72 7708                <1> 	ja 	short cfe1   ; jday = jday +1
   650 00006F74 6683FA3C            <1> 	cmp 	dx, 60       ; if past 2/29 and leap year then
   651 00006F78 F5                  <1>         cmc		     ; add a leap day to the # of whole
   652                              <1> 	;adc 	cx, 0        ; days since 1/1 of current year
   653                              <1> 	; 25/07/2022
   654 00006F79 83D100              <1> 	adc	ecx, 0
   655                              <1> cfe1:
   656                              <1> 	;mov 	[jday], cx
   657                              <1> 	;mov 	bx, 12       ; estimate month
   658                              <1> 	; 18/04/2021
   659 00006F7C 29DB                <1> 	sub	ebx, ebx
   660 00006F7E B30C                <1> 	mov	bl, 12
   661 00006F80 66BA6E01            <1> 	mov 	dx, 366      ; mday, max. days since 1/1 is 365
   662 00006F84 6683E003            <1> 	and 	ax, 11b      ; year mod 4 (and dx, 3)
   663                              <1> cfe2:	; Month calculation  ; 0 to 11  (11 to 0)
   664                              <1> 	;cmp 	cx, dx       ; mday = # of days passed from 1/1
   665                              <1> 	; 25/07/2022
   666 00006F88 39D1                <1> 	cmp	ecx, edx
   667 00006F8A 731B                <1> 	jnb 	short cfe3
   668                              <1> 	;dec 	bx           ; month = month - 1
   669                              <1> 	;shl 	bx, 1
   670                              <1> 	; 18/04/2021
   671 00006F8C FECB                <1> 	dec	bl
   672 00006F8E D0E3                <1> 	shl	bl, 1 
   673 00006F90 668B93[94790100]    <1> 	mov 	dx, [EBX+DMonth] ; # elapsed days at 1st of month
   674                              <1> 	; 18/04/2021
   675                              <1> 	;shr 	bx, 1        ; bx = month - 1 (0 to 11)
   676 00006F97 D0EB                <1> 	shr	bl, 1
   677                              <1> 	;cmp	bx, 1        ; if month > 2 and year mod 4  = 0	
   678 00006F99 80FB01              <1> 	cmp	bl, 1
   679 00006F9C 76EA                <1> 	jna 	short cfe2   ; then mday = mday + 1
   680 00006F9E 76E8                <1> 	jna 	short cfe2   ; then mday = mday + 1
   681 00006FA0 08C0                <1> 	or 	al, al       ; if past 2/29 and leap year then
   682 00006FA2 75E4                <1> 	jnz 	short cfe2   ; add leap day (to mday)
   683                              <1> 	;inc 	dx           ; mday = mday + 1
   684                              <1> 	; 25/07/2022
   685 00006FA4 42                  <1> 	inc	edx
   686 00006FA5 EBE1                <1> 	jmp 	short cfe2
   687                              <1> cfe3:
   688                              <1> 	;inc 	bx	     ; -> bx = month, 1 to 12
   689                              <1> 	; 18/04/2021
   690 00006FA7 FEC3                <1> 	inc	bl
   691 00006FA9 66891D[8A790100]    <1> 	mov 	[month], bx
   692                              <1> 	;sub 	cx, dx	     ; day = jday - mday + 1
   693                              <1> 	; 25/07/2022
   694 00006FB0 29D1                <1> 	sub	ecx, edx
   695                              <1> 	;inc 	cx
   696                              <1> 	; 18/04/2021
   697 00006FB2 FEC1                <1> 	inc	cl
   698                              <1> 	;mov 	[day], cx
   699 00006FB4 880D[8C790100]      <1> 	mov	[day], cl
   700                              <1> 
   701                              <1> 	; eax, ebx, ecx, edx is changed at return
   702                              <1> 	; output ->
   703                              <1> 	; [year], [month], [day], [hour], [minute], [second]
   704                              <1> 
   705 00006FBA C3                  <1> 	retn	; 31/12/2017 (TRDOS 386)
   706                              <1> 
   707                              <1> set_rtc_date_time:
   708                              <1> 	; 31/12/2017 (v2.0.0)
   709                              <1> 	; 30/12/2017 (TRDOS 386)
   710                              <1> 	; 15/03/2015 (Retro UNIX 386 v1 - 32 bit version)
   711                              <1> 	; 20/06/2013 (Retro UNIX 8086 v1)
   712 00006FBB E80F000000          <1> 	call	set_date_bcd
   713                              <1> 	; Set real-time clock date
   714 00006FC0 E8D7F3FFFF          <1> 	call	set_rtc_date ; RTC_50
   715                              <1> 	; Set real-time clock time
   716 00006FC5 E832000000          <1> 	call	set_time_bcd
   717 00006FCA E96AF3FFFF          <1> 	jmp	set_rtc_time ; RTC_30
   718                              <1> 
   719                              <1> ; 31/12/2017
   720                              <1> set_date_bcd:
   721 00006FCF A0[89790100]        <1>         mov     al, [year+1]
   722 00006FD4 D40A                <1> 	aam 	; ah = al / 10, al = al mod 10
   723 00006FD6 D510                <1> 	db 	0D5h, 10h    ; Undocumented inst. AAD
   724                              <1> 			     ; AL = AH * 10h + AL
   725 00006FD8 88C5                <1> 	mov 	ch, al ; century (BCD)
   726 00006FDA A0[88790100]        <1> 	mov 	al, [year]
   727 00006FDF D40A                <1> 	aam 	; ah = al / 10, al = al mod 10
   728 00006FE1 D510                <1> 	db 	0D5h, 10h    ; Undocumented inst. AAD
   729                              <1> 			     ; AL = AH * 10h + AL
   730 00006FE3 88C1                <1> 	mov 	cl, al ; year (BCD)
   731 00006FE5 A0[8A790100]        <1>         mov 	al, [month]
   732 00006FEA D40A                <1> 	aam 	; ah = al / 10, al = al mod 10
   733 00006FEC D510                <1> 	db 	0D5h, 10h    ; Undocumented inst. AAD
   734                              <1> 			     ; AL = AH * 10h + AL
   735 00006FEE 88C6                <1> 	mov 	dh, al ; month (BCD)
   736 00006FF0 A0[8C790100]        <1> 	mov 	al, [day]
   737 00006FF5 D40A                <1> 	aam 	; ah = al / 10, al = al mod 10
   738 00006FF7 D510                <1> 	db 	0D5h, 10h    ; Undocumented inst. AAD
   739                              <1> 			     ; AL = AH * 10h + AL
   740                              <1> 	; 18/04/2021
   741 00006FF9 88C2                <1> 	mov 	dl, al ; day (BCD)
   742 00006FFB C3                  <1> 	retn	; 30/12/2017
   743                              <1> 
   744                              <1> ; 31/12/2017
   745                              <1> set_time_bcd:
   746                              <1>         ; Read real-time clock time 
   747                              <1> 	; (get day light saving time bit status)
   748 00006FFC FA                  <1>  	cli
   749 00006FFD E8D5F4FFFF          <1> 	call	UPD_IPR 		; CHECK FOR UPDATE IN PROCESS
   750                              <1> 	; cf = 1 -> al = 0
   751 00007002 7207                <1>         jc      short stime1
   752 00007004 B00B                <1> 	mov	al, CMOS_REG_B		; ADDRESS ALARM REGISTER
   753 00007006 E802F5FFFF          <1> 	call	CMOS_READ		; READ CURRENT VALUE OF DSE BIT
   754                              <1> stime1:
   755 0000700B FB                  <1> 	sti
   756 0000700C 2401                <1> 	and	al, 00000001b		; MASK FOR VALID DSE BIT
   757 0000700E 88C2                <1> 	mov	dl, al			; SET [DL] TO ZERO FOR NO DSE BIT
   758                              <1> 	; DL = 1 or 0 (day light saving time)
   759                              <1> 	
   760 00007010 A0[8E790100]        <1> 	mov 	al, [hour]
   761 00007015 D40A                <1> 	aam 	; ah = al / 10, al = al mod 10
   762 00007017 D510                <1> 	db 	0D5h,10h     ; Undocumented inst. AAD
   763                              <1> 			     ; AL = AH * 10h + AL
   764 00007019 88C5                <1> 	mov 	ch, al ; hour (BCD)
   765 0000701B A0[90790100]        <1>         mov     al, [minute]
   766 00007020 D40A                <1> 	aam 	; ah = al / 10, al = al mod 10
   767 00007022 D510                <1> 	db 	0D5h,10h     ; Undocumented inst. AAD
   768                              <1> 			     ; AL = AH * 10h + AL
   769 00007024 88C1                <1> 	mov 	cl, al       ; minute (BCD)
   770 00007026 A0[92790100]        <1>         mov     al, [second]
   771 0000702B D40A                <1> 	aam 	; ah = al / 10, al = al mod 10
   772 0000702D D510                <1> 	db 	0D5h,10h     ; Undocumented inst. AAD
   773                              <1> 			     ; AL = AH * 10h + AL
   774 0000702F 88C6                <1> 	mov 	dh, al	     ; second (BCD)
   775 00007031 C3                  <1> 	retn	; 30/12/2017
  3431                                  %include 'trdosk2.s' ; 04/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.8) - DRV INIT : trdosk2.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 22/05/2024 (Previous: 29/08/2023)
     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> 	; 22/05/2024 (TRDOS 386 Kernel v2.0.8)
    18                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
    19                              <1> 	; 30/08/2020
    20                              <1> 	; 25/08/2020
    21                              <1> 	; 11/08/2020 - 13/08/2020
    22                              <1> 	; 17/07/2020 - 20/07/2020
    23                              <1> 	; 14/07/2020 - 15/07/2020
    24                              <1> 	; 30/01/2018
    25                              <1> 	; 27/12/2017
    26                              <1> 	; 12/02/2016
    27                              <1> 	; 06/01/2016
    28                              <1> 	;  	('diskinit.inc', 'diskio.inc' integration)
    29                              <1> 	; 04/01/2016 (TRDOS 386 = TRDOS v2.0)
    30                              <1> 	; 07/08/2011
    31                              <1> 	; 20/09/2009
    32                              <1> 	; 2005
    33                              <1> 
    34                              <1> 	; 15/07/2020
    35                              <1> 	;movzx	ecx, byte [HF_NUM] ; number of fixed disks
    36                              <1> 	;cmp	cl, 1
    37                              <1> 	;jnb	short load_hd_partition_tables
    38                              <1> 
    39 00007032 A0[587D0100]        <1> 	mov	al, [HF_NUM] ; number of fixed disks
    40 00007037 20C0                <1> 	and 	al, al
    41 00007039 7501                <1> 	jnz	short load_hd_partition_tables
    42                              <1> 
    43                              <1> 	; no any hard disks
    44 0000703B C3                  <1> 	retn
    45                              <1> 
    46                              <1> load_hd_partition_tables:
    47                              <1> 	;mov	esi, [HDPM_TBL_VEC] ; primary master disk FDPT
    48                              <1> 	; 15/07/2020
    49 0000703C BE[5C7D0100]        <1> 	mov	esi, HDPM_TBL_VEC
    50 00007041 BF[82810100]        <1> 	mov 	edi, PTable_hd0
    51 00007046 B280                <1> 	mov 	dl, 80h
    52                              <1> 	; 15/07/2020
    53 00007048 A2[3B660000]        <1> 	mov	[hdc], al
    54                              <1> 	;xor	ecx, ecx ; 0
    55                              <1> load_next_hd_partition_table:
    56                              <1> 	; 20/07/2020
    57 0000704D 31C9                <1> 	xor	ecx, ecx ; 0
    58                              <1> 	;push	ecx
    59 0000704F 57                  <1> 	push	edi ; *
    60                              <1> 	;push	esi ; FDPT (+ DPTE) address
    61                              <1> 	; 15/07/2020
    62 00007050 AD                  <1> 	lodsd
    63 00007051 56                  <1> 	push	esi ; ** ; next FDPT (+ DPTE) address ptr
    64                              <1> 
    65                              <1> 	;mov	al, [esi+20] ; DPTE offset 4
    66                              <1> 	;and	al, 40h ;  LBA bit (bit 6)
    67                              <1> 	;;shr	al, 6
    68                              <1> 	;mov 	[HD_LBA_yes], al
    69                              <1> 
    70                              <1> 	; 15/07/2020
    71 00007052 8A4814              <1> 	mov	cl, [eax+20]
    72 00007055 80E140              <1> 	and	cl, 40h
    73                              <1> 	;mov	[HD_LBA_yes], cl
    74                              <1> 	; 22/05/2024 (BugFix)
    75 00007058 0FB6C2              <1> 	movzx	eax, dl
    76 0000705B 05[02820100]        <1> 	add	eax, HD_LBA_yes - 80h
    77 00007060 8808                <1> 	mov	[eax], cl
    78                              <1> 
    79 00007062 E844040000          <1> 	call	load_masterboot
    80                              <1> 	;jc	short pass_pt_this_hard_disk
    81                              <1> 	; 13/08/2020
    82                              <1> 	;jc	pass_pt_this_hard_disk
    83                              <1> 	; 25/07/2022
    84 00007067 7305                <1> 	jnc	short load_mbr_ok
    85 00007069 E98A000000          <1> 	jmp	pass_pt_this_hard_disk
    86                              <1> 
    87                              <1> load_mbr_ok:
    88 0000706E BB[40810100]        <1> 	mov	ebx, PartitionTable
    89 00007073 89DE                <1> 	mov	esi, ebx
    90                              <1> 	;mov	ecx, 16
    91 00007075 B110                <1> 	mov	cl, 16
    92 00007077 F3A5                <1> 	rep 	movsd
    93 00007079 89DE                <1> 	mov 	esi, ebx
    94                              <1> 	;mov 	byte [hdc], 4 ; 4 - partition index
    95                              <1> 	; 15/07/2020
    96 0000707B C605[87820100]04    <1> 	mov	byte [PP_Counter], 4
    97                              <1> loc_validate_hdp_partition:
    98                              <1> 	;cmp 	byte [esi+ptFileSystemID], 0
    99                              <1> 	;jna	short loc_validate_next_hdp_partition2
   100                              <1> 	; 13/08/2020
   101 00007082 8A4604              <1> 	mov	al, [esi+ptFileSystemID]
   102 00007085 20C0                <1> 	and	al, al
   103 00007087 7457                <1> 	jz	short loc_validate_next_hdp_partition2
   104                              <1> 
   105 00007089 56                  <1> 	push	esi ; *** ; Masterboot partition table offset
   106 0000708A 52                  <1> 	push	edx ; **** ; dl = Physical drive number
   107                              <1> 
   108                              <1> 	; 13/08/2020
   109 0000708B 3C05                <1> 	cmp	al, 05h  ; Extended partition CHS
   110 0000708D 7404                <1>  	je	short loc_set_ep_counter
   111 0000708F 3C0F                <1> 	cmp	al, 0Fh  ; Extended partition LBA
   112 00007091 7511                <1>  	jne	short loc_validate_next_hdp_partition0
   113                              <1> 
   114                              <1> 	;;inc	byte [PP_Counter]
   115                              <1> 	; 15/07/2020
   116                              <1> 	;inc 	byte [EP_Counter] ; disk has valid partition(s)
   117                              <1> 
   118                              <1> loc_set_ep_counter:
   119                              <1> 	; 13/08/2020
   120 00007093 803D[88820100]80    <1> 	cmp	byte [EP_Counter], 80h
   121 0000709A 7342                <1> 	jnb	short loc_validate_next_hdp_partition1
   122                              <1> 
   123 0000709C 8815[88820100]      <1> 	mov	byte [EP_Counter], dl ; disk drv has extd. part.
   124                              <1> 
   125 000070A2 EB3A                <1> 	jmp	short loc_validate_next_hdp_partition1
   126                              <1> 
   127                              <1> loc_validate_next_hdp_partition0:
   128 000070A4 31FF                <1> 	xor	edi, edi ; 0  
   129                              <1> 	; Input -> ESI = PartitionTable offset
   130                              <1> 	; DL = Hard disk drive number
   131                              <1> 	; EDI = 0 -> Primary Partition
   132                              <1> 	; EDI > 0 -> Extended Partition's Start Sector
   133 000070A6 E88C010000          <1> 	call 	validate_hd_fat_partition
   134 000070AB 730E                <1> 	jnc 	short loc_set_valid_hdp_partition_entry
   135                              <1> 
   136                              <1> 	;pop	edx
   137                              <1> 	;push	edx
   138 000070AD 8B1424              <1> 	mov	edx, [esp]  ; ****
   139 000070B0 8B742404            <1> 	mov	esi, [esp+4] ; *** ; 30/01/2018
   140 000070B4 E8D1020000          <1> 	call	validate_hd_fs_partition
   141 000070B9 7223                <1> 	jc	short loc_validate_next_hdp_partition1
   142                              <1> loc_set_valid_hdp_partition_entry:
   143 000070BB 8A0D[9A340100]      <1> 	mov 	cl, [Last_DOS_DiskNo] 
   144 000070C1 80C141              <1> 	add 	cl, 'A'
   145                              <1> 	; ESI = Logical dos drive description table address
   146 000070C4 880E                <1> 	mov	[esi+LD_Name], cl
   147                              <1> 	; 15/07/2020
   148 000070C6 8A4602              <1> 	mov	al, [esi+LD_PhyDrvNo] ; Physical drive number
   149                              <1> 	;mov	al, [esp] ; ****
   150 000070C9 2C7F                <1> 	sub	al, 7Fh
   151                              <1> 		; AL = 1 to 4
   152 000070CB C0E002              <1> 	shl	al, 2 ; AL = 4 to 16
   153                              <1> 
   154 000070CE 8A15[87820100]      <1> 	mov	dl, [PP_Counter]
   155                              <1> 
   156                              <1> 	;sub	al, [PP_Counter]
   157 000070D4 28D0                <1> 	sub	al, dl ; [PP_Counter] ; 4 - partition index
   158                              <1> 
   159                              <1> 	; AL = Partition entry/index, 0 based
   160                              <1> 	;  0 -> hd 0, Partition Table offset = 0
   161                              <1> 	; 15 -> hd 3, Partition Table offset = 3
   162                              <1> 
   163                              <1> 	;mov	[esi+LD_PartitionEntry], al
   164                              <1> 
   165                              <1> 	; 15/07/2020
   166 000070D6 B404                <1> 	mov	ah, 4
   167                              <1> 	;sub	ah, [PP_Counter]
   168 000070D8 28D4                <1> 	sub	ah, dl
   169                              <1> 
   170                              <1> 	; AH = Primary partition index, 0 to 3 ; pt entry
   171                              <1> 	;		(4 to 7 for logical disk partitions)
   172                              <1> 
   173                              <1> 	;mov 	[esi+LD_DParamEntry], ah
   174 000070DA 6689467C            <1> 	mov 	[esi+LD_PartitionEntry], ax
   175                              <1> 
   176                              <1> loc_validate_next_hdp_partition1:
   177 000070DE 5A                  <1> 	pop 	edx ; **** ; dl = Physical drive number 
   178 000070DF 5E                  <1> 	pop	esi ; *** ; Masterboot partition table offset
   179                              <1> 
   180                              <1> loc_validate_next_hdp_partition2:
   181                              <1> 	; ESI = PartitionTable offset
   182                              <1> 	; DL = Hard/Fixed disk drive number
   183                              <1> 
   184                              <1> 	;dec	byte [hdc] ; 4 - partition index
   185                              <1> 	;jz	short pass_pt_this_hard_disk
   186                              <1> 	; 15/07/2020
   187 000070E0 FE0D[87820100]      <1> 	dec	byte [PP_Counter] ; 4 - partition index
   188 000070E6 7410                <1> 	jz	short pass_pt_this_hard_disk
   189                              <1> 
   190 000070E8 83C610              <1> 	add	esi, 16 ; 10h
   191 000070EB EB95                <1> 	jmp	short loc_validate_hdp_partition
   192                              <1> 
   193                              <1> loc_not_any_extd_partitions:
   194                              <1> 	; 15/07/2020
   195 000070ED C3                  <1> 	retn
   196                              <1> 
   197                              <1> loc_next_hd_partition_table:
   198 000070EE FEC2                <1> 	inc	dl
   199                              <1> 	; 15/07/2020
   200                              <1> 	;add	esi, 32 ; next FDPT address
   201 000070F0 83C740              <1> 	add	edi, 64 ; next partition table destination
   202 000070F3 E955FFFFFF          <1>         jmp     load_next_hd_partition_table
   203                              <1> 
   204                              <1> pass_pt_this_hard_disk:
   205                              <1> 	;pop	esi ; FDPT (+ DPTE) address
   206                              <1> 	; 15/07/2020
   207 000070F8 5E                  <1> 	pop	esi ; ** ; next FDPT (+ DPTE) address ptr
   208 000070F9 5F                  <1> 	pop	edi ; * ; Ptable_hd?
   209                              <1> 	;pop	ecx
   210                              <1> 	;loop	loc_next_hd_partition_table
   211 000070FA FE0D[3B660000]      <1> 	dec	byte [hdc]
   212 00007100 75EC                <1> 	jnz	short loc_next_hd_partition_table
   213                              <1> 
   214                              <1> 	;cmp	byte [PP_Counter], 1
   215                              <1> 	;jnb	short load_extended_dos_partitions
   216                              <1> 	;; Empty partition table
   217                              <1> 	;retn
   218                              <1> 
   219                              <1> 	; 11/08/2020
   220                              <1> 	; 17/07/2020
   221                              <1> check_extended_partitions:
   222                              <1> 	; 15/07/2020
   223                              <1> 	;cmp	byte [EP_Counter], 0
   224                              <1> 	;jna	short loc_not_any_extd_partitions
   225                              <1> 	; 13/08/2020
   226 00007102 A0[88820100]        <1> 	mov	al, [EP_Counter] ; 1st disk drv has extd partition
   227 00007107 08C0                <1> 	or	al, al ; 0 ?
   228 00007109 74E2                <1> 	jz	short loc_not_any_extd_partitions
   229                              <1> 
   230                              <1> load_extended_dos_partitions:
   231                              <1> 	;mov	byte [hdc], 80h
   232                              <1> 	; 13/08/2020
   233 0000710B A2[3B660000]        <1> 	mov	byte [hdc], al ; 1st disk drv has extd partition
   234                              <1> 	; 25/08/2020
   235 00007110 2C80                <1> 	sub	al, 80h
   236 00007112 740E                <1> 	jz	short loc_set_ext_ptable_hd0
   237 00007114 C0E006              <1> 	shl	al, 6 ; * 64
   238 00007117 0FB6F0              <1> 	movzx	esi, al
   239 0000711A 81C6[82810100]      <1> 	add	esi, PTable_hd0
   240 00007120 EB05                <1> 	jmp 	short next_hd_extd_partition
   241                              <1> 
   242                              <1> 	; 25/08/2020
   243                              <1> loc_set_ext_ptable_hd0:
   244 00007122 BE[82810100]        <1> 	mov	esi, PTable_hd0
   245                              <1> 
   246                              <1> next_hd_extd_partition:
   247                              <1> 	; 17/07/2020
   248                              <1> 	;mov 	byte [EP_Counter], 0 ; Reset for each physical disk
   249                              <1> 	; 13/08/2020
   250                              <1> 	;mov	byte [LD_Counter], 0 ; Reset logical drive index
   251 00007127 66C705[88820100]00- <1> 	mov 	word [EP_Counter], 0 ; Reset EP index and LD index
   251 0000712F 00                  <1>
   252                              <1> 
   253 00007130 56                  <1> 	push	esi ; **** ; PTable_hd? offset
   254                              <1> 
   255 00007131 C605[87820100]04    <1> 	mov 	byte [PP_Counter], 4
   256                              <1> 				; set for each extd partition table
   257                              <1> 	;;mov	ecx, 4
   258                              <1> 	;mov	cl, 4
   259 00007138 8A15[3B660000]      <1> 	mov	dl, [hdc]
   260                              <1> hd_check_fs_id_05h:
   261 0000713E 8A4604              <1> 	mov	al, [esi+ptFileSystemID]
   262 00007141 3C05                <1> 	cmp	al, 05h ; Is it an extended dos partition ?
   263 00007143 7411                <1> 	je	short loc_set_ep_start_sector ; yes
   264                              <1> hd_check_fs_id_0Fh:
   265 00007145 3C0F                <1> 	cmp	al, 0Fh ; Is it an extended win4 (LBA mode) partition ?
   266 00007147 740D                <1> 	je	short loc_set_ep_start_sector ; yes
   267                              <1> 
   268                              <1> continue_to_check_ep:
   269                              <1> 	;add	esi, 16
   270                              <1> 	;loop	hd_check_fs_id_05h
   271                              <1> 	; 15/07/2020
   272                              <1> 	;dec	cl
   273                              <1> 	;jz	short continue_check_ep_next_disk
   274 00007149 FE0D[87820100]      <1> 	dec	byte [PP_Counter] ; 4 --> 0
   275 0000714F 7432                <1> 	jz	short continue_check_ep_next_disk
   276 00007151 83C610              <1> 	add	esi, 16
   277 00007154 EBE8                <1> 	jmp	short hd_check_fs_id_05h
   278                              <1> 
   279                              <1> loc_set_ep_start_sector:
   280                              <1> 	; dl = [hdc] ; Drive number
   281                              <1> 	; 15/07/2020
   282 00007156 8B4E08              <1> 	mov	ecx, [esi+ptStartSector]
   283                              <1> 	; 30/08/2020
   284 00007159 890D[8A820100]      <1> 	mov	[MBR_EP_StartSector], ecx 
   285                              <1> 	; 20/07/2020
   286                              <1> loc_validate_hde_partition_next:
   287                              <1> 	; 22/05/2024 (BugFix)
   288 0000715F 0FB6FA              <1> 	movzx	edi, dl
   289 00007162 81C7[02820100]      <1> 	add	edi, HD_LBA_yes - 80h
   290                              <1> 	;
   291 00007168 890D[8E820100]      <1> 	mov	[EP_StartSector], ecx ; Extended partition's start sector
   292 0000716E BB[827F0100]        <1>         mov	ebx, MasterBootBuff
   293                              <1> 	; 22/05/2024
   294 00007173 803F01              <1> 	cmp	byte [edi], 1 ; LBA ready = Yes
   295                              <1> 	;cmp	byte [HD_LBA_yes], 1 ; LBA ready = Yes
   296 00007176 7227                <1> 	jb	short loc_hd_load_ep_05h ; cf = 1 ; 20/07/2020 
   297                              <1> 	; 11/08/2020
   298                              <1> 	; (BugFix for extended partition type 05h beyond CHS limit)
   299                              <1> 	; (Infact if extended partition starts at the beyond of CHS limit,
   300                              <1> 	;  it's partition ID must be 0Fh but they/somebodies had used 05h.)
   301                              <1> 	;cmp	al, 05h
   302                              <1> 	;je	short loc_hd_load_ep_05h
   303                              <1> loc_hd_load_ep_0Fh:
   304                              <1> 	; 04/01/2016
   305                              <1> 	;push	ecx
   306                              <1> 	; 15/07/2020
   307                              <1> 	;mov	ecx, [esi+ptStartSector] ; sector number
   308                              <1> 	;mov	ebx, MasterBootBuff ; buffer address
   309                              <1> 	; LBA read/write (with private LBA function) 
   310                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
   311                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
   312                              <1> 	;mov	ah, 1Bh ; LBA read
   313                              <1> 	;mov	al, 1 ; sector count
   314 00007178 66B8011B            <1> 	mov	ax, 1B01h
   315 0000717C E844DEFFFF          <1> 	call	int13h
   316                              <1> 	;pop	ecx
   317                              <1> 	;jnc	short loc_hd_move_ep_table
   318                              <1> 	; 15/07/2020
   319 00007181 732E                <1> 	jnc	short loc_validate_hde_partition
   320                              <1> 
   321                              <1> continue_check_ep_next_disk:
   322                              <1> 	; 15/07/2020
   323                              <1> 	;pop	edi ; PTable_ep?
   324 00007183 5E                  <1> 	pop	esi ; **** ; PTable_hd?
   325 00007184 A0[587D0100]        <1> 	mov	al, [HF_NUM] ; number of hard disks
   326 00007189 047F                <1> 	add	al, 7Fh
   327 0000718B 3805[3B660000]      <1> 	cmp	[hdc], al
   328 00007191 730B                <1> 	jnb	short loc_validating_hd_partitions_ok
   329 00007193 83C640              <1> 	add	esi, 64
   330                              <1> 	; 15/07/2020
   331                              <1> 	;add	edi, 64
   332 00007196 FE05[3B660000]      <1> 	inc	byte [hdc]
   333 0000719C EB89                <1> 	jmp	short next_hd_extd_partition
   334                              <1> 
   335                              <1> loc_validating_hd_partitions_ok:
   336                              <1> 	; 15/07/2020
   337                              <1> 	;mov	al, [Last_DOS_DiskNo]
   338                              <1> loc_drv_init_retn:
   339 0000719E C3                  <1> 	retn
   340                              <1> 
   341                              <1> loc_hd_load_ep_05h:
   342                              <1> 	; 20/07/2020 ('diskio.s', int13h, cf = 1 -> bugfix)
   343                              <1> 	;clc    ; (Bug: int13h would not clear carry flag bit,
   344                              <1> 	;	; even if there would not be an error)
   345                              <1> 	;	; ((Fix: now, int13h procedure clears carry flag
   346                              <1> 	;	;  at the entrance of it.. 20/07/2020))
   347                              <1> 	; 15/07/2020
   348                              <1> 	;push	ecx
   349 0000719F 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
   350 000071A2 668B4E02            <1>         mov     cx, [esi+ptBeginSector]
   351 000071A6 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
   352                              <1> 	;mov	ebx, MasterBootBuff
   353 000071AA E816DEFFFF          <1> 	call	int13h ; 20/07/2020
   354                              <1> 		       ; 'diskio.s' modification, 'clc'
   355                              <1> 	;pop	ecx
   356 000071AF 72D2                <1> 	jc	short continue_check_ep_next_disk
   357                              <1> 	; 15/07/2020
   358                              <1> 	;jmp	short loc_validate_hde_partition
   359                              <1> 
   360                              <1> 	; 15/07/2020
   361                              <1> ;loc_hd_move_ep_table:
   362                              <1> 	;;pop	edi
   363                              <1> 	;;push	edi  ; PTable_ep?
   364                              <1> 	;mov	edi, [esp]
   365                              <1>         ;mov	esi, PartitionTable ; Extended
   366                              <1> 	;mov	ebx, esi
   367                              <1> 	;;mov	ecx, 16
   368                              <1> 	;mov	cl, 16
   369                              <1>        	;rep	movsd
   370                              <1> 	;mov	esi, ebx
   371                              <1> ;loc_set_hde_sub_partition_count:
   372                              <1> 	;mov	byte [PP_Counter], 4
   373                              <1> 	;mov	byte [EP_Counter], 0
   374                              <1> 
   375                              <1> loc_validate_hde_partition:
   376                              <1> 	; 13/08/2020
   377                              <1> 	; 15/07/2020
   378                              <1> 	;mov	byte [PP_Counter], 4
   379 000071B1 BE[40810100]        <1> 	mov	esi, PartitionTable ; (in MasterBootBuff)
   380                              <1> 	; 13/08/2020
   381                              <1> 	;jmp	short get_minidisk_partition_entry
   382                              <1> 
   383                              <1> ;get_minidisk_partition_entry:
   384                              <1> ;	; 20/07/2020
   385                              <1> ;	cmp	byte [esi+ptFileSystemID], 0
   386                              <1> ;	ja	short loc_validate_minidisk_partition
   387                              <1> ;	; 13/08/2020
   388                              <1> ;	jmp	short continue_check_ep_next_disk
   389                              <1> 
   390                              <1> ;	; 11/08/2020
   391                              <1> ;get_minidisk_partition_entry_next:
   392                              <1> ;	; 13/08/2020
   393                              <1> ;	;dec 	byte [PP_Counter]
   394                              <1> ;	;jz	short continue_check_ep_next_disk
   395                              <1> ;	; 20/07/2020
   396                              <1> ;;get_minidisk_partition_entry_next:
   397                              <1> ;	; 13/08/2020
   398                              <1> ;	cmp	esi, PartitionTable+64 
   399                              <1> ;	jnb	short continue_check_ep_next_disk
   400                              <1> ;
   401                              <1> ;	add 	esi, 16 ; 10h
   402                              <1> ;	;jmp	short get_minidisk_partition_entry
   403                              <1> 
   404                              <1> 	; 13/08/2020
   405                              <1> get_minidisk_partition_entry:
   406                              <1> 	; 20/07/2020
   407 000071B6 807E0400            <1> 	cmp	byte [esi+ptFileSystemID], 0
   408 000071BA 76C7                <1> 	jna	short continue_check_ep_next_disk ; 13/08/2020
   409                              <1> 
   410                              <1> loc_validate_minidisk_partition:
   411                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   412                              <1> 	; 13/08/2020
   413                              <1> 	; 20/07/2020
   414                              <1> 	;push	esi ; *** ; Extended partition table offset
   415                              <1> 
   416                              <1> 	; 13/08/2020
   417 000071BC FE05[88820100]      <1> 	inc	byte [EP_Counter] ; current (sub partition) index
   418                              <1> 				  ; in current extended partition
   419 000071C2 BF[8E820100]        <1> 	mov	edi, EP_StartSector
   420                              <1> 
   421                              <1> 	; Input -> ESI = PartitionTable offset
   422                              <1> 	; DL = Hard disk drive number   
   423                              <1> 	; EDI = Extended partition start sector pointer
   424 000071C7 E86B000000          <1> 	call	validate_hd_fat_partition
   425                              <1> 	;pop	ecx ; *
   426 000071CC 7308                <1> 	jnc	short loc_set_valid_hde_partition_entry
   427                              <1> 			 ; jump down to deep !!!
   428                              <1> 
   429                              <1> 	;pop	esi ; *** ; Extended partition table offset
   430                              <1> 	; 13/08/2020
   431                              <1> 	;mov	esi, PartitionTable
   432                              <1> 
   433                              <1> 	; 11/08/2020
   434                              <1> 	; ESI = Extended partition table offset
   435 000071CE 8A15[3B660000]      <1> 	mov	dl, [hdc]
   436                              <1> 
   437                              <1> 	;; DL = Hard disk drive number
   438                              <1> 	;dec	byte [PP_Counter]
   439                              <1> 	;jz	short continue_check_ep_next_disk
   440                              <1> 	;add 	esi, 16 ; 10h
   441                              <1> 	;mov	dl, [hdc]
   442                              <1> 	;jmp	short get_minidisk_partition_entry
   443                              <1> 
   444                              <1> 	; 11/08/2020
   445                              <1> 	;jmp	short get_minidisk_partition_entry_next
   446                              <1> 
   447                              <1> 	; 23/08/2020
   448 000071D4 EB3E                <1> 	jmp	short validate_next_minidisk_partition_ok
   449                              <1> 
   450                              <1> 	; 17/07/2020
   451                              <1> 	;; jumping down to deep levels !!!
   452                              <1> 	; ((That is a pitty microsoft preferred ep table chain
   453                              <1> 	; instead of a single table as mbr partition table!?))
   454                              <1> 
   455                              <1> loc_set_valid_hde_partition_entry:
   456                              <1> 	; 15/07/2020
   457 000071D6 A0[3B660000]        <1> 	mov	al, [hdc] ; Hard disk drive number (>=80h)
   458 000071DB 88C2                <1> 	mov	dl, al ; mov dl, [hdc]
   459 000071DD 2C7F                <1> 	sub	al, 7Fh
   460                              <1> 		    ; 1 to 4
   461 000071DF C0E002              <1> 	shl	al, 2 ; 4 to 16
   462 000071E2 2A05[87820100]      <1> 	sub	al, [PP_Counter] ; al - (4 - partition index)
   463                              <1> 			; (disk number * 4) + partition index
   464                              <1> 
   465                              <1> 	; AL = Partition entry/index, 0 based
   466                              <1>         ;  0 -> hd 0, Partition Table offset = 0
   467                              <1>         ; 15 -> hd 3, Partition Table offset = 3
   468                              <1> 
   469                              <1> 	;mov	ah, 4 ; Logical dos partition (>= 4)
   470                              <1> 	;add	ah, [EP_Counter]
   471                              <1> 		; Logical disk partition index = 4 to 7
   472                              <1> 		; (Primary disk partition index = 0 to 3)
   473                              <1> 
   474                              <1> 	; 13/08/2020
   475 000071E8 8A25[89820100]      <1> 	mov	ah, [LD_Counter] ; Logical drive index number
   476                              <1> 				; (in current extended partition)
   477 000071EE 80C404              <1> 	add	ah, 4 ; 4 to 7
   478                              <1> 	
   479                              <1> 	; 15/07/2020
   480                              <1> 	; CX -> AX
   481                              <1> 	;; 06/01/2016 (TRDOS v2.0)
   482                              <1> 	;; BUGFIX *
   483                              <1> 	;;mov	[esi+LD_PartitionEntry], cl
   484                              <1> 	;;mov	[esi+LD_DParamEntry], ch 
   485                              <1> 	;mov	[esi+LD_PartitionEntry], cx
   486 000071F1 6689467C            <1> 	mov	[esi+LD_PartitionEntry], ax
   487                              <1> 
   488 000071F5 8A0D[9A340100]      <1> 	mov	cl, [Last_DOS_DiskNo]
   489 000071FB 80C141              <1> 	add	cl, 'A'
   490 000071FE 880E                <1> 	mov	[esi+LD_Name], cl
   491                              <1> 
   492                              <1> 	; 17/07/2020
   493                              <1> 	;cmp	cl, 'Z'
   494                              <1> 	;jb	short logical_drive_count_ok_for_next
   495                              <1> 	;pop	esi ; ***
   496                              <1> 	;pop	esi ; ****
   497                              <1> 	;retn
   498                              <1> 
   499                              <1> ;logical_drive_count_ok_for_next:
   500                              <1> 
   501                              <1> 	;; 15/07/2020
   502                              <1> 	;inc	byte [EP_Counter]
   503                              <1> 	; 13/08/2020
   504 00007200 FE05[89820100]      <1> 	inc	byte [LD_Counter]
   505                              <1> 
   506                              <1> 	;mov	dl, [hdc]
   507                              <1> 
   508                              <1> 	; 17/07/2020
   509                              <1> 	;; Now, 
   510                              <1> 	;; we are swimming in deep of an extended partition !!!
   511                              <1> 	; (! sub or chained extended partition tables !)
   512                              <1> 	; ((Logical dos partitions in extended partition were called
   513                              <1> 	;  as 'mini disk partition' in msdos 6.0 source code.))
   514                              <1> 
   515                              <1> validate_next_minidisk_partition:
   516                              <1> 	; 13/08/2020
   517                              <1> 	;pop	esi ; *** ; Extended partition table offset
   518                              <1> 
   519                              <1> 	; 17/07/2020
   520                              <1> 	;cmp	byte [EP_Counter], 4
   521                              <1> 	; 13/08/2020
   522 00007206 803D[89820100]04    <1> 	cmp	byte [LD_Counter], 4 ; maximum 4 logical disks
   523                              <1> 				     ; per extended partition
   524                              <1> 	;jnb	continue_check_ep_next_disk
   525                              <1> 	; 25/07/2022
   526 0000720D 7205                <1> 	jb	short validate_next_minidisk_partition_ok
   527 0000720F E96FFFFFFF          <1> 	jmp	continue_check_ep_next_disk
   528                              <1> 
   529                              <1> validate_next_minidisk_partition_ok:
   530                              <1> 	; 13/08/2020
   531                              <1> 	;dec	byte [PP_Counter] ; 4 --> 0
   532                              <1> 	;jz	continue_check_ep_next_disk
   533                              <1> 
   534                              <1> 	;cmp	esi, PartitionTable+64
   535                              <1> 	;jnb	continue_check_ep_next_disk
   536                              <1> 
   537                              <1> 	;add	esi, 16
   538                              <1> 	; 13/08/2020
   539 00007214 BE[50810100]        <1> 	mov	esi, PartitionTable+16
   540                              <1> 
   541                              <1> 	; 20/07/2020
   542 00007219 8A4604              <1> 	mov	al, [esi+ptFileSystemID]
   543                              <1> 
   544                              <1> 	; 20/07/2020
   545 0000721C 3C05                <1> 	cmp	al, 05h ; Is it an extended dos partition ?
   546 0000721E 7409                <1> 	je	short loc_minidisk_next_ep_lba_chs ; 17/07/2020
   547 00007220 3C0F                <1> 	cmp	al, 0Fh ; Is it an extended win4 (LBA mode) partition ?
   548                              <1> 	;jne	continue_check_ep_next_disk ; AL must be 0 here
   549                              <1> 					; (when it is not 05h or 0Fh)
   550                              <1> 					; If AL is not ZERO -> EP Bug!
   551                              <1> 					; (!Microsoft DOS convention!)
   552                              <1> 	; 25/07/2022
   553 00007222 7405                <1> 	je	short loc_minidisk_next_ep_lba_chs
   554 00007224 E95AFFFFFF          <1> 	jmp	continue_check_ep_next_disk
   555                              <1> 
   556                              <1> loc_minidisk_next_ep_lba_chs:
   557                              <1> 	; 17/07/2020
   558 00007229 8B4E08              <1> 	mov	ecx, [esi+ptStartSector] ; relative start sector number
   559                              <1> 	;add	ecx, [EP_StartSector]
   560                              <1> 	; 30/08/2020	
   561 0000722C 030D[8A820100]      <1> 	add	ecx, [MBR_EP_StartSector]
   562                              <1> 	; 20/07/2020
   563 00007232 E928FFFFFF          <1> 	jmp	loc_validate_hde_partition_next
   564                              <1> 
   565                              <1> validate_hd_fat_partition:
   566                              <1> 	; 17/07/2020
   567                              <1> 	; 15/07/2020
   568                              <1> 	;	(optimization)
   569                              <1> 	; 14/07/2020
   570                              <1> 	;	(fat16 -big- partition search bugfix)
   571                              <1> 	; 27/12/2017
   572                              <1> 	; 12/02/2016
   573                              <1> 	; 07/01/2016 (TRDOS 386 = TRDOS v2.0)
   574                              <1> 	; 07/08/2011
   575                              <1> 	; 23/07/2011
   576                              <1> 	; Input
   577                              <1> 	;   DL = Hard/Fixed Disk Drive Number
   578                              <1> 	;   ESI = PartitionTable offset
   579                              <1> 	;   EDI = Extend. Part. Start Sector Pointer
   580                              <1> 	;   EDI = 0 -> Primary Partition
   581                              <1> 	;   byte [Last_DOS_DiskNo]
   582                              <1>  	; Output
   583                              <1> 	;  cf=0 -> Validated
   584                              <1> 	;   ESI = Logical dos drv desc. table
   585                              <1> 	;   EBX = FAT boot sector buffer
   586                              <1> 	;   byte [Last_DOS_DiskNo]
   587                              <1> 	;  cf=1 -> Not a valid FAT partition
   588                              <1> 	; EAX, EDX, ECX, EDI -> changed
   589                              <1> 
   590                              <1> 	;mov 	esi, PartitionTable
   591 00007237 8A6604              <1> 	mov 	ah, [esi+ptFileSystemID]
   592 0000723A B002                <1> 	mov	al, 2 ; 27/12/2017
   593 0000723C 80FC06              <1> 	cmp 	ah, 06h ; FAT16 CHS partition (>=32MB)
   594                              <1> 	; 12/02/2016
   595                              <1> 	;;jb	short loc_not_a_valid_fat_partition2
   596                              <1>  	;jnb	short vhdp_FAT16_32
   597                              <1> 	; 14/07/2020 (BugFix)
   598 0000723F 7711                <1> 	ja	short vhdp_FAT16_32
   599 00007241 7425                <1> 	je	short loc_set_valid_hd_partition_params
   600                              <1> 
   601                              <1> vhdp_FAT12_16:
   602                              <1> 	; 27/12/2017
   603 00007243 FEC8                <1> 	dec	al ; mov al, 1
   604 00007245 38C4                <1> 	cmp	ah, al ; 1 ; FAT12 partition
   605 00007247 741F                <1> 	je	short loc_set_valid_hd_partition_params
   606                              <1> 	;
   607 00007249 FEC0                <1> 	inc	al ; mov al, 2
   608 0000724B 80FC04              <1> 	cmp	ah, 04h ; FAT16 CHS partition (< 32MB)
   609 0000724E 7418                <1> 	je	short loc_set_valid_hd_partition_params
   610                              <1> 	
   611                              <1> 	; 15/07/2020
   612                              <1> 	; (ah = 05h, 02h or 03h)
   613                              <1> loc_not_a_valid_fat_partition1:
   614 00007250 F9                  <1> 	stc
   615                              <1> 	; cf=1
   616 00007251 C3                  <1> 	retn
   617                              <1> 
   618                              <1> vhdp_FAT16_32:
   619                              <1> 	; 15/07/2020
   620                              <1> 	;mov	al, 3
   621 00007252 FEC0                <1> 	inc	al
   622 00007254 80FC0C              <1> 	cmp	ah, 0Ch ; FAT32 LBA partition
   623 00007257 740F                <1> 	je	short loc_set_valid_hd_partition_params
   624 00007259 7706                <1> 	ja	short vhdp_check_FAT16_lba
   625                              <1> 
   626                              <1> vhdp_check_FAT32_chs:
   627 0000725B 80FC0B              <1> 	cmp	ah, 0Bh ; FAT32 CHS partition 
   628 0000725E 7408                <1> 	je	short loc_set_valid_hd_partition_params
   629                              <1> 	;jne	short loc_not_a_valid_fat_partition1
   630                              <1> 
   631                              <1> 	;stc
   632                              <1> loc_not_a_valid_fat_partition2:
   633 00007260 C3                  <1> 	retn
   634                              <1> 
   635                              <1> vhdp_check_FAT16_lba:
   636 00007261 80FC0E              <1> 	cmp	ah, 0Eh ; FAT16 LBA partition
   637 00007264 75EA                <1> 	jne	short loc_not_a_valid_fat_partition1
   638                              <1> 
   639                              <1> 	;mov	al, 2
   640 00007266 FEC8                <1> 	dec	al
   641                              <1> 
   642                              <1> loc_set_valid_hd_partition_params:
   643                              <1> 	; 30/07/2022
   644                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   645                              <1> 	; 15/07/2020
   646                              <1> 	;inc 	byte [Last_DOS_DiskNo] ; > 1
   647                              <1> 	;
   648 00007268 31DB                <1> 	xor	ebx, ebx
   649 0000726A 8A3D[9A340100]      <1> 	mov	bh, [Last_DOS_DiskNo] ; * 256
   650 00007270 FEC7                <1> 	inc	bh ; 15/07/2020
   651 00007272 81C300010900        <1> 	add	ebx, Logical_DOSDisks
   652                              <1> 	;
   653 00007278 C6430102            <1> 	mov	byte [ebx+LD_DiskType], 2
   654 0000727C 885302              <1> 	mov	byte [ebx+LD_PhyDrvNo], dl
   655                              <1> 	;mov	byte [ebx+LD_FATType], al ; 2 or 3
   656                              <1> 	;mov	byte [ebx+LD_FSType], ah ; 06h, 0Eh, 0Bh, 0Ch
   657 0000727F 66894303            <1> 	mov	word [ebx+LD_FATType], ax
   658                              <1> 	;
   659 00007283 8B4E08              <1> 	mov	ecx, [esi+ptStartSector]
   660 00007286 09FF                <1> 	or	edi, edi 
   661 00007288 7402                <1> 	jz	short pass_hd_FAT_ep_start_sector_adding
   662                              <1> loc_add_hd_FAT_ep_start_sector:
   663                              <1> 	; 17/07/2020
   664 0000728A 030F                <1> 	add	ecx, [edi]
   665                              <1> pass_hd_FAT_ep_start_sector_adding:
   666 0000728C 894B6C              <1> 	mov	[ebx+LD_StartSector], ecx
   667                              <1> loc_hd_FAT_logical_drv_init:
   668 0000728F 89DD                <1> 	mov	ebp, ebx
   669                              <1> 	;mov	dl, [ebx+LD_PhyDrvNo]
   670 00007291 A0[82820100]        <1> 	mov	al, [HD_LBA_yes] ; 07/01/2016
   671 00007296 884305              <1> 	mov	[ebx+LD_LBAYes], al
   672 00007299 BB[92820100]        <1> 	mov	ebx, DOSBootSectorBuff ; buffer address
   673 0000729E 08C0                <1> 	or	al, al
   674 000072A0 740C                <1> 	jz	short loc_hd_FAT_drv_init_load_bs_chs
   675                              <1> loc_hd_FAT_drv_init_load_bs_lba:
   676                              <1> 	; DL = Physical drive number
   677                              <1>    	;mov	ecx, [esi+ptStartSector] ; sector number
   678                              <1> 	;mov	ebx, DOSBootSectorBuff ; buffer address
   679                              <1> 	; LBA read/write (with private LBA function) 
   680                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
   681                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
   682 000072A2 B41B                <1> 	mov	ah, 1Bh ; LBA read
   683 000072A4 B001                <1> 	mov	al, 1 ; sector count
   684 000072A6 E81ADDFFFF          <1> 	call	int13h
   685 000072AB 7313                <1> 	jnc	short loc_hd_drv_FAT_boot_validation
   686                              <1> loc_not_a_valid_fat_partition3:
   687 000072AD C3                  <1> 	retn
   688                              <1> loc_hd_FAT_drv_init_load_bs_chs:
   689 000072AE 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
   690 000072B1 668B4E02            <1> 	mov	cx, [esi+ptBeginSector]
   691 000072B5 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
   692                              <1> 	;mov	ebx, DOSBootSectorBuff
   693 000072B9 E807DDFFFF          <1> 	call	int13h
   694 000072BE 72ED                <1> 	jc	short loc_not_a_valid_fat_partition3
   695                              <1> loc_hd_drv_FAT_boot_validation:
   696                              <1> 	;mov	esi, DOSBootSectorBuff
   697 000072C0 89DE                <1> 	mov	esi, ebx
   698 000072C2 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
   699 000072CB 7514                <1> 	jne	short loc_not_a_valid_fat_partition4
   700 000072CD 807E15F8            <1> 	cmp	byte [esi+BPB_Media], 0F8h
   701 000072D1 750E                <1> 	jne	short loc_not_a_valid_fat_partition4
   702                              <1> 
   703                              <1> 	; 25/07/2022
   704 000072D3 31C9                <1> 	xor	ecx, ecx
   705                              <1> 
   706                              <1> 	; 27/12/2017
   707 000072D5 807D0303            <1> 	cmp	byte [ebp+LD_FATType], 3
   708 000072D9 7508                <1> 	jne	short loc_hd_FAT16_BPB
   709                              <1> 
   710                              <1> loc_hd_drv_FAT32_boot_validation:
   711 000072DB 807E4229            <1> 	cmp	byte [esi+BS_FAT32_BootSig], 29h
   712 000072DF 7413                <1> 	je	short loc_hd_FAT32_BPB
   713                              <1> 
   714                              <1> loc_not_a_valid_fat_partition4:
   715 000072E1 F9                  <1> 	stc
   716 000072E2 C3                  <1> 	retn
   717                              <1> 
   718                              <1> loc_hd_FAT16_BPB:
   719 000072E3 807E2629            <1> 	cmp	byte [esi+BS_BootSig], 29h
   720 000072E7 75F8                <1> 	jne	short loc_not_a_valid_fat_partition4
   721                              <1> 
   722 000072E9 66837E1600          <1> 	cmp	word [esi+BPB_FATSz16], 0
   723 000072EE 7604                <1> 	jna	short loc_hd_big_FAT16_BPB
   724                              <1> 	;mov	ecx, 32
   725                              <1> 	; 25/07/2022
   726 000072F0 B120                <1> 	mov	cl, 32
   727                              <1> 	; ecx = 32
   728 000072F2 EB02                <1> 	jmp	short loc_hd_move_FAT_BPB
   729                              <1> 
   730                              <1> loc_hd_FAT32_BPB:
   731                              <1> 	;cmp	word [esi+BPB_FATSz16], 0
   732                              <1> 	;ja	short loc_not_a_valid_fat_partition4
   733                              <1> loc_hd_big_FAT16_BPB:
   734                              <1> 	;mov	ecx, 45
   735                              <1> 	; 25/07/2022
   736 000072F4 B12D                <1> 	mov	cl, 45
   737                              <1> 	; ecx = 45
   738                              <1> loc_hd_move_FAT_BPB:
   739 000072F6 89EF                <1> 	mov 	edi, ebp
   740                              <1> 	;mov	esi, ebx ; Boot sector
   741 000072F8 57                  <1> 	push	edi
   742 000072F9 83C706              <1> 	add	edi, LD_BPB
   743 000072FC F366A5              <1> 	rep	movsw
   744 000072FF 5E                  <1> 	pop	esi
   745 00007300 0FB74614            <1> 	movzx	eax, word [esi+LD_BPB+BPB_RsvdSecCnt]
   746 00007304 03466C              <1> 	add	eax, [esi+LD_StartSector]
   747 00007307 894660              <1> 	mov	[esi+LD_FATBegin], eax
   748 0000730A 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3
   749 0000730E 7223                <1> 	jb	short loc_set_FAT16_RootDirLoc
   750                              <1> loc_set_FAT32_RootDirLoc:
   751 00007310 8B462A              <1> 	mov	eax, [esi+LD_BPB+BPB_FATSz32]
   752 00007313 0FB65E16            <1>         movzx	ebx, byte [esi+LD_BPB+BPB_NumFATs]
   753 00007317 F7E3                <1> 	mul	ebx
   754 00007319 034660              <1> 	add	eax, [esi+LD_FATBegin]
   755                              <1> loc_set_FAT32_data_begin:
   756 0000731C 894668              <1> 	mov	[esi+LD_DATABegin], eax
   757 0000731F 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
   758                              <1> 	; If Root Directory Cluster <> 2 then
   759                              <1> 	; change the beginning sector value 
   760                              <1> 	; of the root dir by adding sector offset.
   761 00007322 8B4632              <1> 	mov	eax, [esi+LD_BPB+BPB_RootClus]
   762                              <1> 	;sub	eax, 2
   763                              <1> 	; 30/07/2022
   764 00007325 48                  <1> 	dec	eax ; 2 -> 1
   765 00007326 48                  <1> 	dec	eax ; 1 -> 0
   766 00007327 7433                <1> 	jz	short short loc_set_32bit_FAT_total_sectors
   767                              <1> 	;movzx	ebx, byte [esi+LD_BPB+BPB_SecPerClust]
   768 00007329 8A5E13              <1> 	mov	bl, [esi+LD_BPB+BPB_SecPerClust] 
   769 0000732C F7E3                <1> 	mul	ebx
   770 0000732E 014664              <1> 	add	[esi+LD_ROOTBegin], eax
   771 00007331 EB29                <1> 	jmp	short loc_set_32bit_FAT_total_sectors
   772                              <1> 	;
   773                              <1> loc_set_FAT16_RootDirLoc:
   774 00007333 0FB64616            <1> 	movzx	eax, byte [esi+LD_BPB+BPB_NumFATs]
   775 00007337 0FB7561C            <1> 	movzx	edx, word [esi+LD_BPB+BPB_FATSz16]
   776 0000733B F7E2                <1> 	mul	edx
   777 0000733D 034660              <1> 	add	eax, [esi+LD_FATBegin]
   778 00007340 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
   779                              <1> loc_set_FAT16_data_begin:
   780 00007343 894668              <1> 	mov	[esi+LD_DATABegin], eax 
   781                              <1> 	;mov	eax, 20h  ; Size of a directory entry
   782                              <1> 	;;movzx	edx, word [esi+LD_BPB+BPB_RootEntCnt]
   783                              <1>         ;mov	dx, [esi+LD_BPB+BPB_RootEntCnt]
   784                              <1>         ;mul	edx
   785                              <1> 	;;mov	ecx, 511
   786                              <1> 	;mov	cx, 511
   787                              <1> 	;add	eax, ecx
   788                              <1> 	;inc	ecx ; 512
   789                              <1> 	;div	ecx
   790                              <1> 	; 14/07/2020
   791 00007346 0FB74617            <1> 	movzx	eax, word [esi+LD_BPB+BPB_RootEntCnt]
   792 0000734A 6683C00F            <1> 	add	ax, 15
   793                              <1> 	;shr	ax, 4 ; / 16 ; (16 entries per sector)
   794                              <1> 	; 25/07/2022
   795 0000734E C1E804              <1> 	shr	eax, 4
   796 00007351 014668              <1> 	add	[esi+LD_DATABegin], eax
   797                              <1> 	;movzx	eax, word [esi+LD_BPB+BPB_TotalSec16]
   798 00007354 668B4619            <1> 	mov	ax, [esi+LD_BPB+BPB_TotalSec16]
   799                              <1> 	;test	ax, ax
   800                              <1> 	; 25/07/2022
   801 00007358 85C0                <1> 	test	eax, eax
   802                              <1> 	;jz	short loc_set_32bit_FAT_total_sectors
   803                              <1> ;loc_set_16bit_FAT_total_sectors:
   804                              <1> 	;mov	[esi+LD_TotalSectors], eax
   805                              <1> 	;jmp	short loc_set_hd_FAT_cluster_count
   806                              <1> 	; 14/07/2020
   807 0000735A 7503                <1> 	jnz	short loc_set_hd_FAT_cluster_count
   808                              <1> loc_set_32bit_FAT_total_sectors:
   809 0000735C 8B4626              <1> 	mov	eax, [esi+LD_BPB+BPB_TotalSec32]
   810                              <1> 	;mov	[esi+LD_TotalSectors], eax
   811                              <1> loc_set_hd_FAT_cluster_count:
   812 0000735F 894670              <1> 	mov	[esi+LD_TotalSectors], eax ; 14/07/2020
   813 00007362 8B5668              <1> 	mov	edx, [esi+LD_DATABegin]
   814 00007365 2B566C              <1> 	sub	edx, [esi+LD_StartSector]
   815 00007368 29D0                <1> 	sub	eax, edx
   816 0000736A 31D2                <1> 	xor	edx, edx ; 0
   817 0000736C 0FB64E13            <1>         movzx   ecx, byte [esi+LD_BPB+BPB_SecPerClust]
   818 00007370 F7F1                <1>         div	ecx 
   819 00007372 894678              <1> 	mov	[esi+LD_Clusters], eax
   820                              <1> 	; Maximum Valid Cluster Number= EAX +1
   821                              <1> 	; with 2 reserved clusters= EAX +2
   822                              <1> loc_set_hd_FAT_fs_free_sectors:
   823                              <1> 	;mov	dword [esi+LD_FreeSectors], 0
   824 00007375 E852010000          <1> 	call	get_free_FAT_sectors
   825 0000737A 720D                <1> 	jc	short loc_validate_hd_FAT_partition_retn
   826 0000737C 894674              <1> 	mov	[esi+LD_FreeSectors], eax
   827 0000737F C6467E06            <1> 	mov	byte [esi+LD_MediaChanged], 6  ; Volume Name Reset
   828                              <1> 
   829                              <1> 	; 15/07/2020
   830 00007383 FE05[9A340100]      <1> 	inc 	byte [Last_DOS_DiskNo] ; > 1
   831                              <1> 
   832                              <1> 	;mov	cl, [Last_DOS_DiskNo] 
   833                              <1> 	;add	cl, 'A'
   834                              <1> 	;mov	[esi+LD_FS_Name], cl
   835                              <1> 
   836                              <1> loc_validate_hd_FAT_partition_retn:
   837 00007389 C3                  <1> 	retn
   838                              <1> 
   839                              <1> validate_hd_fs_partition:
   840                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   841                              <1> 	; 03/02/2018
   842                              <1> 	; 09/12/2017
   843                              <1> 	; 13/02/2016
   844                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
   845                              <1> 	; 29/01/2011
   846                              <1> 	; 23/07/2011
   847                              <1> 	; Input
   848                              <1> 	;   DL = Hard/Fixed Disk Drive Number
   849                              <1> 	;   ESI = PartitionTable offset
   850                              <1> 	;   byte [Last_DOS_DiskNo]
   851                              <1> 	; Output
   852                              <1> 	;  cf=0 -> Validated
   853                              <1> 	;   ESI = Logical dos drv desc. table
   854                              <1> 	;   EBX = Singlix FS boot sector buffer
   855                              <1> 	;   byte [Last_DOS_DiskNo]
   856                              <1> 	;  cf=1 -> Not a valid 'Singlix FS' partition
   857                              <1> 	; EAX, EDX, ECX, EDI -> changed 
   858                              <1> 
   859                              <1> 	;mov	esi, PartitionTable
   860 0000738A 8A6604              <1> 	mov	ah, [esi+ptFileSystemID]
   861 0000738D 80FCA1              <1> 	cmp	ah, 0A1h ; SINGLIX FS1 (trfs1) partition
   862 00007390 7549                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
   863                              <1> loc_set_valid_hd_fs_partition_params:
   864 00007392 FE05[9A340100]      <1> 	inc	byte [Last_DOS_DiskNo] ; > 1
   865 00007398 30C0                <1> 	xor	al, al ; mov al, 0
   866                              <1> 	;mov	[drv], dl
   867 0000739A 29DB                <1> 	sub	ebx, ebx ; 0
   868 0000739C 8A3D[9A340100]      <1> 	mov	bh, [Last_DOS_DiskNo]
   869 000073A2 81C300010900        <1> 	add	ebx, Logical_DOSDisks
   870 000073A8 C6430102            <1> 	mov	byte [ebx+LD_DiskType], 2
   871 000073AC 885302              <1> 	mov	[ebx+LD_PhyDrvNo], dl
   872                              <1> 	;mov	[ebx+LD_FATType], al ; 0
   873                              <1> 	;mov	[ebx+LD_FSType], ah
   874 000073AF 66894303            <1> 	mov	[ebx+LD_FATType], ax
   875                              <1> 	;mov	eax, [esi+ptStartSector]
   876                              <1> 	;mov	[ebx+LD_StartSector], eax
   877                              <1> loc_hd_fs_logical_drv_init:
   878 000073B3 89DD                <1> 	mov	ebp, ebx ; 10/01/2016
   879                              <1> 	;mov	dl, [ebx+LD_PhyDrvNo]
   880 000073B5 A0[82820100]        <1> 	mov	al, [HD_LBA_yes] ; 10/01/2016
   881 000073BA 884305              <1> 	mov	[ebx+LD_LBAYes], al
   882 000073BD 89DE                <1> 	mov	esi, ebx
   883 000073BF BB[92820100]        <1> 	mov	ebx, DOSBootSectorBuff ; buffer address
   884 000073C4 08C0                <1> 	or	al, al
   885 000073C6 7515                <1> 	jnz	short loc_hd_fs_drv_init_load_bs_lba
   886                              <1> loc_hd_fs_drv_init_load_bs_chs:
   887 000073C8 8A7601              <1> 	mov	dh, [esi+ptBeginHead]
   888 000073CB 668B4E02            <1> 	mov	cx, [esi+ptBeginSector]
   889 000073CF 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
   890                              <1> 	;mov	ebx, DOSBootSectorBuff
   891 000073D3 E8EDDBFFFF          <1> 	call	int13h
   892 000073D8 7311                <1> 	jnc	short loc_hd_drv_fs_boot_validation
   893                              <1> loc_validate_hd_fs_partition_err_retn:
   894 000073DA C3                  <1> 	retn
   895                              <1> loc_validate_hd_fs_partition_stc_retn:
   896 000073DB F9                  <1> 	stc
   897 000073DC C3                  <1> 	retn
   898                              <1> loc_hd_fs_drv_init_load_bs_lba:
   899                              <1> 	; DL = Physical drive number
   900                              <1> 	;mov	esi, ebx
   901 000073DD 8B4E08              <1>    	mov	ecx, [esi+ptStartSector] ; sector number
   902                              <1> 	;mov	ebx, DOSBootSectorBuff ; buffer address
   903                              <1> 	; LBA read/write (with private LBA function) 
   904                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
   905                              <1> 	; dl = physical drive number (0,1, 80h, 81h, 82h, 83h)
   906 000073E0 B41B                <1> 	mov	ah, 1Bh ; LBA read
   907 000073E2 B001                <1> 	mov	al, 1 ; sector count
   908 000073E4 E8DCDBFFFF          <1> 	call	int13h
   909 000073E9 72EF                <1> 	jc	short loc_validate_hd_fs_partition_err_retn
   910                              <1> loc_hd_drv_fs_boot_validation:
   911                              <1> 	;mov	esi, DOSBootSectorBuff
   912 000073EB 89DE                <1> 	mov	esi, ebx ; Boot sector buffer
   913 000073ED 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
   914 000073F6 75E3                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
   915                              <1>         ;
   916                              <1> 	;Singlix FS Extensions to TR-DOS (7/6/2009) 
   917 000073F8 66817E034653        <1> 	cmp	word [esi+bs_FS_Identifier], 'FS' ; 03/02/2018
   918 000073FE 75DB                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
   919                              <1>         ;'A1h' check is not necessary
   920                              <1> 	;  if 'FS' check is passed as OK/Yes.
   921 00007400 807E09A1            <1> 	cmp	byte [esi+bs_FS_PartitionID], 0A1h
   922 00007404 75D5                <1> 	jne	short loc_validate_hd_fs_partition_stc_retn
   923                              <1> 	;
   924 00007406 89EF                <1> 	mov	edi, ebp ; 10/01/2016
   925                              <1> 	;
   926 00007408 8A462D              <1> 	mov	al, byte [esi+bs_FS_LBA_Ready]
   927 0000740B 884705              <1> 	mov	[edi+LD_FS_LBAYes], al
   928                              <1> 	;
   929                              <1> 	; 03/01/2010 CHS -> DOS FAT/BPB compatibility fix
   930 0000740E 8A4608              <1> 	mov	al, [esi+bs_FS_MediaAttrib]
   931 00007411 884706              <1> 	mov	byte [edi+LD_FS_MediaAttrib], al
   932                              <1> 	;
   933 00007414 8A460A              <1> 	mov	al, [esi+bs_FS_VersionMaj]
   934 00007417 884707              <1> 	mov	[edi+LD_FS_VersionMajor], al
   935                              <1> 	;
   936 0000741A 668B4606            <1> 	mov	ax, [esi+bs_FS_BytesPerSec]
   937 0000741E 66894711            <1> 	mov	[edi+LD_FS_BytesPerSec], ax
   938 00007422 8A462E              <1> 	mov	al, [esi+bs_FS_SecPerTrack]
   939 00007425 30E4                <1> 	xor	ah, ah ; 09/12/2017
   940 00007427 6689471E            <1> 	mov	[edi+LD_FS_SecPerTrack], ax
   941 0000742B 8A462F              <1> 	mov	al, [esi+bs_FS_Heads]
   942 0000742E 66894720            <1> 	mov	[edi+LD_FS_NumHeads], ax
   943                              <1> 	;
   944 00007432 8B4628              <1> 	mov	eax, [esi+bs_FS_UnDelDirD]
   945 00007435 894722              <1> 	mov	[edi+LD_FS_UnDelDirD], eax
   946 00007438 8B5618              <1> 	mov	edx, [esi+bs_FS_MATLocation]
   947 0000743B 89570C              <1> 	mov	[edi+LD_FS_MATLocation], edx
   948 0000743E 8B461C              <1> 	mov	eax, [esi+bs_FS_RootDirD]
   949 00007441 894708              <1> 	mov	[edi+LD_FS_RootDirD], eax
   950 00007444 8B460C              <1> 	mov	eax, [esi+bs_FS_BeginSector]
   951 00007447 89476C              <1> 	mov	[edi+LD_FS_BeginSector], eax
   952 0000744A 8B4710              <1> 	mov	eax, [edi+bs_FS_VolumeSize]
   953 0000744D 894770              <1> 	mov	[edi+LD_FS_VolumeSize], eax
   954                              <1> 	;
   955 00007450 89D0                <1> 	mov	eax, edx ; [edi+LD_FS_MATLocation]
   956 00007452 03476C              <1> 	add	eax, [edi+LD_FS_BeginSector]
   957 00007455 89FE                <1> 	mov	esi, edi
   958                              <1> mread_hd_fs_MAT_sector:
   959                              <1>         ;mov	ebx, DOSBootSectorBuff
   960                              <1> 	;mov	ecx, 1
   961                              <1> 	; 25/07/2022
   962 00007457 29C9                <1> 	sub	ecx, ecx
   963 00007459 FEC1                <1> 	inc	cl
   964                              <1> 	; ecx = 1
   965 0000745B E8A0AB0000          <1> 	call	disk_read
   966 00007460 7248                <1> 	jc	short loc_validate_hd_fs_partition_retn
   967                              <1> 	; EDI will not be changed
   968 00007462 89DE                <1> 	mov	esi, ebx
   969                              <1> use_hdfs_mat_sector_params:
   970 00007464 8B460C              <1> 	mov	eax, [esi+FS_MAT_DATLocation]
   971 00007467 894714              <1> 	mov	[edi+LD_FS_DATLocation], eax
   972 0000746A 8B4610              <1> 	mov	eax, [esi+FS_MAT_DATScount]
   973 0000746D 894718              <1> 	mov	[edi+LD_FS_DATSectors], eax
   974 00007470 8B4614              <1> 	mov	eax, [esi+FS_MAT_FreeSectors]
   975 00007473 894774              <1>         mov     [edi+LD_FS_FreeSectors], eax
   976 00007476 8B4618              <1> 	mov	eax, [esi+FS_MAT_FirstFreeSector]
   977 00007479 894778              <1> 	mov	[edi+LD_FS_FirstFreeSector], eax
   978 0000747C 8B4708              <1> 	mov	eax, [edi+LD_FS_RootDirD]
   979 0000747F 03476C              <1> 	add	eax, [edi+LD_FS_BeginSector]
   980 00007482 89FE                <1> 	mov	esi, edi
   981                              <1> read_hd_fs_RDT_sector:
   982 00007484 BB[92820100]        <1> 	mov	ebx, DOSBootSectorBuff
   983                              <1> 	;mov	ecx, 1
   984 00007489 B101                <1> 	mov	cl, 1
   985 0000748B E870AB0000          <1> 	call	disk_read
   986 00007490 7218                <1> 	jc	short loc_validate_hd_fs_partition_retn
   987                              <1> 	; EDI will not be changed
   988 00007492 89DE                <1> 	mov	esi, ebx
   989                              <1> use_hdfs_RDT_sector_params:
   990 00007494 8B461C              <1> 	mov	eax, [esi+FS_RDT_VolumeSerialNo]
   991 00007497 894728              <1> 	mov	[edi+LD_FS_VolumeSerial], eax
   992 0000749A 57                  <1> 	push	edi
   993                              <1> 	;mov	ecx, 16
   994 0000749B B110                <1> 	mov	cl, 16
   995 0000749D 83C640              <1> 	add	esi, FS_RDT_VolumeName
   996 000074A0 83C72C              <1> 	add	edi, LD_FS_VolumeName
   997 000074A3 F3A5                <1> 	rep	movsd ; 64 bytes
   998 000074A5 5E                  <1> 	pop	esi
   999                              <1> 		; Volume Name Reset
  1000 000074A6 C6467E06            <1>         mov     byte [esi+LD_FS_MediaChanged], 6
  1001                              <1> 	;
  1002                              <1>         ;mov	cl, [Last_DOS_DiskNo] 
  1003                              <1> 	;add	cl, 'A'
  1004                              <1> 	;mov	[esi+LD_FS_Name], cl
  1005                              <1> 
  1006                              <1> loc_validate_hd_fs_partition_retn:
  1007 000074AA C3                  <1> 	retn
  1008                              <1> 
  1009                              <1> load_masterboot:
  1010                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
  1011                              <1> 	; 14/07/2020 (Reset function has been removed)
  1012                              <1> 	;
  1013                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
  1014                              <1> 	; 2005 - 2011
  1015                              <1> 	; input -> DL = drive number
  1016                              <1> ;	mov	ah, 0Dh ; Alternate disk reset
  1017                              <1> ;	call	int13h
  1018                              <1> ;	jnc	short pass_reset_error
  1019                              <1> ;harddisk_error:
  1020                              <1> ;  	retn
  1021                              <1> ;pass_reset_error:
  1022 000074AB BB[827F0100]        <1> 	mov	ebx, MasterBootBuff
  1023                              <1> 	;mov	ax, 0201h
  1024                              <1> 	;mov	cx, 1
  1025                              <1> 	; 25/07/2022
  1026                              <1> 	;xor	ecx, ecx
  1027                              <1> 	;inc	cl
  1028 000074B0 B101                <1> 	mov	cl, 1
  1029                              <1> 	; ecx = 1
  1030 000074B2 89C8                <1> 	mov	eax, ecx ; ch = cylinder = 0
  1031 000074B4 B402                <1> 	mov	ah, 2  ; chs read
  1032                              <1> 	; eax = 0201h
  1033 000074B6 30F6                <1> 	xor	dh, dh ; head = 0
  1034 000074B8 E808DBFFFF          <1> 	call	int13h
  1035 000074BD 720C                <1> 	jc	short harddisk_error
  1036                              <1> 	;
  1037 000074BF 66813D[80810100]55- <1> 	cmp	word [MBIDCode], 0AA55h
  1037 000074C7 AA                  <1>
  1038 000074C8 7401                <1> 	je	short load_masterboot_ok
  1039 000074CA F9                  <1> 	stc
  1040                              <1> harddisk_error:
  1041                              <1> load_masterboot_ok:
  1042 000074CB C3                  <1> 	retn
  1043                              <1> 
  1044                              <1> get_free_FAT_sectors:
  1045                              <1> 	; 29/08/2023
  1046                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
  1047                              <1> 	; 21/12/2017
  1048                              <1> 	; 29/02/2016
  1049                              <1> 	; 13/02/2016
  1050                              <1> 	; 04/02/2016
  1051                              <1> 	; 07/01/2016 (TRDOS 386 = TRDOS v2.0)
  1052                              <1> 	; 11/07/2010
  1053                              <1> 	; 21/06/2009
  1054                              <1> 	; INPUT: ESI = Logical DOS Drive Description Table address
  1055                              <1> 	; OUTPUT: STC => Error
  1056                              <1>         ;	cf = 0 and EAX = Free FAT sectors
  1057                              <1> 	; Also, related parameters and FAT buffer will be reset and updated
  1058                              <1> 
  1059 000074CC 31C0                <1> 	xor	eax, eax
  1060                              <1> 	;mov	[esi+LD_FreeSectors], eax ; Reset
  1061                              <1> 	
  1062 000074CE 807E0302            <1>         cmp     byte [esi+LD_FATType], 2
  1063 000074D2 7653                <1> 	jna	short loc_gfc_get_fat_free_clusters
  1064                              <1> 
  1065                              <1> 	; 29/02/2016
  1066 000074D4 48                  <1> 	dec	eax ; 0FFFFFFFFh
  1067 000074D5 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count (reset)
  1068 000074D8 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First Free Cluster (reset)
  1069 000074DB 40                  <1> 	inc	eax ; 0
  1070                              <1> 	;
  1071 000074DC 668B4636            <1> 	mov	ax, [esi+LD_BPB+BPB_FSInfo]
  1072 000074E0 03466C              <1> 	add	eax, [esi+LD_StartSector]
  1073                              <1> 
  1074 000074E3 BB[92820100]        <1> 	mov	ebx, DOSBootSectorBuff
  1075                              <1> 	;mov	ecx, 1
  1076                              <1> 	; 25/07/2022
  1077 000074E8 31C9                <1> 	xor	ecx, ecx
  1078 000074EA FEC1                <1> 	inc	cl
  1079                              <1> 	; ecx = 1
  1080 000074EC E80FAB0000          <1>  	call	disk_read
  1081 000074F1 7301                <1> 	jnc	short loc_gfc_check_fsinfo_signs
  1082                              <1> retn_gfc_get_fsinfo_sec:
  1083 000074F3 C3                  <1> 	retn
  1084                              <1> 
  1085                              <1> loc_gfc_check_fsinfo_signs:
  1086 000074F4 BB[92820100]        <1> 	mov 	ebx, DOSBootSectorBuff ; 13/02/2016
  1087 000074F9 813B52526141        <1>         cmp     dword [ebx], 41615252h
  1088 000074FF 7524                <1> 	jne	short retn_gfc_get_fsinfo_stc
  1089                              <1> 	;add	ebx, 484
  1090                              <1> 	;cmp	dword [ebx], 61417272h
  1091 00007501 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
  1091 0000750A 61                  <1>
  1092 0000750B 7518                <1> 	jne	short retn_gfc_get_fsinfo_stc
  1093                              <1> 	;add	ebx, 4
  1094                              <1> 	;mov	eax, [ebx]
  1095 0000750D 8B83E8010000        <1> 	mov	eax, [ebx+488]
  1096                              <1> 	; 29/02/2016
  1097 00007513 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count
  1098 00007516 8B93EC010000        <1> 	mov	edx, [ebx+492] 
  1099                              <1> 	; 29/08/2023 (BugFix)
  1100 0000751C 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx ; First Free Cluster
  1101                              <1> 	; 21/12/2017
  1102 0000751F 89C3                <1> 	mov	ebx, eax ; (initial value = 0FFFFFFFFh)
  1103 00007521 43                  <1> 	inc	ebx ; 0FFFFFFFFh -> 0  
  1104 00007522 7513                <1> 	jnz	short short retn_from_get_free_fat32_clusters
  1105 00007524 C3                  <1> 	retn
  1106                              <1> 
  1107                              <1> retn_gfc_get_fsinfo_stc:
  1108 00007525 F9                  <1> 	stc
  1109 00007526 C3                  <1> 	retn
  1110                              <1> 
  1111                              <1> loc_gfc_get_fat_free_clusters:
  1112                              <1> 	;mov	eax, 2
  1113 00007527 B002                <1> 	mov	al, 2
  1114                              <1> 	;mov	[FAT_CurrentCluster], eax
  1115                              <1> loc_gfc_loop_get_next_cluster:
  1116 00007529 E8F24D0000          <1> 	call	get_next_cluster
  1117 0000752E 730E                <1> 	jnc	short loc_gfc_free_fat_clusters_cont
  1118 00007530 21C0                <1> 	and	eax, eax
  1119 00007532 7411                <1> 	jz	short loc_gfc_pass_inc_free_cluster_count
  1120                              <1> 
  1121                              <1> retn_from_get_free_fat_clusters:
  1122 00007534 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors] ; Free clusters !
  1123                              <1> retn_from_get_free_fat32_clusters:
  1124 00007537 0FB65E13            <1>         movzx	ebx, byte [esi+LD_BPB+BPB_SecPerClust]
  1125 0000753B F7E3                <1>       	mul	ebx
  1126                              <1> 	;mov	[esi+LD_FreeSectors], eax ; Free sectors
  1127                              <1> retn_get_free_sectors_calc:
  1128 0000753D C3                  <1> 	retn
  1129                              <1> 
  1130                              <1> loc_gfc_free_fat_clusters_cont:
  1131 0000753E 09C0                <1> 	or	eax, eax
  1132 00007540 7503                <1> 	jnz	short loc_gfc_pass_inc_free_cluster_count
  1133 00007542 FF4674              <1> 	inc	dword [esi+LD_FreeSectors] ; Free clusters !
  1134                              <1>    
  1135                              <1> loc_gfc_pass_inc_free_cluster_count:
  1136                              <1> 	;mov	eax, [FAT_CurrentCluster]
  1137 00007545 89C8                <1> 	mov	eax, ecx ; [FAT_CurrentCluster]
  1138 00007547 3B4678              <1> 	cmp	eax, [esi+LD_Clusters]
  1139 0000754A 77E8                <1> 	ja	short retn_from_get_free_fat_clusters
  1140 0000754C 40                  <1> 	inc	eax
  1141                              <1> 	;mov	[FAT_CurrentCluster], eax
  1142 0000754D EBDA                <1> 	jmp	short loc_gfc_loop_get_next_cluster
  1143                              <1> 
  1144                              <1> floppy_drv_init:
  1145                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
  1146                              <1> 	; 09/12/2017
  1147                              <1> 	; 06/07/2016
  1148                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
  1149                              <1> 	; 24/07/2011
  1150                              <1> 	; 04/07/2009
  1151                              <1> 	; INPUT ->
  1152                              <1> 	;	DL = Drive number (0,1)
  1153                              <1> 	; OUTPUT ->
  1154                              <1> 	;	BL = drive name
  1155                              <1> 	;	BH = drive number
  1156                              <1> 	;	ESI = Logical DOS drv description table
  1157                              <1> 	;	EAX = Volume serial number
  1158                              <1> 
  1159 0000754F BE[3C660000]        <1> 	mov	esi, fd0_type ; 10/01/2016
  1160 00007554 BF00010900          <1> 	mov	edi, Logical_DOSDisks
  1161 00007559 08D2                <1> 	or	dl, dl
  1162 0000755B 7407                <1> 	jz	short loc_drv_init_fd0_fd1
  1163 0000755D 81C700010000        <1> 	add	edi, 100h
  1164 00007563 46                  <1> 	inc	esi ; fd1_type ; 10/01/2016
  1165                              <1> loc_drv_init_fd0_fd1:
  1166 00007564 C6477E00            <1> 	mov	byte [edi+LD_MediaChanged], 0
  1167 00007568 803E01              <1> 	cmp	byte [esi], 1 ; type (>0 if it is existing) 
  1168                              <1> 		; 4 = 1.44 MB, 80 track, 3 1/2"
  1169 0000756B 7221                <1> 	jb	short read_fd_boot_sector_retn
  1170 0000756D 885702              <1> 	mov	[edi+LD_PhyDrvNo], dl
  1171                              <1> read_fd_boot_sector:
  1172 00007570 30F6                <1> 	xor	dh, dh
  1173 00007572 B904000000          <1> 	mov	ecx, 4 ; Retry Count
  1174                              <1> read_fd_boot_sector_again:
  1175 00007577 51                  <1> 	push 	ecx
  1176                              <1> 	;mov	cx, 1
  1177 00007578 B101                <1> 	mov	cl, 1
  1178 0000757A 66B80102            <1> 	mov	ax, 0201h ; Read 1 sector
  1179 0000757E BB[92820100]        <1> 	mov	ebx, DOSBootSectorBuff
  1180 00007583 E83DDAFFFF          <1> 	call	int13h
  1181 00007588 59                  <1> 	pop	ecx
  1182 00007589 7304                <1> 	jnc	short use_fd_boot_sector_params
  1183 0000758B E2EA                <1> 	loop	read_fd_boot_sector_again
  1184                              <1> 
  1185                              <1> read_fd_boot_sector_stc_retn:
  1186 0000758D F9                  <1> 	stc
  1187                              <1> read_fd_boot_sector_retn:
  1188 0000758E C3                  <1> 	retn
  1189                              <1> 
  1190                              <1> use_fd_boot_sector_params:
  1191                              <1> 	;mov	esi, DOSBootSectorBuff
  1192 0000758F 89DE                <1> 	mov	esi, ebx
  1193 00007591 6681BEFE01000055AA  <1> 	cmp	word [esi+BS_Validation], 0AA55h
  1194 0000759A 75F1                <1> 	jne	short read_fd_boot_sector_stc_retn
  1195 0000759C 66817E035346        <1>         cmp     word [esi+bs_FS_Identifier], 'SF'
  1196                              <1> 	;jne	use_fd_fatfs_boot_sector_params
  1197                              <1> 	; 25/07/2022
  1198 000075A2 7405                <1> 	je	short use_fdfs_boot_sector_params
  1199 000075A4 E9A1000000          <1> 	jmp	use_fd_fatfs_boot_sector_params
  1200                              <1> use_fdfs_boot_sector_params:
  1201 000075A9 8A462D              <1> 	mov	al, [esi+bs_FS_LBA_Ready]
  1202 000075AC 884705              <1> 	mov	[edi+LD_FS_LBAYes], al
  1203                              <1> 	;
  1204                              <1> 	; 03/01/2010 CHS -> DOS FAT/BPB compatibility fix
  1205 000075AF 8A4608              <1> 	mov	al, [esi+bs_FS_MediaAttrib]
  1206 000075B2 884706              <1> 	mov	[edi+LD_FS_MediaAttrib], al
  1207                              <1> 	;
  1208 000075B5 8A460A              <1>         mov	al, [esi+bs_FS_VersionMaj]
  1209 000075B8 884707              <1> 	mov	byte [edi+LD_FS_VersionMajor], al
  1210 000075BB 668B4606            <1> 	mov	ax, [esi+bs_FS_BytesPerSec]
  1211 000075BF 66894711            <1> 	mov	[edi+LD_FS_BytesPerSec], ax
  1212 000075C3 8A462E              <1> 	mov	al, [esi+bs_FS_SecPerTrack]
  1213 000075C6 28E4                <1> 	sub	ah, ah ; 09/12/2017
  1214 000075C8 6689471E            <1> 	mov	[edi+LD_FS_SecPerTrack], ax
  1215 000075CC 8A462F              <1> 	mov	al, [esi+bs_FS_Heads]
  1216 000075CF 66894720            <1> 	mov	[edi+LD_FS_NumHeads], ax
  1217                              <1> 	;
  1218 000075D3 8B4628              <1> 	mov	eax, [esi+bs_FS_UnDelDirD]
  1219 000075D6 894722              <1> 	mov	[edi+LD_FS_UnDelDirD], eax
  1220 000075D9 8B4618              <1> 	mov	eax, [esi+bs_FS_MATLocation]
  1221 000075DC 89470C              <1> 	mov	[edi+LD_FS_MATLocation], eax
  1222 000075DF 8B461C              <1> 	mov	eax, [esi+bs_FS_RootDirD]
  1223 000075E2 894708              <1> 	mov	[edi+LD_FS_RootDirD], eax
  1224 000075E5 8B460C              <1> 	mov	eax, [esi+bs_FS_BeginSector]
  1225 000075E8 89476C              <1> 	mov	[edi+LD_FS_BeginSector], eax
  1226 000075EB 8B4610              <1> 	mov	eax, [esi+bs_FS_VolumeSize]
  1227 000075EE 894770              <1> 	mov	[edi+LD_FS_VolumeSize], eax
  1228                              <1> 	;		
  1229 000075F1 89FE                <1> 	mov	esi, edi
  1230 000075F3 8B460C              <1>  	mov	eax, [esi+LD_FS_MATLocation]
  1231                              <1> 	;add	eax, [edi+LD_FS_BeginSector]
  1232                              <1> read_fd_MAT_sector_again:
  1233                              <1> 	;mov	ebx, DOSBootSectorBuff
  1234                              <1> 	;mov	ecx, 1
  1235 000075F6 B101                <1> 	mov	cl, 1
  1236 000075F8 E809AA0000          <1> 	call	chs_read
  1237 000075FD 89DE                <1> 	mov	esi, ebx
  1238                              <1> 	;jnc	short use_fdfs_mat_sector_params
  1239                              <1> 	;jmp	short read_fd_boot_sector_retn
  1240                              <1> 	;retn
  1241                              <1> 	; 25/07/2022
  1242 000075FF 7248                <1> 	jc	short read_fd_RDT_sector_retn
  1243                              <1> use_fdfs_mat_sector_params:
  1244 00007601 8B460C              <1> 	mov	eax, [esi+FS_MAT_DATLocation]
  1245 00007604 894714              <1> 	mov	[edi+LD_FS_DATLocation], eax
  1246 00007607 8B4610              <1> 	mov	eax, [esi+FS_MAT_DATScount]
  1247 0000760A 894718              <1> 	mov	[edi+LD_FS_DATSectors], eax
  1248 0000760D 8B4714              <1> 	mov	eax, [edi+FS_MAT_FreeSectors]
  1249 00007610 894774              <1> 	mov	[edi+LD_FS_FreeSectors], eax
  1250 00007613 8B4618              <1> 	mov	eax, [esi+FS_MAT_FirstFreeSector]
  1251 00007616 894778              <1> 	mov	[edi+LD_FS_FirstFreeSector], eax
  1252                              <1> 	;
  1253 00007619 89FE                <1> 	mov	esi, edi
  1254 0000761B 8B4608              <1>  	mov	eax, [esi+LD_FS_RootDirD]
  1255                              <1> read_fd_RDT_sector_again:
  1256                              <1> 	;mov	ebx, DOSBootSectorBuff
  1257                              <1> 	;mov	cx, 1
  1258 0000761E B101                <1> 	mov	cl, 1
  1259 00007620 E8E1A90000          <1> 	call	chs_read
  1260 00007625 89DE                <1> 	mov	esi, ebx
  1261 00007627 7220                <1> 	jc	short read_fd_RDT_sector_retn
  1262                              <1> use_fdfs_RDT_sector_params:
  1263 00007629 8B461C              <1> 	mov	eax, [esi+FS_RDT_VolumeSerialNo]
  1264 0000762C 894728              <1> 	mov	[edi+LD_FS_VolumeSerial], eax
  1265 0000762F 57                  <1> 	push	edi
  1266                              <1> 	;mov	ecx, 16
  1267 00007630 B110                <1> 	mov	cl, 16	
  1268 00007632 83C640              <1> 	add	esi, FS_RDT_VolumeName
  1269 00007635 83C72C              <1> 	add	edi, LD_FS_VolumeName
  1270 00007638 F3A5                <1> 	rep	movsd ; 64 bytes
  1271 0000763A 5E                  <1> 	pop	esi
  1272 0000763B C6460300            <1> 	mov	byte [esi+LD_FATType], 0
  1273 0000763F C64604A1            <1> 	mov	byte [esi+LD_FSType], 0A1h
  1274 00007643 E9A2000000          <1>         jmp     loc_cont_use_fd_boot_sector_params
  1275                              <1> 
  1276                              <1> read_fd_RDT_sector_stc_retn:
  1277 00007648 F9                  <1> 	stc
  1278                              <1> read_fd_RDT_sector_retn:
  1279 00007649 C3                  <1> 	retn
  1280                              <1> 
  1281                              <1> use_fd_fatfs_boot_sector_params:
  1282 0000764A 807E2629            <1> 	cmp	byte [esi+BS_BootSig], 29h
  1283 0000764E 75F8                <1> 	jne	short read_fd_RDT_sector_stc_retn
  1284 00007650 807E15F0            <1> 	cmp	byte [esi+BPB_Media], 0F0h
  1285 00007654 72F3                <1> 	jb	short read_fd_RDT_sector_retn
  1286 00007656 57                  <1> 	push	edi
  1287 00007657 83C706              <1> 	add	edi, LD_BPB
  1288                              <1> 	;mov	ecx, 16
  1289 0000765A B110                <1> 	mov	cl, 16
  1290 0000765C F3A5                <1> 	rep	movsd ; 64 bytes
  1291 0000765E 5E                  <1> 	pop	esi
  1292 0000765F 31C0                <1> 	xor	eax, eax
  1293 00007661 89466C              <1> 	mov	[esi+LD_StartSector], eax ; 0
  1294 00007664 668B461C            <1> 	mov	ax, [esi+LD_BPB+BPB_FATSz16]
  1295 00007668 8A4E16              <1> 	mov	cl, [esi+LD_BPB+BPB_NumFATs]
  1296 0000766B F7E1                <1>   	mul	ecx
  1297                              <1> 	; edx = 0 !
  1298 0000766D 668B5614            <1> 	mov	dx, [esi+LD_BPB+BPB_RsvdSecCnt]
  1299 00007671 66895660            <1> 	mov	[esi+LD_FATBegin], dx
  1300                              <1> 	; 25/07/2022
  1301 00007675 01D0                <1> 	add	eax, edx
  1302                              <1> 	;add	ax, dx
  1303 00007677 894664              <1> 	mov	[esi+LD_ROOTBegin], eax
  1304 0000767A 894668              <1> 	mov	[esi+LD_DATABegin], eax 
  1305 0000767D 668B5617            <1> 	mov	dx, [esi+LD_BPB+BPB_RootEntCnt]
  1306                              <1> 	;;shl	edx, 5 ; * 32 (Size of a directory entry)
  1307                              <1> 	;shl	dx, 5
  1308                              <1> 	;;add	edx, 511
  1309                              <1> 	;add	dx, 511
  1310                              <1> 	;;shr	edx, 9 ; edx = ((edx*32)+511) / 512
  1311                              <1> 	;shr	dx, 9
  1312 00007681 6683C20F            <1> 	add	dx, 15 ; 06/07/2016 (+(512/32)-1)
  1313                              <1> 	;shr	dx, 4 ; / 16 (==16 entries per sector)
  1314                              <1> 	; 25/07/2022
  1315 00007685 C1EA04              <1> 	shr	edx, 4
  1316 00007688 015668              <1> 	add 	[esi+LD_DATABegin], edx ; + rd sectors
  1317                              <1> 	;movzx	eax, word [esi+LD_BPB+BPB_TotalSec16]
  1318 0000768B 668B4619            <1> 	mov	ax, [esi+LD_BPB+BPB_TotalSec16]
  1319 0000768F 894670              <1> 	mov	[esi+LD_TotalSectors], eax
  1320 00007692 2B4668              <1> 	sub	eax, [esi+LD_DATABegin]
  1321                              <1>   	;movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust]
  1322 00007695 8A4E13              <1> 	mov	cl, [esi+LD_BPB+BPB_SecPerClust]
  1323 00007698 80F901              <1> 	cmp	cl, 1
  1324 0000769B 7604                <1> 	jna	short save_fd_fatfs_cluster_count
  1325                              <1> 	; 25/07/2022
  1326 0000769D 29D2                <1> 	sub	edx, edx
  1327                              <1> 	;sub	dx, dx ; 0
  1328                              <1> 	;sub	dl, dl ; 06/07/2016
  1329 0000769F F7F1                <1> 	div	ecx
  1330                              <1> save_fd_fatfs_cluster_count:
  1331 000076A1 894678              <1> 	mov	[esi+LD_Clusters], eax
  1332                              <1> 
  1333                              <1>       ; Maximum Valid Cluster Number = EAX +1
  1334                              <1>       ; with 2 reserved clusters = EAX +2
  1335                              <1> 
  1336                              <1> reset_FAT_buffer_decriptors:
  1337 000076A4 29C0                <1> 	sub	eax, eax ; 0  
  1338 000076A6 A2[96840100]        <1> 	mov	[FAT_BuffValidData], al ; 0
  1339 000076AB A2[97840100]        <1> 	mov	[FAT_BuffDrvName], al ; 0
  1340 000076B0 A3[9A840100]        <1> 	mov	[FAT_BuffSector], eax ; 0
  1341                              <1> 
  1342                              <1> read_fd_FAT_sectors:
  1343 000076B5 BB001C0900          <1>   	mov	ebx, FAT_Buffer
  1344 000076BA 668B4614            <1> 	mov	ax, [esi+LD_BPB+BPB_RsvdSecCnt]
  1345                              <1> 	;mov	ecx, 3
  1346 000076BE B103                <1> 	mov	cl, 3 ; 3 sectors
  1347 000076C0 E841A90000          <1> 	call	chs_read
  1348 000076C5 7240                <1> 	jc	short read_fd_FAT_sectors_retn
  1349                              <1> use_fd_FAT_sectors:
  1350 000076C7 8A4602              <1> 	mov	al, [esi+LD_PhyDrvNo]
  1351 000076CA 0441                <1> 	add	al, 'A' 
  1352 000076CC A2[97840100]        <1> 	mov	[FAT_BuffDrvName], al
  1353 000076D1 C605[96840100]01    <1>  	mov	byte [FAT_BuffValidData], 1
  1354 000076D8 E82B000000          <1> 	call	fd_init_calculate_free_clusters
  1355 000076DD 7228                <1> 	jc	short read_fd_FAT_sectors_retn
  1356                              <1> 
  1357                              <1> loc_use_fd_boot_sector_params_FAT:
  1358 000076DF C6460301            <1> 	mov	byte [esi+LD_FATType], 1 ; FAT 12
  1359 000076E3 C6460401            <1> 	mov	byte [esi+LD_FSType], 1
  1360 000076E7 8B462D              <1>         mov     eax, [esi+LD_BPB+VolumeID]
  1361                              <1> loc_cont_use_fd_boot_sector_params:
  1362 000076EA 8A7E02              <1> 	mov	bh, [esi+LD_PhyDrvNo]
  1363 000076ED 887E7D              <1> 	mov	[esi+LD_DParamEntry], bh
  1364 000076F0 88FB                <1> 	mov	bl, bh
  1365 000076F2 80C341              <1> 	add	bl, 'A'
  1366 000076F5 881E                <1> 	mov	byte [esi+LD_Name], bl
  1367 000076F7 C6460101            <1> 	mov	byte [esi+LD_DiskType], 1
  1368 000076FB C6460500            <1> 	mov	byte [esi+LD_LBAYes], 0
  1369 000076FF C6467C00            <1> 	mov	byte [esi+LD_PartitionEntry], 0
  1370 00007703 C6467E06            <1> 	mov	byte [esi+LD_MediaChanged], 6 ; Volume Name Reset
  1371                              <1> 
  1372                              <1> read_fd_FAT_sectors_retn:
  1373 00007707 C3                  <1> 	retn
  1374                              <1> 
  1375                              <1> fd_init_calculate_free_clusters:
  1376                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
  1377                              <1> 	; 09/12/2017
  1378                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
  1379                              <1> 	; 04/07/2009
  1380                              <1> 	; INPUT ->
  1381                              <1> 	;     ESI = Logical DOS drive description table address
  1382                              <1> 	; OUTPUT ->
  1383                              <1> 	;    [ESI+LD_FreeSectors] will be set
  1384                              <1> 	
  1385 00007708 29C0                <1> 	sub	eax, eax
  1386 0000770A 894674              <1> 	mov	[esi+LD_FreeSectors], eax ; 0
  1387 0000770D B002                <1> 	mov	al, 2 ; eax = 2
  1388                              <1> 
  1389                              <1> fd_init_loop_get_next_cluster:
  1390 0000770F E828000000          <1> 	call	fd_init_get_next_cluster
  1391 00007714 7225                <1> 	jc	short fd_init_calculate_free_clusters_retn
  1392                              <1> 
  1393                              <1> fd_init_free_fat_clusters:
  1394                              <1> 	;cmp 	eax, 0
  1395                              <1> 	;ja	short fd_init_pass_inc_free_cluster_count
  1396                              <1> 	;and	eax, eax
  1397                              <1> 	;jnz	short fd_init_pass_inc_free_cluster_count
  1398                              <1> 	;and	ax, ax
  1399 00007716 21C0                <1> 	and	eax, eax ; 25/07/2022
  1400 00007718 7503                <1> 	jnz	short fd_init_pass_inc_free_cluster_count
  1401                              <1> 	; 25/07/2022
  1402 0000771A FF4674              <1> 	inc	dword [esi+LD_FreeSectors]
  1403                              <1>         ;inc	word [esi+LD_FreeSectors]
  1404                              <1> 
  1405                              <1> fd_init_pass_inc_free_cluster_count:
  1406                              <1>   	; 25/07/2022
  1407 0000771D A1[92840100]        <1> 	mov	eax, [FAT_CurrentCluster]
  1408                              <1> 	;mov	ax, [FAT_CurrentCluster]
  1409 00007722 3B4678              <1> 	cmp	eax, [esi+LD_Clusters]
  1410                              <1> 	;cmp	ax, [esi+LD_Clusters]
  1411 00007725 7703                <1> 	ja	short short retn_from_fd_init_calculate_free_clusters
  1412 00007727 40                  <1> 	inc	eax
  1413                              <1> 	;inc	ax
  1414 00007728 EBE5                <1> 	jmp	short fd_init_loop_get_next_cluster
  1415                              <1> 
  1416                              <1> retn_from_fd_init_calculate_free_clusters:
  1417                              <1> 	; 25/07/2022
  1418                              <1> 	;xor	eax, eax
  1419 0000772A 30E4                <1> 	xor	ah, ah
  1420 0000772C 8A4613              <1>   	mov	al, [esi+LD_BPB+BPB_SecPerClust]
  1421 0000772F 3C01                <1>   	cmp	al, 1
  1422 00007731 7608                <1> 	jna	short fd_init_calculate_free_clusters_retn
  1423                              <1> 	;;movzx	eax, al
  1424                              <1> 	;xor	ah, ah ; 09/12/2017
  1425                              <1> 	; 25/07/2022
  1426 00007733 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
  1427                              <1> 	;mov	cx, [esi+LD_FreeSectors] ; Count of free clusters
  1428 00007736 F7E1                <1>   	mul	ecx
  1429                              <1> 	;mul	cx
  1430 00007738 894674              <1> 	mov	[esi+LD_FreeSectors], eax
  1431                              <1> 	;mov	[esi+LD_FreeSectors], ax
  1432                              <1> fd_init_calculate_free_clusters_retn:
  1433 0000773B C3                  <1> 	retn
  1434                              <1> 
  1435                              <1> fd_init_get_next_cluster:
  1436                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
  1437                              <1> 	; 04/02/2016
  1438                              <1> 	; 02/02/2016
  1439                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
  1440                              <1> 	; 04/07/2009
  1441                              <1> 	; INPUT ->
  1442                              <1> 	;    EAX = Current cluster
  1443                              <1> 	;    ESI = Logical DOS drive description table address
  1444                              <1> 	;    EDX = 0
  1445                              <1> 	; OUTPUT ->
  1446                              <1> 	;    EAX = Next cluster
  1447                              <1> 
  1448 0000773C A3[92840100]        <1> 	mov	[FAT_CurrentCluster], eax
  1449                              <1> fd_init_get_next_cluster_readnext:
  1450 00007741 29D2                <1> 	sub	edx, edx ; 0
  1451 00007743 BB00040000          <1>   	mov	ebx, 1024 ; 400h
  1452 00007748 F7F3                <1>   	div	ebx
  1453                              <1>   	; EAX = Count of 3 FAT sectors
  1454                              <1>   	; EDX = Buffer entry index
  1455 0000774A 89C1                <1> 	mov	ecx, eax
  1456                              <1> 	;mov	eax, 3
  1457 0000774C B003                <1> 	mov	al, 3
  1458 0000774E F7E2                <1> 	mul	edx ; Multiply by 3
  1459                              <1> 	;shr	ax, 1 ; Divide by 2
  1460                              <1> 	; 25/07/2022
  1461 00007750 D1E8                <1> 	shr	eax, 1
  1462 00007752 89C3                <1> 	mov	ebx, eax ; Buffer byte offset
  1463 00007754 81C3001C0900        <1> 	add	ebx, FAT_Buffer
  1464 0000775A 89C8                <1> 	mov	eax, ecx
  1465                              <1> 	;mov	edx, 3
  1466 0000775C 66BA0300            <1> 	mov	dx, 3
  1467 00007760 F7E2                <1> 	mul	edx
  1468                              <1>   	; EAX = FAT Beginning Sector
  1469                              <1> 	; EDX = 0
  1470 00007762 8A0E                <1> 	mov	cl, [esi+LD_Name]
  1471                              <1> 	;cmp	byte [FAT_BuffValidData], 0
  1472                              <1> 	;jna	short fd_init_load_FAT_sectors0
  1473 00007764 3A0D[97840100]      <1> 	cmp	cl, [FAT_BuffDrvName]
  1474 0000776A 751D                <1> 	jne	short fd_init_load_FAT_sectors0
  1475 0000776C 3B05[9A840100]      <1> 	cmp	eax, [FAT_BuffSector]
  1476 00007772 751B                <1> 	jne	short fd_init_load_FAT_sectors1
  1477                              <1> 	; 25/07/2022
  1478 00007774 A1[92840100]        <1> 	mov	eax, [FAT_CurrentCluster]
  1479                              <1> 	;mov	al, [FAT_CurrentCluster]
  1480 00007779 D1E8                <1> 	shr	eax, 1
  1481                              <1> 	;shr	al, 1
  1482 0000777B 668B03              <1> 	mov	ax, [ebx]
  1483 0000777E 7305                <1>   	jnc	short fd_init_gnc_even
  1484                              <1> 	;shr	ax, 4
  1485                              <1> 	; 25/04/2022
  1486 00007780 C1E804              <1> 	shr	eax, 4
  1487                              <1> fd_init_gnc_clc_retn:
  1488 00007783 F8                  <1> 	clc
  1489 00007784 C3                  <1> 	retn
  1490                              <1> 
  1491                              <1> fd_init_gnc_even:
  1492 00007785 80E40F              <1> 	and	ah, 0Fh
  1493 00007788 C3                  <1> 	retn
  1494                              <1> 
  1495                              <1> fd_init_load_FAT_sectors0:
  1496 00007789 880D[97840100]      <1> 	mov 	[FAT_BuffDrvName], cl
  1497                              <1> fd_init_load_FAT_sectors1:
  1498 0000778F C605[96840100]00    <1> 	mov	byte [FAT_BuffValidData], 0
  1499 00007796 A3[9A840100]        <1> 	mov	[FAT_BuffSector], eax
  1500 0000779B 034660              <1> 	add	eax, [esi+LD_FATBegin]
  1501 0000779E BB001C0900          <1>  	mov	ebx, FAT_Buffer
  1502                              <1> 	;movzx	ecx, word [esi+LD_BPB+BPB_FATSz16]
  1503 000077A3 668B4E1C            <1> 	mov	cx, [esi+LD_BPB+BPB_FATSz16]
  1504                              <1> 	;sub	cx, [FAT_BuffSector]
  1505                              <1>         ; 25/07/2022
  1506 000077A7 2B0D[9A840100]      <1> 	sub	ecx, [FAT_BuffSector]
  1507                              <1> 	;sub	edx, edx
  1508 000077AD B203                <1> 	mov	dl, 3
  1509                              <1> 	; edx = 3 
  1510                              <1> 	;;cmp	ecx, 3
  1511                              <1> 	;cmp	cx, 3
  1512 000077AF 39D1                <1> 	cmp	ecx, edx ; 3
  1513 000077B1 7602                <1> 	jna	short fdinit_pass_fix_sector_count_3
  1514                              <1> 	;;mov	ecx, 3
  1515                              <1> 	;mov	ecx, 3
  1516 000077B3 89D1                <1> 	mov	ecx, edx ; 3
  1517                              <1> fdinit_pass_fix_sector_count_3:
  1518 000077B5 E84CA80000          <1> 	call	chs_read
  1519 000077BA 730D                <1> 	jnc	short fd_init_FAT_sectors_no_load_error
  1520 000077BC C605[96840100]00    <1> 	mov	byte [FAT_BuffValidData], 0
  1521                              <1> 		; Drv not ready or read Error !
  1522 000077C3 B80F000000          <1> 	mov	eax, ERR_DRV_NOT_RDY ; 15
  1523                              <1> 	;xor	edx, edx
  1524 000077C8 C3                  <1> 	retn
  1525                              <1> 
  1526                              <1> fd_init_FAT_sectors_no_load_error:
  1527 000077C9 C605[96840100]01    <1> 	mov	byte [FAT_BuffValidData], 1
  1528 000077D0 A1[92840100]        <1> 	mov	eax, [FAT_CurrentCluster]
  1529 000077D5 E967FFFFFF          <1>         jmp     fd_init_get_next_cluster_readnext
  1530                              <1> 
  1531                              <1> get_FAT_volume_name:
  1532                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
  1533                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
  1534                              <1> 	; 12/09/2009
  1535                              <1> 	; INPUT ->
  1536                              <1> 	;	BH = Logical DOS drive number (0,1,2,3,4 ...)
  1537                              <1> 	;       BL = 0
  1538                              <1> 	; OUTPUT ->
  1539                              <1> 	;	CF = 0 -> ESI = Volume name address
  1540                              <1> 	; 	CF = 1 -> Root volume name not found
  1541                              <1> 
  1542                              <1> 	;mov 	ah, 0FFh
  1543                              <1> 	;mov 	al, [Last_Dos_DiskNo]
  1544                              <1> 	;cmp 	al, bh
  1545                              <1> 	;jb     short loc_gfvn_dir_load_err
  1546                              <1> 
  1547 000077DA 89DE                <1> 	mov	esi, ebx
  1548 000077DC 81E600FF0000        <1> 	and	esi, 0FF00h ; esi = bh
  1549 000077E2 81C600010900        <1> 	add	esi, Logical_DOSDisks
  1550 000077E8 8A06                <1> 	mov     al, [esi+LD_Name]
  1551 000077EA 8A6603              <1> 	mov     ah, [esi+LD_FATType]
  1552 000077ED 80FC01              <1> 	cmp     ah, 1
  1553 000077F0 7210                <1> 	jb    	short loc_gfvn_dir_load_err
  1554 000077F2 3C41                <1> 	cmp 	al, 'A'
  1555 000077F4 720C                <1> 	jb      short loc_gfvn_dir_load_err
  1556 000077F6 80FC02              <1> 	cmp 	ah, 2 
  1557 000077F9 7708                <1> 	ja      short get_FAT32_root_cluster
  1558                              <1> 	
  1559 000077FB E85E4C0000          <1> 	call    load_FAT_root_directory
  1560 00007800 730B                <1> 	jnc     short loc_get_volume_name
  1561                              <1> 
  1562                              <1> loc_gfvn_dir_load_err:
  1563                              <1> loc_get_volume_name_retn: ; 29/08/2023
  1564 00007802 C3                  <1> 	retn
  1565                              <1> 
  1566                              <1> get_FAT32_root_cluster:
  1567 00007803 8B4632              <1> 	mov	eax, [esi+LD_BPB+BPB_RootClus]
  1568 00007806 E8D14C0000          <1> 	call    load_FAT_sub_directory
  1569 0000780B 72F5                <1> 	jc	short loc_get_volume_name_retn
  1570                              <1> 
  1571                              <1> loc_get_volume_name:
  1572 0000780D BE00000800          <1>         mov     esi, Directory_Buffer
  1573                              <1> 	;xor	cx, cx ; 0
  1574                              <1> 	; 25/07/2022
  1575 00007812 31C9                <1> 	xor	ecx, ecx ; 0
  1576                              <1> check_root_volume_name:
  1577 00007814 8A06                <1> 	mov	al, [esi]
  1578 00007816 08C0                <1> 	or      al, al
  1579 00007818 74E8                <1> 	jz      short loc_get_volume_name_retn
  1580 0000781A 807E0B08            <1> 	cmp     byte [esi+0Bh], 08h
  1581 0000781E 74E2                <1> 	je      short loc_get_volume_name_retn
  1582 00007820 663B0D[AC840100]    <1> 	cmp     cx, [DirBuff_LastEntry]
  1583 00007827 7306                <1> 	jnb     short pass_check_root_volume_name
  1584                              <1> 	;inc	cx
  1585                              <1> 	; 25/07/2022
  1586 00007829 41                  <1> 	inc	ecx
  1587 0000782A 83C620              <1> 	add     esi, 32
  1588 0000782D EBE5                <1> 	jmp     short check_root_volume_name
  1589                              <1> 
  1590                              <1> 	; 29/08/2023
  1591                              <1> ;loc_get_volume_name_retn:
  1592                              <1> 	;retn
  1593                              <1> 
  1594                              <1> pass_check_root_volume_name:
  1595 0000782F 803D[A8840100]03    <1> 	cmp	byte [DirBuff_FATType], 3
  1596 00007836 7230                <1> 	jb	short loc_get_volume_name_retn_xor
  1597                              <1> 
  1598 00007838 BB001C0900          <1> 	mov	ebx, FAT_Buffer
  1599 0000783D BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1600 00007842 31C0                <1> 	xor	eax, eax
  1601 00007844 8A25[A7840100]      <1> 	mov	ah, [DirBuff_DRV]
  1602 0000784A 80EC41              <1> 	sub	ah, 'A' 
  1603 0000784D 01C6                <1> 	add	esi, eax
  1604 0000784F A1[AE840100]        <1> 	mov	eax, [DirBuff_Cluster]
  1605 00007854 E8C74A0000          <1> 	call	get_next_cluster
  1606 00007859 7305                <1> 	jnc 	short loc_gfvn_load_FAT32_dir_cluster
  1607                              <1> 
  1608 0000785B 83F801              <1> 	cmp     eax, 1
  1609 0000785E F5                  <1> 	cmc
  1610 0000785F C3                  <1> 	retn
  1611                              <1> 
  1612                              <1> loc_gfvn_load_FAT32_dir_cluster:
  1613 00007860 E8774C0000          <1> 	call	load_FAT_sub_directory
  1614 00007865 73A6                <1> 	jnc	short loc_get_volume_name
  1615 00007867 C3                  <1> 	retn
  1616                              <1> 
  1617                              <1> loc_get_volume_name_retn_xor:
  1618 00007868 31C0                <1> 	xor 	eax, eax
  1619 0000786A C3                  <1> 	retn
  1620                              <1> 
  1621                              <1> get_media_change_status:
  1622                              <1> 	; 10/01/2016 (TRDOS 386 = TRDOS v2.0)
  1623                              <1> 	; 09/09/2009
  1624                              <1> 	; INPUT:
  1625                              <1> 	;     DL = Drive number (physical)
  1626                              <1> 	; OUTPUT: clc & AH = 6 media changed
  1627                              <1> 	;     clc & AH = 0 media not changed
  1628                              <1> 	;     stc -> Drive not ready or an error
  1629                              <1> 
  1630 0000786B B416                <1> 	mov	ah, 16h
  1631 0000786D E853D7FFFF          <1>   	call	int13h
  1632 00007872 80FC06              <1> 	cmp	ah, 06h
  1633 00007875 7405                <1> 	je	short loc_gmc_status_retn
  1634 00007877 08E4                <1> 	or	ah, ah
  1635 00007879 7401                <1> 	jz	short loc_gmc_status_retn
  1636                              <1> loc_gmc_status_stc_retn:
  1637 0000787B F9                  <1> 	stc
  1638                              <1> loc_gmc_status_retn:
  1639 0000787C C3                  <1> 	retn
  3432                                  %include 'trdosk3.s' ; 06/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.9) - MAIN PROGRAM : trdosk3.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 26/09/2024  (Previous: 02/12/2023, TRDOS 386 v2.0.7)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 06/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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> 	; 26/07/2022 (TRDOS 386 Kernel v2.0.5)
    21                              <1> 	; 16/10/2016
    22                              <1> 	; 02/02/2016
    23                              <1> 	; 15/01/2016 (TRDOS 386 = TRDOS v2.0)
    24                              <1> 	; 18/08/2011
    25                              <1> 	; 09/09/2009
    26                              <1> 	; INPUT:
    27                              <1> 	;   DL = Logical DOS Drive Number
    28                              <1> 	; OUTPUT:
    29                              <1> 	;  cf=1 -> Not successful
    30                              <1> 	;   EAX = Error code
    31                              <1> 	;  cf=0 ->
    32                              <1> 	;   EAX = 0 (successful)
    33                              <1> 
    34 0000787D 31DB                <1> 	xor	ebx, ebx
    35 0000787F 88D7                <1> 	mov	bh, dl
    36                              <1> 
    37                              <1> 	;cmp	dl, 1
    38                              <1> 	;jna	short loc_ccdrv_initial_media_change_check
    39                              <1> 	;cmp	bh, [Last_Dos_DiskNo]
    40                              <1> 	;ja	short loc_ccdrv_drive_not_ready_err
    41                              <1> 
    42                              <1> loc_ccdrv_initial_media_change_check:
    43 00007881 BE00010900          <1> 	mov	esi, Logical_DOSDisks
    44 00007886 01DE                <1> 	add	esi, ebx
    45                              <1> loc_ccdrv_dos_drive_name_check:
    46 00007888 80FA02              <1> 	cmp	dl, 2
    47 0000788B 720E                <1> 	jb	short loc_ccdrv_dos_drive_name_check_ok
    48                              <1> 
    49 0000788D 8A06                <1> 	mov	al, [esi+LD_Name]
    50 0000788F 2C41                <1> 	sub	al, 'A'
    51 00007891 38D0                <1> 	cmp	al, dl
    52 00007893 7406                <1> 	je	short loc_ccdrv_dos_drive_name_check_ok
    53                              <1> 
    54                              <1> loc_ccdrv_drive_not_ready_err:
    55                              <1> 	; 16/10/2016 (15h -> 15)
    56                              <1> 	;mov	eax, 15 ; Drive not ready
    57                              <1> 	; 26/07/2022
    58 00007895 29C0                <1> 	sub	eax, eax
    59 00007897 B00F                <1> 	mov	al, 15
    60                              <1> loc_change_current_drive_stc_retn:
    61 00007899 F9                  <1> 	stc
    62 0000789A C3                  <1> 	retn
    63                              <1> 
    64                              <1> loc_ccdrv_dos_drive_name_check_ok:
    65 0000789B 8A667E              <1> 	mov	ah, [esi+LD_MediaChanged]
    66 0000789E 80FC06              <1> 	cmp	ah, 6  ; VOLUME NAME CHECK/MOVE SIGN
    67 000078A1 7455                <1> 	je	short loc_ccdrv_get_FAT_volume_name_0
    68                              <1> 
    69 000078A3 80FA01              <1> 	cmp	dl, 1
    70 000078A6 777D                <1> 	ja	short loc_gmcs_init_drv_hd
    71                              <1> 
    72                              <1> loc_gmcs_init_drv_fd:
    73 000078A8 08E4                <1> 	or	ah, ah 
    74                              <1> 	; AH = 1 is initialization sign (invalid_fd_parameter)
    75 000078AA 7517                <1> 	jnz	short loc_ccdrv_call_fd_init
    76                              <1> 
    77 000078AC E8BAFFFFFF          <1> 	call	get_media_change_status
    78 000078B1 72E2                <1> 	jc	short loc_ccdrv_drive_not_ready_err
    79                              <1> 
    80 000078B3 20E4                <1> 	and	ah, ah
    81 000078B5 7476                <1> 	jz	short loc_change_current_drv3
    82                              <1> 
    83 000078B7 80F406              <1> 	xor	ah, 6
    84 000078BA 75D9                <1> 	jnz	short loc_ccdrv_drive_not_ready_err
    85                              <1> 
    86                              <1> loc_ccdrv_call_fd_init_check_vol_id:
    87 000078BC E86D090000          <1> 	call	get_volume_serial_number
    88 000078C1 730D                <1> 	jnc	short loc_ccdrv_check_vol_serial
    89                              <1> 
    90                              <1> loc_ccdrv_call_fd_init:
    91 000078C3 E887FCFFFF          <1> 	call	floppy_drv_init
    92 000078C8 731A                <1> 	jnc	short loc_reset_drv_fd_current_dir
    93                              <1> 
    94                              <1> loc_ccdrv_fdinit_fail_retn:
    95                              <1> 	; 16/10/2016
    96 000078CA B80F000000          <1> 	mov	eax, 15 ; Drive not ready
    97 000078CF C3                  <1> 	retn
    98                              <1> 
    99                              <1> loc_ccdrv_check_vol_serial:
   100 000078D0 A3[787D0100]        <1> 	mov	[Current_VolSerial], eax
   101                              <1> 	;mov	dl, bh
   102 000078D5 E875FCFFFF          <1> 	call	floppy_drv_init
   103 000078DA 72EE                <1> 	jc	short loc_ccdrv_fdinit_fail_retn
   104                              <1> 
   105 000078DC 3B05[787D0100]      <1> 	cmp	eax, [Current_VolSerial]
   106 000078E2 7445                <1> 	je	short loc_change_current_drv2
   107                              <1> 
   108                              <1> loc_reset_drv_fd_current_dir:
   109 000078E4 31C0                <1> 	xor	eax, eax
   110 000078E6 88467F              <1>         mov	[esi+LD_CDirLevel], al
   111 000078E9 89F7                <1> 	mov	edi, esi
   112 000078EB 81C780000000        <1> 	add	edi, LD_CurrentDirectory
   113 000078F1 B920000000          <1> 	mov	ecx, 32
   114 000078F6 F3AB                <1> 	rep	stosd
   115                              <1> 
   116                              <1> loc_ccdrv_get_FAT_volume_name_0:
   117 000078F8 8A4603              <1> 	mov	al, [esi+LD_FATType]
   118 000078FB 08C0                <1> 	or	al, al
   119 000078FD 742A                <1> 	jz	short loc_change_current_drv2
   120                              <1> 
   121 000078FF 56                  <1> 	push	esi 
   122 00007900 3C02                <1> 	cmp	al, 2
   123 00007902 7705                <1> 	ja	short loc_ccdrv_get_FAT32_vol_name
   124                              <1>              
   125                              <1> loc_ccdrv_get_FAT2_16_vol_name:
   126 00007904 83C631              <1> 	add	esi, LD_BPB + VolumeLabel
   127 00007907 EB03                <1> 	jmp	short loc_ccdrv_get_FAT_volume_name_1
   128                              <1> 
   129                              <1> loc_ccdrv_get_FAT32_vol_name:
   130 00007909 83C64D              <1> 	add	esi, LD_BPB + FAT32_VolLab
   131                              <1> loc_ccdrv_get_FAT_volume_name_1:
   132 0000790C 53                  <1> 	push	ebx
   133 0000790D 56                  <1> 	push	esi
   134 0000790E E8C7FEFFFF          <1> 	call	get_FAT_volume_name
   135 00007913 5F                  <1> 	pop	edi
   136 00007914 5B                  <1> 	pop	ebx
   137                              <1> 	; BL = 0
   138 00007915 720B                <1> 	jc	short loc_change_current_drv1
   139 00007917 20C0                <1> 	and	al, al
   140 00007919 7407                <1> 	jz	short loc_change_current_drv1
   141                              <1> 
   142                              <1> loc_ccdrv_move_FAT_volume_name:
   143 0000791B B90B000000          <1> 	mov	ecx, 11
   144 00007920 F3A4                <1> 	rep	movsb
   145                              <1> 
   146                              <1> loc_change_current_drv1:
   147 00007922 5E                  <1> 	pop	esi
   148 00007923 EB04                <1> 	jmp	short loc_change_current_drv2
   149                              <1> 
   150                              <1> loc_gmcs_init_drv_hd:
   151 00007925 08E4                <1> 	or	ah, ah
   152 00007927 7404                <1> 	jz	short loc_change_current_drv3
   153                              <1> 	; BL = 0, BH = Logical DOS drive number
   154                              <1> loc_change_current_drv2:
   155 00007929 C6467E00            <1> 	mov	byte [esi+LD_MediaChanged], 0
   156                              <1> loc_change_current_drv3:
   157 0000792D 883D[827D0100]      <1> 	mov	[Current_Drv], bh
   158                              <1> 
   159                              <1> 	;call	restore_current_directory
   160                              <1> 	;retn
   161                              <1> 
   162                              <1> restore_current_directory:
   163                              <1> 	; 26/07/2022 (TRDOS 386 Kernel v2.0.5)
   164                              <1> 	; 11/02/2016
   165                              <1> 	; 15/01/2016 (TRDOS 386 = TRDOS v2.0)
   166                              <1> 	; 25/01/2010
   167                              <1> 	; 12/10/2009
   168                              <1> 	;
   169                              <1> 	; INPUT:
   170                              <1> 	;   ESI = Logical DOS Drive Description Table
   171                              <1> 	;
   172                              <1> 	; OUTPUT:
   173                              <1> 	;   ESI = Logical DOS Drive Description Table
   174                              <1> 	;   EDI = offset Current_Dir_Drv 
   175                              <1> 
   176 00007933 8A4603              <1> 	mov	al, [esi+LD_FATType]
   177 00007936 A2[817D0100]        <1> 	mov	[Current_FATType], al
   178                              <1> 
   179 0000793B 8A26                <1> 	mov	ah, [esi+LD_Name] 
   180 0000793D 8825[837D0100]      <1> 	mov	[Current_Dir_Drv], ah
   181                              <1> 
   182 00007943 20C0                <1> 	and	al, al
   183 00007945 741D                <1> 	jz	short loc_restore_FS_current_directory
   184                              <1> 
   185                              <1> loc_restore_FAT_current_directory:
   186 00007947 8A667F              <1> 	mov	ah, [esi+LD_CDirLevel]
   187 0000794A 8825[807D0100]      <1> 	mov	[Current_Dir_Level], ah
   188 00007950 08E4                <1> 	or	ah, ah
   189 00007952 7415                <1>         jz	short loc_ccdrv_reset_cdir_FAT_12_16_32_fcluster
   190                              <1> 
   191 00007954 0FB6D4              <1> 	movzx	edx, ah
   192 00007957 C0E204              <1> 	shl	dl, 4 ; * 16
   193 0000795A 01F2                <1>         add	edx, esi
   194 0000795C 8B828C000000        <1> 	mov	eax, [edx+LD_CurrentDirectory+12]
   195 00007962 EB29                <1> 	jmp	short loc_ccdrv_reset_cdir_FAT_fcluster
   196                              <1> 
   197                              <1> loc_restore_FS_current_directory:
   198                              <1> 	;call	load_current_FS_directory
   199                              <1> 	;retn
   200                              <1> 	; 26/07/2022
   201 00007964 E9AD4B0000          <1> 	jmp	load_current_FS_directory
   202                              <1> 
   203                              <1> loc_ccdrv_reset_cdir_FAT_12_16_32_fcluster:
   204 00007969 3C03                <1> 	cmp	al, 3
   205 0000796B 7205                <1> 	jb	short loc_ccdrv_reset_cdir_FAT_12_16_fcluster
   206                              <1> loc_ccdrv_reset_cdir_FAT32_fcluster:
   207 0000796D 8B4632              <1> 	mov	eax, [esi+LD_BPB+FAT32_RootFClust]
   208 00007970 EB02                <1> 	jmp	short loc_ccdrv_check_rootdir_sign
   209                              <1> loc_ccdrv_reset_cdir_FAT_12_16_fcluster:   
   210                              <1> 	;xor	al, al  ; xor eax, eax
   211                              <1> 	; 26/07/2022
   212 00007972 31C0                <1> 	xor	eax, eax
   213                              <1> 	;xor	edx, edx
   214                              <1> loc_ccdrv_check_rootdir_sign:
   215 00007974 80BE8000000000      <1> 	cmp	byte [esi+LD_CurrentDirectory], 0
   216 0000797B 7510                <1> 	jne	short loc_ccdrv_reset_cdir_FAT_fcluster
   217                              <1> loc_ccdrv_set_rootdir_FAT_fcluster:
   218 0000797D 89868C000000        <1>         mov     [esi+LD_CurrentDirectory+12], eax
   219 00007983 C78680000000524F4F- <1> 	mov	dword [esi+LD_CurrentDirectory], 'ROOT'
   219 0000798C 54                  <1>
   220                              <1> 
   221                              <1> loc_ccdrv_reset_cdir_FAT_fcluster:
   222 0000798D A3[7C7D0100]        <1> 	mov	[Current_Dir_FCluster], eax
   223                              <1> 
   224 00007992 BF[E0840100]        <1> 	mov	edi, PATH_Array
   225 00007997 89F2                <1> 	mov	edx, esi
   226 00007999 81C680000000        <1> 	add	esi, LD_CurrentDirectory
   227 0000799F B920000000          <1> 	mov	ecx, 32
   228 000079A4 F3A5                <1> 	rep	movsd
   229                              <1> 
   230 000079A6 E8AE2B0000          <1> 	call	change_prompt_dir_string
   231                              <1> 	
   232 000079AB 89D6                <1> 	mov	esi, edx
   233                              <1> 	
   234 000079AD 29C0                <1>         sub	eax, eax
   235                              <1>        ;sub	edx, edx
   236 000079AF BF[837D0100]        <1> 	mov	edi, Current_Dir_Drv
   237                              <1> 
   238 000079B4 A2[9B340100]        <1> 	mov	[Restore_CDIR], al ; 0
   239 000079B9 C3                  <1> 	retn
   240                              <1> 
   241                              <1> dos_prompt:
   242                              <1> 	; 26/07/2022 (TRDOS 386 Kernel v2.0.5)
   243                              <1> 	; 06/05/2016
   244                              <1> 	; 30/01/2016
   245                              <1> 	; 29/01/2016
   246                              <1> 	; 16/01/2016 (TRDOS 386 = TRDOS v2.0)
   247                              <1> 	; 15/09/2011
   248                              <1> 	; 13/09/2009
   249                              <1> 	; 2004-2005
   250                              <1> 
   251                              <1> 	; 06/05/2016
   252 000079BA C705[3C890100]-     <1> 	mov	dword [mainprog_return_addr], return_from_cmd_interpreter
   252 000079C0 [6C7A0000]          <1>
   253                              <1> 
   254                              <1> loc_TRDOS_prompt:
   255 000079C4 BF[827E0100]        <1> 	mov	edi, TextBuffer
   256 000079C9 C6075B              <1> 	mov	byte [edi], "["
   257 000079CC 47                  <1> 	inc	edi
   258 000079CD BE[F6340100]        <1> 	mov	esi, TRDOSPromptLabel
   259                              <1> get_next_prompt_label_char:
   260 000079D2 803E20              <1> 	cmp	byte [esi], 20h
   261 000079D5 7203                <1> 	jb	short pass_prompt_label
   262 000079D7 A4                  <1> 	movsb
   263 000079D8 EBF8                <1> 	jmp	short get_next_prompt_label_char
   264                              <1> pass_prompt_label:
   265 000079DA C6075D              <1> 	mov	byte [edi], "]"
   266 000079DD 47                  <1> 	inc	edi
   267 000079DE C60720              <1> 	mov	byte [edi], 20h
   268 000079E1 47                  <1> 	inc	edi
   269 000079E2 BE[837D0100]        <1> 	mov	esi, Current_Dir_Drv
   270 000079E7 66A5                <1> 	movsw
   271 000079E9 A4                  <1> 	movsb
   272                              <1> loc_prompt_current_directory:
   273 000079EA 803E20              <1> 	cmp	byte [esi], 20h
   274 000079ED 7203                <1> 	jb	short pass_prompt_current_directory
   275 000079EF A4                  <1> 	movsb
   276 000079F0 EBF8                <1> 	jmp	short loc_prompt_current_directory
   277                              <1> pass_prompt_current_directory:
   278 000079F2 C6073E              <1> 	mov	byte [edi], '>'
   279 000079F5 47                  <1> 	inc	edi
   280 000079F6 C60700              <1> 	mov	byte [edi], 0  
   281 000079F9 BE[827E0100]        <1> 	mov	esi, TextBuffer
   282 000079FE E867F3FFFF          <1> 	call	print_msg
   283                              <1> 
   284                              <1> 	;sub	bh, bh ; video page = 0
   285                              <1> 	;call	get_cpos ; get cursor position
   286 00007A03 668B15[DE7C0100]    <1> 	mov	dx, [CURSOR_POSN] ; video page 0
   287 00007A0A 8815[E27D0100]      <1> 	mov	[CursorColumn], dl
   288                              <1> 
   289                              <1> 	; 30/01/2016 (to show cursor on the row, again)
   290                              <1> 	; (Initial color attributes of video page 0 is 0)
   291                              <1> 	; (see: 'StartPMP' in trdos386.s)
   292                              <1> 	;
   293                              <1> 	;mov	edi, 0B8000h ; start of video page 0
   294                              <1> 	;movzx	ecx, dl ; column
   295                              <1> 	;mov	al, 80
   296                              <1> 	;mul	dh
   297                              <1> 	;add	ax, cx
   298                              <1> 	;shl	ax, 1 ; character + attribute
   299                              <1> 	;add	di, ax ; (2*80*row) + (2*column)
   300                              <1> 	;neg	cl
   301                              <1> 	;add	cl, 80
   302                              <1> 	;mov	ax, 700h ;  ah = 7 (color attribute)
   303                              <1> 	;rep	stosw
   304                              <1> 
   305                              <1> loc_rw_char:
   306 00007A10 E8AB000000          <1> 	call	rw_char
   307                              <1> loc_move_command:
   308 00007A15 BE[327E0100]        <1> 	mov	esi, CommandBuffer
   309 00007A1A 89F7                <1> 	mov	edi, esi
   310 00007A1C 31C9                <1> 	xor	ecx, ecx
   311                              <1> first_command_char:
   312 00007A1E AC                  <1> 	lodsb
   313 00007A1F 3C20                <1> 	cmp	al, 20h
   314 00007A21 770C                <1> 	ja	short pass_space_control
   315 00007A23 723F                <1> 	jb	short loc_move_cmd_arguments_ok
   316 00007A25 81FE[817E0100]      <1> 	cmp	esi, CommandBuffer + 79
   317 00007A2B 72F1                <1> 	jb	short first_command_char
   318 00007A2D EB35                <1> 	jmp	short loc_move_cmd_arguments_ok
   319                              <1> 
   320                              <1> 	; 26/07/2022
   321                              <1> pass_space_control:
   322 00007A2F 3C61                <1> 	cmp	al, 61h
   323 00007A31 7206                <1> 	jb	short pass_capitalize
   324 00007A33 3C7A                <1> 	cmp	al, 7Ah
   325 00007A35 7702                <1> 	ja	short pass_capitalize
   326 00007A37 24DF                <1> 	and	al, 0DFh
   327                              <1> pass_capitalize:
   328 00007A39 AA                  <1> 	stosb   
   329 00007A3A FEC1                <1> 	inc     cl
   330 00007A3C 81FE[817E0100]      <1> 	cmp     esi, CommandBuffer + 79
   331                              <1> 	;jb	short next_command_char
   332                              <1> 	; 26/07/2022
   333 00007A42 7320                <1> 	jnb	short loc_move_cmd_arguments_ok
   334                              <1> 
   335                              <1> next_command_char:
   336 00007A44 AC                  <1> 	lodsb
   337 00007A45 3C20                <1> 	cmp	al, 20h
   338 00007A47 77E6                <1> 	ja	short pass_space_control
   339 00007A49 7219                <1> 	jb	short loc_move_cmd_arguments_ok
   340                              <1> 
   341                              <1> loc_1st_cmd_arg: ; 30/01/2016
   342 00007A4B AC                  <1> 	lodsb
   343 00007A4C 3C20                <1> 	cmp	al, 20h
   344 00007A4E 74FB                <1> 	je	short loc_1st_cmd_arg
   345 00007A50 7212                <1> 	jb	short loc_move_cmd_arguments_ok
   346                              <1> 
   347 00007A52 C60700              <1>         mov     byte [edi], 0
   348 00007A55 47                  <1> 	inc	edi
   349                              <1> 
   350                              <1> loc_move_cmd_arguments:
   351 00007A56 AA                  <1> 	stosb
   352 00007A57 81FE[817E0100]      <1> 	cmp	esi, CommandBuffer + 79
   353 00007A5D 7305                <1> 	jnb	short loc_move_cmd_arguments_ok
   354 00007A5F AC                  <1>         lodsb
   355 00007A60 3C20                <1> 	cmp	al, 20h
   356 00007A62 73F2                <1> 	jnb	short loc_move_cmd_arguments
   357                              <1> 	; 26/07/2022
   358                              <1> 	;jmp	short loc_move_cmd_arguments_ok
   359                              <1> 
   360                              <1> ; 26/07/2022
   361                              <1> ;pass_space_control:
   362                              <1> ;	cmp	al, 61h
   363                              <1> ;	jb	short pass_capitalize
   364                              <1> ;	cmp	al, 7Ah
   365                              <1> ;	ja	short pass_capitalize
   366                              <1> ;	and	al, 0DFh
   367                              <1> ;pass_capitalize:
   368                              <1> ;	stosb
   369                              <1> ;	inc     cl
   370                              <1> ;	cmp     esi, CommandBuffer + 79
   371                              <1> ;	jb      short next_command_char
   372                              <1> 
   373                              <1> loc_move_cmd_arguments_ok:
   374 00007A64 C60700              <1>         mov     byte [edi], 0
   375                              <1> 
   376                              <1> call_command_interpreter:
   377 00007A67 E8FD070000          <1> 	call    command_interpreter
   378                              <1> 
   379                              <1> return_from_cmd_interpreter:
   380 00007A6C B950000000          <1>         mov	ecx, 80
   381                              <1> 	;mov	cx, 80
   382 00007A71 BF[327E0100]        <1> 	mov	edi, CommandBuffer
   383 00007A76 30C0                <1> 	xor	al, al
   384 00007A78 F3AA                <1> 	rep	stosb
   385                              <1> 	;cmp	byte [Program_Exit], 0
   386                              <1> 	;ja	short loc_terminate_trdos
   387                              <1> 
   388                              <1> 	; 16/01/2016
   389 00007A7A 803D[DE670000]03    <1> 	cmp	byte [CRT_MODE], 3 ; 80*25 color
   390 00007A81 7419                <1> 	je	short pass_set_txt_mode
   391                              <1> 
   392 00007A83 E8B9A0FFFF          <1> 	call	set_txt_mode ; set vide mode to 03h
   393                              <1> 	; 07/01/2017
   394 00007A88 30C0                <1> 	xor	al, al
   395                              <1> 
   396                              <1> loc_check_active_page:
   397                              <1> 	;xor	al, al
   398 00007A8A 3805[EE7C0100]      <1> 	cmp	[ACTIVE_PAGE], al ; 0
   399                              <1>         ;je	loc_TRDOS_prompt
   400                              <1> 	; 26/07/2022
   401 00007A90 7405                <1> 	je	short loc_prompt_again
   402                              <1> 
   403                              <1> 	; AL = 0 = video page 0
   404 00007A92 E8D2A4FFFF          <1> 	call	set_active_page
   405                              <1> loc_prompt_again: ; 26/07/2022
   406 00007A97 E928FFFFFF          <1>         jmp     loc_TRDOS_prompt ; infinitive loop
   407                              <1> 
   408                              <1> pass_set_txt_mode:
   409 00007A9C BE[273F0100]        <1> 	mov	esi, nextline
   410 00007AA1 E8C4F2FFFF          <1> 	call	print_msg
   411 00007AA6 EBE2                <1> 	jmp     short loc_check_active_page
   412                              <1> 
   413                              <1> ;rw_char:
   414                              <1> 	; 26/07/2022 (TRDOS 386 Kernel v2.0.5)
   415                              <1> loc_arrow:
   416 00007AA8 80FC4B              <1> 	cmp	ah, 4Bh
   417 00007AAB 7426                <1> 	je	short loc_back
   418 00007AAD 80FC53              <1> 	cmp	ah, 53h
   419 00007AB0 7421                <1> 	je      short loc_back
   420 00007AB2 80FC4D              <1> 	cmp	ah, 4Dh
   421 00007AB5 7509                <1> 	jne	short readnextchar
   422 00007AB7 80FA4F              <1> 	cmp	dl, 79
   423 00007ABA 7304                <1> 	jnb	short readnextchar
   424 00007ABC FEC2                <1> 	inc	dl
   425 00007ABE EB1D                <1> 	jmp	short set_cursor_pos
   426                              <1> 
   427                              <1> rw_char: 
   428                              <1> 	; 26/07/2022 (TRDOS 386 Kernel v2.0.5)
   429                              <1> 	; 13/05/2016
   430                              <1> 	; 30/01/2016
   431                              <1> 	; 29/01/2016
   432                              <1> 	; 17/01/2016 (TRDOS 386 = TRDOS v2.0)
   433                              <1> 	; 2004-2005
   434                              <1> 
   435                              <1> 	; DH = cursor row, DL = cursor column
   436                              <1> 	; BH = 0 = video page number (active page)
   437                              <1> 
   438                              <1> 	;xor	bh, bh ; 0 = video page 0
   439                              <1> 
   440                              <1> readnextchar:
   441 00007AC0 30E4                <1> 	xor     ah, ah
   442 00007AC2 E85594FFFF          <1> 	call	int16h
   443 00007AC7 20C0                <1> 	and	al, al
   444 00007AC9 74DD                <1> 	jz	short loc_arrow
   445 00007ACB 3CE0                <1> 	cmp	al, 0E0h
   446 00007ACD 74D9                <1> 	je	short loc_arrow
   447 00007ACF 3C08                <1> 	cmp	al, 08h
   448 00007AD1 752A                <1> 	jne	short char_return
   449                              <1> loc_back:
   450 00007AD3 3A15[E27D0100]      <1> 	cmp	dl, [CursorColumn]
   451 00007AD9 76E5                <1> 	jna     short readnextchar
   452                              <1> prev_column:
   453 00007ADB FECA                <1> 	dec	dl
   454                              <1> set_cursor_pos:
   455                              <1> 	;push	dx
   456 00007ADD 52                  <1> 	push	edx ; 29/12/2017
   457                              <1> 	;xor	bh, bh ; 0 = video page 0
   458                              <1> 	; DH = Row, DL = Column
   459 00007ADE E84AA8FFFF          <1> 	call	_set_cpos ; 17/01/2016
   460 00007AE3 5A                  <1>         pop	edx ; 29/12/2017
   461                              <1> 	;pop	dx
   462                              <1> 	;movzx	ebx, dl
   463 00007AE4 88D3                <1> 	mov	bl, dl
   464 00007AE6 2A1D[E27D0100]      <1> 	sub	bl, [CursorColumn]
   465 00007AEC B020                <1> 	mov	al, 20h
   466 00007AEE 8883[327E0100]      <1> 	mov	[CommandBuffer+ebx], al
   467                              <1> 	;sub	bh, bh ; video page 0
   468                              <1> 	;mov	cx, 1
   469 00007AF4 B307                <1> 	mov	bl, 7 ; color attribute
   470                              <1> 	; bh = 0 ; 26/07/2022
   471 00007AF6 E819A7FFFF          <1> 	call	_write_c_current ; 17/01/2016
   472                              <1> 	;mov	dx, [CURSOR_POSN]
   473 00007AFB EBC3                <1> 	jmp	short readnextchar
   474                              <1> 
   475                              <1> 	; 26/07/2022
   476                              <1> ;loc_arrow:    
   477                              <1> ;	cmp	ah, 4Bh
   478                              <1> ;	je	short loc_back
   479                              <1> ;	cmp	ah, 53h
   480                              <1> ;	je      short loc_back
   481                              <1> ;	cmp	ah, 4Dh
   482                              <1> ;	jne	short readnextchar
   483                              <1> ;	cmp	dl, 79
   484                              <1> ;	jnb	short readnextchar
   485                              <1> ;	inc	dl
   486                              <1> ;	jmp	short set_cursor_pos
   487                              <1> 
   488                              <1> char_return:
   489 00007AFD 0FB6DA              <1> 	movzx	ebx, dl
   490 00007B00 2A1D[E27D0100]      <1> 	sub	bl, [CursorColumn]
   491 00007B06 3C20                <1> 	cmp	al, 20h
   492 00007B08 721D                <1> 	jb	short loc_escape
   493 00007B0A 8883[327E0100]      <1> 	mov	[CommandBuffer+ebx], al
   494 00007B10 80FA4F              <1> 	cmp	dl, 79
   495 00007B13 73AB                <1> 	jnb	short readnextchar
   496 00007B15 66BB0700            <1> 	mov	bx, 7 ; color attribute
   497 00007B19 E877A7FFFF          <1> 	call	_write_tty
   498 00007B1E 668B15[DE7C0100]    <1> 	mov	dx, [CURSOR_POSN] ; video page 0
   499 00007B25 EB99                <1>         jmp	short readnextchar ; 26/07/2022
   500                              <1> 
   501                              <1> loc_escape:
   502 00007B27 3C1B                <1> 	cmp	al, 1Bh
   503 00007B29 7414                <1> 	je	short rw_char_retn
   504                              <1> 	;
   505 00007B2B 3C0D                <1> 	cmp	al, 0Dh ; CR
   506 00007B2D 7591                <1>         jne	short readnextchar ; 26/07/2022
   507                              <1> 
   508                              <1> 	; 13/05/2016
   509 00007B2F 66BB0700            <1> 	mov	bx, 7 ; attribute/color (bl)
   510                              <1> 		      ; video page 0 (bh=0)
   511 00007B33 E85DA7FFFF          <1> 	call	_write_tty
   512                              <1> 	;mov	bx, 7  ; attribute/color
   513                              <1> 		      ; video page 0 (bh=0)
   514 00007B38 B00A                <1> 	mov	al, 0Ah ; LF
   515 00007B3A E856A7FFFF          <1> 	call	_write_tty
   516                              <1> rw_char_retn:
   517 00007B3F C3                  <1> 	retn
   518                              <1> 
   519                              <1> show_date:
   520                              <1> 	; 26/07/2022 (TRDOS 386 Kernel v2.0.5)
   521                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   522                              <1>         ; 2004-2005
   523                              <1> 
   524                              <1> 	;mov	ah, 04h
   525                              <1> 	;call	int1Ah
   526 00007B40 E831E8FFFF          <1> 	call	RTC_40	; GET RTC DATE
   527                              <1> 
   528 00007B45 88D0                <1> 	mov	al, dl
   529 00007B47 E8C393FFFF          <1>   	call	bcd_to_ascii
   530 00007B4C 66A3[E2350100]      <1> 	mov	[Day], ax
   531                              <1> 
   532 00007B52 88F0                <1> 	mov	al, dh
   533 00007B54 E8B693FFFF          <1>   	call	bcd_to_ascii
   534 00007B59 66A3[E5350100]      <1> 	mov	[Month], ax
   535                              <1> 
   536 00007B5F 88E8                <1> 	mov	al, ch
   537 00007B61 E8A993FFFF          <1>   	call	bcd_to_ascii
   538 00007B66 66A3[E8350100]      <1> 	mov	[Century], ax
   539                              <1> 
   540 00007B6C 88C8                <1> 	mov	al, cl
   541 00007B6E E89C93FFFF          <1>   	call	bcd_to_ascii
   542 00007B73 66A3[EA350100]      <1> 	mov	[Year], ax
   543                              <1> 
   544 00007B79 BE[D2350100]        <1> 	mov	esi, Msg_Show_Date
   545                              <1> 	;call	print_msg
   546                              <1> 	;retn
   547                              <1> 	; 26/07/2022
   548 00007B7E E9E7F1FFFF          <1> 	jmp	print_msg
   549                              <1> 
   550                              <1> set_date:
   551                              <1> 	; 26/07/2022 (TRDOS 386 Kernel v2.0.5)
   552                              <1> 	; 13/05/2016
   553                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   554                              <1>         ; 2004-2005
   555                              <1> 
   556 00007B83 BE[B6350100]        <1> 	mov	esi, Msg_Enter_Date
   557 00007B88 E8DDF1FFFF          <1> 	call	print_msg
   558                              <1> 
   559                              <1> loc_enter_day_1:
   560 00007B8D 30E4                <1> 	xor     ah, ah
   561 00007B8F E88893FFFF          <1> 	call	int16h
   562                              <1> 	; AL = ASCII Code of the Character
   563 00007B94 3C0D                <1> 	cmp	al, 13
   564                              <1> 	;je	loc_set_date_retn
   565                              <1> 	; 26/07/2022
   566 00007B96 7404                <1> 	je	short set_date_0
   567 00007B98 3C1B                <1> 	cmp	al, 27
   568                              <1> 	;je	loc_set_date_retn
   569                              <1> 	; 26/07/2022
   570 00007B9A 7511                <1> 	jne	short set_date_1
   571                              <1> 
   572                              <1> set_date_0:
   573                              <1> ;loc_set_date_retn:
   574 00007B9C BE[273F0100]        <1> 	mov	esi, nextline
   575                              <1> 	;call	print_msg
   576                              <1> 	;retn
   577                              <1> 	; 26/07/2022
   578 00007BA1 E9C4F1FFFF          <1> 	jmp	print_msg
   579                              <1> 
   580                              <1> 	; 26/07/2022
   581                              <1> loc_set_date_stc_0:
   582                              <1> 	;xor	bh, bh ; video page 0
   583 00007BA6 E8D4A7FFFF          <1> 	call	beeper ; BEEP !
   584 00007BAB EBE0                <1> 	jmp	short loc_enter_day_1
   585                              <1> 
   586                              <1> 	; 26/07/2022
   587                              <1> set_date_1:
   588 00007BAD A2[E2350100]        <1> 	mov	[Day], al
   589 00007BB2 3C30                <1> 	cmp	al, '0'
   590 00007BB4 72F0                <1> 	jb	short loc_set_date_stc_0
   591 00007BB6 3C33                <1> 	cmp	al, '3'
   592 00007BB8 77EC                <1> 	ja	short loc_set_date_stc_0
   593                              <1> 	; 13/05/2016
   594                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   595                              <1> 		      ; video page 0 (bh)
   596 00007BBA B307                <1> 	mov	bl, 7
   597 00007BBC E8D4A6FFFF          <1> 	call	_write_tty
   598                              <1> loc_enter_day_2:
   599 00007BC1 30E4                <1> 	xor     ah, ah
   600 00007BC3 E85493FFFF          <1> 	call	int16h
   601                              <1> 	; AL = ASCII Code of the Character
   602 00007BC8 3C1B                <1> 	cmp	al, 27
   603                              <1>         ;je	loc_set_date_retn
   604                              <1> 	; 26/07/2022
   605 00007BCA 74D0                <1> 	je	short set_date_0
   606 00007BCC A2[E3350100]        <1> 	mov	[Day+1], al
   607 00007BD1 3C30                <1> 	cmp	al, '0'
   608 00007BD3 7211                <1>         jb      short loc_set_date_stc_1
   609 00007BD5 3C39                <1> 	cmp	al, '9'
   610 00007BD7 770D                <1>         ja      short loc_set_date_stc_1
   611 00007BD9 803D[E2350100]33    <1> 	cmp	byte [Day], '3'
   612 00007BE0 7219                <1> 	jb	short pass_set_day_31
   613 00007BE2 3C31                <1> 	cmp	al, '1'
   614                              <1>         ;ja	loc_set_date_stc_1
   615                              <1> 	; 26/07/2022
   616 00007BE4 7615                <1> 	jna	short pass_set_day_31
   617                              <1> 
   618                              <1> 	; 26/07/2022
   619                              <1> loc_set_date_stc_1:
   620 00007BE6 E8E4010000          <1> 	call	check_for_backspace
   621 00007BEB 7407                <1> 	je	short loc_set_date_bs_1
   622                              <1> 	;xor	bh, bh ; video page 0
   623 00007BED E88DA7FFFF          <1> 	call	beeper ; BEEP !
   624 00007BF2 EBCD                <1> 	jmp	short loc_enter_day_2
   625                              <1> loc_set_date_bs_1:
   626 00007BF4 E8C4010000          <1> 	call	write_backspace
   627 00007BF9 EB92                <1> 	jmp     short loc_enter_day_1
   628                              <1> 
   629                              <1> pass_set_day_31:
   630                              <1> 	; 13/05/2016
   631                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   632                              <1> 		      ; video page 0 (bh)
   633 00007BFB B307                <1> 	mov	bl, 7
   634 00007BFD E893A6FFFF          <1> 	call	_write_tty
   635                              <1> loc_enter_separator_1:
   636 00007C02 28E4                <1> 	sub     ah, ah ; 0
   637 00007C04 E81393FFFF          <1> 	call	int16h
   638                              <1> 	; AL = ASCII Code of the Character
   639 00007C09 3C1B                <1> 	cmp	al, 27
   640                              <1>         ;je	loc_set_date_retn
   641                              <1> 	; 26/07/2022
   642 00007C0B 748F                <1> 	je	short set_date_0
   643 00007C0D 3C2D                <1> 	cmp	al, '-'
   644 00007C0F 7443                <1> 	je	short pass_set_date_separator_1
   645 00007C11 3C2F                <1> 	cmp	al, '/'
   646                              <1> 	;jne	loc_set_date_stc_2
   647                              <1> 	; 26/07/2022
   648 00007C13 743F                <1> 	je	short pass_set_date_separator_1
   649                              <1> 
   650                              <1> 	; 26/07/2022
   651                              <1> loc_set_date_stc_2:
   652 00007C15 E8B5010000          <1> 	call	check_for_backspace
   653 00007C1A 7407                <1> 	je	short loc_set_date_bs_2
   654                              <1> 	;xor	bh, bh ; video page 0
   655 00007C1C E85EA7FFFF          <1> 	call	beeper ; BEEP !
   656 00007C21 EBDF                <1> 	jmp	short loc_enter_separator_1
   657                              <1> loc_set_date_bs_2:
   658 00007C23 E895010000          <1> 	call	write_backspace
   659 00007C28 EB97                <1> 	jmp	short loc_enter_day_2
   660                              <1> 
   661                              <1> 	; 26/07/2022
   662                              <1> loc_set_date_stc_3:
   663 00007C2A E8A0010000          <1> 	call	check_for_backspace
   664 00007C2F 7407                <1> 	je	short loc_set_date_bs_3
   665                              <1> 	;xor	bh, bh ; video page 0
   666 00007C31 E849A7FFFF          <1> 	call	beeper ; BEEP !
   667 00007C36 EB23                <1> 	jmp	short loc_enter_month_1
   668                              <1> loc_set_date_bs_3:
   669 00007C38 E880010000          <1> 	call	write_backspace
   670 00007C3D EBC3                <1> 	jmp	short loc_enter_separator_1
   671                              <1> 
   672                              <1> 	; 26/07/2022
   673                              <1> loc_set_date_stc_4:
   674 00007C3F E88B010000          <1> 	call	check_for_backspace
   675 00007C44 7407                <1> 	je	short loc_set_date_bs_4
   676                              <1> 	;xor	bh, bh ; video page 0
   677 00007C46 E834A7FFFF          <1> 	call	beeper ; BEEP !
   678 00007C4B EB2D                <1> 	jmp	short loc_enter_month_2
   679                              <1> loc_set_date_bs_4:
   680 00007C4D E86B010000          <1> 	call	write_backspace
   681 00007C52 EB07                <1> 	jmp	short loc_enter_month_1
   682                              <1> 	
   683                              <1> pass_set_date_separator_1:
   684                              <1> 	; 13/05/2016
   685                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   686                              <1> 		      ; video page 0 (bh)
   687 00007C54 B307                <1> 	mov	bl, 7	
   688 00007C56 E83AA6FFFF          <1> 	call	_write_tty
   689                              <1> loc_enter_month_1:
   690 00007C5B 30E4                <1> 	xor     ah, ah ; 0
   691 00007C5D E8BA92FFFF          <1> 	call	int16h
   692                              <1> 	; AL = ASCII Code of the Character
   693 00007C62 3C1B                <1> 	cmp	al, 27
   694                              <1>         ;je	loc_set_date_retn
   695                              <1> 	; 26/07/2022
   696                              <1> 	;je	short loc_set_date_ok
   697                              <1> 	; 07/08/2022
   698 00007C64 741F                <1> 	je	short jmp_loc_set_date_ok
   699 00007C66 A2[E5350100]        <1> 	mov	[Month], al
   700 00007C6B 3C30                <1> 	cmp	al, '0'
   701 00007C6D 72BB                <1>         jb      short loc_set_date_stc_3
   702 00007C6F 3C31                <1> 	cmp	al, '1'
   703 00007C71 77B7                <1>         ja	short loc_set_date_stc_3
   704                              <1> 	; 13/05/2016
   705                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   706                              <1> 		      ; video page 0 (bh)
   707 00007C73 B307                <1> 	mov	bl, 7
   708 00007C75 E81BA6FFFF          <1> 	call	_write_tty
   709                              <1> loc_enter_month_2:
   710 00007C7A 30E4                <1> 	xor     ah, ah
   711 00007C7C E89B92FFFF          <1> 	call	int16h
   712                              <1> 	; AL = ASCII Code of the Character
   713 00007C81 3C1B                <1> 	cmp	al, 27
   714                              <1>         ;;je	loc_set_date_retn
   715                              <1> 	; 26/07/2022
   716                              <1> 	;je	short loc_set_date_ok
   717                              <1> 	; 07/08/2022
   718 00007C83 7505                <1> 	jne	short loc_enter_month_3
   719                              <1> jmp_loc_set_date_ok:
   720 00007C85 E996000000          <1> 	jmp	loc_set_date_ok
   721                              <1> loc_enter_month_3:
   722 00007C8A A2[E6350100]        <1> 	mov	[Month+1], al
   723 00007C8F 3C30                <1> 	cmp	al, '0'
   724 00007C91 72AC                <1>         jb	short loc_set_date_stc_4
   725 00007C93 3C39                <1> 	cmp	al, '9'
   726 00007C95 77A8                <1>         ja	short loc_set_date_stc_4
   727 00007C97 803D[E5350100]31    <1> 	cmp	byte [Month], '1'
   728 00007C9E 7204                <1> 	jb	short pass_set_month_12
   729 00007CA0 3C32                <1> 	cmp	al, '2'
   730 00007CA2 779B                <1>         ja	short loc_set_date_stc_4
   731                              <1> pass_set_month_12:
   732                              <1> 	; 13/05/2016
   733                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   734                              <1> 		      ; video page 0 (bh)
   735 00007CA4 B307                <1> 	mov	bl, 7	
   736 00007CA6 E8EAA5FFFF          <1> 	call	_write_tty
   737                              <1> loc_enter_separator_2:
   738 00007CAB 28E4                <1> 	sub     ah, ah
   739 00007CAD E86A92FFFF          <1> 	call	int16h
   740                              <1> 	; AL = ASCII Code of the Character
   741 00007CB2 3C1B                <1> 	cmp	al, 27
   742                              <1>         ;je	loc_set_date_retn
   743                              <1> 	; 26/07/2022
   744 00007CB4 746A                <1> 	je	short loc_set_date_ok
   745 00007CB6 3C2D                <1> 	cmp	al, '-'
   746 00007CB8 7404                <1> 	je	short pass_set_date_separator_2
   747 00007CBA 3C2F                <1> 	cmp	al, '/'
   748 00007CBC 756C                <1>         jne	short loc_set_date_stc_5
   749                              <1> pass_set_date_separator_2:
   750                              <1> 	; 13/05/2016
   751                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   752                              <1> 		      ; video page 0 (bh)
   753 00007CBE B307                <1> 	mov	bl, 7
   754 00007CC0 E8D0A5FFFF          <1> 	call	_write_tty
   755                              <1> loc_enter_year_1:
   756 00007CC5 30E4                <1> 	xor    ah, ah
   757 00007CC7 E85092FFFF          <1> 	call	int16h
   758                              <1> 	; AL = ASCII Code of the Character
   759 00007CCC 3C1B                <1> 	cmp	al, 27
   760                              <1>         ;je	loc_set_date_retn
   761                              <1> 	; 26/07/2022
   762 00007CCE 7450                <1> 	je	short loc_set_date_ok
   763 00007CD0 A2[EA350100]        <1> 	mov	[Year], al
   764 00007CD5 3C30                <1> 	cmp	al, '0'
   765 00007CD7 726C                <1>         jb	short loc_set_date_stc_6
   766 00007CD9 3C39                <1> 	cmp	al, '9'
   767 00007CDB 7768                <1>         ja	short loc_set_date_stc_6
   768                              <1> 	; 13/05/2016
   769                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   770                              <1> 		      ; video page 0 (bh)
   771 00007CDD B307                <1> 	mov	bl, 7
   772 00007CDF E8B1A5FFFF          <1> 	call	_write_tty
   773                              <1> loc_enter_year_2:
   774 00007CE4 30E4                <1> 	xor	ah, ah
   775 00007CE6 E83192FFFF          <1> 	call	int16h
   776                              <1> 	; AL = ASCII Code of the Character
   777 00007CEB 3C1B                <1> 	cmp	al, 27
   778                              <1> 	;je	short loc_set_date_retn
   779                              <1> 	; 26/07/2022
   780 00007CED 7431                <1> 	je	short loc_set_date_ok
   781 00007CEF A2[EB350100]        <1> 	mov	byte [Year+1], al
   782 00007CF4 3C30                <1> 	cmp	al, '0'
   783 00007CF6 7268                <1>         jb 	short loc_set_date_stc_7
   784 00007CF8 3C39                <1> 	cmp	al, '9'
   785 00007CFA 7764                <1>         ja	short loc_set_date_stc_7
   786                              <1> 	; 13/05/2016
   787                              <1> 	;mov	bx, 7 ; attribute/color (bl)
   788                              <1> 		      ; video page 0 (bh)
   789 00007CFC B307                <1> 	mov	bl, 7
   790 00007CFE E892A5FFFF          <1> 	call	_write_tty
   791                              <1> loc_set_date_get_lchar_again:
   792 00007D03 28E4                <1> 	sub	ah, ah ; 0
   793 00007D05 E81292FFFF          <1> 	call	int16h
   794                              <1> 	; AL = ASCII Code of the Character
   795 00007D0A 3C0D                <1> 	cmp	al, 13 ; ENTER key
   796 00007D0C 746D                <1> 	je	short loc_set_date_progress
   797 00007D0E 3C1B                <1> 	cmp	al, 27 ; ESC key
   798                              <1> 	;je	short loc_set_date_retn
   799                              <1> 	; 26/07/2022
   800 00007D10 740E                <1> 	je	short loc_set_date_ok
   801                              <1> 	;
   802 00007D12 E8B8000000          <1> 	call	check_for_backspace
   803 00007D17 75EA                <1> 	jne	short loc_set_date_get_lchar_again
   804                              <1> 
   805                              <1> loc_set_date_bs_8:
   806 00007D19 E89F000000          <1> 	call	write_backspace
   807 00007D1E EBC4                <1> 	jmp	short loc_enter_year_2
   808                              <1> 
   809                              <1> loc_set_date_ok:
   810                              <1> ;loc_set_date_retn:
   811 00007D20 BE[273F0100]        <1> 	mov	esi, nextline
   812                              <1> 	;call	print_msg
   813                              <1> 	;retn
   814                              <1> 	; 26/07/2022
   815 00007D25 E940F0FFFF          <1> 	jmp	print_msg
   816                              <1> 
   817                              <1> 	; 26/07/2022
   818                              <1> ;loc_set_date_stc_0:
   819                              <1> ;	;xor	bh, bh ; video page 0
   820                              <1> ;	call	beeper ; BEEP !
   821                              <1> ;	jmp	loc_enter_day_1
   822                              <1> ;loc_set_date_stc_1:
   823                              <1> ;	call	check_for_backspace
   824                              <1> ;	je	short loc_set_date_bs_1
   825                              <1> ;	;xor	bh, bh ; video page 0
   826                              <1> ;	call	beeper ; BEEP !
   827                              <1> ;	jmp	loc_enter_day_2
   828                              <1> ;loc_set_date_bs_1:
   829                              <1> ;	call	write_backspace
   830                              <1> ;	jmp     loc_enter_day_1
   831                              <1> ;loc_set_date_stc_2:
   832                              <1> ;	call	check_for_backspace
   833                              <1> ;	je	short loc_set_date_bs_2
   834                              <1> ;	;xor	bh, bh ; video page 0
   835                              <1> ;	call	beeper ; BEEP !
   836                              <1> ;	jmp	loc_enter_separator_1
   837                              <1> ;loc_set_date_bs_2:
   838                              <1> ;	call	write_backspace
   839                              <1> ;	jmp	loc_enter_day_2
   840                              <1> ;loc_set_date_stc_3:
   841                              <1> ;	call	check_for_backspace
   842                              <1> ;	je	short loc_set_date_bs_3
   843                              <1> ;	;xor	bh, bh ; video page 0
   844                              <1> ;	call	beeper ; BEEP !
   845                              <1> ;	jmp	loc_enter_month_1
   846                              <1> ;loc_set_date_bs_3:
   847                              <1> ;	call	write_backspace
   848                              <1> ;	jmp	loc_enter_separator_1
   849                              <1> ;loc_set_date_stc_4:
   850                              <1> ;	call	check_for_backspace
   851                              <1> ;	je	short loc_set_date_bs_4
   852                              <1> ;	;xor	bh, bh ; video page 0
   853                              <1> ;	call	beeper ; BEEP !
   854                              <1> ;	jmp	loc_enter_month_2
   855                              <1> ;loc_set_date_bs_4:
   856                              <1> ;	call	write_backspace
   857                              <1> ;	jmp	loc_enter_month_1
   858                              <1> 
   859                              <1> 	; 26/07/2022
   860                              <1> loc_set_date_stc_5:
   861 00007D2A E8A0000000          <1> 	call	check_for_backspace
   862 00007D2F 740A                <1> 	je	short loc_set_date_bs_5
   863                              <1> 	;xor	bh, bh ; video page 0
   864 00007D31 E849A6FFFF          <1> 	call	beeper ; BEEP !
   865 00007D36 E970FFFFFF          <1> 	jmp	loc_enter_separator_2
   866                              <1> loc_set_date_bs_5:
   867 00007D3B E87D000000          <1> 	call	write_backspace
   868 00007D40 E935FFFFFF          <1> 	jmp	loc_enter_month_2
   869                              <1> loc_set_date_stc_6:
   870 00007D45 E885000000          <1> 	call	check_for_backspace
   871 00007D4A 740A                <1>         je      short loc_set_date_bs_6
   872                              <1> 	;xor	bh, bh ; video page 0
   873 00007D4C E82EA6FFFF          <1> 	call	beeper ; BEEP !
   874 00007D51 E96FFFFFFF          <1> 	jmp	loc_enter_year_1
   875                              <1> loc_set_date_bs_6:
   876 00007D56 E862000000          <1> 	call	write_backspace
   877 00007D5B E94BFFFFFF          <1> 	jmp	loc_enter_separator_2
   878                              <1> loc_set_date_stc_7:
   879 00007D60 E86A000000          <1> 	call	check_for_backspace
   880 00007D65 740A                <1> 	je	short loc_set_date_bs_7
   881                              <1> 	;xor	bh, bh ; video page 0
   882 00007D67 E813A6FFFF          <1> 	call	beeper ; BEEP !
   883 00007D6C E973FFFFFF          <1> 	jmp	loc_enter_year_2
   884                              <1> loc_set_date_bs_7:
   885 00007D71 E847000000          <1> 	call	write_backspace
   886 00007D76 E94AFFFFFF          <1> 	jmp	loc_enter_year_1
   887                              <1> 
   888                              <1> loc_set_date_progress:
   889                              <1> 	; Get Current Date
   890                              <1> 	;mov	ah, 04h
   891                              <1> 	;call	int1Ah
   892 00007D7B E8F6E5FFFF          <1> 	call	RTC_40	; GET RTC DATE
   893                              <1> 	; CH = century (in BCD)
   894                              <1> 
   895 00007D80 66A1[EA350100]      <1> 	mov	ax, [Year]
   896 00007D86 662D3030            <1> 	sub	ax, '00'
   897 00007D8A C0E004              <1> 	shl	al, 4 ; * 16
   898 00007D8D 88C1                <1> 	mov	cl, al
   899 00007D8F 00E1                <1> 	add	cl, ah
   900 00007D91 66A1[E5350100]      <1> 	mov	ax, [Month]
   901 00007D97 662D3030            <1> 	sub	ax, '00'
   902 00007D9B C0E004              <1> 	shl	al, 4 ; * 16
   903 00007D9E 88C6                <1> 	mov	dh, al
   904 00007DA0 00E6                <1> 	add	dh, ah
   905 00007DA2 66A1[E2350100]      <1> 	mov	ax, [Day]
   906 00007DA8 662D3030            <1> 	sub	ax, '00'
   907 00007DAC C0E004              <1> 	shl	al, 4 ; * 16
   908 00007DAF 88C2                <1> 	mov	dl, al
   909 00007DB1 00E2                <1> 	add	dl, ah
   910                              <1> 
   911                              <1> 	;mov	ah, 05h
   912                              <1> 	;call	int1Ah
   913 00007DB3 E8E4E5FFFF          <1> 	call	RTC_50	; SET RTC DATE
   914                              <1> 
   915                              <1> ;loc_set_date_retn:
   916                              <1> ;	mov	esi, nextline
   917                              <1> ;	;call	print_msg
   918                              <1> ;	;retn
   919                              <1> ;	; 26/07/2022
   920                              <1> ;	jmp	print_msg
   921                              <1> 
   922                              <1> 	; 26/07/2022
   923 00007DB8 E963FFFFFF          <1> 	jmp	loc_set_date_ok 
   924                              <1> 
   925                              <1> write_backspace:
   926                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   927 00007DBD B008                <1> 	mov	al, 08h ; BACKSPACE
   928                              <1> 	; 13/05/2016
   929 00007DBF 66BB0700            <1> 	mov	bx, 7 ; bl = attribute/color
   930                              <1> 		      ; bh = video page = 0
   931 00007DC3 E8CDA4FFFF          <1> 	call	_write_tty
   932 00007DC8 B020                <1> 	mov	al, 20h ; BLANK/SPACE char 
   933                              <1> 	;mov	bx, 7 ; attribute/color
   934                              <1> 	;call	_write_c_current
   935                              <1> 	;retn
   936 00007DCA E945A4FFFF          <1> 	jmp	_write_c_current
   937                              <1> 
   938                              <1> check_for_backspace:
   939                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   940 00007DCF 663D080E            <1> 	cmp	ax, 0E08h
   941 00007DD3 7410                <1> 	je	short cfbs_retn
   942 00007DD5 663DE04B            <1> 	cmp	ax, 4BE0h
   943 00007DD9 740A                <1> 	je	short cfbs_retn
   944 00007DDB 663D004B            <1> 	cmp	ax, 4B00h
   945 00007DDF 7404                <1> 	je	short cfbs_retn
   946 00007DE1 663DE053            <1> 	cmp	ax, 53E0h
   947                              <1> cfbs_retn:
   948 00007DE5 C3                  <1> 	retn
   949                              <1> 
   950                              <1> show_time:
   951                              <1> 	; 26/07/2022 (TRDOS 386 Kernel v2.0.5)
   952                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   953                              <1>         ; 2004-2005
   954                              <1> 
   955                              <1> 	;mov	ah, 02h
   956                              <1> 	;call	int1Ah
   957 00007DE6 E820E5FFFF          <1> 	call	RTC_20	; GET RTC TIME
   958                              <1> 	
   959 00007DEB 88E8                <1> 	mov	al, ch
   960 00007DED E81D91FFFF          <1> 	call	bcd_to_ascii
   961 00007DF2 66A3[10360100]      <1> 	mov	[Hour], ax
   962                              <1> 
   963 00007DF8 88C8                <1> 	mov	al, cl
   964 00007DFA E81091FFFF          <1> 	call	bcd_to_ascii
   965 00007DFF 66A3[13360100]      <1> 	mov	[Minute], ax
   966                              <1> 
   967 00007E05 88F0                <1> 	mov	al, dh
   968 00007E07 E80391FFFF          <1> 	call	bcd_to_ascii
   969 00007E0C 66A3[16360100]      <1> 	mov	[Second], ax
   970                              <1> 
   971 00007E12 BE[00360100]        <1> 	mov	esi, Msg_Show_Time
   972                              <1> 	;call	print_msg
   973                              <1> 	;retn
   974                              <1> 	; 26/07/2022
   975 00007E17 E94EEFFFFF          <1> 	jmp	print_msg
   976                              <1> 
   977                              <1> set_time:
   978                              <1> 	; 26/07/2022 (TRDOS 386 Kernel v2.0.5)
   979                              <1> 	; 13/05/2016
   980                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
   981                              <1>         ; 2004-2005
   982                              <1> 
   983 00007E1C BE[EF350100]        <1> 	mov 	esi, Msg_Enter_Time
   984 00007E21 E844EFFFFF          <1> 	call	print_msg
   985                              <1> 
   986                              <1> loc_enter_hour_1:
   987 00007E26 30E4                <1> 	xor     ah, ah
   988 00007E28 E8EF90FFFF          <1> 	call	int16h
   989                              <1> 	; AL = ASCII Code of the Character
   990 00007E2D 3C0D                <1> 	cmp	al, 13 ; ENTER key
   991 00007E2F 742D                <1>         je	short loc_set_time_retn
   992 00007E31 3C1B                <1> 	cmp	al, 27 ; ESC key
   993 00007E33 7429                <1>         je	short loc_set_time_retn
   994                              <1> set_time_0:
   995 00007E35 A2[10360100]        <1> 	mov	[Hour], al
   996 00007E3A 3C30                <1> 	cmp	al, '0'
   997 00007E3C 7204                <1>         jb	short loc_set_time_stc_0
   998 00007E3E 3C32                <1> 	cmp	al, '2'
   999                              <1>  	;ja	loc_set_time_stc_0
  1000                              <1> 	; 26/07/2022
  1001 00007E40 7626                <1> 	jna	short set_time_1
  1002                              <1> 
  1003                              <1> 	; 26/07/2022
  1004                              <1> loc_set_time_stc_0:
  1005                              <1> 	;xor	bh, bh ; video page 0
  1006 00007E42 E838A5FFFF          <1> 	call	beeper ; BEEP !
  1007 00007E47 EBDD                <1> 	jmp	short loc_enter_hour_1
  1008                              <1> 
  1009                              <1> loc_set_time_stc_1:
  1010 00007E49 E881FFFFFF          <1> 	call	check_for_backspace
  1011 00007E4E 7407                <1> 	je	short loc_set_time_bs_1
  1012                              <1> 	;xor	bh, bh ; video page 0
  1013 00007E50 E82AA5FFFF          <1> 	call	beeper ; BEEP !
  1014 00007E55 EB18                <1> 	jmp	short loc_enter_hour_2
  1015                              <1> loc_set_time_bs_1:
  1016 00007E57 E861FFFFFF          <1> 	call	write_backspace
  1017 00007E5C EBC8                <1> 	jmp	short loc_enter_hour_1
  1018                              <1> 
  1019                              <1> 	; 26/07/2022
  1020                              <1> loc_set_time_retn:
  1021 00007E5E BE[273F0100]        <1> 	mov 	esi, nextline
  1022                              <1> 	;call	print_msg
  1023                              <1> 	;retn
  1024 00007E63 E902EFFFFF          <1> 	jmp	print_msg
  1025                              <1> 
  1026                              <1> set_time_1:
  1027                              <1> 	; 13/05/2016
  1028                              <1> 	;mov	bx, 7 ; attribute/color (bl)
  1029                              <1> 		      ; video page 0 (bh)
  1030 00007E68 B307                <1> 	mov	bl, 7
  1031 00007E6A E826A4FFFF          <1> 	call	_write_tty
  1032                              <1> loc_enter_hour_2:
  1033 00007E6F 30E4                <1> 	xor     ah, ah
  1034 00007E71 E8A690FFFF          <1> 	call	int16h
  1035                              <1> 	; AL = ASCII Code of the Character
  1036 00007E76 3C1B                <1> 	cmp	al, 27
  1037 00007E78 74E4                <1> 	je	short loc_set_time_retn
  1038 00007E7A A2[11360100]        <1> 	mov	[Hour+1], al
  1039 00007E7F 3C30                <1> 	cmp	al, '0'
  1040 00007E81 72C6                <1> 	jb	short loc_set_time_stc_1
  1041 00007E83 3C39                <1> 	cmp	al, '9'
  1042 00007E85 77C2                <1> 	ja	short loc_set_time_stc_1
  1043 00007E87 803D[10360100]32    <1>         cmp     byte [Hour], '2'
  1044 00007E8E 7204                <1> 	jb	short pass_set_time_24
  1045 00007E90 3C34                <1> 	cmp	al, '4'
  1046 00007E92 77B5                <1> 	ja	short loc_set_time_stc_1
  1047                              <1> pass_set_time_24:
  1048                              <1> 	; 13/05/2016
  1049                              <1> 	;mov	bx, 7 ; attribute/color (bl)
  1050                              <1> 		      ; video page 0 (bh)
  1051 00007E94 B307                <1> 	mov	bl, 7
  1052 00007E96 E8FAA3FFFF          <1> 	call	_write_tty
  1053                              <1> loc_enter_time_separator_1:
  1054 00007E9B 28E4                <1> 	sub    ah, ah ; 0
  1055 00007E9D E87A90FFFF          <1> 	call	int16h
  1056                              <1> 	; AL = ASCII Code of the Character
  1057 00007EA2 3C1B                <1> 	cmp	al, 27
  1058 00007EA4 74B8                <1> 	je	short loc_set_time_retn
  1059 00007EA6 3C3A                <1> 	cmp	al, ':'
  1060                              <1> 	;jne	loc_set_time_stc_2
  1061                              <1> 	; 26/07/2022
  1062 00007EA8 7415                <1> 	je	short set_time_2
  1063                              <1> 
  1064                              <1> 	; 26/07/2022
  1065                              <1> loc_set_time_stc_2:
  1066 00007EAA E820FFFFFF          <1> 	call	check_for_backspace
  1067 00007EAF 7407                <1> 	je	short loc_set_time_bs_2
  1068                              <1> 	;xor	bh, bh ; video page 0
  1069 00007EB1 E8C9A4FFFF          <1> 	call	beeper ; BEEP !
  1070 00007EB6 EBE3                <1> 	jmp	short loc_enter_time_separator_1
  1071                              <1> loc_set_time_bs_2:
  1072 00007EB8 E800FFFFFF          <1> 	call	write_backspace
  1073 00007EBD EBB0                <1> 	jmp	short loc_enter_hour_2
  1074                              <1> 
  1075                              <1> set_time_2:
  1076                              <1> 	; 13/05/2016
  1077                              <1> 	;mov	bx, 7 ; attribute/color (bl)
  1078                              <1> 		      ; video page 0 (bh)
  1079 00007EBF B307                <1> 	mov	bl, 7
  1080 00007EC1 E8CFA3FFFF          <1> 	call	_write_tty
  1081                              <1> loc_enter_minute_1:
  1082 00007EC6 30E4                <1> 	xor     ah, ah
  1083 00007EC8 E84F90FFFF          <1> 	call	int16h
  1084                              <1> 	; AL = ASCII Code of the Character
  1085 00007ECD 3C1B                <1> 	cmp	al, 27
  1086 00007ECF 748D                <1> 	je	short loc_set_time_retn
  1087 00007ED1 A2[13360100]        <1> 	mov	[Minute], al
  1088 00007ED6 3C30                <1> 	cmp	al, '0'
  1089 00007ED8 7204                <1> 	jb	short loc_set_time_stc_3
  1090 00007EDA 3C35                <1> 	cmp	al, '5'
  1091                              <1> 	;ja	loc_set_time_stc_3
  1092                              <1> 	; 26/07/2022
  1093 00007EDC 7615                <1> 	jna	short set_time_3
  1094                              <1> 
  1095                              <1> 	; 26/07/2022
  1096                              <1> loc_set_time_stc_3:
  1097 00007EDE E8ECFEFFFF          <1> 	call	check_for_backspace
  1098 00007EE3 7407                <1> 	je	short loc_set_time_bs_3
  1099                              <1> 	;xor	bh, bh ; video page 0
  1100 00007EE5 E895A4FFFF          <1> 	call	beeper ; BEEP !6
  1101 00007EEA EBDA                <1> 	jmp	short loc_enter_minute_1
  1102                              <1> loc_set_time_bs_3:
  1103 00007EEC E8CCFEFFFF          <1> 	call	write_backspace
  1104 00007EF1 EBA8                <1> 	jmp	short loc_enter_time_separator_1
  1105                              <1> 
  1106                              <1> set_time_3:
  1107                              <1> 	; 13/05/2016
  1108                              <1> 	;mov	bx, 7 ; attribute/color (bl)
  1109                              <1> 		      ; video page 0 (bh)
  1110 00007EF3 B307                <1> 	mov	bl, 7
  1111 00007EF5 E89BA3FFFF          <1> 	call	_write_tty
  1112                              <1> loc_enter_minute_2:
  1113 00007EFA 30E4                <1> 	xor     ah, ah
  1114 00007EFC E81B90FFFF          <1> 	call	int16h
  1115                              <1> 	; AL = ASCII Code of the Character
  1116 00007F01 3C1B                <1> 	cmp	al, 27
  1117                              <1> 	;je	short loc_set_time_retn
  1118                              <1> 	; 07/08/2022
  1119 00007F03 7505                <1> 	jne	short loc_enter_minute_3
  1120 00007F05 E954FFFFFF          <1> 	jmp	loc_set_time_retn
  1121                              <1> loc_enter_minute_3:
  1122 00007F0A A2[14360100]        <1> 	mov	[Minute+1], al
  1123 00007F0F 3C30                <1> 	cmp	al, '0'
  1124 00007F11 7204                <1> 	jb	short loc_set_time_stc_4
  1125 00007F13 3C39                <1> 	cmp	al, '9'
  1126                              <1> 	;ja	loc_set_time_stc_4
  1127                              <1> 	; 26/07/2022
  1128 00007F15 7615                <1> 	jna	short set_time_4
  1129                              <1> 
  1130                              <1> 	; 26/07/2022
  1131                              <1> loc_set_time_stc_4:
  1132 00007F17 E8B3FEFFFF          <1> 	call	check_for_backspace
  1133 00007F1C 7407                <1> 	je	short loc_set_time_bs_4
  1134                              <1> 	;xor	bh, bh ; video page 0
  1135 00007F1E E85CA4FFFF          <1> 	call	beeper ; BEEP !
  1136 00007F23 EBD5                <1> 	jmp	short loc_enter_minute_2
  1137                              <1> loc_set_time_bs_4:
  1138 00007F25 E893FEFFFF          <1> 	call	write_backspace
  1139 00007F2A EB9A                <1> 	jmp	short loc_enter_minute_1
  1140                              <1> 
  1141                              <1> set_time_4:
  1142                              <1> 	; 13/05/2016
  1143                              <1> 	;mov	bx, 7 ; attribute/color (bl)
  1144                              <1> 		      ; video page 0 (bh)
  1145 00007F2C B307                <1> 	mov	bl, 7
  1146 00007F2E E862A3FFFF          <1> 	call	_write_tty
  1147                              <1> loc_enter_time_separator_2:
  1148 00007F33 66C705[16360100]30- <1> 	mov	word [Second], 3030h
  1148 00007F3B 30                  <1>
  1149 00007F3C 28E4                <1> 	sub     ah, ah
  1150 00007F3E E8D98FFFFF          <1> 	call	int16h
  1151                              <1> 	; AL = ASCII Code of the Character
  1152 00007F43 3C0D                <1> 	cmp	al, 13
  1153                              <1>         ;je	short loc_set_time_progress
  1154                              <1> 	; 07/08/2022
  1155 00007F45 7505                <1> 	jne	short loc_enter_time_separator_3
  1156                              <1> jmp_loc_set_time_progress:
  1157 00007F47 E9D4000000          <1> 	jmp	loc_set_time_progress
  1158                              <1> loc_enter_time_separator_3:
  1159 00007F4C 3C1B                <1> 	cmp	al, 27
  1160                              <1> 	;;je	loc_set_time_retn
  1161                              <1> 	; 26/07/2022
  1162                              <1> 	;je	short loc_set_time_ok
  1163                              <1> 	; 07/08/2022
  1164 00007F4E 7505                <1> 	jne	short loc_enter_time_separator_4
  1165 00007F50 E982000000          <1> 	jmp	loc_set_time_ok
  1166                              <1> loc_enter_time_separator_4:
  1167 00007F55 3C3A                <1> 	cmp	al, ':'
  1168 00007F57 7563                <1>         jne	short loc_set_time_stc_5
  1169                              <1> 
  1170                              <1> 	; 13/05/2016
  1171                              <1> 	;mov	bx, 7 ; attribute/color (bl)
  1172                              <1> 		      ; video page 0 (bh)
  1173 00007F59 B307                <1> 	mov	bl, 7
  1174 00007F5B E835A3FFFF          <1> 	call	_write_tty
  1175                              <1> loc_enter_second_1:
  1176 00007F60 30E4                <1> 	xor     ah, ah
  1177 00007F62 E8B58FFFFF          <1> 	call	int16h
  1178                              <1> 	; AL = ASCII Code of the Character
  1179 00007F67 3C0D                <1> 	cmp	al, 13
  1180                              <1> 	;je	short loc_set_time_progress
  1181                              <1> 	; 07/08/2022
  1182 00007F69 74DC                <1> 	je	short jmp_loc_set_time_progress
  1183 00007F6B 3C1B                <1> 	cmp	al, 27
  1184                              <1> 	;;je	loc_set_time_retn
  1185                              <1> 	; 26/07/2022
  1186                              <1> 	;je	short loc_set_time_ok
  1187                              <1> 	; 07/08/2022
  1188 00007F6D 7502                <1> 	jne	short loc_enter_second_2
  1189 00007F6F EB66                <1> 	jmp	loc_set_time_ok
  1190                              <1> loc_enter_second_2:
  1191 00007F71 A2[16360100]        <1> 	mov	[Second], al
  1192 00007F76 3C30                <1> 	cmp	al, '0'
  1193 00007F78 7267                <1> 	jb	short loc_set_time_stc_6
  1194 00007F7A 3C35                <1> 	cmp	al, '5'
  1195 00007F7C 7763                <1> 	ja	short loc_set_time_stc_6
  1196                              <1> 	; 13/05/2016
  1197                              <1> 	;mov	bx, 7 ; attribute/color (bl)
  1198                              <1> 		      ; video page 0 (bh)
  1199 00007F7E B307                <1> 	mov	bl, 7
  1200 00007F80 E810A3FFFF          <1> 	call	_write_tty
  1201                              <1> loc_enter_second_3:
  1202 00007F85 30E4                <1> 	xor     ah, ah
  1203 00007F87 E8908FFFFF          <1> 	call	int16h
  1204                              <1> 	; AL = ASCII Code of the Character
  1205 00007F8C 3C1B                <1> 	cmp	al, 27
  1206                              <1> 	;je	short loc_set_time_retn
  1207                              <1> 	; 26/07/2022
  1208 00007F8E 7447                <1> 	je	short loc_set_time_ok
  1209 00007F90 3C30                <1> 	cmp	al, '0'
  1210 00007F92 7271                <1>         jb	short loc_set_time_stc_7
  1211 00007F94 3C39                <1> 	cmp	al, '9'
  1212 00007F96 776D                <1>         ja	short loc_set_time_stc_7
  1213                              <1> 	; 13/05/2016
  1214                              <1> 	;mov	bx, 7 ; attribute/color (bl)
  1215                              <1> 		      ; video page 0 (bh)
  1216 00007F98 B307                <1> 	mov	bl, 7
  1217 00007F9A E8F6A2FFFF          <1> 	call	_write_tty
  1218                              <1> loc_set_time_get_lchar_again:
  1219 00007F9F 28E4                <1> 	sub	ah, ah ; 0
  1220 00007FA1 E8768FFFFF          <1> 	call	int16h
  1221                              <1> 	; AL = ASCII Code of the Character
  1222 00007FA6 3C0D                <1> 	cmp	al, 13
  1223 00007FA8 7476                <1> 	je	short loc_set_time_progress
  1224 00007FAA 3C1B                <1> 	cmp	al, 27
  1225                              <1> 	;je	short loc_set_time_retn
  1226                              <1> 	; 07/08/2022
  1227 00007FAC 7429                <1> 	je	short loc_set_time_ok
  1228                              <1> 	;
  1229 00007FAE E81CFEFFFF          <1> 	call	check_for_backspace
  1230 00007FB3 75EA                <1> 	jne	short loc_set_time_get_lchar_again
  1231                              <1> 
  1232                              <1> loc_set_time_bs_8:
  1233 00007FB5 E803FEFFFF          <1> 	call	write_backspace
  1234 00007FBA EBC9                <1> 	jmp	short loc_enter_second_3
  1235                              <1> 
  1236                              <1> ;	; 26/07/2022
  1237                              <1> ;loc_set_time_retn:
  1238                              <1> ;	mov 	esi, nextline
  1239                              <1> ;	;call	print_msg
  1240                              <1> ;	;retn
  1241                              <1> ;	jmp	print_msg
  1242                              <1> 
  1243                              <1> 	; 26/07/2022
  1244                              <1> ;loc_set_time_stc_0:
  1245                              <1> ;	;xor	bh, bh ; video page 0
  1246                              <1> ;	call	beeper ; BEEP !
  1247                              <1> ;	jmp	loc_enter_hour_1
  1248                              <1> ;loc_set_time_stc_1:
  1249                              <1> ;	call	check_for_backspace
  1250                              <1> ;	je	short loc_set_time_bs_1
  1251                              <1> ;	;xor	bh, bh ; video page 0
  1252                              <1> ;	call	beeper ; BEEP !
  1253                              <1> ;	jmp	loc_enter_hour_2
  1254                              <1> ;loc_set_time_bs_1:
  1255                              <1> ;	call	write_backspace
  1256                              <1> ;	jmp	loc_enter_hour_1
  1257                              <1> ;loc_set_time_stc_2:
  1258                              <1> ;	call	check_for_backspace
  1259                              <1> ;	je	short loc_set_time_bs_2
  1260                              <1> ;	;xor	bh, bh ; video page 0
  1261                              <1> ;	call	beeper ; BEEP !
  1262                              <1> ;	jmp	loc_enter_time_separator_1
  1263                              <1> ;loc_set_time_bs_2:
  1264                              <1> ;	call	write_backspace
  1265                              <1> ;	jmp	loc_enter_hour_2
  1266                              <1> ;loc_set_time_stc_3:
  1267                              <1> ;	call	check_for_backspace
  1268                              <1> ;	je	short loc_set_time_bs_3
  1269                              <1> ;	;xor	bh, bh ; video page 0
  1270                              <1> ;	call	beeper ; BEEP !6
  1271                              <1> ;	jmp	loc_enter_minute_1
  1272                              <1> ;loc_set_time_bs_3:
  1273                              <1> ;	call	write_backspace
  1274                              <1> ;	jmp	loc_enter_time_separator_1
  1275                              <1> ;loc_set_time_stc_4:
  1276                              <1> ;	call	check_for_backspace
  1277                              <1> ;	je	short loc_set_time_bs_4
  1278                              <1> ;	;xor	bh, bh ; video page 0
  1279                              <1> ;	call	beeper ; BEEP !
  1280                              <1> ;	jmp	loc_enter_minute_2
  1281                              <1> ;loc_set_time_bs_4:
  1282                              <1> ;	call	write_backspace
  1283                              <1> ;	jmp	loc_enter_minute_1
  1284                              <1> 
  1285                              <1> 	; 26/07/2022
  1286                              <1> loc_set_time_stc_5:
  1287 00007FBC E80EFEFFFF          <1> 	call	check_for_backspace
  1288 00007FC1 740A                <1> 	je	short loc_set_time_bs_5
  1289                              <1> 	;xor	bh, bh ; video page 0
  1290 00007FC3 E8B7A3FFFF          <1> 	call	beeper ; BEEP !
  1291 00007FC8 E966FFFFFF          <1> 	jmp	loc_enter_time_separator_2
  1292                              <1> loc_set_time_bs_5:
  1293 00007FCD E8EBFDFFFF          <1> 	call	write_backspace
  1294 00007FD2 E923FFFFFF          <1> 	jmp	loc_enter_minute_2
  1295                              <1> 
  1296                              <1> 	; 26/07/2022
  1297                              <1> loc_set_time_ok:
  1298 00007FD7 BE[273F0100]        <1> 	mov 	esi, nextline
  1299                              <1> 	;call	print_msg
  1300                              <1> 	;retn
  1301 00007FDC E989EDFFFF          <1> 	jmp	print_msg
  1302                              <1> 
  1303                              <1> 	; 07/08/2022
  1304                              <1> loc_set_time_stc_6:
  1305 00007FE1 E8E9FDFFFF          <1> 	call	check_for_backspace
  1306 00007FE6 7413                <1> 	je	short loc_set_time_bs_6
  1307                              <1> 	;xor	bh, bh ; video page 0
  1308 00007FE8 E892A3FFFF          <1> 	call	beeper ; BEEP !
  1309 00007FED 66C705[16360100]30- <1> 	mov	word [Second], 3030h
  1309 00007FF5 30                  <1>
  1310 00007FF6 E965FFFFFF          <1> 	jmp	loc_enter_second_1
  1311                              <1> loc_set_time_bs_6:
  1312 00007FFB E8BDFDFFFF          <1> 	call	write_backspace
  1313 00008000 E92EFFFFFF          <1> 	jmp	loc_enter_time_separator_2
  1314                              <1> loc_set_time_stc_7:
  1315 00008005 E8C5FDFFFF          <1> 	call	check_for_backspace
  1316 0000800A 740A                <1> 	je	short loc_set_time_bs_7
  1317                              <1> 	;xor	bh, bh ; video page 0
  1318 0000800C E86EA3FFFF          <1> 	call	beeper ; BEEP !
  1319 00008011 E96FFFFFFF          <1> 	jmp	loc_enter_second_3
  1320                              <1> loc_set_time_bs_7:
  1321 00008016 E8A2FDFFFF          <1> 	call	write_backspace
  1322 0000801B E940FFFFFF          <1> 	jmp	loc_enter_second_1
  1323                              <1> 
  1324                              <1> loc_set_time_progress:
  1325                              <1> 	; Get Current Time
  1326                              <1> 	;mov 	ah, 02h
  1327                              <1> 	;call	int1Ah
  1328 00008020 E8E6E2FFFF          <1> 	call	RTC_20	; GET RTC TIME
  1329                              <1> 	;DL = Daylight Savings Enable option (0-1)
  1330                              <1> 
  1331 00008025 66A1[10360100]      <1> 	mov	ax, [Hour]
  1332 0000802B 662D3030            <1> 	sub	ax, '00'
  1333 0000802F C0E004              <1> 	shl	al, 4 ; * 16
  1334 00008032 88C5                <1> 	mov	ch, al
  1335 00008034 00E5                <1> 	add	ch, ah
  1336 00008036 66A1[13360100]      <1> 	mov	ax, [Minute]
  1337 0000803C 662D3030            <1> 	sub	ax, '00'
  1338 00008040 C0E004              <1> 	shl	al, 4 ; * 16
  1339 00008043 88C1                <1> 	mov	cl, al
  1340 00008045 00E1                <1> 	add	cl, ah
  1341 00008047 66A1[16360100]      <1> 	mov	ax, [Second]
  1342 0000804D 662D3030            <1> 	sub	ax, '00'
  1343 00008051 C0E004              <1> 	shl	al, 4 ; * 16
  1344 00008054 88C6                <1> 	mov	dh, al
  1345 00008056 00E6                <1> 	add	dh, ah
  1346                              <1> 	
  1347                              <1> 	;mov	ah, 03h
  1348                              <1> 	;call	int1Ah
  1349 00008058 E8DCE2FFFF          <1> 	call	RTC_30	; SET RTC TIME
  1350                              <1> 
  1351                              <1> 	; 26/07/2022
  1352 0000805D E975FFFFFF          <1> 	jmp	loc_set_time_ok
  1353                              <1> 
  1354                              <1> print_volume_info:
  1355                              <1> 	; 01/03/2016
  1356                              <1> 	; 08/02/2016
  1357                              <1> 	; 06/02/2016
  1358                              <1> 	; 04/02/2016
  1359                              <1> 	; 18/01/2016 (TRDOS 386 = TRDOS v2.0)
  1360                              <1> 	; 25/10/2009
  1361                              <1> 	;
  1362                              <1> 	; "Volume Serial No: "
  1363                              <1>  	;
  1364                              <1> 	; INPUT  : AL = DOS Drive Number
  1365                              <1> 	; OUTPUT : AH = FS Type
  1366                              <1> 	;          AL = DOS Drive Name
  1367                              <1> 	; CF = 0 -> OK
  1368                              <1> 	; CF = 1 -> Drive not ready
  1369                              <1> 
  1370 00008062 88C4                <1> 	mov	ah, al
  1371 00008064 28C0                <1> 	sub	al, al
  1372 00008066 0FB7F0              <1> 	movzx	esi, ax	
  1373 00008069 81C600010900        <1> 	add	esi, Logical_DOSDisks
  1374 0000806F 8A06                <1> 	mov	al, [esi]
  1375 00008071 3C41                <1> 	cmp	al, 'A'  
  1376 00008073 7304                <1> 	jnb	short loc_pvi_set_vol_name
  1377 00008075 8A6604              <1> 	mov	ah, [esi+LD_FSType]
  1378 00008078 C3                  <1> 	retn
  1379                              <1> 
  1380                              <1> loc_pvi_set_vol_name:
  1381 00008079 A2[4A360100]        <1> 	mov	[Vol_Drv_Name], al
  1382 0000807E 56                  <1> 	push	esi
  1383 0000807F E858010000          <1> 	call	move_volume_name_and_serial_no ;;;
  1384 00008084 7302                <1> 	jnc	short loc_pvi_mvn_ok
  1385 00008086 5E                  <1> 	pop	esi
  1386 00008087 C3                  <1> 	retn
  1387                              <1> 
  1388                              <1> loc_pvi_mvn_ok:
  1389 00008088 8B3424              <1> 	mov	esi, [esp]
  1390 0000808B 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
  1391 0000808F 7509                <1> 	jne	short loc_pvi_fat_vol_size
  1392 00008091 8B4670              <1> 	mov	eax, [esi+LD_FS_VolumeSize]
  1393 00008094 0FB75E11            <1> 	movzx	ebx, word [esi+LD_FS_BytesPerSec]
  1394 00008098 EB07                <1> 	jmp	short loc_vol_size_mul32
  1395                              <1> loc_pvi_fat_vol_size:
  1396 0000809A 8B4670              <1> 	mov	eax, [esi+LD_TotalSectors]
  1397 0000809D 0FB75E11            <1> 	movzx	ebx, word [esi+LD_BPB+BPB_BytsPerSec]
  1398                              <1> loc_vol_size_mul32:
  1399 000080A1 F7E3                <1> 	mul	ebx
  1400 000080A3 09D2                <1> 	or	edx, edx
  1401 000080A5 7507                <1> 	jnz	short loc_vol_size_in_kbytes
  1402                              <1> loc_vol_size_in_bytes:
  1403 000080A7 B9[28360100]        <1> 	mov	ecx, VolSize_Bytes
  1404 000080AC EB0D                <1> 	jmp	short loc_write_vol_size_str
  1405                              <1> loc_vol_size_in_kbytes:
  1406 000080AE 66BB0004            <1> 	mov	bx, 1024
  1407 000080B2 F7F3                <1> 	div	ebx
  1408 000080B4 B9[1B360100]        <1> 	mov 	ecx, VolSize_KiloBytes
  1409 000080B9 31D2                <1> 	xor	edx, edx ; 0
  1410                              <1> loc_write_vol_size_str:
  1411 000080BB 890D[B8840100]      <1> 	mov	[VolSize_Unit1], ecx
  1412                              <1> 	; 
  1413 000080C1 BF[CE840100]        <1> 	mov	edi, Vol_Tot_Sec_Str_End
  1414                              <1>         ;mov	byte [edi], 0
  1415 000080C6 B90A000000          <1> 	mov	ecx, 10
  1416                              <1> loc_write_vol_size_chr:
  1417 000080CB F7F1                <1> 	div	ecx
  1418 000080CD 80C230              <1> 	add	dl, '0'
  1419 000080D0 4F                  <1> 	dec	edi
  1420 000080D1 8817                <1> 	mov	[edi], dl
  1421 000080D3 85C0                <1> 	test	eax, eax
  1422 000080D5 7404                <1> 	jz	short loc_write_vol_size_str_ok
  1423 000080D7 28D2                <1> 	sub	dl, dl ; 0
  1424 000080D9 EBF0                <1> 	jmp	short loc_write_vol_size_chr
  1425                              <1> 
  1426                              <1> loc_write_vol_size_str_ok:
  1427 000080DB 893D[C0840100]      <1> 	mov	[Vol_Tot_Sec_Str_Start], edi
  1428                              <1> 	;
  1429 000080E1 BF[33360100]        <1> 	mov	edi, Vol_FS_Name
  1430 000080E6 8A4E03              <1> 	mov	cl, [esi+LD_FATType]
  1431 000080E9 20C9                <1> 	and	cl, cl ; 0 ?
  1432 000080EB 7515                <1> 	jnz	short loc_write_vol_FAT_str_1
  1433 000080ED 66C7075452          <1> 	mov	word [edi], 'TR'
  1434 000080F2 C7470420465331      <1> 	mov	dword [edi+4], ' FS1'
  1435                              <1> 	;movzx	ebx, word [esi+LD_FS_BytesPerSec]
  1436 000080F9 668B5E11            <1> 	mov	bx, [esi+LD_FS_BytesPerSec]
  1437 000080FD 8B4674              <1> 	mov	eax, [esi+LD_FS_FreeSectors]
  1438 00008100 EB36                <1> 	jmp	short loc_vol_freespace_mul32
  1439                              <1> 
  1440                              <1> loc_write_vol_FAT_str_1:
  1441 00008102 66B83332            <1> 	mov	ax, '32' ; FAT32
  1442 00008106 80F902              <1> 	cmp	cl, 2 ; [esi+LD_FATType]
  1443 00008109 7708                <1> 	ja	short loc_write_vol_FAT_str_2
  1444 0000810B 66B83132            <1> 	mov	ax, '12' ; FAT12
  1445 0000810F 7202                <1> 	jb	short loc_write_vol_FAT_str_2
  1446 00008111 B436                <1> 	mov	ah, '6'  ; FAT16
  1447                              <1> loc_write_vol_FAT_str_2:
  1448 00008113 C70746415420        <1> 	mov	dword [edi], 'FAT '
  1449 00008119 66894704            <1> 	mov	word [edi+4], ax
  1450                              <1> 	;
  1451                              <1> 	;movzx	ebx, word [esi+LD_BPB+BPB_BytsPerSec]
  1452 0000811D 668B5E11            <1> 	mov	bx, [esi+LD_BPB+BPB_BytsPerSec]
  1453 00008121 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors]
  1454                              <1> 
  1455                              <1> loc_vol_freespace_recalc0:
  1456                              <1> 	; 01/03/2016
  1457 00008124 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh
  1458 00008127 720F                <1> 	jb	short loc_vol_freespace_mul32
  1459                              <1> 	;inc	eax ; 0
  1460 00008129 20C9                <1> 	and	cl, cl ; byte [esi+LD_FATType]
  1461 0000812B 740B                <1> 	jz	short loc_vol_freespace_mul32
  1462 0000812D 53                  <1> 	push	ebx
  1463 0000812E 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free sectors
  1464 00008132 E8DD470000          <1> 	call	calculate_fat_freespace
  1465 00008137 5B                  <1> 	pop	ebx
  1466                              <1> 
  1467                              <1> loc_vol_freespace_mul32:
  1468 00008138 F7E3                <1> 	mul	ebx
  1469 0000813A 09D2                <1> 	or	edx, edx
  1470 0000813C 7507                <1> 	jnz	short loc_vol_fspace_in_kbytes
  1471                              <1> loc_vol_fspace_in_bytes:
  1472 0000813E B9[28360100]        <1> 	mov	ecx, VolSize_Bytes
  1473 00008143 EB0D                <1> 	jmp	short loc_write_vol_fspace_str
  1474                              <1> loc_vol_fspace_in_kbytes:
  1475 00008145 66BB0004            <1> 	mov	bx, 1024
  1476 00008149 F7F3                <1> 	div	ebx
  1477 0000814B B9[1B360100]        <1> 	mov 	ecx, VolSize_KiloBytes
  1478 00008150 31D2                <1> 	xor	edx, edx ; 0
  1479                              <1> loc_write_vol_fspace_str:
  1480 00008152 890D[BC840100]      <1> 	mov	[VolSize_Unit2], ecx
  1481                              <1> 	;
  1482 00008158 BF[DE840100]        <1> 	mov	edi, Vol_Free_Sectors_Str_End
  1483                              <1>         ;mov	byte [edi], 0
  1484 0000815D B90A000000          <1> 	mov	ecx, 10
  1485                              <1> loc_write_vol_fspace_chr:
  1486 00008162 F7F1                <1> 	div	ecx
  1487 00008164 80C230              <1> 	add	dl, '0'
  1488 00008167 4F                  <1> 	dec	edi
  1489 00008168 8817                <1> 	mov	[edi], dl
  1490 0000816A 85C0                <1> 	test	eax, eax
  1491 0000816C 7404                <1> 	jz	short loc_write_vol_fspace_str_ok
  1492 0000816E 28D2                <1> 	sub	dl, dl ; 0
  1493 00008170 EBF0                <1> 	jmp	short loc_write_vol_fspace_chr
  1494                              <1> 
  1495                              <1> loc_write_vol_fspace_str_ok:
  1496 00008172 893D[D0840100]      <1> 	mov	[Vol_Free_Sectors_Str_Start], edi
  1497                              <1> 	;
  1498 00008178 BE[31360100]        <1> 	mov	esi, Volume_in_drive
  1499 0000817D E8E8EBFFFF          <1> 	call	print_msg
  1500 00008182 BE[71360100]        <1> 	mov	esi, Vol_Name
  1501 00008187 E8DEEBFFFF          <1> 	call	print_msg
  1502 0000818C BE[273F0100]        <1> 	mov	esi, nextline
  1503 00008191 E8D4EBFFFF          <1> 	call	print_msg
  1504                              <1> 	;
  1505 00008196 BE[D2360100]        <1> 	mov	esi, Vol_Total_Sector_Header
  1506 0000819B E8CAEBFFFF          <1> 	call	print_msg
  1507 000081A0 8B35[C0840100]      <1> 	mov	esi, [Vol_Tot_Sec_Str_Start]
  1508 000081A6 E8BFEBFFFF          <1> 	call	print_msg
  1509 000081AB 8B35[B8840100]      <1> 	mov	esi, [VolSize_Unit1]
  1510 000081B1 E8B4EBFFFF          <1> 	call	print_msg
  1511                              <1> 	;
  1512 000081B6 BE[E3360100]        <1> 	mov	esi, Vol_Free_Sectors_Header
  1513 000081BB E8AAEBFFFF          <1> 	call	print_msg
  1514 000081C0 8B35[D0840100]      <1> 	mov	esi, [Vol_Free_Sectors_Str_Start]
  1515 000081C6 E89FEBFFFF          <1> 	call	print_msg
  1516 000081CB 8B35[BC840100]      <1> 	mov	esi, [VolSize_Unit2]
  1517 000081D1 E894EBFFFF          <1> 	call	print_msg
  1518                              <1> 	;
  1519 000081D6 5E                  <1> 	pop	esi
  1520                              <1> 
  1521                              <1> 	;mov	ah, [esi+LD_FSType]
  1522                              <1> 	;mov	al, [esi+LD_FATType]
  1523 000081D7 668B4603            <1> 	mov	ax, [esi+LD_FATType]
  1524                              <1> 
  1525 000081DB C3                  <1> 	retn
  1526                              <1> 
  1527                              <1> move_volume_name_and_serial_no:
  1528                              <1> 	; 26/07/2022 (TRDOS 386 Kernel v2.0.5)
  1529                              <1> 	; 08/02/2016  (TRDOS 386 = TRDOS v2.0)
  1530                              <1> 	; this routine will be called by
  1531                              <1> 	; "print_volume_info" and "print_directory"
  1532                              <1> 	; INPUT ->
  1533                              <1> 	;	ESI = Logical DOS drv descripton table address
  1534                              <1> 	; OUTPUT ->
  1535                              <1> 	;	*Volume name will be moved to text area
  1536                              <1> 	;	*Volume serial number will be converted to
  1537                              <1> 	;	 text and will be moved to text area
  1538                              <1> 	;   cf = 1 -> invalid/unknown dos drive
  1539                              <1> 	;   cf = 0 -> ecx = 0
  1540                              <1> 	;
  1541                              <1> 	; (eax, edx, ecx, esi, edi will be changed)
  1542                              <1> 
  1543                              <1> 	; 26/07/2022
  1544 000081DC 31C9                <1> 	xor	ecx, ecx
  1545                              <1> 
  1546 000081DE BF[71360100]        <1> 	mov 	edi, Vol_Name
  1547                              <1> 
  1548                              <1> 	;mov	ah, [esi+LD_FSType]
  1549                              <1> 	;mov	al, [esi+LD_FATType]
  1550 000081E3 668B4603            <1> 	mov	ax, [esi+LD_FATType]
  1551 000081E7 80FCA1              <1> 	cmp	ah, 0A1h
  1552 000081EA 7418                <1> 	je	short mvn_2
  1553 000081EC 08E4                <1> 	or	ah, ah
  1554 000081EE 7404                <1> 	jz	short mvn_0
  1555 000081F0 08C0                <1> 	or	al, al
  1556 000081F2 7504                <1> 	jnz	short mvn_1
  1557                              <1> mvn_0:
  1558 000081F4 8A06                <1> 	mov	al, [esi]
  1559 000081F6 F9                  <1> 	stc
  1560 000081F7 C3                  <1> 	retn
  1561                              <1> mvn_1:
  1562 000081F8 3C02                <1> 	cmp	al, 2
  1563 000081FA 7714                <1> 	ja	short mvn_3 
  1564                              <1> 	;or	al, al
  1565                              <1> 	;jz	short mvn_2
  1566 000081FC 8B462D              <1> 	mov	eax, [esi+LD_BPB+VolumeID]
  1567 000081FF 83C631              <1> 	add	esi, LD_BPB+VolumeLabel
  1568 00008202 EB12                <1> 	jmp	short mvn_4
  1569                              <1> mvn_2:
  1570 00008204 8B4628              <1> 	mov	eax, [esi+LD_FS_VolumeSerial]
  1571 00008207 83C62C              <1> 	add	esi, LD_FS_VolumeName
  1572                              <1> 	;mov	ecx, 16
  1573                              <1> 	; 26/07/2022
  1574 0000820A B110                <1> 	mov	cl, 16
  1575 0000820C F3A5                <1> 	rep	movsd
  1576 0000820E EB0D                <1> 	jmp	short mvn_5
  1577                              <1> mvn_3:
  1578 00008210 8B4649              <1> 	mov	eax, [esi+LD_BPB+FAT32_VolID]
  1579 00008213 83C64D              <1> 	add	esi, LD_BPB+FAT32_VolLab
  1580                              <1> mvn_4:
  1581                              <1> 	;mov	ecx, 11
  1582                              <1> 	; 26/07/2022
  1583 00008216 B10B                <1> 	mov	cl, 11
  1584 00008218 F3A4                <1> 	rep	movsb
  1585 0000821A C60700              <1> 	mov	byte [edi], 0
  1586                              <1> mvn_5:
  1587                              <1> 	;mov	[Current_VolSerial], eax
  1588 0000821D E893BFFFFF          <1> 	call	dwordtohex
  1589 00008222 8915[C6360100]      <1> 	mov	[Vol_Serial1], edx
  1590 00008228 A3[CB360100]        <1> 	mov	[Vol_Serial2], eax
  1591                              <1> 	; ecx = 0
  1592 0000822D C3                  <1> 	retn
  1593                              <1> 
  1594                              <1> get_volume_serial_number:
  1595                              <1> 	; 19/01/2016 (TRDOS 386 = TRDOS v2.0)
  1596                              <1> 	; 08/08/2010
  1597                              <1> 	;
  1598                              <1> 	; INPUT -> DL = Logical DOS Drive number
  1599                              <1> 	; OUTPUT -> EAX = Volume serial number
  1600                              <1> 	;          BL= FAT Type	    
  1601                              <1> 	;          BH = Logical DOS drv Number (DL input)
  1602                              <1> 	; cf = 1 -> Drive not ready
  1603                              <1> 
  1604 0000822E 31DB                <1> 	xor	ebx, ebx
  1605 00008230 88D7                <1> 	mov	bh, dl
  1606 00008232 3815[9A340100]      <1> 	cmp	[Last_DOS_DiskNo], dl
  1607 00008238 7304                <1> 	jnb	short loc_gvsn_start
  1608                              <1> loc_gvsn_stc_retn:
  1609 0000823A 31C0                <1> 	xor	eax, eax
  1610 0000823C F9                  <1> 	stc
  1611 0000823D C3                  <1>         retn
  1612                              <1> loc_gvsn_start:
  1613 0000823E 56                  <1> 	push	esi
  1614 0000823F BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1615 00008244 01DE                <1> 	add	esi, ebx
  1616 00008246 8A5E03              <1> 	mov	bl, [esi+LD_FATType]
  1617 00008249 20DB                <1> 	and	bl, bl
  1618 0000824B 740F                <1> 	jz	short loc_gvsn_fs
  1619 0000824D 80FB02              <1> 	cmp	bl, 2
  1620 00008250 7705                <1> 	ja	short loc_gvsn_fat32
  1621                              <1> loc_gvsn_fat:
  1622 00008252 83C62D              <1> 	add	esi, LD_BPB + VolumeID
  1623 00008255 EB0E                <1> 	jmp	short loc_gvsn_return
  1624                              <1> loc_gvsn_fat32: 
  1625 00008257 83C649              <1> 	add	esi, LD_BPB + FAT32_VolID
  1626 0000825A EB09                <1> 	jmp	short loc_gvsn_return 
  1627                              <1> loc_gvsn_fs:
  1628 0000825C 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
  1629 00008260 75D8                <1> 	jne	short loc_gvsn_stc_retn 
  1630 00008262 83C628              <1> 	add	esi, LD_FS_VolumeSerial
  1631                              <1> loc_gvsn_return:
  1632 00008265 8B06                <1> 	mov	eax, [esi]
  1633 00008267 5E                  <1> 	pop	esi
  1634 00008268 C3                  <1> 	retn
  1635                              <1> 
  1636                              <1> ; CMD_INTR.ASM [ TRDOS Command Interpreter Procedure ]
  1637                              <1> ; 09/11/2011
  1638                              <1> ; 29/01/2005
  1639                              <1> 
  1640                              <1> command_interpreter:
  1641                              <1> 	; 26/07/2022 (TRDOS 386 Kernel v2.0.5)
  1642                              <1> 	; 16/10/2016
  1643                              <1> 	; 12/10/2016
  1644                              <1> 	; 13/05/2016
  1645                              <1> 	; 07/05/2016
  1646                              <1> 	; 04/03/2016
  1647                              <1> 	; 04/02/2016
  1648                              <1> 	; 03/02/2016
  1649                              <1> 	; 30/01/2016
  1650                              <1> 	; 29/01/2016 (TRDOS 386 = TRDOS 2.0)
  1651                              <1> 	; 15/09/2011
  1652                              <1> 	; 29/01/2005
  1653                              <1>         
  1654                              <1> 	; Input: ecx = command word length (CL)
  1655                              <1> 	;	 CommandBuffer = Command string offset
  1656                              <1>  
  1657 00008269 C605[70850100]00    <1> 	mov	byte [Program_Exit], 0
  1658                              <1> 
  1659                              <1> 	;cmp	cl, 4
  1660                              <1> 	;ja	c_6
  1661                              <1> 	;jb	c_2
  1662                              <1> 
  1663                              <1> 	; 26/07/2022
  1664 00008270 80F903              <1> 	cmp	cl, 3
  1665 00008273 777C                <1> 	ja	short c_4
  1666 00008275 7405                <1> 	je	short c_3
  1667 00008277 E9D2010000          <1> 	jmp	c_2
  1668                              <1> c_3:
  1669                              <1> cmp_cmd_dir:
  1670 0000827C BF[02350100]        <1> 	mov	edi, Cmd_Dir
  1671 00008281 E8D1030000          <1> 	call	cmp_cmd	
  1672                              <1> 	;jnc	print_directory_list
  1673                              <1> 	; 26/07/2022
  1674 00008286 7205                <1> 	jc	short cmp_cmd_cls
  1675 00008288 E97D040000          <1> 	jmp	print_directory_list
  1676                              <1> 
  1677                              <1> cmp_cmd_cls:
  1678 0000828D B103                <1> 	mov	cl, 3
  1679 0000828F BF[3E350100]        <1> 	mov	edi, Cmd_Cls
  1680 00008294 E8BE030000          <1> 	call	cmp_cmd	
  1681                              <1>         ;jnc	clear_screen
  1682                              <1> 	; 26/07/2022
  1683 00008299 7205                <1> 	jc	short cmp_cmd_ver
  1684 0000829B E9E0EAFFFF          <1> 	jmp	clear_screen
  1685                              <1> 
  1686                              <1> cmp_cmd_ver:
  1687 000082A0 B103                <1> 	mov	cl, 3
  1688 000082A2 BF[0C350100]        <1> 	mov	edi, Cmd_Ver
  1689 000082A7 E8AB030000          <1> 	call	cmp_cmd	
  1690 000082AC 720A                <1> 	jc	short cmp_cmd_mem
  1691                              <1> 
  1692 000082AE BE[A2340100]        <1> 	mov	esi, mainprog_Version
  1693                              <1> 	;call	print_msg
  1694 000082B3 E9B2EAFFFF          <1> 	jmp	print_msg
  1695                              <1> 	;retn
  1696                              <1> 
  1697                              <1> cmp_cmd_mem:
  1698 000082B8 B103                <1> 	mov	cl, 3
  1699 000082BA BF[74350100]        <1> 	mov	edi, Cmd_Mem
  1700 000082BF E893030000          <1> 	call	cmp_cmd	
  1701                              <1> 	;jnc	memory_info
  1702                              <1> 	; 26/07/2022
  1703 000082C4 7205                <1> 	jc	short cmp_cmd_del
  1704 000082C6 E917BEFFFF          <1> 	jmp	memory_info
  1705                              <1> 
  1706                              <1> cmp_cmd_del:
  1707 000082CB B103                <1> 	mov	cl, 3
  1708 000082CD BF[47350100]        <1> 	mov	edi, Cmd_Del
  1709 000082D2 E880030000          <1> 	call	cmp_cmd	
  1710                              <1>         ;jnc	delete_file
  1711                              <1> 	; 26/07/2022
  1712 000082D7 7205                <1> 	jc	short cmp_cmd_set
  1713 000082D9 E901110000          <1> 	jmp	delete_file
  1714                              <1> 
  1715                              <1> cmp_cmd_set:
  1716 000082DE B103                <1> 	mov	cl, 3
  1717 000082E0 BF[3A350100]        <1> 	mov	edi, Cmd_Set
  1718 000082E5 E86D030000          <1> 	call	cmp_cmd	
  1719                              <1> 	;jnc	set_get_env
  1720                              <1> 	; 26/07/2022
  1721 000082EA 720F                <1> 	jc	short cmp_cmd_run
  1722 000082EC E949190000          <1> 	jmp	set_get_env
  1723                              <1> 
  1724                              <1> 	; 07/08/2022
  1725                              <1> c_4:
  1726                              <1> 	; 26/07/2022
  1727 000082F1 80F904              <1> 	cmp	cl, 4
  1728 000082F4 741D                <1> 	je	short cmp_cmd_4
  1729 000082F6 E937020000          <1> 	jmp	c_6
  1730                              <1> 
  1731                              <1> cmp_cmd_run:
  1732 000082FB B103                <1> 	mov	cl, 3
  1733 000082FD BF[36350100]        <1> 	mov	edi, Cmd_Run
  1734 00008302 E850030000          <1> 	call	cmp_cmd	
  1735                              <1> 	; 07/05/2016
  1736                              <1>         ;jc	cmp_cmd_external
  1737                              <1> 	; 26/07/2022
  1738 00008307 7305                <1> 	jnc	short c3_run
  1739 00008309 E92C030000          <1> 	jmp	cmp_cmd_external
  1740                              <1> c3_run:
  1741 0000830E E9481F0000          <1> 	jmp	load_and_execute_file
  1742                              <1> 
  1743                              <1> cmp_cmd_4:
  1744                              <1> 	; 26/07/2022
  1745                              <1> cmp_cmd_exit:
  1746 00008313 BF[10350100]        <1> 	mov	edi, Cmd_Exit
  1747 00008318 E83A030000          <1> 	call	cmp_cmd	
  1748 0000831D 7208                <1> 	jc	short cmp_cmd_date
  1749                              <1> 
  1750 0000831F C605[70850100]01    <1>         mov     byte [Program_Exit], 1
  1751 00008326 C3                  <1>         retn
  1752                              <1> 
  1753                              <1> cmp_cmd_date:
  1754 00008327 B104                <1> 	mov	cl, 4
  1755 00008329 BF[2C350100]        <1> 	mov	edi, Cmd_Date
  1756 0000832E E824030000          <1> 	call	cmp_cmd	
  1757 00008333 720A                <1>         jc	short cmp_cmd_time
  1758                              <1> 	
  1759 00008335 E806F8FFFF          <1> 	call	show_date
  1760                              <1> 	;call	set_date
  1761                              <1> 	;retn
  1762                              <1> 	; 26/07/2022
  1763 0000833A E944F8FFFF          <1> 	jmp	set_date
  1764                              <1> 
  1765                              <1> cmp_cmd_time:
  1766 0000833F B104                <1> 	mov	cl, 4
  1767 00008341 BF[31350100]        <1> 	mov	edi, Cmd_Time
  1768 00008346 E80C030000          <1>    	call	cmp_cmd	
  1769 0000834B 720A                <1> 	jc	short cmp_cmd_show
  1770                              <1> 
  1771 0000834D E894FAFFFF          <1> 	call	show_time
  1772                              <1> 	;call	set_time
  1773                              <1> 	;retn
  1774                              <1> 	; 26/07/2022
  1775 00008352 E9C5FAFFFF          <1> 	jmp	set_time
  1776                              <1> 
  1777                              <1> cmp_cmd_show:
  1778 00008357 B104                <1> 	mov	cl, 4
  1779 00008359 BF[42350100]        <1> 	mov	edi, Cmd_Show
  1780 0000835E E8F4020000          <1>    	call	cmp_cmd	
  1781                              <1>         ;jnc	show_file
  1782                              <1> 	; 26/07/2022
  1783 00008363 7205                <1> 	jc	short cmp_cmd_echo
  1784 00008365 E985090000          <1> 	jmp	show_file
  1785                              <1> 
  1786                              <1> cmp_cmd_echo:
  1787 0000836A B104                <1> 	mov	cl, 4
  1788 0000836C BF[7E350100]        <1> 	mov	edi, Cmd_Echo
  1789 00008371 E8E1020000          <1>    	call	cmp_cmd	
  1790 00008376 7224                <1> 	jc	short cmp_cmd_copy
  1791                              <1> 	
  1792                              <1> 	; 22/11/2017
  1793                              <1> 	; AL = 0
  1794 00008378 803E20              <1> 	cmp	byte [esi], 20h
  1795 0000837B 7215                <1> 	jb	short cmd_echo_nextline
  1796                              <1> 	; 14/04/2016
  1797 0000837D 56                  <1> 	push	esi
  1798                              <1> cmd_echo_asciiz:
  1799                              <1> 	;inc	esi
  1800                              <1> 	;mov	al, [esi]
  1801                              <1> 	; 22/11/2017
  1802 0000837E AC                  <1> 	lodsb
  1803 0000837F 3C20                <1> 	cmp	al, 20h
  1804 00008381 73FB                <1> 	jnb	short cmd_echo_asciiz
  1805 00008383 4E                  <1> 	dec	esi
  1806 00008384 C60600              <1> 	mov	byte [esi], 0
  1807 00008387 5E                  <1> 	pop	esi
  1808 00008388 89F7                <1> 	mov	edi, esi
  1809 0000838A E8DBE9FFFF          <1> 	call	print_msg
  1810 0000838F C60700              <1> 	mov	byte [edi], 0
  1811                              <1> cmd_echo_nextline:
  1812 00008392 BE[953F0100]        <1> 	mov	esi, NextLine
  1813                              <1> 	;call	print_msg
  1814                              <1> 	;retn
  1815 00008397 E9CEE9FFFF          <1> 	jmp	print_msg
  1816                              <1> 
  1817                              <1> cmp_cmd_copy:
  1818 0000839C B104                <1> 	mov	cl, 4
  1819 0000839E BF[65350100]        <1> 	mov	edi, Cmd_Copy
  1820 000083A3 E8AF020000          <1>    	call	cmp_cmd	
  1821                              <1> 	;jnc	copy_file
  1822                              <1> 	; 26/07/2022
  1823 000083A8 7205                <1> 	jc	short cmp_cmd_move
  1824 000083AA E9EC160000          <1> 	jmp	copy_file
  1825                              <1> 
  1826                              <1> cmp_cmd_move:
  1827 000083AF B104                <1> 	mov	cl, 4
  1828 000083B1 BF[6A350100]        <1> 	mov	edi, Cmd_Move
  1829 000083B6 E89C020000          <1>    	call	cmp_cmd	
  1830                              <1> 	;jnc	move_file
  1831                              <1> 	; 26/07/2022
  1832 000083BB 7205                <1> 	jc	short cmp_cmd_path
  1833 000083BD E997150000          <1> 	jmp	move_file
  1834                              <1> 
  1835                              <1> cmp_cmd_path:
  1836 000083C2 B104                <1> 	mov	cl, 4
  1837 000083C4 BF[6F350100]        <1> 	mov	edi, Cmd_Path
  1838 000083C9 E889020000          <1>    	call	cmp_cmd	
  1839                              <1> 	;jnc	set_get_path
  1840                              <1> 	; 26/07/2022
  1841 000083CE 7205                <1> 	jc	short cmp_cmd_beep
  1842 000083D0 E9ED180000          <1> 	jmp	set_get_path
  1843                              <1> 
  1844                              <1> cmp_cmd_beep:
  1845 000083D5 B104                <1> 	mov	cl, 4
  1846 000083D7 BF[9C350100]        <1> 	mov	edi, Cmd_Beep
  1847 000083DC E876020000          <1>    	call	cmp_cmd	
  1848 000083E1 720B                <1> 	jc	short cmp_cmd_find
  1849                              <1> 	; 13/05/2016
  1850 000083E3 8A3D[EE7C0100]      <1> 	mov	bh, [ptty] ; [ACTIVE_PAGE]
  1851 000083E9 E9919FFFFF          <1> 	jmp	beeper
  1852                              <1> 
  1853                              <1> cmp_cmd_find:
  1854 000083EE B104                <1> 	mov	cl, 4
  1855 000083F0 BF[79350100]        <1> 	mov	edi, Cmd_Find
  1856 000083F5 E85D020000          <1>    	call	cmp_cmd	
  1857                              <1>         ;jc	cmp_cmd_external
  1858                              <1> 	; 26/07/2022
  1859 000083FA 7305                <1> 	jnc	short c4_find
  1860 000083FC E939020000          <1> 	jmp	cmp_cmd_external
  1861                              <1> c4_find:
  1862                              <1> 	;call	find_and_list_files
  1863 00008401 E94F210000          <1> 	jmp	find_and_list_files
  1864                              <1> 	;retn
  1865                              <1> 
  1866                              <1> c_1:
  1867 00008406 AD                  <1> 	lodsd
  1868                              <1> cmp_cmd_help:
  1869 00008407 3C3F                <1> 	cmp	al, '?'
  1870 00008409 751D                <1>         jne     short cmp_cmd_remark
  1871                              <1> 
  1872 0000840B BE[02350100]        <1> 	mov	esi, Command_List
  1873                              <1> cmd_help_next_w:
  1874 00008410 E855E9FFFF          <1> 	call	print_msg
  1875                              <1> 
  1876 00008415 803E20              <1> 	cmp	byte [esi], 20h ; 0
  1877 00008418 7233                <1> 	jb	short cmd_help_retn
  1878                              <1> 
  1879 0000841A 56                  <1> 	push	esi
  1880 0000841B BE[273F0100]        <1> 	mov	esi, nextline
  1881 00008420 E845E9FFFF          <1> 	call	print_msg
  1882 00008425 5E                  <1> 	pop	esi
  1883 00008426 EBE8                <1> 	jmp	short cmd_help_next_w
  1884                              <1> 
  1885                              <1> cmp_cmd_remark:
  1886 00008428 3C2A                <1> 	cmp	al, '*'
  1887                              <1> 	;jne	cmp_cmd_external
  1888                              <1> 	; 26/07/2022
  1889 0000842A 7405                <1> 	je	short cmp_cmd_rem
  1890 0000842C E909020000          <1> 	jmp	cmp_cmd_external
  1891                              <1> cmp_cmd_rem:
  1892 00008431 46                  <1> 	inc	esi
  1893 00008432 BF[E47D0100]        <1> 	mov	edi, Remark
  1894 00008437 8A06                <1> 	mov	al, [esi]
  1895 00008439 3C20                <1> 	cmp	al, 20h
  1896 0000843B 7707                <1> 	ja	short cmd_remark_write
  1897 0000843D 89FE                <1> 	mov	esi, edi ; Remark
  1898 0000843F E926E9FFFF          <1> 	jmp	print_msg
  1899                              <1> 
  1900                              <1> cmd_remark_write:
  1901 00008444 AA                  <1> 	stosb
  1902 00008445 AC                  <1> 	lodsb
  1903 00008446 3C20                <1> 	cmp	al, 20h
  1904 00008448 73FA                <1> 	jnb	short cmd_remark_write
  1905 0000844A C60700              <1> 	mov	byte [edi], 0
  1906                              <1> 
  1907                              <1> cmd_help_retn:
  1908                              <1> cmd_remark_retn:
  1909                              <1> cd_retn:
  1910 0000844D C3                  <1> 	retn
  1911                              <1> c_2:
  1912                              <1> 	; 26/07/2022
  1913 0000844E BE[327E0100]        <1> 	mov	esi, CommandBuffer
  1914 00008453 80F902              <1> 	cmp	cl, 2
  1915                              <1> 	;ja	c_3
  1916                              <1> 	;mov	esi, CommandBuffer
  1917 00008456 72AE                <1> 	jb	short c_1
  1918                              <1> 	; 26/07/2022
  1919                              <1> 	;jne	short c_1
  1920                              <1> 
  1921                              <1> cmp_cmd_cd:
  1922 00008458 66AD                <1> 	lodsw
  1923 0000845A 663D4344            <1> 	cmp	ax, 'CD'
  1924 0000845E 754E                <1> 	jne	short cmp_cmd_drive
  1925 00008460 46                  <1>         inc	esi
  1926                              <1> cd_0:
  1927 00008461 668B06              <1> 	mov	ax, [esi]
  1928 00008464 3C20                <1> 	cmp	al, 20h
  1929 00008466 76E5                <1> 	jna	short cd_retn
  1930                              <1> 	; 10/02/2016
  1931 00008468 80FC3A              <1> 	cmp	ah, ':'
  1932 0000846B 7504                <1> 	jne	short cd_1
  1933 0000846D 46                  <1> 	inc	esi
  1934 0000846E 46                  <1> 	inc	esi
  1935 0000846F EB47                <1> 	jmp	short cd_2
  1936                              <1> 
  1937                              <1> cd_1:	; change current directory
  1938                              <1> 	; 29/11/2009
  1939                              <1> 	; AH = CDh	; to separate 'CD' command from others
  1940                              <1> 			; for restoring current directory
  1941                              <1> 			; 0CDh sign is for saving cdir into
  1942                              <1> 			; DOS drv description table cdir area
  1943                              <1> 
  1944 00008471 B4CD                <1> 	mov	ah, 0CDh ; mov byte [CD_COMMAND], 0CDh 
  1945                              <1> 
  1946 00008473 E8B8210000          <1> 	call	change_current_directory
  1947                              <1> 	;jnc	change_prompt_dir_string
  1948                              <1> 	; 26/07/2022
  1949 00008478 7205                <1> 	jc	short cd_error_messages
  1950 0000847A E9DA200000          <1> 	jmp	change_prompt_dir_string
  1951                              <1> 
  1952                              <1> cd_error_messages:
  1953 0000847F 3C03                <1> 	cmp	al, 3
  1954 00008481 740C                <1> 	je	short cd_path_not_found
  1955                              <1> 	; 16/10/2016 (15h -> 15)
  1956 00008483 3C0F                <1> 	cmp	al, 15 ; drive not ready error
  1957 00008485 7453                <1> 	je	short cd_drive_not_ready
  1958 00008487 3C11                <1> 	cmp	al, 17 ; read error
  1959 00008489 744F                <1> 	je	short cd_drive_not_ready
  1960 0000848B 3C13                <1> 	cmp	al, 19 ; ; Bad directory/path name
  1961 0000848D 7460                <1> 	je	short cd_command_failed
  1962                              <1> 
  1963                              <1> cd_path_not_found:
  1964 0000848F 50                  <1> 	push	eax ; 29/12/2017
  1965                              <1> 	;push	ax
  1966 00008490 BE[A5370100]        <1> 	mov	esi, Msg_Dir_Not_Found
  1967 00008495 E8D0E8FFFF          <1> 	call	print_msg
  1968                              <1> 	;pop	ax
  1969 0000849A 58                  <1> 	pop	eax ; 29/12/2017
  1970 0000849B 3A25[807D0100]      <1> 	cmp	ah, [Current_Dir_Level]
  1971                              <1>         ;jnb	change_prompt_dir_string
  1972                              <1> 	; 26/07/2022
  1973 000084A1 7306                <1> 	jnb	short cd_cpds
  1974 000084A3 8825[807D0100]      <1> 	mov	[Current_Dir_Level], ah
  1975                              <1> cd_cpds:
  1976 000084A9 E9AB200000          <1>         jmp     change_prompt_dir_string
  1977                              <1> 
  1978                              <1> cmp_cmd_drive: ; change current drive
  1979                              <1> 	; C:, D:, E: etc.
  1980 000084AE 80FC3A              <1> 	cmp	ah, ':'
  1981                              <1> 	;jne	cmp_cmd_external
  1982                              <1> 	; 26/07/2022
  1983 000084B1 7405                <1> 	je	short cd_2
  1984                              <1> cmd_ext:
  1985 000084B3 E982010000          <1> 	jmp	cmp_cmd_external
  1986                              <1> 
  1987                              <1> cd_2:	; 'CD C:', 'CD D:' ...
  1988 000084B8 803E20              <1> 	cmp	byte [esi], 20h
  1989                              <1> 	;ja	loc_cmd_failed
  1990                              <1> 	; 26/07/2022
  1991 000084BB 7706                <1> 	ja	short cd_failed
  1992 000084BD 24DF                <1> 	and	al, 0DFh
  1993 000084BF 2C41                <1> 	sub	al, 'A'
  1994                              <1> 	;jc	loc_cmd_failed
  1995                              <1> 	; 26/07/2022
  1996 000084C1 7305                <1> 	jnc	short cd_3
  1997                              <1> cd_failed:
  1998 000084C3 E97C010000          <1> 	jmp	loc_cmd_failed
  1999                              <1> cd_3:
  2000 000084C8 3A05[9A340100]      <1>         cmp     al, [Last_DOS_DiskNo]
  2001 000084CE 770A                <1>         ja	short cd_drive_not_ready
  2002                              <1> 	
  2003 000084D0 88C2                <1> 	mov	dl, al
  2004 000084D2 E8A6F3FFFF          <1> 	call 	change_current_drive
  2005 000084D7 7201                <1> 	jc	short cd_drive_not_ready
  2006 000084D9 C3                  <1> 	retn
  2007                              <1> 
  2008                              <1> cd_drive_not_ready:
  2009 000084DA BE[62370100]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
  2010 000084DF E886E8FFFF          <1> 	call	print_msg
  2011                              <1> 
  2012                              <1> cd_fail_drive_restart:
  2013 000084E4 8A15[827D0100]      <1> 	mov	dl, [Current_Drv]
  2014                              <1> 	;call 	change_current_drive
  2015 000084EA E98EF3FFFF          <1>         jmp     change_current_drive
  2016                              <1> 	;retn
  2017                              <1> 
  2018                              <1> cd_command_failed:
  2019 000084EF BE[43370100]        <1> 	mov	esi, Msg_Bad_Command
  2020 000084F4 E871E8FFFF          <1> 	call	print_msg
  2021 000084F9 EBE9                <1> 	jmp	short cd_fail_drive_restart
  2022                              <1> 
  2023                              <1> c_5:
  2024                              <1> cmp_cmd_mkdir:
  2025 000084FB BF[5F350100]        <1> 	mov	edi, Cmd_Mkdir
  2026 00008500 E852010000          <1> 	call	cmp_cmd
  2027                              <1> 	;jnc	make_directory
  2028                              <1> 	; 26/07/2022
  2029 00008505 7205                <1> 	jc	short cmp_cmd_rmdir
  2030 00008507 E99B0A0000          <1> 	jmp	make_directory
  2031                              <1> 
  2032                              <1> cmp_cmd_rmdir:
  2033 0000850C B105                <1> 	mov	cl, 5
  2034 0000850E BF[59350100]        <1> 	mov	edi, Cmd_Rmdir
  2035 00008513 E83F010000          <1> 	call	cmp_cmd	
  2036                              <1> 	;jnc	delete_directory
  2037                              <1> 	; 26/07/2022
  2038 00008518 7205                <1> 	jc	short cmp_cmd_chdir
  2039 0000851A E9A40B0000          <1> 	jmp	delete_directory
  2040                              <1> 
  2041                              <1> cmp_cmd_chdir:
  2042 0000851F B105                <1> 	mov	cl, 5
  2043 00008521 BF[96350100]        <1> 	mov	edi, Cmd_Chdir
  2044 00008526 E82C010000          <1> 	call	cmp_cmd	
  2045                              <1> 	;jc	cmp_cmd_external
  2046                              <1> 	; 26/07/2022
  2047 0000852B 7286                <1> 	jc	short cmd_ext
  2048                              <1> 
  2049 0000852D E92FFFFFFF          <1> 	jmp	cd_0
  2050                              <1> 
  2051                              <1> c_6:
  2052 00008532 80F906              <1> 	cmp	cl, 6
  2053                              <1> 	;ja	c_8
  2054                              <1> 	; 26/07/2022
  2055 00008535 72C4                <1> 	jb	short c_5
  2056 00008537 7405                <1> 	je	short cmd_6
  2057 00008539 E9E4000000          <1> 	jmp	c_8
  2058                              <1> 
  2059                              <1> cmd_6:
  2060                              <1> cmp_cmd_prompt:
  2061 0000853E BF[15350100]        <1> 	mov	edi, Cmd_Prompt
  2062 00008543 E80F010000          <1> 	call	cmp_cmd	
  2063 00008548 722F                <1>         jc	short cmp_cmd_volume
  2064                              <1> get_prompt_name_fchar:
  2065 0000854A AC                  <1> 	lodsb
  2066 0000854B 3C20                <1> 	cmp	al, 20h
  2067 0000854D 74FB                <1> 	je	short get_prompt_name_fchar
  2068 0000854F 7713                <1> 	ja	short loc_change_prompt_label
  2069                              <1> default_command_prompt: ; 31/12/2017 ('sysprompt')
  2070 00008551 BE[F6340100]        <1> 	mov	esi, TRDOSPromptLabel
  2071 00008556 C7065452444F        <1> 	mov	dword [esi], "TRDO"
  2072 0000855C 66C746045300        <1>        	mov	word [esi+4], "S" 
  2073                              <1> loc_cmd_prompt_return:
  2074 00008562 C3                  <1> 	retn
  2075                              <1> 
  2076                              <1> set_command_prompt: ; 31/12/2017 ('sysprompt')
  2077 00008563 AC                  <1> 	lodsb
  2078                              <1> loc_change_prompt_label:
  2079                              <1> 	;mov	cx, 11
  2080                              <1> 	; 26/07/2022
  2081 00008564 29C9                <1> 	sub	ecx, ecx
  2082 00008566 B10B                <1> 	mov	cl, 11
  2083 00008568 BF[F6340100]        <1> 	mov	edi, TRDOSPromptLabel
  2084                              <1> put_char_new_prompt_label:
  2085 0000856D AA                  <1> 	stosb
  2086 0000856E AC                  <1> 	lodsb
  2087 0000856F 3C20                <1> 	cmp	al, 20h
  2088 00008571 7202                <1> 	jb	short pass_put_new_prompt_label
  2089 00008573 E2F8                <1> 	loop	put_char_new_prompt_label
  2090                              <1> pass_put_new_prompt_label:
  2091 00008575 C60700              <1> 	mov	byte [edi], 0
  2092 00008578 C3                  <1> 	retn
  2093                              <1> 
  2094                              <1> cmp_cmd_volume:
  2095 00008579 B106                <1> 	mov	cl, 6
  2096 0000857B BF[1C350100]        <1> 	mov	edi, Cmd_Volume
  2097 00008580 E8D2000000          <1> 	call	cmp_cmd	
  2098 00008585 7259                <1>         jc	short cmp_cmd_attrib
  2099                              <1> 
  2100                              <1> cmd_vol1:
  2101 00008587 AC                  <1> 	lodsb
  2102 00008588 3C20                <1> 	cmp	al, 20h
  2103 0000858A 7707                <1> 	ja	short cmd_vol2
  2104 0000858C A0[827D0100]        <1> 	mov	al, [Current_Drv]
  2105 00008591 EB41                <1> 	jmp	short cmd_vol4
  2106                              <1> cmd_vol2:
  2107 00008593 3C41                <1> 	cmp	al, 'A'
  2108                              <1> 	;jb	loc_cmd_failed
  2109                              <1> 	; 26/07/2022
  2110 00008595 722D                <1> 	jb	short cmd_vol_failed_1
  2111 00008597 3C7A                <1> 	cmp	al, 'z'
  2112                              <1> 	;ja	loc_cmd_failed
  2113                              <1> 	; 26/07/2022
  2114 00008599 7731                <1> 	ja	short cmd_vol_failed_2
  2115 0000859B 3C5A                <1> 	cmp	al, 'Z'
  2116 0000859D 7606                <1> 	jna	short cmd_vol3
  2117 0000859F 3C61                <1> 	cmp	al, 'a'
  2118                              <1>         ;jb	loc_cmd_failed
  2119                              <1> 	; 26/07/2022
  2120 000085A1 722B                <1> 	jb	short cmd_vol_failed_3
  2121 000085A3 24DF                <1> 	and	al, 0DFh
  2122                              <1> cmd_vol3:
  2123 000085A5 8A26                <1> 	mov	ah, [esi]
  2124 000085A7 80FC3A              <1> 	cmp	ah, ':'
  2125 000085AA 0F8594000000        <1>         jne     loc_cmd_failed
  2126 000085B0 2C41                <1> 	sub	al, 'A'
  2127 000085B2 3A05[9A340100]      <1>         cmp     al, [Last_DOS_DiskNo]
  2128 000085B8 761A                <1> 	jna	short cmd_vol4
  2129                              <1> 
  2130 000085BA BE[62370100]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
  2131 000085BF E9A6E7FFFF          <1> 	jmp	print_msg
  2132                              <1> 
  2133                              <1> 	; 26/07/2022
  2134                              <1> 	; (numeric characters and underscore are allowed)
  2135                              <1> cmd_vol_failed_1:
  2136                              <1> 	; check for numeric characters
  2137 000085C4 3C30                <1> 	cmp	al, '0'
  2138 000085C6 7204                <1> 	jb	short cmd_vol_failed_2
  2139 000085C8 3C39                <1> 	cmp	al, '9'
  2140 000085CA 76D9                <1> 	jna	short cmd_vol3
  2141                              <1> cmd_vol_failed_2:
  2142 000085CC EB76                <1> 	jmp	loc_cmd_failed
  2143                              <1> cmd_vol_failed_3:
  2144 000085CE 3C5F                <1> 	cmp	al, '_' ; underline ?
  2145 000085D0 74D3                <1> 	je	short cmd_vol3 ; is ok..
  2146 000085D2 EBF8                <1> 	jmp	short cmd_vol_failed_2
  2147                              <1> 
  2148                              <1> cmd_vol4:
  2149 000085D4 E889FAFFFF          <1> 	call	print_volume_info
  2150                              <1> 	;jc	cd_drive_not_ready
  2151                              <1> 	; 26/07/2022
  2152 000085D9 7339                <1> 	jnc	short cmd_vol5
  2153 000085DB E9FAFEFFFF          <1> 	jmp	cd_drive_not_ready
  2154                              <1> ;cmd_vol5:
  2155                              <1> ;	retn
  2156                              <1> 
  2157                              <1> cmp_cmd_attrib:
  2158 000085E0 B106                <1> 	mov	cl, 6
  2159 000085E2 BF[4B350100]        <1> 	mov	edi, Cmd_Attrib
  2160 000085E7 E86B000000          <1> 	call	cmp_cmd	
  2161                              <1> 	;jnc	set_file_attributes
  2162                              <1> 	; 26/07/2022
  2163 000085EC 7205                <1> 	jc	short cmp_cmd_rename
  2164 000085EE E9F70E0000          <1> 	jmp	set_file_attributes
  2165                              <1> 
  2166                              <1> cmp_cmd_rename:
  2167 000085F3 B106                <1> 	mov	cl, 6
  2168 000085F5 BF[52350100]        <1> 	mov	edi, Cmd_Rename
  2169 000085FA E858000000          <1> 	call	cmp_cmd	
  2170                              <1> 	;jnc	rename_file
  2171                              <1> 	; 26/07/2022
  2172 000085FF 7205                <1> 	jc	short cmp_cmd_device
  2173 00008601 E918110000          <1> 	jmp	rename_file
  2174                              <1> 
  2175                              <1> cmp_cmd_device:
  2176 00008606 B106                <1> 	mov	cl, 6
  2177 00008608 BF[87350100]        <1> 	mov	edi, Cmd_Device
  2178 0000860D E845000000          <1> 	call	cmp_cmd	
  2179 00008612 7226                <1> 	jc	short cmp_cmd_external
  2180                              <1> 	; 26/07/2022
  2181                              <1> cmd_vol5:
  2182                              <1> cmd_dev:
  2183 00008614 C3                  <1> 	retn
  2184                              <1> 
  2185                              <1> c_7:
  2186                              <1> cmp_cmd_devlist:
  2187 00008615 BF[8E350100]        <1> 	mov	edi, Cmd_DevList
  2188 0000861A E838000000          <1> 	call	cmp_cmd	
  2189 0000861F 7219                <1>         jc	short cmp_cmd_external
  2190                              <1> 
  2191                              <1> loc_cmd_return:
  2192 00008621 C3                  <1> 	retn
  2193                              <1> 
  2194                              <1> c_8:
  2195 00008622 80F908              <1>         cmp	cl, 8
  2196 00008625 7713                <1> 	ja	short cmp_cmd_external
  2197 00008627 72EC                <1> 	jb	short c_7
  2198                              <1> 
  2199                              <1> cmp_cmd_longname:
  2200 00008629 BF[23350100]        <1> 	mov	edi, Cmd_LongName
  2201 0000862E E824000000          <1> 	call	cmp_cmd	
  2202                              <1> 	;jnc	get_and_print_longname
  2203                              <1> 	; 26/07/2022
  2204 00008633 7205                <1> 	jc	short cmp_cmd_external
  2205 00008635 E962060000          <1> 	jmp	get_and_print_longname
  2206                              <1> 
  2207                              <1> cmp_cmd_external:
  2208                              <1> 	; 07/05/2016
  2209                              <1> 	; 22/04/2016
  2210 0000863A BE[327E0100]        <1> 	mov	esi, CommandBuffer
  2211 0000863F E9171C0000          <1> 	jmp	loc_run_check_filename
  2212                              <1> 
  2213                              <1> loc_cmd_failed:
  2214 00008644 803D[327E0100]20    <1> 	cmp	byte [CommandBuffer], 20h
  2215 0000864B 76D4                <1> 	jna	short loc_cmd_return
  2216 0000864D BE[43370100]        <1> 	mov	esi, Msg_Bad_Command
  2217                              <1> ;	call	print_msg
  2218                              <1> ;loc_cmd_return:
  2219                              <1> ;	retn
  2220 00008652 E913E7FFFF          <1> 	jmp	print_msg
  2221                              <1> 
  2222                              <1> cmp_cmd:
  2223                              <1> 	; 26/07/2022 (TRDOS 386 Kernel v2.0.5)
  2224                              <1> 	; 29/01/2016 (TRDOS 386 = TRDOS v2.0)
  2225 00008657 BE[327E0100]        <1>         mov	esi, CommandBuffer
  2226                              <1>         ; edi = internal command word (ASCIIZ)
  2227                              <1> 	; ecx = command length (<=8)
  2228                              <1> cmp_cmd_1:
  2229 0000865C AC                  <1> 	lodsb
  2230 0000865D AE                  <1> 	scasb
  2231 0000865E 750D                <1> 	jne	short cmp_cmd_3
  2232 00008660 E2FA                <1> 	loop	cmp_cmd_1
  2233 00008662 AC                  <1>  	lodsb
  2234 00008663 3C20                <1> 	cmp	al, 20h
  2235 00008665 7703                <1> 	ja	short cmp_cmd_2
  2236 00008667 30C0                <1> 	xor	al, al
  2237                              <1> 	; ZF = 1 -> internal command word matches
  2238 00008669 C3                  <1> 	retn
  2239                              <1> cmp_cmd_2:
  2240                              <1> 	; ZF = 0 (CF = 0) -> external command word
  2241 0000866A 58                  <1> 	pop	eax ; no return to the caller from here 
  2242 0000866B EBCD                <1> 	jmp	short cmp_cmd_external ; 26/07/2022
  2243                              <1> cmp_cmd_3:
  2244 0000866D F9                  <1> 	stc
  2245                              <1> 	; CF = 1 -> internal command word does not match
  2246 0000866E C3                  <1> 	retn
  2247                              <1> 
  2248                              <1> loc_run_cmd_failed:
  2249                              <1> 	; 26/07/2022 (TRDOS 386 Kernel v2.0.5)
  2250                              <1> 	; 15/03/2016
  2251                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
  2252                              <1> 	; 07/12/2009 (CMD_INTR.ASM)
  2253                              <1> 	; 29/11/2009
  2254                              <1> 
  2255 0000866F E863000000          <1> 	call	restore_cdir_after_cmd_fail
  2256                              <1> 
  2257                              <1> loc_run_cmd_failed_cmp_al:
  2258                              <1> 	; End of Restore_CDIR code (29/11/2009)
  2259                              <1> 
  2260 00008674 3C01                <1> 	cmp	al, 1 ; Bad command or file name
  2261 00008676 74CC                <1> 	je	short loc_cmd_failed ; 26/07/2022
  2262                              <1> loc_run_dir_not_found:
  2263 00008678 3C03                <1> 	cmp	al, 3
  2264 0000867A 750A                <1> 	jne	short loc_run_file_notfound_msg
  2265                              <1> 	; Path not found (MS-DOS Error Code = 3)
  2266 0000867C BE[A5370100]        <1> 	mov	esi, Msg_Dir_Not_Found
  2267 00008681 E9E4E6FFFF          <1> 	jmp	print_msg
  2268                              <1> 
  2269                              <1> loc_run_file_notfound_msg:
  2270 00008686 3C02                <1> 	cmp	al, 2 ; File not found
  2271 00008688 750A                <1> 	jne	short loc_run_file_drv_read_err
  2272                              <1> 
  2273                              <1> loc_print_file_notfound_msg:
  2274 0000868A BE[BC370100]        <1>         mov     esi, Msg_File_Not_Found
  2275                              <1> 	;call	proc_printmsg
  2276                              <1> 	;retn
  2277 0000868F E9D6E6FFFF          <1> 	jmp	print_msg
  2278                              <1> 
  2279                              <1> loc_run_file_drv_read_err:
  2280                              <1> 	; Err: 17 (Read fault)
  2281 00008694 3C11                <1> 	cmp	al, 17 ; Drive not ready or read error
  2282 00008696 7404                <1> 	je	short loc_run_file_print_drv_read_err
  2283                              <1> 	;
  2284 00008698 3C0F                <1> 	cmp	al, 15 ; Drive not ready (or read error)
  2285 0000869A 750A                <1> 	jne	short loc_run_file_toobig
  2286                              <1> 
  2287                              <1> loc_run_file_print_drv_read_err:
  2288 0000869C BE[62370100]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
  2289 000086A1 E9C4E6FFFF          <1> 	jmp	print_msg
  2290                              <1> 
  2291                              <1> loc_run_file_toobig:
  2292 000086A6 3C08                <1> 	cmp	al, 8 ; Not enough free memory to load&run file
  2293 000086A8 750A                <1> 	jne	short loc_run_file_perm_denied
  2294 000086AA BE[07380100]        <1> 	mov	esi, Msg_Insufficient_Memory
  2295 000086AF E9B6E6FFFF          <1> 	jmp	print_msg
  2296                              <1> 
  2297                              <1> loc_run_file_perm_denied:
  2298                              <1> 	; 29/12/2017
  2299 000086B4 3C0B                <1> 	cmp	al, ERR_PERM_DENIED ; 11 ; Permission denied
  2300 000086B6 750A                <1> 	jne	short loc_run_misc_error
  2301 000086B8 BE[9C390100]        <1> 	mov	esi, Msg_Permission_Denied
  2302 000086BD E9A8E6FFFF          <1> 	jmp	print_msg
  2303                              <1> 
  2304                              <1> 	; 15/03/2016
  2305                              <1> print_misc_error_msg:
  2306                              <1> loc_run_misc_error:
  2307                              <1> 	; AL = Error code
  2308 000086C2 E8AEBAFFFF          <1> 	call	bytetohex
  2309 000086C7 66A3[3B380100]      <1>         mov     [error_code_hex], ax
  2310                              <1> 	
  2311 000086CD BE[1E380100]        <1> 	mov	esi, Msg_Error_Code 
  2312                              <1> 	;call	print_msg 
  2313                              <1> 	;retn
  2314 000086D2 E993E6FFFF          <1> 	jmp	print_msg
  2315                              <1> 
  2316                              <1> restore_cdir_after_cmd_fail:
  2317                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
  2318 000086D7 50                  <1> 	push	eax
  2319 000086D8 8A3D[DF840100]      <1> 	mov	bh, [RUN_CDRV] ; it is set at the beginning
  2320                              <1> 				; of the 'run' command.
  2321 000086DE 3A3D[827D0100]      <1> 	cmp	bh, [Current_Drv]
  2322 000086E4 7409                <1> 	je	short loc_run_restore_cdir
  2323 000086E6 88FA                <1> 	mov	dl, bh
  2324 000086E8 E890F1FFFF          <1> 	call	change_current_drive 
  2325 000086ED EB19                <1> 	jmp	short loc_run_err_pass_restore_cdir
  2326                              <1> 
  2327                              <1> loc_run_restore_cdir:
  2328 000086EF 803D[9B340100]00    <1> 	cmp	byte [Restore_CDIR], 0
  2329 000086F6 7610                <1> 	jna	short loc_run_err_pass_restore_cdir
  2330 000086F8 30DB                <1> 	xor	bl, bl
  2331 000086FA 0FB7F3              <1> 	movzx	esi, bx
  2332 000086FD 81C600010900        <1> 	add	esi, Logical_DOSDisks
  2333 00008703 E82BF2FFFF          <1> 	call	restore_current_directory
  2334                              <1> 
  2335                              <1> loc_run_err_pass_restore_cdir:
  2336 00008708 58                  <1> 	pop	eax
  2337 00008709 C3                  <1> 	retn
  2338                              <1> 
  2339                              <1> print_directory_list:
  2340                              <1> 	; 02/12/2023 (TRDOS 386 v2.0.7)
  2341                              <1> 	; 07/08/2022
  2342                              <1> 	; 27/07/2022 (TRDOS 386 Kernel v2.0.5)
  2343                              <1> 	; 10/02/2016
  2344                              <1> 	; 08/02/2016 (TRDOS 386 = TRDOS v2.0)
  2345                              <1> 	; 06/12/2009 ('cmp_cmd_dir')	
  2346                              <1> 	;
  2347 0000870A 66C705[20860100]00- <1> 	mov	word [AttributesMask], 0800h ; ..except volume names..
  2347 00008712 08                  <1>
  2348 00008713 A0[827D0100]        <1> 	mov	al, [Current_Drv]
  2349 00008718 A2[DF840100]        <1> 	mov	[RUN_CDRV], al
  2350                              <1> 	; 02/12/2023
  2351 0000871D 3C02                <1> 	cmp	al, 2
  2352 0000871F 733A                <1> 	jnb	short get_dfname_fchar
  2353 00008721 A0[417D0100]        <1> 	mov	al, [TIMER_LOW+1]
  2354 00008726 D0E8                <1> 	shr	al, 1	; 512/18.2 (>= 28 seconds)
  2355 00008728 8605[A6840100]      <1> 	xchg	al, [P_TIMER]  ; 28 seconds
  2356 0000872E 3A05[A6840100]      <1> 	cmp	al, [P_TIMER]
  2357 00008734 7425                <1> 	je	short get_dfname_fchar
  2358 00008736 E830F1FFFF          <1> 	call	get_media_change_status
  2359 0000873B 7205                <1> 	jc	short pdl_chdrv
  2360 0000873D 80FC06              <1> 	cmp	ah, 6
  2361 00008740 7519                <1> 	jne	short get_dfname_fchar
  2362                              <1> pdl_chdrv:
  2363 00008742 56                  <1> 	push	esi
  2364 00008743 8A15[DF840100]      <1> 	mov	dl, [RUN_CDRV]
  2365 00008749 E82FF1FFFF          <1> 	call	change_current_drive
  2366 0000874E 5E                  <1> 	pop	esi
  2367 0000874F 730A                <1> 	jnc	short get_dfname_fchar
  2368 00008751 BE[62370100]        <1> 	mov	esi, Msg_Not_Ready_Read_Err
  2369                              <1> 	;call	print_msg
  2370                              <1> 	;retn
  2371 00008756 E90FE6FFFF          <1> 	jmp	print_msg
  2372                              <1> 
  2373                              <1> get_dfname_fchar:
  2374 0000875B AC                  <1> 	lodsb
  2375 0000875C 3C20                <1> 	cmp	al, 20h
  2376 0000875E 74FB                <1> 	je	short get_dfname_fchar
  2377                              <1> 	;jb	loc_print_dir_call_all
  2378                              <1> 	; 02/12/2023
  2379 00008760 7705                <1> 	ja	short get_dfname_fchar_2
  2380 00008762 E9E0000000          <1> 	jmp	loc_print_dir_call_all
  2381                              <1> get_dfname_fchar_2:
  2382 00008767 3C2D                <1> 	cmp	al, '-'
  2383 00008769 753C                <1> 	jne	short loc_print_dir_call_flt
  2384                              <1> get_next_attr_char:
  2385 0000876B AC                  <1> 	lodsb
  2386 0000876C 3C20                <1> 	cmp	al, 20h
  2387 0000876E 74FB                <1> 	je	short get_next_attr_char
  2388                              <1> 	;jb	loc_cmd_failed
  2389                              <1> 	; 27/07/2022
  2390 00008770 7305                <1> 	jnb	short pdl_1
  2391                              <1> pdl_0:
  2392 00008772 E9CDFEFFFF          <1> 	jmp	loc_cmd_failed
  2393                              <1> pdl_1:
  2394 00008777 24DF                <1> 	and	al, 0DFh
  2395 00008779 3C44                <1> 	cmp	al, 'D' ; directories only ?
  2396 0000877B 750E                <1> 	jne	short pass_only_directories
  2397 0000877D AC                  <1> 	lodsb
  2398 0000877E 3C20                <1> 	cmp	al, 20h
  2399                              <1> 	;ja	loc_cmd_failed
  2400                              <1> 	; 27/07/2022
  2401 00008780 77F0                <1> 	ja	short pdl_0
  2402 00008782 800D[20860100]10    <1> 	or	byte [AttributesMask], 10h ; ..directory..
  2403 00008789 EB10                <1> 	jmp	short get_dfname_fchar_attr
  2404                              <1> pass_only_directories:
  2405 0000878B 3C46                <1> 	cmp	al, 'F'	; files only ?
  2406 0000878D 7530                <1> 	jne	short check_attr_s ; 27/07/2022
  2407 0000878F AC                  <1> 	lodsb
  2408 00008790 3C20                <1> 	cmp	al, 20h
  2409                              <1> 	;ja	loc_cmd_failed
  2410                              <1> 	; 27/07/2022
  2411 00008792 77DE                <1> 	ja	short pdl_0
  2412 00008794 800D[21860100]10    <1> 	or	byte [AttributesMask+1], 10h ; ..except directories..
  2413                              <1> get_dfname_fchar_attr:
  2414 0000879B AC                  <1> 	lodsb
  2415 0000879C 3C20                <1> 	cmp	al, 20h
  2416 0000879E 74FB                <1> 	je	short get_dfname_fchar_attr
  2417                              <1> 	;jb	short loc_print_dir_call_all
  2418                              <1> 	; 07/08/2022
  2419 000087A0 7305                <1> 	jnb	short loc_print_dir_call_flt
  2420 000087A2 E9A0000000          <1> 	jmp	loc_print_dir_call_all
  2421                              <1> loc_print_dir_call_flt:
  2422 000087A7 4E                  <1> 	dec	esi
  2423 000087A8 BF[22860100]        <1> 	mov	edi, FindFile_Drv
  2424 000087AD E868240000          <1> 	call	parse_path_name
  2425 000087B2 7352                <1>  	jnc	short loc_print_dir_change_drv_1
  2426 000087B4 3C01                <1> 	cmp	al, 1
  2427                              <1> 	;ja	loc_run_cmd_failed
  2428                              <1> 	; 27/07/2022
  2429 000087B6 764E                <1> 	jna	short loc_print_dir_change_drv_1
  2430                              <1> pdl_2:
  2431 000087B8 E9B2FEFFFF          <1> 	jmp	loc_run_cmd_failed
  2432                              <1> 
  2433                              <1> 	; 27/07/2022
  2434                              <1> check_attr_s_cap:
  2435 000087BD 24DF                <1> 	and	al, 0DFh
  2436                              <1> check_attr_s:
  2437 000087BF 3C53                <1> 	cmp	al, 'S'
  2438 000087C1 7510                <1> 	jne	short pass_attr_s
  2439 000087C3 800D[20860100]04    <1> 	or	byte [AttributesMask], 4 ; system
  2440 000087CA AC                  <1> 	lodsb
  2441 000087CB 3C20                <1> 	cmp	al, 20h
  2442 000087CD 74CC                <1> 	je	short get_dfname_fchar_attr
  2443 000087CF 7276                <1> 	jb	short loc_print_dir_call_all
  2444 000087D1 24DF                <1> 	and	al, 0DFh
  2445                              <1> pass_attr_s:
  2446 000087D3 3C48                <1> 	cmp	al, 'H'
  2447 000087D5 7510                <1> 	jne	short pass_attr_h
  2448 000087D7 800D[20860100]02    <1> 	or	byte [AttributesMask], 2 ; hidden
  2449                              <1> pass_attr_shr:
  2450 000087DE AC                  <1> 	lodsb
  2451 000087DF 3C20                <1> 	cmp	al, 20h
  2452 000087E1 74B8                <1> 	je	short get_dfname_fchar_attr
  2453 000087E3 7262                <1> 	jb	short loc_print_dir_call_all
  2454 000087E5 EBD6                <1> 	jmp	short check_attr_s_cap
  2455                              <1> pass_attr_h:
  2456 000087E7 3C52                <1> 	cmp	al, 'R'
  2457 000087E9 7509                <1> 	jne	short pass_attr_r
  2458 000087EB 800D[20860100]01    <1> 	or	byte [AttributesMask], 1 ; read only
  2459 000087F2 EBEA                <1> 	jmp	short pass_attr_shr
  2460                              <1> pass_attr_r:
  2461 000087F4 3C41                <1> 	cmp	al, 'A'
  2462                              <1> 	;jne	loc_cmd_failed
  2463                              <1> 	; 27/07/2022
  2464 000087F6 7405                <1> 	je	short pass_attr_a
  2465 000087F8 E947FEFFFF          <1> 	jmp	loc_cmd_failed
  2466                              <1> pass_attr_a:
  2467 000087FD 800D[20860100]20    <1> 	or	byte [AttributesMask], 20h ; archive
  2468 00008804 EBD8                <1> 	jmp	short pass_attr_shr
  2469                              <1> 
  2470                              <1> 	; 07/08/2022
  2471                              <1> loc_print_dir_change_drv_1:
  2472 00008806 8A15[22860100]      <1> 	mov	dl, [FindFile_Drv]
  2473                              <1> loc_print_dir_change_drv_2:
  2474 0000880C 3A15[DF840100]      <1> 	cmp	dl, [RUN_CDRV]
  2475 00008812 7407                <1> 	je	short loc_print_dir_change_directory 
  2476 00008814 E864F0FFFF          <1> 	call	change_current_drive
  2477                              <1>         ;jc	loc_run_cmd_failed
  2478                              <1> 	; 27/07/2022
  2479 00008819 729D                <1> 	jc	short pdl_2
  2480                              <1> loc_print_dir_change_directory:
  2481 0000881B 803D[23860100]20    <1> 	cmp	byte [FindFile_Directory], 20h ; 0 or 20h ?
  2482 00008822 7619                <1> 	jna	short pass_print_dir_change_directory
  2483                              <1> 
  2484 00008824 FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  2485 0000882A BE[23860100]        <1> 	mov	esi, FindFile_Directory
  2486 0000882F 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0 
  2487 00008831 E8FA1D0000          <1> 	call	change_current_directory
  2488                              <1>         ;jc	loc_run_cmd_failed
  2489                              <1> 	; 27/07/2022
  2490 00008836 7280                <1> 	jc	short pdl_2
  2491                              <1> 
  2492                              <1> loc_print_dir_change_prompt_dir_string:
  2493 00008838 E81C1D0000          <1> 	call	change_prompt_dir_string
  2494                              <1> 
  2495                              <1> pass_print_dir_change_directory:
  2496 0000883D BE[64860100]        <1> 	mov	esi, FindFile_Name
  2497 00008842 803E20              <1> 	cmp	byte [esi], 20h ; ; 0 or 20h ?
  2498 00008845 7706                <1> 	ja	short loc_print_dir_call
  2499                              <1> 
  2500                              <1> loc_print_dir_call_all:
  2501 00008847 C7062A2E2A00        <1> 	mov	dword [esi], '*.*'
  2502                              <1> loc_print_dir_call:
  2503 0000884D E82D000000          <1> 	call	print_directory
  2504                              <1> 
  2505 00008852 8A15[DF840100]      <1> 	mov	dl, [RUN_CDRV]  ; it is set at the beginning
  2506 00008858 3A15[827D0100]      <1> 	cmp	dl, [Current_Drv]
  2507 0000885E 7405                <1> 	je	short loc_print_dir_call_restore_cdir_retn
  2508                              <1> 	;call	change_current_drive
  2509                              <1> 	;retn
  2510                              <1> 	; 27/07/2022
  2511 00008860 E918F0FFFF          <1> 	jmp	change_current_drive
  2512                              <1> 
  2513                              <1> loc_print_dir_call_restore_cdir_retn:
  2514 00008865 803D[9B340100]00    <1> 	cmp	byte [Restore_CDIR], 0
  2515 0000886C 7610                <1> 	jna	short pass_print_dir_call_restore_cdir_retn
  2516                              <1> 
  2517 0000886E BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2518 00008873 31C0                <1> 	xor	eax, eax
  2519 00008875 88D4                <1> 	mov	ah, dl
  2520 00008877 01C6                <1> 	add	esi, eax
  2521                              <1> 
  2522                              <1> 	;call	restore_current_directory
  2523                              <1> 	; 27/07/2022
  2524 00008879 E9B5F0FFFF          <1> 	jmp	restore_current_directory
  2525                              <1> 
  2526                              <1> pass_print_dir_call_restore_cdir_retn:
  2527 0000887E C3                  <1> 	retn
  2528                              <1> 
  2529                              <1> print_directory:
  2530                              <1> 	; 27/07/2022 (TRDOS 386 Kernel v2.0.5)
  2531                              <1> 	; 13/05/2016
  2532                              <1> 	; 11/02/2016
  2533                              <1> 	; 10/02/2016
  2534                              <1> 	; 08/02/2016 (TRDOS 386 = TRDOS v2.0)
  2535                              <1> 	; 30/10/2010 ('proc_print_directory')
  2536                              <1> 	; 19/09/2009
  2537                              <1> 	; 2005 
  2538                              <1> 	; INPUT ->
  2539                              <1> 	;	ESI = Asciiz File/Dir Name Address
  2540                              <1> 
  2541 0000887F 56                  <1> 	push	esi
  2542                              <1> 
  2543 00008880 29C0                <1> 	sub	eax, eax
  2544                              <1> 
  2545 00008882 66A3[AC860100]      <1> 	mov	[Dir_Count], ax ; 0
  2546 00008888 66A3[AA860100]      <1> 	mov 	[File_Count], ax ; 0
  2547 0000888E A3[AE860100]        <1> 	mov 	[Total_FSize], eax ; 0
  2548                              <1> 
  2549 00008893 E8E8E4FFFF          <1> 	call    clear_screen
  2550                              <1> 
  2551 00008898 31C9                <1> 	xor	ecx, ecx
  2552 0000889A 8A2D[827D0100]      <1> 	mov     ch, [Current_Drv] ; DirBuff_Drv - 'A'
  2553 000088A0 A0[837D0100]        <1> 	mov     al, [Current_Dir_Drv] 
  2554 000088A5 A2[60360100]        <1> 	mov     [Dir_Drive_Name], al
  2555 000088AA BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2556 000088AF 01CE                <1> 	add	esi, ecx
  2557                              <1> 
  2558 000088B1 E826F9FFFF          <1> 	call	move_volume_name_and_serial_no
  2559 000088B6 730C                <1> 	jnc	short print_dir_strlen_check
  2560                              <1> 
  2561 000088B8 5E                  <1> 	pop	esi
  2562 000088B9 8A3D[EE7C0100]      <1> 	mov	bh, [ptty] ; [ACTIVE_PAGE]
  2563                              <1> 	;call	beeper
  2564                              <1> 	;retn
  2565 000088BF E9BB9AFFFF          <1> 	jmp	beeper  ; beep ! and return
  2566                              <1> 
  2567                              <1> print_dir_strlen_check:
  2568 000088C4 BE[857D0100]        <1> 	mov	esi, Current_Dir_Root
  2569 000088C9 BF[FD360100]        <1> 	mov	edi, Dir_Str_Root
  2570                              <1> 	
  2571                              <1> 	;xor	ecx, ecx
  2572 000088CE 8A0D[E17D0100]      <1>         mov     cl, [Current_Dir_StrLen]
  2573 000088D4 FEC1                <1> 	inc	cl
  2574 000088D6 80F940              <1> 	cmp	cl, 64
  2575 000088D9 760D                <1> 	jna	short pass_print_dir_strlen_shorting
  2576 000088DB 46                  <1> 	inc	esi
  2577 000088DC 01CE                <1> 	add	esi, ecx
  2578 000088DE 83EE40              <1> 	sub	esi, 64 
  2579 000088E1 47                  <1> 	inc	edi
  2580 000088E2 B82E2E2E20          <1> 	mov	eax, '... '
  2581 000088E7 AB                  <1> 	stosd
  2582                              <1>  
  2583                              <1> pass_print_dir_strlen_shorting:
  2584 000088E8 F3A4                <1> 	rep	movsb
  2585                              <1> 
  2586 000088EA BE[53360100]        <1> 	mov	esi, Dir_Drive_Str
  2587 000088EF E876E4FFFF          <1> 	call	print_msg
  2588                              <1> 
  2589 000088F4 BE[B2360100]        <1> 	mov	esi, Vol_Serial_Header
  2590 000088F9 E86CE4FFFF          <1> 	call	print_msg
  2591                              <1> 
  2592 000088FE BE[F2360100]        <1> 	mov	esi, Dir_Str_Header
  2593 00008903 E862E4FFFF          <1> 	call	print_msg
  2594                              <1> 	
  2595 00008908 BE[253F0100]        <1> 	mov	esi, next2line
  2596 0000890D E858E4FFFF          <1> 	call	print_msg
  2597                              <1> 
  2598                              <1> loc_print_dir_first_file:
  2599 00008912 C605[C1860100]10    <1> 	mov	byte [PrintDir_RowCounter], 16
  2600 00008919 66A1[20860100]      <1> 	mov	ax, [AttributesMask]
  2601 0000891F 5E                  <1> 	pop	esi
  2602                              <1> 
  2603 00008920 E845020000          <1> 	call	find_first_file
  2604                              <1> 	;jc	loc_dir_ok
  2605                              <1> 	; 27/07/2022
  2606 00008925 7305                <1> 	jnc	short loc_dfname_use_this
  2607 00008927 E97B010000          <1> 	jmp	loc_dir_ok
  2608                              <1> 	 
  2609                              <1> loc_dfname_use_this:
  2610                              <1> 	; bl =	File Attributes (bh = Long Name Entry Length)
  2611 0000892C F6C310              <1> 	test	bl, 10h  ; Is it a directory?
  2612 0000892F 741B                <1> 	jz	short loc_not_dir
  2613                              <1> 
  2614 00008931 66FF05[AC860100]    <1> 	inc	word [Dir_Count]
  2615 00008938 89F2                <1> 	mov	edx, esi 	; FindFile_DirEntry address
  2616 0000893A BE[42380100]        <1>  	mov	esi, Type_Dir	; '<DIR>     '
  2617 0000893F BF[59380100]        <1> 	mov	edi, Dir_Or_FileSize
  2618                              <1> 	; move 10 bytes
  2619 00008944 A5                  <1> 	movsd
  2620 00008945 A5                  <1> 	movsd
  2621 00008946 66A5                <1> 	movsw
  2622 00008948 89D6                <1> 	mov	esi, edx
  2623 0000894A EB36                <1> 	jmp     short loc_dir_attribute
  2624                              <1> 
  2625                              <1> loc_not_dir:
  2626 0000894C 66FF05[AA860100]    <1> 	inc	word [File_Count]
  2627 00008953 0105[AE860100]      <1> 	add	[Total_FSize], eax
  2628                              <1> 
  2629 00008959 B90A000000          <1> 	mov	ecx, 10  ; 32 bit divisor
  2630 0000895E 89CF                <1> 	mov	edi, ecx
  2631 00008960 81C7[59380100]      <1> 	add	edi, Dir_Or_FileSize
  2632                              <1> loc_dir_rdivide:
  2633 00008966 29D2                <1> 	sub	edx, edx
  2634 00008968 F7F1                <1> 	div	ecx 	 ; remainder in dl (< 10)
  2635 0000896A 80C230              <1> 	add     dl, '0'	 ; to make visible (ascii)
  2636 0000896D 4F                  <1> 	dec	edi
  2637 0000896E 8817                <1> 	mov     [edi], dl
  2638 00008970 21C0                <1> 	and	eax, eax
  2639 00008972 75F2                <1> 	jnz	short loc_dir_rdivide
  2640                              <1> 
  2641                              <1> loc_dir_fill_space:
  2642 00008974 81FF[59380100]      <1> 	cmp     edi, Dir_Or_FileSize
  2643 0000897A 7606                <1> 	jna     short loc_dir_attribute
  2644 0000897C 4F                  <1> 	dec     edi
  2645 0000897D C60720              <1> 	mov     byte [edi], 20h
  2646 00008980 EBF2                <1> 	jmp     short loc_dir_fill_space
  2647                              <1> 
  2648                              <1> loc_dir_attribute:
  2649 00008982 C705[64380100]2020- <1> 	mov	dword [File_Attribute], 20202020h
  2649 0000898A 2020                <1>
  2650                              <1> 
  2651 0000898C 80FB20              <1> 	cmp	bl, 20h  ; Is it an archive file?
  2652 0000898F 7207                <1> 	jb	short loc_dir_pass_arch
  2653 00008991 C605[67380100]41    <1> 	mov	byte [File_Attribute+3], 'A'
  2654                              <1> 
  2655                              <1> loc_dir_pass_arch:
  2656 00008998 80E307              <1> 	and	bl, 7
  2657 0000899B 7428                <1> 	jz	short loc_dir_file_name
  2658 0000899D 88DF                <1> 	mov	bh, bl
  2659 0000899F 80E303              <1> 	and	bl, 3
  2660 000089A2 38DF                <1> 	cmp	bh, bl
  2661 000089A4 7607                <1> 	jna	short loc_dir_pass_s
  2662 000089A6 C605[64380100]53    <1> 	mov	byte [File_Attribute], 'S'
  2663                              <1> 
  2664                              <1> loc_dir_pass_s:
  2665 000089AD 80E302              <1> 	and     bl,2
  2666 000089B0 7407                <1> 	jz      short loc_dir_pass_h
  2667 000089B2 C605[65380100]48    <1> 	mov     byte [File_Attribute+1], 'H'
  2668                              <1> loc_dir_pass_h:
  2669 000089B9 80E701              <1> 	and     bh,1
  2670 000089BC 7407                <1> 	jz      short loc_dir_file_name
  2671 000089BE C605[66380100]52    <1> 	mov     byte [File_Attribute+2], 'R'
  2672                              <1> loc_dir_file_name:
  2673                              <1> 	;mov	bx, [esi+18h] ; Date
  2674                              <1> 	;mov	dx, [esi+16h] ; Time
  2675 000089C5 8B5E16              <1> 	mov	ebx, [esi+16h]
  2676 000089C8 89F1                <1> 	mov	ecx, esi ; FindFile_DirEntry address
  2677 000089CA BF[4C380100]        <1> 	mov     edi, File_Name
  2678                              <1> 	; move 8 bytes
  2679 000089CF A5                  <1> 	movsd
  2680 000089D0 A5                  <1> 	movsd
  2681 000089D1 C60720              <1> 	mov	byte [edi], 20h
  2682 000089D4 47                  <1> 	inc	edi
  2683                              <1> 	; move 3 bytes
  2684 000089D5 66A5                <1> 	movsw
  2685 000089D7 A4                  <1> 	movsb
  2686 000089D8 89CE                <1> 	mov	esi, ecx
  2687                              <1> 
  2688                              <1> Dir_Time_start:
  2689                              <1> 	;mov	ax, dx		; Time
  2690 000089DA 6689D8              <1> 	mov	ax, bx
  2691 000089DD 66C1E805            <1> 	shr	ax, 5		; shift right 5 times
  2692 000089E1 6683E03F            <1> 	and	ax, 0000111111b	; Minute Mask
  2693 000089E5 D40A                <1> 	aam			; Q([AL]/10)->AH
  2694                              <1> 				; R([AL]/10)->AL
  2695                              <1> 				; [AL]+[AH]= Minute as BCD
  2696 000089E7 660D3030            <1> 	or	ax, '00'	; Convert to ASCII
  2697 000089EB 86C4                <1> 	xchg	ah, al
  2698 000089ED 66A3[77380100]      <1> 	mov	[File_Minute], ax
  2699                              <1> 
  2700                              <1> 	;mov	al, dh
  2701 000089F3 88F8                <1> 	mov	al, bh
  2702 000089F5 C0E803              <1> 	shr	al, 3		; shift right 3 times
  2703 000089F8 D40A                <1> 	aam			; [AL]+[AH]= Hours as BCD
  2704 000089FA 660D3030            <1> 	or	ax, '00'
  2705 000089FE 86C4                <1> 	xchg	ah, al
  2706 00008A00 66A3[74380100]      <1> 	mov     [File_Hour], ax
  2707                              <1> 
  2708 00008A06 C1EB10              <1> 	shr	ebx, 16		; BX = Date
  2709                              <1> 
  2710                              <1> Dir_Date_start:
  2711                              <1> 	;mov	ax, bx		; Date
  2712                              <1> 	; 27/07/2022
  2713 00008A09 89D8                <1> 	mov	eax, ebx
  2714 00008A0B 6683E01F            <1> 	and	ax, 00011111b	; Day Mask
  2715 00008A0F D40A                <1> 	aam			; Q([AL]/10)->AH
  2716                              <1> 				; R([AL]/10)->AL
  2717                              <1> 				; [AL]+[AH]= Day as BCD
  2718 00008A11 660D3030            <1> 	or	ax, '00'	; Convert to ASCII
  2719 00008A15 86E0                <1> 	xchg	al, ah
  2720                              <1> 
  2721 00008A17 66A3[69380100]      <1> 	mov	[File_Day], ax
  2722                              <1> 
  2723                              <1> 	;mov	ax, bx
  2724                              <1> 	; 27/07/2022
  2725 00008A1D 89D8                <1> 	mov	eax, ebx
  2726                              <1> 	;shr	ax, 5		; shift right 5 times
  2727 00008A1F C1E805              <1> 	shr	eax, 5
  2728 00008A22 6683E00F            <1> 	and	ax, 00001111b	; Month Mask
  2729 00008A26 D40A                <1> 	aam
  2730 00008A28 660D3030            <1> 	or	ax, '00'
  2731 00008A2C 86C4                <1> 	xchg	ah, al
  2732 00008A2E 66A3[6C380100]      <1> 	mov	[File_Month], ax
  2733                              <1> 
  2734                              <1> 	;mov	ax, bx
  2735                              <1> 	; 27/07/2022
  2736 00008A34 89D8                <1> 	mov	eax, ebx
  2737                              <1> 	;shr	ax, 9
  2738 00008A36 C1E809              <1> 	shr	eax, 9
  2739 00008A39 6683E07F            <1> 	and	ax, 01111111b	; Result = Year - 1980
  2740 00008A3D 6605BC07            <1> 	add	ax, 1980
  2741                              <1> 
  2742 00008A41 B10A                <1> 	mov	cl, 10
  2743 00008A43 F6F1                <1> 	div	cl		; Q -> AL, R -> AH 
  2744 00008A45 80CC30              <1> 	or	ah, '0'
  2745 00008A48 8825[72380100]      <1> 	mov	[File_Year+3], ah
  2746 00008A4E D40A                <1> 	aam
  2747 00008A50 86C4                <1> 	xchg	ah, al
  2748 00008A52 80CC30              <1> 	or	ah, '0'	  ; Convert to ASCII
  2749 00008A55 8825[71380100]      <1> 	mov	[File_Year+2], ah
  2750 00008A5B D40A                <1> 	aam
  2751 00008A5D 86E0                <1> 	xchg	al, ah
  2752 00008A5F 660D3030            <1> 	or	ax, '00'
  2753 00008A63 66A3[6F380100]      <1> 	mov	[File_Year], ax
  2754                              <1> 
  2755                              <1> loc_show_line:
  2756 00008A69 56                  <1> 	push	esi
  2757 00008A6A BE[4C380100]        <1> 	mov     esi, File_Name
  2758 00008A6F E8F6E2FFFF          <1> 	call	print_msg
  2759 00008A74 BE[273F0100]        <1> 	mov	esi, nextline
  2760 00008A79 E8ECE2FFFF          <1> 	call	print_msg
  2761 00008A7E 5E                  <1> 	pop	esi
  2762                              <1> 
  2763 00008A7F FE0D[C1860100]      <1> 	dec	byte [PrintDir_RowCounter]
  2764 00008A85 740C                <1> 	jz	short pause_dir_scroll ; 27/07/2022
  2765                              <1> 
  2766                              <1> loc_next_entry:
  2767 00008A87 E88B010000          <1> 	call	find_next_file
  2768                              <1> 	;jnc	loc_dfname_use_this
  2769                              <1> 	; 27/07/2022
  2770 00008A8C 7219                <1> 	jc	short loc_dir_ok
  2771 00008A8E E999FEFFFF          <1> 	jmp	loc_dfname_use_this
  2772                              <1> 
  2773                              <1> 	; 27/07/2022
  2774                              <1> pause_dir_scroll:
  2775 00008A93 28E4                <1> 	sub	ah, ah
  2776 00008A95 E88284FFFF          <1> 	call	int16h
  2777 00008A9A 3C1B                <1> 	cmp	al, 1Bh
  2778 00008A9C 7409                <1> 	je	short loc_dir_ok
  2779 00008A9E C605[C1860100]10    <1> 	mov	byte [PrintDir_RowCounter], 16 ; Reset counter
  2780 00008AA5 EBE0                <1>         jmp     short loc_next_entry
  2781                              <1> 
  2782                              <1> loc_dir_ok:
  2783 00008AA7 B90A000000          <1> 	mov     ecx, 10
  2784                              <1> 	;mov	ax, [Dir_Count]
  2785                              <1> 	; 27/07/2022
  2786 00008AAC 0FB705[AC860100]    <1> 	movzx	eax, word [Dir_Count]
  2787 00008AB3 BF[8D380100]        <1> 	mov	edi, Decimal_Dir_Count
  2788                              <1> 	;cmp	ax, cx ; 10
  2789                              <1> 	; 27/07/2022
  2790 00008AB8 39C8                <1> 	cmp	eax, ecx
  2791 00008ABA 7216                <1> 	jb	short pass_ddc
  2792 00008ABC 47                  <1> 	inc	edi
  2793 00008ABD 6683F864            <1> 	cmp	ax, 100
  2794 00008AC1 720F                <1> 	jb	short pass_ddc
  2795 00008AC3 47                  <1> 	inc	edi
  2796 00008AC4 663DE803            <1> 	cmp	ax, 1000
  2797 00008AC8 7208                <1> 	jb	short pass_ddc
  2798 00008ACA 47                  <1> 	inc	edi
  2799 00008ACB 663D1027            <1> 	cmp	ax, 10000
  2800 00008ACF 7201                <1> 	jb	short pass_ddc
  2801 00008AD1 47                  <1> 	inc	edi
  2802                              <1> pass_ddc:
  2803 00008AD2 886F01              <1> 	mov     [edi+1], ch ; 0
  2804                              <1> loc_ddc_rediv:
  2805 00008AD5 31D2                <1> 	xor     edx, edx
  2806                              <1> 	;div	cx  ; 10
  2807                              <1> 	; 27/07/2022
  2808 00008AD7 F7F1                <1> 	div	ecx
  2809 00008AD9 80C230              <1> 	add     dl, '0'
  2810 00008ADC 8817                <1> 	mov     [edi], dl
  2811 00008ADE 4F                  <1> 	dec     edi
  2812                              <1> 	;or	ax, ax
  2813                              <1> 	; 27/07/2022
  2814 00008ADF 09C0                <1> 	or	eax, eax
  2815 00008AE1 75F2                <1> 	jnz	short loc_ddc_rediv
  2816                              <1> 
  2817 00008AE3 66A1[AA860100]      <1> 	mov     ax, [File_Count]
  2818 00008AE9 BF[7C380100]        <1> 	mov     edi, Decimal_File_Count
  2819                              <1> 	;cmp	ax, cx ; 10
  2820                              <1> 	; 27/07/2022
  2821 00008AEE 39C8                <1> 	cmp	eax, ecx ; 10
  2822 00008AF0 7216                <1> 	jb      short pass_dfc
  2823 00008AF2 47                  <1> 	inc     edi
  2824 00008AF3 6683F864            <1> 	cmp     ax, 100
  2825 00008AF7 720F                <1> 	jb      short pass_dfc
  2826 00008AF9 47                  <1> 	inc     edi
  2827 00008AFA 663DE803            <1> 	cmp     ax, 1000
  2828 00008AFE 7208                <1> 	jb      short pass_dfc
  2829 00008B00 47                  <1> 	inc     edi
  2830 00008B01 663D1027            <1> 	cmp     ax, 10000
  2831 00008B05 7201                <1> 	jb      short pass_dfc
  2832 00008B07 47                  <1> 	inc     edi
  2833                              <1> pass_dfc:
  2834                              <1> 	;mov    cx, 10
  2835 00008B08 886F01              <1> 	mov     [edi+1], ch ; 00
  2836                              <1> loc_dfc_rediv:
  2837                              <1> 	;;xor	dx, dx
  2838                              <1> 	;xor	dl, dl
  2839                              <1> 	;div	cx
  2840                              <1> 	; 27/07/022
  2841 00008B0B 31D2                <1> 	xor	edx, edx
  2842 00008B0D F7F1                <1> 	div	ecx
  2843 00008B0F 80C230              <1> 	add	dl, '0'
  2844 00008B12 8817                <1> 	mov	[edi], dl
  2845 00008B14 4F                  <1> 	dec	edi
  2846                              <1> 	;or	ax, ax
  2847                              <1> 	; 27/07/2022
  2848 00008B15 09C0                <1> 	or	eax, eax
  2849 00008B17 75F2                <1> 	jnz	short loc_dfc_rediv
  2850                              <1> 
  2851 00008B19 BF[C0860100]        <1> 	mov     edi, TFS_Dec_End
  2852                              <1>         ;mov    byte [edi], 0
  2853 00008B1E A1[AE860100]        <1> 	mov     eax, [Total_FSize]
  2854                              <1> 	;mov    ecx, 10
  2855                              <1> rediv_tfs_hex:
  2856 00008B23 29D2                <1> 	sub	edx, edx ; 27/07/2022
  2857                              <1> 	;sub	dl, dl
  2858 00008B25 F7F1                <1> 	div	ecx
  2859 00008B27 80C230              <1> 	add	dl, '0'
  2860 00008B2A 4F                  <1> 	dec     edi
  2861 00008B2B 8817                <1> 	mov     [edi], dl
  2862 00008B2D 21C0                <1> 	and	eax, eax
  2863 00008B2F 75F2                <1> 	jnz	short rediv_tfs_hex
  2864                              <1> 	
  2865 00008B31 893D[B2860100]      <1> 	mov	[TFS_Dec_Begin], edi
  2866 00008B37 BE[7A380100]        <1> 	mov	esi, Decimal_File_Count_Header
  2867 00008B3C E829E2FFFF          <1> 	call	print_msg
  2868 00008B41 BE[82380100]        <1> 	mov	esi, str_files
  2869 00008B46 E81FE2FFFF          <1> 	call	print_msg
  2870 00008B4B BE[93380100]        <1> 	mov	esi, str_dirs
  2871 00008B50 E815E2FFFF          <1> 	call	print_msg
  2872 00008B55 8B35[B2860100]      <1> 	mov	esi, [TFS_Dec_Begin]
  2873 00008B5B E80AE2FFFF          <1> 	call	print_msg
  2874 00008B60 BE[A4380100]        <1> 	mov	esi, str_bytes
  2875                              <1> 	;call	print_msg
  2876                              <1> 	;retn
  2877                              <1> 	; 27/07/2022
  2878 00008B65 E900E2FFFF          <1> 	jmp	print_msg
  2879                              <1> 
  2880                              <1> find_first_file:
  2881                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
  2882                              <1> 	; 11/02/2016
  2883                              <1> 	; 10/02/2016
  2884                              <1> 	; 08/02/2016 (TRDOS 386 = TRDOS v2.0)
  2885                              <1> 	; 09/10/2011
  2886                              <1> 	; 17/09/2009
  2887                              <1> 	; 2005
  2888                              <1> 	; INPUT ->
  2889                              <1> 	;	ESI = ASCIIZ File/Dir Name Address (in Current Directory)
  2890                              <1> 	;	AL = Attributes AND mask (The AND result must be equal to AL)
  2891                              <1> 	;	      bit 0 = Read Only
  2892                              <1> 	;	      bir 1 = Hidden
  2893                              <1> 	;	      bit 2 = System
  2894                              <1> 	;	      bit 3 = Volume Label
  2895                              <1> 	;	      bit 4 = Directory
  2896                              <1> 	;	      bit 5 = Archive
  2897                              <1> 	;	      bit 6 = Reserved, must be 0
  2898                              <1> 	;	      bit 7 = Reserved, must be 0
  2899                              <1> 	;       AH = Attributes Negative AND mask (The AND result must be ZERO)
  2900                              <1> 	;
  2901                              <1> 	; OUTPUT ->
  2902                              <1> 	;	CF = 1 -> Error, Error Code in EAX (AL)
  2903                              <1> 	;	CF = 0 ->
  2904                              <1> 	;	     ESI = Directory Entry (FindFile_DirEntry) Location
  2905                              <1> 	;	     EDI = Directory Buffer Directory Entry Location
  2906                              <1> 	;	     EAX = File Size
  2907                              <1> 	;	      BL = Attributes of The File/Directory
  2908                              <1> 	;	      BH = Long Name Yes/No Status (>0 is YES)
  2909                              <1> 	;             DX > 0 : Ambiguous filename chars are used
  2910                              <1> 	;
  2911                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
  2912                              <1> 
  2913 00008B6A 66A3[72860100]      <1> 	mov	[FindFile_AttributesMask], ax
  2914 00008B70 BF[74860100]        <1> 	mov	edi, FindFile_DirEntry ; TR-DOS Fullfilename formatted buffer
  2915 00008B75 31C0                <1> 	xor	eax, eax
  2916                              <1> 	;mov	ecx, 11
  2917                              <1> 	; 28/07/2022
  2918 00008B77 31C9                <1> 	xor	ecx, ecx
  2919 00008B79 B10B                <1> 	mov	cl, 11
  2920 00008B7B F3AB                <1> 	rep	stosd	; 44 bytes
  2921                              <1> 	;stosw		; +2 bytes 
  2922                              <1> 
  2923 00008B7D BF[64860100]        <1> 	mov	edi, FindFile_Name ; FFF structure, offset 66
  2924 00008B82 39FE                <1> 	cmp	esi, edi
  2925 00008B84 7408                <1> 	je	short loc_fff_mfn_ok
  2926 00008B86 89FA                <1> 	mov	edx, edi 
  2927                              <1> 	; move 13 bytes
  2928 00008B88 A5                  <1> 	movsd
  2929 00008B89 A5                  <1> 	movsd
  2930 00008B8A A5                  <1> 	movsd
  2931 00008B8B AA                  <1> 	stosb
  2932 00008B8C 89D6                <1> 	mov	esi, edx
  2933                              <1> loc_fff_mfn_ok:
  2934 00008B8E BF[13860100]        <1> 	mov	edi, Dir_Entry_Name ; Dir Entry Format File Name
  2935 00008B93 E8B81F0000          <1> 	call	convert_file_name
  2936 00008B98 89FE                <1> 	mov	esi, edi ; offset Dir_Entry_Name
  2937                              <1> 
  2938 00008B9A 66A1[72860100]      <1> 	mov	ax, [FindFile_AttributesMask]
  2939                              <1> 	;xor	ecx, ecx
  2940 00008BA0 30C9                <1> 	xor	cl, cl  
  2941 00008BA2 E8DC1C0000          <1> 	call	locate_current_dir_file
  2942 00008BA7 726D                <1> 	jc	short loc_fff_retn
  2943                              <1> 	; EDI = Directory Entry
  2944                              <1> 	; EBX = Directory Buffer Entry Index/Number
  2945                              <1> 
  2946                              <1> loc_fff_fnf_ln_check:
  2947 00008BA9 30ED                <1> 	xor	ch, ch
  2948 00008BAB 80F60F              <1> 	xor	dh, 0Fh
  2949 00008BAE 7408                <1> 	jz	short loc_fff_longname_yes
  2950 00008BB0 882D[71860100]      <1> 	mov	[FindFile_LongNameYes], ch ; 0
  2951 00008BB6 EB0C                <1> 	jmp	short loc_fff_longname_no
  2952                              <1> 
  2953                              <1> loc_fff_longname_yes:
  2954                              <1> 	;inc	byte [FindFile_LongNameYes]
  2955 00008BB8 8A0D[7E850100]      <1> 	mov	cl, [LFN_EntryLength]  
  2956 00008BBE 880D[71860100]      <1> 	mov	[FindFile_LongNameEntryLength], cl ; FindFile_LongNameYes
  2957                              <1> 
  2958                              <1> loc_fff_longname_no:
  2959                              <1> 	;mov	bx, [DirBuff_CurrentEntry]
  2960 00008BC4 66891D[9C860100]    <1> 	mov	[FindFile_DirEntryNumber], bx
  2961                              <1> 	;mov	dx, ax ; Ambiguous Filename chars used sign > 0
  2962                              <1> 	; 28/07/2022
  2963 00008BCB 89C2                <1> 	mov	edx, eax
  2964                              <1> 
  2965 00008BCD A0[827D0100]        <1> 	mov	al, [Current_Drv]
  2966 00008BD2 A2[22860100]        <1> 	mov	[FindFile_Drv], al 
  2967                              <1> 
  2968 00008BD7 A1[7C7D0100]        <1> 	mov	eax, [Current_Dir_FCluster]
  2969 00008BDC A3[94860100]        <1> 	mov	[FindFile_DirFirstCluster], eax
  2970                              <1> 
  2971 00008BE1 A1[AE840100]        <1> 	mov	eax, [DirBuff_Cluster]
  2972 00008BE6 A3[98860100]        <1> 	mov	[FindFile_DirCluster], eax
  2973                              <1> 
  2974 00008BEB 66FF05[9E860100]    <1> 	inc	word [FindFile_MatchCounter]
  2975                              <1> 
  2976 00008BF2 89FB                <1> 	mov	ebx, edi
  2977 00008BF4 89FE                <1> 	mov	esi, edi
  2978 00008BF6 BF[74860100]        <1> 	mov	edi, FindFile_DirEntry
  2979 00008BFB 89F8                <1> 	mov	eax, edi
  2980 00008BFD B108                <1> 	mov	cl, 8
  2981 00008BFF F3A5                <1> 	rep	movsd
  2982 00008C01 89C6                <1> 	mov	esi, eax
  2983 00008C03 89DF                <1> 	mov	edi, ebx
  2984                              <1> 
  2985 00008C05 A1[90860100]        <1> 	mov	eax, [FindFile_DirEntry+28] ; File Size
  2986                              <1> 
  2987 00008C0A 8A1D[7F860100]      <1> 	mov	bl, [FindFile_DirEntry+11] ; File Attributes
  2988 00008C10 8A3D[71860100]      <1> 	mov	bh, [FindFile_LongNameYes]
  2989                              <1> 
  2990                              <1> 	;mov	cx, [DirBuff_EntryCounter]
  2991                              <1> 	;mov	[FindFile_DirEntryNumber], cx
  2992                              <1> 	;mov	cx, [FindFile_DirEntryNumber]
  2993                              <1> 	; ecx = 0
  2994                              <1> 
  2995                              <1> loc_fff_retn:
  2996 00008C16 C3                  <1> 	retn
  2997                              <1> 
  2998                              <1> find_next_file:
  2999                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
  3000                              <1> 	; 15/10/2016
  3001                              <1> 	; 10/02/2016
  3002                              <1> 	; 08/02/2016 (TRDOS 386 = TRDOS v2.0)
  3003                              <1> 	; 06/02/2011
  3004                              <1> 	; 17/09/2009
  3005                              <1> 	; 2005
  3006                              <1> 	; INPUT ->
  3007                              <1> 	;	NONE, Find First File Parameters
  3008                              <1> 	; OUTPUT ->
  3009                              <1> 	;	CF = 1 -> Error, Error Code in EAX (AL)
  3010                              <1> 	;	CF = 0 ->
  3011                              <1> 	;	    ESI = Directory Entry (FindFile_DirEntry) Location
  3012                              <1> 	;	    EDI = Directory Buffer Directory Entry Location
  3013                              <1> 	;	    EAX = File Size
  3014                              <1> 	;	      BL = Attributes of The File/Directory
  3015                              <1> 	;	      BH = Long Name Yes/No Status (>0 is YES)
  3016                              <1> 	;             DX > 0 : Ambiguous filename chars are used
  3017                              <1> 	;
  3018                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
  3019                              <1> 
  3020 00008C17 66833D[9E860100]00  <1> 	cmp	word [FindFile_MatchCounter], 0
  3021 00008C1F 7707                <1> 	ja	short loc_start_search_next_file
  3022                              <1> 
  3023                              <1> loc_fnf_stc_retn:
  3024 00008C21 F9                  <1> 	stc
  3025                              <1> loc_fnf_ax12h_retn:
  3026 00008C22 B80C000000          <1> 	mov	eax, 12 ; No More files
  3027                              <1> ;loc_fnf_retn:
  3028 00008C27 C3                  <1> 	retn
  3029                              <1> 
  3030                              <1> loc_start_search_next_file:
  3031 00008C28 668B1D[9C860100]    <1> 	mov	bx, [FindFile_DirEntryNumber]
  3032                              <1> 	;inc	bx
  3033                              <1> 	; 28/07/2022
  3034 00008C2F 43                  <1> 	inc	ebx
  3035 00008C30 663B1D[AC840100]    <1> 	cmp	bx, [DirBuff_LastEntry]
  3036 00008C37 7719                <1> 	ja	short loc_cont_search_next_file
  3037                              <1> 
  3038                              <1> loc_fnf_search:
  3039 00008C39 BE[13860100]        <1> 	mov	esi, Dir_Entry_Name
  3040 00008C3E 66A1[72860100]      <1> 	mov	ax, [FindFile_AttributesMask]
  3041                              <1> 	;xor	cx, cx
  3042                              <1> 	; 28/07/2022
  3043 00008C44 31C9                <1> 	xor	ecx, ecx
  3044 00008C46 E8341D0000          <1> 	call	find_directory_entry
  3045                              <1> 	;jnc	loc_fff_fnf_ln_check
  3046                              <1> 	; 28/07/2022
  3047 00008C4B 7205                <1> 	jc	short loc_cont_search_next_file
  3048 00008C4D E957FFFFFF          <1> 	jmp	loc_fff_fnf_ln_check
  3049                              <1> 
  3050                              <1> loc_cont_search_next_file:
  3051 00008C52 31DB                <1> 	xor	ebx, ebx
  3052 00008C54 8A3D[827D0100]      <1> 	mov	bh, [Current_Drv]
  3053 00008C5A BE00010900          <1> 	mov	esi, Logical_DOSDisks
  3054 00008C5F 01DE                <1> 	add	esi, ebx
  3055                              <1> 
  3056 00008C61 803D[807D0100]00    <1> 	cmp	byte [Current_Dir_Level], 0
  3057 00008C68 7608                <1> 	jna	short loc_fnf_check_FAT_type
  3058 00008C6A 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  3059 00008C6E 72B2                <1> 	jb	short loc_fnf_ax12h_retn
  3060 00008C70 EB06                <1> 	jmp	short loc_fnf_check_next_cluster
  3061                              <1> 
  3062                              <1> loc_fnf_check_FAT_type:
  3063 00008C72 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3
  3064 00008C76 72AA                <1> 	jb	short loc_fnf_ax12h_retn
  3065                              <1> 
  3066                              <1> loc_fnf_check_next_cluster:
  3067 00008C78 A1[AE840100]        <1> 	mov	eax, [DirBuff_Cluster]
  3068 00008C7D E89E360000          <1> 	call	get_next_cluster
  3069 00008C82 7306                <1> 	jnc	short loc_fnf_load_next_dir_cluster
  3070 00008C84 09C0                <1> 	or	eax, eax
  3071 00008C86 7499                <1> 	jz	short loc_fnf_stc_retn
  3072                              <1> 	;mov	eax, 17 ;Drive not ready or read error
  3073 00008C88 F5                  <1>  	cmc	;stc
  3074                              <1> loc_fnf_retn:
  3075 00008C89 C3                  <1> 	retn
  3076                              <1> 
  3077                              <1> loc_fnf_load_next_dir_cluster:
  3078 00008C8A E84D380000          <1> 	call	load_FAT_sub_directory
  3079 00008C8F 72F8                <1> 	jc	short loc_fnf_retn
  3080                              <1> 	;xor	bx, bx
  3081                              <1> 	; 28/07/2022
  3082 00008C91 31DB                <1> 	xor	ebx, ebx
  3083 00008C93 66891D[9C860100]    <1> 	mov	[FindFile_DirEntryNumber], bx
  3084 00008C9A EB9D                <1> 	jmp	short loc_fnf_search
  3085                              <1> 
  3086                              <1> get_and_print_longname:
  3087                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
  3088                              <1> 	; 16/10/2016
  3089                              <1> 	; 13/02/2016 (TRDOS 386 = TRDOS v2.0)
  3090                              <1> 	; 24/01/2010
  3091                              <1> 	; 17/10/2009 (CMD_INTR.ASM, 'cmp_cmd_longname')
  3092                              <1> get_longname_fchar:
  3093 00008C9C 803E20              <1> 	cmp	byte [esi], 20h
  3094 00008C9F 7701                <1> 	ja	short loc_find_longname
  3095                              <1> 	;jb	short loc_longname_retn
  3096                              <1> 	;inc	esi
  3097                              <1> 	;je	short get_longname_fchar
  3098                              <1> ;loc_longname_retn:
  3099 00008CA1 C3                  <1> 	retn
  3100                              <1> loc_find_longname:
  3101 00008CA2 E811200000          <1> 	call	find_longname
  3102 00008CA7 731D                <1> 	jnc	short loc_print_longname
  3103                              <1> 
  3104 00008CA9 08C0                <1> 	or	al, al
  3105 00008CAB 7412                <1> 	jz	short loc_longname_not_found
  3106                              <1> 
  3107                              <1> 	; 16/10/2016 (15h -> 15, 17)
  3108 00008CAD 3C0F                <1> 	cmp	al, 15
  3109                              <1> 	;je	cd_drive_not_ready ; drive not ready
  3110                              <1> 	; 28/07/2022
  3111 00008CAF 7505                <1> 	jne	short loc_fln_err2
  3112                              <1> loc_fln_err1:
  3113 00008CB1 E924F8FFFF          <1> 	jmp	cd_drive_not_ready
  3114                              <1> loc_fln_err2:
  3115                              <1> 				   ; or
  3116 00008CB6 3C11                <1> 	cmp	al, 17		   ; read error	
  3117                              <1> 	;je	cd_drive_not_ready
  3118                              <1> 	; 28/07/2022
  3119                              <1> 	;je	short loc_fln_err1
  3120                              <1> 
  3121                              <1> loc_ln_file_dir_not_found:
  3122 00008CB8 BE[CE370100]        <1> 	mov	esi, Msg_File_Directory_Not_Found
  3123                              <1> 	;;call	print_msg
  3124                              <1>         ;;retn
  3125                              <1> 	;jmp	print_msg
  3126                              <1> 	; 28/07/2022
  3127 00008CBD EB2B                <1> 	jmp	short loc_lfn_err3
  3128                              <1> 
  3129                              <1> loc_longname_not_found:
  3130 00008CBF BE[ED370100]        <1>         mov     esi, Msg_LongName_Not_Found
  3131                              <1> 	;;call	print_msg
  3132                              <1>         ;;retn
  3133                              <1> 	;jmp	print_msg
  3134                              <1> 	; 28/07/2022
  3135 00008CC4 EB24                <1> 	jmp	short loc_lfn_err3
  3136                              <1> 
  3137                              <1> loc_print_longname:
  3138                              <1> 	;mov	esi, LongFileName
  3139 00008CC6 BF[827E0100]        <1> 	mov	edi, TextBuffer
  3140 00008CCB 57                  <1> 	push	edi 
  3141 00008CCC 3C00                <1> 	cmp	al, 0
  3142 00008CCE 7708                <1> 	ja	short loc_print_longname_1
  3143                              <1> loc_print_FS_longname: ; Singlix FS (64 byte ASCIIZ file name)
  3144 00008CD0 AC                  <1> 	lodsb
  3145 00008CD1 AA                  <1> 	stosb
  3146 00008CD2 08C0                <1> 	or	al, al
  3147 00008CD4 75FA                <1> 	jnz	short loc_print_FS_longname
  3148 00008CD6 EB07                <1> 	jmp	short loc_print_longname_2
  3149                              <1> 	;
  3150                              <1> loc_print_longname_1: ; MS Windows long name (UNICODE chars)
  3151 00008CD8 66AD                <1> 	lodsw
  3152 00008CDA AA                  <1> 	stosb
  3153 00008CDB 08C0                <1> 	or	al, al
  3154 00008CDD 75F9                <1> 	jnz	short loc_print_longname_1
  3155                              <1> 	;
  3156                              <1> loc_print_longname_2:
  3157 00008CDF 5E                  <1> 	pop	esi
  3158 00008CE0 E885E0FFFF          <1> 	call	print_msg
  3159 00008CE5 BE[273F0100]        <1>   	mov	esi, nextline
  3160                              <1> loc_lfn_err3:
  3161                              <1> 	;call	print_msg
  3162                              <1> 	;retn
  3163 00008CEA E97BE0FFFF          <1> 	jmp	print_msg
  3164                              <1> 
  3165                              <1> show_file:
  3166                              <1> 	; 07/08/2022
  3167                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
  3168                              <1> 	; 18/02/2016
  3169                              <1> 	; 17/02/2016
  3170                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
  3171                              <1> 	; 13/09/2011 (CMD_INTR.ASM, 'cmp_cmd_show')
  3172                              <1> 	; 08/11/2009
  3173                              <1> 
  3174                              <1> loc_show_parse_path_name:
  3175 00008CEF BF[22860100]        <1> 	mov	edi, FindFile_Drv
  3176 00008CF4 E8211F0000          <1> 	call	parse_path_name
  3177                              <1> 	;jc	loc_cmd_failed
  3178                              <1> 	; 28/07/2022
  3179 00008CF9 7305                <1> 	jnc	short loc_show_check_filename_exists
  3180                              <1> show_file_err1:
  3181 00008CFB E944F9FFFF          <1> 	jmp	loc_cmd_failed
  3182                              <1> 
  3183                              <1> loc_show_check_filename_exists:
  3184 00008D00 BE[64860100]        <1> 	mov	esi, FindFile_Name
  3185 00008D05 803E20              <1> 	cmp	byte [esi], 20h
  3186                              <1> 	;jna	loc_cmd_failed
  3187                              <1> 	; 28/07/2022
  3188 00008D08 76F1                <1> 	jna	short show_file_err1
  3189                              <1> 
  3190                              <1> 	; 15/02/2016 (invalid file name check)
  3191 00008D0A E800020000          <1> 	call	check_filename 	
  3192 00008D0F 730A                <1> 	jnc	short loc_show_change_drv
  3193                              <1> 
  3194 00008D11 BE[BA380100]        <1> 	mov	esi, Msg_invalid_name_chars
  3195 00008D16 E94FE0FFFF          <1> 	jmp	print_msg
  3196                              <1> 
  3197                              <1> loc_show_change_drv:
  3198 00008D1B 8A35[827D0100]      <1> 	mov	dh, [Current_Drv]
  3199 00008D21 8835[DF840100]      <1> 	mov	[RUN_CDRV], dh
  3200 00008D27 8A15[22860100]      <1> 	mov	dl, [FindFile_Drv]
  3201 00008D2D 38F2                <1> 	cmp	dl, dh
  3202 00008D2F 740C                <1> 	je	short loc_show_change_directory
  3203 00008D31 E847EBFFFF          <1> 	call	change_current_drive
  3204                              <1> 	;;jc	loc_file_rw_cmd_failed
  3205                              <1> 	;jc	loc_run_cmd_failed
  3206                              <1> 	; 28/07/2022
  3207 00008D36 7305                <1> 	jnc	short loc_show_change_directory
  3208                              <1> show_file_err2:
  3209 00008D38 E932F9FFFF          <1> 	jmp	loc_run_cmd_failed
  3210                              <1> 
  3211                              <1> loc_show_change_directory:
  3212 00008D3D 803D[23860100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  3213 00008D44 7614                <1> 	jna	short loc_findload_showfile
  3214                              <1> 
  3215 00008D46 FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  3216 00008D4C BE[23860100]        <1> 	mov	esi, FindFile_Directory
  3217 00008D51 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0
  3218 00008D53 E8D8180000          <1> 	call	change_current_directory
  3219                              <1> 	;;jc	loc_file_rw_cmd_failed
  3220                              <1> 	;jc	loc_run_cmd_failed
  3221                              <1> 	; 28/07/2022
  3222 00008D58 72DE                <1> 	jc	short show_file_err2
  3223                              <1> 
  3224                              <1> ;loc_show_change_prompt_dir_string:
  3225                              <1> 	;call	change_prompt_dir_string
  3226                              <1> 
  3227                              <1> loc_findload_showfile:
  3228                              <1> 	; 15/02/2016
  3229 00008D5A BE[64860100]        <1> 	mov	esi, FindFile_Name
  3230 00008D5F BF[13860100]        <1> 	mov	edi, Dir_Entry_Name ; Dir Entry Format File Name
  3231 00008D64 E8E71D0000          <1> 	call	convert_file_name
  3232 00008D69 89FE                <1> 	mov	esi, edi ; offset Dir_Entry_Name
  3233                              <1> 
  3234 00008D6B 28C0                <1> 	sub	al, al	; Attrib AND mask = 0
  3235                              <1> 	; Directory attribute : 10h
  3236                              <1> 	; Volume name attribute: 8h
  3237 00008D6D B418                <1> 	mov	ah, 00011000b ; 18h (Attrib NAND, AND --> zero mask)
  3238                              <1> 	;
  3239                              <1> 	;xor	cx, cx
  3240                              <1> 	; 28/07/2022
  3241 00008D6F 31C9                <1> 	xor	ecx, ecx
  3242 00008D71 E80D1B0000          <1> 	call	locate_current_dir_file
  3243                              <1> 	;;jc	loc_file_rw_cmd_failed
  3244                              <1> 	;jc	loc_run_cmd_failed
  3245                              <1> 	; 28/07/2022
  3246 00008D76 72C0                <1> 	jc	short show_file_err2
  3247                              <1> 
  3248                              <1> loc_show_load_file:
  3249                              <1> 	; EDI = Directory Entry
  3250 00008D78 668B4714            <1> 	mov	ax, [edi+DirEntry_FstClusHI] ; First Cluster High Word
  3251 00008D7C C1E010              <1> 	shl	eax, 16
  3252 00008D7F 668B471A            <1> 	mov	ax, [edi+DirEntry_FstClusLO] ; First Cluster Low Word
  3253 00008D83 A3[CC860100]        <1> 	mov	[Show_Cluster], eax
  3254 00008D88 8B471C              <1> 	mov	eax, [edi+DirEntry_FileSize] ; File Size
  3255 00008D8B 21C0                <1> 	and	eax, eax ; Empty file !
  3256                              <1> 	;jz	end_of_show_file
  3257                              <1> 	; 28/07/2022
  3258 00008D8D 7505                <1> 	jnz	short loc_show_load_file_set_size
  3259 00008D8F E904010000          <1> 	jmp	end_of_show_file 
  3260                              <1> 
  3261                              <1> loc_show_load_file_set_size: ; 28/07/2022
  3262 00008D94 A3[D0860100]        <1> 	mov	[Show_FileSize], eax
  3263 00008D99 31C0                <1> 	xor	eax, eax
  3264 00008D9B A3[D4860100]        <1> 	mov	[Show_FilePointer], eax ; 0
  3265 00008DA0 66A3[D8860100]      <1> 	mov	[Show_ClusterPointer], ax ; 0
  3266 00008DA6 29DB                <1> 	sub	ebx, ebx
  3267 00008DA8 8A3D[827D0100]      <1> 	mov	bh, [Current_Drv]
  3268 00008DAE BE00010900          <1> 	mov	esi, Logical_DOSDisks
  3269 00008DB3 01DE                <1> 	add	esi, ebx
  3270 00008DB5 8935[C8860100]      <1> 	mov	[Show_LDDDT], esi ; Logical DOS Drv Description Table addr
  3271                              <1> 
  3272 00008DBB 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  3273 00008DBF 7713                <1> 	ja	short loc_show_calculate_cluster_size
  3274                              <1> 	; Singlix FS
  3275                              <1> 	; First Cluster Number is FDT number (in compatibility buffer)
  3276 00008DC1 8B15[CC860100]      <1> 	mov	edx, [Show_Cluster] ; Compatibility dir. buffer value (FDT)
  3277 00008DC7 8915[C4860100]      <1> 	mov	[Show_FDT], edx
  3278 00008DCD 31C0                <1> 	xor	eax, eax
  3279 00008DCF A3[CC860100]        <1> 	mov	[Show_Cluster], eax ; Sector index  = 0
  3280                              <1> 				    ; (next time it will be 1)
  3281                              <1> loc_show_calculate_cluster_size:
  3282 00008DD4 668B5E11            <1> 	mov	bx, [esi+LD_BPB+BPB_BytsPerSec] ; FAT 12-16-32 (512)
  3283                              <1> 	; BX = 512 = [esi+LD_FS_BytesPerSec] ; Singlix FS
  3284 00008DD8 8A4613              <1> 	mov	al, [esi+LD_BPB+BPB_SecPerClust] ; FAT 12-16-32 (<= 128)
  3285                              <1> 	; AL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
  3286 00008DDB F7E3                <1> 	mul	ebx
  3287                              <1> 
  3288                              <1> 	;cmp	eax, 65536 ; non-compatible (very big) cluster size
  3289                              <1> 	;ja	short end_of_show_file
  3290 00008DDD 66A3[DA860100]      <1> 	mov	[Show_ClusterSize], ax
  3291                              <1> 
  3292                              <1> loc_start_show_file:
  3293 00008DE3 BE[273F0100]        <1> 	mov	esi, nextline
  3294 00008DE8 E87DDFFFFF          <1> 	call	print_msg
  3295                              <1> 
  3296 00008DED A1[CC860100]        <1> 	mov	eax, [Show_Cluster]
  3297 00008DF2 C605[DC860100]17    <1> 	mov	byte [Show_RowCount], 23
  3298                              <1> 
  3299                              <1> 	; 17/02/2016
  3300 00008DF9 8B35[C8860100]      <1> 	mov	esi, [Show_LDDDT]
  3301                              <1> 
  3302                              <1> 	; 07/08/2022
  3303                              <1> loc_show_next_cluster:
  3304                              <1> 	; 15/02/2016
  3305 00008DFF BB00000700          <1> 	mov	ebx, Cluster_Buffer ; 70000h (for current TRDOS 386 version)
  3306                              <1> 	; ESI = Logical DOS drv description table address
  3307 00008E04 E80E370000          <1> 	call	read_cluster
  3308                              <1> 	;;jc	loc_file_rw_cmd_failed
  3309                              <1> 	;jc	loc_run_cmd_failed
  3310                              <1> 	; 07/08/2022
  3311 00008E09 7305                <1> 	jnc	short loc_show_nc_rc_ok
  3312 00008E0B E95FF8FFFF          <1> 	jmp	loc_run_cmd_failed
  3313                              <1> loc_show_nc_rc_ok:
  3314 00008E10 31DB                <1> 	xor 	ebx, ebx
  3315                              <1> loc_show_next_byte:
  3316 00008E12 803D[DC860100]00    <1> 	cmp	byte [Show_RowCount], 0
  3317 00008E19 7512                <1> 	jne	short pass_show_wait_for_key
  3318 00008E1B 30E4                <1> 	xor	ah, ah
  3319 00008E1D E8FA80FFFF          <1> 	call	int16h
  3320 00008E22 3C1B                <1> 	cmp	al, 1Bh
  3321                              <1> 	;jne	short pass_exit_show
  3322                              <1> 	; 28/07/2022
  3323 00008E24 7472                <1> 	je	short end_of_show_file
  3324                              <1> 
  3325                              <1> ;end_of_show_file:
  3326                              <1> ;pass_show_file:
  3327                              <1> ;	mov	esi, nextline
  3328                              <1> ;	call	print_msg
  3329                              <1> ;	jmp	loc_file_rw_restore_retn
  3330                              <1> 
  3331                              <1> pass_exit_show:
  3332 00008E26 C605[DC860100]14    <1> 	mov	byte [Show_RowCount], 20
  3333                              <1> pass_show_wait_for_key:
  3334 00008E2D 81C300000700        <1> 	add	ebx, Cluster_Buffer
  3335 00008E33 8A03                <1> 	mov	al, [ebx]
  3336 00008E35 3C0D                <1> 	cmp	al, 0Dh
  3337                              <1>  	;jne	loc_show_check_tab_space
  3338                              <1> 	; 28/07/2022
  3339 00008E37 740B                <1> 	je	short loc_show_dec_row_count
  3340 00008E39 E991000000          <1> 	jmp	loc_show_check_tab_space
  3341                              <1> 
  3342                              <1> 	; 07/08/2022
  3343                              <1> loc_show_next:
  3344                              <1> 	;and	bx, bx ; 65536 -> 0
  3345                              <1> 	; 28/07/2022
  3346 00008E3E 21DB                <1> 	and	ebx, ebx
  3347 00008E40 75D0                <1> 	jnz	short loc_show_next_byte
  3348 00008E42 EBBB                <1> 	jmp     short loc_show_next_cluster
  3349                              <1> 
  3350                              <1> loc_show_dec_row_count:	; 28/07/2022
  3351 00008E44 FE0D[DC860100]      <1> 	dec	byte [Show_RowCount]
  3352                              <1> pass_show_dec_rowcount:
  3353 00008E4A B307                <1> 	mov	bl, 7 ; (light gray character color, black background)
  3354 00008E4C 8A3D[EE7C0100]      <1> 	mov	bh, [ACTIVE_PAGE] ; [ptty]
  3355 00008E52 E83E94FFFF          <1> 	call	_write_tty
  3356                              <1> loc_show_check_eof:
  3357 00008E57 FF05[D4860100]      <1> 	inc	dword [Show_FilePointer]
  3358 00008E5D A1[D4860100]        <1> 	mov	eax, [Show_FilePointer]
  3359 00008E62 3B05[D0860100]      <1> 	cmp	eax, [Show_FileSize]
  3360 00008E68 732E                <1> 	jnb	short end_of_show_file
  3361 00008E6A 66FF05[D8860100]    <1> 	inc	word [Show_ClusterPointer]
  3362 00008E71 0FB71D[D8860100]    <1> 	movzx	ebx, word [Show_ClusterPointer]
  3363                              <1> 
  3364                              <1> 	; 17/02/2016
  3365                              <1> 	; (sector boundary -9 bits- check, 512 = 0)
  3366 00008E78 66F7C3FF01          <1>         test    bx, 1FFh ; 1 to 511
  3367 00008E7D 7593                <1> 	jnz	short loc_show_next_byte
  3368                              <1> 
  3369                              <1> 	; 16/02/2016
  3370 00008E7F 8B35[C8860100]      <1> 	mov	esi, [Show_LDDDT]
  3371                              <1> 	;
  3372 00008E85 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  3373 00008E89 771C                <1> 	ja	short loc_show_check_fat_cluster_size
  3374                              <1> 
  3375                              <1> 	; Singlix FS
  3376                              <1> 	; 1 sector, more... (cluster size = 1 sector)
  3377 00008E8B A1[CC860100]        <1> 	mov	eax, [Show_Cluster]
  3378 00008E90 40                  <1> 	inc	eax
  3379 00008E91 A3[CC860100]        <1> 	mov	[Show_Cluster], eax
  3380                              <1> 
  3381                              <1> 	; 07/08/2022
  3382 00008E96 EBA6                <1> 	jmp	short loc_show_next
  3383                              <1> 
  3384                              <1> 	; 28/07/2022
  3385                              <1> end_of_show_file:
  3386                              <1> pass_show_file:
  3387 00008E98 BE[273F0100]        <1> 	mov	esi, nextline
  3388 00008E9D E8C8DEFFFF          <1> 	call	print_msg
  3389 00008EA2 E9D7000000          <1> 	jmp	loc_file_rw_restore_retn
  3390                              <1> 	 
  3391                              <1> loc_show_check_fat_cluster_size:
  3392                              <1> 	; 17/02/2016
  3393 00008EA7 663B1D[DA860100]    <1> 	cmp	bx, [Show_ClusterSize] ; cluster size in bytes
  3394                              <1>         ;jb	short loc_show_next_byte ; 28/07/2022
  3395                              <1> 	; 07/08/2022
  3396 00008EAE 7305                <1> 	jnb	short loc_show_file_cluster_ok
  3397 00008EB0 E95DFFFFFF          <1> 	jmp	loc_show_next_byte
  3398                              <1> 
  3399                              <1> loc_show_file_cluster_ok:
  3400 00008EB5 66C705[D8860100]00- <1> 	mov	word [Show_ClusterPointer], 0
  3400 00008EBD 00                  <1>
  3401                              <1> 
  3402 00008EBE A1[CC860100]        <1> 	mov	eax, [Show_Cluster]
  3403                              <1> 	;mov	esi, [Show_LDDDT]
  3404                              <1> loc_show_get_next_cluster:
  3405 00008EC3 E858340000          <1> 	call	get_next_cluster
  3406                              <1> 	;;jc	loc_file_rw_cmd_failed
  3407                              <1> 	;jc	loc_run_cmd_failed
  3408                              <1> 	; 28/07/2022
  3409 00008EC8 733B                <1> 	jnc	short loc_show_update_ccluster
  3410 00008ECA E9A0F7FFFF          <1> 	jmp	loc_run_cmd_failed
  3411                              <1> 
  3412                              <1> loc_show_check_tab_space:
  3413 00008ECF 3C09                <1> 	cmp	al, 09h
  3414                              <1> 	;jne	short pass_show_dec_rowcount ; 28/07/2022
  3415                              <1> 	; 07/08/2022
  3416 00008ED1 7405                <1> 	je	short loc_show_put_tab_space
  3417 00008ED3 E972FFFFFF          <1> 	jmp	pass_show_dec_rowcount
  3418                              <1> loc_show_put_tab_space:
  3419 00008ED8 8A3D[EE7C0100]      <1> 	mov	bh, [ACTIVE_PAGE] ; [ptty]
  3420 00008EDE E85090FFFF          <1> 	call	get_cpos
  3421                              <1> 	; dl = cursor column
  3422 00008EE3 80E207              <1> 	and	dl, 7 ; 18/02/2016
  3423                              <1> 	;shr	bh, 1 ; [ACTIVE_PAGE]
  3424 00008EE6 8A3D[EE7C0100]      <1> 	mov	bh, [ACTIVE_PAGE]
  3425 00008EEC B307                <1> 	mov	bl, 7 ; color attribute
  3426                              <1> loc_show_put_space_chars:
  3427 00008EEE B020                <1> 	mov	al, 20h ; space
  3428                              <1> 	;mov	bh, [ACTIVE_PAGE] ; [ptty]
  3429                              <1> 	;mov	bl, 7 ; color attribute
  3430                              <1> 	;push	dx
  3431 00008EF0 52                  <1> 	push	edx ; 29/12/2017
  3432 00008EF1 E89F93FFFF          <1> 	call	_write_tty
  3433 00008EF6 5A                  <1> 	pop	edx ; 29/12/2017
  3434                              <1> 	;pop	dx
  3435                              <1> 	; 18/02/2016
  3436 00008EF7 80FA07              <1> 	cmp	dl, 7
  3437                              <1> 	;jnb	short loc_show_check_eof ; 28/07/2022
  3438                              <1> 	; 07/08/2022
  3439 00008EFA 7205                <1> 	jb	short loc_show_next_tab_space
  3440 00008EFC E956FFFFFF          <1> 	jmp	loc_show_check_eof
  3441                              <1> loc_show_next_tab_space:
  3442 00008F01 FEC2                <1> 	inc	dl
  3443 00008F03 EBE9                <1> 	jmp	short loc_show_put_space_chars
  3444                              <1> 
  3445                              <1> loc_show_update_ccluster:
  3446 00008F05 A3[CC860100]        <1> 	mov	[Show_Cluster], eax
  3447 00008F0A E9F0FEFFFF          <1>         jmp     loc_show_next_cluster
  3448                              <1> 
  3449                              <1> check_filename:
  3450                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
  3451                              <1> 	; 10/10/2016
  3452                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
  3453                              <1> 	; 07/08/2010 (FILE.ASM, 'proc_check_filename')
  3454                              <1> 	; 10/07/2010
  3455                              <1> 	; Derived from 'proc_check_filename'
  3456                              <1> 	; in the old TRDOS.ASM (09/02/2005).
  3457                              <1> 	;
  3458                              <1> 	; INPUT ->
  3459                              <1> 	;	ESI = Dot File Name Location
  3460                              <1> 	; OUTPUT ->
  3461                              <1> 	;	cf = 1 -> error code in AL
  3462                              <1> 	;	     AL = ERR_INV_FILE_NAME (=26)
  3463                              <1> 	;		  Invalid file name chars
  3464                              <1> 	;	cf = 0 -> valid file name
  3465                              <1> 	; 
  3466                              <1> 	; (EAX, ECX, EDI will be changed)
  3467                              <1> 
  3468                              <1> check_invalid_filename_chars:
  3469                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
  3470                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
  3471                              <1> 	; 10/07/2010 (FILE.ASM, 'proc_check_invalid_filename_chars')
  3472                              <1> 	; 10/02/2010
  3473                              <1> 	; Derived from 'proc_check_invalid_filename_chars'
  3474                              <1> 	; in the old TRDOS.ASM (09/02/2005).
  3475                              <1> 	;
  3476                              <1> 	; INPUT ->
  3477                              <1> 	;	ESI = ASCIIZ FileName
  3478                              <1> 	; OUTPUT ->
  3479                              <1> 	;	cf = 1 -> invalid
  3480                              <1> 	;	cf = 0 -> valid
  3481                              <1> 	; 
  3482                              <1> 	;(EAX, ECX, EDI will be changed)
  3483                              <1>   
  3484 00008F0F 56                  <1> 	push	esi
  3485                              <1> 
  3486 00008F10 BF[A2350100]        <1>         mov     edi, invalid_fname_chars
  3487 00008F15 AC                  <1> 	lodsb
  3488                              <1> check_filename_next_char:
  3489 00008F16 B914000000          <1> 	mov	ecx, sizeInvFnChars
  3490 00008F1B BF[A2350100]        <1> 	mov	edi, invalid_fname_chars
  3491                              <1> loc_scan_invalid_filename_char:
  3492 00008F20 AE                  <1> 	scasb 
  3493 00008F21 741E                <1> 	je	short loc_invalid_filename_stc
  3494 00008F23 E2FB                <1> 	loop	loc_scan_invalid_filename_char
  3495 00008F25 AC                  <1> 	lodsb
  3496 00008F26 3C1F                <1> 	cmp	al, 1Fh  ; 20h and above 
  3497 00008F28 77EC                <1> 	ja	short check_filename_next_char
  3498                              <1> 
  3499                              <1> check_filename_dot:
  3500 00008F2A 8B3424              <1> 	mov	esi, [esp]
  3501                              <1> 
  3502 00008F2D B421                <1> 	mov	ah, 21h
  3503                              <1> 	;mov	ecx, 8
  3504                              <1> 	; 28/07/2022
  3505 00008F2F 29C9                <1> 	sub	ecx, ecx
  3506 00008F31 B108                <1> 	mov	cl, 8
  3507                              <1> loc_check_filename_next_char:
  3508 00008F33 AC                  <1> 	lodsb
  3509 00008F34 3C2E                <1> 	cmp	al, 2Eh
  3510 00008F36 7511                <1> 	jne	short pass_check_fn_dot_check
  3511                              <1> loc_check_filename_ext_0:
  3512 00008F38 AC                  <1> 	lodsb
  3513 00008F39 38E0                <1> 	cmp	al, ah ; 21h
  3514 00008F3B 7205                <1> 	jb	short loc_invalid_filename
  3515 00008F3D 3C2E                <1> 	cmp	al, 2Eh
  3516 00008F3F 7519                <1> 	jne	short loc_check_filename_ext_1
  3517                              <1> 
  3518                              <1> loc_invalid_filename_stc:
  3519                              <1> loc_check_fn_stc_rtn:
  3520 00008F41 F9                  <1> 	stc
  3521                              <1> loc_invalid_filename:
  3522                              <1> 	; 10/10/2016 (0Bh -> 26)
  3523 00008F42 B81A000000          <1> 	mov	eax, ERR_INV_FILE_NAME ; (=26)
  3524                              <1> 	; Invalid file name chars
  3525                              <1> loc_check_fn_rtn:
  3526 00008F47 5E                  <1> 	pop	esi
  3527 00008F48 C3                  <1> 	retn
  3528                              <1> 
  3529                              <1> pass_check_fn_dot_check:
  3530 00008F49 38E0                <1> 	cmp	al, ah ; 21h
  3531 00008F4B 7224                <1> 	jb	short loc_check_fn_clc_rtn
  3532 00008F4D E2E4                <1> 	loop	loc_check_filename_next_char
  3533 00008F4F AC                  <1> 	lodsb
  3534 00008F50 38E0                <1> 	cmp	al, ah ; 21h
  3535 00008F52 721D                <1> 	jb	short loc_check_fn_clc_rtn
  3536 00008F54 3C2E                <1> 	cmp	al, 2Eh
  3537 00008F56 75E9                <1> 	jne	short loc_check_fn_stc_rtn
  3538 00008F58 EBDE                <1> 	jmp	short loc_check_filename_ext_0
  3539                              <1> 
  3540                              <1> loc_check_filename_ext_1:
  3541 00008F5A AC                  <1> 	lodsb
  3542 00008F5B 38E0                <1> 	cmp	al, ah ; 21h
  3543 00008F5D 7212                <1> 	jb	short loc_check_fn_clc_rtn
  3544 00008F5F 3C2E                <1> 	cmp	al, 2Eh
  3545 00008F61 74DE                <1> 	je	short loc_check_fn_stc_rtn
  3546 00008F63 AC                  <1> 	lodsb
  3547 00008F64 38E0                <1> 	cmp	al, ah ; 21h
  3548 00008F66 7209                <1> 	jb	short loc_check_fn_clc_rtn
  3549 00008F68 3C2E                <1> 	cmp	al, 2Eh
  3550 00008F6A 74D5                <1> 	je	short loc_check_fn_stc_rtn
  3551 00008F6C AC                  <1> 	lodsb
  3552 00008F6D 38E0                <1> 	cmp	al, ah ; 21h
  3553 00008F6F 73D0                <1> 	jnb	short loc_check_fn_stc_rtn
  3554                              <1> 
  3555                              <1> loc_check_fn_clc_rtn:
  3556 00008F71 5E                  <1> 	pop	esi
  3557 00008F72 F8                  <1> 	clc
  3558 00008F73 C3                  <1> 	retn
  3559                              <1> 
  3560                              <1> loc_print_deleted_message:
  3561 00008F74 BE[8F390100]        <1> 	mov	esi, Msg_Deleted
  3562 00008F79 E8ECDDFFFF          <1> 	call	print_msg
  3563                              <1> 
  3564                              <1> 	;clc
  3565                              <1> 
  3566                              <1> loc_file_rw_restore_retn:
  3567                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
  3568                              <1> 	; 28/02/2010 (CMD_INTR.ASM)
  3569                              <1> loc_file_rw_cmd_failed:
  3570 00008F7E 9C                  <1> 	pushf 
  3571 00008F7F E853F7FFFF          <1> 	call	restore_cdir_after_cmd_fail
  3572 00008F84 9D                  <1> 	popf
  3573 00008F85 720D                <1> 	jc	short loc_file_rw_check_write_fault
  3574 00008F87 C3                  <1> 	retn
  3575                              <1> 
  3576                              <1> loc_permission_denied:
  3577                              <1> 	; 27/02/2016
  3578 00008F88 BE[9C390100]        <1> 	mov	esi, Msg_Permission_Denied
  3579 00008F8D E8D8DDFFFF          <1> 	call	print_msg
  3580 00008F92 EBEA                <1> 	jmp	short loc_file_rw_restore_retn
  3581                              <1> 
  3582                              <1> loc_file_rw_check_write_fault:
  3583                              <1> 	;cmp	al, 1Dh ; Write Fault
  3584 00008F94 3C12                <1>         cmp	al, 18 ; 05/11/2016
  3585                              <1> 	;jne	loc_run_cmd_failed_cmp_al
  3586                              <1> 	; 28/07/2022
  3587 00008F96 7405                <1> 	je	short loc_file_rw_fault
  3588 00008F98 E9D7F6FFFF          <1> 	jmp	loc_run_cmd_failed_cmp_al
  3589                              <1> 
  3590                              <1> loc_file_rw_fault:
  3591 00008F9D BE[83370100]        <1> 	mov	esi, Msg_Not_Ready_Write_Err
  3592                              <1> 	;call	print_msg
  3593                              <1> 	;retn
  3594 00008FA2 E9C3DDFFFF          <1> 	jmp	print_msg
  3595                              <1> 
  3596                              <1> make_directory:
  3597                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
  3598                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
  3599                              <1> 	; 12/03/2011 (CMD_INTR.ASM, 'cmp_cmd_mkdir')
  3600                              <1> 	; 14/08/2010
  3601                              <1> 	; 10/07/2010
  3602                              <1> 	; 29/11/2009
  3603                              <1> 	;
  3604                              <1> get_mkdir_fchar:
  3605                              <1> 	; esi = directory name
  3606 00008FA7 803E20              <1> 	cmp	byte [esi], 20h
  3607 00008FAA 7701                <1>         ja	short loc_mkdir_parse_path_name
  3608                              <1> 
  3609                              <1> loc_mkdir_nodirname_retn:
  3610 00008FAC C3                  <1> 	retn
  3611                              <1> 
  3612                              <1> loc_mkdir_parse_path_name:
  3613 00008FAD BF[22860100]        <1> 	mov	edi, FindFile_Drv
  3614 00008FB2 E8631C0000          <1>         call    parse_path_name
  3615                              <1> 	;jc	loc_cmd_failed
  3616                              <1> 	; 28/07/2022
  3617 00008FB7 7305                <1> 	jnc	short loc_mkdir_check_dirname_exists
  3618                              <1> loc_mkdir_cmd_failed:
  3619 00008FB9 E986F6FFFF          <1> 	jmp	loc_cmd_failed
  3620                              <1> 
  3621                              <1> loc_mkdir_check_dirname_exists:
  3622 00008FBE BE[64860100]        <1> 	mov	esi, FindFile_Name
  3623 00008FC3 803E20              <1> 	cmp	byte [esi], 20h
  3624                              <1> 	;jna	loc_cmd_failed
  3625                              <1> 	; 28/07/2022
  3626 00008FC6 76F1                <1> 	jna	short loc_mkdir_cmd_failed
  3627 00008FC8 8935[E0860100]      <1> 	mov	[DelFile_FNPointer], esi
  3628 00008FCE E83CFFFFFF          <1> 	call	check_filename
  3629 00008FD3 725B                <1> 	jc	short loc_mkdir_invalid_dir_name_chars
  3630                              <1> 
  3631                              <1> loc_mkdir_drv:
  3632 00008FD5 8A35[827D0100]      <1> 	mov	dh, [Current_Drv]
  3633 00008FDB 8835[DF840100]      <1> 	mov	[RUN_CDRV], dh
  3634                              <1> 	
  3635 00008FE1 8A15[22860100]      <1> 	mov	dl, [FindFile_Drv]
  3636 00008FE7 38F2                <1> 	cmp	dl, dh
  3637 00008FE9 7409                <1> 	je	short loc_mkdir_change_directory
  3638                              <1> 
  3639 00008FEB E88DE8FFFF          <1> 	call	change_current_drive
  3640                              <1> 	;jc	loc_file_rw_cmd_failed
  3641                              <1> 	; 28/07/2022
  3642 00008FF0 7302                <1> 	jnc	short loc_mkdir_change_directory
  3643 00008FF2 EB8A                <1> 	jmp	loc_file_rw_cmd_failed
  3644                              <1> 
  3645                              <1> loc_mkdir_change_directory:
  3646 00008FF4 803D[23860100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  3647 00008FFB 7614                <1> 	jna	short loc_mkdir_find_directory
  3648                              <1> 
  3649 00008FFD FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  3650 00009003 BE[23860100]        <1> 	mov	esi, FindFile_Directory
  3651 00009008 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0
  3652 0000900A E821160000          <1> 	call	change_current_directory
  3653 0000900F 7226                <1> 	jc	short loc_mkdir_check_error_code
  3654                              <1> 
  3655                              <1> ;loc_mkdir_change_prompt_dir_string:
  3656                              <1> 	;call	change_prompt_dir_string
  3657                              <1> 
  3658                              <1> loc_mkdir_find_directory:
  3659                              <1> 	;mov	esi, FindFile_Name
  3660 00009011 8B35[E0860100]      <1> 	mov	esi, [DelFile_FNPointer]
  3661                              <1> 	;xor	eax, eax
  3662 00009017 6631C0              <1> 	xor	ax, ax ; any name (dir, file, volume)
  3663 0000901A E84BFBFFFF          <1> 	call	find_first_file
  3664 0000901F 7216                <1> 	jc	short loc_mkdir_check_error_code
  3665                              <1> 
  3666                              <1> loc_mkdir_directory_found:
  3667 00009021 BE[E7380100]        <1> 	mov	esi, Msg_Name_Exists
  3668                              <1> loc_mkdir_inv_dname_chrs_msg:
  3669 00009026 E83FDDFFFF          <1> 	call	print_msg
  3670 0000902B E94EFFFFFF          <1> 	jmp	loc_file_rw_restore_retn
  3671                              <1> 
  3672                              <1> loc_mkdir_invalid_dir_name_chars:
  3673 00009030 BE[BA380100]        <1> 	mov	esi, Msg_invalid_name_chars
  3674                              <1> 	;call	print_msg
  3675                              <1>         ;jmp	loc_file_rw_restore_retn
  3676                              <1> 	; 28/07/2022
  3677 00009035 EBEF                <1> 	jmp	short loc_mkdir_inv_dname_chrs_msg
  3678                              <1> 
  3679                              <1> loc_mkdir_check_error_code:
  3680 00009037 3C02                <1> 	cmp	al, 2
  3681                              <1> 	;je	short loc_mkdir_directory_not_found
  3682 00009039 7406                <1> 	je	short loc_mkdir_ask_for_yes_no
  3683 0000903B F9                  <1> 	stc
  3684 0000903C E93DFFFFFF          <1>         jmp     loc_file_rw_cmd_failed
  3685                              <1> 
  3686                              <1> loc_mkdir_directory_not_found:
  3687                              <1> loc_mkdir_ask_for_yes_no:
  3688 00009041 BE[08390100]        <1> 	mov	esi, Msg_DoYouWantMkdir
  3689 00009046 E81FDDFFFF          <1> 	call	print_msg
  3690 0000904B 8B35[E0860100]      <1> 	mov	esi, [DelFile_FNPointer]
  3691 00009051 E814DDFFFF          <1> 	call	print_msg
  3692 00009056 BE[27390100]        <1> 	mov	esi, Msg_YesNo
  3693 0000905B E80ADDFFFF          <1> 	call	print_msg
  3694                              <1> 
  3695 00009060 C605[31390100]20    <1> 	mov	byte [Y_N_nextline], 20h
  3696                              <1> 
  3697                              <1> loc_mkdir_ask_again:
  3698 00009067 30E4                <1> 	xor	ah, ah
  3699 00009069 E8AE7EFFFF          <1> 	call	int16h
  3700 0000906E 3C1B                <1> 	cmp	al, 1Bh
  3701                              <1> 	;je	short loc_do_not_make_directory
  3702 00009070 743B                <1> 	je	short loc_mkdir_y_n_escape
  3703 00009072 24DF                <1> 	and	al, 0DFh ; y -> Y, n -> N
  3704 00009074 3C59                <1> 	cmp	al, 'Y' ; 'yes'
  3705 00009076 7404                <1> 	je	short loc_mkdir_yes_make_directory
  3706 00009078 3C4E                <1> 	cmp	al, 'N' ; 'no'
  3707 0000907A 75EB                <1> 	jne	short loc_mkdir_ask_again
  3708                              <1> 
  3709                              <1> loc_do_not_make_directory:
  3710                              <1> loc_mkdir_yes_make_directory:
  3711 0000907C E830000000          <1> 	call	y_n_answer ; 29/12/2017
  3712                              <1> 	;cmp	al, 'Y' ; 'yes'
  3713                              <1> 	;cmc
  3714                              <1>         ;jnc	loc_file_rw_restore_retn
  3715 00009081 3C4E                <1> 	cmp	al, 'N' ; 'no'
  3716                              <1> 	;je	loc_file_rw_restore_retn
  3717                              <1> 	; 28/07/2022
  3718 00009083 7505                <1> 	jne	short loc_mkdir_call_make_sub_dir
  3719 00009085 E9F4FEFFFF          <1> 	jmp	loc_file_rw_restore_retn
  3720                              <1> 
  3721                              <1> loc_mkdir_call_make_sub_dir:
  3722 0000908A 8B35[E0860100]      <1> 	mov	esi, [DelFile_FNPointer]
  3723 00009090 B110                <1> 	mov	cl, 10h ; Directory attributes 
  3724 00009092 E8721C0000          <1> 	call	make_sub_directory
  3725                              <1> loc_rename_file_ok: ; 06/03/2016
  3726                              <1>         ;jc	loc_file_rw_cmd_failed
  3727                              <1> 	; 28/07/2022
  3728 00009097 7305                <1> 	jnc	short move_source_file_to_dest_OK
  3729 00009099 E9E0FEFFFF          <1> 	jmp	loc_file_rw_cmd_failed
  3730                              <1> move_source_file_to_dest_OK:
  3731 0000909E BE[35390100]        <1> 	mov	esi, Msg_OK
  3732 000090A3 E8C2DCFFFF          <1> 	call	print_msg
  3733 000090A8 E9D1FEFFFF          <1> 	jmp	loc_file_rw_restore_retn
  3734                              <1> 
  3735                              <1> loc_mkdir_y_n_escape:
  3736 000090AD B04E                <1> 	mov	al, 'N' ; 'no'
  3737 000090AF EBCB                <1> 	jmp	short loc_do_not_make_directory
  3738                              <1> 
  3739                              <1> y_n_answer:
  3740                              <1> 	; 29/12/2017
  3741 000090B1 A2[31390100]        <1> 	mov	[Y_N_nextline], al
  3742                              <1> 	;push	ax
  3743 000090B6 50                  <1> 	push	eax
  3744 000090B7 BE[31390100]        <1> 	mov	esi, Y_N_nextline
  3745 000090BC E8A9DCFFFF          <1> 	call	print_msg
  3746 000090C1 58                  <1> 	pop	eax
  3747                              <1> 	;pop	ax
  3748 000090C2 C3                  <1> 	retn
  3749                              <1> 
  3750                              <1> delete_directory:
  3751                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
  3752                              <1> 	; 29/12/2017
  3753                              <1> 	; 15/10/2016
  3754                              <1> 	; 01/03/2016, 06/03/2016
  3755                              <1> 	; 27/02/2016, 28/02/2016, 29/02/2016
  3756                              <1> 	; 26/02/2016 (TRDOS 386 = TRDOS v2.0)
  3757                              <1> 	; 16/10/2010 (CMD_INTR.ASM, 'cmp_cmd_rmdir')
  3758                              <1> 	; 05/06/2010
  3759                              <1> 	;
  3760                              <1> get_fchar:
  3761                              <1> 	; esi = directory name
  3762 000090C3 803E20              <1> 	cmp	byte [esi], 20h
  3763 000090C6 7701                <1>         ja	short loc_rmdir_parse_path_name
  3764                              <1> 
  3765                              <1> loc_rmdir_nodirname_retn:
  3766 000090C8 C3                  <1> 	retn
  3767                              <1> 
  3768                              <1> loc_rmdir_parse_path_name:
  3769 000090C9 BF[22860100]        <1> 	mov	edi, FindFile_Drv
  3770 000090CE E8471B0000          <1> 	call	parse_path_name
  3771                              <1> 	;jc	loc_cmd_failed
  3772                              <1> 	; 28/07/2022
  3773 000090D3 7305                <1> 	jnc	short loc_rmdir_check_dirname_exists
  3774                              <1> lc_del_dir_failed:
  3775 000090D5 E96AF5FFFF          <1> 	jmp	loc_cmd_failed
  3776                              <1> 
  3777                              <1> loc_rmdir_check_dirname_exists:
  3778 000090DA BE[64860100]        <1> 	mov	esi, FindFile_Name
  3779 000090DF 803E20              <1> 	cmp	byte [esi], 20h
  3780                              <1> 	;jna	loc_cmd_failed
  3781                              <1> 	; 28/07/2022
  3782 000090E2 76F1                <1> 	jna	short lc_del_dir_failed
  3783 000090E4 8935[E0860100]      <1> 	mov	[DelFile_FNPointer], esi
  3784                              <1> 
  3785                              <1> loc_rmdir_drv:
  3786 000090EA 8A35[827D0100]      <1> 	mov	dh, [Current_Drv]
  3787 000090F0 8835[DF840100]      <1> 	mov	[RUN_CDRV], dh
  3788                              <1> 
  3789 000090F6 8A15[22860100]      <1> 	mov	dl, [FindFile_Drv]
  3790 000090FC 38F2                <1> 	cmp	dl, dh
  3791 000090FE 7407                <1> 	je	short loc_rmdir_change_directory
  3792                              <1> 
  3793 00009100 E878E7FFFF          <1> 	call	change_current_drive
  3794                              <1> 	;jc	loc_file_rw_cmd_failed
  3795                              <1> 	; 28/07/2022
  3796                              <1> 	;jnc	short loc_rmdir_change_directory
  3797                              <1> 	;jmp	loc_file_rw_cmd_failed
  3798 00009105 7233                <1> 	jc	short loc_rmdir_chdrv_failed
  3799                              <1> 
  3800                              <1> loc_rmdir_change_directory:
  3801 00009107 803D[23860100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  3802 0000910E 7614                <1> 	jna	short loc_rmdir_find_directory
  3803                              <1> 
  3804 00009110 FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  3805 00009116 BE[23860100]        <1> 	mov	esi, FindFile_Directory
  3806 0000911B 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0
  3807 0000911D E80E150000          <1> 	call	change_current_directory
  3808 00009122 7211                <1> 	jc	short loc_rmdir_check_error_code
  3809                              <1> 
  3810                              <1> ;loc_rmdir_change_prompt_dir_string:
  3811                              <1> 	;call	change_prompt_dir_string
  3812                              <1> 
  3813                              <1> loc_rmdir_find_directory:
  3814                              <1> 	;mov	esi, FindFile_Name
  3815 00009124 8B35[E0860100]      <1> 	mov	esi, [DelFile_FNPointer]
  3816 0000912A 66B81008            <1> 	mov	ax, 0810h ; Only directories
  3817 0000912E E837FAFFFF          <1> 	call	find_first_file
  3818 00009133 730A                <1> 	jnc	short loc_rmdir_ambgfn_check
  3819                              <1> 
  3820                              <1> loc_rmdir_check_error_code:
  3821 00009135 3C02                <1> 	cmp	al, 2
  3822 00009137 740B                <1> 	je	short loc_rmdir_directory_not_found
  3823 00009139 F9                  <1> 	stc
  3824                              <1> loc_rmdir_chdrv_failed:
  3825 0000913A E93FFEFFFF          <1> 	jmp	loc_file_rw_cmd_failed
  3826                              <1> 
  3827                              <1> loc_rmdir_ambgfn_check:
  3828 0000913F 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3829 00009142 740F                <1> 	jz	short loc_rmdir_directory_found
  3830                              <1> 
  3831                              <1> loc_rmdir_directory_not_found:
  3832 00009144 BE[A5370100]        <1> 	mov	esi, Msg_Dir_Not_Found
  3833 00009149 E81CDCFFFF          <1> 	call	print_msg
  3834                              <1> 
  3835 0000914E E92BFEFFFF          <1> 	jmp	loc_file_rw_restore_retn
  3836                              <1> 
  3837                              <1> loc_rmdir_directory_found:
  3838 00009153 80E307              <1> 	and	bl, 07h ; Attributes
  3839                              <1> 	;jnz	loc_permission_denied
  3840                              <1> 	; 28/07/2022
  3841 00009156 7405                <1> 	jz	short loc_rmdir_save_lnel
  3842 00009158 E92BFEFFFF          <1> 	jmp	loc_permission_denied
  3843                              <1> 
  3844                              <1> loc_rmdir_save_lnel: ; 28/02/2016
  3845                              <1>        ;mov	bh, [LongName_EntryLength]
  3846 0000915D 883D[EA860100]      <1> 	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
  3847                              <1> 	; edi = Directory Entry Offset (DirBuff)
  3848                              <1> 	; esi = Directory Entry (FFF Structure)
  3849                              <1> 	;mov	[DelFile_DirEntryAddr], edi ; not required
  3850                              <1> 	;mov	ax, [edi+20] ; First Cluster High Word
  3851                              <1>         ;shl	eax, 16
  3852                              <1> 	;mov	ax, [edi+26] ; First Cluster Low Word
  3853                              <1> 	; ROOT Dir First Cluster = 0
  3854                              <1>         ;cmp	eax, 2
  3855                              <1> 	;jb	loc_update_direntry_1
  3856                              <1> 
  3857                              <1> pass_rmdir_fc_check:
  3858 00009163 57                  <1> 	push	edi ; * (29/02/2016)
  3859                              <1> 
  3860 00009164 BE[3B390100]        <1> 	mov	esi, Msg_DoYouWantRmDir
  3861 00009169 E8FCDBFFFF          <1> 	call	print_msg
  3862 0000916E 8B35[E0860100]      <1> 	mov	esi, [DelFile_FNPointer]
  3863 00009174 E8F1DBFFFF          <1> 	call	print_msg
  3864 00009179 BE[27390100]        <1> 	mov	esi, Msg_YesNo
  3865 0000917E E8E7DBFFFF          <1> 	call	print_msg
  3866                              <1> 
  3867                              <1> loc_rmdir_ask_again:
  3868 00009183 30E4                <1> 	xor	ah, ah
  3869 00009185 E8927DFFFF          <1> 	call	int16h
  3870 0000918A 3C1B                <1> 	cmp	al, 1Bh
  3871                              <1> 	;je	short loc_do_not_delete_directory
  3872 0000918C 742F                <1>         je	short loc_rmdir_y_n_escape ; 06/03/2016
  3873 0000918E 24DF                <1> 	and	al, 0DFh
  3874 00009190 A2[31390100]        <1> 	mov	[Y_N_nextline], al
  3875 00009195 3C59                <1> 	cmp	al, 'Y'
  3876 00009197 7404                <1> 	je	short loc_rmdir_yes_delete_directory
  3877 00009199 3C4E                <1> 	cmp	al, 'N'
  3878 0000919B 75E6                <1> 	jne	short loc_rmdir_ask_again
  3879                              <1> 
  3880                              <1> loc_do_not_delete_directory:
  3881                              <1> loc_rmdir_yes_delete_directory:
  3882 0000919D E80FFFFFFF          <1> 	call	y_n_answer ; 29/12/2017
  3883 000091A2 5F                  <1> 	pop	edi ; * (29/02/2016)
  3884                              <1> 	;cmp	al, 'Y' ; 'yes'
  3885                              <1> 	;cmc
  3886                              <1>         ;jnc	loc_file_rw_restore_retn
  3887 000091A3 3C4E                <1> 	cmp	al, 'N' ; 'no'
  3888                              <1> 	;je	loc_file_rw_restore_retn
  3889                              <1> 	; 28/07/2022
  3890                              <1> 	;jne	short loc_delete_sub_dir
  3891                              <1> 	;jmp	loc_file_rw_restore_retn
  3892 000091A5 7411                <1> 	je	short loc_rmdir_rw_restore_retn
  3893                              <1> 
  3894                              <1> loc_delete_sub_dir:
  3895                              <1> 	; 29/12/2017
  3896 000091A7 E85E000000          <1> 	call	delete_sub_directory
  3897 000091AC 7213                <1> 	jc	short loc_rmdir_cmd_failed
  3898                              <1> 
  3899                              <1> loc_rmdir_ok:
  3900 000091AE BE[35390100]        <1> 	mov	esi, Msg_OK
  3901 000091B3 E8B2DBFFFF          <1> 	call	print_msg
  3902                              <1> loc_rmdir_rw_restore_retn: ; 28/07/2022
  3903 000091B8 E9C1FDFFFF          <1> 	jmp	loc_file_rw_restore_retn
  3904                              <1> 
  3905                              <1> loc_rmdir_y_n_escape:
  3906 000091BD B04E                <1> 	mov	al, 'N' ; 'no'
  3907 000091BF EBDC                <1>         jmp     loc_do_not_delete_directory
  3908                              <1> 
  3909                              <1> loc_rmdir_cmd_failed:
  3910                              <1> 	; 29/12/2017
  3911 000091C1 09C0                <1> 	or	eax, eax ; EAX = 0 -> Directory not empty!
  3912 000091C3 7423                <1> 	jz	short loc_rmdir_directory_not_empty
  3913                              <1> 
  3914                              <1> 	; EAX > 0 -> Error code in AL (or AX or EAX)
  3915                              <1> 
  3916 000091C5 833D[9E840100]01    <1> 	cmp	dword [FAT_ClusterCounter], 1
  3917                              <1> 	;jb	loc_file_rw_cmd_failed
  3918                              <1> 	; 28/07/2022
  3919 000091CC 7305                <1> 	jnb	short loc_rmdir_failed
  3920 000091CE E9ABFDFFFF          <1> 	jmp	loc_file_rw_cmd_failed
  3921                              <1> 
  3922                              <1> loc_rmdir_failed:
  3923 000091D3 F9                  <1> 	stc
  3924                              <1> loc_rmdir_cmd_return:
  3925                              <1> 	; 01/03/2016
  3926 000091D4 9C                  <1> 	pushf
  3927                              <1> 	; ESI = Logical DOS Drive Description Table address
  3928 000091D5 66BB00FF            <1> 	mov	bx, 0FF00h ; BH = FFh -> use ESI for Drive parameters
  3929                              <1> 	           ; BL = 0 -> Recalculate free cluster count
  3930 000091D9 50                  <1> 	push	eax
  3931 000091DA E835370000          <1> 	call	calculate_fat_freespace	
  3932 000091DF 58                  <1> 	pop	eax
  3933 000091E0 9D                  <1> 	popf
  3934                              <1> 	;jc	loc_file_rw_cmd_failed
  3935                              <1> 	;jmp	loc_file_rw_restore_retn
  3936                              <1> 	; 28/07/2022
  3937 000091E1 73D5                <1> 	jnc	short loc_rmdir_rw_restore_retn
  3938 000091E3 E996FDFFFF          <1> 	jmp	loc_file_rw_cmd_failed
  3939                              <1> 
  3940                              <1> loc_rmdir_directory_not_empty:
  3941 000091E8 BE[5C390100]        <1> 	mov	esi, Msg_Dir_Not_Empty
  3942 000091ED E878DBFFFF          <1> 	call	print_msg
  3943                              <1> 	; 01/03/2016
  3944 000091F2 A1[9E840100]        <1> 	mov	eax, [FAT_ClusterCounter]
  3945 000091F7 09C0                <1> 	or	eax, eax ; 0 ?
  3946                              <1> 	;jz	loc_file_rw_restore_retn
  3947                              <1> 	; 28/07/2022
  3948 000091F9 74BD                <1> 	jz	short loc_rmdir_rw_restore_retn	
  3949                              <1> 
  3950                              <1> 	; ESI = Logical DOS Drive Description Table address
  3951 000091FB 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> use ESI for Drive parameters
  3952                              <1> 	           ; BL = 1 -> add free clusters
  3953 000091FF E810370000          <1> 	call	calculate_fat_freespace
  3954 00009204 09C9                <1> 	or	ecx, ecx
  3955                              <1> 	;jz	loc_file_rw_restore_retn ; ecx = 0 -> OK
  3956                              <1> 	;; ecx > 0 -> Error (Recalculation is needed)
  3957                              <1> 	;jmp	short loc_rmdir_cmd_return
  3958                              <1> 	; 28/07/2022
  3959 00009206 75CC                <1> 	jnz	short loc_rmdir_cmd_return
  3960 00009208 EBAE                <1> 	jmp	short loc_rmdir_rw_restore_retn
  3961                              <1> 	;jmp	loc_file_rw_restore_retn
  3962                              <1> 
  3963                              <1> 
  3964                              <1> delete_sub_directory:
  3965                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
  3966                              <1> 	; 29/12/2017 
  3967                              <1> 	; (moved here from 'delete_directory' for 'sysrmdir' )
  3968                              <1> 
  3969                              <1> 	; EDI = Directory buffer entry offset/address
  3970                              <1> 
  3971                              <1> loc_rmdir_delete_short_name_check_dir_empty:
  3972 0000920A 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
  3973 0000920E C1E010              <1>         shl	eax, 16
  3974 00009211 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
  3975                              <1> 
  3976                              <1> 	;mov 	[DelFile_FCluster], eax
  3977                              <1> 
  3978                              <1> 	;;mov	bx, [DirBuff_EntryCounter]
  3979                              <1> 	;mov	bx, [FindFile_DirEntryNumber] ; 27/02/2016
  3980                              <1> 	;mov	[DelFile_EntryCounter], bx
  3981                              <1> 
  3982 00009215 29DB                <1>     	sub	ebx, ebx
  3983                              <1> 	; 29/12/2017
  3984 00009217 891D[9E840100]      <1> 	mov	[FAT_ClusterCounter], ebx ; 0 ; Reset
  3985                              <1> 
  3986 0000921D 8A3D[22860100]      <1> 	mov	bh, [FindFile_Drv]
  3987 00009223 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  3988 00009228 01DE                <1> 	add	esi, ebx
  3989                              <1> 
  3990 0000922A 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h
  3991 00009230 745A                <1> 	je	short loc_rmdir_check_fs_directory
  3992                              <1> 
  3993                              <1> 	;cmp	byte [esi+LD_FATType], 1
  3994                              <1> 	;jb	short loc_rmdir_get__last_cluster_0
  3995                              <1> 
  3996                              <1> 	; 29/12/2017
  3997 00009232 83F802              <1> 	cmp	eax, 2
  3998 00009235 7306                <1> 	jnb	short loc_rmdir_get_last_cluster_1
  3999                              <1> 	; eax < 2
  4000                              <1> loc_rmdir_get_last_cluster_0:
  4001                              <1> 	;mov	eax, ERR_INV_FORMAT ; invalid format!
  4002 00009237 B813000000          <1> 	mov	eax, ERR_NOT_DIR ; not a valid directory!
  4003                              <1> 	;stc
  4004 0000923C C3                  <1> 	retn
  4005                              <1> 
  4006                              <1> loc_rmdir_get_last_cluster_1:
  4007 0000923D 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3 ; FAT32
  4008 00009241 750C                <1> 	jne	short loc_rmdir_get_last_cluster_2
  4009                              <1> 
  4010                              <1> 	; is it root directory ?
  4011 00009243 3B4632              <1> 	cmp	eax, [esi+LD_BPB+BPB_RootClus]
  4012 00009246 7507                <1> 	jne	short loc_rmdir_get_last_cluster_2
  4013                              <1> 
  4014                              <1> 	; root directory can not be deleted !!
  4015                              <1> loc_rmdir_permission_denied:
  4016 00009248 B80B000000          <1> 	mov	eax, ERR_PERM_DENIED ; permission denied!
  4017 0000924D F9                  <1> 	stc
  4018 0000924E C3                  <1> 	retn
  4019                              <1> 
  4020                              <1> loc_rmdir_get_last_cluster_2:
  4021                              <1> 	; 29/12/2017
  4022 0000924F A3[E4860100]        <1> 	mov 	[DelFile_FCluster], eax
  4023                              <1> 
  4024                              <1> 	;mov	dx, [DirBuff_EntryCounter]
  4025 00009254 668B15[9C860100]    <1> 	mov	dx, [FindFile_DirEntryNumber] ; 27/02/2016
  4026 0000925B 668915[E8860100]    <1> 	mov	[DelFile_EntryCounter], dx
  4027                              <1> 
  4028 00009262 8B15[AE840100]      <1> 	mov	edx, [DirBuff_Cluster]
  4029 00009268 8915[14870100]      <1> 	mov	[RmDir_ParentDirCluster], edx
  4030                              <1> 
  4031 0000926E 893D[10870100]      <1> 	mov	[RmDir_DirEntryOffset], edi
  4032                              <1> 
  4033                              <1> 	; 01/03/2016
  4034                              <1> 	;mov	dword [FAT_ClusterCounter], 0 ; Reset
  4035                              <1> 
  4036                              <1> loc_rmdir_get_last_cluster_3:
  4037 00009274 E819380000          <1> 	call	get_last_cluster
  4038                              <1>         ;jc	loc_rmdir_cmd_failed
  4039 00009279 721E                <1> 	jc	short loc_delete_sub_dir_retn ; 29/12/2017
  4040                              <1> 
  4041 0000927B 3B05[E4860100]      <1> 	cmp	eax, [DelFile_FCluster]
  4042 00009281 7517                <1> 	jne	short loc_rmdir_multi_dir_clusters
  4043                              <1> 
  4044 00009283 C605[0F870100]00    <1> 	mov	byte [RmDir_MultiClusters], 0
  4045 0000928A EB15                <1> 	jmp	short pass_rmdir_multi_dir_clusters
  4046                              <1> 
  4047                              <1> loc_rmdir_check_fs_directory:
  4048                              <1> 	; 29/12/2017
  4049 0000928C 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
  4050 00009290 75B6                <1> 	jne	short loc_rmdir_permission_denied
  4051                              <1> 
  4052                              <1> loc_rmdir_delete_fs_directory:
  4053 00009292 E8BF120000          <1> 	call	delete_fs_directory
  4054                              <1> 	;jnc	loc_print_deleted_message
  4055 00009297 7300                <1> 	jnc	short loc_delete_sub_dir_retn ; 29/12/2017
  4056                              <1> 
  4057                              <1> 	; EAX=0 -> Directory not empty !
  4058                              <1> 	; EAX>0 -> Disk r/w error or another (misc) error
  4059                              <1> 
  4060                              <1> 	;or	eax, eax
  4061                              <1> 	;jz	loc_rmdir_directory_not_empty_2
  4062                              <1> 	;;stc
  4063                              <1> 	;;jmp	loc_file_rw_cmd_failed
  4064                              <1> 	
  4065                              <1> loc_delete_sub_dir_retn:
  4066 00009299 C3                  <1> 	retn
  4067                              <1> 
  4068                              <1> loc_rmdir_multi_dir_clusters:
  4069 0000929A C605[0F870100]01    <1> 	mov	byte [RmDir_MultiClusters], 1
  4070                              <1> 
  4071                              <1> pass_rmdir_multi_dir_clusters:
  4072 000092A1 A3[18870100]        <1> 	mov 	[RmDir_DirLastCluster], eax
  4073 000092A6 890D[1C870100]      <1> 	mov	[RmDir_PreviousCluster], ecx
  4074                              <1> 
  4075                              <1> loc_rmdir_load_fat_sub_directory:
  4076 000092AC E82B320000          <1> 	call	load_FAT_sub_directory
  4077                              <1> 	;jc	loc_rmdir_cmd_failed
  4078 000092B1 72E6                <1> 	jc	short loc_delete_sub_dir_retn
  4079                              <1> 
  4080                              <1> loc_rmdir_find_last_dir_entry:
  4081 000092B3 56                  <1> 	push	esi
  4082 000092B4 BE[06860100]        <1> 	mov	esi, Dir_File_Name
  4083 000092B9 C6062A              <1> 	mov	byte [esi], '*'
  4084 000092BC C646082A            <1> 	mov	byte [esi+8], '*'
  4085 000092C0 31DB                <1> 	xor	ebx, ebx ; Entry offset  = 0
  4086                              <1> loc_rmdir_find_last_dir_entry_next:
  4087                              <1> 	;mov	ax, 0800h ; Except volume/long names
  4088                              <1> 	;xor	cx, cx ; 0 = Find a valid file or dir name
  4089                              <1> 	; 28/07/2022
  4090 000092C2 31C0                <1> 	xor	eax, eax
  4091 000092C4 B408                <1> 	mov	ah, 8
  4092                              <1> 	; eax = 0800h
  4093 000092C6 31C9                <1> 	xor	ecx, ecx ; 0
  4094 000092C8 E8B2160000          <1> 	call	find_directory_entry
  4095 000092CD 7225                <1> 	jc	short loc_rmdir_empty_dir_cluster
  4096 000092CF 83FB01              <1> 	cmp	ebx, 1
  4097 000092D2 771B                <1> 	ja	short loc_rmdir_directory_not_empty_1
  4098                              <1> loc_rmdir_dot_entry_check:
  4099 000092D4 80FD2E              <1> 	cmp	ch, '.' ; The first char of the dir entry
  4100 000092D7 7516                <1> 	jne	short loc_rmdir_directory_not_empty_1
  4101 000092D9 08DB                <1> 	or	bl, bl
  4102 000092DB 7506                <1> 	jnz	short loc_rmdir_dotdot_entry_check
  4103 000092DD 807F0120            <1> 	cmp	byte [edi+1], 20h
  4104 000092E1 EB06                <1> 	jmp	short pass_rmdir_dot_entry_check
  4105                              <1> 
  4106                              <1> loc_rmdir_dotdot_entry_check:
  4107 000092E3 66817F012E20        <1> 	cmp	word [edi+1], '. '
  4108                              <1> pass_rmdir_dot_entry_check:
  4109 000092E9 7504                <1> 	jne	short loc_rmdir_directory_not_empty_1 
  4110 000092EB FEC3                <1> 	inc	bl
  4111 000092ED EBD3                <1> 	jmp	short loc_rmdir_find_last_dir_entry_next 
  4112                              <1> 
  4113                              <1> loc_rmdir_directory_not_empty_1:
  4114 000092EF 58                  <1> 	pop	eax ; pushed esi 
  4115 000092F0 31C0                <1> 	xor	eax, eax ; 0
  4116                              <1> loc_rmdir_directory_not_empty_2:
  4117                              <1> loc_delete_sub_dir_stc_retn:
  4118 000092F2 F9                  <1> 	stc
  4119 000092F3 C3                  <1> 	retn
  4120                              <1> 
  4121                              <1> loc_rmdir_empty_dir_cluster:
  4122 000092F4 5E                  <1> 	pop	esi
  4123                              <1> 
  4124                              <1> loc_rmdir_set_prev_cluster_dir_last_cluster:
  4125 000092F5 803D[0F870100]00    <1> 	cmp	byte [RmDir_MultiClusters], 0
  4126 000092FC 7613                <1> 	jna	short loc_rmdir_unlink_dir_last_cluster
  4127                              <1> 
  4128 000092FE A1[1C870100]        <1> 	mov	eax, [RmDir_PreviousCluster]
  4129                              <1> 	;xor	ecx, ecx
  4130 00009303 49                  <1> 	dec	ecx ; FFFFFFFFh
  4131 00009304 E806330000          <1> 	call	update_cluster
  4132 00009309 7306                <1> 	jnc	short loc_rmdir_unlink_dir_last_cluster
  4133                              <1> 
  4134                              <1> 	; 01/03/2016
  4135                              <1> 	;cmp	eax, 1  ; eax = 0 -> end of cluster chain
  4136                              <1> 	;cmc 
  4137                              <1> 	;jc	short loc_rmdir_cmd_failed
  4138                              <1> 	;jmp	short loc_rmdir_save_fat_buffer
  4139                              <1> 	; 29/12/2017 
  4140 0000930B 21C0                <1> 	and	eax, eax
  4141 0000930D 75E3                <1> 	jnz	short loc_delete_sub_dir_stc_retn
  4142 0000930F EB12                <1> 	jmp	short loc_rmdir_save_fat_buffer
  4143                              <1> 
  4144                              <1> loc_rmdir_unlink_dir_last_cluster:
  4145 00009311 A1[18870100]        <1> 	mov	eax, [RmDir_DirLastCluster]
  4146 00009316 31C9                <1> 	xor	ecx, ecx ; 0
  4147 00009318 E8F2320000          <1> 	call	update_cluster
  4148 0000931D 7327                <1> 	jnc	short loc_rmdir_unlink_stc_retn_0Bh
  4149                              <1> 	; Because of it is the last cluster
  4150                              <1> 	; 'update_cluster' must return with eocc error
  4151 0000931F 09C0                <1> 	or	eax, eax
  4152                              <1> 	;jz	short loc_rmdir_save_fat_buffer ; eocc
  4153                              <1> 	;stc
  4154                              <1>         ;jmp	short loc_rmdir_cmd_failed
  4155                              <1> 	; 29/12/2017
  4156 00009321 75CF                <1> 	jnz	short loc_delete_sub_dir_stc_retn
  4157                              <1> 
  4158                              <1> loc_rmdir_save_fat_buffer:
  4159 00009323 803D[96840100]02    <1> 	cmp	byte [FAT_BuffValidData], 2
  4160 0000932A 7527                <1> 	jne	short loc_rmdir_calculate_FAT_freespace
  4161 0000932C E852350000          <1> 	call	save_fat_buffer
  4162                              <1> 	;jc	short loc_rmdir_cmd_failed
  4163                              <1> 	; 29/12/2017
  4164 00009331 7219                <1> 	jc	short loc_rmdir_unlink_error_retn
  4165                              <1> 
  4166                              <1> 	; 01/03/2016
  4167 00009333 803D[0F870100]00    <1> 	cmp	byte [RmDir_MultiClusters], 0
  4168 0000933A 7617                <1> 	jna	short loc_rmdir_calculate_FAT_freespace
  4169                              <1> 
  4170 0000933C A1[E4860100]        <1> 	mov	eax, [DelFile_FCluster]
  4171 00009341 E92EFFFFFF          <1>         jmp     loc_rmdir_get_last_cluster_3
  4172                              <1> 
  4173                              <1> loc_rmdir_unlink_stc_retn_0Bh:
  4174                              <1> 	; 15/10/2016 (0Bh -> 28)
  4175 00009346 B81C000000          <1> 	mov	eax, ERR_INV_FORMAT ; 28 = Invalid format
  4176                              <1> loc_rmdir_unlink_stc_retn:
  4177 0000934B F9                  <1> 	stc
  4178                              <1> loc_rmdir_unlink_error_retn:
  4179 0000934C C3                  <1> 	retn
  4180                              <1> 
  4181                              <1> loc_rmdir_delete_short_name_invalid_data:
  4182                              <1> 	;mov	eax, 29 ; Invalid data (15/10/2016)
  4183                              <1> 	; 28/07/2022
  4184 0000934D 29C0                <1> 	sub	eax, eax
  4185 0000934F B01D                <1> 	mov	al, 29
  4186                              <1> 	;stc
  4187                              <1>         ;jmp	loc_rmdir_cmd_failed
  4188                              <1> 	; 29/12/2017
  4189 00009351 EBF8                <1> 	jmp	short loc_rmdir_unlink_stc_retn
  4190                              <1> 
  4191                              <1> loc_rmdir_calculate_FAT_freespace:
  4192                              <1> 	;mov	eax, [FAT_ClusterCounter]
  4193                              <1> 	; 29/12/2017
  4194 00009353 29C0                <1> 	sub	eax, eax ; 0
  4195 00009355 8705[9E840100]      <1> 	xchg	eax, [FAT_ClusterCounter]
  4196                              <1> 	;
  4197 0000935B 66BB01FF            <1> 	mov	bx, 0FF01h
  4198                              <1> 	; BL = 1 -> Add EAX to free space count
  4199                              <1> 	; BH = FFh ->
  4200                              <1> 	; ESI = Logical DOS Drive Description Table address
  4201 0000935F E8B0350000          <1> 	call	calculate_fat_freespace
  4202                              <1> 
  4203 00009364 21C9                <1> 	and	ecx, ecx ; ecx = 0 -> valid free sector count
  4204 00009366 7409                <1> 	jz 	short loc_rmdir_delete_short_name_continue
  4205                              <1> 
  4206                              <1> loc_rmdir_recalculate_FAT_freespace:
  4207 00009368 66BB00FF            <1>         mov     bx, 0FF00h ; BL = 0 -> Recalculate free space
  4208 0000936C E8A3350000          <1> 	call	calculate_fat_freespace
  4209                              <1> 
  4210                              <1> loc_rmdir_delete_short_name_continue:
  4211 00009371 A1[14870100]        <1> 	mov	eax, [RmDir_ParentDirCluster]
  4212 00009376 83F802              <1> 	cmp	eax, 2
  4213 00009379 7309                <1> 	jnb	short loc_rmdir_del_short_name_load_sub_dir
  4214 0000937B E8DE300000          <1> 	call	load_FAT_root_directory
  4215                              <1> 	;jc	loc_file_rw_cmd_failed
  4216                              <1> 	; 29/12/2017
  4217 00009380 72CA                <1> 	jc	short loc_rmdir_unlink_error_retn
  4218 00009382 EB07                <1> 	jmp	short loc_rmdir_del_short_name_ld_chk_fclust
  4219                              <1> 
  4220                              <1> loc_rmdir_del_short_name_load_sub_dir:
  4221 00009384 E853310000          <1> 	call	load_FAT_sub_directory
  4222                              <1> 	;jc	loc_file_rw_cmd_failed
  4223                              <1> 	; 29/12/2017
  4224 00009389 72C1                <1> 	jc	short loc_rmdir_unlink_error_retn
  4225                              <1> 
  4226                              <1> loc_rmdir_del_short_name_ld_chk_fclust:
  4227 0000938B 0FB73D[10870100]    <1> 	movzx	edi, word [RmDir_DirEntryOffset]
  4228 00009392 81C700000800        <1> 	add	edi, Directory_Buffer
  4229                              <1> 
  4230 00009398 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
  4231 0000939C C1E010              <1> 	shl	eax, 16
  4232 0000939F 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
  4233                              <1>         ; Not necessary... 
  4234 000093A3 3B05[E4860100]      <1> 	cmp	eax, [DelFile_FCluster]
  4235 000093A9 75A2                <1> 	jne	short loc_rmdir_delete_short_name_invalid_data
  4236                              <1> 	;
  4237 000093AB C607E5              <1> 	mov	byte [edi], 0E5h ; 'Deleted' sign
  4238                              <1> 	; 27/02/2016
  4239                              <1> 	; TRDOS v1 has a bug here! it does not set
  4240                              <1> 	; 'DirBuff_ValidData' to 2; as result of this bug,
  4241                              <1> 	; 'save_directory_buffer' would not save the change !
  4242 000093AE C605[A9840100]02    <1>   	mov	byte [DirBuff_ValidData], 2 ; change sign
  4243                              <1> 	;
  4244 000093B5 E8971C0000          <1> 	call	save_directory_buffer
  4245                              <1> 	;jc	loc_file_rw_cmd_failed
  4246                              <1> 	; 29/12/2017
  4247 000093BA 7290                <1> 	jc	short loc_rmdir_unlink_error_retn
  4248                              <1> 
  4249                              <1> loc_rmdir_del_long_name:
  4250 000093BC 0FB615[EA860100]    <1> 	movzx	edx, byte [DelFile_LNEL]
  4251 000093C3 08D2                <1> 	or	dl, dl
  4252 000093C5 7410                <1> 	jz	short loc_rmdir_update_parent_dir_lmdt
  4253                              <1> 
  4254 000093C7 0FB705[E8860100]    <1> 	movzx	eax, word [DelFile_EntryCounter]
  4255 000093CE 29D0                <1> 	sub	eax, edx
  4256                              <1> 	; 29/12/2017
  4257 000093D0 7205                <1> 	jc	short loc_rmdir_update_parent_dir_lmdt
  4258                              <1> 
  4259                              <1>  	; EAX = Directory Entry Number of the long name last entry
  4260 000093D2 E8D31D0000          <1> 	call	delete_longname
  4261                              <1> 
  4262                              <1> loc_rmdir_update_parent_dir_lmdt:
  4263 000093D7 E80D1D0000          <1> 	call	update_parent_dir_lmdt
  4264                              <1> 	;jc	short loc_file_rw_cmd_failed
  4265                              <1> 	; 29/12/2017
  4266                              <1> 	;jc	short loc_rmdir_unlink_error_retn
  4267                              <1> 
  4268                              <1> loc_delete_sub_directory_ok:
  4269                              <1> 	; 29/12/2017
  4270 000093DC 31C0                <1> 	xor	eax, eax ;  0 ;  cf = 0
  4271 000093DE C3                  <1> 	retn
  4272                              <1> 
  4273                              <1> delete_file:
  4274                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
  4275                              <1> 	; 29/02/2016
  4276                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
  4277                              <1> 	; 09/08/2010 (CMD_INTR.ASM, 'cmp_cmd_del')
  4278                              <1> 	; 28/02/2010
  4279                              <1> 
  4280                              <1> get_delfile_fchar:
  4281                              <1> 	; esi = file name
  4282 000093DF 803E20              <1> 	cmp	byte [esi], 20h
  4283 000093E2 7701                <1>         ja	short loc_delfile_parse_path_name
  4284                              <1> 
  4285                              <1> loc_delfile_nofilename_retn:
  4286 000093E4 C3                  <1> 	retn
  4287                              <1> 
  4288                              <1> loc_delfile_parse_path_name:
  4289 000093E5 BF[22860100]        <1> 	mov	edi, FindFile_Drv
  4290 000093EA E82B180000          <1> 	call	parse_path_name
  4291                              <1> 	;jc	loc_cmd_failed
  4292                              <1> 	; 28/07/2022
  4293 000093EF 7305                <1> 	jnc	short loc_delfile_check_filename_exists
  4294                              <1> loc_delfile_failed:
  4295 000093F1 E94EF2FFFF          <1> 	jmp	loc_cmd_failed
  4296                              <1> 
  4297                              <1> loc_delfile_check_filename_exists:
  4298 000093F6 BE[64860100]        <1> 	mov	esi, FindFile_Name
  4299 000093FB 803E20              <1> 	cmp	byte [esi], 20h
  4300                              <1> 	;jna	loc_cmd_failed
  4301                              <1> 	; 28/07/2022
  4302 000093FE 76F1                <1> 	jna	short loc_delfile_failed
  4303 00009400 8935[E0860100]      <1> 	mov	[DelFile_FNPointer], esi
  4304                              <1> 
  4305                              <1> loc_delfile_drv:
  4306 00009406 8A15[22860100]      <1> 	mov	dl, [FindFile_Drv]
  4307 0000940C 8A35[827D0100]      <1> 	mov	dh, [Current_Drv]
  4308 00009412 8835[DF840100]      <1> 	mov	[RUN_CDRV], dh
  4309 00009418 38F2                <1> 	cmp	dl, dh
  4310 0000941A 7407                <1> 	je	short loc_delfile_change_directory
  4311                              <1> 
  4312 0000941C E85CE4FFFF          <1> 	call	change_current_drive
  4313                              <1> 	;jc	loc_file_rw_cmd_failed
  4314                              <1> 	; 28/07/2022
  4315                              <1> 	;jnc	short loc_delfile_change_directory
  4316                              <1> 	;jmp	loc_file_rw_cmd_failed
  4317 00009421 721D                <1> 	jc	short loc_delfile_chdrv_failed
  4318                              <1> 
  4319                              <1> loc_delfile_change_directory:
  4320 00009423 803D[23860100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  4321 0000942A 7619                <1> 	jna	short loc_delfile_find
  4322                              <1> 
  4323 0000942C FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  4324 00009432 BE[23860100]        <1> 	mov	esi, FindFile_Directory
  4325 00009437 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0
  4326 00009439 E8F2110000          <1> 	call	change_current_directory
  4327                              <1> 	;jc	loc_file_rw_cmd_failed
  4328                              <1> 	; 28/07/2022
  4329 0000943E 7305                <1> 	jnc	short loc_delfile_chdir_ok
  4330                              <1> loc_delfile_chdrv_failed:
  4331                              <1> loc_delfile_fff_failed:
  4332 00009440 E939FBFFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4333                              <1> 
  4334                              <1> loc_delfile_chdir_ok: ; 28/07/2022
  4335                              <1> 
  4336                              <1> ;loc_delfile_change_prompt_dir_string:
  4337                              <1> 	;call	change_prompt_dir_string
  4338                              <1> 
  4339                              <1> loc_delfile_find:
  4340                              <1> 	;mov	esi, FindFile_Name
  4341 00009445 8B35[E0860100]      <1> 	mov	esi, [DelFile_FNPointer]
  4342 0000944B 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
  4343 0000944F E816F7FFFF          <1> 	call	find_first_file
  4344                              <1> 	;jc	loc_file_rw_cmd_failed
  4345                              <1> 	; 28/07/2022
  4346 00009454 72EA                <1> 	jc	short loc_delfile_fff_failed
  4347                              <1> 
  4348                              <1> loc_delfile_ambgfn_check:
  4349 00009456 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  4350 00009459 740A                <1> 	jz	short loc_delfile_found
  4351                              <1> 
  4352                              <1> loc_file_not_found:
  4353                              <1> 	;mov	eax, 2 ; File not found sign
  4354                              <1> 	; 28/07/2022
  4355 0000945B 31C0                <1> 	xor	eax, eax
  4356 0000945D B002                <1> 	mov	al, 2
  4357 0000945F F9                  <1> 	stc
  4358 00009460 E919FBFFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4359                              <1> 
  4360                              <1> loc_delfile_found:
  4361 00009465 80E307              <1> 	and	bl, 07h ; Attributes
  4362                              <1> 	;jnz	loc_permission_denied
  4363                              <1> 	; 28/07/2022
  4364 00009468 7405                <1> 	jz	short loc_delfile_attrb_ok
  4365 0000946A E919FBFFFF          <1> 	jmp	loc_permission_denied
  4366                              <1> 
  4367                              <1> loc_delfile_attrb_ok: ; 28/07/2022
  4368                              <1> 
  4369                              <1> ;loc_delfile_found_save_lnel:
  4370                              <1> ;	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
  4371                              <1> 
  4372                              <1> loc_delfile_ask_for_delete:
  4373 0000946F 57                  <1> 	push	edi ; * (29/02/2016)
  4374                              <1> 
  4375 00009470 BE[73390100]        <1> 	mov	esi, Msg_DoYouWantDelete
  4376 00009475 E8F0D8FFFF          <1> 	call	print_msg
  4377 0000947A 8B35[E0860100]      <1> 	mov	esi, [DelFile_FNPointer]
  4378 00009480 E8E5D8FFFF          <1> 	call	print_msg
  4379 00009485 BE[27390100]        <1> 	mov	esi, Msg_YesNo
  4380 0000948A E8DBD8FFFF          <1> 	call	print_msg
  4381                              <1> 
  4382                              <1> loc_delfile_ask_again:
  4383 0000948F 30E4                <1> 	xor	ah, ah
  4384 00009491 E8867AFFFF          <1> 	call	int16h
  4385 00009496 3C1B                <1> 	cmp	al, 1Bh
  4386                              <1> 	;je	short loc_do_not_delete_file
  4387 00009498 744C                <1> 	je	short loc_delfile_y_n_escape ; 06/03/2016
  4388 0000949A 24DF                <1> 	and	al, 0DFh
  4389 0000949C A2[31390100]        <1> 	mov	[Y_N_nextline], al
  4390 000094A1 3C59                <1> 	cmp	al, 'Y'
  4391 000094A3 7404                <1> 	je	short loc_yes_delete_file
  4392 000094A5 3C4E                <1> 	cmp	al, 'N'
  4393 000094A7 75E6                <1> 	jne	short loc_delfile_ask_again
  4394                              <1> 
  4395                              <1> loc_do_not_delete_file:
  4396                              <1> loc_yes_delete_file:
  4397 000094A9 E803FCFFFF          <1> 	call	y_n_answer ; 29/12/2017
  4398 000094AE 5F                  <1> 	pop	edi ; * (29/02/2016)
  4399                              <1> 	;cmp	al, 'Y' ; 'yes'
  4400                              <1> 	;cmc
  4401                              <1>         ;jnc	loc_file_rw_restore_retn
  4402 000094AF 3C4E                <1> 	cmp	al, 'N' ; 'no'
  4403                              <1>         ;je	loc_file_rw_restore_retn
  4404                              <1> 	; 28/07/2022
  4405 000094B1 7505                <1> 	jne	short loc_delete_file
  4406 000094B3 E9C6FAFFFF          <1> 	jmp	loc_file_rw_restore_retn
  4407                              <1> 
  4408                              <1> loc_delete_file:
  4409 000094B8 8A3D[22860100]      <1> 	mov	bh, [FindFile_Drv]
  4410                              <1> 	;mov	bl, [DelFile_LNEL]
  4411 000094BE 8A1D[71860100]      <1> 	mov	bl, [FindFile_LongNameEntryLength]
  4412                              <1> 	;mov	cx, [DirBuff_EntryCounter]
  4413 000094C4 668B0D[9C860100]    <1> 	mov	cx, [FindFile_DirEntryNumber]
  4414                              <1> 	; (*) EDI = Directory buffer entry offset/address
  4415 000094CB E8B21E0000          <1> 	call	remove_file ; (FILE.ASM, 'proc_delete_file')
  4416                              <1> 	;jnc	loc_print_deleted_message
  4417                              <1> 	; 28/07/2022
  4418 000094D0 7205                <1> 	jc	short loc_delete_file_err1
  4419 000094D2 E99DFAFFFF          <1> 	jmp	loc_print_deleted_message
  4420                              <1> 
  4421                              <1> loc_delete_file_err1:
  4422                              <1> 	;cmp	al, 05h
  4423 000094D7 3C0B                <1> 	cmp	al, ERR_PERM_DENIED  ; 29/12/2017 (5 -> 11)
  4424                              <1> 	;je	loc_permission_denied
  4425                              <1> 	; 28/07/2022
  4426 000094D9 7505                <1> 	jne	short loc_delete_file_err2
  4427 000094DB E9A8FAFFFF          <1> 	jmp	loc_permission_denied
  4428                              <1> loc_delete_file_err2:
  4429 000094E0 F9                  <1> 	stc
  4430 000094E1 E998FAFFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4431                              <1> 
  4432                              <1> loc_delfile_y_n_escape:
  4433 000094E6 B04E                <1> 	mov	al, 'N' ; 'no'
  4434 000094E8 EBBF                <1> 	jmp	short loc_do_not_delete_file
  4435                              <1> 
  4436                              <1> set_file_attributes:
  4437                              <1> 	; 26/09/2024 (TRDOS 386 v2.0.9)
  4438                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
  4439                              <1> 	; 06/03/2016
  4440                              <1> 	; 04/03/2016 (TRDOS 386 = TRDOS v2.0)
  4441                              <1> 	; 10/07/2010 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_attrib')
  4442                              <1> 	; 23/05/2010 
  4443                              <1> 	; 17/12/2000 (P2000.ASM)
  4444                              <1> 
  4445                              <1> 	; esi = file or directory name
  4446                              <1> 	;xor	ax, ax
  4447                              <1> 	; 28/07/2022
  4448 000094EA 31C0                <1> 	xor	eax, eax
  4449 000094EC 66A3[C4390100]      <1> 	mov	[Attr_Chars], ax
  4450 000094F2 A2[38870100]        <1> 	mov	[Attributes], al
  4451                              <1> 
  4452                              <1> get_attrib_fchar:
  4453                              <1> 	; esi = file name
  4454 000094F7 8A06                <1> 	mov	al, [esi]
  4455 000094F9 3C20                <1> 	cmp	al, 20h
  4456 000094FB 7621                <1> 	jna	short loc_attr_file_nofilename_retn
  4457                              <1> 
  4458                              <1> loc_scan_attrib_params:
  4459 000094FD 3C2D                <1> 	cmp	al, '-'
  4460                              <1> 	;ja	loc_attr_file_parse_path_name
  4461                              <1> 	;je	short loc_attr_space
  4462                              <1> 	; 28/07/2022
  4463 000094FF 7207                <1> 	jb	short loc_sfa_1
  4464 00009501 740E                <1> 	je	short loc_attr_space
  4465 00009503 E911010000          <1> 	jmp	loc_attr_file_parse_path_name
  4466                              <1> 
  4467                              <1> loc_sfa_1:
  4468                              <1> 	; 28/07/2022
  4469 00009508 3C2B                <1> 	cmp	al, '+'
  4470                              <1> 	;jne	loc_cmd_failed
  4471 0000950A 7405                <1> 	je	short loc_attr_space
  4472                              <1> loc_sfa_2: 
  4473 0000950C E933F1FFFF          <1> 	jmp	loc_cmd_failed
  4474                              <1> loc_attr_space:
  4475 00009511 8A6601              <1> 	mov	ah, [esi+1]
  4476 00009514 80FC20              <1>  	cmp	ah, 20h
  4477 00009517 7706                <1> 	ja	short pass_attr_space
  4478                              <1> 	;jb	loc_cmd_failed
  4479                              <1> 	; 28/07/2022
  4480 00009519 72F1                <1> 	jb	short loc_sfa_2
  4481 0000951B 46                  <1> 	inc	esi
  4482 0000951C EBF3                <1> 	jmp	short loc_attr_space
  4483                              <1> 
  4484                              <1> loc_attr_file_nofilename_retn:
  4485 0000951E C3                  <1> 	retn
  4486                              <1> 
  4487                              <1> pass_attr_space:
  4488 0000951F 80E4DF              <1> 	and	ah, 0DFh
  4489 00009522 80FC53              <1> 	cmp	ah, 'S'
  4490                              <1> 	;ja	loc_cmd_failed
  4491                              <1> 	; 28/07/2022
  4492 00009525 77E5                <1> 	ja	short loc_sfa_2
  4493 00009527 7204                <1> 	jb	short pass_attr_system
  4494 00009529 B404                <1> 	mov	ah, 04h	; System
  4495 0000952B EB1D                <1> 	jmp	short pass_attr_archive
  4496                              <1> 
  4497                              <1> pass_attr_system:
  4498 0000952D 80FC48              <1> 	cmp	ah, 'H'
  4499 00009530 7706                <1> 	ja	short pass_attr_hidden
  4500 00009532 720F                <1> 	jb	short pass_attr_read_only
  4501 00009534 B402                <1> 	mov	ah, 02h	; Hidden
  4502 00009536 EB12                <1> 	jmp	short pass_attr_archive
  4503                              <1> 
  4504                              <1> pass_attr_hidden:
  4505 00009538 80FC52              <1> 	cmp	ah, 'R'
  4506                              <1> 	;ja	loc_cmd_failed
  4507                              <1> 	; 28/07/2022
  4508 0000953B 77CF                <1> 	ja	short loc_sfa_2
  4509 0000953D 7204                <1> 	jb	short pass_attr_read_only ; Read only
  4510 0000953F B401                <1> 	mov	ah, 01h
  4511 00009541 EB07                <1> 	jmp	short pass_attr_archive
  4512                              <1> 
  4513                              <1> pass_attr_read_only:
  4514 00009543 80FC41              <1> 	cmp	ah, 'A'
  4515 00009546 753B                <1> 	jne	short loc_chk_attr_enter
  4516 00009548 B420                <1> 	mov	ah, 20h	; Archive
  4517                              <1> 
  4518                              <1> pass_attr_archive:
  4519 0000954A 3C2D                <1> 	cmp	al, '-'
  4520 0000954C 7508                <1> 	jne	short pass_reducing_attributes
  4521 0000954E 0825[C4390100]      <1> 	or	[Attr_Chars], ah
  4522 00009554 EB06                <1> 	jmp	short loc_change_attributes_inc
  4523                              <1> 
  4524                              <1> pass_reducing_attributes:
  4525 00009556 0825[C5390100]      <1> 	or	[Attr_Chars+1], ah
  4526                              <1> 
  4527                              <1> loc_change_attributes_inc:
  4528 0000955C 46                  <1> 	inc	esi
  4529 0000955D 8A6601              <1> 	mov	ah, [esi+1]
  4530 00009560 80FC20              <1> 	cmp	ah, 20h
  4531 00009563 7228                <1> 	jb	short pass_change_attr
  4532 00009565 74F5                <1> 	je	short loc_change_attributes_inc
  4533 00009567 80FC2D              <1> 	cmp	ah, '-'
  4534 0000956A 770D                <1> 	ja	short loc_chk_next_attr_char1
  4535 0000956C 7405                <1> 	je	short loc_chk_next_attr_char0
  4536 0000956E 80FC2B              <1> 	cmp	ah, '+'
  4537 00009571 7506                <1> 	jne	short loc_chk_next_attr_char1
  4538                              <1> 
  4539                              <1> loc_chk_next_attr_char0:
  4540 00009573 46                  <1> 	inc	esi
  4541 00009574 668B06              <1> 	mov	ax, [esi]
  4542 00009577 EBA6                <1> 	jmp	short pass_attr_space
  4543                              <1> 
  4544                              <1> loc_chk_next_attr_char1:
  4545 00009579 803E2D              <1> 	cmp	byte [esi], '-'
  4546 0000957C 77A1                <1> 	ja	short pass_attr_space
  4547 0000957E E989000000          <1>         jmp     loc_attr_file_check_fname_fchar
  4548                              <1> 
  4549                              <1> loc_chk_attr_enter:
  4550 00009583 80FC0D              <1> 	cmp	ah, 0Dh
  4551                              <1> 	;jne	loc_cmd_failed
  4552                              <1> 	; 28/07/202
  4553 00009586 7405                <1> 	je	short pass_change_attr
  4554 00009588 E9B7F0FFFF          <1> 	jmp	loc_cmd_failed
  4555                              <1> 
  4556                              <1> pass_change_attr:
  4557 0000958D A0[C4390100]        <1> 	mov	al, [Attr_Chars]
  4558 00009592 F6D0                <1> 	not	al
  4559 00009594 2005[38870100]      <1> 	and	[Attributes], al
  4560 0000959A A0[C5390100]        <1> 	mov	al, [Attr_Chars+1]
  4561 0000959F 0805[38870100]      <1> 	or	[Attributes], al
  4562                              <1> 
  4563                              <1> loc_show_attributes:
  4564 000095A5 BE[273F0100]        <1> 	mov	esi, nextline
  4565 000095AA E8BBD7FFFF          <1> 	call	print_msg
  4566                              <1> 
  4567                              <1> loc_show_attributes_no_nextline:
  4568 000095AF C705[C4390100]4E4F- <1> 	mov	dword [Attr_Chars], 'NORM'
  4568 000095B7 524D                <1>
  4569 000095B9 66C705[C8390100]41- <1> 	mov	word [Attr_Chars+4], 'AL'
  4569 000095C1 4C                  <1>
  4570 000095C2 BE[C4390100]        <1> 	mov	esi, Attr_Chars
  4571 000095C7 A0[38870100]        <1> 	mov	al, [Attributes]
  4572 000095CC A804                <1> 	test	al, 04h
  4573 000095CE 7406                <1> 	jz	short pass_put_attr_s
  4574 000095D0 66C7065300          <1> 	mov	word [esi], 0053h     ; S
  4575 000095D5 46                  <1> 	inc	esi
  4576                              <1> 
  4577                              <1> pass_put_attr_s:
  4578 000095D6 A802                <1> 	test	al, 02h
  4579 000095D8 7406                <1> 	jz	short pass_put_attr_h
  4580 000095DA 66C7064800          <1> 	mov	word [esi], 0048h     ; H
  4581 000095DF 46                  <1> 	inc	esi
  4582                              <1> 
  4583                              <1> pass_put_attr_h:
  4584 000095E0 A801                <1> 	test	al, 01h
  4585 000095E2 7406                <1> 	jz	short pass_put_attr_r
  4586 000095E4 66C7065200          <1> 	mov	word [esi], 0052h     ; R
  4587 000095E9 46                  <1> 	inc	esi
  4588                              <1> 
  4589                              <1> pass_put_attr_r:
  4590 000095EA 3C20                <1> 	cmp	al, 20h
  4591 000095EC 7205                <1> 	jb	short pass_put_attr_a
  4592 000095EE 66C7064100          <1> 	mov	word [esi], 0041h     ; A
  4593                              <1> 
  4594                              <1> pass_put_attr_a:
  4595 000095F3 BE[B7390100]        <1> 	mov	esi, Str_Attributes
  4596 000095F8 E86DD7FFFF          <1> 	call	print_msg
  4597 000095FD BE[273F0100]        <1> 	mov	esi, nextline
  4598 00009602 E863D7FFFF          <1> 	call	print_msg
  4599 00009607 E972F9FFFF          <1> 	jmp	loc_file_rw_restore_retn 
  4600                              <1> 
  4601                              <1> loc_attr_file_check_fname_fchar:
  4602 0000960C 46                  <1> 	inc	esi
  4603 0000960D 803E20              <1> 	cmp	byte [esi], 20h
  4604 00009610 74FA                <1> 	je	short loc_attr_file_check_fname_fchar
  4605                              <1>         ;jb	pass_change_attr
  4606                              <1> 	; 28/07/2022
  4607 00009612 7705                <1> 	ja	short loc_attr_file_parse_path_name
  4608 00009614 E974FFFFFF          <1> 	jmp	pass_change_attr
  4609                              <1> 
  4610                              <1> loc_attr_file_parse_path_name:
  4611 00009619 BF[22860100]        <1> 	mov	edi, FindFile_Drv
  4612 0000961E E8F7150000          <1> 	call	parse_path_name
  4613                              <1> 	;jc	loc_cmd_failed
  4614                              <1> 	; 28/07/2022
  4615 00009623 7305                <1> 	jnc	short loc_attr_file_check_filename_exists
  4616                              <1> loc_sfa_3:
  4617 00009625 E91AF0FFFF          <1> 	jmp	loc_cmd_failed
  4618                              <1> 
  4619                              <1> loc_attr_file_check_filename_exists:
  4620 0000962A BE[64860100]        <1> 	mov	esi, FindFile_Name
  4621 0000962F 803E20              <1> 	cmp	byte [esi], 20h
  4622                              <1> 	;jna	loc_cmd_failed
  4623                              <1> 	; 28/07/2022
  4624 00009632 76F1                <1> 	jna	short loc_sfa_3
  4625 00009634 8935[E0860100]      <1> 	mov	[DelFile_FNPointer], esi
  4626                              <1> 
  4627                              <1> loc_attr_file_drv:
  4628 0000963A 8A35[827D0100]      <1> 	mov	dh, [Current_Drv]
  4629 00009640 8835[DF840100]      <1> 	mov	[RUN_CDRV], dh
  4630                              <1> 
  4631 00009646 8A15[22860100]      <1> 	mov	dl, [FindFile_Drv]
  4632 0000964C 38F2                <1> 	cmp	dl, dh
  4633 0000964E 7407                <1> 	je	short loc_attr_file_change_directory
  4634                              <1> 
  4635 00009650 E828E2FFFF          <1> 	call	change_current_drive
  4636                              <1> 	;jc	loc_file_rw_cmd_failed
  4637                              <1> 	; 28/07/2022
  4638 00009655 722E                <1> 	jc	short loc_sfa_4
  4639                              <1> 
  4640                              <1> loc_attr_file_change_directory:
  4641 00009657 803D[23860100]20    <1>         cmp     byte [FindFile_Directory], 20h
  4642 0000965E 7614                <1> 	jna	short loc_attr_file_find
  4643                              <1> 
  4644 00009660 FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  4645                              <1> 
  4646 00009666 BE[23860100]        <1> 	mov	esi, FindFile_Directory
  4647 0000966B 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0
  4648 0000966D E8BE0F0000          <1> 	call	change_current_directory
  4649                              <1> 	;jc	loc_file_rw_cmd_failed
  4650                              <1> 	; 28/07/2022
  4651 00009672 7211                <1> 	jc	short loc_sfa_4
  4652                              <1> 
  4653                              <1> ;loc_attr_file_change_prompt_dir_string:
  4654                              <1> 	;call	change_prompt_dir_string
  4655                              <1> 
  4656                              <1> loc_attr_file_find:
  4657                              <1> 	;mov	esi, FindFile_Name
  4658 00009674 8B35[E0860100]      <1> 	mov	esi, [DelFile_FNPointer]
  4659 0000967A 66B80008            <1> 	mov	ax, 0800h ; Except volume labels
  4660 0000967E E8E7F4FFFF          <1> 	call	find_first_file
  4661                              <1> 	;jc	loc_file_rw_cmd_failed
  4662                              <1> 	; 28/07/2022
  4663 00009683 7305                <1> 	jnc	short loc_attr_file_ambgfn_check
  4664                              <1> loc_sfa_4:
  4665 00009685 E9F4F8FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4666                              <1> 
  4667                              <1> loc_attr_file_ambgfn_check:
  4668 0000968A 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
  4669                              <1> 	;	(Note: It was BX in TRDOS v1)
  4670                              <1> 	;;jz	short loc_attr_file_found
  4671                              <1> 	;jnz	loc_file_not_found ; 06/03/2016
  4672                              <1> 	; 28/07/2022 
  4673 0000968D 7405                <1> 	jz	short loc_attr_file_found
  4674 0000968F E9C7FDFFFF          <1> 	jmp	loc_file_not_found
  4675                              <1> 
  4676                              <1> 	;mov	eax, 2 ; File not found sign
  4677                              <1> 	;stc
  4678                              <1> 	;jmp	loc_file_rw_cmd_failed
  4679                              <1> 
  4680                              <1> loc_attr_file_found:
  4681                              <1> 	; EDI = Directory buffer entry offset/address
  4682                              <1> 	; BL = File (or Directory) Attributes 
  4683                              <1> 	;	(Note: It was 'CL' in TRDOS v1)
  4684                              <1> 	; mov	bl, [EDI+0Bh]
  4685                              <1> 
  4686 00009694 66833D[C4390100]00  <1> 	cmp	word [Attr_Chars], 0
  4687 0000969C 770B                <1> 	ja	short loc_attr_file_change_attributes
  4688 0000969E 881D[38870100]      <1> 	mov	[Attributes], bl
  4689 000096A4 E9FCFEFFFF          <1> 	jmp	loc_show_attributes
  4690                              <1> 
  4691                              <1> loc_attr_file_change_attributes:
  4692 000096A9 A0[C4390100]        <1> 	mov	al, [Attr_Chars]
  4693 000096AE F6D0                <1> 	not	al
  4694 000096B0 20C3                <1> 	and	bl, al
  4695 000096B2 A0[C5390100]        <1> 	mov	al, [Attr_Chars+1]
  4696 000096B7 08C3                <1> 	or	bl, al
  4697                              <1> 
  4698 000096B9 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h ; Singlix FS
  4699 000096BF 741C                <1> 	je	short loc_attr_file_fs_check
  4700                              <1> 
  4701 000096C1 881D[38870100]      <1> 	mov	[Attributes], bl
  4702 000096C7 885F0B              <1> 	mov	[edi+0Bh], bl    ; Attributes (New!)
  4703                              <1> 
  4704                              <1> 	; 04/03/2016
  4705                              <1> 	; TRDOS v1 has a bug here! it does not set
  4706                              <1> 	; 'DirBuff_ValidData' to 2; as result of this bug,
  4707                              <1> 	; 'save_directory_buffer' would not save the new attributes !
  4708                              <1> 	
  4709 000096CA C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  4710                              <1> 
  4711 000096D1 E87B190000          <1> 	call 	save_directory_buffer
  4712                              <1> 	;jc	loc_file_rw_cmd_failed
  4713                              <1> 	;jmp	short loc_print_attr_changed_message
  4714                              <1> 	; 28/07/2022
  4715 000096D6 7337                <1> 	jnc	short loc_print_attr_changed_message
  4716                              <1> loc_sfa_5:
  4717 000096D8 E9A1F8FFFF          <1> 	jmp	loc_file_rw_cmd_failed 
  4718                              <1> 
  4719                              <1> loc_attr_file_fs_check:
  4720 000096DD 29C0                <1> 	sub	eax, eax
  4721 000096DF 8A25[A7840100]      <1>         mov     ah, [DirBuff_DRV]
  4722                              <1> 	; 26/09/2024 (BugFix)
  4723 000096E5 80EC41              <1> 	sub	ah, 'A'
  4724 000096E8 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  4725 000096ED 01C6                <1>         add     esi, eax
  4726 000096EF 807E04A1            <1>         cmp     byte [esi+LD_FSType], 0A1h
  4727 000096F3 7309                <1> 	jnc	short loc_attr_file_change_fs_file_attributes
  4728                              <1> 	; 29/12/2017 (0Dh -> 29)
  4729 000096F5 66B81D00            <1> 	mov	ax, 29 ; Invalid Data
  4730 000096F9 E980F8FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4731                              <1> 
  4732                              <1> loc_attr_file_change_fs_file_attributes:
  4733                              <1> 	; BL = New MS-DOS File Attributes
  4734 000096FE 88D8                <1> 	mov	al, bl ; File/Directory Attributes
  4735 00009700 30E4                <1> 	xor	ah, ah ; Attributes in MS-DOS format sign
  4736 00009702 E832050000          <1> 	call	change_fs_file_attributes
  4737                              <1> 	;jc	loc_file_rw_cmd_failed
  4738                              <1> 	; 28/07/2022
  4739 00009707 72CF                <1> 	jc	short loc_sfa_5
  4740                              <1> 
  4741 00009709 881D[38870100]      <1> 	mov	[Attributes], bl
  4742                              <1> 
  4743                              <1> loc_print_attr_changed_message:
  4744 0000970F BE[B2390100]        <1> 	mov	esi, Msg_New
  4745 00009714 E851D6FFFF          <1> 	call	print_msg
  4746 00009719 E991FEFFFF          <1> 	jmp	loc_show_attributes_no_nextline
  4747                              <1> 
  4748                              <1> rename_file:
  4749                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
  4750                              <1> 	; 13/11/2017
  4751                              <1> 	; 06/11/2016
  4752                              <1> 	; 05/11/2016
  4753                              <1> 	; 16/10/2016
  4754                              <1> 	; 08/03/2016
  4755                              <1> 	; 06/03/2016 (TRDOS 386 = TRDOS v2.0)
  4756                              <1> 	; 20/11/2010 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_rename')
  4757                              <1> 	; 16/11/2010 
  4758                              <1> 
  4759                              <1> get_rename_source_fchar:
  4760                              <1> 	; esi = file name
  4761 0000971E 803E20              <1> 	cmp	byte [esi], 20h
  4762 00009721 7613                <1>         jna	short loc_rename_nofilename_retn
  4763                              <1> 
  4764 00009723 8935[60870100]      <1> 	mov	[SourceFilePath], esi
  4765                              <1> 
  4766                              <1> rename_scan_source_file:
  4767 00009729 46                  <1> 	inc	esi
  4768 0000972A 803E20              <1> 	cmp	byte [esi], 20h
  4769 0000972D 7408                <1> 	je	short rename_scan_destination_file_1
  4770                              <1> 	;;jb	short loc_rename_nofilename_retn
  4771                              <1> 	;jb	loc_cmd_failed
  4772                              <1> 	;jmp	short rename_scan_source_file
  4773                              <1> 	; 28/07/2022
  4774 0000972F 77F8                <1> 	ja	short rename_scan_source_file
  4775                              <1> loc_rename_failed:
  4776 00009731 E90EEFFFFF          <1> 	jmp	loc_cmd_failed
  4777                              <1> 
  4778                              <1> loc_rename_nofilename_retn: ; 08/03/2016
  4779 00009736 C3                  <1> 	retn
  4780                              <1> 
  4781                              <1> rename_scan_destination_file_1:
  4782 00009737 C60600              <1> 	mov	byte [esi], 0
  4783                              <1> 
  4784                              <1> rename_scan_destination_file_2:
  4785 0000973A 46                  <1> 	inc	esi  
  4786 0000973B 803E20              <1> 	cmp	byte [esi], 20h
  4787 0000973E 74FA                <1> 	je	short rename_scan_destination_file_2
  4788                              <1> 	;;jb	short loc_rename_nofilename_retn
  4789                              <1> 	;jb	loc_cmd_failed
  4790                              <1> 	; 28/07/2022
  4791 00009740 72EF                <1> 	jb	short loc_rename_failed
  4792                              <1> 
  4793 00009742 8935[64870100]      <1> 	mov	[DestinationFilePath], esi
  4794                              <1> 
  4795                              <1> rename_scan_destination_file_3:
  4796 00009748 46                  <1> 	inc	esi  
  4797 00009749 803E20              <1> 	cmp	byte [esi], 20h
  4798 0000974C 77FA                <1> 	ja	short rename_scan_destination_file_3
  4799                              <1> 
  4800 0000974E C60600              <1> 	mov	byte [esi], 0
  4801                              <1> 
  4802                              <1> loc_rename_save_current_drive:
  4803 00009751 8A35[827D0100]      <1> 	mov	dh, [Current_Drv]
  4804 00009757 8835[DF840100]      <1> 	mov	byte [RUN_CDRV], dh
  4805                              <1> 
  4806                              <1> loc_rename_sf_parse_path_name:
  4807 0000975D 8B35[60870100]      <1> 	mov	esi, [SourceFilePath]
  4808 00009763 BF[22860100]        <1> 	mov	edi, FindFile_Drv
  4809 00009768 E8AD140000          <1> 	call	parse_path_name
  4810                              <1> 	;jc	loc_cmd_failed
  4811                              <1> 	; 28/07/2022
  4812 0000976D 72C2                <1> 	jc	short loc_rename_failed
  4813                              <1> 
  4814                              <1> loc_rename_sf_check_filename_exists:
  4815 0000976F BE[64860100]        <1> 	mov	esi, FindFile_Name
  4816 00009774 803E20              <1> 	cmp	byte [esi], 20h
  4817                              <1> 	;jna	loc_cmd_failed
  4818                              <1> 	; 28/07/2022
  4819 00009777 76B8                <1> 	jna	short loc_rename_failed
  4820                              <1> 
  4821                              <1> 	;mov	[DelFile_FNPointer], esi
  4822                              <1> 
  4823                              <1> loc_rename_sf_drv:
  4824                              <1> 	;mov	dh, [Current_Drv]
  4825                              <1> 	;mov	[RUN_CDRV], dh
  4826                              <1> 
  4827 00009779 8A15[22860100]      <1> 	mov	dl, [FindFile_Drv]
  4828 0000977F 38F2                <1> 	cmp	dl, dh ; dh = [Current_Drv]
  4829 00009781 7407                <1> 	je	short rename_sf_change_directory
  4830                              <1> 
  4831 00009783 E8F5E0FFFF          <1> 	call	change_current_drive
  4832                              <1>  	;jc	loc_file_rw_cmd_failed
  4833                              <1> 	; 28/07/2022
  4834 00009788 722D                <1> 	jc	short loc_rename_fff_failed
  4835                              <1> 
  4836                              <1> rename_sf_change_directory:
  4837 0000978A 803D[23860100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  4838 00009791 7614                <1> 	jna	short rename_sf_find
  4839                              <1> 
  4840 00009793 FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  4841 00009799 BE[23860100]        <1> 	mov	esi, FindFile_Directory
  4842 0000979E 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0
  4843 000097A0 E88B0E0000          <1> 	call	change_current_directory
  4844                              <1>  	;jc	loc_file_rw_cmd_failed
  4845                              <1> 	; 28/07/2022
  4846 000097A5 7210                <1> 	jc	short loc_rename_fff_failed
  4847                              <1> 
  4848                              <1> ;rename_sf_change_prompt_dir_string:
  4849                              <1> 	;call	change_prompt_dir_string
  4850                              <1> 
  4851                              <1> rename_sf_find:
  4852                              <1> 	;mov	esi, [DelFile_FNPointer]
  4853 000097A7 BE[64860100]        <1> 	mov	esi, FindFile_Name
  4854                              <1> 
  4855 000097AC 66B80008            <1> 	mov	ax, 0800h ; Except volume labels
  4856 000097B0 E8B5F3FFFF          <1> 	call	find_first_file
  4857                              <1> 	;jc	loc_file_rw_cmd_failed
  4858                              <1> 	; 28/07/2022
  4859 000097B5 7305                <1> 	jnc	short loc_rename_sf_ambgfn_check
  4860                              <1> 
  4861                              <1> loc_rename_fff_failed:
  4862 000097B7 E9C2F7FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4863                              <1> 
  4864                              <1> loc_rename_sf_ambgfn_check:
  4865 000097BC 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  4866                              <1> 	;	(Note: It was BX in TRDOS v1)
  4867                              <1> 	;;jz	short loc_rename_sf_found
  4868                              <1> 	;jnz	loc_file_not_found
  4869                              <1> 	; 28/07/2022
  4870 000097BF 7405                <1> 	jz	short loc_rename_sf_found
  4871 000097C1 E995FCFFFF          <1> 	jmp	loc_file_not_found
  4872                              <1> 
  4873                              <1> 	;mov	eax, 2 ; File not found sign
  4874                              <1> 	;stc
  4875                              <1> 	;jmp	loc_file_rw_cmd_failed
  4876                              <1> 
  4877                              <1> loc_rename_sf_found:
  4878                              <1> 	; EDI = Directory buffer entry offset/address
  4879                              <1> 	; BL = File (or Directory) Attributes 
  4880                              <1> 	;	(Note: It was 'CL' in TRDOS v1)
  4881                              <1> 	; mov	bl, [EDI+0Bh]
  4882                              <1> 
  4883 000097C6 F6C307              <1> 	test	bl, 07h ; Attributes, S-H-R
  4884                              <1> 	;jnz	loc_permission_denied
  4885                              <1> 	; 28/07/2022
  4886 000097C9 7405                <1> 	jz	short loc_rename_attrb_ok
  4887 000097CB E9B8F7FFFF          <1> 	jmp	loc_permission_denied
  4888                              <1> 
  4889                              <1> loc_rename_attrb_ok:
  4890 000097D0 BE[22860100]        <1>         mov     esi, FindFile_Drv
  4891 000097D5 BF[68870100]        <1>         mov     edi, SourceFile_Drv
  4892 000097DA B920000000          <1> 	mov	ecx, 32
  4893 000097DF F3A5                <1> 	rep	movsd
  4894                              <1> 
  4895                              <1> loc_rename_df_parse_path_name:
  4896 000097E1 8B35[64870100]      <1> 	mov	esi, [DestinationFilePath]
  4897 000097E7 BF[22860100]        <1> 	mov	edi, FindFile_Drv
  4898 000097EC E829140000          <1> 	call	parse_path_name
  4899 000097F1 7219                <1> 	jc	short loc_rename_df_cmd_failed
  4900                              <1> 
  4901                              <1> 	;mov	dh, [RUN_CDRV]
  4902 000097F3 8A35[827D0100]      <1> 	mov	dh, [Current_Drv]
  4903                              <1> 
  4904                              <1> 	; 'rename' command is valid only for same dos drive and same dir!
  4905                              <1> 	; ('move' command must be used if source file and destination file
  4906                              <1> 	; directories are not same!)
  4907 000097F9 8A15[22860100]      <1> 	mov	dl, [FindFile_Drv]
  4908 000097FF 38F2                <1> 	cmp	dl, dh ; are source and destination drives different ?!
  4909 00009801 7509                <1> 	jne	short loc_rename_df_cmd_failed ; yes!
  4910                              <1> 
  4911                              <1> rename_df_check_dirname_exists:
  4912 00009803 803D[23860100]00    <1> 	cmp	byte [FindFile_Directory], 0
  4913 0000980A 760B                <1> 	jna	short rename_df_check_filename_exists
  4914                              <1> 
  4915                              <1> 	; different source file and destination file directories !
  4916                              <1> loc_rename_df_cmd_failed:
  4917 0000980C B801000000          <1> 	mov	eax, 1 ; TRDOS 'Bad command or file name' error
  4918 00009811 F9                  <1> 	stc
  4919 00009812 E967F7FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4920                              <1> 
  4921                              <1> rename_df_check_filename_exists:
  4922 00009817 BE[64860100]        <1> 	mov	esi, FindFile_Name
  4923 0000981C E8EEF6FFFF          <1> 	call	check_filename
  4924                              <1> 	;jc	loc_mkdir_invalid_dir_name_chars
  4925                              <1> 	; 28/07/2022
  4926 00009821 7305                <1> 	jnc	short loc_rename_file_name_ok
  4927 00009823 E908F8FFFF          <1> 	jmp	loc_mkdir_invalid_dir_name_chars
  4928                              <1> 
  4929                              <1> loc_rename_file_name_ok:
  4930                              <1> 	;mov	[DelFile_FNPointer], esi
  4931                              <1> 	;cmp	byte [esi], 20h
  4932                              <1> 	;ja	short loc_rename_df_find
  4933                              <1> 
  4934                              <1> 	;mov	dh, [Current_Drv] ; dh has not been changed
  4935                              <1> 
  4936                              <1> rename_df_drv_check_writable:
  4937 00009828 0FB6F6              <1> 	movzx	esi, dh
  4938                              <1> 	;movzx	esi, byte [Current_Drv]
  4939 0000982B 81C600010900        <1> 	add	esi, Logical_DOSDisks
  4940                              <1> 
  4941 00009831 88F2                <1> 	mov	dl, dh ; dl = [Current_Drv]
  4942 00009833 8A7601              <1> 	mov	dh, [esi+LD_DiskType]
  4943                              <1> 
  4944 00009836 80FE01              <1> 	cmp	dh, 1 ; 0 = Invalid
  4945 00009839 7310                <1> 	jnb	short rename_df_compare_sf_df_name
  4946                              <1> 
  4947                              <1> 	; 16/10/2016 (13h -> 30)
  4948 0000983B B81E000000          <1> 	mov	eax, 30 ; 'Disk write-protected' error
  4949 00009840 8B1D[64870100]      <1> 	mov	ebx, [DestinationFilePath]
  4950 00009846 E933F7FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4951                              <1> 
  4952                              <1> rename_df_compare_sf_df_name:
  4953 0000984B BE[64860100]        <1> 	mov	esi, FindFile_Name
  4954 00009850 BF[AA870100]        <1> 	mov	edi, SourceFile_Name
  4955                              <1> 	;mov	ecx, 12
  4956                              <1> 	; 28/07/2022
  4957 00009855 29C9                <1> 	sub	ecx, ecx
  4958 00009857 B10C                <1> 	mov	cl, 12
  4959                              <1> rename_df_compare_sf_df_name_next:
  4960 00009859 AC                  <1> 	lodsb
  4961 0000985A AE                  <1> 	scasb
  4962 0000985B 7506                <1> 	jne	short loc_rename_df_find
  4963 0000985D 08C0                <1> 	or	al, al
  4964 0000985F 74AB                <1> 	jz	short loc_rename_df_cmd_failed
  4965 00009861 E2F6                <1> 	loop	rename_df_compare_sf_df_name_next
  4966                              <1> 
  4967                              <1> loc_rename_df_find:
  4968                              <1> 	;mov	esi, [DelFile_FNPointer]
  4969 00009863 BE[64860100]        <1> 	mov	esi, FindFile_Name
  4970                              <1> 
  4971                              <1> 	;xor	ax, ax ; Any
  4972                              <1> 	; 28/07/2022
  4973 00009868 31C0                <1> 	xor	eax, eax ; 0 ; Any
  4974 0000986A E8FBF2FFFF          <1> 	call	find_first_file
  4975                              <1> 	;;jnc	short loc_rename_df_found
  4976                              <1> 	;; 29/12/2017
  4977                              <1> 	;jnc	loc_permission_denied
  4978                              <1> 	; 28/07/2022
  4979 0000986F 7205                <1> 	jc	short loc_rename_df_check_error_code
  4980 00009871 E912F7FFFF          <1> 	jmp	loc_permission_denied
  4981                              <1> 
  4982                              <1> loc_rename_df_check_error_code:
  4983                              <1> 	;cmp	eax, 2
  4984 00009876 3C02                <1> 	cmp	al, 2 ; Not found error
  4985 00009878 7406                <1> 	je	short rename_df_move_find_struct_to_dest
  4986 0000987A F9                  <1> 	stc
  4987 0000987B E9FEF6FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  4988                              <1> 
  4989                              <1> ;loc_rename_df_found:
  4990                              <1> 	; 05/11/2016
  4991                              <1> 	; Permission denied error
  4992                              <1> 	;mov	eax, ERR_PERM_DENIED ; 29/12/2017
  4993                              <1> 	;stc
  4994                              <1> 	;jmp	loc_permission_denied  ; 06/11/2016
  4995                              <1> 
  4996                              <1> rename_df_move_find_struct_to_dest:
  4997 00009880 BE[22860100]        <1>         mov     esi, FindFile_Drv
  4998 00009885 BF[E8870100]        <1>         mov     edi, DestinationFile_Drv
  4999                              <1> 	;mov	ecx, 32
  5000                              <1> 	; 28/07/2022
  5001 0000988A 29C9                <1> 	sub	ecx, ecx
  5002 0000988C B120                <1> 	mov	cl, 32
  5003 0000988E F3A5                <1> 	rep	movsd
  5004                              <1> 
  5005                              <1> loc_rename_df_process_q_sf:
  5006                              <1> 	;mov	ecx, 12
  5007 00009890 B10C                <1> 	mov	cl, 12
  5008 00009892 BE[AA870100]        <1>  	mov	esi, SourceFile_Name
  5009 00009897 BF[F3390100]        <1> 	mov	edi, Rename_OldName
  5010                              <1> rename_df_process_q_nml_1_sf:
  5011 0000989C AC                  <1> 	lodsb
  5012 0000989D 3C20                <1>         cmp	al, 20h
  5013 0000989F 7603                <1>         jna	short rename_df_process_q_nml_2_sf
  5014 000098A1 AA                  <1> 	stosb
  5015 000098A2 E2F8                <1> 	loop	rename_df_process_q_nml_1_sf
  5016                              <1> 
  5017                              <1> rename_df_process_q_nml_2_sf:
  5018 000098A4 C60700              <1> 	mov	byte [edi], 0
  5019                              <1> 
  5020                              <1> loc_rename_df_process_q_df:
  5021                              <1> 	;mov	ecx, 12
  5022 000098A7 B10C                <1> 	mov	cl, 12
  5023 000098A9 BE[2A880100]        <1> 	mov	esi, DestinationFile_Name
  5024 000098AE BF[043A0100]        <1> 	mov	edi, Rename_NewName
  5025                              <1> rename_df_process_q_nml_1_df:
  5026 000098B3 AC                  <1> 	lodsb
  5027 000098B4 3C20                <1> 	cmp	al, 20h
  5028 000098B6 7603                <1> 	jna	short loc_rename_df_process_q_nml_2_df
  5029 000098B8 AA                  <1> 	stosb
  5030 000098B9 E2F8                <1> 	loop	rename_df_process_q_nml_1_df
  5031                              <1> 
  5032                              <1> loc_rename_df_process_q_nml_2_df:
  5033 000098BB C60700              <1> 	mov	byte [edi], 0
  5034                              <1> 
  5035                              <1> loc_rename_confirmation_question:
  5036 000098BE BE[CB390100]        <1> 	mov	esi, Msg_DoYouWantRename
  5037 000098C3 E8A2D4FFFF          <1> 	call	print_msg
  5038                              <1> 
  5039 000098C8 A0[C5870100]        <1> 	mov	al, [SourceFile_DirEntry+11] ; Attributes
  5040 000098CD 2410                <1> 	and	al, 10h
  5041 000098CF 750C                <1> 	jnz	short rename_confirmation_question_dir
  5042                              <1> 
  5043                              <1> rename_confirmation_question_file:
  5044 000098D1 BE[E2390100]        <1> 	mov	esi, Rename_File
  5045 000098D6 E88FD4FFFF          <1> 	call	print_msg 
  5046 000098DB EB0A                <1> 	jmp	short rename_confirmation_question_as
  5047                              <1> 
  5048                              <1> rename_confirmation_question_dir:
  5049 000098DD BE[E8390100]        <1> 	mov	esi, Rename_Directory
  5050 000098E2 E883D4FFFF          <1> 	call	print_msg
  5051                              <1> 
  5052                              <1> rename_confirmation_question_as:
  5053 000098E7 BE[F3390100]        <1> 	mov	esi, Rename_OldName
  5054 000098EC E879D4FFFF          <1> 	call	print_msg
  5055 000098F1 BE[003A0100]        <1> 	mov	esi, Msg_File_rename_as
  5056 000098F6 E86FD4FFFF          <1> 	call	print_msg
  5057 000098FB BE[27390100]        <1> 	mov	esi, Msg_YesNo
  5058 00009900 E865D4FFFF          <1> 	call	print_msg
  5059                              <1> 
  5060                              <1> loc_rename_ask_again:
  5061 00009905 30E4                <1> 	xor	ah, ah
  5062 00009907 E81076FFFF          <1> 	call	int16h
  5063 0000990C 3C1B                <1> 	cmp	al, 1Bh
  5064 0000990E 740F                <1> 	je	short loc_do_not_rename_file
  5065 00009910 24DF                <1> 	and	al, 0DFh
  5066 00009912 A2[31390100]        <1> 	mov	[Y_N_nextline], al
  5067 00009917 3C59                <1> 	cmp	al, 'Y'
  5068 00009919 7404                <1> 	je	short loc_yes_rename_file
  5069 0000991B 3C4E                <1> 	cmp	al, 'N'
  5070 0000991D 75E6                <1> 	jne	short loc_rename_ask_again
  5071                              <1> 
  5072                              <1> loc_do_not_rename_file:
  5073                              <1> loc_yes_rename_file:
  5074 0000991F E88DF7FFFF          <1> 	call	y_n_answer ; 29/12/2017
  5075                              <1> 	;cmp	al, 'Y' ; 'yes'
  5076                              <1> 	;cmc
  5077                              <1>         ;jnc	loc_file_rw_restore_retn
  5078 00009924 3C4E                <1> 	cmp	al, 'N' ; 'no'
  5079                              <1> 	;je	loc_file_rw_restore_retn
  5080                              <1> 	; 28/07/2022
  5081 00009926 7505                <1> 	jne	short loc_rename_file_yes
  5082 00009928 E951F6FFFF          <1> 	jmp	loc_file_rw_restore_retn
  5083                              <1> 
  5084                              <1> loc_rename_file_yes: ; 28/07/2022
  5085 0000992D BE[043A0100]        <1> 	mov	esi, Rename_NewName
  5086 00009932 668B0D[E2870100]    <1> 	mov	cx, [SourceFile_DirEntryNumber]
  5087 00009939 66A1[CE870100]      <1> 	mov	ax, [SourceFile_DirEntry+20] ; First Cluster, HW
  5088 0000993F C1E010              <1> 	shl	eax, 16 ; 13/11/2017
  5089 00009942 66A1[D4870100]      <1> 	mov	ax, [SourceFile_DirEntry+26] ; First Cluster, LW
  5090                              <1> 
  5091 00009948 0FB61D[B7870100]    <1>   	movzx	ebx, byte [SourceFile_LongNameEntryLength]
  5092 0000994F E8C91A0000          <1>    	call	rename_directory_entry
  5093 00009954 E93EF7FFFF          <1> 	jmp	loc_rename_file_ok
  5094                              <1> ;loc_rename_file_ok:
  5095                              <1> ;	jc	loc_run_cmd_failed
  5096                              <1> ;	mov	esi, Msg_OK
  5097                              <1> ;	call	proc_printmsg
  5098                              <1> ;	jmp	loc_file_rw_restore_retn
  5099                              <1> 
  5100                              <1> move_file:
  5101                              <1> 	; 07/08/2022
  5102                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
  5103                              <1> 	; 11/03/2016
  5104                              <1> 	; 09/03/2016
  5105                              <1> 	; 08/03/2016 (TRDOS 386 = TRDOS v2.0)
  5106                              <1> 	; 21/05/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_move')
  5107                              <1> 	; 23/04/2011
  5108                              <1> 
  5109                              <1> get_move_source_fchar:
  5110                              <1> 	; esi = file name
  5111 00009959 803E20              <1> 	cmp	byte [esi], 20h
  5112 0000995C 7613                <1>         jna	short loc_move_nofilename_retn
  5113                              <1> 
  5114 0000995E 8935[60870100]      <1> 	mov	[SourceFilePath], esi
  5115                              <1> 
  5116                              <1> move_scan_source_file:
  5117 00009964 46                  <1> 	inc	esi
  5118 00009965 803E20              <1> 	cmp	byte [esi], 20h
  5119 00009968 7408                <1>         je      short move_scan_destination_1
  5120                              <1> 	;;jb	short loc_move_nofilename_retn
  5121                              <1> 	;jb	loc_cmd_failed
  5122                              <1> 	;jmp	short move_scan_source_file
  5123                              <1> 	; 28/07/2022
  5124 0000996A 77F8                <1> 	ja	short move_scan_source_file
  5125                              <1> loc_move_failed:
  5126 0000996C E9D3ECFFFF          <1> 	jmp	loc_cmd_failed
  5127                              <1> 
  5128                              <1> loc_move_nofilename_retn:
  5129 00009971 C3                  <1> 	retn
  5130                              <1> 
  5131                              <1> move_scan_destination_1:
  5132 00009972 C60600              <1> 	mov	byte [esi], 0
  5133                              <1> 
  5134                              <1> move_scan_destination_2:
  5135 00009975 46                  <1> 	inc	esi  
  5136 00009976 803E20              <1> 	cmp	byte [esi], 20h
  5137 00009979 74FA                <1> 	je	short move_scan_destination_2
  5138                              <1> 	;;jb	short loc_move_nofilename_retn
  5139                              <1> 	;jb	loc_cmd_failed
  5140                              <1> 	; 28/07/2022
  5141 0000997B 72EF                <1> 	jb	short loc_move_failed
  5142                              <1> 
  5143 0000997D 8935[64870100]      <1> 	mov	[DestinationFilePath], esi
  5144                              <1> 
  5145                              <1> move_scan_destination_3:
  5146 00009983 46                  <1> 	inc	esi  
  5147 00009984 803E20              <1> 	cmp	byte [esi], 20h
  5148 00009987 77FA                <1> 	ja	short move_scan_destination_3
  5149 00009989 C60600              <1> 	mov	byte [esi], 0
  5150                              <1> 
  5151                              <1> loc_move_scan_destination_OK:
  5152 0000998C 8B35[60870100]      <1> 	mov	esi, [SourceFilePath]
  5153 00009992 8B3D[64870100]      <1> 	mov	edi, [DestinationFilePath]
  5154                              <1> 
  5155 00009998 B001                <1> 	mov	al, 1  ; move procedure Phase 1
  5156 0000999A E8F81A0000          <1> 	call	move_source_file_to_destination_file
  5157 0000999F 7325                <1> 	jnc	short move_source_file_to_destination_question
  5158                              <1> 
  5159                              <1> loc_move_cmd_failed_1:
  5160 000099A1 08C0                <1> 	or	al, al
  5161                              <1> 	;jz	loc_cmd_failed
  5162                              <1> 	; 28/07/2022
  5163 000099A3 74C7                <1> 	jz	short loc_move_failed
  5164                              <1> 
  5165 000099A5 3C11                <1> 	cmp	al, 11h
  5166 000099A7 7409                <1> 	je	short loc_msg_not_same_device
  5167                              <1> 	;cmp	al, 05h
  5168                              <1> 	;cmp	al, ERR_PERM_DENIED ; 29/12/2017
  5169                              <1> 	;jne	loc_run_cmd_failed
  5170                              <1> 	;jmp	loc_permission_denied
  5171 000099A9 3C0B                <1> 	cmp	al, ERR_PERM_DENIED
  5172                              <1> 	;je	loc_permission_denied
  5173                              <1> 	; 28/07/2022
  5174 000099AB 7414                <1> 	je	short loc_move_perm_denied
  5175 000099AD E9BDECFFFF          <1> 	jmp	loc_run_cmd_failed
  5176                              <1> 
  5177                              <1> 	;mov	esi, Msg_Permission_denied
  5178                              <1> 	;call	print_msg
  5179                              <1> 	;jmp	loc_file_rw_restore_retn
  5180                              <1> 
  5181                              <1> loc_msg_not_same_device:
  5182 000099B2 BE[113A0100]        <1> 	mov	esi, msg_not_same_drv
  5183 000099B7 E8AED3FFFF          <1> 	call	print_msg
  5184 000099BC E9BDF5FFFF          <1> 	jmp	loc_file_rw_restore_retn
  5185                              <1> 
  5186                              <1> 	; 28/07/2022
  5187                              <1> loc_move_perm_denied:
  5188 000099C1 E9C2F5FFFF          <1> 	jmp	loc_permission_denied
  5189                              <1> 
  5190                              <1> move_source_file_to_destination_question:
  5191 000099C6 A0[68870100]        <1>         mov     al, [SourceFile_Drv]
  5192 000099CB 0441                <1> 	add	al, 'A'
  5193 000099CD A2[733A0100]        <1> 	mov	[msg_source_file_drv], al
  5194 000099D2 A0[E8870100]        <1>         mov     al, [DestinationFile_Drv]
  5195 000099D7 0441                <1> 	add	al, 'A'
  5196 000099D9 A2[923A0100]        <1> 	mov	[msg_destination_file_drv], al
  5197                              <1> 
  5198 000099DE 57                  <1> 	push	edi ; *
  5199                              <1> 
  5200 000099DF BE[573A0100]        <1> 	mov	esi, msg_source_file
  5201 000099E4 E881D3FFFF          <1> 	call	print_msg
  5202 000099E9 BE[69870100]        <1> 	mov	esi, SourceFile_Directory
  5203 000099EE 803E20              <1> 	cmp	byte [esi], 20h
  5204 000099F1 7605                <1> 	jna	short msftdfq_sfn
  5205 000099F3 E872D3FFFF          <1> 	call	print_msg
  5206                              <1> msftdfq_sfn:
  5207 000099F8 BE[AA870100]        <1> 	mov	esi, SourceFile_Name
  5208 000099FD E868D3FFFF          <1> 	call	print_msg
  5209 00009A02 BE[763A0100]        <1> 	mov	esi, msg_destination_file
  5210 00009A07 E85ED3FFFF          <1> 	call	print_msg
  5211 00009A0C BE[E9870100]        <1> 	mov	esi, DestinationFile_Directory
  5212 00009A11 803E20              <1> 	cmp	byte [esi], 20h
  5213 00009A14 7605                <1> 	jna	short msftdfq_dfn
  5214 00009A16 E84FD3FFFF          <1> 	call	print_msg
  5215                              <1> msftdfq_dfn:
  5216 00009A1B BE[2A880100]        <1> 	mov	esi, DestinationFile_Name
  5217 00009A20 E845D3FFFF          <1> 	call	print_msg
  5218 00009A25 BE[953A0100]        <1> 	mov	esi, msg_copy_nextline
  5219 00009A2A E83BD3FFFF          <1> 	call	print_msg
  5220 00009A2F BE[953A0100]        <1> 	mov	esi, msg_copy_nextline
  5221 00009A34 E831D3FFFF          <1> 	call	print_msg
  5222                              <1> 
  5223                              <1> loc_move_ask_for_new_file_yes_no:
  5224 00009A39 BE[233A0100]        <1> 	mov	esi, Msg_DoYouWantMoveFile
  5225 00009A3E E827D3FFFF          <1> 	call	print_msg
  5226 00009A43 BE[27390100]        <1> 	mov	esi, Msg_YesNo
  5227 00009A48 E81DD3FFFF          <1> 	call	print_msg
  5228                              <1> loc_move_ask_for_new_file_again:
  5229 00009A4D 30E4                <1> 	xor	ah, ah
  5230 00009A4F E8C874FFFF          <1> 	call	int16h
  5231 00009A54 3C1B                <1> 	cmp	al, 1Bh
  5232                              <1> 	;je	short loc_do_not_move_file
  5233 00009A56 743F                <1> 	je	short loc_move_y_n_escape
  5234 00009A58 24DF                <1> 	and	al, 0DFh
  5235 00009A5A A2[31390100]        <1>         mov     [Y_N_nextline], al
  5236 00009A5F 3C59                <1> 	cmp	al, 'Y'
  5237 00009A61 7404                <1> 	je	short loc_yes_move_file
  5238 00009A63 3C4E                <1> 	cmp	al, 'N'
  5239 00009A65 75E6                <1> 	jne	short loc_move_ask_for_new_file_again
  5240                              <1> 
  5241                              <1> loc_do_not_move_file:
  5242                              <1> loc_yes_move_file:
  5243 00009A67 E845F6FFFF          <1> 	call	y_n_answer ; 29/12/2017
  5244 00009A6C 5F                  <1> 	pop	edi ; *
  5245                              <1> 	;cmp	al, 'Y' ; 'yes'
  5246                              <1> 	;cmc
  5247                              <1>         ;jnc	loc_file_rw_restore_retn
  5248 00009A6D 3C4E                <1> 	cmp	al, 'N' ; 'no'
  5249                              <1>         ;je	loc_file_rw_restore_retn
  5250                              <1> 	; 28/07/2022
  5251 00009A6F 7421                <1> 	je	short loc_move_rw_restore_retn
  5252                              <1> 
  5253                              <1> loc_move_yes_move_file:
  5254 00009A71 B002                <1> 	mov	al, 2 ; move procedure Phase 2
  5255 00009A73 E81F1A0000          <1> 	call	move_source_file_to_destination_file
  5256                              <1> 	;;jc	short loc_move_cmd_failed_2
  5257                              <1>         ;jnc	move_source_file_to_dest_OK
  5258                              <1> 	; 28/07/2022
  5259 00009A78 7205                <1> 	jc	short loc_move_cmd_failed_2
  5260                              <1> 	; 07/08/2022
  5261 00009A7A E91FF6FFFF          <1> 	jmp	move_source_file_to_dest_OK
  5262                              <1> 
  5263                              <1> ;move_source_file_to_destination_OK:
  5264                              <1> ;	mov	esi, Msg_OK
  5265                              <1> ;	call	print_msg
  5266                              <1> ;	jmp	loc_file_rw_restore_retn
  5267                              <1> 
  5268                              <1> loc_move_cmd_failed_2:
  5269 00009A7F 3C27                <1> 	cmp	al, 27h
  5270                              <1> 	;jne	loc_run_cmd_failed
  5271                              <1> 	; 28/07/2022
  5272 00009A81 7405                <1> 	je	short loc_move_ids_err
  5273 00009A83 E9E7EBFFFF          <1> 	jmp	loc_run_cmd_failed
  5274                              <1> 
  5275                              <1> loc_move_ids_err: ; 28/07/2022
  5276 00009A88 BE[3C3A0100]        <1> 	mov	esi, msg_insufficient_disk_space
  5277 00009A8D E8D8D2FFFF          <1> 	call	print_msg
  5278                              <1> 
  5279                              <1> loc_move_rw_restore_retn: ; 28/07/2022
  5280 00009A92 E9E7F4FFFF          <1> 	jmp	loc_file_rw_restore_retn
  5281                              <1> 
  5282                              <1> loc_move_y_n_escape:
  5283 00009A97 B04E                <1> 	mov	al, 'N' ; 'no'
  5284 00009A99 EBCC                <1> 	jmp	short loc_do_not_move_file
  5285                              <1> 
  5286                              <1> copy_file:
  5287                              <1> 	; 31/08/2024 - TRDOS 386 v2.0.9
  5288                              <1> 	; 25/07/2022 - TRDOS 386 Kernel v2.0.5
  5289                              <1> 	; 15/10/2016
  5290                              <1> 	; 24/03/2016
  5291                              <1> 	; 21/03/2016
  5292                              <1> 	; 15/03/2016 (TRDOS 386 = TRDOS v2.0)
  5293                              <1> 	; 21/05/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_copy')
  5294                              <1> 	; 01/08/2010
  5295                              <1> 
  5296                              <1> get_copy_source_fchar:
  5297                              <1> 	; esi = file name
  5298 00009A9B 803E20              <1> 	cmp	byte [esi], 20h
  5299 00009A9E 7613                <1>         jna     short loc_copy_nofilename_retn
  5300                              <1> 
  5301 00009AA0 8935[60870100]      <1> 	mov	[SourceFilePath], esi
  5302                              <1> 
  5303                              <1> copy_scan_source_file:
  5304 00009AA6 46                  <1> 	inc	esi  
  5305 00009AA7 803E20              <1> 	cmp	byte [esi], 20h
  5306 00009AAA 7408                <1> 	je	short copy_scan_destination_1
  5307                              <1> 	;;jb	short loc_copy_nofilename_retn
  5308                              <1> 	;jb	loc_cmd_failed
  5309                              <1> 	;jmp	short copy_scan_source_file
  5310                              <1> 	; 25/07/2022
  5311 00009AAC 73F8                <1> 	jnb	short copy_scan_source_file
  5312                              <1> copy_scan_destination_0:
  5313 00009AAE E991EBFFFF          <1> 	jmp	loc_cmd_failed
  5314                              <1> 
  5315                              <1> loc_copy_nofilename_retn:
  5316 00009AB3 C3                  <1> 	retn
  5317                              <1> 
  5318                              <1> copy_scan_destination_1:
  5319 00009AB4 C60600              <1> 	mov	byte [esi], 0
  5320                              <1> 
  5321                              <1> copy_scan_destination_2:
  5322 00009AB7 46                  <1> 	inc	esi  
  5323 00009AB8 803E20              <1> 	cmp	byte [esi], 20h
  5324 00009ABB 74FA                <1> 	je	short copy_scan_destination_2
  5325                              <1> 	;;jb	short loc_copy_nofilename_retn
  5326                              <1> 	;jb	loc_cmd_failed
  5327                              <1> 	; 25/07/2022
  5328 00009ABD 72EF                <1> 	jb	short copy_scan_destination_0
  5329                              <1> 
  5330 00009ABF 8935[64870100]      <1> 	mov	[DestinationFilePath], esi
  5331                              <1> 
  5332                              <1> copy_scan_destination_3:
  5333 00009AC5 46                  <1> 	inc	esi
  5334 00009AC6 803E20              <1> 	cmp	byte [esi], 20h
  5335 00009AC9 77FA                <1> 	ja	short copy_scan_destination_3
  5336 00009ACB C60600              <1> 	mov	byte [esi], 0
  5337                              <1> 
  5338                              <1> loc_copy_save_current_drive:
  5339 00009ACE 8A35[827D0100]      <1> 	mov	dh, [Current_Drv]
  5340 00009AD4 8835[DF840100]      <1> 	mov	[RUN_CDRV], dh
  5341                              <1> 
  5342                              <1> copy_source_file_to_destination_phase_1:
  5343 00009ADA 8B35[60870100]      <1> 	mov	esi, [SourceFilePath]
  5344 00009AE0 8B3D[64870100]      <1> 	mov	edi, [DestinationFilePath]
  5345                              <1> 
  5346 00009AE6 B001                <1> 	mov	al, 1  ; copy procedure Phase 1
  5347 00009AE8 E8431C0000          <1> 	call	copy_source_file_to_destination_file
  5348 00009AED 7327                <1> 	jnc	short copy_source_file_to_destination_question
  5349                              <1> 
  5350                              <1> loc_copy_cmd_failed_1:
  5351                              <1> 	; 18/03/2016 (restore current drive and directory)
  5352 00009AEF 08C0                <1> 	or	al, al
  5353 00009AF1 7507                <1> 	jnz	short loc_copy_cmd_failed_2
  5354                              <1> 
  5355 00009AF3 FEC0                <1>         inc     al ; mov al, 1 ; Bad command or file name !
  5356                              <1> loc_copy_cmd_failed_3:	; 25/07/2022
  5357 00009AF5 E975EBFFFF          <1> 	jmp	loc_run_cmd_failed
  5358                              <1> 
  5359                              <1> loc_copy_cmd_failed_2:
  5360 00009AFA 3C27                <1> 	cmp	al, 27h ; Insufficient disk space 
  5361 00009AFC 7409                <1> 	je	short loc_file_write_insuff_disk_space_msg
  5362                              <1> 
  5363                              <1> 	; 29/12/2017
  5364                              <1> 	;cmp	al, 05h
  5365 00009AFE 3C0B                <1> 	cmp	al, ERR_PERM_DENIED
  5366                              <1> 	;jne	loc_run_cmd_failed
  5367                              <1> 	; 25/07/2022
  5368 00009B00 75F3                <1> 	jne	short loc_copy_cmd_failed_3
  5369                              <1> 
  5370 00009B02 E981F4FFFF          <1> 	jmp	loc_permission_denied
  5371                              <1> 
  5372                              <1> loc_file_write_insuff_disk_space_msg:
  5373 00009B07 BE[3C3A0100]        <1> 	mov	esi, msg_insufficient_disk_space
  5374 00009B0C E859D2FFFF          <1> 	call	print_msg
  5375 00009B11 E968F4FFFF          <1>         jmp     loc_file_rw_restore_retn 
  5376                              <1> 
  5377                              <1> copy_source_file_to_destination_question:
  5378 00009B16 57                  <1> 	push	edi ; *
  5379                              <1> 
  5380                              <1> 	; dh = source file attributes
  5381                              <1> 	; dl > 0 -> destination file found
  5382 00009B17 20D2                <1> 	and	dl, dl
  5383 00009B19 7446                <1> 	jz	short copy_source_file_to_destination_pass_owrq
  5384                              <1> 
  5385                              <1> loc_copy_ask_for_owr_yes_no:
  5386 00009B1B BE[983A0100]        <1> 	mov	esi, Msg_DoYouWantOverWriteFile
  5387 00009B20 E845D2FFFF          <1> 	call	print_msg
  5388 00009B25 BE[2A880100]        <1> 	mov	esi, DestinationFile_Name
  5389 00009B2A E83BD2FFFF          <1> 	call	print_msg
  5390 00009B2F BE[27390100]        <1> 	mov	esi, Msg_YesNo
  5391 00009B34 E831D2FFFF          <1> 	call	print_msg
  5392                              <1> 
  5393                              <1> loc_copy_ask_for_owr_again:
  5394 00009B39 30E4                <1> 	xor	ah, ah
  5395 00009B3B E8DC73FFFF          <1> 	call	int16h
  5396 00009B40 3C1B                <1> 	cmp	al, 1Bh
  5397                              <1>         ;je     loc_do_not_copy_file
  5398 00009B42 7419                <1>         je      short loc_copy_y_n_escape
  5399 00009B44 24DF                <1> 	and	al, 0DFh
  5400 00009B46 A2[31390100]        <1>         mov     [Y_N_nextline], al
  5401 00009B4B 3C59                <1> 	cmp	al, 'Y'
  5402                              <1> 	;je	loc_yes_copy_file
  5403                              <1> 	; 25/07/2022
  5404 00009B4D 7505                <1> 	jne	short loc_copy_ask_for_owr_n
  5405 00009B4F E9AD000000          <1> 	jmp	loc_yes_copy_file
  5406                              <1> 
  5407                              <1> loc_copy_ask_for_owr_n: ; 25/07/2022
  5408 00009B54 3C4E                <1> 	cmp	al, 'N'
  5409                              <1>         ;je	loc_do_not_copy_file
  5410                              <1> 	;jmp	short loc_copy_ask_for_owr_again
  5411                              <1> 	; 25/07/2022
  5412 00009B56 75E1                <1> 	jne	short loc_copy_ask_for_owr_again
  5413                              <1> loc_do_not_copy_file_j:
  5414 00009B58 E9A4000000          <1> 	jmp	loc_do_not_copy_file
  5415                              <1> 
  5416                              <1> loc_copy_y_n_escape:
  5417 00009B5D B04E                <1> 	mov	al, 'N' ; 'no'
  5418                              <1> 	;jmp	loc_do_not_copy_file
  5419                              <1> 	; 25/07/2022
  5420 00009B5F EBF7                <1> 	jmp	short loc_do_not_copy_file_j
  5421                              <1> 
  5422                              <1> copy_source_file_to_destination_pass_owrq:
  5423 00009B61 A0[68870100]        <1> 	mov     al, [SourceFile_Drv]
  5424 00009B66 0441                <1> 	add	al, 'A'
  5425 00009B68 A2[733A0100]        <1> 	mov	[msg_source_file_drv], al
  5426 00009B6D A0[E8870100]        <1>         mov     al, [DestinationFile_Drv]
  5427 00009B72 0441                <1> 	add	al, 'A'
  5428 00009B74 A2[923A0100]        <1> 	mov	[msg_destination_file_drv], al
  5429                              <1> 
  5430 00009B79 BE[573A0100]        <1> 	mov	esi, msg_source_file
  5431 00009B7E E8E7D1FFFF          <1> 	call	print_msg
  5432 00009B83 BE[69870100]        <1> 	mov	esi, SourceFile_Directory
  5433 00009B88 803E20              <1> 	cmp	byte [esi], 20h
  5434 00009B8B 7605                <1> 	jna	short csftdfq_sfn
  5435 00009B8D E8D8D1FFFF          <1> 	call	print_msg
  5436                              <1> csftdfq_sfn:
  5437 00009B92 BE[AA870100]        <1> 	mov	esi, SourceFile_Name
  5438 00009B97 E8CED1FFFF          <1> 	call	print_msg
  5439 00009B9C BE[763A0100]        <1> 	mov	esi, msg_destination_file
  5440 00009BA1 E8C4D1FFFF          <1> 	call	print_msg
  5441 00009BA6 BE[E9870100]        <1> 	mov	esi, DestinationFile_Directory
  5442 00009BAB 803E20              <1> 	cmp	byte [esi], 20h
  5443 00009BAE 7605                <1> 	jna	short csftdfq_dfn
  5444 00009BB0 E8B5D1FFFF          <1> 	call	print_msg
  5445                              <1> csftdfq_dfn:
  5446 00009BB5 BE[2A880100]        <1> 	mov	esi, DestinationFile_Name
  5447 00009BBA E8ABD1FFFF          <1> 	call	print_msg
  5448 00009BBF BE[953A0100]        <1> 	mov	esi, msg_copy_nextline
  5449 00009BC4 E8A1D1FFFF          <1> 	call	print_msg
  5450 00009BC9 BE[953A0100]        <1> 	mov	esi, msg_copy_nextline
  5451 00009BCE E897D1FFFF          <1> 	call	print_msg
  5452                              <1> 
  5453                              <1> loc_copy_ask_for_new_file_yes_no:
  5454 00009BD3 BE[B73A0100]        <1> 	mov	esi, Msg_DoYouWantCopyFile
  5455 00009BD8 E88DD1FFFF          <1> 	call	print_msg
  5456 00009BDD BE[27390100]        <1> 	mov	esi, Msg_YesNo
  5457 00009BE2 E883D1FFFF          <1> 	call	print_msg
  5458                              <1> 
  5459                              <1> loc_copy_ask_for_new_file_again:
  5460 00009BE7 30E4                <1> 	xor	ah, ah
  5461 00009BE9 E82E73FFFF          <1> 	call	int16h
  5462 00009BEE 3C1B                <1> 	cmp	al, 1Bh
  5463 00009BF0 740F                <1> 	je	short loc_do_not_copy_file
  5464 00009BF2 24DF                <1> 	and	al, 0DFh
  5465 00009BF4 A2[31390100]        <1>         mov     [Y_N_nextline], al
  5466 00009BF9 3C59                <1> 	cmp	al, 'Y'
  5467 00009BFB 7404                <1> 	je	short loc_yes_copy_file
  5468 00009BFD 3C4E                <1> 	cmp	al, 'N'
  5469 00009BFF 75E6                <1> 	jne	short loc_copy_ask_for_new_file_again
  5470                              <1> 
  5471                              <1> loc_do_not_copy_file:
  5472                              <1> loc_yes_copy_file:
  5473 00009C01 E8ABF4FFFF          <1> 	call	y_n_answer ; 29/12/2017
  5474 00009C06 5F                  <1> 	pop	edi ; *
  5475                              <1> 	;cmp	al, 'Y' ; 'yes'
  5476                              <1> 	;cmc
  5477                              <1>         ;jnc	loc_file_rw_restore_retn
  5478 00009C07 3C4E                <1> 	cmp	al, 'N' ; 'no'
  5479                              <1> 	;je	loc_file_rw_restore_retn
  5480                              <1> 	; 25/07/2022
  5481 00009C09 7505                <1> 	jne	short copy_source_file_to_destination_pass_q
  5482 00009C0B E96EF3FFFF          <1> 	jmp	loc_file_rw_restore_retn
  5483                              <1> 
  5484                              <1> copy_source_file_to_destination_pass_q:
  5485 00009C10 B002                <1> 	mov	al, 2  ; copy procedure Phase 2
  5486 00009C12 E8191B0000          <1> 	call	copy_source_file_to_destination_file
  5487                              <1> 	;jc	short loc_file_write_check_disk_space_err
  5488                              <1> 
  5489                              <1> 	; 31/08/2024
  5490 00009C17 9C                  <1> 	pushf
  5491                              <1> 
  5492                              <1> 	; 24/03/2016
  5493                              <1> 	;;push	cx
  5494                              <1> 	;push	ecx ; 29/12/2017
  5495                              <1> 
  5496 00009C18 BE[953A0100]        <1> 	mov	esi, msg_copy_nextline
  5497 00009C1D E848D1FFFF          <1> 	call	print_msg
  5498                              <1> 
  5499                              <1> 	;pop	eax ; 29/12/2017
  5500                              <1> 	;;pop	cx
  5501                              <1> 	;pop	ax
  5502                              <1> 
  5503                              <1> 	; 31/08/2024
  5504 00009C22 9D                  <1> 	popf
  5505 00009C23 7305                <1> 	jnc	short copy_source_file_to_destination_OK
  5506                              <1> 
  5507                              <1> 	; 31/08/2024
  5508                              <1> 	;;or	cl, cl
  5509                              <1> 	;;or	al, al
  5510                              <1> 	;jz	short copy_source_file_to_destination_OK
  5511                              <1> 	;
  5512                              <1> 	;; 15/10/2016 (1Dh -> 18)
  5513                              <1> 	;; 18/03/2016 (1Dh)
  5514                              <1> 	;;cmp	cl, 18 ; write error
  5515                              <1> 	;cmp	al, 18
  5516                              <1> 	;jne	short copy_source_file_to_destination_not_OK
  5517                              <1> 	;;
  5518                              <1> 	;;mov	al, cl ; error number (write fault!)
  5519                              <1> 	;stc
  5520                              <1> 
  5521 00009C25 E954F3FFFF          <1> 	jmp	loc_file_rw_cmd_failed
  5522                              <1> 
  5523                              <1> 	; 31/08/2024
  5524                              <1> ;copy_source_file_to_destination_not_OK:
  5525                              <1> 	;mov	esi, Msg_read_file_error_before_EOF
  5526                              <1> 	;call	print_msg
  5527                              <1> 	;jmp	loc_file_rw_restore_retn
  5528                              <1> 
  5529                              <1> copy_source_file_to_destination_OK:
  5530 00009C2A BE[35390100]        <1> 	mov	esi, Msg_OK
  5531 00009C2F E836D1FFFF          <1> 	call	print_msg
  5532                              <1> 
  5533 00009C34 E945F3FFFF          <1> 	jmp	loc_file_rw_restore_retn
  5534                              <1> 
  5535                              <1> ;loc_file_write_check_disk_space_err:
  5536                              <1> 	;cmp	al, 27h ; Insufficient disk space
  5537                              <1> 	;je	loc_file_write_insuff_disk_space_msg
  5538                              <1>         ;jb	loc_file_rw_cmd_failed
  5539                              <1> 
  5540                              <1> 	;call	print_misc_error_msg ; 15/03/2016
  5541                              <1>         ;jmp	loc_file_rw_restore_retn
  5542                              <1> 
  5543                              <1> change_fs_file_attributes:
  5544                              <1> 	; 04/03/2016 ; Temporary
  5545                              <1> 	; AL = File or directory attributes
  5546                              <1> 	; AH = 0 -> Attributes are in MS-DOS format
  5547                              <1> 	; AH > 0 -> Attributes are in SINGLIX format
  5548                              <1> 	;push	ebx
  5549                              <1> 	; ... do somethings here ...
  5550                              <1> 	;pop	ebx
  5551                              <1> 	; BL = File or directory attributes
  5552 00009C39 C3                  <1> 	retn
  5553                              <1> 
  5554                              <1> set_get_env:
  5555                              <1> 	; 25/07/2022 - TRDOS 386 Kernel v2.0.5
  5556                              <1> 	; 11/04/2016 (TRDOS 386 = TRDOS v2.0)
  5557                              <1> 	; 02/09/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_set')
  5558                              <1> 	; 2005 - 28/08/2011 
  5559                              <1> get_setenv_fchar:
  5560                              <1> 	; esi = environment variable/string
  5561 00009C3A 8A06                <1> 	mov	al, [esi]
  5562 00009C3C 3C20                <1> 	cmp	al, 20h
  5563 00009C3E 771E                <1> 	ja	short loc_find_env
  5564                              <1> 
  5565 00009C40 BE00300900          <1> 	mov	esi, Env_Page
  5566                              <1> loc_print_setline:
  5567 00009C45 803E00              <1> 	cmp	byte [esi], 0
  5568 00009C48 7613                <1> 	jna	short loc_setenv_retn
  5569 00009C4A E81BD1FFFF          <1> 	call	print_msg
  5570 00009C4F 56                  <1> 	push	esi
  5571 00009C50 BE[273F0100]        <1> 	mov	esi, nextline
  5572 00009C55 E810D1FFFF          <1> 	call	print_msg
  5573 00009C5A 5E                  <1> 	pop	esi
  5574 00009C5B EBE8                <1> 	jmp	short loc_print_setline
  5575                              <1> 
  5576                              <1> loc_setenv_retn:
  5577 00009C5D C3                  <1> 	retn
  5578                              <1> 
  5579                              <1> loc_find_env:
  5580 00009C5E 3C3D                <1> 	cmp	al, '='
  5581                              <1> 	;je	loc_cmd_failed
  5582                              <1> 	; 25/07/2022
  5583 00009C60 7505                <1> 	jne	short loc_find_envr
  5584 00009C62 E9DDE9FFFF          <1> 	jmp	loc_cmd_failed
  5585                              <1> 
  5586                              <1> loc_find_envr:	; 25/07/2022
  5587 00009C67 56                  <1> 	push	esi
  5588                              <1> loc_repeat_env_equal_check:
  5589 00009C68 46                  <1> 	inc	esi
  5590 00009C69 803E3D              <1> 	cmp	byte [esi], '='
  5591 00009C6C 7430                <1> 	je	short pass_env_equal_check
  5592 00009C6E 803E20              <1> 	cmp	byte [esi], 20h
  5593 00009C71 73F5                <1> 	jnb	short loc_repeat_env_equal_check
  5594 00009C73 C60600              <1> 	mov	byte [esi], 0
  5595 00009C76 5E                  <1> 	pop	esi
  5596                              <1> 	; 25/07/2022 (*)
  5597                              <1> loc_print_env_string:
  5598 00009C77 BF[827E0100]        <1> 	mov	edi, TextBuffer ; out buffer
  5599 00009C7C B9FF000000          <1> 	mov	ecx, 255 ; maximum size (limit)
  5600 00009C81 30C0                <1> 	xor	al, al ; 0 -> use [ESI]
  5601 00009C83 E877000000          <1> 	call	get_environment_string
  5602 00009C88 72D3                <1> 	jc	short loc_setenv_retn
  5603                              <1> 	 ; 25/07/2022
  5604                              <1> ;loc_print_env_string:
  5605 00009C8A BE[827E0100]        <1> 	mov	esi, TextBuffer
  5606 00009C8F E8D6D0FFFF          <1> 	call	print_msg
  5607 00009C94 BE[273F0100]        <1> 	mov	esi, nextline
  5608                              <1> 	;call	print_msg
  5609                              <1> 	;retn
  5610                              <1> 	; 25/07/2022
  5611 00009C99 E9CCD0FFFF          <1> 	jmp	print_msg
  5612                              <1> 
  5613                              <1> pass_env_equal_check:
  5614 00009C9E 46                  <1> 	inc	esi
  5615 00009C9F 803E20              <1> 	cmp	byte [esi], 20h
  5616 00009CA2 73FA                <1> 	jnb	short pass_env_equal_check
  5617 00009CA4 C60600              <1> 	mov	byte [esi], 0
  5618                              <1> 
  5619                              <1> loc_call_set_env_string:
  5620 00009CA7 5E                  <1> 	pop	esi
  5621 00009CA8 E815010000          <1> 	call	set_environment_string
  5622 00009CAD 73AE                <1> 	jnc	short loc_setenv_retn
  5623                              <1> 
  5624                              <1> loc_set_cmd_failed:
  5625 00009CAF 3C08                <1> 	cmp	al, 08h
  5626                              <1> 	;jne	loc_cmd_failed
  5627                              <1> 	; 25/07/2022
  5628 00009CB1 7405                <1> 	je	short loc_set_cmd_failed_spc
  5629 00009CB3 E98CE9FFFF          <1> 	jmp	loc_cmd_failed
  5630                              <1> 
  5631                              <1> loc_set_cmd_failed_spc:
  5632 00009CB8 BE[103B0100]        <1> 	mov	esi, Msg_No_Set_Space
  5633                              <1> 	;call	print_msg
  5634                              <1> 	;retn
  5635                              <1> 	; 25/07/2022
  5636 00009CBD E9A8D0FFFF          <1> 	jmp	print_msg
  5637                              <1> 
  5638                              <1> set_get_path:
  5639                              <1> 	; 25/07/2022 - TRDOS 386 Kernel v2.0.5
  5640                              <1> 	; 11/04/2016 (TRDOS 386 = TRDOS v2.0)
  5641                              <1> 	; 03/09/2011 (TRDOS v1, CMD_INTR.ASM, 'cmp_cmd_path')
  5642                              <1> 	; 2005
  5643                              <1> get_path_fchar:
  5644                              <1>  	; esi = path
  5645 00009CC2 803E20              <1> 	cmp	byte [esi], 20h
  5646 00009CC5 7711                <1> 	ja	short loc_set_path
  5647                              <1> 
  5648 00009CC7 BE00300900          <1> 	mov	esi, Env_Page
  5649                              <1> loc_print_path:
  5650 00009CCC 803E00              <1> 	cmp	byte [esi], 0
  5651 00009CCF 762D                <1> 	jna	short loc_path_retn
  5652                              <1> 
  5653 00009CD1 BE[6F350100]        <1> 	mov	esi, Cmd_Path ; 'PATH' address
  5654                              <1> 	; 25/07/2022 (*)
  5655 00009CD6 EB9F                <1> 	jmp	short loc_print_env_string
  5656                              <1> ; 25/07/2022
  5657                              <1> ;	mov	edi, TextBuffer ; out buffer
  5658                              <1> ;	xor	al, al  ; use [ESI]
  5659                              <1> ;	mov	ecx, 255 ; maximum size (limit)
  5660                              <1> ;	call	get_environment_string
  5661                              <1> ;	;jc	short loc_path_retn
  5662                              <1> ;	; 25/07/2022
  5663                              <1> ;	jnc	short loc_print_env_string
  5664                              <1> ;	retn
  5665                              <1> 
  5666                              <1> ;	mov	esi, TextBuffer
  5667                              <1> ;	call	print_msg
  5668                              <1> ;	mov	esi, nextline
  5669                              <1> ;	;call	print_msg
  5670                              <1> ;loc_path_retn:
  5671                              <1> ;	;retn
  5672                              <1> ;	; 25/07/2022
  5673                              <1> ;	jmp	print_msg
  5674                              <1> 
  5675                              <1> loc_set_path:
  5676 00009CD8 56                  <1> 	push	esi
  5677                              <1> loc_set_path_find_end:
  5678 00009CD9 46                  <1> 	inc	esi
  5679 00009CDA 803E20              <1> 	cmp	byte [esi], 20h
  5680 00009CDD 73FA                <1> 	jnb	short loc_set_path_find_end
  5681 00009CDF C60600              <1> 	mov	byte [esi], 0
  5682                              <1> loc_set_path_header:
  5683 00009CE2 5E                  <1> 	pop	esi
  5684                              <1> set_path_x: ; 31/12/2017 ('syspath')
  5685 00009CE3 4E                  <1> 	dec	esi
  5686 00009CE4 C6063D              <1> 	mov	byte [esi], '='
  5687 00009CE7 4E                  <1> 	dec	esi
  5688 00009CE8 C60648              <1> 	mov	byte [esi], 'H'
  5689 00009CEB 4E                  <1> 	dec	esi
  5690 00009CEC C60654              <1> 	mov	byte [esi], 'T'
  5691 00009CEF 4E                  <1> 	dec	esi
  5692 00009CF0 C60641              <1> 	mov	byte [esi], 'A'
  5693 00009CF3 4E                  <1> 	dec	esi
  5694 00009CF4 C60650              <1> 	mov	byte [esi], 'P'
  5695                              <1> 
  5696                              <1> loc_path_call_set_env_string:
  5697 00009CF7 E8C6000000          <1> 	call	set_environment_string
  5698 00009CFC 72B1                <1>         jc	short loc_set_cmd_failed
  5699                              <1> loc_path_retn:	; 25/07/2022
  5700 00009CFE C3                  <1> 	retn
  5701                              <1> 
  5702                              <1> get_environment_string:
  5703                              <1> 	; 12/04/2016
  5704                              <1> 	; 11/04/2016
  5705                              <1> 	; 05/04/2016 (TRDOS 386 = TRDOS v2.0)
  5706                              <1> 	; 02/09/2011 (TRDOS v1, MAINPROG.ASM)
  5707                              <1> 	; 28/08/2011
  5708                              <1> 	; INPUT->
  5709                              <1> 	;	EDI = Output buffer
  5710                              <1> 	;	CX = Buffer length (<= ENV_PAGE_SIZE)
  5711                              <1> 	;
  5712                              <1> 	;	AL > 0 = AL = String sequence number
  5713                              <1> 	;	AL = 0 -> ESI = ASCIIZ Set word
  5714                              <1> 	;		(environment variable)
  5715                              <1> 	; OUTPUT ->
  5716                              <1> 	;	ESI is not changed
  5717                              <1> 	;	EDI is not changed
  5718                              <1> 	;	EAX = String length (with zero tail)
  5719                              <1> 	;	EDX = Environment variables page address
  5720                              <1> 	;	CF = 1 -> Not found (EAX not valid)
  5721                              <1> 	;
  5722                              <1> 	; (Modified registers: EAX, EDX)
  5723                              <1> 
  5724 00009CFF BA00300900          <1> 	mov	edx, Env_Page
  5725 00009D04 803A00              <1> 	cmp	byte [edx], 0
  5726 00009D07 7474                <1> 	jz	short get_env_string_with_word_stc_retn
  5727                              <1> 
  5728 00009D09 66890D[EC880100]    <1> 	mov	[env_var_length], cx
  5729                              <1> 
  5730 00009D10 51                  <1> 	push	ecx ; *
  5731 00009D11 56                  <1> 	push	esi ; **
  5732                              <1> 
  5733 00009D12 08C0                <1> 	or	al, al
  5734 00009D14 7449                <1> 	jz	short get_env_string_with_word
  5735                              <1> 
  5736                              <1> get_env_string_with_seq_number:
  5737 00009D16 B101                <1> 	mov	cl, 1
  5738 00009D18 88C5                <1> 	mov	ch, al
  5739 00009D1A 31C0                <1> 	xor	eax, eax
  5740 00009D1C 89D6                <1> 	mov	esi, edx ; Env_Page
  5741                              <1> 
  5742                              <1> get_env_string_seq_number_check:
  5743 00009D1E 38CD                <1> 	cmp	ch, cl
  5744 00009D20 7726                <1> 	ja	short get_env_string_seq_number_next
  5745                              <1> 
  5746                              <1> get_env_string_move_to_buff:
  5747 00009D22 57                  <1> 	push	edi ; ***
  5748                              <1> 
  5749 00009D23 29D2                <1> 	sub	edx, edx
  5750                              <1> 
  5751                              <1> get_env_string_seq_number_repeat1:
  5752 00009D25 42                  <1> 	inc	edx
  5753 00009D26 AC                  <1> 	lodsb
  5754 00009D27 AA                  <1> 	stosb
  5755                              <1> 
  5756 00009D28 66FF0D[EC880100]    <1> 	dec	word [env_var_length]
  5757 00009D2F 7508                <1> 	jnz	short get_env_string_seq_number_repeat3
  5758                              <1> 
  5759                              <1> get_env_string_seq_number_repeat2:
  5760 00009D31 20C0                <1> 	and	al, al
  5761 00009D33 7408                <1> 	jz	short get_env_string_seq_number_ok
  5762 00009D35 42                  <1> 	inc	edx
  5763 00009D36 AC                  <1> 	lodsb
  5764 00009D37 EBF8                <1> 	jmp	short get_env_string_seq_number_repeat2
  5765                              <1> 
  5766                              <1> get_env_string_seq_number_repeat3:
  5767 00009D39 08C0                <1> 	or	al, al
  5768 00009D3B 75E8                <1> 	jnz	short get_env_string_seq_number_repeat1
  5769                              <1> 
  5770                              <1> get_env_string_seq_number_ok:
  5771 00009D3D 5F                  <1> 	pop	edi ; ***
  5772 00009D3E 89D0                <1> 	mov	eax, edx ; Length of the environment string
  5773                              <1> 			 ; (ASCIIZ, includes ZERO tail)
  5774 00009D40 BA00300900          <1> 	mov	edx, Env_Page
  5775                              <1> 
  5776                              <1> get_env_string_stc_retn:
  5777 00009D45 5E                  <1> 	pop	esi ; **
  5778 00009D46 59                  <1> 	pop	ecx ; *
  5779 00009D47 C3                  <1> 	retn   
  5780                              <1> 	
  5781                              <1> get_env_string_seq_number_next:
  5782 00009D48 AC                  <1> 	lodsb
  5783 00009D49 08C0                <1> 	or	al, al
  5784 00009D4B 75FB                <1> 	jnz	short get_env_string_seq_number_next
  5785                              <1> 
  5786 00009D4D 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size ; +512 (+4096)
  5787 00009D53 F5                  <1> 	cmc
  5788 00009D54 72EF                <1> 	jc	short get_env_string_stc_retn
  5789                              <1> 
  5790 00009D56 AC                  <1> 	lodsb
  5791 00009D57 3C01                <1> 	cmp	al, 1
  5792 00009D59 72EA                <1> 	jb	short get_env_string_stc_retn
  5793 00009D5B FEC1                <1> 	inc	cl
  5794 00009D5D EBBF                <1> 	jmp	short get_env_string_seq_number_check
  5795                              <1> 
  5796                              <1> get_env_string_with_word:
  5797 00009D5F 31C9                <1> 	xor	ecx, ecx
  5798                              <1> 
  5799                              <1> get_env_string_calc_word_length:
  5800 00009D61 AC                  <1> 	lodsb 
  5801 00009D62 3C20                <1> 	cmp	al, 20h
  5802 00009D64 7211                <1> 	jb	short get_env_string_calc_word_length_ok
  5803                              <1> 	;inc	cx
  5804 00009D66 FEC1                <1> 	inc	cl
  5805                              <1> 
  5806 00009D68 3C61                <1> 	cmp	al, 'a'
  5807 00009D6A 72F5                <1> 	jb	short get_env_string_calc_word_length
  5808 00009D6C 3C7A                <1> 	cmp	al, 'z'
  5809 00009D6E 77F1                <1> 	ja	short get_env_string_calc_word_length
  5810 00009D70 24DF                <1> 	and	al, 0DFh
  5811 00009D72 8846FF              <1> 	mov	[esi-1], al
  5812 00009D75 EBEA                <1> 	jmp	short get_env_string_calc_word_length
  5813                              <1> 
  5814                              <1> get_env_string_calc_word_length_ok:
  5815 00009D77 08C9                <1> 	or	cl, cl
  5816 00009D79 7506                <1> 	jnz	short get_env_string_calc_word_length_save
  5817                              <1> 
  5818 00009D7B 5E                  <1> 	pop	esi ; **
  5819                              <1> 
  5820                              <1> get_env_string_stc_retn1:
  5821 00009D7C 59                  <1> 	pop	ecx ; *
  5822                              <1> 
  5823                              <1> get_env_string_with_word_stc_retn:
  5824 00009D7D 31C0                <1> 	xor	eax, eax
  5825 00009D7F F9                  <1> 	stc
  5826 00009D80 C3                  <1> 	retn
  5827                              <1> 
  5828                              <1> get_env_string_calc_word_length_save:
  5829 00009D81 871C24              <1> 	xchg	ebx, [esp] ; **
  5830 00009D84 89DE                <1> 	mov	esi, ebx 
  5831                              <1> 		; Start of the env string (to be searched)
  5832                              <1> 
  5833 00009D86 57                  <1> 	push	edi ; ***
  5834 00009D87 89D7                <1> 	mov	edi, edx ; Env_Page
  5835                              <1> 
  5836                              <1> get_env_string_compare:
  5837 00009D89 57                  <1> 	push	edi ; ****
  5838 00009D8A 51                  <1> 	push	ecx ; ***** ; Variable name length
  5839                              <1> 
  5840                              <1> get_env_string_compare_rep:
  5841 00009D8B AC                  <1> 	lodsb
  5842 00009D8C AE                  <1> 	scasb
  5843 00009D8D 7511                <1> 	jne	short get_env_string_compare_next1
  5844 00009D8F E2FA                <1> 	loop	get_env_string_compare_rep
  5845                              <1> 
  5846 00009D91 803F3D              <1> 	cmp	byte [edi], '='
  5847 00009D94 750A                <1> 	jne	short get_env_string_compare_next1
  5848                              <1> 
  5849 00009D96 59                  <1> 	pop	ecx ; *****
  5850 00009D97 5F                  <1> 	pop	edi ; ****
  5851 00009D98 89FE                <1> 	mov	esi, edi
  5852 00009D9A 5F                  <1> 	pop	edi ; ***
  5853 00009D9B 871C24              <1> 	xchg	ebx, [esp] ; **
  5854 00009D9E EB82                <1> 	jmp	short get_env_string_move_to_buff
  5855                              <1> 
  5856                              <1> get_env_string_compare_next1:
  5857 00009DA0 89FE                <1> 	mov	esi, edi
  5858 00009DA2 59                  <1> 	pop	ecx ; *****
  5859 00009DA3 5F                  <1> 	pop	edi ; ****
  5860                              <1> get_env_string_compare_next2:
  5861 00009DA4 81FEFF310900        <1> 	cmp	esi, Env_Page + Env_Page_Size - 1 ; +511 (+4095)
  5862 00009DAA 7310                <1> 	jnb	short get_env_string_compare_not_ok
  5863 00009DAC 20C0                <1> 	and	al, al
  5864 00009DAE AC                  <1> 	lodsb
  5865 00009DAF 75F3                <1> 	jnz	short get_env_string_compare_next2
  5866 00009DB1 08C0                <1> 	or	al, al
  5867 00009DB3 7407                <1> 	jz	short get_env_string_compare_not_ok
  5868 00009DB5 4E                  <1> 	dec	esi ; 12/04/2016
  5869 00009DB6 89F7                <1> 	mov	edi, esi
  5870 00009DB8 89DE                <1> 	mov	esi, ebx
  5871 00009DBA EBCD                <1> 	jmp	short get_env_string_compare
  5872                              <1> 
  5873                              <1> get_env_string_compare_not_ok:
  5874 00009DBC 5F                  <1> 	pop	edi ; ***
  5875 00009DBD 89DE                <1> 	mov	esi, ebx
  5876 00009DBF 5B                  <1> 	pop	ebx ; **
  5877 00009DC0 EBBA                <1> 	jmp	short get_env_string_stc_retn1
  5878                              <1> 
  5879                              <1> set_environment_string:
  5880                              <1> 	; 25/07/2022 - TRDOS 386 Kernel v2.0.5
  5881                              <1> 	; 13/04/2016
  5882                              <1> 	; 12/04/2016
  5883                              <1> 	; 11/04/2016
  5884                              <1> 	; 06/04/2016
  5885                              <1> 	; 05/04/2016 (TRDOS 386 = TRDOS v2.0)
  5886                              <1> 	; 02/09/2011 (TRDOS v1, MAINPROG.ASM)
  5887                              <1> 	; 29/08/2011
  5888                              <1> 	; 29/08/2011
  5889                              <1> 	; INPUT->
  5890                              <1> 	;	ESI = ASCIIZ environment string
  5891                              <1> 	; OUTPUT ->
  5892                              <1> 	;	ESI is not changed
  5893                              <1> 	;	CF = 1 -> Could not set,
  5894                              <1> 	;	     insufficient environment space
  5895                              <1> 	;
  5896                              <1> 	; (EAX, EDX will be changed)
  5897                              <1> 	;
  5898                              <1> 	;    (EAX = Start address of the env string if > 0)
  5899                              <1> 	;    (EDX = Environment string length)
  5900                              <1> 
  5901 00009DC2 56                  <1> 	push 	esi ; *
  5902                              <1> 
  5903 00009DC3 31C0                <1> 	xor	eax, eax
  5904                              <1> 
  5905                              <1> set_env_chk_validation1:
  5906 00009DC5 FEC4                <1> 	inc	ah ; variable (string) length
  5907 00009DC7 AC                  <1> 	lodsb
  5908 00009DC8 3C3D                <1> 	cmp	al, '='
  5909 00009DCA 7415                <1> 	je	short set_env_chk_validation2
  5910 00009DCC 3C20                <1> 	cmp	al, 20h
  5911 00009DCE 720F                <1> 	jb	short set_env_string_stc
  5912                              <1> 
  5913                              <1> 	; 06/04/2016
  5914 00009DD0 3C61                <1> 	cmp	al, 'a'
  5915 00009DD2 72F1                <1> 	jb	short set_env_chk_validation1
  5916 00009DD4 3C7A                <1> 	cmp	al, 'z'
  5917 00009DD6 77ED                <1> 	ja	short set_env_chk_validation1
  5918 00009DD8 2C20                <1> 	sub	al, 'a'-'A'
  5919 00009DDA 8846FF              <1> 	mov	[esi-1], al
  5920 00009DDD EBE6                <1> 	jmp	short set_env_chk_validation1
  5921                              <1> 
  5922                              <1> set_env_string_stc:
  5923 00009DDF 5E                  <1> 	pop	esi ; *
  5924                              <1> 	;stc
  5925 00009DE0 C3                  <1> 	retn
  5926                              <1> 
  5927                              <1> set_env_chk_validation2:
  5928 00009DE1 51                  <1> 	push	ecx ; **
  5929 00009DE2 53                  <1> 	push	ebx ; ***
  5930 00009DE3 57                  <1> 	push	edi ; ****
  5931                              <1> 
  5932                              <1> 	; 12/04/2016
  5933                              <1> 	;mov	ebx, [esp+12]
  5934                              <1> 	; 25/07/2022
  5935 00009DE4 8B54240C            <1> 	mov	edx, [esp+12]
  5936                              <1> 
  5937                              <1> set_env_chk_validation2w:
  5938 00009DE8 89F7                <1> 	mov	edi, esi
  5939 00009DEA 4F                  <1> 	dec	edi
  5940                              <1> 
  5941 00009DEB 807FFF20            <1> 	cmp	byte [edi-1], 20h
  5942 00009DEF 771A                <1> 	ja	short set_env_chk_validation2z
  5943                              <1> 
  5944 00009DF1 56                  <1> 	push	esi
  5945 00009DF2 89FE                <1> 	mov	esi, edi
  5946 00009DF4 4E                  <1> 	dec	esi
  5947                              <1> 
  5948                              <1> set_env_chk_validation2x:
  5949 00009DF5 4E                  <1> 	dec	esi
  5950                              <1> 
  5951                              <1> 	;cmp	esi, ebx
  5952 00009DF6 39D6                <1> 	cmp	esi, edx ; 25/07/2022
  5953 00009DF8 7207                <1> 	jb	short set_env_chk_validation2y
  5954                              <1> 
  5955 00009DFA 4F                  <1> 	dec	edi
  5956                              <1> 
  5957 00009DFB 8A06                <1> 	mov	al, [esi]
  5958 00009DFD 8807                <1> 	mov	[edi], al
  5959                              <1> 
  5960 00009DFF EBF4                <1> 	jmp	short set_env_chk_validation2x
  5961                              <1> 
  5962                              <1> set_env_chk_validation2y:
  5963 00009E01 5E                  <1> 	pop	esi
  5964                              <1> 
  5965                              <1> 	;;mov	byte [ebx], 20h
  5966                              <1> 	; 25/07/2022
  5967                              <1> 	;mov	byte [edx], 20h
  5968                              <1> 
  5969                              <1> 	;inc 	ebx
  5970                              <1> 	;mov	[esp+12], ebx
  5971                              <1> 	; 25/07/2022
  5972 00009E02 42                  <1> 	inc	edx
  5973 00009E03 8954240C            <1> 	mov	[esp+12], edx
  5974                              <1> 
  5975 00009E07 FECC                <1> 	dec 	ah ; 13/04/2016
  5976                              <1> 
  5977 00009E09 EBDD                <1> 	jmp	short set_env_chk_validation2w
  5978                              <1> 
  5979                              <1> set_env_chk_validation2z:
  5980                              <1> 	;mov	edx, Env_Page
  5981                              <1> 	;mov	edi, edx
  5982                              <1> 	; 25/07/2022
  5983 00009E0B BB00300900          <1> 	mov	ebx, Env_Page
  5984 00009E10 89DF                <1> 	mov	edi, ebx
  5985                              <1> 
  5986                              <1> set_env_chk_validation3:
  5987 00009E12 AC                  <1> 	lodsb
  5988 00009E13 3C20                <1> 	cmp	al, 20h
  5989 00009E15 74FB                <1> 	je	short set_env_chk_validation3
  5990                              <1> 
  5991 00009E17 9C                  <1> 	pushf
  5992                              <1> 
  5993                              <1> 	; 12/04/2016
  5994                              <1> set_env_chk_validation3n:
  5995 00009E18 3C61                <1> 	cmp	al, 'a'
  5996 00009E1A 720C                <1> 	jb	short set_env_chk_validation3c
  5997 00009E1C 3C7A                <1> 	cmp	al, 'z'
  5998 00009E1E 7705                <1> 	ja	short set_env_chk_validation3x
  5999 00009E20 2C20                <1> 	sub	al, 'a'-'A'
  6000 00009E22 8846FF              <1> 	mov	[esi-1], al
  6001                              <1> 
  6002                              <1> set_env_chk_validation3x:
  6003 00009E25 AC                  <1> 	lodsb
  6004 00009E26 EBF0                <1> 	jmp	short set_env_chk_validation3n
  6005                              <1> 
  6006                              <1> set_env_chk_validation3c:
  6007 00009E28 3C20                <1> 	cmp	al, 20h
  6008 00009E2A 73F9                <1> 	jnb	short set_env_chk_validation3x
  6009                              <1> 		
  6010 00009E2C 803F00              <1> 	cmp	byte [edi], 0
  6011 00009E2F 772B                <1> 	ja	short set_env_chk_validation4
  6012                              <1> 
  6013 00009E31 9D                  <1> 	popf
  6014 00009E32 7222                <1> 	jb	short set_env_string_nothing
  6015                              <1> 
  6016 00009E34 B900020000          <1> 	mov	ecx, Env_Page_Size ; 512 (4096)
  6017                              <1> 
  6018                              <1> 	;mov	esi, ebx ; 12/04/2016
  6019                              <1> 	; 25/07/2022
  6020 00009E39 89D6                <1> 	mov	esi, edx
  6021                              <1> 
  6022                              <1> 	; 25/07/2022
  6023 00009E3B 89CA                <1> 	mov	edx, ecx
  6024                              <1> 
  6025                              <1> set_env_string_copy_to_envb:
  6026 00009E3D AC                  <1> 	lodsb
  6027 00009E3E 3C20                <1> 	cmp	al, 20h
  6028 00009E40 7207                <1> 	jb	short set_env_string_copy_to_envb_z
  6029 00009E42 AA                  <1> 	stosb
  6030 00009E43 E2F8                <1> 	loop	set_env_string_copy_to_envb
  6031                              <1> 
  6032                              <1> 	; 11/04/2016
  6033                              <1> 	;mov	edi, edx ; Env_Page
  6034                              <1> 	; 25/07/2022
  6035 00009E45 89DF                <1> 	mov	edi, ebx
  6036                              <1> 	; 25/07/2022
  6037                              <1> 	;mov	ecx, Env_Page_Size
  6038 00009E47 89D1                <1> 	mov	ecx, edx
  6039                              <1> 
  6040                              <1> set_env_string_copy_to_envb_z:
  6041                              <1> 	; 25/07/2022
  6042                              <1> 	;push	edx  ; Start address of the variable
  6043                              <1> 
  6044                              <1> 	;;mov	edx, Env_Page_Size
  6045                              <1> 	;; 25/07/2022
  6046 00009E49 29CA                <1> 	sub	edx, ecx ; variable (string) length
  6047                              <1> 
  6048 00009E4B 28C0                <1> 	sub	al, al ; 0
  6049 00009E4D F3AA                <1>  	rep	stosb ; clear remain bytes of the env page
  6050                              <1> 
  6051                              <1> 	;pop	eax  ; Start address of the variable
  6052                              <1> 	; 25/07/2022
  6053 00009E4F 89D8                <1> 	mov	eax, ebx
  6054                              <1> 
  6055                              <1> set_env_string_allocate_envb_retn:  ; stc or clc return
  6056 00009E51 5F                  <1> 	pop	edi ; ****
  6057 00009E52 5B                  <1> 	pop	ebx ; ***
  6058 00009E53 59                  <1> 	pop	ecx ; **
  6059 00009E54 5E                  <1> 	pop	esi ; *
  6060 00009E55 C3                  <1> 	retn
  6061                              <1> 
  6062                              <1> set_env_string_nothing:
  6063 00009E56 31C0                <1> 	xor	eax, eax
  6064 00009E58 31D2                <1> 	xor	edx, edx ; 11/04/2016
  6065 00009E5A EBF5                <1> 	jmp	short set_env_string_allocate_envb_retn
  6066                              <1> 
  6067                              <1> set_env_chk_validation4:
  6068                              <1> 	; 11/04/2016
  6069 00009E5C 9D                  <1> 	popf
  6070                              <1> 
  6071                              <1> 	;mov	esi, edx  ; Env_Page
  6072                              <1> 	; 25/07/2022
  6073 00009E5D 89DE                <1> 	mov	esi, ebx
  6074                              <1> 
  6075                              <1> set_env_chk_validation5:
  6076                              <1> 	;mov	edi, ebx ; ASCIIZ environment string address
  6077                              <1> 	; 25/07/2022
  6078 00009E5F 89D7                <1> 	mov	edi, edx
  6079 00009E61 0FB6CC              <1> 	movzx	ecx, ah ; Variable (string) length (with '=')
  6080                              <1> 
  6081                              <1> set_env_chk_validation5_loop:
  6082 00009E64 AC                  <1> 	lodsb
  6083 00009E65 AE                  <1> 	scasb
  6084 00009E66 7508                <1> 	jne	short set_env_chk_validation6
  6085 00009E68 E2FA                <1> 	loop	set_env_chk_validation5_loop
  6086                              <1> 
  6087 00009E6A 3C3D                <1> 	cmp	al, '='
  6088                              <1>         ;je	set_env_change_variable
  6089                              <1> 	; 25/07/2022
  6090 00009E6C 7502                <1> 	jne	short set_env_chk_validation6
  6091 00009E6E EB7E                <1> 	jmp	set_env_change_variable
  6092                              <1> 
  6093                              <1> set_env_chk_validation6:
  6094 00009E70 08C0                <1> 	or	al, al ; 0
  6095 00009E72 7403                <1> 	jz	short set_env_chk_validation7
  6096                              <1> 
  6097 00009E74 AC                  <1> 	lodsb
  6098 00009E75 EBF9                <1> 	jmp	short set_env_chk_validation6
  6099                              <1> 
  6100                              <1> set_env_chk_validation7:
  6101 00009E77 88E1                <1> 	mov	cl, ah
  6102 00009E79 01F1                <1> 	add	ecx, esi
  6103 00009E7B 81F9FF310900        <1> 	cmp	ecx, Env_Page + Env_Page_Size - 1
  6104                              <1> 		; 511 (4095) 
  6105                              <1> 		; strlen + '=' + 0
  6106 00009E81 72DC                <1> 	jb	short set_env_chk_validation5
  6107                              <1> 
  6108                              <1> set_env_chk_validation8: ; variable not found
  6109 00009E83 0FB6F4              <1> 	movzx	esi, ah  ; variable name length (with '=')
  6110                              <1> 	;add	esi, ebx ; position just after of the '='
  6111                              <1> 	; 25/07/2022
  6112 00009E86 01D6                <1> 	add	esi, edx
  6113                              <1> 
  6114                              <1> set_env_chk_validation8_loop:
  6115 00009E88 AC                  <1> 	lodsb
  6116 00009E89 3C20                <1> 	cmp	al, 20h
  6117 00009E8B 74FB                <1> 	je	short set_env_chk_validation8_loop
  6118 00009E8D 72C7                <1> 	jb	short set_env_string_nothing
  6119                              <1> 
  6120                              <1> set_env_chk_validation9:
  6121 00009E8F AC                  <1> 	lodsb
  6122 00009E90 3C20                <1> 	cmp	al, 20h
  6123 00009E92 73FB                <1> 	jnb	short set_env_chk_validation9
  6124                              <1> 
  6125                              <1> 	; End of ASCIIZ environment string
  6126                              <1> 
  6127                              <1> set_env_add_variable:
  6128                              <1> 	;sub	esi, ebx ; variable+definition length
  6129                              <1> 	; 25/07/2022
  6130 00009E94 29D6                <1> 	sub	esi, edx
  6131                              <1> 
  6132 00009E96 56                  <1> 	push	esi ; *****
  6133                              <1> 
  6134                              <1> 	;mov	esi, edx ; Environment page address
  6135                              <1> 	; 25/07/2022
  6136 00009E97 89DE                <1> 	mov	esi, ebx
  6137                              <1> 
  6138 00009E99 B900020000          <1> 	mov	ecx, Env_Page_Size ; 512 (4096)
  6139                              <1> 
  6140                              <1> set_env_add_variable_loop:
  6141 00009E9E AC                  <1> 	lodsb
  6142 00009E9F 20C0                <1> 	and	al, al
  6143 00009EA1 7406                <1> 	jz	short set_env_add_variable_chk1 ; 0
  6144 00009EA3 E2F9                <1> 	loop	set_env_add_variable_loop
  6145                              <1> 
  6146                              <1> 	; 11/04/2016
  6147 00009EA5 884EFF              <1> 	mov	[esi-1], cl ; 0
  6148 00009EA8 41                  <1> 	inc	ecx
  6149                              <1> 
  6150                              <1> set_env_add_variable_chk1:
  6151 00009EA9 49                  <1> 	dec	ecx
  6152 00009EAA 7408                <1> 	jz	short set_env_add_variable_nspc
  6153 00009EAC AC                  <1> 	lodsb
  6154 00009EAD 08C0                <1> 	or 	al, al
  6155 00009EAF 740B                <1> 	jz	short set_env_add_variable_chk2 ; 00
  6156 00009EB1 49                  <1> 	dec	ecx
  6157 00009EB2 75EA                <1> 	jnz	short set_env_add_variable_loop
  6158                              <1> 
  6159                              <1> set_env_add_variable_nspc: ; no space on environment page
  6160 00009EB4 58                  <1> 	pop	eax ; *****
  6161                              <1> 	;mov	eax, 8 ; No space for new environment string
  6162                              <1> 	; 25/07/2022
  6163 00009EB5 29C0                <1> 	sub	eax, eax
  6164 00009EB7 B008                <1> 	mov	al, 8
  6165 00009EB9 F9                  <1> 	stc
  6166 00009EBA EB95                <1>         jmp     short set_env_string_allocate_envb_retn
  6167                              <1> 
  6168                              <1> set_env_add_variable_chk2:
  6169 00009EBC 8B0C24              <1> 	mov	ecx, [esp] ; *****
  6170 00009EBF 4E                  <1> 	dec	esi ; beginning address of the new variable
  6171 00009EC0 89F0                <1> 	mov	eax, esi
  6172 00009EC2 01C8                <1> 	add	eax, ecx ; string length (with CR)
  6173                              <1> 	;add	edx, Env_Page_Size ; 512 (4096)
  6174                              <1> 	; 25/07/2022
  6175 00009EC4 81C300020000        <1> 	add	ebx, Env_Page_Size
  6176                              <1> 	;cmp	eax, edx 
  6177 00009ECA 39D8                <1> 	cmp	eax, ebx ; 25/07/2022
  6178 00009ECC 77E6                <1> 	ja	short set_env_add_variable_nspc
  6179 00009ECE 49                  <1> 	dec	ecx ; except CR at the end
  6180                              <1> 	;mov	edx, ecx ; 12/04/2016
  6181                              <1> 	; 25/07/2022
  6182 00009ECF 89CB                <1> 	mov	ebx, ecx
  6183 00009ED1 89F7                <1> 	mov	edi, esi
  6184 00009ED3 893C24              <1> 	mov	[esp], edi ; ***** ; Start address of new variable
  6185                              <1> 	;mov	esi, ebx ; ASCIIZ environment string address
  6186                              <1> 	; 25/07/2022
  6187 00009ED6 89D6                <1> 	mov	esi, edx
  6188 00009ED8 F3A4                <1> 	rep	movsb
  6189 00009EDA 28C0                <1> 	sub	al, al
  6190 00009EDC AA                  <1> 	stosb
  6191 00009EDD 58                  <1> 	pop	eax ; ***** ; Beginning address of new variable
  6192 00009EDE 81FF00320900        <1>         cmp     edi, Env_Page + Env_Page_Size ; 12/04/2016
  6193                              <1> 	;jnb	set_env_string_allocate_envb_retn ; OK !
  6194                              <1> 	; 25/07/2022
  6195 00009EE4 7303                <1>  	jnb	short set_env_add_variable_chk3
  6196 00009EE6 880F                <1> 	mov	[edi], cl ; 0
  6197 00009EE8 F8                  <1> 	clc	; 13/04/2016
  6198                              <1> set_env_add_variable_chk3:
  6199 00009EE9 E963FFFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  6200                              <1> 
  6201                              <1> set_env_change_variable:
  6202                              <1> 	; 06/04/2016
  6203                              <1> 	; esi = Variable's address in environment page (after '=')
  6204                              <1> 	; edi = ASCIIZ environment string address (after '=')
  6205                              <1> 
  6206                              <1> 	; ah = variable length from start to the '='
  6207 00009EEE 8825[EC880100]      <1> 	mov	[env_var_length], ah
  6208                              <1> 
  6209 00009EF4 28C9                <1> 	sub	cl, cl ; ecx = 0
  6210                              <1> 
  6211 00009EF6 57                  <1> 	push	edi ; *****
  6212                              <1> 
  6213 00009EF7 89F7                <1> 	mov	edi, esi ; 11/04/2016
  6214                              <1> 
  6215                              <1> set_env_change_variable_calc1:
  6216 00009EF9 AC                  <1> 	lodsb
  6217 00009EFA 08C0                <1> 	or	al, al
  6218 00009EFC 7403                <1> 	jz	short set_env_change_variable_calc2
  6219                              <1> 
  6220 00009EFE 41                  <1> 	inc	ecx ; length of environment string (after the '=')
  6221                              <1> 
  6222 00009EFF EBF8                <1> 	jmp	short set_env_change_variable_calc1
  6223                              <1> 
  6224                              <1> set_env_change_variable_calc2:
  6225 00009F01 8B3424              <1> 	mov	esi, [esp] ; ASCIIZ environment string address
  6226                              <1> 
  6227 00009F04 29D2                <1> 	sub	edx, edx
  6228                              <1> 
  6229                              <1> set_env_change_variable_calc3:
  6230 00009F06 AC                  <1> 	lodsb
  6231 00009F07 3C20                <1> 	cmp	al, 20h
  6232 00009F09 7203                <1> 	jb	short set_env_change_variable_calc4
  6233                              <1> 
  6234 00009F0B 42                  <1> 	inc	edx ; length of ASCIIZ string (after the '=')
  6235                              <1> 
  6236 00009F0C EBF8                <1> 	jmp	short set_env_change_variable_calc3
  6237                              <1> 	
  6238                              <1> set_env_change_variable_calc4:
  6239 00009F0E C646FF00            <1> 	mov	byte [esi-1], 0  ; put ZERO instead of CR
  6240                              <1> 
  6241 00009F12 5E                  <1> 	pop	esi ; ***** ; ASCIIZ string address (after '=')
  6242                              <1> 
  6243                              <1> 	; EDI = Old variable's address (after '=')
  6244                              <1> 
  6245                              <1> 	; compare the new string with the old string
  6246 00009F13 39CA                <1> 	cmp	edx, ecx
  6247 00009F15 7718                <1> 	ja	short set_env_change_variable_calc5 ; longer
  6248                              <1> 	;jb	set_env_change_variable_calc9 ; shorter
  6249                              <1> 	; 25/07/2022
  6250 00009F17 7405                <1> 	je	short set_env_change_variable_calc22
  6251 00009F19 E98C000000          <1> 	jmp	set_env_change_variable_calc9 
  6252                              <1> 
  6253                              <1> set_env_change_variable_calc22:
  6254                              <1> 	;same length (simple copy)
  6255 00009F1E 0FB6C4              <1> 	movzx	eax, ah
  6256 00009F21 01C2                <1> 	add	edx, eax
  6257 00009F23 F7D8                <1> 	neg	eax
  6258 00009F25 01F8                <1> 	add	eax, edi
  6259                              <1> 	; EAX = Start address of the variable
  6260                              <1> 	; EDX = Variable length (without ZERO at the end of variable)
  6261                              <1> 
  6262 00009F27 F3A4                <1> 	rep	movsb
  6263 00009F29 F8                  <1> 	clc	; 13/04/2016
  6264 00009F2A E922FFFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  6265                              <1> 
  6266                              <1> set_env_change_variable_calc5:
  6267                              <1> 	; 11/04/2016
  6268 00009F2F 52                  <1> 	push	edx ; *****
  6269 00009F30 29CA                <1> 	sub	edx, ecx ; difference ; (the new string is longer)
  6270 00009F32 89F3                <1> 	mov 	ebx, esi
  6271 00009F34 89FE                <1> 	mov	esi, edi
  6272                              <1> 
  6273                              <1> set_env_change_variable_calc6:
  6274 00009F36 AC                  <1> 	lodsb 
  6275 00009F37 20C0                <1> 	and	al, al
  6276 00009F39 75FB                <1> 	jnz	short set_env_change_variable_calc6
  6277                              <1> 
  6278 00009F3B 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size ; 512 (4096)
  6279 00009F41 0F836DFFFFFF        <1>         jnb     set_env_add_variable_nspc
  6280                              <1> 
  6281 00009F47 89F9                <1> 	mov	ecx, edi  ; current (old) variable's address
  6282 00009F49 89F7                <1> 	mov	edi, esi  ; next variable's address
  6283                              <1> 
  6284 00009F4B AC                  <1> 	lodsb
  6285 00009F4C 08C0                <1> 	or	al, al
  6286 00009F4E 7417                <1> 	jz	short set_env_change_variable_calc8 ; 00
  6287                              <1> 
  6288                              <1> set_env_change_variable_calc7:
  6289 00009F50 AC                  <1> 	lodsb
  6290 00009F51 20C0                <1> 	and	al, al
  6291 00009F53 75FB                <1> 	jnz	short set_env_change_variable_calc7
  6292                              <1> 
  6293 00009F55 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size ; 512 (4096)
  6294                              <1> 	;jnb	set_env_add_variable_nspc
  6295                              <1> 	; 25/07/2022
  6296 00009F5B 7205                <1> 	jb	short set_env_change_variable_calc24
  6297                              <1> set_env_change_variable_calc23:
  6298 00009F5D E952FFFFFF          <1> 	jmp	set_env_add_variable_nspc
  6299                              <1> 
  6300                              <1> set_env_change_variable_calc24:
  6301 00009F62 AC                  <1> 	lodsb
  6302 00009F63 08C0                <1> 	or	al, al
  6303 00009F65 75E9                <1> 	jnz	short set_env_change_variable_calc7
  6304                              <1> 
  6305                              <1> set_env_change_variable_calc8:
  6306 00009F67 4E                  <1> 	dec	esi ; address of the second (last) 0 of the 00
  6307                              <1> 
  6308 00009F68 01F2                <1> 	add	edx, esi ; final position of the last 0
  6309                              <1> 
  6310 00009F6A 81FA00320900        <1> 	cmp	edx, Env_Page + Env_Page_Size ; 512 (4096)
  6311                              <1> 	;jnb     set_env_add_variable_nspc
  6312                              <1> 	; 25/07/2022
  6313 00009F70 73EB                <1> 	jnb	short set_env_change_variable_calc23
  6314                              <1> 
  6315 00009F72 89C8                <1> 	mov	eax, ecx ; old variable's address (after '=')
  6316                              <1> 
  6317 00009F74 89F1                <1> 	mov	ecx, esi 
  6318 00009F76 29F9                <1> 	sub	ecx, edi ; count of bytes to move forward
  6319                              <1> 
  6320                              <1> 	; 13/04/2016
  6321 00009F78 C60200              <1> 	mov	byte [edx], 0
  6322 00009F7B 89D7                <1> 	mov	edi, edx
  6323 00009F7D 29F2                <1> 	sub	edx, esi ; difference (additional byte count)
  6324 00009F7F 4F                  <1> 	dec	edi ; the last zero address (first byte of the 00)
  6325 00009F80 89FE                <1> 	mov	esi, edi
  6326 00009F82 29D6                <1> 	sub	esi, edx ; - displacement
  6327                              <1> 
  6328 00009F84 FA                  <1> 	cli	; disable interrupts
  6329 00009F85 FD                  <1> 	std	; backward
  6330                              <1> 
  6331 00009F86 F3A4                <1> 	rep	movsb ; move ECX bytes from DS:ESI to ES:EDI
  6332                              <1> 
  6333 00009F88 FC                  <1> 	cld	; forward (default)
  6334 00009F89 FB                  <1> 	sti	; enable interrupts
  6335                              <1> 
  6336 00009F8A 89C7                <1> 	mov	edi, eax
  6337 00009F8C 59                  <1> 	pop	ecx ; ***** ; byte count (after '=')
  6338 00009F8D 89CA                <1> 	mov	edx, ecx
  6339 00009F8F 89DE                <1> 	mov	esi, ebx ; ASCIIZ string address (after '=')
  6340 00009F91 89FB                <1> 	mov	ebx, edi
  6341                              <1> 
  6342 00009F93 F3A4                <1> 	rep	movsb
  6343                              <1> 
  6344 00009F95 880F                <1> 	mov	[edi], cl ; 0 ; end of variable
  6345                              <1> 
  6346 00009F97 0FB605[EC880100]    <1> 	movzx	eax, byte [env_var_length]
  6347 00009F9E 01C2                <1> 	add	edx, eax ; variable length (total)
  6348 00009FA0 F7D8                <1> 	neg	eax
  6349 00009FA2 01D8                <1> 	add	eax, ebx ; start address of the variable
  6350 00009FA4 F8                  <1> 	clc	; 13/04/2016
  6351 00009FA5 E9A7FEFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  6352                              <1> 
  6353                              <1> set_env_change_variable_calc9:
  6354                              <1> 	; 11/04/2016
  6355 00009FAA 21D2                <1> 	and	edx, edx ; is empty ?
  6356 00009FAC 753B                <1> 	jnz	short set_env_change_variable_calc15
  6357                              <1> 
  6358 00009FAE 0FB6DC              <1> 	movzx	ebx, ah
  6359 00009FB1 F7DB                <1> 	neg	ebx
  6360 00009FB3 01FB                <1> 	add	ebx, edi
  6361                              <1> 
  6362                              <1> 	; EBX = Start address of the variable (in env page)
  6363                              <1> 	; EDX = Variable length = 0
  6364                              <1> 
  6365 00009FB5 89FE                <1> 	mov	esi, edi
  6366                              <1> 
  6367                              <1> set_env_change_variable_calc10:
  6368 00009FB7 AC                  <1> 	lodsb
  6369 00009FB8 08C0                <1> 	or	al, al
  6370 00009FBA 75FB                <1> 	jnz	short set_env_change_variable_calc10
  6371                              <1> 
  6372 00009FBC B9FF310900          <1> 	mov	ecx, Env_Page + Env_Page_Size - 1
  6373                              <1> 
  6374 00009FC1 39CE                <1> 	cmp	esi, ecx ; +511 (+4095)
  6375 00009FC3 7604                <1> 	jna	short set_env_change_variable_calc11
  6376                              <1> 
  6377 00009FC5 89CE                <1> 	mov	esi, ecx
  6378 00009FC7 8806                <1> 	mov	[esi], al ; 0
  6379                              <1> 
  6380                              <1> set_env_change_variable_calc11:
  6381 00009FC9 89DF                <1> 	mov	edi, ebx ; old variable's start address
  6382                              <1> 
  6383                              <1> set_env_change_variable_calc12:
  6384 00009FCB AC                  <1> 	lodsb
  6385 00009FCC AA                  <1> 	stosb
  6386 00009FCD 20C0                <1> 	and	al, al
  6387 00009FCF 75FA                <1> 	jnz	short set_env_change_variable_calc12
  6388 00009FD1 39CE                <1> 	cmp	esi, ecx
  6389 00009FD3 7706                <1> 	ja	short set_env_change_variable_calc13
  6390 00009FD5 AC                  <1> 	lodsb
  6391 00009FD6 AA                  <1> 	stosb
  6392 00009FD7 20C0                <1> 	and	al, al
  6393 00009FD9 75F0                <1> 	jnz	short set_env_change_variable_calc12
  6394                              <1> 
  6395                              <1> set_env_change_variable_calc13:
  6396 00009FDB 29F9                <1> 	sub	ecx, edi
  6397 00009FDD 7203                <1> 	jb	short set_env_change_variable_calc14
  6398 00009FDF 41                  <1> 	inc	ecx ; 1-512 (1-4096)
  6399 00009FE0 F3AA                <1> 	rep	stosb ; al = 0
  6400                              <1> 
  6401                              <1> set_env_change_variable_calc14:
  6402 00009FE2 29C0                <1> 	sub	eax, eax ; Start address of the variable
  6403                              <1> 	; EAX = 0 -> Variable is removed
  6404                              <1> 	; EDX = Variable length = 0
  6405                              <1> 
  6406 00009FE4 E968FEFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  6407                              <1> 
  6408                              <1> set_env_change_variable_calc15:
  6409 00009FE9 52                  <1> 	push	edx ; *****
  6410 00009FEA F7DA                <1> 	neg	edx
  6411 00009FEC 01CA                <1> 	add	edx, ecx ; difference (the old string is longer)
  6412 00009FEE 89F3                <1> 	mov 	ebx, esi
  6413 00009FF0 89FE                <1> 	mov	esi, edi
  6414                              <1> 
  6415                              <1> set_env_change_variable_calc16:
  6416 00009FF2 AC                  <1> 	lodsb
  6417 00009FF3 20C0                <1> 	and	al, al
  6418 00009FF5 75FB                <1> 	jnz	short set_env_change_variable_calc16
  6419                              <1> 
  6420 00009FF7 B900320900          <1> 	mov	ecx, Env_Page + Env_Page_Size
  6421                              <1> 
  6422 00009FFC 39CE                <1> 	cmp	esi, ecx ; +512 (+4096)
  6423 00009FFE 7605                <1> 	jna	short set_env_change_variable_calc17
  6424                              <1> 
  6425 0000A000 89CE                <1> 	mov	esi, ecx
  6426 0000A002 8846FF              <1> 	mov	[esi-1], al ; 0
  6427                              <1> 
  6428                              <1> set_env_change_variable_calc17:
  6429 0000A005 89F9                <1> 	mov	ecx, edi  ; current (old) variable's address
  6430 0000A007 89F7                <1> 	mov	edi, esi  ; next variable's address
  6431                              <1> 
  6432 0000A009 AC                  <1> 	lodsb
  6433 0000A00A 08C0                <1> 	or	al, al
  6434 0000A00C 741D                <1> 	jz	short set_env_change_variable_calc20
  6435                              <1> 
  6436                              <1> set_env_change_variable_calc18:
  6437 0000A00E AC                  <1> 	lodsb
  6438 0000A00F 20C0                <1> 	and	al, al
  6439 0000A011 75FB                <1> 	jnz	short set_env_change_variable_calc18
  6440                              <1> 
  6441 0000A013 81FE00320900        <1> 	cmp	esi, Env_Page + Env_Page_Size
  6442 0000A019 720B                <1> 	jb	short set_env_change_variable_calc19
  6443 0000A01B 740E                <1> 	je	short set_env_change_variable_calc20
  6444                              <1> 
  6445 0000A01D BEFF310900          <1> 	mov	esi, Env_Page + Env_Page_Size - 1
  6446 0000A022 8806                <1> 	mov	[esi], al ; 0
  6447 0000A024 EB06                <1> 	jmp	short set_env_change_variable_calc21
  6448                              <1> 
  6449                              <1> set_env_change_variable_calc19:
  6450 0000A026 AC                  <1> 	lodsb
  6451 0000A027 08C0                <1> 	or	al, al
  6452 0000A029 75E3                <1> 	jnz	short set_env_change_variable_calc18
  6453                              <1> 
  6454                              <1> set_env_change_variable_calc20:
  6455 0000A02B 4E                  <1> 	dec	esi ; address of the second (last) 0 of the 00
  6456                              <1> 
  6457                              <1> set_env_change_variable_calc21:
  6458                              <1> 	; edx = difference (byte count)
  6459                              <1> 
  6460 0000A02C 89C8                <1> 	mov	eax, ecx ; old variable's address (after '=')
  6461                              <1> 
  6462 0000A02E 89F1                <1> 	mov	ecx, esi 
  6463 0000A030 29F9                <1> 	sub	ecx, edi ; count of bytes to move backward
  6464                              <1> 
  6465 0000A032 89FE                <1> 	mov	esi, edi ; next variable's address
  6466 0000A034 29D7                <1> 	sub	edi, edx ; (displacement)
  6467                              <1> 
  6468 0000A036 F3A4                <1> 	rep	movsb
  6469                              <1> 
  6470 0000A038 880F                <1> 	mov	[edi], cl ; 0 ; 00 ; end of environment variables
  6471                              <1> 
  6472 0000A03A 89C7                <1> 	mov	edi, eax
  6473 0000A03C 5A                  <1> 	pop	edx ; ***** ; byte count (after '=')
  6474 0000A03D 89D1                <1> 	mov	ecx, edx
  6475 0000A03F 89DE                <1> 	mov	esi, ebx ; ASCIIZ string address (after '=')
  6476 0000A041 89FB                <1> 	mov	ebx, edi
  6477                              <1> 
  6478 0000A043 F3A4                <1> 	rep	movsb
  6479                              <1> 
  6480 0000A045 880F                <1> 	mov	[edi], cl ; 0 ; end of variable
  6481                              <1> 
  6482 0000A047 0FB605[EC880100]    <1> 	movzx	eax, byte [env_var_length]
  6483 0000A04E 01C2                <1> 	add	edx, eax ; variable length (total)
  6484 0000A050 F7D8                <1> 	neg	eax
  6485 0000A052 01D8                <1> 	add	eax, ebx ; start address of the variable
  6486 0000A054 F8                  <1> 	clc	; 13/04/2016
  6487 0000A055 E9F7FDFFFF          <1>         jmp     set_env_string_allocate_envb_retn ; OK !
  6488                              <1> 
  6489                              <1> mainprog_startup_configuration:
  6490                              <1> 	; 25/07/2022 - TRDOS 386 Kernel v2.0.5
  6491                              <1> 	; 22/11/2017
  6492                              <1> 	; 06/05/2016
  6493                              <1> 	; 14/04/2016 (TRDOS 386 = TRDOS v2.0)
  6494                              <1> 	; 17/09/2011 (TRDOS v1, MAINPROG.ASM)
  6495                              <1> 	;
  6496                              <1> loc_load_mainprog_cfg_file:
  6497 0000A05A BE[E9340100]        <1> 	mov	esi, MainProgCfgFile
  6498 0000A05F 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
  6499 0000A063 E802EBFFFF          <1> 	call	find_first_file
  6500 0000A068 7256                <1> 	jc	short loc_load_mainprog_cfg_exit
  6501                              <1> 
  6502                              <1> 	;or	eax, eax
  6503                              <1> 	;jz	short loc_load_mainprog_cfg_exit
  6504                              <1> 
  6505                              <1> loc_start_mainprog_configuration:
  6506                              <1> 	; ESI = FindFile_DirEntry Location
  6507                              <1> 	; EAX = File Size
  6508                              <1> 
  6509 0000A06A A3[707D0100]        <1> 	mov	[MainProgCfg_FileSize], eax
  6510                              <1> 
  6511 0000A06F 668B5614            <1> 	mov	dx, [esi+DirEntry_FstClusHI]
  6512 0000A073 C1E210              <1> 	shl	edx, 16
  6513 0000A076 668B561A            <1> 	mov	dx, [esi+DirEntry_FstClusLO]
  6514 0000A07A 8915[A0880100]      <1> 	mov	[csftdf_sf_cluster], edx
  6515                              <1> 
  6516 0000A080 89C1                <1> 	mov	ecx, eax
  6517 0000A082 29C0                <1> 	sub	eax, eax
  6518                              <1> 
  6519                              <1> 	; TRDOS 386 (TRDOS v2.0)
  6520                              <1> 	; Allocate contiguous memory block for loading the file
  6521                              <1> 
  6522                              <1> 	; eax = 0 (Allocate memory from the beginning)
  6523                              <1> 	; ecx = File (Allocation) size in bytes
  6524                              <1> 
  6525 0000A084 E86ABCFFFF          <1> 	call	allocate_memory_block
  6526 0000A089 7235                <1> 	jc	short loc_load_mainprog_cfg_exit
  6527                              <1> 
  6528 0000A08B A3[98880100]        <1> 	mov	[csftdf_sf_mem_addr], eax ; loading address
  6529 0000A090 890D[9C880100]      <1> 	mov	[csftdf_sf_mem_bsize], ecx ; block size
  6530                              <1> 
  6531 0000A096 31DB                <1> 	xor	ebx, ebx
  6532                              <1> 	;mov	[csftdf_sf_rbytes], ebx ; 0, reset
  6533                              <1> 
  6534 0000A098 8A3D[827D0100]      <1> 	mov	bh, [Current_Drv] ; [FindFile_Drv]
  6535 0000A09E BE00010900          <1> 	mov	esi, Logical_DOSDisks
  6536 0000A0A3 01DE                <1> 	add	esi, ebx
  6537                              <1> 
  6538 0000A0A5 8B1D[98880100]      <1> 	mov	ebx, [csftdf_sf_mem_addr] ; memory block address
  6539                              <1> 
  6540 0000A0AB 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  6541 0000A0AF 7710                <1>         ja	short loc_mcfg_load_fat_file
  6542                              <1> 
  6543 0000A0B1 C705[A8880100]0000- <1> 	mov	dword [csftdf_r_size], 65536
  6543 0000A0B9 0100                <1>
  6544 0000A0BB E99A010000          <1>         jmp     loc_mcfg_load_fs_file
  6545                              <1> 
  6546                              <1> loc_load_mainprog_cfg_exit:
  6547 0000A0C0 C3                  <1> 	retn
  6548                              <1> 
  6549                              <1> loc_mcfg_load_fat_file:
  6550 0000A0C1 0FB74611            <1> 	movzx	eax, word [esi+LD_BPB+BytesPerSec]
  6551 0000A0C5 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  6552 0000A0C9 F7E1                <1> 	mul	ecx
  6553 0000A0CB A3[A8880100]        <1> 	mov	[csftdf_r_size], eax
  6554                              <1> 
  6555                              <1> loc_mcfg_load_fat_file_next:
  6556 0000A0D0 E81D010000          <1> 	call	mcfg_read_fat_file_sectors
  6557 0000A0D5 7259                <1>         jc	short mcfg_deallocate_mem ; 25/07/2022
  6558                              <1> 
  6559 0000A0D7 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  6560 0000A0D9 74F5                <1> 	jz	short loc_mcfg_load_fat_file_next
  6561                              <1> 
  6562                              <1> loc_mcfg_load_fat_file_ok:
  6563                              <1> 	; 06/05/2016
  6564 0000A0DB C705[3C890100]-     <1> 	mov	dword [mainprog_return_addr], loc_mcfg_ci_return_addr 
  6564 0000A0E1 [ADA10000]          <1>
  6565                              <1> 	;
  6566 0000A0E5 8B35[98880100]      <1> 	mov	esi, [csftdf_sf_mem_addr]
  6567 0000A0EB 8935[747D0100]      <1> 	mov	[MainProgCfg_LineOffset], esi
  6568                              <1> 
  6569 0000A0F1 A1[707D0100]        <1> 	mov	eax, [MainProgCfg_FileSize]
  6570 0000A0F6 89C2                <1> 	mov	edx, eax
  6571 0000A0F8 01F2                <1> 	add	edx, esi
  6572                              <1> 
  6573                              <1> loc_mcfg_process_next_line_check:
  6574 0000A0FA 89C1                <1> 	mov	ecx, eax
  6575                              <1> 
  6576 0000A0FC 803E2A              <1> 	cmp	byte [esi], "*" ; Remark sign
  6577 0000A0FF 7503                <1> 	jne	short loc_mcfg_process_next_line
  6578 0000A101 46                  <1> 	inc	esi
  6579 0000A102 EB16                <1> 	jmp	short loc_move_mainprog_cfg_nl1
  6580                              <1> 
  6581                              <1> loc_mcfg_process_next_line:
  6582 0000A104 83F94F              <1> 	cmp	ecx, 79
  6583 0000A107 7604                <1> 	jna	short loc_start_mainprog_cfg_process
  6584                              <1> 
  6585                              <1> 	;mov	ecx, 79
  6586                              <1> 	; 25/07/2022
  6587 0000A109 29C9                <1> 	sub	ecx, ecx
  6588 0000A10B B14F                <1> 	mov	cl, 79
  6589                              <1> 
  6590                              <1> loc_start_mainprog_cfg_process:
  6591 0000A10D BF[327E0100]        <1> 	mov	edi, CommandBuffer
  6592                              <1> 
  6593                              <1> loc_move_mainprog_cfg_line:
  6594 0000A112 AC                  <1> 	lodsb
  6595 0000A113 3C20                <1> 	cmp	al, 20h
  6596 0000A115 720C                <1> 	jb	short loc_move_mainprog_cfg_nl2
  6597 0000A117 AA                  <1> 	stosb
  6598 0000A118 E2F8                <1> 	loop	loc_move_mainprog_cfg_line
  6599                              <1> 
  6600                              <1> loc_move_mainprog_cfg_nl1:
  6601 0000A11A 39D6                <1> 	cmp	esi, edx ; + configuration file size
  6602 0000A11C 7322                <1> 	jnb	short loc_end_of_mainprog_cfg_line
  6603 0000A11E AC                  <1> 	lodsb
  6604 0000A11F 3C20                <1> 	cmp	al, 20h
  6605 0000A121 73F7                <1> 	jnb	short loc_move_mainprog_cfg_nl1
  6606                              <1> 
  6607                              <1> loc_move_mainprog_cfg_nl2:
  6608 0000A123 39D6                <1> 	cmp	esi, edx
  6609 0000A125 7319                <1> 	jnb	short loc_end_of_mainprog_cfg_line
  6610 0000A127 8A06                <1> 	mov	al, [esi]
  6611 0000A129 3C20                <1> 	cmp	al, 20h
  6612 0000A12B 7713                <1>  	ja	short loc_end_of_mainprog_cfg_line
  6613 0000A12D 46                  <1> 	inc	esi
  6614 0000A12E EBF3                <1> 	jmp	short loc_move_mainprog_cfg_nl2	
  6615                              <1> 
  6616                              <1> 	; 25/07/2022
  6617                              <1> mcfg_deallocate_mem:
  6618 0000A130 A1[98880100]        <1> 	mov	eax, [csftdf_sf_mem_addr] ; start address
  6619 0000A135 8B0D[9C880100]      <1> 	mov	ecx, [csftdf_sf_mem_bsize] ; block size
  6620                              <1> 	;call	deallocate_memory_block
  6621                              <1> 	;retn
  6622 0000A13B E9CDBDFFFF          <1> 	jmp	deallocate_memory_block
  6623                              <1> 
  6624                              <1> loc_end_of_mainprog_cfg_line:
  6625 0000A140 C60700              <1> 	mov	byte [edi], 0
  6626                              <1> 
  6627 0000A143 8935[747D0100]      <1> 	mov	[MainProgCfg_LineOffset], esi
  6628                              <1> 
  6629                              <1> 	; 22/11/2017
  6630 0000A149 BE[3A7E0100]        <1> 	mov	esi, CommandBuffer + 8
  6631 0000A14E 29FE                <1> 	sub	esi, edi
  6632 0000A150 7606                <1> 	jna	short loc_move_mainprog_cfg_command
  6633 0000A152 30C0                <1> 	xor	al, al
  6634                              <1> loc_mainprog_cfg_clear_chrs:
  6635 0000A154 AA                  <1> 	stosb
  6636 0000A155 4E                  <1> 	dec	esi
  6637 0000A156 75FC                <1> 	jnz	short loc_mainprog_cfg_clear_chrs
  6638                              <1> 
  6639                              <1> loc_move_mainprog_cfg_command:
  6640 0000A158 BE[327E0100]        <1> 	mov	esi, CommandBuffer
  6641 0000A15D 89F7                <1> 	mov	edi, esi
  6642 0000A15F 31DB                <1> 	xor	ebx, ebx
  6643                              <1> 	;xor	ecx, ecx
  6644 0000A161 30C9                <1> 	xor	cl, cl
  6645                              <1> 
  6646                              <1> loc_move_mcfg_first_cmd_char:
  6647 0000A163 8A041E              <1> 	mov	al, [esi+ebx]
  6648 0000A166 FEC3                <1> 	inc	bl
  6649 0000A168 3C20                <1> 	cmp	al, 20h
  6650 0000A16A 7712                <1> 	ja	short loc_move_mcfg_cmd_capitalizing
  6651 0000A16C 7237                <1> 	jb	short loc_move_mcfg_cmd_arguments_ok
  6652 0000A16E 80FB4F              <1> 	cmp	bl, 79
  6653 0000A171 72F0                <1> 	jb	short loc_move_mcfg_first_cmd_char
  6654 0000A173 EB30                <1> 	jmp	short loc_move_mcfg_cmd_arguments_ok
  6655                              <1> 
  6656                              <1> loc_move_mcfg_next_cmd_char:
  6657 0000A175 8A041E              <1> 	mov	al, [esi+ebx]
  6658 0000A178 FEC3                <1> 	inc	bl
  6659 0000A17A 3C20                <1> 	cmp	al, 20h
  6660 0000A17C 7614                <1> 	jna	short loc_move_mcfg_cmd_ok
  6661                              <1> 
  6662                              <1> loc_move_mcfg_cmd_capitalizing:
  6663 0000A17E 3C61                <1> 	cmp	al, 61h ; 'a'
  6664 0000A180 7206                <1> 	jb	short loc_move_mcfg_cmd_caps_ok
  6665 0000A182 3C7A                <1> 	cmp	al, 7Ah ; 'z'
  6666 0000A184 7702                <1> 	ja	short loc_move_mcfg_cmd_caps_ok
  6667 0000A186 24DF                <1> 	and	al, 0DFh ; sub	al, 'a'-'A'
  6668                              <1> 
  6669                              <1> loc_move_mcfg_cmd_caps_ok:
  6670 0000A188 AA                  <1> 	stosb
  6671 0000A189 FEC1                <1> 	inc	cl
  6672 0000A18B 80FB4F              <1> 	cmp	bl, 79
  6673 0000A18E 72E5                <1> 	jb	short loc_move_mcfg_next_cmd_char
  6674 0000A190 EB13                <1> 	jmp	short loc_move_mcfg_cmd_arguments_ok
  6675                              <1> 
  6676                              <1> loc_move_mcfg_cmd_ok:
  6677 0000A192 30C0                <1> 	xor	al, al ; 0
  6678                              <1> 
  6679                              <1> loc_move_mcfg_cmd_arguments:
  6680 0000A194 8807                <1> 	mov	[edi], al
  6681 0000A196 47                  <1> 	inc	edi
  6682 0000A197 80FB4F              <1> 	cmp	bl, 79
  6683 0000A19A 7309                <1> 	jnb	short loc_move_mcfg_cmd_arguments_ok
  6684 0000A19C 8A041E              <1> 	mov	al, [esi+ebx]
  6685 0000A19F FEC3                <1> 	inc	bl
  6686 0000A1A1 3C20                <1> 	cmp	al, 20h
  6687 0000A1A3 73EF                <1> 	jnb	short loc_move_mcfg_cmd_arguments
  6688                              <1> 
  6689                              <1> loc_move_mcfg_cmd_arguments_ok:
  6690 0000A1A5 C60700              <1> 	mov	byte [edi], 0
  6691                              <1> 
  6692                              <1> loc_mcfg_process_cmd_interpreter:
  6693 0000A1A8 E8BCE0FFFF          <1> 	call    command_interpreter
  6694                              <1> 
  6695                              <1> loc_mcfg_ci_return_addr:
  6696 0000A1AD A1[707D0100]        <1> 	mov	eax, [MainProgCfg_FileSize]
  6697 0000A1B2 89C2                <1> 	mov	edx, eax
  6698 0000A1B4 8B35[747D0100]      <1> 	mov	esi, [MainProgCfg_LineOffset]
  6699 0000A1BA 01F2                <1> 	add	edx, esi
  6700 0000A1BC 0305[98880100]      <1> 	add	eax, [csftdf_sf_mem_addr]
  6701 0000A1C2 29F0                <1> 	sub	eax, esi
  6702 0000A1C4 0F8730FFFFFF        <1>         ja      loc_mcfg_process_next_line_check
  6703                              <1> 
  6704 0000A1CA E861FFFFFF          <1> 	call	mcfg_deallocate_mem
  6705                              <1> 
  6706 0000A1CF B94F000000          <1>  	mov	ecx, 79 ; 80 ?
  6707 0000A1D4 BF[327E0100]        <1> 	mov	edi, CommandBuffer
  6708 0000A1D9 30C0                <1> 	xor	al, al
  6709 0000A1DB F3AA                <1> 	rep	stosb
  6710                              <1> 
  6711                              <1> 	; 06/05/2016
  6712 0000A1DD BE[273F0100]        <1> 	mov	esi, nextline
  6713 0000A1E2 E883CBFFFF          <1> 	call	print_msg
  6714 0000A1E7 E9CED7FFFF          <1> 	jmp	dos_prompt
  6715                              <1> 
  6716                              <1> mcfg_read_file_sectors:
  6717                              <1> 	; 14/04/2016
  6718 0000A1EC 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  6719 0000A1F0 7668                <1>         jna	short mcfg_read_fs_file_sectors
  6720                              <1> 
  6721                              <1> mcfg_read_fat_file_sectors:
  6722                              <1> 	; return:
  6723                              <1> 	;   CF = 0 & EDX > 0 -> END OF FILE
  6724                              <1> 	;   CF = 0 & EDX = 0 -> not EOF
  6725                              <1> 	;   CF = 1 -> read error (error code in AL)
  6726                              <1> 
  6727                              <1> mcfg_read_fat_file_secs_0:
  6728 0000A1F2 8B15[707D0100]      <1> 	mov	edx, [MainProgCfg_FileSize]
  6729 0000A1F8 2B15[B0880100]      <1> 	sub	edx, [csftdf_sf_rbytes]
  6730 0000A1FE 3B15[A8880100]      <1> 	cmp	edx, [csftdf_r_size]
  6731 0000A204 7306                <1> 	jnb	short mcfg_read_fat_file_secs_1
  6732 0000A206 8915[A8880100]      <1> 	mov	[csftdf_r_size], edx
  6733                              <1> 
  6734                              <1> mcfg_read_fat_file_secs_1:
  6735 0000A20C A1[A8880100]        <1> 	mov	eax, [csftdf_r_size]
  6736 0000A211 29D2                <1> 	sub	edx, edx
  6737 0000A213 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec]
  6738 0000A217 01C8                <1> 	add	eax, ecx
  6739 0000A219 48                  <1> 	dec	eax
  6740 0000A21A F7F1                <1> 	div	ecx
  6741 0000A21C 89C1                <1> 	mov	ecx, eax ; sector count
  6742 0000A21E A1[A0880100]        <1> 	mov	eax, [csftdf_sf_cluster]
  6743                              <1> 
  6744                              <1> 	; EBX = memory block address (current)
  6745                              <1> 
  6746 0000A223 E8F8220000          <1> 	call	read_fat_file_sectors
  6747 0000A228 7230                <1> 	jc	short mcfg_read_fat_file_secs_3
  6748                              <1> 
  6749                              <1> 	; EBX = next memory address
  6750                              <1> 
  6751 0000A22A A1[B0880100]        <1> 	mov	eax, [csftdf_sf_rbytes]
  6752 0000A22F 0305[A8880100]      <1> 	add	eax, [csftdf_r_size]
  6753 0000A235 8B15[707D0100]      <1> 	mov	edx, [MainProgCfg_FileSize]
  6754 0000A23B 39D0                <1> 	cmp	eax, edx
  6755 0000A23D 731B                <1> 	jnb	short mcfg_read_fat_file_secs_3 ; edx > 0
  6756 0000A23F A3[B0880100]        <1> 	mov	[csftdf_sf_rbytes], eax
  6757                              <1> 
  6758 0000A244 53                  <1> 	push	ebx ; *
  6759                              <1> 	; get next cluster (csftdf_r_size! bytes)
  6760 0000A245 A1[A0880100]        <1> 	mov	eax, [csftdf_sf_cluster]
  6761 0000A24A E8D1200000          <1> 	call	get_next_cluster
  6762 0000A24F 5B                  <1> 	pop	ebx ; *
  6763 0000A250 7301                <1> 	jnc	short mcfg_read_fat_file_secs_2
  6764                              <1> 
  6765                              <1> 	;mov	eax, 17; Read error !
  6766 0000A252 C3                  <1> 	retn
  6767                              <1> 
  6768                              <1> mcfg_read_fat_file_secs_2:
  6769 0000A253 29D2                <1> 	sub	edx, edx ; 0
  6770 0000A255 A3[A0880100]        <1> 	mov	[csftdf_sf_cluster], eax ; next cluster
  6771                              <1> 
  6772                              <1> ; 25/07/2022 - TRDOS 386 Kernel v2.0.5
  6773                              <1> 
  6774                              <1> mcfg_read_fat_file_secs_3:
  6775                              <1> 	;retn
  6776                              <1> 
  6777                              <1> mcfg_read_fs_file_sectors:
  6778                              <1> 	;retn
  6779                              <1> 
  6780                              <1> loc_mcfg_load_fs_file:
  6781 0000A25A C3                  <1> 	retn
  6782                              <1> 
  6783                              <1> load_and_execute_file:
  6784                              <1> 	; 03/09/2024 - TRDOS 386 Kernel v2.0.9
  6785                              <1> 	; 30/08/2023 - TRDOS 386 Kernel v2.0.6
  6786                              <1> 	; 25/07/2022 - TRDOS 386 Kernel v2.0.5
  6787                              <1> 	; 04/01/2017
  6788                              <1> 	; 06/05/2016 - 07/05/2016 - 11/05/2016
  6789                              <1> 	; 23/04/2016 - 24/04/2016
  6790                              <1> 	; 22/04/2016 (TRDOS 386 = TRDOS v2.0)
  6791                              <1> 	; 05/11/2011 
  6792                              <1> 	; (TRDOS v1, CMDINTR.ASM, 'cmp_cmd_run', 'cmp_cmd_external')
  6793                              <1> 	; ('loc_run_check_filename')
  6794                              <1> 	; 29/08/2011
  6795                              <1> 	; 10/09/2011
  6796                              <1> 	; INPUT->
  6797                              <1> 	;	ESI = Path Name address (CommandBuffer address)
  6798                              <1> 	; OUTPUT ->
  6799                              <1> 	;	none (error message will be shown if an error will occur)
  6800                              <1> 	;
  6801                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI, EBP will be changed) 
  6802                              <1> 	;
  6803                              <1> loc_run_check_filename:
  6804 0000A25B 803E20              <1> 	cmp	byte [esi], 20h
  6805                              <1> 	;jb	loc_cmd_failed
  6806                              <1> 	; 25/07/2022
  6807 0000A25E 7237                <1> 	jb	short loc_run_ppn_failed
  6808 0000A260 7703                <1> 	ja	short loc_run_check_filename_ok
  6809 0000A262 46                  <1> 	inc	esi
  6810 0000A263 EBF6                <1> 	jmp	short loc_run_check_filename
  6811                              <1> 
  6812                              <1> loc_run_check_filename_ok:
  6813 0000A265 C605[E37D0100]00    <1> 	mov	byte [CmdArgStart], 0 ; reset
  6814 0000A26C 56                  <1> 	push	esi ; *
  6815                              <1> loc_run_get_first_arg_pos:
  6816 0000A26D 46                  <1> 	inc	esi
  6817 0000A26E 8A06                <1> 	mov	al, [esi]
  6818 0000A270 3C20                <1> 	cmp	al, 20h
  6819 0000A272 77F9                <1> 	ja	short loc_run_get_first_arg_pos
  6820 0000A274 C60600              <1> 	mov	byte [esi], 0
  6821                              <1> loc_run_get_external_arg_pos:
  6822                              <1> 	; 11/05/2016
  6823 0000A277 46                  <1> 	inc	esi
  6824 0000A278 8A06                <1> 	mov	al, [esi]
  6825 0000A27A 3C20                <1> 	cmp	al, 20h
  6826 0000A27C 760C                <1> 	jna	short loc_run_parse_path_name
  6827 0000A27E 89F0                <1> 	mov	eax, esi
  6828 0000A280 2D[327E0100]        <1> 	sub	eax, CommandBuffer
  6829 0000A285 A2[E37D0100]        <1> 	mov	byte [CmdArgStart], al
  6830                              <1> loc_run_parse_path_name:
  6831 0000A28A 5E                  <1> 	pop	esi ; *
  6832 0000A28B BF[22860100]        <1> 	mov	edi, FindFile_Drv
  6833 0000A290 E885090000          <1> 	call	parse_path_name
  6834                              <1> 	;jc	loc_cmd_failed
  6835                              <1> 	; 25/07/2022
  6836 0000A295 7305                <1> 	jnc	short loc_run_check_filename_exists
  6837                              <1> loc_run_ppn_failed:
  6838 0000A297 E9A8E3FFFF          <1> 	jmp	loc_cmd_failed
  6839                              <1> 
  6840                              <1> loc_run_check_filename_exists:
  6841 0000A29C BE[64860100]        <1> 	mov	esi, FindFile_Name
  6842 0000A2A1 803E20              <1> 	cmp	byte [esi], 20h
  6843                              <1> 	;jna	loc_cmd_failed
  6844                              <1> 	; 25/07/2022
  6845 0000A2A4 76F1                <1> 	jna	short loc_run_ppn_failed
  6846                              <1> 
  6847                              <1> loc_run_check_exe_filename_ext:
  6848 0000A2A6 E878020000          <1> 	call	check_prg_filename_ext
  6849                              <1> 	;jc	loc_cmd_failed
  6850                              <1> 	; 25/07/2022
  6851 0000A2AB 72EA                <1> 	jc	short loc_run_ppn_failed
  6852                              <1> 
  6853                              <1> loc_run_check_exe_filename_ext_ok:
  6854 0000A2AD 66A3[3A890100]      <1> 	mov	word [EXE_ID], ax
  6855                              <1> 
  6856                              <1> loc_run_drv:
  6857 0000A2B3 C605[39890100]00    <1> 	mov	byte [Run_Manual_Path], 0
  6858 0000A2BA A1[7C7D0100]        <1> 	mov	eax, [Current_Dir_FCluster]
  6859 0000A2BF A3[34890100]        <1>         mov     [Run_CDirFC], eax
  6860                              <1> 	;
  6861 0000A2C4 8A35[827D0100]      <1> 	mov	dh, [Current_Drv]
  6862 0000A2CA 8835[DF840100]      <1> 	mov	[RUN_CDRV], dh
  6863                              <1> 
  6864 0000A2D0 8A15[22860100]      <1> 	mov	dl, [FindFile_Drv]
  6865 0000A2D6 38F2                <1> 	cmp	dl, dh
  6866 0000A2D8 7413                <1> 	je	short loc_run_change_directory
  6867                              <1> 
  6868 0000A2DA 8005[39890100]02    <1> 	add	byte [Run_Manual_Path], 2
  6869                              <1> 
  6870 0000A2E1 E897D5FFFF          <1> 	call	change_current_drive
  6871                              <1> 	;jc	loc_run_cmd_failed
  6872                              <1> 	; 25/07/2022
  6873 0000A2E6 7305                <1> 	jnc	short loc_run_change_directory
  6874 0000A2E8 E982E3FFFF          <1> 	jmp	loc_run_cmd_failed
  6875                              <1> 
  6876                              <1> loc_run_change_directory:
  6877 0000A2ED 803D[23860100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  6878 0000A2F4 7624                <1> 	jna	short loc_run_find_executable_file
  6879                              <1> 
  6880 0000A2F6 FE05[39890100]      <1> 	inc	byte [Run_Manual_Path]
  6881                              <1> 
  6882 0000A2FC FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  6883                              <1> 
  6884 0000A302 BE[23860100]        <1> 	mov	esi, FindFile_Directory
  6885 0000A307 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0
  6886 0000A309 E822030000          <1> 	call	change_current_directory
  6887                              <1> 	;jc	loc_run_cmd_failed
  6888                              <1> 	; 25/07/2022
  6889 0000A30E 7305                <1> 	jnc	short loc_run_change_prompt_dir_string
  6890 0000A310 E95AE3FFFF          <1> 	jmp	loc_run_cmd_failed
  6891                              <1> 
  6892                              <1> loc_run_change_prompt_dir_string:
  6893 0000A315 E83F020000          <1> 	call	change_prompt_dir_string
  6894                              <1> 
  6895                              <1> loc_run_find_executable_file:
  6896 0000A31A 66C705[38890100]00- <1> 	mov	word [Run_Auto_Path], 0
  6896 0000A322 00                  <1>
  6897                              <1> 
  6898                              <1> loc_run_find_executable_file_next:
  6899 0000A323 BE[64860100]        <1> 	mov	esi, FindFile_Name
  6900                              <1> loc_run_find_program_file_next:
  6901 0000A328 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
  6902 0000A32C E839E8FFFF          <1> 	call	find_first_file
  6903                              <1> 	; ESI = Directory Entry (FindFile_DirEntry) Location
  6904                              <1> 	; EDI = Directory Buffer Directory Entry Location
  6905                              <1> 	; EAX = File size
  6906                              <1> 	;jnc	loc_load_and_run_file
  6907                              <1> 	; 25/07/2022
  6908 0000A331 7205                <1> 	jc	short loc_run_program_file_not_found
  6909 0000A333 E94A010000          <1> 	jmp	loc_load_and_run_file
  6910                              <1> 
  6911                              <1> loc_run_program_file_not_found:	 
  6912 0000A338 3C02                <1> 	cmp	al, 2 ; file not found
  6913                              <1> 	;jne	loc_run_cmd_failed
  6914                              <1> 	; 25/07/2022
  6915 0000A33A 7405                <1> 	je	short loc_run_progr_file_chk_prg_ext
  6916 0000A33C E92EE3FFFF          <1> 	jmp	loc_run_cmd_failed
  6917                              <1> 
  6918                              <1> loc_run_progr_file_chk_prg_ext: ; 25/07/2022
  6919 0000A341 66A1[3A890100]      <1> 	mov	ax, word [EXE_ID]
  6920 0000A347 80FC2E              <1> 	cmp	ah, '.' ; File name has extension sign
  6921 0000A34A 7424                <1> 	je	short loc_run_check_auto_path
  6922                              <1> 
  6923 0000A34C 08C0                <1> 	or	al, al
  6924 0000A34E 7520                <1> 	jnz	short loc_run_check_auto_path
  6925                              <1> 
  6926 0000A350 80FC08              <1> 	cmp	ah, 8 ; count of file name chars
  6927 0000A353 771B                <1> 	ja	short loc_run_check_auto_path
  6928                              <1> 
  6929                              <1> loc_run_change_file_ext_to_prg:
  6930 0000A355 0FB6DC              <1> 	movzx	ebx, ah ; count of file name chars
  6931 0000A358 BE[64860100]        <1> 	mov	esi, FindFile_Name
  6932 0000A35D 01F3                <1> 	add	ebx, esi
  6933                              <1> 	; 07/05/2016
  6934 0000A35F C7032E505247        <1> 	mov	dword [ebx],  '.PRG'
  6935 0000A365 66C705[3A890100]50- <1> 	mov	word [EXE_ID], 'P.'
  6935 0000A36D 2E                  <1>
  6936 0000A36E EBB8                <1> 	jmp	short loc_run_find_program_file_next
  6937                              <1> 
  6938                              <1> loc_run_check_auto_path:
  6939                              <1> 	; NOTE: /// 07/05/2016 ///
  6940                              <1> 	; If the path is given, value of byte [Run_Manual_Path]
  6941                              <1> 	; will not be ZERO. If so, file searching by using
  6942                              <1> 	; Automatic Path (via 'PATH' environment variable)
  6943                              <1> 	; will not be applicable, because the program file
  6944                              <1> 	; is already/absolutely not found.
  6945                              <1> 
  6946 0000A370 A0[39890100]        <1> 	mov	al, [Run_Manual_Path]
  6947 0000A375 08C0                <1> 	or	al, al
  6948                              <1> 	;jnz	loc_cmd_failed
  6949                              <1> 	; 25/07/2022
  6950 0000A377 7528                <1> 	jnz	short loc_run_cap_failed
  6951                              <1> 
  6952                              <1> loc_run_check_auto_path_again:
  6953 0000A379 66833D[38890100]FF  <1> 	cmp	word [Run_Auto_Path], 0FFFFh
  6954                              <1> 		; 0FFFFh = Not a valid run path (in ENV block) 
  6955                              <1> 	;jnb	loc_cmd_failed
  6956                              <1> 	; 25/07/2022
  6957 0000A381 731E                <1> 	jnb	short loc_run_cap_failed
  6958                              <1> 	;xor	al, al
  6959 0000A383 BE[6F350100]        <1> 	mov	esi, Cmd_Path ; 'PATH'
  6960 0000A388 BF[827E0100]        <1> 	mov	edi, TextBuffer
  6961                              <1> 	; 03/09/2024 (bugfix)
  6962 0000A38D 66B90001            <1> 	mov	cx, 256 ; TextBuffer (maximum) length
  6963 0000A391 E869F9FFFF          <1> 	call	get_environment_string
  6964 0000A396 7310                <1> 	jnc	short loc_run_chk_filename_ext_again
  6965 0000A398 66C705[38890100]FF- <1> 	mov	word [Run_Auto_Path], 0FFFFh ; invalid
  6965 0000A3A0 FF                  <1>
  6966                              <1> loc_run_cap_failed: ; 25/07/2022
  6967                              <1> 	;jmp	loc_cmd_failed
  6968                              <1> 	; 30/08/2023
  6969 0000A3A1 B001                <1> 	mov	al, 1 ; (force jump to loc_cmd_failed at the end)
  6970 0000A3A3 E9C7E2FFFF          <1> 	jmp	loc_run_cmd_failed ; (restore cdir if it is needed)
  6971                              <1> 
  6972                              <1> loc_run_chk_filename_ext_again:
  6973 0000A3A8 89C1                <1> 	mov	ecx, eax ; string length (with zero tail)
  6974 0000A3AA 49                  <1> 	dec	ecx ; without zero tail
  6975 0000A3AB 66A1[3A890100]      <1> 	mov	ax, [EXE_ID]
  6976 0000A3B1 80FC2E              <1> 	cmp	ah, '.'
  6977 0000A3B4 740E                <1> 	je	short loc_run_chk_auto_path_pos
  6978                              <1> 
  6979                              <1> loc_run_change_file_ext_to_noext_again:
  6980 0000A3B6 0FB6DC              <1> 	movzx	ebx, ah
  6981 0000A3B9 BE[64860100]        <1> 	mov	esi, FindFile_Name
  6982 0000A3BE 01F3                <1> 	add 	ebx, esi
  6983 0000A3C0 29C0                <1> 	sub	eax, eax
  6984 0000A3C2 8903                <1> 	mov	[ebx], eax ; 0 ; erase extension (.PRG)
  6985                              <1> 
  6986                              <1> loc_run_chk_auto_path_pos:
  6987                              <1> 	;movzx	eax, word [Run_Auto_Path]
  6988 0000A3C4 66A1[38890100]      <1> 	mov	ax, [Run_Auto_Path]
  6989 0000A3CA 39C8                <1> 	cmp	eax, ecx ; ecx = string length (except zero tail)
  6990                              <1> 	;jnb	loc_cmd_failed
  6991                              <1>  	; 25/07/2022
  6992 0000A3CC 73D3                <1> 	jnb	short loc_run_cap_failed
  6993                              <1> 
  6994                              <1> 	;or	eax, eax
  6995 0000A3CE 6609C0              <1> 	or	ax, ax
  6996 0000A3D1 7502                <1> 	jnz	short loc_run_auto_path_pos_move
  6997 0000A3D3 B005                <1> 	mov	al, 5
  6998                              <1> 
  6999                              <1> loc_run_auto_path_pos_move:
  7000 0000A3D5 89FE                <1> 	mov	esi, edi ; offset TextBuffer
  7001 0000A3D7 01C6                <1> 	add	esi, eax
  7002                              <1> 
  7003                              <1> loc_run_auto_path_pos_space_loop:
  7004 0000A3D9 AC                  <1> 	lodsb
  7005 0000A3DA 3C20                <1> 	cmp	al, 20h
  7006 0000A3DC 74FB                <1> 	je	short loc_run_auto_path_pos_space_loop
  7007                              <1> 	;jb	loc_cmd_failed
  7008                              <1>  	; 25/07/2022
  7009 0000A3DE 72C1                <1> 	jb	short loc_run_cap_failed
  7010                              <1> 	;
  7011                              <1> loc_run_auto_path_pos_move_next_@:
  7012 0000A3E0 AA                  <1> 	stosb
  7013                              <1> loc_run_auto_path_pos_move_next:
  7014 0000A3E1 AC                  <1> 	lodsb
  7015 0000A3E2 3C3B                <1> 	cmp	al, ';'
  7016 0000A3E4 7411                <1> 	je	short loc_run_auto_path_pos_move_last_byte
  7017 0000A3E6 3C20                <1> 	cmp	al, 20h
  7018 0000A3E8 74F7                <1> 	je	short loc_run_auto_path_pos_move_next
  7019                              <1> 	;jb	short loc_byte_ptr_end_of_path
  7020                              <1> 	;stosb
  7021                              <1> 	;jmp	short loc_run_auto_path_pos_move_next
  7022                              <1> 	; 03/09/2024
  7023 0000A3EA 73F4                <1> 	jnb	short loc_run_auto_path_pos_move_next_@
  7024                              <1> 
  7025                              <1> loc_byte_ptr_end_of_path: 
  7026 0000A3EC 66C705[38890100]FF- <1> 	mov	word [Run_Auto_Path], 0FFFFh ; end of path
  7026 0000A3F4 FF                  <1>
  7027 0000A3F5 EB0D                <1> 	jmp	short loc_run_auto_path_move_ok
  7028                              <1> 
  7029                              <1> loc_run_auto_path_pos_move_last_byte:
  7030 0000A3F7 89F0                <1> 	mov	eax, esi
  7031 0000A3F9 2D[827E0100]        <1> 	sub	eax, TextBuffer
  7032 0000A3FE 66A3[38890100]      <1> 	mov	[Run_Auto_Path], ax ; next path position
  7033                              <1> 
  7034                              <1> loc_run_auto_path_move_ok:
  7035 0000A404 4F                  <1> 	dec	edi
  7036 0000A405 B02F                <1> 	mov	al, '/'
  7037 0000A407 3807                <1> 	cmp	[edi], al
  7038 0000A409 7403                <1> 	je	short loc_run_auto_path_move_file_name
  7039 0000A40B 47                  <1> 	inc	edi
  7040 0000A40C 8807                <1> 	mov	[edi], al
  7041                              <1> 
  7042                              <1> loc_run_auto_path_move_file_name:
  7043 0000A40E 47                  <1> 	inc	edi   
  7044 0000A40F BE[64860100]        <1> 	mov	esi, FindFile_Name
  7045                              <1> 
  7046                              <1> loc_run_auto_path_move_fn_loop:
  7047 0000A414 AC                  <1> 	lodsb
  7048 0000A415 AA                  <1> 	stosb
  7049 0000A416 08C0                <1> 	or	al, al
  7050 0000A418 75FA                <1> 	jnz	short loc_run_auto_path_move_fn_loop
  7051                              <1> 
  7052 0000A41A BE[827E0100]        <1> 	mov	esi, TextBuffer
  7053 0000A41F BF[22860100]        <1> 	mov	edi, FindFile_Drv
  7054 0000A424 E8F1070000          <1> 	call	parse_path_name
  7055                              <1> 	;jc	loc_run_cmd_failed
  7056                              <1> 	; 25/07/2022
  7057                              <1> 	;jnc	short loc_run_change_current_drive
  7058                              <1> 	;jmp	loc_run_cmd_failed
  7059 0000A429 7234                <1> 	jc	short loc_run_path_failed
  7060                              <1> 
  7061                              <1> loc_run_change_current_drive:
  7062 0000A42B 8A35[827D0100]      <1> 	mov	dh, [Current_Drv]
  7063 0000A431 8A15[22860100]      <1> 	mov	dl, [FindFile_Drv]
  7064 0000A437 38F2                <1> 	cmp	dl, dh
  7065 0000A439 7407                <1> 	je	short loc_run_change_directory_again
  7066                              <1> 
  7067 0000A43B E83DD4FFFF          <1> 	call	change_current_drive
  7068                              <1> 	;jc	loc_run_cmd_failed
  7069                              <1> 	; 25/07/2022
  7070                              <1> 	;jnc	short loc_run_change_directory_again
  7071                              <1> 	;jmp	loc_run_cmd_failed
  7072 0000A440 721D                <1> 	jc	short loc_run_path_failed
  7073                              <1> 
  7074                              <1> loc_run_change_directory_again:
  7075 0000A442 803D[23860100]20    <1> 	cmp	byte [FindFile_Directory], 20h
  7076 0000A449 761E                <1> 	jna	short loc_load_executable_cdir_chk_again
  7077                              <1> 
  7078 0000A44B FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  7079 0000A451 BE[23860100]        <1> 	mov	esi, FindFile_Directory
  7080 0000A456 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0
  7081 0000A458 E8D3010000          <1> 	call	change_current_directory
  7082                              <1> 	;jc	loc_run_cmd_failed
  7083                              <1> 	; 25/07/2022
  7084 0000A45D 7305                <1> 	jnc	short loc_run_chg_prompt_dir_str_again
  7085                              <1> 
  7086                              <1> loc_run_path_failed: ; 25/07/2022
  7087 0000A45F E90BE2FFFF          <1> 	jmp	loc_run_cmd_failed
  7088                              <1> 
  7089                              <1> loc_run_chg_prompt_dir_str_again:
  7090 0000A464 E8F0000000          <1> 	call	change_prompt_dir_string
  7091                              <1> 
  7092                              <1> loc_load_executable_cdir_chk_again:
  7093 0000A469 A1[7C7D0100]        <1> 	mov	eax, [Current_Dir_FCluster]
  7094 0000A46E 3B05[34890100]      <1> 	cmp	eax, [Run_CDirFC]
  7095                              <1> 	;jne	loc_run_find_executable_file_next
  7096                              <1> 	; 30/08/2023
  7097 0000A474 7405                <1> 	je	short jmp_loc_run_check_auto_path_again
  7098 0000A476 E9A8FEFFFF          <1> 	jmp	loc_run_find_executable_file_next
  7099                              <1> jmp_loc_run_check_auto_path_again:
  7100 0000A47B 30C0                <1> 	xor	al, al ; 0
  7101 0000A47D E9F7FEFFFF          <1> 	jmp	loc_run_check_auto_path_again
  7102                              <1> 
  7103                              <1> loc_load_and_run_file:
  7104                              <1> 	; 25/07/2022 - TRDOS 386 Kernel v2.0.5
  7105                              <1> 	; 13/11/2017
  7106                              <1> 	; 04/01/2017
  7107                              <1> 	; 23/04/2016
  7108 0000A482 BE[64860100]        <1> 	mov	esi, FindFile_Name
  7109 0000A487 BF[827E0100]        <1> 	mov	edi, TextBuffer
  7110                              <1> 
  7111                              <1>  	; 24/04/2016
  7112 0000A48C 31D2                <1> 	xor	edx, edx
  7113                              <1> 	;mov	word [argc], dx ; 0
  7114                              <1> 	; 25/07/2022
  7115 0000A48E 8915[70950100]      <1> 	mov	dword [argc], edx
  7116 0000A494 8915[A0940100]      <1> 	mov	dword [u.nread], edx ; 0
  7117                              <1> 
  7118                              <1> loc_load_and_run_file_1:
  7119 0000A49A AC                  <1> 	lodsb
  7120 0000A49B AA                  <1> 	stosb
  7121 0000A49C FF05[A0940100]      <1> 	inc	dword [u.nread]
  7122 0000A4A2 20C0                <1> 	and	al, al
  7123 0000A4A4 75F4                <1> 	jnz 	short loc_load_and_run_file_1
  7124                              <1> 
  7125 0000A4A6 A0[E37D0100]        <1> 	mov	al, [CmdArgStart]
  7126 0000A4AB 20C0                <1> 	and	al, al
  7127 0000A4AD 7442                <1> 	jz	short loc_load_and_run_file_7
  7128                              <1> 
  7129 0000A4AF 0FB6F0              <1> 	movzx	esi, al ; 11/05/2016
  7130                              <1> 	;mov	ecx, 80
  7131                              <1> 	; 25/07/2022
  7132 0000A4B2 31C9                <1> 	xor	ecx, ecx
  7133 0000A4B4 B150                <1> 	mov	cl, 80
  7134                              <1> 	;sub	ecx, esi
  7135 0000A4B6 28C1                <1> 	sub	cl, al
  7136 0000A4B8 81C6[327E0100]      <1> 	add	esi, CommandBuffer
  7137                              <1> 
  7138                              <1> 	;inc	word [argc] ; 11/05/2016
  7139                              <1> 	; 25/07/2022
  7140 0000A4BE FF05[70950100]      <1> 	inc	dword [argc]
  7141                              <1> 
  7142                              <1> loc_load_and_run_file_2:
  7143 0000A4C4 AC                  <1> 	lodsb
  7144 0000A4C5 3C20                <1> 	cmp	al, 20h
  7145 0000A4C7 7716                <1> 	ja	short loc_load_and_run_file_5
  7146 0000A4C9 721D                <1> 	jb	short loc_load_and_run_file_6
  7147                              <1> 
  7148                              <1> loc_load_and_run_file_3:
  7149 0000A4CB 803E20              <1> 	cmp	byte [esi], 20h
  7150 0000A4CE 7707                <1> 	ja	short loc_load_and_run_file_4
  7151 0000A4D0 7216                <1> 	jb	short loc_load_and_run_file_6
  7152 0000A4D2 46                  <1> 	inc	esi
  7153 0000A4D3 E2F6                <1> 	loop	loc_load_and_run_file_3
  7154 0000A4D5 EB11                <1> 	jmp	short loc_load_and_run_file_6
  7155                              <1> 
  7156                              <1> loc_load_and_run_file_4:
  7157 0000A4D7 28C0                <1> 	sub	al, al ; 0
  7158                              <1> 	;inc	word [argc]
  7159                              <1> 	; 25/07/2022
  7160 0000A4D9 FF05[70950100]      <1> 	inc	dword [argc]
  7161                              <1> loc_load_and_run_file_5:
  7162 0000A4DF AA                  <1> 	stosb
  7163 0000A4E0 FF05[A0940100]      <1> 	inc	dword [u.nread]
  7164 0000A4E6 E2DC                <1> 	loop	loc_load_and_run_file_2
  7165                              <1> 			
  7166                              <1> loc_load_and_run_file_6:
  7167 0000A4E8 30C0                <1> 	xor	al, al ; 0
  7168 0000A4EA AA                  <1> 	stosb
  7169 0000A4EB FF05[A0940100]      <1> 	inc	dword [u.nread]
  7170                              <1> loc_load_and_run_file_7:
  7171 0000A4F1 8807                <1> 	mov 	[edi], al ; 0
  7172                              <1> 	;inc	word [argc] ; 24/04/2016
  7173                              <1> 	; 25/07/2022
  7174 0000A4F3 FF05[70950100]      <1> 	inc	dword [argc]
  7175 0000A4F9 FF05[A0940100]      <1> 	inc	dword [u.nread] ; 24/04/2016
  7176 0000A4FF BE[827E0100]        <1> 	mov	esi, TextBuffer
  7177 0000A504 8B15[90860100]      <1> 	mov	edx, [FindFile_DirEntry+DirEntry_FileSize]
  7178 0000A50A 66A1[88860100]      <1> 	mov	ax, [FindFile_DirEntry+DirEntry_FstClusHI]
  7179 0000A510 C1E010              <1> 	shl	eax, 16 ; 13/11/2017
  7180 0000A513 66A1[8E860100]      <1> 	mov	ax, [FindFile_DirEntry+DirEntry_FstClusLO]
  7181                              <1> 	; EAX = First Cluster number
  7182                              <1> 	; EDX = File Size
  7183                              <1> 	; ESI = Argument list address
  7184                              <1> 	; [argc] = argument count
  7185                              <1> 	; [u.nread] = argument list length
  7186 0000A519 E8E5640000          <1> 	call	load_and_run_file ; trdosk6.s
  7187                              <1>         ;jc	loc_run_cmd_failed ; 04/01/2017
  7188                              <1> loc_load_and_run_file_8: ; 06/05/2016
  7189 0000A51E E95BEAFFFF          <1> 	jmp	loc_file_rw_restore_retn
  7190                              <1> 
  7191                              <1> check_prg_filename_ext:
  7192                              <1> 	; 23/04/2016 (TRDOS 386 = TRDOS v2.0)
  7193                              <1> 	; 10/09/2011 
  7194                              <1> 	; (TRDOS v1, CMDINTR.ASM, 'proc_check_exe_filename_ext')
  7195                              <1> 	; 14/11/2009
  7196                              <1> 	; INPUT ->
  7197                              <1> 	;	ESI = Dot File Name
  7198                              <1> 	; OUTPUT ->
  7199                              <1> 	;     cf = 0 -> EXE_ID in AL
  7200                              <1> 	;	ESI = Last char + 1 position
  7201                              <1> 	;     cf = 1 -> Invalid executable file name
  7202                              <1> 	;	or no file name extension if AH<=8
  7203                              <1> 	;	AL = Last file name char     
  7204                              <1> 	;     cf = 0 -> AL='P' (PRG), AL=0 (no extension)
  7205                              <1> 	;
  7206                              <1> 	; (Modified registers: EAX, ESI)
  7207                              <1> 
  7208 0000A523 30E4                <1> 	xor	ah, ah
  7209                              <1> loc_run_check_filename_ext:
  7210 0000A525 AC                  <1> 	lodsb
  7211 0000A526 3C21                <1> 	cmp	al, 21h
  7212 0000A528 7229                <1> 	jb	short loc_check_exe_fn_retn 
  7213 0000A52A FEC4                <1> 	inc	ah
  7214 0000A52C 3C2E                <1> 	cmp	al, '.'
  7215 0000A52E 75F5                <1> 	jne	short loc_run_check_filename_ext
  7216                              <1> 
  7217                              <1> loc_run_check_filename_ext_dot:
  7218 0000A530 80FC02              <1> 	cmp	ah, 2  ; .??? is not valid
  7219 0000A533 88C4                <1> 	mov	ah, al ; '.' 
  7220 0000A535 7219                <1> 	jb	short loc_check_prg_fn_retn
  7221                              <1> 
  7222                              <1> loc_run_check_filename_ext_dot_ok:
  7223 0000A537 AC                  <1> 	lodsb
  7224 0000A538 24DF                <1> 	and	al, 0DFh
  7225                              <1> 
  7226                              <1> loc_run_check_filename_ext_prg:
  7227 0000A53A 3C50                <1> 	cmp	al, 'P'
  7228 0000A53C 7212                <1> 	jb	short loc_check_prg_fn_retn
  7229 0000A53E 7711                <1> 	ja	short loc_check_prg_fn_stc
  7230 0000A540 AC                  <1> 	lodsb
  7231 0000A541 24DF                <1> 	and	al, 0DFh
  7232 0000A543 3C52                <1> 	cmp	al, 'R'
  7233 0000A545 750A                <1> 	jne	short loc_check_prg_fn_stc
  7234 0000A547 AC                  <1> 	lodsb
  7235 0000A548 24DF                <1> 	and	al, 0DFh
  7236 0000A54A 3C47                <1> 	cmp	al, 'G'
  7237 0000A54C 7503                <1> 	jne	short loc_check_prg_fn_stc
  7238                              <1> 
  7239 0000A54E B050                <1> 	mov	al, 'P'
  7240                              <1> loc_check_prg_fn_retn:
  7241 0000A550 C3                  <1> 	retn
  7242                              <1> 
  7243                              <1> ; 25/07/2022 - TRDOS 386 Kernel v2.0.5
  7244                              <1> 
  7245                              <1> loc_check_prg_fn_stc:
  7246 0000A551 F9                  <1> 	stc
  7247 0000A552 C3                  <1> 	retn
  7248                              <1> 
  7249                              <1> loc_check_exe_fn_retn:
  7250 0000A553 28C0                <1> 	sub	al, al ; 0
  7251                              <1> 	;retn
  7252                              <1> 
  7253                              <1> find_and_list_files:
  7254                              <1> 	;retn
  7255                              <1> set_exec_arguments:
  7256 0000A555 C3                  <1> 	retn
  7257                              <1> 
  7258                              <1> delete_fs_directory:
  7259 0000A556 31C0                <1> 	xor	eax, eax
  7260 0000A558 C3                  <1> 	retn
  3433                                  %include 'trdosk4.s' ; 24/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.9) - Directory Functions : trdosk4.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 03/09/2024  (Previous: 29/08/2023)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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 0000A559 BE[E0840100]        <1> 	mov	esi, PATH_Array
    28                              <1> change_prompt_dir_str: ; 05/10/2016 (call from 'set_working_path')
    29 0000A55E BF[867D0100]        <1> 	mov	edi, Current_Directory
    30 0000A563 8A25[807D0100]      <1> 	mov	ah, [Current_Dir_Level]
    31 0000A569 E807000000          <1> 	call	set_current_directory_string
    32 0000A56E 880D[E17D0100]      <1> 	mov	[Current_Dir_StrLen], cl
    33                              <1> 
    34 0000A574 C3                  <1> 	retn
    35                              <1> 
    36                              <1> set_current_directory_string:
    37                              <1> 	; 11/08/2022 (TRDOS 386 Kernel v2.0.5)
    38                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
    39                              <1> 	; 27/03/2011
    40                              <1> 	; 09/10/2009
    41                              <1> 	; INPUT:
    42                              <1> 	;    ESI = Path Array Address
    43                              <1> 	;    EDI = Current Directory String Buffer
    44                              <1> 	;    AH = Current Directory Level
    45                              <1> 	; OUTPUT => EAX, EBX, ESI will be changed
    46                              <1> 	;    EDI will be same with input
    47                              <1> 	;    ECX = Current Directory String Length
    48                              <1> 
    49 0000A575 57                  <1> 	push    edi
    50 0000A576 80FC00              <1> 	cmp     ah, 0
    51 0000A579 7651                <1> 	jna	short pass_write_path
    52 0000A57B 83C610              <1> 	add	esi, 16
    53 0000A57E 89F3                <1> 	mov	ebx, esi
    54                              <1> loc_write_path:
    55                              <1> 	;mov	ecx, 8
    56                              <1> 	; 11/08/2022
    57 0000A580 29C9                <1> 	sub	ecx, ecx
    58 0000A582 B108                <1> 	mov	cl, 8
    59                              <1> path_write_dirname1:
    60 0000A584 AC                  <1> 	lodsb
    61 0000A585 3C20                <1> 	cmp	al, 20h
    62 0000A587 7612                <1> 	jna	short pass_write_dirname1
    63 0000A589 AA                  <1> 	stosb
    64 0000A58A 81FF[E07D0100]      <1> 	cmp	edi, End_Of_Current_Dir_Str
    65 0000A590 733A                <1> 	jnb	short pass_write_path
    66 0000A592 E2F0                <1> 	loop	path_write_dirname1
    67 0000A594 803E20              <1> 	cmp	byte [esi], 20h
    68 0000A597 7624                <1> 	jna	short pass_write_dirname2
    69 0000A599 EB0A                <1> 	jmp     short loc_put_dot_cont_ext
    70                              <1> pass_write_dirname1:
    71 0000A59B 89DE                <1> 	mov	esi, ebx
    72 0000A59D 83C608              <1> 	add	esi, 8
    73 0000A5A0 803E20              <1> 	cmp	byte [esi], 20h
    74 0000A5A3 7618                <1> 	jna	short pass_write_dirname2
    75                              <1> loc_put_dot_cont_ext:
    76 0000A5A5 C6072E              <1> 	mov	byte [edi], "."
    77                              <1> 	;mov	ecx, 3
    78 0000A5A8 B103                <1> 	mov	cl, 3
    79                              <1> loc_check_dir_name_ext:
    80 0000A5AA AC                  <1> 	lodsb
    81 0000A5AB 47                  <1> 	inc	edi
    82 0000A5AC 3C20                <1> 	cmp	al, 20h
    83 0000A5AE 760D                <1> 	jna	short pass_write_dirname2
    84 0000A5B0 8807                <1> 	mov	[edi], al
    85 0000A5B2 81FF[E07D0100]      <1> 	cmp	edi, End_Of_Current_Dir_Str
    86 0000A5B8 7312                <1> 	jnb	short pass_write_path
    87 0000A5BA E2EE                <1> 	loop    loc_check_dir_name_ext
    88 0000A5BC 47                  <1> 	inc	edi
    89                              <1> pass_write_dirname2:
    90 0000A5BD FECC                <1> 	dec	ah
    91 0000A5BF 740B                <1> 	jz      short pass_write_path
    92 0000A5C1 83C310              <1> 	add	ebx, 16
    93 0000A5C4 89DE                <1> 	mov	esi, ebx
    94 0000A5C6 C6072F              <1> 	mov	byte [edi],"/"
    95 0000A5C9 47                  <1> 	inc	edi
    96 0000A5CA EBB4                <1> 	jmp	short loc_write_path
    97                              <1> pass_write_path:
    98 0000A5CC C60700              <1> 	mov	byte [edi], 0
    99 0000A5CF 47                  <1> 	inc	edi
   100 0000A5D0 89F9                <1> 	mov	ecx, edi
   101 0000A5D2 5F                  <1> 	pop	edi
   102 0000A5D3 29F9                <1> 	sub	ecx, edi
   103                              <1> 	; ECX = Current Directory String Length
   104 0000A5D5 C3                  <1> 	retn
   105                              <1> 
   106                              <1> get_current_directory:
   107                              <1> 	; 29/08/2023 (TRDOS 386 Kernel v2.0.6)
   108                              <1> 	; 11/08/2022
   109                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
   110                              <1> 	; 15/10/2016
   111                              <1> 	; 14/02/2016
   112                              <1> 	; 24/01/2016 (TRDOS 386 = TRDOS v2.0)
   113                              <1> 	; 27/03/2011
   114                              <1> 	;
   115                              <1> 	; INPUT-> ESI = Current Directory Buffer
   116                              <1> 	;         DL = TRDOS Logical Dos Drive Number + 1
   117                              <1> 	;              (0 = Default/Current Drive)
   118                              <1> 	;
   119                              <1> 	;   Note: Required dir buffer length may be <= 92 bytes
   120                              <1> 	;         for TRDOS (7*12 name chars + 7 slash + 0)
   121                              <1> 	; OUTPUT ->  ESI = Current Directory Buffer
   122                              <1> 	;            EAX, EBX, ECX, EDX, EDI will be changed
   123                              <1> 	;            CX/CL = Current Directory String Length
   124                              <1> 	;	     DL = Drive Number (0 based)
   125                              <1> 	;            (If input is 0, output is current drv number)
   126                              <1> 	;            DH = same with input 
   127                              <1> 	;   cf = 0 -> AL = 0
   128                              <1> 	;   cf = 1 -> error code in AL
   129                              <1> 
   130                              <1> loc_get_current_drive_0:
   131                              <1> 	; 29/08/2023
   132 0000A5D6 29C0                <1> 	sub	eax, eax ; 0
   133                              <1> 	;cmp	dl, 0
   134 0000A5D8 38C2                <1> 	cmp	dl, al
   135 0000A5DA 7724                <1> 	ja	short loc_get_current_drive_1
   136 0000A5DC 8A15[827D0100]      <1> 	mov	dl, [Current_Drv]
   137                              <1> 	; 29/08/2023
   138                              <1> 	;jmp	short loc_get_current_drive_2
   139                              <1> 
   140                              <1> loc_get_current_drive_2:
   141                              <1> 	; 29/08/2023
   142                              <1> 	;xor	eax, eax
   143                              <1> 	; eax = 0
   144 0000A5E2 88D4                <1> 	mov	ah, dl
   145 0000A5E4 56                  <1> 	push	esi ; (*)
   146 0000A5E5 BE00010900          <1> 	mov	esi, Logical_DOSDisks
   147 0000A5EA 01C6                <1> 	add	esi, eax
   148 0000A5EC 8A06                <1> 	mov	al, [esi+LD_Name]
   149 0000A5EE 3C41                <1> 	cmp	al, 'A'
   150 0000A5F0 721C                <1> 	jb	short loc_get_current_drive_not_ready_retn
   151                              <1> 
   152                              <1> 	; 28/07/2022
   153 0000A5F2 31C9                <1> 	xor	ecx, ecx
   154                              <1> 
   155 0000A5F4 8A667F              <1> 	mov	ah, [esi+LD_CDirLevel]
   156 0000A5F7 08E4                <1> 	or	ah, ah
   157 0000A5F9 7519                <1> 	jnz	short loc_get_current_drive_3
   158                              <1> 
   159                              <1> 	;xor	ah, ah ; mov ah, 0
   160                              <1> 
   161                              <1> 	; 11/08/2022 - BugFix (*)
   162 0000A5FB 5E                  <1> 	pop	esi ; (*) Current Directory Buffer address
   163                              <1> 
   164 0000A5FC 8826                <1> 	mov	[esi], ah
   165                              <1> 	; 28/07/2022
   166                              <1> 	;xor	ecx, ecx
   167 0000A5FE EB2D                <1> 	jmp	short loc_get_current_drive_4
   168                              <1> 
   169                              <1> 	; 29/08/2023
   170                              <1> loc_get_current_drive_1:
   171 0000A600 FECA                <1> 	dec 	dl
   172 0000A602 3A15[9A340100]      <1> 	cmp	dl, [Last_DOS_DiskNo]
   173 0000A608 76D8                <1> 	jna	short loc_get_current_drive_2
   174                              <1> 	;mov	eax, 0Fh ; Invalid drive (Drive not ready!)
   175                              <1> 	;cmc 	; stc
   176                              <1> 	; 28/07/2022
   177                              <1> 	;sub	eax, eax ; 29/08/2023
   178                              <1> 	; eax = 0
   179 0000A60A B00F                <1> 	mov	al, 0Fh
   180 0000A60C F9                  <1> 	stc
   181 0000A60D C3                  <1> 	retn
   182                              <1> 
   183                              <1> loc_get_current_drive_not_ready_retn:
   184 0000A60E 5E                  <1> 	pop	esi
   185                              <1> 	;mov	eax, 15
   186 0000A60F 66B80F00            <1> 	mov	ax, 15 ; Drive not ready
   187 0000A613 C3                  <1> 	retn
   188                              <1> 
   189                              <1> loc_get_current_drive_3:
   190 0000A614 BF[E0840100]        <1>         mov     edi, PATH_Array
   191 0000A619 57                  <1> 	push	edi
   192 0000A61A 81C680000000        <1> 	add	esi, LD_CurrentDirectory
   193                              <1> 	;mov	ecx, 32
   194                              <1> 	; 28/07/2022
   195 0000A620 B120                <1> 	mov	cl, 32
   196 0000A622 F3A5                <1> 	rep	movsd
   197 0000A624 5E                  <1> 	pop	esi ; Path Array Address
   198 0000A625 5F                  <1> 	pop	edi ; pushed esi (current dir buffer offset)
   199                              <1> 	;
   200 0000A626 E84AFFFFFF          <1> 	call	set_current_directory_string
   201 0000A62B 89FE                <1> 	mov	esi, edi
   202                              <1> 
   203                              <1> loc_get_current_drive_4:
   204 0000A62D 30C0                <1> 	xor	al, al
   205 0000A62F C3                  <1> 	retn
   206                              <1> 
   207                              <1> change_current_directory:
   208                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
   209                              <1> 	; 02/03/2021 (TRDOS 386 v2.0.3) ((BugFix))
   210                              <1> 	; 19/02/2016
   211                              <1> 	; 11/02/2016
   212                              <1> 	; 10/02/2016
   213                              <1> 	; 08/02/2016
   214                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
   215                              <1> 	; 18/09/2011 (DIR.ASM, 09/10/2011)
   216                              <1> 	; 04/10/2009
   217                              <1> 	; 2005
   218                              <1> 	; INPUT ->
   219                              <1> 	;	ESI = Directory string
   220                              <1> 	;	ah = CD command (CDh = save current dir string)
   221                              <1> 	; OUTPUT ->
   222                              <1> 	; 	EDI = DOS Drive Description Table
   223                              <1> 	; 	cf = 1 -> error
   224                              <1> 	;	   EAX = Error code
   225                              <1> 	;	cf = 0 -> successful
   226                              <1> 	;	   ESI = PATH_Array
   227                              <1> 	;	   EAX = Current Directory First Cluster
   228                              <1> 	;
   229                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
   230                              <1> 
   231 0000A630 8825[6E850100]      <1> 	mov	[CD_COMMAND], ah
   232 0000A636 803E2F              <1> 	cmp	byte [esi], '/'
   233 0000A639 7505                <1> 	jne	short loc_ccd_cdir_level
   234 0000A63B 46                  <1> 	inc	esi
   235 0000A63C 30C0                <1> 	xor	al, al
   236 0000A63E EB05                <1> 	jmp	short loc_ccd_parse_path_name
   237                              <1> loc_ccd_cdir_level:
   238 0000A640 A0[807D0100]        <1> 	mov	al, [Current_Dir_Level]
   239                              <1> loc_ccd_parse_path_name:
   240 0000A645 88C4                <1> 	mov	ah, al
   241 0000A647 BF[E0840100]        <1> 	mov	edi, PATH_Array
   242                              <1> 
   243                              <1> ; Reset directory levels > cdir level
   244                              <1> 	; is this required !?
   245                              <1> 	;
   246                              <1> 	; Relations:
   247                              <1> 	; MAINPROG.ASM (pass_ccdrv_reset_cdir_FAT_fcluster)
   248                              <1> 	; proc_parse_dir_name,
   249                              <1> 	; proc_change_current_directory (this procedure)
   250                              <1> 	; proc_change_prompt_dir_string
   251                              <1> 
   252 0000A64C 0FB6C8              <1> 	movzx	ecx, al
   253 0000A64F FEC1                <1> 	inc	cl
   254 0000A651 C0E104              <1> 	shl	cl, 4
   255 0000A654 01CF                <1> 	add	edi, ecx
   256 0000A656 B107                <1> 	mov	cl, 7
   257 0000A658 28C1                <1> 	sub	cl, al
   258 0000A65A C0E102              <1> 	shl	cl, 2
   259 0000A65D 89C3                <1> 	mov	ebx, eax
   260 0000A65F 31C0                <1> 	xor	eax, eax ; 0
   261 0000A661 F3AB                <1> 	rep	stosd
   262 0000A663 89D8                <1> 	mov	eax, ebx
   263                              <1> 
   264 0000A665 BF[E0840100]        <1> 	mov	edi, PATH_Array
   265                              <1> 
   266 0000A66A 803E20              <1> 	cmp	byte [esi], 20h
   267 0000A66D F5                  <1> 	cmc
   268 0000A66E 7305                <1> 	jnc	short pass_ccd_parse_dir_name
   269                              <1> 
   270                              <1> 		; ESI = Path name
   271                              <1> 		; AL = CCD_Level
   272 0000A670 E871010000          <1>         call    parse_dir_name
   273                              <1> 		; AL = CCD_Level
   274                              <1> 		; AH = Last_Dir_Level
   275                              <1> 		; (EDI = PATH_Array)
   276                              <1> 
   277                              <1> pass_ccd_parse_dir_name:
   278 0000A675 9C                  <1> 	pushf
   279                              <1> 
   280                              <1> 	;mov	[CCD_Level], al
   281                              <1>         ;mov	[Last_Dir_Level], ah
   282 0000A676 66A3[64850100]      <1> 	mov	[CCD_Level], ax
   283                              <1> 
   284 0000A67C 31DB                <1> 	xor	ebx, ebx
   285 0000A67E 8A3D[827D0100]      <1> 	mov	bh, [Current_Drv]
   286 0000A684 BE00010900          <1> 	mov	esi, Logical_DOSDisks
   287 0000A689 01DE                <1> 	add	esi, ebx
   288                              <1> 
   289 0000A68B 9D                  <1> 	popf
   290 0000A68C 720A                <1> 	jc	short loc_ccd_bad_path_name_retn
   291                              <1> 
   292 0000A68E 8935[60850100]      <1> 	mov	[CCD_DriveDT], esi
   293                              <1> 
   294 0000A694 3C07                <1> 	cmp	al, 7
   295 0000A696 7208                <1> 	jb	short loc_ccd_load_child_dir
   296                              <1> 
   297                              <1> loc_ccd_bad_path_name_retn:
   298 0000A698 87FE                <1> 	xchg	esi, edi
   299                              <1> 	;mov	eax, 19 ; Bad directory/path name
   300                              <1> 	; 28/07/2022
   301 0000A69A 29C0                <1> 	sub	eax, eax
   302 0000A69C B013                <1> 	mov	al, 19
   303 0000A69E F9                  <1> 	stc
   304                              <1> loc_ccd_retn_p:
   305 0000A69F C3                  <1> 	retn
   306                              <1> 
   307                              <1> loc_ccd_load_child_dir:
   308                              <1> 	; AL = CCD_Level
   309 0000A6A0 08C0                <1> 	or	al, al
   310 0000A6A2 7467                <1> 	jz	short loc_ccd_load_root_dir
   311                              <1> 
   312                              <1> 	;mov	cx, ax
   313                              <1> 	; 28/07/2022
   314 0000A6A4 89C1                <1> 	mov	ecx, eax
   315 0000A6A6 C0E004              <1> 	shl	al, 4
   316 0000A6A9 0FB6F0              <1> 	movzx	esi, al
   317 0000A6AC 01FE                <1>      	add	esi, edi  ; offset PATH_Array
   318                              <1> 
   319 0000A6AE 8B460C              <1> 	mov	eax, [esi+12]
   320 0000A6B1 38E9                <1> 	cmp	cl, ch
   321                              <1> 	;je	loc_ccd_load_sub_directory
   322                              <1> 	; 28/07/2022
   323 0000A6B3 7505                <1> 	jne	short loc_ccd_1
   324 0000A6B5 E9FA000000          <1> 	jmp	loc_ccd_load_sub_directory
   325                              <1> 
   326                              <1> loc_ccd_1:	; 28/07/2022
   327 0000A6BA A3[7C7D0100]        <1> 	mov	[Current_Dir_FCluster], eax
   328                              <1> 
   329                              <1> loc_ccd_load_child_dir_next:
   330 0000A6BF 83C610              <1> 	add	esi, 16 ; DOS DirEntry Format FileName Address
   331                              <1> 
   332                              <1>  	; Directory attribute : 10h
   333 0000A6C2 B010                <1> 	mov	al, 00010000b ; 10h (Attrib AND mask)
   334                              <1> 	;mov	ah, 11001000b ; C8h
   335                              <1> 	; Volume name attribute: 8h
   336 0000A6C4 B408                <1> 	mov	ah, 00001000b ; 08h (Attrib NAND, AND --> zero mask)
   337                              <1> 
   338                              <1> 	;xor	cx, cx  
   339 0000A6C6 31C9                <1> 	xor	ecx, ecx ; 02/03/2021
   340 0000A6C8 E8B6010000          <1> 	call	locate_current_dir_file
   341 0000A6CD 7353                <1> 	jnc	short loc_ccd_set_dir_cluster_ptr
   342                              <1> 
   343                              <1> 	; 19/02/2016
   344                              <1> 	;mov	edi, [CCD_DriveDT]
   345 0000A6CF 8A25[64850100]      <1> 	mov	ah, [CCD_Level]
   346 0000A6D5 803D[6E850100]CD    <1> 	cmp	byte [CD_COMMAND], 0CDh ;'CD' command or another
   347 0000A6DC 7509                <1> 	jne	short loc_ccd_load_child_dir_err
   348                              <1> 	; It is better to save recent successful part
   349                              <1> 	; of the (requested) path as current directory.
   350                              <1> 	; (Otherwise the path would be reset to back
   351                              <1> 	; on the next 'CD' command.)
   352 0000A6DE 88E1                <1> 	mov	cl, ah
   353 0000A6E0 50                  <1> 	push	eax
   354 0000A6E1 E8E4000000          <1> 	call	loc_ccd_save_current_dir
   355 0000A6E6 58                  <1> 	pop	eax
   356                              <1> loc_ccd_load_child_dir_err:
   357 0000A6E7 3C03                <1> 	cmp	al, 3	; AL = 2 => File not found error
   358 0000A6E9 7202                <1> 	jb	short loc_ccd_path_not_found_retn
   359 0000A6EB F9                  <1> 	stc
   360 0000A6EC C3                  <1> 	retn
   361                              <1> 
   362                              <1> loc_ccd_path_not_found_retn:
   363 0000A6ED B003                <1> 	mov	al, 3	; Path not found
   364 0000A6EF C3                  <1> 	retn
   365                              <1> 
   366                              <1> loc_ccd_load_FAT_root_dir:
   367 0000A6F0 803D[817D0100]02    <1> 	cmp	byte [Current_FATType], 2
   368 0000A6F7 776B                <1> 	ja	short loc_ccd_load_FAT32_root_dir
   369                              <1> 
   370                              <1> 	;mov	esi, [CCD_DriveDT]
   371                              <1> 	;push	esi
   372 0000A6F9 E8601D0000          <1> 	call	load_FAT_root_directory
   373                              <1> 	;pop	edi ; Dos Drv Description Table
   374                              <1> 
   375 0000A6FE 89F7                <1> 	mov	edi, esi
   376 0000A700 BE[E0840100]        <1> 	mov	esi, PATH_Array
   377 0000A705 7298                <1> 	jc	short loc_ccd_retn_p
   378                              <1> 
   379 0000A707 31C0                <1> 	xor	eax, eax
   380 0000A709 EB78                <1>         jmp	short loc_ccd_set_cdfc
   381                              <1> 
   382                              <1> loc_ccd_load_root_dir:
   383 0000A70B 803D[817D0100]01    <1> 	cmp	byte [Current_FATType], 1
   384 0000A712 73DC                <1> 	jnb	short loc_ccd_load_FAT_root_dir
   385                              <1> 
   386                              <1> loc_ccd_load_FS_root_dir:
   387 0000A714 E8FD1D0000          <1> 	call	load_FS_root_directory
   388 0000A719 EB5C                <1> 	jmp	short pass_ccd_load_FAT_sub_directory
   389                              <1> 
   390                              <1> loc_ccd_load_FS_sub_directory_next:
   391 0000A71B E8F61D0000          <1> 	call	load_FS_sub_directory
   392 0000A720 EB1F                <1> 	jmp	short pass_ccd_set_dir_cluster_ptr
   393                              <1> 
   394                              <1> loc_ccd_set_dir_cluster_ptr:
   395                              <1> 	; EDI = Directory Entry
   396 0000A722 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
   397 0000A726 C1E010              <1> 	shl	eax, 16
   398 0000A729 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
   399                              <1> 
   400 0000A72D 8B35[60850100]      <1> 	mov	esi, [CCD_DriveDT]
   401 0000A733 803D[817D0100]01    <1> 	cmp	byte [Current_FATType], 1
   402 0000A73A 72DF                <1> 	jb	short loc_ccd_load_FS_sub_directory_next
   403                              <1> 	;push	esi
   404 0000A73C E89B1D0000          <1> 	call	load_FAT_sub_directory
   405                              <1> 	;pop	edi ; Dos Drv Description Table
   406                              <1> 
   407                              <1> pass_ccd_set_dir_cluster_ptr:
   408                              <1> 	;mov	edi, esi
   409 0000A741 BE[E0840100]        <1> 	mov	esi, PATH_Array
   410 0000A746 7265                <1> 	jc	short loc_ccd_retn_c
   411                              <1> 
   412 0000A748 A1[AE840100]        <1> 	mov	eax, [DirBuff_Cluster]
   413                              <1> 
   414 0000A74D FE05[64850100]      <1> 	inc	byte [CCD_Level]
   415 0000A753 0FB61D[64850100]    <1> 	movzx	ebx, byte [CCD_Level]
   416 0000A75A C0E304              <1> 	shl	bl, 4 ; * 16 (<= 128)
   417 0000A75D 01DE                <1> 	add	esi, ebx ; 19/02/2016
   418 0000A75F 89460C              <1> 	mov	[esi+12], eax
   419 0000A762 EB1F                <1> 	jmp	short loc_ccd_set_cdfc
   420                              <1> 
   421                              <1> loc_ccd_load_FAT32_root_dir:
   422 0000A764 BE[E0840100]        <1> 	mov	esi, PATH_Array
   423 0000A769 8B460C              <1> 	mov	eax, [esi+12]
   424 0000A76C 8B35[60850100]      <1> 	mov	esi, [CCD_DriveDT]
   425                              <1> 
   426                              <1> loc_ccd_load_FAT_sub_directory:
   427                              <1> 	;push	esi
   428 0000A772 E8651D0000          <1> 	call	load_FAT_sub_directory
   429                              <1> 	;pop	edi ; Dos Drv Description Table
   430                              <1> 
   431                              <1> pass_ccd_load_FAT_sub_directory:
   432                              <1> 	;mov	edi, esi
   433 0000A777 BE[E0840100]        <1> 	mov	esi, PATH_Array
   434 0000A77C 722F                <1> 	jc	short loc_ccd_retn_c
   435                              <1> 
   436 0000A77E A1[AE840100]        <1> 	mov	eax, [DirBuff_Cluster]
   437                              <1> 
   438                              <1> loc_ccd_set_cdfc:
   439 0000A783 8A0D[64850100]      <1> 	mov	cl, [CCD_Level]
   440 0000A789 880D[807D0100]      <1> 	mov	[Current_Dir_Level], cl
   441 0000A78F A3[7C7D0100]        <1> 	mov	[Current_Dir_FCluster], eax
   442                              <1> 
   443 0000A794 8A2D[65850100]      <1> 	mov	ch, [Last_Dir_Level]
   444 0000A79A 38E9                <1> 	cmp	cl, ch 
   445                              <1> 	;jb	loc_ccd_load_child_dir_next
   446                              <1> 	; 28/07/2022
   447 0000A79C 7305                <1> 	jnb	short loc_ccd_2	
   448 0000A79E E91CFFFFFF          <1> 	jmp	loc_ccd_load_child_dir_next
   449                              <1> loc_ccd_2:
   450 0000A7A3 803D[6E850100]CD    <1> 	cmp	byte [CD_COMMAND], 0CDh ;'CD' command or another
   451 0000A7AA 741E                <1> 	je	short loc_ccd_save_current_dir
   452                              <1> 
   453                              <1>         ; jne -> don't save, restore (the previous cdir) later !
   454                              <1>         ; (saving the cdir would prevent previous cdir restoration!)
   455                              <1> 
   456 0000A7AC F8                  <1> 	clc
   457                              <1> 
   458                              <1> loc_ccd_retn_c:
   459 0000A7AD 8B3D[60850100]      <1> 	mov	edi, [CCD_DriveDT]
   460 0000A7B3 C3                  <1> 	retn
   461                              <1> 
   462                              <1> loc_ccd_load_sub_directory:
   463 0000A7B4 8B35[60850100]      <1> 	mov	esi, [CCD_DriveDT]
   464 0000A7BA 803D[817D0100]01    <1> 	cmp	byte [Current_FATType], 1
   465 0000A7C1 73AF                <1> 	jnb	short loc_ccd_load_FAT_sub_directory
   466 0000A7C3 E84E1D0000          <1> 	call	load_FS_sub_directory
   467 0000A7C8 EBAD                <1> 	jmp	short pass_ccd_load_FAT_sub_directory
   468                              <1> 
   469                              <1> loc_ccd_save_current_dir:
   470                              <1> 	; 02/03/2021 (TRDOS 386 v2.0.3) ((BugFix))
   471                              <1> 	; ('find_directory_entry' has been fixed to prevent large
   472                              <1> 	; ECX value > 65535)
   473                              <1> 	;
   474 0000A7CA BE[E0840100]        <1> 	mov	esi, PATH_Array ; 19/02/2016
   475 0000A7CF 8B3D[60850100]      <1> 	mov	edi, [CCD_DriveDT]
   476 0000A7D5 57                  <1> 	push	edi
   477 0000A7D6 83C77F              <1>         add     edi, LD_CDirLevel
   478 0000A7D9 880F                <1> 	mov	[edi], cl
   479 0000A7DB 47                  <1> 	inc	edi ; LD_CurrentDirectory
   480 0000A7DC 56                  <1> 	push	esi
   481                              <1> 	;;mov	ecx, 32  ; always < 65536 (in this procedure)
   482 0000A7DD 66B92000            <1> 	mov	cx, 32
   483                              <1> 	; 02/03/2021
   484                              <1> 	;mov	ecx, 32
   485 0000A7E1 F3A5                <1> 	rep	movsd
   486                              <1> 	; Current directory has been saved to
   487                              <1> 	; the DOS drive description table, cdir area !
   488 0000A7E3 5E                  <1> 	pop	esi  ; PATH_Array
   489 0000A7E4 5F                  <1> 	pop	edi  ; Dos Drv Description Table
   490                              <1> 
   491 0000A7E5 C3                  <1> 	retn
   492                              <1> 
   493                              <1> parse_dir_name:
   494                              <1> 	; 11/02/2016
   495                              <1> 	; 10/02/2016
   496                              <1> 	; 07/02/2016 (TRDOS 386 = TRDOS v2.0)
   497                              <1> 	; 18/09/2011
   498                              <1> 	; 17/10/2009
   499                              <1> 	; INPUT ->
   500                              <1> 	;	ESI = ASCIIZ Directory String Address
   501                              <1> 	;	AL = Current Directory Level
   502                              <1> 	;	EDI = Destination Adress
   503                              <1> 	;	     (8 levels, each one 12+4 byte)
   504                              <1> 	; OUTPUT ->
   505                              <1> 	;	EDI = Dir Entry Formatted Array
   506                              <1> 	;	     with zero cluster pointer at the last level
   507                              <1> 	;	AH = Last Dir Level
   508                              <1> 	;	AL = Current Dir Level
   509                              <1> 	;
   510                              <1> 	; (esi, ebx, ecx will be changed)
   511                              <1> 
   512                              <1> 	;mov	[PATH_Array_Ptr], edi
   513 0000A7E6 88C4                <1> 	mov	ah, al
   514 0000A7E8 66A3[04860100]      <1> 	mov	[PATH_CDLevel], ax
   515                              <1> repeat_ppdn_check_slash:
   516 0000A7EE AC                  <1> 	lodsb
   517 0000A7EF 3C2F                <1> 	cmp	al, '/'
   518 0000A7F1 74FB                <1> 	je	short repeat_ppdn_check_slash
   519 0000A7F3 3C21                <1> 	cmp	al, 21h
   520 0000A7F5 7219                <1> 	jb	short loc_ppdn_retn
   521 0000A7F7 57                  <1> 	push	edi
   522                              <1> loc_ppdn_get_dir_name:
   523 0000A7F8 B90C000000          <1> 	mov	ecx, 12
   524 0000A7FD BF[06860100]        <1> 	mov	edi, Dir_File_Name
   525                              <1> repeat_ppdn_get_dir_name:
   526 0000A802 AA                  <1> 	stosb
   527 0000A803 AC                  <1> 	lodsb
   528 0000A804 3C2F                <1> 	cmp	al, '/'
   529 0000A806 740A                <1> 	je	short loc_check_level_dot_conv_dir_name
   530 0000A808 3C20                <1> 	cmp	al, 20h
   531 0000A80A 7605                <1> 	jna	short loc_ppdn_end_of_path_scan
   532 0000A80C E2F4                <1> 	loop	repeat_ppdn_get_dir_name
   533 0000A80E 5F                  <1> 	pop	edi
   534 0000A80F F9                  <1> 	stc
   535                              <1> loc_ppdn_retn:
   536 0000A810 C3                  <1> 	retn
   537                              <1> 
   538                              <1> loc_ppdn_end_of_path_scan:
   539 0000A811 4E                  <1> 	dec	esi
   540                              <1> loc_check_level_dot_conv_dir_name:
   541 0000A812 31C0                <1> 	xor	eax, eax
   542 0000A814 AA                  <1> 	stosb
   543 0000A815 89F3                <1> 	mov	ebx, esi
   544 0000A817 BE[06860100]        <1> 	mov	esi, Dir_File_Name
   545 0000A81C AC                  <1> 	lodsb
   546                              <1> repeat_ppdn_name_check_dot:
   547 0000A81D 3C2E                <1> 	cmp	al, '.'
   548 0000A81F 7509                <1> 	jne	short loc_ppdn_convert_sub_dir_name
   549                              <1> repeat_ppdn_name_dot_dot:
   550 0000A821 AC                  <1> 	lodsb
   551 0000A822 3C2E                <1> 	cmp	al, '.'
   552 0000A824 743E                <1> 	je	short loc_ppdn_dot_dot
   553 0000A826 3C21                <1> 	cmp	al, 21h
   554 0000A828 7226                <1> 	jb	short pass_ppdn_convert_sub_dir_name
   555                              <1> loc_ppdn_convert_sub_dir_name:
   556 0000A82A 8A25[05860100]      <1> 	mov	ah, [PATH_Level]
   557 0000A830 80FC07              <1> 	cmp	ah, 7
   558 0000A833 731B                <1> 	jnb	short pass_ppdn_convert_sub_dir_name
   559 0000A835 FEC4                <1> 	inc	ah
   560 0000A837 8825[05860100]      <1> 	mov	[PATH_Level], ah
   561 0000A83D BE[06860100]        <1> 	mov	esi, Dir_File_Name
   562                              <1> 	;mov	edi, [PATH_Array_Ptr]
   563 0000A842 B010                <1> 	mov	al, 16
   564 0000A844 F6E4                <1> 	mul	ah
   565 0000A846 8B3C24              <1> 	mov	edi, [esp]
   566                              <1> 	;push	edi
   567 0000A849 01C7                <1> 	add	edi, eax
   568 0000A84B E800030000          <1> 	call	convert_file_name
   569                              <1> 	;pop	edi
   570                              <1> pass_ppdn_convert_sub_dir_name:
   571 0000A850 89DE                <1> 	mov	esi, ebx
   572                              <1> repeat_ppdn_check_last_slash:
   573 0000A852 AC                  <1> 	lodsb
   574 0000A853 3C2F                <1> 	cmp	al, '/'
   575 0000A855 74FB                <1> 	je	short repeat_ppdn_check_last_slash
   576 0000A857 3C21                <1> 	cmp	al, 21h
   577 0000A859 739D                <1> 	jnb	short loc_ppdn_get_dir_name
   578                              <1> end_of_parse_dir_name:
   579 0000A85B 5F                  <1> 	pop	edi
   580 0000A85C F5                  <1> 	cmc
   581                              <1> 	;mov	al, [PATH_CDLevel]
   582                              <1> 	;mov	ah, [PATH_Level]
   583 0000A85D 66A1[04860100]      <1> 	mov	ax, [PATH_CDLevel]
   584 0000A863 C3                  <1> 	retn
   585                              <1> 
   586                              <1> loc_ppdn_dot_dot:
   587 0000A864 AC                  <1> 	lodsb
   588 0000A865 3C21                <1> 	cmp	al, 21h
   589 0000A867 73F2                <1> 	jnb	short end_of_parse_dir_name
   590                              <1> loc_ppdn_dot_dot_prev_level:
   591 0000A869 66A1[04860100]      <1> 	mov	ax, [PATH_CDLevel]
   592 0000A86F 80EC01              <1> 	sub	ah, 1
   593 0000A872 80D400              <1> 	adc	ah, 0
   594 0000A875 38E0                <1> 	cmp	al, ah
   595 0000A877 7602                <1> 	jna	short pass_ppdn_set_al_to_ah
   596 0000A879 88E0                <1> 	mov	al, ah
   597                              <1> pass_ppdn_set_al_to_ah:
   598 0000A87B 66A3[04860100]      <1> 	mov	[PATH_CDLevel], ax
   599 0000A881 EBCD                <1> 	jmp	short pass_ppdn_convert_sub_dir_name
   600                              <1> 
   601                              <1> locate_current_dir_file:
   602                              <1> 	; 26/08/2024 (TRDOS 386 v2.0.9)
   603                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
   604                              <1> 	; 20/11/2017
   605                              <1> 	; 14/02/2016
   606                              <1> 	; 13/02/2016
   607                              <1> 	; 10/02/2016
   608                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
   609                              <1> 	; 14/08/2010
   610                              <1> 	; 19/09/2009
   611                              <1>         ; 2005
   612                              <1> 	; INPUT ->
   613                              <1> 	;	ESI = DOS DirEntry Format FileName Address
   614                              <1> 	;	AL = Attributes Mask
   615                              <1> 	;	(<AL AND EntryAttrib> must be equal to AL)
   616                              <1> 	;	AH = Negative Attributes Mask (If AH>0)
   617                              <1> 	;	(<AH AND EntryAttrib> must be ZERO)
   618                              <1> 	;	CH > 0 Find First Free Dir Entry or Deleted Entry
   619                              <1> 	;	CL = 0 -> Return the First Free Dir Entry
   620                              <1> 	;	CL = E5h -> Return the 1st deleted entry
   621                              <1> 	;	CL = FFh -> Return the 1st deleted or free entry
   622                              <1> 	;	CL > 0 and CL <> E5h and CL <> FFh -> Return the first
   623                              <1> 	;	     proper entry (which fits with Atributes Masks)
   624                              <1> 	;	CX = 0 Find Valid File/Directory/VolumeName
   625                              <1> 	;	? = Any One Char
   626                              <1> 	;	* = Every Chars
   627                              <1> 	; OUTPUT ->
   628                              <1> 	;	EDI = Directory Entry Address (in Directory Buffer)
   629                              <1> 	;	ESI = DOS DirEntry Format FileName Address
   630                              <1> 	;	CF = 0 -> No Error, Proper Entry,
   631                              <1> 	;	DL = Attributes
   632                              <1> 	;	DH = Previous Entry Attr (LongName Check)
   633                              <1> 	;	AL > 0 -> Ambiguous filename wildcard "?" used
   634                              <1> 	;	AH > 0 -> Ambiguous filename wildcard "*" used
   635                              <1> 	;	AX = 0 -> Filename full fits with directory entry
   636                              <1> 	;	CH = The 1st Name Char of Current Dir Entry
   637                              <1> 	;	CF = 1 -> Proper entry not found, Error Code in EAX/AL
   638                              <1> 	;	CL = 0 and CH = 0 -> Free Entry (End Of Dir)
   639                              <1> 	;	CL = 0 and CH = E5h -> Deleted Entry fits with filters
   640                              <1> 	;	CL > 0 -> Entry not found, CH invalid
   641                              <1> 	;	CF = 0 ->
   642                              <1> 	;	EBX = Current Directory Entry Index/Number (BX)
   643                              <1> 
   644                              <1> 	;mov	word [DirBuff_EntryCounter], 0 ; Zero Based
   645                              <1> 
   646 0000A883 8935[68850100]      <1> 	mov	[CDLF_FNAddress], esi
   647 0000A889 66A3[66850100]      <1> 	mov	[CDLF_AttributesMask], ax
   648 0000A88F 66890D[6C850100]    <1> 	mov	[CDLF_DEType], cx
   649                              <1> 
   650 0000A896 31DB                <1> 	xor	ebx, ebx
   651 0000A898 881D[7C850100]      <1> 	mov	[PreviousAttr], bl ; 0  ; 13/02/2016
   652                              <1> 
   653 0000A89E 8A3D[827D0100]      <1> 	mov	bh, [Current_Drv]
   654 0000A8A4 381D[A9840100]      <1> 	cmp	byte [DirBuff_ValidData], bl ; 0
   655 0000A8AA 761D                <1> 	jna	short loc_lcdf_reload_current_dir2
   656 0000A8AC 8A1D[A7840100]      <1>         mov     bl, [DirBuff_DRV]
   657 0000A8B2 80EB41              <1> 	sub	bl, 'A'
   658 0000A8B5 38DF                <1> 	cmp	bh, bl
   659 0000A8B7 750E                <1> 	jne	short loc_lcdf_reload_current_dir1
   660 0000A8B9 8B15[AE840100]      <1> 	mov	edx, [DirBuff_Cluster]
   661 0000A8BF 3B15[7C7D0100]      <1> 	cmp	edx, [Current_Dir_FCluster]
   662 0000A8C5 7412                <1> 	je	short loc_cdir_locatefile_search
   663                              <1> 
   664                              <1> loc_lcdf_reload_current_dir1:
   665 0000A8C7 30DB                <1> 	xor	bl, bl
   666                              <1> loc_lcdf_reload_current_dir2:
   667 0000A8C9 89DE                <1> 	mov	esi, ebx
   668 0000A8CB 81C600010900        <1>         add     esi, Logical_DOSDisks
   669 0000A8D1 E870000000          <1> 	call	reload_current_directory
   670 0000A8D6 7359                <1> 	jnc	short loc_locatefile_search_again
   671 0000A8D8 C3                  <1> 	retn
   672                              <1> 
   673                              <1> loc_cdir_locatefile_search:
   674 0000A8D9 31DB                <1> 	xor	ebx, ebx
   675 0000A8DB 55                  <1> 	push	ebp ; 20/11/2017
   676 0000A8DC E89E000000          <1> 	call	find_directory_entry
   677 0000A8E1 5D                  <1> 	pop	ebp ; 20/11/2017
   678 0000A8E2 7345                <1> 	jnc	short loc_cdir_locate_file_retn
   679                              <1> 
   680                              <1> loc_locatefile_check_stc_reason:
   681 0000A8E4 08ED                <1> 	or	ch, ch
   682 0000A8E6 7440                <1> 	jz	short loc_cdir_locate_file_stc_retn
   683                              <1> 
   684                              <1> loc_locatefile_check_next_entryblock:
   685                              <1> 	;mov	bh, [Current_Drv]
   686                              <1> 	;sub	bl, bl
   687                              <1> 	;movzx	esi, bx
   688                              <1> 	; 28/07/2022
   689 0000A8E8 31DB                <1>         xor	ebx, ebx
   690 0000A8EA 8A3D[827D0100]      <1> 	mov	bh, [Current_Drv]
   691 0000A8F0 89DE                <1> 	mov	esi, ebx
   692 0000A8F2 81C600010900        <1> 	add     esi, Logical_DOSDisks
   693                              <1> 
   694 0000A8F8 803D[807D0100]00    <1> 	cmp	byte [Current_Dir_Level], 0
   695 0000A8FF 760A                <1> 	jna	short loc_locatefile_check_FAT_type
   696                              <1> 
   697 0000A901 803D[817D0100]01    <1> 	cmp	byte [Current_FATType], 1
   698 0000A908 730A                <1> 	jnb	short loc_locatefile_load_subdir_cluster
   699 0000A90A C3                  <1> 	retn
   700                              <1> 
   701                              <1> loc_locatefile_check_FAT_type:
   702 0000A90B 803D[817D0100]03    <1> 	cmp	byte [Current_FATType], 3
   703 0000A912 7215                <1> 	jb	short loc_cdir_locate_file_retn
   704                              <1> 
   705                              <1> loc_locatefile_load_subdir_cluster:
   706 0000A914 A1[AE840100]        <1> 	mov	eax, [DirBuff_Cluster]
   707 0000A919 E8021A0000          <1> 	call	get_next_cluster
   708 0000A91E 730A                <1> 	jnc	short loc_locatefile_next_cluster
   709 0000A920 09C0                <1> 	or	eax, eax
   710 0000A922 7504                <1> 	jnz	short loc_locatefile_drive_not_ready_read_err
   711                              <1> 	;stc
   712                              <1> 	; 28/07/2022
   713                              <1> ;loc_locatefile_file_notfound:
   714                              <1> 	;mov	eax, 2 ; File/Directory/VolName not found
   715                              <1> 	;xor	eax, eax
   716                              <1> 	; 26/08/2024
   717                              <1> 	; eax = 0
   718 0000A924 B002                <1> 	mov	al, 2
   719 0000A926 F9                  <1> 	stc
   720 0000A927 C3                  <1> 	retn
   721                              <1> 
   722                              <1> loc_locatefile_drive_not_ready_read_err:
   723                              <1> 	;mov	eax, 17 ;Drive not ready or read error
   724                              <1> loc_cdir_locate_file_stc_retn:
   725 0000A928 F5                  <1> 	cmc ;stc
   726                              <1> loc_cdir_locate_file_retn:
   727 0000A929 C3                  <1> 	retn
   728                              <1> 
   729                              <1> loc_locatefile_next_cluster:
   730 0000A92A E8AD1B0000          <1> 	call	load_FAT_sub_directory
   731                              <1> 	;jc	short loc_locatefile_drive_not_ready_read_err
   732 0000A92F 72F8                <1> 	jc	short loc_cdir_locate_file_retn 
   733                              <1> 
   734                              <1> loc_locatefile_search_again:
   735 0000A931 8B35[68850100]      <1> 	mov	esi, [CDLF_FNAddress] 
   736 0000A937 66A1[66850100]      <1> 	mov	ax, [CDLF_AttributesMask]
   737 0000A93D 668B0D[6C850100]    <1> 	mov	cx, [CDLF_DEType] 
   738 0000A944 EB93                <1> 	jmp	short loc_cdir_locatefile_search
   739                              <1> 
   740                              <1> reload_current_directory:
   741                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
   742                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
   743                              <1> 	; 13/06/2010
   744                              <1> 	; 22/09/2009
   745                              <1>         ;
   746                              <1> 	; INPUT ->
   747                              <1> 	;	ESI = Dos drive description table address
   748                              <1> 
   749                              <1> 	;mov	al, [esi+LD_FATType]
   750 0000A946 A0[817D0100]        <1> 	mov	al, [Current_FATType]
   751 0000A94B 3C02                <1> 	cmp	al, 2
   752 0000A94D 7726                <1> 	ja	short loc_reload_FAT_sub_directory
   753 0000A94F 8A25[807D0100]      <1> 	mov	ah, [Current_Dir_Level]
   754 0000A955 08C0                <1> 	or	al, al
   755 0000A957 7409                <1> 	jz	short loc_reload_FS_directory
   756 0000A959 08E4                <1> 	or	ah, ah
   757 0000A95B 7518                <1> 	jnz	short loc_reload_FAT_sub_directory
   758                              <1> loc_reload_FAT_12_16_root_directory:
   759                              <1> 	;call	load_FAT_root_directory
   760                              <1> 	;retn
   761                              <1> 	; 28/07/2022
   762 0000A95D E9FC1A0000          <1> 	jmp	load_FAT_root_directory
   763                              <1> loc_reload_FS_directory:
   764 0000A962 20E4                <1> 	and	ah, ah
   765 0000A964 7505                <1> 	jnz	short loc_reload_FS_sub_directory 
   766                              <1> loc_reload_FS_root_directory: 
   767                              <1> 	;call	load_FS_root_directory
   768                              <1> 	;retn
   769                              <1> 	; 28/07/2022
   770 0000A966 E9AB1B0000          <1> 	jmp	load_FS_root_directory
   771                              <1> loc_reload_FS_sub_directory:
   772 0000A96B A1[7C7D0100]        <1> 	mov	eax, [Current_Dir_FCluster]
   773                              <1> 	;call	load_FS_sub_directory
   774                              <1> 	;retn
   775 0000A970 E9A11B0000          <1> 	jmp	load_FS_sub_directory 
   776                              <1> loc_reload_FAT_sub_directory:
   777 0000A975 A1[7C7D0100]        <1> 	mov	eax, [Current_Dir_FCluster]
   778                              <1> 	;call	load_FAT_sub_directory
   779                              <1> 	;retn
   780                              <1> 	; 28/07/2022
   781 0000A97A E95D1B0000          <1> 	jmp	load_FAT_sub_directory
   782                              <1> 
   783                              <1> find_directory_entry:
   784                              <1> 	; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
   785                              <1> 	; 02/03/2021 (TRDOS 386 v2.0.3) ((BugFix))
   786                              <1> 	; 14/02/2016
   787                              <1> 	; 13/02/2016
   788                              <1> 	; 10/02/2016
   789                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
   790                              <1> 	; 14/08/2010 (DIR.ASM, "proc_find_direntry")
   791                              <1> 	; 19/09/2009
   792                              <1> 	; 2005
   793                              <1> 	; INPUT ->
   794                              <1> 	;	ESI = Sub Dir or File Name Address
   795                              <1> 	;	AL = Attributes Mask 
   796                              <1> 	;	(<AL AND EntryAttrib> must be equal to AL)
   797                              <1> 	;	AH = Negative Attributes Mask (If AH>0)
   798                              <1> 	;	(<AH AND EntryAttrib> must be ZERO)
   799                              <1> 	;	CH > 0 Find First Free Dir Entry or Deleted Entry
   800                              <1> 	;	CL = 0 -> Return the First Free Dir Entry
   801                              <1> 	;	CL = E5h -> Return the 1st deleted entry
   802                              <1> 	;	CL = FFh -> Return the 1st deleted or free entry
   803                              <1> 	;	CL > 0 and CL <> E5h and CL <> FFh -> Return the first 
   804                              <1> 	;            proper entry (which fits with Atributes Masks)
   805                              <1> 	;	CX = 0 -> Find Valid File/Directory/VolumeName
   806                              <1> 	;	? = Any One Char
   807                              <1> 	;	* = Every Chars
   808                              <1> 	;	EBX = Current Dir Entry (BX)
   809                              <1> 	;
   810                              <1> 	; OUTPUT ->
   811                              <1> 	;	EDI = Directory Entry Address (in DirectoryBuffer)
   812                              <1> 	;	ESI = Sub Dir or File Name Address
   813                              <1> 	;	CF = 0 -> No Error, Proper Entry,
   814                              <1> 	;	DL = Attributes
   815                              <1> 	;	DH = Previous Entry Attr (LongName Check)
   816                              <1> 	;	AL > 0 -> Ambiguous filename wildcard "?" used
   817                              <1> 	;	AH > 0 -> Ambiguous filename wildcard "*" used
   818                              <1> 	;	AX = 0 -> Filename full fits with directory entry
   819                              <1> 	;	EBX = CurrentDirEntry (BX)
   820                              <1> 	;	CH = The 1st Name Char of Current Dir Entry
   821                              <1> 	;	CF = 1 -> Proper entry not found, Error Code in AX/AL
   822                              <1> 	;	CL = 0 and CH = 0 -> Free Entry (End Of Dir)
   823                              <1> 	;	CL = 0 and CH = E5h -> Deleted Entry fits with filters
   824                              <1> 	;	CL > 0 -> Entry not found, CH invalid
   825                              <1> 	;
   826                              <1> 	; (EAX, EBX, ECX, EDX, EDI, EBP will be changed)
   827                              <1> 
   828 0000A97F 663B1D[AC840100]    <1> 	cmp	bx, [DirBuff_LastEntry]
   829 0000A986 7728                <1> 	ja      short loc_ffde_stc_retn_255 ; 28/07/2022
   830                              <1> 
   831                              <1> 	;mov    [DirBuff_CurrentEntry], bx
   832                              <1> 
   833 0000A988 BF00000800          <1>   	mov	edi, Directory_Buffer
   834 0000A98D 66A3[78850100]      <1> 	mov	[FDE_AttrMask], ax
   835                              <1> 
   836 0000A993 29C0                <1> 	sub	eax, eax
   837                              <1> 
   838                              <1> 	;;mov	[PreviousAttr], al ; 0 ;; 13/02/2016
   839 0000A995 66A3[7A850100]      <1> 	mov	[AmbiguousFileName], ax ; 0
   840                              <1> 
   841 0000A99B 6689D8              <1> 	mov	ax, bx
   842                              <1> 	;shl	ax, 5 ; ; * 32 ; Directory entry size
   843                              <1> 	; 28/07/2022
   844 0000A99E C1E005              <1> 	shl	eax, 5
   845 0000A9A1 01C7                <1> 	add     edi, eax
   846                              <1> 
   847 0000A9A3 08ED                <1> 	or	ch, ch
   848                              <1> 	;jnz	loc_find_free_deleted_entry_0
   849                              <1> 	; 28/07/2022
   850 0000A9A5 7405                <1> 	jz	short loc_fde_any_valid_entry_opt
   851 0000A9A7 E911010000          <1> 	jmp	loc_find_free_deleted_entry_0
   852                              <1> 
   853                              <1> loc_fde_any_valid_entry_opt:
   854 0000A9AC 08C9                <1> 	or      cl, cl
   855                              <1>         ;jnz	loc_ffde_stc_retn_255
   856                              <1> 	; 28/07/2022
   857 0000A9AE 742E                <1> 	jz	short check_find_dir_entry
   858                              <1> 
   859                              <1> 	; 28/07/2022
   860                              <1> loc_ffde_stc_retn_255:
   861                              <1> 	; 02/03/2021 (TRDOS 386 v2.0.3) ((BugFix))
   862                              <1> 	; (ECX must not be > 65535)
   863                              <1> 	; ((because 'loc_ccd_save_current_dir'
   864                              <1> 	;  sets CX to 32 for 'rep movsd'))
   865 0000A9B0 66B9FFFF            <1> 	mov	cx, 0FFFFh
   866                              <1> 	;xor	ecx, ecx
   867                              <1> 	;dec	ecx ; 0FFFFFFFFh
   868                              <1> 	;xor	eax, eax
   869                              <1> loc_find_direntry_stc_retn:
   870                              <1> loc_check_ffde_retn_1:
   871                              <1> 	;mov	ax, 2
   872                              <1> 	;mov	eax, 2 ; File Not Found
   873                              <1> 	; 28/07/2022
   874 0000A9B4 29C0                <1> 	sub	eax, eax
   875 0000A9B6 B002                <1> 	mov	al, 2
   876 0000A9B8 8A35[7C850100]      <1> 	mov	dh, [PreviousAttr]
   877 0000A9BE 66891D[AA840100]    <1> 	mov	[DirBuff_CurrentEntry], bx
   878 0000A9C5 F9                  <1> 	stc
   879 0000A9C6 C3                  <1> 	retn
   880                              <1> 
   881                              <1> 	; 28/07/2022
   882                              <1> loc_find_dir_next_entry_prevdeleted:
   883 0000A9C7 80CA80              <1> 	or	dl, 80h  ; Bit 7 -> deleted entry sign
   884                              <1> 	;jmp	short loc_find_dir_next_entry
   885                              <1> 
   886                              <1> 	; 28/07/2022
   887                              <1> loc_find_dir_next_entry:
   888 0000A9CA 8815[7C850100]      <1> 	mov	byte [PreviousAttr], dl ; LongName check
   889                              <1> loc_find_dir_next_entry_1:
   890 0000A9D0 5E                  <1> 	pop	esi
   891 0000A9D1 83C720              <1> 	add	edi, 32
   892                              <1> 	;;inc	word [DirBuff_EntryCounter]
   893                              <1> 	;inc	bx
   894                              <1> 	; 28/07/2022
   895 0000A9D4 43                  <1> 	inc	ebx
   896 0000A9D5 663B1D[AC840100]    <1> 	cmp	bx, [DirBuff_LastEntry]
   897 0000A9DC 77D2                <1> 	ja	short loc_ffde_stc_retn_255
   898                              <1>         ; 28/07/2022
   899                              <1> 	;jmp	short check_find_dir_entry
   900                              <1> 
   901                              <1> check_find_dir_entry:
   902 0000A9DE 66A1[78850100]      <1> 	mov	ax, [FDE_AttrMask]
   903 0000A9E4 8A2F                <1> 	mov	ch, [edi]
   904 0000A9E6 80FD00              <1> 	cmp     ch, 0 ; Is it never used entry?
   905                              <1> 	;jna	loc_find_direntry_stc_retn
   906                              <1> 	; 28/07/2022
   907 0000A9E9 7702                <1> 	ja	short loc_fde_check_attrib
   908                              <1> 	; end of directory entries
   909 0000A9EB EBC7                <1> 	jmp	loc_find_direntry_stc_retn
   910                              <1> loc_fde_check_attrib:
   911 0000A9ED 56                  <1> 	push	esi
   912 0000A9EE 8A570B              <1> 	mov	dl, [edi+0Bh] ; File attributes
   913 0000A9F1 80FDE5              <1> 	cmp	ch, 0E5h ; Is it a deleted file?
   914 0000A9F4 74D1                <1> 	je	short loc_find_dir_next_entry_prevdeleted
   915                              <1> 
   916 0000A9F6 80FA0F              <1> 	cmp     dl, 0Fh ; longname sub component check
   917 0000A9F9 7505                <1> 	jne     short loc_check_attributes_mask
   918 0000A9FB E8A6010000          <1> 	call	save_longname_sub_component
   919                              <1> 
   920                              <1> loc_check_attributes_mask:
   921 0000AA00 88C6                <1> 	mov	dh, al
   922 0000AA02 20D6                <1> 	and	dh, dl
   923                              <1> 	; 28/07/2022
   924 0000AA04 38F0                <1> 	cmp	al, dh
   925 0000AA06 75C2                <1> 	jne	short loc_find_dir_next_entry
   926 0000AA08 20D4                <1> 	and	ah, dl
   927 0000AA0A 75BE                <1>         jnz	short loc_find_dir_next_entry
   928 0000AA0C 80FA0F              <1> 	cmp	dl, 0Fh
   929 0000AA0F 7515                <1> 	jne	short pass_direntry_attr_check
   930                              <1> 
   931 0000AA11 3C0F                <1> 	cmp	al, 0Fh ; AL = 0Fh -> find long name
   932 0000AA13 75B5                <1> 	jne	short loc_find_dir_next_entry
   933                              <1> 
   934 0000AA15 5E                  <1> 	pop	esi
   935                              <1> 	;xor	ax, ax
   936                              <1> 	; 28/07/2022
   937                              <1> 	;sub	eax, eax
   938 0000AA16 30C0                <1> 	xor	al, al
   939 0000AA18 8A35[7C850100]      <1> 	mov	dh, [PreviousAttr]
   940 0000AA1E 66891D[AA840100]    <1> 	mov	[DirBuff_CurrentEntry], bx
   941 0000AA25 C3                  <1> 	retn
   942                              <1> 
   943                              <1> pass_direntry_attr_check:
   944 0000AA26 89FD                <1> 	mov	ebp, edi ; 14/02/2016
   945                              <1> 	;mov	ecx, 8
   946                              <1> 	; 28/07/2022
   947 0000AA28 29C9                <1> 	sub	ecx, ecx
   948 0000AA2A B108                <1> 	mov	cl, 8
   949                              <1> loc_lodsb_find_dir:
   950 0000AA2C AC                  <1> 	lodsb
   951 0000AA2D 3C2A                <1> 	cmp	al, '*'
   952 0000AA2F 7508                <1> 	jne	short pass_fde_ambiguous1_check
   953 0000AA31 FE05[7B850100]      <1>         inc     byte [AmbiguousFileName+1]
   954 0000AA37 EB23                <1> 	jmp	short loc_check_direntry_extension
   955                              <1> 
   956                              <1> pass_fde_ambiguous1_check:
   957 0000AA39 3C3F                <1> 	cmp	al, '?'
   958 0000AA3B 750D                <1> 	jne	short pass_fde_ambiguous2_check
   959 0000AA3D FE05[7A850100]      <1> 	inc	byte [AmbiguousFileName]
   960 0000AA43 803F20              <1> 	cmp	byte [edi], 20h
   961 0000AA46 763E                <1> 	jna	short loc_find_dir_next_entry_ebp
   962 0000AA48 EB0F                <1> 	jmp	short loc_scasb_find_dir_inc_di
   963                              <1> 
   964                              <1> pass_fde_ambiguous2_check:
   965 0000AA4A 3C20                <1> 	cmp	al, 20h
   966 0000AA4C 7507                <1> 	jne	short loc_scasb_find_dir
   967 0000AA4E 803F20              <1> 	cmp	byte [edi], 20h
   968 0000AA51 7533                <1> 	jne	short loc_find_dir_next_entry_ebp
   969 0000AA53 EB07                <1> 	jmp	short loc_check_direntry_extension
   970                              <1> 
   971                              <1> loc_scasb_find_dir:
   972 0000AA55 3A07                <1> 	cmp	al, [edi]
   973 0000AA57 752D                <1> 	jne	short loc_find_dir_next_entry_ebp
   974                              <1> loc_scasb_find_dir_inc_di:
   975 0000AA59 47                  <1> 	inc	edi
   976 0000AA5A E2D0                <1> 	loop	loc_lodsb_find_dir
   977                              <1> 
   978                              <1> loc_check_direntry_extension:
   979 0000AA5C BE08000000          <1> 	mov	esi, 8
   980 0000AA61 89F7                <1> 	mov	edi, esi ; 8
   981 0000AA63 033424              <1> 	add	esi, [esp] ; Sub Dir or File Name Address
   982 0000AA66 01EF                <1> 	add	edi, ebp
   983 0000AA68 B103                <1> 	mov	cl, 3
   984                              <1> loc_lodsb_find_dir_ext:
   985 0000AA6A AC                  <1> 	lodsb
   986 0000AA6B 3C2A                <1> 	cmp	al, '*'
   987 0000AA6D 7508                <1> 	jne	short pass_fde_ambiguous3_check
   988 0000AA6F FE05[7B850100]      <1> 	inc	byte [AmbiguousFileName+1]
   989 0000AA75 EB1F                <1> 	jmp	short loc_find_dir_proper_direntry
   990                              <1> 
   991                              <1> pass_fde_ambiguous3_check:
   992 0000AA77 3C3F                <1> 	cmp	al, '?'
   993 0000AA79 7512                <1> 	jne	short pass_fde_ambiguous4_check
   994 0000AA7B FE05[7A850100]      <1> 	inc	byte [AmbiguousFileName]
   995 0000AA81 803F20              <1> 	cmp	byte [edi], 20h
   996                              <1> 	;jna	short loc_find_dir_next_entry_ebp
   997                              <1> 	;jmp	short loc_scasb_find_dir_ext_inc_di
   998                              <1> 	; 28/07/2022
   999 0000AA84 7732                <1> 	ja	short loc_scasb_find_dir_ext_inc_di
  1000                              <1> 
  1001                              <1> loc_find_dir_next_entry_ebp:
  1002 0000AA86 89EF                <1> 	mov	edi, ebp ; 14/02/2016
  1003 0000AA88 E93DFFFFFF          <1> 	jmp	loc_find_dir_next_entry ; 28/07/2022
  1004                              <1> 
  1005                              <1> pass_fde_ambiguous4_check:
  1006 0000AA8D 3C20                <1> 	cmp	al, 20h
  1007 0000AA8F 7523                <1> 	jne	short loc_scasb_find_dir_ext
  1008 0000AA91 803F20              <1> 	cmp	byte [edi], 20h
  1009                              <1> 	; 28/07/2022
  1010 0000AA94 75F0                <1> 	jne	short loc_find_dir_next_entry_ebp
  1011                              <1> 	;jmp	short loc_find_dir_proper_direntry
  1012                              <1> 
  1013                              <1> loc_find_dir_proper_direntry:
  1014 0000AA96 30C9                <1> 	xor	cl, cl
  1015                              <1> loc_find_dir_proper_direntry_1:
  1016 0000AA98 5E                  <1> 	pop	esi
  1017 0000AA99 89EF                <1>         mov     edi, ebp
  1018 0000AA9B 8A2F                <1> 	mov	ch, [edi]
  1019 0000AA9D 8A570B              <1> 	mov     dl, [edi+0Bh] ; Dir entry attributes
  1020 0000AAA0 66A1[7A850100]      <1> 	mov	ax, [AmbiguousFileName]
  1021                              <1> loc_find_dir_proper_direntry_2:
  1022 0000AAA6 8A35[7C850100]      <1> 	mov     dh, [PreviousAttr]
  1023 0000AAAC 66891D[AA840100]    <1> 	mov	[DirBuff_CurrentEntry], bx
  1024 0000AAB3 C3                  <1> 	retn
  1025                              <1> 
  1026                              <1> loc_scasb_find_dir_ext:
  1027 0000AAB4 3A07                <1> 	cmp	al, [edi]
  1028 0000AAB6 75CE                <1> 	jne	short loc_find_dir_next_entry_ebp
  1029                              <1> loc_scasb_find_dir_ext_inc_di:
  1030 0000AAB8 47                  <1> 	inc	edi
  1031 0000AAB9 E2AF                <1> 	loop    loc_lodsb_find_dir_ext
  1032 0000AABB EBDB                <1> 	jmp	short loc_find_dir_proper_direntry_1
  1033                              <1> 
  1034                              <1> loc_find_free_deleted_entry_0:
  1035 0000AABD 66A1[78850100]      <1> 	mov	ax, [FDE_AttrMask]
  1036 0000AAC3 8A2F                <1> 	mov	ch, [edi]
  1037 0000AAC5 8A570B              <1> 	mov	dl, [edi+0Bh] ; File attributes
  1038 0000AAC8 08C9                <1> 	or	cl, cl
  1039 0000AACA 7407                <1> 	jz	short loc_check_ffde_0_repeat
  1040                              <1> 	;cmp	cl, 0E5h
  1041                              <1> 	;je	short pass_loc_check_ffde_0_err
  1042 0000AACC 80F9FF              <1> 	cmp	cl, 0FFh
  1043 0000AACF 7430                <1> 	je	short loc_find_free_deleted_entry_1
  1044 0000AAD1 EB4A                <1> 	jmp	short pass_loc_check_ffde_0_err
  1045                              <1> 
  1046                              <1> loc_check_ffde_0_repeat:
  1047 0000AAD3 08ED                <1> 	or	ch, ch
  1048 0000AAD5 7510                <1> 	jnz	short loc_check_ffde_0_next
  1049                              <1> 
  1050                              <1> loc_check_ffde_retn_2:
  1051                              <1> 	;sub	ax, ax
  1052                              <1> 	; 28/07/2022
  1053 0000AAD7 29C0                <1> 	sub	eax, eax
  1054 0000AAD9 8A35[7C850100]      <1> 	mov	dh, [PreviousAttr]
  1055 0000AADF 66891D[AA840100]    <1> 	mov	[DirBuff_CurrentEntry], bx
  1056 0000AAE6 C3                  <1> 	retn
  1057                              <1>  
  1058                              <1> loc_check_ffde_0_next:
  1059                              <1> 	;inc	bx
  1060                              <1> 	; 28/07/2022
  1061 0000AAE7 43                  <1> 	inc	ebx
  1062 0000AAE8 83C720              <1> 	add	edi, 32
  1063                              <1> 	;inc	word [DirBuff_EntryCounter]
  1064                              <1> 	 
  1065 0000AAEB 663B1D[AC840100]    <1>         cmp	bx, [DirBuff_LastEntry]
  1066                              <1> 	;ja	short loc_ffde_stc_retn_255
  1067                              <1> 	; 07/08/2022
  1068 0000AAF2 773A                <1> 	ja	short jmp_ffde_stc_retn_255
  1069                              <1> 
  1070 0000AAF4 8815[7C850100]      <1> 	mov	[PreviousAttr], dl
  1071 0000AAFA 8A2F                <1> 	mov	ch, [edi]
  1072 0000AAFC 8A570B              <1> 	mov	dl, [edi+0Bh] ; file attributes
  1073 0000AAFF EBD2                <1> 	jmp	short loc_check_ffde_0_repeat
  1074                              <1> 
  1075                              <1> loc_find_free_deleted_entry_1:
  1076 0000AB01 28D2                <1> 	sub	dl, dl
  1077                              <1> loc_find_free_deleted_entry_2:
  1078 0000AB03 20ED                <1> 	and	ch, ch  
  1079 0000AB05 74D0                <1> 	jz	short loc_check_ffde_retn_2
  1080 0000AB07 80FDE5              <1> 	cmp	ch, 0E5h
  1081 0000AB0A 74CB                <1> 	je	short loc_check_ffde_retn_2
  1082                              <1> 	;inc	bx
  1083                              <1> 	; 28/07/2022
  1084 0000AB0C 43                  <1> 	inc	ebx
  1085 0000AB0D 83C720              <1> 	add	edi, 32
  1086 0000AB10 663B1D[AC840100]    <1> 	cmp	bx, [DirBuff_LastEntry]
  1087                              <1> 	;ja	short loc_ffde_stc_retn_255
  1088                              <1> 	; 07/08/2022
  1089 0000AB17 7715                <1> 	ja	short jmp_ffde_stc_retn_255
  1090                              <1> 
  1091 0000AB19 8A2F                <1> 	mov	ch, [edi]
  1092 0000AB1B EBE6                <1> 	jmp	short loc_find_free_deleted_entry_2
  1093                              <1> 
  1094                              <1> pass_loc_check_ffde_0_err:
  1095 0000AB1D 38CD                <1> 	cmp	ch, cl
  1096 0000AB1F 741F                <1> 	je	short loc_check_ffde_attrib
  1097                              <1> 
  1098                              <1> 	;inc	bx
  1099                              <1> 	; 28/07/2022
  1100 0000AB21 43                  <1> 	inc	ebx
  1101 0000AB22 83C720              <1> 	add	edi, 32
  1102 0000AB25 663B1D[AC840100]    <1> 	cmp	bx, [DirBuff_LastEntry]
  1103                              <1>         ;ja	loc_ffde_stc_retn_255
  1104                              <1> 	; 28/07/2022
  1105 0000AB2C 7605                <1> 	jna	short loc_ffe_save_prev_attr
  1106                              <1> jmp_ffde_stc_retn_255:	; 07/08/2022
  1107 0000AB2E E97DFEFFFF          <1> 	jmp	loc_ffde_stc_retn_255
  1108                              <1> 
  1109                              <1> loc_ffe_save_prev_attr: ; 28/07/2022
  1110 0000AB33 8815[7C850100]      <1> 	mov	[PreviousAttr], dl
  1111 0000AB39 8A2F                <1> 	mov	ch, [edi]
  1112 0000AB3B 8A570B              <1> 	mov	dl, [edi+0Bh]
  1113 0000AB3E EBDD                <1> 	jmp	short pass_loc_check_ffde_0_err
  1114                              <1> 
  1115                              <1> loc_check_ffde_attrib:
  1116 0000AB40 88C6                <1> 	mov	dh, al
  1117 0000AB42 20D6                <1> 	and	dh, dl
  1118 0000AB44 38F0                <1> 	cmp	al, dh
  1119 0000AB46 759F                <1> 	jne	short loc_check_ffde_0_next
  1120 0000AB48 20D4                <1> 	and	ah, dl
  1121 0000AB4A 759B                <1> 	jnz	short loc_check_ffde_0_next
  1122 0000AB4C 30C9                <1> 	xor	cl, cl 
  1123 0000AB4E EB87                <1>         jmp	short loc_check_ffde_retn_2
  1124                              <1> 
  1125                              <1> convert_file_name:
  1126                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  1127                              <1> 	; 06/03/2016
  1128                              <1> 	; 11/02/2016
  1129                              <1> 	; 07/02/2016 (TRDOS 386 = TRDOS v2.0)
  1130                              <1> 	; 06/10/2009
  1131                              <1> 	; 2005
  1132                              <1> 	;
  1133                              <1> 	; INPUT  ->
  1134                              <1> 	;	ESI = Dot File Name Location
  1135                              <1> 	;	EDI = Dir Entry Format File Name Location
  1136                              <1> 	; OUTPUT ->
  1137                              <1> 	;	EDI = Dir Entry Format File Name Location
  1138                              <1> 	;	ESI = Dot File Name Location (capitalized)
  1139                              <1> 	;
  1140                              <1> 	; (ECX, AL will be changed)
  1141                              <1> 
  1142 0000AB50 56                  <1> 	push	esi
  1143 0000AB51 57                  <1> 	push	edi
  1144                              <1> 
  1145                              <1> 	;mov	ecx, 11
  1146                              <1> 	; 29/07 2022
  1147 0000AB52 29C9                <1> 	sub	ecx, ecx
  1148 0000AB54 B10B                <1> 	mov	cl, 11
  1149 0000AB56 B020                <1> 	mov	al, 20h
  1150 0000AB58 F3AA                <1> 	rep	stosb
  1151                              <1> 
  1152 0000AB5A 8B3C24              <1> 	mov	edi, [esp]
  1153                              <1> 
  1154 0000AB5D B10C                <1> 	mov	cl, 12 ; file name length (max.)
  1155                              <1> 	; 06/03/2016
  1156                              <1> 	; Directory entry name limit (11 bytes) check for
  1157                              <1> 	; 'rename_directory_entry' procedure.
  1158                              <1> 	; (EDI points to Directory Entry)
  1159                              <1> 	; (If the file name would not contain a dot
  1160                              <1> 	; and file name length would be 12, this would cause to
  1161                              <1> 	; overwrite the attributes byte of the directory entry.)
  1162                              <1> 	;
  1163 0000AB5F B50B                <1> 	mov	ch, 11 ; directory entry's name length
  1164                              <1> loc_check_first_dot:
  1165 0000AB61 8A06                <1> 	mov	al, [esi]
  1166 0000AB63 3C2E                <1> 	cmp	al, 2Eh
  1167 0000AB65 750C                <1> 	jne	short pass_check_first_dot
  1168 0000AB67 8807                <1> 	mov	[edi], al
  1169 0000AB69 47                  <1> 	inc	edi
  1170 0000AB6A 46                  <1> 	inc	esi
  1171 0000AB6B FEC9                <1> 	dec	cl
  1172 0000AB6D 75F2                <1> 	jnz	short loc_check_first_dot
  1173                              <1> 	;;(ecx <= 12)
  1174                              <1> 	;;loop	loc_check_first_dot 
  1175 0000AB6F EB30                <1> 	jmp	short stop_convert_file
  1176                              <1> 
  1177                              <1> loc_get_fchar:
  1178 0000AB71 8A06                <1> 	mov	al, [esi]
  1179                              <1> pass_check_first_dot:
  1180 0000AB73 3C61                <1> 	cmp	al, 61h ; 'a'
  1181 0000AB75 7208                <1> 	jb	short pass_name_capitalize
  1182 0000AB77 3C7A                <1> 	cmp	al, 7Ah ; 'z'
  1183 0000AB79 7704                <1> 	ja	short pass_name_capitalize
  1184 0000AB7B 24DF                <1> 	and	al, 0DFh
  1185 0000AB7D 8806                <1> 	mov	[esi], al
  1186                              <1> pass_name_capitalize:
  1187 0000AB7F 3C21                <1> 	cmp	al, 21h
  1188 0000AB81 721E                <1> 	jb	short stop_convert_file
  1189 0000AB83 3C2E                <1> 	cmp	al, 2Eh ; '.'
  1190 0000AB85 750C                <1> 	jne	short pass_dot_space
  1191                              <1> add_dot_space:
  1192 0000AB87 80F904              <1> 	cmp	cl, 4
  1193 0000AB8A 760E                <1> 	jna	short inc_and_loop
  1194 0000AB8C 47                  <1> 	inc	edi
  1195 0000AB8D FECD                <1> 	dec	ch ; 06/03/2016
  1196 0000AB8F FEC9                <1> 	dec	cl
  1197 0000AB91 EBF4                <1> 	jmp	short add_dot_space
  1198                              <1> 
  1199                              <1> 	;mov	al, 4
  1200                              <1> 	;cmp	cl, al
  1201                              <1> 	;jna	short inc_and_loop
  1202                              <1> 	;sub	cl, al
  1203                              <1> 	;add	edi, ecx
  1204                              <1> 	;mov	cl, al
  1205                              <1> 	;jmp	short inc_and_loop
  1206                              <1> 
  1207                              <1> pass_dot_space:
  1208 0000AB93 8807                <1> 	mov	[edi], al
  1209                              <1> loc_after_double_dot:
  1210                              <1> 	; 06/03/2016
  1211 0000AB95 FECD                <1> 	dec	ch ; count down for 11 bytes dir entry limit
  1212 0000AB97 740A                <1> 	jz	short stop_convert_file_x
  1213 0000AB99 47                  <1> 	inc	edi
  1214                              <1> inc_and_loop:
  1215 0000AB9A FEC9                <1> 	dec	cl ; count down for 12 bytes filename limit 
  1216 0000AB9C 7403                <1> 	jz	short stop_convert_file	
  1217 0000AB9E 46                  <1> 	inc	esi
  1218                              <1> 	;;(ecx <= 12)
  1219                              <1> 	;;loop	loc_get_fchar
  1220 0000AB9F EBD0                <1> 	jmp	short loc_get_fchar
  1221                              <1> 
  1222                              <1> stop_convert_file:
  1223                              <1> 	; 06/03/2016
  1224 0000ABA1 30ED                <1> 	xor	ch, ch
  1225                              <1> 	; ECX < 256 ; 'find_first_file' -> xor cl, cl
  1226                              <1> stop_convert_file_x:
  1227 0000ABA3 5F                  <1> 	pop	edi
  1228 0000ABA4 5E                  <1> 	pop	esi
  1229 0000ABA5 C3                  <1> 	retn
  1230                              <1> 
  1231                              <1> save_longname_sub_component:
  1232                              <1> 	; 13/02/2016
  1233                              <1> 	; 06/02/2016 (TRDOS 386 = TRDOS v2.0)
  1234                              <1> 	; 28/02/2010
  1235                              <1> 	; 17/10/2009
  1236                              <1> 	; INPUT ->
  1237                              <1> 	;	EDI = Directory Entry
  1238                              <1> 	;     	// This procedure is called
  1239                              <1> 	;	// from 'find_directory_entry' procedure.
  1240                              <1> 	;	// If the last entry returns with
  1241                              <1> 	;	// a non-zero LongnameFound value and
  1242                              <1> 	;	// if LFN_CheckSum value is equal to
  1243                              <1> 	;	// the next shortname checksum,
  1244                              <1> 	;	// long name is valid.
  1245                              <1> 	;	// If a longname is longer than 65 bytes,
  1246                              <1> 	;	// it is invalid for trdos. (>45h)
  1247                              <1> 
  1248 0000ABA6 57                  <1> 	push	edi
  1249 0000ABA7 56                  <1> 	push	esi
  1250                              <1> 	;push	ebx
  1251                              <1> 	;push	ecx
  1252                              <1> 	;push	edx
  1253 0000ABA8 50                  <1> 	push	eax
  1254                              <1>            
  1255 0000ABA9 29C9                <1> 	sub	ecx, ecx
  1256                              <1> 	;sub	eax, eax
  1257 0000ABAB B11A                <1> 	mov	cl, 26
  1258                              <1> 
  1259 0000ABAD 0FB607              <1> 	movzx	eax, byte [edi] ; LDIR_Order
  1260 0000ABB0 3C41                <1> 	cmp	al, 41h  ; 40h (last long entry sign) + 1
  1261 0000ABB2 722B                <1> 	jb	short pass_pslnsc_last_long_entry
  1262                              <1> 
  1263 0000ABB4 88C4                <1> 	mov	ah, al
  1264 0000ABB6 80EC40              <1> 	sub	ah, 40h
  1265 0000ABB9 8825[7E850100]      <1> 	mov	[LFN_EntryLength], ah
  1266                              <1> 	
  1267 0000ABBF 3C45                <1> 	cmp	al, 45h  ; 40h (last long entry sign) + 5
  1268                              <1>  		; Max 130 byte length is usable in TRDOS
  1269                              <1> ; 26*5 = 130
  1270 0000ABC1 7753                <1> 	ja	short loc_pslnsc_retn
  1271                              <1> 
  1272 0000ABC3 2407                <1> 	and	al, 07h ; 0Fh
  1273 0000ABC5 A2[7D850100]        <1> 	mov	[LongNameFound], al
  1274                              <1> 
  1275 0000ABCA FEC8                <1> 	dec	al
  1276                              <1> 	;mov	cl, 26
  1277 0000ABCC F6E1                <1> 	mul	cl
  1278                              <1> 
  1279 0000ABCE 89C6                <1> 	mov	esi, eax
  1280 0000ABD0 01CE                <1> 	add	esi, ecx
  1281                              <1> 		; to make is an ASCIIZ string
  1282                              <1> 		; with ax+26 bytes length
  1283 0000ABD2 81C6[80850100]      <1> 	add	esi, LongFileName
  1284 0000ABD8 66C7060000          <1> 	mov	word [esi], 0
  1285 0000ABDD EB16                <1> 	jmp	short loc_pslsc_move_ldir_name2
  1286                              <1> 
  1287                              <1> pass_pslnsc_last_long_entry:
  1288 0000ABDF 3C04                <1> 	cmp	al, 04h
  1289 0000ABE1 7733                <1> 	ja	short loc_pslnsc_retn
  1290 0000ABE3 FE0D[7D850100]      <1> 	dec	byte [LongNameFound]
  1291 0000ABE9 3A05[7D850100]      <1> 	cmp	al, [LongNameFound]
  1292 0000ABEF 7525                <1> 	jne	short loc_pslnsc_retn
  1293                              <1> 
  1294                              <1> loc_pslsc_move_ldir_name1:
  1295 0000ABF1 FEC8                <1> 	dec	al
  1296                              <1> 	;mov	cl, 26
  1297 0000ABF3 F6E1                <1> 	mul	cl
  1298                              <1> 
  1299                              <1> loc_pslsc_move_ldir_name2:
  1300 0000ABF5 8A4F0D              <1> 	mov	cl, [edi+0Dh] ; long name checksum
  1301 0000ABF8 880D[7F850100]      <1> 	mov	[LFN_CheckSum], cl
  1302 0000ABFE 89FE                <1> 	mov	esi, edi ; LDIR_Order
  1303 0000AC00 BF[80850100]        <1> 	mov	edi, LongFileName
  1304 0000AC05 01C7                <1> 	add	edi, eax
  1305 0000AC07 46                  <1> 	inc	esi
  1306 0000AC08 B105                <1> 	mov	cl, 5 ; chars 1 to 5
  1307 0000AC0A F366A5              <1> 	rep	movsw
  1308 0000AC0D 83C603              <1> 	add	esi, 3
  1309 0000AC10 A5                  <1> 	movsd	; char 6 & 7
  1310 0000AC11 A5                  <1> 	movsd	; char 8 & 9
  1311 0000AC12 A5                  <1> 	movsd	; char 10 & 11
  1312 0000AC13 46                  <1> 	inc	esi
  1313 0000AC14 46                  <1> 	inc	esi
  1314 0000AC15 A5                  <1> 	movsd   ; char 12 & 13 
  1315                              <1> 
  1316                              <1> loc_pslnsc_retn:
  1317 0000AC16 58                  <1>  	pop	eax
  1318                              <1> 	;pop	edx
  1319                              <1> 	;pop	ecx
  1320                              <1> 	;pop	ebx
  1321 0000AC17 5E                  <1> 	pop	esi
  1322 0000AC18 5F                  <1> 	pop	edi
  1323                              <1> 
  1324 0000AC19 C3                  <1>     	retn
  1325                              <1> 
  1326                              <1> parse_path_name:
  1327                              <1> 	; 03/09/2024 (TRDOS 386 v2.0.9)
  1328                              <1> 	; 09/08/2022
  1329                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  1330                              <1> 	; 10/02/2016
  1331                              <1> 	; 08/02/2016 (TRDOS 386 = TRDOS v2.0)
  1332                              <1> 	; 10/009/2011 ('proc_parse_pathname')
  1333                              <1> 	; 27/11/2009
  1334                              <1> 	; 05/12/2004
  1335                              <1> 	;
  1336                              <1> 	; INPUT ->
  1337                              <1> 	;	ESI = Beginning of ASCIIZ pathname string
  1338                              <1> 	;       EDI = Destination Address
  1339                              <1> 	;	      (which is TR-DOS FindFile data buffer)
  1340                              <1> 	; OUTPUT ->
  1341                              <1> 	;	CF = 1 -> Error
  1342                              <1> 	;	     EAX = Error Code (AL)
  1343                              <1> 	;
  1344                              <1> 	; (Modified registers: eax, ecx, esi, edi)
  1345                              <1> 	
  1346                              <1> 	; Clear the pathname bytes in TR-DOS Findfile data buffer
  1347 0000AC1A 57                  <1> 	push	edi
  1348                              <1> 	;mov	ecx, 20  ; 80 bytes
  1349                              <1> 	; 29/07/2022
  1350 0000AC1B 29C9                <1> 	sub	ecx, ecx
  1351 0000AC1D B114                <1> 	mov	cl, 20
  1352 0000AC1F 31C0                <1> 	xor	eax, eax
  1353 0000AC21 F3AB                <1> 	rep	stosd 
  1354 0000AC23 5F                  <1> 	pop	edi
  1355                              <1> 
  1356 0000AC24 668B06              <1> 	mov	ax, [esi]
  1357 0000AC27 80FC3A              <1> 	cmp	ah, ':'
  1358 0000AC2A 741C                <1> 	je	short loc_ppn_change_drive
  1359 0000AC2C A0[827D0100]        <1> 	mov	al, [Current_Drv]
  1360 0000AC31 EB33                <1> 	jmp	short pass_ppn_change_drive
  1361                              <1> 
  1362                              <1> pass_ppn_cdir:
  1363 0000AC33 8B35[A2860100]      <1> 	mov	esi, [First_Path_Pos]
  1364 0000AC39 AC                  <1> 	lodsb
  1365                              <1> loc_ppn_get_filename:
  1366 0000AC3A 83C741              <1> 	add	edi, 65 ; FindFile_Name location
  1367                              <1> 	; TRDOS Filename length must not be more than 12 bytes
  1368                              <1> 	;mov	ecx, 12
  1369 0000AC3D B10C                <1> 	mov	cl, 12
  1370                              <1> loc_ppn_get_fnchar_next:
  1371 0000AC3F AA                  <1> 	stosb
  1372 0000AC40 AC                  <1> 	lodsb
  1373 0000AC41 3C21                <1> 	cmp	al, 21h
  1374 0000AC43 726A                <1> 	jb	short loc_ppn_clc_return
  1375 0000AC45 E2F8                <1>         loop    loc_ppn_get_fnchar_next
  1376                              <1> loc_ppn_return:
  1377 0000AC47 C3                  <1> 	retn
  1378                              <1> 
  1379                              <1> loc_ppn_change_drive:
  1380                              <1> 	; 29/07/2022
  1381                              <1> 	; ecx = 0
  1382 0000AC48 24DF                <1> 	and	al, 0DFh
  1383 0000AC4A 2C41                <1> 	sub	al, 'A' ; A:
  1384 0000AC4C 7265                <1> 	jc	short loc_ppn_invalid_drive
  1385 0000AC4E 3805[9A340100]      <1> 	cmp	[Last_DOS_DiskNo], al
  1386 0000AC54 725D                <1> 	jb	short loc_ppn_invalid_drive
  1387                              <1> 
  1388 0000AC56 46                  <1> 	inc	esi
  1389 0000AC57 46                  <1> 	inc	esi
  1390 0000AC58 8A26                <1> 	mov	ah, [esi]
  1391 0000AC5A 80FC21              <1> 	cmp	ah, 21h
  1392 0000AC5D 7307                <1> 	jnb	short pass_ppn_change_drive
  1393                              <1> 
  1394                              <1> loc_ppn_cmd_failed:
  1395                              <1> 	; File or directory name is not existing
  1396 0000AC5F 8807                <1> 	mov	[edi], al ; Drv 
  1397 0000AC61 66B80100            <1> 	mov	ax, 1 ; eax = 1
  1398                              <1> 	; TR-DOS Error Code 01h = Bad Command Argument
  1399                              <1> 	; MS-DOS Error Code 01h : Invalid Function Number
  1400                              <1> 	;stc
  1401                              <1> 	; (MainProg ErrMsg: "Bad command or file name!")
  1402 0000AC65 C3                  <1> 	retn
  1403                              <1> 
  1404                              <1> pass_ppn_change_drive:
  1405 0000AC66 8935[A2860100]      <1> 	mov	[First_Path_Pos], esi
  1406                              <1> 	;mov	dword [Last_Slash_Pos], 0
  1407                              <1> 	; 29/07/2022
  1408 0000AC6C 890D[A6860100]      <1> 	mov	[Last_Slash_Pos], ecx ; 0
  1409 0000AC72 AA                  <1> 	stosb
  1410 0000AC73 8A06                <1> 	mov	al, [esi]
  1411                              <1> loc_scan_ppn_dslash:
  1412 0000AC75 3C2F                <1> 	cmp	al, '/'
  1413 0000AC77 7506                <1>   	jne	short loc_scan_next_slash_pos
  1414 0000AC79 8935[A6860100]      <1> 	mov	[Last_Slash_Pos], esi
  1415                              <1> loc_scan_next_slash_pos:
  1416 0000AC7F 46                  <1> 	inc	esi
  1417 0000AC80 8A06                <1> 	mov	al, [esi]
  1418 0000AC82 3C20                <1> 	cmp	al, 20h
  1419 0000AC84 77EF                <1> 	ja	short loc_scan_ppn_dslash
  1420                              <1> 	;cmp	dword [Last_Slash_Pos], 0
  1421                              <1> 	; 09/08/2022
  1422                              <1> 	;cmp	[Last_Slash_Pos], ecx ; 0 ?
  1423                              <1> 	;jna	short pass_ppn_cdir
  1424                              <1> 
  1425 0000AC86 8B0D[A6860100]      <1> 	mov	ecx, [Last_Slash_Pos]
  1426                              <1> 	; 03/09/2024
  1427 0000AC8C 67E3A4              <1> 	jcxz	pass_ppn_cdir
  1428 0000AC8F 8B35[A2860100]      <1> 	mov	esi, [First_Path_Pos]
  1429 0000AC95 29F1                <1> 	sub	ecx, esi
  1430 0000AC97 41                  <1> 	inc	ecx
  1431                              <1> 	;cmp	ecx, 64
  1432 0000AC98 80F940              <1> 	cmp	cl, 64
  1433 0000AC9B 7715                <1> 	ja	short loc_ppn_invalid_drive_stc
  1434                              <1> 
  1435 0000AC9D 89F8                <1> 	mov	eax, edi ; Dest Dir String Location (65 bytes)
  1436 0000AC9F F3A4                <1> 	rep	movsb
  1437                              <1> 	;mov	[edi], cl ; 0, End of Dir String
  1438 0000ACA1 8B35[A6860100]      <1> 	mov	esi, [Last_Slash_Pos]
  1439 0000ACA7 46                  <1> 	inc	esi
  1440 0000ACA8 89C7                <1> 	mov	edi, eax
  1441 0000ACAA AC                  <1> 	lodsb
  1442 0000ACAB 3C21                <1> 	cmp	al, 21h
  1443 0000ACAD 738B                <1> 	jnb	short loc_ppn_get_filename
  1444                              <1> loc_ppn_clc_return:
  1445                              <1> 	;clc
  1446 0000ACAF 31C0                <1> 	xor	eax, eax
  1447 0000ACB1 C3                  <1> 	retn
  1448                              <1> 
  1449                              <1> loc_ppn_invalid_drive_stc:
  1450 0000ACB2 F5                  <1> 	cmc	 ; stc
  1451                              <1> loc_ppn_invalid_drive:
  1452                              <1> 	; cf = 1
  1453                              <1> 	; The Drive Letter/Char < "A" or > "Z"
  1454 0000ACB3 66B80F00            <1> 	mov	ax, 0Fh
  1455                              <1> 	; MS-DOS Error Code 0Fh = Disk Drive Invalid 
  1456                              <1> 	; (MainProg ErrMsg: "Drive not ready or read error!")
  1457 0000ACB7 C3                  <1> 	retn
  1458                              <1> 
  1459                              <1> find_longname:
  1460                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  1461                              <1> 	; 13/02/2016 (TRDOS 386 = TRDOS v2.0)
  1462                              <1> 	; 24/01/2010 (DIR.ASM, 'proc_find_longname')
  1463                              <1> 	; 17/10/2009
  1464                              <1> 	
  1465                              <1> 	; INPUT -> 
  1466                              <1> 	;	ESI = DOS short file name address
  1467                              <1> 	; 	for example: "filename.ext"
  1468                              <1> 	;
  1469                              <1> 	; OUTPUT ->
  1470                              <1> 	; 	ESI = ASCIIZ longname address (cf = 0)
  1471                              <1> 	;	cf = 1 -> error number returns in EAX (AL)
  1472                              <1> 	;	AL = 0 & CF=1 -> longname not found
  1473                              <1> 	;	     the file/directory has no longname
  1474                              <1> 	; 	cf = 0 -> AL = FAT Type 
  1475                              <1>  
  1476                              <1> 	; 17/10/2009
  1477                              <1> 	; ASCIIZ string will be returned
  1478                              <1> 	; as LongFileName
  1479                              <1> 	; clearing/reset is not needed
  1480                              <1> 	;mov	ecx, 33
  1481                              <1> 	;mov	edi, LongFileName
  1482                              <1> 	;sub	ax, ax ; 0
  1483                              <1> 	;rep	stosw
  1484                              <1> 
  1485                              <1> 	;mov	byte [LongNameFound], 0
  1486                              <1> 
  1487                              <1> 	; ESI = ASCIIZ file/directory name address
  1488                              <1> 	;   AL = Attributes AND mask 
  1489                              <1> 	;	(Result of AND must be equal to AL)
  1490                              <1> 	;   AH = Negative attributes mask
  1491                              <1> 	;	(Result of AND must be ZERO)
  1492 0000ACB8 66B80008            <1> 	mov	ax, 0800h 
  1493                              <1> 		; it must not be volume name or longname
  1494 0000ACBC E8A9DEFFFF          <1> 	call	find_first_file
  1495 0000ACC1 7212                <1> 	jc	short loc_fln_retn
  1496                              <1> 
  1497                              <1> loc_fln_check_FAT_Type:
  1498 0000ACC3 803D[817D0100]01    <1> 	cmp	byte [Current_FATType], 1
  1499 0000ACCA 7302                <1> 	jnb	short loc_fln_check_longname_yes_sign
  1500                              <1> 
  1501                              <1> 	;call	get_fs_longname
  1502                              <1> 	;retn
  1503                              <1> 	; 29/07/2022
  1504 0000ACCC EB37                <1> 	jmp	get_fs_longname
  1505                              <1> 
  1506                              <1> loc_fln_check_longname_yes_sign:
  1507 0000ACCE 08FF                <1> 	or	bh, bh
  1508 0000ACD0 7504                <1> 	jnz	short loc_fln_check_longnamefound_number
  1509                              <1> loc_fln_longname_not_found_retn:
  1510 0000ACD2 31C0                <1> 	xor	eax, eax 
  1511                              <1> 	; cf = 1 & al = 0 -> longname not found
  1512 0000ACD4 F9                  <1> 	stc
  1513                              <1> loc_fln_retn:
  1514 0000ACD5 C3                  <1> 	retn
  1515                              <1> 
  1516                              <1> loc_fln_check_longnamefound_number:
  1517                              <1> 	; 'LongNameFound' is set by
  1518                              <1>         ; by 'save_longname_sub_component'
  1519                              <1> 	; which is called from
  1520                              <1> 	; 'find_directory_entry'
  1521                              <1> 	; which is called from
  1522                              <1> 	; 'find_first_file'
  1523                              <1> 	; It must 1 if the longname is valid
  1524 0000ACD6 803D[7D850100]01    <1>         cmp     byte [LongNameFound], 1
  1525 0000ACDD 75F3                <1> 	jne	short loc_fln_longname_not_found_retn
  1526                              <1> 
  1527                              <1> loc_fln_calculate_checksum: 
  1528 0000ACDF E813000000          <1> 	call	calculate_checksum
  1529                              <1> 	; AL = shortname checksum
  1530                              <1> 
  1531                              <1> loc_fln_longname_validation:
  1532                              <1> 	; 'LFN_CheckSum' has been set already
  1533                              <1> 	; by 'save_longname_sub_component'
  1534                              <1> 	; which is called from
  1535                              <1> 	; 'find_directory_entry'
  1536                              <1> 	; which is called from
  1537                              <1> 	; 'find_first_file'
  1538 0000ACE4 3805[7F850100]      <1> 	cmp	[LFN_CheckSum], al
  1539 0000ACEA 75E6                <1> 	jne	short loc_fln_longname_not_found_retn
  1540                              <1> 
  1541 0000ACEC BE[80850100]        <1> 	mov	esi, LongFileName
  1542 0000ACF1 A0[817D0100]        <1> 	mov	al, [Current_FATType]
  1543 0000ACF6 C3                  <1> 	retn
  1544                              <1> 
  1545                              <1> calculate_checksum:
  1546                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  1547                              <1> 	; 13/02/2016 (TRDOS 386 = TRDOS v2.0)
  1548                              <1> 	; 17/10/2009 (DIR.ASM, 'proc_calculate_checksum')
  1549                              <1>         ;
  1550                              <1> 	; INPUT ->
  1551                              <1> 	;	ESI = 11 byte DOS File Name location
  1552                              <1> 	;	(in DOS Directory Entry Format)
  1553                              <1> 	; OUTPUT ->
  1554                              <1> 	;	 AL = 8 bit checksum (CRC) value
  1555                              <1> 	;
  1556                              <1> 	; (Modified registers: EAX, ECX, ESI)
  1557                              <1> 
  1558                              <1> 	; Erdogan Tan [ 17-10-2009 ]
  1559                              <1> 	;  'ror al, 1' instruction
  1560                              <1> 
  1561                              <1> 	; Erdogan Tan [ 20-06-2004 ]
  1562                              <1> 	; This 8086 assembly code is an original code
  1563                              <1> 	; which is adapted from C code in
  1564                              <1> 	; Microsoft FAT32 File System Specification
  1565                              <1> 	; Version 1.03, December 6, 2000
  1566                              <1> 	; Page 28
  1567                              <1> 
  1568 0000ACF7 30C0                <1> 	xor	al, al
  1569                              <1> 	;mov	ecx, 11
  1570                              <1> 	; 29/07/2022
  1571 0000ACF9 29C9                <1> 	sub	ecx, ecx
  1572 0000ACFB B10B                <1> 	mov	cl, 11
  1573                              <1> loc_next_sum:
  1574                              <1> 	;xor	ah, ah
  1575                              <1> 	;test	al, 1
  1576                              <1> 	;jz	short pass_ah_80h
  1577                              <1> 	;mov	ah, 80h
  1578                              <1> ;pass_ah_80h:
  1579                              <1> 	;shr	al, 1
  1580 0000ACFD D0C8                <1> 	ror	al, 1 ; 17/10/2009
  1581 0000ACFF 0206                <1> 	add	al, [esi]
  1582 0000AD01 46                  <1> 	inc	esi
  1583                              <1> 	;add	al, ah
  1584 0000AD02 E2F9                <1> 	loop	loc_next_sum
  1585 0000AD04 C3                  <1> 	retn
  1586                              <1> 
  1587                              <1> get_fs_longname:
  1588                              <1> 	; temporary (13/02/2016)
  1589 0000AD05 31C0                <1> 	xor	eax, eax
  1590 0000AD07 F9                  <1> 	stc
  1591 0000AD08 C3                  <1> 	retn
  1592                              <1> 
  1593                              <1> make_sub_directory:
  1594                              <1> 	; 07/08/2022
  1595                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  1596                              <1> 	; 16/10/2016
  1597                              <1> 	; 02/03/2016, 03/03/2016
  1598                              <1> 	; 26/02/2016, 27/02/2016
  1599                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
  1600                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_make_directory')
  1601                              <1> 	; 10/07/2010
  1602                              <1> 	; INPUT ->
  1603                              <1> 	; 	ESI = ASCIIZ Directory Name
  1604                              <1> 	;	CL = Directory Attributes
  1605                              <1> 	; OUTPUT ->
  1606                              <1> 	;	EAX = New sub dir's first cluster
  1607                              <1> 	;	ESI = Logical Dos Drv Descr. Table Addr.
  1608                              <1> 	;	CF = 1 -> error code in AL (EAX)
  1609                              <1> 
  1610                              <1> 	;test	cl, 10h  ; directory
  1611                              <1> 	;jz	short loc_make_directory_access_denied
  1612                              <1> 	;test	cl, 08h ; volume name
  1613                              <1> 	;jnz	short loc_make_directory_access_denied
  1614                              <1> 
  1615 0000AD09 80E107              <1> 	and	cl, 07h
  1616 0000AD0C 880D[FC860100]      <1> 	mov	byte [mkdir_attrib], cl
  1617                              <1> 
  1618 0000AD12 56                  <1> 	push	esi
  1619 0000AD13 31DB                <1> 	xor	ebx, ebx
  1620 0000AD15 8A3D[827D0100]      <1> 	mov	bh, [Current_Drv]
  1621 0000AD1B BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1622 0000AD20 01DE                <1> 	add	esi, ebx
  1623 0000AD22 5B                  <1> 	pop	ebx
  1624                              <1> 
  1625                              <1> 	; 10/07/2010 -> 1st writable disk check for trdos
  1626                              <1> 	; LD_DiskType = 0 for write protection (read only)
  1627 0000AD23 807E0101            <1> 	cmp	byte [esi+LD_DiskType], 1 ; 0 = Invalid
  1628 0000AD27 7308                <1> 	jnb	short loc_mkdir_check_file_sytem
  1629                              <1> 	; 16/10/2016 (13h -> 30)
  1630                              <1> 	;mov	eax, 30 ; 'Disk write-protected' error
  1631                              <1> 	;mov	edx, 0
  1632                              <1> 	; 29/07/2022
  1633 0000AD29 29C0                <1> 	sub	eax, eax
  1634 0000AD2B B01E                <1> 	mov	al, 30
  1635 0000AD2D 29D2                <1> 	sub	edx, edx ; 0
  1636 0000AD2F F9                  <1> 	stc
  1637                              <1> 	; err retn: EDX = 0, EBX = Dir name offset
  1638                              <1> 	;ESI = Logical DOS drive description table address
  1639 0000AD30 C3                  <1> 	retn
  1640                              <1> 
  1641                              <1> ;loc_make_directory_access_denied:
  1642                              <1> 	;mov	ax, 05h ; access denied (invalid attributes input)
  1643                              <1> 	;stc
  1644                              <1> 	;retn
  1645                              <1> 
  1646                              <1> loc_mkdir_check_file_sytem:
  1647 0000AD31 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  1648 0000AD35 730A                <1> 	jnb	short loc_mkdir_check_free_sectors
  1649                              <1> 
  1650                              <1> loc_make_fs_directory:
  1651 0000AD37 A1[7C7D0100]        <1> 	mov	eax, [Current_Dir_FCluster]
  1652                              <1> 
  1653                              <1> 	; EAX = Parent directory DDT Address
  1654                              <1> 	; ESI = Logical DOS Drive DT Address
  1655                              <1> 	; EBX = Directory name offset (as ASCIIZ name)
  1656                              <1> 
  1657                              <1> 	;call	make_fs_directory
  1658                              <1> 	;retn
  1659                              <1> 	; 29/07/2022
  1660 0000AD3C E9DE150000          <1> 	jmp	make_fs_directory
  1661                              <1> 
  1662                              <1> loc_mkdir_check_free_sectors:
  1663 0000AD41 0FB64613            <1>         movzx   eax, byte [esi+LD_BPB+SecPerClust]
  1664 0000AD45 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
  1665 0000AD48 39C1                <1> 	cmp	ecx, eax
  1666 0000AD4A 7254                <1> 	jb	short loc_mkdir_insufficient_disk_space
  1667                              <1> 
  1668                              <1> loc_make_fat_directory:
  1669 0000AD4C 891D[EC860100]      <1> 	mov	[mkdir_DirName_Offset], ebx
  1670 0000AD52 890D[F8860100]      <1> 	mov	[mkdir_FreeSectors], ecx
  1671                              <1> 
  1672                              <1> 	;mov	al, [esi+LD_BPB+SecPerClust]
  1673 0000AD58 A2[FE860100]        <1> 	mov	byte [mkdir_SecPerClust], al
  1674                              <1> 
  1675                              <1> loc_mkdir_gffc_1:
  1676 0000AD5D E8E0170000          <1> 	call	get_first_free_cluster
  1677 0000AD62 722A                <1> 	jc	short loc_mkdir_gffc_retn
  1678                              <1> 
  1679                              <1> ;loc_mkdir_gffc_1_cont: 
  1680                              <1> 	;cmp	eax, 2
  1681                              <1> 	;jb	short loc_mkdir_gffc_insufficient_disk_space
  1682                              <1> 
  1683                              <1> ;loc_mkdir_gffc_1_save_fcluster:  
  1684 0000AD64 A3[F0860100]        <1> 	mov	[mkdir_FFCluster], eax
  1685                              <1> 
  1686                              <1> loc_mkdir_locate_ffe:
  1687                              <1> 	; Current directory fcluster <> Directory buffer cluster
  1688                              <1> 	; Current directory will be reloaded by
  1689                              <1> 	; 'locate_current_dir_file' procedure
  1690                              <1> 	;
  1691                              <1> 	; ESI = Logical DOS Drive Description Table Address
  1692                              <1> 	;push	esi ; 27/02/2016
  1693 0000AD69 31C0                <1> 	xor	eax, eax
  1694 0000AD6B 89C1                <1>         mov	ecx, eax
  1695 0000AD6D 6649                <1> 	dec	cx ; FFFFh  
  1696                              <1> 	; CX = FFFFh -> find first deleted or free entry
  1697                              <1> 	; ESI would be ASCIIZ filename address if the call
  1698                              <1> 	; would not be for first free or deleted dir entry
  1699 0000AD6F E80FFBFFFF          <1> 	call	locate_current_dir_file
  1700 0000AD74 734A                <1> 	jnc	short loc_mkdir_set_ff_dir_entry_1
  1701                              <1> 	;pop	esi
  1702                              <1> 	; ESI = Logical DOS Drive Description Table Address
  1703 0000AD76 83F802              <1> 	cmp	eax, 2  ; cmp al, 2 ; File/Dir not found !
  1704 0000AD79 7529                <1> 	jne	short loc_mkdir_stc_return
  1705                              <1> 
  1706                              <1> loc_mkdir_add_new_cluster:
  1707 0000AD7B 3805[817D0100]      <1> 	cmp	byte [Current_FATType], al ; 2
  1708                              <1> 	;cmp	byte ptr [esi+LD_FATType], 2
  1709 0000AD81 770C                <1> 	ja	short loc_mkdir_add_new_cluster_check_fsc
  1710 0000AD83 803D[807D0100]01    <1> 	cmp	byte [Current_Dir_Level], 1
  1711                              <1> 	;cmp	byte [esi+LD_CDirLevel], 1
  1712 0000AD8A 7303                <1> 	jnb	short loc_mkdir_add_new_cluster_check_fsc
  1713                              <1> 
  1714 0000AD8C B00C                <1> 	mov	al, 12 ; No more files 
  1715                              <1> loc_mkdir_gffc_retn:
  1716 0000AD8E C3                  <1> 	retn
  1717                              <1> 
  1718                              <1> loc_mkdir_add_new_cluster_check_fsc:
  1719 0000AD8F 8B0D[F8860100]      <1> 	mov	ecx, [mkdir_FreeSectors]
  1720                              <1> 	;movzx	eax, byte [mkdir_SecPerClust]
  1721 0000AD95 A0[FE860100]        <1> 	mov	al, [mkdir_SecPerClust]
  1722                              <1> 	;shl	ax, 1 ; AX = 2 * AX
  1723                              <1> 	; 29/07/2022
  1724 0000AD9A D1E0                <1> 	shl	eax, 1
  1725 0000AD9C 39C1                <1> 	cmp	ecx, eax
  1726 0000AD9E 7350                <1> 	jnb	short loc_mkdir_add_new_subdir_cluster
  1727                              <1> 
  1728                              <1> loc_mkdir_insufficient_disk_space:
  1729                              <1> 	;mov	edx, ecx
  1730                              <1> ;loc_mkdir_gffc_insufficient_disk_space:
  1731                              <1> 	; 29/07/2022
  1732                              <1> 	;mov	ax, 27h ; MSDOS err => insufficient disk space
  1733                              <1> 
  1734                              <1> 	; err retn: EDX = Free sectors, EBX = Dir name offset
  1735                              <1>         ; ESI -> Dos drive description table address
  1736                              <1> 	;; ecx = edx
  1737                              <1> 
  1738                              <1> 	;retn
  1739                              <1> 
  1740                              <1> 	; 29/07/2022
  1741 0000ADA0 30E4                <1> 	xor	ah, ah
  1742 0000ADA2 B027                <1> 	mov	al, 27h
  1743                              <1> 
  1744                              <1> loc_mkdir_stc_return:
  1745 0000ADA4 F9                  <1> 	stc
  1746 0000ADA5 C3                  <1> 	retn
  1747                              <1> 
  1748                              <1> loc_mkdir_gffc_2:
  1749 0000ADA6 E897170000          <1> 	call	get_first_free_cluster
  1750 0000ADAB 72E1                <1> 	jc	short loc_mkdir_gffc_retn
  1751                              <1> 
  1752                              <1> ;loc_mkdir_gffc_1_cont:
  1753                              <1> 	;cmp	eax, 2
  1754                              <1> 	;jb	short loc_mkdir_gffc_insufficient_disk_space
  1755                              <1> 
  1756                              <1> ;loc_mkdir_gffc_2_save_fcluster:
  1757 0000ADAD A3[F0860100]        <1> 	mov	[mkdir_FFCluster], eax
  1758                              <1> 
  1759 0000ADB2 A1[F4860100]        <1> 	mov	eax, [mkdir_LastDirCluster]
  1760                              <1> 
  1761 0000ADB7 E820170000          <1> 	call	load_FAT_sub_directory
  1762 0000ADBC 72D0                <1> 	jc	short loc_mkdir_gffc_retn
  1763                              <1> 
  1764 0000ADBE 31FF                <1> 	xor	edi, edi
  1765                              <1> loc_mkdir_set_ff_dir_entry_1:
  1766                              <1> 	; 27/02/2016
  1767 0000ADC0 56                  <1> 	push	esi ; Logical DOS Drv Desc. Tbl. address
  1768                              <1> 	; EDI = Directory Entry Address
  1769 0000ADC1 8B35[EC860100]      <1> 	mov	esi, [mkdir_DirName_Offset]
  1770 0000ADC7 A1[F0860100]        <1> 	mov	eax, [mkdir_FFCluster]
  1771                              <1> 
  1772 0000ADCC 66B91000            <1> 	mov	cx, 10h	; CL = Directory attribute
  1773                              <1> 			; CH = 0 -> File size is 0
  1774 0000ADD0 0A0D[FC860100]      <1> 	or	cl, [mkdir_attrib] ; S, H, R
  1775 0000ADD6 E8A3010000          <1> 	call	make_directory_entry
  1776                              <1> 
  1777 0000ADDB 5E                  <1> 	pop	esi
  1778                              <1> 
  1779 0000ADDC C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  1780 0000ADE3 E869020000          <1> 	call	save_directory_buffer
  1781                              <1>         ;jnc	loc_mkdir_set_ff_dir_entry_2
  1782                              <1> 	; 29/07/2022
  1783 0000ADE8 7205                <1> 	jc	short loc_mkdir_return
  1784 0000ADEA E9CA000000          <1> 	jmp	loc_mkdir_set_ff_dir_entry_2
  1785                              <1> 
  1786                              <1> loc_mkdir_return:
  1787 0000ADEF C3                  <1> 	retn
  1788                              <1> 
  1789                              <1> loc_mkdir_add_new_subdir_cluster:
  1790 0000ADF0 8B15[AE840100]      <1> 	mov	edx, [DirBuff_Cluster]
  1791 0000ADF6 8915[F4860100]      <1> 	mov	[mkdir_LastDirCluster], edx
  1792                              <1> 
  1793 0000ADFC A1[F0860100]        <1> 	mov	eax, [mkdir_FFCluster]
  1794 0000AE01 E8D6160000          <1> 	call	load_FAT_sub_directory
  1795 0000AE06 72E7                <1> 	jc	short loc_mkdir_return
  1796                              <1> 	; eax = 0
  1797                              <1> 	; ecx = directory buffer sector count (<= 128)
  1798                              <1> 
  1799                              <1> pass_mkdir_add_new_subdir_cluster:
  1800                              <1> 
  1801                              <1> ; 29/07/2022
  1802                              <1> ;	;sub	edi, edi ; 0
  1803                              <1> ;	; 29/07/2022 - BUGFIX !
  1804                              <1> ;	mov	edi, Directory_Buffer
  1805                              <1> ;
  1806                              <1> ;	;mov	al, 128 ; double word
  1807                              <1> ;	;mul	ecx ; ecx =  directory buffer sector count
  1808                              <1> ;	;mov	ecx, eax
  1809                              <1> ;	;shl	cx, 7 ; 128 * sector count
  1810                              <1> ;	mov	ax, [esi+LD_BPB+BytesPerSec] ; 512
  1811                              <1> ;	;shr	ax, 2 ; 'byte count / 4' for 'stosd'
  1812                              <1> ;	; 29/07/2022
  1813                              <1> ;	shr	eax, 2
  1814                              <1> ;	;mul	cx ; max = 128*(512/4) -> 16384 (stosd)
  1815                              <1> ;	;mov	cx, ax
  1816                              <1> ;	;sub	ax, ax ; 0
  1817                              <1> ;	; 29/07/2022
  1818                              <1> ;	mul	ecx
  1819                              <1> ;	mov	ecx, eax
  1820                              <1> ;	sub	eax, eax
  1821                              <1> ;	rep	stosd ; clear directory buffer
  1822                              <1> 
  1823                              <1> 	; 29/07/2022
  1824 0000AE08 E85C010000          <1> 	call	clear_directory_buffer
  1825                              <1> 
  1826 0000AE0D C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  1827 0000AE14 E838020000          <1> 	call	save_directory_buffer 
  1828 0000AE19 72D4                <1> 	jc	short loc_mkdir_return
  1829                              <1> 
  1830                              <1> loc_mkdir_save_added_cluster:
  1831 0000AE1B A1[F4860100]        <1> 	mov	eax, [mkdir_LastDirCluster]
  1832 0000AE20 8B0D[F0860100]      <1> 	mov	ecx, [mkdir_FFCluster]
  1833                              <1> 	; 01/03/2016
  1834 0000AE26 31D2                <1> 	xor	edx, edx
  1835 0000AE28 8915[9E840100]      <1> 	mov	[FAT_ClusterCounter], edx ; 0 ; reset
  1836 0000AE2E E8DC170000          <1> 	call	update_cluster
  1837 0000AE33 7304                <1> 	jnc	short loc_mkdir_save_fat_buffer_0
  1838 0000AE35 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  1839 0000AE37 7518                <1> 	jnz	short loc_mkdir_save_fat_buffer_stc_retn
  1840                              <1> 
  1841                              <1> loc_mkdir_save_fat_buffer_0:
  1842 0000AE39 A1[F0860100]        <1> 	mov	eax, [mkdir_FFCluster]
  1843 0000AE3E A3[F4860100]        <1> 	mov	[mkdir_LastDirCluster], eax
  1844                              <1> 
  1845 0000AE43 31C9                <1> 	xor	ecx, ecx
  1846 0000AE45 49                  <1> 	dec	ecx ; FFFFFFFFh
  1847                              <1> 	; ESI = Logical DOS Drive Description Table address
  1848 0000AE46 E8C4170000          <1> 	call	update_cluster
  1849 0000AE4B 731A                <1> 	jnc	short loc_mkdir_save_fat_buffer_1
  1850 0000AE4D 09C0                <1> 	or	eax, eax
  1851 0000AE4F 7416                <1> 	jz	short loc_mkdir_save_fat_buffer_1
  1852                              <1> 
  1853                              <1> loc_mkdir_save_fat_buffer_stc_retn:
  1854                              <1> 	; 01/03/2016
  1855 0000AE51 803D[9E840100]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
  1856 0000AE58 720C                <1> 	jb	short loc_mkdir_save_fat_buffer_retn
  1857                              <1> 
  1858 0000AE5A 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space (BL = 0)
  1859                              <1> 			   ; (BH = FFh -> Use ESI as Drv Param. Tbl.)
  1860 0000AE5E 50                  <1> 	push	eax
  1861 0000AE5F E8B01A0000          <1> 	call	calculate_fat_freespace
  1862 0000AE64 58                  <1> 	pop	eax
  1863 0000AE65 F9                  <1> 	stc
  1864                              <1> loc_mkdir_save_fat_buffer_retn:
  1865 0000AE66 C3                  <1> 	retn
  1866                              <1> 
  1867                              <1> loc_mkdir_save_fat_buffer_1:
  1868                              <1> 	; byte [FAT_BuffValidData] = 2
  1869 0000AE67 E8171A0000          <1> 	call	save_fat_buffer
  1870 0000AE6C 72E3                <1> 	jc	short loc_mkdir_save_fat_buffer_stc_retn
  1871                              <1> 
  1872                              <1> 	; 01/03/2016
  1873 0000AE6E 803D[9E840100]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
  1874 0000AE75 721B                <1> 	jb	short loc_mkdir_save_fat_buffer_2
  1875                              <1> 
  1876                              <1> 	; ESI = Logical DOS Drive Description Table address
  1877 0000AE77 A1[9E840100]        <1> 	mov	eax, [FAT_ClusterCounter]
  1878 0000AE7C 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters
  1879 0000AE80 E88F1A0000          <1> 	call	calculate_fat_freespace
  1880                              <1> 
  1881                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
  1882                              <1> 	;jnz	short loc_mkdir_save_fat_buffer_2
  1883                              <1> 
  1884                              <1> 	; ecx > 0 -> Recalculation is needed
  1885 0000AE85 09C9                <1> 	or	ecx, ecx 
  1886 0000AE87 7409                <1> 	jz	short loc_mkdir_save_fat_buffer_2
  1887                              <1> 
  1888 0000AE89 66BB00FF            <1> 	mov	bx, 0FF00h ; ; recalculate free space
  1889 0000AE8D E8821A0000          <1> 	call	calculate_fat_freespace
  1890                              <1> 
  1891                              <1> loc_mkdir_save_fat_buffer_2:
  1892 0000AE92 C605[FF860100]01    <1> 	mov	byte [mkdir_add_new_cluster], 1
  1893 0000AE99 E9B0000000          <1> 	jmp	loc_mkdir_upd_parent_dir_lmdt
  1894                              <1> 
  1895                              <1> loc_mkdir_update_sub_dir_cluster:
  1896 0000AE9E A1[F0860100]        <1> 	mov	eax, [mkdir_FFCluster]
  1897 0000AEA3 29C9                <1> 	sub	ecx, ecx ; 0
  1898                              <1> 	; 01/03/2016
  1899 0000AEA5 890D[9E840100]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; Reset
  1900 0000AEAB 49                  <1> 	dec	ecx ; 0FFFFFFFFh
  1901                              <1> 
  1902                              <1> 	; ESI = Logical DOS Drive Descisption Table address
  1903 0000AEAC E85E170000          <1> 	call	update_cluster
  1904 0000AEB1 7364                <1> 	jnc	short loc_mkdir_save_fat_buffer_3
  1905 0000AEB3 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  1906 0000AEB5 7460                <1> 	jz	short loc_mkdir_save_fat_buffer_3
  1907                              <1> 	; 01/03/2016
  1908 0000AEB7 EB98                <1> 	jmp	short loc_mkdir_save_fat_buffer_stc_retn
  1909                              <1> 
  1910                              <1> loc_mkdir_set_ff_dir_entry_2:
  1911                              <1> 	; ESI = Logical DOS Drive Description Table address
  1912 0000AEB9 A1[F0860100]        <1> 	mov	eax, [mkdir_FFCluster]
  1913                              <1> 	; Load disk sectors as a directory cluster
  1914 0000AEBE E819160000          <1> 	call	load_FAT_sub_directory
  1915 0000AEC3 7251                <1> 	jc	short retn_make_fat_directory
  1916                              <1> 
  1917                              <1> 	; eax = 0
  1918                              <1> 	; ecx = directory buffer sector count (<= 128)
  1919                              <1> 
  1920                              <1> ; 29/07/2022
  1921                              <1> ;	mov	edi, Directory_Buffer + 64 ; 26/02/2016
  1922                              <1> ;
  1923                              <1> ;	; 02/03/2016
  1924                              <1> ;	mov	ax, [esi+LD_BPB+BytesPerSec] ; 512
  1925                              <1> ;	;shr	ax, 2 ; 'byte count / 4' for 'stosd'
  1926                              <1> ;	; 29/07/2022
  1927                              <1> ;	shr	eax, 2
  1928                              <1> ;	mul 	ecx
  1929                              <1> ;	mov	ecx, eax
  1930                              <1> ;	;
  1931                              <1> ;	; 29/07/2022 - BUGFIX !
  1932                              <1> ;	sub	ecx, 16 ; - 64 bytes
  1933                              <1> ;			; (space for '.' & '..' entries)
  1934                              <1> ;	;sub	ax, ax
  1935                              <1> ;	sub	eax, eax
  1936                              <1> ;	rep	stosd
  1937                              <1> ;
  1938                              <1> ;	;;mov	al, 128 ; double word (count in sector)
  1939                              <1> ;	;;mul	ecx ; ecx = directory buffer sector count
  1940                              <1> ;	;;mov	ecx, eax
  1941                              <1> ;	;shl	cx, 7 ; 128 * sector count
  1942                              <1> ;	;sub	ecx, 64 ; 29/07/2022
  1943                              <1> ;	;;sub	eax, eax
  1944                              <1> ;	;;sub	al, al ; 0
  1945                              <1> ;	;rep	stosd ; clear directory buffer
  1946                              <1> 
  1947                              <1> 	; 29/07/2022
  1948 0000AEC5 E89F000000          <1> 	call	clear_directory_buffer
  1949                              <1> 
  1950 0000AECA BF00000800          <1> 	mov	edi, Directory_Buffer ; 26/02/2016
  1951                              <1> 
  1952 0000AECF 56                  <1> 	push	esi
  1953                              <1> 
  1954 0000AED0 BE[00870100]        <1> 	mov	esi, mkdir_Name
  1955 0000AED5 66C7062E00          <1> 	mov	word [esi], 2Eh ; db '.', '0'
  1956                              <1> 
  1957 0000AEDA A1[F0860100]        <1> 	mov	eax, [mkdir_FFCluster]
  1958                              <1> 	;mov	cx, 10h ; CL = Directory attribute
  1959                              <1> 			; CH = 0 -> File size is 0
  1960                              <1> 	; 29/07/2022
  1961 0000AEDF B110                <1> 	mov	cl, 10h
  1962 0000AEE1 E898000000          <1> 	call	make_directory_entry
  1963                              <1> 
  1964 0000AEE6 BF20000800          <1> 	mov	edi, Directory_Buffer + 32 ; 26/02/2016
  1965                              <1> 
  1966                              <1> 	; 03/03/2016
  1967                              <1> 	; Following modification has been done according to
  1968                              <1> 	; 'Microsoft Extensible Firmware Initiative
  1969                              <1> 	; FAT32 File System Specification' document,
  1970                              <1> 	; 'FAT: General Overview of On-Disk FormatPage 25'.
  1971                              <1> 	; "Finally, you set DIR_FstClusLO and DIR_FstClusHI
  1972                              <1> 	; for the dotdot entry (the second entry) to the
  1973                              <1> 	; first cluster number of the directory in which you
  1974                              <1> 	; just created the directory (value is 0 if this directory
  1975                              <1> 	; is the root directory even for FAT32 volumes)."
  1976                              <1> 	; (Correctness of this modification has been verified
  1977                              <1> 	;  by using Windows 98 'scandisk.exe'.)
  1978                              <1> 
  1979 0000AEEB 29C0                <1> 	sub	eax, eax
  1980 0000AEED 3805[807D0100]      <1> 	cmp	byte [Current_Dir_Level], al ; 0
  1981 0000AEF3 7605                <1> 	jna	short loc_mkdir_set_ff_dir_entry_3
  1982 0000AEF5 A1[7C7D0100]        <1> 	mov	eax, [Current_Dir_FCluster] ; parent dir
  1983                              <1> loc_mkdir_set_ff_dir_entry_3:
  1984 0000AEFA 66C746012E00        <1> 	mov	word [esi+1], 2Eh ; db '.', '0'
  1985                              <1> 
  1986                              <1> 	;mov	cx, 10h
  1987 0000AF00 E879000000          <1> 	call	make_directory_entry
  1988                              <1> 
  1989 0000AF05 5E                  <1> 	pop	esi
  1990                              <1> 
  1991 0000AF06 C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  1992 0000AF0D E83F010000          <1> 	call	save_directory_buffer
  1993                              <1> 	;jnc	loc_mkdir_update_sub_dir_cluster
  1994                              <1> 	; 29/07/2022
  1995 0000AF12 7202                <1> 	jc	short retn_make_fat_directory
  1996 0000AF14 EB88                <1> 	jmp	loc_mkdir_update_sub_dir_cluster
  1997                              <1> 
  1998                              <1> retn_make_fat_directory:
  1999 0000AF16 C3                  <1> 	retn
  2000                              <1> 
  2001                              <1> loc_mkdir_save_fat_buffer_3:
  2002                              <1> 	; 01/03/2016
  2003                              <1> 	; byte [FAT_BuffValidData] = 2
  2004 0000AF17 E867190000          <1> 	call	save_fat_buffer
  2005                              <1> 	;jc	short loc_mkdir_save_fat_buffer_stc_retn
  2006                              <1> 	; 07/08/2022
  2007 0000AF1C 7305                <1> 	jnc	short loc_mkdir_save_fat_buffer_4
  2008 0000AF1E E92EFFFFFF          <1> 	jmp	loc_mkdir_save_fat_buffer_stc_retn
  2009                              <1> 
  2010                              <1> loc_mkdir_save_fat_buffer_4:
  2011 0000AF23 803D[9E840100]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
  2012 0000AF2A 721B                <1> 	jb	short loc_mkdir_save_fat_buffer_5
  2013                              <1> 
  2014                              <1> 	; ESI = Logical DOS Drive Description Table address
  2015 0000AF2C A1[9E840100]        <1> 	mov	eax, [FAT_ClusterCounter]
  2016 0000AF31 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters
  2017 0000AF35 E8DA190000          <1> 	call	calculate_fat_freespace
  2018                              <1> 
  2019                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
  2020                              <1>         ;jnz    short loc_mkdir_save_fat_buffer_5
  2021                              <1> 
  2022                              <1> 	; ecx > 0 -> Recalculation is needed
  2023 0000AF3A 09C9                <1> 	or	ecx, ecx
  2024 0000AF3C 7409                <1>         jz      short loc_mkdir_save_fat_buffer_5
  2025                              <1> 
  2026 0000AF3E 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space
  2027 0000AF42 E8CD190000          <1> 	call	calculate_fat_freespace
  2028                              <1> 
  2029                              <1> loc_mkdir_save_fat_buffer_5:
  2030 0000AF47 C605[FF860100]00    <1> 	mov	byte [mkdir_add_new_cluster], 0
  2031                              <1> 
  2032                              <1> loc_mkdir_upd_parent_dir_lmdt:
  2033 0000AF4E E896010000          <1> 	call	update_parent_dir_lmdt
  2034                              <1> 
  2035                              <1> 	; 01/03/2016
  2036 0000AF53 803D[FF860100]00    <1> 	cmp	byte [mkdir_add_new_cluster], 0
  2037                              <1> 	;ja	loc_mkdir_gffc_2
  2038                              <1> 	; 29/07/2022
  2039 0000AF5A 7605                <1> 	jna	short loc_mkdir_retn_new_dir_cluster
  2040 0000AF5C E945FEFFFF          <1> 	jmp	loc_mkdir_gffc_2
  2041                              <1> 
  2042                              <1> loc_mkdir_retn_new_dir_cluster:
  2043 0000AF61 A1[F0860100]        <1> 	mov	eax, [mkdir_FFCluster]
  2044 0000AF66 31D2                <1> 	xor	edx, edx
  2045                              <1> loc_mkdir_retn:
  2046 0000AF68 C3                  <1> 	retn
  2047                              <1> 
  2048                              <1> clear_directory_buffer:
  2049                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  2050                              <1> 	;
  2051                              <1> 	; eax = 0
  2052                              <1> 	; ecx = directory buffer sector count (<= 128)
  2053                              <1> 	;
  2054 0000AF69 BF00000800          <1> 	mov	edi, Directory_Buffer
  2055                              <1> 	;mov	al, 128 ; double word
  2056                              <1> 	;mul	ecx ; ecx = directory buffer sector count
  2057                              <1> 	;mov	ecx, eax
  2058                              <1> 	;shl	cx, 7 ; 128 * sector count
  2059 0000AF6E 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec] ; 512
  2060 0000AF72 C1E802              <1> 	shr	eax, 2 ; 'byte count / 4' for 'stosd'
  2061 0000AF75 F7E1                <1> 	mul	ecx ; max = 128*(512/4) -> 16384 (stosd)
  2062 0000AF77 89C1                <1> 	mov	ecx, eax
  2063 0000AF79 29C0                <1> 	sub	eax, eax
  2064 0000AF7B F3AB                <1> 	rep	stosd ; clear directory buffer
  2065 0000AF7D C3                  <1> 	retn
  2066                              <1> 
  2067                              <1> make_directory_entry:
  2068                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  2069                              <1> 	; 02/03/2016
  2070                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
  2071                              <1> 	; 09/08/2010 (DIR.ASM, 'proc_make_directory_entry')
  2072                              <1> 	; 17/07/2010
  2073                              <1> 	; INPUT ->
  2074                              <1> 	; 	EDI = Directory Entry Address
  2075                              <1> 	;	ESI = Dot File Name Location
  2076                              <1> 	;	EAX = First Cluster
  2077                              <1> 	;	File Size = 0 (Must be set later)
  2078                              <1> 	;	CL = Attributes
  2079                              <1> 	;	CH = 0 (File size = 0)
  2080                              <1> 	;	(If CH>0, File size is in dword [EBX]) (*)
  2081                              <1> 	; OUTPUT ->
  2082                              <1> 	;	EDI = Directory Entry Address
  2083                              <1> 	;	ESI = Dot File Name Location (Capitalized)
  2084                              <1> 	;	If CH input = 0, File Size = 0
  2085                              <1> 	;	Otherwise file size is as dword [EBX] (*)
  2086                              <1> 	;	DX = Date, AX = Time in DOS Dir Entry format
  2087                              <1> 	;	EBX = same
  2088                              <1> 	;	ECX = same
  2089                              <1> 
  2090 0000AF7E 51                  <1> 	push	ecx
  2091                              <1> 
  2092 0000AF7F 884F0B              <1> 	mov	[edi+11], cl ; Attributes
  2093 0000AF82 6689471A            <1> 	mov	[edi+26], ax ; FClusterLw, 26
  2094 0000AF86 C1E810              <1> 	shr	eax, 16
  2095 0000AF89 66894714            <1> 	mov	[edi+20], ax ; FClusterHw, 20
  2096                              <1> 	;xor	ax, ax
  2097                              <1> 	; 29/07/2022
  2098 0000AF8D 31C0                <1> 	xor	eax, eax
  2099 0000AF8F 6689470C            <1> 	mov	[edi+12], ax ; NTReserved, 12
  2100                              <1> 			     ; CrtTimeTenth, 13
  2101 0000AF93 08ED                <1> 	or	ch, ch
  2102 0000AF95 7402                <1> 	jz	short loc_make_direntry_set_filesize
  2103                              <1> 
  2104 0000AF97 8B03                <1> 	mov	eax, [ebx]
  2105                              <1> 
  2106                              <1> loc_make_direntry_set_filesize:
  2107 0000AF99 89471C              <1> 	mov	[edi+28], eax ; FileSize, 28
  2108                              <1> 
  2109 0000AF9C E8AFFBFFFF          <1> 	call	convert_file_name
  2110                              <1> 	; EDI = Dir Entry Format File Name Location
  2111                              <1> 	; ESI = Dot File Name Location (capitalized)
  2112                              <1> 
  2113 0000AFA1 E816000000          <1> 	call	convert_current_date_time
  2114                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
  2115                              <1>         ; 	    AX = Time in dos dir entry format
  2116 0000AFA6 6689470E            <1> 	mov	[edi+14], ax ; CrtTime, 14
  2117 0000AFAA 66895710            <1> 	mov	[edi+16], dx ; CrtDate, 16
  2118 0000AFAE 66895712            <1> 	mov	[edi+18], dx ; LastAccDate, 18
  2119 0000AFB2 66894716            <1> 	mov	[edi+22], ax ; WrtTime, 14
  2120 0000AFB6 66895718            <1> 	mov	[edi+24], dx ; WrtDate, 16
  2121 0000AFBA 59                  <1> 	pop	ecx
  2122                              <1> 
  2123 0000AFBB C3                  <1> 	retn
  2124                              <1> 
  2125                              <1> convert_current_date_time:
  2126                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  2127                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
  2128                              <1> 	; 13/06/2010 (DIR.ASM, 'proc_convert_current_date_time')
  2129                              <1> 	; converts date&time to dos dir entry format
  2130                              <1> 	; INPUT -> none
  2131                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
  2132                              <1> 	;           AX = Time in dos dir entry format
  2133                              <1> 
  2134 0000AFBC B404                <1> 	mov	ah, 04h ; Return Current Date
  2135 0000AFBE E8D4B2FFFF          <1> 	call	int1Ah
  2136                              <1> 
  2137 0000AFC3 88E8                <1> 	mov	al, ch ; <- century BCD
  2138 0000AFC5 240F                <1> 	and	al, 0Fh
  2139 0000AFC7 88EC                <1> 	mov	ah, ch
  2140 0000AFC9 C0EC04              <1> 	shr	ah, 4
  2141 0000AFCC D50A                <1> 	aad
  2142 0000AFCE 88C5                <1> 	mov	ch, al ; -> century
  2143                              <1> 
  2144 0000AFD0 88C8                <1> 	mov	al, cl ; <- year BCD
  2145 0000AFD2 240F                <1> 	and	al, 0Fh
  2146 0000AFD4 88CC                <1> 	mov	ah, cl
  2147 0000AFD6 C0EC04              <1> 	shr	ah, 4
  2148 0000AFD9 D50A                <1> 	aad
  2149 0000AFDB 88C1                <1> 	mov	cl, al ; -> year
  2150                              <1> 
  2151                              <1> 	;mov	al, ch
  2152                              <1> 	;mov	ah, 100
  2153                              <1> 	;mul	ah
  2154                              <1> 	; 29/07/2022
  2155 0000AFDD B064                <1> 	mov	al, 100
  2156 0000AFDF F6E5                <1> 	mul	ch
  2157                              <1> 
  2158                              <1> 	;xor	ch, ch
  2159                              <1> 	;add	ax, cx
  2160                              <1> 	; 29/07/2022
  2161 0000AFE1 00C8                <1> 	add	al, cl
  2162 0000AFE3 80D400              <1> 	adc	ah, 0
  2163 0000AFE6 662DBC07            <1> 	sub	ax, 1980 ; ms-dos epoch
  2164                              <1> 	;mov	cx, ax
  2165                              <1> 	; 29/07/2022
  2166 0000AFEA 88C1                <1> 	mov	cl, al
  2167                              <1> 	;mov	ecx, eax
  2168                              <1> 
  2169 0000AFEC 88F0                <1> 	mov	al, dh ; <- month in bcd
  2170 0000AFEE 240F                <1> 	and	al, 0Fh
  2171 0000AFF0 88F4                <1> 	mov	ah, dh
  2172 0000AFF2 C0EC04              <1> 	shr	ah, 4
  2173 0000AFF5 D50A                <1> 	aad
  2174 0000AFF7 88C6                <1> 	mov	dh, al ; -> month
  2175                              <1> 
  2176 0000AFF9 88D0                <1> 	mov	al, dl ; <- day BCD
  2177 0000AFFB 240F                <1> 	and	al, 0Fh
  2178 0000AFFD 88D4                <1> 	mov	ah, dl
  2179 0000AFFF C0EC04              <1> 	shr	ah, 4
  2180 0000B002 D50A                <1> 	aad
  2181 0000B004 88C2                <1> 	mov	dl, al ; -> day
  2182                              <1> 
  2183 0000B006 88C8                <1> 	mov	al, cl ; count of years from 1980
  2184                              <1> 	;shl	ax, 4
  2185                              <1> 	; 29/07/2022
  2186                              <1> 	;mov	eax, ecx
  2187 0000B008 C1E004              <1> 	shl	eax, 4
  2188                              <1> 
  2189 0000B00B 08F0                <1> 	or	al, dh ; month of year, 1 to 12
  2190                              <1> 	;shl	ax, 5
  2191                              <1> 	; 29/07/2022
  2192 0000B00D C1E005              <1> 	shl	eax, 5
  2193 0000B010 08D0                <1> 	or	al, dl ; day of year, 1 to 31
  2194                              <1> 
  2195                              <1> 	;push	ax ; push date
  2196                              <1> 	; 29/07/2022
  2197 0000B012 50                  <1> 	push	eax
  2198                              <1> 
  2199 0000B013 B402                <1> 	mov	ah, 02h ; Return Current Time
  2200 0000B015 E87DB2FFFF          <1> 	call	int1Ah
  2201                              <1> 
  2202 0000B01A 88E8                <1> 	mov	al, ch ; <- hours BCD
  2203 0000B01C 240F                <1> 	and	al, 0Fh
  2204 0000B01E 88EC                <1> 	mov	ah, ch
  2205 0000B020 C0EC04              <1> 	shr	ah, 4
  2206 0000B023 D50A                <1> 	aad
  2207 0000B025 88C5                <1> 	mov	ch, al ; -> hours
  2208                              <1> 
  2209 0000B027 88C8                <1> 	mov	al, cl ; <- minutes BCD
  2210 0000B029 240F                <1> 	and	al, 0Fh
  2211 0000B02B 88CC                <1> 	mov	ah, cl
  2212 0000B02D C0EC04              <1> 	shr	ah, 4
  2213 0000B030 D50A                <1> 	aad
  2214 0000B032 88C1                <1> 	mov	cl, al ; -> minutes
  2215                              <1> 
  2216 0000B034 88F0                <1> 	mov	al, dh ; <- seconds BCD
  2217 0000B036 240F                <1> 	and	al, 0Fh
  2218 0000B038 88F4                <1> 	mov	ah, dh
  2219 0000B03A C0EC04              <1> 	shr	ah, 4
  2220 0000B03D D50A                <1> 	aad
  2221 0000B03F 88C6                <1> 	mov	dh, al ; -> seconds
  2222                              <1> 
  2223 0000B041 88E8                <1> 	mov	al, ch ; hours
  2224                              <1> 	;shl	ax, 6
  2225                              <1> 	; 29/07/2022
  2226 0000B043 C1E006              <1> 	shl	eax, 6
  2227 0000B046 08C8                <1> 	or	al, cl ; minutes
  2228                              <1> 	;shl	ax, 5
  2229                              <1> 	; 29/07/2022
  2230 0000B048 C1E005              <1> 	shl	eax, 5
  2231 0000B04B D0EE                <1> 	shr	dh, 1 ; 2 seconds
  2232                              <1> 	; There is a bug in TRDOS v1 here !
  2233                              <1> 	; it was 'or al, dl' !
  2234 0000B04D 08F0                <1> 	or	al, dh ; seconds
  2235                              <1> 
  2236                              <1> 	;pop	dx ; pop date
  2237                              <1> 	; 29/07/2022
  2238 0000B04F 5A                  <1> 	pop	edx
  2239                              <1> 
  2240 0000B050 C3                  <1> 	retn
  2241                              <1> 
  2242                              <1> save_directory_buffer:
  2243                              <1> 	; 30/07/2022
  2244                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  2245                              <1> 	; 15/10/2016
  2246                              <1> 	; 23/03/2016
  2247                              <1> 	; 26/02/2016
  2248                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
  2249                              <1> 	; 01/08/2011
  2250                              <1> 	; 14/03/2010
  2251                              <1> 	; INPUT ->
  2252                              <1> 	; 	 none
  2253                              <1> 	; OUTPUT ->
  2254                              <1> 	;  cf = 0 -> write OK...
  2255                              <1> 	;  cf = 1 -> error code in AL (EAX)
  2256                              <1> 	;  cf = 1 & AL = 0Dh => CH & CL = FS & FAT type
  2257                              <1> 	;  EBX = Directory Buffer Address
  2258                              <1> 	;
  2259                              <1> 	;  (EAX, ECX, EDX will be modified)
  2260                              <1> 
  2261 0000B051 BB00000800          <1> 	mov	ebx, Directory_Buffer
  2262 0000B056 803D[A9840100]02    <1> 	cmp	byte [DirBuff_ValidData], 2
  2263 0000B05D 7403                <1> 	je	short loc_save_dir_buffer
  2264 0000B05F 31C0                <1> 	xor	eax, eax
  2265 0000B061 C3                  <1> 	retn
  2266                              <1> 
  2267                              <1> loc_save_dir_buffer:
  2268 0000B062 56                  <1> 	push	esi
  2269 0000B063 31DB                <1> 	xor	ebx, ebx
  2270 0000B065 8A3D[A7840100]      <1>         mov     bh, [DirBuff_DRV]
  2271 0000B06B 80EF41              <1> 	sub	bh, 'A'
  2272 0000B06E BE00010900          <1>         mov     esi, Logical_DOSDisks
  2273 0000B073 01DE                <1> 	add	esi, ebx
  2274 0000B075 668B4E03            <1>         mov     cx, [esi+LD_FATType]
  2275                              <1> 	; CH = FS Type (A1h for FS)
  2276                              <1> 	; CL = FAT Type (0 for FS)
  2277 0000B079 08C9                <1> 	or	cl, cl
  2278 0000B07B 7431                <1> 	jz	short loc_save_dir_buff_stc_retn
  2279                              <1> 
  2280                              <1> loc_save_dir_buffer_check_cluster_no:
  2281 0000B07D A1[AE840100]        <1> 	mov	eax, [DirBuff_Cluster]
  2282 0000B082 28FF                <1> 	sub	bh, bh ; ebx = 0
  2283 0000B084 09C0                <1> 	or	eax, eax
  2284 0000B086 753E                <1> 	jnz	short loc_save_sub_dir_buffer
  2285 0000B088 8A25[A8840100]      <1> 	mov	ah, [DirBuff_FATType]
  2286 0000B08E FEC3                <1> 	inc	bl ;  bl = 1
  2287 0000B090 38DC                <1> 	cmp	ah, bl
  2288 0000B092 721B                <1> 	jb	short loc_save_dir_buff_inv_data_retn
  2289 0000B094 FEC3                <1> 	inc	bl ; bl = 2
  2290 0000B096 38E3                <1> 	cmp	bl, ah
  2291 0000B098 7215                <1> 	jb	short loc_save_dir_buff_inv_data_retn
  2292                              <1> 
  2293                              <1> loc_save_root_dir_buffer:
  2294 0000B09A 668B5E17            <1> 	mov	bx, [esi+LD_BPB+RootDirEnts]
  2295 0000B09E 6683C30F            <1> 	add	bx, 15
  2296                              <1> 	;shr	bx, 4 ; 16 dir entries per sector
  2297                              <1> 	; 29/07/2022
  2298 0000B0A2 C1EB04              <1> 	shr	ebx, 4
  2299                              <1> 	;or	bx, bx
  2300 0000B0A5 09DB                <1> 	or	ebx, ebx
  2301 0000B0A7 7405                <1> 	jz	short loc_save_dir_buff_stc_retn
  2302                              <1> 	;mov	ecx, ebx
  2303 0000B0A9 8B4664              <1> 	mov	eax, [esi+LD_ROOTBegin] ; 26/02/2016
  2304 0000B0AC EB22                <1> 	jmp	short loc_write_directory_to_disk
  2305                              <1> 
  2306                              <1> loc_save_dir_buff_stc_retn:
  2307 0000B0AE F9                  <1> 	stc
  2308                              <1> loc_save_dir_buff_inv_data_retn:
  2309                              <1> 	; 15/10/2016 (0Dh -> 29)
  2310 0000B0AF B01D                <1> 	mov	al, 29 ; Invalid data !
  2311 0000B0B1 C605[A9840100]00    <1> 	mov	byte [DirBuff_ValidData], 0
  2312 0000B0B8 EB05                <1> 	jmp	short loc_save_dir_buff_retn
  2313                              <1> 
  2314                              <1> loc_write_directory_to_disk_err:
  2315                              <1> 	; 15/10/2016 (disk write error code, 1Dh -> 18)
  2316 0000B0BA B812000000          <1> 	mov	eax, 18 ; Drive not ready or write error
  2317                              <1> 
  2318                              <1> loc_save_dir_buff_retn:
  2319 0000B0BF BB00000800          <1> 	mov	ebx, Directory_Buffer
  2320 0000B0C4 5E                  <1> 	pop	esi
  2321 0000B0C5 C3                  <1> 	retn
  2322                              <1> 
  2323                              <1> loc_save_sub_dir_buffer:
  2324                              <1> 	; ebx  = 0
  2325                              <1> 	;sub	eax, 2
  2326                              <1> 	; 30/07/2022
  2327 0000B0C6 48                  <1> 	dec	eax
  2328 0000B0C7 48                  <1> 	dec	eax
  2329 0000B0C8 8A5E13              <1> 	mov	bl, [esi+LD_BPB+SecPerClust]
  2330 0000B0CB F7E3                <1> 	mul	ebx
  2331 0000B0CD 034668              <1>         add     eax, [esi+LD_DATABegin]
  2332                              <1>  	;mov	ecx, ebx
  2333                              <1> 
  2334                              <1> loc_write_directory_to_disk:
  2335 0000B0D0 89D9                <1>  	mov	ecx, ebx
  2336 0000B0D2 BB00000800          <1> 	mov	ebx, Directory_Buffer
  2337 0000B0D7 E8156F0000          <1> 	call	disk_write
  2338 0000B0DC 72DC                <1> 	jc	short loc_write_directory_to_disk_err
  2339                              <1> 
  2340                              <1> loc_save_dir_buff_validate_retn:
  2341 0000B0DE C605[A9840100]01    <1> 	mov	byte [DirBuff_ValidData], 1
  2342 0000B0E5 31C0                <1> 	xor	eax, eax
  2343                              <1> 	; 26/02/2016
  2344 0000B0E7 EBD6                <1> 	jmp	short loc_save_dir_buff_retn
  2345                              <1> 
  2346                              <1> update_parent_dir_lmdt:
  2347                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  2348                              <1> 	; 29/12/2017
  2349                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
  2350                              <1> 	; 01/08/2011
  2351                              <1> 	; 16/10/2010
  2352                              <1> 	;
  2353                              <1> 	; INPUT ->
  2354                              <1> 	;	none
  2355                              <1>  	; OUTPUT ->
  2356                              <1> 	;	(last modification date & time of the parent dir
  2357                              <1> 	;	will be changed/updated)
  2358                              <1> 	;
  2359                              <1> 	; (EAX, EBX, ECX, EDX, EDI will be changed)
  2360                              <1> 
  2361 0000B0E9 29C0                <1> 	sub	eax, eax
  2362 0000B0EB 8A25[807D0100]      <1> 	mov	ah, [Current_Dir_Level]
  2363 0000B0F1 A0[817D0100]        <1> 	mov	al, [Current_FATType]
  2364 0000B0F6 3C01                <1> 	cmp	al, 1
  2365 0000B0F8 7239                <1> 	jb	short loc_UPDLMDT_proc_retn
  2366                              <1> 
  2367                              <1> loc_update_parent_dir_lm_date_time:
  2368 0000B0FA 08E4                <1> 	or	ah, ah
  2369 0000B0FC 7435                <1> 	jz	short loc_UPDLMDT_proc_retn
  2370                              <1> 
  2371 0000B0FE 56                  <1> 	push	esi ; *
  2372 0000B0FF 8825[20870100]      <1> 	mov	[UPDLMDT_CDirLevel], ah
  2373 0000B105 8B15[7C7D0100]      <1> 	mov	edx, [Current_Dir_FCluster]
  2374 0000B10B 8915[21870100]      <1> 	mov	[UPDLMDT_CDirFCluster], edx
  2375                              <1> 
  2376 0000B111 FECC                <1> 	dec	ah
  2377                              <1> 	;mov	ecx, 12
  2378                              <1>         ; 29/07/2022
  2379 0000B113 29C9                <1> 	sub	ecx, ecx
  2380 0000B115 B10C                <1> 	mov	cl, 12
  2381                              <1> 	;
  2382 0000B117 BE[E0840100]        <1> 	mov     esi, PATH_Array
  2383                              <1> 
  2384 0000B11C 8825[807D0100]      <1> 	mov	[Current_Dir_Level], ah
  2385 0000B122 08E4                <1> 	or	ah, ah
  2386 0000B124 750E                <1> 	jnz	short loc_update_parent_dir_lmdt_load_sub_dir_1
  2387 0000B126 803D[817D0100]02    <1> 	cmp	byte [Current_FATType], 2
  2388 0000B12D 770B                <1> 	ja	short loc_update_parent_dir_lmdt_load_sub_dir_2
  2389 0000B12F 28C0                <1> 	sub	al, al ; eax = 0
  2390 0000B131 EB0A                <1> 	jmp	short loc_update_parent_dir_lmdt_load_sub_dir_3
  2391                              <1> 
  2392                              <1> loc_UPDLMDT_proc_retn:
  2393 0000B133 C3                  <1> 	retn
  2394                              <1> 
  2395                              <1> loc_update_parent_dir_lmdt_load_sub_dir_1:
  2396 0000B134 B010                <1> 	mov	al, 16
  2397 0000B136 F6E4                <1> 	mul	ah
  2398 0000B138 01C6                <1> 	add	esi, eax
  2399                              <1> 
  2400                              <1> loc_update_parent_dir_lmdt_load_sub_dir_2:
  2401 0000B13A 8B460C              <1> 	mov	eax, [esi+12] ; Parent Dir First Cluster
  2402                              <1> 
  2403                              <1> loc_update_parent_dir_lmdt_load_sub_dir_3:
  2404 0000B13D A3[7C7D0100]        <1> 	mov	[Current_Dir_FCluster], eax
  2405                              <1> 
  2406 0000B142 83C610              <1> 	add	esi, 16
  2407 0000B145 66BF[0686]          <1> 	mov	di, Dir_File_Name
  2408 0000B149 F3A4                <1> 	rep	movsb
  2409                              <1> 	
  2410 0000B14B BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2411 0000B150 29DB                <1> 	sub	ebx, ebx
  2412 0000B152 8A3D[827D0100]      <1> 	mov	bh, [Current_Drv]
  2413 0000B158 01DE                <1> 	add	esi, ebx
  2414 0000B15A E8E7F7FFFF          <1> 	call	reload_current_directory
  2415 0000B15F 722F                <1> 	jc	short loc_update_parent_dir_lmdt_restore_cdirlevel
  2416                              <1> 
  2417                              <1> loc_update_parent_dir_lmdt_locate_dir:
  2418 0000B161 BE[06860100]        <1> 	mov	esi, Dir_File_Name
  2419                              <1> 	;xor	cx, cx
  2420                              <1> 	; 29/07/2022
  2421 0000B166 31C9                <1> 	xor	ecx, ecx
  2422 0000B168 66B81008            <1> 	mov	ax, 0810h ; Only directories
  2423 0000B16C E812F7FFFF          <1>         call    locate_current_dir_file
  2424                              <1> 	; EDI = DirBuff Directory Entry Address
  2425 0000B171 721D                <1> 	jc	short loc_update_parent_dir_lmdt_restore_cdirlevel
  2426                              <1> 
  2427 0000B173 E844FEFFFF          <1> 	call	convert_current_date_time
  2428 0000B178 66895712            <1> 	mov	[edi+18], dx ; Last Access Date
  2429 0000B17C 66895718            <1> 	mov	[edi+24], dx ; Last Write Date
  2430 0000B180 66894716            <1> 	mov	[edi+22], ax ; Last Write Time
  2431                              <1> 
  2432 0000B184 C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  2433 0000B18B E8C1FEFFFF          <1> 	call	save_directory_buffer
  2434                              <1> 	; 29/12/2017
  2435                              <1> 	;jc	short loc_update_parent_dir_lmdt_restore_cdirlevel
  2436                              <1> 	;xor	al, al
  2437                              <1> loc_update_parent_dir_lmdt_restore_cdirlevel:
  2438                              <1>  	;current directory level restoration
  2439 0000B190 8A25[20870100]      <1> 	mov	ah, [UPDLMDT_CDirLevel]
  2440 0000B196 8825[807D0100]      <1> 	mov	[Current_Dir_Level], ah
  2441 0000B19C 8B15[21870100]      <1>         mov     edx, [UPDLMDT_CDirFCluster]
  2442 0000B1A2 8915[7C7D0100]      <1> 	mov	[Current_Dir_FCluster], edx
  2443                              <1> 
  2444 0000B1A8 5E                  <1> 	pop	esi ; *
  2445 0000B1A9 C3                  <1> 	retn
  2446                              <1> 
  2447                              <1> delete_longname:
  2448                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  2449                              <1> 	; 27/02/2016 (TRDOS 386 = TRDOS v2.0)
  2450                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_delete_longname')
  2451                              <1> 	; 14/03/2010
  2452                              <1> 	; INPUT ->
  2453                              <1> 	; 	EAX = Directory Entry (Index) Number (< 65536)
  2454                              <1> 	; OUTPUT ->
  2455                              <1> 	;	cf = 0 -> OK  (EAX = 0)
  2456                              <1> 	; 	cf = 1 -> error code in EAX (AL)
  2457                              <1> 	;
  2458                              <1> 	; (Modified registers: EAX, EDX, ECX, EBX, EDI)
  2459                              <1> 
  2460 0000B1AA 66A3[50870100]      <1> 	mov	[DLN_EntryNumber], ax
  2461 0000B1B0 C605[52870100]40    <1>         mov     byte [DLN_40h], 40h
  2462                              <1> 
  2463 0000B1B7 E857000000          <1> 	call	locate_current_dir_entry
  2464 0000B1BC 7307                <1> 	jnc	short loc_dln_check_attributes
  2465 0000B1BE C3                  <1> 	retn
  2466                              <1> 
  2467                              <1> loc_dln_longname_not_found:
  2468                              <1> 	;mov	eax, 2
  2469                              <1> 	; 29/07/2022
  2470 0000B1BF 29C0                <1> 	sub	eax, eax
  2471 0000B1C1 B002                <1> 	mov	al, 2
  2472 0000B1C3 F9                  <1> 	stc
  2473 0000B1C4 C3                  <1> 	retn
  2474                              <1> 
  2475                              <1> loc_dln_check_attributes:
  2476 0000B1C5 B00F                <1> 	mov	al, 0Fh  ; long name
  2477 0000B1C7 8A670B              <1> 	mov	ah, [edi+0Bh] ; dir entry attributes
  2478 0000B1CA 38C4                <1> 	cmp	ah, al
  2479 0000B1CC 75F1                <1> 	jne	short loc_dln_longname_not_found
  2480 0000B1CE 8A27                <1> 	mov	ah, [edi]
  2481 0000B1D0 2A25[52870100]      <1> 	sub	ah, [DLN_40h]
  2482 0000B1D6 76E7                <1> 	jna	short loc_dln_longname_not_found
  2483 0000B1D8 80FC14              <1> 	cmp	ah, 14h ; 84-64=20 -> 20*13=260 bytes
  2484 0000B1DB 77E2                <1> 	ja	short loc_dln_longname_not_found
  2485                              <1> 
  2486 0000B1DD C607E5              <1> 	mov	byte [edi], 0E5h  ; deleted sign
  2487 0000B1E0 C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2 ; changed/write sign
  2488 0000B1E7 C605[52870100]00    <1> 	mov	byte [DLN_40h], 0 ; 40h -> 0
  2489                              <1> 
  2490                              <1> loc_dln_delete_next_ln_entry:
  2491 0000B1EE 80FC01              <1> 	cmp	ah, 1
  2492 0000B1F1 7616                <1> 	jna	short loc_dln_longname_retn
  2493                              <1> loc_dln_delete_next_ln_entry_0:
  2494 0000B1F3 66FF05[50870100]    <1> 	inc	word [DLN_EntryNumber]
  2495 0000B1FA 0FB705[50870100]    <1> 	movzx	eax, word [DLN_EntryNumber]
  2496 0000B201 E80D000000          <1> 	call	locate_current_dir_entry
  2497 0000B206 73BD                <1> 	jnc	short loc_dln_check_attributes
  2498                              <1> 
  2499                              <1> loc_dln_longname_stc_retn:
  2500 0000B208 C3                  <1> 	retn
  2501                              <1> 
  2502                              <1> loc_dln_longname_retn:
  2503                              <1> 	;cmp	byte [DirBuff_ValidData], 2
  2504                              <1> 	;jne	short loc_dln_longname_retn_xor_eax
  2505 0000B209 E843FEFFFF          <1> 	call	save_directory_buffer
  2506 0000B20E 72F8                <1> 	jc	short loc_dln_longname_stc_retn
  2507                              <1> 
  2508                              <1> loc_dln_longname_retn_xor_eax:
  2509 0000B210 31C0                <1> 	xor	eax, eax
  2510 0000B212 C3                  <1> 	retn
  2511                              <1> 
  2512                              <1> locate_current_dir_entry:
  2513                              <1> 	; 30/07/2022
  2514                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  2515                              <1> 	; 16/10/2016
  2516                              <1> 	; 15/10/2016
  2517                              <1> 	; 23/03/2016
  2518                              <1> 	; 27/02/2016 (TRDOS 386 = TRDOS v2.0)
  2519                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_locate_current_dir_entry')
  2520                              <1> 	; 07/03/2010
  2521                              <1> 	; INPUT ->
  2522                              <1> 	;	EAX = Directory Entry (Index) Number (< 65536)
  2523                              <1> 	; OUTPUT ->
  2524                              <1> 	;	EDI = Directory Entry Address
  2525                              <1> 	; 	EAX = Cluster Number of Directory Buffer
  2526                              <1> 	;	EBX = Directory Buffer Entry Offset
  2527                              <1> 	;	ECX = DirBuff Valid Data identifier (CL)
  2528                              <1> 	;   	If CF = 0 and CL = 2 then
  2529                              <1> 	;	   directory buffer modified and
  2530                              <1> 	;	   must be written to disk.
  2531                              <1> 	; 	If CF = 0  and CL = 1 then
  2532                              <1> 	;	   dir buffer has been written to disk, already.
  2533                              <1> 	;	CF = 1 -> Error code in EAX (AL)
  2534                              <1> 	;
  2535                              <1> 	; (Modified registers: EAX, EDX, ECX, EBX, EDI)
  2536                              <1> 
  2537                              <1> loc_locate_current_dir_entry:
  2538 0000B213 56                  <1> 	push	esi
  2539 0000B214 89C1                <1> 	mov	ecx, eax
  2540                              <1> 	;mov	edx, 32
  2541                              <1> 	; 29/07/2022
  2542 0000B216 29D2                <1> 	sub	edx, edx
  2543 0000B218 B220                <1> 	mov	dl, 32
  2544 0000B21A F7E2                <1> 	mul	edx 
  2545 0000B21C A3[5C870100]        <1> 	mov	[LCDE_ByteOffset], eax
  2546 0000B221 31DB                <1> 	xor	ebx, ebx
  2547 0000B223 8A3D[827D0100]      <1> 	mov	bh, [Current_Drv]
  2548 0000B229 A0[A7840100]        <1>         mov     al, [DirBuff_DRV]
  2549 0000B22E 2C41                <1> 	sub	al, 'A'
  2550 0000B230 BE00010900          <1>         mov     esi, Logical_DOSDisks
  2551 0000B235 01DE                <1> 	add	esi, ebx
  2552 0000B237 38C7                <1> 	cmp	bh, al
  2553                              <1> 	;jne	loc_lcde_reload_current_directory
  2554                              <1> 	; 29/07/2022
  2555 0000B239 7405                <1> 	je	short loc_lcde_cdl_check
  2556 0000B23B E986000000          <1> 	jmp	loc_lcde_reload_current_directory
  2557                              <1> loc_lcde_cdl_check:
  2558                              <1> 	; 29/07/2022
  2559 0000B240 31C0                <1> 	xor	eax, eax
  2560 0000B242 803D[807D0100]00    <1> 	cmp	byte [Current_Dir_Level], 0
  2561 0000B249 7728                <1> 	ja	short loc_lcde_calc_dirbuff_cluster_offset
  2562                              <1> 	; 27/02/2016
  2563                              <1> 	; TRDOS v1 has bug here for FAT32 fs !
  2564                              <1> 	; (Root Directory Entries for FAT32 = 0)
  2565 0000B24B 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3  ; FAT32
  2566 0000B24F 7322                <1> 	jnb	short loc_lcde_calc_dirbuff_cluster_offset
  2567                              <1> 
  2568                              <1> loc_lcde_cdl_check_FAT12_16:
  2569                              <1> 	; 29/07/2022
  2570                              <1> 	;xor	eax, eax
  2571 0000B251 668B4617            <1> 	mov	ax, [esi+LD_BPB+RootDirEnts]
  2572                              <1> 	;dec	ax
  2573 0000B255 48                  <1> 	dec	eax
  2574                              <1> 	;xor	dx, dx
  2575                              <1> 	;cmp	ax, cx ; cx = Directory Entry (Index) Number
  2576                              <1> 	; 29/07/2022
  2577 0000B256 39C8                <1> 	cmp	eax, ecx
  2578 0000B258 720E                <1> 	jb	short loc_lcde_stc_12h_retn
  2579 0000B25A 66890D[54870100]    <1> 	mov	[LCDE_EntryIndex], cx
  2580 0000B261 31C0                <1> 	xor	eax, eax
  2581 0000B263 E985000000          <1>         jmp     loc_lcde_check_dir_buffer_cluster
  2582                              <1> 
  2583                              <1> loc_lcde_stc_12h_retn:
  2584 0000B268 5E                  <1> 	pop	esi
  2585 0000B269 89CB                <1> 	mov	ebx, ecx
  2586 0000B26B 89D1                <1> 	mov	ecx, edx
  2587                              <1> 	; 16/10/2016 (12h -> 12)
  2588 0000B26D B80C000000          <1> 	mov	eax, 12 ; No more files
  2589 0000B272 C3                  <1> 	retn
  2590                              <1> 
  2591                              <1> loc_lcde_calc_dirbuff_cluster_offset:
  2592                              <1> 	;mov	bl, [esi+LD_BPB+SecPerClust]
  2593                              <1> 	;xor	bh, bh
  2594                              <1> 	;mov	ax, [esi+LD_BPB+BytesPerSec]
  2595                              <1> 	;mul	bx
  2596                              <1>  	;;or	dx, dx ; If bytes per cluster > 32KB it is invalid
  2597                              <1> 	;; 29/07/2022
  2598                              <1> 	;or	dl, dl
  2599                              <1> 	;jnz	short loc_lcde_invalid_format
  2600                              <1> 	; 29/07/2022
  2601 0000B273 31DB                <1> 	xor	ebx, ebx
  2602 0000B275 8A5E13              <1> 	mov	bl, [esi+LD_BPB+SecPerClust]
  2603 0000B278 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec]
  2604 0000B27C F7E3                <1> 	mul	ebx
  2605 0000B27E 89C1                <1> 	mov	ecx, eax
  2606                              <1> 	;mov	cx, ax ; BYTES PER CLUSTER
  2607 0000B280 A1[5C870100]        <1> 	mov	eax, [LCDE_ByteOffset]
  2608                              <1> 	;sub	edx, edx
  2609 0000B285 F7F1                <1> 	div	ecx
  2610 0000B287 3DFFFF0000          <1> 	cmp	eax, 65535
  2611 0000B28C 7746                <1> 	ja	short loc_lcde_invalid_format
  2612                              <1> 
  2613                              <1> 	; cluster sequence number of directory (< 65536)
  2614 0000B28E 66A3[56870100]      <1> 	mov	[LCDE_ClusterSN], ax
  2615                              <1> 
  2616                              <1> 	;mov	ax, dx ; byte offset in cluster (directory buffer)
  2617                              <1> 	; 29/07/2022
  2618 0000B294 89D0                <1> 	mov	eax, edx
  2619                              <1> 	;mov	bx, 32	; 1 dir entry = 32 bytes
  2620 0000B296 B320                <1>         mov	bl, 32
  2621                              <1> 	;sub	dx, dx	; 0
  2622                              <1> 	;div	bx
  2623 0000B298 29D2                <1> 	sub	edx, edx
  2624 0000B29A F7F3                <1> 	div	ebx
  2625 0000B29C 66A3[54870100]      <1> 	mov	[LCDE_EntryIndex], ax ; dir entry index/sequence number
  2626                              <1> 				      ; (in directory buffer/cluster)
  2627                              <1> loc_lcde_get_current_sub_dir_fcluster:
  2628 0000B2A2 A1[7C7D0100]        <1> 	mov	eax, [Current_Dir_FCluster]
  2629                              <1> 
  2630                              <1> loc_lcde_get_next_cluster:
  2631 0000B2A7 66833D[56870100]00  <1> 	cmp	word [LCDE_ClusterSN], 0
  2632 0000B2AF 763C                <1> 	jna	short loc_lcde_check_dir_buffer_cluster
  2633 0000B2B1 A3[58870100]        <1> 	mov	[LCDE_Cluster], eax
  2634 0000B2B6 E865100000          <1> 	call	get_next_cluster
  2635 0000B2BB 721E                <1> 	jc	short loc_lcde_check_gnc_error
  2636 0000B2BD 66FF0D[56870100]    <1>   	dec	word [LCDE_ClusterSN]
  2637 0000B2C4 EBE1                <1> 	jmp	short loc_lcde_get_next_cluster
  2638                              <1> 
  2639                              <1> loc_lcde_reload_current_directory:
  2640 0000B2C6 51                  <1> 	push	ecx
  2641 0000B2C7 E87AF6FFFF          <1> 	call	reload_current_directory
  2642 0000B2CC 59                  <1> 	pop	ecx
  2643                              <1> 	;jnc	loc_lcde_cdl_check
  2644                              <1> 	;pop	esi
  2645                              <1> 	;retn
  2646                              <1> 	; 09/08/2022
  2647 0000B2CD 727E                <1> 	jc	short loc_lcde_retn
  2648 0000B2CF E96CFFFFFF          <1> 	jmp	loc_lcde_cdl_check
  2649                              <1> 
  2650                              <1> loc_lcde_invalid_format:
  2651                              <1> 	; 15/10/2016 (0Bh -> 28)
  2652                              <1> 	;mov	eax, 28 ; Invalid Format !
  2653                              <1> 	; 29/07/2022
  2654 0000B2D4 29C0                <1> 	sub	eax, eax
  2655 0000B2D6 B01C                <1> 	mov	al, 28
  2656                              <1> loc_lcde_drive_not_ready_read_err:
  2657 0000B2D8 F9                  <1> 	stc
  2658 0000B2D9 5E                  <1> 	pop	esi
  2659 0000B2DA C3                  <1> 	retn
  2660                              <1> 
  2661                              <1> loc_lcde_check_gnc_error:
  2662 0000B2DB 09C0                <1> 	or	eax, eax
  2663 0000B2DD 75F9                <1> 	jnz	short loc_lcde_drive_not_ready_read_err
  2664 0000B2DF 66FF0D[56870100]    <1> 	dec	word [LCDE_ClusterSN]
  2665 0000B2E6 75EC                <1> 	jnz	short loc_lcde_invalid_format
  2666 0000B2E8 A1[58870100]        <1> 	mov	eax, [LCDE_Cluster]
  2667                              <1> 
  2668                              <1> loc_lcde_check_dir_buffer_cluster:
  2669 0000B2ED 3B05[AE840100]      <1> 	cmp	eax, [DirBuff_Cluster]
  2670 0000B2F3 755A                <1> 	jne	short loc_lcde_load_dir_cluster
  2671 0000B2F5 803D[A9840100]00    <1> 	cmp	byte [DirBuff_ValidData], 0
  2672 0000B2FC 7726                <1> 	ja	short lcde_check_dir_buffer_cluster_next
  2673 0000B2FE 803D[807D0100]00    <1> 	cmp	byte [Current_Dir_Level], 0
  2674 0000B305 775D                <1> 	ja	short loc_lcde_load_dir_cluster_0
  2675                              <1> 	; 27/02/2016
  2676                              <1> 	; TRDOS v1 has bug here for FAT32 fs !
  2677 0000B307 807E0303            <1> 	cmp	byte [esi+LD_FATType], 3  ; FAT32
  2678 0000B30B 7357                <1> 	jnb	short loc_lcde_load_dir_cluster_0
  2679                              <1> 	;
  2680 0000B30D 0FB74E17            <1> 	movzx	ecx, word [esi+LD_BPB+RootDirEnts]
  2681 0000B311 6683C10F            <1> 	add	cx, 15 ; round up (16 entries per sector)
  2682                              <1> 	;shr	cx, 4 ; 1 sector contains 16 dir entries
  2683                              <1> 	; 29/07/2022
  2684 0000B315 C1E904              <1> 	shr	ecx, 4
  2685 0000B318 8B4664              <1>         mov     eax, [esi+LD_ROOTBegin]
  2686 0000B31B EB52                <1> 	jmp	short loc_lcde_load_dir_cluster_1
  2687                              <1> 
  2688                              <1> loc_lcde_validate_dirBuff:
  2689 0000B31D C605[A9840100]01    <1> 	mov	byte [DirBuff_ValidData], 1
  2690                              <1> 
  2691                              <1> lcde_check_dir_buffer_cluster_next:
  2692 0000B324 0FB71D[54870100]    <1> 	movzx	ebx, word [LCDE_EntryIndex]
  2693 0000B32B 663B1D[AC840100]    <1> 	cmp	bx, [DirBuff_LastEntry]
  2694 0000B332 77A0                <1> 	ja	short loc_lcde_invalid_format
  2695                              <1> 	;mov	eax, 32
  2696                              <1> 	; 29/07/2022
  2697 0000B334 31C0                <1> 	xor	eax, eax
  2698 0000B336 B020                <1> 	mov	al, 32
  2699 0000B338 F7E3                <1> 	mul	ebx
  2700                              <1> 	;or	edx, edx
  2701                              <1> 	;jnz	short loc_lcde_invalid_format
  2702                              <1> 
  2703 0000B33A BF00000800          <1> 	mov	edi, Directory_Buffer
  2704 0000B33F 01C7                <1> 	add	edi, eax ; add entry offset to buffer address
  2705                              <1> 
  2706                              <1> loc_lcde_dir_buffer_last_check:
  2707 0000B341 A1[AE840100]        <1> 	mov	eax, [DirBuff_Cluster]
  2708 0000B346 0FB60D[A9840100]    <1> 	movzx	ecx, byte [DirBuff_ValidData]
  2709                              <1> 
  2710                              <1> loc_lcde_retn:
  2711 0000B34D 5E                  <1> 	pop	esi
  2712 0000B34E C3                  <1> 	retn
  2713                              <1> 
  2714                              <1> loc_lcde_load_dir_cluster:
  2715                              <1> 	;cmp	byte [DirBuff_ValidData], 2
  2716                              <1> 	;jne	short loc_lcde_load_dir_cluster_n2
  2717 0000B34F 50                  <1> 	push	eax
  2718 0000B350 E8FCFCFFFF          <1> 	call	save_directory_buffer
  2719 0000B355 58                  <1> 	pop	eax
  2720 0000B356 72F5                <1> 	jc	short loc_lcde_retn
  2721                              <1> 
  2722                              <1> loc_lcde_load_dir_cluster_n2:
  2723 0000B358 C605[A9840100]00    <1> 	mov	byte [DirBuff_ValidData], 0
  2724 0000B35F A3[AE840100]        <1> 	mov	[DirBuff_Cluster], eax
  2725                              <1> 
  2726                              <1> loc_lcde_load_dir_cluster_0:
  2727                              <1> 	;sub	eax, 2
  2728                              <1> 	; 30/07/2022
  2729 0000B364 48                  <1> 	dec	eax
  2730 0000B365 48                  <1> 	dec	eax
  2731 0000B366 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  2732 0000B36A F7E1                <1> 	mul	ecx
  2733 0000B36C 034668              <1>         add     eax, [esi+LD_DATABegin]
  2734                              <1> 
  2735                              <1> loc_lcde_load_dir_cluster_1:
  2736 0000B36F BB00000800          <1> 	mov	ebx, Directory_Buffer
  2737                              <1> 	; ecx = sector count
  2738 0000B374 E8876C0000          <1> 	call	disk_read
  2739 0000B379 73A2                <1> 	jnc	short loc_lcde_validate_dirBuff
  2740                              <1> 
  2741                              <1> 	; 15/10/2016
  2742                              <1> 	; (Disk read error instead of drv not ready err)
  2743 0000B37B B811000000          <1> 	mov	eax, 17 ; Drive not ready or read error !
  2744 0000B380 EBCB                <1> 	jmp	short loc_lcde_retn
  2745                              <1> 
  2746                              <1> remove_file:
  2747                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  2748                              <1> 	; 15/10/2016
  2749                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
  2750                              <1> 	; 10/04/2011 (FILE.ASM, 'proc_delete_file')
  2751                              <1> 	; 09/08/2010
  2752                              <1> 	; INPUT ->
  2753                              <1> 	;	EDI = Directory Buffer Entry Address
  2754                              <1> 	;	 CX = Directory Buffer Entry Counter/Index
  2755                              <1> 	;	 BL = Longname Entry Length
  2756                              <1> 	;	 BH = Logical DOS Drive Number
  2757                              <1> 
  2758 0000B382 29C0                <1> 	sub	eax, eax
  2759 0000B384 88FC                <1> 	mov	ah, bh
  2760 0000B386 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  2761 0000B38B 01C6                <1> 	add	esi, eax
  2762                              <1> 
  2763 0000B38D 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  2764 0000B391 7311                <1> 	jnb	short loc_del_fat_file
  2765                              <1> 
  2766 0000B393 807E04A1            <1> 	cmp	byte [esi+LD_FSType], 0A1h
  2767 0000B397 7406                <1> 	je	short loc_del_fs_file
  2768                              <1> 
  2769                              <1> loc_del_file_invalid_format:
  2770 0000B399 30E4                <1> 	xor	ah, ah
  2771                              <1> 	; 15/10/2016 (0Bh -> 28)
  2772 0000B39B B01C                <1> 	mov	al, 28  ; Invalid Format
  2773 0000B39D F9                  <1> 	stc 
  2774 0000B39E C3                  <1> 	retn
  2775                              <1> 
  2776                              <1> loc_del_fs_file:
  2777                              <1> 	;call	delete_fs_file
  2778                              <1> 	;retn
  2779                              <1> 	; 29/07/2022
  2780 0000B39F E97B0F0000          <1> 	jmp	delete_fs_file
  2781                              <1> 
  2782                              <1> loc_del_fat_file:
  2783 0000B3A4 E808000000          <1> 	call	delete_directory_entry
  2784 0000B3A9 7205                <1> 	jc	short loc_del_file_err_retn
  2785                              <1> 
  2786                              <1> loc_delfile_unlink_cluster_chain:
  2787 0000B3AB E811170000          <1> 	call	truncate_cluster_chain
  2788                              <1> 	;jc	short loc_del_file_err_retn
  2789                              <1> 
  2790                              <1> loc_delfile_return:
  2791                              <1> loc_del_file_err_retn:
  2792 0000B3B0 C3                  <1> 	retn
  2793                              <1> 
  2794                              <1> delete_directory_entry:
  2795                              <1> 	; 15/10/2016
  2796                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
  2797                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_delete_directory_entry')
  2798                              <1> 	; 10/04/2011
  2799                              <1> 	; INPUT ->
  2800                              <1> 	; 	ESI = Logical Dos Drive Descripton Table Address 
  2801                              <1> 	;	EDI = Directory Buffer Entry Address
  2802                              <1> 	;	 CX = Directory Buffer Entry Counter/Index
  2803                              <1> 	;	 BL = Longname Entry Length
  2804                              <1> 	; OUTPUT ->
  2805                              <1> 	; 	ESI = Logical dos drive descripton table address 
  2806                              <1> 	;	EAX = First cluster to be truncated/unlinked
  2807                              <1> 	;       CF = 1 -> Error code in EAX (AL)
  2808                              <1> 	;       CF = 0 & BH <> 0 -> LMDT write error  (BH = 1)
  2809                              <1> 	;       CF = 0 & BL <> 0 -> Long name delete error (BL = FFh) 
  2810                              <1> 	;
  2811                              <1> 	;  (EDI, EBX, ECX register contents will be changed)
  2812                              <1> 
  2813 0000B3B1 881D[EA860100]      <1> 	mov	[DelFile_LNEL], bl
  2814 0000B3B7 66890D[E8860100]    <1> 	mov	[DelFile_EntryCounter], cx
  2815                              <1> 
  2816 0000B3BE 668B4714            <1> 	mov	ax, [edi+20] ; First Cluster High Word
  2817 0000B3C2 C1E010              <1> 	shl	eax, 16
  2818 0000B3C5 668B471A            <1> 	mov	ax, [edi+26] ; First Cluster Low Word
  2819                              <1> 
  2820 0000B3C9 A3[E4860100]        <1> 	mov	[DelFile_FCluster], eax
  2821                              <1> 
  2822                              <1> loc_del_short_name:
  2823 0000B3CE C607E5              <1> 	mov	byte [edi], 0E5h  ; Deleted sign
  2824                              <1> 
  2825 0000B3D1 C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  2826 0000B3D8 E874FCFFFF          <1> 	call	save_directory_buffer
  2827 0000B3DD 723D                <1> 	jc	short loc_delete_direntry_err_return
  2828                              <1> 
  2829                              <1> loc_del_long_name:
  2830 0000B3DF 0FB615[EA860100]    <1> 	movzx	edx, byte [DelFile_LNEL]
  2831 0000B3E6 08D2                <1> 	or	dl, dl
  2832 0000B3E8 7416                <1> 	jz	short loc_del_dir_entry_update_parent_dir_lm_date
  2833                              <1> 
  2834 0000B3EA 8835[EA860100]      <1> 	mov	[DelFile_LNEL], dh ; 0
  2835                              <1> 
  2836 0000B3F0 0FB705[E8860100]    <1> 	movzx	eax, word [DelFile_EntryCounter]
  2837 0000B3F7 29D0                <1> 	sub	eax, edx
  2838                              <1> 	;jnc	short loc_del_long_name_continue
  2839 0000B3F9 7205                <1> 	jc	short loc_del_dir_entry_update_parent_dir_lm_date
  2840                              <1> 
  2841                              <1> ;loc_del_direntry_inv_data_return: ; 15/10/2016 (0Dh -> 29)
  2842                              <1> ;	mov	eax, 29 ; 0Dh (TRDOS 8086) ; Invalid data
  2843                              <1> ;	retn
  2844                              <1> 
  2845                              <1> loc_del_long_name_continue: 
  2846                              <1> 	; AX = Directory Entry Number of the long name last entry
  2847 0000B3FB E8AAFDFFFF          <1> 	call	delete_longname
  2848                              <1> 	;jc	short loc_delete_direntry_err_return
  2849                              <1> 
  2850                              <1> loc_del_dir_entry_update_parent_dir_lm_date:
  2851 0000B400 801D[EA860100]00    <1> 	sbb	byte [DelFile_LNEL], 0 ; 0FFh if cf = 1
  2852                              <1> 
  2853 0000B407 E8DDFCFFFF          <1> 	call	update_parent_dir_lmdt
  2854 0000B40C B700                <1> 	mov	bh, 0
  2855 0000B40E 80D700              <1> 	adc	bh, 0
  2856                              <1> 
  2857 0000B411 8A1D[EA860100]      <1> 	mov	bl, byte [DelFile_LNEL]
  2858                              <1> 
  2859                              <1> loc_delete_direntry_return:
  2860 0000B417 A1[E4860100]        <1> 	mov	eax, [DelFile_FCluster]
  2861                              <1> loc_delete_direntry_err_return:
  2862 0000B41C C3                  <1> 	retn
  2863                              <1> 
  2864                              <1> rename_directory_entry:
  2865                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  2866                              <1> 	; 13/11/2017
  2867                              <1> 	; 15/10/2016
  2868                              <1> 	; 06/03/2016 (TRDOS 386 = TRDOS v2.0)
  2869                              <1> 	; 01/08/2011 (DIR.ASM, 'proc_rename_directory_entry')
  2870                              <1> 	; 19/11/2010
  2871                              <1> 	; INPUT -> (Current Directory)
  2872                              <1> 	;	CX = Directory Entry Number
  2873                              <1> 	;      EAX = First Cluster number of file or directory
  2874                              <1> 	;      EBX = Longname Length (dir entry count) (< 256)
  2875                              <1> 	;      ESI = New file (or directory) name (no path).
  2876                              <1> 	;           (ASCIIZ string)
  2877                              <1> 	; OUTPUT -> 
  2878                              <1> 	;      CF = 0 -> successfull
  2879                              <1> 	;      CF = 1 -> error code in EAX (AL)
  2880                              <1> 	;
  2881                              <1> 	; (EAX, EBX, ECX, EDX, ESI, EDI will be changed)
  2882                              <1> 
  2883 0000B41D 803D[817D0100]00    <1> 	cmp	byte [Current_FATType], 0
  2884 0000B424 7705                <1> 	ja	short loc_rename_directory_entry
  2885                              <1> 
  2886                              <1> 	;call	rename_fs_file_or_directory
  2887                              <1> 	;retn
  2888                              <1> 	; 29/07/2022
  2889 0000B426 E9F40E0000          <1>  	jmp	rename_fs_file_or_directory
  2890                              <1> 	
  2891                              <1> loc_rename_directory_entry:
  2892 0000B42B 881D[EA860100]      <1> 	mov	[DelFile_LNEL], bl
  2893 0000B431 66890D[E8860100]    <1> 	mov	[DelFile_EntryCounter], cx
  2894 0000B438 A3[E4860100]        <1> 	mov	[DelFile_FCluster], eax
  2895                              <1> 
  2896 0000B43D 0FB7C1              <1> 	movzx	eax, cx
  2897 0000B440 E8CEFDFFFF          <1> 	call	locate_current_dir_entry
  2898 0000B445 7307                <1> 	jnc	short loc_rename_direntry_check_fcluster
  2899                              <1> 
  2900                              <1> loc_rename_direntry_pop_retn:
  2901 0000B447 C3                  <1> 	retn
  2902                              <1> 
  2903                              <1> loc_rename_direntry_pop_invd_retn:
  2904                              <1> 	; 29/07/2022
  2905                              <1> 	;stc
  2906                              <1> loc_rename_direntry_invd_retn:
  2907                              <1> 	; 15/10/2016 (0Dh -> 29)
  2908                              <1> 	;mov	eax, 29 ; Invalid data
  2909                              <1> 	; 29/07/2022
  2910 0000B448 29C0                <1> 	sub	eax, eax
  2911 0000B44A B01D                <1> 	mov	al, 29
  2912 0000B44C F9                  <1> 	stc
  2913                              <1> loc_rename_retn:
  2914 0000B44D C3                  <1> 	retn
  2915                              <1> 
  2916                              <1> loc_rename_direntry_check_fcluster:
  2917 0000B44E 668B5714            <1> 	mov	dx, [edi+20] ; First Cluster HW
  2918 0000B452 C1E210              <1> 	shl	edx, 16 ; 13/11/2017
  2919 0000B455 668B571A            <1> 	mov	dx, [edi+26] ; First Cluster LW
  2920 0000B459 3B15[E4860100]      <1> 	cmp	edx, [DelFile_FCluster]
  2921 0000B45F 75E7                <1> 	jne	short loc_rename_direntry_pop_invd_retn
  2922                              <1> 	; ESI = New file (or directory) name. (ASCIIZ string)
  2923                              <1> 	; 06/03/2016
  2924                              <1> 	; TRDOS v2 - NOTE: 'convert_file_name' procedure
  2925                              <1> 	; has been modified for eliminating following situation.
  2926                              <1> 	; 
  2927                              <1> 	; TRDOS v1 - NOTE: If file/dir name is more than 11 bytes
  2928                              <1> 	; without a dot, attributes (edi+11) byte will be overwritten !
  2929                              <1> 	; (Dot file name input must be proper for 11 byte dir entry
  2930                              <1> 	;  type file name output.)
  2931 0000B461 E8EAF6FFFF          <1> 	call	convert_file_name
  2932                              <1> 
  2933 0000B466 C605[A9840100]02    <1>         mov     byte [DirBuff_ValidData], 2
  2934 0000B46D E8DFFBFFFF          <1> 	call	save_directory_buffer
  2935 0000B472 72D9                <1> 	jc	short loc_rename_retn
  2936                              <1> 
  2937                              <1> loc_rename_direntry_del_ln:
  2938 0000B474 0FB615[EA860100]    <1> 	movzx	edx, byte [DelFile_LNEL]
  2939 0000B47B 08D2                <1> 	or	dl, dl
  2940 0000B47D 7410                <1> 	jz	short loc_rename_direntry_update_parent_dir_lm_date
  2941                              <1> 
  2942 0000B47F 0FB705[E8860100]    <1> 	movzx	eax, word [DelFile_EntryCounter]
  2943 0000B486 29D0                <1> 	sub	eax, edx
  2944 0000B488 72BE                <1> 	jc	short loc_rename_direntry_invd_retn
  2945                              <1> 
  2946                              <1> loc_rename_direntry_del_ln_continue:
  2947                              <1> 	; EAX = Directory Entry Number of the long name last entry
  2948 0000B48A E81BFDFFFF          <1> 	call	delete_longname
  2949                              <1> 
  2950                              <1> loc_rename_direntry_update_parent_dir_lm_date:
  2951 0000B48F E855FCFFFF          <1> 	call	update_parent_dir_lmdt
  2952 0000B494 31C0                <1> 	xor	eax, eax
  2953 0000B496 C3                  <1> 	retn
  2954                              <1> 
  2955                              <1> move_source_file_to_destination_file:
  2956                              <1> 	; 07/08/2022
  2957                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  2958                              <1> 	; 15/10/2016
  2959                              <1> 	; 11/03/2016
  2960                              <1> 	; 10/03/2016 (TRDOS 386 = TRDOS v2.0)
  2961                              <1> 	; 01/08/2011 (FILE.ASM)
  2962                              <1> 	; 04/08/2010
  2963                              <1> 	;
  2964                              <1> 	;   Phase 1 -> Check destination file,
  2965                              <1> 	;              'not found' is required
  2966                              <1> 	;   Phase 2 -> Check source file
  2967                              <1> 	;              'found' and proper attributes is required
  2968                              <1> 	;   Phase 3 -> Make destination directory entry,
  2969                              <1> 	;           add new dir cluster or section if it is required
  2970                              <1> 	;   Phase 4 -> Delete source directory entry.
  2971                              <1> 	;       cf = 1 causes to return before the phase 4.
  2972                              <1> 	;    (source file protection against any possible errors)
  2973                              <1> 	;
  2974                              <1> 	; 08/05/2011 major modification
  2975                              <1> 	;            -> destination file deleting is removed
  2976                              <1> 	;            for msdos move/rename compatibility.
  2977                              <1> 	;            (Access denied error will return if
  2978                              <1> 	;            the destination file is found...)
  2979                              <1> 	; INPUT ->
  2980                              <1> 	;	 ESI = Source File Pathname (Asciiz)
  2981                              <1> 	;        EDI = Destination File Pathname (Asciiz)
  2982                              <1> 	;        AL = 0 --> Interrupt (System call)
  2983                              <1> 	;        AL > 0 --> Command Interpreter (Question)
  2984                              <1> 	;        AL = 1 --> Question Phase
  2985                              <1> 	;        AL = 2 --> Progress Phase
  2986                              <1> 	; OUTPUT ->
  2987                              <1> 	;	 cf = 0 -> OK
  2988                              <1> 	;        EAX = Destination directory first cluster
  2989                              <1> 	;        ESI = Logical DOS drive description table
  2990                              <1> 	;        EBX = Destination file structure offset
  2991                              <1> 	;        CX = 0 (CX > 0 --> calculate free space error)
  2992                              <1> 	;        cf = 1 -> Error code in EAX (AL) 
  2993                              <1> 	;
  2994                              <1> 	;  (EDX, ECX, EBX, ESI, EDI will be changed)
  2995                              <1> 
  2996 0000B497 3C02                <1> 	cmp	al, 2
  2997                              <1> 	;je	msftdf_df2_check_directory
  2998                              <1> 	; 29/07/2022
  2999 0000B499 7505                <1> 	jne	short msftdf
  3000 0000B49B E97B010000          <1> 	jmp	msftdf_df2_check_directory
  3001                              <1> msftdf:
  3002 0000B4A0 A2[6A880100]        <1> 	mov	[move_cmd_phase], al
  3003                              <1> 
  3004                              <1> msftdf_parse_sf_path:
  3005                              <1> 	; ESI = ASCIIZ pathname (Source)
  3006 0000B4A5 57                  <1> 	push	edi 
  3007 0000B4A6 BF[68870100]        <1> 	mov	edi, SourceFile_Drv
  3008 0000B4AB E86AF7FFFF          <1> 	call	parse_path_name
  3009 0000B4B0 5E                  <1> 	pop	esi
  3010 0000B4B1 7211                <1> 	jc	short msftdf_psf_retn
  3011                              <1> 
  3012                              <1> msftdf_parse_df_path:
  3013                              <1> 	; ESI = ASCIIZ pathname	(Destination)
  3014 0000B4B3 BF[E8870100]        <1> 	mov	edi, DestinationFile_Drv
  3015 0000B4B8 E85DF7FFFF          <1> 	call	parse_path_name
  3016 0000B4BD 7306                <1> 	jnc	short msftdf_check_sf_drv
  3017                              <1> 
  3018 0000B4BF 3C01                <1> 	cmp	al, 1 ; File or directory name is not existing
  3019 0000B4C1 7602                <1> 	jna	short msftdf_check_sf_drv
  3020                              <1> 
  3021                              <1> msftdf_stc_retn:
  3022 0000B4C3 F9                  <1> 	stc
  3023                              <1> msftdf_psf_retn:
  3024 0000B4C4 C3                  <1> 	retn
  3025                              <1> 
  3026                              <1> msftdf_check_sf_drv:
  3027 0000B4C5 A0[68870100]        <1> 	mov	al, [SourceFile_Drv]
  3028                              <1> 
  3029                              <1> msftdf_check_df_drv:
  3030 0000B4CA 8A15[E8870100]      <1> 	mov	dl, [DestinationFile_Drv]
  3031                              <1> 
  3032                              <1> msftdf_compare_sf_df_drv:
  3033 0000B4D0 29DB                <1> 	sub	ebx, ebx
  3034 0000B4D2 8A3D[827D0100]      <1> 	mov	bh, [Current_Drv]
  3035 0000B4D8 38C2                <1> 	cmp	dl, al
  3036 0000B4DA 7408                <1> 	je	short msftdf_check_sf_df_drv_ok
  3037                              <1> 
  3038                              <1> msftdf_not_same_drv:
  3039                              <1>         ; DL = source file's drive number
  3040 0000B4DC 88C6                <1> 	mov	dh, al ; destination file's drive number
  3041                              <1> 	; 15/10/2016 (11h -> 21)
  3042                              <1> 	;mov	eax, 21 ; Not the same drive
  3043                              <1> 	; 29/07/2022
  3044 0000B4DE 29C0                <1> 	sub	eax, eax
  3045 0000B4E0 B015                <1> 	mov	al, 21
  3046 0000B4E2 F9                  <1> 	stc
  3047 0000B4E3 C3                  <1> 	retn 
  3048                              <1> 
  3049                              <1> msftdf_check_sf_df_drv_ok:
  3050 0000B4E4 8815[6B880100]      <1> 	mov	[msftdf_sf_df_drv], dl
  3051                              <1> 
  3052 0000B4EA 29C0                <1>         sub	eax, eax
  3053 0000B4EC 88D4                <1> 	mov	ah, dl
  3054 0000B4EE 0500010900          <1> 	add	eax, Logical_DOSDisks
  3055 0000B4F3 A3[6C880100]        <1> 	mov	[msftdf_drv_offset], eax
  3056                              <1> 
  3057 0000B4F8 38FA                <1> 	cmp	dl, bh ; byte [Current_Drv]
  3058 0000B4FA 7407                <1> 	je	short msftdf_df_check_directory
  3059                              <1> 
  3060                              <1> msftdf_change_drv:
  3061 0000B4FC E87CC3FFFF          <1> 	call 	change_current_drive
  3062 0000B501 726D                <1> 	jc	short msftdf_df_error_retn
  3063                              <1> 	  
  3064                              <1> msftdf_check_destination_file:
  3065                              <1> msftdf_df_check_directory:
  3066 0000B503 BE[E9870100]        <1> 	mov	esi, DestinationFile_Directory
  3067 0000B508 803E20              <1> 	cmp	byte [esi], 20h
  3068 0000B50B 760F                <1> 	jna	short msftdf_df_find_1
  3069                              <1> 
  3070                              <1> msftdf_df_change_directory:
  3071 0000B50D FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  3072 0000B513 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0
  3073 0000B515 E816F1FFFF          <1> 	call	change_current_directory
  3074 0000B51A 7254                <1> 	jc	short msftdf_df_error_retn
  3075                              <1> 
  3076                              <1> ;msftdf_df_change_prompt_dir_string:
  3077                              <1> ;	call 	change_prompt_dir_string
  3078                              <1> 
  3079                              <1> msftdf_df_find_1:
  3080 0000B51C BE[2A880100]        <1>         mov     esi, DestinationFile_Name
  3081 0000B521 803E20              <1> 	cmp	byte [esi], 20h
  3082 0000B524 7632                <1> 	jna	short msftdf_df_copy_sf_name
  3083                              <1> 
  3084                              <1> msftdf_df_find_2:
  3085 0000B526 6631C0              <1> 	xor	ax, ax ; DestinationFile_AttributesMask -> any/zero
  3086 0000B529 E83CD6FFFF          <1> 	call	find_first_file
  3087                              <1> 	;jnc	msftdf_permission_denied_retn
  3088                              <1> 	; 29/07/2022
  3089 0000B52E 7205                <1> 	jc	short msftdf_df_check_error_code
  3090 0000B530 E98B000000          <1> 	jmp	msftdf_permission_denied_retn
  3091                              <1> 
  3092                              <1> msftdf_df_check_error_code:
  3093                              <1> 	;cmp	eax, 2 ; File not found error
  3094 0000B535 3C02                <1> 	cmp	al, 2
  3095 0000B537 7536                <1> 	jne	short msftdf_df_stc_retn
  3096                              <1> 
  3097                              <1> msftdf_df_check_fname:
  3098                              <1> 	; 15/10/2016
  3099 0000B539 BE[2A880100]        <1> 	mov	esi, DestinationFile_Name ; *
  3100 0000B53E E8CCD9FFFF          <1> 	call	check_filename
  3101 0000B543 7307                <1> 	jnc	short msftdf_convert_df_direntry_name
  3102                              <1> 	; invalid file name chars !
  3103 0000B545 B81A000000          <1> 	mov	eax, ERR_INV_FILE_NAME  ; 26
  3104 0000B54A EB23                <1> 	jmp	short msftdf_df_stc_retn
  3105                              <1> 
  3106                              <1> msftdf_convert_df_direntry_name:
  3107                              <1> 	; mov	esi, DestinationFile_Name ; *
  3108 0000B54C BF[3A880100]        <1> 	mov	edi, DestinationFile_DirEntry
  3109 0000B551 E8FAF5FFFF          <1> 	call	convert_file_name
  3110 0000B556 EB19                <1>   	jmp	short msftdf_restore_current_dir_1
  3111                              <1> 
  3112                              <1> msftdf_df_copy_sf_name:
  3113 0000B558 89F7                <1> 	mov	edi, esi
  3114 0000B55A 57                  <1> 	push	edi
  3115 0000B55B BE[AA870100]        <1>         mov     esi, SourceFile_Name
  3116                              <1> 	;mov	ecx, 12
  3117                              <1> 	; 29/07/2022
  3118 0000B560 29C9                <1> 	sub	ecx, ecx
  3119 0000B562 B10C                <1> 	mov	cl, 12
  3120                              <1> msftdf_df_copy_sf_name_loop:
  3121 0000B564 AC                  <1> 	lodsb
  3122 0000B565 AA                  <1>         stosb
  3123 0000B566 08C0                <1> 	or	al, al
  3124 0000B568 7402                <1> 	jz	short msftdf_df_copy_sf_name_ok
  3125 0000B56A E2F8                <1>         loop    msftdf_df_copy_sf_name_loop
  3126                              <1> msftdf_df_copy_sf_name_ok:
  3127 0000B56C 5E                  <1> 	pop	esi
  3128 0000B56D EBB7                <1> 	jmp	short msftdf_df_find_2
  3129                              <1> 
  3130                              <1> msftdf_df_stc_retn:
  3131 0000B56F F9                  <1> 	stc
  3132                              <1> msftdf_restore_cdir_failed:
  3133                              <1> msftdf_df_error_retn:
  3134 0000B570 C3                  <1> 	retn
  3135                              <1> 
  3136                              <1> msftdf_restore_current_dir_1:
  3137 0000B571 803D[9B340100]00    <1> 	cmp	byte [Restore_CDIR], 0
  3138 0000B578 760D                <1> 	jna	short msftdf_sf_check_directory
  3139 0000B57A 8B35[6C880100]      <1> 	mov	esi, [msftdf_drv_offset] 
  3140 0000B580 E8AEC3FFFF          <1> 	call	restore_current_directory
  3141 0000B585 72E9                <1> 	jc	short msftdf_restore_cdir_failed
  3142                              <1> 
  3143                              <1> msftdf_sf_check_directory:
  3144 0000B587 BE[69870100]        <1> 	mov	esi, SourceFile_Directory
  3145 0000B58C 803E20              <1> 	cmp	byte [esi], 20h
  3146 0000B58F 760F                <1> 	jna	short msftdf_sf_find
  3147                              <1> msftdf_sf_change_directory:
  3148 0000B591 FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  3149 0000B597 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0
  3150 0000B599 E892F0FFFF          <1> 	call	change_current_directory
  3151 0000B59E 7225                <1> 	jc	short msftdf_return
  3152                              <1> 
  3153                              <1> ;msftdf_sf_change_prompt_dir_string:
  3154                              <1> ;	call	change_prompt_dir_string
  3155                              <1> 
  3156                              <1> msftdf_sf_find:
  3157 0000B5A0 BE[AA870100]        <1>         mov     esi, SourceFile_Name  ; Offset 66
  3158 0000B5A5 66B80018            <1> 	mov	ax, 1800h ; Only files
  3159 0000B5A9 E8BCD5FFFF          <1> 	call	find_first_file
  3160 0000B5AE 7215                <1> 	jc	short msftdf_return
  3161                              <1> 
  3162                              <1> msftdf_sf_ambgfn_check:
  3163 0000B5B0 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3164 0000B5B3 7406                <1> 	jz	short msftdf_sf_found
  3165                              <1> 
  3166                              <1> msftdf_ambiguous_file_name_error:
  3167                              <1> 	;mov	eax, 2 ; File not found error
  3168                              <1> 	; 29/07/2022
  3169 0000B5B5 29C0                <1> 	sub	eax, eax
  3170 0000B5B7 B002                <1> 	mov	al, 2
  3171 0000B5B9 F9                  <1> 	stc
  3172 0000B5BA C3                  <1> 	retn
  3173                              <1> 
  3174                              <1> msftdf_sf_found:
  3175 0000B5BB 80E31F              <1> 	and	bl, 1Fh ; Attributes, D-V-S-H-R
  3176 0000B5BE 7415                <1> 	jz	short msftdf_save_sf_structure
  3177                              <1> 
  3178                              <1> msftdf_permission_denied_retn:
  3179                              <1> 	;mov	eax, 05h ; Access (Permission) denied !
  3180                              <1> 	; 29/07/2022
  3181 0000B5C0 29C0                <1> 	sub	eax, eax
  3182 0000B5C2 B005                <1> 	mov	al, 5
  3183 0000B5C4 F9                  <1> 	stc
  3184                              <1> msftdf_rest_cdir_err_retn:
  3185                              <1> msftdf_return:
  3186 0000B5C5 C3                  <1> 	retn
  3187                              <1> 
  3188                              <1> msftdf_phase_1_return:
  3189 0000B5C6 31C0                <1> 	xor	eax, eax
  3190 0000B5C8 A2[6A880100]        <1> 	mov	[move_cmd_phase], al ; 0
  3191 0000B5CD FEC0                <1> 	inc	al ; mov al, 1
  3192 0000B5CF BB[1BB60000]        <1> 	mov	ebx, msftdf_df2_check_directory
  3193                              <1> 	;mov	edx, 0FFFFFFFFh 
  3194 0000B5D4 C3                  <1> 	retn
  3195                              <1> 
  3196                              <1> msftdf_save_sf_structure:
  3197 0000B5D5 BE[74860100]        <1> 	mov	esi, FindFile_DirEntry
  3198 0000B5DA BF[BA870100]        <1> 	mov	edi, SourceFile_DirEntry
  3199                              <1> 	;mov	ecx, 8
  3200                              <1> 	; 29/07/2022
  3201 0000B5DF 29C9                <1> 	sub	ecx, ecx
  3202 0000B5E1 B108                <1> 	mov	cl, 8
  3203 0000B5E3 F3A5                <1> 	rep	movsd
  3204                              <1> 
  3205                              <1> msftdf_df_copy_sf_parameters:
  3206 0000B5E5 BE0B000000          <1> 	mov	esi, 11
  3207 0000B5EA 89F7                <1> 	mov	edi, esi
  3208 0000B5EC 81C6[BA870100]      <1> 	add	esi, SourceFile_DirEntry
  3209 0000B5F2 81C7[3A880100]      <1> 	add	edi, DestinationFile_DirEntry
  3210                              <1> 	;mov	ecx, 21
  3211 0000B5F8 B115                <1> 	mov	cl, 21
  3212 0000B5FA F3A4                <1> 	rep	movsb
  3213                              <1> 
  3214                              <1> msftdf_restore_current_dir_2:
  3215 0000B5FC 803D[9B340100]00    <1> 	cmp	byte [Restore_CDIR], 0
  3216 0000B603 760D                <1> 	jna	short msftdf_df2_check_move_cmd_phase
  3217 0000B605 8B35[6C880100]      <1>  	mov	esi, [msftdf_drv_offset]
  3218 0000B60B E823C3FFFF          <1> 	call	restore_current_directory
  3219 0000B610 72B3                <1> 	jc	short msftdf_rest_cdir_err_retn
  3220                              <1> 
  3221                              <1> msftdf_df2_check_move_cmd_phase:
  3222 0000B612 803D[6A880100]01    <1> 	cmp	byte [move_cmd_phase], 1
  3223 0000B619 74AB                <1> 	je	short msftdf_phase_1_return
  3224                              <1> 
  3225                              <1> msftdf_df2_check_directory:
  3226 0000B61B BE[E9870100]        <1> 	mov	esi, DestinationFile_Directory
  3227 0000B620 803E20              <1> 	cmp	byte [esi], 20h
  3228 0000B623 760F                <1> 	jna	short msftdf_make_dfde_locate_ffe_on_directory
  3229                              <1> msftdf_df2_change_directory:
  3230 0000B625 FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  3231 0000B62B 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0
  3232 0000B62D E8FEEFFFFF          <1> 	call	change_current_directory
  3233 0000B632 7291                <1> 	jc	short msftdf_return
  3234                              <1> 
  3235                              <1> ;msftdf_df2_change_prompt_dir_string:
  3236                              <1> ;	call	change_prompt_dir_string
  3237                              <1> 
  3238                              <1> msftdf_make_dfde_locate_ffe_on_directory:
  3239                              <1> 	; Current directory fcluster <> Directory buffer cluster
  3240                              <1> 	; Current directory will be reloaded by
  3241                              <1> 	; 'locate_current_dir_file' procedure
  3242                              <1> 	;
  3243                              <1> 	;xor	ax, ax
  3244 0000B634 31C0                <1> 	xor	eax, eax
  3245 0000B636 89C1                <1> 	mov	ecx, eax
  3246 0000B638 6649                <1> 	dec	cx ; FFFFh
  3247                              <1> 		; CX = FFFFh -> find first deleted or free entry
  3248                              <1> 		; ESI would be ASCIIZ filename address if the call
  3249                              <1> 		; would not be for first free or deleted dir entry
  3250 0000B63A E844F2FFFF          <1> 	call	locate_current_dir_file
  3251                              <1> 	; 07/08/2022
  3252 0000B63F 733F                <1> 	jnc	short msftdf_make_dfde_set_ff_dir_entry
  3253                              <1> 
  3254                              <1> 	;cmp	eax, 2
  3255 0000B641 3C02                <1>         cmp	al, 2
  3256 0000B643 7537                <1> 	jne	short msftdf_error_retn
  3257                              <1> 
  3258                              <1> msftdf_add_new_dir_entry_check_fs:
  3259 0000B645 8B35[6C880100]      <1> 	mov	esi, [msftdf_drv_offset]
  3260 0000B64B A1[AE840100]        <1> 	mov 	eax, [DirBuff_Cluster]
  3261 0000B650 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  3262 0000B654 7711                <1> 	ja	short msftdf_add_new_subdir_cluster
  3263                              <1> 
  3264                              <1> msftdf_add_new_fs_subdir_section:
  3265                              <1> 	;CL=0, CH=E5h --> deleted entry, CH=0 --> free entry
  3266                              <1>         ;xor	cx, cx
  3267 0000B656 30ED                <1> 	xor	ch, ch ; cx = 0 --> add a new subdir section
  3268 0000B658 E8C20C0000          <1> 	call	add_new_fs_section
  3269 0000B65D 721E                <1>         jc	short msftdf_dsfde_error_retn
  3270                              <1> 	;mov	[createfile_LastDirCluster], eax
  3271                              <1> 
  3272 0000B65F E8B20E0000          <1> 	call	load_FS_sub_directory
  3273                              <1> 	;mov	ebx, Directory_Buffer
  3274 0000B664 7318                <1> 	jnc	short msftdf_add_new_fs_subdir_section_ok
  3275 0000B666 C3                  <1> 	retn
  3276                              <1> 
  3277                              <1> msftdf_add_new_subdir_cluster:
  3278 0000B667 E843150000          <1> 	call	add_new_cluster
  3279 0000B66C 720F                <1> 	jc	short msftdf_dsfde_error_retn
  3280                              <1> 
  3281                              <1> 	;mov	[createfile_LastDirCluster], eax
  3282                              <1> 
  3283 0000B66E E8690E0000          <1> 	call	load_FAT_sub_directory
  3284 0000B673 7309                <1> 	jnc	short msftdf_add_new_subdir_cluster_ok
  3285                              <1> 	; EBX = Directory buffer address
  3286                              <1> 
  3287                              <1> msftdf_ansdc_update_parent_dir_lmdt:
  3288                              <1> msftdf_make_dfde_err_upd_pdir_lmdt:
  3289 0000B675 50                  <1> 	push	eax
  3290 0000B676 E86EFAFFFF          <1> 	call	update_parent_dir_lmdt
  3291 0000B67B 58                  <1> 	pop	eax
  3292                              <1> 
  3293                              <1> msftdf_error_retn:
  3294 0000B67C F9                  <1> 	stc
  3295                              <1> msftdf_dsfde_restore_cdir_failed:
  3296                              <1> msftdf_dsfde_error_retn:
  3297 0000B67D C3                  <1> 	retn
  3298                              <1> 
  3299                              <1> msftdf_add_new_fs_subdir_section_ok:
  3300                              <1> msftdf_add_new_subdir_cluster_ok:
  3301 0000B67E 89DF                <1> 	mov	edi, ebx ; Directory buffer address
  3302                              <1> 
  3303                              <1> msftdf_make_dfde_set_ff_dir_entry:
  3304 0000B680 8B15[7C7D0100]      <1> 	mov	edx, [Current_Dir_FCluster]
  3305 0000B686 8915[D0880100]      <1> 	mov	[createfile_FFCluster], edx
  3306                              <1> 	; EDI = Directory entry offset
  3307 0000B68C BE[3A880100]        <1> 	mov	esi, DestinationFile_DirEntry
  3308                              <1> 	;mov	ecx, 8
  3309                              <1> 	; 29/07/2022
  3310 0000B691 29C9                <1> 	sub	ecx, ecx
  3311 0000B693 B108                <1> 	mov	cl, 8
  3312 0000B695 F3A5                <1> 	rep	movsd
  3313                              <1> 
  3314 0000B697 C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  3315 0000B69E E8AEF9FFFF          <1> 	call	save_directory_buffer
  3316 0000B6A3 72D0                <1> 	jc	short msftdf_make_dfde_err_upd_pdir_lmdt
  3317                              <1> 
  3318                              <1> msftdf_make_dfde_update_pdir_lmdt:
  3319 0000B6A5 E83FFAFFFF          <1> 	call	update_parent_dir_lmdt
  3320                              <1> 
  3321                              <1> msftdf_dsfde_restore_current_dir_1:
  3322 0000B6AA 803D[9B340100]00    <1> 	cmp	byte [Restore_CDIR], 0
  3323 0000B6B1 760D                <1> 	jna	short msftdf_dsfde_check_directory
  3324 0000B6B3 8B35[6C880100]      <1>  	mov	esi, [msftdf_drv_offset]
  3325 0000B6B9 E875C2FFFF          <1> 	call	restore_current_directory
  3326 0000B6BE 72BD                <1> 	jc	short msftdf_dsfde_restore_cdir_failed
  3327                              <1> 
  3328                              <1> msftdf_dsfde_check_directory:
  3329 0000B6C0 BE[69870100]        <1> 	mov	esi, SourceFile_Directory
  3330 0000B6C5 803E20              <1> 	cmp	byte [esi], 20h
  3331 0000B6C8 760F                <1> 	jna	short msftdf_dsfde_find_file
  3332                              <1> 
  3333                              <1> msftdf_dsfde_change_directory:
  3334 0000B6CA FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  3335 0000B6D0 28E4                <1> 	sub	ah, ah ; CD_COMMAND sign -> 0
  3336 0000B6D2 E859EFFFFF          <1> 	call	change_current_directory
  3337 0000B6D7 72A4                <1> 	jc	short msftdf_dsfde_error_retn
  3338                              <1> 
  3339                              <1> ;msftdf_dsfde_sf_change_prompt_dir_string:
  3340                              <1> ;	call	change_prompt_dir_string
  3341                              <1> 
  3342                              <1> msftdf_dsfde_find_file:
  3343 0000B6D9 BE[AA870100]        <1> 	mov	esi, SourceFile_Name  ; Offset 66
  3344 0000B6DE 668B460E            <1> 	mov	ax, [esi+14] ; 80 -> SourceFile_AttributesMask
  3345 0000B6E2 E883D4FFFF          <1> 	call	find_first_file
  3346 0000B6E7 7294                <1> 	jc	short msftdf_dsfde_error_retn
  3347                              <1> 
  3348                              <1> msftdf_dsfde_delete_direntry:
  3349 0000B6E9 8B35[6C880100]      <1> 	mov	esi, [msftdf_drv_offset]
  3350                              <1> 
  3351 0000B6EF 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  3352 0000B6F3 770A                <1> 	ja	short msftdf_delete_FAT_direntry
  3353                              <1> 
  3354 0000B6F5 30DB                <1> 	xor	bl, bl
  3355                              <1> 	; BL = 0 -> File
  3356                              <1> 	; EDI -> Directory buffer entry offset/address 
  3357 0000B6F7 E8230C0000          <1> 	call	delete_fs_directory_entry
  3358 0000B6FC 7315                <1> 	jnc	short msftdf_dsfde_restore_current_dir_2
  3359 0000B6FE C3                  <1> 	retn
  3360                              <1> 
  3361                              <1> msftdf_delete_FAT_direntry:
  3362 0000B6FF 8A1D[71860100]      <1> 	mov	bl, [FindFile_LongNameEntryLength]
  3363 0000B705 668B0D[9C860100]    <1> 	mov	cx, [FindFile_DirEntryNumber]
  3364                              <1> 	; ESI = Logical DOS drive description table address
  3365                              <1> 	; EDI = Directory buffer entry offset/address
  3366 0000B70C E8A0FCFFFF          <1> 	call	delete_directory_entry
  3367 0000B711 721C                <1> 	jc	short msftdf_retn
  3368                              <1> 
  3369                              <1> msftdf_dsfde_restore_current_dir_2:
  3370 0000B713 803D[9B340100]00    <1> 	cmp	byte [Restore_CDIR], 0
  3371 0000B71A 7607                <1> 	jna	short msftdf_new_dir_fcluster_retn
  3372                              <1> 	;mov	esi, [msftdf_drv_offset]
  3373 0000B71C E812C2FFFF          <1> 	call	restore_current_directory
  3374 0000B721 720C                <1> 	jc	short msftdf_retn
  3375                              <1> 
  3376                              <1> msftdf_new_dir_fcluster_retn:
  3377 0000B723 31C9                <1> 	xor	ecx, ecx 
  3378 0000B725 A1[D0880100]        <1> 	mov	eax, [createfile_FFCluster]
  3379 0000B72A BB[E8870100]        <1> 	mov	ebx, DestinationFile_Drv
  3380                              <1> 
  3381                              <1> msftdf_retn:
  3382 0000B72F C3                  <1> 	retn
  3383                              <1> 
  3384                              <1> copy_source_file_to_destination_file:
  3385                              <1> 	; 31/08/2024
  3386                              <1> 	; 30/08/2024
  3387                              <1> 	; 29/08/2024
  3388                              <1> 	; 26/08/2024
  3389                              <1> 	; 25/08/2024 (TRDOS 386 v2.0.9)
  3390                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  3391                              <1> 	; 17/10/2016
  3392                              <1> 	; 16/10/2016
  3393                              <1> 	; 15/10/2016
  3394                              <1> 	; 30/03/2016, 31/03/2016
  3395                              <1> 	; 24/03/2016, 25/03/2016, 28/03/2016
  3396                              <1> 	; 21/03/2016, 22/03/2016, 23/03/2016
  3397                              <1> 	; 16/03/2016, 17/03/2016, 18/03/2016
  3398                              <1> 	; 15/03/2016 (TRDOS 386 = TRDOS v2.0)
  3399                              <1> 	; 02/09/2011 (FILE.ASM 'copy_source_file_to_destination_file')
  3400                              <1> 	; 01/08/2010 - 18/05/2011
  3401                              <1> 	;
  3402                              <1> 	;   Command Interpreter phase 1 enter ->
  3403                              <1> 	;           AL = 1 -> Caller is command interpreter
  3404                              <1> 	;           AL = 2 -> The second call, re-enter/continue
  3405                              <1> 	;   Phase 1 -> Check source file
  3406                              <1> 	;              'found' is required
  3407                              <1> 	;   Phase 2 -> Check destination file,
  3408                              <1> 	;              save 'found' or 'not found' status
  3409                              <1> 	;              'permission denied' error will be return
  3410                              <1> 	;              if attributes have not for ordinary file
  3411                              <1> 	;              without readonly attribute
  3412                              <1> 	;   Command Interpreter phase 1 return ->
  3413                              <1> 	;              DH = Source file attributes
  3414                              <1> 	;              DL = Destination file found status
  3415                              <1> 	;              EAX = 0
  3416                              <1> 	;   Command Interpreter phase 2 enter ->
  3417                              <1> 	;              AL = 2 -> Continue from the last position
  3418                              <1> 	;              AH =
  3419                              <1> 	;   Phase 3 -> Load source file or use read/write cluster method
  3420                              <1> 	;   Phase 4 -> Create destination file if it is not found
  3421                              <1> 	;   Phase 5 -> Open destination file
  3422                              <1> 	;   Phase 6 -> Read from source and write to destination
  3423                              <1> 	;   Phase 7 -> Unload source file, if it is loaded at memory
  3424                              <1> 	;       cf = 1 causes to return before the phase 7
  3425                              <1> 	;              but loaded file will be unloaded
  3426                              <1> 	;	       (allocated memory block will be deallocated)
  3427                              <1> 	;
  3428                              <1> 	; INPUT ->
  3429                              <1> 	;	 ESI = Source File Pathname (Asciiz)
  3430                              <1> 	;        EDI = Destination File Pathname (Asciiz)
  3431                              <1> 	;        AL = 0 --> Interrupt (System call)
  3432                              <1> 	;        AL > 0 --> Command Interpreter (Question)
  3433                              <1> 	;        AL = 1 --> Question Phase
  3434                              <1> 	;        AL = 2 --> Progress Phase
  3435                              <1> 	;
  3436                              <1> 	; OUTPUT ->
  3437                              <1> 	;	cf = 0 -> OK ; (*)
  3438                              <1> 	;	EAX = Destination file first cluster
  3439                              <1> 	;
  3440                              <1> 	;	31/08/2024 - TRDOS v2.0.9 ; (*)
  3441                              <1> 	; obsolete ;CL > 0 if there is file reading error before EOF
  3442                              <1> 	;          ;	        (incomplete copy) 
  3443                              <1> 	;          ;CH > 0 if file is (full) loaded at memory
  3444                              <1> 	;
  3445                              <1> 	;	cf = 1 -> Error code in AL (EAX) ; (*)
  3446                              <1> 	;
  3447                              <1> 	; (EBX, ECX, ESI, EDI register contents will be changed)
  3448                              <1> 
  3449 0000B730 3C02                <1> 	cmp	al, 2
  3450                              <1> 	;je	csftdf2_check_cdrv
  3451                              <1> 	; 29/07/2022
  3452 0000B732 7205                <1> 	jb	short csftdf_ph1
  3453                              <1> 	;jmp	csftdf2_check_cdrv
  3454 0000B734 E942020000          <1> 	jmp	csftdf_ph2
  3455                              <1> 
  3456                              <1> ; Phase 1
  3457                              <1> 	; 29/07/2022
  3458                              <1> csftdf_ph1:
  3459 0000B739 A2[90880100]        <1> 	mov	byte [copy_cmd_phase], al
  3460                              <1> 
  3461 0000B73E 57                  <1> 	push	edi ; *
  3462                              <1> 
  3463                              <1> csftdf_parse_sf_path:
  3464 0000B73F BF[68870100]        <1> 	mov	edi, SourceFile_Drv
  3465 0000B744 E8D1F4FFFF          <1> 	call	parse_path_name
  3466 0000B749 721C                <1> 	jc	short csftdf_parse_sf_path_failed
  3467                              <1> 
  3468                              <1> csftdf_parse_df_path:
  3469 0000B74B 5E                  <1> 	pop	esi ; * (pushed edi)
  3470                              <1> 
  3471                              <1> csftdf_sf_check_filename_exists:
  3472 0000B74C 803D[AA870100]21    <1> 	cmp	byte [SourceFile_Name], 21h
  3473 0000B753 7214                <1> 	jb	short csftdf_sf_file_not_found_error
  3474                              <1> 
  3475 0000B755 BF[E8870100]        <1> 	mov	edi, DestinationFile_Drv
  3476 0000B75A E8BBF4FFFF          <1> 	call	parse_path_name
  3477 0000B75F 730E                <1> 	jnc	short csftdf_check_sf_cdrv
  3478                              <1> 
  3479 0000B761 3C01                <1> 	cmp	al, 1 ; File or directory name is not existing
  3480 0000B763 760A                <1> 	jna	short csftdf_check_sf_cdrv
  3481                              <1> 
  3482                              <1> csftdf_parse_df_path_failed:
  3483 0000B765 F9                  <1> 	stc 
  3484                              <1> csftdf_sf_error_retn:
  3485 0000B766 C3                  <1> 	retn
  3486                              <1> 
  3487                              <1> csftdf_parse_sf_path_failed:
  3488 0000B767 5F                  <1> 	pop	edi ; *
  3489                              <1> 	;jmp	short csftdf_sf_error_retn
  3490                              <1> 	; 25/08/2024
  3491 0000B768 C3                  <1> 	retn
  3492                              <1> 
  3493                              <1> csftdf_sf_file_not_found_error:
  3494 0000B769 B802000000          <1> 	mov	eax, 2 ; File not found
  3495                              <1> 	;jmp	short csftdf_sf_error_retn
  3496                              <1> 	; 25/08/2024
  3497 0000B76E C3                  <1> 	retn
  3498                              <1> 
  3499                              <1> csftdf_check_sf_cdrv:
  3500 0000B76F 8A3D[827D0100]      <1> 	mov	bh, [Current_Drv]
  3501                              <1> 
  3502 0000B775 883D[93880100]      <1> 	mov	[csftdf_cdrv], bh ; 23/03/2016
  3503                              <1> 
  3504 0000B77B 8A15[68870100]      <1> 	mov	dl, [SourceFile_Drv]
  3505 0000B781 38FA                <1> 	cmp	dl, bh ; byte [Current_Drv]
  3506 0000B783 7407                <1> 	je	short csftdf_sf_check_directory
  3507                              <1> 
  3508 0000B785 E8F3C0FFFF          <1> 	call	change_current_drive
  3509 0000B78A 72DA                <1> 	jc	short csftdf_sf_error_retn
  3510                              <1> 
  3511                              <1> csftdf_sf_check_directory:
  3512 0000B78C BE[69870100]        <1> 	mov	esi, SourceFile_Directory
  3513 0000B791 803E20              <1> 	cmp	byte [esi], 20h
  3514 0000B794 760F                <1> 	jna	short csftdf_find_sf
  3515                              <1> 
  3516                              <1> csftdf_sf_change_directory:
  3517 0000B796 FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  3518 0000B79C 30E4                <1> 	xor	ah, ah ; CD_COMMAND sign -> 0
  3519 0000B79E E88DEEFFFF          <1> 	call	change_current_directory
  3520 0000B7A3 72C1                <1> 	jc	short csftdf_sf_error_retn
  3521                              <1> 
  3522                              <1> ;csftdf_sf_change_prompt_dir_string:
  3523                              <1> ;	call	change_prompt_dir_string
  3524                              <1> 
  3525                              <1> csftdf_find_sf:
  3526 0000B7A5 BE[AA870100]        <1> 	mov	esi, SourceFile_Name
  3527 0000B7AA 66B80018            <1> 	mov	ax, 1800h ; Except volume label and dirs
  3528 0000B7AE E8B7D3FFFF          <1> 	call	find_first_file
  3529 0000B7B3 72B1                <1> 	jc	short csftdf_sf_error_retn
  3530                              <1> 
  3531                              <1> csftdf_sf_ambgfn_check:
  3532 0000B7B5 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3533 0000B7B8 7406                <1> 	jz	short csftdf_sf_found
  3534                              <1> 
  3535                              <1> csftdf_ambiguous_file_name_error:
  3536                              <1> 	;mov	eax, 2 ; File not found error
  3537                              <1> 	; 29/07/2022
  3538 0000B7BA 29C0                <1> 	sub	eax, eax
  3539 0000B7BC B002                <1> 	mov	al, 2
  3540 0000B7BE F9                  <1> 	stc
  3541 0000B7BF C3                  <1> 	retn
  3542                              <1> 
  3543                              <1> csftdf_sf_found:
  3544 0000B7C0 A3[94880100]        <1> 	mov	[csftdf_filesize], eax
  3545                              <1> 
  3546 0000B7C5 09C0                <1> 	or	eax, eax
  3547 0000B7C7 7504                <1> 	jnz	short csftdf_set_source_file_direntry
  3548                              <1> 
  3549                              <1> ;csftdf_sf_file_size_zero:
  3550                              <1> 	;mov	eax, 20 ; TRDOS zero length (file size) error
  3551                              <1> 	; 25/08/2024
  3552                              <1> 	; eax = 0
  3553                              <1> 	; 29/07/2022
  3554                              <1> 	;sub	eax, eax
  3555 0000B7C9 B014                <1> 	mov	al, 20
  3556 0000B7CB F9                  <1> 	stc
  3557 0000B7CC C3                  <1> 	retn
  3558                              <1> 
  3559                              <1> csftdf_set_source_file_direntry:
  3560 0000B7CD BE[74860100]        <1> 	mov	esi, FindFile_DirEntry
  3561 0000B7D2 BF[BA870100]        <1> 	mov	edi, SourceFile_DirEntry
  3562                              <1> 	;mov	ecx, 8
  3563                              <1> 	; 29/07/2022
  3564 0000B7D7 31C9                <1> 	xor	ecx, ecx
  3565 0000B7D9 B108                <1> 	mov	cl, 8
  3566 0000B7DB F3A5                <1> 	rep	movsd
  3567                              <1> 
  3568                              <1> csftdf_sf_restore_cdrv:
  3569                              <1> 	; 22/03/2016
  3570 0000B7DD 8A15[93880100]      <1> 	mov	dl, [csftdf_cdrv]
  3571 0000B7E3 3A15[827D0100]      <1> 	cmp	dl, [Current_Drv]
  3572 0000B7E9 7407                <1> 	je	short csftdf_sf_restore_cdir
  3573 0000B7EB E88DC0FFFF          <1> 	call	change_current_drive
  3574 0000B7F0 724F                <1> 	jc	short csftdf_df_error_retn ; 30/03/2016
  3575                              <1> 
  3576                              <1> csftdf_sf_restore_cdir:
  3577 0000B7F2 803D[9B340100]00    <1> 	cmp	byte [Restore_CDIR], 0
  3578 0000B7F9 7612                <1> 	jna	short csftdf_df_check_filename_exists
  3579 0000B7FB 29C0                <1> 	sub	eax, eax
  3580 0000B7FD BE00010900          <1> 	mov	esi, Logical_DOSDisks
  3581 0000B802 88D4                <1> 	mov	ah, dl ; byte [csftdf_cdrv]
  3582 0000B804 01C6                <1> 	add	esi, eax
  3583 0000B806 E828C1FFFF          <1> 	call	restore_current_directory
  3584 0000B80B 7234                <1> 	jc	short csftdf_df_error_retn
  3585                              <1> 
  3586                              <1> csftdf_df_check_filename_exists:
  3587 0000B80D 803D[2A880100]20    <1> 	cmp	byte [DestinationFile_Name], 20h
  3588 0000B814 7716                <1> 	ja	short csftdf_check_df_cdrv
  3589                              <1> 
  3590                              <1> csftdf_copy_sf_name:
  3591 0000B816 BF[2A880100]        <1> 	mov	edi, DestinationFile_Name
  3592 0000B81B BE[AA870100]        <1> 	mov	esi, SourceFile_Name
  3593 0000B820 B10C                <1> 	mov	cl, 12
  3594                              <1> 
  3595                              <1> csftdf_df_copy_sf_name_loop:
  3596 0000B822 AC                  <1> 	lodsb
  3597 0000B823 AA                  <1> 	stosb
  3598 0000B824 08C0                <1> 	or	al, al
  3599 0000B826 7404                <1> 	jz	short csftdf_check_df_cdrv
  3600 0000B828 FEC9                <1> 	dec	cl
  3601 0000B82A 75F6                <1> 	jnz	csftdf_df_copy_sf_name_loop
  3602                              <1> 
  3603                              <1> csftdf_check_df_cdrv:
  3604 0000B82C 8A15[E8870100]      <1> 	mov	dl, [DestinationFile_Drv]
  3605 0000B832 3A15[827D0100]      <1> 	cmp	dl, [Current_Drv]
  3606 0000B838 7408                <1> 	je	short csftdf_df_check_directory
  3607                              <1> 
  3608 0000B83A E83EC0FFFF          <1> 	call	change_current_drive
  3609 0000B83F 7301                <1> 	jnc	short csftdf_df_check_directory
  3610                              <1> 
  3611                              <1> csftdf_df_error_retn:
  3612 0000B841 C3                  <1> 	retn
  3613                              <1> 
  3614                              <1> csftdf_df_check_directory:
  3615 0000B842 BE[E9870100]        <1> 	mov	esi, DestinationFile_Directory
  3616 0000B847 803E20              <1>         cmp     byte [esi], 20h
  3617 0000B84A 760F                <1> 	jna	short csftdf_find_df
  3618                              <1> 
  3619                              <1> csftdf_df_change_directory:
  3620 0000B84C FE05[9B340100]      <1> 	inc	byte [Restore_CDIR]
  3621 0000B852 28E4                <1> 	sub	ah, ah ; CD_COMMAND sign -> 0
  3622 0000B854 E8D7EDFFFF          <1> 	call	change_current_directory
  3623 0000B859 72E6                <1> 	jc	short csftdf_df_error_retn
  3624                              <1> 
  3625                              <1> ;csftdf_df_change_prompt_dir_string:
  3626                              <1> ;	call	change_prompt_dir_string
  3627                              <1> 
  3628                              <1> csftdf_find_df:
  3629                              <1> 	; 23/03/2016
  3630 0000B85B 29DB                <1> 	sub	ebx, ebx
  3631 0000B85D 8A3D[E8870100]      <1> 	mov	bh, [DestinationFile_Drv]
  3632 0000B863 81C300010900        <1> 	add	ebx, Logical_DOSDisks
  3633 0000B869 891D[C0880100]      <1> 	mov	[csftdf_df_drv_dt], ebx
  3634                              <1> 
  3635 0000B86F BE[2A880100]        <1> 	mov	esi, DestinationFile_Name
  3636                              <1> 	;xor	ax, ax
  3637                              <1> 	; 25/08/2024
  3638 0000B874 31C0                <1> 	xor	eax, eax
  3639                              <1> 		; DestinationFile_AttributesMask -> any/zero
  3640 0000B876 E8EFD2FFFF          <1> 	call	find_first_file
  3641 0000B87B 7217                <1> 	jc	short csftdf_df_check_error_code
  3642                              <1> 
  3643                              <1> csftdf_df_ambgfn_check:
  3644 0000B87D 6609D2              <1> 	or	dx, dx ; Ambiguous filename chars used sign (DX>0)
  3645 0000B880 7529                <1> 	jnz	short csftdf_df_error_inv_fname
  3646                              <1> 
  3647                              <1> csftdf_df_found:
  3648 0000B882 C605[92880100]01    <1> 	mov	byte [DestinationFileFound], 1
  3649                              <1> 	; 17/10/2016 (cl -> bl)
  3650 0000B889 80E31F              <1> 	and	bl, 1Fh ; Attributes, D-V-S-H-R
  3651 0000B88C 7451                <1> 	jz	short csftdf_df_save_first_cluster
  3652                              <1> 
  3653                              <1> csftdf_df_permission_denied_retn:
  3654                              <1> 	;mov	eax, 05h ; Access/Permission denied.
  3655                              <1> 	; 29/07/2022
  3656 0000B88E 29C0                <1> 	sub	eax, eax
  3657 0000B890 B005                <1> 	mov	al, 5
  3658                              <1> csftdf_df_error_stc_retn:
  3659 0000B892 F9                  <1> 	stc
  3660 0000B893 C3                  <1> 	retn
  3661                              <1> 
  3662                              <1> csftdf_df_check_error_code:
  3663                              <1> 	;cmp	eax, 2
  3664 0000B894 3C02                <1> 	cmp	al, 2
  3665 0000B896 75FA                <1> 	jne	short csftdf_df_error_stc_retn
  3666                              <1> 
  3667 0000B898 C605[92880100]00    <1> 	mov	byte [DestinationFileFound], 0
  3668                              <1> 
  3669                              <1> 	; 15/10/2016
  3670 0000B89F BE[64860100]        <1> 	mov	esi, FindFile_Name ; *
  3671 0000B8A4 E866D6FFFF          <1> 	call	check_filename
  3672 0000B8A9 7306                <1> 	jnc	short csftdf_df_valid_fname
  3673                              <1> csftdf_df_error_inv_fname: ; 'invalid file name !'
  3674                              <1> 	;mov 	eax, ERR_INV_FILE_NAME  ; 26
  3675                              <1> 	; 29/07/2022
  3676 0000B8AB 29C0                <1> 	sub	eax, eax
  3677 0000B8AD B01A                <1> 	mov	al, ERR_INV_FILE_NAME ; 26
  3678 0000B8AF F9                  <1> 	stc
  3679 0000B8B0 C3                  <1> 	retn
  3680                              <1> 
  3681                              <1> csftdf_df_valid_fname:
  3682                              <1> 	; 21/03/2016
  3683                              <1> 	; (Capitalized file name)
  3684                              <1> 	;mov	esi, FindFile_Name ; * ; 15/10/2016
  3685 0000B8B1 BF[2A880100]        <1> 	mov	edi, DestinationFile_Name
  3686 0000B8B6 A5                  <1> 	movsd
  3687 0000B8B7 A5                  <1> 	movsd
  3688 0000B8B8 A5                  <1> 	movsd
  3689                              <1> 	;movsb
  3690                              <1> 
  3691                              <1> csftdf_check_disk_free_size_0:
  3692 0000B8B9 A1[D6870100]        <1> 	mov	eax, [SourceFile_DirEntry+DirEntry_FileSize]
  3693                              <1> 
  3694                              <1> csftdf_check_disk_free_size_1:
  3695                              <1> 	;sub	ebx, ebx
  3696                              <1> 	;mov 	esi, Logical_DOSDisks
  3697                              <1> 	;mov	bh,  [DestinationFile_Drv]
  3698                              <1> 	;add	esi, ebx
  3699                              <1> 
  3700 0000B8BE 8B35[C0880100]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 23/03/2016
  3701                              <1> 
  3702 0000B8C4 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 17, LD_BPB + 0Bh
  3703 0000B8C8 01C8                <1> 	add	eax, ecx
  3704 0000B8CA 48                  <1> 	dec	eax  ; file size (additional bytes) + 511 (round up)
  3705                              <1> csftdf_check_disk_free_size_3: ; 16/03/2016
  3706 0000B8CB 29D2                <1> 	sub	edx, edx
  3707 0000B8CD F7F1                <1> 	div	ecx ; bytes per sector
  3708                              <1> 
  3709                              <1> csftdf_check_disk_free_size:
  3710 0000B8CF 3B4674              <1> 	cmp	eax, [esi+LD_FreeSectors]
  3711                              <1>         ;jb	csftdf_check_disk_free_size_ok
  3712                              <1> 	; 25/08/2024
  3713                              <1> 	; 29/07/2022
  3714                              <1> 	;jb	short csftdf_check_dfs_ok
  3715 0000B8D2 7705                <1> 	ja	short csftdf_df_insufficient_disk_space
  3716                              <1> 
  3717                              <1> 	; 25/08/2024
  3718                              <1> 	;cmp	byte [esi+LD_FATType], 0 ; FS needs FDT sector also.
  3719                              <1> 	;;ja	csftdf_check_disk_free_size_ok
  3720                              <1> 	;; 29/07/2022
  3721                              <1> 	;jna	short csftdf_df_insufficient_disk_space
  3722                              <1> 
  3723                              <1> csftdf_check_dfs_ok:
  3724 0000B8D4 E985000000          <1> 	jmp	csftdf_check_disk_free_size_ok
  3725                              <1> 
  3726                              <1> csftdf_df_insufficient_disk_space:
  3727                              <1> 	;mov	eax, 27h ; insufficient disk space
  3728                              <1> 	; 29/07/2022
  3729 0000B8D9 29C0                <1> 	sub	eax, eax
  3730 0000B8DB B027                <1> 	mov	al, 27h
  3731                              <1> 	;jmp	short csftdf_df_error_stc_retn
  3732                              <1> 	; 25/08/2024
  3733 0000B8DD F9                  <1> 	stc
  3734 0000B8DE C3                  <1> 	retn
  3735                              <1> 
  3736                              <1> csftdf_df_save_first_cluster:
  3737                              <1> 	; ESI = FindFile_DirEntry (for the old destination file)
  3738                              <1> 	; EAX = Old destination file size
  3739                              <1> 	; 24/03/2016
  3740                              <1> 	; EDI = Directory entry address (within Dir Buffer boundaries)
  3741 0000B8DF 81EF00000800        <1> 	sub	edi, Directory_Buffer  ; (<65536)
  3742                              <1> 	;shr	di, 5 ; Convert entry offset to entry index/number
  3743                              <1> 	; 29/07/2022
  3744 0000B8E5 C1EF05              <1> 	shr	edi, 5
  3745 0000B8E8 66893D[62880100]    <1> 	mov	[DestinationFile_DirEntryNumber], di ; (<2048)
  3746                              <1> 
  3747                              <1> csftdf_df_check_sf_df_fcluster:
  3748 0000B8EF 668B5614            <1> 	mov	dx, [esi+DirEntry_FstClusHI]
  3749 0000B8F3 C1E210              <1> 	shl	edx, 16
  3750 0000B8F6 668B561A            <1> 	mov	dx, [esi+DirEntry_FstClusLO]
  3751 0000B8FA 8915[A4880100]      <1> 	mov	[csftdf_df_cluster], edx
  3752                              <1> csftdf_df_check_sf_df_fcluster_1:
  3753 0000B900 668B15[CE870100]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusHI]
  3754 0000B907 C1E210              <1> 	shl	edx, 16
  3755 0000B90A 668B15[D4870100]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusLO]
  3756 0000B911 3B15[A4880100]      <1> 	cmp	edx, [csftdf_df_cluster]
  3757 0000B917 7512                <1> 	jne	short csftdf_df_check_sf_df_fcluster_ok
  3758                              <1> csftdf_df_check_sf_df_drv:
  3759 0000B919 8A15[68870100]      <1> 	mov	dl, [SourceFile_Drv]
  3760 0000B91F 3A15[E8870100]      <1> 	cmp	dl, [DestinationFile_Drv]
  3761 0000B925 7504                <1> 	jne	short csftdf_df_check_sf_df_fcluster_ok
  3762                              <1> 
  3763                              <1> 	; source and destination files are same !
  3764                              <1> 	; (they have same first cluster value on same logical disk)
  3765                              <1> 
  3766 0000B927 31C0                <1> 	xor	eax, eax ; mov eax, 0 -> Bad command or file name !
  3767 0000B929 F9                  <1> 	stc
  3768 0000B92A C3                  <1> 	retn
  3769                              <1> 
  3770                              <1> csftdf_df_check_sf_df_fcluster_ok:
  3771                              <1> csftdf_df_move_findfile_struct:
  3772                              <1> 	; mov	esi, FindFile_DirEntry
  3773 0000B92B BF[3A880100]        <1> 	mov	edi, DestinationFile_DirEntry
  3774                              <1> 	;mov	ecx, 8
  3775 0000B930 31C9                <1> 	xor	ecx, ecx
  3776 0000B932 B108                <1> 	mov	cl, 8
  3777 0000B934 F3A5                <1> 	rep	movsd
  3778                              <1> 
  3779                              <1> ;csftdf_check_disk_free_size_2:
  3780 0000B936 89C2                <1> 	mov	edx, eax ; Old destination file size
  3781                              <1> 
  3782                              <1> 	;mov	eax, [SourceFile_DirEntry+DirEntry_FileSize]
  3783 0000B938 A1[94880100]        <1> 	mov	eax, [csftdf_filesize] ; 23/03/2016
  3784                              <1> 
  3785                              <1> 	;;sub	ecx, ecx ; 0
  3786                              <1> 	;mov 	esi, Logical_DOSDisks
  3787                              <1> 	;mov	ch, [DestinationFile_Drv]
  3788                              <1> 	;add	esi, ecx
  3789                              <1> 	;
  3790                              <1> 	;mov	[csftdf_df_drv_dt], esi
  3791                              <1> 
  3792 0000B93D 8B35[C0880100]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 23/03/2016
  3793                              <1> 
  3794 0000B943 668B4E11            <1> 	mov	cx, [esi+LD_BPB+BytesPerSec] ; 17, LD_BPB + 0Bh
  3795 0000B947 01CA                <1> 	add	edx, ecx ; + 512
  3796 0000B949 01C8                <1> 	add	eax, ecx ; + 512
  3797 0000B94B 4A                  <1> 	dec	edx ; old file size + 511 (round up)
  3798 0000B94C 48                  <1> 	dec	eax ; new file size + 511 (round up)
  3799 0000B94D F7D9                <1> 	neg	ecx ; -512 ; 0FFFFFE00h
  3800 0000B94F 21CA                <1> 	and	edx, ecx ; = old sector count * 512
  3801 0000B951 21C8                <1> 	and	eax, ecx ; = new sector count * 512
  3802                              <1> 
  3803 0000B953 29D0                <1> 	sub	eax, edx ; new file size - old file size (on disk)
  3804 0000B955 7607                <1> 	jna	short csftdf_check_disk_free_size_ok
  3805                              <1> 
  3806 0000B957 F7D9                <1> 	neg	ecx ; 512 (bytes per sector) ; 200h
  3807                              <1> 	; check free space for additional sectors
  3808                              <1> 	; eax = number of additional sectors * bytes per sector
  3809                              <1> 	; esi = Logical DOS drive number (of destination disk)
  3810 0000B959 E96DFFFFFF          <1>         jmp	csftdf_check_disk_free_size_3
  3811                              <1> 
  3812                              <1> csftdf_check_disk_free_size_ok:
  3813                              <1> 	; 18/03/2016
  3814                              <1> csftdf_df_check_copy_cmd_phase:
  3815 0000B95E A0[90880100]        <1> 	mov	al, [copy_cmd_phase]
  3816 0000B963 3C01                <1> 	cmp	al, 1
  3817 0000B965 7514                <1> 	jne	short csftdf2_check_cdrv
  3818                              <1> 
  3819 0000B967 31C0                <1> 	xor	eax, eax
  3820 0000B969 A2[90880100]        <1> 	mov	[copy_cmd_phase], al ; 0
  3821                              <1> 
  3822 0000B96E 8A15[92880100]      <1> 	mov	dl, [DestinationFileFound]
  3823 0000B974 8A35[C5870100]      <1> 	mov	dh, [SourceFile_DirEntry+11] ; Attributes
  3824                              <1> 
  3825                              <1> csftdf_return:
  3826 0000B97A C3                  <1> 	retn
  3827                              <1> 
  3828                              <1> ; Phase 2
  3829                              <1> csftdf_ph2:
  3830                              <1> 	; 29/07/2022
  3831                              <1> csftdf2_check_cdrv:
  3832                              <1> 	; 18/03/2016
  3833                              <1> 	; Here, destination drive and directory are ready !
  3834                              <1> 	; (checking/restoring is not needed)
  3835                              <1> 	; (Since at the end of the phase 1)
  3836                              <1> 
  3837                              <1> ;	mov	dl, [DestinationFile_Drv]
  3838                              <1> ;	cmp	dl, [Current_Drv]
  3839                              <1> ;	je	short csftdf2_df_check_directory
  3840                              <1> ;
  3841                              <1> ;	call	change_current_drive
  3842                              <1> ;	jc	short csftdf2_read_error
  3843                              <1> ;
  3844                              <1> ;csftdf2_df_check_directory:
  3845                              <1> ;	mov	esi, DestinationFile_Directory
  3846                              <1> ;	cmp	byte [esi], 20h
  3847                              <1> ;	jna	short csftdf2_df_check_found_or_not
  3848                              <1> ;
  3849                              <1> ;csftdf2_df_change_directory:
  3850                              <1> ;	inc	byte [Restore_CDIR]
  3851                              <1> ;	xor	ah, ah ; CD_COMMAND sign -> 0
  3852                              <1> ;	call	change_current_directory
  3853                              <1> ;	jc	short csftdf2_stc_return
  3854                              <1> ;
  3855                              <1> ;;csftdf2_df_change_prompt_dir_string:
  3856                              <1> ;;	call	change_prompt_dir_string
  3857                              <1> 
  3858                              <1> csftdf2_df_check_found_or_not:
  3859                              <1> 	; 21/03/2016
  3860 0000B97B 803D[92880100]00    <1> 	cmp	byte [DestinationFileFound], 0
  3861 0000B982 7742                <1> 	ja	short csftdf2_set_sf_percentage
  3862                              <1> 
  3863                              <1> csftdf2_create_file:
  3864 0000B984 BE[2A880100]        <1> 	mov	esi, DestinationFile_Name
  3865 0000B989 A1[94880100]        <1> 	mov	eax, [csftdf_filesize]
  3866 0000B98E 30C9                <1> 	xor	cl, cl ; 0
  3867                              <1> 
  3868 0000B990 31DB                <1> 	xor	ebx, ebx ; 0
  3869 0000B992 4B                  <1> 	dec	ebx ; 0FFFFFFFFh 
  3870                              <1> 
  3871                              <1> 	; INPUT ->
  3872                              <1> 	; 	EAX -> File Size
  3873                              <1> 	; 	ESI = ASCIIZ File name
  3874                              <1> 	;	 CL = File attributes
  3875                              <1> 	;	EBX = FFFFFFFFh -> empty file sign for FAT fs
  3876                              <1> 	;	EBX <> FFFFFFFFh -> use file size for FAT fs 
  3877                              <1> 	;
  3878                              <1> 	; OUTPUT ->
  3879                              <1> 	;	EAX = New file's first cluster
  3880                              <1> 	;		 (0 for empty file) ; 29/08/2024
  3881                              <1> 	;	ESI = Logical Dos Drv Descr. Table Addr.
  3882                              <1> 	;	;EBX = CreateFile_Size address
  3883                              <1> 	;	;ECX = Sectors per cluster (<256)
  3884                              <1> 	;	;EDX = Directory Entry Index/Number (<65536)
  3885                              <1> 	;	; 29/08/2024
  3886                              <1> 	;	EBX = File Size (0 for a new, empty file)
  3887                              <1> 	;	ECX = Directory Entry Index/Number (<2048)
  3888                              <1> 	;	     (in directory cluster, not in directory)
  3889                              <1> 	;	EDX = Directory Cluster Number (of the file)
  3890                              <1> 	;	
  3891                              <1> 	;	cf = 1 -> error code in AL (EAX)
  3892                              <1> 
  3893 0000B993 E84E060000          <1> 	call	create_file
  3894                              <1> 	;pop	esi
  3895                              <1> 	;jc	csftdf2_rw_error
  3896                              <1> 	; 29/07/2022
  3897 0000B998 7305                <1> 	jnc	short csftdf2_create_file_OK
  3898 0000B99A E9B9050000          <1> 	jmp	csftdf2_rw_error
  3899                              <1> 
  3900                              <1> csftdf2_create_file_OK:
  3901                              <1> 
  3902 0000B99F A3[A4880100]        <1> 	mov	[csftdf_df_cluster], eax
  3903                              <1> 	; 27/08/2024
  3904                              <1> 	; eax = 0
  3905                              <1> 
  3906                              <1> 	; 24/03/2016
  3907                              <1> 	;mov	[DestinationFile_DirEntryNumber], dx
  3908                              <1> 	; 29/08/2024
  3909                              <1> 	; (these 3 parameters are needed for
  3910                              <1> 	;  loading same dir entry for first cluster update)
  3911 0000B9A4 8915[5E880100]      <1> 	mov	[DestinationFile_DirCluster], edx
  3912 0000B9AA 66890D[62880100]    <1> 	mov	[DestinationFile_DirEntryNumber], cx
  3913                              <1> 
  3914                              <1> 	; 30/08/2024
  3915                              <1> 	; edx -> ecx
  3916                              <1> 	; 21/03/2016
  3917 0000B9B1 BE00000800          <1> 	mov	esi, Directory_Buffer
  3918                              <1> 	;shl	edx, 5 ; 32 * index number
  3919 0000B9B6 C1E105              <1> 	shl	ecx, 5
  3920                              <1> 	;add	esi, edx
  3921 0000B9B9 01CE                <1> 	add	esi, ecx
  3922 0000B9BB BF[3A880100]        <1> 	mov	edi, DestinationFile_DirEntry
  3923                              <1> 	;mov	cl, 8 ; 32 bytes
  3924                              <1> 	; 29/08/2024
  3925 0000B9C0 29C9                <1> 	sub	ecx, ecx
  3926 0000B9C2 B108                <1> 	mov	cl,8
  3927 0000B9C4 F3A5                <1> 	rep	movsd
  3928                              <1> 
  3929                              <1> 	;mov	cl, [esi] ; L.D.D.D.T.
  3930                              <1> 	;mov	[DestinationFile_Drv], cl
  3931                              <1> 
  3932                              <1> csftdf2_set_sf_percentage:
  3933                              <1> 	; 17/03/2016
  3934 0000B9C6 31C0                <1> 	xor	eax, eax
  3935 0000B9C8 A2[B8880100]        <1> 	mov 	[csftdf_percentage], al ; 0, reset
  3936                              <1> 
  3937 0000B9CD A3[B0880100]        <1> 	mov	[csftdf_sf_rbytes], eax ; 0, reset
  3938 0000B9D2 A3[B4880100]        <1> 	mov	[csftdf_df_wbytes], eax ; 0, reset
  3939                              <1> 
  3940 0000B9D7 8A25[68870100]      <1> 	mov	ah, [SourceFile_Drv]
  3941 0000B9DD BE00010900          <1> 	mov	esi, Logical_DOSDisks
  3942 0000B9E2 01C6                <1> 	add	esi, eax
  3943                              <1> 
  3944 0000B9E4 8935[BC880100]      <1> 	mov	[csftdf_sf_drv_dt], esi ; 23/03/2016
  3945                              <1> 
  3946 0000B9EA 668B15[CE870100]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusHI]
  3947 0000B9F1 C1E210              <1> 	shl	edx, 16
  3948 0000B9F4 668B15[D4870100]    <1> 	mov	dx, [SourceFile_DirEntry+DirEntry_FstClusLO]
  3949 0000B9FB 8915[A0880100]      <1> 	mov	[csftdf_sf_cluster], edx
  3950                              <1> 
  3951                              <1> 	; 16/03/2016
  3952                              <1> 	; Note: Singlix FS boot sector parameters (for cluster
  3953                              <1> 	;	related calculations) has same offset
  3954                              <1> 	;	values from LD_BPB as in FAT file system.
  3955                              <1> 	;	[esi+LD_BPB+SecPerClust] is 1 for Singlix FS.
  3956                              <1> 	;
  3957 0000BA01 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  3958 0000BA05 880D[E6870100]      <1> 	mov	[SourceFile_SecPerClust], cl
  3959                              <1> 
  3960                              <1> 	; 17/03/2016
  3961 0000BA0B 386E03              <1> 	cmp	[esi+LD_FATType], ch ; 0
  3962 0000BA0E 7707                <1> 	ja	short csftdf2_set_sf_percent_rsize1
  3963                              <1> 
  3964 0000BA10 B800000100          <1> 	mov	eax, 65536 ; read/write buffer size for Singlix FS
  3965 0000BA15 EB06                <1> 	jmp	short csftdf2_set_sf_percent_rsize2
  3966                              <1> 
  3967                              <1> csftdf2_set_sf_percent_rsize1:
  3968 0000BA17 668B4611            <1> 	mov	ax, [esi+LD_BPB+BytesPerSec]
  3969 0000BA1B F7E1                <1> 	mul	ecx
  3970                              <1> 	;sub	edx, edx
  3971                              <1> csftdf2_set_sf_percent_rsize2:
  3972 0000BA1D A3[A8880100]        <1> 	mov	[csftdf_r_size], eax
  3973                              <1> 
  3974                              <1> csftdf2_set_df_percentage:
  3975                              <1> 	;sub	eax, eax
  3976                              <1> 	;mov	ah, [DestinationFile_Drv]
  3977                              <1> 	;mov	edi, Logical_DOSDisks
  3978                              <1> 	;add	edi, eax
  3979                              <1> 	;mov	[csftdf_df_drv_dt], edi ; 17/03/2016
  3980                              <1> 
  3981 0000BA22 8B3D[C0880100]      <1> 	mov	edi, [csftdf_df_drv_dt] ; 23/03/2016
  3982                              <1> 
  3983                              <1> 	; 16/03/2016
  3984                              <1> 	; Note: Singlix FS boot sector parameters (for cluster
  3985                              <1> 	;	related calculations) has same offset
  3986                              <1> 	;	values from LD_BPB as in FAT file system.
  3987                              <1> 	;	[edi+LD_BPB+SecPerClust] is 1 for Singlix FS.
  3988                              <1> 	;	
  3989                              <1> 	;movzx	ecx, byte [edi+LD_BPB+SecPerClust]
  3990 0000BA28 8A4F13              <1> 	mov	cl, [edi+LD_BPB+SecPerClust]
  3991 0000BA2B 880D[66880100]      <1> 	mov	[DestinationFile_SecPerClust], cl
  3992                              <1> 
  3993                              <1> 	; 17/03/2016
  3994 0000BA31 386F03              <1> 	cmp	[edi+LD_FATType], ch ; 0
  3995 0000BA34 7707                <1> 	ja	short csftdf2_set_df_percent_wsize1
  3996                              <1> 
  3997 0000BA36 B800000100          <1> 	mov	eax, 65536 ; read/write buffer size for Singlix FS
  3998 0000BA3B EB06                <1> 	jmp	short csftdf2_set_df_percent_wsize2
  3999                              <1> 
  4000                              <1> csftdf2_set_df_percent_wsize1:
  4001 0000BA3D 0FB74711            <1> 	movzx	eax, word [edi+LD_BPB+BytesPerSec]
  4002 0000BA41 F7E1                <1> 	mul	ecx
  4003                              <1> 	;sub	edx, edx
  4004                              <1> csftdf2_set_df_percent_wsize2:
  4005 0000BA43 A3[AC880100]        <1> 	mov	[csftdf_w_size], eax
  4006                              <1> 
  4007 0000BA48 A1[94880100]        <1> 	mov	eax, [csftdf_filesize]
  4008                              <1> 
  4009 0000BA4D 3D00000100          <1> 	cmp	eax, 65536 ; 64KB	; small file
  4010 0000BA52 721F                <1> 	jb	short csftdf2_load_file ; do not display percentage
  4011                              <1> 
  4012                              <1> csftdf2_reset_wf_percent_ptr_chk_64k:
  4013 0000BA54 B201                <1> 	mov	dl, 1 ; 25/03/2016
  4014                              <1> 
  4015 0000BA56 3D00000400          <1> 	cmp	eax, 65536*4 ; 256KB
  4016 0000BA5B 7310                <1> 	jnb	short csftdf2_enable_percentage_display ; big file
  4017                              <1> 
  4018                              <1> 	; 64-128KB file size for floppy disks
  4019 0000BA5D 3815[68870100]      <1> 	cmp	byte [SourceFile_Drv], dl ; 1 ; read from floppy disk ?
  4020 0000BA63 7608                <1> 	jna	short csftdf2_enable_percentage_display
  4021                              <1> 
  4022 0000BA65 3815[E8870100]      <1> 	cmp	byte [DestinationFile_Drv], dl ; 1 ; write to floppy disk ?
  4023 0000BA6B 7706                <1> 	ja	short csftdf2_load_file
  4024                              <1> 
  4025                              <1> csftdf2_enable_percentage_display:
  4026 0000BA6D 8815[B8880100]      <1> 	mov	[csftdf_percentage], dl ; 1
  4027                              <1> 
  4028                              <1> csftdf2_load_file:
  4029                              <1> 	; 13/05/2016
  4030                              <1> 	; 19/03/2016
  4031                              <1> 	; 18/03/2016
  4032                              <1> 	; 17/03/2016
  4033 0000BA73 B40F                <1> 	mov	ah, 0Fh
  4034 0000BA75 E8AA5CFFFF          <1> 	call	_int10h
  4035                              <1> 	; 13/05/2016
  4036 0000BA7A 883D[B9880100]      <1> 	mov	[csftdf_videopage], bh ; active video page
  4037 0000BA80 B403                <1> 	mov	ah, 03h
  4038 0000BA82 E89D5CFFFF          <1> 	call	_int10h
  4039 0000BA87 668915[BA880100]    <1> 	mov	[csftdf_cursorpos], dx
  4040                              <1> 
  4041 0000BA8E 29C0                <1> 	sub	eax, eax
  4042 0000BA90 A2[91880100]        <1> 	mov	[csftdf_rw_err], al ; 0
  4043                              <1> 
  4044                              <1> ; ///
  4045                              <1> csftdf_sf_amb: ; 15/03/2016
  4046 0000BA95 8B0D[94880100]      <1> 	mov	ecx, [csftdf_filesize]	; 23/03/2016
  4047                              <1> 
  4048                              <1> 	; TRDOS 386 (TRDOS v2.0)
  4049                              <1> 	; Allocate contiguous memory block for loading the file
  4050                              <1> 
  4051                              <1> 	;mov	ecx, [SourceFile_DirEntry+DirEntry_FileSize]
  4052                              <1> 
  4053                              <1> 	;sub	eax, eax ; First free memory aperture
  4054                              <1> 
  4055                              <1> 	; eax = 0 (Allocate memory from the beginning)
  4056                              <1> 	; ecx = File (Allocation) size in bytes
  4057                              <1> 
  4058                              <1> ; 31/08/2024 - temporary
  4059                              <1> ;%if 0
  4060 0000BA9B E853A2FFFF          <1> 	call	allocate_memory_block
  4061 0000BAA0 7304                <1> 	jnc	short loc_check_sf_save_loading_parms
  4062                              <1> ;%endif
  4063                              <1> 
  4064                              <1> csftdf_use_cluster_buff: ; 27/08/2024
  4065                              <1> 
  4066 0000BAA2 29C0                <1> 	sub	eax, eax
  4067 0000BAA4 29C9                <1> 	sub	ecx, ecx
  4068                              <1> 
  4069                              <1> loc_check_sf_save_loading_parms:
  4070 0000BAA6 A3[98880100]        <1> 	mov	[csftdf_sf_mem_addr], eax ; loading address
  4071 0000BAAB 890D[9C880100]      <1> 	mov	[csftdf_sf_mem_bsize], ecx ; block size
  4072                              <1> ; ///
  4073                              <1> 	; 19/03/2016
  4074 0000BAB1 8B35[BC880100]      <1> 	mov	esi, [csftdf_sf_drv_dt] ; logical dos drv desc. tbl.
  4075                              <1> 
  4076                              <1> 	; 17/03/2016
  4077 0000BAB7 09C0                <1> 	or	eax, eax ; contiguous free memory block address
  4078                              <1> 	;jz	csftdf2_read_sf_cluster
  4079                              <1> 	; 29/07/2022
  4080 0000BAB9 7505                <1> 	jnz	short csftdf2_1
  4081 0000BABB E95E010000          <1> 	jmp	csftdf2_read_sf_cluster
  4082                              <1> 
  4083                              <1> csftdf2_1:
  4084                              <1> 	; 18/03/2016
  4085 0000BAC0 8B1D[98880100]      <1> 	mov	ebx, [csftdf_sf_mem_addr] ; memory block address
  4086                              <1> 
  4087 0000BAC6 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  4088                              <1>         ;jna	csftdf2_load_fs_file
  4089                              <1> 	; 29/07/2022
  4090 0000BACA 7705                <1> 	ja	short csftdf2_load_fat_file
  4091 0000BACC E90F020000          <1> 	jmp	csftdf2_load_fs_file
  4092                              <1> 
  4093                              <1> csftdf2_load_fat_file:
  4094 0000BAD1 53                  <1> 	push	ebx ; *
  4095                              <1> 
  4096                              <1> csftdf2_load_fat_file_next:
  4097 0000BAD2 BE[F33A0100]        <1> 	mov	esi, msg_reading
  4098 0000BAD7 E88EB2FFFF          <1> 	call	print_msg
  4099                              <1> 
  4100 0000BADC 803D[B8880100]00    <1> 	cmp	byte [csftdf_percentage], 0
  4101 0000BAE3 7605                <1> 	jna	short csftdf2_load_fat_file_1
  4102                              <1> 
  4103 0000BAE5 E87E000000          <1> 	call	csftdf2_print_percentage ; 19/03/2016
  4104                              <1> 
  4105                              <1> csftdf2_load_fat_file_1:
  4106 0000BAEA 8B35[BC880100]      <1> 	mov	esi, [csftdf_sf_drv_dt]
  4107 0000BAF0 5B                  <1> 	pop	ebx ; *
  4108                              <1> 
  4109                              <1> csftdf2_load_fat_file_2:
  4110 0000BAF1 E8BA000000          <1> 	call	csftdf2_read_fat_file_sectors ; 19/03/2016
  4111                              <1> 	;jc	csftdf2_rw_error ; eocc! or disk error!
  4112                              <1> 	; 29/07/2022
  4113 0000BAF6 7305                <1> 	jnc	short csftdf2_load_fat_file_3
  4114 0000BAF8 E95B040000          <1> 	jmp	csftdf2_rw_error
  4115                              <1> csftdf2_load_fat_file_3:
  4116 0000BAFD 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  4117 0000BAFF 7520                <1> 	jnz	short csftdf2_load_fat_file_ok
  4118                              <1> 
  4119 0000BB01 803D[B8880100]00    <1> 	cmp	byte [csftdf_percentage], 0
  4120 0000BB08 76E7                <1> 	jna	short csftdf2_load_fat_file_2
  4121                              <1> 
  4122 0000BB0A 53                  <1> 	push	ebx ; *
  4123                              <1> 
  4124                              <1> 	; Set cursor position
  4125                              <1> 	; AH= 02h, BH= Page Number, DH= Row, DL= Column
  4126 0000BB0B 8A3D[B9880100]      <1> 	mov	bh, [csftdf_videopage]
  4127 0000BB11 668B15[BA880100]    <1> 	mov	dx, [csftdf_cursorpos]
  4128 0000BB18 B402                <1> 	mov	ah, 2
  4129 0000BB1A E8055CFFFF          <1> 	call	_int10h
  4130 0000BB1F EBB1                <1> 	jmp	short csftdf2_load_fat_file_next
  4131                              <1> 
  4132                              <1> csftdf2_load_fat_file_ok:
  4133 0000BB21 803D[B8880100]00    <1> 	cmp	byte [csftdf_percentage], 0
  4134                              <1> 	;jna	csftdf2_save_file ; 25/03/2016
  4135                              <1> 	; 29/07/2022
  4136 0000BB28 7705                <1> 	ja	short csftdf2_2
  4137 0000BB2A E955020000          <1> 	jmp	csftdf2_save_file
  4138                              <1> csftdf2_2:
  4139                              <1> 	; "Reading... 100%"
  4140 0000BB2F BF[0B3B0100]        <1> 	mov	edi, percentagestr
  4141 0000BB34 B031                <1> 	mov	al, '1'
  4142 0000BB36 AA                  <1> 	stosb
  4143 0000BB37 B030                <1> 	mov	al, '0'
  4144 0000BB39 AA                  <1> 	stosb
  4145 0000BB3A AA                  <1> 	stosb
  4146                              <1> 
  4147 0000BB3B 8A3D[B9880100]      <1> 	mov	bh, [csftdf_videopage]
  4148 0000BB41 668B15[BA880100]    <1> 	mov	dx, [csftdf_cursorpos]
  4149 0000BB48 B402                <1> 	mov	ah, 2
  4150 0000BB4A E8D55BFFFF          <1> 	call	_int10h
  4151                              <1> 
  4152 0000BB4F BE[F33A0100]        <1> 	mov	esi, msg_reading
  4153 0000BB54 E811B2FFFF          <1> 	call	print_msg
  4154                              <1> 
  4155 0000BB59 BE[0B3B0100]        <1> 	mov	esi, percentagestr
  4156 0000BB5E E807B2FFFF          <1> 	call	print_msg
  4157                              <1> 
  4158 0000BB63 E91C020000          <1>         jmp	csftdf2_save_file ; 25/03/2016
  4159                              <1> 
  4160                              <1> csftdf2_print_percentage:
  4161                              <1> 	; 09/12/2017
  4162                              <1> 	; 19/03/2016
  4163                              <1> 	; 18/03/2016
  4164 0000BB68 B020                <1> 	mov	al, 20h
  4165 0000BB6A BF[0B3B0100]        <1> 	mov	edi, percentagestr
  4166 0000BB6F AA                  <1> 	stosb
  4167 0000BB70 AA                  <1> 	stosb
  4168 0000BB71 A1[B0880100]        <1> 	mov	eax, [csftdf_sf_rbytes]
  4169                              <1> 	;mov	edx, 100
  4170                              <1> 	; 29/07/2022
  4171 0000BB76 29D2                <1> 	sub	edx, edx
  4172 0000BB78 B264                <1> 	mov	dl, 100
  4173 0000BB7A F7E2                <1> 	mul	edx
  4174 0000BB7C 8B0D[94880100]      <1> 	mov	ecx, [csftdf_filesize]
  4175 0000BB82 F7F1                <1> 	div	ecx
  4176 0000BB84 B10A                <1> 	mov	cl, 10
  4177 0000BB86 F6F1                <1> 	div	cl
  4178 0000BB88 80C430              <1> 	add	ah, '0'
  4179 0000BB8B 8827                <1> 	mov	[edi], ah
  4180 0000BB8D 20C0                <1> 	and	al, al
  4181 0000BB8F 740A                <1> 	jz	short csftdf2_print_percent_1
  4182 0000BB91 4F                  <1> 	dec	edi
  4183                              <1> 	;cbw
  4184 0000BB92 28E4                <1> 	sub	ah, ah ; 09/12/2017
  4185 0000BB94 F6F1                <1> 	div	cl
  4186 0000BB96 80C430              <1> 	add	ah, '0'
  4187 0000BB99 8827                <1> 	mov	[edi], ah
  4188                              <1> 	;and	al, al
  4189                              <1> 	;jz	short csftdf2_print_percent_1
  4190                              <1> 	;dec	edi
  4191                              <1> 	;mov	[edi], '1' ; 100%
  4192                              <1> 
  4193                              <1> csftdf2_print_percent_1:
  4194 0000BB9B BE[0B3B0100]        <1> 	mov	esi, percentagestr
  4195                              <1> 	;call	print_msg
  4196                              <1> 	;retn
  4197 0000BBA0 E9C5B1FFFF          <1> 	jmp	print_msg
  4198                              <1> 
  4199                              <1> csftdf2_read_file_sectors:
  4200                              <1> 	; 19/03/2016
  4201 0000BBA5 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  4202                              <1> 	;jna	csftdf2_read_fs_file_sectors
  4203                              <1> 	; 29/07/2022
  4204 0000BBA9 7705                <1> 	ja	short csftdf2_read_fat_file_sectors
  4205 0000BBAB E96F070000          <1> 	jmp	csftdf2_read_fs_file_sectors
  4206                              <1> 
  4207                              <1> csftdf2_read_fat_file_sectors:
  4208                              <1> 	; 19/03/2016
  4209                              <1> 	; 18/03/2016
  4210                              <1> 	; return:
  4211                              <1> 	;   CF = 0 & EDX > 0 -> END OF FILE
  4212                              <1> 	;   CF = 0 & EDX = 0 -> not EOF
  4213                              <1> 	;   CF = 1 -> read error (error code in AL)
  4214                              <1> 
  4215                              <1> csftdf2_read_fat_file_secs_0:
  4216 0000BBB0 8B15[94880100]      <1> 	mov	edx, [csftdf_filesize]
  4217 0000BBB6 2B15[B0880100]      <1> 	sub	edx, [csftdf_sf_rbytes]
  4218 0000BBBC 3B15[A8880100]      <1> 	cmp	edx, [csftdf_r_size]
  4219 0000BBC2 7306                <1> 	jnb	short csftdf2_read_fat_file_secs_1
  4220 0000BBC4 8915[A8880100]      <1> 	mov	[csftdf_r_size], edx
  4221                              <1> 
  4222                              <1> csftdf2_read_fat_file_secs_1:
  4223 0000BBCA A1[A8880100]        <1> 	mov	eax, [csftdf_r_size]
  4224 0000BBCF 29D2                <1> 	sub	edx, edx
  4225 0000BBD1 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec]
  4226 0000BBD5 01C8                <1> 	add	eax, ecx
  4227 0000BBD7 48                  <1> 	dec	eax
  4228 0000BBD8 F7F1                <1> 	div	ecx
  4229 0000BBDA 89C1                <1> 	mov	ecx, eax ; sector count
  4230 0000BBDC A1[A0880100]        <1> 	mov	eax, [csftdf_sf_cluster]
  4231                              <1> 
  4232                              <1> 	; EBX = memory block address (current)
  4233                              <1> 
  4234 0000BBE1 E83A090000          <1> 	call	read_fat_file_sectors
  4235 0000BBE6 7235                <1> 	jc	short csftdf2_read_fat_file_secs_3
  4236                              <1> 
  4237                              <1> 	; EBX = next memory address
  4238                              <1> 
  4239 0000BBE8 A1[B0880100]        <1> 	mov	eax, [csftdf_sf_rbytes]
  4240 0000BBED 0305[A8880100]      <1> 	add	eax, [csftdf_r_size]
  4241 0000BBF3 8B15[94880100]      <1> 	mov	edx, [csftdf_filesize]
  4242 0000BBF9 39D0                <1> 	cmp	eax, edx
  4243 0000BBFB 7320                <1> 	jnb	short csftdf2_read_fat_file_secs_3 ; edx > 0
  4244 0000BBFD A3[B0880100]        <1> 	mov	[csftdf_sf_rbytes], eax
  4245                              <1> 
  4246 0000BC02 53                  <1> 	push	ebx ; *
  4247                              <1> 	; get next cluster (csftdf_r_size! bytes)
  4248 0000BC03 A1[A0880100]        <1> 	mov	eax, [csftdf_sf_cluster]
  4249 0000BC08 E813070000          <1> 	call	get_next_cluster
  4250 0000BC0D 5B                  <1> 	pop	ebx ; *
  4251 0000BC0E 7306                <1> 	jnc	short csftdf2_read_fat_file_secs_2
  4252                              <1> 
  4253                              <1> 	; 15/10/2016
  4254                              <1> 	; Disk read error instead of drv not ready err
  4255 0000BC10 B811000000          <1> 	mov	eax, 17 ; Read error !
  4256 0000BC15 C3                  <1> 	retn
  4257                              <1> 
  4258                              <1> csftdf2_read_fat_file_secs_2:
  4259 0000BC16 29D2                <1> 	sub	edx, edx ; 0
  4260 0000BC18 A3[A0880100]        <1> 	mov	[csftdf_sf_cluster], eax ; next cluster
  4261                              <1> 
  4262                              <1> csftdf2_read_fat_file_secs_3:
  4263 0000BC1D C3                  <1> 	retn
  4264                              <1> 
  4265                              <1> csftdf2_read_sf_cluster:
  4266                              <1> 	; 19/03/2016
  4267 0000BC1E BB00000700          <1> 	mov	ebx, Cluster_Buffer ; buffer address (64KB)
  4268                              <1> 
  4269 0000BC23 803D[B8880100]00    <1> 	cmp	byte [csftdf_percentage], 0
  4270 0000BC2A 760D                <1> 	jna	short csftdf2_read_sf_clust_2
  4271                              <1> 
  4272 0000BC2C 53                  <1> 	push	ebx ; *
  4273                              <1> 
  4274                              <1> csftdf2_read_sf_clust_next:
  4275 0000BC2D E836FFFFFF          <1> 	call	csftdf2_print_percentage
  4276                              <1> 
  4277                              <1> csftdf2_read_sf_clust_0:
  4278 0000BC32 8B35[BC880100]      <1> 	mov	esi, [csftdf_sf_drv_dt]
  4279                              <1> csftdf2_read_sf_clust_1:
  4280 0000BC38 5B                  <1> 	pop	ebx ; *
  4281                              <1> 
  4282                              <1> csftdf2_read_sf_clust_2:
  4283 0000BC39 89DA                <1> 	mov	edx, ebx
  4284 0000BC3B 0315[A8880100]      <1> 	add	edx, [csftdf_r_size]
  4285 0000BC41 81FA00000800        <1> 	cmp	edx, Cluster_Buffer + 65536
  4286 0000BC47 772B                <1> 	ja	short csftdf2_write_df_cluster
  4287                              <1> 
  4288 0000BC49 E857FFFFFF          <1> 	call	csftdf2_read_file_sectors ; 19/03/2016
  4289                              <1> 	;jc	csftdf2_save_fat_file_err2 ; eocc! or disk error!
  4290                              <1> 	; 29/07/2022
  4291 0000BC4E 723C                <1> 	jc	short csftdf2_3
  4292                              <1> 
  4293 0000BC50 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  4294 0000BC52 7520                <1> 	jnz	short csftdf2_write_df_cluster
  4295                              <1> 
  4296 0000BC54 803D[B8880100]00    <1> 	cmp	byte [csftdf_percentage], 0
  4297 0000BC5B 76DC                <1> 	jna	short csftdf2_read_sf_clust_2
  4298                              <1> 
  4299 0000BC5D 53                  <1> 	push	ebx ; *
  4300                              <1> 
  4301                              <1> 	; Set cursor position
  4302                              <1> 	; AH= 02h, BH= Page Number, DH= Row, DL= Column
  4303 0000BC5E 8A3D[B9880100]      <1> 	mov	bh, [csftdf_videopage]
  4304 0000BC64 668B15[BA880100]    <1> 	mov	dx, [csftdf_cursorpos]
  4305 0000BC6B B402                <1> 	mov	ah, 2
  4306 0000BC6D E8B25AFFFF          <1> 	call	_int10h
  4307 0000BC72 EBB9                <1> 	jmp	short csftdf2_read_sf_clust_next
  4308                              <1> 
  4309                              <1> csftdf2_write_df_cluster:
  4310                              <1> 
  4311                              <1> ; 31/08/2024
  4312                              <1> %if 1
  4313                              <1> 	; 27/08/2024
  4314                              <1> 	; 19/03/2016
  4315                              <1> 	;mov	esi, [csftdf_df_drv_dt] ; (!)
  4316                              <1> 	;mov	ebx, Cluster_Buffer ; buffer address (64KB)
  4317                              <1> 	;;;
  4318                              <1> 	; 27/08/2024
  4319 0000BC74 E814030000          <1> 	call	csftdf2_update_df_fclust
  4320                              <1> 	; 31/08/2024
  4321 0000BC79 7305                <1> 	jnc	short csftdf2_update_df_fclust_ok
  4322 0000BC7B E9D8020000          <1> 	jmp	csftdf2_rw_error
  4323                              <1> 
  4324                              <1> csftdf2_update_df_fclust_ok:
  4325                              <1> %endif
  4326                              <1> 	; esi = [csftdf_df_drv_dt]
  4327                              <1> 
  4328                              <1> 	;mov	esi, [csftdf_df_drv_dt]
  4329 0000BC80 BB00000700          <1> 	mov	ebx, Cluster_Buffer ; buffer address (64KB)
  4330                              <1> 
  4331                              <1> csftdf2_write_df_clust_next:
  4332 0000BC85 E85B000000          <1> 	call	csftdf2_write_file_sectors ; 19/03/2016
  4333                              <1> 	;jc	csftdf2_save_fat_file_err2 ; eocc! or disk error!
  4334                              <1> 	; 29/07/2022
  4335 0000BC8A 7305                <1> 	jnc	short csftdf2_4
  4336                              <1> csftdf2_3:
  4337 0000BC8C E94E020000          <1> 	jmp	csftdf2_save_fat_file_err2
  4338                              <1> csftdf2_4:
  4339 0000BC91 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  4340 0000BC93 7513                <1> 	jnz	short csftdf2_rw_f_clust_ok
  4341                              <1> 
  4342 0000BC95 81FB00000800        <1> 	cmp	ebx, Cluster_Buffer + 65536
  4343 0000BC9B 72E8                <1> 	jb	short csftdf2_write_df_clust_next
  4344                              <1> 
  4345                              <1> 	; 31/08/2024
  4346 0000BC9D 8B35[BC880100]      <1> 	mov	esi, [csftdf_sf_drv_dt]
  4347                              <1> 
  4348 0000BCA3 E976FFFFFF          <1> 	jmp	csftdf2_read_sf_cluster ; 31/08/2024
  4349                              <1> 
  4350                              <1> csftdf2_rw_f_clust_ok:
  4351 0000BCA8 803D[B8880100]00    <1> 	cmp	byte [csftdf_percentage], 0
  4352                              <1> 	;jna	csftdf2_save_fat_file_4 ; 25/03/2016
  4353                              <1> 	; 29/07/2022
  4354 0000BCAF 762A                <1> 	jna	short csftdf2_5
  4355                              <1> 
  4356                              <1> 	; "100%"
  4357 0000BCB1 BF[0B3B0100]        <1> 	mov	edi, percentagestr
  4358 0000BCB6 B031                <1> 	mov	al, '1'
  4359 0000BCB8 AA                  <1> 	stosb
  4360 0000BCB9 B030                <1> 	mov	al, '0'
  4361 0000BCBB AA                  <1> 	stosb
  4362 0000BCBC AA                  <1> 	stosb
  4363                              <1> 
  4364 0000BCBD 8A3D[B9880100]      <1> 	mov	bh, [csftdf_videopage]
  4365 0000BCC3 668B15[BA880100]    <1> 	mov	dx, [csftdf_cursorpos]
  4366 0000BCCA B402                <1> 	mov	ah, 2
  4367 0000BCCC E8535AFFFF          <1> 	call	_int10h
  4368                              <1> 
  4369 0000BCD1 BE[0B3B0100]        <1> 	mov	esi, percentagestr
  4370 0000BCD6 E88FB0FFFF          <1> 	call	print_msg
  4371                              <1> csftdf2_5:
  4372 0000BCDB E989010000          <1>         jmp     csftdf2_save_fat_file_4
  4373                              <1> 
  4374                              <1> csftdf2_load_fs_file:
  4375                              <1> 	; temporary - 18/03/2016
  4376 0000BCE0 E971020000          <1>         jmp     csftdf2_read_error
  4377                              <1> 
  4378                              <1> csftdf2_write_file_sectors:
  4379                              <1> 	; 31/08/2024
  4380                              <1> 	; 30/08/2024
  4381                              <1> 	; 19/03/2016
  4382 0000BCE5 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  4383                              <1> 	;jna	csftdf2_write_fs_file_sectors
  4384                              <1> 	; 29/07/2022
  4385 0000BCE9 7705                <1> 	ja	short csftdf2_write_fat_file_sectors
  4386 0000BCEB E92F060000          <1> 	jmp	csftdf2_write_fs_file_sectors
  4387                              <1> 
  4388                              <1> csftdf2_write_fat_file_sectors:
  4389                              <1> 	; 30/08/2024
  4390                              <1> 	; 19/03/2016
  4391                              <1> 	; 18/03/2016
  4392                              <1> 	; return:
  4393                              <1> 	;   CF = 0 & EDX > 0 -> END OF FILE
  4394                              <1> 	;   CF = 0 & EDX = 0 -> not EOF
  4395                              <1> 	;   CF = 1 -> write error (error code in AL)
  4396                              <1> 
  4397                              <1> csftdf2_write_fat_file_secs_0:
  4398 0000BCF0 8B15[94880100]      <1> 	mov	edx, [csftdf_filesize]
  4399 0000BCF6 2B15[B4880100]      <1> 	sub	edx, [csftdf_df_wbytes]
  4400 0000BCFC 3B15[AC880100]      <1> 	cmp	edx, [csftdf_w_size]
  4401 0000BD02 7306                <1> 	jnb	short csftdf2_write_fat_file_secs_1
  4402 0000BD04 8915[AC880100]      <1> 	mov	[csftdf_w_size], edx
  4403                              <1> 
  4404                              <1> csftdf2_write_fat_file_secs_1:
  4405                              <1> 
  4406                              <1> ; 31/08/2024
  4407                              <1> %if 0
  4408                              <1> 	;;;
  4409                              <1> 	; 30/08/2024
  4410                              <1> 	mov	eax, [csftdf_df_cluster]
  4411                              <1> 	and	eax, eax
  4412                              <1> 	jnz	short csftdf2_write_fat_file_secs_@
  4413                              <1> 	push	ebx
  4414                              <1> 	call	add_new_cluster
  4415                              <1> 	pop	ebx
  4416                              <1> 	jc	short csftdf2_write_fat_file_secs_5
  4417                              <1> 	mov	[csftdf_df_cluster], eax
  4418                              <1> csftdf2_write_fat_file_secs_@:
  4419                              <1> 	;;;
  4420                              <1> %endif
  4421                              <1> 
  4422 0000BD0A A1[AC880100]        <1> 	mov	eax, [csftdf_w_size]
  4423 0000BD0F 29D2                <1> 	sub	edx, edx
  4424 0000BD11 0FB74E11            <1> 	movzx	ecx, word [esi+LD_BPB+BytesPerSec]
  4425 0000BD15 01C8                <1> 	add	eax, ecx
  4426 0000BD17 48                  <1> 	dec	eax
  4427 0000BD18 F7F1                <1> 	div	ecx
  4428 0000BD1A 89C1                <1> 	mov	ecx, eax ; sector count
  4429 0000BD1C A1[A4880100]        <1> 	mov	eax, [csftdf_df_cluster]
  4430                              <1> 
  4431                              <1> 	; EBX = memory block address (current)
  4432                              <1> 
  4433 0000BD21 E8200F0000          <1> 	call	write_fat_file_sectors
  4434 0000BD26 7254                <1> 	jc	short csftdf2_write_fat_file_secs_4
  4435                              <1> 
  4436                              <1> 	; EBX = next memory address
  4437                              <1> 
  4438 0000BD28 A1[B4880100]        <1> 	mov	eax, [csftdf_df_wbytes]
  4439 0000BD2D 0305[AC880100]      <1> 	add	eax, [csftdf_w_size]
  4440 0000BD33 8B15[94880100]      <1> 	mov	edx, [csftdf_filesize]
  4441 0000BD39 39D0                <1> 	cmp	eax, edx
  4442 0000BD3B 733F                <1> 	jnb	short csftdf2_write_fat_file_secs_4
  4443 0000BD3D A3[B4880100]        <1> 	mov	[csftdf_df_wbytes], eax
  4444                              <1> 	;
  4445 0000BD42 A3[56880100]        <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], eax
  4446                              <1> 
  4447                              <1> 
  4448 0000BD47 53                  <1> 	push	ebx ; *
  4449                              <1> 
  4450                              <1> 	; 30/08/2024
  4451 0000BD48 A1[A4880100]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
  4452                              <1> 
  4453 0000BD4D 803D[92880100]01    <1> 	cmp	byte [DestinationFileFound], 1
  4454 0000BD54 720B                <1> 	jb	short csftdf2_write_fat_file_secs_2
  4455                              <1> 
  4456                              <1> 	; get next cluster (csftdf_w_size! bytes)
  4457                              <1> 	;mov	eax, [csftdf_df_cluster]
  4458 0000BD56 E8C5050000          <1> 	call	get_next_cluster
  4459 0000BD5B 7317                <1> 	jnc	short csftdf2_write_fat_file_secs_3
  4460                              <1> 
  4461 0000BD5D 21C0                <1> 	and	eax, eax ; end of cluster chain!?
  4462 0000BD5F 751C                <1> 	jnz	short csftdf2_write_fat_file_secs_5 ; disk error !
  4463                              <1> 
  4464                              <1> csftdf2_write_fat_file_secs_2:
  4465                              <1> 	;mov	eax, [csftdf_df_cluster] ; last cluster
  4466                              <1> 	; 30/08/2024
  4467 0000BD61 E8490E0000          <1> 	call	add_new_cluster
  4468 0000BD66 7215                <1> 	jc	short csftdf2_write_fat_file_secs_5
  4469                              <1> 
  4470                              <1> 	; NOTE: Destination file size may be bigger than
  4471                              <1> 	; source file size when the last reading fails after here.
  4472                              <1> 	; (The last -empty- cluster of destination file must be
  4473                              <1> 	; truncated and LMDT must be current date&time for partial
  4474                              <1> 	; copy result!)
  4475 0000BD68 8B15[AC880100]      <1> 	mov	edx, [csftdf_w_size] ; < = bytes per cluster
  4476 0000BD6E 0115[56880100]      <1> 	add	[DestinationFile_DirEntry+DirEntry_FileSize], edx
  4477                              <1> 
  4478                              <1> csftdf2_write_fat_file_secs_3:
  4479                              <1> 	; 30/08/2024
  4480                              <1> 	;pop	ebx ; *
  4481 0000BD74 29D2                <1> 	sub	edx, edx ; 0
  4482 0000BD76 A3[A4880100]        <1> 	mov	[csftdf_df_cluster], eax ; next cluster
  4483                              <1> 
  4484                              <1> 	; 30/08/2024
  4485 0000BD7B 5B                  <1> 	pop	ebx ; *
  4486                              <1> 
  4487                              <1> csftdf2_write_fat_file_secs_4:
  4488 0000BD7C C3                  <1> 	retn
  4489                              <1> 
  4490                              <1> csftdf2_write_fat_file_secs_5:
  4491 0000BD7D 5B                  <1> 	pop	ebx ; *
  4492 0000BD7E B812000000          <1> 	mov	eax, 18 ; Write error !
  4493                              <1> 	; 16/10/2016 (1Dh -> 18)
  4494 0000BD83 C3                  <1> 	retn
  4495                              <1> 
  4496                              <1> csftdf2_save_file:
  4497                              <1> 	; 31/08/2024
  4498                              <1> 	; 26/08/2024, 30/08/2024
  4499                              <1> 	; 09/12/2017
  4500                              <1> 	; 19/03/2016, 25/03/2016
  4501                              <1> 	; 18/03/2016 
  4502 0000BD84 8B35[C0880100]      <1> 	mov	esi, [csftdf_df_drv_dt] ; logical dos drv desc. tbl.
  4503 0000BD8A 8B1D[98880100]      <1> 	mov	ebx, [csftdf_sf_mem_addr] ; memory block address
  4504                              <1> 
  4505 0000BD90 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  4506                              <1> 	;jna	csftdf2_save_fs_file
  4507                              <1> 	; 29/07/2022
  4508 0000BD94 7705                <1> 	ja	short csftdf2_save_fat_file
  4509 0000BD96 E945020000          <1> 	jmp	csftdf2_save_fs_file
  4510                              <1> 
  4511                              <1> csftdf2_save_fat_file:
  4512                              <1> 
  4513                              <1> ; 31/08/2024
  4514                              <1> %if 1
  4515                              <1> 	; 30/08/2024
  4516 0000BD9B 53                  <1> 	push	ebx ; *
  4517                              <1> 	;;;
  4518                              <1> 	; 27/08/2024
  4519                              <1> 	;call	csftdf2_update_df_fclust
  4520 0000BD9C E8F2010000          <1> 	call	csftdf2_update_df_fclust_@ ; 31/08/2024
  4521 0000BDA1 5B                  <1> 	pop	ebx ; *
  4522 0000BDA2 7236                <1> 	jc	short csftdf2_save_fat_file_err
  4523                              <1> 	; esi = [csftdf_df_drv_dt] ; (*)
  4524                              <1> 	;;;
  4525                              <1> %endif
  4526                              <1> 
  4527 0000BDA4 803D[B8880100]00    <1> 	cmp	byte [csftdf_percentage], 0
  4528 0000BDAB 7726                <1> 	ja	short csftdf2_save_fat_file_0 ; 30/08/2024
  4529                              <1> 
  4530 0000BDAD 53                  <1> 	push	ebx ; **
  4531                              <1> 
  4532                              <1> 	; Set cursor position
  4533                              <1> 	; AH= 02h, BH= Page Number, DH= Row, DL= Column
  4534 0000BDAE 8A3D[B9880100]      <1> 	mov	bh, [csftdf_videopage]
  4535 0000BDB4 668B15[BA880100]    <1> 	mov	dx, [csftdf_cursorpos]
  4536 0000BDBB B402                <1> 	mov	ah, 2
  4537 0000BDBD E86259FFFF          <1> 	call	_int10h
  4538                              <1> 
  4539 0000BDC2 BE[FF3A0100]        <1> 	mov	esi, msg_writing
  4540 0000BDC7 E89EAFFFFF          <1> 	call	print_msg
  4541                              <1> 
  4542                              <1> csftdf2_save_fat_file_next:
  4543 0000BDCC 5B                  <1> 	pop	ebx ; **
  4544                              <1> 
  4545                              <1> 	; 31/08/2024
  4546 0000BDCD 8B35[C0880100]      <1> 	mov	esi, [csftdf_df_drv_dt]
  4547                              <1> 
  4548                              <1> csftdf2_save_fat_file_0: ; 30/08/2024
  4549                              <1> 
  4550                              <1> csftdf2_save_fat_file_1:
  4551 0000BDD3 E80DFFFFFF          <1> 	call	csftdf2_write_file_sectors ; 19/03/2016
  4552                              <1> 	;jc	csftdf2_rw_error ; eocc! or disk error!
  4553                              <1> 	; 29/07/2022
  4554 0000BDD8 7305                <1> 	jnc	short csftdf2_6
  4555                              <1> csftdf2_save_fat_file_err: ; 27/08/2024
  4556 0000BDDA E979010000          <1> 	jmp	csftdf2_rw_error
  4557                              <1> 
  4558                              <1> csftdf2_6:
  4559 0000BDDF 09D2                <1> 	or	edx, edx ; edx > 0 -> EOF
  4560 0000BDE1 756C                <1>         jnz     short csftdf2_save_fat_file_3 ; 25/03/2016
  4561                              <1> 
  4562 0000BDE3 803D[B8880100]00    <1> 	cmp	byte [csftdf_percentage], 0
  4563 0000BDEA 76E7                <1> 	jna	short csftdf2_save_fat_file_1
  4564                              <1> 
  4565 0000BDEC B020                <1> 	mov	al, 20h
  4566 0000BDEE BF[0B3B0100]        <1> 	mov	edi, percentagestr
  4567 0000BDF3 AA                  <1> 	stosb
  4568 0000BDF4 AA                  <1> 	stosb
  4569 0000BDF5 A1[B4880100]        <1> 	mov	eax, [csftdf_df_wbytes]
  4570                              <1> 	;mov	edx, 100
  4571                              <1> 	; 29/07/2022
  4572 0000BDFA 31D2                <1> 	xor	edx, edx
  4573 0000BDFC B264                <1> 	mov	dl, 100
  4574 0000BDFE F7E2                <1> 	mul	edx
  4575 0000BE00 8B0D[94880100]      <1> 	mov	ecx, [csftdf_filesize]
  4576 0000BE06 F7F1                <1> 	div	ecx
  4577 0000BE08 B10A                <1> 	mov	cl, 10
  4578 0000BE0A F6F1                <1> 	div	cl
  4579 0000BE0C 80C430              <1> 	add	ah, '0'
  4580 0000BE0F 8827                <1> 	mov	[edi], ah
  4581 0000BE11 20C0                <1> 	and	al, al
  4582 0000BE13 740A                <1> 	jz	short csftdf2_save_fat_file_2
  4583 0000BE15 4F                  <1> 	dec	edi
  4584                              <1> 	;cbw
  4585 0000BE16 30E4                <1> 	xor	ah, ah ; 09/12/2017
  4586 0000BE18 F6F1                <1> 	div	cl
  4587 0000BE1A 80C430              <1> 	add	ah, '0'
  4588 0000BE1D 8827                <1> 	mov	[edi], ah
  4589                              <1> 	;and	al, al
  4590                              <1> 	;jz	short csftdf2_save_fat_file_2
  4591                              <1> 	;dec	edi
  4592                              <1> 	;mov	[edi], '1' ; 100%
  4593                              <1> 
  4594                              <1> csftdf2_save_fat_file_2:
  4595 0000BE1F 53                  <1> 	push	ebx ; *
  4596                              <1> 
  4597 0000BE20 E802000000          <1> 	call	csftdf2_print_wr_percentage ; 25/03/2016
  4598                              <1> 
  4599 0000BE25 EBA5                <1>         jmp     csftdf2_save_fat_file_next
  4600                              <1> 
  4601                              <1> csftdf2_print_wr_percentage:
  4602                              <1> 	; Set cursor position
  4603                              <1> 	; AH= 02h, BH= Page Number, DH= Row, DL= Column
  4604 0000BE27 8A3D[B9880100]      <1> 	mov	bh, [csftdf_videopage]
  4605 0000BE2D 668B15[BA880100]    <1> 	mov	dx, [csftdf_cursorpos]
  4606 0000BE34 B402                <1> 	mov	ah, 2
  4607 0000BE36 E8E958FFFF          <1> 	call	_int10h
  4608                              <1> 
  4609 0000BE3B BE[FF3A0100]        <1> 	mov	esi, msg_writing
  4610 0000BE40 E825AFFFFF          <1> 	call	print_msg
  4611                              <1> 
  4612 0000BE45 BE[0B3B0100]        <1> 	mov	esi, percentagestr
  4613                              <1> 	;call	print_msg
  4614                              <1> 	;retn
  4615 0000BE4A E91BAFFFFF          <1> 	jmp	print_msg
  4616                              <1> 
  4617                              <1> csftdf2_save_fat_file_3:
  4618 0000BE4F 803D[B8880100]00    <1> 	cmp	byte [csftdf_percentage], 0
  4619                              <1>         ;jna	csftdf2_save_fat_file_4 ; 25/03/2016
  4620                              <1> 	; 29/07/2022
  4621                              <1> 	;ja	short csftdf2_7
  4622                              <1> 	;jmp	csftdf2_save_fat_file_4
  4623                              <1> 	; 31/08/2024
  4624 0000BE56 7611                <1> 	jna	short csftdf2_save_fat_file_4
  4625                              <1> 
  4626                              <1> csftdf2_7:
  4627                              <1> 	; "100%"
  4628 0000BE58 BF[0B3B0100]        <1> 	mov	edi, percentagestr
  4629 0000BE5D B031                <1> 	mov	al, '1'
  4630 0000BE5F AA                  <1> 	stosb
  4631 0000BE60 B030                <1> 	mov	al, '0'
  4632 0000BE62 AA                  <1> 	stosb
  4633 0000BE63 AA                  <1> 	stosb
  4634                              <1> 
  4635 0000BE64 E8BEFFFFFF          <1> 	call	csftdf2_print_wr_percentage
  4636                              <1> 
  4637                              <1> csftdf2_save_fat_file_4:
  4638 0000BE69 803D[92880100]00    <1> 	cmp	byte [DestinationFileFound], 0
  4639 0000BE70 7645                <1> 	jna	short csftdf2_save_fat_file_6
  4640                              <1> 
  4641 0000BE72 8B35[C0880100]      <1> 	mov	esi, [csftdf_df_drv_dt] ; 31/03/2016
  4642                              <1> 
  4643 0000BE78 A1[A4880100]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
  4644 0000BE7D E89E040000          <1> 	call	get_next_cluster
  4645 0000BE82 7233                <1> 	jc	short csftdf2_save_fat_file_6 ; eocc! or disk error!
  4646                              <1> 
  4647 0000BE84 A1[A4880100]        <1> 	mov	eax, [csftdf_df_cluster] ; last cluster
  4648                              <1> 	; 29/08/2024
  4649 0000BE89 31C9                <1> 	xor	ecx, ecx
  4650                              <1> 	;mov	[FAT_ClusterCounter], ecx ; 0 ; reset
  4651 0000BE8B 49                  <1> 	dec	ecx ; 0FFFFFFFFh
  4652                              <1> 	;shr	ecx, 4 ; 28 bit ; 0FFFFFFFh
  4653                              <1> 	; 29/08/2024
  4654                              <1> 	; (update_cluster will save 28 bit cluster value)
  4655                              <1> 	;mov	ecx, 0FFFFFFFh
  4656 0000BE8C E87E070000          <1> 	call	update_cluster
  4657 0000BE91 7224                <1> 	jc	short csftdf2_save_fat_file_6 ; really last cluster!?
  4658                              <1> 
  4659 0000BE93 A3[A4880100]        <1> 	mov	[csftdf_df_cluster], eax ; next cluster
  4660                              <1> 	
  4661                              <1> 	; byte [FAT_BuffValidData] = 2
  4662 0000BE98 E8E6090000          <1> 	call	save_fat_buffer
  4663 0000BE9D 730E                <1> 	jnc	short csftdf2_save_fat_file_5
  4664                              <1> 	
  4665 0000BE9F 8B15[94880100]      <1> 	mov	edx, [csftdf_filesize]
  4666 0000BEA5 8915[56880100]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], edx
  4667 0000BEAB EB57                <1> 	jmp	short csftdf2_save_fat_file_err3
  4668                              <1> 
  4669                              <1> csftdf2_save_fat_file_5:
  4670 0000BEAD A1[A4880100]        <1> 	mov	eax, [csftdf_df_cluster]
  4671                              <1> 
  4672                              <1> 	; EAX = First cluster to be truncated/unlinked
  4673                              <1> 	; ESI = Logical dos drive description table address
  4674 0000BEB2 E80A0C0000          <1> 	call	truncate_cluster_chain
  4675                              <1> 
  4676                              <1> csftdf2_save_fat_file_6:
  4677                              <1> 	; 28/03/2016
  4678 0000BEB7 BE[C5870100]        <1> 	mov	esi, SourceFile_DirEntry+DirEntry_Attr ; +11 to + 18
  4679 0000BEBC BF[45880100]        <1> 	mov	edi, DestinationFile_DirEntry+DirEntry_Attr ; +11 to + 18
  4680 0000BEC1 A4                  <1> 	movsb ; +11
  4681 0000BEC2 A5                  <1> 	movsd ; +12 .. +15
  4682 0000BEC3 66A5                <1> 	movsw ; +16 .. +17
  4683                              <1> 		; + 18
  4684 0000BEC5 83C604              <1> 	add	esi, 4
  4685 0000BEC8 83C704              <1> 	add	edi, 4
  4686 0000BECB A5                  <1> 	movsd	; DirEntry_WrtTime ; +22 .. +25
  4687                              <1> 
  4688 0000BECC 8B15[94880100]      <1> 	mov	edx, [csftdf_filesize]
  4689 0000BED2 8915[56880100]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], edx
  4690                              <1> 
  4691 0000BED8 E8DFF0FFFF          <1> 	call	convert_current_date_time
  4692                              <1> 	; DX = Date in dos dir entry format
  4693                              <1> 	; AX = Time in dos dir entry format
  4694 0000BEDD EB4C                <1> 	jmp	short csftdf2_save_fat_file_7
  4695                              <1> 
  4696                              <1> 	; 31/08/2024
  4697                              <1> ;csftdf2_save_fat_file_err1:
  4698                              <1> 	;pop	ebx ; *
  4699                              <1> 
  4700                              <1> csftdf2_save_fat_file_err2:
  4701 0000BEDF A1[B4880100]        <1> 	mov	eax, [csftdf_df_wbytes]
  4702 0000BEE4 8B15[56880100]      <1> 	mov	edx, [DestinationFile_DirEntry+DirEntry_FileSize]
  4703 0000BEEA 39C2                <1> 	cmp	edx, eax
  4704 0000BEEC 7616                <1> 	jna	short csftdf2_save_fat_file_err3
  4705 0000BEEE A1[A4880100]        <1> 	mov	eax, [csftdf_df_cluster] ; last (empty) cluster
  4706                              <1> 	; ESI = Logical dos drive description table address
  4707 0000BEF3 E8C90B0000          <1> 	call	truncate_cluster_chain
  4708 0000BEF8 720A                <1> 	jc	short csftdf2_save_fat_file_err3
  4709 0000BEFA A1[B4880100]        <1> 	mov	eax, [csftdf_df_wbytes]
  4710 0000BEFF A3[56880100]        <1> 	mov	[DestinationFile_DirEntry+DirEntry_FileSize], eax
  4711                              <1> csftdf2_save_fat_file_err3:
  4712 0000BF04 E8B3F0FFFF          <1> 	call	convert_current_date_time
  4713                              <1> 	; DX = Date in dos dir entry format
  4714                              <1> 	; AX = Time in dos dir entry format
  4715 0000BF09 C605[47880100]00    <1> 	mov	byte [DestinationFile_DirEntry+DirEntry_CrtTimeTenth], 0
  4716 0000BF10 66A3[48880100]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_CrtTime], ax
  4717 0000BF16 668915[4A880100]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_CrtDate], dx
  4718 0000BF1D 66A3[50880100]      <1> 	mov	[DestinationFile_DirEntry+DirEntry_WrtTime], ax
  4719 0000BF23 668915[52880100]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_WrtDate], dx
  4720 0000BF2A F9                  <1> 	stc
  4721                              <1> csftdf2_save_fat_file_7:
  4722 0000BF2B 9C                  <1> 	pushf
  4723 0000BF2C 668915[4C880100]    <1> 	mov	[DestinationFile_DirEntry+DirEntry_LastAccDate], dx
  4724 0000BF33 BE[3A880100]        <1> 	mov	esi, DestinationFile_DirEntry
  4725 0000BF38 BF00000800          <1> 	mov	edi, Directory_Buffer
  4726 0000BF3D 0FB70D[62880100]    <1> 	movzx	ecx, word [DestinationFile_DirEntryNumber] ; (<2048)
  4727                              <1> 	;shl	cx, 5 ; 32 * directory entry number
  4728                              <1> 	; 29/07/2022
  4729 0000BF44 C1E105              <1> 	shl	ecx, 5
  4730 0000BF47 01CF                <1> 	add	edi, ecx
  4731                              <1> 	;mov	ecx, 8
  4732                              <1> 	;mov	cx, 8
  4733                              <1> 	; 31/08/2024
  4734                              <1> 	; 29/07/2022
  4735 0000BF49 29C9                <1> 	sub	ecx, ecx
  4736                              <1> 	;sub	ch, ch
  4737 0000BF4B B108                <1> 	mov	cl, 8
  4738 0000BF4D F3A5                <1> 	rep	movsd
  4739 0000BF4F 9D                  <1> 	popf
  4740 0000BF50 730B                <1> 	jnc	short csftdf2_write_file_OK
  4741                              <1> 
  4742                              <1> csftdf2_write_error:
  4743                              <1> 	; 18/03/2016
  4744                              <1> 	;mov	al, 1Dh ; write error
  4745                              <1> 	; 31/08/2024
  4746 0000BF52 B012                <1> 	mov	al, ERR_DRV_WRITE ; 18 ; write error
  4747 0000BF54 EB02                <1> 	jmp	short csftdf2_rw_error
  4748                              <1> 
  4749                              <1> 	; 16/03/2016
  4750                              <1> csftdf2_read_error:
  4751 0000BF56 B011                <1> 	mov	al, 17 ; ; Drive not ready or read error!
  4752                              <1> csftdf2_rw_error:
  4753 0000BF58 A2[91880100]        <1> 	mov	[csftdf_rw_err], al
  4754                              <1> 
  4755                              <1> csftdf2_write_file_OK:
  4756                              <1> 	; 18/03/2016
  4757 0000BF5D C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  4758 0000BF64 E8E8F0FFFF          <1> 	call	save_directory_buffer
  4759                              <1> 
  4760                              <1>  	; Update last modification date&time of destination
  4761                              <1> 	; file's (parent) directory
  4762 0000BF69 E87BF1FFFF          <1> 	call	update_parent_dir_lmdt
  4763                              <1> 	;
  4764 0000BF6E A1[98880100]        <1> 	mov	eax, [csftdf_sf_mem_addr] ; start address
  4765                              <1> 
  4766 0000BF73 21C0                <1> 	and	eax, eax
  4767 0000BF75 7509                <1> 	jnz	short csftdf2_dealloc_mblock
  4768                              <1> 
  4769                              <1> 	; 31/08/2024
  4770                              <1> 	;mov	ch, al ; 0 (Cluster r/w, not full loading)
  4771                              <1> csftdf2_dealloc_retn:
  4772                              <1> 	;mov	cl, [csftdf_rw_err]
  4773                              <1> 	;mov	eax, [csftdf_df_cluster]
  4774                              <1> 	; 31/08/2024
  4775 0000BF77 A0[91880100]        <1> 	mov	al, [csftdf_rw_err]
  4776 0000BF7C 3C01                <1> 	cmp	al, 1
  4777 0000BF7E F5                  <1> 	cmc
  4778                              <1> 	; if al > 0 -> cf = 1
  4779                              <1> csftdf2_write_df_error:	; 31/08/2024
  4780                              <1> csftdf2_write_df_clust_@@: ; 31/08/2024
  4781 0000BF7F C3                  <1> 	retn
  4782                              <1> 
  4783                              <1> csftdf2_dealloc_mblock:
  4784 0000BF80 8B0D[9C880100]      <1> 	mov	ecx, [csftdf_sf_mem_bsize] ; block size
  4785 0000BF86 E8829FFFFF          <1> 	call	deallocate_memory_block
  4786                              <1> 	; 31/08/2024
  4787                              <1>         ;mov	ch, 0FFh ; (File was full loaded at memory)
  4788 0000BF8B EBEA                <1> 	jmp	short csftdf2_dealloc_retn
  4789                              <1> 
  4790                              <1> 	;;;;
  4791                              <1> csftdf2_update_df_fclust:
  4792                              <1> 	; 31/08/2024
  4793                              <1> 	; 27/08/2024 - TRDOS 386 v2.0.9
  4794                              <1> 	; update (directory entry of)
  4795                              <1> 	; the new (created) destination file
  4796                              <1> 	; with new first cluster (it was 0 before)
  4797                              <1> 	
  4798 0000BF8D 8B35[C0880100]      <1> 	mov	esi, [csftdf_df_drv_dt]	; (!)
  4799                              <1> 
  4800                              <1> csftdf2_update_df_fclust_@: ; 31/08/2024
  4801 0000BF93 A1[A4880100]        <1> 	mov	eax, [csftdf_df_cluster]
  4802 0000BF98 21C0                <1> 	and	eax, eax
  4803 0000BF9A 75E3                <1> 	jnz	short csftdf2_write_df_clust_@@
  4804                              <1> 	; if eax = 0, add new cluster
  4805                              <1> ; 31/08/2024
  4806                              <1> %if 0
  4807                              <1> 	call	get_first_free_cluster
  4808                              <1> 	jc	short csftdf2_write_df_error
  4809                              <1> 	; EAX >= 2 and EAX < FFFFFFFFh is valid
  4810                              <1> 
  4811                              <1> 	cmp	eax, 0FFFFFFFFh ; no free space
  4812                              <1> 	jne	short csftdf2_write_df_clust_@
  4813                              <1> 	inc	eax ; 0
  4814                              <1> 	stc
  4815                              <1> 	mov	al, 27h ; insufficient disk space
  4816                              <1> csftdf2_write_df_error:
  4817                              <1> 	retn
  4818                              <1> %else
  4819                              <1> 	; 31/08/2024
  4820 0000BF9C E80E0C0000          <1> 	call	add_new_cluster
  4821 0000BFA1 72DC                <1> 	jc	short csftdf2_write_df_error
  4822                              <1> %endif
  4823                              <1> 
  4824                              <1> csftdf2_write_df_clust_@:
  4825                              <1> 	; 31/08/2024
  4826 0000BFA3 A3[A4880100]        <1> 	mov	[csftdf_df_cluster], eax
  4827                              <1> 	;
  4828                              <1> 	; eax = (new) first cluster
  4829 0000BFA8 56                  <1> 	push	esi
  4830 0000BFA9 BE[3A880100]        <1> 	mov	esi, DestinationFile_DirEntry
  4831 0000BFAE 0FB73D[62880100]    <1> 	movzx	edi, word [DestinationFile_DirEntryNumber]
  4832 0000BFB5 C1E705              <1> 	shl	edi, 5 ; 32 * index number
  4833 0000BFB8 81C700000800        <1> 	add	edi, Directory_Buffer
  4834 0000BFBE C1C010              <1> 	rol	eax, 16
  4835 0000BFC1 66894614            <1> 	mov	[esi+DirEntry_FstClusHI],ax
  4836 0000BFC5 C1C810              <1> 	ror	eax, 16
  4837 0000BFC8 6689461A            <1> 	mov	[esi+DirEntry_FstClusLO],ax
  4838 0000BFCC B908000000          <1> 	mov	ecx, 8 ; 32 bytes
  4839 0000BFD1 F3A5                <1> 	rep	movsd
  4840 0000BFD3 5E                  <1> 	pop	esi
  4841                              <1> 	;
  4842 0000BFD4 C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2 ; change sign
  4843                              <1> 
  4844                              <1> ; 31/08/2024
  4845                              <1> %if 0
  4846                              <1> 	call	save_directory_buffer
  4847                              <1> 	jc	short csftdf2_write_df_error
  4848                              <1> 	;
  4849                              <1> 	; +1 cluster is in use (as first cluster)
  4850                              <1> 	mov	ebx, [esi+LD_FreeSectors]
  4851                              <1> 	inc	ebx  ; 0FFFFFFFFh ? invalid ?
  4852                              <1> 	jz	short csftdf2_write_df_clust_@@ ; yes
  4853                              <1> 	xor	ebx, ebx
  4854                              <1> 	mov	bl, [esi+LD_BPB+BPB_SecPerClust]
  4855                              <1> 	sub	[esi+LD_FreeSectors], ebx
  4856                              <1> 	;
  4857                              <1> csftdf2_write_df_clust_@@:
  4858                              <1> 	retn
  4859                              <1> 	;;;;
  4860                              <1> %else
  4861                              <1> 	; 31/08/2024
  4862 0000BFDB E971F0FFFF          <1> 	jmp	save_directory_buffer
  4863                              <1> %endif
  4864                              <1> 
  4865                              <1> csftdf2_save_fs_file:
  4866                              <1> 	; 16/10/2016 (1Dh -> 18)
  4867                              <1> 	; temporary - (21/03/2016)
  4868                              <1> 	;mov	eax, 18 ; write error
  4869                              <1> 	; 29/07/2022
  4870 0000BFE0 31C0                <1> 	xor	eax, eax
  4871 0000BFE2 B012                <1> 	mov	al, 18
  4872 0000BFE4 F9                  <1> 	stc
  4873 0000BFE5 C3                  <1> 	retn
  4874                              <1> 
  4875                              <1> create_file:
  4876                              <1> 	; 31/08/2024
  4877                              <1> 	; 29/08/2024
  4878                              <1> 	; 27/08/2024
  4879                              <1> 	; 26/08/2024 (TRDOS 386 v2.0.9)
  4880                              <1> 	; 30/07/2022
  4881                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  4882                              <1> 	; 16/10/2016
  4883                              <1> 	; 24/03/2016, 31/03/2016
  4884                              <1> 	; 20/03/2016, 21/03/2016, 23/03/2016
  4885                              <1> 	; 19/03/2016 (TRDOS 396 = TRDOS v2.0)
  4886                              <1> 	; 03/09/2011 (FILE.ASM, 'proc_create_file')
  4887                              <1> 	; 09/08/2010
  4888                              <1> 	;
  4889                              <1> 	; INPUT ->
  4890                              <1> 	; 	EAX = File Size
  4891                              <1> 	; 	ESI = ASCIIZ File Name
  4892                              <1> 	; 	CL = File Attributes 
  4893                              <1> 	;	EBX = FFFFFFFFh -> create empty file
  4894                              <1> 	;			 (only for FAT fs)
  4895                              <1> 	; OUTPUT ->
  4896                              <1> 	;	EAX = New file's first cluster
  4897                              <1> 	;		 (0 for empty file) ; 29/08/2024
  4898                              <1> 	;	ESI = Logical Dos Drv Descr. Table Addr.
  4899                              <1> 	;	;EBX = CreateFile_Size address
  4900                              <1> 	;	;ECX = Sectors per cluster (<256)
  4901                              <1> 	;	;EDX = Directory Entry Index/Number (<65536)
  4902                              <1> 	;	; 29/08/2024
  4903                              <1> 	;	EBX = File Size (0 for a new, empty file)
  4904                              <1> 	;	ECX = Directory Entry Index/Number (<2048)
  4905                              <1> 	;	     (in directory cluster, not in directory)
  4906                              <1> 	;	EDX = Directory Cluster Number (of the file)
  4907                              <1> 	;	
  4908                              <1> 	;	cf = 1 -> error code in AL (EAX)
  4909                              <1> 	;
  4910                              <1> 	; (Modified registers: eax, ebx, ecx, edx, esi, edi)
  4911                              <1> 	;
  4912                              <1> 
  4913                              <1> ;	test	cl, 18h (directory or volume name)
  4914                              <1> ;	jnz	short loc_createfile_access_denied
  4915 0000BFE6 80E107              <1> 	and	cl, 07h ; S, H, R
  4916 0000BFE9 880D[E0880100]      <1>         mov     [createfile_attrib], cl
  4917                              <1> 
  4918 0000BFEF 89D9                <1> 	mov	ecx, ebx
  4919 0000BFF1 89F3                <1> 	mov	ebx, esi ; ASCIIZ File Name address
  4920 0000BFF3 29D2                <1> 	sub	edx, edx
  4921 0000BFF5 8A35[827D0100]      <1>         mov     dh, [Current_Drv]
  4922 0000BFFB BE00010900          <1>         mov     esi, Logical_DOSDisks
  4923 0000C000 01D6                <1> 	add	esi, edx
  4924                              <1> 
  4925 0000C002 8815[EB880100]      <1> 	mov	[createfile_UpdatePDir], dl ; 0 ; 31/03/2016
  4926                              <1> 
  4927                              <1> 	; LD_DiskType = 0 for write protection (read only)
  4928 0000C008 807E0101            <1> 	cmp	byte [esi+LD_DiskType], 1 ; 0 = Invalid
  4929 0000C00C 7308                <1> 	jnb	short loc_createfile_check_file_sytem
  4930                              <1> 	; 16/10/2016 (TRDOS Error code: 30, disk write protected)
  4931                              <1> 	;mov	eax, 30 ; 13h, MSDOS err : Disk write-protected
  4932                              <1> 	;mov	dx, 0
  4933                              <1> 	; 29/07/2022
  4934 0000C00E 31D2                <1> 	xor	edx, edx ; 0
  4935 0000C010 31C0                <1> 	xor	eax, eax ; 0
  4936 0000C012 B01E                <1> 	mov	al, 30
  4937 0000C014 F9                  <1> 	stc
  4938                              <1> 	; err retn: EDX = 0, EBX = File name offset
  4939                              <1> 	; ESI -> Dos drive description table address
  4940 0000C015 C3                  <1> 	retn
  4941                              <1> 
  4942                              <1> ;loc_createfile_access_denied:
  4943                              <1> ;	mov	eax, 05h ; access denied (invalid attributes input)
  4944                              <1> ;	stc
  4945                              <1> ;	retn
  4946                              <1> 
  4947                              <1> loc_createfile_check_file_sytem:
  4948                              <1> 	; 27/08/2024
  4949 0000C016 A3[CC880100]        <1> 	mov	[createfile_size], eax
  4950                              <1> 	;
  4951 0000C01B 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  4952 0000C01F 7305                <1> 	jnb	short loc_createfile_chk_empty_FAT_file_sign1
  4953                              <1> 
  4954                              <1> 	; 27/08/2024
  4955                              <1> 	;mov	[createfile_size], eax
  4956                              <1> 	; ESI = Logical Dos Drive Description Table address
  4957                              <1> 	; EBX = ASCIIZ File Name address
  4958 0000C021 E9F9020000          <1> 	jmp	create_fs_file
  4959                              <1> 
  4960                              <1> loc_createfile_chk_empty_FAT_file_sign1:
  4961                              <1> 	; ECX = FFFFFFFFh -> create empty file if drive has FAT fs
  4962 0000C026 41                  <1> 	inc	ecx
  4963 0000C027 7506                <1> 	jnz	short loc_createfile_chk_empty_FAT_file_sign2
  4964                              <1> 
  4965 0000C029 890D[CC880100]      <1> 	mov	[createfile_size], ecx ; 0  ; empty file
  4966                              <1> 
  4967                              <1> loc_createfile_chk_empty_FAT_file_sign2:
  4968                              <1> 	; 23/03/2016
  4969 0000C02F 668B4E11            <1> 	mov	cx, [esi+LD_BPB+BytesPerSec]
  4970 0000C033 66890D[E8880100]    <1> 	mov	[createfile_BytesPerSec], cx
  4971                              <1> 
  4972                              <1> 	; EBX = ASCIIZ File Name address
  4973 0000C03A 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+SecPerClust]
  4974 0000C03E 8815[E1880100]      <1> 	mov	[createfile_SecPerClust], dl
  4975 0000C044 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
  4976 0000C047 39D1                <1> 	cmp	ecx, edx ; byte [createfile_SecPerClust]
  4977 0000C049 7306                <1> 	jnb	short loc_create_fat_file
  4978                              <1> 
  4979                              <1> loc_createfile_insufficient_disk_space:
  4980 0000C04B B827000000          <1> 	mov	eax, 27h
  4981                              <1> loc_createfile_gffc_retn:
  4982 0000C050 C3                  <1> 	retn
  4983                              <1> 
  4984                              <1> loc_create_fat_file:
  4985 0000C051 891D[C4880100]      <1> 	mov	[createfile_Name_Offset], ebx
  4986 0000C057 890D[C8880100]      <1> 	mov	[createfile_FreeSectors], ecx
  4987                              <1> 
  4988                              <1> 	; 27/08/2024
  4989                              <1> ;loc_createfile_gffc_1:
  4990                              <1> 	;call	get_first_free_cluster
  4991                              <1> 	;jc	short loc_createfile_gffc_retn
  4992                              <1> 	;
  4993                              <1> 	;mov	[createfile_FFCluster], eax
  4994                              <1> 
  4995                              <1> loc_createfile_locate_ffe_on_directory:
  4996                              <1> 	; Current directory fcluster <> Directory buffer cluster
  4997                              <1> 	; Current directory will be reloaded by
  4998                              <1> 	; 'locate_current_dir_file' procedure
  4999                              <1> 	;
  5000                              <1> 	; ESI = Logical Dos Drv Desc. Table Adress
  5001 0000C05D 56                  <1> 	push	esi ; *
  5002 0000C05E 31C0                <1> 	xor	eax, eax
  5003                              <1> 
  5004 0000C060 A3[9E840100]        <1> 	mov	[FAT_ClusterCounter], eax ; 0
  5005                              <1> 	; 21/03/2016
  5006 0000C065 A2[EA880100]        <1> 	mov	[createfile_wfc], al ; 0
  5007                              <1> 
  5008 0000C06A 89C1                <1>  	mov	ecx, eax
  5009 0000C06C 6649                <1> 	dec	cx ; FFFFh
  5010                              <1> 	; CX = FFFFh -> find first deleted or free entry
  5011                              <1> 	; ESI would be ASCIIZ filename address if the call
  5012                              <1> 	; would not be for first free or deleted dir entry
  5013 0000C06E E810E8FFFF          <1> 	call	locate_current_dir_file
  5014                              <1> 	;jnc	loc_createfile_set_ff_dir_entry
  5015                              <1> 	; 29/07/2022
  5016 0000C073 7205                <1> 	jc	short loc_createfile_locate_file_err
  5017                              <1> 	; 26/08/2024
  5018                              <1> 	; cl = 0FFh, ch=0 or ch=0E5h
  5019                              <1> 	; 27/08/2024
  5020                              <1> 	;xor	ecx, ecx ; 26/08/2024
  5021 0000C075 E9E5000000          <1> 	jmp	loc_createfile_set_ff_dir_entry
  5022                              <1> 
  5023                              <1> loc_createfile_locate_file_err: ; 29/07/2022
  5024 0000C07A 5E                  <1> 	pop	esi ; *
  5025                              <1> 	; ESI = Logical DOS Drv. Description Table Address
  5026 0000C07B 83F802              <1> 	cmp	eax, 2
  5027 0000C07E 7402                <1> 	je	short loc_createfile_add_new_cluster
  5028                              <1> loc_createfile_locate_file_stc_retn:
  5029 0000C080 F9                  <1> 	stc
  5030 0000C081 C3                  <1> 	retn
  5031                              <1> 
  5032                              <1> loc_createfile_add_new_cluster:
  5033 0000C082 803D[817D0100]02    <1> 	cmp	byte [Current_FATType], 2
  5034                              <1> 	;cmp	byte [esi+LD_FATType], 2
  5035 0000C089 770C                <1> 	ja	short loc_createfile_add_new_cluster_check_fsc
  5036 0000C08B 803D[807D0100]01    <1> 	cmp	byte [Current_Dir_Level], 1
  5037                              <1> 	;cmp	byte [esi+LD_CDirLevel], 1
  5038 0000C092 7303                <1> 	jnb	short loc_createfile_add_new_cluster_check_fsc
  5039                              <1> 
  5040                              <1> 	;mov	eax, 12
  5041 0000C094 B00C                <1> 	mov	al, 12 ; No more files 
  5042                              <1> 
  5043                              <1> loc_createfile_anc_retn:
  5044 0000C096 C3                  <1> 	retn
  5045                              <1> 
  5046                              <1> loc_createfile_add_new_cluster_check_fsc:
  5047 0000C097 8B0D[C8880100]      <1> 	mov	ecx, [createfile_FreeSectors]
  5048 0000C09D 0FB605[E1880100]    <1> 	movzx	eax, byte [createfile_SecPerClust]
  5049                              <1> 	;shl	ax, 1 ; AX = 2 * AX
  5050                              <1> 	; 29/07/2022
  5051 0000C0A4 D1E0                <1> 	shl	eax, 1
  5052 0000C0A6 39C1                <1> 	cmp	ecx, eax
  5053 0000C0A8 72A1                <1>         jb	short loc_createfile_insufficient_disk_space
  5054                              <1> 
  5055                              <1> loc_createfile_add_new_subdir_cluster:
  5056 0000C0AA 8B15[AE840100]      <1> 	mov	edx, [DirBuff_Cluster]
  5057 0000C0B0 8915[D4880100]      <1> 	mov	[createfile_LastDirCluster], edx
  5058                              <1> 
  5059                              <1> 	; 27/08/2024
  5060                              <1> 	;;;
  5061 0000C0B6 E887040000          <1> 	call	get_first_free_cluster
  5062 0000C0BB 72D9                <1> 	jc	short loc_createfile_anc_retn
  5063 0000C0BD A3[D0880100]        <1> 	mov	[createfile_FFCluster], eax
  5064                              <1> 	;;;
  5065                              <1> 	; 27/08/2024
  5066                              <1> 	;;;
  5067                              <1> 	;mov	eax, [createfile_FFCluster]
  5068                              <1> 	; eax = cluster address of the new directory sector
  5069                              <1> 	;;;
  5070                              <1> 
  5071 0000C0C2 E815040000          <1> 	call	load_FAT_sub_directory
  5072 0000C0C7 72CD                <1> 	jc	short loc_createfile_anc_retn
  5073                              <1> 
  5074                              <1> 	; 27/08/2024
  5075                              <1> 	; [DirBuff_Cluster] = [createfile_FFCluster]
  5076                              <1> 
  5077                              <1> pass_createfile_add_new_subdir_cluster:
  5078                              <1> 	; clear directory buffer (new dir sector) ; 27/08/2024
  5079                              <1> 	;movzx	eax, word [esi+LD_BPB+BytesPerSec]
  5080 0000C0C9 0FB705[E8880100]    <1> 	movzx	eax, word [createfile_BytesPerSec] ; 23/03/2016
  5081                              <1> 	; ecx = directory buffer sector count 
  5082                              <1> 	;	(sectors per cluster)
  5083 0000C0D0 F7E1                <1> 	mul	ecx
  5084 0000C0D2 89C1                <1> 	mov	ecx, eax 
  5085                              <1> 		; (bytes per cluster or directory buffer size)
  5086 0000C0D4 C1E902              <1> 	shr	ecx, 2 ; dword count
  5087 0000C0D7 29C0                <1> 	sub	eax, eax ; 0
  5088 0000C0D9 F3AB                <1> 	rep	stosd
  5089                              <1> 	;
  5090 0000C0DB C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  5091 0000C0E2 E86AEFFFFF          <1> 	call	save_directory_buffer
  5092 0000C0E7 72AD                <1> 	jc	short loc_createfile_anc_retn
  5093                              <1> 
  5094                              <1> loc_createfile_save_added_subdir_cluster:
  5095 0000C0E9 A1[D4880100]        <1> 	mov	eax, [createfile_LastDirCluster]
  5096 0000C0EE 8B0D[D0880100]      <1> 	mov	ecx, [createfile_FFCluster]
  5097 0000C0F4 E816050000          <1> 	call	update_cluster
  5098 0000C0F9 7304                <1> 	jnc	short loc_createfile_save_fat_buffer_0
  5099 0000C0FB 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  5100 0000C0FD 7518                <1> 	jnz	short loc_createfile_save_fat_buffer_stc_retn
  5101                              <1> 
  5102                              <1> loc_createfile_save_fat_buffer_0:
  5103 0000C0FF A1[D0880100]        <1> 	mov	eax, [createfile_FFCluster]
  5104 0000C104 A3[D4880100]        <1> 	mov	[createfile_LastDirCluster], eax
  5105                              <1> 	;mov	ecx, 0FFFFFFFh ; 28 bit
  5106                              <1> 	; 29/08/2024
  5107                              <1> 	; (update_cluster will save 28 bit cluster value)
  5108                              <1> 	;mov	ecx, 0FFFFFFFFh
  5109 0000C109 29C9                <1> 	sub	ecx, ecx
  5110 0000C10B 49                  <1> 	dec	ecx ; 0FFFFFFFFh
  5111 0000C10C E8FE040000          <1> 	call	update_cluster
  5112 0000C111 7306                <1> 	jnc	short loc_createfile_save_fat_buffer_1
  5113 0000C113 09C0                <1> 	or	eax, eax ; Was it EOF ?
  5114 0000C115 7402                <1> 	jz	short loc_createfile_save_fat_buffer_1 ; yes
  5115                              <1> 
  5116                              <1> loc_createfile_save_fat_buffer_stc_retn:
  5117 0000C117 F9                  <1> 	stc
  5118                              <1> loc_createfile_save_fat_buffer_retn:
  5119                              <1> loc_createfile_gffc_2_stc_retn:
  5120 0000C118 C3                  <1> 	retn
  5121                              <1> 
  5122                              <1> loc_createfile_save_fat_buffer_1:
  5123                              <1> 	; byte [FAT_BuffValidData] = 2
  5124 0000C119 E865070000          <1> 	call	save_fat_buffer
  5125 0000C11E 72F8                <1> 	jc	short loc_createfile_save_fat_buffer_retn
  5126                              <1> 
  5127 0000C120 803D[9E840100]01    <1> 	cmp	byte [FAT_ClusterCounter], 1
  5128 0000C127 7222                <1> 	jb	short loc_createfile_save_fat_buffer_2
  5129                              <1> 
  5130                              <1> 	; ESI = Logical DOS Drive Description Table address
  5131 0000C129 A1[9E840100]        <1> 	mov	eax, [FAT_ClusterCounter]
  5132                              <1> 
  5133 0000C12E C605[9E840100]00    <1> 	mov	byte [FAT_ClusterCounter], 0 ; 21/03/2016
  5134                              <1> 
  5135 0000C135 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters 
  5136 0000C139 E8D6070000          <1> 	call	calculate_fat_freespace
  5137                              <1> 
  5138                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
  5139                              <1> 	;jnz	short loc_createfile_save_fat_buffer_2
  5140                              <1> 
  5141                              <1> 	; ecx > 0 -> Recalculation is needed
  5142 0000C13E 09C9                <1> 	or	ecx, ecx 
  5143 0000C140 7409                <1> 	jz	short loc_createfile_save_fat_buffer_2
  5144                              <1> 
  5145 0000C142 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space
  5146 0000C146 E8C9070000          <1> 	call	calculate_fat_freespace
  5147                              <1> 
  5148                              <1> loc_createfile_save_fat_buffer_2:
  5149                              <1> 	;call	update_parent_dir_lmdt
  5150                              <1> 
  5151                              <1> 	; 27/08/2024
  5152                              <1> ;loc_createfile_gffc_2:
  5153                              <1> 	;call	get_first_free_cluster
  5154                              <1> 	;jc	short loc_createfile_gffc_2_stc_retn
  5155                              <1> 	;
  5156                              <1> 	;mov	[createfile_FFCluster], eax
  5157                              <1> 	;
  5158                              <1> 
  5159 0000C14B A1[D4880100]        <1> 	mov	eax, [createfile_LastDirCluster]
  5160                              <1> 
  5161 0000C150 E887030000          <1> 	call	load_FAT_sub_directory
  5162 0000C155 72C1                <1> 	jc	short loc_createfile_gffc_2_stc_retn
  5163                              <1> 
  5164 0000C157 BF00000800          <1> 	mov	edi, Directory_Buffer
  5165                              <1> 
  5166                              <1> 	; 27/08/2024
  5167                              <1> 	;sub	bx, bx ; directory entry index/number = 0
  5168 0000C15C 29DB                <1> 	sub	ebx, ebx
  5169                              <1> 	; 29/07/2022
  5170                              <1> 	;sub	ecx, ecx
  5171                              <1> 
  5172 0000C15E 56                  <1> 	push	esi ; * ; 23/03/2016
  5173                              <1> 
  5174                              <1> loc_createfile_set_ff_dir_entry:
  5175                              <1> 	;;;
  5176                              <1> 	; 29/08/2024
  5177 0000C15F A1[AE840100]        <1> 	mov	eax, [DirBuff_Cluster]
  5178 0000C164 A3[D4880100]        <1> 	mov	[createfile_LastDirCluster], eax
  5179                              <1> 	;;;
  5180                              <1> 
  5181                              <1> 	; 27/08/2024
  5182 0000C169 66891D[E2880100]    <1> 	mov	[createfile_DirIndex], bx
  5183                              <1> 	; 29/07/2022
  5184                              <1> 	;mov	[createfile_DirIndex], cx ; 0
  5185                              <1> 
  5186                              <1> 	;;;
  5187 0000C170 A1[CC880100]        <1> 	mov	eax, [createfile_size]
  5188 0000C175 09C0                <1> 	or	eax, eax 
  5189 0000C177 740A                <1> 	jz	short loc_createfile_sffc
  5190                              <1> 	; 31/08/2024
  5191 0000C179 8B3424              <1> 	mov	esi, [esp] ; * ; LDDDT address
  5192 0000C17C E8C1030000          <1> 	call	get_first_free_cluster
  5193 0000C181 7295                <1> 	jc	short loc_createfile_gffc_2_stc_retn
  5194                              <1> loc_createfile_sffc:
  5195 0000C183 A3[D0880100]        <1> 	mov	[createfile_FFCluster], eax
  5196 0000C188 29C9                <1> 	sub	ecx, ecx ; 0
  5197                              <1> 	;;;
  5198                              <1> 
  5199                              <1>         ; EDI = Directory entry address
  5200 0000C18A 8B35[C4880100]      <1> 	mov	esi, [createfile_Name_Offset]
  5201                              <1> 	;;;
  5202                              <1> 	; 27/08/2024
  5203                              <1> 	;mov	eax, [createfile_FFCluster]
  5204                              <1> 	;;;
  5205 0000C190 A3[D8880100]        <1> 	mov	[createfile_Cluster], eax ; 24/03/2016
  5206                              <1> 	;mov	ch, 0FFh
  5207                              <1>         ; 29/07/2022
  5208                              <1> 	; ecx = 0
  5209 0000C195 FECD                <1> 	dec	ch ; 0 -> 0FFh
  5210 0000C197 8A0D[E0880100]      <1> 	mov	cl, [createfile_attrib] ; file attributes
  5211                              <1> 	; CH > 0 -> File size is in [EBX]
  5212 0000C19D BB[CC880100]        <1> 	mov	ebx, createfile_size
  5213                              <1> 
  5214 0000C1A2 E8D7EDFFFF          <1> 	call	make_directory_entry
  5215                              <1> 
  5216 0000C1A7 5E                  <1> 	pop	esi ; * ; ESI = Logical Dos Drv Desc. Table address
  5217                              <1> 
  5218 0000C1A8 C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2
  5219 0000C1AF E89DEEFFFF          <1> 	call	save_directory_buffer
  5220 0000C1B4 7213                <1> 	jc	short loc_createfile_set_ff_dir_entry_retn
  5221                              <1> 
  5222 0000C1B6 C605[EB880100]01    <1> 	mov	byte [createfile_UpdatePDir], 1 ; 31/03/2016
  5223                              <1> 
  5224                              <1> loc_createfile_get_set_write_file_cluster:
  5225 0000C1BD A1[CC880100]        <1> 	mov	eax, [createfile_size]
  5226 0000C1C2 09C0                <1> 	or	eax, eax ; 0 ?
  5227 0000C1C4 755B                <1> 	jnz	short loc_createfile_get_set_wfc_cont ; no
  5228 0000C1C6 40                  <1> 	inc	eax ; eax = 1
  5229                              <1> 
  5230                              <1> 	; 27/08/2024 (empty file)
  5231                              <1> 	;;;
  5232                              <1> 	; 23/03/2016
  5233                              <1> 	;movzx	ebx, byte [createfile_SecPerClust]
  5234                              <1> 	;;movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 512
  5235                              <1>         ;movzx   ecx, word [createfile_BytesPerSec] ; 512
  5236                              <1> 	;;;
  5237 0000C1C7 EB74                <1> 	jmp	loc_createfile_set_cluster_count
  5238                              <1> 
  5239                              <1> loc_createfile_set_ff_dir_entry_retn:
  5240 0000C1C9 C3                  <1> 	retn
  5241                              <1> 
  5242                              <1> loc_createfile_write_fcluster_to_disk:
  5243 0000C1CA 034668              <1> 	add	eax, [esi+LD_DATABegin] ; convert to physical address
  5244 0000C1CD BB00000700          <1> 	mov	ebx, Cluster_Buffer
  5245                              <1> 	; ESI = Logical DOS Drv. Desc. Tbl. address
  5246                              <1> 	; EAX = Disk address
  5247                              <1> 	; EBX = Sector Buffer
  5248                              <1> 	; ECX = sectors per cluster
  5249 0000C1D2 E81A5E0000          <1> 	call	disk_write
  5250 0000C1D7 7211                <1> 	jc	short loc_createfile_dsk_wr_err
  5251                              <1> 
  5252                              <1> loc_createfile_update_fat_cluster:
  5253                              <1> 	; 21/03/2016
  5254 0000C1D9 803D[EA880100]00    <1> 	cmp	byte [createfile_wfc], 0
  5255 0000C1E0 7711                <1> 	ja	short loc_createfile_update_fat_cluster_n1
  5256                              <1> 
  5257 0000C1E2 FE05[EA880100]      <1> 	inc	byte [createfile_wfc] ; 1
  5258 0000C1E8 EB1F                <1> 	jmp	short loc_createfile_update_fat_cluster_n2
  5259                              <1> 
  5260                              <1> loc_createfile_dsk_wr_err:
  5261                              <1> 	; 16/10/2016 (1Dh -> 18)
  5262                              <1> 	; 23/03/2016
  5263                              <1> 	;mov	eax, 18 ; Drive not ready or write error !
  5264                              <1> 	; 29/07/2022
  5265 0000C1EA 29C0                <1> 	sub	eax, eax
  5266 0000C1EC B012                <1> 	mov	al, 18
  5267                              <1> loc_cf_stc_retn:
  5268 0000C1EE E9BC000000          <1> 	jmp	loc_createfile_stc_retn
  5269                              <1> 
  5270                              <1> loc_createfile_update_fat_cluster_n1:
  5271 0000C1F3 A1[DC880100]        <1> 	mov	eax, [createfile_PCluster]
  5272 0000C1F8 8B0D[D8880100]      <1> 	mov	ecx, [createfile_Cluster]
  5273 0000C1FE E80C040000          <1> 	call	update_cluster
  5274 0000C203 7304                <1> 	jnc	short loc_createfile_update_fat_cluster_n2
  5275 0000C205 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  5276                              <1> 	;jnz	loc_createfile_stc_retn
  5277                              <1> 	; 29/07/2022
  5278 0000C207 75E5                <1> 	jnz	short loc_cf_stc_retn
  5279                              <1> 
  5280                              <1> loc_createfile_update_fat_cluster_n2:
  5281 0000C209 A1[D8880100]        <1>         mov	eax, [createfile_Cluster]
  5282                              <1> 	;mov	ecx, 0FFFFFFFh
  5283                              <1> 	; 29/08/2024
  5284                              <1> 	; (update_cluster will save 28 bit cluster value)
  5285                              <1> 	;mov	ecx, 0FFFFFFFFh
  5286 0000C20E 29C9                <1> 	sub	ecx, ecx
  5287 0000C210 49                  <1> 	dec	ecx
  5288 0000C211 E8F9030000          <1> 	call	update_cluster
  5289 0000C216 7355                <1> 	jnc	short loc_createfile_save_fat_buffer_3
  5290 0000C218 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  5291 0000C21A 7451                <1> 	jz	short loc_createfile_save_fat_buffer_3
  5292                              <1> 
  5293                              <1> loc_cf_upd_fat_fcluster_stc_retn:
  5294 0000C21C E98E000000          <1> 	jmp	loc_createfile_stc_retn
  5295                              <1> 
  5296                              <1> loc_createfile_get_set_wfc_cont:
  5297                              <1> 	;movzx	ecx, word [esi+LD_BPB+BytesPerSec] ; 512
  5298 0000C221 0FB70D[E8880100]    <1> 	movzx	ecx, word [createfile_BytesPerSec] ; 512
  5299 0000C228 01C8                <1> 	add	eax, ecx
  5300 0000C22A 48                  <1> 	dec	eax  ; add eax, 511
  5301 0000C22B 29D2                <1> 	sub	edx, edx
  5302 0000C22D F7F1                <1> 	div	ecx
  5303 0000C22F 0FB61D[E1880100]    <1> 	movzx	ebx, byte [createfile_SecPerClust]
  5304 0000C236 01D8                <1> 	add	eax, ebx
  5305 0000C238 48                  <1> 	dec	eax  ; add eax, SecPerClust - 1
  5306                              <1> 	;xor	dx, dx
  5307                              <1> 	; 27/08/2024
  5308 0000C239 31D2                <1> 	xor	edx, edx
  5309 0000C23B F7F3                <1> 	div	ebx
  5310                              <1> 
  5311                              <1> loc_createfile_set_cluster_count:
  5312 0000C23D A3[E4880100]        <1> 	mov 	[createfile_CCount], eax
  5313                              <1> 
  5314                              <1> 	; 31/08/2024
  5315                              <1> 	;;;
  5316 0000C242 833D[CC880100]00    <1> 	cmp	dword [createfile_size], 0 ; empty file ?
  5317 0000C249 7422                <1> 	jz	short loc_createfile_save_fat_buffer_3
  5318                              <1> 	;;;
  5319                              <1> 
  5320 0000C24B BF00000700          <1> 	mov	edi, Cluster_Buffer
  5321 0000C250 89C8                <1> 	mov	eax, ecx ; Bytes per Sector
  5322 0000C252 F7E3                <1> 	mul	ebx ; Sectors per Cluster
  5323                              <1> 	; EAX = Bytes per Cluster
  5324 0000C254 89C1                <1> 	mov	ecx, eax
  5325 0000C256 C1E902              <1> 	shr	ecx, 2 ; dword count
  5326 0000C259 31C0                <1> 	xor	eax, eax
  5327 0000C25B F3AB                <1> 	rep	stosd ; clear cluster buffer
  5328                              <1> 
  5329 0000C25D A1[D8880100]        <1> 	mov	eax, [createfile_Cluster] ; 24/03/2016
  5330                              <1> 
  5331 0000C262 89D9                <1> 	mov	ecx, ebx
  5332                              <1> 
  5333                              <1> loc_createfile_get_set_wf_fclust_cont:
  5334                              <1> 	;sub	eax, 2
  5335                              <1> 	; 30/07/2022
  5336 0000C264 48                  <1> 	dec	eax
  5337 0000C265 48                  <1> 	dec	eax
  5338 0000C266 F7E1                <1> 	mul	ecx
  5339                              <1> 	; EAX = Logical DOS disk address (offset)
  5340 0000C268 E95DFFFFFF          <1>         jmp     loc_createfile_write_fcluster_to_disk
  5341                              <1> 
  5342                              <1> loc_createfile_save_fat_buffer_3:
  5343                              <1> 	; byte [FAT_BuffValidData] = 2
  5344 0000C26D E811060000          <1> 	call	save_fat_buffer
  5345                              <1> 	;jc	loc_createfile_stc_retn
  5346                              <1> 	; 29/07/2022
  5347 0000C272 72A8                <1> 	jc	short loc_cf_upd_fat_fcluster_stc_retn
  5348                              <1> 
  5349                              <1> 	; 21/03/2016
  5350                              <1> 	;cmp	byte [FAT_ClusterCounter], 1
  5351                              <1> 	;jb	short loc_createfile_save_fat_buffer_4
  5352                              <1> 	; 31/08/2024
  5353 0000C274 803D[9E840100]00    <1> 	cmp	byte [FAT_ClusterCounter], 0
  5354 0000C27B 761B                <1> 	jna	short loc_createfile_save_fat_buffer_4 ; cf = 0
  5355                              <1> 
  5356                              <1> 	; ESI = Logical DOS Drive Description Table address
  5357 0000C27D A1[9E840100]        <1> 	mov	eax, [FAT_ClusterCounter]
  5358 0000C282 66BB01FF            <1> 	mov	bx, 0FF01h ; add free clusters
  5359 0000C286 E889060000          <1> 	call	calculate_fat_freespace
  5360                              <1> 
  5361                              <1> 	;inc	eax ; 0FFFFFFFFh -> 0 ; recalculation is needed!
  5362                              <1> 	;jnz	short loc_createfile_save_fat_buffer_4
  5363                              <1> 
  5364                              <1> 	; ecx > 0 -> Recalculation is needed
  5365 0000C28B 09C9                <1> 	or	ecx, ecx 
  5366 0000C28D 7409                <1> 	jz	short loc_createfile_save_fat_buffer_4
  5367                              <1> 
  5368 0000C28F 66BB00FF            <1> 	mov	bx, 0FF00h ; ; recalculate free space
  5369 0000C293 E87C060000          <1> 	call	calculate_fat_freespace
  5370                              <1> 
  5371                              <1> loc_createfile_save_fat_buffer_4:
  5372 0000C298 FF0D[E4880100]      <1> 	dec	dword [createfile_CCount]
  5373                              <1> 	;jz	short loc_createfile_upd_dir_modif_date_time
  5374 0000C29E 743D                <1> 	jz	short loc_createfile_stc_retn_cc ; 31/03/2016
  5375                              <1> 
  5376                              <1> loc_createfile_get_set_write_next_cluster:
  5377 0000C2A0 E89D020000          <1> 	call	get_first_free_cluster
  5378 0000C2A5 7208                <1> 	jc	short loc_createfile_stc_retn
  5379                              <1> 
  5380                              <1> loc_createfile_get_set_write_next_cluster_1:
  5381 0000C2A7 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh
  5382 0000C2AA 7211                <1> 	jb	short loc_createfile_get_set_write_next_cluster_2
  5383                              <1> 
  5384                              <1> ;loc_createfile_wnc_insufficient_disk_space:
  5385                              <1> 	;mov	eax, 27h ; Insufficient disk space
  5386                              <1> 	; 29/07/2022
  5387                              <1> 	;xor	eax, eax
  5388                              <1> 	; 29/08/2024
  5389                              <1> 	; eax = FFFFFFFFh
  5390 0000C2AC 40                  <1> 	inc	eax ; eax = 0
  5391 0000C2AD B027                <1> 	mov	al, 27h
  5392                              <1> 
  5393                              <1> loc_createfile_stc_retn:
  5394 0000C2AF 803D[EA880100]01    <1> 	cmp	byte [createfile_wfc], 1
  5395 0000C2B6 7324                <1> 	jnb	short loc_createfile_err_retn
  5396 0000C2B8 C3                  <1> 	retn
  5397                              <1> 
  5398                              <1> loc_createfile_wnc_inv_format_retn:
  5399                              <1> 	;mov	eax, 28
  5400 0000C2B9 B01C                <1> 	mov	al, 28 ; Invalid format
  5401 0000C2BB EBF2                <1> 	jmp	short loc_createfile_stc_retn
  5402                              <1> 
  5403                              <1> loc_createfile_get_set_write_next_cluster_2:
  5404 0000C2BD 83F802              <1> 	cmp	eax, 2
  5405 0000C2C0 72F7                <1> 	jb	short loc_createfile_wnc_inv_format_retn
  5406                              <1> 
  5407                              <1> loc_createfile_get_set_write_next_cluster_3:
  5408 0000C2C2 8B0D[D8880100]      <1> 	mov	ecx, [createfile_Cluster]
  5409 0000C2C8 A3[D8880100]        <1> 	mov	[createfile_Cluster], eax
  5410 0000C2CD 890D[DC880100]      <1> 	mov	[createfile_PCluster], ecx
  5411 0000C2D3 0FB60D[E1880100]    <1> 	movzx	ecx, byte [createfile_SecPerClust]
  5412 0000C2DA EB88                <1> 	jmp	short loc_createfile_get_set_wf_fclust_cont
  5413                              <1> 
  5414                              <1> loc_createfile_err_retn:
  5415 0000C2DC F9                  <1> 	stc
  5416                              <1> 
  5417                              <1> ;loc_createfile_upd_dir_modif_date_time:
  5418                              <1> loc_createfile_stc_retn_cc: ; 31/03/2016
  5419 0000C2DD 9C                  <1> 	pushf	; cpu is here for an error return or completion
  5420 0000C2DE 50                  <1> 	push	eax ; error code if cf = 1
  5421                              <1> 
  5422                              <1> 	;call	update_parent_dir_lmdt
  5423                              <1> 
  5424                              <1> ;loc_createfile_stc_retn_cc:
  5425 0000C2DF A1[9E840100]        <1> 	mov	eax, [FAT_ClusterCounter]
  5426 0000C2E4 09C0                <1> 	or	eax, eax
  5427 0000C2E6 741A                <1> 	jz	short loc_createfile_stc_retn_pop_eax
  5428 0000C2E8 8A3D[827D0100]      <1> 	mov	bh, [Current_Drv]
  5429 0000C2EE B301                <1> 	mov	bl, 01h ; BL = 1 -> add clusters
  5430                              <1> 	; NOTE: EAX value will be added to Free Cluster Count
  5431                              <1> 	; (If EAX value is negative, Free Cluster Count will be decreased)
  5432 0000C2F0 E81F060000          <1>   	call	calculate_fat_freespace
  5433                              <1>         ; ESI = Logical DOS Drive Description Table Address
  5434                              <1>         ;jc	short loc_createfile_stc_retn_pop_eax_cf
  5435 0000C2F5 21C9                <1> 	and	ecx, ecx ; cx = 0 -> valid free sector count
  5436 0000C2F7 7409                <1> 	jz	short loc_createfile_stc_retn_pop_eax
  5437                              <1> 
  5438                              <1> loc_createfile_stc_retn_recalc_FAT_freespace:
  5439 0000C2F9 66BB00FF            <1> 	mov	bx, 0FF00h ; bh = 0FFh ->
  5440                              <1> 	; ESI = Logical DOS Drv DT Addr
  5441                              <1> 	; BL = 0 -> Recalculate 
  5442 0000C2FD E812060000          <1> 	call	calculate_fat_freespace
  5443                              <1> 
  5444                              <1> loc_createfile_stc_retn_pop_eax:
  5445 0000C302 58                  <1> 	pop	eax
  5446 0000C303 9D                  <1> 	popf
  5447 0000C304 7218                <1> 	jc	short loc_createfile_retn
  5448                              <1> 
  5449                              <1> loc_createfile_retn_fcluster:
  5450 0000C306 A1[D0880100]        <1> 	mov	eax, [createfile_FFCluster]
  5451                              <1> 	;mov	ebx, createfile_size
  5452                              <1> 	;;movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  5453                              <1> 	;movzx	ecx, byte [createfile_SecPerClust] ; 23/03/2016
  5454                              <1> 	;movzx	edx, word [createfile_DirIndex]
  5455                              <1> 	; 29/08/2024 - TRDOS 386 v2.0.9
  5456 0000C30B 8B1D[CC880100]      <1> 	mov	ebx, [createfile_size]
  5457 0000C311 0FB70D[E2880100]    <1> 	movzx	ecx, word [createfile_DirIndex] ; = directory entry index
  5458 0000C318 8B15[D4880100]      <1> 	mov	edx, [createfile_LastDirCluster] ; = [DirBuff_Cluster]
  5459                              <1> 	; esi = Logical DOS Drive Description Table address 
  5460                              <1> 	; byte [esi] = drive name ; 'A','B','C','D'
  5461                              <1> 
  5462                              <1> loc_createfile_retn:
  5463 0000C31E C3                  <1> 	retn
  5464                              <1> 
  5465                              <1> ; 28/07/2022 (TRDOS 386 Kernel v2.0.5)
  5466                              <1> 
  5467                              <1> create_fs_file:
  5468                              <1> 	; temporary (21/03/2016)
  5469                              <1> 	;retn
  5470                              <1> 
  5471                              <1> delete_fs_file:
  5472                              <1> 	; temporary (28/02/2016)
  5473                              <1> 	;retn
  5474                              <1> 
  5475                              <1> rename_fs_file_or_directory:
  5476                              <1> 	;retn
  5477                              <1> 
  5478                              <1> make_fs_directory:
  5479                              <1> 	; temporary (21/02/2016)
  5480                              <1> 	;retn
  5481                              <1> 
  5482                              <1> add_new_fs_section:
  5483                              <1> 	; temporary (11/03/2016)
  5484                              <1> 	;retn
  5485                              <1> 
  5486                              <1> delete_fs_directory_entry:
  5487                              <1> 	; temporary (11/03/2016)
  5488                              <1> 	;retn
  5489                              <1> 
  5490                              <1> csftdf2_read_fs_file_sectors:
  5491                              <1> 	; temporary (19/03/2016)
  5492                              <1> 	;retn
  5493                              <1> 
  5494                              <1> csftdf2_write_fs_file_sectors:
  5495                              <1> 	; temporary (19/03/2016)
  5496 0000C31F C3                  <1> 	retn
  3434                                  %include 'trdosk5.s' ; 24/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.9) - File System Procedures : trdosk5s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 31/08/2024 (Previous: 07/08/2022)
     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> 	; 07/08/2022
    17                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
    18                              <1> 	; 15/10/2016
    19                              <1> 	; 23/03/2016
    20                              <1> 	; 01/02/2016 (TRDOS 386 = TRDOS v2.0)
    21                              <1> 	; 05/07/2011
    22                              <1> 	; 07/07/2009
    23                              <1> 	; 2005
    24                              <1> 	; INPUT ->
    25                              <1> 	;	EAX = Cluster Number (32 bit)
    26                              <1> 	;	ESI = Logical DOS Drive Parameters Table
    27                              <1> 	; OUTPUT ->
    28                              <1> 	;	cf = 0 -> No Error, EAX valid
    29                              <1> 	;	cf = 1 & EAX = 0 -> End Of Cluster Chain
    30                              <1> 	;	cf = 1 & EAX > 0 -> Error
    31                              <1> 	;	ECX = Current/Previous cluster (if CF = 0)
    32                              <1> 	;	EAX = Next Cluster Number (32 bit)
    33                              <1> 	;
    34                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
    35                              <1> 
    36 0000C320 A3[92840100]        <1> 	mov	[FAT_CurrentCluster], eax
    37                              <1> check_next_cluster_fat_type:
    38 0000C325 29D2                <1> 	sub	edx, edx ; 0
    39 0000C327 807E0302            <1> 	cmp     byte [esi+LD_FATType], 2
    40 0000C32B 7243                <1> 	jb	short get_FAT12_next_cluster
    41                              <1> 	;ja	get_FAT32_next_cluster
    42                              <1> 	; 25/07/2022
    43 0000C32D 7605                <1> 	jna	short get_FAT16_next_cluster
    44 0000C32F E9B2000000          <1> 	jmp	get_FAT32_next_cluster
    45                              <1> 
    46                              <1> get_FAT16_next_cluster:
    47 0000C334 BB00030000          <1> 	mov	ebx, 300h ;768
    48 0000C339 F7F3                <1> 	div	ebx
    49                              <1> 	; EAX = Count of 3 FAT sectors
    50                              <1> 	; EDX = Cluster Offset (< 768)
    51                              <1> 	;shl	dx, 1 ; Multiply by 2
    52                              <1> 	; 25/07/2022
    53 0000C33B D1E2                <1> 	shl	edx, 1
    54 0000C33D 89D3                <1> 	mov	ebx, edx ; Byte Offset
    55 0000C33F 81C3001C0900        <1> 	add	ebx, FAT_Buffer
    56 0000C345 66BA0300            <1> 	mov	dx, 3
    57 0000C349 F7E2                <1> 	mul	edx
    58                              <1> 	; EAX = FAT Sector (<= 256)
    59                              <1> 	; EDX = 0
    60 0000C34B 8A0E                <1> 	mov	cl, [esi+LD_Name]
    61                              <1> 	;cmp	byte [FAT_BuffValidData], 0
    62 0000C34D 3815[96840100]      <1>         cmp	[FAT_BuffValidData], dl ; 0
    63 0000C353 7674                <1> 	jna	short load_FAT_sectors0
    64 0000C355 3A0D[97840100]      <1> 	cmp	cl, [FAT_BuffDrvName]
    65 0000C35B 756C                <1>         jne	short load_FAT_sectors0
    66 0000C35D 3B05[9A840100]      <1> 	cmp	eax, [FAT_BuffSector]
    67 0000C363 756A                <1>         jne	short load_FAT_sectors1
    68                              <1> 	;movzx	eax, word [ebx]
    69 0000C365 668B03              <1> 	mov	ax, [ebx]
    70                              <1> 	; 01/02/2016
    71                              <1> 	; DRV_FAT.ASM (21/08/2011) had a FATal bug here !
    72                              <1> 	; (cmp ah, 0Fh) ! (ax >= FF7h)
    73                              <1> 	; (how can i do a such mistake!?)
    74                              <1> 	;cmp	al, 0F7h
    75                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
    76                              <1> 	;cmp	ah, 0FFh
    77                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
    78 0000C368 6683F8F7            <1> 	cmp	ax, 0FFF7h
    79 0000C36C 724E                <1> 	jb	short loc_pass_gnc_FAT16_eoc_check
    80                              <1> 	; ax >= FFF7h (cluster 0002h to FFF6h is valid, in use)
    81 0000C36E EB4A                <1> 	jmp	short loc_pass_gnc_FAT16_eoc_check_xor_eax
    82                              <1> 
    83                              <1> get_FAT12_next_cluster:
    84 0000C370 BB00040000          <1> 	mov	ebx, 400h ;1024
    85 0000C375 F7F3                <1> 	div	ebx
    86                              <1> 	; EAX = Count of 3 FAT sectors
    87                              <1> 	; EDX = Cluster Offset (< 1024)
    88                              <1> 	; 25/07/2022
    89                              <1> 	;push	ax
    90 0000C377 50                  <1> 	push	eax
    91                              <1> 	;mov	ax, 3
    92 0000C378 B003                <1> 	mov	al, 3
    93                              <1> 	;mul	dx    	; Multiply by 3
    94 0000C37A F7E2                <1> 	mul	edx
    95                              <1> 	;shr	ax, 1	; Divide by 2
    96 0000C37C D1E8                <1>         shr	eax, 1
    97                              <1> 	;mov	bx, ax 	; Byte Offset
    98 0000C37E 89C3                <1> 	mov	ebx, eax
    99 0000C380 81C3001C0900        <1> 	add	ebx, FAT_Buffer
   100 0000C386 58                  <1> 	pop	eax
   101                              <1> 	;pop	ax
   102                              <1> 	;mov	dx, 3
   103 0000C387 B203                <1> 	mov	dl, 3
   104 0000C389 F7E2                <1> 	mul	edx
   105                              <1> 	; EAX = FAT Sector (<= 12)
   106                              <1> 	; EDX = 0
   107 0000C38B 8A0E                <1> 	mov	cl, [esi+LD_Name]
   108                              <1> 	;cmp	byte [FAT_BuffValidData], 0
   109 0000C38D 3815[96840100]      <1> 	cmp	[FAT_BuffValidData], dl ; 0
   110 0000C393 7634                <1> 	jna	short load_FAT_sectors0
   111 0000C395 3A0D[97840100]      <1> 	cmp	cl, [FAT_BuffDrvName]
   112 0000C39B 752C                <1> 	jne	short load_FAT_sectors0
   113 0000C39D 3B05[9A840100]      <1> 	cmp	eax, [FAT_BuffSector]
   114 0000C3A3 752A                <1> 	jne	short load_FAT_sectors1
   115 0000C3A5 A1[92840100]        <1> 	mov	eax, [FAT_CurrentCluster]
   116                              <1> 	;shr	ax, 1
   117                              <1> 	; 25/07/2022
   118 0000C3AA D1E8                <1> 	shr	eax, 1
   119                              <1> 	;movzx	eax, word [ebx]
   120 0000C3AC 668B03              <1> 	mov	ax, [ebx]
   121 0000C3AF 7313                <1> 	jnc	short get_FAT12_nc_even
   122                              <1> 	;shr	ax, 4
   123 0000C3B1 C1E804              <1> 	shr	eax, 4
   124                              <1> loc_gnc_fat12_eoc_check:
   125                              <1> 	;cmp	al, 0F7h
   126                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
   127                              <1> 	;cmp	ah, 0Fh
   128                              <1> 	;jb	short loc_pass_gnc_FAT16_eoc_check
   129 0000C3B4 663DF70F            <1> 	cmp	ax, 0FF7h
   130 0000C3B8 7202                <1> 	jb	short loc_pass_gnc_FAT16_eoc_check
   131                              <1> 	; ax >= FF7h (cluster 0002h to FF6h is valid, in use)
   132                              <1> 
   133                              <1> loc_pass_gnc_FAT16_eoc_check_xor_eax:
   134 0000C3BA 31C0                <1> 	xor	eax, eax ; 0
   135                              <1> loc_pass_gnc_FAT16_eoc_check:
   136                              <1> loc_pass_gnc_FAT32_eoc_check:
   137 0000C3BC 8B0D[92840100]      <1> 	mov	ecx, [FAT_CurrentCluster]
   138 0000C3C2 F5                  <1> 	cmc
   139 0000C3C3 C3                  <1> 	retn
   140                              <1> 
   141                              <1> get_FAT12_nc_even:
   142 0000C3C4 80E40F              <1> 	and	ah, 0Fh
   143 0000C3C7 EBEB                <1> 	jmp	short loc_gnc_fat12_eoc_check
   144                              <1> 
   145                              <1> load_FAT_sectors0:
   146 0000C3C9 880D[97840100]      <1> 	mov	[FAT_BuffDrvName], cl
   147                              <1> load_FAT_sectors1:
   148                              <1> 	; 25/07/2022
   149                              <1> 	;sub	edx, edx
   150                              <1> 	; edx = 0
   151 0000C3CF A3[9A840100]        <1> 	mov	[FAT_BuffSector], eax
   152 0000C3D4 89C3                <1> 	mov	ebx, eax
   153 0000C3D6 034660              <1>         add     eax, [esi+LD_FATBegin]
   154 0000C3D9 B202                <1> 	mov	dl, 2
   155                              <1> 	;cmp	byte [esi+LD_FATType], 2
   156 0000C3DB 385603              <1>         cmp	[esi+LD_FATType], dl ; 2
   157 0000C3DE 7748                <1> 	ja      short load_FAT_sectors3
   158 0000C3E0 0FB74E1C            <1> 	movzx	ecx, word [esi+LD_BPB+BPB_FATSz16]
   159 0000C3E4 EB45                <1> 	jmp	short load_FAT_sectors4
   160                              <1> 
   161                              <1> 	; 07/08/2022
   162                              <1> get_FAT32_next_cluster:
   163 0000C3E6 BB80010000          <1> 	mov	ebx, 180h ;384
   164 0000C3EB F7F3                <1> 	div	ebx
   165                              <1> 	; EAX = Count of 3 FAT sectors
   166                              <1> 	; EDX = Cluster Offset (< 384)
   167                              <1> 	;shl	dx, 2	; Multiply by 4
   168                              <1> 	; 25/07/2022
   169 0000C3ED C1E202              <1> 	shl	edx, 2
   170 0000C3F0 89D3                <1> 	mov	ebx, edx ; Byte Offset
   171 0000C3F2 81C3001C0900        <1> 	add	ebx, FAT_Buffer
   172 0000C3F8 66BA0300            <1> 	mov	dx, 3
   173 0000C3FC F7E2                <1> 	mul	edx
   174                              <1>         ; EAX = FAT Sector (<= 2097152) ; (FFFFFF7h * 4) / 512
   175                              <1> 	; 	for 32KB cluster size:
   176                              <1> 	;	EAX <= 1024 = (4GB / 32KB) * 4) / 512
   177                              <1> 	; EDX = 0
   178 0000C3FE 8A0E                <1> 	mov	cl, [esi+LD_Name]
   179                              <1> 	;cmp	byte [FAT_BuffValidData], 0
   180 0000C400 3815[96840100]      <1> 	cmp	[FAT_BuffValidData], dl ; 0
   181 0000C406 76C1                <1> 	jna	short load_FAT_sectors0
   182 0000C408 3A0D[97840100]      <1> 	cmp	cl, [FAT_BuffDrvName]
   183 0000C40E 75B9                <1> 	jne	short load_FAT_sectors0
   184 0000C410 3B05[9A840100]      <1> 	cmp	eax, [FAT_BuffSector] ; 0, 3, 6, 9 ...
   185 0000C416 75B7                <1> 	jne	short load_FAT_sectors1
   186 0000C418 8B03                <1> 	mov	eax, [ebx]
   187 0000C41A 25FFFFFF0F          <1>  	and	eax, 0FFFFFFFh ; 28 bit Cluster
   188 0000C41F 3DF7FFFF0F          <1> 	cmp	eax, 0FFFFFF7h
   189 0000C424 7296                <1> 	jb	short loc_pass_gnc_FAT32_eoc_check
   190                              <1> 	; eax >= FFFFFF7h (cluster 0002h to FFFFFF6h is valid)
   191 0000C426 EB92                <1> 	jmp	short loc_pass_gnc_FAT16_eoc_check_xor_eax
   192                              <1> 
   193                              <1> load_FAT_sectors3:
   194 0000C428 8B4E2A              <1> 	mov	ecx, [esi+LD_BPB+BPB_FATSz32]
   195                              <1> load_FAT_sectors4:
   196 0000C42B 29D9                <1> 	sub	ecx, ebx ; [FAT_BuffSector]
   197                              <1> 	; 25/07/2022
   198 0000C42D FEC2                <1> 	inc	dl
   199                              <1> 	; edx = 3
   200                              <1>         ;cmp	ecx, 3
   201 0000C42F 39D1                <1>         cmp	ecx, edx ; 3
   202 0000C431 7602                <1> 	jna     short load_FAT_sectors5
   203                              <1> 	;mov	ecx, 3
   204                              <1> 	; 25/07/2022
   205 0000C433 89D1                <1> 	mov	ecx, edx ; 3
   206                              <1> load_FAT_sectors5:
   207 0000C435 BB001C0900          <1> 	mov	ebx, FAT_Buffer
   208 0000C43A E8C15B0000          <1> 	call	disk_read
   209 0000C43F 730C                <1> 	jnc	short load_FAT_sectors_ok
   210                              <1> 	; 15/10/2016 (15h -> 17)
   211                              <1> 	; 23/03/2016 (15h)
   212 0000C441 B811000000          <1> 	mov	eax, 17 ; Drive not ready or read error
   213                              <1> 	;mov	byte [FAT_BuffValidData], 0
   214                              <1> 	; 25/07/2022
   215 0000C446 8825[96840100]      <1> 	mov	byte [FAT_BuffValidData], ah ; 0
   216 0000C44C C3                  <1> 	retn
   217                              <1> load_FAT_sectors_ok:
   218 0000C44D C605[96840100]01    <1> 	mov	byte [FAT_BuffValidData], 1
   219 0000C454 A1[92840100]        <1> 	mov	eax, [FAT_CurrentCluster]
   220 0000C459 E9C7FEFFFF          <1>         jmp     check_next_cluster_fat_type
   221                              <1> 
   222                              <1> load_FAT_root_directory:
   223                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   224                              <1> 	; 23/10/2016
   225                              <1> 	; 15/10/2016
   226                              <1> 	; 07/02/2016
   227                              <1> 	; 02/02/2016
   228                              <1> 	; 01/02/2016 (TRDOS 386 = TRDOS v2.0)
   229                              <1> 	; 21/05/2011
   230                              <1> 	; 22/08/2009
   231                              <1> 	;
   232                              <1> 	; INPUT ->
   233                              <1> 	;	ESI = Logical DOS Drive Description Table
   234                              <1> 	; OUTPUT ->
   235                              <1> 	;	cf = 1 -> Root directory could not be loaded
   236                              <1> 	;	    EAX > 0 -> Error number
   237                              <1> 	;	cf = 0 -> EAX = 0
   238                              <1> 	;	ECX = Directory buffer size in sectors (CL)
   239                              <1> 	;	EBX = Directory buffer address
   240                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
   241                              <1> 	;
   242                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
   243                              <1> 
   244                              <1> 	; NOTE: Only for FAT12 and FAT16 file systems !
   245                              <1> 	; (FAT32 fs root dir must be loaded as sub directory)
   246                              <1> 
   247 0000C45E 8A1E                <1> 	mov	bl, [esi+LD_Name]
   248 0000C460 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
   249                              <1> 
   250                              <1> 	;mov	[DirBuff_DRV], bl
   251                              <1> 	;mov	[DirBuff_FATType], bh
   252 0000C463 66891D[A7840100]    <1> 	mov	[DirBuff_DRV], bx
   253                              <1> 
   254                              <1> 	;cmp	bh, 2
   255                              <1> 	;ja	short load_FAT32_root_dir0 ; FAT32 root dir
   256                              <1> 
   257                              <1> load_FAT_root_dir0: ; 23/10/2016
   258 0000C46A 0FB75617            <1> 	movzx	edx, word [esi+LD_BPB+RootDirEnts]
   259                              <1> 
   260                              <1> 	;or	dx, dx ; 0 for FAT32 file systems
   261                              <1> 	;jz	short load_FAT32_root_dir0 ; FAT32 root dir
   262                              <1> 	
   263                              <1> 	; 25/07/2022
   264 0000C46E 89D0                <1> 	mov	eax, edx
   265 0000C470 6681FA0002          <1> 	cmp	dx, 512 ; Number of Root Dir Entries
   266 0000C475 740B                <1> 	je	short lrd_mov_ecx_32
   267                              <1> 	;mov	eax, edx ; 25/07/2022
   268                              <1> 	; 23/10/2016
   269 0000C477 89C1                <1> 	mov	ecx, eax
   270 0000C479 6683C10F            <1> 	add	cx, 15 ; round up 
   271                              <1> 	;shr	cx, 4  ; 16 entries per sector (512/32)
   272                              <1> 	; 25/07/2022
   273 0000C47D C1E904              <1> 	shr	ecx, 4
   274                              <1> 	; ecx = Root directory size in sectors
   275                              <1> 	;;shl	ax, 5 ; Root directory size in bytes
   276                              <1> 	; 25/07/2022
   277                              <1> 	;shl	eax, 5
   278                              <1> 	;;dec	dx    ; Last entry number of root dir
   279                              <1> 	;dec	edx
   280                              <1> 	; cx = Dir Buffer sector count
   281 0000C480 EB04                <1> 	jmp	short lrd_check_dir_buffer
   282                              <1> 
   283                              <1> lrd_mov_ecx_32:
   284                              <1> 	;mov	ecx, 32
   285                              <1> 	; 25/07/2022
   286 0000C482 29C9                <1> 	sub	ecx, ecx
   287 0000C484 B120                <1> 	mov	cl, 32
   288                              <1> 	;dec	dx ; 511
   289                              <1> 	;mov	ax, 32*512 
   290                              <1> 
   291                              <1> lrd_check_dir_buffer:
   292                              <1> 	; 25/07/2022
   293 0000C486 4A                  <1> 	dec	edx ; root dir entries - 1
   294 0000C487 C1E005              <1> 	shl	eax, 5 ; * 32
   295                              <1> 	;
   296 0000C48A 29DB                <1> 	sub	ebx, ebx ; 0
   297 0000C48C 881D[A9840100]      <1> 	mov	[DirBuff_ValidData], bl ; 0
   298 0000C492 668915[AC840100]    <1> 	mov	[DirBuff_LastEntry], dx
   299 0000C499 891D[AE840100]      <1> 	mov	[DirBuff_Cluster], ebx ; 0
   300 0000C49F 66A3[B2840100]      <1> 	mov	[DirBuffer_Size], ax
   301                              <1> 
   302 0000C4A5 8B4664              <1> 	mov	eax, [esi+LD_ROOTBegin]
   303                              <1> read_directory:
   304 0000C4A8 BB00000800          <1> 	mov	ebx, Directory_Buffer
   305 0000C4AD 51                  <1> 	push	ecx ; Directory buffer sector count
   306 0000C4AE 53                  <1> 	push	ebx
   307 0000C4AF E84C5B0000          <1> 	call	disk_read
   308 0000C4B4 5B                  <1> 	pop	ebx
   309 0000C4B5 720B                <1> 	jc	short load_DirBuff_error
   310                              <1> 
   311                              <1> validate_DirBuff_and_return:
   312 0000C4B7 59                  <1> 	pop	ecx ; Number of loaded sectors
   313 0000C4B8 C605[A9840100]01    <1> 	mov	byte [DirBuff_ValidData], 1
   314 0000C4BF 31C0                <1> 	xor	eax, eax ; 0 = no error
   315 0000C4C1 C3                  <1> 	retn
   316                              <1> 
   317                              <1> load_DirBuff_error:
   318 0000C4C2 89C8                <1> 	mov	eax, ecx ; remaining sectors
   319 0000C4C4 59                  <1> 	pop	ecx ; sector count
   320 0000C4C5 29C1                <1> 	sub	ecx, eax ; Number of loaded sectors
   321                              <1> 	; 15/10/2016 (15h -> 17)
   322                              <1> 	;mov	eax, 17 ; DRV NOT READY OR READ ERROR !
   323                              <1> 	; 25/07/2022
   324                              <1> 	;sub	eax, eax
   325 0000C4C7 B011                <1> 	mov	al, 17
   326 0000C4C9 F9                  <1> 	stc
   327 0000C4CA C3                  <1>         retn
   328                              <1> 
   329                              <1> load_FAT32_root_directory:
   330                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   331                              <1> 	; 02/02/2016 (TRDOS 386 = TRDOS v2.0)
   332                              <1> 	;
   333                              <1> 	; INPUT ->
   334                              <1> 	;	ESI = Logical DOS Drive Description Table
   335                              <1> 	; OUTPUT ->
   336                              <1> 	;	cf = 1 -> Root directory could not be loaded
   337                              <1> 	;	    EAX > 0 -> Error number
   338                              <1> 	;	cf = 0 -> EAX = 0
   339                              <1> 	;	ECX = Directory buffer size in sectors (CL)
   340                              <1> 	;	EBX = Directory buffer address
   341                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
   342                              <1> 	;
   343                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
   344                              <1> 
   345 0000C4CB 8A1E                <1> 	mov	bl, [esi+LD_Name]
   346 0000C4CD 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
   347                              <1> 
   348                              <1> 	;mov	[DirBuff_DRV], bl
   349                              <1> 	;mov	[DirBuff_FATType], bh
   350 0000C4D0 66891D[A7840100]    <1> 	mov	[DirBuff_DRV], bx
   351                              <1> 
   352                              <1> load_FAT32_root_dir0:
   353 0000C4D7 8B4632              <1> 	mov	eax, [esi+LD_BPB+FAT32_RootFClust]
   354 0000C4DA EB0C                <1> 	jmp	short load_FAT_sub_dir0
   355                              <1> 	
   356                              <1> load_FAT_sub_directory:
   357                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   358                              <1> 	; 01/02/2016 (TRDOS 386 = TRDOS v2.0)
   359                              <1> 	; 05/07/2011
   360                              <1> 	; 23/08/2009
   361                              <1> 	;
   362                              <1> 	; INPUT ->
   363                              <1> 	;	ESI = Logical DOS Drive Description Table
   364                              <1> 	;	EAX = Cluster Number
   365                              <1> 	; OUTPUT ->
   366                              <1> 	;	cf = 1 -> Sub directory could not be loaded
   367                              <1> 	;	    EAX > 0 -> Error number
   368                              <1> 	;	cf = 0 -> EAX = 0
   369                              <1> 	;	ECX = Directory buffer size in sectors (CL)
   370                              <1> 	;	EBX = Directory buffer address
   371                              <1> 	;
   372                              <1> 	; 	NOTE: DirBuffer_Size is in bytes ! (word)
   373                              <1> 	;
   374                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
   375                              <1> 
   376 0000C4DC 8A1E                <1> 	mov	bl, [esi+LD_Name]
   377 0000C4DE 8A7E03              <1> 	mov	bh, [esi+LD_FATType]
   378                              <1> 
   379                              <1> 	;mov	[DirBuff_DRV], bl
   380                              <1> 	;mov	[DirBuff_FATType], bh
   381 0000C4E1 66891D[A7840100]    <1> 	mov	[DirBuff_DRV], bx
   382                              <1> 
   383                              <1> load_FAT_sub_dir0:
   384 0000C4E8 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
   385                              <1> 
   386 0000C4EC 882D[A9840100]      <1> 	mov	[DirBuff_ValidData], ch ; 0
   387 0000C4F2 A3[AE840100]        <1> 	mov	[DirBuff_Cluster], eax
   388                              <1> 
   389 0000C4F7 0FB74611            <1> 	movzx	eax, word [esi+LD_BPB+BytesPerSec]
   390 0000C4FB F7E1                <1> 	mul	ecx
   391 0000C4FD C1E805              <1> 	shr	eax, 5 ; directory entry count (dir size / 32)
   392                              <1> 	;dec	ax ; last entry
   393                              <1> 	; 25/07/2022
   394 0000C500 48                  <1> 	dec	eax
   395 0000C501 66A3[AC840100]      <1> 	mov	[DirBuff_LastEntry], ax
   396                              <1> 
   397 0000C507 A1[AE840100]        <1> 	mov	eax, [DirBuff_Cluster]
   398 0000C50C 83E802              <1> 	sub	eax, 2
   399 0000C50F F7E1                <1> 	mul	ecx
   400 0000C511 034668              <1> 	add	eax, [esi+LD_DATABegin]
   401                              <1> 	; ecx = sectors per cluster (dir buffer size <= 128 sectors)
   402 0000C514 EB92                <1> 	jmp	short read_directory
   403                              <1> 
   404                              <1> ; DRV_FS.ASM
   405                              <1> 
   406                              <1> ; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   407                              <1> 
   408                              <1> load_current_FS_directory:
   409                              <1> 	;retn
   410                              <1> load_FS_root_directory:
   411                              <1> 	;retn
   412                              <1> load_FS_sub_directory:
   413 0000C516 C3                  <1> 	retn
   414                              <1> 
   415                              <1> read_cluster:
   416                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   417                              <1> 	; 15/10/2016
   418                              <1> 	; 18/03/2016
   419                              <1> 	; 16/03/2016
   420                              <1> 	; 17/02/2016
   421                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
   422                              <1> 	;
   423                              <1> 	; INPUT ->
   424                              <1> 	;	EAX = Cluster Number (Sector index for SINGLIX FS)
   425                              <1> 	;	ESI = Logical DOS Drive Description Table address
   426                              <1> 	;	EBX = Cluster (File R/W) Buffer address (max. 64KB)
   427                              <1> 	;	Only for SINGLIX FS:
   428                              <1> 	;	EDX = File Number (The 1st FDT address)
   429                              <1> 	; OUTPUT ->
   430                              <1> 	;	cf = 1 -> Cluster can not be loaded at the buffer
   431                              <1> 	;	    EAX > 0 -> Error number
   432                              <1> 	;	cf = 0 -> Cluster has been loaded at the buffer
   433                              <1> 	;
   434                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
   435                              <1> 	
   436 0000C517 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust]
   437                              <1> 	; CL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
   438                              <1> 
   439                              <1> read_file_sectors: ; 16/03/2016
   440                              <1> 	;cmp	byte [esi+LD_FATType], 0
   441                              <1> 	; 25/07/2022
   442 0000C51B 386E03              <1> 	cmp	[esi+LD_FATType], ch ; 0
   443 0000C51E 761C                <1> 	jna	short read_fs_cluster
   444                              <1> 
   445                              <1> read_fat_file_sectors: ; 18/03/2016
   446 0000C520 83E802              <1> 	sub	eax, 2 ; Beginning cluster number is always 2
   447 0000C523 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+BPB_SecPerClust] ; 18/03/2016 
   448 0000C527 F7E2                <1> 	mul	edx
   449 0000C529 034668              <1> 	add	eax, [esi+LD_DATABegin] ; absolute address of the cluster
   450                              <1> 
   451                              <1> 	; EAX = Disk sector address
   452                              <1> 	; ECX = Sector count
   453                              <1> 	; EBX = Buffer address
   454                              <1> 	; (EDX = 0)
   455                              <1> 	; ESI = Logical DOS drive description table address
   456                              <1> 
   457 0000C52C E8CF5A0000          <1> 	call	disk_read
   458 0000C531 7306                <1> 	jnc	short rclust_retn
   459                              <1> 	
   460                              <1> 	; 15/10/2016 (15h -> 17)
   461 0000C533 B811000000          <1> 	mov	eax, 17 ; Drive not ready or read error !
   462 0000C538 C3                  <1> 	retn
   463                              <1> 
   464                              <1> rclust_retn:
   465 0000C539 29C0                <1> 	sub	eax, eax ; 0
   466 0000C53B C3                  <1> 	retn
   467                              <1> 
   468                              <1> read_fs_cluster:
   469                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   470                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
   471                              <1> 	; Singlix FS
   472                              <1> 
   473                              <1> 	; EAX = Cluster number is sector index number of the file (eax)
   474                              <1> 	
   475                              <1> 	; EDX = File number is the first File Descriptor Table address
   476                              <1> 	;	of the file. (Absolute address of the FDT).
   477                              <1> 
   478                              <1> 	; eax = sector index (0 for the first sector)
   479                              <1> 	; edx = FDT0 address
   480                              <1> 		; 64 KB buffer = 128 sectors (limit) 
   481                              <1> 	;mov	ecx, 128 ; maximum count of sectors (before eof)
   482                              <1> 	; 25/07/2022
   483 0000C53C 29C9                <1> 	sub	ecx, ecx
   484 0000C53E B180                <1> 	mov	cl, 128
   485                              <1> 	;call	read_fs_sectors
   486                              <1> 	;retn
   487                              <1> 	;jmp	short read_fs_sectors
   488                              <1> 
   489                              <1> read_fs_sectors:
   490                              <1> 	; 15/02/2016 (TRDOS 386 = TRDOS v2.0)
   491 0000C540 F9                  <1> 	stc
   492 0000C541 C3                  <1> 	retn
   493                              <1> 
   494                              <1> get_first_free_cluster:
   495                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   496                              <1> 	; 02/03/2016
   497                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
   498                              <1> 	; 26/10/2010 (DRV_FAT.ASM, 'proc_get_first_free_cluster')
   499                              <1> 	; 10/07/2010
   500                              <1> 	; INPUT ->
   501                              <1> 	;	ESI = Logical DOS Drive Description Table address
   502                              <1> 	; OUTPUT ->
   503                              <1> 	;	cf = 1 -> Error code in AL (EAX)
   504                              <1> 	;	cf = 0 -> 
   505                              <1> 	;	  EAX = Cluster number
   506                              <1> 	;	  If EAX = FFFFFFFFh -> no free space
   507                              <1> 	;	If the drive has FAT32 fs:
   508                              <1> 	;	  EBX = FAT32 FSI sector buffer address (if > 0)
   509                              <1> 	;
   510                              <1> 	; (Modified registers: eax, ebx, ecx, edx)
   511                              <1> 	;
   512                              <1> 
   513 0000C542 8B4678              <1> 	mov	eax, [esi+LD_Clusters]
   514 0000C545 40                  <1> 	inc	eax ; add eax, 1
   515 0000C546 A3[30870100]        <1> 	mov	[gffc_last_free_cluster], eax
   516                              <1> 
   517 0000C54B 31DB                <1> 	xor	ebx, ebx ; 0 ; 02/03/2016
   518                              <1> 
   519 0000C54D 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
   520 0000C551 760E                <1> 	jna	short loc_gffc_get_first_fat_free_cluster0
   521                              <1> 
   522                              <1> loc_gffc_get_first_fat32_free_cluster:
   523                              <1> 	; 02/03/2016
   524 0000C553 E802060000          <1> 	call	get_fat32_fsinfo_sector_parms
   525 0000C558 7207                <1> 	jc	short loc_gffc_get_first_fat_free_cluster0
   526                              <1> 
   527                              <1> loc_gffc_check_fsinfo_parms:
   528                              <1> 	;;mov	ebx, DOSBootSectorBuff
   529                              <1> 	;cmp	dword [ebx], 41615252h
   530                              <1> 	;jne	short loc_gffc_fat32_fsinfo_err
   531                              <1> 	;cmp	dword [ebx+484], 61417272h
   532                              <1> 	;jne	short loc_gffc_fat32_fsinfo_err
   533                              <1> 	;mov	eax, [ebx+492] ; FSI_Next_Free
   534                              <1> 	;EAX = First free cluster
   535                              <1> 	;(from FAT32 FSInfo sector)
   536 0000C55A 89D0                <1> 	mov	eax, edx ; FSI_Next_Free (First Free Cluster)
   537 0000C55C 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh ; invalid (unknown) !
   538 0000C55F 7204                <1> 	jb	short loc_gffc_get_first_fat_free_cluster1
   539                              <1> 
   540                              <1> 	; Start from the 1st cluster of the FAT(32) file system
   541                              <1> loc_gffc_get_first_fat_free_cluster0:
   542                              <1> 	;mov	eax, 2
   543                              <1> 	; 25/07/2022
   544 0000C561 29C0                <1> 	sub	eax, eax
   545 0000C563 B002                <1> 	mov	al, 2
   546                              <1> 	;xor	edx, edx
   547                              <1> 
   548                              <1> loc_gffc_get_first_fat_free_cluster1:
   549 0000C565 53                  <1> 	push	ebx ; 02/03/2016
   550                              <1> 
   551                              <1> loc_gffc_get_first_fat_free_cluster2:
   552 0000C566 A3[2C870100]        <1> 	mov	[gffc_first_free_cluster], eax
   553 0000C56B A3[28870100]        <1> 	mov	[gffc_next_free_cluster], eax
   554                              <1> 
   555                              <1> 	; EBX = FAT32 FSINFO sector buffer address
   556                              <1> 	; (EBX = 0, if the drive has not got FAT32 fs or
   557                              <1> 	; FAT32 FSINFO sector buffer is invalid.)
   558                              <1> 
   559                              <1> loc_gffc_get_first_fat_free_cluster3:
   560 0000C570 E8ABFDFFFF          <1> 	call	get_next_cluster
   561 0000C575 7307                <1> 	jnc	short loc_gffc_get_first_fat_free_cluster4
   562 0000C577 09C0                <1> 	or	eax, eax
   563 0000C579 740B                <1> 	jz	short loc_gffc_first_free_fat_cluster_next
   564 0000C57B 5B                  <1> 	pop	ebx ; 02/03/2016
   565 0000C57C F5                  <1> 	cmc 	; stc
   566 0000C57D C3                  <1> 	retn
   567                              <1> 
   568                              <1> loc_gffc_get_first_fat_free_cluster4:
   569 0000C57E 21C0                <1> 	and	eax, eax ; next cluster value
   570 0000C580 7504                <1> 	jnz	short loc_gffc_first_free_fat_cluster_next
   571 0000C582 89C8                <1> 	mov	eax, ecx ; current (previous cluster) value
   572 0000C584 EB22                <1> 	jmp	short loc_gffc_check_for_set
   573                              <1> 
   574                              <1> loc_gffc_first_free_fat_cluster_next:
   575 0000C586 A1[28870100]        <1> 	mov	eax, [gffc_next_free_cluster]
   576 0000C58B 3B05[30870100]      <1> 	cmp	eax, [gffc_last_free_cluster]
   577 0000C591 7308                <1> 	jnb	short retn_stc_from_get_first_free_cluster
   578                              <1> pass_gffc_last_cluster_eax_check:
   579 0000C593 40                  <1> 	inc	eax ; add eax, 1
   580 0000C594 A3[28870100]        <1> 	mov	[gffc_next_free_cluster], eax
   581 0000C599 EBD5                <1> 	jmp	short loc_gffc_get_first_fat_free_cluster3
   582                              <1> 
   583                              <1> retn_stc_from_get_first_free_cluster:
   584 0000C59B A1[2C870100]        <1> 	mov	eax, [gffc_first_free_cluster]
   585 0000C5A0 83F802              <1> 	cmp	eax, 2
   586 0000C5A3 7709                <1> 	ja	short loc_gffc_check_previous_clusters
   587 0000C5A5 29C0                <1> 	sub	eax, eax
   588 0000C5A7 48                  <1> 	dec	eax ; FFFFFFFFh
   589                              <1> 
   590                              <1> loc_gffc_check_for_set:
   591                              <1> 	; 02/03/2016
   592 0000C5A8 5B                  <1> 	pop	ebx
   593                              <1> 
   594                              <1> 	; EBX = FAT32 FSINFO sector buffer address
   595                              <1> 	; (EBX = 0, if the drive has not got FAT32 fs or
   596                              <1> 	; FAT32 FSINFO sector buffer is invalid.)
   597                              <1> 
   598 0000C5A9 09DB                <1> 	or	ebx, ebx
   599 0000C5AB 750D                <1> 	jnz	short loc_gffc_set_ffree_fat32_cluster
   600                              <1> 
   601                              <1> 	;cmp	byte [esi+LD_FATType], 3
   602                              <1> 	;jnb	short loc_gffc_set_ffree_fat32_cluster
   603                              <1> 
   604                              <1> 	;xor	ebx, ebx ; 0
   605                              <1> 
   606                              <1> loc_gffc_retn:
   607 0000C5AD C3                  <1> 	retn
   608                              <1> 
   609                              <1> loc_gffc_check_previous_clusters:
   610 0000C5AE 48                  <1> 	dec	eax ; sub eax, 1
   611 0000C5AF A3[30870100]        <1> 	mov	[gffc_last_free_cluster], eax
   612                              <1> 	;mov	eax, 2
   613                              <1> 	; 25/07/2022
   614 0000C5B4 31C0                <1> 	xor	eax, eax
   615 0000C5B6 B002                <1> 	mov	al, 2
   616                              <1> 	; eax = 2
   617                              <1> 	;xor	edx, edx
   618 0000C5B8 EBAC                <1> 	jmp	short loc_gffc_get_first_fat_free_cluster2
   619                              <1> 
   620                              <1> loc_gffc_set_ffree_fat32_cluster:
   621                              <1> 	;call	set_first_free_cluster
   622                              <1> 	;retn
   623                              <1> 	;jmp	short set_first_free_cluster
   624                              <1> 
   625                              <1> set_first_free_cluster:
   626                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   627                              <1> 	; 15/10/2016
   628                              <1> 	; 23/03/2016
   629                              <1> 	; 02/03/2016
   630                              <1> 	; 29/02/2016
   631                              <1> 	; 26/02/2016
   632                              <1> 	; 21/02/2016 (TRDOS 386 = TRDOS v2.0)
   633                              <1> 	; 21/08/2011 (DRV_FAT.ASM, 'proc_set_first_free_cluster')
   634                              <1> 	; 11/07/2010
   635                              <1> 	; INPUT ->
   636                              <1> 	;	ESI = Logical DOS Drive Description Table address
   637                              <1> 	;	EAX = First free cluster
   638                              <1> 	;	EBX = FSINFO sector buffer address
   639                              <1> 	;  	;;If EBX > 0, it is FSINFO sector buffer address
   640                              <1> 	;	;;EBX = 0, if FSINFO sector is not loaded
   641                              <1> 	; OUTPUT->
   642                              <1> 	;	ESI = Logical DOS Drive Description Table address
   643                              <1> 	;  	If EBX > 0, it is FSINFO sector buffer address
   644                              <1> 	;	EBX = 0, if FSINFO sector could not be loaded
   645                              <1> 	; 	CF = 1 -> Error code in AL (EAX)
   646                              <1> 	;	CF = 0 -> first free cluster is successfully updated
   647                              <1> 
   648                              <1> 	;cmp	byte [esi+LD_FATType], 3
   649                              <1> 	;jb	short loc_sffc_invalid_drive
   650                              <1> 
   651                              <1> 	; Save First Free Cluster value for 'update_cluster'
   652 0000C5BA 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; First free Cluster
   653                              <1> 
   654                              <1> 	;or	ebx, ebx
   655                              <1> 	;jnz	short loc_sffc_read_fsinfo_sector
   656                              <1> 
   657 0000C5BD 813B52526141        <1> 	cmp     dword [ebx], 41615252h
   658 0000C5C3 753C                <1> 	jne	short loc_sffc_read_fsinfo_sector
   659 0000C5C5 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
   659 0000C5CE 61                  <1>
   660 0000C5CF 7530                <1> 	jne	short loc_sffc_read_fsinfo_sector
   661                              <1> 
   662 0000C5D1 3B83EC010000        <1> 	cmp	eax, [ebx+492]  ; FSI_Next_Free
   663 0000C5D7 741E                <1> 	je	short loc_sffc_retn
   664                              <1> 
   665                              <1> loc_sffc_write_fsinfo_sector:
   666                              <1> 	; EBX = FSINFO sector buffer
   667                              <1> 	; [CFS_FAT32FSINFOSEC] is set in 'get_fat32_fsinfo_sector_parms'
   668 0000C5D9 8983EC010000        <1> 	mov	[ebx+492], eax
   669 0000C5DF A1[40870100]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC]
   670                              <1> 	;mov	ecx, 1
   671                              <1> 	; 25/07/2022
   672 0000C5E4 31C9                <1> 	xor	ecx, ecx
   673 0000C5E6 FEC1                <1> 	inc	cl
   674                              <1> 	; ecx = 1
   675 0000C5E8 53                  <1> 	push	ebx
   676 0000C5E9 E8035A0000          <1> 	call	disk_write
   677 0000C5EE 7208                <1> 	jc      short loc_sffc_read_fsinfo_sector_err1
   678 0000C5F0 5B                  <1> 	pop	ebx
   679                              <1> 
   680 0000C5F1 8B83EC010000        <1> 	mov	eax, [ebx+492] ; First (Next) Free Cluster
   681                              <1> 
   682                              <1> loc_sffc_retn:
   683 0000C5F7 C3                  <1> 	retn
   684                              <1> 
   685                              <1> ;loc_sffc_invalid_drive:
   686                              <1> ;	mov	eax, 0Fh ; MSDOS Error : Invalid drive
   687                              <1> ;	push	edx
   688                              <1> 
   689                              <1> loc_sffc_read_fsinfo_sector_err1:
   690                              <1> 	; 25/07/2022
   691                              <1> 	;mov	ebx, 0
   692                              <1> 	; 15/10/2016 (1Dh -> 18)
   693                              <1> 	; 23/03/2016 (1Dh)
   694                              <1> 	;mov	eax, 18 ; Drive not ready or write error
   695 0000C5F8 31C0                <1> 	xor	eax, eax
   696 0000C5FA 89C3                <1> 	mov	ebx, eax ; 0
   697 0000C5FC B012                <1> 	mov	al, 18
   698 0000C5FE F9                  <1> 	stc
   699                              <1> loc_sffc_read_fsinfo_sector_err2:
   700 0000C5FF 5A                  <1> 	pop	edx
   701 0000C600 C3                  <1> 	retn
   702                              <1> 	
   703                              <1> loc_sffc_read_fsinfo_sector:
   704 0000C601 50                  <1> 	push	eax
   705                              <1> 
   706 0000C602 E853050000          <1> 	call	get_fat32_fsinfo_sector_parms
   707 0000C607 72F6                <1> 	jc	short loc_sffc_read_fsinfo_sector_err2
   708                              <1> 
   709 0000C609 58                  <1> 	pop	eax
   710                              <1> 	; EDX = First (Next) Free Cluster value from FSINFO sector
   711                              <1> 	; EAX = First Free Cluster value from 'get_next_cluster'
   712                              <1> 	; (edx = old value)
   713 0000C60A 39D0                <1> 	cmp	eax, edx ; First free Cluster (eax = new value)
   714 0000C60C 75CB                <1> 	jne	short loc_sffc_write_fsinfo_sector
   715                              <1> 
   716 0000C60E C3                  <1> 	retn
   717                              <1> 
   718                              <1> update_cluster:
   719                              <1> 	; 31/08/2024
   720                              <1> 	; 29/08/2024
   721                              <1> 	; 26/08/2024
   722                              <1> 	; 24/08/2024 (TRDOS 386 Kernel v2.0.9)
   723                              <1> 	; 07/08/2022
   724                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
   725                              <1> 	; 23/10/2016
   726                              <1> 	; 23/03/2016
   727                              <1> 	; 02/03/2016
   728                              <1> 	; 01/03/2016
   729                              <1> 	; 29/02/2016
   730                              <1> 	; 27/02/2016
   731                              <1> 	; 26/02/2016
   732                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
   733                              <1> 	; 11/08/2011
   734                              <1> 	; 09/02/2005
   735                              <1> 	; INPUT ->
   736                              <1> 	;	EAX = Cluster Number
   737                              <1> 	;	ECX = New Cluster Value
   738                              <1> 	;	ESI = Logical Dos Drive Parameters Table
   739                              <1> 	;
   740                              <1> 	;	/// dword [FAT_ClusterCounter] ///
   741                              <1> 	;
   742                              <1> 	; OUTPUT ->
   743                              <1> 	;	cf = 0 -> No Error, EAX is valid
   744                              <1> 	;	cf = 1 & EAX = 0 -> End Of Cluster Chain
   745                              <1> 	; 	cf = 1 & EAX > 0 -> Error
   746                              <1> 	;		(ECX -> any value)
   747                              <1> 	; 	EAX = Next Cluster
   748                              <1> 	;	ECX = New Cluster Value
   749                              <1> 	;
   750                              <1> 	;	/// [FAT_ClusterCounter] is updated,
   751                              <1> 	;	/// decreased when a free cluster is assigned,
   752                              <1> 	;	/// increased if an assigned cluster is freed.
   753                              <1> 	;
   754                              <1> 	;
   755                              <1> 	; (Modified registers: EAX, EBX, -ECX-, EDX)
   756                              <1> 	
   757 0000C60F A3[92840100]        <1> 	mov	[FAT_CurrentCluster], eax
   758 0000C614 890D[34870100]      <1> 	mov	[ClusterValue], ecx
   759                              <1> 
   760                              <1> loc_update_cluster_check_fat_buffer:
   761 0000C61A 8A1E                <1> 	mov	bl, [esi+LD_Name]
   762 0000C61C 381D[97840100]      <1> 	cmp	[FAT_BuffDrvName], bl
   763 0000C622 7418                <1> 	je	short loc_update_cluster_check_fat_type
   764 0000C624 803D[96840100]02    <1> 	cmp	byte [FAT_BuffValidData], 2
   765                              <1> 	;je	loc_uc_save_fat_buffer
   766                              <1> 	; 25/07/2022
   767 0000C62B 7502                <1> 	jne	short loc_uc_reset_fat_buffer_validation
   768 0000C62D EB66                <1> 	jmp	loc_uc_save_fat_buffer
   769                              <1> 
   770                              <1> loc_uc_reset_fat_buffer_validation:
   771 0000C62F C605[96840100]00    <1> 	mov	byte [FAT_BuffValidData], 0
   772                              <1> 
   773                              <1> loc_uc_check_fat_type_reset_drvname:
   774 0000C636 881D[97840100]      <1> 	mov	[FAT_BuffDrvName], bl
   775                              <1> 
   776                              <1> loc_update_cluster_check_fat_type:
   777 0000C63C 29D2                <1> 	sub	edx, edx ; 26/02/2016
   778 0000C63E 8A5E03              <1> 	mov	bl, [esi+LD_FATType]
   779 0000C641 83F802              <1> 	cmp	eax, 2
   780 0000C644 7218                <1>         jb	short update_cluster_inv_data
   781                              <1> 
   782                              <1> 	;;;
   783                              <1> 	; 24/08/2024
   784                              <1> 	; edx = 0 ; 24/08/2024
   785 0000C646 8B4E78              <1> 	mov	ecx, [esi+LD_Clusters]
   786 0000C649 41                  <1> 	inc	ecx
   787 0000C64A 890D[A2840100]      <1> 	mov	[LastCluster], ecx
   788                              <1> 	;
   789 0000C650 39C8                <1> 	cmp	eax, ecx
   790                              <1> 	;ja	short return_uc_fat32_stc ; 25/07/2022
   791                              <1> 	; edx = 0 ; (must be -1 or > 0 after here)
   792 0000C652 7717                <1> 	ja	short return_uc_fat_stc
   793                              <1> 	;;;
   794                              <1> 
   795 0000C654 80FB02              <1> 	cmp	bl, 2
   796                              <1>         ;ja	update_fat32_cluster
   797                              <1> 	; 25/07/2022
   798 0000C657 7608                <1> 	jna	short loc_uc_check_fat_type_1
   799 0000C659 E97B010000          <1> 	jmp	update_fat32_cluster
   800                              <1> 
   801                              <1> ; 24/08/2024
   802                              <1> ;loc_uc_check_fat_type_1:
   803                              <1> ;	;cmp	bl, 1
   804                              <1> ;	;jb	short update_cluster_inv_data
   805                              <1> ;	mov	ecx, [esi+LD_Clusters]
   806                              <1> ;	inc	ecx  
   807                              <1> ;	mov	[LastCluster], ecx
   808                              <1> ;	cmp	eax, ecx ; dword [LastCluster]
   809                              <1> ;	;ja	return_uc_fat_stc
   810                              <1> ;	; 25/07/2022
   811                              <1> ;	jna	short loc_uc_check_fat_type_2
   812                              <1> ;	; 24/08/2024
   813                              <1> ;	; edx = 0 ; (must be -1 or > 0 after here)
   814                              <1> ;	jmp	return_uc_fat_stc
   815                              <1> 
   816                              <1> 	; 25/07/2022
   817                              <1> update_cluster_inv_data:
   818                              <1> 	;;mov	eax, 0Dh
   819                              <1> 	;mov	al, 0Dh  ; Invalid Data
   820                              <1> 	; 31/08/2024
   821 0000C65E B01D                <1> 	mov	al, ERR_INV_DATA ; 29 ; Invalid Data
   822 0000C660 C3                  <1> 	retn
   823                              <1> 
   824                              <1> 	; 24/08/2024
   825                              <1> loc_uc_check_fat_type_1:
   826                              <1> loc_uc_check_fat_type_2:
   827                              <1> 	; TRDOS v1 has a FATal bug here !
   828                              <1> 		; or bl, bl ; cmp bl, 0
   829                              <1> 		; jz short update_fat12_cluster
   830                              <1> 	; !! It would destroy FAT12 floppy disk fs here !!
   831                              <1> 	; ('A:' disks of TRDOS v1 operating system project
   832                              <1> 	; had 'singlix fs', so, I could not differ this mistake
   833                              <1> 	; on a drive 'A:')
   834 0000C661 80FB01              <1> 	cmp	bl, 1 ; correct comparison is this !
   835                              <1> 	;jna	update_fat12_cluster
   836                              <1> 	; 25/07/2022
   837 0000C664 770B                <1> 	ja	short update_fat16_cluster
   838 0000C666 E9CF000000          <1> 	jmp	update_fat12_cluster
   839                              <1> 
   840                              <1> 	; 24/08/2024
   841                              <1> ;return_uc_fat16_stc:
   842                              <1> 	; 25/07/2022
   843                              <1> return_uc_fat_stc:
   844                              <1> 	; 24/08/2024
   845                              <1> 	; edx = 0
   846 0000C66B 4A                  <1> 	dec	edx
   847                              <1> 	; edx = -1 ; 0FFFFFFFFh
   848                              <1> 	; ecx > 0
   849                              <1> return_uc_fat16_stc:	; 24/08/2024
   850                              <1> loc_fat_buffer_stc_0:	; 24/08/2024
   851                              <1> 	; 01/03/2016
   852 0000C66C 31C0                <1> 	xor	eax, eax
   853 0000C66E F9                  <1> 	stc
   854 0000C66F EB70                <1> 	jmp	short loc_fat_buffer_stc_1
   855                              <1> 
   856                              <1> update_fat16_cluster:
   857                              <1> pass_uc_fat16_errc:
   858                              <1> 	;sub	edx, edx
   859                              <1> 	; edx = 0
   860 0000C671 BB00030000          <1> 	mov	ebx, 300h ; 768
   861 0000C676 F7F3                <1> 	div	ebx
   862                              <1> 	; EAX = Count of 3 FAT sectors
   863                              <1> 	; DX = Cluster index in FAT buffer
   864                              <1> 	;mov	bx, dx  
   865                              <1> 	; 25/07/2022
   866 0000C678 89D3                <1> 	mov	ebx, edx
   867                              <1> 	;shl	bx, 1 ; Multiply by 2
   868                              <1> 	; 25/07/2022
   869 0000C67A D1E3                <1> 	shl	ebx, 1
   870 0000C67C 66BA0300            <1> 	mov	dx, 3
   871 0000C680 F7E2                <1> 	mul	edx
   872                              <1> 	; EAX = FAT Sector
   873                              <1> 	; EDX = 0
   874                              <1> 	; EBX = Byte offset in FAT buffer
   875 0000C682 8A0D[96840100]      <1> 	mov	cl, [FAT_BuffValidData]
   876 0000C688 80F902              <1> 	cmp	cl, 2
   877 0000C68B 7518                <1> 	jne	short loc_uc_check_fat16_buff_sector_load
   878                              <1> 
   879                              <1> loc_uc_check_fat16_buff_sector_save:
   880 0000C68D 3B05[9A840100]      <1> 	cmp	eax, [FAT_BuffSector]
   881                              <1> 	;jne	short loc_uc_save_fat_buffer
   882                              <1> 	;jmp	short loc_update_fat16_cell
   883                              <1> 	; 07/08/2022
   884 0000C693 741D                <1> 	je	short loc_update_fat16_cell
   885                              <1> 	;jmp	loc_uc_save_fat_buffer
   886                              <1> 
   887                              <1> 	; 07/08/2022
   888                              <1> loc_uc_save_fat_buffer:
   889                              <1> 	; byte [FAT_BuffValidData] = 2
   890 0000C695 E8E9010000          <1> 	call	save_fat_buffer
   891 0000C69A 7267                <1>         jc	short loc_fat_sectors_rw_error2
   892                              <1> 	;mov	byte [FAT_BuffValidData], 1
   893 0000C69C A1[92840100]        <1> 	mov	eax, [FAT_CurrentCluster]
   894                              <1> 	;mov	ecx, [ClusterValue]
   895                              <1> 	;jmp	short loc_update_cluster_check_fat_buffer
   896 0000C6A1 8A1E                <1> 	mov	bl, [esi+LD_Name] ; 01/03/2016
   897 0000C6A3 EB8A                <1>         jmp	loc_uc_reset_fat_buffer_validation
   898                              <1> 
   899                              <1> loc_uc_check_fat16_buff_sector_load:
   900 0000C6A5 80F901              <1> 	cmp	cl, 1 ; byte [FAT_BuffValidData]
   901 0000C6A8 7560                <1>         jne	short loc_uc_load_fat_sectors
   902 0000C6AA 3B05[9A840100]      <1> 	cmp	eax, [FAT_BuffSector]
   903 0000C6B0 7558                <1>         jne	short loc_uc_load_fat_sectors
   904                              <1> 
   905                              <1> loc_update_fat16_cell:
   906                              <1> loc_update_fat16_buffer:
   907 0000C6B2 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
   908                              <1> 	;movzx	eax, word [ebx]
   909 0000C6B8 668B03              <1> 	mov	ax, [ebx]
   910                              <1> 	; 01/03/2016
   911 0000C6BB 89C2                <1> 	mov	edx, eax ; old value of the cluster
   912 0000C6BD A3[92840100]        <1> 	mov	[FAT_CurrentCluster], eax
   913 0000C6C2 8B0D[34870100]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
   914 0000C6C8 66890B              <1> 	mov	[ebx], cx ; 16 bits !
   915                              <1> 
   916 0000C6CB C605[96840100]02    <1> 	mov	byte [FAT_BuffValidData], 2
   917                              <1> 	
   918 0000C6D2 6683F802            <1> 	cmp	ax, 2
   919 0000C6D6 7294                <1> 	jb	short return_uc_fat16_stc
   920 0000C6D8 3B05[A2840100]      <1> 	cmp	eax, [LastCluster]
   921 0000C6DE 778C                <1> 	ja	short return_uc_fat16_stc
   922                              <1> 
   923                              <1> loc_fat_buffer_updated:
   924                              <1> 	; 01/03/2016
   925 0000C6E0 F8                  <1> 	clc
   926                              <1> loc_fat_buffer_stc_1:
   927 0000C6E1 9C                  <1> 	pushf
   928 0000C6E2 21C9                <1> 	and	ecx, ecx
   929 0000C6E4 7506                <1> 	jnz	short loc_fat_buffer_updated_1
   930                              <1> 
   931                              <1> 	; 01/03/2016 
   932                              <1> 	; new value of the cluster = 0 (free)
   933                              <1> 	; increase free(d) cluster count
   934 0000C6E6 FF05[9E840100]      <1> 	inc	dword [FAT_ClusterCounter]
   935                              <1> 
   936                              <1> loc_fat_buffer_updated_1: ; new value of the cluster > 0
   937 0000C6EC 09D2                <1> 	or	edx, edx ; 02/03/2016
   938 0000C6EE 7506                <1> 	jnz	short loc_fat_buffer_updated_2
   939                              <1> 	; old value of the cluster = 0 (it was free cluster)
   940                              <1> 	; decrease free(d) cluster count
   941 0000C6F0 FF0D[9E840100]      <1> 	dec	dword [FAT_ClusterCounter] ; it may be negative number
   942                              <1> 
   943                              <1> loc_fat_buffer_updated_2:
   944 0000C6F6 9D                  <1> 	popf
   945 0000C6F7 C3                  <1> 	retn
   946                              <1> 
   947                              <1> 	; 25/07/2022
   948                              <1> loc_fat_sectors_rw_error1:
   949                              <1> 	;mov	byte [FAT_BuffValidData], 0
   950                              <1> 	; 23/10/2016 (15h -> 17)
   951                              <1> 	; 23/03/2016
   952 0000C6F8 B811000000          <1> 	mov	eax, 17 ; Drive not ready or read error
   953 0000C6FD 8825[96840100]      <1> 	mov	[FAT_BuffValidData], ah ; 0
   954                              <1> 
   955                              <1> loc_fat_sectors_rw_error2:
   956                              <1> 	;mov	eax, error code
   957                              <1> 	;mov	edx, 0
   958 0000C703 8B0D[34870100]      <1> 	mov	ecx, [ClusterValue]
   959 0000C709 C3                  <1> 	retn
   960                              <1> 
   961                              <1> 	; 25/07/2022
   962                              <1> loc_uc_load_fat_sectors:
   963 0000C70A A3[9A840100]        <1> 	mov	[FAT_BuffSector], eax
   964                              <1> 
   965                              <1> load_uc_fat_sectors_zero:
   966 0000C70F 034660              <1> 	add	eax, [esi+LD_FATBegin]
   967 0000C712 BB001C0900          <1> 	mov	ebx, FAT_Buffer
   968 0000C717 B903000000          <1> 	mov	ecx, 3
   969 0000C71C E8DF580000          <1> 	call	disk_read
   970 0000C721 72D5                <1> 	jc	short loc_fat_sectors_rw_error1
   971                              <1> 
   972 0000C723 C605[96840100]01    <1>         mov     byte [FAT_BuffValidData], 1
   973 0000C72A A1[92840100]        <1> 	mov 	eax, [FAT_CurrentCluster]
   974 0000C72F 8B0D[34870100]      <1> 	mov	ecx, [ClusterValue]
   975 0000C735 E902FFFFFF          <1>         jmp     loc_update_cluster_check_fat_type
   976                              <1> 
   977                              <1> update_fat12_cluster:
   978                              <1> pass_uc_fat12_errc:
   979                              <1> 	;sub	edx, edx
   980 0000C73A BB00040000          <1> 	mov	ebx, 400h ; 1024
   981 0000C73F F7F3                <1> 	div	ebx
   982                              <1> 	; EAX = Count of 3 FAT sectors
   983                              <1> 	; DX = Cluster index in FAT buffer
   984                              <1> 	;mov	cx, 3
   985                              <1> 	; 25/07/2022
   986 0000C741 29C9                <1> 	sub	ecx, ecx
   987 0000C743 B103                <1> 	mov	cl, 3
   988                              <1> 	; ecx = 3
   989                              <1> 	;mov	bx, ax
   990 0000C745 89C3                <1> 	mov	ebx, eax
   991                              <1> 	;mov	ax, cx ; 3
   992 0000C747 89C8                <1> 	mov	eax, ecx
   993                              <1> 	;mul	dx     ; Multiply by 3
   994 0000C749 F7E2                <1> 	mul	edx
   995                              <1> 	;shr	ax, 1  ; Divide by 2
   996 0000C74B D1E8                <1> 	shr	eax, 1
   997                              <1> 	;xchg	bx, ax
   998 0000C74D 93                  <1> 	xchg	ebx, eax
   999                              <1> 	; EAX = Count of 3 FAT sectors
  1000                              <1> 	; EBX = Byte Offset in FAT buffer
  1001                              <1> 	;mul	cx  ; 3 * AX
  1002 0000C74E F7E1                <1> 	mul	ecx ; 3 * EAX
  1003                              <1> 	; EAX = FAT Beginning Sector
  1004                              <1> 	; EDX = 0
  1005 0000C750 8A0D[96840100]      <1> 	mov	cl, [FAT_BuffValidData]
  1006                              <1> 	; TRDOS v1 has a FATal bug here ! 
  1007                              <1> 	; (it does not have 'cmp cl, 2' instruction here !
  1008                              <1> 	;  while 'jne' is existing !)
  1009 0000C756 80F902              <1> 	cmp	cl, 2 ; 2 = dirty buffer (must be written to disk)
  1010 0000C759 750D                <1> 	jne	short loc_uc_check_fat12_buff_sector_load
  1011                              <1> 
  1012                              <1> loc_uc_check_fat12_buff_sector_save:
  1013 0000C75B 3B05[9A840100]      <1> 	cmp	eax, [FAT_BuffSector]
  1014                              <1>         ;jne	short loc_uc_save_fat_buffer
  1015                              <1> 	;jmp	short loc_update_fat12_cell
  1016                              <1> 	; 07/08/2022
  1017 0000C761 7412                <1> 	je	short loc_update_fat12_cell
  1018 0000C763 E92DFFFFFF          <1> 	jmp	loc_uc_save_fat_buffer
  1019                              <1> 
  1020                              <1> loc_uc_check_fat12_buff_sector_load:
  1021 0000C768 80F901              <1> 	cmp	cl, 1 ; byte ptr [FAT_BuffValidData]
  1022 0000C76B 759D                <1>         jne     short loc_uc_load_fat_sectors
  1023 0000C76D 3B05[9A840100]      <1> 	cmp	eax, [FAT_BuffSector]
  1024 0000C773 7595                <1> 	jne	short loc_uc_load_fat_sectors
  1025                              <1> 	; 07/08/2022
  1026                              <1> 	;je	short loc_update_fat12_cell
  1027                              <1> 	;jmp	loc_uc_load_fat_sectors
  1028                              <1> 
  1029                              <1> loc_update_fat12_cell:
  1030 0000C775 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
  1031                              <1> 	;mov	cx, [FAT_CurrentCluster]
  1032                              <1> 	; 25/07/2022
  1033 0000C77B 8B0D[92840100]      <1> 	mov	ecx, [FAT_CurrentCluster]
  1034                              <1> 	;shr	cx, 1
  1035                              <1> 	; 25/07/2022
  1036 0000C781 D1E9                <1> 	shr	ecx, 1
  1037 0000C783 668B03              <1> 	mov	ax, [ebx]
  1038                              <1> 	;mov	dx, ax
  1039 0000C786 89C2                <1> 	mov	edx, eax ; 25/07/2022
  1040                              <1> 	; 24/08/2024 (*)
  1041 0000C788 8B0D[34870100]      <1> 	mov	ecx, [ClusterValue] ; 32 bits
  1042 0000C78E 7336                <1> 	jnc	short uc_fat12_nc_even
  1043                              <1> 
  1044                              <1> 	; 26/08/2024
  1045                              <1> 	; ODD cluster number
  1046                              <1> 	; eax = current value (before updated)
  1047                              <1> 	; ecx = new value of the cluster
  1048                              <1>  	; of the cluster
  1049                              <1> 	; low 4 bit of al is high 4 bit
  1050                              <1> 	; of the previous cluster
  1051                              <1> 	;	(it must not be overwritten)
  1052                              <1> 
  1053                              <1> 	;and	ax, 0Fh
  1054                              <1> 	; 25/07/2022
  1055 0000C790 240F                <1> 	and	al, 0Fh
  1056                              <1> 	; 24/08/2024 (*)
  1057                              <1> 	;mov	ecx, [ClusterValue] ; 32 bits
  1058                              <1> 	;shl	cx, 4
  1059 0000C792 C1E104              <1> 	shl	ecx, 4
  1060                              <1> 	;or	cx, ax
  1061 0000C795 08C1                <1> 	or	cl, al ; 25/07/2022
  1062                              <1> 	;mov	ax, dx
  1063 0000C797 89D0                <1> 	mov	eax, edx
  1064 0000C799 66890B              <1> 	mov	[ebx], cx  ; 16 bits !
  1065                              <1> 	;shr	ax, 4 ; al(bit4..7)+ah(bit0..7)
  1066                              <1> 	; 25/07/2022
  1067 0000C79C C1E804              <1> 	shr	eax, 4
  1068                              <1> 
  1069                              <1> update_fat12_buffer:
  1070                              <1> 	;;;
  1071                              <1> 	; 24/08/2024
  1072 0000C79F 8B0D[34870100]      <1> 	mov	ecx, [ClusterValue]
  1073                              <1> 	;;;
  1074 0000C7A5 A3[92840100]        <1> 	mov	[FAT_CurrentCluster], eax
  1075 0000C7AA 89C2                <1> 	mov	edx, eax ; 01/03/2016
  1076 0000C7AC C605[96840100]02    <1> 	mov	byte [FAT_BuffValidData], 2
  1077 0000C7B3 6683F802            <1> 	cmp	ax, 2
  1078 0000C7B7 724A                <1>         jb      short return_uc_fat12_stc
  1079 0000C7B9 3B05[A2840100]      <1> 	cmp	eax, [LastCluster]
  1080 0000C7BF 7742                <1>         ja      short return_uc_fat12_stc
  1081 0000C7C1 E91AFFFFFF          <1>         jmp     loc_fat_buffer_updated
  1082                              <1> 
  1083                              <1> uc_fat12_nc_even:
  1084                              <1> 	; 26/08/2024
  1085                              <1> 	; EVEN cluster number
  1086                              <1> 	; eax = current value (before updated)
  1087                              <1> 	; ecx = new value of the cluster
  1088                              <1>  	; of the cluster
  1089                              <1> 	; high 4 bit of ah is low 4 bit
  1090                              <1> 	; of the next cluster (it must not be overwritten)
  1091                              <1> 
  1092 0000C7C6 662500F0            <1> 	and	ax, 0F000h
  1093                              <1> 	; 24/08/2024 (*)
  1094                              <1> 	;mov	ecx, [ClusterValue] ; 32 bits
  1095 0000C7CA 80E50F              <1> 	and	ch, 0Fh
  1096                              <1> 	;or	cx, ax
  1097                              <1> 	; 25/07/2022
  1098 0000C7CD 09C1                <1> 	or	ecx, eax
  1099                              <1> 	;mov	ax, dx
  1100 0000C7CF 89D0                <1> 	mov	eax, edx
  1101 0000C7D1 66890B              <1> 	mov	[ebx], cx ; 16 bits !
  1102 0000C7D4 80E40F              <1> 	and	ah, 0Fh ; al(bit0..7)+ah(bit0..3)
  1103 0000C7D7 EBC6                <1> 	jmp	short update_fat12_buffer
  1104                              <1> 
  1105                              <1> update_fat32_cluster:
  1106                              <1> 	; edx = 0 ; 24/08/2024
  1107                              <1> 	;mov	ecx, [esi+LD_Clusters]
  1108                              <1> 	;inc	ecx
  1109                              <1> 	;mov	[LastCluster], ecx
  1110                              <1> 	; 24/08/2024
  1111                              <1> 	; ecx = [LastCluster]
  1112                              <1> 
  1113                              <1> 	; 24/08/2024
  1114                              <1> 	;cmp	eax, ecx
  1115                              <1> 	;;ja	short return_uc_fat32_stc ; 25/07/2022
  1116                              <1> 	;; 24/08/2024
  1117                              <1> 	;; edx = 0 ; (must be -1 or > 0 after here)
  1118                              <1> 	;ja	short return_uc_fat_stc
  1119                              <1> 
  1120                              <1> pass_uc_fat32_errc:
  1121                              <1> 	;sub	edx, edx
  1122 0000C7D9 BB80010000          <1> 	mov	ebx, 180h ; 384
  1123 0000C7DE F7F3                <1> 	div	ebx
  1124                              <1> 	; EAX = Count of 3 FAT sectors
  1125                              <1> 	; DX = Cluster index in FAT buffer
  1126 0000C7E0 89D3                <1> 	mov	ebx, edx
  1127 0000C7E2 C1E302              <1> 	shl	ebx, 2 ; Multiply by 4
  1128                              <1> 	;mov	edx, 3
  1129                              <1> 	; 25/07/2022
  1130                              <1> 	;xor	dh, dh
  1131                              <1> 	;mov	dl, 3
  1132 0000C7E5 66BA0300            <1> 	mov	dx, 3
  1133 0000C7E9 F7E2                <1> 	mul	edx
  1134                              <1> 	; EBX = Cluster Offset in FAT buffer
  1135                              <1> 	; EAX = FAT Sector
  1136                              <1> 	; EDX = 0
  1137 0000C7EB 8A0D[96840100]      <1> 	mov	cl, [FAT_BuffValidData]
  1138 0000C7F1 80F902              <1> 	cmp	cl, 2
  1139 0000C7F4 7512                <1> 	jne	short loc_uc_check_fat32_buff_sector_load
  1140                              <1> 
  1141                              <1> loc_uc_check_fat32_buff_sector_save:
  1142 0000C7F6 3B05[9A840100]      <1> 	cmp	eax, [FAT_BuffSector]
  1143                              <1> 	;jne	loc_uc_save_fat_buffer
  1144                              <1> 	;jmp	short loc_update_fat32_cell
  1145                              <1> 	; 25/07/2022
  1146 0000C7FC 741C                <1> 	je	short loc_update_fat32_cell
  1147 0000C7FE E992FEFFFF          <1> 	jmp	loc_uc_save_fat_buffer
  1148                              <1> 
  1149                              <1> return_uc_fat12_stc:
  1150                              <1> return_uc_fat32_stc:
  1151                              <1> 	; 24/08/2024
  1152 0000C803 E964FEFFFF          <1> 	jmp	loc_fat_buffer_stc_0 ; (*)
  1153                              <1> 	; 25/07/2022
  1154                              <1> 	;sub	eax, eax
  1155                              <1> 	;stc
  1156                              <1> 	;jmp	loc_fat_buffer_stc_1 ; (*)
  1157                              <1> 
  1158                              <1> loc_uc_check_fat32_buff_sector_load:
  1159 0000C808 80F901              <1> 	cmp	cl, 1 ; byte [FAT_BuffValidData]
  1160                              <1> 	;jne	loc_uc_load_fat_sectors
  1161                              <1> 	; 25/07/2022
  1162 0000C80B 7508                <1> 	jne	short loc_uc_load_fat_sects
  1163 0000C80D 3B05[9A840100]      <1> 	cmp	eax, [FAT_BuffSector]
  1164                              <1> 	;jne	loc_uc_load_fat_sectors
  1165                              <1> 	; 25/07/2022
  1166 0000C813 7405                <1> 	je	short loc_update_fat32_cell
  1167                              <1> loc_uc_load_fat_sects:
  1168 0000C815 E9F0FEFFFF          <1> 	jmp	loc_uc_load_fat_sectors
  1169                              <1> 
  1170                              <1> loc_update_fat32_cell:
  1171                              <1> loc_update_fat32_buffer:
  1172 0000C81A 81C3001C0900        <1> 	add	ebx, FAT_Buffer ; 26/02/2016
  1173 0000C820 8B03                <1> 	mov	eax, [ebx]
  1174 0000C822 25FFFFFF0F          <1> 	and	eax, 0FFFFFFFh ; 28 bit cluster value
  1175                              <1> 	
  1176 0000C827 8B15[92840100]      <1> 	mov	edx, [FAT_CurrentCluster] ; 01/03/2016
  1177                              <1> 
  1178 0000C82D A3[92840100]        <1> 	mov 	[FAT_CurrentCluster], eax
  1179 0000C832 8B0D[34870100]      <1> 	mov	ecx, [ClusterValue]
  1180                              <1> 	;;;
  1181                              <1> 	; 29/08/2024
  1182 0000C838 81E1FFFFFF0F        <1> 	and	ecx, 0FFFFFFFh ; 28 bit cluster value
  1183                              <1> 	;;; 
  1184 0000C83E 890B                <1> 	mov	[ebx], ecx ; 29/02/2016
  1185                              <1> 
  1186 0000C840 C605[96840100]02    <1> 	mov	byte [FAT_BuffValidData], 2
  1187                              <1> 
  1188                              <1> 	; 01/03/2016
  1189 0000C847 21C0                <1> 	and	eax, eax ; was it free cluster ?
  1190 0000C849 7513                <1> 	jnz	short loc_upd_fat32_c0
  1191                              <1> 
  1192                              <1> 	;or	ecx, ecx ; it will be left free ?!
  1193                              <1> 	;jz	short loc_upd_fat32_c3
  1194                              <1> 
  1195 0000C84B 3B563E              <1> 	cmp	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free cluster
  1196 0000C84E 751F                <1> 	jne	short loc_upd_fat32_c3
  1197                              <1> 
  1198 0000C850 3B15[A2840100]      <1> 	cmp	edx, [LastCluster]
  1199 0000C856 7206                <1> 	jb	short loc_upd_fat32_c0
  1200                              <1> 
  1201                              <1> 	;mov	edx, 2 ; rewind !
  1202                              <1> 	; 25/07/2022
  1203 0000C858 29D2                <1> 	sub	edx, edx
  1204 0000C85A B202                <1> 	mov	dl, 2
  1205 0000C85C EB0E                <1> 	jmp	short loc_upd_fat32_c2
  1206                              <1> 
  1207                              <1> loc_upd_fat32_c0:
  1208 0000C85E FF463E              <1> 	inc	dword [esi+LD_BPB+BPB_Reserved+4] ; set it to next cluster
  1209 0000C861 EB0C                <1> 	jmp	short loc_upd_fat32_c3
  1210                              <1> 
  1211                              <1> loc_upd_fat32_c1:
  1212 0000C863 09C9                <1> 	or	ecx, ecx ; will it be free cluster ?
  1213 0000C865 7508                <1> 	jnz	short loc_upd_fat32_c3
  1214                              <1> 
  1215 0000C867 3B563E              <1> 	cmp	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free cluster
  1216 0000C86A 7303                <1> 	jnb	short loc_upd_fat32_c3
  1217                              <1> 
  1218                              <1> loc_upd_fat32_c2:
  1219 0000C86C 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx
  1220                              <1> 
  1221                              <1> loc_upd_fat32_c3:
  1222 0000C86F 89C2                <1> 	mov	edx, eax
  1223                              <1> 
  1224                              <1> loc_upd_fat32_c4:
  1225 0000C871 83F802              <1> 	cmp	eax, 2
  1226 0000C874 728D                <1> 	jb	short return_uc_fat32_stc ; 25/07/2022 
  1227                              <1> 
  1228                              <1> pass_uc_fat32_c_zero_check_2:
  1229 0000C876 3B05[A2840100]      <1> 	cmp	eax, [LastCluster]
  1230 0000C87C 7785                <1> 	ja	short return_uc_fat32_stc ; 25/07/2022
  1231                              <1> 	
  1232 0000C87E E95DFEFFFF          <1> 	jmp     loc_fat_buffer_updated
  1233                              <1> 
  1234                              <1> save_fat_buffer:
  1235                              <1> 	; 31/08/2024 (TRDOS 386 v2.0.9)
  1236                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
  1237                              <1> 	; 15/10/2016
  1238                              <1> 	; 01/03/2016
  1239                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
  1240                              <1> 	; 11/08/2011
  1241                              <1> 	; 09/02/2005
  1242                              <1> 	; INPUT ->
  1243                              <1> 	;	None
  1244                              <1> 	; OUTPUT ->
  1245                              <1> 	;	cf = 0 -> OK.
  1246                              <1> 	;	cf = 1 -> error code in AL (EAX)
  1247                              <1> 	;
  1248                              <1> 	;	EBX = FAT_Buffer address
  1249                              <1> 	;
  1250                              <1> 	; (EAX, EDX, ECX, EBX will be modified)
  1251                              <1> 
  1252                              <1> 	;cmp	byte [FAT_BuffValidData], 2
  1253                              <1> 	;je	short loc_save_fat_buff
  1254                              <1> 
  1255                              <1> ;loc_save_fat_buffer_retn:
  1256                              <1> ;	xor	eax, eax
  1257                              <1> ;	retn
  1258                              <1> 
  1259                              <1> loc_save_fat_buff:
  1260 0000C883 31D2                <1> 	xor	edx, edx
  1261 0000C885 8A35[97840100]      <1> 	mov	dh, [FAT_BuffDrvName]
  1262 0000C88B 80FE41              <1> 	cmp	dh, 'A'
  1263 0000C88E 7252                <1> 	jb	short loc_save_fat_buffer_inv_data_retn
  1264 0000C890 80EE41              <1> 	sub	dh, 'A'
  1265 0000C893 56                  <1> 	push	esi ; *
  1266 0000C894 BE00010900          <1>         mov     esi, Logical_DOSDisks
  1267 0000C899 01D6                <1> 	add	esi, edx
  1268                              <1> 
  1269 0000C89B 8A5603              <1> 	mov	dl, [esi+LD_FATType]
  1270 0000C89E 20D2                <1> 	and	dl, dl
  1271 0000C8A0 743F                <1> 	jz	short loc_save_fat_buffer_inv_data_pop_retn
  1272                              <1> 
  1273 0000C8A2 A1[9A840100]        <1> 	mov	eax, [FAT_BuffSector]
  1274 0000C8A7 80FA02              <1> 	cmp	dl, 2
  1275 0000C8AA 772E                <1> 	ja	short loc_save_fat32_buff
  1276                              <1> 
  1277                              <1> loc_save_fat_12_16_buff:
  1278                              <1> 	; 01/03/2016
  1279                              <1> 	; TRDOS v1 has a FATal bug here!
  1280                              <1> 	; Correct code: mov dx, word ptr [FAT_BuffSector]+2
  1281                              <1> 	; (DX:AX in TRDOS v1 -> EAX in TRDOS v2)
  1282                              <1> 	;
  1283 0000C8AC 0FB74E1C            <1> 	movzx	ecx, word [esi+LD_BPB+FATSecs]
  1284 0000C8B0 29C1                <1> 	sub	ecx, eax
  1285                              <1> 	; TRDOS v1 has a bug here... ('pop esi' was forgotten!)
  1286                              <1> 	;jna	short loc_save_fat_buffer_inv_data_retn ; wrong addr!
  1287 0000C8B2 762D                <1> 	jna	short loc_save_fat_buffer_inv_data_pop_retn ; correct addr.
  1288                              <1> 	; 25/07/2022
  1289                              <1> 	;jmp	short loc_save_fat_buffer_check_rs3
  1290                              <1> 
  1291                              <1> loc_save_fat_buffer_check_rs3:
  1292                              <1> 	; 25/07/2022
  1293 0000C8B4 29DB                <1> 	sub	ebx, ebx
  1294 0000C8B6 B303                <1> 	mov	bl, 3
  1295                              <1> 	;cmp	ecx, 3
  1296 0000C8B8 39D9                <1> 	cmp	ecx, ebx ; 3
  1297 0000C8BA 7602                <1> 	jna	short loc_save_fat_buff_continue
  1298 0000C8BC 89D9                <1> 	mov	ecx, ebx ; mov ecx, 3
  1299                              <1> loc_save_fat_buff_continue:
  1300 0000C8BE BB001C0900          <1> 	mov	ebx, FAT_Buffer
  1301 0000C8C3 034660              <1> 	add	eax, [esi+LD_FATBegin]
  1302 0000C8C6 51                  <1> 	push	ecx
  1303 0000C8C7 E825570000          <1> 	call	disk_write
  1304 0000C8CC 59                  <1> 	pop	ecx
  1305 0000C8CD 7239                <1> 	jc	short loc_save_FAT_buff_write_err
  1306                              <1> 
  1307 0000C8CF 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
  1308 0000C8D3 7613                <1> 	jna	short loc_calc_2nd_fat12_16_addr
  1309                              <1> 
  1310                              <1> loc_calc_2nd_fat32_addr:
  1311 0000C8D5 8B462A              <1> 	mov	eax, [esi+LD_BPB+FAT32_FAT_Size]
  1312 0000C8D8 EB12                <1> 	jmp	short loc_calc_2nd_fat_addr
  1313                              <1> 
  1314                              <1> 	; 25/07/2022
  1315                              <1> loc_save_fat32_buff:
  1316 0000C8DA 8B4E2A              <1> 	mov	ecx, [esi+LD_BPB+FAT32_FAT_Size]
  1317 0000C8DD 29C1                <1> 	sub	ecx, eax
  1318 0000C8DF 77D3                <1> 	ja	short loc_save_fat_buffer_check_rs3
  1319                              <1> 
  1320                              <1> loc_save_fat_buffer_inv_data_pop_retn:
  1321 0000C8E1 5E                  <1> 	pop	esi ; *
  1322                              <1> loc_save_fat_buffer_inv_data_retn:
  1323                              <1> 	;mov	eax, 0Dh ; Invalid DATA
  1324                              <1> 	; 25/07/2022
  1325 0000C8E2 29C0                <1> 	sub	eax, eax
  1326                              <1> 	;mov	al, 0Dh  ; Invalid Data
  1327                              <1> 	; 31/08/2024
  1328 0000C8E4 B01D                <1> 	mov	al, ERR_INV_DATA ; 29 ; Invalid Data
  1329 0000C8E6 F9                  <1> 	stc	; cf = 1
  1330 0000C8E7 C3                  <1> 	retn
  1331                              <1> 
  1332                              <1> loc_calc_2nd_fat12_16_addr:
  1333 0000C8E8 0FB7461C            <1> 	movzx	eax, word [esi+LD_BPB+FATSecs]
  1334                              <1> 
  1335                              <1> loc_calc_2nd_fat_addr:
  1336 0000C8EC 034660              <1> 	add	eax, [esi+LD_FATBegin]
  1337 0000C8EF 0305[9A840100]      <1> 	add	eax, [FAT_BuffSector]
  1338 0000C8F5 BB001C0900          <1> 	mov	ebx, FAT_Buffer
  1339                              <1> 	; ecx = 1 to 3
  1340 0000C8FA E8F2560000          <1> 	call	disk_write
  1341 0000C8FF 7207                <1> 	jc	short loc_save_FAT_buff_write_err
  1342                              <1>  	; Valid buffer (1 = valid but do not save)
  1343 0000C901 C605[96840100]01    <1> 	mov	byte [FAT_BuffValidData], 1
  1344                              <1> 
  1345                              <1> loc_save_FAT_buff_write_err:
  1346 0000C908 5E                  <1> 	pop	esi ; *
  1347 0000C909 BB001C0900          <1> 	mov	ebx, FAT_Buffer
  1348                              <1> 	; 15/10/2016 (1Dh -> 18)
  1349                              <1> 	; 23/03/2016 (1Dh)
  1350 0000C90E B812000000          <1> 	mov	eax, 18 ; Drive not ready or write error
  1351 0000C913 C3                  <1> 	retn
  1352                              <1> 
  1353                              <1> calculate_fat_freespace:
  1354                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
  1355                              <1> 	; 23/03/2016
  1356                              <1> 	; 02/03/2016
  1357                              <1> 	; 01/03/2016
  1358                              <1> 	; 29/02/2016
  1359                              <1> 	; 22/02/2016 (TRDOS 386 = TRDOS v2.0)
  1360                              <1> 	; 30/04/2011
  1361                              <1> 	; 03/04/2010
  1362                              <1> 	; 2005
  1363                              <1> 	; INPUT ->
  1364                              <1> 	;	EAX = Cluster count to be added or subtracted
  1365                              <1> 	; 	If BH = FFh, ESI = TR-DOS Logical Drive Description Table
  1366                              <1> 	; 	If BH < FFh, BH = TR-DOS Logical Drive Number
  1367                              <1> 	; 	BL: 
  1368                              <1> 	;	0 = Calculate, 1 = Add, 2 = Subtract, 3 = Get (Not Set/Calc)
  1369                              <1> 	; OUTPUT ->
  1370                              <1> 	;	EAX = Free Space in sectors
  1371                              <1> 	;	ESI = Logical Dos Drive Description Table address
  1372                              <1> 	;	BH = Logical Dos Drive Number (same with input value of BH)
  1373                              <1> 	;	BL = Type of operation (same with input value of BL)
  1374                              <1> 	;	ECX = 0 -> valid
  1375                              <1> 	;	ECX > 0 -> error or invalid
  1376                              <1> 	;	If EAX = FFFFFFFFh, it is 're-calculation needed'
  1377                              <1> 	;			          sign due to r/w error
  1378                              <1> 	;
  1379                              <1> 	; (Modifed registers: eax, ebx, ecx, edx, esi)
  1380                              <1> 	;
  1381                              <1> 
  1382 0000C914 66891D[3A870100]    <1> 	mov	[CFS_OPType], bx
  1383 0000C91B A3[3C870100]        <1> 	mov	[CFS_CC], eax
  1384                              <1> 
  1385 0000C920 80FFFF              <1> 	cmp	bh, 0FFh
  1386 0000C923 740B                <1> 	je	short pass_calculate_freespace_get_drive_dt_offset
  1387                              <1> 
  1388                              <1> loc_calculate_freespace_get_drive_dt_offset:
  1389 0000C925 31C0                <1> 	xor	eax, eax
  1390 0000C927 88FC                <1>         mov     ah, bh
  1391 0000C929 BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1392 0000C92E 01C6                <1>         add     esi, eax
  1393                              <1> 
  1394                              <1> pass_calculate_freespace_get_drive_dt_offset:
  1395 0000C930 08DB                <1> 	or	bl, bl
  1396 0000C932 7436                <1> 	jz	short loc_reset_fcc
  1397                              <1> 
  1398                              <1> loc_get_free_sectors:
  1399 0000C934 8B4674              <1> 	mov	eax, [esi+LD_FreeSectors]
  1400                              <1> 
  1401                              <1> 	;xor	ecx, ecx
  1402                              <1> 	;dec	ecx ; 0FFFFFFFFh
  1403                              <1> 	;cmp	eax, ecx ; 29/02/2016
  1404                              <1> 	;je	short loc_get_free_sectors_retn ; recalculation is needed!
  1405                              <1> 
  1406                              <1> 	; 23/03/2016
  1407 0000C937 8B4E70              <1> 	mov	ecx, [esi+LD_TotalSectors]
  1408 0000C93A 39C1                <1> 	cmp	ecx, eax ; Total sectors must be greater than Free sectors !
  1409 0000C93C 7707                <1> 	ja	short loc_get_free_sectors_check_optype
  1410                              <1> 
  1411 0000C93E 31C0                <1> 	xor	eax, eax
  1412 0000C940 48                  <1> 	dec	eax ; 0FFFFFFFFh  ; recalculation is needed!
  1413 0000C941 894674              <1> 	mov	[esi+LD_FreeSectors], eax ; reset (for recalculation)
  1414                              <1> 
  1415                              <1> loc_get_free_sectors_retn:
  1416 0000C944 C3                  <1> 	retn
  1417                              <1> 
  1418                              <1> loc_get_free_sectors_check_optype:
  1419 0000C945 80FB03              <1> 	cmp	bl, 3
  1420 0000C948 7203                <1> 	jb	short loc_set_fcc_1 ; 25/07/2022
  1421                              <1> 
  1422 0000C94A 29C9                <1> 	sub	ecx, ecx ; 0
  1423                              <1> 
  1424 0000C94C C3                  <1> 	retn
  1425                              <1> 
  1426                              <1> loc_set_fcc_1:
  1427 0000C94D 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
  1428                              <1> 	;ja	loc_update_FAT32_fs_info_fcc
  1429                              <1> 	; 25/07/2022
  1430 0000C951 7605                <1> 	jna	short loc_set_fcc_2
  1431 0000C953 E9DD000000          <1> 	jmp	loc_update_FAT32_fs_info_fcc
  1432                              <1> 
  1433                              <1> loc_set_fcc_2:
  1434                              <1> 	;mov	eax, [esi+LD_FreeSectors]
  1435 0000C958 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+SecPerClust]
  1436 0000C95C 29D2                <1> 	sub	edx, edx
  1437 0000C95E F7F1                <1> 	div	ecx
  1438                              <1> 	;or	dx, dx
  1439                              <1> 	;	; DX -> Remain sectors < SecPerClust
  1440                              <1> 	;	; DX > 0 -> invalid free sector count
  1441                              <1> 	;jnz	short loc_reset_fcc
  1442                              <1> 
  1443                              <1> ;pass_set_fcc_div32:
  1444 0000C960 A3[B4840100]        <1> 	mov	[FreeClusterCount], eax
  1445 0000C965 E986000000          <1>         jmp     loc_set_free_sectors_FAT12_FAT16
  1446                              <1> 
  1447                              <1> loc_reset_fcc:
  1448 0000C96A 31C0                <1> 	xor	eax, eax
  1449 0000C96C A3[B4840100]        <1> 	mov	[FreeClusterCount], eax ; 0
  1450 0000C971 8B5678              <1> 	mov	edx, [esi+LD_Clusters]
  1451 0000C974 42                  <1> 	inc	edx
  1452 0000C975 8915[A2840100]      <1> 	mov	[LastCluster], edx
  1453                              <1> 
  1454 0000C97B 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
  1455 0000C97F 7645                <1> 	jna	short loc_count_free_fat_clusters_0
  1456                              <1> 
  1457 0000C981 48                  <1> 	dec	eax ; FFFFFFFFh
  1458 0000C982 A3[44870100]        <1> 	mov	[CFS_FAT32FC], eax
  1459                              <1> 
  1460                              <1> 	; 29/02/2016
  1461 0000C987 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; reset
  1462 0000C98A 89463E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], eax ; reset
  1463                              <1> 
  1464                              <1> 	;mov 	eax, 2
  1465                              <1> 	; 25/07/2022
  1466 0000C98D 40                  <1> 	inc	eax ; eax = 0
  1467 0000C98E B002                <1> 	mov	al, 2
  1468                              <1> 
  1469                              <1> loc_count_fc_next_cluster_0:
  1470 0000C990 50                  <1> 	push	eax
  1471 0000C991 E88AF9FFFF          <1> 	call	get_next_cluster
  1472 0000C996 7310                <1> 	jnc	short loc_check_fat32_ff_cluster
  1473 0000C998 09C0                <1> 	or	eax, eax
  1474 0000C99A 741E                <1> 	jz	short pass_inc_cfs_fcc_0
  1475                              <1> 
  1476                              <1> loc_put_fcc_unknown_sign:
  1477 0000C99C 58                  <1> 	pop	eax
  1478                              <1> 	; "Free count is Unknown" sign
  1479                              <1> 	;mov	dword [FreeClusterCount], 0FFFFFFFFh
  1480                              <1> 
  1481                              <1> 	; 29/02/2016
  1482                              <1> 	; Save Free Cluster Count value in FAT32 'BPB_Reserved' area
  1483                              <1> 	;mov	[esi+LD_BPB+BPB_Reserved], 0FFFFFFFFh ; unknown!
  1484 0000C99D 8B15[44870100]      <1> 	mov	edx, [CFS_FAT32FC] ; First Free Cluster
  1485                              <1> 	; Save First Free Cluster value in FAT32 'BPB_Reserved+4' area
  1486 0000C9A3 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx
  1487                              <1> 
  1488 0000C9A6 EB7D                <1>         jmp     loc_put_fcc_invalid_sign
  1489                              <1> 
  1490                              <1> loc_check_fat32_ff_cluster:
  1491 0000C9A8 09C0                <1> 	or	eax, eax
  1492 0000C9AA 750E                <1> 	jnz	short pass_inc_cfs_fcc_0
  1493 0000C9AC 58                  <1> 	pop	eax
  1494 0000C9AD A3[44870100]        <1> 	mov	[CFS_FAT32FC], eax
  1495                              <1> 	;mov	dword [FreeClusterCount], 1
  1496 0000C9B2 FF05[B4840100]      <1> 	inc	dword [FreeClusterCount]
  1497 0000C9B8 EB27                <1> 	jmp	short pass_inc_cfs_fcc_1
  1498                              <1> 
  1499                              <1> pass_inc_cfs_fcc_0:
  1500 0000C9BA 58                  <1> 	pop	eax
  1501                              <1> 
  1502                              <1> pass_inc_cfs_fcc_0c:
  1503 0000C9BB 40                  <1> 	inc	eax ; add eax, 1
  1504 0000C9BC 3B05[A2840100]      <1> 	cmp	eax, [LastCluster]
  1505 0000C9C2 76CC                <1> 	jna 	short loc_count_fc_next_cluster_0
  1506 0000C9C4 EB6F                <1> 	jmp	short loc_update_FAT32_fs_info_fcc
  1507                              <1> 
  1508                              <1> loc_count_free_fat_clusters_0:
  1509                              <1> 	;mov	eax, 2
  1510 0000C9C6 B002                <1> 	mov	al, 2
  1511                              <1> 
  1512                              <1> loc_count_fc_next_cluster:
  1513 0000C9C8 50                  <1> 	push	eax
  1514 0000C9C9 E852F9FFFF          <1> 	call	get_next_cluster
  1515 0000C9CE 720C                <1> 	jc	short loc_count_fcc_stc
  1516                              <1> 
  1517                              <1> loc_count_free_clusters_1:
  1518 0000C9D0 21C0                <1> 	and	eax, eax
  1519 0000C9D2 750C                <1> 	jnz	short pass_inc_cfs_fcc
  1520                              <1> 
  1521 0000C9D4 FF05[B4840100]      <1> 	inc	dword [FreeClusterCount]
  1522 0000C9DA EB04                <1> 	jmp	short pass_inc_cfs_fcc
  1523                              <1> 
  1524                              <1> loc_count_fcc_stc:
  1525 0000C9DC 09C0                <1> 	or	eax, eax
  1526 0000C9DE 75BC                <1> 	jnz	short loc_put_fcc_unknown_sign ; 29/02/2016
  1527                              <1> 
  1528                              <1> pass_inc_cfs_fcc:
  1529 0000C9E0 58                  <1> 	pop	eax
  1530                              <1> 
  1531                              <1> pass_inc_cfs_fcc_1:
  1532 0000C9E1 40                  <1> 	inc	eax ; add eax, 1
  1533 0000C9E2 3B05[A2840100]      <1> 	cmp	eax, [LastCluster]
  1534 0000C9E8 76DE                <1> 	jna	short loc_count_fc_next_cluster
  1535                              <1> 
  1536                              <1> loc_set_free_sectors:
  1537 0000C9EA 807E0302            <1> 	cmp	byte [esi+LD_FATType], 2
  1538 0000C9EE 7745                <1> 	ja	short loc_update_FAT32_fs_info_fcc
  1539                              <1> 
  1540                              <1> loc_set_free_sectors_FAT12_FAT16:
  1541 0000C9F0 803D[3A870100]00    <1> 	cmp	byte [CFS_OPType], 0
  1542 0000C9F7 761C                <1> 	jna	short pass_FAT_add_sub_fcc
  1543 0000C9F9 A1[3C870100]        <1> 	mov	eax, [CFS_CC]
  1544 0000C9FE 803D[3A870100]01    <1> 	cmp	byte [CFS_OPType], 1
  1545 0000CA05 7708                <1> 	ja	short pass_FAT_add_fcc
  1546 0000CA07 0105[B4840100]      <1> 	add 	[FreeClusterCount], eax
  1547 0000CA0D EB06                <1> 	jmp	short pass_FAT_add_sub_fcc
  1548                              <1> 
  1549                              <1> pass_FAT_add_fcc:
  1550 0000CA0F 2905[B4840100]      <1> 	sub	[FreeClusterCount], eax
  1551                              <1> 
  1552                              <1> pass_FAT_add_sub_fcc:
  1553 0000CA15 0FB64613            <1> 	movzx	eax, byte [esi+LD_BPB+SecPerClust]
  1554 0000CA19 8B15[B4840100]      <1> 	mov	edx, [FreeClusterCount]
  1555 0000CA1F F7E2                <1> 	mul	edx
  1556                              <1> 
  1557 0000CA21 31C9                <1> 	xor	ecx, ecx 
  1558 0000CA23 EB05                <1> 	jmp	short loc_cfs_retn_params
  1559                              <1> 
  1560                              <1> loc_put_fcc_invalid_sign:
  1561 0000CA25 29C0                <1>        	sub	eax, eax ; 0
  1562 0000CA27 48                  <1> 	dec	eax ; FFFFFFFFh
  1563                              <1> loc_fat32_ffc_recalc_needed:
  1564 0000CA28 89C1                <1> 	mov	ecx, eax
  1565                              <1> 
  1566                              <1> loc_cfs_retn_params:
  1567 0000CA2A 894674              <1> 	mov 	[esi+LD_FreeSectors], eax
  1568 0000CA2D 0FB71D[3A870100]    <1> 	movzx	ebx, word [CFS_OPType]
  1569 0000CA34 C3                  <1> 	retn
  1570                              <1> 
  1571                              <1> loc_update_FAT32_fs_info_fcc:
  1572                              <1> loc_check_fcc_FSINFO_op:
  1573                              <1> 	; 29/02/2016
  1574                              <1> 	; EAX = Free cluster count (before this update) ; value from disk
  1575                              <1> 	; EDX = First Free Cluster (before this update) ; value from disk
  1576 0000CA35 803D[3A870100]01    <1> 	cmp	byte [CFS_OPType], 1
  1577 0000CA3C 7221                <1> 	jb	short loc_cfs_FAT32_get_rcalc_parms ; 0 = recalculated
  1578 0000CA3E 7406                <1> 	je	short loc_check_fcc_FSINFO_op1 ; 1 = add
  1579                              <1> loc_check_fcc_FSINFO_op2: ; subtract
  1580 0000CA40 F71D[3C870100]      <1> 	neg	dword [CFS_CC] ; prepare to subtract ; 2 = sub (add negative)
  1581                              <1> loc_check_fcc_FSINFO_op1:
  1582                              <1> 	; 01/03/2016
  1583 0000CA46 31D2                <1> 	xor	edx, edx ; 0
  1584 0000CA48 4A                  <1> 	dec	edx ; 0FFFFFFFFh
  1585 0000CA49 8B463A              <1> 	mov	eax, [esi+LD_BPB+BPB_Reserved]
  1586 0000CA4C 39D0                <1> 	cmp	eax, edx
  1587 0000CA4E 73D5                <1> 	jnb	short loc_put_fcc_invalid_sign
  1588 0000CA50 0305[3C870100]      <1>         add     eax, [CFS_CC] ; free cluster count on disk + current count
  1589 0000CA56 72CD                <1> 	jc	short loc_put_fcc_invalid_sign
  1590                              <1> 
  1591 0000CA58 A3[B4840100]        <1> 	mov	[FreeClusterCount], eax
  1592 0000CA5D EB0E                <1> 	jmp	short loc_cfs_write_FSINFO_sector
  1593                              <1> 
  1594                              <1> loc_cfs_FAT32_get_rcalc_parms:
  1595 0000CA5F 8B15[44870100]      <1> 	mov	edx, [CFS_FAT32FC]
  1596 0000CA65 A1[B4840100]        <1> 	mov	eax, [FreeClusterCount]
  1597 0000CA6A 89563E              <1> 	mov	[esi+LD_BPB+BPB_Reserved+4], edx ; First Free Cluster
  1598                              <1> loc_cfs_write_FSINFO_sector:
  1599 0000CA6D 89463A              <1> 	mov	[esi+LD_BPB+BPB_Reserved], eax ; Free cluster count
  1600                              <1> 	; 01/03/2016
  1601 0000CA70 E8BC000000          <1> 	call	set_fat32_fsinfo_sector_parms
  1602 0000CA75 72AE                <1>         jc      short loc_put_fcc_invalid_sign
  1603                              <1> 
  1604                              <1> loc_set_FAT32_free_sectors:
  1605                              <1> 	; 29/02/2016
  1606                              <1> 	;mov	eax, [FreeClusterCount]
  1607                              <1> 	;mov	ecx, eax
  1608                              <1> 	;cmp	eax, 0FFFFFFFFh ; Invalid !
  1609                              <1> 	;je	short loc_cfs_retn_params
  1610                              <1> 	;
  1611 0000CA77 8B0D[B4840100]      <1> 	mov	ecx, [FreeClusterCount]
  1612 0000CA7D 0FB64613            <1> 	movzx	eax, byte [esi+LD_BPB+SecPerClust]
  1613 0000CA81 F7E1                <1> 	mul	ecx
  1614                              <1> 	; 29/02/2016
  1615 0000CA83 31C9                <1> 	xor	ecx, ecx ; 0
  1616 0000CA85 09D2                <1> 	or	edx, edx ; 0 ?
  1617 0000CA87 759C                <1>         jnz	short loc_put_fcc_invalid_sign ; 25/07/2022
  1618 0000CA89 394670              <1> 	cmp	[esi+LD_TotalSectors], eax ; Volume size in sectors
  1619 0000CA8C 7697                <1>         jna     short loc_put_fcc_invalid_sign
  1620                              <1> 	;
  1621                              <1> loc_set_FAT32_free_sectors_ok:
  1622 0000CA8E 31D2                <1> 	xor	edx, edx ; 0
  1623 0000CA90 EB98                <1>         jmp     short loc_cfs_retn_params
  1624                              <1> 	;
  1625                              <1> 
  1626                              <1> get_last_cluster:
  1627                              <1> 	; 22/10/2016
  1628                              <1> 	; 27/02/2016 (TRDOS 386 = TRDOS v2.0)
  1629                              <1> 	; 12/06/2010 (DRV_FAT.ASM, 'proc_get_last_custer')
  1630                              <1> 	; 06/06/2010
  1631                              <1> 	; INPUT ->
  1632                              <1> 	;	EAX = First Cluster Number
  1633                              <1> 	; 	ESI = Logical Dos Drive Parameters Table
  1634                              <1> 	; OUTPUT ->
  1635                              <1> 	;	cf = 0 -> No Error, EAX is valid
  1636                              <1> 	;	cf = 1 -> EAX > 0 -> Error
  1637                              <1> 	;	EAX = Last Cluster Number
  1638                              <1> 	;       ECX = Previous Cluster -just before the last cluster-
  1639                              <1> 	;       ; 22/10/2016
  1640                              <1> 	;	[glc_index] = cluster index number of the last cluster	
  1641                              <1> 	;
  1642                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
  1643                              <1> 
  1644 0000CA92 89C1                <1> 	mov	ecx, eax
  1645                              <1> 
  1646 0000CA94 C705[4C870100]FFFF- <1> 	mov	dword [glc_index], 0FFFFFFFFh ; 22/10/2016	
  1646 0000CA9C FFFF                <1>
  1647                              <1> 
  1648                              <1> loc_glc_get_next_cluster_1:
  1649 0000CA9E 890D[48870100]      <1> 	mov	[glc_prevcluster], ecx
  1650                              <1>  	; 22/10/2016
  1651 0000CAA4 FF05[4C870100]      <1> 	inc	dword [glc_index]
  1652                              <1> 
  1653                              <1> loc_glc_get_next_cluster_2:
  1654 0000CAAA E871F8FFFF          <1> 	call	get_next_cluster
  1655                              <1> 	; ecx = current/previous cluster 
  1656                              <1> 	; eax = next/last cluster
  1657 0000CAAF 73ED                <1> 	jnc	short loc_glc_get_next_cluster_1
  1658                              <1> 
  1659 0000CAB1 09C0                <1> 	or	eax, eax
  1660 0000CAB3 7509                <1> 	jnz	short loc_glc_stc_retn
  1661                              <1> 
  1662                              <1> 	; ecx = previous cluster
  1663 0000CAB5 89C8                <1>         mov	eax, ecx
  1664                              <1> 
  1665                              <1> 	; previous cluster becomes last cluster (ecx -> eax)
  1666                              <1> 	; previous of previous cluster becomes previous cluster (ecx)
  1667                              <1> 
  1668                              <1> loc_glc_prev_cluster_retn:
  1669 0000CAB7 8B0D[48870100]      <1> 	mov	ecx, [glc_prevcluster] 
  1670 0000CABD C3                  <1> 	retn
  1671                              <1> 
  1672                              <1> loc_glc_stc_retn:
  1673 0000CABE F5                  <1> 	cmc	;stc
  1674 0000CABF EBF6                <1>         jmp	short loc_glc_prev_cluster_retn
  1675                              <1> 
  1676                              <1> truncate_cluster_chain:
  1677                              <1> 	; 31/08/2024 - TRDOS 386 v2.0.9
  1678                              <1> 	; 01/03/2016
  1679                              <1> 	; 28/02/2016 (TRDOS 386 = TRDOS v2.0)
  1680                              <1> 	; 22/01/2011 (DRV_FAT.ASM, 'proc_truncate_cluster_chain')
  1681                              <1> 	; 11/09/2010
  1682                              <1> 	; INPUT ->
  1683                              <1> 	;	ESI = Logical dos drive description table address
  1684                              <1> 	;	EAX = First cluster to be truncated/unlinked 
  1685                              <1> 	; OUTPUT ->
  1686                              <1> 	;	ESI = Logical dos drive description table address
  1687                              <1> 	; 	ECX = Count of truncated/removed clusters
  1688                              <1> 	; 	CF = 0 -> EAX = Free sectors
  1689                              <1> 	; 	CF = 1 -> Error code in EAX (AL)
  1690                              <1> 
  1691                              <1> 	; NOTE: This procedure does not update lm date&time !
  1692                              <1> 	 
  1693                              <1> loc_truncate_cc:	
  1694 0000CAC1 31C9                <1> 	xor	ecx, ecx ; mov ecx, 0
  1695                              <1> 	;mov	byte [FAT_BuffValidData], 0
  1696 0000CAC3 890D[9E840100]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; reset
  1697                              <1> 
  1698                              <1> 	;;;
  1699                              <1> 	; 31/08/2024
  1700 0000CAC9 21C0                <1> 	and	eax, eax ; 0
  1701 0000CACB 740D                <1> 	jz	short loc_tcc_unlink_zero_cluster  ; zero
  1702                              <1> 	;cmp	eax, 0FFFFFF7h
  1703 0000CACD 3DFFFFFF0F          <1> 	cmp	eax, 0FFFFFFFh ; 28 bit cluster number limit (EOF)
  1704 0000CAD2 7207                <1> 	jb	short loc_tcc_unlink_clusters
  1705                              <1> 
  1706                              <1> 	; (possible FAT32) EOF signature...
  1707                              <1> 	;	not a valid cluster number
  1708                              <1> 	;	
  1709                              <1> 	; NOTE: update_cluster returns EOF (if eax > [LastCluster])
  1710                              <1> 	;	instead of invalid data error
  1711                              <1> 
  1712 0000CAD4 B81D000000          <1> 	mov	eax, ERR_INV_DATA  ; invalid cluster number
  1713 0000CAD9 F9                  <1> 	stc
  1714                              <1> loc_tcc_unlink_zero_cluster:	; nothing to do
  1715 0000CADA C3                  <1> 	retn
  1716                              <1> 	;;;
  1717                              <1> 
  1718                              <1> loc_tcc_unlink_clusters:
  1719 0000CADB E82FFBFFFF          <1> 	call	update_cluster
  1720                              <1> 	; EAX = Next Cluster
  1721                              <1> 	; ECX = Cluster Value
  1722                              <1> 	; Note:
  1723                              <1> 	; Returns count of unlinked clusters in
  1724                              <1> 	; dword ptr FAT_ClusterCounter
  1725 0000CAE0 73F9                <1> 	jnc	short loc_tcc_unlink_clusters
  1726                              <1> 
  1727                              <1> 	; error or EOF (end of cluster chain) ; 31/08/2024
  1728                              <1> 
  1729                              <1> pass_tcc_unlink_clusters:
  1730 0000CAE2 A2[53870100]        <1> 	mov	byte [TCC_FATErr], al
  1731 0000CAE7 803D[96840100]02    <1> 	cmp	byte [FAT_BuffValidData], 2
  1732 0000CAEE 750E                <1> 	jne	short loc_tcc_calculate_FAT_freespace
  1733 0000CAF0 E88EFDFFFF          <1> 	call	save_fat_buffer
  1734 0000CAF5 7307                <1> 	jnc	short loc_tcc_calculate_FAT_freespace
  1735 0000CAF7 A2[53870100]        <1> 	mov	byte [TCC_FATErr], al ; Error
  1736                              <1> 	;mov	byte [FAT_BuffValidData], 0
  1737                              <1> 
  1738                              <1> 	; 01/03/2016
  1739 0000CAFC EB12                <1> 	jmp	short loc_tcc_recalculate_FAT_freespace
  1740                              <1> 
  1741                              <1> loc_tcc_calculate_FAT_freespace:
  1742 0000CAFE A1[9E840100]        <1> 	mov	eax, [FAT_ClusterCounter] ; signed (+-) number
  1743 0000CB03 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> ESI = Dos drv desc. table
  1744                              <1> 			   ; BL = 1 -> add cluster(s)
  1745 0000CB07 E808FEFFFF          <1> 	call	calculate_fat_freespace
  1746 0000CB0C 21C9                <1> 	and	ecx, ecx ; cx = 0 -> valid free sector count
  1747 0000CB0E 7409                <1> 	jz	short pass_truncate_cc_recalc_FAT_freespace
  1748                              <1> 
  1749                              <1> loc_tcc_recalculate_FAT_freespace:
  1750 0000CB10 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate !
  1751 0000CB14 E8FBFDFFFF          <1> 	call	calculate_fat_freespace
  1752                              <1>               
  1753                              <1> loc_tcc_calculate_FAT_freespace_err:
  1754                              <1> pass_truncate_cc_recalc_FAT_freespace:
  1755 0000CB19 8B0D[9E840100]      <1> 	mov	ecx, [FAT_ClusterCounter]
  1756                              <1> 
  1757 0000CB1F 803D[53870100]00    <1> 	cmp	byte [TCC_FATErr], 0
  1758 0000CB26 7608                <1> 	jna	short loc_tcc_unlink_clusters_retn
  1759                              <1> 
  1760                              <1> loc_tcc_unlink_clusters_error:
  1761 0000CB28 0FB605[53870100]    <1> 	movzx	eax, byte [TCC_FATErr]
  1762 0000CB2F F9                  <1> 	stc
  1763                              <1> loc_tcc_unlink_clusters_retn:
  1764 0000CB30 C3                  <1> 	retn
  1765                              <1> 
  1766                              <1> set_fat32_fsinfo_sector_parms:
  1767                              <1> 	; 15/10/2016
  1768                              <1> 	; 23/03/2016
  1769                              <1> 	; 29/02/2016 (TRDOS 386 = TRDOS v2.0)
  1770                              <1> 	; INPUT ->
  1771                              <1> 	;	ESI = Logical dos drive description table address
  1772                              <1> 	;	[esi+LD_BPB+BPB_Reserved] = Free Cluster Count
  1773                              <1> 	;	[esi+LD_BPB+BPB_Reserved+4] = First Free Cluster 
  1774                              <1> 	; OUTPUT ->
  1775                              <1> 	;	ESI = Logical dos drive description table address
  1776                              <1> 	; 	CF = 0 -> OK..
  1777                              <1> 	; 	CF = 1 -> Error code in EAX (AL)
  1778                              <1> 	;
  1779                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
  1780                              <1> 
  1781 0000CB31 E824000000          <1> 	call	get_fat32_fsinfo_sector_parms
  1782 0000CB36 7221                <1> 	jc	short update_fat32_fsinfo_sector_retn
  1783                              <1> 
  1784 0000CB38 8B463A              <1> 	mov	eax, [esi+LD_BPB+BPB_Reserved] ; Free Cluster Count
  1785 0000CB3B 8B563E              <1> 	mov	edx, [esi+LD_BPB+BPB_Reserved+4] ; First free Cluster	
  1786                              <1> 
  1787                              <1>         ;mov	ebx, DOSBootSectorBuff
  1788 0000CB3E 8983E8010000        <1> 	mov	[ebx+488], eax
  1789 0000CB44 8993EC010000        <1> 	mov	[ebx+492], edx	
  1790                              <1> 
  1791 0000CB4A A1[40870100]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC]
  1792 0000CB4F B901000000          <1> 	mov	ecx, 1
  1793 0000CB54 E898540000          <1> 	call	disk_write
  1794                              <1> 	;jnc	short update_fat32_fsinfo_sector_retn
  1795                              <1> 
  1796                              <1> 	; 15/10/2016 (1Dh -> 18)
  1797                              <1> 	; 23/03/2016 (1Dh)
  1798                              <1> 	;mov	eax, 18 ; Drive not ready or write error
  1799                              <1> 
  1800                              <1> update_fat32_fsinfo_sector_retn:
  1801 0000CB59 C3                  <1> 	retn
  1802                              <1> 
  1803                              <1> get_fat32_fsinfo_sector_parms:
  1804                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
  1805                              <1> 	; 15/10/2016
  1806                              <1> 	; 23/03/2016
  1807                              <1> 	; 01/03/2016
  1808                              <1> 	; 29/02/2016 (TRDOS 386 = TRDOS v2.0)
  1809                              <1> 	; INPUT ->
  1810                              <1> 	;	ESI = Logical dos drive description table address
  1811                              <1> 	; OUTPUT ->
  1812                              <1> 	;	ESI = Logical dos drive description table address
  1813                              <1> 	;	EBX = FSINFO sector buffer address (DOSBootSectorBuff)	
  1814                              <1> 	;	CF = 0 -> OK..
  1815                              <1> 	;	   EAX = FsInfo sector address
  1816                              <1> 	;	   ECX = Free cluster count
  1817                              <1> 	;	   EDX = First free cluster 	
  1818                              <1> 	;	CF = 1 -> Error code in AL (EAX)
  1819                              <1> 	;	   EBX = 0
  1820                              <1> 	;	
  1821                              <1> 	;	[CFS_FAT32FSINFOSEC] = FAT32 FSINFO sector address
  1822                              <1>         ;
  1823                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
  1824                              <1> 
  1825 0000CB5A 0FB74636            <1> 	movzx	eax, word [esi+LD_BPB+FAT32_FSInfoSec]
  1826 0000CB5E 03466C              <1> 	add	eax, [esi+LD_StartSector]
  1827 0000CB61 A3[40870100]        <1> 	mov	[CFS_FAT32FSINFOSEC], eax
  1828                              <1> 	
  1829 0000CB66 BB[92820100]        <1>         mov     ebx, DOSBootSectorBuff
  1830                              <1> 	;mov	ecx, 1
  1831                              <1> 	; 25/07/2022
  1832 0000CB6B 29C9                <1> 	sub	ecx, ecx
  1833 0000CB6D FEC1                <1> 	inc	cl
  1834                              <1> 	; ecx = 1
  1835 0000CB6F E88C540000          <1> 	call	disk_read
  1836 0000CB74 722F                <1> 	jc	short loc_read_FAT32_fsinfo_sec_err
  1837                              <1> 
  1838 0000CB76 BB[92820100]        <1> 	mov	ebx, DOSBootSectorBuff
  1839                              <1> 
  1840 0000CB7B 813B52526141        <1> 	cmp	dword [ebx], 41615252h
  1841 0000CB81 751E                <1> 	jne	short loc_read_FAT32_fsinfo_sec_stc
  1842                              <1> 
  1843 0000CB83 81BBE4010000727241- <1> 	cmp	dword [ebx+484], 61417272h
  1843 0000CB8C 61                  <1>
  1844 0000CB8D 7512                <1> 	jne	short loc_read_FAT32_fsinfo_sec_stc
  1845                              <1> 
  1846 0000CB8F A1[40870100]        <1> 	mov	eax, [CFS_FAT32FSINFOSEC]
  1847 0000CB94 8B8BE8010000        <1> 	mov	ecx, [ebx+488] ; free cluster count
  1848 0000CB9A 8B93EC010000        <1> 	mov	edx, [ebx+492] ; first (next) free cluster	
  1849                              <1> 
  1850 0000CBA0 C3                  <1> 	retn
  1851                              <1> 
  1852                              <1> loc_read_FAT32_fsinfo_sec_stc: 
  1853                              <1> 	; 15/10/2016 (0Bh -> 28)
  1854                              <1> 	;mov	eax, 28 ; Invalid format!
  1855                              <1> 	; 25/07/2022
  1856 0000CBA1 B31C                <1> 	mov	bl, 28
  1857 0000CBA3 EB02                <1> 	jmp	short loc_read_FAT32_fsinfo_sec_stc_retn
  1858                              <1> 
  1859                              <1> loc_read_FAT32_fsinfo_sec_err:
  1860                              <1> 	; 15/10/2016 (15h -> 17)
  1861                              <1> 	; 23/03/2016 (15h)
  1862                              <1> 	;mov	eax, 17 ; Drive not ready or read error
  1863                              <1> 	; 25/07/2022
  1864 0000CBA5 B311                <1> 	mov	bl, 17
  1865                              <1> loc_read_FAT32_fsinfo_sec_stc_retn:
  1866                              <1> 	; 25/07/2022
  1867 0000CBA7 29C0                <1> 	sub	eax, eax
  1868 0000CBA9 88D8                <1> 	mov	al, bl ; error code
  1869                              <1> 	; eax = error code
  1870 0000CBAB 29DB                <1> 	sub	ebx, ebx ; 0
  1871 0000CBAD F9                  <1> 	stc
  1872 0000CBAE C3                  <1> 	retn
  1873                              <1> 
  1874                              <1> add_new_cluster:
  1875                              <1> 	; 30/08/2024
  1876                              <1> 	; 27/08/2024
  1877                              <1> 	; 25/08/2024 - TRDOS 386 v2.0.9
  1878                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
  1879                              <1> 	; 15/10/2016
  1880                              <1> 	; 16/05/2016
  1881                              <1> 	; 18/03/2016, 24/03/2016
  1882                              <1> 	; 11/03/2016 (TRDOS 386 = TRDOS v2.0)
  1883                              <1> 	; 30/07/2011 (DRV_FAT.ASM)
  1884                              <1> 	; 11/09/2010
  1885                              <1> 	; INPUT ->
  1886                              <1> 	;	ESI = Logical dos drv desc. table address
  1887                              <1> 	;	EAX = Last cluster
  1888                              <1> 	; OUTPUT ->
  1889                              <1> 	;	ESI = Logical dos drv desc. table address
  1890                              <1> 	;	EAX = New Last cluster (next cluster)
  1891                              <1> 	;	cf = 1 -> error code in EAX (AL)
  1892                              <1> 	;	cf = 1 -> EBX = sectors per cluster
  1893                              <1> 	;	ECX = Free sectors
  1894                              <1> 	;;;	25/07/2022
  1895                              <1> 	;	(EBX = sectors per cluster -not used-)
  1896                              <1> 	;	EDX = 0 (if cf = 0)
  1897                              <1> 	; NOTE:
  1898                              <1> 	; This procedure does not update lm date&time !
  1899                              <1> 	;    ; 30/08/2024	
  1900                              <1> 	; and doesn't update 1st clust and file size fields !
  1901                              <1> 	;
  1902                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, EDI)
  1903                              <1> 
  1904 0000CBAF A3[70880100]        <1> 	mov	[FAT_anc_LCluster], eax
  1905                              <1> 
  1906 0000CBB4 E889F9FFFF          <1> 	call	get_first_free_cluster
  1907 0000CBB9 7206                <1> 	jc	short loc_add_new_cluster_retn
  1908                              <1> 	; EAX >= 2 and EAX < FFFFFFFFh is valid
  1909                              <1> 
  1910                              <1> 	;mov	edx, eax
  1911                              <1> 	;
  1912                              <1> 	;inc	edx
  1913                              <1> 	;;jnz	short loc_add_new_cluster_check_ffc_eax
  1914                              <1> 	;jnz	short loc_add_new_cluster_save_fcc
  1915                              <1> 
  1916                              <1> 	; 27/08/2024
  1917 0000CBBB 40                  <1> 	inc	eax ; (*)
  1918 0000CBBC 750D                <1> 	jnz	short loc_add_new_cluster_save_fcc
  1919                              <1> 
  1920                              <1> loc_add_new_cluster_no_disk_space_retn:
  1921                              <1> 	;mov	eax, 27h ; MSDOS err => insufficient disk space
  1922                              <1> 	; 27/08/2024
  1923                              <1> 	; eax = 0
  1924                              <1> 	; 25/07/2022
  1925                              <1> 	;xor	eax, eax
  1926 0000CBBE B027                <1> 	mov	al, 27h
  1927                              <1> loc_add_new_cluster_stc_retn:
  1928 0000CBC0 F9                  <1> 	stc
  1929                              <1> loc_add_new_cluster_retn:
  1930                              <1> 	; 25/07/2022
  1931                              <1> 	;movzx	ebx, byte [esi+LD_BPB+SecPerClust]
  1932 0000CBC1 8B4E74              <1> 	mov	ecx, [esi+LD_FreeSectors]
  1933                              <1> 	;xor	edx, edx
  1934                              <1> 	;stc
  1935 0000CBC4 C3                  <1> 	retn
  1936                              <1> 
  1937                              <1> loc_anc_invalid_format_stc_retn:
  1938                              <1> 	; 27/08/2024
  1939                              <1> 	;stc
  1940                              <1> loc_add_new_cluster_invalid_format_retn:
  1941                              <1> 	; 15/10/2016 (0Bh -> 28)
  1942                              <1> 	;mov	eax, 28 ; Invalid format
  1943                              <1> 	;jmp	short loc_add_new_cluster_retn
  1944                              <1> 	; 25/07/2022
  1945 0000CBC5 29C0                <1> 	sub	eax, eax
  1946 0000CBC7 B01C                <1> 	mov	al, 28
  1947 0000CBC9 EBF5                <1> 	jmp	short loc_add_new_cluster_stc_retn
  1948                              <1> 
  1949                              <1> ;loc_add_new_cluster_check_ffc_eax:
  1950                              <1> ;	cmp	eax, 2
  1951                              <1> ;	jb	short loc_add_new_cluster_invalid_format_retn
  1952                              <1> 
  1953                              <1> loc_add_new_cluster_save_fcc:
  1954                              <1> 	;;;
  1955                              <1> 	; 27/08/2024
  1956 0000CBCB 48                  <1> 	dec	eax ; (*)
  1957                              <1> 	;;;  
  1958 0000CBCC A3[74880100]        <1> 	mov	[FAT_anc_FFCluster], eax
  1959                              <1> 
  1960                              <1> ; 27/08/2024 (TRDOS 386 v2.0.9)
  1961                              <1> %if 0
  1962                              <1> 	sub	eax, 2
  1963                              <1> 	movzx   ebx, byte [esi+LD_BPB+SecPerClust]
  1964                              <1> 	mul	ebx
  1965                              <1> 	or	edx, edx
  1966                              <1> 	jnz	short loc_anc_invalid_format_stc_retn
  1967                              <1> 
  1968                              <1> loc_add_new_cluster_allocate_cluster:
  1969                              <1> 	; 18/03/2016
  1970                              <1> 	xchg	edx, eax ; eax = 0
  1971                              <1> 	; 16/05/2016
  1972                              <1> 	;cmp	[ClusterBuffer_Valid], al ; 0
  1973                              <1> 	;jna	short loc_anc_clear_cluster_buffer
  1974                              <1> 	;; 'copy' command, 
  1975                              <1> 	;; writing destination file clust after reading source file clust
  1976                              <1> 	;mov	[ClusterBuffer_Valid], al ; 0 ; reset
  1977                              <1> 	;jmp	short loc_add_new_cluster_write_nc_to_disk
  1978                              <1> 
  1979                              <1> loc_anc_clear_cluster_buffer:
  1980                              <1> 	; 11/03/2016
  1981                              <1> 	; Clear buffer
  1982                              <1> 	mov	edi, Cluster_Buffer ; 70000h (for current TRDOS 386 version)
  1983                              <1> 	mov	ecx, ebx ; sector count
  1984                              <1> 	shl	ecx, 7 ; 1 sector = 512 bytes -> 128 double words
  1985                              <1> 	;xor	eax, eax ; 0
  1986                              <1> 	rep	stosd
  1987                              <1> 
  1988                              <1> loc_add_new_cluster_write_nc_to_disk:
  1989                              <1> 	; 11/03/2016
  1990                              <1> 	;xchg	eax, edx ; edx = 0, eax = sector offset
  1991                              <1> 	mov	eax, edx
  1992                              <1>         add     eax, [esi+LD_DATABegin]
  1993                              <1> 	jc	short loc_add_new_cluster_invalid_format_retn
  1994                              <1> 		
  1995                              <1> 	mov	ecx, ebx ; ECX = sectors per cluster (<256)
  1996                              <1> 	mov	ebx, Cluster_Buffer
  1997                              <1> 	call	disk_write
  1998                              <1> 	jnc	short loc_add_new_cluster_update_fat_nlc
  1999                              <1> 	
  2000                              <1> 	; 15/10/2016 (1Dh -> 18)
  2001                              <1> 	;mov	eax, 18 ; Write Error
  2002                              <1> 	; 25/07/2022
  2003                              <1> 	xor	eax, eax
  2004                              <1> 	mov	al, 18
  2005                              <1> 	jmp	short loc_add_new_cluster_stc_retn
  2006                              <1> 
  2007                              <1> loc_add_new_cluster_update_fat_nlc:
  2008                              <1> 	mov	eax, [FAT_anc_FFCluster]
  2009                              <1> %endif
  2010                              <1> 	; 30/08/2024
  2011                              <1> 	; eax = [FAT_anc_FFCluster] ; first free cluster
  2012 0000CBD1 31C9                <1> 	xor	ecx, ecx ; 0
  2013 0000CBD3 890D[9E840100]      <1> 	mov	[FAT_ClusterCounter], ecx ; 0 ; reset
  2014 0000CBD9 49                  <1> 	dec	ecx ; -1 ; 0FFFFFFFFh
  2015 0000CBDA 850D[70880100]      <1> 	test	[FAT_anc_LCluster], ecx	; 0 ?
  2016 0000CBE0 7416                <1> 	jz	short loc_add_new_cluster_update_fat_fc ; yes
  2017                              <1> 
  2018                              <1> 	; 27/08/2024
  2019                              <1> 	; eax = (first free) cluster to be added as last cluster
  2020                              <1> 	;;;
  2021                              <1> 	;xor	ecx, ecx
  2022                              <1> 
  2023                              <1> loc_add_new_cluster_update_fat_nlc: ; 30/08/2024
  2024                              <1> 	;mov	[FAT_ClusterCounter], ecx ; 0 ; reset
  2025                              <1> 	;dec	ecx ; 0FFFFFFFFh ; last cluster
  2026 0000CBE2 E828FAFFFF          <1> 	call	update_cluster
  2027 0000CBE7 7304                <1> 	jnc	short loc_add_new_cluster_update_fat_plc
  2028 0000CBE9 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  2029 0000CBEB 75D3                <1> 	jnz	short loc_add_new_cluster_stc_retn
  2030                              <1> 
  2031                              <1> loc_add_new_cluster_update_fat_plc:
  2032 0000CBED A1[70880100]        <1> 	mov	eax, [FAT_anc_LCluster]
  2033 0000CBF2 8B0D[74880100]      <1> 	mov	ecx, [FAT_anc_FFCluster]
  2034                              <1> loc_add_new_cluster_update_fat_fc: ; 30/08/2024
  2035 0000CBF8 E812FAFFFF          <1> 	call	update_cluster
  2036 0000CBFD 7311                <1> 	jnc	short loc_add_new_cluster_save_fat_buffer
  2037                              <1> 
  2038 0000CBFF 09C0                <1> 	or	eax, eax ; EAX = 0 -> cluster value is 0 or eocc
  2039 0000CC01 740D                <1> 	jz	short loc_add_new_cluster_save_fat_buffer
  2040                              <1> 
  2041                              <1> loc_anc_save_fat_buffer_err_retn:
  2042                              <1> 	;cmp	byte [FAT_ClusterCounter], 1
  2043                              <1> 	;jb	short loc_add_new_cluster_retn
  2044                              <1> 
  2045 0000CC03 66BB00FF            <1> 	mov	bx, 0FF00h ; recalculate free space (BL = 0)
  2046                              <1> 			   ; (BH = FFh -> Use ESI as Drv Param. Tbl.)
  2047 0000CC07 50                  <1> 	push	eax
  2048 0000CC08 E807FDFFFF          <1> 	call	calculate_fat_freespace
  2049 0000CC0D 58                  <1> 	pop	eax
  2050 0000CC0E EBB0                <1>         jmp     loc_add_new_cluster_stc_retn
  2051                              <1> 
  2052                              <1> loc_add_new_cluster_save_fat_buffer:
  2053                              <1> 	;cmp	byte [FAT_BuffValidData], 2
  2054                              <1> 	;jne	short loc_add_new_cluster_calc_FAT_freespace
  2055                              <1> 	;Byte [FAT_BuffValidData] = 2 
  2056 0000CC10 E86EFCFFFF          <1> 	call	save_fat_buffer
  2057 0000CC15 72EC                <1> 	jc	short loc_anc_save_fat_buffer_err_retn
  2058                              <1> 
  2059                              <1> loc_add_new_cluster_calc_FAT_freespace:
  2060                              <1> 	;mov	eax, 1 ; Only one Cluster
  2061 0000CC17 A1[9E840100]        <1> 	mov	eax, [FAT_ClusterCounter]
  2062 0000CC1C 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> ESI -> Dos drv desc. table
  2063                              <1> 		; BL = 1 -> add cluster(s)
  2064                              <1> 	;mov	bl, 01h ; 27/08/2024
  2065                              <1> 	; NOTE: EAX value will be added to Free Cluster Count
  2066                              <1> 	; (Free Cluster Count is decreased when EAX value is negative)
  2067 0000CC20 E8EFFCFFFF          <1>         call    calculate_fat_freespace
  2068                              <1> 	; ECX = 0 -> no error, ECX > 0 -> error or invalid return
  2069 0000CC25 21C9                <1> 	and	ecx, ecx ; ECX = 0 -> valid free sector count
  2070 0000CC27 7409                <1> 	jz	short loc_add_new_cluster_return_cluster_number
  2071                              <1> 
  2072                              <1> loc_add_new_cluster_recalc_FAT_freespace:
  2073 0000CC29 66BB00FF            <1> 	mov	bx, 0FF00h  ; recalculate free space
  2074 0000CC2D E8E2FCFFFF          <1>         call    calculate_fat_freespace
  2075                              <1> 	; cf = 0
  2076                              <1> loc_add_new_cluster_return_cluster_number:
  2077 0000CC32 89C1                <1> 	mov	ecx, eax ; Free sector count
  2078 0000CC34 A1[74880100]        <1> 	mov	eax, [FAT_anc_FFCluster]
  2079                              <1> 	;mov	edi, Cluster_Buffer
  2080                              <1> 	; 25/07/2022 (EBX is not used by callers of this sprocedure)
  2081                              <1> 	;movzx	ebx, byte [esi+LD_BPB+SecPerClust]
  2082 0000CC39 31D2                <1> 	xor	edx, edx ; 0
  2083 0000CC3B C3                  <1>         retn
  2084                              <1> 
  2085                              <1> write_cluster:
  2086                              <1> 	; 31/08/2024 - TRDOS 386 v2.0.9
  2087                              <1> 	; 15/10/2016
  2088                              <1> 	; 21/03/2016 (TRDOS 386 = TRDOS v2.0)
  2089                              <1> 	;
  2090                              <1> 	; INPUT ->
  2091                              <1> 	;	EAX = Cluster Number (Sector index for SINGLIX FS)
  2092                              <1> 	;	ESI = Logical DOS Drive Description Table address
  2093                              <1> 	;	EBX = Cluster (File R/W) Buffer address (max. 64KB)
  2094                              <1> 	;	Only for SINGLIX FS:
  2095                              <1> 	;	EDX = File Number (The 1st FDT address) 
  2096                              <1> 	; OUTPUT ->
  2097                              <1> 	;	cf = 1 -> Cluster can not be written onto disk
  2098                              <1> 	;	    EAX > 0 -> Error number
  2099                              <1> 	;	cf = 0 -> Cluster has been written successfully
  2100                              <1> 	;
  2101                              <1> 	; (Modified registers: EAX, ECX, EBX, EDX)
  2102                              <1> 	
  2103 0000CC3C 0FB64E13            <1> 	movzx	ecx, byte [esi+LD_BPB+BPB_SecPerClust] 
  2104                              <1> 	; CL = 1 = [esi+LD_FS_Reserved2] ; SectPerClust for Singlix FS
  2105                              <1> 
  2106                              <1> write_file_sectors: ; 16/03/2016
  2107 0000CC40 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
  2108 0000CC44 761C                <1> 	jna	short write_fs_cluster
  2109                              <1> 
  2110                              <1> write_fat_file_sectors:
  2111                              <1> 	; 31/08/2024
  2112                              <1> 	; ecx = sector count (may be different than sectors per cluster)
  2113 0000CC46 83E802              <1> 	sub	eax, 2 ; Beginning cluster number is always 2
  2114 0000CC49 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+BPB_SecPerClust] ; 18/03/2016 
  2115 0000CC4D F7E2                <1> 	mul	edx
  2116 0000CC4F 034668              <1> 	add	eax, [esi+LD_DATABegin] ; absolute address of the cluster
  2117                              <1> 
  2118                              <1> 	; EAX = Disk sector address
  2119                              <1> 	; ECX = Sector count
  2120                              <1> 	; EBX = Buffer address
  2121                              <1> 	; (EDX = 0)
  2122                              <1> 	; ESI = Logical DOS drive description table address	
  2123                              <1> 
  2124 0000CC52 E89A530000          <1> 	call	disk_write
  2125 0000CC57 7306                <1> 	jnc	short wclust_retn
  2126                              <1> 	
  2127                              <1> 	; 15/10/2016 (1Dh -> 18)
  2128 0000CC59 B812000000          <1> 	mov	eax, 18 ; Drive not ready or write error !
  2129 0000CC5E C3                  <1> 	retn
  2130                              <1> 
  2131                              <1> wclust_retn:
  2132 0000CC5F 29C0                <1> 	sub	eax, eax ; 0
  2133 0000CC61 C3                  <1> 	retn
  2134                              <1> 
  2135                              <1> write_fs_cluster:
  2136                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
  2137                              <1> 	; 21/03/2016 (TRDOS 386 = TRDOS v2.0)
  2138                              <1> 	; Singlix FS
  2139                              <1> 	
  2140                              <1> 	; EAX = Cluster number is sector index number of the file (eax)
  2141                              <1> 	
  2142                              <1> 	; EDX = File number is the first File Descriptor Table address 
  2143                              <1> 	;	of the file. (Absolute address of the FDT).
  2144                              <1> 	
  2145                              <1> 	; eax = sector index (0 for the first sector)
  2146                              <1> 	; edx = FDT0 address
  2147                              <1> 		; 64 KB buffer = 128 sectors (limit) 
  2148                              <1> 	;mov	ecx, 128 ; maximum count of sectors (before eof) 
  2149                              <1> 	; 25/07/2022
  2150 0000CC62 29C9                <1> 	sub	ecx, ecx
  2151 0000CC64 B180                <1> 	mov	cl, 128
  2152                              <1> 	;call	write_fs_sectors
  2153                              <1> 	;retn
  2154                              <1> 	;jmp	short write_fs_sectors
  2155                              <1> 
  2156                              <1> write_fs_sectors:
  2157                              <1> 	; 21/03/2016 (TRDOS 386 = TRDOS v2.0)
  2158 0000CC66 F9                  <1> 	stc
  2159 0000CC67 C3                  <1> 	retn
  2160                              <1> 
  2161                              <1> get_cluster_by_index:
  2162                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
  2163                              <1> 	; 29/04/2016 (TRDOS 386 = TRDOS v2.0)
  2164                              <1> 	; INPUT ->
  2165                              <1> 	; 	EAX = Beginning cluster
  2166                              <1> 	; 	EDX = Sector index in disk/file section
  2167                              <1> 	;	      (Only for SINGLIX file system!)
  2168                              <1> 	; 	ECX = Cluster sequence number after the beginning cluster
  2169                              <1> 	; 	ESI = Logical DOS Drive Description Table address
  2170                              <1> 	; OUTPUT ->
  2171                              <1> 	;	EAX = Cluster number 
  2172                              <1> 	;	cf = 1 -> Error code in AL (EAX)
  2173                              <1> 	;
  2174                              <1> 	;(Modified registers: EAX, ECX, EBX, EDX)
  2175                              <1> 	;	
  2176 0000CC68 807E0301            <1> 	cmp	byte [esi+LD_FATType], 1
  2177 0000CC6C 721D                <1>         jb      short get_fs_section_by_index 
  2178                              <1> 
  2179 0000CC6E 3B4E78              <1> 	cmp	ecx, [esi+LD_Clusters]
  2180 0000CC71 7206                <1> 	jb	short gcbi_1
  2181                              <1> gcbi_0:
  2182                              <1> 	;stc
  2183                              <1> 	;mov	eax, 23h ; Cluster not available ! 
  2184                              <1> 			 ; MSDOS error code: FCB unavailable
  2185                              <1> 	; 25/07/2022
  2186 0000CC73 29C0                <1> 	sub	eax, eax
  2187                              <1> gcbi_4:
  2188 0000CC75 B023                <1> 	mov	al, 23h
  2189 0000CC77 F9                  <1> 	stc
  2190 0000CC78 C3                  <1> 	retn
  2191                              <1> gcbi_1:
  2192 0000CC79 51                  <1> 	push	ecx
  2193 0000CC7A E8A1F6FFFF          <1> 	call	get_next_cluster
  2194 0000CC7F 59                  <1> 	pop	ecx
  2195 0000CC80 7203                <1> 	jc	short gcbi_3
  2196 0000CC82 E2F5                <1> 	loop	gcbi_1
  2197                              <1> gcbi_2:
  2198 0000CC84 C3                  <1> 	retn
  2199                              <1> gcbi_3:
  2200 0000CC85 09C0                <1> 	or	eax, eax
  2201                              <1> 	;jz	short gcbi_0
  2202                              <1> 	; 25/07/2022
  2203 0000CC87 74EC                <1> 	jz	short gcbi_4
  2204 0000CC89 F5                  <1> 	cmc 	; stc
  2205 0000CC8A C3                  <1> 	retn
  2206                              <1> 
  2207                              <1> get_fs_section_by_index:
  2208                              <1> 	; 29/04/2016 (TRDOS 386 = TRDOS v2.0)
  2209                              <1> 	; INPUT ->
  2210                              <1> 	; 	EAX = Beginning FDT number/address
  2211                              <1> 	; 	EDX = Sector index in disk/file section
  2212                              <1> 	; 	ECX = Sector sequence number after the beginning FDT
  2213                              <1> 	; 	ESI = Logical DOS Drive Description Table address
  2214                              <1> 	; OUTPUT ->
  2215                              <1> 	; 	EAX = FDT number/address
  2216                              <1> 	; 	EDX = Sector index of the section (0,1,2,3,4...)
  2217                              <1> 	;	cf = 1 -> Error code in AL (EAX)
  2218                              <1> 	;
  2219                              <1> 	;(Modified registers: EAX, ECX, EBX, EDX)
  2220                              <1> 	;
  2221 0000CC8B B8FFFFFFFF          <1> 	mov	eax, 0FFFFFFFFh
  2222 0000CC90 C3                  <1> 	retn
  2223                              <1> 
  2224                              <1> get_last_section:
  2225                              <1> 	; 22/10/2016 (TRDOS 386 = TRDOS v2.0)	
  2226                              <1> 	; INPUT ->
  2227                              <1> 	; 	EAX = (The 1st) FDT number/address
  2228                              <1> 	; 	ESI = Logical DOS Drive Description Table address
  2229                              <1> 	; OUTPUT ->
  2230                              <1> 	; 	EAX = FDT number/address of the last section
  2231                              <1> 	; 	EDX = Last sector of the section (0,1,2,3,4...)
  2232                              <1> 	;	[glc_index] = sector index number of the last sector
  2233                              <1> 	;		      (for file, not for the last section)  	
  2234                              <1> 	;		   	
  2235                              <1> 	;	cf = 1 -> Error code in AL (EAX)
  2236                              <1> 	;
  2237                              <1> 	;(Modified registers: EAX, ECX, EBX, EDX)
  2238                              <1> 	;
  2239 0000CC91 B800000000          <1> 	mov	eax, 0
  2240 0000CC96 BA00000000          <1> 	mov	edx, 0
  2241 0000CC9B C3                  <1> 	retn
  3435                                  %include 'trdosk6.s' ; 24/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.9) - MAIN PROGRAM : trdosk6.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 27/09/2024  (Previous: 29/08/2023)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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> ; Ref: Retro UNIX 386 v1.2 Kernel (v0.2.2.3) - ux.s - 15/07/2022
    19                              <1> 
    20                              <1> sysent: ; < enter to system call >
    21                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
    22                              <1> 	; 17/03/2017
    23                              <1> 	; 03/03/2017
    24                              <1> 	; 19/02/2017
    25                              <1> 	; 13/01/2017
    26                              <1> 	; 06/06/2016
    27                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
    28                              <1> 	; 16/04/2015 - 19/10/2015 (Retro UNIX 386 v1)
    29                              <1> 	; 10/04/2013 - 18/01/2014 (Retro UNIX 8086 v1)
    30                              <1> 	;
    31                              <1> 	; 'unkni' or 'sysent' is sytem entry from various traps. 
    32                              <1> 	; The trap type is determined and an indirect jump is made to 
    33                              <1> 	; the appropriate system call handler. If there is a trap inside
    34                              <1> 	; the system a jump to panic is made. All user registers are saved
    35                              <1> 	; and u.sp points to the end of the users stack. The sys (trap)
    36                              <1> 	; instructor is decoded to get the the system code part (see
    37                              <1> 	; trap instruction in the PDP-11 handbook) and from this
    38                              <1> 	; the indirect jump address is calculated. If a bad system call is
    39                              <1> 	; made, i.e., the limits of the jump table are exceeded, 'badsys'
    40                              <1> 	; is called. If the call is legitimate control passes to the
    41                              <1> 	; appropriate system routine.
    42                              <1> 	;
    43                              <1> 	; Calling sequence:
    44                              <1> 	;	Through a trap caused by any sys call outside the system.
    45                              <1> 	; Arguments:
    46                              <1> 	;	Arguments of particular system call.
    47                              <1> 	; ...............................................................
    48                              <1> 	;
    49                              <1> 	; Retro UNIX 8086 v1 modification: 
    50                              <1> 	;       System call number is in EAX register.
    51                              <1> 	;
    52                              <1> 	;       Other parameters are in EDX, EBX, ECX, ESI, EDI, EBP
    53                              <1> 	;	registers depending of function details.
    54                              <1>   	;
    55                              <1> 	; 16/04/2015
    56 0000CC9C 368925[6C940100]    <1>         mov     [ss:u.sp], esp ; Kernel stack points to return address
    57                              <1> 
    58                              <1> 	; save user registers
    59 0000CCA3 1E                  <1> 	push	ds
    60 0000CCA4 06                  <1> 	push	es
    61 0000CCA5 0FA0                <1> 	push	fs
    62 0000CCA7 0FA8                <1> 	push	gs
    63 0000CCA9 60                  <1> 	pushad  ; eax, ecx, edx, ebx, esp -before pushad-, ebp, esi, edi
    64                              <1> 	;
    65                              <1> 	; ESPACE = [ss:u.sp] - esp ; 4*12 = 48 ; 17/09/2015 ; 06/06/2016
    66                              <1> 	; 	(ESPACE is size of space in kernel stack 
    67                              <1> 	;	for saving/restoring user registers.)
    68                              <1> 	;
    69 0000CCAA 50                  <1> 	push	eax ; 01/07/2015
    70 0000CCAB 66B81000            <1> 	mov     ax, KDATA
    71 0000CCAF 8ED8                <1>         mov     ds, ax
    72 0000CCB1 8EC0                <1>         mov     es, ax
    73 0000CCB3 8EE0                <1>         mov     fs, ax
    74 0000CCB5 8EE8                <1>         mov     gs, ax
    75 0000CCB7 A1[C07C0100]        <1> 	mov	eax, [k_page_dir]
    76 0000CCBC 0F22D8              <1> 	mov	cr3, eax
    77 0000CCBF 58                  <1> 	pop	eax ; 01/07/2015
    78                              <1> 	; 19/10/2015
    79 0000CCC0 FC                  <1> 	cld
    80                              <1> 	;
    81 0000CCC1 FE05[68940100]      <1> 	inc	byte [sysflg]
    82                              <1> 		; incb sysflg / indicate a system routine is in progress
    83 0000CCC7 FB                  <1>         sti 	; 18/01/2014
    84                              <1> 	;jnz	panic ; 24/05/2013
    85                              <1> 		; beq 1f
    86                              <1> 		; jmp panic ; / called if trap inside system
    87                              <1> 	; 23/07/2022
    88 0000CCC8 7405                <1> 	jz	short sysent0
    89 0000CCCA E9FAA0FFFF          <1> 	jmp	panic
    90                              <1> ;1:
    91                              <1> sysent0:
    92                              <1> 	; 17/03/2017
    93 0000CCCF 80642438FE          <1> 	and	byte [esp+ESPACE+8], ~1 ; clear carry flag
    94                              <1> 
    95                              <1> 	; 16/04/2015
    96 0000CCD4 A3[74940100]        <1> 	mov	[u.r0], eax
    97 0000CCD9 8925[70940100]      <1> 	mov	[u.usp], esp ; kernel stack points to user's registers
    98                              <1> 
    99                              <1> 	; 13/01/2017 (TRDOS 386 Feaure only !)
   100 0000CCDF 803D[EC940100]00    <1> 	cmp	byte [u.t_lock], 0 ; timer interrupt lock ?
   101                              <1> 	;ja	sysrele		   ; yes, sys release only !!!
   102                              <1> 	; 23/07/2022
   103 0000CCE6 7605                <1> 	jna	short sysent1
   104 0000CCE8 E902020000          <1> 	jmp	sysrele
   105                              <1> 		; mov $s.syst+2,clockp
   106                              <1> 		; mov r0,-(sp) / save user registers 
   107                              <1> 		; mov sp,u.r0 / pointer to bottom of users stack
   108                              <1> 			   ; / in u.r0
   109                              <1> 		; mov r1,-(sp)
   110                              <1> 		; mov r2,-(sp)
   111                              <1> 		; mov r3,-(sp)
   112                              <1> 		; mov r4,-(sp)
   113                              <1> 		; mov r5,-(sp)
   114                              <1> 		; mov ac,-(sp) / "accumulator" register for extended
   115                              <1> 		             ; / arithmetic unit
   116                              <1> 		; mov mq,-(sp) / "multiplier quotient" register for the
   117                              <1> 		             ; / extended arithmetic unit
   118                              <1> 		; mov sc,-(sp) / "step count" register for the extended
   119                              <1> 		             ; / arithmetic unit
   120                              <1> 		; mov sp,u.sp / u.sp points to top of users stack
   121                              <1> 		; mov 18.(sp),r0 / store pc in r0
   122                              <1> 		; mov -(r0),r0 / sys inst in r0
   123                              <1> 		; sub $sys,r0 / get xxx code
   124                              <1> sysent1:
   125 0000CCED C1E002              <1> 	shl	eax, 2
   126                              <1> 		; asl r0 / multiply by 2 to jump indirect in bytes
   127 0000CCF0 3DBC000000          <1> 	cmp	eax, end_of_syscalls - syscalls
   128                              <1> 		; cmp r0,$2f-1f / limit of table (35) exceeded
   129                              <1> 	;jnb	short badsys
   130                              <1> 		; bhis badsys / yes, bad system call
   131 0000CCF5 F5                  <1> 	cmc
   132 0000CCF6 9C                  <1> 	pushf
   133 0000CCF7 50                  <1> 	push	eax
   134 0000CCF8 8B2D[6C940100]      <1>  	mov 	ebp, [u.sp] ; Kernel stack at the beginning of sys call
   135 0000CCFE B0FE                <1> 	mov	al, 0FEh ; 11111110b
   136 0000CD00 1400                <1> 	adc	al, 0 ; al = al + cf
   137 0000CD02 204508              <1> 	and	[ebp+8], al ; flags (reset carry flag)
   138                              <1> 		; bic $341,20.(sp) / set users processor priority to 0
   139                              <1> 				 ; / and clear carry bit
   140 0000CD05 5D                  <1> 	pop	ebp ; eax
   141 0000CD06 9D                  <1> 	popf
   142 0000CD07 720B                <1>         jc      short badsys ; 23/07/2022
   143 0000CD09 A1[74940100]        <1> 	mov	eax, [u.r0]
   144                              <1> 	; system call registers: EAX, EDX, ECX, EBX, ESI, EDI
   145 0000CD0E FFA5[61CD0000]      <1> 	jmp	dword [ebp+syscalls]
   146                              <1> 		; jmp *1f(r0) / jump indirect thru table of addresses
   147                              <1> 		            ; / to proper system routine.
   148                              <1> 
   149                              <1> 	; 20/08/2024 (exit code)
   150                              <1> 	; 30/07/2022
   151                              <1> 	; 23/07/2022
   152                              <1> badsys:
   153                              <1> 	; 25/12/2016
   154                              <1> 	; 18/04/2016 (TRDOS 386 = TRDOS v2.0)
   155                              <1> 	; 17/04/2011 (TRDOS v1.0, 'IFC.ASM')
   156                              <1> 	; 03/02/2011 ('trdos_ifc_routine')
   157                              <1> 	;
   158                              <1> 	; 16/04/2015 (Retro UNIX 386 v1, 'badsys')
   159                              <1> 	; (EIP, EAX values will be shown on screen with error message)
   160                              <1> 	; (EIP = 'CD 40h' instruction address -INT 40h-)
   161                              <1> 	; (EAX = Function number)  
   162                              <1> 	;
   163 0000CD14 FE05[C4940100]      <1> 	inc	byte [u.bsys]
   164                              <1> 	;
   165 0000CD1A 8B1D[6C940100]      <1> 	mov	ebx, [u.sp] ; esp at the beginning of 'sysent'
   166 0000CD20 8B03                <1> 	mov	eax, [ebx] ; EIP (return address, not 'INT 30h' address)
   167                              <1> 	;sub	eax, 2 ; CDh, ##h
   168                              <1> 	; 30/07/2022
   169 0000CD22 48                  <1> 	dec	eax
   170 0000CD23 48                  <1> 	dec	eax
   171 0000CD24 E88C74FFFF          <1> 	call	dwordtohex
   172 0000CD29 8915[B13B0100]      <1> 	mov	[eip_str], edx
   173 0000CD2F A3[B53B0100]        <1> 	mov	[eip_str+4], eax
   174 0000CD34 A1[74940100]        <1> 	mov	eax, [u.r0]
   175 0000CD39 E87774FFFF          <1> 	call	dwordtohex
   176 0000CD3E 8915[A03B0100]      <1> 	mov	[eax_str], edx
   177 0000CD44 A3[A43B0100]        <1> 	mov	[eax_str+4], eax
   178                              <1> 
   179 0000CD49 66C705[953B0100]34- <1> 	mov	word [int_num_str], SYSCALL_INT_NUM ; 25/12/2016
   179 0000CD51 30                  <1>
   180                              <1> 
   181 0000CD52 BE[673B0100]        <1> 	mov	esi, ifc_msg ; "invalid function call !" msg (trdosk9.s)
   182                              <1> 
   183 0000CD57 E80EA0FFFF          <1> 	call	print_msg
   184                              <1> 
   185                              <1> ;; 20/08/2024 - temporary
   186                              <1> ;	mov	ebx, 07h
   187                              <1> ;	mov	ah, 0Eh
   188                              <1> ;p_fc_msg:
   189                              <1> ;	lodsb
   190                              <1> ;	and	al, al
   191                              <1> ;	jz	short p_fc_ms_ok
   192                              <1> ;	call	_int10h
   193                              <1> ;	jmp	short p_fc_msg
   194                              <1> ;p_fc_ms_ok:
   195                              <1> 
   196                              <1> 	;jmp	sysexit
   197                              <1> 
   198                              <1> 	; 20/08/2024 (exit code)
   199                              <1> 	;mov	bl, 0FFh ; -1
   200                              <1> 	;jmp	sysexit
   201                              <1> 	;
   202 0000CD5C E92C020000          <1> 	jmp	sysexit_0FFh
   203                              <1> 
   204                              <1> syscalls: ; 1:
   205                              <1> 	; 20/08/2024 - TRDOS 386 v2.0.9
   206                              <1> 	; 31/12/2017
   207                              <1> 	; 28/02/2017
   208                              <1> 	; 20/02/2017
   209                              <1> 	; 19/02/2017
   210                              <1> 	; 15/10/2016
   211                              <1> 	; 20/05/2016
   212                              <1> 	; 19/05/2016
   213                              <1> 	; 16/05/2016
   214                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   215                              <1> 	; 21/09/2015
   216                              <1> 	; 01/07/2015
   217                              <1> 	; 16/04/2015 (32 bit address modification) 
   218 0000CD61 [DC0E0100]          <1> 	dd sysver	; 0 ; Get TRDOS 386 version number (v2.0)
   219 0000CD65 [92CF0000]          <1> 	dd sysexit 	; 1
   220 0000CD69 [BBD10000]          <1> 	dd sysfork 	; 2
   221 0000CD6D [91D50000]          <1> 	dd sysread 	; 3
   222 0000CD71 [B0D50000]          <1> 	dd syswrite 	; 4
   223 0000CD75 [A5D30000]          <1> 	dd sysopen 	; 5
   224 0000CD79 [67D50000]          <1> 	dd sysclose 	; 6
   225 0000CD7D [1FD10000]          <1> 	dd syswait 	; 7
   226 0000CD81 [C8D20000]          <1> 	dd syscreat 	; 8
   227 0000CD85 [541D0100]          <1> 	dd sysrename	; 9  ; TRDOS 386, Rename File (31/12/2017)
   228 0000CD89 [E1180100]          <1> 	dd sysdelete	; 10 ; TRDOS 386, Delete File (29/12/2017)
   229 0000CD8D [E1020100]          <1> 	dd sysexec 	; 11
   230 0000CD91 [FD190100]          <1> 	dd syschdir 	; 12
   231 0000CD95 [BE1B0100]          <1> 	dd systime 	; 13 ; TRDOS 386, Get Sys Date&Time (30/12/2017)
   232 0000CD99 [2AD50000]          <1> 	dd sysmkdir 	; 14
   233 0000CD9D [311A0100]          <1> 	dd syschmod 	; 15 ; TRDOS 386, Change Attributes (30/12/2017)
   234 0000CDA1 [48190100]          <1> 	dd sysrmdir 	; 16 ; TRDOS 386, Remove Directory (29/12/2017)
   235 0000CDA5 [77070100]          <1> 	dd sysbreak 	; 17
   236 0000CDA9 [131B0100]          <1> 	dd sysdrive 	; 18 ; TRDOS 386, Get/Set Current Drv (30/12/2017)
   237 0000CDAD [E6070100]          <1> 	dd sysseek 	; 19
   238 0000CDB1 [F8070100]          <1> 	dd systell 	; 20
   239 0000CDB5 [6A1E0100]          <1> 	dd sysmem 	; 21 ; TRDOS 386, Get Total&Free Mem (31/12/2017)
   240 0000CDB9 [A01E0100]          <1> 	dd sysprompt 	; 22 ; TRDOS 386, Change Cmd Prompt (31/12/2017)
   241 0000CDBD [E11E0100]          <1> 	dd syspath 	; 23 ; TRDOS 386, Get/Set Run Path (31/12/2017)
   242 0000CDC1 [461F0100]          <1> 	dd sysenv 	; 24 ; TRDOS 386, Get/Set Env Vars (31/12/2017)
   243 0000CDC5 [3F1C0100]          <1> 	dd sysstime 	; 25 ; TRDOS 386, Set Sys Date&Time (30/12/2017)
   244 0000CDC9 [69080100]          <1> 	dd sysquit 	; 26
   245 0000CDCD [52080100]          <1> 	dd sysintr 	; 27
   246 0000CDD1 [621B0100]          <1> 	dd sysdir 	; 28 ; TRDOS 386, Get Curr Drive&Dir (30/12/2017)
   247 0000CDD5 [1DCE0000]          <1> 	dd sysemt 	; 29
   248 0000CDD9 [9D1B0100]          <1> 	dd sysldrvt	; 30 ; TRDOS 386, Get Logical DOS DDT (30/12/2017)
   249 0000CDDD [B5D70000]          <1> 	dd sysvideo 	; 31 ; TRDOS 386 Video Functions (16/05/2016)
   250 0000CDE1 [6F260100]          <1> 	dd sysaudio 	; 32 ; TRDOS 386 Audio Functions (16/05/2016)
   251 0000CDE5 [20D60000]          <1> 	dd systimer 	; 33 ; TRDOS 386 Timer Functions (18/05/2016)
   252 0000CDE9 [85080100]          <1> 	dd syssleep 	; 34 ; Retro UNIX 8086 v1 feature only !
   253                              <1> 			     ; 11/06/2014
   254 0000CDED [C5080100]          <1> 	dd sysmsg	; 35 ; Retro UNIX 386 v1 feature only !
   255                              <1> 			     ; 01/07/2015
   256 0000CDF1 [E0090100]          <1> 	dd sysgeterr	; 36 ; Retro UNIX 386 v1 feature only !
   257                              <1> 			     ; 21/09/2015 - get last error number
   258 0000CDF5 [B8180100]          <1> 	dd sysfpstat	; 37 ; TRDOS 386 FPU state option (28/02/2017)
   259 0000CDF9 [EB0E0100]          <1> 	dd syspri 	; 38 ; change priority - TRDOS 386 (20/05/2016)
   260 0000CDFD [EFCE0000]          <1> 	dd sysrele	; 39 ; TRDOS 386 (19/05/2016) (0 -> 39)
   261 0000CE01 [16100100]          <1> 	dd sysfff	; 40 ; Find First File - TRDOS 386 (15/10/2016)
   262 0000CE05 [F0100100]          <1> 	dd sysfnf	; 41 ; Find Next File - TRDOS 386 (15/10/2016)
   263 0000CE09 [A6170100]          <1> 	dd sysalloc	; 42 ; Allocate contiguous memory block/pages
   264                              <1> 			     ; TRDOS 386 (19/02/2017) DMA buff fuctions
   265 0000CE0D [60180100]          <1> 	dd sysdalloc	; 43 ; Deallocate contiguous memory block/pages
   266                              <1> 			     ; TRDOS 386 (19/02/2017) DMA buff fuctions
   267 0000CE11 [9B180100]          <1> 	dd syscalbac	; 44 ; IRQ Callback and Signal Response Byte
   268                              <1> 			     ; service setup - TRDOS 386 (20/02/2017)
   269                              <1> 			     ; 28/08/2017 (20/08/2017)
   270 0000CE15 [502F0100]          <1> 	dd sysdma	; 45 ; TRDOS 386 - (ISA) DMA service
   271 0000CE19 [8C320100]          <1> 	dd sysstdio	; 46 ; TRDOS 386 v2.0.9 (STDIN/STDOUT functions)
   272                              <1> 
   273                              <1> end_of_syscalls:
   274                              <1> 
   275                              <1> sysemt: ; enable (or disable) multi tasking -time sharing-
   276                              <1> 	;
   277                              <1> 	; 08/08/2022
   278                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
   279                              <1> 	; 23/05/2016 - TRDOS 386 (TRDOS v2.0)
   280                              <1> 	; 14/05/2015 (Retro UNIX 386 v1)
   281                              <1> 	; 10/12/2013 - 20/04/2014 (Retro UNIX 8086 v1)
   282                              <1> 	;
   283                              <1> 	; Retro UNIX 8086 v1 modification:
   284                              <1> 	;	'Enable Multi Tasking'  system call instead
   285                              <1> 	;	of 'Emulator Trap' in original UNIX v1 for PDP-11.
   286                              <1> 	;
   287                              <1> 	; Retro UNIX 8086 v1 feature only!
   288                              <1> 	;	Using purpose: Kernel will start without time-out
   289                              <1> 	;	(internal clock/timer) functionality.
   290                              <1> 	;	Then etc/init will enable clock/timer for
   291                              <1> 	;	multi tasking.
   292                              <1> 	;
   293                              <1> 	; INPUT ->
   294                              <1> 	;	BL = 0 -> disable multi tasking
   295                              <1> 	;	BL > 1 -> enable multi tasking (time sharing)
   296                              <1> 	; OUTPUT ->
   297                              <1> 	;	none
   298                              <1> 	;
   299                              <1> 	;  Note: Multi tasking is disabled during system
   300                              <1> 	;	 initialization, it must be enabled by using
   301                              <1> 	;	 this system call. (Otherwise, running proces 
   302                              <1> 	;	 will not be changed by another process within
   303                              <1> 	;	 run time sequence/schedule, if running process
   304                              <1> 	;	 will not 'release' itself. Only 'wakeup' procedure
   305                              <1> 	;	 for waiting processes and programmed timer events
   306                              <1> 	;	 for other processes can change running process 
   307                              <1> 	;	 while multi tasking is disabled.) ** 23/05/2016 **
   308                              <1> 
   309 0000CE1D 803D[C6940100]00    <1> 	cmp	byte [u.uid], 0 ; root ?
   310                              <1> 	;ja	short error
   311                              <1> 	; 23/07/2022
   312                              <1> 	;ja	short badsys ; 14/05/2015
   313                              <1> 	; 08/08/2022
   314 0000CE24 7605                <1> 	jna	short sysemt_root
   315 0000CE26 E9E9FEFFFF          <1> 	jmp	badsys
   316                              <1> sysemt_root:	; 08/08/2022
   317 0000CE2B FA                  <1> 	cli
   318 0000CE2C 881D[4E890100]      <1> 	mov	[multi_tasking], bl ; 0 to disable, >0 to enable
   319 0000CE32 EB20                <1> 	jmp	sysret
   320                              <1> 
   321                              <1> error:
   322                              <1> 	; 18/05/2016
   323                              <1> 	; 13/05/2016
   324                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   325                              <1> 	; 16/04/2015 - 17/09/2015 (Retro UNIX 386 v1)
   326                              <1> 	; 10/04/2013 - 07/08/2013 (Retro UNIX 8086 v1)
   327                              <1> 	;
   328                              <1> 	; 'error' merely sets the error bit off the processor status (c-bit)
   329                              <1> 	; then falls right into the 'sysret', 'sysrele' return sequence.
   330                              <1> 	;
   331                              <1> 	; INPUTS -> none
   332                              <1> 	; OUTPUTS ->
   333                              <1> 	;	processor status - carry (c) bit is set (means error)
   334                              <1> 	;
   335                              <1> 	; 26/05/2013 (Stack pointer must be reset here!
   336                              <1> 	; 	      Because, jumps to error procedure
   337                              <1> 	;	      disrupts push-pop nesting balance)
   338                              <1> 	;
   339 0000CE34 8B2D[6C940100]      <1> 	mov	ebp, [u.sp] ; interrupt (system call) return (iretd) address
   340 0000CE3A 804D0801            <1> 	or	byte [ebp+8], 1  ; set carry bit of flags register
   341                              <1> 				 ; (system call will return with cf = 1)
   342                              <1> 		; bis $1,20.(r1) / set c bit in processor status word below
   343                              <1> 		               ; / users stack
   344                              <1> 	; 17/09/2015
   345 0000CE3E 83ED30              <1> 	sub	ebp, ESPACE ; 48 ; total size of stack frame ('sysdefs.inc')
   346                              <1> 				 ; for saving/restoring user registers
   347                              <1> 	;cmp	ebp, [u.usp]
   348                              <1> 	;je	short err0
   349 0000CE41 892D[70940100]      <1> 	mov	[u.usp], ebp
   350                              <1> ;err0:
   351                              <1> 	; 01/09/2015
   352 0000CE47 8B25[70940100]      <1> 	mov	esp, [u.usp] 	    ; Retro Unix 8086 v1 modification!
   353                              <1> 				    ; 10/04/2013
   354                              <1> 				    ; (If an I/O error occurs during disk I/O,
   355                              <1> 				    ; related procedures will jump to 'error'
   356                              <1> 				    ; procedure directly without returning to
   357                              <1> 				    ; the caller procedure. So, stack pointer
   358                              <1>                                     ; must be restored here.)
   359                              <1> 	; 13/05/2016
   360                              <1> 	; NOTE: (The last) error code is in 'u.error', it can be retrieved by
   361                              <1> 	;	'get last error' system call later.
   362                              <1> 
   363                              <1> 	; 03/09/2015 - 09/06/2015 - 07/08/2013
   364 0000CE4D C605[DA940100]00    <1> 	mov 	byte [u.kcall], 0 ; namei_r, mkdir_w reset
   365                              <1> 
   366                              <1> sysret: ; < return from system call>
   367                              <1> 	; 28/08/2024 - TRDOS 386 Kernel v2.0.9
   368                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
   369                              <1> 	; 01/03/2017
   370                              <1> 	; 28/02/2017
   371                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   372                              <1> 	; 16/04/2015 - 10/09/2015 (Retro UNIX 386 v1)
   373                              <1> 	; 10/04/2013 - 23/02/2014 (Retro UNIX 8086 v1)
   374                              <1> 	;
   375                              <1> 	; 'sysret' first checks to see if process is about to be
   376                              <1> 	; terminated (u.bsys). If it is, 'sysexit' is called.
   377                              <1> 	; If not, following happens:
   378                              <1> 	; 	1) The user's stack pointer is restored.
   379                              <1> 	;	2) r1=0 and 'iget' is called to see if last mentioned
   380                              <1> 	;	   i-node has been modified. If it has, it is written out
   381                              <1> 	;	   via 'ppoke'.
   382                              <1> 	;	3) If the super block has been modified, it is written out
   383                              <1> 	;	   via 'ppoke'.
   384                              <1> 	;	4) If the dismountable file system's super block has been
   385                              <1> 	;	   modified, it is written out to the specified device
   386                              <1> 	;	   via 'ppoke'.
   387                              <1> 	;	5) A check is made if user's time quantum (uquant) ran out
   388                              <1> 	;	   during his execution. If so, 'tswap' is called to give
   389                              <1> 	;	   another user a chance to run.
   390                              <1> 	;	6) 'sysret' now goes into 'sysrele'.
   391                              <1> 	;	    (See 'sysrele' for conclusion.)
   392                              <1> 	;
   393                              <1> 	; Calling sequence:
   394                              <1> 	;	jump table or 'br sysret'
   395                              <1> 	; Arguments: 
   396                              <1> 	;	-
   397                              <1> 	; ...............................................................
   398                              <1> 	;
   399                              <1> 	; ((AX=r1 for 'iget' input))
   400                              <1> 	;
   401 0000CE54 31C0                <1> 	xor	eax, eax ; 28/02/2017
   402                              <1> sysret0: ; 29/07/2015 (eax = 0, jump from sysexec)
   403 0000CE56 FEC0                <1> 	inc	al ; 04/05/2013
   404 0000CE58 3805[C4940100]      <1> 	cmp	[u.bsys], al ; 1
   405                              <1> 		; tstb u.bsys / is a process about to be terminated because
   406                              <1>         ;jnb	sysexit ; 04/05/2013
   407                              <1> 		; bne sysexit / of an error? yes, go to sysexit
   408                              <1> 	; 23/07/2022
   409 0000CE5E 7205                <1> 	jb	short sysret1
   410                              <1> 	;jmp	sysexit
   411                              <1> 	; 22/08/2024
   412 0000CE60 E92B010000          <1> 	jmp	sysexit_@ ; BL = 0FFh ; -1
   413                              <1> sysret1:	; 23/07/2022
   414                              <1> 	;mov	esp, [u.usp] ; 24/05/2013 (that is not needed here)
   415                              <1> 		; mov u.sp,sp / no point stack to users stack
   416 0000CE65 FEC8                <1> 	dec 	al ; mov ax, 0
   417                              <1> 		; clr r1 / zero r1 to check last mentioned i-node
   418 0000CE67 E884510000          <1> 	call	iget
   419                              <1> 		; jsr r0,iget / if last mentioned i-node has been modified
   420                              <1> 		            ; / it is written out
   421                              <1> 	; 10/01/2017
   422                              <1> 	; 09/01/2017
   423                              <1> ;sysrele: ; < release >
   424                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   425                              <1> 	; 16/04/2015 - 14/10/2015 (Retro UNIX 386 v1)
   426                              <1> 	; 10/04/2013 - 07/03/2014 (Retro UNIX 8086 v1)
   427                              <1> 	;
   428                              <1> 	; 'sysrele' first calls 'tswap' if the time quantum for a user is
   429                              <1> 	;  zero (see 'sysret'). It then restores the user's registers and
   430                              <1> 	; turns off the system flag. It then checked to see if there is
   431                              <1> 	; an interrupt from the user by calling 'isintr'. If there is,
   432                              <1> 	; the output gets flashed (see isintr) and interrupt action is
   433                              <1> 	; taken by a branch to 'intract'. If there is no interrupt from
   434                              <1> 	; the user, a rti is made.
   435                              <1> 	;
   436                              <1> 	; Calling sequence:
   437                              <1> 	;	Fall through a 'bne' in 'sysret' & ?
   438                              <1> 	; Arguments:
   439                              <1> 	;	-
   440                              <1> 	; ...............................................................
   441                              <1> 	;
   442                              <1> 	; 23/02/2014 (swapret)
   443                              <1> 	; 22/09/2013
   444                              <1> sysrel0: ;1:
   445 0000CE6C 803D[BC940100]00    <1> 	cmp	byte [u.quant], 0 ; 16/05/2013
   446                              <1> 		; tstb uquant / is the time quantum 0?
   447 0000CE73 7705                <1>         ja      short swapret
   448                              <1> 		; bne 1f / no, don't swap it out
   449                              <1> sysrelease: ; 07/12/2013 (jump from 'clock')
   450 0000CE75 E82B3F0000          <1> 	call	tswap
   451                              <1> 		; jsr r0,tswap / yes, swap it out
   452                              <1> 
   453                              <1> ; Retro Unix 8086 v1 feature: return from 'swap' to 'swapret' address.
   454                              <1> swapret: ;1:
   455                              <1> 	; 10/09/2015
   456                              <1> 	; 01/09/2015
   457                              <1> 	; 14/05/2015
   458                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - 32 bit, pm modifications)
   459                              <1> 	; 26/05/2013 (Retro UNIX 8086 v1)
   460                              <1> 	; cli
   461                              <1> 	; 24/07/2015
   462                              <1> 	;
   463                              <1> 	;; 'esp' must be already equal to '[u.usp]' here !
   464                              <1> 	;; mov	esp, [u.usp]
   465                              <1> 
   466                              <1> 	; 22/09/2013
   467 0000CE7A E869510000          <1> 	call	isintr
   468                              <1> 	; 20/10/2013
   469 0000CE7F 7405                <1> 	jz	short sysrel1
   470 0000CE81 E8F4000000          <1> 	call	intract
   471                              <1> 		; jsr r0,isintr / is there an interrupt from the user
   472                              <1> 		;     br intract / yes, output gets flushed, take interrupt
   473                              <1> 		               ; / action
   474                              <1> sysrel1:
   475 0000CE86 FA                  <1> 	cli	; 14/10/2015
   476                              <1> sysrel2:
   477                              <1> 	; 28/02/2017
   478                              <1> 	; Check if there is a (delayed) callback for current user/process
   479 0000CE87 A0[EF940100]        <1> 	mov	al, [u.irqwait]
   480 0000CE8C 240F                <1> 	and	al, 0Fh ; is there a waiting IRQ callback service ?
   481 0000CE8E 7444                <1> 	jz	short sysrel8 ; no
   482                              <1> 
   483                              <1> 	; Set return to IRQ callback service and return from the service
   484 0000CE90 0FB6D8              <1> 	movzx	ebx, al
   485 0000CE93 883D[EF940100]      <1> 	mov 	[u.irqwait], bh ; 0 ; reset
   486 0000CE99 8A9B[BE3B0100]      <1> 	mov	bl, [ebx+IRQenum] ; (available) IRQ index +1 (1 to 9)
   487                              <1> 	; 01/03/2017
   488 0000CE9F FECB                <1> 	dec	bl ; IRQ index number, 0 to 8
   489 0000CEA1 7831                <1> 	js	short sysrel8 ; 0 -> FFh (not in use!?) 
   490                              <1> 	;
   491 0000CEA3 A0[C5940100]        <1> 	mov 	al, [u.uno] ; current process (user) number 
   492 0000CEA8 3883[9C8E0100]      <1> 	cmp	[ebx+IRQ.owner], al
   493 0000CEAE 7524                <1> 	jne	short sysrel8 ; it is not the current user/process !?
   494 0000CEB0 F683[AE8E0100]01    <1> 	test	byte [ebx+IRQ.method], 1 ; callback ?
   495 0000CEB7 741B                <1> 	jz	short sysrel8 ; not a callback method !?
   496                              <1> 
   497 0000CEB9 8B93[C08E0100]      <1> 	mov	edx, [ebx+IRQ.addr] ; IRQ callback service address (virtual)
   498 0000CEBF C605[F0940100]01    <1> 	mov	byte [u.r_lock], 1 ; IRQ callback service in progress flag
   499                              <1> 
   500 0000CEC6 E8813F0000          <1> 	call	wswap ; save user's registers & status 
   501                              <1> 		      ;	(for return from IRQ callback service)
   502                              <1> 
   503 0000CECB 8B2D[6C940100]      <1> 	mov	ebp, [u.sp]; kernel's stack, points to EIP (user)
   504 0000CED1 895500              <1> 	mov	[ebp], edx ; IRQ call back service address
   505                              <1> sysrel8:
   506 0000CED4 FE0D[68940100]      <1> 	dec	byte [sysflg]
   507                              <1> 		; decb sysflg / turn system flag off
   508                              <1> 
   509 0000CEDA A1[CC940100]        <1> 	mov	eax, [u.pgdir]
   510 0000CEDF 0F22D8              <1> 	mov	cr3, eax  ; 1st PDE points to Kernel Page Table 0 (1st 4 MB)
   511                              <1> 			  ; (others are different than kernel page tables)
   512                              <1> 	; 10/09/2015
   513 0000CEE2 61                  <1> 	popad ; edi, esi, ebp, temp (icrement esp by 4), ebx, edx, ecx, eax
   514                              <1> 		; mov (sp)+,sc / restore user registers
   515                              <1> 		; mov (sp)+,mq
   516                              <1> 		; mov (sp)+,ac
   517                              <1> 		; mov (sp)+,r5
   518                              <1> 		; mov (sp)+,r4
   519                              <1> 		; mov (sp)+,r3
   520                              <1> 		; mov (sp)+,r2
   521                              <1> 	;
   522 0000CEE3 A1[74940100]        <1> 	mov	eax, [u.r0]  ; ((return value in EAX))
   523 0000CEE8 0FA9                <1> 	pop	gs
   524 0000CEEA 0FA1                <1> 	pop	fs
   525 0000CEEC 07                  <1> 	pop	es
   526 0000CEED 1F                  <1> 	pop	ds
   527                              <1> 	;or	word [esp+8], 200h ; 22/01/2017 ; force enabling interrupts
   528 0000CEEE CF                  <1> 	iretd
   529                              <1> 		; rti / no, return from interrupt
   530                              <1> 
   531                              <1> sysrele:
   532                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
   533                              <1> 	; 24/03/2017
   534                              <1> 	; 28/02/2017
   535                              <1> 	; 27/02/2017
   536                              <1> 	; 29/01/2017
   537                              <1> 	; 14/01/2017
   538                              <1> 	; 13/01/2017
   539                              <1> 	; 09/01/2017 - 10/01/2017 - 12/01/2017
   540                              <1> 	; Major modification for TRDOS 386 (CallBack return)
   541                              <1> 	;
   542                              <1> 	; 'sysrele' system call restores previously saved
   543                              <1> 	; registers and addresses of the process
   544                              <1> 	; (Main purpose -in TRDOS 386- is to return from
   545                              <1> 	; timer callback service routine in ring 3 -user mode-.)
   546                              <1> 	;
   547                              <1> 	; check if the process is in timer callback phase
   548 0000CEEF 803D[EC940100]00    <1> 	cmp	byte [u.t_lock], 0 ; TIMER INT LOCK
   549                              <1> 	;je	short sysrel0 ; classic (Retro UNIX 386 type) sysrele
   550 0000CEF6 7735                <1> 	ja	short sysrel3
   551                              <1> 	; 27/02/2017
   552 0000CEF8 803D[F0940100]00    <1> 	cmp	byte [u.r_lock], 0 ; IRQ callback lock	
   553                              <1> 	;jna	sysrel0 ; classic sysrele ; 24/03/2017
   554                              <1> 	; 23/07/2022
   555 0000CEFF 7705                <1> 	ja	short sysrel9
   556 0000CF01 E966FFFFFF          <1> 	jmp	sysrel0
   557                              <1> sysrel9:	; 23/07/2022
   558 0000CF06 E859000000          <1> 	call	sysrel7
   559 0000CF0B 803D[F0940100]00    <1> 	cmp	byte [u.r_lock], 0 ; IRQ callback service lock
   560 0000CF12 7628                <1> 	jna	short sysrel4
   561 0000CF14 C605[F0940100]00    <1> 	mov	byte [u.r_lock], 0 ; reset
   562                              <1> 	;mov	byte [u.irqwait], 0 ; reset ; 28/02/2017
   563 0000CF1B A0[F1940100]        <1> 	mov	al, [u.r_mode]
   564 0000CF20 08C0                <1> 	or	al, al
   565 0000CF22 7518                <1> 	jnz	short sysrel4
   566 0000CF24 FEC8                <1> 	dec	al
   567 0000CF26 A2[F1940100]        <1> 	mov	[u.r_mode], al ; 0FFh ; not necessary !?
   568 0000CF2B EB32                <1> 	jmp	short sysrel6
   569                              <1> sysrel3:
   570                              <1> 	; 27/02/2017
   571 0000CF2D E832000000          <1> 	call	sysrel7
   572                              <1> 	; 14/01/2017
   573 0000CF32 28C0                <1> 	sub	al, al
   574 0000CF34 3805[EC940100]      <1> 	cmp	[u.t_lock], al ; 0 ; TIMER INT LOCK
   575 0000CF3A 770E                <1> 	ja	short sysrel5 ; yes
   576                              <1> sysrel4:
   577                              <1> 	; 29/01/2017
   578 0000CF3C 8B44241C            <1> 	mov	eax, [esp+28] ; eax
   579 0000CF40 A3[74940100]        <1> 	mov	[u.r0], eax
   580 0000CF45 E93DFFFFFF          <1> 	jmp	sysrel2
   581                              <1> sysrel5:
   582 0000CF4A A2[EC940100]        <1> 	mov	[u.t_lock], al ; 0 ; reset
   583 0000CF4F A0[ED940100]        <1> 	mov	al, [u.t_mode]
   584 0000CF54 20C0                <1> 	and	al, al
   585                              <1> 	;jnz	short sysrel2 ; 0FFh ; user mode
   586 0000CF56 75E4                <1> 	jnz	short sysrel4 ; 29/01/2017
   587 0000CF58 FEC8                <1> 	dec	al
   588 0000CF5A A2[ED940100]        <1> 	mov	[u.t_mode], al ; 0FFh ; not necessary !?
   589                              <1> sysrel6:
   590                              <1> 	; cpu will continue from the interrupted sytem call addr
   591 0000CF5F 61                  <1> 	popad		; edi, esi, ebp, esp, ebx, edx, ecx, eax
   592 0000CF60 83C410              <1> 	add	esp, 16	; pass segment segisters: ds, es, fs, gs
   593 0000CF63 CF                  <1> 	iretd		; eip, cs, eflags
   594                              <1> 
   595                              <1> sysrel7:
   596 0000CF64 0FB61D[C5940100]    <1> 	movzx	ebx, byte [u.uno] ; current process number
   597                              <1> 	;shl	bx, 2
   598                              <1> 	; 23/07/2022
   599 0000CF6B C1E302              <1> 	shl	ebx, 2
   600                              <1> 	;cmp	[ebx+p.tcb-4], eax ; 0 ; is there callback address ?
   601                              <1> 	;jna	short sysrel0 
   602                              <1> 	; yes, reset callback address then restore process registers
   603                              <1> 	;mov	[ebx+p.tcb-4], eax ; 0 ; reset
   604 0000CF6E 8B83[B4930100]      <1> 	mov     eax, [ebx+p.upage-4] ; UPAGE address
   605 0000CF74 FA                  <1> 	cli	; disable interrupts till 'iretd'
   606 0000CF75 E90A3F0000          <1> 	jmp	rswap ; restore process 'u' structure
   607                              <1> 
   608                              <1> intract: ; / interrupt action
   609                              <1> 	; 14/10/2015
   610                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
   611                              <1> 	; 09/05/2013 - 07/12/2013 (Retro UNIX 8086 v1)
   612                              <1> 	;
   613                              <1> 	; Retro UNIX 8086 v1 modification !
   614                              <1> 	; (Process/task switching and quit routine by using
   615                              <1> 	; Retro UNIX 8086 v1 keyboard interrupt output.))
   616                              <1> 	;
   617                              <1> 	; input -> 'u.quit' (also value of 'u.intr' > 0)
   618                              <1> 	; output -> If value of 'u.quit' = FFFFh ('ctrl+brk' sign)
   619                              <1> 	;		'intract' will jump to 'sysexit'.
   620                              <1> 	;	    Intract will return to the caller
   621                              <1> 	;		if value of 'u.quit' <> FFFFh.
   622                              <1> 	; 14/10/2015
   623 0000CF7A FB                  <1> 	sti
   624                              <1> 	; 07/12/2013
   625 0000CF7B 66FF05[C2940100]    <1> 	inc 	word [u.quit]
   626 0000CF82 7408                <1> 	jz	short intrct0 ; FFFFh -> 0
   627 0000CF84 66FF0D[C2940100]    <1> 	dec	word [u.quit]
   628                              <1> 	; 16/04/2015
   629 0000CF8B C3                  <1> 	retn
   630                              <1> intrct0:
   631 0000CF8C 58                  <1> 	pop	eax ; call intract -> retn
   632                              <1> 	;
   633                              <1> 	; 20/08/2024
   634                              <1> 	;xor 	eax, eax
   635                              <1> 	;inc	al  ; mov ax, 1
   636                              <1> ;;;
   637                              <1> 	; UNIX v1 original 'intract' routine...
   638                              <1> 	; / interrupt action
   639                              <1> 		;cmp *(sp),$rti / are you in a clock interrupt?
   640                              <1> 		; bne 1f / no, 1f
   641                              <1> 		; cmp (sp)+,(sp)+ / pop clock pointer
   642                              <1> 	; 1: / now in user area
   643                              <1> 		; mov r1,-(sp) / save r1
   644                              <1> 		; mov u.ttyp,r1 
   645                              <1> 			; / pointer to tty buffer in control-to r1
   646                              <1> 		; cmpb 6(r1),$177
   647                              <1> 			; / is the interrupt char equal to "del"
   648                              <1> 		; beq 1f / yes, 1f
   649                              <1> 		; clrb 6(r1) 
   650                              <1> 		        ; / no, clear the byte 
   651                              <1> 			; / (must be a quit character)
   652                              <1> 		; mov (sp)+,r1 / restore r1
   653                              <1> 		; clr u.quit / clear quit flag
   654                              <1> 		; bis $20,2(sp) 
   655                              <1> 		    	; / set trace for quit (sets t bit of
   656                              <1> 			; / ps-trace trap)
   657                              <1> 		; rti   ;  / return from interrupt
   658                              <1> 	; 1: / interrupt char = del
   659                              <1> 		; clrb 6(r1) / clear the interrupt byte
   660                              <1> 			   ; / in the buffer
   661                              <1> 		; mov (sp)+,r1 / restore r1
   662                              <1> 		; cmp u.intr,$core / should control be
   663                              <1> 				; / transferred to loc core?
   664                              <1> 		; blo 1f
   665                              <1> 		; jmp *u.intr / user to do rti yes, 
   666                              <1> 				; / transfer to loc core
   667                              <1> 	; 1:
   668                              <1> 		; sys 1 / exit
   669                              <1> 
   670                              <1> 	; 20/08/2024
   671                              <1> 	; ctrl+break -> exit code = -1
   672                              <1> sysexit_0FFh:
   673                              <1> 	; 20/08/2024
   674 0000CF8D 31C0                <1> 	xor 	eax, eax
   675 0000CF8F 40                  <1> 	inc	eax	; mov eax, 1
   676                              <1> sysexit_@:	; 22/08/2024
   677 0000CF90 B3FF                <1> 	mov	bl, 0FFh ;  exit code ; -1
   678                              <1> 
   679                              <1> sysexit: ; <terminate process>
   680                              <1> 	; 22/08/2024
   681                              <1> 	; 20/08/2024
   682                              <1> 	; 18/08/2024 - TRDOS 386 v2.0.9 
   683                              <1> 	; 30/07/2022
   684                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
   685                              <1> 	; 14/11/2017
   686                              <1> 	; 27/05/2017
   687                              <1> 	; 10/04/2017
   688                              <1> 	; 26/02/2017 - 28/02/2017
   689                              <1> 	; 02/01/2017 - 23/01/2017
   690                              <1> 	; 06/06/2016 - 10/06/2016
   691                              <1> 	; 19/05/2016 - 23/05/2016
   692                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   693                              <1> 	; 16/04/2015 - 01/09/2015 (Retro UNIX 386 v1)
   694                              <1> 	; 19/04/2013 - 14/02/2014 (Retro UNIX 8086 v1)
   695                              <1> 	;
   696                              <1> 	; 'sysexit' terminates a process. First each file that
   697                              <1> 	; the process has opened is closed by 'flose'. The process
   698                              <1> 	; status is then set to unused. The 'p.pid' table is then
   699                              <1> 	; searched to find children of the dying process. If any of
   700                              <1> 	; children are zombies (died by not waited for), they are
   701                              <1> 	; set free. The 'p.pid' table is then searched to find the
   702                              <1> 	; dying process's parent. When the parent is found, it is
   703                              <1> 	; checked to see if it is free or it is a zombie. If it is
   704                              <1> 	; one of these, the dying process just dies. If it is waiting
   705                              <1> 	; for a child process to die, it notified that it doesn't 
   706                              <1> 	; have to wait anymore by setting it's status from 2 to 1
   707                              <1> 	; (waiting to active). It is awakened and put on runq by
   708                              <1> 	; 'putlu'. The dying process enters a zombie state in which
   709                              <1> 	; it will never be run again but stays around until a 'wait'
   710                              <1> 	; is completed by it's parent process. If the parent is not
   711                              <1> 	; found, process just dies. This means 'swap' is called with
   712                              <1> 	; 'u.uno=0'. What this does is the 'wswap' is not called
   713                              <1> 	; to write out the process and 'rswap' reads the new process
   714                              <1> 	; over the one that dies..i.e., the dying process is 
   715                              <1> 	; overwritten and destroyed.
   716                              <1>  	;
   717                              <1> 	; Calling sequence:
   718                              <1> 	;	sysexit or conditional branch.
   719                              <1> 	; Arguments:
   720                              <1> 	;	-
   721                              <1> 	; ...............................................................
   722                              <1> 	;
   723                              <1> 	; Retro UNIX 8086 v1 modification: 
   724                              <1> 	;       System call number (=1) is in EAX register.
   725                              <1> 	;
   726                              <1> 	;       Other parameters are in EDX, EBX, ECX, ESI, EDI, EBP
   727                              <1> 	;       registers depending of function details.
   728                              <1> 	;
   729                              <1> 	; ('swap' procedure is mostly different than original UNIX v1.)
   730                              <1> 	;
   731                              <1> ; / terminate process
   732                              <1> 	; AX = 1
   733                              <1> 	;dec 	ax ; 0
   734                              <1> 	; 18/08/2024
   735 0000CF92 48                  <1> 	dec	eax
   736 0000CF93 66A3[C0940100]      <1> 	mov	[u.intr], ax ; 0
   737                              <1> 		; clr u.intr / clear interrupt control word
   738                              <1> 		; clr r1 / clear r1
   739                              <1> 	; 18/08/2024 - exit code (in EBX, BL)
   740 0000CF99 881D[F2940100]      <1> 	mov	[u.exit], bl
   741                              <1> sysexit_0:
   742                              <1> 	; 30/07/2022
   743                              <1> 	; 23/01/2017
   744                              <1> 	; 02/01/2017
   745                              <1> 	; 10/06/2016
   746                              <1> 	; 06/06/2016
   747                              <1> 	; 23/05/2016
   748                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
   749                              <1> 	; Check and stop/clear timer event(s) of this (dying) process
   750                              <1> 	; if there is.
   751                              <1> 
   752                              <1> 	; 02/01/2017
   753 0000CF9F FA                  <1> 	cli	; disable interrupts
   754                              <1> 	; 23/01/2017 - reset timer frequency (to 18.2Hz)
   755 0000CFA0 B036                <1> 	mov	al, 00110110b ; 36h
   756 0000CFA2 E643                <1>  	out	43h, al
   757 0000CFA4 28C0                <1> 	sub	al, al ; 0
   758 0000CFA6 E640                <1> 	out	40h, al ; LB
   759 0000CFA8 E640                <1> 	out	40h, al ; HB
   760                              <1>  	; 
   761 0000CFAA 0FB61D[C5940100]    <1> 	movzx	ebx, byte [u.uno]
   762                              <1> 	;mov	bl, [u.uno] ; process number of dying process
   763 0000CFB1 3883[F7930100]      <1> 	cmp	byte [ebx+p.timer-1], al ; 0
   764 0000CFB7 7639                <1> 	jna	short sysexit_12 ; no timer events for this process
   765 0000CFB9 8883[F7930100]      <1> 	mov	byte [ebx+p.timer-1], al ; 0 ; reset
   766                              <1> 	;mov	al, [timer_events]
   767                              <1> 	;or	al, al
   768                              <1>  	;jz	short sysexit_12 ; no timer events
   769                              <1> 	;mov	cl, al
   770 0000CFBF 8A0D[4F890100]      <1> 	mov	cl, [timer_events] ; 14/11/2017
   771                              <1> 	;cli	; disable interrupts 
   772 0000CFC5 B410                <1> 	mov	ah, 16 ; number of available timer events
   773 0000CFC7 BE[88950100]        <1> 	mov	esi, timer_set ; beginning address of timer events
   774                              <1> sysexit_7:
   775 0000CFCC 8A06                <1> 	mov	al, [esi] ; process number (of timer event)
   776 0000CFCE 38D8                <1> 	cmp	al, bl ; process number comparison
   777 0000CFD0 7411                <1> 	je	short sysexit_10
   778 0000CFD2 20C0                <1> 	and	al, al
   779 0000CFD4 7404                <1> 	jz	short sysexit_9
   780                              <1> sysexit_8:
   781 0000CFD6 FEC9                <1> 	dec	cl
   782 0000CFD8 7416                <1> 	jz	short sysexit_11
   783                              <1> sysexit_9:
   784 0000CFDA FECC                <1> 	dec	ah
   785 0000CFDC 7414                <1> 	jz	short sysexit_12
   786 0000CFDE 83C610              <1> 	add	esi, 16
   787 0000CFE1 EBE9                <1> 	jmp	short sysexit_7
   788                              <1> 
   789                              <1> sysexit_10:
   790                              <1> 	;mov	byte [esi], 0
   791 0000CFE3 66C7060000          <1> 	mov	word [esi], 0
   792                              <1> 	;mov	dword [esi+12], 0
   793                              <1> 	;
   794 0000CFE8 FE0D[4F890100]      <1> 	dec	byte [timer_events] ; 02/01/2017
   795                              <1> 	;
   796 0000CFEE EBE6                <1> 	jmp	short sysexit_8
   797                              <1> 
   798                              <1> sysexit_11:
   799                              <1> 	;sub	ax, ax ; 0 ; 26/02/2017
   800                              <1> 	; 30/07/2022
   801 0000CFF0 29C0                <1> 	sub	eax, eax ; 0
   802                              <1> sysexit_12:
   803                              <1> 	; 26/02/2017 (Unlink IRQ callbacks belong to the user)
   804 0000CFF2 803D[EE940100]00    <1> 	cmp	byte [u.irqc], 0 ; Count of IRQ callbacks
   805 0000CFF9 7E53                <1> 	jng	short sysexit_16 ; zero or invalid
   806                              <1> 	; 28/02/2017
   807                              <1> 	; clear IRQ callback flags (for 'sysrele' and 'sysret')
   808 0000CFFB A2[EF940100]        <1> 	mov	[u.irqwait], al ; 0 ; force to clear waiting flag
   809 0000D000 A2[F0940100]        <1> 	mov	[u.r_lock], al ; 0 ; force to clear busy flag
   810 0000D005 BE[9C8E0100]        <1> 	mov	esi, IRQ.owner
   811                              <1> sysexit_13:
   812 0000D00A AC                  <1> 	lodsb
   813 0000D00B 3A05[C5940100]      <1> 	cmp	al, [u.uno] ; owner = current user ?
   814 0000D011 7531                <1> 	jne	short sysexit_14
   815 0000D013 C646FF00            <1> 	mov	byte [esi-1], 0 ; owner = 0 : Free
   816                              <1> 
   817                              <1> 	;;;
   818                              <1> 	; 22/08/2024 - Reset Hardware Interrupt Handler
   819 0000D017 89F1                <1> 	mov	ecx, esi
   820 0000D019 81E9[9C8E0100]      <1> 	sub	ecx, IRQ.owner
   821                              <1> 	; CL = (user configurable) IRQ index + 1 (1 to 9)
   822 0000D01F B8[BE3B0100]        <1> 	mov	eax, IRQenum
   823                              <1> sysexit_18:
   824 0000D024 3A08                <1> 	cmp	cl, [eax]
   825 0000D026 740A                <1> 	je	short sysexit_19
   826 0000D028 3D[CD3B0100]        <1> 	cmp	eax, IRQenum+15
   827 0000D02D 730D                <1> 	jnb	short sysexit_20
   828 0000D02F 40                  <1> 	inc	eax
   829 0000D030 EBF2                <1> 	jmp	short sysexit_18
   830                              <1> sysexit_19:
   831 0000D032 2D[BE3B0100]        <1> 	sub	eax, IRQenum
   832                              <1> 	; AL = IRQ number (will be reset to system's IRQ handler)
   833                              <1> 	; AH = 0
   834                              <1> 	;mov	ah, 0 ; reset
   835 0000D037 E8ED530000          <1> 	call	set_hardware_int_vector
   836                              <1> sysexit_20:
   837                              <1> 	;;;
   838                              <1> 
   839 0000D03C FE0D[EE940100]      <1> 	dec	byte [u.irqc]
   840 0000D042 7408                <1> 	jz	short sysexit_15
   841                              <1> sysexit_14:
   842 0000D044 81FE[A48E0100]      <1> 	cmp	esi, IRQ.owner + 8 ; the last IRQ index number ?
   843 0000D04A 76BE                <1> 	jna	short sysexit_13 ; no
   844                              <1> sysexit_15:
   845                              <1> 	;xor	al, al ; 0
   846                              <1> 	; 22/08/2024
   847 0000D04C 31C0                <1> 	xor	eax, eax
   848                              <1> sysexit_16: ; 2:
   849 0000D04E FB                  <1> 	sti	; enable interrupts
   850                              <1> 	;
   851                              <1> 	; AX = 0
   852                              <1> sysexit_1: ; 1:
   853                              <1> 	; AX = File descriptor
   854                              <1> 		; / r1 has file descriptor (index to u.fp list)
   855                              <1> 		; / Search the whole list
   856 0000D04F E864360000          <1> 	call	fclose
   857                              <1> 		; jsr r0,fclose / close all files the process opened
   858                              <1> 	;; ignore error return
   859                              <1> 		; br .+2 / ignore error return
   860                              <1> 	;;inc	ax
   861                              <1> 	;inc	al
   862                              <1> 	; 22/08/2024
   863 0000D054 40                  <1> 	inc	eax
   864                              <1> 		; inc r1 / increment file descriptor
   865                              <1> 	;cmp	ax, 10
   866 0000D055 3C0A                <1> 	cmp	al, 10
   867                              <1> 		; cmp r1,$10. / end of u.fp list?
   868 0000D057 72F6                <1> 	jb	short sysexit_1
   869                              <1> 		; blt 1b / no, go back
   870                              <1> 
   871                              <1> 	; 22/08/2024
   872                              <1> 	; reset IRQs if owned by the current (dying) process
   873 0000D059 BE[9C8E0100]        <1> 	mov	esi, IRQ.owner
   874                              <1> 
   875                              <1> 	;movzx	ebx, byte [u.uno]
   876 0000D05E 8A1D[C5940100]      <1> 	mov	bl, [u.uno] ; 02/01/2017
   877                              <1> 		; movb	u.uno,r1 / yes, move dying process's number to r1
   878 0000D064 88A3[A7930100]      <1> 	mov	[ebx+p.stat-1], ah ; 0, SFREE
   879                              <1> 		; clrb p.stat-1(r1) / free the process
   880                              <1> 	; 10/04/2017
   881 0000D06A 381D[198F0100]      <1> 	cmp	[audio_user], bl
   882 0000D070 7518                <1> 	jne	short sysexit_17
   883                              <1> 	; reset audio device (current) owner and 'initializated' flag
   884 0000D072 883D[198F0100]      <1> 	mov	[audio_user], bh ; 0
   885                              <1> 	; 27/05/2017
   886 0000D078 8B0D[008F0100]      <1> 	mov	ecx, [audio_buffer]
   887 0000D07E 09C9                <1> 	or	ecx, ecx
   888 0000D080 7408                <1> 	jz	short sysexit_17
   889                              <1> 	; 'deallocate_user_pages' is not necessary in sysexit !!!
   890                              <1> 	;push	ebx
   891                              <1> 	;mov	ebx, ecx
   892                              <1> 	;mov	ecx, [audio_buff_size]
   893                              <1> 	;call	deallocate_user_pages
   894                              <1> 	;; (Modified Registers -> EAX, EDX, ESI, EDI, EBX, ECX, EBP)
   895 0000D082 29C9                <1> 	sub	ecx, ecx
   896 0000D084 890D[008F0100]      <1> 	mov	[audio_buffer], ecx ; 0
   897                              <1> 	;pop	ebx
   898                              <1> sysexit_17:
   899                              <1> 	;shl	bx, 1
   900 0000D08A D0E3                <1> 	shl	bl, 1
   901                              <1> 	; 22/08/2024
   902                              <1> 	;shl	ebx, 1
   903                              <1> 		; asl r1 / use r1 for index into the below tables
   904 0000D08C 668B8B[46930100]    <1> 	mov	cx, [ebx+p.pid-2]
   905                              <1> 		; mov p.pid-2(r1),r3 / move dying process's name to r3
   906 0000D093 668B93[66930100]    <1> 	mov	dx, [ebx+p.ppid-2]
   907                              <1> 		; mov p.ppid-2(r1),r4 / move its parents name to r4
   908                              <1> 	;xor 	bx, bx ; 0
   909 0000D09A 30DB                <1> 	xor	bl, bl ; 0
   910                              <1> 		; clr r2
   911 0000D09C 31F6                <1> 	xor	esi, esi ; 0
   912                              <1> 		; clr r5 / initialize reg
   913                              <1> sysexit_2: ; 1:
   914                              <1> 	        ; / find children of this dying process,
   915                              <1> 		; / if they are zombies, free them
   916                              <1> 	;add	bx, 2
   917 0000D09E 80C302              <1> 	add	bl, 2
   918                              <1> 		; add $2,r2 / search parent process table
   919                              <1> 		          ; / for dying process's name
   920 0000D0A1 66398B[66930100]    <1> 	cmp	[ebx+p.ppid-2], cx
   921                              <1> 		; cmp p.ppid-2(r2),r3 / found it?
   922 0000D0A8 7513                <1> 	jne	short sysexit_4
   923                              <1> 		; bne 3f / no
   924                              <1> 	;shr	bx, 1
   925 0000D0AA D0EB                <1> 	shr	bl, 1
   926                              <1> 		; asr r2 / yes, it is a parent
   927 0000D0AC 80BB[A7930100]03    <1> 	cmp	byte [ebx+p.stat-1], 3 ; SZOMB
   928                              <1> 		; cmpb p.stat-1(r2),$3 / is the child of this
   929                              <1> 				     ; / dying process a zombie
   930 0000D0B3 7506                <1> 	jne	short sysexit_3
   931                              <1> 		; bne 2f / no
   932 0000D0B5 88A3[A7930100]      <1> 	mov	[ebx+p.stat-1], ah ; 0, SFREE
   933                              <1> 		; clrb p.stat-1(r2) / yes, free the child process
   934                              <1> sysexit_3: ; 2:
   935                              <1> 	;shr	bx, 1
   936 0000D0BB D0E3                <1> 	shl	bl, 1
   937                              <1> 		; asl r2
   938                              <1> sysexit_4: ; 3:
   939                              <1> 		; / search the process name table 
   940                              <1> 		; / for the dying process's parent
   941 0000D0BD 663993[46930100]    <1> 	cmp	[ebx+p.pid-2], dx
   942                              <1> 		; cmp p.pid-2(r2),r4 / found it?
   943 0000D0C4 7502                <1> 	jne	short sysexit_5
   944                              <1> 		; bne 3f / no
   945 0000D0C6 89DE                <1> 	mov	esi, ebx
   946                              <1> 		; mov r2,r5 / yes, put index to p.pid table (parents
   947                              <1> 		          ; / process # x2) in r5
   948                              <1> sysexit_5: ; 3:
   949                              <1> 	;cmp	bx, nproc + nproc
   950 0000D0C8 80FB20              <1> 	cmp	bl, nproc + nproc
   951                              <1> 		; cmp r2,$nproc+nproc / has whole table been searched?
   952 0000D0CB 72D1                <1> 	jb	short sysexit_2
   953                              <1> 		; blt 1b / no, go back
   954                              <1> 		; mov r5,r1 / yes, r1 now has parents process # x2
   955 0000D0CD 21F6                <1> 	and	esi, esi ; r5=r1
   956 0000D0CF 743F                <1> 	jz	short sysexit_6
   957                              <1> 		; beq 2f / no parent has been found.
   958                              <1> 		       ; / The process just dies
   959                              <1> 	;shr	si, 1
   960                              <1> 	; 23/07/2022
   961 0000D0D1 D1EE                <1> 	shr	esi, 1
   962                              <1> 		; asr r1 / set up index to p.stat
   963 0000D0D3 8A86[A7930100]      <1> 	mov	al, [esi+p.stat-1]
   964                              <1> 		; movb p.stat-1(r1),r2 / move status of parent to r2
   965 0000D0D9 20C0                <1> 	and	al, al
   966 0000D0DB 7433                <1> 	jz	short sysexit_6
   967                              <1> 		; beq 2f / if its been freed, 2f
   968 0000D0DD 3C03                <1> 	cmp	al, 3
   969                              <1> 		; cmp r2,$3 / is parent a zombie?
   970 0000D0DF 742F                <1> 	je	short sysexit_6
   971                              <1> 		; beq 2f / yes, 2f
   972                              <1> 
   973                              <1> 	; BH = 0
   974 0000D0E1 8A1D[C5940100]      <1> 	mov	bl, [u.uno]
   975                              <1> 		; movb u.uno,r3 / move dying process's number to r3
   976 0000D0E7 C683[A7930100]03    <1> 	mov	byte [ebx+p.stat-1], 3 ; SZOMB
   977                              <1> 		; movb $3,p.stat-1(r3) / make the process a zombie
   978                              <1> 
   979 0000D0EE 3C01                <1> 	cmp	al, 1 ; SRUN
   980 0000D0F0 741E                <1> 	je	short sysexit_6
   981                              <1> 	;cmp	al, 2
   982                              <1> 		; cmp r2,$2 / is the parent waiting for 
   983                              <1> 			  ; / this child to die
   984                              <1> 	;jne	short sysexit_6	
   985                              <1> 		; bne 2f / yes, notify parent not to wait any more
   986                              <1> 	; p.stat = 2 --> waiting
   987                              <1> 	; p.stat = 4 --> sleeping
   988 0000D0F2 C686[A7930100]01    <1> 	mov	byte [esi+p.stat-1], 1 ; SRUN
   989                              <1> 	;;;
   990                              <1> 	; 18/08/2024 - exit code
   991 0000D0F9 A0[F2940100]        <1> 	mov	al, [u.exit] ; exit code of the child
   992                              <1> 	; 20/08/2024
   993 0000D0FE 8883[47940100]      <1> 	mov	[ebx+p.exitc-1], al ; save it to use by the parent
   994                              <1> 	;;;
   995                              <1> 	;dec	byte [esi+p.stat-1]
   996                              <1> 		; decb	p.stat-1(r1) / awaken it by putting it (parent)
   997                              <1> 	;;;
   998                              <1> 	;mov	ax, si ; r1  (process number in AL)
   999                              <1> 	; 18/08/2024
  1000 0000D104 89F0                <1> 	mov	eax, esi
  1001                              <1> 	;;;
  1002                              <1> 	;mov	ebx, runq + 4
  1003                              <1> 		; mov $runq+4,r2 / on the runq
  1004 0000D106 BB[64940100]        <1> 	mov	ebx, runq+2 ; normal run queue ; 02/01/2017
  1005 0000D10B E8AC3D0000          <1> 	call	putlu
  1006                              <1> 		; jsr r0, putlu
  1007                              <1> sysexit_6:
  1008                              <1> 		; / the process dies
  1009 0000D110 C605[C5940100]00    <1> 	mov	byte [u.uno], 0
  1010                              <1> 		; clrb u.uno / put zero as the process number,
  1011                              <1> 	           ; / so "swap" will
  1012 0000D117 E8A33C0000          <1> 	call	swap
  1013                              <1> 		; jsr r0,swap / overwrite process with another process
  1014                              <1> hlt_sys:
  1015                              <1> 	;sti
  1016                              <1> hlts0:
  1017 0000D11C F4                  <1> 	hlt
  1018 0000D11D EBFD                <1> 	jmp	short hlts0
  1019                              <1> 		; 0 / and thereby kill it; halt?
  1020                              <1> 
  1021                              <1> syswait: ; < wait for a processs to die >
  1022                              <1> 	; 20/08/2024
  1023                              <1> 	; 30/07/2022
  1024                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
  1025                              <1> 	; 17/09/2015
  1026                              <1> 	; 02/09/2015
  1027                              <1> 	; 01/09/2015
  1028                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - Beginning)
  1029                              <1> 	; 24/05/2013 - 05/02/2014 (Retro UNIX 8086 v1)
  1030                              <1> 	;
  1031                              <1> 	; 'syswait' waits for a process die.
  1032                              <1> 	; It works in following way:
  1033                              <1> 	;    1) From the parent process number, the parent's 
  1034                              <1> 	; 	process name is found. The p.ppid table of parent
  1035                              <1> 	;	names is then searched for this process name.
  1036                              <1> 	;	If a match occurs, r2 contains child's process
  1037                              <1> 	;	number. The child status is checked to see if it is
  1038                              <1> 	;	a zombie, i.e; dead but not waited for (p.stat=3)
  1039                              <1> 	;	If it is, the child process is freed and it's name
  1040                              <1> 	;	is put in (u.r0). A return is then made via 'sysret'.
  1041                              <1> 	;	If the child is not a zombie, nothing happens and
  1042                              <1> 	;	the search goes on through the p.ppid table until
  1043                              <1> 	;	all processes are checked or a zombie is found.
  1044                              <1> 	;    2) If no zombies are found, a check is made to see if
  1045                              <1> 	;	there are any children at all. If there are none,
  1046                              <1> 	;	an error return is made. If there are, the parent's
  1047                              <1> 	;	status is set to 2 (waiting for child to die),
  1048                              <1> 	;	the parent is swapped out, and a branch to 'syswait'
  1049                              <1> 	;	is made to wait on the next process.
  1050                              <1> 	;
  1051                              <1> 	; Calling sequence:
  1052                              <1> 	;	?
  1053                              <1> 	; Arguments:
  1054                              <1> 	;	-
  1055                              <1> 	; Inputs: - 
  1056                              <1> 	; Outputs: if zombie found, it's name put in u.r0.
  1057                              <1> 	; ...............................................................
  1058                              <1> 	;
  1059                              <1> 
  1060                              <1> ; / wait for a process to die
  1061                              <1> 
  1062                              <1> syswait_0:
  1063 0000D11F 0FB61D[C5940100]    <1> 	movzx	ebx, byte [u.uno] ; 01/09/2015
  1064                              <1> 		; movb u.uno,r1 / put parents process number in r1
  1065 0000D126 D0E3                <1> 	shl	bl, 1
  1066                              <1> 	;shl	bx, 1
  1067                              <1> 		; asl r1 / x2 to get index into p.pid table
  1068 0000D128 668B83[46930100]    <1> 	mov	ax, [ebx+p.pid-2]
  1069                              <1> 		; mov p.pid-2(r1),r1 / get the name of this process
  1070 0000D12F 31F6                <1> 	xor	esi, esi
  1071                              <1> 		; clr r2
  1072 0000D131 31C9                <1> 	xor	ecx, ecx ; 30/10/2013
  1073                              <1> 	;xor 	cl, cl
  1074                              <1> 		; clr r3 / initialize reg 3
  1075                              <1> syswait_1: ; 1:
  1076                              <1> 	;add	si, 2
  1077                              <1> 	; 23/07/2022
  1078 0000D133 46                  <1> 	inc	esi
  1079 0000D134 46                  <1> 	inc	esi
  1080                              <1> 		; add $2,r2 / use r2 for index into p.ppid table
  1081                              <1> 			  ; / search table of parent processes
  1082                              <1> 			  ; / for this process name
  1083 0000D135 663B86[66930100]    <1> 	cmp	ax, [esi+p.ppid-2]
  1084                              <1> 		; cmp p.ppid-2(r2),r1 / r2 will contain the childs
  1085                              <1> 			            ; / process number
  1086 0000D13C 7542                <1> 	jne	short syswait_3
  1087                              <1> 		;bne 3f / branch if no match of parent process name
  1088                              <1> 	;inc	cx
  1089 0000D13E FEC1                <1> 	inc	cl
  1090                              <1> 		;inc r3 / yes, a match, r3 indicates number of children
  1091                              <1> 	;shr	si, 1
  1092                              <1> 	; 23/07/2022
  1093 0000D140 D1EE                <1> 	shr	esi, 1
  1094                              <1> 		; asr r2 / r2/2 to get index to p.stat table
  1095                              <1> 	; The possible states ('p.stat' values) of a process are:
  1096                              <1> 	;	0 = free or unused
  1097                              <1> 	;	1 = active
  1098                              <1> 	;	2 = waiting for a child process to die
  1099                              <1> 	;	3 = terminated, but not yet waited for (zombie).
  1100 0000D142 80BE[A7930100]03    <1> 	cmp	byte [esi+p.stat-1], 3 ; SZOMB, 05/02/2014
  1101                              <1> 		; cmpb p.stat-1(r2),$3 / is the child process a zombie?
  1102 0000D149 7533                <1> 	jne	short syswait_2
  1103                              <1> 		; bne 2f / no, skip it
  1104 0000D14B 88BE[A7930100]      <1> 	mov	[esi+p.stat-1], bh ; 0
  1105                              <1> 		; clrb p.stat-1(r2) / yes, free it
  1106                              <1> 
  1107                              <1> 	; 20/08/2024 (ebx = child's exit code)
  1108 0000D151 31C0                <1> 	xor	eax, eax
  1109 0000D153 8A86[47940100]      <1> 	mov	al, [esi+p.exitc-1] ; exit code
  1110 0000D159 8B2D[70940100]      <1> 	mov	ebp, [u.usp]
  1111                              <1> 	; 22/08/2024
  1112 0000D15F 894510              <1> 	mov	[ebp+16], eax ; ebx
  1113                              <1> 
  1114                              <1> 	;shl	si, 1
  1115                              <1> 	; 23/07/2022
  1116 0000D162 D1E6                <1> 	shl	esi, 1
  1117                              <1> 		; asl r2 / r2x2 to get index into p.pid table
  1118                              <1> 	;movzx	eax, word [esi+p.pid-2]
  1119                              <1> 	; 20/08/2024
  1120 0000D164 668B86[46930100]    <1> 	mov	ax, [esi+p.pid-2]
  1121 0000D16B A3[74940100]        <1> 	mov	[u.r0], eax
  1122                              <1> 		; mov p.pid-2(r2),*u.r0 
  1123                              <1> 			      ; / put childs process name in (u.r0)
  1124                              <1> 	;
  1125                              <1> 	; Retro UNIX 386 v1 modification ! (17/09/2015)
  1126                              <1> 	;
  1127                              <1> 	; Parent process ID -p.ppid- field (of the child process)
  1128                              <1> 	; must be cleared in order to prevent infinitive 'syswait'
  1129                              <1> 	; system call loop from the application/program if it calls
  1130                              <1> 	; 'syswait' again (mistakenly) while there is not a zombie
  1131                              <1> 	; or running child process to wait. ('forktest.s', 17/09/2015)
  1132                              <1> 	;
  1133                              <1> 	; Note: syswait will return with error if there is not a
  1134                              <1> 	;       zombie or running process to wait.
  1135                              <1> 
  1136                              <1> 	;sub	ax, ax
  1137                              <1> 	; 30/07/2022
  1138 0000D170 29C0                <1> 	sub	eax, eax ; 0
  1139 0000D172 668986[66930100]    <1> 	mov 	[esi+p.ppid-2], ax ; 0 ; 17/09/2015
  1140 0000D179 E9D8FCFFFF          <1> 	jmp	sysret0 ; ax = 0
  1141                              <1> 	;
  1142                              <1> 	;jmp	sysret
  1143                              <1> 		; br sysret1 / return cause child is dead
  1144                              <1> syswait_2: ; 2:
  1145                              <1> 	;shl	si, 1
  1146                              <1> 	; 23/07/2022
  1147 0000D17E D1E6                <1> 	shl	esi, 1
  1148                              <1> 		; asl r2 / r2x2 to get index into p.ppid table
  1149                              <1> syswait_3: ; 3:
  1150 0000D180 6683FE20            <1> 	cmp	si, nproc+nproc
  1151                              <1> 		; cmp r2,$nproc+nproc / have all processes been checked?
  1152 0000D184 72AD                <1> 	jb	short syswait_1
  1153                              <1> 		; blt 1b / no, continue search
  1154                              <1> 	;and	cx, cx
  1155 0000D186 20C9                <1> 	and	cl, cl
  1156                              <1> 		; tst r3 / one gets here if there are no children
  1157                              <1> 		       ; / or children that are still active
  1158                              <1> 	; 30/10/2013
  1159 0000D188 7515                <1> 	jnz	short syswait_4
  1160                              <1> 	;jz	error
  1161                              <1> 		; beq error1 / there are no children, error
  1162 0000D18A 890D[74940100]      <1> 	mov	[u.r0], ecx ; 0
  1163                              <1> 
  1164                              <1> 	; 20/08/2024 (ebx = child's exit code)
  1165 0000D190 8B2D[70940100]      <1> 	mov	ebp, [u.usp]
  1166 0000D196 49                  <1> 	dec	ecx ; -1 ; 0FFFFFFFFh
  1167                              <1> 	; 22/08/2024
  1168 0000D197 894D10              <1> 	mov	[ebp+16], ecx ; ebx
  1169                              <1> 
  1170 0000D19A E995FCFFFF          <1> 	jmp	error
  1171                              <1> syswait_4:
  1172 0000D19F 8A1D[C5940100]      <1> 	mov	bl, [u.uno]
  1173                              <1> 		; movb u.uno,r1 / there are children so put 
  1174                              <1> 			      ; / parent process number in r1
  1175 0000D1A5 FE83[A7930100]      <1> 	inc	byte [ebx+p.stat-1] ; 2, SWAIT, 05/02/2014
  1176                              <1> 		; incb p.stat-1(r1) / it is waiting for
  1177                              <1> 				  ; / other children to die
  1178                              <1> 	; 04/11/2013
  1179 0000D1AB E80F3C0000          <1> 	call	swap
  1180                              <1> 		; jsr r0,swap / swap it out, because it's waiting
  1181                              <1> 
  1182                              <1> 	; 23/08/2024 - bugfix
  1183                              <1> 	; restore [u.usp]
  1184                              <1> 	; (swap above changes [u.usp] just before wswap)
  1185 0000D1B0 8925[70940100]      <1> 	mov	[u.usp], esp
  1186                              <1> 		; points to user's regs on top ofn system stack
  1187                              <1> 
  1188 0000D1B6 E964FFFFFF          <1> 	jmp	syswait_0
  1189                              <1> 		; br syswait / wait on next process
  1190                              <1> 
  1191                              <1> sysfork: ; < create a new process >
  1192                              <1> 	; 19/08/2024 - TRDOS 386 Kernel v2.0.9 (STDIN/STDOUT)
  1193                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
  1194                              <1> 	; 02/01/2017 (TRDOS 386 modification)
  1195                              <1> 	; 04/09/2015 - 18/05/2015
  1196                              <1> 	; 28/08/2015 - 01/09/2015 - 02/09/2015
  1197                              <1> 	; 09/05/2015 - 10/05/2015 - 14/05/2015
  1198                              <1> 	; 06/05/2015 (Retro UNIX 386 v1 - Beginning)
  1199                              <1> 	; 24/05/2013 - 14/02/2014 (Retro UNIX 8086 v1)
  1200                              <1> 	;
  1201                              <1> 	; 'sysfork' creates a new process. This process is referred
  1202                              <1> 	; to as the child process. This new process core image is
  1203                              <1> 	; a copy of that of the caller of 'sysfork'. The only
  1204                              <1> 	; distinction is the return location and the fact that (u.r0)
  1205                              <1> 	; in the old process (parent) contains the process id (p.pid)
  1206                              <1> 	; of the new process (child). This id is used by 'syswait'.
  1207                              <1> 	; 'sysfork' works in the following manner:
  1208                              <1> 	;    1) The process status table (p.stat) is searched to find
  1209                              <1> 	;	a process number that is unused. If none are found
  1210                              <1> 	;	an error occurs.
  1211                              <1> 	;    2) when one is found, it becomes the child process number
  1212                              <1> 	;	and it's status (p.stat) is set to active.
  1213                              <1> 	;    3) If the parent had a control tty, the interrupt
  1214                              <1> 	;	character in that tty buffer is cleared.
  1215                              <1> 	;    4) The child process is put on the lowest priority run
  1216                              <1> 	;	queue via 'putlu'.
  1217                              <1> 	;    5) A new process name is gotten from 'mpid' (actually
  1218                              <1> 	;	it is a unique number) and is put in the child's unique
  1219                              <1> 	;	identifier; process id (p.pid).
  1220                              <1> 	;    6) The process name of the parent is then obtained and
  1221                              <1> 	;	placed in the unique identifier of the parent process
  1222                              <1> 	;	name is then put in 'u.r0'.
  1223                              <1> 	;    7) The child process is then written out on disk by
  1224                              <1> 	;	'wswap',i.e., the parent process is copied onto disk
  1225                              <1> 	;	and the child is born. (The child process is written
  1226                              <1> 	;	out on disk/drum with 'u.uno' being the child process
  1227                              <1> 	;	number.)
  1228                              <1> 	;    8) The parent process number is then restored to 'u.uno'.
  1229                              <1> 	;    9) The child process name is put in 'u.r0'.
  1230                              <1> 	;   10) The pc on the stack sp + 18 is incremented by 2 to
  1231                              <1> 	;	create the return address for the parent process.
  1232                              <1> 	;   11) The 'u.fp' list as then searched to see what files
  1233                              <1> 	;	the parent has opened. For each file the parent has
  1234                              <1> 	;	opened, the corresponding 'fsp' entry must be updated
  1235                              <1> 	;	to indicate that the child process also has opened
  1236                              <1> 	;	the file. A branch to 'sysret' is then made.
  1237                              <1> 	;
  1238                              <1> 	; Calling sequence:
  1239                              <1> 	;	from shell ?
  1240                              <1> 	; Arguments:
  1241                              <1> 	;	-
  1242                              <1> 	; Inputs: -
  1243                              <1> 	; Outputs: *u.r0 - child process name
  1244                              <1> 	; ...............................................................
  1245                              <1> 	;	
  1246                              <1> 	; Retro UNIX 8086 v1 modification: 
  1247                              <1> 	;	AX = r0 = PID (>0) (at the return of 'sysfork')
  1248                              <1> 	;	= process id of child a parent process returns
  1249                              <1> 	;	= process id of parent when a child process returns
  1250                              <1> 	;
  1251                              <1> 	;       In original UNIX v1, sysfork is called and returns as
  1252                              <1> 	;	in following manner: (with an example: c library, fork)
  1253                              <1> 	;
  1254                              <1> 	;	1:
  1255                              <1> 	;		sys	fork
  1256                              <1> 	;			br 1f  / child process returns here
  1257                              <1> 	;		bes	2f     / parent process returns here
  1258                              <1> 	;		/ pid of new process in r0
  1259                              <1> 	;		rts	pc
  1260                              <1> 	;	2: / parent process condionally branches here
  1261                              <1> 	;		mov	$-1,r0 / pid = -1 means error return
  1262                              <1> 	;		rts	pc
  1263                              <1> 	;
  1264                              <1> 	;	1: / child process brances here
  1265                              <1> 	;		clr	r0   / pid = 0 in child process
  1266                              <1> 	;		rts	pc
  1267                              <1> 	;
  1268                              <1> 	;	In UNIX v7x86 (386) by Robert Nordier (1999)
  1269                              <1> 	;		// pid = fork();
  1270                              <1> 	;		//
  1271                              <1> 	;		// pid == 0 in child process; 
  1272                              <1> 	;		// pid == -1 means error return
  1273                              <1> 	;		// in child, 
  1274                              <1> 	;		//	parents id is in par_uid if needed
  1275                              <1> 	;
  1276                              <1> 	;		_fork:
  1277                              <1> 	;			mov	$.fork,eax
  1278                              <1> 	;			int	$0x30
  1279                              <1> 	;			jmp	1f
  1280                              <1> 	;			jnc	2f
  1281                              <1> 	;			jmp	cerror
  1282                              <1> 	;		1:
  1283                              <1> 	;			mov	eax,_par_uid
  1284                              <1> 	;			xor	eax,eax
  1285                              <1> 	;		2:
  1286                              <1> 	;			ret
  1287                              <1> 	;
  1288                              <1> 	;	In Retro UNIX 8086 v1,
  1289                              <1> 	;	'sysfork' returns in following manner:
  1290                              <1> 	;
  1291                              <1> 	;		mov	ax, sys_fork
  1292                              <1> 	;		mov	bx, offset @f ; routine for child
  1293                              <1> 	;		int	20h
  1294                              <1> 	;		jc	error
  1295                              <1> 	;
  1296                              <1> 	;	; Routine for parent process here (just after 'jc')
  1297                              <1> 	;		mov	word ptr [pid_of_child], ax
  1298                              <1> 	;		jmp	next_routine_for_parent	
  1299                              <1> 	;
  1300                              <1> 	;	@@: ; routine for child process here
  1301                              <1> 	;		....
  1302                              <1> 	;	NOTE: 'sysfork' returns to specified offset
  1303                              <1> 	;	       for child process by using BX input.
  1304                              <1> 	;	      (at first, parent process will return then
  1305                              <1> 	;	      child process will return -after swapped in-
  1306                              <1> 	;	      'syswait' is needed in parent process
  1307                              <1> 	;	      if return from child process will be waited for.)
  1308                              <1> 	;
  1309                              <1> 
  1310                              <1> ; / create a new process
  1311                              <1> 	; EBX = return address for child process
  1312                              <1> 	     ; (Retro UNIX 8086 v1 modification !)
  1313 0000D1BB 31F6                <1> 	xor 	esi, esi
  1314                              <1> 		; clr r1
  1315                              <1> sysfork_1: ; 1: / search p.stat table for unused process number
  1316 0000D1BD 46                  <1> 	inc	esi
  1317                              <1> 		; inc r1
  1318 0000D1BE 80BE[A7930100]00    <1> 	cmp	byte [esi+p.stat-1], 0 ; SFREE, 05/02/2014
  1319                              <1> 		; tstb p.stat-1(r1) / is process active, unused, dead
  1320 0000D1C5 760B                <1> 	jna	short sysfork_2	
  1321                              <1> 		; beq 1f / it's unused so branch
  1322 0000D1C7 6683FE10            <1> 	cmp	si, nproc
  1323                              <1> 		; cmp r1,$nproc / all processes checked
  1324 0000D1CB 72F0                <1> 	jb	short sysfork_1
  1325                              <1> 		; blt 1b / no, branch back
  1326                              <1> 	;
  1327                              <1> 	; Retro UNIX 8086 v1. modification:
  1328                              <1> 	;	Parent process returns from 'sysfork' to address 
  1329                              <1> 	;	which is just after 'sysfork' system call in parent
  1330                              <1> 	;	process. Child process returns to address which is put
  1331                              <1> 	;	in BX register by parent process for 'sysfork'. 
  1332                              <1> 	;
  1333                              <1> 		; add $2,18.(sp) / add 2 to pc when trap occured, points
  1334                              <1> 		             ; / to old process return
  1335                              <1> 		; br error1 / no room for a new process
  1336                              <1> sysfork_err:
  1337 0000D1CD E962FCFFFF          <1> 	jmp	error
  1338                              <1> sysfork_2: ; 1:
  1339 0000D1D2 E80986FFFF          <1> 	call	allocate_page
  1340                              <1> 	;jc	error
  1341                              <1> 	; 23/07/2022
  1342 0000D1D7 72F4                <1> 	jc	short sysfork_err
  1343 0000D1D9 50                  <1> 	push	eax   ; UPAGE (user structure page) address
  1344                              <1> 	; Retro UNIX 386 v1 modification!
  1345 0000D1DA E8F187FFFF          <1> 	call	duplicate_page_dir
  1346                              <1> 		; EAX = New page directory
  1347 0000D1DF 730B                <1> 	jnc	short sysfork_3
  1348 0000D1E1 58                  <1> 	pop	eax   ; UPAGE (user structure page) address
  1349 0000D1E2 E8B887FFFF          <1> 	call 	deallocate_page
  1350 0000D1E7 E948FCFFFF          <1> 	jmp	error
  1351                              <1> sysfork_3:
  1352                              <1> 	; Retro UNIX 386 v1 modification !
  1353 0000D1EC 56                  <1> 	push	esi
  1354 0000D1ED E85A3C0000          <1> 	call	wswap ; save current user (u) structure, user registers
  1355                              <1> 		      ; and interrupt return components (for IRET)
  1356 0000D1F2 8705[CC940100]      <1> 	xchg	eax, [u.pgdir] ; page directory of the child process
  1357 0000D1F8 A3[D0940100]        <1> 	mov	[u.ppgdir], eax ; page directory of the parent process
  1358 0000D1FD 5E                  <1> 	pop	esi
  1359 0000D1FE 58                  <1> 	pop	eax   ; UPAGE (user structure page) address
  1360                              <1> 		; [u.usp] = esp
  1361 0000D1FF 89F7                <1> 	mov	edi, esi
  1362                              <1> 	;shl	di, 2
  1363                              <1> 	; 23/07/2022
  1364 0000D201 C1E702              <1> 	shl	edi, 2
  1365 0000D204 8987[B4930100]      <1> 	mov	[edi+p.upage-4], eax ; memory page for 'user' struct
  1366 0000D20A A3[C8940100]        <1> 	mov	[u.upage], eax ; memory page for 'user' struct (child)
  1367                              <1> 	;;;
  1368                              <1> 	; 19/08/2024 - reset STDIN/STDOUT redirections (and ungetchar)
  1369 0000D20F 31C0                <1> 	xor	eax, eax ; 0
  1370                              <1> 	; 19/08/2024
  1371                              <1> 	;mov	[u.stdin], al ; 0
  1372                              <1> 	;mov	[u.stdout], al ; 0
  1373                              <1> 	;mov	[u.ungetc], al ; 0
  1374                              <1> 	;mov	[u.getc], al ; 0
  1375 0000D211 A3[DC940100]        <1> 	mov	[u.stdin], eax ; 0
  1376                              <1> 	;;;
  1377                              <1> 
  1378                              <1> 	; 28/08/2015
  1379                              <1> 	;movzx	eax, byte [u.uno] ; parent process number
  1380                              <1> 	; 19/08/2024
  1381                              <1> 	; eax = 0
  1382 0000D216 A0[C5940100]        <1> 	mov	al, [u.uno] ; parent process number
  1383                              <1> 		; movb u.uno,-(sp) / save parent process number
  1384 0000D21B 89C7                <1> 	mov	edi, eax
  1385 0000D21D 50                  <1>         push	eax ; **
  1386 0000D21E 8A87[87930100]      <1> 	mov     al, [edi+p.ttyc-1] ; console tty (parent)
  1387                              <1> 	; 18/09/2015
  1388                              <1> 	;;mov	[esi+p.ttyc-1], al ; set child's console tty
  1389                              <1> 	;;mov	[esi+p.waitc-1], ah ; 0 ; reset child's wait channel
  1390                              <1> 	;mov    [esi+p.ttyc-1], ax ; al - set child's console tty
  1391                              <1> 				   ; ah - reset child's wait channel
  1392                              <1> 	; 23/07/2022
  1393 0000D224 8886[87930100]      <1> 	mov	[esi+p.ttyc-1], al ; set child's console tty
  1394 0000D22A 89F0                <1> 	mov	eax, esi
  1395 0000D22C A2[C5940100]        <1> 	mov	[u.uno], al ; child process number
  1396                              <1> 		;movb r1,u.uno / set child process number to r1
  1397 0000D231 FE86[A7930100]      <1>         inc     byte [esi+p.stat-1] ; 1, SRUN, 05/02/2014
  1398                              <1> 		; incb p.stat-1(r1) / set p.stat entry for child 
  1399                              <1> 				; / process to active status
  1400                              <1> 		; mov u.ttyp,r2 / put pointer to parent process' 
  1401                              <1> 			      ; / control tty buffer in r2
  1402                              <1>                 ; beq 2f / branch, if no such tty assigned
  1403                              <1> 		; clrb 6(r2) / clear interrupt character in tty buffer
  1404                              <1> 	; 2:
  1405 0000D237 53                  <1> 	push	ebx  ; * return address for the child process
  1406                              <1> 		     ; * Retro UNIX 8086 v1 feature only !
  1407                              <1> 	; (Retro UNIX 8086 v1 modification!)
  1408                              <1> 		; mov $runq+4,r2
  1409 0000D238 BB[64940100]        <1> 	mov	ebx, runq+2 ; normal run queue ; 02/01/2017
  1410 0000D23D E87A3C0000          <1> 	call	putlu
  1411                              <1>  		; jsr r0,putlu / put child process on lowest priority
  1412                              <1> 			   ; / run queue
  1413                              <1> 	; 23/07/2022
  1414 0000D242 D1E6                <1> 	shl	esi, 1
  1415                              <1> 	;shl	si, 1
  1416                              <1> 		; asl r1 / multiply r1 by 2 to get index 
  1417                              <1> 		       ; / into p.pid table
  1418 0000D244 66FF05[5C940100]    <1> 	inc	word [mpid]
  1419                              <1> 		; inc mpid / increment m.pid; get a new process name
  1420 0000D24B 66A1[5C940100]      <1> 	mov	ax, [mpid]
  1421 0000D251 668986[46930100]    <1> 	mov	[esi+p.pid-2], ax
  1422                              <1> 		;mov mpid,p.pid-2(r1) / put new process name 
  1423                              <1> 				    ; / in child process' name slot
  1424 0000D258 5A                  <1> 	pop	edx  ; * return address for the child process
  1425                              <1> 		     ; * Retro UNIX 8086 v1 feature only !
  1426 0000D259 5B                  <1>   	pop	ebx  ; **
  1427                              <1> 	;mov	ebx, [esp] ; ** parent process number
  1428                              <1> 		; movb (sp),r2 / put parent process number in r2
  1429                              <1> 	; 23/07/2022
  1430 0000D25A D1E3                <1> 	shl	ebx, 1
  1431                              <1> 	;shl 	bx, 1
  1432                              <1> 		;asl r2 / multiply by 2 to get index into below tables
  1433                              <1> 	;movzx eax, word [ebx+p.pid-2]
  1434 0000D25C 668B83[46930100]    <1> 	mov	ax, [ebx+p.pid-2]
  1435                              <1> 		; mov p.pid-2(r2),r2 / get process name of parent
  1436                              <1> 				   ; / process
  1437 0000D263 668986[66930100]    <1> 	mov	[esi+p.ppid-2], ax
  1438                              <1> 		; mov r2,p.ppid-2(r1) / put parent process name
  1439                              <1> 			  ; / in parent process slot for child
  1440 0000D26A A3[74940100]        <1> 	mov	[u.r0], eax
  1441                              <1> 		; mov r2,*u.r0 / put parent process name on stack
  1442                              <1> 			     ; / at location where r0 was saved
  1443 0000D26F 8B2D[6C940100]      <1> 	mov 	ebp, [u.sp] ; points to return address (EIP for IRET)
  1444 0000D275 895500              <1> 	mov	[ebp], edx ; *, CS:EIP -> EIP
  1445                              <1> 			   ; * return address for the child process
  1446                              <1> 		; mov $sysret1,-(sp) /
  1447                              <1> 		; mov sp,u.usp / contents of sp at the time when 
  1448                              <1> 			      ; / user is swapped out
  1449                              <1> 		; mov $sstack,sp / point sp to swapping stack space
  1450                              <1> 	; 04/09/2015 - 01/09/2015
  1451                              <1> 	; [u.usp] = esp
  1452 0000D278 68[54CE0000]        <1> 	push	sysret ; ***
  1453 0000D27D 8925[70940100]      <1> 	mov	[u.usp], esp ; points to 'sysret' address (***)
  1454                              <1> 			     ; (for child process)
  1455 0000D283 31C0                <1> 	xor 	eax, eax
  1456 0000D285 66A3[A8940100]      <1> 	mov 	[u.ttyp], ax ; 0
  1457                              <1> 	;
  1458 0000D28B E8BC3B0000          <1> 	call	wswap ; Retro UNIX 8086 v1 modification !
  1459                              <1> 		; jsr r0,wswap / put child process out on drum
  1460                              <1> 		; jsr r0,unpack / unpack user stack
  1461                              <1> 		; mov u.usp,sp / restore user stack pointer
  1462                              <1> 		; tst (sp)+ / bump stack pointer
  1463                              <1> 	; Retro UNIX 386 v1 modification !
  1464 0000D290 58                  <1> 	pop	eax ; ***
  1465                              <1> 	;shl	bx, 1
  1466                              <1> 	; 23/07/2022
  1467 0000D291 D1E3                <1> 	shl	ebx, 1
  1468 0000D293 8B83[B4930100]      <1> 	mov     eax, [ebx+p.upage-4] ; UPAGE address ; 14/05/2015
  1469 0000D299 E8E63B0000          <1> 	call	rswap ; restore parent process 'u' structure,
  1470                              <1> 		      ; registers and return address (for IRET)
  1471                              <1> 		;movb (sp)+,u.uno / put parent process number in u.uno
  1472 0000D29E 0FB705[5C940100]    <1>         movzx   eax, word [mpid]
  1473 0000D2A5 A3[74940100]        <1> 	mov	[u.r0], eax
  1474                              <1> 		; mov mpid,*u.r0 / put child process name on stack
  1475                              <1> 			       ; / where r0 was saved
  1476                              <1> 		; add $2,18.(sp) / add 2 to pc on stack; gives parent
  1477                              <1> 			          ; / process return
  1478                              <1> 	;xor	ebx, ebx
  1479 0000D2AA 31F6                <1> 	xor     esi, esi
  1480                              <1> 		;clr r1
  1481                              <1> sysfork_4: ; 1: / search u.fp list to find the files
  1482                              <1> 	      ; / opened by the parent process
  1483                              <1> 	; 01/09/2015
  1484                              <1> 	;xor	bh, bh
  1485                              <1> 	;mov 	bl, [esi+u.fp]
  1486 0000D2AC 8A86[7E940100]      <1> 	mov 	al, [esi+u.fp]
  1487                              <1> 		; movb u.fp(r1),r2 / get an open file for this process
  1488                              <1>         ;or	bl, bl
  1489 0000D2B2 08C0                <1> 	or	al, al
  1490 0000D2B4 7406                <1> 	jz	short sysfork_5	
  1491                              <1> 		; beq 2f / file has not been opened by parent,
  1492                              <1> 		       ; / so branch
  1493                              <1> 	;mov	ah, 10 ; Retro UNIX 386 v1 fsp structure size = 10 bytes
  1494                              <1> 	;mul	ah
  1495                              <1> 	; 23/07/2022
  1496                              <1> 	; Retro UNIX 386 v2 & TRDOS 386 v2.0.5 fsp struc size = 16 bytes
  1497                              <1> 	;mov	ebx, eax
  1498                              <1> 	;shl	ebx, 4 ; * 16
  1499                              <1> 	;inc	byte [ebx+fsp-10]
  1500                              <1> 
  1501                              <1> 	; 23/07/2022 (BugFix)
  1502 0000D2B6 FE80[608A0100]      <1> 	inc	byte [OF_OPENCOUNT+eax]
  1503                              <1> 
  1504                              <1> 	;;movzx	ebx, ax
  1505                              <1> 	;mov	bx, ax
  1506                              <1> 	;shl	bx, 3
  1507                              <1> 		; asl r2 / multiply by 8
  1508                              <1>        		; asl r2 / to get index into fsp table
  1509                              <1>        		; asl r2
  1510                              <1>   	;inc	byte [ebx+fsp-2]
  1511                              <1> 		; incb fsp-2(r2) / increment number of processes
  1512                              <1> 			     ; / using file, because child will now be
  1513                              <1> 			     ; / using this file
  1514                              <1> sysfork_5: ; 2:
  1515 0000D2BC 46                  <1>         inc     esi
  1516                              <1> 		; inc r1 / get next open file
  1517                              <1> 	; 23/07/2022
  1518 0000D2BD 6683FE20            <1> 	cmp	si, OPENFILES ; = 10
  1519                              <1> 	;cmp	si, 10
  1520                              <1> 		; cmp r1,$10. / 10. files is the maximum number which
  1521                              <1> 			    ; / can be opened
  1522 0000D2C1 72E9                <1> 	jb	short sysfork_4	
  1523                              <1> 		; blt 1b / check next entry
  1524 0000D2C3 E98CFBFFFF          <1> 	jmp	sysret
  1525                              <1> 		; br sysret1
  1526                              <1> 
  1527                              <1> syscreat: ; < create file >
  1528                              <1> 	; 29/08/2024
  1529                              <1> 	; 25/08/2024 - TRDOS 386 v2.0.9	
  1530                              <1> 	; 08/08/2022
  1531                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
  1532                              <1> 	; 13/11/2017
  1533                              <1> 	; 27/10/2016
  1534                              <1> 	; 25/10/2016 - 26/10/2016
  1535                              <1> 	; 15/10/2016 - 16/10/2016 - 17/10/2016
  1536                              <1> 	; 10/10/2016 (TRDOS 386 = TRDOS v2.0)
  1537                              <1> 	;	     -derived from INT_21H.ASM-
  1538                              <1> 	;            ("loc_INT21h_create_file")
  1539                              <1>         ; 	10/07/2011 (12/03/2011)
  1540                              <1>         ;	INT 21h Function AH = 3Ch
  1541                              <1>         ;	Create File
  1542                              <1>         ;	INPUT
  1543                              <1>         ;	   CX = Attributes
  1544                              <1>         ;          DS:DX= Address of zero terminaned path name
  1545                              <1>         ;
  1546                              <1> 	; 27/12/2015 (Retro UNIX 386 v1.1)
  1547                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
  1548                              <1> 	; 27/05/2013 (Retro UNIX 8086 v1)
  1549                              <1> 	;
  1550                              <1> 	; 'syscreat' called with two arguments; name and mode.
  1551                              <1> 	; u.namep points to name of the file and mode is put
  1552                              <1> 	; on the stack. 'namei' is called to get i-number of the file.
  1553                              <1> 	; If the file aready exists, it's mode and owner remain 
  1554                              <1> 	; unchanged, but it is truncated to zero length. If the file
  1555                              <1> 	; did not exist, an i-node is created with the new mode via
  1556                              <1> 	; 'maknod' whether or not the file already existed, it is
  1557                              <1> 	; open for writing. The fsp table is then searched for a free
  1558                              <1> 	; entry. When a free entry is found, proper data is placed
  1559                              <1> 	; in it and the number of this entry is put in the u.fp list.
  1560                              <1> 	; The index to the u.fp (also know as the file descriptor)
  1561                              <1> 	; is put in the user's r0.
  1562                              <1> 	;
  1563                              <1> 	; Calling sequence:
  1564                              <1> 	;	syscreate; name; mode
  1565                              <1> 	; Arguments:
  1566                              <1> 	;	name - name of the file to be created
  1567                              <1> 	;	mode - mode of the file to be created
  1568                              <1> 	; Inputs: (arguments)
  1569                              <1> 	; Outputs: *u.r0 - index to u.fp list 
  1570                              <1> 	;		   (the file descriptor of new file)
  1571                              <1> 	; ...............................................................
  1572                              <1> 	;
  1573                              <1> 	; Retro UNIX 8086 v1 modification:
  1574                              <1> 	;       'syscreate' system call has two arguments; so,
  1575                              <1> 	;	* 1st argument, name is pointed to by BX register
  1576                              <1> 	;	* 2nd argument, mode is in CX register
  1577                              <1> 	;
  1578                              <1> 	;	AX register (will be restored via 'u.r0') will return
  1579                              <1> 	;	to the user with the file descriptor/number 
  1580                              <1> 	;	(index to u.fp list).
  1581                              <1> 	;
  1582                              <1> 	;call	arg2
  1583                              <1> 	; * name - 'u.namep' points to address of file/path name
  1584                              <1> 	;          in the user's program segment ('u.segmnt')
  1585                              <1> 	;          with offset in BX register (as sysopen argument 1).
  1586                              <1> 	; * mode - sysopen argument 2 is in CX register 
  1587                              <1> 	;          which is on top of stack.
  1588                              <1> 	;
  1589                              <1> 	; TRDOS 386 (10/10/2016)
  1590                              <1> 	;
  1591                              <1>         ; INPUT ->
  1592                              <1>         ;	   CL = File Attributes
  1593                              <1> 	;     	      bit 0 (1) - Read only file (R)
  1594                              <1> 	;             bit 1 (1) - Hidden file (H)
  1595                              <1>         ;             bit 2 (1) - System file (R)
  1596                              <1> 	;             bit 3 (1) - Volume label/name (V)
  1597                              <1>         ;             bit 4 (1) - Subdirectory (D)
  1598                              <1> 	;	      bit 5 (1) - File has been archived (A)
  1599                              <1>         ;          EBX = Pointer to filename (ASCIIZ) -path-
  1600                              <1> 	;
  1601                              <1> 	; OUTPUT ->
  1602                              <1> 	;          eax = File/Device Handle/Number (index) (AL)
  1603                              <1> 	;          cf = 1 -> Error code in AL
  1604                              <1> 	;
  1605                              <1> 	; Modified Registers: EAX (at the return of system call)
  1606                              <1> 	; 
  1607                              <1> 	; Note: If the file is existing and it has not any one
  1608                              <1> 	;	of S,H,R,V,D attributes, it will be truncated
  1609                              <1> 	;	to zero length; otherwise, access error will be
  1610                              <1> 	;	returned.
  1611                              <1> 
  1612                              <1> sysmkdir_0:
  1613 0000D2C8 F6C108              <1> 	test	cl, 08h ; Volume name
  1614 0000D2CB 740A                <1> 	jz	short syscreat_0
  1615                              <1> 
  1616                              <1> 	; Volume name or long name creation
  1617                              <1> 	; is not permitted (in TRDOS 386)!
  1618 0000D2CD B80B000000          <1> 	mov	eax, ERR_FILE_ACCESS  ; 11 ; 'permission denied !'
  1619 0000D2D2 E9D8000000          <1>         jmp	sysopen_dev_err ; 08/08/2022
  1620                              <1> syscreat_0:
  1621                              <1>         ;mov	[u.namep], ebx
  1622 0000D2D7 51                  <1> 	push	ecx
  1623 0000D2D8 89DE                <1> 	mov	esi, ebx
  1624                              <1> 	; file name is forced, change directory as temporary
  1625                              <1> 	;mov	ax, 1
  1626                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset ; 17/10/2016
  1627                              <1> 	;call	set_working_path 
  1628 0000D2DA E803500000          <1> 	call	set_working_path_x ; 17/10/2016	
  1629                              <1> 	;jc	short syscreat_err
  1630                              <1> 	; 23/07/2022
  1631 0000D2DF 7305                <1> 	jnc	short syscreat_3
  1632 0000D2E1 E9E2000000          <1> 	jmp	syscreat_err
  1633                              <1> 
  1634                              <1> syscreat_3:
  1635                              <1> 	; 16/10/2016
  1636 0000D2E6 803D[77890100]00    <1> 	cmp	byte [SWP_inv_fname], 0
  1637 0000D2ED 7776                <1> 	ja	short syscreat_inv_fname ; invalid file name !
  1638                              <1> 
  1639                              <1> 	; Here, we have a valid path and also a valid file name
  1640                              <1> 	; (Working dir has been changed if the path
  1641                              <1> 	;  -file name string- had contained a dir name.)
  1642                              <1> 
  1643                              <1> 	;xor	ax, ax
  1644                              <1> 	; 25/08/2024
  1645 0000D2EF 31C0                <1> 	xor	eax, eax
  1646                              <1> 	;mov	esi, FindFile_Name
  1647 0000D2F1 E874B8FFFF          <1> 	call	find_first_file
  1648 0000D2F6 59                  <1> 	pop	ecx
  1649                              <1> 		; ESI = Directory Entry (FindFile_DirEntry) Location
  1650                              <1> 		; EDI = Directory Buffer Directory Entry Location
  1651                              <1> 		; EAX = File Size
  1652                              <1> 		;  BL = Attributes of The File/Directory
  1653                              <1> 		;  BH = Long Name Yes/No Status (>0 is YES)
  1654                              <1> 		;  DX > 0 : Ambiguous filename chars are used
  1655 0000D2F7 7274                <1> 	jc	short syscreat_1 ; file not found (the good!)
  1656                              <1> 				 ; or another error (the bad!)
  1657                              <1> 
  1658                              <1> 	; (& the uggly!) truncate file to zero length before open
  1659                              <1> 
  1660                              <1> 	;'*' and '?' already checked at 'set_working_path' stage
  1661                              <1> 	;and	dx, dx
  1662                              <1> 	;jnz	short sysmkdir_err ; permission denied
  1663                              <1> 				   ; invalid filename chars
  1664                              <1> 
  1665                              <1> 	;test	cl, 10h ; subdirectory ?
  1666                              <1> 	;jnz	short sysmkdir_err
  1667                              <1> 
  1668                              <1> 	; BL = File Attributes:
  1669                              <1> 	;     	      bit 0 (1) - Read only file (R)
  1670                              <1> 	;             bit 1 (1) - Hidden file (H)
  1671                              <1>         ;             bit 2 (1) - System file (R)
  1672                              <1> 	;             bit 3 (1) - Volume label/name (V)
  1673                              <1>         ;             bit 4 (1) - Subdirectory (D)
  1674                              <1> 	;	      bit 5 (1) - File has been archived
  1675                              <1> 
  1676                              <1> 	; * existing directory must not be truncated
  1677                              <1> 	;   (we don't know it is empty or not, at this stage)
  1678                              <1> 	; * existing volume name (or a long name) can not be
  1679                              <1> 	;   re-created or truncated by 'syscreat'
  1680                              <1> 	; * A file with S, H, R attributes must not be truncated
  1681                              <1> 	;   (change attributes to normal, if you need truncate it)
  1682                              <1> 
  1683 0000D2F9 F6C31F              <1> 	test	bl, 00011111b  ; check attributes of existing file
  1684 0000D2FC 7559                <1> 	jnz	short sysmkdir_err
  1685                              <1> 
  1686                              <1> 	;; normal file, OK to continue...
  1687                              <1> 
  1688                              <1> 	; ESI = FindFile_DirEntry
  1689 0000D2FE 668B4614            <1> 	mov	ax, [esi+DirEntry_FstClusHI] ; 20
  1690 0000D302 C1E010              <1> 	shl	eax, 16 ; 13/11/2017
  1691 0000D305 668B461A            <1> 	mov	ax, [esi+DirEntry_FstClusLO] ; 26
  1692                              <1> 
  1693                              <1> 	; 24/08/2024
  1694 0000D309 21C0                <1> 	and	eax, eax
  1695 0000D30B 7426                <1> 	jz	short skip_truncate ; first cluster is 0 !
  1696                              <1> 
  1697                              <1> 	; EAX = First cluster to be truncated/unlinked
  1698 0000D30D 57                  <1> 	push	edi
  1699 0000D30E 51                  <1> 	push	ecx
  1700 0000D30F BE00010900          <1> 	mov	esi, Logical_DOSDisks
  1701 0000D314 29C9                <1> 	sub	ecx, ecx
  1702                              <1> 	;mov	ch, [Current_Drv] ; = [FindFile_Drv]
  1703                              <1> 	; 03/09/2024
  1704 0000D316 8A2D[22860100]      <1> 	mov	ch, [FindFile_Drv]
  1705 0000D31C 01CE                <1> 	add	esi, ecx
  1706                              <1> 	; ESI = Logical dos drive description table address
  1707 0000D31E E89EF7FFFF          <1> 	call	truncate_cluster_chain
  1708 0000D323 59                  <1> 	pop	ecx
  1709 0000D324 5F                  <1> 	pop	edi
  1710 0000D325 7237                <1> 	jc	short syscreate_truncate_err
  1711                              <1> 
  1712                              <1> 	; 03/09/2024
  1713 0000D327 66C747140000        <1> 	mov	word [edi+DirEntry_FstClusHI], 0
  1714 0000D32D 66C7471A0000        <1> 	mov	word [edi+DirEntry_FstClusLO], 0
  1715                              <1> 
  1716                              <1> 	; 24/08/2024
  1717                              <1> skip_truncate:
  1718                              <1> 	; 26/10/2016
  1719                              <1> 	; EDI = Directory entry address in directory buffer
  1720                              <1> 	; Update directory entry
  1721 0000D333 E884DCFFFF          <1> 	call	convert_current_date_time
  1722                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
  1723                              <1>         ; 	    AX = Time in dos dir entry format
  1724 0000D338 66894716            <1> 	mov	[edi+DirEntry_WrtTime], ax
  1725 0000D33C 66895718            <1> 	mov	[edi+DirEntry_WrtDate], dx
  1726 0000D340 66895712            <1> 	mov	[edi+DirEntry_LastAccDate], dx
  1727 0000D344 31C0                <1> 	xor	eax, eax ; file size = 0 
  1728 0000D346 89471C              <1> 	mov	[edi+DirEntry_FileSize], eax ; 0
  1729 0000D349 C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2 ; data changed sign	
  1730                              <1> 	;mov	esi, FindFile_DirEntry
  1731                              <1> 	; 03/09/2024
  1732 0000D350 B201                <1> 	mov	dl, 1 ; open file for writing
  1733 0000D352 E9AB000000          <1> 	jmp	sysopen_2 ; 08/08/2022
  1734                              <1> 
  1735                              <1> sysmkdir_err:
  1736                              <1> 	; 1 = write, 2 = read & write, >2 = invalid
  1737 0000D357 B80B000000          <1>         mov	eax, ERR_FILE_ACCESS  ; 11 ; 'permission denied !'
  1738 0000D35C EB74                <1>         jmp	short sysopen_err
  1739                              <1> 
  1740                              <1> syscreate_truncate_err:
  1741 0000D35E B812000000          <1> 	mov	eax, ERR_DRV_WRITE ; 18 ; 'disk write error !'
  1742 0000D363 EB6D                <1>         jmp	short sysopen_err
  1743                              <1> 
  1744                              <1> syscreat_inv_fname:  ; invalid file name chars
  1745                              <1> 	; 16/10/2016
  1746 0000D365 B81A000000          <1> 	mov	eax, ERR_INV_FILE_NAME  ; 26 ; invalid file name chars 
  1747 0000D36A 59                  <1> 	pop	ecx
  1748 0000D36B EB65                <1> 	jmp	short sysopen_err
  1749                              <1> 
  1750                              <1> syscreat_1:
  1751                              <1> 	; Error code in EAX
  1752 0000D36D 3C02                <1>         cmp	al, 02h ; 'File not found' error
  1753 0000D36F 7561                <1>         jne	short sysopen_err
  1754                              <1> 
  1755 0000D371 F6C110              <1> 	test	cl, 10h ; Directory
  1756                              <1> 	;jnz	sysmkdir_2
  1757                              <1> 	; 23/07/2022
  1758 0000D374 7405                <1> 	jz	short syscreat_2
  1759 0000D376 E9CC010000          <1> 	jmp	sysmkdir_2
  1760                              <1> 
  1761                              <1> syscreat_2:
  1762 0000D37B BE[64860100]        <1> 	mov	esi, FindFile_Name
  1763                              <1>         ;xor	edx, edx
  1764 0000D380 31C0                <1>         xor	eax, eax ; File Size  = 0
  1765 0000D382 31DB                <1> 	xor	ebx, ebx
  1766 0000D384 4B                  <1> 	dec 	ebx ; FFFFFFFFh -> create empty file
  1767                              <1> 	            ;              (only for FAT fs)
  1768                              <1> 	; CL = File Attributes
  1769 0000D385 E85CECFFFF          <1> 	call	create_file
  1770 0000D38A 7246                <1> 	jc	short sysopen_err
  1771                              <1> 		; EAX = New file's first cluster
  1772                              <1> 		; ESI = Logical Dos Drv Descr. Table Addr.
  1773                              <1> 		; EBX = offset CreateFile_Size
  1774                              <1> 		; ECX = Sectors per cluster (<256) 
  1775                              <1> 		; EDX = Directory entry index/number (<65536)
  1776                              <1> 		; 29/08/2024
  1777                              <1> 		; EBX = File Size (0 for a new, empty file)
  1778                              <1> 		; ECX = Directory Entry Index/Number (<2048)
  1779                              <1> 		;      (in directory cluster, not in directory)
  1780                              <1> 		; EDX = Directory Cluster Number (of the file)
  1781                              <1> 
  1782                              <1> 	; 26/10/2016
  1783                              <1> 	;mov	esi, Directory_Buffer
  1784                              <1> 	;shl	dx, 5 ; *32
  1785                              <1> 	;add	esi, edx
  1786                              <1> 	;; esi = directory entry address in directory buffer
  1787                              <1> 
  1788                              <1> 	; Here, directory entry has been created but last
  1789                              <1> 	; modification date & time of the parent dir has not
  1790                              <1> 	; been updated, yet! 
  1791                              <1> 	; (Note: Directory and FAT buffers have been updated...)
  1792                              <1> 
  1793 0000D38C E858DDFFFF          <1> 	call	update_parent_dir_lmdt ; now, it is OK too!
  1794                              <1> 
  1795                              <1> 	; 25/10/2016
  1796 0000D391 66B80018            <1> 	mov	ax, 1800h
  1797 0000D395 BE[64860100]        <1> 	mov	esi, FindFile_Name
  1798 0000D39A E8CBB7FFFF          <1> 	call	find_first_file
  1799 0000D39F 7231                <1> 	jc	short sysopen_err
  1800                              <1> 
  1801                              <1> 	; Only possible error after here is
  1802                              <1> 	; "too many open files !" error.
  1803                              <1> 	;
  1804                              <1> 	; If "syscreat" will return with that error,
  1805                              <1> 	; (the file has been created but it could not be opened)
  1806                              <1> 	; the user must retry to open this file again
  1807                              <1> 	; or must close another file before using 
  1808                              <1> 	; "sysopen" system call.
  1809                              <1> 
  1810 0000D3A1 B201                <1> 	mov	dl, 1 ; open file for writing
  1811                              <1> 	; ESI = Directory Entry (FindFile_DirEntry) Location
  1812                              <1> 	; EAX = File Size (= 0)
  1813 0000D3A3 EB5D                <1> 	jmp	short sysopen_2
  1814                              <1> 
  1815                              <1> sysopen: ;<open file>
  1816                              <1> 	; 03/09/2024
  1817                              <1> 	; 19/08/2024 - TRDOS 386 v2.0.9
  1818                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
  1819                              <1> 	; 17/04/2021 - TRDOS 386 v2.0.4
  1820                              <1> 	;	(temporary modifications)
  1821                              <1> 	; 26/10/2016
  1822                              <1> 	; 24/10/2016
  1823                              <1> 	; 17/10/2016
  1824                              <1> 	; 15/10/2016
  1825                              <1> 	; 06/10/2016, 07/10/2016, 08/10/2016
  1826                              <1> 	; 05/10/2016 (TRDOS 386 = TRDOS v2.0)
  1827                              <1> 	;	     -derived from INT_21H.ASM-
  1828                              <1> 	;            ("loc_INT21h_open_file")
  1829                              <1>         ; 	26/02/2011 
  1830                              <1>         ;	INT 21h Function AH = 3Dh
  1831                              <1>         ;	Open File
  1832                              <1>         ;	INPUT
  1833                              <1>         ;	   AL= File Access Value
  1834                              <1> 	;     	     0- Open for reading
  1835                              <1> 	;            1- Open for writing
  1836                              <1>         ;            2- Open for reading and writing
  1837                              <1>         ;          DS:DX= Pointer to filename (ASCIIZ)
  1838                              <1>         ;
  1839                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
  1840                              <1> 	; 22/05/2013 - 27/05/2013 (Retro UNIX 8086 v1)
  1841                              <1> 	;
  1842                              <1> 	; 'sysopen' opens a file in following manner:
  1843                              <1> 	;    1) The second argument in a sysopen says whether to
  1844                              <1> 	;	open the file ro read (0) or write (>0).
  1845                              <1> 	;    2) I-node of the particular file is obtained via 'namei'.
  1846                              <1> 	;    3) The file is opened by 'iopen'.
  1847                              <1> 	;    4) Next housekeeping is performed on the fsp table
  1848                              <1> 	;	and the user's open file list - u.fp.
  1849                              <1> 	;	a) u.fp and fsp are scanned for the next available slot.
  1850                              <1> 	;	b) An entry for the file is created in the fsp table.
  1851                              <1> 	;	c) The number of this entry is put on u.fp list.
  1852                              <1> 	;	d) The file descriptor index to u.fp list is pointed
  1853                              <1> 	;	   to by u.r0.
  1854                              <1> 	;
  1855                              <1> 	; Calling sequence:
  1856                              <1> 	;	sysopen; name; mode
  1857                              <1> 	; Arguments:
  1858                              <1> 	;	name - file name or path name
  1859                              <1> 	;	mode - 0 to open for reading
  1860                              <1> 	;	       1 to open for writing
  1861                              <1> 	; Inputs: (arguments)
  1862                              <1> 	; Outputs: *u.r0 - index to u.fp list (the file descriptor)
  1863                              <1> 	;		  is put into r0's location on the stack.
  1864                              <1> 	; ...............................................................
  1865                              <1> 	;
  1866                              <1> 	; Retro UNIX 8086 v1 modification:
  1867                              <1> 	;       'sysopen' system call has two arguments; so,
  1868                              <1> 	;	* 1st argument, name is pointed to by BX register
  1869                              <1> 	;	* 2nd argument, mode is in CX register
  1870                              <1> 	;
  1871                              <1> 	;	AX register (will be restored via 'u.r0') will return
  1872                              <1> 	;	to the user with the file descriptor/number 
  1873                              <1> 	;	(index to u.fp list).
  1874                              <1> 	;
  1875                              <1> 	;call	arg2
  1876                              <1> 	; * name - 'u.namep' points to address of file/path name
  1877                              <1> 	;          in the user's program segment ('u.segmnt')
  1878                              <1> 	;          with offset in BX register (as sysopen argument 1).
  1879                              <1> 	; * mode - sysopen argument 2 is in CX register 
  1880                              <1> 	;          which is on top of stack.
  1881                              <1> 	;
  1882                              <1> 	; jsr r0,arg2 / get sys args into u.namep and on stack
  1883                              <1> 	;
  1884                              <1>        	; system call registers: ebx, ecx (through 'sysenter')
  1885                              <1> 	;
  1886                              <1> 	; TRDOS 386 (05/10/2016)
  1887                              <1> 	;
  1888                              <1>         ; INPUT ->
  1889                              <1>         ;	   CL = File Access Value (Open Mode)
  1890                              <1> 	;     	      0 - Open file for reading
  1891                              <1> 	;             1 - Open file for writing
  1892                              <1>         ;             2 - Open device for reading
  1893                              <1> 	;	      3 - Open device for writing
  1894                              <1>         ;          EBX = Pointer to filename/devicename (ASCIIZ)
  1895                              <1> 	; OUTPUT ->
  1896                              <1> 	;          eax = File/Device Handle/Number (index) (AL)
  1897                              <1> 	;          cf = 1 -> Error code in AL
  1898                              <1> 	;
  1899                              <1> 	; Modified Registers: EAX (at the return of system call)
  1900                              <1> 	;
  1901                              <1> 
  1902 0000D3A5 80F901              <1> 	cmp	cl, 1 ; read file (0), write file (1)
  1903 0000D3A8 7614                <1> 	jna	short sysopen_0
  1904                              <1> 
  1905                              <1> 	; 17/04/2021 (temporary)
  1906                              <1> 	;cmp	cl, 3
  1907                              <1> 	;jna	sysopen_device
  1908                              <1> 
  1909                              <1> 	; Invalid access code
  1910 0000D3AA B817000000          <1> 	mov	eax, ERR_INV_PARAMETER
  1911                              <1> 	;jmp	sysopen_dev_err
  1912                              <1> 
  1913                              <1> sysopen_dev_err:
  1914 0000D3AF A3[74940100]        <1> 	mov	[u.r0], eax
  1915 0000D3B4 A3[E0940100]        <1> 	mov	[u.error], eax
  1916 0000D3B9 E976FAFFFF          <1> 	jmp	error
  1917                              <1> 
  1918                              <1> sysopen_0:
  1919                              <1> 	;mov	[u.namep], ebx
  1920 0000D3BE 51                  <1> 	push	ecx
  1921 0000D3BF 89DE                <1> 	mov	esi, ebx
  1922                              <1> 	; file name is forced, change directory as temporary
  1923                              <1> 	;mov	ax, 1
  1924                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset ; 17/10/2016
  1925                              <1> 	;call	set_working_path
  1926 0000D3C1 E81C4F0000          <1> 	call	set_working_path_x ; 17/10/2016	
  1927 0000D3C6 731E                <1> 	jnc	short sysopen_1
  1928                              <1> 
  1929                              <1> syscreat_err: ; ecx = file attributes (for 'syscreat')
  1930 0000D3C8 59                  <1> 	pop	ecx ; open mode  
  1931 0000D3C9 21C0                <1> 	and	eax, eax  ; 0 -> Bad Path!
  1932 0000D3CB 7505                <1> 	jnz	short sysopen_err
  1933                              <1> 	; eax = 0
  1934 0000D3CD B80C000000          <1> 	mov	eax, ERR_DIR_NOT_FOUND ; Directory not found !
  1935                              <1> sysopen_err:
  1936 0000D3D2 A3[74940100]        <1> 	mov	[u.r0], eax
  1937 0000D3D7 A3[E0940100]        <1> 	mov	[u.error], eax
  1938 0000D3DC E8D64F0000          <1> 	call 	reset_working_path
  1939 0000D3E1 E94EFAFFFF          <1> 	jmp	error
  1940                              <1> 
  1941                              <1> sysopen_1:
  1942                              <1> 	;mov	esi, FindFile_Name
  1943 0000D3E6 66B80018            <1>         mov	ax, 1800h ; Only files
  1944 0000D3EA E87BB7FFFF          <1> 	call	find_first_file
  1945 0000D3EF 5A                  <1> 	pop	edx
  1946 0000D3F0 72E0                <1> 	jc	short sysopen_err ; eax = 2 (File not found !)
  1947                              <1> 
  1948                              <1> 	; check_open_file_attr_access_code
  1949                              <1> 
  1950 0000D3F2 F6C307              <1>         test	bl, 7  ; system, hidden, readonly
  1951 0000D3F5 740B                <1>         jz	short sysopen_2
  1952                              <1> 
  1953 0000D3F7 20D2                <1> 	and	dl, dl ; 0 = read mode
  1954 0000D3F9 7407                <1> 	jz	short sysopen_2
  1955                              <1> 
  1956                              <1> sysopen_access_err:
  1957                              <1> 	; 1 = write, 2 = read & write, >2 = invalid
  1958 0000D3FB B80B000000          <1>         mov	eax, ERR_FILE_ACCESS ; 11 = 'permission denied !'
  1959 0000D400 EBD0                <1>         jmp	short sysopen_err
  1960                              <1> 
  1961                              <1> sysopen_2:
  1962                              <1> 	; esi = Directory Entry (FindFile_DirEntry) Location
  1963                              <1> 	;mov	ebx, esi
  1964                              <1>         ; 03/09/2024
  1965 0000D402 89FB                <1> 	mov	ebx, edi ; Directory entry in directory buffer
  1966 0000D404 31F6                <1> 	xor     esi, esi ; 0
  1967 0000D406 31FF                <1>         xor     edi, edi ; 0
  1968                              <1> sysopen_3: ; scan the list of entries in fsp table
  1969 0000D408 80BE[7E940100]00    <1>         cmp     byte [esi+u.fp], 0
  1970 0000D40F 760E                <1>         jna     short sysopen_4 ; empty slot
  1971                              <1>         ;inc	si
  1972                              <1> 	; 19/08/2024
  1973 0000D411 46                  <1> 	inc	esi
  1974 0000D412 6683FE0A            <1>         cmp     si, 10
  1975 0000D416 72F0                <1> 	jb	short sysopen_3
  1976                              <1> toomanyf:
  1977 0000D418 B80D000000          <1> 	mov	eax, ERR_TOO_MANY_FILES ; too many open files !
  1978 0000D41D EBB3                <1> 	jmp	short sysopen_err
  1979                              <1> 
  1980                              <1> sysopen_4: 
  1981 0000D41F 80BF[208A0100]00    <1>         cmp     byte [edi+OF_MODE], 0 ; Scan open files table
  1982 0000D426 7609                <1> 	jna     short sysopen_5
  1983                              <1> 
  1984                              <1> 	;inc	di
  1985                              <1> 	; 19/08/2024
  1986 0000D428 47                  <1> 	inc	edi
  1987 0000D429 6683FF20            <1> 	cmp     di, OPENFILES ; max. number of open files (sytem)
  1988 0000D42D 72F0                <1> 	jb	short sysopen_4
  1989 0000D42F EBE7                <1> 	jmp	short toomanyf
  1990                              <1> 
  1991                              <1> sysopen_5:
  1992                              <1> 	; 19/08/2024
  1993                              <1> 	;;;
  1994 0000D431 50                  <1> 	push	eax ; size
  1995 0000D432 668B4314            <1>         mov 	ax, [ebx+DirEntry_FstClusHI]
  1996 0000D436 C1E010              <1> 	shl	eax, 16
  1997 0000D439 668B431A            <1> 	mov 	ax, [ebx+DirEntry_FstClusLO]
  1998 0000D43D 5B                  <1> 	pop	ebx ; size
  1999                              <1> 	; eax = First Cluster
  2000                              <1> 	; ebx = File Size
  2001 0000D43E 80FA01              <1> 	cmp	dl, 1 ; is open mode = open for write ?
  2002 0000D441 7535                <1> 	jne	short sysopen_8
  2003                              <1> 	; check if the file is already open for write
  2004 0000D443 57                  <1> 	push	edi
  2005 0000D444 29FF                <1> 	sub	edi, edi
  2006 0000D446 8A15[22860100]      <1> 	mov	dl, [FindFile_Drv]
  2007                              <1> sysopen_5_@:
  2008 0000D44C 80BF[208A0100]02    <1> 	cmp 	byte [edi+OF_MODE], 2 ; open for write
  2009 0000D453 7519                <1> 	jne	short sysopen_5_@@@
  2010 0000D455 3A97[008A0100]      <1> 	cmp	dl, [edi+OF_DRIVE]
  2011 0000D45B 7511                <1> 	jne	short sysopen_5_@@@
  2012 0000D45D C1E702              <1> 	shl 	edi, 2
  2013 0000D460 3B87[80890100]      <1> 	cmp	eax, [edi+OF_FCLUSTER]
  2014 0000D466 7503                <1> 	jne	short sysopen_5_@@
  2015 0000D468 5F                  <1> 	pop	edi
  2016 0000D469 EB90                <1> 	jmp	short sysopen_access_err
  2017                              <1> sysopen_5_@@:
  2018 0000D46B C1EF02              <1> 	shr 	edi, 2
  2019                              <1> 	;;;
  2020                              <1> sysopen_5_@@@:
  2021 0000D46E 47                  <1> 	inc	edi
  2022 0000D46F 6683FF20            <1> 	cmp	di, OPENFILES
  2023 0000D473 72D7                <1> 	jb	short sysopen_5_@
  2024 0000D475 5F                  <1> 	pop	edi
  2025 0000D476 B201                <1> 	mov	dl, 1 ; open for write
  2026                              <1> sysopen_8:
  2027 0000D478 FEC2                <1> 	inc	dl
  2028 0000D47A 8897[208A0100]      <1>         mov     [edi+OF_MODE], dl
  2029 0000D480 8A15[22860100]      <1> 	mov	dl, [FindFile_Drv]
  2030 0000D486 8897[008A0100]      <1>         mov     [edi+OF_DRIVE], dl ; Logical DOS drive number
  2031                              <1> 	;shl	di, 2 ; *4 (dword offset)
  2032                              <1> 	; 23/07/2022
  2033 0000D48C C1E702              <1> 	shl	edi, 2
  2034                              <1> 
  2035                              <1> 	; 19/08/2024
  2036                              <1> 	;mov	[edi+OF_SIZE], eax ; File size in bytes
  2037 0000D48F 899F[008B0100]      <1> 	mov	[edi+OF_SIZE], ebx ; File size in bytes
  2038                              <1> 
  2039                              <1> 	; 19/08/2024
  2040                              <1> 	; eax = Fist Cluster
  2041                              <1>         ;mov 	ax, [ebx+DirEntry_FstClusHI]
  2042                              <1> 	;shl	eax, 16
  2043                              <1> 	;mov 	ax, [ebx+DirEntry_FstClusLO]
  2044                              <1> 
  2045 0000D495 8987[80890100]      <1> 	mov     [edi+OF_FCLUSTER], eax ; First cluster
  2046 0000D49B 8987[008D0100]      <1> 	mov     [edi+OF_CCLUSTER], eax ; Current cluster
  2047                              <1> 
  2048 0000D4A1 31DB                <1>         xor	ebx, ebx
  2049 0000D4A3 899F[808A0100]      <1>         mov     [edi+OF_POINTER], ebx ; offset pointer (0)
  2050 0000D4A9 899F[808D0100]      <1>         mov     [edi+OF_CCINDEX], ebx ; cluster index (0)
  2051                              <1> 
  2052 0000D4AF A1[94860100]        <1> 	mov	eax, [FindFile_DirFirstCluster]
  2053 0000D4B4 8987[808B0100]      <1> 	mov	[edi+OF_DIRFCLUSTER], eax
  2054                              <1> 
  2055 0000D4BA A1[98860100]        <1> 	mov	eax, [FindFile_DirCluster]
  2056 0000D4BF 8987[008C0100]      <1> 	mov	[edi+OF_DIRCLUSTER], eax
  2057                              <1> 
  2058                              <1> 	; Get (& Save) Volume ID
  2059                              <1> 	; Important for files of removable drives
  2060                              <1> 	; (In order to check the drive has same volume/disk)
  2061 0000D4C5 88D7                <1> 	mov	bh, dl
  2062 0000D4C7 81C300010900        <1>         add	ebx, Logical_DOSDisks
  2063 0000D4CD 8A4303              <1>         mov	al, [ebx+LD_FATType]
  2064 0000D4D0 3C01                <1>         cmp	al, 1
  2065 0000D4D2 7209                <1>         jb	short sysopen_6_fs
  2066 0000D4D4 3C02                <1>         cmp	al, 2
  2067 0000D4D6 770A                <1>         ja	short sysopen_6_fat32
  2068                              <1> sysopen_6_fat:
  2069 0000D4D8 8B432D              <1>         mov	eax, [ebx+LD_BPB+VolumeID]
  2070 0000D4DB EB08                <1>         jmp	short sysopen_7
  2071                              <1> sysopen_6_fs:
  2072 0000D4DD 8B4328              <1>         mov	eax, [ebx+LD_FS_VolumeSerial]
  2073 0000D4E0 EB03                <1>         jmp	short sysopen_7
  2074                              <1> sysopen_6_fat32:
  2075 0000D4E2 8B4349              <1>         mov	eax, [ebx+LD_BPB+FAT32_VolID]
  2076                              <1> sysopen_7:
  2077 0000D4E5 A3[787D0100]        <1>         mov	[Current_VolSerial], eax
  2078                              <1> 
  2079 0000D4EA 8987[808C0100]      <1> 	mov	[edi+OF_VOLUMEID], eax
  2080                              <1> 
  2081                              <1> 	; 24/10/2016
  2082                              <1> 	;shr	di, 1 ; 4/2, word offset
  2083                              <1> 	; 23/07/2022
  2084 0000D4F0 D1EF                <1> 	shr	edi, 1
  2085 0000D4F2 668B1D[9C860100]    <1> 	mov	bx, [FindFile_DirEntryNumber]
  2086 0000D4F9 66899F[008E0100]    <1> 	mov	[edi+OF_DIRENTRY], bx
  2087                              <1> 
  2088 0000D500 31D2                <1> 	xor	edx, edx
  2089                              <1> 	;;shr	di, 2 ; /4 (byte offset)
  2090                              <1> 	;shr	di, 1 ; 2/2, byte offset
  2091                              <1> 	; 23/07/2022
  2092 0000D502 D1EF                <1> 	shr	edi, 1
  2093 0000D504 8897[608A0100]      <1> 	mov	byte [edi+OF_OPENCOUNT], dl ; 0
  2094 0000D50A 8897[408A0100]      <1> 	mov	byte [edi+OF_STATUS], dl ; 0
  2095                              <1> 
  2096 0000D510 89FB                <1> 	mov	ebx, edi
  2097 0000D512 FEC3                <1> 	inc	bl
  2098                              <1> 
  2099 0000D514 889E[7E940100]      <1>         mov     [esi+u.fp], bl ; Open File Entry Number
  2100 0000D51A 8935[74940100]      <1> 	mov     [u.r0], esi ; move index to u.fp list
  2101                              <1> 			    ; into eax on stack
  2102                              <1> 
  2103 0000D520 E8924E0000          <1> 	call 	reset_working_path
  2104                              <1> 
  2105 0000D525 E92AF9FFFF          <1> 	jmp	sysret
  2106                              <1> 
  2107                              <1> 
  2108                              <1> ; fsp table (original UNIX v1)
  2109                              <1> ;
  2110                              <1> ;Entry
  2111                              <1> ;          15                                      0
  2112                              <1> ;  1     |---|---------------------------------------|
  2113                              <1> ;        |r/w|       i-number of open file           |
  2114                              <1> ;        |---|---------------------------------------|
  2115                              <1> ;        |               device number               |
  2116                              <1> ;        |-------------------------------------------|
  2117                              <1> ;    (*) | offset pointer, i.e., r/w pointer to file |
  2118                              <1> ;        |-------------------------------------------|
  2119                              <1> ;        |  flag that says    | number of processes  |
  2120                              <1> ;        |   file deleted     | that have file open  |
  2121                              <1> ;        |-------------------------------------------|
  2122                              <1> ;  2     |                                           |
  2123                              <1> ;        |-------------------------------------------|
  2124                              <1> ;        |                                           |
  2125                              <1> ;        |-------------------------------------------|
  2126                              <1> ;        |                                           |
  2127                              <1> ;        |-------------------------------------------|
  2128                              <1> ;        |                                           |
  2129                              <1> ;        |-------------------------------------------|
  2130                              <1> ;  3     |                                           |
  2131                              <1> ;        |                                           |
  2132                              <1> ;
  2133                              <1> ; (*) Retro UNIX 386 v1 modification: 32 bit offset pointer
  2134                              <1> 
  2135                              <1> ; 27/03/2020 - Retro UNIX 386 v2 - FSP (OPEN FILES) TABLE
  2136                              <1> 
  2137                              <1> ;Entry
  2138                              <1> ;         15                    7                   0
  2139                              <1> ;  1     |-------------------------------------------|
  2140                              <1> ;        |   	     i-number of open file           |
  2141                              <1> ;        |-------------------------------------------|
  2142                              <1> ;        |        high word of 32 bit i-number       |
  2143                              <1> ;        |-------------------------------------------|
  2144                              <1> ;        | open mode & status  |   device number     |
  2145                              <1> ;        |-------------------------------------------|
  2146                              <1> ;        |    reserved byte    |     open count      |
  2147                              <1> ;        |-------------------------------------------|
  2148                              <1> ;        | offset pointer, i.e., r/w pointer to file |
  2149                              <1> ;        |-------------------------------------------|
  2150                              <1> ;        |   64 bit file offset pointer (bit 16-31)  |
  2151                              <1> ;        |-------------------------------------------|
  2152                              <1> ;        |   64 bit file offset pointer (bit 32-47)  |
  2153                              <1> ;        |-------------------------------------------|
  2154                              <1> ;        |   64 bit file offset pointer (bit 48-63)  |
  2155                              <1> ;        |-------------------------------------------|
  2156                              <1> ;  2     |                                           |
  2157                              <1> ;        |-------------------------------------------|
  2158                              <1> ;        |                                           |
  2159                              <1> ;        |-------------------------------------------|
  2160                              <1> ;        |                                           |
  2161                              <1> ;        |-------------------------------------------|
  2162                              <1> ;        |                                           |
  2163                              <1> ;        |-------------------------------------------|
  2164                              <1> ;        |                                           |
  2165                              <1> 
  2166                              <1> ; 23/07/2022 - TRDOS 386 Kernel v2.0.5
  2167                              <1> ; OPENFILES equ 10 (sysdefs.s)
  2168                              <1> ;; 06/10/2016
  2169                              <1> ;; Open File Parameters (trdoskx.s)
  2170                              <1> ;OF_FCLUSTER:	resd OPENFILES  ; First clusters of open files
  2171                              <1> ;OF_DRIVE:	resb OPENFILES  ; Logical DOS drive numbers of open files
  2172                              <1> ;OF_MODE:	resb OPENFILES  ; Open mode (1 = read, 2 = write, 3 = r&w)
  2173                              <1> ;OF_STATUS:	resb OPENFILES  ; (bit 0 = read, bit 1 = write)
  2174                              <1> ;OF_OPENCOUNT:	resb OPENFILES  ; Open counts of open files
  2175                              <1> ;OF_POINTER:	resd OPENFILES	; File seek/read/write pointer
  2176                              <1> ;OF_SIZE:	resd OPENFILES	; File sizes of open files (in bytes)
  2177                              <1> ;OF_DIRFCLUSTER: resd OPENFILES  ; Directory First Clusters of open files
  2178                              <1> ;OF_DIRCLUSTER:	resd OPENFILES  ; Directory (Entry) Clusters of open files
  2179                              <1> ;OF_VOLUMEID:	resd OPENFILES  ; Vol ID for removable drives of open files
  2180                              <1> ;OF_CCLUSTER:	resd OPENFILES  ; Current clusters of open files
  2181                              <1> ;OF_CCINDEX:	resd OPENFILES  ; Cluster index numbers of current clusters
  2182                              <1> ;; 24/10/2016
  2183                              <1> ;OF_DIRENTRY:	resw OPENFILES  ; Directory entry index no. in dir cluster
  2184                              <1> 
  2185                              <1> ; 17/04/2021
  2186                              <1> ; ('sysopen_device' procedure is disabled as temporary)
  2187                              <1> 
  2188                              <1> ;sysopen_device:
  2189                              <1> ;	; 15/10/2016
  2190                              <1> ;	; 08/10/2016
  2191                              <1> ;	; 07/10/2016 (TRDOS 386 = TRDOS v2.0)
  2192                              <1> ;	push	ecx ; open mode
  2193                              <1> ;	mov	ebp, esp
  2194                              <1> ;	mov	ecx, 16 ; transfer length = 16 bytes
  2195                              <1> ;	sub	esp, ecx
  2196                              <1> ;	mov	edi, esp ; destination address
  2197                              <1> ;	mov 	esi, ebx ; dev name in user's memory space
  2198                              <1> ;	call	transfer_from_user_buffer
  2199                              <1> ;	jnc	short sysopen_dev_0
  2200                              <1> ;	; eax = ERR_OUT_OF_MEMORY = 4 = ERR_MINOR_IM
  2201                              <1> ;	pop	ecx
  2202                              <1> ;sysopen_dev_err:
  2203                              <1> ;	mov	[u.r0], eax
  2204                              <1> ;	mov	[u.error], eax
  2205                              <1> ;	jmp	error
  2206                              <1> ;sysopen_dev_0:
  2207                              <1> ;	mov	esi, edi ; Device name addr (max. 16 bytes, ASCIIZ)
  2208                              <1> ;			 ; for example: "tty, TTY, /dev/tty"
  2209                              <1> ;	call	get_device_number
  2210                              <1> ;	mov	esp, ebp
  2211                              <1> ;	pop	ecx
  2212                              <1> ;	jnc	short sysopen_dev_1
  2213                              <1> ;	mov	eax, ERR_INV_DEV_NAME ; 24 ; 'invalid device name !'
  2214                              <1> ;	jmp	short sysopen_dev_err
  2215                              <1> ;sysopen_dev_1:
  2216                              <1> ;	; eax = Device Number (AL)
  2217                              <1> ;	;  cl = Open mode (2 = device read, 3 = device write)
  2218                              <1> ;       xor     ebx, ebx ; 0
  2219                              <1> ;sysopen_dev_2: ; scan the list of entries
  2220                              <1> ;       cmp     [ebx+u.fp], bl ; 0
  2221                              <1> ;       jna     short sysopen_dev_3 ; empty slot
  2222                              <1> ;       inc     bl
  2223                              <1> ;       cmp     bl, 10
  2224                              <1> ;	jb	short sysopen_dev_2
  2225                              <1> ;	;
  2226                              <1> ;	mov	eax, ERR_TOO_MANY_FILES ; too many open files !
  2227                              <1> ;	jmp	short sysopen_dev_err
  2228                              <1> ;sysopen_dev_3:
  2229                              <1> ;	mov 	[u.r0], ebx ; File/Device index/handle/descriptor
  2230                              <1> ;	; eax = device number (entry offset)
  2231                              <1> ;	mov	ch, [eax+DEV_ACCESS] ; bit 0 = accessable by users
  2232                              <1> ;				     ; bit 1 = read access perm
  2233                              <1> ;				     ; bit 2 = write access perm
  2234                              <1> ;				     ; bit 3 = IOCTL permit to users
  2235                              <1> ;				     ; bit 4 = block device if set
  2236                              <1> ;				     ; bit 5 = 16 bit or 1024 byte
  2237                              <1> ;				     ; bit 6 = 32 bit or 2048 byte
  2238                              <1> ;				     ; bit 7 = installable device drv
  2239                              <1> ;	test 	ch, 1 ; accessable by normal users (except root)
  2240                              <1> ;	jnz	short sysopen_dev_4 ; yes, permission has been given
  2241                              <1> ;	cmp	byte [u.uid], 0 ; root?
  2242                              <1> ;	jna	short sysopen_dev_4 ; superuser can open all devices
  2243                              <1> ;sysopen_dev_perm_err:
  2244                              <1> ;	mov	eax, ERR_DEV_ACCESS  ; 11 = 'permission denied !'
  2245                              <1> ;	jmp	short sysopen_dev_err
  2246                              <1> ;sysopen_dev_4:
  2247                              <1> ;	shr	ch, 1 ; result: 1 = read, 2 = write, 3 = r & w
  2248                              <1> ;	dec	cl  ; result: 1 = read, 2 = write
  2249                              <1> ;	test	cl, ch
  2250                              <1> ;	jz	short sysopen_dev_perm_err
  2251                              <1> ;
  2252                              <1> ;	shl	ch, 1 ; bit 0 = 0
  2253                              <1> ;	; eax = device number (entry offset)
  2254                              <1> ;	call	device_open
  2255                              <1> ;	jc	short sysopen_dev_perm_err
  2256                              <1> ;
  2257                              <1> ;	; eax = device number (entry offset)
  2258                              <1> ;	or	al, 80h ; set device bit (set bit 7 to 1)
  2259                              <1> ;	mov	ebx, [u.r0]
  2260                              <1> ;	mov	[ebx+u.fp], al	; bit 7 (=1) points to device
  2261                              <1> ;
  2262                              <1> ;	jmp	sysret
  2263                              <1> 
  2264                              <1> sysmkdir: ; < make directory >
  2265                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
  2266                              <1> 	; 15/10/2016
  2267                              <1> 	; 10/10/2016 (TRDOS 386 = TRDOS v2.0)
  2268                              <1> 	;	     -derived from INT_21H.ASM-
  2269                              <1> 	;            ("loc_INT21h_create_file")
  2270                              <1>         ; 	10/07/2011 (12/03/2011)
  2271                              <1>         ;	INT 21h Function AH = 3Ch
  2272                              <1>         ;	Create File
  2273                              <1>         ;	INPUT
  2274                              <1>         ;	   CX = Attributes
  2275                              <1>         ;          DS:DX= Address of zero terminaned path name
  2276                              <1>         ;
  2277                              <1>         ;
  2278                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
  2279                              <1> 	; 27/05/2013 - 02/08/2013 (Retro UNIX 8086 v1)
  2280                              <1> 	;
  2281                              <1> 	; 'sysmkdir' creates an empty directory whose name is
  2282                              <1> 	; pointed to by arg 1. The mode of the directory is arg 2.
  2283                              <1> 	; The special entries '.' and '..' are not present.
  2284                              <1> 	; Errors are indicated if the directory already exists or
  2285                              <1> 	; user is not the super user. 
  2286                              <1> 	;
  2287                              <1> 	; Calling sequence:
  2288                              <1> 	;	sysmkdir; name; mode
  2289                              <1> 	; Arguments:
  2290                              <1> 	;	name - points to the name of the directory
  2291                              <1> 	;	mode - mode of the directory
  2292                              <1> 	; Inputs: (arguments)
  2293                              <1> 	; Outputs: -
  2294                              <1> 	;    (sets 'directory' flag to 1; 
  2295                              <1> 	;    'set user id on execution' and 'executable' flags to 0)
  2296                              <1> 	; ...............................................................
  2297                              <1> 	;
  2298                              <1> 	; Retro UNIX 8086 v1 modification: 
  2299                              <1> 	;       'sysmkdir' system call has two arguments; so,
  2300                              <1> 	;	* 1st argument, name is pointed to by BX register
  2301                              <1> 	;	* 2nd argument, mode is in CX register
  2302                              <1> 	;
  2303                              <1> 	; TRDOS 386 (10/10/2016)
  2304                              <1> 	;
  2305                              <1>         ; INPUT ->
  2306                              <1>         ;	   CL = Directory Attributes
  2307                              <1> 	;     	      bit 0 (1) - Read only file/dir (R)
  2308                              <1> 	;             bit 1 (1) - Hidden file/dir (H)
  2309                              <1>         ;             bit 2 (1) - System file/dir (R)
  2310                              <1> 	;             bit 3 (1) - Volume label/name (V)
  2311                              <1>         ;             bit 4 (1) - Subdirectory (D)
  2312                              <1> 	;	      bit 5 (1) - File/Dir has been archived (A)
  2313                              <1> 	;	   CX = 0 -> create normal directory
  2314                              <1>         ;          EBX = Pointer to directory name (ASCIIZ) -path-
  2315                              <1> 	;
  2316                              <1> 	; OUTPUT ->
  2317                              <1> 	;          eax = First cluster of the new directory
  2318                              <1> 	;          cf = 1 -> Error code in AL
  2319                              <1> 	;
  2320                              <1> 	; Modified Registers: EAX (at the return of system call)
  2321                              <1> 	;
  2322                              <1> 	; Note: If the file or directory is existing
  2323                              <1> 	;	an access error will be returned.
  2324                              <1> 
  2325 0000D52A 6621C9              <1> 	and	cx, cx ; if cx = 0 -> create a normal subdir
  2326 0000D52D 7414                <1> 	jz	short sysmkdir_1
  2327                              <1> 
  2328 0000D52F F6C110              <1> 	test	cl, 10h ; if dir flags set, also use other flags
  2329                              <1> 	;jnz	sysmkdir_0 ; jump to head of 'syscreat'
  2330                              <1> 	; 23/07/2022
  2331 0000D532 7405                <1> 	jz	short sysmkdir_invf
  2332                              <1> sysmkdir_3:
  2333 0000D534 E98FFDFFFF          <1> 	jmp	sysmkdir_0
  2334                              <1> 
  2335                              <1> sysmkdir_invf:
  2336                              <1> 	; CX has wrong flags
  2337 0000D539 B817000000          <1> 	mov 	eax, ERR_INV_FLAGS
  2338 0000D53E E96CFEFFFF          <1> 	jmp	sysopen_dev_err
  2339                              <1> 
  2340                              <1> sysmkdir_1:
  2341 0000D543 B110                <1> 	mov	cl, 10h ; set subdir flag and reset other flags
  2342                              <1> 	;jmp	sysmkdir_0
  2343                              <1> 	; 23/07/2022
  2344 0000D545 EBED                <1> 	jmp	short sysmkdir_3 ; jump to head of 'syscreat'
  2345                              <1> sysmkdir_2: 
  2346                              <1> 	; jump from 'syscreat' ; from 'syscreat_1'
  2347                              <1> 	;  CL = Directory attributes/flags
  2348 0000D547 BE[64860100]        <1> 	mov	esi, FindFile_Name 
  2349 0000D54C E8B8D7FFFF          <1> 	call	make_sub_directory
  2350                              <1> 	;jc	sysopen_err       ; NOTE: Old type (TRDOS 8086)
  2351                              <1> 				  ; error codes must be modified
  2352                              <1> 				  ; for next TRDOS 386 versions
  2353                              <1> 				  ; (10/10/2016)
  2354                              <1> 				  ; Old (MSDOS type)
  2355                              <1> 				  ; error codes (2011):
  2356                              <1> 				  ;  2 = file not found
  2357                              <1> 				  ;  3 = directory not found
  2358                              <1> 				  ;  5 = access denied
  2359                              <1> 				  ; 12 = no more files
  2360                              <1> 			          ; 19 = disk write protected
  2361                              <1> 				  ; 39 = insufficient disk space
  2362                              <1> 				  ; 'sysdefs.s' ; 10/10/2016
  2363                              <1> 	; 23/07/2022
  2364 0000D551 7305                <1> 	jnc	short sysmkdir_4
  2365 0000D553 E97AFEFFFF          <1> 	jmp	sysopen_err
  2366                              <1> 
  2367                              <1> sysmkdir_4:	
  2368 0000D558 A3[74940100]        <1> 	mov	[u.r0], eax ; New sub dir's first cluster
  2369 0000D55D E8554E0000          <1>         call 	reset_working_path
  2370 0000D562 E9EDF8FFFF          <1> 	jmp	sysret
  2371                              <1> 
  2372                              <1> sysclose: ;<close file>
  2373                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
  2374                              <1> 	; 06/10/2016 (TRDOS 386 = TRDOS v2.0)
  2375                              <1> 	;
  2376                              <1> 	; 14/05/2015 (Retro UNIX 386 v1 - Beginning)
  2377                              <1> 	; 22/05/2013 - 26/05/2013 (Retro UNIX 8086 v1)
  2378                              <1> 	;
  2379                              <1> 	; 'sysclose', given a file descriptor in 'u.r0', closes the
  2380                              <1> 	; associated file. The file descriptor (index to 'u.fp' list)
  2381                              <1> 	; is put in r1 and 'fclose' is called.
  2382                              <1> 	;
  2383                              <1> 	; Calling sequence:
  2384                              <1> 	;	sysclose
  2385                              <1> 	; Arguments:
  2386                              <1> 	;	-  
  2387                              <1> 	; Inputs: *u.r0 - file descriptor
  2388                              <1> 	; Outputs: -
  2389                              <1> 	; ...............................................................
  2390                              <1> 	;
  2391                              <1> 	; Retro UNIX 8086 v1 modification:
  2392                              <1> 	;	 The user/application program puts file descriptor
  2393                              <1> 	;        in BX register as 'sysclose' system call argument.
  2394                              <1> 	; 	 (argument transfer method 1)
  2395                              <1> 
  2396                              <1> 	; TRDOS 386 (06/10/2016)
  2397                              <1> 	;
  2398                              <1>         ; INPUT ->
  2399                              <1>         ;	   EBX = File Handle/Number (file index) (AL)
  2400                              <1> 	; OUTPUT ->
  2401                              <1> 	;          cf = 0 -> EAX = 0
  2402                              <1> 	;          cf = 1 -> Error code in EAX (ERR_FILE_NOT_OPEN)
  2403                              <1> 	;
  2404                              <1> 	; Modified Registers: EAX (at the return of system call)
  2405                              <1> 	;
  2406                              <1> 
  2407 0000D567 89D8                <1> 	mov 	eax, ebx
  2408 0000D569 31DB                <1> 	xor	ebx, ebx
  2409 0000D56B 891D[74940100]      <1> 	mov	[u.r0], ebx ; 0  ; return value of EAX
  2410 0000D571 E842310000          <1> 	call 	fclose
  2411                              <1> 	;jnc	sysret
  2412                              <1> 	; 23/07/2022
  2413 0000D576 7205                <1> 	jc	short sysclose_err
  2414 0000D578 E9D7F8FFFF          <1> 	jmp	sysret
  2415                              <1> sysclose_err:
  2416 0000D57D B80A000000          <1> 	mov	eax, ERR_FILE_NOT_OPEN ; file not open !
  2417 0000D582 A3[E0940100]        <1> 	mov	[u.error], eax ;
  2418 0000D587 A3[74940100]        <1> 	mov	[u.r0], eax ; ! invalid handle !
  2419 0000D58C E9A3F8FFFF          <1> 	jmp	error
  2420                              <1> 
  2421                              <1> sysread: ; < read from file >
  2422                              <1> 	; 27/09/2024
  2423                              <1> 	; 18/09/2024
  2424                              <1> 	; 03/09/2024 (TRDOS v2.0.9)
  2425                              <1> 	; 11/10/2016 (TRDOS 386 = TRDOS v2.0)
  2426                              <1> 	;	     -derived from INT_21H.ASM-
  2427                              <1> 	;            ("loc_INT21h_read_file")
  2428                              <1>         ; 	13/03/2011 (05/03/2011)
  2429                              <1>         ;	INT 21h Function AH = 3Fh
  2430                              <1>         ;	Read from a File
  2431                              <1>         ;	INPUT
  2432                              <1> 	;	   BX = File Handle
  2433                              <1>         ;	   CX = Number of bytes to read
  2434                              <1>         ;          DS:DX= Buffer address
  2435                              <1>         ;
  2436                              <1> 	; Note: TRDOS 386 'sysread' has been derived from 
  2437                              <1> 	;	Retro UNIX 386 v1 'sysread', except a few 
  2438                              <1> 	;	code modifications.
  2439                              <1> 	;
  2440                              <1> 	; 13/05/2015 (Retro UNIX 386 v1)
  2441                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
  2442                              <1> 	; 23/05/2013 (Retro UNIX 8086 v1)
  2443                              <1> 	;
  2444                              <1> 	; 'sysread' is given a buffer to read into and the number of
  2445                              <1> 	; characters to be read. If finds the file from the file
  2446                              <1> 	; descriptor located in *u.r0 (r0). This file descriptor
  2447                              <1> 	; is returned from a successful open call (sysopen).
  2448                              <1> 	; The i-number of file is obtained via 'rw1' and the data
  2449                              <1> 	; is read into core via 'readi'.
  2450                              <1> 	;
  2451                              <1> 	; Calling sequence:
  2452                              <1> 	;	sysread; buffer; nchars
  2453                              <1> 	; Arguments:
  2454                              <1> 	;	buffer - location of contiguous bytes where 
  2455                              <1> 	;		 input will be placed.
  2456                              <1> 	;	nchars - number of bytes or characters to be read.
  2457                              <1> 	; Inputs: *u.r0 - file descriptor (& arguments)
  2458                              <1> 	; Outputs: *u.r0 - number of bytes read.
  2459                              <1> 	; ...............................................................
  2460                              <1> 	;				
  2461                              <1> 	; Retro UNIX 8086 v1 modification: 
  2462                              <1> 	;       'sysread' system call has three arguments; so,
  2463                              <1> 	;	* 1st argument, file descriptor is in BX register
  2464                              <1> 	;	* 2nd argument, buffer address/offset in CX register
  2465                              <1> 	;	* 3rd argument, number of bytes is in DX register
  2466                              <1> 	;
  2467                              <1> 	;	AX register (will be restored via 'u.r0') will return
  2468                              <1> 	;	to the user with number of bytes read. 
  2469                              <1> 	;
  2470                              <1> 	; TRDOS 386 (05/10/2016)
  2471                              <1> 	;
  2472                              <1>         ; INPUT ->
  2473                              <1>         ;	   EBX = File handle (descriptor/index)
  2474                              <1> 	;	   ECX = Buffer address
  2475                              <1>         ;          EDX = Number of bytes
  2476                              <1> 	; OUTPUT ->
  2477                              <1> 	;          EAX = Number of bytes have been read
  2478                              <1> 	;          cf = 1 -> Error code in AL
  2479                              <1> 	;
  2480                              <1> 	; Modified Registers: EAX (at the return of system call)
  2481                              <1> 	;
  2482                              <1> 
  2483                              <1> 	; EBX = File descriptor
  2484 0000D591 E86B310000          <1> 	call	getf1 
  2485 0000D596 723A                <1> 	jc	short device_read ; read data from device
  2486                              <1> 
  2487                              <1> 	; EAX = First cluster of the file
  2488                              <1> 
  2489 0000D598 E83C000000          <1> 	call	rw1	; 03/09/2024 (major modification)
  2490 0000D59D 730A                <1> 	jnc	short sysread_0
  2491                              <1> 
  2492                              <1> sysrw_err:	; 03/09/2024
  2493 0000D59F A3[74940100]        <1> 	mov	[u.r0], eax ; error code
  2494 0000D5A4 E98BF8FFFF          <1> 	jmp	error
  2495                              <1> 	 
  2496                              <1> sysread_0:
  2497 0000D5A9 E829350000          <1> 	call	readi
  2498 0000D5AE EB13                <1> 	jmp	short rw0
  2499                              <1> 
  2500                              <1> syswrite: ; < write to file >
  2501                              <1> 	; 27/09/2024
  2502                              <1> 	; 18/09/2024
  2503                              <1> 	; 03/09/2024
  2504                              <1> 	; 25/08/2024 - TRDOS 386 v2.0.9
  2505                              <1> 	; 23/10/2016
  2506                              <1> 	; 11/10/2016 (TRDOS 386 = TRDOS v2.0)
  2507                              <1> 	;	     -derived from INT_21H.ASM-
  2508                              <1> 	;            ("loc_INT21h_write_file")
  2509                              <1>         ; 	13/03/2011 (05/03/2011)
  2510                              <1>         ;	INT 21h Function AH = 40h
  2511                              <1>         ;	Write to a File
  2512                              <1>         ;	INPUT
  2513                              <1> 	;	   BX = File Handle
  2514                              <1>         ;	   CX = Number of bytes to write
  2515                              <1>         ;          DS:DX= Buffer address
  2516                              <1>         ;
  2517                              <1> 	; Note: TRDOS 386 'sysrwrite' has been derived from
  2518                              <1> 	;	Retro UNIX 386 v1 'syswrite', except a few
  2519                              <1> 	;	code modifications.
  2520                              <1> 	;
  2521                              <1> 
  2522                              <1> 	; 13/05/2015 (Retro UNIX 386 v1)
  2523                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
  2524                              <1> 	; 23/05/2013 (Retro UNIX 8086 v1)
  2525                              <1> 	;
  2526                              <1> 	; 'syswrite' is given a buffer to write onto an output file
  2527                              <1> 	; and the number of characters to write. If finds the file
  2528                              <1> 	; from the file descriptor located in *u.r0 (r0). This file
  2529                              <1> 	; descriptor is returned from a successful open or create call
  2530                              <1> 	; (sysopen or syscreat). The i-number of file is obtained via
  2531                              <1> 	; 'rw1' and buffer is written on the output file via 'write'.
  2532                              <1> 	;
  2533                              <1> 	; Calling sequence:
  2534                              <1> 	;	syswrite; buffer; nchars
  2535                              <1> 	; Arguments:
  2536                              <1> 	;	buffer - location of contiguous bytes to be writtten.
  2537                              <1> 	;	nchars - number of characters to be written.
  2538                              <1> 	; Inputs: *u.r0 - file descriptor (& arguments)
  2539                              <1> 	; Outputs: *u.r0 - number of bytes written.
  2540                              <1> 	; ...............................................................
  2541                              <1> 	;
  2542                              <1> 	; Retro UNIX 8086 v1 modification: 
  2543                              <1> 	;       'syswrite' system call has three arguments; so,
  2544                              <1> 	;	* 1st argument, file descriptor is in BX register
  2545                              <1> 	;	* 2nd argument, buffer address/offset in CX register
  2546                              <1> 	;	* 3rd argument, number of bytes is in DX register
  2547                              <1> 	;
  2548                              <1> 	;	AX register (will be restored via 'u.r0') will return
  2549                              <1> 	;	to the user with number of bytes written. 
  2550                              <1> 	;
  2551                              <1> 	; INPUT ->
  2552                              <1>         ;	   EBX = File handle (descriptor/index)
  2553                              <1> 	;	   ECX = Buffer address
  2554                              <1>         ;          EDX = Number of bytes
  2555                              <1> 	; OUTPUT ->
  2556                              <1> 	;          EAX = Number of bytes have been written
  2557                              <1> 	;          cf = 1 -> Error code in AL
  2558                              <1> 	;
  2559                              <1> 	; Modified Registers: EAX (at the return of system call)
  2560                              <1> 	;
  2561                              <1> 
  2562                              <1> 	; EBX = File descriptor
  2563 0000D5B0 E84C310000          <1> 	call	getf1
  2564 0000D5B5 721B                <1> 	jc	short device_write ; write data to device
  2565                              <1> 	; EAX = First cluster of the file
  2566                              <1> 	; EBX = File number (Open file number) ; 23/10/2016
  2567                              <1> 
  2568 0000D5B7 E81D000000          <1> 	call	rw1	; 03/09/2024 (major modification)
  2569                              <1> 	; 03/09/2024
  2570 0000D5BC 72E1                <1> 	jc	short sysrw_err
  2571                              <1> 
  2572                              <1> 	; 25/08/2024 (*)
  2573                              <1> 	;jnc	short syswrite_0
  2574                              <1> 	;mov	[u.r0], eax ; error code
  2575                              <1> 	;jmp	error
  2576                              <1> 
  2577                              <1> 	; 25/08/2024 - TRDOS 386 v2.0.9 (bugfix) (*)
  2578                              <1> 	; (if eax = 0, lets add a cluster at 'mget_w_0')
  2579                              <1> 	; ('mget_w' and 'add_new_cluster' procs are modified)
  2580                              <1> 
  2581                              <1> syswrite_0:
  2582 0000D5BE E82F3C0000          <1> 	call	writei	; 24/08/2024 ('mget_w' modification)
  2583                              <1> rw0: ; 1:
  2584 0000D5C3 A1[A0940100]        <1>         mov	eax, [u.nread]
  2585 0000D5C8 A3[74940100]        <1> 	mov	[u.r0], eax
  2586 0000D5CD E982F8FFFF          <1> 	jmp	sysret
  2587                              <1> 
  2588                              <1> 	; 17/04/2021 (temporary)
  2589                              <1> device_write:
  2590                              <1> device_read:
  2591                              <1> 	; 26/09/2024
  2592                              <1> 	; 18/09/2024 - TRDOS 386 v2.0.9
  2593                              <1> 	; 17/04/2021 - TRDOS 386 v2.0.4
  2594                              <1> 	;	(temporary modifications)
  2595                              <1> 	;
  2596                              <1> 	; 11/10/2016 (TRDOS 386 = TRDOS v2.0)
  2597                              <1> 	; cl = DEV_OPENMODE ; open mode
  2598                              <1> 	; ch = DEV_ACCESS   ; access flags
  2599                              <1> 	; al = DEV_DRIVER   ; device number (eax)
  2600                              <1> 
  2601                              <1> 	; 18/09/2024 (temporary)
  2602 0000D5D2 E83E000000          <1> 	call	rw2 ; file not open ; cf = 1
  2603                              <1> 	;jmp	error
  2604                              <1> 	; 26/09/2024
  2605 0000D5D7 EBC6                <1> 	jmp	short sysrw_err
  2606                              <1> 
  2607                              <1> ;	test	cl, 1 ; 1 = read, 2 = write, 3 = read&write
  2608                              <1> ;	jz	short rw3
  2609                              <1> ;
  2610                              <1> ;	mov	ebx, eax
  2611                              <1> ;	shl	bx, 2 ; *4
  2612                              <1> ;
  2613                              <1> ;	test	ch, 80h ; bit 7, installable device driver flag
  2614                              <1> ;	jz	short d_read_2 ; Kernel device
  2615                              <1> ;	; installable device
  2616                              <1> ;d_read_1:
  2617                              <1> ;       jmp	dword [ebx+IDEV_RADDR-4]
  2618                              <1> ;d_read_2:
  2619                              <1> ;	jmp	dword [ebx+KDEV_RADDR-4]
  2620                              <1> 
  2621                              <1> ;device_write:
  2622                              <1> 	; 17/04/2021 - TRDOS 386 v2.0.4
  2623                              <1> 	;	(temporary modifications)
  2624                              <1> 	;
  2625                              <1> 	; 11/10/2016 (TRDOS 386 = TRDOS v2.0)
  2626                              <1> 	; cl = DEV_OPENMODE ; open mode
  2627                              <1> 	; ch = DEV_ACCESS   ; access flags
  2628                              <1> 	; al = DEV_DRIVER   ; device number (eax)
  2629                              <1> 
  2630                              <1> 	; 17/04/2021 (temporary)
  2631                              <1> 	;jmp	short rw2 ; file not open
  2632                              <1> 
  2633                              <1> ;	test	cl, 2 ; 1 = read, 2 = write, 3 = read&write
  2634                              <1> ;	jz	short rw3
  2635                              <1> ;
  2636                              <1> ;	mov	ebx, eax
  2637                              <1> ;	shl	bx, 2 ; *4
  2638                              <1> ;
  2639                              <1> ;	test	ch, 80h ; bit 7, installable device driver flag
  2640                              <1> ;	jz	short d_write_2 ; Kernel device
  2641                              <1> ;	; installable device
  2642                              <1> ;d_write_1:
  2643                              <1> ;       jmp	dword [ebx+IDEV_WADDR-4]
  2644                              <1> ;d_write_2:
  2645                              <1> ;	jmp	dword [ebx+KDEV_WADDR-4]
  2646                              <1> 
  2647                              <1> rw1:
  2648                              <1> 	; 27/09/2024	
  2649                              <1> 	; 03/09/2024 (TRDOS 386 v2.0.9)
  2650                              <1> 	; 17/04/2021 (TRDOS 386 v2.0.4)
  2651                              <1> 	; 11/10/2016 (TRDOS 386 = TRDOS v2.0)
  2652                              <1> 	; 14/05/2015 (Retro UNIX 386 v1)
  2653                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
  2654                              <1> 	; 23/05/2013 - 24/05/2013 (Retro UNIX 8086 v1)
  2655                              <1> 	; System call registers: ebx, ecx, edx (through 'sysenter')
  2656                              <1> 	;
  2657                              <1> 	; EBX = File descriptor
  2658                              <1> 	;call	getf1 ; calling point in 'getf' from 'rw1'
  2659                              <1> 	;jc	short device_rw ; read/write data from/to device
  2660                              <1> 	; EAX = First cluster of the file
  2661                              <1> 
  2662                              <1> 	; 03/09/2024
  2663 0000D5D9 09C0                <1> 	or	eax, eax
  2664 0000D5DB 7421                <1> 	jz	short rw7 ; eax = 0 -> empty file (OK for now)
  2665                              <1> 
  2666 0000D5DD 83F802              <1> 	cmp 	eax, 2	  ; is it valid cluster number ?
  2667                              <1> 	;jb	short rw2
  2668                              <1> 	; 03/09/2024
  2669 0000D5E0 7307                <1> 	jnb	short rw6 ; yes, check upper limit
  2670                              <1> 
  2671                              <1> 	;;;
  2672                              <1> 	; eax = 1 -> invalid cluster number
  2673                              <1> rw5:
  2674 0000D5E2 B823000000          <1> 	mov	eax, ERR_CLUSTER ; 35 ; 'cluster not available !'
  2675 0000D5E7 EB31                <1> 	jmp	short rw4 ; cf = 1
  2676                              <1> 
  2677                              <1> rw6:	; 03/09/2024 (check cluster number is valid or not)
  2678 0000D5E9 53                  <1> 	push	ebx
  2679                              <1> 	; ebx <= OPENFILES-1 ; 0-31
  2680 0000D5EA 8ABB[008A0100]      <1> 	mov	bh, [ebx+OF_DRIVE] ; drive number * 256
  2681 0000D5F0 28DB                <1> 	sub	bl, bl ; 27/09/2024
  2682 0000D5F2 8B9B78010900        <1> 	mov	ebx, [ebx+Logical_DOSDisks+LD_Clusters]
  2683 0000D5F8 43                  <1> 	inc	ebx ; cluster count + 1 = last cluster number
  2684 0000D5F9 39C3                <1> 	cmp	ebx, eax
  2685 0000D5FB 5B                  <1> 	pop	ebx
  2686 0000D5FC 72E4                <1> 	jb	short rw5
  2687                              <1> rw7:
  2688                              <1> 	;;;
  2689                              <1> 
  2690 0000D5FE 890D[98940100]      <1> 	mov	[u.base], ecx 	; buffer address/offset 
  2691                              <1> 				;(in the user's virtual memory space)
  2692 0000D604 8915[9C940100]      <1> 	mov	[u.count], edx 
  2693 0000D60A C705[E0940100]0000- <1>         mov	dword [u.error], 0 ; reset the last error code
  2693 0000D612 0000                <1>
  2694 0000D614 C3                  <1> 	retn
  2695                              <1> 
  2696                              <1> rw2:
  2697 0000D615 B80A000000          <1> 	mov	eax, ERR_FILE_NOT_OPEN ; file not open !
  2698                              <1> 	;mov	dword [u.error], eax
  2699                              <1> 	;retn
  2700                              <1> 
  2701                              <1> 	; 03/09/2024
  2702                              <1> 	; 17/04/2021
  2703                              <1> 	;jmp	short rw4
  2704                              <1> 
  2705                              <1> 	; 03/09/2024
  2706                              <1> rw3: 
  2707                              <1> ;	mov	eax, ERR_FILE_ACCESS ; permission denied !
  2708                              <1> ;	stc
  2709                              <1> 
  2710                              <1> rw4:	; 17/04/2021
  2711 0000D61A A3[E0940100]        <1> 	mov	dword [u.error], eax
  2712 0000D61F C3                  <1> 	retn
  2713                              <1> 
  2714                              <1> systimer:
  2715                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
  2716                              <1> 	; 02/01/2017
  2717                              <1> 	; 21/12/2016
  2718                              <1> 	; 19/12/2016
  2719                              <1> 	; 10/12/2016 (callback)
  2720                              <1> 	; 10/06/2016
  2721                              <1> 	; 07/06/2016
  2722                              <1> 	; 06/06/2016
  2723                              <1> 	; 21/05/2016
  2724                              <1> 	; 19/05/2016
  2725                              <1> 	; 18/05/2016 - TRDOS 386 (TRDOS v2.0)
  2726                              <1> 	; (TRDOS 386 feature only!)
  2727                              <1> 	;
  2728                              <1> 	; (start or stop timer event(s))
  2729                              <1> 	;
  2730                              <1> 	; INPUT ->
  2731                              <1> 	;	BL = Signal return byte (response byte)
  2732                              <1> 	;	     (Any requested value between 0 and 255)
  2733                              <1> 	;	     (Kernel will put it at the requested address)
  2734                              <1> 	;	BH = Time count unit
  2735                              <1> 	;	     0 = Stop timer event
  2736                              <1> 	;	     1 = 18.2 ticks per second
  2737                              <1> 	;	     2 = 10 milliseconds
  2738                              <1> 	;	     3 = 1 second (for real time clock interrupt)
  2739                              <1> 	;	     4 = time/tick count in current time count unit
  2740                              <1> 	;	    // 10/12/2016
  2741                              <1> 	;	    80h = Stop timer event (callback method)
  2742                              <1> 	;	    81h = 18.2 ticks per second, callback method
  2743                              <1> 	;	    82h = 10 milliseconds, callback method
  2744                              <1> 	;	    83h = 1 second (for RTC int), callback method
  2745                              <1> 	;	    84h = current time count unit, callback method
  2746                              <1> 	;
  2747                              <1> 	;	    Note: Only 03h or 83h will set real time clock
  2748                              <1> 	;		  (RTC) events (Others are for PIT events)!
  2749                              <1> 	;	
  2750                              <1> 	;	NOTE: If callback (user service) method is used,
  2751                              <1> 	;	    EDX will point to the return address (of service
  2752                              <1> 	;	    procedure) in user's space instead of signal 
  2753                              <1> 	;	    response byte address. (TRDOS 386 kernel will
  2754                              <1> 	;	    direct the cpu to that address -in user's space-
  2755                              <1> 	;	    at the return of system call or interrupt 
  2756                              <1> 	;	    just after the adjusted count/time is elapsed.)
  2757                              <1> 	;	    User's sevice routine must be ended with a
  2758                              <1> 	;	    'iret'. Normal return addresses from system 
  2759                              <1> 	;	    calls or and interrupts will be kept same except
  2760                              <1> 	;	    the timer returns.
  2761                              <1>      	;
  2762                              <1> 	;	BH = 0 -> Stop timer event
  2763                              <1> 	;	BL = Timer event number (1 to 255) if BH = 0
  2764                              <1> 	;	     If BL = 0, all timer events (which are belongs
  2765                              <1> 	;	      to running process) will be stopped
  2766                              <1> 	;	ECX = Time/Tick count (depending on time count unit)
  2767                              <1> 	;	EDX = Signal return (Response) byte address
  2768                              <1> 	;	      (virtual address in user's memory space)
  2769                              <1> 	; OUTPUT ->
  2770                              <1> 	;	AL = Timer event number	(1 to 255) (max. value = 16)
  2771                              <1> 	;	IF BH Input = 0 & CF = 0 & AL = 0 -> 
  2772                              <1> 	;	     timer event(s) has/have been stopped/finished
  2773                              <1> 	;	CF = 1 & AL = 0 -> no timer setting space to set
  2774                              <1> 	;	CF = 1 & AL > 0 -> timer count unit is not usable
  2775                              <1> 	;
  2776                              <1> 	;	NOTE: To modify a time count for a user function,
  2777                              <1> 	;	      at first, current timer event must be stopped
  2778                              <1> 	;	      then a new timer event (which is related with
  2779                              <1> 	;	      same user function) must be started.
  2780                              <1> 	;		
  2781                              <1> 	;	      Signal return (response) byte may be used for
  2782                              <1> 	;	      several purposes. Kernel will put this value
  2783                              <1> 	;	      to requested address during timer interrupt,
  2784                              <1> 	;	      program/user can check this value to understand
  2785                              <1> 	;	      which event has been occurred and what is changed.
  2786                              <1> 	;	      (Multi timer events can share same signal address)
  2787                              <1> 	;	
  2788                              <1> 	;	NOTE: If the process is running while the time count
  2789                              <1> 	;	      is reached, kernel will put signal return (response)
  2790                              <1> 	;	      byte value at requested address during timer
  2791                              <1> 	;	      interrupt and the process will continue to run.
  2792                              <1> 	;	      Program/process must call (jump to) it's timer event
  2793                              <1> 	;	      function as required, for checking the timer event
  2794                              <1> 	;	      status via signal return (response) byte address.
  2795                              <1> 	;
  2796                              <1> 	;	      If the process is not running (waiting or sleeping
  2797                              <1> 	;	      or released) while the time count is reached,
  2798                              <1> 	;	      it is restarted from where it left, to ensure
  2799                              <1> 	;	      proper multi media (video, audio, clock, timer)
  2800                              <1> 	;	      functionality.
  2801                              <1> 	;
  2802                              <1> 	;	      (It is better to use 'syswait' or 'syssleep',
  2803                              <1> 	;	      or 'sysrele' system call just after the timer
  2804                              <1> 	;	      function. Otherwise, timer events may block other
  2805                              <1> 	;	      processes which are not using timer events.)
  2806                              <1> 	;
  2807                              <1> 	; Timer Event Structure: (max. 16 timer events, 16*16 bytes)
  2808                              <1> 	;       Owner:	        resb 1 ; 0 = free
  2809                              <1> 	;		  	       ;>0 = process number (u.uno)
  2810                              <1> 	;	Calback:	resb 1 ; 1 = callback, 0 = response byte
  2811                              <1> 	;	Interrupt:      resb 1 ; 0 = Timer interrupt (or none)
  2812                              <1> 	;		   	       ; 1 = Real Time Clock interrupt
  2813                              <1> 	;	Response:       resb 1 ; 0 to 255, signal return value
  2814                              <1> 	;	Count Limit:	resd 1 ; count of ticks (total/set)
  2815                              <1> 	;	Current Count: 	resd 1 ; count of ticks (current)
  2816                              <1> 	;	Response Addr:  resd 1 ; response byte (pointer) address
  2817                              <1> 	;
  2818                              <1> 
  2819                              <1> 	; 19/12/2016 (timer callback)
  2820 0000D620 C605[588E0100]00    <1> 	mov	byte [tcallback], 0
  2821 0000D627 C605[598E0100]00    <1> 	mov	byte [trtc], 0
  2822 0000D62E C705[E8940100]0000- <1> 	mov	dword [u.tcb], 0 ; this is not necessary...
  2822 0000D636 0000                <1>
  2823                              <1> 
  2824 0000D638 80FF80              <1> 	cmp	bh, 80h
  2825 0000D63B 7224                <1> 	jb	short systimer_cb2
  2826 0000D63D 7704                <1> 	ja	short systimer_cb0
  2827                              <1> 
  2828 0000D63F 31D2                <1> 	xor	edx, edx ; 0, reset callback address
  2829 0000D641 EB0B                <1> 	jmp	short systimer_cb1
  2830                              <1> 
  2831                              <1> systimer_cb0:
  2832 0000D643 80FF84              <1> 	cmp	bh, 84h	
  2833 0000D646 7764                <1> 	ja	short systimer_5 ;  undefined, error
  2834                              <1> 
  2835                              <1> 	;mov	byte [tcallback], 1 ; 19/12/2016
  2836 0000D648 FE05[588E0100]      <1> 	inc	byte [tcallback]
  2837                              <1> 
  2838                              <1> systimer_cb1:
  2839 0000D64E 0FB635[C5940100]    <1> 	movzx	esi, byte [u.uno] ; process number
  2840                              <1> 	;shl	si, 2	
  2841                              <1> 	; 23/07/2022
  2842 0000D655 C1E602              <1> 	shl	esi, 2
  2843 0000D658 8996[04940100]      <1> 	mov	[esi+p.tcb-4], edx ; set process timer callback address
  2844                              <1> 				   ; (overwrite prev value if it is set!)
  2845 0000D65E 80E77F              <1> 	and	bh, 7Fh
  2846                              <1> 
  2847                              <1> systimer_cb2:
  2848 0000D661 80FF02              <1> 	cmp	bh, 2
  2849 0000D664 7446                <1>         je      short systimer_5  ; only 18.2 ticks per second is usable
  2850                              <1> 				  ; 10 milliseconds (100 Hertz) timer 
  2851                              <1> 				  ; will be set later (18/05/2016)
  2852 0000D666 774C                <1>         ja      short systimer_6 
  2853                              <1> 
  2854 0000D668 20FF                <1> 	and	bh, bh
  2855                              <1> 	;jz	systimer_9        ; stop timer event(s)
  2856                              <1> 	; 23/07/2022
  2857 0000D66A 7505                <1> 	jnz	short systimer_19
  2858 0000D66C E9BA000000          <1> 	jmp	systimer_9
  2859                              <1> 
  2860                              <1> 	; bh = 1 (timer interrupt, 18.2 Hz, IBM PC/AT ROMBIOS default)
  2861                              <1> 
  2862                              <1> systimer_19:
  2863 0000D671 B00A                <1> 	mov	al, 10 ; (*)
  2864                              <1> 
  2865                              <1> systimer_0:
  2866 0000D673 B710                <1> 	mov	bh, 16
  2867                              <1> 	;
  2868 0000D675 383D[4F890100]      <1> 	cmp	[timer_events], bh ; 16 ; 07/06/2016
  2869 0000D67B 7319                <1> 	jnb 	short systimer_3  ; max. 16 timer events
  2870                              <1> 	;
  2871 0000D67D 50                  <1> 	push	eax ; (*)
  2872                              <1> 
  2873 0000D67E BF[88950100]        <1> 	mov	edi, timer_set  ; beginning address of timer events
  2874                              <1> 				; setting space
  2875 0000D683 30C0                <1> 	xor	al, al ; 0
  2876                              <1> systimer_1:
  2877 0000D685 FEC0                <1> 	inc	al
  2878 0000D687 803F00              <1> 	cmp	byte [edi], 0 	; is it free space ?
  2879 0000D68A 7639                <1> 	jna	short systimer_7 ; yes
  2880 0000D68C FECF                <1> 	dec	bh
  2881 0000D68E 7405                <1> 	jz	short systimer_2
  2882 0000D690 83C710              <1> 	add	edi, 16
  2883 0000D693 EBF0                <1> 	jmp	short  systimer_1 ; next event space
  2884                              <1> 
  2885                              <1> systimer_2:
  2886 0000D695 58                  <1> 	pop	eax ; (*) discard
  2887                              <1> systimer_3:
  2888 0000D696 C605[74940100]00    <1> 	mov	byte [u.r0], 0
  2889                              <1> systimer_4:
  2890 0000D69D C705[E0940100]1B00- <1>         mov     dword [u.error], ERR_MISC
  2890 0000D6A5 0000                <1>
  2891                              <1>                                 ; one of miscellaneous/other errors
  2892 0000D6A7 E988F7FFFF          <1> 	jmp	error ; cf -> 1
  2893                              <1> 
  2894                              <1> systimer_5:
  2895 0000D6AC 883D[74940100]      <1> 	mov	[u.r0], bh ; Time count unit (=2 or >3)
  2896 0000D6B2 EBE9                <1> 	jmp	short systimer_4 ; 07/06/2016
  2897                              <1> 
  2898                              <1> systimer_6:
  2899 0000D6B4 80FF04              <1> 	cmp	bh, 4
  2900 0000D6B7 77F3                <1>         ja      short systimer_5  ; undefined time count unit
  2901                              <1> 	;jb	short systimer_16
  2902                              <1> 
  2903                              <1> 	;mov	al, 1	; default (use current timer unit)
  2904                              <1> 			; countdown value is in ECX !
  2905                              <1> 			; max. value of ecx = 4294967296/10
  2906                              <1>         ;jmp    short systimer_0
  2907                              <1> 	;jmp	short systimer_19
  2908 0000D6B9 74B6                <1> 	je	short systimer_19
  2909                              <1> 
  2910                              <1> systimer_16:
  2911                              <1> 	; bh = 3
  2912                              <1> 	; timer event via real time clock interrupt
  2913                              <1> 	; interrupt/update frequency: 1 Hz (1 tick per second)
  2914                              <1> 	
  2915 0000D6BB B0B6                <1> 	mov	al, 182 ; (*) ; 18.2 * 10
  2916 0000D6BD FE05[598E0100]      <1> 	inc	byte [trtc] ; timer event via real time clock
  2917 0000D6C3 EBAE                <1>         jmp     short systimer_0
  2918                              <1> 
  2919                              <1> systimer_7:
  2920 0000D6C5 A2[74940100]        <1> 	mov	[u.r0], al ; timer event number
  2921                              <1> 	;
  2922                              <1> 	; edi = address of empty timer event area
  2923 0000D6CA A0[C5940100]        <1> 	mov	al, [u.uno]
  2924 0000D6CF FA                  <1> 	cli 	; disable interrupts 
  2925 0000D6D0 AA                  <1> 	stosb	; process number
  2926 0000D6D1 A0[588E0100]        <1> 	mov	al, [tcallback] ; timer callback flag
  2927 0000D6D6 AA                  <1> 	stosb 	; 1= callback method, 0= signal response byte method
  2928 0000D6D7 A0[598E0100]        <1> 	mov	al, [trtc] ; timer interrupt type
  2929 0000D6DC AA                  <1> 	stosb	; 1= real time clock, 0= programmable interval timer
  2930 0000D6DD 88D8                <1> 	mov	al, bl ; Signal return (Response) value
  2931 0000D6DF AA                  <1> 	stosb   ; response byte
  2932 0000D6E0 58                  <1> 	pop	eax ; (*) ; 10 or 182
  2933 0000D6E1 89D3                <1> 	mov	ebx, edx ; virtual address for response/signal byte
  2934 0000D6E3 F7E1                <1> 	mul	ecx
  2935                              <1> 	; (eax = 10 * count of 18.2 Hz timer ticks)
  2936                              <1> 	; (count down step = 10)
  2937 0000D6E5 AB                  <1> 	stosd  ; count limit (reset value)
  2938 0000D6E6 AB                  <1> 	stosd  ; current count value
  2939                              <1> 
  2940                              <1> 	; 19/12/2016
  2941 0000D6E7 803D[588E0100]00    <1> 	cmp	byte [tcallback], 0 ; timer callback method ?
  2942 0000D6EE 7604                <1> 	jna	short systimer_17 ; no
  2943 0000D6F0 89D8                <1> 	mov	eax, ebx ; virtual address for callback routine
  2944 0000D6F2 EB0D                <1> 	jmp	short systimer_18
  2945                              <1> 
  2946                              <1> systimer_17: ; signal response byte method
  2947                              <1> 	; ebx = virtual address
  2948                              <1> 	; [u.pgdir] = page directory's physical address
  2949                              <1> 	; 20/02/2017
  2950 0000D6F4 FE05[5A8E0100]      <1> 	inc	 byte [no_page_swap] ; 1 
  2951                              <1> 			; Do not add this page to swap queue
  2952                              <1> 			; and remove it from swap queue if it is
  2953                              <1> 			; on the queue.
  2954 0000D6FA E8BF84FFFF          <1> 	call	get_physical_addr
  2955 0000D6FF 721A                <1> 	jc	short systimer_8 ; 07/06/2016
  2956                              <1> 	; eax = physical address of the virtual address in user's space
  2957                              <1> systimer_18:
  2958 0000D701 AB                  <1> 	stosd	; response addr (physical) or callback addr (virtual)
  2959 0000D702 FE05[4F890100]      <1> 	inc	byte [timer_events] ; 07/06/201
  2960                              <1> 	; 02/01/2017
  2961 0000D708 0FB605[C5940100]    <1> 	movzx	eax, byte [u.uno]
  2962 0000D70F FE80[F7930100]      <1> 	inc	byte [eax+p.timer-1]
  2963                              <1> 	;
  2964 0000D715 FB                  <1> 	sti 	; enable interrupts
  2965 0000D716 E939F7FFFF          <1> 	jmp	sysret
  2966                              <1> 
  2967                              <1> systimer_8:
  2968                              <1> 	; 10/06/2016
  2969                              <1> 	; 07/06/2016
  2970 0000D71B 28C0                <1> 	sub	al, al ; 0
  2971 0000D71D 8847F4              <1> 	mov	[edi-12], al ; clear process number (free timer event)
  2972                              <1> 	;mov	dword [edi], eax ; 0
  2973 0000D720 FB                  <1> 	sti
  2974 0000D721 A2[74940100]        <1> 	mov	[u.r0], al ; 0
  2975 0000D726 E909F7FFFF          <1> 	jmp	error
  2976                              <1> 
  2977                              <1> systimer_9:
  2978                              <1> 	; 10/06/2016
  2979                              <1> 	; 07/06/2016
  2980 0000D72B 28C0                <1> 	sub	al, al
  2981 0000D72D A2[74940100]        <1> 	mov	byte [u.r0], al ; 0
  2982 0000D732 3805[4F890100]      <1> 	cmp     byte [timer_events], al ;  0
  2983 0000D738 7631                <1> 	jna	short systimer_12
  2984                              <1> 
  2985                              <1> 	; Note: ecx and edx are undefined here
  2986                              <1> 	;	(for stop timer function)
  2987                              <1> 
  2988 0000D73A BE[88950100]        <1> 	mov	esi, timer_set  ; beginning address of timer events
  2989                              <1> 				; setting space
  2990 0000D73F A0[C5940100]        <1> 	mov	al, [u.uno]
  2991                              <1> 
  2992 0000D744 B710                <1> 	mov	bh, 16
  2993                              <1> 
  2994 0000D746 08DB                <1> 	or	bl, bl
  2995 0000D748 7544                <1> 	jnz	short systimer_15
  2996                              <1> 
  2997                              <1> 	; clear timer event areas belong to current process
  2998                              <1> 	; (for stopping all timer events belong to current process) 
  2999 0000D74A FA                  <1> 	cli 	; disable interrupts
  3000                              <1> systimer_10:
  3001                              <1> 	; 10/06/2016
  3002                              <1> 	; 07/06/2016 	
  3003 0000D74B 8A26                <1> 	mov	ah, [esi]
  3004 0000D74D 08E4                <1> 	or	ah, ah ; 0 ?
  3005 0000D74F 7411                <1> 	jz	short systimer_11
  3006 0000D751 38C4                <1> 	cmp	ah, al ; is the process number (owner) same ?
  3007 0000D753 750D                <1>         jne     short systimer_11 ; no
  3008                              <1> 
  3009                              <1> 	;mov	byte [esi], 0
  3010 0000D755 66C7060000          <1> 	mov	word [esi], 0 ; clear
  3011                              <1> 	;mov	dword [esi+12], 0 ; clear
  3012                              <1> 
  3013 0000D75A FE0D[4F890100]      <1> 	dec	byte [timer_events]
  3014 0000D760 7409                <1> 	jz	short systimer_12
  3015                              <1> 
  3016                              <1> systimer_11:
  3017 0000D762 FECF                <1> 	dec	bh
  3018 0000D764 7405                <1> 	jz	short systimer_12
  3019 0000D766 83C610              <1> 	add	esi, 16
  3020 0000D769 EBE0                <1> 	jmp	short systimer_10
  3021                              <1> 
  3022                              <1> systimer_12:
  3023 0000D76B 0FB635[C5940100]    <1> 	movzx	esi, byte [u.uno]
  3024 0000D772 08DB                <1> 	or	bl, bl ; all timer events or one timer event ?
  3025 0000D774 740C                <1> 	jz	short systimer_13
  3026 0000D776 8A9E[F7930100]      <1> 	mov	bl, [esi+p.timer-1]
  3027 0000D77C 20DB                <1> 	and	bl, bl	; previous number of timer events for the process
  3028 0000D77E 7408                <1> 	jz	short systimer_14
  3029 0000D780 FECB                <1> 	dec	bl  ; previous number of timer events for the process - 1
  3030                              <1> systimer_13:
  3031 0000D782 889E[F7930100]      <1> 	mov	[esi+p.timer-1], bl ; 0 ; no timer events for process
  3032                              <1> systimer_14:
  3033 0000D788 FB                  <1> 	sti	; enable interrupts
  3034 0000D789 E9C6F6FFFF          <1> 	jmp	sysret
  3035                              <1> 
  3036                              <1> systimer_15:
  3037 0000D78E 38FB                <1> 	cmp	bl, bh ; 16
  3038                              <1>         ;ja	systimer_4      ; max. 16 timer events !
  3039                              <1> 	; 23/07/2022
  3040 0000D790 7605                <1> 	jna	short systimer_21
  3041                              <1> systimer_20:
  3042 0000D792 E906FFFFFF          <1> 	jmp	systimer_4
  3043                              <1> systimer_21:	; 23/07/2022
  3044 0000D797 88DA                <1> 	mov	dl, bl
  3045 0000D799 FECA                <1> 	dec	dl  ; 16 -> 15 ... 1 -> 0
  3046 0000D79B C0E204              <1> 	shl	dl, 4 ; * 16
  3047 0000D79E 0FB6FA              <1> 	movzx	edi, dl
  3048 0000D7A1 01F7                <1> 	add	edi, esi ; timer_set 
  3049                              <1> 	
  3050 0000D7A3 3A07                <1> 	cmp	al, [edi] ; process number
  3051                              <1>         ;jne	systimer_4
  3052                              <1> 	; 23/07/2022
  3053 0000D7A5 75EB                <1> 	jne	short systimer_20 ; jmp systimer_4
  3054                              <1> 	
  3055                              <1> 	; same process ID
  3056 0000D7A7 FA                  <1> 	cli	; disable interrupts
  3057                              <1>  	; 10/06/2016 ; 02/01/2017
  3058                              <1> 	;mov	byte [edi], 0 
  3059 0000D7A8 66C7070000          <1> 	mov	word [edi], 0 ; clear
  3060                              <1> 	;mov	dword [edi+12], 0 ; clear
  3061 0000D7AD FE0D[4F890100]      <1> 	dec	byte [timer_events]
  3062 0000D7B3 EBB6                <1> 	jmp	short systimer_12
  3063                              <1> 
  3064                              <1> sysvideo: ; VIDEO DATA TRANSFER FUNCTIONS
  3065                              <1> 	; 11/08/2022
  3066                              <1> 	; 08/08/2022
  3067                              <1> 	; 23/07/2022 (TRDOS 386 v2.0.5)
  3068                              <1> 	; 06/03/2021
  3069                              <1> 	; 02/03/2021
  3070                              <1> 	; 28/02/2021
  3071                              <1> 	; 27/02/2021
  3072                              <1> 	; 26/02/2021
  3073                              <1> 	; 25/02/2021
  3074                              <1> 	; 21/02/2021, 22/02/2021, 23/02/2021
  3075                              <1> 	; 15/02/2021, 16/02/2021, 18/02/2021
  3076                              <1> 	; 10/02/2021, 11/02/2021, 12/02/2021
  3077                              <1> 	; 07/02/2021, 08/02/2021
  3078                              <1> 	; 01/02/2021, 02/02/2021, 05/02/2021
  3079                              <1> 	; 29/01/2021, 30/01/2021, 31/01/2021
  3080                              <1> 	; 23/01/2021, 24/01/2021, 28/01/2021
  3081                              <1> 	; 18/01/2021, 19/01/2021, 22/01/2021
  3082                              <1> 	; 04/01/2021, 10/01/2021, 11/01/2021
  3083                              <1> 	; 01/01/2021, 02/01/2021, 03/01/2021
  3084                              <1> 	; 28/12/2020, 29/12/2020, 30/12/2020
  3085                              <1> 	; 25/12/2020, 26/12/2020
  3086                              <1> 	; 21/12/2020, 23/12/2020
  3087                              <1> 	; 12/12/2020, 14/12/2020
  3088                              <1> 	; 10/12/2020, 11/12/2020
  3089                              <1> 	; 03/12/2020, 04/12/2020
  3090                              <1> 	; 22/11/2020, 23/11/2020
  3091                              <1> 	; 21/11/2020 (TRDOS 386 v2.0.3)
  3092                              <1> 	; 12/05/2017
  3093                              <1> 	; 11/07/2016
  3094                              <1> 	; 13/06/2016
  3095                              <1> 	; 16/05/2016 - TRDOS 386 (TRDOS v2.0)
  3096                              <1> 	;
  3097                              <1> 	; VIDEO DATA TRANSFER FUNCTIONS:
  3098                              <1> 	;
  3099                              <1> 	; Inputs:
  3100                              <1> 	;		; 07/02/2021
  3101                              <1> 	;	BH = 0 = VIDEO BIOS Mode 3, tty/text mode data transfers
  3102                              <1> 	;	     BL = 
  3103                              <1> 	;		Bits 0&1, Transfer direction
  3104                              <1> 	;	     	 	0 - System to system
  3105                              <1> 	;			1 - User to system
  3106                              <1> 	;			2 - System to user
  3107                              <1> 	;			3 - Exhange (Swap) - 28/01/2021
  3108                              <1> 	;		Bits 2, Transfer Type
  3109                              <1> 	;			0 - Display page (complete) transfer
  3110                              <1> 	;	     		1 - Display page window (col,row) transfer
  3111                              <1> 	;		; 28/01/2021
  3112                              <1> 	;		Bits 3..7 - Reserved, undefined (must be 0)
  3113                              <1> 	;	        ; 28/01/2021	
  3114                              <1> 	;	     /// BL = 0 -> System to system (display page) transfer
  3115                              <1> 	;		 CL = Source page (0FFh = current video page)
  3116                              <1> 	;		 DL = Destination page (0FFh = current video page)
  3117                              <1> 	;		 (Note: Nothing to do if src & dest are same page)
  3118                              <1> 	;	     /// BL = 1&2 -> user to system & system to user transfer
  3119                              <1> 	;		 ECX = User's buffer address
  3120                              <1> 	;		 DL = Video page (0FFh = current video page)
  3121                              <1> 	;	     /// BL = 3 -> exchange (swap) display page ; 28/01/2021
  3122                              <1> 	;		 ECX = User's buffer address
  3123                              <1> 	;		 DL = Video page (0FFh = current video page)
  3124                              <1> 	;		 EDI = Swap address in user's memory (must be > 0)
  3125                              <1> 	;	     /// BL = 5&6&7 -> user to system, system to user transfer 
  3126                              <1> 	;		(system window is in current/active display page)
  3127                              <1> 	;		 ESI = User's buffer address
  3128                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  3129                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  3130                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  3131                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  3132                              <1>         ;                If BL = 5 or BL bit 0 & bit 1 are 1 ; 28/01/2021
  3133                              <1> 	;		 EDI = Swap address (in user's memory space)
  3134                              <1> 	;		 (If swap address > 0, previous content of the window
  3135                              <1> 	;		 will be saved into swap area in user's memory space)
  3136                              <1> 	;	     /// BL = 4 -> system to system transfer
  3137                              <1> 	;		 ESI = System's source buffer (video page) address
  3138                              <1> 	;		 ECX Low 16 bits = Top left column (X1 position)
  3139                              <1> 	;		 ECX High 16 bits = Top row (Y1 position)
  3140                              <1> 	;		 EDX Low 16 bits = Bottom right column (X2 position)
  3141                              <1> 	;		 EDX High 16 bits = Bottom row (Y2 position)
  3142                              <1> 	;		 EDI = System's destination buffer (video page) addr
  3143                              <1> 	;
  3144                              <1> 	;		; 06/02/2021
  3145                              <1> 	;		; 05/02/2021
  3146                              <1> 	;		; 01/02/2021, 02/02/2021
  3147                              <1> 	;		; 30/01/2021, 31/02/2021
  3148                              <1> 	;		; 29/01/2021 (major modification)
  3149                              <1> 	;		; 23/11/2020 (major modification)
  3150                              <1> 	;		; 22/11/2020 (bugfixes and extensions)
  3151                              <1> 	;	BH = 1 = VGA Graphics (0A0000h) data transfers
  3152                              <1> 	;		BL bit 7
  3153                              <1> 	;		   resolution (screen width) option
  3154                              <1> 	;		   0 = 320 pixels
  3155                              <1> 	;		   1 = 640 pixels
  3156                              <1> 	;		.. followings are same with SVGA transfer function
  3157                              <1> 	;		BL bit 6
  3158                              <1> 	;		   direction option
  3159                              <1> 	;		   0 = user to system (video memory)
  3160                              <1> 	;		   1 = system to user
  3161                              <1> 	;		BL bit 5
  3162                              <1> 	;		   masked/direct (non-masked) operations
  3163                              <1> 	;		   1 = masked, 0 = non-masked (direct)
  3164                              <1> 	;		BL bit 4
  3165                              <1> 	;		   page/window option
  3166                              <1> 	;		   1 = window, 0 = display page (screen)
  3167                              <1> 	;		BL bit 0 to 3 (pixel operation types)
  3168                              <1> 	;		   0 = Copy pixels (colors) ((mask color))
  3169                              <1> 	;		   1 = Change (New, Fill) color
  3170                              <1> 	;		   2 = Add color
  3171                              <1> 	;		   3 = Sub color
  3172                              <1> 	;		   4 = OR color
  3173                              <1> 	;		   5 = AND color
  3174                              <1> 	;		   6 = XOR color
  3175                              <1> 	;		   7 = NOT color
  3176                              <1> 	;		   8 = NEG color
  3177                              <1> 	;		   9 = INC color
  3178                              <1> 	;		  10 = DEC color
  3179                              <1> 	;		  11 = Mix (Average) colors
  3180                              <1> 	;		  12 = Replace pixel colors
  3181                              <1> 	;		  13 = Copy pixel block(s)
  3182                              <1> 	;		  14 = Write line(s)
  3183                              <1> 	;		  15 = Write character (font)
  3184                              <1> 	;
  3185                              <1> 	;	   Input Registers for pixel operations:
  3186                              <1> 	;		 Same with LFB data transfer function below
  3187                              <1> 	;
  3188                              <1> 	;		; 25/02/2021
  3189                              <1> 	;		; 05/02/2021, 06/02/2021
  3190                              <1> 	;		; 01/02/2021, 02/02/2021
  3191                              <1> 	;		; 30/01/2021, 31/02/2021
  3192                              <1> 	; 		; 29/01/2021 (major modification)
  3193                              <1> 	;		; 23/11/2020 (major modification)
  3194                              <1> 	;		; 22/11/2020 (bugfixes and extensions)
  3195                              <1> 	;	BH = 2 = Super VGA, LINEAR FRAME BUFFER data transfers
  3196                              <1> 	;		BL bit 7
  3197                              <1> 	;		   unused (invalid), must be 0
  3198                              <1> 	;		BL bit 6
  3199                              <1> 	;		   direction option
  3200                              <1> 	;		   0 = user to system (video memory)
  3201                              <1> 	;		   1 = system to user
  3202                              <1> 	;		BL bit 5
  3203                              <1> 	;		   masked/direct (non-masked) operations
  3204                              <1> 	;		   1 = masked, 0 = non-masked (direct)
  3205                              <1> 	;		BL bit 4
  3206                              <1> 	;		   page/window option
  3207                              <1> 	;		   1 = window, 0 = display page (screen)
  3208                              <1> 	;		BL bit 0 to 3 (pixel operation types)
  3209                              <1> 	;		   0 = Copy pixels (colors) ((mask color))
  3210                              <1> 	;		   1 = Change (New, Fill) color
  3211                              <1> 	;		   2 = Add color
  3212                              <1> 	;		   3 = Sub color
  3213                              <1> 	;		   4 = OR color
  3214                              <1> 	;		   5 = AND color
  3215                              <1> 	;		   6 = XOR color
  3216                              <1> 	;		   7 = NOT color
  3217                              <1> 	;		   8 = NEG color
  3218                              <1> 	;		   9 = INC color
  3219                              <1> 	;		  10 = DEC color
  3220                              <1> 	;		  11 = Mix (Average) colors
  3221                              <1> 	;		  12 = Replace pixel colors
  3222                              <1> 	;		  13 = Copy pixel block(s)
  3223                              <1> 	;		  14 = Write line(s)
  3224                              <1> 	;		  15 = Write character (font)
  3225                              <1> 	;
  3226                              <1> 	;	   Note: If HW of EBX > 0, it is VESA VBE mode number
  3227                              <1> 	;		 otherwise, function will be applied
  3228                              <1> 	;		 to current (VESA VBE) video mode.
  3229                              <1> 	;
  3230                              <1> 	;	   Input Registers for pixel operations:
  3231                              <1> 	;		-- user to system & system to system --
  3232                              <1> 	;		-- (BL = 0 to 0Fh) -- non-masked, screen --
  3233                              <1> 	;		-- (BL = 10h to 1Fh) -- non-masked, window --
  3234                              <1> 	;		-- (BL = 20h to 2Fh) -- masked, screen --
  3235                              <1> 	;		-- (BL = 30h to 3Fh) -- masked, window --
  3236                              <1> 	;		(*) window, (**) masked (***) sys to sys
  3237                              <1> 	;		for BL bit 0 to 3
  3238                              <1> 	;		00h: COPY PIXELS
  3239                              <1> 	;		  If BL bit 4 = 0 ; 21/02/2021
  3240                              <1> 	;		     full screen copy	
  3241                              <1>    	;		     ECX & EDX will not be used
  3242                              <1> 	;		    (user buffer must fit to display page)
  3243                              <1> 	;		  If BL bit 4 = 1 ; 21/02/2021
  3244                              <1> 	;		    ECX = start position (row, column) (*)
  3245                              <1> 	;			  (HW = row, CX = column)
  3246                              <1> 	;		    EDX = size (rows, colums) (*)
  3247                              <1> 	;			  (HW = rows, DX = columns)
  3248                              <1> 	;		          (0 -> invalid)
  3249                              <1> 	;		          (1 -> horizontal or vertical line)
  3250                              <1> 	;		    ESI = user's buffer address
  3251                              <1> 	;		    EDI = mask color (**) ; 25/02/2021
  3252                              <1> 	;			  (this color will be excluded)
  3253                              <1> 	;		01h: CHANGE PIXEL COLORS
  3254                              <1> 	;		02h: ADD PIXEL COLORS
  3255                              <1> 	;		03h: SUB PIXEL COLORS
  3256                              <1> 	;		04h: OR PIXEL COLORS
  3257                              <1> 	;		05h: AND PIXEL COLORS
  3258                              <1> 	;		06h: XOR PIXEL COLORS
  3259                              <1> 	;		0Bh: MIX PIXEL COLORS
  3260                              <1> 	;		     CL = color (8 bit, 256 colors)
  3261                              <1> 	;		    ECX = color (16 bit and true colors)
  3262                              <1> 	;		    EDX = start position (row, column) (*)
  3263                              <1> 	;			 (HW = row, DX = column)
  3264                              <1> 	;		    ESI = size (rows, colums) (*)
  3265                              <1> 	;			  (HW = rows, SI = columns)
  3266                              <1> 	;		    EDI = mask color (**) ; 25/02/2021
  3267                              <1> 	;			  (this color will be excluded)
  3268                              <1> 	;		07h: NOT PIXEL COLORS
  3269                              <1> 	;		08h: NEG PIXEL COLORS
  3270                              <1> 	;		09h: INC PIXEL COLORS
  3271                              <1> 	;		0Ah: DEC PIXEL COLORS
  3272                              <1> 	;		    ECX = start position (row, column) (*)
  3273                              <1> 	;			  (HW = row, CX = column)
  3274                              <1> 	;		    EDX = size (rows, colums) (*)
  3275                              <1> 	;			  (HW = rows, DX = columns)
  3276                              <1> 	;		          (0 -> invalid)
  3277                              <1> 	;		          (1 -> horizontal or vertical line)
  3278                              <1> 	;		    EDI = mask color (**) ; 25/02/2021
  3279                              <1> 	;			  (this color will be excluded)
  3280                              <1> 	;		0Ch: REPLACE PIXEL COLORS
  3281                              <1> 	;		     CL = current color (8 bit, 256 colors)
  3282                              <1> 	;		    ECX = current color (16 bit and true colors)
  3283                              <1> 	;		     DL = new color (8 bit, 256 colors)
  3284                              <1> 	;		    EDX = new color (16 bit and true colors)
  3285                              <1> 	;		    ESI = start position (row, column) (*)
  3286                              <1> 	;			  (HW = row, SI = column)
  3287                              <1> 	;		    EDI = size (rows, colums) (*)
  3288                              <1> 	;			  (HW = rows, DI = columns)
  3289                              <1> 	;		0Dh: COPY PIXEL BLOCK(S) -full screen-
  3290                              <1> 	;		   -If BL bit 5 is 0-
  3291                              <1> 	;		    ECX = start position (row, column) (*)
  3292                              <1> 	;			  (HW = row, CX = column)
  3293                              <1> 	;		    EDX = size (rows, colums) (*)
  3294                              <1> 	;			  (HW = rows, DX = columns)
  3295                              <1> 	;		          (0 -> invalid)
  3296                              <1> 	;		          (1 -> horizontal or vertical line)
  3297                              <1> 	;		    ESI = destination (row, column) (***)
  3298                              <1> 	;		   -If BL bit 5 is 1-
  3299                              <1> 	;	               CL = color (8 bit, 256 colors)
  3300                              <1> 	;		      ECX = color (16 bit and true colors)
  3301                              <1> 	;	   	      EDX = count of blocks (not bytes)
  3302                              <1> 	;			    (limit: 2048 blocks)
  3303                              <1> 	;		      ESI = user's buffer address 
  3304                              <1> 	;			  contains 64 bits block data
  3305                              <1> 	;			  BLOCK ADDRESS - (row, col), dword
  3306                              <1> 	;			  (first 32 bits)
  3307                              <1> 	;			  BLOCK SIZE - (rows, cols), dword
  3308                              <1> 	;			  (second 32 bits)
  3309                              <1> 	;		; 10/02/2021
  3310                              <1> 	;		0Eh: WRITE LINE(s) -full screen- 
  3311                              <1> 	;		   -If BL bit 5 is 0-	
  3312                              <1> 	; 		    CL = color (8 bit, 256 colors)
  3313                              <1> 	; 		   ECX = color (16 bit and true colors)
  3314                              <1> 	; 		    DX = low 12 bits - size (length)
  3315                              <1> 	;			 high 4 bits - direction or type
  3316                              <1> 	;			     0 - Horizontal line
  3317                              <1> 	;			     1 - Vertical line
  3318                              <1> 	;			   > 1 - undefined, invalid
  3319                              <1> 	; 		   ESI = start position (row, column)
  3320                              <1> 	;			 (HW = row, SI = column)
  3321                              <1> 	;		   -If BL bit 5 is 1-
  3322                              <1> 	;		     CL = color (8 bit, 256 colors)
  3323                              <1> 	;		    ECX = color (16 bit and true colors)
  3324                              <1> 	;		     DX = number of lines (in user buffer)
  3325                              <1> 	;			   (limit: 2048 lines)	
  3326                              <1> 	;		    ESI = user's buffer
  3327                              <1> 	;		          contains 64 bit data for lines
  3328                              <1> 	;			   START POINT: 32 bit (row, col)
  3329                              <1> 	;			   LENGTH: 32 bit
  3330                              <1> 	;			   high 16 bits - 0
  3331                              <1> 	;			   bit 0-11 - length
  3332                              <1> 	;			   bit 12-15 - type (length)
  3333                              <1> 	;		0Fh: WRITE CHARACTER (FONT)
  3334                              <1> 	;		     CL = char's color (8 bit, 256 colors)
  3335                              <1> 	;		    ECX = char's color (16 bit and true colors)
  3336                              <1> 	;		     DL = Character's ASCII code
  3337                              <1> 	;		     DH bit 0 -> font height
  3338                              <1> 	;			  0 -> 8x16 character font
  3339                              <1> 	;			  1 -> 8x8 character font
  3340                              <1> 	;		     DH bit 1 & 2 -> scale
  3341                              <1> 	;			  0 = 1/1 (8 pixels per char row)
  3342                              <1> 	;			  1 = 2/1 (16 pixels per char row)
  3343                              <1> 	;			  2 = 3/1 (24 pixels per char row)
  3344                              <1> 	;			  3 = 4/1 (32 pixels per char row) 
  3345                              <1> 	;		     DH bit 6 -> [ufont] option (1 = use [ufont])
  3346                              <1> 	;		     If DH bit 7 = 1
  3347                              <1> 	;			 USER FONT (from user buffer)
  3348                              <1> 	;			    DL = 0 -> 8x8 (width: 1 byte per row)
  3349                              <1> 	;			    DL = 1 -> 8x16
  3350                              <1> 	;			    DL = 2 -> 16x16 (width: 2 bytes)
  3351                              <1> 	;			    DL = 3 -> 16x32
  3352                              <1> 	;			    DL = 4 -> 24x24 (width: 3 bytes)
  3353                              <1> 	;			    DL = 5 -> 24x48
  3354                              <1> 	;			    DL = 6 -> 32x32 (width: 4 bytes)
  3355                              <1> 	;			    DL = 7 -> 32x64
  3356                              <1> 	;			    DL > 7 -> invalid (unused)
  3357                              <1> 	;			 EDI = user's font buffer address
  3358                              <1> 	;			    (NOTE: byte order is as row0,row1,row2..)
  3359                              <1> 	; 		    ESI = start position (row, column) (*)
  3360                              <1> 	;			     (HW = row, SI = column)
  3361                              <1> 	;
  3362                              <1> 	;		-- system to user --
  3363                              <1> 	;		   BL (bit 0 to 7)
  3364                              <1> 	;	 	40h: COPY PIXELS (full screen, display page)
  3365                              <1> 	;		    EDI = user's buffer address
  3366                              <1> 	;		41h: COPY PIXELS (window)
  3367                              <1> 	;		    ECX = start position (row, column) (*)
  3368                              <1> 	;			  (HW = row, CX = column)
  3369                              <1> 	;		    EDX = size (rows, colums) (*)
  3370                              <1> 	;			  (HW = rows, DX = columns)
  3371                              <1> 	;		          (<=1 -> horizontal or vertical line)
  3372                              <1> 	;		    EDI = user's buffer address
  3373                              <1> 	;
  3374                              <1> 	;		Example: (29/01/2021)
  3375                              <1> 	;		    ecx = 00400064h (start at row 64, column 100)
  3376                              <1> 	;		    edx = 00320048h (size: 50 rows, 72 columns)
  3377                              <1> 	;				    (end at row 114, column 172)
  3378                              <1> 	;		    If video memory starts at 0A0000h
  3379                              <1> 	;		    and if resolution is 320x200 (256 colors) ..
  3380                              <1> 	;		    window start offset: (64*320)+100 = 20580
  3381                              <1> 	;		    window size: 16072 bytes (pixels) 
  3382                              <1> 	;		    window end offset: 20580+16072 = 36652
  3383                              <1> 	;		    window start address: 0A0000h+564h = 0A5064h
  3384                              <1> 	; Outputs:
  3385                              <1> 	;	EAX = transfer/byte count
  3386                              <1> 	;
  3387                              <1> 	;	NOTE: If the source or destination address passes out of
  3388                              <1> 	;	video pages (display memory limits), data will not be transferred
  3389                              <1> 	;	and EAX will return as 0.
  3390                              <1> 	;
  3391                              <1> 	; 08/02/2021
  3392                              <1> 	; 07/02/2021
  3393                              <1> 	; 04/01/2021
  3394                              <1> 	; PIXEL READ/WRITE (in current/active video mode)
  3395                              <1> 	;
  3396                              <1> 	;	BH = 3 = Read/Write pixel(s) -for all graphics modes-
  3397                              <1> 	;	     BL = 
  3398                              <1> 	;		0 = Read pixel
  3399                              <1> 	;		1 = Write pixel
  3400                              <1> 	;	     	2 = swap pixel colors
  3401                              <1> 	;		3 = mix pixel colors
  3402                              <1> 	;	     29/01/2021	
  3403                              <1> 	;		4 = read pixels from user defined positions 
  3404                              <1> 	;		5 = write single color pixels to user defined positions
  3405                              <1> 	;		6 = write multi color pixels to user defined positions 
  3406                              <1> 	;
  3407                              <1> 	;	      > 6 = invalid/unimplemented
  3408                              <1> 	;
  3409                              <1> 	;	     .. for BL = 0 to 5
  3410                              <1> 	;	     CL = color for writing pixel(s) or
  3411                              <1>  	;	     ECX = color for writing pixel(s) in true color modes
  3412                              <1> 	;
  3413                              <1> 	;	     EDX = Offset from start of video memory (0A0000h)
  3414                              <1> 	;		   or start of linear frame buffer
  3415                              <1> 	;
  3416                              <1> 	;	     07/02/2021	
  3417                              <1> 	;	     .. for BL = 4
  3418                              <1> 	;	     EDI = user's destination buffer address for pixel colors
  3419                              <1> 	;	     29/01/2021
  3420                              <1> 	;	     .. for BL = 4 & 5
  3421                              <1> 	;	     ESI = user's source buffer address for BL = 4 & 5
  3422                              <1> 	;	     (buffer contains dword offset positions for pixels)
  3423                              <1> 	;	     EDX = number of pixels
  3424                              <1> 	;	     .. for BL = 6
  3425                              <1> 	;	     ESI = user's buffer address for BL = 6
  3426                              <1> 	;	     (buffer contains dword offset position and dword color
  3427                              <1> 	;	      value for each pixel)
  3428                              <1> 	;	     EDX = number of pixels
  3429                              <1> 	;
  3430                              <1> 	; Note:
  3431                              <1> 	;	Pixel read/write will be performed in current video mode.
  3432                              <1> 	;	If [CRT_MODE] < 0FFh, 0A0000h will be used 
  3433                              <1> 	;	   as video memory and limit will be 65536
  3434                              <1> 	;	   (new/mix pixel color will be in CL)
  3435                              <1> 	;	if [CRT_MODE] = 0FFh (VESA VBE video mode)
  3436                              <1> 	;	   LFB base address will be used as video memory
  3437                              <1> 	;	   and limit will be video page size
  3438                              <1> 	;	   (new/mix pixel color will be in CL)
  3439                              <1> 	;
  3440                              <1> 	; Outputs:
  3441                              <1> 	;	EAX = pixel color (according to BL and ECX input)
  3442                              <1> 	;	EAX = 0 (pixel color is 0 or there is an error)
  3443                              <1> 	;	     (BL will return as 0FFh if there is an error)
  3444                              <1> 	;	; 29/01/2021
  3445                              <1> 	;	EAX = number of pixels (for BL input = 4&5&6)
  3446                              <1> 	;
  3447                              <1> 	; DIRECT (STANDARD VGA/CGA) DISPLAY MEMORY ACCESS FUNCTIONS:
  3448                              <1> 	;
  3449                              <1> 	;	BH = 4 = CGA direct video memory (0B8000h, 32K) access
  3450                              <1> 	;		Page directory & page tables of the user's
  3451                              <1> 	;		program will be updated to direct access to
  3452                              <1> 	;		0B8000h (32K) video (CGA, color) memory; if
  3453                              <1> 	;		there is not a permission conflict or lock!
  3454                              <1> 	;	        (User's program/process will have permission to
  3455                              <1> 	;		access locked display memory if the owner is
  3456                              <1> 	;		it's parent.)
  3457                              <1>         ;
  3458                              <1> 	;	    Screen width = 320
  3459                              <1> 	;
  3460                              <1> 	;	BH = 5 = VGA direct video memory (0A0000h, 64K) access
  3461                              <1> 	;		Page directory & page tables of the user's
  3462                              <1> 	;		program will be updated to direct access to
  3463                              <1> 	;		0A0000h (64K) video (VGA) memory; if there is not
  3464                              <1> 	;		a permission conflict or lock!  
  3465                              <1> 	;	        (User's program/process will have permission to
  3466                              <1> 	;		access locked display memory if the owner is
  3467                              <1> 	;		it's parent.)
  3468                              <1> 	;
  3469                              <1> 	;	    ; 23/11/2020
  3470                              <1> 	;	    Screen width options = 320, 640, 800
  3471                              <1> 	;
  3472                              <1> 	; Outputs:
  3473                              <1> 	;	EAX = Display memory address for direct access
  3474                              <1> 	;	      0A0000h for VGA, 0B8000h for CGA
  3475                              <1> 	;	(Display memory size: 32K for CGA, 64K for VGA)
  3476                              <1> 	; 	EAX = 0 if display page access permission has been denied.
  3477                              <1> 	;	      (Locked!)
  3478                              <1> 	;
  3479                              <1> 	; LINEAR FRAME BUFFER ACCESS FUNCTIONS:
  3480                              <1> 	;
  3481                              <1> 	;	BH = 6 = Linear Frame Buffer direct video memory access
  3482                              <1> 	;
  3483                              <1> 	;		Page directory & page tables of the user's
  3484                              <1> 	;		program will be updated to direct access to
  3485                              <1> 	;		the configured LFB (Linear Frame Buffer) address,
  3486                              <1> 	;		if there is not a permission conflict or lock!
  3487                              <1> 	;	        (User's program/process will have permission to
  3488                              <1> 	;		access locked display memory if the owner is
  3489                              <1> 	;		it's parent.)
  3490                              <1> 	;
  3491                              <1> 	;	   ; 10/12/2020
  3492                              <1> 	;	   BL = 0FFh -> Direct LFB access for current video mode
  3493                              <1> 	;	   BL = XXh < 0FFh -> Direct LFB access
  3494                              <1> 	; 			      for VESA video mode 1XXh
  3495                              <1> 	;
  3496                              <1> 	;		Return: EAX = Linear Frame Buffer address
  3497                              <1> 	;			(EAX = 0 -> error)
  3498                              <1> 	;		     If EAX > 0
  3499                              <1> 	;			EDX = Frame Buffer Size in bytes
  3500                              <1> 	;		         BH = Requested Video Mode - 100h
  3501                              <1> 	;		              (VESA VBE video modes)	
  3502                              <1> 	;		         BL = bits per pixel
  3503                              <1> 	;			      8 = 256 colors, 8
  3504                              <1> 	;		             16 = 65536 colors, 5-6(G)-5 
  3505                              <1> 	;		             24 = RGB, 16M colors, 8-8-8
  3506                              <1> 	;		             32 = RGB + alpha bytes, 8-8-8-8
  3507                              <1> 	;		     If BH = 0FFh
  3508                              <1> 	;		        BL = VGA/CGA video mode (also EAX = 0)
  3509                              <1> 	;
  3510                              <1> 	;		** Function will return with EAX = 0 if the mode
  3511                              <1> 	;		is not a valid VESA VBE video mode as 1??h **
  3512                              <1> 	;
  3513                              <1> 	;		ECX = Pixel resolution
  3514                              <1> 	;		      CX = Width (320, 640, 800, 1024, 1366, 1920)
  3515                              <1> 	;		      High 16 bits of ECX = Height
  3516                              <1> 	;
  3517                              <1> 	; 	23/11/2020
  3518                              <1> 	; ***	GET VIDEO MODE & LINEAR FRAME BUFFER INFO
  3519                              <1> 	;	(This function -7- also is used for VGA and CGA modes)
  3520                              <1> 	;
  3521                              <1> 	;	BH = 7 = Get Linear Frame Buffer info
  3522                              <1> 	;
  3523                              <1> 	;	   ; 22/01/2021
  3524                              <1> 	;	   ; 10/12/2020
  3525                              <1> 	;	   BL = any -not used- (22/01/2021)
  3526                              <1> 	;
  3527                              <1> 	;		Return:
  3528                              <1> 	;		EAX = Frame Buffer Address (0 = is not in use)
  3529                              <1> 	;		EDX = Frame Buffer Size in bytes
  3530                              <1> 	;		 BH = Current Video Mode - 100h  ; 22/01/2021
  3531                              <1> 	;		     (VESA VBE video modes)
  3532                              <1> 	;		 BL = bits per pixel
  3533                              <1> 	;			8 = 256 colors, 8
  3534                              <1> 	;		       16 = 65536 colors, 5-6(G)-5
  3535                              <1> 	;		       24 = RGB, 16M colors, 8-8-8
  3536                              <1> 	;		       32 = RGB + alpha bytes, 8-8-8-8
  3537                              <1> 	;		If BH = 0FFh
  3538                              <1> 	;		   BL = VGA/CGA video mode (also EAX = 0)
  3539                              <1> 	;
  3540                              <1> 	;		Note:
  3541                              <1> 	;		Alpha byte will be used as virtual color index.
  3542                              <1> 	;		(32 bit pixel colors.. byte 0,1,2 rgb and 3 alpha)
  3543                              <1> 	;
  3544                              <1> 	;		** Function will return with EAX = 0 if the mode
  3545                              <1> 	;		is not a valid VESA VBE video mode as 1??h **
  3546                              <1> 	;
  3547                              <1> 	;		ECX = Pixel resolution
  3548                              <1> 	;		      CX = Width (320, 640, 800, 1024, 1366, 1920)
  3549                              <1> 	;		      High 16 bits of ECX = Height  
  3550                              <1> 	;
  3551                              <1> 	;	NOTE: Each process will have it's own frame buffer
  3552                              <1> 	;	      address and resolution parameters in 'u' area.
  3553                              <1> 	;	      Then, if the current frame buffer & resolution
  3554                              <1> 	;	      is different, frame buffer r/w functions
  3555                              <1> 	;	      will use scale factor to convert process's
  3556                              <1>         ;             pixel coordinates to actual screen coordinates.
  3557                              <1> 	;	      resolution -> dimensional scale
  3558                              <1> 	;	      color size -> color scale
  3559                              <1> 	;	     * RGB (TRUE) colors to 256 colors conversion:
  3560                              <1>         ;             TRUE Colors -> 8,8,8 (R,G,B; byte 0 is R)
  3561                              <1> 	;	      256 colors -> 2,2,2,2 (R,G,B,L; bit 0&1 is R)
  3562                              <1> 	; 		  bit 6&7 -> luminosity base level (0,1,2,3)
  3563                              <1> 	;		  bit 4&5 -> blue level (0,1,2,3)
  3564                              <1> 	;		  bit 2%3 -> green level (0,1,2,3)
  3565                              <1> 	;		  bit 0&1 -> red level (0,1,2,3)
  3566                              <1> 	;	      Example: total red level : luminosity + red level
  3567                              <1> 	;	      Luminosity base level: 0 -> 16
  3568                              <1> 	;		 		     1 -> 32
  3569                              <1> 	;				     2 -> 64
  3570                              <1> 	;				     3 -> 128
  3571                              <1> 	;	      Color level:
  3572                              <1> 	;				    0 -> 0
  3573                              <1> 	;				    1 -> luminosity level
  3574                              <1> 	;				    2 -> luminosity level + 64
  3575                              <1> 	;				    3 -> 255
  3576                              <1> 	;	     Luminosity base level = min (R,G,B)
  3577                              <1> 	;			if it is <16, it will be set to 16
  3578                              <1> 	;	     Color levels: Color values are fixed to (nearest)
  3579                              <1> 	;		   one of all possible set level (step) values
  3580                              <1> 	;		   (according to luminosity base level); then
  3581                              <1> 	;		   color levels are set to R-L, G-L, B-L.
  3582                              <1> 	;	 For example: If luminosity base level is 32
  3583                              <1> 	;		  all possible set values are 0, 32, 96, 255.
  3584                              <1> 	;
  3585                              <1> 	;	    * RGB (TRUE) colors to 16 colors conversion:
  3586                              <1> 	;	    16 colors: R,B,G,L bits (4 bits)
  3587                              <1> 	;	    	   If any one of R,G,B >= 128 L = 1
  3588                              <1>  	;		   If max. value of (R,G,B) >= 32, it is 1
  3589                              <1> 	;		      else all color bits (R&G&B&L) are 0
  3590                              <1> 	;		   If the second value >= max. value / 2
  3591                              <1> 	;		      it is 1
  3592                              <1> 	;		   If the third value >= max. value / 2
  3593                              <1> 	;		      it is 1
  3594                              <1> 	;	    Example: R = 132, G = 64, B = 78
  3595                              <1> 	;		     L = 1, R = 1
  3596                              <1> 	;		     G < 66 --> G = 0
  3597                              <1> 	;		     B >= 66 --> B = 1
  3598                              <1> 	;
  3599                              <1> 	; 10/12/2020
  3600                              <1> 	; SET VIDEO MODE (& RETURN LFB INFO for VESA VBE VIDEO MODES)
  3601                              <1> 	;	
  3602                              <1> 	;	BH = 8 = Set Video Mode
  3603                              <1> 	;		
  3604                              <1> 	;		BL = Requested Video Mode (method)
  3605                              <1> 	;		If BL = 0FFh
  3606                              <1> 	;		   CX = VESA VBE Video Mode
  3607                              <1> 	;		   ; 11/12/2020
  3608                              <1> 	;		   If EDX > 0 -> LFB INFO (user) buffer addr
  3609                              <1> 	;		If BL < 0FFh, it is VGA/CGA video mode and
  3610                              <1> 	;			CX & EDX will not be used
  3611                              <1> 	;
  3612                              <1> 	;	    NOTE: The last VESA VBE video mode is 11Bh but
  3613                              <1> 	;	    TRDOS 386 will permit to set video mode upto 11Fh.
  3614                              <1> 	;	    Above 11Fh, from 140h to 1FEh, it will be accepted
  3615                              <1> 	;	    as Bochs/Plex86 emulator video mode and it will be
  3616                              <1> 	;	    used only if [vbe3] = 2 and detected
  3617                              <1> 	;	    video bios is BOCHS/PLEX86/QEMU/VIRTUALBOX vbios.
  3618                              <1> 	;
  3619                              <1> 	; Outputs:
  3620                              <1> 	;	EAX = Requested (Proper) video mode number + 1
  3621                              <1> 	;	      ("dec eax" by user will give requested video mode),
  3622                              <1> 	;
  3623                              <1> 	;	If BL input is 0FFh
  3624                              <1> 	;	   EDX = LFBINFO table/structure (in user's buffer addr)
  3625                              <1> 	;	   EDX = 0 -> Invalid LFBINFO (do not use it)
  3626                              <1> 	;
  3627                              <1> 	;	EAX = 0 -> Error (but EDX will not be changed)
  3628                              <1> 	;
  3629                              <1> 	; 03/12/2020
  3630                              <1> 	; VESA VBE3 VIDEO BIOS (32 bit) PROTECTED MODE INTERFACE SETTINGS
  3631                              <1> 	;
  3632                              <1> 	;	BH = 9 = set/get VBE3 Protected Mode Interface parameters
  3633                              <1> 	;
  3634                              <1> 	;		BL = 0 - Disable protected mode interface
  3635                              <1> 	;			([pmi32] = 0)
  3636                              <1> 	;		 	Return: AL = 1
  3637                              <1> 	;		BL = 1 - Enable protected mode Interface
  3638                              <1> 	;			([pmi32] = 1)
  3639                              <1> 	;			Return: AL = 2
  3640                              <1> 	;		BL = 2 - Get protected mode interface status
  3641                              <1> 	;			Return: AL = [pmi32] + 1 (AL = 1 or 2)
  3642                              <1> 	;
  3643                              <1> 	;		If [vbe3] <> 3 --> AL = 0
  3644                              <1> 	;
  3645                              <1> 	;		; 17/01/2021
  3646                              <1> 	;		BL = 3 - Disable/Cancel restore permission to user
  3647                              <1> 	;			Return: AL = 1 (if disabled) or 0
  3648                              <1> 	;		BL = 4 - Enable/Give restore permission to user
  3649                              <1> 	;			Return: AL = 2 (if enabled) or 0
  3650                              <1> 	;		BL = 5 - Get video state save/restore status
  3651                              <1> 	;			 (permission status)
  3652                              <1> 	;		        Return: AL = Status (enabled = 1)
  3653                              <1> 	;				; 22/01/2021
  3654                              <1> 	;				AH = state options ([srvso])
  3655                              <1> 	;		BL = 6 - Return VESA VBE number/status
  3656                              <1> 	;		        Return: AX = status
  3657                              <1> 	;			      if AH =  2, AL > 0 : Emulator
  3658                              <1> 	;				 AH =  3, VESA VBE3 video bios
  3659                              <1> 	;		; 28/02/2021
  3660                              <1> 	;		BL = 7 - Set true color mode as 32bpp (default)
  3661                              <1> 	;			Return: AX = 32 (if VBE3) 
  3662                              <1> 	;		NOTE: Initial/default value is 32bpp for vbe3.
  3663                              <1> 	;			Return: AX = 0 -> error
  3664                              <1> 	;		BL = 8 - Set true color mode as 24bpp (default)
  3665                              <1> 	;			Return: AX = 24
  3666                              <1> 	;			;Return: AX = 0 -> error
  3667                              <1> 	;		BL = 9 - Return default/current true color mode
  3668                              <1> 	;			Return: AX = 32 (32 bpp)
  3669                              <1> 	;			Return: AX = 24 (24 bpp)
  3670                              <1> 	;			Return: AX = 0 -> error (not VESA bios)
  3671                              <1> 	;
  3672                              <1> 	;		BL > 9 : not implemented (28/02/2021)
  3673                              <1> 	;
  3674                              <1> 	;	; 19/01/2021 ([u.uid] check)
  3675                              <1> 	;	Note: Enabling/Disabling are done by root ([u.uid] = 0)
  3676                              <1> 	;	      while [multi_tasking] = 0.
  3677                              <1> 	;
  3678                              <1>     	; 23/12/2020
  3679                              <1> 	; VIDEO MEMORY MAPPING:
  3680                              <1> 	;	BH = 10 = Map video memory to user's buffer
  3681                              <1> 	;
  3682                              <1> 	;	   BL = 0 : CGA memory (0B8000h) map (32K)
  3683                              <1> 	;	   BL = 1 : VGA memory (0A0000h) map (64K)
  3684                              <1> 	;	   BL = 2 : SVGA memory (LFB) map to user's buffer
  3685                              <1> 	;
  3686                              <1> 	;	ECX = User's buffer addr (low 12 bits will be cleared)
  3687                              <1> 	;	EDX = Buffer size in bytes (if BL = 2)
  3688                              <1> 	;		(will be trimmed if LFB size < EDX)
  3689                              <1> 	; Return:
  3690                              <1>         ;	EAX = physical address of video memory (buffer)
  3691                              <1> 	;	EBX = mapped (actual) size of video memory (bytes)
  3692                              <1> 	;	ECX = virtual start address of user's video buffer 
  3693                              <1> 	;	EDX is same with EDX input
  3694                              <1> 	;
  3695                              <1> 	;	(Note: Memory page boundaries will be applied 
  3696                              <1> 	;	 to buffer size and buff start addr by rounding down.
  3697                              <1> 	;	 Rounded size & address values must not be zero.) 
  3698                              <1> 	;	-Normally, it is expected to request mapping by using
  3699                              <1> 	;	 correct buffer size of current or desired video mode-
  3700                              <1> 	;
  3701                              <1> 	;	EAX = 0 -> error ! memory can not mapped to user
  3702                              <1> 	;
  3703                              <1> 	; 04/01/2021
  3704                              <1> 	; SET/READ COLOR PALETTE (set/read DAC color registers)
  3705                              <1> 	;	((256 colors (8bpp) VGA/CGA video hardware feature))
  3706                              <1> 	;
  3707                              <1> 	;	BH = 11 = Set/Read DAC color registers
  3708                              <1> 	;
  3709                              <1> 	;	   (BL<4 Original method for std VGA video hardware)
  3710                              <1> 	;	   BL = 0 : Read all DAC color registers (256 colors)
  3711                              <1> 	;	       (6 bit colors, in RGB order)
  3712                              <1> 	;	   BL = 1 : Set all DAC color registers (256 colors)
  3713                              <1> 	;	       (6 bit colors, in RGB order)
  3714                              <1> 	;	   BL = 2 : Read single DAC color register
  3715                              <1> 	;	       (6 bit color, in RGB order)
  3716                              <1> 	;		((EAX will return with color value))
  3717                              <1> 	;		CL = DAC color register (index)
  3718                              <1> 	;	   BL = 3 : Set/Write single DAC color register
  3719                              <1> 	;	       (6 bit color, in RGB order, bit 6&7 are 0)
  3720                              <1> 	;		ECX byte 0 - DAC color register
  3721                              <1> 	;		ECX byte 1 - Red (6 bit)
  3722                              <1> 	;		ECX byte 2 - Green (6 bit)
  3723                              <1> 	;		ECX byte 3 - Blue (6 bit)
  3724                              <1> 	;	   (BL>3 Alternative method for BMP files etc.)	
  3725                              <1> 	;	   BL = 4 : Read all DAC color registers (256 colors)
  3726                              <1> 	;	       (8 bit colors, in BGR order, bit 0&1 is 0)
  3727                              <1> 	;	   BL = 5 : Set all DAC color registers (256 colors)
  3728                              <1> 	;	       (8 bit colors, in BGR order, bit 0&1 is 0)
  3729                              <1> 	;	   BL = 6 : Read single DAC color register
  3730                              <1> 	;	       (8 bit color, in BGR order, bit 0&1 is 0)
  3731                              <1> 	;		((EAX will return with color value))
  3732                              <1> 	;		CL = DAC color register (index)
  3733                              <1> 	;	   BL = 7 : Set/Write single DAC color register
  3734                              <1> 	;	       (8 bit color, bit 0&1 are 0)
  3735                              <1> 	;		ECX byte 0 - DAC color register
  3736                              <1> 	;		ECX byte 1 - Blue (8 bit)
  3737                              <1> 	;		ECX byte 2 - Green (8 bit)
  3738                              <1> 	;		ECX byte 3 - Red (8 bit)
  3739                              <1> 	;
  3740                              <1> 	;	  BL > 7 : invalid (not implemented)
  3741                              <1> 	;
  3742                              <1> 	;   if BL bit 2 is 1, 6 bit colors converted to 8 bit colors
  3743                              <1> 	;	(low two bits of color bytes will be 0)
  3744                              <1> 	;     ((color byte 00111111b will be converted to 11111100b))
  3745                              <1> 	;	and RGB byte order will be 
  3746                              <1> 	;		byte 0 - Blue (low 2 bits are 0)
  3747                              <1> 	;		byte 1 - Green (low 2 bits are 0)
  3748                              <1> 	;		byte 2 - Red (low 2 bits are 0)
  3749                              <1> 	;		byte 3 - pad (or zero byte)
  3750                              <1> 	;	and 256 colors buffer size must be 256*4 = 1024 bytes
  3751                              <1> 	;   if BL bit 2 is 0, 6 bit colors will be used directly
  3752                              <1> 	;	  (high two bits of 8 bit color bytes will be 0)
  3753                              <1> 	;     ((dac color 111111b will be converted to 00111111b))
  3754                              <1> 	;		byte 0 - Red (high 2 bits are 0)
  3755                              <1> 	;		byte 1 - Green (high 2 bits are 0)
  3756                              <1> 	;		byte 2 - Blue (high 2 bits are 0)
  3757                              <1> 	;	and 256 colors buffer size must be 256*3 = 768 bytes
  3758                              <1> 	;
  3759                              <1> 	;	ECX = User's buffer addr (256*3 = 768 bytes) or
  3760                              <1> 	;	      Color
  3761                              <1> 	;
  3762                              <1> 	; Return:
  3763                              <1>         ;	EAX = buffer size (for BL input = 0,1,4,5)
  3764                              <1> 	;	      or color value (for BL input = 2,3,6,7)
  3765                              <1> 	;
  3766                              <1> 	; 10/01/2021
  3767                              <1> 	; SET/READ FONT DATA
  3768                              <1> 	;
  3769                              <1> 	;	BH = 12 = Set/Read Character Font Data
  3770                              <1> 	;
  3771                              <1> 	;	   BL = 0 : Disable system font overwrite
  3772                              <1> 	;	   BL = 1 : Enable system font overwrite
  3773                              <1> 	;	   BL = 2 : Read system font 8x8
  3774                              <1> 	;	   BL = 3 : Read system font 8x14
  3775                              <1> 	;	   BL = 4 : Read system font 8x16
  3776                              <1> 	;	   BL = 5 : Read user defined font 8x8
  3777                              <1> 	;	   BL = 6 : Read user defined font 8x16
  3778                              <1> 	;	   BL = 7 : Write system font 8x8
  3779                              <1> 	;	   BL = 8 : Write system font 8x14
  3780                              <1> 	;	   BL = 9 : Write system font 8x16
  3781                              <1> 	;	   BL = 10 : Write user defined font 8x8
  3782                              <1> 	;	   BL = 11 : Write user defined font 8x16
  3783                              <1> 	;
  3784                              <1> 	;	  BL > 11 : invalid (not implemented)
  3785                              <1> 	;
  3786                              <1> 	;	For BL = 1 to 11
  3787                              <1> 	;	   ECX = number of characters (<= 256)
  3788                              <1> 	;	   EDX = first character (ascii code in DL)
  3789                              <1> 	;	   ESI = user's buffer address
  3790                              <1> 	;
  3791                              <1> 	; Return:
  3792                              <1>         ;	EAX = number of characters (ecx input)
  3793                              <1> 	;	EAX = 0 -> error
  3794                              <1> 	;	(EAX = 256 for BL = 0 and 1 if successful)
  3795                              <1> 	;
  3796                              <1> 	; Note: system font overwrite permission will be
  3797                              <1> 	;       given if [multi_tasking] = 0
  3798                              <1> 	;	and [u.uid] = 0 (BL = 1) ; 19/01/2021
  3799                              <1> 	;       and if [ufont] bit 7 is 1 (BL = 7,8,9)
  3800                              <1> 	;
  3801                              <1> 	; 18/01/2021
  3802                              <1> 	; SAVE/RESTORE STANDARD VGA VIDEO STATE
  3803                              <1> 	;
  3804                              <1> 	;	BH = 13 = Save/Restore std VGA video state
  3805                              <1> 	;
  3806                              <1> 	;	   BL = 0 : Save VGA state (without DAC regs)
  3807                              <1> 	;		Return: EAX = VideoStateID (>0)
  3808                              <1> 	;			EAX = 0 (failed!)
  3809                              <1> 	;	       (size: 110 bytes for TRDOS 386 v2.0.3)
  3810                              <1> 	;	   BL = 1 : Restore VGA state (without DAC regs)
  3811                              <1> 	;		ECX = VideoStateID (to be verified)
  3812                              <1> 	;	        Return: EAX = Restore size (>0)
  3813                              <1> 	;	   BL = 2 : Save VGA state (complete)
  3814                              <1> 	;		Return: EAX = VideoStateID (>0)
  3815                              <1> 	;			EAX = 0 (failed!)
  3816                              <1> 	;	       (size: 882 bytes for TRDOS 386 v2.0.3)
  3817                              <1> 	;	   BL = 3 : Restore VGA state (complete)
  3818                              <1> 	;		ECX = VideoStateID (to be verified)
  3819                              <1> 	;	        Return: EAX = Restore size (>0)
  3820                              <1> 	;
  3821                              <1> 	;	* Above options are for saving
  3822                              <1> 	;	*       video state to system memory
  3823                              <1> 	;	*	(location: VBE3VIDEOSTATE, 2048 bytes)
  3824                              <1> 	;
  3825                              <1> 	;	   BL = 4 : Save VGA state (without DAC regs)
  3826                              <1> 	;		ECX = buffer address
  3827                              <1> 	;		Return: EAX = transfer count
  3828                              <1> 	;	       (size: 110 bytes for TRDOS 386 v2.0.3)
  3829                              <1> 	;		ECX = buffer address
  3830                              <1> 	;	   BL = 5 : Restore VGA state (without DAC regs)
  3831                              <1> 	;		ECX = buffer address
  3832                              <1> 	;	        Return: EAX = transfer count
  3833                              <1> 	;	   BL = 6 : Save VGA state (complete)
  3834                              <1> 	;		ECX = buffer address
  3835                              <1> 	;		Return: EAX = transfer count
  3836                              <1> 	;	       (size: 882 bytes for TRDOS 386 v2.0.3)
  3837                              <1> 	;	   BL = 7 : Restore VGA state (complete)
  3838                              <1> 	;		ECX = buffer address
  3839                              <1> 	;	        Return: EAX = transfer count
  3840                              <1> 	;
  3841                              <1> 	;	* Above options are for saving
  3842                              <1> 	;	*       video state to user's buffer
  3843                              <1> 	;	*	(buffer size: 110 bytes or 882 bytes)
  3844                              <1> 	;
  3845                              <1> 	;	  BL > 7 : invalid (not implemented)
  3846                              <1> 	;
  3847                              <1> 	; 18/01/2021
  3848                              <1> 	; SAVE/RESTORE SUPER VGA (VESA VBE 2/3) VIDEO STATE
  3849                              <1> 	;
  3850                              <1> 	;	BH = 14 = Save/Restore SVGA video state
  3851                              <1> 	;
  3852                              <1> 	;	   BL = options
  3853                              <1> 	;		bit 0 - Save (0) or Restore (1)
  3854                              <1> 	;		bit 1 - controller hardware state
  3855                              <1> 	;		bit 2 - BIOS data state
  3856                              <1> 	;		bit 3 - DAC state
  3857                              <1> 	;		bit 4 - (extended) Register state
  3858                              <1> 	;		bit 5 - system (0) or user (1) memory
  3859                              <1> 	;		bit 6 - verify without transfer
  3860                              <1> 	;		bit 7 - not used (must be 0)
  3861                              <1> 	;
  3862                              <1> 	;	     if bit 0 = 0 and bit 5 = 0
  3863                              <1> 	;		Return:	EAX = VideoStateID (>0)
  3864                              <1> 	;	     if bit 0 = 1
  3865                              <1> 	;		ECX = VideoStateID (bit 5 = 0)
  3866                              <1> 	;		Return: EAX = restore (transfer) size
  3867                              <1> 	;	     if bit 5 = 1
  3868                              <1> 	;		ECX = Buffer address
  3869                              <1> 	;		Return: EAX = transfer count (size)
  3870                              <1> 	;
  3871                              <1> 	;	     ECX = Buffer address or VideoStateID
  3872                              <1> 	;
  3873                              <1> 	;	  BL > 127 : invalid (not implemented)
  3874                              <1> 	;
  3875                              <1> 	;  Note: Required buffer size may be > 2048 bytes
  3876                              <1> 	;	 (function fails when buff size > 2048 bytes)
  3877                              <1> 	;	 proper option must be used
  3878                              <1> 	;
  3879                              <1> 	; 18/01/2021
  3880                              <1> 	; READ VESA EDID (EXTENDED DISPLAY IDENTIFICATION DATA)
  3881                              <1> 	;
  3882                              <1> 	;	BH = 15 = Read VESA EDID for connected monitor
  3883                              <1> 	;		  (copy EDID to user)
  3884                              <1> 	;
  3885                              <1> 	;	   BL = any
  3886                              <1> 	;
  3887                              <1> 	;	Input:
  3888                              <1> 	;	    ECX = user's (EDID) buffer address 
  3889                              <1> 	;		 (buffer size: 128 bytes)
  3890                              <1> 	;	Output:
  3891                              <1> 	;	    EAX = 128 (EDID size)
  3892                              <1> 	;	    or EAX = 0 -> Error!
  3893                              <1> 	;	       (EDID not ready or buffer addr error)
  3894                              <1> 	;
  3895                              <1> 
  3896                              <1> 	; 16/05/2016
  3897 0000D7B5 31C0                <1> 	xor	eax, eax
  3898 0000D7B7 A3[74940100]        <1> 	mov	[u.r0], eax
  3899 0000D7BC 20FF                <1> 	and	bh, bh
  3900                              <1> 	;jnz	sysvideo_13 ; 11/07/2016
  3901                              <1> 	; 23/07/2022
  3902 0000D7BE 7405                <1> 	jz	short sysvideo_40
  3903 0000D7C0 E974020000          <1> 	jmp	sysvideo_13
  3904                              <1> 
  3905                              <1> sysvideo_40:	; 23/07/2022
  3906                              <1> 	;; 21/11/2020 (TRDOS 386 v2.0.3)
  3907                              <1> 	;; tty/text mode transfers are only for video mode 3
  3908                              <1> 
  3909                              <1> 	; 22/11/2020
  3910                              <1> 	;cmp	byte [CRT_MODE], 3 ; 80x25 text, 16 colors
  3911                              <1> 	;jne	sysret ; invalid (nothing to do), [u.r0] = 0
  3912                              <1> 	
  3913                              <1> 	; 23/11/2020
  3914                              <1> 	; bit 7,6,5,4 of BL are reserved and it must be 0
  3915                              <1> 	;	 	 for current 'sysvideo' version
  3916                              <1> 	;test	bl, 0F0h
  3917                              <1> 	;;jnz	sysret ; invalid (undefined) !
  3918                              <1> 	;; 28/01/2021
  3919                              <1> 	;jnz	short sysvideo_1_2 ; invalid (undefined) !
  3920                              <1> 	; 28/01/2021
  3921 0000D7C5 80FB07              <1> 	cmp	bl, 7
  3922 0000D7C8 776E                <1> 	ja	short sysvideo_1_2 ; invalid (undefined) !
  3923                              <1> 
  3924                              <1> 	; Video mode 0, 80*25 text mode, CGA 16 colors  
  3925                              <1> 	; [CRT_MODE] = 3
  3926                              <1> 	;mov	bh, bl
  3927                              <1> 	;shr	bh, 2 ; 4..7 -> 1, 8..11 -> 2, 12..15 -> 3
  3928                              <1> 	;; 21/11/2020
  3929                              <1> 	;;and	bh, bh
  3930                              <1>         ;jnz	sysvideo_4  ; Display page window transfer etc.
  3931                              <1> 
  3932                              <1> 	; 28/01/2021
  3933 0000D7CA F6C304              <1> 	test	bl, 4 ; bit 2
  3934                              <1> 	;jnz	sysvideo_4 ; Display page window transfer
  3935                              <1> 	; 23/07/2022
  3936 0000D7CD 7405                <1> 	jz	short sysvideo_41
  3937 0000D7CF E9A1000000          <1> 	jmp	sysvideo_4
  3938                              <1> sysvideo_41:	; 23/07/2022
  3939                              <1> 	; Display page (complete) transfer
  3940 0000D7D4 80FA07              <1> 	cmp	dl, 7
  3941                              <1> 	;jnz	sysret ; invalid (nothing to do), [u.r0] = 0
  3942 0000D7D7 760A                <1> 	jna	short sysvideo_0 ; 28/01/2021
  3943 0000D7D9 FEC2                <1> 	inc	dl ; 0FFh -> 0 ("use current video page")
  3944 0000D7DB 755B                <1> 	jnz	short sysvideo_1_2  ; invalid
  3945                              <1> 	; dl = 0 -> use current current page
  3946 0000D7DD 8A15[EE7C0100]      <1> 	mov	dl, [ACTIVE_PAGE]
  3947                              <1> sysvideo_0:
  3948                              <1> 	; 28/01/2021
  3949 0000D7E3 80FB03              <1> 	cmp	bl, 3
  3950 0000D7E6 7206                <1> 	jb	short sysvideo_0_0
  3951 0000D7E8 09FF                <1> 	or	edi, edi
  3952 0000D7EA 744C                <1> 	jz	short sysvideo_1_2  ; invalid
  3953 0000D7EC 89FE                <1> 	mov	esi, edi ; save swap/exchange buffer addr
  3954                              <1> 	; ecx = user buffer for new video page content
  3955                              <1> 	; esi = user (swap) buffer for saving current video page
  3956                              <1> sysvideo_0_0:
  3957 0000D7EE BF00800B00          <1> 	mov	edi, 0B8000h
  3958                              <1> 	; dl = display page number, destination
  3959 0000D7F3 66B80010            <1> 	mov	ax, 4096 ; 21/11/2020
  3960 0000D7F7 20D2                <1> 	and	dl, dl
  3961 0000D7F9 7408                <1> 	jz	short sysvideo_1
  3962                              <1> 	; 07/02/2021
  3963 0000D7FB 88D6                <1> 	mov	dh, dl
  3964                              <1> sysvideo_0_1:
  3965                              <1> 	; page length = 4096 bytes (but page content is 80*25*2 bytes)
  3966 0000D7FD 01C7                <1> 	add	edi, eax ; 21//11/2020 ([CRT_LEN] = 1000h for mode 3)
  3967 0000D7FF FECE                <1> 	dec	dh
  3968 0000D801 75FA                <1> 	jnz	short sysvideo_0_1
  3969                              <1> sysvideo_1:
  3970 0000D803 80E303              <1> 	and	bl, 3
  3971 0000D806 7535                <1> 	jnz	short sysvideo_2 ; user to system display page transfer
  3972                              <1> 	; system to system video page (content) transfer
  3973                              <1> 	; cl = display page number, source
  3974 0000D808 80F907              <1> 	cmp	cl, 7
  3975                              <1> 	;ja	sysret ; invalid (nothing to do), [u.r0] = 0
  3976 0000D80B 760A                <1> 	jna	short sysvideo_1_0
  3977 0000D80D FEC1                <1> 	inc	cl ; 0FFh -> 0 ("use current video page")
  3978 0000D80F 7527                <1> 	jnz	short sysvideo_1_2  ; invalid
  3979 0000D811 8A0D[EE7C0100]      <1> 	mov	cl, [ACTIVE_PAGE]
  3980                              <1> sysvideo_1_0:
  3981                              <1> 	; 28/01/2021
  3982 0000D817 38D1                <1> 	cmp	cl, dl
  3983 0000D819 741D                <1> 	je	short sysvideo_1_2  ; same video page !
  3984                              <1> 
  3985                              <1> 	; system to system video/display page transfer (mode 0)
  3986                              <1> 	; 21/11/2020
  3987                              <1> 	;mov	esi, 0B8000h
  3988                              <1> 	;movzx	eax, cl
  3989                              <1> 	;mov	edx, 4096 ; [CRT_LEN] = 1000h for video mode 3
  3990                              <1> 	;mov	ecx, edx
  3991                              <1> 	;mul	edx
  3992                              <1> 	;add	esi, eax
  3993                              <1> 	; 28/01/2021
  3994                              <1> 	;movzx	esi, cl
  3995                              <1> 	;shl	si, 12 ; * 4096
  3996                              <1> 	;add	esi, 0B8000h
  3997                              <1> 	
  3998                              <1> 	; 28/01/2021
  3999 0000D81B A3[74940100]        <1> 	mov	[u.r0], eax ; 4096
  4000 0000D820 BE00800B00          <1> 	mov	esi, 0B8000h
  4001 0000D825 08C9                <1> 	or	cl, cl
  4002 0000D827 7409                <1> 	jz	short sysvideo_1_1
  4003                              <1> 	; 07/02/2021
  4004                              <1> 	;mov	al, cl ; display/video page
  4005                              <1> 	;xor	ah, ah
  4006                              <1> 	;shl	ax, 12 ; * 4096
  4007                              <1> 	; 23/07/2022
  4008 0000D829 30C0                <1>  	xor	al, al
  4009                              <1> 	;xor	eax, eax
  4010 0000D82B 88CC                <1> 	mov	ah, cl ; CL * 256
  4011 0000D82D C1E004              <1> 	shl	eax, 4 ; * 16 = CL * 4096
  4012 0000D830 01C6                <1> 	add	esi, eax
  4013                              <1> sysvideo_1_1:
  4014                              <1> 	; 21/11/2020
  4015                              <1> 	;;mov	ecx, 4096
  4016                              <1> 	;mov	ecx, eax ; 4096
  4017                              <1> 	;;mov	[u.r0], ecx ; 4096 bytes
  4018                              <1> 	; 28/01/2021
  4019                              <1> 	;mov	[u.r0], cx
  4020 0000D832 31C9                <1> 	xor	ecx, ecx
  4021 0000D834 B504                <1> 	mov	ch, 4 ; mov ecx, 1024
  4022                              <1> 	;shr	cx, 2 ; / 4
  4023 0000D836 F3A5                <1> 	rep	movsd
  4024                              <1> sysvideo_1_2:
  4025 0000D838 E917F6FFFF          <1> 	jmp	sysret
  4026                              <1> sysvideo_2:
  4027 0000D83D 80FB02              <1> 	cmp	bl, 2
  4028                              <1>         ;ja	sysret; invalid (user to user), [u.r0] = 0
  4029                              <1> 	; 28/01/2021
  4030 0000D840 7226                <1> 	jb	short sysvideo_3 ; user to system
  4031 0000D842 7404                <1> 	je	short sysvideo_2_0 ; system to user
  4032                              <1> 	; bl = 3
  4033 0000D844 89CA                <1> 	mov	edx, ecx ; save user's buffer addr
  4034 0000D846 89F1                <1> 	mov	ecx, esi ; save swap address
  4035                              <1> sysvideo_2_0:
  4036                              <1> 	; bl = 2 (or bl = 3, stage 1)
  4037                              <1> 	; system to user video/display page transfer (mode 0)
  4038 0000D848 89FE                <1> 	mov	esi, edi
  4039 0000D84A 89CF                <1> 	mov	edi, ecx ; user buffer ; 28/01/2021
  4040                              <1> 	; 21/11/2020
  4041 0000D84C 89C1                <1> 	mov	ecx, eax ; 4096
  4042 0000D84E E83D370000          <1> 	call	transfer_to_user_buffer ; fast transfer
  4043                              <1> 	;jc	sysret ; [u.r0] = 0
  4044 0000D853 72E3                <1> 	jc	short sysvideo_1_2 ; 28/01/2021
  4045                              <1> 	; 28/01/2021
  4046 0000D855 80FB03              <1> 	cmp	bl, 3
  4047 0000D858 7408                <1> 	je	short sysvideo_2_2
  4048                              <1> sysvideo_2_1:
  4049                              <1> 	; 21/11/2020
  4050 0000D85A 890D[74940100]      <1> 	mov	[u.r0], ecx
  4051                              <1> 	;;mov	[u.r0], cx
  4052                              <1> 	;jmp	sysret
  4053 0000D860 EBD6                <1> 	jmp	short sysvideo_1_2
  4054                              <1> 
  4055                              <1> sysvideo_2_2:
  4056                              <1> 	; bl = 3 (exchange/swap) complete display page
  4057                              <1> 	; esi = video page start address
  4058                              <1> 	; edx = user's buffer address
  4059                              <1> 	
  4060                              <1> 	;mov	ecx, 4096
  4061 0000D862 89F7                <1> 	mov	edi, esi ; video page start address
  4062 0000D864 89D6                <1> 	mov	esi, edx ; user's (new page) buffer address
  4063 0000D866 EB04                <1> 	jmp	short sysvideo_2_3
  4064                              <1> sysvideo_3: 
  4065                              <1> 	; bl = 1 (or bl = 3, stage 2)
  4066                              <1> 	; user to system video/display page transfer (mode 0)
  4067 0000D868 89CE                <1> 	mov	esi, ecx ; user buffer
  4068                              <1> 	; edi = video page address
  4069                              <1> 	; 21/11/2020
  4070 0000D86A 89C1                <1> 	mov	ecx, eax ; 4096
  4071                              <1> sysvideo_2_3:
  4072 0000D86C E869370000          <1> 	call	transfer_from_user_buffer ; fast transfer
  4073                              <1> 	;jc	sysret ; [u.r0] = 0
  4074 0000D871 72C5                <1> 	jc	short sysvideo_1_2 ; 28/01/2021
  4075 0000D873 EBE5                <1> 	jmp	short sysvideo_2_1
  4076                              <1> 
  4077                              <1> 	; 21/11/2020
  4078                              <1> 	;mov	[u.r0], ecx
  4079                              <1> 	;;mov	[u.r0], cx
  4080                              <1> 	;;jmp	sysret
  4081                              <1> 	;jmp	short sysvideo_1_2 ; 28/01/2021
  4082                              <1> 
  4083                              <1> sysvideo_4:
  4084                              <1> 	; 23/07/2022
  4085                              <1> 	; 23/11/2020 (TRDOS 386 v2.0.3)
  4086                              <1> 
  4087                              <1> 	; Display page window transfer etc.
  4088 0000D875 80E303              <1> 	and	bl, 3
  4089                              <1>         ;jnz	sysvideo_9 ; user to system or system to user
  4090                              <1> 	; 23/07/2022
  4091 0000D878 7405                <1> 	jz	short sysvideo_4_0
  4092 0000D87A E9E3000000          <1> 	jmp	sysvideo_9
  4093                              <1> sysvideo_4_0:
  4094                              <1> 	; 21/11/2020
  4095                              <1> 	; system to system video/display page window transfer (mode 0)
  4096 0000D87F 81FE00800B00        <1> 	cmp	esi, 0B8000h	; source buffer address (system)
  4097                              <1> 	;jb	sysret
  4098                              <1> 	; 23/07/2022
  4099 0000D885 7245                <1> 	jb	short sysvideo_4_3  ; jmp sysret
  4100 0000D887 81FE00000C00        <1> 	cmp	esi, 0B8000h+(4096*8)
  4101                              <1> 	; 23/07/2022
  4102                              <1> 	;jnb	sysret
  4103 0000D88D 733D                <1> 	jnb	short sysvideo_4_3  ; jmp sysret
  4104 0000D88F 81FF00800B00        <1> 	cmp	edi, 0B8000h	; destination buffer address (system)
  4105                              <1> 	;jb	sysret
  4106                              <1> 	; 23/07/2022
  4107 0000D895 7235                <1> 	jb	short sysvideo_4_3  ; jmp sysret
  4108 0000D897 81FF00000C00        <1>         cmp     edi, 0B8000h+(4096*8)
  4109                              <1> 	; 23/07/2022
  4110                              <1> 	;jnb	sysret
  4111 0000D89D 732D                <1> 	jnb	short sysvideo_4_3  ; jmp sysret
  4112                              <1> 	;
  4113 0000D89F 51                  <1> 	push	ecx ; X1 and Y1 position - top left column, row
  4114 0000D8A0 0FB7C1              <1> 	movzx	eax, cx ; top left column
  4115                              <1> 	; 21/11/2020
  4116 0000D8A3 C1E910              <1> 	shr	ecx, 16 ; top row
  4117 0000D8A6 740E                <1> 	jz	short sysvideo_4_1 ; bypass following code
  4118 0000D8A8 52                  <1> 	push	edx ; X2 and Y2 position - bottom right column, row
  4119 0000D8A9 50                  <1> 	push	eax
  4120 0000D8AA 66B8A000            <1> 	mov	ax, 80*2 ; 80 colums, 160 bytes per row
  4121 0000D8AE F7E1                <1> 	mul	ecx
  4122                              <1> 		; eax = offset for start row number 
  4123 0000D8B0 01C6                <1> 	add	esi, eax
  4124 0000D8B2 01C7                <1> 	add	edi, eax
  4125 0000D8B4 58                  <1> 	pop	eax
  4126 0000D8B5 5A                  <1> 	pop	edx
  4127                              <1> sysvideo_4_1:
  4128                              <1> 	;shl	ax, 1 ; * 2 ; convert start column number to offset
  4129                              <1> 	; 23/07/2022
  4130 0000D8B6 D1E0                <1> 	shl	eax, 1
  4131 0000D8B8 7404                <1> 	jz	short sysvideo_4_2
  4132 0000D8BA 01C6                <1> 	add	esi, eax
  4133 0000D8BC 01C7                <1> 	add	edi, eax
  4134                              <1> 		; esi = source page window start offset
  4135                              <1> 		; edi = destination page window start offset
  4136                              <1> sysvideo_4_2:
  4137 0000D8BE 59                  <1> 	pop	ecx
  4138                              <1> 	;mov	eax, 0B8000h+(80*25*2*8)
  4139                              <1> 	; 21/11/2020
  4140 0000D8BF B800000C00          <1> 	mov	eax, 0B8000h+(4096*8)
  4141 0000D8C4 39C6                <1> 	cmp	esi, eax
  4142                              <1> 	;jnb	sysret ; out of video page
  4143                              <1> 	; 23/07/2022
  4144 0000D8C6 7304                <1> 	jnb	short sysvideo_4_3  ; jmp sysret
  4145 0000D8C8 39C6                <1> 	cmp	esi, eax
  4146                              <1> 	;jnb	sysret  ;out of video page
  4147                              <1> 	; 23/07/2022
  4148 0000D8CA 7205                <1> 	jb	short sysvideo_4_4
  4149                              <1> sysvideo_4_3:
  4150 0000D8CC E983F5FFFF          <1> 	jmp	sysret
  4151                              <1> sysvideo_4_4:
  4152 0000D8D1 56                  <1> 	push	esi ; ****
  4153 0000D8D2 57                  <1> 	push	edi ; ***
  4154 0000D8D3 52                  <1> 	push	edx ; **
  4155 0000D8D4 51                  <1> 	push	ecx ; *
  4156 0000D8D5 C1E910              <1> 	shr	ecx, 16 ; top row
  4157 0000D8D8 C1EA10              <1> 	shr	edx, 16 ; bottom row
  4158                              <1> 	; 21/11/2020
  4159                              <1> 	;cmp	ecx, 24 ; max. 25 rows
  4160 0000D8DB 6683F918            <1> 	cmp	cx, 24
  4161 0000D8DF 7778                <1> 	ja	short sysvideo_6 ; invalid, [u.r0] = 0
  4162                              <1> 	;cmp	edx, 24 ; max. 25 rows
  4163 0000D8E1 6683FA18            <1> 	cmp	dx, 24
  4164 0000D8E5 7772                <1> 	ja	short sysvideo_6 ; invalid, [u.r0] = 0
  4165 0000D8E7 28CA                <1> 	sub	dl, cl ; end >= start
  4166 0000D8E9 726E                <1> 	jc	short sysvideo_6 ; invalid, [u.r0] = 0
  4167                              <1> 	; 21/11/2020
  4168 0000D8EB 89D3                <1> 	mov	ebx, edx ; row count - 1
  4169 0000D8ED 7415                <1> 	jz	short sysvideo_4_5
  4170 0000D8EF 50                  <1> 	push	eax ; *****
  4171 0000D8F0 B8A0000000          <1> 	mov	eax, 80*2 ; bytes per row
  4172 0000D8F5 F7E3                <1> 	mul	ebx ; 21/11/2020
  4173                              <1> 		; eax = window end offset 
  4174                              <1> 		; (for the last row, before adding column bytes)
  4175 0000D8F7 01C6                <1> 	add	esi, eax
  4176 0000D8F9 01C7                <1> 	add	edi, eax
  4177 0000D8FB 58                  <1> 	pop	eax ; ***** ; mode 3 video memory end (0C000h)
  4178 0000D8FC 39C6                <1> 	cmp	esi, eax
  4179                              <1> 	;ja	short sysvideo_6 ; invalid, [u.r0] = 0
  4180 0000D8FE 7359                <1> 	jnb	short sysvideo_6 ; 21/11/2020
  4181 0000D900 39C7                <1> 	cmp	edi, eax
  4182                              <1> 	;ja	short sysvideo_6 ; invalid, [u.r0] = 0
  4183 0000D902 7355                <1> 	jnb	short sysvideo_6 ; 21/11/2020
  4184                              <1> sysvideo_4_5:
  4185 0000D904 59                  <1> 	pop	ecx ; *
  4186 0000D905 5A                  <1> 	pop	edx ; **
  4187 0000D906 81E1FFFF0000        <1> 	and	ecx, 0FFFFh
  4188 0000D90C 81E2FFFF0000        <1> 	and	edx, 0FFFFh
  4189                              <1> 	; 21/11/2020
  4190                              <1> 	;cmp	ecx, 79 ; max. 80 columns
  4191 0000D912 6683F94F            <1> 	cmp	cx, 79
  4192 0000D916 7743                <1> 	ja	short sysvideo_7 ; invalid, [u.r0] = 0
  4193                              <1> 	;cmp	edx, 79 ; max. 80 columns
  4194 0000D918 6683FA4F            <1> 	cmp	dx, 79 
  4195 0000D91C 773D                <1> 	ja	short sysvideo_7 ; invalid, [u.r0] = 0
  4196 0000D91E 28CA                <1> 	sub	dl, cl
  4197 0000D920 7639                <1> 	jna	short sysvideo_7 ; invalid, [u.r0] = 0
  4198                              <1> 	; 21/11/2020
  4199 0000D922 740E                <1> 	jz	short sysvideo_4_6 
  4200                              <1> 	; edx = column count (width) - 1
  4201 0000D924 D0E2                <1> 	shl	dl, 1 ; * 2 ; byte offset (in end row)
  4202 0000D926 01D6                <1> 	add	esi, edx
  4203 0000D928 01D7                <1> 	add	edi, edx
  4204                              <1> 		; esi = source page window end offset
  4205                              <1> 		; edi = destination page window end offset
  4206 0000D92A 39C6                <1> 	cmp	esi, eax ; video memory end
  4207                              <1> 	;ja	short sysvideo_7
  4208 0000D92C 732D                <1> 	jnb	short sysvideo_7 ; 21/11/2020
  4209 0000D92E 39C7                <1> 	cmp	edi, eax ; video memory end
  4210                              <1> 	;ja	short sysvideo_7
  4211 0000D930 7329                <1> 	jnb	short sysvideo_7 ; 21/11/2020
  4212                              <1> sysvideo_4_6:
  4213 0000D932 5F                  <1> 	pop	edi ; ***
  4214 0000D933 5E                  <1> 	pop	esi ; ****
  4215 0000D934 FEC3                <1> 	inc	bl ; row count - 1 -> row count
  4216 0000D936 FEC2                <1> 	inc	dl ; column count
  4217 0000D938 88D7                <1> 	mov	bh, dl
  4218 0000D93A D0E2                <1> 	shl	dl, 1 ; convert column count to byte offset
  4219                              <1> 	; 21/11/2020
  4220                              <1> 	; esi = source page window start offset
  4221                              <1> 	; edi = destination page window start offset
  4222 0000D93C B8A0000000          <1> 	mov	eax, 80*2 ; bytes per row
  4223                              <1> 	; Note: 160 bytes per row (even if move count < 160)
  4224                              <1> sysvideo_5:
  4225 0000D941 88F9                <1> 	mov	cl, bh ; move/transfer -word- count per row
  4226 0000D943 0115[74940100]      <1> 	add	[u.r0], edx ; transfer count in bytes
  4227 0000D949 F366A5              <1> 	rep	movsw
  4228 0000D94C 01C6                <1> 	add	esi, eax ; + 160 bytes to next row
  4229 0000D94E 01C7                <1> 	add	edi, eax ; + 160 bytes to next row
  4230 0000D950 FECB                <1> 	dec	bl ; remain count of rows
  4231 0000D952 75ED                <1> 	jnz	short sysvideo_5
  4232 0000D954 E9FBF4FFFF          <1> 	jmp	sysret
  4233                              <1> 
  4234                              <1> sysvideo_6:
  4235 0000D959 59                  <1> 	pop	ecx ; *
  4236 0000D95A 5A                  <1> 	pop	edx ; **
  4237                              <1> sysvideo_7:
  4238 0000D95B 5F                  <1> 	pop	edi ; ***
  4239 0000D95C 5E                  <1> 	pop	esi ; ****
  4240                              <1> sysvideo_8:
  4241 0000D95D E9F2F4FFFF          <1> 	jmp	sysret
  4242                              <1> 
  4243                              <1> sysvideo_9:
  4244                              <1> 	; user to system or system to user window transfer
  4245                              <1> 	; 28/01/2021 (bl = 3 -> swap/exchange)
  4246                              <1> 	;cmp	bl, 2
  4247                              <1> 	;;ja	sysret	; user to user transfer is invalid
  4248                              <1> 	;		; [u.r0] = 0
  4249                              <1> 	;ja	short sysvideo_8 ; 26/12/2020
  4250                              <1> 
  4251                              <1> 	; 28/01/2021
  4252 0000D962 80FB02              <1> 	cmp	bl, 2
  4253 0000D965 7604                <1> 	jna	short sysvideo_9_8 
  4254                              <1> 
  4255                              <1> 	; swap/ exchange video memory and user mem windows
  4256                              <1> 	; edi = swap address in user's memory space
  4257 0000D967 21FF                <1> 	and	edi, edi
  4258 0000D969 74F2                <1> 	jz	short sysvideo_8 ; invalid ; 28/01/2021
  4259                              <1> 
  4260                              <1> sysvideo_9_8:
  4261 0000D96B 56                  <1> 	push	esi ; ****
  4262 0000D96C 57                  <1> 	push	edi ; ***
  4263 0000D96D 52                  <1> 	push	edx ; **
  4264 0000D96E 51                  <1> 	push	ecx ; *
  4265                              <1> 
  4266 0000D96F C1E910              <1> 	shr	ecx, 16 ; top row
  4267 0000D972 C1EA10              <1> 	shr	edx, 16 ; bottom row
  4268                              <1> 
  4269                              <1> 	; 21/11/2020
  4270                              <1> 	;cmp	ecx, 24 ; max. 25 rows
  4271 0000D975 6683F918            <1> 	cmp	cx, 24
  4272 0000D979 77DE                <1> 	ja	short sysvideo_6 ; invalid, [u.r0] = 0
  4273                              <1> 	;cmp	edx, 24 ; max. 25 rows
  4274 0000D97B 6683FA18            <1> 	cmp	dx, 24
  4275 0000D97F 77D8                <1> 	ja	short sysvideo_6 ; invalid, [u.r0] = 0
  4276 0000D981 28CA                <1> 	sub	dl, cl
  4277 0000D983 72D4                <1> 	jc	short sysvideo_6 ; invalid, [u.r0] = 0
  4278                              <1> 
  4279                              <1> 	;mov	ch, cl ; top row
  4280                              <1> 	;mov	cl, [ACTIVE_PAGE]
  4281                              <1> 
  4282                              <1> 	;mov	edi, 80*25*2 ; 4000
  4283                              <1> 	; 21/11/2020
  4284                              <1> 	;mov	edi, 4096 ; [CRT_LEN = 4096 for video mode 3
  4285                              <1> 	;shl	edi, cl  ; ! wrong for page 2 to page 7 !
  4286                              <1> 	;;add	edi, 0B8000h - 80*25*2
  4287                              <1> 	;add	edi, 0B8000h - 1000h ; - 4096
  4288                              <1> 
  4289                              <1> 	; 21/11/2020
  4290                              <1> 	;xor	eax, eax
  4291                              <1> 	;mov	edi, 0B8000h
  4292                              <1> 	;and	cl, cl ; is video page = 0 ?
  4293                              <1> 	;jz	short sysvideo_9_1 ; yes
  4294                              <1> 	; eax = 0
  4295                              <1> 
  4296                              <1> ;sysvideo_9_0:
  4297                              <1> 	;add	ax, 4096
  4298                              <1> 	;dec	cl
  4299                              <1> 	;jnz	short sysvideo_9_0
  4300                              <1> 	;add	edi, eax
  4301                              <1> 	;	; edi = video page start address
  4302                              <1> 
  4303                              <1> 	; 21/11/2020
  4304 0000D985 BF00800B00          <1> 	mov	edi, 0B8000h
  4305 0000D98A 803D[EE7C0100]00    <1> 	cmp	byte [ACTIVE_PAGE], 0
  4306 0000D991 760C                <1> 	jna	short sysvideo_9_1
  4307                              <1> stsvideo_9_0:
  4308 0000D993 B010                <1> 	mov	al, 16 ; 4096/256
  4309 0000D995 F625[EE7C0100]      <1> 	mul	byte [ACTIVE_PAGE]
  4310 0000D99B 86C4                <1> 	xchg	ah, al ; * 256
  4311 0000D99D 01C7                <1> 	add	edi, eax
  4312                              <1> 		; edi = video page start address
  4313                              <1> sysvideo_9_1:
  4314                              <1> 	; bl = transfer direction 
  4315                              <1> 	;     (1 = from user, 2 = to user)
  4316                              <1> 	;     (3 = swap) ; 28/01/2021
  4317 0000D99F 88D7                <1> 	mov	bh, dl ; row count - 1
  4318                              <1> 	;mov	dl, ch ; top row
  4319                              <1> 	; 21/11/2020
  4320 0000D9A1 08C9                <1> 	or	cl, cl ; top row number
  4321 0000D9A3 7408                <1> 	jz	short sysvideo_9_2
  4322                              <1> 
  4323                              <1> 	;mov	eax, 80*2
  4324 0000D9A5 66B8A000            <1> 	mov	ax, 80*2 ; 160, bytes per row
  4325 0000D9A9 F7E1                <1> 	mul	ecx ; 22/11/2020
  4326 0000D9AB 01C7                <1> 	add	edi, eax
  4327                              <1> 		; edi = window start address for top row
  4328                              <1> sysvideo_9_2:
  4329 0000D9AD 59                  <1> 	pop	ecx ; *
  4330 0000D9AE 5A                  <1> 	pop	edx ; **
  4331 0000D9AF 81E1FFFF0000        <1> 	and	ecx, 0FFFFh
  4332 0000D9B5 81E2FFFF0000        <1> 	and	edx, 0FFFFh
  4333                              <1> 	; 21/11/2020
  4334                              <1> 	;cmp	ecx, 79 ; max. 80 columns
  4335 0000D9BB 6683F94F            <1> 	cmp	cx, 79
  4336 0000D9BF 779A                <1> 	ja	short sysvideo_7 ; invalid, [u.r0] = 0
  4337                              <1> 	;cmp	edx, 79 ; max. 80 columns
  4338 0000D9C1 6683FA4F            <1> 	cmp	dx, 79
  4339 0000D9C5 7794                <1> 	ja	short sysvideo_7 ; invalid, [u.r0] = 0
  4340                              <1> 
  4341 0000D9C7 28CA                <1> 	sub	dl, cl
  4342 0000D9C9 7290                <1> 	jc	short sysvideo_7 ; invalid, [u.r0] = 0
  4343                              <1> 
  4344 0000D9CB 08C9                <1> 	or	cl, cl ; left column 
  4345 0000D9CD 7404                <1> 	jz	short sysvideo_9_3 ; 0
  4346                              <1> 
  4347                              <1> 	; 21/11/2020
  4348 0000D9CF D0E1                <1> 	shl	cl, 1  ; column * 2
  4349 0000D9D1 01CF                <1> 	add	edi, ecx
  4350                              <1> 		; edi = window start addr for top left column
  4351                              <1> sysvideo_9_3:
  4352 0000D9D3 88D1                <1> 	mov	cl, dl
  4353 0000D9D5 FEC1                <1> 	inc	cl ; column count
  4354 0000D9D7 D0E1                <1> 	shl	cl, 1 ; column count * 2
  4355                              <1> 		; ecx = transfer count per row
  4356                              <1> 
  4357 0000D9D9 58                  <1> 	pop	eax ; *** (swap address)
  4358 0000D9DA 5E                  <1> 	pop	esi ; ****
  4359                              <1> 
  4360 0000D9DB FEC7                <1> 	inc	bh  ; row count
  4361                              <1> 	
  4362                              <1> 	;mov	edx, 80*2
  4363 0000D9DD B2A0                <1> 	mov	dl, 80*2  ; bytes per row
  4364                              <1> 	;
  4365                              <1> 	;cmp	bl, 1 ; transfer direction
  4366                              <1> 	;ja	short sysvideo_11 ; system to user transfer
  4367                              <1> 	; 28/01/2021
  4368 0000D9DF F6C301              <1> 	test	bl, 1
  4369 0000D9E2 7439                <1> 	jz	short sysvideo_11 ; system to user transfer
  4370                              <1> 
  4371                              <1> 	; user to system video/display page window transfer (mode 0)	
  4372 0000D9E4 21C0                <1> 	and	eax, eax ; swap address
  4373 0000D9E6 741B                <1> 	jz	short sysvideo_10 ; no window swap
  4374                              <1> sysvideo_9_7: ; 28/01/2021
  4375                              <1> 	; save previous window content in user's buffer (swap address)
  4376 0000D9E8 56                  <1> 	push	esi ; user buffer
  4377 0000D9E9 57                  <1> 	push	edi ; beginning address of the window
  4378                              <1> 	; 21/11/2020
  4379 0000D9EA 53                  <1> 	push	ebx ; save bh
  4380 0000D9EB 89FE                <1> 	mov	esi, edi
  4381 0000D9ED 89C7                <1> 	mov	edi, eax
  4382                              <1> sysvideo_9_4:
  4383 0000D9EF E89C350000          <1> 	call	transfer_to_user_buffer ; fast transfer
  4384 0000D9F4 7208                <1> 	jc	short sysvideo_9_5
  4385                              <1> 	; ecx = actual transfer count (must be same with input)
  4386 0000D9F6 01D6                <1> 	add	esi, edx ; next row address of (video page) window 
  4387 0000D9F8 01CF                <1> 	add	edi, ecx ; next row address of user's window
  4388                              <1> 		; Note: ecx may be less than row length of video page
  4389                              <1> 		; user's window uses offset according to window width
  4390 0000D9FA FECF                <1> 	dec	bh
  4391 0000D9FC 75F1                <1> 	jnz	short sysvideo_9_4 ; repeat for next row
  4392                              <1> sysvideo_9_5:
  4393 0000D9FE 5B                  <1> 	pop	ebx ; restore bh
  4394 0000D9FF 5F                  <1> 	pop	edi
  4395 0000DA00 5E                  <1> 	pop	esi
  4396                              <1> 	;jnc	short sysvideo_10
  4397 0000DA01 7215                <1> 	jc	short sysvideo_9_6 ; 28/01/2021
  4398                              <1> ;sysvideo_9_6:
  4399                              <1> ;	jmp	sysret ; [u.r0] = 0
  4400                              <1> 
  4401                              <1> sysvideo_10:
  4402                              <1> 	; user to system video/display page window transfer (mode 0)
  4403                              <1> 	; esi =	user buffer
  4404 0000DA03 E8D2350000          <1> 	call	transfer_from_user_buffer ; fast transfer
  4405                              <1> 	;jc	sysret
  4406 0000DA08 720E                <1> 	jc	short sysvideo_9_6 ; 28/01/2021
  4407                              <1> 	; ecx = actual transfer count (must be same with input)
  4408 0000DA0A 010D[74940100]      <1> 	add	[u.r0], ecx ; actual transfer count
  4409 0000DA10 01D7                <1> 	add	edi, edx ; next row address of (video page) window 
  4410 0000DA12 01CE                <1> 	add	esi, ecx ; next row address of user's window
  4411                              <1> 		; Note: ecx may be less than row length of video page
  4412                              <1> 		; user's window uses offset according to window width
  4413 0000DA14 FECF                <1> 	dec	bh
  4414 0000DA16 75EB                <1> 	jnz	short sysvideo_10 ; repeat for next row
  4415                              <1> 	;jmp	sysret
  4416                              <1> sysvideo_9_6:
  4417 0000DA18 E937F4FFFF          <1> 	jmp	sysret
  4418                              <1> 	
  4419                              <1> sysvideo_11:
  4420                              <1> 	; system to user video/display page window transfer (mode 0)
  4421 0000DA1D 87F7                <1> 	xchg	edi, esi
  4422                              <1> sysvideo_12:
  4423                              <1> 	; esi = beginning addr of the (screen, video page) window
  4424                              <1> 	; edi =	user's buffer	
  4425 0000DA1F E86C350000          <1> 	call	transfer_to_user_buffer ; fast transfer
  4426                              <1> 	;jc	sysret
  4427                              <1> 	; 23/07/2022
  4428 0000DA24 72F2                <1> 	jc	short sysvideo_9_6 ; jmp sysret	
  4429                              <1> 
  4430                              <1> 	; ecx = actual transfer count (must be same with input)
  4431 0000DA26 010D[74940100]      <1> 	add	[u.r0], ecx
  4432 0000DA2C 01D6                <1> 	add	esi, edx ; next row (edx = 160)
  4433 0000DA2E 01CF                <1> 	add	edi, ecx ; next row of the user's window
  4434                              <1> 			 ; (ecx <= 160)
  4435 0000DA30 FECF                <1> 	dec	bh
  4436 0000DA32 75EB                <1> 	jnz	short sysvideo_12
  4437                              <1> sysvideo_12_0:
  4438 0000DA34 E91BF4FFFF          <1> 	jmp	sysret
  4439                              <1> 
  4440                              <1> sysvideo_13:
  4441                              <1> 	; 28/12/2020
  4442 0000DA39 80FF01              <1> 	cmp	bh, 1
  4443 0000DA3C 7752                <1>         ja      short sysvideo_15 ; 23/11/2020
  4444                              <1> 
  4445                              <1> 	; 25/02/2021
  4446                              <1> 	; 12/02/2021
  4447                              <1> 	; 29/01/2021, 31/01/2021
  4448                              <1> 	; 23/11/2020 (TRDOS 386 v2.0.3)
  4449                              <1> 	; (major modification, from mode 13h to all VGA modes,
  4450                              <1> 	;  except super VGA modes and liner frame buffer method)
  4451                              <1> 
  4452                              <1> 	; BH = 1 = VGA Graphics mode (0A0000h) data transfers
  4453                              <1> 
  4454                              <1> 	; 29/01/2021
  4455 0000DA3E 66B84001            <1> 	mov	ax, 320	; 320 pixels
  4456 0000DA42 F6C380              <1> 	test	bl, 80h	; bit 7 (screen width, 640 pixels)
  4457 0000DA45 7407                <1> 	jz	short sysvideo_13_0
  4458                              <1> 	;shl	ax, 1	; 640 pixels
  4459                              <1> 	; 23/07/2022
  4460 0000DA47 D1E0                <1> 	shl	eax, 1
  4461                              <1> 	;
  4462 0000DA49 80E37F              <1> 	and	bl, 7Fh
  4463 0000DA4C 7405                <1> 	jz	short sysvideo_14
  4464                              <1> sysvideo_13_0:
  4465                              <1> 	; 29/01/2021
  4466 0000DA4E 80FB41              <1> 	cmp	bl, 41h
  4467 0000DA51 77E1                <1> 	ja	short sysvideo_12_0 ; invalid (unknown) sub function
  4468                              <1> sysvideo_14:
  4469 0000DA53 66A3[96A30100]      <1> 	mov	[v_width], ax	; save screen width
  4470 0000DA59 C705[9AA30100]0000- <1> 	mov	dword [v_mem], 0A0000h  ; save video memory address
  4470 0000DA61 0A00                <1>
  4471 0000DA63 C705[9EA30100]0000- <1> 	mov	dword [v_siz], 65536	; save video memory size
  4471 0000DA6B 0100                <1>
  4472 0000DA6D C705[A6A30100]0000- <1> 	mov	dword [v_end], 0B0000h	; save end of video page
  4472 0000DA75 0B00                <1>
  4473 0000DA77 B708                <1> 	mov	bh, 8
  4474 0000DA79 883D[99A30100]      <1> 	mov	[v_bpp], bh ; 8	; bits per pixel (256 colors)
  4475 0000DA7F 881D[98A30100]      <1> 	mov	[v_ops], bl	; VGA data transfer options
  4476                              <1> 	;mov	[maskbuff], edi ; 25/02/2021 
  4477 0000DA85 893D[AAA30100]      <1> 	mov	[maskcolor], edi ; 25/02/2021
  4478                              <1> 			; save mask color or bitmask buffer address
  4479 0000DA8B E9BE000000          <1> 	jmp	sysvideo_15_7
  4480                              <1> 
  4481                              <1> sysvideo_15:
  4482                              <1> 	; 23/07/2022
  4483                              <1> 	; 28/12/2020
  4484 0000DA90 80FF02              <1> 	cmp	bh, 2
  4485                              <1>         ;ja	sysvideo_16
  4486                              <1> 	; 23/07/2022
  4487 0000DA93 7605                <1> 	jna	short sysvideo_15_17
  4488 0000DA95 E9ED1E0000          <1> 	jmp	sysvideo_16
  4489                              <1> sysvideo_15_17:	; 23/07/2022
  4490                              <1> 	; 25/02/2021
  4491                              <1> 	; 12/02/2021
  4492                              <1> 	; 30/01/2021 - 31/01/2021
  4493                              <1> 	; 01/01/2021 - 29/01/2021
  4494                              <1> 	; 26/12/2020 - 27/12/2020
  4495                              <1> 	; 25/12/2020 (TRDOS 386 v2.0.3)
  4496                              <1> 	;
  4497                              <1> 	; BH = 2 = SVGA (VESA VBE) Graphics mode (LFB) data transfers
  4498                              <1> 
  4499                              <1> 	; 25/12/2020
  4500                              <1> 	; resolution table entry will be saved into EBP register
  4501                              <1> 
  4502 0000DA9A 803D[86090000]02    <1> 	cmp	byte [vbe3], 2 ; VESA VBE 3 video bios 
  4503                              <1> 			  ; or BOCHS/QEMU/VIRTUALBOX emu video bios
  4504 0000DAA1 724E                <1> 	jb	short sysvideo_15_4 ; no, nothing to do !
  4505 0000DAA3 770B                <1> 	ja	short sysvideo_15_0 ; yes
  4506                              <1> 
  4507                              <1> 	; Only Bochs/Plex86 (emu) vbe2 video bios is usable in pmid
  4508                              <1> 	; (if [vbe3] = 2) 
  4509 0000DAA5 A0[87090000]        <1> 	mov	al, [vbe2bios] ; Bochs vbios sign is from C0h to C5h
  4510 0000DAAA 24F0                <1> 	and	al, 0F0h
  4511 0000DAAC 3CC0                <1> 	cmp	al, 0C0h
  4512 0000DAAE 7541                <1> 	jne	short sysvideo_15_4 ; unknown (vbe2) video bios
  4513                              <1> sysvideo_15_0:
  4514                              <1> 	; 29/01/2021
  4515 0000DAB0 80FB41              <1> 	cmp	bl, 41h
  4516 0000DAB3 773C                <1> 	ja	short sysvideo_15_4 ; invalid (unknown) sub function
  4517                              <1> 	; 29/01/2021
  4518 0000DAB5 881D[98A30100]      <1> 	mov	[v_ops], bl	; SVGA data transfer options
  4519                              <1> 
  4520 0000DABB 89D8                <1> 	mov	eax, ebx ; hw of ebx is vesa vbe video mode
  4521 0000DABD C1E810              <1> 	shr	eax, 16 ; ax = vesa vbe video mode
  4522 0000DAC0 7513                <1> 	jnz	short sysvideo_15_2 
  4523                              <1> 	; ax = 0
  4524                              <1> 
  4525                              <1> 	; check & use current video mode
  4526 0000DAC2 803D[DE670000]FF    <1> 	cmp	byte [CRT_MODE], 0FFh ; extended (SVGA) mode ?
  4527 0000DAC9 7526                <1> 	jne	short sysvideo_15_4 ; no
  4528                              <1> sysvideo_15_1:
  4529                              <1> 	; use current vbe (svga) video mode
  4530 0000DACB 66A1[2EA30100]      <1> 	mov	ax, [video_mode] ; extended (SVGA, VESA VBE) mode
  4531 0000DAD1 6625FF01            <1> 	and	ax, 1FFh ; vesa vbe video mode: 1XXh
  4532                              <1> sysvideo_15_2:
  4533                              <1> 	; 29/01/2021
  4534                              <1> 	;mov	[maskbuff], edi ; 25/02/2021
  4535 0000DAD5 893D[AAA30100]      <1> 	mov	[maskcolor], edi ; 25/02/2021
  4536                              <1> 			; save mask color or bitmask buffer address
  4537 0000DADB BD[6A6B0000]        <1> 	mov	ebp, b_vbe_modes ; vbe mode table (in 'vidata.s')
  4538                              <1> sysvideo_15_3:
  4539 0000DAE0 663B4500            <1> 	cmp	ax, [ebp]
  4540 0000DAE4 7410                <1> 	je	short sysvideo_15_5
  4541 0000DAE6 83C508              <1> 	add	ebp, 8 ; vbe mode table entry size
  4542 0000DAE9 81FD[2A6C0000]      <1> 	cmp	ebp, end_of_b_vbe_modes
  4543 0000DAEF 72EF                <1>  	jb	short sysvideo_15_3
  4544                              <1> sysvideo_15_4:
  4545                              <1> 	; desired video mode is not a valid (implemented)
  4546                              <1> 	;	  extended (VESA VBE, SVGA) video mode
  4547                              <1> 	;
  4548                              <1> 	; nothing to do !
  4549                              <1> 
  4550                              <1>  	; [u.r0] = 0  ; return value of EAX
  4551 0000DAF1 E95EF3FFFF          <1>  	jmp	sysret
  4552                              <1> 
  4553                              <1> sysvideo_15_5:
  4554                              <1> 	; get LFB address
  4555 0000DAF6 A1[3CA30100]        <1> 	mov	eax, [LFB_ADDR] ; [LFB_Info+LFBINFO.LFB_addr]
  4556 0000DAFB 09C0                <1> 	or	eax, eax
  4557 0000DAFD 7509                <1> 	jnz	short sysvideo_15_6
  4558 0000DAFF 66A1[1A0F0000]      <1> 	mov	ax, [def_LFB_addr] ; default LFB addr 
  4559                              <1> 				   ; (for vbe mode 118h)
  4560 0000DB05 C1E010              <1> 	shl	eax, 16
  4561                              <1> 	; 27/12/2020
  4562                              <1> 	;jz	short sysvideo_15_4
  4563                              <1> sysvideo_15_6:
  4564                              <1> 	; 29/01/2021
  4565 0000DB08 A3[9AA30100]        <1> 	mov	[v_mem], eax ; save video memory address
  4566                              <1> 	
  4567                              <1> 	; 27/12/2020
  4568                              <1> 	; 26/12/2020
  4569 0000DB0D 8B4502              <1> 	mov	eax, [ebp+2] ; width, height
  4570                              <1> 	; 29/01/2021
  4571 0000DB10 66A3[96A30100]      <1> 	mov	[v_width], ax ; save screen width
  4572                              <1> 	; 28/12/2020
  4573 0000DB16 8A7D06              <1> 	mov	bh, [ebp+6] ; bpp
  4574                              <1> 	; 28/02/2021
  4575                              <1> 	; check default truecolor bpp value and use
  4576                              <1> 	; 32bpp instead of 24bpp if the default value
  4577                              <1> 	; has been set to 32bpp.
  4578 0000DB19 80FF18              <1> 	cmp	bh, 24
  4579 0000DB1C 750B                <1> 	jne	short sysvideo_15_16
  4580 0000DB1E 803D[87790100]20    <1> 	cmp	byte [truecolor], 32
  4581                              <1> 		; Default truecolor bpp value,
  4582                              <1> 		; it is 32 for VBE3 video bios
  4583                              <1> 		; (it can be set to 32 or 24)
  4584 0000DB25 7502                <1> 	jne	short sysvideo_15_16 ; not VBE3 !
  4585                              <1> 				; or it is set to 24
  4586 0000DB27 B720                <1> 	mov	bh, 32
  4587                              <1> 	; 28/02/2021
  4588                              <1> sysvideo_15_16:
  4589                              <1> 	; 29/01/2021
  4590 0000DB29 883D[99A30100]      <1> 	mov	[v_bpp], bh ; bits per pixel
  4591                              <1> 
  4592 0000DB2F 52                  <1> 	push	edx ; *
  4593 0000DB30 0FB7D0              <1> 	movzx	edx, ax  ; width
  4594 0000DB33 C1E810              <1> 	shr	eax, 16  ; height
  4595 0000DB36 F7E2                <1> 	mul	edx
  4596                              <1> 	; eax = linear frame buffer size (pixels)
  4597                              <1> 	; 29/01/2021
  4598 0000DB38 A3[9EA30100]        <1> 	mov	[v_siz], eax ; save video page size
  4599 0000DB3D E8FD000000          <1> 	call	pixels_to_byte_count
  4600 0000DB42 0305[9AA30100]      <1> 	add	eax, [v_mem]
  4601 0000DB48 A3[A6A30100]        <1> 	mov	[v_end], eax ; save end of video page 
  4602 0000DB4D 5A                  <1> 	pop	edx ; *
  4603                              <1> 
  4604                              <1> 	; bh = bits per pixel
  4605                              <1> 	; (bh will not be used after here, 29/01/2021)
  4606                              <1> 
  4607                              <1> 	; bl = pixel operations & options
  4608                              <1> 	; ecx, edx, esi, edi input parameters
  4609                              <1> 	; [maskcolor] = edi input ; 25/02/2021
  4610                              <1> 
  4611                              <1> sysvideo_15_7:
  4612                              <1> 	; 29/01/2021
  4613                              <1> 	;test	byte [v_ops], 40h  ; system to user ?
  4614 0000DB4E F6C340              <1> 	test	bl, 40h
  4615 0000DB51 7517                <1> 	jnz	short sysvideo_15_9
  4616                              <1> 
  4617 0000DB53 31C0                <1> 	xor	eax, eax
  4618 0000DB55 88D8                <1> 	mov	al, bl
  4619 0000DB57 BB[7DDC0000]        <1> 	mov	ebx, pixel_ops
  4620 0000DB5C 240F                <1> 	and	al, 0Fh ; isolate 16 pixel operations
  4621 0000DB5E C0E002              <1> 	shl	al, 2 ; * 4 for dword table pointers 
  4622 0000DB61 01C3                <1> 	add	ebx, eax
  4623                              <1> 
  4624                              <1> 	; ebx = subroutine address
  4625                              <1> 
  4626                              <1> 	; ecx, edx, esi, edi input parameters
  4627                              <1> 	; [maskbuff] = edi input
  4628                              <1> 	; [maskcolor] = edi input ; 25/02/2021
  4629                              <1> 
  4630 0000DB63 FF13                <1> 	call	[ebx]
  4631                              <1> sysvideo_15_8:
  4632 0000DB65 E9EAF2FFFF          <1> 	jmp	sysret
  4633                              <1> 
  4634                              <1> sysvideo_15_9:
  4635                              <1> 	; system to user display page or window copy
  4636                              <1> 	;test	byte [v_ops], 1 ; window copy ?
  4637 0000DB6A F6C301              <1> 	test	bl, 1	
  4638 0000DB6D 7521                <1> 	jnz	short sysvideo_15_10
  4639                              <1> 
  4640                              <1> 	; display page (full screen copy)
  4641 0000DB6F 8B35[9AA30100]      <1> 	mov	esi, [v_mem] ; LFB start address
  4642 0000DB75 A1[9EA30100]        <1> 	mov	eax, [v_siz]
  4643 0000DB7A E8C0000000          <1> 	call	pixels_to_byte_count
  4644 0000DB7F 89C1                <1> 	mov	ecx, eax ; transfer count in bytes
  4645                              <1> 	;edi = user's buffer address
  4646 0000DB81 E80A340000          <1> 	call	transfer_to_user_buffer
  4647 0000DB86 72DD                <1> 	jc	short sysvideo_15_8
  4648 0000DB88 890D[74940100]      <1> 	mov	[u.r0], ecx
  4649 0000DB8E EBD5                <1> 	jmp	short sysvideo_15_8
  4650                              <1> 
  4651                              <1> sysvideo_15_10:
  4652 0000DB90 E820000000          <1> 	call	sysvideo_15_12 ; window preparations
  4653 0000DB95 72CE                <1> 	jc	short sysvideo_15_8
  4654                              <1> 
  4655 0000DB97 8B35[A2A30100]      <1> 	mov	esi, [v_str]
  4656                              <1> sysvideo_15_11:
  4657                              <1> 	; esi = window's current row address (video mem)
  4658                              <1> 	; edi = current row (virtual) addr in user's buff
  4659                              <1> 	; ecx = transfer count per row
  4660 0000DB9D E8EE330000          <1> 	call	transfer_to_user_buffer
  4661 0000DBA2 72C1                <1> 	jc	short sysvideo_15_8
  4662 0000DBA4 010D[74940100]      <1>  	add	[u.r0], ecx
  4663 0000DBAA 4B                  <1> 	dec	ebx
  4664 0000DBAB 74B8                <1> 	jz	short sysvideo_15_8 ; ok.
  4665                              <1> 	; next row
  4666 0000DBAD 01CF                <1> 	add	edi, ecx ; next row in user's buffer
  4667 0000DBAF 01D6                <1> 	add	esi, edx ; next row of window (system)
  4668 0000DBB1 EBEA                <1> 	jmp	short sysvideo_15_11
  4669                              <1> 
  4670                              <1> sysvideo_15_14:
  4671 0000DBB3 F9                  <1> 	stc	 ; error !
  4672                              <1> sysvideo_15_15:
  4673 0000DBB4 C3                  <1> 	retn
  4674                              <1> 
  4675                              <1> sysvideo_15_12:
  4676                              <1> 	; 30/01/2021
  4677                              <1> 	; 29/01/2021
  4678                              <1> 	; Window address preparations for window copy
  4679 0000DBB5 6621D2              <1> 	and	dx, dx
  4680 0000DBB8 74F9                <1> 	jz	short sysvideo_15_14 ; invalid (zero columns)
  4681                              <1> 	;test	edx, 0FFFF0000h
  4682                              <1> 	;jz	short sysvideo_15_14 ; invalid (zero rows)
  4683 0000DBBA 81FA00000100        <1> 	cmp	edx, 65536
  4684 0000DBC0 72F2                <1> 	jb	short sysvideo_15_15 ; invalid (zero rows)
  4685 0000DBC2 89C8                <1> 	mov	eax, ecx ; start position (row, column)
  4686 0000DBC4 E899000000          <1> 	call	calc_pixel_offset
  4687 0000DBC9 3B05[9EA30100]      <1> 	cmp	eax, [v_siz]
  4688 0000DBCF 73E2                <1> 	jnb	short sysvideo_15_14 ; out of display page
  4689                              <1> 				; nothing to do
  4690 0000DBD1 E869000000          <1> 	call	pixels_to_byte_count
  4691 0000DBD6 0305[9AA30100]      <1> 	add	eax, [v_mem]
  4692 0000DBDC A3[A2A30100]        <1> 	mov	[v_str], eax ; window start address
  4693                              <1> 			     ; (addr of top left corner)
  4694                              <1> 	; check column limit
  4695 0000DBE1 89C8                <1> 	mov	eax, ecx
  4696 0000DBE3 6601D0              <1> 	add	ax, dx  ; add columns to start column
  4697 0000DBE6 72CC                <1> 	jc	short sysvideo_15_15 ; cf = 1
  4698 0000DBE8 663B05[96A30100]    <1> 	cmp	ax, [v_width]
  4699 0000DBEF 77C2                <1> 	ja	short sysvideo_15_14
  4700                              <1> 
  4701 0000DBF1 89D0                <1> 	mov	eax, edx ; size
  4702 0000DBF3 2D00000100          <1> 	sub	eax, 65536 ; row count -> 0 based row #
  4703 0000DBF8 E865000000          <1> 	call	calc_pixel_offset
  4704 0000DBFD 3B05[9EA30100]      <1> 	cmp	eax, [v_siz] ; video (display) page size
  4705 0000DC03 77AE                <1> 	ja	short sysvideo_15_14 ; out of display page
  4706                              <1> 				; nothing to do
  4707 0000DC05 E835000000          <1> 	call	pixels_to_byte_count
  4708 0000DC0A 0305[A2A30100]      <1> 	add	eax, [v_str] ; window start address
  4709 0000DC10 3B05[A6A30100]      <1> 	cmp	eax, [v_end] ; window end address (+1)
  4710                              <1> 			 ; (addr of bottom right corner +1)
  4711 0000DC16 779B                <1> 	ja	short sysvideo_15_14 ; out of display page
  4712                              <1> 				; nothing to do
  4713 0000DC18 89D3                <1> 	mov	ebx, edx
  4714 0000DC1A C1EB10              <1> 	shr	ebx, 16
  4715                              <1> 	; ebx = row count
  4716 0000DC1D 81E2FFFF0000        <1> 	and	edx, 0FFFFh
  4717                              <1> 	; edx = transfer count per row (from user's buffer)
  4718                              <1> 	;	(in pixels, window width)
  4719 0000DC23 89D0                <1> 	mov	eax, edx
  4720 0000DC25 A3[AEA30100]        <1> 	mov	[pixcount], eax ; 27/02/2021
  4721 0000DC2A E810000000          <1> 	call	pixels_to_byte_count
  4722 0000DC2F 89C1                <1> 	mov	ecx, eax
  4723                              <1> 	; ecx = transfer count per row (from user's buffer)
  4724                              <1> 	;	(in bytes, window width)
  4725 0000DC31 66A1[96A30100]      <1> 	mov	ax, [v_width]
  4726 0000DC37 E803000000          <1> 	call	pixels_to_byte_count
  4727 0000DC3C 89C2                <1> 	mov	edx, eax
  4728                              <1> 	; edx = byte count per row
  4729 0000DC3E C3                  <1> 	retn ; cf = 0
  4730                              <1> 
  4731                              <1> pixels_to_byte_count:
  4732                              <1> 	; 29/01/2021
  4733                              <1> 	; INPUT:
  4734                              <1> 	;   eax = pixel count
  4735                              <1> 	; OUTPUT:
  4736                              <1> 	;   eax = byte count
  4737                              <1> 	;
  4738 0000DC3F 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8
  4739 0000DC46 7619                <1> 	jna	short pixtobc_3 ; 8 bit colors
  4740 0000DC48 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24
  4741 0000DC4F 720A                <1> 	jb	short pixtobc_1 ; 16 bit colors
  4742 0000DC51 770B                <1> 	ja	short pixtobc_2 ; 32 bit colors
  4743                              <1> 	; 24 bit pixels
  4744                              <1> 	; eax = eax * 3
  4745                              <1> 	;push	edx
  4746                              <1> 	;mov	edx, eax
  4747                              <1> 	;shl	eax, 1
  4748                              <1> 	;add	eax, edx
  4749                              <1> 	;pop	edx
  4750 0000DC53 50                  <1> 	push	eax
  4751 0000DC54 D1E0                <1> 	shl	eax, 1
  4752 0000DC56 010424              <1> 	add	[esp], eax
  4753 0000DC59 58                  <1> 	pop	eax
  4754 0000DC5A C3                  <1> 	retn
  4755                              <1> pixtobc_1:
  4756                              <1> 	; 32 bit pixels
  4757                              <1> 	; eax = eax * 2
  4758 0000DC5B D1E0                <1> 	shl	eax, 1
  4759 0000DC5D C3                  <1> 	retn
  4760                              <1> pixtobc_2:
  4761                              <1> 	; 16 bit pixels
  4762                              <1> 	; eax = eax * 4
  4763 0000DC5E C1E002              <1> 	shl	eax, 2
  4764                              <1> pixtobc_3:
  4765 0000DC61 C3                  <1> 	retn
  4766                              <1> 
  4767                              <1> calc_pixel_offset:
  4768                              <1> 	; 29/01/2021
  4769                              <1> 	; INPUT:
  4770                              <1> 	;   eax = pixel position (row, column)
  4771                              <1> 	; OUTPUT:
  4772                              <1> 	;   eax = pixel offset (linear address)
  4773                              <1> 	;
  4774 0000DC62 52                  <1> 	push	edx
  4775 0000DC63 50                  <1> 	push	eax
  4776 0000DC64 C1E810              <1> 	shr	eax, 16
  4777 0000DC67 7409                <1> 	jz	short cpixo_0
  4778                              <1> 	; eax = row 
  4779 0000DC69 0FB715[96A30100]    <1> 	movzx	edx, word [v_width]
  4780 0000DC70 F7E2                <1> 	mul	edx
  4781                              <1> cpixo_0:
  4782                              <1> 	; eax = row * screen width
  4783 0000DC72 5A                  <1> 	pop	edx
  4784 0000DC73 81E2FFFF0000        <1> 	and	edx, 0FFFFh
  4785                              <1> 	; edx = column
  4786 0000DC79 01D0                <1> 	add	eax, edx
  4787                              <1> 	; eax = (row * screen width) + column
  4788 0000DC7B 5A                  <1> 	pop	edx
  4789 0000DC7C C3                  <1> 	retn
  4790                              <1> 
  4791                              <1> 	; 02/02/2021
  4792                              <1> 	; 29/01/2021
  4793                              <1> pixel_ops:
  4794 0000DC7D [BDDC0000]          <1> 	dd	pix_op_cpy ; copy pixels (user to system)
  4795 0000DC81 [08E20000]          <1> 	dd	pix_op_new ; change (new, fill) color
  4796 0000DC85 [25DD0000]          <1> 	dd	pix_op_add ; add color (up to 0FFh)
  4797 0000DC89 [D7DD0000]          <1> 	dd	pix_op_sub ; sub color (down to 0)
  4798 0000DC8D [F2DF0000]          <1> 	dd	pix_op_orc ; or color
  4799 0000DC91 [A4E00000]          <1> 	dd	pix_op_and ; and color
  4800 0000DC95 [56E10000]          <1> 	dd	pix_op_xor ; xor color
  4801 0000DC99 [CCE20000]          <1> 	dd	pix_op_not ; not color
  4802 0000DC9D [76E30000]          <1> 	dd	pix_op_neg ; neg color
  4803 0000DCA1 [20E40000]          <1> 	dd	pix_op_inc ; inc color
  4804 0000DCA5 [CAE40000]          <1> 	dd	pix_op_dec ; dec color
  4805 0000DCA9 [89DE0000]          <1> 	dd	pix_op_mix ; mix color
  4806 0000DCAD [50DF0000]          <1> 	dd	pix_op_rpl ; replace color
  4807 0000DCB1 [74E50000]          <1> 	dd	pix_op_blk ; copy pixel block(s) (sys)
  4808 0000DCB5 [22E60000]          <1> 	dd	pix_op_lin ; write line(s)
  4809 0000DCB9 [05EA0000]          <1> 	dd	pix_op_chr ; write character (font)
  4810                              <1> 
  4811                              <1> pix_op_cpy:
  4812                              <1> 	; 21/02/2021
  4813                              <1> 	; 06/02/2021
  4814                              <1> 	; 30/01/2021
  4815                              <1> 	; COPY PIXELS
  4816                              <1> 	;
  4817                              <1> 	; INPUT:
  4818                              <1> 	;  If bit 4 of BL or [v_ops] = 1 -window copy-
  4819                              <1> 	;  ECX = start position (row, column)
  4820                              <1> 	;        (HW = row, CX = column)
  4821                              <1> 	;  EDX = size (rows, colums)
  4822                              <1> 	;        (HW = rows, DX = columns)
  4823                              <1> 	;	 (0 -> invalid 	
  4824                              <1> 	;        (1 -> horizontal or vertical line)
  4825                              <1> 	;  If bit 4 of BL or [v_ops] = 0 -full screen-
  4826                              <1> 	;     ECX and EDX will not be used
  4827                              <1>   	;  ESI = user's buffer address
  4828                              <1> 	;  [maskcolor] = mask color (to be excluded)
  4829                              <1> 	;
  4830                              <1> 	; OUTPUT:
  4831                              <1> 	; 	[u.r0] will be > 0 if succesful
  4832                              <1> 
  4833 0000DCBD F605[98A30100]10    <1> 	test	byte [v_ops], 10h ; display page or window ?
  4834 0000DCC4 752E                <1> 	jnz	short pix_op_cpy_w ; window
  4835                              <1> 
  4836 0000DCC6 8B3D[9AA30100]      <1> 	mov	edi, [v_mem] ; 21/02/2021
  4837                              <1> 	
  4838                              <1> 	; Copy user's buffer content do display page
  4839                              <1> 	; (full screen copy)
  4840 0000DCCC A1[9EA30100]        <1> 	mov	eax, [v_siz] ; video page size
  4841 0000DCD1 E869FFFFFF          <1> 	call	pixels_to_byte_count
  4842 0000DCD6 89C1                <1> 	mov	ecx, eax ; transfer count
  4843                              <1> 	; esi = user's buffer address (virtual)
  4844 0000DCD8 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked copy ?
  4845 0000DCDF 7405                <1> 	jz	short pix_op_cpy_0 ; no	
  4846 0000DCE1 E96F0F0000          <1> 	jmp	m_pix_op_cpy ; copy pixels except mask color
  4847                              <1> pix_op_cpy_0:
  4848                              <1> 	; esi = user buffer for full screen copy
  4849                              <1> 	; edi = start of video memory 
  4850                              <1> 	;	(start of display page)
  4851                              <1> 	; ecx = byte count (display page size in bytes)
  4852 0000DCE6 E8EF320000          <1> 	call	transfer_from_user_buffer
  4853 0000DCEB 7206                <1> 	jc	short pix_op_cpy_1
  4854 0000DCED 890D[74940100]      <1> 	mov	[u.r0], ecx
  4855                              <1> pix_op_cpy_1:
  4856 0000DCF3 C3                  <1> 	retn	; 06/02/2021
  4857                              <1> 
  4858                              <1> pix_op_cpy_w:
  4859 0000DCF4 E8BCFEFFFF          <1> 	call	sysvideo_15_12 ; window preparations
  4860 0000DCF9 72F8                <1> 	jc	short pix_op_cpy_1
  4861                              <1> 	; ecx = bytes per row (to be applied)
  4862                              <1> 	; edx = screen width in bytes
  4863                              <1> 	; ebx = row count
  4864 0000DCFB 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  4865 0000DD01 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked copy ?
  4866 0000DD08 7405                <1> 	jz	short pix_op_cpy_w_0 ; no
  4867 0000DD0A E909100000          <1> 	jmp	m_pix_op_cpy_w ; window copy except mask color
  4868                              <1> pix_op_cpy_w_0:
  4869                              <1> 	; esi = current row (virtual) addr in user's buff
  4870                              <1> 	; edi = window's current row address (video mem)
  4871                              <1> 	; ecx = transfer count per row
  4872 0000DD0F E8C6320000          <1> 	call	transfer_from_user_buffer
  4873 0000DD14 72DD                <1> 	jc	short pix_op_cpy_1
  4874 0000DD16 010D[74940100]      <1>  	add	[u.r0], ecx
  4875 0000DD1C 4B                  <1> 	dec	ebx
  4876 0000DD1D 74D4                <1> 	jz	short pix_op_cpy_1 ; ok.
  4877                              <1> 	; next row
  4878 0000DD1F 01CE                <1> 	add	esi, ecx ; next row in user's buffer
  4879 0000DD21 01D7                <1> 	add	edi, edx ; next row of window (system)
  4880 0000DD23 EBEA                <1> 	jmp	short pix_op_cpy_w_0
  4881                              <1> 
  4882                              <1> pix_op_add:
  4883                              <1> 	; 31/01/2021
  4884                              <1> 	; 30/01/2021
  4885                              <1> 	; ADD COLOR
  4886                              <1> 	;
  4887                              <1> 	; INPUT:
  4888                              <1> 	;   CL = color (8 bit, 256 colors)
  4889                              <1> 	;  ECX = color (16 bit and true colors)
  4890                              <1> 	;  EDX = start position (row, column)
  4891                              <1> 	;        (HW = row, DX = column)
  4892                              <1> 	;  ESI = size (rows, colums)
  4893                              <1> 	;        (HW = rows, SI = columns)
  4894                              <1> 	;
  4895                              <1> 	;  [maskcolor] = mask color (to be excluded)
  4896                              <1> 	;
  4897                              <1> 	; OUTPUT:
  4898                              <1> 	; 	[u.r0] will be > 0 if succesful
  4899                              <1> 
  4900 0000DD25 F605[98A30100]10    <1> 	test	byte [v_ops], 10h ; display page or window ?
  4901 0000DD2C 7555                <1> 	jnz	short pix_op_add_w ; window
  4902                              <1> 
  4903 0000DD2E 8B3D[9AA30100]      <1> 	mov	edi, [v_mem]
  4904 0000DD34 89FE                <1> 	mov	esi, edi
  4905                              <1> 	; ecx = color (CL, CX, ECX)
  4906 0000DD36 89C8                <1> 	mov	eax, ecx
  4907 0000DD38 8B0D[9EA30100]      <1> 	mov	ecx, [v_siz] ; display page pixel count
  4908                              <1> 
  4909 0000DD3E F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color adding ?
  4910 0000DD45 7405                <1> 	jz	short pix_op_add_0 ; no
  4911 0000DD47 E9CB100000          <1> 	jmp	m_pix_op_add ; add color except mask color
  4912                              <1> pix_op_add_0:
  4913 0000DD4C 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  4914 0000DD53 7707                <1> 	ja	short pix_op_add_1
  4915                              <1> 
  4916                              <1> 	; 256 colors (8bpp)
  4917 0000DD55 E84C0A0000          <1> 	call	pix_op_add_8
  4918 0000DD5A EB1E                <1> 	jmp	short pix_op_add_4
  4919                              <1> 
  4920                              <1> pix_op_add_1:
  4921 0000DD5C 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  4922 0000DD63 7710                <1> 	ja	short pix_op_add_3 ; 32bpp
  4923 0000DD65 7207                <1> 	jb	short pix_op_add_2 ; 16bpp
  4924                              <1> 
  4925                              <1> 	; 24 bit true colors
  4926 0000DD67 E85A0A0000          <1> 	call	pix_op_add_24
  4927 0000DD6C EB0C                <1> 	jmp	short pix_op_add_4
  4928                              <1> 
  4929                              <1> 	; 65536 colors (16bpp)
  4930                              <1> pix_op_add_2:
  4931 0000DD6E E8410A0000          <1> 	call	pix_op_add_16
  4932 0000DD73 EB05                <1> 	jmp	short pix_op_add_4
  4933                              <1> 
  4934                              <1> 	; 32 bit true colors
  4935                              <1> pix_op_add_3:
  4936 0000DD75 E86C0A0000          <1> 	call	pix_op_add_32
  4937                              <1> pix_op_add_4:
  4938 0000DD7A 29F7                <1> 	sub	edi, esi
  4939 0000DD7C 893D[74940100]      <1> 	mov	[u.r0], edi
  4940                              <1> pix_op_add_5:
  4941 0000DD82 C3                  <1> 	retn
  4942                              <1> 
  4943                              <1> pix_op_add_w:
  4944                              <1> 	; 31/01/2021
  4945 0000DD83 51                  <1> 	push	ecx ; * ; color
  4946 0000DD84 89D1                <1> 	mov	ecx, edx ; win start pos
  4947 0000DD86 89F2                <1> 	mov	edx, esi ; size (rows, cols)
  4948 0000DD88 E828FEFFFF          <1> 	call	sysvideo_15_12 ; window preparations
  4949 0000DD8D 58                  <1> 	pop	eax ; * ; color
  4950 0000DD8E 72F2                <1> 	jc	short pix_op_add_5
  4951                              <1> 
  4952 0000DD90 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color adding ?
  4953 0000DD97 7405                <1> 	jz	short pix_op_add_w_0 ; no
  4954 0000DD99 E927110000          <1> 	jmp	m_pix_op_add_w
  4955                              <1> 			; window add color except mask color
  4956                              <1> pix_op_add_w_0:
  4957                              <1> 	; ecx = bytes per row (to be applied)
  4958                              <1> 	; edx = screen width in bytes
  4959                              <1> 	; ebx = row count
  4960                              <1> 	; eax = color
  4961                              <1> 
  4962 0000DD9E 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  4963 0000DDA4 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  4964 0000DDAB 7707                <1> 	ja	short pix_op_add_w_1
  4965                              <1> 
  4966                              <1> 	; 256 colors (8bpp)
  4967 0000DDAD BD[A6E70000]        <1> 	mov	ebp, pix_op_add_8
  4968 0000DDB2 EB1E                <1> 	jmp	short pix_op_add_w_4
  4969                              <1> 
  4970                              <1> pix_op_add_w_1:
  4971 0000DDB4 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  4972 0000DDBB 7710                <1> 	ja	short pix_op_add_w_3 ; 32bpp
  4973 0000DDBD 7207                <1> 	jb	short pix_op_add_w_2 ; 16bpp
  4974                              <1> 
  4975                              <1> 	; 24 bit true colors
  4976 0000DDBF BD[C6E70000]        <1> 	mov	ebp, pix_op_add_24
  4977 0000DDC4 EB0C                <1> 	jmp	short pix_op_add_w_4
  4978                              <1> 
  4979                              <1> 	; 65536 colors (16bpp)
  4980                              <1> pix_op_add_w_2:
  4981 0000DDC6 BD[B4E70000]        <1> 	mov	ebp, pix_op_add_16
  4982 0000DDCB EB05                <1> 	jmp	short pix_op_add_w_4
  4983                              <1> 
  4984                              <1> 	; 32 bit true colors
  4985                              <1> pix_op_add_w_3:
  4986 0000DDCD BD[E6E70000]        <1> 	mov	ebp, pix_op_add_32
  4987                              <1> pix_op_add_w_4:
  4988 0000DDD2 E95F010000          <1> 	jmp	pix_op_add_w_x
  4989                              <1> 
  4990                              <1> pix_op_sub:
  4991                              <1> 	; 31/01/2021
  4992                              <1> 	; SUB COLOR
  4993                              <1> 	;
  4994                              <1> 	; INPUT:
  4995                              <1> 	;   CL = color (8 bit, 256 colors)
  4996                              <1> 	;  ECX = color (16 bit and true colors)
  4997                              <1> 	;  EDX = start position (row, column)
  4998                              <1> 	;        (HW = row, DX = column)
  4999                              <1> 	;  ESI = size (rows, colums)
  5000                              <1> 	;        (HW = rows, SI = columns)
  5001                              <1> 	;
  5002                              <1> 	;  [maskcolor] = mask color (to be excluded)
  5003                              <1> 	;
  5004                              <1> 	; OUTPUT:
  5005                              <1> 	; 	[u.r0] will be > 0 if succesful
  5006                              <1> 
  5007 0000DDD7 F605[98A30100]10    <1> 	test	byte [v_ops], 10h ; display page or window ?
  5008 0000DDDE 7555                <1> 	jnz	short pix_op_sub_w ; window
  5009                              <1> 
  5010 0000DDE0 8B3D[9AA30100]      <1> 	mov	edi, [v_mem]
  5011 0000DDE6 89FE                <1> 	mov	esi, edi
  5012                              <1> 	; ecx = color (CL, CX, ECX)
  5013 0000DDE8 89C8                <1> 	mov	eax, ecx
  5014 0000DDEA 8B0D[9EA30100]      <1> 	mov	ecx, [v_siz] ; display page pixel count
  5015                              <1> 
  5016 0000DDF0 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color subtract ?
  5017 0000DDF7 7405                <1> 	jz	short pix_op_sub_0 ; no
  5018 0000DDF9 E9FA100000          <1> 	jmp	m_pix_op_sub ; sub color except mask color
  5019                              <1> pix_op_sub_0:
  5020 0000DDFE 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5021 0000DE05 7707                <1> 	ja	short pix_op_sub_1
  5022                              <1> 
  5023                              <1> 	; 256 colors (8bpp)
  5024 0000DE07 E8E9090000          <1> 	call	pix_op_sub_8
  5025 0000DE0C EB1E                <1> 	jmp	short pix_op_sub_4
  5026                              <1> 
  5027                              <1> pix_op_sub_1:
  5028 0000DE0E 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5029 0000DE15 7710                <1> 	ja	short pix_op_sub_3 ; 32bpp
  5030 0000DE17 7207                <1> 	jb	short pix_op_sub_2 ; 16bpp
  5031                              <1> 
  5032                              <1> 	; 24 bit true colors
  5033 0000DE19 E8FA090000          <1> 	call	pix_op_sub_24
  5034 0000DE1E EB0C                <1> 	jmp	short pix_op_sub_4
  5035                              <1> 
  5036                              <1> 	; 65536 colors (16bpp)
  5037                              <1> pix_op_sub_2:
  5038 0000DE20 E8E0090000          <1> 	call	pix_op_sub_16
  5039 0000DE25 EB05                <1> 	jmp	short pix_op_sub_4
  5040                              <1> 
  5041                              <1> 	; 32 bit true colors
  5042                              <1> pix_op_sub_3:
  5043 0000DE27 E8060A0000          <1> 	call	pix_op_sub_32
  5044                              <1> pix_op_sub_4:
  5045 0000DE2C 29F7                <1> 	sub	edi, esi
  5046 0000DE2E 893D[74940100]      <1> 	mov	[u.r0], edi
  5047                              <1> pix_op_sub_5:
  5048 0000DE34 C3                  <1> 	retn
  5049                              <1> 
  5050                              <1> pix_op_sub_w:
  5051                              <1> 	; 31/01/2021
  5052 0000DE35 51                  <1> 	push	ecx ; * ; color
  5053 0000DE36 89D1                <1> 	mov	ecx, edx ; win start pos
  5054 0000DE38 89F2                <1> 	mov	edx, esi ; size (rows, cols)
  5055 0000DE3A E876FDFFFF          <1> 	call	sysvideo_15_12 ; window preparations
  5056 0000DE3F 58                  <1> 	pop	eax ; * ; color
  5057 0000DE40 72F2                <1> 	jc	short pix_op_sub_5
  5058                              <1> 
  5059 0000DE42 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color subtract ?
  5060 0000DE49 7405                <1> 	jz	short pix_op_sub_w_0 ; no
  5061 0000DE4B E94B110000          <1> 	jmp	m_pix_op_sub_w 
  5062                              <1> 			; window sub color except mask color
  5063                              <1> pix_op_sub_w_0:
  5064                              <1> 	; ecx = bytes per row (to be applied)
  5065                              <1> 	; edx = screen width in bytes
  5066                              <1> 	; ebx = row count
  5067                              <1> 	; eax = color
  5068                              <1> 
  5069 0000DE50 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  5070 0000DE56 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5071 0000DE5D 7707                <1> 	ja	short pix_op_sub_w_1
  5072                              <1> 
  5073                              <1> 	; 256 colors (8bpp)
  5074 0000DE5F BD[F5E70000]        <1> 	mov	ebp, pix_op_sub_8
  5075 0000DE64 EB1E                <1> 	jmp	short pix_op_sub_w_4
  5076                              <1> 
  5077                              <1> pix_op_sub_w_1:
  5078 0000DE66 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5079 0000DE6D 7710                <1> 	ja	short pix_op_sub_w_3 ; 32bpp
  5080 0000DE6F 7207                <1> 	jb	short pix_op_sub_w_2 ; 16bpp
  5081                              <1> 
  5082                              <1> 	; 24 bit true colors
  5083 0000DE71 BD[18E80000]        <1> 	mov	ebp, pix_op_sub_24
  5084 0000DE76 EB0C                <1> 	jmp	short pix_op_sub_w_4
  5085                              <1> 
  5086                              <1> 	; 65536 colors (16bpp)
  5087                              <1> pix_op_sub_w_2:
  5088 0000DE78 BD[05E80000]        <1> 	mov	ebp, pix_op_sub_16
  5089 0000DE7D EB05                <1> 	jmp	short pix_op_sub_w_4
  5090                              <1> 
  5091                              <1> 	; 32 bit true colors
  5092                              <1> pix_op_sub_w_3:
  5093 0000DE7F BD[32E80000]        <1> 	mov	ebp, pix_op_sub_32
  5094                              <1> pix_op_sub_w_4:
  5095 0000DE84 E9AD000000          <1> 	jmp	pix_op_sub_w_x
  5096                              <1> 
  5097                              <1> pix_op_mix:
  5098                              <1> 	; 31/01/2021
  5099                              <1> 	; MIX COLOR
  5100                              <1> 	;
  5101                              <1> 	; INPUT:
  5102                              <1> 	;   CL = color (8 bit, 256 colors)
  5103                              <1> 	;  ECX = color (16 bit and true colors)
  5104                              <1> 	;  EDX = start position (row, column)
  5105                              <1> 	;        (HW = row, DX = column)
  5106                              <1> 	;  ESI = size (rows, colums)
  5107                              <1> 	;        (HW = rows, SI = columns)
  5108                              <1> 	;
  5109                              <1> 	;  [maskcolor] = mask color (to be excluded)
  5110                              <1> 	;
  5111                              <1> 	; OUTPUT:
  5112                              <1> 	; 	[u.r0] will be > 0 if succesful
  5113                              <1> 
  5114 0000DE89 F605[98A30100]10    <1> 	test	byte [v_ops], 10h ; display page or window ?
  5115 0000DE90 7555                <1> 	jnz	short pix_op_mix_w ; window
  5116                              <1> 
  5117 0000DE92 8B3D[9AA30100]      <1> 	mov	edi, [v_mem]
  5118 0000DE98 89FE                <1> 	mov	esi, edi
  5119                              <1> 	; ecx = color (CL, CX, ECX)
  5120 0000DE9A 89C8                <1> 	mov	eax, ecx
  5121 0000DE9C 8B0D[9EA30100]      <1> 	mov	ecx, [v_siz] ; display page pixel count
  5122                              <1> 
  5123 0000DEA2 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color mix ?
  5124 0000DEA9 7405                <1> 	jz	short pix_op_mix_0 ; no
  5125 0000DEAB E91E110000          <1> 	jmp	m_pix_op_mix ; mix colors except mask color
  5126                              <1> pix_op_mix_0:
  5127 0000DEB0 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5128 0000DEB7 7707                <1> 	ja	short pix_op_mix_1
  5129                              <1> 
  5130                              <1> 	; 256 colors (8bpp)
  5131 0000DEB9 E8F3090000          <1> 	call	pix_op_mix_8
  5132 0000DEBE EB1E                <1> 	jmp	short pix_op_mix_4
  5133                              <1> 
  5134                              <1> pix_op_mix_1:
  5135 0000DEC0 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5136 0000DEC7 7710                <1> 	ja	short pix_op_mix_3 ; 32bpp
  5137 0000DEC9 7207                <1> 	jb	short pix_op_mix_2 ; 16bpp
  5138                              <1> 
  5139                              <1> 	; 24 bit true colors
  5140 0000DECB E8FC090000          <1> 	call	pix_op_mix_24
  5141 0000DED0 EB0C                <1> 	jmp	short pix_op_mix_4
  5142                              <1> 
  5143                              <1> 	; 65536 colors (16bpp)
  5144                              <1> pix_op_mix_2:
  5145 0000DED2 E8E6090000          <1> 	call	pix_op_mix_16
  5146 0000DED7 EB05                <1> 	jmp	short pix_op_mix_4
  5147                              <1> 
  5148                              <1> 	; 32 bit true colors
  5149                              <1> pix_op_mix_3:
  5150 0000DED9 E80A0A0000          <1> 	call	pix_op_mix_32
  5151                              <1> pix_op_mix_4:
  5152 0000DEDE 29F7                <1> 	sub	edi, esi
  5153 0000DEE0 893D[74940100]      <1> 	mov	[u.r0], edi
  5154                              <1> pix_op_mix_5:
  5155 0000DEE6 C3                  <1> 	retn
  5156                              <1> 
  5157                              <1> pix_op_mix_w:
  5158                              <1> 	; 31/01/2021
  5159 0000DEE7 51                  <1> 	push	ecx ; * ; color
  5160 0000DEE8 89D1                <1> 	mov	ecx, edx ; win start pos
  5161 0000DEEA 89F2                <1> 	mov	edx, esi ; size (rows, cols)
  5162 0000DEEC E8C4FCFFFF          <1> 	call	sysvideo_15_12 ; window preparations
  5163 0000DEF1 58                  <1> 	pop	eax ; * ; color
  5164 0000DEF2 72F2                <1> 	jc	short pix_op_mix_5
  5165                              <1> 
  5166 0000DEF4 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color mix ?
  5167 0000DEFB 7405                <1> 	jz	short pix_op_mix_w_0 ; no
  5168 0000DEFD E969110000          <1> 	jmp	m_pix_op_mix_w 
  5169                              <1> 			; window mix colors except mask color
  5170                              <1> pix_op_mix_w_0:
  5171                              <1> 	; ecx = bytes per row (to be applied)
  5172                              <1> 	; edx = screen width in bytes
  5173                              <1> 	; ebx = row count
  5174                              <1> 	; eax = color
  5175                              <1> 
  5176 0000DF02 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  5177 0000DF08 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5178 0000DF0F 7707                <1> 	ja	short pix_op_mix_w_1
  5179                              <1> 
  5180                              <1> 	; 256 colors (8bpp)
  5181 0000DF11 BD[B1E80000]        <1> 	mov	ebp, pix_op_mix_8
  5182 0000DF16 EB1E                <1> 	jmp	short pix_op_mix_w_x
  5183                              <1> 
  5184                              <1> pix_op_mix_w_1:
  5185 0000DF18 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5186 0000DF1F 7710                <1> 	ja	short pix_op_mix_w_3 ; 32bpp
  5187 0000DF21 7207                <1> 	jb	short pix_op_mix_w_2 ; 16bpp
  5188                              <1> 
  5189                              <1> 	; 24 bit true colors
  5190 0000DF23 BD[CCE80000]        <1> 	mov	ebp, pix_op_mix_24
  5191 0000DF28 EB0C                <1> 	jmp	short pix_op_mix_w_x
  5192                              <1> 
  5193                              <1> 	; 65536 colors (16bpp)
  5194                              <1> pix_op_mix_w_2:
  5195 0000DF2A BD[BDE80000]        <1> 	mov	ebp, pix_op_mix_16
  5196 0000DF2F EB05                <1> 	jmp	short pix_op_mix_w_x
  5197                              <1> 
  5198                              <1> 	; 32 bit true colors
  5199                              <1> pix_op_mix_w_3:
  5200 0000DF31 BD[E8E80000]        <1> 	mov	ebp, pix_op_mix_32
  5201                              <1> 	;jmp	short pix_op_mix_w_x
  5202                              <1> 
  5203                              <1> pix_op_mix_w_x:
  5204                              <1> pix_op_add_w_x:
  5205                              <1> pix_op_sub_w_x:
  5206                              <1> pix_op_rpl_w_x:
  5207                              <1> pix_op_orc_w_x:
  5208                              <1> pix_op_and_w_x:
  5209                              <1> pix_op_xor_w_x:
  5210                              <1> 	; 27/02/2021
  5211                              <1> 	; 31/01/2021
  5212                              <1> 	; ecx = bytes per row (to be applied)
  5213                              <1> 	; edx = windows (screen) width in bytes
  5214                              <1> 	; ebx = row count
  5215                              <1> 	; eax = color
  5216                              <1> 	; ebp = pixel operation subroutine address
  5217 0000DF36 52                  <1> 	push	edx
  5218 0000DF37 51                  <1> 	push	ecx
  5219 0000DF38 57                  <1> 	push	edi
  5220 0000DF39 8B0D[AEA30100]      <1> 	mov	ecx, [pixcount] ; 27/02/2021
  5221 0000DF3F FFD5                <1> 	call	ebp ; call pixel-row operation
  5222 0000DF41 5F                  <1> 	pop	edi
  5223 0000DF42 59                  <1> 	pop	ecx ; bytes per row
  5224 0000DF43 010D[74940100]      <1> 	add	[u.r0], ecx
  5225 0000DF49 5A                  <1> 	pop	edx
  5226 0000DF4A 01D7                <1> 	add	edi, edx ; next row
  5227 0000DF4C 4B                  <1> 	dec	ebx
  5228 0000DF4D 75E7                <1> 	jnz	short pix_op_mix_w_x
  5229 0000DF4F C3                  <1> 	retn
  5230                              <1> 
  5231                              <1> pix_op_rpl:
  5232                              <1> 	; 01/02/2021
  5233                              <1> 	; REPLACE COLOR
  5234                              <1> 	;
  5235                              <1> 	; INPUT:
  5236                              <1> 	;   CL = old/current color (8 bit, 256 colors)
  5237                              <1> 	;  ECX = old/current color (16 bit and true colors)
  5238                              <1> 	;   DL = new color (8 bit, 256 colors)
  5239                              <1> 	;  EDX = new color (16 bit and true colors)
  5240                              <1> 	;  ESI = start position (row, column)
  5241                              <1> 	;        (HW = row, DX = column)
  5242                              <1> 	;  EDI = size (rows, colums)
  5243                              <1> 	;        (HW = rows, SI = columns)
  5244                              <1> 	; OUTPUT:
  5245                              <1> 	; 	[u.r0] will be > 0 if succesful
  5246                              <1> 	
  5247 0000DF50 F605[98A30100]10    <1> 	test	byte [v_ops], 10h ; display page or window ?
  5248 0000DF57 754D                <1> 	jnz	short pix_op_rpl_w ; window
  5249                              <1> 	
  5250 0000DF59 8B3D[9AA30100]      <1> 	mov	edi, [v_mem]
  5251 0000DF5F 89FE                <1> 	mov	esi, edi
  5252                              <1> 	; ecx = old color (CL, CX, ECX) -to be replaced with-
  5253                              <1> 	; edx = new color (CL, CX, ECX) -new one-
  5254 0000DF61 89D0                <1> 	mov	eax, edx ; new color
  5255 0000DF63 890D[AAA30100]      <1> 	mov	[maskcolor], ecx ; old color
  5256 0000DF69 8B0D[9EA30100]      <1> 	mov	ecx, [v_siz] ; display page pixel count
  5257                              <1> pix_op_rpl_0:
  5258 0000DF6F 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5259 0000DF76 7707                <1> 	ja	short pix_op_rpl_1
  5260                              <1> 
  5261                              <1> 	; 256 colors (8bpp)
  5262 0000DF78 E82F0A0000          <1> 	call	pix_op_rpl_8
  5263 0000DF7D EB1E                <1> 	jmp	short pix_op_rpl_4
  5264                              <1> 
  5265                              <1> pix_op_rpl_1:
  5266 0000DF7F 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5267 0000DF86 7710                <1> 	ja	short pix_op_rpl_3 ; 32bpp
  5268 0000DF88 7207                <1> 	jb	short pix_op_rpl_2 ; 16bpp
  5269                              <1> 
  5270                              <1> 	; 24 bit true colors
  5271 0000DF8A E8400A0000          <1> 	call	pix_op_rpl_24
  5272 0000DF8F EB0C                <1> 	jmp	short pix_op_rpl_4
  5273                              <1> 
  5274                              <1> 	; 65536 colors (16bpp)
  5275                              <1> pix_op_rpl_2:
  5276 0000DF91 E8260A0000          <1> 	call	pix_op_rpl_16
  5277 0000DF96 EB05                <1> 	jmp	short pix_op_rpl_4
  5278                              <1> 
  5279                              <1> 	; 32 bit true colors
  5280                              <1> pix_op_rpl_3:
  5281 0000DF98 E8540A0000          <1> 	call	pix_op_rpl_32
  5282                              <1> pix_op_rpl_4:
  5283 0000DF9D 29F7                <1> 	sub	edi, esi
  5284 0000DF9F 893D[74940100]      <1> 	mov	[u.r0], edi
  5285                              <1> pix_op_rpl_5:
  5286 0000DFA5 C3                  <1> 	retn
  5287                              <1> 
  5288                              <1> pix_op_rpl_w:
  5289                              <1> 	; 01/02/2021
  5290 0000DFA6 890D[AAA30100]      <1> 	mov	[maskcolor], ecx ; old color
  5291 0000DFAC 52                  <1> 	push	edx ; * ; new color
  5292 0000DFAD 89F1                <1> 	mov	ecx, esi ; win start pos
  5293 0000DFAF 89FA                <1> 	mov	edx, edi ; size (rows, cols)
  5294 0000DFB1 E8FFFBFFFF          <1> 	call	sysvideo_15_12 ; window preparations
  5295 0000DFB6 58                  <1> 	pop	eax ; * ; new color
  5296 0000DFB7 72EC                <1> 	jc	short pix_op_rpl_5
  5297                              <1> 
  5298                              <1> 	; replace window color
  5299                              <1> pix_op_rpl_w_0:
  5300                              <1> 	; ecx = bytes per row (to be applied)
  5301                              <1> 	; edx = screen width in bytes
  5302                              <1> 	; ebx = row count
  5303                              <1> 	; eax = new color
  5304                              <1> 	; [maskcolor] = old color
  5305                              <1> 
  5306 0000DFB9 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  5307                              <1> 
  5308 0000DFBF 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5309 0000DFC6 7707                <1> 	ja	short pix_op_rpl_w_1
  5310                              <1> 
  5311                              <1> 	; 256 colors (8bpp)
  5312 0000DFC8 BD[ACE90000]        <1> 	mov	ebp, pix_op_rpl_8
  5313 0000DFCD EB1E                <1> 	jmp	short pix_op_rpl_w_4
  5314                              <1> 
  5315                              <1> pix_op_rpl_w_1:
  5316 0000DFCF 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5317 0000DFD6 7710                <1> 	ja	short pix_op_rpl_w_3 ; 32bpp
  5318 0000DFD8 7207                <1> 	jb	short pix_op_rpl_w_2 ; 16bpp
  5319                              <1> 
  5320                              <1> 	; 24 bit true colors
  5321 0000DFDA BD[CFE90000]        <1> 	mov	ebp, pix_op_rpl_24
  5322 0000DFDF EB0C                <1> 	jmp	short pix_op_rpl_w_4
  5323                              <1> 
  5324                              <1> 	; 65536 colors (16bpp)
  5325                              <1> pix_op_rpl_w_2:
  5326 0000DFE1 BD[BCE90000]        <1> 	mov	ebp, pix_op_rpl_16
  5327 0000DFE6 EB05                <1> 	jmp	short pix_op_rpl_w_4
  5328                              <1> 
  5329                              <1> 	; 32 bit true colors
  5330                              <1> pix_op_rpl_w_3:
  5331 0000DFE8 BD[F1E90000]        <1> 	mov	ebp, pix_op_rpl_32
  5332                              <1> pix_op_rpl_w_4:
  5333 0000DFED E944FFFFFF          <1> 	jmp	pix_op_rpl_w_x
  5334                              <1> 
  5335                              <1> pix_op_orc:
  5336                              <1> 	; 31/01/2021
  5337                              <1> 	; OR COLOR
  5338                              <1> 	;
  5339                              <1> 	; INPUT:
  5340                              <1> 	;   CL = color (8 bit, 256 colors)
  5341                              <1> 	;  ECX = color (16 bit and true colors)
  5342                              <1> 	;  EDX = start position (row, column)
  5343                              <1> 	;        (HW = row, DX = column)
  5344                              <1> 	;  ESI = size (rows, colums)
  5345                              <1> 	;        (HW = rows, SI = columns)
  5346                              <1> 	;
  5347                              <1> 	;  [maskcolor] = mask color (to be excluded)
  5348                              <1> 	;
  5349                              <1> 	; OUTPUT:
  5350                              <1> 	; 	[u.r0] will be > 0 if succesful
  5351                              <1> 	
  5352 0000DFF2 F605[98A30100]10    <1> 	test	byte [v_ops], 10h ; display page or window ?
  5353 0000DFF9 7555                <1> 	jnz	short pix_op_or_w ; window
  5354                              <1> 	
  5355 0000DFFB 8B3D[9AA30100]      <1> 	mov	edi, [v_mem]
  5356 0000E001 89FE                <1> 	mov	esi, edi
  5357                              <1> 	; ecx = color (CL, CX, ECX)
  5358 0000E003 89C8                <1> 	mov	eax, ecx
  5359 0000E005 8B0D[9EA30100]      <1> 	mov	ecx, [v_siz] ; display page pixel count
  5360                              <1> 
  5361 0000E00B F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color 'or' ?
  5362 0000E012 7405                <1> 	jz	short pix_op_or_0 ; no
  5363 0000E014 E945110000          <1> 	jmp	m_pix_op_or ; 'or' color except mask color
  5364                              <1> pix_op_or_0:
  5365 0000E019 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5366 0000E020 7707                <1> 	ja	short pix_op_or_1
  5367                              <1> 
  5368                              <1> 	; 256 colors (8bpp)
  5369 0000E022 E81B080000          <1> 	call	pix_op_or_8
  5370 0000E027 EB1E                <1> 	jmp	short pix_op_or_4
  5371                              <1> 
  5372                              <1> pix_op_or_1:
  5373 0000E029 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5374 0000E030 7710                <1> 	ja	short pix_op_or_3 ; 32bpp
  5375 0000E032 7207                <1> 	jb	short pix_op_or_2 ; 16bpp
  5376                              <1> 
  5377                              <1> 	; 24 bit true colors
  5378 0000E034 E817080000          <1> 	call	pix_op_or_24
  5379 0000E039 EB0C                <1> 	jmp	short pix_op_or_4
  5380                              <1> 
  5381                              <1> 	; 65536 colors (16bpp)
  5382                              <1> pix_op_or_2:
  5383 0000E03B E808080000          <1> 	call	pix_op_or_16
  5384 0000E040 EB05                <1> 	jmp	short pix_op_or_4
  5385                              <1> 
  5386                              <1> 	; 32 bit true colors
  5387                              <1> pix_op_or_3:
  5388 0000E042 E818080000          <1> 	call	pix_op_or_32
  5389                              <1> pix_op_or_4:
  5390 0000E047 29F7                <1> 	sub	edi, esi
  5391 0000E049 893D[74940100]      <1> 	mov	[u.r0], edi
  5392                              <1> pix_op_or_5:
  5393 0000E04F C3                  <1> 	retn
  5394                              <1> 
  5395                              <1> pix_op_or_w:
  5396                              <1> 	; 31/01/2021
  5397 0000E050 51                  <1> 	push	ecx ; * ; color
  5398 0000E051 89D1                <1> 	mov	ecx, edx ; win start pos
  5399 0000E053 89F2                <1> 	mov	edx, esi ; size (rows, cols)
  5400 0000E055 E85BFBFFFF          <1> 	call	sysvideo_15_12 ; window preparations
  5401 0000E05A 58                  <1> 	pop	eax ; * ; color
  5402 0000E05B 72F2                <1> 	jc	short pix_op_or_5
  5403                              <1> 
  5404 0000E05D F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color 'or' ?
  5405 0000E064 7405                <1> 	jz	short pix_op_or_w_0 ; no
  5406 0000E066 E980110000          <1> 	jmp	m_pix_op_or_w 
  5407                              <1> 			; window 'or' color except mask color
  5408                              <1> pix_op_or_w_0:
  5409                              <1> 	; ecx = bytes per row (to be applied)
  5410                              <1> 	; edx = screen width in bytes
  5411                              <1> 	; ebx = row count
  5412                              <1> 	; eax = color
  5413                              <1> 
  5414 0000E06B 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  5415 0000E071 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5416 0000E078 7707                <1> 	ja	short pix_op_or_w_1
  5417                              <1> 
  5418                              <1> 	; 256 colors (8bpp)
  5419 0000E07A BD[42E80000]        <1> 	mov	ebp, pix_op_or_8
  5420 0000E07F EB1E                <1> 	jmp	short pix_op_or_w_4
  5421                              <1> 
  5422                              <1> pix_op_or_w_1:
  5423 0000E081 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5424 0000E088 7710                <1> 	ja	short pix_op_or_w_3 ; 32bpp
  5425 0000E08A 7207                <1> 	jb	short pix_op_or_w_2 ; 16bpp
  5426                              <1> 
  5427                              <1> 	; 24 bit true colors
  5428 0000E08C BD[50E80000]        <1> 	mov	ebp, pix_op_or_24
  5429 0000E091 EB0C                <1> 	jmp	short pix_op_or_w_4
  5430                              <1> 
  5431                              <1> 	; 65536 colors (16bpp)
  5432                              <1> pix_op_or_w_2:
  5433 0000E093 BD[48E80000]        <1> 	mov	ebp, pix_op_or_16
  5434 0000E098 EB05                <1> 	jmp	short pix_op_or_w_4
  5435                              <1> 
  5436                              <1> 	; 32 bit true colors
  5437                              <1> pix_op_or_w_3:
  5438 0000E09A BD[5FE80000]        <1> 	mov	ebp, pix_op_or_32
  5439                              <1> pix_op_or_w_4:
  5440 0000E09F E992FEFFFF          <1> 	jmp	pix_op_orc_w_x
  5441                              <1> 
  5442                              <1> pix_op_and:
  5443                              <1> 	; 31/01/2021
  5444                              <1> 	; AND COLOR
  5445                              <1> 	;
  5446                              <1> 	; INPUT:
  5447                              <1> 	;   CL = color (8 bit, 256 colors)
  5448                              <1> 	;  ECX = color (16 bit and true colors)
  5449                              <1> 	;  EDX = start position (row, column)
  5450                              <1> 	;        (HW = row, DX = column)
  5451                              <1> 	;  ESI = size (rows, colums)
  5452                              <1> 	;        (HW = rows, SI = columns)
  5453                              <1> 	;
  5454                              <1> 	;  [maskcolor] = mask color (to be excluded)
  5455                              <1> 	;
  5456                              <1> 	; OUTPUT:
  5457                              <1> 	; 	[u.r0] will be > 0 if succesful
  5458                              <1> 	
  5459 0000E0A4 F605[98A30100]10    <1> 	test	byte [v_ops], 10h ; display page or window ?
  5460 0000E0AB 7555                <1> 	jnz	short pix_op_and_w ; window
  5461                              <1> 	
  5462 0000E0AD 8B3D[9AA30100]      <1> 	mov	edi, [v_mem]
  5463 0000E0B3 89FE                <1> 	mov	esi, edi
  5464                              <1> 	; ecx = color (CL, CX, ECX)
  5465 0000E0B5 89C8                <1> 	mov	eax, ecx
  5466 0000E0B7 8B0D[9EA30100]      <1> 	mov	ecx, [v_siz] ; display page pixel count
  5467                              <1> 
  5468 0000E0BD F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color 'and' ?
  5469 0000E0C4 7405                <1> 	jz	short pix_op_and_0 ; no
  5470 0000E0C6 E9D30F0000          <1> 	jmp	m_pix_op_and ; 'and' color except mask color
  5471                              <1> pix_op_and_0:
  5472 0000E0CB 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5473 0000E0D2 7707                <1> 	ja	short pix_op_and_1
  5474                              <1> 
  5475                              <1> 	; 256 colors (8bpp)
  5476 0000E0D4 E88E070000          <1> 	call	pix_op_and_8
  5477 0000E0D9 EB1E                <1> 	jmp	short pix_op_and_4
  5478                              <1> 
  5479                              <1> pix_op_and_1:
  5480 0000E0DB 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5481 0000E0E2 7710                <1> 	ja	short pix_op_and_3 ; 32bpp
  5482 0000E0E4 7207                <1> 	jb	short pix_op_and_2 ; 16bpp
  5483                              <1> 
  5484                              <1> 	; 24 bit true colors
  5485 0000E0E6 E88A070000          <1> 	call	pix_op_and_24
  5486 0000E0EB EB0C                <1> 	jmp	short pix_op_and_4
  5487                              <1> 
  5488                              <1> 	; 65536 colors (16bpp)
  5489                              <1> pix_op_and_2:
  5490 0000E0ED E87B070000          <1> 	call	pix_op_and_16
  5491 0000E0F2 EB05                <1> 	jmp	short pix_op_and_4
  5492                              <1> 
  5493                              <1> 	; 32 bit true colors
  5494                              <1> pix_op_and_3:
  5495 0000E0F4 E88B070000          <1> 	call	pix_op_and_32
  5496                              <1> pix_op_and_4:
  5497 0000E0F9 29F7                <1> 	sub	edi, esi
  5498 0000E0FB 893D[74940100]      <1> 	mov	[u.r0], edi
  5499                              <1> pix_op_and_5:
  5500 0000E101 C3                  <1> 	retn
  5501                              <1> 
  5502                              <1> pix_op_and_w:
  5503                              <1> 	; 31/01/2021
  5504 0000E102 51                  <1> 	push	ecx ; * ; color
  5505 0000E103 89D1                <1> 	mov	ecx, edx ; win start pos
  5506 0000E105 89F2                <1> 	mov	edx, esi ; size (rows, cols)
  5507 0000E107 E8A9FAFFFF          <1> 	call	sysvideo_15_12 ; window preparations
  5508 0000E10C 58                  <1> 	pop	eax ; * ; color
  5509 0000E10D 72F2                <1> 	jc	short pix_op_and_5
  5510                              <1> 
  5511 0000E10F F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color 'and' ?
  5512 0000E116 7405                <1> 	jz	short pix_op_and_w_0 ; no
  5513 0000E118 E90E100000          <1> 	jmp	m_pix_op_and_w 
  5514                              <1> 			; window 'and' color except mask color
  5515                              <1> pix_op_and_w_0:
  5516                              <1> 	; ecx = bytes per row (to be applied)
  5517                              <1> 	; edx = screen width in bytes
  5518                              <1> 	; ebx = row count
  5519                              <1> 	; eax = color
  5520                              <1> 
  5521 0000E11D 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  5522 0000E123 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5523 0000E12A 7707                <1> 	ja	short pix_op_and_w_1
  5524                              <1> 
  5525                              <1> 	; 256 colors (8bpp)
  5526 0000E12C BD[67E80000]        <1> 	mov	ebp, pix_op_and_8
  5527 0000E131 EB1E                <1> 	jmp	short pix_op_and_w_4
  5528                              <1> 
  5529                              <1> pix_op_and_w_1:
  5530 0000E133 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5531 0000E13A 7710                <1> 	ja	short pix_op_and_w_3 ; 32bpp
  5532 0000E13C 7207                <1> 	jb	short pix_op_and_w_2 ; 16bpp
  5533                              <1> 
  5534                              <1> 	; 24 bit true colors
  5535 0000E13E BD[75E80000]        <1> 	mov	ebp, pix_op_and_24
  5536 0000E143 EB0C                <1> 	jmp	short pix_op_and_w_4
  5537                              <1> 
  5538                              <1> 	; 65536 colors (16bpp)
  5539                              <1> pix_op_and_w_2:
  5540 0000E145 BD[6DE80000]        <1> 	mov	ebp, pix_op_and_16
  5541 0000E14A EB05                <1> 	jmp	short pix_op_and_w_4
  5542                              <1> 
  5543                              <1> 	; 32 bit true colors
  5544                              <1> pix_op_and_w_3:
  5545 0000E14C BD[84E80000]        <1> 	mov	ebp, pix_op_and_32
  5546                              <1> pix_op_and_w_4:
  5547 0000E151 E9E0FDFFFF          <1> 	jmp	pix_op_and_w_x
  5548                              <1> 
  5549                              <1> pix_op_xor:
  5550                              <1> 	; 31/01/2021
  5551                              <1> 	; XOR COLOR
  5552                              <1> 	;
  5553                              <1> 	; INPUT:
  5554                              <1> 	;   CL = color (8 bit, 256 colors)
  5555                              <1> 	;  ECX = color (16 bit and true colors)
  5556                              <1> 	;  EDX = start position (row, column)
  5557                              <1> 	;        (HW = row, DX = column)
  5558                              <1> 	;  ESI = size (rows, colums)
  5559                              <1> 	;        (HW = rows, SI = columns)
  5560                              <1> 	;
  5561                              <1> 	;  [maskcolor] = mask color (to be excluded)
  5562                              <1> 	;
  5563                              <1> 	; OUTPUT:
  5564                              <1> 	; 	[u.r0] will be > 0 if succesful
  5565                              <1> 	
  5566 0000E156 F605[98A30100]10    <1> 	test	byte [v_ops], 10h ; display page or window ?
  5567 0000E15D 7555                <1> 	jnz	short pix_op_xor_w ; window
  5568                              <1> 
  5569 0000E15F 8B3D[9AA30100]      <1> 	mov	edi, [v_mem]
  5570 0000E165 89FE                <1> 	mov	esi, edi
  5571                              <1> 	; ecx = color (CL, CX, ECX)
  5572 0000E167 89C8                <1> 	mov	eax, ecx
  5573 0000E169 8B0D[9EA30100]      <1> 	mov	ecx, [v_siz] ; display page pixel count
  5574                              <1> 
  5575 0000E16F F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color 'xor' ?
  5576 0000E176 7405                <1> 	jz	short pix_op_xor_0 ; no
  5577 0000E178 E9A1100000          <1> 	jmp	m_pix_op_xor ; 'xor' color except mask color
  5578                              <1> pix_op_xor_0:
  5579 0000E17D 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5580 0000E184 7707                <1> 	ja	short pix_op_xor_1
  5581                              <1> 
  5582                              <1> 	; 256 colors (8bpp)
  5583 0000E186 E801070000          <1> 	call	pix_op_xor_8
  5584 0000E18B EB1E                <1> 	jmp	short pix_op_xor_4
  5585                              <1> 
  5586                              <1> pix_op_xor_1:
  5587 0000E18D 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5588 0000E194 7710                <1> 	ja	short pix_op_xor_3 ; 32bpp
  5589 0000E196 7207                <1> 	jb	short pix_op_xor_2 ; 16bpp
  5590                              <1> 
  5591                              <1> 	; 24 bit true colors
  5592 0000E198 E8FD060000          <1> 	call	pix_op_xor_24
  5593 0000E19D EB0C                <1> 	jmp	short pix_op_xor_4
  5594                              <1> 
  5595                              <1> 	; 65536 colors (16bpp)
  5596                              <1> pix_op_xor_2:
  5597 0000E19F E8EE060000          <1> 	call	pix_op_xor_16
  5598 0000E1A4 EB05                <1> 	jmp	short pix_op_xor_4
  5599                              <1> 
  5600                              <1> 	; 32 bit true colors
  5601                              <1> pix_op_xor_3:
  5602 0000E1A6 E8FE060000          <1> 	call	pix_op_xor_32
  5603                              <1> pix_op_xor_4:
  5604 0000E1AB 29F7                <1> 	sub	edi, esi
  5605 0000E1AD 893D[74940100]      <1> 	mov	[u.r0], edi
  5606                              <1> pix_op_xor_5:
  5607 0000E1B3 C3                  <1> 	retn
  5608                              <1> 
  5609                              <1> pix_op_xor_w:
  5610                              <1> 	; 31/01/2021
  5611 0000E1B4 51                  <1> 	push	ecx ; * ; color
  5612 0000E1B5 89D1                <1> 	mov	ecx, edx ; win start pos
  5613 0000E1B7 89F2                <1> 	mov	edx, esi ; size (rows, cols)
  5614 0000E1B9 E8F7F9FFFF          <1> 	call	sysvideo_15_12 ; window preparations
  5615 0000E1BE 58                  <1> 	pop	eax ; * ; color
  5616 0000E1BF 72F2                <1> 	jc	short pix_op_xor_5
  5617                              <1> 
  5618 0000E1C1 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color 'xor' ?
  5619 0000E1C8 7405                <1> 	jz	short pix_op_xor_w_0 ; no
  5620 0000E1CA E9DC100000          <1> 	jmp	m_pix_op_xor_w 
  5621                              <1> 			; window 'xor' color except mask color
  5622                              <1> pix_op_xor_w_0:
  5623                              <1> 	; ecx = bytes per row (to be applied)
  5624                              <1> 	; edx = screen width in bytes
  5625                              <1> 	; ebx = row count
  5626                              <1> 	; eax = color
  5627                              <1> 
  5628 0000E1CF 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  5629 0000E1D5 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5630 0000E1DC 7707                <1> 	ja	short pix_op_xor_w_1
  5631                              <1> 
  5632                              <1> 	; 256 colors (8bpp)
  5633 0000E1DE BD[8CE80000]        <1> 	mov	ebp, pix_op_xor_8
  5634 0000E1E3 EB1E                <1> 	jmp	short pix_op_xor_w_4
  5635                              <1> 
  5636                              <1> pix_op_xor_w_1:
  5637 0000E1E5 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5638 0000E1EC 7710                <1> 	ja	short pix_op_xor_w_3 ; 32bpp
  5639 0000E1EE 7207                <1> 	jb	short pix_op_xor_w_2 ; 16bpp
  5640                              <1> 
  5641                              <1> 	; 24 bit true colors
  5642 0000E1F0 BD[9AE80000]        <1> 	mov	ebp, pix_op_xor_24
  5643 0000E1F5 EB0C                <1> 	jmp	short pix_op_xor_w_4
  5644                              <1> 
  5645                              <1> 	; 65536 colors (16bpp)
  5646                              <1> pix_op_xor_w_2:
  5647 0000E1F7 BD[92E80000]        <1> 	mov	ebp, pix_op_xor_16
  5648 0000E1FC EB05                <1> 	jmp	short pix_op_xor_w_4
  5649                              <1> 
  5650                              <1> 	; 32 bit true colors
  5651                              <1> pix_op_xor_w_3:
  5652 0000E1FE BD[A9E80000]        <1> 	mov	ebp, pix_op_xor_32
  5653                              <1> pix_op_xor_w_4:
  5654 0000E203 E92EFDFFFF          <1> 	jmp	pix_op_xor_w_x
  5655                              <1> 
  5656                              <1> pix_op_new:
  5657                              <1> 	; 31/01/2021
  5658                              <1> 	; 30/01/2021
  5659                              <1> 	; CHANGE COLOR
  5660                              <1> 	;
  5661                              <1> 	; INPUT:
  5662                              <1> 	;   CL = color (8 bit, 256 colors)
  5663                              <1> 	;  ECX = color (16 bit and true colors)
  5664                              <1> 	;  EDX = start position (row, column)
  5665                              <1> 	;        (HW = row, DX = column)
  5666                              <1> 	;  ESI = size (rows, colums)
  5667                              <1> 	;        (HW = rows, SI = columns)
  5668                              <1> 	;
  5669                              <1> 	;  [maskcolor] = mask color (to be excluded)
  5670                              <1> 	;
  5671                              <1> 	; OUTPUT:
  5672                              <1> 	; 	[u.r0] will be > 0 if succesful
  5673                              <1> 	
  5674 0000E208 F605[98A30100]10    <1> 	test	byte [v_ops], 10h ; display page or window ?
  5675 0000E20F 7554                <1> 	jnz	short pix_op_new_w ; window
  5676                              <1> 	
  5677 0000E211 8B3D[9AA30100]      <1> 	mov	edi, [v_mem]
  5678 0000E217 89FE                <1> 	mov	esi, edi
  5679                              <1> 	; ecx = color (CL, CX, ECX)
  5680 0000E219 89C8                <1> 	mov	eax, ecx
  5681 0000E21B 8B0D[9EA30100]      <1> 	mov	ecx, [v_siz] ; display page pixel count
  5682                              <1> 
  5683 0000E221 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color change ?
  5684 0000E228 7405                <1> 	jz	short pix_op_new_0 ; no
  5685 0000E22A E90A0B0000          <1> 	jmp	m_pix_op_new ; change color except mask color
  5686                              <1> pix_op_new_0:
  5687 0000E22F 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5688 0000E236 7706                <1> 	ja	short pix_op_new_2
  5689                              <1> 
  5690                              <1> 	; 256 colors (8bpp)
  5691                              <1> pix_op_new_1:
  5692 0000E238 88C4                <1> 	mov	ah, al
  5693 0000E23A D1E9                <1> 	shr	ecx, 1
  5694 0000E23C EB12                <1> 	jmp	short pix_op_new_3
  5695                              <1> 
  5696                              <1> pix_op_new_2:
  5697 0000E23E 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5698 0000E245 7713                <1> 	ja	short pix_op_new_4 ; 32bpp
  5699 0000E247 7207                <1> 	jb	short pix_op_new_3 ; 16bpp
  5700                              <1> 
  5701                              <1> 	; 31/01/2021
  5702                              <1> 	
  5703                              <1> 	; 24 bit true colors
  5704 0000E249 E849050000          <1> 	call	pix_op_new_24
  5705                              <1> 
  5706 0000E24E EB0C                <1> 	jmp	short pix_op_new_5
  5707                              <1> 
  5708                              <1> 	; 65536 colors (16bpp)
  5709                              <1> pix_op_new_3:
  5710 0000E250 89C2                <1> 	mov	edx, eax
  5711 0000E252 C1E010              <1> 	shl	eax, 16
  5712 0000E255 6689D0              <1> 	mov	ax, dx
  5713 0000E258 D1E9                <1> 	shr	ecx, 1 ; dword counts
  5714                              <1> 	; 32 bit true colors
  5715                              <1> pix_op_new_4:
  5716 0000E25A F3AB                <1> 	rep	stosd
  5717                              <1> pix_op_new_5:
  5718 0000E25C 29F7                <1> 	sub	edi, esi
  5719 0000E25E 893D[74940100]      <1> 	mov	[u.r0], edi
  5720                              <1> pix_op_new_6:
  5721 0000E264 C3                  <1> 	retn
  5722                              <1> 
  5723                              <1> pix_op_new_w:
  5724                              <1> 	; 31/01/2021
  5725                              <1> 	; 30/01/2021
  5726 0000E265 51                  <1> 	push	ecx ; * ; color
  5727 0000E266 89D1                <1> 	mov	ecx, edx ; win start pos
  5728 0000E268 89F2                <1> 	mov	edx, esi ; size (rows, cols)
  5729 0000E26A E846F9FFFF          <1> 	call	sysvideo_15_12 ; window preparations
  5730 0000E26F 58                  <1> 	pop	eax ; * ; color
  5731 0000E270 72F2                <1> 	jc	short pix_op_new_6
  5732                              <1> 
  5733 0000E272 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color change ?
  5734 0000E279 7405                <1> 	jz	short pix_op_new_w_0 ; no
  5735 0000E27B E9470B0000          <1> 	jmp	m_pix_op_new_w 
  5736                              <1> 			; window chg color except mask color
  5737                              <1> pix_op_new_w_0:
  5738                              <1> 	; ecx = bytes per row (to be applied)
  5739                              <1> 	; edx = screen width in bytes
  5740                              <1> 	; ebx = row count
  5741                              <1> 	; eax = color
  5742                              <1> 
  5743 0000E280 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  5744                              <1> 
  5745 0000E286 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5746 0000E28D 7707                <1> 	ja	short pix_op_new_w_1
  5747                              <1> 
  5748                              <1> 	; 256 colors (8bpp)
  5749 0000E28F BD[90E70000]        <1> 	mov	ebp, pix_op_new_8
  5750 0000E294 EB1E                <1> 	jmp	short pix_op_new_w_x
  5751                              <1> 
  5752                              <1> pix_op_new_w_1:
  5753 0000E296 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5754 0000E29D 7710                <1> 	ja	short pix_op_new_w_3 ; 32bpp
  5755 0000E29F 7207                <1> 	jb	short pix_op_new_w_2 ; 16bpp
  5756                              <1> 
  5757                              <1> 	; 24 bit true colors
  5758 0000E2A1 BD[97E70000]        <1> 	mov	ebp, pix_op_new_24
  5759 0000E2A6 EB0C                <1> 	jmp	short pix_op_new_w_x
  5760                              <1> 
  5761                              <1> 	; 65536 colors (16bpp)
  5762                              <1> pix_op_new_w_2:
  5763 0000E2A8 BD[93E70000]        <1> 	mov	ebp, pix_op_new_16
  5764 0000E2AD EB05                <1> 	jmp	short pix_op_new_w_x
  5765                              <1> 
  5766                              <1> 	; 32 bit true colors
  5767                              <1> pix_op_new_w_3:
  5768 0000E2AF BD[A3E70000]        <1> 	mov	ebp, pix_op_new_32
  5769                              <1> 	;jmp	short pix_op_new_w_x
  5770                              <1> 
  5771                              <1> pix_op_new_w_x:
  5772                              <1> pix_op_not_w_x:
  5773                              <1> pix_op_neg_w_x:
  5774                              <1> pix_op_inc_w_x:
  5775                              <1> pix_op_dec_w_x:
  5776                              <1> 	; 27/02/2021
  5777                              <1> 	; 01/02/2021
  5778                              <1> 	; 31/01/2021
  5779                              <1> 	; ecx = bytes per row (to be applied)
  5780                              <1> 	; edx = windows (screen) width in bytes
  5781                              <1> 	; ebx = row count
  5782                              <1> 	; eax = color
  5783                              <1> 	; ebp = pixel operation subroutine address
  5784                              <1> 	;push	edx ; 01/02/2021
  5785 0000E2B4 51                  <1> 	push	ecx
  5786 0000E2B5 57                  <1> 	push	edi
  5787 0000E2B6 8B0D[AEA30100]      <1> 	mov	ecx, [pixcount] ; 27/02/2021
  5788 0000E2BC FFD5                <1> 	call	ebp ; call pixel-row operation
  5789 0000E2BE 5F                  <1> 	pop	edi
  5790 0000E2BF 59                  <1> 	pop	ecx ; bytes per row
  5791 0000E2C0 010D[74940100]      <1> 	add	[u.r0], ecx
  5792                              <1> 	;pop	edx ; 01/02/2021
  5793 0000E2C6 01D7                <1> 	add	edi, edx ; next row
  5794 0000E2C8 4B                  <1> 	dec	ebx
  5795 0000E2C9 75E9                <1> 	jnz	short pix_op_new_w_x
  5796 0000E2CB C3                  <1> 	retn
  5797                              <1> 
  5798                              <1> pix_op_not:
  5799                              <1> 	; 31/01/2021
  5800                              <1> 	; NOT COLOR
  5801                              <1> 	;
  5802                              <1> 	; INPUT:
  5803                              <1> 	;  ECX = start position (row, column)
  5804                              <1> 	;        (HW = row, CX = column)
  5805                              <1> 	;  EDX = size (rows, colums)
  5806                              <1> 	;        (HW = rows, DX = columns)
  5807                              <1> 	;	 (0 -> invalid 	
  5808                              <1> 	;        (1 -> horizontal or vertical line)
  5809                              <1> 	;  [maskcolor] = mask color (to be excluded)
  5810                              <1> 	;
  5811                              <1> 	; OUTPUT:
  5812                              <1> 	; 	[u.r0] will be > 0 if succesful
  5813                              <1> 	
  5814 0000E2CC F605[98A30100]10    <1> 	test	byte [v_ops], 10h ; display page or window ?
  5815 0000E2D3 7553                <1> 	jnz	short pix_op_not_w ; window
  5816                              <1> 	
  5817 0000E2D5 8B3D[9AA30100]      <1> 	mov	edi, [v_mem]
  5818 0000E2DB 89FE                <1> 	mov	esi, edi
  5819 0000E2DD 8B0D[9EA30100]      <1> 	mov	ecx, [v_siz] ; display page pixel count
  5820                              <1> 
  5821 0000E2E3 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color 'not' ?
  5822 0000E2EA 7405                <1> 	jz	short pix_op_not_0 ; no
  5823 0000E2EC E9ED0F0000          <1> 	jmp	m_pix_op_not ; 'not' color except mask color
  5824                              <1> pix_op_not_0:
  5825 0000E2F1 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5826 0000E2F8 7707                <1> 	ja	short pix_op_not_1
  5827                              <1> 
  5828                              <1> 	; 256 colors (8bpp)
  5829 0000E2FA E8F5050000          <1> 	call	pix_op_not_8
  5830 0000E2FF EB1E                <1> 	jmp	short pix_op_not_4
  5831                              <1> 
  5832                              <1> pix_op_not_1:
  5833 0000E301 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5834 0000E308 7710                <1> 	ja	short pix_op_not_3 ; 32bpp
  5835 0000E30A 7207                <1> 	jb	short pix_op_not_2 ; 16bpp
  5836                              <1> 
  5837                              <1> 	; 24 bit true colors
  5838 0000E30C E8F1050000          <1> 	call	pix_op_not_24
  5839 0000E311 EB0C                <1> 	jmp	short pix_op_not_4
  5840                              <1> 
  5841                              <1> 	; 65536 colors (16bpp)
  5842                              <1> pix_op_not_2:
  5843 0000E313 E8E2050000          <1> 	call	pix_op_not_16
  5844 0000E318 EB05                <1> 	jmp	short pix_op_not_4
  5845                              <1> 
  5846                              <1> 	; 32 bit true colors
  5847                              <1> pix_op_not_3:
  5848 0000E31A E8EE050000          <1> 	call	pix_op_not_32
  5849                              <1> pix_op_not_4:
  5850 0000E31F 29F7                <1> 	sub	edi, esi
  5851 0000E321 893D[74940100]      <1> 	mov	[u.r0], edi
  5852                              <1> pix_op_not_5:
  5853 0000E327 C3                  <1> 	retn
  5854                              <1> 
  5855                              <1> pix_op_not_w:
  5856                              <1> 	; 31/01/2021
  5857                              <1> 	; ecx = win start pos (row, column)
  5858                              <1> 	; edx = size (rows, columns)
  5859 0000E328 E888F8FFFF          <1> 	call	sysvideo_15_12 ; window preparations
  5860 0000E32D 72F8                <1> 	jc	short pix_op_not_5
  5861                              <1> 
  5862 0000E32F F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked color 'not' ?
  5863 0000E336 7405                <1> 	jz	short pix_op_not_w_0 ; no
  5864 0000E338 E926100000          <1> 	jmp	m_pix_op_not_w 
  5865                              <1> 			; window 'not' color except mask color
  5866                              <1> pix_op_not_w_0:
  5867                              <1> 	; ecx = bytes per row (to be applied)
  5868                              <1> 	; edx = screen width in bytes
  5869                              <1> 	; ebx = row count
  5870                              <1> 
  5871 0000E33D 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  5872                              <1> 
  5873 0000E343 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5874 0000E34A 7707                <1> 	ja	short pix_op_not_w_1
  5875                              <1> 
  5876                              <1> 	; 256 colors (8bpp)
  5877 0000E34C BD[F4E80000]        <1> 	mov	ebp, pix_op_not_8
  5878 0000E351 EB1E                <1> 	jmp	short pix_op_not_w_4
  5879                              <1> 
  5880                              <1> pix_op_not_w_1:
  5881 0000E353 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5882 0000E35A 7710                <1> 	ja	short pix_op_not_w_3 ; 32bpp
  5883 0000E35C 7207                <1> 	jb	short pix_op_not_w_2 ; 16bpp
  5884                              <1> 
  5885                              <1> 	; 24 bit true colors
  5886 0000E35E BD[02E90000]        <1> 	mov	ebp, pix_op_not_24
  5887 0000E363 EB0C                <1> 	jmp	short pix_op_not_w_4
  5888                              <1> 
  5889                              <1> 	; 65536 colors (16bpp)
  5890                              <1> pix_op_not_w_2:
  5891 0000E365 BD[FAE80000]        <1> 	mov	ebp, pix_op_not_16
  5892 0000E36A EB05                <1> 	jmp	short pix_op_not_w_4
  5893                              <1> 
  5894                              <1> 	; 32 bit true colors
  5895                              <1> pix_op_not_w_3:
  5896 0000E36C BD[0DE90000]        <1> 	mov	ebp, pix_op_not_32
  5897                              <1> pix_op_not_w_4:
  5898 0000E371 E93EFFFFFF          <1> 	jmp	pix_op_not_w_x
  5899                              <1> 
  5900                              <1> pix_op_neg:
  5901                              <1> 	; 31/01/2021
  5902                              <1> 	; NEGATE COLOR
  5903                              <1> 	;
  5904                              <1> 	; INPUT:
  5905                              <1> 	;  ECX = start position (row, column)
  5906                              <1> 	;        (HW = row, CX = column)
  5907                              <1> 	;  EDX = size (rows, colums)
  5908                              <1> 	;        (HW = rows, DX = columns)
  5909                              <1> 	;	 (0 -> invalid 	
  5910                              <1> 	;        (1 -> horizontal or vertical line)
  5911                              <1> 	;  [maskcolor] = mask color (to be excluded)
  5912                              <1> 	;
  5913                              <1> 	; OUTPUT:
  5914                              <1> 	; 	[u.r0] will be > 0 if succesful
  5915                              <1> 
  5916 0000E376 F605[98A30100]10    <1> 	test	byte [v_ops], 10h ; display page or window ?
  5917 0000E37D 7553                <1> 	jnz	short pix_op_neg_w ; window
  5918                              <1> 
  5919 0000E37F 8B3D[9AA30100]      <1> 	mov	edi, [v_mem]
  5920 0000E385 89FE                <1> 	mov	esi, edi
  5921 0000E387 8B0D[9EA30100]      <1> 	mov	ecx, [v_siz] ; display page pixel count
  5922                              <1> 
  5923 0000E38D F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked negate color ?
  5924 0000E394 7405                <1> 	jz	short pix_op_neg_0 ; no
  5925 0000E396 E9FB0F0000          <1> 	jmp	m_pix_op_neg ; 'neg' color except mask color
  5926                              <1> pix_op_neg_0:
  5927 0000E39B 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5928 0000E3A2 7707                <1> 	ja	short pix_op_neg_1
  5929                              <1> 
  5930                              <1> 	; 256 colors (8bpp)
  5931 0000E3A4 E86C050000          <1> 	call	pix_op_neg_8
  5932 0000E3A9 EB1E                <1> 	jmp	short pix_op_neg_4
  5933                              <1> 
  5934                              <1> pix_op_neg_1:
  5935 0000E3AB 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5936 0000E3B2 7710                <1> 	ja	short pix_op_neg_3 ; 32bpp
  5937 0000E3B4 7207                <1> 	jb	short pix_op_neg_2 ; 16bpp
  5938                              <1> 
  5939                              <1> 	; 24 bit true colors
  5940 0000E3B6 E868050000          <1> 	call	pix_op_neg_24
  5941 0000E3BB EB0C                <1> 	jmp	short pix_op_neg_4
  5942                              <1> 
  5943                              <1> 	; 65536 colors (16bpp)
  5944                              <1> pix_op_neg_2:
  5945 0000E3BD E859050000          <1> 	call	pix_op_neg_16
  5946 0000E3C2 EB05                <1> 	jmp	short pix_op_neg_4
  5947                              <1> 
  5948                              <1> 	; 32 bit true colors
  5949                              <1> pix_op_neg_3:
  5950 0000E3C4 E86C050000          <1> 	call	pix_op_neg_32
  5951                              <1> pix_op_neg_4:
  5952 0000E3C9 29F7                <1> 	sub	edi, esi
  5953 0000E3CB 893D[74940100]      <1> 	mov	[u.r0], edi
  5954                              <1> pix_op_neg_5:
  5955 0000E3D1 C3                  <1> 	retn
  5956                              <1> 
  5957                              <1> pix_op_neg_w:
  5958                              <1> 	; 31/01/2021
  5959                              <1> 	; ecx = win start pos (row, column)
  5960                              <1> 	; edx = size (rows, columns)
  5961 0000E3D2 E8DEF7FFFF          <1> 	call	sysvideo_15_12 ; window preparations
  5962 0000E3D7 72F8                <1> 	jc	short pix_op_neg_5
  5963                              <1> 
  5964 0000E3D9 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked negate color ?
  5965 0000E3E0 7405                <1> 	jz	short pix_op_neg_w_0 ; no
  5966 0000E3E2 E934100000          <1> 	jmp	m_pix_op_neg_w 
  5967                              <1> 			; window 'neg' color except mask color
  5968                              <1> pix_op_neg_w_0:
  5969                              <1> 	; ecx = bytes per row (to be applied)
  5970                              <1> 	; edx = screen width in bytes
  5971                              <1> 	; ebx = row count
  5972                              <1> 
  5973 0000E3E7 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  5974                              <1> 
  5975 0000E3ED 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  5976 0000E3F4 7707                <1> 	ja	short pix_op_neg_w_1
  5977                              <1> 
  5978                              <1> 	; 256 colors (8bpp)
  5979 0000E3F6 BD[15E90000]        <1> 	mov	ebp, pix_op_neg_8
  5980 0000E3FB EB1E                <1> 	jmp	short pix_op_neg_w_4
  5981                              <1> 
  5982                              <1> pix_op_neg_w_1:
  5983 0000E3FD 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  5984 0000E404 7710                <1> 	ja	short pix_op_neg_w_3 ; 32bpp
  5985 0000E406 7207                <1> 	jb	short pix_op_neg_w_2 ; 16bpp
  5986                              <1> 
  5987                              <1> 	; 24 bit true colors
  5988 0000E408 BD[23E90000]        <1> 	mov	ebp, pix_op_neg_24
  5989 0000E40D EB0C                <1> 	jmp	short pix_op_neg_w_4
  5990                              <1> 
  5991                              <1> 	; 65536 colors (16bpp)
  5992                              <1> pix_op_neg_w_2:
  5993 0000E40F BD[1BE90000]        <1> 	mov	ebp, pix_op_neg_16
  5994 0000E414 EB05                <1> 	jmp	short pix_op_neg_w_4
  5995                              <1> 
  5996                              <1> 	; 32 bit true colors
  5997                              <1> pix_op_neg_w_3:
  5998 0000E416 BD[35E90000]        <1> 	mov	ebp, pix_op_neg_32
  5999                              <1> pix_op_neg_w_4:
  6000 0000E41B E994FEFFFF          <1> 	jmp	pix_op_neg_w_x
  6001                              <1> 
  6002                              <1> pix_op_inc:
  6003                              <1> 	; 31/01/2021
  6004                              <1> 	; INCREASE COLOR
  6005                              <1> 	;
  6006                              <1> 	; INPUT:
  6007                              <1> 	;  ECX = start position (row, column)
  6008                              <1> 	;        (HW = row, CX = column)
  6009                              <1> 	;  EDX = size (rows, colums)
  6010                              <1> 	;        (HW = rows, DX = columns)
  6011                              <1> 	;	 (0 -> invalid 	
  6012                              <1> 	;        (1 -> horizontal or vertical line)
  6013                              <1> 	;  [maskcolor] = mask color (to be excluded)
  6014                              <1> 	;
  6015                              <1> 	; OUTPUT:
  6016                              <1> 	; 	[u.r0] will be > 0 if succesful
  6017                              <1> 	
  6018 0000E420 F605[98A30100]10    <1> 	test	byte [v_ops], 10h ; display page or window ?
  6019 0000E427 7553                <1> 	jnz	short pix_op_inc_w ; window
  6020                              <1> 	
  6021 0000E429 8B3D[9AA30100]      <1> 	mov	edi, [v_mem]
  6022 0000E42F 89FE                <1> 	mov	esi, edi
  6023 0000E431 8B0D[9EA30100]      <1> 	mov	ecx, [v_siz] ; display page pixel count
  6024                              <1> 
  6025 0000E437 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked increase color ?
  6026 0000E43E 7405                <1> 	jz	short pix_op_inc_0 ; no
  6027 0000E440 E909100000          <1> 	jmp	m_pix_op_inc ; 'inc' color except mask color
  6028                              <1> pix_op_inc_0:
  6029 0000E445 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  6030 0000E44C 7707                <1> 	ja	short pix_op_inc_1
  6031                              <1> 
  6032                              <1> 	; 256 colors (8bpp)
  6033 0000E44E E8EA040000          <1> 	call	pix_op_inc_8
  6034 0000E453 EB1E                <1> 	jmp	short pix_op_inc_4
  6035                              <1> 
  6036                              <1> pix_op_inc_1:
  6037 0000E455 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  6038 0000E45C 7710                <1> 	ja	short pix_op_inc_3 ; 32bpp
  6039 0000E45E 7207                <1> 	jb	short pix_op_inc_2 ; 16bpp
  6040                              <1> 
  6041                              <1> 	; 24 bit true colors
  6042 0000E460 E8EF040000          <1> 	call	pix_op_inc_24
  6043 0000E465 EB0C                <1> 	jmp	short pix_op_inc_4
  6044                              <1> 
  6045                              <1> 	; 65536 colors (16bpp)
  6046                              <1> pix_op_inc_2:
  6047 0000E467 E8DB040000          <1> 	call	pix_op_inc_16
  6048 0000E46C EB05                <1> 	jmp	short pix_op_inc_4
  6049                              <1> 
  6050                              <1> 	; 32 bit true colors
  6051                              <1> pix_op_inc_3:
  6052 0000E46E E8F5040000          <1> 	call	pix_op_inc_32
  6053                              <1> pix_op_inc_4:
  6054 0000E473 29F7                <1> 	sub	edi, esi
  6055 0000E475 893D[74940100]      <1> 	mov	[u.r0], edi
  6056                              <1> pix_op_inc_5:
  6057 0000E47B C3                  <1> 	retn
  6058                              <1> 
  6059                              <1> pix_op_inc_w:
  6060                              <1> 	; 31/01/2021
  6061                              <1> 	; ecx = win start pos (row, column)
  6062                              <1> 	; edx = size (rows, columns)
  6063 0000E47C E834F7FFFF          <1> 	call	sysvideo_15_12 ; window preparations
  6064 0000E481 72F8                <1> 	jc	short pix_op_inc_5
  6065                              <1> 
  6066 0000E483 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked increase color ?
  6067 0000E48A 7405                <1> 	jz	short pix_op_inc_w_0 ; no
  6068 0000E48C E956100000          <1> 	jmp	m_pix_op_inc_w 
  6069                              <1> 			; window 'inc' color except mask color
  6070                              <1> pix_op_inc_w_0:
  6071                              <1> 	; ecx = bytes per row (to be applied)
  6072                              <1> 	; edx = screen width in bytes
  6073                              <1> 	; ebx = row count
  6074                              <1> 
  6075 0000E491 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  6076                              <1> 
  6077 0000E497 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  6078 0000E49E 7707                <1> 	ja	short pix_op_inc_w_1
  6079                              <1> 
  6080                              <1> 	; 256 colors (8bpp)
  6081 0000E4A0 BD[3DE90000]        <1> 	mov	ebp, pix_op_inc_8
  6082 0000E4A5 EB1E                <1> 	jmp	short pix_op_inc_w_4
  6083                              <1> 
  6084                              <1> pix_op_inc_w_1:
  6085 0000E4A7 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  6086 0000E4AE 7710                <1> 	ja	short pix_op_inc_w_3 ; 32bpp
  6087 0000E4B0 7207                <1> 	jb	short pix_op_inc_w_2 ; 16bpp
  6088                              <1> 
  6089                              <1> 	; 24 bit true colors
  6090 0000E4B2 BD[54E90000]        <1> 	mov	ebp, pix_op_inc_24
  6091 0000E4B7 EB0C                <1> 	jmp	short pix_op_inc_w_4
  6092                              <1> 
  6093                              <1> 	; 65536 colors (16bpp)
  6094                              <1> pix_op_inc_w_2:
  6095 0000E4B9 BD[47E90000]        <1> 	mov	ebp, pix_op_inc_16
  6096 0000E4BE EB05                <1> 	jmp	short pix_op_inc_w_4
  6097                              <1> 
  6098                              <1> 	; 32 bit true colors
  6099                              <1> pix_op_inc_w_3:
  6100 0000E4C0 BD[68E90000]        <1> 	mov	ebp, pix_op_inc_32
  6101                              <1> pix_op_inc_w_4:
  6102 0000E4C5 E9EAFDFFFF          <1> 	jmp	pix_op_inc_w_x
  6103                              <1> 
  6104                              <1> pix_op_dec:
  6105                              <1> 	; 31/01/2021
  6106                              <1> 	; DECREASE COLOR
  6107                              <1> 	;
  6108                              <1> 	; INPUT:
  6109                              <1> 	;  ECX = start position (row, column)
  6110                              <1> 	;        (HW = row, CX = column)
  6111                              <1> 	;  EDX = size (rows, colums)
  6112                              <1> 	;        (HW = rows, DX = columns)
  6113                              <1> 	;	 (0 -> invalid 	
  6114                              <1> 	;        (1 -> horizontal or vertical line)
  6115                              <1> 	;  [maskcolor] = mask color (to be excluded)
  6116                              <1> 	;
  6117                              <1> 	; OUTPUT:
  6118                              <1> 	; 	[u.r0] will be > 0 if succesful
  6119                              <1> 	
  6120 0000E4CA F605[98A30100]10    <1> 	test	byte [v_ops], 10h ; display page or window ?
  6121 0000E4D1 7553                <1> 	jnz	short pix_op_dec_w ; window
  6122                              <1> 	
  6123 0000E4D3 8B3D[9AA30100]      <1> 	mov	edi, [v_mem]
  6124 0000E4D9 89FE                <1> 	mov	esi, edi
  6125 0000E4DB 8B0D[9EA30100]      <1> 	mov	ecx, [v_siz] ; display page pixel count
  6126                              <1> 
  6127 0000E4E1 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked decrease color ?
  6128 0000E4E8 7405                <1> 	jz	short pix_op_dec_0 ; no
  6129 0000E4EA E92B100000          <1> 	jmp	m_pix_op_dec ; 'dec' color except mask color
  6130                              <1> pix_op_dec_0:
  6131 0000E4EF 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  6132 0000E4F6 7707                <1> 	ja	short pix_op_dec_1
  6133                              <1> 
  6134                              <1> 	; 256 colors (8bpp)
  6135 0000E4F8 E877040000          <1> 	call	pix_op_dec_8
  6136 0000E4FD EB1E                <1> 	jmp	short pix_op_dec_4
  6137                              <1> 
  6138                              <1> pix_op_dec_1:
  6139 0000E4FF 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  6140 0000E506 7710                <1> 	ja	short pix_op_dec_3 ; 32bpp
  6141 0000E508 7207                <1> 	jb	short pix_op_dec_2 ; 16bpp
  6142                              <1> 
  6143                              <1> 	; 24 bit true colors
  6144 0000E50A E87C040000          <1> 	call	pix_op_dec_24
  6145 0000E50F EB0C                <1> 	jmp	short pix_op_dec_4
  6146                              <1> 
  6147                              <1> 	; 65536 colors (16bpp)
  6148                              <1> pix_op_dec_2:
  6149 0000E511 E868040000          <1> 	call	pix_op_dec_16
  6150 0000E516 EB05                <1> 	jmp	short pix_op_dec_4
  6151                              <1> 
  6152                              <1> 	; 32 bit true colors
  6153                              <1> pix_op_dec_3:
  6154 0000E518 E881040000          <1> 	call	pix_op_dec_32
  6155                              <1> pix_op_dec_4:
  6156 0000E51D 29F7                <1> 	sub	edi, esi
  6157 0000E51F 893D[74940100]      <1> 	mov	[u.r0], edi
  6158                              <1> pix_op_dec_5:
  6159 0000E525 C3                  <1> 	retn
  6160                              <1> 
  6161                              <1> pix_op_dec_w:
  6162                              <1> 	; 31/01/2021
  6163                              <1> 	; ecx = win start pos (row, column)
  6164                              <1> 	; edx = size (rows, columns)
  6165 0000E526 E88AF6FFFF          <1> 	call	sysvideo_15_12 ; window preparations
  6166 0000E52B 72F8                <1> 	jc	short pix_op_dec_5
  6167                              <1> 
  6168 0000E52D F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked decrease color ?
  6169 0000E534 7405                <1> 	jz	short pix_op_dec_w_0 ; no
  6170 0000E536 E973100000          <1> 	jmp	m_pix_op_dec_w 
  6171                              <1> 			; window 'dec' color except mask color
  6172                              <1> pix_op_dec_w_0:
  6173                              <1> 	; ecx = bytes per row (to be applied)
  6174                              <1> 	; edx = screen width in bytes
  6175                              <1> 	; ebx = row count
  6176                              <1> 
  6177 0000E53B 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  6178                              <1> 
  6179 0000E541 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  6180 0000E548 7707                <1> 	ja	short pix_op_dec_w_1
  6181                              <1> 
  6182                              <1> 	; 256 colors (8bpp)
  6183 0000E54A BD[74E90000]        <1> 	mov	ebp, pix_op_dec_8
  6184 0000E54F EB1E                <1> 	jmp	short pix_op_dec_w_4
  6185                              <1> 
  6186                              <1> pix_op_dec_w_1:
  6187 0000E551 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  6188 0000E558 7710                <1> 	ja	short pix_op_dec_w_3 ; 32bpp
  6189 0000E55A 7207                <1> 	jb	short pix_op_dec_w_2 ; 16bpp
  6190                              <1> 
  6191                              <1> 	; 24 bit true colors
  6192 0000E55C BD[8BE90000]        <1> 	mov	ebp, pix_op_dec_24
  6193 0000E561 EB0C                <1> 	jmp	short pix_op_dec_w_4
  6194                              <1> 
  6195                              <1> 	; 65536 colors (16bpp)
  6196                              <1> pix_op_dec_w_2:
  6197 0000E563 BD[7EE90000]        <1> 	mov	ebp, pix_op_dec_16
  6198 0000E568 EB05                <1> 	jmp	short pix_op_dec_w_4
  6199                              <1> 
  6200                              <1> 	; 32 bit true colors
  6201                              <1> pix_op_dec_w_3:
  6202 0000E56A BD[9EE90000]        <1> 	mov	ebp, pix_op_dec_32
  6203                              <1> pix_op_dec_w_4:
  6204 0000E56F E940FDFFFF          <1> 	jmp	pix_op_dec_w_x
  6205                              <1> 
  6206                              <1> pix_op_blk:
  6207                              <1> 	; 11/08/2022 (TRDOS 386 Kernel v2.0.5)
  6208                              <1> 	; 23/01/2021
  6209                              <1> 	; 22/02/2021
  6210                              <1> 	; 02/02/2021
  6211                              <1> 	; COPY PIXEL BLOCK -system to system-
  6212                              <1> 	; WRITE PIXEL BLOCKS -user to system-
  6213                              <1> 	;
  6214                              <1> 	; INPUT:
  6215                              <1> 	;   -If BL bit 5 is 0-
  6216                              <1> 	;    ECX = start position (row, column) (*)
  6217                              <1> 	;    (HW = row, CX = column)
  6218                              <1> 	;    EDX = size (rows, colums) (*)
  6219                              <1> 	;    (HW = rows, DX = columns)
  6220                              <1> 	;         (0 -> invalid)
  6221                              <1> 	;         (1 -> horizontal or vertical line)
  6222                              <1> 	;    ESI = destination (row, column) (***)
  6223                              <1> 	;   -If BL bit 5 is 1-	
  6224                              <1> 	;     CL = color (8 bit, 256 colors)
  6225                              <1> 	;    ECX = color (16 bit and true colors)
  6226                              <1> 	;    EDX = count of blocks (not bytes)
  6227                              <1> 	;	 (limit: 2048 blocks/windows)
  6228                              <1> 	;    ESI = user's buffer address 
  6229                              <1> 	;	  contains 64 bit block data
  6230                              <1> 	;	  BLOCK ADDRESS - (row, col), dword
  6231                              <1> 	;	  (first 32 bits)
  6232                              <1> 	;	  BLOCK SIZE - (rows, cols), dword
  6233                              <1> 	;	  (second 32 bits)
  6234                              <1> 	; OUTPUT:
  6235                              <1> 	; 	[u.r0] will be > 0 if succesful
  6236                              <1> 
  6237                              <1> 	; Window option ([v_ops] bit 4) will be ignored
  6238                              <1> 	; (Function is used for display page coordinates)
  6239                              <1> 
  6240 0000E574 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked or direct ?
  6241 0000E57B 755A                <1> 	jnz	short pix_op_blk_u ; blocks from user's buffer
  6242                              <1> 
  6243 0000E57D 89F0                <1> 	mov	eax, esi ; destination position (row, col)
  6244 0000E57F E8DEF6FFFF          <1> 	call	calc_pixel_offset
  6245 0000E584 3B05[9EA30100]      <1> 	cmp	eax, [v_siz]
  6246 0000E58A 734A                <1> 	jnb	short pix_op_blk_retn ; out of display page
  6247 0000E58C 89C6                <1> 	mov	esi, eax
  6248 0000E58E E8ACF6FFFF          <1> 	call	pixels_to_byte_count
  6249 0000E593 89C7                <1> 	mov	edi, eax
  6250 0000E595 89D0                <1> 	mov	eax, edx  ; size
  6251 0000E597 E8C6F6FFFF          <1> 	call	calc_pixel_offset
  6252                              <1> 	; 22/02/2021
  6253 0000E59C 3B05[9EA30100]      <1> 	cmp	eax, [v_siz]
  6254 0000E5A2 7732                <1> 	ja	short pix_op_blk_retn ; out of display page
  6255 0000E5A4 01C6                <1> 	add	esi, eax
  6256 0000E5A6 3B35[9EA30100]      <1> 	cmp	esi, [v_siz]
  6257 0000E5AC 7728                <1> 	ja	short pix_op_blk_retn ; out of display page
  6258                              <1> 
  6259 0000E5AE 033D[9AA30100]      <1> 	add	edi, [v_mem] ; destination address
  6260                              <1> 
  6261                              <1> 	; 23/01/2021
  6262                              <1> 	;call	pixels_to_byte_count
  6263                              <1> 	;add	edi, eax
  6264                              <1> 	;jc	short pix_op_blk_retn ; out of display page
  6265                              <1> 	;cmp	edi, [v_end]
  6266                              <1> 	;ja	short pix_op_blk_retn ; out of display page
  6267                              <1> 	;sub	edi, eax
  6268                              <1> 
  6269 0000E5B4 E8FCF5FFFF          <1> 	call	sysvideo_15_12 ; window preparations
  6270 0000E5B9 721B                <1> 	jc	short pix_op_blk_retn ; something wrong !?
  6271                              <1> 	; ecx = bytes per row (to be applied)
  6272                              <1> 	; edx = screen width in bytes
  6273                              <1> 	; ebx = row count
  6274                              <1> 
  6275 0000E5BB 8B35[A2A30100]      <1> 	mov	esi, [v_str] ; source address
  6276                              <1> 
  6277                              <1> 	; Note:
  6278                              <1> 	; ecx & edx are already adjusted for pixel sizes
  6279                              <1> 	; so, following code is proper all pixel sizes
  6280                              <1> 
  6281 0000E5C1 29CA                <1> 	sub	edx, ecx ; screen width - window width
  6282                              <1> pix_op_blk_0:
  6283 0000E5C3 89C8                <1> 	mov	eax, ecx
  6284 0000E5C5 0105[74940100]      <1> 	add	[u.r0], eax
  6285 0000E5CB F3A4                <1> 	rep	movsb
  6286 0000E5CD 89C1                <1> 	mov	ecx, eax
  6287 0000E5CF 01D6                <1> 	add	esi, edx ; next row
  6288 0000E5D1 01D7                <1> 	add	edi, edx ; next row
  6289 0000E5D3 4B                  <1> 	dec	ebx
  6290 0000E5D4 75ED                <1> 	jnz	short pix_op_blk_0
  6291                              <1> pix_op_blk_retn:
  6292 0000E5D6 C3                  <1> 	retn
  6293                              <1> 
  6294                              <1> pix_op_blk_u:
  6295                              <1> 	; fill blocks (windows) with desired color
  6296                              <1> 	; according to block definitions in user's buffer
  6297 0000E5D7 81FA00080000        <1> 	cmp	edx, 2048
  6298 0000E5DD 7605                <1> 	jna	short pix_op_blk_u_0
  6299                              <1> 	; Maximum 2048 blocks
  6300 0000E5DF BA00080000          <1> 	mov	edx, 2048
  6301                              <1> pix_op_blk_u_0:
  6302 0000E5E4 8025[98A30100]DF    <1> 	and	byte [v_ops], ~20h ; clear masked bit
  6303 0000E5EB 890D[AAA30100]      <1> 	mov	[maskcolor], ecx ; save pixel color
  6304                              <1> 	; 22/02/2021
  6305                              <1> 	;mov	ebp, edx ; save blocks count
  6306                              <1> 	;push	ebp
  6307                              <1> pix_op_blk_u_next:
  6308 0000E5F1 52                  <1> 	push	edx
  6309                              <1> 	;mov	ecx, 8
  6310                              <1> 	; 11/08/2022
  6311 0000E5F2 29C9                <1> 	sub	ecx, ecx
  6312 0000E5F4 B108                <1> 	mov	cl, 8
  6313 0000E5F6 BF[B2A30100]        <1> 	mov	edi, buffer8 ; 8 bytes small buffer
  6314                              <1> 	; esi = user's buffer address
  6315 0000E5FB E8DA290000          <1> 	call	transfer_from_user_buffer
  6316 0000E600 72D4                <1> 	jc	short pix_op_blk_retn
  6317 0000E602 01CE                <1> 	add	esi, ecx ; 22/02/2021
  6318 0000E604 56                  <1> 	push	esi
  6319 0000E605 8B15[B2A30100]      <1> 	mov	edx, [buffer8] ; block start pos (row,col)
  6320 0000E60B 8B35[B6A30100]      <1> 	mov	esi, [buffer8+4] ; block size (rows,cols)
  6321 0000E611 8B0D[AAA30100]      <1> 	mov	ecx, [maskcolor]
  6322 0000E617 E849FCFFFF          <1> 	call	pix_op_new_w ; new (change) color (window)
  6323 0000E61C 5E                  <1> 	pop	esi
  6324                              <1> 	;pop	ebp
  6325                              <1> 	;dec	ebp
  6326 0000E61D 5A                  <1> 	pop	edx
  6327 0000E61E 4A                  <1> 	dec	edx
  6328 0000E61F 75D0                <1> 	jnz	short pix_op_blk_u_next
  6329 0000E621 C3                  <1> 	retn
  6330                              <1> 
  6331                              <1> pix_op_lin:
  6332                              <1> 	; 11/08/2022
  6333                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
  6334                              <1> 	; 12/02/2021
  6335                              <1> 	; 11/02/2021
  6336                              <1> 	; 10/02/2021
  6337                              <1> 	; 05/02/2021
  6338                              <1> 	; 02/02/2021
  6339                              <1> 	; WRITE LINE -direct-
  6340                              <1> 	; WRITE LINE(S) -via user's buffer-
  6341                              <1> 	;
  6342                              <1> 	; INPUT:
  6343                              <1> 	;   -If BL bit 5 is 0-	
  6344                              <1> 	;     CL = color (8 bit, 256 colors)
  6345                              <1> 	;    ECX = color (16 bit and true colors)
  6346                              <1> 	;     DX = low 12 bits - size (length)
  6347                              <1> 	;	   high 4 bits - direction or type
  6348                              <1> 	;	     0 - Horizontal line
  6349                              <1> 	;	     1 - Vertical line
  6350                              <1> 	;	   > 1 - undefined, invalid
  6351                              <1> 	;    ESI = start position (row, column)
  6352                              <1> 	;	  (HW = row, SI = column)
  6353                              <1> 	;   -If BL bit 5 is 1-
  6354                              <1> 	;     CL = color (8 bit, 256 colors)
  6355                              <1> 	;    ECX = color (16 bit and true colors)
  6356                              <1> 	;     DX = number of lines (in user buffer)
  6357                              <1> 	;	   (limit: 2048 lines)	
  6358                              <1> 	;    ESI = user's buffer
  6359                              <1> 	;          contains 64 bit data for lines
  6360                              <1> 	;	   START POINT: 32 bit (row, col)
  6361                              <1> 	;	   LENGTH: 32 bit
  6362                              <1> 	;		   high 16 bits - 0
  6363                              <1> 	;		   bit 0-11 - length
  6364                              <1> 	;	   	   bit 12-15 - type (length)
  6365                              <1> 	; OUTPUT:
  6366                              <1> 	; 	[u.r0] will be > 0 if succesful
  6367                              <1> 
  6368                              <1> 	; Window option ([v_ops] bit 4) will be ignored
  6369                              <1> 	; (Function is used for display page coordinates)
  6370                              <1> 
  6371                              <1> 	; 10/02/2021
  6372 0000E622 F605[98A30100]20    <1> 	test	byte [v_ops], 20h ; masked or direct ?
  6373 0000E629 7444                <1> 	jz	short pix_op_lin_vh ; direct (v/h lines)
  6374                              <1> 
  6375                              <1> 	; lines from user's buffer
  6376                              <1> pix_op_lin_u:
  6377                              <1> 	; draw lines with desired color
  6378                              <1> 	; according to line definitions in user's buffer
  6379 0000E62B 81FA00080000        <1> 	cmp	edx, 2048
  6380 0000E631 7605                <1> 	jna	short pix_op_lin_u_0
  6381                              <1> 	; Maximum 2048 lines
  6382 0000E633 BA00080000          <1> 	mov	edx, 2048
  6383                              <1> pix_op_lin_u_0:
  6384 0000E638 890D[AAA30100]      <1> 	mov	[maskcolor], ecx ; save pixel color
  6385 0000E63E 89D5                <1> 	mov	ebp, edx ; save line count
  6386                              <1> pix_op_lin_u_next:
  6387                              <1> 	;mov	ecx, 8
  6388                              <1> 	; 11/08/2022
  6389 0000E640 29C9                <1> 	sub	ecx, ecx
  6390 0000E642 B108                <1> 	mov	cl, 8
  6391 0000E644 BF[B2A30100]        <1> 	mov	edi, buffer8 ; 8 bytes small buffer
  6392                              <1> 	; esi = user's buffer address
  6393 0000E649 E88C290000          <1> 	call	transfer_from_user_buffer
  6394 0000E64E 721E                <1> 	jc	short pix_op_lin_retn
  6395 0000E650 01CE                <1> 	add	esi, ecx ; 11/02/2021
  6396 0000E652 56                  <1> 	push	esi
  6397 0000E653 8B35[B2A30100]      <1> 	mov	esi, [buffer8] ; line start pos (row,col)
  6398 0000E659 8B15[B6A30100]      <1> 	mov	edx, [buffer8+4] ; line length
  6399 0000E65F 8B0D[AAA30100]      <1> 	mov	ecx, [maskcolor]
  6400 0000E665 E805000000          <1> 	call	pix_op_lin_vh ; new (change) color (window)
  6401 0000E66A 5E                  <1> 	pop	esi
  6402 0000E66B 4D                  <1> 	dec	ebp
  6403 0000E66C 75D2                <1> 	jnz	short pix_op_lin_u_next
  6404                              <1> pix_op_lin_retn:
  6405 0000E66E C3                  <1> 	retn
  6406                              <1> 
  6407                              <1> pix_op_lin_vh:
  6408 0000E66F 81FA38140000        <1> 	cmp	edx, 1438h ; 1920*1080 (780hx438h) limit
  6409 0000E675 7762                <1> 	ja	short pix_op_lin_err1 ; invalid type 
  6410                              <1> 			    	; (for current version)
  6411 0000E677 66F7C2FF0F          <1> 	test	dx, 0FFFh
  6412 0000E67C 745B                <1> 	jz	short pix_op_lin_err1 ; zero length!
  6413                              <1> 
  6414 0000E67E 89F0                <1> 	mov	eax, esi ; start point (row, col)
  6415 0000E680 E8DDF5FFFF          <1> 	call	calc_pixel_offset
  6416 0000E685 3B05[9EA30100]      <1> 	cmp	eax, [v_siz]
  6417 0000E68B 734C                <1> 	jnb	short pix_op_lin_err1 ; out of display page!
  6418 0000E68D E8ADF5FFFF          <1> 	call	pixels_to_byte_count
  6419 0000E692 89C7                <1> 	mov	edi, eax ; start point offset
  6420 0000E694 033D[9AA30100]      <1> 	add	edi, [v_mem] ; LFB start address
  6421 0000E69A 89C8                <1> 	mov	eax, ecx ; color
  6422                              <1> 
  6423 0000E69C F6C610              <1> 	test	dh, 10h
  6424                              <1> 	;jz	pix_op_lin_h ; Horizontal line
  6425                              <1> 	; 23/07/2022
  6426 0000E69F 7505                <1> 	jnz	short pix_op_lin_v
  6427 0000E6A1 E98A000000          <1> 	jmp	pix_op_lin_h
  6428                              <1> 
  6429                              <1> pix_op_lin_v:
  6430                              <1> 	; Vertical line
  6431 0000E6A6 80E60F              <1> 	and 	dh, 0Fh ; low 12 bits
  6432 0000E6A9 51                  <1> 	push	ecx ; color
  6433 0000E6AA 89D1                <1> 	mov	ecx, edx
  6434 0000E6AC 0FB705[96A30100]    <1> 	movzx	eax, word [v_width]
  6435 0000E6B3 89C3                <1> 	mov	ebx, eax
  6436                              <1> 	; 12/02/2021
  6437 0000E6B5 F7E2                <1> 	mul	edx ; rows * [v_width]
  6438 0000E6B7 01F8                <1> 	add	eax, edi
  6439 0000E6B9 3B05[A6A30100]      <1> 	cmp	eax, [v_end]
  6440 0000E6BF 58                  <1> 	pop	eax ; color
  6441 0000E6C0 7717                <1> 	ja	short pix_op_lin_err1 ; out of display page
  6442                              <1> 	; ecx = rows	
  6443 0000E6C2 89CA                <1> 	mov	edx, ecx
  6444                              <1> 
  6445 0000E6C4 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  6446 0000E6CB 770D                <1> 	ja	short pix_op_lin_v_2
  6447                              <1> 	; 256 colors (1 byte per pixel)
  6448 0000E6CD 010D[74940100]      <1> 	add	[u.r0], ecx ; byte count
  6449                              <1> pix_op_lin_v_1:
  6450 0000E6D3 8807                <1> 	mov	[edi], al
  6451 0000E6D5 01DF                <1> 	add	edi, ebx  ; next row
  6452 0000E6D7 E2FA                <1> 	loop	pix_op_lin_v_1
  6453                              <1> pix_op_lin_err1:
  6454 0000E6D9 C3                  <1> 	retn
  6455                              <1> 
  6456                              <1> pix_op_lin_v_2:
  6457 0000E6DA 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  6458 0000E6E1 773A                <1> 	ja	short pix_op_lin_v_6 ; 32bpp
  6459 0000E6E3 7226                <1> 	jb	short pix_op_lin_v_4 ; 16bpp
  6460                              <1> 
  6461                              <1> 	; 24 bit true colors
  6462                              <1> 	; * 3
  6463 0000E6E5 53                  <1> 	push	ebx ; screen width in pixels
  6464 0000E6E6 D1E3                <1> 	shl	ebx, 1
  6465 0000E6E8 011C24              <1> 	add	[esp], ebx
  6466 0000E6EB 5B                  <1> 	pop	ebx ; screen width in bytes
  6467 0000E6EC 010D[74940100]      <1> 	add	[u.r0], ecx
  6468 0000E6F2 D1E2                <1> 	shl	edx, 1
  6469 0000E6F4 0115[74940100]      <1> 	add	[u.r0], edx ; byte count
  6470                              <1> pix_op_lin_v_3:
  6471 0000E6FA 668907              <1> 	mov	[edi], ax
  6472 0000E6FD C1C810              <1> 	ror	eax, 16
  6473 0000E700 884702              <1> 	mov	[edi+2], al
  6474 0000E703 C1C010              <1> 	rol	eax, 16
  6475 0000E706 01DF                <1> 	add	edi, ebx  ; next row
  6476 0000E708 E2F0                <1> 	loop	pix_op_lin_v_3
  6477 0000E70A C3                  <1> 	retn
  6478                              <1> 
  6479                              <1> pix_op_lin_v_4:
  6480                              <1> 	; 16 bit (65536) colors
  6481 0000E70B D1E3                <1> 	shl	ebx, 1
  6482 0000E70D D1E2                <1> 	shl	edx, 1
  6483 0000E70F 0115[74940100]      <1> 	add	[u.r0], edx
  6484                              <1> pix_op_lin_v_5:
  6485 0000E715 668907              <1> 	mov	[edi], ax
  6486 0000E718 01DF                <1> 	add	edi, ebx  ; next row
  6487 0000E71A E2F9                <1> 	loop	pix_op_lin_v_5
  6488 0000E71C C3                  <1> 	retn
  6489                              <1> 
  6490                              <1> pix_op_lin_v_6:
  6491                              <1> 	; 32 bit true colors
  6492 0000E71D C1E302              <1> 	shl	ebx, 2
  6493 0000E720 C1E202              <1> 	shl	edx, 2
  6494 0000E723 0115[74940100]      <1> 	add	[u.r0], edx ; byte count
  6495                              <1> pix_op_lin_v_7:
  6496 0000E729 8907                <1> 	mov	[edi], eax
  6497 0000E72B 01DF                <1> 	add	edi, ebx  ; next row
  6498 0000E72D E2FA                <1> 	loop	pix_op_lin_v_7
  6499 0000E72F C3                  <1> 	retn
  6500                              <1> 
  6501                              <1> pix_op_lin_h:
  6502                              <1> 	; Horizontal line
  6503 0000E730 80E60F              <1> 	and 	dh, 0Fh ; low 12 bits
  6504 0000E733 89D1                <1>   	mov	ecx, edx
  6505 0000E735 6601D6              <1> 	add	si, dx ; start column + columns
  6506 0000E738 663B35[96A30100]    <1> 	cmp	si, [v_width] ; screen width
  6507 0000E73F 7711                <1> 	ja	short pix_op_lin_err2 ; out of columns limit
  6508                              <1> 
  6509 0000E741 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  6510 0000E748 7709                <1> 	ja	short pix_op_lin_h_1
  6511                              <1> 	; 256 colors (1 byte per pixel)
  6512 0000E74A 010D[74940100]      <1> 	add	[u.r0], ecx
  6513 0000E750 F3AA                <1> 	rep	stosb
  6514                              <1> pix_op_lin_err2:
  6515 0000E752 C3                  <1> 	retn
  6516                              <1> 
  6517                              <1> pix_op_lin_h_1:
  6518 0000E753 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  6519 0000E75A 7728                <1> 	ja	short pix_op_lin_h_4 ; 32bpp
  6520 0000E75C 721A                <1> 	jb	short pix_op_lin_h_3 ; 16bpp
  6521                              <1> 	
  6522                              <1> 	; 24 bit true colors
  6523                              <1> 	; * 3
  6524 0000E75E 0115[74940100]      <1> 	add	[u.r0], edx
  6525 0000E764 D1E2                <1> 	shl	edx, 1
  6526 0000E766 0115[74940100]      <1> 	add	[u.r0], edx
  6527                              <1> pix_op_lin_h_2:
  6528 0000E76C 66AB                <1> 	stosw
  6529 0000E76E C1C810              <1> 	ror	eax, 16
  6530 0000E771 AA                  <1> 	stosb	
  6531 0000E772 C1C010              <1> 	rol	eax, 16
  6532 0000E775 E2F5                <1> 	loop	pix_op_lin_h_2
  6533 0000E777 C3                  <1> 	retn
  6534                              <1> 
  6535                              <1> pix_op_lin_h_3:
  6536                              <1> 	; 16 bit (65536) colors
  6537 0000E778 D1E2                <1> 	shl	edx, 1
  6538 0000E77A 0115[74940100]      <1> 	add	[u.r0], edx
  6539 0000E780 F366AB              <1> 	rep	stosw
  6540 0000E783 C3                  <1> 	retn
  6541                              <1> 
  6542                              <1> pix_op_lin_h_4:
  6543                              <1> 	; 32 bit true colors
  6544 0000E784 C1E202              <1> 	shl	edx, 2
  6545 0000E787 0115[74940100]      <1> 	add	[u.r0], edx
  6546 0000E78D F3AB                <1> 	rep	stosd
  6547 0000E78F C3                  <1> 	retn
  6548                              <1> 
  6549                              <1> pix_op_new_8:
  6550                              <1> 	; 8 bit colors (256 colors)
  6551                              <1> 	; CHANGE PIXEL COLOR
  6552                              <1> 	; ecx = pixel count per row
  6553                              <1> 	;  al = color
  6554                              <1> 	; edi = start pixel address
  6555                              <1> 
  6556 0000E790 F3AA                <1> 	rep	stosb
  6557 0000E792 C3                  <1> 	retn
  6558                              <1> 
  6559                              <1> pix_op_new_16:
  6560                              <1> 	; 16 bit colors (65536 colors)
  6561                              <1> 	; CHANGE PIXEL COLOR
  6562                              <1> 	; ecx = pixel count per row
  6563                              <1> 	;  ax = color
  6564                              <1> 	; edi = start pixel address
  6565                              <1> 
  6566 0000E793 F366AB              <1> 	rep	stosw
  6567 0000E796 C3                  <1> 	retn
  6568                              <1> 
  6569                              <1> pix_op_new_24:
  6570                              <1> 	; 24 bit true colors
  6571                              <1> 	; CHANGE PIXEL COLOR
  6572                              <1> 	; ecx = pixel count per row
  6573                              <1> 	; eax = color
  6574                              <1> 	; edi = start pixel address
  6575                              <1> 
  6576 0000E797 66AB                <1> 	stosw
  6577 0000E799 C1C810              <1> 	ror	eax, 16	
  6578 0000E79C AA                  <1> 	stosb
  6579 0000E79D C1C010              <1> 	rol	eax, 16
  6580 0000E7A0 E2F5                <1> 	loop	pix_op_new_24
  6581 0000E7A2 C3                  <1> 	retn
  6582                              <1> 
  6583                              <1> pix_op_new_32:
  6584                              <1> 	; 32 bit true colors
  6585                              <1> 	; CHANGE PIXEL COLOR
  6586                              <1> 	; ecx = pixel count per row
  6587                              <1> 	; eax = color
  6588                              <1> 	; edi = start pixel address 
  6589                              <1> 
  6590 0000E7A3 F3AB                <1> 	rep	stosd
  6591 0000E7A5 C3                  <1> 	retn
  6592                              <1> 
  6593                              <1> pix_op_add_8:
  6594                              <1> 	; 8 bit colors (256 colors)
  6595                              <1> 	; ADD PIXEL COLOR
  6596                              <1> 	; ecx = pixel count per row
  6597                              <1> 	;  al = color
  6598                              <1> 	; edi = start pixel address
  6599                              <1> 
  6600 0000E7A6 88C4                <1> 	mov	ah, al
  6601                              <1> pix_op_add_8_0:
  6602 0000E7A8 0207                <1> 	add	al, [edi]
  6603 0000E7AA 7302                <1> 	jnc	short pix_op_add_8_1
  6604 0000E7AC B0FF                <1> 	mov	al, 0FFh ; Max. value
  6605                              <1> pix_op_add_8_1:
  6606 0000E7AE AA                  <1> 	stosb
  6607 0000E7AF 88E0                <1> 	mov	al, ah
  6608 0000E7B1 E2F5                <1> 	loop	pix_op_add_8_0
  6609 0000E7B3 C3                  <1> 	retn
  6610                              <1> 
  6611                              <1> pix_op_add_16:
  6612                              <1> 	; 16 bit colors (65536 colors)
  6613                              <1> 	; ADD PIXEL COLOR
  6614                              <1> 	; ecx = pixel count per row
  6615                              <1> 	;  ax = color
  6616                              <1> 	; edi = start pixel address
  6617                              <1> 
  6618 0000E7B4 89C2                <1> 	mov	edx, eax
  6619                              <1> pix_op_add_16_0:
  6620 0000E7B6 660307              <1> 	add	ax, [edi]
  6621 0000E7B9 7304                <1> 	jnc	short pix_op_add_16_1
  6622 0000E7BB 66B8FFFF            <1> 	mov	ax, 0FFFFh ; Max. value
  6623                              <1> pix_op_add_16_1:
  6624 0000E7BF 66AB                <1> 	stosw
  6625 0000E7C1 89D0                <1> 	mov	eax, edx
  6626 0000E7C3 E2F1                <1> 	loop	pix_op_add_16_0
  6627 0000E7C5 C3                  <1> 	retn
  6628                              <1> 
  6629                              <1> pix_op_add_24:
  6630                              <1> 	; 24 bit true colors
  6631                              <1> 	; ADD PIXEL COLOR
  6632                              <1> 	; ecx = pixel count per row
  6633                              <1> 	; eax = color
  6634                              <1> 	; edi = start pixel address
  6635                              <1> 
  6636 0000E7C6 53                  <1> 	push	ebx
  6637 0000E7C7 BBFFFFFF00          <1> 	mov	ebx, 0FFFFFFh
  6638                              <1> 	;and	eax, ebx ; 0FFFFFFh
  6639 0000E7CC 89C2                <1> 	mov	edx, eax
  6640                              <1> pix_op_add_24_0:
  6641 0000E7CE 8B07                <1> 	mov	eax, [edi]
  6642 0000E7D0 21D8                <1> 	and	eax, ebx ; 0FFFFFFh
  6643 0000E7D2 01D0                <1> 	add	eax, edx
  6644 0000E7D4 39D8                <1> 	cmp	eax, ebx
  6645 0000E7D6 7602                <1> 	jna	short pix_op_add_24_1
  6646 0000E7D8 89D8                <1> 	mov	eax, ebx ; 0FFFFFFh  ; Max. value
  6647                              <1> pix_op_add_24_1:
  6648 0000E7DA 66AB                <1> 	stosw
  6649 0000E7DC C1E810              <1> 	shr	eax, 16
  6650 0000E7DF AA                  <1> 	stosb
  6651 0000E7E0 E2EC                <1> 	loop	pix_op_add_24_0
  6652 0000E7E2 89D0                <1> 	mov	eax, edx
  6653 0000E7E4 5B                  <1> 	pop	ebx
  6654 0000E7E5 C3                  <1> 	retn
  6655                              <1> 
  6656                              <1> pix_op_add_32:
  6657                              <1> 	; 32 bit true colors
  6658                              <1> 	; ADD PIXEL COLOR
  6659                              <1> 	; ecx = pixel count per row
  6660                              <1> 	; eax = color
  6661                              <1> 	; edi = start pixel address
  6662                              <1> 
  6663 0000E7E6 89C2                <1> 	mov	edx, eax
  6664                              <1> pix_op_add_32_0:
  6665 0000E7E8 0307                <1> 	add	eax, [edi]
  6666 0000E7EA 7303                <1> 	jnc	short pix_op_add_32_1
  6667                              <1> 	;mov	eax, 0FFFFFFFFh ; Max. value
  6668 0000E7EC 29C0                <1> 	sub	eax, eax
  6669 0000E7EE 48                  <1> 	dec	eax
  6670                              <1> pix_op_add_32_1:
  6671 0000E7EF AB                  <1> 	stosd
  6672 0000E7F0 89D0                <1> 	mov	eax, edx
  6673 0000E7F2 E2F4                <1> 	loop	pix_op_add_32_0
  6674 0000E7F4 C3                  <1> 	retn
  6675                              <1> 
  6676                              <1> pix_op_sub_8:
  6677                              <1> 	; 8 bit colors (256 colors)
  6678                              <1> 	; SUBTRACT PIXEL COLOR
  6679                              <1> 	; ecx = pixel count per row
  6680                              <1> 	;  al = color
  6681                              <1> 	; edi = start pixel address 
  6682                              <1> 
  6683 0000E7F5 88C4                <1> 	mov	ah, al
  6684                              <1> pix_op_sub_8_0:
  6685 0000E7F7 8A07                <1> 	mov	al, [edi]
  6686 0000E7F9 28E0                <1> 	sub	al, ah
  6687 0000E7FB 7302                <1> 	jnb	short pix_op_sub_8_1
  6688 0000E7FD 30C0                <1> 	xor	al, al ; 0 ; Min. value
  6689                              <1> pix_op_sub_8_1:
  6690 0000E7FF AA                  <1> 	stosb
  6691 0000E800 E2F5                <1> 	loop	pix_op_sub_8_0
  6692 0000E802 88E0                <1> 	mov	al, ah
  6693 0000E804 C3                  <1> 	retn
  6694                              <1> 
  6695                              <1> pix_op_sub_16:
  6696                              <1> 	; 16 bit colors (65536 colors)
  6697                              <1> 	; SUBTRACT PIXEL COLOR
  6698                              <1> 	; ecx = pixel count per row
  6699                              <1> 	;  ax = color
  6700                              <1> 	; edi = start pixel address
  6701                              <1> 
  6702 0000E805 89C2                <1> 	mov	edx, eax
  6703                              <1> pix_op_sub_16_0:
  6704 0000E807 668B07              <1> 	mov	ax, [edi]
  6705 0000E80A 6629D0              <1> 	sub	ax, dx
  6706 0000E80D 7302                <1> 	jnb	short pix_op_sub_16_1
  6707 0000E80F 31C0                <1> 	xor	eax, eax ; 0 ; Min. value
  6708                              <1> pix_op_sub_16_1:
  6709 0000E811 66AB                <1> 	stosw
  6710 0000E813 E2F2                <1> 	loop	pix_op_sub_16_0
  6711 0000E815 89D0                <1> 	mov	eax, edx
  6712 0000E817 C3                  <1> 	retn
  6713                              <1> 
  6714                              <1> pix_op_sub_24:
  6715                              <1> 	; 24 bit true colors
  6716                              <1> 	; SUBTRACT PIXEL COLOR
  6717                              <1> 	; ecx = pixel count per row
  6718                              <1> 	; eax = color
  6719                              <1> 	; edi = start pixel address
  6720                              <1> 
  6721                              <1> 	;and	eax, 0FFFFFFh
  6722 0000E818 89C2                <1> 	mov	edx, eax
  6723                              <1> pix_op_sub_24_0:
  6724 0000E81A 8B07                <1> 	mov	eax, [edi]
  6725                              <1> 	; 27/02/2021
  6726 0000E81C 25FFFFFF00          <1> 	and	eax, 0FFFFFFh
  6727 0000E821 29D0                <1> 	sub	eax, edx
  6728 0000E823 7302                <1> 	jnb	short pix_op_sub_24_1
  6729 0000E825 31C0                <1> 	xor	eax, eax ; 0 ; Min. value
  6730                              <1> pix_op_sub_24_1: 
  6731 0000E827 66AB                <1> 	stosw
  6732 0000E829 C1E810              <1> 	shr	eax, 16
  6733 0000E82C AA                  <1> 	stosb
  6734 0000E82D E2EB                <1> 	loop	pix_op_sub_24_0
  6735 0000E82F 89D0                <1> 	mov	eax, edx
  6736 0000E831 C3                  <1> 	retn
  6737                              <1> 
  6738                              <1> pix_op_sub_32:
  6739                              <1> 	; 32 bit true colors
  6740                              <1> 	; SUBTRACT PIXEL COLOR
  6741                              <1> 	; ecx = pixel count per row
  6742                              <1> 	; eax = color
  6743                              <1> 	; edi = start pixel address
  6744                              <1> 
  6745 0000E832 89C2                <1> 	mov	edx, eax
  6746                              <1> pix_op_sub_32_0:
  6747 0000E834 8B07                <1> 	mov	eax, [edi]
  6748 0000E836 29D0                <1> 	sub	eax, edx
  6749 0000E838 7302                <1> 	jnb	short pix_op_sub_32_1
  6750 0000E83A 31C0                <1> 	xor	eax, eax ; 0 ; Min. value
  6751                              <1> pix_op_sub_32_1:
  6752 0000E83C AB                  <1> 	stosd
  6753 0000E83D E2F5                <1> 	loop	pix_op_sub_32_0
  6754 0000E83F 89D0                <1> 	mov	eax, edx
  6755 0000E841 C3                  <1> 	retn
  6756                              <1> 
  6757                              <1> pix_op_or_8:
  6758                              <1> 	; 8 bit colors (256 colors)
  6759                              <1> 	; OR PIXEL COLOR
  6760                              <1> 	; ecx = pixel count per row
  6761                              <1> 	;  al = color
  6762                              <1> 	; edi = start pixel address
  6763                              <1> 
  6764                              <1> pix_op_or_8_0:
  6765 0000E842 0807                <1> 	or	[edi], al
  6766 0000E844 47                  <1> 	inc	edi
  6767 0000E845 E2FB                <1> 	loop	pix_op_or_8_0
  6768 0000E847 C3                  <1> 	retn
  6769                              <1> 
  6770                              <1> pix_op_or_16:
  6771                              <1> 	; 16 bit colors (65536 colors)
  6772                              <1> 	; OR PIXEL COLOR
  6773                              <1> 	; ecx = pixel count per row
  6774                              <1> 	;  ax = color
  6775                              <1> 	; edi = start pixel address 
  6776                              <1> 
  6777                              <1> pix_op_or_16_0:
  6778 0000E848 660907              <1> 	or	[edi], ax
  6779 0000E84B 47                  <1> 	inc	edi
  6780 0000E84C 47                  <1> 	inc	edi
  6781 0000E84D E2F9                <1> 	loop	pix_op_or_16_0
  6782 0000E84F C3                  <1> 	retn
  6783                              <1> 
  6784                              <1> pix_op_or_24:
  6785                              <1> 	; 24 bit true colors
  6786                              <1> 	; OR PIXEL COLOR
  6787                              <1> 	; ecx = pixel count per row
  6788                              <1> 	; eax = color
  6789                              <1> 	; edi = start pixel address
  6790                              <1> 
  6791 0000E850 89C2                <1> 	mov	edx, eax
  6792                              <1> pix_op_or_24_0:
  6793 0000E852 0B07                <1> 	or	eax, [edi]
  6794 0000E854 66AB                <1> 	stosw
  6795 0000E856 C1E810              <1> 	shr	eax, 16
  6796 0000E859 AA                  <1> 	stosb	
  6797 0000E85A 89D0                <1> 	mov	eax, edx
  6798 0000E85C E2F4                <1> 	loop	pix_op_or_24_0
  6799 0000E85E C3                  <1> 	retn
  6800                              <1> 
  6801                              <1> pix_op_or_32:
  6802                              <1> 	; 32 bit true colors
  6803                              <1> 	; OR PIXEL COLOR
  6804                              <1> 	; ecx = pixel count per row
  6805                              <1> 	; eax = color
  6806                              <1> 	; edi = start pixel address
  6807                              <1> 
  6808                              <1> 	;mov	edx, eax
  6809                              <1> pix_op_or_32_0:
  6810                              <1> 	;or	eax, [edi]
  6811                              <1> 	;stosd
  6812                              <1> 	;mov	eax, edx
  6813 0000E85F 0907                <1> 	or	[edi], eax
  6814 0000E861 83C704              <1> 	add	edi, 4
  6815 0000E864 E2F9                <1> 	loop	pix_op_or_32_0
  6816 0000E866 C3                  <1> 	retn
  6817                              <1> 
  6818                              <1> pix_op_and_8:
  6819                              <1> 	; 8 bit colors (256 colors)
  6820                              <1> 	; AND PIXEL COLOR
  6821                              <1> 	; ecx = pixel count per row
  6822                              <1> 	;  al = color
  6823                              <1> 	; edi = start pixel address
  6824                              <1> 
  6825                              <1> pix_op_and_8_0:
  6826 0000E867 2007                <1> 	and	[edi], al
  6827 0000E869 47                  <1> 	inc	edi
  6828 0000E86A E2FB                <1> 	loop	pix_op_and_8_0
  6829 0000E86C C3                  <1> 	retn
  6830                              <1> 
  6831                              <1> pix_op_and_16:
  6832                              <1> 	; 16 bit colors (65536 colors)
  6833                              <1> 	; AND PIXEL COLOR
  6834                              <1> 	; ecx = pixel count per row
  6835                              <1> 	;  ax = color
  6836                              <1> 	; edi = start pixel address
  6837                              <1> 
  6838                              <1> pix_op_and_16_0:
  6839 0000E86D 662107              <1> 	and	[edi], ax
  6840 0000E870 47                  <1> 	inc	edi
  6841 0000E871 47                  <1> 	inc	edi
  6842 0000E872 E2F9                <1> 	loop	pix_op_and_16_0
  6843 0000E874 C3                  <1> 	retn
  6844                              <1> 
  6845                              <1> pix_op_and_24:
  6846                              <1> 	; 24 bit true colors
  6847                              <1> 	; AND PIXEL COLOR
  6848                              <1> 	; ecx = pixel count per row
  6849                              <1> 	; eax = color
  6850                              <1> 	; edi = start pixel address
  6851                              <1> 
  6852 0000E875 89C2                <1> 	mov	edx, eax
  6853                              <1> pix_op_and_24_0:
  6854 0000E877 2307                <1> 	and	eax, [edi]
  6855 0000E879 66AB                <1> 	stosw
  6856 0000E87B C1E810              <1> 	shr	eax, 16
  6857 0000E87E AA                  <1> 	stosb	
  6858 0000E87F 89D0                <1> 	mov	eax, edx
  6859 0000E881 E2F4                <1> 	loop	pix_op_and_24_0
  6860 0000E883 C3                  <1> 	retn
  6861                              <1> 
  6862                              <1> pix_op_and_32:
  6863                              <1> 	; 32 bit true colors
  6864                              <1> 	; AND PIXEL COLOR
  6865                              <1> 	; ecx = pixel count per row
  6866                              <1> 	; eax = color
  6867                              <1> 	; edi = start pixel address
  6868                              <1> 
  6869                              <1> 	;mov	edx, eax
  6870                              <1> pix_op_and_32_0:
  6871                              <1> 	;and	eax, [edi]
  6872                              <1> 	;stosd
  6873                              <1> 	;mov	eax, edx
  6874 0000E884 2107                <1> 	and	[edi], eax
  6875 0000E886 83C704              <1> 	add	edi, 4
  6876 0000E889 E2F9                <1> 	loop	pix_op_and_32_0
  6877 0000E88B C3                  <1> 	retn
  6878                              <1> 
  6879                              <1> pix_op_xor_8:
  6880                              <1> 	; 8 bit colors (256 colors)
  6881                              <1> 	; XOR PIXEL COLOR
  6882                              <1> 	; ecx = pixel count per row
  6883                              <1> 	;  al = color
  6884                              <1> 	; edi = start pixel address
  6885                              <1> 
  6886                              <1> pix_op_xor_8_0:
  6887 0000E88C 3007                <1> 	xor	[edi], al
  6888 0000E88E 47                  <1> 	inc	edi
  6889 0000E88F E2FB                <1> 	loop	pix_op_xor_8_0
  6890 0000E891 C3                  <1> 	retn
  6891                              <1> 
  6892                              <1> pix_op_xor_16:
  6893                              <1> 	; 16 bit colors (65536 colors)
  6894                              <1> 	; XOR PIXEL COLOR
  6895                              <1> 	; ecx = pixel count per row
  6896                              <1> 	;  ax = color
  6897                              <1> 	; edi = start pixel address
  6898                              <1> 
  6899                              <1> pix_op_xor_16_0:
  6900 0000E892 663107              <1> 	xor	[edi], ax
  6901 0000E895 47                  <1> 	inc	edi
  6902 0000E896 47                  <1> 	inc	edi
  6903 0000E897 E2F9                <1> 	loop	pix_op_xor_16_0
  6904 0000E899 C3                  <1> 	retn
  6905                              <1> 
  6906                              <1> pix_op_xor_24:
  6907                              <1> 	; 24 bit true colors
  6908                              <1> 	; XOR PIXEL COLOR
  6909                              <1> 	; ecx = pixel count per row
  6910                              <1> 	; eax = color
  6911                              <1> 	; edi = start pixel address
  6912                              <1> 
  6913 0000E89A 89C2                <1> 	mov	edx, eax
  6914                              <1> pix_op_xor_24_0:
  6915 0000E89C 3307                <1> 	xor	eax, [edi]
  6916 0000E89E 66AB                <1> 	stosw
  6917 0000E8A0 C1E810              <1> 	shr	eax, 16
  6918 0000E8A3 AA                  <1> 	stosb	
  6919 0000E8A4 89D0                <1> 	mov	eax, edx
  6920 0000E8A6 E2F4                <1> 	loop	pix_op_xor_24_0
  6921 0000E8A8 C3                  <1> 	retn
  6922                              <1> 
  6923                              <1> pix_op_xor_32:
  6924                              <1> 	; 32 bit true colors
  6925                              <1> 	; XOR PIXEL COLOR
  6926                              <1> 	; ecx = pixel count per row
  6927                              <1> 	; eax = color
  6928                              <1> 	; edi = start pixel address
  6929                              <1> 
  6930                              <1> 	;mov	edx, eax
  6931                              <1> pix_op_xor_32_0:
  6932                              <1> 	;xor	eax, [edi]
  6933                              <1> 	;stosd
  6934                              <1> 	;mov	eax, edx
  6935 0000E8A9 3107                <1> 	xor	[edi], eax
  6936 0000E8AB 83C704              <1> 	add	edi, 4
  6937 0000E8AE E2F9                <1> 	loop	pix_op_xor_32_0
  6938 0000E8B0 C3                  <1> 	retn
  6939                              <1> 
  6940                              <1> pix_op_mix_8:
  6941                              <1> 	; 8 bit colors (256 colors)
  6942                              <1> 	; MIX (AVERAGE) PIXEL COLORS
  6943                              <1> 	; ecx = pixel count per row
  6944                              <1> 	;  al = color
  6945                              <1> 	; edi = start pixel address
  6946                              <1> 
  6947 0000E8B1 88C4                <1> 	mov	ah, al
  6948                              <1> pix_op_mix_8_0:
  6949 0000E8B3 0207                <1> 	add	al, [edi]
  6950 0000E8B5 D0D8                <1> 	rcr	al, 1
  6951 0000E8B7 AA                  <1> 	stosb
  6952 0000E8B8 88E0                <1> 	mov	al, ah
  6953 0000E8BA E2F7                <1> 	loop	pix_op_mix_8_0
  6954 0000E8BC C3                  <1> 	retn
  6955                              <1> 
  6956                              <1> pix_op_mix_16:
  6957                              <1> 	; 16 bit colors (65536 colors)
  6958                              <1> 	; MIX (AVERAGE) PIXEL COLORS
  6959                              <1> 	; ecx = pixel count per row
  6960                              <1> 	;  ax = color
  6961                              <1> 	; edi = start pixel address
  6962                              <1> 
  6963 0000E8BD 89C2                <1> 	mov	edx, eax
  6964                              <1> pix_op_mix_16_0:
  6965 0000E8BF 660307              <1> 	add	ax, [edi]
  6966 0000E8C2 66D1D8              <1> 	rcr	ax, 1
  6967 0000E8C5 66AB                <1> 	stosw
  6968 0000E8C7 89D0                <1> 	mov	eax, edx
  6969 0000E8C9 E2F4                <1> 	loop	pix_op_mix_16_0
  6970 0000E8CB C3                  <1> 	retn
  6971                              <1> 
  6972                              <1> pix_op_mix_24:
  6973                              <1> 	; 24 bit true colors
  6974                              <1> 	; MIX (AVERAGE) PIXEL COLORS
  6975                              <1> 	; ecx = pixel count per row
  6976                              <1> 	; eax = color
  6977                              <1> 	; edi = start pixel address
  6978                              <1> 
  6979 0000E8CC 53                  <1> 	push	ebx
  6980 0000E8CD BBFFFFFF00          <1> 	mov	ebx, 0FFFFFFh
  6981                              <1> 	;and	eax, ebx ; 0FFFFFFh
  6982 0000E8D2 89C2                <1> 	mov	edx, eax
  6983                              <1> pix_op_mix_24_0:
  6984 0000E8D4 8B07                <1> 	mov	eax, [edi]
  6985 0000E8D6 21D8                <1> 	and	eax, ebx ; 0FFFFFFh
  6986 0000E8D8 01D0                <1> 	add	eax, edx
  6987 0000E8DA D1E8                <1> 	shr	eax, 1
  6988                              <1> 	;rcr	eax, 1
  6989 0000E8DC 66AB                <1> 	stosw
  6990 0000E8DE C1E810              <1> 	shr	eax, 16
  6991 0000E8E1 AA                  <1> 	stosb
  6992 0000E8E2 E2F0                <1> 	loop	pix_op_mix_24_0
  6993 0000E8E4 89D0                <1> 	mov	eax, edx
  6994 0000E8E6 5B                  <1> 	pop	ebx
  6995 0000E8E7 C3                  <1> 	retn
  6996                              <1> 
  6997                              <1> pix_op_mix_32:
  6998                              <1> 	; 32 bit true colors
  6999                              <1> 	; MIX (AVERAGE) PIXEL COLORS
  7000                              <1> 	; ecx = pixel count per row
  7001                              <1> 	; eax = color
  7002                              <1> 	; edi = start pixel address
  7003                              <1> 
  7004 0000E8E8 89C2                <1> 	mov	edx, eax
  7005                              <1> pix_op_mix_32_0:
  7006 0000E8EA 0307                <1> 	add	eax, [edi]
  7007 0000E8EC D1D8                <1> 	rcr	eax, 1	
  7008 0000E8EE AB                  <1> 	stosd
  7009 0000E8EF 89D0                <1> 	mov	eax, edx
  7010 0000E8F1 E2F7                <1> 	loop	pix_op_mix_32_0
  7011 0000E8F3 C3                  <1> 	retn
  7012                              <1> 
  7013                              <1> pix_op_not_8:
  7014                              <1> 	; 8 bit colors (256 colors)
  7015                              <1> 	; NOT PIXEL COLOR
  7016                              <1> 	; ecx = pixel count per row
  7017                              <1> 	; edi = start pixel address
  7018                              <1> 
  7019                              <1> pix_op_not_8_0:
  7020 0000E8F4 F617                <1> 	not	byte [edi]
  7021 0000E8F6 47                  <1> 	inc	edi
  7022 0000E8F7 E2FB                <1> 	loop	pix_op_not_8_0
  7023 0000E8F9 C3                  <1> 	retn
  7024                              <1> 
  7025                              <1> pix_op_not_16:
  7026                              <1> 	; 16 bit colors (65536 colors)
  7027                              <1> 	; NOT PIXEL COLOR
  7028                              <1> 	; ecx = pixel count per row
  7029                              <1> 	; edi = start pixel address
  7030                              <1> 
  7031                              <1> pix_op_not_16_0:
  7032 0000E8FA 66F717              <1> 	not	word [edi]
  7033 0000E8FD 47                  <1> 	inc	edi
  7034 0000E8FE 47                  <1> 	inc	edi
  7035 0000E8FF E2F9                <1> 	loop	pix_op_not_16_0
  7036 0000E901 C3                  <1> 	retn
  7037                              <1> 
  7038                              <1> pix_op_not_24:
  7039                              <1> 	; 24 bit true colors
  7040                              <1> 	; NOT PIXEL COLOR
  7041                              <1> 	; ecx = pixel count per row
  7042                              <1> 	; edi = start pixel address
  7043                              <1> 
  7044                              <1> pix_op_not_24_0:
  7045 0000E902 66F717              <1> 	not	word [edi]
  7046 0000E905 47                  <1> 	inc	edi
  7047 0000E906 47                  <1> 	inc	edi
  7048 0000E907 F617                <1> 	not	byte [edi]
  7049 0000E909 47                  <1> 	inc	edi
  7050 0000E90A E2F6                <1> 	loop	pix_op_not_24_0
  7051 0000E90C C3                  <1> 	retn
  7052                              <1> 
  7053                              <1> pix_op_not_32:
  7054                              <1> 	; 32 bit true colors
  7055                              <1> 	; NOT PIXEL COLOR
  7056                              <1> 	; ecx = pixel count per row
  7057                              <1> 	; eax = color
  7058                              <1> 	; edi = start pixel address
  7059                              <1> pix_op_not_32_0:
  7060 0000E90D F717                <1> 	not	dword [edi]
  7061 0000E90F 83C704              <1> 	add	edi, 4
  7062 0000E912 E2F9                <1> 	loop	pix_op_not_32_0
  7063 0000E914 C3                  <1> 	retn
  7064                              <1> 
  7065                              <1> pix_op_neg_8:
  7066                              <1> 	; 8 bit colors (256 colors)
  7067                              <1> 	; NEG PIXEL COLOR
  7068                              <1> 	; ecx = pixel count per row
  7069                              <1> 	; edi = start pixel address
  7070                              <1> 
  7071                              <1> pix_op_neg_8_0:
  7072 0000E915 F61F                <1> 	neg	byte [edi]
  7073 0000E917 47                  <1> 	inc	edi
  7074 0000E918 E2FB                <1> 	loop	pix_op_neg_8_0
  7075 0000E91A C3                  <1> 	retn
  7076                              <1> 
  7077                              <1> pix_op_neg_16:
  7078                              <1> 	; 16 bit colors (65536 colors)
  7079                              <1> 	; NEG PIXEL COLOR
  7080                              <1> 	; ecx = pixel count per row
  7081                              <1> 	; edi = start pixel address
  7082                              <1> 
  7083                              <1> pix_op_neg_16_0:
  7084 0000E91B 66F71F              <1> 	neg	word [edi]
  7085 0000E91E 47                  <1> 	inc	edi
  7086 0000E91F 47                  <1> 	inc	edi
  7087 0000E920 E2F9                <1> 	loop	pix_op_neg_16_0
  7088 0000E922 C3                  <1> 	retn
  7089                              <1> 
  7090                              <1> pix_op_neg_24:
  7091                              <1> 	; 24 bit true colors
  7092                              <1> 	; NEG PIXEL COLOR
  7093                              <1> 	; ecx = pixel count per row
  7094                              <1> 	; edi = start pixel address
  7095                              <1> 
  7096                              <1> pix_op_neg_24_0:
  7097 0000E923 8B07                <1> 	mov	eax, [edi]
  7098 0000E925 25FFFFFF00          <1> 	and	eax, 0FFFFFFh
  7099 0000E92A F7D8                <1> 	neg	eax
  7100 0000E92C 66AB                <1> 	stosw
  7101 0000E92E C1E810              <1> 	shr	eax, 16
  7102 0000E931 AA                  <1> 	stosb
  7103 0000E932 E2EF                <1> 	loop	pix_op_neg_24_0
  7104 0000E934 C3                  <1> 	retn
  7105                              <1> 
  7106                              <1> pix_op_neg_32:
  7107                              <1> 	; 32 bit true colors
  7108                              <1> 	; NEG PIXEL COLOR
  7109                              <1> 	; ecx = pixel count per row
  7110                              <1> 	; eax = color
  7111                              <1> 	; edi = start pixel address
  7112                              <1> pix_op_neg_32_0:
  7113 0000E935 F71F                <1> 	neg	dword [edi]
  7114 0000E937 83C704              <1> 	add	edi, 4
  7115 0000E93A E2F9                <1> 	loop	pix_op_neg_32_0
  7116 0000E93C C3                  <1> 	retn
  7117                              <1> 
  7118                              <1> pix_op_inc_8:
  7119                              <1> 	; 8 bit colors (256 colors)
  7120                              <1> 	; INCREASE PIXEL COLOR
  7121                              <1> 	; ecx = pixel count per row
  7122                              <1> 	; edi = start pixel address
  7123                              <1> 
  7124                              <1> pix_op_inc_8_0:
  7125 0000E93D FE07                <1> 	inc	byte [edi]
  7126 0000E93F 7502                <1> 	jnz	short pix_op_inc_8_1
  7127                              <1> 	;mov	[edi], 0FFh ; Max. value
  7128 0000E941 FE0F                <1> 	dec	byte [edi]
  7129                              <1> pix_op_inc_8_1:
  7130 0000E943 47                  <1> 	inc	edi
  7131 0000E944 E2F7                <1> 	loop	pix_op_inc_8_0
  7132 0000E946 C3                  <1> 	retn
  7133                              <1> 
  7134                              <1> pix_op_inc_16:
  7135                              <1> 	; 16 bit colors (65536 colors)
  7136                              <1> 	; INCREASE PIXEL COLOR
  7137                              <1> 	; ecx = pixel count per row
  7138                              <1> 	; edi = start pixel address
  7139                              <1> 
  7140                              <1> pix_op_inc_16_0:
  7141 0000E947 66FF07              <1> 	inc	word [edi]
  7142 0000E94A 7503                <1> 	jnz	short pix_op_inc_16_1
  7143                              <1> 	;mov	word [edi], 0FFFFh ; Max. value
  7144 0000E94C 66FF0F              <1> 	dec	word [edi]
  7145                              <1> pix_op_inc_16_1:
  7146 0000E94F 47                  <1> 	inc	edi
  7147 0000E950 47                  <1> 	inc	edi
  7148 0000E951 E2F4                <1> 	loop	pix_op_inc_16_0
  7149 0000E953 C3                  <1> 	retn
  7150                              <1> 
  7151                              <1> pix_op_inc_24:
  7152                              <1> 	; 24 bit true colors
  7153                              <1> 	; INCREASE PIXEL COLOR
  7154                              <1> 	; ecx = pixel count per row
  7155                              <1> 	; edi = start pixel address
  7156                              <1> 
  7157                              <1> pix_op_inc_24_0:
  7158 0000E954 8B07                <1> 	mov	eax, [edi]
  7159 0000E956 40                  <1> 	inc	eax
  7160 0000E957 25FFFFFF00          <1> 	and	eax, 0FFFFFFh
  7161 0000E95C 7501                <1> 	jnz	short pix_op_inc_24_1
  7162                              <1> 	;mov	eax, 0FFFFFFh  ; Max. value
  7163 0000E95E 48                  <1> 	dec	eax ; 0FFFFFFFFh
  7164                              <1> pix_op_inc_24_1: 
  7165 0000E95F 66AB                <1> 	stosw
  7166 0000E961 C1E810              <1> 	shr	eax, 16
  7167 0000E964 AA                  <1> 	stosb
  7168 0000E965 E2ED                <1> 	loop	pix_op_inc_24_0
  7169 0000E967 C3                  <1> 	retn
  7170                              <1> 
  7171                              <1> pix_op_inc_32:
  7172                              <1> 	; 32 bit true colors
  7173                              <1> 	; INCREASE PIXEL COLOR
  7174                              <1> 	; ecx = pixel count per row
  7175                              <1> 	; edi = start pixel address
  7176                              <1> 
  7177                              <1> pix_op_inc_32_0:
  7178 0000E968 FF07                <1> 	inc	dword [edi]
  7179 0000E96A 7502                <1> 	jnz	short pix_op_inc_32_1
  7180                              <1> 	;mov	dword [edi], 0FFFFFFFFh ; Max. value
  7181 0000E96C FF0F                <1> 	dec	dword [edi]
  7182                              <1> pix_op_inc_32_1:
  7183 0000E96E 83C704              <1> 	add	edi, 4
  7184 0000E971 E2F5                <1> 	loop	pix_op_inc_32_0
  7185 0000E973 C3                  <1> 	retn
  7186                              <1> 
  7187                              <1> pix_op_dec_8:
  7188                              <1> 	; 8 bit colors (256 colors)
  7189                              <1> 	; DECREASE PIXEL COLOR
  7190                              <1> 	; ecx = pixel count per row
  7191                              <1> 	; edi = start pixel address
  7192                              <1> 
  7193                              <1> pix_op_dec_8_0:
  7194 0000E974 FE0F                <1> 	dec	byte [edi]
  7195 0000E976 7902                <1> 	jns	short pix_op_dec_8_1
  7196 0000E978 FE07                <1> 	inc	byte [edi] ; 0 ; Min. value
  7197                              <1> pix_op_dec_8_1:
  7198 0000E97A 47                  <1> 	inc	edi
  7199 0000E97B E2F7                <1> 	loop	pix_op_dec_8_0
  7200 0000E97D C3                  <1> 	retn
  7201                              <1> 
  7202                              <1> pix_op_dec_16:
  7203                              <1> 	; 16 bit colors (65536 colors)
  7204                              <1> 	; DECREASE PIXEL COLOR
  7205                              <1> 	; ecx = pixel count per row
  7206                              <1> 	; edi = start pixel address
  7207                              <1> 
  7208                              <1> pix_op_dec_16_0:
  7209 0000E97E 66FF0F              <1> 	dec	word [edi]
  7210 0000E981 7903                <1> 	jns	short pix_op_dec_16_1
  7211 0000E983 66FF07              <1> 	inc	word [edi] ; 0 ; Min. value
  7212                              <1> pix_op_dec_16_1:
  7213 0000E986 47                  <1> 	inc edi
  7214 0000E987 47                  <1> 	inc edi
  7215 0000E988 E2F4                <1> 	loop	pix_op_dec_16_0
  7216 0000E98A C3                  <1> 	retn
  7217                              <1> 
  7218                              <1> pix_op_dec_24:
  7219                              <1> 	; 24 bit true colors
  7220                              <1> 	; DECREASE PIXEL COLOR
  7221                              <1> 	; ecx = pixel count per row
  7222                              <1> 	; edi = start pixel address
  7223                              <1> 
  7224                              <1> pix_op_dec_24_0:
  7225 0000E98B 8B07                <1> 	mov	eax, [edi]
  7226 0000E98D 25FFFFFF00          <1> 	and	eax, 0FFFFFFh
  7227 0000E992 7401                <1> 	jz	short pix_op_dec_24_1
  7228                              <1> 			; 0 ; Min. value
  7229 0000E994 48                  <1> 	dec	eax
  7230                              <1> pix_op_dec_24_1:
  7231 0000E995 66AB                <1> 	stosw
  7232 0000E997 C1E810              <1> 	shr	eax, 16
  7233 0000E99A AA                  <1> 	stosb
  7234 0000E99B E2B7                <1> 	loop	pix_op_inc_24_0
  7235 0000E99D C3                  <1> 	retn
  7236                              <1> 
  7237                              <1> pix_op_dec_32:
  7238                              <1> 	; 32 bit true colors
  7239                              <1> 	; DECREASE PIXEL COLOR
  7240                              <1> 	; ecx = pixel count per row
  7241                              <1> 	; edi = start pixel address
  7242                              <1> 
  7243                              <1> pix_op_dec_32_0:
  7244 0000E99E FF0F                <1> 	dec	dword [edi]
  7245 0000E9A0 7902                <1> 	jns	short pix_op_dec_32_1
  7246 0000E9A2 FF07                <1> 	inc	dword [edi] ; 0 ; Min. value
  7247                              <1> pix_op_dec_32_1:
  7248 0000E9A4 83C704              <1> 	add	edi, 4
  7249 0000E9A7 E2F5                <1> 	loop	pix_op_dec_32_0
  7250 0000E9A9 89D0                <1> 	mov	eax, edx
  7251 0000E9AB C3                  <1> 	retn
  7252                              <1> 
  7253                              <1> pix_op_rpl_8:
  7254                              <1> 	; 8 bit colors (256 colors)
  7255                              <1> 	; REPLACE PIXEL COLORS
  7256                              <1> 	; ecx = pixel count per row
  7257                              <1> 	;  al = new color
  7258                              <1> 	; byte [maskcolor] = old color
  7259                              <1> 	; edi = start pixel address
  7260                              <1> 
  7261 0000E9AC 8A25[AAA30100]      <1> 	mov	ah, [maskcolor]
  7262                              <1> pix_op_rpl_8_0:
  7263 0000E9B2 3A27                <1> 	cmp	ah, [edi]
  7264 0000E9B4 7502                <1> 	jne	short pix_op_rpl_8_1
  7265 0000E9B6 8807                <1> 	mov	[edi], al
  7266                              <1> pix_op_rpl_8_1:
  7267 0000E9B8 47                  <1> 	inc	edi
  7268 0000E9B9 E2F7                <1> 	loop	pix_op_rpl_8_0
  7269 0000E9BB C3                  <1> 	retn
  7270                              <1> 
  7271                              <1> pix_op_rpl_16:
  7272                              <1> 	; 16 bit colors (65536 colors)
  7273                              <1> 	; REPLACE PIXEL COLORS
  7274                              <1> 	; ecx = pixel count per row
  7275                              <1> 	;  ax = new color
  7276                              <1> 	; word [maskcolor] = old color
  7277                              <1> 	; edi = start pixel address
  7278                              <1> 
  7279 0000E9BC 8B15[AAA30100]      <1> 	mov	edx, [maskcolor]
  7280                              <1> pix_op_rpl_16_0:
  7281 0000E9C2 663B17              <1> 	cmp	dx, [edi]
  7282 0000E9C5 7503                <1> 	jne	short pix_op_rpl_16_1
  7283 0000E9C7 668907              <1> 	mov	[edi], ax
  7284                              <1> pix_op_rpl_16_1:
  7285 0000E9CA 47                  <1> 	inc	edi
  7286 0000E9CB 47                  <1> 	inc	edi
  7287 0000E9CC E2F4                <1> 	loop	pix_op_rpl_16_0
  7288 0000E9CE C3                  <1> 	retn
  7289                              <1> 
  7290                              <1> pix_op_rpl_24:
  7291                              <1> 	; 24 bit true colors
  7292                              <1> 	; REPLACE PIXEL COLORS
  7293                              <1> 	; ecx = pixel count per row
  7294                              <1> 	; eax = new color
  7295                              <1> 	; [maskcolor] = old color
  7296                              <1> 	; edi = start pixel address
  7297                              <1> 
  7298                              <1> pix_op_rpl_24_0:
  7299 0000E9CF 8B17                <1> 	mov	edx, [edi]
  7300 0000E9D1 81E2FFFFFF00        <1> 	and	edx, 0FFFFFFh
  7301 0000E9D7 3B15[AAA30100]      <1> 	cmp	edx, [maskcolor]
  7302 0000E9DD 7406                <1> 	je	short pix_op_rpl_24_1
  7303 0000E9DF 83C703              <1> 	add	edi, 3
  7304 0000E9E2 E2EB                <1> 	loop	pix_op_rpl_24_0
  7305 0000E9E4 C3                  <1> 	retn
  7306                              <1> pix_op_rpl_24_1:
  7307 0000E9E5 AA                  <1> 	stosb
  7308 0000E9E6 C1C808              <1> 	ror	eax, 8
  7309 0000E9E9 66AB                <1> 	stosw
  7310 0000E9EB C1C008              <1> 	rol	eax, 8
  7311 0000E9EE E2DF                <1> 	loop	pix_op_rpl_24_0
  7312 0000E9F0 C3                  <1> 	retn
  7313                              <1> 
  7314                              <1> pix_op_rpl_32:
  7315                              <1> 	; 32 bit true colors
  7316                              <1> 	; REPLACE PIXEL COLORS
  7317                              <1> 	; ecx = pixel count per row
  7318                              <1> 	; eax = new color
  7319                              <1> 	; [maskcolor] = old color
  7320                              <1> 	; edi = start pixel address
  7321                              <1> 
  7322 0000E9F1 8B15[AAA30100]      <1> 	mov	edx, [maskcolor]
  7323                              <1> pix_op_rpl_32_0:
  7324 0000E9F7 3B17                <1> 	cmp	edx, [edi]
  7325 0000E9F9 7504                <1> 	jne	short pix_op_rpl_32_2
  7326 0000E9FB AB                  <1> 	stosd
  7327 0000E9FC E2F9                <1> 	loop	pix_op_rpl_32_0
  7328 0000E9FE C3                  <1> 	retn
  7329                              <1> pix_op_rpl_32_2:
  7330 0000E9FF 83C704              <1> 	add	edi, 4
  7331 0000EA02 E2F3                <1> 	loop	pix_op_rpl_32_0
  7332 0000EA04 C3                  <1> 	retn
  7333                              <1> 
  7334                              <1> pix_op_chr:
  7335                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
  7336                              <1> 	; 15/02/2021
  7337                              <1> 	; 05/02/2021
  7338                              <1> 	; WRITE CHARACTER (FONT)
  7339                              <1> 	; 05/01/2021 ([ufont])
  7340                              <1> 	; 01/01/2021
  7341                              <1> 	;     CL = char's color (8 bit, 256 colors)
  7342                              <1> 	;    ECX = char's color (16 bit and true colors)
  7343                              <1> 	;     DL = Character's ASCII code
  7344                              <1> 	;     DH bit 0 -> font height
  7345                              <1> 	;	  0 -> 8x16 character font
  7346                              <1> 	;	  1 -> 8x8 character font
  7347                              <1> 	;     DH bit 1 & 2 -> scale
  7348                              <1> 	;	  0 = 1/1 (8 pixels per char row)
  7349                              <1> 	;	  1 = 2/1 (16 pixels per char row)
  7350                              <1> 	;	  2 = 3/1 (24 pixels per char row)
  7351                              <1> 	;	  3 = 4/1 (32 pixels per char row)
  7352                              <1> 	;     DH bit 6 -> [ufont] option (1 = use [ufont])
  7353                              <1> 	;     If DH bit 7 = 1
  7354                              <1> 	;	 USER FONT (from user buffer)
  7355                              <1> 	;	    DL = 0 -> 8x8 (width: 1 byte per row)
  7356                              <1> 	;	    DL = 1 -> 8x16
  7357                              <1> 	;	    DL = 2 -> 16x16 (width: 2 bytes)
  7358                              <1> 	;	    DL = 3 -> 16x32
  7359                              <1> 	;	    DL = 4 -> 24x24 (width: 3 bytes)
  7360                              <1> 	;	    DL = 5 -> 24x48
  7361                              <1> 	;	    DL = 6 -> 32x32 (width: 4 bytes)
  7362                              <1> 	;	    DL = 7 -> 32x64
  7363                              <1> 	;	    DL > 7 -> invalid (unused)
  7364                              <1> 	;	 EDI = user's font buffer address
  7365                              <1> 	;	    (NOTE: byte order is as row0,row1,row2..)
  7366                              <1> 	;     ESI = start position (row, column) (*)
  7367                              <1> 	;	     (HW = row, SI = column)
  7368                              <1> 
  7369 0000EA05 89F0                <1> 	mov	eax, esi ; start position
  7370 0000EA07 E856F2FFFF          <1> 	call	calc_pixel_offset
  7371 0000EA0C 3B05[9EA30100]      <1> 	cmp	eax, [v_siz]
  7372 0000EA12 736D                <1> 	jnb	short pix_op_chr_err ; out of display page!
  7373 0000EA14 E826F2FFFF          <1> 	call	pixels_to_byte_count
  7374                              <1> 	; eax = font start offset
  7375 0000EA19 0305[9AA30100]      <1> 	add	eax, [v_mem] ; LFB start address
  7376 0000EA1F A3[A2A30100]        <1> 	mov	[v_str], eax ; font start address
  7377                              <1> 
  7378 0000EA24 890D[AAA30100]      <1> 	mov	[maskcolor], ecx ; save char's color
  7379                              <1> 
  7380 0000EA2A 8835[98A30100]      <1> 	mov	[v_ops], dh
  7381                              <1> 
  7382 0000EA30 81E6FFFF0000        <1> 	and	esi, 0FFFFh
  7383 0000EA36 8935[B2A30100]      <1> 	mov	[buffer8], esi ; start column
  7384                              <1> 
  7385 0000EA3C 31DB                <1> 	xor	ebx, ebx ; 0
  7386 0000EA3E 31C0                <1> 	xor	eax, eax ; 15/02/2021
  7387                              <1> 
  7388 0000EA40 F6C680              <1> 	test	dh, 80h
  7389 0000EA43 7577                <1> 	jnz	short pix_op_chr_u ; user font
  7390                              <1> 
  7391 0000EA45 80E63F              <1> 	and	dh, 3Fh ; clear bit 6, [UFONT] option bit
  7392 0000EA48 7409                <1> 	jz	short pix_op_chr_0
  7393                              <1> 
  7394 0000EA4A 80FE07              <1> 	cmp	dh, 7
  7395 0000EA4D 7732                <1> 	ja	short pix_op_chr_err
  7396                              <1> 			 ; invalid (undefined) option
  7397 0000EA4F 88F4                <1> 	mov	ah, dh
  7398 0000EA51 D0EC                <1> 	shr	ah, 1
  7399                              <1> 	; ah = 0 to 3, scale
  7400                              <1> 	;jmp	short pix_op_chr_font_pixels
  7401                              <1> 
  7402                              <1> pix_op_chr_font_pixels:
  7403                              <1> 	; 05/02/2021
  7404                              <1> 	; write scaled font to buffer
  7405                              <1> 
  7406                              <1> 	; DL = ASCII code of character
  7407                              <1> 	; AH = scale
  7408                              <1> 	; EDI = buffer address (kernel)
  7409                              <1> 
  7410                              <1> pix_op_chr_0:
  7411 0000EA53 88D3                <1> 	mov	bl, dl ; 15/02/2021
  7412 0000EA55 31C9                <1> 	xor	ecx, ecx
  7413 0000EA57 B610                <1> 	mov	dh, 16
  7414 0000EA59 F605[98A30100]01    <1> 	test	byte [v_ops], 1 ; 8x8 font ?
  7415 0000EA60 7428                <1> 	jz	short pix_op_chr_2 ; 8x16 font
  7416 0000EA62 B608                <1> 	mov	dh, 8
  7417 0000EA64 C1E303              <1> 	shl	ebx, 3 ; * 8
  7418 0000EA67 F605[98A30100]40    <1> 	test	byte [v_ops], 40h ; [ufont] option
  7419 0000EA6E 7412                <1> 	jz	short pix_op_chr_1  ; no
  7420                              <1> 	; test 8x8 user font is ready flag
  7421 0000EA70 F605[8EA30100]01    <1> 	test	byte [ufont], 1
  7422 0000EA77 7409                <1> 	jz	short pix_op_chr_1 ; no
  7423 0000EA79 81C300500900        <1> 	add	ebx, VGAFONT8USER
  7424 0000EA7F EB2C                <1> 	jmp	short pix_op_chr_fpos_0
  7425                              <1> pix_op_chr_err:
  7426 0000EA81 C3                  <1> 	retn
  7427                              <1> pix_op_chr_1:
  7428 0000EA82 81C3[54530100]      <1> 	add	ebx, vgafont8 ; system font (8x8)
  7429 0000EA88 EB23                <1> 	jmp	short pix_op_chr_fpos_0
  7430                              <1> pix_op_chr_2:
  7431 0000EA8A C1E304              <1> 	shl	ebx, 4 ; * 16
  7432 0000EA8D F605[98A30100]40    <1> 	test	byte [v_ops], 40h ; [ufont] option
  7433 0000EA94 7411                <1> 	jz	short pix_op_chr_3  ; no
  7434                              <1> 	; test 8x16 user font is ready flag
  7435 0000EA96 F605[8EA30100]02    <1> 	test	byte [ufont], 2
  7436 0000EA9D 7408                <1> 	jz	short pix_op_chr_3 ; no
  7437 0000EA9F 81C300400900        <1> 	add	ebx, VGAFONT16USER
  7438 0000EAA5 EB06                <1> 	jmp	short pix_op_chr_fpos_0
  7439                              <1> pix_op_chr_3:
  7440 0000EAA7 81C3[54690100]      <1> 	add	ebx, vgafont16 ; system font (8x16)
  7441                              <1> pix_op_chr_fpos_0:
  7442 0000EAAD 20E4                <1> 	and	ah, ah
  7443 0000EAAF 754A                <1> 	jnz	short pix_op_chr_fpos_1 ; scale > 1
  7444                              <1> 	; no scale (scale = 1)
  7445 0000EAB1 89DE                <1> 	mov	esi, ebx ; 15/02/2021
  7446 0000EAB3 88F1                <1> 	mov	cl, dh ; rows/height (16 or 8)
  7447 0000EAB5 B608                <1> 	mov	dh, 8  ; columns/width
  7448 0000EAB7 E9CB000000          <1> 	jmp	pix_op_chr_f2p
  7449                              <1> pix_op_chr_u:
  7450                              <1> 	; write user defined font 
  7451 0000EABC 80FE80              <1> 	cmp	dh, 80h
  7452 0000EABF 75C0                <1> 	jne	short pix_op_chr_err
  7453 0000EAC1 80FA07              <1> 	cmp	dl, 7
  7454 0000EAC4 77BB                <1> 	ja	short pix_op_chr_err
  7455                              <1> 
  7456                              <1> 	; 16/02/2021
  7457 0000EAC6 89FE                <1> 	mov	esi, edi ; user's font buffer
  7458                              <1> 	
  7459                              <1> 	;xor	eax, eax
  7460                              <1> 	; eax = 0 ; 15/02/2021
  7461 0000EAC8 88D4                <1> 	mov	ah, dl
  7462 0000EACA D0EC                <1> 	shr	ah, 1
  7463 0000EACC FEC4                <1> 	inc	ah
  7464                              <1> 	; ah =  1 to 4
  7465 0000EACE 88E0                <1> 	mov	al, ah
  7466 0000EAD0 C0E003              <1> 	shl	al, 3 ; * 8
  7467                              <1> 	; al = 8,16,24,32
  7468 0000EAD3 88C3                <1> 	mov	bl, al
  7469 0000EAD5 88C7                <1> 	mov	bh, al
  7470 0000EAD7 F6E4                <1> 	mul	ah
  7471                              <1> 	; ax = 8,32,72,128 bytes
  7472 0000EAD9 F6C201              <1> 	test	dl, 1
  7473 0000EADC 7404                <1> 	jz	short pix_op_chr_u_0
  7474                              <1> 	;shl	ax, 1 ; *2
  7475                              <1> 	; 23/07/2022
  7476 0000EADE D1E0                <1> 	shl	eax, 1
  7477                              <1> 	; ax = 16,32,144,256 bytes
  7478 0000EAE0 D0E7                <1> 	shl	bh, 1
  7479                              <1> pix_op_chr_u_0:
  7480                              <1> 	; eax = byte count
  7481 0000EAE2 89C1                <1> 	mov	ecx, eax
  7482 0000EAE4 BF00760900          <1> 	mov	edi, VBE3SAVERESTOREBLOCK
  7483                              <1> 	; esi = user buffer
  7484 0000EAE9 E8EC240000          <1> 	call	transfer_from_user_buffer
  7485 0000EAEE 7291                <1> 	jc	short pix_op_chr_err
  7486                              <1> 
  7487 0000EAF0 88F9                <1> 	mov	cl, bh ; rows/height
  7488 0000EAF2 88DE                <1> 	mov	dh, bl ; columns (width)
  7489 0000EAF4 89FE                <1> 	mov	esi, edi ; VBE3SAVERESTOREBLOCK
  7490 0000EAF6 E98C000000          <1> 	jmp	pix_op_chr_f2p
  7491                              <1> 
  7492                              <1> pix_op_chr_fpos_1:
  7493                              <1> 	; 18/02/2021
  7494                              <1> 	; scale > 1
  7495 0000EAFB 88F5                <1> 	mov	ch, dh ; 16 or 8
  7496 0000EAFD BF00760900          <1> 	mov	edi, VBE3SAVERESTOREBLOCK
  7497 0000EB02 89FE                <1> 	mov	esi, edi
  7498 0000EB04 FECC                <1> 	dec	ah
  7499 0000EB06 7522                <1> 	jnz	short pix_op_chr_fpos_5 ; scale > 2
  7500                              <1> 	; scale = 2
  7501                              <1> pix_op_chr_fpos_2:
  7502 0000EB08 B108                <1> 	mov	cl, 8
  7503 0000EB0A 8A13                <1> 	mov	dl, [ebx]
  7504                              <1> pix_op_chr_fpos_3:
  7505                              <1> 	;shl 	ax, 2
  7506                              <1> 	; 23/07/2022
  7507 0000EB0C C1E002              <1> 	shl	eax, 2
  7508 0000EB0F D0E2                <1> 	shl	dl, 1
  7509 0000EB11 7302                <1> 	jnc	short pix_op_chr_fpos_4
  7510 0000EB13 0C03                <1> 	or	al, 3
  7511                              <1> pix_op_chr_fpos_4:
  7512 0000EB15 FEC9                <1> 	dec	cl
  7513 0000EB17 75F3                <1> 	jnz	short pix_op_chr_fpos_3
  7514 0000EB19 66AB                <1> 	stosw
  7515                              <1> 	; 18/02/2021
  7516 0000EB1B 66AB                <1> 	stosw
  7517 0000EB1D 43                  <1> 	inc	ebx
  7518 0000EB1E FECD                <1> 	dec	ch
  7519 0000EB20 75E6                <1> 	jnz	short pix_op_chr_fpos_2
  7520                              <1> 	; scale = 2
  7521 0000EB22 88F1                <1> 	mov	cl, dh ; 16 or 8 (height/rows)
  7522 0000EB24 D0E1                <1> 	shl	cl, 1  ; 32 or 16 rows
  7523 0000EB26 B610                <1> 	mov	dh, 16 ; columns (width)
  7524 0000EB28 EB5D                <1> 	jmp	short pix_op_chr_f2p
  7525                              <1> pix_op_chr_fpos_5:
  7526 0000EB2A FECC                <1> 	dec	ah
  7527 0000EB2C 7538                <1> 	jnz	short pix_op_chr_fpos_9 ; scale = 4
  7528                              <1> 	; scale = 3
  7529                              <1> pix_op_chr_fpos_6:
  7530 0000EB2E B108                <1> 	mov	cl, 8
  7531 0000EB30 8A13                <1> 	mov	dl, [ebx]
  7532                              <1> pix_op_chr_fpos_7:
  7533 0000EB32 C1E003              <1> 	shl 	eax, 3
  7534 0000EB35 D0E2                <1> 	shl	dl, 1 ; 18/02/2021
  7535 0000EB37 7302                <1> 	jnc	short pix_op_chr_fpos_8
  7536 0000EB39 0C07                <1> 	or	al, 7
  7537                              <1> pix_op_chr_fpos_8:
  7538 0000EB3B FEC9                <1> 	dec	cl
  7539 0000EB3D 75F3                <1> 	jnz	short pix_op_chr_fpos_7
  7540 0000EB3F 66AB                <1> 	stosw
  7541                              <1> 	; 18/02/2021
  7542 0000EB41 C1C810              <1> 	ror	eax, 16
  7543 0000EB44 AA                  <1> 	stosb
  7544 0000EB45 C1C010              <1> 	rol	eax, 16
  7545 0000EB48 66AB                <1> 	stosw
  7546 0000EB4A C1C810              <1> 	ror	eax, 16
  7547 0000EB4D AA                  <1> 	stosb
  7548 0000EB4E C1C010              <1> 	rol	eax, 16
  7549 0000EB51 66AB                <1> 	stosw
  7550 0000EB53 C1E810              <1> 	shr	eax, 16 ; 27/02/2021
  7551 0000EB56 AA                  <1> 	stosb
  7552 0000EB57 43                  <1> 	inc	ebx
  7553                              <1> 	; 18/02/2021
  7554 0000EB58 FECD                <1> 	dec	ch
  7555 0000EB5A 75D2                <1> 	jnz	short pix_op_chr_fpos_6
  7556                              <1> 	; scale = 3
  7557 0000EB5C 88F1                <1> 	mov	cl, dh ; 16 or 8 (height/rows)
  7558 0000EB5E D0E1                <1> 	shl	cl, 1 
  7559 0000EB60 00F1                <1> 	add	cl, dh ; 48 or 24 rows
  7560 0000EB62 B618                <1> 	mov	dh, 24 ; columns (width)
  7561 0000EB64 EB21                <1> 	jmp	short pix_op_chr_f2p
  7562                              <1> 
  7563                              <1> pix_op_chr_fpos_9:
  7564                              <1> 	; scale = 4
  7565 0000EB66 B108                <1> 	mov	cl, 8
  7566 0000EB68 8A13                <1> 	mov	dl, [ebx]
  7567                              <1> pix_op_chr_fpos_10:
  7568                              <1> 	; 18/02/2021
  7569 0000EB6A C1E004              <1> 	shl 	eax, 4
  7570 0000EB6D D0E2                <1> 	shl	dl, 1 ; 18/02/2021
  7571 0000EB6F 7302                <1> 	jnc	short pix_op_chr_fpos_11
  7572 0000EB71 0C0F                <1> 	or	al, 0Fh ; or al, 15
  7573                              <1> pix_op_chr_fpos_11:
  7574 0000EB73 FEC9                <1> 	dec	cl
  7575 0000EB75 75F3                <1> 	jnz	short pix_op_chr_fpos_10
  7576 0000EB77 AB                  <1> 	stosd
  7577                              <1> 	; 18/02/2021
  7578 0000EB78 AB                  <1> 	stosd
  7579 0000EB79 AB                  <1> 	stosd
  7580 0000EB7A AB                  <1> 	stosd
  7581 0000EB7B 43                  <1> 	inc	ebx
  7582 0000EB7C FECD                <1> 	dec	ch
  7583 0000EB7E 75E6                <1> 	jnz	short pix_op_chr_fpos_9
  7584                              <1> 	; scale = 4
  7585 0000EB80 88F1                <1> 	mov	cl, dh ; 16 or 8 (height/rows)
  7586 0000EB82 C0E102              <1> 	shl	cl, 2 ; 64 or 32 rows
  7587 0000EB85 B620                <1> 	mov	dh, 32 ; columns (width)
  7588                              <1> 	;jmp	short pix_op_chr_f2p
  7589                              <1>  	
  7590                              <1> pix_op_chr_f2p:
  7591                              <1> 	; write font pixels
  7592 0000EB87 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  7593                              <1> 	; 15/02/2021
  7594                              <1> pix_op_chr_f2p_next:
  7595 0000EB8D 80FE08              <1> 	cmp	dh, 8
  7596 0000EB90 7706                <1> 	ja	short pix_op_chr_f2p_24
  7597                              <1> pix_op_chr_f2p_8:
  7598 0000EB92 AC                  <1> 	lodsb
  7599 0000EB93 C1E018              <1> 	shl	eax, 24 ; 15/02/2021
  7600 0000EB96 EB16                <1> 	jmp	short pix_op_chr_f2p_0
  7601                              <1> pix_op_chr_f2p_24:
  7602 0000EB98 80FE18              <1> 	cmp	dh, 24
  7603 0000EB9B 7710                <1> 	ja	short pix_op_chr_f2p_32
  7604 0000EB9D 7207                <1> 	jb	short pix_op_chr_f2p_16
  7605                              <1> 	; 27/02/2021
  7606                              <1> 	;mov	eax, [esi]
  7607 0000EB9F AD                  <1> 	lodsd
  7608 0000EBA0 C1E008              <1> 	shl	eax, 8
  7609                              <1> 	;add	esi, 3
  7610 0000EBA3 4E                  <1> 	dec	esi
  7611 0000EBA4 EB08                <1> 	jmp	short pix_op_chr_f2p_0
  7612                              <1> pix_op_chr_f2p_16:
  7613 0000EBA6 66AD                <1> 	lodsw
  7614 0000EBA8 C1E010              <1> 	shl	eax, 16 ; 15/02/2021
  7615 0000EBAB EB01                <1> 	jmp	short pix_op_chr_f2p_0
  7616                              <1> pix_op_chr_f2p_32:
  7617 0000EBAD AD                  <1> 	lodsd
  7618                              <1> pix_op_chr_f2p_0:
  7619                              <1> 	; EAX = font row (8,16,24,32 pixels)
  7620                              <1> 	;	(bits are shifted to left)
  7621                              <1> 	; CL = rows
  7622                              <1> 	; DH = bits per row (8,16,24,32)
  7623 0000EBAE 8B1D[B2A30100]      <1> 	mov	ebx, [buffer8] ; start column
  7624 0000EBB4 57                  <1> 	push	edi ; *
  7625 0000EBB5 52                  <1> 	push	edx ; **
  7626                              <1> pix_op_chr_f2p_1:
  7627 0000EBB6 E82E000000          <1> 	call	pix_op_chr_w_pixel
  7628                              <1> pix_op_chr_f2p_2:
  7629 0000EBBB 663B1D[96A30100]    <1> 	cmp	bx, [v_width] ; current column
  7630 0000EBC2 7304                <1> 	jnb	short pix_op_chr_f2p_3
  7631 0000EBC4 FECE                <1> 	dec	dh
  7632 0000EBC6 75EE                <1> 	jnz	short pix_op_chr_f2p_1 ; next bit
  7633                              <1> pix_op_chr_f2p_3:
  7634                              <1> 	;mov	ebx, [buffer8]
  7635 0000EBC8 5A                  <1> 	pop	edx ; **
  7636 0000EBC9 58                  <1> 	pop	eax ; *
  7637 0000EBCA 3B3D[A6A30100]      <1> 	cmp	edi, [v_end]
  7638 0000EBD0 7316                <1> 	jnb	short pix_op_chr_f2p_4
  7639 0000EBD2 FEC9                <1> 	dec	cl
  7640 0000EBD4 7412                <1> 	jz	short pix_op_chr_f2p_4
  7641                              <1> 	; 27/02/2021
  7642 0000EBD6 89C7                <1> 	mov	edi, eax
  7643 0000EBD8 0FB705[96A30100]    <1> 	movzx	eax, word [v_width]
  7644 0000EBDF E85BF0FFFF          <1> 	call	pixels_to_byte_count
  7645 0000EBE4 01C7                <1> 	add	edi, eax ; next position
  7646 0000EBE6 EBA5                <1> 	jmp	short pix_op_chr_f2p_next
  7647                              <1> pix_op_chr_f2p_4:
  7648 0000EBE8 C3                  <1> 	retn
  7649                              <1> 
  7650                              <1> pix_op_chr_w_pixel:
  7651                              <1> 	; 15/02/2021
  7652 0000EBE9 89C5                <1> 	mov	ebp, eax
  7653 0000EBEB A1[AAA30100]        <1> 	mov	eax, [maskcolor]
  7654 0000EBF0 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  7655 0000EBF7 7711                <1> 	ja	short pix_op_chr_wp_2
  7656                              <1> 	; 256 colors (1 byte per pixel)
  7657 0000EBF9 D1E5                <1> 	shl	ebp, 1
  7658 0000EBFB 7302                <1> 	jnc	short pix_op_chr_wp_0
  7659 0000EBFD 8807                <1> 	mov	[edi], al
  7660                              <1> pix_op_chr_wp_0:
  7661 0000EBFF 47                  <1> 	inc	edi
  7662 0000EC00 FF05[74940100]      <1> 	inc	dword [u.r0] ; +1
  7663                              <1> pix_op_chr_wp_1:
  7664 0000EC06 43                  <1> 	inc	ebx
  7665 0000EC07 89E8                <1> 	mov	eax, ebp
  7666 0000EC09 C3                  <1> 	retn
  7667                              <1> pix_op_chr_wp_2:
  7668 0000EC0A 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  7669 0000EC11 772E                <1> 	ja	short pix_op_chr_wp_6 ; 32bpp
  7670 0000EC13 721C                <1> 	jb	short pix_op_chr_wp_4 ; 16bpp
  7671                              <1> 	; 24 bit true colors
  7672                              <1> 	; * 3
  7673 0000EC15 D1E5                <1> 	shl	ebp, 1
  7674 0000EC17 7309                <1> 	jnc	short pix_op_chr_wp_3
  7675 0000EC19 668907              <1> 	mov	[edi], ax
  7676 0000EC1C C1E810              <1> 	shr	eax, 16
  7677 0000EC1F 884702              <1> 	mov	[edi+2], al
  7678                              <1> pix_op_chr_wp_3:
  7679 0000EC22 B803000000          <1> 	mov	eax, 3 ; 27/02/2021
  7680 0000EC27 01C7                <1> 	add	edi, eax  ; add edi, 3
  7681 0000EC29 0105[74940100]      <1> 	add	[u.r0], eax ; +3
  7682                              <1> 	
  7683 0000EC2F EBD5                <1> 	jmp	short pix_op_chr_wp_1
  7684                              <1> 
  7685                              <1> pix_op_chr_wp_4:
  7686                              <1> 	; 16 bit (65536) colors
  7687 0000EC31 D1E5                <1> 	shl	ebp, 1
  7688 0000EC33 7303                <1> 	jnc	short pix_op_chr_wp_5
  7689 0000EC35 668907              <1> 	mov	[edi], ax
  7690                              <1> pix_op_chr_wp_5:
  7691 0000EC38 47                  <1> 	inc	edi
  7692 0000EC39 FF05[74940100]      <1> 	inc	dword [u.r0] ; +1 
  7693 0000EC3F EBBE                <1> 	jmp	short pix_op_chr_wp_0
  7694                              <1> 
  7695                              <1> pix_op_chr_wp_6:
  7696                              <1> 	; 32 bit true colors
  7697 0000EC41 D1E5                <1> 	shl	ebp, 1
  7698 0000EC43 7302                <1> 	jnc	short pix_op_chr_wp_7
  7699 0000EC45 8907                <1> 	mov	[edi], eax
  7700                              <1> pix_op_chr_wp_7:
  7701 0000EC47 31C0                <1> 	xor	eax, eax
  7702 0000EC49 B004                <1> 	mov	al, 4
  7703 0000EC4B 01C7                <1> 	add	edi, eax ; add edi, 4
  7704 0000EC4D 0105[74940100]      <1> 	add	[u.r0], eax ; +4
  7705 0000EC53 EBB1                <1> 	jmp	short pix_op_chr_wp_1
  7706                              <1> 
  7707                              <1> m_pix_op_cpy:
  7708                              <1> 	; 26/02/2021
  7709                              <1> 	; 06/02/2021
  7710                              <1> 	; MASKED COPY PIXELS (full screen)
  7711                              <1> 	;
  7712                              <1> 	; jump from pix_op_cpy
  7713                              <1> 	;
  7714                              <1> 	; INPUT:
  7715                              <1> 	;   ecx = transfer count (bytes)
  7716                              <1> 	;   edi = [v_mem] = start address of LFB 
  7717                              <1> 	;   esi = user's buffer address (virtual)
  7718                              <1> 	;
  7719                              <1> 	; OUTPUT:
  7720                              <1> 	;   [u.r0] will be > 0 if succesful
  7721                              <1> 
  7722                              <1> 	; Full screen masked copy
  7723                              <1> 
  7724                              <1> 	; Modified regs: eax, ebx, edx, esi, edi, ecx
  7725                              <1> 
  7726                              <1> m_pix_op_cpy_0:
  7727                              <1> 	;push	ebx ; *** ; 26/02/2021
  7728 0000EC55 57                  <1> 	push	edi ; **
  7729 0000EC56 51                  <1> 	push	ecx ; *
  7730 0000EC57 81F9F8070000        <1> 	cmp	ecx, 2040 ; (3*680) ; 26/02/2021
  7731 0000EC5D 7605                <1> 	jna	short m_pix_op_cpy_1
  7732 0000EC5F B9F8070000          <1> 	mov	ecx, 2040
  7733                              <1> m_pix_op_cpy_1:
  7734 0000EC64 BF00760900          <1> 	mov	edi, VBE3SAVERESTOREBLOCK ; temporary buff
  7735 0000EC69 E86C230000          <1> 	call	transfer_from_user_buffer
  7736 0000EC6E 726C                <1> 	jc	short m_pix_op_cpy_3
  7737 0000EC70 01CE                <1> 	add	esi, ecx
  7738 0000EC72 89F5                <1> 	mov	ebp, esi  ; save user's buffer address
  7739 0000EC74 89FE                <1> 	mov	esi, edi
  7740 0000EC76 89CB                <1> 	mov	ebx, ecx
  7741 0000EC78 59                  <1> 	pop	ecx ; *
  7742 0000EC79 29D9                <1> 	sub	ecx, ebx
  7743 0000EC7B 5F                  <1> 	pop	edi ; **
  7744 0000EC7C 31D2                <1> 	xor	edx, edx ; 26/02/2021
  7745 0000EC7E 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8
  7746 0000EC85 7435                <1> 	je	short m_pix_op_cpy_1_8
  7747 0000EC87 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24
  7748 0000EC8E 776D                <1> 	ja	short m_pix_op_cpy_1_32
  7749 0000EC90 724D                <1> 	jb	short m_pix_op_cpy_1_16
  7750                              <1> m_pix_op_cpy_1_24:
  7751                              <1> 	; 24 bit masked copy
  7752                              <1> 	;mov	edx, 3
  7753 0000EC92 B203                <1> 	mov	dl, 3 ; 26/02/2021
  7754                              <1> m_pix_op_cpy_1_24_0:
  7755 0000EC94 66AD                <1> 	lodsw
  7756 0000EC96 C1E010              <1> 	shl	eax, 16
  7757 0000EC99 AC                  <1> 	lodsb
  7758 0000EC9A C1C010              <1> 	rol	eax, 16
  7759 0000EC9D 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  7760 0000ECA3 740F                <1> 	je	short m_pix_op_cpy_1_24_1 ; exclude
  7761 0000ECA5 668907              <1> 	mov	[edi], ax
  7762 0000ECA8 C1E810              <1> 	shr	eax, 16
  7763 0000ECAB 884702              <1> 	mov	[edi+2], al
  7764 0000ECAE 0115[74940100]      <1> 	add	[u.r0], edx ; +3
  7765                              <1> m_pix_op_cpy_1_24_1:
  7766 0000ECB4 01D7                <1> 	add	edi, edx ; +3
  7767 0000ECB6 29D3                <1> 	sub	ebx, edx ; sub ebx, 3
  7768 0000ECB8 77DA                <1> 	ja	short m_pix_op_cpy_1_24_0
  7769 0000ECBA EB15                <1>  	jmp	short m_pix_op_cpy_2
  7770                              <1> 
  7771                              <1> m_pix_op_cpy_1_8:
  7772                              <1> 	; 8 bit masked copy
  7773 0000ECBC AC                  <1> 	lodsb
  7774 0000ECBD 3A05[AAA30100]      <1> 	cmp	al, [maskcolor]
  7775 0000ECC3 7408                <1> 	je	short m_pix_op_cpy_1_8_1 ; exclude
  7776 0000ECC5 8807                <1> 	mov	[edi], al
  7777 0000ECC7 FF05[74940100]      <1> 	inc	dword [u.r0] ; +1
  7778                              <1> m_pix_op_cpy_1_8_1:
  7779 0000ECCD 47                  <1> 	inc	edi ; +1
  7780 0000ECCE 4B                  <1> 	dec	ebx
  7781 0000ECCF 75EB                <1> 	jnz	short m_pix_op_cpy_1_8
  7782                              <1> m_pix_op_cpy_2:
  7783 0000ECD1 89EE                <1> 	mov	esi, ebp ; restore user's buffer addr
  7784 0000ECD3 09C9                <1> 	or	ecx, ecx
  7785                              <1> 	; 26/02/2021
  7786 0000ECD5 7407                <1> 	jz	short m_pix_of_cpy_4
  7787 0000ECD7 E979FFFFFF          <1> 	jmp	m_pix_op_cpy_0
  7788                              <1> m_pix_op_cpy_3:
  7789 0000ECDC 59                  <1> 	pop	ecx ; *
  7790 0000ECDD 5F                  <1> 	pop	edi ; **
  7791                              <1> m_pix_of_cpy_4:
  7792                              <1> 	;pop	ebx ; *** ; 26/02/2021
  7793 0000ECDE C3                  <1> 	retn
  7794                              <1> 
  7795                              <1> m_pix_op_cpy_1_16:
  7796                              <1> 	; 16 bit masked copy
  7797                              <1> 	;mov	edx, 2
  7798 0000ECDF B202                <1> 	mov	dl, 2 ; 26/02/2021
  7799                              <1> m_pix_op_cpy_1_16_0:
  7800 0000ECE1 66AD                <1> 	lodsw
  7801 0000ECE3 663B05[AAA30100]    <1> 	cmp	ax, [maskcolor]
  7802 0000ECEA 7409                <1> 	je	short m_pix_op_cpy_1_16_1 ; exclude
  7803 0000ECEC 668907              <1> 	mov	[edi], ax
  7804 0000ECEF 0115[74940100]      <1> 	add	[u.r0], edx ; +2
  7805                              <1> m_pix_op_cpy_1_16_1:
  7806 0000ECF5 01D7                <1> 	add	edi, edx ; +2
  7807 0000ECF7 29D3                <1> 	sub	ebx, edx ; sub ebx, 2
  7808 0000ECF9 77E6                <1> 	ja	short m_pix_op_cpy_1_16_0
  7809 0000ECFB EBD4                <1>  	jmp	short m_pix_op_cpy_2
  7810                              <1> 
  7811                              <1> m_pix_op_cpy_1_32:
  7812                              <1> 	; 32 bit masked copy
  7813                              <1> 	;mov	edx, 4
  7814 0000ECFD B204                <1> 	mov	dl, 4 ; 26/02/2021
  7815                              <1> m_pix_op_cpy_1_32_0:
  7816 0000ECFF AD                  <1> 	lodsd
  7817 0000ED00 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  7818 0000ED06 7408                <1> 	je	short m_pix_op_cpy_1_32_1 ; exclude
  7819 0000ED08 8907                <1> 	mov	[edi], eax
  7820 0000ED0A 0115[74940100]      <1> 	add	[u.r0], edx ; +4
  7821                              <1> m_pix_op_cpy_1_32_1:
  7822 0000ED10 01D7                <1> 	add	edi, edx ; +4
  7823 0000ED12 29D3                <1> 	sub	ebx, edx ; sub ebx, 4
  7824 0000ED14 77E9                <1> 	ja	short m_pix_op_cpy_1_32_0
  7825 0000ED16 EBB9                <1>  	jmp	short m_pix_op_cpy_2
  7826                              <1> 
  7827                              <1> m_pix_op_cpy_w:
  7828                              <1> 	; 26/02/2021
  7829                              <1> 	; 06/02/2021
  7830                              <1> 	; MASKED COPY PIXELS (window)
  7831                              <1> 	;
  7832                              <1> 	; jump from pix_op_cpy_w
  7833                              <1> 	;
  7834                              <1> 	; INPUT:
  7835                              <1> 	;   ecx = bytes per row (to be applied)
  7836                              <1> 	;   edx = screen width in bytes
  7837                              <1> 	;   ebx = row count
  7838                              <1> 	;   esi = user's buffer address
  7839                              <1> 	;   [v_str] = window start address
  7840                              <1> 	;
  7841                              <1> 	; OUTPUT:
  7842                              <1> 	;   [u.r0] will be > 0 if succesful
  7843                              <1> 
  7844                              <1> 	; Window masked copy
  7845                              <1> 
  7846                              <1> m_pix_op_cpy_w_0:
  7847 0000ED18 8B3D[A2A30100]      <1> 	mov	edi, [v_str]
  7848                              <1> m_pix_op_cpy_w_1:
  7849 0000ED1E 57                  <1> 	push	edi
  7850 0000ED1F 56                  <1> 	push	esi
  7851 0000ED20 53                  <1> 	push	ebx
  7852 0000ED21 52                  <1> 	push	edx
  7853 0000ED22 51                  <1> 	push	ecx
  7854 0000ED23 E82DFFFFFF          <1> 	call	m_pix_op_cpy ; 26/02/2021
  7855 0000ED28 59                  <1> 	pop	ecx
  7856 0000ED29 5A                  <1> 	pop	edx
  7857 0000ED2A 5B                  <1> 	pop	ebx
  7858 0000ED2B 5E                  <1> 	pop	esi
  7859 0000ED2C 5F                  <1> 	pop	edi
  7860 0000ED2D 7209                <1> 	jc	short m_pix_op_cpy_w_2
  7861 0000ED2F 4B                  <1> 	dec	ebx
  7862 0000ED30 7406                <1> 	jz	short m_pix_op_cpy_w_2 ; ok.
  7863                              <1> 	; next row
  7864 0000ED32 01CE                <1> 	add	esi, ecx ; next row in user's buffer
  7865 0000ED34 01D7                <1> 	add	edi, edx ; next row of window (system)
  7866 0000ED36 EBE6                <1> 	jmp	short m_pix_op_cpy_w_1
  7867                              <1> m_pix_op_cpy_w_2:
  7868 0000ED38 C3                  <1> 	retn
  7869                              <1> 
  7870                              <1> m_pix_op_new:
  7871                              <1> 	; 06/02/2021
  7872                              <1> 	; CHANGE COLOR (MASKED, full screen)
  7873                              <1> 	;
  7874                              <1> 	; jump from pix_op_new
  7875                              <1> 	;
  7876                              <1> 	; INPUT:
  7877                              <1> 	;   eax = color (AL, AX, EAX)
  7878                              <1> 	;   ecx = [v_siz] ; display page pixel count
  7879                              <1> 	;   esi = edi = [v_mem] ; LFB start address
  7880                              <1> 	;
  7881                              <1> 	;   [maskcolor] = mask color (to be excluded)
  7882                              <1> 	;
  7883                              <1> 	; OUTPUT:
  7884                              <1> 	; 	[u.r0] will be > 0 if succesful
  7885                              <1> 
  7886                              <1> 	; Full screen
  7887                              <1> m_pix_op_new_0:
  7888 0000ED39 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  7889 0000ED40 7717                <1> 	ja	short m_pix_op_new_1
  7890                              <1> 	; 256 colors (8bpp)
  7891                              <1> 	;jmp	short m_pix_op_new_8
  7892                              <1> m_pix_op_new_8:
  7893                              <1> 	; 8 bit colors (256 colors)
  7894 0000ED42 88C2                <1> 	mov	dl, al ; new color
  7895                              <1> m_pix_op_new_8_0:
  7896 0000ED44 AC                  <1> 	lodsb 
  7897 0000ED45 3A05[AAA30100]      <1> 	cmp	al, [maskcolor]
  7898 0000ED4B 7408                <1> 	je	short m_pix_op_new_8_1 ; exclude
  7899 0000ED4D 8817                <1> 	mov	[edi], dl
  7900 0000ED4F FF05[74940100]      <1> 	inc	dword [u.r0]
  7901                              <1> m_pix_op_new_8_1:
  7902 0000ED55 47                  <1> 	inc	edi
  7903 0000ED56 E2EC                <1> 	loop	m_pix_op_new_8_0
  7904 0000ED58 C3                  <1> 	retn
  7905                              <1> m_pix_op_new_1:
  7906 0000ED59 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  7907 0000ED60 774B                <1> 	ja	short m_pix_op_new_3 ; 32bpp
  7908 0000ED62 722C                <1> 	jb	short m_pix_op_new_2 ; 16bpp
  7909                              <1> 	; 24 bit true colors
  7910                              <1> 	;jmp	short m_pix_op_new_24
  7911                              <1> m_pix_op_new_24:
  7912                              <1> 	; 24 bit true colors
  7913 0000ED64 89C2                <1> 	mov	edx, eax ; new color
  7914                              <1> m_pix_op_new_24_0:
  7915 0000ED66 66AD                <1> 	lodsw
  7916 0000ED68 C1E010              <1> 	shl	eax, 16
  7917 0000ED6B AC                  <1> 	lodsb
  7918 0000ED6C C1C010              <1> 	rol	eax, 16	
  7919 0000ED6F 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  7920 0000ED75 7413                <1> 	je	short m_pix_op_new_24_1 ; exclude
  7921 0000ED77 668917              <1> 	mov	[edi], dx
  7922 0000ED7A C1CA10              <1> 	ror	edx, 16
  7923 0000ED7D 885702              <1> 	mov	[edi+2], dl
  7924 0000ED80 C1C210              <1> 	rol	edx, 16
  7925 0000ED83 8305[74940100]03    <1> 	add	dword [u.r0], 3
  7926                              <1> m_pix_op_new_24_1:
  7927 0000ED8A 83C703              <1> 	add	edi, 3
  7928 0000ED8D E2D7                <1> 	loop	m_pix_op_new_24_0
  7929 0000ED8F C3                  <1> 	retn
  7930                              <1> 	; 65536 colors (16bpp)
  7931                              <1> m_pix_op_new_2:
  7932                              <1> 	;jmp	short m_pix_op_new_16
  7933                              <1> m_pix_op_new_16:
  7934                              <1> 	; 16 bit colors (65536 colors)
  7935 0000ED90 89C2                <1> 	mov	edx, eax ; new color
  7936                              <1> m_pix_op_new_16_0:
  7937 0000ED92 66AD                <1> 	lodsw
  7938 0000ED94 663B05[AAA30100]    <1> 	cmp	ax, [maskcolor]
  7939 0000ED9B 740A                <1> 	je	short m_pix_op_new_16_1 ; exclude
  7940 0000ED9D 668917              <1> 	mov	[edi], dx
  7941 0000EDA0 8305[74940100]02    <1> 	add	dword [u.r0], 2
  7942                              <1> m_pix_op_new_16_1:
  7943 0000EDA7 83C702              <1> 	add	edi, 2
  7944 0000EDAA E2E6                <1> 	loop	m_pix_op_new_16_0
  7945 0000EDAC C3                  <1> 	retn
  7946                              <1> m_pix_op_new_3:
  7947                              <1> 	; 32 bit true colors
  7948                              <1> 	;jmp	short m_pix_op_new_32
  7949                              <1> m_pix_op_new_32:
  7950                              <1> 	; 32 bit true colors
  7951 0000EDAD 89C2                <1> 	mov	edx, eax ; new color
  7952                              <1> m_pix_op_new_32_0:
  7953 0000EDAF AD                  <1> 	lodsd 
  7954 0000EDB0 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  7955 0000EDB6 7409                <1> 	je	short m_pix_op_new_32_1 ; exclude
  7956 0000EDB8 8917                <1> 	mov	[edi], edx
  7957 0000EDBA 8305[74940100]04    <1> 	add	dword [u.r0], 4
  7958                              <1> m_pix_op_new_32_1:
  7959 0000EDC1 83C704              <1> 	add	edi, 4
  7960 0000EDC4 E2E9                <1> 	loop	m_pix_op_new_32_0
  7961 0000EDC6 C3                  <1> 	retn
  7962                              <1> 
  7963                              <1> m_pix_op_new_w:
  7964                              <1> 	; 06/02/2021
  7965                              <1> 	; CHANGE COLOR (MASKED, window)
  7966                              <1> 	;
  7967                              <1> 	; jump from pix_op_new_w
  7968                              <1> 	;
  7969                              <1> 	; INPUT:
  7970                              <1> 	;   ecx = bytes per row (to be applied)
  7971                              <1> 	;   edx = screen width in bytes
  7972                              <1> 	;   ebx = row count
  7973                              <1> 	;   eax = color
  7974                              <1> 	;
  7975                              <1> 	;   [maskcolor] = mask color (to be excluded)
  7976                              <1> 	;
  7977                              <1> 	; OUTPUT:
  7978                              <1> 	; 	[u.r0] will be > 0 if succesful
  7979                              <1> 
  7980                              <1> 	; Window
  7981                              <1> 	;mov	edi, [v_str] ; LFB start address
  7982                              <1> 	;mov	esi, edi 
  7983                              <1> 
  7984 0000EDC7 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  7985 0000EDCE 7707                <1> 	ja	short m_pix_op_new_w_1
  7986                              <1> 
  7987                              <1> 	; 256 colors (8bpp)
  7988 0000EDD0 BD[42ED0000]        <1> 	mov	ebp, m_pix_op_new_8
  7989 0000EDD5 EB1E                <1> 	jmp	short m_pix_op_new_w_x
  7990                              <1> 
  7991                              <1> m_pix_op_new_w_1:
  7992 0000EDD7 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  7993 0000EDDE 7710                <1> 	ja	short m_pix_op_new_w_3 ; 32bpp
  7994 0000EDE0 7207                <1> 	jb	short m_pix_op_new_w_2 ; 16bpp
  7995                              <1> 
  7996                              <1> 	; 24 bit true colors
  7997 0000EDE2 BD[64ED0000]        <1> 	mov	ebp, m_pix_op_new_24
  7998 0000EDE7 EB0C                <1> 	jmp	short m_pix_op_new_w_x
  7999                              <1> 
  8000                              <1> 	; 65536 colors (16bpp)
  8001                              <1> m_pix_op_new_w_2:
  8002 0000EDE9 BD[90ED0000]        <1> 	mov	ebp, m_pix_op_new_16
  8003 0000EDEE EB05                <1> 	jmp	short m_pix_op_new_w_x
  8004                              <1> 
  8005                              <1> 	; 32 bit true colors
  8006                              <1> m_pix_op_new_w_3:
  8007 0000EDF0 BD[ADED0000]        <1> 	mov	ebp, m_pix_op_new_32
  8008                              <1> 	;jmp	short m_pix_op_new_w_x
  8009                              <1> 
  8010                              <1> m_pix_op_new_w_x:
  8011                              <1> m_pix_op_add_w_x:
  8012                              <1> m_pix_op_sub_w_x:
  8013                              <1> m_pix_op_mix_w_x:
  8014                              <1> m_pix_op_and_w_x:
  8015                              <1> m_pix_op_orc_w_x:
  8016                              <1> m_pix_op_xor_w_x:
  8017                              <1> m_pix_op_not_w_x:
  8018                              <1> m_pix_op_neg_w_x:
  8019                              <1> m_pix_op_inc_w_x:
  8020                              <1> m_pix_op_dec_w_x:
  8021                              <1> 	; 27/02/2021
  8022                              <1> 	; 26/02/2021
  8023                              <1> 	; 06/02/2021
  8024                              <1> 	; ecx = bytes per row (to be applied)
  8025                              <1> 	; edx = windows (screen) width in bytes
  8026                              <1> 	; ebx = row count
  8027                              <1> 	; eax = color
  8028                              <1> 	; ebp = pixel operation subroutine address
  8029                              <1> 	; edi = esi = window start address
  8030                              <1> 
  8031 0000EDF5 8B3D[A2A30100]      <1> 	mov	edi, [v_str] ; LFB start address
  8032 0000EDFB 89FE                <1> 	mov	esi, edi
  8033                              <1> m_pix_op_w_x_next:
  8034 0000EDFD 52                  <1> 	push	edx
  8035 0000EDFE 51                  <1> 	push	ecx
  8036 0000EDFF 56                  <1> 	push	esi
  8037 0000EE00 57                  <1> 	push	edi
  8038 0000EE01 50                  <1> 	push	eax ; 26/02/2021
  8039 0000EE02 8B0D[AEA30100]      <1> 	mov	ecx, [pixcount] ; 27/02/2021
  8040 0000EE08 FFD5                <1> 	call	ebp ; call masked pixel-row operation
  8041 0000EE0A 58                  <1> 	pop	eax ; 26/02/2021
  8042 0000EE0B 5F                  <1> 	pop	edi
  8043 0000EE0C 5E                  <1> 	pop	esi
  8044 0000EE0D 59                  <1> 	pop	ecx
  8045 0000EE0E 5A                  <1> 	pop	edx
  8046 0000EE0F 01D6                <1> 	add	esi, edx ; next row
  8047 0000EE11 01D7                <1> 	add	edi, edx ; next row
  8048 0000EE13 4B                  <1> 	dec	ebx
  8049 0000EE14 75E7                <1> 	jnz	short m_pix_op_w_x_next
  8050 0000EE16 C3                  <1> 	retn
  8051                              <1> 
  8052                              <1> m_pix_op_add:
  8053                              <1> 	; 06/02/2021
  8054                              <1> 	; ADD COLOR (MASKED, full screen)
  8055                              <1> 	;
  8056                              <1> 	; jump from pix_op_add
  8057                              <1> 	;
  8058                              <1> 	; INPUT:
  8059                              <1> 	;   eax = color (AL, AX, EAX)
  8060                              <1> 	;   ecx = [v_siz] ; display page pixel count
  8061                              <1> 	;   esi = edi = [v_mem] ; LFB start address
  8062                              <1> 	;
  8063                              <1> 	;   [maskcolor] = mask color (to be excluded)
  8064                              <1> 	;
  8065                              <1> 	; OUTPUT:
  8066                              <1> 	; 	[u.r0] will be > 0 if succesful
  8067                              <1> 
  8068                              <1> 	; Full screen
  8069                              <1> m_pix_op_add_0:
  8070 0000EE17 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  8071 0000EE1E 771C                <1> 	ja	short m_pix_op_add_1
  8072                              <1> 	; 256 colors (8bpp)
  8073                              <1> 	;jmp	short m_pix_op_add_8
  8074                              <1> m_pix_op_add_8:
  8075                              <1> 	; 8 bit colors (256 colors)
  8076 0000EE20 88C2                <1> 	mov	dl, al ; new color
  8077                              <1> m_pix_op_add_8_0:
  8078 0000EE22 AC                  <1> 	lodsb 
  8079 0000EE23 3A05[AAA30100]      <1> 	cmp	al, [maskcolor]
  8080 0000EE29 740D                <1> 	je	short m_pix_op_add_8_1 ; exclude
  8081 0000EE2B FF05[74940100]      <1> 	inc	dword [u.r0] ; +1
  8082 0000EE31 0017                <1> 	add	[edi], dl
  8083 0000EE33 7303                <1> 	jnc	short m_pix_op_add_8_1
  8084 0000EE35 C607FF              <1> 	mov	byte [edi], 0FFh 
  8085                              <1> m_pix_op_add_8_1:
  8086 0000EE38 47                  <1> 	inc	edi
  8087 0000EE39 E2E7                <1> 	loop	m_pix_op_add_8_0
  8088 0000EE3B C3                  <1> 	retn
  8089                              <1> m_pix_op_add_1:
  8090 0000EE3C 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  8091 0000EE43 775E                <1> 	ja	short m_pix_op_add_3 ; 32bpp
  8092 0000EE45 7238                <1> 	jb	short m_pix_op_add_2 ; 16bpp
  8093                              <1> 	; 24 bit true colors
  8094                              <1> 	;jmp	short m_pix_op_add_24
  8095                              <1> m_pix_op_add_24:
  8096                              <1> 	; 24 bit true colors
  8097 0000EE47 89C2                <1> 	mov	edx, eax ; new color
  8098 0000EE49 81CA000000FF        <1> 	or	edx, 0FF000000h
  8099                              <1> m_pix_op_add_24_0:
  8100 0000EE4F 66AD                <1> 	lodsw
  8101 0000EE51 C1E010              <1> 	shl	eax, 16
  8102 0000EE54 AC                  <1> 	lodsb
  8103 0000EE55 C1C010              <1> 	rol	eax, 16	
  8104 0000EE58 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  8105 0000EE5E 7419                <1> 	je	short m_pix_op_add_24_2 ; exclude
  8106 0000EE60 8305[74940100]03    <1> 	add	dword [u.r0], 3 ; +3
  8107 0000EE67 01D0                <1> 	add	eax, edx
  8108 0000EE69 7305                <1> 	jnc	short m_pix_op_add_24_1
  8109 0000EE6B B8FFFFFF00          <1> 	mov	eax, 0FFFFFFh
  8110                              <1> m_pix_op_add_24_1:	
  8111 0000EE70 668907              <1> 	mov	[edi], ax
  8112 0000EE73 C1E810              <1> 	shr	eax, 16
  8113 0000EE76 884702              <1> 	mov	[edi+2], al
  8114                              <1> m_pix_op_add_24_2:
  8115 0000EE79 83C703              <1> 	add	edi, 3 ; +3
  8116 0000EE7C E2D1                <1> 	loop	m_pix_op_add_24_0
  8117 0000EE7E C3                  <1> 	retn
  8118                              <1> 	; 65536 colors (16bpp)
  8119                              <1> m_pix_op_add_2:
  8120                              <1> 	;jmp	short m_pix_op_add_16
  8121                              <1> m_pix_op_add_16:
  8122                              <1> 	; 16 bit colors (65536 colors)
  8123 0000EE7F 89C2                <1> 	mov	edx, eax ; new color
  8124                              <1> m_pix_op_add_16_0:
  8125 0000EE81 66AD                <1> 	lodsw
  8126 0000EE83 663B05[AAA30100]    <1> 	cmp	ax, [maskcolor]
  8127 0000EE8A 7411                <1> 	je	short m_pix_op_add_16_1 ; exclude
  8128 0000EE8C 8305[74940100]02    <1> 	add	dword [u.r0], 2 ; +2
  8129 0000EE93 660117              <1> 	add	[edi], dx
  8130 0000EE96 7305                <1> 	jnc	short m_pix_op_add_16_1
  8131 0000EE98 66C707FFFF          <1> 	mov	word [edi], 0FFFFh
  8132                              <1> m_pix_op_add_16_1:
  8133 0000EE9D 83C702              <1> 	add	edi, 2 ; +2
  8134 0000EEA0 E2DF                <1> 	loop	m_pix_op_add_16_0
  8135 0000EEA2 C3                  <1> 	retn
  8136                              <1> m_pix_op_add_3:
  8137                              <1> 	; 32 bit true colors
  8138                              <1> 	;jmp	short m_pix_op_add_32
  8139                              <1> m_pix_op_add_32:
  8140                              <1> 	; 32 bit true colors
  8141 0000EEA3 89C2                <1> 	mov	edx, eax ; new color
  8142                              <1> m_pix_op_add_32_0:
  8143 0000EEA5 AD                  <1> 	lodsd
  8144 0000EEA6 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  8145 0000EEAC 7411                <1> 	je	short m_pix_op_add_32_1 ; exclude
  8146 0000EEAE 8305[74940100]04    <1> 	add	dword [u.r0], 4 ; +4
  8147 0000EEB5 0117                <1> 	add	[edi], edx
  8148 0000EEB7 7306                <1> 	jnc	short m_pix_op_add_32_1
  8149 0000EEB9 C707FFFFFFFF        <1> 	mov	dword [edi], 0FFFFFFFFh
  8150                              <1> m_pix_op_add_32_1:
  8151 0000EEBF 83C704              <1> 	add	edi, 4 ; +4
  8152 0000EEC2 E2E1                <1> 	loop	m_pix_op_add_32_0
  8153 0000EEC4 C3                  <1> 	retn
  8154                              <1> 
  8155                              <1> m_pix_op_add_w:
  8156                              <1> 	; 06/02/2021
  8157                              <1> 	; ADD COLOR (MASKED, window)
  8158                              <1> 	;
  8159                              <1> 	; jump from pix_op_add_w
  8160                              <1> 	;
  8161                              <1> 	; INPUT:
  8162                              <1> 	;   ecx = bytes per row (to be applied)
  8163                              <1> 	;   edx = screen width in bytes
  8164                              <1> 	;   ebx = row count
  8165                              <1> 	;   eax = color
  8166                              <1> 	;
  8167                              <1> 	;   [maskcolor] = mask color (to be excluded)
  8168                              <1> 	;
  8169                              <1> 	; OUTPUT:
  8170                              <1> 	; 	[u.r0] will be > 0 if succesful
  8171                              <1> 
  8172                              <1> 	; window
  8173                              <1> 	;mov	edi, [v_str] ; LFB start address
  8174                              <1> 	;mov	esi, edi 
  8175                              <1> 
  8176 0000EEC5 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  8177 0000EECC 7707                <1> 	ja	short m_pix_op_add_w_1
  8178                              <1> 
  8179                              <1> 	; 256 colors (8bpp)
  8180 0000EECE BD[20EE0000]        <1> 	mov	ebp, m_pix_op_add_8
  8181 0000EED3 EB1E                <1> 	jmp	short m_pix_op_add_w_4
  8182                              <1> 
  8183                              <1> m_pix_op_add_w_1:
  8184 0000EED5 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  8185 0000EEDC 7710                <1> 	ja	short m_pix_op_add_w_3 ; 32bpp
  8186 0000EEDE 7207                <1> 	jb	short m_pix_op_add_w_2 ; 16bpp
  8187                              <1> 
  8188                              <1> 	; 24 bit true colors
  8189 0000EEE0 BD[47EE0000]        <1> 	mov	ebp, m_pix_op_add_24
  8190 0000EEE5 EB0C                <1> 	jmp	short m_pix_op_add_w_4
  8191                              <1> 
  8192                              <1> 	; 65536 colors (16bpp)
  8193                              <1> m_pix_op_add_w_2:
  8194 0000EEE7 BD[7FEE0000]        <1> 	mov	ebp, m_pix_op_add_16
  8195 0000EEEC EB05                <1> 	jmp	short m_pix_op_add_w_4
  8196                              <1> 
  8197                              <1> 	; 32 bit true colors
  8198                              <1> m_pix_op_add_w_3:
  8199 0000EEEE BD[A3EE0000]        <1> 	mov	ebp, m_pix_op_add_32
  8200                              <1> m_pix_op_add_w_4:
  8201 0000EEF3 E9FDFEFFFF          <1> 	jmp	m_pix_op_add_w_x
  8202                              <1> 
  8203                              <1> m_pix_op_sub:
  8204                              <1> 	; 02/03/2021
  8205                              <1> 	; 06/02/2021
  8206                              <1> 	; SUBTRACT COLOR (MASKED, full screen)
  8207                              <1> 	;
  8208                              <1> 	; jump from pix_op_sub
  8209                              <1> 	;
  8210                              <1> 	; INPUT:
  8211                              <1> 	;   eax = color (AL, AX, EAX)
  8212                              <1> 	;   ecx = [v_siz] ; display page pixel count
  8213                              <1> 	;   esi = edi = [v_mem] ; LFB start address
  8214                              <1> 	;
  8215                              <1> 	;   [maskcolor] = mask color (to be excluded)
  8216                              <1> 	;
  8217                              <1> 	; OUTPUT:
  8218                              <1> 	; 	[u.r0] will be > 0 if succesful
  8219                              <1> 
  8220                              <1> 	; Full screen
  8221                              <1> m_pix_op_sub_0:
  8222 0000EEF8 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  8223 0000EEFF 771C                <1> 	ja	short m_pix_op_sub_1
  8224                              <1> 	; 256 colors (8bpp)
  8225                              <1> 	;jmp	short m_pix_op_sub_8
  8226                              <1> m_pix_op_sub_8:
  8227                              <1> 	; 8 bit colors (256 colors)
  8228 0000EF01 88C2                <1> 	mov	dl, al ; new color
  8229                              <1> m_pix_op_sub_8_0:
  8230 0000EF03 AC                  <1> 	lodsb
  8231 0000EF04 3A05[AAA30100]      <1> 	cmp	al, [maskcolor]
  8232 0000EF0A 740D                <1> 	je	short m_pix_op_sub_8_1 ; exclude
  8233 0000EF0C FF05[74940100]      <1> 	inc	dword [u.r0] ; +1
  8234 0000EF12 2817                <1> 	sub	[edi], dl
  8235 0000EF14 7303                <1> 	jnb	short m_pix_op_sub_8_1
  8236 0000EF16 C60700              <1> 	mov	byte [edi], 0 
  8237                              <1> m_pix_op_sub_8_1:
  8238 0000EF19 47                  <1> 	inc	edi
  8239 0000EF1A E2E7                <1> 	loop	m_pix_op_sub_8_0
  8240 0000EF1C C3                  <1> 	retn
  8241                              <1> m_pix_op_sub_1:
  8242 0000EF1D 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  8243 0000EF24 7755                <1> 	ja	short m_pix_op_sub_3 ; 32bpp
  8244 0000EF26 722F                <1> 	jb	short m_pix_op_sub_2 ; 16bpp
  8245                              <1> 	; 24 bit true colors
  8246                              <1> 	;jmp	short m_pix_op_sub_24
  8247                              <1> m_pix_op_sub_24:
  8248                              <1> 	; 24 bit true colors
  8249 0000EF28 89C2                <1> 	mov	edx, eax ; new color
  8250                              <1> 	; 02/03/2021
  8251                              <1> m_pix_op_sub_24_0:
  8252 0000EF2A 66AD                <1> 	lodsw
  8253 0000EF2C C1E010              <1> 	shl	eax, 16
  8254 0000EF2F AC                  <1> 	lodsb
  8255 0000EF30 C1C010              <1> 	rol	eax, 16
  8256 0000EF33 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  8257 0000EF39 7416                <1> 	je	short m_pix_op_sub_24_2 ; exclude
  8258 0000EF3B 8305[74940100]03    <1> 	add	dword [u.r0], 3 ; +3
  8259 0000EF42 29D0                <1> 	sub	eax, edx
  8260 0000EF44 7302                <1> 	jnb	short m_pix_op_sub_24_1
  8261 0000EF46 31C0                <1> 	xor	eax, eax ; 0
  8262                              <1> m_pix_op_sub_24_1:
  8263 0000EF48 668907              <1> 	mov	[edi], ax
  8264 0000EF4B C1E810              <1> 	shr	eax, 16
  8265 0000EF4E 884702              <1> 	mov	[edi+2], al
  8266                              <1> m_pix_op_sub_24_2:
  8267 0000EF51 83C703              <1> 	add	edi, 3 ; +3
  8268 0000EF54 E2D4                <1> 	loop	m_pix_op_sub_24_0
  8269 0000EF56 C3                  <1> 	retn
  8270                              <1> 	; 65536 colors (16bpp)
  8271                              <1> m_pix_op_sub_2:
  8272                              <1> 	;jmp	short m_pix_op_sub_16
  8273                              <1> m_pix_op_sub_16:
  8274                              <1> 	; 16 bit colors (65536 colors)
  8275 0000EF57 89C2                <1> 	mov	edx, eax ; new color
  8276                              <1> m_pix_op_sub_16_0:
  8277 0000EF59 66AD                <1> 	lodsw
  8278 0000EF5B 663B05[AAA30100]    <1> 	cmp	ax, [maskcolor]
  8279 0000EF62 7411                <1> 	je	short m_pix_op_sub_16_1 ; exclude
  8280 0000EF64 8305[74940100]02    <1> 	add	dword [u.r0], 2 ; +2
  8281 0000EF6B 662917              <1> 	sub	[edi], dx
  8282 0000EF6E 7305                <1> 	jnb	short m_pix_op_sub_16_1
  8283 0000EF70 31C0                <1> 	xor	eax, eax
  8284 0000EF72 668907              <1> 	mov	[edi], ax ; 0
  8285                              <1> m_pix_op_sub_16_1:
  8286 0000EF75 83C702              <1> 	add	edi, 2 ; +2
  8287 0000EF78 E2DF                <1> 	loop	m_pix_op_sub_16_0
  8288 0000EF7A C3                  <1> 	retn
  8289                              <1> m_pix_op_sub_3:
  8290                              <1> 	; 32 bit true colors
  8291                              <1> 	;jmp	short m_pix_op_sub_32
  8292                              <1> m_pix_op_sub_32:
  8293                              <1> 	; 32 bit true colors
  8294 0000EF7B 89C2                <1> 	mov	edx, eax ; new color
  8295                              <1> m_pix_op_sub_32_0:
  8296 0000EF7D AD                  <1> 	lodsd 
  8297 0000EF7E 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  8298 0000EF84 740F                <1> 	je	short m_pix_op_sub_32_1 ; exclude
  8299 0000EF86 8305[74940100]04    <1> 	add	dword [u.r0], 4 ; +4
  8300 0000EF8D 2917                <1> 	sub	[edi], edx
  8301 0000EF8F 7304                <1> 	jnb	short m_pix_op_sub_32_1
  8302 0000EF91 31C0                <1> 	xor	eax, eax
  8303 0000EF93 8907                <1> 	mov	[edi], eax ; 0
  8304                              <1> m_pix_op_sub_32_1:
  8305 0000EF95 83C704              <1> 	add	edi, 4 ; +4
  8306 0000EF98 E2E3                <1> 	loop	m_pix_op_sub_32_0
  8307 0000EF9A C3                  <1> 	retn
  8308                              <1> 
  8309                              <1> m_pix_op_sub_w:
  8310                              <1> 	; 06/02/2021
  8311                              <1> 	; SUBTRACT COLOR (MASKED, window)
  8312                              <1> 	;
  8313                              <1> 	; jump from pix_op_sub_w
  8314                              <1> 	;
  8315                              <1> 	; INPUT:
  8316                              <1> 	;   ecx = bytes per row (to be applied)
  8317                              <1> 	;   edx = screen width in bytes
  8318                              <1> 	;   ebx = row count
  8319                              <1> 	;   eax = color
  8320                              <1> 	;
  8321                              <1> 	;   [maskcolor] = mask color (to be excluded)
  8322                              <1> 	;
  8323                              <1> 	; OUTPUT:
  8324                              <1> 	; 	[u.r0] will be > 0 if succesful
  8325                              <1> 
  8326                              <1> 	; window
  8327                              <1> 	;mov	edi, [v_str] ; LFB start address
  8328                              <1> 	;mov	esi, edi 
  8329                              <1> 
  8330 0000EF9B 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  8331 0000EFA2 7707                <1> 	ja	short m_pix_op_sub_w_1
  8332                              <1> 
  8333                              <1> 	; 256 colors (8bpp)
  8334 0000EFA4 BD[01EF0000]        <1> 	mov	ebp, m_pix_op_sub_8
  8335 0000EFA9 EB1E                <1> 	jmp	short m_pix_op_sub_w_4
  8336                              <1> 
  8337                              <1> m_pix_op_sub_w_1:
  8338 0000EFAB 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  8339 0000EFB2 7710                <1> 	ja	short m_pix_op_sub_w_3 ; 32bpp
  8340 0000EFB4 7207                <1> 	jb	short m_pix_op_sub_w_2 ; 16bpp
  8341                              <1> 
  8342                              <1> 	; 24 bit true colors
  8343 0000EFB6 BD[28EF0000]        <1> 	mov	ebp, m_pix_op_sub_24
  8344 0000EFBB EB0C                <1> 	jmp	short m_pix_op_sub_w_4
  8345                              <1> 
  8346                              <1> 	; 65536 colors (16bpp)
  8347                              <1> m_pix_op_sub_w_2:
  8348 0000EFBD BD[57EF0000]        <1> 	mov	ebp, m_pix_op_sub_16
  8349 0000EFC2 EB05                <1> 	jmp	short m_pix_op_sub_w_4
  8350                              <1> 
  8351                              <1> 	; 32 bit true colors
  8352                              <1> m_pix_op_sub_w_3:
  8353 0000EFC4 BD[7BEF0000]        <1> 	mov	ebp, m_pix_op_sub_32
  8354                              <1> m_pix_op_sub_w_4:
  8355 0000EFC9 E927FEFFFF          <1> 	jmp	m_pix_op_sub_w_x
  8356                              <1> 
  8357                              <1> m_pix_op_mix:
  8358                              <1> 	; 25/02/2021
  8359                              <1> 	; 06/02/2021
  8360                              <1> 	; MIX COLOR (MASKED, full screen)
  8361                              <1> 	;
  8362                              <1> 	; jump from pix_op_mix
  8363                              <1> 	;
  8364                              <1> 	; INPUT:
  8365                              <1> 	;   eax = color (AL, AX, EAX)
  8366                              <1> 	;   ecx = [v_siz] ; display page pixel count
  8367                              <1> 	;   esi = edi = [v_mem] ; LFB start address
  8368                              <1> 	;
  8369                              <1> 	;   [maskcolor] = mask color (to be excluded)
  8370                              <1> 	;
  8371                              <1> 	; OUTPUT:
  8372                              <1> 	; 	[u.r0] will be > 0 if succesful
  8373                              <1> 
  8374                              <1> 	; Full screen
  8375                              <1> m_pix_op_mix_0:
  8376 0000EFCE 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  8377 0000EFD5 771B                <1> 	ja	short m_pix_op_mix_1
  8378                              <1> 	; 256 colors (8bpp)
  8379                              <1> 	;jmp	short m_pix_op_mix_8
  8380                              <1> m_pix_op_mix_8:
  8381                              <1> 	; 8 bit colors (256 colors)
  8382 0000EFD7 88C2                <1> 	mov	dl, al ; new (mixing) color
  8383                              <1> m_pix_op_mix_8_0:
  8384 0000EFD9 AC                  <1> 	lodsb 
  8385 0000EFDA 3A05[AAA30100]      <1> 	cmp	al, [maskcolor]
  8386 0000EFE0 740C                <1> 	je	short m_pix_op_mix_8_1 ; exclude
  8387 0000EFE2 00D0                <1> 	add	al, dl ; 25/02/2021
  8388 0000EFE4 D0D8                <1> 	rcr	al, 1	
  8389 0000EFE6 8807                <1> 	mov	[edi], al
  8390 0000EFE8 FF05[74940100]      <1> 	inc	dword [u.r0] ; +1
  8391                              <1> m_pix_op_mix_8_1:
  8392 0000EFEE 47                  <1> 	inc	edi
  8393 0000EFEF E2E8                <1> 	loop	m_pix_op_mix_8_0
  8394 0000EFF1 C3                  <1> 	retn
  8395                              <1> m_pix_op_mix_1:
  8396 0000EFF2 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  8397 0000EFF9 7752                <1> 	ja	short m_pix_op_mix_3 ; 32bpp
  8398 0000EFFB 722D                <1> 	jb	short m_pix_op_mix_2 ; 16bpp
  8399                              <1> 	; 24 bit true colors
  8400                              <1> 	;jmp	short m_pix_op_mix_24
  8401                              <1> m_pix_op_mix_24:
  8402                              <1> 	; 24 bit true colors
  8403 0000EFFD 89C2                <1> 	mov	edx, eax ; new color
  8404                              <1> 	;and	edx, 0FFFFFFh
  8405                              <1> m_pix_op_mix_24_0:
  8406 0000EFFF 66AD                <1> 	lodsw
  8407 0000F001 C1E010              <1> 	shl	eax, 16
  8408 0000F004 AC                  <1> 	lodsb
  8409 0000F005 C1C010              <1> 	rol	eax, 16	
  8410 0000F008 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  8411 0000F00E 7414                <1> 	je	short m_pix_op_mix_24_1 ; exclude
  8412 0000F010 01D0                <1> 	add	eax, edx
  8413 0000F012 D1E8                <1> 	shr	eax, 1
  8414 0000F014 668907              <1> 	mov	[edi], ax
  8415 0000F017 C1E810              <1> 	shr	eax, 16
  8416 0000F01A 884702              <1> 	mov	[edi+2], al
  8417 0000F01D 8305[74940100]03    <1> 	add	dword [u.r0], 3 ; +3
  8418                              <1> m_pix_op_mix_24_1:
  8419 0000F024 83C703              <1> 	add	edi, 3 ; +3
  8420 0000F027 E2D6                <1> 	loop	m_pix_op_mix_24_0
  8421 0000F029 C3                  <1> 	retn
  8422                              <1> 	; 65536 colors (16bpp)
  8423                              <1> m_pix_op_mix_2:
  8424                              <1> 	;jmp	short m_pix_op_mix_16
  8425                              <1> m_pix_op_mix_16:
  8426                              <1> 	; 16 bit colors (65536 colors)
  8427 0000F02A 89C2                <1> 	mov	edx, eax ; new color
  8428                              <1> 	;and	edx, 0FFFFh
  8429                              <1> m_pix_op_mix_16_0:
  8430 0000F02C 66AD                <1> 	lodsw
  8431 0000F02E 663B05[AAA30100]    <1> 	cmp	ax, [maskcolor]
  8432 0000F035 7410                <1> 	je	short m_pix_op_mix_16_1 ; exclude
  8433 0000F037 6601D0              <1> 	add	ax, dx
  8434 0000F03A 66D1D8              <1> 	rcr	ax, 1
  8435 0000F03D 668907              <1> 	mov	[edi], ax
  8436 0000F040 8305[74940100]02    <1> 	add	dword [u.r0], 2 ; +2
  8437                              <1> m_pix_op_mix_16_1:
  8438 0000F047 83C702              <1> 	add	edi, 2 ; +2
  8439 0000F04A E2E0                <1> 	loop	m_pix_op_mix_16_0
  8440 0000F04C C3                  <1> 	retn
  8441                              <1> m_pix_op_mix_3:
  8442                              <1> 	; 32 bit true colors
  8443                              <1> 	;jmp	short m_pix_op_mix_32
  8444                              <1> m_pix_op_mix_32:
  8445                              <1> 	; 32 bit true colors
  8446 0000F04D 89C2                <1> 	mov	edx, eax ; new color
  8447                              <1> m_pix_op_mix_32_0:
  8448 0000F04F AD                  <1> 	lodsd 
  8449 0000F050 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  8450 0000F056 740D                <1> 	je	short m_pix_op_mix_32_1 ; exclude
  8451 0000F058 01D0                <1> 	add	eax, edx
  8452                              <1> 	; 02/03/2021
  8453 0000F05A D1D8                <1> 	rcr	eax, 1
  8454 0000F05C 8907                <1> 	mov	[edi], eax
  8455 0000F05E 8305[74940100]04    <1> 	add	dword [u.r0], 4 ; +4
  8456                              <1> m_pix_op_mix_32_1:
  8457 0000F065 83C704              <1> 	add	edi, 4 ; +4
  8458 0000F068 E2E5                <1> 	loop	m_pix_op_mix_32_0
  8459 0000F06A C3                  <1> 	retn
  8460                              <1> 
  8461                              <1> m_pix_op_mix_w:
  8462                              <1> 	; 06/02/2021
  8463                              <1> 	; MIX COLOR (MASKED, window)
  8464                              <1> 	;
  8465                              <1> 	; jump from pix_op_mix_w
  8466                              <1> 	;
  8467                              <1> 	; INPUT:
  8468                              <1> 	;   ecx = bytes per row (to be applied)
  8469                              <1> 	;   edx = screen width in bytes
  8470                              <1> 	;   ebx = row count
  8471                              <1> 	;   eax = color
  8472                              <1> 	;
  8473                              <1> 	;   [maskcolor] = mask color (to be excluded)
  8474                              <1> 	;
  8475                              <1> 	; OUTPUT:
  8476                              <1> 	; 	[u.r0] will be > 0 if succesful
  8477                              <1> 
  8478                              <1> 	; window
  8479                              <1> 	;mov	edi, [v_str] ; LFB start address
  8480                              <1> 	;mov	esi, edi
  8481                              <1> 
  8482 0000F06B 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  8483 0000F072 7707                <1> 	ja	short m_pix_op_mix_w_1
  8484                              <1> 
  8485                              <1> 	; 256 colors (8bpp)
  8486 0000F074 BD[D7EF0000]        <1> 	mov	ebp, m_pix_op_mix_8
  8487 0000F079 EB1E                <1> 	jmp	short m_pix_op_mix_w_4
  8488                              <1> 
  8489                              <1> m_pix_op_mix_w_1:
  8490 0000F07B 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  8491 0000F082 7710                <1> 	ja	short m_pix_op_mix_w_3 ; 32bpp
  8492 0000F084 7207                <1> 	jb	short m_pix_op_mix_w_2 ; 16bpp
  8493                              <1> 
  8494                              <1> 	; 24 bit true colors
  8495 0000F086 BD[FDEF0000]        <1> 	mov	ebp, m_pix_op_mix_24
  8496 0000F08B EB0C                <1> 	jmp	short m_pix_op_mix_w_4
  8497                              <1> 
  8498                              <1> 	; 65536 colors (16bpp)
  8499                              <1> m_pix_op_mix_w_2:
  8500 0000F08D BD[2AF00000]        <1> 	mov	ebp, m_pix_op_mix_16
  8501 0000F092 EB05                <1> 	jmp	short m_pix_op_mix_w_4
  8502                              <1> 
  8503                              <1> 	; 32 bit true colors
  8504                              <1> m_pix_op_mix_w_3:
  8505 0000F094 BD[4DF00000]        <1> 	mov	ebp, m_pix_op_mix_32
  8506                              <1> m_pix_op_mix_w_4:
  8507 0000F099 E957FDFFFF          <1> 	jmp	m_pix_op_mix_w_x
  8508                              <1> 
  8509                              <1> m_pix_op_and:
  8510                              <1> 	; 06/02/2021
  8511                              <1> 	; AND COLOR (MASKED, full screen)
  8512                              <1> 	;
  8513                              <1> 	; jump from pix_op_and
  8514                              <1> 	;
  8515                              <1> 	; INPUT:
  8516                              <1> 	;   eax = color (AL, AX, EAX)
  8517                              <1> 	;   ecx = [v_siz] ; display page pixel count
  8518                              <1> 	;   esi = edi = [v_mem] ; LFB start address
  8519                              <1> 	;
  8520                              <1> 	;   [maskcolor] = mask color (to be excluded)
  8521                              <1> 	;
  8522                              <1> 	; OUTPUT:
  8523                              <1> 	; 	[u.r0] will be > 0 if succesful
  8524                              <1> 
  8525                              <1> 	; Full screen
  8526                              <1> m_pix_op_and_0:
  8527 0000F09E 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  8528 0000F0A5 7717                <1> 	ja	short m_pix_op_and_1
  8529                              <1> 	; 256 colors (8bpp)
  8530                              <1> 	;jmp	short m_pix_op_and_8
  8531                              <1> m_pix_op_and_8:
  8532                              <1> 	; 8 bit colors (256 colors)
  8533 0000F0A7 88C2                <1> 	mov	dl, al ; new color
  8534                              <1> m_pix_op_and_8_0:
  8535 0000F0A9 AC                  <1> 	lodsb
  8536 0000F0AA 3A05[AAA30100]      <1> 	cmp	al, [maskcolor]
  8537 0000F0B0 7408                <1> 	je	short m_pix_op_and_8_1 ; exclude
  8538 0000F0B2 2017                <1> 	and	[edi], dl
  8539 0000F0B4 FF05[74940100]      <1> 	inc	dword [u.r0] ; +1
  8540                              <1> m_pix_op_and_8_1:
  8541 0000F0BA 47                  <1> 	inc	edi
  8542 0000F0BB E2EC                <1> 	loop	m_pix_op_and_8_0
  8543 0000F0BD C3                  <1> 	retn
  8544                              <1> m_pix_op_and_1:
  8545 0000F0BE 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  8546 0000F0C5 774A                <1> 	ja	short m_pix_op_and_3 ; 32bpp
  8547 0000F0C7 722B                <1> 	jb	short m_pix_op_and_2 ; 16bpp
  8548                              <1> 	; 24 bit true colors
  8549                              <1> 	;jmp	short m_pix_op_and_24
  8550                              <1> m_pix_op_and_24:
  8551                              <1> 	; 24 bit true colors
  8552 0000F0C9 89C2                <1> 	mov	edx, eax ; new color
  8553                              <1> 	;and	edx, 0FFFFFFh
  8554                              <1> m_pix_op_and_24_0:
  8555 0000F0CB 66AD                <1> 	lodsw
  8556 0000F0CD C1E010              <1> 	shl	eax, 16
  8557 0000F0D0 AC                  <1> 	lodsb
  8558 0000F0D1 C1C010              <1> 	rol	eax, 16	
  8559 0000F0D4 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  8560 0000F0DA 7412                <1> 	je	short m_pix_op_and_24_1 ; exclude
  8561 0000F0DC 21D0                <1> 	and	eax, edx
  8562 0000F0DE 668907              <1> 	mov	[edi], ax
  8563 0000F0E1 C1E810              <1> 	shr	eax, 16
  8564 0000F0E4 884702              <1> 	mov	[edi+2], al
  8565 0000F0E7 8305[74940100]03    <1> 	add	dword [u.r0], 3 ; +3
  8566                              <1> m_pix_op_and_24_1:
  8567 0000F0EE 83C703              <1> 	add	edi, 3 ; +3
  8568 0000F0F1 E2D8                <1> 	loop	m_pix_op_and_24_0
  8569 0000F0F3 C3                  <1> 	retn
  8570                              <1> 	; 65536 colors (16bpp)
  8571                              <1> m_pix_op_and_2:
  8572                              <1> 	;jmp	short m_pix_op_and_16
  8573                              <1> m_pix_op_and_16:
  8574                              <1> 	; 16 bit colors (65536 colors)
  8575 0000F0F4 89C2                <1> 	mov	edx, eax ; new color
  8576                              <1> 	;and	edx, 0FFFFh
  8577                              <1> m_pix_op_and_16_0:
  8578 0000F0F6 66AD                <1> 	lodsw
  8579 0000F0F8 663B05[AAA30100]    <1> 	cmp	ax, [maskcolor]
  8580 0000F0FF 740A                <1> 	je	short m_pix_op_and_16_1 ; exclude
  8581 0000F101 662117              <1> 	and	[edi], dx
  8582 0000F104 8305[74940100]02    <1> 	add	dword [u.r0], 2 ; +2
  8583                              <1> m_pix_op_and_16_1:
  8584 0000F10B 83C702              <1> 	add	edi, 2 ; +2
  8585 0000F10E E2E6                <1> 	loop	m_pix_op_and_16_0
  8586 0000F110 C3                  <1> 	retn
  8587                              <1> m_pix_op_and_3:
  8588                              <1> 	; 32 bit true colors
  8589                              <1> 	;jmp	short m_pix_op_and_32
  8590                              <1> m_pix_op_and_32:
  8591                              <1> 	; 32 bit true colors
  8592 0000F111 89C2                <1> 	mov	edx, eax ; new color
  8593                              <1> m_pix_op_and_32_0:
  8594 0000F113 AD                  <1> 	lodsd 
  8595 0000F114 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  8596 0000F11A 7409                <1> 	je	short m_pix_op_and_32_1 ; exclude
  8597 0000F11C 2117                <1> 	and	[edi], edx ; 25/02/2021
  8598 0000F11E 8305[74940100]04    <1> 	add	dword [u.r0], 4 ; +4
  8599                              <1> m_pix_op_and_32_1:
  8600 0000F125 83C704              <1> 	add	edi, 4 ; +4
  8601 0000F128 E2E9                <1> 	loop	m_pix_op_and_32_0
  8602 0000F12A C3                  <1> 	retn
  8603                              <1> 
  8604                              <1> m_pix_op_and_w:
  8605                              <1> 	; 06/02/2021
  8606                              <1> 	; AND COLOR (MASKED, window)
  8607                              <1> 	;
  8608                              <1> 	; jump from pix_op_and_w
  8609                              <1> 	;
  8610                              <1> 	; INPUT:
  8611                              <1> 	;   ecx = bytes per row (to be applied)
  8612                              <1> 	;   edx = screen width in bytes
  8613                              <1> 	;   ebx = row count
  8614                              <1> 	;   eax = color
  8615                              <1> 	;
  8616                              <1> 	;   [maskcolor] = mask color (to be excluded)
  8617                              <1> 	;
  8618                              <1> 	; OUTPUT:
  8619                              <1> 	; 	[u.r0] will be > 0 if succesful
  8620                              <1> 
  8621                              <1> 	; window
  8622                              <1> 	;mov	edi, [v_str] ; LFB start address
  8623                              <1> 	;mov	esi, edi 
  8624                              <1> 
  8625 0000F12B 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  8626 0000F132 7707                <1> 	ja	short m_pix_op_and_w_1
  8627                              <1> 
  8628                              <1> 	; 256 colors (8bpp)
  8629 0000F134 BD[A7F00000]        <1> 	mov	ebp, m_pix_op_and_8
  8630 0000F139 EB1E                <1> 	jmp	short m_pix_op_and_w_4
  8631                              <1> 
  8632                              <1> m_pix_op_and_w_1:
  8633 0000F13B 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  8634 0000F142 7710                <1> 	ja	short m_pix_op_and_w_3 ; 32bpp
  8635 0000F144 7207                <1> 	jb	short m_pix_op_and_w_2 ; 16bpp
  8636                              <1> 
  8637                              <1> 	; 24 bit true colors
  8638 0000F146 BD[C9F00000]        <1> 	mov	ebp, m_pix_op_and_24
  8639 0000F14B EB0C                <1> 	jmp	short m_pix_op_and_w_4
  8640                              <1> 
  8641                              <1> 	; 65536 colors (16bpp)
  8642                              <1> m_pix_op_and_w_2:
  8643 0000F14D BD[F4F00000]        <1> 	mov	ebp, m_pix_op_and_16
  8644 0000F152 EB05                <1> 	jmp	short m_pix_op_and_w_4
  8645                              <1> 
  8646                              <1> 	; 32 bit true colors
  8647                              <1> m_pix_op_and_w_3:
  8648 0000F154 BD[11F10000]        <1> 	mov	ebp, m_pix_op_and_32
  8649                              <1> m_pix_op_and_w_4:
  8650 0000F159 E997FCFFFF          <1> 	jmp	m_pix_op_and_w_x
  8651                              <1> 
  8652                              <1> m_pix_op_or:
  8653                              <1> 	; 06/02/2021
  8654                              <1> 	; OR COLOR (MASKED, full screen)
  8655                              <1> 	;
  8656                              <1> 	; jump from pix_op_orc
  8657                              <1> 	;
  8658                              <1> 	; INPUT:
  8659                              <1> 	;   eax = color (AL, AX, EAX)
  8660                              <1> 	;   ecx = [v_siz] ; display page pixel count
  8661                              <1> 	;   esi = edi = [v_mem] ; LFB start address
  8662                              <1> 	;
  8663                              <1> 	;   [maskcolor] = mask color (to be excluded)
  8664                              <1> 	;
  8665                              <1> 	; OUTPUT:
  8666                              <1> 	; 	[u.r0] will be > 0 if succesful
  8667                              <1> 
  8668                              <1> 	; Full screen
  8669                              <1> m_pix_op_or_0:
  8670 0000F15E 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  8671 0000F165 7717                <1> 	ja	short m_pix_op_or_1
  8672                              <1> 	; 256 colors (8bpp)
  8673                              <1> 	;jmp	short m_pix_op_or_8
  8674                              <1> m_pix_op_or_8:
  8675                              <1> 	; 8 bit colors (256 colors)
  8676 0000F167 88C2                <1> 	mov	dl, al ; new color
  8677                              <1> m_pix_op_or_8_0:
  8678 0000F169 AC                  <1> 	lodsb 
  8679 0000F16A 3A05[AAA30100]      <1> 	cmp	al, [maskcolor]
  8680 0000F170 7408                <1> 	je	short m_pix_op_or_8_1 ; exclude
  8681 0000F172 0817                <1> 	or	[edi], dl
  8682 0000F174 FF05[74940100]      <1> 	inc	dword [u.r0] ; +1
  8683                              <1> m_pix_op_or_8_1:
  8684 0000F17A 47                  <1> 	inc	edi
  8685 0000F17B E2EC                <1> 	loop	m_pix_op_or_8_0
  8686 0000F17D C3                  <1> 	retn
  8687                              <1> m_pix_op_or_1:
  8688 0000F17E 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  8689 0000F185 774A                <1> 	ja	short m_pix_op_or_3 ; 32bpp
  8690 0000F187 722B                <1> 	jb	short m_pix_op_or_2 ; 16bpp
  8691                              <1> 	; 24 bit true colors
  8692                              <1> 	;jmp	short m_pix_op_or_24
  8693                              <1> m_pix_op_or_24:
  8694                              <1> 	; 24 bit true colors
  8695 0000F189 89C2                <1> 	mov	edx, eax ; new color
  8696                              <1> 	;and	edx, 0FFFFFFh
  8697                              <1> m_pix_op_or_24_0:
  8698 0000F18B 66AD                <1> 	lodsw
  8699 0000F18D C1E010              <1> 	shl	eax, 16
  8700 0000F190 AC                  <1> 	lodsb
  8701 0000F191 C1C010              <1> 	rol	eax, 16	
  8702 0000F194 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  8703 0000F19A 7412                <1> 	je	short m_pix_op_or_24_1 ; exclude
  8704 0000F19C 09D0                <1> 	or	eax, edx
  8705 0000F19E 668907              <1> 	mov	[edi], ax
  8706 0000F1A1 C1E810              <1> 	shr	eax, 16
  8707 0000F1A4 884702              <1> 	mov	[edi+2], al
  8708 0000F1A7 8305[74940100]03    <1> 	add	dword [u.r0], 3 ; +3
  8709                              <1> m_pix_op_or_24_1:
  8710 0000F1AE 83C703              <1> 	add	edi, 3 ; +3
  8711 0000F1B1 E2D8                <1> 	loop	m_pix_op_or_24_0
  8712 0000F1B3 C3                  <1> 	retn
  8713                              <1> 	; 65536 colors (16bpp)
  8714                              <1> m_pix_op_or_2:
  8715                              <1> 	;jmp	short m_pix_op_or_16
  8716                              <1> m_pix_op_or_16:
  8717                              <1> 	; 16 bit colors (65536 colors)
  8718 0000F1B4 89C2                <1> 	mov	edx, eax ; new color
  8719                              <1> 	;and	edx, 0FFFFh
  8720                              <1> m_pix_op_or_16_0:
  8721 0000F1B6 66AD                <1> 	lodsw
  8722 0000F1B8 663B05[AAA30100]    <1> 	cmp	ax, [maskcolor]
  8723 0000F1BF 740A                <1> 	je	short m_pix_op_or_16_1 ; exclude
  8724 0000F1C1 660917              <1> 	or	[edi], dx
  8725 0000F1C4 8305[74940100]02    <1> 	add	dword [u.r0], 2 ; +2
  8726                              <1> m_pix_op_or_16_1:
  8727 0000F1CB 83C702              <1> 	add	edi, 2 ; +2
  8728 0000F1CE E2E6                <1> 	loop	m_pix_op_or_16_0
  8729 0000F1D0 C3                  <1> 	retn
  8730                              <1> m_pix_op_or_3:
  8731                              <1> 	; 32 bit true colors
  8732                              <1> 	;jmp	short m_pix_op_or_32
  8733                              <1> m_pix_op_or_32:
  8734                              <1> 	; 32 bit true colors
  8735 0000F1D1 89C2                <1> 	mov	edx, eax ; new color
  8736                              <1> m_pix_op_or_32_0:
  8737 0000F1D3 AD                  <1> 	lodsd 
  8738 0000F1D4 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  8739 0000F1DA 7409                <1> 	je	short m_pix_op_or_32_1 ; exclude
  8740 0000F1DC 0917                <1> 	or	[edi], edx ; 25/02/2021
  8741 0000F1DE 8305[74940100]04    <1> 	add	dword [u.r0], 4 ; +4
  8742                              <1> m_pix_op_or_32_1:
  8743 0000F1E5 83C704              <1> 	add	edi, 4 ; +4
  8744 0000F1E8 E2E9                <1> 	loop	m_pix_op_or_32_0
  8745 0000F1EA C3                  <1> 	retn
  8746                              <1> 
  8747                              <1> m_pix_op_or_w:
  8748                              <1> 	; 06/02/2021
  8749                              <1> 	; MIX COLOR (MASKED, window)
  8750                              <1> 	;
  8751                              <1> 	; jump from pix_op_or_w
  8752                              <1> 	;
  8753                              <1> 	; INPUT:
  8754                              <1> 	;   ecx = bytes per row (to be applied)
  8755                              <1> 	;   edx = screen width in bytes
  8756                              <1> 	;   ebx = row count
  8757                              <1> 	;   eax = color
  8758                              <1> 	;
  8759                              <1> 	;   [maskcolor] = mask color (to be excluded)
  8760                              <1> 	;
  8761                              <1> 	; OUTPUT:
  8762                              <1> 	; 	[u.r0] will be > 0 if succesful
  8763                              <1> 
  8764                              <1> 	; window
  8765                              <1> 	;mov	edi, [v_str] ; LFB start address
  8766                              <1> 	;mov	esi, edi 
  8767                              <1> 
  8768 0000F1EB 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  8769 0000F1F2 7707                <1> 	ja	short m_pix_op_or_w_1
  8770                              <1> 
  8771                              <1> 	; 256 colors (8bpp)
  8772 0000F1F4 BD[67F10000]        <1> 	mov	ebp, m_pix_op_or_8
  8773 0000F1F9 EB1E                <1> 	jmp	short m_pix_op_or_w_4
  8774                              <1> 
  8775                              <1> m_pix_op_or_w_1:
  8776 0000F1FB 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  8777 0000F202 7710                <1> 	ja	short m_pix_op_or_w_3 ; 32bpp
  8778 0000F204 7207                <1> 	jb	short m_pix_op_or_w_2 ; 16bpp
  8779                              <1> 
  8780                              <1> 	; 24 bit true colors
  8781 0000F206 BD[89F10000]        <1> 	mov	ebp, m_pix_op_or_24
  8782 0000F20B EB0C                <1> 	jmp	short m_pix_op_or_w_4
  8783                              <1> 
  8784                              <1> 	; 65536 colors (16bpp)
  8785                              <1> m_pix_op_or_w_2:
  8786 0000F20D BD[B4F10000]        <1> 	mov	ebp, m_pix_op_or_16
  8787 0000F212 EB05                <1> 	jmp	short m_pix_op_or_w_4
  8788                              <1> 
  8789                              <1> 	; 32 bit true colors
  8790                              <1> m_pix_op_or_w_3:
  8791 0000F214 BD[D1F10000]        <1> 	mov	ebp, m_pix_op_or_32
  8792                              <1> m_pix_op_or_w_4:
  8793 0000F219 E9D7FBFFFF          <1> 	jmp	m_pix_op_orc_w_x
  8794                              <1> 
  8795                              <1> m_pix_op_xor:
  8796                              <1> 	; 06/02/2021
  8797                              <1> 	; XOR COLOR (MASKED, full screen)
  8798                              <1> 	;
  8799                              <1> 	; jump from pix_op_xor
  8800                              <1> 	;
  8801                              <1> 	; INPUT:
  8802                              <1> 	;   eax = color (AL, AX, EAX)
  8803                              <1> 	;   ecx = [v_siz] ; display page pixel count
  8804                              <1> 	;   esi = edi = [v_mem] ; LFB start address
  8805                              <1> 	;
  8806                              <1> 	;   [maskcolor] = mask color (to be excluded)
  8807                              <1> 	;
  8808                              <1> 	; OUTPUT:
  8809                              <1> 	; 	[u.r0] will be > 0 if succesful
  8810                              <1> 
  8811                              <1> 	; Full screen
  8812                              <1> m_pix_op_xor_0:
  8813 0000F21E 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  8814 0000F225 7717                <1> 	ja	short m_pix_op_xor_1
  8815                              <1> 	; 256 colors (8bpp)
  8816                              <1> 	;jmp	short m_pix_op_xor_8
  8817                              <1> m_pix_op_xor_8:
  8818                              <1> 	; 8 bit colors (256 colors)
  8819 0000F227 88C2                <1> 	mov	dl, al ; new color
  8820                              <1> m_pix_op_xor_8_0:
  8821 0000F229 AC                  <1> 	lodsb 
  8822 0000F22A 3A05[AAA30100]      <1> 	cmp	al, [maskcolor]
  8823 0000F230 7408                <1> 	je	short m_pix_op_xor_8_1 ; exclude
  8824 0000F232 3017                <1> 	xor	[edi], dl
  8825 0000F234 FF05[74940100]      <1> 	inc	dword [u.r0] ; +1
  8826                              <1> m_pix_op_xor_8_1:
  8827 0000F23A 47                  <1> 	inc	edi
  8828 0000F23B E2EC                <1> 	loop	m_pix_op_xor_8_0
  8829 0000F23D C3                  <1> 	retn
  8830                              <1> m_pix_op_xor_1:
  8831 0000F23E 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  8832 0000F245 774A                <1> 	ja	short m_pix_op_xor_3 ; 32bpp
  8833 0000F247 722B                <1> 	jb	short m_pix_op_xor_2 ; 16bpp
  8834                              <1> 	; 24 bit true colors
  8835                              <1> 	;jmp	short m_pix_op_xor_24
  8836                              <1> m_pix_op_xor_24:
  8837                              <1> 	; 24 bit true colors
  8838 0000F249 89C2                <1> 	mov	edx, eax ; new color
  8839                              <1> 	;and	edx, 0FFFFFFh
  8840                              <1> m_pix_op_xor_24_0:
  8841 0000F24B 66AD                <1> 	lodsw
  8842 0000F24D C1E010              <1> 	shl	eax, 16
  8843 0000F250 AC                  <1> 	lodsb
  8844 0000F251 C1C010              <1> 	rol	eax, 16	
  8845 0000F254 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  8846 0000F25A 7412                <1> 	je	short m_pix_op_xor_24_1 ; exclude
  8847 0000F25C 31D0                <1> 	xor	eax, edx
  8848 0000F25E 668907              <1> 	mov	[edi], ax
  8849 0000F261 C1E810              <1> 	shr	eax, 16
  8850 0000F264 884702              <1> 	mov	[edi+2], al
  8851 0000F267 8305[74940100]03    <1> 	add	dword [u.r0], 3 ; +3
  8852                              <1> m_pix_op_xor_24_1:
  8853 0000F26E 83C703              <1> 	add	edi, 3 ; +3
  8854 0000F271 E2D8                <1> 	loop	m_pix_op_xor_24_0
  8855 0000F273 C3                  <1> 	retn
  8856                              <1> 	; 65536 colors (16bpp)
  8857                              <1> m_pix_op_xor_2:
  8858                              <1> 	;jmp	short m_pix_op_xor_16
  8859                              <1> m_pix_op_xor_16:
  8860                              <1> 	; 16 bit colors (65536 colors)
  8861 0000F274 89C2                <1> 	mov	edx, eax ; new color
  8862                              <1> 	;and	edx, 0FFFFh
  8863                              <1> m_pix_op_xor_16_0:
  8864 0000F276 66AD                <1> 	lodsw
  8865 0000F278 663B05[AAA30100]    <1> 	cmp	ax, [maskcolor]
  8866 0000F27F 740A                <1> 	je	short m_pix_op_xor_16_1 ; exclude
  8867 0000F281 663117              <1> 	xor	[edi], dx
  8868 0000F284 8305[74940100]02    <1> 	add	dword [u.r0], 2 ; +2
  8869                              <1> m_pix_op_xor_16_1:
  8870 0000F28B 83C702              <1> 	add	edi, 2 ; +2
  8871 0000F28E E2E6                <1> 	loop	m_pix_op_xor_16_0
  8872 0000F290 C3                  <1> 	retn
  8873                              <1> m_pix_op_xor_3:
  8874                              <1> 	; 32 bit true colors
  8875                              <1> 	;jmp	short m_pix_op_xor_32
  8876                              <1> m_pix_op_xor_32:
  8877                              <1> 	; 32 bit true colors
  8878 0000F291 89C2                <1> 	mov	edx, eax ; new color
  8879                              <1> m_pix_op_xor_32_0:
  8880 0000F293 AD                  <1> 	lodsd
  8881 0000F294 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  8882 0000F29A 7409                <1> 	je	short m_pix_op_xor_32_1 ; exclude
  8883 0000F29C 3117                <1> 	xor	[edi], edx ; 25/02/2021
  8884 0000F29E 8305[74940100]04    <1> 	add	dword [u.r0], 4 ; +4
  8885                              <1> m_pix_op_xor_32_1:
  8886 0000F2A5 83C704              <1> 	add	edi, 4 ; +4
  8887 0000F2A8 E2E9                <1> 	loop	m_pix_op_xor_32_0
  8888 0000F2AA C3                  <1> 	retn
  8889                              <1> 
  8890                              <1> m_pix_op_xor_w:
  8891                              <1> 	; 06/02/2021
  8892                              <1> 	; XOR COLOR (MASKED, window)
  8893                              <1> 	;
  8894                              <1> 	; jump from pix_op_xor_w
  8895                              <1> 	;
  8896                              <1> 	; INPUT:
  8897                              <1> 	;   ecx = bytes per row (to be applied)
  8898                              <1> 	;   edx = screen width in bytes
  8899                              <1> 	;   ebx = row count
  8900                              <1> 	;   eax = color
  8901                              <1> 	;
  8902                              <1> 	;   [maskcolor] = mask color (to be excluded)
  8903                              <1> 	;
  8904                              <1> 	; OUTPUT:
  8905                              <1> 	; 	[u.r0] will be > 0 if succesful
  8906                              <1> 
  8907                              <1> 	; window
  8908                              <1> 	;mov	edi, [v_str] ; LFB start address
  8909                              <1> 	;mov	esi, edi 
  8910                              <1> 
  8911 0000F2AB 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  8912 0000F2B2 7707                <1> 	ja	short m_pix_op_xor_w_1
  8913                              <1> 
  8914                              <1> 	; 256 colors (8bpp)
  8915 0000F2B4 BD[27F20000]        <1> 	mov	ebp, m_pix_op_xor_8
  8916 0000F2B9 EB1E                <1> 	jmp	short m_pix_op_xor_w_4
  8917                              <1> 
  8918                              <1> m_pix_op_xor_w_1:
  8919 0000F2BB 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  8920 0000F2C2 7710                <1> 	ja	short m_pix_op_xor_w_3 ; 32bpp
  8921 0000F2C4 7207                <1> 	jb	short m_pix_op_xor_w_2 ; 16bpp
  8922                              <1> 
  8923                              <1> 	; 24 bit true colors
  8924 0000F2C6 BD[49F20000]        <1> 	mov	ebp, m_pix_op_xor_24
  8925 0000F2CB EB0C                <1> 	jmp	short m_pix_op_xor_w_4
  8926                              <1> 
  8927                              <1> 	; 65536 colors (16bpp)
  8928                              <1> m_pix_op_xor_w_2:
  8929 0000F2CD BD[74F20000]        <1> 	mov	ebp, m_pix_op_xor_16
  8930 0000F2D2 EB05                <1> 	jmp	short m_pix_op_xor_w_4
  8931                              <1> 
  8932                              <1> 	; 32 bit true colors
  8933                              <1> m_pix_op_xor_w_3:
  8934 0000F2D4 BD[91F20000]        <1> 	mov	ebp, m_pix_op_xor_32
  8935                              <1> m_pix_op_xor_w_4:
  8936 0000F2D9 E917FBFFFF          <1> 	jmp	m_pix_op_xor_w_x
  8937                              <1> 
  8938                              <1> m_pix_op_not:
  8939                              <1> 	; 06/02/2021
  8940                              <1> 	; NOT COLOR (MASKED, full screen)
  8941                              <1> 	;
  8942                              <1> 	; jump from pix_op_not
  8943                              <1> 	;
  8944                              <1> 	; INPUT:
  8945                              <1> 	;   ecx = [v_siz] ; display page pixel count
  8946                              <1> 	;   esi = edi = [v_mem] ; LFB start address
  8947                              <1> 	;
  8948                              <1> 	;   [maskcolor] = mask color (to be excluded)
  8949                              <1> 	;
  8950                              <1> 	; OUTPUT:
  8951                              <1> 	; 	[u.r0] will be > 0 if succesful
  8952                              <1> 
  8953                              <1> 	; Full screen
  8954                              <1> m_pix_op_not_0:
  8955 0000F2DE 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  8956 0000F2E5 7715                <1> 	ja	short m_pix_op_not_1
  8957                              <1> 	; 256 colors (8bpp)
  8958                              <1> 	;jmp	short m_pix_op_not_8
  8959                              <1> m_pix_op_not_8:
  8960                              <1> 	; 8 bit colors (256 colors)
  8961 0000F2E7 AC                  <1> 	lodsb 
  8962 0000F2E8 3A05[AAA30100]      <1> 	cmp	al, [maskcolor]
  8963 0000F2EE 7408                <1> 	je	short m_pix_op_not_8_1 ; exclude
  8964 0000F2F0 F617                <1> 	not	byte [edi]
  8965 0000F2F2 FF05[74940100]      <1> 	inc	dword [u.r0] ; +1
  8966                              <1> m_pix_op_not_8_1:
  8967 0000F2F8 47                  <1> 	inc	edi
  8968 0000F2F9 E2EC                <1> 	loop	m_pix_op_not_8
  8969 0000F2FB C3                  <1> 	retn
  8970                              <1> m_pix_op_not_1:
  8971 0000F2FC 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  8972 0000F303 7746                <1> 	ja	short m_pix_op_not_3 ; 32bpp
  8973 0000F305 7229                <1> 	jb	short m_pix_op_not_2 ; 16bpp
  8974                              <1> 	; 24 bit true colors
  8975                              <1> 	;jmp	short m_pix_op_not_24
  8976                              <1> m_pix_op_not_24:
  8977                              <1> 	; 24 bit true colors
  8978 0000F307 66AD                <1> 	lodsw
  8979 0000F309 C1E010              <1> 	shl	eax, 16
  8980 0000F30C AC                  <1> 	lodsb
  8981 0000F30D C1C010              <1> 	rol	eax, 16	
  8982 0000F310 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  8983 0000F316 7412                <1> 	je	short m_pix_op_not_24_1 ; exclude
  8984 0000F318 F7D0                <1> 	not	eax
  8985 0000F31A 668907              <1> 	mov	[edi], ax
  8986 0000F31D C1E810              <1> 	shr	eax, 16
  8987 0000F320 884702              <1> 	mov	[edi+2], al
  8988 0000F323 8305[74940100]03    <1> 	add	dword [u.r0], 3 ; +3
  8989                              <1> m_pix_op_not_24_1:
  8990 0000F32A 83C703              <1> 	add	edi, 3 ; +3
  8991 0000F32D E2D8                <1> 	loop	m_pix_op_not_24
  8992 0000F32F C3                  <1> 	retn
  8993                              <1> 	; 65536 colors (16bpp)
  8994                              <1> m_pix_op_not_2:
  8995                              <1> 	;jmp	short m_pix_op_not_16
  8996                              <1> m_pix_op_not_16:
  8997                              <1> 	; 16 bit colors (65536 colors)
  8998 0000F330 66AD                <1> 	lodsw
  8999 0000F332 663B05[AAA30100]    <1> 	cmp	ax, [maskcolor]
  9000 0000F339 740A                <1> 	je	short m_pix_op_not_16_1 ; exclude
  9001 0000F33B 66F717              <1> 	not	word [edi]
  9002 0000F33E 8305[74940100]02    <1> 	add	dword [u.r0], 2 ; +2
  9003                              <1> m_pix_op_not_16_1:
  9004 0000F345 83C702              <1> 	add	edi, 2 ; +2
  9005 0000F348 E2E6                <1> 	loop	m_pix_op_not_16
  9006 0000F34A C3                  <1> 	retn
  9007                              <1> m_pix_op_not_3:
  9008                              <1> 	; 32 bit true colors
  9009                              <1> 	;jmp	short m_pix_op_not_32
  9010                              <1> m_pix_op_not_32:
  9011                              <1> 	; 32 bit true colors
  9012 0000F34B AD                  <1> 	lodsd 
  9013 0000F34C 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  9014 0000F352 7409                <1> 	je	short m_pix_op_not_32_1 ; exclude
  9015 0000F354 F717                <1> 	not	dword [edi]	
  9016 0000F356 8305[74940100]04    <1> 	add	dword [u.r0], 4 ; +4
  9017                              <1> m_pix_op_not_32_1:
  9018 0000F35D 83C704              <1> 	add	edi, 4 ; +4
  9019 0000F360 E2E9                <1> 	loop	m_pix_op_not_32
  9020 0000F362 C3                  <1> 	retn
  9021                              <1> 
  9022                              <1> m_pix_op_not_w:
  9023                              <1> 	; 06/02/2021
  9024                              <1> 	; NOT COLOR (MASKED, window)
  9025                              <1> 	;
  9026                              <1> 	; jump from pix_op_not_w
  9027                              <1> 	;
  9028                              <1> 	; INPUT:
  9029                              <1> 	;   ecx = bytes per row (to be applied)
  9030                              <1> 	;   edx = screen width in bytes
  9031                              <1> 	;   ebx = row count
  9032                              <1> 	;
  9033                              <1> 	;   [maskcolor] = mask color (to be excluded)
  9034                              <1> 	;
  9035                              <1> 	; OUTPUT:
  9036                              <1> 	; 	[u.r0] will be > 0 if succesful
  9037                              <1> 
  9038                              <1> 	; window
  9039                              <1> 	;mov	edi, [v_str] ; LFB start address
  9040                              <1> 	;mov	esi, edi 
  9041                              <1> 
  9042 0000F363 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  9043 0000F36A 7707                <1> 	ja	short m_pix_op_not_w_1
  9044                              <1> 
  9045                              <1> 	; 256 colors (8bpp)
  9046 0000F36C BD[E7F20000]        <1> 	mov	ebp, m_pix_op_not_8
  9047 0000F371 EB1E                <1> 	jmp	short m_pix_op_not_w_4
  9048                              <1> 
  9049                              <1> m_pix_op_not_w_1:
  9050 0000F373 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  9051 0000F37A 7710                <1> 	ja	short m_pix_op_not_w_3 ; 32bpp
  9052 0000F37C 7207                <1> 	jb	short m_pix_op_not_w_2 ; 16bpp
  9053                              <1> 
  9054                              <1> 	; 24 bit true colors
  9055 0000F37E BD[07F30000]        <1> 	mov	ebp, m_pix_op_not_24
  9056 0000F383 EB0C                <1> 	jmp	short m_pix_op_not_w_4
  9057                              <1> 
  9058                              <1> 	; 65536 colors (16bpp)
  9059                              <1> m_pix_op_not_w_2:
  9060 0000F385 BD[30F30000]        <1> 	mov	ebp, m_pix_op_not_16
  9061 0000F38A EB05                <1> 	jmp	short m_pix_op_not_w_4
  9062                              <1> 
  9063                              <1> 	; 32 bit true colors
  9064                              <1> m_pix_op_not_w_3:
  9065 0000F38C BD[4BF30000]        <1> 	mov	ebp, m_pix_op_not_32
  9066                              <1> m_pix_op_not_w_4:
  9067 0000F391 E95FFAFFFF          <1> 	jmp	m_pix_op_not_w_x
  9068                              <1> 
  9069                              <1> m_pix_op_neg:
  9070                              <1> 	; 06/02/2021
  9071                              <1> 	; NEGATIVE COLOR (MASKED, full screen)
  9072                              <1> 	;
  9073                              <1> 	; jump from pix_op_neg
  9074                              <1> 	;
  9075                              <1> 	; INPUT:
  9076                              <1> 	;   ecx = [v_siz] ; display page pixel count
  9077                              <1> 	;   esi = edi = [v_mem] ; LFB start address
  9078                              <1> 	;
  9079                              <1> 	;   [maskcolor] = mask color (to be excluded)
  9080                              <1> 	;
  9081                              <1> 	; OUTPUT:
  9082                              <1> 	; 	[u.r0] will be > 0 if succesful
  9083                              <1> 
  9084                              <1> 	; Full screen
  9085                              <1> m_pix_op_neg_0:
  9086 0000F396 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  9087 0000F39D 7715                <1> 	ja	short m_pix_op_neg_1
  9088                              <1> 	; 256 colors (8bpp)
  9089                              <1> 	;jmp	short m_pix_op_neg_8
  9090                              <1> m_pix_op_neg_8:
  9091                              <1> 	; 8 bit colors (256 colors)
  9092 0000F39F AC                  <1> 	lodsb 
  9093 0000F3A0 3A05[AAA30100]      <1> 	cmp	al, [maskcolor]
  9094 0000F3A6 7408                <1> 	je	short m_pix_op_neg_8_1 ; exclude
  9095 0000F3A8 F61F                <1> 	neg	byte [edi]
  9096 0000F3AA FF05[74940100]      <1> 	inc	dword [u.r0] ; +1
  9097                              <1> m_pix_op_neg_8_1:
  9098 0000F3B0 47                  <1> 	inc	edi
  9099 0000F3B1 E2EC                <1> 	loop	m_pix_op_neg_8
  9100 0000F3B3 C3                  <1> 	retn
  9101                              <1> m_pix_op_neg_1:
  9102 0000F3B4 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  9103 0000F3BB 7746                <1> 	ja	short m_pix_op_neg_3 ; 32bpp
  9104 0000F3BD 7229                <1> 	jb	short m_pix_op_neg_2 ; 16bpp
  9105                              <1> 	; 24 bit true colors
  9106                              <1> 	;jmp	short m_pix_op_neg_24
  9107                              <1> m_pix_op_neg_24:
  9108                              <1> 	; 24 bit true colors
  9109 0000F3BF 66AD                <1> 	lodsw
  9110 0000F3C1 C1E010              <1> 	shl	eax, 16
  9111 0000F3C4 AC                  <1> 	lodsb
  9112 0000F3C5 C1C010              <1> 	rol	eax, 16	
  9113 0000F3C8 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  9114 0000F3CE 7412                <1> 	je	short m_pix_op_neg_24_1 ; exclude
  9115 0000F3D0 F7D8                <1> 	neg	eax
  9116 0000F3D2 668907              <1> 	mov	[edi], ax
  9117 0000F3D5 C1E810              <1> 	shr	eax, 16
  9118 0000F3D8 884702              <1> 	mov	[edi+2], al
  9119 0000F3DB 8305[74940100]03    <1> 	add	dword [u.r0], 3 ; +3
  9120                              <1> m_pix_op_neg_24_1:
  9121 0000F3E2 83C703              <1> 	add	edi, 3 ; +3
  9122 0000F3E5 E2D8                <1> 	loop	m_pix_op_neg_24
  9123 0000F3E7 C3                  <1> 	retn
  9124                              <1> 	; 65536 colors (16bpp)
  9125                              <1> m_pix_op_neg_2:
  9126                              <1> 	;jmp	short m_pix_op_neg_16
  9127                              <1> m_pix_op_neg_16:
  9128                              <1> 	; 16 bit colors (65536 colors)
  9129 0000F3E8 66AD                <1> 	lodsw
  9130 0000F3EA 663B05[AAA30100]    <1> 	cmp	ax, [maskcolor]
  9131 0000F3F1 740A                <1> 	je	short m_pix_op_neg_16_1 ; exclude
  9132 0000F3F3 66F71F              <1> 	neg	word [edi]
  9133 0000F3F6 8305[74940100]02    <1> 	add	dword [u.r0], 2 ; +2
  9134                              <1> m_pix_op_neg_16_1:
  9135 0000F3FD 83C702              <1> 	add	edi, 2 ; +2
  9136 0000F400 E2E6                <1> 	loop	m_pix_op_neg_16
  9137 0000F402 C3                  <1> 	retn
  9138                              <1> m_pix_op_neg_3:
  9139                              <1> 	; 32 bit true colors
  9140                              <1> 	;jmp	short m_pix_op_neg_32
  9141                              <1> m_pix_op_neg_32:
  9142                              <1> 	; 32 bit true colors
  9143 0000F403 AD                  <1> 	lodsd 
  9144 0000F404 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  9145 0000F40A 7409                <1> 	je	short m_pix_op_neg_32_1 ; exclude
  9146 0000F40C F71F                <1> 	neg	dword [edi]
  9147 0000F40E 8305[74940100]04    <1> 	add	dword [u.r0], 4 ; +4
  9148                              <1> m_pix_op_neg_32_1:
  9149 0000F415 83C704              <1> 	add	edi, 4 ; +4
  9150 0000F418 E2E9                <1> 	loop	m_pix_op_neg_32
  9151 0000F41A C3                  <1> 	retn
  9152                              <1> 
  9153                              <1> m_pix_op_neg_w:
  9154                              <1> 	; 06/02/2021
  9155                              <1> 	; NEGATIVE COLOR (MASKED, window)
  9156                              <1> 	;
  9157                              <1> 	; jump from pix_op_neg_w
  9158                              <1> 	;
  9159                              <1> 	; INPUT:
  9160                              <1> 	;   ecx = bytes per row (to be applied)
  9161                              <1> 	;   edx = screen width in bytes
  9162                              <1> 	;   ebx = row count
  9163                              <1> 	;
  9164                              <1> 	;   [maskcolor] = mask color (to be excluded)
  9165                              <1> 	;
  9166                              <1> 	; OUTPUT:
  9167                              <1> 	; 	[u.r0] will be > 0 if succesful
  9168                              <1> 
  9169                              <1> 	; window
  9170                              <1> 	;mov	edi, [v_str] ; LFB start address
  9171                              <1> 	;mov	esi, edi 
  9172                              <1> 
  9173 0000F41B 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  9174 0000F422 7707                <1> 	ja	short m_pix_op_neg_w_1
  9175                              <1> 
  9176                              <1> 	; 256 colors (8bpp)
  9177 0000F424 BD[9FF30000]        <1> 	mov	ebp, m_pix_op_neg_8
  9178 0000F429 EB1E                <1> 	jmp	short m_pix_op_neg_w_4
  9179                              <1> 			
  9180                              <1> m_pix_op_neg_w_1:
  9181 0000F42B 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  9182 0000F432 7710                <1> 	ja	short m_pix_op_neg_w_3 ; 32bpp
  9183 0000F434 7207                <1> 	jb	short m_pix_op_neg_w_2 ; 16bpp
  9184                              <1> 
  9185                              <1> 	; 24 bit true colors
  9186 0000F436 BD[BFF30000]        <1> 	mov	ebp, m_pix_op_neg_24
  9187 0000F43B EB0C                <1> 	jmp	short m_pix_op_neg_w_4
  9188                              <1> 
  9189                              <1> 	; 65536 colors (16bpp)
  9190                              <1> m_pix_op_neg_w_2:
  9191 0000F43D BD[E8F30000]        <1> 	mov	ebp, m_pix_op_neg_16
  9192 0000F442 EB05                <1> 	jmp	short m_pix_op_neg_w_4
  9193                              <1> 
  9194                              <1> 	; 32 bit true colors
  9195                              <1> m_pix_op_neg_w_3:
  9196 0000F444 BD[03F40000]        <1> 	mov	ebp, m_pix_op_neg_32
  9197                              <1> m_pix_op_neg_w_4:
  9198 0000F449 E9A7F9FFFF          <1> 	jmp	m_pix_op_neg_w_x
  9199                              <1> 
  9200                              <1> m_pix_op_inc:
  9201                              <1> 	; 06/02/2021
  9202                              <1> 	; INCREASE COLOR (MASKED, full screen)
  9203                              <1> 	;
  9204                              <1> 	; jump from pix_op_inc
  9205                              <1> 	;
  9206                              <1> 	; INPUT:
  9207                              <1> 	;   ecx = [v_siz] ; display page pixel count
  9208                              <1> 	;   esi = edi = [v_mem] ; LFB start address
  9209                              <1> 	;
  9210                              <1> 	;   [maskcolor] = mask color (to be excluded)
  9211                              <1> 	;
  9212                              <1> 	; OUTPUT:
  9213                              <1> 	; 	[u.r0] will be > 0 if succesful
  9214                              <1> 
  9215                              <1> 	; Full screen
  9216                              <1> m_pix_op_inc_0:
  9217 0000F44E 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  9218 0000F455 7719                <1> 	ja	short m_pix_op_inc_1
  9219                              <1> 	; 256 colors (8bpp)
  9220                              <1> 	;jmp	short m_pix_op_inc_8
  9221                              <1> m_pix_op_inc_8:
  9222                              <1> 	; 8 bit colors (256 colors)
  9223 0000F457 AC                  <1> 	lodsb
  9224 0000F458 3A05[AAA30100]      <1> 	cmp	al, [maskcolor]
  9225 0000F45E 740C                <1> 	je	short m_pix_op_inc_8_1 ; exclude
  9226 0000F460 FE07                <1> 	inc	byte [edi]
  9227 0000F462 7502                <1> 	jnz	short m_pix_op_inc_8_0
  9228 0000F464 FE0F                <1> 	dec	byte [edi]
  9229                              <1> m_pix_op_inc_8_0:
  9230 0000F466 FF05[74940100]      <1> 	inc	dword [u.r0] ; +1
  9231                              <1> m_pix_op_inc_8_1:
  9232 0000F46C 47                  <1> 	inc	edi
  9233 0000F46D E2E8                <1> 	loop	m_pix_op_inc_8
  9234 0000F46F C3                  <1> 	retn
  9235                              <1> m_pix_op_inc_1:
  9236 0000F470 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  9237 0000F477 7752                <1> 	ja	short m_pix_op_inc_3 ; 32bpp
  9238 0000F479 7230                <1> 	jb	short m_pix_op_inc_2 ; 16bpp
  9239                              <1> 	; 24 bit true colors
  9240                              <1> 	;jmp	short m_pix_op_inc_24
  9241                              <1> m_pix_op_inc_24:
  9242                              <1> 	; 24 bit true colors
  9243 0000F47B 66AD                <1> 	lodsw
  9244 0000F47D C1E010              <1> 	shl	eax, 16
  9245 0000F480 AC                  <1> 	lodsb
  9246 0000F481 C1C010              <1> 	rol	eax, 16	
  9247 0000F484 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  9248 0000F48A 7419                <1> 	je	short m_pix_op_inc_24_1 ; exclude
  9249 0000F48C 40                  <1> 	inc	eax
  9250 0000F48D 3DFFFFFF00          <1> 	cmp	eax, 0FFFFFFh
  9251 0000F492 7601                <1> 	jna	short m_pix_op_inc_24_0
  9252 0000F494 48                  <1> 	dec	eax
  9253                              <1> m_pix_op_inc_24_0:
  9254 0000F495 668907              <1> 	mov	[edi], ax
  9255 0000F498 C1E810              <1> 	shr	eax, 16
  9256 0000F49B 884702              <1> 	mov	[edi+2], al
  9257 0000F49E 8305[74940100]03    <1> 	add	dword [u.r0], 3 ; +3
  9258                              <1> m_pix_op_inc_24_1:
  9259 0000F4A5 83C703              <1> 	add	edi, 3 ; +3
  9260 0000F4A8 E2D1                <1> 	loop	m_pix_op_inc_24
  9261 0000F4AA C3                  <1> 	retn
  9262                              <1> 	; 65536 colors (16bpp)
  9263                              <1> m_pix_op_inc_2:
  9264                              <1> 	;jmp	short m_pix_op_inc_16
  9265                              <1> m_pix_op_inc_16:
  9266                              <1> 	; 16 bit colors (65536 colors)
  9267 0000F4AB 66AD                <1> 	lodsw
  9268 0000F4AD 663B05[AAA30100]    <1> 	cmp	ax, [maskcolor]
  9269 0000F4B4 740F                <1> 	je	short m_pix_op_inc_16_1 ; exclude
  9270 0000F4B6 66FF07              <1> 	inc	word [edi]
  9271 0000F4B9 7503                <1> 	jnz	short m_pix_op_inc_16_0
  9272 0000F4BB 66FF0F              <1> 	dec	word [edi]
  9273                              <1> m_pix_op_inc_16_0:
  9274 0000F4BE 8305[74940100]02    <1> 	add	dword [u.r0], 2 ; +2
  9275                              <1> m_pix_op_inc_16_1:
  9276 0000F4C5 83C702              <1> 	add	edi, 2 ; +2
  9277 0000F4C8 E2E1                <1> 	loop	m_pix_op_inc_16
  9278 0000F4CA C3                  <1> 	retn
  9279                              <1> m_pix_op_inc_3:
  9280                              <1> 	; 32 bit true colors
  9281                              <1> 	;jmp	short m_pix_op_inc_32
  9282                              <1> m_pix_op_inc_32:
  9283                              <1> 	; 32 bit true colors
  9284 0000F4CB AD                  <1> 	lodsd
  9285 0000F4CC 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  9286 0000F4D2 740D                <1> 	je	short m_pix_op_inc_32_1 ; exclude
  9287 0000F4D4 FF07                <1> 	inc	dword [edi]
  9288 0000F4D6 7502                <1> 	jnz	short m_pix_op_inc_32_0
  9289 0000F4D8 FF0F                <1> 	dec	dword [edi]
  9290                              <1> m_pix_op_inc_32_0:
  9291 0000F4DA 8305[74940100]04    <1> 	add	dword [u.r0], 4 ; +4
  9292                              <1> m_pix_op_inc_32_1:
  9293 0000F4E1 83C704              <1> 	add	edi, 4 ; +4
  9294 0000F4E4 E2E5                <1> 	loop	m_pix_op_inc_32
  9295 0000F4E6 C3                  <1> 	retn
  9296                              <1> 
  9297                              <1> m_pix_op_inc_w:
  9298                              <1> 	; 06/02/2021
  9299                              <1> 	; INCREASE COLOR (MASKED, window)
  9300                              <1> 	;
  9301                              <1> 	; jump from pix_op_inc_w
  9302                              <1> 	;
  9303                              <1> 	; INPUT:
  9304                              <1> 	;   ecx = bytes per row (to be applied)
  9305                              <1> 	;   edx = screen width in bytes
  9306                              <1> 	;   ebx = row count
  9307                              <1> 	;
  9308                              <1> 	;   [maskcolor] = mask color (to be excluded)
  9309                              <1> 	;
  9310                              <1> 	; OUTPUT:
  9311                              <1> 	; 	[u.r0] will be > 0 if succesful
  9312                              <1> 
  9313                              <1> 	; window
  9314                              <1> 	;mov	edi, [v_str] ; LFB start address
  9315                              <1> 	;mov	esi, edi 
  9316                              <1> 
  9317 0000F4E7 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  9318 0000F4EE 7707                <1> 	ja	short m_pix_op_inc_w_1
  9319                              <1> 
  9320                              <1> 	; 256 colors (8bpp)
  9321 0000F4F0 BD[57F40000]        <1> 	mov	ebp, m_pix_op_inc_8
  9322 0000F4F5 EB1E                <1> 	jmp	short m_pix_op_inc_w_4
  9323                              <1> 
  9324                              <1> m_pix_op_inc_w_1:
  9325 0000F4F7 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  9326 0000F4FE 7710                <1> 	ja	short m_pix_op_inc_w_3 ; 32bpp
  9327 0000F500 7207                <1> 	jb	short m_pix_op_inc_w_2 ; 16bpp
  9328                              <1> 
  9329                              <1> 	; 24 bit true colors
  9330 0000F502 BD[7BF40000]        <1> 	mov	ebp, m_pix_op_inc_24
  9331 0000F507 EB0C                <1> 	jmp	short m_pix_op_inc_w_4
  9332                              <1> 
  9333                              <1> 	; 65536 colors (16bpp)
  9334                              <1> m_pix_op_inc_w_2:
  9335 0000F509 BD[ABF40000]        <1> 	mov	ebp, m_pix_op_inc_16
  9336 0000F50E EB05                <1> 	jmp	short m_pix_op_inc_w_4
  9337                              <1> 
  9338                              <1> 	; 32 bit true colors
  9339                              <1> m_pix_op_inc_w_3:
  9340 0000F510 BD[CBF40000]        <1> 	mov	ebp, m_pix_op_inc_32
  9341                              <1> m_pix_op_inc_w_4:
  9342 0000F515 E9DBF8FFFF          <1> 	jmp	m_pix_op_inc_w_x
  9343                              <1> 
  9344                              <1> m_pix_op_dec:
  9345                              <1> 	; 06/02/2021
  9346                              <1> 	; DECREASE COLOR (MASKED, full screen)
  9347                              <1> 	;
  9348                              <1> 	; jump from pix_op_dec
  9349                              <1> 	;
  9350                              <1> 	; INPUT:
  9351                              <1> 	;   ecx = [v_siz] ; display page pixel count
  9352                              <1> 	;   esi = edi = [v_mem] ; LFB start address
  9353                              <1> 	;
  9354                              <1> 	;   [maskcolor] = mask color (to be excluded)
  9355                              <1> 	;
  9356                              <1> 	; OUTPUT:
  9357                              <1> 	; 	[u.r0] will be > 0 if succesful
  9358                              <1> 
  9359                              <1> 	; Full screen
  9360                              <1> m_pix_op_dec_0:
  9361 0000F51A 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  9362 0000F521 7719                <1> 	ja	short m_pix_op_dec_1
  9363                              <1> 	; 256 colors (8bpp)
  9364                              <1> 	;jmp	short m_pix_op_dec_8
  9365                              <1> m_pix_op_dec_8:
  9366                              <1> 	; 8 bit colors (256 colors)
  9367 0000F523 AC                  <1> 	lodsb 
  9368 0000F524 3A05[AAA30100]      <1> 	cmp	al, [maskcolor]
  9369 0000F52A 740C                <1> 	je	short m_pix_op_dec_8_1 ; exclude
  9370 0000F52C FE0F                <1> 	dec	byte [edi]
  9371 0000F52E 7902                <1> 	jns	short m_pix_op_dec_8_0
  9372 0000F530 FE07                <1> 	inc	byte [edi]
  9373                              <1> m_pix_op_dec_8_0:
  9374 0000F532 FF05[74940100]      <1> 	inc	dword [u.r0] ; +1
  9375                              <1> m_pix_op_dec_8_1:
  9376 0000F538 47                  <1> 	inc	edi
  9377 0000F539 E2E8                <1> 	loop	m_pix_op_dec_8
  9378 0000F53B C3                  <1> 	retn
  9379                              <1> m_pix_op_dec_1:
  9380 0000F53C 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  9381 0000F543 774D                <1> 	ja	short m_pix_op_dec_3 ; 32bpp
  9382 0000F545 722B                <1> 	jb	short m_pix_op_dec_2 ; 16bpp
  9383                              <1> 	; 24 bit true colors
  9384                              <1> 	;jmp	short m_pix_op_dec_24
  9385                              <1> m_pix_op_dec_24:
  9386                              <1> 	; 24 bit true colors
  9387 0000F547 66AD                <1> 	lodsw
  9388 0000F549 C1E010              <1> 	shl	eax, 16
  9389 0000F54C AC                  <1> 	lodsb
  9390 0000F54D C1C010              <1> 	rol	eax, 16	
  9391 0000F550 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  9392 0000F556 7414                <1> 	je	short m_pix_op_dec_24_1 ; exclude
  9393 0000F558 48                  <1> 	dec	eax
  9394 0000F559 7901                <1> 	jns	short m_pix_op_dec_24_0
  9395 0000F55B 40                  <1> 	inc	eax 
  9396                              <1> m_pix_op_dec_24_0:
  9397 0000F55C 668907              <1> 	mov	[edi], ax
  9398 0000F55F C1E810              <1> 	shr	eax, 16
  9399 0000F562 884702              <1> 	mov	[edi+2], al
  9400 0000F565 8305[74940100]03    <1> 	add	dword [u.r0], 3 ; +3
  9401                              <1> m_pix_op_dec_24_1:
  9402 0000F56C 83C703              <1> 	add	edi, 3 ; +3
  9403 0000F56F E2D6                <1> 	loop	m_pix_op_dec_24
  9404 0000F571 C3                  <1> 	retn
  9405                              <1> 	; 65536 colors (16bpp)
  9406                              <1> m_pix_op_dec_2:
  9407                              <1> 	;jmp	short m_pix_op_dec_16
  9408                              <1> m_pix_op_dec_16:
  9409                              <1> 	; 16 bit colors (65536 colors)
  9410 0000F572 66AD                <1> 	lodsw
  9411 0000F574 663B05[AAA30100]    <1> 	cmp	ax, [maskcolor]
  9412 0000F57B 740F                <1> 	je	short m_pix_op_dec_16_1 ; exclude
  9413 0000F57D 66FF0F              <1> 	dec	word [edi]
  9414 0000F580 7903                <1> 	jns	short m_pix_op_dec_16_0
  9415 0000F582 66FF07              <1> 	inc	word [edi]
  9416                              <1> m_pix_op_dec_16_0:
  9417 0000F585 8305[74940100]02    <1> 	add	dword [u.r0], 2 ; +2
  9418                              <1> m_pix_op_dec_16_1:
  9419 0000F58C 83C702              <1> 	add	edi, 2 ; +2
  9420 0000F58F E2E1                <1> 	loop	m_pix_op_dec_16
  9421 0000F591 C3                  <1> 	retn
  9422                              <1> m_pix_op_dec_3:
  9423                              <1> 	; 32 bit true colors
  9424                              <1> 	;jmp	short m_pix_op_dec_32
  9425                              <1> m_pix_op_dec_32:
  9426                              <1> 	; 32 bit true colors
  9427 0000F592 AD                  <1> 	lodsd 
  9428 0000F593 3B05[AAA30100]      <1> 	cmp	eax, [maskcolor]
  9429 0000F599 740D                <1> 	je	short m_pix_op_dec_32_1 ; exclude
  9430 0000F59B FF0F                <1> 	dec	dword [edi]
  9431 0000F59D 7902                <1> 	jns	short m_pix_op_dec_32_0
  9432 0000F59F FF07                <1> 	inc	dword [edi]
  9433                              <1> m_pix_op_dec_32_0:
  9434 0000F5A1 8305[74940100]04    <1> 	add	dword [u.r0], 4 ; +4
  9435                              <1> m_pix_op_dec_32_1:
  9436 0000F5A8 83C704              <1> 	add	edi, 4 ; +4
  9437 0000F5AB E2E5                <1> 	loop	m_pix_op_dec_32
  9438 0000F5AD C3                  <1> 	retn
  9439                              <1> 
  9440                              <1> m_pix_op_dec_w:
  9441                              <1> 	; 06/02/2021
  9442                              <1> 	; DECREASE COLOR (MASKED, window)
  9443                              <1> 	;
  9444                              <1> 	; jump from pix_op_dec_w
  9445                              <1> 	;
  9446                              <1> 	; INPUT:
  9447                              <1> 	;   ecx = bytes per row (to be applied)
  9448                              <1> 	;   edx = screen width in bytes
  9449                              <1> 	;   ebx = row count
  9450                              <1> 	;
  9451                              <1> 	;   [maskcolor] = mask color (to be excluded)
  9452                              <1> 	;
  9453                              <1> 	; OUTPUT:
  9454                              <1> 	; 	[u.r0] will be > 0 if succesful
  9455                              <1> 
  9456                              <1> 	; window
  9457                              <1> 	;mov	edi, [v_str] ; LFB start address
  9458                              <1> 	;mov	esi, edi 
  9459                              <1> 
  9460 0000F5AE 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  9461 0000F5B5 7707                <1> 	ja	short m_pix_op_dec_w_1
  9462                              <1> 
  9463                              <1> 	; 256 colors (8bpp)
  9464 0000F5B7 BD[23F50000]        <1> 	mov	ebp, m_pix_op_dec_8
  9465 0000F5BC EB1E                <1> 	jmp	short m_pix_op_dec_w_4
  9466                              <1> 
  9467                              <1> m_pix_op_dec_w_1:
  9468 0000F5BE 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  9469 0000F5C5 7710                <1> 	ja	short m_pix_op_dec_w_3 ; 32bpp
  9470 0000F5C7 7207                <1> 	jb	short m_pix_op_dec_w_2 ; 16bpp
  9471                              <1> 
  9472                              <1> 	; 24 bit true colors
  9473 0000F5C9 BD[47F50000]        <1> 	mov	ebp, m_pix_op_dec_24
  9474 0000F5CE EB0C                <1> 	jmp	short m_pix_op_dec_w_4
  9475                              <1> 
  9476                              <1> 	; 65536 colors (16bpp)
  9477                              <1> m_pix_op_dec_w_2:
  9478 0000F5D0 BD[72F50000]        <1> 	mov	ebp, m_pix_op_dec_16
  9479 0000F5D5 EB05                <1> 	jmp	short m_pix_op_dec_w_4
  9480                              <1> 
  9481                              <1> 	; 32 bit true colors
  9482                              <1> m_pix_op_dec_w_3:
  9483 0000F5D7 BD[92F50000]        <1> 	mov	ebp, m_pix_op_dec_32
  9484                              <1> m_pix_op_dec_w_4:
  9485 0000F5DC E914F8FFFF          <1> 	jmp	m_pix_op_dec_w_x
  9486                              <1> 
  9487                              <1> sysvideo_39:
  9488                              <1> 	; 15/02/2021
  9489                              <1> 	; 07/02/2021, 08/02/2021
  9490                              <1> 	; 03/01/2021, 04/01/2021
  9491                              <1> 	; 23/11/2020
  9492                              <1> 	; BH = 3
  9493                              <1> 	; PIXEL READ/WRITE
  9494                              <1> 	
  9495                              <1> 	; 07/02/2021
  9496                              <1> 	; 04/01/2021 (TRDOS 386 v2.0.3)
  9497 0000F5E1 80FB03              <1> 	cmp	bl, 3
  9498 0000F5E4 761A                <1> 	jna	short sysvideo_39_1
  9499                              <1> 	; 07/02/2021
  9500 0000F5E6 80FB06              <1> 	cmp	bl, 6
  9501 0000F5E9 7705                <1> 	ja	short sysvideo_39_0
  9502 0000F5EB E91A010000          <1> 	jmp	sysvideo_39_31
  9503                              <1> sysvideo_39_0:
  9504                              <1> 	; error
  9505 0000F5F0 B3FF                <1> 	mov	bl, 0FFh
  9506 0000F5F2 8B2D[70940100]      <1> 	mov	ebp, [u.usp]  ; ebp points to user's registers
  9507 0000F5F8 895D10              <1> 	mov	[ebp+16], ebx ; EBX
  9508 0000F5FB E954D8FFFF          <1> 	jmp	sysret
  9509                              <1> sysvideo_39_1:
  9510 0000F600 803D[DE670000]FF    <1> 	cmp	byte [CRT_MODE], 0FFh
  9511 0000F607 7312                <1> 	jnb	short sysvideo_39_2 ; SVGA (VESA VBE) video mode
  9512                              <1> 
  9513                              <1> 	; Std VGA or CGA mode
  9514 0000F609 81C200000A00        <1> 	add	edx, 0A0000h
  9515 0000F60F 72DF                <1> 	jc	short sysvideo_39_0
  9516 0000F611 81FAFFFF0A00        <1> 	cmp	edx, 0AFFFFh
  9517 0000F617 77D7                <1> 	ja	short sysvideo_39_0
  9518 0000F619 EB1E                <1> 	jmp	short sysvideo_39_3 ; 8bpp
  9519                              <1> 
  9520                              <1> sysvideo_39_2:
  9521                              <1> 	; use current vbe (svga) video mode
  9522                              <1> 
  9523                              <1> 	; get LFB address
  9524 0000F61B A1[3CA30100]        <1> 	mov	eax, [LFB_ADDR] ; [LFB_Info+LFBINFO.LFB_addr]
  9525 0000F620 09C0                <1> 	or	eax, eax
  9526 0000F622 74CC                <1> 	jz	short sysvideo_39_0
  9527 0000F624 3B15[40A30100]      <1> 	cmp	edx, [LFB_SIZE] 
  9528 0000F62A 73C4                <1> 	jnb	short sysvideo_39_0
  9529                              <1> 
  9530 0000F62C 01C2                <1> 	add	edx, eax
  9531                              <1> 	;jc	short sysvideo_39_0
  9532                              <1> 
  9533                              <1> 	; Pixel read/write in VESA VBE (2/3) video mode
  9534                              <1> 	; Video memory at Linear Frame Buffer base address
  9535                              <1> 
  9536 0000F62E 8A3D[48A30100]      <1> 	mov	bh, [LFB_Info+LFBINFO.bpp]
  9537                              <1> 
  9538 0000F634 80FF08              <1> 	cmp	bh, 8 ; 8bpp
  9539 0000F637 775D                <1> 	ja	short sysvideo_39_17
  9540                              <1> 
  9541                              <1> 	; 8 bits per pixel
  9542                              <1> sysvideo_39_3:
  9543 0000F639 80FB01              <1> 	cmp	bl, 1 ; 1 = write pixel
  9544 0000F63C 7406                <1> 	je	short sysvideo_39_5
  9545 0000F63E 7712                <1> 	ja	short sysvideo_39_8
  9546                              <1> sysvideo_39_4:
  9547                              <1> 	; read pixel (8bpp)
  9548 0000F640 8A02                <1> 	mov	al, [edx]
  9549                              <1> 	;mov	[u.r0], al
  9550                              <1> 	;jmp	sysret
  9551 0000F642 EB04                <1> 	jmp	short sysvideo_39_7
  9552                              <1> sysvideo_39_5:
  9553                              <1> 	; write pixel (8bpp)
  9554 0000F644 88C8                <1> 	mov	al, cl
  9555                              <1> sysvideo_39_6:
  9556 0000F646 8802                <1> 	mov	[edx], al
  9557                              <1> sysvideo_39_7:
  9558 0000F648 A2[74940100]        <1> 	mov	[u.r0], al
  9559 0000F64D E902D8FFFF          <1> 	jmp	sysret
  9560                              <1> sysvideo_39_8:
  9561 0000F652 80FB03              <1> 	cmp	bl, 3 ; mix
  9562 0000F655 7208                <1> 	jb	short sysvideo_39_9
  9563                              <1> 	; mix  pixel colors (8bpp)
  9564 0000F657 8A02                <1> 	mov	al, [edx]
  9565 0000F659 00C8                <1> 	add	al, cl
  9566 0000F65B D0D8                <1> 	rcr	al, 1
  9567 0000F65D EBE7                <1> 	jmp	short sysvideo_39_6
  9568                              <1> sysvideo_39_9:
  9569                              <1> 	 ; swap pixel colors (8bpp)
  9570 0000F65F 88C8                <1> 	mov	al, cl
  9571 0000F661 8602                <1> 	xchg	[edx], al
  9572 0000F663 EBE3                <1> 	jmp	short sysvideo_39_7
  9573                              <1> 
  9574                              <1> 	; 16 bits per pixel
  9575                              <1> sysvideo_39_10:
  9576 0000F665 80FB01              <1> 	cmp	bl, 1 ; 1 = write pixel
  9577 0000F668 7406                <1> 	je	short sysvideo_39_12
  9578 0000F66A 7714                <1> 	ja	short sysvideo_39_15
  9579                              <1> sysvideo_39_11:
  9580                              <1> 	; read pixel (16bpp)
  9581 0000F66C 8B02                <1> 	mov	eax, [edx]
  9582                              <1> 	;mov	[u.r0], ax
  9583                              <1> 	;jmp	sysret
  9584 0000F66E EB05                <1> 	jmp	short sysvideo_39_14
  9585                              <1> sysvideo_39_12:
  9586                              <1> 	; write pixel (16bpp)
  9587 0000F670 89C8                <1> 	mov	eax, ecx
  9588                              <1> sysvideo_39_13:
  9589 0000F672 668902              <1> 	mov	[edx], ax
  9590                              <1> sysvideo_39_14:
  9591 0000F675 66A3[74940100]      <1> 	mov	[u.r0], ax
  9592 0000F67B E9D4D7FFFF          <1> 	jmp	sysret
  9593                              <1> sysvideo_39_15:
  9594 0000F680 80FB03              <1> 	cmp	bl, 3 ; mix
  9595 0000F683 720A                <1> 	jb	short sysvideo_39_16
  9596                              <1> 	; mix  pixel colors (16bpp)
  9597 0000F685 8B02                <1> 	mov	eax, [edx]
  9598 0000F687 6601C8              <1> 	add	ax, cx
  9599 0000F68A 66D1D8              <1> 	rcr	ax, 1
  9600 0000F68D EBE3                <1> 	jmp	short sysvideo_39_13
  9601                              <1> sysvideo_39_16:
  9602                              <1> 	 ; swap pixel colors (16bpp)
  9603 0000F68F 89C8                <1> 	mov	eax, ecx
  9604 0000F691 668702              <1> 	xchg	[edx], ax
  9605 0000F694 EBDF                <1> 	jmp	short sysvideo_39_14
  9606                              <1> sysvideo_39_17:
  9607 0000F696 80FF18              <1> 	cmp	bh, 24
  9608 0000F699 7743                <1> 	ja	short sysvideo_39_24
  9609 0000F69B 72C8                <1> 	jb	short sysvideo_39_10  
  9610                              <1> 	
  9611                              <1> 	; 24 bits per pixel
  9612 0000F69D 81E1FFFFFF00        <1> 	and	ecx, 0FFFFFFh
  9613 0000F6A3 80FB01              <1> 	cmp	bl, 1 ; 1 = write pixel
  9614 0000F6A6 7406                <1> 	je	short sysvideo_39_19
  9615 0000F6A8 7712                <1> 	ja	short sysvideo_39_22
  9616                              <1> sysvideo_39_18:
  9617                              <1> 	; read pixel (24bpp)
  9618 0000F6AA 8B02                <1> 	mov	eax, [edx]
  9619                              <1> 	;and	eax, 0FFFFFFh
  9620                              <1> 	;mov	[u.r0], eax
  9621                              <1> 	;jmp	sysret
  9622 0000F6AC EB04                <1> 	jmp	short sysvideo_39_21
  9623                              <1> sysvideo_39_19:
  9624                              <1> 	; write pixel (24bpp)
  9625 0000F6AE 89C8                <1> 	mov	eax, ecx
  9626                              <1> sysvideo_39_20:
  9627                              <1> 	;and	eax, 0FFFFFFh
  9628 0000F6B0 8902                <1> 	mov	[edx], eax
  9629                              <1> sysvideo_39_21:
  9630 0000F6B2 A3[74940100]        <1> 	mov	[u.r0], eax
  9631 0000F6B7 E998D7FFFF          <1> 	jmp	sysret
  9632                              <1> sysvideo_39_22:
  9633 0000F6BC 80FB03              <1> 	cmp	bl, 3 ; mix
  9634 0000F6BF 720D                <1> 	jb	short sysvideo_39_23
  9635                              <1> 	; mix  pixel colors (24bpp)
  9636 0000F6C1 8B02                <1> 	mov	eax, [edx]
  9637 0000F6C3 25FFFFFF00          <1> 	and	eax, 0FFFFFFh
  9638                              <1> 	;and	ecx, 0FFFFFFh
  9639 0000F6C8 01C8                <1> 	add	eax, ecx
  9640 0000F6CA D1D8                <1> 	rcr	eax, 1
  9641 0000F6CC EBE2                <1> 	jmp	short sysvideo_39_20
  9642                              <1> sysvideo_39_23:
  9643                              <1> 	 ; swap pixel colors (24bpp)
  9644 0000F6CE 89C8                <1> 	mov	eax, ecx
  9645                              <1> 	;and	eax, 0FFFFFFh
  9646 0000F6D0 668702              <1> 	xchg	[edx], ax
  9647 0000F6D3 C1C810              <1> 	ror	eax, 16
  9648 0000F6D6 884202              <1> 	mov	[edx+2], al
  9649 0000F6D9 C1C010              <1> 	rol	eax, 16
  9650 0000F6DC EBD4                <1> 	jmp	short sysvideo_39_21
  9651                              <1> 
  9652                              <1> 	; 32 bits per pixel
  9653                              <1> sysvideo_39_24:
  9654 0000F6DE 80FB01              <1> 	cmp	bl, 1 ; 1 = write pixel
  9655 0000F6E1 7406                <1> 	je	short sysvideo_39_26
  9656 0000F6E3 7712                <1> 	ja	short sysvideo_39_29
  9657                              <1> sysvideo_39_25:
  9658                              <1> 	; read pixel (32bpp)
  9659 0000F6E5 8B02                <1> 	mov	eax, [edx]
  9660                              <1> 	;mov	[u.r0], eax
  9661                              <1> 	;jmp	sysret
  9662 0000F6E7 EB04                <1> 	jmp	short sysvideo_39_28
  9663                              <1> sysvideo_39_26:
  9664                              <1> 	; write pixel (32bpp)
  9665 0000F6E9 89C8                <1> 	mov	eax, ecx
  9666                              <1> sysvideo_39_27:
  9667 0000F6EB 8902                <1> 	mov	[edx], eax
  9668                              <1> sysvideo_39_28:
  9669 0000F6ED A3[74940100]        <1> 	mov	[u.r0], eax
  9670 0000F6F2 E95DD7FFFF          <1> 	jmp	sysret
  9671                              <1> sysvideo_39_29:
  9672 0000F6F7 80FB03              <1> 	cmp	bl, 3 ; mix
  9673 0000F6FA 7208                <1> 	jb	short sysvideo_39_30
  9674                              <1> 	; mix  pixel colors (32bpp)
  9675 0000F6FC 8B02                <1> 	mov	eax, [edx]
  9676 0000F6FE 01C8                <1> 	add	eax, ecx
  9677 0000F700 D1D8                <1> 	rcr	eax, 1
  9678 0000F702 EBE7                <1> 	jmp	short sysvideo_39_27
  9679                              <1> sysvideo_39_30:
  9680                              <1> 	 ; swap pixel colors (32bpp)
  9681 0000F704 89C8                <1> 	mov	eax, ecx
  9682 0000F706 8702                <1> 	xchg	[edx], eax
  9683 0000F708 EBE3                <1> 	jmp	short sysvideo_39_28
  9684                              <1> 
  9685                              <1> sysvideo_39_31:
  9686                              <1> 	; 06/03/2021
  9687                              <1> 	; 08/02/2021
  9688                              <1> 	; 07/02/2021
  9689                              <1> 	; BL = 4 -> read pixels from user defined positions
  9690                              <1> 	; BL = 5 -> write single color pixels to user defined pos.
  9691                              <1> 	; BL = 6 -> write multi color pixels to user defined pos.
  9692                              <1> 	; ECX = color (CL, CX, ECX)
  9693                              <1> 	; EDX = number of pixels
  9694                              <1> 	; ESI = user buffer contains dword pixel positions
  9695                              <1> 	;	 (and dword colors for BL input = 6)
  9696                              <1> 	; EDI = user's pixel color buff (destination) for BL = 4
  9697                              <1> 
  9698 0000F70A 890D[AAA30100]      <1> 	mov	[maskcolor], ecx
  9699 0000F710 89D5                <1> 	mov	ebp, edx ; number of pixels    
  9700 0000F712 803D[DE670000]FF    <1> 	cmp	byte [CRT_MODE], 0FFh ; SVGA flag
  9701 0000F719 7317                <1> 	jnb	short sysvideo_39_33 ; SVGA (VESA VBE mode)
  9702                              <1> 	; Standard VGA mode
  9703 0000F71B B900000100          <1> 	mov	ecx, 65536 ; Video page size (maximum)
  9704 0000F720 39CA                <1> 	cmp	edx, ecx
  9705 0000F722 7709                <1> 	ja	short sysvideo_39_32 ; abnormal value !
  9706 0000F724 B800000A00          <1> 	mov	eax, 0A0000h ; Video page start address
  9707 0000F729 B708                <1> 	mov	bh, 8  ; 8 bits per pixel (256 colors)
  9708 0000F72B EB35                <1> 	jmp	short sysvideo_39_34
  9709                              <1> sysvideo_39_32:
  9710                              <1> 	; nonsense! (edx has abnormal value)
  9711 0000F72D E922D7FFFF          <1> 	jmp	sysret
  9712                              <1> sysvideo_39_33:
  9713                              <1> 	; 06/03/2021
  9714 0000F732 8A3D[48A30100]      <1> 	mov	bh, [LFB_Info+LFBINFO.bpp]
  9715 0000F738 80FF08              <1> 	cmp	bh, 8
  9716 0000F73B 7412                <1> 	je	short sysvideo_39_81 ; 8bpp
  9717 0000F73D 89D0                <1> 	mov	eax, edx
  9718 0000F73F 80FF10              <1> 	cmp	bh, 16
  9719 0000F742 7409                <1> 	je	short sysvideo_39_80 ; 16bpp
  9720 0000F744 D1E2                <1> 	shl	edx, 1
  9721 0000F746 80FF20              <1> 	cmp	bh, 32
  9722 0000F749 7502                <1> 	jne	short sysvideo_39_80 ; 24bpp
  9723 0000F74B D1E0                <1> 	shl	eax, 1
  9724                              <1> sysvideo_39_80:
  9725 0000F74D 01C2                <1> 	add	edx, eax
  9726                              <1> 	; edx = number of bytes
  9727                              <1> sysvideo_39_81:
  9728                              <1> 	; get LFB address
  9729 0000F74F A1[3CA30100]        <1> 	mov	eax, [LFB_ADDR] ; [LFB_Info+LFBINFO.LFB_addr]
  9730 0000F754 09C0                <1> 	or	eax, eax
  9731 0000F756 74D5                <1> 	jz	short sysvideo_39_32 ; LFB is not ready !
  9732 0000F758 8B0D[40A30100]      <1> 	mov	ecx, [LFB_SIZE]
  9733 0000F75E 39CA                <1> 	cmp	edx, ecx 
  9734 0000F760 77CB                <1> 	ja	short sysvideo_39_32 ; abnormal value !
  9735                              <1> 
  9736                              <1> 	; 02/03/2021
  9737                              <1> 	; 08/02/2021
  9738                              <1> 	;mov	ebp, edx ; pixel count  
  9739                              <1> 	;shl	ebp, 2 ; byte count (pixel pos: 4 bytes)
  9740                              <1> 
  9741                              <1> 	; 06/03/2021
  9742                              <1> 	; bits per pixel (pixel color size)
  9743                              <1> 	;mov	bh, [LFB_Info+LFBINFO.bpp]
  9744                              <1> sysvideo_39_34:
  9745 0000F762 C1E502              <1> 	shl	ebp, 2 ; 15/02/2021 (byte count)
  9746 0000F765 A3[9AA30100]        <1> 	mov	[v_mem], eax ; Save video page start address
  9747 0000F76A 88DE                <1> 	mov	dh, bl ; sub function
  9748                              <1> 	; 06/03/2021
  9749 0000F76C 883D[99A30100]      <1> 	mov	[v_bpp], bh ; bits per pixel (color size)
  9750                              <1> 	;mov	ebx, [LFB_SIZE]
  9751 0000F772 89CB                <1> 	mov	ebx, ecx ; [LFB_SIZE]
  9752                              <1> 
  9753 0000F774 B900080000          <1> 	mov	ecx, 2048
  9754 0000F779 39CD                <1> 	cmp	ebp, ecx
  9755 0000F77B 7302                <1> 	jnb	short sysvideo_39_35
  9756 0000F77D 89E9                <1> 	mov	ecx, ebp ; fix to requested byte count
  9757                              <1> sysvideo_39_35:
  9758 0000F77F 80FE04              <1> 	cmp	dh, 4 ; 08/02/2021
  9759                              <1> 	;cmp	bl, 4 ; read pixels from user defined positions
  9760 0000F782 7605                <1> 	jna	short sysvideo_39_36
  9761 0000F784 E9B2000000          <1> 	jmp	sysvideo_39_52
  9762                              <1> 	; 08/02/2021
  9763                              <1> 	;mov	[buffer8], edi  ; user's destination buff addr
  9764                              <1> sysvideo_39_36:
  9765                              <1> 	; 08/02/2021
  9766                              <1> 	; read pixel positions
  9767                              <1> 	; as defined in user's source buffer
  9768 0000F789 893D[B2A30100]      <1> 	mov	[buffer8], edi  ; user's destination buff addr
  9769 0000F78F BF00760900          <1> 	mov	edi, VBE3SAVERESTOREBLOCK ; kernel buffer for
  9770                              <1> 					  ; 2028 byte data
  9771                              <1> 	; esi = user's source buffer for pixel positions
  9772                              <1> 	; ecx = byte count
  9773 0000F794 E841180000          <1> 	call	transfer_from_user_buffer
  9774 0000F799 7292                <1> 	jc	short sysvideo_39_32 ; error
  9775                              <1> 	; ecx  = transfer count (bytes)
  9776                              <1> 
  9777 0000F79B 57                  <1> 	push	edi ; *
  9778 0000F79C 56                  <1> 	push	esi ; **
  9779 0000F79D 51                  <1> 	push	ecx ; ***
  9780                              <1> 
  9781 0000F79E 89FE                <1> 	mov	esi, edi ; kernel buffer
  9782 0000F7A0 8B15[9AA30100]      <1> 	mov	edx, [v_mem] ; video memory
  9783 0000F7A6 C1E902              <1> 	shr	ecx, 2 ; pixel count (within buffer capacity)
  9784                              <1> 
  9785 0000F7A9 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  9786 0000F7B0 7753                <1> 	ja	short sysvideo_39_49
  9787                              <1> sysvideo_39_37:
  9788                              <1> 	; 8bpp
  9789 0000F7B2 AD                  <1> 	lodsd
  9790 0000F7B3 39D8                <1> 	cmp	eax, ebx ; < [LFB_SIZE]
  9791 0000F7B5 7309                <1> 	jnb	short sysvideo_39_39
  9792 0000F7B7 0FB60402            <1> 	movzx	eax, byte [edx+eax]
  9793                              <1> sysvideo_39_38:
  9794 0000F7BB AB                  <1> 	stosd
  9795 0000F7BC E2F4                <1> 	loop	sysvideo_39_37
  9796 0000F7BE EB49                <1> 	jmp	short sysvideo_39_50
  9797                              <1> sysvideo_39_39:
  9798                              <1> 	; write black color for improper positions
  9799 0000F7C0 31C0                <1> 	xor	eax, eax
  9800 0000F7C2 EBF7                <1> 	jmp	short sysvideo_39_38
  9801                              <1> sysvideo_39_40:
  9802 0000F7C4 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  9803 0000F7CB 772A                <1> 	ja	short sysvideo_39_47 ; 32bpp
  9804 0000F7CD 7216                <1> 	jb	short sysvideo_39_44 ; 16bpp
  9805                              <1> sysvideo_39_41:
  9806                              <1> 	; 24bpp
  9807 0000F7CF AD                  <1> 	lodsd
  9808 0000F7D0 39D8                <1> 	cmp	eax, ebx ; < [LFB_SIZE]
  9809 0000F7D2 730D                <1> 	jnb	short sysvideo_39_43
  9810 0000F7D4 8B0402              <1> 	mov	eax, [edx+eax]
  9811 0000F7D7 25FFFFFF00          <1> 	and	eax, 0FFFFFFh
  9812                              <1> sysvideo_39_42:
  9813 0000F7DC AB                  <1> 	stosd
  9814 0000F7DD E2F0                <1> 	loop	sysvideo_39_41
  9815 0000F7DF EB28                <1> 	jmp	short sysvideo_39_50
  9816                              <1> sysvideo_39_43:
  9817                              <1> 	; write black color for improper positions
  9818 0000F7E1 31C0                <1> 	xor	eax, eax
  9819 0000F7E3 EBF7                <1> 	jmp	short sysvideo_39_42
  9820                              <1> sysvideo_39_44:
  9821                              <1> 	; 16bpp
  9822 0000F7E5 AD                  <1> 	lodsd
  9823 0000F7E6 39D8                <1> 	cmp	eax, ebx ; < [LFB_SIZE]
  9824 0000F7E8 7309                <1> 	jnb	short sysvideo_39_46
  9825 0000F7EA 0FB70402            <1> 	movzx	eax, word [edx+eax]
  9826                              <1> sysvideo_39_45:
  9827 0000F7EE AB                  <1> 	stosd
  9828 0000F7EF E2F4                <1> 	loop	sysvideo_39_44
  9829 0000F7F1 EB16                <1> 	jmp	short sysvideo_39_50
  9830                              <1> sysvideo_39_46:
  9831                              <1> 	; write black color for improper positions
  9832 0000F7F3 31C0                <1> 	xor	eax, eax
  9833 0000F7F5 EBF7                <1> 	jmp	short sysvideo_39_45
  9834                              <1> sysvideo_39_47:
  9835                              <1> 	; 32bpp
  9836 0000F7F7 AD                  <1> 	lodsd
  9837 0000F7F8 39D8                <1> 	cmp	eax, ebx ; < [LFB_SIZE]
  9838 0000F7FA 7309                <1> 	jnb	short sysvideo_39_49
  9839 0000F7FC 0FB70402            <1> 	movzx	eax, word [edx+eax]
  9840                              <1> sysvideo_39_48:
  9841 0000F800 AB                  <1> 	stosd
  9842 0000F801 E2F4                <1> 	loop	sysvideo_39_47
  9843 0000F803 EB04                <1> 	jmp	short sysvideo_39_50
  9844                              <1> sysvideo_39_49:
  9845                              <1> 	; write black color for improper positions
  9846 0000F805 31C0                <1> 	xor	eax, eax
  9847 0000F807 EBF7                <1> 	jmp	short sysvideo_39_48
  9848                              <1> sysvideo_39_50:
  9849 0000F809 59                  <1> 	pop	ecx ; transfer count in bytes
  9850 0000F80A 5E                  <1> 	pop	esi ; ** ; kernel buffer
  9851                              <1>  	;mov	esi, VBE3SAVERESTOREBLOCK ; kernel buffer for
  9852                              <1> 					  ; 2048 byte data
  9853 0000F80B 8B3D[B2A30100]      <1> 	mov	edi, [buffer8]
  9854                              <1> 	; edi = user's destination buffer for pixel colors
  9855                              <1> 	; ecx = byte count
  9856 0000F811 E87A170000          <1> 	call	transfer_to_user_buffer
  9857 0000F816 5E                  <1> 	pop	esi ; *
  9858 0000F817 7266                <1> 	jc	short sysvideo_39_56 ; error
  9859                              <1> 	; ecx  = transfer count (bytes)
  9860 0000F819 89C8                <1> 	mov	eax, ecx
  9861 0000F81B C1E802              <1> 	shr	eax, 2
  9862 0000F81E 0105[74940100]      <1> 	add	[u.r0], eax ; transfer count (in pixels)
  9863                              <1> 		
  9864 0000F824 29CD                <1> 	sub	ebp, ecx
  9865 0000F826 7657                <1> 	jna	short sysvideo_39_56 ; completed/finished
  9866 0000F828 01CE                <1> 	add	esi, ecx ; next position in source buffer
  9867                              <1> 	;add	[buffer8], ecx ; next pos in destination buff
  9868 0000F82A 01CF                <1> 	add	edi, ecx
  9869 0000F82C 66B90008            <1> 	mov	cx, 2048 ; new count, limit: kernel buff size
  9870 0000F830 39CD                <1> 	cmp	ebp, ecx ; remain >= limit ?
  9871 0000F832 7302                <1> 	jnb	short sysvideo_39_51 ; yes
  9872 0000F834 89E9                <1> 	mov	ecx, ebp ; fix byte count to remain bytes
  9873                              <1> sysvideo_39_51:
  9874 0000F836 E94EFFFFFF          <1> 	jmp	sysvideo_39_36
  9875                              <1> 
  9876                              <1> sysvideo_39_52:
  9877 0000F83B 80FE05              <1> 	cmp	dh, 5 ; 08/02/2021
  9878                              <1> 	;cmp	bl, 5 ; write pixels to user defined positions 
  9879 0000F83E 7605                <1> 	jna	short sysvideo_39_53
  9880 0000F840 E9A1000000          <1> 	jmp	sysvideo_39_66
  9881                              <1> sysvideo_39_53:
  9882                              <1> 	; single color pixel writing
  9883 0000F845 BF00760900          <1> 	mov	edi, VBE3SAVERESTOREBLOCK ; kernel buffer for
  9884                              <1> 					  ; 2028 byte data
  9885                              <1> 	; esi = user's source buffer for pixel positions
  9886                              <1> 	; ecx = byte count
  9887 0000F84A E88B170000          <1> 	call	transfer_from_user_buffer
  9888 0000F84F 722E                <1> 	jc	short sysvideo_39_56 ; error
  9889                              <1> 	; ecx = transfer count (bytes)
  9890                              <1> 
  9891                              <1> 	; write pixels by using (user) defined positions
  9892                              <1> 	; ecx = byte count (1,2,3,4 times pixel count)	
  9893                              <1> 	; edi = system buffer address
  9894                              <1> 
  9895 0000F851 56                  <1> 	push	esi ; *
  9896 0000F852 51                  <1> 	push	ecx ; **
  9897                              <1> 
  9898 0000F853 89FE                <1> 	mov	esi, edi
  9899 0000F855 8B3D[9AA30100]      <1> 	mov	edi, [v_mem]
  9900                              <1> 
  9901                              <1> 	; 08/02/2021
  9902 0000F85B C1E902              <1> 	shr	ecx, 2 ; pixel count
  9903 0000F85E 8B15[AAA30100]      <1> 	mov	edx, [maskcolor]
  9904                              <1> 	;mov	ebx, [v_siz]
  9905                              <1> 
  9906 0000F864 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
  9907 0000F86B 7717                <1> 	ja	short sysvideo_39_57
  9908                              <1> sysvideo_39_54:
  9909                              <1> 	; 8bpp
  9910 0000F86D AD                  <1> 	lodsd
  9911 0000F86E 39D8                <1> 	cmp	eax, ebx ; < [v_siz]
  9912 0000F870 7309                <1> 	jnb	short sysvideo_39_55
  9913 0000F872 881407              <1> 	mov	[edi+eax], dl
  9914                              <1> 	; 06/03/2021
  9915 0000F875 FF05[74940100]      <1> 	inc	dword [u.r0]
  9916                              <1> sysvideo_39_55:
  9917 0000F87B E2F0                <1> 	loop	sysvideo_39_54
  9918 0000F87D EB50                <1> 	jmp	short sysvideo_39_64
  9919                              <1> sysvideo_39_56:
  9920 0000F87F E9D0D5FFFF          <1> 	jmp	sysret
  9921                              <1> sysvideo_39_57:
  9922 0000F884 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
  9923 0000F88B 7732                <1> 	ja	short sysvideo_39_62 ; 32bpp
  9924 0000F88D 721D                <1> 	jb	short sysvideo_39_60 ; 16bpp
  9925                              <1> sysvideo_39_58:
  9926                              <1> 	; 24bpp
  9927 0000F88F AD                  <1> 	lodsd
  9928 0000F890 39D8                <1> 	cmp	eax, ebx ; < [v_siz]
  9929 0000F892 7314                <1> 	jnb	short sysvideo_39_59
  9930 0000F894 881407              <1> 	mov	[edi+eax], dl
  9931 0000F897 40                  <1> 	inc	eax
  9932 0000F898 C1CA08              <1> 	ror	edx, 8
  9933 0000F89B 66891407            <1> 	mov	[edi+eax], dx
  9934 0000F89F C1C208              <1> 	rol	edx, 8
  9935 0000F8A2 FF05[74940100]      <1> 	inc	dword [u.r0]
  9936                              <1> sysvideo_39_59:
  9937 0000F8A8 E2E5                <1> 	loop	sysvideo_39_58
  9938 0000F8AA EB23                <1> 	jmp	short sysvideo_39_64
  9939                              <1> sysvideo_39_60:
  9940                              <1> 	; 16bpp
  9941 0000F8AC AD                  <1> 	lodsd
  9942 0000F8AD 39D8                <1> 	cmp	eax, ebx ; < [v_siz]
  9943 0000F8AF 730A                <1> 	jnb	short sysvideo_39_61
  9944 0000F8B1 66891407            <1> 	mov	[edi+eax], dx
  9945 0000F8B5 FF05[74940100]      <1> 	inc	dword [u.r0]
  9946                              <1> sysvideo_39_61:	
  9947 0000F8BB E2EF                <1> 	loop	sysvideo_39_60
  9948 0000F8BD EB10                <1> 	jmp	short sysvideo_39_64
  9949                              <1> sysvideo_39_62:
  9950                              <1> 	; 32bpp
  9951 0000F8BF AD                  <1> 	lodsd
  9952 0000F8C0 39D8                <1> 	cmp	eax, ebx ; < [v_siz]
  9953 0000F8C2 7309                <1> 	jnb	short sysvideo_39_63
  9954 0000F8C4 891407              <1> 	mov	[edi+eax], edx
  9955 0000F8C7 FF05[74940100]      <1> 	inc	dword [u.r0]
  9956                              <1> sysvideo_39_63:
  9957 0000F8CD E2F0                <1> 	loop	sysvideo_39_62
  9958                              <1> sysvideo_39_64:
  9959 0000F8CF 59                  <1> 	pop	ecx ; **
  9960 0000F8D0 5E                  <1> 	pop	esi ; *	
  9961 0000F8D1 29CD                <1> 	sub	ebp, ecx
  9962 0000F8D3 76AA                <1> 	jna	short sysvideo_39_56
  9963 0000F8D5 01CE                <1> 	add	esi, ecx
  9964 0000F8D7 66B90008            <1> 	mov	cx, 2048
  9965 0000F8DB 39CD                <1> 	cmp	ebp, ecx
  9966 0000F8DD 7302                <1> 	jnb	short sysvideo_39_65
  9967 0000F8DF 89E9                <1> 	mov	ecx, ebp
  9968                              <1> sysvideo_39_65:
  9969 0000F8E1 E95FFFFFFF          <1> 	jmp	sysvideo_39_53
  9970                              <1> 
  9971                              <1> sysvideo_39_66:
  9972                              <1> 	; 15/02/2021
  9973 0000F8E6 D1E5                <1> 	shl	ebp, 1 ; 8 bytes per pixel (position&color)
  9974                              <1> sysvideo_39_67:
  9975 0000F8E8 66B90008            <1> 	mov	cx, 2048
  9976 0000F8EC 39CD                <1> 	cmp	ebp, ecx
  9977 0000F8EE 7302                <1> 	jnb	short sysvideo_39_68
  9978 0000F8F0 89E9                <1> 	mov	ecx, ebp
  9979                              <1> sysvideo_39_68:
  9980                              <1> 	; multi colors pixel writing
  9981 0000F8F2 BF00760900          <1> 	mov	edi, VBE3SAVERESTOREBLOCK ; kernel buffer for
  9982                              <1> 					  ; 2048 byte data
  9983                              <1> 	; esi = user's source buffer for pixel positions
  9984                              <1> 	; ecx = byte count
  9985 0000F8F7 E8DE160000          <1> 	call	transfer_from_user_buffer
  9986 0000F8FC 7281                <1> 	jc	short sysvideo_39_56 ; error
  9987                              <1> 	; ecx  = transfer count
  9988                              <1> 	
  9989                              <1> 	; write pixels & colors as defined in user buffer
  9990                              <1> 	; ecx = byte count (2,4,6,8 times pixel count)
  9991                              <1> 	; edi = system buffer address
  9992                              <1> 
  9993 0000F8FE 56                  <1> 	push	esi ; **
  9994 0000F8FF 51                  <1> 	push	ecx ; *
  9995                              <1> 
  9996 0000F900 89FE                <1> 	mov	esi, edi
  9997 0000F902 8B3D[9AA30100]      <1> 	mov	edi, [v_mem]
  9998                              <1> 
  9999                              <1> 	; 08/02/2021
 10000 0000F908 C1E903              <1> 	shr	ecx, 3 ; pixel count
 10001                              <1> 
 10002                              <1> 	;mov	ebx, [v_siz]
 10003                              <1> 
 10004 0000F90B 803D[99A30100]08    <1> 	cmp	byte [v_bpp], 8 ; 8bpp
 10005 0000F912 7715                <1> 	ja	short sysvideo_39_71
 10006                              <1> sysvideo_39_69:
 10007                              <1> 	; 8bpp
 10008 0000F914 AD                  <1> 	lodsd	; position
 10009 0000F915 89C2                <1> 	mov	edx, eax
 10010 0000F917 AD                  <1> 	lodsd	; color
 10011 0000F918 39DA                <1> 	cmp	edx, ebx ; < [v_siz]
 10012 0000F91A 7309                <1> 	jnb	short sysvideo_39_70
 10013 0000F91C 880417              <1> 	mov	[edi+edx], al
 10014                              <1> 	; 06/03/2021
 10015 0000F91F FF05[74940100]      <1> 	inc	dword [u.r0]
 10016                              <1> sysvideo_39_70:
 10017 0000F925 E2ED                <1> 	loop	sysvideo_39_69
 10018 0000F927 EB51                <1> 	jmp	short sysvideo_39_78
 10019                              <1> sysvideo_39_71:
 10020 0000F929 803D[99A30100]18    <1> 	cmp	byte [v_bpp], 24 ; 24bpp
 10021 0000F930 7735                <1> 	ja	short sysvideo_39_76 ; 32bpp
 10022 0000F932 721D                <1> 	jb	short sysvideo_39_74 ; 16bpp
 10023                              <1> sysvideo_39_72:
 10024                              <1> 	; 24bpp
 10025 0000F934 AD                  <1> 	lodsd	; position
 10026 0000F935 89C2                <1> 	mov	edx, eax
 10027 0000F937 AD                  <1> 	lodsd	; color
 10028 0000F938 39DA                <1> 	cmp	edx, ebx ; < [v_siz]
 10029 0000F93A 7311                <1> 	jnb	short sysvideo_39_73
 10030 0000F93C 880417              <1> 	mov	[edi+edx], al
 10031 0000F93F 42                  <1> 	inc	edx
 10032 0000F940 C1E808              <1> 	shr	eax, 8
 10033 0000F943 66890417            <1> 	mov	[edi+edx], ax
 10034 0000F947 FF05[74940100]      <1> 	inc	dword [u.r0]
 10035                              <1> sysvideo_39_73:	
 10036 0000F94D E2E5                <1> 	loop	sysvideo_39_72
 10037 0000F94F EB29                <1> 	jmp	short sysvideo_39_78
 10038                              <1> sysvideo_39_74:
 10039                              <1> 	; 16bpp
 10040 0000F951 AD                  <1> 	lodsd	; position
 10041 0000F952 89C2                <1> 	mov	edx, eax
 10042 0000F954 AD                  <1> 	lodsd	; color
 10043 0000F955 39DA                <1> 	cmp	edx, ebx ; < [v_siz]
 10044 0000F957 730A                <1> 	jnb	short sysvideo_39_75
 10045 0000F959 66890417            <1> 	mov	[edi+edx], ax
 10046 0000F95D FF05[74940100]      <1> 	inc	dword [u.r0]
 10047                              <1> sysvideo_39_75:	
 10048 0000F963 E2EC                <1> 	loop	sysvideo_39_74
 10049 0000F965 EB13                <1> 	jmp	short sysvideo_39_78
 10050                              <1> sysvideo_39_76:
 10051                              <1> 	; 32bpp
 10052 0000F967 AD                  <1> 	lodsd	; position
 10053 0000F968 89C2                <1> 	mov	edx, eax
 10054 0000F96A AD                  <1> 	lodsd	; color
 10055 0000F96B 39DA                <1> 	cmp	edx, ebx ; < [v_siz]
 10056 0000F96D 7309                <1> 	jnb	short sysvideo_39_77
 10057 0000F96F 890417              <1> 	mov	[edi+edx], eax
 10058 0000F972 FF05[74940100]      <1> 	inc	dword [u.r0]
 10059                              <1> sysvideo_39_77:	
 10060 0000F978 E2ED                <1> 	loop	sysvideo_39_76
 10061                              <1> sysvideo_39_78:
 10062 0000F97A 59                  <1> 	pop	ecx ; *
 10063 0000F97B 5E                  <1> 	pop	esi ; **
 10064                              <1> 
 10065 0000F97C 29CD                <1> 	sub	ebp, ecx
 10066 0000F97E 762A                <1> 	jna	short sysvideo_39_79
 10067 0000F980 01CE                <1> 	add	esi, ecx
 10068 0000F982 E961FFFFFF          <1> 	jmp	sysvideo_39_67
 10069                              <1> ;sysvideo_39_79:
 10070                              <1> ;	jmp	sysret
 10071                              <1> 
 10072                              <1> sysvideo_16:
 10073                              <1> 	; 11/08/2022
 10074                              <1> 	; 23/07/2022
 10075                              <1> 	; 06/03/2021
 10076                              <1> 	; 23/11/2020
 10077 0000F987 80FF04              <1> 	cmp	bh, 4
 10078                              <1> 	;jb	sysvideo_39 ; bh = 3, pixel r/w
 10079                              <1> 	;ja	short sysvideo_17
 10080                              <1> 	; 23/07/2022
 10081 0000F98A 7407                <1> 	je	short sysvideo_16_0
 10082 0000F98C 7721                <1> 	ja	short sysvideo_17
 10083 0000F98E E94EFCFFFF          <1> 	jmp	sysvideo_39
 10084                              <1> sysvideo_16_0:
 10085                              <1> 	; BH = 4
 10086                              <1> 	; Direct User Access for CGA video memory.
 10087                              <1> 	; Setup user's page tables for direct access to 0B8000h.
 10088                              <1> 	;
 10089                              <1> 	; Permission checks are not implemented yet !
 10090                              <1> 	; (11/07/2016)
 10091                              <1> 
 10092 0000F993 B800800B00          <1> 	mov	eax, 0B8000h
 10093                              <1> 	;mov	ecx, 8 ; 8 pages (8*4K=32K)
 10094                              <1> 	; 11/08/2022
 10095 0000F998 31C9                <1> 	xor	ecx, ecx
 10096 0000F99A B108                <1> 	mov	cl, 8
 10097 0000F99C 89C3                <1> 	mov	ebx, eax ; 12/05/2017 ; virtual = physical
 10098 0000F99E E8DA65FFFF          <1> 	call	direct_memory_access
 10099                              <1> 	;jc	sysret
 10100 0000F9A3 7205                <1> 	jc	short sysvideo_39_79 ; 06/03/2021
 10101                              <1> 	; eax = 0B8000h if there is not an error
 10102 0000F9A5 A3[74940100]        <1> 	mov	[u.r0], eax
 10103                              <1> sysvideo_39_79: ; 08/01/2021
 10104 0000F9AA E9A5D4FFFF          <1> 	jmp	sysret
 10105                              <1> 
 10106                              <1> sysvideo_17:
 10107                              <1> 	; 23/07/2022
 10108                              <1> 	; 23/12/2020
 10109                              <1> 	; 11/12/2020
 10110                              <1> 	; 10/12/2020
 10111                              <1> 	; 23/11/2020
 10112 0000F9AF 80FF06              <1> 	cmp	bh, 6
 10113 0000F9B2 7424                <1> 	je	short sysvideo_17_0 ; 23/07/2022
 10114 0000F9B4 7205                <1> 	jb	short sysvideo_18 ; 23/07/2022
 10115 0000F9B6 E95E010000          <1> 	jmp	sysvideo_20 ; ja
 10116                              <1> 
 10117                              <1> 	; 23/07/2022
 10118                              <1> sysvideo_18:
 10119                              <1> 	; BH = 5
 10120                              <1> 	; Direct User Access for VGA video memory.
 10121                              <1> 	; Setup user's page tables for direct access to 0A0000h.
 10122                              <1> 	;
 10123                              <1> 	; Permission checks are not implemented yet !
 10124                              <1> 	; (11/07/2016)
 10125                              <1> 
 10126 0000F9BB B800000A00          <1> 	mov	eax, 0A0000h
 10127 0000F9C0 B910000000          <1> 	mov	ecx, 16 ; 16 pages (16*4K=64K)
 10128 0000F9C5 89C3                <1> 	mov	ebx, eax ; 12/05/2017 ; virtual = physical
 10129 0000F9C7 E8B165FFFF          <1> 	call	direct_memory_access	
 10130                              <1> 	;jc	sysret
 10131                              <1> 	; 23/07/2022
 10132 0000F9CC 7205                <1> 	jc	short sysvideo_18_0
 10133                              <1> 	; eax = 0A0000h if there is not an error
 10134 0000F9CE A3[74940100]        <1> 	mov	[u.r0], eax
 10135                              <1> sysvideo_18_0:
 10136 0000F9D3 E97CD4FFFF          <1> 	jmp	sysret
 10137                              <1> 
 10138                              <1> sysvideo_17_0:
 10139                              <1> 	; BH = 6
 10140                              <1> 	; Direct User Access to Linear Frame Buffer.
 10141                              <1> 	; Setup user's page tables for direct access to LFB.
 10142                              <1> 	;
 10143                              <1> 	; Permission checks are not implemented yet !
 10144                              <1> 	; (10/12/2020)
 10145                              <1> 
 10146 0000F9D8 80FBFF              <1> 	cmp	bl, 0FFh ; current video mode
 10147 0000F9DB 722C                <1> 	jb	short sysvideo_17_2 ; for desired video mode
 10148                              <1> 
 10149 0000F9DD 381D[DE670000]      <1> 	cmp	[CRT_MODE], bl ; VESA VBE video mode ?
 10150 0000F9E3 750E                <1> 	jne	short sysvideo_17_1
 10151 0000F9E5 668B0D[2EA30100]    <1> 	mov	cx, [video_mode]
 10152 0000F9EC 6681E1FF01          <1> 	and	cx, 1FFh
 10153 0000F9F1 EB29                <1> 	jmp	short sysvideo_17_3
 10154                              <1> sysvideo_17_1:
 10155                              <1> 	; 11/12/2020
 10156 0000F9F3 88DF                <1> 	mov	bh, bl ; 0FFh
 10157 0000F9F5 8A1D[DE670000]      <1> 	mov	bl, [CRT_MODE] ; VGA/CGA video mode
 10158 0000F9FB 8B2D[70940100]      <1> 	mov	ebp, [u.usp]  ; ebp points to user's registers
 10159                              <1> 	; 23/12/2020
 10160 0000FA01 895D10              <1> 	mov	[ebp+16], ebx ; return to user with EBX value
 10161 0000FA04 E94BD4FFFF          <1> 	jmp	sysret ; return to user with EAX = 0
 10162                              <1> sysvideo_17_2:
 10163                              <1> 	; bl = VESA video mode - 100h
 10164 0000FA09 B701                <1> 	mov	bh, 1 ; bx = 1XXh
 10165 0000FA0B 53                  <1> 	push	ebx ; requested vesa video mode
 10166 0000FA0C E85C40FFFF          <1> 	call	vbe_biosfn_return_current_mode
 10167 0000FA11 59                  <1> 	pop	ecx ; requested vesa video mode
 10168 0000FA12 6681E3FF01          <1> 	and	bx, 1FFh
 10169 0000FA17 6639D9              <1> 	cmp	cx, bx
 10170 0000FA1A 7564                <1> 	jne	short sysvideo_17_8
 10171                              <1> sysvideo_17_3:
 10172 0000FA1C 663B0D[3AA30100]    <1> 	cmp	cx, [LFB_Info+LFBINFO.mode]
 10173 0000FA23 755B                <1> 	jne	short sysvideo_17_8
 10174                              <1> sysvideo_17_4:
 10175                              <1> 	; 11/12/2020
 10176 0000FA25 A1[3CA30100]        <1> 	mov	eax, [LFB_Info+LFBINFO.LFB_addr]
 10177                              <1> 	; 21/12/2020
 10178 0000FA2A 09C0                <1> 	or	eax, eax
 10179 0000FA2C 744D                <1> 	jz	short sysvideo_17_7
 10180                              <1> 	;
 10181 0000FA2E 8B0D[40A30100]      <1> 	mov	ecx, [LFB_Info+LFBINFO.LFB_size] ; buff size
 10182 0000FA34 89C3                <1> 	mov 	ebx, eax ; user's address = physical address
 10183                              <1> 	;push	ebx
 10184 0000FA36 51                  <1> 	push	ecx
 10185                              <1> 	; 21/12/2020
 10186 0000FA37 81C1FF0F0000        <1> 	add	ecx, 4095  ; PAGESIZE - 1
 10187                              <1> 	; 14/12/2020
 10188 0000FA3D C1E90C              <1> 	shr	ecx, 12  ; convert bytes to pages
 10189 0000FA40 E83865FFFF          <1> 	call	direct_memory_access
 10190 0000FA45 5A                  <1> 	pop	edx  ; linear frame buffer size in bytes
 10191                              <1> 	;pop	eax  ; linear frame buffer address (physical)
 10192 0000FA46 7233                <1> 	jc	short sysvideo_17_7 ; [u.r0] = eax = 0
 10193                              <1> sysvideo_17_5:
 10194 0000FA48 668B0D[46A30100]    <1> 	mov	cx, [LFB_Info+LFBINFO.Y_res] ; screen height
 10195 0000FA4F C1E110              <1> 	shl	ecx, 16
 10196 0000FA52 668B0D[44A30100]    <1> 	mov	cx,  [LFB_Info+LFBINFO.X_res] ; screen width
 10197 0000FA59 31DB                <1> 	xor	ebx, ebx
 10198 0000FA5B 8A1D[48A30100]      <1> 	mov	bl, [LFB_Info+LFBINFO.bpp] ; bits per pixel
 10199 0000FA61 8A3D[3AA30100]      <1> 	mov	bh, [LFB_Info+LFBINFO.mode] ; XX part of 1XXh
 10200                              <1> sysvideo_26_4: ; 23/12/2020	
 10201 0000FA67 8B2D[70940100]      <1> 	mov	ebp, [u.usp]  ; ebp points to user's registers
 10202 0000FA6D 895514              <1> 	mov	[ebp+20], edx ; return to user with EDX value
 10203 0000FA70 895D10              <1> 	mov	[ebp+16], ebx ; EBX
 10204 0000FA73 894D18              <1> 	mov	[ebp+24], ecx ; ECX
 10205                              <1> sysvideo_17_6:
 10206 0000FA76 A3[74940100]        <1> 	mov	[u.r0], eax ; LFB address
 10207                              <1> sysvideo_17_7:
 10208 0000FA7B E9D4D3FFFF          <1> 	jmp	sysret 
 10209                              <1> sysvideo_17_8:
 10210                              <1> 	; cx = mode
 10211                              <1> 	; 21/12/2020
 10212 0000FA80 80CD40              <1> 	or	ch, 40h  ; Linear frame buffer flag
 10213 0000FA83 E8083EFFFF          <1> 	call	_vbe_biosfn_return_mode_info
 10214 0000FA88 72F1                <1> 	jc	short sysvideo_17_7
 10215 0000FA8A EB99                <1> 	jmp	short sysvideo_17_4
 10216                              <1> 
 10217                              <1> sysvideo_19:
 10218                              <1> 	; 23/07/2022
 10219                              <1> 	; 22/01/2021
 10220                              <1> 	; 12/12/2020
 10221                              <1> 	; 11/12/2020
 10222                              <1> 	; 23/11/2020
 10223                              <1> 	; BH = 7
 10224                              <1> 	; Get (Super/Extended VGA) mode
 10225                              <1> 	; and Linear Frame Buffer info.
 10226                              <1> 	
 10227                              <1> 	; 22/01/2021
 10228 0000FA8C B3FF                <1> 	mov	bl, 0FFh
 10229                              <1> 	; 11/12/2020
 10230                              <1> 	;cmp	byte [CRT_MODE], 0FFh ; (extended mode?)
 10231                              <1> 	; 22/01/2021
 10232 0000FA8E 381D[DE670000]      <1> 	cmp	[CRT_MODE], bl  ; 0FFh
 10233                              <1> 	;jb	short sysvideo_17_1 ; not a VESA VBE mode
 10234                              <1> 	; 23/07/2022
 10235                              <1> 	; 12/12/2020
 10236 0000FA94 7305                <1> 	jnb	short sysvideo_19_0
 10237                              <1> 	; 23/07/2022
 10238 0000FA96 E958FFFFFF          <1> 	jmp	sysvideo_17_1
 10239                              <1> 
 10240                              <1> sysvideo_19_0:
 10241 0000FA9B E8CD3FFFFF          <1> 	call	vbe_biosfn_return_current_mode
 10242 0000FAA0 6681E3FF01          <1> 	and	bx, 1FFh
 10243 0000FAA5 663B1D[3AA30100]    <1> 	cmp	bx, [LFB_Info+LFBINFO.mode]
 10244 0000FAAC 750D                <1> 	jne	short sysvideo_19_2
 10245                              <1> sysvideo_19_1:
 10246 0000FAAE A1[3CA30100]        <1> 	mov	eax, [LFB_Info+LFBINFO.LFB_addr]
 10247 0000FAB3 8B15[40A30100]      <1> 	mov	edx, [LFB_Info+LFBINFO.LFB_size]
 10248 0000FAB9 EB8D                <1> 	jmp	sysvideo_17_5
 10249                              <1> sysvideo_19_2:
 10250 0000FABB E8D03DFFFF          <1> 	call	_vbe_biosfn_return_mode_info
 10251 0000FAC0 73EC                <1> 	jnc	short sysvideo_19_1
 10252 0000FAC2 E98DD3FFFF          <1> 	jmp	sysret
 10253                              <1> 
 10254                              <1> sysvideo_20_1:
 10255                              <1> 	; cx = vesa video mode
 10256 0000FAC7 6689C8              <1> 	mov	ax, cx
 10257 0000FACA 663D0001            <1> 	cmp	ax, 100h
 10258 0000FACE 725C                <1> 	jb	short sysvideo_20_0 ; VGA/CGA mode
 10259 0000FAD0 663DFF01            <1> 	cmp	ax, 1FFh
 10260                              <1> 	;ja	short sysvideo_20_4 ; not valid
 10261 0000FAD4 773E                <1> 	ja	short sysvideo_20_3
 10262 0000FAD6 50                  <1> 	push	eax
 10263 0000FAD7 6689C3              <1> 	mov	bx, ax
 10264 0000FADA 66B8024F            <1> 	mov	ax, 4F02h
 10265                              <1> 
 10266                              <1> 	; simulate _int10h (int 31h) for func 4F02h
 10267                              <1> 	;pushfd
 10268                              <1> 	;push	cs
 10269                              <1> 	;push	sysvideo_20_1_retn 
 10270                              <1> 	;push	es ; *
 10271                              <1> 	;push	ds ; **	; SAVE WORK AND PARAMETER REGISTERS
 10272                              <1> 	;jmp	VBE_func
 10273                              <1> ;sysvideo_20_1_retn:
 10274                              <1> 
 10275 0000FADE E8411CFFFF          <1> 	call	_int10h ; simulate int 10h (int 31h)
 10276                              <1> 
 10277 0000FAE3 6683F84F            <1> 	cmp	ax, 004Fh
 10278 0000FAE7 58                  <1> 	pop	eax
 10279 0000FAE8 752A                <1> 	jne	short sysvideo_20_3 ; error
 10280                              <1> 	;pop	eax
 10281 0000FAEA 40                  <1> 	inc	eax
 10282 0000FAEB A3[74940100]        <1> 	mov	[u.r0], eax ; video mode + 1
 10283 0000FAF0 09D2                <1> 	or	edx, edx ; is LFBINFO requested by user ?
 10284                              <1> 	;jz	short sysvideo_20_4
 10285 0000FAF2 7420                <1> 	jz	short sysvideo_20_3 ; no
 10286                              <1> 
 10287                              <1> 	; 11/12/2020
 10288                              <1> 	; Check LFBINFO table/structure
 10289                              <1> 	; (it is set by vbe2 'vbe_biosfn_set_mode'
 10290                              <1> 	; but if vbe3 vbios pmi is in use,
 10291                              <1> 	; it will not set LFBINFO table)
 10292                              <1> 
 10293 0000FAF4 52                  <1> 	push	edx
 10294 0000FAF5 48                  <1> 	dec	eax  ; video mode
 10295 0000FAF6 BE[3AA30100]        <1> 	mov	esi, LFB_Info
 10296 0000FAFB 663B06              <1> 	cmp	ax, [esi+LFBINFO.mode]
 10297 0000FAFE 7407                <1> 	je	short sysvideo_20_2
 10298                              <1> 
 10299 0000FB00 E88B3DFFFF          <1> 	call	_vbe_biosfn_return_mode_info
 10300                              <1> 	;jnc	short sysvideo_20_2
 10301 0000FB05 723B                <1> 	jc	short sysvideo_20_4 ; edx = 0
 10302                              <1> 
 10303                              <1> 	;; clear LFBINFO table for invalidating	
 10304                              <1> 	;mov	ecx, LFBINFO.size ; 16
 10305                              <1> 	;mov	edi, esi ; LFB_Info table address
 10306                              <1> 	;xor	eax, eax
 10307                              <1> 	;rep	stosb
 10308                              <1> 
 10309                              <1> sysvideo_20_2:
 10310                              <1> 	;pop	ecx
 10311                              <1> 	;mov	edi, ecx ; user buffer
 10312 0000FB07 5F                  <1> 	pop	edi
 10313 0000FB08 B910000000          <1> 	mov	ecx, LFBINFO.size ; 16
 10314 0000FB0D E87E140000          <1> 	call	transfer_to_user_buffer ; fast transfer
 10315 0000FB12 722F                <1> 	jc	short sysvideo_20_5
 10316                              <1> 
 10317                              <1> 	;jmp	sysret
 10318                              <1> sysvideo_20_3:	
 10319                              <1> 	;pop	eax ; [u.r0] = 0
 10320                              <1> ;sysvideo_20_4:
 10321 0000FB14 E93BD3FFFF          <1> 	jmp	sysret
 10322                              <1> 
 10323                              <1> 	; 23/07/2022
 10324                              <1> sysvideo_20:
 10325                              <1> 	; 11/12/2020
 10326                              <1> 	; 23/11/2020
 10327 0000FB19 80FF08              <1> 	cmp	bh, 8
 10328                              <1> 	; 08/08/2022
 10329                              <1> 	;jb	short sysvideo_19 ; video mode & lfb info
 10330 0000FB1C 7407                <1> 	je	short sysvideo_20_6
 10331                              <1> 	; 23/07/2022
 10332 0000FB1E 7733                <1> 	ja	short sysvideo_21 ; 12/12/2020
 10333                              <1> 	; 08/08/2022 - jb
 10334 0000FB20 E967FFFFFF          <1> 	jmp	sysvideo_19
 10335                              <1> sysvideo_20_6:
 10336                              <1> 	; BH = 8
 10337                              <1> 	; Set (Super/Extended VGA) mode & return LFB info
 10338                              <1> 
 10339                              <1> 	; 11/12/2020
 10340 0000FB25 80FBFF              <1> 	cmp	bl, 0FFh  ; CGA/VGA mode ?
 10341 0000FB28 739D                <1> 	jnb	short sysvideo_20_1
 10342                              <1> 
 10343                              <1> 	;xor	ah, ah
 10344 0000FB2A 88D8                <1> 	mov	al, bl
 10345                              <1> sysvideo_20_0:
 10346 0000FB2C E8F31BFFFF          <1> 	call	_int10h  ; uses vbe3 pmi32 option
 10347 0000FB31 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh ; -1
 10348 0000FB34 74DE                <1> 	je	short sysvideo_20_3 ; error
 10349                              <1> 	
 10350                              <1> 	; 11/12/2020
 10351                              <1> 	; alternative (it does not use vbe3 pmi32)
 10352                              <1> 	;push	eax
 10353                              <1> 	;call	_set_mode
 10354                              <1> 	;pop	eax
 10355                              <1> 	;jc	short sysvideo_20_3
 10356                              <1> 
 10357                              <1> 	;inc	eax
 10358 0000FB36 FEC0                <1> 	inc	al
 10359                              <1> 	;mov	[u.r0], ax ; video mode + 1
 10360 0000FB38 A2[74940100]        <1> 	mov	[u.r0], al
 10361 0000FB3D E912D3FFFF          <1> 	jmp	sysret
 10362                              <1> 
 10363                              <1> sysvideo_20_4:
 10364 0000FB42 5A                  <1> 	pop	edx
 10365                              <1> sysvideo_20_5:
 10366 0000FB43 31D2                <1> 	xor	edx, edx ; 0
 10367                              <1> 	; edx = 0 -> invalid LFBINFO data
 10368 0000FB45 8B2D[70940100]      <1> 	mov	ebp, [u.usp]  ; ebp points to user's registers
 10369 0000FB4B 895514              <1> 	mov	[ebp+20], edx ; return to user with EDX value
 10370 0000FB4E E901D3FFFF          <1> 	jmp	sysret
 10371                              <1> 
 10372                              <1> sysvideo_21:
 10373                              <1> 	; 23/07/2022
 10374                              <1> 	; 04/01/2021
 10375                              <1> 	; 03/12/2020
 10376 0000FB53 80FF0A              <1> 	cmp	bh, 10
 10377                              <1> 	;jb	sysvideo_22 ; VESA VBE3 pmi parms
 10378                              <1> 	; 23/07/2022
 10379 0000FB56 723F                <1> 	jb	short sysvideo_21_19
 10380                              <1> 	; 23/12/2020
 10381                              <1> 	;je	sysvideo_26 ; Video memory mapping
 10382                              <1> 	; 23/07/2022
 10383 0000FB58 7442                <1> 	je	short sysvideo_21_20
 10384                              <1> 
 10385                              <1> 	; 04/01/2020
 10386 0000FB5A 80FF0B              <1> 	cmp	bh, 11
 10387                              <1> 	;ja	sysvideo_27
 10388                              <1> 	; 23/07/2022
 10389 0000FB5D 7742                <1> 	ja	short sysvideo_21_21
 10390                              <1> 		
 10391                              <1> 	; BH = 11
 10392                              <1> 	; set/read DAC color registers (for 8bpp)
 10393                              <1> 
 10394 0000FB5F 80FB04              <1> 	cmp	bl, 4
 10395                              <1> 	;jnb	sysvideo_21_7	; BMP file type palette
 10396                              <1> 				; handling
 10397                              <1> 	; 23/07/2022
 10398                              <1> 	;jnb	short sysvideo_21_7
 10399                              <1> 	; 08/08/2022
 10400 0000FB62 7205                <1> 	jb	short sysvideo_21_18
 10401 0000FB64 E989000000          <1> 	jmp	sysvideo_21_7
 10402                              <1> sysvideo_21_18:	
 10403 0000FB69 F6C301              <1> 	test	bl, 1
 10404 0000FB6C 7563                <1> 	jnz	short sysvideo_21_4 ; set/write DAC colors
 10405                              <1> 		
 10406                              <1> 	; Read DAC color register or all DAC color registers
 10407 0000FB6E F6C302              <1> 	test	bl, 2  ; read single DAC color register
 10408 0000FB71 7433                <1> 	jz	short sysvideo_21_2 ; read all DAC color regs
 10409                              <1> 
 10410                              <1> 	; read single DAC color register
 10411                              <1> 	; CL = DAC color register (index)
 10412                              <1>  	
 10413 0000FB73 66BAC703            <1> 	mov	dx, 3C7h ; VGAREG_DAC_READ_ADDRESS
 10414 0000FB77 88C8                <1> 	mov	al, cl	; DAC color register
 10415 0000FB79 31C9                <1> 	xor	ecx, ecx ; (this may not be necessary)
 10416 0000FB7B EE                  <1> 	out	dx, al
 10417                              <1> 	;mov	dx, 3C9h ; VGAREG_DAC_DATA
 10418 0000FB7C B2C9                <1> 	mov	dl, 0C9h
 10419 0000FB7E EC                  <1> 	in	al, dx
 10420 0000FB7F 88C4                <1> 	mov	ah, al	; red
 10421 0000FB81 EC                  <1> 	in	al, dx
 10422 0000FB82 88C1                <1> 	mov	cl, al	; green
 10423 0000FB84 EC                  <1> 	in	al, dx
 10424 0000FB85 88C5                <1> 	mov	ch, al	; blue
 10425 0000FB87 C1E108              <1> 	shl	ecx, 8
 10426 0000FB8A 88E1                <1> 	mov	cl, ah	; red
 10427                              <1> 	; CL = Red, CH = Green, byte 3 = Blue, byte 4 = 0
 10428                              <1> sysvideo_21_0:
 10429 0000FB8C 890D[74940100]      <1> 	mov	[u.r0], ecx
 10430                              <1> sysvideo_21_1:
 10431 0000FB92 E9BDD2FFFF          <1> 	jmp	sysret
 10432                              <1> sysvideo_21_19:
 10433                              <1> 	; 23/07/2022
 10434 0000FB97 E97A010000          <1> 	jmp	sysvideo_22
 10435                              <1> sysvideo_21_20:
 10436                              <1> 	; 23/07/2022
 10437 0000FB9C E930020000          <1> 	jmp	sysvideo_26
 10438                              <1> sysvideo_21_21:
 10439                              <1> 	; 23/07/2022
 10440 0000FBA1 E9B6020000          <1> 	jmp	sysvideo_27
 10441                              <1> sysvideo_21_2:
 10442                              <1> 	; read all DAC color registers
 10443 0000FBA6 89CB                <1> 	mov	ebx, ecx ; user's buffer address
 10444 0000FBA8 BF00600900          <1> 	mov	edi, VBE3STACKADDR
 10445 0000FBAD 89FE                <1> 	mov	esi, edi
 10446                              <1> 	;mov	ecx, 768 ; 256*3
 10447                              <1> 	; 08/08/2022
 10448 0000FBAF 29C9                <1> 	sub	ecx, ecx
 10449 0000FBB1 B503                <1> 	mov	ch, 3
 10450                              <1> 	; ecx = 768 = 300h
 10451                              <1> 	;push	ecx
 10452 0000FBB3 66BAC703            <1> 	mov	dx, 3C7h ; VGAREG_DAC_READ_ADDRESS
 10453 0000FBB7 28C0                <1> 	sub	al, al ; 0
 10454 0000FBB9 EE                  <1> 	out	dx, al
 10455                              <1> 	;mov	dx, 3C9h ; VGAREG_DAC_DATA
 10456 0000FBBA B2C9                <1> 	mov	dl, 0C9h
 10457                              <1> sysvideo_21_3:
 10458 0000FBBC EC                  <1> 	in	al, dx
 10459 0000FBBD AA                  <1> 	stosb
 10460 0000FBBE EC                  <1> 	in	al, dx
 10461 0000FBBF AA                  <1> 	stosb
 10462 0000FBC0 EC                  <1> 	in	al, dx
 10463 0000FBC1 AA                  <1> 	stosb
 10464 0000FBC2 E2F8                <1> 	loop	sysvideo_21_3
 10465                              <1> 	;pop	ecx
 10466                              <1> 	; 18/08/2022
 10467 0000FBC4 B503                <1> 	mov	ch, 3
 10468                              <1> 	; ecx = 768 = 300h
 10469                              <1> 
 10470 0000FBC6 89DF                <1> 	mov	edi, ebx ; user's buffer address
 10471                              <1> 	;mov	esi, VBE3STACKADDR
 10472                              <1> 	;mov	ecx, 256*3 = 768
 10473 0000FBC8 E8C3130000          <1> 	call	transfer_to_user_buffer
 10474 0000FBCD 72C3                <1> 	jc	short sysvideo_21_1
 10475                              <1> 	;mov	[u.r0], ecx ; actual transfer count
 10476 0000FBCF EBBB                <1> 	jmp	short sysvideo_21_0
 10477                              <1> 
 10478                              <1> sysvideo_21_4:
 10479                              <1> 	; Set/Write DAC color register or all registers
 10480 0000FBD1 F6C302              <1> 	test	bl, 2 ; write/set single DAC color register
 10481 0000FBD4 7456                <1> 	jz	short sysvideo_21_5 ; set all DAC color regs
 10482                              <1> 
 10483                              <1> 	; set single DAC color register
 10484                              <1> 	; CL = DAC color register (index)
 10485                              <1> 	; (byte 1 = Red, byte 2 = Green, byte 3 = Blue)
 10486                              <1> 
 10487 0000FBD6 66BAC803            <1> 	mov	dx, 3C8h ; VGAREG_DAC_WRITE_ADDRESS
 10488 0000FBDA 89C8                <1> 	mov	eax, ecx ; DAC color register (index)
 10489 0000FBDC C1E910              <1> 	shr	ecx, 16  ; CL = green, AH = Red
 10490 0000FBDF EE                  <1> 	out	dx, al
 10491                              <1> 	;mov	dx, 3C9h ; VGAREG_DAC_DATA
 10492 0000FBE0 FEC2                <1> 	inc	dl
 10493 0000FBE2 88E0                <1> 	mov	al, ah	; Red
 10494 0000FBE4 EE                  <1> 	out	dx, al
 10495 0000FBE5 88C8                <1> 	mov	al, cl	; Green
 10496 0000FBE7 EE                  <1> 	out	dx, al
 10497 0000FBE8 88E8                <1> 	mov	al, ch	; Blue
 10498 0000FBEA EE                  <1> 	out	dx, al
 10499                              <1> 	;rol	ecx, 8
 10500 0000FBEB C1E108              <1> 	shl	ecx, 8	; 21/02/2021
 10501 0000FBEE 88E1                <1> 	mov	cl, ah	; Red
 10502                              <1> 		; ecx = 00BBGGRRh
 10503 0000FBF0 EB9A                <1> 	jmp	short sysvideo_21_0
 10504                              <1> 
 10505                              <1> 	; 23/07/2022
 10506                              <1> sysvideo_21_7:	
 10507                              <1> 	; BMP file type palette handling
 10508                              <1> 
 10509 0000FBF2 F6C301              <1> 	test	bl, 1
 10510                              <1> 	;jnz	short sysvideo_21_12 ; set/write DAC colors
 10511                              <1> 	; 08/08/2022
 10512 0000FBF5 7405                <1> 	jz	short sysvideo_21_16
 10513 0000FBF7 E9A3000000          <1> 	jmp	sysvideo_21_12
 10514                              <1> 
 10515                              <1> sysvideo_21_16:
 10516                              <1> 	; Read DAC color register or all DAC color registers
 10517 0000FBFC F6C302              <1> 	test	bl, 2  ; read single DAC color register
 10518 0000FBFF 7460                <1> 	jz	short sysvideo_21_10 ; read all DAC color regs
 10519                              <1> 
 10520                              <1> 	; read single DAC color register
 10521                              <1> 	; CL = DAC color register (index)
 10522                              <1>  	
 10523 0000FC01 66BAC703            <1> 	mov	dx, 3C7h ; VGAREG_DAC_READ_ADDRESS
 10524 0000FC05 88C8                <1> 	mov	al, cl	; DAC color register
 10525 0000FC07 31C9                <1> 	xor	ecx, ecx
 10526 0000FC09 EE                  <1> 	out	dx, al
 10527                              <1> 	;mov	dx, 3C9h ; VGAREG_DAC_DATA
 10528 0000FC0A B2C9                <1> 	mov	dl, 0C9h
 10529 0000FC0C EC                  <1> 	in	al, dx
 10530 0000FC0D C0E002              <1> 	shl	al, 2
 10531 0000FC10 88C5                <1> 	mov	ch, al	; red
 10532 0000FC12 EC                  <1> 	in	al, dx
 10533 0000FC13 C0E002              <1> 	shl	al, 2
 10534 0000FC16 88C1                <1> 	mov	cl, al	; green
 10535 0000FC18 EC                  <1> 	in	al, dx
 10536 0000FC19 C0E002              <1> 	shl	al, 2
 10537                              <1> 	; 21/02/2021
 10538 0000FC1C C1E108              <1> 	shl	ecx, 8
 10539 0000FC1F 88C1                <1> 	mov	cl, al	; blue
 10540                              <1> 	; CL = Blue, CH = Green, byte 3 = Red, byte 4 = 0
 10541                              <1> sysvideo_21_8:
 10542 0000FC21 890D[74940100]      <1> 	mov	[u.r0], ecx
 10543                              <1> sysvideo_21_9:
 10544 0000FC27 E928D2FFFF          <1> 	jmp	sysret
 10545                              <1> 
 10546                              <1> sysvideo_21_5:
 10547                              <1> 	; write/set all DAC color registers
 10548 0000FC2C 89CE                <1> 	mov	esi, ecx ; user's buffer address
 10549 0000FC2E BF00600900          <1> 	mov	edi, VBE3STACKADDR
 10550 0000FC33 89FB                <1> 	mov	ebx, edi
 10551 0000FC35 B900030000          <1> 	mov	ecx, 768 ; 256*3
 10552 0000FC3A E89B130000          <1> 	call	transfer_from_user_buffer
 10553                              <1> 	;jc	short sysvideo_21_1
 10554                              <1> 	; 08/08/2022
 10555 0000FC3F 7305                <1> 	jnc	short sysvideo_21_17
 10556 0000FC41 E94CFFFFFF          <1> 	jmp	sysvideo_21_1
 10557                              <1> sysvideo_21_17:
 10558 0000FC46 890D[74940100]      <1> 	mov	[u.r0], ecx ; actual transfer count
 10559                              <1> 
 10560 0000FC4C 89DE                <1> 	mov	esi, ebx ; VBE3STACKADDR
 10561 0000FC4E 66BAC803            <1> 	mov	dx, 3C8h ; VGAREG_DAC_WRITE_ADDRESS
 10562 0000FC52 28C0                <1> 	sub	al, al ; 0
 10563 0000FC54 EE                  <1> 	out	dx, al
 10564                              <1> 	;mov	dx, 3C9h ; VGAREG_DAC_DATA
 10565 0000FC55 FEC2                <1> 	inc	dl
 10566                              <1> sysvideo_21_6:
 10567 0000FC57 AC                  <1> 	lodsb
 10568 0000FC58 EE                  <1> 	out	dx, al
 10569 0000FC59 AC                  <1> 	lodsb
 10570 0000FC5A EE                  <1> 	out	dx, al
 10571 0000FC5B AC                  <1> 	lodsb
 10572 0000FC5C EE                  <1> 	out	dx, al
 10573 0000FC5D E2F8                <1> 	loop	sysvideo_21_6
 10574 0000FC5F EBC6                <1> 	jmp	short sysvideo_21_9
 10575                              <1> 
 10576                              <1> sysvideo_21_10:
 10577                              <1> 	; read all DAC color registers
 10578 0000FC61 89CD                <1> 	mov	ebp, ecx ; user's buffer address
 10579 0000FC63 BF00600900          <1> 	mov	edi, VBE3STACKADDR
 10580 0000FC68 89FE                <1> 	mov	esi, edi
 10581 0000FC6A B900040000          <1> 	mov	ecx, 1024 ; 256*4
 10582 0000FC6F 51                  <1> 	push	ecx
 10583 0000FC70 66BAC703            <1> 	mov	dx, 3C7h ; VGAREG_DAC_READ_ADDRESS
 10584 0000FC74 28C0                <1> 	sub	al, al ; 0
 10585 0000FC76 EE                  <1> 	out	dx, al
 10586                              <1> 	;mov	dx, 3C9h ; VGAREG_DAC_DATA
 10587 0000FC77 B2C9                <1> 	mov	dl, 0C9h
 10588                              <1> sysvideo_21_11:
 10589 0000FC79 31DB                <1> 	xor	ebx, ebx
 10590 0000FC7B EC                  <1> 	in	al, dx	; Red
 10591 0000FC7C C0E002              <1> 	shl	al, 2
 10592 0000FC7F 88C7                <1> 	mov	bh, al
 10593 0000FC81 EC                  <1> 	in	al, dx	; Green
 10594 0000FC82 C0E002              <1> 	shl	al, 2
 10595 0000FC85 88C3                <1> 	mov	bl, al
 10596 0000FC87 EC                  <1> 	in	al, dx	; Blue
 10597 0000FC88 C0E002              <1> 	shl	al, 2
 10598 0000FC8B C1E308              <1> 	shl	ebx, 8
 10599 0000FC8E 89D8                <1> 	mov	eax, ebx ; 00RRGGBBh
 10600 0000FC90 AB                  <1> 	stosd	
 10601 0000FC91 E2E6                <1> 	loop	sysvideo_21_11
 10602 0000FC93 59                  <1> 	pop	ecx
 10603                              <1> 
 10604 0000FC94 89EF                <1> 	mov	edi, ebp ; user's buffer address
 10605                              <1> 	;mov	esi, VBE3STACKADDR
 10606                              <1> 	;mov	ecx, 1024 = 4*256
 10607 0000FC96 E8F5120000          <1> 	call	transfer_to_user_buffer
 10608 0000FC9B 728A                <1> 	jc	short sysvideo_21_9
 10609                              <1> 	;mov	[u.r0], ecx ; actual transfer count
 10610 0000FC9D EB82                <1> 	jmp	short sysvideo_21_8
 10611                              <1> 
 10612                              <1> sysvideo_21_12:
 10613                              <1> 	; Set/Write DAC color register or all registers
 10614 0000FC9F F6C302              <1> 	test	bl, 2 ; write/set single DAC color register
 10615 0000FCA2 742A                <1> 	jz	short sysvideo_21_13 ; set all DAC color regs
 10616                              <1> 
 10617                              <1> 	; set single DAC color register
 10618                              <1> 	; CL = DAC color register (index)
 10619                              <1> 	; (byte 1 = Blue, byte 2 = Green, byte 3 = Red)
 10620                              <1> 
 10621 0000FCA4 66BAC803            <1> 	mov	dx, 3C8h ; VGAREG_DAC_WRITE_ADDRESS
 10622 0000FCA8 88C8                <1> 	mov	al, cl	; DAC color register (index)
 10623 0000FCAA 88EC                <1> 	mov	ah, ch	; Blue
 10624 0000FCAC C1E910              <1> 	shr	ecx, 16
 10625 0000FCAF EE                  <1> 	out	dx, al
 10626                              <1> 	;mov	dx, 3C9h ; VGAREG_DAC_DATA
 10627 0000FCB0 FEC2                <1> 	inc	dl
 10628 0000FCB2 88E8                <1> 	mov	al, ch	; Red
 10629 0000FCB4 C0E802              <1> 	shr	al, 2
 10630 0000FCB7 EE                  <1> 	out	dx, al
 10631 0000FCB8 88C8                <1> 	mov	al, cl	; Green
 10632 0000FCBA C0E802              <1> 	shr	al, 2
 10633 0000FCBD EE                  <1> 	out	dx, al
 10634 0000FCBE 88E0                <1> 	mov	al, ah	; Blue
 10635 0000FCC0 C0E802              <1> 	shr	al, 2
 10636 0000FCC3 EE                  <1> 	out	dx, al
 10637                              <1> 	;rol	ecx, 8
 10638 0000FCC4 C1E108              <1> 	shl	ecx, 8 ; 21/02/2021
 10639 0000FCC7 88E1                <1> 	mov	cl, ah
 10640 0000FCC9 E953FFFFFF          <1> 	jmp	sysvideo_21_8 ; 08/08/2022
 10641                              <1> 
 10642                              <1> sysvideo_21_13:
 10643                              <1> 	; write/set all DAC color registers
 10644 0000FCCE 89CE                <1> 	mov	esi, ecx ; user's buffer address
 10645 0000FCD0 BF00600900          <1> 	mov	edi, VBE3STACKADDR
 10646 0000FCD5 89FB                <1> 	mov	ebx, edi
 10647 0000FCD7 B900040000          <1> 	mov	ecx, 1024 ; 256*4
 10648 0000FCDC E8F9120000          <1> 	call	transfer_from_user_buffer
 10649 0000FCE1 722E                <1> 	jc	short sysvideo_21_15
 10650 0000FCE3 890D[74940100]      <1> 	mov	[u.r0], ecx ; actual transfer count
 10651                              <1> 
 10652 0000FCE9 89DE                <1> 	mov	esi, ebx ; VBE3STACKADDR
 10653 0000FCEB 66BAC803            <1> 	mov	dx, 3C8h ; VGAREG_DAC_WRITE_ADDRESS
 10654 0000FCEF 28C0                <1> 	sub	al, al ; 0
 10655 0000FCF1 EE                  <1> 	out	dx, al
 10656                              <1> 	;mov	dx, 3C9h ; VGAREG_DAC_DATA
 10657 0000FCF2 FEC2                <1> 	inc	dl
 10658                              <1> sysvideo_21_14:
 10659 0000FCF4 AD                  <1> 	lodsd
 10660                              <1> 	; byte 0 = Blue, byte 1 = Green, byte 2 = Red
 10661                              <1> 	; 21/02/2021
 10662 0000FCF5 89C3                <1> 	mov	ebx, eax ; BL = Blue, BH = Green
 10663 0000FCF7 C1CB08              <1> 	ror	ebx, 8 ; BL = Green, BH = Red
 10664 0000FCFA 88F8                <1> 	mov	al, bh
 10665 0000FCFC C0E802              <1> 	shr	al, 2
 10666 0000FCFF EE                  <1> 	out	dx, al ; Red
 10667 0000FD00 88D8                <1> 	mov	al, bl
 10668 0000FD02 C0E802              <1> 	shr	al, 2	
 10669 0000FD05 EE                  <1> 	out	dx, al ; Green
 10670 0000FD06 C1C308              <1> 	rol	ebx, 8 ; BL = Blue
 10671 0000FD09 88D8                <1> 	mov	al, bl
 10672 0000FD0B C0E802              <1> 	shr	al, 2
 10673 0000FD0E EE                  <1> 	out	dx, al ; Blue 
 10674 0000FD0F E2E3                <1> 	loop	sysvideo_21_14
 10675                              <1> sysvideo_21_15:
 10676 0000FD11 E93ED1FFFF          <1> 	jmp	sysret
 10677                              <1> 
 10678                              <1> sysvideo_22:
 10679                              <1> 	; 28/02/2021
 10680                              <1> 	; 22/01/2021
 10681                              <1> 	; 17/01/2021
 10682                              <1> 	; 04/12/2020
 10683                              <1> 	; 03/12/2020
 10684                              <1> 	; BH = 9
 10685                              <1> 	; Set/Get VESA VBE3 protected mode interface params
 10686                              <1> 
 10687                              <1> 	; 22/01/2021
 10688                              <1> 	;cmp	byte [vbe3], 3
 10689                              <1> 	;jne	short sysvideo_25 ; not applicable if
 10690                              <1> 				; vbe3 compatible video bios
 10691                              <1> 				; is not detected by kernel
 10692 0000FD16 80FB02              <1> 	cmp	bl, 2
 10693                              <1> 	;ja	short sysvideo_25 ; bl > 2 not implemented
 10694                              <1> 	; 17/01/2021
 10695 0000FD19 7716                <1> 	ja	short sysvideo_22_0 ; srvs flag sub function
 10696                              <1> 	;jb	short sysvideo_23
 10697                              <1> 
 10698                              <1> 	; 21/01/2021
 10699 0000FD1B 803D[86090000]03    <1> 	cmp	byte [vbe3], 3
 10700                              <1> 	;jne	short sysvideo_25 ; not applicable if
 10701                              <1> 				; vbe3 compatible video bios
 10702                              <1> 				; is not detected by kernel
 10703 0000FD22 75ED                <1> 	jne	short sysvideo_21_15 ; 28/02/2021
 10704                              <1> 	
 10705 0000FD24 80FB01              <1> 	cmp	bl, 1
 10706 0000FD27 7673                <1> 	jna	short sysvideo_23
 10707                              <1> 
 10708 0000FD29 8A1D[2CA30100]      <1> 	mov	bl, [pmi32] ; Video bios 32 bit PMI functions
 10709 0000FD2F EB78                <1> 	jmp	short sysvideo_24
 10710                              <1> 
 10711                              <1> sysvideo_22_0:
 10712                              <1> 	; 17/01/2021
 10713                              <1> 	; save/restore video state user permission
 10714 0000FD31 80FB05              <1> 	cmp	bl, 5
 10715 0000FD34 771E                <1> 	ja	short sysvideo_22_2
 10716 0000FD36 7208                <1> 	jb	short sysvideo_22_1
 10717                              <1> 	; get srvs flag value/status
 10718 0000FD38 8A1D[90A30100]      <1> 	mov	bl, [srvsf] ; 0 = disabled, 1 = enabled
 10719 0000FD3E EB2C                <1> 	jmp	short sysvideo_22_3
 10720                              <1> 
 10721                              <1> sysvideo_22_1:
 10722                              <1> 	; permission (root and multi tasking) check
 10723 0000FD40 E836000000          <1> 	call	sysvideo_22_4
 10724 0000FD45 736A                <1> 	jnc	short sysvideo_25 ; not permitted !
 10725                              <1> 	; cf = 1
 10726 0000FD47 80EB03              <1> 	sub	bl, 3 ; disable = 0, enable = 1
 10727                              <1> 	; 22/01/2021
 10728 0000FD4A 881D[90A30100]      <1> 	mov	[srvsf], bl
 10729 0000FD50 FEC3                <1> 	inc	bl ; 1 = disabled, 2 = enabled
 10730 0000FD52 EB18                <1> 	jmp	short sysvideo_22_3
 10731                              <1> 
 10732                              <1> sysvideo_22_2:
 10733 0000FD54 80FB06              <1> 	cmp	bl, 6
 10734                              <1> 	;ja	short sysvideo_25 ; invalid/unimplemented
 10735                              <1> 	; 28/02/2021
 10736 0000FD57 7733                <1> 	ja	short sysvideo_22_6
 10737                              <1> 	; get VESA VBE number/status
 10738 0000FD59 8A25[86090000]      <1> 	mov	ah, [vbe3] ; vbe3 = 3, vbe2 = 2, others = 0
 10739 0000FD5F A0[87090000]        <1> 	mov	al, [vbe2bios] ; bochs/qemu/vbox emulator status
 10740 0000FD64 66A3[74940100]      <1> 	mov	[u.r0], ax
 10741 0000FD6A EB45                <1> 	jmp	short sysvideo_25
 10742                              <1> 
 10743                              <1> sysvideo_22_3:
 10744                              <1> 	; 22/01/2021
 10745 0000FD6C 8A3D[91A30100]      <1> 	mov	bh, [srvso] ; state options (> 80h -> svga)
 10746 0000FD72 66891D[74940100]    <1> 	mov	[u.r0], bx ; function result is return value 
 10747 0000FD79 EB36                <1> 	jmp	short sysvideo_25 
 10748                              <1> 
 10749                              <1> sysvideo_22_4:
 10750                              <1> 	; 17/01/2021 - permission will be given by root only
 10751 0000FD7B 803D[4E890100]00    <1> 	cmp	byte [multi_tasking], 0 ; in single user mode
 10752 0000FD82 7707                <1> 	ja	short sysvideo_22_5
 10753                              <1> 	; 19/01/2021
 10754 0000FD84 803D[C6940100]01    <1>  	cmp	byte [u.uid], 1 ; ([u.uid] = 0 -> root)
 10755                              <1> sysvideo_22_5:
 10756                              <1> 	; [multi_tasking] = 0 & [u.uid] = 0 -> CF = 1
 10757                              <1> 	; otherwise -> CF = 0 
 10758 0000FD8B C3                  <1> 	retn
 10759                              <1> 
 10760                              <1> sysvideo_22_6:
 10761                              <1> 	; 28/02/2021
 10762 0000FD8C 80FB09              <1> 	cmp	bl, 9
 10763 0000FD8F 7720                <1> 	ja	short sysvideo_25 ; invalid/unimplemented
 10764 0000FD91 7436                <1> 	je	short sysvideo_22_9
 10765 0000FD93 80FB08              <1> 	cmp	bl, 8
 10766 0000FD96 721E                <1> 	jb	short sysvideo_22_7
 10767                              <1> 
 10768                              <1> 	; BL = 8
 10769                              <1> 	; Set default true color bpp to 24
 10770                              <1> 
 10771 0000FD98 B318                <1> 	mov	bl, 24
 10772                              <1> 	;mov	[truecolor], al	; 24bpp (RRGGBBh)
 10773                              <1> 	;mov	[u.r0], al
 10774                              <1> 	;jmp	short sysvideo_25
 10775 0000FD9A EB25                <1> 	jmp	short sysvideo_22_8
 10776                              <1> 
 10777                              <1> sysvideo_23:
 10778                              <1> 	; 17/01/2021
 10779                              <1> 	; permission (root and multi tasking) check
 10780 0000FD9C E8DAFFFFFF          <1> 	call	sysvideo_22_4
 10781 0000FDA1 730E                <1> 	jnc	short sysvideo_25 ; not permitted !
 10782                              <1> 
 10783 0000FDA3 881D[2CA30100]      <1> 	mov	[pmi32], bl ; 1 = enabled, 0 = disabled
 10784                              <1> sysvideo_24:
 10785 0000FDA9 FEC3                <1> 	inc	bl
 10786                              <1> sysvideo_22_10:	; 28/02/2021
 10787 0000FDAB 881D[74940100]      <1> 	mov	[u.r0], bl ; function result is return value
 10788                              <1> sysvideo_25:
 10789 0000FDB1 E99ED0FFFF          <1> 	jmp	sysret
 10790                              <1> 
 10791                              <1> sysvideo_22_7:
 10792                              <1> 	; BL = 7
 10793                              <1> 	; Set default true color bpp to 32
 10794                              <1> 	; (it will set if [VBE3]=3)
 10795                              <1> 
 10796                              <1> 	; Note: This sub function is used to set 24bpp
 10797                              <1> 	; VESA VBE video modes to 32bpp.. because,
 10798                              <1> 	; old hardware uses 24 bpp but new video hardware
 10799                              <1> 	; uses 32bpp for same VESA VBE truecolor modes.
 10800                              <1> 	; (For example: VBE mode 112h is 640*480, 24bpp but
 10801                              <1> 	; new hardware uses/apply it as 640*480, 32bpp.)
 10802                              <1> 	; So, TRDOS 386 v2.0.3 kernel will check [truecolor]
 10803                              <1> 	; status is 32 bpp or not and it will change 24bpp
 10804                              <1> 	; to 32bpp if default [truecolor] value is 32, for
 10805                              <1> 	; same video mode number.
 10806                              <1> 
 10807 0000FDB6 803D[86090000]03    <1> 	cmp	byte [vbe3], 3
 10808 0000FDBD 75F2                <1> 	jne	short sysvideo_25 ; Only applicable 
 10809                              <1> 				  ; for VBE3 video hardware!
 10810 0000FDBF B320                <1> 	mov	bl, 32
 10811                              <1> sysvideo_22_8:
 10812 0000FDC1 881D[87790100]      <1> 	mov	[truecolor], bl	; 32bpp (00RRGGBBh)
 10813                              <1> 	;mov	[u.r0], bl
 10814                              <1> 	;jmp	short sysvideo_25
 10815 0000FDC7 EBE2                <1> 	jmp	short sysvideo_22_10
 10816                              <1> 
 10817                              <1> sysvideo_22_9:
 10818                              <1> 	; BL = 9
 10819                              <1> 	; Return default true color bpp
 10820 0000FDC9 8A1D[87790100]      <1> 	mov	bl, [truecolor]
 10821 0000FDCF EBDA                <1> 	jmp	short sysvideo_22_10
 10822                              <1> ;sysvideo_22_10:
 10823                              <1> 	;mov	[u.r0], bl
 10824                              <1> 	;jmp	sysret
 10825                              <1> 
 10826                              <1> sysvideo_26:
 10827                              <1> 	; 23/12/2020
 10828                              <1> 	; BH = 10
 10829                              <1> 	; Map video memory to user's buffer
 10830                              <1> 	; (multiuser/owner r/w permisions are ignored
 10831                              <1> 	;  for current TRDOS 386 version !)
 10832                              <1> 
 10833 0000FDD1 6681E100F0          <1> 	and	cx, ~4095  ; clear low 12 bits
 10834 0000FDD6 09C9                <1> 	or	ecx, ecx ; start address of user's buffer
 10835 0000FDD8 74D7                <1> 	jz	short sysvideo_25 ; error !
 10836                              <1> 
 10837 0000FDDA 80FB01              <1> 	cmp	bl, 1  ; VGA memory mapping ?
 10838 0000FDDD 740E                <1> 	je	short sysvideo_26_1
 10839 0000FDDF 7718                <1> 	ja	short sysvideo_26_2
 10840                              <1> sysvideo_26_0:
 10841                              <1> 	; BL = 0 : CGA memory (0B8000h) map (32K)
 10842 0000FDE1 B800800B00          <1> 	mov	eax, 0B8000h
 10843 0000FDE6 BB00800000          <1> 	mov	ebx, 32768
 10844 0000FDEB EB37                <1> 	jmp	short sysvideo_26_3
 10845                              <1> sysvideo_26_1:
 10846                              <1> 	; BL = 1 : VGA memory (0A0000h) map (64K)
 10847 0000FDED B800000A00          <1> 	mov	eax, 0A0000h
 10848 0000FDF2 BB00000100          <1> 	mov	ebx, 65536
 10849 0000FDF7 EB2B                <1> 	jmp	short sysvideo_26_3
 10850                              <1> sysvideo_26_2:
 10851                              <1> 	; BL = 2 : SVGA memory (LFB) map to user's buffer
 10852 0000FDF9 803D[86090000]02    <1> 	cmp	byte [vbe3], 2  ; VESA VBE 2/3 vbios ready ?
 10853 0000FE00 72AF                <1> 	jb	short sysvideo_25  ; no, error !
 10854 0000FE02 6681E200F0          <1> 	and	dx, ~4095 ; clear low 12 bits
 10855 0000FE07 09D2                <1> 	or	edx, edx  ; buffer size in bytes
 10856 0000FE09 74A6                <1> 	jz	short sysvideo_25  ; error
 10857 0000FE0B 89D3                <1> 	mov	ebx, edx
 10858 0000FE0D A1[3CA30100]        <1> 	mov	eax, [LFB_ADDR] ; [LFB_Info+LFBINFO.LFB_addr]
 10859 0000FE12 21C0                <1> 	and	eax, eax
 10860 0000FE14 7425                <1> 	jz	short sysvideo_26_5
 10861                              <1> 				; (LFB parms are not set yet)
 10862 0000FE16 3B1D[40A30100]      <1> 	cmp	ebx, [LFB_SIZE] ; [LFB_Info+LFBINFO.LFB_size]
 10863 0000FE1C 7606                <1> 	jna	short sysvideo_26_3
 10864 0000FE1E 8B1D[40A30100]      <1> 	mov	ebx, [LFB_SIZE]
 10865                              <1> sysvideo_26_3: 
 10866 0000FE24 52                  <1> 	push	edx
 10867 0000FE25 53                  <1> 	push	ebx	; buffer size in bytes
 10868 0000FE26 51                  <1> 	push	ecx	; user's buffer address
 10869 0000FE27 87CB                <1> 	xchg	ebx, ecx
 10870 0000FE29 C1E90C              <1> 	shr	ecx, 12 ; convert buffer size to page count
 10871 0000FE2C E84C61FFFF          <1> 	call	direct_memory_access
 10872 0000FE31 59                  <1> 	pop	ecx	; user's buffer address
 10873 0000FE32 5B                  <1> 	pop	ebx	; buffer size
 10874 0000FE33 5A                  <1> 	pop	edx
 10875                              <1> 	;jc	short sysvideo_25 ; error !
 10876                              <1> 				  ; [u.r0] = 0
 10877                              <1> 	; 28/02/2021
 10878 0000FE34 7235                <1> 	jc	short sysvideo_27_0 ; error !
 10879                              <1> 
 10880                              <1> ;sysvideo_26_4:
 10881                              <1> 	;mov	ebp, [u.usp] ; ebp points to user's registers
 10882                              <1> 	;mov	[ebp+20], edx ; return to user with EDX value
 10883                              <1> 	;mov	[ebp+16], ebx ; EBX
 10884                              <1> 	;mov	[ebp+24], ecx ; ECX
 10885                              <1> 	; eax = physical address of video memory (LFB)
 10886                              <1> 	;mov	[u.r0], eax
 10887                              <1> 	;jmp	sysret
 10888 0000FE36 E92CFCFFFF          <1> 	jmp	sysvideo_26_4
 10889                              <1> 
 10890                              <1> sysvideo_26_5:
 10891 0000FE3B 66A1[1A0F0000]      <1> 	mov	ax, [def_LFB_addr] ; default LFB for mode 118h
 10892                              <1> 	; ah must be 0C0h or 0D0h or E0h
 10893                              <1> 	; others are nonsence !?
 10894 0000FE41 08E4                <1>  	or	ah, ah
 10895                              <1> 	;jz	short sysvideo_25 ; invalid lfb addr or
 10896                              <1> 			  	; it is not a vbe2 -bochs emu-
 10897                              <1> 			  	; or vbe3 -real- video bios
 10898                              <1> 	; 28/02/2021
 10899 0000FE43 7426                <1> 	jz	short sysvideo_27_0 ; invalid LFB address
 10900                              <1>  
 10901 0000FE45 80FCF0              <1> 	cmp	ah, 0F0h  
 10902                              <1> 	;jnb	short sysvideo_25 ; nonsence !?
 10903                              <1> 	; 28/02/2021
 10904 0000FE48 7321                <1> 	jnb	short sysvideo_27_0 ; nonsence !?
 10905                              <1> 
 10906 0000FE4A C1E010              <1> 	shl	eax, 16
 10907                              <1> 	;jz	short sysvideo_25 ; eax = 0 
 10908                              <1> 
 10909 0000FE4D 81FB00907E00        <1> 	cmp	ebx, 1920*1080*4 ; maximum value of possible
 10910                              <1> 				 ; buffer sizes
 10911 0000FE53 76CF                <1> 	jna	short sysvideo_26_3  ; buffer size is proper
 10912                              <1> 	; resize buffer to fit 4GB limit
 10913 0000FE55 BB00907E00          <1> 	mov	ebx, 1920*1080*4
 10914 0000FE5A EBC8                <1> 	jmp	short sysvideo_26_3
 10915                              <1> 
 10916                              <1> sysvideo_27:
 10917                              <1> 	; 23/07/2022
 10918                              <1> 	; 16/02/2021
 10919                              <1> 	; 18/01/2021
 10920 0000FE5C 80FF0C              <1> 	cmp	bh, 12
 10921                              <1> 	;ja	sysvideo_28 ; 19/01/2021
 10922                              <1> 	; 23/07/2022
 10923 0000FE5F 7605                <1> 	jna	short sysvideo_27_24
 10924 0000FE61 E970010000          <1> 	jmp	sysvideo_28
 10925                              <1> 
 10926                              <1> sysvideo_27_24:	; 23/07/2022
 10927                              <1> 	; BH = 12
 10928                              <1> 	; Font sub functions.
 10929                              <1> 	; 12/02/2021
 10930                              <1> 	; 11/01/2021
 10931                              <1> 	; 10/01/2021
 10932                              <1> 	;   BL = 0 : Disable system font overwrite
 10933                              <1> 	;   BL = 1 : Enable system font overwrite
 10934                              <1> 	;   BL = 2 : Read system font 8x8
 10935                              <1> 	;   BL = 3 : Read system font 8x14
 10936                              <1> 	;   BL = 4 : Read system font 8x16
 10937                              <1> 	;   BL = 5 : Read user defined font 8x8
 10938                              <1> 	;   BL = 6 : Read user defined font 8x16
 10939                              <1> 	;   BL = 7 : Write system font 8x8
 10940                              <1> 	;   BL = 8 : Write system font 8x14
 10941                              <1> 	;   BL = 9 : Write system font 8x16
 10942                              <1> 	;   BL = 10 : Write user defined font 8x8
 10943                              <1> 	;   BL = 11 : Write user defined font 8x16
 10944                              <1> 	;
 10945                              <1> 	;  BL > 11 : invalid (not implemented)
 10946                              <1> 	;
 10947                              <1> 	; For BL = 1 to 11
 10948                              <1> 	;   ECX = number of characters (<= 256)
 10949                              <1> 	;   EDX = first character (ascii code in DL)
 10950                              <1> 	;   ESI = user's buffer address
 10951                              <1> 	;
 10952                              <1> 	; Return: EAX = character count 
 10953                              <1> 
 10954 0000FE66 80FB0B              <1> 	cmp	bl, 11
 10955 0000FE69 7605                <1> 	jna	short sysvideo_27_1
 10956                              <1> sysvideo_27_0:
 10957 0000FE6B E9E4CFFFFF          <1> 	jmp	sysret ; not implemented yet !
 10958                              <1> sysvideo_27_1:
 10959 0000FE70 66B80001            <1> 	mov	ax, 256
 10960 0000FE74 08DB                <1> 	or	bl, bl
 10961 0000FE76 750E                <1>  	jnz	short sysvideo_27_3
 10962                              <1> 	
 10963                              <1> 	; bl = 0
 10964                              <1> 	; disable system font overwrite 
 10965                              <1> 
 10966 0000FE78 8025[8EA30100]7F    <1> 	and	byte [ufont], 7Fh ; clear bit 7
 10967                              <1> sysvideo_27_2:
 10968                              <1> 	;mov	word [u.r0], 256  ; > 0 -> successful
 10969 0000FE7F A3[74940100]        <1> 	mov	[u.r0], eax ; 256
 10970 0000FE84 EBE5                <1> 	jmp	short sysvideo_27_0
 10971                              <1> sysvideo_27_3:
 10972 0000FE86 80FB01              <1> 	cmp	bl, 1
 10973 0000FE89 7710                <1> 	ja	short sysvideo_27_4
 10974                              <1> 
 10975                              <1> 	; bl = 1
 10976                              <1> 	; enable system font overwrite 
 10977                              <1> 	;	if [multi_tasking]= 0 and [u.uid] = 0
 10978                              <1> 
 10979                              <1> 	;cmp	byte [multi_tasking], 0 
 10980                              <1> 	;			; multi tasking enabled ?
 10981                              <1> 	;ja	short sysvideo_27_0 ; yes
 10982                              <1> 	;; 19/01/2021 
 10983                              <1> 	;; system maintenance or single user mode
 10984                              <1> 	;cmp	byte [u.uid], 0  ; root ?
 10985                              <1> 	;ja	short sysvideo_27_0 ; no
 10986                              <1> 
 10987                              <1> 	; 19/01/2021
 10988                              <1> 	; multi tasking & root check
 10989 0000FE8B E8EBFEFFFF          <1> 	call	sysvideo_22_4
 10990 0000FE90 73D9                <1> 	jnc	short sysvideo_27_0 ; not permitted
 10991                              <1> 
 10992                              <1> 	; [multi_tasking]= 0 and [u.uid] = 0
 10993                              <1> 
 10994 0000FE92 800D[8EA30100]80    <1> 	or	byte [ufont], 80h ; set bit 7
 10995                              <1> 		
 10996 0000FE99 EBE4                <1>  	jmp	short sysvideo_27_2
 10997                              <1> 
 10998                              <1> sysvideo_27_4:
 10999 0000FE9B 09C9                <1> 	or	ecx, ecx
 11000 0000FE9D 74CC                <1> 	jz	short sysvideo_27_0
 11001 0000FE9F 21D2                <1> 	and	edx, edx
 11002 0000FEA1 7410                <1> 	jz	short sysvideo_27_4_0
 11003                              <1> 	;mov	ax, 256
 11004 0000FEA3 39C1                <1> 	cmp	ecx, eax ; 256
 11005 0000FEA5 77C4                <1> 	ja	short sysvideo_27_0
 11006 0000FEA7 48                  <1> 	dec	eax
 11007 0000FEA8 39C2                <1> 	cmp	edx, eax ; 255
 11008 0000FEAA 77BF                <1> 	ja	short sysvideo_27_0
 11009 0000FEAC 40                  <1> 	inc	eax
 11010 0000FEAD 29D0                <1> 	sub	eax, edx ; 256 - DX
 11011 0000FEAF 39C8                <1> 	cmp	eax, ecx
 11012 0000FEB1 72B8                <1> 	jb	short sysvideo_27_0
 11013                              <1> 
 11014                              <1> sysvideo_27_4_0:
 11015 0000FEB3 89F5                <1> 	mov	ebp, esi
 11016                              <1> 
 11017 0000FEB5 80FB06              <1> 	cmp	bl, 6
 11018 0000FEB8 7768                <1> 	ja	short sysvideo_27_13
 11019 0000FEBA 7210                <1> 	jb	short sysvideo_27_5
 11020                              <1> 	; bl = 6
 11021 0000FEBC F605[8EA30100]10    <1> 	test	byte [ufont], 16 ; 8x16 user font loaded ?
 11022 0000FEC3 74A6                <1> 	jz	short sysvideo_27_0
 11023                              <1> 	; read 8x16 user defined font
 11024 0000FEC5 BE00400900          <1> 	mov	esi, VGAFONT16USER
 11025 0000FECA EB0C                <1> 	jmp	short sysvideo_27_6
 11026                              <1> sysvideo_27_5:
 11027 0000FECC 80FB04              <1> 	cmp	bl, 4
 11028 0000FECF 7239                <1> 	jb	short sysvideo_27_11
 11029 0000FED1 7721                <1> 	ja	short sysvideo_27_9
 11030                              <1> 	; bl = 4
 11031                              <1> 	; read 8x16 system font
 11032 0000FED3 BE[54690100]        <1> 	mov	esi, vgafont16
 11033                              <1> sysvideo_27_6:
 11034                              <1> 	; read 8x16 font
 11035                              <1> 	;shl	dx, 4 ; * 16
 11036                              <1> 	;shl	cx, 4 ; * 16 ; 16 bytes per char
 11037                              <1> 	; 23/07/2022
 11038 0000FED8 C1E204              <1> 	shl	edx, 4 ; * 16
 11039 0000FEDB C1E104              <1> 	shl	ecx, 4 ; * 16
 11040                              <1> sysvideo_27_7:
 11041 0000FEDE 89EF                <1> 	mov	edi, ebp
 11042                              <1> 	;add	edi, edx ; 16/02/2021
 11043 0000FEE0 01D6                <1> 	add	esi, edx
 11044                              <1> 	; ecx = byte count
 11045                              <1> 	; esi = source (in system memory)
 11046                              <1> 	; edi = destination (in user memory)
 11047 0000FEE2 E8A9100000          <1> 	call	transfer_to_user_buffer
 11048 0000FEE7 7206                <1> 	jc	short sysvideo_27_8
 11049 0000FEE9 890D[74940100]      <1> 	mov	[u.r0], ecx
 11050                              <1> sysvideo_27_8:
 11051 0000FEEF E960CFFFFF          <1> 	jmp	sysret
 11052                              <1> sysvideo_27_9:
 11053                              <1> 	; bl = 5
 11054 0000FEF4 F605[8EA30100]08    <1> 	test	byte [ufont], 8 ; 8x8 user font loaded ?
 11055 0000FEFB 74F2                <1> 	jz	short sysvideo_27_8
 11056                              <1> 	; read 8x8 user defined font
 11057 0000FEFD BE00500900          <1> 	mov	esi, VGAFONT8USER
 11058                              <1> sysvideo_27_10:
 11059                              <1> 	; read 8x8 font
 11060                              <1> 	;shl	dx, 3 ; * 8
 11061                              <1> 	;shl	cx, 3 ; * 8 ; 8 bytes per char
 11062                              <1> 	; 23/07/2022
 11063 0000FF02 C1E203              <1> 	shl	edx, 3 ; * 8
 11064 0000FF05 C1E103              <1> 	shl	ecx, 3 ; * 8
 11065 0000FF08 EBD4                <1> 	jmp	short sysvideo_27_7
 11066                              <1> 
 11067                              <1> sysvideo_27_11:
 11068 0000FF0A 80FB03              <1> 	cmp	bl, 3  ; 8x14 system font
 11069 0000FF0D 720C                <1> 	jb	short sysvideo_27_12 ; 8x8 system font
 11070                              <1> 	; bl = 3
 11071                              <1> 	; read 8x14 system font
 11072                              <1> 	;mov	al, 14
 11073                              <1> 	;mul	dl
 11074                              <1> 	;mov	dx, ax
 11075                              <1> 	;push	edx
 11076                              <1> 	;mov	ax, 14
 11077                              <1> 	;mul	cx
 11078                              <1> 	;mov	cx, ax
 11079                              <1> 	;pop	edx
 11080 0000FF0F E8A5000000          <1> 	call	sysvideo_27_14
 11081 0000FF14 BE[545B0100]        <1> 	mov	esi, vgafont14
 11082 0000FF19 EBC3                <1> 	jmp	short sysvideo_27_7
 11083                              <1> 	
 11084                              <1> sysvideo_27_12:
 11085                              <1> 	; bl = 2
 11086                              <1> 	; read 8x8 system font
 11087 0000FF1B BE[54530100]        <1> 	mov	esi, vgafont8
 11088 0000FF20 EBE0                <1> 	jmp	short sysvideo_27_10
 11089                              <1> 
 11090                              <1> sysvideo_27_13:
 11091                              <1> 	; overwrite font
 11092 0000FF22 80FB0A              <1> 	cmp	bl, 10
 11093 0000FF25 776E                <1> 	ja	short sysvideo_27_22 ; 8x16 user font
 11094 0000FF27 7224                <1> 	jb	short sysvideo_27_15
 11095                              <1> 	; bl = 10
 11096 0000FF29 BF00500900          <1> 	mov	edi, VGAFONT8USER
 11097 0000FF2E F605[8EA30100]08    <1> 	test	byte [ufont], 8 ; 8x8 user font loaded ?
 11098 0000FF35 7556                <1> 	jnz	short sysvideo_27_21 ; yes
 11099 0000FF37 08ED                <1> 	or	ch, ch ; cx = 256
 11100                              <1> 	;jnz	short sysvideo_27_21 ; 256 chars
 11101 0000FF39 7406                <1> 	jz	short sysvideo_27_13_0
 11102 0000FF3B 66B90008            <1> 	mov	cx, 8*256
 11103 0000FF3F EB35                <1> 	jmp	short sysvideo_27_18_0
 11104                              <1> sysvideo_27_13_0:
 11105                              <1> 	; copy system font to user font before overwrite
 11106 0000FF41 BE[54530100]        <1> 	mov	esi, vgafont8
 11107                              <1> 	;push	edi
 11108                              <1> 	;push	ecx
 11109                              <1> 	;mov	cl, 64
 11110                              <1> 	;rep	movsd
 11111                              <1> 	;pop	ecx
 11112                              <1> 	;pop	edi
 11113                              <1> 	;mov	esi, ebp ; user's font buffer
 11114 0000FF46 E880000000          <1> 	call	sysvideo_27_23
 11115 0000FF4B EB40                <1> 	jmp	short sysvideo_27_21
 11116                              <1> 
 11117                              <1> sysvideo_27_15:
 11118                              <1> 	; check system font overwrite permission
 11119 0000FF4D F605[8EA30100]80    <1> 	test	byte [ufont], 80h
 11120 0000FF54 7499                <1> 	jz	short sysvideo_27_8
 11121                              <1> 
 11122 0000FF56 80FB08              <1> 	cmp	bl, 8
 11123 0000FF59 773A                <1> 	ja	short sysvideo_27_22 ; 8x16 system font
 11124 0000FF5B 722B                <1> 	jb	short sysvideo_27_20 ; 8x8 system font
 11125                              <1> 	; bl = 8
 11126                              <1> 	; overwrite 8x14 system font
 11127                              <1> 	;mov	al, 14
 11128                              <1> 	;mul	dl
 11129                              <1> 	;mov	dx, ax
 11130                              <1> 	;push	edx
 11131                              <1> 	;mov	ax, 14
 11132                              <1> 	;mul	cx
 11133                              <1> 	;mov	cx, ax
 11134                              <1> 	;pop	edx
 11135 0000FF5D E857000000          <1> 	call	sysvideo_27_14
 11136 0000FF62 BF[545B0100]        <1> 	mov	edi, vgafont14
 11137 0000FF67 EB0B                <1> 	jmp	short sysvideo_27_18
 11138                              <1> sysvideo_27_16:
 11139                              <1> 	; bl = 9
 11140                              <1> 	; overwrite 8x16 system font
 11141 0000FF69 BF[54690100]        <1> 	mov	edi, vgafont16
 11142                              <1> sysvideo_27_17:
 11143                              <1> 	; overwrite 8x16 font
 11144                              <1> 	;shl	dx, 4 ; * 16
 11145                              <1> 	;shl	cx, 4 ; * 16 ; 16 bytes per char
 11146                              <1> 	; 23/07/2022
 11147 0000FF6E C1E204              <1> 	shl	edx, 4 ; * 16
 11148 0000FF71 C1E104              <1> 	shl	ecx, 4 ; * 16
 11149                              <1> sysvideo_27_18:
 11150 0000FF74 01D7                <1> 	add	edi, edx
 11151                              <1> 	;add	esi, edx ; 16/02/2021
 11152                              <1> sysvideo_27_18_0:
 11153                              <1> 	; ecx = byte count
 11154                              <1> 	; esi = source (in user memory)
 11155                              <1> 	; edi = destination (in system memory)
 11156 0000FF76 E85F100000          <1> 	call	transfer_from_user_buffer
 11157 0000FF7B 7206                <1> 	jc	short sysvideo_27_19
 11158 0000FF7D 890D[74940100]      <1> 	mov	[u.r0], ecx
 11159                              <1> sysvideo_27_19:
 11160 0000FF83 E9CCCEFFFF          <1> 	jmp	sysret
 11161                              <1> sysvideo_27_20:
 11162                              <1> 	; bl = 7
 11163                              <1> 	; overwrite 8x8 system font
 11164 0000FF88 BF[54530100]        <1> 	mov	edi, vgafont8
 11165                              <1> sysvideo_27_21:
 11166                              <1> 	; overwrite 8x8 font
 11167                              <1> 	;shl	dx, 3 ; * 8
 11168                              <1> 	;shl	cx, 3 ; * 8 ; 8 bytes per char
 11169                              <1> 	; 23/07/2022
 11170 0000FF8D C1E203              <1> 	shl	edx, 3 ; * 8
 11171 0000FF90 C1E103              <1> 	shl	ecx, 3 ; * 8
 11172 0000FF93 EBDF                <1> 	jmp	short sysvideo_27_18
 11173                              <1> sysvideo_27_22:
 11174                              <1> 	; bl = 11
 11175                              <1> 	; overwrite 8x16 user defined font
 11176 0000FF95 BF00400900          <1> 	mov	edi, VGAFONT16USER
 11177 0000FF9A F605[8EA30100]10    <1> 	test	byte [ufont], 16 ; 8x16 user font loaded ?
 11178 0000FFA1 75CB                <1> 	jnz	short sysvideo_27_17 ; yes
 11179 0000FFA3 08ED                <1> 	or	ch, ch ; cx = 256
 11180                              <1> 	;jnz	short sysvideo_27_17 ; 256 chars
 11181 0000FFA5 7406                <1> 	jz	short sysvideo_27_22_0
 11182 0000FFA7 66B90010            <1> 	mov	cx, 16*256
 11183 0000FFAB EBC9                <1> 	jmp	short sysvideo_27_18_0
 11184                              <1> sysvideo_27_22_0:
 11185                              <1> 	; copy system font to user font before overwrite
 11186 0000FFAD BE[54690100]        <1> 	mov	esi, vgafont16
 11187                              <1> 	;push	edi
 11188                              <1> 	;push	ecx
 11189                              <1> 	;mov	cl, 64
 11190                              <1> 	;rep	movsd
 11191                              <1> 	;pop	ecx
 11192                              <1> 	;pop	edi
 11193                              <1> 	;mov	esi, ebp ; user's font buffer
 11194 0000FFB2 E814000000          <1> 	call	sysvideo_27_23
 11195 0000FFB7 EBB5                <1> 	jmp	short sysvideo_27_17
 11196                              <1> 
 11197                              <1> sysvideo_27_14:
 11198                              <1> 	; 16/02/2021
 11199 0000FFB9 52                  <1> 	push	edx
 11200 0000FFBA 66B80E00            <1> 	mov	ax, 14
 11201 0000FFBE 66F7E1              <1> 	mul	cx
 11202 0000FFC1 89C1                <1> 	mov	ecx, eax
 11203 0000FFC3 5A                  <1> 	pop	edx
 11204 0000FFC4 B00E                <1> 	mov	al, 14
 11205 0000FFC6 F6E2                <1> 	mul	dl
 11206 0000FFC8 89C2                <1> 	mov	edx, eax
 11207 0000FFCA C3                  <1> 	retn
 11208                              <1> 
 11209                              <1> 	;mov	al, 14
 11210                              <1> 	;mul	dl
 11211                              <1> 	;mov	dx, ax
 11212                              <1> 	;push	edx
 11213                              <1> 	;; 12/02/2021
 11214                              <1> 	;mov	ax, 14
 11215                              <1> 	;;mov	eax, 14
 11216                              <1> 	;;mul	cx
 11217                              <1> 	;mul	ecx
 11218                              <1> 	;;mov	cx, ax
 11219                              <1> 	;mov	ecx, eax
 11220                              <1> 	;pop	edx
 11221                              <1> 	;retn
 11222                              <1> 
 11223                              <1> sysvideo_27_23:
 11224 0000FFCB 57                  <1> 	push	edi
 11225 0000FFCC 51                  <1> 	push	ecx
 11226 0000FFCD B140                <1> 	mov	cl, 64
 11227 0000FFCF F3A5                <1> 	rep	movsd
 11228 0000FFD1 59                  <1> 	pop	ecx
 11229 0000FFD2 5F                  <1> 	pop	edi
 11230 0000FFD3 89EE                <1> 	mov	esi, ebp ; user's font buffer
 11231 0000FFD5 C3                  <1> 	retn
 11232                              <1> 
 11233                              <1> sysvideo_28:
 11234                              <1> 	; 23/07/2022
 11235                              <1> 	; 24/01/2021
 11236                              <1> 	; 23/01/2021
 11237                              <1> 	; 18/01/2021
 11238 0000FFD6 80FF0E              <1> 	cmp	bh, 14
 11239                              <1> 	;jb	sysvideo_29
 11240                              <1> 	; 23/07/2022
 11241 0000FFD9 7222                <1> 	jb	short sysvideo_28_29
 11242                              <1> 	;ja	sysvideo_30
 11243                              <1> 	; 23/07/2022
 11244 0000FFDB 7725                <1> 	ja	short sysvideo_28_30
 11245                              <1> 
 11246                              <1> 	; BH = 14
 11247                              <1> 	; Save/Restore Super VGA video state
 11248                              <1> 	
 11249                              <1> 	; BL = options
 11250                              <1> 	;	bit 0 - Save (0) or Restore (1)	
 11251                              <1> 	;	bit 1 - controller hardware state
 11252                              <1> 	;	bit 2 - BIOS data state
 11253                              <1> 	;	bit 3 - DAC state
 11254                              <1> 	;	bit 4 - (extended) Register state
 11255                              <1> 	;	bit 5 - system (0) or user (1) memory
 11256                              <1> 	;	bit 6 - verify without transfer
 11257                              <1> 	;	bit 7 - not used (must be 0)
 11258                              <1> 
 11259                              <1> 	; ECX = Buffer address or VideoStateID
 11260                              <1> 
 11261 0000FFDD 803D[86090000]02    <1> 	cmp	byte [vbe3], 2 ;  VESA VBE2 or VBE3 ?
 11262 0000FFE4 7721                <1> 	ja	short sysvideo_28_0 ; yes
 11263 0000FFE6 7210                <1> 	jb	short sysvideo_28_16 ; not a SVGA sys !
 11264                              <1> 
 11265                              <1> 	; == VBE2 ==
 11266                              <1> 	; Check Bochs/Qemu/VirtualBox PC emulator
 11267                              <1> 	; (vbe2 is usable only for emulator's vbios)
 11268 0000FFE8 8A25[87090000]      <1> 	mov	ah, [vbe2bios]
 11269 0000FFEE 80FCC0              <1> 	cmp	ah, 0C0h
 11270 0000FFF1 7205                <1> 	jb	short sysvideo_28_16 ; unknown vbios !
 11271 0000FFF3 80FCC5              <1> 	cmp	ah, 0C5h
 11272 0000FFF6 760F                <1> 	jna	short sysvideo_28_0
 11273                              <1> 		; Use kernel's vbios functions (video.s)
 11274                              <1> sysvideo_28_16:
 11275                              <1> 	; unknown vbios !
 11276 0000FFF8 E957CEFFFF          <1> 	jmp	sysret
 11277                              <1> 
 11278                              <1> sysvideo_28_29:
 11279                              <1> 	; 23/07/2022
 11280 0000FFFD E955010000          <1> 	jmp	sysvideo_29
 11281                              <1> sysvideo_28_30:
 11282                              <1> 	; 23/07/2022
 11283 00010002 E935020000          <1> 	jmp	sysvideo_30
 11284                              <1> 
 11285                              <1> sysvideo_28_0:
 11286 00010007 80FB7F              <1> 	cmp	bl, 7Fh
 11287 0001000A 77EC                <1> 	ja	short sysvideo_28_16 ; unknown options
 11288                              <1> 
 11289 0001000C 88DA                <1> 	mov	dl, bl
 11290 0001000E 80E21F              <1> 	and	dl, 1Fh 
 11291 00010011 D0EA                <1> 	shr	dl, 1
 11292 00010013 74E3                <1> 	jz	short sysvideo_28_16 ; invalid !
 11293                              <1> 	; DL = VBE Function 4F04h Save/Restore options
 11294                              <1> 	;  bit 0 : controller hardware state
 11295                              <1> 	;  bit 1 : BIOS data state
 11296                              <1> 	;  bit 2 : DAC state
 11297                              <1> 	;  bit 3 : (extended) Register state
 11298                              <1> 	
 11299 00010015 F6C320              <1> 	test	bl, 32 ; bit 5
 11300                              <1> 	;jnz	sysvideo_28_7 ; user buffer
 11301                              <1> 	; 23/07/2022
 11302 00010018 7405                <1> 	jz	short sysvideo_28_17
 11303 0001001A E9B1000000          <1> 	jmp	sysvideo_28_7
 11304                              <1> 
 11305                              <1> sysvideo_28_17:	 ; 23/07/2022
 11306                              <1> 	; source or destination is kernel/system buffer
 11307                              <1> 
 11308 0001001F 803D[90A30100]00    <1> 	cmp	byte [srvsf], 0 ; srs permission flag
 11309 00010026 76D0                <1> 	jna	short sysvideo_28_16 ; not permitted
 11310                              <1> 
 11311 00010028 F6C301              <1> 	test	bl, 1
 11312 0001002B 743A                <1> 	jz	short sysvideo_28_4 ; Save
 11313                              <1> 
 11314                              <1> 	; Restore
 11315 0001002D 3B0D[92A30100]      <1> 	cmp	ecx, [VideoStateID]
 11316 00010033 75C3                <1> 	jne	short sysvideo_28_16 ; not correct ID !
 11317                              <1> 
 11318 00010035 0FB6CA              <1> 	movzx	ecx, dl
 11319 00010038 80CA80              <1> 	or	dl, 80h
 11320 0001003B 3A15[91A30100]      <1> 	cmp	dl, [srvso]
 11321 00010041 75B5                <1> 	jne	short sysvideo_28_16 ; not correct !
 11322                              <1> 
 11323 00010043 88DA                <1> 	mov	dl, bl
 11324                              <1> 
 11325                              <1> 	; ecx = cl = options
 11326 00010045 E8E73AFFFF          <1> 	call	vbe_srs_gbs
 11327                              <1> 	; ebx = state buffer size (data size)
 11328                              <1> 
 11329 0001004A 891D[74940100]      <1> 	mov	[u.r0], ebx
 11330                              <1> 
 11331 00010050 F6C240              <1> 	test	dl, 64 ; verify without transfer
 11332 00010053 75A3                <1> 	jnz	short sysvideo_28_16 ; yes
 11333                              <1> 
 11334 00010055 BE00580900          <1> 	mov	esi, VBE3VIDEOSTATE
 11335 0001005A BF00760900          <1> 	mov	edi, VBE3SAVERESTOREBLOCK
 11336 0001005F 87D9                <1> 	xchg	ecx, ebx
 11337 00010061 F3A4                <1> 	rep	movsb
 11338                              <1> 
 11339 00010063 88D9                <1> 	mov	cl, bl
 11340                              <1> 
 11341                              <1> 	; 23/01/2021
 11342 00010065 EB44                <1> 	jmp	short sysvideo_28_10
 11343                              <1> 
 11344                              <1> sysvideo_28_4:
 11345 00010067 53                  <1> 	push	ebx
 11346                              <1> 	; 24/01/2021
 11347 00010068 31DB                <1> 	xor	ebx, ebx ; 0 ; use kernel's buffer
 11348 0001006A 881D[91A30100]      <1> 	mov	[srvso], bl ; 0 ; invalidate
 11349 00010070 891D[92A30100]      <1> 	mov	[VideoStateID], ebx ; 0 ; invalidate
 11350 00010076 0FB6CA              <1> 	movzx	ecx, dl ; options
 11351 00010079 B201                <1> 	mov	dl, 1 ; save state
 11352 0001007B E890000000          <1> 	call	sysvideo_28_11 ; 23/01/2021
 11353                              <1> 	; Note: VBE3 BIOS data save option will be
 11354                              <1> 	;	disabled.. ; 24/01/2021
 11355 00010080 89CA                <1> 	mov	edx, ecx ; state (save) options
 11356 00010082 5B                  <1> 	pop	ebx
 11357                              <1> 
 11358 00010083 6683F84F            <1> 	cmp	ax, 4Fh ; successful ?
 11359 00010087 7536                <1> 	jne	short sysvideo_28_3 ; no !
 11360                              <1> 
 11361 00010089 F6C340              <1> 	test	bl, 64 ; verify without transfer
 11362 0001008C 7536                <1> 	jnz	short sysvideo_28_6 ; yes
 11363                              <1> 
 11364                              <1> 	; ecx = cl = options
 11365 0001008E E89E3AFFFF          <1> 	call	vbe_srs_gbs
 11366                              <1> 	; ebx = state buffer size (data size)
 11367                              <1> 
 11368 00010093 BE00760900          <1> 	mov	esi, VBE3SAVERESTOREBLOCK
 11369 00010098 BF00580900          <1> 	mov	edi, VBE3VIDEOSTATE
 11370 0001009D 89D9                <1> 	mov	ecx, ebx
 11371 0001009F F3A4                <1> 	rep	movsb
 11372                              <1> 
 11373 000100A1 88D1                <1> 	mov	cl, dl
 11374 000100A3 80C980              <1> 	or	cl, 80h ; SVGA (VESA VBE) flag
 11375                              <1> 	;mov	[srvso], dl
 11376                              <1> 
 11377 000100A6 E908010000          <1> 	jmp	sysvideo_28_15
 11378                              <1> 
 11379                              <1> 	; 23/01/2021
 11380                              <1> sysvideo_28_10:
 11381                              <1> 	; CL = VESA VBE3 Save/Restore options
 11382                              <1> 
 11383 000100AB B202                <1> 	mov	dl, 2 ; restore state
 11384                              <1> 
 11385 000100AD E85C000000          <1> 	call	sysvideo_28_1
 11386                              <1> 
 11387 000100B2 6683F84F            <1> 	cmp	ax, 4Fh ; successful ?
 11388 000100B6 7407                <1> 	je	short sysvideo_28_3
 11389                              <1> 	;jmp	short sysvideo_28_9
 11390                              <1> 
 11391                              <1> sysvideo_28_9:
 11392                              <1> 	; return zero size (error) to user
 11393 000100B8 29C0                <1> 	sub	eax, eax
 11394                              <1> sysvideo_28_5:
 11395 000100BA A3[74940100]        <1> 	mov	[u.r0], eax
 11396                              <1> sysvideo_28_3:
 11397 000100BF E990CDFFFF          <1> 	jmp	sysret
 11398                              <1> 
 11399                              <1> sysvideo_28_6:
 11400                              <1> 	; use timer ticks as VideoStateID
 11401 000100C4 A1[407D0100]        <1> 	mov	eax, [TIMER_LH]
 11402 000100C9 09C0                <1> 	or 	eax, eax
 11403 000100CB 75ED                <1> 	jnz	short sysvideo_28_5
 11404 000100CD 40                  <1> 	inc	eax
 11405 000100CE EBEA                <1> 	jmp	short sysvideo_28_5
 11406                              <1> 
 11407                              <1> sysvideo_28_7:
 11408                              <1> 	; save/restore to/from user buffer
 11409                              <1> 
 11410                              <1> 	; 23/01/2021
 11411 000100D0 89CE                <1> 	mov	esi, ecx ; user's vstate buffer
 11412 000100D2 BF00760900          <1> 	mov	edi, VBE3SAVERESTOREBLOCK
 11413                              <1> 
 11414 000100D7 0FB6CA              <1> 	movzx	ecx, dl ; VESA VBE func 4F04h options
 11415                              <1> 
 11416                              <1> 	; source or destination is user buffer
 11417 000100DA F6C301              <1> 	test	bl, 1
 11418 000100DD 7444                <1> 	jz	short sysvideo_28_12  ; Save
 11419                              <1> 
 11420                              <1> 	; Restore
 11421 000100DF 803D[90A30100]00    <1> 	cmp	byte [srvsf], 0 ; srs permission flag
 11422 000100E6 766A                <1> 	jna	short sysvideo_28_14 ; not permitted
 11423                              <1> 
 11424 000100E8 88DA                <1> 	mov	dl, bl ; 'sysvideo' options
 11425                              <1> 
 11426                              <1> 	; ecx = cl = options
 11427 000100EA E8423AFFFF          <1> 	call	vbe_srs_gbs
 11428                              <1> 	; ebx = state buffer size (data size)
 11429                              <1> 
 11430 000100EF 891D[74940100]      <1> 	mov	[u.r0], ebx ; transfer count
 11431                              <1> 
 11432 000100F5 F6C240              <1> 	test	dl, 64 ; verify without transfer
 11433 000100F8 7558                <1> 	jnz	short sysvideo_28_14 ; yes
 11434                              <1> 
 11435 000100FA 6681FB0008          <1> 	cmp	bx, 2048
 11436 000100FF 73B7                <1> 	jnb	short sysvideo_28_9 ; invalid
 11437                              <1> 
 11438 00010101 87D9                <1> 	xchg	ecx, ebx
 11439                              <1> 	; esi = user buffer
 11440                              <1> 	; edi = VBE3SAVERESTOREBLOCK
 11441                              <1> 
 11442 00010103 E8D20E0000          <1> 	call	transfer_from_user_buffer
 11443 00010108 72AE                <1> 	jc	short sysvideo_28_9 ; error 
 11444                              <1> 
 11445 0001010A 89D9                <1> 	mov	ecx, ebx ; Function 4F04h options
 11446 0001010C EB9D                <1> 	jmp	short sysvideo_28_10 ; 23/01/2021
 11447                              <1> 
 11448                              <1> sysvideo_28_1:
 11449 0001010E 31DB                <1> 	xor	ebx, ebx ; 0 ; use kernel's buffer
 11450                              <1> sysvideo_28_11:
 11451                              <1> 	; 24/01/2021
 11452 00010110 803D[86090000]03    <1> 	cmp	byte [vbe3], 3
 11453 00010117 7405                <1> 	je	short sysvideo_28_2
 11454                              <1> 
 11455                              <1> 	; VESA VBE2 (BOCHS/QEMU/VBOX) video bios
 11456 00010119 E97C39FFFF          <1> 	jmp	_vbe_biosfn_save_restore_state
 11457                              <1> sysvideo_28_2:
 11458                              <1> 	;24/01/2021
 11459                              <1> 	;mov	eax, 4F04h  ; Save/Restore vstate
 11460                              <1> 	; VESA VBE3 video bios
 11461 0001011E E9F218FFFF          <1> 	jmp	_vbe3_pmfn_save_restore_state
 11462                              <1> 
 11463                              <1> sysvideo_28_12:
 11464                              <1> 	; Save
 11465                              <1> 	;mov	edi, VBE3SAVERESTOREBLOCK
 11466                              <1> 
 11467                              <1> 	;movzx	ecx, dl ; options
 11468 00010123 56                  <1> 	push	esi
 11469 00010124 53                  <1> 	push	ebx
 11470                              <1> 	; 23/01/2021
 11471 00010125 B201                <1> 	mov	dl, 1 ; save state
 11472 00010127 E8E2FFFFFF          <1> 	call	sysvideo_28_1
 11473 0001012C 5A                  <1> 	pop	edx ; 'sysvideo' options
 11474 0001012D 5F                  <1> 	pop	edi ; user's video state buffer
 11475                              <1> 
 11476 0001012E 6683F84F            <1> 	cmp	ax, 4Fh ; successful ?
 11477 00010132 751E                <1> 	jne	short sysvideo_28_14 ; no !
 11478                              <1> 
 11479                              <1> 	; ecx = cl = options
 11480 00010134 E8F839FFFF          <1> 	call	vbe_srs_gbs
 11481                              <1> 	; ebx = state buffer size (data size)
 11482                              <1> 
 11483 00010139 89D9                <1> 	mov	ecx, ebx ; transfer count
 11484                              <1> 
 11485 0001013B F6C240              <1> 	test	dl, 64 ; verify without transfer
 11486 0001013E 750C                <1> 	jnz	short sysvideo_28_13 ; yes
 11487                              <1> 		
 11488                              <1> 	;mov	edi, esi
 11489 00010140 BE00760900          <1> 	mov	esi, VBE3SAVERESTOREBLOCK
 11490 00010145 E8460E0000          <1> 	call	transfer_to_user_buffer
 11491 0001014A 7206                <1> 	jc	short sysvideo_28_14
 11492                              <1> sysvideo_28_13:
 11493 0001014C 890D[74940100]      <1> 	mov	[u.r0], ecx
 11494                              <1> sysvideo_28_14:
 11495 00010152 E9FDCCFFFF          <1> 	jmp	sysret
 11496                              <1> 
 11497                              <1> sysvideo_29:
 11498                              <1> 	; 18/01/2021
 11499                              <1> 	; BH = 13
 11500                              <1> 	; Save/Restore std VGA video state
 11501                              <1> 
 11502                              <1> 	; bl = 0..3
 11503                              <1> 	;	save to or restore from
 11504                              <1> 	;	system buffer, VBE3VIDEOSTATE
 11505                              <1> 	;	ECX = VideoStateID for restoring
 11506                              <1> 	; bl = 4..7
 11507                              <1> 	;	save to or restore from
 11508                              <1> 	;	user buffer pointed by ECX
 11509                              <1> 
 11510 00010157 80FB03              <1> 	cmp	bl, 3
 11511 0001015A 7776                <1> 	ja	short sysvideo_29_6
 11512                              <1> 
 11513                              <1> 	; source or destination is kernel/system buffer
 11514                              <1> 
 11515 0001015C 803D[90A30100]00    <1> 	cmp	byte [srvsf], 0 ; srs permission flag
 11516 00010163 7668                <1> 	jna	short sysvideo_29_5 ; not permitted
 11517                              <1> 
 11518 00010165 F6C301              <1> 	test	bl, 1
 11519 00010168 7437                <1> 	jz	short sysvideo_29_2  ; Save
 11520                              <1> 
 11521                              <1> 	; Restore
 11522 0001016A 3B0D[92A30100]      <1> 	cmp	ecx, [VideoStateID]
 11523 00010170 755B                <1> 	jne	short sysvideo_29_5 ; not correct ID !
 11524 00010172 80FB01              <1> 	cmp	bl, 1
 11525 00010175 7709                <1> 	ja	short sysvideo_29_0
 11526                              <1> 	; bl = 1
 11527 00010177 BB6E000000          <1> 	mov	ebx, 110 
 11528 0001017C B103                <1> 	mov	cl, 3 ; ctrl, vbios data
 11529 0001017E EB07                <1> 	jmp	short sysvideo_29_1
 11530                              <1> sysvideo_29_0:
 11531                              <1>  	; bl  = 3
 11532 00010180 BB72030000          <1> 	mov	ebx, 882 
 11533 00010185 B107                <1> 	mov	cl, 7 ; ctrl, vbios data, dac
 11534                              <1> sysvideo_29_1:
 11535 00010187 3A0D[91A30100]      <1> 	cmp	cl, [srvso]
 11536 0001018D 753E                <1> 	jne	short sysvideo_29_5 ; not correct !
 11537                              <1> 
 11538 0001018F BE00580900          <1> 	mov	esi, VBE3VIDEOSTATE ; 22/01/2021
 11539 00010194 E82C3BFFFF          <1> 	call	biosfn_restore_video_state
 11540 00010199 891D[74940100]      <1> 	mov	[u.r0], ebx ; video state size (bytes)
 11541                              <1> 	;jmp	sysret
 11542 0001019F EB2C                <1> 	jmp	short sysvideo_29_5
 11543                              <1> sysvideo_29_2:
 11544                              <1> 	;mov	esi, ecx
 11545 000101A1 BF00580900          <1> 	mov	edi, VBE3VIDEOSTATE
 11546                              <1> 
 11547 000101A6 B107                <1> 	mov	cl, 7 ; ctrl, vbios data, dac
 11548 000101A8 08DB                <1> 	or	bl, bl
 11549 000101AA 7502                <1> 	jnz	short sysvideo_29_3 ; bl = 2
 11550                              <1> 	; bl = 0
 11551 000101AC B103                <1> 	mov	cl, 3 ; ctrl, vbios data
 11552                              <1> sysvideo_29_3:
 11553 000101AE E8AA39FFFF          <1> 	call	biosfn_save_video_state
 11554                              <1> sysvideo_28_15:
 11555                              <1> 	; use timer ticks as VideoStateID
 11556 000101B3 A1[407D0100]        <1> 	mov	eax, [TIMER_LH]
 11557 000101B8 21C0                <1> 	and 	eax, eax
 11558 000101BA 7501                <1> 	jnz	short sysvideo_29_4
 11559 000101BC 40                  <1> 	inc	eax
 11560                              <1> sysvideo_29_4:
 11561 000101BD 880D[91A30100]      <1> 	mov	[srvso], cl
 11562 000101C3 A3[92A30100]        <1> 	mov	[VideoStateID], eax
 11563 000101C8 A3[74940100]        <1> 	mov	[u.r0], eax
 11564                              <1> sysvideo_29_5:
 11565 000101CD E982CCFFFF          <1> 	jmp	sysret
 11566                              <1> 
 11567                              <1> sysvideo_29_6:
 11568 000101D2 80FB07              <1> 	cmp	bl, 7
 11569 000101D5 77F6                <1> 	ja	short sysvideo_29_5 ; invalid sub function 
 11570                              <1> 
 11571 000101D7 89CE                <1> 	mov	esi, ecx
 11572 000101D9 BF00760900          <1> 	mov	edi, VBE3SAVERESTOREBLOCK
 11573                              <1> 
 11574                              <1> 	; source or destination is user buffer
 11575 000101DE F6C301              <1> 	test	bl, 1
 11576 000101E1 7434                <1> 	jz	short sysvideo_29_9  ; Save
 11577                              <1> 
 11578                              <1> 	; Restore
 11579 000101E3 803D[90A30100]00    <1> 	cmp	byte [srvsf], 0 ; srs permission flag
 11580 000101EA 76E1                <1> 	jna	short sysvideo_29_5 ; not permitted
 11581                              <1> 	
 11582                              <1> 	;mov	esi, ecx
 11583                              <1> 	;mov	edi, VBE3SAVERESTOREBLOCK
 11584                              <1> 	
 11585 000101EC 80FB07              <1> 	cmp	bl, 7
 11586 000101EF 7409                <1> 	je	short sysvideo_29_7
 11587                              <1> 	; bl = 5 
 11588 000101F1 B303                <1> 	mov	bl, 3
 11589 000101F3 B96E000000          <1> 	mov	ecx, 110
 11590 000101F8 EB05                <1> 	jmp	short sysvideo_29_8
 11591                              <1> sysvideo_29_7:
 11592                              <1> 	; bl = 7
 11593 000101FA B972030000          <1> 	mov	ecx, 882
 11594                              <1> sysvideo_29_8:
 11595 000101FF E8D60D0000          <1> 	call	transfer_from_user_buffer
 11596 00010204 72C7                <1> 	jc	short sysvideo_29_5
 11597 00010206 890D[74940100]      <1> 	mov	[u.r0], ecx
 11598 0001020C 88D9                <1> 	mov	cl, bl ; mov cl,7 (mov cl,3)
 11599 0001020E 89FE                <1> 	mov	esi, edi ; VBE3SAVERESTOREBLOCK
 11600                              <1> 	; cl = 3 or 7
 11601 00010210 E8B03AFFFF          <1> 	call	biosfn_restore_video_state
 11602 00010215 EBB6                <1> 	jmp	sysvideo_29_5
 11603                              <1> 	;jmp	sysret
 11604                              <1> sysvideo_29_9:
 11605                              <1> 	; Save
 11606                              <1> 	;mov	edi, VBE3SAVERESTOREBLOCK
 11607                              <1> 
 11608 00010217 80FB06              <1> 	cmp	bl, 6
 11609 0001021A 7409                <1> 	je	short sysvideo_29_10
 11610                              <1> 	; bl = 4
 11611 0001021C BB6E000000          <1> 	mov	ebx, 110
 11612 00010221 B103                <1> 	mov	cl, 3 ; ctrl, vbios data
 11613 00010223 EB07                <1> 	jmp	short sysvideo_29_11
 11614                              <1> sysvideo_29_10:
 11615                              <1> 	; bl = 6
 11616 00010225 BB72030000          <1> 	mov	ebx, 882
 11617 0001022A B107                <1> 	mov	cl, 7 ; ctrl, vbios data, dac
 11618                              <1> sysvideo_29_11:
 11619 0001022C E82C39FFFF          <1> 	call	biosfn_save_video_state
 11620                              <1> 
 11621 00010231 89D9                <1> 	mov	ecx, ebx ; transfer count
 11622 00010233 89F7                <1> 	mov	edi, esi
 11623 00010235 BE00760900          <1> 	mov	esi, VBE3SAVERESTOREBLOCK
 11624                              <1> 
 11625                              <1> 	;call	transfer_to_user_buffer
 11626                              <1> 	;jc	short sysvideo_29_5
 11627                              <1> 	;mov	[u.r0], ecx ; transfer count
 11628                              <1> 	;;jmp	sysret
 11629                              <1> 	;jmp	short sysvideo_29_5
 11630                              <1>  
 11631 0001023A EB1A                <1> 	jmp	short sysvideo_29_12
 11632                              <1> 
 11633                              <1> sysvideo_30:
 11634 0001023C 80FF0F              <1> 	cmp	bh, 15
 11635 0001023F 7722                <1> 	ja	short sysvideo_31 ; invalid function
 11636                              <1> 
 11637                              <1> 	; BH = 15
 11638                              <1> 	; Copy VESA EDID to user's buffer
 11639                              <1> 
 11640 00010241 803D[D3410000]4F    <1> 	cmp	byte [edid], 4Fh
 11641 00010248 7519                <1> 	jne	short sysvideo_31 ; not ready !
 11642                              <1> 
 11643                              <1> 	;and	ecx, ecx
 11644                              <1> 	;jz	short sysvideo_31
 11645                              <1> 
 11646                              <1> 	; ecx = user's buffer address
 11647 0001024A 89CF                <1> 	mov	edi, ecx
 11648 0001024C BE[ACA20100]        <1> 	mov	esi, edid_info
 11649 00010251 B980000000          <1> 	mov	ecx, 128 ; 128 bytes
 11650                              <1> sysvideo_29_12:
 11651 00010256 E8350D0000          <1> 	call	transfer_to_user_buffer
 11652 0001025B 7206                <1> 	jc	short sysvideo_31
 11653                              <1> 
 11654 0001025D 890D[74940100]      <1> 	mov	[u.r0], ecx ; EDID size, 128 bytes
 11655                              <1> sysvideo_31:
 11656 00010263 E9ECCBFFFF          <1> 	jmp	sysret
 11657                              <1> 
 11658                              <1> mkdir:
 11659                              <1> 	; 04/12/2015 (14 byte directory names)
 11660                              <1> 	; 12/10/2015
 11661                              <1> 	; 17/06/2015 (Retro UNIX 386 v1 - Beginning)
 11662                              <1> 	; 29/04/2013 - 01/08/2013 (Retro UNIX 8086 v1)
 11663                              <1> 	;
 11664                              <1> 	; 'mkdir' makes a directory entry from the name pointed to
 11665                              <1> 	; by u.namep into the current directory.
 11666                              <1> 	;
 11667                              <1> 	; INPUTS ->
 11668                              <1> 	;    u.namep - points to a file name 
 11669                              <1> 	;	           that is about to be a directory entry.
 11670                              <1> 	;    ii - current directory's i-number.	
 11671                              <1> 	; OUTPUTS ->
 11672                              <1> 	;    u.dirbuf+2 - u.dirbuf+10 - contains file name.
 11673                              <1> 	;    u.off - points to entry to be filled
 11674                              <1> 	;	     in the current directory
 11675                              <1> 	;    u.base - points to start of u.dirbuf.
 11676                              <1> 	;    r1 - contains i-number of current directory
 11677                              <1> 	;
 11678                              <1> 	; ((AX = R1)) output
 11679                              <1> 	;
 11680                              <1> 	;    (Retro UNIX Prototype : 11/11/2012, UNIXCOPY.ASM)
 11681                              <1>         ;    ((Modified registers: EAX, EDX, EBX, ECX, ESI, EDI, EBP))
 11682                              <1> 	;
 11683                              <1> 
 11684                              <1> 	; 17/06/2015 - 32 bit modifications (Retro UNIX 386 v1)
 11685 00010268 31C0                <1> 	xor 	eax, eax
 11686 0001026A BF[AE940100]        <1> 	mov     edi, u.dirbuf+2
 11687 0001026F 89FE                <1> 	mov	esi, edi
 11688 00010271 AB                  <1> 	stosd
 11689 00010272 AB                  <1> 	stosd
 11690                              <1> 	; 04/12/2015 (14 byte directory names)
 11691 00010273 AB                  <1> 	stosd
 11692 00010274 66AB                <1> 	stosw
 11693                              <1> 		; jsr r0,copyz; u.dirbuf+2; u.dirbuf+10. / clear this
 11694 00010276 89F7                <1> 	mov	edi, esi ; offset to u.dirbuf
 11695                              <1> 	; 12/10/2015 ([u.namep] -> ebp)
 11696                              <1> 	;mov 	ebp, [u.namep]
 11697 00010278 E8C8040000          <1> 	call	trans_addr_nmbp ; convert virtual address to physical
 11698                              <1> 		; esi = physical address (page start + offset)
 11699                              <1> 		; ecx = byte count in the page (1 - 4096)
 11700                              <1> 	; edi = offset to u.dirbuf (edi is not modified in trans_addr_nm)
 11701                              <1> 		; mov u.namep,r2 / r2 points to name of directory entry
 11702                              <1> 		; mov $u.dirbuf+2,r3 / r3 points to u.dirbuf+2
 11703                              <1> mkdir_1: ; 1:
 11704 0001027D 45                  <1> 	inc	ebp ; 12/10/2015
 11705                              <1> 	;
 11706                              <1> 	; / put characters in the directory name in u.dirbuf+2 - u.dirbuf+10
 11707                              <1> 	 ; 01/08/2013
 11708 0001027E AC                  <1> 	lodsb
 11709                              <1> 		; movb (r2)+,r1 / move character in name to r1
 11710 0001027F 20C0                <1> 	and 	al, al
 11711 00010281 7427                <1> 	jz 	short mkdir_3
 11712                              <1> 		; beq 1f / if null, done
 11713 00010283 3C2F                <1> 	cmp	al, '/'
 11714                              <1> 		; cmp r1,$'/ / is it a "/"?
 11715 00010285 7414                <1> 	je	short mkdir_err
 11716                              <1> 	;je	error
 11717                              <1> 		; beq error9 / yes, error
 11718                              <1> 	; 12/10/2015
 11719 00010287 6649                <1> 	dec	cx
 11720 00010289 7505                <1> 	jnz	short mkdir_2
 11721                              <1> 	; 12/10/2015 ([u.namep] -> ebp)
 11722 0001028B E8BB040000          <1> 	call	trans_addr_nm ; convert virtual address to physical
 11723                              <1> 		; esi = physical address (page start + offset)
 11724                              <1> 		; ecx = byte count in the page
 11725                              <1> 	; edi = offset to u.dirbuf (edi is not modified in trans_addr_nm)
 11726                              <1> mkdir_2:
 11727 00010290 81FF[BC940100]      <1> 	cmp     edi, u.dirbuf+16 ; ; 04/12/2015 (10 -> 16)
 11728                              <1> 		; cmp r3,$u.dirbuf+10. / have we reached the last slot for
 11729                              <1> 				     ; / a char?
 11730 00010296 74E5                <1> 	je	short mkdir_1
 11731                              <1> 		; beq 1b / yes, go back
 11732 00010298 AA                  <1> 	stosb
 11733                              <1> 		; movb r1,(r3)+ / no, put the char in the u.dirbuf
 11734 00010299 EBE2                <1> 	jmp 	short mkdir_1
 11735                              <1> 		; br 1b / get next char
 11736                              <1> mkdir_err:
 11737                              <1> 	; 17/06/2015
 11738 0001029B C705[E0940100]1300- <1> 	mov	dword [u.error], ERR_NOT_DIR ; 'not a valid directory !'
 11738 000102A3 0000                <1>
 11739 000102A5 E98ACBFFFF          <1> 	jmp	error
 11740                              <1> 
 11741                              <1> mkdir_3: ; 1:
 11742 000102AA A1[8C940100]        <1> 	mov	eax, [u.dirp]
 11743 000102AF A3[94940100]        <1> 	mov	[u.off], eax
 11744                              <1> 		; mov u.dirp,u.off / pointer to empty current directory
 11745                              <1> 				 ; / slot to u.off
 11746                              <1> wdir: ; 29/04/2013
 11747 000102B4 C705[98940100]-     <1>         mov     dword [u.base], u.dirbuf
 11747 000102BA [AC940100]          <1>
 11748                              <1> 		; mov $u.dirbuf,u.base / u.base points to created file name
 11749 000102BE C705[9C940100]1000- <1>         mov     dword [u.count], 16 ; 04/12/2015 (10 -> 16) 
 11749 000102C6 0000                <1>
 11750                              <1> 		; mov $10.,u.count / u.count = 10
 11751 000102C8 66A1[7C950100]      <1> 	mov	ax, [ii] 
 11752                              <1> 		; mov ii,r1 / r1 has i-number of current directory
 11753 000102CE B201                <1> 	mov	dl, 1 ; owner flag mask ; RETRO UNIX 8086 v1 modification !
 11754 000102D0 E81B1D0000          <1> 	call 	access
 11755                              <1> 		; jsr r0,access; 1 / get i-node and set its file up
 11756                              <1> 				 ; / for writing
 11757                              <1> 	; AX = i-number of current directory
 11758                              <1> 	; 01/08/2013
 11759 000102D5 FE05[DA940100]      <1> 	inc     byte [u.kcall] ; the caller is 'mkdir' sign
 11760 000102DB E8120F0000          <1> 	call	writei
 11761                              <1> 		; jsr r0,writei / write into directory
 11762 000102E0 C3                  <1> 	retn
 11763                              <1> 		; rts r0
 11764                              <1> 
 11765                              <1> sysexec:
 11766                              <1> 	; 21/08/2024 - TRDOS 386 v2.0.9
 11767                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
 11768                              <1> 	; 06/02/2022 - Retro UNIX 386 v1.2
 11769                              <1> 	; 18/11/2017
 11770                              <1> 	; 14/11/2017
 11771                              <1> 	; 13/11/2017
 11772                              <1> 	; 24/10/2016 - 04/01/2017
 11773                              <1> 	; 24/04/2016 - TRDOS 386 (TRDOS v2.0)
 11774                              <1> 	; 23/06/2015 - 23/10/2015 (Retro UNIX 386 v1)
 11775                              <1> 	; 03/06/2013 - 06/12/2013 (Retro UNIX 8086 v1)
 11776                              <1> 	;
 11777                              <1> 	; 'sysexec' initiates execution of a file whose path name if
 11778                              <1> 	; pointed to by 'name' in the sysexec call. 
 11779                              <1> 	; 'sysexec' performs the following operations:
 11780                              <1> 	;    1. obtains i-number of file to be executed via 'namei'.
 11781                              <1> 	;    2. obtains i-node of file to be exceuted via 'iget'.
 11782                              <1> 	;    3. sets trap vectors to system routines.
 11783                              <1> 	;    4. loads arguments to be passed to executing file into
 11784                              <1> 	;	highest locations of user's core
 11785                              <1> 	;    5. puts pointers to arguments in locations immediately
 11786                              <1> 	;	following arguments.
 11787                              <1> 	;    6.	saves number of arguments in next location.
 11788                              <1> 	;    7. initializes user's stack area so that all registers
 11789                              <1> 	;	will be zeroed and the PS is cleared and the PC set
 11790                              <1> 	;	to core when 'sysret' restores registers
 11791                              <1> 	;	and does an rti.
 11792                              <1> 	;    8. initializes u.r0 and u.sp
 11793                              <1> 	;    9. zeros user's core down to u.r0
 11794                              <1> 	;   10.	reads executable file from storage device into core
 11795                              <1> 	;	starting at location 'core'.
 11796                              <1> 	;   11.	sets u.break to point to end of user's code with
 11797                              <1> 	;	data area appended.
 11798                              <1> 	;   12.	calls 'sysret' which returns control at location
 11799                              <1> 	;	'core' via 'rti' instruction.
 11800                              <1> 	;
 11801                              <1> 	; Calling sequence:
 11802                              <1> 	;	sysexec; namep; argp
 11803                              <1> 	; Arguments:
 11804                              <1> 	;	namep - points to pathname of file to be executed
 11805                              <1> 	;	argp  - address of table of argument pointers
 11806                              <1> 	;	argp1... argpn - table of argument pointers
 11807                              <1> 	;	argp1:<...0> ... argpn:<...0> - argument strings
 11808                              <1> 	; Inputs: (arguments)
 11809                              <1> 	; Outputs: -	
 11810                              <1> 	; ...............................................................
 11811                              <1> 	;
 11812                              <1> 	; Retro UNIX 386 v1 modification:
 11813                              <1> 	;	User application runs in it's own virtual space 
 11814                              <1> 	;	which is izolated from kernel memory (and other
 11815                              <1> 	;	memory pages) via 80386	paging in ring 3 
 11816                              <1> 	;	privilige mode. Virtual start address is always 0.
 11817                              <1> 	;	User's core memory starts at linear address 400000h
 11818                              <1> 	;	(the end of the 1st 4MB).
 11819                              <1> 	;
 11820                              <1> 	; Retro UNIX 8086 v1 modification:
 11821                              <1> 	;	user/application segment and system/kernel segment
 11822                              <1> 	;	are different and sysenter/sysret/sysrele routines
 11823                              <1> 	;	are different (user's registers are saved to 
 11824                              <1> 	;	and then restored from system's stack.)
 11825                              <1> 	;
 11826                              <1> 	;	NOTE: Retro UNIX 8086 v1 'arg2' routine gets these
 11827                              <1> 	;	      arguments which were in these registers;
 11828                              <1> 	;	      but, it returns by putting the 1st argument
 11829                              <1> 	;	      in 'u.namep' and the 2nd argument
 11830                              <1> 	;	      on top of stack. (1st argument is offset of the
 11831                              <1> 	;	      file/path name in the user's program segment.)
 11832                              <1> 	
 11833                              <1> 	;call	arg2
 11834                              <1> 	; * name - 'u.namep' points to address of file/path name
 11835                              <1> 	;          in the user's program segment ('u.segmnt')
 11836                              <1> 	;          with offset in BX register (as sysopen argument 1).
 11837                              <1> 	; * argp - sysexec argument 2 is in CX register 
 11838                              <1> 	;          which is on top of stack.
 11839                              <1> 	;
 11840                              <1> 		; jsr r0,arg2 / arg0 in u.namep,arg1 on top of stack
 11841                              <1> 
 11842                              <1> 	; 23/06/2015 (32 bit modifications)
 11843                              <1> 
 11844                              <1> 	;; 13/11/2017
 11845                              <1> 	;;mov	[u.namep], ebx ; argument 1
 11846                              <1>         ; 18/10/2015
 11847 000102E1 890D[74950100]      <1> 	mov     [argv], ecx  ; * ; argument 2
 11848                              <1> 
 11849                              <1> 	; 13/11/2017
 11850 000102E7 89DE                <1> 	mov	esi, ebx
 11851 000102E9 E8F41F0000          <1> 	call	set_working_path_x
 11852 000102EE 7319                <1> 	jnc	short sysexec_0
 11853                              <1> 
 11854                              <1> 	;; 'bad command or file name'
 11855                              <1> 	;mov	eax, ERR_BAD_CMD_ARG ; 01h ; TRDOS 8086
 11856                              <1> 	
 11857                              <1> 	; 'file not found !' error
 11858 000102F0 B802000000          <1> 	mov	eax, ERR_NOT_FOUND ; 02h ; TRDOS 8086
 11859                              <1> sysexec_not_found_err:
 11860                              <1> sysexec_access_error:
 11861                              <1> sysexec_ext_error:
 11862 000102F5 A3[74940100]        <1> 	mov	[u.r0], eax
 11863 000102FA A3[E0940100]        <1> 	mov	[u.error], eax
 11864 000102FF E8B3200000          <1> 	call 	reset_working_path
 11865 00010304 E92BCBFFFF          <1> 	jmp	error
 11866                              <1> 
 11867                              <1> sysexec_0:
 11868                              <1> 	; 13/11/2017
 11869                              <1> 	;mov	esi, FindFile_Name
 11870 00010309 66B80018            <1>         mov	ax, 1800h ; Only files
 11871 0001030D E85888FFFF          <1> 	call	find_first_file
 11872 00010312 72E1                <1> 	jc	short sysexec_not_found_err ; eax = 2
 11873                              <1> 
 11874                              <1> 	; check_ file attributes
 11875                              <1> 	; (attribute bits = 00ADVSHR) ; 18h = Directory+Volume
 11876                              <1> 	; BL = Attributes byte
 11877                              <1> 	
 11878 00010314 F6C306              <1>         test	bl, 6  ; system file or hidden file (S+H) 
 11879                              <1> 	;jz	short sysexec_0ext
 11880 00010317 7417                <1> 	jz	short sysexec_1 ; yes
 11881                              <1> 
 11882                              <1> 	; 13/11/2017 
 11883                              <1> 	; /// TRDOS386 permission check for multiuser mode ///
 11884                              <1> 	; SYSTEM file or HIDDEN file !!
 11885                              <1> 	; (Only super user has permission to run this file.)
 11886                              <1> 	
 11887                              <1> 	; ([u.uid]=0 for super user or root in multiuser mode)
 11888                              <1> 	; ([u.uid]=0 for any users in singleuser mode)
 11889 00010319 803D[C6940100]00    <1> 	cmp 	byte [u.uid], 0 ; Super User ([u.uid]=0) ?
 11890                              <1> 	;jna	short sysexec_0ext
 11891 00010320 760E                <1> 	jna	short sysexec_1 ; yes
 11892                              <1> 
 11893                              <1> 	; 'permission denied !' error
 11894 00010322 B80B000000          <1>         mov	eax, ERR_FILE_ACCESS  ; 11 = ERR_PERM_DENIED
 11895 00010327 EBCC                <1>         jmp	short sysexec_access_error
 11896                              <1> 
 11897                              <1> sysexec_not_exf:
 11898                              <1> 	; 'not executable file !' error
 11899 00010329 B816000000          <1> 	mov	eax, ERR_NOT_EXECUTABLE
 11900 0001032E EBC5                <1> 	jmp	sysexec_ext_error
 11901                              <1> 
 11902                              <1> ;sysexec_0ext:
 11903                              <1> sysexec_1:
 11904                              <1> 	; 18/11/2017
 11905 00010330 BE[64860100]        <1> 	mov	esi, FindFile_Name
 11906                              <1> 	; 13/11/2017
 11907                              <1> 	; check program file name extension
 11908                              <1> 	; ('.PRG' for current TRDOS version)
 11909 00010335 E8E9A1FFFF          <1> 	call	check_prg_filename_ext
 11910 0001033A 72ED                <1> 	jc	short sysexec_not_exf
 11911                              <1> 	
 11912                              <1> 	; 18/11/2017
 11913 0001033C 3C50                <1> 	cmp	al, 'P'
 11914 0001033E 75E9                <1> 	jne	short sysexec_not_exf
 11915                              <1> 
 11916                              <1> 	; '.PRG' extension is OK.
 11917                              <1> 	; Only '.PRG' files are valid program files
 11918                              <1> 	; for current TRDOS 386 version.
 11919                              <1> 
 11920 00010340 8B15[90860100]      <1> 	mov	edx, [FindFile_DirEntry+DirEntry_FileSize]
 11921 00010346 66A1[88860100]      <1> 	mov	ax, [FindFile_DirEntry+DirEntry_FstClusHI]
 11922 0001034C C1E010              <1> 	shl	eax, 16
 11923 0001034F 66A1[8E860100]      <1> 	mov	ax, [FindFile_DirEntry+DirEntry_FstClusLO]
 11924                              <1> 	; EAX = First Cluster number
 11925                              <1> 	; EDX = File Size
 11926                              <1> 
 11927 00010355 A3[7C950100]        <1> 	mov	[ii], eax
 11928 0001035A 8915[80950100]      <1> 	mov	[i.size], edx
 11929                              <1> 
 11930                              <1> ;sysexec_1:
 11931                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
 11932                              <1> 	; 06/02/2022 - Retro UNIX 386 v1.2
 11933                              <1> 	; 13/11/2017 - TRDOS 386 (TRDOS v2.0)
 11934                              <1> 	; 24/06/2015 - 23/10/2015 (Retro UNIX 386 v1)
 11935                              <1>         ; Moving arguments to the end of [u.upage]
 11936                              <1> 	; (by regarding page borders in user's memory space)
 11937                              <1> 	;
 11938                              <1> 	; 10/10/2015
 11939                              <1> 	; 21/07/2015
 11940                              <1> 	;mov	ebp, esp ; (**)
 11941                              <1> 	; 18/10/2015
 11942                              <1> 	;mov 	edi, ebp
 11943                              <1> 	; 23/07/2022
 11944 00010360 89E7                <1> 	mov	edi, esp ; (**)
 11945 00010362 B900010000          <1> 	mov 	ecx, MAX_ARG_LEN ; 256
 11946                              <1> 	;sub	edi, MAX_ARG_LEN ; 256
 11947 00010367 29CF                <1> 	sub	edi, ecx
 11948 00010369 89FC                <1> 	mov	esp, edi ; *!*
 11949 0001036B 31C0                <1> 	xor	eax, eax
 11950 0001036D A3[A0940100]        <1> 	mov 	[u.nread], eax ; 0
 11951                              <1> 	; ([argc] must be cleared because previous 'sysexec'
 11952                              <1> 	; may leave it with any value after an error))
 11953                              <1> 	;mov	[argc], ax ; 0 ; 13/11/2017
 11954                              <1> 	; 23/07/2022
 11955 00010372 A3[70950100]        <1> 	mov	[argc], eax ; 0
 11956 00010377 49                  <1> 	dec	ecx ; 256 - 1
 11957 00010378 890D[9C940100]      <1> 	mov 	[u.count], ecx ; MAX_ARG_LEN - 1 ; 255
 11958                              <1> 	;mov 	dword [u.count], MAX_ARG_LEN - 1 ; 255
 11959                              <1> sysexec_2:
 11960 0001037E 8B35[74950100]      <1> 	mov	esi, [argv] ; 18/10/2015 
 11961 00010384 E878020000          <1> 	call	get_argp
 11962                              <1> 	;mov	ecx, 4
 11963                              <1> 	; 23/07/2022
 11964 00010389 31C9                <1> 	xor	ecx, ecx
 11965 0001038B B104                <1> 	mov	cl, 4
 11966                              <1> sysexec_3:
 11967 0001038D 21C0                <1> 	and	eax, eax
 11968 0001038F 7453                <1>         jz	short sysexec_6 ; 23/07/2022
 11969                              <1> 	; 18/10/2015
 11970 00010391 010D[74950100]      <1> 	add	[argv], ecx ; 4
 11971                              <1> 	;;inc	word [argc]
 11972                              <1> 	; 23/07/2022
 11973                              <1> 	;inc	dword [argc]
 11974 00010397 FE05[70950100]      <1> 	inc	byte [argc]
 11975                              <1> 	;
 11976 0001039D A3[98940100]        <1> 	mov	[u.base], eax
 11977                              <1>  	; 23/10/2015
 11978 000103A2 66C705[D8940100]00- <1> 	mov	word [u.pcount], 0
 11978 000103AA 00                  <1>
 11979                              <1> sysexec_4:
 11980 000103AB E8810B0000          <1> 	call	cpass ; get a character from user's core memory
 11981 000103B0 750B                <1>         jnz	short sysexec_5
 11982                              <1> 		; (max. 255 chars + null)
 11983                              <1> 	; 18/10/2015
 11984 000103B2 28C0                <1> 	sub 	al, al
 11985 000103B4 AA                  <1> 	stosb
 11986 000103B5 FF05[A0940100]      <1> 	inc	dword [u.nread]
 11987                              <1> 	; 23/07/2022
 11988 000103BB EB27                <1> 	jmp	short sysexec_6 ; 24/04/2016
 11989                              <1> sysexec_5:
 11990 000103BD AA                  <1> 	stosb
 11991 000103BE 20C0                <1> 	and 	al, al
 11992 000103C0 75E9                <1> 	jnz	short sysexec_4
 11993                              <1> 	;mov	ecx, 4
 11994                              <1> 	; 23/07/2022
 11995 000103C2 31C9                <1> 	xor	ecx, ecx
 11996 000103C4 B104                <1> 	mov	cl, 4
 11997 000103C6 390D[6C950100]      <1> 	cmp	[ncount], ecx ; 4
 11998 000103CC 72B0                <1> 	jb	short sysexec_2
 11999 000103CE 8B35[68950100]      <1> 	mov	esi, [nbase]
 12000 000103D4 010D[68950100]      <1> 	add	[nbase], ecx ; 4
 12001                              <1> 	;sub	[ncount], cx 
 12002                              <1> 	; 23/07/2022
 12003 000103DA 290D[6C950100]      <1> 	sub	[ncount], ecx
 12004 000103E0 8B06                <1> 	mov	eax, [esi]
 12005 000103E2 EBA9                <1> 	jmp	short sysexec_3
 12006                              <1> 
 12007                              <1> sysexec_6:
 12008                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
 12009                              <1> 	; 19/11/2017
 12010                              <1> 	; 18/11/2017
 12011                              <1> 	; 14/11/2017
 12012                              <1> 	; 13/11/2017
 12013 000103E4 8925[74950100]      <1> 	mov	[argv], esp ; *!* ; start address of argument list
 12014                              <1> 
 12015                              <1> 	; 04/01/2017
 12016                              <1> 	; 24/10/2016
 12017                              <1> 	;;02/05/2016
 12018                              <1> 	; 23/04/2016 (TRDOS 386)
 12019                              <1> 	; 18/10/2015 ('sysexec_6')
 12020                              <1> 	; 23/06/2015
 12021 000103EA A1[CC940100]        <1> 	mov	eax, [u.pgdir] ; physical address of page directory
 12022                              <1> 	;cmp 	eax, [k_page_dir] ; TRDOS MainProg ?
 12023                              <1> 	;je	short sysexec_7
 12024                              <1> 	; 19/11/2017
 12025 000103EF 8B1D[D0940100]      <1> 	mov	ebx, [u.ppgdir] ; phy addr of the parent's page dir
 12026 000103F5 E81655FFFF          <1> 	call	deallocate_page_dir
 12027                              <1> sysexec_7:
 12028 000103FA E84654FFFF          <1> 	call	make_page_dir
 12029                              <1> 	;jc	panic  ; allocation error 
 12030                              <1> 	;	       ; after a deallocation would be nonsence !?
 12031                              <1> 	; 23/07/2022
 12032 000103FF 7243                <1> 	jc	short sysexec_panic
 12033                              <1> 
 12034                              <1> 	; 24/07/2015
 12035                              <1> 	; map kernel pages (1st 4MB) to PDE 0
 12036                              <1> 	;     of the user's page directory
 12037                              <1> 	;     (It is needed for interrupts!)
 12038                              <1> 	; 18/10/2015
 12039 00010401 8B15[C07C0100]      <1> 	mov	edx, [k_page_dir] ; Kernel's page directory
 12040 00010407 8B02                <1> 	mov	eax, [edx] ; physical address of
 12041                              <1> 			   ; kernel's first page table (1st 4 MB)
 12042                              <1> 			   ; (PDE 0 of kernel's page directory)
 12043 00010409 8B15[CC940100]      <1> 	mov 	edx, [u.pgdir]
 12044 0001040F 8902                <1> 	mov	[edx], eax ; PDE 0 (1st 4MB)
 12045                              <1> 	;
 12046                              <1> 	; 20/07/2015
 12047 00010411 BB00004000          <1> 	mov	ebx, CORE ; start address = 0 (virtual) + CORE
 12048                              <1> 	; 18/10/2015
 12049 00010416 BE[60950100]        <1> 	mov	esi, pcore ; physical start address
 12050                              <1> sysexec_8:	
 12051 0001041B B907000000          <1> 	mov	ecx, PDE_A_USER + PDE_A_WRITE + PDE_A_PRESENT
 12052 00010420 E83E54FFFF          <1> 	call	make_page_table
 12053                              <1> 	;jc	panic
 12054                              <1> 	; 23/07/2022
 12055 00010425 721D                <1> 	jc	short sysexec_panic
 12056                              <1> 	;
 12057                              <1> 	;mov	ecx, PTE_A_USER + PTE_A_WRITE + PTE_A_PRESENT
 12058 00010427 E84554FFFF          <1> 	call	make_page ; make new page, clear and set the pte
 12059                              <1> 	;jc	panic
 12060                              <1> 	; 23/07/2022
 12061 0001042C 7216                <1> 	jc	short sysexec_panic
 12062                              <1> 	;
 12063 0001042E 8906                <1> 	mov	[esi], eax ; 24/06/2015
 12064                              <1> 	; ebx = virtual address (24/07/2015)
 12065                              <1> 	; 23/07/2022
 12066                              <1> 	;call 	add_to_swap_queue
 12067                              <1> 	; 18/10/2015
 12068 00010430 81FE[64950100]      <1> 	cmp	esi, ecore ; user's stack (last) page ?
 12069 00010436 7411                <1> 	je	short sysexec_9 ; yes
 12070 00010438 BE[64950100]        <1> 	mov	esi, ecore  ; physical address of the last page
 12071                              <1> 	; 20/07/2015
 12072 0001043D BB00F0FFFF          <1> 	mov	ebx, (ECORE - PAGE_SIZE) + CORE
 12073                              <1> 	; ebx = virtual end address + segment base address - 4K
 12074 00010442 EBD7                <1>         jmp     short sysexec_8
 12075                              <1> sysexec_panic:
 12076                              <1> 	; 23/07/2022
 12077 00010444 E98069FFFF          <1> 	jmp	panic
 12078                              <1> 
 12079                              <1> sysexec_9:
 12080                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
 12081                              <1> 	; 19/11/2017 
 12082                              <1> 	; 24/04/2016 (TRDOS 386 = TRDOS v2.0)
 12083                              <1> 	; 25/06/2015 - 26/08/2015 - 18/10/2015
 12084                              <1> 	; move arguments from kernel stack to [ecore]
 12085                              <1> 	; (argument list/line will be copied from kernel stack
 12086                              <1> 	; frame to the last (stack) page of user's core memory)
 12087                              <1> 	; 18/10/2015
 12088 00010449 8B3D[64950100]      <1> 	mov	edi, [ecore]
 12089 0001044F 81C700100000        <1> 	add	edi, PAGE_SIZE
 12090                              <1> 	; 19/11/2017
 12091                              <1> 	;sub	edi, 4
 12092                              <1> 	;mov	dword [edi], 0
 12093                              <1> 	;mov	ebx, edi
 12094                              <1> 	;
 12095                              <1> 	;movzx	eax, word [argc]
 12096                              <1> 	;or	eax, eax
 12097                              <1> 	;jz	short sysexec_13 ; 19/11/2017
 12098                              <1> 	;;jnz	short sysexec_10
 12099                              <1> 	;;mov 	ebx, edi
 12100                              <1> 	;;sub	ebx, 4 
 12101                              <1> 	;;mov	[ebx], eax ; 0
 12102                              <1> 	;;jmp 	short sysexec_13
 12103                              <1> 	; 23/07/2022
 12104                              <1> 	; [argc] < 32
 12105 00010455 A1[70950100]        <1> 	mov	eax, [argc]
 12106 0001045A 09C0                <1> 	or	eax, eax
 12107 0001045C 7509                <1> 	jnz	short sysexec_10
 12108 0001045E 89FB                <1> 	mov 	ebx, edi
 12109 00010460 83EB04              <1> 	sub	ebx, 4 
 12110 00010463 8903                <1> 	mov	[ebx], eax ; 0
 12111 00010465 EB47                <1> 	jmp 	short sysexec_13
 12112                              <1> 
 12113                              <1> sysexec_10:
 12114 00010467 8B0D[A0940100]      <1> 	mov	ecx, [u.nread]
 12115                              <1> 	; 13/11/2017
 12116                              <1> 	;;mov	esi, TextBuffer ; 'load_and_execute_file'
 12117                              <1> 	;mov	esi, esp  	; 'sysexec'
 12118 0001046D 8B35[74950100]      <1> 	mov	esi, [argv] ; 24/04/2016 (TRDOS 386  = TRDOS v2.0)
 12119                              <1> 	; 23/07/2022
 12120 00010473 29CF                <1> 	sub	edi, ecx ; page end address - argument list length
 12121                              <1> 	;sub	ebx, ecx ; 19/11/2017
 12122                              <1> 
 12123                              <1> 	;;;;
 12124                              <1> 	; 23/07/2022
 12125                              <1> 	; (move edi -backward- to dword boundary)
 12126                              <1> 	; ((this will prevent 'general protection fault' error
 12127                              <1> 	;  as result of a lodsd or dword move instruction
 12128                              <1> 	;  at the end of argument list))
 12129 00010475 83EF03              <1> 	sub	edi, 3
 12130 00010478 83E7FC              <1> 	and	edi, ~3 ; (*)
 12131                              <1> 	;;;
 12132                              <1> 
 12133 0001047B 89C2                <1> 	mov	edx, eax
 12134 0001047D FEC2                <1> 	inc	dl ; argument count + 1 for argc value
 12135 0001047F C0E202              <1> 	shl 	dl, 2  ; 4 * (argument count + 1)
 12136                              <1> 	; edx <= 128
 12137 00010482 89FB                <1> 	mov	ebx, edi
 12138                              <1> 	;mov	edi, ebx ; 19//11/2017
 12139                              <1> 	; 23/07/2022 (*) - edi is already dword aligned -
 12140                              <1> 	;and	bl, 0FCh ; 32 bit (dword) alignment
 12141 00010484 29D3                <1> 	sub 	ebx, edx
 12142 00010486 89FA                <1> 	mov	edx, edi
 12143 00010488 F3A4                <1> 	rep	movsb
 12144 0001048A 89D6                <1> 	mov 	esi, edx
 12145 0001048C 89DF                <1> 	mov 	edi, ebx
 12146 0001048E BA00F0BFFF          <1> 	mov	edx, ECORE - PAGE_SIZE ; virtual addr. of the last page
 12147 00010493 2B15[64950100]      <1> 	sub 	edx, [ecore] ; difference (virtual - physical)
 12148 00010499 AB                  <1> 	stosd	; eax = argument count
 12149                              <1> sysexec_11:
 12150 0001049A 89F0                <1> 	mov	eax, esi
 12151 0001049C 01D0                <1> 	add	eax, edx
 12152 0001049E AB                  <1> 	stosd  ; eax = virtual address
 12153                              <1> 	; 23/07/2022
 12154 0001049F FE0D[70950100]      <1> 	dec	byte [argc]
 12155                              <1> 	;dec	dword [argc]
 12156                              <1> 	;;dec	word [argc] ; 14/11/2017
 12157 000104A5 7407                <1> 	jz	short sysexec_13
 12158                              <1> sysexec_12:
 12159 000104A7 AC                  <1> 	lodsb
 12160 000104A8 20C0                <1> 	and	al, al
 12161 000104AA 75FB                <1> 	jnz	short sysexec_12
 12162 000104AC EBEC                <1> 	jmp	short sysexec_11
 12163                              <1> sysexec_13:
 12164                              <1> 	; 24/10/2016
 12165                              <1> 	; 24/04/2016 - TRDOS 386 (TRDOS v2.0)
 12166                              <1> 	; 23/06/2015 - 19/10/2015 (Retro UNIX 386 v1, 'sysexec_13')
 12167                              <1> 	;
 12168                              <1> 	; moving arguments to [ecore] is OK here..
 12169                              <1> 	;
 12170                              <1> 	; ebx = beginning addres of argument list pointers
 12171                              <1> 		;	in user's stack
 12172 000104AE 2B1D[64950100]      <1> 	sub 	ebx, [ecore]
 12173 000104B4 81C300F0BFFF        <1> 	add     ebx, (ECORE - PAGE_SIZE)
 12174                              <1> 			; end of core - 4096 (last page)
 12175                              <1> 			; (virtual address)
 12176 000104BA 891D[74950100]      <1> 	mov	[argv], ebx
 12177 000104C0 891D[A4940100]      <1> 	mov	[u.break], ebx ; available user memory
 12178                              <1> 	;
 12179 000104C6 29C0                <1> 	sub	eax, eax
 12180 000104C8 C705[9C940100]2000- <1> 	mov	dword [u.count], 32 ; Executable file header size
 12180 000104D0 0000                <1>
 12181 000104D2 C705[88940100]-     <1> 	mov	dword [u.fofp], u.off
 12181 000104D8 [94940100]          <1>
 12182 000104DC A3[94940100]        <1> 	mov	[u.off], eax ; 0
 12183 000104E1 A3[98940100]        <1> 	mov	[u.base], eax ; 0, start of user's core (virtual)
 12184                              <1> 	; 24/10/2016
 12185 000104E6 A0[827D0100]        <1> 	mov	al, [Current_Drv]
 12186 000104EB A2[59940100]        <1> 	mov	[cdev], al
 12187                              <1> 	;
 12188 000104F0 A1[7C950100]        <1> 	mov	eax, [ii] ; Fist Cluster of the Program (PRG) file
 12189                              <1> 	; EAX = First cluster of the executable file
 12190 000104F5 E8DD050000          <1> 	call	readi
 12191                              <1> 
 12192 000104FA 8B0D[A4940100]      <1> 	mov	ecx, [u.break] ; top of user's stack (physical addr.)
 12193 00010500 890D[9C940100]      <1> 	mov	[u.count], ecx ; save for overrun check
 12194                              <1> 	;
 12195 00010506 8B0D[A0940100]      <1> 	mov	ecx, [u.nread]
 12196 0001050C 890D[A4940100]      <1> 	mov	[u.break], ecx ; virtual address (offset from start)
 12197 00010512 80F920              <1> 	cmp	cl, 32
 12198 00010515 7540                <1>         jne     short sysexec_15
 12199                              <1> 	;:
 12200                              <1> 	; Retro UNIX 386 v1 (32 bit) executable file header format
 12201 00010517 8B35[60950100]      <1> 	mov	esi, [pcore] ; start address of user's core memory 
 12202                              <1> 		             ; (phys. start addr. of the exec. file)
 12203 0001051D AD                  <1> 	lodsd
 12204 0001051E 663DEB1E            <1> 	cmp	ax, 1EEBh ; EBH, 1Eh -> jump to +32
 12205 00010522 7533                <1> 	jne	short sysexec_15
 12206 00010524 AD                  <1> 	lodsd
 12207 00010525 89C1                <1> 	mov	ecx, eax ; text (code) section size
 12208 00010527 AD                  <1> 	lodsd
 12209 00010528 01C1                <1> 	add	ecx, eax ; + data section size (initialized data)
 12210 0001052A 89CB                <1> 	mov	ebx, ecx
 12211 0001052C AD                  <1> 	lodsd	
 12212 0001052D 01C3                <1> 	add	ebx, eax ; + bss section size (for overrun checking)
 12213 0001052F 3B1D[9C940100]      <1> 	cmp	ebx, [u.count]
 12214 00010535 7711                <1> 	ja	short sysexec_14  ; program overruns stack !
 12215                              <1> 	;
 12216                              <1> 	; add bss section size to [u.break]
 12217 00010537 0105[A4940100]      <1> 	add 	[u.break], eax
 12218                              <1> 	;
 12219 0001053D 83E920              <1> 	sub	ecx, 32  ; header size (already loaded)
 12220                              <1> 	;cmp	ecx, [u.count]
 12221                              <1> 	;jnb	short sysexec_16
 12222 00010540 890D[9C940100]      <1> 	mov	[u.count], ecx ; required read count
 12223 00010546 EB29                <1> 	jmp	short sysexec_16
 12224                              <1> sysexec_14:
 12225                              <1> 	; insufficient (out of) memory
 12226 00010548 C705[E0940100]0400- <1> 	mov	dword [u.error], ERR_MINOR_IM ; 1
 12226 00010550 0000                <1>
 12227 00010552 E9DDC8FFFF          <1> 	jmp	error
 12228                              <1> sysexec_15:
 12229 00010557 8B15[80950100]      <1>         mov	edx, [i.size] ; file size
 12230 0001055D 29CA                <1> 	sub	edx, ecx ; file size - loaded bytes
 12231 0001055F 7626                <1> 	jna	short sysexec_17 ; no need to next read
 12232 00010561 01D1                <1> 	add	ecx, edx ; [i.size]
 12233 00010563 3B0D[9C940100]      <1> 	cmp	ecx, [u.count] ; overrun check (!)
 12234 00010569 77DD                <1> 	ja	short sysexec_14
 12235 0001056B 8915[9C940100]      <1> 	mov	[u.count], edx
 12236                              <1> sysexec_16:
 12237 00010571 A1[7C950100]        <1> 	mov	eax, [ii] ; first cluster
 12238 00010576 E85C050000          <1> 	call	readi
 12239 0001057B 8B0D[A0940100]      <1> 	mov	ecx, [u.nread]
 12240 00010581 010D[A4940100]      <1> 	add	[u.break], ecx
 12241                              <1> sysexec_17:
 12242 00010587 A1[7C950100]        <1> 	mov	eax, [ii] ; first cluster
 12243 0001058C E85F1A0000          <1> 	call	iclose
 12244 00010591 31C0                <1> 	xor     eax, eax
 12245                              <1> 	
 12246                              <1> 	; 21/08/2024
 12247                              <1> 	;inc	al
 12248                              <1> 	;mov	[u.intr], ax ; 1 (interrupt/time-out is enabled)
 12249                              <1> 	;mov	[u.quit], ax ; 1 ('crtl+brk' signal is enabled)
 12250                              <1> 	; 23/07/2022
 12251                              <1> 	;dec	al
 12252                              <1> 	; 21/08/2024
 12253 00010593 48                  <1> 	dec	eax
 12254 00010594 66A3[C0940100]      <1> 	mov	[u.intr], ax ; -1 ; 0FFFFh ; enable CTRL+CRK
 12255 0001059A 40                  <1> 	inc	eax
 12256 0001059B 66A3[C2940100]      <1> 	mov	[u.quit], ax ; 0 ; reset CTRL+BRK flag
 12257                              <1> 
 12258                              <1> 	;cmp	dword [u.ppgdir], 0  ; is the caller MainProg (kernel) ?
 12259 000105A1 3905[D0940100]      <1> 	cmp	[u.ppgdir], eax ; 0 ; 23/07/2022
 12260 000105A7 770C                <1> 	ja	short sysexec_18 ; no, the caller is user process
 12261                              <1> 	; If the caller is kernel (MainProg), 'sysexec' will come here
 12262 000105A9 8B15[C07C0100]      <1> 	mov	edx, [k_page_dir] ; kernel's page directory
 12263 000105AF 8915[D0940100]      <1> 	mov	[u.ppgdir], edx ; next time 'sysexec' must not come here
 12264                              <1> sysexec_18:
 12265                              <1> 	; 02/05/2016
 12266                              <1> 	; 24/04/2016 (TRDOS 386 = TRDOS v2.0)
 12267                              <1> 	; 18/10/2015 (Retro UNIX 386 v1)
 12268                              <1> 	; 05/08/2015
 12269                              <1> 	; 29/07/2015
 12270                              <1> 
 12271                              <1> ;	; **** arguments list test start - 19/11/2017
 12272                              <1> ;	mov	ebp, [argv]
 12273                              <1> ;	sub	ebp, ECORE - 4096
 12274                              <1> ;	add	ebp, [ecore]
 12275                              <1> ;
 12276                              <1> ;	mov	ebx, [ebp]
 12277                              <1> ;	mov	[argc], bx
 12278                              <1> ;	add	ebp, 4
 12279                              <1> ;	mov	byte [ccolor], 1Fh
 12280                              <1> ;_zx0:
 12281                              <1> ;	cmp	word [argc], 0
 12282                              <1> ;	jna	short _zx2
 12283                              <1> ;_zx1:
 12284                              <1> ;	push	ebp
 12285                              <1> ;	mov	esi, [ebp]
 12286                              <1> ;
 12287                              <1> ;	sub	esi, ECORE - 4096
 12288                              <1> ;	add	esi, [ecore]
 12289                              <1> ;
 12290                              <1> ;	call	print_cmsg
 12291                              <1> ;
 12292                              <1> ;	dec	word [argc]
 12293                              <1> ;	jz	short _zx2
 12294                              <1> ;
 12295                              <1> ;	mov	al, '.'
 12296                              <1> ;	mov	bl, 07h
 12297                              <1> ;	mov	bh, [u.ttyn]
 12298                              <1> ;	call 	_write_tty 
 12299                              <1> ;
 12300                              <1> ;	pop	ebp
 12301                              <1> ;	add	ebp, 4
 12302                              <1> ;	jmp	short _zx1
 12303                              <1> ;_zx2:
 12304                              <1> ;	pop	ebp
 12305                              <1> ;	mov	byte [ccolor], 07h
 12306                              <1> ;	mov	eax, 1
 12307                              <1> ;	; **** arguments list test stop
 12308                              <1> ;	Test result is OK! (there is not a wrong thing) - 19/11/2017
 12309                              <1> 
 12310 000105B5 8B2D[74950100]      <1> 	mov	ebp, [argv] ; user's stack pointer must point to argument
 12311                              <1> 			    ; list pointers (argument count)
 12312 000105BB FA                  <1> 	cli
 12313 000105BC 8B25[5C7C0100]      <1>         mov     esp, [tss.esp0] ; ring 0 (kernel) stack pointer
 12314                              <1> 	;mov   	esp, [u.sp] ; Restore Kernel stack
 12315                              <1> 			    ; for this process
 12316                              <1> 	;add	esp, 20 ; --> EIP, CS, EFLAGS, ESP, SS
 12317                              <1> 	;;xor	eax, eax ; 0
 12318                              <1> 	; 23/07/2022
 12319                              <1> 	;dec	al ; eax = 0
 12320                              <1> 	; eax = 0
 12321                              <1> 
 12322                              <1> 	;mov	edx, UDATA
 12323                              <1> 	; 18/11/2017
 12324 000105C2 6A23                <1> 	push	UDATA ; user's stack segment
 12325                              <1> 	;push	edx
 12326 000105C4 55                  <1> 	push	ebp ; user's stack pointer
 12327                              <1> 		    ; (points to number of arguments)
 12328                              <1> 	
 12329                              <1> 	; 04/01/2017
 12330                              <1> 	; MainProg comes here while [sysflg]= 0FFh
 12331                              <1> 	; (but sysexec comes here while [sysflg]= 0)
 12332 000105C5 C605[68940100]00    <1> 	mov	byte [sysflg], 0 ; 04/01/2017
 12333                              <1> 				 ; (timer_int sysflg control)
 12334 000105CC FB                  <1> 	sti
 12335 000105CD 9C                  <1> 	pushfd	; EFLAGS
 12336                              <1> 		; Set IF for enabling interrupts in user mode
 12337                              <1> 	;or	dword [esp], 200h 
 12338                              <1> 	;
 12339                              <1> 	;mov	bx, UCODE
 12340                              <1> 	;push	bx ; user's code segment
 12341 000105CE 6A1B                <1> 	push	UCODE
 12342                              <1> 	;push	0
 12343 000105D0 50                  <1> 	push	eax ; EIP (=0) - start address -
 12344 000105D1 8925[6C940100]      <1> 	mov	[u.sp], esp ; 29/07/2015
 12345                              <1> 	; 05/08/2015
 12346                              <1> 	; Remedy of a General Protection Fault during 'iretd' is here !
 12347                              <1> 	; ('push dx' would cause to general protection fault, 
 12348                              <1> 	; after 'pop ds' etc.)
 12349                              <1> 	;
 12350                              <1> 	;; push dx ; ds (UDATA)
 12351                              <1> 	;; push dx ; es (UDATA)
 12352                              <1> 	;; push dx ; fs (UDATA)
 12353                              <1> 	;; push dx ; gs (UDATA)
 12354                              <1> 	;
 12355                              <1> 	; This is a trick to prevent general protection fault
 12356                              <1> 	; during 'iretd' intruction at the end of 'sysrele' (in u1.s):
 12357 000105D7 66BA2300            <1> 	mov	dx, UDATA ; 19/11/2017
 12358 000105DB 8EC2                <1> 	mov 	es, dx ; UDATA
 12359 000105DD 06                  <1> 	push 	es ; ds (UDATA)
 12360 000105DE 06                  <1> 	push 	es ; es (UDATA)
 12361 000105DF 06                  <1> 	push 	es ; fs (UDATA)
 12362 000105E0 06                  <1> 	push	es ; gs (UDATA)
 12363 000105E1 66BA1000            <1> 	mov	dx, KDATA
 12364 000105E5 8EC2                <1> 	mov	es, dx
 12365                              <1> 	;
 12366                              <1> 	;; pushad simulation
 12367 000105E7 89E5                <1> 	mov	ebp, esp ; esp before pushad
 12368 000105E9 50                  <1> 	push	eax ; eax (0)
 12369 000105EA 50                  <1> 	push	eax ; ecx (0)
 12370 000105EB 50                  <1> 	push	eax ; edx (0)
 12371 000105EC 50                  <1> 	push	eax ; ebx (0)
 12372 000105ED 55                  <1> 	push	ebp ; esp before pushad
 12373 000105EE 50                  <1> 	push	eax ; ebp (0)
 12374 000105EF 50                  <1> 	push	eax ; esi (0)
 12375 000105F0 50                  <1> 	push	eax ; edi (0)
 12376                              <1> 	;
 12377 000105F1 A3[74940100]        <1> 	mov	[u.r0], eax ; eax = 0
 12378 000105F6 8925[70940100]      <1> 	mov	[u.usp], esp
 12379                              <1> 
 12380                              <1> 	; 14/11/2017
 12381 000105FC E955C8FFFF          <1> 	jmp	sysret0
 12382                              <1> 
 12383                              <1> get_argp:
 12384                              <1> 	; 08/08/2022
 12385                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
 12386                              <1> 	; 11/12/2021 - Retro UNIX 386 v1.2 
 12387                              <1> 	; 14/11/2017 - TRDOS 386 (TRDOS v2.0)
 12388                              <1> 	; 18/10/2015 (nbase, ncount)
 12389                              <1> 	; 21/07/2015
 12390                              <1> 	; 24/06/2015 (Retro UNIX 386 v1)
 12391                              <1> 	; Get (virtual) address of argument from user's core memory
 12392                              <1> 	;
 12393                              <1> 	; INPUT:
 12394                              <1> 	;	esi = virtual address of argument pointer
 12395                              <1> 	; OUTPUT:
 12396                              <1> 	;	eax = virtual address of argument
 12397                              <1> 	;
 12398                              <1> 	; Modified registers: EAX, EBX, ECX, EDX, ESI 
 12399                              <1> 	;
 12400 00010601 833D[D0940100]00    <1>  	cmp     dword [u.ppgdir], 0 ; /etc/init ?
 12401                              <1> 				    ; (the caller is kernel)
 12402                              <1> 	;jna	short get_argpk
 12403                              <1> 	; 08/08/2022
 12404 00010608 7705                <1> 	ja	short get_argp5
 12405 0001060A E985000000          <1> 	jmp	get_argpk
 12406                              <1> get_argp5:
 12407 0001060F 89F3                <1>      	mov	ebx, esi
 12408 00010611 E8A855FFFF          <1> 	call	get_physical_addr ; get physical address
 12409 00010616 7253                <1>         jc      short get_argp_err ; 23/07/2022
 12410 00010618 A3[68950100]        <1> 	mov 	[nbase], eax ; physical address
 12411                              <1> 	;mov	[ncount], cx ; remain byte count in page (1-4096)
 12412                              <1> 	; 23/07/2022
 12413 0001061D 890D[6C950100]      <1> 	mov	[ncount], ecx
 12414                              <1> 	;mov	eax, 4 ; 21/07/2015
 12415 00010623 31C0                <1> 	xor	eax, eax
 12416 00010625 B004                <1> 	mov	al, 4
 12417                              <1> 	;cmp	cx, ax ; 4
 12418                              <1> 	; 23/07/2022
 12419 00010627 39C1                <1> 	cmp	ecx, eax ; 4
 12420 00010629 7354                <1> 	jnb	short get_argp2
 12421 0001062B 89F3                <1> 	mov	ebx, esi
 12422 0001062D 01CB                <1> 	add	ebx, ecx
 12423 0001062F E88A55FFFF          <1> 	call	get_physical_addr ; get physical address
 12424 00010634 7235                <1> 	jc	short get_argp_err
 12425                              <1> 	;push	esi
 12426 00010636 89C6                <1> 	mov	esi, eax
 12427                              <1> 	;xchg	cx, [ncount]
 12428                              <1> 	; 23/07/2022
 12429 00010638 870D[6C950100]      <1> 	xchg	ecx, [ncount]
 12430 0001063E 8735[68950100]      <1> 	xchg	esi, [nbase]
 12431 00010644 B504                <1> 	mov	ch, 4
 12432 00010646 28CD                <1> 	sub	ch, cl
 12433                              <1> get_argp0:
 12434 00010648 AC                  <1> 	lodsb
 12435                              <1> 	;push	ax
 12436                              <1> 	; 23/07/2022
 12437 00010649 50                  <1> 	push	eax
 12438 0001064A FEC9                <1> 	dec	cl
 12439 0001064C 75FA                <1>         jnz     short get_argp0
 12440 0001064E 8B35[68950100]      <1> 	mov	esi, [nbase]
 12441                              <1> 	; 21/07/2015
 12442 00010654 0FB6C5              <1> 	movzx	eax, ch
 12443 00010657 0105[68950100]      <1> 	add	[nbase], eax
 12444                              <1> 	;sub	[ncount], ax
 12445                              <1> 	; 23/07/2022
 12446 0001065D 2905[6C950100]      <1> 	sub	[ncount], eax
 12447                              <1> get_argp1:
 12448 00010663 AC                  <1> 	lodsb
 12449 00010664 FECD                <1> 	dec	ch
 12450 00010666 7445                <1>         jz      short get_argp3
 12451                              <1>         ;push	ax
 12452                              <1> 	; 23/07/2022
 12453 00010668 50                  <1> 	push	eax
 12454 00010669 EBF8                <1> 	jmp     short get_argp1
 12455                              <1> get_argp_err:
 12456 0001066B A3[E0940100]        <1> 	mov	[u.error], eax
 12457                              <1> 	; 14/11/2017
 12458 00010670 B801000000          <1> 	mov	eax, ERR_BAD_CMD_ARG ; 01h ; TRDOS 8086
 12459 00010675 A3[74940100]        <1> 	mov	[u.r0], eax
 12460 0001067A E9B5C7FFFF          <1> 	jmp	error
 12461                              <1> get_argp2:
 12462                              <1> 	; 21/07/2015
 12463                              <1> 	;mov	eax, 4
 12464 0001067F 8B15[68950100]      <1> 	mov 	edx, [nbase] ; 18/10/2015
 12465 00010685 0105[68950100]      <1> 	add	[nbase], eax
 12466                              <1> 	;sub	[ncount], ax
 12467                              <1> 	; 23/07/2022
 12468 0001068B 2905[6C950100]      <1> 	sub	[ncount], eax
 12469                              <1> 	;
 12470 00010691 8B02                <1> 	mov	eax, [edx]
 12471 00010693 C3                  <1> 	retn
 12472                              <1> get_argpk:
 12473                              <1> 	; Argument is in kernel's memory space
 12474 00010694 66C705[6C950100]00- <1> 	mov	word [ncount], PAGE_SIZE ; 4096
 12474 0001069C 10                  <1>
 12475 0001069D 8935[68950100]      <1> 	mov	[nbase], esi
 12476 000106A3 8305[68950100]04    <1> 	add	dword [nbase], 4
 12477 000106AA 8B06                <1> 	mov	eax, [esi] ; virtual addr. = physical addr.
 12478 000106AC C3                  <1> 	retn
 12479                              <1> get_argp3:
 12480 000106AD B103                <1> 	mov	cl, 3
 12481                              <1> get_argp4:
 12482 000106AF C1E008              <1> 	shl	eax, 8
 12483                              <1> 	;pop	dx
 12484                              <1> 	; 23/07/2022
 12485 000106B2 5A                  <1> 	pop	edx
 12486 000106B3 88D0                <1> 	mov 	al, dl
 12487 000106B5 E2F8                <1>         loop    get_argp4
 12488                              <1> 	;pop	esi
 12489 000106B7 C3                  <1> 	retn
 12490                              <1> 
 12491                              <1> 	; 23/07/2022
 12492                              <1> %if 0	
 12493                              <1> 
 12494                              <1> sysstat: 
 12495                              <1> 	; 13/01/2017 - TRDOS 386 (TRDOS v2.0)
 12496                              <1> 	; temporary !
 12497                              <1> 	mov	eax, ERR_INV_FNUMBER ; 'invalid function number !'
 12498                              <1>         mov     [u.error], eax
 12499                              <1>         mov     [u.r0], eax 
 12500                              <1> 	jmp	error
 12501                              <1> 
 12502                              <1> sysfstat: 
 12503                              <1> 	; 13/01/2017 - TRDOS 386 (TRDOS v2.0)
 12504                              <1> 	; temporary !
 12505                              <1> 	mov	eax, ERR_INV_FNUMBER ; 'invalid function number !'
 12506                              <1>         mov     [u.error], eax
 12507                              <1>         mov     [u.r0], eax 
 12508                              <1> 	jmp	error
 12509                              <1> 
 12510                              <1> %endif
 12511                              <1> 
 12512                              <1> fclose:
 12513                              <1> 	; 18/09/2024 - TRDOS 386 Kernel v2.0.9
 12514                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
 12515                              <1> 	; 06/10/2016 (TRDOS 386 = TRDOS v2.0)
 12516                              <1> 	;
 12517                              <1> 	; 18/06/2015 (Retro UNIX 386 v1 - Beginning)
 12518                              <1> 	;            (32 bit offset pointer modification)
 12519                              <1> 	; 19/04/2013 - 12/01/2014 (Retro UNIX 8086 v1)
 12520                              <1> 	;
 12521                              <1> 	; Given the file descriptor (index to the u.fp list)
 12522                              <1> 	; 'fclose' first gets the i-number of the file via 'getf'.
 12523                              <1> 	; If i-node is active (i-number > 0) the entry in 
 12524                              <1> 	; u.fp list is cleared. If all the processes that opened
 12525                              <1> 	; that file close it, then fsp etry is freed and the file
 12526                              <1> 	; is closed. If not a return is taken. 
 12527                              <1> 	; If the file has been deleted while open, 'anyi' is called
 12528                              <1> 	; to see anyone else has it open, i.e., see if it is appears
 12529                              <1> 	; in another entry in the fsp table. Upon return from 'anyi'
 12530                              <1> 	; a check is made to see if the file is special.
 12531                              <1> 	;
 12532                              <1> 	; INPUTS ->
 12533                              <1> 	;    r1 - contains the file descriptor (value=0,1,2...)
 12534                              <1> 	;    u.fp - list of entries in the fsp table
 12535                              <1> 	;    fsp - table of entries (4 words/entry) of open files.
 12536                              <1> 	; OUTPUTS ->
 12537                              <1> 	;    r1 - contains the same file descriptor
 12538                              <1> 	;    r2 - contains i-number
 12539                              <1> 	;
 12540                              <1> 	; ((AX = R1))
 12541                              <1> 	; ((Modified registers: EDX, EBX, ECX, ESI, EDI, EBP))
 12542                              <1> 	;
 12543                              <1> 	; Retro UNIX 8086 v1 modification : CF = 1
 12544                              <1> 	;              if i-number of the file is 0. (error)
 12545                              <1> 	;
 12546                              <1> 	; TRDOS 386 (06/10/2016)
 12547                              <1> 	; 
 12548                              <1> 	; INPUT:
 12549                              <1> 	;	EAX = File Handle (File Descriptor, File Index)
 12550                              <1> 	;
 12551                              <1> 	; OUTPUT:
 12552                              <1> 	;	CF = 1 -> File not open !
 12553                              <1> 	;	CF = 0 -> OK!
 12554                              <1> 	;	     EBX = File Number (System)
 12555                              <1> 	;	     [cdev] = Logical DOS Drive Number
 12556                              <1> 	;	     EAX = File Handle/Number (user)
 12557                              <1> 	;
 12558                              <1> 	; Modified Registers: EBX
 12559                              <1> 
 12560 000106B8 50                  <1> 	push	eax ; File handle
 12561                              <1> 
 12562 000106B9 E841000000          <1> 	call	getf
 12563                              <1> 	;jc	device_close ; eax = device number
 12564                              <1> 	; 17/04/2021 (temporary)
 12565 000106BE 7306                <1> 	jnc	short _fclose_0
 12566 000106C0 58                  <1> 	pop	eax
 12567 000106C1 E94FCFFFFF          <1> 	jmp	rw2 ; file not open !
 12568                              <1> _fclose_0:
 12569 000106C6 80BB[208A0100]01    <1> 	cmp	byte [ebx+OF_MODE], 1 ; open mode ; 0 = empty entry
 12570 000106CD 7227                <1> 	jb	short fclose_1	      ; 1 = read, 2 = write
 12571                              <1> 	
 12572                              <1> 	; 18/09/2024 (EMPTY FILE BugFix)
 12573                              <1> 	;cmp	eax, 1 ; is the first cluster number > 0
 12574                              <1> 	;jb	short fclose_1 ; no, this is empty entry
 12575                              <1> 
 12576                              <1> fclose_0:
 12577 000106CF FE8B[608A0100]      <1> 	dec	byte [ebx+OF_OPENCOUNT] ; decrement the number of processes
 12578                              <1> 			                ; that have opened the file
 12579 000106D5 791F                <1> 	jns	short fclose_1 ; jump if not negative (jump if bit 7 is 0)
 12580                              <1> 			; if all processes haven't closed the file, return
 12581                              <1> 	;
 12582                              <1> 	; eax ; First cluster
 12583 000106D7 31C0                <1> 	xor	eax, eax ; 0
 12584 000106D9 8883[208A0100]      <1> 	mov	[ebx+OF_MODE], al ; 0 = empty entry
 12585                              <1> 	;mov	[ebx+OF_STATUS], al ; 0 = empty entry
 12586                              <1> 	;shl	bx, 2 
 12587                              <1> 	; 23/07/2022
 12588                              <1> 	;shl	bl, 2
 12589 000106DF C1E302              <1> 	shl	ebx, 2
 12590 000106E2 8983[80890100]      <1> 	mov	[ebx+OF_FCLUSTER], eax ; 0
 12591 000106E8 8983[008D0100]      <1> 	mov	[ebx+OF_CCLUSTER], eax ; 0
 12592                              <1> 	;mov	[ebx+OF_CCINDEX], eax ; 0
 12593                              <1> 	; 23/07/2022
 12594                              <1> 	;mov	[ebx+OF_OPENCOUNT], al ; 0
 12595 000106EE A3[88940100]        <1> 	mov	[u.fofp], eax ; 0
 12596                              <1> 	;shr	bx, 2
 12597                              <1> 	; 23/07/2022
 12598                              <1> 	;shr	bl, 2
 12599 000106F3 C1EB02              <1> 	shr	ebx, 2
 12600                              <1> fclose_1: ; 1:
 12601 000106F6 58                  <1> 	pop	eax ; File handle (File Descriptor, File Index)
 12602 000106F7 C680[7E940100]00    <1> 	mov	byte [eax+u.fp], 0 ; clear that entry in the u.fp list
 12603 000106FE C3                  <1> 	retn
 12604                              <1> 
 12605                              <1> getf:
 12606                              <1> 	; 03/09/2024 - TRDOS 386 v2.0.9
 12607                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
 12608                              <1> 	; 17/04/2021 - TRDOS 386 v2.0.4
 12609                              <1> 	;	(temporary modifications)
 12610                              <1> 	; 12/10/2016
 12611                              <1> 	; 11/10/2016
 12612                              <1> 	; 08/10/2016
 12613                              <1> 	; 06/10/2016 (TRDOS 386 = TRDOS v2.0)
 12614                              <1> 	; / get the device number and the i-number of an open file
 12615                              <1> 	; 13/05/2015
 12616                              <1> 	; 11/05/2015 (Retro UNIX 386 v1 - Beginning)
 12617                              <1> 	; 19/04/2013 - 18/11/2013 (Retro UNIX 8086 v1)
 12618                              <1> 	;
 12619 000106FF 89C3                <1> 	mov	ebx, eax
 12620                              <1> getf1:
 12621 00010701 83FB0A              <1> 	cmp	ebx, 10
 12622 00010704 730A                <1>         jnb	short getf2
 12623 00010706 8A9B[7E940100]      <1> 	mov	bl, [ebx+u.fp]
 12624 0001070C 08DB                <1> 	or	bl, bl
 12625 0001070E 7504                <1> 	jnz	short getf3
 12626                              <1> getf2:
 12627                              <1> 	; 'File not open !' error (ax=0)
 12628 00010710 29C0                <1> 	sub	eax, eax
 12629                              <1> 	; 03/09/2024
 12630 00010712 F9                  <1> 	stc
 12631 00010713 C3                  <1> 	retn
 12632                              <1> getf3:
 12633                              <1> 	; 23/07/2022
 12634                              <1> 	;test	bl, 80h
 12635                              <1> 	;jnz	short getf5 ; device
 12636 00010714 FECB                <1> 	dec	bl ; 0 based
 12637 00010716 8A83[008A0100]      <1> 	mov	al, [ebx+OF_DRIVE]
 12638 0001071C A2[59940100]        <1> 	mov	[cdev], al
 12639 00010721 C0E302              <1> 	shl	bl, 2 ; *4 (dword offset)
 12640                              <1> 	; 23/07/2022
 12641                              <1> 	;shl	ebx, 2
 12642 00010724 8B83[008B0100]      <1> 	mov	eax, [ebx+OF_SIZE]
 12643 0001072A A3[80950100]        <1> 	mov	[i.size], eax ; file size
 12644 0001072F 8D83[808A0100]      <1> 	lea	eax, [ebx+OF_POINTER] ; 12/10/2016
 12645 00010735 A3[88940100]        <1> 	mov	[u.fofp], eax
 12646 0001073A 8B83[80890100]      <1> 	mov	eax, [ebx+OF_FCLUSTER]
 12647 00010740 C0EB02              <1> 	shr	bl, 2 ; /4 (byte offset)
 12648                              <1> 	; 23/07/2022
 12649                              <1> 	;shr	ebx, 2
 12650                              <1> 	; 17/04/2021
 12651 00010743 F8                  <1> 	clc 
 12652                              <1> getf4:
 12653 00010744 C3                  <1> 	retn
 12654                              <1> ;getf5: 
 12655                              <1> 	; 17/04/2021
 12656                              <1> 	; (following code is disabled as temporary)
 12657                              <1> 	;
 12658                              <1> 	;; get device number
 12659                              <1> 	;and	bl, 7Fh ; 1 to 7Fh
 12660                              <1> 	;dec	bl ; 0 based (0 to 7Eh)
 12661                              <1> 	;mov	al, [ebx+DEV_DRIVER]
 12662                              <1> 	;mov	ch, [ebx+DEV_ACCESS]
 12663                              <1> 	;mov	cl, [ebx+DEV_OPENMODE]
 12664                              <1> 	;and	ch, 0FEh ; reset bit 0 ; dev_close
 12665                              <1> 	;
 12666                              <1> 	; 23/07/2022
 12667                              <1> 	;stc ; cf = 1
 12668                              <1> 	;retn
 12669                              <1> 
 12670                              <1> trans_addr_nmbp:
 12671                              <1> 	; 18/10/2015
 12672                              <1> 	; 12/10/2015
 12673 00010745 8B2D[90940100]      <1> 	mov 	ebp, [u.namep]
 12674                              <1> trans_addr_nm: 
 12675                              <1> 	; Convert virtual (pathname) address to physical address
 12676                              <1> 	; (Retro UNIX 386 v1 feature only !)
 12677                              <1> 	; 18/10/2015
 12678                              <1> 	; 12/10/2015 (u.pnbase & u.pncount has been removed from code)
 12679                              <1> 	; 02/07/2015
 12680                              <1> 	; 17/06/2015
 12681                              <1> 	; 16/06/2015
 12682                              <1> 	;
 12683                              <1> 	; INPUTS: 
 12684                              <1> 	;	ebp = pathname address (virtual) ; [u.namep]
 12685                              <1> 	;	[u.pgdir] = user's page directory
 12686                              <1> 	; OUTPUT:
 12687                              <1> 	;       esi = physical address of the pathname
 12688                              <1> 	;	ecx = remain byte count in the page
 12689                              <1> 	;
 12690                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX, ESI)
 12691                              <1> 	;
 12692 0001074B 833D[D0940100]00    <1>         cmp     dword [u.ppgdir], 0  ; /etc/init ? (sysexec)
 12693 00010752 7618                <1> 	jna	short trans_addr_nmk ; the caller is os kernel;
 12694                              <1> 				     ; it is already physical address
 12695 00010754 50                  <1>    	push	eax
 12696 00010755 89EB                <1> 	mov	ebx, ebp ; [u.namep] ; pathname address (virtual)
 12697 00010757 E86254FFFF          <1>        	call	get_physical_addr ; get physical address
 12698 0001075C 7204                <1> 	jc	short tr_addr_nm_err
 12699                              <1> 	; 18/10/2015
 12700                              <1> 	; eax = physical address 
 12701                              <1> 	; cx = remain byte count in page (1-4096)
 12702                              <1> 		; 12/10/2015 (cx = [u.pncount])
 12703 0001075E 89C6                <1> 	mov	esi, eax ; 12/10/2015 (esi=[u.pnbase])
 12704 00010760 58                  <1> 	pop	eax
 12705 00010761 C3                  <1> 	retn
 12706                              <1> 
 12707                              <1> tr_addr_nm_err:
 12708 00010762 A3[E0940100]        <1> 	mov	[u.error], eax
 12709                              <1> 	;pop 	eax
 12710 00010767 E9C8C6FFFF          <1> 	jmp	error
 12711                              <1> 
 12712                              <1> trans_addr_nmk:
 12713                              <1> 	; 12/10/2015
 12714                              <1> 	; 02/07/2015
 12715 0001076C 8B35[90940100]      <1> 	mov	esi, [u.namep]  ; [u.pnbase]
 12716 00010772 66B90010            <1> 	mov	cx, PAGE_SIZE ; 4096 ; [u.pncount]
 12717 00010776 C3                  <1> 	retn
 12718                              <1> 
 12719                              <1> sysbreak:
 12720                              <1> 	; 06/09/2024 - TRDOS 386 v2.0.9
 12721                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
 12722                              <1> 	; 18/10/2015
 12723                              <1> 	; 07/10/2015
 12724                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 12725                              <1> 	; 20/06/2013 - 24/03/2014 (Retro UNIX 8086 v1)
 12726                              <1> 	;
 12727                              <1> 	; 'sysbreak' sets the programs break points. 
 12728                              <1> 	; It checks the current break point (u.break) to see if it is
 12729                              <1> 	; between "core" and the stack (sp). If it is, it is made an
 12730                              <1> 	; even address (if it was odd) and the area between u.break
 12731                              <1> 	; and the stack is cleared. The new breakpoint is then put
 12732                              <1> 	; in u.break and control is passed to 'sysret'.
 12733                              <1> 	;
 12734                              <1> 	; Calling sequence:
 12735                              <1> 	;	sysbreak; addr
 12736                              <1> 	; Arguments: -
 12737                              <1> 	;	
 12738                              <1> 	; Inputs: u.break - current breakpoint
 12739                              <1> 	; Outputs: u.break - new breakpoint 
 12740                              <1> 	;	area between old u.break and the stack (sp) is cleared.
 12741                              <1> 	; 
 12742                              <1> 	; ...............................................................
 12743                              <1> 	; 06/09/2024 - TRDOS 386 v2.0.9 - Major Modification -
 12744                              <1> 	;
 12745                              <1> 	; 	This system call performs "malloc" function as in C.
 12746                              <1> 	; Input:
 12747                              <1> 	;    EBX = new u.break address (virtual, user's space)
 12748                              <1> 	; (Note: Default/Initial u.break address is the start of the BSS
 12749                              <1> 	;	 section. Or it is file size for PRG -flat image- files.)
 12750                              <1> 	; If EBX = 0FFFFFFFFh ; -1
 12751                              <1> 	;    Return current u.break in EAX
 12752                              <1> 	; Output:
 12753                              <1> 	;    If EBX input is -1, EAX = current u.break address (virtual)
 12754                              <1> 	;	otherwise, EAX = new u.break address
 12755                              <1> 	; Area between the new u.break and the old u.break is cleared.
 12756                              <1> 	; (Note: If the new break address cross overs user's esp,
 12757                              <1> 	;	 this area <new break - old break> is not cleared.)
 12758                              <1> 	; If CF=1 at return, it means Memory Allocation Error.
 12759                              <1> 	;		(or "Insufficient Memory" error)
 12760                              <1> 	;	EAX = 0
 12761                              <1> 	; ...............................................................
 12762                              <1> 	;	
 12763                              <1> 	; Retro UNIX 8086 v1 modification:
 12764                              <1> 	;	The user/application program puts breakpoint address
 12765                              <1> 	;       in BX register as 'sysbreak' system call argument.
 12766                              <1> 	; 	(argument transfer method 1)
 12767                              <1> 	;
 12768                              <1> 	;  NOTE: Beginning of core is 0 in Retro UNIX 8086 v1 !
 12769                              <1> 	; 	((!'sysbreak' is not needed in Retro UNIX 8086 v1!))
 12770                              <1> 	;  NOTE:
 12771                              <1> 	; 	'sysbreak' clears extended part (beyond of previous
 12772                              <1> 	;	'u.break' address) of user's memory for original unix's
 12773                              <1> 	;	'bss' compatibility with Retro UNIX 8086 v1 (19/11/2013)
 12774                              <1> 	
 12775                              <1> 		; mov u.break,r1 / move users break point to r1
 12776                              <1> 		; cmp r1,$core / is it the same or lower than core?
 12777                              <1> 		; blos 1f / yes, 1f
 12778                              <1> 	; 23/06/2015
 12779 00010777 8B2D[A4940100]      <1> 	mov	ebp, [u.break] ; virtual address (offset)
 12780                              <1> 	
 12781                              <1> 	; 06/09/2024
 12782 0001077D 31C0                <1> 	xor	eax, eax
 12783 0001077F A3[74940100]        <1> 	mov	[u.r0], eax ; 0 ; default ('memory allocation error')
 12784 00010784 48                  <1> 	dec	eax ; -1
 12785                              <1> 
 12786                              <1> 	; 06/09/2024 - TRDOS 386 v2.0.9
 12787                              <1> 	; get u.break address (for 'malloc' in c compiler)
 12788                              <1> 	; for PRG files:
 12789                              <1> 	; default/initial u.break address is file size
 12790 00010785 39C3                <1> 	cmp	ebx, eax ; -1 ; 0FFFFFFFFh
 12791 00010787 7214                <1> 	jb	short sysbreak_@
 12792                              <1> 
 12793                              <1> sysbreak_4:
 12794 00010789 89EB                <1> 	mov	ebx, ebp
 12795                              <1> 	;(allocates a new page for user if it is not present)
 12796 0001078B E82E54FFFF          <1> 	call	get_physical_addr ; get physical address
 12797 00010790 72D0                <1> 	jc	short tr_addr_nm_err
 12798                              <1> 
 12799 00010792 892D[74940100]      <1> 	mov	[u.r0], ebp  ; start of bss space (to be allocated)
 12800 00010798 E9B7C6FFFF          <1> 	jmp	sysret
 12801                              <1> 
 12802                              <1> sysbreak_@:
 12803                              <1> 	;and	ebp, ebp
 12804                              <1> 	;jz	short sysbreak_3 
 12805                              <1> 	; Retro UNIX 386 v1 NOTE: u.break points to virtual address !!!
 12806                              <1> 	; (Even break point address is not needed for Retro UNIX 386 v1)
 12807 0001079D 8B15[6C940100]      <1> 	mov	edx, [u.sp] ; kernel stack at the beginning of sys call
 12808 000107A3 83C20C              <1> 	add	edx, 12 ; EIP -4-> CS -4-> EFLAGS -4-> ESP (user) 
 12809                              <1> 	; 07/10/2015
 12810                              <1> 	;mov	[u.break], ebx ; virtual address !!!
 12811                              <1> 	;
 12812                              <1> 	; 06/09/2024
 12813                              <1> 	; ebp = old/current u.break
 12814                              <1> 
 12815 000107A6 3B1A                <1> 	cmp	ebx, [edx] ; compare new break point with 
 12816                              <1> 			   ; with top of user's stack (virtual!)
 12817 000107A8 732B                <1> 	jnb	short sysbreak_3
 12818                              <1> 		; cmp r1,sp / is it the same or higher 
 12819                              <1> 			  ; / than the stack?
 12820                              <1> 		; bhis 1f / yes, 1f
 12821 000107AA 89DE                <1> 	mov	esi, ebx
 12822 000107AC 29EE                <1> 	sub	esi, ebp ; new break point - old break point
 12823                              <1> 	;jna	short sysbreak_3 
 12824                              <1> 	; 06/09/2024
 12825 000107AE 7706                <1> 	ja	short sysbreak_1
 12826 000107B0 74D7                <1> 	jz	short sysbreak_4
 12827 000107B2 F7DE                <1> 	neg	esi ; convert to positive number (big-small)
 12828 000107B4 89DD                <1> 	mov	ebp, ebx ; move small number (address) to ebp
 12829                              <1> 
 12830                              <1> sysbreak_1:
 12831                              <1> 	; 06/09/2024
 12832 000107B6 53                  <1> 	push	ebx
 12833 000107B7 89EB                <1> 	mov	ebx, ebp
 12834 000107B9 E80054FFFF          <1> 	call	get_physical_addr ; get physical address
 12835 000107BE 5B                  <1> 	pop	ebx
 12836 000107BF 72A1                <1> 	jc	short tr_addr_nm_err ; 23/07/2022
 12837                              <1> 	; 18/10/2015
 12838 000107C1 89C7                <1> 	mov	edi, eax
 12839 000107C3 29C0                <1> 	sub	eax, eax ; 0
 12840                              <1> 		 ; ECX = remain byte count in page (1-4096)
 12841 000107C5 39CE                <1> 	cmp	esi, ecx
 12842 000107C7 7302                <1> 	jnb	short sysbreak_2
 12843 000107C9 89F1                <1> 	mov	ecx, esi
 12844                              <1> sysbreak_2:
 12845 000107CB 29CE                <1> 	sub	esi, ecx
 12846 000107CD 01CD                <1> 	add	ebp, ecx
 12847 000107CF F3AA                <1> 	rep 	stosb
 12848 000107D1 09F6                <1> 	or	esi, esi
 12849 000107D3 75E1                <1> 	jnz	short sysbreak_1
 12850                              <1> 		; bit $1,r1 / is it an odd address
 12851                              <1> 		; beq 2f / no, its even
 12852                              <1> 		; clrb (r1)+ / yes, make it even
 12853                              <1> 	; 2: / clear area between the break point and the stack
 12854                              <1> 		; cmp r1,sp / is it higher or same than the stack
 12855                              <1> 		; bhis 1f / yes, quit
 12856                              <1> 		; clr (r1)+ / clear word
 12857                              <1> 		; br 2b / go back
 12858                              <1> 	;pop	ebx
 12859                              <1> sysbreak_3: ; 1:
 12860                              <1> 	; 06/09/2024
 12861 000107D5 891D[A4940100]      <1> 	mov	[u.break], ebx ; virtual address !!!
 12862                              <1> 		; jsr r0,arg; u.break / put the "address"
 12863                              <1> 			; / in u.break (set new break point)
 12864                              <1> 		; br sysret4 / br sysret
 12865                              <1> 	; 06/09/2024
 12866 000107DB 891D[74940100]      <1> 	mov	[u.r0], ebx ; return new break point in eax
 12867 000107E1 E96EC6FFFF          <1> 	jmp	sysret
 12868                              <1> 
 12869                              <1> sysseek: ; / moves read write pointer in an fsp entry
 12870                              <1> 	; 06/11/2016 - TRDOS 386 (TRDOS v2.0)
 12871                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 12872                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
 12873                              <1> 	;
 12874                              <1> 	; 'sysseek' changes the r/w pointer of (3rd word of in an
 12875                              <1> 	; fsp entry) of an open file whose file descriptor is in u.r0.
 12876                              <1> 	; The file descriptor refers to a file open for reading or
 12877                              <1> 	; writing. The read (or write) pointer is set as follows:
 12878                              <1> 	;	* if 'ptrname' is 0, the pointer is set to offset.
 12879                              <1> 	;	* if 'ptrname' is 1, the pointer is set to its
 12880                              <1> 	;	  current location plus offset.
 12881                              <1> 	;	* if 'ptrname' is 2, the pointer is set to the
 12882                              <1> 	;	  size of file plus offset.
 12883                              <1> 	; The error bit (e-bit) is set for an undefined descriptor.
 12884                              <1> 	;
 12885                              <1> 	; Calling sequence:
 12886                              <1> 	;	sysseek; offset; ptrname
 12887                              <1> 	; Arguments:
 12888                              <1> 	;	offset - number of bytes desired to move
 12889                              <1> 	;		 the r/w pointer
 12890                              <1> 	;	ptrname - a switch indicated above
 12891                              <1> 	;
 12892                              <1> 	; Inputs: r0 - file descriptor 
 12893                              <1> 	; Outputs: -
 12894                              <1> 	; ...............................................................
 12895                              <1> 	;	
 12896                              <1> 	; Retro UNIX 8086 v1 modification: 
 12897                              <1> 	;       'sysseek' system call has three arguments; so,
 12898                              <1> 	;	* 1st argument, file descriptor is in BX (BL) register
 12899                              <1> 	;	* 2nd argument, offset is in CX register
 12900                              <1> 	;	* 3rd argument, ptrname/switch is in DX (DL) register
 12901                              <1> 
 12902 000107E6 E821000000          <1> 	call	seektell
 12903                              <1> 	; EAX = Current R/W pointer of the file
 12904                              <1> 	; EBX = [u.fofp]
 12905                              <1> 	; [u.base] = offset (ECX input)
 12906                              <1> 
 12907 000107EB 0305[98940100]      <1> 	add	eax, [u.base]
 12908 000107F1 8903                <1> 	mov	[ebx], eax
 12909 000107F3 E95CC6FFFF          <1> 	jmp	sysret
 12910                              <1> 
 12911                              <1> systell: ; / get the r/w pointer
 12912                              <1> 	; 06/11/2016 - TRDOS 386 (TRDOS v2.0) - temporary !-
 12913                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 12914                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
 12915                              <1> 	;
 12916                              <1> 	; Retro UNIX 8086 v1 modification:
 12917                              <1> 	; ! 'systell' does not work in original UNIX v1,
 12918                              <1> 	; 	    it returns with error !
 12919                              <1> 	; Inputs: r0 - file descriptor 
 12920                              <1> 	; Outputs: r0 - file r/w pointer
 12921                              <1> 
 12922                              <1> 	;xor	ecx, ecx ; 0
 12923 000107F8 BA01000000          <1> 	mov	edx, 1 ; 05/08/2013
 12924                              <1> 	;call 	seektell
 12925 000107FD E810000000          <1> 	call 	seektell0 ; 05/08/2013
 12926                              <1> 	;; 06/11/2016
 12927                              <1> 	;; mov	eax, [ebx]
 12928 00010802 A3[74940100]        <1> 	mov	[u.r0], eax
 12929 00010807 E948C6FFFF          <1> 	jmp	sysret
 12930                              <1> 
 12931                              <1> ; Original unix v1 'systell' system call:
 12932                              <1> 		; jsr r0,seektell
 12933                              <1> 		; br error4
 12934                              <1> 
 12935                              <1> seektell:
 12936                              <1> 	; 06/11/2016 - TRDOS 386 (TRDOS v2.0)
 12937                              <1> 	; 03/01/2016
 12938                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 12939                              <1> 	; 07/07/2013 - 05/08/2013 (Retro UNIX 8086 v1)
 12940                              <1> 	;
 12941                              <1> 	; 'seektell' puts the arguments from sysseek and systell
 12942                              <1> 	; call in u.base and u.count. It then gets the i-number of
 12943                              <1> 	; the file from the file descriptor in u.r0 and by calling
 12944                              <1> 	; getf. The i-node is brought into core and then u.count
 12945                              <1> 	; is checked to see it is a 0, 1, or 2.
 12946                              <1> 	; If it is 0 - u.count stays the same
 12947                              <1> 	;          1 - u.count = offset (u.fofp)
 12948                              <1> 	;	   2 - u.count = i.size (size of file)
 12949                              <1> 	;
 12950                              <1> 	; !! Retro UNIX 8086 v1 modification:
 12951                              <1> 	;	Argument 1, file descriptor is in BX;
 12952                              <1> 	;	Argument 2, offset is in CX;
 12953                              <1> 	;	Argument 3, ptrname/switch is in DX register.
 12954                              <1> 	;
 12955                              <1> 	; ((Return -> eax = base for offset (position= base+offset))
 12956                              <1> 	;
 12957 0001080C 890D[98940100]      <1> 	mov 	[u.base], ecx ; offset
 12958                              <1> seektell0:
 12959 00010812 8915[9C940100]      <1> 	mov 	[u.count], edx
 12960                              <1> 	; EBX = file descriptor (file number)
 12961 00010818 E8E4FEFFFF          <1> 	call	getf1
 12962                              <1> 	; EAX = First cluster of the file
 12963                              <1> 	; EBX = File number (Open file number)
 12964                              <1> 	; [u.fofp] = Pointer to File pointer
 12965                              <1> 	; [i.size] = File size
 12966                              <1> 
 12967 0001081D 09C0                <1> 	or	eax, eax
 12968 0001081F 7514                <1> 	jnz	short seektell1
 12969                              <1> 
 12970 00010821 B80A000000          <1> 	mov	eax, ERR_FILE_NOT_OPEN
 12971 00010826 A3[74940100]        <1> 	mov	[u.r0], eax 
 12972 0001082B A3[E0940100]        <1> 	mov	dword [u.error], eax ; 'file not open !'
 12973 00010830 E9FFC5FFFF          <1> 	jmp	error
 12974                              <1> 
 12975                              <1> seektell1:
 12976 00010835 8B1D[88940100]      <1>         mov     ebx, [u.fofp]
 12977 0001083B 803D[9C940100]01    <1> 	cmp	byte [u.count], 1
 12978 00010842 7705                <1> 	ja	short seektell2
 12979 00010844 7409                <1> 	je	short seektell3
 12980 00010846 31C0                <1> 	xor	eax, eax
 12981 00010848 C3                  <1> 	retn
 12982                              <1> 
 12983                              <1> seektell2:
 12984 00010849 A1[80950100]        <1>         mov   	eax, [i.size]
 12985 0001084E C3                  <1> 	retn
 12986                              <1> 
 12987                              <1> seektell3:
 12988 0001084F 8B03                <1> 	mov	eax, [ebx]
 12989 00010851 C3                  <1> 	retn
 12990                              <1> 
 12991                              <1> sysintr: ; / set interrupt handling
 12992                              <1> 	; 21/08/2024 - TRDOS 386 v2.0.9 modification
 12993                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 12994                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
 12995                              <1> 	;
 12996                              <1> 	; 'sysintr' sets the interrupt handling value. It puts
 12997                              <1> 	; argument of its call in u.intr then branches into 'sysquit'
 12998                              <1> 	; routine. u.tty is checked if to see if a control tty exists.
 12999                              <1> 	; If one does the interrupt character in the tty buffer is
 13000                              <1> 	; cleared and 'sysret'is called. If one does not exits
 13001                              <1> 	; 'sysret' is just called.
 13002                              <1> 	;
 13003                              <1> 	; Calling sequence:
 13004                              <1> 	;	sysintr; arg
 13005                              <1> 	; Argument:
 13006                              <1> 	;	arg - if 0, interrupts (ASCII DELETE) are ignored.
 13007                              <1> 	;	    - if 1, interrupts cause their normal result
 13008                              <1> 	;		 i.e force an exit.
 13009                              <1> 	;	    - if arg is a location within the program,
 13010                              <1> 	;		control is passed to that location when
 13011                              <1> 	;		an interrupt occurs.
 13012                              <1> 	; Inputs: -
 13013                              <1> 	; Outputs: -
 13014                              <1> 	; ...............................................................
 13015                              <1> 	;	
 13016                              <1> 	; Retro UNIX 8086 v1 modification: 
 13017                              <1> 	;       'sysintr' system call sets u.intr to value of BX
 13018                              <1> 	;	then branches into sysquit.
 13019                              <1> 
 13020                              <1> 	; 21/08/2024 - TRDOS 386
 13021                              <1> 	; enable/disable terminate (CTRL+BREAK) interrupt 
 13022                              <1> 	;
 13023                              <1> 	; INPUT:
 13024                              <1> 	;	bx = 0 -> disable CTRL+BREAK
 13025                              <1> 	;		-u.intr will be set to 0, u.quit will be ignored-
 13026                              <1> 	;	bx > 0 -> enable CTRL+BREAK (also default at start)
 13027                              <1> 	;		-u.intr will be set to 0FFFFh, u.quit will be used-
 13028                              <1> 	;	NOTE: u.quit is flag for CTRL+BREAK key press status
 13029                              <1> 	;	      -1 = pressed -termination request-, 0 = not pressed 
 13030                              <1> 	; OUTPUT:
 13031                              <1> 	;	none
 13032                              <1> 
 13033                              <1> 	;;;
 13034                              <1> 	; 21/08/2024
 13035 00010852 F7C3FFFF0000        <1> 	test	ebx, 0FFFFh
 13036 00010858 7403                <1> 	jz	short sysintr_@ ; 0
 13037                              <1> 	;mov	bx, 0FFFFh
 13038 0001085A 31DB                <1> 	xor	ebx, ebx
 13039 0001085C 4B                  <1> 	dec	ebx ; -1
 13040                              <1> sysintr_@:
 13041                              <1> 	;;;
 13042 0001085D 66891D[C0940100]    <1> 	mov	[u.intr], bx
 13043                              <1> 		; jsr r0,arg; u.intr / put the argument in u.intr
 13044                              <1> 		; br 1f / go into quit routine
 13045 00010864 E9EBC5FFFF          <1> 	jmp	sysret
 13046                              <1> 
 13047                              <1> sysquit:
 13048                              <1> 	; 21/08/2024 - TRDOS 386 v2.0.9 modification
 13049                              <1> 	;	get/reset QUIT (u.quit) status
 13050                              <1> 	;
 13051                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 13052                              <1> 	; 07/07/2013 (Retro UNIX 8086 v1)
 13053                              <1> 	;
 13054                              <1> 	; 'sysquit' turns off the quit signal. it puts the argument of
 13055                              <1> 	; the call in u.quit. u.tty is checked if to see if a control 
 13056                              <1> 	; tty exists. If one does the interrupt character in the tty
 13057                              <1> 	; buffer is cleared and 'sysret'is called. If one does not exits
 13058                              <1> 	; 'sysret' is just called.
 13059                              <1> 	;
 13060                              <1> 	; Calling sequence:
 13061                              <1> 	;	sysquit; arg
 13062                              <1> 	; Argument:
 13063                              <1> 	;	arg - if 0, this call diables quit signals from the
 13064                              <1> 	;		typewriter (ASCII FS)
 13065                              <1> 	;	    - if 1, quits are re-enabled and cause execution to
 13066                              <1> 	;		cease and a core image to be produced.
 13067                              <1> 	;		 i.e force an exit.
 13068                              <1> 	;	    - if arg is an addres in the program,
 13069                              <1> 	;		a quit causes control to sent to that
 13070                              <1> 	;		location.
 13071                              <1> 	; Inputs: -
 13072                              <1> 	; Outputs: -
 13073                              <1> 	; ...............................................................
 13074                              <1> 	;	
 13075                              <1> 	; Retro UNIX 8086 v1 modification: 
 13076                              <1> 	;       'sysquit' system call sets u.quit to value of BX
 13077                              <1> 	;	then branches into 'sysret'.
 13078                              <1> 
 13079                              <1> 	; 21/08/2024
 13080                              <1> 	;mov	[u.quit], bx
 13081                              <1> 	;jmp	sysret
 13082                              <1> 		; jsr r0,arg; u.quit / put argument in u.quit
 13083                              <1> 	;1:
 13084                              <1> 		; mov u.ttyp,r1 / move pointer to control tty buffer
 13085                              <1> 			      ; / to r1
 13086                              <1> 		; beq sysret4 / return to user
 13087                              <1> 		; clrb 6(r1) / clear the interrupt character
 13088                              <1> 			   ; / in the tty buffer
 13089                              <1> 		; br sysret4 / return to user
 13090                              <1> 
 13091                              <1> 	; 21/08/2024 - TRDOS 386
 13092                              <1> 	; get/reset QUIT (u.quit) status
 13093                              <1> 	;
 13094                              <1> 	; INPUT:
 13095                              <1> 	;	none
 13096                              <1> 	; OUTPUT:
 13097                              <1> 	;	eax = 0 -> no CTRL+BREAK
 13098                              <1> 	;	eax = -1 -> CTRL+BREAK status (but not applied)
 13099                              <1> 	;		-u.intr may be 0-
 13100                              <1> 	;	NOTE: u.quit will be reset to 0
 13101                              <1> 
 13102 00010869 31C0                <1> 	xor	eax, eax ; 0
 13103 0001086B 663905[C2940100]    <1> 	cmp	[u.quit], ax
 13104 00010872 7407                <1> 	jz	short sysquit_@ ; already 0
 13105 00010874 66A3[C2940100]      <1> 	mov	[u.quit], ax ; 0 ; reset
 13106 0001087A 48                  <1> 	dec	eax ; -1
 13107                              <1> sysquit_@:
 13108 0001087B A3[74940100]        <1> 	mov	[u.r0], eax
 13109 00010880 E9CFC5FFFF          <1> 	jmp	sysret	
 13110                              <1> 
 13111                              <1> %if 0
 13112                              <1> 
 13113                              <1> anyi: 
 13114                              <1> 	; 23/07/2022
 13115                              <1> 	; 06/10/2016 (TRDOS 386 = TRDOS v2.0)
 13116                              <1> 	; Major Modification!
 13117                              <1> 	; TRDOS 386 does not permit to delete a file while it is open 
 13118                              <1> 	; The role of 'anyi' procedure has beeen changed to ensure that.
 13119                              <1> 	; 	
 13120                              <1> 	; 22/06/2015 (Retro UNIX 386 v1 - Beginning)
 13121                              <1> 	; 25/04/2013 (Retro UNIX 8086 v1)
 13122                              <1> 	;
 13123                              <1> 	; 'anyi' is called if a file deleted while open.
 13124                              <1> 	; "anyi" checks to see if someone else has opened this file.
 13125                              <1> 	;
 13126                              <1> 	; INPUTS ->
 13127                              <1> 	;    r1 - contains an i-number
 13128                              <1> 	;    fsp - start of table containing open files
 13129                              <1> 	;
 13130                              <1> 	; OUTPUTS ->
 13131                              <1> 	;    "deleted" flag set in fsp entry of another occurrence of
 13132                              <1> 	;	   this file and r2 points 1st word of this fsp entry.
 13133                              <1> 	;    if file not found - bit in i-node map is cleared
 13134                              <1> 	;    			 (i-node is freed)
 13135                              <1> 	;               all blocks related to i-node are freed
 13136                              <1> 	;	        all flags in i-node are cleared
 13137                              <1> 	; ((AX = R1)) input
 13138                              <1> 	;
 13139                              <1> 	;    (Retro UNIX Prototype : 02/12/2012, UNIXCOPY.ASM)
 13140                              <1>         ;    ((Modified registers: EDX, ECX, EBX, ESI, EDI, EBP))
 13141                              <1> 	;
 13142                              <1> 	; / r1 contains an i-number
 13143                              <1> 
 13144                              <1> 	; TRDOS 386 (06/10/2016)
 13145                              <1> 	; 
 13146                              <1> 	; INPUT:
 13147                              <1> 	;	EAX = First Cluster
 13148                              <1> 	;	 DL = Logical DOS Drive Number
 13149                              <1> 	;
 13150                              <1> 	; OUTPUT:
 13151                              <1> 	;	CF = 1 -> EBX = File Handle/Number/Index
 13152                              <1> 	;	CF = 0 -> EBX = 0
 13153                              <1> 	;
 13154                              <1> 	; Modified Registers: EBX
 13155                              <1> 
 13156                              <1> 	xor	ebx, ebx
 13157                              <1> anyi_0: 
 13158                              <1> 	cmp	byte [ebx+OF_MODE], 0 ; 0 = empty entry
 13159                              <1> 	ja	short anyi_2 ; 1 (r), 2 (w) or 3 (r&w)
 13160                              <1> anyi_1:
 13161                              <1> 	inc	bl
 13162                              <1> 	cmp	bl, OPENFILES ; max. count of open files
 13163                              <1> 	jb	short anyi_0
 13164                              <1> 	xor	eax, eax
 13165                              <1> 	retn 
 13166                              <1> anyi_2:
 13167                              <1> 	cmp	dl, [ebx+OF_DRIVE]
 13168                              <1> 	jne	short anyi_1
 13169                              <1> 	;shl	bx, 2 ; *4 (dword offset)
 13170                              <1> 	shl	ebx, 2 ; 23/07/2022
 13171                              <1> 	cmp	eax, [ebx+OF_FCLUSTER]
 13172                              <1> 	je	short anyi_3
 13173                              <1> 	;shr	bx, 2 ; /4 (byte offset)
 13174                              <1> 	shr	ebx, 2 ; 23/07/2022
 13175                              <1> 	jmp	short anyi_1 	
 13176                              <1> anyi_3:
 13177                              <1> 	;shr	bx, 2 ; /4 (bytes offset) (index)
 13178                              <1> 	shr	ebx, 2 ; 23/07/2022
 13179                              <1> 	stc
 13180                              <1> 	retn
 13181                              <1> 
 13182                              <1> %endif
 13183                              <1> 
 13184                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - SYS9.INC
 13185                              <1> ; Last Modification: 09/12/2015
 13186                              <1> 
 13187                              <1> syssleep:
 13188                              <1> 	; 28/08/2024 - TRDOS 386 v2.0.9
 13189                              <1> 	; 24/07/2022 - TRDOS 386 v2.0.5
 13190                              <1> 	; 29/06/2015 - (Retro UNIX 386 v1)
 13191                              <1> 	; 11/06/2014 - (Retro UNIX 8086 v1)
 13192                              <1> 	;
 13193                              <1> 	; Retro UNIX 8086 v1 feature only
 13194                              <1> 	; (INPUT -> none)
 13195                              <1> 	
 13196                              <1> 	; Temporary - 24/07/2022
 13197 00010885 891D[74940100]      <1> 	mov	[u.r0], ebx
 13198                              <1> 	;
 13199 0001088B 0FB61D[C5940100]    <1> 	movzx	ebx, byte [u.uno] ; process number
 13200 00010892 8AA3[87930100]      <1> 	mov	ah, [ebx+p.ttyc-1] ; current/console tty
 13201 00010898 E853170000          <1> 	call	sleep
 13202                              <1> 
 13203                              <1> 	; 23/08/2024 - restore [u.usp]
 13204                              <1> 	; swap changes [u.usp] to esp which points to
 13205                              <1> 	; return of sleep
 13206 0001089D 8925[70940100]      <1> 	mov	[u.usp], esp
 13207                              <1> 		; points to user's regs on top ofn system stack
 13208                              <1> 
 13209                              <1> 	; 24/07/2022
 13210 000108A3 FF05[74940100]      <1> 	inc	dword [u.r0] ; Temporary !
 13211 000108A9 E9A6C5FFFF          <1> 	jmp	sysret
 13212                              <1> 
 13213                              <1> _vp_clr:
 13214                              <1> 	; Reset/Clear Video Page
 13215                              <1> 	;
 13216                              <1> 	; 24/07/2022 - TRDOS 386 v2.0.5
 13217                              <1> 	; 30/06/2015 - (Retro UNIX 386 v1)
 13218                              <1> 	; 21/05/2013 - 30/10/2013(Retro UNIX 8086 v1) (U0.ASM)
 13219                              <1> 	;
 13220                              <1> 	; Retro UNIX 8086 v1 feature only !
 13221                              <1> 	;
 13222                              <1> 	; INPUTS -> 
 13223                              <1> 	;   BH = video page number
 13224                              <1> 	;
 13225                              <1> 	; OUTPUT ->
 13226                              <1> 	;   none
 13227                              <1> 	; ((Modified registers: EAX, BH, ECX, EDX, ESI, EDI))
 13228                              <1> 	;
 13229                              <1> 	; 04/12/2013
 13230 000108AE 28C0                <1> 	sub	al, al
 13231                              <1> 	; al = 0 (clear video page)
 13232                              <1> 	; bh = video page ; 13/05/2016
 13233 000108B0 B407                <1> 	mov	ah, 07h
 13234                              <1> 	; ah = 7 (attribute/color)
 13235                              <1> 	;xor 	cx, cx ; 0, left upper column (cl) & row (cl)
 13236                              <1> 	;mov	dx, 184Fh ; right lower column & row (dl=24, dh=79)
 13237                              <1> 	; 24/07/2022
 13238 000108B2 31C9                <1> 	xor	ecx, ecx
 13239 000108B4 BA4F180000          <1> 	mov	edx, 184Fh
 13240 000108B9 E82917FFFF          <1> 	call	_scroll_up
 13241                              <1> 	; bh = video page
 13242                              <1> 	;xor	dx, dx ; 0 (cursor position)
 13243                              <1> 	; 24/07/2022
 13244 000108BE 31D2                <1> 	xor	edx, edx
 13245 000108C0 E9681AFFFF          <1> 	jmp 	_set_cpos
 13246                              <1> 
 13247                              <1> sysmsg:
 13248                              <1> 	; 28/08/2024 - TRDOS 386 v2.0.9
 13249                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
 13250                              <1> 	; 07/12/2020
 13251                              <1> 	; 05/12/2020
 13252                              <1> 	; 13/05/2016
 13253                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
 13254                              <1> 	; 01/07/2015 - 11/11/2015 (Retro UNIX 386 v1)
 13255                              <1> 	; Print user-application message on user's console tty
 13256                              <1> 	;
 13257                              <1> 	; Input -> EBX = Message address
 13258                              <1> 	;	   ECX = Message length (max. 255)
 13259                              <1> 	;	   DL = Color (IBM PC Rombios color attributes)
 13260                              <1> 	;
 13261 000108C5 81F9FF000000        <1> 	cmp	ecx, MAX_MSG_LEN ; 255
 13262                              <1> 	;ja	sysret ; nothing to do with big message size
 13263                              <1> 	; 23/07/2022
 13264 000108CB 7605                <1> 	jna	short sysmsg8
 13265                              <1> sysmsg7:
 13266 000108CD E982C5FFFF          <1> 	jmp	sysret
 13267                              <1> sysmsg8:	; 23/07/2022
 13268 000108D2 08C9                <1> 	or	cl, cl
 13269                              <1> 	;jz	sysret
 13270                              <1> 	; 23/07/2022
 13271 000108D4 74F7                <1> 	jz	short sysmsg7
 13272 000108D6 20D2                <1> 	and	dl, dl
 13273 000108D8 7502                <1> 	jnz	short sysmsg0
 13274 000108DA B207                <1> 	mov	dl, 07h ; default color
 13275                              <1> 		; (black background, light gray character)
 13276                              <1> sysmsg0:
 13277 000108DC 891D[98940100]      <1> 	mov	[u.base], ebx
 13278 000108E2 8815[EF7C0100]      <1> 	mov	[ccolor], dl ; color attributes
 13279 000108E8 89E5                <1> 	mov	ebp, esp ; save stack pointer
 13280 000108EA 31DB                <1> 	xor	ebx, ebx ; 0
 13281 000108EC 891D[A0940100]      <1> 	mov	[u.nread], ebx ; 0
 13282                              <1> 	;
 13283 000108F2 381D[DA940100]      <1> 	cmp	[u.kcall], bl ; 0
 13284 000108F8 7770                <1> 	ja	short sysmsgk ; Temporary (01/07/2015)
 13285                              <1> 	;
 13286 000108FA 890D[9C940100]      <1> 	mov	[u.count], ecx
 13287                              <1> 	;inc	ecx ; + 00h ; ASCIIZ
 13288                              <1> 	;
 13289                              <1> 	; 07/12/2020
 13290                              <1> 	;add	ecx, 3
 13291 00010900 6683C103            <1> 	add	cx, 3
 13292 00010904 80E1FC              <1> 	and	cl, ~3  ; not 3
 13293                              <1> 	;
 13294                              <1> 	;;;
 13295                              <1> 	; 20/08/2024
 13296                              <1> 	; for safety, against a possibility which if ecx+1
 13297                              <1> 	; chars (without a 0 in ecx chars) overs stack frame
 13298                              <1> 	; (for example 255 chars without 0, safe stack frame
 13299                              <1> 	; size is 260.)
 13300                              <1> 	; !!! 'sysmsg' will put a 0 at ecx+1 position.!!!
 13301 00010907 51                  <1> 	push	ecx
 13302                              <1> 	;;;
 13303                              <1> 	;
 13304 00010908 29CC                <1> 	sub	esp, ecx
 13305 0001090A 89E7                <1> 	mov	edi, esp
 13306 0001090C 89E6                <1> 	mov	esi, esp
 13307 0001090E 66891D[D8940100]    <1> 	mov	[u.pcount], bx ; reset page (phy. addr.) counter
 13308                              <1> 	; 11/11/2015
 13309 00010915 8A25[A8940100]      <1> 	mov 	ah, [u.ttyp] ; recent open tty
 13310                              <1> 	; 0 = none
 13311 0001091B FECC                <1> 	dec	ah
 13312 0001091D 790C                <1> 	jns	short sysmsg1
 13313 0001091F 8A1D[C5940100]      <1> 	mov	bl, [u.uno] ; process number
 13314 00010925 8AA3[87930100]      <1> 	mov	ah, [ebx+p.ttyc-1] ; user's (process's) console tty
 13315                              <1> sysmsg1:
 13316 0001092B 8825[AA940100]      <1> 	mov	[u.ttyn], ah
 13317                              <1> sysmsg2:
 13318 00010931 E8FB050000          <1> 	call	cpass
 13319 00010936 7416                <1> 	jz	short sysmsg5
 13320 00010938 AA                  <1> 	stosb
 13321 00010939 20C0                <1> 	and	al, al
 13322 0001093B 75F4                <1> 	jnz	short sysmsg2
 13323                              <1> sysmsg3:
 13324 0001093D 80FC07              <1> 	cmp	ah, 7 ; tty number
 13325 00010940 7711                <1> 	ja	short sysmsg6 ; serial port
 13326 00010942 E83E000000          <1> 	call	print_cmsg ; 05/12/2020
 13327                              <1> sysmsg4:
 13328 00010947 89EC                <1> 	mov	esp, ebp ; restore stack pointer
 13329 00010949 E906C5FFFF          <1> 	jmp	sysret
 13330                              <1> sysmsg5:
 13331 0001094E C60700              <1> 	mov	byte [edi], 0
 13332 00010951 EBEA                <1> 	jmp	short sysmsg3
 13333                              <1> sysmsg6:
 13334 00010953 8A06                <1> 	mov	al, [esi]
 13335 00010955 E896160000          <1> 	call	sndc
 13336 0001095A 72EB                <1> 	jc	short sysmsg4
 13337 0001095C 803E00              <1> 	cmp	byte [esi], 0  ; 0 is stop character
 13338 0001095F 76E6                <1> 	jna	short sysmsg4
 13339 00010961 46                  <1> 	inc 	esi
 13340 00010962 8A25[AA940100]      <1> 	mov	ah, [u.ttyn]
 13341 00010968 EBE9                <1> 	jmp	short sysmsg6
 13342                              <1> 
 13343                              <1> sysmsgk: ; Temporary (01/07/2015)
 13344                              <1> 	; The message has been sent by Kernel (ASCIIZ string)
 13345                              <1> 	; (ECX -character count- will not be considered)
 13346 0001096A 8B35[98940100]      <1> 	mov	esi, [u.base]
 13347 00010970 8A25[EE7C0100]      <1> 	mov	ah, [ptty] ; present/current screen (video page)
 13348 00010976 8825[AA940100]      <1> 	mov	[u.ttyn], ah
 13349 0001097C C605[DA940100]00    <1> 	mov	byte [u.kcall], 0
 13350 00010983 EBB8                <1> 	jmp	short sysmsg3
 13351                              <1> 
 13352                              <1> print_cmsg:
 13353                              <1> 	; 08/12/2020
 13354                              <1> 	; 07/12/2020
 13355                              <1> 	; 05/12/2020
 13356                              <1> 	; 18/11/2017
 13357                              <1> 	; 13/05/2016 - TRDOS 386 (TRDOS v2.0)
 13358                              <1> 	; 01/07/2015 (Retro UNIX 386 v1)
 13359                              <1> 	;
 13360                              <1> 	; print message (on user's console tty)
 13361                              <1> 	;	with requested color
 13362                              <1> 	;
 13363                              <1> 	; INPUTS:
 13364                              <1> 	;	esi = message address
 13365                              <1> 	;	[u.ttyn] = tty number (0 to 7)
 13366                              <1> 	;	[ccolor] = color attributes (IBM PC BIOS colors)
 13367                              <1> 	;
 13368                              <1> 	; Modified registers: eax, ebx, ecx, edx, esi, edi
 13369                              <1> 	; (ebp must be preserved)
 13370                              <1> 
 13371                              <1> 	;mov	bh, ah
 13372 00010985 8A3D[AA940100]      <1> 	mov	bh, [u.ttyn]
 13373 0001098B 8A1D[EF7C0100]      <1> 	mov	bl, [ccolor] ; * ; 05/12/2020
 13374                              <1> 
 13375                              <1> 	; 05/12/2020
 13376 00010991 803D[2CA30100]00    <1> 	cmp	byte [pmi32], 0 ; is vbios's 32 bit pmi enabled ?
 13377 00010998 772E                <1> 	ja	short pcmsg5 ; yes
 13378                              <1> pcmsg1:
 13379                              <1> 	; 08/12/2020
 13380 0001099A 8A1D[EF7C0100]      <1> 	mov	bl, [ccolor] ; * (video.s 'u11'&'beep' change BL)
 13381                              <1> 	
 13382 000109A0 AC                  <1> 	lodsb
 13383 000109A1 20C0                <1> 	and 	al, al  ; 0
 13384 000109A3 743A                <1> 	jz 	short pcmsg2
 13385                              <1> pcmsg7:
 13386 000109A5 56                  <1> 	push 	esi
 13387                              <1> 	;mov	bl, [ccolor] ; * (video.s 'u11'&'beep' change BL)
 13388                              <1> 	; 05/12/2020
 13389                              <1> 	;;mov	bh, [u.ttyn]
 13390                              <1> 	;call 	_write_tty
 13391                              <1> 	;pop	esi
 13392                              <1> 	;jmp	short pcmsg1
 13393                              <1> ;pcmsg2:
 13394                              <1> 	;retn
 13395                              <1> 
 13396                              <1> 	; 07/12/2020
 13397 000109A6 803D[DE670000]03    <1> 	cmp     byte [CRT_MODE], 3
 13398 000109AD 7708                <1> 	ja 	short pcmsg4
 13399                              <1> pcmsg3:
 13400 000109AF E8F418FFFF          <1> 	call	_write_tty_m3
 13401 000109B4 5E                  <1> 	pop	esi
 13402 000109B5 EBE3                <1> 	jmp	short pcmsg1
 13403                              <1> pcmsg4:
 13404 000109B7 803D[DE670000]07    <1>         cmp     byte [CRT_MODE], 7
 13405 000109BE 76EF                <1> 	jna 	short pcmsg3
 13406 000109C0 E8AC25FFFF          <1> 	call	vga_write_teletype
 13407 000109C5 5E                  <1> 	pop	esi
 13408 000109C6 EBD2                <1> 	jmp	short pcmsg1
 13409                              <1> pcmsg5:
 13410                              <1> 	; 07/12/2020
 13411 000109C8 803D[DE670000]07    <1>         cmp     byte [CRT_MODE], 7
 13412 000109CF 76C9                <1> 	jna 	short pcmsg1
 13413                              <1> 
 13414                              <1> 	; 05/12/2020
 13415                              <1> 	; writing message by using
 13416                              <1> 	; VESA VBE3 video bios protected mode interface
 13417                              <1> 	
 13418 000109D1 B40E                <1> 	mov	ah, 0Eh
 13419                              <1> pcmsg6:
 13420 000109D3 AC                  <1> 	lodsb
 13421 000109D4 20C0                <1> 	and 	al, al  ; 0
 13422 000109D6 7407                <1> 	jz 	short pcmsg2
 13423                              <1> 	; bh = video page
 13424                              <1> 	; ah = 0Eh 
 13425                              <1> 	; al = character
 13426                              <1> 	; bl = color
 13427 000109D8 E80C10FFFF          <1> 	call	int10h_32bit_pmi
 13428 000109DD EBF4                <1> 	jmp	short pcmsg6
 13429                              <1> pcmsg2:
 13430 000109DF C3                  <1> 	retn
 13431                              <1> 
 13432                              <1> sysgeterr:
 13433                              <1> 	; 09/12/2015
 13434                              <1> 	; 21/09/2015 - (Retro UNIX 386 v1 feature only!)
 13435                              <1> 	; Get last error number or page fault count
 13436                              <1> 	; (for debugging)
 13437                              <1> 	;
 13438                              <1> 	; Input -> EBX = return type
 13439                              <1> 	;	   0 = last error code (which is in 'u.error')
 13440                              <1> 	;	   FFFFFFFFh = page fault count for running process
 13441                              <1> 	;	   FFFFFFFEh = total page fault count
 13442                              <1> 	;	   1 .. FFFFFFFDh = undefined 
 13443                              <1> 	;
 13444                              <1> 	; Output -> EAX = last error number or page fault count
 13445                              <1> 	;	   (depending on EBX input)
 13446                              <1> 	;
 13447 000109E0 21DB                <1> 	and 	ebx, ebx
 13448 000109E2 750B                <1> 	jnz	short glerr_2
 13449                              <1> glerr_0:
 13450 000109E4 A1[E0940100]        <1> 	mov	eax, [u.error]
 13451                              <1> glerr_1:
 13452 000109E9 A3[74940100]        <1> 	mov	[u.r0], eax
 13453 000109EE C3                  <1>  	retn
 13454                              <1> glerr_2:
 13455 000109EF 43                  <1> 	inc	ebx ; FFFFFFFFh -> 0, FFFFFFFEh -> FFFFFFFFh
 13456 000109F0 74FD                <1> 	jz	short glerr_2 ; page fault count for process
 13457 000109F2 43                  <1> 	inc	ebx ; FFFFFFFFh -> 0	
 13458 000109F3 75EF                <1> 	jnz	short glerr_0
 13459 000109F5 A1[90960100]        <1> 	mov	eax, [PF_Count] ; total page fault count
 13460 000109FA EBED                <1>         jmp     short glerr_1
 13461                              <1> glerr_3:
 13462 000109FC A1[E4940100]        <1> 	mov 	eax, [u.pfcount]
 13463 00010A01 EBE6                <1> 	jmp	short glerr_1
 13464                              <1> 
 13465                              <1> load_and_run_file:
 13466                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
 13467                              <1> 	; 18/11/2017
 13468                              <1> 	; 22/01/2017
 13469                              <1> 	; 04/01/2017 - 07/01/2017
 13470                              <1> 	; 24/10/2016
 13471                              <1> 	; 24/04/2016 - 02/05/2016 - 03/05/2016 - 06/05/2016
 13472                              <1> 	; 23/04/2016 (TRDOS 386 = TRDOS v2.0)
 13473                              <1> 	; 23/10/2015 (Retro UNIX 386 v1, 'sysexec')
 13474                              <1> 	; 23/06/2015 (Retro UNIX 386 v1 - Beginning)
 13475                              <1> 	; 03/06/2013 - 06/12/2013 (Retro UNIX 8086 v1)
 13476                              <1> 	; EAX = First Cluster number
 13477                              <1> 	; EDX = File Size
 13478                              <1> 	; ESI = Argument list address
 13479                              <1> 	; [argc] = argument count
 13480                              <1> 	; [u.nread] = argument list length
 13481                              <1> 	; [esp] = return address to the caller (*)
 13482                              <1> 	;
 13483 00010A03 8935[74950100]      <1> 	mov	[argv], esi
 13484 00010A09 8915[80950100]      <1> 	mov	[i.size], edx
 13485 00010A0F A3[7C950100]        <1> 	mov	[ii], eax
 13486                              <1> 
 13487                              <1> 	;sti	; 07/01/2017
 13488                              <1> 	;mov	eax, [k_page_dir]
 13489                              <1> 	;mov	[u.pgdir], eax
 13490 00010A14 31C0                <1> 	xor 	eax, eax ; clc ; *** ; 04/01/2017
 13491                              <1> 	;mov	[u.r0], eax ; 0 ; 07/01/2017
 13492                              <1> 
 13493                              <1> 	; 06/05/2016
 13494                              <1> 	; Set 'sysexit' return order to MainProg
 13495                              <1> 	;
 13496 00010A16 58                  <1> 	pop	eax ; * 'loc_load_and_run_file_8:' address
 13497                              <1> 	;; 22/01/2017
 13498                              <1> 	;;cli ; 07/01/2017
 13499 00010A17 8B25[5C7C0100]      <1> 	mov	esp, [tss.esp0]
 13500                              <1> 	;
 13501                              <1> 	; 'loc_load_run_file_8' address has 
 13502                              <1> 	; 'jmp loc_file_rw_restore_retn' instruction
 13503                              <1> 	; 'loc_file_rw_restore_retn:' will return to
 13504                              <1> 	; [mainprog_return_addr] 
 13505                              <1> 	; just after 'call command_interpreter'
 13506                              <1> 	;
 13507 00010A1D 68[486D0000]        <1> 	push	_end_of_mainprog ; we must not return to here !
 13508 00010A22 FF35[3C890100]      <1> 	push	dword [mainprog_return_addr]
 13509 00010A28 89E5                <1> 	mov	ebp, esp ; **
 13510                              <1> 	;	
 13511 00010A2A 9C                  <1> 	pushfd  ; EFLAGS      ; IRETD ; ***
 13512 00010A2B 6A08                <1> 	push	KCODE ; cs    ; IRETD
 13513 00010A2D 50                  <1> 	push	eax ; * (eip) ; IRETD
 13514 00010A2E 8925[6C940100]      <1> 	mov	[u.sp], esp
 13515                              <1> 	;mov	byte [u.quant], time_count
 13516 00010A34 1E                  <1> 	push	ds
 13517 00010A35 06                  <1> 	push	es
 13518 00010A36 0FA0                <1> 	push	fs
 13519 00010A38 0FA8                <1> 	push	gs
 13520                              <1> 	;mov	eax, [u.r0]
 13521 00010A3A 29C0                <1> 	sub	eax, eax
 13522 00010A3C 60                  <1> 	pushad
 13523 00010A3D 68[54CE0000]        <1> 	push	sysret
 13524                              <1> 	;push	sysrel1 ; 07/01/2017
 13525 00010A42 8925[70940100]      <1> 	mov	[u.usp], esp
 13526                              <1> 	;
 13527 00010A48 E8FF030000          <1> 	call	wswap ; Save MainProg (process 1) 'u' structure
 13528                              <1> 		      ; and registers for return (from program)	
 13529 00010A4D 89EC                <1> 	mov	esp, ebp ; **
 13530                              <1> 	;;22/01/2017
 13531                              <1> 	;;sti ; 07/01/2017
 13532                              <1> 	; 23/07/2022
 13533                              <1> 	;push	eax  ; * 'loc_load_and_run_file_8:' address
 13534                              <1> 	;
 13535                              <1> 	;;; 02/05/2016
 13536                              <1> 	;;; Create a new process (parent: MainProg)
 13537 00010A4F 31F6                <1> 	xor 	esi, esi
 13538                              <1> cnpm_1: ; search p.stat table for unused process number
 13539 00010A51 46                  <1> 	inc	esi
 13540 00010A52 80BE[A7930100]00    <1> 	cmp	byte [esi+p.stat-1], 0 ; SFREE
 13541                              <1> 				; is process active, unused, dead
 13542 00010A59 760B                <1> 	jna	short cnpm_2	; it's unused so branch
 13543 00010A5B 6683FE10            <1> 	cmp	si, nproc 	; all processes checked
 13544 00010A5F 72F0                <1> 	jb	short cnpm_1    ; no, branch back
 13545                              <1> cnpm_panic:
 13546 00010A61 E96363FFFF          <1> 	jmp	panic 
 13547                              <1> cnpm_2:
 13548 00010A66 A1[CC940100]        <1> 	mov	eax, [u.pgdir] ; page directory of MainProg
 13549 00010A6B A3[D0940100]        <1> 	mov	[u.ppgdir], eax ; parent's page directory
 13550 00010A70 E86B4DFFFF          <1> 	call	allocate_page
 13551                              <1> 	;jc	panic
 13552                              <1> 	; 23/07/2022
 13553 00010A75 72EA                <1> 	jc	short cnpm_panic
 13554                              <1> 	
 13555                              <1> 	; EAX = UPAGE (user structure page) address
 13556 00010A77 A3[C8940100]        <1> 	mov	[u.upage], eax ; memory page for 'user' struct (child)
 13557 00010A7C 89F7                <1> 	mov	edi, esi
 13558                              <1> 	;shl	di, 2
 13559                              <1> 	; 23/07/2022
 13560 00010A7E C1E702              <1> 	shl	edi, 2
 13561 00010A81 8987[B4930100]      <1> 	mov	[edi+p.upage-4], eax ; memory page for 'user' struct
 13562 00010A87 E8C54DFFFF          <1> 	call	clear_page ; 03/05/2016
 13563                              <1> 	;;movzx	eax, byte [p.ttyc] ; console tty (for MainProg)
 13564                              <1> 	;sub	ax, ax ; 0
 13565                              <1> 	; 23/07/2022
 13566 00010A8C 29C0                <1> 	sub	eax, eax
 13567 00010A8E 668986[87930100]    <1> 	mov     [esi+p.ttyc-1], ax ; al - set child's console tty
 13568                              <1> 				   ; ah - reset child's wait channel
 13569 00010A95 66A3[A8940100]      <1> 	mov 	[u.ttyp], ax ; 0
 13570                              <1> 	
 13571 00010A9B 89F2                <1> 	mov	edx, esi
 13572 00010A9D 8815[C5940100]      <1> 	mov	[u.uno], dl ; child process number
 13573 00010AA3 FE86[A7930100]      <1>         inc     byte [esi+p.stat-1] ; 1, SRUN
 13574                              <1> 	;shl	si, 1 ; multiply si by 2 to get index into p.pid table
 13575                              <1> 	; 23/07/2022
 13576 00010AA9 D1E6                <1> 	shl	esi, 1
 13577 00010AAB 66FF05[5C940100]    <1> 	inc	word [mpid] ; increment m.pid; get a new process name
 13578                              <1> 
 13579                              <1> 	; 23/07/2022	
 13580                              <1> 	;mov	ax, [p.pid]  ; get process name of MainProg
 13581                              <1> 	;mov	ax, 1
 13582 00010AB2 FEC0                <1> 	inc	al ; eax = 1
 13583 00010AB4 668986[66930100]    <1> 	mov	[esi+p.ppid-2], ax ; put parent process name 
 13584                              <1> 			           ; in parent process slot for child
 13585 00010ABB A2[BE940100]        <1> 	mov	[u.pri], al ; 1	; normal priority
 13586                              <1> 	
 13587                              <1> 	;dec	ax ; 0
 13588                              <1> 	;mov 	[u.ttyp], ax ; 0
 13589                              <1> 
 13590 00010AC0 66A1[5C940100]      <1> 	mov	ax, [mpid]
 13591 00010AC6 668986[46930100]    <1> 	mov	[esi+p.pid-2], ax ; put new process name 
 13592                              <1> 				  ; in child process' name slot
 13593                              <1> 	;;;
 13594 00010ACD A1[7C950100]        <1> 	mov 	eax, [ii]
 13595                              <1> 	; 23/07/2022
 13596                              <1> 	; Retro UNIX 386 v1, 'sysexec' (u2.s)
 13597                              <1> 	;call	iopen
 13598                              <1> 	; 06/06/2016
 13599                              <1> 	;mov	byte [u.pri], 1 ; normal priority
 13600                              <1> 	;
 13601                              <1> 	;jmp	short sysexec_7 ; 02/05/2016
 13602                              <1> 	; 23/07/2022
 13603 00010AD2 E923F9FFFF          <1> 	jmp	sysexec_7
 13604                              <1> 
 13605                              <1> ;	; 02/05/2016
 13606                              <1> ;	;inc	byte [sysflg] ; 0FFh -> 0
 13607                              <1> ;	;mov	byte [sysflg], 0 ; 04/01/2017
 13608                              <1> ;	movzx	ebx, byte [u.uno]
 13609                              <1> ;	shl	bl, 1 ; 13/11/2017
 13610                              <1> ;	cmp	word [ebx+p.ppid-2], 1 ; MainProg
 13611                              <1> ;	ja	sysret0 ; 03/05/2016
 13612                              <1> ;	push	sysret ; * 
 13613                              <1> ;	mov	[u.usp], esp
 13614                              <1> ;	call	wswap ; save child process 'u' structure and
 13615                              <1> ;		      ; registers
 13616                              <1> ;	add	dword [u.usp], 4 ; 03/05/2016 
 13617                              <1> ;sysexec_19: ; 02/05/2016
 13618                              <1> ;	retn ; * 'sysret' ; byte [sysflg] -> 0FFh
 13619                              <1> 
 13620                              <1> readi:
 13621                              <1> 	; 09/08/2022
 13622                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
 13623                              <1> 	; 01/05/2016
 13624                              <1> 	; 25/04/2016 - TRDOS 386 (TRDOS v2.0)
 13625                              <1> 	; 20/05/2015 - Retro UNIX 386 v1
 13626                              <1> 	; 11/03/2013 - 31/07/2013 (Retro UNIX 8086 v1)
 13627                              <1> 	;
 13628                              <1> 	; Reads from a file whose the first cluster number in EAX
 13629                              <1> 	; 
 13630                              <1> 	; INPUTS ->
 13631                              <1> 	;    EAX - First cluster number of the file
 13632                              <1> 	;    u.count - byte count user desires
 13633                              <1> 	;    u.base - points to user buffer
 13634                              <1> 	;    u.fofp - points to dword with current file offset
 13635                              <1> 	;    i.size - file size
 13636                              <1> 	;    cdev - logical dos drive number of the file
 13637                              <1> 	; OUTPUTS ->
 13638                              <1> 	;    u.count - cleared
 13639                              <1> 	;    u.nread - accumulates total bytes passed back
 13640                              <1> 	;
 13641                              <1> 	; ((EAX)) input/output
 13642                              <1> 	; (Retro UNIX Prototype : 14/12/2012 - 01/03/2013, UNIXCOPY.ASM)
 13643                              <1>         ; ((Modified registers: edx, ebx, ecx, esi, edi))
 13644                              <1> 
 13645 00010AD7 31D2                <1> 	xor	edx, edx ; 0
 13646 00010AD9 8915[A0940100]      <1> 	mov 	[u.nread], edx ; 0
 13647 00010ADF 668915[D8940100]    <1> 	mov	[u.pcount], dx ; 19/05/2015
 13648 00010AE6 3915[9C940100]      <1> 	cmp 	[u.count], edx ; 0
 13649                              <1> 	;ja 	short readi_1
 13650                              <1> 	;retn
 13651                              <1> 	; 09/08/2022
 13652 00010AEC 765E                <1> 	jna	short dskr_5 ; retn
 13653                              <1> ;readi_1:
 13654                              <1> dskr:
 13655                              <1> 	; 01/05/2016
 13656                              <1> 	; 25/04/2016 - TRDOS 386 (TRDOS v2.0)
 13657                              <1> 	; 24/05/2015 - 12/10/2015 (Retro UNIX 386 v1)
 13658                              <1> 	; 26/04/2013 - 03/08/2013 (Retro UNIX 8086 v1)
 13659                              <1> dskr_0:
 13660 00010AEE 8B15[80950100]      <1>         mov	edx, [i.size]
 13661 00010AF4 8B1D[88940100]      <1> 	mov	ebx, [u.fofp]
 13662 00010AFA 2B13                <1> 	sub	edx, [ebx]
 13663 00010AFC 7647                <1> 	jna	short dskr_4
 13664                              <1> 	;
 13665 00010AFE 50                  <1> 	push	eax ; 01/05/2016
 13666 00010AFF 3B15[9C940100]      <1> 	cmp     edx, [u.count] 
 13667 00010B05 7306                <1> 	jnb	short dskr_1
 13668 00010B07 8915[9C940100]      <1> 	mov	[u.count], edx
 13669                              <1> dskr_1:
 13670                              <1> 	; EAX = First Cluster
 13671                              <1> 	; [Current_Drv] = Physical drive number 
 13672 00010B0D E83B000000          <1> 	call	mget_r
 13673                              <1> 	; NOTE: in 'mget_r', relevant sector will be read in buffer
 13674                              <1> 	; if it is not already in buffer !
 13675 00010B12 BB[9C960100]        <1> 	mov	ebx, readi_buffer
 13676 00010B17 803D[DA940100]00    <1> 	cmp	byte [u.kcall], 0 ; the caller is 'namei' sign (=1)
 13677 00010B1E 770F                <1> 	ja	short dskr_3	  ; zf=0 -> the caller is 'namei'
 13678 00010B20 66833D[D8940100]00  <1> 	cmp	word [u.pcount], 0
 13679 00010B28 7705                <1> 	ja	short dskr_3
 13680                              <1> dskr_2:
 13681                              <1> 	; [u.base] = virtual address to transfer (as destination address)
 13682 00010B2A E88D010000          <1> 	call	trans_addr_w ; translate virtual address to physical (w)
 13683                              <1> dskr_3:
 13684                              <1> 	; EBX (r5) = system (I/O) buffer address -physical-
 13685 00010B2F E8F0010000          <1> 	call	sioreg
 13686 00010B34 87FE                <1> 	xchg	esi, edi
 13687                              <1> 	; EDI = file (user data) offset
 13688                              <1> 	; ESI = sector (I/O) buffer offset
 13689                              <1> 	; ECX = byte count
 13690 00010B36 F3A4                <1> 	rep	movsb
 13691                              <1> 	; eax = remain bytes in buffer
 13692                              <1>         ;       (check if remain bytes in the buffer > [u.pcount])
 13693 00010B38 09C0                <1> 	or	eax, eax
 13694 00010B3A 75EE                <1> 	jnz	short dskr_2 ; (page end before system buffer end!)
 13695 00010B3C 58                  <1> 	pop	eax  ; (first cluster number)
 13696 00010B3D 390D[9C940100]      <1> 	cmp	[u.count], ecx ; 0
 13697 00010B43 77A9                <1> 	ja	short dskr_0
 13698                              <1> dskr_4:
 13699 00010B45 C605[DA940100]00    <1> 	mov	byte [u.kcall], 0
 13700                              <1> dskr_5:		; 23/07/2022
 13701 00010B4C C3                  <1> 	retn
 13702                              <1> 
 13703                              <1> mget_r:
 13704                              <1> 	; 29/08/2023
 13705                              <1> 	; 30/07/2022
 13706                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
 13707                              <1> 	; 24/10/2016
 13708                              <1> 	; 22/10/2016
 13709                              <1> 	; 12/10/2016
 13710                              <1> 	; 29/04/2016
 13711                              <1> 	; 25/04/2016 - TRDOS 386 (TRDOS v2.0)
 13712                              <1> 	; 03/06/2015 (Retro UNIX 386 v1, 'mget', u.5s)
 13713                              <1> 	; 22/03/2013 - 31/07/2013 (Retro UNIX 8086 v1)
 13714                              <1> 	;
 13715                              <1> 	; Get existing or (allocate) a new disk block for file
 13716                              <1> 	; 
 13717                              <1> 	; INPUTS ->
 13718                              <1> 	;    [u.fofp] = file offset pointer
 13719                              <1> 	;    EAX = First Cluster
 13720                              <1> 	;    [cdev] = Logical dos drive number
 13721                              <1> 	;    ([u.off] = file offset)
 13722                              <1> 	; OUTPUTS ->
 13723                              <1> 	;    EAX = logical sector number
 13724                              <1> 	;    ESI = Logical Dos Drive Description Table address
 13725                              <1> 	;
 13726                              <1> 	; Modified registers: EDX, EBX, ECX, ESI, EDI
 13727                              <1> 
 13728 00010B4D 8B35[88940100]      <1> 	mov     esi, [u.fofp]
 13729 00010B53 8B1E                <1> 	mov	ebx, [esi] ; (u.off)
 13730                              <1> 
 13731 00010B55 29C9                <1> 	sub	ecx, ecx
 13732 00010B57 8A2D[59940100]      <1> 	mov	ch, [cdev]
 13733                              <1> 
 13734 00010B5D BE00010900          <1> 	mov	esi, Logical_DOSDisks
 13735 00010B62 01CE                <1> 	add	esi, ecx
 13736                              <1> 
 13737 00010B64 380D[F0880100]      <1> 	cmp	[readi.valid], cl ; 0
 13738 00010B6A 7648                <1> 	jna	short mget_r_0
 13739                              <1> 	
 13740 00010B6C 3A2D[F1880100]      <1> 	cmp	ch, [readi.drv]
 13741 00010B72 7540                <1> 	jne	short mget_r_0
 13742                              <1> 
 13743 00010B74 3B05[04890100]      <1> 	cmp	eax, [readi.fclust]
 13744 00010B7A 7561                <1> 	jne	short mget_r_3
 13745                              <1> 	
 13746 00010B7C 89D8                <1> 	mov	eax, ebx ; file offset
 13747 00010B7E 668B0D[F8880100]    <1> 	mov	cx, [readi.bpc]
 13748 00010B85 41                  <1> 	inc	ecx ; <= 65536
 13749 00010B86 29D2                <1> 	sub	edx, edx
 13750 00010B88 F7F1                <1> 	div	ecx
 13751                              <1> 
 13752 00010B8A 8B3D[00890100]      <1> 	mov	edi, [readi.c_index] ; cluster index
 13753                              <1> 
 13754 00010B90 39F8                <1> 	cmp	eax, edi
 13755 00010B92 7576                <1>         jne     short mget_r_4  ; (*)
 13756                              <1> 
 13757                              <1> 	; edx = byte offset in cluster (<= 65535)
 13758 00010B94 668915[FA880100]    <1> 	mov	[readi.offset], dx
 13759                              <1> 	; 23/07/2022
 13760                              <1> 	;shr	dx, 9 ; / 512
 13761 00010B9B C1EA09              <1> 	shr	edx, 9
 13762 00010B9E 8815[F3880100]      <1> 	mov	[readi.s_index], dl ; sector index in cluster (0 to spc -1)
 13763                              <1> 
 13764 00010BA4 A1[FC880100]        <1> 	mov	eax, [readi.cluster]  ; > 0 if [readi.valid] = 1
 13765 00010BA9 8B15[08890100]      <1> 	mov	edx, [readi.fs_index]
 13766 00010BAF E996000000          <1>         jmp     mget_r_7
 13767                              <1> 
 13768                              <1> mget_r_0:
 13769 00010BB4 882D[F1880100]      <1> 	mov	[readi.drv], ch ; physical drive number
 13770 00010BBA 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 13771 00010BBE 7707                <1> 	ja	short mget_r_1
 13772 00010BC0 8A4E12              <1> 	mov	cl, [esi+LD_FS_BytesPerSec+1]
 13773 00010BC3 D0E9                <1> 	shr	cl, 1 ;  ; 1 for 512 bytes, 4 for 2048 bytes
 13774 00010BC5 EB03                <1> 	jmp	short mget_r_2	
 13775                              <1> mget_r_1:
 13776 00010BC7 8A4E13              <1> 	mov	cl, [esi+LD_BPB+BPB_SecPerClust]
 13777                              <1> mget_r_2:
 13778 00010BCA 880D[F2880100]      <1> 	mov	[readi.spc], cl  ; sectors per cluster
 13779                              <1> 	; NOTE: readi bytes per sector value is always 512 !
 13780                              <1> 	; 23/07/2022
 13781                              <1> 	;xor	ch, ch
 13782                              <1> 	; 29/08/2023
 13783 00010BD0 C1E109              <1> 	shl	ecx, 9 
 13784                              <1> 	;shl	cx, 9 ; * 512
 13785                              <1> 	;dec	cx ; bytes per cluster - 1
 13786                              <1> 	; 23/07/2022
 13787 00010BD3 49                  <1> 	dec	ecx
 13788 00010BD4 66890D[F8880100]    <1> 	mov	[readi.bpc], cx
 13789                              <1> 	;sub	cx, cx
 13790                              <1> 	; 23/07/2022
 13791 00010BDB 29C9                <1> 	sub	ecx, ecx
 13792                              <1> mget_r_3:
 13793 00010BDD A3[04890100]        <1> 	mov	[readi.fclust], eax ; first cluster (or FDT address)
 13794 00010BE2 880D[F0880100]      <1> 	mov	[readi.valid], cl ; 0 
 13795                              <1> 	;mov	[readi.s_index], cl ; 0
 13796                              <1> 	;mov	[readi.offset], cx ; 0
 13797 00010BE8 890D[00890100]      <1> 	mov	[readi.c_index], ecx ; 0
 13798 00010BEE 890D[FC880100]      <1> 	mov	[readi.cluster], ecx ; 0
 13799 00010BF4 890D[F4880100]      <1> 	mov	[readi.sector], ecx ; 0
 13800                              <1> 
 13801 00010BFA 89D8                <1> 	mov	eax, ebx ; file offset
 13802 00010BFC 668B0D[F8880100]    <1> 	mov	cx, [readi.bpc]
 13803 00010C03 41                  <1> 	inc	ecx ; <= 65536
 13804 00010C04 29D2                <1> 	sub	edx, edx
 13805 00010C06 F7F1                <1> 	div	ecx
 13806                              <1> 	;mov	edi, [readi.c_index] ; previous cluster index
 13807 00010C08 29FF                <1> 	sub	edi, edi
 13808                              <1> mget_r_4:
 13809 00010C0A A3[00890100]        <1> 	mov	[readi.c_index], eax ; cluster index
 13810                              <1> 	; edx = byte offset in cluster (<= 65535)
 13811 00010C0F 668915[FA880100]    <1> 	mov	[readi.offset], dx
 13812                              <1> 	; 23/07/2022
 13813                              <1> 	;shr	dx, 9 ; / 512
 13814 00010C16 C1EA09              <1> 	shr	edx, 9
 13815 00010C19 8815[F3880100]      <1> 	mov	[readi.s_index], dl ; sector index in cluster (0 to spc -1)
 13816                              <1> 
 13817 00010C1F 89C1                <1> 	mov	ecx, eax ; current cluster index
 13818 00010C21 A1[04890100]        <1> 	mov	eax, [readi.fclust]
 13819 00010C26 09C9                <1> 	or	ecx, ecx ; cluster index
 13820 00010C28 741B                <1> 	jz	short mget_r_6
 13821                              <1> 
 13822 00010C2A 39CF                <1> 	cmp	edi, ecx
 13823 00010C2C 7710                <1> 	ja	short mget_r_5 ; old cluster index is higher
 13824 00010C2E 8B15[FC880100]      <1> 	mov	edx, [readi.cluster]
 13825 00010C34 21D2                <1> 	and	edx, edx
 13826 00010C36 7406                <1> 	jz	short mget_r_5
 13827                              <1> 	; valid 'readi' parameters (*)
 13828 00010C38 89D0                <1> 	mov	eax, edx
 13829 00010C3A 29F9                <1> 	sub	ecx, edi
 13830 00010C3C 740C                <1> 	jz	short mget_r_7
 13831                              <1> mget_r_5:
 13832                              <1> 	; EAX = Beginning cluster
 13833                              <1> 	; EDX = Sector index in disk/file section
 13834                              <1> 	;	(Only for SINGLIX file system!)
 13835                              <1> 	; ECX = Cluster sequence number after the beginning cluster
 13836                              <1> 	; ESI = Logical DOS Drive Description Table address
 13837 00010C3E E825C0FFFF          <1> 	call	get_cluster_by_index
 13838 00010C43 724C                <1> 	jc	short mget_r_err
 13839                              <1> 	; EAX = Cluster number
 13840                              <1> mget_r_6:
 13841 00010C45 A3[FC880100]        <1> 	mov	[readi.cluster], eax ; FDT number for Singlix File System
 13842                              <1> mget_r_7:
 13843 00010C4A 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 13844 00010C4E 765D                <1> 	jna	short mget_r_12
 13845                              <1> 
 13846                              <1> 	;sub	eax, 2
 13847                              <1> 	; 30/07/2022
 13848 00010C50 48                  <1> 	dec	eax
 13849 00010C51 48                  <1> 	dec	eax
 13850 00010C52 0FB615[F2880100]    <1> 	movzx	edx, byte [readi.spc]
 13851 00010C59 F7E2                <1> 	mul	edx
 13852                              <1> 
 13853 00010C5B 034668              <1> 	add	eax, [esi+LD_DATABegin]
 13854 00010C5E 8A15[F3880100]      <1> 	mov	dl, [readi.s_index]
 13855 00010C64 01D0                <1> 	add	eax, edx
 13856                              <1> mget_r_8:
 13857                              <1> 	; eax = logical sector number
 13858 00010C66 803D[F0880100]00    <1> 	cmp	byte [readi.valid], 0
 13859 00010C6D 7608                <1> 	jna	short mget_r_9
 13860 00010C6F 3B05[F4880100]      <1> 	cmp	eax, [readi.sector]
 13861 00010C75 7435                <1> 	je	short mget_r_11 ; sector is already in 'readi' buffer
 13862                              <1> mget_r_9:
 13863 00010C77 A3[F4880100]        <1> 	mov	[readi.sector], eax
 13864 00010C7C BB[9C960100]        <1> 	mov	ebx, readi_buffer ; buffer address
 13865                              <1> 	;mov	ecx, 1
 13866                              <1> 	; 30/07/2022
 13867 00010C81 31C9                <1> 	xor	ecx, ecx
 13868 00010C83 FEC1                <1> 	inc	cl
 13869                              <1> 	; ecx = 1	
 13870                              <1> 
 13871                              <1> 	; 29/04/2016
 13872                              <1> 	;xor	dl, dl
 13873                              <1> 
 13874                              <1> 	; EAX = Logical sector number
 13875                              <1> 	; ECX = Sector count
 13876                              <1> 	; EBX = Buffer address
 13877                              <1> 	; (EDX = 0)
 13878                              <1> 	; ESI = Logical DOS drive description table address
 13879                              <1> 
 13880 00010C85 E876130000          <1> 	call	disk_read
 13881 00010C8A 7314                <1> 	jnc	short mget_r_10
 13882                              <1> 
 13883                              <1> 	; 22/10/2016 (15h -> 17)
 13884 00010C8C B811000000          <1> 	mov	eax, 17 ; Drive not ready or read error !
 13885                              <1> mget_r_err:
 13886 00010C91 A3[E0940100]        <1> 	mov	[u.error], eax
 13887                              <1> 	; 12/10/2016
 13888 00010C96 A3[74940100]        <1> 	mov	[u.r0], eax
 13889 00010C9B E994C1FFFF          <1> 	jmp	error
 13890                              <1> mget_r_10:
 13891 00010CA0 C605[F0880100]01    <1> 	mov	byte [readi.valid], 1 ; 24/10/2016
 13892 00010CA7 A1[F4880100]        <1> 	mov	eax, [readi.sector]
 13893                              <1> mget_r_11:
 13894 00010CAC C3                  <1> 	retn
 13895                              <1> mget_r_12:
 13896                              <1> 	; EAX = FDT number
 13897                              <1> 	; EDX = Sector index from FDT sector (0,1,2,3,4...)
 13898 00010CAD 40                  <1> 	inc	eax ; the first data sector in FS disk section
 13899 00010CAE 8915[08890100]      <1> 	mov	[readi.fs_index], edx
 13900 00010CB4 01D0                <1> 	add	eax, edx
 13901 00010CB6 EBAE                <1> 	jmp	short mget_r_8
 13902                              <1> 
 13903                              <1> trans_addr_r:
 13904                              <1> 	; 12/10/2016
 13905                              <1> 	; 02/05/2016 - TRDOS 386 (TRDOS v2.0)
 13906                              <1> 	; Translate virtual address to physical address 
 13907                              <1> 	; for reading from user's memory space
 13908                              <1> 	; 04/06/2015 - 18/10/2015 (Retro UNIX 386 v1)
 13909                              <1> 
 13910 00010CB8 31D2                <1> 	xor	edx, edx ; 0 (read access sign)
 13911 00010CBA EB04                <1> 	jmp 	short trans_addr_rw
 13912                              <1> 
 13913                              <1> trans_addr_w:
 13914                              <1> 	; 12/10/2016
 13915                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
 13916                              <1> 	; Translate virtual address to physical address
 13917                              <1> 	; for writing to user's memory space
 13918                              <1> 	; 04/06/2015 - 18/10/2015 (Retro UNIX 386 v1)
 13919                              <1> 	
 13920 00010CBC 29D2                <1> 	sub	edx, edx
 13921 00010CBE FEC2                <1> 	inc	dl ; 1 (write access sign)
 13922                              <1> trans_addr_rw:
 13923 00010CC0 50                  <1> 	push	eax
 13924 00010CC1 53                  <1> 	push	ebx
 13925 00010CC2 52                  <1> 	push 	edx ; r/w sign (in DL)
 13926                              <1> 	;
 13927 00010CC3 8B1D[98940100]      <1> 	mov	ebx, [u.base]
 13928 00010CC9 E8F04EFFFF          <1> 	call	get_physical_addr ; get physical address
 13929 00010CCE 730F                <1> 	jnc	short passc_0
 13930 00010CD0 A3[E0940100]        <1> 	mov	[u.error], eax
 13931 00010CD5 A3[74940100]        <1> 	mov	[u.r0], eax ; 12/10/2016
 13932                              <1> 	;pop	edx
 13933                              <1> 	;pop 	ebx
 13934                              <1> 	;pop	eax
 13935 00010CDA E955C1FFFF          <1> 	jmp	error
 13936                              <1> passc_0:
 13937 00010CDF F6C202              <1> 	test	dl, PTE_A_WRITE ; writable page
 13938 00010CE2 5A                  <1> 	pop	edx
 13939 00010CE3 751C                <1> 	jnz	short passc_1
 13940                              <1> 	
 13941 00010CE5 20D2                <1> 	and 	dl, dl
 13942 00010CE7 7418                <1> 	jz	short passc_1
 13943                              <1> 	; read only (duplicated) page -must be copied to a new page-
 13944                              <1> 	; EBX = linear address
 13945 00010CE9 51                  <1> 	push 	ecx
 13946 00010CEA E8404EFFFF          <1> 	call 	copy_page
 13947 00010CEF 59                  <1> 	pop	ecx
 13948 00010CF0 721E                <1> 	jc	short passc_2
 13949 00010CF2 50                  <1> 	push	eax ; physical address of the new/allocated page
 13950 00010CF3 E8C64EFFFF          <1> 	call	add_to_swap_queue
 13951 00010CF8 58                  <1> 	pop	eax
 13952 00010CF9 81E3FF0F0000        <1> 	and 	ebx, PAGE_OFF ; 0FFFh
 13953                              <1> 	;mov 	ecx, PAGE_SIZE
 13954                              <1> 	;sub	ecx, ebx
 13955 00010CFF 01D8                <1> 	add	eax, ebx
 13956                              <1> passc_1: 
 13957 00010D01 A3[D4940100]        <1> 	mov 	[u.pbase], eax ; physical address
 13958 00010D06 66890D[D8940100]    <1> 	mov	[u.pcount], cx ; remain byte count in page (1-4096)
 13959 00010D0D 5B                  <1> 	pop	ebx
 13960 00010D0E 58                  <1> 	pop	eax
 13961 00010D0F C3                  <1> 	retn
 13962                              <1> passc_2:
 13963 00010D10 B804000000          <1> 	mov	eax, ERR_MINOR_IM ; "Insufficient memory !" error
 13964 00010D15 A3[74940100]        <1> 	mov	[u.r0], eax ; 12/10/2016
 13965 00010D1A A3[E0940100]        <1> 	mov	[u.error], eax
 13966                              <1> 	;pop 	ebx
 13967                              <1> 	;pop	eax
 13968 00010D1F E910C1FFFF          <1> 	jmp	error
 13969                              <1> 
 13970                              <1> sioreg: 
 13971                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
 13972                              <1> 	; 19/05/2015 - 25/07/2015 (Retro UNIX 386 v1)
 13973                              <1> 	; 12/03/2013 - 22/07/2013 (Retro UNIX 8086 v1)
 13974                              <1> 	; INPUTS -> 
 13975                              <1> 	;     EBX = system buffer (data) address (r5)
 13976                              <1> 	;     [u.fofp] = pointer to file offset pointer
 13977                              <1> 	;     [u.base] = virtual address of the user buffer
 13978                              <1> 	;     [u.pbase] = physical address of the user buffer
 13979                              <1> 	;     [u.count] = byte count
 13980                              <1> 	;     [u.pcount] = byte count within page frame
 13981                              <1> 	; OUTPUTS -> 
 13982                              <1> 	;     ESI = user data offset (r1)
 13983                              <1> 	;     EDI = system (I/O) buffer offset (r2)
 13984                              <1> 	;     ECX = byte count (r3)
 13985                              <1> 	;     EAX = remain bytes after byte count within page frame
 13986                              <1> 	;	(If EAX > 0, transfer will continue from the next page)
 13987                              <1>         ;
 13988                              <1> 	; ((Modified registers:  EDX))
 13989                              <1>  
 13990 00010D24 8B35[88940100]      <1>         mov     esi, [u.fofp]
 13991 00010D2A 8B3E                <1>         mov     edi, [esi]
 13992 00010D2C 89F9                <1> 	mov	ecx, edi
 13993 00010D2E 81C900FEFFFF        <1> 	or	ecx, 0FFFFFE00h
 13994 00010D34 81E7FF010000        <1> 	and	edi, 1FFh
 13995 00010D3A 01DF                <1> 	add	edi, ebx ; EBX = system buffer (data) address
 13996 00010D3C F7D9                <1> 	neg	ecx
 13997 00010D3E 3B0D[9C940100]      <1> 	cmp	ecx, [u.count]
 13998 00010D44 7606                <1> 	jna	short sioreg_0
 13999 00010D46 8B0D[9C940100]      <1> 	mov	ecx, [u.count]
 14000                              <1> sioreg_0:
 14001 00010D4C 803D[DA940100]00    <1> 	cmp	byte [u.kcall], 0
 14002 00010D53 7613                <1> 	jna	short sioreg_1
 14003                              <1> 	 ; the caller is 'mkdir' or 'namei'
 14004 00010D55 A1[98940100]        <1> 	mov	eax, [u.base]
 14005 00010D5A A3[D4940100]        <1> 	mov 	[u.pbase], eax ; physical address = virtual address
 14006 00010D5F 66890D[D8940100]    <1> 	mov	word [u.pcount], cx ; remain bytes in buffer (1 sector)
 14007 00010D66 EB0B                <1> 	jmp	short sioreg_2
 14008                              <1> sioreg_1:
 14009 00010D68 0FB715[D8940100]    <1> 	movzx	edx, word [u.pcount]
 14010 00010D6F 39D1                <1> 	cmp	ecx, edx
 14011 00010D71 772A                <1> 	ja	short sioreg_4 ; transfer count > [u.pcount]
 14012                              <1> sioreg_2: ; 2:
 14013 00010D73 31C0                <1> 	xor 	eax, eax
 14014                              <1> sioreg_3:
 14015 00010D75 010D[A0940100]      <1> 	add 	[u.nread], ecx
 14016 00010D7B 290D[9C940100]      <1> 	sub 	[u.count], ecx
 14017 00010D81 010D[98940100]      <1> 	add 	[u.base], ecx
 14018 00010D87 010E                <1>         add 	[esi], ecx 
 14019 00010D89 8B35[D4940100]      <1> 	mov	esi, [u.pbase]
 14020 00010D8F 66290D[D8940100]    <1> 	sub	[u.pcount], cx
 14021 00010D96 010D[D4940100]      <1> 	add	[u.pbase], ecx
 14022 00010D9C C3                  <1>         retn
 14023                              <1> sioreg_4:
 14024                              <1> 	; transfer count > [u.pcount]
 14025                              <1> 	; (ecx > edx)
 14026 00010D9D 89C8                <1> 	mov	eax, ecx
 14027 00010D9F 29D0                <1> 	sub	eax, edx ; remain bytes for 1 sector (block) transfer
 14028 00010DA1 89D1                <1> 	mov	ecx, edx ; current transfer count = [u.pcount]
 14029 00010DA3 EBD0                <1> 	jmp	short sioreg_3
 14030                              <1> 
 14031                              <1> tswitch: ; Retro UNIX 386 v1
 14032                              <1> tswap:
 14033                              <1> 	; 16/01/2017
 14034                              <1> 	; 21/05/2016 - TRDOS 386 (TRDOS v2.0)
 14035                              <1> 	; 10/05/2015 - 01/09/2015 (Retro UNIX 386 v1)
 14036                              <1> 	; 14/04/2013 - 14/02/2014 (Retro UNIX 8086 v1)
 14037                              <1> 	; time out swap, called when a user times out.
 14038                              <1> 	; the user is put on the low priority queue.
 14039                              <1> 	; This is done by making a link from the last user
 14040                              <1> 	; on the low priority queue to him via a call to 'putlu'.
 14041                              <1> 	; then he is swapped out.
 14042                              <1> 
 14043                              <1> 	; TRDOS 386 (TRDOS v2.0) modification ->  ** 21/05/2016 **
 14044                              <1> 	;     * when a high priority (event) process will be stopped
 14045                              <1> 	;	(swapped out, swithched out/off), 'tswap/tswitch' will
 14046                              <1> 	;	not add it to a run queue. 
 14047                              <1> 	;	/// What for: Process may be already in a run queue, 
 14048                              <1> 	;	it is unspeficied state because process might be started
 14049                              <1> 	;	by a timer event which does not regard previous priority
 14050                              <1> 	;	level and run queue of the process (for fast executing!).
 14051                              <1> 	;	After the 'run for event', process will be sequenced
 14052                              <1> 	;	to run by it's actual run queue. ///
 14053                              <1> 	;
 14054                              <1> 	; Retro UNIX 386 v1 modification ->
 14055                              <1> 	;       swap (software task switch) is performed by changing
 14056                              <1> 	;	user's page directory (u.pgdir) instead of segment change
 14057                              <1> 	;	as in Retro UNIX 8086 v1.
 14058                              <1> 	;
 14059                              <1> 	; RETRO UNIX 8086 v1 modification ->
 14060                              <1> 	;       'swap to disk' is replaced with 'change running segment'
 14061                              <1> 	;	according to 8086 cpu (x86 real mode) architecture.
 14062                              <1> 	;	pdp-11 was using 64KB uniform memory while IBM PC
 14063                              <1> 	;	compatibles was using 1MB segmented memory
 14064                              <1> 	;	in 8086/8088 times.
 14065                              <1> 	;
 14066                              <1> 	; INPUTS ->
 14067                              <1> 	;    u.uno - users process number
 14068                              <1> 	;    runq+4 - lowest priority queue
 14069                              <1> 	; OUTPUTS ->
 14070                              <1> 	;    r0 - users process number
 14071                              <1> 	;    r2 - lowest priority queue address
 14072                              <1> 	;
 14073                              <1> 	; ((AX = R0, BX = R2)) output
 14074                              <1> 	; ((Modified registers: EDX, EBX, ECX, ESI, EDI))
 14075                              <1> 	;
 14076                              <1> 
 14077                              <1> 	NOTE:
 14078                              <1> 	;* [u.pri] priority level is specified by run queue which is process 
 14079                              <1> 	;  comes to run from.
 14080                              <1> 	;* Initial [u.pri] is 1 ('normal/regular') for programs 
 14081                              <1> 	;  (which are launched by MainProg or 'sysexec'), it is changed
 14082                              <1> 	;  to 2 ('high') by timer event, if program uses 'systimer' system call.
 14083                              <1> 	;* Program (Process) also can change it's running priority 
 14084                              <1> 	;  from 1 to 0 or up to 2 by using 'syspri' system call; but,
 14085                              <1> 	;  if program selects priority level 2 (high) for running, next time
 14086                              <1> 	;  it is reduced to 1 (normal/regular) because 'syspri' adds this
 14087                              <1> 	;  program to 'run for normal' queue while running duration is a bit
 14088                              <1> 	;  protected from swap/switch out immediate, behalf of other high 
 14089                              <1> 	;  priority process in sequence. Program (with high priority) will not
 14090                              <1> 	;  be swapped/switched out (by timer event) before it's time quantum
 14091                              <1> 	;  will be elapsed, but, this will be temporary if program is not using
 14092                              <1> 	;  timer event function.
 14093                              <1> 
 14094                              <1> 	;For example:
 14095                              <1> 	;If a process frequently gets a timer event, it runs at high priority
 14096                              <1> 	;level but when it returns from running it returns to actual run queue,
 14097                              <1> 	;not to 'run for event' queue again.
 14098                              <1> 	;'tswap' will not change the sequence at return/stop(swap out) stage.
 14099                              <1> 	;But if priority level not high (=2, 'run for event'), 'tswap/tswitch'
 14100                              <1> 	;will add the stopping process to relevant run queue according to
 14101                              <1> 	;[u.pri] priority level.
 14102                              <1> 
 14103                              <1> 	; 16/01/2017
 14104 00010DA5 BB[64940100]        <1> 	mov	ebx, runq+2 	; 'runq_normal' ; normal/regular priority
 14105                              <1> 	; 21/05/2016
 14106                              <1> 	;cmp	byte [u.pri], 2	; high priority (run for event) ?
 14107                              <1> 	;jnb	short swap
 14108                              <1> 	; 16/01/2017
 14109                              <1> 	; (Normal and also high/event priority processes will be added to
 14110                              <1> 	; normal priority run queue for ensuring circular running sequence!)
 14111                              <1> 	; (Timer interrupt or 'syspri' system call may change priority and run
 14112                              <1> 	; queue to high/event level.)
 14113 00010DAA 803D[BE940100]00    <1> 	cmp	byte [u.pri], 0
 14114 00010DB1 7702                <1> 	ja	short tswap_1	; normal priority run queue
 14115                              <1> 	;
 14116 00010DB3 43                  <1> 	inc	ebx
 14117 00010DB4 43                  <1> 	inc	ebx		; runq+4, 'runq_background', low priority
 14118                              <1> tswap_1:
 14119 00010DB5 A0[C5940100]        <1> 	mov 	al, [u.uno]
 14120                              <1> 	       	; movb u.uno,r1 / move users process number to r1
 14121                              <1> 		; mov  $runq+4,r2 
 14122                              <1> 			; / move lowest priority queue address to r2
 14123                              <1>       	; ebx = run queue
 14124 00010DBA E8FD000000          <1> 	call 	putlu
 14125                              <1> 		; jsr r0,putlu / create link from last user on Q to 
 14126                              <1> 		             ; / u.uno's user
 14127                              <1> 
 14128                              <1> switch: ; Retro UNIX 386 v1
 14129                              <1> swap:
 14130                              <1> 	; 20/08/2024
 14131                              <1> 	; 02/01/2017
 14132                              <1> 	; 21/05/2016
 14133                              <1> 	; 20/05/2016
 14134                              <1> 	; 02/05/2016
 14135                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
 14136                              <1> 	; 10/05/2015 - 02/09/2015 (Retro UNIX 386 v1)
 14137                              <1> 	; 14/04/2013 - 08/03/2014 (Retro UNIX 8086 v1)
 14138                              <1> 	;
 14139                              <1> 	; 'swap' is routine that controls the swapping of processes
 14140                              <1> 	; in and out of core.
 14141                              <1> 	;
 14142                              <1> 	; TRDOS 386 (TRDOS v2.0) modification ->  ** 20/05/2016 **
 14143                              <1> 	;     * 3 different priority level is applied
 14144                              <1> 	;	(just as original unix v1)
 14145                              <1> 	;	1) high priority (event) run queue, 'runq_event'
 14146                              <1> 	;	2) normal priority (regular) run queue, 'runq_normal'
 14147                              <1> 	;	3) low priority (background) run queue, 'runq_backgroud'
 14148                              <1> 	;	'swap' code will run a process which has max. priority
 14149                              <1>         ;       (for earliest event at first)
 14150                              <1> 	;
 14151                              <1> 	; Retro UNIX 386 v1 modification ->
 14152                              <1> 	;       swap (software task switch) is performed by changing
 14153                              <1> 	;	user's page directory (u.pgdir) instead of segment change
 14154                              <1> 	;	as in Retro UNIX 8086 v1.
 14155                              <1> 	;
 14156                              <1> 	; RETRO UNIX 8086 v1 modification ->
 14157                              <1> 	;       'swap to disk' is replaced with 'change running segment'
 14158                              <1> 	;	according to 8086 cpu (x86 real mode) architecture.
 14159                              <1> 	;	pdp-11 was using 64KB uniform memory while IBM PC
 14160                              <1> 	;	compatibles was using 1MB segmented memory
 14161                              <1> 	;	in 8086/8088 times.
 14162                              <1> 	;
 14163                              <1> 	; INPUTS ->
 14164                              <1> 	;    runq table - contains processes to run.
 14165                              <1> 	;    p.link - contains next process in line to be run.
 14166                              <1> 	;    u.uno - process number of process in core
 14167                              <1> 	;    s.stack - swap stack used as an internal stack for swapping.
 14168                              <1> 	; OUTPUTS ->
 14169                              <1> 	;    (original unix v1 -> present process to its disk block)
 14170                              <1> 	;    (original unix v1 -> new process into core -> 
 14171                              <1> 	;	   Retro Unix 8086 v1 -> segment registers changed 
 14172                              <1> 	;	   for new process)
 14173                              <1> 	;    u.quant = 3 (Time quantum for a process)
 14174                              <1> 	; 	((INT 1Ch count down speed -> 18.2 times per second)
 14175                              <1> 	;    RETRO UNIX 8086 v1 will use INT 1Ch (18.2 times per second)
 14176                              <1> 	;	 for now, it will swap the process if there is not
 14177                              <1> 	;	 a keyboard event (keystroke) (Int 15h, function 4Fh)
 14178                              <1> 	;	 or will count down from 3 to 0 even if there is a
 14179                              <1> 	;        keyboard event locking due to repetitive key strokes.
 14180                              <1> 	;	 u.quant will be reset to 3 for RETRO UNIX 8086 v1.
 14181                              <1> 	;
 14182                              <1> 	; ((Modified registers: EAX, EDX, EBX, ECX, ESI, EDI))
 14183                              <1> 
 14184                              <1> 	;NOTE:
 14185                              <1> 	;High priority queue is the first for selecting a process to run.
 14186                              <1> 	;If there is not a process in high priority level run queue,
 14187                              <1> 	;a process in normal priority run queue will be selected
 14188                              <1> 	;or a proces in low priority run queue will be selected if normal
 14189                              <1> 	;priority level run queue is empty.
 14190                              <1> 	
 14191                              <1> 	; 21/05/2016 -(3 priority levels, 3 run queues)
 14192 00010DBF BE[62940100]        <1> 	mov	esi, runq ; 'runq_event' ; high priority, 'run for event'
 14193 00010DC4 C605[4C890100]03    <1> 	mov	byte [priority], 3 ; high priority + 1
 14194 00010DCB 31DB                <1> 	xor	ebx, ebx ; 02/01/2017
 14195                              <1> swap_0: ; 1: / search runq table for highest priority process
 14196 00010DCD 66AD                <1> 	lodsw  ; mov ax, [esi], add esi+2
 14197                              <1> 	;xor	ebx, ebx ; 02/05/2016
 14198 00010DCF 6621C0              <1> 	and 	ax, ax ; are there any processes to run in this Q entry
 14199 00010DD2 750E                <1> 	jnz	short swap_2
 14200                              <1> 	; 21/05/2026
 14201                              <1> 	; runq_normal = runq+2, runq_background = runq+4
 14202 00010DD4 FE0D[4C890100]      <1> 	dec	byte [priority] ; 3 -> 3, 2 -> 1, 1-> 0
 14203 00010DDA 75F1                <1> 	jnz	short swap_0
 14204                              <1> 	;cmp	esi, runq+6  ; if zero compare address to end of table
 14205                              <1> 	;jb	short swap_0 ; if not at end, go back
 14206                              <1> swap_1:
 14207                              <1> 	; 02/05/2016
 14208                              <1> 	; 29/04/2016 (TRDOS 386 = TRDOS v2.0)
 14209                              <1> 	; No user process to run...
 14210                              <1> 	; Run the kernel process... MainProg: Internal Command Interpreter
 14211 00010DDC FEC0                <1> 	inc	al ; mov al, 1  ; process number of MainProg
 14212 00010DDE FEC3                <1> 	inc	bl ; mov bl, al ; 1
 14213 00010DE0 EB1D                <1> 	jmp	short swap_4
 14214                              <1> swap_2:
 14215                              <1> 	; 21/05/2016
 14216 00010DE2 FE0D[4C890100]      <1> 	dec	byte [priority] ; priority level of present user/process
 14217                              <1> 			        ; 0, 1, 2
 14218 00010DE8 4E                  <1> 	dec	esi
 14219 00010DE9 4E                  <1>         dec     esi
 14220                              <1> 	;
 14221 00010DEA 88C3                <1> 	mov	bl, al
 14222 00010DEC 38E0                <1> 	cmp	al, ah ; is there only 1 process in the queue to be run
 14223 00010DEE 740A                <1> 	je	short swap_3 ; yes
 14224 00010DF0 8AA3[97930100]      <1> 	mov	ah, [ebx+p.link-1]
 14225 00010DF6 8826                <1>        	mov	[esi], ah ; move next process in line into run queue
 14226 00010DF8 EB05                <1> 	jmp	short swap_4
 14227                              <1> swap_3:
 14228                              <1> 	;xor	dx, dx
 14229                              <1> 	; 20/08/2024
 14230 00010DFA 31D2                <1> 	xor	edx, edx
 14231 00010DFC 668916              <1> 	mov	[esi], dx ; zero the entry; no processes on the Q
 14232                              <1> swap_4:
 14233 00010DFF 8A25[C5940100]      <1> 	mov 	ah, [u.uno]
 14234 00010E05 38C4                <1> 	cmp	ah, al ; is this process the same as the process in core?
 14235 00010E07 743B                <1>        	je	short swap_8 ; yes, don't have to swap
 14236 00010E09 08E4                <1> 	or	ah, ah ; is the process # = 0
 14237 00010E0B 740D                <1>        	jz	short swap_6 ; 'sysexit'
 14238                              <1> 	;cmp	ah, al ; is this process the same as the process in core?
 14239                              <1>        	;je	short swap_8 ; yes, don't have to swap
 14240 00010E0D 8925[70940100]      <1> 	mov	[u.usp], esp ; return address for 'syswait' & 'sleep'
 14241 00010E13 E834000000          <1> 	call	wswap  ; write out core to disk
 14242 00010E18 EB1C                <1> 	jmp 	short swap_7
 14243                              <1> swap_6:
 14244                              <1> 	; Deallocate memory pages belong to the process
 14245                              <1> 	; which is being terminated.
 14246                              <1> 	; (Retro UNIX 386 v1 modification !)
 14247                              <1> 	;
 14248 00010E1A 53                  <1> 	push	ebx
 14249 00010E1B A1[CC940100]        <1> 	mov 	eax, [u.pgdir]  ; page directory of the process
 14250 00010E20 8B1D[D0940100]      <1> 	mov	ebx, [u.ppgdir] ; page directory of the parent process
 14251 00010E26 E8E54AFFFF          <1> 	call	deallocate_page_dir
 14252 00010E2B A1[C8940100]        <1> 	mov	eax, [u.upage] ; 'user' structure page of the process
 14253 00010E30 E86A4BFFFF          <1> 	call	deallocate_page
 14254 00010E35 5B                  <1> 	pop	ebx
 14255                              <1> swap_7:
 14256 00010E36 C0E302              <1> 	shl	bl, 2 ; * 4
 14257                              <1> 	;;;
 14258 00010E39 8B83[B4930100]      <1> 	mov	eax, [ebx+p.upage-4] ; the 'u' page of the new process
 14259 00010E3F E840000000          <1> 	call	rswap ; read new process into core
 14260                              <1> swap_8:
 14261                              <1> 	; Retro UNIX  8086 v1 modification !
 14262 00010E44 C605[BC940100]04    <1> 	mov	byte [u.quant], time_count
 14263 00010E4B C3                  <1> 	retn
 14264                              <1> 
 14265                              <1> wswap:  ; < swap out, swap to disk >
 14266                              <1> 	; 28/02/2017 (fnsave)
 14267                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
 14268                              <1> 	; 09/05/2015 (Retro UNIX 386 v1)
 14269                              <1> 	; 26/05/2013 - 08/03/2014 (Retro UNIX 8086 v1)
 14270                              <1> 	; 'wswap' writes out the process that is in core onto its
 14271                              <1> 	; appropriate disk area.
 14272                              <1> 	;
 14273                              <1> 	; Retro UNIX 386 v1 modification ->
 14274                              <1> 	;       User (u) structure content and the user's register content
 14275                              <1> 	;	will be copied to the process's/user's UPAGE (a page for
 14276                              <1> 	;	saving 'u' structure and user registers for task switching).
 14277                              <1> 	;	u.usp - points to kernel stack address which contains
 14278                              <1> 	;		user's registers while entering system call.
 14279                              <1> 	;	u.sp  - points to kernel stack address 
 14280                              <1> 	;		to return from system call -for IRET-.
 14281                              <1> 	;	[u.usp]+32+16 = [u.sp] 
 14282                              <1> 	;	[u.usp] -> edi, esi, ebp, esp (= [u.usp]+32), ebx, 
 14283                              <1> 	;		edx, ecx, eax, gs, fs, es, ds, -> [u.sp].
 14284                              <1> 	;
 14285                              <1> 	; Retro UNIX 8086 v1 modification ->
 14286                              <1> 	;       'swap to disk' is replaced with 'change running segment'
 14287                              <1> 	;	according to 8086 cpu (x86 real mode) architecture.
 14288                              <1> 	;	pdp-11 was using 64KB uniform memory while IBM PC
 14289                              <1> 	;	compatibles was using 1MB segmented memory 
 14290                              <1> 	;	in 8086/8088 times.
 14291                              <1> 	;
 14292                              <1> 	; INPUTS ->
 14293                              <1> 	;    u.break - points to end of program
 14294                              <1> 	;    u.usp - stack pointer at the moment of swap
 14295                              <1> 	;    core - beginning of process program
 14296                              <1> 	;    ecore - end of core 	
 14297                              <1> 	;    user - start of user parameter area
 14298                              <1> 	;    u.uno - user process number
 14299                              <1> 	;    p.dska - holds block number of process
 14300                              <1> 	; OUTPUTS ->
 14301                              <1> 	;    swp I/O queue
 14302                              <1> 	;    p.break - negative word count of process 
 14303                              <1> 	;    r1 - process disk address
 14304                              <1> 	;    r2 - negative word count
 14305                              <1> 	;
 14306                              <1> 	; RETRO UNIX 8086 v1 input/output:
 14307                              <1> 	;
 14308                              <1> 	; INPUTS ->
 14309                              <1> 	;    u.uno - process number (to be swapped out)
 14310                              <1> 	; OUTPUTS ->
 14311                              <1> 	;    none
 14312                              <1> 	;
 14313                              <1> 	;   ((Modified registers: ECX, ESI, EDI))
 14314                              <1> 	;
 14315                              <1> 
 14316                              <1> 	; 28/02/2017
 14317                              <1> 	;cmp	byte [multi_tasking], 0  ; Musti tasking mode ?
 14318                              <1> 	;jna	short wswp
 14319 00010E4C 803D[F3940100]00    <1> 	cmp	byte [u.fpsave], 0 ; 28/02/2017
 14320 00010E53 7606                <1> 	jna	short wswp
 14321 00010E55 DD35[F4940100]      <1> 	fnsave	[u.fpregs] ; save floating point registers (94 bytes)
 14322                              <1> wswp:
 14323 00010E5B 8B3D[C8940100]      <1> 	mov	edi, [u.upage] ; process's user (u) structure page addr
 14324 00010E61 B93D000000          <1> 	mov	ecx, (U_SIZE + 3) / 4
 14325 00010E66 BE[6C940100]        <1> 	mov	esi, user ; active user (u) structure
 14326 00010E6B F3A5                <1> 	rep	movsd
 14327                              <1> 	;
 14328 00010E6D 8B35[70940100]      <1> 	mov	esi, [u.usp] ; esp (system stack pointer,
 14329                              <1> 			     ;      points to user registers)
 14330 00010E73 8B0D[6C940100]      <1> 	mov	ecx, [u.sp]  ; return address from the system call
 14331                              <1> 			     ; (for IRET)
 14332                              <1> 			     ; [u.sp] -> EIP (user)
 14333                              <1> 			     ; [u.sp+4]-> CS (user)
 14334                              <1> 			     ; [u.sp+8] -> EFLAGS (user)
 14335                              <1> 			     ; [u.sp+12] -> ESP (user)
 14336                              <1> 			     ; [u.sp+16] -> SS (user)
 14337 00010E79 29F1                <1> 	sub	ecx, esi     ; required space for user registers
 14338 00010E7B 83C114              <1> 	add	ecx, 20	     ; +5 dwords to return from system call
 14339                              <1> 			     ; (for IRET)
 14340 00010E7E C1E902              <1> 	shr	ecx, 2
 14341 00010E81 F3A5                <1> 	rep	movsd
 14342 00010E83 C3                  <1> 	retn
 14343                              <1> 
 14344                              <1> rswap:  ; < swap in, swap from disk >
 14345                              <1> 	; 28/02/2017 (frstor)
 14346                              <1> 	; 15/01/2017
 14347                              <1> 	; 14/01/2017
 14348                              <1> 	; 21/05/2016
 14349                              <1> 	; 03/05/2016
 14350                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
 14351                              <1> 	; 09/05/2015 - 15/09/2015 (Retro UNIX 386 v1)
 14352                              <1> 	; 26/05/2013 - 08/03/2014 (Retro UNIX 8086 v1)
 14353                              <1> 	; 'rswap' reads a process whose number is in r1,
 14354                              <1> 	; from disk into core.
 14355                              <1> 	;
 14356                              <1> 	; Retro UNIX 386 v1 modification ->
 14357                              <1> 	;       User (u) structure content and the user's register content
 14358                              <1> 	;	will be restored from process's/user's UPAGE (a page for
 14359                              <1> 	;	saving 'u' structure and user registers for task switching).
 14360                              <1> 	;	u.usp - points to kernel stack address which contains
 14361                              <1> 	;		user's registers while entering system call.
 14362                              <1> 	;	u.sp  - points to kernel stack address 
 14363                              <1> 	;		to return from system call -for IRET-.
 14364                              <1> 	;	[u.usp]+32+16 = [u.sp] 
 14365                              <1> 	;	[u.usp] -> edi, esi, ebp, esp (= [u.usp]+32), ebx,
 14366                              <1> 	;		edx, ecx, eax, gs, fs, es, ds, -> [u.sp].
 14367                              <1> 	;
 14368                              <1> 	; RETRO UNIX 8086 v1 modification ->
 14369                              <1> 	;       'swap to disk' is replaced with 'change running segment'
 14370                              <1> 	;	according to 8086 cpu (x86 real mode) architecture.
 14371                              <1> 	;	pdp-11 was using 64KB uniform memory while IBM PC
 14372                              <1> 	;	compatibles was using 1MB segmented memory
 14373                              <1> 	;	in 8086/8088 times.
 14374                              <1> 	;
 14375                              <1> 	; INPUTS ->
 14376                              <1> 	;    r1 - process number of process to be read in
 14377                              <1> 	;    p.break - negative of word count of process
 14378                              <1> 	;    p.dska - disk address of the process
 14379                              <1> 	;    u.emt - determines handling of emt's
 14380                              <1> 	;    u.ilgins - determines handling of illegal instructions
 14381                              <1> 	; OUTPUTS ->
 14382                              <1> 	;    8 = (u.ilgins)
 14383                              <1> 	;    24 = (u.emt)
 14384                              <1> 	;    swp - bit 10 is set to indicate read 
 14385                              <1> 	;		(bit 15=0 when reading is done)
 14386                              <1> 	;    swp+2 - disk block address
 14387                              <1> 	;    swp+4 - negative word count
 14388                              <1> 	;      ((swp+6 - address of user structure))
 14389                              <1> 	;
 14390                              <1> 	; RETRO UNIX 8086 v1 input/output:
 14391                              <1> 	;
 14392                              <1> 	; INPUTS ->
 14393                              <1> 	;    AL	- new process number (to be swapped in)
 14394                              <1> 	; OUTPUTS ->
 14395                              <1> 	;    none
 14396                              <1> 	;
 14397                              <1> 	;   ((Modified registers: EAX, ECX, ESI, EDI, ESP))
 14398                              <1> 	;
 14399                              <1> 	; Retro UNIX 386 v1 - modification ! 14/05/2015
 14400 00010E84 89C6                <1> 	mov	esi, eax  ; process's user (u) structure page addr
 14401 00010E86 B93D000000          <1> 	mov	ecx, (U_SIZE + 3) / 4
 14402 00010E8B BF[6C940100]        <1> 	mov	edi, user ; active user (u) structure
 14403 00010E90 F3A5                <1> 	rep	movsd
 14404 00010E92 58                  <1> 	pop	eax	; 'rswap' return address
 14405                              <1> 	;
 14406                              <1> 	;cli
 14407 00010E93 8B3D[70940100]      <1> 	mov	edi, [u.usp] ; esp (system stack pointer,
 14408                              <1> 			     ;     points to user registers)
 14409 00010E99 89FC                <1> 	mov	esp, edi     ; 14/01/2017
 14410 00010E9B 8B0D[6C940100]      <1> 	mov	ecx, [u.sp]  ; return address from the system call
 14411                              <1> 			     ; (for IRET)
 14412                              <1> 			     ; [u.sp] -> EIP (user)
 14413                              <1> 			     ; [u.sp+4]-> CS (user)
 14414                              <1> 			     ; [u.sp+8] -> EFLAGS (user)
 14415                              <1> 			     ; [u.sp+12] -> ESP (user)
 14416                              <1> 			     ; [u.sp+16] -> SS (user)
 14417 00010EA1 29F9                <1> 	sub	ecx, edi     ; required space for user registers
 14418 00010EA3 83C114              <1> 	add	ecx, 20	     ; +5 dwords to return from system call
 14419                              <1> 			     ; (for IRET)
 14420 00010EA6 C1E902              <1> 	shr	ecx, 2
 14421 00010EA9 F3A5                <1> 	rep	movsd
 14422                              <1> 	;mov	esp, [u.usp] ; 15/09/2015
 14423                              <1> 	;sti
 14424                              <1> 	; 28/02/2017
 14425                              <1> 	;cmp	byte [multi_tasking], 0  ; Multi tasking mode ?
 14426                              <1> 	;jna	short rswp_retn
 14427 00010EAB 803D[F3940100]00    <1> 	cmp	byte [u.fpsave], 0
 14428 00010EB2 7606                <1> 	jna	short rswp_retn
 14429 00010EB4 DD25[F4940100]      <1> 	frstor	[u.fpregs] ; restore floating point regs (94 bytes)
 14430                              <1> 			; 108 bytes (22/08/2024)	
 14431                              <1> rswp_retn:
 14432 00010EBA 50                  <1> 	push	eax	; 'rswap' return address
 14433 00010EBB C3                  <1> 	retn
 14434                              <1> 
 14435                              <1> putlu: 
 14436                              <1> 	; 20/05/2016
 14437                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
 14438                              <1> 	; 10/05/2015 - 12/09/2015 (Retro UNIX 386 v1)
 14439                              <1> 	; 15/04/2013 - 23/02/2014 (Retro UNIX 8086 v1)
 14440                              <1> 	; 'putlu' is called with a process number in r1 and a pointer
 14441                              <1> 	; to lowest priority Q (runq+4) in r2. A link is created from
 14442                              <1> 	; the last process on the queue to process in r1 by putting
 14443                              <1> 	; the process number in r1 into the last process's link.
 14444                              <1> 	;
 14445                              <1> 	; INPUTS ->
 14446                              <1> 	;    r1 - user process number
 14447                              <1> 	;    r2 - points to lowest priority queue
 14448                              <1> 	;    p.dska - disk address of the process
 14449                              <1> 	;    u.emt - determines handling of emt's
 14450                              <1> 	;    u.ilgins - determines handling of illegal instructions
 14451                              <1> 	; OUTPUTS ->
 14452                              <1> 	;    r3 - process number of last process on the queue upon
 14453                              <1> 	;	  entering putlu
 14454                              <1> 	;    p.link-1 + r3 - process number in r1
 14455                              <1> 	;    r2 - points to lowest priority queue
 14456                              <1> 	;
 14457                              <1> 	; ((Modified registers: EDX, EBX))
 14458                              <1> 	;
 14459                              <1> 	; / r1 = user process no.; r2 points to lowest priority queue
 14460                              <1> 
 14461                              <1> 	; EBX = r2
 14462                              <1> 	; EAX = r1 (AL=r1b)
 14463                              <1> 
 14464                              <1> 	; 20/05/2016
 14465                              <1> 	; AL = process number (1 to 16) // Retro UNIX 8086, 386 v1 //
 14466                              <1> 	;     (max. 16 processes available for current kernel version)
 14467                              <1> 	; EBX = run queue address ; 20/05/2016 (TRDOS 386)
 14468                              <1> 		; which is one of following addresses:
 14469                              <1> 		;  1) 'runq_event' high priority run queue
 14470                              <1> 		;  2) 'runq_normal' normal/regular priority run queue
 14471                              <1> 		;  3) 'runq_background' low priority run queue
 14472                              <1> 
 14473                              <1> 	;mov	ebx, runq
 14474 00010EBC 0FB613              <1> 	movzx  	edx, byte [ebx]
 14475 00010EBF 43                  <1> 	inc	ebx
 14476 00010EC0 20D2                <1> 	and	dl, dl
 14477                              <1> 		; tstb (r2)+ / is queue empty?
 14478 00010EC2 740A                <1>        	jz	short putlu_1
 14479                              <1> 		; beq 1f / yes, branch
 14480 00010EC4 8A13                <1> 	mov 	dl, [ebx] ; 12/09/2015
 14481                              <1> 		; movb (r2),r3 / no, save the "last user" process number
 14482                              <1> 			     ; / in r3
 14483 00010EC6 8882[97930100]      <1>        	mov	[edx+p.link-1], al
 14484                              <1> 		; movb r1,p.link-1(r3) / put pointer to user on
 14485                              <1> 			     ; / "last users" link
 14486 00010ECC EB03                <1> 	jmp	short putlu_2
 14487                              <1> 		; br 2f /
 14488                              <1> putlu_1: ; 1:
 14489 00010ECE 8843FF              <1> 	mov	[ebx-1], al
 14490                              <1>        		; movb r1,-1(r2) / user is only user; 
 14491                              <1> 			    ; / put process no. at beginning and at end
 14492                              <1> putlu_2: ; 2: 
 14493 00010ED1 8803                <1> 	mov	[ebx], al
 14494                              <1>        		; movb r1,(r2) / user process in r1 is now the last entry
 14495                              <1> 			     ; / on the queue
 14496 00010ED3 88C2                <1> 	mov	dl, al
 14497 00010ED5 88B2[97930100]      <1>         mov     [edx+p.link-1], dh ; 0
 14498                              <1> 		; dec r2 / restore r2
 14499 00010EDB C3                  <1>         retn
 14500                              <1> 		; rts r0
 14501                              <1> 
 14502                              <1> sysver:
 14503                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
 14504 00010EDC C705[74940100]0002- <1> 	mov	dword [u.r0], 200h ; AH = major version, AL = minor version 
 14504 00010EE4 0000                <1>
 14505 00010EE6 E969BFFFFF          <1> 	jmp	sysret
 14506                              <1> 
 14507                              <1> syspri: ; change running priority (of the process)
 14508                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
 14509                              <1> 	; 21/05/2016
 14510                              <1> 	; 20/05/2026 - TRDOS 386 (TRDOS v2.0)
 14511                              <1> 	; INPUT ->
 14512                              <1> 	;	BL = priority level
 14513                              <1> 	;	   0 = low running priority (running on background)
 14514                              <1> 	;	   1 = normal/regular priority (running as regular)
 14515                              <1> 	;	   2 = high/event priority (running for event)
 14516                              <1> 	;	   >2 = invalid, it will accepted as 2 (event)
 14517                              <1> 	;	   0FFh = get/return current running priority only
 14518                              <1> 	; OUTPUT ->
 14519                              <1> 	;	* if current [u.pri] < 2
 14520                              <1> 	;	  if BL input < 0FFh ->
 14521                              <1> 	;	     [u.pri] is updated as in BL input (0,1,2)
 14522                              <1> 	;	  if BL input = 0FFh -> AL = [u.pri] (current)
 14523                              <1> 	;
 14524                              <1> 	;	* if current [u.pri] = 2
 14525                              <1> 	;	  if BL input < 0FFh -> cf = 1 & AL = 2
 14526                              <1> 	;	  if BL input = 0FFh -> cf = 0 & AL = 2
 14527                              <1> 	;
 14528                              <1> 	;	NOTE:
 14529                              <1> 	;	If [u.pri] = 2, it can not be changed to 1 or 0;
 14530                              <1> 	;	because, run queue of the running process is unspecified
 14531                              <1> 	;	at this	stage. Process might be started by a timer event
 14532                              <1> 	;	or priority might be changed to high by previous
 14533                              <1> 	;	'syspri' system	call. In both cases, the process is in
 14534                              <1> 	;	'runq_normal' or 'runq_background' queue.
 14535                              <1> 	;	As result of this fact, when the [u.quant] time quantum
 14536                              <1> 	;	of the process is elapsed or 'sysrele' system call is
 14537                              <1> 	;	instructed by the process, 'tswap' ('tswitch') procedure
 14538                              <1> 	;	will be called (to 'swap' or 'switch' out the procedure)
 14539                              <1> 	;	and it will not call 'putlu' to add the (stopping)
 14540                              <1> 	;	process to relevant run queue when [u.pri] = 2.
 14541                              <1> 	;	(Otherwise, it would be possible to add process to
 14542                              <1> 	;	a run queue while it is already in a run queue, wrongly.)
 14543                              <1>   	;
 14544                              <1> 	;	If [u.pri]< 2, 'tswap/tswitch' procedure will call
 14545                              <1> 	;	'putlu' to add process to relevant run queue
 14546                              <1> 	;	according to [u.pri] value. ('runq_normal' for 1,
 14547                              <1> 	;	'runq_background' for 0).
 14548                              <1> 	;
 14549                              <1> 	;	If BL input >= 2 and < 0FFh while [u.pri] < 2,
 14550                              <1> 	;	process will be added to 'runq_normal' queue and
 14551                              <1> 	;	[u.pri] will be set to 2. (in 'syspri' system call)
 14552                              <1> 	;
 14553                              <1> 
 14554 00010EEB 29C0                <1> 	sub	eax, eax ; 0
 14555 00010EED A3[E0940100]        <1> 	mov	[u.error], eax
 14556                              <1> 
 14557 00010EF2 A0[BE940100]        <1> 	mov	al, [u.pri]
 14558 00010EF7 A3[74940100]        <1> 	mov	[u.r0], eax
 14559                              <1> 
 14560 00010EFC FEC3                <1> 	inc	bl
 14561                              <1> 	;jz	sysret ; 0FFh -> 0, get priority level
 14562                              <1> 	; 23/07/2022
 14563 00010EFE 742C                <1> 	jz	short syspri_2	; jmp sysret
 14564                              <1> 
 14565 00010F00 3C02                <1> 	cmp	al, 2
 14566                              <1> 	;jnb	error ; CF = 1 & AL = 2 (& last error = 0)
 14567                              <1> 	; 23/07/2022
 14568 00010F02 7205                <1> 	jb	short syspri_0
 14569 00010F04 E92BBFFFFF          <1> 	jmp	error
 14570                              <1> syspri_0:
 14571 00010F09 FECB                <1> 	dec	bl
 14572 00010F0B 80FB02              <1> 	cmp	bl, 2
 14573 00010F0E 7602                <1> 	jna	short syspri_1
 14574 00010F10 B302                <1> 	mov	bl, 2
 14575                              <1> syspri_1:
 14576 00010F12 881D[BE940100]      <1> 	mov	[u.pri], bl
 14577 00010F18 80FB02              <1> 	cmp	bl, 2
 14578                              <1> 	;jb	sysret
 14579                              <1> 	; 23/07/2022
 14580 00010F1B 720F                <1> 	jb	short syspri_2	; jmp sysret
 14581                              <1> 
 14582                              <1> 	; here...
 14583                              <1> 	; Priority of current process has been changed to high
 14584                              <1> 	; ('run for event') but current process will be added to
 14585                              <1> 	; 'run as normal' queue. ('run for event' high priority
 14586                              <1> 	; queue is under control of timer -& RTC- interrupt only!)
 14587                              <1> 	;
 14588                              <1> 	; (Otherwise, process can fall into black hole!
 14589                              <1> 	; e.g. if it is not in waiting list and it has not got
 14590                              <1> 	; a timer event and it is not in a run queue!
 14591                              <1> 	; Because, when [u.pri] is 2, 'tswap/tswitch' will not
 14592                              <1> 	; add the stopping process to a run queue.)
 14593                              <1> 
 14594 00010F1D A0[C5940100]        <1> 	mov	al, [u.uno]
 14595 00010F22 BB[64940100]        <1> 	mov	ebx, runq_normal ; normal priority !
 14596                              <1> 				 ; [u.pri] is set to high
 14597                              <1> 				 ; but 'runq_event' queue is set
 14598                              <1> 				 ; only by the kernel's timer
 14599                              <1> 				 ; event function (timer interrupt). 
 14600 00010F27 E890FFFFFF          <1> 	call	putlu
 14601                              <1> syspri_2:
 14602 00010F2C E923BFFFFF          <1> 	jmp	sysret
 14603                              <1> 
 14604                              <1> cpass: ; / get next character from user area of core and put it in AL (r1)
 14605                              <1> 	; 30/07/2022 - TRDOS 386 Kernel v2.0.5
 14606                              <1> 	; 02/05/2016 - TRDOS 386 (TRDOS v2.0)
 14607                              <1> 	; 19/05/2015 - 18/10/2015 (Retro UNIX 386 v1)
 14608                              <1> 	; 14/08/2013 - 20/09/2013 (Retro UNIX 8086 v1)
 14609                              <1> 	; INPUTS -> 
 14610                              <1> 	;     [u.base] = virtual address in user area
 14611                              <1> 	;     [u.count] = byte count (max.)
 14612                              <1> 	;     [u.pcount] = byte count in page (0 = reset)
 14613                              <1> 	; OUTPUTS -> 
 14614                              <1> 	;     AL = the character which is pointed by [u.base]
 14615                              <1> 	;     zf = 1 -> transfer count has been completed
 14616                              <1>         ;
 14617                              <1> 	; ((Modified registers: EAX, EDX, ECX))
 14618                              <1> 	
 14619                              <1> 	; 30/07/2022
 14620 00010F31 29C0                <1> 	sub	eax, eax
 14621                              <1> 	
 14622 00010F33 3905[9C940100]      <1> 	cmp	[u.count], eax ; 0
 14623                              <1> 	;cmp 	dword [u.count], 0  ; have all the characters been transferred
 14624                              <1> 			    	    ; i.e., u.count, # of chars. left
 14625 00010F39 763D                <1> 	jna	short cpass_3	    ; to be transferred = 0?) yes, branch
 14626 00010F3B FF0D[9C940100]      <1> 	dec	dword [u.count]	    ; no, decrement u.count
 14627                              <1>         ; 19/05/2015 
 14628                              <1> 	;(Retro UNIX 386 v1 - translation from user's virtual address
 14629                              <1> 	;		      to physical address
 14630                              <1> 	; 30/07/2022
 14631 00010F41 663905[D8940100]    <1> 	cmp	[u.pcount], ax ; 0
 14632                              <1> 	;cmp	word [u.pcount], 0 ; byte count in page = 0 (initial value)
 14633                              <1> 			     ; 1-4095 --> use previous physical base address
 14634                              <1> 			     ; in [u.pbase]
 14635 00010F48 770D                <1> 	ja	short cpass_1
 14636                              <1> 	; 30/07/2022
 14637 00010F4A 3905[D0940100]      <1> 	cmp	[u.ppgdir], eax ; 0
 14638                              <1> 	;cmp	dword [u.ppgdir], 0 ; is the caller os kernel
 14639 00010F50 7427                <1>         je      short cpass_k       ; (sysexec, '/etc/init') ?  (MainProg)
 14640 00010F52 E861FDFFFF          <1> 	call	trans_addr_r
 14641                              <1> cpass_1:
 14642 00010F57 66FF0D[D8940100]    <1> 	dec	word [u.pcount]
 14643                              <1> cpass_2: 
 14644 00010F5E 8B15[D4940100]      <1> 	mov	edx, [u.pbase]
 14645 00010F64 8A02                <1> 	mov	al, [edx]	; take the character pointed to
 14646                              <1> 				; by u.base and put it in r1
 14647 00010F66 FF05[A0940100]      <1> 	inc	dword [u.nread] ; increment no. of bytes transferred
 14648 00010F6C FF05[98940100]      <1> 	inc	dword [u.base]  ; increment the buffer address to point to the
 14649                              <1> 			        ; next byte
 14650 00010F72 FF05[D4940100]      <1> 	inc	dword [u.pbase]
 14651                              <1> cpass_3:
 14652 00010F78 C3                  <1> 	retn
 14653                              <1> cpass_k:
 14654                              <1> 	; 02/07/2015
 14655                              <1> 	; The caller is os kernel
 14656                              <1> 	; (get sysexec arguments from kernel's memory space)
 14657 00010F79 8B1D[98940100]      <1> 	mov	ebx, [u.base]
 14658 00010F7F 66C705[D8940100]00- <1>         mov     word [u.pcount], PAGE_SIZE ; 4096
 14658 00010F87 10                  <1>
 14659 00010F88 891D[D4940100]      <1> 	mov	[u.pbase], ebx
 14660 00010F8E EBCE                <1> 	jmp	short cpass_2
 14661                              <1> 
 14662                              <1> transfer_to_user_buffer: ; fast transfer
 14663                              <1> 	; 27/05/2016
 14664                              <1> 	; 16/05/2016 - TRDOS 386 (TRDOS v2.0)
 14665                              <1> 	;
 14666                              <1> 	; INPUT ->
 14667                              <1> 	;	ESI = source address in system space
 14668                              <1> 	;	EDI = user's buffer address
 14669                              <1> 	;	ECX = transfer (byte) count
 14670                              <1> 	;	[u.pgdir] = user's page directory
 14671                              <1> 	; OUTPUT ->
 14672                              <1> 	;	ECX = actual transfer count
 14673                              <1> 	;	cf = 1 -> error
 14674                              <1> 	;	[u.count] = remain byte count
 14675                              <1> 	;
 14676                              <1> 	; Modified registers: eax, ecx
 14677                              <1> 	;
 14678                              <1> 
 14679 00010F90 21C9                <1> 	and	ecx, ecx
 14680 00010F92 743B                <1> 	jz	short ttub_4
 14681                              <1> 
 14682 00010F94 890D[9C940100]      <1> 	mov	[u.count], ecx
 14683                              <1> 	
 14684 00010F9A 57                  <1> 	push	edi
 14685 00010F9B 56                  <1> 	push	esi
 14686 00010F9C 53                  <1> 	push	ebx
 14687 00010F9D 52                  <1> 	push	edx
 14688 00010F9E 51                  <1> 	push	ecx
 14689                              <1> 
 14690 00010F9F 89FB                <1> 	mov	ebx, edi
 14691 00010FA1 81C300004000        <1> 	add	ebx, CORE ; 27/05/2016
 14692                              <1> ttub_1:
 14693                              <1> 	; ebx = virtual (linear) address
 14694                              <1> 	; [u.pgdir] = user's page directory
 14695 00010FA7 E8184CFFFF          <1>        	call	get_physical_addr_x ; get physical address
 14696 00010FAC 7222                <1> 	jc	short ttub_5
 14697                              <1> 	; eax = physical address 
 14698                              <1> 	; ecx = remain byte count in page (1-4096)
 14699 00010FAE 89C7                <1> 	mov	edi, eax
 14700 00010FB0 A1[9C940100]        <1> 	mov	eax, [u.count]
 14701 00010FB5 39C1                <1> 	cmp	ecx, eax
 14702 00010FB7 7602                <1> 	jna	short ttub_2
 14703 00010FB9 89C1                <1> 	mov	ecx, eax
 14704                              <1> ttub_2:	
 14705 00010FBB 29C8                <1> 	sub	eax, ecx
 14706 00010FBD 01CB                <1> 	add	ebx, ecx
 14707 00010FBF F3A4                <1> 	rep	movsb
 14708 00010FC1 A3[9C940100]        <1> 	mov	[u.count], eax
 14709 00010FC6 09C0                <1> 	or	eax, eax
 14710 00010FC8 75DD                <1> 	jnz	short ttub_1
 14711                              <1> ttub_retn:
 14712                              <1> tfub_retn:
 14713 00010FCA 59                  <1> 	pop	ecx ; transfer count = actual transfer count
 14714                              <1> ttub_3:
 14715 00010FCB 5A                  <1> 	pop	edx
 14716 00010FCC 5B                  <1> 	pop	ebx
 14717 00010FCD 5E                  <1> 	pop	esi
 14718 00010FCE 5F                  <1> 	pop	edi
 14719                              <1> ttub_4:
 14720 00010FCF C3                  <1> 	retn
 14721                              <1> ttub_5:
 14722 00010FD0 59                  <1> 	pop	ecx
 14723 00010FD1 2B0D[9C940100]      <1> 	sub	ecx, [u.count] ; actual transfer count
 14724 00010FD7 F9                  <1> 	stc
 14725 00010FD8 EBF1                <1> 	jmp	short ttub_3
 14726                              <1> 
 14727                              <1> transfer_from_user_buffer: ; fast transfer
 14728                              <1> 	; 27/05/2016
 14729                              <1> 	; 16/05/2016 - TRDOS 386 (TRDOS v2.0)
 14730                              <1> 	;
 14731                              <1> 	; INPUT ->
 14732                              <1> 	;	ESI = user's buffer address
 14733                              <1> 	;	EDI = destination address in system space
 14734                              <1> 	;	ECX = transfer (byte) count
 14735                              <1> 	;	[u.pgdir] = user's page directory
 14736                              <1> 	; OUTPUT ->
 14737                              <1> 	;	ecx = actual transfer count
 14738                              <1> 	;	cf = 1 -> error
 14739                              <1> 	;	[u.count] = remain byte count
 14740                              <1> 	;
 14741                              <1> 	; Modified registers: eax, ecx
 14742                              <1> 	;
 14743                              <1> 
 14744 00010FDA 21C9                <1> 	and	ecx, ecx
 14745                              <1> 	;jz	short tfub_4
 14746 00010FDC 74F1                <1> 	jz	short ttub_4
 14747                              <1> 
 14748 00010FDE 890D[9C940100]      <1> 	mov	[u.count], ecx
 14749                              <1> 
 14750 00010FE4 57                  <1> 	push	edi
 14751 00010FE5 56                  <1> 	push	esi
 14752 00010FE6 53                  <1> 	push	ebx
 14753 00010FE7 52                  <1> 	push	edx
 14754 00010FE8 51                  <1> 	push	ecx
 14755                              <1> 
 14756 00010FE9 89F3                <1> 	mov	ebx, esi
 14757 00010FEB 81C300004000        <1> 	add	ebx, CORE ; 27/05/2016
 14758                              <1> tfub_1:
 14759                              <1> 	; ebx = virtual (linear) address
 14760                              <1> 	; [u.pgdir] = user's page directory
 14761 00010FF1 E8CE4BFFFF          <1>        	call	get_physical_addr_x ; get physical address
 14762                              <1> 	;jc	short tfub_5
 14763 00010FF6 72D8                <1> 	jc	short ttub_5
 14764                              <1> 	; eax = physical address 
 14765                              <1> 	; ecx = remain byte count in page (1-4096)
 14766 00010FF8 89C6                <1> 	mov	esi, eax
 14767 00010FFA A1[9C940100]        <1> 	mov	eax, [u.count]
 14768 00010FFF 39C1                <1> 	cmp	ecx, eax
 14769 00011001 7602                <1> 	jna	short tfub_2
 14770 00011003 89C1                <1> 	mov	ecx, eax
 14771                              <1> tfub_2:	
 14772 00011005 29C8                <1> 	sub	eax, ecx
 14773 00011007 01CB                <1> 	add	ebx, ecx
 14774 00011009 F3A4                <1> 	rep	movsb
 14775 0001100B A3[9C940100]        <1> 	mov	[u.count], eax
 14776 00011010 09C0                <1> 	or	eax, eax
 14777 00011012 75DD                <1> 	jnz	short tfub_1
 14778                              <1> 
 14779 00011014 EBB4                <1> 	jmp	short tfub_retn
 14780                              <1> 
 14781                              <1> ;tfub_retn:
 14782                              <1> ;	pop	ecx ; transfer count = actual transfer count
 14783                              <1> ;tfub_3:
 14784                              <1> ;	pop	edx
 14785                              <1> ;	pop	ebx
 14786                              <1> ;	pop	esi
 14787                              <1> ;	pop	edi
 14788                              <1> ;tfub_4:
 14789                              <1> ;	retn
 14790                              <1> ;tfub_5:
 14791                              <1> ;	pop	ecx
 14792                              <1> ;	sub	ecx, [u.count] ; actual transfer count
 14793                              <1> ;	stc
 14794                              <1> ;	jmp	short tfub_3
 14795                              <1> 
 14796                              <1> sysfff: ; <Find First File>
 14797                              <1> 	; 25/08/2024 (TRDOS 386 Kernel v2.0.9)
 14798                              <1> 	; 08/08/2022
 14799                              <1> 	; 30/07/2022 (TRDOS 386 Kernel v2.0.5)
 14800                              <1> 	; 17/10/2016
 14801                              <1> 	; 16/10/2016
 14802                              <1> 	; 15/10/2016 TRDOS 386 (TRDOS v2.0) feature only !
 14803                              <1> 	;           -derived from TRDOS v1.0, INT_21H.ASM-
 14804                              <1> 	;            ("loc_INT21h_find_first_file")
 14805                              <1> 	; TRDOS 8086 (v1.0)
 14806                              <1>         ; 	07/08/2011 
 14807                              <1>         ;	Find First File
 14808                              <1> 	;	INPUT:
 14809                              <1>         ;	    CX= Attributes
 14810                              <1>         ;	    DS:DX= Pointer to filename
 14811                              <1> 	;	MSDOS OUTPUT:
 14812                              <1> 	;	    DTA: (Default address: PSP offset 80h)
 14813                              <1> 	;	    Offset  Descrription
 14814                              <1> 	;	    0	    Reserved for use find next file
 14815                              <1> 	;	    21	    Attribute of file found
 14816                              <1> 	;	    22	    Time stamp of file
 14817                              <1> 	;	    24	    Date stamp of file
 14818                              <1> 	;	    26	    File size in bytes
 14819                              <1> 	;	    30	    Filename and extension (zero terminated)
 14820                              <1> 	;	If cf = 1:
 14821                              <1> 	;	    Error Codes: (in AX)
 14822                              <1> 	;	    	2 - File not found
 14823                              <1> 	;	       18 - No more files
 14824                              <1>         ;
 14825                              <1> 	; TRDOS 386 (v2.0) 
 14826                              <1> 	; 15/10/2016
 14827                              <1> 	;	
 14828                              <1>         ; INPUT ->
 14829                              <1>         ;	   CL = File attributes
 14830                              <1> 	;     	      bit 0 (1) - Read only file (R)
 14831                              <1> 	;             bit 1 (1) - Hidden file (H)
 14832                              <1>         ;             bit 2 (1) - System file (R)
 14833                              <1> 	;             bit 3 (1) - Volume label/name (V)
 14834                              <1>         ;             bit 4 (1) - Subdirectory (D)
 14835                              <1> 	;	      bit 5 (1) - File has been archived (A)
 14836                              <1> 	;	   CH = 0 -> Return basic parameters (24 bytes)
 14837                              <1> 	;	   CH > 0 -> Return FindFile structure/table (128 bytes)
 14838                              <1>         ;          EBX = Pointer to filename (ASCIIZ) -path-
 14839                              <1> 	;	   EDX = File parameters buffer address
 14840                              <1> 	;		(buffer size = 24 bytes if CH input = 0)
 14841                              <1> 	;		(buffer size = 128 bytes if CH input > 0)
 14842                              <1> 	;
 14843                              <1> 	; OUTPUT ->
 14844                              <1> 	;	   EAX = 0 if CH input > 0
 14845                              <1> 	;	   EAX = First cluster number of file if CH input = 0
 14846                              <1> 	;	   EDX = File parameters table/structure address
 14847                              <1> 	;	   Basic Parameters:
 14848                              <1> 	;		Offset  Description
 14849                              <1> 	;		------	---------------
 14850                              <1> 	;		0	File Attributes
 14851                              <1> 	;		1	Ambiguous filename chars are used sign
 14852                              <1> 	;			(0 = filename fits exactly with request)
 14853                              <1> 	;			(>0 = ambiguous filename chars are used)
 14854                              <1> 	;	      	2	Time stamp of file
 14855                              <1> 	;		4	Date stamp of file
 14856                              <1> 	;		6	File size in bytes
 14857                              <1> 	;		10	Short Filename (ASCIIZ, max. 13 bytes)
 14858                              <1> 	;		23	Longname Length (1-255) if existing
 14859                              <1> 	;
 14860                              <1> 	;          cf = 1 -> Error code in AL
 14861                              <1> 	;
 14862                              <1> 	; Modified Registers: EAX (at the return of system call)
 14863                              <1> 	;  
 14864                              <1> 	; TR-DOS FindFile (FFF) Structure (128 bytes):
 14865                              <1> 	; 09/10/2011 (DIR.ASM) - 10/02/2016 (trdoskx.s)
 14866                              <1> 	;
 14867                              <1> 	; Offset	Parameter		Size
 14868                              <1> 	; ------	------------------	--------
 14869                              <1> 	; 0		FindFile_Drv		1 byte
 14870                              <1> 	; 1		FindFile_Directory	65 bytes
 14871                              <1> 	; 66		FindFile_Name		13 bytes
 14872                              <1> 	; 79		FindFile_LongNameEntryLength 1 byte
 14873                              <1> 	;Above 80 bytes form
 14874                              <1> 	;TR-DOS Source/Destination File FullName Format/Structure
 14875                              <1> 	; 80		FindFile_AttributesMask 1 word
 14876                              <1> 	; 82		FindFile_DirEntry	32 bytes (*)
 14877                              <1> 	; 114		FindFile_DirFirstCluster 1 double word
 14878                              <1> 	; 118		FindFile_DirCluster	1 double word
 14879                              <1> 	; 122		FindFile_DirEntryNumber 1 word
 14880                              <1> 	; 124		FindFile_MatchCounter	1 word
 14881                              <1> 	; 126		FindFile_Reserved	1 word
 14882                              <1>    	; (*) MS-DOS, FAT 12-16-32 classic directory entry (32 bytes)
 14883                              <1> 
 14884                              <1> 	;mov	[u.namep], ebx
 14885                              <1> 	; 16/10/2016
 14886 00011016 8915[70890100]      <1> 	mov	[FFF_UBuffer], edx
 14887 0001101C 66890D[75890100]    <1> 	mov	[FFF_Attrib], cx ; [FFF_RType] = ch
 14888                              <1> 		    ; Attributes in CL, return data type in CH
 14889 00011023 89DE                <1> 	mov	esi, ebx
 14890                              <1> 	; file name is forced, change directory as temporary
 14891                              <1> 	;mov	ax, 1
 14892                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset ; 17/10/2016
 14893                              <1> 	;call	set_working_path
 14894 00011025 E8B8120000          <1> 	call	set_working_path_x ; 17/10/2016
 14895 0001102A 731D                <1> 	jnc	short sysfff_0
 14896                              <1> 
 14897 0001102C 21C0                <1> 	and	eax, eax  ; 0 -> Bad Path!
 14898 0001102E 7505                <1> 	jnz	short sysfff_err
 14899                              <1> 
 14900                              <1> 	; eax = 0
 14901 00011030 B80C000000          <1> 	mov	eax, ERR_DIR_NOT_FOUND ; Directory not found !
 14902                              <1> sysfff_err:
 14903 00011035 A3[74940100]        <1> 	mov	[u.r0], eax
 14904 0001103A A3[E0940100]        <1> 	mov	[u.error], eax
 14905 0001103F E873130000          <1>         call 	reset_working_path
 14906 00011044 E9EBBDFFFF          <1> 	jmp	error
 14907                              <1> 
 14908                              <1> sysfff_0:
 14909                              <1> 	;;;
 14910                              <1> 	; 25/08/2024 (bugfix)
 14911                              <1> 	;mov	al, [esp] ; ???
 14912 00011049 A0[75890100]        <1> 	mov	al, [FFF_Attrib]
 14913                              <1> 	;;;
 14914 0001104E 08C0                <1> 	or	al, al
 14915 00011050 7412                <1> 	jz	short sysfff_2
 14916 00011052 B410                <1> 	mov	ah, 10h
 14917 00011054 A808                <1> 	test	al, 08h
 14918 00011056 7503                <1> 	jnz	short sysfff_1
 14919 00011058 80CC08              <1> 	or	ah, 08h
 14920                              <1> sysfff_1:
 14921 0001105B 2410                <1> 	and	al, 10h ; Directory
 14922 0001105D 7405                <1> 	jz	short sysfff_2
 14923 0001105F 80E408              <1> 	and	ah, 08h
 14924 00011062 30C0                <1> 	xor	al, al ; When a directory is searched,
 14925                              <1> 		       ; filename will be returned even if
 14926                              <1> 		       ; it is not a directory!
 14927                              <1> 		       ; Because: (in order to prevent
 14928                              <1> 		       ; creating a dir with existing file name)
 14929                              <1> 		       ; Dir and file names must not be same!
 14930                              <1> 		       ; (return attribute must be checked)
 14931                              <1> sysfff_2:
 14932                              <1> 	; AX = Attributes mask
 14933                              <1> 		; AL = AND mask (result must be equal to AL)
 14934                              <1> 		; AH = Negative AND mask (result must be ZERO)
 14935                              <1>  	; ESI = FindFile_Name address
 14936                              <1> 
 14937 00011064 E8017BFFFF          <1> 	call	find_first_file
 14938 00011069 72CA                <1> 	jc	short sysfff_err ; eax = 2 (File not found !)
 14939                              <1> 
 14940                              <1> 	; ESI = Directory Entry (FindFile_DirEntry) Location
 14941                              <1> 	; EDI = Directory Buffer Directory Entry Location
 14942                              <1> 	; EAX = File Size
 14943                              <1> 	;  BL = Attributes of The File/Directory
 14944                              <1> 	;  BH = Long Name Yes/No Status (>0 is YES)
 14945                              <1> 	;  DX > 0 : Ambiguous filename chars are used
 14946                              <1> 
 14947                              <1> sysfff_3:
 14948                              <1> 	; 16/10/2016
 14949 0001106B 668B0D[75890100]    <1> 	mov	cx, [FFF_Attrib]
 14950                              <1> 	; Attribs in CL, return data type in CH
 14951                              <1> 
 14952                              <1> 	;or	cl, cl
 14953                              <1> 	;jz	short sysfff_4 ; 0 = No filter
 14954 00011072 80F1FF              <1> 	xor	cl, 0FFh
 14955                              <1> 	; cl = negative attributes ; 25/08/2024
 14956 00011075 20D9                <1> 	and	cl, bl
 14957 00011077 7409                <1> 	jz	short sysfff_4
 14958                              <1> 
 14959                              <1> 	;mov	eax, 2 ; 'file not found !' error
 14960                              <1> 	;jmp	short sysfff_err_1
 14961                              <1> 
 14962                              <1> 	; 16/10/2016
 14963 00011079 E8997BFFFF          <1> 	call	find_next_file
 14964 0001107E 72B5                <1> 	jc	short sysfff_err ; eax = 12 (no more files !)
 14965 00011080 EBE9                <1> 	jmp	short sysfff_3
 14966                              <1> 
 14967                              <1> sysfff_4:
 14968 00011082 20ED                <1> 	and	ch, ch ; [FFF_RType]
 14969                              <1> 	;jz	short sysfff_5
 14970                              <1> 	; 25/08/2024
 14971 00011084 755A                <1> 	jnz	short sysfff_7
 14972                              <1> 
 14973                              <1> 	;mov	ecx, 128 ; ; transfer length
 14974                              <1> 	; 30/07/2022
 14975                              <1> 	;sub	ecx, ecx
 14976                              <1> 	;mov	cl, 128
 14977                              <1> 	;mov	[FFF_Valid], cl
 14978                              <1> 	; 25/08/2024
 14979                              <1> 	;mov	byte [FFF_Valid], 128 ; (*)
 14980                              <1> 	;jmp	short sysfff_7 ; sysfnf_11
 14981                              <1> 
 14982                              <1> sysfff_5:
 14983                              <1> 	;;mov	esi, FindFile_DirEntry
 14984                              <1> 	;mov	ecx, 24  ; transfer length
 14985                              <1> 	; 30/07/2022
 14986                              <1> 	;sub	ecx, ecx
 14987                              <1> 	;mov	cl, 24
 14988                              <1> 	;mov	[FFF_Valid], cl
 14989 00011086 C605[74890100]18    <1> 	mov	byte [FFF_Valid], 24 ; (*)
 14990                              <1> sysfnf_12:
 14991 0001108D BF[408E0100]        <1> 	mov	edi, DTA ; FFF data transfer address
 14992                              <1> 	;mov	al, [esi+DirEntry_Attr] ; 11
 14993 00011092 88D8                <1> 	mov	al, bl ; File/Dir Attributes
 14994 00011094 887F17              <1> 	mov	[edi+23], bh ; Longname length (0= none)
 14995 00011097 AA                  <1> 	stosb
 14996 00011098 88D0                <1> 	mov	al, dl ; DL is for '?'
 14997 0001109A 00F0                <1> 	add	al, dh ; DH is for '*'
 14998                              <1> 	; AL > 0 if ambiguous file name wildcards are used
 14999 0001109C AA                  <1> 	stosb
 15000 0001109D 8B4616              <1> 	mov	eax, [esi+DirEntry_WrtTime] ; 22
 15001 000110A0 AB                  <1>         stosd	; DirEntry_WrtTime & DirEntry_WrtDate
 15002 000110A1 8B461C              <1>         mov	eax, [esi+DirEntry_FileSize] ; 28
 15003 000110A4 AB                  <1>         stosd
 15004 000110A5 668B4614            <1> 	mov	ax, [esi+DirEntry_FstClusHI] ; 20
 15005                              <1> 	;shl	ax, 16
 15006                              <1> 	; 23/07/2022 (BugFix)
 15007 000110A9 C1E010              <1> 	shl	eax, 16 
 15008 000110AC 668B461A            <1> 	mov	ax, [esi+DirEntry_FstClusLO] ; 26
 15009 000110B0 A3[74940100]        <1> 	mov	[u.r0], eax ; First Cluster
 15010                              <1> 
 15011                              <1>         ;mov	esi, FindFile_DirEntry
 15012 000110B5 E83A130000          <1> 	call	get_file_name
 15013                              <1> 	
 15014                              <1> 	; 25/08/2024
 15015                              <1> 	; ecx <= 7 (from 'get_file_name')
 15016                              <1> 	;mov	cl, [FFF_Valid] ; (*)
 15017 000110BA BE[408E0100]        <1>        	mov	esi, DTA ; FFF data transfer address
 15018                              <1> 
 15019                              <1> sysfff_6:
 15020                              <1> 	; 25/08/2024
 15021                              <1> 	;sub	ecx, ecx
 15022 000110BF 8A0D[74890100]      <1> 	mov	cl, [FFF_Valid] ; (*) ecx <= 128
 15023                              <1> 
 15024 000110C5 8B3D[70890100]      <1> 	mov	edi, [FFF_UBuffer] ; user's buffer address (edx)
 15025 000110CB E8C0FEFFFF          <1> 	call	transfer_to_user_buffer
 15026                              <1> 
 15027 000110D0 890D[74940100]      <1> 	mov	[u.r0], ecx ; actual transfer count
 15028 000110D6 E8DC120000          <1>         call 	reset_working_path
 15029 000110DB E974BDFFFF          <1> 	jmp	sysret
 15030                              <1> 
 15031                              <1> sysfff_7:
 15032                              <1> 	; 25/08/2024
 15033 000110E0 C605[74890100]80    <1> 	mov	byte [FFF_Valid], 128 ; (*)
 15034                              <1> sysfnf_11:
 15035                              <1> 	; ecx = 128
 15036                              <1> 	; 25/08/2024 (bugfix)
 15037                              <1> 	; 08/08/2022
 15038 000110E7 BE[22860100]        <1> 	mov	esi, FindFile_Drv
 15039                              <1> 	; 25/08/2024
 15040 000110EC 29C9                <1> 	sub	ecx, ecx ; 0
 15041 000110EE EBCF                <1> 	jmp	short sysfff_6
 15042                              <1> 
 15043                              <1> sysfnf: ; <Find Next File>
 15044                              <1> 	; 25/08/2024 (TRDOS 386 Kernel v2.0.9)
 15045                              <1> 	; 29/08/2023 (TRDOS 386 Kernel v2.0.6)
 15046                              <1> 	; 08/08/2022
 15047                              <1> 	; 30/07/2022 (TRDOS 386 Kernel v2.0.5)
 15048                              <1> 	; 16/10/2016 TRDOS 386 (TRDOS v2.0) feature only !
 15049                              <1> 	;           -derived from TRDOS v1.0, INT_21H.ASM-
 15050                              <1> 	;            ("loc_INT21h_find_next_file")
 15051                              <1> 	; TRDOS 8086 (v1.0)
 15052                              <1>         ; 	07/08/2011 
 15053                              <1>         ;	Find First File
 15054                              <1> 	;	INPUT:
 15055                              <1>         ;	    none
 15056                              <1> 	;	MSDOS OUTPUT:
 15057                              <1> 	;	    DTA: (Default address: PSP offset 80h)
 15058                              <1> 	;	    Offset  Descrription
 15059                              <1> 	;	    0	    Reserved for use find next file
 15060                              <1> 	;	    21	    Attribute of file found
 15061                              <1> 	;	    22	    Time stamp of file
 15062                              <1> 	;	    24	    Date stamp of file
 15063                              <1> 	;	    26	    File size in bytes
 15064                              <1> 	;	    30	    Filename and extension (zero terminated)
 15065                              <1> 	;	If cf = 1:
 15066                              <1> 	;	    Error Codes: (in AX)
 15067                              <1> 	;	       18 - No more files
 15068                              <1>         ;
 15069                              <1> 	; TRDOS 386 (v2.0) 
 15070                              <1> 	; 16/10/2016
 15071                              <1> 	;
 15072                              <1>         ; INPUT ->
 15073                              <1>        	; 	   none
 15074                              <1> 	; OUTPUT ->
 15075                              <1> 	;	   EAX = 0 if CH input of 'Find First File' > 0
 15076                              <1> 	;	   EAX = First cluster number of file
 15077                              <1> 	;		 if CH input of 'Find First File' = 0
 15078                              <1> 	;	   EDX = File parameters table/structure address
 15079                              <1> 	;
 15080                              <1> 	;          cf = 1 -> Error code in AL
 15081                              <1> 	;
 15082                              <1>  	; Modified Registers: EAX (at the return of system call)
 15083                              <1> 
 15084                              <1> 	; Note: If byte [FFF_Valid] = 0
 15085                              <1> 	;	'sysfnf' will return with 'no more files' error.
 15086                              <1> 	;	If byte [FFF_Valid] = 24
 15087                              <1> 	;	'sysfnf' will return with 24 bytes basic parameters
 15088                              <1> 	;	at the address which is in EDX.
 15089                              <1> 	;	If byte [FFF_Valid] = 128
 15090                              <1> 	;	'sysfnf' will return with 128 bytes Find File
 15091                              <1> 	;	Structure/Table at the address which is in EDX.
 15092                              <1> 
 15093 000110F0 803D[74890100]00    <1> 	cmp	byte [FFF_Valid], 0
 15094 000110F7 7713                <1> 	ja	short stsfnf_0
 15095                              <1>  	; 'no more files !' error
 15096                              <1> 	;mov	eax, ERR_NO_MORE_FILES ; 12
 15097                              <1> 	; 30/07/2022
 15098 000110F9 29C0                <1> 	sub	eax, eax
 15099 000110FB B00C                <1> 	mov	al, ERR_NO_MORE_FILES ; 12
 15100 000110FD A3[74940100]        <1> 	mov	[u.r0], eax
 15101 00011102 A3[E0940100]        <1> 	mov	[u.error], eax
 15102 00011107 E928BDFFFF          <1> 	jmp	error
 15103                              <1> 
 15104                              <1> stsfnf_0:
 15105                              <1> 	;cmp	byte [FFF_Valid], 128
 15106                              <1> 	;je	short stsfnf_1
 15107                              <1> 	;cmp	byte [FFF_Valid], 24
 15108                              <1> 	;je	short stsfnf_1
 15109                              <1> 	;mov	[FFF_Valid], 24 ; Default
 15110                              <1> stsfnf_1:
 15111 0001110C 0FB61D[827D0100]    <1> 	movzx	ebx, byte [Current_Drv]
 15112 00011113 66891D[7A890100]    <1> 	mov	[SWP_DRV], bx
 15113 0001111A 8A15[22860100]      <1> 	mov	dl, [FindFile_Drv]
 15114 00011120 38DA                <1> 	cmp	dl, bl
 15115 00011122 7532                <1> 	jne	short stsfnf_2
 15116 00011124 86DF                <1> 	xchg	bh, bl
 15117 00011126 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 15118 0001112B 01DE                <1> 	add	esi, ebx
 15119 0001112D EB34                <1> 	jmp	short sysfnf_3
 15120                              <1> 
 15121                              <1> sysfnf_8:
 15122 0001112F E8A8B3FFFF          <1> 	call	load_FAT_sub_directory
 15123 00011134 7272                <1> 	jc	short sysfnf_err_1 ; read error (no FNF stop)
 15124                              <1> 
 15125                              <1> sysfnf_9:
 15126 00011136 E8DC7AFFFF          <1> 	call	find_next_file
 15127 0001113B 7260                <1> 	jc	short sysfnf_5
 15128                              <1> 	; 25/08/2024
 15129                              <1> 	; esi = Directory Entry (FindFile_DirEntry) Location
 15130                              <1> 	;; 08/08/2022
 15131                              <1> 	;; esi = FindFile_Drv ; wrong ! ; 25/08/2024
 15132                              <1> 
 15133 0001113D A0[75890100]        <1> 	mov	al, [FFF_Attrib]
 15134                              <1> 	;or	al, al
 15135                              <1> 	;jz	short sysfnf_10 ; 0 = No filter
 15136 00011142 34FF                <1> 	xor	al, 0FFh
 15137 00011144 20D8                <1> 	and	al, bl
 15138 00011146 75EE                <1> 	jnz	short sysfnf_9 ; search for next file until
 15139                              <1> 			       ; an error return from
 15140                              <1> 			       ; find_next_file procedure
 15141                              <1> sysfnf_10:
 15142                              <1>         ;movzx	ecx, byte [FFF_Valid]
 15143                              <1> 	;cmp	cl, 128 ; complete FindFile structure/table
 15144                              <1> 	;je	sysfnf_11
 15145                              <1> 	;;cmp	cl, 24  ; basic parameters
 15146                              <1> 	;;je	sysfnf_12
 15147                              <1> 	;jmp	sysfnf_12
 15148                              <1> 	; 30/07/2022
 15149                              <1> 	;movzx	ecx, byte [FFF_Valid]
 15150                              <1> 	; 25/08/2024
 15151                              <1> 	;cmp	cl, 128
 15152 00011148 803D[74890100]80    <1> 	cmp	byte [FFF_Valid], 128 
 15153                              <1> 	;jne	short sysfnf_12
 15154                              <1> 	;jmp	short sysfnf_11 (*)
 15155                              <1> 	;; 08/08/2022
 15156                              <1> 	;;je	short sysfnf_6 ; esi = FindFile_Drv
 15157                              <1> 	; 29/08/2023 (BugFix)
 15158                              <1> 	;je	short sysfff_6 ; esi = FindFile_Drv
 15159                              <1> 	; 25/08/2024 (BugFix of BugFix) (*)
 15160 0001114F 7496                <1> 	je	short sysfnf_11 ; esi <> FindFile_Drv
 15161                              <1> 	
 15162 00011151 E937FFFFFF          <1> 	jmp	sysfnf_12
 15163                              <1> 
 15164                              <1> stsfnf_2:
 15165 00011156 FE05[7B890100]      <1> 	inc	byte [SWP_DRV_chg]
 15166                              <1> 
 15167 0001115C E81C67FFFF          <1> 	call	change_current_drive
 15168 00011161 7245                <1> 	jc	short sysfnf_err_1 ; read error ! 
 15169                              <1> 				   ; (do not stop, because
 15170                              <1> 				   ; we don't have a
 15171                              <1> 				   ; 'no more files'
 15172                              <1> 				   ; -file not found- error,
 15173                              <1> 				   ; next sysfnf system call
 15174                              <1> 				   ; may solve the problem,
 15175                              <1> 				   ; after re-placing the disk)
 15176                              <1> sysfnf_3:
 15177 00011163 A1[98860100]        <1> 	mov	eax, [FindFile_DirCluster]
 15178 00011168 21C0                <1> 	and	eax, eax
 15179 0001116A 7550                <1> 	jnz	short sysfnf_6
 15180                              <1>         
 15181 0001116C 803D[817D0100]02    <1> 	cmp	byte [Current_FATType], 2
 15182 00011173 772C                <1> 	ja	short sysfnf_err_0 ; invalid, we neeed to stop !?
 15183 00011175 803D[817D0100]01    <1> 	cmp	byte [Current_FATType], 1
 15184 0001117C 7223                <1> 	jb	short sysfnf_err_0 ; invalid, we neeed to stop !?
 15185                              <1> 
 15186 0001117E 3805[A9840100]      <1> 	cmp	byte [DirBuff_ValidData], al ; 0
 15187 00011184 7608                <1> 	jna	short sysfnf_4 
 15188                              <1> 
 15189 00011186 3B05[AE840100]      <1> 	cmp	eax, [DirBuff_Cluster] ; 0 ?
 15190 0001118C 74A8                <1> 	je	short sysfnf_9
 15191                              <1> 
 15192                              <1> 	;cmp	byte [Current_Dir_Level], 0
 15193                              <1>         ;ja	short sysfnf_4  
 15194                              <1>         ;jna	short sysfnf_9 
 15195                              <1> 
 15196                              <1> sysfnf_4:
 15197 0001118E FE05[7B890100]      <1> 	inc	byte [SWP_DRV_chg]
 15198 00011194 E8C5B2FFFF          <1> 	call 	load_FAT_root_directory
 15199 00011199 739B                <1> 	jnc	short sysfnf_9
 15200                              <1> 	; eax = error code (17, 'drv not ready or read error')
 15201 0001119B EB0B                <1> 	jmp	short sysfnf_err_1 ; read error ! (no FNF stop)
 15202                              <1> 				   ; (if you want, try again,
 15203                              <1> 				   ;  after re-placing the disk)
 15204                              <1> sysfnf_5:
 15205 0001119D 3C0C                <1> 	cmp	al, 12 ; 'no more files' error
 15206 0001119F 7507                <1> 	jne	short sysfnf_err_1 ; (no FNF stop -sysfnf will try
 15207                              <1> 				   ;  to read the directory again,
 15208                              <1> 				   ;  if the user calls sysfnf
 15209                              <1> 				   ;  just after this error return-)
 15210                              <1> 	; (FNF stop -sysfnf will not try
 15211                              <1> 	;  to read the directory again-)
 15212                              <1> 
 15213                              <1> sysfnf_err_0:
 15214 000111A1 C605[74890100]00    <1> 	mov	byte [FFF_Valid], 0 ; FNF stop sign
 15215                              <1> sysfnf_err_1:
 15216 000111A8 A3[74940100]        <1> 	mov	[u.r0], eax
 15217 000111AD A3[E0940100]        <1> 	mov	[u.error], eax
 15218 000111B2 E800120000          <1> 	call	reset_working_path
 15219 000111B7 E978BCFFFF          <1> 	jmp	error
 15220                              <1> 
 15221                              <1> sysfnf_6:
 15222 000111BC 803D[A9840100]00    <1> 	cmp	byte [DirBuff_ValidData], 0
 15223 000111C3 760D                <1> 	jna	short sysfnf_7
 15224                              <1> 
 15225 000111C5 3B05[AE840100]      <1> 	cmp	eax, [DirBuff_Cluster]
 15226                              <1> 	;je	short sysfnf_9
 15227                              <1> 	; 08/08/2022
 15228 000111CB 7505                <1> 	jne	short sysfnf_7
 15229 000111CD E964FFFFFF          <1> 	jmp	sysfnf_9
 15230                              <1> sysfnf_7:
 15231 000111D2 FE05[7B890100]      <1> 	inc	byte [SWP_DRV_chg]
 15232 000111D8 803D[817D0100]01    <1> 	cmp	byte [Current_FATType], 1
 15233                              <1> 	;jnb	short sysfnf_8
 15234                              <1> 	; 08/08/2022
 15235 000111DF 7205                <1> 	jb	short sysfnf_13
 15236 000111E1 E949FFFFFF          <1> 	jmp	sysfnf_8
 15237                              <1> sysfnf_13:
 15238                              <1> 	; Singlix (TRFS) File System 
 15239                              <1> 	; (access via compatibility buffer)
 15240 000111E6 E82BB3FFFF          <1> 	call	load_FS_sub_directory
 15241                              <1> 	;jnc	short sysfnf_9
 15242                              <1> 	;jmp	short sysfnf_err_1 ; read error (no FNF stop)
 15243                              <1> 	; 08/08/2022
 15244 000111EB 72BB                <1> 	jc	short sysfnf_err_1
 15245 000111ED E944FFFFFF          <1> 	jmp	sysfnf_9
 15246                              <1> 
 15247                              <1> writei:
 15248                              <1> 	; 02/09/2024
 15249                              <1> 	; 27/08/2024 - TRDOS 386 v2.0.9 
 15250                              <1> 	; 08/08/2022
 15251                              <1> 	; 30/07/2022
 15252                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
 15253                              <1> 	; 26/10/2016
 15254                              <1> 	; 25/10/2016
 15255                              <1> 	; 23/10/2016
 15256                              <1> 	; 22/10/2016
 15257                              <1> 	; 19/10/2016 - TRDOS 386 (TRDOS v2.0)
 15258                              <1> 	; 19/05/2015 - 20/05/2015 (Retro UNIX 386 v1)
 15259                              <1> 	; 12/03/2013 - 31/07/2013 (Retro UNIX 8086 v1)
 15260                              <1> 	;
 15261                              <1> 	; Write data to file with first cluster number in EAX
 15262                              <1> 	; 
 15263                              <1> 	; INPUTS ->
 15264                              <1> 	;    EAX - First cluster number of the file
 15265                              <1> 	;    EBX - File number (Open file index number)
 15266                              <1> 	;    u.count - byte count to be written
 15267                              <1> 	;    u.base - points to user buffer
 15268                              <1> 	;    u.fofp - points to dword with current file offset
 15269                              <1> 	;    i.size - file size
 15270                              <1> 	;    cdev - logical dos drive number of the file
 15271                              <1> 	; OUTPUTS ->
 15272                              <1> 	;    u.count - cleared
 15273                              <1> 	;    u.nread - accumulates total bytes passed back
 15274                              <1> 	;    i.size - new file size (if file byte offset overs file size)
 15275                              <1> 	;    u.fofp - points to u.off (with new offset value)
 15276                              <1> 	;
 15277                              <1> 	; (Retro UNIX Prototype : 11/11/2012 - 18/11/2012, UNIXCOPY.ASM)
 15278                              <1> 	; ((Modified registers: eax, edx, ebx, ecx, esi, edi, ebp))
 15279                              <1> 
 15280 000111F2 31C9                <1> 	xor	ecx, ecx
 15281 000111F4 890D[A0940100]      <1> 	mov 	[u.nread], ecx  ; 0
 15282 000111FA 66890D[D8940100]    <1> 	mov	[u.pcount], cx ; 19/05/2015
 15283 00011201 390D[9C940100]      <1> 	cmp 	[u.count], ecx
 15284 00011207 7701                <1> 	ja 	short writei_1 ; 08/08/2022
 15285 00011209 C3                  <1> 	retn
 15286                              <1> 	; 23/07/2022
 15287                              <1> 	;jna	short dskw_8 ; retn
 15288                              <1> writei_1:
 15289                              <1> 	; 02/09/2024
 15290 0001120A C705[20890100]FFFF- <1> 	mov	dword [writei.fclust], 0FFFFFFFFh ; -1 ; reset
 15290 00011212 FFFF                <1>
 15291                              <1> dskw:
 15292 00011214 881D[30890100]      <1> 	mov	[writei.ofn], bl ; Open file number
 15293 0001121A 880D[6B890100]      <1> 	mov	[setfmod], cl ; 0 ; reset 'update lm date&time' sign
 15294                              <1> dskw_0: 
 15295                              <1> 	; 26/10/2016
 15296                              <1> 	; 22/10/2016, 23/10/2016, 25/10/2016
 15297                              <1> 	; 19/10/2016 - TRDOS 386 (TRDOS v2.0)
 15298                              <1> 	; 31/05/2015 - 25/07/2015 (Retro UNIX 386 v1)
 15299                              <1> 	; 26/04/2013 - 20/09/2013 (Retro UNIX 8086 v1)
 15300                              <1> 	;
 15301                              <1> 	; 01/08/2013 (mkdir_w check)
 15302 00011220 E8D0000000          <1>  	call	mget_w
 15303                              <1> 	; eax = sector/block number
 15304                              <1> 
 15305 00011225 8B1D[88940100]      <1> 	mov     ebx, [u.fofp]
 15306 0001122B 8B13                <1> 	mov	edx, [ebx]
 15307 0001122D 81E2FF010000        <1> 	and	edx, 1FFh  ; / test the lower 9 bits of the file offset
 15308 00011233 750C                <1> 	jnz	short dskw_1 ; / if its non-zero, branch
 15309                              <1> 			     ; if zero, file offset = 0,
 15310                              <1> 		       	     ; / 512, 1024,...(i.e., start of new block)
 15311 00011235 813D[9C940100]0002- <1> 	cmp	dword [u.count], 512
 15311 0001123D 0000                <1>
 15312                              <1> 				; / if zero, is there enough data to fill
 15313                              <1> 				; / an entire block? (i.e., no. of
 15314 0001123F 7331                <1> 	jnb	short dskw_2 ; / bytes to be written greater than 512.?
 15315                              <1> 			     ; / Yes, branch. Don't have to read block
 15316                              <1> dskw_1: ; in as no past info. is to be saved 
 15317                              <1> 	; (the entire block will be overwritten).
 15318                              <1> 	; 23/10/2016
 15319                              <1> 
 15320 00011241 BB[A4980100]        <1> 	mov	ebx, writei_buffer
 15321                              <1> 	; esi = logical dos drive description table address
 15322                              <1> 	; eax = sector number
 15323                              <1> 	; ebx = buffer address (in kernel's memory space)
 15324                              <1> 	; ecx = sector count
 15325                              <1> 	; 30/07/2022
 15326                              <1> 	;mov	ecx, 1
 15327 00011246 31C9                <1> 	xor	ecx, ecx
 15328 00011248 FEC1                <1> 	inc	cl
 15329                              <1> 	; ecx = 1
 15330 0001124A E8B10D0000          <1> 	call	disk_read
 15331                              <1> 	;call	dskrd 	; / no, must retain old info.. 
 15332                              <1> 		       	; / Hence, read block 'r1' into an I/O buffer
 15333 0001124F 7321                <1> 	jnc	short dskw_2
 15334                              <1> 
 15335                              <1> 	; disk read error
 15336                              <1> 	; 30/07/2022
 15337                              <1> 	;mov	eax, 17 ; drive not ready or READ ERROR !
 15338 00011251 29C0                <1> 	sub	eax, eax
 15339 00011253 B011                <1> 	mov	al, 17
 15340                              <1> dskw_err: ; jump from disk write error
 15341 00011255 A3[74940100]        <1> 	mov	[u.r0], eax
 15342 0001125A A3[E0940100]        <1> 	mov	[u.error], eax
 15343                              <1> 
 15344 0001125F 803D[6B890100]00    <1> 	cmp	byte [setfmod], 0
 15345                              <1> 	;jna	error
 15346                              <1> 	; 23/07/2022
 15347 00011266 7605                <1> 	jna	short writei_err
 15348                              <1> 
 15349 00011268 E8CD030000          <1> 	call	update_file_lmdt ; update last modif. date&time of the file
 15350                              <1> 	;mov	byte [setfmod], 0
 15351                              <1> writei_err:
 15352 0001126D E9C2BBFFFF          <1> 	jmp	error
 15353                              <1> 
 15354                              <1> dskw_2: ; 3:
 15355                              <1> 	; 23/10/2016
 15356 00011272 C605[0C890100]01    <1> 	mov	byte [writei.valid], 1 ; writei buffer contains valid data
 15357 00011279 56                  <1> 	push	esi ; logical dos drive description table address
 15358                              <1> 	; EAX (r1) = block/sector number
 15359                              <1> 	;call	wslot
 15360                              <1> 		; jsr r0,wslot / set write and inhibit bits in I/O queue,
 15361                              <1> 			   ; / proc. status=0, r5 points to 1st word of data
 15362 0001127A 803D[DA940100]00    <1> 	cmp	byte [u.kcall], 0
 15363 00011281 770F                <1> 	ja	short dskw_4 ; zf=0 -> the caller is 'mkdir'
 15364                              <1> 	;
 15365 00011283 66833D[D8940100]00  <1> 	cmp	word [u.pcount], 0
 15366 0001128B 7705                <1> 	ja	short dskw_4
 15367                              <1> dskw_3:
 15368                              <1> 	; [u.base] = virtual address to transfer (as source address)
 15369 0001128D E826FAFFFF          <1> 	call	trans_addr_r ; translate virtual address to physical (r)
 15370                              <1> dskw_4:
 15371 00011292 BB[A4980100]        <1> 	mov	ebx, writei_buffer
 15372                              <1> 	; EBX (r5) = system (I/O) buffer address
 15373 00011297 E888FAFFFF          <1> 	call	sioreg
 15374                              <1> 	; ESI = file (user data) offset
 15375                              <1> 	; EDI = sector (I/O) buffer offset
 15376                              <1> 	; ECX = byte count
 15377                              <1> 	;
 15378 0001129C F3A4                <1>   	rep	movsb
 15379                              <1> 	; 25/07/2015
 15380                              <1> 	; eax = remain bytes in buffer
 15381                              <1>         ;       (check if remain bytes in the buffer > [u.pcount])
 15382 0001129E 09C0                <1> 	or	eax, eax
 15383 000112A0 75EB                <1> 	jnz	short dskw_3 ; (page end before system buffer end!)
 15384                              <1> 
 15385                              <1> 	; 23/10/2016
 15386 000112A2 B101                <1> 	mov	cl, 1
 15387 000112A4 5E                  <1> 	pop	esi
 15388 000112A5 A1[10890100]        <1> 	mov	eax, [writei.sector]
 15389                              <1> 	; esi = logical dos drive description table address
 15390                              <1> 	; eax = sector number
 15391                              <1> 	; ebx = writei buffer address
 15392                              <1> 	; ecx = sector count
 15393 000112AA E8420D0000          <1> 	call	disk_write ; / yes, write the block
 15394 000112AF 7313                <1> 	jnc	short dskw_5
 15395                              <1> 
 15396                              <1> 	;mov	eax, 18 ; drive not ready or WRITE ERROR !
 15397                              <1> 	; 30/08/2022
 15398 000112B1 29C0                <1> 	sub	eax, eax
 15399 000112B3 B012                <1> 	mov	al, 18
 15400 000112B5 EB9E                <1> 	jmp	short dskw_err
 15401                              <1> 
 15402                              <1> dskw_7:
 15403                              <1>  	; update last modif. date&time of the file
 15404                              <1> 	; (also updates file size as OF_SIZE)
 15405 000112B7 E87E030000          <1> 	call	update_file_lmdt
 15406                              <1> 	;mov	byte [setfmod], 0
 15407                              <1> 
 15408                              <1> 	; 03/08/2013
 15409 000112BC C605[DA940100]00    <1> 	mov	byte [u.kcall], 0
 15410                              <1> 	; 23/10/2016
 15411                              <1> 	;mov	eax, [writei.fclust]
 15412                              <1> dskw_8:		; 23/07/2022
 15413 000112C3 C3                  <1> 	retn
 15414                              <1> 
 15415                              <1> dskw_5:
 15416                              <1> 	; 26/10/2016
 15417 000112C4 0FB61D[30890100]    <1> 	movzx	ebx, byte [writei.ofn] ; open file number
 15418 000112CB C0E302              <1> 	shl	bl, 2 ; *4
 15419 000112CE 8B83[808A0100]      <1> 	mov	eax, [ebx+OF_POINTER]
 15420 000112D4 3B83[008B0100]      <1> 	cmp	eax, [ebx+OF_SIZE]
 15421 000112DA 7606                <1> 	jna	short dskw_6
 15422 000112DC 8983[008B0100]      <1> 	mov	[ebx+OF_SIZE], eax
 15423                              <1> dskw_6:
 15424                              <1> 	;shr	bl, 2
 15425 000112E2 833D[9C940100]00    <1>         cmp     dword [u.count], 0 ; / any more data to write?
 15426 000112E9 76CC                <1> 	jna	short dskw_7
 15427 000112EB A1[20890100]        <1> 	mov	eax, [writei.fclust]
 15428 000112F0 E92BFFFFFF          <1> 	jmp	dskw_0 ; / yes, branch
 15429                              <1> 
 15430                              <1> mget_w:
 15431                              <1> 	; 03/09/2024
 15432                              <1> 	; 02/09/2024
 15433                              <1> 	; 25/08/2024 - TRDOS 386 v2.0.9
 15434                              <1> 	; 08/08/2022
 15435                              <1> 	; 25/07/2022
 15436                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
 15437                              <1> 	; 02/11/2016
 15438                              <1> 	; 01/11/2016
 15439                              <1> 	; 23/10/2016, 31/10/2016
 15440                              <1> 	; 22/10/2016 - TRDOS 386 (TRDOS v2.0)
 15441                              <1> 	; 03/06/2015 (Retro UNIX 386 v1, 'mget', u.5s)
 15442                              <1> 	; 22/03/2013 - 31/07/2013 (Retro UNIX 8086 v1)
 15443                              <1> 	;
 15444                              <1> 	; Get existing or (allocate) a new disk block for file
 15445                              <1> 	;
 15446                              <1> 	; INPUTS ->
 15447                              <1> 	;    [u.fofp] = file offset pointer
 15448                              <1> 	;    [i.size] = file size
 15449                              <1> 	;    [u.count] = byte count
 15450                              <1> 	;    EAX = First cluster
 15451                              <1> 	;    [cdev] = Logical dos drive number
 15452                              <1> 	;    [writei.ofn] = File Number
 15453                              <1> 	;		   (Open file index, 0 based)
 15454                              <1> 	;    ([u.off] = file offset)
 15455                              <1> 	; OUTPUTS ->
 15456                              <1> 	;    EAX = logical sector number
 15457                              <1> 	;    ESI = Logical Dos Drive Description Table address
 15458                              <1> 	;
 15459                              <1> 	; Modified registers: EDX, EBX, ECX, ESI, EDI, EBP
 15460                              <1> 
 15461 000112F5 8B35[88940100]      <1>         mov     esi, [u.fofp]
 15462 000112FB 8B2E                <1> 	mov	ebp, [esi] ; u.off (or EBX*4+OF_POINTER)
 15463                              <1> 
 15464 000112FD 29C9                <1> 	sub	ecx, ecx
 15465 000112FF 8A2D[59940100]      <1> 	mov	ch, [cdev]
 15466                              <1> 
 15467 00011305 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 15468 0001130A 01CE                <1> 	add	esi, ecx
 15469                              <1> 
 15470                              <1> 	; 31/10/2016
 15471 0001130C 89C3                <1> 	mov	ebx, eax ; First Cluster or FDT address
 15472                              <1> 
 15473 0001130E 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 15474                              <1> 	;jna	mget_w_14 ; Singlix FS
 15475                              <1> 	; 23/07/2022
 15476 00011312 7705                <1> 	ja	short mget_w_20
 15477 00011314 E9FC010000          <1> 	jmp	mget_w_14  ; Singlix FS
 15478                              <1> 
 15479                              <1> mget_w_20:
 15480 00011319 0FB74611            <1> 	movzx	eax, word [esi+LD_BPB+BytesPerSec]
 15481 0001131D 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+SecPerClust]
 15482 00011321 8815[0E890100]      <1> 	mov	[writei.spc], dl  ; sectors per cluster
 15483 00011327 F7E2                <1> 	mul	edx
 15484                              <1> 	; edx = 0
 15485                              <1> 	; eax = bytes per cluster (<= 65536)
 15486                              <1> 
 15487                              <1> 	; 02/11/2016
 15488 00011329 89C1                <1> 	mov	ecx, eax
 15489 0001132B 48                  <1> 	dec	eax
 15490 0001132C 66A3[14890100]      <1> 	mov	[writei.bpc], ax
 15491                              <1> 
 15492 00011332 89E8                <1> 	mov	eax, ebp
 15493 00011334 0305[9C940100]      <1> 	add	eax, [u.count] ; next file position
 15494 0001133A 3B05[80950100]      <1> 	cmp	eax, [i.size] ; <= file size ?
 15495                              <1> 	;jna	mget_w_4 ; no
 15496                              <1> 	; 23/07/2022
 15497 00011340 7705                <1> 	ja	short mget_w_21
 15498                              <1> 	; 02/09/2024
 15499                              <1> 	; ebx  = first cluster (input)
 15500 00011342 E925010000          <1> 	jmp	mget_w_4
 15501                              <1> mget_w_21:
 15502 00011347 F7F1                <1> 	div	ecx
 15503 00011349 A3[1C890100]        <1> 	mov	[writei.c_index], eax ; cluster index
 15504                              <1> 	; edx = byte offset in cluster (<= 65535)
 15505                              <1> 	;mov	[writei.offset], dx
 15506                              <1> 	;shr	dx, 9 ; / 512
 15507                              <1> 	;mov	[writei.s_index], dl ; sector index in cluster (0 to spc -1)
 15508                              <1> 
 15509 0001134E 29D2                <1> 	sub	edx, edx ; 01/11/2016
 15510 00011350 8915[10890100]      <1> 	mov 	[writei.sector], edx ; 0
 15511 00011356 668915[16890100]    <1> 	mov	[writei.offset], dx  ; byte offset in cluster
 15512 0001135D 8815[0F890100]      <1> 	mov	[writei.s_index], dl ; sector index in cluster (0 to spc -1)
 15513                              <1> 
 15514 00011363 89D8                <1> 	mov	eax, ebx ; First Cluster
 15515                              <1> 
 15516                              <1> 	; is this the 1st mget_w or a next mget_w call ? (by 'writei')
 15517 00011365 3815[0C890100]      <1> 	cmp	byte [writei.valid], dl ; 0
 15518 0001136B 7624                <1> 	jna	short mget_w_0
 15519                              <1> 
 15520 0001136D 8815[0C890100]      <1> 	mov 	byte [writei.valid], dl ; 0 ; reset ('writei' will set it) 
 15521                              <1> 
 15522 00011373 3B05[20890100]      <1> 	cmp	eax, [writei.fclust]
 15523 00011379 7516                <1> 	jne	short mget_w_0
 15524                              <1> 
 15525 0001137B 8A0D[59940100]      <1> 	mov	cl, [cdev]
 15526 00011381 3A0D[0D890100]      <1> 	cmp	cl, [writei.drv]
 15527 00011387 7508                <1> 	jne	short mget_w_0
 15528                              <1>  	; [writei.l_clust] & [writei.l_index] are valid,
 15529                              <1> 	;  we don't need to get last cluster & last cluster index
 15530 00011389 8B0D[2C890100]      <1> 	mov	ecx, [writei.l_index]
 15531 0001138F EB7F                <1> 	jmp	short mget_w_2
 15532                              <1> mget_w_0:
 15533 00011391 A3[20890100]        <1> 	mov	[writei.fclust], eax ; first cluster
 15534                              <1> 	; edx = 0
 15535 00011396 A3[18890100]        <1> 	mov	[writei.cluster], eax ; first cluster ; 01/11/2016
 15536 0001139B 8915[24890100]      <1> 	mov 	[writei.fs_index], edx ; 0 ; current cluster index
 15537                              <1> 
 15538                              <1> 	;;;
 15539                              <1> 	; 25/08/2024 - TRDOS 386 v2.0.9
 15540 000113A1 09C0                <1> 	or	eax, eax ; is first cluster number = 0 ?
 15541 000113A3 751A                <1> 	jnz	short mget_w_27 ; no
 15542                              <1> 
 15543                              <1> 	; eax = 0 (*)
 15544                              <1> 	; ((a directory entry with zero file size)) (*)
 15545                              <1> 	; (*) ((('syswrite' may be used for writing to an empty file.
 15546                              <1> 	; Before this modification, 'syscreat' and 'syswrite' system calls
 15547                              <1> 	; did wrong things together... 'writetest.s' file, 24/08/2024.)))
 15548                              <1> 
 15549 000113A5 E805B8FFFF          <1> 	call	add_new_cluster ; (*) 2024 (v2.0.9) modification
 15550 000113AA 721A                <1> 	jc	short mget_w_errj ; eax = error code
 15551                              <1> 	; eax = (new) first cluster
 15552                              <1> 	; skip 'get_last_cluster' and set ecx to -1
 15553                              <1> 	;
 15554                              <1> 	; 02/09/2024
 15555 000113AC A3[20890100]        <1> 	mov	[writei.fclust], eax ; first cluster
 15556 000113B1 A3[18890100]        <1> 	mov	[writei.cluster], eax
 15557                              <1> 	; 03/09/2024
 15558 000113B6 A3[6C890100]        <1> 	mov	[setfclust], eax
 15559                              <1> 	;
 15560 000113BB 31C9                <1> 	xor	ecx, ecx
 15561 000113BD EB12                <1> 	jmp	short mget_w_28
 15562                              <1> 	;;;
 15563                              <1> 
 15564                              <1> mget_w_27:
 15565                              <1> 	; FAT file system (FAT12, FAT16, FAT32)
 15566 000113BF E8CEB6FFFF          <1> 	call	get_last_cluster
 15567                              <1> 	;jc	short mget_w_err ; eax = error code
 15568                              <1> 	; 08/08/2022
 15569 000113C4 7305                <1> 	jnc	short mget_w_25
 15570                              <1> mget_w_errj:	; 25/08/2024
 15571 000113C6 E992000000          <1> 	jmp	mget_w_err
 15572                              <1> 
 15573                              <1> mget_w_25:
 15574                              <1> 	; 25/08/2024
 15575 000113CB 8B0D[4C870100]      <1> 	mov	ecx, [glc_index] ; last cluster index
 15576                              <1> mget_w_28:	; 02/09/2024
 15577 000113D1 890D[2C890100]      <1> 	mov	[writei.l_index], ecx
 15578 000113D7 A3[28890100]        <1> 	mov	[writei.lclust], eax ; last cluster
 15579                              <1> 
 15580 000113DC A0[30890100]        <1> 	mov	al, [writei.ofn]
 15581 000113E1 FEC0                <1> 	inc	al
 15582 000113E3 A2[6B890100]        <1> 	mov	[setfmod], al ; update lm date&time sign
 15583                              <1> 
 15584                              <1> mget_w_1:
 15585 000113E8 3B0D[1C890100]      <1> 	cmp	ecx, [writei.c_index] ; last cluster index
 15586 000113EE 7320                <1> 	jnb	short mget_w_2 ; 01/11/2016
 15587                              <1> 
 15588 000113F0 A1[28890100]        <1> 	mov	eax, [writei.lclust]
 15589                              <1> 	; EAX = Last cluster
 15590 000113F5 E8B5B7FFFF          <1> 	call	add_new_cluster
 15591 000113FA 7261                <1> 	jc	short mget_w_err ; eax = error code
 15592                              <1> 	; edx = 0
 15593 000113FC A3[28890100]        <1> 	mov	[writei.lclust], eax ; (new) last cluster
 15594 00011401 8B0D[2C890100]      <1> 	mov	ecx, [writei.l_index]
 15595 00011407 41                  <1> 	inc	ecx ; add 1 to last cluster index
 15596 00011408 890D[2C890100]      <1> 	mov	[writei.l_index], ecx ; current last cluster index
 15597                              <1> 
 15598 0001140E EBD8                <1> 	jmp	short mget_w_1
 15599                              <1> 
 15600                              <1> mget_w_2:
 15601 00011410 89E9                <1> 	mov	ecx, ebp
 15602 00011412 030D[9C940100]      <1> 	add	ecx, [u.count]
 15603 00011418 890D[80950100]      <1> 	mov	[i.size], ecx ; save new file size
 15604                              <1> 	;sub	edx, edx ; 0
 15605                              <1> 
 15606 0001141E A0[59940100]        <1> 	mov	al, [cdev]
 15607 00011423 A2[0D890100]        <1> 	mov	[writei.drv], al ; physical drive number
 15608                              <1> 	; edx = 0
 15609 00011428 89E8                <1> 	mov	eax, ebp ; file offset
 15610 0001142A 0FB70D[14890100]    <1> 	movzx	ecx, word [writei.bpc] ; bytes per cluster - 1
 15611 00011431 41                  <1> 	inc	ecx ; bytes per cluster
 15612 00011432 F7F1                <1> 	div	ecx
 15613                              <1> 	; edx = byte offset in cluster (<= 65535)
 15614                              <1> 	; eax = cluster index
 15615 00011434 A3[1C890100]        <1> 	mov	[writei.c_index], eax
 15616 00011439 668915[16890100]    <1> 	mov	[writei.offset], dx
 15617                              <1> 	;shr	dx, 9 ; / 512
 15618                              <1> 	; 23/07/2022
 15619 00011440 C1EA09              <1> 	shr	edx, 9
 15620 00011443 8815[0F890100]      <1> 	mov	[writei.s_index], dl ; sector index in cluster (0 to spc -1)
 15621                              <1> 
 15622                              <1> mget_w_3:
 15623 00011449 3B05[2C890100]      <1> 	cmp	eax, [writei.l_index] ; last cluster index
 15624 0001144F 753E                <1> 	jne	short mget_w_5
 15625                              <1> 
 15626 00011451 A3[24890100]        <1> 	mov	[writei.fs_index], eax ; cluster index (for next check)
 15627 00011456 A1[28890100]        <1> 	mov	eax, [writei.lclust] ; last cluster
 15628 0001145B EB74                <1> 	jmp	short mget_w_10
 15629                              <1> 
 15630                              <1> mget_w_err:
 15631 0001145D A3[E0940100]        <1> 	mov	[u.error], eax
 15632 00011462 A3[74940100]        <1> 	mov	[u.r0], eax
 15633 00011467 E9C8B9FFFF          <1> 	jmp	error
 15634                              <1> 
 15635                              <1> mget_w_4: ; 02/11/2016
 15636                              <1> 	; eax = next file position
 15637 0001146C 2B05[9C940100]      <1> 	sub	eax, [u.count] ; current file position
 15638                              <1> 	; edx = 0
 15639                              <1> 	; ecx = bytes per cluster
 15640 00011472 F7F1                <1> 	div	ecx
 15641 00011474 A3[1C890100]        <1> 	mov	[writei.c_index], eax ; cluster index
 15642 00011479 668915[16890100]    <1> 	mov	[writei.offset], dx
 15643                              <1> 	;shr	dx, 9 ; / 512
 15644                              <1> 	; 23/07/2022
 15645 00011480 C1EA09              <1> 	shr	edx, 9
 15646 00011483 8815[0F890100]      <1> 	mov	[writei.s_index], dl ; sector index in cluster (0 to spc -1)
 15647                              <1> 
 15648                              <1> 	; 02/09/2024
 15649 00011489 891D[20890100]      <1> 	mov	 [writei.fclust], ebx
 15650                              <1> 
 15651                              <1> mget_w_5:
 15652 0001148F 21C0                <1> 	and	eax, eax ; 0 = First Cluster's index number
 15653 00011491 750C                <1> 	jnz	short mget_w_6
 15654                              <1> 
 15655 00011493 A3[24890100]        <1> 	mov	[writei.fs_index], eax ; cluster index (for next check)
 15656 00011498 A1[20890100]        <1> 	mov	eax, [writei.fclust] ; first cluster
 15657 0001149D EB32                <1> 	jmp	short mget_w_10
 15658                              <1> 
 15659                              <1> mget_w_6:
 15660 0001149F 3B05[24890100]      <1> 	cmp	eax, [writei.fs_index] ; current cluster index (>0)
 15661 000114A5 7507                <1> 	jne	short mget_w_7
 15662 000114A7 A1[18890100]        <1> 	mov	eax, [writei.cluster] ; current cluster
 15663 000114AC EB3A                <1> 	jmp	short mget_w_11
 15664                              <1> 
 15665                              <1> mget_w_7:
 15666 000114AE 89C1                <1> 	mov	ecx, eax
 15667 000114B0 2B0D[24890100]      <1> 	sub	ecx, [writei.fs_index]
 15668 000114B6 730D                <1> 	jnc	short mget_w_8
 15669                              <1> 	; get cluster by index from the first cluster
 15670 000114B8 A1[20890100]        <1> 	mov	eax, [writei.fclust]
 15671 000114BD 8B0D[1C890100]      <1> 	mov	ecx, [writei.c_index]
 15672 000114C3 EB05                <1> 	jmp	short mget_w_9
 15673                              <1> 
 15674                              <1> mget_w_8:
 15675 000114C5 A1[18890100]        <1> 	mov	eax, [writei.cluster] ; beginning cluster
 15676                              <1> 	; ecx = cluster sequence number after the beginning cluster
 15677                              <1> 	; sub	edx, edx ; 0
 15678                              <1> 
 15679                              <1> mget_w_9:
 15680                              <1> 	; EAX = Beginning cluster
 15681                              <1> 	; EDX = Sector index in disk/file section
 15682                              <1> 	;	(Only for SINGLIX file system!)
 15683                              <1> 	; ECX = Cluster sequence number after the beginning cluster
 15684                              <1> 	; ESI = Logical DOS Drive Description Table address
 15685 000114CA E899B7FFFF          <1> 	call	get_cluster_by_index
 15686 000114CF 728C                <1> 	jc	short mget_w_err ; error code in EAX
 15687                              <1> 
 15688                              <1> 	; EAX = Cluster number
 15689                              <1> mget_w_10:
 15690 000114D1 A3[18890100]        <1> 	mov	[writei.cluster], eax ; FDT number for Singlix File System
 15691                              <1> 
 15692 000114D6 807E0300            <1> 	cmp	byte [esi+LD_FATType], 0
 15693 000114DA 7628                <1> 	jna	short mget_w_13
 15694                              <1> 	; 01/11/2016
 15695 000114DC 8B15[1C890100]      <1> 	mov	edx, [writei.c_index]
 15696 000114E2 8915[24890100]      <1> 	mov	[writei.fs_index], edx
 15697                              <1> mget_w_11:
 15698                              <1> 	;sub	eax, 2
 15699                              <1> 	; 23/07/2022
 15700 000114E8 48                  <1> 	dec	eax
 15701 000114E9 48                  <1> 	dec	eax
 15702 000114EA 0FB615[0E890100]    <1> 	movzx	edx, byte [writei.spc]
 15703 000114F1 F7E2                <1> 	mul	edx
 15704                              <1> 
 15705 000114F3 034668              <1> 	add	eax, [esi+LD_DATABegin]
 15706 000114F6 8A15[0F890100]      <1> 	mov	dl, [writei.s_index]
 15707 000114FC 01D0                <1> 	add	eax, edx
 15708                              <1> mget_w_12:
 15709 000114FE A3[10890100]        <1> 	mov	[writei.sector], eax
 15710                              <1> 	;; buffer validation must be done in writei
 15711                              <1> 	;;mov	byte [writei.valid], 1
 15712 00011503 C3                  <1> 	retn
 15713                              <1> 
 15714                              <1> mget_w_13:
 15715                              <1> 	; EAX = FDT number (Current Section)
 15716                              <1> 	; EDX = Sector index from the first section (0,1,2,3,4...)
 15717 00011504 2B15[24890100]      <1> 	sub	edx, [writei.fs_index]
 15718                              <1> 	; EDX = Sector index from current section
 15719 0001150A 8915[24890100]      <1> 	mov	[writei.fs_index], edx
 15720 00011510 40                  <1> 	inc	eax ; the first data sector in FS disk section
 15721 00011511 01D0                <1> 	add	eax, edx
 15722 00011513 EBE9                <1> 	jmp	short mget_w_12
 15723                              <1> 
 15724                              <1> mget_w_14:
 15725 00011515 8A4E12              <1> 	mov	cl, [esi+LD_FS_BytesPerSec+1]
 15726 00011518 D0E9                <1> 	shr	cl, 1 ;  ; 1 for 512 bytes, 4 for 2048 bytes
 15727 0001151A 880D[0E890100]      <1> 	mov	[writei.spc], cl  ; sectors per cluster
 15728                              <1> 	; NOTE: writei bytes per sector value is always 512 !
 15729 00011520 66C705[14890100]00- <1> 	mov	word [writei.bpc], 512
 15729 00011528 02                  <1>
 15730                              <1> 
 15731 00011529 89E9                <1> 	mov	ecx, ebp
 15732 0001152B 030D[9C940100]      <1> 	add	ecx, [u.count] ; next file position
 15733 00011531 3B0D[80950100]      <1> 	cmp	ecx, [i.size] ; <= file size ?
 15734                              <1> 	;jna	mget_w_19 ; no
 15735 00011537 7705                <1> 	ja	short mget_w_22
 15736                              <1> 	; 23/07/2022
 15737 00011539 E9C6000000          <1> 	jmp	mget_w_19
 15738                              <1> 
 15739                              <1> mget_w_22:
 15740 0001153E 29D2                <1> 	sub	edx, edx ; 0
 15741 00011540 8915[10890100]      <1> 	mov 	[writei.sector], edx ; 0
 15742 00011546 668915[16890100]    <1> 	mov	[writei.offset], dx  ; byte offset in cluster 
 15743 0001154D 8815[0F890100]      <1> 	mov	[writei.s_index], dl ; sector index in cluster (0 to spc -1)
 15744                              <1> 
 15745 00011553 C1E909              <1> 	shr	ecx, 9 ; 1 cluster = 512 bytes
 15746 00011556 890D[1C890100]      <1> 	mov	[writei.c_index], ecx ; section/cluster index
 15747                              <1> 	
 15748 0001155C 89D8                <1> 	mov	eax, ebx ; FDT number (First FDT address)
 15749                              <1> 
 15750                              <1> 	; is this the 1st mget_w or a next mget_w call ? (by 'writei')
 15751 0001155E 3815[0C890100]      <1> 	cmp	byte [writei.valid], dl ; 0
 15752 00011564 7624                <1> 	jna	short mget_w_15
 15753                              <1> 
 15754 00011566 8815[0C890100]      <1> 	mov 	byte [writei.valid], dl ; 0 ; reset ('writei' will set it)
 15755                              <1> 
 15756 0001156C 3B05[20890100]      <1> 	cmp	eax, [writei.fclust]
 15757 00011572 7516                <1> 	jne	short mget_w_15
 15758                              <1> 
 15759 00011574 8A0D[59940100]      <1> 	mov	cl, [cdev]
 15760 0001157A 3A0D[0D890100]      <1> 	cmp	cl, [writei.drv]
 15761 00011580 7508                <1> 	jne	short mget_w_15
 15762                              <1>  	; [writei.l_clust] & [writei.l_index] are valid, 
 15763                              <1> 	;  we don't need to get last cluster & last cluster index
 15764 00011582 8B0D[2C890100]      <1> 	mov	ecx, [writei.l_index]
 15765 00011588 EB4A                <1> 	jmp	short mget_w_17
 15766                              <1> mget_w_15:
 15767 0001158A A3[20890100]        <1> 	mov	[writei.fclust], eax ; first section (FDT number)
 15768                              <1> 	; edx = 0
 15769 0001158F 8915[18890100]      <1> 	mov	[writei.cluster], edx ; 0 ; current section
 15770 00011595 8915[24890100]      <1> 	mov 	[writei.fs_index], edx ; 0 ; curret section index
 15771                              <1> 
 15772                              <1> 	; eax = FDT number (section 0 header address)
 15773 0001159B E8F1B6FFFF          <1> 	call	get_last_section
 15774                              <1> 	;jc	short mget_w_err ; eax = error code
 15775                              <1> 	; 08/08/2022
 15776 000115A0 7305                <1> 	jnc	short mget_w_26
 15777 000115A2 E9B6FEFFFF          <1> 	jmp	mget_w_err
 15778                              <1> mget_w_26:
 15779 000115A7 8915[24890100]      <1> 	mov 	[writei.fs_index], edx ; sector index in last section
 15780                              <1> 
 15781 000115AD A3[28890100]        <1> 	mov	[writei.lclust], eax ; last section address
 15782                              <1> 
 15783 000115B2 8B0D[4C870100]      <1> 	mov	ecx, [glc_index] ; last section index
 15784 000115B8 890D[2C890100]      <1> 	mov	[writei.l_index], ecx
 15785                              <1> 
 15786 000115BE A0[30890100]        <1> 	mov	al, [writei.ofn]
 15787 000115C3 FEC0                <1> 	inc	al
 15788 000115C5 A2[6B890100]        <1> 	mov	[setfmod], al ; update lm date&time sign
 15789                              <1> 
 15790                              <1> mget_w_16:
 15791                              <1> 	; edx = (existing) last section (sector) index
 15792 000115CA 8B0D[1C890100]      <1> 	mov	ecx, [writei.c_index] ; final section (sector) index
 15793 000115D0 29D1                <1> 	sub	ecx, edx
 15794 000115D2 7630                <1> 	jna	short mget_w_19
 15795                              <1> 	; ecx = sector count
 15796                              <1> mget_w_17:
 15797 000115D4 A1[28890100]        <1> 	mov	eax, [writei.lclust]
 15798                              <1> 	; ESI = Logical dos drv desc. table address
 15799                              <1>         ; EAX = Last section
 15800                              <1>         ; (ECX = 0 for directory)
 15801                              <1>         ; ECX = sector count (except FDT)
 15802 000115D9 E841ADFFFF          <1> 	call	add_new_fs_section
 15803 000115DE 730F                <1> 	jnc	short mget_w_18
 15804                              <1> 
 15805                              <1> 	; If error number = 27h (insufficient disk space)
 15806                              <1> 	; it is needed to check free consequent sectors
 15807                              <1> 	; (1 data sector at least and +1 section header sector)
 15808                              <1> 
 15809 000115E0 83F827              <1> 	cmp	eax, 27h
 15810                              <1> 	;jne	mget_w_err ; eax = error code
 15811                              <1> 	; 25/07/2022
 15812 000115E3 7405                <1> 	je	short mget_w_24
 15813                              <1> mget_w_23:
 15814 000115E5 E973FEFFFF          <1> 	jmp	mget_w_err
 15815                              <1> mget_w_24:
 15816                              <1> 	; ecx = count of free consequent sectors
 15817                              <1> 	; ecx must be > 1 (1 data + 1 header sector)
 15818 000115EA 49                  <1> 	dec	ecx
 15819                              <1> 	;jz	short mget_w_err
 15820                              <1> 	;jmp	short mget_w_17
 15821                              <1> 	; 23/07/2022
 15822 000115EB 75E7                <1> 	jnz	short mget_w_17
 15823                              <1> 	;jmp	mget_w_err
 15824                              <1> 	; 25/07/2022
 15825 000115ED EBF6                <1> 	jmp	short mget_w_23
 15826                              <1> 
 15827                              <1> mget_w_18:
 15828 000115EF A3[28890100]        <1> 	mov	[writei.lclust], eax ; (new) last section
 15829                              <1> 	; ecx = sector count (except section header)
 15830 000115F4 8B15[2C890100]      <1> 	mov	edx, [writei.l_index]
 15831 000115FA 01CA                <1> 	add	edx, ecx ; add sector count to index
 15832 000115FC 8915[2C890100]      <1> 	mov	[writei.l_index], edx
 15833 00011602 EBC6                <1> 	jmp	short mget_w_16
 15834                              <1> 
 15835                              <1> mget_w_19:
 15836 00011604 89E9                <1> 	mov	ecx, ebp
 15837 00011606 030D[9C940100]      <1> 	add	ecx, [u.count]
 15838 0001160C 890D[80950100]      <1> 	mov	[i.size], ecx ; save new file size
 15839                              <1> 	;sub	edx, edx ; 0
 15840                              <1> 
 15841 00011612 A0[59940100]        <1> 	mov	al, [cdev]
 15842 00011617 A2[0D890100]        <1> 	mov	[writei.drv], al ; physical drive number
 15843                              <1> 	; edx = 0
 15844 0001161C 89E8                <1> 	mov	eax, ebp ; file offset
 15845 0001161E 89C2                <1> 	mov	edx, eax
 15846                              <1> 	; 1 cluster = 512 bytes (for Singlix FS)
 15847 00011620 C1E809              <1> 	shr	eax, 9  ; / 512
 15848 00011623 81E2FF010000        <1> 	and	edx, 1FFh
 15849                              <1> 	; edx = byte offset in cluster/sector (<= 511)
 15850                              <1> 	; eax = section (sector/cluster) index
 15851 00011629 A3[1C890100]        <1> 	mov	[writei.c_index], eax
 15852 0001162E 668915[16890100]    <1> 	mov	[writei.offset], dx
 15853                              <1> 	;mov	byte [writei.s_index], 0 ; sector index in cluster
 15854 00011635 E90FFEFFFF          <1> 	jmp	mget_w_3
 15855                              <1> 
 15856                              <1> update_file_lmdt: ; & update file size
 15857                              <1> 	; 03/09/2024
 15858                              <1> 	; 27/08/2024 - TRDOS 386 v2.0.9
 15859                              <1> 	; 30/07/2022
 15860                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
 15861                              <1> 	; 26/10/2016
 15862                              <1> 	; 24/10/2016
 15863                              <1> 	; 23/10/2016
 15864                              <1> 	; 22/10/2016 - TRDOS 386 (TRDOS v2.0)
 15865                              <1> 	;
 15866                              <1> 	; Update last modification date&time of file
 15867                              <1> 	; (call from syswrite -> writei)
 15868                              <1> 	; ((also updates file size)) // 26/10/2016
 15869                              <1> 	;
 15870                              <1> 	; INPUT:
 15871                              <1> 	;      byte [setfmod] = open file number
 15872                              <1> 	; OUTPUT:
 15873                              <1> 	;      cf = 0 -> success !
 15874                              <1> 	;      cf = 1 -> lmdt update has been failed!
 15875                              <1> 	;
 15876                              <1> 	; Modified registers: eax, ebx, ecx, edx, esi, edi
 15877                              <1> 	;
 15878                              <1> 
 15879                              <1> 	;cmp	byte [setfmod], 0
 15880                              <1> 	;jna	short uflmdt_2 ; nothing to do
 15881                              <1> 
 15882                              <1> 	; 27/08/2024
 15883                              <1> 	; if [ebx+OF_FCLUSTER] = 0 and [setfclust] > 0
 15884                              <1> 	; [setfclust] will be copied to Directory entry's
 15885                              <1> 	; first cluster fields (LO/HI).
 15886                              <1> 	; (and [setfclust] will be cleared.)
 15887                              <1> 
 15888 0001163A 31C0                <1> 	xor	eax, eax
 15889                              <1> 
 15890 0001163C 0FB61D[6B890100]    <1> 	movzx	ebx, byte [setfmod]
 15891 00011643 FECB                <1> 	dec	bl ; open file index number (0 based)
 15892                              <1> 
 15893 00011645 8AA3[008A0100]      <1> 	mov	ah, [ebx+OF_DRIVE]
 15894 0001164B BE00010900          <1> 	mov	esi, Logical_DOSDisks
 15895 00011650 01C6                <1> 	add	esi, eax
 15896 00011652 C0E302              <1> 	shl	bl, 2 ; *4
 15897 00011655 8B8B[80890100]      <1> 	mov	ecx, [ebx+OF_FCLUSTER] ; first cluster
 15898 0001165B 8B93[008C0100]      <1> 	mov	edx, [ebx+OF_DIRCLUSTER] ; dir cluster
 15899                              <1> 
 15900 00011661 D0EB                <1> 	shr	bl, 1 ; /2
 15901 00011663 0FB7BB[008E0100]    <1> 	movzx	edi, word [ebx+OF_DIRENTRY]
 15902                              <1> 
 15903                              <1> 	; 03/09/2024
 15904 0001166A 80C441              <1> 	add	ah, 'A'
 15905 0001166D 8A4603              <1> 	mov	al, [esi+LD_FATType]
 15906                              <1> 	
 15907 00011670 803D[A9840100]01    <1> 	cmp	byte [DirBuff_ValidData], 1
 15908 00011677 727E                <1> 	jb	short uflmdt_4
 15909                              <1> 
 15910                              <1> 	;mov	al, [DirBuff_DRV]
 15911                              <1> 	;sub	al, 'A'	
 15912                              <1> 	;cmp	al, ah
 15913                              <1> 	; 03/09/2024
 15914                              <1> 	; 27/08/2024
 15915                              <1> 	;add	ah, 'A'
 15916                              <1> 	;mov	al, [esi+LD_FATType]
 15917 00011679 3A25[A7840100]      <1> 	cmp	ah, [DirBuff_DRV]
 15918 0001167F 7576                <1> 	jne	short uflmdt_4 ; different drive
 15919                              <1> 	;mov	al, [esi+LD_FATType]
 15920 00011681 3A05[A8840100]      <1> 	cmp	al, [DirBuff_FATType]
 15921 00011687 756E                <1> 	jne	short uflmdt_5 ; different FS type
 15922 00011689 3B15[AE840100]      <1> 	cmp	edx, [DirBuff_Cluster]
 15923 0001168F 7566                <1> 	jne	short uflmdt_5 ; different cluster
 15924                              <1> 
 15925                              <1> uflmdt_1:
 15926                              <1> 	; Directory buffer is ready here!
 15927                              <1> 	; OF_FCLUSTER must be compared/verified
 15928 00011691 BE00000800          <1> 	mov	esi, Directory_Buffer
 15929                              <1> 	;shl	di, 5 ; dir entry index * 32
 15930                              <1> 	; 23/07/2022
 15931 00011696 C1E705              <1> 	shl	edi, 5
 15932 00011699 01FE                <1> 	add	esi, edi ; offset
 15933                              <1> 	;
 15934                              <1> 	; 03/09/2024
 15935                              <1> 	;test	byte [esi+DirEntry_Attr], 18h ; Vol & Dir
 15936                              <1> 	;jnz	short uflmdt_2 ; not a valid file !
 15937 0001169B 668B4614            <1> 	mov	ax, [esi+DirEntry_FstClusHI]
 15938 0001169F C1E010              <1> 	shl	eax, 16
 15939 000116A2 668B461A            <1> 	mov	ax, [esi+DirEntry_FstClusLO]
 15940                              <1> 
 15941                              <1> 	; 03/09/2024 (short jump)
 15942 000116A6 F6460B18            <1> 	test	byte [esi+DirEntry_Attr], 18h ; Vol & Dir
 15943 000116AA 7575                <1> 	jnz	short uflmdt_2 ; not a valid file !
 15944                              <1> 
 15945 000116AC 39C8                <1> 	cmp	eax, ecx ; same first cluster ?
 15946                              <1> 	;je	short uflmdt_3 ; yes, it is OK !!!
 15947                              <1> 	; 23/07/2022
 15948 000116AE 7571                <1> 	jne	short uflmdt_2
 15949                              <1> 
 15950                              <1> 	;;;
 15951                              <1> 	; 03/09/2024
 15952 000116B0 D0E3                <1> 	shl	bl, 1 ; *2
 15953                              <1> 	; 27/08/2024 
 15954 000116B2 21C0                <1> 	and	eax, eax
 15955 000116B4 751B                <1> 	jnz	short uflmdt_3 ; not empty file
 15956 000116B6 8705[6C890100]      <1> 	xchg	eax, [setfclust]
 15957 000116BC 09C0                <1> 	or	eax, eax
 15958 000116BE 7411                <1> 	jz	short uflmdt_3
 15959                              <1> 	; 03/09/2024
 15960 000116C0 8983[80890100]      <1> 	mov	[ebx+OF_FCLUSTER], eax
 15961                              <1> 	;
 15962 000116C6 6689461A            <1> 	mov	[esi+DirEntry_FstClusLO], ax
 15963 000116CA C1E810              <1> 	shr	eax, 16
 15964 000116CD 66894614            <1> 	mov	[esi+DirEntry_FstClusHI], ax
 15965                              <1> 	;;;
 15966                              <1> 
 15967                              <1> uflmdt_3:
 15968                              <1> 	; Update directory entry
 15969                              <1> 	; 03/09/2024
 15970                              <1> 	; 26/10/2016
 15971                              <1> 	;shl	bl, 1 ; *2
 15972 000116D1 8B83[008B0100]      <1> 	mov	eax, [ebx+OF_SIZE] ; file size
 15973 000116D7 89461C              <1> 	mov	[esi+DirEntry_FileSize], eax
 15974                              <1> 	;
 15975 000116DA E8DD98FFFF          <1> 	call	convert_current_date_time
 15976                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
 15977                              <1>         ; 	    AX = Time in dos dir entry format
 15978 000116DF 66894616            <1> 	mov	[esi+DirEntry_WrtTime], ax
 15979 000116E3 66895618            <1> 	mov	[esi+DirEntry_WrtDate], dx
 15980 000116E7 66895612            <1> 	mov	[esi+DirEntry_LastAccDate], dx
 15981 000116EB C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2
 15982                              <1> 	;call	save_directory_buffer
 15983                              <1> 	;retn
 15984                              <1> 	; 23/07/2022
 15985 000116F2 E95A99FFFF          <1> 	jmp	save_directory_buffer
 15986                              <1> 
 15987                              <1> uflmdt_4:
 15988                              <1> 	; Directory buffer sector read&write
 15989                              <1> 	; 23/10/2016
 15990                              <1> 	; 27/08/2024
 15991                              <1> 	;mov	al, [esi+LD_FATType]
 15992                              <1> uflmdt_5:
 15993 000116F7 BB[AC9A0100]        <1> 	mov	ebx, rw_buffer ; Common r/w sector buffer addr
 15994                              <1> 
 15995 000116FC 20C0                <1> 	and	al, al ; 0 = Singlix FS
 15996 000116FE 7428                <1> 	jz	short uflmdt_11
 15997                              <1> 
 15998                              <1> ;uflmdt_12:
 15999 00011700 21D2                <1> 	and	edx, edx
 16000 00011702 752B                <1> 	jnz	short uflmdt_9
 16001                              <1> 
 16002 00011704 3C02                <1> 	cmp	al, 2  ; 3 = FAT32
 16003 00011706 7724                <1> 	ja	short uflmdt_8
 16004                              <1> 
 16005 00011708 89F8                <1> 	mov	eax, edi ; directory entry index number
 16006                              <1> 	;shr	ax, 4 ; 16 entries per sector
 16007                              <1> 	; 23/07/2022
 16008 0001170A C1E804              <1> 	shr	eax, 4
 16009 0001170D 034664              <1> 	add	eax, [esi+LD_ROOTBegin]
 16010                              <1> 	; eax = root directory sector
 16011                              <1> uflmdt_6:
 16012 00011710 50                  <1> 	push	eax ; * ; disk sector address
 16013 00011711 51                  <1> 	push	ecx ; first cluster
 16014 00011712 B901000000          <1> 	mov	ecx, 1
 16015                              <1> 	; ecx = sector count
 16016 00011717 E8E4080000          <1> 	call	disk_read
 16017 0001171C 59                  <1> 	pop	ecx
 16018 0001171D 7324                <1> 	jnc	short uflmdt_10
 16019 0001171F 58                  <1> 	pop	eax ; *
 16020                              <1> uflmdt_7:
 16021 00011720 C3                  <1> 	retn
 16022                              <1> 
 16023                              <1> uflmdt_2:
 16024                              <1> 	; save directory buffer if has modified/changed sign
 16025                              <1> 	; (It is good to save dir buff even if the searched
 16026                              <1> 	; directory entry is not found !?)
 16027 00011721 E82B99FFFF          <1> 	call	save_directory_buffer
 16028 00011726 F9                  <1> 	stc	; update failed
 16029 00011727 C3                  <1> 	retn
 16030                              <1> 
 16031                              <1> uflmdt_11:
 16032                              <1> 	; 24/10/2016
 16033                              <1> 	; Update last modification date & time of a file
 16034                              <1> 	; on a disk with Singlix File System.
 16035                              <1> 	;
 16036                              <1> 	; (Method: Read the FDT -File Description Table-
 16037                              <1> 	; sector of the file and update the lmdt data fields,
 16038                              <1> 	; then write FDT sector to the disk.
 16039                              <1> 	; /// It is easy but there is compatibility buffer
 16040                              <1> 	; method also for changing directory entry data and
 16041                              <1> 	; also there are some programming issues for Singlix
 16042                              <1> 	; file system (TRFS), which are not completed yet!)
 16043                              <1> 	;
 16044                              <1> 	; Not ready yet ! (24/10/2016)
 16045                              <1> 	; /// Temporary code for error return ! ///
 16046 00011728 31C0                <1> 	xor	eax, eax
 16047 0001172A F9                  <1> 	stc
 16048 0001172B C3                  <1> 	retn
 16049                              <1> 
 16050                              <1> uflmdt_8:
 16051 0001172C 8B5632              <1> 	mov	edx, [esi+LD_BPB+FAT32_RootFClust]
 16052                              <1> uflmdt_9:
 16053 0001172F 83FA02              <1> 	cmp	edx, 2
 16054 00011732 72EC                <1> 	jb	short uflmdt_7 ; invalid, nothing to do
 16055                              <1> 
 16056                              <1> 	;sub	edx, 2
 16057                              <1> 	; 30/07/2022
 16058 00011734 4A                  <1> 	dec	edx
 16059 00011735 4A                  <1> 	dec	edx
 16060 00011736 89D0                <1> 	mov	eax, edx
 16061 00011738 0FB65613            <1> 	movzx	edx, byte [esi+LD_BPB+SecPerClust]
 16062 0001173C F7E2                <1> 	mul	edx
 16063 0001173E 034668              <1> 	add	eax, [esi+LD_DATABegin]
 16064                              <1> 	; eax = sub directory (data) sector
 16065 00011741 EBCD                <1> 	jmp	short uflmdt_6
 16066                              <1> 
 16067                              <1> uflmdt_10:
 16068                              <1> 	; Directory sector buffer is ready here!
 16069                              <1> 	; OF_FCLUSTER must be compared/verified
 16070                              <1> 	; edi = dir entry index number (<= 2047)
 16071 00011743 6683E70F            <1> 	and	di, 0Fh ; 16 entries per sector
 16072                              <1> 	;shl	di, 5 ; dir entry index * 32
 16073                              <1> 	; 23/07/2022
 16074 00011747 C1E705              <1> 	shl	edi, 5
 16075 0001174A 81C7[AC9A0100]      <1> 	add	edi, rw_buffer
 16076                              <1> 	;
 16077 00011750 F6470B18            <1> 	test	byte [edi+DirEntry_Attr], 18h ; Vol & Dir
 16078 00011754 75CB                <1> 	jnz	short uflmdt_2 ; not a valid file !
 16079 00011756 668B5714            <1> 	mov	dx, [edi+DirEntry_FstClusHI]
 16080 0001175A C1E210              <1> 	shl	edx, 16
 16081 0001175D 668B571A            <1> 	mov	dx, [edi+DirEntry_FstClusLO]
 16082 00011761 39CA                <1> 	cmp	edx, ecx ; same first cluster ?
 16083 00011763 75BC                <1> 	jne	short uflmdt_2 ; no !?
 16084                              <1> 
 16085                              <1> 	;;;
 16086                              <1> 	; 27/08/2024 
 16087 00011765 21D2                <1> 	and	edx, edx
 16088 00011767 7515                <1> 	jnz	short uflmdt_12 ; not empty file
 16089 00011769 8715[6C890100]      <1> 	xchg	edx, [setfclust]
 16090 0001176F 09D2                <1> 	or	edx, edx
 16091 00011771 740B                <1> 	jz	short uflmdt_12
 16092 00011773 6689571A            <1> 	mov	[edi+DirEntry_FstClusLO], dx
 16093 00011777 C1EA10              <1> 	shr	edx, 16
 16094 0001177A 66895714            <1> 	mov	[edi+DirEntry_FstClusHI], dx
 16095                              <1> uflmdt_12:
 16096                              <1> 	;;;
 16097                              <1> 
 16098                              <1> 	; Update directory entry
 16099 0001177E E83998FFFF          <1> 	call	convert_current_date_time
 16100                              <1> 	; OUTPUT -> DX = Date in dos dir entry format
 16101                              <1>         ; 	    AX = Time in dos dir entry format
 16102 00011783 66894716            <1> 	mov	[edi+DirEntry_WrtTime], ax
 16103 00011787 66895718            <1> 	mov	[edi+DirEntry_WrtDate], dx
 16104 0001178B 66895712            <1> 	mov	[edi+DirEntry_LastAccDate], dx
 16105                              <1> 
 16106 0001178F 58                  <1> 	pop	eax ; *
 16107                              <1> 
 16108 00011790 BB[AC9A0100]        <1> 	mov	ebx, rw_buffer ; Common r/w sector buffer addr
 16109 00011795 B901000000          <1> 	mov	ecx, 1
 16110                              <1> 	; esi = logical dos description table address
 16111                              <1> 	; eax = disk sector number/address (LBA)
 16112                              <1> 	; ecx = sector count
 16113                              <1> 	; ebx = buffer address
 16114 0001179A E852080000          <1> 	call	disk_write
 16115 0001179F 7280                <1> 	jc	short uflmdt_2
 16116                              <1> ;uflmdt_12:
 16117                              <1> 	; save directory buffer if has modified/changed sign
 16118                              <1> 	;call	save_directory_buffer
 16119                              <1> 	;retn
 16120                              <1> 	; 23/07/2022
 16121 000117A1 E9AB98FFFF          <1> 	jmp	save_directory_buffer
 16122                              <1> 
 16123                              <1> sysalloc:
 16124                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
 16125                              <1> 	; 14/10/2017
 16126                              <1> 	; 20/08/2017 - 01/09/2017
 16127                              <1> 	; 20/02/2017 - 04/03/2017 - 15/05/2017
 16128                              <1> 	; 19/02/2017 - TRDOS 386 (TRDOS v2.0)
 16129                              <1> 	; (TRDOS 386 feature only!)
 16130                              <1> 	;
 16131                              <1> 	; Allocate Contiguous Memory Block/Pages (for user)
 16132                              <1> 	; (System call for DMA Buffer allocation etc.)
 16133                              <1> 	;
 16134                              <1> 	; INPUT ->
 16135                              <1> 	;	EBX = Virtual address (for user)
 16136                              <1> 	;	     (Physical memory block/aperture
 16137                              <1> 	;	     will be mapped to this virtual address)
 16138                              <1> 	;	ECX = Byte Count
 16139                              <1> 	;	     (will be rounded up to page border)
 16140                              <1> 	;	If ECX = 0
 16141                              <1> 	;	    System call will return with an error (cf=1)
 16142                              <1> 	;	    but ECX will contain maximum size of
 16143                              <1> 	;	    available memory aperture and physical
 16144                              <1> 	;	    (beginning) address of that aperture
 16145                              <1> 	;	    (which have maximum size) will be in EAX.
 16146                              <1> 	;	EDX = Upper limit of the requested physical memory
 16147                              <1> 	;	      block/pages.
 16148                              <1> 	;	     (The last byte address of the memory aperture
 16149                              <1> 	;	      must not be equal to or above this limit.)
 16150                              <1> 	;	If EDX = 0
 16151                              <1> 	; 	   there is NOLIMIT !
 16152                              <1> 	;	If EDX = 0FFFFFFFFh (-1)
 16153                              <1> 	;	   ESI = Lower Limit !
 16154                              <1> 	;		(Beginning of the block must not be 'less'
 16155                              <1> 	;		than this.) (Must be equal to or above...)
 16156                              <1> 	;	   EDI = Upper Limit !
 16157                              <1> 	;		(End of the block must be !less! than this)
 16158                              <1> 	;		(The last byte addr of the memory aperture
 16159                              <1> 	;		must not be equal to or above this limit.)
 16160                              <1> 	;
 16161                              <1> 	; OUTPUT ->
 16162                              <1> 	;	If CF = 0
 16163                              <1> 	;	EAX = Physical address of the allocated memory block
 16164                              <1> 	;	ECX = Allocated bytes (as rounded up to page borders)
 16165                              <1> 	;	EBX = Virtual address (as rounded up)
 16166                              <1> 	;	IF CF = 1
 16167                              <1> 	;	    Requested (size of) Memory block could not be
 16168                              <1> 	;	    allocated to the user!
 16169                              <1> 	;	IF CF = 1 & EAX = 0 (Insufficient memory error!)
 16170                              <1> 	;	   ECX = Total number of free bytes
 16171                              <1> 	;	         (not size of available contiguous bytes!)
 16172                              <1> 	;	If CF = 1 & EAX > 0
 16173                              <1> 	;	   there is not a memory aperture with requested size
 16174                              <1> 	;	   but total free mem is not less than requested size.
 16175                              <1> 	;	   EAX = Physical addr of available memory aperture
 16176                              <1> 	;	   	 with max size 
 16177                              <1> 	;	        (but it doesn't fit to the conditions!)
 16178                              <1> 	;	   ECX = Size of available memory aperture in bytes.
 16179                              <1> 	;	If CF = 1 -> EAX = 0FFFFFFFFh
 16180                              <1> 	;	   Conditions/Parameters are wrong !
 16181                              <1> 	;	   ECX is same with input value.
 16182                              <1> 	;
 16183                              <1> 	; Note:	Previously allocated pages will be deallocated if
 16184                              <1> 	;       new allocation conditions are met.
 16185                              <1> 	;
 16186                              <1> 	; Note: u.break control may be included in future versions
 16187                              <1> 	;
 16188                              <1> 
 16189 000117A6 31C0                <1> 	xor	eax, eax ; 0
 16190                              <1> 	; 14/10/2017
 16191 000117A8 4A                  <1> 	dec	edx ; is there a limit ?
 16192 000117A9 7810                <1> 	js	short sysalloc_1 ;  0 -> 0FFFFFFFFh -> NO LIMIT
 16193 000117AB 42                  <1> 	inc	edx ; > 0
 16194                              <1> 	; Check upper address limit
 16195                              <1> 	;(round up to page borders)
 16196 000117AC 81C1FF0F0000        <1> 	add	ecx, PAGE_SIZE-1 ; 4095
 16197 000117B2 6681E100F0          <1> 	and	cx, ~PAGE_OFF ; not 4095
 16198 000117B7 39CA                <1> 	cmp	edx, ecx ; upper limit - block size
 16199 000117B9 7224                <1> 	jb	short sysalloc_err
 16200                              <1> sysalloc_1:
 16201                              <1> 	; EAX = Beginning address (physical)
 16202                              <1> 	; EAX = 0 -> Allocate mem block from the 1st proper aperture
 16203                              <1> 	; ECX = Number of bytes to be allocated
 16204 000117BB E83345FFFF          <1> 	call	allocate_memory_block
 16205 000117C0 721D                <1> 	jc	short sysalloc_err
 16206                              <1> 	; 01/09/2017
 16207 000117C2 29C2                <1> 	sub	edx, eax ; upper limit address - beginning address
 16208 000117C4 760F                <1> 	jna	short sysalloc_3 ; begin addr not less than the limit
 16209 000117C6 39CA                <1> 	cmp	edx, ecx
 16210 000117C8 720B                <1> 	jb	short sysalloc_3 ; end address overs the limit
 16211                              <1> sysalloc_2:	
 16212                              <1> 	; EAX = Beginning (physical) addr of the allocated mem block
 16213                              <1> 	; ECX = Num of allocated bytes (rounded up to page borders) 
 16214 000117CA 50                  <1> 	push	eax ; * ; 04/03/2017
 16215                              <1> 	; Here, requested contiquous memory pages have been allocated
 16216                              <1> 	; on Memory Allocation Table but user's page directory
 16217                              <1> 	; and page tables have not been updated yet!
 16218 000117CB 51                  <1> 	push	ecx ; **
 16219                              <1> 	; ebx = virtual address (will be rounded up to page border)
 16220                              <1> 	; ecx = number of bytes to be deallocated
 16221                              <1> 	;	will be adjusted to ebx+ecx round down - ebx round up
 16222 000117CC E87A48FFFF          <1> 	call	deallocate_user_pages
 16223 000117D1 731F                <1> 	jnc	short sysalloc_4 ; EAX = Deallocated memory bytes
 16224 000117D3 59                  <1> 	pop	ecx ; **
 16225 000117D4 58                  <1> 	pop	eax ; *
 16226                              <1> sysalloc_3:
 16227                              <1> 	; error !
 16228                              <1> 	; restore Memory Allocation Table Content
 16229 000117D5 E83347FFFF          <1> 	call	deallocate_memory_block
 16230 000117DA 31C0                <1> 	xor	eax, eax ; 0
 16231 000117DC 48                  <1> 	dec	eax ; 0FFFFFFFFh ; 15/05/2017
 16232 000117DD EB09                <1> 	jmp	short sysalloc_wrong
 16233                              <1> sysalloc_err:
 16234 000117DF 8B2D[70940100]      <1> 	mov	ebp, [u.usp]  ; ebp points to user's registers
 16235 000117E5 894D18              <1> 	mov	[ebp+24], ecx ; return to user with ecx value
 16236                              <1> sysalloc_wrong:
 16237                              <1> 	; eax = 0FFFFFFFFh
 16238 000117E8 A3[74940100]        <1> 	mov	[u.r0], eax
 16239 000117ED E942B6FFFF          <1> 	jmp	error
 16240                              <1> sysalloc_4:
 16241 000117F2 8B2D[70940100]      <1> 	mov	ebp, [u.usp]  ; ebp points to user's registers
 16242 000117F8 894518              <1> 	mov	[ebp+24], eax ; return to user with ecx value
 16243 000117FB 895D10              <1> 	mov	[ebp+16], ebx ; new value of ebx (rounded up)
 16244 000117FE 89C1                <1> 	mov	ecx, eax ; byte count (from 'deallocate_user_pages')
 16245 00011800 5A                  <1> 	pop	edx ; ** ; discard (another) byte count
 16246 00011801 58                  <1> 	pop	eax ; *
 16247 00011802 A3[74940100]        <1> 	mov	[u.r0], eax ; physical address
 16248                              <1> 
 16249 00011807 51                  <1> 	push	ecx ; 20/08/2017
 16250                              <1> 	;
 16251                              <1> 	; Write newly allocated contiguous (physical) pages
 16252                              <1> 	; on page dir and page tables of current user/process
 16253                              <1> 	; as PRESENT, USER, WRITABLE
 16254                              <1> 	; (then clear allocated pages)
 16255 00011808 E82649FFFF          <1> 	call	allocate_user_pages
 16256                              <1> 	;jnc	sysret ; OK! return to process with success...
 16257                              <1> 
 16258                              <1> 	; 20/08/2017 ('sysdma' modification)
 16259 0001180D 59                  <1> 	pop	ecx
 16260 0001180E A1[74940100]        <1> 	mov	eax, [u.r0]   ; physical address (of the block)
 16261                              <1> 
 16262 00011813 7219                <1> 	jc	short sysalloc_6
 16263                              <1> 
 16264 00011815 833D[38930100]FF    <1> 	cmp	dword [dma_addr], 0FFFFFFFFh ; -1
 16265                              <1> 	;jb	sysret
 16266                              <1> 	; 23/07/2022
 16267 0001181C 720B                <1> 	jb	short sysalloc_5 ; jmp sysret
 16268                              <1> 
 16269 0001181E A3[38930100]        <1> 	mov	[dma_addr], eax ; save dma address for sysdma
 16270 00011823 890D[3C930100]      <1> 	mov	[dma_size], ecx ; save dma buff size for sysdma
 16271                              <1> sysalloc_5:
 16272 00011829 E926B6FFFF          <1> 	jmp	sysret
 16273                              <1> 
 16274                              <1> sysalloc_6:
 16275                              <1> 	;
 16276                              <1> 	; unexpected error ! insufficient memory !? conflict !?
 16277                              <1> 	; (!!?there is not a free page for a new page table?!!)
 16278                              <1> 	; We need to terminate process with error message !!!
 16279                              <1> 	;
 16280 0001182E 8B2D[70940100]      <1> 	mov	ebp, [u.usp]  ; ebp points to user's registers
 16281 00011834 8B4D18              <1> 	mov	ecx, [ebp+24] ; byte count
 16282                              <1> 
 16283                              <1> 	; 20/08/2017
 16284                              <1> 	;mov	eax, [u.r0]   ; physical address (of the block)
 16285                              <1> 
 16286                              <1> 	;
 16287                              <1> 	; restore Memory Allocation Table Content
 16288 00011837 E8D146FFFF          <1> 	call	deallocate_memory_block
 16289                              <1> 	;
 16290 0001183C 803D[DE670000]03    <1> 	cmp	byte [CRT_MODE], 3 ; 80x25 text mode?
 16291 00011843 7407                <1> 	je	short sysalloc_7 ; yes
 16292                              <1> 	; Current mode is VGA (or CGA graphics) mode,
 16293                              <1> 	; We need to return to text mode for displaying
 16294                              <1> 	; error message just before 'sysexit'.
 16295 00011845 B003                <1> 	mov	al, 3
 16296 00011847 E8F702FFFF          <1> 	call	_set_mode
 16297                              <1> sysalloc_7:
 16298 0001184C BE[04380100]        <1> 	mov	esi, beep_Insufficient_Memory ; error message
 16299 00011851 E81455FFFF          <1> 	call	print_msg ; print/display the message
 16300 00011856 B801000000          <1> 	mov	eax, 1 ; ax=1 is needed for 'sysexit' procedure
 16301 0001185B E932B7FFFF          <1> 	jmp	sysexit ; and terminate the process !
 16302                              <1> 
 16303                              <1> sysdalloc:
 16304                              <1> 	; 19/02/2017 - TRDOS 386 (TRDOS v2.0)
 16305                              <1> 	; (TRDOS 386 feature only!)
 16306                              <1> 	;
 16307                              <1> 	; Deallocate Memory Block/Pages (for user)
 16308                              <1> 	; (Complementary call for sysalloc.)
 16309                              <1> 	;
 16310                              <1> 	; INPUT ->
 16311                              <1> 	;	EBX = Virtual address (for user)
 16312                              <1> 	;	      (will be rounded up to page border)
 16313                              <1> 	;	ECX = Byte Count
 16314                              <1> 	;	     (will be adjusted to page borders)
 16315                              <1> 	;	If ICX = 0
 16316                              <1> 	;	   nothing to do
 16317                              <1> 	;	If EBX + ECX > User's ESP
 16318                              <1> 	;	   nothing to do
 16319                              <1> 	;
 16320                              <1> 	; Note: u.break control may be included in future versions
 16321                              <1> 	;
 16322                              <1> 	; OUTPUT ->
 16323                              <1> 	;	If CF = 0
 16324                              <1> 	;	   EAX = Deallocated memory bytes
 16325                              <1> 	;	   EBX = Virtual address (as rounded up)
 16326                              <1> 	;	IF CF = 1
 16327                              <1> 	;	   EAX = 0
 16328                              <1> 	;
 16329                              <1> 	; Note:	Main purpose of this call is to deallocate/release
 16330                              <1> 	;	previously allocated (physically) contiguous memory
 16331                              <1> 	;	pages but beginning (virtual) address may not be
 16332                              <1> 	;	followed by physically contiguous pages. So, this
 16333                              <1> 	;	system call will deallocate user's virtually
 16334                              <1> 	;	contiguous memory pages. Also, there is not any
 16335                              <1> 	;	objections to use this system call without sysalloc
 16336                              <1> 	;	system call; only possible objection is to lost data
 16337                              <1> 	;	within user's memory space, if the beginning address
 16338                              <1> 	;	and size is not proper.
 16339                              <1> 	;
 16340                              <1> 	; Note: Empty page tables will not be deallocated!!!
 16341                              <1> 	;       (they will be deallocated at process termination)
 16342                              <1> 	;
 16343                              <1> 	; Note: When the program terminates itself or when it is 
 16344                              <1> 	;	terminated by operating system kernel, all allocated
 16345                              <1> 	;	memory pages will be deallocated during termination
 16346                              <1> 	;	stage. So, 'sysdalloc' is not necessary except 
 16347                              <1> 	;	forgiving memory block to other programs/processes.
 16348                              <1> 	;
 16349 00011860 8B15[6C940100]      <1> 	mov	edx, [u.sp]
 16350 00011866 8B420C              <1> 	mov	eax, [edx+12] ; user's stack pointer
 16351 00011869 29C8                <1> 	sub	eax, ecx ; esp - byte count
 16352 0001186B 24FC                <1> 	and	al, 0FCh ; dword alignment
 16353 0001186D 39D8                <1> 	cmp	eax, ebx
 16354 0001186F 7220                <1> 	jb	short sysdalloc_err ; deallocation overlaps with stack
 16355                              <1> 
 16356 00011871 31C0                <1> 	xor	eax, eax
 16357 00011873 21C9                <1> 	and	ecx, ecx
 16358 00011875 7407                <1> 	jz	short sysdalloc_2
 16359                              <1> 	
 16360 00011877 E8CF47FFFF          <1> 	call	deallocate_user_pages
 16361 0001187C 7213                <1> 	jc	short sysdalloc_err
 16362                              <1> 
 16363                              <1> sysdalloc_2:
 16364 0001187E A3[74940100]        <1> 	mov	[u.r0], eax
 16365 00011883 8B2D[70940100]      <1> 	mov	ebp, [u.usp]
 16366 00011889 895D10              <1> 	mov	[ebp+16], ebx ; new value of ebx
 16367 0001188C E9C3B5FFFF          <1> 	jmp	sysret
 16368                              <1> 
 16369                              <1> sysdalloc_err:
 16370 00011891 A3[74940100]        <1> 	mov	[u.r0], eax ; 0
 16371 00011896 E999B5FFFF          <1> 	jmp	error
 16372                              <1> 
 16373                              <1> syscalbac:
 16374                              <1> 	; SYS CALLBACK
 16375                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
 16376                              <1> 	; 03/08/2020
 16377                              <1> 	; 16/04/2017
 16378                              <1> 	; 14/04/2017
 16379                              <1> 	; 13/04/2017
 16380                              <1> 	; 28/02/2017
 16381                              <1> 	; 26/02/2017
 16382                              <1> 	; 24/02/2017
 16383                              <1> 	; 21/02/2017 - TRDOS 386 (TRDOS v2.0)
 16384                              <1> 	; (TRDOS 386 feature only!)
 16385                              <1> 	;
 16386                              <1> 	; Link or unlink IRQ callback service to/from user (ring 3)
 16387                              <1> 	;
 16388                              <1> 	; INPUT ->
 16389                              <1> 	;	BL = IRQ number (Hardware interrupt request number)
 16390                              <1> 	;	     (0 t0 15 but IRQ 0,1,2,6,8,14,15 are prohibited)
 16391                              <1> 	;	     IRQ numbers 3,4,5,7,9,10,11,12,13 are valid
 16392                              <1> 	;	     (numbers >15 are invalid)
 16393                              <1> 	;
 16394                              <1> 	;	BH = 0 = Unlink IRQ (in BL) from user (ring 3) service
 16395                              <1> 	;	     1 = Link IRQ by using Signal Response Byte method
 16396                              <1> 	;	     2 = Link IRQ by using Callback service method
 16397                              <1> 	;	     3 = Link IRQ by using Auto Increment S.R.B. method
 16398                              <1> 	;	    >3 = invalid 
 16399                              <1> 	;
 16400                              <1> 	;	CL = Signal Return/Response Byte value
 16401                              <1> 	;
 16402                              <1> 	;	If BH = 3, kernel will put a counter value  ; 03/08/2020
 16403                              <1> 	;	          (into the S.R.B. addr)
 16404                              <1> 	;		  between 0 to 255. (start value = CL+1)
 16405                              <1> 	;
 16406                              <1> 	;	NOTE: counter value, for example: even and odd numbers
 16407                              <1> 	;	      may be used for -audio- DMA buffer switch
 16408                              <1> 	;	      within double buffer method, etc.
 16409                              <1> 	;
 16410                              <1> 	;	EDX = Signal return (Response) byte address
 16411                              <1> 	;	       		  - or -
 16412                              <1> 	;	      Interrupt/Callback service/routine address
 16413                              <1> 	;
 16414                              <1> 	;	      (virtual address in user's memory space)
 16415                              <1> 	;
 16416                              <1> 	; OUTPUT ->
 16417                              <1> 	;	CF = 0 & EAX = 0 -> Successful setting
 16418                              <1> 	;	CF = 1 & EAX > 0 -> IRQ is prohibited or locked
 16419                              <1> 	;			by another process
 16420                              <1> 	;		 eax = ERR_PERM_DENIED -> prohibited or locked
 16421                              <1> 	;		 eax = ERR_INV_PARAMETER -> 
 16422                              <1> 	;		       invalid parameter/option or bad address
 16423                              <1> 	;
 16424                              <1> 	;	NOTE: Timer callbacks are set by using 'systimer'
 16425                              <1> 	;	      system call (IRQ 0, PIT and IRQ 8, RTC)
 16426                              <1> 	;
 16427                              <1> 	;	      Direct keyboard access is performed by using
 16428                              <1> 	;	      Keyboard Interrupt (INT 32h)
 16429                              <1> 	;
 16430                              <1> 	;	      It is prohibited here because:
 16431                              <1> 	;		1) Signal Response Byte method has not advantage
 16432                              <1> 	;		   against INT 32h, function AH = 1. Also,
 16433                              <1> 	;		   keyboard service interrupt will return with
 16434                              <1> 	;		   ascii and scan codes (AL, AH) while
 16435                              <1> 	;		   SRB method has only 1 byte space for ascii code
 16436                              <1> 	;		   or scan code. One byte signal response is used
 16437                              <1> 	;		   for ensuring very simple and very fast
 16438                              <1> 	;		   virtual to physical memory address conversion
 16439                              <1> 	;		   without any memory page crossover risk.
 16440                              <1> 	;		   (Otherwise double page conversion or word
 16441                              <1> 	;		   alignment would be needed.)
 16442                              <1> 	;		2) Badly written user code (callback code)
 16443                              <1> 	;		   can prevent keyboard and timesharing functions
 16444                              <1> 	;		   of the operating system via continuous and long
 16445                              <1> 	;		   keyboard event handling by callback service.
 16446                              <1> 	;		   (It can cause to lose immediate keystroke
 16447                              <1> 	;		   response from hardware to user.)
 16448                              <1> 	;		3) If user will check any keyboard events, 'getkey'
 16449                              <1> 	;		   (or 'getchar') must have more priority than other
 16450                              <1> 	;		   (video etc.) events because only control ability
 16451                              <1> 	;		   on a procedural infinite loop is a keyboard or
 16452                              <1> 	;		   mouse event. So user can use keyboard function
 16453                              <1> 	;		   at the end or at the beginning of a loop.
 16454                              <1> 	;		   In this case, INT 32h is used for that purpose
 16455                              <1> 	;		   and timer interrupt etc. callbacks can be used
 16456                              <1> 	;		   for dynamic and synchronized data refresh/transfer
 16457                              <1> 	;		   while cpu is in a static loop (without polling).
 16458                              <1> 	;		   Keyboard Int callback is not more useful because
 16459                              <1> 	;		   already a manual check (a key is pressed or not)
 16460                              <1> 	;		   can be performed (via INT 32h, AH = 1) efficiently
 16461                              <1> 	;		   in a loop to prevent a locked infinitive loop.
 16462                              <1> 	;
 16463                              <1> 	;	    Disk IRQs (6,14,15) have been phohibited from ring 3 
 16464                              <1> 	;	    callback because, disk operations (file system services
 16465                              <1> 	;	    etc.) are independent from user program, for fast disk r/w.
 16466                              <1> 	;	    They are not more useful at ring 3 while they are in use
 16467                              <1> 	;	    by standard diskio functions which are mandatory part of
 16468                              <1> 	;	    (monolithic) OS kernel and mainprog command interpreter.
 16469                              <1> 	;	    INT 33h diskio functions are enough for user level disk
 16470                              <1> 	;	    r/w.
 16471                              <1> 	;
 16472                              <1> 	; TRDOS 386 - IRQ CALLBACK structures (parameters):
 16473                              <1> 	;	
 16474                              <1> 	;	   [u.irqlock] = 1 word, IRQ flags (0-15) that indicates
 16475                              <1> 	;			which IRQs are locked by (that) user.
 16476                              <1> 	;		        Lock and unlock (by user) will change
 16477                              <1> 	;			these flags or 'terminate process' (sysexit)
 16478                              <1> 	;			will clear these flags and unlock those IRQs.
 16479                              <1> 	;			               
 16480                              <1> 	;		   	Bit 0 is for IRQ 0 and Bit 15 is for IRQ 15
 16481                              <1> 	;
 16482                              <1> 	;	   IRQ(x).owner	 : 1 byte, user, [u.uno], 0 = free (unlocked)
 16483                              <1> 	;
 16484                              <1> 	;	   IRQ(x).method : 1 byte for callback method & status
 16485                              <1> 	;			   0 = Signal Response Byte method
 16486                              <1> 	;			   1 = Callback service method
 16487                              <1> 	;			   >1 = invalid for current 'syscalback'.
 16488                              <1> 	;			or(+) 80h = IRQ is in use by system (ring 0)
 16489                              <1> 	;			            function (audio etc.) or
 16490                              <1> 	;			   	    a device driver.
 16491                              <1> 	;			(system function will ignore the lock/owner)
 16492                              <1> 	;
 16493                              <1> 	;	   IRQ(x).srb	: 1 byte, Signal Return/Response byte value
 16494                              <1> 	;			  (a fixed value by user or a counter value
 16495                              <1> 	;			 from 0 to 255, which is increased by every
 16496                              <1> 	;			 interrupt just before putting it into
 16497                              <1> 	;			 the Signal Response byte address
 16498                              <1> 	;			 (This is not used in callback serv method)
 16499                              <1> 	;
 16500                              <1> 	;	   IRQ(x).addr	: 1 dword
 16501                              <1> 	;			  Signal Response Byte address (physical)
 16502                              <1> 	;			  		-or-
 16503                              <1> 	;			  Callback service address (virtual)
 16504                              <1> 	;
 16505                              <1> 	;	   IRQ(x).dev	: 1 byte
 16506                              <1> 	;			  0 = Default device or kernel function
 16507                              <1> 	;			  		-or-
 16508                              <1> 	;			  1-255 = Assigned device driver number
 16509                              <1> 	;
 16510                              <1> 	;	   (x) = 3,4,5,7,9,10,11,12,13
 16511                              <1> 	;
 16512                              <1> 	;
 16513                              <1> 	;	NOTE: If user's process/program calls the kernel (INT 40h)
 16514                              <1> 	;	      while it is already running in a (ring 3) callback
 16515                              <1> 	;	      service, kernel will force (convert) system call to
 16516                              <1> 	;	      'sysrele' (sys release). So, this feature provides
 16517                              <1> 	;	      easy and simple usage of callback services without
 16518                              <1> 	;	      falling into deepless <please 'callback me' then 
 16519                              <1> 	;	      let me 'callback you'> cycles! (User must return
 16520                              <1> 	;	      from callback service by using 'sysrele' system
 16521                              <1> 	;	      call, without a significant delay. Otherwise user
 16522                              <1> 	;	      process/program may be late to catch the next event
 16523                              <1> 	;	      within same callback purpose.
 16524                              <1> 	;
 16525                              <1> 
 16526 0001189B 30C0                <1> 	xor	al, al ; the caller is 'syscalbac' sign/flag
 16527 0001189D E8ED150000          <1>  	call	set_irq_callback_service
 16528                              <1> 	; 16/04/2017
 16529 000118A2 A3[74940100]        <1> 	mov	[u.r0], eax
 16530                              <1> 	;jnc	sysret
 16531                              <1> 	; 23/07/2022
 16532 000118A7 7205                <1> 	jc	short syscalbac_err
 16533 000118A9 E9A6B5FFFF          <1> 	jmp	sysret
 16534                              <1> syscalbac_err:
 16535 000118AE A3[E0940100]        <1> 	mov	dword [u.error], eax
 16536 000118B3 E97CB5FFFF          <1> 	jmp	error
 16537                              <1> 
 16538                              <1> sysfpstat:
 16539                              <1> 	; 28/02/2017 - TRDOS 386 (TRDOS v2.0)
 16540                              <1> 	; (TRDOS 386 feature only!)
 16541                              <1> 	;
 16542                              <1> 	; Set or reset FPU registers save/restore option (for user)
 16543                              <1> 	;	       (during software task switching, wswap-rswap)
 16544                              <1> 	;
 16545                              <1> 	; INPUT ->
 16546                              <1> 	;	BL = 0 -> reset
 16547                              <1> 	;	BL = 1 -> set (FPU register will be saved and restored)
 16548                              <1> 	;	
 16549                              <1> 	; OUTPUT ->
 16550                              <1> 	;	cf = 0 -> no error, FPU is ready...
 16551                              <1> 	;		  (EAX = 0)
 16552                              <1> 	;	Cf = 1 -> error, 80387 FPU is not ready !
 16553                              <1> 	;		  (EAX = 0FFFFFFFFh)
 16554                              <1> 
 16555 000118B8 31C0                <1> 	xor	eax, eax
 16556 000118BA 803D[7C890100]00    <1> 	cmp	byte [fpready], 0
 16557 000118C1 7613                <1> 	jna	short sysfpstat_err
 16558                              <1> 
 16559 000118C3 80E301              <1> 	and	bl, 1 ; use BIT 0 only !
 16560 000118C6 881D[F3940100]      <1> 	mov	[u.fpsave], bl
 16561 000118CC A3[74940100]        <1> 	mov	[u.r0], eax ; 0
 16562 000118D1 E97EB5FFFF          <1> 	jmp	sysret
 16563                              <1> 
 16564                              <1> sysfpstat_err:
 16565 000118D6 48                  <1> 	dec 	eax ; 0FFFFFFFFh
 16566 000118D7 A3[74940100]        <1> 	mov 	[u.r0], eax ; -1
 16567 000118DC E953B5FFFF          <1> 	jmp 	error
 16568                              <1> 
 16569                              <1> sysdelete: ; Delete (Remove, Unlink) File
 16570                              <1> 	; 29/12/2017 (TRDOS 386 = TRDOS v2.0) 
 16571                              <1> 	;	
 16572                              <1>         ; INPUT ->
 16573                              <1>         ;          EBX = File name (ASCIIZ string) address
 16574                              <1> 	; OUTPUT ->
 16575                              <1> 	;          cf = 0 -> eax = 0
 16576                              <1> 	;          cf = 1 -> Error code in AL
 16577                              <1> 	;
 16578                              <1> 	; Modified Registers: EAX (at the return of system call)
 16579                              <1> 	;
 16580                              <1> 
 16581 000118E1 89DE                <1> 	mov	esi, ebx
 16582                              <1> 	; file name is forced, change directory as temporary
 16583                              <1> 	;mov	ax, 1
 16584                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset
 16585                              <1> 	;call	set_working_path 
 16586 000118E3 E8FA090000          <1> 	call	set_working_path_x
 16587 000118E8 731D                <1> 	jnc	short sysdelete_1
 16588                              <1> 
 16589 000118EA 21C0                <1> 	and	eax, eax  ; 0 -> Bad Path!
 16590 000118EC 7505                <1> 	jnz	short sysdelete_err
 16591                              <1> 	; eax = 0
 16592                              <1> sysdelete_path_err:
 16593 000118EE B813000000          <1> 	mov	eax, ERR_INV_PATH_NAME ; 'bad path name !'
 16594                              <1> sysdelete_err:
 16595 000118F3 A3[74940100]        <1> 	mov	[u.r0], eax
 16596 000118F8 A3[E0940100]        <1> 	mov	[u.error], eax
 16597 000118FD E8B50A0000          <1> 	call 	reset_working_path
 16598 00011902 E92DB5FFFF          <1> 	jmp	error
 16599                              <1> sysdelete_1:
 16600                              <1> 	;mov	esi, FindFile_Name
 16601 00011907 66B80018            <1> 	mov	ax, 1800h ; Only files
 16602 0001190B E85A72FFFF          <1> 	call	find_first_file
 16603 00011910 72E1                <1> 	jc	short sysdelete_err
 16604                              <1> sysdelete_2:
 16605                              <1> 	; check file attributes
 16606                              <1> 
 16607                              <1> 	;test	bl, 17 ; system, hidden, readonly, directory
 16608 00011912 F6C307              <1>         test	bl, 7 ; system, hidden, readonly 
 16609 00011915 7407                <1>         jz	short sysdelete_3
 16610                              <1> 
 16611 00011917 B80B000000          <1>         mov	eax, ERR_FILE_ACCESS ; 11 = 'permission denied !'
 16612 0001191C EBD5                <1>         jmp	short sysdelete_err
 16613                              <1> sysdelete_3:
 16614 0001191E 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
 16615 00011921 7407                <1> 	jz	short sysdelete_4
 16616 00011923 B81A000000          <1> 	mov	eax, ERR_INV_FILE_NAME ; 26 = 'invalid file name !'
 16617 00011928 EBC9                <1>         jmp	short sysdelete_err
 16618                              <1> sysdelete_4:
 16619                              <1> 	;mov	bh, [LongName_EntryLength]
 16620 0001192A 883D[EA860100]      <1> 	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
 16621                              <1> 	; edi = Directory Entry Offset (DirBuff)
 16622                              <1> 	; esi = Directory Entry (FFF Structure)
 16623 00011930 E84D9AFFFF          <1> 	call	remove_file
 16624 00011935 72BC                <1> 	jc	short sysdelete_err
 16625                              <1> sysrmdir_5:
 16626 00011937 31C0                <1> 	xor	eax, eax ; 0
 16627 00011939 A3[74940100]        <1> 	mov	[u.r0], eax
 16628                              <1> 	;mov	[u.error], eax
 16629 0001193E E8740A0000          <1> 	call 	reset_working_path
 16630 00011943 E90CB5FFFF          <1> 	jmp	sysret
 16631                              <1> 
 16632                              <1> sysrmdir: ; Remove (Unlink) Directory
 16633                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
 16634                              <1> 	; 19/01/2021
 16635                              <1> 	; 29/12/2017 (TRDOS 386 = TRDOS v2.0)
 16636                              <1> 	;
 16637                              <1>         ; INPUT ->
 16638                              <1>         ;          EBX = Pointer to directory name
 16639                              <1> 	; OUTPUT ->
 16640                              <1> 	;          cf = 0 -> eax = 0
 16641                              <1> 	;          cf = 1 -> Error code in AL
 16642                              <1> 	;
 16643                              <1> 	; Modified Registers: EAX (at the return of system call)
 16644                              <1> 	;
 16645                              <1> 
 16646                              <1> 	; 19/01/2021
 16647 00011948 803D[C6940100]00    <1> 	cmp	byte [u.uid], 0  ; root (super user) ?
 16648 0001194F 7614                <1> 	jna	short sysrmdir_0
 16649                              <1> 
 16650                              <1> 	;mov	dword [u.r0], ERR_PERM_DENIED
 16651 00011951 B80B000000          <1> 	mov	eax, ERR_PERM_DENIED ; ERR_NOT_SUPERUSER
 16652 00011956 A3[74940100]        <1> 	mov	[u.r0], eax
 16653 0001195B A3[E0940100]        <1> 	mov	[u.error], eax
 16654 00011960 E9CFB4FFFF          <1> 	jmp	error
 16655                              <1> 
 16656                              <1> sysrmdir_0:
 16657 00011965 89DE                <1> 	mov	esi, ebx
 16658                              <1> 	; file name is forced, change directory as temporary
 16659                              <1> 	;mov	ax, 1
 16660                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset
 16661                              <1> 	;call	set_working_path 
 16662 00011967 E876090000          <1> 	call	set_working_path_x
 16663 0001196C 7308                <1> 	jnc	short sysrmdir_1
 16664                              <1> 
 16665 0001196E 21C0                <1> 	and	eax, eax  ; 0 -> Bad Path!
 16666 00011970 7513                <1> 	jnz	short sysrmdir_err
 16667                              <1> 	; eax = 0
 16668                              <1> sysrmdir_not_found:
 16669                              <1> 	;mov	eax, ERR_DIR_NOT_FOUND ; Directory not found !
 16670                              <1> 	; 23/07/2022
 16671 00011972 B00C                <1> 	mov	al, ERR_DIR_NOT_FOUND
 16672 00011974 EB0F                <1> 	jmp	short sysrmdir_err
 16673                              <1> ;sysrmdir_err:
 16674                              <1> ;	mov	[u.r0], eax
 16675                              <1> ;	mov	[u.error], eax
 16676                              <1> ;	call 	reset_working_path
 16677                              <1> ;	jmp	error
 16678                              <1> sysrmdir_1:
 16679                              <1> 	;mov	esi, FindFile_Name
 16680 00011976 66B81008            <1> 	mov	ax, 0810h ; Only directories
 16681 0001197A E8EB71FFFF          <1> 	call	find_first_file
 16682 0001197F 7318                <1> 	jnc	short sysrmdir_2
 16683                              <1> 
 16684                              <1> 	; eax = 2 (File not found !)
 16685 00011981 3C02                <1> 	cmp	al, 2 ; ERR_NOT_FOUND
 16686 00011983 74ED                <1> 	je	short sysrmdir_not_found
 16687                              <1> 	;jmp	short sysrmdir_err
 16688                              <1> 	; 23/07/2022
 16689                              <1> sysrmdir_err:
 16690 00011985 A3[74940100]        <1> 	mov	[u.r0], eax
 16691 0001198A A3[E0940100]        <1> 	mov	[u.error], eax
 16692                              <1> sysrmdir_8:	; 23/07/2022
 16693 0001198F E8230A0000          <1> 	call 	reset_working_path
 16694 00011994 E99BB4FFFF          <1> 	jmp	error
 16695                              <1> sysrmdir_2:
 16696                              <1> 	; check directory attributes
 16697                              <1> 
 16698 00011999 F6C307              <1>         test	bl, 7 ; system, hidden, readonly
 16699 0001199C 7407                <1>         jz	short sysrmdir_3
 16700                              <1> 
 16701 0001199E B80B000000          <1>         mov	eax, ERR_DIR_ACCESS ; 11 = 'permission denied !'
 16702 000119A3 EBE0                <1>         jmp	short sysrmdir_err
 16703                              <1> sysrmdir_3:
 16704 000119A5 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
 16705 000119A8 7407                <1> 	jz	short sysrmdir_4
 16706                              <1> 	;mov	eax, ERR_NOT_DIR ; 'not a valid directory !'
 16707 000119AA B813000000          <1> 	mov	eax, ERR_INV_PATH_NAME ; 'bad path name !'
 16708 000119AF EBD4                <1>         jmp	short sysrmdir_err
 16709                              <1> sysrmdir_4:
 16710                              <1> 	;mov	bh, [LongName_EntryLength]
 16711 000119B1 883D[EA860100]      <1> 	mov	[DelFile_LNEL], bh ; Long name entry length (if > 0)
 16712                              <1> 	; edi = Directory Entry Offset (DirBuff)
 16713                              <1> 	; esi = Directory Entry (FFF Structure)
 16714 000119B7 E84E78FFFF          <1> 	call	delete_sub_directory
 16715                              <1> 	;jnc	sysrmdir_5
 16716                              <1> 	; 23/07/2022
 16717 000119BC 7205                <1> 	jc	short sysrmdir_6
 16718 000119BE E974FFFFFF          <1> 	jmp	sysrmdir_5
 16719                              <1> 
 16720                              <1> ;	jc	short sysrmdir_6
 16721                              <1> ;
 16722                              <1> ;	xor	eax, eax ; 0
 16723                              <1> ;sysrmdir_5:
 16724                              <1> ;	mov	[u.r0], eax
 16725                              <1> ;	;mov	[u.error], eax
 16726                              <1> ;	call 	reset_working_path
 16727                              <1> ;	jmp	sysret
 16728                              <1> 
 16729                              <1> sysrmdir_6:
 16730 000119C3 A3[74940100]        <1> 	mov	[u.r0], eax
 16731 000119C8 A3[E0940100]        <1> 	mov	[u.error], eax
 16732                              <1> 
 16733 000119CD 09C0                <1> 	or	eax, eax ; EAX = 0 -> Directory not empty!
 16734 000119CF 7414                <1> 	jz	short sysrmdir_9
 16735                              <1> 
 16736                              <1> 	; EAX > 0 -> Error code in AL (or AX or EAX)
 16737                              <1> 
 16738 000119D1 833D[9E840100]01    <1> 	cmp	dword [FAT_ClusterCounter], 1
 16739 000119D8 72B5                <1> 	jb	short sysrmdir_8
 16740                              <1> sysrmdir_7:
 16741                              <1> 	; ESI = Logical DOS Drive Description Table address
 16742 000119DA 66BB00FF            <1> 	mov	bx, 0FF00h ; BH = FFh -> use ESI for Drive parameters
 16743                              <1> 	           ; BL = 0 -> Recalculate free cluster count
 16744 000119DE E831AFFFFF          <1> 	call	calculate_fat_freespace	
 16745                              <1> 	; 23/07/2022
 16746 000119E3 EBAA                <1> 	jmp	short sysrmdir_8
 16747                              <1> ;sysrmdir_8:
 16748                              <1> ;	call 	reset_working_path
 16749                              <1> ;	jmp	error
 16750                              <1> 
 16751                              <1> sysrmdir_9:
 16752 000119E5 A1[9E840100]        <1> 	mov	eax, [FAT_ClusterCounter]
 16753 000119EA 09C0                <1> 	or	eax, eax ; 0 ?
 16754                              <1> 	;jz	short sysrmdir_err
 16755                              <1> 	; 23/07/2022
 16756 000119EC 74A1                <1> 	jz	short sysrmdir_8
 16757                              <1> 
 16758                              <1> 	; ESI = Logical DOS Drive Description Table address
 16759 000119EE 66BB01FF            <1> 	mov	bx, 0FF01h ; BH = FFh -> use ESI for Drive parameters
 16760                              <1> 	           ; BL = 1 -> add free clusters
 16761 000119F2 E81DAFFFFF          <1> 	call	calculate_fat_freespace
 16762 000119F7 09C9                <1> 	or	ecx, ecx
 16763 000119F9 7494                <1>         jz	short sysrmdir_8 ; ecx = 0 -> OK
 16764                              <1> 	; ecx > 0 -> Error (Recalculation is needed)
 16765 000119FB EBDD                <1> 	jmp	short sysrmdir_7
 16766                              <1> 
 16767                              <1> syschdir: ; Change Current (Working) Drive & Directory (for user)
 16768                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0) 
 16769                              <1> 	;
 16770                              <1>         ; INPUT ->
 16771                              <1>         ;          EBX = Directory name (ASCIIZ string) address
 16772                              <1> 	; OUTPUT ->
 16773                              <1> 	;          cf = 0 -> eax = 0
 16774                              <1> 	;          cf = 1 -> Error code in AL
 16775                              <1> 	;
 16776                              <1> 	; Modified Registers: EAX (at the return of system call)
 16777                              <1> 	;
 16778                              <1> 	; NOTE: If drive name is not included, only the working
 16779                              <1> 	; directory (for user, not for drive/OS) will be chanded.
 16780                              <1> 	; If there is a drive name (as A:, B:, C:, D: etc.)
 16781                              <1> 	; at the beginning of the ASCIIZ (directory) string,
 16782                              <1> 	; working drive and working directory (for user) 
 16783                              <1> 	; will be changed together.
 16784                              <1> 	; (When the program is terminated, MainProg -internal
 16785                              <1> 	; shell- will reset working directory to the previous
 16786                              <1> 	; -current- logical drive's current directory again.)
 16787                              <1> 
 16788 000119FD 89DE                <1> 	mov	esi, ebx
 16789                              <1> 	; file name is not forced, change directory as temporary
 16790 000119FF 31C0                <1> 	xor	eax, eax
 16791                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset
 16792                              <1> 	;call	set_working_path 
 16793 00011A01 E8E0080000          <1> 	call	set_working_path_xx
 16794 00011A06 731D                <1> 	jnc	short syschdir_ok
 16795 00011A08 21C0                <1> 	and	eax, eax  ; 0 -> Bad Path!
 16796 00011A0A 7505                <1> 	jnz	short syschdir_err
 16797                              <1> 	; eax = 0
 16798                              <1> syschdir_not_found:
 16799 00011A0C B80C000000          <1> 	mov	eax, ERR_DIR_NOT_FOUND ; Directory not found !
 16800                              <1> syschdir_err:
 16801 00011A11 A3[74940100]        <1> 	mov	[u.r0], eax
 16802 00011A16 A3[E0940100]        <1> 	mov	[u.error], eax
 16803 00011A1B E897090000          <1> 	call 	reset_working_path
 16804 00011A20 E90FB4FFFF          <1> 	jmp	error
 16805                              <1> syschdir_ok:
 16806 00011A25 31C0                <1> 	xor	eax, eax ; 0
 16807 00011A27 A3[74940100]        <1> 	mov	[u.r0], eax
 16808                              <1> 	;mov	[u.error], eax
 16809 00011A2C E923B4FFFF          <1> 	jmp	sysret
 16810                              <1> 
 16811                              <1> 
 16812                              <1> syschmod: ; Get & Change File (or Directory) Attributes
 16813                              <1> 	; 26/09/2024 - TRDOS 386 v2.0.9
 16814                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
 16815                              <1> 	; 19/01/2021
 16816                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0) 
 16817                              <1> 	;
 16818                              <1>         ; INPUT ->
 16819                              <1>         ;          EBX = File/Directory (ASCIIZ) name address
 16820                              <1> 	;	    CL = New attributes (if CL < 40h)
 16821                              <1> 	;	    CL >= 40h -> Get File Attributes
 16822                              <1> 	; OUTPUT ->
 16823                              <1> 	;          cf = 0 -> EAX = File attributes (in AL)
 16824                              <1> 	;          cf = 1 -> Error code in AL
 16825                              <1> 	;
 16826                              <1> 	; Modified Registers: EAX (at the return of system call)
 16827                              <1> 	;
 16828                              <1> 	; MSDOS File Attributes:    (bit value of attrib byte)
 16829                              <1> 	;	ATTR_READ_ONLY	=	01h  (bit 0, 'R')
 16830                              <1> 	;	ATTR_HIDDEN	=	02h  (bit 1, 'H')
 16831                              <1> 	;	ATTR_SYSTEM	=	04h  (bit 2, 'S')
 16832                              <1> 	;	ATTR_VOLUME_ID	=	08h  (bit 3)
 16833                              <1> 	;	ATTR_DIRECTORY	=	10h  (bit 4)
 16834                              <1> 	;	ATTR_ARCHIVE	=	20h  (bit 5, 'A')
 16835                              <1> 	;	ATTR_LONG_NAME	=	ATTR_READONLY |
 16836                              <1> 	;				ATTR_HIDDEN |
 16837                              <1> 	;				ATTR_SYSTEM |
 16838                              <1> 	;				ATTR_VOLUME_ID
 16839                              <1> 	;	The upper two bits of attributes must be 0.
 16840                              <1> 
 16841                              <1> 	; Note:	* If ATTR_DIRECTORY is set, only directory names
 16842                              <1> 	;	  will be searched (and S,H,R,A attributeds of
 16843                              <1> 	;	  the directory will be changed.)
 16844                              <1> 	;	* If ATTR_VOLUME_ID is set, 'syschmod' system call
 16845                              <1> 	;	  will return with 'permission denied' error.
 16846                              <1> 	;	* If ATTR_DIRECTORY is not set, only file names
 16847                              <1> 	;	  will be searched (and S,H,R,A attributes of the
 16848                              <1> 	;	  file will be changed.)
 16849                              <1> 	;
 16850                              <1> 	; (Ony Super User can change S,H,R attributes.)
 16851                              <1> 
 16852 00011A31 80F940              <1> 	cmp	cl, 40h
 16853 00011A34 7327                <1> 	jnb	short syschmod_0
 16854                              <1> 
 16855 00011A36 F6C108              <1> 	test	cl, 08h ; ATTR_VOLUME_ID
 16856 00011A39 750E                <1> 	jnz	short syschmod_perm_err
 16857                              <1> 
 16858                              <1> 	; 19/01/2021
 16859 00011A3B 803D[C6940100]00    <1> 	cmp	byte [u.uid], 0  ; root (super user) ?
 16860 00011A42 7619                <1> 	jna	short syschmod_0
 16861                              <1> 
 16862                              <1> 	; Not super user..
 16863 00011A44 F6C107              <1> 	test	cl, 07h	; S,H,R attributes
 16864 00011A47 7414                <1> 	jz	short syschmod_0
 16865                              <1> 
 16866                              <1> syschmod_perm_err:
 16867                              <1> 	;mov	dword [u.r0], ERR_PERM_DENIED
 16868 00011A49 B80B000000          <1> 	mov	eax, ERR_PERM_DENIED ; 'permission denied !'
 16869 00011A4E A3[74940100]        <1> 	mov	[u.r0], eax
 16870 00011A53 A3[E0940100]        <1> 	mov	[u.error], eax
 16871 00011A58 E9D7B3FFFF          <1> 	jmp	error
 16872                              <1> 
 16873                              <1> syschmod_0:
 16874 00011A5D 880D[38870100]      <1> 	mov	[Attributes], cl
 16875 00011A63 89DE                <1> 	mov	esi, ebx
 16876                              <1> 	; file name is forced, change directory as temporary
 16877                              <1> 	;mov	ax, 1
 16878                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset
 16879                              <1> 	;call	set_working_path 
 16880 00011A65 E878080000          <1> 	call	set_working_path_x
 16881 00011A6A 7308                <1> 	jnc	short syschmod_1
 16882 00011A6C 21C0                <1> 	and	eax, eax  ; 0 -> Bad Path!
 16883 00011A6E 751E                <1> 	jnz	short syschmod_err
 16884                              <1> 	; eax = 0
 16885                              <1> syschmod_path_not_found:
 16886                              <1> 	;mov	eax, ERR_INV_PATH_NAME ; 'Bad path name !'
 16887                              <1> 	; 23/07/2022
 16888 00011A70 B013                <1> 	mov	al, ERR_INV_PATH_NAME
 16889                              <1> ;syschmod_err:
 16890                              <1> 	;mov	[u.r0], eax
 16891                              <1> 	;mov	[u.error], eax
 16892                              <1> 	;call 	reset_working_path
 16893                              <1> 	;jmp	error
 16894                              <1> 	; 23/07/2022
 16895 00011A72 EB1A                <1> 	jmp	short syschmod_err
 16896                              <1> syschmod_1:
 16897 00011A74 B008                <1> 	mov	al, 08h ; Except volume labels (& long names)
 16898 00011A76 A0[38870100]        <1> 	mov	al, [Attributes]
 16899 00011A7B 2410                <1> 	and	al, 10h ;
 16900                              <1> 	;mov	esi, FindFile_Name
 16901                              <1> 	;mov	ax, 1800h ; Only files
 16902                              <1> 	;mov	ax, 0810h ; Only directories
 16903 00011A7D E8E870FFFF          <1> 	call	find_first_file
 16904                              <1> 	;jnc	short syschmod_2
 16905 00011A82 720A                <1> 	jc	short syschmod_err
 16906                              <1> 
 16907                              <1> 	;; eax = 2 (File not found !)
 16908                              <1> 	;cmp	al, 2 ; ERR_NOT_FOUND
 16909                              <1> 	;jne	short syschmod_err
 16910                              <1> 
 16911                              <1> 	;and	byte [Attributes], 10h
 16912                              <1> 	;jz	short syschmod_err
 16913                              <1> 
 16914                              <1> 	;; Directory not found !
 16915                              <1> 	;mov	al, 3 ; ERR_PATH_NOT_FOUND
 16916                              <1> 	;jmp	short syschmod_err
 16917                              <1> 
 16918                              <1> syschmod_2:
 16919 00011A84 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
 16920 00011A87 7419                <1> 	jz	short syschmod_3
 16921 00011A89 B81A000000          <1> 	mov	eax, ERR_INV_FILE_NAME ; 'invalid file name !'
 16922                              <1>         ;jmp	short syschmod_err
 16923                              <1> syschmod_err:
 16924 00011A8E A3[74940100]        <1> 	mov	[u.r0], eax
 16925 00011A93 A3[E0940100]        <1> 	mov	[u.error], eax
 16926 00011A98 E81A090000          <1> 	call 	reset_working_path
 16927 00011A9D E992B3FFFF          <1> 	jmp	error
 16928                              <1> syschmod_3:
 16929                              <1> 	; EDI = Directory buffer entry offset/address
 16930                              <1> 	; BL = File (or Directory) Attributes
 16931                              <1> 	; mov	bl, [EDI+0Bh]
 16932                              <1> 
 16933                              <1> 	; check directory attributes
 16934 00011AA2 8A3D[38870100]      <1> 	mov	bh, [Attributes] ; new attributes
 16935 00011AA8 80FF40              <1> 	cmp	bh, 40h  ;>=40 -> get file/directory attributes
 16936 00011AAB 732D                <1> 	jnb	short syschmod_6
 16937                              <1> 
 16938                              <1> 	; set file/directory attributes
 16939 00011AAD F6C307              <1> 	test	bl, 7 ; system, hidden, readonly
 16940 00011AB0 7409                <1>         jz	short syschmod_4
 16941                              <1> 
 16942                              <1> 	; 19/01/2021
 16943 00011AB2 803D[C6940100]00    <1> 	cmp	byte [u.uid], 0  ; root (super user) ?
 16944 00011AB9 778E                <1> 	ja	short syschmod_perm_err
 16945                              <1> syschmod_4:
 16946 00011ABB 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h ; Singlix FS
 16947 00011AC1 7424                <1> 	je	short syschmod_7
 16948                              <1> 
 16949 00011AC3 887F0B              <1> 	mov	[edi+0Bh], bh    ; Attributes (New!)
 16950                              <1> 
 16951 00011AC6 C605[A9840100]02    <1> 	mov	byte [DirBuff_ValidData], 2 ; modified sign
 16952                              <1> 					    ; to force write
 16953 00011ACD E87F95FFFF          <1> 	call 	save_directory_buffer
 16954 00011AD2 72BA                <1> 	jc	short syschmod_err
 16955                              <1> 
 16956                              <1> syschmod_5:
 16957 00011AD4 8A1D[38870100]      <1> 	mov	bl, [Attributes]
 16958                              <1> syschmod_6:
 16959 00011ADA 0FB6C3              <1> 	movzx	eax, bl
 16960 00011ADD A3[74940100]        <1> 	mov	[u.r0], eax
 16961                              <1> 	;mov	dword [u.error], 0
 16962 00011AE2 E96DB3FFFF          <1> 	jmp	sysret
 16963                              <1> 
 16964                              <1> syschmod_7:
 16965 00011AE7 29C0                <1> 	sub	eax, eax
 16966 00011AE9 8A25[A7840100]      <1>         mov     ah, [DirBuff_DRV]
 16967                              <1> 	; 26/09/2024 (BugFix)
 16968 00011AEF 80EC41              <1> 	sub	ah, 'A'
 16969 00011AF2 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 16970 00011AF7 01C6                <1>         add     esi, eax
 16971 00011AF9 807E04A1            <1>         cmp     byte [esi+LD_FSType], 0A1h
 16972 00011AFD 7304                <1> 	jnc	short syschmod_8
 16973 00011AFF B01D                <1> 	mov	al, ERR_INV_DATA ; 29 = Invalid Data
 16974 00011B01 EB8B                <1> 	jmp	short syschmod_err
 16975                              <1> 
 16976                              <1> syschmod_8:
 16977                              <1> 	; BH = New MS-DOS File Attributes
 16978 00011B03 88F8                <1> 	mov	al, bh ; File/Directory Attributes
 16979 00011B05 30E4                <1> 	xor	ah, ah ; Attributes in MS-DOS format sign
 16980 00011B07 E82D81FFFF          <1> 	call	change_fs_file_attributes
 16981                              <1> 	;jc	syschmod_err
 16982                              <1> 	;jmp	short syschmod_5
 16983                              <1> 	; 23/07/2022
 16984 00011B0C 73C6                <1> 	jnc	short syschmod_5
 16985 00011B0E E97BFFFFFF          <1> 	jmp	syschmod_err ; 26/09/2024 
 16986                              <1> 
 16987                              <1> 
 16988                              <1> sysdrive: ; Get/Set Current (Working) Drive (for user)
 16989                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0) 
 16990                              <1> 	;	
 16991                              <1>         ; INPUT ->
 16992                              <1>         ;          BL = Logical DOS Drive number (0=A: ... 2=C:)
 16993                              <1> 	;	   If BL = 0FFh -> Get Current Drive
 16994                              <1> 	; OUTPUT ->
 16995                              <1> 	;          cf = 0 -> 
 16996                              <1> 	;		   AL = Current Drive number
 16997                              <1> 	;		   AH = The Last Logical DOS Drive no.
 16998                              <1> 	;          cf = 1 -> Error code in AL
 16999                              <1> 	;
 17000                              <1> 	; Modified Registers: EAX (at the return of system call)
 17001                              <1> 	;
 17002                              <1> 	; NOTE: If the requested logical dos drive is ready, 
 17003                              <1> 	;	it's current current directory will be the user's
 17004                              <1> 	;	(program's) current directory.
 17005                              <1> 	;	(When the program is terminated, MainProg -internal
 17006                              <1> 	;	shell- will reset the previous -current- logical drive
 17007                              <1> 	;       as current drive again).
 17008                              <1> 
 17009 00011B13 80FBFF              <1> 	cmp	bl, 0FFh
 17010 00011B16 7435                <1> 	je	short sysdrive_ok
 17011 00011B18 3A1D[9A340100]      <1> 	cmp	bl, [Last_DOS_DiskNo]
 17012 00011B1E 771E                <1> 	ja	short sysdrive_err
 17013                              <1> 
 17014                              <1> 	; Save current drive and reset mode
 17015                              <1> 	; for 'reset_working_path' procedure (for MainProg)
 17016 00011B20 30C0                <1> 	xor	al, al
 17017 00011B22 66A3[78890100]      <1> 	mov	[SWP_Mode], ax ; ah = 0
 17018 00011B28 A0[827D0100]        <1> 	mov	al, [Current_Drv]
 17019 00011B2D FEC4                <1> 	inc	ah ; mov ah, 1
 17020 00011B2F 66A3[7A890100]      <1> 	mov	[SWP_DRV], ax 
 17021                              <1> 
 17022 00011B35 88DA                <1> 	mov	dl, bl
 17023 00011B37 E8415DFFFF          <1> 	call	change_current_drive
 17024 00011B3C 730F                <1> 	jnc	short sysdrive_ok
 17025                              <1> sysdrive_err:
 17026 00011B3E C705[74940100]0F00- <1> 	mov	dword [u.r0], ERR_DRV_NOT_RDY ; 'drive not ready !'
 17026 00011B46 0000                <1>
 17027 00011B48 E9E7B2FFFF          <1> 	jmp	error
 17028                              <1> sysdrive_ok:
 17029 00011B4D A0[827D0100]        <1> 	mov	al, [Current_Drv]
 17030 00011B52 8A25[9A340100]      <1> 	mov	ah, [Last_DOS_DiskNo]
 17031 00011B58 A3[74940100]        <1> 	mov	[u.r0], eax
 17032 00011B5D E9F2B2FFFF          <1> 	jmp	sysret
 17033                              <1> 
 17034                              <1> sysdir: ; Get Current (Working) Drive & Directory (for user)
 17035                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0)
 17036                              <1> 	;
 17037                              <1>         ; INPUT ->
 17038                              <1>         ;          EBX = Current directory name buffer address
 17039                              <1> 	;		(Buffer length = 92 bytes)
 17040                              <1> 	; OUTPUT ->
 17041                              <1> 	;          AL = Current drive (0=A: .. 2=C:)
 17042                              <1> 	;	   If CF = 1 -> AL = error code
 17043                              <1> 	;
 17044                              <1> 	; Modified Registers: EAX (at the return of system call)
 17045                              <1> 	;
 17046                              <1> 	; Note: Required directory name buffer length may be
 17047                              <1> 	;	<= 92 bytes for current TRDOS 386 version.
 17048                              <1> 	;	(7*12 name chars + 7 slash + 0)
 17049                              <1> 
 17050 00011B62 89E5                <1> 	mov	ebp, esp
 17051 00011B64 83EC60              <1> 	sub	esp, 96
 17052 00011B67 53                  <1> 	push	ebx ; User's buffer address
 17053 00011B68 30D2                <1> 	xor	dl, dl ; 0 = current drive
 17054 00011B6A E8678AFFFF          <1>   	call	get_current_directory
 17055 00011B6F 72CD                <1> 	jc	short sysdrive_err ; 'drive not ready !' error
 17056 00011B71 89E6                <1> 	mov	esi, esp ; System's buffer address
 17057 00011B73 5F                  <1> 	pop	edi  ; User's buffer address
 17058                              <1> 	; ecx = transfer (byte) count (<=92)
 17059 00011B74 E817F4FFFF          <1> 	call	transfer_to_user_buffer
 17060 00011B79 89EC                <1> 	mov	esp, ebp
 17061 00011B7B 730F                <1> 	jnc	short sysdir_ok
 17062                              <1> sysdir_err:
 17063 00011B7D C705[74940100]2E00- <1> 	mov	dword [u.r0], ERR_BUFFER  ; 'buffer error !'
 17063 00011B85 0000                <1>
 17064 00011B87 E9A8B2FFFF          <1> 	jmp	error
 17065                              <1> sysdir_ok:
 17066 00011B8C 8A0D[827D0100]      <1> 	mov	cl, [Current_Drv]
 17067 00011B92 890D[74940100]      <1> 	mov	[u.r0], ecx
 17068 00011B98 E9B7B2FFFF          <1> 	jmp	sysret
 17069                              <1> 
 17070                              <1> sysldrvt: ; Get copy of Logical DOS Drive Description Table
 17071                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0) 
 17072                              <1> 	;
 17073                              <1>         ; INPUT ->
 17074                              <1> 	;	    BL = Logical DOS drive number (zero based)
 17075                              <1>         ;          ECX = Logical DOS drv desc table buffer addr
 17076                              <1> 	;		(Buffer length = 256 bytes)
 17077                              <1> 	; OUTPUT ->
 17078                              <1> 	;          cf = 0 -> 
 17079                              <1> 	;		   AL = Current Drive number
 17080                              <1> 	;		   AH = The Last Logical DOS Drive no.
 17081                              <1> 	;          cf = 1 -> Error code in AL
 17082                              <1> 	;		   AH = The Last Logical DOS Drive no.
 17083                              <1> 	;
 17084                              <1> 	; Modified Registers: EAX (at the return of system call)
 17085                              <1> 	;
 17086                              <1> 	; Note: Required description table buffer length is
 17087                              <1> 	;	256 bytes for current TRDOS 386 version.
 17088                              <1> 
 17089 00011B9D 89CF                <1> 	mov	edi, ecx ; Destination address (user space)
 17090 00011B9F 88DC                <1> 	mov	ah, bl
 17091 00011BA1 30C0                <1> 	xor	al, al
 17092 00011BA3 BE00010900          <1> 	mov	esi, Logical_DOSDisks
 17093 00011BA8 01C6                <1> 	add	esi, eax ; Source address (system space)
 17094 00011BAA B900010000          <1> 	mov	ecx, 256 ; Byte count 
 17095                              <1> 			 ; Logical Dos Drv Desc Table size
 17096 00011BAF E8DCF3FFFF          <1> 	call	transfer_to_user_buffer
 17097 00011BB4 72C7                <1> 	jc	short sysdir_err
 17098 00011BB6 8A2D[9A340100]      <1> 	mov	ch, [Last_DOS_DiskNo]
 17099 00011BBC EBCE                <1> 	jmp	short sysdir_ok
 17100                              <1> 
 17101                              <1> systime: ; Get System Date&Time
 17102                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0)
 17103                              <1> 	;	
 17104                              <1>         ; INPUT -> BL =
 17105                              <1> 	;	    0 = Get Date&Time in Unix/Epoch format
 17106                              <1> 	;	    1 = Get Time in MSDOS format
 17107                              <1> 	;	    2 = Get Date in MSDOS format
 17108                              <1> 	;	    3 = Get Date&Time in MSDOS format
 17109                              <1> 	;	    4 & other values =
 17110                              <1> 	;		System timer ticks will be returned
 17111                              <1> 	;		in EAX and Carry Flag will be set.
 17112                              <1> 	;		(CF will not be set if BL = 4)
 17113                              <1> 	; OUTPUT ->
 17114                              <1> 	;	For BL input = 3
 17115                              <1> 	;          EAX = Current Time (RTC)
 17116                              <1> 	;		AL = Second (DL in MSDOS)
 17117                              <1> 	;		AH = Minute (CL in MSDOS)
 17118                              <1> 	;	   	HW of EAX = Hour (CH in MSDOS)
 17119                              <1> 	;	   EDX = Current System Date (RTC)
 17120                              <1> 	;		DL = Day (DL in MSDOS)
 17121                              <1> 	;		DH = Month (DH in MSDOS)
 17122                              <1> 	;		HW of EDX = Year (CX in MSDOS)
 17123                              <1> 	;
 17124                              <1> 	;	For BL input = 2
 17125                              <1> 	;	   EAX = Current System Date (RTC)
 17126                              <1> 	;		DL = Day (DL in MSDOS)
 17127                              <1> 	;		DH = Month (DH in MSDOS)
 17128                              <1> 	;		HW of EDX = Year (CX in MSDOS)
 17129                              <1> 	;
 17130                              <1> 	;	For BL input = 1
 17131                              <1> 	;          EAX = Current Time (RTC)
 17132                              <1> 	;		AL = Second (DL in MSDOS)
 17133                              <1> 	;		AH = Minute (CL in MSDOS)
 17134                              <1> 	;	   	HW of EAX = Hour (CH in MSDOS)
 17135                              <1> 	;
 17136                              <1> 	;	For BL input = 0
 17137                              <1> 	;          EAX = Unix (Epoch) Time Ticks/Seconds
 17138                              <1> 	;
 17139                              <1> 	;	For BL input  = 4
 17140                              <1> 	;	   EAX = System timer ticks
 17141                              <1> 	;
 17142                              <1> 	;	If CF = 1 (for other values of BL input)
 17143                              <1> 	;	   EAX = System timer ticks (no error code!)
 17144                              <1> 	;
 17145                              <1> 	; Modified Registers: EAX, (EDX)
 17146                              <1> 	;		 (at the return of system call)
 17147                              <1> 	;
 17148                              <1> 
 17149 00011BBE 20DB                <1> 	and	bl, bl
 17150 00011BC0 750F                <1> 	jnz	short systime_1
 17151 00011BC2 E8CA52FFFF          <1> 	call	epoch
 17152                              <1> systime_0:
 17153 00011BC7 A3[74940100]        <1> 	mov	[u.r0], eax
 17154 00011BCC E983B2FFFF          <1> 	jmp	sysret
 17155                              <1> systime_1:
 17156 00011BD1 80FB04              <1> 	cmp	bl, 4
 17157 00011BD4 7211                <1> 	jb	short systime_2
 17158 00011BD6 A1[407D0100]        <1> 	mov	eax, [TIMER_LH] ; 18.2 Hz timer ticks
 17159                              <1> 				; Note: [TIMER_LH] may be set
 17160                              <1> 				; to wrong timer value due to
 17161                              <1> 				; program functions.
 17162                              <1> 				; (This value must not be
 17163                              <1> 				; accepted as [TIMER_LH]/18.2
 17164                              <1> 				; seconds since the midnight.)
 17165 00011BDB 76EA                <1> 	jna	short systime_0
 17166 00011BDD A3[74940100]        <1> 	mov	[u.r0], eax	
 17167 00011BE2 E94DB2FFFF          <1> 	jmp	error ; cf = 1 & [u.r0] = eax = timer ticks
 17168                              <1> 
 17169                              <1> systime_2:
 17170                              <1> 	;push	ebx
 17171 00011BE7 E81F52FFFF          <1> 	call	get_rtc_date_time
 17172                              <1> 	;pop	ebx
 17173 00011BEC F6C301              <1> 	test	bl, 1
 17174 00011BEF 7429                <1> 	jz	short systime_4
 17175 00011BF1 30E4                <1> 	xor	ah, ah
 17176 00011BF3 A0[8E790100]        <1> 	mov	al, [hour]
 17177 00011BF8 88C2                <1> 	mov	dl, al
 17178 00011BFA C1E010              <1> 	shl	eax, 16
 17179 00011BFD A0[92790100]        <1> 	mov	al, [second]
 17180 00011C02 8A25[90790100]      <1> 	mov	ah, [minute]
 17181 00011C08 F6C302              <1> 	test	bl, 2
 17182 00011C0B 74BA                <1> 	jz	short systime_0
 17183                              <1> 	; Check time & date match risk
 17184                              <1> 	; (23:59:59 may cause to wrong
 17185                              <1> 	; date -new day with previous date-...)
 17186 00011C0D 80FA17              <1> 	cmp	dl, 23
 17187 00011C10 7206                <1> 	jb	short systime_3
 17188 00011C12 663D3B3B            <1> 	cmp	ax, (59*256)+59 ; if hour is 23:59:59
 17189 00011C16 73CF                <1> 	jnb	short systime_2 ; wait for 1 second
 17190                              <1> systime_3:
 17191                              <1> 	; eax = time
 17192 00011C18 89C6                <1> 	mov	esi, eax
 17193                              <1> systime_4:	
 17194 00011C1A 66A1[88790100]      <1> 	mov	ax, [year]
 17195 00011C20 C1E010              <1> 	shl	eax, 16
 17196 00011C23 A0[8C790100]        <1> 	mov	al, [day]
 17197 00011C28 8A25[8A790100]      <1> 	mov	ah, [month]
 17198                              <1> 	; eax = date
 17199 00011C2E 80E301              <1> 	and	bl, 1
 17200 00011C31 7494                <1> 	jz	short systime_0
 17201 00011C33 96                  <1> 	xchg	esi, eax
 17202                              <1> 	; eax = time, esi = date
 17203 00011C34 8B2D[70940100]      <1> 	mov	ebp, [u.usp]  ; EBP points to user's registers
 17204                              <1> 	; (user) edx <-- (system) esi
 17205 00011C3A 897514              <1> 	mov	[ebp+20], esi ; return to user with EDX value
 17206 00011C3D EB88                <1> 	jmp	short systime_0
 17207                              <1> 
 17208                              <1> sysstime: ; Set System Date&Time
 17209                              <1> 	; 31/12/2017
 17210                              <1> 	; 30/12/2017 (TRDOS 386 = TRDOS v2.0)
 17211                              <1> 	;
 17212                              <1>         ; INPUT -> BL =
 17213                              <1> 	;	    0 = Set Date&Time in Unix/Epoch format
 17214                              <1> 	;	    1 = Set Time in MSDOS format
 17215                              <1> 	;	    2 = Set Date in MSDOS format
 17216                              <1> 	;	    3 = Set Date&Time in MSDOS format
 17217                              <1> 	;	    4 = Set System Timer (Ticks)
 17218                              <1> 	;	    5 = Convert/Save current time to/as
 17219                              <1> 	;		18.2 Hz system timer ticks
 17220                              <1> 	;	    6 = Convert MSDOS Date&Time to UNIX format
 17221                              <1> 	;		without setting system date&time ; (test)
 17222                              <1> 	;	    7 = Convert UNIX Date&Time to MSDOS format
 17223                              <1> 	;		without setting system date&time ; (test)
 17224                              <1> 	;	   8-0FFh = invalid !
 17225                              <1> 	;	  ECX = Time (or Timer) value in selected format
 17226                              <1> 	;	  EDX = Date value in MSDOS format if BL=2,3,6
 17227                              <1> 	;
 17228                              <1> 	; OUTPUT ->
 17229                              <1> 	;	If CF = 0 ->
 17230                              <1> 	;          EAX = Set value
 17231                              <1> 	;	If CF = 1 -> (invalid BL input)
 17232                              <1> 	;	   EAX = Ticks count [TIMER_LH]
 17233                              <1> 	;
 17234                              <1> 
 17235 00011C3F 20DB                <1> 	and	bl, bl ; 0
 17236 00011C41 7511                <1> 	jnz	short sysstime_0
 17237 00011C43 89C8                <1> 	mov	eax, ecx
 17238 00011C45 E8CC52FFFF          <1> 	call	convert_from_epoch
 17239 00011C4A E86C53FFFF          <1> 	call	set_rtc_date_time
 17240 00011C4F E900B2FFFF          <1> 	jmp	sysret
 17241                              <1> sysstime_0:
 17242 00011C54 80FB08              <1> 	cmp	bl, 8
 17243 00011C57 722D                <1> 	jb	short sysstime_1
 17244                              <1> 	; invalid input (>7)
 17245 00011C59 A1[407D0100]        <1> 	mov	eax, [TIMER_LH] ; 18.2 Hz timer ticks
 17246                              <1> 				; Note: [TIMER_LH] may be set
 17247                              <1> 				; to wrong timer value due to
 17248                              <1> 				; program functions.
 17249                              <1> 				; (This value must not be
 17250                              <1> 				; accepted as [TIMER_LH]/18.2
 17251                              <1> 				; seconds since the midnight.)
 17252 00011C5E A3[74940100]        <1> 	mov	[u.r0], eax	
 17253 00011C63 E9CCB1FFFF          <1> 	jmp	error ; cf = 1 & [u.r0] = eax = timer ticks
 17254                              <1> 
 17255                              <1> sysstime_8:
 17256                              <1> 	; BL = 7
 17257 00011C68 89C8                <1> 	mov	eax, ecx ; seconds since 1/1/1970 00:00:00
 17258 00011C6A E8A752FFFF          <1> 	call	convert_from_epoch
 17259 00011C6F 30E4                <1> 	xor	ah, ah
 17260 00011C71 A0[8E790100]        <1> 	mov	al, [hour]
 17261 00011C76 C1E010              <1> 	shl	eax, 16
 17262 00011C79 A0[92790100]        <1> 	mov	al, [second]
 17263 00011C7E 8A25[90790100]      <1> 	mov	ah, [minute]
 17264 00011C84 EB92                <1> 	jmp	short systime_3
 17265                              <1> 
 17266                              <1> sysstime_1:
 17267 00011C86 80FB04              <1> 	cmp	bl, 4
 17268 00011C89 743F                <1> 	je	short sysstime_2 ; set system timer ticks
 17269 00011C8B 80FB05              <1> 	cmp	bl, 5
 17270 00011C8E 754B                <1> 	jne	short sysstime_4
 17271                              <1> 	; convert current time to system timer ticks (18.2Hz)
 17272 00011C90 E87651FFFF          <1> 	call	get_rtc_date_time
 17273 00011C95 0FB60D[8E790100]    <1> 	movzx	ecx, byte [hour]
 17274 00011C9C B8100E0000          <1> 	mov	eax, 60*60 ; 1 hour = 3600 seconds
 17275 00011CA1 F7E1                <1> 	mul	ecx
 17276 00011CA3 89C3                <1> 	mov	ebx, eax
 17277 00011CA5 B13C                <1> 	mov	cl, 60  ; 1 minute = 60 seconds
 17278 00011CA7 0FB605[90790100]    <1> 	movzx	eax, byte [minute]
 17279 00011CAE F7E1                <1> 	mul	ecx
 17280 00011CB0 01D8                <1> 	add	eax, ebx
 17281 00011CB2 8A0D[92790100]      <1> 	mov	cl, [second]
 17282 00011CB8 01C8                <1> 	add	eax, ecx
 17283 00011CBA B1B6                <1> 	mov	cl, 182
 17284 00011CBC F7E1                <1> 	mul	ecx
 17285 00011CBE 83C009              <1> 	add	eax, 9
 17286 00011CC1 83D200              <1> 	adc	edx, 0
 17287 00011CC4 B10A                <1> 	mov	cl, 10
 17288 00011CC6 F7F1                <1> 	div	ecx
 17289                              <1> 	; eax = ((182*seconds)+9)/10
 17290 00011CC8 89C1                <1> 	mov	ecx, eax
 17291                              <1> sysstime_2:
 17292 00011CCA 890D[407D0100]      <1> 	mov	[TIMER_LH], ecx ; 18.2 * seconds
 17293                              <1> sysstime_3:
 17294 00011CD0 890D[74940100]      <1> 	mov	[u.r0], ecx
 17295 00011CD6 E979B1FFFF          <1> 	jmp	sysret
 17296                              <1> sysstime_4:
 17297 00011CDB 80FB06              <1> 	cmp	bl, 6
 17298 00011CDE 7788                <1> 	ja	short sysstime_8
 17299                              <1> 
 17300 00011CE0 890D[74940100]      <1> 	mov	[u.r0], ecx
 17301                              <1> 
 17302 00011CE6 880D[92790100]      <1> 	mov	[second], cl
 17303 00011CEC 882D[90790100]      <1> 	mov	[minute], ch
 17304 00011CF2 C1E910              <1> 	shr	ecx, 16
 17305 00011CF5 880D[8E790100]      <1> 	mov	[hour], cl
 17306                              <1> 	; BL = 1,2,3,6
 17307 00011CFB 80FB01              <1> 	cmp	bl, 1
 17308 00011CFE 762A                <1> 	jna	short sysstime_5
 17309                              <1> 	; BL = 2,3,6
 17310 00011D00 8815[8C790100]      <1> 	mov	[day], dl
 17311 00011D06 8835[8A790100]      <1> 	mov	[month], dh
 17312 00011D0C C1EA10              <1> 	shr	edx, 16
 17313 00011D0F 668915[88790100]    <1> 	mov	[year], dx
 17314 00011D16 80E303              <1> 	and	bl, 3
 17315 00011D19 742D                <1> 	jz	short sysstime_7 ; 6
 17316                              <1> 	; BL = 2,3
 17317 00011D1B F6C301              <1> 	test	bl, 1
 17318 00011D1E 7419                <1> 	jz	short sysstime_6 ; 2
 17319                              <1> 	; BL = 3
 17320 00011D20 E89652FFFF          <1> 	call	set_rtc_date_time
 17321 00011D25 E92AB1FFFF          <1> 	jmp	sysret
 17322                              <1> sysstime_5:
 17323                              <1> 	; BL = 1
 17324 00011D2A E8CD52FFFF          <1> 	call	set_time_bcd
 17325 00011D2F E80546FFFF          <1> 	call	set_rtc_time
 17326 00011D34 E91BB1FFFF          <1> 	jmp	sysret
 17327                              <1> sysstime_6:
 17328                              <1> 	; BL = 2
 17329 00011D39 E89152FFFF          <1> 	call	set_date_bcd
 17330 00011D3E E85946FFFF          <1> 	call	set_rtc_date
 17331 00011D43 E90CB1FFFF          <1> 	jmp	sysret
 17332                              <1> sysstime_7:
 17333                              <1> 	; BL = 6
 17334                              <1> 	; [year], [month], [day],
 17335                              <1> 	; [hour], [minute], [second]
 17336 00011D48 E84951FFFF          <1> 	call	convert_to_epoch
 17337 00011D4D 89C1                <1> 	mov	ecx, eax ; seconds since 1/1/1970 00:00:00
 17338 00011D4F E97CFFFFFF          <1> 	jmp	sysstime_3
 17339                              <1> 
 17340                              <1> sysrename: ; Rename File (or Directory)
 17341                              <1> 	; 08/08/2022
 17342                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
 17343                              <1> 	; 19/01/2021
 17344                              <1> 	; 31/12/2017 (TRDOS 386 = TRDOS v2.0)
 17345                              <1> 	;
 17346                              <1>         ; INPUT ->
 17347                              <1>         ;          EBX = File/Directory (ASCIIZ) name address
 17348                              <1> 	;	   ECX = New name (in same dir, no path name)
 17349                              <1> 	; OUTPUT ->
 17350                              <1> 	;          cf = 0 -> EAX = 0
 17351                              <1> 	;          cf = 1 -> Error code in AL
 17352                              <1> 
 17353                              <1> 	; 19/01/2021
 17354 00011D54 803D[C6940100]00    <1> 	cmp	byte [u.uid], 0  ; root (super user) ?
 17355                              <1> 	;jna	short sysrename_0
 17356                              <1> 	; 23/07/2022
 17357 00011D5B 7717                <1> 	ja	short sysrename_perm_err
 17358                              <1> 
 17359                              <1> ;sysrename_perm_err:
 17360                              <1> ;	;mov	dword [u.r0], ERR_PERM_DENIED
 17361                              <1> ;	mov	eax, ERR_PERM_DENIED ; 'permission denied !'
 17362                              <1> ;	mov	[u.r0], eax
 17363                              <1> ;	mov	[u.error], eax
 17364                              <1> ;	jmp	error
 17365                              <1> 
 17366                              <1> sysrename_0:
 17367 00011D5D 51                  <1> 	push	ecx ; new file name address (in user space)
 17368 00011D5E 89DE                <1> 	mov	esi, ebx
 17369                              <1> 	; file name is forced, change directory as temporary
 17370                              <1> 	;mov	ax, 1
 17371                              <1> 	;mov	[FFF_Valid], ah ; 0 ; reset
 17372                              <1> 	;call	set_working_path
 17373 00011D60 E87D050000          <1> 	call	set_working_path_x
 17374 00011D65 7321                <1> 	jnc	short sysrename_1
 17375 00011D67 21C0                <1> 	and	eax, eax  ; 0 -> Bad Path!
 17376 00011D69 753B                <1> 	jnz	short sysrename_err
 17377                              <1> 	; eax = 0
 17378                              <1> sysrename_path_not_found:
 17379 00011D6B B813000000          <1> 	mov	eax, ERR_INV_PATH_NAME ; 'Bad path name !'
 17380                              <1> 	; 23/07/2022
 17381 00011D70 B013                <1> 	mov	al, ERR_INV_PATH_NAME
 17382 00011D72 EB32                <1> 	jmp	short sysrename_err
 17383                              <1> ;sysrename_err:
 17384                              <1> ;	pop	ecx ; new file name address (in user space)
 17385                              <1> ;sysrename_error:
 17386                              <1> ;	mov	[u.r0], eax
 17387                              <1> ;	mov	[u.error], eax
 17388                              <1> ;	call 	reset_working_path
 17389                              <1> ;	jmp	error
 17390                              <1> 
 17391                              <1> 	; 23/07/2022
 17392                              <1> sysrename_perm_err:
 17393                              <1> 	;mov	dword [u.r0], ERR_PERM_DENIED
 17394 00011D74 B80B000000          <1> 	mov	eax, ERR_PERM_DENIED ; 'permission denied !'
 17395 00011D79 A3[74940100]        <1> 	mov	[u.r0], eax
 17396 00011D7E A3[E0940100]        <1> 	mov	[u.error], eax
 17397 00011D83 E9ACB0FFFF          <1> 	jmp	error
 17398                              <1> 
 17399                              <1> sysrename_1:
 17400 00011D88 B008                <1> 	mov	al, 08h ; Except volume labels (& long names)
 17401 00011D8A A0[38870100]        <1> 	mov	al, [Attributes]
 17402 00011D8F 2410                <1> 	and	al, 10h ;
 17403                              <1> 	;mov	esi, FindFile_Name
 17404                              <1> 	;mov	ax, 1800h ; Only files
 17405                              <1> 	;mov	ax, 0810h ; Only directories
 17406 00011D91 66B80008            <1> 	mov	ax, 0800h ; Find File or Directory
 17407 00011D95 E8D06DFFFF          <1> 	call	find_first_file
 17408                              <1> 	;jnc	short sysrename_2
 17409 00011D9A 720A                <1> 	jc	short sysrename_err
 17410                              <1> sysrename_2:
 17411                              <1> 	; ESI = Directory Entry (FindFile_DirEntry) Location
 17412                              <1> 	; EDI = Directory Buffer Directory Entry Location
 17413                              <1> 	; EAX = File Size
 17414                              <1> 	;  BL = Attributes of The File/Directory
 17415                              <1> 	;  BH = Long Name Yes/No Status (>0 is YES)
 17416                              <1> 	;  DX > 0 : Ambiguous filename chars are used
 17417                              <1> 
 17418 00011D9C 6621D2              <1> 	and	dx, dx ; Ambiguous filename chars used sign (DX>0)
 17419 00011D9F 741A                <1> 	jz	short sysrename_3
 17420 00011DA1 B81A000000          <1> 	mov	eax, ERR_INV_FILE_NAME ; 'invalid file name !'
 17421                              <1> 	;jmp	short sysrename_err
 17422                              <1> 	; 23/07/2022
 17423                              <1> sysrename_err:
 17424 00011DA6 59                  <1> 	pop	ecx ; new file name address (in user space)
 17425                              <1> sysrename_error:
 17426 00011DA7 A3[74940100]        <1> 	mov	[u.r0], eax
 17427 00011DAC A3[E0940100]        <1> 	mov	[u.error], eax
 17428 00011DB1 E801060000          <1> 	call 	reset_working_path
 17429 00011DB6 E979B0FFFF          <1> 	jmp	error
 17430                              <1> sysrename_3:
 17431                              <1> 	; EDI = Directory buffer entry offset/address
 17432                              <1> 	; BL = File (or Directory) Attributes 
 17433                              <1> 	; mov	bl, [EDI+0Bh]
 17434                              <1> 
 17435 00011DBB 5A                  <1> 	pop	edx ; new file name address (in user space)
 17436                              <1> 
 17437                              <1> 	; check file/directory attributes
 17438 00011DBC F6C307              <1> 	test	bl, 7 ; system, hidden, readonly
 17439 00011DBF 75B3                <1>         jnz	short sysrename_perm_err
 17440                              <1> sysrename_4:
 17441 00011DC1 66817F0CA101        <1> 	cmp	word [edi+DirEntry_NTRes], 01A1h ; Singlix FS
 17442 00011DC7 74AB                <1> 	je	short sysrename_perm_err ; -temporary!-
 17443                              <1> 
 17444                              <1> 	; save old file name & file info (FFF structure)
 17445 00011DC9 BE[22860100]        <1> 	mov	esi, FindFile_Drv
 17446 00011DCE BF[68870100]        <1> 	mov	edi, SourceFile_Drv
 17447                              <1> 	;mov	ecx, 128/4
 17448                              <1> 	; 23/07/2022
 17449 00011DD3 29C9                <1> 	sub	ecx, ecx
 17450 00011DD5 B120                <1> 	mov	cl, 128/4
 17451 00011DD7 F3A5                <1> 	rep	movsd
 17452                              <1> 
 17453 00011DD9 89D6                <1> 	mov	esi, edx ; new file name address (in user space)
 17454 00011DDB BF[E8870100]        <1> 	mov	edi, DestinationFile_Drv
 17455 00011DE0 E8358EFFFF          <1> 	call	parse_path_name
 17456 00011DE5 72C0                <1> 	jc	short sysrename_error ; eax = 1 (Bad file name)
 17457                              <1> 
 17458                              <1> 	; same drive ?
 17459 00011DE7 A0[22860100]        <1> 	mov	al, [FindFile_Drv]
 17460 00011DEC 3A05[E8870100]      <1> 	cmp	al, [DestinationFile_Drv]
 17461                              <1> 	;jne	short sysrename_perm_err ; Permission denied
 17462 00011DF2 7509                <1> 	jne	short sysrename_5 ; Bad file name
 17463                              <1> 
 17464                              <1> 	; no path name !? (rename file in same directory)
 17465 00011DF4 803D[E9870100]20    <1> 	cmp	byte [DestinationFile_Directory], 20h
 17466 00011DFB 7607                <1> 	jna	short sysrename_6
 17467                              <1> sysrename_5:
 17468 00011DFD B801000000          <1> 	mov	eax, ERR_BAD_CMD_ARG ; 1 = Bad file name
 17469                              <1> 				     ; (Bad argument)
 17470 00011E02 EBA3                <1> 	jmp	short sysrename_error
 17471                              <1> sysrename_6:
 17472 00011E04 803D[2A880100]20    <1> 	cmp	byte [DestinationFile_Name], 20h
 17473 00011E0B 76F0                <1> 	jna	short sysrename_5
 17474                              <1> 
 17475 00011E0D BE[2A880100]        <1> 	mov	esi, DestinationFile_Name
 17476 00011E12 E8F870FFFF          <1> 	call	check_filename ; is it a valid msdos file name?
 17477 00011E17 728E                <1> 	jc	short sysrename_error ; 26 = ERR_INV_FILE_NAME
 17478                              <1> 
 17479                              <1> 	;mov	esi, DestinationFile_Name
 17480 00011E19 66B80008            <1> 	mov	ax, 0800h ; Find File or Directory
 17481 00011E1D E8486DFFFF          <1> 	call	find_first_file
 17482 00011E22 720A                <1> 	jc	short sysrename_7
 17483                              <1> 
 17484 00011E24 B80E000000          <1> 	mov	eax, ERR_FILE_EXISTS  ; file already exists !
 17485                              <1> jmp_sysrename_err:	; 08/08/2022
 17486 00011E29 E979FFFFFF          <1> 	jmp	sysrename_error
 17487                              <1> sysrename_7:
 17488                              <1> 	; eax = 2 (File not found !)
 17489 00011E2E 3C02                <1> 	cmp	al, 2 ; ERR_NOT_FOUND
 17490                              <1> 	;jne	short sysrename_error
 17491                              <1> 	; 08/08/2022
 17492 00011E30 75F7                <1> 	jne	short jmp_sysrename_err
 17493                              <1> 
 17494                              <1> 	; 31/12/2017
 17495                              <1> 	; Following code is also part of 'rename_file' in
 17496                              <1> 	; 'trdosk3.s' (MainProg's 'rename' command) ; 13/11/2017
 17497 00011E32 BE[2A880100]        <1> 	mov	esi, DestinationFile_Name ; (Rename_NewName)
 17498 00011E37 668B0D[E2870100]    <1> 	mov	cx, [SourceFile_DirEntryNumber] 
 17499 00011E3E 66A1[CE870100]      <1> 	mov	ax, [SourceFile_DirEntry+20] ; First Cluster, HW 
 17500 00011E44 C1E010              <1> 	shl	eax, 16
 17501 00011E47 66A1[D4870100]      <1> 	mov	ax, [SourceFile_DirEntry+26] ; First Cluster, LW 
 17502 00011E4D 0FB61D[B7870100]    <1>   	movzx	ebx, byte [SourceFile_LongNameEntryLength]
 17503 00011E54 E8C495FFFF          <1>    	call	rename_directory_entry
 17504                              <1> 	;jc	short sysrename_error
 17505                              <1> 	; 08/08/2022
 17506 00011E59 72CE                <1> 	jc	short jmp_sysrename_err
 17507                              <1> 	;xor	eax, eax
 17508 00011E5B A3[74940100]        <1> 	mov	[u.r0], eax ; 0
 17509                              <1> 	;mov	[u.error], eax
 17510 00011E60 E852050000          <1> 	call 	reset_working_path
 17511 00011E65 E9EAAFFFFF          <1> 	jmp	sysret
 17512                              <1> 
 17513                              <1> sysmem: ; Get Total&Free Memory amount 
 17514                              <1> 	; 31/12/2017 (TRDOS 386 = TRDOS v2.0)
 17515                              <1> 	;
 17516                              <1>         ; INPUT ->
 17517                              <1> 	;	none
 17518                              <1> 	; OUTPUT ->
 17519                              <1> 	;	EAX = Total memory count (in bytes)
 17520                              <1> 	;	EBX = Virtually available memory amount (in bytes)
 17521                              <1> 	;	      = 4GB - CORE (4MB)
 17522                              <1> 	;	ECX = Free memory count (in bytes)
 17523                              <1> 	;	EDX = Calculated free memory count (in bytes)
 17524                              <1> 	
 17525 00011E6A A1[C47C0100]        <1> 	mov	eax, [memory_size] ; in pages
 17526 00011E6F C1E00C              <1> 	shl	eax, 12		   ; in bytes
 17527 00011E72 A3[74940100]        <1> 	mov	[u.r0], eax
 17528 00011E77 E87523FFFF          <1> 	call	calc_free_mem
 17529                              <1> 	; edx = calculated free pages
 17530                              <1> 	; ecx = 0
 17531 00011E7C 8B2D[70940100]      <1> 	mov	ebp, [u.usp]  ; EBP points to user's registers
 17532 00011E82 C745100000C0FF      <1> 	mov	dword [ebp+16], ECORE ; EBX (for user)
 17533                              <1> 				; 0FFC00000h ; 4GB - 4MB
 17534 00011E89 C1E20C              <1> 	shl	edx, 12
 17535 00011E8C 895514              <1> 	mov	[ebp+20], edx ; EDX (for user)
 17536 00011E8F 8B0D[C87C0100]      <1> 	mov 	ecx, [free_pages]
 17537 00011E95 C1E10C              <1> 	shl	ecx, 12	; free bytes
 17538 00011E98 894D18              <1> 	mov	[ebp+24], ecx ; ECX (for user)
 17539                              <1> 	;mov	[free_pages], edx
 17540 00011E9B E9B4AFFFFF          <1> 	jmp	sysret
 17541                              <1> 
 17542                              <1> sysprompt:
 17543                              <1> 	; Set TRDOS 386 Command Interpreter (MainProg) prompt
 17544                              <1> 	; 30/07/2022 (TRDOS 386 Kernel v2.0.5)
 17545                              <1> 	; 31/12/2017 (TRDOS 386 = TRDOS v2.0) 
 17546                              <1> 	;
 17547                              <1>         ; INPUT -> 
 17548                              <1> 	;	EBX = 0 -> use default prompt
 17549                              <1> 	;	EBX > 0 -> prompt string (ASCIIZ) address
 17550                              <1> 	;		  (Max. 11 characters except ZERO tail)
 17551                              <1> 	; OUTPUT ->
 17552                              <1> 	;	(EAX = 0)
 17553                              <1> 	;	CF = 0 -> Successful
 17554                              <1> 	;	CF = 1 -> Failed
 17555                              <1> 
 17556 00011EA0 21DB                <1> 	and	ebx, ebx
 17557 00011EA2 750A                <1> 	jnz	short sysprompt_0
 17558                              <1> 
 17559 00011EA4 E8A866FFFF          <1> 	call	default_command_prompt ; '['+'TRDOS'+']'
 17560 00011EA9 E9A6AFFFFF          <1> 	jmp	sysret
 17561                              <1> 
 17562                              <1> sysprompt_0:
 17563 00011EAE 31C0                <1> 	xor	eax, eax
 17564 00011EB0 A3[74940100]        <1> 	mov	[u.r0], eax
 17565 00011EB5 89DE                <1> 	mov	esi, ebx
 17566                              <1> 	;mov	ecx, 12
 17567                              <1> 	; 30/07/2022
 17568 00011EB7 31C9                <1> 	xor	ecx, ecx
 17569 00011EB9 B10C                <1> 	mov	cl, 12
 17570 00011EBB 89E5                <1> 	mov	ebp, esp
 17571 00011EBD 29CC                <1> 	sub	esp, ecx
 17572 00011EBF 49                  <1> 	dec	ecx ; 11
 17573 00011EC0 89E7                <1> 	mov	edi, esp
 17574 00011EC2 E813F1FFFF          <1> 	call	transfer_from_user_buffer
 17575 00011EC7 7211                <1> 	jc	short sysprompt_err
 17576 00011EC9 803E20              <1> 	cmp	byte [esi], 20h
 17577 00011ECC 760C                <1> 	jna	short sysprompt_err
 17578 00011ECE E89066FFFF          <1> 	call	set_command_prompt
 17579 00011ED3 89EC                <1> 	mov	esp, ebp
 17580 00011ED5 E97AAFFFFF          <1> 	jmp	sysret
 17581                              <1> sysprompt_err:
 17582                              <1> syspath_err:
 17583 00011EDA 89EC                <1> 	mov	esp, ebp
 17584 00011EDC E953AFFFFF          <1> 	jmp	error
 17585                              <1> 
 17586                              <1> syspath:
 17587                              <1> 	; Get/Set Run Path
 17588                              <1> 	;
 17589                              <1> 	; 30/07/2022 (TRDOS 386 Kernel v2.0.5)
 17590                              <1> 	; 31/12/2017 (TRDOS 386 = TRDOS v2.0)
 17591                              <1> 	;
 17592                              <1>         ; INPUT ->
 17593                              <1> 	;	EBX = 0 -> get path (to buffer address in ECX)
 17594                              <1> 	;	EBX > 0 -> set path
 17595                              <1> 	;	    EBX = Path string buffer address (ASCIIZ)
 17596                              <1> 	;	    	  (Path description except 'PATH=')
 17597                              <1> 	;	ECX = Buffer address (if EBX = 0)
 17598                              <1> 	;	      (ECX will not be used if EBX > 0)
 17599                              <1> 	;	DL = Buffer size (0 = 256 byte)	
 17600                              <1> 	;
 17601                              <1> 	; OUTPUT ->
 17602                              <1> 	;	CF = 0 -> Successful (EAX = String length)
 17603                              <1> 	;	CF = 1 -> Failed (EAX = 0)
 17604                              <1> 	;
 17605                              <1> 	; NOTE: 'PATH=' or 'PATH' must be excluded
 17606                              <1> 	;  (It must not be at the beginning of the string.)
 17607                              <1> 
 17608 00011EE1 89E5                <1> 	mov	ebp, esp
 17609 00011EE3 81EC00010000        <1> 	sub	esp, 256
 17610 00011EE9 89E7                <1> 	mov	edi, esp
 17611                              <1> 
 17612 00011EEB 31C0                <1> 	xor	eax, eax
 17613 00011EED A3[74940100]        <1> 	mov	[u.r0], eax
 17614                              <1> 
 17615 00011EF2 21DB                <1> 	and	ebx, ebx
 17616 00011EF4 752A                <1> 	jnz	short syspath_0
 17617                              <1> 
 17618                              <1> 	; EBX = 0 -> get run path
 17619 00011EF6 89CB                <1> 	mov	ebx, ecx ; buffer addr (in user's mem space)
 17620 00011EF8 BE[6F350100]        <1> 	mov	esi, Cmd_Path  ; 'PATH' address
 17621 00011EFD 0FB6CA              <1> 	movzx	ecx, dl
 17622                              <1> 	;sub	cl, 1 ; 0 -> 255, 1 -> 0
 17623                              <1> 	;adc	cx, 1 ; 255 -> 256, 0 -> 1
 17624                              <1> 	; 30/07/2022
 17625 00011F00 FEC9                <1> 	dec	cl ; 0 -> 255, 1 -> 0
 17626 00011F02 41                  <1> 	inc	ecx ; 255 -> 256, 0 -> 1 
 17627                              <1> 	; EDI = Output buffer
 17628                              <1> 	; CX = Buffer length
 17629                              <1> 	; AL = 0 -> use ASCIIZ word in [ESI]
 17630                              <1> 	; ESI = 'PATH' address (with zero tail)
 17631 00011F03 E8F77DFFFF          <1> 	call	get_environment_string
 17632 00011F08 72D0                <1> 	jc	short syspath_err
 17633 00011F0A 89DF                <1> 	mov	edi, ebx ; User's buffer address
 17634 00011F0C 89E6                <1> 	mov	esi, esp
 17635                              <1> 	; EDI = User's buffer address
 17636                              <1> 	; ECX = transfer (byte) count
 17637 00011F0E E87DF0FFFF          <1> 	call	transfer_to_user_buffer
 17638 00011F13 72C5                <1> 	jc	short syspath_err
 17639 00011F15 890D[74940100]      <1> 	mov	[u.r0], ecx 
 17640 00011F1B E934AFFFFF          <1> 	jmp	sysret
 17641                              <1> 
 17642                              <1> syspath_0:
 17643 00011F20 89DE                <1> 	mov	esi, ebx
 17644 00011F22 0FB6CA              <1> 	movzx	ecx, dl
 17645                              <1> 	;sub	cl, 1 ; 0 -> 255, 1 -> 0
 17646                              <1> 	;adc	cx, 1 ; 255 -> 256, 0 -> 1
 17647                              <1> 	; 30/07/2022
 17648 00011F25 FEC9                <1> 	dec	cl ; 0 -> 255, 1 -> 0
 17649 00011F27 41                  <1> 	inc	ecx ; 255 -> 256, 0 -> 1
 17650 00011F28 E8ADF0FFFF          <1> 	call	transfer_from_user_buffer
 17651 00011F2D 72AB                <1> 	jc	short syspath_err
 17652                              <1> 	;(*) 'PATH=' will be added to
 17653                              <1> 	;         the head of the string
 17654 00011F2F 83EC08              <1> 	sub	esp, 8 ;(*)
 17655 00011F32 89FE                <1> 	mov	esi, edi ;(*)
 17656 00011F34 E8AA7DFFFF          <1> 	call	set_path_x ;(*)
 17657 00011F39 729F                <1> 	jc	short syspath_err
 17658 00011F3B 8915[74940100]      <1> 	mov	[u.r0], edx ; run path string length
 17659 00011F41 E90EAFFFFF          <1> 	jmp	sysret
 17660                              <1> 
 17661                              <1> sysenv:
 17662                              <1> 	; Get/Set Environment Variables
 17663                              <1> 	;
 17664                              <1> 	; 30/07/2022
 17665                              <1> 	; 23/07/2022 - TRDOS 386 v2.0.5
 17666                              <1> 	; 31/12/2017 (TRDOS 386 = TRDOS v2.0)
 17667                              <1> 	;
 17668                              <1>         ; INPUT ->
 17669                              <1> 	;	EBX = 0 -> get (all) environment variables
 17670                              <1> 	;	      (Required Buffer length = 512 bytes)
 17671                              <1> 	;	EBX > 0 -> set (one) environment variable
 17672                              <1> 	;	      (If there is not a '=' after
 17673                              <1> 	;	      the environment variable name, it will
 17674                              <1> 	;	      accepted as 'get environment variable'.)
 17675                              <1> 	;	       EBX = Buffer address
 17676                              <1> 	;	ECX = Buffer address (if EBX = 0)
 17677                              <1> 	;	      (ECX will not be used if EBX > 0)
 17678                              <1> 	;	      (Note: Buffer size is 512 bytes.)
 17679                              <1> 	;	DL = Buffer size (0 = 256 byte)
 17680                              <1> 	;	     (For one envrionment variable)
 17681                              <1> 	;
 17682                              <1> 	; OUTPUT ->
 17683                              <1> 	;	(EAX = 0)
 17684                              <1> 	;	CF = 0 -> Successful (EAX = String length)
 17685                              <1> 	;	CF = 1 -> Failed (EAX = 0)
 17686                              <1> 	;
 17687                              <1> 	; Note: Environment variable name, for example,
 17688                              <1> 	;	'PATH=' must be included at the beginning
 17689                              <1> 	;	of the environment string. If the variable
 17690                              <1> 	;	name is as 'PATH' but it is not as 'PATH='
 17691                              <1> 	;	the variable string (row) will be returned.
 17692                              <1> 	;	If variable name is as 'PATH=' but there is
 17693                              <1> 	;	not a following text after the variable name,
 17694                              <1> 	;	the environment variable will be reset/deleted.
 17695                              <1> 
 17696 00011F46 89E5                <1> 	mov	ebp, esp
 17697 00011F48 81EC00020000        <1> 	sub	esp, 512
 17698 00011F4E 89E7                <1> 	mov	edi, esp
 17699                              <1> 
 17700 00011F50 31C0                <1> 	xor	eax, eax
 17701 00011F52 A3[74940100]        <1> 	mov	[u.r0], eax
 17702                              <1> 
 17703 00011F57 21DB                <1> 	and	ebx, ebx
 17704 00011F59 751F                <1> 	jnz	short sysenv_0
 17705                              <1> 
 17706                              <1> 	; EBX = 0 -> get (all) environment variables
 17707 00011F5B 89EC                <1> 	mov	esp, ebp
 17708 00011F5D BE00300900          <1> 	mov	esi, Env_Page  ; Environment page
 17709 00011F62 89CF                <1> 	mov	edi, ecx ; buffer addr (in user's mem space)
 17710                              <1> 	;mov	ecx, 512
 17711                              <1> 	; 30/07/2022
 17712 00011F64 29C9                <1> 	sub	ecx, ecx
 17713 00011F66 B502                <1> 	mov	ch, 2
 17714                              <1> 	; ecx = 512
 17715 00011F68 E823F0FFFF          <1> 	call	transfer_to_user_buffer
 17716                              <1> 	;jc	error
 17717                              <1> 	; 23/07/2022
 17718 00011F6D 725B                <1> 	jc	short sysenv_error
 17719 00011F6F 890D[74940100]      <1> 	mov	[u.r0], ecx
 17720 00011F75 E9DAAEFFFF          <1> 	jmp	sysret
 17721                              <1> 
 17722                              <1> sysenv_0:
 17723 00011F7A 89DE                <1> 	mov	esi, ebx ; * ; user's buffer address
 17724 00011F7C 0FB6CA              <1> 	movzx	ecx, dl
 17725                              <1> 	;sub	cl, 1 ; 0 -> 255, 1 -> 0
 17726                              <1> 	;adc	cx, 1 ; 255 -> 256, 0 -> 1
 17727                              <1> 	; 30/07/2022
 17728 00011F7F FEC9                <1> 	dec	cl ; 0 -> 255, 1 -> 0
 17729 00011F81 41                  <1> 	inc	ecx ; 255 -> 256, 0 -> 1
 17730 00011F82 E853F0FFFF          <1> 	call	transfer_from_user_buffer
 17731 00011F87 723F                <1> 	jc	short sysenv_err
 17732 00011F89 89FE                <1> 	mov	esi, edi
 17733 00011F8B 8A06                <1> 	mov	al, [esi]
 17734 00011F8D 3C20                <1> 	cmp	al, 20h
 17735 00011F8F 7637                <1> 	jna	short sysenv_err
 17736 00011F91 3C3D                <1> 	cmp	al, '='
 17737 00011F93 7433                <1> 	je	short sysenv_err
 17738 00011F95 56                  <1> 	push	esi
 17739                              <1> sysenv_1:
 17740 00011F96 46                  <1> 	inc	esi
 17741 00011F97 803E3D              <1> 	cmp	byte [esi], '='
 17742 00011F9A 7433                <1> 	je	short sysenv_3
 17743 00011F9C 803E20              <1> 	cmp	byte [esi], 20h
 17744 00011F9F 73F5                <1> 	jnb	short sysenv_1
 17745 00011FA1 C60600              <1> 	mov	byte [esi], 0
 17746 00011FA4 5E                  <1> 	pop	esi
 17747                              <1> 	; EDI = Output buffer
 17748                              <1> 	; CX = Buffer length
 17749 00011FA5 30C0                <1> 	xor	al, al
 17750                              <1> 	; AL = 0 -> use ASCIIZ word in [ESI]
 17751                              <1> 	; ESI = Environment variable name address
 17752 00011FA7 E8537DFFFF          <1> 	call	get_environment_string
 17753 00011FAC 721A                <1> 	jc	short sysenv_err
 17754 00011FAE 89DF                <1> 	mov	edi, ebx ; * ; user's buffer address
 17755 00011FB0 89C1                <1> 	mov	ecx, eax ; String length
 17756 00011FB2 89E6                <1> 	mov	esi, esp 
 17757                              <1> 	; ESI = system buffer address
 17758                              <1> 	; EDI = User's buffer address
 17759                              <1> 	; ECX = transfer (byte) count
 17760 00011FB4 E8D7EFFFFF          <1> 	call	transfer_to_user_buffer
 17761 00011FB9 720D                <1> 	jc	short sysenv_err
 17762 00011FBB 890D[74940100]      <1> 	mov	[u.r0], ecx ; transfer (byte) count
 17763                              <1> sysenv_2:
 17764 00011FC1 89EC                <1> 	mov	esp, ebp
 17765 00011FC3 E98CAEFFFF          <1> 	jmp	sysret
 17766                              <1> sysenv_err:
 17767 00011FC8 89EC                <1> 	mov	esp, ebp
 17768                              <1> sysenv_error:	; 23/07/2022
 17769 00011FCA E965AEFFFF          <1> 	jmp	error
 17770                              <1> sysenv_3:
 17771 00011FCF 46                  <1> 	inc	esi
 17772 00011FD0 803E20              <1> 	cmp	byte [esi], 20h
 17773 00011FD3 73FA                <1> 	jnb	short sysenv_3
 17774 00011FD5 C60600              <1> 	mov	byte [esi], 0
 17775 00011FD8 5E                  <1> 	pop	esi
 17776 00011FD9 E8E47DFFFF          <1> 	call	set_environment_string
 17777 00011FDE 72E8                <1> 	jc	short sysenv_err
 17778 00011FE0 8915[74940100]      <1> 	mov	[u.r0], edx
 17779 00011FE6 EBD9                <1> 	jmp	short sysenv_2
 17780                              <1> 
 17781                              <1> isintr:
 17782                              <1> 	; 21/08/2024 - TRDOS 386 v2.0.9
 17783                              <1> 	; check terminate (CTRL+BREAK)
 17784                              <1> 	;	interrupt is enabled or disabled
 17785                              <1> 	;test	word [u.intr], 0FFFFh
 17786 00011FE8 F605[C0940100]FF    <1> 	test	byte [u.intr], 0FFh
 17787                              <1> 	; zf = 1 -> terminate interrupt disabled
 17788                              <1> 	; zf = 0 -> terminate interrupt enabled
 17789 00011FEF C3                  <1> 	retn
 17790                              <1> 
 17791                              <1> ; 23/07/2022 - TRDOS 386 v2.0.5
 17792                              <1> 
 17793                              <1> ; 22/01/2021
 17794                              <1> ; temporary - 24/01/2016
 17795                              <1> 
 17796                              <1> iget:
 17797                              <1> 	;retn
 17798                              <1> iopen:
 17799                              <1> 	;retn
 17800                              <1> iclose:
 17801                              <1> 	;retn
 17802                              <1> sndc:
 17803                              <1> 	;retn
 17804                              <1> access:
 17805                              <1> 	;retn
 17806                              <1> sleep:
 17807 00011FF0 C3                  <1> 	retn
  3436                                  %include 'trdosk7.s' ; 24/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.6) - DISK READ&WRITE : trdosk7.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 29/08/2023  (Previous: 25/07/2022 - Kernel v2.0.5)
     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 00011FF1 807E0500            <1> 	cmp	byte [esi+LD_LBAYes], 0
    20 00011FF5 7774                <1>         ja      short lba_write
    21                              <1> 
    22                              <1> chs_write:
    23                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
    24                              <1> 	; 25/02/2016
    25                              <1> 	; 23/02/2016
    26 00011FF7 C605[71850100]03    <1> 	mov	byte [disk_rw_op], 3 ; CHS write
    27 00011FFE EB0D                <1> 	jmp	short chs_rw
    28                              <1> 
    29                              <1> disk_read:
    30                              <1> 	; 25/02/2016
    31                              <1> 	; 24/02/2016
    32                              <1> 	; 23/02/2016
    33                              <1> 	; 17/02/2016
    34                              <1> 	; 14/02/2016
    35                              <1> 	; 31/01/2016 (TRDOS 386 = TRDOS v2.0)
    36                              <1> 	; 17/10/2010
    37                              <1> 	; 18/04/2010
    38                              <1> 	;
    39                              <1> 	; INPUT -> EAX = Logical Block Address
    40                              <1> 	;	   ESI = Logical Dos Disk Table Offset (DRV)
    41                              <1> 	;	   ECX = Sector Count
    42                              <1> 	; 	   EBX = Destination Buffer
    43                              <1> 	; OUTPUT ->
    44                              <1> 	;	   cf = 0 or cf = 1
    45                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
    46                              <1> 
    47 00012000 807E0500            <1> 	cmp	byte [esi+LD_LBAYes], 0
    48 00012004 776E                <1>         ja      short lba_read
    49                              <1> 
    50                              <1> chs_read:
    51                              <1> 	; 29/08/2023 (TRDOS 386 Kernel v2.0.6)
    52                              <1> 	; 25/07/2022 (TRDOS 386 Kernel v2.0.5)
    53                              <1> 	; 25/02/2016
    54                              <1> 	; 24/02/2016
    55                              <1> 	; 23/02/2016
    56                              <1> 	; 31/01/2016 (TRDOS 386 = TRDOS v2.0)
    57                              <1> 	; 20/07/2011
    58                              <1> 	; 04/07/2009
    59                              <1> 	;
    60                              <1> 	; INPUT -> EAX = Logical Block Address
    61                              <1> 	;	   ECX = Number of sectors to read
    62                              <1> 	; 	   ESI = Logical Dos Disk Table Offset (DRV)
    63                              <1> 	; 	   EBX = Destination Buffer
    64                              <1> 	; OUTPUT ->
    65                              <1> 	;	   cf = 0 or cf = 1
    66                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
    67                              <1> 
    68                              <1> 	; 23/02/2016
    69 00012006 C605[71850100]02    <1> 	mov	byte [disk_rw_op], 2 ; CHS read
    70                              <1> 
    71                              <1> chs_rw:
    72                              <1> 	;;movzx	edx, word [esi+LD_BPB+SecPerTrack]
    73                              <1> 	;movzx	edx, byte [esi+LD_BPB+SecPerTrack] ; <= 63
    74                              <1> 	;mov	[disk_rw_spt], dl
    75                              <1> 
    76                              <1> chs_read_next_sector:
    77 0001200D C605[72850100]04    <1> 	mov	byte [retry_count], 4
    78                              <1> 
    79                              <1> chs_read_retry:
    80                              <1> 	;mov	[sector_count], ecx ; 23/02/2016
    81                              <1> 
    82 00012014 50                  <1> 	push	eax			; Linear sector #
    83 00012015 51                  <1> 	push	ecx			; # of FAT/FILE/DIR sectors
    84                              <1> 
    85 00012016 0FB74E1E            <1> 	movzx	ecx, word [esi+LD_BPB+SecPerTrack]
    86                              <1> 	;movzx	ecx, byte [disk_rw_spt] ; 23/02/2016
    87 0001201A 29D2                <1> 	sub	edx, edx
    88 0001201C F7F1                <1> 	div	ecx
    89                              <1> 	; eax = track, dx (dl ) = sector (on track)
    90                              <1> 	;sub	cl, dl ; 24/02/2016 (spt - sec)
    91                              <1> 	;push	ecx ; *
    92                              <1> 	; 25/07/2022
    93                              <1> 	;mov	cx, dx			; Sector (zero based)
    94                              <1> 	;inc	cx			; To make it 1 based
    95                              <1> 	;push	cx
    96                              <1> 	; 29/08/2023
    97                              <1> 	;mov	ecx, edx
    98                              <1> 	;inc	ecx
    99                              <1> 	;push	ecx
   100 0001201E 42                  <1> 	inc	edx
   101 0001201F 52                  <1> 	push	edx ; dl = sector number (on track)
   102                              <1> 	;
   103 00012020 668B4E20            <1> 	mov	cx, [esi+LD_BPB+Heads]
   104                              <1> 	;sub	dx, dx
   105                              <1> 	; 25/07/2022
   106 00012024 29D2                <1> 	sub	edx, edx
   107 00012026 F7F1                <1> 	div	ecx			; Convert track to head & cyl
   108                              <1> 	; eax (ax) = cylinder, dx (dl) = head (max. FFh)
   109 00012028 88D6                <1> 	mov	dh, dl
   110                              <1> 	;pop	cx			; AX=Cyl, DH=Head, CX=Sector
   111                              <1> 	; 25/07/2022
   112 0001202A 59                  <1> 	pop	ecx ; sector number (on track)
   113 0001202B 8A5602              <1> 	mov	dl, [esi+LD_PhyDrvNo]
   114                              <1> 
   115 0001202E 88C5                <1> 	mov	ch, al			; NOTE: max. 1023 cylinders !
   116 00012030 C0CC02              <1> 	ror	ah, 2			; Rotate 2 bits right
   117 00012033 08E1                <1> 	or	cl, ah
   118                              <1> 
   119                              <1> 	; 24/02/2016
   120                              <1> 	;pop	eax ; * (spt - sec) (example: 63 - 0 = 63)
   121                              <1> 	;cmp	eax, [sector_count]
   122                              <1> 	;jb	short chs_write_sectors
   123                              <1> 	;je	short chs_read_sectors
   124                              <1> 	;; (# of sectors to read is more than remaining sectors on the track)
   125                              <1> 	;mov	al, [sector_count]
   126                              <1> ;chs_read_sectors: ; read or write !
   127 00012035 B001                <1> 	mov	al, 1 ; 25/02/2016
   128 00012037 8A25[71850100]      <1> 	mov	ah, [disk_rw_op]  ; 02h = chs read, 03h = chs write 
   129                              <1> 	;
   130 0001203D E8832FFFFF          <1> 	call	int13h			; BIOS Service func ( ah ) = 2
   131                              <1>                                         ; Read disk sectors
   132                              <1>                                         ; AL-sec num CH-track CL-sec
   133                              <1>                                         ; DH-head DL-drive ES:BX-buffer
   134                              <1>                                         ; CF-flag AH-stat AL-sec read
   135                              <1> 	                                ; If CF = 1 then (If AH > 0)
   136 00012042 8825[73850100]      <1> 	mov	[disk_rw_err], ah
   137                              <1> 
   138 00012048 59                  <1> 	pop	ecx
   139 00012049 58                  <1> 	pop	eax
   140 0001204A 7314                <1> 	jnc	short chs_read_ok
   141                              <1> 
   142 0001204C 803D[73850100]09    <1> 	cmp	byte [disk_rw_err], 09h ; DMA crossed 64K segment boundary
   143 00012053 7408                <1> 	je	short chs_read_error_retn
   144                              <1> 
   145 00012055 FE0D[72850100]      <1> 	dec	byte [retry_count]
   146 0001205B 75B7                <1> 	jnz	short chs_read_retry
   147                              <1> 
   148                              <1> chs_read_error_retn:
   149 0001205D F9                  <1> 	stc
   150                              <1> 	;retn
   151 0001205E EB67                <1> 	jmp	short update_drv_error_byte
   152                              <1> 
   153                              <1> ;chs_write_sectors: ; read or write
   154                              <1> 	;; (# of sectors to read is less than remaining sectors on the track)
   155                              <1> 	;mov	[sector_count], al
   156                              <1> 	;jmp	short chs_read_sectors
   157                              <1> 
   158                              <1> chs_read_ok:
   159                              <1> 	;; 23/02/2016
   160                              <1> 	;movzx	edx, byte [sector_count] ; sector count (<= spt)
   161                              <1>         ;sub    ecx, edx  ; remaining sector count
   162                              <1> 	;jna	short update_drv_error_byte
   163                              <1> 	;add	eax, edx ; next disk sector
   164                              <1> 	;shl	edx, 9 ; 512 * sector count
   165                              <1> 	;add	ebx, edx ; next buffer byte address
   166                              <1>         ;jmp	chs_read_next_sector
   167                              <1> 	; 25/02/2016
   168 00012060 40                  <1> 	inc	eax ; next sector
   169 00012061 81C300020000        <1> 	add	ebx, 512
   170 00012067 E2A4                <1> 	loop	chs_read_next_sector
   171 00012069 EB5C                <1> 	jmp	short update_drv_error_byte
   172                              <1> 
   173                              <1> lba_write:
   174                              <1> 	; 23/02/2016
   175 0001206B C605[71850100]1C    <1> 	mov	byte [disk_rw_op], 1Ch ; LBA write
   176 00012072 EB07                <1> 	jmp	short lba_rw
   177                              <1> 
   178                              <1> lba_read:
   179                              <1> 	; 14/07/2022
   180                              <1> 	; 23/02/2016
   181                              <1> 	; 17/02/2016
   182                              <1> 	; 14/02/2016
   183                              <1> 	; 13/02/2016
   184                              <1> 	; 31/01/2016 (TRDOS 386 = TRDOS v2.0)
   185                              <1> 	; 10/07/2015 (Retro UNIX 386 v1)
   186                              <1> 	;
   187                              <1> 	; INPUT -> EAX = Logical Block Address
   188                              <1> 	;	   ESI = Logical Dos Disk Table Offset (DRV)
   189                              <1> 	;	   ECX = Sector Count	
   190                              <1> 	; 	   EBX = Destination Buffer
   191                              <1> 	; OUTPUT ->
   192                              <1> 	;	   cf = 0 or cf = 1
   193                              <1> 	; (Modified registers: EAX, EBX, ECX, EDX)
   194                              <1> 
   195                              <1> 	; LBA read/write (with private LBA function)
   196                              <1> 	;((Retro UNIX 386 v1 - DISK I/O code by Erdogan Tan))
   197                              <1> 
   198                              <1> 	; 23/02/2016
   199 00012074 C605[71850100]1B    <1> 	mov	byte [disk_rw_op], 1Bh ; LBA read
   200                              <1> 
   201                              <1> lba_rw:
   202                              <1> 	; 17/02/2016
   203 0001207B 57                  <1> 	push	edi
   204                              <1> 
   205 0001207C 890D[74850100]      <1> 	mov	[sector_count], ecx ; total sector (read) count
   206                              <1> 
   207 00012082 8A5602              <1> 	mov	dl, [esi+LD_PhyDrvNo]
   208                              <1> 	; dl = physical drive number (0, 1, 80h, 81h, 82h, 83h)
   209                              <1> 
   210                              <1> lba_read_next:
   211                              <1> 	; 14/07/2022
   212 00012085 BF00010000          <1> 	mov	edi, 256
   213 0001208A 39F9                <1> 	cmp	ecx, edi
   214                              <1> 	;cmp	ecx, 256
   215 0001208C 7602                <1> 	jna	short lba_read_rsc
   216                              <1> 	;mov	ecx, 256 ; 17/02/2016
   217 0001208E 89F9                <1> 	mov	ecx, edi
   218                              <1> lba_read_rsc:
   219 00012090 290D[74850100]      <1> 	sub	[sector_count], ecx ; remain sectors
   220                              <1> 
   221 00012096 89CF                <1> 	mov	edi, ecx 
   222 00012098 89C1                <1> 	mov	ecx, eax ; sector number/address
   223                              <1> 
   224 0001209A C605[72850100]04    <1> 	mov	byte [retry_count], 4
   225                              <1> lba_read_retry:
   226 000120A1 89F8                <1> 	mov	eax, edi
   227                              <1> 	;
   228                              <1> 	; ecx = sector number
   229                              <1> 	; al = sector count (0 - 255) /// (0 = 256)
   230                              <1> 	; dl = drive number
   231                              <1> 	; ebx = buffer offset
   232                              <1> 	;
   233                              <1> 	; Function 1Bh = LBA read, 1Ch = LBA write
   234                              <1> 	; 23/02/2016
   235 000120A3 8A25[71850100]      <1> 	mov	ah, [disk_rw_op] ; 1Bh = LBA read, 1Ch = LBA write
   236 000120A9 E8172FFFFF          <1> 	call	int13h
   237                              <1> 	; al = ? (changed)
   238                              <1> 	; ah = error code
   239 000120AE 8825[73850100]      <1> 	mov	[disk_rw_err], ah
   240 000120B4 7332                <1> 	jnc	short lba_read_ok
   241 000120B6 80FC80              <1> 	cmp	ah, 80h ; time out?
   242 000120B9 740A                <1>         je      short lba_read_stc_retn
   243 000120BB FE0D[72850100]      <1> 	dec	byte [retry_count]
   244 000120C1 7FDE                <1> 	jg	short lba_read_retry
   245 000120C3 7438                <1> 	jz	short lba_read_reset
   246                              <1> 	; sf = 1
   247                              <1> 
   248                              <1> lba_read_stc_retn:
   249 000120C5 F9                  <1> 	stc
   250                              <1> lba_read_retn:
   251 000120C6 5F                  <1> 	pop	edi
   252                              <1> 
   253                              <1> update_drv_error_byte:
   254 000120C7 9C                  <1> 	pushf
   255 000120C8 53                  <1> 	push	ebx
   256                              <1> 	;push	cx
   257 000120C9 51                  <1> 	push	ecx ; 14/07/2022
   258                              <1> 	;or	ecx, ecx
   259                              <1> 	;jz	short udrv_errb0
   260 000120CA 8A0D[73850100]      <1> 	mov	cl, [disk_rw_err]
   261                              <1> udrv_errb0:
   262 000120D0 0FB65E02            <1> 	movzx	ebx, byte [esi+LD_PhyDrvNo]
   263 000120D4 80FB02              <1> 	cmp	bl, 2
   264 000120D7 7203                <1>         jb      short udrv_errb1
   265 000120D9 80EB7E              <1> 	sub	bl, 7Eh
   266                              <1> 	;cmp	bl, 5
   267                              <1> 	;ja	short udrv_errb2
   268                              <1> udrv_errb1:
   269 000120DC 81C3[65660000]      <1>         add     ebx, drv.error ; 13/02/2016
   270 000120E2 880B                <1> 	mov	[ebx], cl ; error code
   271                              <1> udrv_errb2:
   272                              <1> 	;pop	cx
   273 000120E4 59                  <1> 	pop	ecx  ; 14/07/2022
   274 000120E5 5B                  <1> 	pop	ebx
   275 000120E6 9D                  <1> 	popf
   276 000120E7 C3                  <1> 	retn
   277                              <1> 
   278                              <1> lba_read_ok:
   279 000120E8 89C8                <1> 	mov	eax, ecx ; sector number
   280 000120EA 01F8                <1> 	add	eax, edi ; sector number (next)
   281 000120EC C1E709              <1> 	shl	edi, 9 ; sector count * 512
   282 000120EF 01FB                <1> 	add	ebx, edi ; next buffer offset
   283                              <1> 
   284 000120F1 8B0D[74850100]      <1> 	mov	ecx, [sector_count] ; remaining sectors
   285 000120F7 09C9                <1> 	or	ecx, ecx
   286 000120F9 758A                <1> 	jnz	short lba_read_next
   287 000120FB EBC9                <1> 	jmp	short lba_read_retn
   288                              <1> 
   289                              <1> lba_read_reset:
   290 000120FD B40D                <1> 	mov	ah, 0Dh ; Alternate reset
   291 000120FF E8C12EFFFF          <1>         call	int13h
   292                              <1> 	; al = ? (changed)
   293                              <1> 	; ah = error code
   294 00012104 739B                <1> 	jnc	short lba_read_retry
   295 00012106 EBBE                <1> 	jmp	short lba_read_retn
  3437                                  %include 'trdosk8.s' ; 24/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.9) - MAIN PROGRAM : trdosk8.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 29/12/2024  (Previous: 05/06/2024)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
    20                              <1> 	; 23/12/2016
    21                              <1> 	; 10/06/2016
    22                              <1> 	; 22/05/2016
    23                              <1> 	; 20/05/2016
    24                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
    25                              <1> 	; TRDOS 386 feature only !
    26                              <1> 	;
    27                              <1> 	; INPUT ->
    28                              <1> 	;	AL = process number (next process)
    29                              <1> 	;
    30                              <1> 	;	this process must be added to run sequence
    31                              <1> 	;
    32                              <1> 	;	[u.pri] = priority of present process
    33                              <1> 	;
    34                              <1> 	;	DL = priority (queue)
    35                              <1> 	;	     0 = background (low) ; run on background 
    36                              <1> 	;	     1 = regular (normal) ; run as regular
    37                              <1> 	;	     2 = event (high)     ; run for event
    38                              <1> 	;
    39                              <1> 	;	1) If the requested process is already running:
    40                              <1> 	;	   a) If present priority is high ([u.pri]=2) 
    41                              <1> 	;	      and requested priority is also high, 
    42                              <1> 	;	      there is nothing to do! Because it has been
    43                              <1> 	;	      done already (before this attempt).
    44                              <1> 	;	   b) If present priority is high ([u.pri]=2)
    45                              <1> 	;	      and requested priority is not high, there is
    46                              <1> 	;	      nothing to do! Because, it's current
    47                              <1> 	;	      run queue is unspecified, here. (It may be in
    48                              <1> 	;	      a waiting list or in a run queue; if the new
    49                              <1> 	;	      priority would be used to add it to relavant
    50                              <1>         ;             run queue, this would be wrong, unnecessary
    51                              <1> 	;	      and destabilizing duplication!)
    52                              <1> 	;	   c) If present priority is not high ([u.pri]<2)
    53                              <1>         ;             and requested priority is high (event),
    54                              <1> 	;	      process will be added to present priority's
    55                              <1> 	;	      run queue and then, priority will be changed
    56                              <1> 	;	      to high ([u.pri]=2).
    57                              <1> 	;	   d) If present priority is not high ([u.pri]<2)
    58                              <1> 	;	      and requested priority is not high, [u.pri]
    59                              <1> 	;	      value will be changed. There is nothing to do
    60                              <1> 	;	      in addition. (The new priority value will be
    61                              <1> 	;	      used by 'tswap/tswitch' procedure at 'sysret'
    62                              <1> 	;	      or 'sysrele' stage.)
    63                              <1> 	;
    64                              <1> 	;	2) If the requested process is not running:
    65                              <1> 	;	   a) If requested priority of the requested
    66                              <1> 	;	      (next) process is high (event) and priority
    67                              <1> 	;	      of present process is not high, the requested
    68                              <1> 	;	      process will be added to ('runq_event') high
    69                              <1> 	;	      priority run queue and then present (running)
    70                              <1> 	;	      process will be stopped (swapped/switched out)
    71                              <1> 	;	      immediately if it is in user mode, or it's
    72                              <1> 	;	      [u.quant] value will be reset to 0 and (then)
    73                              <1> 	;	      it will be stopped at 'sysret' stage.
    74                              <1> 	;	   b) If requested priority of the requested
    75                              <1> 	;	      (next) process is high (event) and priority
    76                              <1> 	;	      of present process is also high, the requested
    77                              <1> 	;	      process will be added to ('runq_event') high
    78                              <1> 	;	      priority run queue and present (running)
    79                              <1> 	;	      process will be allowed to run until it's
    80                              <1> 	;	      time quantum will be elapsed ([u.quant]=0).
    81                              <1> 	;	   c) If requested priority of the requested
    82                              <1> 	;	      (next) process is not high ('run for event'),
    83                              <1> 	;	      there is nothing to do. Because, it's current
    84                              <1> 	;	      run queue is unspecified, here. (It may be in
    85                              <1> 	;	      a waiting list or in a run queue; if the new
    86                              <1> 	;	      priority would be used to add it to relavant
    87                              <1>         ;             run queue, this would be wrong, unnecessary
    88                              <1> 	;	      and destabilizing duplication!)
    89                              <1> 	;
    90                              <1> 	; OUTPUT ->
    91                              <1> 	;	none
    92                              <1> 	;
    93                              <1> 	;	[u.pri] = priority of present process
    94                              <1> 	;
    95                              <1> 	;	cf = 1, if the request could not be fulfilled.
    96                              <1> 	;			 	     	  
    97                              <1> 	;	NOTE: 
    98                              <1>         ;          * Processes in 'run as regular' queue can run
    99                              <1> 	;	     if there is no process in 'run for event' queue
   100                              <1> 	;	     ('run for event' processes have higher priority)
   101                              <1> 	;	   * When [u.quant] time quantum of a process is
   102                              <1> 	;	     elapsed, it's high priority ('run for event')
   103                              <1> 	;	     status will be disabled, it can be run in sequence
   104                              <1> 	;	     of it's actual run queue.
   105                              <1> 	;	   * A 'run on background' process will always be
   106                              <1> 	;	     sequenced in 'run on background' (low priority)
   107                              <1> 	;	     queue, it can run only when other priority queues
   108                              <1> 	;	     are empty. (idle time processes, e.g. printing)
   109                              <1> 	;
   110                              <1> 	; Modified registers: eax, ebx, edx
   111                              <1> 	;
   112                              <1> 
   113                              <1> srunseq_0:
   114 00012108 3A05[C5940100]      <1>         cmp     al, [u.uno]     ; same process ?
   115 0001210E 750C                <1> 	jne	short srunseq_2 ; no
   116                              <1> 
   117 00012110 8A25[BE940100]      <1> 	mov	ah, [u.pri] 	; present/current priority
   118 00012116 80FC02              <1> 	cmp	ah, 2       	; 'run for event' priority level
   119 00012119 7220                <1> 	jb	short srunseq_6 ; no
   120                              <1> 
   121                              <1> srunseq_1:
   122                              <1> 	; there is nothing to do!
   123 0001211B C3                  <1> 	retn
   124                              <1> 
   125                              <1> srunseq_2:
   126                              <1> 	;;this not necessary ! 23/12/2016
   127                              <1>         ;;cmp	al, nproc	; number of processes = 16
   128                              <1> 	;;jnb	short srunseq_5	; error ! invalid process number
   129                              <1> 
   130                              <1> 	; dl = priority
   131 0001211C 80FA02              <1> 	cmp	dl, 2 		; event queue
   132 0001211F 72FA                <1> 	jb	short srunseq_1 ; requested process is not present
   133                              <1> 				; process and priority of requested
   134                              <1> 				; process is not high (event),
   135                              <1> 				; there is nothing to do!
   136                              <1> 	
   137                              <1> 	; requested process is not present process
   138                              <1> 	; & priority of requested process is high
   139 00012121 3A15[BE940100]      <1> 	cmp	dl, [u.pri] 	; priority of present process
   140 00012127 7606                <1> 	jna	short srunseq_3 ; is high, also
   141                              <1> 	;
   142                              <1> 	; present process will be swapped/switched out
   143 00012129 FE05[4D890100]      <1> 	inc	byte [p_change] ; 1
   144                              <1> 
   145                              <1> srunseq_3:
   146                              <1> 	; add process to 'runq_event' queue for new event
   147 0001212F BB[62940100]        <1> 	mov	ebx, runq_event ; high priority run queue
   148                              <1> 
   149                              <1> srunseq_4:
   150                              <1> 	; al = process number
   151                              <1> 	; ebx = run queue
   152                              <1> 	;call	putlu
   153                              <1> 	;retn
   154                              <1> 	; 29/07/2022
   155 00012134 E983EDFFFF          <1> 	jmp	putlu
   156                              <1> 
   157                              <1> srunseq_5:
   158 00012139 F5                  <1> 	cmc
   159 0001213A C3                  <1> 	retn
   160                              <1> 
   161                              <1> srunseq_6:
   162                              <1> 	; present priority of the process is not high
   163                              <1> 	
   164 0001213B 8815[BE940100]      <1> 	mov	[u.pri], dl ; new priority 
   165                              <1> 			    ; (will be used by 'tswap')
   166                              <1> 
   167 00012141 80FA02              <1> 	cmp	dl, 2 		; high priority ?
   168 00012144 72F3                <1> 	jb	short srunseq_5 ; no, there is nothing to do
   169                              <1> 				; in addition
   170                              <1> 
   171                              <1> 	; process must be added to relevant run queue, here!
   172                              <1> 	; (new priority is high/event priority and process
   173                              <1> 	; will not be added to a run queue by 'tswap')
   174                              <1> 
   175 00012146 BB[64940100]        <1> 	mov	ebx, runq_normal ; 'run as regular' queue
   176                              <1> 
   177 0001214B 20E4                <1> 	and	ah, ah  ;  previous value of [u.pri]
   178 0001214D 75E5                <1> 	jnz	short srunseq_4
   179                              <1> 
   180 0001214F 43                  <1> 	inc	ebx
   181 00012150 43                  <1> 	inc	ebx
   182                              <1> 	; ebx = runq_background ; 'run on backgroud' queue
   183                              <1> 
   184 00012151 EBE1                <1> 	jmp	short srunseq_4
   185                              <1> clock:
   186                              <1> 	; 21/08/2024 - TRDOS 386 v2.0.9
   187                              <1> 	; 23/05/2016
   188                              <1> 	; 22/05/2016
   189                              <1> 	; 20/05/2016
   190                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
   191                              <1> 	; 14/05/2015 - 14/10/2015 (Retro UNIX 386 v1)
   192                              <1> 	; 07/12/2013 - 10/04/2014 (Retro UNIX 8086 v1)
   193                              <1> 
   194                              <1> 	;;;
   195                              <1> 	; 21/08/2024
   196                              <1> 	;cmp	word [u.quit], 0FFFFh
   197 00012153 803D[C2940100]FF    <1> 	cmp	byte [u.quit], 0FFh
   198 0001215A 721A                <1> 	jb	short clk_0
   199                              <1> 	; CTRL+BRK keys pressed
   200                              <1> 	;cmp	word [u.intr], 0
   201 0001215C 803D[C0940100]00    <1> 	cmp	byte [u.intr], 0
   202 00012163 7611                <1> 	jna	short clk_0
   203 00012165 C605[4D890100]FF    <1> 	mov	byte [p_change], 0FFh ; -1 ; CTRL+BREAK sign
   204 0001216C F605[BC940100]FF    <1> 	test	byte [u.quant], 0FFh  ; if [u.quant] number > 0
   205 00012173 752D                <1> 	jnz	short clk_1 ; decrease [u.quant] number
   206                              <1> 	; [u.quant] = 0
   207 00012175 C3                  <1> 	retn
   208                              <1> 	;;;
   209                              <1> clk_0:
   210 00012176 803D[BC940100]00    <1> 	cmp	byte [u.quant], 0
   211 0001217D 7723                <1> 	ja	short clk_1
   212                              <1> 	;
   213 0001217F 803D[C5940100]01    <1> 	cmp     byte [u.uno], 1 ; /etc/init ? (for Retro UNIX 8086 & 386 v1)
   214                              <1> 				; MainProg (Kernel's Command Interpreter)
   215                              <1> 				; for TRDOS 386.
   216 00012186 761A                <1> 	jna	short clk_1 ; yes, do not swap out
   217                              <1> 	;
   218 00012188 803D[68940100]FF    <1> 	cmp     byte [sysflg], 0FFh ; user or system space ?
   219 0001218F 7517                <1> 	jne	short clk_2 	    ; system space (sysflg <> 0FFh)
   220                              <1> 	;
   221                              <1> 	; 21/08/2024
   222                              <1> 	;cmp	word [u.intr], 0
   223                              <1> 	;jna	short clk_2
   224                              <1> 	;
   225                              <1> 	; 23/05/2016
   226 00012191 803D[4E890100]00    <1> 	cmp	byte [multi_tasking], 0
   227 00012198 760E                <1> 	jna	short clk_2
   228                              <1> 
   229                              <1> 	; 21/08/2024
   230                              <1> 	;inc	byte [p_change] ; it is time to change running process
   231 0001219A C605[4D890100]01    <1> 	mov	byte [p_change], 1
   232 000121A1 C3                  <1> 	retn
   233                              <1> clk_1:
   234 000121A2 FE0D[BC940100]      <1> 	dec	byte [u.quant]
   235                              <1> clk_2:
   236 000121A8 C3                  <1> 	retn   ; return to (hardware) timer interrupt routine
   237                              <1> 
   238                              <1> ; 12/10/2017
   239                              <1> ; 15/01/2017
   240                              <1> ; 14/01/2017
   241                              <1> ; 07/01/2017
   242                              <1> ; 02/01/2017
   243                              <1> ; 17/08/2016
   244                              <1> ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   245                              <1> int34h: ; #IOCTL# (I/O port access support for ring 3)
   246                              <1> 	;
   247                              <1> 	; 23/05/2016
   248                              <1> 	; 20/06/2016
   249                              <1> 	; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
   250                              <1> 	;
   251                              <1> 	; INPUT ->
   252                              <1> 	;	AH = 0 -> read port  (physical IO port) -byte-
   253                              <1> 	;	AH = 1 -> write port (physical IO port) -byte-
   254                              <1> 	;		AL = data byte
   255                              <1> 	;	AH = 2 -> read port  (physical IO port) -word-
   256                              <1> 	;	AH = 3 -> write port (physical IO port) -word-
   257                              <1> 	;		BX = data word
   258                              <1> 	;	AH = 4 -> read port  (physical IO port) -dword-
   259                              <1> 	;	AH = 5 -> write port (physical IO port) -dword-
   260                              <1> 	;		EBX = data dword
   261                              <1> 	;	; 12/10/2017
   262                              <1> 	;	AH = 6 -> read port (physical IO port) twice -byte-
   263                              <1> 	;	AH = 7 -> write port (physical IO port) twice -byte-
   264                              <1> 	;		BX = data word	
   265                              <1> 	;
   266                              <1> 	;	DX = Port number (<= 0FFFFh)
   267                              <1> 	;
   268                              <1> 	; OUTPUT ->
   269                              <1> 	;	AL = data byte (in al, dx)
   270                              <1> 	;	AX = data word (in ax, dx)
   271                              <1> 	;	EAX = data dword (in eax, dx)
   272                              <1> 	;
   273                              <1> 	;	(ECX = actual TRANSFER COUNT for string functions)
   274                              <1> 	;
   275                              <1> 	;
   276                              <1> 	; Modified registers: EAX
   277                              <1> 	;
   278                              <1> 
   279                              <1> 	;cmp	ah, 5
   280                              <1> 	;ja	short int34h_5 ; invalid function !
   281                              <1> 
   282                              <1> 	; 12/10/2017
   283 000121A9 80FC07              <1> 	cmp	ah, 7
   284 000121AC 7743                <1> 	ja	short int34h_5 ; invalid function !
   285                              <1> 
   286                              <1> 	;; 15/01/2017
   287                              <1> 	; 14/01/2017
   288                              <1> 	; 02/01/2017
   289                              <1> 	;;mov	byte [ss:intflg], 34h	; IOCTL interrupt
   290 000121AE FB                  <1> 	sti
   291                              <1> 	
   292                              <1> 	;sti	; enable interrupts
   293 000121AF 80642408FE          <1> 	and	byte [esp+8], 11111110b	; clear carry bit of eflags register
   294                              <1> 
   295 000121B4 80FC01              <1> 	cmp	ah, 1
   296 000121B7 7205                <1> 	jb	short int34h_0
   297 000121B9 7705                <1> 	ja	short int34h_1
   298                              <1> 
   299 000121BB EE                  <1> 	out	dx, al
   300                              <1> 	;iretd
   301 000121BC EB01                <1> 	jmp	short int34h_iret
   302                              <1> 
   303                              <1> int34h_0:
   304 000121BE EC                  <1> 	in	al, dx
   305                              <1> 	;iretd
   306                              <1> int34h_iret:
   307                              <1> 	;cli	; 07/01/2017
   308                              <1> 	;; 15/01/2017
   309                              <1> 	;;mov	byte [ss:intflg], 0 ; reset
   310 000121BF CF                  <1> 	iretd 
   311                              <1> 
   312                              <1> int34h_1:
   313 000121C0 F6C401              <1> 	test	ah, 1
   314 000121C3 7516                <1> 	jnz	short int34h_3 ; out
   315                              <1> 
   316                              <1> 	; in
   317 000121C5 80FC02              <1> 	cmp	ah, 2
   318 000121C8 7707                <1> 	ja	short int34h_2
   319                              <1> 
   320 000121CA 6689D8              <1> 	mov	ax, bx
   321 000121CD 66ED                <1> 	in	ax, dx
   322                              <1> 	;iretd
   323 000121CF EBEE                <1> 	jmp	short int34h_iret
   324                              <1> 
   325                              <1> int34h_2:
   326 000121D1 80FC04              <1> 	cmp	ah, 4
   327 000121D4 772C                <1> 	ja	short int34h_7	; 12/10/2017
   328                              <1> 	; ah = 4
   329 000121D6 89D8                <1> 	mov	eax, ebx
   330 000121D8 ED                  <1> 	in	eax, dx
   331                              <1> 	;iretd
   332 000121D9 EBE4                <1> 	jmp	short int34h_iret
   333                              <1> 
   334                              <1> int34h_3:
   335 000121DB 80FC03              <1> 	cmp	ah, 3
   336 000121DE 7707                <1> 	ja	short int34h_4
   337                              <1> 
   338 000121E0 6689D8              <1> 	mov	ax, bx
   339 000121E3 66EF                <1> 	out	dx, ax
   340                              <1> 	;iretd
   341 000121E5 EBD8                <1> 	jmp	short int34h_iret
   342                              <1> 
   343                              <1> int34h_4:
   344 000121E7 80FC05              <1> 	cmp	ah, 5
   345 000121EA 770B                <1> 	ja	short int34h_6	; 12/10/2017
   346                              <1> 	; ah = 5
   347 000121EC 89D8                <1> 	mov	eax, ebx
   348 000121EE EF                  <1> 	out	dx, eax
   349                              <1> 	;iretd
   350 000121EF EBCE                <1> 	jmp	short int34h_iret
   351                              <1> 
   352                              <1> int34h_5:
   353 000121F1 804C240801          <1> 	or	byte [esp+8], 1	; set carry bit of eflags register
   354 000121F6 CF                  <1> 	iretd
   355                              <1> 
   356                              <1> 	; 12/10/2017
   357                              <1> int34h_6:
   358 000121F7 6689D8              <1> 	mov	ax, bx
   359 000121FA EE                  <1> 	out	dx, al
   360 000121FB EB00                <1> 	jmp	short $+2
   361 000121FD 86C4                <1> 	xchg	ah, al
   362 000121FF EE                  <1> 	out	dx, al
   363                              <1> 	;xchg	al, ah
   364                              <1> 	;iretd
   365 00012200 EB06                <1> 	jmp	short int34h_8
   366                              <1> int34h_7:
   367 00012202 EC                  <1> 	in	al, dx
   368 00012203 EB00                <1> 	jmp	short $+2
   369 00012205 88C4                <1> 	mov	ah, al
   370 00012207 EC                  <1> 	in	al, dx
   371                              <1> int34h_8:
   372 00012208 86E0                <1> 	xchg	al, ah
   373 0001220A CF                  <1> 	iretd
   374                              <1> 
   375                              <1> INT4Ah:
   376                              <1> 	; 24/01/2016
   377                              <1> 	; this procedure will be called by 'RTC_INT' (in 'timer.s')
   378 0001220B C3                  <1> 	retn
   379                              <1> 
   380                              <1> ; u0.s
   381                              <1> ; Retro UNIX 386 v1 Kernel (v0.2) - SYS0.INC
   382                              <1> ; Last Modification: 20/11/2015
   383                              <1> 
   384                              <1> com2_int:
   385                              <1> 	; 07/11/2015 
   386                              <1> 	; 24/10/2015
   387                              <1> 	; 23/10/2015
   388                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - Beginning)
   389                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1)
   390                              <1> 	; < serial port 2 interrupt handler >
   391                              <1> 	;
   392 0001220C 890424              <1> 	mov 	[esp], eax ; overwrite call return address
   393                              <1> 	;push	eax
   394 0001220F 66B80900            <1> 	mov	ax, 9
   395 00012213 EB07                <1> 	jmp	short comm_int
   396                              <1> com1_int:
   397                              <1> 	; 07/11/2015
   398                              <1> 	; 24/10/2015
   399 00012215 890424              <1> 	mov 	[esp], eax ; overwrite call return address
   400                              <1> 	; 23/10/2015
   401                              <1> 	;push	eax
   402 00012218 66B80800            <1> 	mov	ax, 8
   403                              <1> comm_int:
   404                              <1> 	; 20/11/2015
   405                              <1> 	; 18/11/2015
   406                              <1> 	; 17/11/2015
   407                              <1> 	; 16/11/2015
   408                              <1> 	; 09/11/2015
   409                              <1> 	; 08/11/2015
   410                              <1> 	; 07/11/2015
   411                              <1> 	; 06/11/2015 (serial4.asm, 'serial')
   412                              <1> 	; 01/11/2015
   413                              <1> 	; 26/10/2015
   414                              <1> 	; 23/10/2015
   415 0001221C 53                  <1> 	push	ebx
   416 0001221D 56                  <1> 	push	esi
   417 0001221E 57                  <1> 	push	edi
   418 0001221F 1E                  <1> 	push 	ds
   419 00012220 06                  <1> 	push 	es
   420                              <1> 	; 18/11/2015
   421 00012221 0F20DB              <1> 	mov	ebx, cr3
   422 00012224 53                  <1> 	push	ebx ; ****
   423                              <1> 	;
   424 00012225 51                  <1> 	push	ecx ; ***
   425 00012226 52                  <1> 	push	edx ; **
   426                              <1> 	;
   427 00012227 BB10000000          <1> 	mov	ebx, KDATA
   428 0001222C 8EDB                <1> 	mov	ds, bx
   429 0001222E 8EC3                <1> 	mov	es, bx
   430                              <1> 	;
   431 00012230 8B0D[C07C0100]      <1> 	mov	ecx, [k_page_dir]
   432 00012236 0F22D9              <1> 	mov	cr3, ecx
   433                              <1> 	; 20/11/2015
   434                              <1> 	; Interrupt identification register
   435 00012239 66BAFA02            <1> 	mov	dx, 2FAh ; COM2
   436                              <1> 	;
   437 0001223D 3C08                <1> 	cmp 	al, 8 
   438 0001223F 7702                <1> 	ja 	short com_i0
   439                              <1> 	;
   440                              <1> 	; 20/11/2015
   441                              <1> 	; 17/11/2015
   442                              <1> 	; 16/11/2015
   443                              <1> 	; 15/11/2015
   444                              <1> 	; 24/10/2015
   445                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - Beginning)
   446                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1)
   447                              <1> 	; < serial port 1 interrupt handler >
   448                              <1> 	;
   449 00012241 FEC6                <1> 	inc	dh ; 3FAh ; COM1 Interrupt id. register
   450                              <1> com_i0:
   451                              <1> 	;push	eax ; *
   452                              <1> 	; 07/11/2015
   453 00012243 A2[2A7D0100]        <1> 	mov 	byte [ccomport], al
   454                              <1> 	; 09/11/2015
   455 00012248 0FB7D8              <1> 	movzx	ebx, ax ; 8 or 9
   456                              <1> 	; 17/11/2015
   457                              <1>  	; reset request for response status
   458 0001224B 88A3[207D0100]      <1> 	mov	[ebx+req_resp-8], ah ; 0
   459                              <1> 	;
   460                              <1> 	; 20/11/2015
   461 00012251 EC                  <1> 	in	al, dx		; read interrupt id. register
   462 00012252 EB00                <1> 	JMP	$+2	   	; I/O DELAY
   463 00012254 2404                <1> 	and	al, 4		; received data available?
   464 00012256 7470                <1> 	jz	short com_eoi	; (transmit. holding reg. empty)
   465                              <1> 	;
   466                              <1> 	; 20/11/2015
   467 00012258 80EA02              <1> 	sub	dl, 3FAh-3F8h	; data register (3F8h, 2F8h)
   468 0001225B EC                  <1> 	in	al, dx     	; read character
   469                              <1> 	;JMP	$+2	   	; I/O DELAY
   470                              <1> 	; 08/11/2015
   471                              <1> 	; 07/11/2015
   472 0001225C 89DE                <1> 	mov	esi, ebx 
   473 0001225E 89DF                <1> 	mov	edi, ebx
   474 00012260 81C6[247D0100]      <1> 	add 	esi, rchar - 8 ; points to last received char
   475 00012266 81C7[267D0100]      <1> 	add	edi, schar - 8 ; points to last sent char
   476 0001226C 8806                <1> 	mov	[esi], al ; received char (current char)
   477                              <1> 	; query
   478 0001226E 20C0                <1> 	and	al, al
   479 00012270 7527                <1> 	jnz	short com_i2
   480                              <1>    	; response
   481                              <1> 	; 17/11/2015
   482                              <1> 	; set request for response status
   483 00012272 FE83[207D0100]      <1>         inc     byte [ebx+req_resp-8] ; 1
   484                              <1> 	;
   485 00012278 6683C205            <1> 	add	dx, 3FDh-3F8h	; (3FDh, 2FDh)
   486 0001227C EC                  <1> 	in	al, dx	   	; read line status register
   487 0001227D EB00                <1> 	JMP	$+2	   	; I/O DELAY
   488 0001227F 2420                <1> 	and	al, 20h	   	; transmitter holding reg. empty?
   489 00012281 7445                <1> 	jz	short com_eoi 	; no
   490 00012283 B0FF                <1> 	mov 	al, 0FFh   	; response
   491 00012285 6683EA05            <1> 	sub	dx, 3FDh-3F8h 	; data port (3F8h, 2F8h)
   492 00012289 EE                  <1> 	out	dx, al	   	; send on serial port
   493                              <1> 	; 17/11/2015
   494 0001228A 803F00              <1> 	cmp 	byte [edi], 0   ; query ? (schar)
   495 0001228D 7502                <1> 	jne 	short com_i1    ; no
   496 0001228F 8807                <1> 	mov	[edi], al 	; 0FFh (responded)
   497                              <1> com_i1:
   498                              <1> 	; 17/11/2015
   499                              <1> 	; reset request for response status (again)
   500 00012291 FE8B[207D0100]      <1>         dec     byte [ebx+req_resp-8] ; 0 
   501 00012297 EB2F                <1> 	jmp	short com_eoi
   502                              <1> com_i2:	
   503                              <1> 	; 08/11/2015
   504 00012299 3CFF                <1> 	cmp 	al, 0FFh	; (response ?)
   505 0001229B 7417                <1> 	je	short com_i3	; (check for response signal)
   506                              <1> 	; 07/11/2015
   507 0001229D 3C04                <1> 	cmp	al, 04h	; EOT
   508 0001229F 751C                <1> 	jne	short com_i4	
   509                              <1> 	; EOT = 04h (End of Transmit) - 'CTRL + D'
   510                              <1> 	;(an EOT char is supposed as a ctrl+brk from the terminal)
   511                              <1> 	; 08/11/2015
   512                              <1> 		; ptty -> tty 0 to 7 (pseudo screens)
   513 000122A1 861D[EE7C0100]      <1> 	xchg	bl, [ptty]  ; tty number (8 or 9)
   514 000122A7 E8424BFFFF          <1> 	call 	ctrlbrk
   515 000122AC 861D[EE7C0100]      <1> 	xchg	[ptty], bl ; (restore ptty value and BL value)
   516                              <1> 	;mov	al, 04h ; EOT
   517                              <1> 	; 08/11/2015
   518 000122B2 EB09                <1> 	jmp	short com_i4	
   519                              <1> com_i3:
   520                              <1> 	; 08/11/2015
   521                              <1> 	; If 0FFh has been received just after a query
   522                              <1> 	; (schar, ZERO), it is a response signal.
   523                              <1> 	; 17/11/2015
   524 000122B4 803F00              <1>         cmp     byte [edi], 0 ; query ? (schar)
   525 000122B7 7704                <1> 	ja	short com_i4 ; no
   526                              <1> 	; reset query status (schar)
   527 000122B9 8807                <1> 	mov	[edi], al ; 0FFh
   528 000122BB FEC0                <1> 	inc	al ; 0
   529                              <1> com_i4:
   530                              <1> 	; 27/07/2014
   531                              <1> 	; 09/07/2014
   532 000122BD D0E3                <1> 	shl	bl, 1
   533 000122BF 81C3[F07C0100]      <1> 	add	ebx, ttychr
   534                              <1> 	; 23/07/2014 (always overwrite)
   535                              <1> 	;;cmp	word [ebx], 0
   536                              <1> 	;;ja	short com_eoi
   537                              <1> 	;
   538 000122C5 668903              <1> 	mov	[ebx], ax   ; Save ascii code
   539                              <1> 			    ; scan code = 0
   540                              <1> com_eoi:
   541                              <1> 	;mov	al, 20h
   542                              <1> 	;out	20h, al	   ; end of interrupt
   543                              <1> 	;
   544                              <1> 	; 07/11/2015
   545                              <1>       	;pop	eax ; *
   546 000122C8 A0[2A7D0100]        <1> 	mov	al, byte [ccomport] ; current COM port
   547                              <1> 	 ; al = tty number (8 or 9)
   548 000122CD E80F000000          <1>         call	wakeup
   549                              <1> com_iret:
   550                              <1> 	; 23/10/2015
   551 000122D2 5A                  <1> 	pop	edx ; **
   552 000122D3 59                  <1> 	pop	ecx ; ***
   553                              <1> 	; 18/11/2015
   554                              <1> 	;pop	eax ; ****
   555                              <1> 	;mov	cr3, eax
   556                              <1> 	;jmp	iiret
   557 000122D4 E90BEBFEFF          <1> 	jmp	iiretp
   558                              <1> 
   559                              <1> ;iiretp: ; 01/09/2015
   560                              <1> ;	; 28/08/2015
   561                              <1> ;	pop	eax ; (*) page directory
   562                              <1> ;	mov	cr3, eax
   563                              <1> ;iiret:
   564                              <1> ;	; 22/08/2014
   565                              <1> ;	mov	al, 20h ; END OF INTERRUPT COMMAND TO 8259
   566                              <1> ;	out	20h, al	; 8259 PORT
   567                              <1> ;	;
   568                              <1> ;	pop	es
   569                              <1> ;	pop	ds
   570                              <1> ;	pop	edi
   571                              <1> ;	pop	esi
   572                              <1> ;	pop	ebx ; 29/08/2014
   573                              <1> ;	pop 	eax
   574                              <1> ;	iretd
   575                              <1> 
   576                              <1> ; 21/11/2023
   577                              <1> %if 0
   578                              <1> 
   579                              <1> sp_init:
   580                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
   581                              <1> 	; 07/11/2015
   582                              <1> 	; 29/10/2015
   583                              <1> 	; 26/10/2015
   584                              <1> 	; 23/10/2015
   585                              <1> 	; 29/06/2015
   586                              <1> 	; 14/03/2015 (Retro UNIX 386 v1 - 115200 baud)
   587                              <1> 	; 28/07/2014 (Retro UNIX 8086 v1 - 9600 baud)
   588                              <1> 	; Initialization of Serial Port Communication Parameters
   589                              <1> 	; (COM1 base port address = 3F8h, COM1 Interrupt = IRQ 4)
   590                              <1> 	; (COM2 base port address = 2F8h, COM1 Interrupt = IRQ 3)
   591                              <1> 	;
   592                              <1> 	; ((Modified registers: EAX, ECX, EDX, EBX))
   593                              <1> 	;
   594                              <1> 	; INPUT:  (29/06/2015)
   595                              <1> 	;	AL = 0 for COM1
   596                              <1> 	;	     1 for COM2
   597                              <1> 	;	AH = Communication parameters	
   598                              <1> 	;
   599                              <1> 	;  (*) Communication parameters (except BAUD RATE):
   600                              <1> 	;	Bit	4	3	2	1	0
   601                              <1> 	;		-PARITY--   STOP BIT  -WORD LENGTH-
   602                              <1> 	;  this one -->	00 = none    0 = 1 bit  11 = 8 bits
   603                              <1> 	;		01 = odd     1 = 2 bits	10 = 7 bits
   604                              <1> 	;		11 = even
   605                              <1> 	;  Baud rate setting bits: (29/06/2015)
   606                              <1> 	;		Retro UNIX 386 v1 feature only !
   607                              <1> 	;	Bit	7    6    5  | Baud rate
   608                              <1> 	;		------------------------
   609                              <1> 	;	value	0    0    0  | Default (Divisor = 1)
   610                              <1> 	;		0    0    1  | 9600 (12)
   611                              <1> 	;		0    1    0  | 19200 (6)
   612                              <1> 	;		0    1	  1  | 38400 (3)
   613                              <1> 	;		1    0	  0  | 14400 (8)
   614                              <1> 	;		1    0	  1  | 28800 (4)
   615                              <1> 	;		1    1    0  | 57600 (2)
   616                              <1> 	;		1    1    1  | 115200 (1)
   617                              <1> 	
   618                              <1> 	; References:	
   619                              <1> 	; (1) IBM PC-XT Model 286 BIOS Source Code
   620                              <1> 	;     RS232.ASM --- 10/06/1985 COMMUNICATIONS BIOS (RS232)
   621                              <1> 	; (2) Award BIOS 1999 - ATORGS.ASM
   622                              <1> 	; (3) http://wiki.osdev.org/Serial_Ports
   623                              <1> 	;
   624                              <1> 	; Set communication parameters for COM1 (= 03h)
   625                              <1> 	;
   626                              <1> 	mov	ebx, com1p		; COM1 parameters
   627                              <1> 	mov	dx, 3F8h		; COM1
   628                              <1> 	 ; 29/10/2015
   629                              <1> 	mov	cx, 301h  ; divisor = 1 (115200 baud)
   630                              <1> 	call	sp_i3	; call A4
   631                              <1> 	test	al, 80h
   632                              <1> 	jz	short sp_i0 ; OK..
   633                              <1> 		; Error !
   634                              <1> 	;mov	dx, 3F8h
   635                              <1> 	sub	dl, 5 ; 3FDh -> 3F8h
   636                              <1> 	mov	cx, 30Eh  ; divisor = 12 (9600 baud)
   637                              <1> 	call	sp_i3	; call A4
   638                              <1> 	test	al, 80h
   639                              <1> 	jnz	short sp_i1
   640                              <1> sp_i0:
   641                              <1>         ; (Note: Serial port interrupts will be disabled here...)
   642                              <1>         ; (INT 14h initialization code disables interrupts.)
   643                              <1> 	;
   644                              <1> 	mov	byte [ebx], 0E3h ; 11100011b
   645                              <1> 	call	sp_i5 ; 29/06/2015
   646                              <1> sp_i1:
   647                              <1> 	inc	ebx
   648                              <1> 	mov	dx, 2F8h		; COM2
   649                              <1> 	 ; 29/10/2015
   650                              <1> 	mov	cx, 301h  ; divisor = 1 (115200 baud)
   651                              <1> 	call	sp_i3	; call A4
   652                              <1> 	test	al, 80h
   653                              <1> 	jz	short sp_i2 ; OK..
   654                              <1> 		; Error !
   655                              <1> 	;mov	dx, 2F8h
   656                              <1> 	sub	dl, 5 ; 2FDh -> 2F8h
   657                              <1> 	mov	cx, 30Eh  ; divisor = 12 (9600 baud)
   658                              <1> 	call	sp_i3	; call A4
   659                              <1> 	test	al, 80h
   660                              <1> 	jnz	short sp_i7
   661                              <1> sp_i2:
   662                              <1> 	mov	byte [ebx], 0E3h ; 11100011b
   663                              <1> sp_i6:
   664                              <1> 	;; COM2 - enabling IRQ 3
   665                              <1> 	; 29/07/2022
   666                              <1> 	; 07/11/2015
   667                              <1> 	; 26/10/2015
   668                              <1> 	pushf
   669                              <1> 	cli
   670                              <1> 	;
   671                              <1> 	mov	dx, 2FCh   		; modem control register
   672                              <1> 	in	al, dx 	   		; read register
   673                              <1> 	JMP	$+2	   		; I/O DELAY
   674                              <1> 	or	al, 8      		; enable bit 3 (OUT2)
   675                              <1> 	out	dx, al     		; write back to register
   676                              <1> 	JMP	$+2	   		; I/O DELAY
   677                              <1> 	;mov	dx, 2F9h   		; interrupt enable register
   678                              <1> 	; 29/07/2022
   679                              <1> 	mov	dl, 0F9h
   680                              <1> 	in	al, dx     		; read register
   681                              <1> 	JMP	$+2	   		; I/O DELAY
   682                              <1> 	;or	al, 1      		; receiver data interrupt enable and
   683                              <1> 	or	al, 3	   		; transmitter empty interrupt enable
   684                              <1> 	out	dx, al 	   		; write back to register
   685                              <1> 	JMP	$+2        		; I/O DELAY
   686                              <1> 	in	al, 21h    		; read interrupt mask register
   687                              <1> 	JMP	$+2	   		; I/O DELAY
   688                              <1> 	and	al, 0F7h   		; enable IRQ 3 (COM2)
   689                              <1> 	out	21h, al    		; write back to register
   690                              <1> 	;
   691                              <1> 	; 23/10/2015
   692                              <1> 	mov 	eax, com2_int
   693                              <1> 	mov	[com2_irq3], eax
   694                              <1> 	; 26/10/2015
   695                              <1> 	popf	
   696                              <1> sp_i7:
   697                              <1> 	retn
   698                              <1> 
   699                              <1> sp_i3:
   700                              <1> ;A4:  	;-----	INITIALIZE THE COMMUNICATIONS PORT
   701                              <1> 	; 28/10/2015
   702                              <1> 	inc	dl	; 3F9h (2F9h)	; 3F9h, COM1 Interrupt enable register 
   703                              <1> 	mov	al, 0
   704                              <1> 	out	dx, al			; disable serial port interrupt
   705                              <1> 	JMP	$+2			; I/O DELAY
   706                              <1> 	add	dl, 2 	; 3FBh (2FBh)	; COM1 Line control register (3FBh)
   707                              <1> 	mov	al, 80h			
   708                              <1> 	out	dx, al			; SET DLAB=1 ; divisor latch access bit
   709                              <1> 	;-----	SET BAUD RATE DIVISOR
   710                              <1> 	; 26/10/2015
   711                              <1> 	sub 	dl, 3   ; 3F8h (2F8h)	; register for least significant byte
   712                              <1> 					; of the divisor value
   713                              <1> 	mov	al, cl	; 1
   714                              <1> 	out	dx, al			; 1 = 115200 baud (Retro UNIX 386 v1)
   715                              <1> 					; 2 = 57600 baud
   716                              <1> 					; 3 = 38400 baud
   717                              <1> 					; 6 = 19200 baud
   718                              <1> 					; 12 = 9600 baud (Retro UNIX 8086 v1)
   719                              <1> 	JMP	$+2			; I/O DELAY
   720                              <1> 	sub	al, al
   721                              <1> 	inc	dl      ; 3F9h (2F9h)	; register for most significant byte
   722                              <1> 					; of the divisor value
   723                              <1> 	out	dx, al ; 0
   724                              <1> 	JMP	$+2			; I/O DELAY
   725                              <1> 	;	
   726                              <1> 	mov	al, ch ; 3		; 8 data bits, 1 stop bit, no parity
   727                              <1> 	;and	al, 1Fh ; Bits 0,1,2,3,4	
   728                              <1> 	add	dl, 2	; 3FBh (2FBh)	; Line control register
   729                              <1> 	out	dx, al
   730                              <1> 	JMP	$+2			; I/O DELAY
   731                              <1> 	; 29/10/2015
   732                              <1> 	dec 	dl 	; 3FAh (2FAh)	; FIFO Control register (16550/16750)
   733                              <1> 	xor	al, al			; 0
   734                              <1> 	out	dx, al			; Disable FIFOs (reset to 8250 mode)
   735                              <1> 	JMP	$+2	
   736                              <1> sp_i4:
   737                              <1> ;A18:	;-----	COMM PORT STATUS ROUTINE
   738                              <1> 	; 29/06/2015 (line status after modem status)
   739                              <1> 	add	dl, 4	; 3FEh (2FEh)	; Modem status register
   740                              <1> sp_i4s:
   741                              <1> 	in	al, dx			; GET MODEM CONTROL STATUS
   742                              <1> 	JMP	$+2			; I/O DELAY
   743                              <1> 	mov	ah, al			; PUT IN (AH) FOR RETURN
   744                              <1> 	dec	dl	; 3FDh (2FDh)	; POINT TO LINE STATUS REGISTER
   745                              <1> 					; dx = 3FDh for COM1, 2FDh for COM2
   746                              <1> 	in	al, dx			; GET LINE CONTROL STATUS
   747                              <1> 	; AL = Line status, AH = Modem status
   748                              <1> 	retn
   749                              <1> 
   750                              <1> sp_status:
   751                              <1> 	; 29/06/2015
   752                              <1> 	; 27/06/2015 (Retro UNIX 386 v1)
   753                              <1> 	; Get serial port status
   754                              <1> 	mov	dx, 3FEh		; Modem status register (COM1)
   755                              <1> 	sub	dh, al			; dh = 2 for COM2 (al = 1)
   756                              <1> 					; dx = 2FEh for COM2
   757                              <1> 	jmp	short sp_i4s
   758                              <1> 
   759                              <1> sp_setp: ; Set serial port communication parameters
   760                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
   761                              <1> 	; 07/11/2015
   762                              <1> 	; 29/10/2015
   763                              <1> 	; 29/06/2015
   764                              <1> 	; Retro UNIX 386 v1 feature only !
   765                              <1> 	;
   766                              <1> 	; INPUT:
   767                              <1> 	;	AL = 0 for COM1
   768                              <1> 	;	     1 for COM2
   769                              <1> 	;	AH = Communication parameters (*)
   770                              <1> 	; OUTPUT:
   771                              <1> 	;	CL = Line status
   772                              <1> 	;	CH = Modem status
   773                              <1> 	;   If cf = 1 -> Error code in [u.error]
   774                              <1> 	;		 'invalid parameter !'
   775                              <1> 	;		 	 or
   776                              <1> 	;		 'device not ready !' error
   777                              <1> 	;	
   778                              <1> 	;  (*) Communication parameters (except BAUD RATE):
   779                              <1> 	;	Bit	4	3	2	1	0
   780                              <1> 	;		-PARITY--   STOP BIT  -WORD LENGTH-
   781                              <1> 	;  this one -->	00 = none    0 = 1 bit  11 = 8 bits
   782                              <1> 	;		01 = odd     1 = 2 bits	10 = 7 bits
   783                              <1> 	;		11 = even
   784                              <1> 	;  Baud rate setting bits: (29/06/2015)
   785                              <1> 	;		Retro UNIX 386 v1 feature only !
   786                              <1> 	;	Bit	7    6    5  | Baud rate
   787                              <1> 	;		------------------------
   788                              <1> 	;	value	0    0    0  | Default (Divisor = 1)
   789                              <1> 	;		0    0    1  | 9600 (12)
   790                              <1> 	;		0    1    0  | 19200 (6) 
   791                              <1> 	;		0    1	  1  | 38400 (3) 
   792                              <1> 	;		1    0	  0  | 14400 (8)
   793                              <1> 	;		1    0	  1  | 28800 (4)
   794                              <1> 	;		1    1    0  | 57600 (2)
   795                              <1> 	;		1    1    1  | 115200 (1) 
   796                              <1> 	;
   797                              <1> 	; (COM1 base port address = 3F8h, COM1 Interrupt = IRQ 4)
   798                              <1> 	; (COM2 base port address = 2F8h, COM1 Interrupt = IRQ 3)
   799                              <1> 	;
   800                              <1> 	; ((Modified registers: EAX, ECX, EDX, EBX))
   801                              <1> 	;
   802                              <1> 	mov	dx, 3F8h
   803                              <1> 	mov	ebx, com1p ; COM1 control byte offset
   804                              <1> 	cmp	al, 1
   805                              <1> 	ja 	short sp_invp_err
   806                              <1> 	jb	short sp_setp1 ;  COM1 (AL = 0)
   807                              <1> 	dec	dh ; 2F8h
   808                              <1> 	inc	ebx ; COM2 control byte offset
   809                              <1> sp_setp1:
   810                              <1> 	; 29/10/2015
   811                              <1> 	mov	[ebx], ah
   812                              <1> 	movzx 	ecx, ah
   813                              <1> 	shr	cl, 5 ; -> baud rate index
   814                              <1> 	and	ah, 1Fh ; communication parameters except baud rate
   815                              <1> 	mov	al, [ecx+b_div_tbl]
   816                              <1> 	mov	cx, ax
   817                              <1> 	call	sp_i3
   818                              <1> 	mov	cx, ax ; CL = Line status, CH = Modem status
   819                              <1> 	test	al, 80h
   820                              <1> 	jz	short sp_setp2
   821                              <1>         mov     byte [ebx], 0E3h ; Reset to initial value (11100011b)
   822                              <1> stp_dnr_err:
   823                              <1> 	mov	dword [u.error], ERR_DEV_NOT_RDY ; 'device not ready !'
   824                              <1> 	; CL = Line status, CH = Modem status
   825                              <1> 	stc
   826                              <1> 	retn
   827                              <1> sp_setp2:
   828                              <1> 	cmp	dh, 2 ; COM2 (2F?h)
   829                              <1> 	;jna	sp_i6
   830                              <1> 		      ; COM1 (3F?h)
   831                              <1> 	; 29/07/2022
   832                              <1> 	ja	short sp_i5
   833                              <1> 	jmp	sp_i6
   834                              <1> sp_i5: 
   835                              <1> 	; 29/07/2022
   836                              <1> 	; 07/11/2015
   837                              <1> 	; 26/10/2015
   838                              <1> 	; 29/06/2015
   839                              <1> 	;
   840                              <1> 	;; COM1 - enabling IRQ 4
   841                              <1> 	pushf
   842                              <1> 	cli
   843                              <1> 	mov	dx, 3FCh   		; modem control register
   844                              <1> 	in	al, dx 	   		; read register
   845                              <1> 	JMP	$+2			; I/O DELAY
   846                              <1> 	or	al, 8      		; enable bit 3 (OUT2)
   847                              <1> 	out	dx, al     		; write back to register
   848                              <1> 	JMP	$+2			; I/O DELAY
   849                              <1> 	;mov	dx, 3F9h   		; interrupt enable register
   850                              <1> 	; 29/07/2022
   851                              <1> 	mov	dl, 0F9h
   852                              <1> 	in	al, dx     		; read register
   853                              <1> 	JMP	$+2			; I/O DELAY
   854                              <1> 	;or	al, 1      		; receiver data interrupt enable and
   855                              <1> 	or	al, 3	   		; transmitter empty interrupt enable
   856                              <1> 	out	dx, al 	   		; write back to register
   857                              <1> 	JMP	$+2        		; I/O DELAY
   858                              <1> 	in	al, 21h    		; read interrupt mask register
   859                              <1> 	JMP	$+2			; I/O DELAY
   860                              <1> 	and	al, 0EFh   		; enable IRQ 4 (COM1)
   861                              <1> 	out	21h, al    		; write back to register
   862                              <1> 	;
   863                              <1> 	; 23/10/2015
   864                              <1> 	mov 	eax, com1_int
   865                              <1> 	mov	[com1_irq4], eax
   866                              <1> 	; 26/10/2015
   867                              <1> 	popf
   868                              <1> 	retn
   869                              <1> 
   870                              <1> sp_invp_err:
   871                              <1> 	mov	dword [u.error], ERR_INV_PARAMETER ; 'invalid parameter !'
   872                              <1> 	xor	ecx, ecx
   873                              <1> 	dec	ecx ; 0FFFFh
   874                              <1> 	stc
   875                              <1> 	retn
   876                              <1> 
   877                              <1> ; 29/10/2015
   878                              <1> b_div_tbl: ; Baud rate divisor table (115200/divisor)
   879                              <1> 	db 1, 12, 6, 3, 8, 4, 1
   880                              <1> 
   881                              <1> %endif
   882                              <1> 
   883                              <1> ; 23/10/2015
   884                              <1> com1_irq4:
   885 000122D9 [E1220100]          <1> 	dd dummy_retn
   886                              <1> com2_irq3:
   887 000122DD [E1220100]          <1> 	dd dummy_retn
   888                              <1> 
   889                              <1> ; 21/11/2023
   890                              <1> dummy_retn:
   891                              <1> 	;retn
   892                              <1> wakeup:
   893                              <1> 	; 24/01/2016
   894 000122E1 C3                  <1> 	retn
   895                              <1> 
   896                              <1> set_working_path_x:
   897                              <1> 		; 17/10/2016 (TRDOS 386 - FFF & FNF)
   898                              <1> 		;mov	ax, 1 
   899                              <1> 			; File name is needed/forced (AL=1)
   900                              <1> 			; Change directory as temporary (AH=0)
   901                              <1> 		; 29/07/2022
   902 000122E2 31C0                <1> 		xor	eax, eax
   903 000122E4 FEC0                <1> 		inc	al
   904                              <1> 		; eax = 1
   905                              <1> set_working_path_xx: ; 30/12/2017 (syschdir)
   906                              <1> 		; This is needed for preventing wrong Find Next File
   907                              <1> 		; system call after sysopen, syscreate, sysmkdir etc.
   908                              <1> 		; Find Next File must immediate follow Find First File)
   909                              <1> 
   910 000122E6 8825[74890100]      <1> 		mov	[FFF_Valid], ah ; 0 ; reset ; 17/10/2016
   911                              <1> 
   912                              <1> set_working_path:
   913                              <1> 		; 08/08/2022
   914                              <1> 		; 29/07/2022 - TRDOS 386 Kernel v2.0.5
   915                              <1> 		; 16/10/2016
   916                              <1> 		; 12/10/2016
   917                              <1> 		; 10/10/2016
   918                              <1> 		; 05/10/2016 - TRDOS 386 (TRDOS v2.0)
   919                              <1> 		;
   920                              <1> 		; TRDOS v1.0 (DIR.ASM, "proc_set_working_path")
   921                              <1>                 ; 27/01/2011 - 08/02/2011 
   922                              <1> 		; Set/Changes current drive, directory and file
   923                              <1> 		; depending on command tail
   924                              <1> 		; (procedure is derivated from CMD_INTR.ASM 
   925                              <1> 		; file or dir locating code of internal commands)
   926                              <1> 		; (This procedure is prepared for INT 21H file/dir 
   927                              <1> 		; functions and also to get compact code for 
   928                              <1> 		; internal mainprog -command interpreter- commands)
   929                              <1> 		; 
   930                              <1> 		; INPUT: DS:SI -> Command tail (ASCIIZ string)
   931                              <1> 		; AL = 0 -> any, AL > 0 -> file name is forced
   932                              <1> 		; AH = CD -> Change directory permanently 
   933                              <1> 		; AH <> CD -> Change directory as temporary    
   934                              <1> 		; 
   935                              <1> 		; OUTPUT: ES=DS, FindFile structure has been set
   936                              <1> 		;        RUN_CDRV points previous current drive  
   937                              <1> 		;        DS:SI = FindFile structure address
   938                              <1> 		;        (DS=CS)       
   939                              <1> 		;        AX, BX, CX, DX, DI will be changed
   940                              <1> 		;   cf = 1 -> Error code in AX (AL)
   941                              <1> 		;        stc & AX = 0 -> Bad command or path name
   942                              <1> 		; -----------------------------------------------
   943                              <1> 		;
   944                              <1> 		; TRDOS 386 (05/10/2016)
   945                              <1> 		; INPUT:
   946                              <1> 		;	ESI = File/Directory Path (ASCIIZ string)
   947                              <1> 		;             address in user's memory space
   948                              <1> 		;       AL = 0 -> any
   949                              <1> 		;       AL > 0 -> file name is forced
   950                              <1> 		;       AH = CD -> change directory as permanent
   951                              <1> 		;       AH <> CD -> change directory as temporary
   952                              <1> 		; 
   953                              <1> 		; OUTPUT:
   954                              <1> 		;	FindFile structure has been set
   955                              <1> 		;       RUN_CDRV points previous current drive
   956                              <1> 		;       ESI = FindFile_Name address ; 12/10/2016
   957                              <1> 		;
   958                              <1> 		;       cf = 1 -> Error code in EAX (AL)
   959                              <1> 		;       stc & EAX = 0 -> Bad command or path name
   960                              <1> 		;  
   961                              <1> 		; Modified registers: EAX, EBX, ECX, EDX, ESI, EDI
   962                              <1> 
   963 000122EC 66A3[78890100]      <1> 		mov	[SWP_Mode], ax
   964 000122F2 A0[827D0100]        <1> 		mov	al, [Current_Drv]
   965 000122F7 30E4                <1> 		xor	ah, ah
   966 000122F9 66A3[7A890100]      <1> 		mov	[SWP_DRV], ax
   967                              <1> 
   968                              <1> 		; TRDOS 386 ring 3 (user's page directory)
   969                              <1> 		; to ring 0 (kernel's page directory)
   970                              <1> 		; transfer modifications (05/10/2016).
   971                              <1> 
   972 000122FF 55                  <1> 		push	ebp
   973 00012300 89E5                <1> 		mov	ebp, esp
   974                              <1> 		
   975                              <1> 		;mov	ecx, 128 ; maximum path length = 128 bytes
   976                              <1> 		; 29/07/2022
   977 00012302 31C9                <1> 		xor	ecx, ecx
   978 00012304 B180                <1> 		mov	cl, 128
   979 00012306 29CC                <1> 		sub	esp, ecx ; reserve 128 bytes (buffer) on stack
   980 00012308 89E7                <1> 		mov	edi, esp ; destination address (kernel space)
   981                              <1> 		; esi = source address (virtual, in user's memory space)
   982 0001230A E8CBECFFFF          <1> 		call	transfer_from_user_buffer
   983 0001230F 720D                <1> 		jc	short loc_swp_xor_retn 
   984                              <1> 		
   985 00012311 89E6                <1> 		mov	esi, esp ; temporary buffer (the path) on stack
   986                              <1> loc_swp_fchar:
   987 00012313 8A06                <1> 		mov	al, [esi]
   988 00012315 3C20                <1> 		cmp	al, 20h
   989 00012317 7711                <1> 		ja	short loc_swp_parse_path_name
   990                              <1> 		;je	short loc_swp_fchar_next
   991                              <1> 		; 29/07/2022
   992 00012319 7203                <1> 		jb	short loc_swp_xor_retn
   993                              <1> 
   994                              <1> loc_swp_fchar_next:
   995 0001231B 46                  <1> 		inc	esi
   996 0001231C EBF5                <1> 		jmp	short loc_swp_fchar
   997                              <1> 
   998                              <1> loc_swp_xor_retn:
   999 0001231E 31C0                <1> 		xor	eax, eax
  1000 00012320 F9                  <1> 		stc
  1001                              <1> loc_swp_retn:
  1002 00012321 89EC                <1> 		mov	esp, ebp
  1003 00012323 5D                  <1> 		pop	ebp
  1004                              <1> 
  1005                              <1> 		;mov	esi, FindFile_Drv
  1006 00012324 BE[64860100]        <1> 		mov	esi, FindFile_Name ; 12/10/2016
  1007 00012329 C3                  <1> 		retn 
  1008                              <1> 
  1009                              <1> ;loc_swp_fchar_next:
  1010                              <1> ;		inc	esi
  1011                              <1> ;		jmp	short loc_swp_fchar  
  1012                              <1> 
  1013                              <1> loc_swp_parse_path_name:
  1014 0001232A BF[22860100]        <1> 		mov	edi, FindFile_Drv
  1015 0001232F E8E688FFFF          <1> 		call	parse_path_name
  1016 00012334 72EB                <1> 		jc	short loc_swp_retn
  1017                              <1> 
  1018                              <1> loc_swp_checkfile_name:
  1019 00012336 803D[78890100]00    <1> 		cmp	byte [SWP_Mode], 0
  1020 0001233D 761E                <1> 		jna	short loc_swp_drv
  1021                              <1> 
  1022                              <1> 		; 10/10/2016 (valid file name checking)
  1023 0001233F BE[64860100]        <1> 		mov	esi, FindFile_Name
  1024 00012344 803E20              <1> 		cmp	byte [esi], 20h
  1025 00012347 76D5                <1> 		jna	short loc_swp_xor_retn
  1026                              <1> 
  1027                              <1> 		; 16/10/2016
  1028 00012349 C605[77890100]00    <1> 		mov	byte [SWP_inv_fname], 0 ; reset 
  1029                              <1> 		; esi = file name address (ASCIIZ)
  1030 00012350 E8BA6BFFFF          <1> 		call	check_filename
  1031 00012355 7306                <1> 		jnc	short loc_swp_drv
  1032                              <1> 
  1033 00012357 FE05[77890100]      <1> 		inc	byte [SWP_inv_fname] ; set
  1034                              <1> loc_swp_drv:
  1035 0001235D 8A35[827D0100]      <1> 		mov	dh, [Current_Drv]
  1036                              <1>                ;mov	[RUN_CDRV], dh
  1037                              <1> 
  1038 00012363 8A15[22860100]      <1> 		mov	dl, [FindFile_Drv]
  1039                              <1>                ;cmp	dl, dh
  1040 00012369 3A15[827D0100]      <1> 		cmp	dl, [Current_Drv]
  1041 0001236F 740D                <1> 		je	short loc_swp_change_directory
  1042                              <1> 
  1043 00012371 FE05[7B890100]      <1> 		inc	byte [SWP_DRV_chg]
  1044 00012377 E80155FFFF          <1> 		call	change_current_drive
  1045 0001237C 72A3                <1> 		jc	short loc_swp_retn ; eax = error code
  1046                              <1> 		; eax = 0
  1047                              <1> 
  1048                              <1> loc_swp_change_directory:
  1049 0001237E 803D[23860100]21    <1> 		cmp	byte [FindFile_Directory], 21h
  1050 00012385 F5                  <1> 		cmc
  1051 00012386 7399                <1> 		jnc	short loc_swp_retn
  1052                              <1> 
  1053 00012388 FE05[7B890100]      <1> 		inc	byte [SWP_DRV_chg]
  1054 0001238E FE05[9B340100]      <1> 		inc	byte [Restore_CDIR]
  1055 00012394 BE[23860100]        <1> 		mov	esi, FindFile_Directory
  1056 00012399 8A25[79890100]      <1> 		mov	ah, [SWP_Mode+1] 
  1057 0001239F E88C82FFFF          <1> 		call	change_current_directory
  1058                              <1> 		;jc	short loc_swp_retn ; eax = error code
  1059                              <1> 		; 08/08/2022
  1060 000123A4 7305                <1> 		jnc	short loc_swp_change_prompt_dir_string
  1061 000123A6 E976FFFFFF          <1> 		jmp	loc_swp_retn	
  1062                              <1> 
  1063                              <1> loc_swp_change_prompt_dir_string:
  1064                              <1> 		; esi = PATH_Array
  1065                              <1> 		; eax = Current Directory First Cluster
  1066                              <1> 		; edi = Logical DOS Drive Description Table
  1067 000123AB E8AE81FFFF          <1> 		call	change_prompt_dir_str 
  1068 000123B0 29C0                <1> 		sub	eax, eax ; 0
  1069 000123B2 E96AFFFFFF          <1> 		jmp	loc_swp_retn 
  1070                              <1> 
  1071                              <1> reset_working_path:
  1072                              <1> 		; 06/10/2016 - TRDOS 386 (TRDOS v2.0)
  1073                              <1> 		;
  1074                              <1> 		; TRDOS v1.0 (DIR.ASM, "proc_reset_working_path")
  1075                              <1> 		; 05/02/2011 - 08/02/2011
  1076                              <1> 		;
  1077                              <1> 		; Restores current drive and directory
  1078                              <1> 		; 
  1079                              <1> 		; INPUT: none
  1080                              <1> 		; OUTPUT: DL = SWP_DRV, EAX = 0 -> OK
  1081                              <1> 		;
  1082                              <1> 		;    AX = 0 -> ESI = Logical Dos Drv Desc. Table
  1083                              <1> 		;
  1084                              <1> 		;    EAX, EBX, ECX, EDX, ESI, EDI will be changed
  1085                              <1> 		;
  1086                              <1> 
  1087                              <1>   
  1088 000123B7 31C0                <1> 		xor	eax, eax
  1089 000123B9 48                  <1> 		dec	eax 
  1090                              <1> 
  1091 000123BA 668B15[7A890100]    <1> 		mov	dx, [SWP_DRV]
  1092 000123C1 08F6                <1> 		or	dh, dh
  1093 000123C3 742E                <1> 		jz	short loc_rwp_return
  1094                              <1> 
  1095 000123C5 3A15[827D0100]      <1> 		cmp	dl, [Current_Drv]
  1096 000123CB 7407                <1> 		je	short loc_rwp_restore_cdir
  1097                              <1> loc_rwp_restore_cdrv:
  1098 000123CD E8AB54FFFF          <1> 		call	change_current_drive 
  1099 000123D2 EB10                <1> 		jmp	short loc_rwp_restore_ok
  1100                              <1> loc_rwp_restore_cdir:
  1101 000123D4 31DB                <1> 		xor	ebx, ebx
  1102 000123D6 88D7                <1> 		mov	bh, dl
  1103 000123D8 BE00010900          <1> 		mov	esi, Logical_DOSDisks
  1104 000123DD 01DE                <1> 		add	esi, ebx
  1105                              <1> 
  1106 000123DF E84F55FFFF          <1> 		call	restore_current_directory
  1107                              <1> 
  1108                              <1> loc_rwp_restore_ok:
  1109 000123E4 668B15[7A890100]    <1> 		mov	dx, [SWP_DRV]
  1110 000123EB 31C0                <1> 		xor	eax, eax  
  1111 000123ED 66A3[7B890100]      <1> 		mov	[SWP_DRV_chg], ax
  1112                              <1> loc_rwp_return:
  1113 000123F3 C3                  <1> 		retn
  1114                              <1> 
  1115                              <1> get_file_name:
  1116                              <1> 		; 25/08/2024 (TRDOS 386 Kernel v2.0.9)
  1117                              <1> 		; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  1118                              <1> 		; 15/10/2016 - TRDOS 386 (TRDOS v2.0)
  1119                              <1> 		; Convert file name 
  1120                              <1> 		;	from directory entry format
  1121                              <1>                 ; 	to (8.3) dot file name format
  1122                              <1> 		;
  1123                              <1> 		; TRDOS v1.0 (DIR.ASM, "get_file_name")
  1124                              <1>                 ; 2005 - 09/10/2011
  1125                              <1> 		; INPUT: 
  1126                              <1> 		;	DS:SI -> Directory Entry Format File Name
  1127                              <1> 		;       ES:DI -> DOS Dot File Name Address
  1128                              <1> 		; OUTPUT:
  1129                              <1> 		;	DS:SI -> DOS Dot File Name Address
  1130                              <1>                 ;	ES:DI -> Directory Entry Format File Name
  1131                              <1> 		;	
  1132                              <1> 		; TRDOS 386 (15/10/2016)
  1133                              <1> 		; INPUT:
  1134                              <1> 		;	ESI = File name addr in dir entry format
  1135                              <1> 		;	EDI = Dot file name address (destination)
  1136                              <1> 		; OUTPUT: 
  1137                              <1> 		;	File name is converted and moved
  1138                              <1> 		;	to destination (as 8.3 dot filename)
  1139                              <1> 		;  
  1140                              <1> 		; Modified registers: EAX, ECX
  1141                              <1> 
  1142                              <1>                 ; 2005 (TRDOS 8086) - 2016 (TRDOS 386)
  1143                              <1> 
  1144 000123F4 57                  <1> 		push	edi
  1145 000123F5 56                  <1> 		push	esi
  1146 000123F6 AC                  <1> 		lodsb
  1147                              <1> 		; 25/08/2024
  1148 000123F7 31C9                <1> 		xor	ecx, ecx ; 0
  1149 000123F9 3C20                <1> 		cmp	al, 20h
  1150 000123FB 7626                <1> 		jna	short pass_gfn_ext
  1151                              <1> 		; 25/08/2024
  1152                              <1> 		;push	esi
  1153 000123FD AA                  <1> 		stosb
  1154                              <1> 		; 25/08/2024
  1155                              <1> 		; 29/07/2022
  1156                              <1> 		;xor	ecx, ecx
  1157                              <1> 		; ecx <= 128 ; 25/08/2024
  1158 000123FE B107                <1> 		mov	cl, 7
  1159                              <1> 		; 25/08/2024
  1160 00012400 01CE                <1> 		add	esi, ecx ; add esi, 7
  1161 00012402 56                  <1> 		push	esi ; (*)
  1162                              <1> loc_gfn_next_char:
  1163 00012403 AC                  <1> 		lodsb
  1164 00012404 3C20                <1> 		cmp	al, 20h
  1165 00012406 7603                <1> 		jna	short pass_gfn_fn
  1166 00012408 AA                  <1> 		stosb
  1167 00012409 E2F8                <1> 		loop	loc_gfn_next_char
  1168                              <1> pass_gfn_fn:
  1169                              <1> 		;pop	esi
  1170                              <1> 		;add	esi, 7
  1171                              <1> 		; 25/08/2024
  1172 0001240B 5E                  <1> 		pop	esi ; (*)
  1173                              <1> 
  1174 0001240C AC                  <1> 		lodsb
  1175 0001240D 3C20                <1> 		cmp	al, 20h
  1176 0001240F 7612                <1> 		jna	short pass_gfn_ext
  1177 00012411 B42E                <1> 		mov	ah, '.'
  1178 00012413 86C4                <1> 		xchg	ah, al
  1179 00012415 66AB                <1> 		stosw
  1180 00012417 AC                  <1> 		lodsb
  1181 00012418 3C20                <1> 		cmp	al, 20h
  1182 0001241A 7607                <1> 		jna	short pass_gfn_ext
  1183 0001241C AA                  <1> 		stosb
  1184 0001241D AC                  <1> 		lodsb
  1185 0001241E 3C20                <1> 		cmp	al, 20h
  1186 00012420 7601                <1> 		jna	short pass_gfn_ext
  1187 00012422 AA                  <1> 		stosb
  1188                              <1> pass_gfn_ext:
  1189 00012423 30C0                <1> 		xor	al, al
  1190 00012425 AA                  <1> 		stosb
  1191 00012426 5E                  <1> 		pop	esi
  1192 00012427 5F                  <1> 		pop	edi
  1193                              <1> 		; 25/08/2024
  1194                              <1> 		; ecx <= 7
  1195 00012428 C3                  <1> 		retn
  1196                              <1> 
  1197                              <1> set_hardware_int_vector:
  1198                              <1> 		; 18/03/2017
  1199                              <1> 		; 03/03/2017
  1200                              <1> 		; 28/02/2017 - TRDOS 386 (TRDOS v2.0)
  1201                              <1> 		;
  1202                              <1> 		; SET/RESET HARDWARE INTERRUPT GATE
  1203                              <1> 		;
  1204                              <1> 		; Changes interrupt gate descriptor table
  1205                              <1> 		; (without changing default interrupt list)
  1206                              <1> 		;
  1207                              <1> 		; INPUT:
  1208                              <1> 		;	AL = IRQ number (0 to 15)
  1209                              <1> 		;	AH > 0 -> set
  1210                              <1> 		;	AH = 0 -> reset
  1211                              <1> 		;	
  1212                              <1> 		; Modified registers: eax, ebx, edx, edi
  1213                              <1> 		;
  1214                              <1> 		
  1215 00012429 C0E002              <1> 		shl	al, 2 ; IRQ number * 4
  1216 0001242C 0FB6D8              <1> 		movzx	ebx, al
  1217                              <1> 
  1218 0001242F 08E4                <1> 		or	ah, ah
  1219 00012431 7508                <1> 		jnz	short shintv_1 ; set (for user call service)
  1220                              <1> 		
  1221                              <1> 		; 18/03/2017
  1222 00012433 81C3[883C0100]      <1> 		add	ebx, IRQ_list ; reset to default interrupt list
  1223 00012439 EB06                <1> 		jmp	short shintv_2
  1224                              <1> shintv_1:
  1225 0001243B 81C3[62240100]      <1> 		add	ebx, IRQ_u_list
  1226                              <1> shintv_2:	
  1227 00012441 8B13                <1> 		mov	edx, [ebx] ; IRQ handler address
  1228                              <1> 		
  1229                              <1> 		; 03/03/2017
  1230 00012443 D0E0                <1> 		shl	al, 1 ; IRQ number * 8 
  1231                              <1> 		; 18/03/2017
  1232 00012445 0FB6F8              <1> 		movzx	edi, al 
  1233 00012448 81C7[D87A0100]      <1> 		add	edi, idt + (8*32) ; IRQ 0 offset = idt + 256
  1234                              <1> 		
  1235 0001244E 89D0                <1> 		mov	eax, edx ; IRQ handler address
  1236 00012450 BB00000800          <1> 		mov	ebx, 80000h
  1237                              <1> 
  1238                              <1> 		;mov	edx, eax
  1239 00012455 66BA008E            <1> 		mov	dx, 8E00h
  1240 00012459 6689C3              <1> 		mov	bx, ax
  1241 0001245C 89D8                <1> 		mov	eax, ebx ; /* selector = 0x0008 = cs */
  1242                              <1>        			         ; /* interrupt gate - dpl=0, present */
  1243 0001245E AB                  <1> 		stosd	; selector & offset bits 0-15 	
  1244 0001245F 8917                <1> 		mov	[edi], edx ; attributes & offset bits 16-23
  1245                              <1> 
  1246 00012461 C3                  <1> 		retn
  1247                              <1> IRQ_u_list:
  1248                              <1> 		; 28/02/2017
  1249 00012462 [88090000]          <1> 		dd	timer_int
  1250 00012466 [ED100000]          <1> 		dd	kb_int
  1251 0001246A [740B0000]          <1> 		dd	irq2
  1252 0001246E [A2240100]          <1> 		dd	IRQ_service3
  1253 00012472 [AC240100]          <1> 		dd	IRQ_service4
  1254 00012476 [B6240100]          <1> 		dd	IRQ_service5
  1255 0001247A [5A4E0000]          <1> 		dd	fdc_int	
  1256 0001247E [C0240100]          <1> 		dd	IRQ_service7
  1257 00012482 [FC0A0000]          <1> 		dd	rtc_int
  1258 00012486 [CA240100]          <1> 		dd	IRQ_service9
  1259 0001248A [D4240100]          <1> 		dd	IRQ_service10
  1260 0001248E [DE240100]          <1> 		dd	IRQ_service11
  1261 00012492 [E8240100]          <1> 		dd	IRQ_service12
  1262 00012496 [F2240100]          <1> 		dd	IRQ_service13
  1263 0001249A [99570000]          <1> 		dd	hdc1_int
  1264 0001249E [BC570000]          <1> 		dd	hdc2_int
  1265                              <1> 
  1266                              <1> 		; 03/03/2017
  1267                              <1> 		; 27/02/2017
  1268                              <1> IRQ_service3:
  1269 000124A2 36C605[E88E0100]03  <1> 		mov	byte [ss:IRQnum], 3
  1270 000124AA EB4E                <1> 		jmp	short IRQ_service
  1271                              <1> IRQ_service4:
  1272 000124AC 36C605[E88E0100]04  <1> 		mov	byte [ss:IRQnum], 4
  1273 000124B4 EB44                <1> 		jmp	short IRQ_service
  1274                              <1> IRQ_service5:
  1275 000124B6 36C605[E88E0100]05  <1> 		mov	byte [ss:IRQnum], 5
  1276 000124BE EB3A                <1> 		jmp	short IRQ_service
  1277                              <1> IRQ_service7:
  1278 000124C0 36C605[E88E0100]07  <1> 		mov	byte [ss:IRQnum], 7
  1279 000124C8 EB30                <1> 		jmp	short IRQ_service
  1280                              <1> IRQ_service9:
  1281 000124CA 36C605[E88E0100]09  <1> 		mov	byte [ss:IRQnum], 9
  1282 000124D2 EB26                <1> 		jmp	short IRQ_service
  1283                              <1> IRQ_service10:
  1284 000124D4 36C605[E88E0100]0A  <1> 		mov	byte [ss:IRQnum], 10
  1285 000124DC EB1C                <1> 		jmp	short IRQ_service
  1286                              <1> IRQ_service11:
  1287 000124DE 36C605[E88E0100]0B  <1> 		mov	byte [ss:IRQnum], 11
  1288 000124E6 EB12                <1> 		jmp	short IRQ_service
  1289                              <1> IRQ_service12:
  1290 000124E8 36C605[E88E0100]0C  <1> 		mov	byte [ss:IRQnum], 12
  1291 000124F0 EB08                <1> 		jmp	short IRQ_service
  1292                              <1> IRQ_service13:
  1293 000124F2 36C605[E88E0100]0D  <1> 		mov	byte [ss:IRQnum], 13
  1294                              <1> 		;jmp	short IRQ_service
  1295                              <1> IRQ_service:
  1296                              <1> 		; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  1297                              <1> 		; 13/06/2017
  1298                              <1> 		; 11/06/2017
  1299                              <1> 		; 10/06/2017
  1300                              <1> 		; 01/03/2017, 04/03/2017
  1301                              <1> 		; 27/02/2017, 28/02/2017
  1302 000124FA 1E                  <1> 		push	ds
  1303 000124FB 06                  <1> 		push	es
  1304 000124FC 0FA0                <1> 		push	fs
  1305 000124FE 0FA8                <1> 		push	gs
  1306                              <1> 
  1307 00012500 60                  <1> 		pushad	; eax,ecx,edx,ebx,esp,ebp,esi,edi
  1308 00012501 66B91000            <1> 		mov     cx, KDATA
  1309 00012505 8ED9                <1>         	mov     ds, cx
  1310 00012507 8EC1                <1>         	mov     es, cx
  1311 00012509 8EE1                <1>         	mov     fs, cx
  1312 0001250B 8EE9                <1>         	mov     gs, cx
  1313                              <1> 
  1314 0001250D 0F20D8              <1> 		mov	eax, cr3
  1315 00012510 A3[E48E0100]        <1> 		mov	[IRQ_cr3], eax
  1316                              <1> 
  1317 00012515 A1[C07C0100]        <1> 		mov	eax, [k_page_dir]
  1318 0001251A 0F22D8              <1> 		mov	cr3, eax 
  1319                              <1> 
  1320 0001251D A0[E88E0100]        <1> 		mov	al, [IRQnum]
  1321                              <1> 
  1322                              <1> 		;mov	cl, [sysflg]
  1323                              <1> 		;mov	[u.r_mode], cl  ; system (0) or user mode (FFh) 
  1324                              <1> IRQsrv_0:
  1325 00012522 0FB6D8              <1> 		movzx	ebx, al
  1326 00012525 8A9B[BE3B0100]      <1> 		mov	bl, [ebx+IRQenum] ; IRQ (available) index number + 1
  1327                              <1> 		; 01/03/2017
  1328 0001252B FECB                <1> 		dec	bl  ; IRQ index number, 0 to 8
  1329                              <1> 		;js	IRQsrv_5 ; not available to use here!?
  1330                              <1> 		; 29/07/2022
  1331 0001252D 785E                <1> 		js	short IRQsrv_j5  ; (jump to IRQsrv_5)
  1332                              <1> 		;		 
  1333 0001252F 80BB[AE8E0100]80    <1> 		cmp	byte [ebx+IRQ.method], 80h ; using by a dev or kernel? 
  1334 00012536 7205                <1> 		jb	short IRQsrv_1 ; no
  1335                              <1> 
  1336                              <1> 		; If the IRQ service is already owned by TRDOS 386 kernel
  1337                              <1> 		;	 or a Device driver
  1338                              <1> 		; we need to call 'dev_IRQ_service'
  1339                              <1> 
  1340                              <1> 		; IRQ number in AL
  1341 00012538 E80E010000          <1> 		call	dev_IRQ_service	 ; IRQ service for device drivers
  1342                              <1> 		; IRQ number in AL
  1343                              <1> IRQsrv_1:		
  1344                              <1> 		; check user callback service status
  1345                              <1> 		; AL = IRQ number
  1346                              <1> 		; EBX = IRQ (Available) Index number
  1347                              <1> 
  1348 0001253D A2[EF940100]        <1> 		mov	[u.irqwait], al ; set waiting IRQ flag
  1349                              <1> 
  1350 00012542 8A83[9C8E0100]      <1> 		mov	al, [ebx+IRQ.owner]
  1351 00012548 20C0                <1> 		and	al, al
  1352                              <1> 		;jz	IRQsrv_5 ; it is not owned by a user/proc
  1353                              <1> 		; 29/07/2022
  1354 0001254A 7441                <1> 		jz	short IRQsrv_j5  ; (jump to IRQsrv_5)
  1355                              <1> 
  1356                              <1> 		; 03/03/2017
  1357 0001254C 89DA                <1> 		mov	edx, ebx
  1358 0001254E C0E202              <1> 		shl	dl, 2
  1359 00012551 8B92[C08E0100]      <1> 		mov	edx, [edx+IRQ.addr] ; S.R.B. or Callback service addr
  1360                              <1> 		
  1361 00012557 8AA3[AE8E0100]      <1> 		mov	ah, [ebx+IRQ.method]
  1362 0001255D F6C401              <1> 		test	ah, 1
  1363 00012560 7530                <1> 		jnz	short IRQsrv_4 ; Callback service method
  1364                              <1> 
  1365                              <1> 		; Signal Response Byte method
  1366                              <1> 		;mov	edx, [edx+IRQ.addr] ; Signal Response Byte address
  1367                              <1> 		;			    ; (Physical address, non-swappable)
  1368 00012562 80E402              <1> 		and	ah, 2 ; bit 1, (S.R.B.) counter (auto increment) method
  1369 00012565 8AA3[B78E0100]      <1> 		mov	ah, [ebx+IRQ.srb] ; Signal Response Byte value
  1370 0001256B 7408                <1> 		jz	short IRQsrv_2 ; fixed S.R.B. value
  1371                              <1> 		; counter method (auto increment)
  1372 0001256D FEC4                <1> 		inc	ah
  1373 0001256F 88A3[B78E0100]      <1> 		mov	[ebx+IRQ.srb], ah ; next (count) number
  1374                              <1> IRQsrv_2:
  1375 00012575 8822                <1> 		mov	[edx], ah ; put S.R.B. val to the user's S.R.B. addr
  1376 00012577 C605[EF940100]00    <1> 		mov	byte [u.irqwait], 0 ; clear waiting IRQ flag
  1377                              <1> 
  1378 0001257E 3A05[C5940100]      <1> 		cmp	al, [u.uno]
  1379                              <1> 		;je	IRQsrv_5 ; the owner is current user/process
  1380                              <1> 		; 29/07/2022
  1381 00012584 7407                <1> 		je	short IRQsrv_j5  ; (jump to IRQsrv_5)
  1382                              <1> IRQsrv_3:
  1383                              <1> 		; the owner is not current user/process
  1384                              <1> 		; AL = process number
  1385 00012586 B202                <1> 		mov	dl, 2 ; priority, 2 = event (high)
  1386 00012588 E87BFBFFFF          <1> 		call	set_run_sequence
  1387                              <1> 
  1388                              <1> 		; [u.irqwait] = waiting IRQ number for callback service
  1389                              <1> IRQsrv_j5:		; 29/07/2022
  1390 0001258D E998000000          <1> 		jmp	IRQsrv_5
  1391                              <1> IRQsrv_4:
  1392 00012592 3A05[C5940100]      <1> 		cmp	al, [u.uno]  ; is the owner is current user/process?
  1393 00012598 75EC                <1> 		jne	short IRQsrv_3 ; no !
  1394                              <1> 
  1395                              <1> 		; Check if an IRQ callback service already in progress
  1396 0001259A 803D[F0940100]00    <1> 		cmp	byte [u.r_lock], 0
  1397                              <1> 		;ja	IRQsrv_5 ; nothing to do !  
  1398                              <1> 				     ; (we need to complete prev callback)
  1399                              <1> 		; 29/07/2022
  1400 000125A1 77EA                <1> 		ja	short IRQsrv_j5  ; (jump to IRQsrv_5)
  1401                              <1> 
  1402 000125A3 803D[EC940100]00    <1> 		cmp	byte [u.t_lock], 0
  1403 000125AA 777E                <1> 		ja	short IRQsrv_5 ; nothing to do !  
  1404                              <1> 				     ; (we need to complete timer callback)
  1405                              <1> 
  1406                              <1> 		; 04/03/2017
  1407 000125AC C605[EF940100]00    <1> 		mov	byte [u.irqwait], 0 ; reset/clear waiting IRQ flag
  1408                              <1> 
  1409 000125B3 FE05[F0940100]      <1> 		inc	byte [u.r_lock] ; 'IRQ callback service in progress' flag
  1410                              <1> 
  1411 000125B9 8A0D[68940100]      <1> 		mov	cl, [sysflg]   ; (system call) mode flag (kernel/user)
  1412 000125BF 880D[F1940100]      <1> 		mov	[u.r_mode], cl ; system mode (0) or user mode (FFh)
  1413                              <1> 
  1414                              <1> 		; 
  1415 000125C5 8B2D[5C7C0100]      <1> 		mov	ebp, [tss.esp0] ; kernel stack address (for ring 0)
  1416 000125CB 83ED14              <1> 		sub	ebp, 20		; eip, cs, eflags, esp, ss
  1417 000125CE 892D[6C940100]      <1> 	 	mov	[u.sp], ebp
  1418 000125D4 8925[70940100]      <1> 		mov	[u.usp], esp
  1419                              <1> 
  1420                              <1> 		;or	word [ebp+8], 200h ; 22/01/2017, force enabling interrupts
  1421                              <1> 
  1422 000125DA 8B44241C            <1> 		mov	eax, [esp+28] ; pushed eax
  1423 000125DE A3[74940100]        <1> 		mov	[u.r0], eax
  1424                              <1> 
  1425 000125E3 E864E8FFFF          <1> 		call	wswap ; save user's registers & status
  1426                              <1> 
  1427                              <1> 		; software int is in ring 0 but IRQ handler must return to ring 3
  1428                              <1> 		; so, ring 3 return address and stack registers
  1429                              <1> 		; (eip, cs, eflags, esp, ss) 
  1430                              <1> 		; must be copied to IRQ handler return
  1431                              <1> 		; eip will be replaced by callback service routine address
  1432                              <1> 
  1433 000125E8 C605[68940100]FF    <1> 		mov	byte [sysflg], 0FFh ; user mode
  1434                              <1> 
  1435                              <1> 		; system mode (system call)
  1436                              <1> 		;mov	ebp, [u.sp] ; EIP (u), CS (UCODE), EFLAGS (u),
  1437                              <1> 				    ; ESP (u), SS (UDATA)
  1438                              <1> 
  1439 000125EF 8B4510              <1> 		mov	eax, [ebp+16]	; SS (UDATA)
  1440 000125F2 89E6                <1> 		mov	esi, esp
  1441 000125F4 50                  <1> 		push	eax
  1442 000125F5 50                  <1> 		push	eax
  1443 000125F6 89E7                <1> 		mov	edi, esp
  1444 000125F8 893D[70940100]      <1> 		mov	[u.usp], edi
  1445 000125FE B908000000          <1> 		mov	ecx, ((ESPACE/4) - 4) ; except DS, ES, FS, GS
  1446 00012603 F3A5                <1> 		rep	movsd
  1447 00012605 B104                <1> 		mov	cl, 4	
  1448 00012607 F3AB                <1> 		rep	stosd
  1449 00012609 893D[6C940100]      <1> 		mov	[u.sp], edi
  1450 0001260F 89EE                <1> 		mov	esi, ebp
  1451 00012611 B105                <1> 		mov	cl, 5 ; EIP (u), CS (UCODE), EFLAGS (u), ESP (u), SS (UDATA)
  1452 00012613 F3A5                <1> 		rep	movsd
  1453                              <1> 		;
  1454                              <1> 
  1455 00012615 8B0D[CC940100]      <1> 		mov	ecx, [u.pgdir]
  1456 0001261B 890D[E48E0100]      <1> 		mov	[IRQ_cr3], ecx
  1457                              <1> 
  1458                              <1> set_IRQ_callback_addr:
  1459                              <1> 		;
  1460                              <1> 		; This routine sets return address
  1461                              <1> 		; to start of user's interrupt
  1462                              <1> 		; service (callback) address
  1463                              <1> 		;
  1464                              <1> 		; INPUT:
  1465                              <1> 		;	EDX = callback routine/service address
  1466                              <1> 		;	      (virtual, not physical address!)
  1467                              <1> 		;	[u.sp] = kernel stack, points to
  1468                              <1> 		;		 user's EIP,CS,EFLAGS,ESP,SS
  1469                              <1> 		;		 registers.
  1470                              <1> 		; OUTPUT:
  1471                              <1> 		;	EIP (user) = callback (service) address
  1472                              <1> 		;	CS (user) = UCODE
  1473                              <1> 		;	EFLAGS (user) = flags before callback
  1474                              <1> 		;       ESP (user) = ESP-4 (user, before callback)
  1475                              <1> 		;	[ESP](user) = EIP (user) before callback
  1476                              <1> 		;
  1477                              <1> 		; Note: If CPU was in user mode while entering 
  1478                              <1> 		;	the timer interrupt service routine,
  1479                              <1> 		;	'IRET' will get return to callback routine
  1480                              <1> 		;	immediately. If CPU was in system/kernel mode
  1481                              <1> 		;	'iret' will get return to system call and
  1482                              <1> 		;	then, callback routine will be return address
  1483                              <1> 		;	from system call. (User's callback/service code
  1484                              <1> 		;	will be able to return to normal return address
  1485                              <1> 		;	via a 'sysrele' system call at the end.) 
  1486                              <1> 		;
  1487                              <1> 		; Note: User's IRQ callback service code must be ended
  1488                              <1> 		;	with a 'sysrele' system call !
  1489                              <1> 		;
  1490                              <1> 		;	For example:
  1491                              <1> 		;
  1492                              <1> 		;	audio_IRQ_callback:
  1493                              <1> 		;	    ...	 
  1494                              <1> 		;	    <load DMA buffer with audio data>
  1495                              <1> 		;	    ...
  1496                              <1> 		;	    mov eax, 39 ; 'sysrele'
  1497                              <1> 		;	    int 40h ; TRDOS 386 system call (interrupt)
  1498                              <1> 		;
  1499                              <1> 		
  1500                              <1> 		;mov	edx, [edx+IRQ.addr] ; Callback service address
  1501                              <1> 		;			    ; (Virtual address)
  1502                              <1> 		
  1503 00012621 8B2D[6C940100]      <1> 		mov	ebp, [u.sp]; kernel's stack, points to EIP (user)
  1504 00012627 895500              <1> 		mov	[ebp], edx
  1505                              <1> IRQsrv_5:
  1506                              <1> 		; EOI & return
  1507                              <1> 		; 01/08/2020
  1508                              <1> 		; 11/06/2017
  1509                              <1> 		; 10/06/2017 
  1510                              <1> 		;mov	al, [IRQnum]
  1511 0001262A B020                <1> 		mov	al, 20h ; 01/08/2020
  1512 0001262C FA                  <1> 		cli
  1513                              <1> 		;cmp	al, 7
  1514 0001262D 803D[E88E0100]07    <1> 		cmp	byte [IRQnum], 7 ; 01/08/2020
  1515 00012634 7602                <1> 		jna	short IRQsrv_6
  1516                              <1> 		;
  1517                              <1> 		;;mov	al, EOI	; end of interrupt
  1518                              <1> 		;mov	al, 20h ; 01/08/2020
  1519                              <1> 		;cli		; disable interrupts till stack cleared
  1520                              <1> 		;out	INTB00, al ; For controll2 #2
  1521 00012636 E6A0                <1> 		out	0A0h, al
  1522                              <1> IRQsrv_6:
  1523                              <1> 		;mov	byte [IRQnum], 0 ; reset
  1524                              <1> 		;;mov	al, EOI	; end of interrupt
  1525                              <1> 		;mov	al, 20h ; 01/08/2020
  1526                              <1> 		;cli		; disable interrupts till stack cleared
  1527                              <1> 		;out	INTA00, al ; end of interrupt to 8259 - 1
  1528 00012638 E620                <1> 		out	20h, al	
  1529                              <1> IRQsrv_7:	
  1530                              <1> 		;; 13/06/2017
  1531                              <1> 		;or	word [ebp+8], 200h ; force enabling interrupts
  1532                              <1> 		;
  1533 0001263A 8B0D[E48E0100]      <1> 		mov 	ecx, [IRQ_cr3]	; previous content of cr3 register
  1534 00012640 0F22D9              <1>  		mov	cr3, ecx	; restore cr3 register content
  1535                              <1> 		;
  1536 00012643 61                  <1> 		popad ; edi,esi,ebp,(icrement esp by 4),ebx,edx,ecx,eax
  1537                              <1> 		;
  1538 00012644 0FA9                <1> 		pop	gs
  1539 00012646 0FA1                <1> 		pop	fs
  1540 00012648 07                  <1> 		pop	es
  1541 00012649 1F                  <1> 		pop	ds
  1542                              <1> 		;
  1543 0001264A CF                  <1> 		iretd	; return from interrupt
  1544                              <1> 
  1545                              <1> ; 17/04/2021
  1546                              <1> ; ('get_device_number' procedure is disabled as temporary)
  1547                              <1> 
  1548                              <1> ;get_device_number:
  1549                              <1> ;		; 08/10/2016
  1550                              <1> ;		; 07/10/2016 - TRDOS 386 (TRDOS v2.0)
  1551                              <1> ;		;
  1552                              <1> ;		; This procedure compares name of requested
  1553                              <1> ;		; device with kernel device names and
  1554                              <1> ;		; installable device names. If names match, 
  1555                              <1> ;		; the relevant device index (entry) number 
  1556                              <1> ;		; will be returned the caller (sysopen) 
  1557                              <1> ;		; for the requested device.
  1558                              <1> ;		;
  1559                              <1> ;		; NOTE: Installable device drivers must
  1560                              <1> ;		; be loaded before using 'sysopen'
  1561                              <1> ;		; (opendev) system call.
  1562                              <1> ;		;
  1563                              <1> ;		; INPUT:
  1564                              <1> ;		;    ESI = device name address (ASCIIZ)
  1565                              <1> ;		;         (in kernel's memory space)  
  1566                              <1> ;  		;    max name length = 8 without '/dev/')
  1567                              <1> ;		;    Device name will be capitalized 
  1568                              <1> ;		;    and if there is, '/dev/' will be
  1569                              <1> ;		;    removed from name before comparising)
  1570                              <1> ;		;
  1571                              <1> ;		; OUTPUT:
  1572                              <1> ;		;    cf = 0 -> 
  1573                              <1> ;		;      EAX (AL) = device entry/index number
  1574                              <1> ;		;    cf = 1 -> device not found (installed)
  1575                              <1> ;		;	       or invalid device name
  1576                              <1> ;		;	       (AL=0)
  1577                              <1> ;		;    device_name = device name address (asciiz)
  1578                              <1> ;			;
  1579                              <1> ;		; Modified registers: EAX, EBX, ESI, EDI
  1580                              <1> ;
  1581                              <1> ;		mov	edi, device_name
  1582                              <1> ;		call 	lodsb_capitalize
  1583                              <1> ;		mov	ah, al
  1584                              <1> ;		cmp	al, '/'
  1585                              <1> ;		jne	short gdn_1
  1586                              <1> ;		mov	edi, device_name
  1587                              <1> ;		call 	lodsb_capitalize
  1588                              <1> ;gdn_0:
  1589                              <1> ;		and	al, al ; 0 ?
  1590                              <1> ;		jz	short gdn_err ; null name after '/'
  1591                              <1> ;gdn_1:
  1592                              <1> ;		cmp	al, 'D'
  1593                              <1> ;		jne	short gdn_2
  1594                              <1> ;		call 	lodsb_capitalize
  1595                              <1> ;		cmp	al, 'E'
  1596                              <1> ;		jne	short gdn_2
  1597                              <1> ;		call 	lodsb_capitalize
  1598                              <1> ;		cmp	al, 'V'
  1599                              <1> ;		jne	short gdn_2
  1600                              <1> ;		lodsb
  1601                              <1> ;		cmp	al, '/'
  1602                              <1> ;		je	short gdn_4
  1603                              <1> ;gdn_2:
  1604                              <1> ;		cmp	ah, '/'
  1605                              <1> ;		jne	short gdn_5
  1606                              <1> ;gdn_err:		
  1607                              <1> ;		; invalid device name or device not found
  1608                              <1> ;		xor	eax, eax ; 0
  1609                              <1> ;		stc
  1610                              <1> ;		retn
  1611                              <1> ;gdn_3:
  1612                              <1> ;		cmp	al, '/'
  1613                              <1> ;		jne	short gdn_5
  1614                              <1> ;gdn_4:
  1615                              <1> ;		mov	edi, device_name
  1616                              <1> ;		jmp	short gdn_6
  1617                              <1> ;gdn_5:
  1618                              <1> ;		cmp	al, 0
  1619                              <1> ;		je	short gdn_7
  1620                              <1> ;gdn_6:
  1621                              <1> ;		call	lodsb_capitalize
  1622                              <1> ;		cmp	edi, device_name + 8
  1623                              <1> ;		jb	short gdn_3
  1624                              <1> ;		cmp	al, 0
  1625                              <1> ;		jne	short gdn_err
  1626                              <1> ;		cmp	edi, device_name + 1
  1627                              <1> ;		jna	short gdn_err ; null name after '/'
  1628                              <1> ;gdn_7:
  1629                              <1> ;		stosb
  1630                              <1> ;		; zero padding ("NAME",0,0,0,0)
  1631                              <1> ;		cmp	edi, device_name + 8
  1632                              <1> ;		jb	short gdn_7
  1633                              <1> ;gdn_8:
  1634                              <1> ;		; search for kernel device names
  1635                              <1> ;		mov	esi, device_name 
  1636                              <1> ;		mov	edi, KDEV_NAME
  1637                              <1> ;		xor	eax, eax
  1638                              <1> ;gdn_9:
  1639                              <1> ;		cmpsd	
  1640                              <1> ;		jne	short gdn_10
  1641                              <1> ;		cmpsd
  1642                              <1> ;		jne	short gdn_11
  1643                              <1> ;		jmp	short gdn_17 ; match
  1644                              <1> ;gdn_10:
  1645                              <1> ;		cmpsd  ; add esi, 4 & add edi, 4
  1646                              <1> ;gdn_11:
  1647                              <1> ;		mov	esi, device_name
  1648                              <1> ;		inc	al
  1649                              <1> ;		cmp	al, NumOfKernelDevNames
  1650                              <1> ;		jb	short gdn_9
  1651                              <1> ;gdn_12:
  1652                              <1> ;		; search for installable device names
  1653                              <1> ;		; esi = offset device_name 
  1654                              <1> ;		mov	edi, IDEV_NAME
  1655                              <1> ;		sub	al, al ; 0
  1656                              <1> ;gdn_13:
  1657                              <1> ;		cmpsd	
  1658                              <1> ;		jne	short gdn_14
  1659                              <1> ;		cmpsd
  1660                              <1> ;		jne	short gdn_15
  1661                              <1> ;		jmp	short gdn_19 ; match
  1662                              <1> ;gdn_14:
  1663                              <1> ;		cmpsd  ; add esi, 4 & add edi, 4
  1664                              <1> ;gdn_15:
  1665                              <1> ;		mov	esi, device_name
  1666                              <1> ;		inc	al
  1667                              <1> ;		cmp	al, NumOfInstallableDevices
  1668                              <1> ;		jb	short gdn_13
  1669                              <1> ;
  1670                              <1> ;gdn_16: 	; error: invalid device name (not found) !
  1671                              <1> ;		xor	al, al
  1672                              <1> ;		stc
  1673                              <1> ;		retn
  1674                              <1> ;
  1675                              <1> ;gdn_17:	; name match (with one of kernel device names)
  1676                              <1> ;		;
  1677                              <1> ;		; convert KDEV_NAME index to 
  1678                              <1> ;		; KDEV_NUMBER index
  1679                              <1> ;		; (different names are used for same devices)
  1680                              <1> ;		; (example: "COM1" & "TTY8" = device number 18)
  1681                              <1> ;		mov	ebx, eax ; < 256
  1682                              <1> ;		mov	al, [KDEV_NUMBER+ebx]
  1683                              <1> ;
  1684                              <1> ;		; check if empty dev entry in the list
  1685                              <1> ;		cmp	byte [DEV_OPENMODE+eax], 0
  1686                              <1> ;		ja	short gdn_18 ; it must be already set
  1687                              <1> ;
  1688                              <1> ;		; (re)set device name and access flags
  1689                              <1> ;		; (remain open work will be easy after that)
  1690                              <1> ;		; (NOTE: here, data will be copied to bss section)
  1691                              <1> ;		mov	bl, al
  1692                              <1> ;		sub	edi, 8 ; kernel device name address (data)
  1693                              <1> ;		shl	bx, 2 
  1694                              <1> ;		mov	[DEV_NAME_PTR+ebx], edi ; (all) device names
  1695                              <1> ;		mov	bl, [KDEV_ACCESS+eax] ; kernel dev list (data)
  1696                              <1> ;		mov	[DEV_ACCESS+eax], bl ; (all) device list (bss)
  1697                              <1> ;gdn_18:
  1698                              <1> ;		inc	al ; 1 to NumOfKernelDevNames (<=7Fh)
  1699                              <1> ;		; eax = device index/entry number
  1700                              <1> ;		retn		
  1701                              <1> ;
  1702                              <1> ;gdn_19:	; name match (with one of installable device names)
  1703                              <1> ;		;
  1704                              <1> ;		; al = 0 to NumOfInstallableDevices - 1 (<=7Fh)
  1705                              <1> ;
  1706                              <1> ;		mov	ebx, eax
  1707                              <1> ;		add	bl, NumOfKernelDevices 	; < NUMOFDEVICES
  1708                              <1> ;
  1709                              <1> ;		; check if empty dev entry in the list
  1710                              <1> ;		cmp	byte [DEV_OPENMODE+ebx], 0
  1711                              <1> ;		ja	short gdn_20 ; it must be already set
  1712                              <1> ;
  1713                              <1> ;		; (re)set device name and access flags
  1714                              <1> ;		; (remain open work will be easy after that)
  1715                              <1> ;		sub	edi, 8 ; installable device name address
  1716                              <1> ;		shl	bx, 2 ;*4
  1717                              <1> ;		mov	[DEV_NAME_PTR+ebx], edi ; (all) device names
  1718                              <1> ;		shr	bx, 2
  1719                              <1> ;		mov	al, [IDEV_FLAGS+eax] ; installable dev list
  1720                              <1> ;		mov	[DEV_ACCESS+ebx], al ; (all) device list
  1721                              <1> ;gdn_20:	
  1722                              <1> ;		mov	al, bl
  1723                              <1> ;		; eax = device index/entry number ; < NUMOFDEVICES
  1724                              <1> ;		retn
  1725                              <1> 
  1726                              <1> ;lodsb_capitalize:
  1727                              <1> ;	; 07/10/2016 - TRDOS 386 (TRDOS v2.0)
  1728                              <1> ;	; INPUT -> [esi] = character
  1729                              <1> ;	;          edi = destination
  1730                              <1> ;	; OUTPUT -> AL contains capitalized character
  1731                              <1> ;	;	   esi = esi+1
  1732                              <1> ;	;	   edi = edi+1	
  1733                              <1> ;	; 
  1734                              <1> ;	lodsb	
  1735                              <1> ;	cmp	al, 61h
  1736                              <1> ;    	jb	short lodsb_cap_retn
  1737                              <1> ;     	cmp	al, 7Ah
  1738                              <1> ;     	ja	short lodsb_cap_retn
  1739                              <1> ;     	and	al, 0DFh
  1740                              <1> ;lodsb_cap_retn:
  1741                              <1> ;	stosb
  1742                              <1> ;	retn
  1743                              <1> 
  1744                              <1> ; 17/04/2021
  1745                              <1> ; ('device_open' procedure is disabled as temporary)
  1746                              <1> 
  1747                              <1> ;device_open:
  1748                              <1> ;	; 08/10/2016 - TRDOS 386 (TRDOS v2.0)
  1749                              <1> ;	; Complete device opening work for sysopen (device)
  1750                              <1> ;	;
  1751                              <1> ;	; INPUT -> 
  1752                              <1> ;	;	EAX = Device Number (AL)
  1753                              <1> ;	;        CL = Open mode (1 = read, 2 = write)
  1754                              <1> ;	;	 CH = Device access byte (bit 0 = 0)
  1755                              <1> ;	; OUTPUT ->
  1756                              <1> ;	;	EAX = Device Number
  1757                              <1> ;	;	CF = 0 -> device has been opened
  1758                              <1> ;	;	CF = 1 -> device could not be opened
  1759                              <1> ;	;
  1760                              <1> ;	;  Modified registers: ebx, (edx, ecx, esi, edi, ebp)
  1761                              <1> ;	;
  1762                              <1> ;
  1763                              <1> ;	mov	ebx, eax
  1764                              <1> ;	shl	bx, 2 ; *4
  1765                              <1> ;
  1766                              <1> ;	test	ch, 80h ; bit 7, installable device driver flag
  1767                              <1> ;	jz	short d_open_2 ; Kernel device
  1768                              <1> ;	; installable device
  1769                              <1> ;d_open_1:
  1770                              <1> ;       jmp	dword [ebx+IDEV_OADDR-4]
  1771                              <1> ;d_open_2:
  1772                              <1> ;	jmp	dword [ebx+KDEV_OADDR-4]
  1773                              <1> 
  1774                              <1> ; 17/04/2021
  1775                              <1> ; ('device_close' procedure is disabled as temporary)
  1776                              <1> 
  1777                              <1> ;device_close:
  1778                              <1> ;	; 08/10/2016 - TRDOS 386 (TRDOS v2.0)
  1779                              <1> ;	; Complete device closing work for sysclose (device)
  1780                              <1> ;	;
  1781                              <1> ;	; INPUT -> 
  1782                              <1> ;	;	EAX = Device Number (AL)
  1783                              <1> ;	;        CL = Open mode (1 = read, 2 = write)
  1784                              <1> ;	;	 CH = Device access byte (bit 0 = 0)
  1785                              <1> ;	; OUTPUT ->
  1786                              <1> ;	;	EAX = Device Number	
  1787                              <1> ;	;	CF = 0 -> device has been closed
  1788                              <1> ;	;	CF = 1 -> device could not be closed
  1789                              <1> ;	;
  1790                              <1> ;	; Modified registers: ebx, (edx, ecx, esi, edi, ebp)
  1791                              <1> ;	;
  1792                              <1> ;
  1793                              <1> ;	mov	ebx, eax
  1794                              <1> ;	shl	bx, 2 ; *4
  1795                              <1> ;
  1796                              <1> ;	test	ch, 80h ; bit 7, installable device driver flag
  1797                              <1> ;	jz	short d_close_2 ; Kernel device
  1798                              <1> ;	; installable device
  1799                              <1> ;d_close_1:
  1800                              <1> ;       jmp	dword [ebx+IDEV_CADDR-4]
  1801                              <1> ;d_close_2:
  1802                              <1> ;	jmp	dword [ebx+KDEV_CADDR-4]
  1803                              <1> 
  1804                              <1> ;rnull:
  1805                              <1> ;	; 07/10/2016 - TRDOS 386 (TRDOS v2.0)
  1806                              <1> ;	; read null (read from null device)
  1807                              <1> ;	retn
  1808                              <1> 
  1809                              <1> ;wnull:
  1810                              <1> ;	; 07/10/2016 - TRDOS 386 (TRDOS v2.0)
  1811                              <1> ;	; write null (write to null device)
  1812                              <1> ;	retn
  1813                              <1> 
  1814                              <1> dev_IRQ_service:
  1815                              <1> 	; 12/05/2017
  1816                              <1> 	; 13/04/2017
  1817                              <1> 	; 27/02/2017 - TRDOS 386 (TRDOS v2.0)
  1818                              <1> 	; INPUT ->
  1819                              <1> 	;	AL = IRQ Number (0 to 15)
  1820                              <1> 	;	
  1821 0001264B 53                  <1> 	push	ebx
  1822 0001264C 0FB6D8              <1> 	movzx	ebx, al
  1823 0001264F C0E302              <1> 	shl	bl, 2 ; * 4
  1824 00012652 8B9B[5C8E0100]      <1> 	mov	ebx, [ebx+DEV_INT_HNDLR]
  1825 00012658 21DB                <1> 	and 	ebx, ebx
  1826 0001265A 7404                <1>         jz	short dIRQ_s_retn
  1827 0001265C 50                  <1> 	push	eax
  1828                              <1> 
  1829 0001265D FFD3                <1> 	call	ebx
  1830                              <1> 
  1831 0001265F 58                  <1> 	pop	eax
  1832                              <1> dIRQ_s_retn:
  1833 00012660 5B                  <1> 	pop	ebx
  1834 00012661 C3                  <1> 	retn
  1835                              <1> 
  1836                              <1> set_dev_IRQ_service:
  1837                              <1> 	; 09/08/2022
  1838                              <1> 	; 29/07/2022 (TRDOS 386 Kernel v2.0.5)
  1839                              <1> 	; 13/04/2017 - TRDOS 386 (TRDOS v2.0)
  1840                              <1> 	;
  1841                              <1> 	; Set Device Interrupt Service
  1842                              <1> 	;
  1843                              <1> 	; INPUT ->
  1844                              <1> 	;	AL = IRQ Number
  1845                              <1> 	;	EBX = Hardware Interrupt Service Address
  1846                              <1> 	;
  1847                              <1> 	; Note: There is not a validation check here
  1848                              <1> 	;	because this procedure is called by
  1849                              <1> 	;	TRDOS 386 kernel !
  1850                              <1> 	;       (Even if a device driver does not exist
  1851                              <1> 	;	this setting may be used by sysaudio
  1852                              <1> 	;	and other system calls for hardware
  1853                              <1> 	;	components which use IRQ method for I/O.)
  1854                              <1> 	;
  1855                              <1> 	;push	esi
  1856 00012662 0FB6F0              <1> 	movzx	esi, al
  1857                              <1> 	;shl	si, 2 ; * 4
  1858                              <1> 	; 09/08/2022
  1859 00012665 C1E602              <1> 	shl	esi, 2 ; * 4
  1860 00012668 899E[5C8E0100]      <1> 	mov	[esi+DEV_INT_HNDLR], ebx
  1861                              <1> 	;pop	esi
  1862 0001266E C3                  <1> 	retn
  1863                              <1> 
  1864                              <1> sysaudio: ; AUDIO FUNCTIONS
  1865                              <1> 	; 29/12/2024
  1866                              <1> 	; 19/12/2024
  1867                              <1> 	; 23/08/2024 (TRDOS 386 v2.0.9) 
  1868                              <1> 	; 05/06/2024
  1869                              <1> 	; 04/06/2024
  1870                              <1> 	; 23/05/2024 (TRDOS 386 v2.0.8)
  1871                              <1>  	; 19/11/2023 (TRDOS 386 v2.0.7)
  1872                              <1> 	; 29/07/2022 (TRDOS 386 v2.0.5)
  1873                              <1> 	; 12/02/2021 (TRDOS 386 v2.0.3) 
  1874                              <1> 	; 28/07/2020
  1875                              <1> 	; 27/07/2020
  1876                              <1> 	; 10/10/2017
  1877                              <1> 	; 22/06/2017
  1878                              <1> 	; 28/05/2017, 04/06/2017, 05/06/2017, 10/06/2017
  1879                              <1> 	; 01/05/2017, 12/05/2017, 15/05/2017, 20/05/2017
  1880                              <1> 	; 21/04/2017, 22/04/2017, 23/04/2017, 24/04/2017
  1881                              <1> 	; 10/04/2017, 13/04/2017, 14/04/2017, 16/04/2017
  1882                              <1> 	; 03/04/2017 (VIA VT8237R)
  1883                              <1> 	; 01/04/2016 (trdosk6.s -> tdosk8.s)
  1884                              <1> 	; 16/05/2016 - TRDOS 386 (TRDOS v2.0)
  1885                              <1> 	;
  1886                              <1> 	; Inputs:
  1887                              <1> 	;
  1888                              <1> 	;	BH = 0 -> Beep (PC Speaker)
  1889                              <1> 	;	     BL = Duration Counter (1 for 1/64 second)
  1890                              <1> 	;	     CX = Frequency Divisor (1193180/Frequency)
  1891                              <1> 	;		 (1331 for 886 Hz)
  1892                              <1> 	;
  1893                              <1> 	;	01/04/2017	
  1894                              <1> 	;
  1895                              <1> 	; 	BH = 1 -> DETECT (& ENABLE) AUDIO DEVICE
  1896                              <1> 	;	     BL = 0 : PC SPEAKER
  1897                              <1> 	;		  1 : SOUND BLASTER 16
  1898                              <1> 	;		  2 : INTEL AC'97
  1899                              <1> 	;		  3 : VIA VT8237R (VT8233)
  1900                              <1> 	;		  4 : INTEL HDA
  1901                              <1> 	;	      5-FEh : unknown/invalid
  1902                              <1> 	;	        ; 04/06/2017
  1903                              <1> 	;		FFh : Get current audio device id
  1904                              <1> 	;
  1905                              <1> 	; 	BH = 2 -> ALLOCATE AUDIO BUFFER (for user)
  1906                              <1> 	;		ECX = Audio Buffer Size (must be equal to
  1907                              <1> 	;		      the half of DMA buffer size) 
  1908                              <1> 	;		EDX = Virtual Address of the buffer
  1909                              <1> 	;		      (This is not DMA buffer!)
  1910                              <1> 	;
  1911                              <1> 	;	BH = 3 -> INITIALIZE AUDIO DEVICE
  1912                              <1> 	;	     BL = 0,2 -> for Signal Response Byte
  1913                              <1> 	;	     	CL = Signal Response Byte Value (fixed)
  1914                              <1> 	;				if BL = 0
  1915                              <1> 	;	             auto increment of S.R.B. value
  1916                              <1> 	;			 	if BL = 2
  1917                              <1> 	;	        EDX = Signal Response (Return) Byte Address
  1918                              <1> 	;	     	   			
  1919                              <1> 	;	     BL = 1 for CallBack Method
  1920                              <1> 	;	    	EDX = CallBack Service Address (Virtual)
  1921                              <1> 	;
  1922                              <1> 	;	     BL > 2 -> invalid function
  1923                              <1> 	;
  1924                              <1> 	;	    (Audio buffer must be allocated before
  1925                              <1> 	;	     initialization.)
  1926                              <1> 	;
  1927                              <1> 	;	BH = 4 -> START TO PLAY
  1928                              <1> 	;	     BL = Mode
  1929                              <1> 	;		  Bit 0 = mono/stereo (1 = stereo)
  1930                              <1> 	;		  Bit 1 = 8 bit / 16 bit (1 = 16 bit)
  1931                              <1> 	;	     CX = Sampling Rate (Hz)
  1932                              <1> 	;
  1933                              <1> 	;	BH = 5 -> PAUSE
  1934                              <1> 	;	     BL = Any
  1935                              <1> 	;
  1936                              <1> 	;	BH = 6 -> CONTINUE TO PLAY
  1937                              <1> 	;	     BL = Any
  1938                              <1> 	;
  1939                              <1> 	;	BH = 7 -> STOP
  1940                              <1> 	;	     BL = Any
  1941                              <1> 	;
  1942                              <1> 	;	BH = 8 -> RESET 
  1943                              <1> 	;	     BL = Any
  1944                              <1> 	;
  1945                              <1> 	;	BH = 9 -> CANCEL (CALLBACK or S.R.B. SERVICE)
  1946                              <1> 	;	     BL = Any	
  1947                              <1> 	;	
  1948                              <1> 	;	BH = 10 -> DEALLOCATE AUDIO BUFFER (for user)
  1949                              <1> 	;	     BL = Any
  1950                              <1> 	;
  1951                              <1> 	;	BH = 11 -> SET VOLUME LEVEL
  1952                              <1> 	;	     BL: (Bit 0 to 6)
  1953                              <1> 	;		  0 = Master (Playback, Lineout) volume
  1954                              <1> 	;		  1 = PCM out volume ; 23/05/2024
  1955                              <1> 	;	     CL = Left Channel Volume (0 to 31 max)
  1956                              <1> 	;	     CH = Right Channel Volume (0 to 31 max)
  1957                              <1> 	;	
  1958                              <1> 	;	     Note: If BL >= 80h (Bit 7 of BL is set),
  1959                              <1> 	;	     volume level will be set for next playing
  1960                              <1> 	;	     (actual volume level will not be changed
  1961                              <1> 	;	     immediately)
  1962                              <1> 	;
  1963                              <1> 	;	BH = 12 -> DISABLE AUDIO DEVICE
  1964                              <1> 	;	     (reset audio device and unlink dma buffer)
  1965                              <1> 	;	     BL = Any
  1966                              <1> 	;
  1967                              <1> 	;    	12/05/2017
  1968                              <1> 	;	BH = 13 -> MAP DMA BUFFER TO USER
  1969                              <1> 	;	    (for direct access to system's dma buffer)
  1970                              <1> 	;
  1971                              <1> 	;	     ECX = map size in bytes 
  1972                              <1> 	;		  (will be rounded up to page borders)
  1973                              <1> 	;	     EDX = Virtual Address of the buffer
  1974                              <1> 	;		  (Will be rounded up to page borders)
  1975                              <1> 	;
  1976                              <1> 	;	05/06/2017
  1977                              <1> 	;    	04/06/2017
  1978                              <1> 	;	BH = 14 -> GET AUDIO DEVICE INFO
  1979                              <1> 	;	     BL: 0 = Audio Controller Info
  1980                              <1> 	;	     ; 19/11/2023
  1981                              <1> 	;	     BL: 1 = Audio (AC'97) Codec Info
  1982                              <1> 	;	     BL > 1 = Invalid for now! 
  1983                              <1> 	;
  1984                              <1> 	;	22/06/2017	
  1985                              <1> 	;	BH = 15 -> GET CURRENT SOUND DATA (for graphics)
  1986                              <1> 	;	     BL: 0 -> PCM OUT data
  1987                              <1> 	;	       > 0 -> Invalid for now!
  1988                              <1> 	;	     ECX = 0 -> Get DMA Buffer Pointer
  1989                              <1> 	;		 EDX = Not Used
  1990                              <1> 	;	     ECX > 0 -> Byte count for buffer (EDX)
  1991                              <1> 	;	         EDX = Buffer Address (Virtual)
  1992                              <1> 	;
  1993                              <1> 	;	10/10/2017	
  1994                              <1> 	;	BH = 16 -> UPDATE DMA BUFFER DATA
  1995                              <1> 	;		   (by using the Audio Buffer content)
  1996                              <1> 	;	     BL = 0 : Update dma half buffer in sequence
  1997                              <1> 	;		      (automatic destination)	
  1998                              <1> 	;		  1 : Update 1st half of the dma buffer
  1999                              <1> 	;		  2 : Update 2nd half of the dma buffer
  2000                              <1> 	;		  3-FEh: Invalid!
  2001                              <1> 	;		  FFh = Get current flag value
  2002                              <1> 	;			(Half buffer number -1)
  2003                              <1> 	;
  2004                              <1> 	;	24/05/2024
  2005                              <1> 	;	BH = 17 -> GET VOLUME LEVEL
  2006                              <1> 	;	     BL:  0 = Master (Playback, Lineout) volume
  2007                              <1> 	;		  1 = PCM out volume
  2008                              <1> 	;
  2009                              <1> 	; Outputs:
  2010                              <1> 	;
  2011                              <1> 	;	For BH = 0 -> Beep
  2012                              <1> 	;	    None
  2013                              <1> 	;
  2014                              <1> 	;	01/04/2017
  2015                              <1> 	;
  2016                              <1> 	; 	For BH = 1 -> DETECT (& ENABLE) AUDIO DEVICE
  2017                              <1> 	;	    AH = 0 : PC SPEAKER
  2018                              <1> 	;		 1 : SOUND BLASTER 16
  2019                              <1> 	;		 2 : INTEL AC'97
  2020                              <1> 	;		 3 : VIA VT8237R (VT8233)
  2021                              <1> 	;		 4 : INTEL HDA
  2022                              <1> 	;	      5-FFh : unknown/invalid
  2023                              <1> 	;	    AL = mode status
  2024                              <1> 	;		 bit 0 = mono /stereo (1 = stereo)
  2025                              <1> 	;		 bit 1 = 8 bit / 16 bit (1 = 16 bit)
  2026                              <1> 	;	    04/06/2017
  2027                              <1> 	;	    EBX = PCI DEVICE/VENDOR ID (if >0)
  2028                              <1> 	;		 (BX = VENDOR ID) 
  2029                              <1> 	;	    (if CF = 1 -> Error code in EAX)
  2030                              <1> 	;
  2031                              <1> 	; 	For BH = 2 -> ALLOCATE AUDIO BUFFER (for user)
  2032                              <1> 	;	    EAX = Physical Address of the buffer
  2033                              <1> 	;	    (if CF = 1 -> Error code in EAX)
  2034                              <1> 	;
  2035                              <1> 	;	For BH = 3 -> INITIALIZE AUDIO DEVICE
  2036                              <1> 	;	    (if CF = 1 -> Error code in EAX)
  2037                              <1> 	;
  2038                              <1> 	;	For BH = 4 -> START TO PLAY
  2039                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  2040                              <1> 	;
  2041                              <1> 	;	For BH = 5 -> PAUSE
  2042                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  2043                              <1> 	;
  2044                              <1> 	;	For BH = 6 -> CONTINUE TO PLAY
  2045                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  2046                              <1> 	;
  2047                              <1> 	;	For BH = 7 -> STOP
  2048                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  2049                              <1> 	;
  2050                              <1> 	;	For BH = 8 -> RESET 
  2051                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  2052                              <1> 	;
  2053                              <1> 	;	For BH = 9 -> CANCEL (CALLBACK or S.R.B. SERVICE)
  2054                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  2055                              <1> 	;	
  2056                              <1> 	;	For BH = 10 -> DEALLOCATE AUDIO BUFFER (for user)
  2057                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  2058                              <1> 	;
  2059                              <1> 	;	For BH = 11 -> SET VOLUME LEVEL
  2060                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  2061                              <1> 	;
  2062                              <1> 	;	For BH = 12 -> DISABLE AUDIO DEVICE
  2063                              <1> 	;	    none (if CF = 1 -> Error code in EAX)
  2064                              <1> 	; 
  2065                              <1> 	;    	12/05/2017
  2066                              <1> 	;	For BH = 13 -> MAP DMA BUFFER TO USER
  2067                              <1> 	;	    EAX = Physical Address of the buffer
  2068                              <1> 	;	    (if CF = 1 -> Error code in EAX)
  2069                              <1> 	;
  2070                              <1> 	;    	04/06/2017
  2071                              <1> 	;	For BH = 14 -> GET AUDIO DEVICE INFO
  2072                              <1> 	;	(for BL = 0) ; 05/06/2017	
  2073                              <1> 	;	    EAX = IRQ Number in AL
  2074                              <1> 	;		  Audio Device Number in AH 
  2075                              <1> 	;	    EBX = DEV/VENDOR ID
  2076                              <1> 	;		 (DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV)
  2077                              <1> 	;	    ECX = BUS/DEV/FN 
  2078                              <1> 	;		 (00000000BBBBBBBBDDDDDFFF00000000)
  2079                              <1> 	;	    EDX = NABMBAR/NAMBAR (for AC97)
  2080                              <1> 	;		  (Low word, DX = NAMBAR address)
  2081                              <1> 	;	    EDX = Base IO Addr (DX) for SB16 & VT8233
  2082                              <1> 	;	    (if CF = 1 -> Error code in EAX)
  2083                              <1> 	;	                 (ERR_DEV_NOT_RDY = 15)
  2084                              <1> 	;	(for BL = 1) -for AC97- ; 19/11/2023
  2085                              <1> 	;	    EAX = Extended Audio ID (MX28) in AX
  2086                              <1> 	;	     AX bit 0 - VRA bit
  2087                              <1> 	;	     HW of EAX = PCM output sample rate (HZ)
  2088                              <1> 	;	    EBX = VENDOR ID 1 (BX), VENDOR ID 2 (HW)
  2089                              <1> 	;	    (if CF = 1 -> Error code in EAX)	
  2090                              <1> 	;	                 (ERR_DEV_NOT_RDY = 15)
  2091                              <1> 	;	    Note: EAX & EBX = 0 (for SB16,VIA,HDA)
  2092                              <1>  	;
  2093                              <1> 	;	22/06/2017	
  2094                              <1> 	;	For BH = 15 -> GET CURRENT SOUND DATA
  2095                              <1> 	;			 (for graphics)
  2096                              <1> 	;	(for BL = 0)
  2097                              <1> 	;	 If ECX input is 0 
  2098                              <1> 	;	    EAX = DMA Buffer Current Position (Offset)
  2099                              <1> 	;	 If ECX input >  0
  2100                              <1> 	;	    EAX = Actual transfer count
  2101                              <1> 	;	    (Sound samples will be copied from 
  2102                              <1> 	;	     Current DMA Buffer Position to EDX
  2103                              <1> 	;	     virtual address as EAX bytes.)
  2104                              <1> 	;	 ((If CF = 1 ->  Error code in EAX))
  2105                              <1> 	;
  2106                              <1> 	;	10/10/2017	
  2107                              <1> 	;	For BH = 16 -> UPDATE DMA BUFFER DATA
  2108                              <1> 	;	    EAX = 0, if the updated (or current)
  2109                              <1> 	;		     half buffer is DMA half buffer 1
  2110                              <1> 	;	    EAX = 1, if the updated (or current)
  2111                              <1> 	; 		     half buffer is DMA half buffer 2
  2112                              <1> 	;	    (If CF = 1 -> Error code in EAX)
  2113                              <1> 	;
  2114                              <1> 	;	24/05/2024
  2115                              <1> 	;	For BH = 17 -> GET VOLUME LEVEL
  2116                              <1> 	;	    IF BL input is 0
  2117                              <1> 	;		Master (Playback, Lineout) volume
  2118                              <1> 	;	    If BL input is 1
  2119                              <1> 	;		PCM out volume
  2120                              <1> 	;	    If BL input > 1
  2121                              <1> 	;		Invalid for now ; 24/05/2024
  2122                              <1> 	;
  2123                              <1> 	;	    CL = Left Channel Volume (0 to 31 max)
  2124                              <1> 	;	    CH = Right Channel Volume (0 to 31 max)
  2125                              <1> 	;
  2126                              <1> 
  2127 0001266F 80FF12              <1> 	cmp	bh, AUDIO1L/4
  2128 00012672 0F83DCA7FFFF        <1> 	jnb	sysret
  2129                              <1> 
  2130 00012678 C0E702              <1> 	shl	bh, 2 ; *4	
  2131 0001267B 0FB6F7              <1> 	movzx	esi, bh
  2132                              <1> 
  2133                              <1> 	; 22/04/2017
  2134 0001267E 31C0                <1> 	xor	eax, eax
  2135 00012680 A3[74940100]        <1> 	mov	[u.r0], eax  ; 0
  2136                              <1> 		
  2137 00012685 FF96[90260100]      <1> 	call	dword [esi+AUDIO1]
  2138                              <1> 	;jc	error
  2139 0001268B E9C4A7FFFF          <1> 	jmp	sysret	
  2140                              <1> 
  2141 00012690 [77230000]          <1> AUDIO1:	dd	_beep ; 12/02/2021
  2142                              <1> 	;dd	beep ; FUNCTION = 0 (bl = Duration Counter
  2143                              <1> 		     ; 		     cx = Frequency Divisor
  2144 00012694 [D8260100]          <1> 	dd	soundc_detect
  2145 00012698 [6D270100]          <1> 	dd	sound_alloc
  2146 0001269C [38280100]          <1> 	dd	soundc_init
  2147 000126A0 [1C2A0100]          <1> 	dd	sound_play
  2148 000126A4 [A92A0100]          <1> 	dd	sound_pause
  2149 000126A8 [D32A0100]          <1> 	dd	sound_continue
  2150 000126AC [FD2A0100]          <1> 	dd	sound_stop
  2151 000126B0 [282B0100]          <1> 	dd	soundc_reset
  2152 000126B4 [5B2B0100]          <1> 	dd	soundc_cancel
  2153 000126B8 [812B0100]          <1> 	dd	sound_dalloc
  2154 000126BC [AC2B0100]          <1> 	dd	sound_volume
  2155 000126C0 [EC2B0100]          <1> 	dd	soundc_disable
  2156 000126C4 [622C0100]          <1> 	dd	sound_dma_map
  2157 000126C8 [D02C0100]          <1> 	dd	soundc_info
  2158 000126CC [542D0100]          <1> 	dd	sound_data
  2159 000126D0 [F62D0100]          <1> 	dd	sound_update
  2160 000126D4 [782E0100]          <1> 	dd	sound_getvol ; 24/05/2024
  2161                              <1> %if 0
  2162                              <1> 	dd	sound_dmaclear ; 29/12/2024
  2163                              <1> %endif
  2164                              <1> 	
  2165                              <1> AUDIO1L	EQU	$ - AUDIO1
  2166                              <1> 
  2167                              <1> soundc_detect:
  2168                              <1> 	; FUNCTION = 1
  2169                              <1> 	; bl = Audio device type number 
  2170                              <1> 	; (0 = pc speaker, 1 = sound blaster 16, 2 = intel ac97
  2171                              <1> 	;  3 = via vt823x, 4 = intel HDA, 0FFh = any)
  2172                              <1> 	
  2173                              <1> 	; 04/06/2017
  2174 000126D8 8A25[ED8E0100]      <1> 	mov	ah, [audio_device]
  2175 000126DE 80FBFF              <1> 	cmp	bl, 0FFh ; get current audio device id
  2176 000126E1 7408                <1> 	je	short sysaudio0
  2177                              <1> 
  2178 000126E3 20E4                <1> 	and	ah, ah
  2179 000126E5 741E                <1> 	jz	short soundc_get_dev
  2180                              <1> 
  2181 000126E7 38DC                <1> 	cmp	ah, bl
  2182 000126E9 7567                <1> 	jne	short soundc_dev_err
  2183                              <1> 
  2184                              <1> sysaudio0:
  2185 000126EB A0[258F0100]        <1> 	mov	al, [audio_mode]
  2186                              <1> sysaudio1:
  2187 000126F0 A3[74940100]        <1> 	mov	[u.r0], eax
  2188 000126F5 8B1D[F88E0100]      <1> 	mov	ebx, [audio_vendor] ; (DEVICE/VENDOR ID)
  2189 000126FB 8B2D[70940100]      <1> 	mov	ebp, [u.usp]
  2190 00012701 895D10              <1> 	mov	[ebp+16], ebx  ; ebx
  2191 00012704 C3                  <1> 	retn
  2192                              <1> 
  2193                              <1> soundc_get_dev:
  2194                              <1> 	; 28/05/2017
  2195                              <1> 	; 03/04/2017, 24/04/2017
  2196 00012705 C605[EC8E0100]00    <1> 	mov	byte [audio_pci], 0
  2197 0001270C 80FB03              <1> 	cmp	bl, 3 ; VIA VT8233 (VT8237R) Audio Controller & AC97 Codec
  2198                              <1> 	;jne	short soundc_get_dev_sb
  2199                              <1> 	; 28/05/2017
  2200 0001270F 7220                <1> 	jb	short soundc_get_dev_sb
  2201 00012711 773F                <1> 	ja	short soundc_dev_err  ; temporary (28/05/2017)
  2202                              <1> 	;
  2203 00012713 E895180000          <1> 	call	DetectVT8233
  2204 00012718 7238                <1> 	jc	short soundc_dev_err
  2205                              <1> 	; eax = 0
  2206                              <1> 
  2207                              <1> 	;mov	ebx, [audio_vendor]
  2208                              <1> 	; ebx = DEVICE/VENDOR ID
  2209                              <1> 	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
  2210                              <1> 
  2211 0001271A B003                <1> 	mov	al, 3  ; VIA VT8237R (VT3233) Audio Controller
  2212 0001271C 88C4                <1> 	mov	ah, al
  2213                              <1> 
  2214                              <1> soundc_get_pci_dev_ok: ; 28/05/2017
  2215 0001271E FE05[EC8E0100]      <1> 	inc	byte [audio_pci] ; = 1
  2216                              <1> soundc_get_dev_ok:
  2217                              <1> 
  2218                              <1> soundc_get_dev_sb16_ok:
  2219 00012724 A2[ED8E0100]        <1> 	mov	[audio_device], al
  2220 00012729 8825[258F0100]      <1> 	mov	[audio_mode], ah ; stereo (bit0), 16 bit (bit1) capability
  2221 0001272F EBBF                <1> 	jmp	short sysaudio1
  2222                              <1> 
  2223                              <1> soundc_get_dev_sb:
  2224                              <1> 	; 24/04/2017
  2225 00012731 80FB01              <1> 	cmp	bl, 1 ; Sound Blaster 16
  2226 00012734 750E                <1> 	jne	short soundc_get_dev_ich ; 28/05/2017
  2227                              <1> 	;
  2228 00012736 E8461D0000          <1> 	call	DetectSB
  2229 0001273B 7215                <1> 	jc	short soundc_dev_err
  2230 0001273D B801030000          <1> 	mov	eax, 0301h ; Sound Blaster 16
  2231 00012742 EBE0                <1> 	jmp	short soundc_get_dev_sb16_ok
  2232                              <1> 
  2233                              <1> soundc_get_dev_ich:
  2234                              <1> 	; 28/05/2017
  2235                              <1> 	;cmp	bl, 2 ; Intel AC'97 Audio Controller (ICH)
  2236                              <1> 	;jne	short soundc_dev_err ; Temporary  (28/05/2017)
  2237                              <1> 	;			     ; (Here will be modified just after
  2238                              <1> 	;			     ; new sound card code will be ready!)
  2239 00012744 E84F180000          <1> 	call	DetectICH
  2240 00012749 7207                <1> 	jc	short soundc_dev_err
  2241                              <1> 	;
  2242 0001274B B802030000          <1> 	mov	eax, 0302h ; AC'97 (ICH)
  2243 00012750 EBCC                <1> 	jmp	short soundc_get_pci_dev_ok
  2244                              <1> 
  2245                              <1> soundc_dev_err:
  2246 00012752 B80F000000          <1> 	mov	eax, ERR_DEV_NOT_RDY ; Device not ready !
  2247                              <1> 	; 29/07/2022
  2248                              <1> 	;sub	eax, eax
  2249                              <1> 	;mov	al, ERR_DEV_NOT_RDY
  2250 00012757 EB05                <1> 	jmp	short sysaudio_err
  2251                              <1> 
  2252                              <1> soundc_respond_err:
  2253                              <1> 	; ERR_TIME_OUT ; 'time out !' error
  2254 00012759 B819000000          <1> 	mov	eax, ERR_DEV_NOT_RESP ; 'device not responding !' error
  2255                              <1> 	; 29/07/2022
  2256                              <1> 	;sub	eax, eax
  2257                              <1> 	;mov	al, ERR_DEV_NOT_RESP
  2258                              <1> sysaudio_err:
  2259 0001275E A3[74940100]        <1> 	mov	[u.r0], eax
  2260 00012763 A3[E0940100]        <1> 	mov	[u.error], eax
  2261 00012768 E9C7A6FFFF          <1> 	jmp	error
  2262                              <1> 
  2263                              <1> sound_alloc:
  2264                              <1> 	; FUNCTION = 2
  2265                              <1> 	; ecx = audio buffer size (in bytes)
  2266                              <1> 	; edx = audio buffer address (virtual)
  2267                              <1> 	; 25/11/2023
  2268                              <1> 	; 27/07/2020
  2269                              <1> 	; 28/05/2017
  2270                              <1> 	; 01/05/2017, 15/05/2017
  2271                              <1> 	; 21/04/2017, 24/04/2017
  2272 0001276D 803D[EC8E0100]00    <1> 	cmp	byte [audio_pci], 0
  2273 00012774 770F                <1> 	ja	short snd_alloc_0
  2274                              <1> 	; Max. 64KB DMA buffer !!!
  2275 00012776 81F900800000        <1> 	cmp	ecx, 32768
  2276 0001277C 760F                <1> 	jna	short snd_alloc_6
  2277                              <1> 	; 25/11/2023
  2278                              <1> sound_buff_error:
  2279 0001277E B82E000000          <1> 	mov	eax, ERR_BUFFER ; Buffer error !
  2280                              <1> 	; 29/07/2022
  2281                              <1> 	;sub	eax, eax
  2282                              <1> 	;mov	al, ERR_BUFFER
  2283 00012783 EBD9                <1> 	jmp	short sysaudio_err
  2284                              <1> snd_alloc_0:	
  2285                              <1> 	; 25/11/2023
  2286                              <1> 	; Max 128KB DMA buffer size (2 half buffers)
  2287 00012785 81F900000100        <1> 	cmp	ecx, 65536
  2288 0001278B 77F1                <1> 	ja	short sound_buff_error
  2289                              <1> snd_alloc_6:
  2290                              <1> 	; 15/05/2017
  2291 0001278D 81F900100000        <1> 	cmp	ecx, 4096 ; PAGE_SIZE
  2292 00012793 72E9                <1> 	jb	short sound_buff_error
  2293                              <1> 	;
  2294 00012795 A1[008F0100]        <1> 	mov	eax, [audio_buffer] ; audio buffer address (current)
  2295 0001279A 09C0                <1> 	or	eax, eax
  2296 0001279C 7446                <1> 	jz	short snd_alloc_2
  2297                              <1> 	; audio buffer exists !
  2298 0001279E 8A1D[C5940100]      <1> 	mov	bl, [u.uno]
  2299 000127A4 3A1D[198F0100]      <1> 	cmp	bl, [audio_user]
  2300                              <1> 	;jne	sndc_owner_error ; not owner !
  2301                              <1> 	; 25/11/2023
  2302 000127AA 7405                <1> 	je	short snd_alloc_7
  2303 000127AC E9FB000000          <1> 	jmp	sndc_owner_error ; not owner !
  2304                              <1> snd_alloc_7:
  2305 000127B1 39D0                <1> 	cmp	eax, edx ; same virtual buffer address ?
  2306 000127B3 7508                <1> 	jne	short snd_alloc_1
  2307 000127B5 3B0D[088F0100]      <1> 	cmp	ecx, [audio_buff_size]
  2308 000127BB 7469                <1> 	je	short snd_alloc_3 ; Nothing to do !
  2309                              <1> 				  ; Buffer has been set already!
  2310                              <1> snd_alloc_1:
  2311 000127BD 51                  <1> 	push	ecx
  2312 000127BE 52                  <1> 	push	edx
  2313 000127BF 89C3                <1> 	mov	ebx, eax ; audio buffer address (current)
  2314 000127C1 8B0D[088F0100]      <1> 	mov	ecx, [audio_buff_size]
  2315 000127C7 E87F38FFFF          <1> 	call	deallocate_user_pages
  2316 000127CC 5A                  <1> 	pop	edx
  2317 000127CD 59                  <1> 	pop	ecx
  2318 000127CE 31C0                <1> 	xor	eax, eax ; 0
  2319 000127D0 A3[008F0100]        <1> 	mov	[audio_buffer], eax  ; 0
  2320 000127D5 A3[048F0100]        <1>  	mov	[audio_p_buffer], eax  ; 0
  2321 000127DA A3[088F0100]        <1>  	mov	[audio_buff_size], eax
  2322 000127DF A2[198F0100]        <1> 	mov	[audio_user], al ; 0
  2323                              <1> snd_alloc_2:
  2324 000127E4 89D3                <1> 	mov	ebx, edx
  2325                              <1> 	; 01/05/2017
  2326                              <1> 	;mov	edx, ~PAGE_OFF ; truncating page offsets
  2327                              <1> 	;		       ; for aligning to page borders
  2328                              <1> 	;;and	eax, edx
  2329                              <1> 	;and	ebx, edx
  2330                              <1> 	; 26/11/2023
  2331                              <1> 	;and	ecx, edx
  2332 000127E6 81E300F0FFFF        <1> 	and	ebx, ~PAGE_OFF
  2333 000127EC 89CA                <1> 	mov	edx, ecx
  2334                              <1> 	; 15/05/2017
  2335                              <1> 	; EAX = Beginning address (physical)
  2336                              <1> 	; EAX = 0 -> Allocate mem block from the 1st proper aperture	
  2337                              <1> 	; ECX = Number of bytes to be allocated
  2338 000127EE E80035FFFF          <1> 	call	allocate_memory_block
  2339 000127F3 7289                <1> 	jc	short sound_buff_error
  2340                              <1> 
  2341                              <1> 	; EAX = Physical address of the allocated memory block
  2342                              <1> 	; ECX = Allocated bytes (as rounded up to page border)
  2343                              <1> 	; EBX = Virtual address (as truncated to page border)
  2344 000127F5 52                  <1> 	push	edx ; 26/11/2023
  2345 000127F6 50                  <1> 	push	eax
  2346 000127F7 53                  <1> 	push	ebx
  2347 000127F8 51                  <1> 	push	ecx
  2348 000127F9 E83539FFFF          <1> 	call	allocate_user_pages
  2349 000127FE 59                  <1> 	pop	ecx
  2350 000127FF 5B                  <1> 	pop	ebx
  2351 00012800 58                  <1> 	pop	eax
  2352 00012801 5A                  <1> 	pop	edx ; 26/11/2023
  2353 00012802 722A                <1> 	jc	short snd_alloc_4  ; insufficient memory, buff error
  2354                              <1> 	; eax = physical address of the user's audio buffer
  2355                              <1> 	; ebx = virtual address of the user's audio buffer
  2356                              <1> 	; 26/11/2023
  2357                              <1> 	; ecx = allocated buffer size (in bytes)
  2358                              <1> 	;		 -rounded up to page boundary-
  2359                              <1> 	; edx = requested buffer size (in bytes)
  2360 00012804 A3[048F0100]        <1> 	mov	[audio_p_buffer], eax
  2361 00012809 891D[008F0100]      <1> 	mov	[audio_buffer], ebx
  2362                              <1> 	; 26/11/2023
  2363                              <1> 	;mov	ecx, edx
  2364                              <1> 	;; 25/11/2023
  2365                              <1> 	;cmp	ecx, 65536
  2366                              <1> 	;jb	short snd_alloc_5
  2367                              <1> 	;dec	ecx
  2368                              <1> 	;; ecx = 65535
  2369                              <1> 	;; (DMA half buffer's sample count must be < 65536)
  2370                              <1> ;snd_alloc_5:
  2371                              <1>  	;mov	[audio_buff_size], ecx
  2372                              <1> 	; 26/11/2023
  2373 0001280F 8915[088F0100]      <1> 	mov	[audio_buff_size], edx
  2374                              <1> 	;
  2375 00012815 8A15[C5940100]      <1> 	mov	dl, [u.uno]
  2376 0001281B 8815[198F0100]      <1> 	mov	[audio_user], dl
  2377 00012821 A3[74940100]        <1> 	mov	[u.r0], eax
  2378                              <1> snd_alloc_3:
  2379                              <1> 	; 27/07/2020
  2380 00012826 C605[188F0100]00    <1> 	mov	byte [audio_flag], 0 ; clear dma half buffer flag
  2381                              <1> 	;	
  2382 0001282D C3                  <1> 	retn
  2383                              <1> snd_alloc_4:
  2384                              <1> 	; 15/05/2017
  2385                              <1> 	; EAX = Beginning address (physical)
  2386                              <1> 	; ECX = Number of bytes to be deallocated
  2387 0001282E E8DA36FFFF          <1> 	call	deallocate_memory_block
  2388 00012833 E946FFFFFF          <1> 	jmp	sound_buff_error ; insufficient memory, buff error
  2389                              <1> 
  2390                              <1> soundc_init:
  2391                              <1> 	; FUNCTION = 3 
  2392                              <1> 	; bl = method (0= s.r.b., 1= callback, 2= auto incr s.r.b.)
  2393                              <1> 	; cl = signal response byte (initial or fixed) value
  2394                              <1> 	; edx = signal response byte or callback address
  2395                              <1> 	; 05/06/2024
  2396                              <1> 	; 04/06/2024
  2397                              <1> 	; 04/12/2023
  2398                              <1> 	; 02/12/2023
  2399                              <1> 	; 07/08/2022
  2400                              <1> 	; 29/07/2022
  2401                              <1> 	; 27/07/2020
  2402                              <1> 	; 28/05/2017
  2403                              <1> 	; 12/05/2017, 20/05/2017
  2404                              <1> 	; 22/04/2017, 23/04/2017, 24/04/2017
  2405                              <1> 	; 13/04/2017, 14/04/2017, 16/04/2017, 21/04/2017
  2406                              <1> 	; 03/04/2017, 10/04/2017
  2407                              <1> 
  2408 00012838 A0[ED8E0100]        <1> 	mov	al, [audio_device]
  2409 0001283D 20C0                <1> 	and	al, al
  2410 0001283F 754A                <1> 	jnz	short sndc_init6
  2411                              <1> 	;
  2412 00012841 C605[EC8E0100]00    <1> 	mov	byte [audio_pci], 0
  2413 00012848 52                  <1> 	push	edx
  2414 00012849 53                  <1> 	push	ebx
  2415 0001284A 51                  <1> 	push	ecx
  2416 0001284B E8311C0000          <1> 	call	DetectSB
  2417 00012850 7213                <1> 	jc	short sndc_init8
  2418 00012852 66B80103            <1> 	mov	ax, 0301h ; Sound Blaster 16
  2419 00012856 EB1E                <1> 	jmp	short sndc_init7
  2420                              <1> 
  2421                              <1> sndc_init11:
  2422                              <1> 	; 28/05/2017
  2423 00012858 E83B170000          <1> 	call	DetectICH ; Detect AC'97 (ICH) Audio Controller
  2424 0001285D 7217                <1> 	jc	short sndc_init7
  2425 0001285F 66B80203            <1> 	mov	ax, 0302h ; Intel AC'97 Audio Device
  2426 00012863 EB0B                <1> 	jmp	short sndc_init12 ; (PCI device)
  2427                              <1> 
  2428                              <1> sndc_init8:
  2429 00012865 E843170000          <1> 	call	DetectVT8233
  2430                              <1> 	;jc	short sndc_init7
  2431                              <1> 	; 29/07/2022
  2432 0001286A 72EC                <1> 	jc	short sndc_init11 ; 28/05/2017
  2433                              <1> 
  2434                              <1> 	; eax = 0
  2435 0001286C B003                <1> 	mov	al, 3	; VIA VT8237R (VT8233) Audio Controller
  2436 0001286E 88C4                <1> 	mov	ah, al
  2437                              <1> 
  2438                              <1> sndc_init12:
  2439 00012870 FE05[EC8E0100]      <1> 	inc	byte [audio_pci] ; = 1
  2440                              <1> sndc_init7:
  2441 00012876 59                  <1> 	pop	ecx
  2442 00012877 5B                  <1> 	pop	ebx
  2443 00012878 5A                  <1> 	pop	edx
  2444                              <1> 	;jc	soundc_dev_err
  2445                              <1> 	; 29/07/2022
  2446 00012879 7305                <1> 	jnc	short sndc_init14
  2447 0001287B E9D2FEFFFF          <1> 	jmp	soundc_dev_err
  2448                              <1> sndc_init14:
  2449 00012880 A2[ED8E0100]        <1> 	mov	[audio_device], al
  2450 00012885 8825[258F0100]      <1> 	mov	[audio_mode], ah ; stereo (bit0), 16 bit (bit1) capability
  2451                              <1> 
  2452                              <1> sndc_init6:
  2453 0001288B 833D[008F0100]00    <1> 	cmp	dword [audio_buffer], 0
  2454                              <1> 	;jna	sound_buff_error
  2455                              <1> 	; 29/07/2022
  2456 00012892 7705                <1> 	ja	short sndc_init19
  2457 00012894 E9E5FEFFFF          <1> 	jmp	sound_buff_error ; 07/08/2022
  2458                              <1> sndc_init19:
  2459 00012899 A0[C5940100]        <1> 	mov	al, [u.uno]
  2460 0001289E 8A25[198F0100]      <1> 	mov	ah, [audio_user]
  2461 000128A4 08E4                <1> 	or	ah, ah
  2462 000128A6 7418                <1> 	jz	short sndc_init0
  2463 000128A8 38E0                <1> 	cmp	al, ah
  2464 000128AA 7419                <1> 	je	short sndc_init1
  2465                              <1> 
  2466                              <1> sndc_owner_error:
  2467 000128AC B80B000000          <1> 	mov	eax, ERR_NOT_OWNER ; 'permission denied !' error
  2468                              <1> 	; 29/07/2022
  2469                              <1> 	;sub	eax, eax
  2470                              <1> 	;mov	al, ERR_NOT_OWNER
  2471                              <1> sndc_perm_error:
  2472 000128B1 A3[74940100]        <1> 	mov	[u.r0], eax
  2473 000128B6 A3[E0940100]        <1> 	mov	[u.error], eax
  2474 000128BB E974A5FFFF          <1> 	jmp	error
  2475                              <1> sndc_init0:
  2476 000128C0 A2[198F0100]        <1> 	mov	[audio_user], al
  2477                              <1> sndc_init1:
  2478 000128C5 8915[1C8F0100]      <1> 	mov	[audio_cb_addr], edx
  2479 000128CB 881D[1A8F0100]      <1> 	mov	[audio_cb_mode], bl
  2480 000128D1 880D[1B8F0100]      <1> 	mov	[audio_srb], cl
  2481                              <1> 
  2482                              <1> 	; 27/07/2020
  2483                              <1> 	;mov	byte [audio_flag], 0  ; clear dma half buffer flag
  2484                              <1> 
  2485                              <1> 	; 24/04/2017
  2486 000128D7 803D[ED8E0100]03    <1> 	cmp	byte [audio_device], 3 ; VT8233 (VT8237R)
  2487 000128DE 7435                <1> 	je	short sndc_init9
  2488                              <1> 	;ja	short soundc_respond_err ; temporary (28/05/2017)
  2489 000128E0 803D[ED8E0100]01    <1> 	cmp	byte [audio_device], 1 ; SB 16
  2490 000128E7 7510                <1> 	jne	short sndc_init13
  2491 000128E9 BB[93460100]        <1> 	mov	ebx, sb16_int_handler
  2492                              <1> 	; Note: 'SbInit' is at 'Start to Play' stage
  2493                              <1> 	; 20/05/2017
  2494 000128EE 66C705[288F0100]08- <1> 	mov	word [audio_master_volume], 0808h ; 2/8
  2494 000128F6 08                  <1>
  2495 000128F7 EB34                <1> 	jmp	short sndc_init10
  2496                              <1> sndc_init13:
  2497                              <1> 	; 28/05/2017
  2498 000128F9 803D[ED8E0100]02    <1> 	cmp	byte [audio_device], 2 ; AC 97 (ICH)
  2499                              <1> 	;jne	soundc_respond_err ; temporary (28/05/2017)
  2500                              <1> 	; 29/07/2022
  2501 00012900 7405                <1> 	je	short sndc_init16
  2502                              <1> sndc_init15:
  2503 00012902 E952FEFFFF          <1> 	jmp	soundc_respond_err
  2504                              <1> sndc_init16:
  2505 00012907 E8D11E0000          <1> 	call	ac97_codec_config
  2506                              <1> 	;jc	soundc_respond_err ; codec error !
  2507                              <1> 	; 29/07/2022
  2508 0001290C 72F4                <1> 	jc	short sndc_init15
  2509                              <1> 
  2510 0001290E BB[774A0100]        <1> 	mov	ebx, ac97_int_handler
  2511 00012913 EB18                <1> 	jmp	short sndc_init10
  2512                              <1> 
  2513                              <1> sndc_init9:
  2514                              <1> 	;call	reset_codec
  2515                              <1> 	;; eax = 1
  2516                              <1> 	;call	codec_io_w16 ; w32
  2517 00012915 E8E7170000          <1> 	call	init_codec ; 28/05/2017
  2518                              <1> 	;jc	soundc_respond_err ; codec error !
  2519                              <1> 	; 29/07/2022
  2520 0001291A 72E6                <1> 	jc	short sndc_init15
  2521                              <1> 
  2522 0001291C E8F5190000          <1> 	call	channel_reset
  2523                              <1> 
  2524                              <1> 	; setup the Codec (actually mixer registers)
  2525 00012921 E81E190000          <1>         call    codec_config  ; unmute codec, set rates.
  2526                              <1> 	;jc	soundc_respond_err ; codec error !
  2527                              <1> 	; 29/07/2022
  2528 00012926 72DA                <1> 	jc	short sndc_init15
  2529                              <1> 
  2530 00012928 BB[AA420100]        <1> 	mov	ebx, vt8233_int_handler
  2531                              <1> sndc_init10:
  2532                              <1> 	; 13/04/2017
  2533 0001292D A0[EE8E0100]        <1> 	mov	al, [audio_intr] ; IRQ number
  2534 00012932 E82BFDFFFF          <1> 	call	set_dev_IRQ_service
  2535                              <1> 
  2536                              <1> 	; SETUP (audio) INTERRUPT CALLBACK SERVICE
  2537 00012937 8A1D[EE8E0100]      <1> 	mov	bl, [audio_intr] ; IRQ number
  2538 0001293D 8A3D[1A8F0100]      <1> 	mov	bh, [audio_cb_mode]
  2539 00012943 FEC7                <1> 	inc	bh  ; 1 = Signal Response Byte method (fixed value)
  2540                              <1> 		    ; 2 = Callback service method
  2541                              <1> 		    ; 3 = Auto Increment S.R.B. method
  2542 00012945 8A0D[1B8F0100]      <1> 	mov	cl, [audio_srb]
  2543 0001294B 8B15[1C8F0100]      <1> 	mov	edx, [audio_cb_addr]
  2544 00012951 A0[198F0100]        <1> 	mov	al, [audio_user]
  2545                              <1> 	; 14/04/2017
  2546 00012956 E834050000          <1>  	call	set_irq_callback_service
  2547                              <1> 	; 16/04/2017
  2548 0001295B A3[74940100]        <1> 	mov	[u.r0], eax
  2549                              <1> 	;jnc	sysret
  2550 00012960 7316                <1> 	jnc	short sndc_init2 ; 21/04/2017
  2551                              <1> 	;
  2552 00012962 A3[E0940100]        <1> 	mov	dword [u.error], eax
  2553                              <1> 
  2554 00012967 A0[EE8E0100]        <1> 	mov	al, [audio_intr] ; IRQ number
  2555 0001296C 31DB                <1> 	xor	ebx, ebx ; reset IRQ handler address
  2556 0001296E E8EFFCFFFF          <1> 	call	set_dev_IRQ_service
  2557                              <1> 
  2558 00012973 E9BCA4FFFF          <1> 	jmp	error
  2559                              <1> 
  2560                              <1> sndc_init2:
  2561                              <1> 	; 21/04/2017
  2562 00012978 8B0D[088F0100]      <1> 	mov	ecx, [audio_buff_size] ; audio buffer size
  2563                              <1> 	; 05/06/2024	
  2564                              <1> 	;shl	ecx, 1 ; *2
  2565                              <1> 	
  2566                              <1> 	; 05/06/2024
  2567 0001297E A0[ED8E0100]        <1> 	mov	al, [audio_device]
  2568 00012983 3C01                <1> 	cmp	al, 1 ; SB16
  2569 00012985 760A                <1> 	jna	short sndc_init22
  2570 00012987 80E1FE              <1> 	and	cl, ~1 ; truncated for word alignment
  2571 0001298A 3C03                <1> 	cmp	al, 3 ; VT8233  
  2572 0001298C 7303                <1> 	jnb	short sndc_init22
  2573                              <1> 	; al = 2 ; AC'97 	
  2574 0001298E 80E1F8              <1> 	and	cl, ~7 ; truncated for 8 byte (8x) alignment
  2575                              <1> sndc_init22:
  2576                              <1> 	; 05/06/2024
  2577 00012991 890D[148F0100]      <1> 	mov	[dma_hbuff_size], ecx  ; DMA half buffer size
  2578 00012997 D1E1                <1> 	shl	ecx, 1  ; add ecx, ecx ; * 2
  2579                              <1> 	
  2580                              <1> 	;;;
  2581                              <1> 	; 04/06/2024
  2582 00012999 81C1FF0F0000        <1> 	add	ecx, 4095  ; PAGE_SIZE - 1
  2583 0001299F 6681E100F0          <1> 	and	cx, ~4095  ; ~PAGE_OFF	
  2584                              <1> 	; ecx = page border aligned DMA buffer size (required) (*)
  2585                              <1> 	;;;
  2586                              <1> 
  2587 000129A4 A1[0C8F0100]        <1> 	mov	eax, [audio_dma_buff]
  2588 000129A9 21C0                <1> 	and	eax, eax
  2589 000129AB 741C                <1> 	jz	short sndc_init3 ; no need to compare dma buff size
  2590                              <1> 	
  2591 000129AD 8B15[108F0100]      <1> 	mov	edx, [audio_dmabuff_size] ; dma buffer size
  2592 000129B3 39D1                <1> 	cmp	ecx, edx
  2593 000129B5 742B                <1> 	je	short sndc_init5
  2594                              <1> 
  2595                              <1> 	; 04/12/2023
  2596 000129B7 3D00000500          <1> 	cmp	eax, sb16_dma_buffer	; reserved buffer ?
  2597 000129BC 7409                <1> 	je	short sndc_init20 ; it isn't an allocated mem buff
  2598                              <1> 
  2599 000129BE 87D1                <1> 	xchg	ecx, edx
  2600                              <1> 	; 26/11/2023 
  2601                              <1> 	; round up (always -rounded up- page count is allocated)
  2602                              <1> 	; ((so deallocation must be done for the rounded up value))
  2603                              <1> 	;add	ecx, PAGE_SIZE - 1   ; 4095
  2604                              <1> 	;call	deallocate_memory_block
  2605                              <1> 	; 04/06/2024
  2606                              <1> 	;call	deallocate_memory_block_x
  2607                              <1> 	;		; deallocate ((ecx+4095)>>12) pages
  2608 000129C0 E84835FFFF          <1> 	call	deallocate_memory_block	
  2609                              <1> 
  2610 000129C5 87CA                <1> 	xchg	edx, ecx
  2611                              <1> sndc_init20:
  2612 000129C7 31C0                <1> 	xor	eax, eax
  2613                              <1> sndc_init3:
  2614                              <1> 	; 05/06/2024
  2615 000129C9 890D[108F0100]      <1> 	mov	[audio_dmabuff_size], ecx ; (*)
  2616                              <1> 	; 12/05/2017
  2617 000129CF 803D[ED8E0100]01    <1> 	cmp	byte [audio_device], 1 ; SB 16
  2618 000129D6 750B                <1> 	jne	short sndc_init4
  2619 000129D8 C705[0C8F0100]0000- <1> 	mov	dword [audio_dma_buff], sb16_dma_buffer
  2619 000129E0 0500                <1>
  2620                              <1> 	; 05/06/2024
  2621                              <1> 	;mov	dword [audio_dmabuff_size], 65536
  2622                              <1> 	;xor	eax, eax
  2623                              <1> 	;mov	[u.r0], eax ; 0 = no error, successful
  2624                              <1> sndc_init5:	; 29/07/2022
  2625 000129E2 C3                  <1> 	retn 
  2626                              <1> 
  2627                              <1> sndc_init4:
  2628                              <1> 	; 02/12/2023 - TRDOS 386 v2.0.7
  2629 000129E3 81F900000100        <1> 	cmp	ecx, 65536
  2630 000129E9 7707                <1> 	ja	short sndc_init21
  2631 000129EB B800000500          <1> 	mov	eax, sb16_dma_buffer ; use already reserved buffer
  2632 000129F0 EB0C                <1> 	jmp	short sndc_init17
  2633                              <1> 
  2634                              <1> sndc_init21:
  2635                              <1> 	; EAX = Beginning address (physical)
  2636                              <1> 	; EAX = 0 -> Allocate mem block from the 1st proper aperture
  2637                              <1> 	; ECX = Number of bytes to be allocated	(>0)
  2638 000129F2 E8FC32FFFF          <1> 	call	allocate_memory_block
  2639                              <1> 	;jc	sound_buff_error
  2640                              <1> 	; 29/07/2022
  2641 000129F7 7305                <1> 	jnc	short sndc_init17
  2642 000129F9 E980FDFFFF          <1> 	jmp	sound_buff_error
  2643                              <1> 
  2644                              <1> sndc_init17:	; 29/07/2022
  2645                              <1> 	; set dma buffer address and size parameters
  2646 000129FE A3[0C8F0100]        <1> 	mov	[audio_dma_buff], eax ; dma buffer address
  2647                              <1> 	; 05/06/2024
  2648                              <1> 	;mov	[audio_dmabuff_size], ecx ; dma buffer size
  2649                              <1> 
  2650                              <1> 	;;;
  2651                              <1> 	; 05/06/2024
  2652 00012A03 8B0D[148F0100]      <1> 	mov	ecx, [dma_hbuff_size] ; DMA half (1-2) buffer size
  2653                              <1> 	; 04/06/2024
  2654                              <1> 	;mov	ecx, [audio_buff_size] ; audio buffer size in bytes
  2655                              <1> 	;;;
  2656                              <1> 
  2657                              <1> ;	; EAX = Beginning (physical) addr of the allocated mem block
  2658                              <1> ;	; ECX = Num of allocated bytes (rounded up to page borders)
  2659                              <1> ;	cmp	byte [audio_pci], 0 ; AC97 audio controller ?
  2660                              <1> ;	ja	short sndc_init4
  2661                              <1> ;
  2662                              <1> ;	; Sound Blaster 16 uses classic DMA
  2663                              <1> ;	mov	edx, eax
  2664                              <1> ;	add	edx, ecx
  2665                              <1> ;	cmp	edx, 1000000h ; 1st 16 MB
  2666                              <1> ;	jna	short sndc_init4
  2667                              <1> ;
  2668                              <1> ;	; error !
  2669                              <1> ;	; restore Memory Allocation Table Content
  2670                              <1> ;	; EAX = Beginning address (physical)
  2671                              <1> ;	; ECX = Number of bytes to be deallocated
  2672                              <1> ;	call	deallocate_memory_block
  2673                              <1> ;	; reset dma buffer address and size parameters
  2674                              <1> ;	xor	eax, eax ; 0
  2675                              <1> ;	mov	[audio_dma_buff], eax ; 0
  2676                              <1> ;	mov	[audio_dmabuff_size], ecx ; 0
  2677                              <1> ;	jmp	sound_buff_error
  2678                              <1> ;
  2679                              <1> ;sndc_init4:
  2680 00012A09 803D[ED8E0100]03    <1> 	cmp	byte [audio_device], 3
  2681                              <1> 	;jne	short sndc_init5
  2682                              <1> 	; 29/07/2022
  2683 00012A10 7505                <1> 	jne	short sndc_init18 ; 28/05/2017
  2684                              <1> 
  2685                              <1> ; 29/07/2022
  2686                              <1> ;	call	set_vt8233_bdl
  2687                              <1> ;sndc_init5:
  2688                              <1> ;	;sub	eax, eax ; 0
  2689                              <1> ;	;mov	[u.r0], eax ; 0 = no error, successful
  2690                              <1> ;	retn
  2691                              <1> 
  2692                              <1> 	; 05/06/2024
  2693                              <1> 	;;;
  2694                              <1> 	; 04/06/2024 (use truncated buffer size for BDL setup)
  2695                              <1> 	; NOTE: Round up adds spurious bytes (noise) to the DMA buff;
  2696                              <1> 	;	so, round down the size is better than the round up.
  2697                              <1> 	;	((BDL/SGD feature needs word aligned buffer address))
  2698                              <1> 	;
  2699                              <1> 	;mov	ecx, [audio_buff_size] ; audio buffer size in bytes
  2700                              <1> 	;and	cl, ~1
  2701                              <1> 	; 05/06/2024
  2702                              <1> 	;mov	[dma_hbuff_size], ecx
  2703                              <1> 	; ecx = DMA half buffer size as word aligned
  2704                              <1> 	;	(in fact, half buffer is one of the two DMA buffers)
  2705                              <1> 	;;;
  2706                              <1> 
  2707 00012A12 E939190000          <1> 	jmp	set_vt8233_bdl
  2708                              <1> 
  2709                              <1> sndc_init18:
  2710                              <1> 	;call	set_ac97_bdl
  2711                              <1> 	;;jmp	short sndc_init5
  2712                              <1> 	;retn
  2713                              <1> 
  2714                              <1> 	; 05/06/2024
  2715                              <1> 	;;;
  2716                              <1> 	;;;
  2717                              <1> 	; 04/06/2024 (use truncated buffer size for BDL setup)
  2718                              <1> 	; NOTE: Round up adds spurious bytes (noise) to the DMA buff;
  2719                              <1> 	;	so, round down the size is better than the round up.
  2720                              <1> 	;	((BDL feature needs 8 byte aligned buffer address))
  2721                              <1> 	;
  2722                              <1> 	;mov	ecx, [audio_buff_size] ; audio buffer size in bytes
  2723                              <1> 	;and	cl, ~7
  2724                              <1> 	; 05/06/2024
  2725                              <1> 	;mov	[dma_hbuff_size], ecx
  2726                              <1> 	; ecx = DMA half buffer size as truncated for 8 byte alignment
  2727                              <1> 	;	(in fact, half buffer is one of the two DMA buffers)
  2728                              <1> 	;;;
  2729                              <1> 
  2730                              <1> 	; 29/07/2022
  2731 00012A17 E9671F0000          <1> 	jmp	set_ac97_bdl
  2732                              <1> 
  2733                              <1> sound_play:
  2734                              <1> 	; FUNCTION = 4 
  2735                              <1> 	; bl = Mode 
  2736                              <1> 	;      bit 0 = mono/stereo (1 = stereo)
  2737                              <1> 	;      bit 1 = 8 bit / 16 bit (1 = 16 bit)
  2738                              <1> 	; cx = Sampling Rate (Hz)
  2739                              <1> 
  2740                              <1> 	; 13/06/2017
  2741                              <1> 	; Note: Even if Mode bits are not 11b,
  2742                              <1> 	; 	AC'97 Audio Controller (&Codec)
  2743                              <1> 	;	will play audio samples as 16 bit, stereo
  2744                              <1> 	;	samples.
  2745                              <1> 	;	(Program must fill the audio buffer
  2746                              <1> 	;	as required; 8 bit samples must be converted
  2747                              <1> 	;	to 16 bit samples and mono samples must be
  2748                              <1> 	;	converted to stereo samples...)
  2749                              <1> 	 
  2750                              <1> 	; 19/12/2024 (BugFix)
  2751                              <1> 	; 05/06/2024
  2752                              <1> 	; 04/06/2024
  2753                              <1> 	; 30/07/2022
  2754                              <1> 	; 28/07/2020
  2755                              <1> 	; 27/07/2020
  2756                              <1> 	; 28/05/2017
  2757                              <1> 	; 15/05/2017, 20/05/2017
  2758                              <1> 	; 21/04/2017, 24/04/2017
  2759                              <1> 	; ... device check at first
  2760 00012A1C A0[ED8E0100]        <1> 	mov	al, [audio_device]
  2761 00012A21 08C0                <1> 	or	al, al ; 0 ; pc speaker or invalid
  2762                              <1> 	;jz	beeper_gfx ; 'video.s' ; temporary
  2763                              <1> 	; 30/07/022
  2764 00012A23 7505                <1> 	jnz	short snd_play_7
  2765 00012A25 E95EF9FEFF          <1> 	jmp	beeper_gfx
  2766                              <1> 
  2767                              <1> snd_play_7:
  2768                              <1> ;	cmp	al, 3 ; VIA VT 8237R (vt8233)
  2769                              <1> ;	je	short snd_play_1
  2770                              <1> ;	cmp	al, 1 ; SB 16
  2771                              <1> ;	jne	soundc_dev_err ; temporary !
  2772                              <1> ;snd_play_0:
  2773                              <1> 	; ... buffer & (buffer) owner check at second
  2774 00012A2A 833D[008F0100]00    <1> 	cmp	dword [audio_buffer], 0
  2775                              <1> 	;jna	sound_buff_error
  2776                              <1> 	; 30/07/2022
  2777 00012A31 763C                <1> 	jna	short snd_play_4 ; jmp sound_buff_error
  2778 00012A33 A0[C5940100]        <1> 	mov	al, [u.uno]
  2779 00012A38 3A05[198F0100]      <1> 	cmp	al, [audio_user]
  2780                              <1> 	;jne	sndc_owner_error
  2781                              <1> 	; 30/07/2022
  2782 00012A3E 7405                <1> 	je	short snd_play_3
  2783 00012A40 E967FEFFFF          <1> 	jmp	sndc_owner_error
  2784                              <1> snd_play_3:
  2785 00012A45 66890D[228F0100]    <1> 	mov	[audio_freq], cx ; sample frequency (Hertz)
  2786 00012A4C 88D8                <1> 	mov	al, bl
  2787 00012A4E 2401                <1> 	and	al, 1 ; mono/stereo (1= stereo)
  2788 00012A50 FEC0                <1> 	inc	al ; channels
  2789 00012A52 A2[218F0100]        <1> 	mov	[audio_stmo], al ; sound channels (1 or 2)
  2790 00012A57 B008                <1> 	mov	al, 8
  2791 00012A59 F6C302              <1> 	test	bl, 2 ; bits per sample (1= 16 bit)
  2792 00012A5C 7402                <1> 	jz	short snd_play_bps
  2793 00012A5E D0E0                <1> 	shl	al, 1  
  2794                              <1> snd_play_bps:	
  2795 00012A60 A2[208F0100]        <1> 	mov	[audio_bps], al
  2796                              <1> 
  2797                              <1> 	; Transfer ring 3 (user's) audio buffer content to dma buffer
  2798 00012A65 8B3D[0C8F0100]      <1> 	mov	edi, [audio_dma_buff] ; dma buffer (ring 0)
  2799 00012A6B 09FF                <1> 	or	edi, edi
  2800                              <1> 	;jz	sound_buff_error
  2801                              <1> 	; 30/07/2022
  2802 00012A6D 7505                <1> 	jnz	short snd_play_5
  2803                              <1> snd_play_4:
  2804 00012A6F E90AFDFFFF          <1> 	jmp	sound_buff_error
  2805                              <1> snd_play_5:
  2806                              <1> 	; 27/07/2020
  2807 00012A74 8B35[048F0100]      <1> 	mov	esi, [audio_p_buffer] ; physical address (ring 3)
  2808                              <1> 	;mov	ecx, [audio_buff_size] ; 15/05/2017
  2809                              <1> 
  2810                              <1> ; 04/06/2024
  2811                              <1> %if 0
  2812                              <1> 	mov	ecx, [audio_dmabuff_size] ; 27/07/2020
  2813                              <1> 	;or	ecx, ecx 
  2814                              <1> 	;jz	sound_buff_error
  2815                              <1> 	; 28/07/2020
  2816                              <1> 	shr	ecx, 1  ; dma half buffer size
  2817                              <1> %else
  2818                              <1> 	; 05/06/2024
  2819 00012A7A 8B0D[148F0100]      <1> 	mov	ecx, [dma_hbuff_size]  ; DMA half buffer size
  2820                              <1> 
  2821                              <1> 	; 04/06/2024
  2822                              <1> 	;mov	ecx, [audio_buff_size]
  2823                              <1> 	; 19/12/2024 (BugFix)
  2824 00012A80 A0[ED8E0100]        <1> 	mov	al, [audio_device]
  2825                              <1> 	;
  2826                              <1> 	;cmp	al, 1 ; Sound Blaster 16
  2827                              <1> 	;je	short snd_play_8
  2828                              <1> 	;and	cl, ~1
  2829                              <1> 	;cmp	al, 3 ; VT8233 (VT8237R)
  2830                              <1> 	;je	short snd_play_8
  2831                              <1> 	; AC'97
  2832                              <1> 	;and	cl, ~7
  2833                              <1> snd_play_8:
  2834                              <1> %endif
  2835                              <1> 
  2836 00012A85 8035[188F0100]01    <1> 	xor	byte [audio_flag], 1 ;  0 -> 1, 1 -> 0
  2837 00012A8C 7502                <1> 	jnz	short snd_play_0 ; [audio_flag] = 1
  2838                              <1> 				 ; fill dma half buffer 1
  2839                              <1> 	; [audio_flag] = 0
  2840                              <1> 	
  2841                              <1> 	; fill dma half buffer 2
  2842 00012A8E 01CF                <1> 	add	edi, ecx
  2843                              <1> 
  2844                              <1> snd_play_0:
  2845                              <1> 	; 05/06/2024
  2846                              <1> 	;;rep	movsb
  2847                              <1> 	;shr	ecx, 2 ; convert byte count to dword count
  2848                              <1> 	;rep	movsd  ;	
  2849 00012A90 F3A4                <1> 	rep	movsb  ; SB16, AC97, VT8233
  2850                              <1> 
  2851                              <1> 	; here, if [audio_flag] = 0, interrupt handler will update
  2852                              <1> 				; dma half buffer 2 
  2853                              <1> 				; (user's audio buffer data will be
  2854                              <1> 				; copied into dma half buffer 2) 
  2855                              <1> 	;; 20/05/2017
  2856                              <1> 	;mov	byte [audio_flag], 1 ; next half (on next time)
  2857                              <1> 
  2858                              <1> 	; 24/04/2017
  2859                              <1> 	;mov	al, [audio_device]
  2860                              <1> 	; 04/06/2024
  2861                              <1> 	; al = [audio_device]
  2862                              <1> 
  2863 00012A92 3C03                <1> 	cmp	al, 3 ; VT8233 (VT8237R)
  2864 00012A94 7409                <1> 	je	short snd_play_1
  2865 00012A96 3C01                <1> 	cmp	al, 1 ; Sound Blaster 16
  2866 00012A98 750A                <1> 	jne	short snd_play_2  ; 28/05/2017
  2867                              <1> 
  2868                              <1> ; 30/07/2022
  2869                              <1> ;	call	SbInit_play
  2870                              <1> ;	;jc	soundc_respond_err
  2871                              <1> ;	;retn
  2872                              <1> ;	; 30/07/2022
  2873                              <1> ;	jnc	short snd_play_6  ; retn
  2874                              <1> ;	jmp	soundc_respond_err
  2875                              <1> 
  2876                              <1> 	; 30/07/2022
  2877 00012A9A E9A21A0000          <1> 	jmp	SbInit_play	; sb16_start_play
  2878                              <1> 
  2879                              <1> snd_play_1:	
  2880                              <1> 	;call	vt8233_start_play
  2881                              <1> 	;retn
  2882                              <1> 	; 30/07/2022
  2883 00012A9F E9E0180000          <1> 	jmp	vt8233_start_play
  2884                              <1> 
  2885                              <1> snd_play_2:
  2886                              <1> 	; 28/05/2017
  2887                              <1> 	;cmp	al, 2 ; AC'97
  2888                              <1> 	;jne	short snd_play_3
  2889                              <1> 
  2890                              <1> 	;call	ac97_start_play
  2891                              <1> 	;retn
  2892                              <1> 	; 30/07/2022
  2893 00012AA4 E90B1F0000          <1> 	jmp	ac97_start_play
  2894                              <1> 
  2895                              <1> ;snd_play_3:
  2896                              <1> ;	;call	hda_start_play
  2897                              <1> ;	retn
  2898                              <1> 	; 30/07/2022
  2899                              <1> 	;jmp	hda_start_play
  2900                              <1> 
  2901                              <1> ; 04/06/2024
  2902                              <1> ;snd_play_6:
  2903                              <1> ;	; 30/07/2022
  2904                              <1> ;	retn
  2905                              <1> 
  2906                              <1> sound_pause:
  2907                              <1> 	; FUNCTION = 5
  2908                              <1> 	; Pause
  2909                              <1> 	; 28/05/2017
  2910                              <1> 	; 24/04/2017
  2911                              <1> 	; 22/04/2017
  2912 00012AA9 E823030000          <1> 	call	snd_dev_check
  2913 00012AAE 7277                <1> 	jc	short snd_nothing ; temporary.
  2914 00012AB0 E829030000          <1> 	call	snd_buf_check
  2915 00012AB5 7270                <1> 	jc	short snd_nothing ; temporary.
  2916 00012AB7 A0[ED8E0100]        <1> 	mov	al, [audio_device]
  2917 00012ABC 3C03                <1> 	cmp	al, 3 ; VIA VT 8237R (vt8233)
  2918 00012ABE 7409                <1> 	je	short snd_pause_1
  2919 00012AC0 3C01                <1> 	cmp	al, 1 ; Sound Blaster 16
  2920 00012AC2 750A                <1> 	jne	short snd_pause_2 ; 28/05/2017
  2921 00012AC4 E94D1C0000          <1> 	jmp	sb16_pause
  2922                              <1> snd_pause_1:
  2923 00012AC9 E96B190000          <1> 	jmp	vt8233_pause
  2924                              <1> snd_pause_2:
  2925                              <1> 	; 28/05/2017
  2926                              <1> 	;cmp	al, 2 ; AC'97
  2927                              <1> 	;jne	short snd_nothing ; temporary.
  2928 00012ACE E9DD1F0000          <1> 	jmp	ac97_pause
  2929                              <1> 
  2930                              <1> sound_continue:
  2931                              <1> 	; FUNCTION = 6
  2932                              <1> 	; Continue to play
  2933                              <1> 	; 28/05/2017
  2934                              <1> 	; 22/04/2017
  2935 00012AD3 E8F9020000          <1> 	call	snd_dev_check
  2936 00012AD8 724D                <1> 	jc	short snd_nothing ; temporary.
  2937 00012ADA E8FF020000          <1> 	call	snd_buf_check
  2938 00012ADF 7246                <1> 	jc	short snd_nothing ; temporary.
  2939 00012AE1 A0[ED8E0100]        <1> 	mov	al, [audio_device]
  2940 00012AE6 3C03                <1> 	cmp	al, 3 ; VIA VT 8237R (vt8233)
  2941 00012AE8 7409                <1> 	je	short snd_cont_1
  2942 00012AEA 3C01                <1> 	cmp	al, 1 ; Sound Blaster 16
  2943 00012AEC 750A                <1> 	jne	short snd_cont_2 ; 28/05/2017
  2944 00012AEE E9451C0000          <1> 	jmp	sb16_continue
  2945                              <1> snd_cont_1:
  2946 00012AF3 E9F3180000          <1> 	jmp	vt8233_play
  2947                              <1> snd_cont_2:
  2948                              <1> 	; 28/05/2017
  2949                              <1> 	;cmp	al, 2 ; AC'97
  2950                              <1> 	;;jne	short snd_nothing ; temporary.
  2951                              <1> 	; 30/07/2022
  2952                              <1> 	;jne	short snd_cont_3
  2953 00012AF8 E9F41E0000          <1> 	jmp	ac97_play
  2954                              <1> ;snd_cont_3:
  2955                              <1> 	;jmp	hda_play
  2956                              <1> 
  2957                              <1> sound_stop:
  2958                              <1> 	; FUNCTION = 7
  2959                              <1> 	; Stop playing
  2960                              <1> 	; 30/07/2022
  2961                              <1> 	; 28/05/2017
  2962                              <1> 	; 24/05/2017
  2963                              <1> 	; 21/04/2017, 22/04/2017, 24/04/2017
  2964 00012AFD E8CF020000          <1> 	call	snd_dev_check
  2965 00012B02 7223                <1> 	jc	short snd_nothing ; temporary.
  2966                              <1> 	;call	snd_buf_check
  2967 00012B04 E8DE020000          <1> 	call	snd_user_check ; 24/05/2017
  2968 00012B09 721C                <1> 	jc	short snd_nothing ; temporary.	
  2969                              <1> 	
  2970 00012B0B A0[ED8E0100]        <1> 	mov	al, [audio_device]
  2971 00012B10 3C03                <1> 	cmp	al, 3 ; VIA VT 8237R (vt8233)
  2972                              <1> 	;je	vt8233_stop
  2973                              <1> 	;; 28/05/2017
  2974                              <1> 	;;ja	short snd_nothing
  2975                              <1> 	; 30/07/2022
  2976 00012B12 7505                <1> 	jne	short snd_stop_1
  2977 00012B14 E92E180000          <1> 	jmp	vt8233_stop
  2978                              <1> snd_stop_1:
  2979 00012B19 3C01                <1> 	cmp	al, 1 ; Sound Blaster 16
  2980                              <1> 	;je	sb16_stop
  2981                              <1> 	; 30/07/2022
  2982 00012B1B 7505                <1> 	jne	short snd_stop_2
  2983 00012B1D E9381C0000          <1> 	jmp	sb16_stop
  2984                              <1> snd_stop_2:
  2985                              <1> 	;cmp	al, 2 
  2986                              <1> 	;;je	short ac97_stop
  2987                              <1> 	; 30/07/2022
  2988                              <1> 	;jne	short snd_stop_3
  2989 00012B22 E9801F0000          <1> 	jmp	ac97_stop ; temporary.
  2990                              <1> ;snd_stop_3:
  2991                              <1> 	;jmp	hda_stop
  2992                              <1> 
  2993                              <1> sndc_cancel_ok:
  2994                              <1> 	; 30/07/2022
  2995                              <1> sndc_reset_ok:
  2996                              <1> 	; 30/07/2022
  2997                              <1> snd_nothing:
  2998                              <1> 	; 21/04/2017
  2999 00012B27 C3                  <1> 	retn
  3000                              <1> 
  3001                              <1> soundc_reset:
  3002                              <1> 	; FUNCTION = 8
  3003                              <1> 	; Reset Audio Controller
  3004                              <1> 	; 30/07/2022
  3005                              <1> 	; 28/05/2017
  3006                              <1> 	; 22/04/2017
  3007 00012B28 E8A4020000          <1> 	call	snd_dev_check
  3008 00012B2D 72F8                <1> 	jc	short snd_nothing ; temporary.
  3009 00012B2F E8AA020000          <1> 	call	snd_buf_check
  3010 00012B34 72F1                <1> 	jc	short snd_nothing ; temporary.	
  3011                              <1> 	
  3012 00012B36 A0[ED8E0100]        <1> 	mov	al, [audio_device]
  3013                              <1> 	; 30/07/2022
  3014 00012B3B 3C03                <1> 	cmp	al, 3 ; VIA VT 8237R (vt8233)
  3015 00012B3D 7207                <1> 	jb	short sndc_reset_1
  3016                              <1> 	;je	vt8233_reset
  3017 00012B3F 77E6                <1> 	ja	short snd_nothing ; temporary.
  3018                              <1> 	;;ja	hda_reset
  3019                              <1> 	;ja	short sndc_reset_3
  3020                              <1> 	; 30/07/2022
  3021 00012B41 E9FF180000          <1> 	jmp	vt8233_reset	
  3022                              <1> sndc_reset_1:
  3023 00012B46 3C01                <1> 	cmp	al, 1 ; Sound Blaster 16
  3024                              <1> 	;jne	ac97_reset	
  3025                              <1> 	; 30/07/2022
  3026 00012B48 750C                <1> 	jne	short sndc_reset_2
  3027 00012B4A E85C1C0000          <1> 	call	sb16_reset
  3028                              <1> 	;jc	soundc_respond_err
  3029                              <1> 	;retn
  3030                              <1> 	; 30/07/2022
  3031 00012B4F 73D6                <1> 	jnc	short sndc_reset_ok
  3032 00012B51 E903FCFFFF          <1> 	jmp	soundc_respond_err
  3033                              <1> sndc_reset_2:
  3034                              <1> 	; 30/07/2022
  3035                              <1> 	;cmp	al, 2
  3036                              <1> 	;ja	short sndc_reset_3
  3037 00012B56 E911200000          <1> 	jmp	ac97_reset
  3038                              <1> ;sndc_reset_3:
  3039                              <1> 	;jmp	hda_reset
  3040                              <1> 
  3041                              <1> soundc_cancel:
  3042                              <1> 	; FUNCTION = 9
  3043                              <1> 	; Cancel audio callback service
  3044                              <1> 	; 30/07/2022
  3045                              <1> 	; 22/04/2017
  3046 00012B5B A0[198F0100]        <1> 	mov	al, [audio_user]
  3047 00012B60 3A05[C5940100]      <1> 	cmp	al, [u.uno]
  3048 00012B66 75BF                <1> 	jne	short snd_nothing
  3049                              <1> 	; RESET (audio) INTERRUPT CALLBACK SERVICE
  3050 00012B68 8A1D[EE8E0100]      <1> 	mov	bl, [audio_intr] ; IRQ number
  3051 00012B6E A0[C5940100]        <1> 	mov	al, [u.uno]
  3052 00012B73 28FF                <1> 	sub	bh, bh ; 0 ; unlink IRQ from user service
  3053 00012B75 E815030000          <1>  	call	set_irq_callback_service
  3054                              <1> 	;jc	sndc_perm_error ; 'permission denied' error
  3055                              <1> 	;retn
  3056                              <1> 	; 30/07/2022
  3057 00012B7A 73AB                <1> 	jnc	short sndc_cancel_ok
  3058 00012B7C E930FDFFFF          <1> 	jmp	sndc_perm_error
  3059                              <1> 
  3060                              <1> sound_dalloc:
  3061                              <1> 	; FUNCTION = 10
  3062                              <1> 	; Deallocate (ring 3) audio buffer
  3063                              <1> 	; 22/04/2017
  3064 00012B81 A0[198F0100]        <1> 	mov	al, [audio_user]
  3065 00012B86 3A05[C5940100]      <1> 	cmp	al, [u.uno]
  3066 00012B8C 7599                <1> 	jne	short snd_nothing
  3067 00012B8E 8B1D[008F0100]      <1> 	mov	ebx, [audio_buffer]
  3068                              <1> 	;or	ebx, ebx
  3069                              <1> 	;jz	short snd_nothing
  3070 00012B94 8B0D[088F0100]      <1> 	mov	ecx, [audio_buff_size]
  3071 00012B9A E8AC34FFFF          <1> 	call	deallocate_user_pages
  3072 00012B9F 31C0                <1> 	xor	eax, eax
  3073 00012BA1 A3[008F0100]        <1> 	mov	[audio_buffer], eax ; 0
  3074 00012BA6 A2[198F0100]        <1> 	mov	[audio_user], al ; 0
  3075                              <1> ;sndc_cancel_ok:
  3076 00012BAB C3                  <1> 	retn
  3077                              <1> 
  3078                              <1> sound_volume:
  3079                              <1> 	; FUNCTION = 11
  3080                              <1> 	; Set sound volume level
  3081                              <1> 	; 23/05/2024
  3082                              <1> 	; 30/07/2022
  3083                              <1> 	; 28/05/2017
  3084                              <1> 	; 20/05/2017
  3085                              <1> 	; 22/04/2017, 24/04/2017
  3086                              <1> 	; bl = component
  3087                              <1> 	;		0 = master/playback/lineout volume
  3088                              <1> 	;		1 = PCM out volume ; 23/05/2024
  3089                              <1> 	; cl = left channel volume level (0 to 31)
  3090                              <1> 	; ch = right channel volume level (0 to 31)
  3091                              <1> 
  3092 00012BAC 80FB80              <1> 	cmp	bl, 80h
  3093 00012BAF 720A                <1> 	jb	short snd_vol_1
  3094                              <1> 	;ja	snd_nothing ; temporary.
  3095                              <1> 	; 30/07/2022
  3096 00012BB1 7707                <1> 	ja	short snd_vol_0
  3097                              <1> 	; Set volume level for next play (BL>= 80h)
  3098 00012BB3 66890D[288F0100]    <1> 	mov	[audio_master_volume], cx
  3099                              <1> snd_vol_0:
  3100 00012BBA C3                  <1> 	retn
  3101                              <1> snd_vol_1:
  3102                              <1> 	; set volume level immediate (BL< 80h)
  3103                              <1> 	;cmp	bl, 0
  3104                              <1> 	;;ja	snd_nothing ; temporary.
  3105                              <1> 	; 30/07/2022
  3106                              <1> 	;ja	short snd_vol_0
  3107                              <1> 	; 23/05/2024
  3108 00012BBB 80FB01              <1> 	cmp	bl, 1
  3109 00012BBE 77FA                <1> 	ja	short snd_vol_0 ; temporary
  3110                              <1> 
  3111 00012BC0 E80C020000          <1> 	call	snd_dev_check
  3112                              <1> 	;jc	snd_nothing ; temporary.
  3113                              <1> 	; 30/07/2022
  3114 00012BC5 72F3                <1> 	jc	short snd_vol_0
  3115 00012BC7 E812020000          <1> 	call	snd_buf_check
  3116                              <1> 	;jc	snd_nothing ; temporary.
  3117                              <1> 	; 30/07/2022
  3118 00012BCC 72EC                <1> 	jc	short snd_vol_0	
  3119                              <1> 
  3120 00012BCE A0[ED8E0100]        <1> 	mov	al, [audio_device]
  3121 00012BD3 3C03                <1> 	cmp	al, 3 ; VIA VT 8237R (vt8233)
  3122                              <1> 	;je	vt8233_volume
  3123                              <1> 	; 30/07/2022
  3124 00012BD5 7207                <1> 	jb	short snd_vol_2
  3125                              <1> 	; 28/05/2017
  3126                              <1> 	;ja	snd_nothing ; temporary.
  3127                              <1> 	; 30/07/2022
  3128 00012BD7 77E1                <1> 	ja	short snd_vol_0
  3129                              <1> 	;ja	hda_volume
  3130                              <1> 	; 30/07/2022
  3131 00012BD9 E980180000          <1> 	jmp	vt8233_volume
  3132                              <1> snd_vol_2:	
  3133                              <1> 	; Sound Blaster 16
  3134 00012BDE 3C01                <1> 	cmp	al, 1 ; SB 16
  3135                              <1> 	;je	sb16_volume
  3136                              <1> 	; 30/07/2022
  3137 00012BE0 7705                <1> 	ja	short snd_vol_3
  3138 00012BE2 E9FE1A0000          <1> 	jmp	sb16_volume
  3139                              <1> snd_vol_3:
  3140                              <1> 	; 30/07/2022
  3141                              <1> 	;cmp	al, 2
  3142                              <1> 	;ja	short snd_vol_4
  3143 00012BE7 E9511E0000          <1> 	jmp	ac97_volume
  3144                              <1> ;snd_vol_4:
  3145                              <1> 	;jmp	hda_volume
  3146                              <1> 
  3147                              <1> soundc_disable:
  3148                              <1> 	; FUNCTION = 12 
  3149                              <1> 	; Disable audio device (and unlink DMA memory)
  3150                              <1> 	; 23/08/2024
  3151                              <1> 	; 04/06/2024
  3152                              <1> 	; 30/07/2022
  3153                              <1> 	; 28/05/2017
  3154                              <1> 	; 24/05/2017
  3155                              <1> 	; 22/04/2017
  3156 00012BEC E8E0010000          <1> 	call	snd_dev_check
  3157                              <1> 	;jc	soundc_dev_err ; temporary.
  3158                              <1> 	; 30/07/2022
  3159 00012BF1 7305                <1> 	jnc	short snd_disable_4
  3160 00012BF3 E95AFBFFFF          <1> 	jmp	soundc_dev_err
  3161                              <1> snd_disable_4:
  3162                              <1> 	;call	snd_buf_check
  3163                              <1> 	;;jc	sndc_owner_error ; temporary.
  3164                              <1> 	; 30/07/2022
  3165                              <1> 	;jnc	short snd_disable_5
  3166                              <1> 	;jmp	sndc_owner_error
  3167                              <1> ;snd_disable_5:
  3168 00012BF8 A0[ED8E0100]        <1> 	mov	al, [audio_device]
  3169 00012BFD 3C03                <1> 	cmp	al, 3 ; VIA VT 8237R (vt8233)
  3170 00012BFF 7414                <1> 	je	short snd_disable_1
  3171                              <1> 	;ja	snd_nothing ; temporary.
  3172                              <1> 	; 30/07/2022
  3173 00012C01 775E                <1> 	ja	short snd_disable_3 ; retn
  3174 00012C03 3C01                <1> 	cmp	al, 1 ; Sound Blaster 16
  3175 00012C05 7507                <1> 	jne	short snd_disable_0
  3176 00012C07 E84E1B0000          <1> 	call	sb16_stop
  3177 00012C0C EB0C                <1> 	jmp	short snd_disable_2
  3178                              <1> snd_disable_0:
  3179 00012C0E E8941E0000          <1> 	call	ac97_stop
  3180 00012C13 EB05                <1> 	jmp	short snd_disable_2
  3181                              <1> snd_disable_1:
  3182 00012C15 E82D170000          <1> 	call	vt8233_stop
  3183                              <1> snd_disable_2:
  3184 00012C1A A0[EE8E0100]        <1> 	mov	al, [audio_intr]
  3185 00012C1F 29DB                <1> 	sub	ebx, ebx ; 0 = reset
  3186 00012C21 E83CFAFFFF          <1> 	call	set_dev_IRQ_service
  3187                              <1> 
  3188                              <1> 	;mov	al, [audio_intr]
  3189 00012C26 28E4                <1> 	sub	ah, ah ; 0 = reset
  3190 00012C28 E8FCF7FFFF          <1> 	call	set_hardware_int_vector
  3191                              <1> 
  3192 00012C2D 31C0                <1> 	xor	eax, eax
  3193 00012C2F A2[ED8E0100]        <1> 	mov	byte [audio_device], al
  3194 00012C34 A2[EE8E0100]        <1> 	mov	byte [audio_intr], al
  3195 00012C39 8705[0C8F0100]      <1> 	xchg	eax, [audio_dma_buff]
  3196                              <1> 
  3197                              <1> 	; 24/05/2017
  3198                              <1> 	;or	eax, eax
  3199                              <1> 	;jz	short snd_disable_3
  3200                              <1> 	;cmp	eax, sb16_dma_buffer ; default DMA buffer
  3201                              <1> 	;je	short snd_disable_3
  3202 00012C3F 803D[EC8E0100]00    <1> 	cmp	byte [audio_pci], 0 ; AC97 audio controller ?
  3203 00012C46 7619                <1> 	jna	short snd_disable_3
  3204 00012C48 C605[EC8E0100]00    <1> 	mov	byte [audio_pci], 0
  3205                              <1> 
  3206                              <1> 	; 23/08/2024 - bugfix
  3207 00012C4F 3D00000500          <1> 	cmp	eax, sb16_dma_buffer	; reserved buffer ?
  3208 00012C54 740B                <1> 	je	short snd_disable_3 ; it isn't an allocated mem buff
  3209                              <1> 
  3210                              <1> 	;sub	ecx, ecx
  3211                              <1> 	;xchg	ecx, [audio_dmabuff_size]
  3212 00012C56 8B0D[108F0100]      <1> 	mov	ecx, [audio_dmabuff_size]
  3213                              <1> 	; 26/11/2023 
  3214                              <1> 	; round up (always -rounded up- page count is allocated)
  3215                              <1> 	; ((so deallocation must be done for the rounded up value))
  3216                              <1> 	;add	ecx, PAGE_SIZE - 1   ; 4095
  3217                              <1> 	;call	deallocate_memory_block
  3218                              <1> 	; 04/06/2024
  3219                              <1> 	;call	deallocate_memory_block_x 
  3220                              <1> 			; deallocate ((ecx+4095)>>12) pages
  3221 00012C5C E8AC32FFFF          <1> 	call	deallocate_memory_block
  3222                              <1> snd_disable_3:
  3223 00012C61 C3                  <1> 	retn
  3224                              <1> 
  3225                              <1> sound_dma_map:
  3226                              <1> 	; FUNCTION = 13 
  3227                              <1> 	; Map audio dma buff addr to user's buffer addr
  3228                              <1> 	; 30/07/2022
  3229                              <1> 	; 12/05/2017
  3230 00012C62 21C9                <1> 	and	ecx, ecx
  3231                              <1> 	;jz	sound_buff_error
  3232                              <1> 	; 30/07/2022
  3233 00012C64 7505                <1> 	jnz	short snd_dma_map_3
  3234 00012C66 E913FBFFFF          <1> 	jmp	sound_buff_error
  3235                              <1> snd_dma_map_3:
  3236 00012C6B 803D[ED8E0100]01    <1> 	cmp	byte [audio_device], 1
  3237 00012C72 722A                <1> 	jb	short snd_dma_map_1
  3238                              <1> snd_dma_map_0:
  3239 00012C74 A1[0C8F0100]        <1> 	mov	eax, [audio_dma_buff]
  3240 00012C79 21C0                <1> 	and	eax, eax
  3241 00012C7B 7421                <1> 	jz	short snd_dma_map_1
  3242                              <1> 	;
  3243 00012C7D 8A1D[198F0100]      <1> 	mov	bl, [audio_user]
  3244 00012C83 08DB                <1> 	or	bl, bl
  3245 00012C85 7417                <1> 	jz	short snd_dma_map_1
  3246 00012C87 3A1D[C5940100]      <1> 	cmp	bl, [u.uno]
  3247                              <1> 	;jne	sndc_owner_error
  3248                              <1> 	; 30/07/2022
  3249 00012C8D 7405                <1> 	je	short snd_dma_map_4
  3250 00012C8F E918FCFFFF          <1> 	jmp	sndc_owner_error
  3251                              <1> snd_dma_map_4:
  3252 00012C94 8B1D[108F0100]      <1> 	mov	ebx, [audio_dmabuff_size]
  3253 00012C9A 21DB                <1> 	and	ebx, ebx
  3254 00012C9C 750A                <1> 	jnz	short snd_dma_map_2
  3255                              <1> snd_dma_map_1:
  3256 00012C9E B800000500          <1> 	mov	eax, sb16_dma_buffer
  3257 00012CA3 BB00000100          <1> 	mov	ebx, 65536
  3258                              <1> snd_dma_map_2:	
  3259 00012CA8 81C1FF0F0000        <1> 	add	ecx, PAGE_SIZE-1 ; 4095
  3260 00012CAE 6681E100F0          <1> 	and	cx, ~PAGE_OFF ; not 4095
  3261 00012CB3 39D9                <1> 	cmp	ecx, ebx
  3262                              <1> 	;ja	sound_buff_error
  3263                              <1> 	; 30/07/2022
  3264 00012CB5 7605                <1> 	jna	short snd_dma_map_6
  3265                              <1> snd_dma_map_5:
  3266 00012CB7 E9C2FAFFFF          <1> 	jmp	sound_buff_error
  3267                              <1> snd_dma_map_6:
  3268 00012CBC 50                  <1> 	push	eax
  3269 00012CBD 89D3                <1> 	mov	ebx, edx
  3270 00012CBF C1E90C              <1> 	shr	ecx, 12 ; byte count to page count
  3271                              <1> 	; eax = physical address of (audio) dma buffer
  3272                              <1> 	; ebx = virtual address of (audio) dma buffer (user's pgdir)
  3273                              <1> 	; ecx = page count (>0)
  3274 00012CC2 E8B632FFFF          <1> 	call	direct_memory_access
  3275 00012CC7 58                  <1> 	pop	eax
  3276                              <1> 	;jc	sound_buff_error
  3277                              <1> 	; 30/07/2022
  3278 00012CC8 72ED                <1> 	jc	short snd_dma_map_5
  3279 00012CCA A3[74940100]        <1> 	mov	[u.r0], eax
  3280 00012CCF C3                  <1> 	retn
  3281                              <1> 
  3282                              <1> soundc_info:
  3283                              <1> 	; FUNCTION = 14 
  3284                              <1> 	; Get Audio Controller Info
  3285                              <1> 	; 19/11/2023
  3286                              <1> 	; 30/07/2022
  3287                              <1> 	; 10/06/2017
  3288                              <1> 	; 05/06/2017
  3289                              <1> 	
  3290                              <1> 	;and	bl, bl ; 0
  3291                              <1> 	;jz	short sndc_info_0
  3292                              <1> 	
  3293                              <1> 	; 19/11/2023
  3294 00012CD0 80FB01              <1> 	cmp	bl, 1
  3295 00012CD3 7609                <1> 	jna	short sndc_info_0
  3296                              <1> 
  3297                              <1> ; invalid parameter !
  3298                              <1> ; 30/07/2022
  3299                              <1> 	;mov	eax, ERR_INV_PARAMETER ; 23
  3300                              <1> ;sndc_inf_error:
  3301                              <1> ;	mov	[u.r0], eax
  3302                              <1> ;	mov	[u.error], eax
  3303                              <1> ;	jmp	error
  3304                              <1> 	; 30/07/2022
  3305 00012CD5 29C0                <1> 	sub	eax, eax
  3306 00012CD7 B017                <1> 	mov	al, ERR_INV_PARAMETER ; 23
  3307 00012CD9 E980FAFFFF          <1> 	jmp	sysaudio_err
  3308                              <1> 
  3309                              <1> sndc_info_0:
  3310 00012CDE E8EE000000          <1> 	call	snd_dev_check
  3311                              <1> 	;jc	soundc_dev_err
  3312                              <1> 	; 30/07/2022
  3313 00012CE3 7305                <1> 	jnc	short sndc_info_3
  3314                              <1> snd_data_dev_err:
  3315 00012CE5 E968FAFFFF          <1> 	jmp	soundc_dev_err
  3316                              <1> sndc_info_3:
  3317                              <1> 	; 19/11/2023
  3318                              <1> 	;cmp	bl, 1
  3319                              <1> 	;je	short sndc_info_4
  3320 00012CEA 20DB                <1> 	and	bl, bl
  3321 00012CEC 7546                <1> 	jnz	short sndc_info_4
  3322                              <1> 
  3323 00012CEE 8B1D[F88E0100]      <1> 	mov	ebx, [audio_vendor]
  3324 00012CF4 8B0D[F48E0100]      <1> 	mov	ecx, [audio_dev_id]
  3325                              <1> 	;mov	al,  [audio_device]
  3326 00012CFA 3C02                <1> 	cmp	al, 2 ; AC'97 (ICH)
  3327 00012CFC 7513                <1> 	jne	short sndc_info_1
  3328                              <1> 	; Intel AC97 (ICH) Audio Controller (=2)
  3329 00012CFE 668B15[F28E0100]    <1> 	mov	dx, [NABMBAR]
  3330 00012D05 C1E210              <1> 	shl	edx, 16
  3331 00012D08 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  3332 00012D0F EB07                <1> 	jmp	short sndc_info_2
  3333                              <1> sndc_info_1:
  3334                              <1> 	; 05/06/2017
  3335                              <1> 	; Note: Intel HDA code (here) is not ready yet!
  3336                              <1> 	; !!! SB16 or VT8233 (VT8237R) !!!
  3337 00012D11 0FB715[F28E0100]    <1> 	movzx	edx, word [audio_io_base]
  3338                              <1> sndc_info_2:
  3339 00012D18 88C4                <1> 	mov	ah, al ; [audio_device]
  3340 00012D1A A0[EE8E0100]        <1> 	mov	al, [audio_intr] 
  3341                              <1> 
  3342                              <1> 	; EAX = IRQ Number in AL
  3343                              <1> 	;	Audio Device Number in AH 
  3344                              <1> 	; EBX = DEV/VENDOR ID
  3345                              <1> 	;	(DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV)
  3346                              <1> 	; ECX = BUS/DEV/FN 
  3347                              <1> 	;	(00000000BBBBBBBBDDDDDFFF00000000)
  3348                              <1> 	; EDX = NABMBAR/NAMBAR (for AC97)
  3349                              <1> 	;	(Low word, DX = NAMBAR address)
  3350                              <1> 	; EDX = Base IO Addr (DX) for SB16 & VT8233
  3351                              <1> 
  3352                              <1> 	; 10/06/2017
  3353 00012D1F A3[74940100]        <1> 	mov	[u.r0], eax
  3354 00012D24 8B2D[70940100]      <1> 	mov	ebp, [u.usp]
  3355 00012D2A 895D10              <1> 	mov	[ebp+16], ebx  ; ebx
  3356 00012D2D 895514              <1> 	mov	[ebp+20], edx  ; edx
  3357 00012D30 894D18              <1> 	mov	[ebp+24], ecx  ; ecx
  3358                              <1> 
  3359 00012D33 C3                  <1>  	retn
  3360                              <1> 
  3361                              <1> sndc_info_4:
  3362                              <1> 	; 19/11/2023
  3363 00012D34 3C02                <1> 	cmp	al, 2 ; Intel AC97 (ICH) Audio Controller
  3364 00012D36 7413                <1> 	je	short sndc_info_7
  3365                              <1> sndc_info_5:
  3366                              <1> 	; return ZERO if it is not AC97 audio controller codec
  3367 00012D38 31C0                <1> 	xor	eax, eax ; 0
  3368 00012D3A 31DB                <1> 	xor	ebx, ebx ; 0
  3369                              <1> sndc_info_6:
  3370 00012D3C A3[74940100]        <1> 	mov	[u.r0], eax
  3371 00012D41 8B2D[70940100]      <1> 	mov	ebp, [u.usp]
  3372 00012D47 895D10              <1> 	mov	[ebp+16], ebx  ; ebx
  3373 00012D4A C3                  <1> 	retn
  3374                              <1> sndc_info_7:
  3375 00012D4B E8F51F0000          <1> 	call	ac97_codec_info
  3376 00012D50 72E6                <1> 	jc	short sndc_info_5
  3377                              <1> 
  3378                              <1> 	; 26/11/2023 - temporary
  3379                              <1> 	;and	al, 0FEh	; clear VRA support bit for test
  3380                              <1> 
  3381 00012D52 EBE8                <1> 	jmp	short sndc_info_6
  3382                              <1> 
  3383                              <1> sound_data:
  3384                              <1> 	; FUNCTION = 15 
  3385                              <1> 	; Get Current Sound data for graphics
  3386                              <1> 	; 30/07/2022
  3387                              <1> 	; 22/06/2017
  3388                              <1> 	;
  3389 00012D54 E878000000          <1> 	call	snd_dev_check
  3390                              <1> 	;jc	soundc_dev_err ; Device not ready !
  3391                              <1> 	; 30/07/2022
  3392 00012D59 728A                <1> 	jc	short snd_data_dev_err
  3393                              <1> 
  3394 00012D5B 80FB00              <1> 	cmp	bl, 0
  3395 00012D5E 760A                <1> 	jna	short sound_data_0
  3396                              <1> 
  3397                              <1> 	; Only PCM OUT buffer data is valid for now!
  3398 00012D60 B817000000          <1> 	mov	eax, ERR_INV_PARAMETER  ; 23
  3399 00012D65 E9F4F9FFFF          <1> 	jmp	sysaudio_err
  3400                              <1> 
  3401                              <1> sound_data_0:
  3402 00012D6A A1[0C8F0100]        <1> 	mov	eax, [audio_dma_buff]
  3403 00012D6F 09C0                <1> 	or	eax, eax
  3404                              <1> 	;jz	sound_buff_error
  3405                              <1> 	; 30/07/2022
  3406 00012D71 741A                <1> 	jz	short sound_data_5
  3407                              <1> 
  3408 00012D73 803D[ED8E0100]04    <1> 	cmp	byte [audio_device], 4 ; Intel HDA
  3409 00012D7A 744C                <1> 	je	short sound_data_4 ; temporary ! (22/06/2017)
  3410                              <1> 
  3411 00012D7C 21C9                <1> 	and	ecx, ecx
  3412                              <1> 	;jnz	short sound_data_1 ; sample transfer
  3413                              <1> 	
  3414                              <1> 	; Return only DMA Buffer pointer/offset... 
  3415                              <1> 	; (If DMA Buffer has been mapped to user's
  3416                              <1> 	;  memory space; program can get graphics
  3417                              <1> 	;  data by using only this pointer value.)
  3418                              <1> 	   	
  3419                              <1> 	;call	get_dma_buffer_offset
  3420                              <1> 	;; eax = DMA buffer offset
  3421                              <1> 	;;	(!not half buffer offset!)
  3422                              <1> 	;mov	[u.r0], eax
  3423                              <1> 	;retn
  3424                              <1> 
  3425                              <1> 	;jz	get_dma_buffer_offset
  3426                              <1> 	; 30/07/2022
  3427 00012D7E 7505                <1> 	jnz	short sound_data_1
  3428 00012D80 E9611F0000          <1> 	jmp	get_dma_buffer_offset
  3429                              <1> 	
  3430                              <1> sound_data_1:
  3431                              <1> 	;mov	eax, [audio_dmabuff_size]
  3432                              <1> 	;shr	eax, 1 ; half buffer size
  3433                              <1> 	;cmp	ecx, eax
  3434                              <1> 	;ja	short sound_buff_error
  3435                              <1> 
  3436 00012D85 3B0D[108F0100]      <1> 	cmp	ecx, [audio_dmabuff_size]
  3437                              <1> 	;ja	sound_buff_error
  3438                              <1> 	; 30/07/2022
  3439 00012D8B 7605                <1> 	jna	short sound_data_6
  3440                              <1> sound_data_5:
  3441 00012D8D E9ECF9FFFF          <1> 	jmp	sound_buff_error	
  3442                              <1> sound_data_6:
  3443 00012D92 89D0                <1> 	mov	eax, edx
  3444 00012D94 25FF0F0000          <1> 	and	eax, PAGE_OFF ; 4095 (0FFFh)
  3445 00012D99 81F900100000        <1> 	cmp	ecx, 4096
  3446 00012D9F 7604                <1> 	jna	short sound_data_2
  3447                              <1> 	;mov	ecx, 4096 ; max. 1 page
  3448                              <1> 	; 30/07/2022
  3449 00012DA1 31C9                <1> 	xor	ecx, ecx
  3450 00012DA3 B510                <1> 	mov	ch, 16
  3451                              <1> 	; ecx = 4096
  3452                              <1> sound_data_2:
  3453 00012DA5 01C8                <1> 	add	eax, ecx
  3454 00012DA7 3D00100000          <1> 	cmp	eax, 4096
  3455 00012DAC 7606                <1> 	jna	short sound_data_3
  3456 00012DAE 6625FF0F            <1> 	and	ax, PAGE_OFF ; 4095 (0FFFh)
  3457 00012DB2 29C1                <1> 	sub	ecx, eax
  3458                              <1> 	; here, ECX has been adjusted to fit 
  3459                              <1> 	;	in page border..  (<= 4096, >0)
  3460                              <1> sound_data_3:
  3461 00012DB4 51                  <1> 	push	ecx
  3462 00012DB5 52                  <1> 	push	edx
  3463 00012DB6 89D3                <1> 	mov	ebx, edx 
  3464 00012DB8 E8012EFFFF          <1> 	call	get_physical_addr
  3465 00012DBD 5A                  <1> 	pop	edx
  3466 00012DBE 59                  <1> 	pop	ecx
  3467                              <1> 	;jc	sound_buff_error
  3468                              <1> 	; 30/07/2022
  3469 00012DBF 72CC                <1> 	jc	short sound_data_5
  3470                              <1> 	
  3471                              <1> 	; eax = physical address of user's buffer
  3472 00012DC1 89C3                <1> 	mov	ebx, eax  
  3473                              <1> 	; ecx = byte (transfer) count
  3474                              <1> 	;call	get_current_sound_data
  3475                              <1> 	;retn
  3476 00012DC3 E9731E0000          <1> 	jmp	get_current_sound_data
  3477                              <1> 
  3478                              <1> sound_data_4:
  3479                              <1> 	; Intel HDA code is not ready yet !
  3480                              <1> 	; 22/06/2017
  3481 00012DC8 31C0                <1> 	xor	eax, eax
  3482 00012DCA 48                  <1> 	dec	eax
  3483 00012DCB A3[74940100]        <1> 	mov	[u.r0], eax ; 0FFFFFFFFh
  3484 00012DD0 C3                  <1> 	retn 
  3485                              <1> 
  3486                              <1> snd_dev_check:
  3487                              <1> 	; 10/06/2017
  3488                              <1> 	; 05/06/2017
  3489                              <1> 	; 24/05/2017
  3490                              <1> 	; 22/04/2017
  3491                              <1> 	; 21/04/2017
  3492                              <1> 	; ... device check at first
  3493 00012DD1 A0[ED8E0100]        <1> 	mov	al, [audio_device]
  3494 00012DD6 3C01                <1> 	cmp	al, 1 ; SB 16
  3495 00012DD8 7203                <1> 	jb	short snd_dev_chk_retn ; error !
  3496                              <1> 	;cmp	al, 4 ; Intel HDA
  3497                              <1> 	;ja	short snd_dbchk_stc ; invalid !
  3498                              <1> 	; 10/06/2017
  3499 00012DDA 3C05                <1> 	cmp	al, 5
  3500 00012DDC F5                  <1> 	cmc
  3501                              <1> snd_dev_chk_retn:
  3502 00012DDD C3                  <1> 	retn
  3503                              <1> 
  3504                              <1> snd_buf_check:
  3505                              <1> 	; 10/06/2017
  3506                              <1> 	; 22/04/2017
  3507                              <1> 	; 21/04/2017
  3508                              <1> 	; ... buffer & (buffer) owner check at second
  3509 00012DDE 833D[008F0100]00    <1> 	cmp	dword [audio_buffer], 0
  3510 00012DE5 760D                <1> 	jna	short snd_dbchk_stc
  3511                              <1> snd_user_check:
  3512 00012DE7 A0[C5940100]        <1> 	mov	al, [u.uno]
  3513 00012DEC 3A05[198F0100]      <1> 	cmp	al, [audio_user]
  3514                              <1> 	;jne	short snd_dbchk_stc
  3515                              <1> 	;retn
  3516 00012DF2 74E9                <1> 	je	short snd_dev_chk_retn
  3517                              <1> 
  3518                              <1> snd_dbchk_stc:
  3519 00012DF4 F9                  <1> 	stc
  3520 00012DF5 C3                  <1> 	retn
  3521                              <1> 
  3522                              <1> sound_update:
  3523                              <1> 	; FUNCTION = 16
  3524                              <1> 	; bl = 
  3525                              <1> 	;    0 = automatic (sequental) update (with flag switch!)
  3526                              <1> 	;    1 = update dma half buffer 1 (without flag switch!)
  3527                              <1> 	;    2 = update dma half buffer 2 (without flag switch!)
  3528                              <1> 	;  FFh = get current flag value	
  3529                              <1> 	;      0 = dma half buffer 1 (will be played next)
  3530                              <1> 	;      1 = dma half buffer 2 (will be played next)
  3531                              <1> 	;
  3532                              <1> 	; 29/12/2024
  3533                              <1> 	; Note:	Requested half buffer is updated and 
  3534                              <1> 	;	flag is set to other value for other half buffer
  3535                              <1> 	;
  3536                              <1> 	; For example:
  3537                              <1> 	;     *	if BL input is 1, half buffer 1 is loaded and
  3538                              <1> 	;	   flag is switched to 1 -half buff 2 is in order-
  3539                              <1> 	;     (next time half buffer 2 is updated automaticly)
  3540                              <1> 	;     *	if BL input is 2, half buffer 2 is updated/loaded
  3541                              <1> 	;	   and flag is switched to 0
  3542                              <1> 	;
  3543                              <1> 	; Return value for BL input = 0,1,2
  3544                              <1>  	;     Current flag value (just after switched)
  3545                              <1> 	;       -flag will have same value-
  3546                              <1> 	;     If BL input is 1, return value will be 1 (1 xor 0)
  3547                              <1> 	;     IF BL input is 2, return value will be 0 (1 xor 1)
  3548                              <1> 	
  3549                              <1> 	; 28/12/2024
  3550                              <1> 	; 05/06/2024
  3551                              <1> 	; 30/07/2022
  3552                              <1> 	; 10/10/2017
  3553                              <1> 	; ... device check at first
  3554 00012DF6 A0[ED8E0100]        <1> 	mov	al, [audio_device]
  3555 00012DFB 08C0                <1> 	or	al, al ; 0 ; pc speaker or invalid 
  3556                              <1> 	;jz	soundc_dev_err
  3557                              <1> 	; 30/07/2022
  3558 00012DFD 7505                <1> 	jnz	short snd_update_4
  3559 00012DFF E94EF9FFFF          <1> 	jmp	soundc_dev_err
  3560                              <1> snd_update_4:
  3561                              <1> 	; ... buffer & (buffer) owner check at second
  3562 00012E04 833D[008F0100]00    <1> 	cmp	dword [audio_buffer], 0
  3563                              <1> 	;jna	sound_buff_error
  3564                              <1> 	; 30/07/2022
  3565 00012E0B 761C                <1> 	jna	short snd_update_6 ; jmp sound_buff_error
  3566 00012E0D A0[C5940100]        <1> 	mov	al, [u.uno]
  3567 00012E12 3A05[198F0100]      <1> 	cmp	al, [audio_user]
  3568                              <1> 	;jne	sndc_owner_error
  3569                              <1> 	; 30/07/2022
  3570 00012E18 7405                <1> 	je	short snd_update_5
  3571 00012E1A E98DFAFFFF          <1> 	jmp	sndc_owner_error
  3572                              <1> snd_update_5:
  3573                              <1> 	; Transfer ring 3 (user's) audio buffer content to dma buffer
  3574 00012E1F 8B3D[0C8F0100]      <1> 	mov	edi, [audio_dma_buff] ; dma buffer (ring 0)
  3575 00012E25 09FF                <1> 	or	edi, edi
  3576                              <1> 	;jz	sound_buff_error
  3577                              <1> 	; 30/07/2022
  3578 00012E27 7505                <1> 	jnz	short snd_update_7
  3579                              <1> snd_update_6:
  3580 00012E29 E950F9FFFF          <1> 	jmp	sound_buff_error
  3581                              <1> snd_update_7:
  3582 00012E2E 8B35[048F0100]      <1> 	mov	esi, [audio_p_buffer] ; physical address (ring 3)
  3583                              <1> 	; 05/06/2024
  3584                              <1> 	;mov	ecx, [audio_buff_size]
  3585                              <1> 	;
  3586                              <1> 	;;;
  3587                              <1> 	; 04/06/2024
  3588                              <1> 	;mov	al, [audio_device]
  3589                              <1> 	;cmp	al, 1
  3590                              <1> 	;je	short snd_update_8 ; SB16
  3591                              <1> 	;and	cl, ~1 ; word alignment
  3592                              <1> 	;cmp	al, 3
  3593                              <1> 	;je	short snd_update_8 ; VIA VT8233
  3594                              <1> 	;; al = 2 ; AC97
  3595                              <1> 	;and	cl, ~7 ; 8 byte alignment
  3596                              <1> ;snd_update_8:
  3597                              <1> 	;;;
  3598                              <1> 
  3599                              <1> 	; 05/06/2024
  3600 00012E34 8B0D[148F0100]      <1> 	mov	ecx, [dma_hbuff_size] ; DMA half buffer size
  3601                              <1> 
  3602                              <1> 	;movzx	eax, byte [audio_flag]
  3603 00012E3A A0[188F0100]        <1> 	mov	al, [audio_flag]
  3604 00012E3F FEC3                <1> 	inc	bl
  3605 00012E41 742F                <1> 	jz	short snd_update_3 ; bl = 0FFh
  3606 00012E43 FECB                <1> 	dec	bl 
  3607 00012E45 7417                <1> 	jz	short snd_update_0 ; bl = 0
  3608                              <1> 
  3609                              <1> 	; 28/12/2024
  3610 00012E47 80FB02              <1> 	cmp	bl, 2
  3611 00012E4A 7609                <1> 	jna	short snd_update_8
  3612                              <1> 	;cmp	bl, 2
  3613                              <1> 	;je	short snd_update_1 ; dma half buffer 2
  3614                              <1> 	;jb	short snd_update_2 ; dma half buffer 1
  3615                              <1> 	; 28/12/2024
  3616                              <1> 	;jz	short  snd_update_2
  3617                              <1> 
  3618                              <1> 	; invalid parameter !
  3619                              <1> ; 30/07/2022
  3620                              <1> 	;mov	eax, ERR_INV_PARAMETER ; 23
  3621                              <1> ;	mov	[u.r0], eax
  3622                              <1> ;	mov	[u.error], eax
  3623                              <1> ;	jmp	error
  3624                              <1> 
  3625                              <1> snd_update_err:
  3626                              <1> 	; 30/07/2022
  3627 00012E4C 29C0                <1> 	sub	eax, eax
  3628 00012E4E B017                <1> 	mov	al, ERR_INV_PARAMETER ; 23
  3629 00012E50 E909F9FFFF          <1> 	jmp	sysaudio_err
  3630                              <1> 
  3631                              <1> 	; 29/12/2024
  3632                              <1> snd_update_8:
  3633 00012E55 88D8                <1> 	mov	al, bl	; 1 or 2
  3634 00012E57 FEC8                <1> 	dec	al
  3635 00012E59 A2[188F0100]        <1> 	mov	[audio_flag], al ; 0 or 1
  3636                              <1> snd_update_0:
  3637 00012E5E 8035[188F0100]01    <1> 	xor	byte [audio_flag], 1 ; update flag !!!
  3638                              <1> snd_update_9:
  3639 00012E65 3C01                <1> 	cmp	al, 1
  3640 00012E67 7202                <1> 	jb	short snd_update_2 ; dma half buffer 1
  3641                              <1> snd_update_1:
  3642                              <1> 	; dma half buffer 2
  3643 00012E69 01CF                <1> 	add	edi, ecx
  3644                              <1> snd_update_2:
  3645                              <1> 	;rep	movsb
  3646                              <1> 	; 05/06/2024
  3647                              <1> 	;shr	ecx, 2
  3648                              <1> 	;rep	movsd
  3649 00012E6B F3A4                <1> 	rep	movsb ; SB16, AC97, VT8233
  3650                              <1> 	; 29/12/2024
  3651 00012E6D A0[188F0100]        <1> 	mov	al, [audio_flag]
  3652                              <1> snd_update_3:
  3653 00012E72 A3[74940100]        <1> 	mov	[u.r0], eax
  3654                              <1> 
  3655 00012E77 C3                  <1> 	retn
  3656                              <1> 
  3657                              <1> sound_getvol:
  3658                              <1> 	; FUNCTION = 17
  3659                              <1> 	; Get sound volume level
  3660                              <1> 	; 24/05/2024
  3661                              <1> 	; bl = component
  3662                              <1> 	;		0 = master/playback/lineout volume
  3663                              <1> 	;		1 = PCM out volume
  3664                              <1> 	; Return:
  3665                              <1> 	; cl = left channel volume level (0 to 31)
  3666                              <1> 	; ch = right channel volume level (0 to 31)
  3667                              <1> 
  3668 00012E78 80FB01              <1> 	cmp	bl, 1
  3669 00012E7B 7709                <1> 	ja	short snd_gvol_0 ; temporary ; 24/05/2024
  3670 00012E7D 7408                <1> 	je	short snd_gvol_1
  3671 00012E7F 668B0D[288F0100]    <1> 	mov	cx, [audio_master_volume]
  3672                              <1> snd_gvol_0:
  3673 00012E86 C3                  <1> 	retn
  3674                              <1> snd_gvol_1:
  3675 00012E87 668B0D[2A8F0100]    <1> 	mov	cx, [audio_pcmo_volume]
  3676 00012E8E C3                  <1> 	retn
  3677                              <1> 
  3678                              <1> %if 0
  3679                              <1> 
  3680                              <1> sound_dmaclear:
  3681                              <1> 	; FUNCTION = 18
  3682                              <1> 	; Clear DMA buffer
  3683                              <1> 	;	 (may be useful for non-VRA AC97 hardware)
  3684                              <1> 	; bl = cleaning byte value
  3685                              <1> 	;      0 or 80h (not a necessary value, 0 is most proper)
  3686                              <1> 	;
  3687                              <1> 	; Return value
  3688                              <1> 	;	eax = DMA half buffer size (DMA buff size / 2)
  3689                              <1> 	;  If eax = 0
  3690                              <1> 	;	there is not an active DMA buffer for user)
  3691                              <1> 	;
  3692                              <1> 	; 28/12/2024
  3693                              <1> 	mov	edi, [audio_dma_buff]
  3694                              <1> 	and	edi, edi
  3695                              <1> 	jz	short snd_dma_clear_ok
  3696                              <1> 	mov	ecx, [audio_dmabuff_size]
  3697                              <1> 	or	ecx, ecx
  3698                              <1> 	jz	short snd_dma_clear_ok
  3699                              <1> 	; security (is necessary for multitasking)
  3700                              <1> 	mov	cl, [audio_user]
  3701                              <1> 	or	cl, cl
  3702                              <1> 	jz	short snd_dma_clear_ok
  3703                              <1> 	cmp	cl, [u.uno]
  3704                              <1> 	jne 	short snd_dma_clear_ok
  3705                              <1> 	mov	ecx, [dma_hbuff_size]
  3706                              <1> 	and	ecx, ecx
  3707                              <1> 	jz	short snd_dma_clear_ok
  3708                              <1> 
  3709                              <1> 	mov	[u.r0], ecx
  3710                              <1> 	shl	ecx, 1 ; full buffer size in bytes
  3711                              <1> 	mov	al, bl
  3712                              <1> 	rep	stosb	
  3713                              <1> 
  3714                              <1> snd_dma_clear_ok:
  3715                              <1> 	retn
  3716                              <1> 
  3717                              <1> %endif
  3718                              <1> 
  3719                              <1> set_irq_callback_service:
  3720                              <1> 	; 23/11/2023
  3721                              <1> 	; 20/11/2023 (TRDOS 386 Kernel v2.0.7)
  3722                              <1> 	; 30/07/2022 (TRDOS 386 Kernel v2.0.5)
  3723                              <1> 	; 03/08/2020
  3724                              <1> 	; 10/06/2017
  3725                              <1> 	; 12/05/2017
  3726                              <1> 	; 24/04/2017
  3727                              <1> 	; 22/04/2017
  3728                              <1> 	; caller: 'syscalbac' or 'sysaudio' or ...
  3729                              <1> 	; 13/04/2017, 14/04/2017, 17/04/2017
  3730                              <1> 	; 24/02/2017, 26/02/2017, 28/02/2017
  3731                              <1> 	; 21/02/2017 - TRDOS 386 (TRDOS v2.0)
  3732                              <1> 	;
  3733                              <1> 	; Link or unlink IRQ callback service to/from user (ring 3)
  3734                              <1> 	;
  3735                              <1> 	; INPUT ->
  3736                              <1> 	;	If AL = 0, the caller is 'syscalbac';
  3737                              <1> 	;	   otherwise, the caller is 'sysaudio' or ...
  3738                              <1> 	;	   (AL = user number) 
  3739                              <1> 	;
  3740                              <1> 	;	BL = IRQ number (Hardware interrupt request number)
  3741                              <1> 	;	     (0 to 15 but IRQ 0,1,2,6,8,14,15 are prohibited)
  3742                              <1> 	;	     IRQ numbers 3,4,5,7,9,10,11,12,13 are valid
  3743                              <1> 	;	     (numbers >15 are invalid)
  3744                              <1> 	;
  3745                              <1> 	;	BH = 0 = Unlink IRQ (in BL) from user (ring 3) service
  3746                              <1> 	;	     1 = Link IRQ by using Signal Response Byte method
  3747                              <1> 	;	     2 = Link IRQ by using Callback service method
  3748                              <1> 	;	     3 = Link IRQ by using Auto Increment S.R.B. method
  3749                              <1> 	;	    >3 = invalid 
  3750                              <1> 	;		 (syscallback version will return to user)
  3751                              <1> 	;
  3752                              <1> 	;	CL = Signal Return/Response Byte value 
  3753                              <1> 	;
  3754                              <1> 	;	If BH = 3, kernel will put a counter value ; 03/08/2020
  3755                              <1> 	;	          (into the S.R.B. addr)
  3756                              <1> 	;		  between 0 to 255. (start value = CL+1)
  3757                              <1> 	;	
  3758                              <1> 	;	NOTE: counter value, for example: even and odd numbers
  3759                              <1> 	;	      may be used for -audio- DMA buffer switch 
  3760                              <1> 	;	      within double buffer method, etc.
  3761                              <1> 	;
  3762                              <1> 	;	EDX = Signal return (Response) byte address
  3763                              <1> 	;	       		  - or -
  3764                              <1> 	;	      Interrupt/Callback service/routine address
  3765                              <1> 	;
  3766                              <1> 	;	      (virtual address in user's memory space)
  3767                              <1> 	;
  3768                              <1> 	; OUTPUT ->
  3769                              <1> 	;	CF = 0 & EAX = 0 -> Successful setting
  3770                              <1> 	;	CF = 1 & EAX > 0 -> IRQ is prohibited or locked
  3771                              <1> 	;			by another process
  3772                              <1> 	;		 eax = ERR_PERM_DENIED -> prohibited or locked
  3773                              <1> 	;		 eax = ERR_INV_PARAMETER -> 
  3774                              <1> 	;		       invalid parameter/option or bad address
  3775                              <1> 	;
  3776                              <1> 	; TRDOS 386 - IRQ CALLBACK structures (parameters):
  3777                              <1> 	;
  3778                              <1> 	;	   [u.irqlock]	: 1 word, IRQ flags (0-15) that indicates
  3779                              <1> 	;			which IRQs are locked by (that) user.
  3780                              <1> 	;		        Lock and unlock (by user) will change
  3781                              <1> 	;			these flags or 'terminate process' (sysexit)
  3782                              <1> 	;			will clear these flags and unlock those IRQs.
  3783                              <1> 	;
  3784                              <1> 	;		   	Bit 0 is for IRQ 0 and Bit 15 is for IRQ 15
  3785                              <1> 	;
  3786                              <1> 	;	   IRQ(x).owner	: 1 byte, user, [u.uno], 0 = free (unlocked)
  3787                              <1> 	;
  3788                              <1> 	;	   IRQ(x).method : 1 byte for callback method & status
  3789                              <1> 	;			   0 = Signal Response Byte method
  3790                              <1> 	;			   1 = Callback service method
  3791                              <1> 	;			   >1 = invalid for current 'syscalback'.
  3792                              <1> 	;			or(+) 80h = IRQ is in use by system (ring 0)
  3793                              <1> 	;			            function (audio etc.) or
  3794                              <1> 	;			   	    a device driver.
  3795                              <1> 	;			(system function will ignore the lock/owner)
  3796                              <1> 	;
  3797                              <1> 	;	   IRQ(x).srb	: 1 byte, Signal Return/Response byte value
  3798                              <1> 	;			  (a fixed value by user or a counter value
  3799                              <1> 	;			 from 0 to 255, which is increased by every
  3800                              <1> 	;			 interrupt just before putting it into 
  3801                              <1> 	;			 the Signal Response byte address)
  3802                              <1> 	;			 (This is not used in callback serv method)
  3803                              <1> 	;
  3804                              <1> 	;	   IRQ(x).addr	: 1 dword
  3805                              <1> 	;			  Signal Response Byte address (physical)
  3806                              <1> 	;			  		-or-
  3807                              <1> 	;			  Callback service address (virtual)
  3808                              <1> 	;
  3809                              <1> 	;	   IRQ(x).dev	: 1 byte
  3810                              <1> 	;			  0 = Default device or kernel function
  3811                              <1> 	;			  		-or-
  3812                              <1> 	;			  1-255 = Assigned device driver number
  3813                              <1> 	;
  3814                              <1> 	;	   (x) = 3,4,5,7,9,10,11,12,13
  3815                              <1> 	;
  3816                              <1> 	
  3817 00012E8F 80FB0F              <1> 	cmp	bl, 15
  3818 00012E92 7727                <1> 	ja	short scbs_2
  3819                              <1> 	
  3820 00012E94 80FF03              <1> 	cmp	bh, 3
  3821 00012E97 7722                <1> 	ja	short scbs_2  ; invalid parameter
  3822                              <1> 
  3823 00012E99 0FB6FB              <1> 	movzx	edi, bl ; save IRQ number
  3824                              <1> 
  3825                              <1> 		; IRQ 0,1,2,6,8,14,15 are prohibited
  3826                              <1> 	;IRQenum: ; 'trdosk9.s'
  3827                              <1> 	;	db  0,0,0,1,2,3,0,4,0,5,6,7,8,9,0,0
  3828                              <1> 
  3829 00012E9C 0FB6B7[BE3B0100]    <1> 	movzx	esi, byte [edi+IRQenum] ; IRQ availability
  3830                              <1> 					; enumeration/index
  3831                              <1> 	; 20/11/2023
  3832 00012EA3 4E                  <1> 	dec	esi
  3833                              <1> 	;dec	si
  3834 00012EA4 780F                <1> 	js	short scbs_1 ;  0 -> 0FFFFh  
  3835                              <1> 
  3836                              <1> 	; ESI = IRQ callback parameters index number (0 to 8)
  3837                              <1> 
  3838 00012EA6 08FF                <1> 	or	bh, bh
  3839 00012EA8 7417                <1> 	jz	short scbs_4 ; unlink the IRQ (in BL)
  3840                              <1> 
  3841 00012EAA FECF                <1> 	dec	bh
  3842                              <1> 	; bh = method (0 = signal response byte, 1 = callback)
  3843                              <1> 	;	      (2 = auto increment of signal response byte)
  3844                              <1> 
  3845 00012EAC 80BE[9C8E0100]00    <1> 	cmp	byte [esi+IRQ.owner], 0 ; locked ?
  3846 00012EB3 7635                <1> 	jna	short scbs_6	; no... OK...
  3847                              <1> 
  3848                              <1> scbs_1:
  3849                              <1> 	; permission denied (prohibited IRQ)
  3850                              <1> 	;mov	eax, ERR_PERM_DENIED
  3851                              <1> 	; 30/07/2022
  3852 00012EB5 29C0                <1> 	sub	eax, eax
  3853 00012EB7 B00B                <1> 	mov	al, ERR_PERM_DENIED
  3854 00012EB9 F9                  <1> 	stc
  3855 00012EBA C3                  <1> 	retn
  3856                              <1> scbs_2:
  3857                              <1> 	;stc
  3858                              <1> scbs_3:
  3859                              <1> 	;mov	eax, ERR_INV_PARAMETER
  3860                              <1> 	; 30/07/2022
  3861 00012EBB 29C0                <1> 	sub	eax, eax
  3862 00012EBD B017                <1> 	mov	al, ERR_INV_PARAMETER
  3863 00012EBF F9                  <1> 	stc
  3864 00012EC0 C3                  <1> 	retn
  3865                              <1> 
  3866                              <1> scbs_4: ; unlink the requested IRQ (if it belongs to current user)
  3867                              <1> 	; 10/06/2017
  3868                              <1> 	; 22/04/2017
  3869                              <1> 	; 14/04/2017
  3870                              <1> 	; If AL = 0 -> The caller is 'syscalbac'
  3871 00012EC1 8AA6[9C8E0100]      <1> 	mov	ah, [esi+IRQ.owner]
  3872 00012EC7 3A25[C5940100]      <1> 	cmp	ah, [u.uno]
  3873 00012ECD 75E6                <1> 	jne	short scbs_1
  3874                              <1> 
  3875 00012ECF FE0D[EE940100]      <1> 	dec	byte [u.irqc] ; decrease IRQ count (in use)
  3876                              <1> 
  3877                              <1> 	;sub	ah, ah
  3878                              <1> 	;mov	[esi+IRQ.owner], ah ; 0 ; free !!!
  3879                              <1> 	;and	byte [esi+IRQ.method], 80h
  3880                              <1> 	;mov	[esi+IRQ.srb], ah ; 0
  3881                              <1> 	;mov	[esi+IRQ.dev], ah ; 0
  3882                              <1> 	;mov	dword [esi+IRQ.addr], 0
  3883                              <1> 	;mov	dword [u.r0], 0
  3884                              <1> 
  3885                              <1> 	;mov	byte [esi+IRQ.owner], 0
  3886                              <1> 
  3887                              <1> 	; 22/04/2017
  3888 00012ED5 29C0                <1> 	sub	eax, eax
  3889 00012ED7 8886[9C8E0100]      <1> 	mov	[esi+IRQ.owner], al ; 0
  3890                              <1> 	; 10/06/2017
  3891 00012EDD 8686[AE8E0100]      <1> 	xchg	al, [esi+IRQ.method]
  3892 00012EE3 2480                <1> 	and	al, 80h
  3893 00012EE5 745D                <1> 	jz	short scbs_12 
  3894                              <1> 	; Audio device must be disabled -later- ! ([IRQ.medhod] = 80h)
  3895                              <1> 
  3896                              <1> ;	cmp	byte [esi+IRQ.method], 80h ; device drv or kernel extension ?
  3897                              <1> ;	jb	short scbs_12 ; bh = 0 reset to default IRQ handler
  3898                              <1> ;
  3899                              <1> ;	and	al, al
  3900                              <1> ;	jz	short scbs_5  ; the caller is 'syscalbac'
  3901                              <1> ;	; The caller is 'sysaudio' or ...
  3902 00012EE7 30C0                <1> 	xor	al, al
  3903                              <1> ;	mov	[esi+IRQ.method], al ; 0 ; reset kernel extension flag
  3904                              <1> ;scbs_5:
  3905                              <1> ;	sub	ah, ah
  3906                              <1> 	;mov	[u.r0], eax ; 0
  3907 00012EE9 C3                  <1> 	retn
  3908                              <1> 
  3909                              <1> scbs_6:
  3910                              <1> 	; 14/04/2017
  3911 00012EEA 20C0                <1> 	and	al, al
  3912 00012EEC 7405                <1> 	jz	short scbs_7  ; the caller is 'syscalbac'
  3913                              <1> 	; AL = user number ([u.uno] or [audio.user] or ...)
  3914                              <1> 	; The caller is 'sysaudio' or ...
  3915                              <1> 	;	
  3916                              <1> 	; bh = method (0 = signal response byte, 1 = callback)
  3917                              <1> 	;	      (2 = auto increment of signal response byte) 
  3918                              <1> 
  3919 00012EEE 80CF80              <1> 	or	bh, 80h		; Kernel extension flag !
  3920 00012EF1 EB0A                <1> 	jmp	short scbs_8
  3921                              <1> scbs_7:	
  3922 00012EF3 8A86[AE8E0100]      <1> 	mov	al, [esi+IRQ.method] ; >= 80h = kernel is using this IRQ
  3923 00012EF9 2480                <1> 	and	al, 80h ; use only bit 7 (kernel function flag)
  3924 00012EFB 08C7                <1> 	or	bh, al		 ; method 
  3925                              <1> 				 ; 0 = signal response byte, 1 = callback
  3926                              <1> 				 ; 2 = auto increment of s.r.b.
  3927                              <1> scbs_8:
  3928 00012EFD A0[C5940100]        <1> 	mov	al, [u.uno] ; user (process) number (1 to 16)
  3929 00012F02 8886[9C8E0100]      <1> 	mov	[esi+IRQ.owner], al ; lock the IRQ for user
  3930 00012F08 88BE[AE8E0100]      <1> 	mov	[esi+IRQ.method], bh
  3931                              <1> 
  3932                              <1> ;	test	bh, 1
  3933                              <1> ;	jnz	short scbs_9 	 ; Callback method, CX will not be used
  3934                              <1> ;
  3935                              <1> ;	test	bh, 2		 ; use auto increment (counter) method
  3936                              <1> ;	jz	short scbs_10	 ; (count can be used for buffer switch)
  3937                              <1> ;scbs_9:
  3938                              <1> ;	xor	ecx, ecx ; 0
  3939                              <1> 
  3940                              <1> scbs_10:
  3941                              <1> 	;mov	[esi+IRQ.method], bh
  3942 00012F0E 888E[B78E0100]      <1> 	mov	[esi+IRQ.srb], cl
  3943 00012F14 C686[A58E0100]00    <1> 	mov	byte [esi+IRQ.dev], 0 ; device number is always 0
  3944                              <1> 				 ; for this system call
  3945                              <1> 	;test	bh, 1
  3946 00012F1B 80E701              <1> 	and	bh, 1 ; 17/04/2017
  3947 00012F1E 7513                <1> 	jnz	short scbs_11	 ; callback method, use virtual address
  3948                              <1> 
  3949 00012F20 53                  <1> 	push	ebx ; IRQ number (in BL)
  3950 00012F21 89D3                <1> 	mov	ebx, edx
  3951                              <1> 	; ebx = virtual address
  3952                              <1> 	; [u.pgdir] = page directory's physical address
  3953 00012F23 FE05[5A8E0100]      <1> 	inc	 byte [no_page_swap] ; 1 
  3954                              <1> 			; Do not add this page to swap queue
  3955                              <1> 			; and remove it from swap queue if it is
  3956                              <1> 			; on the queue.
  3957 00012F29 E8902CFFFF          <1> 	call	get_physical_addr
  3958 00012F2E 5B                  <1> 	pop	ebx
  3959 00012F2F 728A                <1> 	jc	short scbs_3 ; invalid address !
  3960                              <1> 	; eax = physical address of the virtual address in user's space
  3961 00012F31 89C2                <1> 	mov	edx, eax
  3962                              <1> scbs_11:
  3963                              <1> 	;shl	si, 2		; byte (index) to dword (offset)
  3964                              <1> 	; 23/11/2023
  3965 00012F33 C1E602              <1> 	shl	esi, 2
  3966 00012F36 8996[C08E0100]      <1> 	mov	[esi+IRQ.addr], edx
  3967                              <1> 
  3968 00012F3C FE05[EE940100]      <1> 	inc	byte [u.irqc]	; increase IRQ (in use) count
  3969                              <1> 
  3970 00012F42 FEC7                <1> 	inc	bh ; 17/04/2017
  3971                              <1> 	; bh > 0 -> set to requested IRQ handler (IRQ_u_list)
  3972                              <1> scbs_12:
  3973 00012F44 88D8                <1> 	mov	al, bl ; IRQ number
  3974 00012F46 88FC                <1> 	mov	ah, bh ; 0 = reset, >0 = set
  3975 00012F48 E8DCF4FFFF          <1> 	call	set_hardware_int_vector
  3976                              <1> 
  3977 00012F4D 31C0                <1> 	xor	eax, eax
  3978                              <1> 	;mov 	[u.r0], eax ; 0	
  3979                              <1> 
  3980 00012F4F C3                  <1> 	retn	; return with success (cf=0, eax=0)
  3981                              <1> 
  3982                              <1> sysdma: ; DMA FUNCTIONS
  3983                              <1> 	; 08/08/2022
  3984                              <1> 	; 30/07/2022 - TRDOS 386 Kernel v2.0.5
  3985                              <1> 	; 02/09/2017
  3986                              <1> 	; 28/08/2017
  3987                              <1> 	; 20/08/2017 - TRDOS 386 (TRDOS v2.0)
  3988                              <1> 	;
  3989                              <1> 	; Inputs:
  3990                              <1> 	;	BH = 0 -> Allocate DMA buffer
  3991                              <1> 	;	   BL = 0 -> Use the system's default DMA
  3992                              <1> 	;		     (SB16) Buffer
  3993                              <1> 	;	        Buffer Size (max.) = 65536 bytes
  3994                              <1> 	;	   BL > 0 -> Allocate (a new) DMA buffer
  3995                              <1>  	;	   ECX = DMA Buffer Size in bytes (<=128KB)
  3996                              <1> 	;	   EDX = Virtual Address of DMA buffer
  3997                              <1> 	;
  3998                              <1> 	;	BH = 1 -> Initialize (Start) DMA service
  3999                              <1> 	;	     BL, bit 0 to 3 = Channel Number (0 to 7)
  4000                              <1> 	;	     BL, bit 7 = Auto Initialized Mode
  4001                              <1> 	;			(If bit 7 is set)
  4002                              <1> 	;		 bit 6 = Record (read) mode (0= playback)
  4003                              <1> 	;	     ECX = byte count (0 = use dma buffer size)
  4004                              <1> 	;	     EDX = physical buffer address
  4005                              <1> 	;	     	   (0 = use dma buffer -start- address)
  4006                              <1> 	;
  4007                              <1> 	;	BH = 2 -> Get Current DMA Buffer Offset
  4008                              <1> 	;	     BL = DMA channel number	
  4009                              <1> 	;
  4010                              <1> 	;	BH = 3 -> Get Current DMA count down value
  4011                              <1> 	;	     BL = DMA channel number (0 tO 7)
  4012                              <1> 	;
  4013                              <1> 	;	BH = 4 -> Get Current DMA channel (in progress)
  4014                              <1> 	;
  4015                              <1> 	;	BH = 5 -> Get System's Default DMA Buffer Address
  4016                              <1> 	;
  4017                              <1> 	;	BH = 6 -> Get Current DMA Buffer Address
  4018                              <1> 	;
  4019                              <1> 	;	BH = 7 -> Stop DMA service
  4020                              <1> 	;
  4021                              <1> 	; Outputs:
  4022                              <1> 	;
  4023                              <1> 	;	For BH = 0 ; Allocate DMA buffer
  4024                              <1> 	;	    EAX = Physical address of DMA buffer
  4025                              <1> 	;	    ECX = Allocated buffer size in bytes
  4026                              <1> 	;		  - page count * 4096 -
  4027                              <1> 	;		  (may be bigger than requested)
  4028                              <1> 	;	    If BL input > 0,
  4029                              <1> 	;	       'sysalloc:' system call will be used with
  4030                              <1>   	;	       EBX (for 'sysalloc') = EDX (for 'sysdma')
  4031                              <1> 	;	       ECX is same, byte count (buffer size)
  4032                              <1> 	;	       EDX = 1024*1024*16 ; 16 MB upper limit
  4033                              <1> 	;	    If BL input = 0,
  4034                              <1> 	;	       Default DMA buffer (SB16 buffer) will be
  4035                              <1> 	;	       checked and if it is free, it's address
  4036                              <1> 	;	       will be returned in EAX and it's size
  4037                              <1> 	;	       will be returned in ECX (as 65536)
  4038                              <1> 	;
  4039                              <1> 	;	    If CF = 1, error code is in EAX
  4040                              <1> 	;	       EAX = -1 ; DMA buffer allocation error!
  4041                              <1> 	;	       EAX = 11 ; 'Permission Denied' error !
  4042                              <1> 	;
  4043                              <1> 	;	       Note: 'sysalloc' error return method
  4044                              <1> 	;		      will be applied if BL input > 0 !
  4045                              <1> 	;
  4046                              <1> 	; 	 For BH = 1 ; Initialize (Start) DMA
  4047                              <1> 	;	     EAX = 0 (Successful)
  4048                              <1> 	;	     If CF = 1, error code is in EAX
  4049                              <1> 	;
  4050                              <1> 	; 	 For BH = 2 ; Get Current DMA Buffer Offset
  4051                              <1> 	;	     EAX = DMA Buffer Offset (in bytes)
  4052                              <1> 	;	     ;
  4053                              <1> 	;	      AX = DMA buffer offset
  4054                              <1> 	;	     EAX bits 16 to 23 = Page register value
  4055                              <1> 	;
  4056                              <1> 	; 	 For BH = 3 ; Get Current DMA count down value
  4057                              <1> 	;	     EAX = Count down value (remain bytes)
  4058                              <1> 	;	
  4059                              <1> 	;	 For BH = 4 ; Get Current DMA channel (in progress)
  4060                              <1> 	;	     EAX = DMA channel number (0 to 7)
  4061                              <1> 	;		AH = 0 if the owner is the caller process
  4062                              <1> 	;		AH > 0 if the dma channel is in use by
  4063                              <1> 	;		       another user/process
  4064                              <1> 	;	     EAX = -1 (0FFFFFFFFh) 
  4065                              <1> 	;		    if DMA service is not in use
  4066                              <1> 	;	 	    (stopped or not initialized/started)
  4067                              <1> 	;
  4068                              <1> 	;	 For BH = 5 ; Get System's Default DMA Buff Addr
  4069                              <1> 	;	     EAX = Default DMA Buffer Address (Physical)
  4070                              <1> 	;		 = offset 'sb16_dma_buffer:'
  4071                              <1> 	;	     ECX = Buffer size
  4072                              <1> 	;		 = 65536
  4073                              <1> 	;
  4074                              <1> 	;	 For BH = 6 ; Get Current DMA Buffer Address
  4075                              <1> 	;	     EAX = Current DMA buffer address (Physical)
  4076                              <1> 	;	     ECX = Current DMA buffer size (setting value)
  4077                              <1> 	;	     Note: These values are for current dma channel
  4078                              <1> 	;		   settings for the user/process
  4079                              <1> 	;	     ** For now (for current TRDOS 386 version)
  4080                              <1> 	;		only one user/process can use only one
  4081                              <1> 	;		dma channel & one dma buffer at same time
  4082                              <1> 	;		(no multi tasking on DMA service) !!! **
  4083                              <1> 	;	     (Once, current DMA user must stop it's own DMA
  4084                              <1> 	;	      DMA service, than another user/program 
  4085                              <1> 	;	      can use DMA service with same dma channel
  4086                              <1> 	;	      or with another DMA channel.)
  4087                              <1> 	;
  4088                              <1> 	;	 For BH = 7 ; Stop DMA service (for current user
  4089                              <1> 	;	     and current DMA channel)
  4090                              <1> 	;	     EAX = 0 ; successful
  4091                              <1> 	;	     CF = 1 & EAX > 0 (= -1) -> Error
  4092                              <1> 
  4093 00012F50 80FF07              <1> 	cmp	bh, 7
  4094 00012F53 7612                <1> 	jna	short sysdma_0
  4095                              <1> 
  4096                              <1> sysdma_err:
  4097 00012F55 31C0                <1> 	xor	eax, eax
  4098 00012F57 48                  <1> 	dec	eax ; -1
  4099                              <1> sysdma_perm_err:
  4100 00012F58 A3[74940100]        <1> 	mov	[u.r0], eax
  4101 00012F5D A3[E0940100]        <1> 	mov	[u.error], eax ; DMA service error !
  4102 00012F62 E9CD9EFFFF          <1> 	jmp	error
  4103                              <1> 
  4104                              <1> sysdma_0:
  4105 00012F67 08FF                <1> 	or	bh, bh
  4106 00012F69 7537                <1> 	jnz	short sysdma_1 ; 30/07/2022
  4107                              <1> 	
  4108 00012F6B 20DB                <1> 	and	bl, bl
  4109 00012F6D 7416                <1> 	jz	short sysdma_01
  4110                              <1> 
  4111                              <1> 	; redirect system call to 'sysalloc'
  4112 00012F6F 89D3                <1> 	mov	ebx, edx ; virtual address of DMA buffer
  4113                              <1> 	;ecx = Buffer size in bytes
  4114                              <1> 	; DMA buffer address <= 16MB upper limit
  4115 00012F71 BA00000001          <1> 	mov	edx, 1024*1024*16 ; 16MB limit for DMA buff
  4116                              <1> 
  4117 00012F76 C705[38930100]FFFF- <1> 	mov	dword [dma_addr], 0FFFFFFFFh ; -1
  4117 00012F7E FFFF                <1>
  4118                              <1> 
  4119 00012F80 E921E8FFFF          <1> 	jmp	sysalloc
  4120                              <1> 
  4121                              <1> sysdma_01:
  4122 00012F85 B800000500          <1> 	mov	eax, sb16_dma_buffer
  4123                              <1> 
  4124 00012F8A 803D[ED8E0100]01    <1> 	cmp	byte [audio_device], 1
  4125 00012F91 724A                <1> 	jb	short sysdma_03
  4126                              <1> 
  4127 00012F93 3B05[0C8F0100]      <1> 	cmp	eax, [audio_dma_buff]
  4128 00012F99 7527                <1> 	jne	short sysdma_02
  4129                              <1> 
  4130                              <1> sysdma_0_err:
  4131 00012F9B B80B000000          <1> 	mov	eax, ERR_PERM_DENIED
  4132 00012FA0 EBB6                <1> 	jmp	short sysdma_perm_err
  4133                              <1> 
  4134                              <1> 	; 30/07/2022
  4135                              <1> sysdma_1:
  4136 00012FA2 80FF01              <1> 	cmp	bh, 1
  4137                              <1> 	;ja	sysdma_5
  4138                              <1> 	; 30/07/2022
  4139 00012FA5 7605                <1> 	jna	short sysdma_10
  4140 00012FA7 E90C010000          <1> 	jmp	sysdma_5
  4141                              <1> 
  4142                              <1> sysdma_10:
  4143 00012FAC F6C340              <1> 	test	bl, 40h	; record (read) mode -BL, bit 6-
  4144                              <1> 	;jnz	sysdma_err ; not ready yet!
  4145                              <1> 	; 30/07/2022
  4146 00012FAF 757C                <1> 	jnz	short sysdma_06 ; jmp sysdma_err
  4147                              <1> 
  4148 00012FB1 A1[38930100]        <1> 	mov	eax, [dma_addr] ; physical address of dma buffer
  4149 00012FB6 21C0                <1> 	and	eax, eax
  4150                              <1> 	;jz	sysdma_err
  4151                              <1> 	; 30/07/2022
  4152 00012FB8 7473                <1> 	jz	short sysdma_06 ; jmp sysdma_err
  4153                              <1> 
  4154 00012FBA 09D2                <1> 	or	edx, edx
  4155 00012FBC 7574                <1> 	jnz	short sysdma_11
  4156                              <1> 
  4157 00012FBE 89C2                <1> 	mov	edx, eax
  4158 00012FC0 EB74                <1> 	jmp	short sysdma_12
  4159                              <1> 
  4160                              <1> sysdma_02:
  4161                              <1> 	; Only one user is permitted for audio/dma functions
  4162                              <1> 
  4163 00012FC2 833D[0C8F0100]00    <1> 	cmp	dword [audio_dma_buff], 0
  4164 00012FC9 7612                <1> 	jna	short sysdma_03
  4165                              <1> 
  4166 00012FCB 8A1D[198F0100]      <1> 	mov	bl, [audio_user]
  4167 00012FD1 08DB                <1> 	or	bl, bl
  4168 00012FD3 7408                <1> 	jz	short sysdma_03
  4169                              <1> 
  4170 00012FD5 3A1D[C5940100]      <1> 	cmp	bl, [u.uno]
  4171 00012FDB 75BE                <1> 	jne	short sysdma_0_err
  4172                              <1> 
  4173                              <1> sysdma_03:
  4174 00012FDD 8A1D[35930100]      <1> 	mov	bl, [dma_user]
  4175 00012FE3 20DB                <1> 	and	bl, bl
  4176 00012FE5 750E                <1> 	jnz	short sysdma_04
  4177                              <1> 	
  4178 00012FE7 8A1D[C5940100]      <1> 	mov	bl, [u.uno]
  4179 00012FED 881D[35930100]      <1> 	mov	[dma_user], bl
  4180                              <1> 
  4181 00012FF3 EB15                <1> 	jmp	short sysdma_05
  4182                              <1> 
  4183                              <1> sysdma_04:
  4184 00012FF5 8B35[38930100]      <1> 	mov	esi, [dma_addr]
  4185 00012FFB 21F6                <1> 	and	esi, esi
  4186 00012FFD 740B                <1> 	jz	short sysdma_05
  4187                              <1> 
  4188 00012FFF 46                  <1> 	inc	esi ; -1 -> 0
  4189 00013000 7408                <1> 	jz	short sysdma_05
  4190                              <1> 
  4191 00013002 3A1D[C5940100]      <1> 	cmp	bl, [u.uno]
  4192 00013008 7591                <1> 	jne	short sysdma_0_err
  4193                              <1> 	
  4194                              <1> sysdma_05:
  4195                              <1> 	; edx = virtual address (user's buffer address)
  4196                              <1> 	; 
  4197 0001300A 81F900000100        <1> 	cmp	ecx, 65536   ; byte count (buffer size)
  4198                              <1> 	;ja	sysdma_err
  4199                              <1> 	; 30/07/2022
  4200 00013010 771B                <1> 	ja	short sysdma_06 ; jmp sysdma_err
  4201                              <1> 	;
  4202 00013012 81C1FF0F0000        <1> 	add	ecx, PAGE_SIZE-1 ; 4095
  4203 00013018 6681E100F0          <1> 	and	cx, ~PAGE_OFF ; not 4095
  4204                              <1> 	;cmp	ecx, 65536
  4205                              <1> 	;ja	sysdma_err
  4206 0001301D 51                  <1> 	push	ecx	; buffer size (allocated pages * 4096)
  4207 0001301E 50                  <1> 	push	eax	; offset sb16_dma_buffer
  4208 0001301F 89D3                <1> 	mov	ebx, edx
  4209 00013021 C1E90C              <1> 	shr	ecx, 12 ; byte count to page count
  4210                              <1> 	; eax = physical address of (audio) dma buffer
  4211                              <1> 	; ebx = virtual address of (audio) dma buffer (user's pgdir)
  4212                              <1> 	; ecx = page count (>0)
  4213 00013024 E8542FFFFF          <1> 	call	direct_memory_access
  4214 00013029 58                  <1> 	pop	eax
  4215 0001302A 59                  <1> 	pop	ecx
  4216                              <1> 	;jc	sysdma_err
  4217                              <1> 	; 30/07/2022
  4218 0001302B 7315                <1> 	jnc	short sysdma_07
  4219                              <1> sysdma_06:
  4220 0001302D E923FFFFFF          <1> 	jmp	sysdma_err
  4221                              <1> 
  4222                              <1> sysdma_11:
  4223 00013032 39C2                <1> 	cmp	edx, eax
  4224                              <1> 	;jb	sysdma_err
  4225                              <1> 	; 30/07/2022
  4226 00013034 72F7                <1> 	jb	short sysdma_06 ; jmp sysdma_err
  4227                              <1> sysdma_12:
  4228 00013036 21C9                <1> 	and	ecx, ecx
  4229 00013038 7515                <1> 	jnz	short sysdma_13
  4230                              <1> 
  4231 0001303A 8B0D[3C930100]      <1> 	mov	ecx, [dma_size]
  4232 00013040 EB15                <1> 	jmp	short sysdma_14
  4233                              <1> 
  4234                              <1> sysdma_07:
  4235 00013042 A3[38930100]        <1> 	mov	[dma_addr], eax
  4236 00013047 890D[3C930100]      <1> 	mov	[dma_size], ecx ; dma buffer size (in bytes)
  4237                              <1> 
  4238                              <1> 	;mov	[u.r0], eax ; DMA Buffer Address (Physical)
  4239                              <1> 
  4240                              <1> 	;mov	ebp, [u.usp]  ; ebp points to user's registers
  4241                              <1> 	;mov	[ebp+24], ecx ; return to user with ecx value
  4242                              <1> 
  4243                              <1> 	;jmp	sysret
  4244                              <1> 
  4245                              <1> 	; 28/08/2017
  4246 0001304D EB7A                <1> 	jmp	sysdma_51
  4247                              <1> 
  4248                              <1> sysdma_13:
  4249 0001304F 3B0D[3C930100]      <1> 	cmp	ecx, [dma_size]
  4250                              <1> 	;ja	sysdma_err
  4251                              <1> 	; 30/07/2022
  4252 00013055 77D6                <1> 	ja	short sysdma_06 ; jmp sysdma_err
  4253                              <1> sysdma_14:
  4254 00013057 89C6                <1> 	mov	esi, eax
  4255 00013059 0335[3C930100]      <1> 	add	esi, [dma_size]
  4256                              <1> 
  4257 0001305F 89D0                <1> 	mov	eax, edx
  4258 00013061 01C8                <1> 	add	eax, ecx
  4259                              <1> 	;jc	sysdma_err ; 02/09/2017
  4260                              <1> 	; 30/07/2022
  4261 00013063 72C8                <1> 	jc	short sysdma_06 ; jmp sysdma_err
  4262                              <1> 		
  4263 00013065 39F0                <1> 	cmp	eax, esi
  4264                              <1> 	;ja	sysdma_err
  4265                              <1> 	; 30/07/2022
  4266 00013067 77C4                <1> 	ja	short sysdma_06 ; jmp sysdma_err
  4267                              <1> 
  4268 00013069 8B3D[0C8F0100]      <1> 	mov	edi, [audio_dma_buff]
  4269 0001306F 8B35[38930100]      <1> 	mov	esi, [dma_addr]
  4270                              <1> 
  4271 00013075 09FF                <1> 	or	edi, edi
  4272 00013077 7425                <1> 	jz	short sysdma_16
  4273                              <1> 	
  4274 00013079 803D[ED8E0100]01    <1> 	cmp	byte [audio_device], 1
  4275 00013080 7209                <1> 	jb	short sysdma_15
  4276                              <1> 
  4277                              <1> 	; Sound Blaster 16
  4278 00013082 39FE                <1> 	cmp	esi, edi
  4279                              <1> 	;je	sysdma_0_err ; permmission denied !
  4280                              <1> 	; 30/07/2022
  4281 00013084 7505                <1> 	jne	short sysdma_15
  4282 00013086 E910FFFFFF          <1> 	jmp	sysdma_0_err
  4283                              <1> sysdma_15:
  4284 0001308B C605[37930100]48    <1> 	mov	byte [dma_mode], 48h ; single mode playback
  4285                              <1> 
  4286 00013092 F6C380              <1> 	test	bl, 80h ; DMA mode - BL, bit 7, auto init -
  4287 00013095 7407                <1> 	jz	short sysdma_16	
  4288                              <1> 	; Auto initialized playback (write) mode
  4289 00013097 8005[37930100]10    <1> 	add	byte [dma_mode], 10h ; = 58h
  4290                              <1> sysdma_16:
  4291 0001309E 80E307              <1> 	and	bl, 07h
  4292 000130A1 881D[36930100]      <1> 	mov	[dma_channel], bl
  4293 000130A7 8915[40930100]      <1> 	mov	[dma_start], edx
  4294 000130AD 890D[44930100]      <1> 	mov	[dma_count], ecx
  4295                              <1> 	 
  4296                              <1> 	; 28/08/2017
  4297                              <1> 	;call	dma_init
  4298                              <1> 	;jmp	sysret
  4299 000130B3 E945010000          <1> 	jmp	dma_init
  4300                              <1> 
  4301                              <1> sysdma_5:
  4302 000130B8 80FF05              <1> 	cmp	bh, 5
  4303 000130BB 726D                <1> 	jb	short sysdma_3
  4304 000130BD 7759                <1> 	ja	short sysdma_6
  4305                              <1> 
  4306                              <1> 	; Get the system's default dma buffer addr and size
  4307 000130BF B800000500          <1> 	mov	eax, sb16_dma_buffer
  4308 000130C4 B900000100          <1> 	mov	ecx, 65536 ; Buffer size in bytes
  4309                              <1> 
  4310                              <1> sysdma_51:
  4311                              <1> 	; 0 = there is not a dma buffer (in use or available)
  4312 000130C9 A3[74940100]        <1> 	mov	[u.r0], eax
  4313                              <1> 
  4314 000130CE 8B2D[70940100]      <1> 	mov	ebp, [u.usp]  ; ebp points to user's registers
  4315 000130D4 894D18              <1> 	mov	[ebp+24], ecx ; return to user with ecx value
  4316                              <1> 
  4317 000130D7 E9789DFFFF          <1> 	jmp	sysret
  4318                              <1> 
  4319                              <1> sysdma_2:
  4320                              <1> 	; Get current dma buffer offset (& page)
  4321                              <1> 	; 28/08/2017
  4322 000130DC 0FB635[36930100]    <1> 	movzx	esi, byte [dma_channel]
  4323 000130E3 0FB696[F63B0100]    <1> 	movzx	edx, byte [dma_flip+esi]
  4324 000130EA EE                  <1> 	out	dx, al			; flip-flop clear
  4325 000130EB 8A96[CE3B0100]      <1> 	mov	dl, [dma_adr+esi]
  4326 000130F1 EC                  <1> 	in	al, dx			; get dma position
  4327 000130F2 0FB6D8              <1> 	movzx	ebx, al
  4328 000130F5 EC                  <1> 	in	al, dx
  4329 000130F6 88C7                <1> 	mov	bh, al
  4330                              <1> 
  4331 000130F8 6683FE04            <1> 	cmp	si, 4	; channel number ?
  4332 000130FC 7202                <1> 	jb	short sysdma_21 ; 8 bit dma channel
  4333                              <1> 
  4334 000130FE D1E3                <1> 	shl	ebx, 1	; word offset to byte offset
  4335                              <1> 
  4336                              <1> sysdma_21:
  4337 00013100 891D[74940100]      <1> 	mov	[u.r0], ebx
  4338                              <1> 
  4339 00013106 8A96[DE3B0100]      <1> 	mov	dl, [dma_page+esi]
  4340 0001310C EC                  <1> 	in	al, dx			; get dma page
  4341                              <1> 
  4342                              <1> 	;add	[u.ro+2], al
  4343 0001310D 0805[76940100]      <1> 	or	[u.r0+2], al
  4344                              <1> 
  4345 00013113 E93C9DFFFF          <1> 	jmp	sysret
  4346                              <1> 
  4347                              <1> sysdma_6:
  4348 00013118 80FF06              <1> 	cmp	bh, 6
  4349 0001311B 775C                <1> 	ja	short sysdma_7
  4350                              <1> 
  4351                              <1> 	; 28/08/2017
  4352                              <1> 	; Get current DMA buffer addr and size
  4353 0001311D A1[38930100]        <1> 	mov	eax, [dma_addr] ; dma buffer address
  4354 00013122 8B0D[3C930100]      <1> 	mov	ecx, [dma_size] ; dma buffer size (in bytes)
  4355                              <1> 
  4356 00013128 EB9F                <1> 	jmp	short sysdma_51
  4357                              <1> 
  4358                              <1> sysdma_3:
  4359 0001312A 80FF03              <1> 	cmp	bh, 3
  4360 0001312D 72AD                <1> 	jb	short sysdma_2
  4361 0001312F 772F                <1> 	ja	short sysdma_4
  4362                              <1> 
  4363                              <1> 	; Get current dma count down value (remain bytes)
  4364                              <1> 	; 28/08/2017
  4365 00013131 0FB635[36930100]    <1> 	movzx	esi, byte [dma_channel]
  4366 00013138 0FB696[F63B0100]    <1> 	movzx	edx, byte [dma_flip+esi]
  4367 0001313F EE                  <1> 	out	dx, al			; flip-flop clear
  4368 00013140 8A96[D63B0100]      <1> 	mov	dl, [dma_cnt+esi] ; dma count register addr
  4369 00013146 EC                  <1> 	in	al, dx
  4370 00013147 0FB6D8              <1> 	movzx	ebx, al
  4371 0001314A EC                  <1> 	in	al, dx
  4372 0001314B 88C7                <1> 	mov     bh, al
  4373                              <1> 	
  4374 0001314D 6683FE04            <1> 	cmp	si, 4	; channel number ?
  4375 00013151 7202                <1> 	jb	short sysdma_31 ; 8 bit dma channel
  4376                              <1> 
  4377 00013153 D1E3                <1> 	shl	ebx, 1	; word count to byte count
  4378                              <1> 
  4379                              <1> sysdma_31:
  4380 00013155 891D[74940100]      <1> 	mov	[u.r0], ebx
  4381                              <1> 
  4382 0001315B E9F49CFFFF          <1> 	jmp	sysret
  4383                              <1> 
  4384                              <1> sysdma_4:
  4385                              <1> 	; Get current DMA channel number
  4386                              <1> 	; 28/08/2017
  4387 00013160 8A25[35930100]      <1> 	mov	ah, [dma_user]
  4388 00013166 20E4                <1> 	and	ah, ah
  4389 00013168 7539                <1> 	jnz	short sysdma_42
  4390                              <1> 
  4391                              <1> sysdma_41:	
  4392                              <1> 	; Not a valid dma channel (in use)
  4393 0001316A C705[74940100]FFFF- <1> 	mov	dword [u.r0], -1 ; 0FFFFFFFFh
  4393 00013172 FFFF                <1>
  4394 00013174 E9DB9CFFFF          <1> 	jmp	sysret
  4395                              <1> 
  4396                              <1> sysdma_7:
  4397                              <1> 	; DMA service STOP
  4398 00013179 A0[C5940100]        <1> 	mov	al, [u.uno]
  4399 0001317E 3A05[35930100]      <1> 	cmp	al, [dma_user]
  4400 00013184 7543                <1> 	jne	short sysdma_72
  4401                              <1> 	
  4402 00013186 28C0                <1> 	sub	al, al ; 0
  4403                              <1> 
  4404 00013188 A2[35930100]        <1> 	mov	[dma_user], al ; clear user
  4405                              <1> 
  4406 0001318D 8605[37930100]      <1> 	xchg	al, [dma_mode]
  4407 00013193 20C0                <1> 	and	al, al
  4408                              <1> 	;jz	short sysdma_err
  4409 00013195 754E                <1> 	jnz	short sysdma_73	
  4410                              <1> 
  4411                              <1> sysdma_71:
  4412 00013197 31C0                <1> 	xor	eax, eax
  4413 00013199 A3[74940100]        <1> 	mov	[u.r0], eax; 0
  4414 0001319E E9B19CFFFF          <1> 	jmp	sysret
  4415                              <1> 
  4416                              <1> sysdma_42:
  4417 000131A3 8B35[38930100]      <1> 	mov	esi, [dma_addr]
  4418 000131A9 21F6                <1> 	and	esi, esi
  4419 000131AB 74BD                <1> 	jz	short sysdma_41
  4420                              <1> 
  4421 000131AD 46                  <1> 	inc	esi ; -1 -> 0
  4422 000131AE 74BA                <1> 	jz	short sysdma_41
  4423                              <1> 
  4424 000131B0 A0[36930100]        <1> 	mov	al, [dma_channel]
  4425                              <1> 
  4426 000131B5 3A25[C5940100]      <1> 	cmp	ah, [u.uno]
  4427 000131BB 7502                <1> 	jne	short sysdma_43
  4428                              <1> 
  4429 000131BD 30E4                <1> 	xor	ah, ah ; DMA channel in use by current user
  4430                              <1> 
  4431                              <1> sysdma_43:
  4432 000131BF A3[74940100]        <1> 	mov	[u.r0], eax ; AL = dma channel number
  4433                              <1> 			    ; AH > 0 if the the channel
  4434                              <1> 			    ; in use by another user/process
  4435 000131C4 E98B9CFFFF          <1> 	jmp	sysret
  4436                              <1> 
  4437                              <1> sysdma_72:
  4438                              <1> 	; 28/08/2017
  4439 000131C9 803D[35930100]00    <1> 	cmp	byte [dma_user], 0
  4440 000131D0 76C5                <1> 	jna	short sysdma_71 ; Nothing to do !
  4441                              <1> 
  4442 000131D2 833D[38930100]00    <1> 	cmp	dword [dma_addr], 0
  4443                              <1> 	;ja	sysdma_0_err
  4444                              <1> 	; 30/07/2022
  4445 000131D9 7605                <1> 	jna	short sysdma_74
  4446 000131DB E9BBFDFFFF          <1> 	jmp	sysdma_0_err
  4447                              <1> 
  4448                              <1> sysdma_74:	
  4449 000131E0 A2[35930100]        <1> 	mov	[dma_user], al ; reset to current user
  4450                              <1> 
  4451                              <1> sysdma_73:
  4452                              <1> 	; 28/08/2017
  4453 000131E5 0FB635[36930100]    <1> 	movzx	esi, byte [dma_channel]
  4454 000131EC 0FB696[E63B0100]    <1> 	movzx	edx, byte [dma_mask+esi]
  4455 000131F3 A0[36930100]        <1> 	mov	al, [dma_channel]
  4456 000131F8 0C04                <1> 	or	al, 4
  4457 000131FA EE                  <1> 	out	dx, al
  4458                              <1> 
  4459 000131FB EB9A                <1> 	jmp	short sysdma_71
  4460                              <1> 
  4461                              <1> dma_init:
  4462                              <1> 	; 30/07/2022 (TRDOS 386 Kernel v2.0.5)
  4463                              <1> 	; 28/08/2017
  4464                              <1> 	; 20/08/2017
  4465                              <1> 	; DMA initialization
  4466                              <1> 	; 14/08/2017
  4467                              <1> 	; 03/08/2017, 06/08/2017, 08/08/2017
  4468                              <1> 	; 02/07/2017, 13/07/2017, 16/07/2017, 30/07/2017
  4469                              <1> 	; (Derived from 'DMA_INIT' procedure in SB16MOD.ASM)
  4470                              <1> 	; Modified for TRDOS 386 DMA buffer allocation & initialization !
  4471                              <1> 
  4472 000131FD 8B1D[40930100]      <1> 	mov	ebx, [dma_start]
  4473 00013203 8B0D[44930100]      <1> 	mov	ecx, [dma_count]
  4474                              <1> 
  4475 00013209 0FB635[36930100]    <1> 	movzx	esi, byte [dma_channel]
  4476                              <1> 
  4477 00013210 6683FE04            <1> 	cmp	si, 4
  4478 00013214 7204                <1> 	jb	short gdmi1
  4479                              <1> 	; 08/08/2017
  4480                              <1> 	;shr	cx, 1 ; word count
  4481                              <1> 	; 30/07/2022
  4482 00013216 D1E9                <1> 	shr	ecx, 1
  4483 00013218 D1EB                <1> 	shr	ebx, 1 ; convert byte offset to word offset
  4484                              <1> gdmi1:
  4485                              <1> 	;mov	[dma_poff], bx ; 08/08/2017
  4486                              <1> 	;dec	cx			; dma size = block size - 1
  4487                              <1> 	; 30/07/2022
  4488 0001321A 49                  <1> 	dec	ecx	
  4489                              <1> 
  4490 0001321B 0FB696[E63B0100]    <1> 	movzx	edx, byte [dma_mask+esi] ; 30/07/2017
  4491 00013222 A0[36930100]        <1> 	mov	al, [dma_channel]
  4492 00013227 0C04                <1> 	or	al, 4
  4493 00013229 EE                  <1> 	out	dx, al			; dma channel mask
  4494                              <1> 
  4495 0001322A 30C0                <1> 	xor	al, al ; 0 ; any value ! 08/08/2017
  4496 0001322C 8A96[F63B0100]      <1> 	mov	dl, [dma_flip+esi]
  4497 00013232 EE                  <1> 	out	dx, al			; flip-flop clear
  4498                              <1> 	
  4499 00013233 8A96[EE3B0100]      <1> 	mov	dl, [dma_mod+esi]
  4500 00013239 A0[36930100]        <1> 	mov	al, [dma_channel]  ; 13/07/2017
  4501 0001323E 2403                <1> 	and	al, 3
  4502                              <1> 	; 08/08/2017
  4503 00013240 0A05[37930100]      <1> 	or	al, [dma_mode] ; 58h    ; dma mode for SB16
  4504 00013246 EE                  <1> 	out	dx, al
  4505                              <1> 
  4506 00013247 8A96[CE3B0100]      <1> 	mov	dl, [dma_adr+esi]
  4507 0001324D 88D8                <1> 	mov	al, bl
  4508 0001324F EE                  <1> 	out	dx, al			; offset low
  4509                              <1> 
  4510 00013250 88F8                <1> 	mov	al, bh
  4511 00013252 EE                  <1> 	out	dx, al			; offset high
  4512                              <1> 
  4513 00013253 8A96[D63B0100]      <1> 	mov	dl, [dma_cnt+esi]
  4514 00013259 88C8                <1> 	mov	al, cl
  4515 0001325B EE                  <1> 	out	dx, al			; size low
  4516                              <1> 
  4517 0001325C 88E8                <1> 	mov	al, ch
  4518 0001325E EE                  <1> 	out	dx, al			; size high
  4519                              <1> 
  4520 0001325F 8A96[DE3B0100]      <1> 	mov	dl, [dma_page+esi]
  4521                              <1> 	; 14/08/2017 
  4522 00013265 6683FE04            <1> 	cmp	si, 4
  4523 00013269 7305                <1> 	jnb	short gdmi2
  4524 0001326B C1EB10              <1> 	shr	ebx, 16
  4525 0001326E EB06                <1> 	jmp	short gdmi3
  4526                              <1> gdmi2:
  4527                              <1> 	; 09/08/2017
  4528 00013270 C1EB0F              <1> 	shr	ebx, 15	 ; complete 16 bit shift
  4529 00013273 80E3FE              <1> 	and	bl, 0FEh ; clear bit 0 (not necessary)
  4530                              <1> gdmi3:	
  4531 00013276 88D8                <1> 	mov	al, bl
  4532 00013278 EE                  <1> 	out	dx, al			; page
  4533                              <1> 	
  4534 00013279 8A96[E63B0100]      <1> 	mov	dl, [dma_mask+esi]
  4535 0001327F A0[36930100]        <1> 	mov	al, [dma_channel]  ; 13/07/2017
  4536 00013284 2403                <1> 	and	al, 3
  4537 00013286 EE                  <1> 	out	dx, al			; dma channel unmask
  4538                              <1> 
  4539                              <1> 	;retn
  4540                              <1> 	; 28/08/2017
  4541 00013287 E9C89BFFFF          <1> 	jmp	sysret
  4542                              <1> 
  4543                              <1> sysstdio: ; STDIN/STDOUT/STDERR functions
  4544                              <1> 	; 18/09/2024
  4545                              <1> 	; 07/09/2024
  4546                              <1> 	;	(STDAUX/STDPRN functions, pre-definions)
  4547                              <1> 	;	(!these functions are not ready!)
  4548                              <1> 	; 24/08/2024
  4549                              <1> 	; 23/08/2024
  4550                              <1> 	; 20/08/2024 - TRDOS 386 Kernel v2.0.9
  4551                              <1> 	;
  4552                              <1> 	; Inputs:
  4553                              <1> 	;	BL = 0 -> read a character on stdin (wait)
  4554                              <1> 	;	BL = 1 -> read a character on stdin (no wait)
  4555                              <1> 	;	BL = 2 -> write a character onto stdout (redirection)
  4556                              <1> 	;	BL = 3 -> write a character onto stderr (no redirection)
  4557                              <1> 	;	BL = 4 -> redirect stdin to file (if cl > 0)
  4558                              <1> 	;	BL = 5 -> redirect stdout to file (if cl > 0)
  4559                              <1> 	;	BL = 6 -> read character (ascii and scancode) on stdin
  4560                              <1> 	;				-no redirection, wait-
  4561                              <1> 	;	BL = 7 -> read character (ascii and scancode) on stdin
  4562                              <1> 	;				-no redirection, no wait-
  4563                              <1> 	;	BL = 8 -> write character and color onto stdout
  4564                              <1> 	;				-no redirection-
  4565                              <1> 	;	BL = 9 -> ungetchar (put back the ascii code in u.getc)
  4566                              <1> 	;
  4567                              <1> 	;	For BL=2,3,8,9
  4568                              <1> 	;	    CL = character (ascii) code
  4569                              <1> 	;	For BL=8
  4570                              <1> 	;	    CH = color (Attribute) -CGA-
  4571                              <1> 	;	For BL=4,5
  4572                              <1> 	;	    CL = file descriptor number + 1
  4573                              <1> 	;	    (File must be open and that number is 'u.fp' index)
  4574                              <1> 	;
  4575                              <1> 	;	07/09/2024 (these subfunctions will not be handled
  4576                              <1> 	;		   by kernel v2.0.9 for now)
  4577                              <1> 	;	 -I am writing them here for C compiler compatibility,
  4578                              <1> 	;	  for now. Ref: SCC STDIO.H-
  4579                              <1> 	;	BL = 10 -> get STDAUX status
  4580                              <1> 	;	BL = 11 -> get/select STDAUX (COM) port
  4581                              <1> 	;				(clears redirection)
  4582                              <1> 	;	BL = 12 -> redirect STDAUX
  4583                              <1> 	;	BL = 13 -> STDAUX IOCTL (control functions)
  4584                              <1> 	;	BL = 14 -> read byte/character from STDAUX
  4585                              <1> 	;	BL = 15 -> write byte/character to STDAUX
  4586                              <1> 	;	BL = 16 -> get STDPRN status (LPT printer only)
  4587                              <1> 	;	BL = 17 -> redirect STDPRN
  4588                              <1> 	;	BL = 18 -> STDPRN IOCTL (init/control functions)
  4589                              <1> 	;	BL = 19 -> write byte/character to STDPRN
  4590                              <1> 	;
  4591                              <1> 	;	For BL = 11
  4592                              <1> 	;	    If	CL = 0 -> get STDAUX (COM) port number
  4593                              <1> 	;		CL = 1 -> COM1
  4594                              <1> 	;		CL = 2 -> COM2
  4595                              <1> 	;		CL > 4 -> invalid
  4596                              <1> 	;	For BL = 12
  4597                              <1> 	;	    If ECX = 0 -> clear redirection
  4598                              <1> 	;	    If  CH & 7Fh = 0 -> redirect INPUT
  4599                              <1> 	;	        CH & 7Fh > 0 -> redirect OUTPUT
  4600                              <1> 	;	    If  CH & 80h = 80h 
  4601                              <1> 	;		CL = file handle (descriptor index)
  4602                              <1> 	;	    If  CH & 80h = 0
  4603                              <1> 	;		CL = console (pseudo) tty number,
  4604                              <1> 	;		     1 to 8 for tty0 to tty7.
  4605                              <1> 	;	For BL = 13
  4606                              <1> 	;	    If CL = 0 -> get control byte
  4607                              <1> 	;	    If CL > 1 -> set control byte (in CL)
  4608                              <1> 	;		bit 0 = 1
  4609                              <1> 	;		bit 1 = data bits (set=8, clear=7)
  4610                              <1> 	;		bit 2 = stop bit (set=2, clear=1)
  4611                              <1> 	;		bit 3 = parity bit (set=yes, clear=no)
  4612                              <1> 	;		bit 4 = parity bit (set=even, clear=odd)
  4613                              <1> 	;		bit 5-6-7 = data rate
  4614                              <1> 	;			000 = 9600
  4615                              <1> 	;		        001 = 19200
  4616                              <1> 	;			010 = 38400
  4617                              <1> 	;			011 = 57600
  4618                              <1> 	;			100 = 115200
  4619                              <1> 	;	For BL = 15, 19
  4620                              <1> 	;	    CL = byte/character to r/w
  4621                              <1> 	;	For BL = 17
  4622                              <1> 	;	    If ECX = 0 -> clear redirection	
  4623                              <1> 	;	    If  CH & 80h = 80h 
  4624                              <1> 	;		CL = file handle (descriptor index)
  4625                              <1> 	;	    If  CH & 80h = 0
  4626                              <1> 	;		CL = console (pseudo) tty number,
  4627                              <1> 	;		     1 to 8 for tty0 to tty7.
  4628                              <1> 	;	For BL = 18
  4629                              <1> 	;	    If CL = 0 -> initialize printer (command=0)
  4630                              <1> 	;	       CL > 0 -> configuration/command byte
  4631                              <1> 	;			 (reserved, not used)		
  4632                              <1> 	;
  4633                              <1> 	; Outputs:
  4634                              <1> 	;
  4635                              <1> 	;	For BL=0,1,2,3,6,7,8,9
  4636                              <1> 	;	    AL = character (ascii) code
  4637                              <1> 	;	For BL=6,7
  4638                              <1> 	;	    AH = scan code
  4639                              <1> 	;	For BL=4,5
  4640                              <1> 	;	    AL = file descriptor (CL input - 1)	
  4641                              <1> 	;
  4642                              <1> 	;	If CF=1
  4643                              <1> 	;	   AL (EAX) = error code
  4644                              <1> 	;	   If EAX = 0 -> EOF ; 18/09/2024
  4645                              <1> 	;
  4646                              <1> 	;	07/09/2024
  4647                              <1> 	;	For BL = 10 to 19
  4648                              <1> 	;	    IF CF = 1, EAX/AL = error code 		
  4649                              <1> 	;    .. If CF = 0 ...
  4650                              <1> 	;	For BL = 10 & 16
  4651                              <1> 	;	    AL (EAX) = status
  4652                              <1> 	;	For BL = 11
  4653                              <1> 	;	    EAX/AL = COM (serial) port (1 to 4)
  4654                              <1> 	;	For BL = 12, 15, 17, 18, 19
  4655                              <1> 	;	    EAX/AL = 0
  4656                              <1> 	;	For BL = 13
  4657                              <1> 	;	    If CL input = 0
  4658                              <1> 	;		  EAX/AL = current ctrl/cfg byte
  4659                              <1> 	;           If CL input > 0
  4660                              <1> 	;		  EAX/AL = ctrl/cfg byte
  4661                              <1> 	;	For BL = 14
  4662                              <1> 	;	    EAX/AL = byte/character
  4663                              <1> 	;			
  4664                              <1> 
  4665 0001328C 80FB0A              <1> 	cmp	bl, (end_of_stdiofuncs-stdiofuncs)>>2
  4666 0001328F 7214                <1> 	jb	short sysstdio_0
  4667                              <1> 	
  4668                              <1> 	; invalid parameter (invalid sub function number)
  4669 00013291 B817000000          <1> 	mov	eax, ERR_INV_PARAMETER
  4670                              <1> sysstdio_err:
  4671 00013296 A3[74940100]        <1> 	mov	[u.r0], eax
  4672 0001329B A3[E0940100]        <1> 	mov	[u.error], eax
  4673 000132A0 E98F9BFFFF          <1> 	jmp	error
  4674                              <1> 
  4675                              <1> sysstdio_0:
  4676 000132A5 31C0                <1> 	xor	eax, eax ; 0
  4677 000132A7 A3[E0940100]        <1> 	mov	[u.error], eax ; clear previous error code	
  4678 000132AC A3[74940100]        <1> 	mov	[u.r0], eax ; clear previous return code
  4679                              <1> 
  4680 000132B1 0FB6F3              <1> 	movzx	esi, bl
  4681 000132B4 C1E602              <1> 	shl	esi, 2
  4682 000132B7 FFA6[BD320100]      <1> 	jmp	dword [esi+stdiofuncs]
  4683                              <1> 
  4684                              <1> stdiofuncs:
  4685 000132BD [47330100]          <1> 	dd	readstdinw
  4686 000132C1 [47330100]          <1> 	dd	readstdinnw
  4687 000132C5 [5E340100]          <1> 	dd	writestdout
  4688 000132C9 [15340100]          <1> 	dd	writestderr
  4689 000132CD [E5320100]          <1> 	dd	redirstdin
  4690 000132D1 [23330100]          <1> 	dd	redirstdout
  4691                              <1> stdinacsc:
  4692 000132D5 [33340100]          <1> 	dd	readstdin2w
  4693 000132D9 [33340100]          <1> 	dd	readstdin2nw
  4694                              <1> stdoutcc:
  4695 000132DD [69340100]          <1> 	dd	writestdoutcc
  4696 000132E1 [80340100]          <1> 	dd	ungetchar
  4697                              <1> end_of_stdiofuncs:
  4698                              <1> 
  4699                              <1> redirstdin:
  4700                              <1> 	; CL = file handle (descriptor/index) + 1
  4701 000132E5 08C9                <1> 	or	cl, cl
  4702 000132E7 7508                <1> 	jnz	short redirstdin_0
  4703 000132E9 880D[DC940100]      <1> 	mov	[u.stdin], cl ; 0 ; reset STDIN to keyboard
  4704 000132EF EB24                <1> 	jmp	short redirstdin_3
  4705                              <1> redirstdin_0: 
  4706 000132F1 88C8                <1> 	mov	al, cl
  4707 000132F3 E807D4FFFF          <1> 	call	getf
  4708                              <1> 	; eax = first cluster
  4709                              <1> 	; ebx = system (not user) open file index
  4710 000132F8 80BB[208A0100]01    <1> 	cmp	byte [ebx+OF_MODE], 1 ; open for read
  4711 000132FF 7407                <1> 	je	short redirstdin_1
  4712                              <1> redir_acc_denied:
  4713 00013301 B805000000          <1> 	mov	eax, ERR_ACCESS_DENIED
  4714 00013306 EB8E                <1> 	jmp	short sysstdio_err
  4715                              <1> redirstdin_1:
  4716 00013308 880D[DC940100]      <1> 	mov	[u.stdin], cl
  4717                              <1> redirstdout_2:
  4718 0001330E 49                  <1> 	dec	ecx
  4719 0001330F 880D[74940100]      <1> 	mov	[u.r0], cl ; return file descriptor
  4720                              <1> redirstdin_3:
  4721                              <1> redirstdout_3:
  4722 00013315 66C705[DE940100]00- <1> 	mov	word [u.ungetc], 0
  4722 0001331D 00                  <1>
  4723                              <1> 		; reset u.ungetc and u.getc
  4724 0001331E E9319BFFFF          <1> 	jmp	sysret
  4725                              <1> 
  4726                              <1> redirstdout:
  4727                              <1> 	; CL = file handle (descriptor/index) + 1
  4728 00013323 08C9                <1> 	or	cl, cl
  4729 00013325 7508                <1> 	jnz	short redirstdout_0
  4730 00013327 880D[DD940100]      <1> 	mov	[u.stdout], cl ; 0 ; reset STDOUT to keyboard
  4731 0001332D EBE6                <1> 	jmp	short redirstdout_3
  4732                              <1> redirstdout_0: 
  4733 0001332F 88C8                <1> 	mov	al, cl
  4734 00013331 E8C9D3FFFF          <1> 	call	getf
  4735                              <1> 	; eax = first cluster
  4736                              <1> 	; ebx = system (not user) open file index
  4737 00013336 80BB[208A0100]02    <1> 	cmp	byte [ebx+OF_MODE], 2 ; open for write
  4738 0001333D 75C2                <1> 	jne	short redir_acc_denied
  4739                              <1> redirstdout_1:
  4740 0001333F 880D[DD940100]      <1> 	mov	[u.stdout], cl
  4741 00013345 EBC7                <1> 	jmp	short redirstdout_2
  4742                              <1> 	
  4743                              <1> readstdinw:
  4744                              <1> readstdinnw:
  4745                              <1> 	; read a character on stdin (wait)
  4746                              <1> 	;sub	eax, eax
  4747 00013347 3805[DE940100]      <1> 	cmp	byte [u.ungetc], al ; 0
  4748 0001334D 761E                <1> 	jna	short readstdinw_0
  4749                              <1> 	; read the character in u.getc buffer (put by ungetchar)
  4750 0001334F A2[DE940100]        <1> 	mov	[u.ungetc], al ; 0
  4751 00013354 8605[DF940100]      <1> 	xchg	al, [u.getc]
  4752                              <1> readstdinw_retn:
  4753 0001335A A2[74940100]        <1> 	mov	[u.r0], al
  4754 0001335F E9F09AFFFF          <1> 	jmp	sysret
  4755                              <1> 
  4756                              <1> readstdinw_3:
  4757                              <1> 	; 23/08/2024
  4758 00013364 B410                <1> 	mov	ah, 10h
  4759 00013366 E8B1DBFEFF          <1> 	call	int16h
  4760 0001336B EBED                <1> 	jmp	short readstdinw_retn
  4761                              <1> 
  4762                              <1> readstdinw_0:
  4763 0001336D A0[DC940100]        <1> 	mov	al, [u.stdin]
  4764 00013372 08C0                <1> 	or	al, al
  4765 00013374 745F                <1> 	jz	short readstdinw_1
  4766                              <1> 
  4767                              <1> readstdinf:
  4768                              <1> 	; 24/08/2024
  4769 00013376 48                  <1> 	dec	eax
  4770                              <1> 
  4771                              <1> 	; file
  4772 00013377 89C3                <1> 	mov	ebx, eax ; File handle (descriptor/index)
  4773                              <1> 	; 18/09/2024
  4774 00013379 B9[98340100]        <1> 	mov	ecx, charbuf ; buffer address
  4775 0001337E BA01000000          <1> 	mov	edx, 1  ; 1 character only
  4776                              <1> 
  4777                              <1> 	; 18/09/2024
  4778                              <1> 	;;;
  4779 00013383 E879D3FFFF          <1> 	call	getf1
  4780 00013388 722B                <1> 	jc	short redirect_fno_err
  4781                              <1> 	
  4782                              <1> readstdinf_@:
  4783                              <1> 	; eax = first cluster
  4784                              <1> 	; ebx = file descriptor (system, open files)
  4785                              <1> 
  4786 0001338A E84AA2FFFF          <1> 	call	rw1
  4787 0001338F 7229                <1> 	jc	short redirection_err
  4788                              <1> 
  4789 00013391 FE05[DA940100]      <1> 	inc	byte [u.kcall]
  4790                              <1> 	;mov	byte [u.kcall], 1 ; >0 means system buffer
  4791                              <1> 			      ; (buff addr is not virtual)
  4792 00013397 E83BD7FFFF          <1> 	call	readi
  4793                              <1> 
  4794                              <1> redirected_rw_OK:
  4795 0001339C 31C0                <1> 	xor	eax, eax
  4796 0001339E 3905[A0940100]      <1> 	cmp	[u.nread], eax ; 0
  4797 000133A4 7623                <1> 	jna	short readstdinf_EOF
  4798                              <1> 
  4799 000133A6 A0[98340100]        <1> 	mov	al, [charbuf]
  4800                              <1> ;redirected_w_not_OK:
  4801 000133AB A3[74940100]        <1> 	mov	[u.r0], eax
  4802 000133B0 E99F9AFFFF          <1> 	jmp	sysret
  4803                              <1> 
  4804                              <1> redirect_fno_err:
  4805 000133B5 B80A000000          <1> 	mov 	eax, ERR_FILE_NOT_OPEN ; file not open !
  4806                              <1> redirection_err:
  4807 000133BA A3[E0940100]        <1> 	mov	[u.error], eax
  4808                              <1> readstdinf_EOF_@:
  4809 000133BF A3[74940100]        <1> 	mov	[u.r0], eax ; error code ; 0 = EOF
  4810 000133C4 E96B9AFFFF          <1> 	jmp	error
  4811                              <1> 
  4812                              <1> readstdinf_EOF:
  4813                              <1> 	; 'end of file !' error 
  4814 000133C9 C705[E0940100]1000- <1> 	mov	dword [u.error], ERR_FILE_EOF ; 16
  4814 000133D1 0000                <1>
  4815 000133D3 EBEA                <1> 	jmp	short readstdinf_EOF_@
  4816                              <1> 	;;;
  4817                              <1> 
  4818                              <1> readstdinw_1:
  4819                              <1> 	; 18/09/2024
  4820 000133D5 20DB                <1> 	and	bl, bl
  4821 000133D7 748B                <1> 	jz	short readstdinw_3 ; wait (int16h, 10h)
  4822                              <1> 	; no wait (int16h, 11h)
  4823 000133D9 B411                <1> 	mov	ah,11h	; EXTENDED ASCII STATUS
  4824 000133DB E83CDBFEFF          <1> 	call	int16h
  4825                              <1> 	; ah = scan code, al = ascii code
  4826                              <1> 	;jnz	short readstdinw_retn
  4827                              <1> 	; 23/08/2024
  4828 000133E0 7582                <1> 	jnz	short readstdinw_3
  4829                              <1> readstdinw_2:
  4830                              <1> 
  4831                              <1> ; 23/08/2024
  4832                              <1> ;	; if zf=1 at here
  4833                              <1> ;	; it means 'no code available' for function 11h
  4834                              <1> ;	and	bl, bl	; 0 ?
  4835                              <1> ;	jz	short  short readstdinw_retn ; function 10h
  4836                              <1> ;	; function 11h
  4837                              <1> ;	; [u.r0] = 0 = eax return
  4838                              <1> readstdin2w@_retn:
  4839 000133E2 E96D9AFFFF          <1> 	jmp	sysret
  4840                              <1> 
  4841                              <1> writestdoutf:
  4842                              <1> 	; 24/08/2024
  4843 000133E7 48                  <1> 	dec	eax
  4844                              <1> 
  4845                              <1> 	; file
  4846 000133E8 89C3                <1> 	mov	ebx, eax ; File handle (descriptor/index)
  4847                              <1> 	; 18/09/2024
  4848 000133EA 880D[98340100]      <1> 	mov	byte [charbuf], cl
  4849 000133F0 B9[98340100]        <1> 	mov	ecx, charbuf
  4850 000133F5 BA01000000          <1> 	mov	edx, 1  ; 1 character only
  4851                              <1> 
  4852                              <1> 	; 18/09/2024
  4853                              <1> 	;;;
  4854 000133FA E802D3FFFF          <1> 	call	getf1
  4855 000133FF 72B4                <1> 	jc	short redirect_fno_err
  4856                              <1> 
  4857                              <1> writestdoutf_@:
  4858                              <1> 	; eax = first cluster
  4859                              <1> 	; ebx = file descriptor (system, open files)
  4860                              <1> 
  4861 00013401 E8D3A1FFFF          <1> 	call	rw1
  4862 00013406 72B2                <1> 	jc	short redirection_err
  4863                              <1> 
  4864 00013408 FE05[DA940100]      <1> 	inc	byte [u.kcall]
  4865                              <1> 	;mov	byte [u.kcall], 1 ; >0 means system buffer
  4866                              <1> 			      ; (buff addr is not virtual)
  4867 0001340E E8DFDDFFFF          <1> 	call	writei
  4868                              <1> 
  4869                              <1> 	;xor	eax, eax
  4870                              <1> 	;cmp	[u.nread], eax ; 0
  4871                              <1> 	;jna	short redirected_w_not_OK
  4872 00013413 EB87                <1> 	jmp	short redirected_rw_OK
  4873                              <1> 	;;;
  4874                              <1> 
  4875                              <1> writestderr:	; skip redirection
  4876                              <1> 		; STDERR = STDOUT (as file redirection disabled)
  4877 00013415 88C8                <1> 	mov	al, cl  ; character
  4878 00013417 A2[74940100]        <1> 	mov	[u.r0], al
  4879 0001341C B40E                <1> 	mov	ah, 0Eh	; write a character (as tty write)
  4880 0001341E BB07000000          <1> 	mov	ebx, 07h ; video page 0 (and color/attrib 07h)
  4881                              <1> 	; 23/08/2024
  4882 00013423 8A3D[EE7C0100]      <1> 	mov	bh, [ptty] ; ACTIVE_PAGE
  4883 00013429 E8F6E2FEFF          <1> 	call	_int10h
  4884 0001342E E9219AFFFF          <1> 	jmp	sysret
  4885                              <1> 
  4886                              <1> readstdin2w:
  4887                              <1> readstdin2nw:
  4888 00013433 66C705[DE940100]00- <1> 	mov	word [u.ungetc], 0
  4888 0001343B 00                  <1>
  4889                              <1> 		; reset u.ungetc and u.getc
  4890 0001343C B410                <1> 	mov	ah, 10h  ; Keyboard, EXTENDED READ
  4891                              <1> 	;cmp	bl, 6
  4892 0001343E 80FB06              <1> 	cmp	bl, (stdinacsc-stdiofuncs)>>2
  4893 00013441 740B                <1> 	je	short readstdin2w_1 ; wait (int16h, 10h)
  4894                              <1> 	; no wait (int16h, 11h)
  4895 00013443 FEC4                <1> 	inc	ah  ; function 11h ; EXTENDED ASCII STATUS
  4896                              <1> 
  4897                              <1> 	; 24/08/2024
  4898 00013445 E8D2DAFEFF          <1> 	call	int16h
  4899                              <1> 	; ah = scan code, al = ascii code
  4900                              <1> 	;jnz	short readstdin2w_retn
  4901                              <1> 	; 23/08/2024
  4902 0001344A 7496                <1> 	jz	short readstdin2w@_retn
  4903                              <1> ;readstdin2w_1:
  4904                              <1> 
  4905                              <1> ; 23/08/2024
  4906                              <1> ;	; if zf=1 at here
  4907                              <1> ;	; it means 'no code available' for function 11h
  4908                              <1> ;	;cmp	bl, 6
  4909                              <1> ;	cmp	bl, (stdinacsc-stdiofuncs)>>2
  4910                              <1> ;	;je	short readstdin2w_retn ; function 10h
  4911                              <1> ;	; function 11h
  4912                              <1> ;	; [u.r0] = 0 = eax return
  4913                              <1> ;	;jmp	sysret
  4914                              <1> ;	jne	short readstdin2w@_retn
  4915                              <1> 
  4916                              <1> 	; 23/08/2024
  4917 0001344C B410                <1> 	mov	ah, 10h
  4918                              <1> readstdin2w_1:	; 18/09/2024
  4919 0001344E E8C9DAFEFF          <1> 	call	int16h
  4920                              <1> 
  4921                              <1> readstdin2w_retn:
  4922 00013453 66A3[74940100]      <1> 	mov	[u.r0], ax
  4923 00013459 E9F699FFFF          <1> 	jmp	sysret
  4924                              <1> 
  4925                              <1> writestdout:
  4926                              <1> 	; 18/09/2024
  4927 0001345E A0[DD940100]        <1> 	mov	al, [u.stdout]
  4928 00013463 20C0                <1> 	and	al, al
  4929 00013465 7580                <1> 	jnz	short writestdoutf ; 18/09/2024
  4930                              <1> 
  4931                              <1> writestdout_1:
  4932                              <1> 	;mov	byte [ccolor], 07h ; default color (CGA) 
  4933                              <1> 			; (black background, light gray character) 
  4934                              <1> 	; 18/09/2024
  4935 00013467 B507                <1> 	mov	ch, 07h
  4936                              <1> writestdoutcc:	
  4937 00013469 BE[74940100]        <1> 	mov	esi, u.r0 ; buffer
  4938                              <1> 	; 18/09/2024
  4939 0001346E 880E                <1> 	mov	[esi], cl ; character
  4940                              <1> 	;;cmp	bl, 8 ; write char and color
  4941                              <1> 	;cmp	bl, (stdoutcc-stdiofuncs)>>2
  4942                              <1> 	;jne	short writestdout_2
  4943 00013470 882D[EF7C0100]      <1> 	mov	byte [ccolor], ch ; color/attribute (CGA)
  4944                              <1> writestdout_2:
  4945 00013476 E80AD5FFFF          <1> 	call	print_cmsg
  4946                              <1> 	; 18/09/2024
  4947                              <1> 	;mov	byte [ccolor], 07h ; set default color again
  4948                              <1> 
  4949                              <1> 	; [u.r0] = written character (AL)
  4950 0001347B E9D499FFFF          <1> 	jmp	sysret
  4951                              <1> 
  4952                              <1> ungetchar:
  4953                              <1> 	; put a character back in u.getc STDIN buffer
  4954 00013480 C605[DE940100]01    <1> 	mov	byte [u.ungetc], 1 
  4955 00013487 880D[DF940100]      <1> 	mov	[u.getc], cl
  4956 0001348D 880D[74940100]      <1> 	mov	[u.r0],cl
  4957 00013493 E9BC99FFFF          <1> 	jmp	sysret
  4958                              <1> 
  4959                              <1> 	; 18/09/2024
  4960 00013498 00                  <1> charbuf: db 0
  4961                              <1> 
  4962                              <1> otty:
  4963                              <1> sret:
  4964                              <1> ocvt:
  4965                              <1> ctty:
  4966                              <1> cret:
  4967                              <1> ccvt:
  4968                              <1> rtty:
  4969                              <1> wtty:
  4970                              <1> rmem:
  4971                              <1> wmem:
  4972                              <1> rfd:
  4973                              <1> rhd:
  4974                              <1> wfd:
  4975                              <1> whd:
  4976                              <1> rlpt:
  4977                              <1> wlpt:
  4978                              <1> rcvt:
  4979                              <1> xmtt:
  4980 00013499 C3                  <1> 	retn
  3438                                  %include 'trdosk9.s' ; 04/01/2016
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.9) - INITIALIZED DATA : trdosk9.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 29/12/2024 (Previous: 23/06/2024 - Kernel v2.0.8)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 04/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; ----------------------------------------------------------------------------
     9                              <1> ; Assembler: NASM version 2.15 (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 0001349A 01                  <1> 		db 1 ; A: = 0 & B: = 1
    22                              <1> 
    23                              <1> Restore_CDIR:	
    24 0001349B FF                  <1> 		db 0FFh ; Initial value -> any number except 0
    25                              <1> 
    26                              <1> msg_CRLF_temp:  
    27 0001349C 070D0A00            <1> 		db 07h, 0Dh, 0Ah, 0
    28                              <1> 
    29                              <1> Magic_Bytes:
    30 000134A0 04                  <1> 		db 4
    31 000134A1 01                  <1> 		db 1
    32                              <1> mainprog_Version:
    33 000134A2 07                  <1> 		db 7
    34 000134A3 5B5452444F535D204D- <1> 		db "[TRDOS] Main Program v2.0.9 (29/12/2024)"
    34 000134AC 61696E2050726F6772- <1>
    34 000134B5 616D2076322E302E39- <1>
    34 000134BE 202832392F31322F32- <1>
    34 000134C7 30323429            <1>
    35 000134CB 0D0A                <1> 		db 0Dh, 0Ah
    36 000134CD 286329204572646F67- <1> 		db "(c) Erdogan Tan 2005-2024"
    36 000134D6 616E2054616E203230- <1>
    36 000134DF 30352D32303234      <1>
    37 000134E6 0D0A00              <1> 		db 0Dh, 0Ah, 0
    38                              <1> 
    39                              <1> MainProgCfgFile: ; 14/04/2016
    40 000134E9 4D41494E50524F472E- <1> 		db "MAINPROG.CFG", 0
    40 000134F2 43464700            <1>
    41                              <1> 
    42                              <1> TRDOSPromptLabel:
    43 000134F6 5452444F53          <1> 		db "TRDOS"
    44 000134FB 00                  <1> 		db 0
    45 000134FC 00<rep 5h>          <1>                 times 5 db 0
    46 00013501 00                  <1> 		db 0
    47                              <1> 
    48                              <1> ; INTERNAL COMMANDS
    49                              <1> Command_List:
    50 00013502 44495200            <1> Cmd_Dir:	db "DIR", 0
    51 00013506 434400              <1> Cmd_Cd:		db "CD", 0
    52 00013509 433A00              <1> Cmd_Drive:	db "C:", 0
    53 0001350C 56455200            <1> Cmd_Ver:	db "VER", 0
    54 00013510 4558495400          <1> Cmd_Exit:	db "EXIT", 0
    55 00013515 50524F4D505400      <1> Cmd_Prompt:	db "PROMPT", 0
    56 0001351C 564F4C554D4500      <1> Cmd_Volume:	db "VOLUME", 0
    57 00013523 4C4F4E474E414D4500  <1> Cmd_LongName:	db "LONGNAME", 0
    58 0001352C 4441544500          <1> Cmd_Date:	db "DATE", 0
    59 00013531 54494D4500          <1> Cmd_Time:	db "TIME", 0
    60 00013536 52554E00            <1> Cmd_Run:	db "RUN", 0
    61 0001353A 53455400            <1> Cmd_Set:	db "SET", 0 
    62 0001353E 434C5300            <1> Cmd_Cls:	db "CLS", 0
    63 00013542 53484F5700          <1> Cmd_Show:	db "SHOW", 0
    64 00013547 44454C00            <1> Cmd_Del:	db "DEL", 0
    65 0001354B 41545452494200      <1> Cmd_Attrib:	db "ATTRIB", 0
    66 00013552 52454E414D4500      <1> Cmd_Rename:	db "RENAME", 0
    67 00013559 524D44495200        <1> Cmd_Rmdir:	db "RMDIR", 0
    68 0001355F 4D4B44495200        <1> Cmd_Mkdir:	db "MKDIR", 0
    69 00013565 434F505900          <1> Cmd_Copy:	db "COPY", 0
    70 0001356A 4D4F564500          <1> Cmd_Move:	db "MOVE", 0
    71 0001356F 5041544800          <1> Cmd_Path:	db "PATH", 0
    72 00013574 4D454D00            <1> Cmd_Mem:	db "MEM", 0
    73 00013578 00                  <1> 		db 0
    74 00013579 46494E4400          <1> Cmd_Find:	db "FIND", 0
    75 0001357E 4543484F00          <1> Cmd_Echo:	db "ECHO", 0
    76 00013583 2A00                <1> Cmd_Remark:	db "*", 0
    77 00013585 3F00                <1> Cmd_Help:	db "?", 0
    78 00013587 44455649434500      <1> Cmd_Device:	db "DEVICE", 0
    79 0001358E 4445564C49535400    <1> Cmd_DevList:	db "DEVLIST", 0
    80 00013596 434844495200        <1> Cmd_Chdir:	db "CHDIR", 0
    81 0001359C 4245455000          <1> Cmd_Beep:	db "BEEP", 0
    82                              <1> 		
    83 000135A1 00                  <1> 		db 0
    84                              <1> 
    85                              <1> ; 15/02/2016 (FILE.ASM, 09/10/2011)
    86                              <1> invalid_fname_chars:
    87 000135A2 222728292A2B2C2F    <1> 		db 22h, 27h, 28h, 29h, 2Ah, 2Bh, 2Ch, 2Fh
    88 000135AA 3A3B3C3D3E3F40      <1> 		db 3Ah, 3Bh, 3Ch, 3Dh, 3Eh, 3Fh, 40h
    89 000135B1 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 000135B6 456E746572206E6577- <1>                 db 'Enter new date (dd-mm-yy): '
    94 000135BF 206461746520286464- <1>
    94 000135C8 2D6D6D2D7979293A20  <1>
    95 000135D1 00                  <1>                 db 0
    96                              <1> Msg_Show_Date:
    97 000135D2 43757272656E742064- <1>                 db   'Current date is '
    97 000135DB 61746520697320      <1>
    98 000135E2 30                  <1> Day:            db   '0'
    99 000135E3 30                  <1> 		db   '0'
   100 000135E4 2F                  <1>                 db   '/'
   101 000135E5 30                  <1> Month:          db   '0'
   102 000135E6 30                  <1> 		db   '0'
   103 000135E7 2F                  <1>                 db   '/'
   104 000135E8 30                  <1> Century:        db   '0'
   105 000135E9 30                  <1>                 db   '0'
   106 000135EA 30                  <1> Year:           db   '0'
   107 000135EB 30                  <1> 		db   '0'
   108 000135EC 0D0A00              <1>                 db   0Dh, 0Ah, 0
   109                              <1> 
   110                              <1> Msg_Enter_Time:
   111 000135EF 456E746572206E6577- <1> 		db 'Enter new time: '
   111 000135F8 2074696D653A20      <1>
   112 000135FF 00                  <1> 		db 0
   113                              <1> Msg_Show_Time:
   114 00013600 43757272656E742074- <1> 		db   'Current time is '
   114 00013609 696D6520697320      <1>
   115 00013610 30                  <1> Hour:           db   '0'
   116 00013611 30                  <1> 		db   '0'
   117 00013612 3A                  <1> 		db   ':'
   118 00013613 30                  <1> Minute:         db   '0'
   119 00013614 30                  <1> 		db   '0'
   120 00013615 3A                  <1> 		db   ':'
   121 00013616 30                  <1> Second:         db   '0'
   122 00013617 30                  <1> 		db   '0'
   123 00013618 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 0001361B 206B696C6F62797465- <1> 		db " kilobytes", 0Dh, 0Ah, 0
   129 00013624 730D0A00            <1>
   130                              <1> VolSize_Bytes:
   131 00013628 2062797465730D0A00  <1> 		db " bytes", 0Dh, 0Ah, 0
   132                              <1> Volume_in_drive:
   133 00013631 0D0A                <1> 		db 0Dh, 0Ah
   134                              <1> Vol_FS_Name:
   135 00013633 54522046533120      <1> 		db "TR FS1 "
   136 0001363A 566F6C756D6520696E- <1> 		db "Volume in drive "
   136 00013643 20647269766520      <1>
   137 0001364A 30                  <1> Vol_Drv_Name:   db 30h
   138 0001364B 3A                  <1> 		db ":"
   139 0001364C 20697320            <1> 		db " is "
   140 00013650 0D0A00              <1> 		db 0Dh, 0Ah, 0
   141                              <1> Dir_Drive_Str:
   142 00013653 54522D444F53204472- <1>                 db "TR-DOS Drive "
   142 0001365C 69766520            <1>
   143                              <1> Dir_Drive_Name:
   144 00013660 303A                <1>                 db "0:"
   145 00013662 0D0A                <1>                 db  0Dh, 0Ah
   146                              <1> Vol_Str_Header:
   147 00013664 566F6C756D65204E61- <1>                 db "Volume Name: "
   147 0001366D 6D653A20            <1>
   148                              <1> Vol_Name:
   149 00013671 00<rep 40h>         <1> 		times 64 db 0
   150 000136B1 00                  <1> 		db 0
   151                              <1> Vol_Serial_Header:
   152 000136B2 0D0A                <1> 		db 0Dh, 0Ah
   153 000136B4 566F6C756D65205365- <1> 		db "Volume Serial No: "
   153 000136BD 7269616C204E6F3A20  <1>
   154                              <1> Vol_Serial1:
   155 000136C6 30303030            <1> 		db "0000"
   156 000136CA 2D                  <1> 		db "-"
   157                              <1> Vol_Serial2:
   158 000136CB 30303030            <1> 		db "0000"
   159 000136CF 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 000136D2 0D0A                <1> 		db 0Dh, 0Ah
   165 000136D4 566F6C756D65205369- <1> 		db "Volume Size : ", 0
   165 000136DD 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 000136E3 467265652053706163- <1> 		db "Free Space  : ", 0
   173 000136EC 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 000136F2 4469726563746F7279- <1>                 db "Directory: "
   180 000136FB 3A20                <1>
   181 000136FD 2F                  <1> Dir_Str_Root:   db "/"
   182 000136FE 00<rep 40h>         <1> Dir_Str:        times 64 db 0
   183 0001373E 00000000            <1>                 dd 0
   184 00013742 00                  <1>                 db 0
   185                              <1> 
   186                              <1> Msg_Bad_Command:
   187 00013743 42616420636F6D6D61- <1>                 db "Bad command or file name!"
   187 0001374C 6E64206F722066696C- <1>
   187 00013755 65206E616D6521      <1>
   188 0001375C 0D0A00              <1>                 db 0Dh, 0Ah, 0
   189                              <1> 
   190                              <1> msgl_drv_not_ready: 
   191 0001375F 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 00013762 4472697665206E6F74- <1>                 db "Drive not ready or read error!"
   196 0001376B 207265616479206F72- <1>
   196 00013774 207265616420657272- <1>
   196 0001377D 6F7221              <1>
   197 00013780 0D0A00              <1>                 db 0Dh, 0Ah, 0
   198                              <1> 
   199                              <1> Msg_Not_Ready_Write_Err:
   200 00013783 4472697665206E6F74- <1>                 db "Drive not ready or write error!"
   200 0001378C 207265616479206F72- <1>
   200 00013795 207772697465206572- <1>
   200 0001379E 726F7221            <1>
   201 000137A2 0D0A00              <1>                 db 0Dh, 0Ah, 0
   202                              <1> 
   203                              <1> Msg_Dir_Not_Found:
   204 000137A5 4469726563746F7279- <1>                 db "Directory not found!"
   204 000137AE 206E6F7420666F756E- <1>
   204 000137B7 6421                <1>
   205 000137B9 0D0A00              <1>                 db 0Dh, 0Ah, 0
   206                              <1> 
   207                              <1> Msg_File_Not_Found:
   208 000137BC 46696C65206E6F7420- <1>                 db "File not found!"
   208 000137C5 666F756E6421        <1>
   209 000137CB 0D0A00              <1>                 db 0Dh, 0Ah, 0
   210                              <1> 
   211                              <1> Msg_File_Directory_Not_Found:
   212 000137CE 46696C65206F722064- <1>                 db "File or directory not found!"
   212 000137D7 69726563746F727920- <1>
   212 000137E0 6E6F7420666F756E64- <1>
   212 000137E9 21                  <1>
   213 000137EA 0D0A00              <1>                 db 0Dh, 0Ah, 0
   214                              <1> 
   215                              <1> Msg_LongName_Not_Found:
   216 000137ED 4C6F6E67206E616D65- <1>                 db "Long name not found!"
   216 000137F6 206E6F7420666F756E- <1>
   216 000137FF 6421                <1>
   217 00013801 0D0A00              <1>                 db 0Dh, 0Ah, 0
   218                              <1> 
   219                              <1> beep_Insufficient_Memory: ; 20/02/2017
   220 00013804 0D0A                <1> 		db 0Dh, 0Ah
   221 00013806 07                  <1> 		db 07h
   222                              <1> Msg_Insufficient_Memory:
   223 00013807 496E73756666696369- <1>                 db "Insufficient memory!"
   223 00013810 656E74206D656D6F72- <1>
   223 00013819 7921                <1>
   224 0001381B 0D0A00              <1>                 db 0Dh, 0Ah, 0
   225                              <1> 
   226                              <1> Msg_Error_Code:
   227 0001381E 436F6D6D616E642066- <1>                 db 'Command failed! Error code : '
   227 00013827 61696C656421204572- <1>
   227 00013830 726F7220636F646520- <1>
   227 00013839 3A20                <1>
   228 0001383B 303068              <1> error_code_hex: db '00h'
   229 0001383E 0A0A00              <1>                 db 0Ah, 0Ah, 0
   230                              <1> 
   231 00013841 90                  <1> align 2
   232                              <1> 
   233                              <1> ; 10/02/2016
   234                              <1> ; DIR.ASM - 09/10/2011
   235                              <1> 
   236 00013842 3C4449523E20202020- <1> Type_Dir:       db '<DIR>     ' ; 10 bytes
   236 0001384B 20                  <1>
   237                              <1> 
   238                              <1> File_Name:
   239 0001384C 20<rep Ch>          <1>                 times 12 db 20h
   240 00013858 20                  <1> 		db 20h
   241                              <1> Dir_Or_FileSize:
   242 00013859 20<rep Ah>          <1>                 times 10 db 20h
   243 00013863 20                  <1> 		db 20h
   244                              <1> File_Attribute:
   245 00013864 20202020            <1> 		dd 20202020h
   246 00013868 20                  <1> 		db 20h
   247                              <1> File_Day:
   248 00013869 3030                <1>                 db '0','0'
   249 0001386B 2F                  <1> 		db '/'
   250                              <1> File_Month:
   251 0001386C 3030                <1>                 db '0','0'
   252 0001386E 2F                  <1> 		db '/'
   253                              <1> File_Year:
   254 0001386F 30303030            <1>                 db '0','0','0','0'
   255 00013873 20                  <1> 		db 20h
   256                              <1> File_Hour:
   257 00013874 3030                <1>                 db '0','0'
   258 00013876 3A                  <1> 		db ':'
   259                              <1> File_Minute:
   260 00013877 3030                <1>                 db '0','0'
   261 00013879 00                  <1> 		db 0
   262                              <1> 
   263                              <1> Decimal_File_Count_Header:
   264 0001387A 0D0A                <1> 		db 0Dh, 0Ah
   265                              <1> Decimal_File_Count:
   266 0001387C 00<rep 6h>          <1> 		times 6 db 0
   267                              <1> 
   268 00013882 2066696C6528732920- <1> str_files:	db " file(s) & "
   268 0001388B 2620                <1>
   269                              <1> Decimal_Dir_Count: 
   270 0001388D 00<rep 6h>          <1> 		times 6 db 0
   271                              <1> str_dirs:       
   272 00013893 206469726563746F72- <1> 		db " directory(s) "
   272 0001389C 7928732920          <1>
   273 000138A1 0D0A00              <1> 		db 0Dh, 0Ah, 0
   274                              <1> 
   275 000138A4 206279746528732920- <1> str_bytes:	db " byte(s) in file(s)"
   275 000138AD 696E2066696C652873- <1>
   275 000138B6 29                  <1>
   276 000138B7 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 000138BA 496E76616C69642066- <1>                 db "Invalid file or directory name characters!"
   281 000138C3 696C65206F72206469- <1>
   281 000138CC 726563746F7279206E- <1>
   281 000138D5 616D65206368617261- <1>
   281 000138DE 637465727321        <1>
   282 000138E4 0D0A00              <1>         	db 0Dh, 0Ah, 0
   283                              <1> ; 21/02/2016
   284 000138E7 46696C65206F722064- <1> Msg_Name_Exists: db "File or directory name exists!"
   284 000138F0 69726563746F727920- <1>
   284 000138F9 6E616D652065786973- <1>
   284 00013902 747321              <1>
   285 00013905 0D0A00              <1>                 db 0Dh, 0Ah, 0
   286                              <1> Msg_DoYouWantMkdir:
   287 00013908 446F20796F75207761- <1>                 db "Do you want to make directory ", 0
   287 00013911 6E7420746F206D616B- <1>
   287 0001391A 65206469726563746F- <1>
   287 00013923 72792000            <1>
   288 00013927 2028592F4E29203F20- <1> Msg_YesNo:      db " (Y/N) ? ", 0  
   288 00013930 00                  <1>
   289 00013931 000D0A00            <1> Y_N_nextline:	db 0, 0Dh, 0Ah, 0 
   290 00013935 4F4B2E0D0A00        <1> Msg_OK:		db "OK.", 0Dh, 0Ah, 0
   291                              <1> 
   292                              <1> ; 27/02/2016
   293                              <1> Msg_DoYouWantRmDir:
   294 0001393B 446F20796F75207761- <1>                 db "Do you want to delete directory ", 0
   294 00013944 6E7420746F2064656C- <1>
   294 0001394D 657465206469726563- <1>
   294 00013956 746F72792000        <1>
   295                              <1> Msg_Dir_Not_Empty:
   296 0001395C 4469726563746F7279- <1>                 db "Directory not empty!"
   296 00013965 206E6F7420656D7074- <1>
   296 0001396E 7921                <1>
   297 00013970 0D0A00              <1>                 db 0Dh, 0Ah, 0
   298                              <1> 
   299                              <1> Msg_DoYouWantDelete:
   300 00013973 446F20796F75207761- <1>                 db "Do you want to delete file ",0
   300 0001397C 6E7420746F2064656C- <1>
   300 00013985 6574652066696C6520- <1>
   300 0001398E 00                  <1>
   301                              <1> 
   302 0001398F 44656C657465642E2E- <1> Msg_Deleted:    db "Deleted...", 0Dh, 0Ah, 0
   302 00013998 2E0D0A00            <1>
   303                              <1> 
   304                              <1> Msg_Permission_Denied:
   305 0001399C 07                  <1>                 db 7
   306 0001399D 5065726D697373696F- <1>                 db "Permission denied!", 0Dh, 0Ah, 0
   306 000139A6 6E2064656E69656421- <1>
   306 000139AF 0D0A00              <1>
   307                              <1> 
   308                              <1> ; 04/03/2016
   309 000139B2 4E657720            <1> Msg_New:        db "New "
   310 000139B6 00                  <1>                 db 0
   311                              <1> Str_Attributes:
   312 000139B7 417474726962757465- <1>                 db "Attributes : "
   312 000139C0 73203A20            <1>
   313 000139C4 4E4F524D414C        <1> Attr_Chars:     db "NORMAL"
   314 000139CA 00                  <1>                 db 0
   315                              <1> 
   316                              <1> ; 06/03/2016
   317                              <1> ; CMD_INTR.ASM - 16/11/2010 
   318                              <1> Msg_DoYouWantRename:
   319 000139CB 446F20796F75207761- <1>                 db "Do you want to rename ", 0
   319 000139D4 6E7420746F2072656E- <1>
   319 000139DD 616D652000          <1>
   320 000139E2 66696C652000        <1> Rename_File:    db "file ", 0
   321 000139E8 6469726563746F7279- <1> Rename_Directory: db "directory ", 0
   321 000139F1 2000                <1>
   322 000139F3 00<rep Dh>          <1> Rename_OldName: times 13 db 0
   323 00013A00 20617320            <1> Msg_File_rename_as: db " as "
   324 00013A04 00<rep Dh>          <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 00013A11 4E6F742073616D6520- <1>                 db "Not same drive!" 
   329 00013A1A 647269766521        <1>
   330 00013A20 0D0A00              <1>                 db 0Dh, 0Ah, 0 
   331                              <1> 
   332                              <1> Msg_DoYouWantMoveFile:
   333 00013A23 446F20796F75207761- <1>                 db "Do you want to move file", 0
   333 00013A2C 6E7420746F206D6F76- <1>
   333 00013A35 652066696C6500      <1>
   334                              <1> 
   335                              <1> msg_insufficient_disk_space:
   336 00013A3C 496E73756666696369- <1>                 db "Insufficient disk space!" 
   336 00013A45 656E74206469736B20- <1>
   336 00013A4E 737061636521        <1>
   337 00013A54 0D0A00              <1>                 db 0Dh, 0Ah, 0
   338                              <1> 
   339                              <1> ; 01/08/2010
   340                              <1> msg_source_file: 
   341 00013A57 0D0A536F7572636520- <1> 		db 0Dh, 0Ah, "Source file name      :   "
   341 00013A60 66696C65206E616D65- <1>
   341 00013A69 2020202020203A2020- <1>
   341 00013A72 20                  <1>
   342                              <1> msg_source_file_drv: 
   343 00013A73 203A00              <1> 		db " :", 0
   344                              <1> msg_destination_file: 
   345 00013A76 0D0A44657374696E61- <1> 		db 0Dh, 0Ah, "Destination file name :   "
   345 00013A7F 74696F6E2066696C65- <1>
   345 00013A88 206E616D65203A2020- <1>
   345 00013A91 20                  <1>
   346                              <1> msg_destination_file_drv: 
   347 00013A92 203A00              <1> 		db " :", 0
   348                              <1> msg_copy_nextline: 
   349 00013A95 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 00013A98 446F20796F75207761- <1>                 db "Do you want to overwrite file ",0
   355 00013AA1 6E7420746F206F7665- <1>
   355 00013AAA 727772697465206669- <1>
   355 00013AB3 6C652000            <1>
   356                              <1>   
   357                              <1> Msg_DoYouWantCopyFile:
   358 00013AB7 446F20796F75207761- <1>                 db "Do you want to copy file",0
   358 00013AC0 6E7420746F20636F70- <1>
   358 00013AC9 792066696C6500      <1>
   359                              <1> 
   360                              <1> Msg_read_file_error_before_EOF:
   361 00013AD0 46696C652072656164- <1> 		db "File reading error! (before EOF)"
   361 00013AD9 696E67206572726F72- <1>
   361 00013AE2 2120286265666F7265- <1>
   361 00013AEB 20454F4629          <1>
   362 00013AF0 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 00013AF3 52656164696E672E2E- <1> 		db "Reading... ", 0
   367 00013AFC 2E2000              <1>
   368                              <1> msg_writing:
   369 00013AFF 57726974696E672E2E- <1> 		db "Writing... ", 0
   369 00013B08 2E2000              <1>
   370                              <1> percentagestr:
   371 00013B0B 2020202500          <1> 		db "   %", 0  ; "  0%" .. "100%"
   372                              <1> ; 11/04/2016
   373                              <1> Msg_No_Set_Space:
   374 00013B10 496E73756666696369- <1>                 db "Insufficient environment space!"
   374 00013B19 656E7420656E766972- <1>
   374 00013B22 6F6E6D656E74207370- <1>
   374 00013B2B 61636521            <1>
   375 00013B2F 0D0A00              <1>                 db 0Dh, 0Ah, 0
   376                              <1> ; 18/04/2016
   377                              <1> isc_msg:	
   378 00013B32 0D0A                <1> 		db 0Dh, 0Ah
   379 00013B34 494E56414C49442053- <1> 		db "INVALID SYSTEM CALL", 0
   379 00013B3D 595354454D2043414C- <1>
   379 00013B46 4C00                <1>
   380                              <1> usi_msg:
   381 00013B48 0D0A                <1> 		db 0Dh, 0Ah
   382 00013B4A 554E444546494E4544- <1> 		db "UNDEFINED SOFTWARE INTERRUPT", 0
   382 00013B53 20534F465457415245- <1>
   382 00013B5C 20494E544552525550- <1>
   382 00013B65 5400                <1>
   383                              <1> ifc_msg:
   384 00013B67 0D0A                <1> 		db 0Dh, 0Ah
   385 00013B69 494E56414C49442046- <1> 		db "INVALID FUNCTION CALL"
   385 00013B72 554E4354494F4E2043- <1>
   385 00013B7B 414C4C              <1>
   386                              <1> inv_msg_for_trdos_v2:
   387 00013B7E 20                  <1> 		db 20h
   388 00013B7F 666F72205452444F53- <1> 		db "for TRDOS v2!"
   388 00013B88 20763221            <1>
   389 00013B8C 07                  <1> 		db 07h
   390 00013B8D 0D0A                <1> 		db 0Dh, 0Ah
   391 00013B8F 0D0A                <1> 		db 0Dh, 0Ah
   392 00013B91 494E5420            <1> 		db "INT "
   393 00013B95 303068              <1> int_num_str:	db "00h"
   394 00013B98 0D0A                <1> 		db 0Dh, 0Ah
   395 00013B9A 454158203A20        <1> 		db "EAX : "
   396 00013BA0 303030303030303068- <1> eax_str:	db "00000000h", 0Dh, 0Ah
   396 00013BA9 0D0A                <1>
   397 00013BAB 454950203A20        <1> 		db "EIP : "
   398 00013BB1 303030303030303068- <1> eip_str:	db "00000000h", 0Dh, 0Ah, 0
   398 00013BBA 0D0A00              <1>
   399                              <1> 
   400                              <1> ; 17/04/2021
   401                              <1> ; ('KDEV' device parameters are disabled as temporary)
   402                              <1> 
   403                              <1> ; 07/10/2016
   404                              <1> ; Device names & parameters (for kernel devices)
   405                              <1> 
   406 00013BBD 90                  <1> align 2
   407                              <1> ;KDEV_NAME:
   408                              <1> ;		db 'TTY',0,0,0,0,0 ; 1
   409                              <1> ;		db 'MEM',0,0,0,0,0 ; 2
   410                              <1> ;		db 'FD0',0,0,0,0,0 ; 3
   411                              <1> ;		db 'FD1',0,0,0,0,0 ; 4
   412                              <1> ;		db 'HD0',0,0,0,0,0 ; 5
   413                              <1> ;		db 'HD1',0,0,0,0,0 ; 6
   414                              <1> ;		db 'HD2',0,0,0,0,0 ; 7
   415                              <1> ;		db 'HD3',0,0,0,0,0 ; 8
   416                              <1> ;		db 'LPT',0,0,0,0,0 ; 9
   417                              <1> ;		db 'TTY0',0,0,0,0 ; 10
   418                              <1> ;		db 'TTY1',0,0,0,0 ; 11
   419                              <1> ;		db 'TTY2',0,0,0,0 ; 12
   420                              <1> ;		db 'TTY3',0,0,0,0 ; 13
   421                              <1> ;		db 'TTY4',0,0,0,0 ; 14
   422                              <1> ;		db 'TTY5',0,0,0,0 ; 15
   423                              <1> ;		db 'TTY6',0,0,0,0 ; 16
   424                              <1> ;		db 'TTY7',0,0,0,0 ; 17
   425                              <1> ;		db 'TTY8',0,0,0,0 ; 18
   426                              <1> ;		db 'TTY9',0,0,0,0 ; 19
   427                              <1> ;		db 'COM1',0,0,0,0 ; 18
   428                              <1> ;		db 'COM2',0,0,0,0 ; 19
   429                              <1> ;		;db 'CONSOLE',0	  ; 1
   430                              <1> ;		;db 'PRINTER',0   ; 9
   431                              <1> ;		;db 'CDROM'	  ; 20
   432                              <1> ;		;db 'CDROM0'	  ; 20
   433                              <1> ;		;db 'CDROM1'	  ; 21		
   434                              <1> ;		;db 'DVD'	  ; 22
   435                              <1> ;		;db 'DVD0'	  ; 22
   436                              <1> ;		;db 'DVD1'	  ; 23		
   437                              <1> ;		;db 'USB'	  ; 24
   438                              <1> ;		;db 'USB0'	  ; 24
   439                              <1> ;		;db 'USB1'	  ; 25
   440                              <1> ;		;db 'USB2'	  ; 26
   441                              <1> ;		;db 'USB3'        ; 27
   442                              <1> ;		;db 'KEYBOARD'	  ; 1	
   443                              <1> ;		;db 'MOUSE'	  ; 28
   444                              <1> ;		;db 'SOUND'	  ; 29
   445                              <1> ;		;db 'VGA',0,0,0,0 ; 30
   446                              <1> ;		;db 'CGA',0,0,0,0 ; 31
   447                              <1> ;		;db 'AUDIO',0,0,0 ; 29
   448                              <1> ;		;db 'VIDEO',0,0,0 ; 32
   449                              <1> ;		;db 'MUSIC',0,0,0 ; 33
   450                              <1> ;		;db 'ETHERNET'	  ; 34 		
   451                              <1> ;		;db 'SD0',0,0,0,0,0 ; 35
   452                              <1> ;		;db 'SD1',0,0,0,0,0 ; 36
   453                              <1> ;		;db 'SD2',0,0,0,0,0 ; 37
   454                              <1> ;		;db 'SD3',0,0,0,0,0 ; 38
   455                              <1> ;		;db 'SATA0'	  ; 35
   456                              <1> ;		;db 'SATA1'	  ; 36
   457                              <1> ;		;db 'SATA2'        ; 37
   458                              <1> ;		;db 'SATA3'        ; 38
   459                              <1> ;		;db 'PATA0',0,0,0  ; 5
   460                              <1> ;		;db 'PATA1',0,0,0  ; 6
   461                              <1> ;		;db 'PATA2',0,0,0  ; 7
   462                              <1> ;		;db 'PATA3',0,0,0  ; 8
   463                              <1> ;		;db 'WIRELESS'	  ; 39
   464                              <1> ;		;db 'HDMI',0,0,0,0 ; 40
   465                              <1> ;		db 'NULL',0,0,0,0 ; 0
   466                              <1> 
   467                              <1> ;NumOfKernelDevNames equ ($-KDEV_NAME) / 8 ; 20 (07/10/2016)
   468                              <1> 
   469                              <1> ;KDEV_NUMBER:
   470                              <1> ;		db 1,2,3,4,5,6,7,8,9
   471                              <1> ;		db 10,11,12,13,14,15,16,17,18,19
   472                              <1> ;		db 18,19,0
   473                              <1> 
   474                              <1> ;NumOfKernelDevices equ $ - KDEV_NUMBER
   475                              <1> 
   476                              <1> ;KDEV_OADDR:
   477                              <1> ;		dd otty ;tty  ; 1
   478                              <1> ;		dd sret ;mem  ; 2
   479                              <1> ; 		dd sret ;fd0  ; 3
   480                              <1> ; 		dd sret ;fd1  ; 4
   481                              <1> ;		dd sret ;hd0  ; 5
   482                              <1> ;		dd sret ;hd1  ; 6
   483                              <1> ;		dd sret ;hd2  ; 7
   484                              <1> ;		dd sret ;hd3  ; 8
   485                              <1> ;		dd sret ;lpt  ; 9
   486                              <1> ;		dd ocvt ;tty0 ; 10
   487                              <1> ;		dd ocvt ;tty1 ; 11
   488                              <1> ;		dd ocvt ;tty2 ; 12
   489                              <1> ;		dd ocvt ;tty3 ; 13
   490                              <1> ;		dd ocvt ;tty4 ; 14
   491                              <1> ;		dd ocvt ;tty5 ; 15
   492                              <1> ;		dd ocvt ;tty6 ; 16
   493                              <1> ;		dd ocvt ;tty7 ; 17
   494                              <1> ;		dd ocvt ;tty8 ; 18
   495                              <1> ;		dd ocvt ;tty9 ; 19
   496                              <1> ;		;dd ocvt ;com1 ; 18
   497                              <1> ;		;dd ocvt ;com2 ; 19
   498                              <1> ;		dd sret ;null ; 20  
   499                              <1> ;KDEV_CADDR:
   500                              <1> ;		dd ctty ;tty  ; 1
   501                              <1> ;		dd cret ;mem  ; 2
   502                              <1> ; 		dd cret ;fd0  ; 3
   503                              <1> ; 		dd cret ;fd1  ; 4
   504                              <1> ;		dd cret ;hd0  ; 5
   505                              <1> ;		dd cret ;hd1  ; 6
   506                              <1> ; 		dd cret ;hd2  ; 7
   507                              <1> ;		dd cret ;hd3  ; 8
   508                              <1> ; 		dd cret ;lpt  ; 9
   509                              <1> ;		dd ocvt ;tty0 ; 10
   510                              <1> ;		dd ccvt ;tty1 ; 11
   511                              <1> ;		dd ccvt ;tty2 ; 12
   512                              <1> ; 		dd ccvt ;tty3 ; 13
   513                              <1> ; 		dd ccvt ;tty4 ; 14
   514                              <1> ; 		dd ccvt ;tty5 ; 15
   515                              <1> ; 		dd ccvt ;tty6 ; 16
   516                              <1> ; 		dd ccvt ;tty7 ; 17
   517                              <1> ; 		dd ccvt ;tty8 ; 18
   518                              <1> ; 		dd ccvt ;tty9 ; 19
   519                              <1> ; 		;dd ccvt ;com1 ; 18
   520                              <1> ; 		;dd ccvt ;com2 ; 19
   521                              <1> ;		dd cret ;null ; 20
   522                              <1> ;
   523                              <1> ;KDEV_RADDR:
   524                              <1> ;		dd rtty ;tty  ; 1
   525                              <1> ;		dd rmem ;mem  ; 2
   526                              <1> ;		dd rfd  ;fd0  ; 3
   527                              <1> ; 		dd rfd  ;fd1  ; 4
   528                              <1> ; 		dd rhd  ;hd0  ; 5
   529                              <1> ; 		dd rhd  ;hd1  ; 6
   530                              <1> ; 		dd rhd  ;hd2  ; 7
   531                              <1> ; 		dd rhd  ;hd3  ; 8
   532                              <1> ; 		dd rlpt ;lpt  ; 9
   533                              <1> ; 		dd rcvt ;tty0 ; 10
   534                              <1> ;		dd rcvt ;tty1 ; 11
   535                              <1> ; 		dd rcvt ;tty2 ; 12
   536                              <1> ; 		dd rcvt ;tty3 ; 13
   537                              <1> ; 		dd rcvt ;tty4 ; 14
   538                              <1> ; 		dd rcvt ;tty5 ; 15
   539                              <1> ; 		dd rcvt ;tty6 ; 16
   540                              <1> ; 		dd rcvt ;tty7 ; 17
   541                              <1> ; 		dd rcvt ;tty8 ; 18
   542                              <1> ; 		dd rcvt ;tty9 ; 19
   543                              <1> ; 		;dd rcvt ;com1 ; 18
   544                              <1> ; 		;dd rcvt ;com2 ; 19
   545                              <1> ;		dd rnull ;null ; 20  
   546                              <1> ;KDEV_WADDR:
   547                              <1> ;		dd wtty ;tty  ; 1
   548                              <1> ;		dd wmem ;mem  ; 2
   549                              <1> ;		dd wfd  ;fd0  ; 3
   550                              <1> ; 		dd wfd  ;fd1  ; 4
   551                              <1> ; 		dd whd  ;hd0  ; 5
   552                              <1> ; 		dd whd  ;hd1  ; 6
   553                              <1> ; 		dd whd  ;hd2  ; 7
   554                              <1> ; 		dd whd  ;hd3  ; 8
   555                              <1> ; 		dd wlpt ;lpt  ; 9
   556                              <1> ; 		dd xmtt ;tty0 ; 10
   557                              <1> ;		dd xmtt ;tty1 ; 11
   558                              <1> ; 		dd xmtt ;tty2 ; 12
   559                              <1> ; 		dd xmtt ;tty3 ; 13
   560                              <1> ; 		dd xmtt ;tty4 ; 14
   561                              <1> ; 		dd xmtt ;tty5 ; 15
   562                              <1> ; 		dd xmtt ;tty6 ; 16
   563                              <1> ; 		dd xmtt ;tty7 ; 17
   564                              <1> ; 		dd xmtt ;tty8 ; 18
   565                              <1> ; 		dd xmtt ;tty9 ; 19
   566                              <1> ; 		;dd xmtt ;com1 ; 18
   567                              <1> ; 		;dd xmtt ;com2 ; 19
   568                              <1> ;		dd wnull ;null ; 20  
   569                              <1> 
   570                              <1> ; DEV_ACCESS bits:
   571                              <1> 	; bit 0 = accessable by normal users
   572                              <1> 	; bit 1 = read access permission
   573                              <1> 	; bit 2 = write access permission
   574                              <1> 	; bit 3 = IOCTL permission to users
   575                              <1> 	; bit 4 = block device if it is set
   576                              <1> 	; bit 5 = 16 bit or 1024 byte data
   577                              <1> 	; bit 6 = 32 bit or 2048 byte data
   578                              <1> 	; bit 7 = installable device driver	
   579                              <1> 
   580                              <1> ;KDEV_ACCESS: ; 08/10/2016
   581                              <1> ;		db  00000111b	; tty, 1
   582                              <1> ;		db  00000111b	; mem, 2	
   583                              <1> ;		db  10001111b	; fd0, 3	
   584                              <1> ;		db  10001111b	; fd1, 4
   585                              <1> ;		db  10001111b	; hd0, 5
   586                              <1> ;		db  10001111b	; hd1, 6
   587                              <1> ;		db  10001111b	; hd2, 7
   588                              <1> ;		db  10001111b	; hd3, 8
   589                              <1> ;		db  00000111b   ; lpt, 9
   590                              <1> ;		db  00000111b	; tty0, 10
   591                              <1> ;		db  00000111b	; tty1, 11
   592                              <1> ;		db  00000111b	; tty2, 12
   593                              <1> ;		db  00000111b	; tty3, 13
   594                              <1> ;		db  00000111b	; tty4, 14
   595                              <1> ;		db  00000111b	; tty5, 15
   596                              <1> ;		db  00000111b	; tty6, 16
   597                              <1> ;		db  00000111b	; tty7, 17
   598                              <1> ;		db  00000111b	; tty8, 18
   599                              <1> ;		db  00000111b	; tty9, 19
   600                              <1> ;		;db 00000111b	; com1, 18
   601                              <1> ;		;db 00000111b	; com2, 19
   602                              <1> ;		db  00000000b   ; null, 0
   603                              <1> 
   604                              <1> ; 07/10/2016
   605                              <1> ;NumOfInstallableDevices equ 8
   606                              <1> ;NUMIDEV	equ NumOfInstallableDevices ; 8
   607                              <1> ;NUMOFDEVICES	equ NumOfKernelDevices + NumOfInstallableDevices
   608                              <1> 
   609                              <1> ; 26/02/2017
   610                              <1> ; IRQ Callback (& Signal Response Byte) service availibity
   611                              <1> ; 'syscalbac'
   612                              <1> ; ***************************************************
   613                              <1> ; IRQ 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
   614                              <1> ; --- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
   615                              <1> ; --- 00 00 00 01 02 03 00 04 00 05 06 07 08 09 00 00
   616                              <1> ; ***************************************************
   617                              <1> IRQenum:
   618 00013BBE 000000010203000400- <1> 	db  0,0,0,1,2,3,0,4,0,5,6,7,8,9,0,0
   618 00013BC7 05060708090000      <1>
   619                              <1> 
   620                              <1> ; 28/08/2017
   621                              <1> ; 20/08/2017
   622                              <1> ; DMA Registers (for 'sysdma')
   623                              <1> ; 02/07/2017 (sb16mod.s)
   624 00013BCE 00020406C0C4C8CC    <1> dma_adr:	db 0,2,4,6,0C0h,0C4h,0C8h,0CCh
   625 00013BD6 01030507C2C6CACE    <1> dma_cnt:	db 1,3,5,7,0C2h,0C6h,0CAh,0CEh
   626 00013BDE 878381828F8B898A    <1> dma_page:	db 87h,83h,81h,82h,8Fh,8Bh,89h,8Ah ; 03/08/2017
   627 00013BE6 0A0A0A0AD4D4D4D4    <1> dma_mask:	db 0Ah,0Ah,0Ah,0Ah,0D4h,0D4h,0D4h,0D4h
   628 00013BEE 0B0B0B0BD6D6D6D6    <1> dma_mod:	db 0Bh,0Bh,0Bh,0Bh,0D6h,0D6h,0D6h,0D6h
   629 00013BF6 0C0C0C0CD8D8D8D8    <1> dma_flip:	db 0Ch,0Ch,0Ch,0Ch,0D8h,0D8h,0D8h,0D8h	
  3439                                  
  3440                                  ; 27/08/2014
  3441                                  scr_row:
  3442 00013BFE E0810B00                	dd 0B8000h + 0A0h + 0A0h + 0A0h ; Row 3
  3443                                  scr_col:
  3444 00013C02 00000000                	dd 0
  3445                                  
  3446 00013C06 90<rep 2h>              Align 4
  3447                                  	; 15/04/2016
  3448                                  	; TRDOS 386 (TRDOS v2.0)
  3449                                  
  3450                                  	; 21/08/2014
  3451                                  ilist:
  3452                                  	;times 	32 dd cpu_except ; INT 0 to INT 1Fh
  3453                                  	;
  3454                                  	; Exception list
  3455                                  	; 25/08/2014	
  3456 00013C08 [1E0C0000]              	dd	exc0	; 0h,  Divide-by-zero Error
  3457 00013C0C [250C0000]              	dd	exc1	
  3458 00013C10 [2C0C0000]              	dd 	exc2	
  3459 00013C14 [330C0000]              	dd	exc3	
  3460 00013C18 [370C0000]              	dd	exc4	
  3461 00013C1C [3B0C0000]              	dd	exc5	
  3462 00013C20 [3F0C0000]              	dd 	exc6	; 06h,  Invalid Opcode
  3463 00013C24 [430C0000]              	dd	exc7	
  3464 00013C28 [470C0000]              	dd	exc8	
  3465 00013C2C [4B0C0000]              	dd	exc9	
  3466 00013C30 [4F0C0000]              	dd 	exc10	
  3467 00013C34 [530C0000]              	dd	exc11
  3468 00013C38 [570C0000]              	dd	exc12
  3469 00013C3C [5B0C0000]              	dd	exc13	; 0Dh, General Protection Fault
  3470 00013C40 [5F0C0000]              	dd 	exc14	; 0Eh, Page Fault
  3471 00013C44 [630C0000]              	dd	exc15
  3472 00013C48 [670C0000]              	dd	exc16
  3473 00013C4C [6B0C0000]              	dd	exc17
  3474 00013C50 [6F0C0000]              	dd 	exc18
  3475 00013C54 [730C0000]              	dd	exc19
  3476 00013C58 [770C0000]              	dd 	exc20
  3477 00013C5C [7B0C0000]              	dd	exc21
  3478 00013C60 [7F0C0000]              	dd	exc22
  3479 00013C64 [830C0000]              	dd	exc23
  3480 00013C68 [870C0000]              	dd 	exc24
  3481 00013C6C [8B0C0000]              	dd	exc25
  3482 00013C70 [8F0C0000]              	dd	exc26
  3483 00013C74 [930C0000]              	dd	exc27
  3484 00013C78 [970C0000]              	dd 	exc28
  3485 00013C7C [9B0C0000]              	dd	exc29
  3486 00013C80 [9F0C0000]              	dd 	exc30
  3487 00013C84 [A30C0000]              	dd	exc31
  3488                                  IRQ_list: ; 28/02/2017 ('syscalbac')
  3489                                  	; Interrupt list
  3490 00013C88 [88090000]              	dd	timer_int	; INT 20h
  3491                                  		;dd	irq0	
  3492 00013C8C [ED100000]              	dd	kb_int		; 24/01/2016
  3493                                  		;dd	irq1
  3494 00013C90 [740B0000]              	dd	irq2
  3495                                  		; COM2 int
  3496 00013C94 [780B0000]              	dd	irq3
  3497                                  		; COM1 int
  3498 00013C98 [830B0000]              	dd	irq4
  3499 00013C9C [8E0B0000]              	dd	irq5
  3500                                  ;DISKETTE_INT: ;06/02/2015
  3501 00013CA0 [5A4E0000]              	dd	fdc_int		; 16/02/2015, IRQ 6 handler	
  3502                                  		;dd	irq6
  3503                                  ; Default IRQ 7 handler against spurious IRQs (from master PIC)
  3504                                  ; 25/02/2015 (source: http://wiki.osdev.org/8259_PIC)
  3505 00013CA4 [FA0E0000]              	dd	default_irq7	; 25/02/2015
  3506                                  		;dd	irq7
  3507                                  ; Real Time Clock Interrupt
  3508 00013CA8 [FC0A0000]              	dd	rtc_int		; 23/02/2015, IRQ 8 handler
  3509                                  		;dd	irq8	; INT 28h
  3510 00013CAC [9E0B0000]              	dd	irq9
  3511 00013CB0 [A20B0000]              	dd	irq10
  3512 00013CB4 [A60B0000]              	dd	irq11
  3513 00013CB8 [AA0B0000]              	dd	irq12
  3514 00013CBC [AE0B0000]              	dd	irq13
  3515                                  ;HDISK_INT1:  ;06/02/2015 	
  3516 00013CC0 [99570000]              	dd	hdc1_int 	; 21/02/2015, IRQ 14 handler		
  3517                                  		;dd	irq14
  3518                                  ;HDISK_INT2:  ;06/02/2015
  3519 00013CC4 [BC570000]              	dd	hdc2_int 	; 21/02/2015, IRQ 15 handler		
  3520                                  		;dd	irq15	; INT 2Fh
  3521                                  		; 14/08/2015
  3522                                  	;dd	sysent		; INT 30h (system calls)
  3523                                  
  3524                                  	; 15/04/2016
  3525                                  	; TRDOS 386(TRDOS v2.0) Software Interrupts
  3526                                  
  3527 00013CC8 [253D0100]              	dd	int30h		; Reserved for
  3528                                  				; !!! Retro UNIX (RUNIX) !!!
  3529                                  				; !!! SINGLIX !!! System Calls
  3530 00013CCC [7C170000]              	dd	int31h		; Video BIOS (IBM PC/AT, Int 10h)
  3531 00013CD0 [490F0000]              	dd	int32h		; Keyboard Functions (IBM PC/AT, Int 16h)
  3532 00013CD4 [FC4E0000]              	dd	int33h		; DISK I/O (IBM PC/AT, Int 13h)
  3533 00013CD8 [A9210100]              	dd	int34h		; #IOCTL# (I/O port access support for ring 3)
  3534 00013CDC [9F620000]              	dd	int35h		; Time/Date Functions (IBM PC/AT, Int 1Ah)
  3535 00013CE0 [AE0D0000]              	dd	ignore_int	; INT 36h : Timer Functions	
  3536 00013CE4 [AE0D0000]              	dd	ignore_int	; INT 37h	
  3537 00013CE8 [AE0D0000]              	dd	ignore_int	; INT 38h
  3538 00013CEC [AE0D0000]              	dd	ignore_int	; INT 39h
  3539 00013CF0 [AE0D0000]              	dd	ignore_int	; INT 3Ah	
  3540 00013CF4 [AE0D0000]              	dd	ignore_int	; INT 3Bh
  3541 00013CF8 [AE0D0000]              	dd	ignore_int	; INT 3Ch
  3542 00013CFC [AE0D0000]              	dd	ignore_int	; INT 3Dh	
  3543 00013D00 [AE0D0000]              	dd	ignore_int	; INT 3Eh
  3544 00013D04 [AE0D0000]              	dd	ignore_int	; INT 3Fh
  3545 00013D08 [9CCC0000]              	dd	sysent		; INT 40h : !!! TRDOS 386 System Calls !!!
  3546                                  	;dd	ignore_int
  3547 00013D0C 00000000                	dd	0
  3548                                  
  3549                                  ; 20/08/2014
  3550                                    ; /* This is the default interrupt "handler" :-) */ 
  3551                                    ; Linux v0.12 (head.s)
  3552                                  int_msg:
  3553 00013D10 556E6B6E6F776E2069-     	db "Unknown interrupt ! ", 0
  3553 00013D19 6E7465727275707420-
  3553 00013D22 212000             
  3554                                  
  3555                                  ; 15/04/2016
  3556                                  ; TRDOS 386 (TRDOS v2.0)
  3557                                  
  3558                                  ; 29/04/2016
  3559                                  int30h:
  3560                                  trdos_isc_routine:
  3561                                  	; 02/05/2016
  3562                                  	; 01/05/2016
  3563                                  	; 29/04/2016
  3564                                  	; 18/04/2016
  3565                                  	; 15/04/2016 (TRDOS 386 = TRDOS v2.0)
  3566                                  	; 17/04/2011 (TRDOS v1.0, 'IFC.ASM')
  3567                                  	; 03/02/2011 ('trdos_ifc_routine')
  3568                                  	;
  3569 00013D25 8B1C24                  	mov	ebx, [esp] ; EIP (next)
  3570 00013D28 83EB02                  	sub	ebx, 2 ; EIP (CD ##h)
  3571                                  
  3572 00013D2B 89C1                    	mov	ecx, eax
  3573 00013D2D 8A4301                  	mov	al, [ebx+1] ; CDh ##h
  3574                                  
  3575 00013D30 66BA1000                	mov	dx, KDATA
  3576 00013D34 8EDA                    	mov	ds, dx
  3577 00013D36 8EC2                    	mov	es, dx
  3578                                  
  3579 00013D38 FC                      	cld
  3580 00013D39 8B15[C07C0100]          	mov	edx, [k_page_dir]
  3581 00013D3F 0F22DA                  	mov	cr3, edx
  3582                                  
  3583 00013D42 E82E04FFFF              	call	bytetohex
  3584 00013D47 66A3[953B0100]          	mov	[int_num_str], ax
  3585                                  
  3586 00013D4D 89D8                    	mov	eax, ebx ; EIP
  3587 00013D4F E86104FFFF              	call	dwordtohex
  3588 00013D54 8915[B13B0100]          	mov	[eip_str], edx
  3589 00013D5A A3[B53B0100]            	mov	[eip_str+4], eax
  3590                                  
  3591 00013D5F 89C8                    	mov	eax, ecx
  3592 00013D61 E84F04FFFF              	call	dwordtohex
  3593 00013D66 8915[A03B0100]          	mov	[eax_str], edx
  3594 00013D6C A3[A43B0100]            	mov	[eax_str+4], eax 	
  3595                                  
  3596 00013D71 43                      	inc	ebx
  3597 00013D72 8A03                    	mov	al, [ebx] ; Interrupt number
  3598                                  
  3599                                  trdos_isc_handler:
  3600 00013D74 80FE30                  	cmp	dh, 30h ; Retro UNIX, SINGLIX System calls
  3601 00013D77 7507                    	jne	short trdos_usi_handler
  3602 00013D79 BE[323B0100]            	mov	esi, isc_msg
  3603 00013D7E EB05                    	jmp	short loc_write_inv_system_call_msg
  3604                                  
  3605                                  trdos_usi_handler:
  3606 00013D80 BE[483B0100]            	mov	esi, usi_msg
  3607                                  
  3608                                  loc_write_inv_system_call_msg:
  3609 00013D85 E8E02FFFFF              	call	print_msg
  3610                                  	; 29/04/2016
  3611 00013D8A BE[7E3B0100]            	mov	esi, inv_msg_for_trdos_v2
  3612 00013D8F E8D62FFFFF              	call	print_msg
  3613                                  
  3614                                  loc_ifc_terminate_process:
  3615                                  	; u.uno = process number
  3616                                  	; 29/04/2016
  3617                                  
  3618                                  	; 02/05/2016
  3619 00013D94 FE05[68940100]          	inc	byte [sysflg] ; 0FFh -> 0
  3620                                  
  3621 00013D9A B801000000              	mov	eax, 1
  3622 00013D9F E9EE91FFFF              	jmp	sysexit
  3623                                  
  3624                                  ; 07/03/2015
  3625                                  ; Temporary Code
  3626                                  display_disks:
  3627 00013DA4 803D[3C660000]00        	cmp 	byte [fd0_type], 0
  3628 00013DAB 7605                    	jna 	short ddsks1
  3629 00013DAD E87D000000              	call	pdskm
  3630                                  ddsks1:
  3631 00013DB2 803D[3D660000]00        	cmp	byte [fd1_type], 0
  3632 00013DB9 760C                    	jna	short ddsks2
  3633 00013DBB C605[FF3E0100]31        	mov	byte [dskx], '1'
  3634 00013DC2 E868000000              	call	pdskm
  3635                                  ddsks2:
  3636 00013DC7 803D[3E660000]00        	cmp	byte [hd0_type], 0
  3637 00013DCE 7654                    	jna	short ddsk6
  3638 00013DD0 66C705[FD3E0100]68-     	mov	word [dsktype], 'hd'
  3638 00013DD8 64                 
  3639 00013DD9 C605[FF3E0100]30        	mov	byte [dskx], '0'
  3640 00013DE0 E84A000000              	call	pdskm
  3641                                  ddsks3:
  3642 00013DE5 803D[3F660000]00        	cmp	byte [hd1_type], 0
  3643 00013DEC 7636                    	jna	short ddsk6
  3644 00013DEE C605[FF3E0100]31        	mov	byte [dskx], '1'
  3645 00013DF5 E835000000              	call	pdskm
  3646                                  ddsks4:
  3647 00013DFA 803D[40660000]00        	cmp	byte [hd2_type], 0
  3648 00013E01 7621                    	jna	short ddsk6
  3649 00013E03 C605[FF3E0100]32        	mov	byte [dskx], '2'
  3650 00013E0A E820000000              	call	pdskm
  3651                                  ddsks5:
  3652 00013E0F 803D[41660000]00        	cmp	byte [hd3_type], 0
  3653 00013E16 760C                    	jna	short ddsk6
  3654 00013E18 C605[FF3E0100]33        	mov	byte [dskx], '3'
  3655 00013E1F E80B000000              	call	pdskm
  3656                                  ddsk6:
  3657 00013E24 BE[273F0100]            	mov	esi, nextline
  3658 00013E29 E806000000              	call	pdskml
  3659                                  pdskm_ok:
  3660 00013E2E C3                      	retn
  3661                                  pdskm:
  3662 00013E2F BE[FB3E0100]            	mov	esi, dsk_ready_msg
  3663                                  pdskml:	
  3664 00013E34 AC                      	lodsb
  3665 00013E35 08C0                    	or	al, al
  3666 00013E37 74F5                    	jz	short pdskm_ok
  3667 00013E39 56                      	push	esi
  3668                                  	; 13/05/2016
  3669 00013E3A BB07000000                      mov     ebx, 7  ; Black background, 
  3670                                  			; light gray forecolor
  3671                                  			; Video page 0 (bh=0)
  3672 00013E3F E851E4FEFF              	call	_write_tty
  3673 00013E44 5E                      	pop	esi
  3674 00013E45 EBED                    	jmp	short pdskml
  3675                                  
  3676 00013E47 90                      Align 2
  3677                                  	; 21/08/2014
  3678                                  exc_msg:
  3679 00013E48 435055206578636570-     	db "CPU exception ! "
  3679 00013E51 74696F6E202120     
  3680                                  excnstr: 		; 25/08/2014
  3681 00013E58 3F3F68202045495020-     	db "??h", "  EIP : "
  3681 00013E61 3A20               
  3682                                  EIPstr: ; 29/08/2014
  3683 00013E63 00<rep Ch>              	times 12 db 0
  3684                                  
  3685                                  	; 23/02/2015
  3686                                  	; 25/08/2014
  3687                                  ;scounter:
  3688                                  ;	db 5
  3689                                  ;	db 19
  3690                                  
  3691                                  ; 06/11/2014
  3692                                  ; Memory Information message
  3693                                  ; 14/08/2015
  3694                                  msg_memory_info:
  3695 00013E6F 07                      	db	07h
  3696 00013E70 0D0A                    	db	0Dh, 0Ah
  3697                                  	;db 	"MEMORY ALLOCATION INFO", 0Dh, 0Ah, 0Dh, 0Ah
  3698 00013E72 546F74616C206D656D-     	db	"Total memory : "
  3698 00013E7B 6F7279203A20       
  3699                                  mem_total_b_str: ; 10 digits
  3700 00013E81 303030303030303030-     	db	"0000000000 bytes", 0Dh, 0Ah
  3700 00013E8A 302062797465730D0A 
  3701 00013E93 202020202020202020-     	db	"               ", 20h, 20h, 20h
  3701 00013E9C 202020202020202020 
  3702                                  mem_total_p_str: ; 7 digits
  3703 00013EA5 303030303030302070-     	db	"0000000 pages", 0Dh, 0Ah
  3703 00013EAE 616765730D0A       
  3704 00013EB4 0D0A                    	db 	0Dh, 0Ah
  3705 00013EB6 46726565206D656D6F-     	db	"Free memory  : "
  3705 00013EBF 727920203A20       
  3706                                  free_mem_b_str:  ; 10 digits
  3707 00013EC5 3F3F3F3F3F3F3F3F3F-     	db	"?????????? bytes", 0Dh, 0Ah
  3707 00013ECE 3F2062797465730D0A 
  3708 00013ED7 202020202020202020-     	db	"               ", 20h, 20h, 20h
  3708 00013EE0 202020202020202020 
  3709                                  free_mem_p_str:  ; 7 digits
  3710 00013EE9 3F3F3F3F3F3F3F2070-     	db	"??????? pages", 0Dh, 0Ah
  3710 00013EF2 616765730D0A       
  3711 00013EF8 0D0A00                  	db	0Dh, 0Ah, 0
  3712                                  
  3713                                  dsk_ready_msg:
  3714 00013EFB 0D0A                    	db 	0Dh, 0Ah
  3715                                  dsktype:
  3716 00013EFD 6664                    	db	'fd'
  3717                                  dskx:
  3718 00013EFF 30                      	db	'0'
  3719 00013F00 20                      	db	20h
  3720 00013F01 697320524541445920-     	db 	'is READY ...'
  3720 00013F0A 2E2E2E             
  3721 00013F0D 00                      	db 	0
  3722                                  
  3723                                  setup_error_msg:
  3724 00013F0E 0D0A                    	db	0Dh, 0Ah
  3725 00013F10 4469736B2053657475-     	db	'Disk Setup Error !' 
  3725 00013F19 70204572726F722021 
  3726 00013F22 0D0A00                  	db	0Dh, 0Ah,0
  3727                                  
  3728                                  next2line: ; 08/02/2016
  3729 00013F25 0D0A                    	db	0Dh, 0Ah
  3730                                  nextline:
  3731 00013F27 0D0A00                  	db 	0Dh, 0Ah, 0
  3732                                  
  3733                                  ; temporary
  3734                                  ; 19/12/2020
  3735                                  msg_lfb_addr:
  3736                                  	;db	0Dh, 0Ah
  3737 00013F2A 4C696E656172206672-     	db	"Linear frame buffer at "
  3737 00013F33 616D65206275666665-
  3737 00013F3C 7220617420         
  3738                                  lfb_addr_str: ; 8 (hex) digits
  3739 00013F41 303030303030303068-     	db	"00000000h", 0Dh, 0Ah
  3739 00013F4A 0D0A               
  3740 00013F4C 0D0A00                  	db	0Dh, 0Ah, 0
  3741                                  
  3742                                  ; KERNEL - SYSINIT Messages
  3743                                  ; 24/08/2015
  3744                                  ; 13/04/2015 - (Retro UNIX 386 v1 Beginning)
  3745                                  ; 14/07/2013
  3746                                  ;kernel_init_err_msg:
  3747                                  ;	db 0Dh, 0Ah
  3748                                  ;	db 07h
  3749                                  ;	db 'Kernel initialization ERROR !'
  3750                                  ;	db 0Dh, 0Ah, 0 
  3751                                  
  3752                                  ;welcome_msg: 
  3753                                  ;	db 0Dh, 0Ah
  3754                                  ;	db 07h
  3755                                  ;	db 'Welcome to TRDOS 386 Operating System !'
  3756                                  ;	db 0Dh, 0Ah
  3757                                  ;	db 'by Erdogan Tan - 31/12/2017 (v2.0.0)'
  3758                                  ;	db 0Dh, 0Ah, 0
  3759                                  
  3760                                  panic_msg:
  3761 00013F4F 0D0A07                  	db 0Dh, 0Ah, 07h
  3762 00013F52 4552524F523A204B65-     	db 'ERROR: Kernel Panic !'
  3762 00013F5B 726E656C2050616E69-
  3762 00013F64 632021             
  3763 00013F67 0D0A00                  	db 0Dh, 0Ah, 0
  3764                                  
  3765                                  ;msgl_drv_not_ready: 
  3766                                  ;	db 07h, 0Dh, 0Ah
  3767                                  ;       db 'Drive not ready or read error !'
  3768                                  ;       db 0Dh, 0Ah, 0
  3769                                  
  3770                                  starting_msg:
  3771                                  	;;;;;db "Turkish Rational DOS v2.0 [18/04/2021] ...", 0
  3772                                  	;;;;db "Turkish Rational DOS v2.0 [11/08/2022] ...", 0
  3773                                  	;;;db "Turkish Rational DOS v2.0 [30/08/2023] ...", 0
  3774                                  	;;db "Turkish Rational DOS v2.0 [07/12/2023] ...", 0
  3775                                  	;db "Turkish Rational DOS v2.0 [23/06/2024] ...", 0
  3776 00013F6A 5475726B6973682052-     	db "Turkish Rational DOS v2.0 [29/12/2024] ...", 0
  3776 00013F73 6174696F6E616C2044-
  3776 00013F7C 4F532076322E30205B-
  3776 00013F85 32392F31322F323032-
  3776 00013F8E 345D202E2E2E00     
  3777                                  
  3778                                  NextLine:
  3779 00013F95 0D0A00                  	db 0Dh, 0Ah, 0
  3780                                  
  3781                                  %include 'audio.s' ; 03/04/2017
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.8 - audio.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 06/06/2024  (Previous: 02/12/2023 - Kernel v2.0.7)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 03/04/2017
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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
   101                              <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
   132                              <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> ; 20/11/2023
   204                              <1> ; (playwav2.com, ac97.inc, Erdogan Tan, 11/11/2023)
   205                              <1> ; 03/11/2023 - Erdogan Tan (Ref: MenuetOS AC97 WAV Player source code, 2004)
   206                              <1> SIS_VID		equ	1039h
   207                              <1> NVIDIA_VID	equ	10DEh	 ; Ref: MPXPLAY/SBEMU/KOLIBRIOS AC97 source c.
   208                              <1> AMD_VID		equ	1022h
   209                              <1> ;
   210                              <1> ICH_DID		equ	2415h	; ICH (82801AA) device ID
   211                              <1> ; 20/11/2023
   212                              <1> ; (playwav2.com, ac97.inc, Erdogan Tan, 11/11/2023)
   213                              <1> ; 17/02/2017 (Erdogan Tan, ref: ALSA Device IDs, ALSA project)
   214                              <1> ICH0_DID        equ     2425h	; ICH0
   215                              <1> ICH2_DID        equ     2445h 	; ICH2
   216                              <1> ICH3_DID	equ     2485h	; ICH3
   217                              <1> ICH4_DID        equ     24C5h	; ICH4
   218                              <1> ICH5_DID	equ     24D5h	; ICH5
   219                              <1> ICH6_DID	equ     266Eh	; ICH6
   220                              <1> ESB6300_DID	equ     25A6h	; 6300ESB
   221                              <1> ESB631X_DID	equ     2698h	; 631XESB
   222                              <1> ICH7_DID	equ	27DEh	; ICH7
   223                              <1> ; 03/11/2023 - Erdogan Tan (Ref: MenuetOS AC97 WAV Player source code, 2004)
   224                              <1> MX82440_DID	equ	7195h
   225                              <1> SI7012_DID	equ	7012h
   226                              <1> NFORCE_DID	equ	01B1h
   227                              <1> NFORCE2_DID	equ	006Ah
   228                              <1> AMD8111_DID	equ	746Dh
   229                              <1> AMD768_DID	equ	7445h
   230                              <1> ; 03/11/2023 - Erdogan Tan - Ref: MPXPLAY/SBEMU/KOLIBRIOS AC97 source code
   231                              <1> CK804_DID	equ	0059h	; NFORCE4
   232                              <1> MCP04_DID	equ	003Ah
   233                              <1> CK8_DID		equ	008Ah
   234                              <1> NFORCE3_DID	equ	00DAh
   235                              <1> CK8S_DID	equ	00EAh
   236                              <1> 
   237                              <1> NAMBAR_REG      equ	10h	; native audio mixer Base Address Register
   238                              <1> NABMBAR_REG     equ	14h	; native audio bus mastering Base Addr Reg
   239                              <1> 
   240                              <1> PI_CR_REG       equ     0Bh     ; PCM in Control Register
   241                              <1> PO_CR_REG	equ     1Bh     ; PCM out Control Register
   242                              <1> MC_CR_REG	equ     2Bh     ; MIC in Control Register
   243                              <1> 
   244                              <1> PI_SR_REG	equ     6       ; PCM in Status register
   245                              <1> PO_SR_REG	equ     16h     ; PCM out Status register
   246                              <1> MC_SR_REG	equ     26h     ; MIC in Status register
   247                              <1> 
   248                              <1> IOCE 		equ     BIT4    ; interrupt on complete enable.
   249                              <1> FEIFE		equ     BIT3    ; set if you want an interrupt to fire
   250                              <1> LVBIE		equ     BIT2    ; last valid buffer interrupt enable.
   251                              <1> RR 		equ     BIT1    ; reset registers. Nukes all regs
   252                              <1>                                 ; except bits 4:2 of this register.
   253                              <1>                                 ; Only set this bit if BIT 0 is 0
   254                              <1> RPBM		equ     BIT0    ; Run/Pause
   255                              <1> 				; set this bit to start the codec!
   256                              <1> 
   257                              <1> PI_BDBAR_REG	equ     0       ; PCM in buffer descriptor BAR
   258                              <1> PO_BDBAR_REG	equ     10h     ; PCM out buffer descriptor BAR
   259                              <1> MC_BDBAR_REG	equ     20h     ; MIC in buffer descriptor BAR
   260                              <1> 
   261                              <1> PI_CIV_REG	equ     4       ; PCM in current Index value (RO)
   262                              <1> PO_CIV_REG	equ     14h     ; PCM out current Index value (RO)
   263                              <1> MC_CIV_REG 	equ     24h     ; MIC in current Index value (RO)
   264                              <1> 
   265                              <1> PI_LVI_REG	equ     5       ; PCM in Last Valid Index
   266                              <1> PO_LVI_REG	equ     15h     ; PCM out Last Valid Index
   267                              <1> MC_LVI_REG	equ     25h     ; MIC in Last Valid Index
   268                              <1> 
   269                              <1> IOC		equ     BIT31	; Fire an interrupt whenever this
   270                              <1>                 		; buffer is complete.
   271                              <1> BUP		equ     BIT30	; Buffer Underrun Policy.
   272                              <1> 
   273                              <1> GLOB_CNT_REG	equ     2Ch     ; Global Control Register
   274                              <1> GLOB_STS_REG	equ     30h     ; Global Status register (RO)
   275                              <1> 
   276                              <1> CTRL_ST_CREADY	equ   BIT8+BIT9+BIT28 ; Primary Codec Ready
   277                              <1> 
   278                              <1> CODEC_REG_POWERDOWN   equ 26h
   279                              <1> CODEC_REG_ST          equ 26h
   280                              <1> 
   281                              <1> ; 22/06/2017
   282                              <1> PO_PICB_REG	equ 18h	; PCM Out Position In Current Buffer Register
   283                              <1> 
   284                              <1> ; 19/11/2023
   285                              <1> AC97_EA_VRA	equ BIT0
   286                              <1> ; 24/11/2023
   287                              <1> BCIS		equ BIT3  ; Buffer Completion Interrupt Status
   288                              <1> 
   289                              <1> ;=============================================================================
   290                              <1> ;               CODE
   291                              <1> ;=============================================================================
   292                              <1> 
   293                              <1> ; CODE for INTEL ICH AC'97 AUDIO CONTROLLER
   294                              <1> 
   295                              <1> DetectICH:
   296                              <1> 	; 22/11/2023
   297                              <1> 	; 19/11/2023
   298                              <1> 	; 01/11/2023 - TRDOS 386 Kernel v2.0.7
   299                              <1> 	;; 10/06/2017
   300                              <1> 	;; 05/06/2017
   301                              <1> 	;; 29/05/2017
   302                              <1> 	;; 28/05/2017
   303                              <1> 	;mov	eax, (ICH_DID << 16) + INTEL_VID
   304                              <1>         ;call	pciFindDevice
   305                              <1>         ;jnc	short d_ac97_1
   306                              <1> 	;
   307                              <1> 	;; 01/11/2023
   308                              <1> 	;mov	eax, (NFORCE_DID << 16) + NFORCE_VID
   309                              <1>         ;call	pciFindDevice
   310                              <1>         ;jnc	short d_ac97_1
   311                              <1> 
   312                              <1> 	; 19/11/2023
   313 00013F98 BE[BD4D0100]        <1> 	mov	esi, valid_ids	; address of Valid ICH (AC97) Device IDs
   314 00013F9D B915000000          <1> 	mov	ecx, valid_id_count
   315                              <1> pfd_1:
   316 00013FA2 AD                  <1> 	lodsd
   317 00013FA3 E857000000          <1> 	call	pciFindDevice
   318 00013FA8 730F                <1> 	jnc	short d_ac97_1
   319 00013FAA E2F6                <1> 	loop	pfd_1
   320                              <1> 	;stc
   321                              <1> 
   322                              <1> d_ac97_0:
   323                              <1> ; couldn't find the audio device!
   324 00013FAC C3                  <1> 	retn
   325                              <1> 
   326                              <1> ; CODE for VIA VT8233 AUDIO CONTROLLER
   327                              <1> 
   328                              <1> DetectVT8233:
   329                              <1> 	; 22/11/2023
   330                              <1> 	; 02/11/2023
   331                              <1> 	; 01/11/2023 - TRDOS 386 Kernel v2.0.7
   332                              <1> 	; 06/08/2022 - TRDOS 386 Kernel v2.0.5
   333                              <1> 	; 10/06/2017
   334                              <1> 	; 05/06/2017
   335                              <1> 	; 29/05/2017
   336                              <1> 	; 03/04/2017
   337 00013FAD B806115930          <1> 	mov     eax, (VT8233_DID << 16) + VIA_VID
   338 00013FB2 E848000000          <1>         call    pciFindDevice
   339                              <1> ;       jnc     short d_vt8233_0
   340                              <1> ; couldn't find the audio device!
   341                              <1> ;	retn
   342 00013FB7 72F3                <1> 	jc	short d_ac97_0  ; 28/05/2017
   343                              <1> d_vt8233_0:
   344                              <1> 	; 24/03/2017 ('player.asm')
   345                              <1> 	; 12/11/2016 
   346                              <1> 	; Erdogan Tan - 8/11/2016
   347                              <1> 	; References: Kolibrios - vt823x.asm (2016)
   348                              <1> 	;	      VIA VT8235 V-Link South Bridge (VT8235-VIA.PDF)(2002)
   349                              <1> 	;	      lowlevel.eu - AC97 (2016)
   350                              <1> 	;	      .wav player for DOS by Jeff Leyda (2002) -this file-
   351                              <1> 	;	      Linux kernel - via82xx.c (2016)
   352                              <1> d_ac97_1:
   353                              <1> 	; eax = BUS/DEV/FN
   354                              <1> 	;	00000000BBBBBBBBDDDDDFFF00000000
   355                              <1> 	; edx = DEV/VENDOR
   356                              <1> 	;	DDDDDDDDDDDDDDDDVVVVVVVVVVVVVVVV
   357                              <1> 
   358 00013FB9 A3[F48E0100]        <1> 	mov	[audio_dev_id], eax
   359 00013FBE 8915[F88E0100]      <1> 	mov	[audio_vendor], edx
   360                              <1> 
   361                              <1> 	; 22/11/2023
   362                              <1> 	;; init controller
   363                              <1> 	;mov	al, PCI_CMD_REG ; command register (04h)
   364                              <1> 	;call	pciRegRead32
   365                              <1> 	;
   366                              <1> 	;; eax = BUS/DEV/FN/REG
   367                              <1> 	;; edx = STATUS/COMMAND
   368                              <1> 	;; 	SSSSSSSSSSSSSSSSCCCCCCCCCCCCCCCC
   369                              <1> 	;mov	[audio_stats_cmd], edx
   370                              <1> 
   371 00013FC4 B010                <1> 	mov	al, PCI_IO_BASE ; IO base address register (10h)
   372                              <1> 	;mov	al, NAMBAR_REG	; Native Audio Mixer BAR (10h)
   373 00013FC6 E8BF000000          <1> 	call	pciRegRead32
   374                              <1> 
   375                              <1> 	;cmp	word [audio_vendor], INTEL_VID ; 8086h ; AC'97 ?
   376                              <1> 	;;jne	short d_vt8233_1
   377                              <1> 	;; 01/11/2023
   378                              <1> 	;je	short d_ac97_3
   379                              <1> 	;cmp	word [audio_vendor], NFORCE_VID ; 10DEh ; AC'97
   380                              <1> 	;jne	short d_vt8233_1
   381                              <1> 	; 02/11/2023
   382 00013FCB 66813D[F88E0100]06- <1> 	cmp	word [audio_vendor], VIA_VID	; 1106h ; VT8233-VT8237R 
   382 00013FD3 11                  <1>
   383 00013FD4 7411                <1> 	je	short d_vt8233_1
   384                              <1> d_ac97_3:
   385                              <1> 	;and	dx, 0FFFEh ; Audio Codec IO_ADDR_MASK
   386                              <1> 	; 06/08/2022
   387 00013FD6 80E2FE              <1> 	and	dl, 0FEh
   388 00013FD9 668915[F08E0100]    <1> 	mov	[NAMBAR], dx
   389                              <1> 
   390 00013FE0 B014                <1> 	mov	al, NABMBAR_REG ; Native Audio Bus Mastering BAR (14h)
   391 00013FE2 E8A3000000          <1> 	call	pciRegRead32
   392                              <1> 
   393                              <1> 	;;and	dx, 0FFC0h ; Audio Controller IO_ADDR_MASK
   394                              <1> 	;; 06/08/2022
   395                              <1> 	;and	dl, 0C0h
   396                              <1> 	;mov	[NABMBAR], dx
   397                              <1>         ;;mov	[audio_io_base], dx
   398                              <1> 	;
   399                              <1> 	;jmp	short d_ac97_2
   400                              <1> 	; 02/11/2023
   401                              <1> 	; NABMBAR = audio_io_base
   402                              <1> 
   403                              <1> d_vt8233_1:
   404                              <1> 	;and	dx, 0FFC0h ; Audio Controller IO_ADDR_MASK 
   405                              <1> 	; 06/08/2022
   406 00013FE7 80E2C0              <1> 	and	dl, 0C0h
   407 00013FEA 668915[F28E0100]    <1>         mov     [audio_io_base], dx
   408                              <1> 
   409                              <1> d_ac97_2:
   410                              <1> 	; 10/06/2017
   411 00013FF1 B03C                <1> 	mov	al, AC97_INT_LINE ; Interrupt Line Register (3Ch)
   412                              <1> 	;call	pciRegRead32
   413 00013FF3 E87F000000          <1> 	call	pciRegRead8
   414                              <1> 
   415                              <1> 	;;and 	edx, 0FFh
   416                              <1> 	; 06/08/2022
   417                              <1> 	;and	dx, 0FFh
   418                              <1> 
   419 00013FF8 8815[EE8E0100]      <1> 	mov     [audio_intr], dl
   420                              <1> 
   421 00013FFE C3                  <1> 	retn
   422                              <1> 
   423                              <1> 	; (Note: Interrupts are already enabled by TRDOS 386 kernel!)
   424                              <1> 	;mov	cx, dx
   425                              <1> 	;
   426                              <1> 	;in	al, 0A1h ; irq 8-15
   427                              <1> 	;mov	ah, al
   428                              <1> 	;in	al, 21h  ; irq 0-7 
   429                              <1> 	;btr	ax, dx	 ; unmask ; 17/03/2017
   430                              <1> 	;;bts	ax, dx   ; MASK interrupt ; 10/06/2017
   431                              <1> 	;out	21h, al  ; irq <= 7
   432                              <1> 	;mov	al, ah
   433                              <1> 	;out	0A1h, al ; irq > 7
   434                              <1> 	;
   435                              <1> 	
   436                              <1> 	; 10/06/2017
   437                              <1> 	; === Intel ICH I/O Controller Hub Datasheet, Section 8.1.16 ===
   438                              <1> 	; PRQ[n]_ROUT Register (61h, PRQB) Bit 7:
   439                              <1> 	; Interrupt Routing Enable (IRQEN).
   440                              <1> 	; 0 = The corresponding PIRQ is routed to one of the ISA-compatible
   441                              <1> 	;     interrupts specified in bits[3:0].
   442                              <1> 	; 1 = The PIRQ is not routed to the 8259.
   443                              <1> 	; Note: If the PIRQ is intended to cause an interrupt to the ICHs
   444                              <1> 	;	integrated I/O APIC, then this bit should be set to 0 and
   445                              <1> 	;	the APIC_EN bit should be set to 1. 
   446                              <1> 	;	The IRQEN must be set to 0 and the PIRQ routed to 
   447                              <1> 	;	an 8259 interrupt via the IRQ Routing filed (bits[3:0).
   448                              <1> 	;	The corresponding 8259 interrupt must be masked via the 
   449                              <1> 	;	appropriated bit in the 8259s OCW1 (Interrupt Mask)
   450                              <1> 	;	register. The IOAPIC must then be enabled by setting 
   451                              <1> 	;	the APIC_EN bit in the GEN_CNTL register.
   452                              <1> 
   453                              <1> 	;mov	eax, 0F861h  ; D31:F0
   454                              <1> 	;	; AL=61h : PIRQ[B] Routing Control Reg, LPC interface
   455                              <1> 	;;mov	dl, [audio_intr]
   456                              <1> 	;call	pciRegWrite8
   457                              <1> 	;;mov	al, 0D0h	; General Control Register (GEN_CTL)
   458                              <1> 	;;call	pciRegRead32
   459                              <1> 	;;or	edx, 100h	; Bit 8, APIC_EN (Enable I/O APIC)
   460                              <1> 	;;call	pciRegWrite32
   461                              <1> 	;;and	edx, ~100h
   462                              <1> 	;;call	pciRegWrite32	; Bit 8, APIC_EN (Disable I/O APIC)
   463                              <1> 	;
   464                              <1> 
   465                              <1> 	;mov	dx, 4D1h	; 8259 ELCR2
   466                              <1>     	;in	al, dx
   467                              <1> 	;mov	ah, al
   468                              <1> 	;;mov	dx, 4D0h 	; 8259 ELCR1
   469                              <1> 	;dec	dl
   470                              <1> 	;in	al, dx
   471                              <1> 	;bts	ax, cx
   472                              <1> 	;;mov	dx, 4D0h
   473                              <1> 	;out	dx, al		; set level-triggered mode
   474                              <1> 	;mov	al, ah ; 29/05/2017
   475                              <1> 	;;mov	dx, 4D1h
   476                              <1> 	;inc	dl
   477                              <1> 	;out	dx, al		; set level-triggered mode
   478                              <1> 
   479                              <1> 	;xor	eax, eax ; 0
   480                              <1> 
   481                              <1> 	;retn
   482                              <1> 
   483                              <1> ; CODE for PCI
   484                              <1> 
   485                              <1> pciFindDevice:
   486                              <1> 	; 19/11/2023
   487                              <1> 	; 03/04/2017 ('pci.asm', 20/03/2017)
   488                              <1> 	;
   489                              <1> 	; scan through PCI space looking for a device+vendor ID
   490                              <1> 	;
   491                              <1> 	; Entry: EAX=Device+Vendor ID
   492                              <1> 	;
   493                              <1> 	; Exit: EAX=PCI address if device found
   494                              <1> 	;	EDX=Device+Vendor ID
   495                              <1> 	;       CY clear if found, set if not found. EAX invalid if CY set.
   496                              <1> 	;
   497                              <1> 	; Destroys: ebx, edi ; 19/11/2023
   498                              <1> 
   499                              <1> 	;push	ecx
   500                              <1> 	;push	eax ; * ; 19/11/2023
   501                              <1> 	;push	esi
   502                              <1> 	;push	edi
   503                              <1> 	;
   504                              <1> 	;mov	esi, eax		; save off vend+device ID
   505                              <1>         ; 19/11/2023
   506 00013FFF 89C3                <1> 	mov	ebx, eax
   507                              <1> 	;mov	edi, (80000000h - 100h)	; start with bus 0, dev 0 func 0
   508 00014001 BF00000080          <1> 	mov	edi, 80000000h
   509                              <1> nextPCIdevice:
   510                              <1> 	;add	edi, 100h
   511                              <1> 	;cmp	edi, 80FFF800h		; scanned all devices?
   512                              <1> 	;stc
   513                              <1> 	;je	short PCIScanExit	; not found
   514                              <1> 
   515 00014006 89F8                <1> 	mov 	eax, edi		; read PCI registers
   516 00014008 E87D000000          <1> 	call	pciRegRead32
   517                              <1> 	; 19/11/2023
   518 0001400D 39DA                <1> 	cmp	edx, ebx
   519                              <1> 	;cmp	edx, esi		; found device?
   520                              <1> 	;jne	short nextPCIdevice
   521                              <1> 	;;clc
   522 0001400F 7412                <1> 	je	short PCIScanExit	; found
   523                              <1> 	; 19/11/2023
   524 00014011 81FF00F8FF80        <1> 	cmp	edi, 80FFF800h
   525 00014017 7308                <1> 	jnb	short pfd_nf		; not found
   526 00014019 81C700010000        <1> 	add	edi, 100h
   527 0001401F EBE5                <1> 	jmp	short nextPCIdevice
   528                              <1> pfd_nf:
   529 00014021 F9                  <1> 	stc
   530 00014022 C3                  <1> 	retn
   531                              <1> PCIScanExit:
   532                              <1> 	;pushf
   533 00014023 B8FFFFFF7F          <1> 	mov	eax, NOT_BIT31 	; 19/03/2017
   534 00014028 21F8                <1> 	and	eax, edi	; return only bus/dev/fn #
   535                              <1> 	;popf
   536                              <1> 	;
   537                              <1> 	;pop	edi
   538                              <1> 	;pop	esi
   539                              <1> 	;pop	edx ; * ; 19/11/2023
   540                              <1> 	;pop	ecx
   541                              <1> 	;
   542 0001402A C3                  <1> 	retn
   543                              <1> 
   544                              <1> ; 26/11/2023
   545                              <1> %if 1
   546                              <1> 
   547                              <1> pciRegRead:
   548                              <1> 	; 03/04/2017 ('pci.asm', 20/03/2017)
   549                              <1> 	;
   550                              <1> 	; 8/16/32bit PCI reader
   551                              <1> 	;
   552                              <1> 	; Entry: EAX=PCI Bus/Device/fn/register number
   553                              <1> 	;           BIT30 set if 32 bit access requested
   554                              <1> 	;           BIT29 set if 16 bit access requested
   555                              <1> 	;           otherwise defaults to 8 bit read
   556                              <1> 	;
   557                              <1> 	; Exit:  DL,DX,EDX register data depending on requested read size
   558                              <1> 	;
   559                              <1> 	; Note1: this routine is meant to be called via pciRegRead8,
   560                              <1> 	;	 pciRegread16 or pciRegRead32, listed below.
   561                              <1> 	;
   562                              <1> 	; Note2: don't attempt to read 32 bits of data from a non dword
   563                              <1> 	;	 aligned reg number. Likewise, don't do 16 bit reads from
   564                              <1> 	;	 non word aligned reg #
   565                              <1> 	
   566 0001402B 53                  <1> 	push	ebx
   567 0001402C 51                  <1> 	push	ecx
   568 0001402D 89C3                <1>         mov     ebx, eax		; save eax, dh
   569 0001402F 88F1                <1>         mov     cl, dh
   570                              <1> 
   571 00014031 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; clear out data size request
   572 00014036 0D00000080          <1>         or      eax, BIT31		; make a PCI access request
   573 0001403B 24FC                <1>         and     al, ~3 ; NOT 3		; force index to be dword
   574                              <1> 
   575 0001403D 66BAF80C            <1>         mov     dx, PCI_INDEX_PORT
   576 00014041 EF                  <1>         out	dx, eax			; write PCI selector
   577                              <1> 	
   578 00014042 66BAFC0C            <1>         mov     dx, PCI_DATA_PORT
   579 00014046 88D8                <1>         mov     al, bl
   580 00014048 2403                <1>         and     al, 3			; figure out which port to
   581 0001404A 00C2                <1>         add     dl, al			; read to
   582                              <1> 
   583 0001404C F7C3000000C0        <1> 	test    ebx, PCI32+PCI16
   584 00014052 7507                <1>         jnz     short _pregr0
   585 00014054 EC                  <1> 	in	al, dx			; return 8 bits of data
   586 00014055 88C2                <1>         mov	dl, al
   587 00014057 88CE                <1> 	mov     dh, cl			; restore dh for 8 bit read
   588 00014059 EB12                <1> 	jmp	short _pregr2
   589                              <1> _pregr0:	
   590 0001405B F7C300000080        <1> 	test    ebx, PCI32
   591 00014061 7507                <1>         jnz	short _pregr1
   592 00014063 66ED                <1> 	in	ax, dx
   593 00014065 6689C2              <1>         mov     dx, ax			; return 16 bits of data
   594 00014068 EB03                <1> 	jmp	short _pregr2
   595                              <1> _pregr1:
   596 0001406A ED                  <1> 	in	eax, dx			; return 32 bits of data
   597 0001406B 89C2                <1> 	mov	edx, eax
   598                              <1> _pregr2:
   599 0001406D 89D8                <1> 	mov     eax, ebx		; restore eax
   600 0001406F 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; clear out data size request
   601 00014074 59                  <1> 	pop	ecx
   602 00014075 5B                  <1> 	pop	ebx
   603 00014076 C3                  <1> 	retn
   604                              <1> 
   605                              <1> pciRegRead8:
   606 00014077 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; set up 8 bit read size
   607 0001407C EBAD                <1>         jmp     short pciRegRead	; call generic PCI access
   608                              <1> 
   609                              <1> pciRegRead16:
   610 0001407E 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; set up 16 bit read size
   611 00014083 0D00000040          <1>         or      eax, PCI16		; call generic PCI access
   612 00014088 EBA1                <1>         jmp     short pciRegRead
   613                              <1> 
   614                              <1> pciRegRead32:
   615 0001408A 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; set up 32 bit read size
   616 0001408F 0D00000080          <1>         or      eax, PCI32		; call generic PCI access
   617 00014094 EB95                <1>         jmp     pciRegRead
   618                              <1> 
   619                              <1> pciRegWrite:
   620                              <1> 	; 03/04/2017 ('pci.asm', 29/11/2016)
   621                              <1> 	;
   622                              <1> 	; 8/16/32bit PCI writer
   623                              <1> 	;
   624                              <1> 	; Entry: EAX=PCI Bus/Device/fn/register number
   625                              <1> 	;           BIT31 set if 32 bit access requested
   626                              <1> 	;           BIT30 set if 16 bit access requested
   627                              <1> 	;           otherwise defaults to 8bit read
   628                              <1> 	;        DL/DX/EDX data to write depending on size
   629                              <1> 	;
   630                              <1> 	; Note1: this routine is meant to be called via pciRegWrite8, 
   631                              <1> 	;	 pciRegWrite16 or pciRegWrite32 as detailed below.
   632                              <1> 	;
   633                              <1> 	; Note2: don't attempt to write 32bits of data from a non dword
   634                              <1> 	;	 aligned reg number. Likewise, don't do 16 bit writes from
   635                              <1> 	;	 non word aligned reg #
   636                              <1> 
   637 00014096 53                  <1> 	push	ebx
   638 00014097 51                  <1> 	push	ecx
   639 00014098 89C3                <1>         mov     ebx, eax		; save eax, edx
   640 0001409A 89D1                <1>         mov     ecx, edx
   641 0001409C 25FFFFFF3F          <1> 	and     eax, NOT_PCI32_PCI16	; clear out data size request
   642 000140A1 0D00000080          <1>         or      eax, BIT31		; make a PCI access request
   643 000140A6 24FC                <1>         and     al, ~3 ; NOT 3		; force index to be dword
   644                              <1> 
   645 000140A8 66BAF80C            <1>         mov     dx, PCI_INDEX_PORT
   646 000140AC EF                  <1>         out	dx, eax			; write PCI selector
   647                              <1> 	
   648 000140AD 66BAFC0C            <1>         mov     dx, PCI_DATA_PORT
   649 000140B1 88D8                <1>         mov     al, bl
   650 000140B3 2403                <1>         and     al, 3			; figure out which port to
   651 000140B5 00C2                <1>         add     dl, al			; write to
   652                              <1> 
   653 000140B7 F7C3000000C0        <1> 	test    ebx, PCI32+PCI16
   654 000140BD 7505                <1>         jnz     short _pregw0
   655 000140BF 88C8                <1> 	mov	al, cl 			; put data into al
   656 000140C1 EE                  <1> 	out	dx, al
   657 000140C2 EB12                <1> 	jmp	short _pregw2
   658                              <1> _pregw0:
   659 000140C4 F7C300000080        <1> 	test    ebx, PCI32
   660 000140CA 7507                <1>         jnz     short _pregw1
   661 000140CC 6689C8              <1> 	mov	ax, cx			; put data into ax
   662 000140CF 66EF                <1> 	out	dx, ax
   663 000140D1 EB03                <1> 	jmp	short _pregw2
   664                              <1> _pregw1:
   665 000140D3 89C8                <1> 	mov	eax, ecx		; put data into eax
   666 000140D5 EF                  <1> 	out	dx, eax
   667                              <1> _pregw2:
   668 000140D6 89D8                <1>         mov     eax, ebx		; restore eax
   669 000140D8 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; clear out data size request
   670 000140DD 89CA                <1>         mov     edx, ecx		; restore dx
   671 000140DF 59                  <1> 	pop	ecx
   672 000140E0 5B                  <1> 	pop	ebx
   673 000140E1 C3                  <1> 	retn
   674                              <1> 
   675                              <1> pciRegWrite8:
   676 000140E2 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; set up 8 bit write size
   677 000140E7 EBAD                <1>         jmp	short pciRegWrite	; call generic PCI access
   678                              <1> 
   679                              <1> pciRegWrite16:
   680 000140E9 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; set up 16 bit write size
   681 000140EE 0D00000040          <1>         or      eax, PCI16		; call generic PCI access
   682 000140F3 EBA1                <1>         jmp	short pciRegWrite
   683                              <1> 
   684                              <1> pciRegWrite32:
   685 000140F5 25FFFFFF3F          <1>         and     eax, NOT_PCI32_PCI16	; set up 32 bit write size
   686 000140FA 0D00000080          <1>         or      eax, PCI32		; call generic PCI access
   687 000140FF EB95                <1>         jmp	pciRegWrite
   688                              <1> 
   689                              <1> %endif
   690                              <1> 
   691                              <1> ; 26/11/2023 - temporary
   692                              <1> %if 0
   693                              <1> 
   694                              <1> ; PLAYWAV3.COM, ac97_vra.asm, 19/11/2023, Erdogan Tan
   695                              <1> 
   696                              <1> ;===============================================================
   697                              <1> ; 8/16/32bit PCI reader
   698                              <1> ;
   699                              <1> ; Entry: EAX=PCI Bus/Device/fn/register number
   700                              <1> ;           BIT30 set if 32 bit access requested
   701                              <1> ;           BIT29 set if 16 bit access requested
   702                              <1> ;           otherwise defaults to 8 bit read
   703                              <1> ;
   704                              <1> ; Exit:  DL,DX,EDX register data depending on requested read size
   705                              <1> ;
   706                              <1> ; Note: this routine is meant to be called via pciRegRead8, pciRegread16,
   707                              <1> ;	or pciRegRead32, listed below.
   708                              <1> ;
   709                              <1> ; Note2: don't attempt to read 32bits of data from a non dword aligned reg
   710                              <1> ;	 number. Likewise, don't do 16bit reads from non word aligned reg #
   711                              <1> ; 
   712                              <1> pciRegRead:
   713                              <1> 	push	ebx
   714                              <1> 	push	ecx
   715                              <1>         mov     ebx, eax                        ; save eax, dh
   716                              <1>         mov     cl, dh
   717                              <1>         and     eax, (~PCI32)+PCI16             ; clear out data size request
   718                              <1>         or      eax, BIT31                      ; make a PCI access request
   719                              <1>         and     al, ~3 ; NOT 3                  ; force index to be dword
   720                              <1> 
   721                              <1>         mov     dx, PCI_INDEX_PORT
   722                              <1>         out     dx, eax                         ; write PCI selector
   723                              <1> 
   724                              <1>         mov     dx, PCI_DATA_PORT
   725                              <1>         mov     al, bl
   726                              <1>         and     al, 3                           ; figure out which port to
   727                              <1>         add     dl, al                          ; read to
   728                              <1> 
   729                              <1> 	in      eax, dx                         ; do 32bit read
   730                              <1>         test    ebx, PCI32
   731                              <1>         jz      short _pregr1
   732                              <1> 
   733                              <1>         mov     edx, eax                        ; return 32bits of data
   734                              <1> _pregr1:
   735                              <1> 	mov     dx, ax                          ; return 16bits of data
   736                              <1>         test    ebx, PCI32+PCI16
   737                              <1>         jnz     short _pregr2
   738                              <1>         mov     dh, cl                          ; restore dh for 8 bit read
   739                              <1> _pregr2:
   740                              <1>         mov     eax, ebx                        ; restore eax
   741                              <1>         and     eax, (~PCI32)+PCI16             ; clear out data size request
   742                              <1> 	pop	ecx
   743                              <1> 	pop	ebx
   744                              <1> 	retn
   745                              <1> 
   746                              <1> pciRegRead8:
   747                              <1>         and     eax, (~PCI16)+PCI32             ; set up 8 bit read size
   748                              <1>         jmp     short pciRegRead		; call generic PCI access
   749                              <1> 
   750                              <1> pciRegRead16:
   751                              <1>         and     eax, (~PCI16)+PCI32		; set up 16 bit read size
   752                              <1>         or      eax, PCI16			; call generic PCI access
   753                              <1>         jmp     short pciRegRead
   754                              <1> 
   755                              <1> pciRegRead32:
   756                              <1>         and     eax, (~PCI16)+PCI32		; set up 32 bit read size
   757                              <1>         or      eax, PCI32			; call generic PCI access
   758                              <1>         jmp     short pciRegRead
   759                              <1> 
   760                              <1> ;===============================================================
   761                              <1> ; 8/16/32bit PCI writer
   762                              <1> ;
   763                              <1> ; Entry: EAX=PCI Bus/Device/fn/register number
   764                              <1> ;           BIT31 set if 32 bit access requested
   765                              <1> ;           BIT30 set if 16 bit access requested
   766                              <1> ;           otherwise defaults to 8bit read
   767                              <1> ;        DL/DX/EDX data to write depending on size
   768                              <1> ;
   769                              <1> ;
   770                              <1> ; note: this routine is meant to be called via pciRegWrite8, pciRegWrite16,
   771                              <1> ; 	or pciRegWrite32 as detailed below.
   772                              <1> ;
   773                              <1> ; Note2: don't attempt to write 32bits of data from a non dword aligned reg
   774                              <1> ;	 number. Likewise, don't do 16bit writes from non word aligned reg #
   775                              <1> ;
   776                              <1> pciRegWrite:
   777                              <1> 	push	ebx
   778                              <1> 	push	ecx
   779                              <1>         mov     ebx, eax                        ; save eax, dx
   780                              <1>         mov     cx, dx
   781                              <1>         or      eax, BIT31                      ; make a PCI access request
   782                              <1>         and     eax, ~PCI16 ; NOT PCI16         ; clear out data size request
   783                              <1>         and     al, ~3 ; NOT 3                  ; force index to be dword
   784                              <1> 
   785                              <1>         mov     dx, PCI_INDEX_PORT
   786                              <1>         out     dx, eax                         ; write PCI selector
   787                              <1> 
   788                              <1>         mov     dx, PCI_DATA_PORT
   789                              <1>         mov     al, bl
   790                              <1>         and     al, 3                           ; figure out which port to
   791                              <1>         add     dl, al                          ; write to
   792                              <1> 
   793                              <1>         mov     eax, edx                        ; put data into eax
   794                              <1>         mov     ax, cx
   795                              <1> 
   796                              <1>         out     dx, al
   797                              <1>         test    ebx, PCI16+PCI32                ; only 8bit access? bail
   798                              <1>         jz      short _pregw1
   799                              <1> 
   800                              <1>         out     dx, ax                          ; write 16 bit value
   801                              <1>         test    ebx, PCI16                      ; 16bit requested?  bail
   802                              <1>         jnz     short _pregw1
   803                              <1> 
   804                              <1>         out     dx, eax                         ; write full 32bit
   805                              <1> _pregw1:
   806                              <1>         mov     eax, ebx                        ; restore eax
   807                              <1>         and     eax, (~PCI32)+PCI16             ; clear out data size request
   808                              <1>         mov     dx, cx                          ; restore dx
   809                              <1> 	pop	ecx
   810                              <1> 	pop	ebx
   811                              <1> 	ret
   812                              <1> 
   813                              <1> pciRegWrite8:
   814                              <1>         and     eax, (~PCI16)+PCI32		; set up 8 bit write size
   815                              <1>         jmp     short pciRegWrite		; call generic PCI access
   816                              <1> 
   817                              <1> pciRegWrite16:
   818                              <1>         and     eax, (~PCI16)+PCI32		; set up 16 bit write size
   819                              <1>         or      eax, PCI16			; call generic PCI access
   820                              <1>         jmp     short pciRegWrite
   821                              <1> 
   822                              <1> pciRegWrite32:
   823                              <1>         and     eax, (~PCI16)+PCI32		; set up 32 bit write size
   824                              <1>         or      eax, PCI32			; call generic PCI access
   825                              <1>         jmp     short pciRegWrite
   826                              <1> 
   827                              <1> ;===============================================================
   828                              <1> 
   829                              <1> %endif
   830                              <1> 
   831                              <1> init_codec:
   832                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
   833                              <1> 	; 05/06/2017
   834                              <1> 	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
   835                              <1> 	;
   836 00014101 A1[F48E0100]        <1> 	mov	eax, [audio_dev_id]
   837 00014106 B041                <1> 	mov	al, VIA_ACLINK_CTRL
   838 00014108 E86AFFFFFF          <1> 	call	pciRegRead8
   839                              <1> 	; ?
   840 0001410D B040                <1> 	mov	al, VIA_ACLINK_STAT
   841 0001410F E863FFFFFF          <1> 	call	pciRegRead8
   842 00014114 F6C201              <1> 	test	dl, VIA_ACLINK_C00_READY
   843 00014117 7508                <1>         jnz     short _codec_ready_1
   844 00014119 E80D000000          <1> 	call	reset_codec
   845 0001411E 7305                <1> 	jnc	short _codec_ready_2 ; eax = 1
   846 00014120 C3                  <1> 	retn
   847                              <1> _codec_ready_1:
   848                              <1> 	;mov	eax, 1
   849                              <1> 	; 06/08/2022
   850 00014121 29C0                <1> 	sub	eax, eax
   851 00014123 FEC0                <1> 	inc	al
   852                              <1> 	; eax = 1
   853                              <1> _codec_ready_2:
   854 00014125 E880000000          <1> 	call	codec_io_w16
   855                              <1> detect_codec:
   856 0001412A C3                  <1> 	retn
   857                              <1> 
   858                              <1> reset_codec:
   859                              <1> 	; 16/04/2017
   860                              <1> 	; 23/03/2017 
   861                              <1> 	; ('codec.asm')
   862                              <1> 	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
   863 0001412B A1[F48E0100]        <1> 	mov	eax, [audio_dev_id]
   864 00014130 B041                <1>  	mov	al, VIA_ACLINK_CTRL
   865 00014132 B2E0                <1>        	mov	dl, VIA_ACLINK_CTRL_ENABLE + VIA_ACLINK_CTRL_RESET + VIA_ACLINK_CTRL_SYNC
   866 00014134 E8A9FFFFFF          <1> 	call	pciRegWrite8
   867                              <1> 
   868 00014139 E843000000          <1> 	call	delay_100ms 	; wait 100 ms
   869                              <1> _rc_cold:
   870 0001413E E811000000          <1>         call    cold_reset
   871 00014143 7301                <1>         jnc     short _reset_codec_ok
   872                              <1> 	
   873                              <1> 	; 16/04/2017
   874                              <1>         ;xor	eax, eax	; timeout error
   875                              <1>        	;stc
   876 00014145 C3                  <1> 	retn
   877                              <1> 
   878                              <1> _reset_codec_ok:
   879                              <1> 	; 01/09/2020
   880                              <1> 	; 15/08/2020
   881                              <1> 	; 27/07/2020
   882                              <1> 	; also reset codec by using index control register 0 of AD1980 or ALC655
   883                              <1> 	; (to fix line out -2 channels audio playing- problem on AD1980 codec)  
   884                              <1> 
   885 00014146 29C0                <1> 	sub	eax, eax
   886                              <1> 	; 02/11/2023
   887                              <1> 	;mov	edx, CODEC_RESET_REG ; 00h ; Reset register
   888 00014148 31D2                <1> 	xor	edx, edx ; 00h ; Reset register
   889 0001414A E8BE000000          <1> 	call	codec_write
   890                              <1> 
   891                              <1> 	;sub	eax, eax
   892                              <1> 	; 01/09/2020
   893                              <1> 	; 15/08/2020
   894                              <1> 	; AD1980 BugFix
   895                              <1> 	; (set HPSEL -headphone amp to be driven from mixer- and
   896                              <1> 	;      CLDIS -center and LFE disable- bits)
   897                              <1> 	;mov	eax, 0C00h ; HPSEL = bit 10, CLDIS = bit 11 ; 01/09/2020
   898                              <1>  	;mov	edx, CODEC_MISC_CRTL_BITS_REG ; 76h ; Misc Ctrl Bits ; AD1980
   899                              <1> 	;call	codec_write
   900                              <1> 
   901 0001414F 31C0                <1>         xor     eax, eax
   902                              <1>         ;mov	al, VIA_ACLINK_C00_READY ; 1
   903 00014151 FEC0                <1>         inc	al
   904 00014153 C3                  <1> 	retn
   905                              <1> 
   906                              <1> cold_reset:
   907                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
   908                              <1> 	; 16/04/2017
   909                              <1> 	; 23/03/2017
   910                              <1> 	; ('codec.asm')
   911                              <1> 	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
   912                              <1> 	;mov	eax, [audio_dev_id]
   913                              <1> 	;mov	al, VIA_ACLINK_CTRL
   914 00014154 30D2                <1> 	xor	dl, dl ; 0
   915 00014156 E887FFFFFF          <1> 	call	pciRegWrite8
   916                              <1> 
   917 0001415B E821000000          <1> 	call	delay_100ms	; wait 100 ms
   918                              <1> 
   919                              <1> 	;; ACLink on, deassert ACLink reset, VSR, SGD data out
   920                              <1>         ;; note - FM data out has trouble with non VRA codecs !!
   921                              <1>         
   922                              <1> 	;mov	eax, [audio_dev_id]
   923                              <1> 	;mov	al, VIA_ACLINK_CTRL
   924 00014160 B2CC                <1> 	mov	dl, VIA_ACLINK_CTRL_INIT
   925 00014162 E87BFFFFFF          <1> 	call	pciRegWrite8
   926                              <1> 
   927                              <1> 	;mov	ecx, 16	; total 2s
   928                              <1> 	; 06/08/2022
   929                              <1> 	;sub	ecx, ecx
   930                              <1> 	; 22/11/2023
   931                              <1> 	; ecx = 0 (from 'delay_100ms')
   932 00014167 B110                <1> 	mov	cl, 16
   933                              <1> _crst_wait:
   934                              <1> 	;mov	eax, [audio_dev_id]
   935 00014169 B040                <1> 	mov	al, VIA_ACLINK_STAT
   936 0001416B E807FFFFFF          <1> 	call	pciRegRead8
   937                              <1> 
   938 00014170 F6C201              <1>         test    dl, VIA_ACLINK_C00_READY
   939 00014173 750B                <1>         jnz     short _crst_ok
   940                              <1> 
   941 00014175 51                  <1> 	push	ecx
   942 00014176 E806000000          <1> 	call	delay_100ms
   943 0001417B 59                  <1> 	pop	ecx
   944                              <1> 
   945 0001417C 49                  <1>         dec     ecx
   946 0001417D 75EA                <1>         jnz     short _crst_wait
   947                              <1> 
   948                              <1> _crst_fail:
   949 0001417F F9                  <1>         stc
   950                              <1> _crst_ok:
   951 00014180 C3                  <1> 	retn
   952                              <1> 
   953                              <1> delay_100ms:
   954                              <1> 	; 29/05/2017
   955                              <1> 	; 24/03/2017 ('codec.asm')
   956                              <1> 	; wait 100 ms
   957 00014181 B990010000          <1> 	mov	ecx, 400  ; 400*0.25ms
   958                              <1> _delay_x_ms:
   959 00014186 E803000000          <1> 	call	delay1_4ms
   960 0001418B E2F9                <1>         loop	_delay_x_ms
   961 0001418D C3                  <1> 	retn
   962                              <1> 
   963                              <1> ;       delay1_4ms - Delay for 1/4 millisecond.
   964                              <1> ;	    1ms = 1000us
   965                              <1> ;       Entry:
   966                              <1> ;         None
   967                              <1> ;       Exit:
   968                              <1> ;	  None
   969                              <1> ;
   970                              <1> ;       Modified:
   971                              <1> ;         None
   972                              <1> 
   973                              <1> 	; 29/05/2017
   974                              <1> 	; 23/04/2017
   975                              <1> 	; 05/03/2017 (TRDOS 386)
   976                              <1> 	; ('UTILS.ASM')
   977                              <1> delay1_4ms:
   978 0001418E 50                  <1>         push    eax 
   979 0001418F 51                  <1>         push    ecx
   980 00014190 B110                <1>         mov	cl, 16		; close enough.
   981                              <1> 
   982 00014192 E461                <1> 	in	al, PORTB ; 61h
   983                              <1> 		
   984 00014194 2410                <1> 	and	al, REFRESH_STATUS ; 10h
   985 00014196 88C5                <1> 	mov	ch, al		; Start toggle state
   986                              <1> _d4ms1:	
   987 00014198 E461                <1> 	in	al, PORTB	; Read system control port
   988                              <1> 	
   989 0001419A 2410                <1> 	and	al, REFRESH_STATUS ; Refresh toggles 15.085 microseconds
   990 0001419C 38C5                <1> 	cmp	ch, al
   991 0001419E 74F8                <1> 	je	short _d4ms1	; Wait for state change
   992                              <1> 
   993 000141A0 88C5                <1> 	mov	ch, al		; Update with new state
   994 000141A2 FEC9                <1> 	dec	cl
   995 000141A4 75F2                <1> 	jnz	short _d4ms1
   996                              <1> 
   997 000141A6 F8                  <1> 	clc	; 29/05/2017
   998                              <1> 
   999 000141A7 59                  <1>         pop     ecx
  1000 000141A8 58                  <1>         pop     eax
  1001 000141A9 C3                  <1>         retn
  1002                              <1> 
  1003                              <1> ; 10/04/2017 (TRDOS 386)
  1004                              <1> ; 12/11/2016
  1005                              <1> 
  1006                              <1> codec_io_w16: ;w32
  1007                              <1> 	; ('codec.asm')
  1008 000141AA 668B15[F28E0100]    <1>         mov	dx, [audio_io_base]
  1009 000141B1 6681C28000          <1>         add     dx, VIA_REG_AC97
  1010 000141B6 EF                  <1> 	out	dx, eax
  1011 000141B7 C3                  <1>         retn
  1012                              <1> 
  1013                              <1> codec_io_r16: ;r32
  1014                              <1> 	; ('codec.asm')
  1015 000141B8 668B15[F28E0100]    <1>         mov     dx, [audio_io_base]
  1016 000141BF 6681C28000          <1>         add     dx, VIA_REG_AC97
  1017 000141C4 ED                  <1>         in	eax, dx
  1018 000141C5 C3                  <1>         retn
  1019                              <1> 
  1020                              <1> ctrl_io_w8:
  1021                              <1> 	; ('codec.asm')
  1022 000141C6 660315[F28E0100]    <1>         add     dx, [audio_io_base]
  1023 000141CD EE                  <1>         out	dx, al
  1024 000141CE C3                  <1>         retn
  1025                              <1> 
  1026                              <1> ctrl_io_r8:
  1027                              <1> 	; ('codec.asm')
  1028 000141CF 660315[F28E0100]    <1>         add     dx, [audio_io_base]
  1029 000141D6 EC                  <1>         in	al, dx
  1030 000141D7 C3                  <1>         retn
  1031                              <1> 
  1032                              <1> ctrl_io_w32:
  1033                              <1> 	; ('codec.asm')
  1034 000141D8 660315[F28E0100]    <1>         add     dx, [audio_io_base]
  1035 000141DF EF                  <1>         out	dx, eax
  1036 000141E0 C3                  <1>         retn
  1037                              <1> 
  1038                              <1> ctrl_io_r32:
  1039                              <1> 	; ('codec.asm')
  1040 000141E1 660315[F28E0100]    <1>         add	dx, [audio_io_base]
  1041 000141E8 ED                  <1> 	in	eax, dx
  1042                              <1> _cr_not_rdy:	; 06/08/2022
  1043 000141E9 C3                  <1>         retn
  1044                              <1> 
  1045                              <1> codec_read:
  1046                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  1047                              <1> 	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1048                              <1>         ; Use only primary codec.
  1049                              <1>         ; eax = register
  1050 000141EA C1E010              <1>         shl     eax, VIA_REG_AC97_CMD_SHIFT
  1051 000141ED 0D00008002          <1>         or      eax, VIA_REG_AC97_PRIMARY_VALID + VIA_REG_AC97_READ
  1052                              <1> 
  1053 000141F2 E8B3FFFFFF          <1> 	call    codec_io_w16
  1054                              <1> 
  1055                              <1>       	; codec_valid
  1056 000141F7 E825000000          <1> 	call	codec_check_ready
  1057                              <1> 	;jnc	short _cr_ok
  1058                              <1> 	;retn
  1059                              <1> 	; 06/08/2022
  1060 000141FC 72EB                <1> 	jc	short _cr_not_rdy
  1061                              <1> 	; ecx <= 20
  1062                              <1> _cr_ok:
  1063                              <1> 	; wait 25 ms
  1064                              <1> 	;mov	ecx, 80 ; (100*0.25 ms)
  1065                              <1> 	; 06/08/2022
  1066                              <1> 	;xor	ecx, ecx
  1067 000141FE B150                <1> 	mov	cl, 80
  1068                              <1> 	; ecx = 80
  1069                              <1> _cr_wloop:
  1070 00014200 E889FFFFFF          <1> 	call	delay1_4ms
  1071 00014205 E2F9                <1> 	loop	_cr_wloop
  1072                              <1> 
  1073 00014207 E8ACFFFFFF          <1>         call    codec_io_r16
  1074                              <1> 	; 06/08/2022
  1075                              <1> 	;and	eax, 0FFFFh
  1076 0001420C C3                  <1>         retn
  1077                              <1> 
  1078                              <1> codec_write:
  1079                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  1080                              <1> 	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1081                              <1>         ; Use only primary codec.
  1082                              <1>         
  1083                              <1> 	; eax = data (volume)
  1084                              <1> 	; edx = register (mixer register)
  1085                              <1> 	
  1086 0001420D C1E210              <1> 	shl     edx, VIA_REG_AC97_CMD_SHIFT
  1087                              <1> 
  1088                              <1> 	; 02/11/2023 (shl eax, 0)
  1089                              <1> 	;shl	eax, VIA_REG_AC97_DATA_SHIFT ; shl eax, 0
  1090 00014210 09C2                <1>         or      edx, eax
  1091                              <1> 
  1092 00014212 B800000000          <1>         mov     eax, VIA_REG_AC97_CODEC_ID_PRIMARY
  1093 00014217 C1E01E              <1>         shl     eax, VIA_REG_AC97_CODEC_ID_SHIFT
  1094 0001421A 09D0                <1>         or      eax, edx
  1095                              <1> 
  1096 0001421C E889FFFFFF          <1>         call    codec_io_w16
  1097                              <1>         ;mov    [codec.regs+esi], ax
  1098                              <1> 
  1099                              <1>         ;call	codec_check_ready
  1100                              <1>        	;retn
  1101                              <1> 	;jmp	short _codec_check_ready
  1102                              <1> 
  1103                              <1> codec_check_ready:
  1104                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  1105                              <1> 	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1106                              <1> 
  1107                              <1> _codec_check_ready:
  1108                              <1> 	;mov	ecx, 20	; total 2s
  1109                              <1> 	; 06/08/2022
  1110 00014221 29C9                <1> 	sub	ecx, ecx
  1111                              <1> 	;mov	cl, 20
  1112                              <1> 	; 02/11/2023
  1113 00014223 B10A                <1> 	mov	cl, 10	; wait 1s
  1114                              <1> _ccr_wait:
  1115 00014225 51                  <1> 	push	ecx
  1116                              <1> 
  1117 00014226 E88DFFFFFF          <1>         call    codec_io_r16
  1118 0001422B A900000001          <1>         test    eax, VIA_REG_AC97_BUSY
  1119 00014230 740B                <1>         jz      short _ccr_ok
  1120                              <1> 
  1121 00014232 E84AFFFFFF          <1> 	call	delay_100ms
  1122                              <1> 
  1123 00014237 59                  <1> 	pop	ecx
  1124                              <1> 
  1125 00014238 49                  <1> 	dec     ecx
  1126 00014239 75EA                <1>         jnz     short _ccr_wait
  1127                              <1> 
  1128 0001423B F9                  <1>         stc
  1129 0001423C C3                  <1>         retn
  1130                              <1> 
  1131                              <1> _ccr_ok:
  1132 0001423D 59                  <1> 	pop	ecx
  1133 0001423E 25FFFF0000          <1> 	and     eax, 0FFFFh
  1134 00014243 C3                  <1>         retn
  1135                              <1> 
  1136                              <1> codec_config:
  1137                              <1> 	; 02/11/2023 - TRDOS 386 Kernel v2.0.7
  1138                              <1> 	; 06/08/2022 - TRDOS 386 Kernel v2.0.5
  1139                              <1> 	; 10/06/2017
  1140                              <1> 	; 29/05/2017
  1141                              <1> 	; 24/04/2017
  1142                              <1> 	; 21/04/2017
  1143                              <1> 	; 16/04/2017 (TRDOS 386 Kernel) 
  1144                              <1> 	; 15/11/2016 ('codec.asm', 'player.com')
  1145                              <1> 	; 14/11/2016
  1146                              <1> 	; 12/11/2016 - Erdogan Tan
  1147                              <1> 	;	     (Ref: KolibriOS, 'setup_codec', codec.inc)
  1148                              <1> 
  1149 00014244 B802020000          <1> 	mov     eax, 0202h
  1150 00014249 66A3[288F0100]      <1> 	mov	[audio_master_volume], ax
  1151                              <1> 
  1152                              <1> 	;mov	ax, 1F1Fh ; 31,31
  1153                              <1> 	; 02/11/2023
  1154 0001424F 66B80B0B            <1> 	mov	ax, 0B0Bh
  1155                              <1> 	;mov	edx, CODEC_MASTER_VOL_REG ; 02h ; Line Out
  1156                              <1> 	; 06/08/2022
  1157 00014253 29D2                <1> 	sub	edx, edx
  1158 00014255 B202                <1> 	mov	dl, CODEC_MASTER_VOL_REG ; 02h ; Line Out
  1159 00014257 E8B1FFFFFF          <1> 	call	codec_write
  1160                              <1> 	;jc	short cconfig_error
  1161                              <1> 
  1162                              <1>  	;mov    eax, 0202h
  1163 0001425C 66B80202            <1> 	mov     ax, 0202h
  1164                              <1> 	;mov	edx, CODEC_PCM_OUT_REG ; 18h ; Wave Output (Stereo)
  1165                              <1> 	; 06/08/2022
  1166 00014260 29D2                <1> 	sub	edx, edx
  1167 00014262 B218                <1> 	mov	dl, CODEC_PCM_OUT_REG ; 18h ; Wave Output (Stereo)
  1168 00014264 E8A4FFFFFF          <1> 	call	codec_write
  1169                              <1> 	;jc	short cconfig_error
  1170                              <1>       
  1171                              <1>  	;mov    eax, 0202h
  1172 00014269 66B80202            <1> 	mov	ax, 0202h
  1173                              <1> 	;mov	edx, CODEC_AUX_VOL ; 04h ; CODEC_HP_VOL_REG ; HeadPhone
  1174                              <1> 	; 06/08/2022
  1175 0001426D 29D2                <1> 	sub	edx, edx
  1176 0001426F B204                <1> 	mov	dl, CODEC_AUX_VOL ; 04h ; CODEC_HP_VOL_REG ; HeadPhone
  1177 00014271 E897FFFFFF          <1> 	call	codec_write
  1178                              <1> 	;jc	short cconfig_error
  1179                              <1> 
  1180                              <1>  	;mov    eax, 08h
  1181                              <1>         ;mov    ax, 08h
  1182 00014276 66B80880            <1> 	mov	ax, 8008h ; Mute
  1183                              <1> 	;mov	edx, 0Ch  ; AC97_PHONE_VOL ; TAD Input (Mono)
  1184                              <1> 	; 06/08/2022
  1185 0001427A 29D2                <1> 	sub	edx, edx
  1186 0001427C B20C                <1> 	mov	dl, 0Ch	  ; AC97_PHONE_VOL ; TAD Input (Mono)
  1187 0001427E E88AFFFFFF          <1> 	call	codec_write
  1188                              <1> 	;jc	short cconfig_error
  1189                              <1> 
  1190                              <1>  	;mov    eax, 0808h
  1191 00014283 66B80808            <1> 	mov	ax, 0808h
  1192                              <1> 	;mov	edx, CODEC_LINE_IN_VOL_REG ; 10h ; Line Input (Stereo)	
  1193                              <1> 	; 06/08/2022
  1194 00014287 29D2                <1> 	sub	edx, edx
  1195 00014289 B210                <1> 	mov	dl, CODEC_LINE_IN_VOL_REG ; 10h ; Line Input (Stereo)	
  1196 0001428B E87DFFFFFF          <1> 	call	codec_write
  1197                              <1> 	;jc	short cconfig_error
  1198                              <1> 
  1199                              <1>  	;mov    eax, 0808h
  1200 00014290 66B80808            <1> 	mov	ax, 0808h
  1201                              <1> 	;mov	edx, CODEC_CD_VOL_REG ; 12h ; CR Input (Stereo)
  1202                              <1> 	; 06/08/2022
  1203 00014294 29D2                <1> 	sub	edx, edx ; 02/11/2023
  1204 00014296 B212                <1> 	mov	dl, CODEC_CD_VOL_REG ; 12h ; CR Input (Stereo)
  1205 00014298 E870FFFFFF          <1> 	call	codec_write
  1206                              <1> 	;jc	short cconfig_error
  1207                              <1> 
  1208                              <1>  	;mov    eax, 0808h
  1209 0001429D 66B80808            <1> 	mov     ax, 0808h
  1210                              <1>         ;mov	edx, CODEC_AUX_VOL_REG ; 16h ; Aux Input (Stereo)
  1211                              <1> 	; 06/08/2022
  1212 000142A1 29D2                <1> 	sub	edx, edx
  1213 000142A3 B216                <1> 	mov	dl, CODEC_AUX_VOL_REG ; 16h ; Aux Input (Stereo)
  1214                              <1> 	;call	codec_write
  1215                              <1> 	;;jc	short cconfig_error
  1216 000142A5 E963FFFFFF          <1> 	jmp	codec_write ; 10/06/2017
  1217                              <1> 
  1218                              <1> ;	; Extended Audio Status (2Ah)
  1219                              <1> ;	mov	eax, CODEC_EXT_AUDIO_CTRL_REG ; 2Ah 
  1220                              <1> ;	call	codec_read
  1221                              <1> ;	and     eax, 0FFFFh - 2		; clear DRA (BIT1)
  1222                              <1> ;	;or     eax, 1			; set VRA (BIT0)
  1223                              <1> ;	or	eax, 5  	; VRA (BIT0) & S/PDIF (BIT2) ; 14/11/2016
  1224                              <1> ;	mov	edx, CODEC_EXT_AUDIO_CTRL_REG
  1225                              <1> ;	call	codec_write
  1226                              <1> ;	;jc	short cconfig_error
  1227                              <1> ;
  1228                              <1> ;set_sample_rate:
  1229                              <1> ;	;movzx	eax, word [audio_freq]
  1230                              <1> ;	mov	ax, [audio_freq]
  1231                              <1> ;	mov	edx, CODEC_PCM_FRONT_DACRATE_REG ; 2Ch ; PCM Front DAC Rate
  1232                              <1> ;	;call	codec_write
  1233                              <1> ;	;retn
  1234                              <1> ;	jmp	codec_write
  1235                              <1> 	
  1236                              <1> ;cconfig_error:
  1237                              <1> ;	retn
  1238                              <1> 
  1239                              <1> vt8233_int_handler:
  1240                              <1> 	; 05/06/2024
  1241                              <1> 	; 04/06/2024 - TRDOS 386 v2.0.8
  1242                              <1> 	; 27/07/2020
  1243                              <1> 	; 22/07/2020
  1244                              <1> 	; Interrupt Handler for VIA VT8237R Audio Controller
  1245                              <1> 	; Note: called by 'dev_IRQ_service'
  1246                              <1> 	; 14/10/2017 
  1247                              <1> 	; 09/10/2017, 10/10/2017, 12/10/2017
  1248                              <1> 	; 13/06/2017
  1249                              <1> 	; 21/04/2017 (TRDOS 386 kernel, 'audio.s')
  1250                              <1> 	; 24/03/2017 - 'PLAYER.COM' ('player.asm')
  1251                              <1> 
  1252                              <1> 	;push	eax ; * must be saved !
  1253                              <1> 	;push	edx
  1254                              <1> 	;push	ecx
  1255                              <1> 	;push	ebx ; * must be saved !
  1256                              <1> 	;push	esi
  1257                              <1> 	;push	edi
  1258                              <1> 
  1259                              <1> 	;cmp	byte [audio_busy], 1
  1260                              <1> 	;jnb	short _ih0 ; 09/10/2017
  1261                              <1> 
  1262                              <1> 	;mov	byte [audio_flag_eol], 0
  1263                              <1> 
  1264 000142AA 66BA0000            <1>         mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STATUS
  1265 000142AE E81CFFFFFF          <1>         call    ctrl_io_r8
  1266                              <1> 
  1267 000142B3 A880                <1> 	test    al, VIA_REG_STAT_ACTIVE
  1268 000142B5 7417                <1>         jz      short _ih0 ; 09/10/2017
  1269                              <1> 
  1270 000142B7 2407                <1>         and     al, VIA_REG_STAT_EOL + VIA_REG_STAT_FLAG + VIA_REG_STAT_STOPPED
  1271 000142B9 A2[278F0100]        <1> 	mov	[audio_flag_eol], al
  1272 000142BE 740E                <1>         jz	short _ih0 ; 09/10/2017
  1273                              <1> 
  1274                              <1> 	; 09/10/2017
  1275                              <1> 	;mov	byte [audio_busy], 1
  1276                              <1> 
  1277 000142C0 803D[268F0100]01    <1> 	cmp	byte [audio_play_cmd], 1
  1278 000142C7 7315                <1> 	jnb	short _ih1 ; 10/10/2017
  1279                              <1> 
  1280 000142C9 E848000000          <1> 	call	channel_reset
  1281                              <1> _ih0:
  1282                              <1> 	; 09/10/2017
  1283 000142CE A0[278F0100]        <1>         mov     al, [audio_flag_eol]   ;; ack ;;
  1284 000142D3 66BA0000            <1>         mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STATUS
  1285 000142D7 E8EAFEFFFF          <1>         call    ctrl_io_w8
  1286 000142DC EB37                <1> 	jmp	short _ih4
  1287                              <1> _ih1:
  1288                              <1> vt8233_tuneLoop:
  1289 000142DE A0[278F0100]        <1>         mov     al, [audio_flag_eol]   ;; ack ;;
  1290 000142E3 66BA0000            <1>         mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STATUS
  1291 000142E7 E8DAFEFFFF          <1>         call    ctrl_io_w8
  1292                              <1> 
  1293                              <1> 	; 22/07/2020
  1294                              <1> 	;; 12/10/2017
  1295                              <1> 	;mov	byte [audio_flag], 0 ; Reset
  1296                              <1> 
  1297                              <1> 	; 10/10/2017
  1298                              <1> 	; 09/10/2017
  1299                              <1> 	;test	byte [audio_flag_eol], VIA_REG_STAT_FLAG
  1300                              <1> 	;jz	short _ih2 ; EOL
  1301                              <1> 
  1302                              <1> 	; 22/07/2020
  1303                              <1> 	; 14/10/2017
  1304                              <1> 	;test	byte [audio_flag_eol], VIA_REG_STAT_EOL
  1305                              <1> 	;jnz	short _ih2 ; EOL
  1306                              <1> 	;		   ; (Half Buffer 2 has been completed 
  1307                              <1> 	;		   ; and Half Buffer 1 will be played.)
  1308                              <1> 	
  1309                              <1> 	; FLAG
  1310                              <1> 	; (Half Buffer 1 has been completed
  1311                              <1> 	;  and Half Buffer 2 will be played.)
  1312                              <1> 
  1313                              <1> 	; 14/10/2017
  1314                              <1> 	;; (Continue to play.)
  1315                              <1> 	;mov	al, VIA_REG_CTRL_INT
  1316                              <1>        	;or	al, VIA_REG_CTRL_START
  1317                              <1>        	;mov	dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_CONTROL
  1318                              <1>         ;call	ctrl_io_w8
  1319                              <1> 	; 12/10/2017
  1320                              <1> 	;mov	byte [audio_flag], 1 
  1321                              <1> 
  1322                              <1> 	; 22/07/2020
  1323                              <1> 	;inc	byte [audio_flag] ; = 1
  1324                              <1> _ih2: 
  1325                              <1> 	; 10/10/2017
  1326 000142EC 8B3D[0C8F0100]      <1> 	mov	edi, [audio_dma_buff]
  1327                              <1> 	
  1328                              <1> 	; 05/06/2024
  1329                              <1> 	; 04/06/2024
  1330                              <1> 	;;mov	ecx, [audio_dmabuff_size]
  1331                              <1> 	;;shr	ecx, 1 ; dma buff size / 2 = half buffer size
  1332                              <1> 	;mov	ecx, [audio_buff_size]
  1333                              <1> 	;and	cl, ~1 ; word aligned
  1334                              <1> 	; 05/06/2024
  1335 000142F2 8B0D[148F0100]      <1> 	mov	ecx, [dma_hbuff_size] ; half buffer size
  1336                              <1> 
  1337                              <1> 	; 22/07/2020
  1338                              <1> 	; 12/10/2017
  1339                              <1> 	;cmp	byte [audio_flag], 0
  1340                              <1> 	;ja	short _ih3 ; Playing Half Buffer 2 (Current: FLAG)
  1341                              <1> 	
  1342                              <1> 	; 27/07/2020
  1343                              <1> 	; 22/07/2020
  1344 000142F8 F605[188F0100]01    <1> 	test	byte [audio_flag], 1  ; Current flag value
  1345 000142FF 7402                <1> 	jz	short _ih3 ; Half Buffer 1 must be filled
  1346                              <1> 
  1347                              <1> 	; Half Buffer 2 must be filled
  1348 00014301 01CF                <1> 	add	edi, ecx
  1349                              <1> _ih3:
  1350                              <1> 	; Update half buffer 2 while playing half buffer 1
  1351                              <1> 	; Update half buffer 1 while playing half buffer 2
  1352                              <1> 
  1353 00014303 8B35[048F0100]      <1> 	mov	esi, [audio_p_buffer] ; phy addr of audio buff
  1354                              <1> 	; 05/06/2024
  1355                              <1> 	;shr	ecx, 2 ; half buff size / 4
  1356                              <1> 	;rep	movsd
  1357 00014309 D1E9                <1> 	shr	ecx, 1	; word aligned buffer
  1358 0001430B F366A5              <1> 	rep	movsw
  1359                              <1> 
  1360                              <1> 	; switch flag value ;
  1361 0001430E 8035[188F0100]01    <1> 	xor	byte [audio_flag], 1
  1362                              <1> 	; 12/10/2017
  1363                              <1> 	; [audio_flag] = 0 : Playing dma half buffer 2
  1364                              <1> 			   ; Next buffer (to update) is dma half buff 1
  1365                              <1> 	; 	       = 1 : Playing dma half buffer 1
  1366                              <1> 			   ; Next buffer (to update) is dma half buff 2
  1367                              <1> _ih4:	
  1368                              <1> 	; 28/05/2017
  1369                              <1> 	;mov	byte [audio_busy], 0 ; 09/10/2017
  1370                              <1> 	;
  1371                              <1> 	;pop	edi
  1372                              <1> 	;pop	esi
  1373                              <1> 	;pop	ebx ; * must be restored !
  1374                              <1> 	;pop	ecx
  1375                              <1> 	;pop	edx
  1376                              <1> 	;pop	eax ; * must be restored !
  1377                              <1> 
  1378 00014315 C3                  <1> 	retn
  1379                              <1> 
  1380                              <1> channel_reset:
  1381                              <1> 	; 06/08/2022 - TRDOS 386 Kernel v2.0.5
  1382                              <1> 	; 24/06/2017
  1383                              <1> 	; 29/05/2017
  1384                              <1> 	; 23/03/2017
  1385                              <1> 	; 14/11/2016 - Erdogan Tan
  1386                              <1> 	; 12/11/2016 - Erdogan Tan (Ref: KolibriOS, vt823x.asm)
  1387                              <1>         ;mov	edx, VIA_REG_OFFSET_CONTROL
  1388                              <1> 	; 06/08/2022
  1389 00014316 29D2                <1> 	sub	edx, edx
  1390 00014318 B201                <1> 	mov	dl, VIA_REG_OFFSET_CONTROL 
  1391                              <1> 	;mov	eax, VIA_REG_CTRL_PAUSE + VIA_REG_CTRL_TERMINATE + VIA_REG_CTRL_RESET
  1392 0001431A B848000000          <1>         mov	eax, VIA_REG_CTRL_PAUSE + VIA_REG_CTRL_TERMINATE ; 24/06/2017
  1393 0001431F E8A2FEFFFF          <1> 	call    ctrl_io_w8
  1394                              <1> 
  1395                              <1>         ;mov	edx, VIA_REG_OFFSET_CONTROL
  1396                              <1>         ;call   ctrl_io_r8
  1397                              <1> 
  1398                              <1> 	; wait for 50 ms
  1399                              <1> 	;mov	ecx, 160 ; (200*0.25 ms) ; 29/05/2017
  1400                              <1> 	; 06/08/2022
  1401 00014324 31C9                <1> 	xor	ecx, ecx
  1402 00014326 B1A0                <1> 	mov	cl, 160
  1403                              <1> _ch_rst_wait:
  1404 00014328 E861FEFFFF          <1> 	call	delay1_4ms
  1405 0001432D 49                  <1> 	dec	ecx
  1406 0001432E 75F8                <1> 	jnz	short _ch_rst_wait
  1407                              <1> 
  1408                              <1>         ; disable interrupts
  1409                              <1> 	;mov	edx, VIA_REG_OFFSET_CONTROL
  1410                              <1>         ; 06/08/2022
  1411 00014330 29D2                <1> 	sub	edx, edx
  1412 00014332 B201                <1> 	mov	dl, VIA_REG_OFFSET_CONTROL
  1413 00014334 31C0                <1>  	xor     eax, eax
  1414 00014336 E88BFEFFFF          <1>         call    ctrl_io_w8
  1415                              <1> 
  1416                              <1>         ; clear interrupts
  1417                              <1>         ;mov	edx, VIA_REG_OFFSET_STATUS
  1418                              <1> 	; 06/08/2022
  1419 0001433B 29D2                <1> 	sub	edx, edx
  1420                              <1> 	;mov	dl, VIA_REG_OFFSET_STATUS ; 0
  1421                              <1> 	; edx = 0
  1422                              <1> 	;mov	eax, 3
  1423                              <1>         ; 06/08/2022
  1424 0001433D 29C0                <1> 	sub	eax, eax
  1425 0001433F B003                <1> 	mov	al, 3
  1426                              <1> 	; eax = 3
  1427 00014341 E880FEFFFF          <1> 	call	ctrl_io_w8
  1428                              <1> 
  1429                              <1> 	;mov	edx, VIA_REG_OFFSET_CURR_PTR
  1430                              <1> 	;xor	eax, eax
  1431                              <1> 	;call	ctrl_io_w32
  1432                              <1> 
  1433 00014346 C3                  <1>         retn	
  1434                              <1> 
  1435                              <1> vt8233_stop: ; 22/04/2017
  1436 00014347 C605[268F0100]00    <1> 	mov	byte [audio_play_cmd], 0 ; stop !
  1437                              <1> _tlp2:
  1438                              <1> 	; 24/06/2017
  1439                              <1>         ; finished with song, stop everything
  1440                              <1> 	;mov	al, VIA_REG_CTRL_INT
  1441                              <1>         ;or	al, VIA_REG_CTRL_TERMINATE
  1442                              <1> 	;mov	dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_CONTROL
  1443                              <1>         ;call	ctrl_io_w8
  1444                              <1> 
  1445                              <1>         ;call	channel_reset
  1446                              <1> 	;retn
  1447                              <1> 
  1448 0001434E EBC6                <1> 	jmp	short channel_reset
  1449                              <1> 
  1450                              <1> set_vt8233_bdl: ; Set VT8237R Buffer Descriptor List
  1451                              <1> 	; 04/06/2024 - TRDOS 386 v2.0.8
  1452                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  1453                              <1> 	; 22/07/2020 - TRDOS 386 v2.0.2
  1454                              <1> 	; 28/05/2017
  1455                              <1> 	; 21/04/2017 (TRDOS 386 kernel, 'audio.s')
  1456                              <1> 	; 24/03/2017 - 'PLAYER.COM' ('via_wav.asm' - 29/11/2016)
  1457                              <1> 	
  1458                              <1> 	; eax = dma buffer address = [audio_DMA_buff]
  1459                              <1> 	; ecx = dma buffer buffer size = [audio_dmabuff_size]
  1460                              <1> 
  1461                              <1> 	; 04/06/2024
  1462                              <1> 	; ecx = DMA half buffer size (same as audio buffer size)
  1463                              <1> 
  1464                              <1> 	;shr	ecx, 1 ; dma half buffer size
  1465 00014350 89CE                <1> 	mov	esi, ecx
  1466                              <1> 
  1467 00014352 BF[308F0100]        <1>         mov     edi, audio_bdl_buff	; get BDL address
  1468                              <1> 	;mov	ecx, 32 / 2		; make 32 entries in BDL
  1469                              <1> 	; 06/08/2022
  1470 00014357 29C9                <1> 	sub	ecx, ecx
  1471 00014359 B110                <1> 	mov	cl, 16
  1472                              <1> 
  1473 0001435B EB05                <1> 	jmp	short s_vt8233_bdl1 
  1474                              <1> 
  1475                              <1> s_vt8233_bdl0:
  1476                              <1> 	; set buffer descriptor 0 to start of data file in memory
  1477                              <1> 
  1478 0001435D A1[0C8F0100]        <1>  	mov	eax, [audio_dma_buff]	; Physical address of DMA buffer
  1479                              <1>  
  1480                              <1> s_vt8233_bdl1:
  1481 00014362 AB                  <1> 	stosd				; store dmabuffer1 address
  1482                              <1> 
  1483 00014363 89C2                <1> 	mov	edx, eax
  1484                              <1> 
  1485                              <1> ; VIA VT8235.PDF: (Page 110) (Erdogan Tan, 29/11/2016)
  1486                              <1> 	;
  1487                              <1> 	; 	Audio SGD Table Format
  1488                              <1> 	;	-------------------------------
  1489                              <1> 	;	63   62    61-56    55-32  31-0
  1490                              <1> 	;	--   --   --------  -----  ----
  1491                              <1> 	;	EOL FLAG -reserved- Base   Base
  1492                              <1> 	;		    	    Count  Address
  1493                              <1> 	;		            [23:0] [31:0]
  1494                              <1> 	;	EOL: End Of Link. 
  1495                              <1> 	;	     1 indicates this block is the last of the link.
  1496                              <1> 	;	     If the channel Interrupt on EOL bit is set, then
  1497                              <1> 	;	     an interrupt is generated at the end of the transfer.
  1498                              <1> 	;
  1499                              <1> 	;	FLAG: Block Flag. If set, transfer pauses at the end of this
  1500                              <1> 	;	      block. If the channel Interrupt on FLAG bit is set,
  1501                              <1> 	;	      then an interrupt is generated at the end of this block.
  1502                              <1> 
  1503 00014365 89F0                <1> 	mov	eax, esi ; DMA half buffer size
  1504                              <1> 
  1505                              <1> 		; 04/06/2024 - Erdogan Tan
  1506                              <1> 		; NOTE: I have changed DMA half buffer size to
  1507                              <1> 		; (word aligned) audio buffer size for smooth audio playing
  1508                              <1> 		; (it was page border aligned before June 4, 2024)
  1509                              <1> 		;
  1510                              <1> 		; For example:
  1511                              <1> 		;    For 65416 bytes audio buffer (22kHz, 16bit samples)
  1512                              <1> 		;       (user's audio buff virtual addr is mapped to physical)
  1513                              <1> 		;	((kernel's and user's audio buff pages are same)) 
  1514                              <1> 		;    1) Memory allocation (of it) is 65536 bytes
  1515                              <1> 		;    2) DMA half buffer size is 65416 bytes
  1516                              <1> 		;	(it would be 65536 bytes before this modification)
  1517                              <1> 		;	((additional 140 bytes would cause to a noise))	     
  1518                              <1> 		;    3) Total DMA buffer size is 131072 bytes
  1519                              <1> 		;       (the last 240 bytes will not be used for playing)
  1520                              <1> 
  1521 00014367 01C2                <1> 	add	edx, eax
  1522 00014369 0D00000040          <1> 	or	eax, FLAG
  1523                              <1> 	;or	eax, EOL
  1524 0001436E AB                  <1> 	stosd
  1525                              <1> 
  1526                              <1> ; 2nd buffer:
  1527                              <1> 
  1528 0001436F 89D0                <1>         mov	eax, edx ; Physical address of the 2nd half of DMA buffer
  1529 00014371 AB                  <1> 	stosd		 ; store dmabuffer2 address
  1530                              <1> 
  1531                              <1> ; set length to [audio_dmabuff_size]/2
  1532                              <1> ; Set control (bits 31:16) to BUP, bits 15:0=number of samples
  1533                              <1> ; 
  1534 00014372 89F0                <1> 	mov	eax, esi ; DMA half buffer size
  1535                              <1> 	; 22/07/2020
  1536                              <1> 	;or	eax, EOL
  1537 00014374 0D00000040          <1> 	or	eax, FLAG
  1538 00014379 AB                  <1> 	stosd
  1539                              <1> 
  1540 0001437A E2E1                <1> 	loop    s_vt8233_bdl0
  1541                              <1> 
  1542                              <1> 	; 22/07/2020
  1543 0001437C 814FFC00000080      <1> 	or	dword [edi-4], EOL
  1544                              <1> 	
  1545 00014383 C3                  <1> 	retn
  1546                              <1> 
  1547                              <1> vt8233_start_play:
  1548                              <1> 	; 06/08/2022 - TRDOS 386 Kernel v2.0.5
  1549                              <1> 	; 01/09/2020
  1550                              <1> 	; 22/07/2020
  1551                              <1> 	; start to play audio data via VT8233 audio controller
  1552                              <1> 	; 13/06/2017
  1553                              <1> 	; 10/06/2017
  1554                              <1> 	; 24/04/2017
  1555                              <1> 	; 21/04/2017 (TRDOS 386 kernel, 'audio.s')
  1556                              <1> 	; 24/03/2017 - 'PLAYER.COM' ('via_wav.asm' - 29/11/2016)
  1557                              <1> 	; write buffer descriptor list address
  1558                              <1> 
  1559                              <1> 	; Extended Audio Status (2Ah)
  1560 00014384 B82A000000          <1> 	mov	eax, CODEC_EXT_AUDIO_CTRL_REG ; 2Ah
  1561 00014389 E85CFEFFFF          <1> 	call	codec_read
  1562 0001438E 25FDFF0000          <1> 	and     eax, 0FFFFh - 2		; clear DRA (BIT1)
  1563                              <1> 	;or     eax, 1			; set VRA (BIT0)
  1564                              <1> 	;or	eax, 5  	; VRA (BIT0) & S/PDIF (BIT2) ; 14/11/2016
  1565 00014393 0C05                <1> 	or	al, 5
  1566                              <1> 	; 01/09/2020
  1567                              <1> 	;or	eax, 3805h ; AD1980 (PRK, PRJ, PRI = 1 .. only front DAC)
  1568                              <1> 	; 01/09/2020
  1569                              <1> 	;mov	edx, CODEC_EXT_AUDIO_CTRL_REG
  1570                              <1> 	;cmp	word [audio_freq], 0BB80h ; 48 kHz
  1571                              <1> 	;jne	short set_extd_audio_status_1
  1572                              <1> 	;and	al, 0FEh ; disable VRA bit (set sample rate to 48000 Hz)
  1573                              <1> 	;jmp	short set_extd_audio_status_2
  1574                              <1> ;set_extd_audio_status_1:
  1575 00014395 BA2A000000          <1> 	mov	edx, CODEC_EXT_AUDIO_CTRL_REG
  1576 0001439A E86EFEFFFF          <1> 	call	codec_write
  1577                              <1> 	;jc	short cconfig_error
  1578                              <1> 
  1579                              <1> set_sample_rate:
  1580                              <1> 	;movzx	eax, word [audio_freq]
  1581 0001439F 66A1[228F0100]      <1> 	mov	ax, [audio_freq]
  1582 000143A5 BA2C000000          <1> 	mov	edx, CODEC_PCM_FRONT_DACRATE_REG ; 2Ch ; PCM Front DAC Rate
  1583                              <1> ;set_extd_audio_status_2:
  1584 000143AA E85EFEFFFF          <1> 	call	codec_write
  1585                              <1> 
  1586                              <1> 	; 01/09/2020
  1587                              <1> 	; set AD1980 MCB register (Index 76h) to 0C00h
  1588                              <1> 	; (CLDIS, HPSEL)
  1589                              <1> 	;mov	ax, 0C00h
  1590                              <1> 	;mov	edx, CODEC_MISC_CRTL_BITS_REG ; 76h 
  1591                              <1> 	;			; Miscellaneous Control Bit Register
  1592                              <1> 	;call	codec_write
  1593                              <1> 	;
  1594                              <1> 
  1595 000143AF B8[308F0100]        <1>         mov	eax, audio_bdl_buff
  1596                              <1>   
  1597                              <1> 	; 12/11/2016 - Erdogan Tan 
  1598                              <1> 	; (Ref: KolibriOS, vt823x.asm, 'create_primary_buff')
  1599                              <1> 	;mov	edx, VIADEV_PLAYBACK + VIA_REG_OFFSET_TABLE_PTR
  1600                              <1>         ; 06/08/2022
  1601 000143B4 29D2                <1> 	sub	edx, edx
  1602                              <1> 	;mov	dl, VIADEV_PLAYBACK + VIA_REG_OFFSET_TABLE_PTR
  1603                              <1> 	; edx = 0
  1604 000143B6 E81DFEFFFF          <1> 	call	ctrl_io_w32
  1605                              <1> 
  1606                              <1> 	;call	codec_check_ready
  1607                              <1> 
  1608 000143BB 66BA0200            <1>   	mov	dx, VIADEV_PLAYBACK + VIA_REG_OFS_PLAYBACK_VOLUME_L
  1609                              <1>         ;mov	eax, 2	; 31
  1610 000143BF B01F                <1> 	mov	al, 31
  1611 000143C1 2A05[288F0100]      <1>         sub	al, [audio_master_volume_l]
  1612 000143C7 E8FAFDFFFF          <1> 	call	ctrl_io_w8
  1613                              <1> 
  1614                              <1> 	;call	codec_check_ready
  1615                              <1> 
  1616 000143CC 66BA0300            <1>         mov     dx, VIADEV_PLAYBACK + VIA_REG_OFS_PLAYBACK_VOLUME_R
  1617                              <1>         ;mov	ax, 2	; 31
  1618 000143D0 B01F                <1> 	mov	al, 31
  1619 000143D2 2A05[298F0100]      <1>         sub	al, [audio_master_volume_r]
  1620 000143D8 E8E9FDFFFF          <1> 	call    ctrl_io_w8
  1621                              <1> 
  1622                              <1> 	;call	codec_check_ready
  1623                              <1> ;
  1624                              <1> ;
  1625                              <1> ; All set. Let's play some music.
  1626                              <1> ;
  1627                              <1> ;
  1628                              <1>        	;mov    dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STOP_IDX
  1629                              <1>         ;mov    ax, VIA8233_REG_TYPE_16BIT or VIA8233_REG_TYPE_STEREO or 0xfffff or 0xff000000
  1630                              <1>         ;call   ctrl_io_w32
  1631                              <1> 
  1632                              <1> 	;call	codec_check_ready
  1633                              <1> 
  1634                              <1> 	; 08/12/2016
  1635                              <1> 	; 07/10/2016
  1636                              <1>         ;;mov    al, 1
  1637                              <1>         ;mov	al, 31
  1638                              <1> 	; 22/07/2020
  1639 000143DD B0FF                <1> 	mov	al, 0FFh
  1640 000143DF E813000000          <1> 	call    set_VT8233_LastValidIndex
  1641                              <1> 
  1642 000143E4 C605[268F0100]01    <1> 	mov	byte [audio_play_cmd], 1 ; play command (do not stop) !
  1643                              <1> 
  1644                              <1> 	; 22/07/2020
  1645                              <1> 	;mov	byte [audio_flag], 0  ; clear half buffer flag
  1646                              <1> 
  1647                              <1> vt8233_play: ; continue to play
  1648                              <1> 	; 22/04/2017
  1649                              <1> 	;mov	al, VIA_REG_CTRL_INT
  1650                              <1>        	;or	al, VIA_REG_CTRL_START
  1651                              <1>         ;;mov	al, VIA_REG_CTRL_AUTOSTART + VIA_REG_CTRL_START
  1652                              <1> 	; 22/07/2020	
  1653 000143EB B0A1                <1> 	mov	al, VIA_REG_CTRL_AUTOSTART + VIA_REG_CTRL_START + VIA_REG_CTRL_INT_FLAG
  1654                              <1> 
  1655 000143ED 66BA0100            <1> 	mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_CONTROL
  1656 000143F1 E8D0FDFFFF          <1>         call    ctrl_io_w8
  1657                              <1> 	;call	codec_check_ready
  1658                              <1> 	;retn
  1659                              <1> 	;jmp	codec_check_ready
  1660 000143F6 C3                  <1> 	retn
  1661                              <1> 
  1662                              <1> ;input AL = index # to stop on
  1663                              <1> set_VT8233_LastValidIndex:
  1664                              <1> 	; 06/08/2022 - TRDOS 386 Kernel v2.0.5
  1665                              <1> 	; 23/07/2020
  1666                              <1> 	; 10/06/2017
  1667                              <1> 	; 21/04/2017 (TRDOS 386 kernel, 'audio.s')
  1668                              <1> 	; 24/03/2017 - 'PLAYER.COM' ('via_wav.asm' - 29/11/2016) 
  1669                              <1> 	; 19/11/2016
  1670                              <1> 	; 14/11/2016 - Erdogan Tan (Ref: VIA VT8235.PDF, Page 110)
  1671                              <1> 	; 12/11/2016 - Erdogan Tan
  1672                              <1> 	; (Ref: KolibriOS, vt823x.asm, 'create_primary_buff')
  1673                              <1> 	;push	edx
  1674                              <1> 	;push	ax
  1675 000143F7 50                  <1> 	push	eax ; 23/07/2020
  1676                              <1> 	;push	ecx
  1677 000143F8 0FB705[228F0100]    <1> 	movzx	eax, word [audio_freq] ; Hertz
  1678 000143FF BA00001000          <1> 	mov	edx, 100000h ; 2^20 = 1048576
  1679 00014404 F7E2                <1> 	mul	edx
  1680 00014406 B980BB0000          <1> 	mov	ecx, 48000
  1681 0001440B F7F1                <1> 	div	ecx
  1682                              <1> 	;and	eax, 0FFFFFh
  1683                              <1> 	;pop	ecx
  1684                              <1> 	;pop	dx 
  1685 0001440D 5A                  <1> 	pop	edx ; 23/07/2020
  1686 0001440E C1E218              <1> 	shl	edx, 24  ; STOP Index Setting: Bit 24 to 31
  1687 00014411 09D0                <1> 	or	eax, edx
  1688                              <1> 	; 19/11/2016
  1689 00014413 803D[208F0100]10    <1> 	cmp	byte [audio_bps], 16
  1690 0001441A 7505                <1> 	jne	short sLVI_1
  1691 0001441C 0D00002000          <1> 	or	eax, VIA8233_REG_TYPE_16BIT
  1692                              <1> sLVI_1:
  1693 00014421 803D[218F0100]02    <1> 	cmp	byte [audio_stmo], 2
  1694 00014428 7505                <1> 	jne	short sLVI_2
  1695 0001442A 0D00001000          <1> 	or	eax, VIA8233_REG_TYPE_STEREO
  1696                              <1> sLVI_2:
  1697                              <1> 	;mov	edx, VIADEV_PLAYBACK + VIA_REG_OFFSET_STOP_IDX
  1698                              <1> 	; 06/08/2022
  1699 0001442F 29D2                <1> 	sub	edx, edx
  1700 00014431 B208                <1> 	mov	dl, VIADEV_PLAYBACK + VIA_REG_OFFSET_STOP_IDX
  1701 00014433 E8A0FDFFFF          <1> 	call    ctrl_io_w32
  1702                              <1> 	;call	codec_check_ready
  1703                              <1> 	;pop	edx
  1704 00014438 C3                  <1> 	retn
  1705                              <1> 
  1706                              <1> vt8233_pause: ; pause
  1707                              <1> 	; 10/06/2017
  1708                              <1> 	; 22/04/2017
  1709                              <1> 	;mov	al, VIA_REG_CTRL_INT
  1710                              <1>         ;or	al, VIA_REG_CTRL_PAUSE
  1711                              <1> 	; 23/07/2020
  1712 00014439 B029                <1> 	mov	al, VIA_REG_CTRL_PAUSE+VIA_REG_CTRL_INT_FLAG+VIA_REG_CTRL_AUTOSTART
  1713                              <1> 	
  1714 0001443B 66BA0100            <1> 	mov     dx, VIADEV_PLAYBACK + VIA_REG_OFFSET_CONTROL
  1715 0001443F E882FDFFFF          <1>         call    ctrl_io_w8
  1716                              <1> 	;call	codec_check_ready
  1717                              <1> 	;retn
  1718                              <1> 	;jmp	codec_check_ready
  1719 00014444 C3                  <1> 	retn
  1720                              <1> 
  1721                              <1> vt8233_reset:
  1722                              <1> 	; 22/04/2017
  1723                              <1> 	; reset VT8237R (vt8233) Audio Controller
  1724                              <1> 	;cmp	byte [audio_play_cmd], 1
  1725                              <1> 	;jna	short vt8233_rst_0
  1726 00014445 C605[268F0100]00    <1> 	mov	byte [audio_play_cmd], 0 ; stop !
  1727                              <1> vt8233_rst_0:
  1728 0001444C E8DAFCFFFF          <1> 	call	reset_codec
  1729 00014451 720A                <1> 	jc	short vt8233_rst_1 ; codec error !
  1730                              <1> 	; eax = 1
  1731 00014453 E852FDFFFF          <1> 	call	codec_io_w16 ; w32
  1732 00014458 E8B9FEFFFF          <1> 	call	channel_reset
  1733                              <1> vt8233_rst_1:
  1734                              <1> vt8233_vol_1:	; 06/08/2022
  1735 0001445D C3                  <1> 	retn
  1736                              <1> 
  1737                              <1> vt8233_volume:
  1738                              <1> 	; set VT8237R (vt8233) sound volume level
  1739                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  1740                              <1> 	; 24/04/2017
  1741                              <1> 	; 22/04/2017
  1742                              <1> 	; bl = component (0 = master/playback/lineout volume)
  1743                              <1> 	; cl = left channel volume level (0 to 31)
  1744                              <1> 	; ch = right channel volume level (0 to 31)
  1745                              <1> 
  1746 0001445E 08DB                <1> 	or	bl, bl
  1747 00014460 75FB                <1> 	jnz	short vt8233_vol_1 ; temporary !
  1748 00014462 66B81F1F            <1> 	mov	ax, 1F1Fh ; 31,31
  1749 00014466 38C1                <1> 	cmp	cl, al
  1750 00014468 77F3                <1> 	ja	short vt8233_vol_1 ; temporary !
  1751 0001446A 38E5                <1> 	cmp	ch, ah
  1752 0001446C 77EF                <1> 	ja	short vt8233_vol_1 ; temporary !
  1753 0001446E 66890D[288F0100]    <1> 	mov	[audio_master_volume], cx
  1754 00014475 6629C8              <1> 	sub	ax, cx
  1755                              <1> 	;mov	edx, CODEC_MASTER_VOL_REG ; 02h ; Line Out
  1756                              <1> 	; 06/08/2022
  1757 00014478 29D2                <1> 	sub	edx, edx
  1758 0001447A B202                <1> 	mov	dl, CODEC_MASTER_VOL_REG ; 02h ; Line Out
  1759                              <1> 	; 06/08/2022
  1760 0001447C E98CFDFFFF          <1> 	jmp	codec_write
  1761                              <1> 	;call	codec_write
  1762                              <1> ;vt8233_vol_1:
  1763                              <1> 	;retn
  1764                              <1> 
  1765                              <1> ; CODE for SOUND BLASTER 16
  1766                              <1> 
  1767                              <1> DetectSB:
  1768                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  1769                              <1> 	; 24/04/2017
  1770                              <1> 	;pushad
  1771                              <1> ScanPort:
  1772                              <1> 	; 06/08/2022
  1773 00014481 66BB1002            <1> 	mov	bx, 0210h	; start scanning ports
  1774                              <1> 				; 210h, 220h, .. 260h
  1775                              <1> 	; 06/08/2022
  1776 00014485 31C9                <1> 	xor	ecx, ecx
  1777 00014487 88FE                <1> 	mov	dh, bh
  1778                              <1> ResetDSP:       
  1779                              <1> 	;mov	dx, bx		; try to reset the DSP.
  1780                              <1> 	;add	dx, 06h
  1781                              <1> 	; 06/08/2022
  1782 00014489 88DA                <1> 	mov	dl, bl
  1783 0001448B 80C206              <1> 	add	dl, 06h
  1784                              <1> 
  1785 0001448E B001                <1> 	mov	al, 1
  1786 00014490 EE                  <1> 	out	dx, al
  1787                              <1> 
  1788 00014491 EC                  <1> 	in	al, dx
  1789 00014492 EC                  <1> 	in	al, dx
  1790 00014493 EC                  <1> 	in	al, dx
  1791 00014494 EC                  <1> 	in	al, dx
  1792                              <1> 
  1793 00014495 30C0                <1> 	xor     al, al
  1794 00014497 EE                  <1> 	out	dx, al
  1795                              <1> 
  1796                              <1> 	;add	dx, 08h
  1797                              <1> 	; 06/08/2022
  1798 00014498 80C208              <1> 	add	dl, 08h
  1799                              <1> 	;mov	cx, 100
  1800 0001449B B164                <1> 	mov	cl, 100
  1801                              <1> WaitID:
  1802 0001449D EC                  <1> 	in	al, dx
  1803 0001449E 08C0                <1> 	or      al, al
  1804 000144A0 7804                <1> 	js      short GetID
  1805 000144A2 E2F9                <1> 	loop    WaitID
  1806 000144A4 EB0D                <1> 	jmp     short NextPort
  1807                              <1> GetID:          
  1808                              <1> 	;sub	dx, 04h
  1809                              <1> 	; 06/08/2022
  1810 000144A6 80EA04              <1> 	sub	dl, 04h
  1811 000144A9 EC                  <1> 	in	al, dx
  1812 000144AA 3CAA                <1> 	cmp     al, 0AAh
  1813 000144AC 740F                <1> 	je      short Found
  1814                              <1> 	;add	dx, 04h
  1815                              <1> 	; 06/08/2022
  1816 000144AE 80C204              <1> 	add	dl, 04h
  1817 000144B1 E2EA                <1> 	loop    WaitID
  1818                              <1> NextPort:
  1819                              <1> 	;add	bx, 10h		; if not response,
  1820                              <1> 	; 06/08/2022
  1821 000144B3 80C310              <1> 	add	bl, 10h
  1822                              <1> 	;cmp	bx, 260h	; try the next port.
  1823 000144B6 80FB60              <1> 	cmp	bl, 60h
  1824 000144B9 76CE                <1> 	jbe     short ResetDSP
  1825 000144BB F9                  <1> 	stc
  1826 000144BC C3                  <1> 	retn
  1827                              <1> Found:
  1828 000144BD 66891D[F28E0100]    <1> 	mov     [audio_io_base], bx	; SB Port Address Found!
  1829                              <1> ScanIRQ:
  1830                              <1> SetIrqs:
  1831 000144C4 28C0                <1> 	sub 	al, al ; 0
  1832 000144C6 A2[E88E0100]        <1> 	mov 	[IRQnum], al ; reset
  1833 000144CB A2[EE8E0100]        <1> 	mov	[audio_intr], al ; reset
  1834                              <1> 
  1835                              <1> 	; ah > 0 -> set IRQ vector
  1836                              <1> 	; al = IRQ number
  1837                              <1> 	;mov	ax, 103h ; IRQ 3
  1838                              <1> 	;call	set_hardware_int_vector
  1839                              <1> 	;mov	ax, 104h ; IRQ 4
  1840                              <1> 	;call	set_hardware_int_vector
  1841 000144D0 66B80501            <1> 	mov	ax, 105h ; IRQ 5
  1842 000144D4 E850DFFFFF          <1> 	call	set_hardware_int_vector
  1843 000144D9 66B80701            <1> 	mov	ax, 107h ; IRQ 7
  1844 000144DD E847DFFFFF          <1> 	call	set_hardware_int_vector
  1845                              <1> 
  1846 000144E2 668B15[F28E0100]    <1> 	mov     dx, [audio_io_base] ; tells to the SB to
  1847                              <1> 	;add	dx, 0Ch		    ; generate a IRQ!
  1848                              <1> 	; 06/08/2022
  1849 000144E9 80C20C              <1> 	add	dl, 0Ch
  1850                              <1> WaitSb:
  1851 000144EC EC                  <1> 	in	al, dx
  1852 000144ED 08C0                <1> 	or      al, al
  1853 000144EF 78FB                <1> 	js      short WaitSb
  1854 000144F1 B0F2                <1> 	mov     al, 0F2h
  1855 000144F3 EE                  <1> 	out	dx, al
  1856                              <1> 
  1857 000144F4 31C9                <1> 	xor     ecx, ecx	; wait until IRQ level
  1858                              <1> WaitIRQ: 
  1859 000144F6 A0[E88E0100]        <1> 	mov	al, [IRQnum]
  1860 000144FB 3C00                <1> 	cmp     al, 0 ; is changed or timeout.
  1861 000144FD 7706                <1> 	ja	short IrqOk
  1862 000144FF 6649                <1> 	dec	cx
  1863 00014501 75F3                <1> 	jnz	short WaitIRQ
  1864 00014503 EB14                <1> 	jmp	short RestoreIrqs
  1865                              <1> IrqOk:
  1866 00014505 A2[EE8E0100]        <1> 	mov	[audio_intr], al ; set
  1867 0001450A 668B15[F28E0100]    <1> 	mov     dx, [audio_io_base]
  1868                              <1> 	;add	dx, 0Eh
  1869                              <1> 	; 06/08/2022
  1870 00014511 80C20E              <1> 	add	dl, 0Eh
  1871 00014514 EC                  <1> 	in	al, dx	; SB acknowledge.
  1872 00014515 B020                <1> 	mov	al, 20h
  1873 00014517 E620                <1> 	out	20h, al	; Hardware acknowledge.
  1874                              <1> 
  1875                              <1> RestoreIrqs:
  1876                              <1> 	; ah = 0 -> reset IRQ vector
  1877                              <1> 	; al = IRQ number
  1878                              <1> 	;mov	ax, 3 ; IRQ 3
  1879                              <1> 	;call	set_hardware_int_vector
  1880                              <1> 	;mov	ax, 4 ; IRQ 4
  1881                              <1> 	;call	set_hardware_int_vector
  1882 00014519 66B80500            <1> 	mov	ax, 5 ; IRQ 5
  1883 0001451D E807DFFFFF          <1> 	call	set_hardware_int_vector
  1884 00014522 66B80700            <1> 	mov	ax, 7 ; IRQ 7
  1885 00014526 E8FEDEFFFF          <1> 	call	set_hardware_int_vector
  1886                              <1> 
  1887 0001452B 31D2                <1> 	xor	edx, edx
  1888 0001452D 8915[F48E0100]      <1> 	mov	[audio_dev_id], edx ; 0
  1889 00014533 8915[F88E0100]      <1> 	mov	[audio_vendor], edx ; 0
  1890                              <1> 	; 22/11/2023
  1891                              <1> 	;mov	[audio_stats_cmd], edx ; 0
  1892                              <1> 
  1893                              <1> 	;popad
  1894                              <1> 
  1895 00014539 803D[EE8E0100]01    <1> 	cmp     byte [audio_intr], 1 ; IRQ level was changed?
  1896                              <1> 	
  1897 00014540 C3                  <1> 	retn
  1898                              <1> 
  1899                              <1> %macro	SbOut	1
  1900                              <1> %%Wait:
  1901                              <1> 	in	al, dx
  1902                              <1> 	or	al, al
  1903                              <1> 	js	short %%Wait
  1904                              <1> 	mov	al, %1
  1905                              <1> 	out	dx, al
  1906                              <1> %endmacro
  1907                              <1> 
  1908                              <1> SbInit_play:
  1909                              <1> 	; 06/08/2022 - TRDOS 386 Kernel v2.0.5
  1910                              <1> 	; 22/10/2017
  1911                              <1> 	; 20/10/2017
  1912                              <1> 	; 06/10/2017
  1913                              <1> 	; 13/07/2017 - 09/08/2017
  1914                              <1> 	; 24/04/2017 - 15/05/2017 - 24/06/2017
  1915                              <1> 	;pushad
  1916                              <1> SetBuffer:
  1917                              <1> 	;mov	byte [DmaFlag], 0
  1918                              <1> 
  1919 00014541 8B1D[0C8F0100]      <1> 	mov	ebx, [audio_dma_buff] ; physical addr of DMA buff
  1920 00014547 89DF                <1> 	mov	edi, ebx
  1921 00014549 8B0D[108F0100]      <1> 	mov     ecx, [audio_dmabuff_size]
  1922                              <1> 
  1923 0001454F 803D[208F0100]10    <1> 	cmp	byte [audio_bps], 16
  1924 00014556 7531                <1> 	jne	short sbInit_0 ; set 8 bit DMA buffer
  1925                              <1> 	
  1926                              <1> 	; 09/08/2017
  1927                              <1> 	; convert byte count to word count
  1928 00014558 D1E9                <1> 	shr	ecx, 1
  1929 0001455A 49                  <1> 	dec	ecx ; word count - 1
  1930                              <1> 	; convert byte offset to word offset
  1931 0001455B D1EB                <1> 	shr	ebx, 1
  1932                              <1> 
  1933                              <1> 	; 16 bit DMA buffer setting (DMA channel 5)
  1934 0001455D B005                <1> 	mov     al, 05h  ; set mask bit for channel 5  (4+1)
  1935 0001455F E6D4                <1> 	out	0D4h, al
  1936                              <1> 	
  1937 00014561 30C0                <1> 	xor     al, al   ; stops all DMA processes on selected channel
  1938 00014563 E6D8                <1> 	out	0D8h, al ; clear selected channel register
  1939                              <1> 
  1940 00014565 88D8                <1> 	mov     al, bl	 ; byte 0 of DMA buffer offset in words (physical)
  1941 00014567 E6C4                <1> 	out	0C4h, al ; DMA channel 5 port number
  1942                              <1> 
  1943 00014569 88F8                <1> 	mov     al, bh   ; byte 1 of DMA buffer offset in words (physical)
  1944 0001456B E6C4                <1> 	out	0C4h, al
  1945                              <1> 	
  1946                              <1> 	; 09/08/2017
  1947 0001456D C1EB0F              <1> 	shr	ebx, 15	 ; complete 16 bit shift
  1948 00014570 80E3FE              <1> 	and	bl, 0FEh ; clear bit 0 (not necessary, it will be ignored)
  1949                              <1> 
  1950 00014573 88D8                <1> 	mov     al, bl   ; byte 2 of DMA buffer address (physical)
  1951 00014575 E68B                <1> 	out	8Bh, al  ; page register port addr for channel 5 ; 13/07/2017
  1952                              <1> 
  1953 00014577 88C8                <1> 	mov     al, cl   ; low byte of DMA count - 1
  1954 00014579 E6C6                <1> 	out	0C6h, al ; count register port addr for channel 1
  1955                              <1> 
  1956 0001457B 88E8                <1> 	mov     al, ch   ; high byte of DMA count - 1
  1957 0001457D E6C6                <1> 	out	0C6h, al
  1958                              <1> 
  1959                              <1> 	; channel 5, read, autoinitialized, single mode
  1960                              <1> 	;mov	al, 49h
  1961 0001457F B059                <1> 	mov	al, 59h  ; 06/10/2017 
  1962 00014581 E6D6                <1> 	out	0D6h, al ; DMA mode register port address
  1963                              <1> 
  1964 00014583 B001                <1> 	mov     al, 01h  ; clear mask bit for channel 1
  1965 00014585 E6D4                <1> 	out	0D4h, al ; DMA mask register port address
  1966                              <1> 
  1967 00014587 EB28                <1> 	jmp	short ClearBuffer
  1968                              <1> 
  1969                              <1> sbInit_0:    
  1970 00014589 49                  <1> 	dec     ecx	; 09/08/2017
  1971                              <1> 
  1972                              <1> 	; 8 bit DMA buffer setting (DMA channel 1)
  1973 0001458A B005                <1> 	mov     al, 05h ; set mask bit for channel 1  (4+1)
  1974 0001458C E60A                <1> 	out	0Ah, al ; DMA mask register
  1975                              <1> 
  1976 0001458E 30C0                <1> 	xor     al, al  ; stops all DMA processes on selected channel
  1977 00014590 E60C                <1> 	out	0Ch, al ; clear selected channel register
  1978                              <1> 
  1979 00014592 88D8                <1> 	mov     al, bl	; byte 0 of DMA buffer address (physical)
  1980 00014594 E602                <1> 	out	02h, al ; DMA channel 1 port number
  1981                              <1> 
  1982 00014596 88F8                <1> 	mov     al, bh  ; byte 1 of DMA buffer address (physical)
  1983 00014598 E602                <1> 	out	02h, al
  1984                              <1> 
  1985 0001459A C1EB10              <1> 	shr	ebx, 16
  1986                              <1> 
  1987 0001459D 88D8                <1> 	mov     al, bl  ; byte 2 of DMA buffer address (physical)
  1988 0001459F E683                <1> 	out	83h, al ; page register port addr for channel 1
  1989                              <1> 
  1990 000145A1 88C8                <1> 	mov     al, cl  ; low byte of DMA count - 1
  1991 000145A3 E603                <1> 	out	03h, al ; count register port addr for channel 1
  1992                              <1> 
  1993 000145A5 88E8                <1> 	mov     al, ch  ; high byte of DMA count - 1
  1994 000145A7 E603                <1> 	out	03h, al
  1995                              <1> 
  1996                              <1> 	; channel 1, read, autoinitialized, single mode
  1997                              <1> 	;mov	al, 49h
  1998 000145A9 B059                <1> 	mov	al, 59h ; 06/10/2017 
  1999 000145AB E60B                <1> 	out	0Bh, al ; DMA mode register port address
  2000                              <1> 
  2001 000145AD B001                <1> 	mov     al, 01h ; clear mask bit for channel 1
  2002 000145AF E60A                <1> 	out	0Ah, al ; DMA mask register port address
  2003                              <1> 
  2004                              <1> ClearBuffer:
  2005                              <1> 	;;mov	edi, [audio_dma_buff]
  2006                              <1> 	;;mov	ecx, [audio_dmabuff_size]
  2007                              <1> 	;inc	ecx
  2008                              <1> 	;mov	al, 80h
  2009                              <1> 	;;cld
  2010                              <1> 	;rep	stosb
  2011                              <1> SetIrq:
  2012                              <1> 	;mov	ebx, SbIrqhandler
  2013                              <1> 	;mov	al, [audio_intr] ; IRQ number
  2014                              <1> 	;call	set_dev_IRQ_service
  2015                              <1> 	;; SETUP (audio) INTERRUPT CALLBACK SERVICE
  2016                              <1> 	;mov	bl, [audio_intr] ; IRQ number
  2017                              <1> 	;mov	bh, [audio_cb_mode]
  2018                              <1> 	;inc	bh  ; 1 = Signal Response Byte method (fixed value)
  2019                              <1> 	;	    ; 2 = Callback service method
  2020                              <1> 	;	    ; 3 = Auto Increment S.R.B. method
  2021                              <1> 	;mov	cl, [audio_srb]
  2022                              <1> 	;mov	edx, [audio_cb_addr]
  2023                              <1> 	;mov	al, [audio_user]
  2024                              <1>  	;call	set_irq_callback_service
  2025                              <1> ResetDsp:
  2026 000145B1 668B15[F28E0100]    <1> 	mov     dx, [audio_io_base]
  2027                              <1> 	;add	dx, 06h
  2028                              <1> 	; 06/08/2022
  2029 000145B8 80C206              <1> 	add	dl, 06h
  2030 000145BB B001                <1> 	mov     al, 1
  2031 000145BD EE                  <1> 	out	dx, al
  2032                              <1> 
  2033 000145BE EC                  <1> 	in	al, dx
  2034 000145BF EC                  <1> 	in	al, dx
  2035 000145C0 EC                  <1> 	in	al, dx
  2036 000145C1 EC                  <1> 	in	al, dx
  2037                              <1> 
  2038 000145C2 30C0                <1> 	xor     al, al
  2039 000145C4 EE                  <1> 	out	dx, al
  2040                              <1> 
  2041                              <1> 	;mov	cx, 100
  2042                              <1> 	; 06/08/2022
  2043 000145C5 29C9                <1> 	sub	ecx, ecx
  2044 000145C7 B164                <1> 	mov	cl, 100
  2045 000145C9 28E4                <1> 	sub	ah, ah ; 0
  2046                              <1> WaitId:         
  2047 000145CB 668B15[F28E0100]    <1> 	mov     dx, [audio_io_base]
  2048                              <1> 	;add	dx, 0Eh
  2049                              <1> 	; 06/08/2022
  2050 000145D2 80C20E              <1> 	add	dl, 0Eh
  2051 000145D5 EC                  <1> 	in	al, dx
  2052 000145D6 08C0                <1> 	or      al, al
  2053 000145D8 7807                <1> 	js      short sb_GetId
  2054 000145DA E2EF                <1> 	loop    WaitId
  2055 000145DC E9B1000000          <1> 	jmp     sb_Exit
  2056                              <1> sb_GetId:
  2057 000145E1 668B15[F28E0100]    <1> 	mov     dx, [audio_io_base]
  2058                              <1> 	;add	dx, 0Ah
  2059                              <1> 	; 06/08/2022
  2060 000145E8 80C20A              <1> 	add	dl, 0Ah
  2061 000145EB EC                  <1> 	in	al, dx
  2062 000145EC 3CAA                <1> 	cmp     al, 0AAh
  2063 000145EE 7407                <1> 	je      short SbOk
  2064 000145F0 E2D9                <1> 	loop    WaitId
  2065 000145F2 E99B000000          <1> 	jmp	sb_Exit
  2066                              <1> SbOk:
  2067 000145F7 668B15[F28E0100]    <1> 	mov     dx, [audio_io_base]
  2068                              <1> 	;add	dx, 0Ch
  2069                              <1> 	; 06/08/2022
  2070 000145FE 80C20C              <1> 	add	dl, 0Ch
  2071                              <1> 	SbOut   0D1h ; Turn on speaker
  1900                              <2> %%Wait:
  1901 00014601 EC                  <2>  in al, dx
  1902 00014602 08C0                <2>  or al, al
  1903 00014604 78FB                <2>  js short %%Wait
  1904 00014606 B0D1                <2>  mov al, %1
  1905 00014608 EE                  <2>  out dx, al
  2072                              <1> 	SbOut   41h ; 8h bit or 16 bit transfer
  1900                              <2> %%Wait:
  1901 00014609 EC                  <2>  in al, dx
  1902 0001460A 08C0                <2>  or al, al
  1903 0001460C 78FB                <2>  js short %%Wait
  1904 0001460E B041                <2>  mov al, %1
  1905 00014610 EE                  <2>  out dx, al
  2073 00014611 668B1D[228F0100]    <1> 	mov	bx, [audio_freq] ; sampling rate (Hz)
  2074                              <1> 	SbOut	bh ; sampling rate high byte
  1900                              <2> %%Wait:
  1901 00014618 EC                  <2>  in al, dx
  1902 00014619 08C0                <2>  or al, al
  1903 0001461B 78FB                <2>  js short %%Wait
  1904 0001461D 88F8                <2>  mov al, %1
  1905 0001461F EE                  <2>  out dx, al
  2075                              <1> 	SbOut	bl ; sampling rate low byte
  1900                              <2> %%Wait:
  1901 00014620 EC                  <2>  in al, dx
  1902 00014621 08C0                <2>  or al, al
  1903 00014623 78FB                <2>  js short %%Wait
  1904 00014625 88D8                <2>  mov al, %1
  1905 00014627 EE                  <2>  out dx, al
  2076                              <1> 
  2077                              <1> 	; 22/05/2017
  2078 00014628 E8BF000000          <1> 	call	sb16_volume_initial ; 15/05/2017
  2079                              <1> 	; 20/05/2017
  2080                              <1> 	;call	sb16_volume
  2081                              <1> 
  2082                              <1> StartDma: 
  2083                              <1> 	; autoinitialized mode
  2084 0001462D 803D[208F0100]10    <1> 	cmp	byte [audio_bps], 16 ; 16 bit samples
  2085 00014634 7411                <1> 	je	short sb_play_1
  2086                              <1> 	; 8 bit samples
  2087 00014636 66BBC600            <1> 	mov	bx, 0C6h ; 8 bit output (0C6h)
  2088 0001463A 803D[218F0100]02    <1> 	cmp	byte [audio_stmo], 2 ; 1 = mono, 2 = stereo
  2089 00014641 7214                <1> 	jb	short sb_play_2
  2090 00014643 B720                <1> 	mov	bh, 20h	; 8 bit stereo (20h)
  2091 00014645 EB10                <1> 	jmp	short sb_play_2
  2092                              <1> sb_play_1:
  2093                              <1> 	; 16 bit samples
  2094 00014647 66BBB610            <1> 	mov	bx, 10B6h ; 16 bit output (0B6h)
  2095 0001464B 803D[218F0100]02    <1> 	cmp	byte [audio_stmo], 2 ; 1 = mono, 2 = stereo
  2096 00014652 7203                <1> 	jb	short sb_play_2
  2097 00014654 80C720              <1> 	add	bh, 20h	; 16 bit stereo (30h)
  2098                              <1> sb_play_2:     
  2099                              <1> 	; PCM output (8/16 bit mono autoinitialized transfer)
  2100                              <1> 	SbOut   bl ; bCommand
  1900                              <2> %%Wait:
  1901 00014657 EC                  <2>  in al, dx
  1902 00014658 08C0                <2>  or al, al
  1903 0001465A 78FB                <2>  js short %%Wait
  1904 0001465C 88D8                <2>  mov al, %1
  1905 0001465E EE                  <2>  out dx, al
  2101                              <1> 	SbOut	bh ; bMode
  1900                              <2> %%Wait:
  1901 0001465F EC                  <2>  in al, dx
  1902 00014660 08C0                <2>  or al, al
  1903 00014662 78FB                <2>  js short %%Wait
  1904 00014664 88F8                <2>  mov al, %1
  1905 00014666 EE                  <2>  out dx, al
  2102 00014667 8B1D[108F0100]      <1> 	mov	ebx, [audio_dmabuff_size]  ; 15/05/2017
  2103 0001466D D1EB                <1> 	shr	ebx, 1 ; half buffer size
  2104                              <1> 	; 20/10/2017	
  2105 0001466F 803D[208F0100]10    <1> 	cmp	byte [audio_bps], 16 ; 16 bit DMA
  2106 00014676 7502                <1> 	jne	short sb_play_3
  2107 00014678 D1EB                <1> 	shr	ebx, 1 ; byte count to word count
  2108                              <1> sb_play_3: 
  2109                              <1> 	;dec	bx  ; wBlkSize is one less than the actual size
  2110                              <1> 	; 06/08/2022
  2111 0001467A 4B                  <1> 	dec	ebx
  2112                              <1> 	SbOut   bl
  1900                              <2> %%Wait:
  1901 0001467B EC                  <2>  in al, dx
  1902 0001467C 08C0                <2>  or al, al
  1903 0001467E 78FB                <2>  js short %%Wait
  1904 00014680 88D8                <2>  mov al, %1
  1905 00014682 EE                  <2>  out dx, al
  2113                              <1> 	SbOut   bh
  1900                              <2> %%Wait:
  1901 00014683 EC                  <2>  in al, dx
  1902 00014684 08C0                <2>  or al, al
  1903 00014686 78FB                <2>  js short %%Wait
  1904 00014688 88F8                <2>  mov al, %1
  1905 0001468A EE                  <2>  out dx, al
  2114                              <1> 
  2115 0001468B C605[268F0100]01    <1> 	mov	byte [audio_play_cmd], 1 ; playing !
  2116                              <1> 
  2117                              <1> 	;; Set Voice and master volumes
  2118                              <1> 	;mov	dx, [audio_io_base]
  2119                              <1> 	;add	dl, 4 ; Mixer chip Register Address Port
  2120                              <1> 	;SbOut	30h   ; select Master Volume Register (L)
  2121                              <1> 	;inc	dl    ; Mixer chip Register Data Port
  2122                              <1> 	;SbOut	0F8h  ; Max. volume value is 31 (31*8)
  2123                              <1> 	;dec	dl
  2124                              <1> 	;SbOut	31h   ; select Master Volume Register (R)
  2125                              <1> 	;inc	dl
  2126                              <1> 	;SbOut	0F8h  ; Max. volume value is 31 (31*8)
  2127                              <1> 	;dec	dl
  2128                              <1> 	;SbOut	32h   ; select Voice Volume Register (L)
  2129                              <1> 	;inc	dl
  2130                              <1> 	;SbOut	0F8h  ; Max. volume value is 31 (31*8)
  2131                              <1> 	;dec	dl
  2132                              <1> 	;SbOut	33h   ; select Voice Volume Register (R)
  2133                              <1> 	;inc	dl
  2134                              <1> 	;SbOut	0F8h  ; Max. volume value is 31 (31*8)
  2135                              <1> 	;;
  2136                              <1> 	;dec	dl
  2137                              <1> 	;SbOut	44h   ; select Treble Register (L)
  2138                              <1> 	;inc	dl
  2139                              <1> 	;SbOut	0F0h  ; Max. Treble value is 15 (15*16)
  2140                              <1> 	;dec	dl
  2141                              <1> 	;SbOut	45h   ; select Treble Register (R)
  2142                              <1> 	;inc	dl
  2143                              <1> 	;SbOut	0F0h  ; Max. Treble value is 15 (15*16)
  2144                              <1> 	;dec	dl
  2145                              <1> 	;SbOut	46h   ; select Bass Register (L)
  2146                              <1> 	;inc	dl
  2147                              <1> 	;SbOut	0F0h  ; Max. Bass value is 15 (15*16)
  2148                              <1> 	;dec	dl
  2149                              <1> 	;SbOut	47h   ; select Bass Register (R)
  2150                              <1> 	;inc	dl
  2151                              <1> 	;SbOut	0F0h  ; Max. Bass value is 15 (15*16)
  2152                              <1> 
  2153                              <1> sb_Exit:
  2154                              <1> 	;popad
  2155 00014692 C3                  <1> 	retn
  2156                              <1> 
  2157                              <1> sb16_int_handler:
  2158                              <1> 	; Interrupt Handler for Sound Blaster 16 Audio Card
  2159                              <1> 	; Note: called by 'dev_IRQ_service'
  2160                              <1> 	; 20/10/2017
  2161                              <1> 	; 12/10/2017
  2162                              <1> 	; 10/10/2017 
  2163                              <1> 	; 12/05/2017, 09/10/2017
  2164                              <1> 	; 24/04/2017 (TRDOS 386 kernel, 'audio.s')
  2165                              <1> 	; 10/03/2017 - 'PLAYWAV.PRG' ('playwav.s')
  2166                              <1> 
  2167                              <1> 	;push	eax ; * must be saved !
  2168                              <1> 	;push	ebx ; * must be saved !
  2169                              <1> 	;push	ecx
  2170                              <1> 	;push	edx
  2171                              <1> 	;push	esi
  2172                              <1> 	;push	edi
  2173                              <1> 
  2174 00014693 668B15[F28E0100]    <1> 	mov     dx, [audio_io_base]
  2175                              <1> 	; 20/10/2017
  2176 0001469A 80C20F              <1> 	add     dl, 0Fh ; 2xFh (DSP 16 bit intr ack)
  2177 0001469D 803D[208F0100]10    <1> 	cmp	byte [audio_bps], 16
  2178 000146A4 7402                <1> 	je	short sb_irq_16bit_ack
  2179                              <1> sb_irq_8bit_ack:
  2180 000146A6 FECA                <1> 	dec	dl  ; 2xEh (DSP 8 bit intr ack)
  2181                              <1> sb_irq_16bit_ack:
  2182 000146A8 EC                  <1> 	in	al, dx
  2183                              <1> 
  2184                              <1> 	;cmp	byte [audio_busy], 0
  2185                              <1> 	;ja	short sb_irq_h3
  2186                              <1> 
  2187                              <1> 	;mov	byte [audio_busy], 1
  2188                              <1> 
  2189 000146A9 803D[268F0100]01    <1> 	cmp	byte [audio_play_cmd], 1
  2190 000146B0 7307                <1> 	jnb	short sb_irq_h1
  2191                              <1> sb_irq_h0:
  2192 000146B2 E8A3000000          <1> 	call	sb16_stop
  2193 000146B7 EB2B                <1> 	jmp	short sb_irq_h3
  2194                              <1> sb_irq_h1:
  2195                              <1> 	;call	sb16_tuneloop
  2196                              <1> 	; 09/10/2017
  2197                              <1> sb16_tuneloop:
  2198 000146B9 8B3D[0C8F0100]      <1> 	mov	edi, [audio_dma_buff]
  2199 000146BF 8B0D[108F0100]      <1> 	mov	ecx, [audio_dmabuff_size]
  2200 000146C5 D1E9                <1> 	shr	ecx, 1 ; dma buff size / 2 = half buffer size
  2201                              <1> 
  2202                              <1> 	; 22/05/2017
  2203 000146C7 F605[188F0100]01    <1> 	test	byte [audio_flag], 1  ; Current flag value
  2204 000146CE 7402                <1> 	jz	short sb_tlp1 ; EOL (Half Buffer 1 must be filled)
  2205                              <1> 	; FLAG (Half Buffer 2 must be filled)
  2206 000146D0 01CF                <1> 	add	edi, ecx
  2207                              <1> 	; 15/05/2017
  2208                              <1> sb_tlp1: 
  2209 000146D2 8B35[048F0100]      <1> 	mov	esi, [audio_p_buffer] ; phy addr of audio buff
  2210                              <1> 	;rep	movsb
  2211 000146D8 C1E902              <1> 	shr	ecx, 2 ; half buff size / 4
  2212 000146DB F3A5                <1> 	rep	movsd
  2213                              <1> 	;retn
  2214                              <1> 
  2215                              <1> 	; 10/10/2017
  2216                              <1> 	; switch flag value
  2217 000146DD 8035[188F0100]01    <1> 	xor	byte [audio_flag], 1
  2218                              <1> 
  2219                              <1> 	; 12/10/2017
  2220                              <1> 	; [audio_flag] = 0 : Playing dma half buffer 2 (odd intr count)
  2221                              <1> 			   ; Next buffer (to update) is dma half buff 1
  2222                              <1> 	; 	       = 1 : Playing dma half buffer 1 (even intr count)
  2223                              <1> 			   ; Next buffer (to update) is dma half buff 2
  2224                              <1> 
  2225                              <1> sb_irq_h3:
  2226                              <1> 	;mov	byte [audio_busy], 0
  2227                              <1> 
  2228                              <1> 	;pop	edi
  2229                              <1> 	;pop	esi
  2230                              <1> 	;pop	edx
  2231                              <1> 	;pop	ecx
  2232                              <1> 	;pop	ebx ; * must be restored !
  2233                              <1> 	;pop	eax ; * must be restored !
  2234                              <1> 	
  2235 000146E4 C3                  <1> 	retn
  2236                              <1> 
  2237                              <1> sb16_volume:
  2238                              <1> 	; 06/08/2022 (TRDOS 386 v2.0.5)
  2239                              <1> 	; 22/10/2017
  2240                              <1> 	; mov [audio_master_volume_l], cl
  2241                              <1> 	; mov [audio_master_volume_h], ch
  2242 000146E5 66890D[288F0100]    <1> 	mov	[audio_master_volume], cx
  2243                              <1> sb16_volume_initial:
  2244                              <1> 	;push	dx ; DX (port address) must be saved
  2245                              <1> 	; 06/08/2022
  2246 000146EC 52                  <1> 	push	edx
  2247 000146ED 668B15[F28E0100]    <1> 	mov	dx, [audio_io_base]
  2248                              <1> 	;add	dx, 4 ; Mixer chip address port
  2249                              <1> 	; 06/08/2022
  2250 000146F4 80C204              <1> 	add	dl, 4
  2251 000146F7 B022                <1> 	mov	al, 22h ; master volume
  2252 000146F9 EE                  <1> 	out	dx, al
  2253                              <1> 	;inc	dx
  2254                              <1> 	; 06/08/2022
  2255 000146FA 42                  <1> 	inc	edx
  2256 000146FB 8A25[288F0100]      <1> 	mov	ah, [audio_master_volume_l]
  2257 00014701 C0EC02              <1> 	shr	ah, 2 ; 32 -> 8 level
  2258 00014704 C0E405              <1> 	shl	ah, 5 ; bit 5 to 7
  2259 00014707 A0[298F0100]        <1> 	mov	al, [audio_master_volume_r]
  2260 0001470C C0E802              <1> 	shr	al, 2 ; 32 -> 8 level
  2261                              <1> 	;and	al, 0Fh
  2262 0001470F D0E0                <1> 	shl	al, 1 ; bit 1 to 3
  2263 00014711 08E0                <1> 	or	al, ah
  2264 00014713 EE                  <1> 	out	dx, al
  2265                              <1> 	;pop	dx ; DX (port address) must be restored
  2266                              <1> 	; 06/08/2022
  2267 00014714 5A                  <1> 	pop	edx
  2268 00014715 C3                  <1> 	retn
  2269                              <1> 
  2270                              <1> sb16_pause:
  2271                              <1> 	; 06/08/2022 (TRDOS 386 v2.0.5)
  2272 00014716 668B15[F28E0100]    <1> 	mov	dx, [audio_io_base]
  2273                              <1> 	;add	dx, 0Ch ; Command & Data Port
  2274                              <1> 	; 06/08/2022
  2275 0001471D 80C20C              <1> 	add	dl, 0Ch
  2276 00014720 803D[208F0100]10    <1> 	cmp	byte [audio_bps], 16 ; 16 bit samples
  2277 00014727 7404                <1> 	je	short sb_pause_1
  2278                              <1> 	; 8 bit samples
  2279 00014729 B3D0                <1> 	mov	bl, 0D0h ; 8 bit DMA mode
  2280 0001472B EB02                <1> 	jmp	short sb_pause_2
  2281                              <1> sb_pause_1:
  2282                              <1> 	; 16 bit samples
  2283 0001472D B3D5                <1> 	mov	bl, 0D5h ; 16 bit DMA mode
  2284                              <1> sb_pause_2:
  2285                              <1> 	SbOut   bl ; bCommand
  1900                              <2> %%Wait:
  1901 0001472F EC                  <2>  in al, dx
  1902 00014730 08C0                <2>  or al, al
  1903 00014732 78FB                <2>  js short %%Wait
  1904 00014734 88D8                <2>  mov al, %1
  1905 00014736 EE                  <2>  out dx, al
  2286                              <1> sb_pause_3:
  2287 00014737 C3                  <1> 	retn
  2288                              <1> 
  2289                              <1> sb16_continue:
  2290                              <1> 	; 06/08/2022 (TRDOS 386 v2.0.5)
  2291 00014738 668B15[F28E0100]    <1> 	mov	dx, [audio_io_base]
  2292                              <1> 	;add	dx, 0Ch ; Command & Data Port
  2293                              <1> 	; 06/08/2022
  2294 0001473F 80C20C              <1> 	add	dl, 0Ch
  2295 00014742 803D[208F0100]10    <1> 	cmp	byte [audio_bps], 16 ; 16 bit samples
  2296 00014749 7404                <1> 	je	short sb_cont_1
  2297                              <1> 	; 8 bit samples
  2298 0001474B B3D4                <1> 	mov	bl, 0D4h ; 8 bit DMA mode
  2299 0001474D EB02                <1> 	jmp	short sb_cont_2
  2300                              <1> sb_cont_1:
  2301                              <1> 	; 16 bit samples
  2302 0001474F B3D6                <1> 	mov	bl, 0D6h ; 16 bit DMA mode
  2303                              <1> sb_cont_2:     
  2304                              <1> 	SbOut   bl ; bCommand
  1900                              <2> %%Wait:
  1901 00014751 EC                  <2>  in al, dx
  1902 00014752 08C0                <2>  or al, al
  1903 00014754 78FB                <2>  js short %%Wait
  1904 00014756 88D8                <2>  mov al, %1
  1905 00014758 EE                  <2>  out dx, al
  2305                              <1> sb_cont_3:
  2306 00014759 C3                  <1> 	retn
  2307                              <1> 
  2308                              <1> sb16_stop:
  2309                              <1> 	; 06/08/2022 (TRDOS 386 v2.0.5)
  2310                              <1> 	; 24/04/2017
  2311 0001475A 803D[268F0100]00    <1> 	cmp	byte [audio_play_cmd], 0
  2312 00014761 7647                <1> 	jna	short sb16_stop_4
  2313                              <1> 
  2314                              <1> 	; 22/05/2017
  2315 00014763 668B15[F28E0100]    <1> 	mov	dx, [audio_io_base]
  2316                              <1> 	;add	dx, 0Ch
  2317                              <1> 	; 06/08/2022
  2318 0001476A 80C20C              <1> 	add	dl, 0Ch
  2319                              <1> 
  2320 0001476D B3D9                <1> 	mov	bl, 0D9h ; exit auto-initialize 16 bit transfer
  2321                              <1> 	; stop  autoinitialized DMA transfer mode 
  2322 0001476F 803D[208F0100]10    <1> 	cmp	byte [audio_bps], 16 ; 16 bit samples
  2323 00014776 7402                <1> 	je	short sb16_stop_1
  2324                              <1> 	;mov	bl, 0DAh ; exit auto-initialize 8 bit transfer
  2325 00014778 FEC3                <1> 	inc	bl
  2326                              <1> sb16_stop_1:
  2327                              <1> 	SbOut	bl ; exit auto-initialize transfer command
  1900                              <2> %%Wait:
  1901 0001477A EC                  <2>  in al, dx
  1902 0001477B 08C0                <2>  or al, al
  1903 0001477D 78FB                <2>  js short %%Wait
  1904 0001477F 88D8                <2>  mov al, %1
  1905 00014781 EE                  <2>  out dx, al
  2328                              <1> 
  2329 00014782 30C0                <1> 	xor     al, al ; stops all DMA processes on selected channel
  2330                              <1> 
  2331 00014784 803D[208F0100]10    <1> 	cmp	byte [audio_bps], 16 ; 16 bit samples
  2332 0001478B 7404                <1> 	je	short sb16_stop_2
  2333 0001478D E60C                <1> 	out	0Ch, al ; clear selected channel register
  2334 0001478F EB02                <1> 	jmp	short sb16_stop_3
  2335                              <1> 
  2336                              <1> sb16_stop_2:
  2337 00014791 E6D8                <1> 	out	0D8h, al ; clear selected channel register
  2338                              <1> 
  2339                              <1> sb16_stop_3:
  2340 00014793 C605[268F0100]00    <1> 	mov	byte [audio_play_cmd], 0 ; stop !
  2341                              <1> SbDone:
  2342                              <1> 	;mov	dx, [audio_io_base]
  2343                              <1> 	;add	dx, 0Ch
  2344                              <1> 	SbOut   0D0h
  1900                              <2> %%Wait:
  1901 0001479A EC                  <2>  in al, dx
  1902 0001479B 08C0                <2>  or al, al
  1903 0001479D 78FB                <2>  js short %%Wait
  1904 0001479F B0D0                <2>  mov al, %1
  1905 000147A1 EE                  <2>  out dx, al
  2345                              <1> 	SbOut   0D3h
  1900                              <2> %%Wait:
  1901 000147A2 EC                  <2>  in al, dx
  1902 000147A3 08C0                <2>  or al, al
  1903 000147A5 78FB                <2>  js short %%Wait
  1904 000147A7 B0D3                <2>  mov al, %1
  1905 000147A9 EE                  <2>  out dx, al
  2346                              <1> sb16_stop_4:
  2347 000147AA C3                  <1> 	retn
  2348                              <1> 
  2349                              <1> sb16_reset:
  2350                              <1> 	; 06/08/2022 (TRDOS 386 v2.0.5)
  2351                              <1> 	; 24/04/2017
  2352 000147AB 668B15[F28E0100]    <1> 	mov     dx, [audio_io_base] ; try to reset the DSP.
  2353                              <1> 	;add	dx, 06h
  2354                              <1> 	; 06/08/2022
  2355 000147B2 80C206              <1> 	add	dl, 06h
  2356 000147B5 B001                <1> 	mov	al, 1
  2357 000147B7 EE                  <1> 	out	dx, al
  2358                              <1> 
  2359 000147B8 EC                  <1> 	in	al, dx
  2360 000147B9 EC                  <1> 	in	al, dx
  2361 000147BA EC                  <1> 	in	al, dx
  2362 000147BB EC                  <1> 	in	al, dx
  2363                              <1> 
  2364 000147BC 30C0                <1> 	xor     al, al
  2365 000147BE EE                  <1> 	out	dx, al
  2366                              <1> 
  2367                              <1> 	;add	dx, 08h
  2368                              <1> 	; 06/08/2022
  2369 000147BF 80C208              <1> 	add	dl, 08h
  2370                              <1> 	;mov	cx, 100
  2371 000147C2 29C9                <1> 	sub	ecx, ecx
  2372 000147C4 B164                <1> 	mov	cl, 100
  2373                              <1> sbrstWaitID:
  2374 000147C6 EC                  <1> 	in	al, dx
  2375 000147C7 08C0                <1> 	or      al, al
  2376 000147C9 7804                <1> 	js      short sbrstGetID
  2377 000147CB E2F9                <1> 	loop    sbrstWaitID
  2378 000147CD F9                  <1> 	stc
  2379 000147CE C3                  <1> 	retn
  2380                              <1> sbrstGetID:
  2381                              <1> 	;sub	dx, 04h
  2382                              <1> 	; 06/08/2022
  2383 000147CF 80EA04              <1> 	sub	dl, 04h
  2384 000147D2 EC                  <1> 	in	al, dx
  2385 000147D3 3CAA                <1> 	cmp     al, 0AAh
  2386 000147D5 7405                <1> 	je      short sb_rst_retn
  2387                              <1> 	;add	dx, 04h
  2388                              <1> 	; 06/08/2022
  2389 000147D7 80C204              <1> 	add	dl, 04h
  2390 000147DA E2EA                <1> 	loop    sbrstWaitID
  2391                              <1> sb_rst_retn:
  2392 000147DC C3                  <1> 	retn
  2393                              <1> 
  2394                              <1> ac97_codec_config:
  2395                              <1> 	; 06/06/2024
  2396                              <1> 	; 04/06/2024
  2397                              <1> 	; 03/06/2024
  2398                              <1> 	; 02/06/2024
  2399                              <1> 	; 01/06/2024 (TRDOS 386 v2.0.8)
  2400                              <1> 	; 26/11/2023
  2401                              <1> 	; 21/11/2023
  2402                              <1> 	; 20/11/2023
  2403                              <1> 	; 19/11/2023 (TRDOS 386 v2.0.7)
  2404                              <1> 	; 10/06/2017
  2405                              <1> 	; 05/06/2017
  2406                              <1> 	; 29/05/2017
  2407                              <1> 	; 28/05/2017 (TRDOS 386, 'audio.s')
  2408                              <1> 	; 07/11/2016 (Erdogan Tan)
  2409                              <1> 	; Derived from 'codecConfig' procedure in 'CODEC.ASM'
  2410                              <1> 	; .wav player for DOS by Jeff Leyda (02/09/2002)
  2411                              <1> 
  2412                              <1> 	;; 'PLAYER.ASM'
  2413                              <1> 	;; get ICH base address regs for mixer and bus master
  2414                              <1> 
  2415                              <1> init_ac97_controller: ; 10/06/2017
  2416 000147DD A1[F48E0100]        <1> 	mov	eax, [audio_dev_id]
  2417                              <1>         ;mov	al, NAMBAR_REG
  2418                              <1>         ;;call  pciRegRead16			; read PCI registers 10-11
  2419                              <1>         ;call	pciRegRead32
  2420                              <1> 	;and	dx, IO_ADDR_MASK 		; mask off BIT0
  2421                              <1> 	;;and	edx, IO_ADDR_MASK
  2422                              <1> 
  2423                              <1>         ;mov	[NAMBAR], dx			; save audio mixer base addr
  2424                              <1> 
  2425                              <1>         ;mov	al, NABMBAR_REG
  2426                              <1>         ;;call	pciRegRead16
  2427                              <1>         ;call	pciRegRead32
  2428                              <1> 	;and	dx, 0FFC0h ; IO_ADDR_MASK
  2429                              <1> 	;;and	edx, 0FFC0h
  2430                              <1> 
  2431                              <1>         ;mov    [NABMBAR], dx			; save bus master base addr
  2432                              <1> 
  2433                              <1> 	;mov	eax, [audio_dev_id]
  2434 000147E2 B004                <1>         mov	al, PCI_CMD_REG
  2435                              <1>         ;call	pciRegRead8			; read PCI command register
  2436 000147E4 E895F8FFFF          <1>         call	pciRegRead16
  2437 000147E9 80CA05              <1> 	or	dl, IO_ENA+BM_ENA               ; enable IO and bus master
  2438                              <1>         ;call	pciRegWrite8
  2439 000147EC E8F8F8FFFF          <1> 	call	pciRegWrite16
  2440                              <1> 
  2441                              <1> 	; 'CODEC.ASM'
  2442                              <1> 
  2443                              <1> 	; enable codec, unmute stuff, set output rate
  2444                              <1> ;	; entry: [audio_freq] = desired sample rate
  2445                              <1> 		
  2446                              <1> ;	mov	dx, [NAMBAR]
  2447                              <1> ;	add	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  2448                              <1> ;	in	ax, dx
  2449                              <1> ;	or	ax, 1
  2450                              <1> ;	out	dx, ax 				; Enable variable rate audio
  2451                              <1> 
  2452                              <1> ;       ;call	delay1_4ms
  2453                              <1> ;       ;call	delay1_4ms
  2454                              <1> ;       ;call	delay1_4ms
  2455                              <1> ;       ;call	delay1_4ms
  2456                              <1> 
  2457                              <1> ;	mov	ax, [audio_freq]		; sample rate
  2458                              <1> 
  2459                              <1> ;	mov	dx, [NAMBAR]               	
  2460                              <1> ;	add	dx, CODEC_PCM_FRONT_DACRATE_REG	; 2Ch
  2461                              <1> ;	out	dx, ax 				; out sample rate
  2462                              <1> 		
  2463                              <1> ;       ;call	delay1_4ms
  2464                              <1> ;       ;call	delay1_4ms
  2465                              <1> ;       ;call	delay1_4ms
  2466                              <1> ;       ;call	delay1_4ms
  2467                              <1> 
  2468                              <1> 	;mov	dx, [NAMBAR]			; mixer base address
  2469                              <1>         ;add	dx, CODEC_RESET_REG  		; reset register
  2470                              <1>         ;mov	ax, 42
  2471                              <1> 	;out	dx, ax                          ; reset
  2472                              <1> 
  2473                              <1> 	;mov	dx, [NABMBAR]			; bus master base address
  2474                              <1>         ;add	dx, GLOB_STS_REG
  2475                              <1>         ;mov	ax, 2
  2476                              <1> 	;out	dx, ax
  2477                              <1> 
  2478                              <1> 	; 01/06/2024
  2479                              <1> 	; 16/05/2024
  2480                              <1> 	; 02/12/2023
  2481                              <1> 	;call	delay_100ms ; 29/05/2017
  2482                              <1> 
  2483                              <1> 	; 02/12/2023
  2484                              <1> 	;call	delay1_4ms
  2485                              <1> 	;call	delay1_4ms
  2486                              <1> 	;call	delay1_4ms
  2487                              <1> 	;call	delay1_4ms
  2488                              <1> 
  2489                              <1> init_ac97_codec:
  2490                              <1> 	; 26/11/2023
  2491                              <1> 	; 19/11/2023
  2492                              <1> 	;   (playwav3.com, ac97_vra.asm, Erdogan Tan, 19/11/2023)
  2493                              <1> 	; 10/06/2017
  2494                              <1> 	; 29/05/2017
  2495                              <1> 	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  2496                              <1> 
  2497                              <1> 	;; 23/11/2023 - temporary
  2498                              <1> 	;push	ebx
  2499                              <1> 	;mov	ebx, 0B8000h
  2500                              <1> 	;mov	al, '?'
  2501                              <1> 	;mov	ah, 4Eh
  2502                              <1> 	;mov	[ebx], ax
  2503                              <1> 	;pop	ebx
  2504                              <1> 
  2505                              <1> 	; 01/06/2024
  2506 000147F1 C605[34930100]01    <1> 	mov	byte [reset], 1
  2507                              <1> 
  2508                              <1> 	; 19/11/2023
  2509 000147F8 BD28000000          <1> 	mov	ebp, 40	; 21/11/2023
  2510                              <1> _initc_1:
  2511                              <1> 	; 26/05/2024
  2512 000147FD 66BA3000            <1> 	mov	dx, GLOB_STS_REG ; 30h
  2513 00014801 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  2514 00014808 ED                  <1> 	in	eax, dx
  2515                              <1> 
  2516                              <1> 	; 01/06/2024
  2517                              <1> 	; 02/12/2023
  2518                              <1> 	;call	delay1_4ms
  2519                              <1> 
  2520 00014809 83F8FF              <1> 	cmp	eax, 0FFFFFFFFh ; -1
  2521 0001480C 750A                <1> 	jne	short _initc_3
  2522                              <1> _initc_2:
  2523 0001480E 4D                  <1> 	dec	ebp	; 21/11/2023
  2524 0001480F 7425                <1> 	jz	short _ac97_codec_ready
  2525                              <1> 
  2526 00014811 E86BF9FFFF          <1> 	call	delay_100ms
  2527 00014816 EBE5                <1> 	jmp	short _initc_1
  2528                              <1> _initc_3:
  2529 00014818 A900030010          <1> 	test	eax, CTRL_ST_CREADY
  2530 0001481D 7517                <1> 	jnz	short _ac97_codec_ready
  2531                              <1> 
  2532                              <1> 	; 01/06/2024
  2533 0001481F 803D[34930100]00    <1> 	cmp	byte [reset], 0
  2534 00014826 76E6                <1> 	jna	short _initc_2
  2535                              <1> 
  2536 00014828 E849030000          <1> 	call	reset_ac97_codec
  2537                              <1> 	;jc	short _initc_2
  2538                              <1> 	; 01/06/2024
  2539 0001482D C605[34930100]00    <1> 	mov	byte [reset], 0
  2540                              <1> 	; 26/11/2023
  2541 00014834 EBD8                <1> 	jmp	short _initc_2
  2542                              <1> 
  2543                              <1> _ac97_codec_ready:
  2544 00014836 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  2545                              <1> 	;add	dx, 0 ; ac_reg_0 ; reset register
  2546 0001483D 66EF                <1> 	out	dx, ax
  2547                              <1> 
  2548                              <1> 	; 06/06/2024
  2549                              <1> 	; 01/06/2024
  2550                              <1> 	;;;
  2551                              <1> 	;call	delay1_4ms
  2552                              <1> 	;call	delay1_4ms
  2553                              <1> 	;call	delay1_4ms
  2554                              <1> 	;call	delay1_4ms
  2555                              <1> 	;;;
  2556                              <1> 
  2557                              <1> 	; 01/06/2024
  2558                              <1> 	; 26/05/2024
  2559                              <1> 	; 19/11/2023
  2560                              <1> 	;call	delay_100ms
  2561                              <1> 	; 24/11/2023 - temporary
  2562                              <1> 	;call	delay_100ms
  2563                              <1> 	;call	delay_100ms
  2564                              <1> 	;call	delay_100ms
  2565                              <1> 
  2566                              <1> 	; 01/06/2024
  2567                              <1> 	;;;
  2568 0001483F 09ED                <1> 	or	ebp, ebp  ; 21/11/2023
  2569 00014841 753E                <1> 	jnz	short _ac97_codec_init_ok
  2570                              <1> 	;;;
  2571                              <1> 
  2572 00014843 31C0                <1> 	xor	eax, eax ; 0
  2573 00014845 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  2574 0001484C 6683C226            <1> 	add	dx, CODEC_REG_POWERDOWN
  2575 00014850 66EF                <1> 	out	dx, ax
  2576                              <1> 
  2577                              <1> 	; 10/06/2017
  2578                              <1> 	; 29/05/2017
  2579                              <1> 	; wait for 1 second
  2580                              <1> 	; 01/06/2024
  2581                              <1> 	; 16/05/2024
  2582 00014852 B9E8030000          <1> 	mov	ecx, 1000 ; 1000*0.25ms
  2583                              <1> 	; 20/11/2023
  2584                              <1> 	;mov	ecx, 10
  2585                              <1> 	; 23/05/2024
  2586                              <1> 	;mov	cl, 10
  2587                              <1> 	; 24/11/2023 - temporary
  2588                              <1> 	;mov	cl, 40
  2589                              <1> 	; ecx = 40 ; 23/05/2024
  2590                              <1> _ac97_codec_rloop:
  2591                              <1> 	; 01/06/2024
  2592 00014857 E832F9FFFF          <1> 	call	delay1_4ms
  2593                              <1> 	; 06/06/2024
  2594 0001485C E82DF9FFFF          <1> 	call	delay1_4ms
  2595 00014861 E828F9FFFF          <1> 	call	delay1_4ms
  2596 00014866 E823F9FFFF          <1> 	call	delay1_4ms
  2597                              <1> 	; 01/06/2024
  2598                              <1> 	; 19/11/2023
  2599                              <1> 	; 22/11/2023
  2600                              <1> 	;push	ecx
  2601                              <1> 	;call	delay_100ms
  2602                              <1> 	;pop	ecx
  2603                              <1> 
  2604                              <1> 	; 01/06/2024
  2605                              <1> 	;;;
  2606 0001486B 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  2607 00014872 6683C226            <1> 	add	dx, CODEC_REG_POWERDOWN
  2608                              <1> 	;;;
  2609 00014876 66ED                <1> 	in	ax, dx
  2610                              <1> 
  2611                              <1> 	; 06/06/2024
  2612                              <1> 	;call	delay1_4ms
  2613                              <1> 
  2614                              <1> 	;and	ax, 0Fh
  2615                              <1> 	; 21/11/2023
  2616 00014878 240F                <1> 	and	al, 0Fh
  2617 0001487A 3C0F                <1> 	cmp	al, 0Fh
  2618 0001487C 7403                <1> 	je	short _ac97_codec_init_ok
  2619                              <1> 	; 24/11/2023 - temporary
  2620                              <1> 	;je	short _ac97_codec_init_ok_
  2621                              <1> _ac97_codec_yloop:	
  2622 0001487E E2D7                <1> 	loop	_ac97_codec_rloop 
  2623                              <1> 	; 22/11/2023
  2624                              <1> 	; cf = 1
  2625                              <1> init_ac97_codec_err1:
  2626                              <1> 	;stc
  2627                              <1> init_ac97_codec_err2:
  2628 00014880 C3                  <1> 	retn
  2629                              <1> 
  2630                              <1> ;_ac97_codec_init_ok_:
  2631                              <1> 	;mov	dx, GLOB_STS_REG ; 30h
  2632                              <1> 	;add	dx, [NABMBAR]
  2633                              <1> 	;in	eax, dx
  2634                              <1> 	;test	eax, CTRL_ST_CREADY
  2635                              <1> 	;jnz	short _ac97_codec_init_ok
  2636                              <1> 	;stc 
  2637                              <1> 	;retn
  2638                              <1> 
  2639                              <1> _ac97_codec_init_ok:
  2640                              <1> 	; 06/06/2024 (temporary)
  2641                              <1> 	; (this may not be needed)
  2642                              <1> 	;;;
  2643                              <1> 	; 24/05/2024
  2644                              <1> 	; 26/11/2023
  2645                              <1> 	; 23/11/2023
  2646 00014881 31C0                <1> 	xor	eax, eax
  2647                              <1> 	; 21/11/2023 - temporary
  2648                              <1> 	; 19/11/2023
  2649 00014883 B002                <1> 	mov	al, 2 ; force set 16-bit 2-channel PCM
  2650 00014885 66BA2C00            <1> 	mov	dx, GLOB_CNT_REG ; 2Ch
  2651 00014889 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  2652 00014890 EF                  <1> 	out	dx, eax
  2653                              <1> 	;
  2654 00014891 E8F8F8FFFF          <1> 	call	delay1_4ms
  2655                              <1> 	;;;
  2656                              <1> 
  2657                              <1> 	; 23/11/2023 - temporary
  2658                              <1> 	;call	delay_100ms
  2659                              <1> 	; 06/06/2024
  2660                              <1> 	;call	delay1_4ms
  2661                              <1> 
  2662                              <1> 	; 10/06/2017
  2663 00014896 E884020000          <1> 	call 	reset_ac97_controller
  2664                              <1> 
  2665                              <1> 	; 21/11/2023
  2666                              <1> 	;call	delay1_4ms
  2667                              <1> 	
  2668                              <1> 	; 01/06/2024
  2669                              <1> 	; 24/05/2024
  2670                              <1> 	; 23/05/2024
  2671                              <1> 	; 21/11/2023 - temporary
  2672 0001489B E8E1F8FFFF          <1> 	call	delay_100ms ; 06/06/2024
  2673                              <1> 
  2674                              <1> ;	call 	setup_ac97_codec
  2675                              <1> ;
  2676                              <1> ;detect_ac97_codec:
  2677                              <1> ;	retn
  2678                              <1> 
  2679                              <1> setup_ac97_codec:
  2680                              <1> 	; 06/06/2024 - TRDOS 386 v2.0.8
  2681                              <1> 	;;;
  2682 000148A0 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  2683 000148A7 6683C22A            <1> 	add	dx, CODEC_EXT_AUDIO_CTRL_REG ; 2Ah
  2684 000148AB 66ED                <1> 	in	ax, dx
  2685                              <1> 
  2686                              <1> 	;and	al, ~BIT1 ; Clear DRA
  2687 000148AD 24FC                <1> 	and	al, ~(BIT1+BIT0) ; Clear DRA+VRA
  2688                              <1> 	;or	al, BIT0  ; Set VRA
  2689                              <1> 
  2690 000148AF 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  2691 000148B6 6683C22A            <1> 	add	dx, CODEC_EXT_AUDIO_CTRL_REG ; 2Ah
  2692 000148BA 66EF                <1> 	out	dx, ax
  2693                              <1> 	;;;
  2694                              <1> 
  2695                              <1> 	; 24/11/2023
  2696                              <1> 	; 19/11/2023 - TRDOS 386 v2.0.7
  2697 000148BC C605[248F0100]01    <1> 	mov	byte [VRA], 1
  2698                              <1> 
  2699                              <1> 	; 25/11/2023 - temporary
  2700                              <1> 	;jmp	short vra_not_supported
  2701                              <1> 
  2702                              <1> 	; 23/05/2024
  2703                              <1> 	; 18/05/2024
  2704                              <1> 	;call	delay1_4ms ; 06/06/2024
  2705                              <1> 	;call	delay_100ms
  2706                              <1> 
  2707                              <1> ; 06/06/2024
  2708                              <1> ; 01/06/2024
  2709                              <1> %if 0
  2710                              <1> 	; 24/05/2024
  2711                              <1> 	; 23/05/2024
  2712                              <1> 	mov	dx, [NAMBAR]
  2713                              <1> 	add	dx, CODEC_EXT_AUDIO_REG	; 28h
  2714                              <1> 	in	ax, dx
  2715                              <1> 	
  2716                              <1> 	; 18/05/2024
  2717                              <1> 	; 02/12/2023
  2718                              <1> 	call	delay1_4ms
  2719                              <1> 	; 17/05/2024
  2720                              <1> 	;call	delay_100ms
  2721                              <1> 	;
  2722                              <1> 	test	al, 1 ; BIT0 ; Variable Rate Audio bit
  2723                              <1> 	jz	short vra_not_supported
  2724                              <1> 
  2725                              <1> 	mov	dx, [NAMBAR]
  2726                              <1> 	add	dx, CODEC_EXT_AUDIO_CTRL_REG ; 2Ah
  2727                              <1> 	in	ax, dx
  2728                              <1> 
  2729                              <1> 	; 06/06/2024
  2730                              <1> 	; 23/05/2024
  2731                              <1> 	; 02/12/2023
  2732                              <1> 	;call	delay1_4ms
  2733                              <1> 	;call	delay_100ms ; 18/05/2024
  2734                              <1> 	; 24/05/2024
  2735                              <1> 	;call	delay1_4ms
  2736                              <1> 	;call	delay1_4ms
  2737                              <1> 	;call	delay1_4ms
  2738                              <1> 
  2739                              <1> 	;and	al, ~BIT1 ; Clear DRA
  2740                              <1> 	;;;
  2741                              <1> 	; 01/06/2024
  2742                              <1> 	and	al, ~(BIT1+BIT0) ; Clear DRA+VRA
  2743                              <1> 	;;;
  2744                              <1> 	; 04/06/2024
  2745                              <1> 	;mov	dx, [NAMBAR]
  2746                              <1> 	;add	dx, CODEC_EXT_AUDIO_CTRL_REG ; 2Ah
  2747                              <1> 	;;;
  2748                              <1> 	out	dx, ax
  2749                              <1> %endif
  2750                              <1> 
  2751                              <1> 	; 04/06/2024
  2752 000148C3 E8C6F8FFFF          <1> 	call	delay1_4ms
  2753                              <1> 	
  2754                              <1> 	; 01/06/2024
  2755                              <1> 	; check VRA
  2756 000148C8 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  2757 000148CF 6683C228            <1> 	add	dx, CODEC_EXT_AUDIO_REG	; 28h
  2758 000148D3 66ED                <1> 	in	ax, dx
  2759                              <1> 
  2760                              <1> 	; 06/06/2024
  2761                              <1> 	;call	delay1_4ms
  2762                              <1> 	
  2763 000148D5 A801                <1> 	test	al, 1 ; BIT0	; Variable Rate Audio bit
  2764 000148D7 746F                <1> 	jz	short vra_not_supported
  2765                              <1> 
  2766 000148D9 6640                <1> 	inc	ax ; 0FFh -> 0
  2767 000148DB 753D                <1> 	jnz	short not_alc ; skip ALC850 (and ALC655) checking
  2768                              <1> 	; ax = -1 -> 0 
  2769                              <1> 
  2770                              <1> 	;;;;
  2771                              <1> 	; 06/06/2024 (temporary!?)
  2772                              <1> 	; check ALC850
  2773                              <1> 	; (which does not support VRA but it may not be detected)
  2774                              <1> 	;
  2775 000148DD E8ACF8FFFF          <1> 	call	delay1_4ms
  2776                              <1> 	;
  2777 000148E2 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  2778 000148E9 6683C27C            <1> 	add	dx, CODEC_VENDOR_ID1 ; 7Ch
  2779 000148ED 66ED                <1> 	in	ax, dx
  2780 000148EF C1E010              <1> 	shl	eax, 16 ; *
  2781                              <1> 	;cmp	ax, 414Ch ; VENDOR_ID - 'AL'
  2782                              <1> 	;jne	short not_alc
  2783 000148F2 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  2784 000148F9 6683C27E            <1> 	add	dx, CODEC_VENDOR_ID2 ; 7Eh
  2785 000148FD 66ED                <1> 	in	ax, dx
  2786                              <1> 	;inc	edx
  2787                              <1> 	;inc	edx
  2788                              <1> 	;in	ax, dx ; VENDOR ID2
  2789                              <1> 
  2790 000148FF 40                  <1> 	inc	eax ; 0FFFFFFFFh -> 0 ; 0 -> 1
  2791 00014900 7446                <1> 	jz	short vra_not_supported
  2792 00014902 48                  <1> 	dec	eax ; 1 -> 0
  2793 00014903 7443                <1> 	jz	short vra_not_supported	
  2794                              <1> 
  2795 00014905 C1C810              <1> 	ror	eax, 16
  2796 00014908 663D4C41            <1> 	cmp	ax, 414Ch ; VENDOR_ID - 'AL'
  2797 0001490C 750C                <1> 	jne	short not_alc
  2798 0001490E C1C010              <1> 	rol	eax, 16
  2799                              <1> 	
  2800                              <1> 	; ALC850
  2801 00014911 80FC47              <1> 	cmp	ah, 47h ; 'G'
  2802 00014914 7504                <1> 	jne	short not_alc
  2803 00014916 3C90                <1> 	cmp	al, 90h
  2804                              <1> 	;cmp	ax, 4790h ; VENDOR ID - 'G' ; bit 8-15
  2805                              <1> 			  ; CHIP ID - 1001b ; bit 4-7
  2806                              <1> 			  ; Version Number - 0 ; bit 0-3
  2807                              <1> 	;jne	short not_alc850 ; not_alc
  2808 00014918 742E                <1> 	je	short vra_not_supported
  2809                              <1> 	;
  2810                              <1> ; 06/06/2024
  2811                              <1> %if 0
  2812                              <1> not_alc850:
  2813                              <1> 	; ALC655
  2814                              <1> 	cmp	al, 60h
  2815                              <1> 	;cmp	ax, 4760h ; VENDOR ID - 'G' ; bit 8-15
  2816                              <1> 			  ; CHIP ID - 0110b ; bit 4-7
  2817                              <1> 			  ; Version Number - 0 ; bit 0-3
  2818                              <1> 	;jne	short not_alc655
  2819                              <1> 	je	short vra_not_supported
  2820                              <1> 	;
  2821                              <1> not_alc655:
  2822                              <1> %endif
  2823                              <1> not_alc:
  2824                              <1> 	; 06/06/2024
  2825                              <1> 
  2826 0001491A 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  2827 00014921 6683C22A            <1> 	add	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  2828 00014925 66ED                <1> 	in	ax, dx
  2829                              <1> 
  2830                              <1> 	;and	al, ~BIT1 ; Clear DRA
  2831                              <1> 
  2832 00014927 0C01                <1> 	or	al, AC97_EA_VRA ; 1 ; 04/11/2023
  2833                              <1> 	
  2834                              <1> 	; 06/06/2024
  2835                              <1> 	; 04/06/2024
  2836                              <1> 	;mov	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  2837                              <1> 	;add	dx, [NAMBAR]
  2838                              <1> 
  2839 00014929 66EF                <1> 	out	dx, ax		; Enable variable rate audio
  2840                              <1> 
  2841                              <1> 	; 01/06/2024
  2842 0001492B B90A000000          <1> 	mov	ecx, 10
  2843                              <1> 	; 21/11/2023
  2844                              <1> 	;mov	cl, 10
  2845                              <1> check_vra:
  2846                              <1> 	; 01/06/2024
  2847                              <1> 	;call	delay_100ms
  2848 00014930 E859F8FFFF          <1> 	call	delay1_4ms
  2849                              <1> 
  2850                              <1> 	;;;
  2851                              <1> 	; 04/06/2024
  2852 00014935 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  2853 0001493C 6683C22A            <1> 	add	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  2854                              <1> 	;;;
  2855                              <1> 
  2856 00014940 66ED                <1> 	in	ax, dx
  2857                              <1> 
  2858                              <1> 	; 24/05/2024
  2859                              <1> 	; 18/05/2024
  2860                              <1> 	; 02/12/2023
  2861                              <1> 	;call	delay1_4ms
  2862                              <1> 
  2863                              <1> 	;test	al, AC97_EA_VRA ; 1
  2864                              <1> 	; 04/06/2024
  2865 00014942 2401                <1> 	and	al, AC97_EA_VRA ; 1
  2866 00014944 7508                <1> 	jnz	short vra_ok
  2867                              <1> 
  2868 00014946 E2E8                <1> 	loop	check_vra
  2869                              <1> 
  2870                              <1> vra_not_supported:	; 24/11/2023
  2871                              <1> 	; VRA is not usable
  2872                              <1> 	;mov	byte [VRA], 0
  2873 00014948 FE0D[248F0100]      <1> 	dec	byte [VRA]
  2874                              <1> 
  2875                              <1> ; 03/06/2024
  2876                              <1> %if 0
  2877                              <1> 	; 02/06/2024
  2878                              <1> 	jmp	short set_volume
  2879                              <1> 
  2880                              <1> 	; 02/06/2024
  2881                              <1> set_sampling_rate:
  2882                              <1> 	mov	dx, [NAMBAR]
  2883                              <1> 	add	dx, CODEC_PCM_FRONT_DACRATE_REG
  2884                              <1> 	out	dx, ax
  2885                              <1> 	retn
  2886                              <1> 
  2887                              <1> 	; 02/06/2024
  2888                              <1> get_sampling_rate:
  2889                              <1> 	mov	dx, CODEC_PCM_FRONT_DACRATE_REG
  2890                              <1> 	add	dx, [NAMBAR]
  2891                              <1> 	in	ax, dx
  2892                              <1> 	retn
  2893                              <1> %endif
  2894                              <1> 
  2895                              <1> vra_ok:
  2896                              <1> 
  2897                              <1> ; 03/06/2024
  2898                              <1> %if 0
  2899                              <1> 	; 02/06/2024
  2900                              <1> 	; a second test for verifying VRA status
  2901                              <1> 	; (may be needed for ALC850 codec and CK804 controller)
  2902                              <1> 	
  2903                              <1> 	call	get_sampling_rate
  2904                              <1> 	or	ax, ax
  2905                              <1> 	jz	short vra_not_supported
  2906                              <1> 	cmp	ax, 48000
  2907                              <1> 	jne	short set_volume
  2908                              <1> 	mov	ax, 24000
  2909                              <1> 	call	set_sampling_rate
  2910                              <1> 	call	get_sampling_rate
  2911                              <1> 	cmp	ax, 48000
  2912                              <1> 	je	short vra_not_supported
  2913                              <1> 	mov	ax, 48000
  2914                              <1> 	call	set_sampling_rate
  2915                              <1> 	;call	get_sampling_rate
  2916                              <1> %endif
  2917                              <1> 
  2918                              <1> 	; 02/06/2024
  2919                              <1> set_volume:
  2920                              <1> 	; 24/05/2024
  2921                              <1> 	; 18/05/2024 - TRDOS 386 v2.0.8
  2922                              <1> 	; 20/11/2023
  2923                              <1> 	; 19/11/2023 - TRDOS 386 v2.0.7
  2924                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  2925                              <1> 	; 22/07/2020
  2926                              <1> 	; 10/06/2017
  2927                              <1> 	; 29/05/2017
  2928                              <1> 
  2929                              <1> 	;mov	eax, 0202h
  2930                              <1> 	; 21/11/2023
  2931                              <1> 	;mov	eax, 0B0Bh
  2932                              <1> 	; 23/11/2023
  2933 0001494E B81D1D0000          <1> 	mov	eax, 1D1Dh
  2934 00014953 66A3[288F0100]      <1> 	mov	[audio_master_volume], ax
  2935                              <1> 	; 24/05/2024
  2936 00014959 66A3[2A8F0100]      <1> 	mov	[audio_pcmo_volume], ax
  2937                              <1> 	;mov	ax, 1F1Fh ; 31, 31
  2938                              <1> 
  2939                              <1> 	; 21/11/2023
  2940                              <1> 	;push	eax
  2941                              <1> 	
  2942                              <1> 	; 20/11/2023
  2943                              <1> 	;mov	ax, 0B0Bh
  2944                              <1> 	; 23/11/2023
  2945 0001495F 66B80202            <1> 	mov	ax, 0202h
  2946                              <1> 
  2947 00014963 668B15[F08E0100]    <1>   	mov	dx, [NAMBAR]
  2948 0001496A 6683C202            <1>   	add	dx, CODEC_MASTER_VOL_REG	;02h
  2949                              <1> 	;xor	ax, ax 	; volume attenuation = 0 (max. volume)
  2950                              <1> 	; 06/08/2022
  2951                              <1> 	;xor	eax, eax
  2952                              <1> 	; 19/11/2023
  2953 0001496E 66EF                <1> 	out	dx, ax
  2954                              <1> 
  2955                              <1> 	; 01/06/2024
  2956                              <1> 	; 23/05/2024
  2957                              <1> 	; 16/05/2024
  2958                              <1> 	; 20/11/2023
  2959 00014970 E819F8FFFF          <1> 	call	delay1_4ms
  2960                              <1> 	;call	delay1_4ms
  2961                              <1> 	;call	delay1_4ms
  2962                              <1> 	;call	delay1_4ms
  2963                              <1> 	; 21/11/2023 temporary
  2964                              <1> 	;call	delay_100ms ; 18/05/2024
  2965                              <1> 
  2966                              <1> 	; 21/11/2023
  2967                              <1> 	;pop	eax
  2968                              <1> 	
  2969                              <1> 	; 23/11/2023
  2970                              <1> 	; 21/11/2023
  2971                              <1> 	;mov	ax, 0202h
  2972                              <1> 
  2973 00014975 668B15[F08E0100]    <1>   	mov	dx, [NAMBAR]
  2974 0001497C 6683C218            <1>   	add	dx, CODEC_PCM_OUT_REG		;18h
  2975                              <1>   	;xor	ax, ax
  2976 00014980 66EF                <1>   	out	dx, ax
  2977                              <1> 
  2978                              <1> 	; 01/06/2024
  2979                              <1> 	; 23/05/2024
  2980                              <1> 	; 16/05/2024
  2981                              <1> 	; 20/11/2023
  2982                              <1>         ;call	delay1_4ms
  2983                              <1>         ;call	delay1_4ms
  2984                              <1>         ;call	delay1_4ms
  2985                              <1> 	;call	delay1_4ms
  2986                              <1> 	; 21/11/2023 - temporary
  2987                              <1> 	;call	delay_100ms ; 18/05/2024
  2988                              <1> 
  2989                              <1> ; 23/11/2023
  2990                              <1> %if 0
  2991                              <1>   	mov	dx, [NAMBAR]
  2992                              <1>   	add	dx, CODEC_MASTER_MONO_VOL_REG	;06h
  2993                              <1> 	;xor	ax, ax
  2994                              <1>   	out	dx, ax
  2995                              <1> 
  2996                              <1>         ;call	delay1_4ms
  2997                              <1>         ;call	delay1_4ms
  2998                              <1>         ;call	delay1_4ms
  2999                              <1> 	;call	delay1_4ms
  3000                              <1> 
  3001                              <1>   	mov	dx, [NAMBAR]
  3002                              <1>   	add	dx, CODEC_PCBEEP_VOL_REG	;0Ah
  3003                              <1>   	;xor	ax, ax
  3004                              <1>   	out	dx, ax
  3005                              <1> 
  3006                              <1>         ;call	delay1_4ms
  3007                              <1>         ;call	delay1_4ms
  3008                              <1>         ;call	delay1_4ms
  3009                              <1> 	;call	delay1_4ms
  3010                              <1> 
  3011                              <1> 	mov	ax, 8008h ; Mute
  3012                              <1>   	mov	dx, [NAMBAR]
  3013                              <1> 	; 22/07/2020
  3014                              <1> 	add	dx, CODEC_PHONE_VOL_REG		;0Ch
  3015                              <1> 				 ; AC97_PHONE_VOL ; TAD Input (Mono)
  3016                              <1>   	out	dx, ax
  3017                              <1> 
  3018                              <1>         ;call	delay1_4ms
  3019                              <1>         ;call	delay1_4ms
  3020                              <1>         ;call	delay1_4ms
  3021                              <1> 	;call	delay1_4ms
  3022                              <1> 
  3023                              <1>         mov	ax, 0808h
  3024                              <1>   	mov	dx, [NAMBAR]
  3025                              <1>         add	dx, CODEC_LINE_IN_VOL_REG ;10h ; Line Input (Stereo)
  3026                              <1>   	out	dx, ax
  3027                              <1> 
  3028                              <1>         ;call	delay1_4ms
  3029                              <1>         ;call	delay1_4ms
  3030                              <1>         ;call	delay1_4ms
  3031                              <1> 	;call	delay1_4ms
  3032                              <1> 
  3033                              <1> 	;mov	ax, 0808h
  3034                              <1>   	mov	dx, [NAMBAR]
  3035                              <1>         add	dx, CODEC_CD_VOL_REG ;12h ; CR Input (Stereo)
  3036                              <1>   	out	dx, ax
  3037                              <1> 
  3038                              <1>         ;call	delay1_4ms
  3039                              <1>         ;call	delay1_4ms
  3040                              <1>         ;call	delay1_4ms
  3041                              <1> 	;call	delay1_4ms
  3042                              <1> 
  3043                              <1> 	;mov	ax, 0808h
  3044                              <1>   	mov	dx, [NAMBAR]
  3045                              <1>         add	dx, CODEC_AUX_VOL_REG ;16h ; Aux Input (Stereo)
  3046                              <1>   	out	dx, ax
  3047                              <1> 
  3048                              <1>         ;call	delay1_4ms
  3049                              <1>         ;call	delay1_4ms
  3050                              <1>         ;call	delay1_4ms
  3051                              <1>         ;call	delay1_4ms
  3052                              <1> 
  3053                              <1> 	; 21/11/2023 - temporary
  3054                              <1> 	;call	delay_100ms
  3055                              <1> %endif
  3056                              <1> 	; 16/05/2024
  3057                              <1> 	;clc
  3058                              <1> 
  3059                              <1> set_volume_ok:
  3060                              <1> 
  3061                              <1> ;detect_ac97_codec:
  3062 00014982 C3                  <1> 	retn
  3063                              <1> 
  3064                              <1> set_ac97_bdl: ; Set AC97 (ICH) Buffer Descriptor List
  3065                              <1> 	; 04/06/2024 - TRDOS 386 v2.0.8
  3066                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  3067                              <1> 	; 17/06/2017
  3068                              <1> 	; 11/06/2017
  3069                              <1> 	; 28/05/2017
  3070                              <1> 	; eax = dma buffer address = [audio_DMA_buff]
  3071                              <1> 	;; ecx = dma buffer buffer size = [audio_dmabuff_size]
  3072                              <1> 
  3073                              <1> 	; 04/06/2024
  3074                              <1> 	; ecx = DMA half buffer size as truncated for 8 byte alignment
  3075                              <1> 
  3076                              <1> 	;shr	ecx, 1 ; dma half buffer size
  3077 00014983 89CE                <1> 	mov	esi, ecx
  3078                              <1> 
  3079 00014985 BF[308F0100]        <1>         mov     edi, audio_bdl_buff	; get BDL address
  3080                              <1> 	;mov	ecx, 32 / 2		; make 32 entries in BDL
  3081                              <1> 	; 06/08/2022
  3082 0001498A 29C9                <1> 	sub	ecx, ecx
  3083 0001498C B110                <1> 	mov	cl, 16
  3084                              <1> 
  3085 0001498E EB05                <1> 	jmp	short s_ac97_bdl1
  3086                              <1> 
  3087                              <1> s_ac97_bdl0:
  3088                              <1> 	; set buffer descriptor 0 to start of data file in memory
  3089                              <1> 
  3090 00014990 A1[0C8F0100]        <1>  	mov	eax, [audio_dma_buff]	; Physical address of DMA buffer
  3091                              <1>  
  3092                              <1> s_ac97_bdl1:
  3093 00014995 AB                  <1> 	stosd				; store dmabuffer1 address
  3094                              <1> 
  3095 00014996 89C2                <1> 	mov	edx, eax
  3096                              <1> 
  3097                              <1> ;
  3098                              <1> ; Buffer Descriptors List
  3099                              <1> ; As stated earlier, each buffer descriptor list is a set of (up to) 32
  3100                              <1> ; descriptors, each 8 bytes in length. Bytes 0-3 of a descriptor entry point
  3101                              <1> ; to a chunk of memory to either play from or record to. Bytes 4-7 of an
  3102                              <1> ; entry describe various control things detailed below.
  3103                              <1> ; 
  3104                              <1> ; Buffer pointers must always be aligned on a Dword boundry.
  3105                              <1> ;
  3106                              <1> 
  3107                              <1> ;IOC	equ     BIT31			; Fire an interrupt whenever this
  3108                              <1> 					; buffer is complete.
  3109                              <1> 
  3110                              <1> ;BUP	equ     BIT30			; Buffer Underrun Policy.
  3111                              <1> 					; if this buffer is the last buffer
  3112                              <1> 					; in a playback, fill the remaining
  3113                              <1> 					; samples with 0 (silence) or not.
  3114                              <1>   					; It's a good idea to set this to 1
  3115                              <1> 					; for the last buffer in playback,
  3116                              <1> 					; otherwise you're likely to get a lot
  3117                              <1> 					; of noise at the end of the sound.
  3118                              <1> 
  3119                              <1> ;
  3120                              <1> ; Bits 15:0 contain the length of the buffer, in number of samples, which
  3121                              <1> ; are 16 bits each, coupled in left and right pairs, or 32bits each.
  3122                              <1> ; Luckily for us, that's the same format as .wav files.
  3123                              <1> ;
  3124                              <1> ; A value of FFFF is 65536 samples. Running at 44.1Khz, that's just about
  3125                              <1> ; 1.5 seconds of sample time. FFFF * 32bits is 1FFFFh bytes or 128k of data.
  3126                              <1> ;
  3127                              <1> ; A value of 0 in these bits means play no samples.
  3128                              <1> ;
  3129                              <1> 
  3130 00014998 89F0                <1> 	mov	eax, esi ; DMA half buffer size
  3131                              <1> 
  3132                              <1> 		; 04/06/2024 - Erdogan Tan
  3133                              <1> 		; NOTE: I have changed DMA half buffer size to truncated
  3134                              <1> 		; (8 byte aligned) audio buffer size for smooth audio playing
  3135                              <1> 		; (it was page border aligned before June 4, 2024)
  3136                              <1> 		;
  3137                              <1> 		; For example:
  3138                              <1> 		;    For 65416 bytes audio buffer (22kHz, 16bit samples)
  3139                              <1> 		;       (user's audio buff virtual addr is mapped to physical)
  3140                              <1> 		;	((kernel's and user's audio buff pages are same)) 
  3141                              <1> 		;    1) Memory allocation (of it) is 65536 bytes
  3142                              <1> 		;    2) DMA half buffer size is 65416 bytes
  3143                              <1> 		;	(it would be 65536 bytes before this modification)
  3144                              <1> 		;	((additional 140 bytes would cause to a noise))	     
  3145                              <1> 		;    3) Total DMA buffer size is 131072 bytes
  3146                              <1> 		;       (the last 240 bytes will not be used for playing)
  3147                              <1> 		;
  3148                              <1> 		; (buffer will be truncated if the size is not a multiple of 8) 
  3149                              <1> 
  3150 0001499A 01C2                <1> 	add	edx, eax
  3151 0001499C D1E8                <1> 	shr	eax, 1	; count of 16 bit samples
  3152                              <1> 	; 19/11/2023
  3153 0001499E 0D000000C0          <1> 	or	eax, IOC+BUP
  3154                              <1> 	;or	eax, IOC ; 11/06/2017
  3155 000149A3 AB                  <1> 	stosd
  3156                              <1> 
  3157                              <1> ; 2nd buffer:
  3158                              <1> 
  3159 000149A4 89D0                <1>         mov	eax, edx ; Physical address of the 2nd half of DMA buffer
  3160 000149A6 AB                  <1> 	stosd		 ; store dmabuffer2 address
  3161                              <1> 
  3162                              <1> ; set length to [audio_dmabuff_size]/2
  3163                              <1> ; Set control (bits 31:16) to BUP, bits 15:0=number of samples
  3164                              <1> ; 
  3165 000149A7 89F0                <1> 	mov	eax, esi ; DMA half buffer size
  3166 000149A9 D1E8                <1> 	shr	eax, 1 ; count of 16 bit samples
  3167                              <1> 	; 19/11/2023
  3168 000149AB 0D000000C0          <1> 	or	eax, IOC+BUP
  3169                              <1> 	;or	eax, IOC ; 11/06/2017
  3170 000149B0 AB                  <1> 	stosd
  3171                              <1> 
  3172 000149B1 E2DD                <1> 	loop    s_ac97_bdl0
  3173                              <1> 	
  3174 000149B3 C3                  <1> 	retn
  3175                              <1> 
  3176                              <1> ac97_start_play:
  3177                              <1> 	; 26/05/2024 - TRDOS 386 v2.0.8
  3178                              <1> 	; 26/11/2023
  3179                              <1> 	; 20/11/2023  
  3180                              <1> 	; 19/11/2023 - TRDOS 386 v2.0.7
  3181                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  3182                              <1> 	; 28/05/2017
  3183                              <1> 	; Derived from 'playWav' procedure in 'ICHWAV.ASM'
  3184                              <1> 	; .wav player for DOS by Jeff Leyda (02/09/2002)
  3185                              <1> 
  3186                              <1> 	; set output rate
  3187                              <1> 	; entry: [audio_freq] = desired sample rate
  3188                              <1> 
  3189                              <1> 	; 21/11/2023 - temporary
  3190                              <1> 	;call	ac97_codec_config
  3191                              <1> 
  3192                              <1> ; 20/11/2023
  3193                              <1> %if 0
  3194                              <1> 	AC97_EA_VRA equ 0001h ; 04/11/2023
  3195                              <1> 		
  3196                              <1> 	mov	dx, [NAMBAR]
  3197                              <1> 	add	dx, CODEC_EXT_AUDIO_CTRL_REG  	; 2Ah
  3198                              <1> 	in	ax, dx
  3199                              <1> 
  3200                              <1> 	; 23/05/2024
  3201                              <1> 	call	delay1_4ms
  3202                              <1> 
  3203                              <1> 	and	al, ~BIT1 ; Clear DRA
  3204                              <1> 	or	al, AC97_EA_VRA ; 1 ; 04/11/2023
  3205                              <1> 	out	dx, ax			; Enable variable rate audio
  3206                              <1> 
  3207                              <1>        ;call	delay1_4ms
  3208                              <1>        ;call	delay1_4ms
  3209                              <1>        ;call	delay1_4ms
  3210                              <1>        ;call	delay1_4ms
  3211                              <1> 
  3212                              <1> 	; 23/05/2024
  3213                              <1> 	call	delay_100ms
  3214                              <1> %endif
  3215                              <1> 
  3216                              <1> 	; 26/11/2023
  3217                              <1> 	; 24/11/2023 - temporary
  3218                              <1> 	;mov	ax, 48000
  3219                              <1> 
  3220                              <1> 	; 20/11/2023
  3221 000149B4 803D[248F0100]01    <1> 	cmp	byte [VRA], 1
  3222 000149BB 7213                <1> 	jb	short skip_set_rate
  3223                              <1> 
  3224 000149BD 66A1[228F0100]      <1> 	mov	ax, [audio_freq]		; sample rate
  3225                              <1> 
  3226                              <1> ;skip_set_rate:	; 24/11/2023
  3227 000149C3 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  3228 000149CA 6683C22C            <1> 	add	dx, CODEC_PCM_FRONT_DACRATE_REG	; 2Ch
  3229 000149CE 66EF                <1> 	out	dx, ax 				; out sample rate
  3230                              <1> 	
  3231                              <1> 	; 01/06/2024
  3232                              <1> 	; 27/11/2023	
  3233                              <1> 	;call	delay1_4ms
  3234                              <1> 	;call	delay1_4ms
  3235                              <1> 	;call	delay1_4ms
  3236                              <1> 	;call	delay1_4ms
  3237                              <1> 	; 27/11/2023 - temporary
  3238                              <1> 	;call	delay_100ms
  3239                              <1> 
  3240                              <1> 	; 26/11/2023
  3241                              <1> skip_set_rate:	; 20/11/2023
  3242                              <1> 
  3243                              <1> 	;; 23/11/2023 - temporary
  3244                              <1> 	;push	ebx
  3245                              <1> 	;mov	ebx, 0B8000h
  3246                              <1> 	;mov	al, 'x'
  3247                              <1> 	;mov	ah, 4Eh
  3248                              <1> 	;mov	[ebx], ax
  3249                              <1> 	;pop	ebx
  3250                              <1> ;
  3251                              <1> ; register reset the DMA engine. This may cause a pop noise on the output
  3252                              <1> ; lines when the device is reset. Prolly a better idea to mute output, then
  3253                              <1> ; reset.
  3254                              <1> ;
  3255                              <1> 	;; 21/11/2023 - temporary
  3256                              <1> 	;; 20/11/2023
  3257                              <1> 	;mov	dx, [NABMBAR]
  3258                              <1> 	;add	dx, PO_CR_REG			; set pointer to Cntl reg
  3259                              <1> 	;mov	al, RR				; set reset
  3260                              <1> 	;out	dx, al				; self clearing bit
  3261                              <1> 
  3262                              <1> 	; 23/11/2023 - temporary
  3263                              <1> 	;call	delay_100ms
  3264                              <1> 
  3265                              <1> ;	mov	edi, audio_bdl_buff
  3266                              <1> ;	mov	edx, [audio_dmabuff_size]
  3267                              <1> ;	shr	edx, 1
  3268                              <1> ;	mov	ecx, 32/2
  3269                              <1> ;ac97_set_bdl_buffer:
  3270                              <1> ;	; 1st half of DMA buffer
  3271                              <1> ;	mov	eax, [audio_dma_buff]
  3272                              <1> ;	push	eax
  3273                              <1> ;	stosd
  3274                              <1> ;	mov	eax, edx ; dma buffer size / 2
  3275                              <1> ;	or	eax, IOC+BUP
  3276                              <1> ;	stosd
  3277                              <1> ;	pop	eax
  3278                              <1> ;	; 2nd half of DMA buffer
  3279                              <1> ;	add	eax, edx
  3280                              <1> ;	stosd
  3281                              <1> ;	mov	eax, edx ; dma buffer size / 2
  3282                              <1> ;	or	eax, IOC+BUP
  3283                              <1> ;	stosd
  3284                              <1> ;	loop	ac97_set_bdl_buffer
  3285                              <1>  	
  3286                              <1> ; tell the DMA engine where to find our list of Buffer Descriptors.
  3287                              <1> ; this 32bit value is a flat mode memory offset (ie no segment:offset)
  3288                              <1> ;
  3289                              <1> ; write NABMBAR+10h with offset of buffer descriptor list
  3290                              <1> ;
  3291 000149D0 B8[308F0100]        <1>         mov	eax, audio_bdl_buff
  3292 000149D5 668B15[F28E0100]    <1> 	mov	dx, [NABMBAR]
  3293 000149DC 6683C210            <1> 	add	dx, PO_BDBAR_REG
  3294 000149E0 EF                  <1> 	out	dx, eax
  3295                              <1> 
  3296                              <1> 	; 01/06/2024
  3297                              <1> 	; 24/05/2024
  3298                              <1> 	; 23/11/2023 - temporary
  3299                              <1> 	;call	delay_100ms
  3300                              <1> 	; 23/05/2024
  3301                              <1> 	;call	delay1_4ms
  3302                              <1> ;
  3303                              <1> ; All set. Let's play some music.
  3304                              <1> ;
  3305                              <1> 	;mov	eax, 31
  3306                              <1> 	; 06/08/2022
  3307 000149E1 29C0                <1> 	sub	eax, eax
  3308 000149E3 B01F                <1> 	mov	al, 31
  3309 000149E5 E846000000          <1> 	call    set_ac97_LastValidIndex
  3310                              <1> 
  3311                              <1> 	; 01/06/2024
  3312                              <1> 	; 24/05/2024
  3313                              <1> 	; 23/11/2023 - temporary
  3314                              <1> 	;call	delay_100ms
  3315                              <1> 	; 23/05/2024
  3316                              <1> 	;call	delay1_4ms
  3317                              <1> 	; 27/05/2024
  3318                              <1> 	;call	delay1_4ms
  3319                              <1> 	;call	delay1_4ms
  3320                              <1> 	;call	delay1_4ms
  3321                              <1> 
  3322 000149EA C605[268F0100]01    <1> 	mov	byte [audio_play_cmd], 1 ; play command (do not stop) !
  3323                              <1> 
  3324                              <1> ac97_play: ; continue to play (after pause)
  3325                              <1> 	; 27/05/2024
  3326                              <1> 	;;;
  3327                              <1> 	; 19/05/2024 - temporary
  3328                              <1> 	; 24/11/2023 - temporary
  3329                              <1> 	;mov	ax, 0202h
  3330                              <1> 	; 23/05/2024
  3331 000149F1 66B81F1F            <1> 	mov	ax, 1F1Fh
  3332 000149F5 662B05[288F0100]    <1> 	sub	ax, [audio_master_volume]
  3333                              <1> 	
  3334 000149FC 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  3335 00014A03 6683C202            <1>   	add	dx, CODEC_MASTER_VOL_REG  ; 02h ; Line Out 
  3336 00014A07 66EF                <1>   	out	dx, ax
  3337                              <1> 
  3338                              <1> 	; 01/06/2024
  3339                              <1> 	; 19/05/2024 - temporary
  3340                              <1> 	;call	delay_100ms
  3341                              <1> 	; 23/05/2024
  3342                              <1> 	;call	delay1_4ms
  3343                              <1> 	; 24/05/2024
  3344                              <1> 	;call	delay1_4ms
  3345                              <1> 	;call	delay1_4ms
  3346                              <1> 	;call	delay1_4ms
  3347                              <1> 
  3348                              <1> 	;mov	ax, 0202h
  3349                              <1> 	; 23/05/2024
  3350                              <1> 	;mov	ax, 1F1Fh
  3351                              <1> 	;sub	ax, [audio_master_volume]
  3352                              <1> 
  3353                              <1> 	; 27/05/2024
  3354 00014A09 66B81F1F            <1> 	mov	ax, 1F1Fh
  3355 00014A0D 662B05[2A8F0100]    <1> 	sub	ax, [audio_pcmo_volume]
  3356                              <1> 	
  3357 00014A14 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  3358 00014A1B 6683C218            <1>   	add	dx, CODEC_PCM_OUT_REG ; 18h ; PCM Out 
  3359 00014A1F 66EF                <1>   	out	dx, ax
  3360                              <1> 
  3361                              <1> 	; 01/06/2024
  3362                              <1> 	; 24/05/2024
  3363                              <1> 	; 23/05/2024
  3364                              <1> 	;call	delay1_4ms
  3365                              <1> 	;call	delay1_4ms
  3366                              <1> 	;call	delay1_4ms
  3367                              <1> 	;call	delay1_4ms
  3368                              <1> 	; 24/05/2024
  3369                              <1> 	;call	delay_100ms
  3370                              <1> 	;;;
  3371                              <1> 
  3372                              <1> 	; 11/06/2017
  3373                              <1> 	; 29/05/2017
  3374                              <1> 	; 28/05/2017
  3375 00014A21 668B15[F28E0100]    <1>         mov     dx, [NABMBAR]
  3376 00014A28 6683C21B            <1>         add     dx, PO_CR_REG		; PCM out control register
  3377                              <1> 	; 26/11/2023
  3378 00014A2C B011                <1> 	mov	al, IOCE+RPBM ; 29/05/2017
  3379                              <1> 	; 24/11/2023
  3380                              <1> 	;mov	al, 1Dh ; (Ref: KolibriOS, intelac97.asm, 'play:')
  3381 00014A2E EE                  <1> 	out     dx, al			; set start!
  3382                              <1> 
  3383                              <1> 	;mov	byte [audio_play_cmd], 1 ; play command (do not stop) !
  3384                              <1> 
  3385 00014A2F C3                  <1> 	retn
  3386                              <1> 
  3387                              <1> ;input AL = index # to stop on
  3388                              <1> set_ac97_LastValidIndex:
  3389                              <1> 	; 28/05/2017
  3390                              <1> 	; Derived from 'setLastValidIndex' procedure in 'ICHWAV.ASM'
  3391                              <1> 	; .wav player for DOS by Jeff Leyda (02/09/2002)
  3392 00014A30 668B15[F28E0100]    <1> 	mov	dx, [NABMBAR]
  3393 00014A37 6683C215            <1> 	add	dx, PO_LVI_REG
  3394 00014A3B EE                  <1>         out     dx, al
  3395                              <1> 	;mov	[audio_lvi], al ; for ac97_int_handler
  3396 00014A3C C3                  <1> 	retn
  3397                              <1> 
  3398                              <1> ac97_volume:
  3399                              <1> 	; 23/05/2024
  3400                              <1> 	; 28/05/2017
  3401                              <1> 	; bl = component (0 = master/playback/lineout volume)
  3402                              <1> 	;		(1 = PCM Out volume) ; 23/05/2024
  3403                              <1> 	; cl = left channel volume level (0 to 31)
  3404                              <1> 	; ch = right channel volume level (0 to 31)
  3405                              <1> 
  3406                              <1> 	; 24/05/2024
  3407 00014A3D 80FB01              <1> 	cmp	bl, 1
  3408 00014A40 7727                <1> 	ja	short ac97_vol_2 ; temporary !
  3409                              <1> 
  3410 00014A42 66B81F1F            <1> 	mov	ax, 1F1Fh ; 31,31
  3411 00014A46 38C1                <1> 	cmp	cl, al
  3412 00014A48 771F                <1> 	ja	short ac97_vol_2
  3413 00014A4A 38E5                <1> 	cmp	ch, ah
  3414 00014A4C 771B                <1> 	ja	short ac97_vol_2
  3415                              <1> 
  3416 00014A4E 08DB                <1> 	or	bl, bl
  3417 00014A50 7518                <1> 	jnz	short ac97_vol_1
  3418                              <1> 
  3419                              <1> 	; 23/05/2024
  3420 00014A52 66BA0200            <1> 	mov	dx, CODEC_MASTER_VOL_REG  ; 02h ; Line Out
  3421                              <1> 	; 24/05/2024
  3422 00014A56 66890D[288F0100]    <1> 	mov	[audio_master_volume], cx
  3423                              <1> ac97_vol_0:
  3424 00014A5D 6629C8              <1> 	sub	ax, cx
  3425                              <1> 	;mov	dx, [NAMBAR]
  3426                              <1> 	;add	dx, CODEC_MASTER_VOL_REG
  3427                              <1>   	; 23/05/2024
  3428 00014A60 660315[F08E0100]    <1> 	add	dx, [NAMBAR]
  3429 00014A67 66EF                <1>   	out     dx, ax
  3430                              <1> 	; 23/05/2024
  3431                              <1> ac97_vol_2:
  3432                              <1> 	; 21/11/2023
  3433                              <1> ;_ac97_ih5:	; 06/08/2022
  3434 00014A69 C3                  <1> 	retn
  3435                              <1> 
  3436                              <1> ac97_vol_1:
  3437                              <1> 	; 24/05/2024
  3438                              <1> 	; 23/05/2024
  3439                              <1> 	;cmp	bl, 1
  3440                              <1> 	;ja	short ac97_vol_2 ; temporary !
  3441                              <1> 	; BL = 1
  3442                              <1> 	; PCM OUT Volume
  3443 00014A6A 66BA1800            <1> 	mov	dx, CODEC_PCM_OUT_REG	; 18h ; PCM out
  3444                              <1> 	; 24/05/2024
  3445 00014A6E 66890D[2A8F0100]    <1> 	mov	[audio_pcmo_volume], cx
  3446 00014A75 EBE6                <1> 	jmp	short ac97_vol_0
  3447                              <1> 
  3448                              <1> ac97_int_handler:
  3449                              <1> 	; 04/06/2024
  3450                              <1> 	; 03/06/2024
  3451                              <1> 	; 02/06/2024 - TRDOS 386 v2.0.8
  3452                              <1> 	; 27/11/2023
  3453                              <1> 	; 24/11/2023
  3454                              <1> 	; 21/11/2023
  3455                              <1> 	; 20/11/2023 - TRDOS 386 v2.0.7
  3456                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  3457                              <1> 	; 12/10/2017
  3458                              <1> 	; 10/10/2017
  3459                              <1> 	; 09/10/2017
  3460                              <1> 	; 13/06/2017, 13/06/2017
  3461                              <1> 	; 10/06/2017, 11/06/2017
  3462                              <1> 	; Interrupt Handler for AC97 (ICH) Audio Controller
  3463                              <1> 	; Note: called by 'dev_IRQ_service'
  3464                              <1> 	; 28/05/2017
  3465                              <1> 
  3466                              <1> 	;push	eax ; * must be saved !
  3467                              <1> 	;push	edx
  3468                              <1> 	;push	ecx
  3469                              <1> 	;push	ebx ; * must be saved !
  3470                              <1> 	;push	esi
  3471                              <1> 	;push	edi
  3472                              <1> 
  3473                              <1> ; 02/06/2024
  3474                              <1> %if 0
  3475                              <1> 
  3476                              <1> 	;cmp	byte [audio_busy], 1
  3477                              <1> 	;jnb	_ac97_ih2 ; busy !
  3478                              <1> 
  3479                              <1> 	; 24/11/2023
  3480                              <1>         ;mov	dx, [NABMBAR]
  3481                              <1> 	;mov	dx, PO_SR_REG
  3482                              <1> 	;in	ax, dx
  3483                              <1> 	;test	al, BCIS ; bit 3, 8
  3484                              <1> 	;jz	short _ac97_ih5
  3485                              <1> 
  3486                              <1> 	; 24/11/2023
  3487                              <1> 	mov	dx, GLOB_STS_REG
  3488                              <1>         add	dx, [NABMBAR]
  3489                              <1> 	in	eax, dx
  3490                              <1> 
  3491                              <1> 	cmp	eax, 0FFFFFFFFh ; -1
  3492                              <1> 	;je	_ac97_ih3 ; exit
  3493                              <1> 	; 06/08/2022
  3494                              <1> 	je	short _ac97_ih5
  3495                              <1> 
  3496                              <1> 	;test	eax, 40h ; PCM Out Interrupt
  3497                              <1> 	; 06/08/2022
  3498                              <1> 	test	al, 40h
  3499                              <1> 	jnz	short _ac97_ih0
  3500                              <1> 
  3501                              <1> 	; 24/11/2023
  3502                              <1> 	test	eax, eax
  3503                              <1> 	;jz	_ac97_ih3 ; exit
  3504                              <1> 	; 06/08/2022
  3505                              <1> 	jz	short _ac97_ih5
  3506                              <1> 
  3507                              <1>  	;mov	dx, GLOB_STS_REG
  3508                              <1>         ;add	dx, [NABMBAR]
  3509                              <1> 	out	dx, eax
  3510                              <1> 	
  3511                              <1> 	;jmp	_ac97_ih3 ; exit
  3512                              <1> 	
  3513                              <1> 	; 06/08/2022
  3514                              <1> 	retn
  3515                              <1> 	; 21/11/2023
  3516                              <1> 	;jmp	short _ac97_ih5
  3517                              <1> 
  3518                              <1> _ac97_ih0:
  3519                              <1> 	; 24/11/2023
  3520                              <1> 	;push	eax
  3521                              <1> 	; 09/10/2017
  3522                              <1> 	cmp	byte [audio_play_cmd], 1
  3523                              <1> 	;jb	short _ac97_ih4 ; stop command !
  3524                              <1> 	; 24/11/2023
  3525                              <1> 	jnb	short _ac97_ih4
  3526                              <1> 
  3527                              <1> 	;mov	dx, GLOB_STS_REG
  3528                              <1>         ;add	dx, [NABMBAR]
  3529                              <1> 	out	dx, eax
  3530                              <1> 	;jmp	short _ac97_stop
  3531                              <1> 
  3532                              <1> 	; 24/11/2023
  3533                              <1> ac97_stop: 
  3534                              <1> 	; 28/05/2017
  3535                              <1> 	mov	byte [audio_play_cmd], 0 ; stop !
  3536                              <1> 
  3537                              <1> %else
  3538                              <1> 	; 02/06/2024
  3539                              <1> _ac97_ih0:
  3540 00014A77 803D[268F0100]01    <1> 	cmp	byte [audio_play_cmd], 1
  3541 00014A7E 7334                <1> 	jnb	short _ac97_ih4	
  3542                              <1> %endif
  3543                              <1> 
  3544                              <1> _ac97_stop: ; 09/10/2017
  3545                              <1> 	; 29/05/2017
  3546                              <1> 	;mov	dx, [NABMBAR]
  3547                              <1> 	;add	dx, PO_CR_REG
  3548                              <1> 	;mov	al, 0
  3549                              <1> 	;out	dx, al
  3550                              <1> 
  3551                              <1> 	; 11/06/2017
  3552 00014A80 30C0                <1> 	xor	al, al ; 0
  3553 00014A82 E813000000          <1> 	call	ac97_po_cmd
  3554                              <1> 
  3555                              <1> 	; (Ref: KolibriOS, intelac97.asm, 'stop:')
  3556                              <1> 	; Clear FIFOE, BCIS, LVBCI (Ref: Intel ICH hub manual)
  3557 00014A87 66B81C00            <1> 	mov     ax, 1Ch
  3558 00014A8B 668B15[F28E0100]    <1> 	mov     dx, [NABMBAR]
  3559 00014A92 6683C216            <1> 	add     dx, PO_SR_REG
  3560 00014A96 66EF                <1> 	out     dx, ax
  3561                              <1> 
  3562                              <1> 	;retn
  3563                              <1> 
  3564                              <1> 	; 11/06/2017
  3565 00014A98 B002                <1> 	mov     al, RR
  3566                              <1> ac97_po_cmd:
  3567                              <1> 	 ;11/06/2017
  3568                              <1> 	; 29/05/2017
  3569 00014A9A 668B15[F28E0100]    <1> 	mov     dx, [NABMBAR]
  3570 00014AA1 6683C21B            <1>         add     dx, PO_CR_REG		; PCM out control register
  3571 00014AA5 EE                  <1> 	out	dx, al
  3572 00014AA6 C3                  <1> 	retn
  3573                              <1> 
  3574                              <1> ; 02/06/2024
  3575                              <1> %if 1
  3576                              <1> 	; 24/11/2023
  3577                              <1> ac97_stop: 
  3578                              <1> 	; 28/05/2017
  3579 00014AA7 C605[268F0100]00    <1> 	mov	byte [audio_play_cmd], 0 ; stop !
  3580 00014AAE EBD0                <1> 	jmp	short _ac97_stop
  3581                              <1> %endif
  3582                              <1> 
  3583                              <1> ac97_pause:
  3584                              <1> 	; 11/06/2017
  3585                              <1> 	; 29/05/2017
  3586 00014AB0 B010                <1> 	mov 	al, IOCE
  3587 00014AB2 EBE6                <1> 	jmp	short ac97_po_cmd
  3588                              <1> 
  3589                              <1> _ac97_ih4:
  3590                              <1> 	;mov	byte [audio_busy], 1
  3591                              <1> 
  3592                              <1> ; 02/06/2024
  3593                              <1> %if 1
  3594                              <1> 	; 24/11/2023 (TRDOS386 'audio.s')
  3595 00014AB4 668B15[F28E0100]    <1>         mov	dx, [NABMBAR]
  3596 00014ABB 6683C216            <1> 	add	dx, PO_SR_REG
  3597 00014ABF 66ED                <1> 	in	ax, dx
  3598                              <1> 
  3599 00014AC1 A808                <1> 	test	al, BCIS ; bit 3, 8
  3600 00014AC3 744C                <1> 	jz	short _ac97_ih2	; 02/06/2024
  3601                              <1> 
  3602                              <1> 	; 02/06/2024
  3603 00014AC5 50                  <1> 	push	eax ; *
  3604                              <1> %else
  3605                              <1> 	; 27/05/2024
  3606                              <1> 	; 24/11/2023
  3607                              <1> 	push	eax
  3608                              <1> 
  3609                              <1> 	mov	ax, 1Ch ; FIFOE(=16)+BCIS(=8)+LVBCI(=4)
  3610                              <1> 	mov	dx, PO_SR_REG
  3611                              <1>         add	dx, [NABMBAR]
  3612                              <1> 	out	dx, ax
  3613                              <1> 
  3614                              <1> 	mov	dx, PO_CIV_REG
  3615                              <1>         add	dx, [NABMBAR]
  3616                              <1> 	in	al, dx
  3617                              <1> 
  3618                              <1> 	;cmp	al, [audio_civ] ; [audio_flag]
  3619                              <1> 	;je	short _ac97_ih2
  3620                              <1> 
  3621                              <1> 	; 21/11/2023
  3622                              <1> 	;mov	[audio_civ], al
  3623                              <1> 	; 20/11/2023
  3624                              <1> 	mov	ah, al
  3625                              <1> 	dec	al
  3626                              <1> 	;inc	al ; 11/06/2017
  3627                              <1> 	and	al, 1Fh
  3628                              <1> %endif
  3629                              <1> 	; 02/06/2024
  3630 00014AC6 66BA1400            <1> 	mov	dx, PO_CIV_REG
  3631 00014ACA 660315[F28E0100]    <1>         add	dx, [NABMBAR]
  3632                              <1> 	;in	ax, dx
  3633                              <1> 	; 03/06/2024
  3634 00014AD1 EC                  <1> 	in	al, dx
  3635                              <1> 			; al = CVI, ah = LVI
  3636                              <1> 	;xchg	ah, al
  3637                              <1> 	;		; al = LVI, ah = CVI
  3638                              <1> 	;cmp	al, ah
  3639                              <1> 	;jne	short _ac97_ih5
  3640                              <1> 	; 03/06/2024
  3641 00014AD2 88C4                <1> 	mov	ah, al
  3642                              <1> 
  3643 00014AD4 FEC8                <1> 	dec	al
  3644 00014AD6 241F                <1> 	and	al, 1Fh
  3645                              <1> 
  3646                              <1> 	;mov	dx, PO_LVI_REG
  3647                              <1> 	;add	dx, [NABMBAR]
  3648 00014AD8 6642                <1>         inc	dx	; 02/06/2024	
  3649 00014ADA EE                  <1> 	out	dx, al
  3650                              <1> 
  3651                              <1> 	; 12/10/2017
  3652                              <1> 	;mov	al, [audio_civ]
  3653                              <1> 	;inc	al
  3654                              <1> 	;and	al, 1
  3655                              <1> 	;mov	[audio_flag], al 
  3656                              <1> 	; 27/11/2023
  3657                              <1> 	; 20/11/2023
  3658                              <1> 	;inc	ah
  3659                              <1> _ac97_ih5:	; 02/06/2024
  3660 00014ADB 80E401              <1> 	and	ah, 1
  3661 00014ADE 8825[188F0100]      <1> 	mov	[audio_flag], ah
  3662                              <1> 
  3663                              <1> 	;; [audio_flag] : 0 = Buffer 1, 1 = Buffer 2
  3664                              <1> 	;
  3665                              <1> 	; 21/11/2023
  3666                              <1> 	;call	ac97_tuneloop
  3667                              <1> 
  3668                              <1> 	; 24/11/2023
  3669                              <1> ac97_tuneloop:
  3670                              <1> 	; 09/10/2017
  3671 00014AE4 8B3D[0C8F0100]      <1> 	mov	edi, [audio_dma_buff]
  3672                              <1> 	; 04/06/2024
  3673                              <1> 	;mov	ecx, [audio_dmabuff_size]
  3674                              <1> 	;shr	ecx, 1 ; dma buff size / 2 = half buffer size
  3675 00014AEA 8B0D[088F0100]      <1> 	mov	ecx, [audio_buff_size]
  3676 00014AF0 80E1F8              <1> 	and	cl, ~7 ; 8 byte aligned
  3677                              <1> 
  3678                              <1> 	; 12/10/2017
  3679 00014AF3 803D[188F0100]00    <1> 	cmp 	byte [audio_flag], 0
  3680 00014AFA 7702                <1> 	ja	short _ac97_ih1  ; Playing Half Buffer 2 (Current: FLAG)
  3681                              <1> 	; Playing Half Buffer 1 (Current: EOL)	
  3682 00014AFC 01CF                <1> 	add	edi, ecx
  3683                              <1> _ac97_ih1: 
  3684                              <1> 	; Update half buffer 2 while playing half buffer 1 (next: FLAG)
  3685                              <1> 	; Update half buffer 1 while playing half buffer 2 (next: EOL)
  3686                              <1> 
  3687 00014AFE 8B35[048F0100]      <1> 	mov	esi, [audio_p_buffer] ; phy addr of audio buff
  3688 00014B04 C1E902              <1> 	shr	ecx, 2 ; half buff size / 4
  3689 00014B07 F3A5                <1> 	rep	movsd
  3690                              <1> 
  3691                              <1> 	; 10/10/2017
  3692                              <1> 	; switch flag value
  3693 00014B09 8035[188F0100]01    <1> 	xor	byte [audio_flag], 1
  3694                              <1> 
  3695                              <1> ; 02/06/2024
  3696                              <1> %if 1
  3697                              <1> 	; 02/06/2024
  3698 00014B10 58                  <1> 	pop	eax ; *
  3699                              <1> _ac97_ih2:
  3700                              <1> 	;mov	ax, 1Ch ; FIFOE(=16)+BCIS(=8)+LVBCI(=4)
  3701 00014B11 66BA1600            <1> 	mov	dx, PO_SR_REG
  3702 00014B15 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  3703 00014B1C 66EF                <1> 	out	dx, ax
  3704                              <1> %else
  3705                              <1> 	; 27/11/2023
  3706                              <1> 	; 21/11/2023 - temporary
  3707                              <1> 	;push	ebx
  3708                              <1> 	;mov	ebx, 0B8002h
  3709                              <1> 	;mov	al, [audio_flag]
  3710                              <1> 	;add	al, '1'
  3711                              <1> 	;mov	ah, 0Fh
  3712                              <1> 	;mov	[ebx], ax
  3713                              <1> 	;pop	ebx
  3714                              <1> 	
  3715                              <1> 	; 12/10/2017
  3716                              <1> 	; [audio_flag] = 0 : Playing dma half buffer 2 (even index value)
  3717                              <1> 			   ; Next buffer (to update) is dma half buff 1
  3718                              <1> 	; 	       = 1 : Playing dma half buffer 1 (odd index value)
  3719                              <1> 			   ; Next buffer (to update) is dma half buff 2
  3720                              <1> 	; 24/11/2023
  3721                              <1> 	;retn
  3722                              <1> 
  3723                              <1> 	;
  3724                              <1> 	; 24/11/2023
  3725                              <1> 	pop	eax
  3726                              <1> 	; 24/11/2023
  3727                              <1> 	; 20/11/2023
  3728                              <1> 	;and	eax, 40h
  3729                              <1>         mov	dx, [NABMBAR]
  3730                              <1> 	add	dx, GLOB_STS_REG
  3731                              <1> 	out	dx, eax
  3732                              <1> 
  3733                              <1> 	;; 13/06/2017
  3734                              <1> 	;mov	al, 11h ; IOCE + RPBM
  3735                              <1> 	;mov	dx, PO_CR_REG
  3736                              <1>         ;add	dx, [NABMBAR]
  3737                              <1> 	;out	dx, al
  3738                              <1> 
  3739                              <1> 	; 24/11/2023
  3740                              <1> 	;mov	dx, [NABMBAR]
  3741                              <1> 	;add	dx, PO_SR_REG	; set pointer to Status reg
  3742                              <1> 	;mov	ax, 1Ch
  3743                              <1> 	;out	dx, ax
  3744                              <1> 
  3745                              <1> 	; 24/11/2023
  3746                              <1> _ac97_ih2:
  3747                              <1> 	;mov	byte [audio_busy], 0
  3748                              <1> %endif
  3749                              <1> 
  3750                              <1> _ac97_ih3:
  3751                              <1> 	;pop	edi
  3752                              <1> 	;pop	esi
  3753                              <1> 	;pop	ebx ; * must be restored !
  3754                              <1> 	;pop	ecx
  3755                              <1> 	;pop	edx
  3756                              <1> 	;pop	eax ; * must be restored !
  3757                              <1> 
  3758 00014B1E C3                  <1> 	retn
  3759                              <1> 
  3760                              <1> reset_ac97_controller:
  3761                              <1> 	; 06/06/2024
  3762                              <1> 	; 01/06/2024
  3763                              <1> 	; 27/05/2024
  3764                              <1> 	; 16/05/2024
  3765                              <1> 	; 10/06/2017
  3766                              <1> 	; 29/05/2017
  3767                              <1> 	; 28/05/2017
  3768                              <1> 	; reset AC97 audio controller registers
  3769 00014B1F 31C0                <1> 	xor     eax, eax
  3770 00014B21 66BA0B00            <1>         mov	dx, PI_CR_REG
  3771 00014B25 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  3772 00014B2C EE                  <1> 	out     dx, al
  3773                              <1> 
  3774                              <1> 	; 16/05/2024
  3775                              <1> 	;call	delay1_4ms
  3776                              <1> 
  3777 00014B2D 66BA1B00            <1>         mov     dx, PO_CR_REG
  3778 00014B31 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  3779 00014B38 EE                  <1> 	out     dx, al
  3780                              <1> 
  3781                              <1> 	; 16/05/2024
  3782                              <1> 	;call	delay1_4ms
  3783                              <1> 
  3784 00014B39 66BA2B00            <1>         mov     dx, MC_CR_REG
  3785 00014B3D 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  3786 00014B44 EE                  <1> 	out     dx, al
  3787                              <1> 
  3788                              <1> 	; 16/05/2024
  3789                              <1> 	;call	delay1_4ms
  3790                              <1> 
  3791 00014B45 B002                <1>         mov     al, RR
  3792 00014B47 66BA0B00            <1>         mov     dx, PI_CR_REG
  3793 00014B4B 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  3794 00014B52 EE                  <1> 	out     dx, al
  3795                              <1> 
  3796                              <1> 	; 16/05/2024
  3797                              <1> 	;call	delay1_4ms
  3798                              <1> 
  3799 00014B53 66BA1B00            <1>         mov     dx, PO_CR_REG
  3800 00014B57 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  3801 00014B5E EE                  <1> 	out     dx, al
  3802                              <1> 
  3803                              <1> 	; 16/05/2024
  3804                              <1> 	;call	delay1_4ms
  3805                              <1> 
  3806 00014B5F 66BA2B00            <1>         mov     dx, MC_CR_REG
  3807 00014B63 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  3808 00014B6A EE                  <1> 	out     dx, al
  3809                              <1> 
  3810                              <1> 	; 27/05/2024
  3811                              <1> 	; 16/05/2024
  3812                              <1> 	;call	delay1_4ms
  3813                              <1> 
  3814 00014B6B C3                  <1> 	retn
  3815                              <1> 
  3816                              <1> ac97_reset:
  3817                              <1> 	; 27/05/2024 - TRDOS 386 v2.0.8
  3818                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  3819                              <1> 	; 10/06/2017
  3820                              <1> 	; 29/05/2017
  3821                              <1> 	; 28/05/2017
  3822 00014B6C E8AEFFFFFF          <1> 	call	reset_ac97_controller
  3823                              <1> 	; 29/05/2017
  3824                              <1> 	;jmp	reset_ac97_codec
  3825                              <1> 	; 27/05/2024
  3826 00014B71 E80BF6FFFF          <1> 	call	delay_100ms
  3827                              <1> reset_ac97_codec:
  3828                              <1> 	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  3829 00014B76 66BA2C00            <1> 	mov	dx, GLOB_CNT_REG ; 2Ch
  3830 00014B7A 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  3831 00014B81 ED                  <1> 	in	eax, dx
  3832                              <1> 
  3833                              <1> 	;test	eax, 2
  3834                              <1> 	; 06/08/2022
  3835 00014B82 A802                <1> 	test	al, 2
  3836 00014B84 7407                <1> 	jz	short _r_ac97codec_cold
  3837                              <1> 
  3838 00014B86 E80F000000          <1> 	call	warm_ac97codec_reset
  3839 00014B8B 7308                <1> 	jnc	short _r_ac97codec_ok
  3840                              <1> _r_ac97codec_cold:
  3841 00014B8D E83B000000          <1>         call    cold_ac97codec_reset
  3842 00014B92 7301                <1>         jnc     short _r_ac97codec_ok
  3843                              <1> 	
  3844                              <1> 	; 16/04/2017
  3845                              <1>         ;xor	eax, eax	; timeout error
  3846                              <1>        	;stc
  3847 00014B94 C3                  <1> 	retn
  3848                              <1> 
  3849                              <1> _r_ac97codec_ok:
  3850 00014B95 31C0                <1>         xor     eax, eax
  3851                              <1>         ;mov	al, VIA_ACLINK_C00_READY ; 1
  3852 00014B97 FEC0                <1>         inc	al
  3853 00014B99 C3                  <1> 	retn
  3854                              <1> 
  3855                              <1> warm_ac97codec_reset:
  3856                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  3857                              <1> 	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  3858                              <1>         ;mov	eax, 6
  3859                              <1> 	; 06/08/2022
  3860 00014B9A 29C0                <1> 	sub	eax, eax
  3861 00014B9C B006                <1> 	mov	al, 6
  3862 00014B9E 66BA2C00            <1> 	mov	dx, GLOB_CNT_REG ; 2Ch
  3863 00014BA2 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  3864 00014BA9 EF                  <1> 	out	dx, eax
  3865                              <1> 
  3866                              <1> 	;mov	ecx, 10	; total 1s
  3867                              <1> 	; 06/08/2022
  3868 00014BAA 31C9                <1> 	xor	ecx, ecx
  3869 00014BAC B10A                <1> 	mov	cl, 10
  3870                              <1> _warm_ac97c_rst_wait:
  3871 00014BAE 51                  <1> 	push	ecx
  3872 00014BAF E8CDF5FFFF          <1> 	call	delay_100ms
  3873 00014BB4 59                  <1> 	pop	ecx
  3874                              <1> 
  3875 00014BB5 66BA3000            <1> 	mov	dx, GLOB_STS_REG ; 30h
  3876 00014BB9 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  3877 00014BC0 ED                  <1> 	in	eax, dx
  3878                              <1> 
  3879 00014BC1 A900030010          <1> 	test	eax, CTRL_ST_CREADY
  3880 00014BC6 7504                <1> 	jnz	short _warm_ac97c_rst_ok
  3881                              <1> 
  3882 00014BC8 49                  <1>         dec     ecx
  3883 00014BC9 75E3                <1>         jnz     short _warm_ac97c_rst_wait
  3884                              <1> 
  3885                              <1> _warm_ac97c_rst_fail:
  3886 00014BCB F9                  <1>         stc
  3887                              <1> _warm_ac97c_rst_ok:
  3888 00014BCC C3                  <1> 	retn
  3889                              <1> 
  3890                              <1> cold_ac97codec_reset:
  3891                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  3892                              <1> 	; 28/05/2017 - Erdogan Tan (Ref: KolibriOS, intelac97.asm)
  3893                              <1>         ;mov	eax, 2
  3894                              <1> 	; 06/08/2022
  3895 00014BCD 31C0                <1> 	xor	eax, eax
  3896 00014BCF B002                <1> 	mov	al, 2
  3897 00014BD1 66BA2C00            <1> 	mov	dx, GLOB_CNT_REG ; 2Ch
  3898 00014BD5 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  3899 00014BDC EF                  <1> 	out	dx, eax
  3900                              <1> 
  3901 00014BDD E89FF5FFFF          <1> 	call	delay_100ms 	; wait 100 ms
  3902 00014BE2 E89AF5FFFF          <1> 	call	delay_100ms 	; wait 100 ms
  3903 00014BE7 E895F5FFFF          <1> 	call	delay_100ms 	; wait 100 ms
  3904 00014BEC E890F5FFFF          <1> 	call	delay_100ms 	; wait 100 ms
  3905                              <1> 
  3906                              <1> 	;mov	ecx, 16	; total 20*100 ms = 2s
  3907                              <1> 	; 06/08/2022
  3908 00014BF1 31C9                <1> 	xor	ecx, ecx
  3909 00014BF3 B110                <1> 	mov	cl, 16
  3910                              <1> _cold_ac97c_rst_wait:
  3911 00014BF5 66BA3000            <1> 	mov	dx, GLOB_STS_REG ; 30h
  3912 00014BF9 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  3913 00014C00 ED                  <1> 	in	eax, dx
  3914                              <1> 
  3915 00014C01 A900030010          <1> 	test	eax, CTRL_ST_CREADY
  3916 00014C06 750B                <1> 	jnz	short _cold_ac97c_rst_ok
  3917                              <1> 
  3918 00014C08 51                  <1> 	push	ecx
  3919 00014C09 E873F5FFFF          <1> 	call	delay_100ms
  3920 00014C0E 59                  <1> 	pop	ecx
  3921                              <1> 
  3922 00014C0F 49                  <1>         dec     ecx
  3923 00014C10 75E3                <1>         jnz     short _cold_ac97c_rst_wait
  3924                              <1> 
  3925                              <1> _cold_ac97c_rst_fail:
  3926 00014C12 F9                  <1>         stc
  3927                              <1> _cold_ac97c_rst_ok:
  3928 00014C13 C3                  <1> 	retn
  3929                              <1> 
  3930                              <1> sb16_current_sound_data:
  3931                              <1> 	; 05/06/2024
  3932                              <1> 	; 04/06/2024 - TRDOS 386 v2.0.8
  3933                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  3934                              <1> 	; 20/08/2017
  3935                              <1> 	; 24/06/2017
  3936                              <1> 	; 22/06/2017
  3937                              <1> 	; get current sound (PCM out) data for graphics
  3938                              <1> 	; (for Sound Blaster 16)
  3939                              <1> 	; ebx = Physical address (on page boundary)
  3940                              <1> 	; ecx = Byte count
  3941                              <1> 	; [audio_buff_size]
  3942                              <1> 
  3943                              <1> 	;;mov	edi, [audio_buff_size]
  3944                              <1> 	;mov	edi, [audio_dmabuff_size]
  3945                              <1> 	;mov	esi, [audio_dma_buff]
  3946                              <1> 
  3947 00014C14 39CF                <1> 	cmp	edi, ecx
  3948 00014C16 7302                <1> 	jnb	short sb16_gcd_0
  3949 00014C18 89F9                <1> 	mov	ecx, edi
  3950                              <1> sb16_gcd_0:
  3951                              <1> 	; 06/08/2022
  3952 00014C1A 31C0                <1> 	xor	eax, eax
  3953                              <1> 	; 20/08/2017
  3954 00014C1C 803D[208F0100]10    <1> 	cmp	byte [audio_bps], 16
  3955 00014C23 750C                <1> 	jne	short sb16_gcd_1 ; 8 bit DMA channel
  3956 00014C25 E4C6                <1> 	in	al, 0C6h ; DMA channel 5 count register
  3957                              <1> 	;mov	dl, al
  3958                              <1> 	; 06/08/2022
  3959 00014C27 88C4                <1> 	mov	ah, al
  3960 00014C29 E4C6                <1> 	in	al, 0C6h
  3961                              <1> 	;mov	dh, al
  3962                              <1> 	;movzx	eax, dx
  3963                              <1> 	; 06/08/2022
  3964 00014C2B 86C4                <1> 	xchg	ah, al
  3965 00014C2D D1E0                <1> 	shl	eax, 1 ; word count -> byte count
  3966 00014C2F EB4C                <1> 	jmp	short sb16_gcd_2
  3967                              <1> sb16_gcd_1:
  3968 00014C31 E403                <1> 	in	al, 03h ; DMA channel 1 count register
  3969                              <1> 	;mov	dl, al
  3970                              <1> 	; 06/08/2022
  3971 00014C33 88C4                <1> 	mov	ah, al
  3972 00014C35 E403                <1> 	in	al, 03h
  3973                              <1> 	;mov	dh, al
  3974                              <1> 	;movzx	eax, dx
  3975                              <1> 	; 06/08/2022
  3976 00014C37 86C4                <1> 	xchg	ah, al
  3977 00014C39 EB42                <1> 	jmp	short sb16_gcd_2
  3978                              <1> ;sb16_gcd_2:
  3979                              <1> ;	cmp	eax, ecx
  3980                              <1> ;	jnb	short sb16_gcd_3
  3981                              <1> ;	; remain count < graphics bytes
  3982                              <1> ;	mov	eax, ecx ; fix remain count to data size
  3983                              <1> ;sb16_gcd_3:
  3984                              <1> ;	sub	edi, eax
  3985                              <1> ;	jna	short sb16_gcd_4
  3986                              <1> ;	add	esi, edi ; dma buffer offset
  3987                              <1> ;sb16_gcd_4:
  3988                              <1> ;	mov	edi, ebx ; buffer address (for graphics) 
  3989                              <1> ;	mov	[u.r0], ecx
  3990                              <1> ;	rep	movsb
  3991                              <1> ;	retn
  3992                              <1> 
  3993                              <1> get_current_sound_data:
  3994                              <1> 	; 05/06/2024
  3995                              <1> 	; 04/06/2024
  3996                              <1> 	; 24/06/2017
  3997                              <1> 	; 22/06/2017
  3998                              <1> 	; get current sound (PCM out) data for graphics
  3999                              <1> 	;
  4000                              <1> 	; ebx = Physical address (on page boundary)
  4001                              <1> 	; ecx = Byte count
  4002                              <1> 	; [audio_buff_size]
  4003                              <1> 
  4004                              <1> 	;mov	edi, [audio_buff_size]
  4005                              <1> 	;;; 
  4006                              <1> 	; 04/06/2024
  4007                              <1> 	;mov	edi, [audio_dmabuff_size]
  4008                              <1> 	; 05/06/2024
  4009                              <1> 	;mov	edi, [audio_buff_size]
  4010 00014C3B 8B3D[148F0100]      <1> 	mov	edi, [dma_hbuff_size]
  4011                              <1> 	;;;
  4012 00014C41 8B35[0C8F0100]      <1> 	mov	esi, [audio_dma_buff]
  4013                              <1> 
  4014                              <1> 	;;;
  4015                              <1> 	; 04/06/2024
  4016                              <1> 	;cmp	byte [audio_device], 2
  4017                              <1> 	;jb	short sb16_current_sound_data ; = 1
  4018                              <1> 	;shr	edi, 1
  4019                              <1> 
  4020                              <1> 	; 04/06/2024
  4021 00014C47 803D[ED8E0100]01    <1> 	cmp	byte [audio_device], 1
  4022 00014C4E 7704                <1> 	ja	short gcd_1
  4023 00014C50 D1E7                <1> 	shl	edi, 1 ; [audio_dmabuff_size] = 2 * edi
  4024                              <1> 	; 05/06/2024
  4025                              <1> 	; edi = [dma_hbuff_size] * 2
  4026 00014C52 EBC0                <1> 	jmp	short sb16_current_sound_data
  4027                              <1> gcd_1:
  4028                              <1> 	;;;
  4029                              <1> 
  4030                              <1> ; 04/06/2024
  4031                              <1> %if 0
  4032                              <1> 	cmp	edi, ecx
  4033                              <1> 	jnb	short gcd_0
  4034                              <1> 	mov	ecx, edi
  4035                              <1> gcd_0:
  4036                              <1> %endif
  4037 00014C54 803D[ED8E0100]03    <1> 	cmp	byte [audio_device], 3
  4038 00014C5B 7237                <1> 	jb	short ac97_current_sound_data ; = 2
  4039                              <1> 	; = 3
  4040                              <1> vt8233_current_sound_data:
  4041                              <1> 	; 05/06/2024
  4042                              <1> 	; 04/06/2024 - TRDOS 386 v2.0.8
  4043                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  4044                              <1> 	; 22/06/2017
  4045                              <1> 	; 21/06/2017
  4046                              <1> 	; get current sound (PCM out) data for graphics
  4047                              <1> 	; (for VT 8233, VT 8237R)
  4048                              <1> 	; ebx = Physical address (on page boundary)
  4049                              <1> 	; ecx = Byte count
  4050                              <1> 	; [audio_buff_size]
  4051                              <1> 	
  4052                              <1> 	;;mov	edi, [audio_buff_size]
  4053                              <1> 	;mov	edi, [audio_dmabuff_size]
  4054                              <1> 	;mov	esi, [audio_dma_buff]
  4055                              <1> 	;shr	edi, 1
  4056                              <1> 	;cmp	edi, ecx
  4057                              <1> 	;jnb	short vt8233_gcd_1
  4058                              <1> 	;mov	ecx, edi
  4059                              <1> 
  4060                              <1> 	;;;
  4061                              <1> 	; 04/06/2024
  4062                              <1> 	; edi = [audio_buff_size]
  4063                              <1> 	; 05/06/2024
  4064                              <1> 	;and	di, ~1	; word alignment
  4065                              <1> 	; edi = [dma_hbuff_size]
  4066 00014C5D 39CF                <1> 	cmp	edi, ecx
  4067 00014C5F 7302                <1> 	jnb	short vt8233_gcd_1
  4068 00014C61 89F9                <1> 	mov	ecx, edi
  4069                              <1> 	;;;
  4070                              <1> 
  4071                              <1> vt8233_gcd_1:
  4072                              <1> 	;mov	edx, VIA_REG_OFFSET_CURR_COUNT
  4073                              <1> 	; 06/08/2022
  4074 00014C63 31D2                <1> 	xor	edx, edx
  4075 00014C65 B20C                <1> 	mov	dl, VIA_REG_OFFSET_CURR_COUNT
  4076 00014C67 E875F5FFFF          <1> 	call	ctrl_io_r32
  4077 00014C6C 89C2                <1> 	mov	edx, eax ; remain count (bits 23-0),
  4078                              <1> 			 ; SGD index (bits 31-24) 
  4079 00014C6E 81E200000001        <1> 	and	edx, 1000000h ; SGD index (0 = 1st half)
  4080 00014C74 7402                <1> 	jz	short vt8233_gcd_2
  4081                              <1> 	; the second half of DMA buffer
  4082 00014C76 01FE                <1> 	add	esi, edi 
  4083                              <1> vt8233_gcd_2:
  4084 00014C78 25FFFFFF00          <1> 	and	eax, 0FFFFFFh ; bits 23-0
  4085                              <1> ac97_gcd_2:
  4086                              <1> sb16_gcd_2:
  4087 00014C7D 39C8                <1> 	cmp	eax, ecx
  4088 00014C7F 7302                <1> 	jnb	short vt8233_gcd_3 
  4089                              <1> 	; remain count < graphics bytes
  4090 00014C81 89C8                <1> 	mov	eax, ecx ; fix remain count to data size
  4091                              <1> vt8233_gcd_3:
  4092 00014C83 29C7                <1> 	sub	edi, eax
  4093 00014C85 7602                <1> 	jna	short vt8233_gcd_4
  4094 00014C87 01FE                <1> 	add	esi, edi ; dma buffer offset
  4095                              <1> vt8233_gcd_4:
  4096 00014C89 89DF                <1> 	mov	edi, ebx ; buffer address (for graphics)
  4097 00014C8B 890D[74940100]      <1> 	mov	[u.r0], ecx
  4098 00014C91 F3A4                <1> 	rep	movsb
  4099                              <1> vt8233_gcd_5:
  4100 00014C93 C3                  <1> 	retn
  4101                              <1> 
  4102                              <1> ac97_current_sound_data:
  4103                              <1> 	; 05/06/2024
  4104                              <1> 	; 04/06/2024 - TRDOS 386 v2.0.8
  4105                              <1> 	; 23/06/2017
  4106                              <1> 	; 22/06/2017
  4107                              <1> 	; get current sound (PCM out) data for graphics
  4108                              <1> 	; (for AC'97, ICH)
  4109                              <1> 	; ebx = Physical address (on page boundary)
  4110                              <1> 	; ecx = Byte count
  4111                              <1> 	; [audio_buff_size]
  4112                              <1> 	
  4113                              <1> 	;;mov	edi, [audio_buff_size]
  4114                              <1> 	;mov	edi, [audio_dmabuff_size]
  4115                              <1> 	;mov	esi, [audio_dma_buff]
  4116                              <1> 	;shr	edi, 1
  4117                              <1> 	;cmp	edi, ecx
  4118                              <1> 	;jnb	short ac97_gcd_0
  4119                              <1> 	;mov	ecx, edi
  4120                              <1> 
  4121                              <1> 	;;;
  4122                              <1> 	; 04/06/2024
  4123                              <1> 	; edi = [audio_buff_size]
  4124                              <1> 	; 05/06/2024
  4125                              <1> 	;and	di, ~7	; 8 byte alignment
  4126                              <1> 	; edi = [dma_hbuff_size]
  4127 00014C94 39CF                <1> 	cmp	edi, ecx
  4128 00014C96 7302                <1> 	jnb	short ac97_gcd_0
  4129 00014C98 89F9                <1> 	mov	ecx, edi
  4130                              <1> 	;;;
  4131                              <1> 
  4132                              <1> ac97_gcd_0:
  4133 00014C9A 66BA1400            <1> 	mov	dx, PO_CIV_REG ; Position In Current Buff Reg
  4134 00014C9E 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  4135 00014CA5 EC                  <1> 	in	al, dx ; current index value
  4136 00014CA6 A801                <1> 	test	al, 1
  4137 00014CA8 7402                <1> 	jz	short ac97_gcd_1
  4138 00014CAA 01FE                <1> 	add	esi, edi
  4139                              <1> ac97_gcd_1:
  4140 00014CAC 31C0                <1> 	xor	eax, eax
  4141 00014CAE 66BA1800            <1> 	mov	dx, PO_PICB_REG ; Position In Current Buff Reg
  4142 00014CB2 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  4143                              <1> 	;in	ax, dx ; remain dwords
  4144                              <1> 	;shl	eax, 2 ; remain bytes ; 23/06/2017
  4145                              <1> 	;;;
  4146                              <1> 	; 04/06/2024
  4147 00014CB9 66ED                <1> 	in	ax, dx ; remain words
  4148 00014CBB D1E0                <1> 	shl	eax, 1 ; remain bytes	
  4149                              <1> 	;;;
  4150 00014CBD EBBE                <1> 	jmp	short ac97_gcd_2
  4151                              <1> ;	cmp	eax, ecx
  4152                              <1> ;	jnb	short ac97_gcd_2 
  4153                              <1> ;	; remain count < graphics bytes
  4154                              <1> ;	mov	eax, ecx ; fix remain count to data size
  4155                              <1> ;ac97_gcd_2:
  4156                              <1> ;	sub	edi, eax
  4157                              <1> ;	jna	short ac97_gcd_3
  4158                              <1> ;	add	esi, edi ; dma buffer offset
  4159                              <1> ;ac97_gcd_3:
  4160                              <1> ;	mov	edi, ebx ; buffer address (for graphics)
  4161                              <1> ;	mov	[u.r0], ecx
  4162                              <1> ;	rep	movsb
  4163                              <1> ;	retn
  4164                              <1> 
  4165                              <1> sb16_get_dma_buff_off:
  4166                              <1> 	; 05/06/2024
  4167                              <1> 	; 04/06/2024 - TRDOS 386 v2.0.8
  4168                              <1> 	; 28/10/2017
  4169                              <1> 	; 24/06/2017
  4170                              <1> 	; 22/06/2017
  4171                              <1> 	; get current (PCM OUT DMA buffer) pointer
  4172                              <1> 	; (for Sound Blaster 16)
  4173                              <1> 
  4174                              <1> 	;mov	ecx, [audio_dmabuff_size]
  4175                              <1> 	;xor	ebx, ebx
  4176                              <1> 	;shr	ecx, 1
  4177                              <1> 	
  4178                              <1> 	;;;
  4179                              <1> 	; 04/06/2024
  4180                              <1> 	; ecx = audio buffer size
  4181                              <1> 	; 05/06/2024
  4182                              <1> 	; ecx = DMA half buffer size
  4183 00014CBF D1E1                <1> 	shl	ecx, 1 ; * 2
  4184                              <1> 	; ecx = DMA buffer size
  4185                              <1> 	;;;
  4186                              <1> 
  4187                              <1> sb16_gdmabo_0:
  4188                              <1> 	; 28/10/2017
  4189 00014CC1 803D[208F0100]10    <1> 	cmp	byte [audio_bps], 16
  4190 00014CC8 750F                <1> 	jne	short sb16_gdmabo_1 ; 8 bit DMA channel
  4191                              <1> 	; 16 bit DMA channel
  4192 00014CCA E4C6                <1> 	in	al, 0C6h ; DMA channel 5 count register
  4193 00014CCC 88C2                <1> 	mov	dl, al	
  4194 00014CCE E4C6                <1> 	in	al, 0C6h
  4195 00014CD0 88C6                <1> 	mov     dh, al
  4196 00014CD2 0FB7C2              <1> 	movzx	eax, dx
  4197 00014CD5 D1E0                <1> 	shl	eax, 1 ; word count -> byte count
  4198 00014CD7 EB3A                <1> 	jmp	short sb16_gdmabo_2
  4199                              <1> sb16_gdmabo_1:
  4200 00014CD9 E403                <1> 	in	al, 03h ; DMA channel 1 count register
  4201 00014CDB 88C2                <1> 	mov	dl, al	
  4202 00014CDD E403                <1> 	in	al, 03h
  4203 00014CDF 88C6                <1> 	mov     dh, al
  4204 00014CE1 0FB7C2              <1> 	movzx	eax, dx
  4205 00014CE4 EB2D                <1> 	jmp	short sb16_gdmabo_2
  4206                              <1> 
  4207                              <1> get_dma_buffer_offset:
  4208                              <1> 	; 05/06/2024
  4209                              <1> 	; 04/06/2024
  4210                              <1> 	; 24/06/2017
  4211                              <1> 	; 22/06/2017
  4212                              <1> 	; get current sound (PCM out) data for graphics
  4213                              <1> 	;
  4214                              <1> 	; ebx = Physical address (on page boundary)
  4215                              <1> 	; ecx = Byte count
  4216                              <1> 	; [audio_buff_size]
  4217                              <1> 
  4218                              <1> 	;mov	ecx, [audio_dmabuff_size]
  4219                              <1> 	;;;
  4220                              <1> 	; 04/06/2024
  4221                              <1> 	;mov	ecx, [audio_buff_size]
  4222                              <1> 	; 05/06/2024
  4223 00014CE6 8B0D[148F0100]      <1> 	mov	ecx, [dma_hbuff_size]
  4224                              <1> 	;;;
  4225 00014CEC 31DB                <1> 	xor	ebx, ebx
  4226                              <1> gdmabo_0:
  4227 00014CEE 803D[ED8E0100]02    <1> 	cmp	byte [audio_device], 2
  4228 00014CF5 72C8                <1> 	jb	short sb16_get_dma_buff_off
  4229 00014CF7 7427                <1> 	je	short ac97_get_dma_buff_off
  4230                              <1> 
  4231                              <1> vt8233_get_dma_buff_off:
  4232                              <1> 	; 05/06/2024
  4233                              <1> 	; 04/06/2024 - TRDOS 386 v2.0.8
  4234                              <1> 	; 06/08/2022 - TRDOS 386 v2.0.5
  4235                              <1> 	; 24/06/2017
  4236                              <1> 	; 22/06/2017
  4237                              <1> 	; get current (PCM OUT DMA buffer) pointer
  4238                              <1> 	; (for VT 8233, VT 8237R)
  4239                              <1> 	
  4240                              <1> 	;mov	ecx, [audio_dmabuff_size]
  4241                              <1> 	;xor	ebx, ebx
  4242                              <1> 	;;;
  4243                              <1> 	; 04/06/2024
  4244                              <1> 	;shr	ecx, 1
  4245                              <1> 	; 05/06/2024
  4246                              <1> 	;and	cl, ~1
  4247                              <1> 	; ecx = DMA Half Buffer Size (word aligned)
  4248                              <1> 	;;;
  4249                              <1> vt8233_gdmabo_0:
  4250                              <1> 	;mov	edx, VIA_REG_OFFSET_CURR_COUNT
  4251                              <1> 	; 06/08/2022
  4252 00014CF9 31D2                <1> 	xor	edx, edx
  4253 00014CFB B20C                <1> 	mov	dl, VIA_REG_OFFSET_CURR_COUNT
  4254 00014CFD E8DFF4FFFF          <1> 	call	ctrl_io_r32
  4255 00014D02 89C2                <1> 	mov	edx, eax ; remain count (bits 23-0),
  4256                              <1> 			 ; SGD index (bits 31-24) 
  4257 00014D04 81E200000001        <1> 	and	edx, 1000000h ; SGD index (0 = 1st half)
  4258 00014D0A 7402                <1> 	jz	short vt8233_gdmabo_1
  4259                              <1> 	; the second half of DMA buffer
  4260 00014D0C 89CB                <1> 	mov	ebx, ecx
  4261                              <1> vt8233_gdmabo_1:
  4262 00014D0E 25FFFFFF00          <1> 	and	eax, 0FFFFFFh ; bits 23-0
  4263                              <1> sb16_gdmabo_2:
  4264                              <1> ac97_gdmabo_2:
  4265 00014D13 29C1                <1> 	sub	ecx, eax
  4266 00014D15 7602                <1> 	jna	short vt8233_gdmabo_2
  4267 00014D17 01CB                <1> 	add	ebx, ecx ; dma buffer offset
  4268                              <1> vt8233_gdmabo_2:
  4269 00014D19 891D[74940100]      <1> 	mov	[u.r0], ebx
  4270 00014D1F C3                  <1> 	retn
  4271                              <1> 
  4272                              <1> ac97_get_dma_buff_off:
  4273                              <1> 	; 06/06/2024
  4274                              <1> 	; 05/06/2024
  4275                              <1> 	; 04/06/2024 - TRDOS 386 v2.0.8
  4276                              <1> 	; 24/06/2017
  4277                              <1> 	; 22/06/2017
  4278                              <1> 	; get current (PCM OUT DMA buffer) pointer
  4279                              <1> 	; (for AC'97, ICH)
  4280                              <1> 	; ebx = Physical address (on page boundary)
  4281                              <1> 	; ecx = Byte count
  4282                              <1> 	; [audio_buff_size]
  4283                              <1> 	
  4284                              <1> 	;mov	ecx, [audio_dmabuff_size]
  4285                              <1> 	;xor	ebx, ebx
  4286                              <1> 	;;;
  4287                              <1> 	; 04/06/2024
  4288                              <1> 	;shr	ecx, 1
  4289                              <1> 	; 05/06/2024
  4290                              <1> 	;and	cl, ~7 ; (truncate bytes if out of 8x)
  4291                              <1> 	; ecx = DMA Half Buffer Size (8 byte aligned)
  4292                              <1> 	;;;
  4293                              <1> ac97_gdmabo_0:
  4294 00014D20 66BA1400            <1> 	mov	dx, PO_CIV_REG ; Position In Current Buff Reg
  4295 00014D24 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  4296 00014D2B EC                  <1> 	in	al, dx ; current index value
  4297 00014D2C A801                <1> 	test	al, 1
  4298 00014D2E 7402                <1> 	jz	short ac97_gdmabo_1
  4299 00014D30 89CB                <1> 	mov	ebx, ecx
  4300                              <1> ac97_gdmabo_1:
  4301 00014D32 31C0                <1> 	xor	eax, eax
  4302 00014D34 66BA1800            <1> 	mov	dx, PO_PICB_REG ; Position In Current Buff Reg
  4303 00014D38 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  4304 00014D3F 66ED                <1> 	in	ax, dx ; remain words (samples)
  4305                              <1> 	;;;
  4306                              <1> 	; 06/06/2024
  4307                              <1> 	; audio samples are counted as words
  4308                              <1> 	; 04/06/2024 (BugFix)
  4309 00014D41 D1E0                <1> 	shl	eax, 1 ; remain bytes
  4310                              <1> 	;;;
  4311 00014D43 EBCE                <1> 	jmp	short ac97_gdmabo_2
  4312                              <1> 
  4313                              <1> ac97_codec_info:
  4314                              <1> 	; 06/06/2024
  4315                              <1> 	; 05/06/2024 - TRDOS 386 v2.0.8
  4316                              <1> 	; 19/11/2023
  4317                              <1> 	; ENTRY: none
  4318                              <1> 	; RETURN: 
  4319                              <1> 	;	eax = Extended Audio ID (MX28) in ax
  4320                              <1> 	;	 ax bit 0 - VRA bit
  4321                              <1> 	;	 hw of eax = PCM output sample rate (48000)
  4322                              <1> 	;	ebx = VENDOR ID 1, VENDOR ID 2 (bx)
  4323                              <1> 	;	cf = 1 -> error
  4324                              <1> 
  4325                              <1> 	; 06/06/2024
  4326                              <1> 	;;;
  4327 00014D45 66BA3000            <1> 	mov	dx, GLOB_STS_REG ; 30h
  4328 00014D49 660315[F28E0100]    <1> 	add	dx, [NABMBAR]
  4329 00014D50 ED                  <1> 	in	eax, dx
  4330                              <1> 
  4331                              <1> 	;cmp	eax, 0FFFFFFFFh ; -1
  4332 00014D51 40                  <1> 	inc	eax
  4333 00014D52 7408                <1> 	jz	short ac97_c_inf_err
  4334 00014D54 48                  <1> 	dec	eax
  4335                              <1> 
  4336 00014D55 2500030010          <1> 	and	eax, CTRL_ST_CREADY
  4337 00014D5A 7502                <1> 	jnz	short ac97_c_inf_1
  4338                              <1> 
  4339                              <1> ac97_c_inf_err:	
  4340 00014D5C F9                  <1> 	stc
  4341 00014D5D C3                  <1> 	retn
  4342                              <1> 	;;;
  4343                              <1> 
  4344                              <1> ac97_c_inf_1:
  4345 00014D5E 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  4346 00014D65 6683C22C            <1> 	add	dx, CODEC_PCM_FRONT_DACRATE_REG 
  4347 00014D69 66ED                <1> 	in	ax, dx	; PCM Output Sample Rate
  4348                              <1> 			; 48000 Hz
  4349 00014D6B C1E010              <1> 	shl	eax, 16
  4350 00014D6E E80EF4FFFF          <1> 	call	delay_100ms
  4351 00014D73 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  4352 00014D7A 6683C228            <1> 	add	dx, CODEC_EXT_AUDIO_REG ; 28h
  4353 00014D7E 66ED                <1> 	in	ax, dx
  4354 00014D80 50                  <1> 	push	eax
  4355 00014D81 E8FBF3FFFF          <1> 	call	delay_100ms
  4356 00014D86 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  4357 00014D8D 6683C27C            <1> 	add	dx, CODEC_VENDOR_ID1
  4358 00014D91 66ED                <1> 	in	ax, dx
  4359 00014D93 C1E010              <1> 	shl	eax, 16
  4360 00014D96 668B15[F08E0100]    <1> 	mov	dx, [NAMBAR]
  4361 00014D9D 6683C27E            <1> 	add	dx, CODEC_VENDOR_ID2
  4362 00014DA1 66ED                <1> 	in	ax, dx
  4363 00014DA3 89C3                <1> 	mov	ebx, eax
  4364 00014DA5 58                  <1> 	pop	eax
  4365                              <1> 	;;;;
  4366                              <1> 	; 06/06/2024 (temporary!?)
  4367                              <1> 	; (ALC850 & ALC655 BugFix)
  4368 00014DA6 83FBFF              <1> 	cmp	ebx, 0FFFFFFFFh ; -1
  4369 00014DA9 74B1                <1> 	je	short ac97_c_inf_err ; invalid
  4370 00014DAB 09DB                <1> 	or	ebx, ebx
  4371 00014DAD 74AD                <1> 	jz	short ac97_c_inf_err ; invalid
  4372 00014DAF 81FB90474C41        <1> 	cmp	ebx, 414C4790h ; ALC850
  4373                              <1> 	;je	short ac97_c_inf_2
  4374                              <1> 	;cmp	ebx, 414C4760h ; ALC655
  4375 00014DB5 7505                <1> 	jne	short ac97_c_inf_3	
  4376                              <1> 	;mov	eax, 0BB8009C6h ; AC655 default (Read only)
  4377                              <1> 	;retn
  4378                              <1> ac97_c_inf_2:
  4379                              <1> 	; ref: ALC850 & ALC655 data sheet
  4380 00014DB7 B8C40980BB          <1> 	mov	eax, 0BB8009C4h ; AC850 default (Read only)
  4381                              <1> ac97_c_inf_3:
  4382                              <1> 	;;;;
  4383 00014DBC C3                  <1> 	retn
  4384                              <1> 
  4385                              <1> ; 19/11/2023
  4386                              <1> ; Valid ICH device IDs
  4387                              <1> 
  4388                              <1> valid_ids:
  4389 00014DBD 86801524            <1> dd	(ICH_DID << 16) + INTEL_VID  	 ; 8086h:2415h
  4390 00014DC1 86802524            <1> dd	(ICH0_DID << 16) + INTEL_VID 	 ; 8086h:2425h
  4391 00014DC5 86804524            <1> dd	(ICH2_DID << 16) + INTEL_VID 	 ; 8086h:2445h
  4392 00014DC9 86808524            <1> dd	(ICH3_DID << 16) + INTEL_VID 	 ; 8086h:2485h
  4393 00014DCD 8680C524            <1> dd	(ICH4_DID << 16) + INTEL_VID 	 ; 8086h:24C5h
  4394 00014DD1 8680D524            <1> dd	(ICH5_DID << 16) + INTEL_VID 	 ; 8086h:24D5h
  4395 00014DD5 86806E26            <1> dd	(ICH6_DID << 16) + INTEL_VID 	 ; 8086h:266Eh
  4396 00014DD9 8680A625            <1> dd	(ESB6300_DID << 16) + INTEL_VID  ; 8086h:25A6h
  4397 00014DDD 86809826            <1> dd	(ESB631X_DID << 16) + INTEL_VID  ; 8086h:2698h
  4398 00014DE1 8680DE27            <1> dd	(ICH7_DID << 16) + INTEL_VID 	 ; 8086h:27DEh
  4399 00014DE5 86809571            <1> dd	(MX82440_DID << 16) + INTEL_VID  ; 8086h:7195h
  4400 00014DE9 39101270            <1> dd	(SI7012_DID << 16)  + SIS_VID	 ; 1039h:7012h
  4401 00014DED DE10B101            <1> dd 	(NFORCE_DID << 16)  + NVIDIA_VID ; 10DEh:01B1h
  4402 00014DF1 DE106A00            <1> dd 	(NFORCE2_DID << 16) + NVIDIA_VID ; 10DEh:006Ah
  4403 00014DF5 22106D74            <1> dd 	(AMD8111_DID << 16) + AMD_VID 	 ; 1022h:746Dh
  4404 00014DF9 22104574            <1> dd 	(AMD768_DID << 16)  + AMD_VID 	 ; 1022h:7445h
  4405 00014DFD DE105900            <1> dd 	(CK804_DID << 16) + NVIDIA_VID	 ; 10DEh:0059h
  4406 00014E01 DE103A00            <1> dd 	(MCP04_DID << 16) + NVIDIA_VID	 ; 10DEh:003Ah
  4407 00014E05 DE108A00            <1> dd 	(CK8_DID << 16) + NVIDIA_VID	 ; 1022h:008Ah
  4408 00014E09 DE10DA00            <1> dd 	(NFORCE3_DID << 16) + NVIDIA_VID ; 10DEh:00DAh
  4409 00014E0D DE10EA00            <1> dd 	(CK8S_DID << 16) + NVIDIA_VID	 ; 10DEh:00EAh
  4410                              <1> 
  4411                              <1> valid_id_count:	equ ($ - valid_ids)>>2 ; 19/11/2023
  3782                                  
  3783 00014E11 90<rep 3h>              align 4
  3784                                  
  3785                                  %include 'vgadata.s' ; 04/07/2016
     1                              <1> ; ****************************************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.3 - vgadata.s  (palette and font data)
     3                              <1> ; -----------------------------------------------------------------------------
     4                              <1> ; Last Update: 01/01/2021
     5                              <1> ; -----------------------------------------------------------------------------
     6                              <1> ; Beginning: 16/01/2016
     7                              <1> ; -----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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> ; 25/11/2020 (TRDOS 386 v2.0.3)
    25                              <1> ; ('vgatables.h' - 30/12/2019 - vruppert)
    26                              <1>  
    27                              <1> ; 04/07/2016
    28                              <1> ; COLOR DATA
    29                              <1> 
    30                              <1> palette0: ; (63+1)*3
    31 00014E14 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
    31 00014E1D 00000000000000      <1>
    32 00014E24 00000000000000002A- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    32 00014E2D 2A2A2A2A2A2A2A      <1>
    33 00014E34 2A2A2A2A2A2A2A2A2A- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    33 00014E3D 2A2A2A2A2A2A2A      <1>
    34 00014E44 2A2A2A2A2A2A2A2A2A- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    34 00014E4D 2A2A2A2A2A2A2A      <1>
    35 00014E54 2A2A2A2A2A2A2A2A3F- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh
    35 00014E5D 3F3F3F3F3F3F3F      <1>
    36 00014E64 3F3F3F3F3F3F3F3F3F- <1>     db  03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh
    36 00014E6D 3F3F3F3F3F3F3F      <1>
    37 00014E74 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
    37 00014E7D 00000000000000      <1>
    38 00014E84 00000000000000002A- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    38 00014E8D 2A2A2A2A2A2A2A      <1>
    39 00014E94 2A2A2A2A2A2A2A2A2A- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    39 00014E9D 2A2A2A2A2A2A2A      <1>
    40 00014EA4 2A2A2A2A2A2A2A2A2A- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah
    40 00014EAD 2A2A2A2A2A2A2A      <1>
    41 00014EB4 2A2A2A2A2A2A2A2A3F- <1>     db  02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 02ah, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh
    41 00014EBD 3F3F3F3F3F3F3F      <1>
    42 00014EC4 3F3F3F3F3F3F3F3F3F- <1>     db  03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh, 03fh
    42 00014ECD 3F3F3F3F3F3F3F      <1>
    43                              <1> palette1: ; (63+1)*3	
    44 00014ED4 00000000002A002A00- <1>     db  000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah, 000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah
    44 00014EDD 002A2A2A00002A      <1>
    45 00014EE4 002A2A15002A2A2A00- <1>     db  000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah
    45 00014EED 000000002A002A      <1>
    46 00014EF4 00002A2A2A00002A00- <1>     db  000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah, 000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah
    46 00014EFD 2A2A15002A2A2A      <1>
    47 00014F04 15151515153F153F15- <1>     db  015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh, 015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh
    47 00014F0D 153F3F3F15153F      <1>
    48 00014F14 153F3F3F153F3F3F15- <1>     db  015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh
    48 00014F1D 151515153F153F      <1>
    49 00014F24 15153F3F3F15153F15- <1>     db  015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh
    49 00014F2D 3F3F3F153F3F3F      <1>
    50 00014F34 00000000002A002A00- <1>     db  000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah, 000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah
    50 00014F3D 002A2A2A00002A      <1>
    51 00014F44 002A2A15002A2A2A00- <1>     db  000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah
    51 00014F4D 000000002A002A      <1>
    52 00014F54 00002A2A2A00002A00- <1>     db  000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah, 000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah
    52 00014F5D 2A2A15002A2A2A      <1>
    53 00014F64 15151515153F153F15- <1>     db  015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh, 015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh
    53 00014F6D 153F3F3F15153F      <1>
    54 00014F74 153F3F3F153F3F3F15- <1>     db  015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh
    54 00014F7D 151515153F153F      <1>
    55 00014F84 15153F3F3F15153F15- <1>     db  015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh
    55 00014F8D 3F3F3F153F3F3F      <1>
    56                              <1> palette2: ; (63+1)*3
    57 00014F94 00000000002A002A00- <1>     db  000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah, 000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah
    57 00014F9D 002A2A2A00002A      <1>
    58 00014FA4 002A2A2A002A2A2A00- <1>     db  000h, 02ah, 02ah, 02ah, 000h, 02ah, 02ah, 02ah, 000h, 000h, 015h, 000h, 000h, 03fh, 000h, 02ah
    58 00014FAD 001500003F002A      <1>
    59 00014FB4 15002A3F2A00152A00- <1>     db  015h, 000h, 02ah, 03fh, 02ah, 000h, 015h, 02ah, 000h, 03fh, 02ah, 02ah, 015h, 02ah, 02ah, 03fh
    59 00014FBD 3F2A2A152A2A3F      <1>
    60 00014FC4 00150000152A003F00- <1>     db  000h, 015h, 000h, 000h, 015h, 02ah, 000h, 03fh, 000h, 000h, 03fh, 02ah, 02ah, 015h, 000h, 02ah
    60 00014FCD 003F2A2A15002A      <1>
    61 00014FD4 152A2A3F002A3F2A00- <1>     db  015h, 02ah, 02ah, 03fh, 000h, 02ah, 03fh, 02ah, 000h, 015h, 015h, 000h, 015h, 03fh, 000h, 03fh
    61 00014FDD 151500153F003F      <1>
    62 00014FE4 15003F3F2A15152A15- <1>     db  015h, 000h, 03fh, 03fh, 02ah, 015h, 015h, 02ah, 015h, 03fh, 02ah, 03fh, 015h, 02ah, 03fh, 03fh
    62 00014FED 3F2A3F152A3F3F      <1>
    63 00014FF4 15000015002A152A00- <1>     db  015h, 000h, 000h, 015h, 000h, 02ah, 015h, 02ah, 000h, 015h, 02ah, 02ah, 03fh, 000h, 000h, 03fh
    63 00014FFD 152A2A3F00003F      <1>
    64 00015004 002A3F2A003F2A2A15- <1>     db  000h, 02ah, 03fh, 02ah, 000h, 03fh, 02ah, 02ah, 015h, 000h, 015h, 015h, 000h, 03fh, 015h, 02ah
    64 0001500D 001515003F152A      <1>
    65 00015014 15152A3F3F00153F00- <1>     db  015h, 015h, 02ah, 03fh, 03fh, 000h, 015h, 03fh, 000h, 03fh, 03fh, 02ah, 015h, 03fh, 02ah, 03fh
    65 0001501D 3F3F2A153F2A3F      <1>
    66 00015024 15150015152A153F00- <1>     db  015h, 015h, 000h, 015h, 015h, 02ah, 015h, 03fh, 000h, 015h, 03fh, 02ah, 03fh, 015h, 000h, 03fh
    66 0001502D 153F2A3F15003F      <1>
    67 00015034 152A3F3F003F3F2A15- <1>     db  015h, 02ah, 03fh, 03fh, 000h, 03fh, 03fh, 02ah, 015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh
    67 0001503D 151515153F153F      <1>
    68 00015044 15153F3F3F15153F15- <1>     db  015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh
    68 0001504D 3F3F3F153F3F3F      <1>
    69                              <1> palette3: ; 256*3
    70 00015054 00000000002A002A00- <1>     db  000h, 000h, 000h, 000h, 000h, 02ah, 000h, 02ah, 000h, 000h, 02ah, 02ah, 02ah, 000h, 000h, 02ah
    70 0001505D 002A2A2A00002A      <1>
    71 00015064 002A2A15002A2A2A15- <1>     db  000h, 02ah, 02ah, 015h, 000h, 02ah, 02ah, 02ah, 015h, 015h, 015h, 015h, 015h, 03fh, 015h, 03fh
    71 0001506D 151515153F153F      <1>
    72 00015074 15153F3F3F15153F15- <1>     db  015h, 015h, 03fh, 03fh, 03fh, 015h, 015h, 03fh, 015h, 03fh, 03fh, 03fh, 015h, 03fh, 03fh, 03fh
    72 0001507D 3F3F3F153F3F3F      <1>
    73 00015084 000000050505080808- <1>     db  000h, 000h, 000h, 005h, 005h, 005h, 008h, 008h, 008h, 00bh, 00bh, 00bh, 00eh, 00eh, 00eh, 011h
    73 0001508D 0B0B0B0E0E0E11      <1>
    74 00015094 11111414141818181C- <1>     db  011h, 011h, 014h, 014h, 014h, 018h, 018h, 018h, 01ch, 01ch, 01ch, 020h, 020h, 020h, 024h, 024h
    74 0001509D 1C1C2020202424      <1>
    75 000150A4 242828282D2D2D3232- <1>     db  024h, 028h, 028h, 028h, 02dh, 02dh, 02dh, 032h, 032h, 032h, 038h, 038h, 038h, 03fh, 03fh, 03fh
    75 000150AD 323838383F3F3F      <1>
    76 000150B4 00003F10003F1F003F- <1>     db  000h, 000h, 03fh, 010h, 000h, 03fh, 01fh, 000h, 03fh, 02fh, 000h, 03fh, 03fh, 000h, 03fh, 03fh
    76 000150BD 2F003F3F003F3F      <1>
    77 000150C4 002F3F001F3F00103F- <1>     db  000h, 02fh, 03fh, 000h, 01fh, 03fh, 000h, 010h, 03fh, 000h, 000h, 03fh, 010h, 000h, 03fh, 01fh
    77 000150CD 00003F10003F1F      <1>
    78 000150D4 003F2F003F3F002F3F- <1>     db  000h, 03fh, 02fh, 000h, 03fh, 03fh, 000h, 02fh, 03fh, 000h, 01fh, 03fh, 000h, 010h, 03fh, 000h
    78 000150DD 001F3F00103F00      <1>
    79 000150E4 003F00003F10003F1F- <1>     db  000h, 03fh, 000h, 000h, 03fh, 010h, 000h, 03fh, 01fh, 000h, 03fh, 02fh, 000h, 03fh, 03fh, 000h
    79 000150ED 003F2F003F3F00      <1>
    80 000150F4 2F3F001F3F00103F1F- <1>     db  02fh, 03fh, 000h, 01fh, 03fh, 000h, 010h, 03fh, 01fh, 01fh, 03fh, 027h, 01fh, 03fh, 02fh, 01fh
    80 000150FD 1F3F271F3F2F1F      <1>
    81 00015104 3F371F3F3F1F3F3F1F- <1>     db  03fh, 037h, 01fh, 03fh, 03fh, 01fh, 03fh, 03fh, 01fh, 037h, 03fh, 01fh, 02fh, 03fh, 01fh, 027h
    81 0001510D 373F1F2F3F1F27      <1>
    82 00015114 3F1F1F3F271F3F2F1F- <1>     db  03fh, 01fh, 01fh, 03fh, 027h, 01fh, 03fh, 02fh, 01fh, 03fh, 037h, 01fh, 03fh, 03fh, 01fh, 037h
    82 0001511D 3F371F3F3F1F37      <1>
    83 00015124 3F1F2F3F1F273F1F1F- <1>     db  03fh, 01fh, 02fh, 03fh, 01fh, 027h, 03fh, 01fh, 01fh, 03fh, 01fh, 01fh, 03fh, 027h, 01fh, 03fh
    83 0001512D 3F1F1F3F271F3F      <1>
    84 00015134 2F1F3F371F3F3F1F37- <1>     db  02fh, 01fh, 03fh, 037h, 01fh, 03fh, 03fh, 01fh, 037h, 03fh, 01fh, 02fh, 03fh, 01fh, 027h, 03fh
    84 0001513D 3F1F2F3F1F273F      <1>
    85 00015144 2D2D3F312D3F362D3F- <1>     db  02dh, 02dh, 03fh, 031h, 02dh, 03fh, 036h, 02dh, 03fh, 03ah, 02dh, 03fh, 03fh, 02dh, 03fh, 03fh
    85 0001514D 3A2D3F3F2D3F3F      <1>
    86 00015154 2D3A3F2D363F2D313F- <1>     db  02dh, 03ah, 03fh, 02dh, 036h, 03fh, 02dh, 031h, 03fh, 02dh, 02dh, 03fh, 031h, 02dh, 03fh, 036h
    86 0001515D 2D2D3F312D3F36      <1>
    87 00015164 2D3F3A2D3F3F2D3A3F- <1>     db  02dh, 03fh, 03ah, 02dh, 03fh, 03fh, 02dh, 03ah, 03fh, 02dh, 036h, 03fh, 02dh, 031h, 03fh, 02dh
    87 0001516D 2D363F2D313F2D      <1>
    88 00015174 2D3F2D2D3F312D3F36- <1>     db  02dh, 03fh, 02dh, 02dh, 03fh, 031h, 02dh, 03fh, 036h, 02dh, 03fh, 03ah, 02dh, 03fh, 03fh, 02dh
    88 0001517D 2D3F3A2D3F3F2D      <1>
    89 00015184 3A3F2D363F2D313F00- <1>     db  03ah, 03fh, 02dh, 036h, 03fh, 02dh, 031h, 03fh, 000h, 000h, 01ch, 007h, 000h, 01ch, 00eh, 000h
    89 0001518D 001C07001C0E00      <1>
    90 00015194 1C15001C1C001C1C00- <1>     db  01ch, 015h, 000h, 01ch, 01ch, 000h, 01ch, 01ch, 000h, 015h, 01ch, 000h, 00eh, 01ch, 000h, 007h
    90 0001519D 151C000E1C0007      <1>
    91 000151A4 1C00001C07001C0E00- <1>     db  01ch, 000h, 000h, 01ch, 007h, 000h, 01ch, 00eh, 000h, 01ch, 015h, 000h, 01ch, 01ch, 000h, 015h
    91 000151AD 1C15001C1C0015      <1>
    92 000151B4 1C000E1C00071C0000- <1>     db  01ch, 000h, 00eh, 01ch, 000h, 007h, 01ch, 000h, 000h, 01ch, 000h, 000h, 01ch, 007h, 000h, 01ch
    92 000151BD 1C00001C07001C      <1>
    93 000151C4 0E001C15001C1C0015- <1>     db  00eh, 000h, 01ch, 015h, 000h, 01ch, 01ch, 000h, 015h, 01ch, 000h, 00eh, 01ch, 000h, 007h, 01ch
    93 000151CD 1C000E1C00071C      <1>
    94 000151D4 0E0E1C110E1C150E1C- <1>     db  00eh, 00eh, 01ch, 011h, 00eh, 01ch, 015h, 00eh, 01ch, 018h, 00eh, 01ch, 01ch, 00eh, 01ch, 01ch
    94 000151DD 180E1C1C0E1C1C      <1>
    95 000151E4 0E181C0E151C0E111C- <1>     db  00eh, 018h, 01ch, 00eh, 015h, 01ch, 00eh, 011h, 01ch, 00eh, 00eh, 01ch, 011h, 00eh, 01ch, 015h
    95 000151ED 0E0E1C110E1C15      <1>
    96 000151F4 0E1C180E1C1C0E181C- <1>     db  00eh, 01ch, 018h, 00eh, 01ch, 01ch, 00eh, 018h, 01ch, 00eh, 015h, 01ch, 00eh, 011h, 01ch, 00eh
    96 000151FD 0E151C0E111C0E      <1>
    97 00015204 0E1C0E0E1C110E1C15- <1>     db  00eh, 01ch, 00eh, 00eh, 01ch, 011h, 00eh, 01ch, 015h, 00eh, 01ch, 018h, 00eh, 01ch, 01ch, 00eh
    97 0001520D 0E1C180E1C1C0E      <1>
    98 00015214 181C0E151C0E111C14- <1>     db  018h, 01ch, 00eh, 015h, 01ch, 00eh, 011h, 01ch, 014h, 014h, 01ch, 016h, 014h, 01ch, 018h, 014h
    98 0001521D 141C16141C1814      <1>
    99 00015224 1C1A141C1C141C1C14- <1>     db  01ch, 01ah, 014h, 01ch, 01ch, 014h, 01ch, 01ch, 014h, 01ah, 01ch, 014h, 018h, 01ch, 014h, 016h
    99 0001522D 1A1C14181C1416      <1>
   100 00015234 1C14141C16141C1814- <1>     db  01ch, 014h, 014h, 01ch, 016h, 014h, 01ch, 018h, 014h, 01ch, 01ah, 014h, 01ch, 01ch, 014h, 01ah
   100 0001523D 1C1A141C1C141A      <1>
   101 00015244 1C14181C14161C1414- <1>     db  01ch, 014h, 018h, 01ch, 014h, 016h, 01ch, 014h, 014h, 01ch, 014h, 014h, 01ch, 016h, 014h, 01ch
   101 0001524D 1C14141C16141C      <1>
   102 00015254 18141C1A141C1C141A- <1>     db  018h, 014h, 01ch, 01ah, 014h, 01ch, 01ch, 014h, 01ah, 01ch, 014h, 018h, 01ch, 014h, 016h, 01ch
   102 0001525D 1C14181C14161C      <1>
   103 00015264 000010040010080010- <1>     db  000h, 000h, 010h, 004h, 000h, 010h, 008h, 000h, 010h, 00ch, 000h, 010h, 010h, 000h, 010h, 010h
   103 0001526D 0C001010001010      <1>
   104 00015274 000C10000810000410- <1>     db  000h, 00ch, 010h, 000h, 008h, 010h, 000h, 004h, 010h, 000h, 000h, 010h, 004h, 000h, 010h, 008h
   104 0001527D 00001004001008      <1>
   105 00015284 00100C001010000C10- <1>     db  000h, 010h, 00ch, 000h, 010h, 010h, 000h, 00ch, 010h, 000h, 008h, 010h, 000h, 004h, 010h, 000h
   105 0001528D 00081000041000      <1>
   106 00015294 001000001004001008- <1>     db  000h, 010h, 000h, 000h, 010h, 004h, 000h, 010h, 008h, 000h, 010h, 00ch, 000h, 010h, 010h, 000h
   106 0001529D 00100C00101000      <1>
   107 000152A4 0C1000081000041008- <1>     db  00ch, 010h, 000h, 008h, 010h, 000h, 004h, 010h, 008h, 008h, 010h, 00ah, 008h, 010h, 00ch, 008h
   107 000152AD 08100A08100C08      <1>
   108 000152B4 100E08101008101008- <1>     db  010h, 00eh, 008h, 010h, 010h, 008h, 010h, 010h, 008h, 00eh, 010h, 008h, 00ch, 010h, 008h, 00ah
   108 000152BD 0E10080C10080A      <1>
   109 000152C4 100808100A08100C08- <1>     db  010h, 008h, 008h, 010h, 00ah, 008h, 010h, 00ch, 008h, 010h, 00eh, 008h, 010h, 010h, 008h, 00eh
   109 000152CD 100E081010080E      <1>
   110 000152D4 10080C10080A100808- <1>     db  010h, 008h, 00ch, 010h, 008h, 00ah, 010h, 008h, 008h, 010h, 008h, 008h, 010h, 00ah, 008h, 010h
   110 000152DD 100808100A0810      <1>
   111 000152E4 0C08100E081010080E- <1>     db  00ch, 008h, 010h, 00eh, 008h, 010h, 010h, 008h, 00eh, 010h, 008h, 00ch, 010h, 008h, 00ah, 010h
   111 000152ED 10080C10080A10      <1>
   112 000152F4 0B0B100C0B100D0B10- <1>     db  00bh, 00bh, 010h, 00ch, 00bh, 010h, 00dh, 00bh, 010h, 00fh, 00bh, 010h, 010h, 00bh, 010h, 010h
   112 000152FD 0F0B10100B1010      <1>
   113 00015304 0B0F100B0D100B0C10- <1>     db  00bh, 00fh, 010h, 00bh, 00dh, 010h, 00bh, 00ch, 010h, 00bh, 00bh, 010h, 00ch, 00bh, 010h, 00dh
   113 0001530D 0B0B100C0B100D      <1>
   114 00015314 0B100F0B10100B0F10- <1>     db  00bh, 010h, 00fh, 00bh, 010h, 010h, 00bh, 00fh, 010h, 00bh, 00dh, 010h, 00bh, 00ch, 010h, 00bh
   114 0001531D 0B0D100B0C100B      <1>
   115 00015324 0B100B0B100C0B100D- <1>     db  00bh, 010h, 00bh, 00bh, 010h, 00ch, 00bh, 010h, 00dh, 00bh, 010h, 00fh, 00bh, 010h, 010h, 00bh
   115 0001532D 0B100F0B10100B      <1>
   116 00015334 0F100B0D100B0C1000- <1>     db  00fh, 010h, 00bh, 00dh, 010h, 00bh, 00ch, 010h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   116 0001533D 00000000000000      <1>
   117 00015344 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   117 0001534D 00000000000000      <1>
   118                              <1> 
   119                              <1> 
   120                              <1> ; 04/07/2016
   121                              <1> ; FONT DATA
   122                              <1> 
   123                              <1> CRT_CHAR_GEN:
   124                              <1> vgafont8: 
   125 00015354 00000000000000007E- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07eh, 081h, 0a5h, 081h, 0bdh, 099h, 081h, 07eh
   125 0001535D 81A581BD99817E      <1>
   126 00015364 7EFFDBFFC3E7FF7E6C- <1>     db  07eh, 0ffh, 0dbh, 0ffh, 0c3h, 0e7h, 0ffh, 07eh, 06ch, 0feh, 0feh, 0feh, 07ch, 038h, 010h, 000h
   126 0001536D FEFEFE7C381000      <1>
   127 00015374 10387CFE7C38100038- <1>     db  010h, 038h, 07ch, 0feh, 07ch, 038h, 010h, 000h, 038h, 07ch, 038h, 0feh, 0feh, 07ch, 038h, 07ch
   127 0001537D 7C38FEFE7C387C      <1>
   128 00015384 1010387CFE7C387C00- <1>     db  010h, 010h, 038h, 07ch, 0feh, 07ch, 038h, 07ch, 000h, 000h, 018h, 03ch, 03ch, 018h, 000h, 000h
   128 0001538D 00183C3C180000      <1>
   129 00015394 FFFFE7C3C3E7FFFF00- <1>     db  0ffh, 0ffh, 0e7h, 0c3h, 0c3h, 0e7h, 0ffh, 0ffh, 000h, 03ch, 066h, 042h, 042h, 066h, 03ch, 000h
   129 0001539D 3C664242663C00      <1>
   130 000153A4 FFC399BDBD99C3FF0F- <1>     db  0ffh, 0c3h, 099h, 0bdh, 0bdh, 099h, 0c3h, 0ffh, 00fh, 007h, 00fh, 07dh, 0cch, 0cch, 0cch, 078h
   130 000153AD 070F7DCCCCCC78      <1>
   131 000153B4 3C6666663C187E183F- <1>     db  03ch, 066h, 066h, 066h, 03ch, 018h, 07eh, 018h, 03fh, 033h, 03fh, 030h, 030h, 070h, 0f0h, 0e0h
   131 000153BD 333F303070F0E0      <1>
   132 000153C4 7F637F636367E6C099- <1>     db  07fh, 063h, 07fh, 063h, 063h, 067h, 0e6h, 0c0h, 099h, 05ah, 03ch, 0e7h, 0e7h, 03ch, 05ah, 099h
   132 000153CD 5A3CE7E73C5A99      <1>
   133 000153D4 80E0F8FEF8E0800002- <1>     db  080h, 0e0h, 0f8h, 0feh, 0f8h, 0e0h, 080h, 000h, 002h, 00eh, 03eh, 0feh, 03eh, 00eh, 002h, 000h
   133 000153DD 0E3EFE3E0E0200      <1>
   134 000153E4 183C7E18187E3C1866- <1>     db  018h, 03ch, 07eh, 018h, 018h, 07eh, 03ch, 018h, 066h, 066h, 066h, 066h, 066h, 000h, 066h, 000h
   134 000153ED 66666666006600      <1>
   135 000153F4 7FDBDB7B1B1B1B003E- <1>     db  07fh, 0dbh, 0dbh, 07bh, 01bh, 01bh, 01bh, 000h, 03eh, 063h, 038h, 06ch, 06ch, 038h, 0cch, 078h
   135 000153FD 63386C6C38CC78      <1>
   136 00015404 000000007E7E7E0018- <1>     db  000h, 000h, 000h, 000h, 07eh, 07eh, 07eh, 000h, 018h, 03ch, 07eh, 018h, 07eh, 03ch, 018h, 0ffh
   136 0001540D 3C7E187E3C18FF      <1>
   137 00015414 183C7E181818180018- <1>     db  018h, 03ch, 07eh, 018h, 018h, 018h, 018h, 000h, 018h, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h
   137 0001541D 1818187E3C1800      <1>
   138 00015424 00180CFE0C18000000- <1>     db  000h, 018h, 00ch, 0feh, 00ch, 018h, 000h, 000h, 000h, 030h, 060h, 0feh, 060h, 030h, 000h, 000h
   138 0001542D 3060FE60300000      <1>
   139 00015434 0000C0C0C0FE000000- <1>     db  000h, 000h, 0c0h, 0c0h, 0c0h, 0feh, 000h, 000h, 000h, 024h, 066h, 0ffh, 066h, 024h, 000h, 000h
   139 0001543D 2466FF66240000      <1>
   140 00015444 00183C7EFFFF000000- <1>     db  000h, 018h, 03ch, 07eh, 0ffh, 0ffh, 000h, 000h, 000h, 0ffh, 0ffh, 07eh, 03ch, 018h, 000h, 000h
   140 0001544D FFFF7E3C180000      <1>
   141 00015454 000000000000000030- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 030h, 078h, 078h, 030h, 030h, 000h, 030h, 000h
   141 0001545D 78783030003000      <1>
   142 00015464 6C6C6C00000000006C- <1>     db  06ch, 06ch, 06ch, 000h, 000h, 000h, 000h, 000h, 06ch, 06ch, 0feh, 06ch, 0feh, 06ch, 06ch, 000h
   142 0001546D 6CFE6CFE6C6C00      <1>
   143 00015474 307CC0780CF8300000- <1>     db  030h, 07ch, 0c0h, 078h, 00ch, 0f8h, 030h, 000h, 000h, 0c6h, 0cch, 018h, 030h, 066h, 0c6h, 000h
   143 0001547D C6CC183066C600      <1>
   144 00015484 386C3876DCCC760060- <1>     db  038h, 06ch, 038h, 076h, 0dch, 0cch, 076h, 000h, 060h, 060h, 0c0h, 000h, 000h, 000h, 000h, 000h
   144 0001548D 60C00000000000      <1>
   145 00015494 183060606030180060- <1>     db  018h, 030h, 060h, 060h, 060h, 030h, 018h, 000h, 060h, 030h, 018h, 018h, 018h, 030h, 060h, 000h
   145 0001549D 30181818306000      <1>
   146 000154A4 00663CFF3C66000000- <1>     db  000h, 066h, 03ch, 0ffh, 03ch, 066h, 000h, 000h, 000h, 030h, 030h, 0fch, 030h, 030h, 000h, 000h
   146 000154AD 3030FC30300000      <1>
   147 000154B4 000000000030306000- <1>     db  000h, 000h, 000h, 000h, 000h, 030h, 030h, 060h, 000h, 000h, 000h, 0fch, 000h, 000h, 000h, 000h
   147 000154BD 0000FC00000000      <1>
   148 000154C4 000000000030300006- <1>     db  000h, 000h, 000h, 000h, 000h, 030h, 030h, 000h, 006h, 00ch, 018h, 030h, 060h, 0c0h, 080h, 000h
   148 000154CD 0C183060C08000      <1>
   149 000154D4 7CC6CEDEF6E67C0030- <1>     db  07ch, 0c6h, 0ceh, 0deh, 0f6h, 0e6h, 07ch, 000h, 030h, 070h, 030h, 030h, 030h, 030h, 0fch, 000h
   149 000154DD 7030303030FC00      <1>
   150 000154E4 78CC0C3860CCFC0078- <1>     db  078h, 0cch, 00ch, 038h, 060h, 0cch, 0fch, 000h, 078h, 0cch, 00ch, 038h, 00ch, 0cch, 078h, 000h
   150 000154ED CC0C380CCC7800      <1>
   151 000154F4 1C3C6CCCFE0C1E00FC- <1>     db  01ch, 03ch, 06ch, 0cch, 0feh, 00ch, 01eh, 000h, 0fch, 0c0h, 0f8h, 00ch, 00ch, 0cch, 078h, 000h
   151 000154FD C0F80C0CCC7800      <1>
   152 00015504 3860C0F8CCCC7800FC- <1>     db  038h, 060h, 0c0h, 0f8h, 0cch, 0cch, 078h, 000h, 0fch, 0cch, 00ch, 018h, 030h, 030h, 030h, 000h
   152 0001550D CC0C1830303000      <1>
   153 00015514 78CCCC78CCCC780078- <1>     db  078h, 0cch, 0cch, 078h, 0cch, 0cch, 078h, 000h, 078h, 0cch, 0cch, 07ch, 00ch, 018h, 070h, 000h
   153 0001551D CCCC7C0C187000      <1>
   154 00015524 003030000030300000- <1>     db  000h, 030h, 030h, 000h, 000h, 030h, 030h, 000h, 000h, 030h, 030h, 000h, 000h, 030h, 030h, 060h
   154 0001552D 30300000303060      <1>
   155 00015534 183060C06030180000- <1>     db  018h, 030h, 060h, 0c0h, 060h, 030h, 018h, 000h, 000h, 000h, 0fch, 000h, 000h, 0fch, 000h, 000h
   155 0001553D 00FC0000FC0000      <1>
   156 00015544 6030180C1830600078- <1>     db  060h, 030h, 018h, 00ch, 018h, 030h, 060h, 000h, 078h, 0cch, 00ch, 018h, 030h, 000h, 030h, 000h
   156 0001554D CC0C1830003000      <1>
   157 00015554 7CC6DEDEDEC0780030- <1>     db  07ch, 0c6h, 0deh, 0deh, 0deh, 0c0h, 078h, 000h, 030h, 078h, 0cch, 0cch, 0fch, 0cch, 0cch, 000h
   157 0001555D 78CCCCFCCCCC00      <1>
   158 00015564 FC66667C6666FC003C- <1>     db  0fch, 066h, 066h, 07ch, 066h, 066h, 0fch, 000h, 03ch, 066h, 0c0h, 0c0h, 0c0h, 066h, 03ch, 000h
   158 0001556D 66C0C0C0663C00      <1>
   159 00015574 F86C6666666CF800FE- <1>     db  0f8h, 06ch, 066h, 066h, 066h, 06ch, 0f8h, 000h, 0feh, 062h, 068h, 078h, 068h, 062h, 0feh, 000h
   159 0001557D 6268786862FE00      <1>
   160 00015584 FE6268786860F0003C- <1>     db  0feh, 062h, 068h, 078h, 068h, 060h, 0f0h, 000h, 03ch, 066h, 0c0h, 0c0h, 0ceh, 066h, 03eh, 000h
   160 0001558D 66C0C0CE663E00      <1>
   161 00015594 CCCCCCFCCCCCCC0078- <1>     db  0cch, 0cch, 0cch, 0fch, 0cch, 0cch, 0cch, 000h, 078h, 030h, 030h, 030h, 030h, 030h, 078h, 000h
   161 0001559D 30303030307800      <1>
   162 000155A4 1E0C0C0CCCCC7800E6- <1>     db  01eh, 00ch, 00ch, 00ch, 0cch, 0cch, 078h, 000h, 0e6h, 066h, 06ch, 078h, 06ch, 066h, 0e6h, 000h
   162 000155AD 666C786C66E600      <1>
   163 000155B4 F06060606266FE00C6- <1>     db  0f0h, 060h, 060h, 060h, 062h, 066h, 0feh, 000h, 0c6h, 0eeh, 0feh, 0feh, 0d6h, 0c6h, 0c6h, 000h
   163 000155BD EEFEFED6C6C600      <1>
   164 000155C4 C6E6F6DECEC6C60038- <1>     db  0c6h, 0e6h, 0f6h, 0deh, 0ceh, 0c6h, 0c6h, 000h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 06ch, 038h, 000h
   164 000155CD 6CC6C6C66C3800      <1>
   165 000155D4 FC66667C6060F00078- <1>     db  0fch, 066h, 066h, 07ch, 060h, 060h, 0f0h, 000h, 078h, 0cch, 0cch, 0cch, 0dch, 078h, 01ch, 000h
   165 000155DD CCCCCCDC781C00      <1>
   166 000155E4 FC66667C6C66E60078- <1>     db  0fch, 066h, 066h, 07ch, 06ch, 066h, 0e6h, 000h, 078h, 0cch, 0e0h, 070h, 01ch, 0cch, 078h, 000h
   166 000155ED CCE0701CCC7800      <1>
   167 000155F4 FCB4303030307800CC- <1>     db  0fch, 0b4h, 030h, 030h, 030h, 030h, 078h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 0fch, 000h
   167 000155FD CCCCCCCCCCFC00      <1>
   168 00015604 CCCCCCCCCC783000C6- <1>     db  0cch, 0cch, 0cch, 0cch, 0cch, 078h, 030h, 000h, 0c6h, 0c6h, 0c6h, 0d6h, 0feh, 0eeh, 0c6h, 000h
   168 0001560D C6C6D6FEEEC600      <1>
   169 00015614 C6C66C38386CC600CC- <1>     db  0c6h, 0c6h, 06ch, 038h, 038h, 06ch, 0c6h, 000h, 0cch, 0cch, 0cch, 078h, 030h, 030h, 078h, 000h
   169 0001561D CCCC7830307800      <1>
   170 00015624 FEC68C183266FE0078- <1>     db  0feh, 0c6h, 08ch, 018h, 032h, 066h, 0feh, 000h, 078h, 060h, 060h, 060h, 060h, 060h, 078h, 000h
   170 0001562D 60606060607800      <1>
   171 00015634 C06030180C06020078- <1>     db  0c0h, 060h, 030h, 018h, 00ch, 006h, 002h, 000h, 078h, 018h, 018h, 018h, 018h, 018h, 078h, 000h
   171 0001563D 18181818187800      <1>
   172 00015644 10386CC60000000000- <1>     db  010h, 038h, 06ch, 0c6h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh
   172 0001564D 000000000000FF      <1>
   173 00015654 303018000000000000- <1>     db  030h, 030h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 078h, 00ch, 07ch, 0cch, 076h, 000h
   173 0001565D 00780C7CCC7600      <1>
   174 00015664 E060607C6666DC0000- <1>     db  0e0h, 060h, 060h, 07ch, 066h, 066h, 0dch, 000h, 000h, 000h, 078h, 0cch, 0c0h, 0cch, 078h, 000h
   174 0001566D 0078CCC0CC7800      <1>
   175 00015674 1C0C0C7CCCCC760000- <1>     db  01ch, 00ch, 00ch, 07ch, 0cch, 0cch, 076h, 000h, 000h, 000h, 078h, 0cch, 0fch, 0c0h, 078h, 000h
   175 0001567D 0078CCFCC07800      <1>
   176 00015684 386C60F06060F00000- <1>     db  038h, 06ch, 060h, 0f0h, 060h, 060h, 0f0h, 000h, 000h, 000h, 076h, 0cch, 0cch, 07ch, 00ch, 0f8h
   176 0001568D 0076CCCC7C0CF8      <1>
   177 00015694 E0606C766666E60030- <1>     db  0e0h, 060h, 06ch, 076h, 066h, 066h, 0e6h, 000h, 030h, 000h, 070h, 030h, 030h, 030h, 078h, 000h
   177 0001569D 00703030307800      <1>
   178 000156A4 0C000C0C0CCCCC78E0- <1>     db  00ch, 000h, 00ch, 00ch, 00ch, 0cch, 0cch, 078h, 0e0h, 060h, 066h, 06ch, 078h, 06ch, 0e6h, 000h
   178 000156AD 60666C786CE600      <1>
   179 000156B4 703030303030780000- <1>     db  070h, 030h, 030h, 030h, 030h, 030h, 078h, 000h, 000h, 000h, 0cch, 0feh, 0feh, 0d6h, 0c6h, 000h
   179 000156BD 00CCFEFED6C600      <1>
   180 000156C4 0000F8CCCCCCCC0000- <1>     db  000h, 000h, 0f8h, 0cch, 0cch, 0cch, 0cch, 000h, 000h, 000h, 078h, 0cch, 0cch, 0cch, 078h, 000h
   180 000156CD 0078CCCCCC7800      <1>
   181 000156D4 0000DC66667C60F000- <1>     db  000h, 000h, 0dch, 066h, 066h, 07ch, 060h, 0f0h, 000h, 000h, 076h, 0cch, 0cch, 07ch, 00ch, 01eh
   181 000156DD 0076CCCC7C0C1E      <1>
   182 000156E4 0000DC766660F00000- <1>     db  000h, 000h, 0dch, 076h, 066h, 060h, 0f0h, 000h, 000h, 000h, 07ch, 0c0h, 078h, 00ch, 0f8h, 000h
   182 000156ED 007CC0780CF800      <1>
   183 000156F4 10307C303034180000- <1>     db  010h, 030h, 07ch, 030h, 030h, 034h, 018h, 000h, 000h, 000h, 0cch, 0cch, 0cch, 0cch, 076h, 000h
   183 000156FD 00CCCCCCCC7600      <1>
   184 00015704 0000CCCCCC78300000- <1>     db  000h, 000h, 0cch, 0cch, 0cch, 078h, 030h, 000h, 000h, 000h, 0c6h, 0d6h, 0feh, 0feh, 06ch, 000h
   184 0001570D 00C6D6FEFE6C00      <1>
   185 00015714 0000C66C386CC60000- <1>     db  000h, 000h, 0c6h, 06ch, 038h, 06ch, 0c6h, 000h, 000h, 000h, 0cch, 0cch, 0cch, 07ch, 00ch, 0f8h
   185 0001571D 00CCCCCC7C0CF8      <1>
   186 00015724 0000FC983064FC001C- <1>     db  000h, 000h, 0fch, 098h, 030h, 064h, 0fch, 000h, 01ch, 030h, 030h, 0e0h, 030h, 030h, 01ch, 000h
   186 0001572D 3030E030301C00      <1>
   187 00015734 1818180018181800E0- <1>     db  018h, 018h, 018h, 000h, 018h, 018h, 018h, 000h, 0e0h, 030h, 030h, 01ch, 030h, 030h, 0e0h, 000h
   187 0001573D 30301C3030E000      <1>
   188 00015744 76DC00000000000000- <1>     db  076h, 0dch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 000h
   188 0001574D 10386CC6C6FE00      <1>
   189 00015754 78CCC0CC78180C7800- <1>     db  078h, 0cch, 0c0h, 0cch, 078h, 018h, 00ch, 078h, 000h, 0cch, 000h, 0cch, 0cch, 0cch, 07eh, 000h
   189 0001575D CC00CCCCCC7E00      <1>
   190 00015764 1C0078CCFCC078007E- <1>     db  01ch, 000h, 078h, 0cch, 0fch, 0c0h, 078h, 000h, 07eh, 0c3h, 03ch, 006h, 03eh, 066h, 03fh, 000h
   190 0001576D C33C063E663F00      <1>
   191 00015774 CC00780C7CCC7E00E0- <1>     db  0cch, 000h, 078h, 00ch, 07ch, 0cch, 07eh, 000h, 0e0h, 000h, 078h, 00ch, 07ch, 0cch, 07eh, 000h
   191 0001577D 00780C7CCC7E00      <1>
   192 00015784 3030780C7CCC7E0000- <1>     db  030h, 030h, 078h, 00ch, 07ch, 0cch, 07eh, 000h, 000h, 000h, 078h, 0c0h, 0c0h, 078h, 00ch, 038h
   192 0001578D 0078C0C0780C38      <1>
   193 00015794 7EC33C667E603C00CC- <1>     db  07eh, 0c3h, 03ch, 066h, 07eh, 060h, 03ch, 000h, 0cch, 000h, 078h, 0cch, 0fch, 0c0h, 078h, 000h
   193 0001579D 0078CCFCC07800      <1>
   194 000157A4 E00078CCFCC07800CC- <1>     db  0e0h, 000h, 078h, 0cch, 0fch, 0c0h, 078h, 000h, 0cch, 000h, 070h, 030h, 030h, 030h, 078h, 000h
   194 000157AD 00703030307800      <1>
   195 000157B4 7CC6381818183C00E0- <1>     db  07ch, 0c6h, 038h, 018h, 018h, 018h, 03ch, 000h, 0e0h, 000h, 070h, 030h, 030h, 030h, 078h, 000h
   195 000157BD 00703030307800      <1>
   196 000157C4 C6386CC6FEC6C60030- <1>     db  0c6h, 038h, 06ch, 0c6h, 0feh, 0c6h, 0c6h, 000h, 030h, 030h, 000h, 078h, 0cch, 0fch, 0cch, 000h
   196 000157CD 300078CCFCCC00      <1>
   197 000157D4 1C00FC607860FC0000- <1>     db  01ch, 000h, 0fch, 060h, 078h, 060h, 0fch, 000h, 000h, 000h, 07fh, 00ch, 07fh, 0cch, 07fh, 000h
   197 000157DD 007F0C7FCC7F00      <1>
   198 000157E4 3E6CCCFECCCCCE0078- <1>     db  03eh, 06ch, 0cch, 0feh, 0cch, 0cch, 0ceh, 000h, 078h, 0cch, 000h, 078h, 0cch, 0cch, 078h, 000h
   198 000157ED CC0078CCCC7800      <1>
   199 000157F4 00CC0078CCCC780000- <1>     db  000h, 0cch, 000h, 078h, 0cch, 0cch, 078h, 000h, 000h, 0e0h, 000h, 078h, 0cch, 0cch, 078h, 000h
   199 000157FD E00078CCCC7800      <1>
   200 00015804 78CC00CCCCCC7E0000- <1>     db  078h, 0cch, 000h, 0cch, 0cch, 0cch, 07eh, 000h, 000h, 0e0h, 000h, 0cch, 0cch, 0cch, 07eh, 000h
   200 0001580D E000CCCCCC7E00      <1>
   201 00015814 00CC00CCCC7C0CF8C3- <1>     db  000h, 0cch, 000h, 0cch, 0cch, 07ch, 00ch, 0f8h, 0c3h, 018h, 03ch, 066h, 066h, 03ch, 018h, 000h
   201 0001581D 183C66663C1800      <1>
   202 00015824 CC00CCCCCCCC780018- <1>     db  0cch, 000h, 0cch, 0cch, 0cch, 0cch, 078h, 000h, 018h, 018h, 07eh, 0c0h, 0c0h, 07eh, 018h, 018h
   202 0001582D 187EC0C07E1818      <1>
   203 00015834 386C64F060E6FC00CC- <1>     db  038h, 06ch, 064h, 0f0h, 060h, 0e6h, 0fch, 000h, 0cch, 0cch, 078h, 0fch, 030h, 0fch, 030h, 030h
   203 0001583D CC78FC30FC3030      <1>
   204 00015844 F8CCCCFAC6CFC6C70E- <1>     db  0f8h, 0cch, 0cch, 0fah, 0c6h, 0cfh, 0c6h, 0c7h, 00eh, 01bh, 018h, 03ch, 018h, 018h, 0d8h, 070h
   204 0001584D 1B183C1818D870      <1>
   205 00015854 1C00780C7CCC7E0038- <1>     db  01ch, 000h, 078h, 00ch, 07ch, 0cch, 07eh, 000h, 038h, 000h, 070h, 030h, 030h, 030h, 078h, 000h
   205 0001585D 00703030307800      <1>
   206 00015864 001C0078CCCC780000- <1>     db  000h, 01ch, 000h, 078h, 0cch, 0cch, 078h, 000h, 000h, 01ch, 000h, 0cch, 0cch, 0cch, 07eh, 000h
   206 0001586D 1C00CCCCCC7E00      <1>
   207 00015874 00F800F8CCCCCC00FC- <1>     db  000h, 0f8h, 000h, 0f8h, 0cch, 0cch, 0cch, 000h, 0fch, 000h, 0cch, 0ech, 0fch, 0dch, 0cch, 000h
   207 0001587D 00CCECFCDCCC00      <1>
   208 00015884 3C6C6C3E007E000038- <1>     db  03ch, 06ch, 06ch, 03eh, 000h, 07eh, 000h, 000h, 038h, 06ch, 06ch, 038h, 000h, 07ch, 000h, 000h
   208 0001588D 6C6C38007C0000      <1>
   209 00015894 30003060C0CC780000- <1>     db  030h, 000h, 030h, 060h, 0c0h, 0cch, 078h, 000h, 000h, 000h, 000h, 0fch, 0c0h, 0c0h, 000h, 000h
   209 0001589D 0000FCC0C00000      <1>
   210 000158A4 000000FC0C0C0000C3- <1>     db  000h, 000h, 000h, 0fch, 00ch, 00ch, 000h, 000h, 0c3h, 0c6h, 0cch, 0deh, 033h, 066h, 0cch, 00fh
   210 000158AD C6CCDE3366CC0F      <1>
   211 000158B4 C3C6CCDB376FCF0318- <1>     db  0c3h, 0c6h, 0cch, 0dbh, 037h, 06fh, 0cfh, 003h, 018h, 018h, 000h, 018h, 018h, 018h, 018h, 000h
   211 000158BD 18001818181800      <1>
   212 000158C4 003366CC6633000000- <1>     db  000h, 033h, 066h, 0cch, 066h, 033h, 000h, 000h, 000h, 0cch, 066h, 033h, 066h, 0cch, 000h, 000h
   212 000158CD CC663366CC0000      <1>
   213 000158D4 228822882288228855- <1>     db  022h, 088h, 022h, 088h, 022h, 088h, 022h, 088h, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah
   213 000158DD AA55AA55AA55AA      <1>
   214 000158E4 DB77DBEEDB77DBEE18- <1>     db  0dbh, 077h, 0dbh, 0eeh, 0dbh, 077h, 0dbh, 0eeh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   214 000158ED 18181818181818      <1>
   215 000158F4 18181818F818181818- <1>     db  018h, 018h, 018h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 018h, 018h, 018h
   215 000158FD 18F818F8181818      <1>
   216 00015904 36363636F636363600- <1>     db  036h, 036h, 036h, 036h, 0f6h, 036h, 036h, 036h, 000h, 000h, 000h, 000h, 0feh, 036h, 036h, 036h
   216 0001590D 000000FE363636      <1>
   217 00015914 0000F818F818181836- <1>     db  000h, 000h, 0f8h, 018h, 0f8h, 018h, 018h, 018h, 036h, 036h, 0f6h, 006h, 0f6h, 036h, 036h, 036h
   217 0001591D 36F606F6363636      <1>
   218 00015924 363636363636363600- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 000h, 000h, 0feh, 006h, 0f6h, 036h, 036h, 036h
   218 0001592D 00FE06F6363636      <1>
   219 00015934 3636F606FE00000036- <1>     db  036h, 036h, 0f6h, 006h, 0feh, 000h, 000h, 000h, 036h, 036h, 036h, 036h, 0feh, 000h, 000h, 000h
   219 0001593D 363636FE000000      <1>
   220 00015944 1818F818F800000000- <1>     db  018h, 018h, 0f8h, 018h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 018h, 018h
   220 0001594D 000000F8181818      <1>
   221 00015954 181818181F00000018- <1>     db  018h, 018h, 018h, 018h, 01fh, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 0ffh, 000h, 000h, 000h
   221 0001595D 181818FF000000      <1>
   222 00015964 00000000FF18181818- <1>     db  000h, 000h, 000h, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 018h, 018h, 018h
   222 0001596D 1818181F181818      <1>
   223 00015974 00000000FF00000018- <1>     db  000h, 000h, 000h, 000h, 0ffh, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 0ffh, 018h, 018h, 018h
   223 0001597D 181818FF181818      <1>
   224 00015984 18181F181F18181836- <1>     db  018h, 018h, 01fh, 018h, 01fh, 018h, 018h, 018h, 036h, 036h, 036h, 036h, 037h, 036h, 036h, 036h
   224 0001598D 36363637363636      <1>
   225 00015994 363637303F00000000- <1>     db  036h, 036h, 037h, 030h, 03fh, 000h, 000h, 000h, 000h, 000h, 03fh, 030h, 037h, 036h, 036h, 036h
   225 0001599D 003F3037363636      <1>
   226 000159A4 3636F700FF00000000- <1>     db  036h, 036h, 0f7h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0f7h, 036h, 036h, 036h
   226 000159AD 00FF00F7363636      <1>
   227 000159B4 363637303736363600- <1>     db  036h, 036h, 037h, 030h, 037h, 036h, 036h, 036h, 000h, 000h, 0ffh, 000h, 0ffh, 000h, 000h, 000h
   227 000159BD 00FF00FF000000      <1>
   228 000159C4 3636F700F736363618- <1>     db  036h, 036h, 0f7h, 000h, 0f7h, 036h, 036h, 036h, 018h, 018h, 0ffh, 000h, 0ffh, 000h, 000h, 000h
   228 000159CD 18FF00FF000000      <1>
   229 000159D4 36363636FF00000000- <1>     db  036h, 036h, 036h, 036h, 0ffh, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0ffh, 018h, 018h, 018h
   229 000159DD 00FF00FF181818      <1>
   230 000159E4 00000000FF36363636- <1>     db  000h, 000h, 000h, 000h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 03fh, 000h, 000h, 000h
   230 000159ED 3636363F000000      <1>
   231 000159F4 18181F181F00000000- <1>     db  018h, 018h, 01fh, 018h, 01fh, 000h, 000h, 000h, 000h, 000h, 01fh, 018h, 01fh, 018h, 018h, 018h
   231 000159FD 001F181F181818      <1>
   232 00015A04 000000003F36363636- <1>     db  000h, 000h, 000h, 000h, 03fh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 036h, 036h, 036h
   232 00015A0D 363636FF363636      <1>
   233 00015A14 1818FF18FF18181818- <1>     db  018h, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h, 000h, 000h, 000h
   233 00015A1D 181818F8000000      <1>
   234 00015A24 000000001F181818FF- <1>     db  000h, 000h, 000h, 000h, 01fh, 018h, 018h, 018h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   234 00015A2D FFFFFFFFFFFFFF      <1>
   235 00015A34 00000000FFFFFFFFF0- <1>     db  000h, 000h, 000h, 000h, 0ffh, 0ffh, 0ffh, 0ffh, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h
   235 00015A3D F0F0F0F0F0F0F0      <1>
   236 00015A44 0F0F0F0F0F0F0F0FFF- <1>     db  00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 000h, 000h
   236 00015A4D FFFFFF00000000      <1>
   237 00015A54 000076DCC8DC760000- <1>     db  000h, 000h, 076h, 0dch, 0c8h, 0dch, 076h, 000h, 000h, 078h, 0cch, 0f8h, 0cch, 0f8h, 0c0h, 0c0h
   237 00015A5D 78CCF8CCF8C0C0      <1>
   238 00015A64 00FCCCC0C0C0C00000- <1>     db  000h, 0fch, 0cch, 0c0h, 0c0h, 0c0h, 0c0h, 000h, 000h, 0feh, 06ch, 06ch, 06ch, 06ch, 06ch, 000h
   238 00015A6D FE6C6C6C6C6C00      <1>
   239 00015A74 FCCC603060CCFC0000- <1>     db  0fch, 0cch, 060h, 030h, 060h, 0cch, 0fch, 000h, 000h, 000h, 07eh, 0d8h, 0d8h, 0d8h, 070h, 000h
   239 00015A7D 007ED8D8D87000      <1>
   240 00015A84 00666666667C60C000- <1>     db  000h, 066h, 066h, 066h, 066h, 07ch, 060h, 0c0h, 000h, 076h, 0dch, 018h, 018h, 018h, 018h, 000h
   240 00015A8D 76DC1818181800      <1>
   241 00015A94 FC3078CCCC7830FC38- <1>     db  0fch, 030h, 078h, 0cch, 0cch, 078h, 030h, 0fch, 038h, 06ch, 0c6h, 0feh, 0c6h, 06ch, 038h, 000h
   241 00015A9D 6CC6FEC66C3800      <1>
   242 00015AA4 386CC6C66C6CEE001C- <1>     db  038h, 06ch, 0c6h, 0c6h, 06ch, 06ch, 0eeh, 000h, 01ch, 030h, 018h, 07ch, 0cch, 0cch, 078h, 000h
   242 00015AAD 30187CCCCC7800      <1>
   243 00015AB4 00007EDBDB7E000006- <1>     db  000h, 000h, 07eh, 0dbh, 0dbh, 07eh, 000h, 000h, 006h, 00ch, 07eh, 0dbh, 0dbh, 07eh, 060h, 0c0h
   243 00015ABD 0C7EDBDB7E60C0      <1>
   244 00015AC4 3860C0F8C060380078- <1>     db  038h, 060h, 0c0h, 0f8h, 0c0h, 060h, 038h, 000h, 078h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 000h
   244 00015ACD CCCCCCCCCCCC00      <1>
   245 00015AD4 00FC00FC00FC000030- <1>     db  000h, 0fch, 000h, 0fch, 000h, 0fch, 000h, 000h, 030h, 030h, 0fch, 030h, 030h, 000h, 0fch, 000h
   245 00015ADD 30FC303000FC00      <1>
   246 00015AE4 603018306000FC0018- <1>     db  060h, 030h, 018h, 030h, 060h, 000h, 0fch, 000h, 018h, 030h, 060h, 030h, 018h, 000h, 0fch, 000h
   246 00015AED 3060301800FC00      <1>
   247 00015AF4 0E1B1B181818181818- <1>     db  00eh, 01bh, 01bh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0d8h, 0d8h, 070h
   247 00015AFD 18181818D8D870      <1>
   248 00015B04 303000FC0030300000- <1>     db  030h, 030h, 000h, 0fch, 000h, 030h, 030h, 000h, 000h, 076h, 0dch, 000h, 076h, 0dch, 000h, 000h
   248 00015B0D 76DC0076DC0000      <1>
   249 00015B14 386C6C380000000000- <1>     db  038h, 06ch, 06ch, 038h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h
   249 00015B1D 00001818000000      <1>
   250 00015B24 00000000180000000F- <1>     db  000h, 000h, 000h, 000h, 018h, 000h, 000h, 000h, 00fh, 00ch, 00ch, 00ch, 0ech, 06ch, 03ch, 01ch
   250 00015B2D 0C0C0CEC6C3C1C      <1>
   251 00015B34 786C6C6C6C00000070- <1>     db  078h, 06ch, 06ch, 06ch, 06ch, 000h, 000h, 000h, 070h, 018h, 030h, 060h, 078h, 000h, 000h, 000h
   251 00015B3D 18306078000000      <1>
   252 00015B44 00003C3C3C3C000000- <1>     db  000h, 000h, 03ch, 03ch, 03ch, 03ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   252 00015B4D 00000000000000      <1>
   253                              <1> vgafont14:
   254 00015B54 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   254 00015B5D 00000000000000      <1>
   255 00015B64 7E81A58181BD99817E- <1>     db  07eh, 081h, 0a5h, 081h, 081h, 0bdh, 099h, 081h, 07eh, 000h, 000h, 000h, 000h, 000h, 07eh, 0ffh
   255 00015B6D 00000000007EFF      <1>
   256 00015B74 DBFFFFC3E7FF7E0000- <1>     db  0dbh, 0ffh, 0ffh, 0c3h, 0e7h, 0ffh, 07eh, 000h, 000h, 000h, 000h, 000h, 000h, 06ch, 0feh, 0feh
   256 00015B7D 000000006CFEFE      <1>
   257 00015B84 FEFE7C381000000000- <1>     db  0feh, 0feh, 07ch, 038h, 010h, 000h, 000h, 000h, 000h, 000h, 000h, 010h, 038h, 07ch, 0feh, 07ch
   257 00015B8D 000010387CFE7C      <1>
   258 00015B94 381000000000000018- <1>     db  038h, 010h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 03ch, 03ch, 0e7h, 0e7h, 0e7h, 018h, 018h
   258 00015B9D 3C3CE7E7E71818      <1>
   259 00015BA4 3C0000000000183C7E- <1>     db  03ch, 000h, 000h, 000h, 000h, 000h, 018h, 03ch, 07eh, 0ffh, 0ffh, 07eh, 018h, 018h, 03ch, 000h
   259 00015BAD FFFF7E18183C00      <1>
   260 00015BB4 00000000000000183C- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 03ch, 03ch, 018h, 000h, 000h, 000h, 000h, 000h
   260 00015BBD 3C180000000000      <1>
   261 00015BC4 FFFFFFFFFFE7C3C3E7- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0e7h, 0c3h, 0c3h, 0e7h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h
   261 00015BCD FFFFFFFFFF0000      <1>
   262 00015BD4 00003C664242663C00- <1>     db  000h, 000h, 03ch, 066h, 042h, 042h, 066h, 03ch, 000h, 000h, 000h, 000h, 0ffh, 0ffh, 0ffh, 0ffh
   262 00015BDD 000000FFFFFFFF      <1>
   263 00015BE4 C399BDBD99C3FFFFFF- <1>     db  0c3h, 099h, 0bdh, 0bdh, 099h, 0c3h, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 01eh, 00eh, 01ah, 032h
   263 00015BED FF00001E0E1A32      <1>
   264 00015BF4 78CCCCCC7800000000- <1>     db  078h, 0cch, 0cch, 0cch, 078h, 000h, 000h, 000h, 000h, 000h, 03ch, 066h, 066h, 066h, 03ch, 018h
   264 00015BFD 003C6666663C18      <1>
   265 00015C04 7E181800000000003F- <1>     db  07eh, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 03fh, 033h, 03fh, 030h, 030h, 030h, 070h, 0f0h
   265 00015C0D 333F30303070F0      <1>
   266 00015C14 E000000000007F637F- <1>     db  0e0h, 000h, 000h, 000h, 000h, 000h, 07fh, 063h, 07fh, 063h, 063h, 063h, 067h, 0e7h, 0e6h, 0c0h
   266 00015C1D 63636367E7E6C0      <1>
   267 00015C24 000000001818DB3CE7- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 0dbh, 03ch, 0e7h, 03ch, 0dbh, 018h, 018h, 000h, 000h, 000h
   267 00015C2D 3CDB1818000000      <1>
   268 00015C34 000080C0E0F8FEF8E0- <1>     db  000h, 000h, 080h, 0c0h, 0e0h, 0f8h, 0feh, 0f8h, 0e0h, 0c0h, 080h, 000h, 000h, 000h, 000h, 000h
   268 00015C3D C0800000000000      <1>
   269 00015C44 02060E3EFE3E0E0602- <1>     db  002h, 006h, 00eh, 03eh, 0feh, 03eh, 00eh, 006h, 002h, 000h, 000h, 000h, 000h, 000h, 018h, 03ch
   269 00015C4D 0000000000183C      <1>
   270 00015C54 7E1818187E3C180000- <1>     db  07eh, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 066h, 066h
   270 00015C5D 00000066666666      <1>
   271 00015C64 666600666600000000- <1>     db  066h, 066h, 000h, 066h, 066h, 000h, 000h, 000h, 000h, 000h, 07fh, 0dbh, 0dbh, 0dbh, 07bh, 01bh
   271 00015C6D 007FDBDBDB7B1B      <1>
   272 00015C74 1B1B1B000000007CC6- <1>     db  01bh, 01bh, 01bh, 000h, 000h, 000h, 000h, 07ch, 0c6h, 060h, 038h, 06ch, 0c6h, 0c6h, 06ch, 038h
   272 00015C7D 60386CC6C66C38      <1>
   273 00015C84 0CC67C000000000000- <1>     db  00ch, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 0feh, 0feh, 000h
   273 00015C8D 000000FEFEFE00      <1>
   274 00015C94 00000000183C7E1818- <1>     db  000h, 000h, 000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 07eh, 03ch, 018h, 07eh, 000h, 000h
   274 00015C9D 187E3C187E0000      <1>
   275 00015CA4 0000183C7E18181818- <1>     db  000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h, 000h
   275 00015CAD 18180000000000      <1>
   276 00015CB4 1818181818187E3C18- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   276 00015CBD 00000000000000      <1>
   277 00015CC4 180CFE0C1800000000- <1>     db  018h, 00ch, 0feh, 00ch, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 030h, 060h
   277 00015CCD 00000000003060      <1>
   278 00015CD4 FE6030000000000000- <1>     db  0feh, 060h, 030h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0c0h, 0c0h, 0c0h
   278 00015CDD 00000000C0C0C0      <1>
   279 00015CE4 FE0000000000000000- <1>     db  0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 028h, 06ch, 0feh, 06ch, 028h, 000h
   279 00015CED 00286CFE6C2800      <1>
   280 00015CF4 000000000000001038- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 010h, 038h, 038h, 07ch, 07ch, 0feh, 0feh, 000h, 000h
   280 00015CFD 387C7CFEFE0000      <1>
   281 00015D04 0000000000FEFE7C7C- <1>     db  000h, 000h, 000h, 000h, 000h, 0feh, 0feh, 07ch, 07ch, 038h, 038h, 010h, 000h, 000h, 000h, 000h
   281 00015D0D 38381000000000      <1>
   282 00015D14 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   282 00015D1D 00000000000000      <1>
   283 00015D24 183C3C3C1818001818- <1>     db  018h, 03ch, 03ch, 03ch, 018h, 018h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 066h, 066h, 066h
   283 00015D2D 00000000666666      <1>
   284 00015D34 240000000000000000- <1>     db  024h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 06ch, 06ch, 0feh, 06ch
   284 00015D3D 0000006C6CFE6C      <1>
   285 00015D44 6C6CFE6C6C00000018- <1>     db  06ch, 06ch, 0feh, 06ch, 06ch, 000h, 000h, 000h, 018h, 018h, 07ch, 0c6h, 0c2h, 0c0h, 07ch, 006h
   285 00015D4D 187CC6C2C07C06      <1>
   286 00015D54 86C67C181800000000- <1>     db  086h, 0c6h, 07ch, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 0c2h, 0c6h, 00ch, 018h, 030h, 066h
   286 00015D5D 00C2C60C183066      <1>
   287 00015D64 C60000000000386C6C- <1>     db  0c6h, 000h, 000h, 000h, 000h, 000h, 038h, 06ch, 06ch, 038h, 076h, 0dch, 0cch, 0cch, 076h, 000h
   287 00015D6D 3876DCCCCC7600      <1>
   288 00015D74 000000303030600000- <1>     db  000h, 000h, 000h, 030h, 030h, 030h, 060h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   288 00015D7D 00000000000000      <1>
   289 00015D84 00000C183030303030- <1>     db  000h, 000h, 00ch, 018h, 030h, 030h, 030h, 030h, 030h, 018h, 00ch, 000h, 000h, 000h, 000h, 000h
   289 00015D8D 180C0000000000      <1>
   290 00015D94 30180C0C0C0C0C1830- <1>     db  030h, 018h, 00ch, 00ch, 00ch, 00ch, 00ch, 018h, 030h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   290 00015D9D 00000000000000      <1>
   291 00015DA4 663CFF3C6600000000- <1>     db  066h, 03ch, 0ffh, 03ch, 066h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h
   291 00015DAD 00000000001818      <1>
   292 00015DB4 7E1818000000000000- <1>     db  07eh, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   292 00015DBD 00000000000000      <1>
   293 00015DC4 181818300000000000- <1>     db  018h, 018h, 018h, 030h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 000h, 000h, 000h
   293 00015DCD 000000FE000000      <1>
   294 00015DD4 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h
   294 00015DDD 00000000181800      <1>
   295 00015DE4 0000000002060C1830- <1>     db  000h, 000h, 000h, 000h, 002h, 006h, 00ch, 018h, 030h, 060h, 0c0h, 080h, 000h, 000h, 000h, 000h
   295 00015DED 60C08000000000      <1>
   296 00015DF4 00007CC6CEDEF6E6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0ceh, 0deh, 0f6h, 0e6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h
   296 00015DFD C67C0000000000      <1>
   297 00015E04 18387818181818187E- <1>     db  018h, 038h, 078h, 018h, 018h, 018h, 018h, 018h, 07eh, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h
   297 00015E0D 00000000007CC6      <1>
   298 00015E14 060C183060C6FE0000- <1>     db  006h, 00ch, 018h, 030h, 060h, 0c6h, 0feh, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 006h, 006h
   298 00015E1D 0000007CC60606      <1>
   299 00015E24 3C0606C67C00000000- <1>     db  03ch, 006h, 006h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 00ch, 01ch, 03ch, 06ch, 0cch, 0feh
   299 00015E2D 000C1C3C6CCCFE      <1>
   300 00015E34 0C0C1E0000000000FE- <1>     db  00ch, 00ch, 01eh, 000h, 000h, 000h, 000h, 000h, 0feh, 0c0h, 0c0h, 0c0h, 0fch, 006h, 006h, 0c6h
   300 00015E3D C0C0C0FC0606C6      <1>
   301 00015E44 7C00000000003860C0- <1>     db  07ch, 000h, 000h, 000h, 000h, 000h, 038h, 060h, 0c0h, 0c0h, 0fch, 0c6h, 0c6h, 0c6h, 07ch, 000h
   301 00015E4D C0FCC6C6C67C00      <1>
   302 00015E54 00000000FEC6060C18- <1>     db  000h, 000h, 000h, 000h, 0feh, 0c6h, 006h, 00ch, 018h, 030h, 030h, 030h, 030h, 000h, 000h, 000h
   302 00015E5D 30303030000000      <1>
   303 00015E64 00007CC6C6C67CC6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 07ch, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h
   303 00015E6D C67C0000000000      <1>
   304 00015E74 7CC6C6C67E06060C78- <1>     db  07ch, 0c6h, 0c6h, 0c6h, 07eh, 006h, 006h, 00ch, 078h, 000h, 000h, 000h, 000h, 000h, 000h, 018h
   304 00015E7D 00000000000018      <1>
   305 00015E84 180000001818000000- <1>     db  018h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h
   305 00015E8D 00000000181800      <1>
   306 00015E94 000018183000000000- <1>     db  000h, 000h, 018h, 018h, 030h, 000h, 000h, 000h, 000h, 000h, 006h, 00ch, 018h, 030h, 060h, 030h
   306 00015E9D 00060C18306030      <1>
   307 00015EA4 180C06000000000000- <1>     db  018h, 00ch, 006h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07eh, 000h, 000h, 07eh, 000h
   307 00015EAD 00007E00007E00      <1>
   308 00015EB4 000000000000603018- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 060h, 030h, 018h, 00ch, 006h, 00ch, 018h, 030h, 060h, 000h
   308 00015EBD 0C060C18306000      <1>
   309 00015EC4 000000007CC6C60C18- <1>     db  000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 00ch, 018h, 018h, 000h, 018h, 018h, 000h, 000h, 000h
   309 00015ECD 18001818000000      <1>
   310 00015ED4 00007CC6C6DEDEDEDC- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0deh, 0deh, 0deh, 0dch, 0c0h, 07ch, 000h, 000h, 000h, 000h, 000h
   310 00015EDD C07C0000000000      <1>
   311 00015EE4 10386CC6C6FEC6C6C6- <1>     db  010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h, 000h, 0fch, 066h
   311 00015EED 0000000000FC66      <1>
   312 00015EF4 66667C666666FC0000- <1>     db  066h, 066h, 07ch, 066h, 066h, 066h, 0fch, 000h, 000h, 000h, 000h, 000h, 03ch, 066h, 0c2h, 0c0h
   312 00015EFD 0000003C66C2C0      <1>
   313 00015F04 C0C0C2663C00000000- <1>     db  0c0h, 0c0h, 0c2h, 066h, 03ch, 000h, 000h, 000h, 000h, 000h, 0f8h, 06ch, 066h, 066h, 066h, 066h
   313 00015F0D 00F86C66666666      <1>
   314 00015F14 666CF80000000000FE- <1>     db  066h, 06ch, 0f8h, 000h, 000h, 000h, 000h, 000h, 0feh, 066h, 062h, 068h, 078h, 068h, 062h, 066h
   314 00015F1D 66626878686266      <1>
   315 00015F24 FE0000000000FE6662- <1>     db  0feh, 000h, 000h, 000h, 000h, 000h, 0feh, 066h, 062h, 068h, 078h, 068h, 060h, 060h, 0f0h, 000h
   315 00015F2D 6878686060F000      <1>
   316 00015F34 000000003C66C2C0C0- <1>     db  000h, 000h, 000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0deh, 0c6h, 066h, 03ah, 000h, 000h, 000h
   316 00015F3D DEC6663A000000      <1>
   317 00015F44 0000C6C6C6C6FEC6C6- <1>     db  000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h, 000h
   317 00015F4D C6C60000000000      <1>
   318 00015F54 3C181818181818183C- <1>     db  03ch, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 01eh, 00ch
   318 00015F5D 00000000001E0C      <1>
   319 00015F64 0C0C0C0CCCCC780000- <1>     db  00ch, 00ch, 00ch, 00ch, 0cch, 0cch, 078h, 000h, 000h, 000h, 000h, 000h, 0e6h, 066h, 06ch, 06ch
   319 00015F6D 000000E6666C6C      <1>
   320 00015F74 786C6C66E600000000- <1>     db  078h, 06ch, 06ch, 066h, 0e6h, 000h, 000h, 000h, 000h, 000h, 0f0h, 060h, 060h, 060h, 060h, 060h
   320 00015F7D 00F06060606060      <1>
   321 00015F84 6266FE0000000000C6- <1>     db  062h, 066h, 0feh, 000h, 000h, 000h, 000h, 000h, 0c6h, 0eeh, 0feh, 0feh, 0d6h, 0c6h, 0c6h, 0c6h
   321 00015F8D EEFEFED6C6C6C6      <1>
   322 00015F94 C60000000000C6E6F6- <1>     db  0c6h, 000h, 000h, 000h, 000h, 000h, 0c6h, 0e6h, 0f6h, 0feh, 0deh, 0ceh, 0c6h, 0c6h, 0c6h, 000h
   322 00015F9D FEDECEC6C6C600      <1>
   323 00015FA4 00000000386CC6C6C6- <1>     db  000h, 000h, 000h, 000h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 06ch, 038h, 000h, 000h, 000h
   323 00015FAD C6C66C38000000      <1>
   324 00015FB4 0000FC6666667C6060- <1>     db  000h, 000h, 0fch, 066h, 066h, 066h, 07ch, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h, 000h
   324 00015FBD 60F00000000000      <1>
   325 00015FC4 7CC6C6C6C6D6DE7C0C- <1>     db  07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0d6h, 0deh, 07ch, 00ch, 00eh, 000h, 000h, 000h, 000h, 0fch, 066h
   325 00015FCD 0E00000000FC66      <1>
   326 00015FD4 66667C6C6666E60000- <1>     db  066h, 066h, 07ch, 06ch, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 060h
   326 00015FDD 0000007CC6C660      <1>
   327 00015FE4 380CC6C67C00000000- <1>     db  038h, 00ch, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 07eh, 07eh, 05ah, 018h, 018h, 018h
   327 00015FED 007E7E5A181818      <1>
   328 00015FF4 18183C0000000000C6- <1>     db  018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h
   328 00015FFD C6C6C6C6C6C6C6      <1>
   329 00016004 7C0000000000C6C6C6- <1>     db  07ch, 000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 06ch, 038h, 010h, 000h
   329 0001600D C6C6C66C381000      <1>
   330 00016014 00000000C6C6C6C6D6- <1>     db  000h, 000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0d6h, 0d6h, 0feh, 07ch, 06ch, 000h, 000h, 000h
   330 0001601D D6FE7C6C000000      <1>
   331 00016024 0000C6C66C3838386C- <1>     db  000h, 000h, 0c6h, 0c6h, 06ch, 038h, 038h, 038h, 06ch, 0c6h, 0c6h, 000h, 000h, 000h, 000h, 000h
   331 0001602D C6C60000000000      <1>
   332 00016034 666666663C1818183C- <1>     db  066h, 066h, 066h, 066h, 03ch, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 0feh, 0c6h
   332 0001603D 0000000000FEC6      <1>
   333 00016044 8C183060C2C6FE0000- <1>     db  08ch, 018h, 030h, 060h, 0c2h, 0c6h, 0feh, 000h, 000h, 000h, 000h, 000h, 03ch, 030h, 030h, 030h
   333 0001604D 0000003C303030      <1>
   334 00016054 303030303C00000000- <1>     db  030h, 030h, 030h, 030h, 03ch, 000h, 000h, 000h, 000h, 000h, 080h, 0c0h, 0e0h, 070h, 038h, 01ch
   334 0001605D 0080C0E070381C      <1>
   335 00016064 0E060200000000003C- <1>     db  00eh, 006h, 002h, 000h, 000h, 000h, 000h, 000h, 03ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch
   335 0001606D 0C0C0C0C0C0C0C      <1>
   336 00016074 3C00000010386CC600- <1>     db  03ch, 000h, 000h, 000h, 010h, 038h, 06ch, 0c6h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   336 0001607D 00000000000000      <1>
   337 00016084 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h
   337 0001608D 0000000000FF00      <1>
   338 00016094 303018000000000000- <1>     db  030h, 030h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   338 0001609D 00000000000000      <1>
   339 000160A4 000000780C7CCCCC76- <1>     db  000h, 000h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 000h, 0e0h, 060h
   339 000160AD 0000000000E060      <1>
   340 000160B4 60786C6666667C0000- <1>     db  060h, 078h, 06ch, 066h, 066h, 066h, 07ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch
   340 000160BD 0000000000007C      <1>
   341 000160C4 C6C0C0C67C00000000- <1>     db  0c6h, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 01ch, 00ch, 00ch, 03ch, 06ch, 0cch
   341 000160CD 001C0C0C3C6CCC      <1>
   342 000160D4 CCCC76000000000000- <1>     db  0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h
   342 000160DD 00007CC6FEC0C6      <1>
   343 000160E4 7C0000000000386C64- <1>     db  07ch, 000h, 000h, 000h, 000h, 000h, 038h, 06ch, 064h, 060h, 0f0h, 060h, 060h, 060h, 0f0h, 000h
   343 000160ED 60F0606060F000      <1>
   344 000160F4 0000000000000076CC- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 076h, 0cch, 0cch, 0cch, 07ch, 00ch, 0cch, 078h, 000h
   344 000160FD CCCC7C0CCC7800      <1>
   345 00016104 0000E060606C766666- <1>     db  000h, 000h, 0e0h, 060h, 060h, 06ch, 076h, 066h, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h, 000h
   345 0001610D 66E60000000000      <1>
   346 00016114 18180038181818183C- <1>     db  018h, 018h, 000h, 038h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 006h, 006h
   346 0001611D 00000000000606      <1>
   347 00016124 000E0606060666663C- <1>     db  000h, 00eh, 006h, 006h, 006h, 006h, 066h, 066h, 03ch, 000h, 000h, 000h, 0e0h, 060h, 060h, 066h
   347 0001612D 000000E0606066      <1>
   348 00016134 6C786C66E600000000- <1>     db  06ch, 078h, 06ch, 066h, 0e6h, 000h, 000h, 000h, 000h, 000h, 038h, 018h, 018h, 018h, 018h, 018h
   348 0001613D 00381818181818      <1>
   349 00016144 18183C000000000000- <1>     db  018h, 018h, 03ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ech, 0feh, 0d6h, 0d6h, 0d6h
   349 0001614D 0000ECFED6D6D6      <1>
   350 00016154 C60000000000000000- <1>     db  0c6h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0dch, 066h, 066h, 066h, 066h, 066h, 000h
   350 0001615D DC666666666600      <1>
   351 00016164 000000000000007CC6- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h
   351 0001616D C6C6C67C000000      <1>
   352 00016174 0000000000DC666666- <1>     db  000h, 000h, 000h, 000h, 000h, 0dch, 066h, 066h, 066h, 07ch, 060h, 060h, 0f0h, 000h, 000h, 000h
   352 0001617D 7C6060F0000000      <1>
   353 00016184 00000076CCCCCC7C0C- <1>     db  000h, 000h, 000h, 076h, 0cch, 0cch, 0cch, 07ch, 00ch, 00ch, 01eh, 000h, 000h, 000h, 000h, 000h
   353 0001618D 0C1E0000000000      <1>
   354 00016194 00DC76666060F00000- <1>     db  000h, 0dch, 076h, 066h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch
   354 0001619D 0000000000007C      <1>
   355 000161A4 C6701CC67C00000000- <1>     db  0c6h, 070h, 01ch, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 010h, 030h, 030h, 0fch, 030h, 030h
   355 000161AD 00103030FC3030      <1>
   356 000161B4 30361C000000000000- <1>     db  030h, 036h, 01ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch
   356 000161BD 0000CCCCCCCCCC      <1>
   357 000161C4 760000000000000000- <1>     db  076h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 066h, 066h, 03ch, 018h, 000h
   357 000161CD 666666663C1800      <1>
   358 000161D4 00000000000000C6C6- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 0d6h, 0d6h, 0feh, 06ch, 000h, 000h, 000h
   358 000161DD D6D6FE6C000000      <1>
   359 000161E4 0000000000C66C3838- <1>     db  000h, 000h, 000h, 000h, 000h, 0c6h, 06ch, 038h, 038h, 06ch, 0c6h, 000h, 000h, 000h, 000h, 000h
   359 000161ED 6CC60000000000      <1>
   360 000161F4 000000C6C6C6C67E06- <1>     db  000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 07eh, 006h, 00ch, 0f8h, 000h, 000h, 000h, 000h, 000h
   360 000161FD 0CF80000000000      <1>
   361 00016204 00FECC183066FE0000- <1>     db  000h, 0feh, 0cch, 018h, 030h, 066h, 0feh, 000h, 000h, 000h, 000h, 000h, 00eh, 018h, 018h, 018h
   361 0001620D 0000000E181818      <1>
   362 00016214 701818180E00000000- <1>     db  070h, 018h, 018h, 018h, 00eh, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 000h, 018h
   362 0001621D 00181818180018      <1>
   363 00016224 181818000000000070- <1>     db  018h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 070h, 018h, 018h, 018h, 00eh, 018h, 018h, 018h
   363 0001622D 1818180E181818      <1>
   364 00016234 70000000000076DC00- <1>     db  070h, 000h, 000h, 000h, 000h, 000h, 076h, 0dch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   364 0001623D 00000000000000      <1>
   365 00016244 00000000000010386C- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 000h, 000h, 000h, 000h
   365 0001624D C6C6FE00000000      <1>
   366 00016254 00003C66C2C0C0C266- <1>     db  000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0c2h, 066h, 03ch, 00ch, 006h, 07ch, 000h, 000h, 000h
   366 0001625D 3C0C067C000000      <1>
   367 00016264 CCCC00CCCCCCCCCC76- <1>     db  0cch, 0cch, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 00ch, 018h, 030h
   367 0001626D 000000000C1830      <1>
   368 00016274 007CC6FEC0C67C0000- <1>     db  000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 010h, 038h, 06ch, 000h, 078h
   368 0001627D 000010386C0078      <1>
   369 00016284 0C7CCCCC7600000000- <1>     db  00ch, 07ch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 000h, 0cch, 0cch, 000h, 078h, 00ch, 07ch
   369 0001628D 00CCCC00780C7C      <1>
   370 00016294 CCCC76000000006030- <1>     db  0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 060h, 030h, 018h, 000h, 078h, 00ch, 07ch, 0cch, 0cch
   370 0001629D 1800780C7CCCCC      <1>
   371 000162A4 7600000000386C3800- <1>     db  076h, 000h, 000h, 000h, 000h, 038h, 06ch, 038h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 076h, 000h
   371 000162AD 780C7CCCCC7600      <1>
   372 000162B4 0000000000003C6660- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 03ch, 066h, 060h, 066h, 03ch, 00ch, 006h, 03ch, 000h, 000h
   372 000162BD 663C0C063C0000      <1>
   373 000162C4 0010386C007CC6FEC0- <1>     db  000h, 010h, 038h, 06ch, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h
   373 000162CD C67C0000000000      <1>
   374 000162D4 CCCC007CC6FEC0C67C- <1>     db  0cch, 0cch, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 060h, 030h, 018h
   374 000162DD 00000000603018      <1>
   375 000162E4 007CC6FEC0C67C0000- <1>     db  000h, 07ch, 0c6h, 0feh, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 000h, 038h
   375 000162ED 00000066660038      <1>
   376 000162F4 181818183C00000000- <1>     db  018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 018h, 03ch, 066h, 000h, 038h, 018h, 018h
   376 000162FD 183C6600381818      <1>
   377 00016304 18183C000000006030- <1>     db  018h, 018h, 03ch, 000h, 000h, 000h, 000h, 060h, 030h, 018h, 000h, 038h, 018h, 018h, 018h, 018h
   377 0001630D 18003818181818      <1>
   378 00016314 3C00000000C6C61038- <1>     db  03ch, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 000h
   378 0001631D 6CC6C6FEC6C600      <1>
   379 00016324 0000386C3800386CC6- <1>     db  000h, 000h, 038h, 06ch, 038h, 000h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 000h, 000h, 000h
   379 0001632D C6FEC6C6000000      <1>
   380 00016334 18306000FE66607C60- <1>     db  018h, 030h, 060h, 000h, 0feh, 066h, 060h, 07ch, 060h, 066h, 0feh, 000h, 000h, 000h, 000h, 000h
   380 0001633D 66FE0000000000      <1>
   381 00016344 0000CC76367ED8D86E- <1>     db  000h, 000h, 0cch, 076h, 036h, 07eh, 0d8h, 0d8h, 06eh, 000h, 000h, 000h, 000h, 000h, 03eh, 06ch
   381 0001634D 00000000003E6C      <1>
   382 00016354 CCCCFECCCCCCCE0000- <1>     db  0cch, 0cch, 0feh, 0cch, 0cch, 0cch, 0ceh, 000h, 000h, 000h, 000h, 010h, 038h, 06ch, 000h, 07ch
   382 0001635D 000010386C007C      <1>
   383 00016364 C6C6C6C67C00000000- <1>     db  0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 000h, 07ch, 0c6h, 0c6h
   383 0001636D 00C6C6007CC6C6      <1>
   384 00016374 C6C67C000000006030- <1>     db  0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 060h, 030h, 018h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h
   384 0001637D 18007CC6C6C6C6      <1>
   385 00016384 7C000000003078CC00- <1>     db  07ch, 000h, 000h, 000h, 000h, 030h, 078h, 0cch, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h
   385 0001638D CCCCCCCCCC7600      <1>
   386 00016394 00000060301800CCCC- <1>     db  000h, 000h, 000h, 060h, 030h, 018h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h
   386 0001639D CCCCCC76000000      <1>
   387 000163A4 0000C6C600C6C6C6C6- <1>     db  000h, 000h, 0c6h, 0c6h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 07eh, 006h, 00ch, 078h, 000h, 000h, 0c6h
   387 000163AD 7E060C780000C6      <1>
   388 000163B4 C6386CC6C6C6C66C38- <1>     db  0c6h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 0c6h, 06ch, 038h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 000h
   388 000163BD 00000000C6C600      <1>
   389 000163C4 C6C6C6C6C6C67C0000- <1>     db  0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 018h, 018h, 03ch, 066h, 060h
   389 000163CD 000018183C6660      <1>
   390 000163D4 60663C181800000000- <1>     db  060h, 066h, 03ch, 018h, 018h, 000h, 000h, 000h, 000h, 038h, 06ch, 064h, 060h, 0f0h, 060h, 060h
   390 000163DD 386C6460F06060      <1>
   391 000163E4 60E6FC000000000066- <1>     db  060h, 0e6h, 0fch, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 03ch, 018h, 07eh, 018h, 07eh, 018h
   391 000163ED 663C187E187E18      <1>
   392 000163F4 1800000000F8CCCCF8- <1>     db  018h, 000h, 000h, 000h, 000h, 0f8h, 0cch, 0cch, 0f8h, 0c4h, 0cch, 0deh, 0cch, 0cch, 0c6h, 000h
   392 000163FD C4CCDECCCCC600      <1>
   393 00016404 0000000E1B1818187E- <1>     db  000h, 000h, 000h, 00eh, 01bh, 018h, 018h, 018h, 07eh, 018h, 018h, 018h, 018h, 0d8h, 070h, 000h
   393 0001640D 18181818D87000      <1>
   394 00016414 0018306000780C7CCC- <1>     db  000h, 018h, 030h, 060h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 00ch
   394 0001641D CC76000000000C      <1>
   395 00016424 18300038181818183C- <1>     db  018h, 030h, 000h, 038h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 018h, 030h, 060h
   395 0001642D 00000000183060      <1>
   396 00016434 007CC6C6C6C67C0000- <1>     db  000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 018h, 030h, 060h, 000h, 0cch
   396 0001643D 000018306000CC      <1>
   397 00016444 CCCCCCCC7600000000- <1>     db  0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h, 000h, 076h, 0dch, 000h, 0dch, 066h, 066h
   397 0001644D 0076DC00DC6666      <1>
   398 00016454 66666600000076DC00- <1>     db  066h, 066h, 066h, 000h, 000h, 000h, 076h, 0dch, 000h, 0c6h, 0e6h, 0f6h, 0feh, 0deh, 0ceh, 0c6h
   398 0001645D C6E6F6FEDECEC6      <1>
   399 00016464 C6000000003C6C6C3E- <1>     db  0c6h, 000h, 000h, 000h, 000h, 03ch, 06ch, 06ch, 03eh, 000h, 07eh, 000h, 000h, 000h, 000h, 000h
   399 0001646D 007E0000000000      <1>
   400 00016474 000000386C6C38007C- <1>     db  000h, 000h, 000h, 038h, 06ch, 06ch, 038h, 000h, 07ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   400 0001647D 00000000000000      <1>
   401 00016484 0000303000303060C6- <1>     db  000h, 000h, 030h, 030h, 000h, 030h, 030h, 060h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h, 000h
   401 0001648D C67C0000000000      <1>
   402 00016494 00000000FEC0C0C000- <1>     db  000h, 000h, 000h, 000h, 0feh, 0c0h, 0c0h, 0c0h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   402 0001649D 00000000000000      <1>
   403 000164A4 0000FE060606000000- <1>     db  000h, 000h, 0feh, 006h, 006h, 006h, 000h, 000h, 000h, 000h, 000h, 0c0h, 0c0h, 0c6h, 0cch, 0d8h
   403 000164AD 0000C0C0C6CCD8      <1>
   404 000164B4 3060DC860C183E0000- <1>     db  030h, 060h, 0dch, 086h, 00ch, 018h, 03eh, 000h, 000h, 0c0h, 0c0h, 0c6h, 0cch, 0d8h, 030h, 066h
   404 000164BD C0C0C6CCD83066      <1>
   405 000164C4 CE9E3E060600000018- <1>     db  0ceh, 09eh, 03eh, 006h, 006h, 000h, 000h, 000h, 018h, 018h, 000h, 018h, 018h, 03ch, 03ch, 03ch
   405 000164CD 180018183C3C3C      <1>
   406 000164D4 180000000000000036- <1>     db  018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 036h, 06ch, 0d8h, 06ch, 036h, 000h, 000h, 000h
   406 000164DD 6CD86C36000000      <1>
   407 000164E4 000000000000D86C36- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 0d8h, 06ch, 036h, 06ch, 0d8h, 000h, 000h, 000h, 000h, 000h
   407 000164ED 6CD80000000000      <1>
   408 000164F4 114411441144114411- <1>     db  011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 055h, 0aah
   408 000164FD 441144114455AA      <1>
   409 00016504 55AA55AA55AA55AA55- <1>     db  055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 0ddh, 077h, 0ddh, 077h
   409 0001650D AA55AADD77DD77      <1>
   410 00016514 DD77DD77DD77DD77DD- <1>     db  0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 018h, 018h, 018h, 018h, 018h, 018h
   410 0001651D 77181818181818      <1>
   411 00016524 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h
   411 0001652D 181818181818F8      <1>
   412 00016534 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 018h, 018h
   412 0001653D 1818F818F81818      <1>
   413 00016544 181818183636363636- <1>     db  018h, 018h, 018h, 018h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0f6h, 036h, 036h, 036h, 036h
   413 0001654D 3636F636363636      <1>
   414 00016554 363600000000000000- <1>     db  036h, 036h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 036h, 036h, 036h, 036h, 036h, 036h
   414 0001655D FE363636363636      <1>
   415 00016564 0000000000F818F818- <1>     db  000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 036h, 036h
   415 0001656D 18181818183636      <1>
   416 00016574 363636F606F6363636- <1>     db  036h, 036h, 036h, 0f6h, 006h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   416 0001657D 36363636363636      <1>
   417 00016584 363636363636363636- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 000h, 000h, 000h, 000h, 000h, 0feh
   417 0001658D 360000000000FE      <1>
   418 00016594 06F636363636363636- <1>     db  006h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0f6h, 006h, 0feh
   418 0001659D 36363636F606FE      <1>
   419 000165A4 000000000000363636- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0feh, 000h, 000h
   419 000165AD 36363636FE0000      <1>
   420 000165B4 000000001818181818- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 000h, 000h, 000h, 000h
   420 000165BD F818F800000000      <1>
   421 000165C4 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h
   421 000165CD F8181818181818      <1>
   422 000165D4 181818181818181F00- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h
   422 000165DD 00000000001818      <1>
   423 000165E4 1818181818FF000000- <1>     db  018h, 018h, 018h, 018h, 018h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   423 000165ED 00000000000000      <1>
   424 000165F4 000000FF1818181818- <1>     db  000h, 000h, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   424 000165FD 18181818181818      <1>
   425 00016604 181F18181818181800- <1>     db  018h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh
   425 0001660D 000000000000FF      <1>
   426 00016614 000000000000181818- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0ffh, 018h, 018h
   426 0001661D 18181818FF1818      <1>
   427 00016624 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 018h, 01fh, 018h, 018h, 018h, 018h
   427 0001662D 1F181F18181818      <1>
   428 00016634 181836363636363636- <1>     db  018h, 018h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 037h, 036h, 036h, 036h, 036h, 036h, 036h
   428 0001663D 37363636363636      <1>
   429 00016644 363636363637303F00- <1>     db  036h, 036h, 036h, 036h, 036h, 037h, 030h, 03fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   429 0001664D 00000000000000      <1>
   430 00016654 0000003F3037363636- <1>     db  000h, 000h, 000h, 03fh, 030h, 037h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   430 0001665D 36363636363636      <1>
   431 00016664 36F700FF0000000000- <1>     db  036h, 0f7h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh
   431 0001666D 000000000000FF      <1>
   432 00016674 00F736363636363636- <1>     db  000h, 0f7h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 037h, 030h, 037h
   432 0001667D 36363636373037      <1>
   433 00016684 363636363636000000- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0ffh, 000h, 000h
   433 0001668D 0000FF00FF0000      <1>
   434 00016694 000000003636363636- <1>     db  000h, 000h, 000h, 000h, 036h, 036h, 036h, 036h, 036h, 0f7h, 000h, 0f7h, 036h, 036h, 036h, 036h
   434 0001669D F700F736363636      <1>
   435 000166A4 36361818181818FF00- <1>     db  036h, 036h, 018h, 018h, 018h, 018h, 018h, 0ffh, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h
   435 000166AD FF000000000000      <1>
   436 000166B4 36363636363636FF00- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   436 000166BD 00000000000000      <1>
   437 000166C4 000000FF00FF181818- <1>     db  000h, 000h, 000h, 0ffh, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   437 000166CD 18181800000000      <1>
   438 000166D4 000000FF3636363636- <1>     db  000h, 000h, 000h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   438 000166DD 36363636363636      <1>
   439 000166E4 363F00000000000018- <1>     db  036h, 03fh, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 018h, 018h, 018h, 01fh, 018h, 01fh
   439 000166ED 181818181F181F      <1>
   440 000166F4 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 01fh, 018h, 01fh, 018h, 018h
   440 000166FD 00001F181F1818      <1>
   441 00016704 181818180000000000- <1>     db  018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 03fh, 036h, 036h, 036h, 036h
   441 0001670D 00003F36363636      <1>
   442 00016714 363636363636363636- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h
   442 0001671D FF363636363636      <1>
   443 00016724 1818181818FF18FF18- <1>     db  018h, 018h, 018h, 018h, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   443 0001672D 18181818181818      <1>
   444 00016734 1818181818F8000000- <1>     db  018h, 018h, 018h, 018h, 018h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   444 0001673D 00000000000000      <1>
   445 00016744 0000001F1818181818- <1>     db  000h, 000h, 000h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   445 0001674D 18FFFFFFFFFFFF      <1>
   446 00016754 FFFFFFFFFFFFFFFF00- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh
   446 0001675D 000000000000FF      <1>
   447 00016764 FFFFFFFFFFFFF0F0F0- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h
   447 0001676D F0F0F0F0F0F0F0      <1>
   448 00016774 F0F0F0F00F0F0F0F0F- <1>     db  0f0h, 0f0h, 0f0h, 0f0h, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh
   448 0001677D 0F0F0F0F0F0F0F      <1>
   449 00016784 0F0FFFFFFFFFFFFFFF- <1>     db  00fh, 00fh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   449 0001678D 00000000000000      <1>
   450 00016794 000000000076DCD8D8- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0dch, 0d8h, 0d8h, 0dch, 076h, 000h, 000h, 000h, 000h, 000h
   450 0001679D DC760000000000      <1>
   451 000167A4 00007CC6FCC6C6FCC0- <1>     db  000h, 000h, 07ch, 0c6h, 0fch, 0c6h, 0c6h, 0fch, 0c0h, 0c0h, 040h, 000h, 000h, 000h, 0feh, 0c6h
   451 000167AD C040000000FEC6      <1>
   452 000167B4 C6C0C0C0C0C0C00000- <1>     db  0c6h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 06ch
   452 000167BD 0000000000FE6C      <1>
   453 000167C4 6C6C6C6C6C00000000- <1>     db  06ch, 06ch, 06ch, 06ch, 06ch, 000h, 000h, 000h, 000h, 000h, 0feh, 0c6h, 060h, 030h, 018h, 030h
   453 000167CD 00FEC660301830      <1>
   454 000167D4 60C6FE000000000000- <1>     db  060h, 0c6h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07eh, 0d8h, 0d8h, 0d8h, 0d8h
   454 000167DD 00007ED8D8D8D8      <1>
   455 000167E4 700000000000000066- <1>     db  070h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 066h, 066h, 066h, 066h, 07ch, 060h, 060h, 0c0h
   455 000167ED 6666667C6060C0      <1>
   456 000167F4 00000000000076DC18- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 076h, 0dch, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h
   456 000167FD 18181818000000      <1>
   457 00016804 00007E183C6666663C- <1>     db  000h, 000h, 07eh, 018h, 03ch, 066h, 066h, 066h, 03ch, 018h, 07eh, 000h, 000h, 000h, 000h, 000h
   457 0001680D 187E0000000000      <1>
   458 00016814 386CC6C6FEC6C66C38- <1>     db  038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 06ch, 038h, 000h, 000h, 000h, 000h, 000h, 038h, 06ch
   458 0001681D 0000000000386C      <1>
   459 00016824 C6C6C66C6C6CEE0000- <1>     db  0c6h, 0c6h, 0c6h, 06ch, 06ch, 06ch, 0eeh, 000h, 000h, 000h, 000h, 000h, 01eh, 030h, 018h, 00ch
   459 0001682D 0000001E30180C      <1>
   460 00016834 3E6666663C00000000- <1>     db  03eh, 066h, 066h, 066h, 03ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07eh, 0dbh, 0dbh
   460 0001683D 000000007EDBDB      <1>
   461 00016844 7E0000000000000003- <1>     db  07eh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 003h, 006h, 07eh, 0dbh, 0dbh, 0f3h, 07eh, 060h
   461 0001684D 067EDBDBF37E60      <1>
   462 00016854 C000000000001C3060- <1>     db  0c0h, 000h, 000h, 000h, 000h, 000h, 01ch, 030h, 060h, 060h, 07ch, 060h, 060h, 030h, 01ch, 000h
   462 0001685D 607C6060301C00      <1>
   463 00016864 00000000007CC6C6C6- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h
   463 0001686D C6C6C6C6000000      <1>
   464 00016874 000000FE0000FE0000- <1>     db  000h, 000h, 000h, 0feh, 000h, 000h, 0feh, 000h, 000h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h
   464 0001687D FE000000000000      <1>
   465 00016884 0018187E18180000FF- <1>     db  000h, 018h, 018h, 07eh, 018h, 018h, 000h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 030h, 018h
   465 0001688D 00000000003018      <1>
   466 00016894 0C060C1830007E0000- <1>     db  00ch, 006h, 00ch, 018h, 030h, 000h, 07eh, 000h, 000h, 000h, 000h, 000h, 00ch, 018h, 030h, 060h
   466 0001689D 0000000C183060      <1>
   467 000168A4 30180C007E00000000- <1>     db  030h, 018h, 00ch, 000h, 07eh, 000h, 000h, 000h, 000h, 000h, 00eh, 01bh, 01bh, 018h, 018h, 018h
   467 000168AD 000E1B1B181818      <1>
   468 000168B4 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0d8h, 0d8h
   468 000168BD 1818181818D8D8      <1>
   469 000168C4 700000000000001818- <1>     db  070h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h, 07eh, 000h, 018h, 018h, 000h, 000h
   469 000168CD 007E0018180000      <1>
   470 000168D4 00000000000076DC00- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 076h, 0dch, 000h, 076h, 0dch, 000h, 000h, 000h, 000h, 000h
   470 000168DD 76DC0000000000      <1>
   471 000168E4 00386C6C3800000000- <1>     db  000h, 038h, 06ch, 06ch, 038h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   471 000168ED 00000000000000      <1>
   472 000168F4 000000001818000000- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   472 000168FD 00000000000000      <1>
   473 00016904 000000180000000000- <1>     db  000h, 000h, 000h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 00fh, 00ch, 00ch, 00ch, 00ch
   473 0001690D 00000F0C0C0C0C      <1>
   474 00016914 0CEC6C3C1C00000000- <1>     db  00ch, 0ech, 06ch, 03ch, 01ch, 000h, 000h, 000h, 000h, 0d8h, 06ch, 06ch, 06ch, 06ch, 06ch, 000h
   474 0001691D D86C6C6C6C6C00      <1>
   475 00016924 0000000000000070D8- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 070h, 0d8h, 030h, 060h, 0c8h, 0f8h, 000h, 000h, 000h
   475 0001692D 3060C8F8000000      <1>
   476 00016934 00000000000000007C- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 07ch, 07ch, 07ch, 07ch, 07ch, 07ch, 000h, 000h
   476 0001693D 7C7C7C7C7C0000      <1>
   477 00016944 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   477 0001694D 00000000000000      <1>
   478                              <1> vgafont16:
   479 00016954 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   479 0001695D 00000000000000      <1>
   480 00016964 00007E81A58181BD99- <1>     db  000h, 000h, 07eh, 081h, 0a5h, 081h, 081h, 0bdh, 099h, 081h, 081h, 07eh, 000h, 000h, 000h, 000h
   480 0001696D 81817E00000000      <1>
   481 00016974 00007EFFDBFFFFC3E7- <1>     db  000h, 000h, 07eh, 0ffh, 0dbh, 0ffh, 0ffh, 0c3h, 0e7h, 0ffh, 0ffh, 07eh, 000h, 000h, 000h, 000h
   481 0001697D FFFF7E00000000      <1>
   482 00016984 000000006CFEFEFEFE- <1>     db  000h, 000h, 000h, 000h, 06ch, 0feh, 0feh, 0feh, 0feh, 07ch, 038h, 010h, 000h, 000h, 000h, 000h
   482 0001698D 7C381000000000      <1>
   483 00016994 0000000010387CFE7C- <1>     db  000h, 000h, 000h, 000h, 010h, 038h, 07ch, 0feh, 07ch, 038h, 010h, 000h, 000h, 000h, 000h, 000h
   483 0001699D 38100000000000      <1>
   484 000169A4 000000183C3CE7E7E7- <1>     db  000h, 000h, 000h, 018h, 03ch, 03ch, 0e7h, 0e7h, 0e7h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   484 000169AD 18183C00000000      <1>
   485 000169B4 000000183C7EFFFF7E- <1>     db  000h, 000h, 000h, 018h, 03ch, 07eh, 0ffh, 0ffh, 07eh, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   485 000169BD 18183C00000000      <1>
   486 000169C4 000000000000183C3C- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 018h, 03ch, 03ch, 018h, 000h, 000h, 000h, 000h, 000h, 000h
   486 000169CD 18000000000000      <1>
   487 000169D4 FFFFFFFFFFFFE7C3C3- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0e7h, 0c3h, 0c3h, 0e7h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   487 000169DD E7FFFFFFFFFFFF      <1>
   488 000169E4 00000000003C664242- <1>     db  000h, 000h, 000h, 000h, 000h, 03ch, 066h, 042h, 042h, 066h, 03ch, 000h, 000h, 000h, 000h, 000h
   488 000169ED 663C0000000000      <1>
   489 000169F4 FFFFFFFFFFC399BDBD- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0c3h, 099h, 0bdh, 0bdh, 099h, 0c3h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   489 000169FD 99C3FFFFFFFFFF      <1>
   490 00016A04 00001E0E1A3278CCCC- <1>     db  000h, 000h, 01eh, 00eh, 01ah, 032h, 078h, 0cch, 0cch, 0cch, 0cch, 078h, 000h, 000h, 000h, 000h
   490 00016A0D CCCC7800000000      <1>
   491 00016A14 00003C666666663C18- <1>     db  000h, 000h, 03ch, 066h, 066h, 066h, 066h, 03ch, 018h, 07eh, 018h, 018h, 000h, 000h, 000h, 000h
   491 00016A1D 7E181800000000      <1>
   492 00016A24 00003F333F30303030- <1>     db  000h, 000h, 03fh, 033h, 03fh, 030h, 030h, 030h, 030h, 070h, 0f0h, 0e0h, 000h, 000h, 000h, 000h
   492 00016A2D 70F0E000000000      <1>
   493 00016A34 00007F637F63636363- <1>     db  000h, 000h, 07fh, 063h, 07fh, 063h, 063h, 063h, 063h, 067h, 0e7h, 0e6h, 0c0h, 000h, 000h, 000h
   493 00016A3D 67E7E6C0000000      <1>
   494 00016A44 0000001818DB3CE73C- <1>     db  000h, 000h, 000h, 018h, 018h, 0dbh, 03ch, 0e7h, 03ch, 0dbh, 018h, 018h, 000h, 000h, 000h, 000h
   494 00016A4D DB181800000000      <1>
   495 00016A54 0080C0E0F0F8FEF8F0- <1>     db  000h, 080h, 0c0h, 0e0h, 0f0h, 0f8h, 0feh, 0f8h, 0f0h, 0e0h, 0c0h, 080h, 000h, 000h, 000h, 000h
   495 00016A5D E0C08000000000      <1>
   496 00016A64 0002060E1E3EFE3E1E- <1>     db  000h, 002h, 006h, 00eh, 01eh, 03eh, 0feh, 03eh, 01eh, 00eh, 006h, 002h, 000h, 000h, 000h, 000h
   496 00016A6D 0E060200000000      <1>
   497 00016A74 0000183C7E1818187E- <1>     db  000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h, 000h, 000h, 000h, 000h
   497 00016A7D 3C180000000000      <1>
   498 00016A84 000066666666666666- <1>     db  000h, 000h, 066h, 066h, 066h, 066h, 066h, 066h, 066h, 000h, 066h, 066h, 000h, 000h, 000h, 000h
   498 00016A8D 00666600000000      <1>
   499 00016A94 00007FDBDBDB7B1B1B- <1>     db  000h, 000h, 07fh, 0dbh, 0dbh, 0dbh, 07bh, 01bh, 01bh, 01bh, 01bh, 01bh, 000h, 000h, 000h, 000h
   499 00016A9D 1B1B1B00000000      <1>
   500 00016AA4 007CC660386CC6C66C- <1>     db  000h, 07ch, 0c6h, 060h, 038h, 06ch, 0c6h, 0c6h, 06ch, 038h, 00ch, 0c6h, 07ch, 000h, 000h, 000h
   500 00016AAD 380CC67C000000      <1>
   501 00016AB4 0000000000000000FE- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 0feh, 0feh, 0feh, 000h, 000h, 000h, 000h
   501 00016ABD FEFEFE00000000      <1>
   502 00016AC4 0000183C7E1818187E- <1>     db  000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 07eh, 03ch, 018h, 07eh, 000h, 000h, 000h, 000h
   502 00016ACD 3C187E00000000      <1>
   503 00016AD4 0000183C7E18181818- <1>     db  000h, 000h, 018h, 03ch, 07eh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   503 00016ADD 18181800000000      <1>
   504 00016AE4 000018181818181818- <1>     db  000h, 000h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 07eh, 03ch, 018h, 000h, 000h, 000h, 000h
   504 00016AED 7E3C1800000000      <1>
   505 00016AF4 0000000000180CFE0C- <1>     db  000h, 000h, 000h, 000h, 000h, 018h, 00ch, 0feh, 00ch, 018h, 000h, 000h, 000h, 000h, 000h, 000h
   505 00016AFD 18000000000000      <1>
   506 00016B04 00000000003060FE60- <1>     db  000h, 000h, 000h, 000h, 000h, 030h, 060h, 0feh, 060h, 030h, 000h, 000h, 000h, 000h, 000h, 000h
   506 00016B0D 30000000000000      <1>
   507 00016B14 000000000000C0C0C0- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 0c0h, 0c0h, 0c0h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h
   507 00016B1D FE000000000000      <1>
   508 00016B24 00000000002466FF66- <1>     db  000h, 000h, 000h, 000h, 000h, 024h, 066h, 0ffh, 066h, 024h, 000h, 000h, 000h, 000h, 000h, 000h
   508 00016B2D 24000000000000      <1>
   509 00016B34 000000001038387C7C- <1>     db  000h, 000h, 000h, 000h, 010h, 038h, 038h, 07ch, 07ch, 0feh, 0feh, 000h, 000h, 000h, 000h, 000h
   509 00016B3D FEFE0000000000      <1>
   510 00016B44 00000000FEFE7C7C38- <1>     db  000h, 000h, 000h, 000h, 0feh, 0feh, 07ch, 07ch, 038h, 038h, 010h, 000h, 000h, 000h, 000h, 000h
   510 00016B4D 38100000000000      <1>
   511 00016B54 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   511 00016B5D 00000000000000      <1>
   512 00016B64 0000183C3C3C181818- <1>     db  000h, 000h, 018h, 03ch, 03ch, 03ch, 018h, 018h, 018h, 000h, 018h, 018h, 000h, 000h, 000h, 000h
   512 00016B6D 00181800000000      <1>
   513 00016B74 006666662400000000- <1>     db  000h, 066h, 066h, 066h, 024h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   513 00016B7D 00000000000000      <1>
   514 00016B84 0000006C6CFE6C6C6C- <1>     db  000h, 000h, 000h, 06ch, 06ch, 0feh, 06ch, 06ch, 06ch, 0feh, 06ch, 06ch, 000h, 000h, 000h, 000h
   514 00016B8D FE6C6C00000000      <1>
   515 00016B94 18187CC6C2C07C0606- <1>     db  018h, 018h, 07ch, 0c6h, 0c2h, 0c0h, 07ch, 006h, 006h, 086h, 0c6h, 07ch, 018h, 018h, 000h, 000h
   515 00016B9D 86C67C18180000      <1>
   516 00016BA4 00000000C2C60C1830- <1>     db  000h, 000h, 000h, 000h, 0c2h, 0c6h, 00ch, 018h, 030h, 060h, 0c6h, 086h, 000h, 000h, 000h, 000h
   516 00016BAD 60C68600000000      <1>
   517 00016BB4 0000386C6C3876DCCC- <1>     db  000h, 000h, 038h, 06ch, 06ch, 038h, 076h, 0dch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   517 00016BBD CCCC7600000000      <1>
   518 00016BC4 003030306000000000- <1>     db  000h, 030h, 030h, 030h, 060h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   518 00016BCD 00000000000000      <1>
   519 00016BD4 00000C183030303030- <1>     db  000h, 000h, 00ch, 018h, 030h, 030h, 030h, 030h, 030h, 030h, 018h, 00ch, 000h, 000h, 000h, 000h
   519 00016BDD 30180C00000000      <1>
   520 00016BE4 000030180C0C0C0C0C- <1>     db  000h, 000h, 030h, 018h, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 018h, 030h, 000h, 000h, 000h, 000h
   520 00016BED 0C183000000000      <1>
   521 00016BF4 0000000000663CFF3C- <1>     db  000h, 000h, 000h, 000h, 000h, 066h, 03ch, 0ffh, 03ch, 066h, 000h, 000h, 000h, 000h, 000h, 000h
   521 00016BFD 66000000000000      <1>
   522 00016C04 000000000018187E18- <1>     db  000h, 000h, 000h, 000h, 000h, 018h, 018h, 07eh, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h
   522 00016C0D 18000000000000      <1>
   523 00016C14 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 018h, 030h, 000h, 000h, 000h
   523 00016C1D 18181830000000      <1>
   524 00016C24 00000000000000FE00- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   524 00016C2D 00000000000000      <1>
   525 00016C34 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h
   525 00016C3D 00181800000000      <1>
   526 00016C44 0000000002060C1830- <1>     db  000h, 000h, 000h, 000h, 002h, 006h, 00ch, 018h, 030h, 060h, 0c0h, 080h, 000h, 000h, 000h, 000h
   526 00016C4D 60C08000000000      <1>
   527 00016C54 00003C66C3C3DBDBC3- <1>     db  000h, 000h, 03ch, 066h, 0c3h, 0c3h, 0dbh, 0dbh, 0c3h, 0c3h, 066h, 03ch, 000h, 000h, 000h, 000h
   527 00016C5D C3663C00000000      <1>
   528 00016C64 000018387818181818- <1>     db  000h, 000h, 018h, 038h, 078h, 018h, 018h, 018h, 018h, 018h, 018h, 07eh, 000h, 000h, 000h, 000h
   528 00016C6D 18187E00000000      <1>
   529 00016C74 00007CC6060C183060- <1>     db  000h, 000h, 07ch, 0c6h, 006h, 00ch, 018h, 030h, 060h, 0c0h, 0c6h, 0feh, 000h, 000h, 000h, 000h
   529 00016C7D C0C6FE00000000      <1>
   530 00016C84 00007CC606063C0606- <1>     db  000h, 000h, 07ch, 0c6h, 006h, 006h, 03ch, 006h, 006h, 006h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   530 00016C8D 06C67C00000000      <1>
   531 00016C94 00000C1C3C6CCCFE0C- <1>     db  000h, 000h, 00ch, 01ch, 03ch, 06ch, 0cch, 0feh, 00ch, 00ch, 00ch, 01eh, 000h, 000h, 000h, 000h
   531 00016C9D 0C0C1E00000000      <1>
   532 00016CA4 0000FEC0C0C0FC0606- <1>     db  000h, 000h, 0feh, 0c0h, 0c0h, 0c0h, 0fch, 006h, 006h, 006h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   532 00016CAD 06C67C00000000      <1>
   533 00016CB4 00003860C0C0FCC6C6- <1>     db  000h, 000h, 038h, 060h, 0c0h, 0c0h, 0fch, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   533 00016CBD C6C67C00000000      <1>
   534 00016CC4 0000FEC606060C1830- <1>     db  000h, 000h, 0feh, 0c6h, 006h, 006h, 00ch, 018h, 030h, 030h, 030h, 030h, 000h, 000h, 000h, 000h
   534 00016CCD 30303000000000      <1>
   535 00016CD4 00007CC6C6C67CC6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   535 00016CDD C6C67C00000000      <1>
   536 00016CE4 00007CC6C6C67E0606- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 07eh, 006h, 006h, 006h, 00ch, 078h, 000h, 000h, 000h, 000h
   536 00016CED 060C7800000000      <1>
   537 00016CF4 000000001818000000- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h
   537 00016CFD 18180000000000      <1>
   538 00016D04 000000001818000000- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 018h, 018h, 030h, 000h, 000h, 000h, 000h
   538 00016D0D 18183000000000      <1>
   539 00016D14 000000060C18306030- <1>     db  000h, 000h, 000h, 006h, 00ch, 018h, 030h, 060h, 030h, 018h, 00ch, 006h, 000h, 000h, 000h, 000h
   539 00016D1D 180C0600000000      <1>
   540 00016D24 00000000007E00007E- <1>     db  000h, 000h, 000h, 000h, 000h, 07eh, 000h, 000h, 07eh, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   540 00016D2D 00000000000000      <1>
   541 00016D34 0000006030180C060C- <1>     db  000h, 000h, 000h, 060h, 030h, 018h, 00ch, 006h, 00ch, 018h, 030h, 060h, 000h, 000h, 000h, 000h
   541 00016D3D 18306000000000      <1>
   542 00016D44 00007CC6C60C181818- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 00ch, 018h, 018h, 018h, 000h, 018h, 018h, 000h, 000h, 000h, 000h
   542 00016D4D 00181800000000      <1>
   543 00016D54 0000007CC6C6DEDEDE- <1>     db  000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0deh, 0deh, 0deh, 0dch, 0c0h, 07ch, 000h, 000h, 000h, 000h
   543 00016D5D DCC07C00000000      <1>
   544 00016D64 000010386CC6C6FEC6- <1>     db  000h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   544 00016D6D C6C6C600000000      <1>
   545 00016D74 0000FC6666667C6666- <1>     db  000h, 000h, 0fch, 066h, 066h, 066h, 07ch, 066h, 066h, 066h, 066h, 0fch, 000h, 000h, 000h, 000h
   545 00016D7D 6666FC00000000      <1>
   546 00016D84 00003C66C2C0C0C0C0- <1>     db  000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0c0h, 0c0h, 0c2h, 066h, 03ch, 000h, 000h, 000h, 000h
   546 00016D8D C2663C00000000      <1>
   547 00016D94 0000F86C6666666666- <1>     db  000h, 000h, 0f8h, 06ch, 066h, 066h, 066h, 066h, 066h, 066h, 06ch, 0f8h, 000h, 000h, 000h, 000h
   547 00016D9D 666CF800000000      <1>
   548 00016DA4 0000FE666268786860- <1>     db  000h, 000h, 0feh, 066h, 062h, 068h, 078h, 068h, 060h, 062h, 066h, 0feh, 000h, 000h, 000h, 000h
   548 00016DAD 6266FE00000000      <1>
   549 00016DB4 0000FE666268786860- <1>     db  000h, 000h, 0feh, 066h, 062h, 068h, 078h, 068h, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h
   549 00016DBD 6060F000000000      <1>
   550 00016DC4 00003C66C2C0C0DEC6- <1>     db  000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0deh, 0c6h, 0c6h, 066h, 03ah, 000h, 000h, 000h, 000h
   550 00016DCD C6663A00000000      <1>
   551 00016DD4 0000C6C6C6C6FEC6C6- <1>     db  000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   551 00016DDD C6C6C600000000      <1>
   552 00016DE4 00003C181818181818- <1>     db  000h, 000h, 03ch, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   552 00016DED 18183C00000000      <1>
   553 00016DF4 00001E0C0C0C0C0CCC- <1>     db  000h, 000h, 01eh, 00ch, 00ch, 00ch, 00ch, 00ch, 0cch, 0cch, 0cch, 078h, 000h, 000h, 000h, 000h
   553 00016DFD CCCC7800000000      <1>
   554 00016E04 0000E666666C78786C- <1>     db  000h, 000h, 0e6h, 066h, 066h, 06ch, 078h, 078h, 06ch, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h
   554 00016E0D 6666E600000000      <1>
   555 00016E14 0000F0606060606060- <1>     db  000h, 000h, 0f0h, 060h, 060h, 060h, 060h, 060h, 060h, 062h, 066h, 0feh, 000h, 000h, 000h, 000h
   555 00016E1D 6266FE00000000      <1>
   556 00016E24 0000C3E7FFFFDBC3C3- <1>     db  000h, 000h, 0c3h, 0e7h, 0ffh, 0ffh, 0dbh, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 000h, 000h, 000h, 000h
   556 00016E2D C3C3C300000000      <1>
   557 00016E34 0000C6E6F6FEDECEC6- <1>     db  000h, 000h, 0c6h, 0e6h, 0f6h, 0feh, 0deh, 0ceh, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   557 00016E3D C6C6C600000000      <1>
   558 00016E44 00007CC6C6C6C6C6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   558 00016E4D C6C67C00000000      <1>
   559 00016E54 0000FC6666667C6060- <1>     db  000h, 000h, 0fch, 066h, 066h, 066h, 07ch, 060h, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h
   559 00016E5D 6060F000000000      <1>
   560 00016E64 00007CC6C6C6C6C6C6- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0d6h, 0deh, 07ch, 00ch, 00eh, 000h, 000h
   560 00016E6D D6DE7C0C0E0000      <1>
   561 00016E74 0000FC6666667C6C66- <1>     db  000h, 000h, 0fch, 066h, 066h, 066h, 07ch, 06ch, 066h, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h
   561 00016E7D 6666E600000000      <1>
   562 00016E84 00007CC6C660380C06- <1>     db  000h, 000h, 07ch, 0c6h, 0c6h, 060h, 038h, 00ch, 006h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   562 00016E8D C6C67C00000000      <1>
   563 00016E94 0000FFDB9918181818- <1>     db  000h, 000h, 0ffh, 0dbh, 099h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   563 00016E9D 18183C00000000      <1>
   564 00016EA4 0000C6C6C6C6C6C6C6- <1>     db  000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   564 00016EAD C6C67C00000000      <1>
   565 00016EB4 0000C3C3C3C3C3C3C3- <1>     db  000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 000h, 000h, 000h, 000h
   565 00016EBD 663C1800000000      <1>
   566 00016EC4 0000C3C3C3C3C3DBDB- <1>     db  000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh, 066h, 066h, 000h, 000h, 000h, 000h
   566 00016ECD FF666600000000      <1>
   567 00016ED4 0000C3C3663C18183C- <1>     db  000h, 000h, 0c3h, 0c3h, 066h, 03ch, 018h, 018h, 03ch, 066h, 0c3h, 0c3h, 000h, 000h, 000h, 000h
   567 00016EDD 66C3C300000000      <1>
   568 00016EE4 0000C3C3C3663C1818- <1>     db  000h, 000h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   568 00016EED 18183C00000000      <1>
   569 00016EF4 0000FFC3860C183060- <1>     db  000h, 000h, 0ffh, 0c3h, 086h, 00ch, 018h, 030h, 060h, 0c1h, 0c3h, 0ffh, 000h, 000h, 000h, 000h
   569 00016EFD C1C3FF00000000      <1>
   570 00016F04 00003C303030303030- <1>     db  000h, 000h, 03ch, 030h, 030h, 030h, 030h, 030h, 030h, 030h, 030h, 03ch, 000h, 000h, 000h, 000h
   570 00016F0D 30303C00000000      <1>
   571 00016F14 00000080C0E070381C- <1>     db  000h, 000h, 000h, 080h, 0c0h, 0e0h, 070h, 038h, 01ch, 00eh, 006h, 002h, 000h, 000h, 000h, 000h
   571 00016F1D 0E060200000000      <1>
   572 00016F24 00003C0C0C0C0C0C0C- <1>     db  000h, 000h, 03ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 00ch, 03ch, 000h, 000h, 000h, 000h
   572 00016F2D 0C0C3C00000000      <1>
   573 00016F34 10386CC60000000000- <1>     db  010h, 038h, 06ch, 0c6h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   573 00016F3D 00000000000000      <1>
   574 00016F44 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 000h
   574 00016F4D 00000000FF0000      <1>
   575 00016F54 303018000000000000- <1>     db  030h, 030h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   575 00016F5D 00000000000000      <1>
   576 00016F64 0000000000780C7CCC- <1>     db  000h, 000h, 000h, 000h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   576 00016F6D CCCC7600000000      <1>
   577 00016F74 0000E06060786C6666- <1>     db  000h, 000h, 0e0h, 060h, 060h, 078h, 06ch, 066h, 066h, 066h, 066h, 07ch, 000h, 000h, 000h, 000h
   577 00016F7D 66667C00000000      <1>
   578 00016F84 00000000007CC6C0C0- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c0h, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   578 00016F8D C0C67C00000000      <1>
   579 00016F94 00001C0C0C3C6CCCCC- <1>     db  000h, 000h, 01ch, 00ch, 00ch, 03ch, 06ch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   579 00016F9D CCCC7600000000      <1>
   580 00016FA4 00000000007CC6FEC0- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   580 00016FAD C0C67C00000000      <1>
   581 00016FB4 0000386C6460F06060- <1>     db  000h, 000h, 038h, 06ch, 064h, 060h, 0f0h, 060h, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h
   581 00016FBD 6060F000000000      <1>
   582 00016FC4 000000000076CCCCCC- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0cch, 0cch, 0cch, 0cch, 0cch, 07ch, 00ch, 0cch, 078h, 000h
   582 00016FCD CCCC7C0CCC7800      <1>
   583 00016FD4 0000E060606C766666- <1>     db  000h, 000h, 0e0h, 060h, 060h, 06ch, 076h, 066h, 066h, 066h, 066h, 0e6h, 000h, 000h, 000h, 000h
   583 00016FDD 6666E600000000      <1>
   584 00016FE4 000018180038181818- <1>     db  000h, 000h, 018h, 018h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   584 00016FED 18183C00000000      <1>
   585 00016FF4 00000606000E060606- <1>     db  000h, 000h, 006h, 006h, 000h, 00eh, 006h, 006h, 006h, 006h, 006h, 006h, 066h, 066h, 03ch, 000h
   585 00016FFD 06060666663C00      <1>
   586 00017004 0000E06060666C7878- <1>     db  000h, 000h, 0e0h, 060h, 060h, 066h, 06ch, 078h, 078h, 06ch, 066h, 0e6h, 000h, 000h, 000h, 000h
   586 0001700D 6C66E600000000      <1>
   587 00017014 000038181818181818- <1>     db  000h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   587 0001701D 18183C00000000      <1>
   588 00017024 0000000000E6FFDBDB- <1>     db  000h, 000h, 000h, 000h, 000h, 0e6h, 0ffh, 0dbh, 0dbh, 0dbh, 0dbh, 0dbh, 000h, 000h, 000h, 000h
   588 0001702D DBDBDB00000000      <1>
   589 00017034 0000000000DC666666- <1>     db  000h, 000h, 000h, 000h, 000h, 0dch, 066h, 066h, 066h, 066h, 066h, 066h, 000h, 000h, 000h, 000h
   589 0001703D 66666600000000      <1>
   590 00017044 00000000007CC6C6C6- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   590 0001704D C6C67C00000000      <1>
   591 00017054 0000000000DC666666- <1>     db  000h, 000h, 000h, 000h, 000h, 0dch, 066h, 066h, 066h, 066h, 066h, 07ch, 060h, 060h, 0f0h, 000h
   591 0001705D 66667C6060F000      <1>
   592 00017064 000000000076CCCCCC- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0cch, 0cch, 0cch, 0cch, 0cch, 07ch, 00ch, 00ch, 01eh, 000h
   592 0001706D CCCC7C0C0C1E00      <1>
   593 00017074 0000000000DC766660- <1>     db  000h, 000h, 000h, 000h, 000h, 0dch, 076h, 066h, 060h, 060h, 060h, 0f0h, 000h, 000h, 000h, 000h
   593 0001707D 6060F000000000      <1>
   594 00017084 00000000007CC66038- <1>     db  000h, 000h, 000h, 000h, 000h, 07ch, 0c6h, 060h, 038h, 00ch, 0c6h, 07ch, 000h, 000h, 000h, 000h
   594 0001708D 0CC67C00000000      <1>
   595 00017094 0000103030FC303030- <1>     db  000h, 000h, 010h, 030h, 030h, 0fch, 030h, 030h, 030h, 030h, 036h, 01ch, 000h, 000h, 000h, 000h
   595 0001709D 30361C00000000      <1>
   596 000170A4 0000000000CCCCCCCC- <1>     db  000h, 000h, 000h, 000h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   596 000170AD CCCC7600000000      <1>
   597 000170B4 0000000000C3C3C3C3- <1>     db  000h, 000h, 000h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 000h, 000h, 000h, 000h
   597 000170BD 663C1800000000      <1>
   598 000170C4 0000000000C3C3C3DB- <1>     db  000h, 000h, 000h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh, 066h, 000h, 000h, 000h, 000h
   598 000170CD DBFF6600000000      <1>
   599 000170D4 0000000000C3663C18- <1>     db  000h, 000h, 000h, 000h, 000h, 0c3h, 066h, 03ch, 018h, 03ch, 066h, 0c3h, 000h, 000h, 000h, 000h
   599 000170DD 3C66C300000000      <1>
   600 000170E4 0000000000C6C6C6C6- <1>     db  000h, 000h, 000h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07eh, 006h, 00ch, 0f8h, 000h
   600 000170ED C6C67E060CF800      <1>
   601 000170F4 0000000000FECC1830- <1>     db  000h, 000h, 000h, 000h, 000h, 0feh, 0cch, 018h, 030h, 060h, 0c6h, 0feh, 000h, 000h, 000h, 000h
   601 000170FD 60C6FE00000000      <1>
   602 00017104 00000E181818701818- <1>     db  000h, 000h, 00eh, 018h, 018h, 018h, 070h, 018h, 018h, 018h, 018h, 00eh, 000h, 000h, 000h, 000h
   602 0001710D 18180E00000000      <1>
   603 00017114 000018181818001818- <1>     db  000h, 000h, 018h, 018h, 018h, 018h, 000h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   603 0001711D 18181800000000      <1>
   604 00017124 0000701818180E1818- <1>     db  000h, 000h, 070h, 018h, 018h, 018h, 00eh, 018h, 018h, 018h, 018h, 070h, 000h, 000h, 000h, 000h
   604 0001712D 18187000000000      <1>
   605 00017134 000076DC0000000000- <1>     db  000h, 000h, 076h, 0dch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   605 0001713D 00000000000000      <1>
   606 00017144 0000000010386CC6C6- <1>     db  000h, 000h, 000h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 0feh, 000h, 000h, 000h, 000h, 000h
   606 0001714D C6FE0000000000      <1>
   607 00017154 00003C66C2C0C0C0C2- <1>     db  000h, 000h, 03ch, 066h, 0c2h, 0c0h, 0c0h, 0c0h, 0c2h, 066h, 03ch, 00ch, 006h, 07ch, 000h, 000h
   607 0001715D 663C0C067C0000      <1>
   608 00017164 0000CC0000CCCCCCCC- <1>     db  000h, 000h, 0cch, 000h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   608 0001716D CCCC7600000000      <1>
   609 00017174 000C1830007CC6FEC0- <1>     db  000h, 00ch, 018h, 030h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   609 0001717D C0C67C00000000      <1>
   610 00017184 0010386C00780C7CCC- <1>     db  000h, 010h, 038h, 06ch, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   610 0001718D CCCC7600000000      <1>
   611 00017194 0000CC0000780C7CCC- <1>     db  000h, 000h, 0cch, 000h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   611 0001719D CCCC7600000000      <1>
   612 000171A4 0060301800780C7CCC- <1>     db  000h, 060h, 030h, 018h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   612 000171AD CCCC7600000000      <1>
   613 000171B4 00386C3800780C7CCC- <1>     db  000h, 038h, 06ch, 038h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   613 000171BD CCCC7600000000      <1>
   614 000171C4 000000003C66606066- <1>     db  000h, 000h, 000h, 000h, 03ch, 066h, 060h, 060h, 066h, 03ch, 00ch, 006h, 03ch, 000h, 000h, 000h
   614 000171CD 3C0C063C000000      <1>
   615 000171D4 0010386C007CC6FEC0- <1>     db  000h, 010h, 038h, 06ch, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   615 000171DD C0C67C00000000      <1>
   616 000171E4 0000C600007CC6FEC0- <1>     db  000h, 000h, 0c6h, 000h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   616 000171ED C0C67C00000000      <1>
   617 000171F4 00603018007CC6FEC0- <1>     db  000h, 060h, 030h, 018h, 000h, 07ch, 0c6h, 0feh, 0c0h, 0c0h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   617 000171FD C0C67C00000000      <1>
   618 00017204 000066000038181818- <1>     db  000h, 000h, 066h, 000h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   618 0001720D 18183C00000000      <1>
   619 00017214 00183C660038181818- <1>     db  000h, 018h, 03ch, 066h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   619 0001721D 18183C00000000      <1>
   620 00017224 006030180038181818- <1>     db  000h, 060h, 030h, 018h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   620 0001722D 18183C00000000      <1>
   621 00017234 00C60010386CC6C6FE- <1>     db  000h, 0c6h, 000h, 010h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   621 0001723D C6C6C600000000      <1>
   622 00017244 386C3800386CC6C6FE- <1>     db  038h, 06ch, 038h, 000h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   622 0001724D C6C6C600000000      <1>
   623 00017254 18306000FE66607C60- <1>     db  018h, 030h, 060h, 000h, 0feh, 066h, 060h, 07ch, 060h, 060h, 066h, 0feh, 000h, 000h, 000h, 000h
   623 0001725D 6066FE00000000      <1>
   624 00017264 00000000006E3B1B7E- <1>     db  000h, 000h, 000h, 000h, 000h, 06eh, 03bh, 01bh, 07eh, 0d8h, 0dch, 077h, 000h, 000h, 000h, 000h
   624 0001726D D8DC7700000000      <1>
   625 00017274 00003E6CCCCCFECCCC- <1>     db  000h, 000h, 03eh, 06ch, 0cch, 0cch, 0feh, 0cch, 0cch, 0cch, 0cch, 0ceh, 000h, 000h, 000h, 000h
   625 0001727D CCCCCE00000000      <1>
   626 00017284 0010386C007CC6C6C6- <1>     db  000h, 010h, 038h, 06ch, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   626 0001728D C6C67C00000000      <1>
   627 00017294 0000C600007CC6C6C6- <1>     db  000h, 000h, 0c6h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   627 0001729D C6C67C00000000      <1>
   628 000172A4 00603018007CC6C6C6- <1>     db  000h, 060h, 030h, 018h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   628 000172AD C6C67C00000000      <1>
   629 000172B4 003078CC00CCCCCCCC- <1>     db  000h, 030h, 078h, 0cch, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   629 000172BD CCCC7600000000      <1>
   630 000172C4 0060301800CCCCCCCC- <1>     db  000h, 060h, 030h, 018h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   630 000172CD CCCC7600000000      <1>
   631 000172D4 0000C60000C6C6C6C6- <1>     db  000h, 000h, 0c6h, 000h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07eh, 006h, 00ch, 078h, 000h
   631 000172DD C6C67E060C7800      <1>
   632 000172E4 00C6007CC6C6C6C6C6- <1>     db  000h, 0c6h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   632 000172ED C6C67C00000000      <1>
   633 000172F4 00C600C6C6C6C6C6C6- <1>     db  000h, 0c6h, 000h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   633 000172FD C6C67C00000000      <1>
   634 00017304 0018187EC3C0C0C0C3- <1>     db  000h, 018h, 018h, 07eh, 0c3h, 0c0h, 0c0h, 0c0h, 0c3h, 07eh, 018h, 018h, 000h, 000h, 000h, 000h
   634 0001730D 7E181800000000      <1>
   635 00017314 00386C6460F0606060- <1>     db  000h, 038h, 06ch, 064h, 060h, 0f0h, 060h, 060h, 060h, 060h, 0e6h, 0fch, 000h, 000h, 000h, 000h
   635 0001731D 60E6FC00000000      <1>
   636 00017324 0000C3663C18FF18FF- <1>     db  000h, 000h, 0c3h, 066h, 03ch, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   636 0001732D 18181800000000      <1>
   637 00017334 00FC66667C62666F66- <1>     db  000h, 0fch, 066h, 066h, 07ch, 062h, 066h, 06fh, 066h, 066h, 066h, 0f3h, 000h, 000h, 000h, 000h
   637 0001733D 6666F300000000      <1>
   638 00017344 000E1B1818187E1818- <1>     db  000h, 00eh, 01bh, 018h, 018h, 018h, 07eh, 018h, 018h, 018h, 018h, 018h, 0d8h, 070h, 000h, 000h
   638 0001734D 181818D8700000      <1>
   639 00017354 0018306000780C7CCC- <1>     db  000h, 018h, 030h, 060h, 000h, 078h, 00ch, 07ch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   639 0001735D CCCC7600000000      <1>
   640 00017364 000C18300038181818- <1>     db  000h, 00ch, 018h, 030h, 000h, 038h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h
   640 0001736D 18183C00000000      <1>
   641 00017374 00183060007CC6C6C6- <1>     db  000h, 018h, 030h, 060h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   641 0001737D C6C67C00000000      <1>
   642 00017384 0018306000CCCCCCCC- <1>     db  000h, 018h, 030h, 060h, 000h, 0cch, 0cch, 0cch, 0cch, 0cch, 0cch, 076h, 000h, 000h, 000h, 000h
   642 0001738D CCCC7600000000      <1>
   643 00017394 000076DC00DC666666- <1>     db  000h, 000h, 076h, 0dch, 000h, 0dch, 066h, 066h, 066h, 066h, 066h, 066h, 000h, 000h, 000h, 000h
   643 0001739D 66666600000000      <1>
   644 000173A4 76DC00C6E6F6FEDECE- <1>     db  076h, 0dch, 000h, 0c6h, 0e6h, 0f6h, 0feh, 0deh, 0ceh, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   644 000173AD C6C6C600000000      <1>
   645 000173B4 003C6C6C3E007E0000- <1>     db  000h, 03ch, 06ch, 06ch, 03eh, 000h, 07eh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   645 000173BD 00000000000000      <1>
   646 000173C4 00386C6C38007C0000- <1>     db  000h, 038h, 06ch, 06ch, 038h, 000h, 07ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   646 000173CD 00000000000000      <1>
   647 000173D4 0000303000303060C0- <1>     db  000h, 000h, 030h, 030h, 000h, 030h, 030h, 060h, 0c0h, 0c6h, 0c6h, 07ch, 000h, 000h, 000h, 000h
   647 000173DD C6C67C00000000      <1>
   648 000173E4 000000000000FEC0C0- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 0feh, 0c0h, 0c0h, 0c0h, 0c0h, 000h, 000h, 000h, 000h, 000h
   648 000173ED C0C00000000000      <1>
   649 000173F4 000000000000FE0606- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 0feh, 006h, 006h, 006h, 006h, 000h, 000h, 000h, 000h, 000h
   649 000173FD 06060000000000      <1>
   650 00017404 00C0C0C2C6CC183060- <1>     db  000h, 0c0h, 0c0h, 0c2h, 0c6h, 0cch, 018h, 030h, 060h, 0ceh, 09bh, 006h, 00ch, 01fh, 000h, 000h
   650 0001740D CE9B060C1F0000      <1>
   651 00017414 00C0C0C2C6CC183066- <1>     db  000h, 0c0h, 0c0h, 0c2h, 0c6h, 0cch, 018h, 030h, 066h, 0ceh, 096h, 03eh, 006h, 006h, 000h, 000h
   651 0001741D CE963E06060000      <1>
   652 00017424 00001818001818183C- <1>     db  000h, 000h, 018h, 018h, 000h, 018h, 018h, 018h, 03ch, 03ch, 03ch, 018h, 000h, 000h, 000h, 000h
   652 0001742D 3C3C1800000000      <1>
   653 00017434 0000000000366CD86C- <1>     db  000h, 000h, 000h, 000h, 000h, 036h, 06ch, 0d8h, 06ch, 036h, 000h, 000h, 000h, 000h, 000h, 000h
   653 0001743D 36000000000000      <1>
   654 00017444 0000000000D86C366C- <1>     db  000h, 000h, 000h, 000h, 000h, 0d8h, 06ch, 036h, 06ch, 0d8h, 000h, 000h, 000h, 000h, 000h, 000h
   654 0001744D D8000000000000      <1>
   655 00017454 114411441144114411- <1>     db  011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h, 011h, 044h
   655 0001745D 44114411441144      <1>
   656 00017464 55AA55AA55AA55AA55- <1>     db  055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah, 055h, 0aah
   656 0001746D AA55AA55AA55AA      <1>
   657 00017474 DD77DD77DD77DD77DD- <1>     db  0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h, 0ddh, 077h
   657 0001747D 77DD77DD77DD77      <1>
   658 00017484 181818181818181818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   658 0001748D 18181818181818      <1>
   659 00017494 18181818181818F818- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   659 0001749D 18181818181818      <1>
   660 000174A4 1818181818F818F818- <1>     db  018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   660 000174AD 18181818181818      <1>
   661 000174B4 36363636363636F636- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   661 000174BD 36363636363636      <1>
   662 000174C4 00000000000000FE36- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0feh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   662 000174CD 36363636363636      <1>
   663 000174D4 0000000000F818F818- <1>     db  000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   663 000174DD 18181818181818      <1>
   664 000174E4 3636363636F606F636- <1>     db  036h, 036h, 036h, 036h, 036h, 0f6h, 006h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   664 000174ED 36363636363636      <1>
   665 000174F4 363636363636363636- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   665 000174FD 36363636363636      <1>
   666 00017504 0000000000FE06F636- <1>     db  000h, 000h, 000h, 000h, 000h, 0feh, 006h, 0f6h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   666 0001750D 36363636363636      <1>
   667 00017514 3636363636F606FE00- <1>     db  036h, 036h, 036h, 036h, 036h, 0f6h, 006h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   667 0001751D 00000000000000      <1>
   668 00017524 36363636363636FE00- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0feh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   668 0001752D 00000000000000      <1>
   669 00017534 1818181818F818F800- <1>     db  018h, 018h, 018h, 018h, 018h, 0f8h, 018h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   669 0001753D 00000000000000      <1>
   670 00017544 00000000000000F818- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0f8h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   670 0001754D 18181818181818      <1>
   671 00017554 181818181818181F00- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   671 0001755D 00000000000000      <1>
   672 00017564 18181818181818FF00- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   672 0001756D 00000000000000      <1>
   673 00017574 00000000000000FF18- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   673 0001757D 18181818181818      <1>
   674 00017584 181818181818181F18- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   674 0001758D 18181818181818      <1>
   675 00017594 00000000000000FF00- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   675 0001759D 00000000000000      <1>
   676 000175A4 18181818181818FF18- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   676 000175AD 18181818181818      <1>
   677 000175B4 18181818181F181F18- <1>     db  018h, 018h, 018h, 018h, 018h, 01fh, 018h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   677 000175BD 18181818181818      <1>
   678 000175C4 363636363636363736- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 037h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   678 000175CD 36363636363636      <1>
   679 000175D4 363636363637303F00- <1>     db  036h, 036h, 036h, 036h, 036h, 037h, 030h, 03fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   679 000175DD 00000000000000      <1>
   680 000175E4 00000000003F303736- <1>     db  000h, 000h, 000h, 000h, 000h, 03fh, 030h, 037h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   680 000175ED 36363636363636      <1>
   681 000175F4 3636363636F700FF00- <1>     db  036h, 036h, 036h, 036h, 036h, 0f7h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   681 000175FD 00000000000000      <1>
   682 00017604 0000000000FF00F736- <1>     db  000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0f7h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   682 0001760D 36363636363636      <1>
   683 00017614 363636363637303736- <1>     db  036h, 036h, 036h, 036h, 036h, 037h, 030h, 037h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   683 0001761D 36363636363636      <1>
   684 00017624 0000000000FF00FF00- <1>     db  000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   684 0001762D 00000000000000      <1>
   685 00017634 3636363636F700F736- <1>     db  036h, 036h, 036h, 036h, 036h, 0f7h, 000h, 0f7h, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   685 0001763D 36363636363636      <1>
   686 00017644 1818181818FF00FF00- <1>     db  018h, 018h, 018h, 018h, 018h, 0ffh, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   686 0001764D 00000000000000      <1>
   687 00017654 36363636363636FF00- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   687 0001765D 00000000000000      <1>
   688 00017664 0000000000FF00FF18- <1>     db  000h, 000h, 000h, 000h, 000h, 0ffh, 000h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   688 0001766D 18181818181818      <1>
   689 00017674 00000000000000FF36- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   689 0001767D 36363636363636      <1>
   690 00017684 363636363636363F00- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 03fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   690 0001768D 00000000000000      <1>
   691 00017694 18181818181F181F00- <1>     db  018h, 018h, 018h, 018h, 018h, 01fh, 018h, 01fh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   691 0001769D 00000000000000      <1>
   692 000176A4 00000000001F181F18- <1>     db  000h, 000h, 000h, 000h, 000h, 01fh, 018h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   692 000176AD 18181818181818      <1>
   693 000176B4 000000000000003F36- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 03fh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   693 000176BD 36363636363636      <1>
   694 000176C4 36363636363636FF36- <1>     db  036h, 036h, 036h, 036h, 036h, 036h, 036h, 0ffh, 036h, 036h, 036h, 036h, 036h, 036h, 036h, 036h
   694 000176CD 36363636363636      <1>
   695 000176D4 1818181818FF18FF18- <1>     db  018h, 018h, 018h, 018h, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   695 000176DD 18181818181818      <1>
   696 000176E4 18181818181818F800- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   696 000176ED 00000000000000      <1>
   697 000176F4 000000000000001F18- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 01fh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   697 000176FD 18181818181818      <1>
   698 00017704 FFFFFFFFFFFFFFFFFF- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   698 0001770D FFFFFFFFFFFFFF      <1>
   699 00017714 00000000000000FFFF- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh
   699 0001771D FFFFFFFFFFFFFF      <1>
   700 00017724 F0F0F0F0F0F0F0F0F0- <1>     db  0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h, 0f0h
   700 0001772D F0F0F0F0F0F0F0      <1>
   701 00017734 0F0F0F0F0F0F0F0F0F- <1>     db  00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh, 00fh
   701 0001773D 0F0F0F0F0F0F0F      <1>
   702 00017744 FFFFFFFFFFFFFF0000- <1>     db  0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   702 0001774D 00000000000000      <1>
   703 00017754 000000000076DCD8D8- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0dch, 0d8h, 0d8h, 0d8h, 0dch, 076h, 000h, 000h, 000h, 000h
   703 0001775D D8DC7600000000      <1>
   704 00017764 000078CCCCCCD8CCC6- <1>     db  000h, 000h, 078h, 0cch, 0cch, 0cch, 0d8h, 0cch, 0c6h, 0c6h, 0c6h, 0cch, 000h, 000h, 000h, 000h
   704 0001776D C6C6CC00000000      <1>
   705 00017774 0000FEC6C6C0C0C0C0- <1>     db  000h, 000h, 0feh, 0c6h, 0c6h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 0c0h, 000h, 000h, 000h, 000h
   705 0001777D C0C0C000000000      <1>
   706 00017784 00000000FE6C6C6C6C- <1>     db  000h, 000h, 000h, 000h, 0feh, 06ch, 06ch, 06ch, 06ch, 06ch, 06ch, 06ch, 000h, 000h, 000h, 000h
   706 0001778D 6C6C6C00000000      <1>
   707 00017794 000000FEC660301830- <1>     db  000h, 000h, 000h, 0feh, 0c6h, 060h, 030h, 018h, 030h, 060h, 0c6h, 0feh, 000h, 000h, 000h, 000h
   707 0001779D 60C6FE00000000      <1>
   708 000177A4 00000000007ED8D8D8- <1>     db  000h, 000h, 000h, 000h, 000h, 07eh, 0d8h, 0d8h, 0d8h, 0d8h, 0d8h, 070h, 000h, 000h, 000h, 000h
   708 000177AD D8D87000000000      <1>
   709 000177B4 000000006666666666- <1>     db  000h, 000h, 000h, 000h, 066h, 066h, 066h, 066h, 066h, 07ch, 060h, 060h, 0c0h, 000h, 000h, 000h
   709 000177BD 7C6060C0000000      <1>
   710 000177C4 0000000076DC181818- <1>     db  000h, 000h, 000h, 000h, 076h, 0dch, 018h, 018h, 018h, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   710 000177CD 18181800000000      <1>
   711 000177D4 0000007E183C666666- <1>     db  000h, 000h, 000h, 07eh, 018h, 03ch, 066h, 066h, 066h, 03ch, 018h, 07eh, 000h, 000h, 000h, 000h
   711 000177DD 3C187E00000000      <1>
   712 000177E4 000000386CC6C6FEC6- <1>     db  000h, 000h, 000h, 038h, 06ch, 0c6h, 0c6h, 0feh, 0c6h, 0c6h, 06ch, 038h, 000h, 000h, 000h, 000h
   712 000177ED C66C3800000000      <1>
   713 000177F4 0000386CC6C6C66C6C- <1>     db  000h, 000h, 038h, 06ch, 0c6h, 0c6h, 0c6h, 06ch, 06ch, 06ch, 06ch, 0eeh, 000h, 000h, 000h, 000h
   713 000177FD 6C6CEE00000000      <1>
   714 00017804 00001E30180C3E6666- <1>     db  000h, 000h, 01eh, 030h, 018h, 00ch, 03eh, 066h, 066h, 066h, 066h, 03ch, 000h, 000h, 000h, 000h
   714 0001780D 66663C00000000      <1>
   715 00017814 00000000007EDBDBDB- <1>     db  000h, 000h, 000h, 000h, 000h, 07eh, 0dbh, 0dbh, 0dbh, 07eh, 000h, 000h, 000h, 000h, 000h, 000h
   715 0001781D 7E000000000000      <1>
   716 00017824 00000003067EDBDBF3- <1>     db  000h, 000h, 000h, 003h, 006h, 07eh, 0dbh, 0dbh, 0f3h, 07eh, 060h, 0c0h, 000h, 000h, 000h, 000h
   716 0001782D 7E60C000000000      <1>
   717 00017834 00001C3060607C6060- <1>     db  000h, 000h, 01ch, 030h, 060h, 060h, 07ch, 060h, 060h, 060h, 030h, 01ch, 000h, 000h, 000h, 000h
   717 0001783D 60301C00000000      <1>
   718 00017844 0000007CC6C6C6C6C6- <1>     db  000h, 000h, 000h, 07ch, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 0c6h, 000h, 000h, 000h, 000h
   718 0001784D C6C6C600000000      <1>
   719 00017854 00000000FE0000FE00- <1>     db  000h, 000h, 000h, 000h, 0feh, 000h, 000h, 0feh, 000h, 000h, 0feh, 000h, 000h, 000h, 000h, 000h
   719 0001785D 00FE0000000000      <1>
   720 00017864 0000000018187E1818- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 07eh, 018h, 018h, 000h, 000h, 0ffh, 000h, 000h, 000h, 000h
   720 0001786D 0000FF00000000      <1>
   721 00017874 00000030180C060C18- <1>     db  000h, 000h, 000h, 030h, 018h, 00ch, 006h, 00ch, 018h, 030h, 000h, 07eh, 000h, 000h, 000h, 000h
   721 0001787D 30007E00000000      <1>
   722 00017884 0000000C1830603018- <1>     db  000h, 000h, 000h, 00ch, 018h, 030h, 060h, 030h, 018h, 00ch, 000h, 07eh, 000h, 000h, 000h, 000h
   722 0001788D 0C007E00000000      <1>
   723 00017894 00000E1B1B18181818- <1>     db  000h, 000h, 00eh, 01bh, 01bh, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h
   723 0001789D 18181818181818      <1>
   724 000178A4 1818181818181818D8- <1>     db  018h, 018h, 018h, 018h, 018h, 018h, 018h, 018h, 0d8h, 0d8h, 0d8h, 070h, 000h, 000h, 000h, 000h
   724 000178AD D8D87000000000      <1>
   725 000178B4 000000001818007E00- <1>     db  000h, 000h, 000h, 000h, 018h, 018h, 000h, 07eh, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h
   725 000178BD 18180000000000      <1>
   726 000178C4 000000000076DC0076- <1>     db  000h, 000h, 000h, 000h, 000h, 076h, 0dch, 000h, 076h, 0dch, 000h, 000h, 000h, 000h, 000h, 000h
   726 000178CD DC000000000000      <1>
   727 000178D4 00386C6C3800000000- <1>     db  000h, 038h, 06ch, 06ch, 038h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   727 000178DD 00000000000000      <1>
   728 000178E4 000000000000001818- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   728 000178ED 00000000000000      <1>
   729 000178F4 000000000000000018- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 018h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   729 000178FD 00000000000000      <1>
   730 00017904 000F0C0C0C0C0CEC6C- <1>     db  000h, 00fh, 00ch, 00ch, 00ch, 00ch, 00ch, 0ech, 06ch, 06ch, 03ch, 01ch, 000h, 000h, 000h, 000h
   730 0001790D 6C3C1C00000000      <1>
   731 00017914 00D86C6C6C6C6C0000- <1>     db  000h, 0d8h, 06ch, 06ch, 06ch, 06ch, 06ch, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   731 0001791D 00000000000000      <1>
   732 00017924 0070D83060C8F80000- <1>     db  000h, 070h, 0d8h, 030h, 060h, 0c8h, 0f8h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   732 0001792D 00000000000000      <1>
   733 00017934 000000007C7C7C7C7C- <1>     db  000h, 000h, 000h, 000h, 07ch, 07ch, 07ch, 07ch, 07ch, 07ch, 07ch, 000h, 000h, 000h, 000h, 000h
   733 0001793D 7C7C0000000000      <1>
   734 00017944 000000000000000000- <1>     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
   734 0001794D 00000000000000      <1>
   735                              <1> 
   736                              <1> ; 01/01/2021 (TRDOS 386 v2.0.3)
   737                              <1> 
   738                              <1> %if 0
   739                              <1> 
   740                              <1> vgafont14alt:
   741                              <1>     db  01dh, 000h, 000h, 000h, 000h, 024h, 066h, 0ffh, 066h, 024h, 000h, 000h, 000h, 000h, 000h, 022h
   742                              <1>     db  000h, 063h, 063h, 063h, 022h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 02bh, 000h
   743                              <1>     db  000h, 000h, 018h, 018h, 018h, 0ffh, 018h, 018h, 018h, 000h, 000h, 000h, 000h, 02dh, 000h, 000h
   744                              <1>     db  000h, 000h, 000h, 000h, 0ffh, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 04dh, 000h, 000h, 0c3h
   745                              <1>     db  0e7h, 0ffh, 0dbh, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 000h, 000h, 000h, 054h, 000h, 000h, 0ffh, 0dbh
   746                              <1>     db  099h, 018h, 018h, 018h, 018h, 018h, 03ch, 000h, 000h, 000h, 056h, 000h, 000h, 0c3h, 0c3h, 0c3h
   747                              <1>     db  0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 000h, 000h, 000h, 057h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h
   748                              <1>     db  0dbh, 0dbh, 0ffh, 066h, 066h, 000h, 000h, 000h, 058h, 000h, 000h, 0c3h, 0c3h, 066h, 03ch, 018h
   749                              <1>     db  03ch, 066h, 0c3h, 0c3h, 000h, 000h, 000h, 059h, 000h, 000h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h
   750                              <1>     db  018h, 018h, 03ch, 000h, 000h, 000h, 05ah, 000h, 000h, 0ffh, 0c3h, 086h, 00ch, 018h, 030h, 061h
   751                              <1>     db  0c3h, 0ffh, 000h, 000h, 000h, 06dh, 000h, 000h, 000h, 000h, 000h, 0e6h, 0ffh, 0dbh, 0dbh, 0dbh
   752                              <1>     db  0dbh, 000h, 000h, 000h, 076h, 000h, 000h, 000h, 000h, 000h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h
   753                              <1>     db  000h, 000h, 000h, 077h, 000h, 000h, 000h, 000h, 000h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh, 066h, 000h
   754                              <1>     db  000h, 000h, 091h, 000h, 000h, 000h, 000h, 06eh, 03bh, 01bh, 07eh, 0d8h, 0dch, 077h, 000h, 000h
   755                              <1>     db  000h, 09bh, 000h, 018h, 018h, 07eh, 0c3h, 0c0h, 0c0h, 0c3h, 07eh, 018h, 018h, 000h, 000h, 000h
   756                              <1>     db  09dh, 000h, 000h, 0c3h, 066h, 03ch, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 000h, 000h, 000h, 09eh
   757                              <1>     db  000h, 0fch, 066h, 066h, 07ch, 062h, 066h, 06fh, 066h, 066h, 0f3h, 000h, 000h, 000h, 0f1h, 000h
   758                              <1>     db  000h, 018h, 018h, 018h, 0ffh, 018h, 018h, 018h, 000h, 0ffh, 000h, 000h, 000h, 0f6h, 000h, 000h
   759                              <1>     db  018h, 018h, 000h, 000h, 0ffh, 000h, 000h, 018h, 018h, 000h, 000h, 000h, 000h
   760                              <1> vgafont16alt:
   761                              <1>     db  01dh, 000h, 000h, 000h, 000h, 000h, 024h, 066h, 0ffh, 066h, 024h, 000h, 000h, 000h, 000h, 000h
   762                              <1>     db  000h, 030h, 000h, 000h, 03ch, 066h, 0c3h, 0c3h, 0dbh, 0dbh, 0c3h, 0c3h, 066h, 03ch, 000h, 000h
   763                              <1>     db  000h, 000h, 04dh, 000h, 000h, 0c3h, 0e7h, 0ffh, 0ffh, 0dbh, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 000h
   764                              <1>     db  000h, 000h, 000h, 054h, 000h, 000h, 0ffh, 0dbh, 099h, 018h, 018h, 018h, 018h, 018h, 018h, 03ch
   765                              <1>     db  000h, 000h, 000h, 000h, 056h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 066h, 03ch
   766                              <1>     db  018h, 000h, 000h, 000h, 000h, 057h, 000h, 000h, 0c3h, 0c3h, 0c3h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh
   767                              <1>     db  066h, 066h, 000h, 000h, 000h, 000h, 058h, 000h, 000h, 0c3h, 0c3h, 066h, 03ch, 018h, 018h, 03ch
   768                              <1>     db  066h, 0c3h, 0c3h, 000h, 000h, 000h, 000h, 059h, 000h, 000h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h
   769                              <1>     db  018h, 018h, 018h, 03ch, 000h, 000h, 000h, 000h, 05ah, 000h, 000h, 0ffh, 0c3h, 086h, 00ch, 018h
   770                              <1>     db  030h, 060h, 0c1h, 0c3h, 0ffh, 000h, 000h, 000h, 000h, 06dh, 000h, 000h, 000h, 000h, 000h, 0e6h
   771                              <1>     db  0ffh, 0dbh, 0dbh, 0dbh, 0dbh, 0dbh, 000h, 000h, 000h, 000h, 076h, 000h, 000h, 000h, 000h, 000h
   772                              <1>     db  0c3h, 0c3h, 0c3h, 0c3h, 066h, 03ch, 018h, 000h, 000h, 000h, 000h, 077h, 000h, 000h, 000h, 000h
   773                              <1>     db  000h, 0c3h, 0c3h, 0c3h, 0dbh, 0dbh, 0ffh, 066h, 000h, 000h, 000h, 000h, 078h, 000h, 000h, 000h
   774                              <1>     db  000h, 000h, 0c3h, 066h, 03ch, 018h, 03ch, 066h, 0c3h, 000h, 000h, 000h, 000h, 091h, 000h, 000h
   775                              <1>     db  000h, 000h, 000h, 06eh, 03bh, 01bh, 07eh, 0d8h, 0dch, 077h, 000h, 000h, 000h, 000h, 09bh, 000h
   776                              <1>     db  018h, 018h, 07eh, 0c3h, 0c0h, 0c0h, 0c0h, 0c3h, 07eh, 018h, 018h, 000h, 000h, 000h, 000h, 09dh
   777                              <1>     db  000h, 000h, 0c3h, 066h, 03ch, 018h, 0ffh, 018h, 0ffh, 018h, 018h, 018h, 000h, 000h, 000h, 000h
   778                              <1>     db  09eh, 000h, 0fch, 066h, 066h, 07ch, 062h, 066h, 06fh, 066h, 066h, 066h, 0f3h, 000h, 000h, 000h
   779                              <1>     db  000h, 0abh, 000h, 0c0h, 0c0h, 0c2h, 0c6h, 0cch, 018h, 030h, 060h, 0ceh, 09bh, 006h, 00ch, 01fh
   780                              <1>     db  000h, 000h, 0ach, 000h, 0c0h, 0c0h, 0c2h, 0c6h, 0cch, 018h, 030h, 066h, 0ceh, 096h, 03eh, 006h
   781                              <1>     db  006h, 000h, 000h, 000h
   782                              <1> 
   783                              <1> %endif
  3786                                  
  3787                                  ; 20/11/2020
  3788                                  vbe2_bochs_vbios:
  3789                                  ;	db "BOCHS/QEMU"
  3790 00017954 424F4348532F51454D-     	db "BOCHS/QEMU/VIRTUALBOX"  ; 26/11/2020
  3790 0001795D 552F5649525455414C-
  3790 00017966 424F58             
  3791                                  ;vbe_vnumber equ vbe2_bochs_vbios + 28 ; "3" or "2"
  3792                                  ; 26/11/2020
  3793                                  vbe_vnumber equ vbe2_bochs_vbios + 30 ; "3" or "2"
  3794                                  ; 15/11/2020
  3795                                  vesa_vbe3_bios_msg:
  3796                                  	;db " VESA VBE version 3 Video BIOS ..."
  3797 00017969 205645534120564245-     	db " VESA VBE3 Video BIOS ..." ; 26/11/2020
  3797 00017972 3320566964656F2042-
  3797 0001797B 494F53202E2E2E     
  3798 00017982 0D0A0D0A00              	db 0Dh, 0Ah, 0Dh, 0Ah, 0
  3799                                  
  3800                                  ; 28/02/2021
  3801 00017987 18                      truecolor: db 24
  3802                                  
  3803                                  align 2
  3804                                  
  3805                                  ; EPOCH Variables
  3806                                  ; 13/04/2015 - Retro UNIX 386 v1 Beginning
  3807                                  ; 09/04/2013 epoch variables
  3808                                  ; Retro UNIX 8086 v1 Prototype: UNIXCOPY.ASM, 10/03/2013
  3809                                  ;
  3810 00017988 B207                    year: 	dw 1970
  3811 0001798A 0100                    month: 	dw 1
  3812 0001798C 0100                    day: 	dw 1
  3813 0001798E 0000                    hour: 	dw 0
  3814 00017990 0000                    minute: dw 0
  3815 00017992 0000                    second: dw 0
  3816                                  
  3817                                  DMonth:
  3818 00017994 0000                    	dw 0
  3819 00017996 1F00                    	dw 31
  3820 00017998 3B00                    	dw 59
  3821 0001799A 5A00                    	dw 90
  3822 0001799C 7800                    	dw 120
  3823 0001799E 9700                    	dw 151
  3824 000179A0 B500                    	dw 181
  3825 000179A2 D400                    	dw 212
  3826 000179A4 F300                    	dw 243
  3827 000179A6 1101                    	dw 273
  3828 000179A8 3001                    	dw 304
  3829 000179AA 4E01                    	dw 334
  3830                                  
  3831                                  ; 15/11/2020
  3832 000179AC 00                      db	0
  3833                                  kernel_version_msg: ; 17/04/2021
  3834                                  ;;;;;db	"TRDOS (386) Kernel v2.0.4 by Erdogan Tan"
  3835                                  ;;;;db	"TRDOS (386) Kernel v2.0.5 by Erdogan Tan" ; 11/08/2022
  3836                                  ;;;db	"TRDOS (386) Kernel v2.0.6 by Erdogan Tan" ; 29/08/2023
  3837                                  ;;db	"TRDOS (386) Kernel v2.0.7 by Erdogan Tan" ; 20/10/2023
  3838                                  ;db	"TRDOS (386) Kernel v2.0.8 by Erdogan Tan" ; 16/05/2024
  3839 000179AD 5452444F5320283338-     db	"TRDOS (386) Kernel v2.0.9 by Erdogan Tan" ; 20/08/2024
  3839 000179B6 3629204B65726E656C-
  3839 000179BF 2076322E302E392062-
  3839 000179C8 79204572646F67616E-
  3839 000179D1 2054616E           
  3840 000179D5 00                      db	0
  3841                                  
  3842                                  ; 20/02/2017
  3843                                  KERNELFSIZE  equ $  ; 04/07/2016
  3844                                  
  3845                                  bss_start:
  3846                                  
  3847                                  ABSOLUTE bss_start
  3848                                  
  3849 000179D6 ????                    alignb 8 ; 25/12/2016
  3850                                  
  3851                                  	; 15/04/2016
  3852                                  	; TRDOS 386 (TRDOS v2.0)
  3853                                  	; 	80 interrupts 	
  3854                                  	; 11/03/2015
  3855                                  	; Interrupt Descriptor Table (20/08/2014)
  3856                                  idt:
  3857                                  	;resb	64*8 ; INT 0 to INT 3Fh
  3858                                  	; 15/04/2016
  3859 000179D8 <res 280h>              	resb	80*8 ; INT 0 to INT 4Fh
  3860                                  
  3861                                  idt_end:
  3862                                  
  3863                                  ;alignb 4
  3864                                  
  3865                                  task_state_segment:
  3866                                  	; 24/03/2015
  3867 00017C58 ????                    tss.link:   resw 1
  3868 00017C5A ????                    	    resw 1
  3869                                  ; tss offset 4	
  3870 00017C5C ????????                tss.esp0:   resd 1
  3871 00017C60 ????                    tss.ss0:    resw 1
  3872 00017C62 ????                    	    resw 1	
  3873 00017C64 ????????                tss.esp1:   resd 1
  3874 00017C68 ????                    tss.ss1:    resw 1
  3875 00017C6A ????                    	    resw 1 	
  3876 00017C6C ????????                tss.esp2:   resd 1
  3877 00017C70 ????                    tss.ss2:    resw 1
  3878 00017C72 ????                    	    resw 1
  3879                                  ; tss offset 28
  3880 00017C74 ????????                tss.CR3:    resd 1
  3881 00017C78 ????????                tss.eip:    resd 1
  3882 00017C7C ????????                tss.eflags: resd 1
  3883                                  ; tss offset 40
  3884 00017C80 ????????                tss.eax:    resd 1		 		
  3885 00017C84 ????????                tss.ecx:    resd 1
  3886 00017C88 ????????                tss.edx:    resd 1
  3887 00017C8C ????????                tss.ebx:    resd 1
  3888 00017C90 ????????                tss.esp:    resd 1
  3889 00017C94 ????????                tss.ebp:    resd 1
  3890 00017C98 ????????                tss.esi:    resd 1
  3891 00017C9C ????????                tss.edi:    resd 1
  3892                                  ; tss offset 72
  3893 00017CA0 ????                    tss.ES:     resw 1
  3894 00017CA2 ????                    	    resw 1	
  3895 00017CA4 ????                    tss.CS:	    resw 1
  3896 00017CA6 ????                    	    resw 1
  3897 00017CA8 ????                    tss.SS:	    resw 1
  3898 00017CAA ????                    	    resw 1
  3899 00017CAC ????                    tss.DS:	    resw 1
  3900 00017CAE ????                    	    resw 1
  3901 00017CB0 ????                    tss.FS:	    resw 1
  3902 00017CB2 ????                    	    resw 1
  3903 00017CB4 ????                    tss.GS:	    resw 1
  3904 00017CB6 ????                    	    resw 1		
  3905 00017CB8 ????                    tss.LDTR:   resw 1
  3906 00017CBA ????                    	    resw 1
  3907                                  ; tss offset 100		
  3908 00017CBC ????                    	    resw 1		
  3909 00017CBE ????                    tss.IOPB:   resw 1
  3910                                  ; tss offset 104 
  3911                                  tss_end:
  3912                                  
  3913 00017CC0 ????????                k_page_dir:  resd 1 ; Kernel's (System) Page Directory address
  3914                                  		    ; (Physical address = Virtual address)	 	
  3915 00017CC4 ????????                memory_size: resd 1 ; memory size in pages
  3916 00017CC8 ????????                free_pages:  resd 1 ; number of free pages		
  3917 00017CCC ????????                next_page:   resd 1 ; offset value in M.A.T. for
  3918                                  		    ; first free page search
  3919 00017CD0 ????????                last_page:   resd 1 ; offset value in M.A.T. which
  3920                                  		    ; next free page search will be
  3921                                  		    ; stopped after it. (end of M.A.T.)
  3922 00017CD4 ????????                first_page:  resd 1 ; offset value in M.A.T. which
  3923                                  		    ; first free page search
  3924                                  		    ; will be started on it. (for user)
  3925 00017CD8 ????????                mat_size:    resd 1 ; Memory Allocation Table size in pages
  3926                                  
  3927                                  ; 20/11/2020
  3928                                  ;vbe2bios:    resw 1 ; VBE2 video bios ID (bochs/qemu)
  3929                                  ;		    ; (0B0C4h or 0B0C5h for bochs/plex86 vgabios)				
  3930                                  
  3931                                  ; 02/09/2014 (Retro UNIX 386 v1)
  3932                                  ; 04/12/2013 (Retro UNIX 8086 v1)
  3933 00017CDC ????                    CRT_START:   resw 1 	  ; starting address in regen buffer
  3934                                  			  ; NOTE: active page only	
  3935 00017CDE <res 10h>               CURSOR_POSN: resw 8 ; cursor positions for video pages
  3936                                  ACTIVE_PAGE: 
  3937 00017CEE ??                      ptty: 	     resb 1 ; current tty
  3938                                  ; 01/07/2015 - 29/01/2016
  3939 00017CEF ??                      ccolor:	     resb 1 ; current color attribute
  3940                                  ; 26/10/2015
  3941                                  ; 07/09/2014
  3942 00017CF0 <res 14h>               ttychr:      resw ntty+2 ; Character buffer (multiscreen)
  3943                                  
  3944                                  ; 18/05/2015 (03/06/2013 - Retro UNIX 8086 v1 feature only!)
  3945 00017D04 ????????                p_time:      resd 1     ; present time (for systime & sysmdate)
  3946                                  
  3947                                  ; 18/05/2015 (16/08/2013 - Retro UNIX 8086 v1 feature only !)
  3948                                  ; (open mode locks for pseudo TTYs)
  3949                                  ; [ major tty locks (return error in any conflicts) ]
  3950 00017D08 <res 14h>               ttyl:        resw ntty+2 ; opening locks for TTYs.
  3951                                  
  3952                                  ; 15/04/2015 (Retro UNIX 386 v1)
  3953                                  ; 22/09/2013 (Retro UNIX 8086 v1)
  3954 00017D1C <res Ah>                wlist:       resb ntty+2 ; wait channel list (0 to 9 for TTYs)
  3955                                  ; 15/04/2015 (Retro UNIX 386 v1)
  3956                                  ;; 12/07/2014 -> sp_init set comm. parameters as 0E3h
  3957                                  ;; 0 means serial port is not available 
  3958                                  ;;comprm: ; 25/06/2014
  3959 00017D26 ??                      com1p:       resb 1  ;;0E3h
  3960 00017D27 ??                      com2p:       resb 1  ;;0E3h
  3961                                  
  3962                                  ; 17/11/2015
  3963                                  ; request for response (from the terminal)	
  3964 00017D28 ????                    req_resp:    resw 1 			
  3965                                  ; 07/11/2015
  3966 00017D2A ??                      ccomport:    resb 1 ; current COM (serial) port
  3967                                  		    ; (0= COM1, 1= COM2)
  3968                                  ; 09/11/2015
  3969 00017D2B ??                      comqr:	     resb 1 ; 'query or response' sign (u9.s, 'sndc')
  3970                                  ; 07/11/2015
  3971 00017D2C ????                    rchar:	     resw 1 ; last received char for COM 1 and COM 2		
  3972 00017D2E ????                    schar:	     resw 1 ; last sent char for COM 1 and COM 2
  3973                                  
  3974                                  ; 22/08/2014 (RTC)
  3975                                  ; (Packed BCD)
  3976 00017D30 ??                      time_seconds: resb 1
  3977 00017D31 ??                      time_minutes: resb 1
  3978 00017D32 ??                      time_hours:   resb 1
  3979 00017D33 ??                      date_wday:    resb 1
  3980 00017D34 ??                      date_day:     resb 1
  3981 00017D35 ??                      date_month:   resb 1			
  3982 00017D36 ??                      date_year:    resb 1
  3983 00017D37 ??                      date_century: resb 1
  3984                                  
  3985                                  ; 24/01/2016
  3986 00017D38 ????????                RTC_LH:	       resd 1
  3987 00017D3C ??                      RTC_WAIT_FLAG: resb 1
  3988 00017D3D ??                      USER_FLAG:     resb 1
  3989                                  ; 19/05/2016
  3990                                  ;RTC_second:
  3991 00017D3E ??                      RTC_2Hz:       resb 1 ;  from 2Hz interrupt to 1Hz timer event function	
  3992                                  
  3993                                  %include 'diskbss.s'	; UNINITIALIZED DISK (BIOS) DATA
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.5 - diskbss.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 06/08/2022 (Previous: 24/01/2016)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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> ;	(Unitialized Disk Parameters Data section for 'DISKIO.INC') 
    22                              <1> 
    23 00017D3F ??                  <1> alignb 2
    24                              <1> 
    25                              <1> ;----------------------------------------
    26                              <1> ;	TIMER DATA AREA 		:
    27                              <1> ;----------------------------------------
    28                              <1> 
    29                              <1> TIMER_LH:	; 16/02/2015
    30 00017D40 ????                <1> TIMER_LOW:      resw	1               ; LOW WORD OF TIMER COUNT
    31 00017D42 ????                <1> TIMER_HIGH:     resw	1               ; HIGH WORD OF TIMER COUNT
    32 00017D44 ??                  <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 00017D45 ??                  <1> SEEK_STATUS:	resb	1
    39 00017D46 ??                  <1> MOTOR_STATUS:	resb	1
    40 00017D47 ??                  <1> MOTOR_COUNT:	resb	1
    41 00017D48 ??                  <1> DSKETTE_STATUS:	resb	1
    42 00017D49 ??????????????      <1> NEC_STATUS:	resb	7
    43                              <1> 
    44                              <1> ;----------------------------------------
    45                              <1> ;	ADDITIONAL MEDIA DATA		:
    46                              <1> ;----------------------------------------
    47                              <1> 
    48 00017D50 ??                  <1> LASTRATE:	resb 	1
    49 00017D51 ??                  <1> HF_STATUS:	resb 	1
    50                              <1> ; 06/08/2022
    51                              <1> ;HF_ERROR:	resb 	1
    52 00017D52 ??                  <1> HF_INT_FLAG:	resb 	1
    53                              <1> ; 06/08/2022
    54                              <1> ;HF_CNTRL:	resb 	1
    55                              <1> ;DSK_STATE:	resb 	4
    56                              <1> ; 06/08/2022
    57 00017D53 ????                <1> DSK_STATE:	resb	2 	
    58 00017D55 ????                <1> DSK_TRK:	resb 	2
    59                              <1> 
    60                              <1> ;----------------------------------------
    61                              <1> ;	FIXED DISK DATA AREAS		:
    62                              <1> ;----------------------------------------
    63                              <1> 
    64 00017D57 ??                  <1> DISK_STATUS1:	resb 	1		; FIXED DISK STATUS
    65 00017D58 ??                  <1> HF_NUM:		resb 	1		; COUNT OF FIXED DISK DRIVES
    66 00017D59 ??                  <1> CONTROL_BYTE:	resb 	1		; HEAD CONTROL BYTE
    67                              <1> ;@PORT_OFF	resb	1		; RESERVED (PORT OFFSET)
    68                              <1> ;port1_off	resb	1		; Hard disk controller 1 - port offset
    69                              <1> ;port2_off	resb	1		; Hard disk controller 2 - port offset
    70                              <1> 
    71 00017D5A ????                <1> alignb 4
    72                              <1> 
    73                              <1> ;HF_TBL_VEC:	resd	1 		; Primary master disk param. tbl. pointer
    74                              <1> ;HF1_TBL_VEC:	resd	1		; Primary slave disk param. tbl. pointer
    75                              <1> HF_TBL_VEC: ; 22/12/2014	
    76 00017D5C ????????            <1> HDPM_TBL_VEC:	resd	1 		; Primary master disk param. tbl. pointer
    77 00017D60 ????????            <1> HDPS_TBL_VEC:	resd	1		; Primary slave disk param. tbl. pointer
    78 00017D64 ????????            <1> HDSM_TBL_VEC:	resd	1 		; Secondary master disk param. tbl. pointer
    79 00017D68 ????????            <1> HDSS_TBL_VEC:	resd	1		; Secondary slave disk param. tbl. pointer
    80                              <1> 
    81                              <1> ; 03/01/2015
    82 00017D6C ??                  <1> LBAMode:     	resb	1
    83                              <1> 
    84                              <1> ; *****************************************************************************
  3994                                  
  3995                                  ;;; Real Mode Data (10/07/2015 - BSS)
  3996                                  
  3997                                  ;alignb 2
  3998                                  
  3999                                  ; 10/01/2016
  4000                                  %include 'trdoskx.s'	; UNINITIALIZED KERNEL (Logical Drive & FS) DATA
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.9) - UNINITIALIZED DATA : trdoskx.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 01/09/2024 (Previous: 05/06/2024 - Kernel v2.0.8)
     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 00017D6D ??????              <1> alignb 4
    20                              <1> 
    21                              <1> ; MAINPROG.ASM
    22 00017D70 ????????            <1> MainProgCfg_FileSize:   resd 1 ; 14/04/2016
    23 00017D74 ????????            <1> MainProgCfg_LineOffset: resd 1 ; 14/04/2016
    24                              <1> 
    25 00017D78 ????????            <1> Current_VolSerial: resd 1
    26                              <1> 
    27 00017D7C ????????            <1> Current_Dir_FCluster: resd 1
    28                              <1> 
    29 00017D80 ??                  <1> Current_Dir_Level: resb 1
    30 00017D81 ??                  <1> Current_FATType: resb 1
    31 00017D82 ??                  <1> Current_Drv: resb 1
    32 00017D83 ??                  <1> Current_Dir_Drv:   resb 1 ; '?'
    33 00017D84 ??                  <1>                    resb 1 ; ':'
    34 00017D85 ??                  <1> Current_Dir_Root:  resb 1 ; '/'
    35 00017D86 <res 5Ah>           <1> Current_Directory: resb 90
    36 00017DE0 ??                  <1> End_Of_Current_Dir_Str: resb 1
    37 00017DE1 ??                  <1> Current_Dir_StrLen: resb 1
    38                              <1> 
    39 00017DE2 ??                  <1> CursorColumn: 	resb 1
    40 00017DE3 ??                  <1> CmdArgStart:    resb 1
    41                              <1> 
    42                              <1> ; 03/02/2016
    43 00017DE4 <res 4Eh>           <1> Remark:		resb 78
    44                              <1> 
    45 00017E32 <res 50h>           <1> CommandBuffer: 	resb 80
    46                              <1> 
    47 00017E82 <res 100h>          <1> TextBuffer:	resb 256
    48                              <1> 
    49                              <1> MasterBootBuff:
    50 00017F82 <res 1BEh>          <1> MasterBootCode: resb 1BEh
    51 00018140 <res 40h>           <1> PartitionTable: resb 64
    52 00018180 ????                <1> MBIDCode: resw 1
    53                              <1> 
    54                              <1> PTable_Buffer:
    55 00018182 <res 40h>           <1> PTable_hd0: resb 64
    56 000181C2 <res 40h>           <1> PTable_hd1: resb 64
    57 00018202 <res 40h>           <1> PTable_hd2: resb 64
    58 00018242 <res 40h>           <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                              <1> ; 22/05/2024
    66 00018282 ????????            <1> HD_LBA_yes: resd 1
    67                              <1> ; 13/08/2020
    68 00018286 ??                  <1> scount: resb 1 ; 16/05/2016 (diskio.s, 'int33h:')
    69                              <1> ; 22/05/2024
    70                              <1> 	;resb 1
    71                              <1> 	;resb 1
    72                              <1> 	;resb 1
    73                              <1> ;HD_LBA_yes: resb 1
    74 00018287 ??                  <1> PP_Counter: resb 1
    75 00018288 ??                  <1> EP_Counter: resb 1
    76                              <1> ; 13/08/2020
    77 00018289 ??                  <1> LD_Counter: resb 1
    78                              <1> 
    79                              <1> ; 30/08/2020
    80 0001828A ????????            <1> MBR_EP_StartSector: resd 1
    81                              <1> 		; Extd partition start sector as in MBR
    82 0001828E ????????            <1> EP_StartSector: resd 1 ; next extd partition start sector
    83                              <1> 	; 15/07/2020
    84                              <1>                 ;resd 1
    85                              <1>                 ;resd 1
    86                              <1> 
    87                              <1> ; 20/07/2020
    88 00018292 <res 200h>          <1> DOSBootSectorBuff: resb 512
    89                              <1> ; 15/07/2020
    90                              <1> ;DOSBootSectorBuff: resb 446 ; 1BEh
    91                              <1> ;MiniPartitionTable: resb 64 ;  40h
    92                              <1> ;MiniPartitionMagic: resw  1 ;  02h
    93                              <1> 
    94                              <1> FAT_BuffDescriptor:
    95 00018492 ????????            <1> FAT_CurrentCluster: resd 1
    96 00018496 ??                  <1> FAT_BuffValidData: resb 1
    97 00018497 ??                  <1> FAT_BuffDrvName: resb 1
    98 00018498 ????                <1> FAT_BuffOffset: resw 1
    99 0001849A ????????            <1> FAT_BuffSector: resd 1
   100                              <1> 
   101 0001849E ????????            <1> FAT_ClusterCounter: resd 1
   102 000184A2 ????????            <1> LastCluster: resd 1
   103                              <1> 
   104                              <1> ; 16/05/2016
   105                              <1> ;; 18/03/2016 (TRDOS v2.0)
   106                              <1> ;ClusterBuffer_Valid: resb 1
   107                              <1> 
   108                              <1> ; 29/07/2022
   109                              <1> ;resb 1
   110                              <1> ; 02/12/2023
   111 000184A6 ??                  <1> P_TIMER: resb 1 ; diskette change check (2 seconds)
   112                              <1> 
   113                              <1> Dir_BuffDescriptor:
   114 000184A7 ??                  <1> DirBuff_DRV: resb 1
   115 000184A8 ??                  <1> DirBuff_FATType: resb 1
   116 000184A9 ??                  <1> DirBuff_ValidData: resb 1
   117 000184AA ????                <1> DirBuff_CurrentEntry: resw 1
   118 000184AC ????                <1> DirBuff_LastEntry: resw 1
   119 000184AE ????????            <1> DirBuff_Cluster: resd 1
   120 000184B2 ????                <1> DirBuffer_Size: resw 1
   121                              <1> ;DirBuff_EntryCounter: resw 1
   122                              <1> 
   123                              <1> ; 01/02/2016
   124                              <1> ; these are on (real mode) segment 8000h and later
   125                              <1> ; FAT_Buffer:	resb 1536 ; 3 sectors
   126                              <1> ; Dir_Buffer:	resb 512*32
   127                              <1> ; Logical_DOSDisks:  resb 6656 ; 26 * 256 bytes
   128                              <1> 
   129                              <1> ; 18/01/2016
   130                              <1> 
   131 000184B4 ????????            <1> FreeClusterCount: resd 1
   132                              <1> 
   133 000184B8 ????????            <1> VolSize_Unit1:   resd 1
   134 000184BC ????????            <1> VolSize_Unit2:   resd 1
   135                              <1> 
   136 000184C0 ????????            <1> Vol_Tot_Sec_Str_Start:	    resd 1
   137 000184C4 <res Ah>            <1> Vol_Tot_Sec_Str: 	    resb 10
   138 000184CE ??                  <1> Vol_Tot_Sec_Str_End:	    resb 1
   139 000184CF ??                  <1> resb 1
   140 000184D0 ????????            <1> Vol_Free_Sectors_Str_Start: resd 1
   141 000184D4 <res Ah>            <1> Vol_Free_Sectors_Str:	    resb 10
   142 000184DE ??                  <1> Vol_Free_Sectors_Str_End:   resb 1
   143                              <1> 
   144                              <1> ; 10/02/2016
   145 000184DF ??                  <1> RUN_CDRV: resb 1 ; CMD_INTR.ASM  ; 09/11/2011
   146                              <1> 
   147                              <1> ; 24/01/2016
   148 000184E0 <res 80h>           <1> PATH_Array:     resb 128 ; DIR.ASM ; 09/10/2011
   149                              <1> ; 06/02/2016
   150 00018560 ????????            <1> CCD_DriveDT:	resd 1 ; DIR.ASM ; (word)
   151 00018564 ??                  <1> CCD_Level:	resb 1 ; DIR.ASM
   152 00018565 ??                  <1> Last_Dir_Level:	resb 1 ; DIR.ASM
   153                              <1> ;
   154 00018566 ????                <1> CDLF_AttributesMask: resw 1 ; DIR.ASM
   155 00018568 ????????            <1> CDLF_FNAddress:	resd 1 ; DIR.ASM (word)
   156 0001856C ????                <1> CDLF_DEType:	resw 1 ; DIR.ASM
   157                              <1> ;
   158 0001856E ??                  <1> CD_COMMAND:	resb 1 ; DIR.ASM
   159                              <1> 
   160 0001856F ??                  <1> alignb 4
   161                              <1> 
   162                              <1> ; 29/01/2016
   163 00018570 ??                  <1> Program_Exit:	resb 1 ; CMD_INTR.ASM  ; 09/11/2011
   164                              <1> 
   165                              <1> ;alignb 4
   166                              <1> ; 23/02/2016
   167 00018571 ??                  <1> disk_rw_op:	resb 1 ; 0 = disk read, 1 = disk write
   168                              <1> ;disk_rw_spt:	resb 1 ; sectors per track (<= 63) /// (<256)
   169                              <1> ; 31/01/2016
   170 00018572 ??                  <1> retry_count: 	resb 1 ; DISK_IO.ASM ; 20/07/2011 (CHS_RetryCount)
   171 00018573 ??                  <1> disk_rw_err: 	resb 1 ; DISK_IO.ASM ; (Disk_IO_err_code)
   172 00018574 ????????            <1> sector_count:	resd 1 ; DISK_IO.ASM ; (Disk_RW_SectorCount)
   173                              <1> 
   174                              <1> ; 06/02/2016 (long name)
   175 00018578 ????                <1> FDE_AttrMask:	   resw 1 ; DIR.ASM
   176 0001857A ????                <1> AmbiguousFileName: resw 1 ; DIR.ASM
   177 0001857C ??                  <1> PreviousAttr:	   resb 1 ; DIR.ASM
   178                              <1> ;
   179 0001857D ??                  <1> LongNameFound:   resb 1	  ; DIR.ASM
   180 0001857E ??                  <1> LFN_EntryLength: resb 1   ; DIR.ASM
   181 0001857F ??                  <1> LFN_CheckSum:    resb 1   ; DIR.ASM
   182 00018580 <res 84h>           <1> LongFileName:    resb 132 ; DIR.ASM
   183                              <1> 
   184                              <1> ;PATH_Array_Ptr: resw 1 ; DIR.ASM
   185 00018604 ??                  <1> PATH_CDLevel:	 resb 1 ; DIR.ASM
   186 00018605 ??                  <1> PATH_Level:	 resb 1 ; DIR.ASM
   187                              <1> 
   188                              <1> ; 07/02/2016
   189 00018606 <res Dh>            <1> Dir_File_Name:	resb 13 ; DIR.ASM ; 09/10/2011
   190                              <1> 
   191                              <1> ; 10/02/2016
   192 00018613 <res Dh>            <1> Dir_Entry_Name:	resb 13 ; DIR.ASM
   193                              <1> 
   194                              <1> alignb 2
   195                              <1> 
   196 00018620 ????                <1> AttributesMask: resw 1 ; CMD_INTR.ASM ; 09/11/2011
   197                              <1> 
   198                              <1> ; 10/02/2016 (128 bytes -> 126 bytes)
   199                              <1> ; 08/02/2016
   200                              <1> ;FFF Structure (128 bytes) ; DIR.ASM ; 09/10/2011
   201 00018622 ??                  <1> FindFile_Drv:		  resb 1
   202 00018623 <res 41h>           <1> FindFile_Directory:	  resb 65
   203 00018664 <res Dh>            <1> FindFile_Name:		  resb 13
   204                              <1> FindFile_LongNameEntryLength:
   205 00018671 ??                  <1> FindFile_LongNameYes: 	  resb 1 ; Sign for longname procedures
   206                              <1> ;Above 80 bytes form
   207                              <1> ;TR-DOS Source/Destination File FullName Format/Structure
   208 00018672 ????                <1> FindFile_AttributesMask:  resw 1
   209 00018674 <res 20h>           <1> FindFile_DirEntry:	  resb 32
   210 00018694 ????????            <1> FindFile_DirFirstCluster: resd 1
   211 00018698 ????????            <1> FindFile_DirCluster:	  resd 1
   212 0001869C ????                <1> FindFile_DirEntryNumber:  resw 1
   213 0001869E ????                <1> FindFile_MatchCounter:	  resw 1
   214 000186A0 ????                <1> FindFile_Reserved:	  resw 1 ; 06/03/2016
   215                              <1> 
   216 000186A2 ????????            <1> First_Path_Pos: resd 1	; DIR.ASM ; 09/10/2011
   217 000186A6 ????????            <1> Last_Slash_Pos: resd 1	; DIR.ASM
   218                              <1> 
   219                              <1> ; 10/02/2016
   220 000186AA ????                <1> File_Count:     resw 1 	; DIR.ASM ; 09/10/2011
   221 000186AC ????                <1> Dir_Count:      resw 1
   222 000186AE ????????            <1> Total_FSize:    resd 1
   223 000186B2 ????????            <1> TFS_Dec_Begin:  resd 1
   224 000186B6 <res Ah>            <1>                 resb 10
   225 000186C0 ??                  <1> TFS_Dec_End:    resb 1
   226                              <1> 
   227 000186C1 ??                  <1> PrintDir_RowCounter: resb 1
   228                              <1> 
   229 000186C2 ????                <1> alignb 4
   230                              <1> ; 15/02/2015 ('show' command variables)
   231 000186C4 ????????            <1> Show_FDT:	resd 1
   232 000186C8 ????????            <1> Show_LDDDT:	resd 1
   233 000186CC ????????            <1> Show_Cluster:	resd 1
   234 000186D0 ????????            <1> Show_FileSize:	resd 1
   235 000186D4 ????????            <1> Show_FilePointer: resd 1
   236 000186D8 ????                <1> Show_ClusterPointer: resw 1
   237 000186DA ????                <1> Show_ClusterSize: resw 1
   238 000186DC ??                  <1> Show_RowCount:	resb 1
   239                              <1> 
   240 000186DD ??????              <1> alignb 4
   241                              <1> ; 21/02/2016
   242 000186E0 ????????            <1> DelFile_FNPointer:	resd 1 ; ; CMD_INTR.ASM (word) ; 09/11/2011
   243                              <1> ; 27/02/2016
   244                              <1> ; DIR.ASM (09/10/2011)
   245 000186E4 ????????            <1> DelFile_FCluster:	resd 1
   246 000186E8 ????                <1> DelFile_EntryCounter:	resw 1
   247 000186EA ??                  <1> DelFile_LNEL:		resb 1
   248 000186EB ??                  <1> resb 1
   249                              <1> 
   250                              <1> ; DIR.ASM
   251 000186EC ????????            <1> mkdir_DirName_Offset: 	resd 1
   252 000186F0 ????????            <1> mkdir_FFCluster:	resd 1
   253 000186F4 ????????            <1> mkdir_LastDirCluster:	resd 1
   254 000186F8 ????????            <1> mkdir_FreeSectors:	resd 1
   255 000186FC ????                <1> mkdir_attrib:		resw 1
   256 000186FE ??                  <1> mkdir_SecPerClust:	resb 1
   257 000186FF ??                  <1> mkdir_add_new_cluster:	resb 1
   258 00018700 <res Dh>            <1> mkdir_Name:		resb 13
   259 0001870D ????                <1> resw 1 ; 01/03/2016
   260                              <1> ; 27/02/2016
   261 0001870F ??                  <1> RmDir_MultiClusters:	resb 1
   262 00018710 ????????            <1> RmDir_DirEntryOffset:	resd 1 ; 01/03/2016 (word -> dword)
   263 00018714 ????????            <1> RmDir_ParentDirCluster: resd 1
   264 00018718 ????????            <1> RmDir_DirLastCluster:   resd 1
   265 0001871C ????????            <1> RmDir_PreviousCluster:  resd 1
   266                              <1> ; 22/02/2016
   267 00018720 ??                  <1> UPDLMDT_CDirLevel:	resb 1
   268 00018721 ????????            <1> UPDLMDT_CDirFCluster:	resd 1
   269                              <1> 
   270 00018725 ??????              <1> alignb 4
   271                              <1> ; DRV_FAT.ASM ; 21/08/2011
   272 00018728 ????????            <1> gffc_next_free_cluster:  resd 1
   273 0001872C ????????            <1> gffc_first_free_cluster: resd 1
   274 00018730 ????????            <1> gffc_last_free_cluster:  resd 1
   275                              <1> 
   276                              <1> ;29/04/2016
   277                              <1> Cluster_Index: ; resd 1
   278                              <1> ; 22/02/2016
   279 00018734 ????????            <1> ClusterValue:	resd 1
   280                              <1> ; 04/03/2016
   281 00018738 ??                  <1> Attributes:	resb 1
   282                              <1> ;;CFS_error:  resb 1 ;; 01/03/2016
   283 00018739 ??                  <1> resb 1
   284 0001873A ??                  <1> CFS_OPType: resb 1
   285 0001873B ??                  <1> CFS_Drv:    resb 1
   286 0001873C ????????            <1> CFS_CC:	    resd 1
   287 00018740 ????????            <1> CFS_FAT32FSINFOSEC: resd 1
   288 00018744 ????????            <1> CFS_FAT32FC: resd 1
   289                              <1> 
   290                              <1> ; 27/02/2016
   291                              <1> ;alignb 4
   292 00018748 ????????            <1> glc_prevcluster: resd 1 ; DRV_FAT.ASM (21/08/2011)
   293                              <1> ; 22/10/2016
   294 0001874C ????????            <1> glc_index:	 resd 1 ; Last Cluster Index (22/10/2016)
   295                              <1> 
   296                              <1> ; DIR.ASM
   297 00018750 ????                <1> DLN_EntryNumber: resw 1
   298 00018752 ??                  <1> DLN_40h:	 resb 1
   299                              <1> ; 28/02/2016
   300 00018753 ??                  <1> TCC_FATErr:	 resb 1 ; DRV_FAT.ASM
   301                              <1> 
   302                              <1> alignb 4
   303                              <1> ; DIR.ASM (09/10/2011)
   304 00018754 ????                <1> LCDE_EntryIndex: resw 1 ; LCDE_EntryOffset
   305 00018756 ????                <1> LCDE_ClusterSN:  resw 1
   306 00018758 ????????            <1> LCDE_Cluster: 	 resd 1
   307 0001875C ????????            <1> LCDE_ByteOffset: resd 1
   308                              <1> 
   309                              <1> ;alignb4
   310                              <1> ; 06/03/2016 (word -> dword)
   311                              <1> ; CMD_INTR.ASM (01/08/2010)
   312 00018760 ????????            <1> SourceFilePath:	     resd 1
   313 00018764 ????????            <1> DestinationFilePath: resd 1
   314                              <1> 
   315                              <1> ;alignb 4
   316                              <1> ; 06/03/2016
   317                              <1> ; FILE.ASM (09/10/2011)
   318                              <1> ;Source File Structure (same with 'Find File' Structure)
   319 00018768 ??                  <1> SourceFile_Drv:			resb 1
   320 00018769 <res 41h>           <1> SourceFile_Directory:		resb 65
   321 000187AA <res Dh>            <1> SourceFile_Name:		resb 13
   322                              <1> SourceFile_LongNameEntryLength: 
   323 000187B7 ??                  <1> SourceFile_LongNameYes:		resb 1 ; Sign for longname procedures
   324                              <1> ;Above 80 bytes
   325                              <1> ;is TR-DOS Source File FullName Format/Structure
   326 000187B8 ????                <1> SourceFile_AttributesMask:	resw 1
   327 000187BA <res 20h>           <1> SourceFile_DirEntry:		resb 32
   328 000187DA ????????            <1> SourceFile_DirFirstCluster:	resd 1
   329 000187DE ????????            <1> SourceFile_DirCluster:		resd 1
   330 000187E2 ????                <1> SourceFile_DirEntryNumber:	resw 1
   331 000187E4 ????                <1> SourceFile_MatchCounter:	resw 1
   332                              <1> ; 16/03/2016
   333 000187E6 ??                  <1> SourceFile_SecPerClust:		resb 1
   334 000187E7 ??                  <1> SourceFile_Reserved:		resb 1
   335                              <1> ; Above is 128 bytes
   336                              <1> 
   337                              <1> ;Destination File Structure (same with 'Find File' Structure)
   338 000187E8 ??                  <1> DestinationFile_Drv:		resb 1
   339 000187E9 <res 41h>           <1> DestinationFile_Directory: 	resb 65
   340 0001882A <res Dh>            <1> DestinationFile_Name:		resb 13
   341                              <1> DestinationFile_LongNameEntryLength:
   342 00018837 ??                  <1> DestinationFile_LongNameYes:	resb 1 ; Sign for longname procedures
   343                              <1> ;Above 80 bytes
   344                              <1> ;is TR-DOS Destination File FullName Format/Structure
   345 00018838 ????                <1> DestinationFile_AttributesMask: resw 1
   346 0001883A <res 20h>           <1> DestinationFile_DirEntry:	resb 32
   347 0001885A ????????            <1> DestinationFile_DirFirstCluster: resd 1
   348 0001885E ????????            <1> DestinationFile_DirCluster:	resd 1
   349 00018862 ????                <1> DestinationFile_DirEntryNumber: resw 1
   350 00018864 ????                <1> DestinationFile_MatchCounter:	resw 1
   351                              <1> ; 16/03/2016
   352 00018866 ??                  <1> DestinationFile_SecPerClust:	resb 1
   353 00018867 ??                  <1> DestinationFile_Reserved:	resb 1
   354                              <1> ; Above is 128 bytes
   355                              <1> 
   356                              <1> ; 24/04/2016
   357 00018868 ????                <1> resw 1
   358                              <1> 
   359                              <1> ; 10/03/2016
   360                              <1> ; FILE.ASM
   361 0001886A ??                  <1> move_cmd_phase:	   resb 1
   362 0001886B ??                  <1> msftdf_sf_df_drv:  resb 1
   363 0001886C ????????            <1> msftdf_drv_offset: resd 1
   364                              <1> 
   365                              <1> ; 11/03/2016
   366                              <1> ; DRV_FAT.ASM (21/08/2011)
   367 00018870 ????????            <1> FAT_anc_LCluster:  resd 1
   368 00018874 ????????            <1> FAT_anc_FFCluster: resd 1
   369                              <1> 
   370                              <1> ;alignb 4
   371                              <1> 
   372                              <1> ; 14/03/2016
   373                              <1> ; TRDOS 386 = TRDOS v2.0 feature only !
   374                              <1> ; 'allocate_memory_block' in 'memory.s'
   375 00018878 ????????            <1> mem_ipg_count:	resd 1 ; page count (for contiguous allocation)
   376 0001887C ????????            <1> mem_pg_count:	resd 1 ; page count (for count down)
   377 00018880 ????????            <1> mem_aperture:	resd 1 ; contiguous free pages (current)
   378 00018884 ????????            <1> mem_max_aperture: resd 1 ; maximum value of contiguous free pages
   379 00018888 ????????            <1> mem_pg_pos:	resd 1 ; mem. position (page #) of current aperture
   380 0001888C ????????            <1> mem_max_pg_pos: resd 1 ; mem. position (page #) of max. aperture
   381                              <1> 
   382                              <1> ; 15/03/2016
   383                              <1> ; FILE.ASM ('copy_source_file_to_destination_file')
   384 00018890 ??                  <1> copy_cmd_phase:       resb 1
   385 00018891 ??                  <1> csftdf_rw_err:	      resb 1
   386 00018892 ??                  <1> DestinationFileFound: resb 1
   387 00018893 ??                  <1> csftdf_cdrv: 	      resb 1
   388 00018894 ????????            <1> csftdf_filesize:      resd 1
   389                              <1> ; TRDOS386 (TRDOS v2.0)
   390 00018898 ????????            <1> csftdf_sf_mem_addr:   resd 1
   391 0001889C ????????            <1> csftdf_sf_mem_bsize:  resd 1
   392                              <1> ;
   393                              <1> 
   394 000188A0 ????????            <1> csftdf_sf_cluster:    resd 1 ; 16/03/2016
   395 000188A4 ????????            <1> csftdf_df_cluster:    resd 1
   396                              <1> ; 16/03/2016
   397 000188A8 ????????            <1> csftdf_r_size:        resd 1
   398 000188AC ????????            <1> csftdf_w_size:        resd 1
   399 000188B0 ????????            <1> csftdf_sf_rbytes:     resd 1
   400 000188B4 ????????            <1> csftdf_df_wbytes:     resd 1
   401 000188B8 ??                  <1> csftdf_percentage:    resb 1
   402                              <1> ; 17/03/2016
   403 000188B9 ??                  <1> csftdf_videopage:     resb 1
   404 000188BA ????                <1> csftdf_cursorpos:     resw 1
   405 000188BC ????????            <1> csftdf_sf_drv_dt:     resd 1
   406 000188C0 ????????            <1> csftdf_df_drv_dt:     resd 1
   407                              <1> ; 01/09/2024
   408                              <1> ; 29/08/2024
   409                              <1> ;csftdf_df_dclust:    resd 1
   410                              <1> ;csftdf_df_dindex:    resd 1
   411                              <1> 
   412                              <1> ; 21/03/2016
   413                              <1> ; 20/03/2016
   414                              <1> ; FILE.ASM
   415 000188C4 ????????            <1> createfile_Name_Offset:  resd 1
   416 000188C8 ????????            <1> createfile_FreeSectors:  resd 1
   417 000188CC ????????            <1> createfile_size:         resd 1
   418 000188D0 ????????            <1> createfile_FFCluster:    resd 1 ; 11/03/2016
   419 000188D4 ????????            <1> createfile_LastDirCluster: resd 1
   420 000188D8 ????????            <1> createfile_Cluster:      resd 1
   421 000188DC ????????            <1> createfile_PCluster:     resd 1
   422 000188E0 ??                  <1> createfile_attrib:	 resb 1
   423 000188E1 ??                  <1> createfile_SecPerClust:  resb 1
   424 000188E2 ????                <1> createfile_DirIndex:     resw 1
   425 000188E4 ????????            <1> createfile_CCount:	 resd 1
   426 000188E8 ????                <1> createfile_BytesPerSec:	 resw 1 ; 23/03/2016
   427 000188EA ??                  <1> createfile_wfc:	         resb 1
   428 000188EB ??                  <1> createfile_UpdatePDir:	 resb 1 ; 31/03/2016
   429                              <1> 
   430                              <1> ;alignb 4
   431                              <1> 
   432                              <1> ; 11/04/2016
   433 000188EC ????                <1> env_var_length:	resw 1
   434                              <1> 
   435 000188EE ????                <1> alignb 4
   436                              <1> 
   437                              <1> ; 25/04/2016
   438 000188F0 ??                  <1> readi.valid:	resb 1 ; valid data (>0 = valid for readi)
   439 000188F1 ??                  <1> readi.drv:	resb 1 ; drive number (0, 1,2,3,4..)
   440 000188F2 ??                  <1> readi.spc:	resb 1 ; sectors per cluster for 'readi' drive
   441 000188F3 ??                  <1> readi.s_index:  resb 1 ; sector index in current cluster (buffer)
   442 000188F4 ????????            <1> readi.sector:	resd 1 ; current disk sector
   443 000188F8 ????                <1> readi.bpc:	resw 1 ; bytes per cluster - 1
   444 000188FA ????                <1> readi.offset:	resw 1 ; byte offset in cluster buffer
   445 000188FC ????????            <1> readi.cluster:  resd 1 ; current cluster number
   446 00018900 ????????            <1> readi.c_index:	resd 1 ; cluster index of the current cluster (0,1,2,3..)
   447 00018904 ????????            <1> readi.fclust:	resd 1 ; first cluster of the current cluster
   448 00018908 ????????            <1> readi.fs_index: resd 1 ; sector index in disk/file section (for Singlix FS)
   449                              <1> ;readi.buffer:	resd 1 ; readi sector buffer address
   450                              <1> 
   451                              <1> ;alignb 4
   452                              <1> 
   453 0001890C ??                  <1> writei.valid:	resb 1 ; valid data (>0 = valid for writei)
   454 0001890D ??                  <1> writei.drv:	resb 1 ; drive number (0, 1,2,3,4..)
   455 0001890E ??                  <1> writei.spc:	resb 1 ; sectors per cluster for 'writei' drive
   456 0001890F ??                  <1> writei.s_index: resb 1 ; sector index in current cluster (buffer)
   457 00018910 ????????            <1> writei.sector:	resd 1 ; current disk sector
   458 00018914 ????                <1> writei.bpc:	resw 1 ; bytes per cluster - 1
   459 00018916 ????                <1> writei.offset:	resw 1 ; byte offset in cluster buffer
   460 00018918 ????????            <1> writei.cluster: resd 1 ; current cluster number
   461 0001891C ????????            <1> writei.c_index:	resd 1 ; cluster index of the current cluster (0,1,2,3..)
   462 00018920 ????????            <1> writei.fclust:  resd 1 ; first cluster of the current cluster
   463 00018924 ????????            <1> writei.fs_index: resd 1 ; sector index in disk/file section (for Singlix FS)
   464                              <1> ;writei.buffer:	resd 1 ; writei sector buffer address
   465 00018928 ????????            <1> writei.lclust:	resd 1 ; writei last cluster (mget_w) ; 23/10/2016
   466 0001892C ????????            <1> writei.l_index:	resd 1 ; writei last cluster index (mget_w) ; 23/10/2016
   467 00018930 ??                  <1> writei.ofn:	resb 1 ; open file number (to be written) ; 23/10/2016
   468                              <1> 
   469 00018931 ??????              <1> alignb 4
   470                              <1> 
   471                              <1> ; 29/04/2016
   472 00018934 ????????            <1> Run_CDirFC:	resd 1
   473 00018938 ??                  <1> Run_Auto_Path:	resb 1
   474 00018939 ??                  <1> Run_Manual_Path: resb 1 ; 0 -> auto path sequence needed
   475 0001893A ??                  <1> EXE_ID:		resb 1
   476 0001893B ??                  <1> EXE_dot:	resb 1
   477                              <1> 
   478                              <1> ; 06/05/2016
   479 0001893C ????????            <1> mainprog_return_addr: resd 1
   480 00018940 ????????            <1> last_error:	resd 1  ; this will be used to return error code to MainProg
   481                              <1> 			; 'lasterror' keyword will be used later to get the
   482                              <1> 			; last error code/number/status.
   483                              <1> ; 12/05/2016
   484 00018944 ????????            <1> video_eax:	resd 1  ; eax return value of video function
   485                              <1> 
   486                              <1> ; 01/06/2016
   487 00018948 ????????            <1> user_buffer:	resd 1  ; 'diskio.s' (INT 33h, Function 08h, floppy disk type)
   488                              <1> 
   489                              <1> ; 21/05/2016 - TRDOS 386 ('swap/switch', 'rswap', [u.pri])
   490 0001894C ??                  <1> priority:	resb 1  ; running priority level of process (0,1,2)
   491                              <1> 			; (run queue which is process comes from)
   492                              <1> ; 22/05/2016 - TRDOS 386 ('set_run_sequence', 'rtc_int', 'u_timer')
   493 0001894D ??                  <1> p_change:	resb 1  ; process change status (for timer events)
   494                              <1> ; 23/05/2016 - TRDOS 386 ('clock')
   495 0001894E ??                  <1> multi_tasking:	resb 1   ; Multi Tasking status (0 = disabled, >0 = enabled)
   496                              <1> 			; (EBX will return with user buffer addr or disk type)
   497                              <1> ; 07/06/2016
   498 0001894F ??                  <1> timer_events:	resb 1  ; number of (active) timer events, <= 16
   499                              <1> 
   500                              <1> ; 24/06/2016
   501 00018950 ??                  <1> w_str_cmd:	resb 1	; WRITE_STRING command (0,1,2,3) ; video.s
   502 00018951 ??                  <1> p_crt_mode:	resb 1  ; previous video mode (=3 or 0), backup mark/sign
   503                              <1> ; 26/06/2016
   504 00018952 ??                  <1> p_crt_page:	resb 1  ; previous active page (for 'set_mode')
   505                              <1> ; 04/07/2016
   506 00018953 ??                  <1> noclearmem:	resb 1  ; if set, 'SET MODE' (INT 31h) function (AH = 4)
   507                              <1> 			; will not clear the video memory
   508                              <1> 			; (usable for graphics modes only)
   509                              <1> alignb 2
   510 00018954 ????                <1> CRT_LEN:	resw 1  ; length of regen buffer in bytes
   511 00018956 <res 10h>           <1> cursor_pposn:	resw 8  ; cursor positions backup
   512                              <1> 
   513                              <1> ; 10/07/2016 ('VGA_FONT_SETUP', INT 43H address for x86 real mode bios)
   514 00018966 ????????            <1> VGA_INT43H:	resd 1	; 0 = default (not configured by user)
   515                              <1> 			; 0FFFFFFFFh = user defined fonts
   516                              <1> 			; address:
   517                              <1> 			; 	vgafont8
   518                              <1> 			; 	vgafont16
   519                              <1> 			; 	vgafont14
   520                              <1> 
   521                              <1> ; 25/07/2016
   522 0001896A ??                  <1> VGA_MTYPE:	resb 1  ; 0=CTEXT,1=MTEXT,2=CGA,3=PLANAR1,4=PLANAR4,5=LINEAR
   523                              <1> 
   524                              <1> ; 23/10/2016
   525 0001896B ??                  <1> setfmod:	resb 1	; update last modification date&time sign (if >0)
   526                              <1> 			; (it is Open File Number + 1, if > 0)
   527                              <1> ; 27/08/2024
   528 0001896C ??                  <1> setfclust:	resb 1  ; first cluster of file
   529                              <1> 			; (is used by update lmdt proc)
   530 0001896D ??????              <1> alignb 4
   531                              <1> 
   532                              <1> ; 16/10/2016
   533 00018970 ????????            <1> FFF_UBuffer:	resd 1  ; User's buffer address for FFF & FNF system calls
   534                              <1> ; 15/10/2016
   535 00018974 ??                  <1> FFF_Valid:	resb 1  ; Find First File Structure validation byte
   536                              <1> 			; 0  = invalid (Find Next File can't use FFF struct)
   537                              <1> 			; >0 = valid, return type for FFF and Find Next File
   538                              <1> 			; 24 = basic parameters, 24 bytes
   539                              <1> 			; 128 = entire FFF structure/table, 128 bytes
   540                              <1> ; 16/10/2016 (FFF_Attrib: resw 1)
   541 00018975 ??                  <1> FFF_Attrib:	resb 1	; Find First File attributes for Find Next File (LB)
   542 00018976 ??                  <1> FFF_RType:	resb 1  ; FFF return type (0 = Basic, >0 = complete) (HB)
   543                              <1> ; 16/10/2016 - 05/10/2016 (Set Working Path)
   544 00018977 ??                  <1> SWP_inv_fname:	resb 1	; Set Working Path - Invalid File Name
   545 00018978 ????                <1> SWP_Mode:	resw 1	; Set Working Path - Mode
   546 0001897A ??                  <1> SWP_DRV:	resb 1	; Set Working Path - Drive
   547 0001897B ??                  <1> SWP_DRV_chg:	resb 1	; Set Working Path - Drive Change
   548                              <1> 
   549                              <1> ; 27/02/2017
   550 0001897C ??                  <1> fpready:	resb 1	; '80387 fpu is ready' flag
   551                              <1> 
   552                              <1> ; 17/04/2021
   553                              <1> ; (DEVICE parameters is disabled as temporary)
   554                              <1> 
   555                              <1> ; 08/10/2016
   556                              <1> ;device_name:	resb 9  ; capitalized (and zero padded) device name
   557                              <1> 			; (example: "TTY0",0,0,0,0,0")
   558                              <1> 
   559 0001897D ??????              <1> alignb 4
   560                              <1> 
   561                              <1> ; 08/10/2016
   562                              <1> ; 07/10/2016
   563                              <1> ; Table of kernel devices (which do not use installable device drivers)
   564                              <1> ; has been coded into KERNEL (trdosk9.s)
   565                              <1> ; 07/10/2016
   566                              <1> ; 8 installable device drivers available to install (NUMIDEV)
   567                              <1> ;IDEV_PGDIR: resd NUMIDEV
   568                              <1> 			; Page directories of installable device drivers
   569                              <1> 			;
   570                              <1> 			; Note: Virtual start address is always 400000h
   571                              <1> 			; (end of the 1st 4MB). [org 400000h]
   572                              <1> 			; Segments: KCODE, KDATA
   573                              <1> 			; Method: call 400000h (after changing page dir)
   574                              <1> 			; Query code located at the start (400000h).
   575                              <1> 			; Query code returns with
   576                              <1> 			;   eax = device type and driver version
   577                              <1> 			;         AL = Device Type minor
   578                              <1> 			;         AH = Device Type major
   579                              <1> 			;         Byte 16-23 : Version minor
   580                              <1> 			;	  Byte 24-31 : Version major - 1
   581                              <1> 			;		       (0:0 -> 1.0)
   582                              <1> 			;   ebx = initialization code address
   583                              <1> 			;   ecx = configuration table address
   584                              <1> 			;   edx = description table address
   585                              <1> 			;   esi = device (default) name address (ASCIIZ)
   586                              <1> 			;	 (name has "/DEV/" prefix)
   587                              <1> 			;   edi = dispatch table address
   588                              <1> 			;        (for calling kernel-device functions)
   589                              <1> 			;   ebp = address table address
   590                              <1> 			; Initialization code returns with
   591                              <1> 			;   eax = open code address
   592                              <1> 			;   ecx = close code address
   593                              <1> 			;   ebx = read code address
   594                              <1> 			;   edx = write code address
   595                              <1> 			;   esi = IOCTL code address
   596                              <1> 			;   edi = dispatch table address
   597                              <1> 			;   ebp = address table address
   598                              <1> 			; Address Table:
   599                              <1> 			;    Offset 0  : open code address
   600                              <1> 			;    Offset 4  : read code address
   601                              <1> 			;    Offset 8  : write code address
   602                              <1> 			;    Offset 12 : close code address
   603                              <1> 			;    Offset 16 : IOCTL code address
   604                              <1> 			;    Offset 20 : initialization code address
   605                              <1> 			;    Offset 24 : description table address
   606                              <1> 			;    Offset 28 : configuration table address
   607                              <1> 			;    Offset 32 : device name address
   608                              <1> 			;    Offset 36 : dispatch table address
   609                              <1> 			;          (for calling kernel-device functions)
   610                              <1> 
   611                              <1> ;IDEV_NAME:  resb 8*NUMIDEV
   612                              <1> 			  ; 8 byte names of installable device drivers
   613                              <1> 
   614                              <1> ;IDEV_TYPE:  resb NUMIDEV ; Driver type of installable device drivers
   615                              <1> ;IDEV_FLAGS: resb NUMIDEV ; Device access parameters for installable
   616                              <1>                           ; device drivers (These values are set while
   617                              <1> 			  ; the device driver is being loaded.)
   618                              <1> ;IDEV_OADDR: resd NUMIDEV ; open function addr for installable dev driver
   619                              <1> ;IDEV_CADDR: resd NUMIDEV ; close function addr for installable dev driver
   620                              <1> ;IDEV_RADDR: resd NUMIDEV ; read function addr for installable dev driver
   621                              <1> ;IDEV_WADDR: resd NUMIDEV ; write function addr for installable dev driver
   622                              <1> 
   623                              <1> ; 08/10/2016
   624                              <1> ; 07/10/2016
   625                              <1> ; Device Open and Access parameters
   626                              <1> ;DEV_ACCESS:	resb NUMOFDEVICES    ; bit 0 = accessable by normal users
   627                              <1> 				     ; bit 1 = read access permission
   628                              <1> 				     ; bit 2 = write access permission
   629                              <1> 				     ; bit 3 = IOCTL permission to users
   630                              <1> 				     ; bit 4 = block device if it is set
   631                              <1> 				     ; bit 5 = 16 bit or 1024 byte data
   632                              <1> 				     ; bit 6 = 32 bit or 2048 byte data
   633                              <1> 				     ; bit 7 = installable device driver
   634                              <1> ;DEV_R_OWNER:	resb NUMOFDEVICES    ; Reading owner no (u.uid) of devices
   635                              <1> ;DEV_R_OPENCOUNT: resb NUMOFDEVICES  ; Reading open count
   636                              <1> ;DEV_W_OWNER:	resb NUMOFDEVICES    ; Writing owner no (u.uid) of devices
   637                              <1> ;DEV_W_OPENCOUNT: resb NUMOFDEVICES  ; Writing open count
   638                              <1> ;DEV_DRIVER:	resb NUMOFDEVICES    ; device driver number (1 to 7Fh)
   639                              <1> 				     ; *if bit 7 is set (80 to FFh)
   640                              <1> 				     ; *if it is installable device driver
   641                              <1> 				     ; *index (0 to 7Fh)
   642                              <1> 				     ; otherwise it is kernel device index
   643                              <1> ;DEV_OPENMODE:	resb NUMOFDEVICES    ; 1 = read mode
   644                              <1> 				     ; 2 = write mode
   645                              <1> 				     ; 3 = read & write
   646                              <1> 				     ; 0 = not open (free)
   647                              <1> ;DEV_NAME_PTR:	resd NUMOFDEVICES    ; pointers to name addresses of drivers
   648                              <1> 				     ; Address base: KDEV_NAME+
   649                              <1> 				     ; or IDEV_NAME+
   650                              <1> ;DEV_R_POINTER:	resd NUMOFDEVICES    ; reading pointer, writing pointer
   651                              <1> ;DEV_W_POINTER:	resd NUMOFDEVICES    ; sector number if block device
   652                              <1> 				     ; character offset if char device
   653                              <1> alignb 4
   654                              <1> 
   655                              <1> ; 06/10/2016
   656                              <1> ; Open File Parameters
   657 00018980 <res 80h>           <1> OF_FCLUSTER:	resd OPENFILES  ; First clusters of open files
   658 00018A00 <res 20h>           <1> OF_DRIVE:	resb OPENFILES  ; Logical DOS drive numbers of open files
   659 00018A20 <res 20h>           <1> OF_MODE:	resb OPENFILES  ; Open mode (1 = read, 2 = write, 3 = r&w)
   660 00018A40 <res 20h>           <1> OF_STATUS:	resb OPENFILES  ; (bit 0 = read, bit 1 = write)
   661 00018A60 <res 20h>           <1> OF_OPENCOUNT:	resb OPENFILES  ; Open counts of open files
   662 00018A80 <res 80h>           <1> OF_POINTER:	resd OPENFILES	; File seek/read/write pointer
   663 00018B00 <res 80h>           <1> OF_SIZE:	resd OPENFILES	; File sizes of open files (in bytes)
   664 00018B80 <res 80h>           <1> OF_DIRFCLUSTER:	resd OPENFILES  ; Directory First Clusters of open files
   665 00018C00 <res 80h>           <1> OF_DIRCLUSTER:	resd OPENFILES  ; Directory (Entry) Clusters of open files
   666 00018C80 <res 80h>           <1> OF_VOLUMEID:	resd OPENFILES  ; Vol ID for removable drives of open files
   667 00018D00 <res 80h>           <1> OF_CCLUSTER:	resd OPENFILES  ; Current clusters of open files
   668 00018D80 <res 80h>           <1> OF_CCINDEX:	resd OPENFILES  ; Cluster index numbers of current clusters
   669                              <1> ; 24/10/2016
   670 00018E00 <res 40h>           <1> OF_DIRENTRY:	resw OPENFILES  ; Directory entry index no. in dir cluster
   671                              <1> 				; Sector index = entry index / 16
   672                              <1> ;alignb 2
   673                              <1> 
   674                              <1> DTA:		;resd 24	; Find First File data transfer area
   675 00018E40 <res 18h>           <1> 		resb 24		; 29/07/2022
   676                              <1> 
   677                              <1> ; 19/12/2016
   678 00018E58 ??                  <1> tcallback:	resb 1		; Timer callback method flag for 'systimer'
   679 00018E59 ??                  <1> trtc:		resb 1		; Timer interrupt type flag for 'systimer'
   680                              <1> ; 20/02/2017
   681 00018E5A ??                  <1> no_page_swap:	resb 1		; Swap lock for Signal Response Byte pages
   682                              <1> ;;15/01/2017
   683                              <1> ; 02/01/2017
   684                              <1> ;;intflg:	resb 1		; software interrupt in progress signal
   685                              <1> 				; (for timer interrupt)
   686 00018E5B ??                  <1> alignb 4
   687                              <1> ; 13/04/2017
   688                              <1> ;DEV_INTR:	resb NUMOFDEVICES ; Device Interrupt (IRQ) number + 1
   689                              <1> 				; (0= not available, 1= IRQ 0, 16= IRQ 15)
   690 00018E5C <res 40h>           <1> DEV_INT_HNDLR:	resd 16		; Device Interrupt Handler addr, if > 0
   691                              <1> 
   692                              <1> ;alignb 4
   693                              <1> 
   694                              <1> ; 26/02/2017 ; IRQ Callback parameters ('syscalbac')
   695                              <1> ;Index: ; 0 to 8
   696                              <1> ;	0 = IRQ3, 1 = IRQ4, 2 = IRQ5, 3 = IRQ7
   697                              <1> ;	4 = IRQ9, 5 = IRQ10, 6 = IRQ11, 7 = IRQ12, 8 = IRQ13  
   698 00018E9C <res 9h>            <1> IRQ.owner:	resb 9		; owner, 0 = free, >0 = [u.uno]
   699 00018EA5 <res 9h>            <1> IRQ.dev:	resb 9		; 0 = default/kernel, >0 = device number
   700 00018EAE <res 9h>            <1> IRQ.method:	resb 9 		; 0 = Signal Response Byte, 1 = Callback
   701 00018EB7 <res 9h>            <1> IRQ.srb:	resb 9 		; Signal Response/Return Byte value
   702 00018EC0 <res 24h>           <1> IRQ.addr:	resd 9		; Rignal Response Byte address (physical)
   703                              <1> 				; or Callback service address (virtual)
   704                              <1> ; 28/02/2017
   705 00018EE4 ????????            <1> IRQ_cr3:	resd 1		; for saving cr3 register in IRQ handler
   706 00018EE8 ??                  <1> IRQnum:		resb 1		; IRQ number for IRQ handler (trdosk8.s)
   707                              <1> 
   708                              <1> ; 10/04/2017
   709                              <1> ; 03/04/2017
   710                              <1> ; UNINITIALIZED AUDIO DATA
   711 00018EE9 ??????              <1> alignb 4
   712 00018EEC ??                  <1> audio_pci:	resb 1
   713 00018EED ??                  <1> audio_device:	resb 1
   714                              <1> ;audio_mode:	resb 1
   715 00018EEE ??                  <1> audio_intr:	resb 1
   716 00018EEF ??                  <1> audio_busy:	resb 1  ; Busy flag for audio irq ; 21/04/2017
   717                              <1> ;audio_reserved: resb 1
   718                              <1> ; 20/11/2023
   719 00018EF0 ????                <1> NAMBAR:		resw 1	; Native Audio Mixer Base Address
   720                              <1> NABMBAR:	; 02/10/2023 (NABMBAR = audio_io_base)
   721 00018EF2 ????                <1> audio_io_base:	resw 1 	; Base I/O address of audio device
   722 00018EF4 ????????            <1> audio_dev_id:	resd 1	; BUS/DEV/FN ; 00000000BBBBBBBBDDDDDFFF00000000
   723 00018EF8 ????????            <1> audio_vendor:	resd 1
   724 00018EFC ????????            <1> audio_stats_cmd: resd 1
   725                              <1> ;
   726 00018F00 ????????            <1> audio_buffer:	resd 1	; virtual address of user's audio buffer
   727 00018F04 ????????            <1> audio_p_buffer:	resd 1	; Physical address of user's audio buffer
   728 00018F08 ????????            <1> audio_buff_size: resd 1 ; user's audio buffer size (half buffer size)
   729 00018F0C ????????            <1> audio_dma_buff: resd 1  ; dma buffer address
   730 00018F10 ????????            <1> audio_dmabuff_size: resd 1 ; dma buffer size (2 * half buffer size)
   731                              <1> ; 05/06/2024
   732 00018F14 ????????            <1> dma_hbuff_size: resd 1 ; dma half buffer size
   733                              <1> ;
   734 00018F18 ??                  <1> audio_flag:	resb 1  ; dma buffer flag (1st half = 0, 2nd half = 1)
   735 00018F19 ??                  <1> audio_user:	resb 1	; user number of the owner
   736 00018F1A ??                  <1> audio_cb_mode:	resb 1	; 0 = signal response byte method
   737                              <1> 			; 1 = callback method
   738                              <1> 			; 2 = s.r.b. method with auto increment
   739 00018F1B ??                  <1> audio_srb:	resb 1	; signal response byte value
   740 00018F1C ????????            <1> audio_cb_addr:	resd 1  ; callback service address or s.r.b. address
   741                              <1> 			; (s.r.b. addr is physical, cbs addr is virtual)
   742                              <1> 
   743 00018F20 ??                  <1> audio_bps:	resb 1  ; selected mode: 8 bit, 16 bit
   744 00018F21 ??                  <1> audio_stmo:	resb 1	; selected mode: mono /stereo
   745 00018F22 ????                <1> audio_freq: 	resw 1	; sampling rate
   746                              <1> ; 20/11/2023
   747 00018F24 ??                  <1> VRA:		resb 1
   748 00018F25 ??                  <1> audio_mode:	resb 1
   749                              <1> 
   750                              <1> ; 21/04/2017
   751 00018F26 ??                  <1> audio_play_cmd: resb 1  ; Play/Stop command (1 = play, 0 = stop)
   752                              <1> ; 21/11/2023
   753                              <1> ;audio_civ: ; 28/05/2017 ; Current Buffer Index (AC'97)
   754                              <1> ; 23/05/2024
   755                              <1> LVI:			; AC'97 Last Valid Buffer Index
   756 00018F27 ??                  <1> audio_flag_eol:	resb 1  ; End of Link status (vt8233, EOL/FLAG)
   757                              <1> 
   758                              <1> audio_master_volume:
   759 00018F28 ??                  <1> audio_master_volume_l: resb 1 ; sound volume (lineout) left channel
   760 00018F29 ??                  <1> audio_master_volume_r: resb 1 ; sound volume (lineout) right channel
   761                              <1> 
   762                              <1> ; 24/05/2024
   763                              <1> audio_pcmo_volume:
   764 00018F2A ??                  <1> audio_pcmo_volume_l: resb 1 ; PCM out volume left channel
   765 00018F2B ??                  <1> audio_pcmo_volume_r: resb 1 ; PCM out volume right channel
   766                              <1> 
   767                              <1> ; 02/06/2024
   768                              <1> ;alignb 4
   769                              <1> 
   770                              <1> ; 20/11/2023
   771                              <1> ; 28/05/2017
   772                              <1> ; AC'97 Audio Controller Base Adress Registers
   773                              <1> ;NAMBAR:	resw 1	; Native Audio Mixer Base Address
   774                              <1> ;NABMBAR:	resw 1	; Native Audio Bus Mastering Base Address
   775                              <1> 
   776                              <1> ; 02/06/2024
   777 00018F2C ????????            <1> alignb 8
   778                              <1> 
   779                              <1> ; 21/04/2017
   780 00018F30 <res 400h>          <1> audio_bdl_buff:	resd 32*8 ; VT8233 (AC97) BDL Buffer Size
   781                              <1> ; 12/05/2017
   782 00019330 ????????            <1> base_addr:	resd 1	; 'direct_memory_access' (memory.s)
   783                              <1> 
   784                              <1> ; 01/06/2024
   785 00019334 ??                  <1> reset:		resb 1	; AC97 init
   786                              <1> 
   787                              <1> ; 28/08/2017
   788                              <1> ; 20/08/2017
   789                              <1> 		;resb 1 ;
   790 00019335 ??                  <1> dma_user:	resb 1	; user number for sysdma
   791 00019336 ??                  <1> dma_channel:	resb 1	; dma channel for sysdma
   792 00019337 ??                  <1> dma_mode:	resb 1  ; dma mode for sysdma
   793 00019338 ????????            <1> dma_addr:	resd 1	; dma buffer physical addr for sysdma
   794 0001933C ????????            <1> dma_size:	resd 1  ; dma buffer size (in bytes) for sysdma
   795 00019340 ????????            <1> dma_start:	resd 1  ; dma start address for sysdma
   796 00019344 ????????            <1> dma_count:	resd 1  ; dma count (in bytes) for sysdma
   797                              <1> 
   798                              <1> ; 04/12/2023
   799                              <1> %if 0
   800                              <1> 
   801                              <1> alignb 65536
   802                              <1> ; 09/08/2017
   803                              <1> ; 12/05/2017
   804                              <1> sb16_dma_buffer: resb 65536 ; DMA buffer for sb16 audio playing.
   805                              <1> 
   806                              <1> %endif
  4001                                  ; 24/01/2016
  4002                                  %include 'ubss.s'	; UNINITIALIZED KERNEL (USER) DATA
     1                              <1> ; ****************************************************************************
     2                              <1> ; TRDOS386.ASM (TRDOS 386 Kernel - v2.0.9) - UNINITIALIZED USER DATA : ubss.s
     3                              <1> ; ----------------------------------------------------------------------------
     4                              <1> ; Last Update: 19/08/2024  (Previous: 07/08/2022)
     5                              <1> ; ----------------------------------------------------------------------------
     6                              <1> ; Beginning: 24/01/2016
     7                              <1> ; ----------------------------------------------------------------------------
     8                              <1> ; Assembler: NASM version 2.15 (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> ; Ref: Retro UNIX 386 v1.2 Kernel (v0.2.2.3) - ux.s - 15/07/2022
    29                              <1> 
    30                              <1> alignb 2
    31                              <1> 
    32                              <1> %if 0
    33                              <1> 
    34                              <1> inode:
    35                              <1> 	;; 11/03/2013. 
    36                              <1> 	;;Derived from UNIX v1 source code 'inode' structure (ux).
    37                              <1> 	;;i.
    38                              <1> 	;
    39                              <1> 	;i.flgs: resw 1
    40                              <1> 	;i.nlks: resb 1
    41                              <1> 	;i.uid:	 resb 1
    42                              <1>         ;i.size: resw 1 ; size
    43                              <1> 	;i.dskp: resw 8 ; 16 bytes
    44                              <1> 	;i.ctim: resd 1
    45                              <1> 	;i.mtim: resd 1
    46                              <1> 	;i.rsvd: resw 1 ; Reserved (ZERO/Undefined word for UNIX v1)
    47                              <1> 
    48                              <1> 	; 26/01/2020
    49                              <1> 	; Retro UNIX 386 v2.0 - Modified UNIX v7 inode model
    50                              <1> 	;	(15/09/2029 .. 18/12/2019)
    51                              <1> 
    52                              <1> 	i.flgs:   resw 1	; /* mode and type of file */
    53                              <1> 	i.nlks:	  resw 1	; /* number of links to file */
    54                              <1> 	i.uid:	  resw 1	; /* owner's user id */  - 0 to 65535 -
    55                              <1> 	i.gid:	  resb 1	; /* owner's group id */ - o to 255 -
    56                              <1> 	i.size_h: resb 1	; /* number of bytes in file */ ; byte 5
    57                              <1> 	i.size:	  resd 1 ; size	; /* number of bytes in file */
    58                              <1> 	i.dskp:	  resd 10 ; 40 bytes ; /* disk block addresses */
    59                              <1> 	i.atim:	  resd 1	; /* time last accessed */
    60                              <1> 	i.mtim:	  resd 1	; /* time last modified */
    61                              <1> 	i.ctim:	  resd 1	; /* time created */
    62                              <1> 
    63                              <1> I_SIZE	equ $ - inode
    64                              <1> 
    65                              <1> %endif 
    66                              <1> 
    67                              <1> process:
    68                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5 
    69                              <1> 	; 27/02/2022
    70                              <1> 	; 12/01/2022 - Retro UNIX 386 v1.2 
    71                              <1> 	; 19/12/2016
    72                              <1> 	; 21/05/2016
    73                              <1> 	; 19/05/2016 - TRDOS 386 (TRDOS v2.0)
    74                              <1> 	; 06/05/2015 - Retro UNIX 386 v1
    75                              <1> 	; 11/03/2013 - 05/02/2014 (Retro UNIX 8086 v1)
    76                              <1> 	;Derived from UNIX v1 source code 'proc' structure (ux).
    77                              <1> 	;p.
    78                              <1> 	
    79 00019348 <res 20h>           <1>         p.pid:   resw nproc
    80 00019368 <res 20h>           <1>         p.ppid:  resw nproc
    81                              <1> 	;p.break: resw nproc ; 12/01/2022 (p.break is not used)
    82 00019388 <res 10h>           <1>         p.ttyc:  resb nproc ; console tty in Retro UNIX 8086 v1.
    83                              <1> 	; 27/02/2022 (p.waitc is not used)
    84                              <1> 	;p.waitc: resb nproc ; waiting channel in Retro UNIX 8086 v1.
    85 00019398 <res 10h>           <1> 	p.link:	 resb nproc
    86 000193A8 <res 10h>           <1> 	p.stat:	 resb nproc
    87                              <1> 
    88                              <1> 	; 06/05/2015 (Retro UNIX 386 v1 feature only !) 
    89 000193B8 <res 40h>           <1> 	p.upage: resd nproc ; Physical address of the process's
    90                              <1> 			    ; 'user' structure
    91                              <1> 	; 21/05/2016
    92                              <1> 	; 19/05/2016 (TRDOS 386 feature only!)
    93 000193F8 <res 10h>           <1> 	p.timer: resb nproc ; number of timer events of the processs
    94                              <1> 
    95                              <1> 	; 19/12/2016
    96 00019408 <res 40h>           <1> 	p.tcb:	resd nproc ; timer callback service address (if > 0)
    97                              <1> 
    98                              <1> 	; 18/08/2024 (TRDOS 386 v2.0.9)
    99 00019448 <res 10h>           <1> 	p.exitc: resb nproc ; exit code of the child
   100                              <1> 
   101                              <1> P_SIZE	equ $ - process
   102                              <1> 
   103                              <1> ; fsp table (original UNIX v1)
   104                              <1> ;
   105                              <1> ;Entry
   106                              <1> ;          15                                      0
   107                              <1> ;  1     |---|---------------------------------------|
   108                              <1> ;        |r/w|       i-number of open file           |
   109                              <1> ;        |---|---------------------------------------|
   110                              <1> ;        |               device number               |
   111                              <1> ;        |-------------------------------------------|
   112                              <1> ;    (*) | offset pointer, i.e., r/w pointer to file |
   113                              <1> ;        |-------------------------------------------|
   114                              <1> ;        |  flag that says    | number of processes  |
   115                              <1> ;        |   file deleted     | that have file open  |
   116                              <1> ;        |-------------------------------------------|
   117                              <1> ;  2     |                                           |
   118                              <1> ;        |-------------------------------------------|
   119                              <1> ;        |                                           |
   120                              <1> ;        |-------------------------------------------|
   121                              <1> ;        |                                           |
   122                              <1> ;        |-------------------------------------------|
   123                              <1> ;        |                                           |
   124                              <1> ;        |-------------------------------------------|
   125                              <1> ;  3     |                                           |
   126                              <1> ;        |                                           |
   127                              <1> ;
   128                              <1> ; (*) Retro UNIX 386 v1 modification: 32 bit offset pointer
   129                              <1> 
   130                              <1> ; 27/03/2020 - Retro UNIX 386 v2 - FSP (OPEN FILES) TABLE
   131                              <1> 
   132                              <1> ;Entry
   133                              <1> ;         15                    7                   0
   134                              <1> ;  1     |-------------------------------------------|
   135                              <1> ;        |   	     i-number of open file           |
   136                              <1> ;        |-------------------------------------------|
   137                              <1> ;        |        high word of 32 bit i-number       |
   138                              <1> ;        |-------------------------------------------|
   139                              <1> ;        | open mode & status  |   device number     |
   140                              <1> ;        |-------------------------------------------|
   141                              <1> ;        |    reserved byte    |     open count      |
   142                              <1> ;        |-------------------------------------------|
   143                              <1> ;        | offset pointer, i.e., r/w pointer to file |
   144                              <1> ;        |-------------------------------------------|
   145                              <1> ;        |   64 bit file offset pointer (bit 16-31)  |
   146                              <1> ;        |-------------------------------------------|
   147                              <1> ;        |   64 bit file offset pointer (bit 32-47)  |
   148                              <1> ;        |-------------------------------------------|
   149                              <1> ;        |   64 bit file offset pointer (bit 48-63)  |
   150                              <1> ;        |-------------------------------------------|
   151                              <1> ;  2     |                                           |
   152                              <1> ;        |-------------------------------------------|
   153                              <1> ;        |                                           |
   154                              <1> ;        |-------------------------------------------|
   155                              <1> ;        |                                           |
   156                              <1> ;        |-------------------------------------------|
   157                              <1> ;        |                                           |
   158                              <1> ;        |-------------------------------------------|
   159                              <1> ;        |                                           |
   160                              <1> 
   161                              <1> %if 0
   162                              <1> 
   163                              <1> ; (Retro UNIX 386 v1.2 - ux.s - 15/07/2022)
   164                              <1> ; 22/11/2021
   165                              <1> ; 21/07/2021 - Retro UNIX 386 v2 open file structure revision
   166                              <1> 
   167                              <1> struc file	; open files (fsp) structure ; (*)
   168                              <1>   .inode:  resw 1  ; inode number of open file (32 bit)
   169                              <1>   .i32:	   resw 1  ; higher word of inode number (reserved)
   170                              <1>   .drive:  resb 1  ; logical drive (disk) number
   171                              <1>   .flags:  resb 1  ; open mode and status
   172                              <1>   .count:  resb 1  ; number of processes that have file open
   173                              <1>   ;.rsvd:  resb 1  ; reserved byte (for next versions)
   174                              <1>   .mnt:    resb 1  ; mnttab index+1 (0 = not mounted)
   175                              <1>   .offset: resd 1  ; file offset/pointer (64 bit)
   176                              <1>   .o64:	   resd 1  ; higher 32 bit of file offset
   177                              <1>  .size:  ; = 16
   178                              <1> endstruc 
   179                              <1> 
   180                              <1> %endif
   181                              <1> 
   182                              <1> ; 23/07/2022
   183                              <1> ;fsp:	resb nfiles * 16 ; (*)
   184                              <1> 
   185 00019458 ??                  <1> idev:	resb 1
   186 00019459 ??                  <1> cdev:	resb 1	
   187                              <1> 
   188                              <1> ; 15/04/2015
   189                              <1> ;fsp:	resb nfiles * 10 ; 11/05/2015 (8 -> 10)
   190                              <1> ;idev:	resw 1 ; device number is 1 byte in Retro UNIX 8086 v1 !
   191                              <1> ;cdev:	resw 1 ; device number is 1 byte in Retro UNIX 8086 v1 !
   192                              <1> 
   193                              <1> ; 18/05/2015
   194                              <1> ; 26/04/2013 device/drive parameters (Retro UNIX 8086 v1 feature only!)
   195                              <1> ; 'UNIX' device numbers (as in 'cdev' and 'u.cdrv')
   196                              <1> ;	0 -> root device (which has Retro UNIX 8086 v1 file system)
   197                              <1> ; 	1 -> mounted device (which has Retro UNIX 8086 v1 file system)
   198                              <1> ; 'Retro UNIX 8086 v1' device numbers: (for disk I/O procedures)
   199                              <1> ;	0 -> fd0 (physical drive, floppy disk 1), physical drive number = 0
   200                              <1> ;	1 -> fd1 (physical drive, floppy disk 2), physical drive number = 1
   201                              <1> ;	2 -> hd0 (physical drive, hard disk 1), physical drive number = 80h
   202                              <1> ;	3 -> hd1 (physical drive, hard disk 2), physical drive number = 81h
   203                              <1> ;	4 -> hd2 (physical drive, hard disk 3), physical drive number = 82h
   204                              <1> ;	5 -> hd3 (physical drive, hard disk 4), physical drive number = 83h
   205                              <1> 
   206 0001945A ??                  <1> rdev:	resb 1 ; root device number ; Retro UNIX 8086 v1 feature only!
   207                              <1> 	        ; as above, for physical drives numbers in following table
   208 0001945B ??                  <1> mdev:	resb 1 ; mounted device number ; Retro UNIX 8086 v1 feature only!
   209                              <1> 
   210                              <1> ; 23/07/2022
   211                              <1> ;; 15/04/2015
   212                              <1> ;active: resb 1
   213                              <1> ;	 resb 1 ; 09/06/2015
   214                              <1> 
   215                              <1> ; 23/07/2022
   216                              <1> ;mnti:	 resw 1
   217                              <1> ; 07/08/2022
   218 0001945C ????                <1> mpid:	 resw 1
   219                              <1> ;rootdir: resw 1
   220 0001945E ????????            <1> rootdir: resd 1
   221                              <1> 
   222                              <1> ; 21/05/2016 - TRDOS 386 (TRDOS v2.0) - priority levels, 3 run queues 
   223                              <1> runq:
   224 00019462 ????                <1> runq_event:	 resw 1 ; high priority, 'run for event'            ; 2
   225 00019464 ????                <1> runq_normal:	 resw 1 ; normal/regular priority, 'run as reqular' ; 1
   226 00019466 ????                <1> runq_background: resw 1 ; low priority, 'run on background'         ; 0
   227                              <1> ;
   228                              <1> ; 23/07/2022
   229                              <1> ;imod:	resb 1
   230                              <1> ;smod:	resb 1
   231                              <1> ;mmod:	resb 1
   232 00019468 ??                  <1> sysflg:	resb 1
   233 00019469 ??                  <1> 	resb 1
   234                              <1> 
   235 0001946A ????                <1> alignb 4
   236                              <1> 
   237                              <1> user:
   238                              <1> 	; 23/07/2022 - TRDOS 386 Kernel v2.0.5
   239                              <1> 	; 04/12/2021 - Retro UNIX 386 v1.2
   240                              <1> 	; 13/01/2017
   241                              <1> 	; 19/12/2016
   242                              <1> 	; 21/05/2016 - TRDOS 386 (TRDOS v2.0)
   243                              <1> 	; 	       [u.pri] usage method modification
   244                              <1> 	; 04/12/2015
   245                              <1> 	; 18/10/2015
   246                              <1> 	; 12/10/2015
   247                              <1> 	; 21/09/2015
   248                              <1> 	; 24/07/2015
   249                              <1> 	; 16/06/2015
   250                              <1> 	; 09/06/2015
   251                              <1> 	; 11/05/2015
   252                              <1> 	; 16/04/2015 (Retro UNIX 386 v1 - 32 bit modifications)
   253                              <1> 	; 10/10/2013
   254                              <1> 	; 11/03/2013.
   255                              <1> 	;Derived from UNIX v1 source code 'user' structure (ux).
   256                              <1> 	;u.
   257                              <1> 
   258 0001946C ????????            <1> 	u.sp:	  resd 1 ; esp (kernel stack at the beginning of 'sysent')
   259 00019470 ????????            <1> 	u.usp:	  resd 1 ; esp (kernel stack points to user's registers)
   260 00019474 ????????            <1> 	u.r0:	  resd 1 ; eax
   261 00019478 ????                <1> 	u.cdir:	  resw 1
   262 0001947A ????                <1> 		  resw 1 ; 23/07/2022
   263 0001947C ??                  <1> 	u.cdrv:	  resb 1 ; 23/07/2022
   264 0001947D ??                  <1> 		  resb 1
   265 0001947E <res Ah>            <1> 	u.fp:	  resb 10
   266                              <1> 	;u.fp:	  resb OPENFILES ; 23/07/202
   267                              <1> 	u.fsp:	  ; 23/07/2022
   268 00019488 ????????            <1> 	u.fofp:	  resd 1
   269 0001948C ????????            <1> 	u.dirp:	  resd 1
   270 00019490 ????????            <1> 	u.namep:  resd 1
   271 00019494 ????????            <1> 	u.off:	  resd 1
   272                              <1> 	;	  resd 1 ; 23/07/2022 (64 bit fptr)
   273 00019498 ????????            <1> 	u.base:	  resd 1
   274 0001949C ????????            <1> 	u.count:  resd 1
   275 000194A0 ????????            <1> 	u.nread:  resd 1
   276 000194A4 ????????            <1> 	u.break:  resd 1 ; break
   277                              <1> 	; 10/01/2017 (TRDOS 386, relocation and dword alignment)
   278                              <1> 	; tty number (rtty, rcvt, wtty)
   279 000194A8 ????                <1> 	u.ttyp:	  resw 1 
   280 000194AA ??                  <1> 	u.ttyn:	  resb 1 ; 28/07/2013 - Retro Unix 8086 v1 feature only !
   281 000194AB ??                  <1> 	u.mode:   resb 1 ; 23/07/2022
   282                              <1> 	;u.resb:  resb 1 ; 10/01/2017 (TRDOS 386, temporary)
   283 000194AC <res 10h>           <1> 	u.dirbuf: resb 16 ; 04/12/2015 (10 -> 16)
   284                              <1> 	;u.pri:	  resw 1 ; 14/02/2014
   285 000194BC ??                  <1> 	u.quant:  resb 1 ; Retro UNIX 8086 v1 Feature only ! (uquant)
   286 000194BD ??                  <1> 		  resb 1 ; 23/07/2022
   287 000194BE ??                  <1> 	u.pri:	  resb 1 ; Modification: 21/05/2016 (priority levels: 0, 1, 2)
   288 000194BF ??                  <1> 		  resb 1 ; 23/07/2022
   289 000194C0 ????                <1> 	u.intr:	  resw 1
   290 000194C2 ????                <1> 	u.quit:	  resw 1
   291                              <1> 	;u.emt:	  resw 1 ; 10/10/2013
   292                              <1> 	;u.ilgins: resw 1 ; 10/01/2017
   293                              <1> 	;u.cdrv:  resw 1 ; cdev
   294 000194C4 ??                  <1> 	u.bsys:	  resb 1
   295 000194C5 ??                  <1> 	u.uno:	  resb 1
   296                              <1> 	; 23/07/2022
   297                              <1> 	;u.uid:	  resw 1 ; uid	; 27/03/2021 - Retro UNIX 386 v2
   298                              <1> 	;u.ruid:  resw 1	; 16 bit uid
   299                              <1> 	;u.gid:	  resb 1 ; gid 	; 27/03/2021 - Retro UNIX 386 v2
   300                              <1> 	;u.rgid:  resb 1
   301                              <1> 	; 23/07/2022
   302                              <1> 	;u.procp: resd 1 ; /* pointer to proc structure */
   303 000194C6 ??                  <1> 	u.uid:	  resb 1 ; uid
   304 000194C7 ??                  <1> 	u.ruid:   resb 1
   305 000194C8 ????????            <1>         u.upage:  resd 1 ; 16/04/2015 - Retro Unix 386 v1 feature only !
   306 000194CC ????????            <1> 	u.pgdir:  resd 1 ; 09/03/2015 (page dir addr of process)
   307 000194D0 ????????            <1> 	u.ppgdir: resd 1 ; 06/05/2015 (page dir addr of the parent process)
   308 000194D4 ????????            <1> 	u.pbase:  resd 1 ; 20/05/2015 (physical base/transfer address)
   309 000194D8 ????                <1> 	u.pcount: resw 1 ; 20/05/2015 (byte -transfer- count for page)
   310                              <1> 	;u.pncount: resw 1
   311                              <1> 		; 16/06/2015 (byte -transfer- count for page, 'namei', 'mkdir')
   312                              <1> 	;u.pnbase:  resd 1
   313                              <1> 		; 16/06/2015 (physical base/transfer address, 'namei', 'mkdir')
   314                              <1> 			 ; 09/06/2015
   315 000194DA ??                  <1> 	u.kcall:  resb 1 ; The caller is 'namei' (dskr) or 'mkdir' (dskw) sign
   316 000194DB ??                  <1> 	u.brwdev: resb 1 ; Block device number for direct I/O (bread & bwrite)
   317                              <1> 			 ; 24/07/2015 - 24/06/2015
   318                              <1> 	;u.args:  resd 1 ; arguments list (line) offset from start of [u.upage]
   319                              <1> 			 ; (arg list/line is from offset [u.args] to 4096 in [u.upage])
   320                              <1> 			 ; ([u.args] points to argument count -argc- address offset)
   321                              <1>  			 ; 24/06/2015
   322                              <1> 	;u.core:  resd 1 ; physical start address of user's memory space (for sys exec)
   323                              <1> 	;u.ecore: resd 1 ; physical end address of user's memory space (for sys exec)
   324                              <1> 	;;;
   325                              <1> 	; 19/08/2024	 ; TRDOS 386 v2.0.9 ; STDIN/STDOUT/STDERR 
   326 000194DC ??                  <1> 	u.stdin:  resb 1 ; 0 is tty-r or > 0 is file (redirection)
   327 000194DD ??                  <1> 	u.stdout: resb 1 ; 0 is tty-w or > 0 is file (redirection)
   328 000194DE ??                  <1> 	u.ungetc: resb 1 ; u.getc is valid if u.ungetc > 0	
   329 000194DF ??                  <1> 	u.getc:	  resb 1 ; last char read on stdin	 	
   330                              <1> 	;;;
   331                              <1> 	; last error number
   332 000194E0 ????????            <1> 	u.error:  resd 1 ; 28/07/2013 - 09/03/2015 
   333                              <1> 		         ; Retro UNIX 8086/386 v1 feature only!
   334                              <1> 			 ; 21/09/2015 (debugging - page fault analyze)
   335 000194E4 ????????            <1> 	u.pfcount: resd 1 ; page fault count for (this) process (for sys geterr)
   336                              <1> 		; 19/12/2016 (TRDOS 386)
   337 000194E8 ????????            <1> 	u.tcb:	  resd 1 ; Timer callback address/flag which will be used by timer int
   338                              <1> 		; 13/01/2017 (TRDOS 386)
   339 000194EC ??                  <1> 	u.t_lock: resb 1 ; Timer interrupt (callback) lock (unlocked by 'sysrele')
   340 000194ED ??                  <1> 	u.t_mode: resb 1 ; running mode during timer interrupt (0= system, 0FFh= user)
   341                              <1> 		; 26/02/2017 (TRDOS 386)
   342 000194EE ??                  <1> 	u.irqc:	  resb 1  ; Count of IRQ callback services (IRQs in use)
   343                              <1> 		; 28/02/2017 (TRDOS 386)
   344 000194EF ??                  <1> 	u.irqwait: resb 1 ; IRQ waiting for callback service flag (IRQ number, If > 0)
   345 000194F0 ??                  <1> 	u.r_lock: resb 1 ; 'IRQ callback service is in progress' flag (IRQ lock)
   346 000194F1 ??                  <1> 	u.r_mode: resb 1 ; running mode during hadware interrupt
   347                              <1> 	; 23/07/2022
   348 000194F2 ??                  <1> 	u.exit:	  resb 1 ; exit code
   349                              <1> 	; 27/02/2017 (TRDOS 386)
   350 000194F3 ??                  <1> 	u.fpsave: resb 1 ; TRDOS 386, 'save/restore FPU registers' flag
   351                              <1> alignb 4
   352                              <1> 	; !! wrong sizing in TRDOS 386 v2.0.4 (in 'ubss.s', 28/02/2017) !!
   353                              <1> 	;u.fpregs: resb 94 ; 94 byte area for saving and restoring FPU registers
   354                              <1> 	; 23/07/2022
   355 000194F4 <res 6Ch>           <1> 	u.fpregs: resb 108 ; 108 byte area for saving and restoring FPU registers
   356                              <1> 
   357                              <1> alignb 4
   358                              <1> 
   359                              <1> U_SIZE	equ $ - user
   360                              <1> 
   361                              <1> ; 18/10/2015 - Retro UNIX 386 v1 (local variables for 'namei' and 'sysexec')
   362 00019560 ????????            <1> pcore:	resd 1  ; physical start address of user's memory space (for sys exec)
   363 00019564 ????????            <1> ecore:	resd 1  ; physical address of user's stack/last page (for sys exec)
   364 00019568 ????????            <1> nbase:	resd 1	; physical base address for 'namei' & 'sysexec'
   365                              <1> ; 23/07/202 - TRDOS 386 Kernel v2.0.5
   366                              <1> ;ncount: resw 1
   367 0001956C ????????            <1> ncount: resd 1	; remain byte count in page for 'namei' & 'sysexec'
   368                              <1> ;argc:	resw 1
   369 00019570 ????????            <1> argc:	resd 1	; argument count for 'sysexec'
   370 00019574 ????????            <1> argv:	resd 1	; argument list (recent) address for 'sysexec'
   371                              <1> 
   372                              <1> ; 03/06/2015 - Retro UNIX 386 v1 Beginning
   373                              <1> ; 07/04/2013 - 31/07/2013 - Retro UNIX 8086 v1
   374 00019578 ??                  <1> rw:	resb 1 ;; Read/Write sign (iget)
   375                              <1> ; 23/07/2022
   376 00019579 ??????              <1> 	resb 3
   377                              <1> 
   378                              <1> alignb 4
   379                              <1> 
   380                              <1> ; 24/04/2016
   381 0001957C ????????            <1> ii:	resd 1 ; first cluster of the program file
   382 00019580 ????????            <1> i.size:	resd 1 ; size of the program file
  4003                                  
  4004                                  alignb 4
  4005                                  
  4006                                  ; 23/05/2016 (TRDOS 386)
  4007                                  ; 14/10/2015 (Retro UNIX 386 v1, 'unix386.s')
  4008 00019584 ????????                cr3reg:	 resd 1  ; cr3 register content at the beginning of the timer
  4009                                  		 ; (or RTC) interrupt handler.
  4010                                  
  4011                                  ; 10/12/2016 (callback)
  4012                                  ; 10/06/2016
  4013                                  ; 19/05/2016
  4014                                  ; 18/05/2016 - TRDOS 386 feature only !
  4015 00019588 <res 100h>              timer_set: resd 16*4   ; 256 bytes memory space for 16 timer events
  4016                                  	; Timer Event Structure: (max. 16 timer events, 16*16 bytes)
  4017                                  	;       Owner:	        resb 1 ; 0 = free
  4018                                  	;		  	       ;>0 = process number (u.uno)
  4019                                  	;	Callback:	resb 1 ; 0 = response byte address (phy)
  4020                                  	;				 1 = callback address (virtual)				
  4021                                  	;	Interrupt:      resb 1 ; 0 = Timer interrupt (or none)
  4022                                  	;		   	       ; 1 = Real Time Clock interrupt 
  4023                                  	;	Response:       resb 1 ; 0 to 255, signal return value
  4024                                  	;	Count Limit:	resd 1 ; count of ticks (total/set)
  4025                                  	;	Current Count: 	resd 1 ; count of ticks (current)
  4026                                  	;	Response Addr:  resd 1 ; response byte (pointer) address
  4027                                  	;			       ; (or callback -user service- address)	
  4028                                  
  4029                                  
  4030                                  ; 17/04/2021
  4031                                  ; (memory page swap parameters are disabled as temporary)
  4032                                  ;
  4033                                  ; Memory (swap) Data (11/03/2015)
  4034                                  ; 09/03/2015
  4035                                  ;swpq_count: resw 1 ; count of pages on the swap queue
  4036                                  ;swp_drv:    resd 1 ; logical drive description table address of the swap drive/disk
  4037                                  ;swpd_size:  resd 1 ; size of swap drive/disk (volume) in sectors (512 bytes). 		  				
  4038                                  ;swpd_free:  resd 1 ; free page blocks (4096 bytes) on swap disk/drive (logical)
  4039                                  ;swpd_next:  resd 1 ; next free page block
  4040                                  ;swpd_last:  resd 1 ; last swap page block	
  4041                                  
  4042                                  alignb 4
  4043                                  
  4044                                  ; 10/07/2015
  4045                                  ; 28/08/2014
  4046 00019688 ????????                error_code:	resd 1
  4047                                  ; 29/08/2014
  4048 0001968C ????????                FaultOffset: 	resd 1
  4049                                  ; 21/09/2015
  4050 00019690 ????????                PF_Count:	resd 1	; total page fault count
  4051                                  		       	; (for debugging - page fault analyze)
  4052                                  		 	; 'page_fault_handler' (memory.inc)
  4053                                  			; 'sysgeterr' (u9.s)
  4054                                  
  4055                                  ; 29/04/2016 (TRDOS 386 = TRDOS v2.0)
  4056                                  ; 22/08/2015 (Retro UNIX 386 v1)
  4057                                  buffer: 
  4058 00019694 ????????????????        	resb	8 
  4059                                  readi_buffer:
  4060 0001969C <res 200h>              	resb 	512
  4061 0001989C ????????????????        	resb	8
  4062                                  writei_buffer:
  4063 000198A4 <res 200h>              	resb	512	
  4064                                  ; 24/10/2016
  4065 00019AA4 ????????????????        	resb	8 
  4066                                  rw_buffer:
  4067 00019AAC <res 800h>              	resb 	2048  ; general purposed, r/w sector buffer
  4068                                  
  4069                                  %if 1
  4070                                  ; 17/01/2021
  4071 0001A2AC <res 80h>               edid_info:	resb 128 ; VESA EDID (monitor capabilities) info	
  4072                                  ; 28/11/2020
  4073 0001A32C ??                      pmi32:		resb 1	; (>0) use VESA VBE3 protected mode calls 
  4074 0001A32D ??                      vbe_mode_x:	resb 1  ; VESA VBE3 video bios mode set options
  4075 0001A32E ????                    video_mode:	resw 1	; VESA VBE3 video mode (with option flags)
  4076                                  ; 30/11/2020
  4077 0001A330 ????????                vbe3bios_addr:	resd 1	; new (writable mem) address of VBE3 bios
  4078                                  ; 02/12/2020
  4079 0001A334 ????????                pmid_addr:	resd 1	; PMInfoBlock ('PMID') linear address
  4080                                  ; 14/01/2021
  4081                                  ; 06/12/2020		; VESA VBE 3 video state
  4082                                  ;vbe3stbufsize: resw 1	; video regs/dac/bios state buffer size
  4083                                  ;			; block size in bytes
  4084                                  ; 16/01/2021
  4085 0001A338 ????                    vbe3stbsflags: resw 1	; video regs/dac/bios state buffer size
  4086                                  ;			; pointer flags for buffer state options
  4087                                  %endif
  4088                                  
  4089                                  %if 1
  4090                                  ; 10/12/2020
  4091                                  LFB_Info:
  4092 0001A33A <res 10h>               		resb 16	; Linear Frame Buffer info block
  4093                                  
  4094                                  ;24/11/2020 - TRDOS 386 v2.0.3
  4095                                  ; BOCHS/PLEX86 VESA VBE3 MODE INFO extension to TRDOS 386 v2 kernel	
  4096                                  MODE_INFO_LIST:
  4097 0001A34A <res 44h>               		resb 68	; mode + 66 byte VESA vbe3 mode info (4F01h) 
  4098                                  %endif
  4099                                  
  4100                                  ; 05/01/2021
  4101 0001A38E ??                      ufont:		resb 1	; (VGA graphics) user font flags
  4102                                  			; bit 7 - permission flag for int 31h
  4103                                  			; bit 4 - 8x16 user font ready/loaded flag  
  4104                                  			; bit 3 - 8x8 user font ready/loaded flag
  4105                                  			; bit 1 - select 8x16 user font (sysvideo)
  4106                                  			; bit 0 - select 8x8 user font (sysvideo)
  4107 0001A38F ??                      		resb 1	; 19/01/2021
  4108                                  ; 17/01/2021
  4109 0001A390 ??                      srvsf:		resb 1	; 'save restore video state' permission flag
  4110                                  ; 18/01/2021
  4111 0001A391 ??                      srvso:		resb 1	; video state buffer save/restore option
  4112 0001A392 ????????                VideoStateID:	resd 1	; used to verify state saved by same prog
  4113                                  ; 29/01/2021
  4114 0001A396 ????                    v_width:	resw 1	; screen (display page) width
  4115 0001A398 ??                      v_ops:		resb 1	; 'sysvideo' graphics data transfer option	
  4116 0001A399 ??                      v_bpp:		resb 1	; bits per pixels ('sysvideo')
  4117 0001A39A ????????                v_mem:		resd 1	; video memory ('sysvideo')	
  4118 0001A39E ????????                v_siz:		resd 1	; video page size ('sysvideo')
  4119 0001A3A2 ????????                v_str:		resd 1	; window start adress ('sysvideo')
  4120 0001A3A6 ????????                v_end:		resd 1	; window end (end+1) adress ('sysvideo')
  4121                                  ; 31/01/2021
  4122                                  ; 01/01/2021
  4123                                  ;maskbuff:     ;resd 1	; user's bitmask buffer addr ('sysvideo')
  4124 0001A3AA ????????                maskcolor:	resd 1	; VGA/SVGA pixel mask color ('sysvideo')
  4125                                  ; 27/02/2021
  4126 0001A3AE ????????                pixcount:	resd 1	; pixel count ('sysvideo' window ops) 
  4127                                  ; 02/02/2021
  4128 0001A3B2 ????????????????        buffer8:	resd 2	; 8 bytes small buffer for 'sysvideo'  
  4129                                  
  4130                                  bss_end:
  4131                                  
  4132                                  ; 27/12/2013
  4133                                  _end:  ; end of kernel code
