// intellectual property is bullshit bgdc

// Storage interface. In the Poly-1, there is a single storage buffer, and it
// is locked when needed. This code manages locking and unlocking it and also
// moving data in and out of it.

#ifndef STOR_HPP
#define STOR_HPP

#include <stdbool.h>
#include <stddef.h>
#include <inttypes.h>

#define STOR_SIZE 512

// Buffer accessed by stor functions
extern          uint8_t  stor_buffer[STOR_SIZE];
// Cursor for user use. Cleared at lock
extern          size_t   stor_cursor;
// Block number memo for user user.
extern          uint32_t stor_block_memo;
extern volatile bool     stor_locked;

// Try to lock the buffer. Returns whether the lock was successfully acquired.
bool stor_try_lock();

// Unlock the buffer.
void stor_unlock();

// Read from raw storage into the buffer. Returns false on failure.
bool stor_read(size_t block);

// Write to raw storage from the buffer. Returns false on failure.
bool stor_write(size_t block);

#endif // !defined(STOR_HPP)
