#ifndef MEMC_H
#define MEMC_H

#include "heap.h"

#define MEMC_CHUNK_ROM 0
#define MEMC_CHUNK_RMA 1
#define MEMC_CHUNK_APP 2
#define MEMC_CHUNK_SYSTEM 3
#define MEMC_CHUNK_ZERO 4
#define MEMC_CHUNK_SCREEN 5
#define MEMC_CHUNK_SPRITE 6
#define MEMC_CHUNK_FONT 7
#define MEMC_CHUNK_RAMFS 8
#define MEMC_CHUNK_FREE 9

// Memory controller class
class MEMC
{
 public:
  struct memchunk
  {
    char name[16]; // Name of chunk
    void *base; // Base address of allocated block
    uint32_t size; // Size of block in bytes;
    uint32_t maxsize; // Maximum size of block in bytes
  };

  // The main RISC OS memory areas
  struct memchunk memory_map[16];

  Heap *rma_heap; // RMA is heap managed
  Heap *system_heap; // System memory is heap managed

  void *svc_stack; // Stack space reserved for SVC mode
  void *irq_stack; // Stack space reserved for IRQ mode
  void *fiq_stack; // Stack space reserved for FIQ mode

  // Point to the top of stack space because we use full-descending
  // stacks.
  void *svc_stack_top, *irq_stack_top, *fiq_stack_top;

  // Pointer to an SWI instruction that will return control to a
  // previously executing SWI.
  void *swi_code_return;

  // Buffer contains private words for each initialised module
  void *module_private_word; 

  void *error_buf; // Memory block for errors
  uint32_t memory_size; // Total RISC OS wimpslot size.
  void *wimpslot; // Main application memory.

  MEMC (int os_version);
  struct memchunk Alloc (const char *name,
			 uint32_t start, uint32_t length, uint32_t maxsize);
  void Resize (int chunk, uint32_t extent);
  void Free (uint32_t start);
};
#endif
