bec72700d7d7e52bbb8983d2cd7b84bab5e0ffe2
[fceu.git] / memory.c
1 /* FCE Ultra - NES/Famicom Emulator
2  *
3  * Copyright notice for this file:
4  *  Copyright (C) 2002 Ben Parnell
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdlib.h>
22
23 #include "types.h"
24 #include "version.h"
25 #include "memory.h"
26 #include "general.h"
27 #include "svga.h"
28
29 void *FCEU_malloc(uint32 size)
30 {
31  void *ret;
32  ret=malloc(size);
33  if(!ret)
34   FCEU_PrintError(MSG_ERRAM);
35  return ret;
36 }
37
38 void FCEU_free(void *ptr)               // Might do something with this and FCEU_malloc later...
39 {
40  free(ptr);
41 }
42
43 void FASTAPASS(3) FCEU_memmove(void *d, void *s, uint32 l)
44 {
45  uint32 x;
46  int t;
47
48  /* Type really doesn't matter. */
49  t=(int)d;
50  t|=(int)s;
51  t|=(int)l;
52
53  if(t&3)          // Not 4-byte aligned and/or length is not a multiple of 4.
54   for(x=l;x;x--)        // This could be optimized further, though(more tests could be performed).
55   {
56    *(uint8*)d=*(uint8 *)s;
57    ((uint8 *)d)++;
58    ((uint8 *)s)++;
59   }
60  else
61   for(x=l>>2;x;x--)
62   {
63    *(uint32*)d=*(uint32*)s;
64    ((uint32 *)d)++;
65    ((uint32 *)s)++;
66   }
67 }