home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / cdfm.zip / FILE.ASM < prev    next >
Assembly Source File  |  1993-07-02  |  11KB  |  476 lines

  1.  OPENFILE              = 1
  2.  READFILE              = 1
  3.  WRITEFILE             = 1
  4.  LSEEKFILE             = 1
  5.  CREATEFILE            = 1
  6.  FILESIZE              = 1
  7.  FILECOPY              = 1
  8.  DELETEFILE            = 1
  9.  FINDFILE              = 1
  10.         .386p
  11. code32  segment para public use32
  12.         assume cs:code32, ds:code32
  13.  
  14. include pmode.inc
  15.  
  16. public  _filebufloc, _filebuflen
  17. public  _closefile
  18.  
  19. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  20. ; DATA
  21. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  22. _filebufloc     dd      0               ; location must be in low mem
  23. _filebuflen     dw      4000h
  24.  
  25. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  26. ; CODE
  27. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  28.  
  29. ifdef   CREATEFILE
  30. public  _createfile
  31. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  32. ; Create file
  33. ; In:
  34. ;   EDX -> ASCIIZ filename
  35. ; Out:
  36. ;   CF=1 - Error creating file
  37. ;   CF=0 - File created succesfully
  38. ;     V86R_BX - file handle
  39. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  40. _createfile:
  41.         push ax
  42.         push edx
  43.         add edx,_code32a
  44.         mov ax,dx
  45.         shr edx,4
  46.         and ax,0fh
  47.         mov v86r_dx,ax
  48.         mov v86r_ds,dx
  49.         mov v86r_ax,3c00h
  50.         mov v86r_cx,20h
  51.         mov al,21h
  52.         int 33h
  53.         mov ax,v86r_ax
  54.         mov v86r_bx,ax
  55.         pop edx
  56.         pop ax
  57.         ret
  58. endif
  59.  
  60. ifdef   OPENFILE
  61. public  _openfile
  62. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  63. ; Open file
  64. ; In:
  65. ;   EDX -> ASCIIZ filename
  66. ; Out:
  67. ;   CF=1 - Error opening file
  68. ;   CF=0 - File opened succesfully
  69. ;     V86R_BX - file handle
  70. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  71. _openfile:
  72.         push ax
  73.         push edx
  74.         add edx,_code32a
  75.         mov ax,dx
  76.         shr edx,4
  77.         and ax,0fh
  78.         mov v86r_dx,ax
  79.         mov v86r_ds,dx
  80.         mov v86r_ax,3d02h
  81.         mov al,21h
  82.         int 33h
  83.         mov ax,v86r_ax
  84.         mov v86r_bx,ax
  85.         pop edx
  86.         pop ax
  87.         ret
  88. endif
  89.  
  90. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  91. ; Close a file
  92. ; In:
  93. ;   V86R_BX - file handle
  94. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  95. _closefile:
  96.         push ax
  97.         mov v86r_ax,3e00h
  98.         mov al,21h
  99.         int 33h
  100.         pop ax
  101.         ret
  102.  
  103. ifdef   DELETEFILE
  104. public  _deletefile
  105. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  106. ; Delete a file
  107. ; In:
  108. ;   EDX -> ASCIIZ filename
  109. ; Out:
  110. ;   CF=1 - Error opening file
  111. ;   CF=0 - File opened succesfully
  112. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  113. _deletefile:
  114.         push ax
  115.         push edx
  116.         add edx,_code32a
  117.         mov ax,dx
  118.         shr edx,4
  119.         and ax,0fh
  120.         mov v86r_dx,ax
  121.         mov v86r_ds,dx
  122.         mov v86r_ah,41h
  123.         mov al,21h
  124.         int 33h
  125.         pop edx
  126.         pop ax
  127.         ret
  128. endif
  129.  
  130. ifdef   LSEEKFILE
  131. public  _lseekfile
  132. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  133. ; Seek position in file
  134. ; In:
  135. ;   V86R_BX - file handle
  136. ;   EAX - signed offset to move to
  137. ;   BL - from: 0-beginning of file, 1-current location, 2-end of file
  138. ; Out:
  139. ;   CF=1  - Error seeking in file
  140. ;     EAX - ?
  141. ;   CF=0  - Seek fine
  142. ;     EAX - new offset from beginning of file
  143. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  144. _lseekfile:
  145.         mov v86r_ah,42h
  146.         mov v86r_al,bl
  147.         mov v86r_dx,ax
  148.         shr eax,16
  149.         mov v86r_cx,ax
  150.         mov al,21h
  151.         int 33h
  152.         pushf
  153.         mov ax,v86r_dx
  154.         shl eax,16
  155.         mov ax,v86r_ax
  156.         popf
  157.         ret
  158. endif
  159.  
  160. ifdef   FILESIZE
  161. public  _filesize
  162. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  163. ; Get size of file
  164. ; In:
  165. ;   V86R_BX - file handle
  166. ; Out:
  167. ;   CF=1  - Error checking file
  168. ;     EAX - ?
  169. ;   CF=0  - chek fine
  170. ;     EAX - size of file
  171. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  172. _filesize:
  173.         mov v86r_ax,4201h
  174.         xor eax,eax
  175.         mov v86r_cx,ax
  176.         mov v86r_dx,ax
  177.         mov al,21h
  178.         int 33h
  179.         push v86r_dx
  180.         push v86r_ax
  181.         mov v86r_ax,4202h
  182.         xor eax,eax
  183.         mov v86r_cx,ax
  184.         mov v86r_dx,ax
  185.         mov al,21h
  186.         int 33h
  187.         mov ax,v86r_dx
  188.         shl eax,16
  189.         mov ax,v86r_ax
  190.         pop v86r_dx
  191.         pop v86r_cx
  192.         mov v86r_ax,4200h
  193.         push eax
  194.         mov al,21h
  195.         int 33h
  196.         pop eax
  197.         ret
  198. endif
  199.  
  200. ifdef   READFILE
  201. public  _readfile
  202. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  203. ; Read from file
  204. ; In:
  205. ;   V86R_BX - file handle
  206. ;   EDX -> buffer to read to
  207. ;   ECX - number of bytes to read
  208. ; Out:
  209. ;   CF=1 - Error reading file
  210. ;     EAX - ?
  211. ;   CF=0 - Read went fine
  212. ;     EAX - number of bytes read
  213. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  214. _readfile:
  215.         pushad
  216.         xor ebp,ebp
  217.         add edx,_code32a
  218.         lea ebx,[ecx+edx]
  219.         cmp ebx,100000h
  220.         ja readlong
  221.         mov eax,edx
  222.         shr eax,4
  223.         and dx,0fh
  224.         mov v86r_ds,ax
  225.         mov v86r_dx,dx
  226. readl:
  227.         mov eax,0fff0h
  228.         cmp eax,ecx
  229.         jbe readlf1
  230.         mov eax,ecx
  231. readlf1:
  232.         mov v86r_cx,ax
  233.         mov v86r_ax,3f00h
  234.         mov al,21h
  235.         int 33h
  236.         jc readdone2
  237.         movzx ebx,v86r_ax
  238.         add ebp,ebx
  239.         sub ecx,ebx
  240.         jbe readdone
  241.         or ebx,ebx
  242.         jz readdone
  243.         add v86r_ds,0fffh
  244.         jmp readl
  245. readlong:
  246.         mov edi,edx
  247.         sub edi,_code32a
  248.         mov edx,ecx
  249.         mov eax,_filebufloc
  250.         add eax,_code32a
  251.         mov ebx,eax
  252.         shr eax,4
  253.         and bx,0fh
  254.         mov v86r_ds,ax
  255.         mov v86r_dx,bx
  256.         movzx ebx,_filebuflen
  257. readlongl:
  258.         mov eax,ebx
  259.         cmp eax,edx
  260.         jbe readlonglf1
  261.         mov eax,edx
  262. readlonglf1:
  263.         mov v86r_cx,ax
  264.         mov v86r_ax,3f00h
  265.         mov al,21h
  266.         int 33h
  267.         jc short readdone2
  268.         movzx ecx,v86r_ax
  269.         add ebp,ecx
  270.         mov eax,ecx
  271.         or eax,eax
  272.         jz readdone
  273.         mov esi,_filebufloc
  274.         rep movsb
  275.         sub edx,eax
  276.         ja readlongl
  277. readdone:
  278.         clc
  279. readdone2:
  280.         mov [esp+28],ebp
  281.         popad
  282.         ret
  283. endif
  284.  
  285. ifdef   WRITEFILE
  286. public  _writefile
  287. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  288. ; Write to file
  289. ; In:
  290. ;   V86R_BX - file handle
  291. ;   EDX -> buffer to write from
  292. ;   ECX - number of bytes to write
  293. ; Out:
  294. ;   CF=1 - Error writing file
  295. ;     EAX - ?
  296. ;   CF=0 - Write went fine
  297. ;     EAX - number of bytes read
  298. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  299. _writefile:
  300.         pushad
  301.         xor ebp,ebp
  302.         add edx,_code32a
  303.         lea ebx,[ecx+edx]
  304.         cmp ebx,100000h
  305.         ja writelong
  306.         mov eax,edx
  307.         shr edx,4
  308.         and ax,0fh
  309.         mov v86r_ds,dx
  310.         mov v86r_dx,ax
  311. writel:
  312.         mov eax,0fff0h
  313.         cmp eax,ecx
  314.         jbe writelf1
  315.         mov eax,ecx
  316. writelf1:
  317.         mov v86r_cx,ax
  318.         mov v86r_ax,4000h
  319.         mov al,21h
  320.         int 33h
  321.         jc writedone2
  322.         movzx ebx,v86r_ax
  323.         add ebp,ebx
  324.         sub ecx,ebx
  325.         jbe writedone
  326.         add v86r_ds,0fffh
  327.         jmp writel
  328. writelong:
  329.         mov esi,edx
  330.         sub esi,_code32a
  331.         mov edx,ecx
  332.         mov eax,_filebufloc
  333.         add eax,_code32a
  334.         mov ebx,eax
  335.         shr eax,4
  336.         and bx,0fh
  337.         mov v86r_ds,ax
  338.         mov v86r_dx,bx
  339.         movzx ebx,_filebuflen
  340. writelongl:
  341.         mov eax,ebx
  342.         cmp eax,edx
  343.         jbe writelonglf1
  344.         mov eax,edx
  345. writelonglf1:
  346.         mov ecx,eax
  347.         mov edi,_filebufloc
  348.         rep movsb
  349.         mov v86r_cx,ax
  350.         mov v86r_ax,4000h
  351.         mov al,21h
  352.         int 33h
  353.         jc writedone2
  354.         movzx ecx,v86r_ax
  355.         add ebp,ecx
  356.         sub edx,ecx
  357.         ja writelongl
  358. writedone:
  359.         clc
  360. writedone2:
  361.         mov [esp+28],ebp
  362.         popad
  363.         ret
  364. endif
  365.  
  366. ifdef   FILECOPY
  367. public  _filecopy
  368. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  369. ; Copy some bytes from one file to another
  370. ; In:
  371. ;   V86R_SI - source file handle
  372. ;   V86R_DI - destination file handle
  373. ;   ECX - number of bytes to copy
  374. ; Out:
  375. ;   CF=1  - Error copying file
  376. ;     EAX - ?
  377. ;   CF=0  - copied fine
  378. ;     EAX - number of bytes copied
  379. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  380. _filecopy:
  381.         pushad
  382.         xor ebp,ebp
  383.         mov edx,_filebufloc
  384.         add edx,_code32a
  385.         mov al,dl
  386.         and ax,0fh
  387.         shr edx,4
  388.         mov v86r_ds,dx
  389.         mov v86r_dx,ax
  390.         movzx ebx,_filebuflen
  391. copylongl:
  392.         mov eax,ebx
  393.         cmp eax,ecx
  394.         jbe copylonglf1
  395.         mov eax,ecx
  396. copylonglf1:
  397.         mov v86r_cx,ax
  398.         mov v86r_ax,3f00h
  399.         mov ax,v86r_si
  400.         mov v86r_bx,ax
  401.         mov al,21h
  402.         int 33h
  403.         jc copydone2
  404.         mov ax,v86r_ax
  405.         or ax,ax
  406.         jz copydone
  407.         mov v86r_cx,ax
  408.         mov v86r_ax,4000h
  409.         mov ax,v86r_di
  410.         mov v86r_bx,ax
  411.         mov al,21h
  412.         int 33h
  413.         jc copydone2
  414.         movzx edx,v86r_ax
  415.         add ebp,edx
  416.         sub ecx,edx
  417.         ja copylongl
  418. copydone:
  419.         clc
  420. copydone2:
  421.         mov [esp+28],ebp
  422.         popad
  423.         ret
  424. endif
  425.  
  426. ifdef   FINDFILE
  427. public  _findfile
  428. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  429. ; Do an AH=4E findfirst
  430. ; In:
  431. ;   AL - type of search: 4E-first, 4F-next
  432. ;   CX - search attributes
  433. ;   EDX -> 13 byte buffer for filename found
  434. ;   EDI -> search mask
  435. ; Out:
  436. ;   CF=1 - file not found
  437. ;     [EDX] - ?
  438. ;   CF=0 - file found
  439. ;     [EDX] - filename
  440. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  441. _findfile:
  442.         push eax
  443.         push esi
  444.         push edi
  445.         add edi,_code32a
  446.         mov esi,edi
  447.         and esi,0fh
  448.         shr edi,4
  449.         mov v86r_ds,di
  450.         mov v86r_dx,si
  451.         mov v86r_ah,al
  452.         mov v86r_cx,cx
  453.         mov esi,_code16a
  454.         sub esi,62h
  455.         mov edi,edx
  456.         mov al,21h
  457.         int 33h
  458.         mov ax,gs
  459.         mov ds,ax
  460.         movsd
  461.         movsd
  462.         movsd
  463.         movsb
  464.         mov ax,es
  465.         mov ds,ax
  466.         pop edi
  467.         pop esi
  468.         pop eax
  469.         ret
  470. endif
  471.  
  472.  
  473. code32  ends
  474.         end
  475.  
  476.