Project

General

Profile

46 markw
#include "freeze.h"

47 markw
#include "regs.h"
180 markw
#include "memory.h"
47 markw
48 markw
unsigned volatile char * store_mem;
47 markw
unsigned volatile char * custom_mirror;
unsigned volatile char * atari_base;

189 markw
// TODO - almost the same as 5200 one
// skctl, chbase and lack of portb to merge into one file...

195 markw
void memset8(void * address, int value, int length);

// Moving this outside function removes gcc pulling in memcpy
unsigned char dl[] = {
0x70,
0x70,
864 markw
0x47,0x40,0x0c,
195 markw
0x70,
864 markw
0x42,0x68,0x0c,
195 markw
0x2,0x2,0x2,0x2,0x2,
0x2,0x2,0x2,0x2,0x2,
0x2,0x2,0x2,0x2,0x2,
0x2,0x2,0x2,0x2,0x2,
0x2,0x2,
0x41,0x00,0x06
};

47 markw
void freeze_init(void * memory)
46 markw
{
48 markw
store_mem = (unsigned volatile char *)memory;
46 markw
47 markw
custom_mirror = (unsigned volatile char *)atari_regmirror;
atari_base = (unsigned volatile char *)atari_regbase;
}
46 markw
195 markw
void memcp8(char const volatile * from, char volatile * to, int offset, int len)
{
from+=offset;
to+=offset;
while (len--)
*to++ = *from++;
}

47 markw
void freeze()
{
int i;
46 markw
// store custom chips
350 markw
store_mem[0xd300] = *atari_portb;
46 markw
{
195 markw
//backup last value written to custom chip regs
46 markw
//gtia
195 markw
memcp8(custom_mirror,store_mem,0xd000,0x20);
46 markw
//pokey1/2
195 markw
memcp8(custom_mirror,store_mem,0xd200,0x20);
46 markw
//antic
195 markw
memcp8(custom_mirror,store_mem,0xd400,0x10);

// Write 0 to custom chip regs
memset8(atari_base+0xd000,0,0x20);
memset8(atari_base+0xd200,0,0x20);
memset8(atari_base+0xd400,0,0x10);
46 markw
}

47 markw
*atari_portb = 0xff;

// Copy 64k ram to sdram
// Atari screen memory...
195 markw
memcp8(atari_base,store_mem,0,0xd000);
memcp8(atari_base,store_mem,0xd800,0x2800);
47 markw
//Clear, except dl (first 0x40 bytes)
55 markw
clearscreen();
47 markw
46 markw
// Put custom chips in a safe state
55 markw
// write a display list at 0600
195 markw
memcp8(dl,atari_base+0x600,0,sizeof(dl));
46 markw
// point antic at my display list
55 markw
*atari_dlisth = 0x06;
46 markw
*atari_dlistl = 0x00;
55 markw
46 markw
*atari_colbk = 0x00;
55 markw
*atari_colpf0 = 0x2f;
*atari_colpf1 = 0x3f;
46 markw
*atari_colpf2 = 0x00;
55 markw
*atari_colpf3 = 0x1f;
46 markw
*atari_prior = 0x00;
*atari_chbase = 0xe0;
*atari_dmactl = 0x22;
*atari_skctl = 0x3;
*atari_chactl = 0x2;
}

void restore()
{
// Restore memory
195 markw
memcp8(store_mem,atari_base,0,0xd000);
memcp8(store_mem,atari_base,0xd800,0x2800);
46 markw
// Restore custom chips
{
195 markw
// gtia
memcp8(store_mem,atari_base,0xd000,0x20);
// pokey
memcp8(store_mem,atari_base,0xd200,0x20);
// antic
memcp8(store_mem,atari_base,0xd400,0x10);
46 markw
}

350 markw
*atari_portb = store_mem[0xd300];
46 markw
}

350 markw
void freeze_save(struct SimpleFile * file)
{
if (file_size(file)>=65536 && file_readonly(file)==0)
{
int byteswritten = 0;
file_write(file,(void *)store_mem,65536,&byteswritten);
file_write_flush();
}
}
void freeze_load(struct SimpleFile * file)
{
if (file_size(file)>=65536)
{
int bytesread = 0;
file_read(file,(void *)store_mem,65536,&bytesread);
}
}


/*
enum SimpleFileStatus file_read(struct SimpleFile * file, void * buffer, int bytes, int * bytesread);

enum SimpleFileStatus file_write(struct SimpleFile * file, void * buffer, int bytes, int * byteswritten);
enum SimpleFileStatus file_write_flush();
*/