home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / PMODE24.ZIP / LIBS.ZIP / FILE.ASM < prev    next >
Assembly Source File  |  1994-02-04  |  11KB  |  478 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      1000h
  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. ;   CF=1 - Error closing file
  95. ;   CF=0 - File closed succesfully
  96. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  97. _closefile:
  98.         push ax
  99.         mov v86r_ax,3e00h
  100.         mov al,21h
  101.         int 33h
  102.         pop ax
  103.         ret
  104.  
  105. ifdef   DELETEFILE
  106. public  _deletefile
  107. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  108. ; Delete a file
  109. ; In:
  110. ;   EDX -> ASCIIZ filename
  111. ; Out:
  112. ;   CF=1 - Error deleting file
  113. ;   CF=0 - File deleted succesfully
  114. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  115. _deletefile:
  116.         push ax
  117.         push edx
  118.         add edx,_code32a
  119.         mov ax,dx
  120.         shr edx,4
  121.         and ax,0fh
  122.         mov v86r_dx,ax
  123.         mov v86r_ds,dx
  124.         mov v86r_ah,41h
  125.         mov al,21h
  126.         int 33h
  127.         pop edx
  128.         pop ax
  129.         ret
  130. endif
  131.  
  132. ifdef   LSEEKFILE
  133. public  _lseekfile
  134. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  135. ; Seek position in file
  136. ; In:
  137. ;   V86R_BX - file handle
  138. ;   EAX - signed offset to move to
  139. ;   BL - from: 0-beginning of file, 1-current location, 2-end of file
  140. ; Out:
  141. ;   CF=1  - Error seeking in file
  142. ;     EAX - ?
  143. ;   CF=0  - Seek fine
  144. ;     EAX - new offset from beginning of file
  145. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  146. _lseekfile:
  147.         mov v86r_ah,42h
  148.         mov v86r_al,bl
  149.         mov v86r_dx,ax
  150.         shr eax,16
  151.         mov v86r_cx,ax
  152.         mov al,21h
  153.         int 33h
  154.         pushf
  155.         mov ax,v86r_dx
  156.         shl eax,16
  157.         mov ax,v86r_ax
  158.         popf
  159.         ret
  160. endif
  161.  
  162. ifdef   FILESIZE
  163. public  _filesize
  164. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  165. ; Get size of file
  166. ; In:
  167. ;   V86R_BX - file handle
  168. ; Out:
  169. ;   CF=1  - Error checking file
  170. ;     EAX - ?
  171. ;   CF=0  - check fine
  172. ;     EAX - size of file
  173. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  174. _filesize:
  175.         mov v86r_ax,4201h
  176.         xor eax,eax
  177.         mov v86r_cx,ax
  178.         mov v86r_dx,ax
  179.         mov al,21h
  180.         int 33h
  181.         push v86r_dx
  182.         push v86r_ax
  183.         mov v86r_ax,4202h
  184.         xor eax,eax
  185.         mov v86r_cx,ax
  186.         mov v86r_dx,ax
  187.         mov al,21h
  188.         int 33h
  189.         mov ax,v86r_dx
  190.         shl eax,16
  191.         mov ax,v86r_ax
  192.         pop v86r_dx
  193.         pop v86r_cx
  194.         mov v86r_ax,4200h
  195.         push eax
  196.         mov al,21h
  197.         int 33h
  198.         pop eax
  199.         ret
  200. endif
  201.  
  202. ifdef   READFILE
  203. public  _readfile
  204. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  205. ; Read from file
  206. ; In:
  207. ;   V86R_BX - file handle
  208. ;   EDX -> buffer to read to
  209. ;   ECX - number of bytes to read
  210. ; Out:
  211. ;   CF=1 - Error reading file
  212. ;     EAX - ?
  213. ;   CF=0 - Read went fine
  214. ;     EAX - number of bytes read
  215. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  216. _readfile:
  217.         pushad
  218.         xor ebp,ebp
  219.         add edx,_code32a
  220.         lea ebx,[ecx+edx]
  221.         cmp ebx,100000h
  222.         ja readlong
  223.         mov eax,edx
  224.         shr eax,4
  225.         and dx,0fh
  226.         mov v86r_ds,ax
  227.         mov v86r_dx,dx
  228. readl:
  229.         mov eax,0fff0h
  230.         cmp eax,ecx
  231.         jbe readlf1
  232.         mov eax,ecx
  233. readlf1:
  234.         mov v86r_cx,ax
  235.         mov v86r_ax,3f00h
  236.         mov al,21h
  237.         int 33h
  238.         jc readdone2
  239.         movzx ebx,v86r_ax
  240.         add ebp,ebx
  241.         sub ecx,ebx
  242.         jbe readdone
  243.         or ebx,ebx
  244.         jz readdone
  245.         add v86r_ds,0fffh
  246.         jmp readl
  247. readlong:
  248.         mov edi,edx
  249.         sub edi,_code32a
  250.         mov edx,ecx
  251.         mov eax,_filebufloc
  252.         add eax,_code32a
  253.         mov ebx,eax
  254.         shr eax,4
  255.         and bx,0fh
  256.         mov v86r_ds,ax
  257.         mov v86r_dx,bx
  258.         movzx ebx,_filebuflen
  259. readlongl:
  260.         mov eax,ebx
  261.         cmp eax,edx
  262.         jbe readlonglf1
  263.         mov eax,edx
  264. readlonglf1:
  265.         mov v86r_cx,ax
  266.         mov v86r_ax,3f00h
  267.         mov al,21h
  268.         int 33h
  269.         jc short readdone2
  270.         movzx ecx,v86r_ax
  271.         add ebp,ecx
  272.         mov eax,ecx
  273.         or eax,eax
  274.         jz readdone
  275.         mov esi,_filebufloc
  276.         rep movsb
  277.         sub edx,eax
  278.         ja readlongl
  279. readdone:
  280.         clc
  281. readdone2:
  282.         mov [esp+28],ebp
  283.         popad
  284.         ret
  285. endif
  286.  
  287. ifdef   WRITEFILE
  288. public  _writefile
  289. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  290. ; Write to file
  291. ; In:
  292. ;   V86R_BX - file handle
  293. ;   EDX -> buffer to write from
  294. ;   ECX - number of bytes to write
  295. ; Out:
  296. ;   CF=1 - Error writing file
  297. ;     EAX - ?
  298. ;   CF=0 - Write went fine
  299. ;     EAX - number of bytes written
  300. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  301. _writefile:
  302.         pushad
  303.         xor ebp,ebp
  304.         add edx,_code32a
  305.         lea ebx,[ecx+edx]
  306.         cmp ebx,100000h
  307.         ja writelong
  308.         mov eax,edx
  309.         shr edx,4
  310.         and ax,0fh
  311.         mov v86r_ds,dx
  312.         mov v86r_dx,ax
  313. writel:
  314.         mov eax,0fff0h
  315.         cmp eax,ecx
  316.         jbe writelf1
  317.         mov eax,ecx
  318. writelf1:
  319.         mov v86r_cx,ax
  320.         mov v86r_ax,4000h
  321.         mov al,21h
  322.         int 33h
  323.         jc writedone2
  324.         movzx ebx,v86r_ax
  325.         add ebp,ebx
  326.         sub ecx,ebx
  327.         jbe writedone
  328.         add v86r_ds,0fffh
  329.         jmp writel
  330. writelong:
  331.         mov esi,edx
  332.         sub esi,_code32a
  333.         mov edx,ecx
  334.         mov eax,_filebufloc
  335.         add eax,_code32a
  336.         mov ebx,eax
  337.         shr eax,4
  338.         and bx,0fh
  339.         mov v86r_ds,ax
  340.         mov v86r_dx,bx
  341.         movzx ebx,_filebuflen
  342. writelongl:
  343.         mov eax,ebx
  344.         cmp eax,edx
  345.         jbe writelonglf1
  346.         mov eax,edx
  347. writelonglf1:
  348.         mov ecx,eax
  349.         mov edi,_filebufloc
  350.         rep movsb
  351.         mov v86r_cx,ax
  352.         mov v86r_ax,4000h
  353.         mov al,21h
  354.         int 33h
  355.         jc writedone2
  356.         movzx ecx,v86r_ax
  357.         add ebp,ecx
  358.         sub edx,ecx
  359.         ja writelongl
  360. writedone:
  361.         clc
  362. writedone2:
  363.         mov [esp+28],ebp
  364.         popad
  365.         ret
  366. endif
  367.  
  368. ifdef   FILECOPY
  369. public  _filecopy
  370. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  371. ; Copy some bytes from one file to another
  372. ; In:
  373. ;   V86R_SI - source file handle
  374. ;   V86R_DI - destination file handle
  375. ;   ECX - number of bytes to copy
  376. ; Out:
  377. ;   CF=1  - Error copying file
  378. ;     EAX - ?
  379. ;   CF=0  - copied fine
  380. ;     EAX - number of bytes copied
  381. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  382. _filecopy:
  383.         pushad
  384.         xor ebp,ebp
  385.         mov edx,_filebufloc
  386.         add edx,_code32a
  387.         mov al,dl
  388.         and ax,0fh
  389.         shr edx,4
  390.         mov v86r_ds,dx
  391.         mov v86r_dx,ax
  392.         movzx ebx,_filebuflen
  393. copylongl:
  394.         mov eax,ebx
  395.         cmp eax,ecx
  396.         jbe copylonglf1
  397.         mov eax,ecx
  398. copylonglf1:
  399.         mov v86r_cx,ax
  400.         mov v86r_ax,3f00h
  401.         mov ax,v86r_si
  402.         mov v86r_bx,ax
  403.         mov al,21h
  404.         int 33h
  405.         jc copydone2
  406.         mov ax,v86r_ax
  407.         or ax,ax
  408.         jz copydone
  409.         mov v86r_cx,ax
  410.         mov v86r_ax,4000h
  411.         mov ax,v86r_di
  412.         mov v86r_bx,ax
  413.         mov al,21h
  414.         int 33h
  415.         jc copydone2
  416.         movzx edx,v86r_ax
  417.         add ebp,edx
  418.         sub ecx,edx
  419.         ja copylongl
  420. copydone:
  421.         clc
  422. copydone2:
  423.         mov [esp+28],ebp
  424.         popad
  425.         ret
  426. endif
  427.  
  428. ifdef   FINDFILE
  429. public  _findfile
  430. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  431. ; Do an AH=4E file find
  432. ; In:
  433. ;   AL - type of search: 4E-first, 4F-next
  434. ;   CX - search attributes
  435. ;   EDX -> 13 byte buffer for filename found
  436. ;   EDI -> search mask
  437. ; Out:
  438. ;   CF=1 - file not found
  439. ;     [EDX] - ?
  440. ;   CF=0 - file found
  441. ;     [EDX] - filename
  442. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  443. _findfile:
  444.         push eax
  445.         push esi
  446.         push edi
  447.         add edi,_code32a
  448.         mov esi,edi
  449.         and esi,0fh
  450.         shr edi,4
  451.         mov v86r_ds,di
  452.         mov v86r_dx,si
  453.         mov v86r_ah,al
  454.         mov v86r_cx,cx
  455.         mov esi,_code16a
  456.         sub esi,62h
  457.         mov edi,edx
  458.         mov al,21h
  459.         int 33h
  460.         mov ax,gs
  461.         mov ds,ax
  462.         movsd
  463.         movsd
  464.         movsd
  465.         movsb
  466.         mov ax,es
  467.         mov ds,ax
  468.         pop edi
  469.         pop esi
  470.         pop eax
  471.         ret
  472. endif
  473.  
  474.  
  475. code32  ends
  476.         end
  477.  
  478.