feat: initial version
This commit is contained in:
parent
0a67fb21d1
commit
ee790e99d6
12 changed files with 798 additions and 0 deletions
54
srcs/memory.c
Normal file
54
srcs/memory.c
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include "../hdrs/memory.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "../hdrs/font.h"
|
||||
#include "libft.h"
|
||||
|
||||
void memory_init(t_memory *mem)
|
||||
{
|
||||
ft_memset(mem->memory, 0, MEMORY_SIZE);
|
||||
}
|
||||
int memory_load_rom(t_memory *mem, FILE *fp)
|
||||
{
|
||||
fseek(fp, 0, SEEK_END);
|
||||
size_t rom_size = ftell(fp);
|
||||
rewind(fp);
|
||||
|
||||
if (rom_size > (sizeof(mem->memory) - 0x200))
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (fread(&mem->memory[0x200], 1, rom_size, fp) != rom_size)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void memory_clear_screen(t_memory *mem)
|
||||
{
|
||||
ft_memset(mem->screen, 0, SCREEN_WIDTH * SCREEN_HEIGHT);
|
||||
}
|
||||
|
||||
void memory_load_fontset(t_memory *mem)
|
||||
{
|
||||
ft_memcpy(&mem->memory[MEMORY_SIZE - FONTSET_SIZE], FONTSET, FONTSET_SIZE);
|
||||
}
|
||||
|
||||
|
||||
void memory_dump(t_memory *mem, const char *path)
|
||||
{
|
||||
FILE *fp = fopen(path, "wb");
|
||||
|
||||
if (!fp)
|
||||
{
|
||||
printf("Failed to open: %s\n", path);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fwrite(mem->memory, 1, MEMORY_SIZE, fp);
|
||||
fclose(fp);
|
||||
printf("Memory dumped to: %s\n", path);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue