-
Notifications
You must be signed in to change notification settings - Fork 0
/
alloc.c
executable file
·53 lines (44 loc) · 1.23 KB
/
alloc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "../wasm_libc_wrapper/stdio.h"
#include "../wasm_libc_wrapper/stdlib.h"
#include "../utils/exit_strategy.h"
#include "alloc.h"
/*
struct block_info {
uint32_t magic;
struct block_info *next; // 32-bit
uint16_t size; // in blocks of 16 bytes
};
*/
uint16_t nextfreeseg = 0x1000;
uint16_t lastallocseg = 0x0;
uint16_t AvailableRam() {
return 0x9FFE - nextfreeseg;
}
uint16_t Allocate(uint16_t paragraphs) {
lastallocseg = nextfreeseg;
nextfreeseg += paragraphs;
if (nextfreeseg >= 0xA000) {
printf("DOS Alloc: Error: Out of memory\n");
exit_or_restart(1);
}
return lastallocseg;
}
void Free(uint16_t seg) {
}
bool Modify(uint16_t seg, uint16_t paragraphs) {
if ((lastallocseg) != seg) {
printf("DOS Alloc: Cannot modify allocated memory block\n");
//exit_or_restart(1);
return false;
}
printf("DOS Alloc: currently alloated: %i segments, new %i segments\n", (nextfreeseg - lastallocseg), paragraphs);
nextfreeseg = seg + paragraphs;
return true;
}
void AllocInit()
{
//nextfreeseg = 0x1000;
//nextfreeseg = 0x020E; // dosbox start sector for executable
nextfreeseg = 0x01A2; // dosbox start sector for executable
lastallocseg = 0x0;
}