098 renderer added
[fceu.git] / memory.c
CommitLineData
c62d2810 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
92764e62 4 * Copyright (C) 2002 Xodnizel
c62d2810 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"
92764e62 24#include "fce.h"
c62d2810 25#include "memory.h"
26#include "general.h"
27#include "svga.h"
28
92764e62 29void *FCEU_gmalloc(uint32 size)
30{
31 void *ret;
32 ret=malloc(size);
33 if(!ret)
34 {
35 FCEU_PrintError("Error allocating memory! Doing a hard exit.");
36 exit(1);
37 }
38 return ret;
39}
40
c62d2810 41void *FCEU_malloc(uint32 size)
42{
43 void *ret;
44 ret=malloc(size);
45 if(!ret)
92764e62 46 {
47 FCEU_PrintError("Error allocating memory!");
48 return(0);
49 }
c62d2810 50 return ret;
51}
52
92764e62 53void FCEU_free(void *ptr) // Might do something with this and FCEU_malloc later...
c62d2810 54{
55 free(ptr);
56}
57
92764e62 58void FCEU_gfree(void *ptr)
59{
60 free(ptr);
61}
5232c20c 62
c62d2810 63void FASTAPASS(3) FCEU_memmove(void *d, void *s, uint32 l)
64{
65 uint32 x;
66 int t;
67
68 /* Type really doesn't matter. */
69 t=(int)d;
70 t|=(int)s;
71 t|=(int)l;
72
92764e62 73 if(t&3) // Not 4-byte aligned and/or length is not a multiple of 4.
5232c20c 74 {
92764e62 75 uint8 *tmpd, *tmps;
5232c20c 76
77 tmpd = d;
78 tmps = s;
79
92764e62 80 for(x=l;x;x--) // This could be optimized further, though(more tests could be performed).
c62d2810 81 {
5232c20c 82 *tmpd=*tmps;
83 tmpd++;
84 tmps++;
85 }
92764e62 86 }
c62d2810 87 else
5232c20c 88 {
89 uint32 *tmpd, *tmps;
90
91 tmpd = d;
92 tmps = s;
93
c62d2810 94 for(x=l>>2;x;x--)
95 {
5232c20c 96 *tmpd=*tmps;
97 tmpd++;
98 tmps++;
c62d2810 99 }
92764e62 100 }
c62d2810 101}