#ifndef MEMORY_H
#define MEMORY_H
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#include <stdbool.h>
#include <SDL3/SDL.h>
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif
#ifndef PAGE_WIDTH
#define PAGE_WIDTH 256
#endif
#define PAGE_HEIGHT (PAGE_SIZE * CHAR_BIT / PAGE_WIDTH)
typedef struct page {
struct page_list *l;
uintptr_t address;
SDL_Texture *tex;
uint64_t hash;
bool in_use;
struct page *next;
} page;
typedef struct page_list {
int fd;
page *first;
} page_list;
uintptr_t to_addr(int x, int y);
void to_pos(uintptr_t addr, int *x, int *y);
int init_page_list(page_list *l, int fd);
page *get_page(page_list *l, uintptr_t addr);
void free_unused_pages(page_list *l);
SDL_Texture *get_texture(page *p);
void free_page_list(page_list *l);
void draw_line(page_list *l,
double x1, double y1, double x2, double y2, bool bit);
#endif