meminter.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* $Id$
  2. * MegaZeux
  3. *
  4. * Copyright (C) 1996 Greg Janson
  5. * Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. //Interface to seamlessly replace FARMALLOC, FARFREE, and FARCORELEFT with
  22. //appropriate DOS calls.
  23. #include <dos.h>
  24. #include <_null.h>
  25. #include "meminter.h"
  26. #include "error.h"
  27. #include "data.h"
  28. unsigned long cdecl farcoreleft(void) {
  29. unsigned tmp;
  30. int tmp2;
  31. tmp2=allocmem(30000,&tmp);
  32. if(tmp2!=-1) return((long)(tmp2))*16l;
  33. freemem(tmp);
  34. return(30000l*16l);
  35. }
  36. void cdecl farfree(void far *__block) {
  37. freemem(FP_SEG(__block));
  38. }
  39. void far * cdecl farmalloc(unsigned long __nbytes) {
  40. unsigned seg;
  41. unsigned size=(__nbytes>>4)+1;
  42. if(allocmem(size,&seg)!=-1) return NULL;
  43. return(MK_FP(seg,0));
  44. }
  45. //For use by File funcs
  46. void cdecl free(void *__block) {
  47. freemem(FP_SEG(__block));
  48. }
  49. void *cdecl malloc(unsigned __nbytes) {
  50. unsigned seg;
  51. unsigned size=(__nbytes>>4)+1;
  52. if(allocmem(size,&seg)!=-1) return NULL;
  53. return(MK_FP(seg,0));
  54. }
  55. /*void *cdecl realloc(void *__block,unsigned __size) {
  56. error2("Error accessing boards",2,24,current_pg_seg,0x0702);
  57. }*/
  58. unsigned long cdecl coreleft (void) {
  59. unsigned tmp;
  60. int tmp2;
  61. tmp2=allocmem(30000,&tmp);
  62. if(tmp2!=-1) return((long)(tmp2))*16l;
  63. freemem(tmp);
  64. return(30000l*16l);
  65. }