some warnings fixed, nsf fixed, palettes, more code backported
[fceu.git] / memory.c
... / ...
CommitLineData
1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Xodnizel
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 "fce.h"
25#include "memory.h"
26#include "general.h"
27#include "svga.h"
28
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
41void *FCEU_malloc(uint32 size)
42{
43 void *ret;
44 ret=malloc(size);
45 if(!ret)
46 {
47 FCEU_PrintError("Error allocating memory!");
48 return(0);
49 }
50 return ret;
51}
52
53void FCEU_free(void *ptr) // Might do something with this and FCEU_malloc later...
54{
55 free(ptr);
56}
57
58void FCEU_gfree(void *ptr)
59{
60 free(ptr);
61}
62
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
73 if(t&3) // Not 4-byte aligned and/or length is not a multiple of 4.
74 {
75 uint8 *tmpd, *tmps;
76
77 tmpd = d;
78 tmps = s;
79
80 for(x=l;x;x--) // This could be optimized further, though(more tests could be performed).
81 {
82 *tmpd=*tmps;
83 tmpd++;
84 tmps++;
85 }
86 }
87 else
88 {
89 uint32 *tmpd, *tmps;
90
91 tmpd = d;
92 tmps = s;
93
94 for(x=l>>2;x;x--)
95 {
96 *tmpd=*tmps;
97 tmpd++;
98 tmps++;
99 }
100 }
101}