1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include "mem.h"
-
- char *mem = NULL;
- int frameCount = 0;
-
-
- int addFrame(char *frame) {
- char *newMem;
-
- if (mem != NULL) {
- newMem = (char *)malloc(65 * (frameCount + 1));
- if (newMem == NULL) {
- return 1;
- }
- memcpy(newMem, mem, 65 * frameCount);
- free(mem);
- } else {
- frameCount = 0;
- newMem = (char *)malloc(65 * (frameCount + 1));
- if (newMem == NULL) {
- return 1;
- }
- }
-
- memcpy((newMem + (65 * frameCount)), frame, 65);
-
- frameCount++;
- mem = newMem;
- return 0;
- }
-
-
- char *getFrame(int index) {
- if (index >= frameCount) {
- return NULL;
- } else if (mem == NULL) {
- return NULL;
- } else {
- return (mem + (65 * index));
- }
- }
-
- int framesStored() {
- return frameCount;
- }
-
- void clearMemory() {
- free(mem);
- mem = NULL;
- frameCount = 0;
- }
|