home *** CD-ROM | disk | FTP | other *** search
/ The Equalizer BBS / equalizer-bbs-collection_2004.zip / equalizer-bbs-collection / DEMOSCENE-STUFF / BKISSSRC.ZIP / JLIBIO.INC < prev    next >
Text File  |  1994-02-14  |  29KB  |  543 lines

  1. ;this is for the assembly version of the library interface.
  2. ;
  3. ;Note:  This requires you to be using TASM in IDEAL mode and to 'INCLUDE'
  4. ;this module in your code.  It also requires TASM to be in 386 compilation
  5. ;mode.  (These restrictions exist because this module is originally from
  6. ;my game that I'm working on)
  7.  
  8. ;_jlib_open_library
  9. ;_jlib_close_library
  10. ;_jlib_open_file
  11. ;_jlib_close_file
  12. ;_jlib_ftell
  13. ;_jlib_filelength
  14. ;_jlib_fseek
  15. ;_jlib_read_file
  16.  
  17. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  18. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  19. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  20.  
  21. MAJORVER = 1                        ;\
  22. MINORVER = 3                        ; > file format version 1.3
  23. VERSION_ID = MINORVER*256+MAJORVER  ;/
  24. MAXFILES = 100                      ;maximum number of files allowed in library
  25. SLIDINGREQUEST = 0                  ;set to 1 to enable to do sliding requests
  26.  
  27. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  28. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  29. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  30. STRUC       LibFile
  31.             Fileattr    DB 0
  32.             Filetime    DW 0
  33.             Filedate    DW 0
  34.             Filesize    DD 0
  35.             Filename    DB 13 DUP (0)
  36.             Fileoffset  DD 0
  37.             CurPos      DD 0              ;\ not stored in file
  38.             Opened      DB 0              ;/
  39. ENDS        LibFile
  40. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  41. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  42. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  43. MACRO       MAKEUPPERCASE LETTER
  44.             LOCAL @@NotLower
  45.             cmp LETTER,'a'
  46.             jb @@NotLower
  47.             cmp LETTER,'z'
  48.             ja @@NotLower
  49.             sub LETTER,'a'-'A'
  50. @@NotLower:
  51. ENDM        MAKEUPPERCASE
  52. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  53. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  54. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  55. LibHandle   DW -1                         ;handle for library
  56. NumFiles    DW 0                          ;number of files in library
  57. FileStats   LibFile MAXFILES DUP (<>)     ;file info structures of each file
  58. Wildcard    DB 13 DUP (0)                 ;\   last defined wildcard
  59. MasterAttr  DW 0                          ; \  original search attribute
  60. HandleNext  DB 0                          ;  > if next FindNext should be done
  61. LastMatch   DW 0                          ; /  number of last match
  62. MasterWild  DB 80 DUP (0)                 ;/   original search wildcard
  63. TempBuffer  DB 13 DUP (0)                 ;temporary I/O buffer
  64. HeaderOffset DD 0                         ;offset to start of JLIB file
  65. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  66. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  67. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  68. ;Sets the library that will be used for all subsequent JLIB file I/O accesses.
  69. ;
  70. ;           ES:DI ==> filename
  71. ;returns:   CARRY set on error
  72. ;
  73. PROC        _jlib_open_library
  74.             cmp [LibHandle],-1                  ;is a library already loaded?
  75.             jnz @@Error                         ;  yes -- return error
  76.  
  77.             ;*** Reading of the JLIB file header ***
  78.             push ds                             ;\
  79.             mov ax,3D00h                        ; \
  80.             mov dx,es                           ;  \
  81.             mov ds,dx                           ;   \
  82.             mov dx,di                           ;    > try to open the library
  83.             int 21h                             ;   /
  84.             pop ds                              ;  /
  85.             jc @@Error                          ; /
  86.             mov [LibHandle],ax                  ;/
  87. ;-------- 1.3 changes start here
  88.             mov ax,-4                           ;\
  89.             cwd                                 ; \
  90.             mov cx,dx                           ;  \
  91.             mov dx,ax                           ;   > seek to 4 bytes before end
  92.             mov ax,4202h                        ;  /
  93.             mov bx,[LibHandle]                  ; /
  94.             int 21h                             ;/
  95.             mov ah,3Fh                          ;\
  96.             mov bx,[LibHandle]                  ; \
  97.             mov cx,4                            ;  > read in the offset to start
  98.             mov dx,offset HeaderOffset          ; /
  99.             int 21h                             ;/
  100.             mov ax,4202h                        ;\
  101.             mov bx,[LibHandle]                  ; \
  102.             xor cx,cx                           ;  > find out length of total file
  103.             xor dx,dx                           ; /
  104.             int 21h                             ;/
  105.             sub ax,[word HeaderOffset+0]        ;\
  106.             sbb dx,[word HeaderOffset+2]        ; \ compute offset to start of JLIB
  107.             mov [word HeaderOffset+0],ax        ; /
  108.             mov [word HeaderOffset+2],dx        ;/
  109.             mov ax,4200h                        ;\
  110.             mov bx,[LibHandle]                  ; \
  111.             mov cx,[word HeaderOffset+2]        ;  > seek to start of JLIB
  112.             mov dx,[word HeaderOffset+0]        ; /
  113.             int 21h                             ;/
  114. ;-------- 1.3 changes end here
  115.             mov ah,3Fh                          ;\
  116.             mov bx,[LibHandle]                  ; \
  117.             mov cx,8                            ;  \ read in signature and
  118.             mov dx,offset TempBuffer            ;  / file version number
  119.             int 21h                             ; /
  120.             jc @@Error                          ;/
  121.             cmp [dword TempBuffer+0],'biLJ'     ;\
  122.             jnz @@Error                         ; \ check the signarure and
  123.             cmp [word TempBuffer+4],VERSION_ID  ; / file version number
  124.             jnz @@Error                         ;/
  125.             mov cx,[word TempBuffer+6]          ;\
  126.             cmp cx,MAXFILES                     ; \ check the number of files
  127.             ja @@Error                          ; /
  128.             mov [NumFiles],cx                   ;/
  129.             mov ah,3Fh                          ;\
  130.             mov bx,[LibHandle]                  ; \
  131.             mov cx,4                            ;  \ read in the offset to
  132.             mov dx,offset TempBuffer            ;  / the directory structures
  133.             int 21h                             ; /
  134.             jc @@Error                          ;/
  135.             mov ax,4200h                        ;\
  136.             mov bx,[LibHandle]                  ; \
  137.             mov cx,[word TempBuffer+2]          ;  \ seek to the start of the
  138.             mov dx,[word TempBuffer+0]          ;  / directory structures
  139. ;-------- 1.3 changes start here
  140.             add dx,[word HeaderOffset+0]
  141.             adc cx,[word HeaderOffset+2]
  142. ;-------- 1.3 changes end here
  143.             int 21h                             ; /
  144.             jc @@Error                          ;/
  145.             mov cx,[NumFiles]                   ;\
  146.             mov dx,offset FileStats             ; \
  147. @@Read:     push cx dx                          ;  \
  148.             mov ah,3Fh                          ;   |
  149.             mov bx,[LibHandle]                  ;   |
  150.             mov cx,size LibFile-5               ;   | read in the directory
  151.             int 21h                             ;   | information for each file
  152.             jc @@Error                          ;   |
  153.             pop dx cx                           ;   |
  154.             mov si,dx                           ;   |
  155.             mov [si+LibFile.Opened],0           ;  /
  156.             add dx,size LibFile                 ; /
  157.             loop @@Read                         ;/
  158.             clc                                 ;\ return with success
  159.             ret                                 ;/
  160.  
  161. @@Error:    cmp [LibHandle],-1                  ;do we need to close the file?
  162.             jz @@Error2                         ;  no -- then don't
  163.             mov ah,3Eh                          ;\
  164.             mov bx,[LibHandle]                  ; \ close the library file
  165.             int 21h                             ; /
  166.             mov [LibHandle],-1                  ;/
  167. @@Error2:   stc                                 ;\ return with error
  168.             ret                                 ;/
  169. ENDP        _jlib_open_library
  170. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  171. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  172. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  173. ;Closes the current library file
  174. ;
  175. ;returns:   CARRY set if no library open
  176. ;
  177. PROC        _jlib_close_library
  178.             cmp [LibHandle],-1                  ;is a library already loaded?
  179.             jz @@Error                          ;  no -- don't need to close it
  180.             mov ah,3Eh                          ;\
  181.             mov bx,[LibHandle]                  ; \ close the library file
  182.             int 21h                             ; /
  183.             mov [LibHandle],-1                  ;/
  184.             clc                                 ;\ return with success
  185.             ret                                 ;/
  186. @@Error:    stc                                 ;\ return with error
  187.             ret                                 ;/
  188. ENDP        _jlib_close_library
  189. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  190. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  191. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  192. ;Opens a file that is stored in the library file for read-only access
  193. ;
  194. ;           ES:DI ==> ASCIIZ filename to open
  195. ;returns:   CARRY set on error
  196. ;           AX = file handle (on success)
  197. ;
  198. PROC        _jlib_open_file
  199.             cmp [LibHandle],-1                  ;is a library already loaded?
  200.             jz @@Error                          ;  no -- return error
  201.  
  202.             mov si,offset TempBuffer            ;\
  203.             call FixFileName                    ; > parse the filename from
  204.             jc @@Error                          ;/  from ES:DI to tempbuffer
  205.             mov ax,cs                           ;\
  206.             mov es,ax                           ; \
  207.             mov di,offset TempBuffer            ;  > match the filename
  208.             call MatchFile                      ; /
  209.             jc @@Error                          ;/
  210.  
  211.             cmp [si+LibFile.Opened],0           ;is the file already "opened"?
  212.             jnz @@Error                         ;  yes -- return error
  213.             mov [si+LibFile.Opened],1           ;say the file is now opened
  214.             mov [si+LibFile.CurPos],0           ;move file pointer to start
  215.             clc                                 ;\ return with success
  216.             ret                                 ;/
  217.  
  218. @@Error:    stc                                 ;\ return with error
  219.             ret                                 ;/
  220. ENDP        _jlib_open_file
  221. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  222. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  223. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  224. ;Closes the file associated with the specified handle
  225. ;
  226. ;           BX = file handle
  227. ;returns:   CARRY set on error
  228. ;
  229. PROC        _jlib_close_file
  230.             cmp [LibHandle],-1                  ;is a library already loaded?
  231.             jz @@Error                          ;  no -- return error
  232.             cmp bx,[NumFiles]                   ;is the handle out of range?
  233.             jae @@Error                         ;  yes -- return error
  234.             mov ax,size LibFile                 ;\
  235.             mul bx                              ; \ DS:SI ==> file information
  236.             mov si,offset FileStats             ; /
  237.             add si,ax                           ;/
  238.             cmp [si+LibFile.Opened],0           ;is the file opened yet?
  239.             jz @@Error                          ;  no -- return error
  240.  
  241.             mov [si+LibFile.Opened],0           ;close the file
  242.             clc                                 ;\ return with success
  243.             ret                                 ;/
  244.  
  245. @@Error:    stc                                 ;\ return with error
  246.             ret                                 ;/
  247. ENDP        _jlib_close_file
  248. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  249. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  250. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  251. ;Returns file pointer position on success
  252. ;
  253. ;           BX = file handle
  254. ;returns:   CARRY set on error
  255. ;           EAX = file position (on success)
  256. ;
  257. PROC        _jlib_ftell
  258.             cmp [LibHandle],-1                  ;is a library already loaded?
  259.             jz @@Error                          ;  no -- return error
  260.             cmp bx,[NumFiles]                   ;is the handle out of range?
  261.             jae @@Error                         ;  yes -- return error
  262.             mov ax,size LibFile                 ;\
  263.             mul bx                              ; \ DS:SI ==> file information
  264.             mov si,offset FileStats             ; /
  265.             add si,ax                           ;/
  266.             cmp [si+LibFile.Opened],0           ;is the file opened yet?
  267.             jz @@Error                          ;  no -- return error
  268.  
  269.             mov eax,[si+LibFile.CurPos]         ;EAX = current position
  270.             clc                                 ;\ return with success
  271.             ret                                 ;/
  272.  
  273. @@Error:    stc                                 ;\ return with error
  274.             ret                                 ;/
  275. ENDP        _jlib_ftell
  276. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  277. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  278. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  279. ;Returns the length of the file associated with the specified handle
  280. ;
  281. ;           BX = file handle
  282. ;returns:   CARRY set on error
  283. ;           EAX = file length (on success)
  284. ;
  285. PROC        _jlib_filelength
  286.             cmp [LibHandle],-1                  ;is a library already loaded?
  287.             jz @@Error                          ;  no -- return error
  288.             cmp bx,[NumFiles]                   ;is the handle out of range?
  289.             jae @@Error                         ;  yes -- return error
  290.             mov ax,size LibFile                 ;\
  291.             mul bx                              ; \ DS:SI ==> file information
  292.             mov si,offset FileStats             ; /
  293.             add si,ax                           ;/
  294.             cmp [si+LibFile.Opened],0           ;is the file opened yet?
  295.             jz @@Error                          ;  no -- return error
  296.  
  297.             mov eax,[si+LibFile.Filesize]       ;EAX = file size
  298.             clc                                 ;\ return with success
  299.             ret                                 ;/
  300.  
  301. @@Error:    stc                                 ;\ return with error
  302.             ret                                 ;/
  303. ENDP        _jlib_filelength
  304. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  305. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  306. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  307. ;Moves the file pointer according to the position and method code
  308. ;
  309. ;           BX = file handle
  310. ;           CL = method code (0 = start, 1 = current, 2 = end)
  311. ;           EAX = offset
  312. ;return:    CARRY set on error
  313. ;           EAX = current position (on success)
  314. ;
  315. PROC        _jlib_fseek
  316.             cmp [LibHandle],-1                  ;is a library already loaded?
  317.             jz @@Error                          ;  no -- return error
  318.             cmp bx,[NumFiles]                   ;is the handle out of range?
  319.             jae @@Error                         ;  yes -- return error
  320.             push eax                            ;\
  321.             mov ax,size LibFile                 ; \
  322.             mul bx                              ;  \ DS:SI ==> file information
  323.             mov si,offset FileStats             ;  /
  324.             add si,ax                           ; /
  325.             pop eax                             ;/
  326.             cmp [si+LibFile.Opened],0           ;is the file opened yet?
  327.             jz @@Error                          ;  no -- return error
  328.  
  329. @@Method0:  cmp cl,0                            ;\ mode 0: offset from start
  330.             jz @@CheckPos                       ;/
  331. @@Method1:  cmp cl,1                            ;\
  332.             jnz @@Method2                       ; \
  333.             add eax,[si+LibFile.CurPos]         ;  > mode 1: current offset
  334.             jc @@Error                          ; /  current position
  335.             jmp @@CheckPos                      ;/
  336. @@Method2:  cmp cl,2                            ;\
  337.             jnz @@Error                         ; \ mode 2: offset from end
  338.             add eax,[si+LibFile.Filesize]       ; /
  339.             jc @@Error                          ;/
  340.  
  341. @@CheckPos: cmp eax,[si+LibFile.Filesize]       ;\ make sure we'll not be past
  342.             ja @@Error                          ;/ the 'end' of the 'file'
  343.             mov [si+LibFile.CurPos],eax         ;save the new position
  344.             clc                                 ;\ return with success
  345.             ret                                 ;/
  346.  
  347. @@Error:    stc                                 ;\ return with error
  348.             ret                                 ;/
  349. ENDP        _jlib_fseek
  350. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  351. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  352. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  353. ;reads a block of count bytes from the file specified by the handle into the
  354. ;specified buffer
  355. ;
  356. ;note:  If 'SLIDINGREQUEST' is nonzero and a value of 'count' is passed that
  357. ;       will go past the end of the logical end of file, it will be forced
  358. ;       down to the maximum number that will not go past the end.  If it is
  359. ;       not defined, then requests that would go past the end will be rejected
  360. ;       and an error will be returned
  361. ;
  362. ;           BX = file handle
  363. ;           CX = number of bytes to read
  364. ;           ES:DI ==> buffer
  365. ;returns:   CARRY set on error
  366. ;           CX = number of bytes read (on success)
  367. ;
  368. PROC        _jlib_read_file
  369.             cmp [LibHandle],-1                  ;is a library already loaded?
  370.             jz @@Error                          ;  no -- return error
  371.             cmp bx,[NumFiles]                   ;is the handle out of range?
  372.             jae @@Error                         ;  yes -- return error
  373.             mov ax,size LibFile                 ;\
  374.             mul bx                              ; \ DS:SI ==> file information
  375.             mov si,offset FileStats             ; /
  376.             add si,ax                           ;/
  377.             cmp [si+LibFile.Opened],0           ;is the file opened yet?
  378.             jz @@Error                          ;  no -- return error
  379.  
  380.             push cx                             ;\
  381.             mov ax,4200h                        ; \
  382.             mov bx,[LibHandle]                  ;  \
  383.             mov ecx,[si+LibFile.Fileoffset]     ;   \
  384.             add ecx,[si+LibFile.CurPos]         ;    \ seek to where we're
  385. ;-------- 1.3 changes start here
  386.             add ecx,[HeaderOffset]
  387. ;-------- 1.3 changes end here
  388.             mov dx,cx                           ;    / supposed to be
  389.             shr ecx,16                          ;   /
  390.             int 21h                             ;  /
  391.             pop cx                              ; /
  392.             jc @@Error                          ;/
  393.  
  394.             mov eax,[si+LibFile.Filesize]       ;\
  395.             sub eax,[si+LibFile.CurPos]         ; \
  396.             and ecx,0000FFFFh                   ;  |
  397.             cmp ecx,eax                         ;  | figure out the maximum
  398.             jbe @@Okay                          ;  | number of bytes that
  399. IF SLIDINGREQUEST ne 0                          ;  | could be read and check
  400.             mov ecx,eax                         ;  | the request against it
  401. ELSE                                            ;  |
  402.             jmp @@Error                         ; /
  403. ENDIF                                           ;/
  404.  
  405. @@Okay:     push ds                             ;\
  406.             mov ah,3Fh                          ; \
  407.             mov bx,[LibHandle]                  ;  \
  408.             mov dx,es                           ;   \
  409.             mov ds,dx                           ;    > actually do the read
  410.             mov dx,di                           ;   /
  411.             int 21h                             ;  /
  412.             pop ds                              ; /
  413.             jc @@Error                          ;/
  414.             mov di,ax                           ;DI = number of bytes read
  415.  
  416.             mov ax,4201h                        ;\
  417.             mov bx,[LibHandle]                  ; \
  418.             xor cx,cx                           ;  \
  419.             xor dx,dx                           ;   \
  420.             int 21h                             ;    \ find out where we
  421.             jc @@Error                          ;    / are now and save it
  422.             shl edx,16                          ;   /
  423.             mov dx,ax                           ;  /
  424.             sub edx,[si+LibFile.Fileoffset]     ; /
  425. ;-------- 1.3 changes start here
  426.             sub edx,[HeaderOffset]
  427. ;-------- 1.3 changes end here
  428.  
  429.             mov [si+LibFile.CurPos],edx         ;/
  430.  
  431.             mov ax,di                           ;AX = number of bytes read
  432.             clc                                 ;\ return with success
  433.             ret                                 ;/
  434.  
  435. @@Error:    stc                                 ;\ return with error
  436.             ret                                 ;/
  437. ENDP        _jlib_read_file
  438. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  439. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  440. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  441. ;capitalize filename, make sure there's a period, only allow 8 characters
  442. ;for the base name and 3 characters for the extension, doesn't allow
  443. ;characters after an asterick
  444. ;
  445. ;           ES:DI ==> ASCIIZ filename to parse
  446. ;           DS:SI ==> buffer to store parsed filename
  447. ;
  448. ;returns:   CARRY set if no filename passed (null name)
  449. ;
  450. PROC        FixFileName
  451.             push si di ax bx dx              ;save what we'll modify
  452.             mov dx,di                        ;ES:DX ==> first byte of filename
  453.             cmp [byte es:di],0               ;\ quit with error, if there's
  454.             jz @@Error                       ;/ nothing given to us
  455. @@FindEnd:  inc di                           ;\
  456.             cmp [byte es:di],0               ; > seek to the end of the name
  457.             jnz @@FindEnd                    ;/
  458. @@FindStart:mov al,[byte es:di]              ;\
  459.             dec di                           ; \
  460.             cmp di,dx                        ;  \
  461.             jz @@GotStart                    ;   | seek back to
  462.             cmp al,'\'                       ;   | the start of
  463.             jz @@IncOne                      ;   | the base name
  464.             cmp al,':'                       ;  /
  465.             jnz @@FindStart                  ; /
  466. @@IncOne:   add di,2                         ;/
  467. @@GotStart: mov ah,8                         ;only copy 8 bytes for the base
  468. @@Basename: mov al,[byte es:di]              ;\
  469.             or al,al                         ; \ load a byte, handling it
  470.             jz @@AddDot                      ; / if it's a NULL
  471.             inc di                           ;/
  472.             cmp al,'.'                       ;if we've found a period, start
  473.             jz @@AddDot                      ;  working on the extension
  474.             MAKEUPPERCASE al                 ;\
  475.             mov [byte ds:si],al              ; > make uppercase and store
  476.             inc si                           ;/
  477.             cmp al,'*'                       ;if we've found an asterick, then
  478.             jz @@Ignore                      ;  ignore all up to period or end
  479.             dec ah                           ;\ only copy 8 characters
  480.             jnz @@Basename                   ;/
  481. @@Ignore:   mov al,[byte es:di]              ;\
  482.             or al,al                         ; \
  483.             jz @@AddDot                      ;  \ skip until a NULL or a
  484.             inc di                           ;  / period is encountered
  485.             cmp al,'.'                       ; /
  486.             jnz @@Ignore                     ;/
  487. @@AddDot:   mov [byte ds:si],'.'             ;\ tack on a period
  488.             inc si                           ;/
  489.             mov ah,3                         ;only copy 3 bytes for the ext
  490. @@Extension:mov al,[byte es:di]              ;\
  491.             inc di                           ; \ load a byte and handle
  492.             or al,al                         ; / it if it's a NULL
  493.             jz @@Done                        ;/
  494.             MAKEUPPERCASE al                 ;\
  495.             mov [byte ds:si],al              ; > make uppercase and store it
  496.             inc si                           ;/
  497.             cmp al,'*'                       ;\ if we copied a '*', then there
  498.             jz @@Done                        ;/ shouldn't be anything after it
  499.             dec ah                           ;\ only copy 3 characters
  500.             jnz @@Extension                  ;/
  501. @@Done:     mov [byte ds:si],0               ;terminate it with a NULL
  502.             clc                              ;signal success (CF = 0)
  503.             jmp @@Quit                       ;
  504. @@Error:    stc                              ;signal error (CF = 1)
  505. @@Quit:     pop dx bx ax di si               ;restore everything
  506.             ret                              ;return
  507. ENDP        FixFileName
  508. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  509. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  510. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  511. ;locates a file structure that matches identically to a specified file
  512. ;
  513. ;           ES:DI ==> ASCIIZ filename to match
  514. ;returns:   DS:SI ==> appropiate structure
  515. ;           AX = file number (0 based)
  516. ;           carry set if not found
  517. ;
  518. PROC        MatchFile
  519.             push bx cx dx
  520.             mov si,offset FileStats          ;SI ==> File structures
  521.             mov cx,[NumFiles]                ;CX = number of files to search
  522.             xor ax,ax                        ;current file number
  523. @@NewFile:  xor bx,bx
  524. @@Compare:  mov dl,[byte ds:si+bx+LibFile.Filename]
  525.             or dl,dl
  526.             jz @@GotIt
  527.             cmp dl,[byte es:di+bx]
  528.             jnz @@Next
  529.             inc bx
  530.             jmp @@Compare
  531. @@Next:     add si,size LibFile
  532.             inc ax
  533.             loop @@NewFile
  534.             stc                              ;signal error (CF = 1)
  535.             jmp @@Quit
  536. @@GotIt:    clc                              ;signal success (CF = 0)
  537. @@Quit:     pop dx cx bx
  538.             ret
  539. ENDP        MatchFile
  540. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  541. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  542. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  543.