Browse Source

Another try at the emulator memory…

Thomas Buck 12 years ago
parent
commit
1299f069cb
1 changed files with 9 additions and 12 deletions
  1. 9
    12
      HardwareEmulator/mem.c

+ 9
- 12
HardwareEmulator/mem.c View File

@@ -16,29 +16,26 @@ int frameCount = 0;
16 16
 
17 17
 // return != 0 if error
18 18
 int addFrame(char *frame) {
19
-	char *newMem, *oldMem = mem;
20
-	int i;
19
+	char *newMem;
21 20
 
22
-	frameCount++;
23
-
24
-	if (oldMem != NULL) {
25
-		newMem = (char *)malloc(65 * frameCount);
21
+	if (mem != NULL) {
22
+		newMem = (char *)malloc(65 * (frameCount + 1));
26 23
 		if (newMem == NULL) {
27 24
 			return 1;
28 25
 		}
29
-		memcpy(newMem, oldMem, 65 * (frameCount - 1)); // Copy old frames
30
-		free(oldMem);
26
+		memcpy(newMem, mem, 65 * frameCount); // Copy old frames
27
+		free(mem);
31 28
 	} else {
32
-		// oldMem == NULL
33
-		frameCount = 1;
34
-		newMem = (char *)malloc(65);
29
+		frameCount = 0;
30
+		newMem = (char *)malloc(65 * (frameCount + 1));
35 31
 		if (newMem == NULL) {
36 32
 			return 1;
37 33
 		}
38 34
 	}
39 35
 
40
-	memcpy((newMem + (65 * (frameCount - 1))), frame, 65); // Add new frame
36
+	memcpy((newMem + (65 * frameCount)), frame, 65); // Add new frame
41 37
 
38
+	frameCount++;
42 39
 	mem = newMem;
43 40
 	return 0;
44 41
 }

Loading…
Cancel
Save