diff --git a/build.bat b/build.bat index 3f135f8..ec2a292 100644 --- a/build.bat +++ b/build.bat @@ -8,6 +8,6 @@ pushd .\build set links= kernel32.lib -cl ..\src\eightysix.c /Feeightysix.exe /nologo /link %links% +cl /Zi ..\src\eightysix.c /Feeightysix.exe /nologo /link %links% popd .\build diff --git a/src/base.c b/src/base.c new file mode 100644 index 0000000..fb9ba67 --- /dev/null +++ b/src/base.c @@ -0,0 +1,29 @@ + +internal void +arena_init(Arena *arena, u8 *backing_buffer, i32 size) +{ + arena->backing_buffer = backing_buffer; + arena->offset = 0; + arena->size = size; +} + +internal void * +arena_alloc(Arena *arena, i32 size) +{ + void *result = 0; + + if (arena->offset + size <= arena->size) { + result = &arena->backing_buffer[arena->offset]; + arena->offset += size; + } else { + printf("Arena ran out of memory\n"); + } + + return result; +} + +internal void +arena_release(Arena *arena) +{ + arena->offset = 0; +} diff --git a/src/base.h b/src/base.h new file mode 100644 index 0000000..b68df4f --- /dev/null +++ b/src/base.h @@ -0,0 +1,54 @@ +#ifndef BASE_H +#define BASE_H + +#include +#include + +//= rhjr: types + +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; + +typedef int8_t i8; +typedef int16_t i16; +typedef int32_t i32; +typedef int64_t i64; + +typedef uint8_t b8; +typedef uint16_t b16; +typedef uint32_t b32; +typedef uint64_t b64; + +#define internal static +#define global static + +//= rhjr: allocator + +#define ARENA_DEFAULT_SIZE 2048 + +typedef struct Arena +{ + u8 *backing_buffer; + i32 offset; + i32 size; +} +Arena; + +internal void arena_init(Arena *arena, u8 *backing_buffer, i32 size); +internal void * arena_alloc(Arena *arena, i32 size); +internal void arena_release(Arena *arena); + +//= rhjr: strings + +typedef struct String8 +{ + u8* contents; + i32 length; +} +String8; + + + +#endif // BASE_H diff --git a/src/eightysix.c b/src/eightysix.c index 18a8036..ea61ddb 100644 --- a/src/eightysix.c +++ b/src/eightysix.c @@ -1,23 +1,33 @@ -j + //= rhjr: [h] +#include "base.h" #include "eightysix.h" -#include "win32_platform.h" +#include "platform/win32_platform.h" //= rhjr: [c] -#include "win32_platform.c" +#include "base.c" +#include "platform/win32_platform.c" -u8 backing_buffer[2048]; +u8 backing_buffer[ARENA_DEFAULT_SIZE]; int main(void) { Arena arena = {0}; - arena.backing_buffer = &backing_buffer[0]; - arena.offset = 0; - arena.size = 2048; + arena_init(&arena, &backing_buffer[0], ARENA_DEFAULT_SIZE); + i64 *idx = arena_alloc(&arena, sizeof(i64)); + *idx = 69; + + i64 *idx2 = arena_alloc(&arena, 2 * sizeof(i64)); + *idx2++ = 69; + + i64 *idx3 = arena_alloc(&arena, sizeof(i64)); + *idx3 = 124; + + *idx2 = 139; return 0; } diff --git a/src/eightysix.h b/src/eightysix.h index 6f23ff5..12ae8de 100644 --- a/src/eightysix.h +++ b/src/eightysix.h @@ -1,46 +1,6 @@ #ifndef EIGHTYSIX_CORE_H #define EIGHTYSIX_CORE_H -#include -#include - -//= rhjr: types - -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; - -typedef int8_t i8; -typedef int16_t i16; -typedef int32_t i32; -typedef int64_t i64; - -typedef uint8_t b8; -typedef uint16_t b16; -typedef uint32_t b32; -typedef uint64_t b64; - -#define internal static -#define global static - -typedef struct String8 -{ - u8* contents; - i32 length; -} -String8; - -//= rhjr: allocator - -typedef struct Arena -{ - u8 *backing_buffer; - i32 offset; - i32 size; -} -Arena; - //= rhjr: instructions. // Intel 8086 manual, pg. 4-22 diff --git a/src/win32_platform.c b/src/platform/win32_platform.c similarity index 60% rename from src/win32_platform.c rename to src/platform/win32_platform.c index 7aa2186..a9075bf 100644 --- a/src/win32_platform.c +++ b/src/platform/win32_platform.c @@ -1,6 +1,6 @@ String8 * -platform_write_file() +platform_write_file(Arena *arena) { String8 *result; diff --git a/src/win32_platform.h b/src/platform/win32_platform.h similarity index 100% rename from src/win32_platform.h rename to src/platform/win32_platform.h