; Copyright (c) 2008-2009, diamond
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
;       * Redistributions of source code must retain the above copyright
;       notice, this list of conditions and the following disclaimer.
;       * Redistributions in binary form must reproduce the above copyright
;       notice, this list of conditions and the following disclaimer in the
;       documentation and/or other materials provided with the distribution.
;       * Neither the name of the <organization> nor the
;       names of its contributors may be used to endorse or promote products
;       derived from this software without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY Alexey Teplov aka <Lrz> ''AS IS'' AND ANY
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;*****************************************************************************

					Sector not found. N. N.N.N. N.N.N.N.N.N.N. N.N. N.N.N.N.N.N.?

    CD/DVD    ISO-9660.
(ISO-9660    -   CD; DVD  
 ISO-9660,  UDF.)

=====================================================================

  :
1)         .
2)   - 80386.
3)       452K   .

=====================================================================

   (    14.09.2008):
	 ISO-9660: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-119.pdf
	  CD: http://www.phoenix.com/NR/rdonlyres/98D3219C-9CC9-4DF5-B496-A286D893E36A/0/specscdrom.pdf
	   EDD BIOS 3.0: http://www.phoenix.com/NR/rdonlyres/19FEBD17-DB40-413C-A0B1-1F3F560E222F/0/specsedd30.pdf
		 ,  1.1: http://www.phoenix.com/NR/rdonlyres/9BEDED98-6B3F-4DAC-BBB7-FA89FA5C30F0/0/specsedd11.pdf
	  BIOS: Interrupt List by Ralf Brown: http://www.cs.cmu.edu/~ralf/files.html
	  Boot BIOS: http://www.phoenix.com/NR/rdonlyres/56E38DE2-3E6F-4743-835F-B4A53726ABED/0/specsbbs101.pdf

=====================================================================

  :
	1000-1800	     
	 ...-7C00	
	7C00-8400	 
	8400-8A00	    :   
			:
			dw    L2-  ,
				   
				(  -  );
			dw      ;
			dd   ;
			dw    ;
			dw  
	60000-...	 Path Table,   
			+   ;
			    
			  -  , 
			 A0000  EBDA, Extended BIOS Data Area

=====================================================================

  .
  (start):    BIOS  ,  
	dl   ,    
1.        CD/DVD  cs:ip
	  0:7C00,   07C0:0000.    
	        cs=0 ( 
	      cs, 
	 ds,  es      ).
2.   ss:sp = 0:7C00 (   )
	   ds=es=0.    
	  .    
	  .
3.   LBA.  CD/DVD  BIOS  
	LBA-.
4.    CD (Primary Volume Descriptor, PVD):  
	ISO9660   10h    ,
	   (Volume Descriptor Set
	Terminator).      ,   
	   ,   .   
	  ,   .
 ,    CD    CD
	 	 .   ElTorito 
	CD     .    ,
	: -,  BIOS    CD 
	   ; -, BIOS int 13h 
	      .    
	    . (-,    BIOS
	 ,      10h,  
	      PVD,  
	  10h+( ).    BIOS    
	 ,      
	     .)
5. ( pvd_found)   PVD     
	 :    ( ,
	     512    ,
	 2048  CD  DVD);     ;
	     (   ,
	        ).
6.      int 12h;    
	 ,     (
	 6000:0000    ).
7.    CD (Path Table) -  ,  
	      .   
	 ( 62K     ),  
	.    ,   
	dir1/dir2/dir3/file     
	   dir1,dir2,dir3;  ,   
	   (    dir1/dir2/dir3)
	  dir3.   ,   
	       
	 .
8.         (   .7
	     ).
9.        kord/loader.  
	       CD.
10.     : al='c' 
	  - CD/DVD; ah=BIOS- ; bx='is'
	   ISO-9660; ds:si  
	callback-,     .
11.    ,   
	 ,  kord/loader  .

      (callback):
	   .
       .
     (load_file 
	    , loadloop.loadnew  
	    ).

 .
   (err):
1.      .
2.   "Press any key...".
3.   any key.
4.  int 18h,   BIOS   - .
5.   .

   (read_sectors):
    :
	es:bx =    ,    
	eax =  
	cx =  
 :
	es:bx    ,     
	   ,  CF 
1.   ( 2-4)  ,   ,    
	     7Fh (	
	EDD BIOS).
2.       7Fh,   ( 
	)  7Fh.
3.      int 13h (    
	push,    :  -  LIFO,   
	        ,   
	).
4.  BIOS.  BIOS   ,  ,
	 CF=1    .
	   ,    .
5.         
	  ,      
	 (  es:bx  es).   , 
	,     2.

    ASCIIZ- (out_string):
 : ds:si -> 
 ,     ,   int 10h/ah=0Eh.

   (load_file):
 :
	ds:di =    ,   
		 ,      
 :
	bx = : 0=, 1=  ,   ,
		2=  , 3= 
	dx:ax =  , 0xFFFFFFFF,    
