First commit, porting from PaCO

This commit is contained in:
2021-04-27 19:02:20 +02:00
commit f1f590735b
11 changed files with 1283 additions and 0 deletions

48
heap.cpp Normal file
View File

@@ -0,0 +1,48 @@
#include "heap.h"
#include <stdlib.h>
static int heap_size = 0;
static int heap_address = 0;
static char* heap_mem = NULL;
void heap_init() {
heap_size = 0;
heap_address = 0;
if (heap_mem != NULL) { free(heap_mem); heap_mem = NULL; }
}
const int heap_get_address() {
return heap_address;
}
void heap_reserve(const int size) {
heap_size += size;
heap_address += size;
}
const int heap_get_size() {
return heap_size;
}
void heap_alloc() {
if (heap_mem == NULL) heap_mem = (char*)malloc(heap_size);
}
const float heap_get_float(const int address) {
return (float)heap_mem[address];
}
const char* heap_get_string(const int address) {
return &heap_mem[address];
}
void heap_set_float(const int address, const float value) {
*(float*)&heap_mem[address] = value;
//float *f = (float*)&heap_mem[address];
//*f = value;
}
void heap_set_string(const int address, const char* value) {
const int size = *value;
for (int i = 0; i <= size; i++) { heap_mem[address+i] = value[i]; }
}