48 lines
800 B
C
48 lines
800 B
C
#include"ram.h"
|
|
|
|
// Allocate RAM for read/write
|
|
ram_t*ram_init(void)
|
|
{
|
|
ram_t*ram=malloc(sizeof(ram_t));
|
|
if(!ram)
|
|
{
|
|
puterr("%s: Failed to allocate RAM\n",__func__);
|
|
return NULL;
|
|
}
|
|
ram->ram=malloc(0x10000);
|
|
if(!ram->ram)
|
|
{
|
|
puterr("%s: Failed to allocate memory for RAM\n",__func__);
|
|
//return ram;
|
|
}
|
|
return ram;
|
|
}
|
|
|
|
// Arithmetic Shift Left
|
|
void ram_asl(ram_t*ram,uint16_t byte)
|
|
{
|
|
ram->ram[byte]=ram->ram[byte]<<1;
|
|
}
|
|
|
|
// Logical Shift Right
|
|
void ram_lsr(ram_t*ram,uint16_t byte)
|
|
{
|
|
ram->ram[byte]=ram->ram[byte]>>1;
|
|
}
|
|
|
|
// Free data belonging to ram object
|
|
void ram_del(ram_t*ram)
|
|
{
|
|
if(!ram->ram)
|
|
{
|
|
puterr("%s: Attempting to free NULL memory\n",__func__);
|
|
return;
|
|
}
|
|
free(ram->ram);
|
|
}
|
|
|
|
uint16_t ram_indirect_address(ram_t*ram,uint16_t src)
|
|
{
|
|
return *(uint16_t*)(ram->ram+src);
|
|
}
|