1.      ,     ,
	     4,  eax =  
	 .
2.  es:di    .   
	,       6000h.
	 dx (       
	,   1), cx (   ),
	bx ( ,     
	  ).
3.           . 
	   (     ),
	         ,
	      ,     
	    bx=2, ax=dx=0xFFFF.   ,
	     ,   
	   .    ,
	     ,      4,
	 eax =    .   ,  
	    ,      3,
	    ds:si     bx.
4. (parse_dir)          eax
	         ds:si. 
	    ,       ;
	  ,    .
5.   ISO-9660      (File Section), 
	      .   
	       , 
	  0000:2000.  cur_desc_end   
	  ,   ,    
	   . (,  ,
	   .)
6.        .
7. (parse_dir.found)      ,     ,
	        
	.15. (       .)
8. (parse_dir.notfound)      ,    
	 .     ( ,
	   ).   /
	      bx=3, dx=ax=0xFFFF.
	        , 
	   .
9.      (   64K   
	  ),     .    
	      (0000:1000)  
	    ,     
	    . (   ,
	     .)    
	 .17.
10. (parse_dir.yescache)      ,  
	    .   
	  -    (
	parse_dir.freeloop).    , ,  ,
	      .
	   -     
	         
	        .
	        
	.   ,    ,
	   . -    
	     .
11.    .     10 
	     ;   ,
	      ;   , 
	      ,  
	 .
12.       ,   ,
	  .
13.        
	   .
14.       ,   
	  .   ,   ,   
	  bx=3, ax=dx=0xFFFF.
15. (parse_dir.scan)        
	.
16.        .
	(-        
	  .)
17. (parse_dir.scandone)        
	  ,  cur_desc_end  ,   .
	         .
18. (filefound)    .     
	(  ,      ),
	  ,    -  ,
	       .4.
	  ,   ,    - 
	    .
19.  ,     . 
	   
	1234:FC08 -> (1234+0FC0):0008,     ,
	   :    
	 400h   rep movsb   ,   8
	     ,   64K .  
	    .  cur_limit 
	     .
20. (loadloop)         
	( 21-27).
21.   [cur_start],    , 
	    .
22. (loadloop.loadnew)         
	,    callback-    
	.       [cur_start] -
	  ,  -   
	,     .
23.    (  esi)     
	   .    , 
	,        .
	       
	    [cur_start].
24.          
	  ,      [first_byte],
	    read_many_bytes.with_first.
25.       (non-interleaved mode),  
	       
	 .     bx=3 (  )
	     .28.
26.       (interleaved mode),  
	     ,  
	         ,
	       .
	          .
	      ,     .
27. (loadloop.loadcontinue)        
	  ,      .20.  
	  bx=0  bx=1    ,  
	  .23.
28. (loadloop.calclen)    ,   
	.

 ,       
	(is_last_component):
 : ds:si =   
 :  CF ,    
         '/';   ,
	  (  CF=0);   ,   CF
	 .

         
  (test_filename1   , test_filename2  ):
 : ds:si =   , es:di =   
	   test_filename1,   test_filename2
 : CF ,    
         
	   .    :   
	 ds:si ( ,   -   '/') - 
	      "filename.ext"  
	"filename.ext;1" ( ISO9660 ";1" -  ,   
	      );
	  - ,    ;
	   -  ,     
	,         .

      (toupper):
 : ASCII-
 :       ( ,    
	 )
    'a' - 'z'    'a'-'A',
	   .

      (scan_for_filename_in_sector):
 :
	ds:si =    
	es:bx =     
	es:dx =     
 :
	CF ,     
		(     )
	        
     ,  ,   
	 Associated (  ,  ). 
	      ,   
	.    (   Multi-Extent),
	    CF=0.    ,   
	 CF=1.     (   
	      ),    
	   .   
	     ;  
	 ,      
	   64K    bx=0 (  
	),    -  ,    
	bx=0,        ZF  ;
	      (   CF=1).

      :
 : eax =  
 : eax =  , dx =     
   32-   32- ( 
	  ,    ).

   ,    
	(load_phys_sector_for_lb_force):
 : eax =  ;
	si - , ,      ,
		      :
	si = 0 -  , si  - 
 :
	     0000:1000
	si     
	CF    
        
	      ;  
	          (si=0),
	    ;   si    
	  .

         
	(read_many_bytes  read_many_bytes.with_first):
 :
	eax =  
	esi =    
	es:bx =    ,    
	cur_limit =   (  esi)
 :
	es:bx    ,     
	   ,  CF 
	cur_limit   
  :      
	[first_byte],       [first_byte];
	,     ,  [first_byte]
	 .
1.         0000:1000,
	        . 
	    .
2.     (, 0 ),   .1,
	 .    .
3.      ,   .
4.       ,  ,
	,      .
5.         ,   
	 ,        .
6.   ,    ,  ,  
	      ,  
	      .
