Project

General

Profile

« Previous | Next » 

Revision 189

Added by markw almost 11 years ago

Started merging in 5200 firmware changes. A800 firmware tested working. 5200 firmware not working, but likely a small fix...

View differences:

firmware/joystick.c
#include "joystick.h"
#include "regs.h"
//#include <stdio.h>
void joystick_poll(struct joystick_status * status)
{
status->x_ = 0;
status->y_ = 0;
status->fire_ = 0;
unsigned char porta = *atari_porta;
status->y_ = !(porta&0x2) -((unsigned int)!(porta&0x1));
status->x_ = !(porta&0x8) -((unsigned int)!(porta&0x4));
status->fire_ = !(1&*atari_trig0);
//if (porta != 0xff)
//printf("%02x %x %x %x\n",porta,status->x_,status->y_,status->fire_);
/*
if (0==(porta&0x2)) // down
{
status->y_ =1;
}
else if (0==(porta&0x1)) // up
{
status->y_ =-1;
}
if (0==(porta&0x8)) // right
{
status->x_ = 1;
}
else if (0==(porta&0x4)) // left
{
status->x_ = -1;
}
if (0==(1&*atari_trig0)) // fire
{
status->fire_ = 1;
}
*/
}
void joystick_wait(struct joystick_status * status, enum JoyWait waitFor)
{
while (1)
{
joystick_poll(status);
switch (waitFor)
{
case WAIT_QUIET:
if (status->x_ == 0 && status->y_ == 0 && status->fire_ == 0) return;
break;
case WAIT_FIRE:
if (status->fire_ == 1) return;
break;
case WAIT_EITHER:
if (status->fire_ == 1) return;
// fall through
case WAIT_MOVE:
if (status->x_ !=0 || status->y_ != 0) return;
break;
}
}
}
firmware/regs.c
#include "regs.h"
#include "memory.h"
int volatile * zpu_in1 = (int *)(0*4+config_regbase);
int volatile * zpu_in2 = (int *)(1*4+config_regbase);
int volatile * zpu_in3 = (int *)(2*4+config_regbase);
int volatile * zpu_in4 = (int *)(3*4+config_regbase);
int volatile * zpu_out1 = (int *)(4*4+config_regbase);
int volatile * zpu_out2 = (int *)(5*4+config_regbase);
int volatile * zpu_out3 = (int *)(6*4+config_regbase);
int volatile * zpu_out4 = (int *)(7*4+config_regbase);
int volatile * zpu_pause = (int *)(8*4+config_regbase);
int volatile * zpu_spi_data = (int *)(9*4+config_regbase);
int volatile * zpu_spi_state = (int *)(10*4+config_regbase);
int volatile * zpu_sio = (int *)(11*4+config_regbase);
int volatile * zpu_board = (int *)(12*4+config_regbase);
int volatile * zpu_spi_dma = (int *)(13*4+config_regbase);
unsigned char volatile * zpu_pokey_audf0 = (unsigned char *)(0x10*4+config_regbase);
unsigned char volatile * zpu_pokey_audc0 = (unsigned char *)(0x11*4+config_regbase);
unsigned char volatile * zpu_pokey_audf1 = (unsigned char *)(0x12*4+config_regbase);
unsigned char volatile * zpu_pokey_audc1 = (unsigned char *)(0x13*4+config_regbase);
unsigned char volatile * zpu_pokey_audf2 = (unsigned char *)(0x14*4+config_regbase);
unsigned char volatile * zpu_pokey_audc2 = (unsigned char *)(0x15*4+config_regbase);
unsigned char volatile * zpu_pokey_audf3 = (unsigned char *)(0x16*4+config_regbase);
unsigned char volatile * zpu_pokey_audc3 = (unsigned char *)(0x17*4+config_regbase);
unsigned char volatile * zpu_pokey_audctl = (unsigned char *)(0x18*4+config_regbase);
unsigned char volatile * zpu_pokey_skrest = (unsigned char *)(0x1a*4+config_regbase);
unsigned char volatile * zpu_pokey_serout = (unsigned char *)(0x1d*4+config_regbase);
unsigned char volatile * zpu_pokey_irqen = (unsigned char *)(0x1e*4+config_regbase);
unsigned char volatile * zpu_pokey_skctl = (unsigned char *)(0x1f*4+config_regbase);
unsigned char volatile * atari_nmien = (unsigned char *)(0xd40e + atari_regbase);
unsigned char volatile * atari_dlistl = (unsigned char *)(0xd402 + atari_regbase);
unsigned char volatile * atari_dlisth = (unsigned char *)(0xd403 + atari_regbase);
unsigned char volatile * atari_colbk = (unsigned char *)(0xd01a + atari_regbase);
unsigned char volatile * atari_colpf1 = (unsigned char *)(0xd017 + atari_regbase);
unsigned char volatile * atari_colpf2 = (unsigned char *)(0xd018 + atari_regbase);
unsigned char volatile * atari_colpf3 = (unsigned char *)(0xd019 + atari_regbase);
unsigned char volatile * atari_colpf0 = (unsigned char *)(0xd016 + atari_regbase);
unsigned char volatile * atari_prior = (unsigned char *)(0xd01b + atari_regbase);
unsigned char volatile * atari_random = (unsigned char *)(0xd20a + atari_regbase);
unsigned char volatile * atari_porta = (unsigned char *)(0xd300 + atari_regbase);
unsigned char volatile * atari_portb = (unsigned char *)(0xd301 + atari_regbase);
unsigned char volatile * atari_trig0 = (unsigned char *)(0xd010 + atari_regbase);
unsigned char volatile * atari_chbase = (unsigned char *)(0xd409 + atari_regbase);
unsigned char volatile * atari_chactl = (unsigned char *)(0xd401 + atari_regbase);
unsigned char volatile * atari_dmactl = (unsigned char *)(0xd400 + atari_regbase);
unsigned char volatile * atari_skctl = (unsigned char *)(0xd20f + atari_regbase);
firmware/freeze.c
#include "freeze.h"
#include "regs.h"
#include "memory.h"
unsigned char store_portb;
unsigned volatile char * store_mem;
unsigned volatile char * custom_mirror;
unsigned volatile char * atari_base;
void freeze_init(void * memory)
{
store_mem = (unsigned volatile char *)memory;
custom_mirror = (unsigned volatile char *)atari_regmirror;
atari_base = (unsigned volatile char *)atari_regbase;
}
void freeze()
{
int i;
// store custom chips
store_portb = *atari_portb;
{
//gtia
for (i=0xd000; i!=0xd020; i++)
{
store_mem[i] = custom_mirror[i];
atari_base[i] = 0;
}
//pokey1/2
for (i=0xd200; i!=0xd220; i++)
{
store_mem[i] = custom_mirror[i];
atari_base[i] = 0;
}
//antic
for (i=0xd400; i!=0xd410; i++)
{
store_mem[i] = custom_mirror[i];
atari_base[i] = 0;
}
}
*atari_portb = 0xff;
// Copy 64k ram to sdram
// Atari screen memory...
for (i=0x0; i!=0xd000; ++i)
{
store_mem[i] = atari_base[i];
}
for (i=0xd800; i!=0x10000; ++i)
{
store_mem[i] = atari_base[i];
}
//Clear, except dl (first 0x40 bytes)
clearscreen();
// Put custom chips in a safe state
// write a display list at 0600
unsigned char dl[] = {
0x70,
0x70,
0x47,0x40,0x9c,
0x70,
0x42,0x68,0x9c,
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
};
int j = 0;
for (i=0x0600; j!=sizeof(dl); ++i,++j)
{
atari_base[i] = dl[j];
}
// point antic at my display list
*atari_dlisth = 0x06;
*atari_dlistl = 0x00;
*atari_colbk = 0x00;
*atari_colpf0 = 0x2f;
*atari_colpf1 = 0x3f;
*atari_colpf2 = 0x00;
*atari_colpf3 = 0x1f;
*atari_prior = 0x00;
*atari_chbase = 0xe0;
*atari_dmactl = 0x22;
*atari_skctl = 0x3;
*atari_chactl = 0x2;
}
void restore()
{
int i;
// Restore memory
for (i=0x0; i!=0xd000; ++i)
{
atari_base[i] = store_mem[i];
}
for (i=0xd800; i!=0x10000; ++i)
{
atari_base[i] = store_mem[i];
}
// Restore custom chips
{
//gtia
for (i=0xd000; i!=0xd020; i++)
{
atari_base[i] = store_mem[i];
}
//pokey1/2
for (i=0xd200; i!=0xd220; i++)
{
atari_base[i] = store_mem[i];
}
//antic
for (i=0xd400; i!=0xd410; i++)
{
atari_base[i] = store_mem[i];
}
}
*atari_portb = store_portb;
}
firmware/main.c
#include <alloca.h>
#include <sys/types.h>
#include "integer.h"
#include "regs.h"
#include "pause.h"
#include "printf.h"
#include "joystick.h"
#include "freeze.h"
#include "simpledir.h"
#include "simplefile.h"
#include "fileselector.h"
#ifdef LINUX_BUILD
#include "curses_screen.h"
#define after_set_reg_hook() display_out_regs()
#else
#define after_set_reg_hook() do { } while(0)
#endif
#include "atari_drive_emulator.h"
#include "memory.h"
extern char ROM_DIR[];
// FUNCTIONS in here
// i) pff init - NOT USED EVERYWHERE
// ii) file selector - kind of crap, no fine scrolling - NOT USED EVERYWHERE
// iii) cold reset atari (clears base ram...)
// iv) start atari (begins paused)
// v) freeze/resume atari - NOT USED EVERYWHERE!
// vi) menu for various options - NOT USED EVERYWHERE!
// vii) pause - TODO - base this on pokey clock...
// standard ZPU IN/OUT use...
// OUT1 - 6502 settings (pause,reset,speed)
// pause_n: bit 0
// reset_n: bit 1
// turbo: bit 2-4: meaning... 0=1.79Mhz,1=3.58MHz,2=7.16MHz,3=14.32MHz,4=28.64MHz,5=57.28MHz,etc.
// ram_select: bit 5-7:
// RAM_SELECT : in std_logic_vector(2 downto 0); -- 64K,128K,320KB Compy, 320KB Rambo, 576K Compy, 576K Rambo, 1088K, 4MB
// rom_select: bit 8-13:
// ROM_SELECT : in std_logic_vector(5 downto 0); -- 16KB ROM Bank
#define BIT_REG(op,mask,shift,name,reg) \
int get_ ## name() \
{ \
int val = *reg; \
return op((val>>shift)&mask); \
} \
void set_ ## name(int param) \
{ \
int val = *reg; \
\
val = (val&~(mask<<shift)); \
val |= op(param)<<shift; \
\
*reg = val; \
after_set_reg_hook(); \
}
#define BIT_REG_RO(op,mask,shift,name,reg) \
int get_ ## name() \
{ \
int val = *reg; \
return op((val>>shift)&mask); \
}
BIT_REG(,0x1,0,pause_6502,zpu_out1)
BIT_REG(,0x1,1,reset_6502,zpu_out1)
BIT_REG(,0x3f,2,turbo_6502,zpu_out1)
BIT_REG(,0x7,8,ram_select,zpu_out1)
BIT_REG(,0x3f,11,rom_select,zpu_out1)
BIT_REG_RO(,0x1,8,hotkey_softboot,zpu_in1)
BIT_REG_RO(,0x1,9,hotkey_coldboot,zpu_in1)
BIT_REG_RO(,0x1,10,hotkey_fileselect,zpu_in1)
BIT_REG_RO(,0x1,11,hotkey_settings,zpu_in1)
void
wait_us(int unsigned num)
{
// pause counter runs at pokey frequency - should be 1.79MHz
int unsigned cycles = (num*230)>>7;
*zpu_pause = cycles;
}
void memset8(void * address, int value, int length)
{
char * mem = address;
while (length--)
*mem++=value;
}
void memset32(void * address, int value, int length)
{
int * mem = address;
while (length--)
*mem++=value;
}
void clear_64k_ram()
{
memset8(SRAM_BASE, 0, 65536); // SRAM, if present (TODO)
memset32(SDRAM_BASE, 0, 16384);
}
void
reboot(int cold)
{
set_pause_6502(1);
if (cold)
{
clear_64k_ram();
}
set_reset_6502(1);
// Do nothing in here - this resets the memory controller!
set_reset_6502(0);
set_pause_6502(0);
}
unsigned char toatarichar(int val)
{
int inv = val>=128;
if (inv)
{
val-=128;
}
if (val>='A' && val<='Z')
{
val+=-'A'+33;
}
else if (val>='a' && val<='z')
{
val+=-'a'+33+64;
}
else if (val>='0' && val<='9')
{
val+=-'0'+16;
}
else if (val>=32 && val<=47)
{
val+=-32;
}
else
{
val = 0;
}
if (inv)
{
val+=128;
}
return val;
}
int debug_pos;
int debug_adjust;
unsigned char volatile * baseaddr;
#ifdef LINUX_BUILD
void char_out(void* p, char c)
{
// get rid of unused parameter p warning
(void)(p);
int x, y;
x = debug_pos % 40;
y = debug_pos / 40;
display_char(x, y, c, debug_adjust == 128);
debug_pos++;
}
#else
void clearscreen()
{
unsigned volatile char * screen;
for (screen=(unsigned volatile char *)(40000+atari_regbase); screen!=(unsigned volatile char *)(atari_regbase+40000+1024); ++screen)
*screen = 0x00;
}
void char_out ( void* p, char c)
{
unsigned char val = toatarichar(c);
if (debug_pos>=0)
{
*(baseaddr+debug_pos) = val|debug_adjust;
++debug_pos;
}
}
#endif
struct SimpleFile * files[6];
void loadromfile(struct SimpleFile * file, int size, size_t ram_address)
{
void* absolute_ram_address = SDRAM_BASE + ram_address;
int read = 0;
file_read(file, absolute_ram_address, size, &read);
}
void loadrom(char const * path, int size, size_t ram_address)
{
if (SimpleFile_OK == file_open_name(path, files[4]))
{
loadromfile(files[4], size, ram_address);
}
}
void loadrom_indir(struct SimpleDirEntry * entries, char const * filename, int size, size_t ram_address)
{
if (SimpleFile_OK == file_open_name_in_dir(entries, filename, files[4]))
{
loadromfile(files[4], size, ram_address);
}
}
void loadosrom()
{
if (file_size(files[5]) == 0x4000)
{
loadromfile(files[5],0x4000, ROM_OFS + 0x4000);
}
else if (file_size(files[5]) ==0x2800)
{
loadromfile(files[5],0x2800, ROM_OFS + 0x5800);
}
}
#ifdef LINUX_BUILD
int zpu_main(void)
#else
int main(void)
#endif
{
/* disk_initialize();
{
char buffer[512];
freeze_init((void*)FREEZE_MEM); // 128k
debug_pos = -1;
debug_adjust = 0;
baseaddr = (unsigned char volatile *)(40000 + atari_regbase);
set_pause_6502(1);
set_reset_6502(1);
set_reset_6502(0);
set_turbo_6502(1);
set_rom_select(1);
set_ram_select(0);
init_printf(0, char_out);
reboot(1);
// for (;;);
wait_us(5000000);
set_pause_6502(1);
freeze();
debug_pos = 0;
printf("Hello world 3");
debug_pos = 40;
int i;
for (i=0;i!=512; ++i)
{
buffer[i] = i;
}
int volatile * x = (int volatile *)0x4000;
int volatile * y = (int volatile *)&buffer[0];
for (i=0;i!=128; ++i)
{
x[i] = y[i];
}
hexdump_pure(0x4000,8);
hexdump_pure(0x41f8,8);
debug_pos = 120;
printf(" Writing sector ");
n_actual_mmc_sector = 30;
disk_writeflush();
printf(" Wrote sector ");
for (i=0;i!=128; ++i)
{
x[i] = 0;
}
n_actual_mmc_sector = -1;
disk_readp(&buffer[0],30,0,512);
hexdump_pure(0x4000,8);
hexdump_pure(0x41f8,8);
debug_pos = 200;
disk_readp(&buffer[0],0x103,0,512);
hexdump_pure(0x4000,8);
hexdump_pure(0x41f8,8);
debug_pos = 280;
disk_readp(&buffer[0],0,0,512);
hexdump_pure(0x4000,8);
hexdump_pure(0x41f8,8);
debug_pos = 360;
printf("OK...");
//for (;;);
wait_us(10000000);
}*/
/* spiInit();
set_spi_clock_freq();
mmcReadLoop();*/
/* spiInit();
set_spi_clock_freq();
char buffer[512];
while (1)
{
mmcReadLoop();
wait_us(500);
}*/
int i;
for (i=0; i!=6; ++i)
{
files[i] = (struct SimpleFile *)alloca(file_struct_size());
file_init(files[i]);
}
freeze_init((void*)FREEZE_MEM); // 128k
debug_pos = -1;
debug_adjust = 0;
baseaddr = (unsigned char volatile *)(40000 + atari_regbase);
set_pause_6502(1);
set_reset_6502(1);
set_reset_6502(0);
set_turbo_6502(1);
set_rom_select(1);
set_ram_select(2);
init_printf(0, char_out);
// TODO...
if (SimpleFile_OK == dir_init((void *)DIR_INIT_MEM, DIR_INIT_MEMSIZE))
{
// printf("DIR init ok\n");
init_drive_emulator();
struct SimpleDirEntry * entries = dir_entries(ROM_DIR);
//loadrom_indir(entries,"atarixl.rom",0x4000, (void *)0x704000);
if (SimpleFile_OK == file_open_name_in_dir(entries, "atarixl.rom", files[5]))
{
loadosrom();
}
/*loadrom_indir(entries,"xlhias.rom",0x4000, (void *)0x708000);
loadrom_indir(entries,"ultimon.rom",0x4000, (void *)0x70c000);
loadrom_indir(entries,"osbhias.rom",0x4000, (void *)0x710000);
loadrom_indir(entries,"osborig.rom",0x2800, (void *)0x715800);
loadrom_indir(entries,"osaorig.rom",0x2800, (void *)0x719800);*/
loadrom_indir(entries,"ataribas.rom",0x2000,ROM_OFS);
//ROM = xlorig.rom,0x4000, (void *)0x704000
//ROM = xlhias.rom,0x4000, (void *)0x708000
//ROM = ultimon.rom,0x4000, (void *)0x70c000
//ROM = osbhias.rom,0x4000, (void *)0x710000
//ROM = osborig.rom,0x2800, (void *)0x715800
//ROM = osaorig.rom,0x2800, (void *)0x719800
//
//ROM = ataribas.rom,0x2000,(void *)0x700000
//--SDRAM_BASIC_ROM_ADDR <= "111"&"000000" &"00000000000000";
//--SDRAM_OS_ROM_ADDR <= "111"&rom_select &"00000000000000";
reboot(1);
run_drive_emulator();
}
else
{
//printf("DIR init failed\n");
}
reboot(1);
for (;;) actions();
}
// struct SimpleFile * file = alloca(file_struct_size());
// printf("Opening file\n");
// if (SimpleFile_OK == file_open_name("GUNPOWDR.ATR",file))
// {
// printf("FILE open ok\n");
//
// set_drive_status(0,file);
//
// }
// else
// {
// printf("FILE open failed\n");
// }
char const * get_ram()
{
static char const * ram[] =
{
"64K",
"128K",
"320K(Compy)",
"320K(Rambo)",
"576K(Compy)",
"576K(Rambo)",
"1MB",
"4MB"
};
return ram[get_ram_select()];
/*switch(get_ram_select())
{
case 0:
return "64K";
case 1:
return "128K";
case 2:
return "320K(Compy)";
case 3:
return "320K(Rambo)";
case 4:
return "576K(Compy)";
case 5:
return "576K(Rambo)";
case 6:
return "1MB";
case 7:
return "4MB";
}*/
}
int settings()
{
struct joystick_status joy;
joy.x_ = joy.y_ = joy.fire_ = 0;
int row = 0;
int done = 0;
for (;!done;)
{
// Render
clearscreen();
debug_pos = 0;
debug_adjust = 0;
printf("Se");
debug_adjust = 128;
printf("ttings");
debug_pos = 80;
debug_adjust = row==0 ? 128 : 0;
printf("Turbo:%dx", get_turbo_6502());
debug_pos = 120;
debug_adjust = row==1 ? 128 : 0;
printf("Ram:%s", get_ram());
debug_pos = 160;
debug_adjust = row==2 ? 128 : 0;
{
printf("Rom:%s", file_name(files[5]));
}
debug_pos = 240;
int i;
for (i=1;i!=5;++i)
{
int temp = debug_pos;
debug_adjust = row==i+2 ? 128 : 0;
char buffer[20];
describe_disk(i-1,&buffer[0]);
printf("Drive %d:%s %s", i, file_name(files[i-1]), &buffer[0]);
debug_pos = temp+40;
}
debug_pos = 400;
debug_adjust = row==7 ? 128 : 0;
printf("Cartridge 8k simple");
debug_pos = 480;
debug_adjust = row==8 ? 128 : 0;
printf("Exit");
// Slow it down a bit
wait_us(100000);
// move
joystick_wait(&joy,WAIT_QUIET);
joystick_wait(&joy,WAIT_EITHER);
row+=joy.y_;
if (row<0) row = 0;
if (row>8) row = 8;
switch (row)
{
case 0:
{
int turbo = get_turbo_6502();
if (joy.x_==1) turbo<<=1;
if (joy.x_==-1) turbo>>=1;
if (turbo>16) turbo = 16;
if (turbo<1) turbo = 1;
set_turbo_6502(turbo);
}
break;
case 1:
{
int ram_select = get_ram_select();
ram_select+=joy.x_;
if (ram_select<0) ram_select = 0;
if (ram_select>7) ram_select = 7;
set_ram_select(ram_select);
}
break;
case 2:
{
if (joy.x_ || joy.fire_)
{
filter = filter_roms;
file_selector(files[5]);
loadosrom();
}
}
break;
case 3:
case 4:
case 5:
case 6:
{
if (joy.x_>0)
{
// Choose new disk
filter = filter_disks;
file_selector(files[row-3]);
set_drive_status(row-3,files[row-3]);
}
else if(joy.x_<0)
{
// Remove disk
file_init(files[row-3]);
set_drive_status(row-3,0);
}
else if (joy.fire_)
{
{
// Swap files
struct SimpleFile * temp = files[row-3];
files[row-3] = files[0];
files[0] = temp;
}
{
// Swap disks
struct SimpleFile * temp = get_drive_status(row-3);
set_drive_status(row-3, get_drive_status(0));
set_drive_status(0,temp);
}
}
}
break;
case 7:
{
if (joy.fire_)
{
filter = filter_roms;
file_selector(files[4]);
loadrom(file_name(files[4]),0x2000,0x700000);
return 1;
}
}
break;
case 8:
if (joy.fire_)
{
done = 1;
}
break;
}
}
return 0;
}
void actions()
{
#ifdef LINUX_BUILD
check_keys();
#endif
// Show some activity!
//*atari_colbk = *atari_random;
// Hot keys
if (get_hotkey_softboot())
{
reboot(0);
}
else if (get_hotkey_coldboot())
{
reboot(1);
}
else if (get_hotkey_settings())
{
set_pause_6502(1);
freeze();
debug_pos = 0;
int do_reboot = settings();
debug_pos = -1;
restore();
if (do_reboot)
reboot(1);
else
set_pause_6502(0);
}
else if (get_hotkey_fileselect())
{
set_pause_6502(1);
freeze();
filter = filter_disks;
file_selector(files[0]);
debug_pos = -1;
restore();
set_drive_status(0,files[0]);
reboot(1);
/* disk_initialize();
{
char buffer[512];
set_pause_6502(1);
freeze();
debug_pos = 0;
printf("Hello world 3");
debug_pos = 40;
n_actual_mmc_sector = -1;
disk_readp(&buffer[0],0,0,512);
hexdump_pure(&buffer[0],512);
wait_us(10000000);
restore();
}*/
}
}
firmware_5200/joystick.c
#include "joystick.h"
#include "regs.h"
//#include <stdio.h>
void joystick_poll(struct joystick_status * status)
{
status->x_ = 0;
status->y_ = 0;
status->fire_ = 0;
unsigned char kbcode = *atari_kbcode;
kbcode &= 0x1e;
unsigned char key_held = *atari_skctl;
if ((key_held&0x4) != 0)
{
kbcode = 0x0;
}
status->y_ = (0x8==(kbcode&0x18)) -((unsigned int)(0x18==(kbcode&0x18)));
status->x_ = (0x2==(kbcode&0x6)) -((unsigned int)(0x6==(kbcode&0x6)));
//status->fire_ = !(1&*atari_trig0);
status->fire_ = kbcode==0x14;
//if (porta != 0xff)
//printf("%02x %x %x %x\n",porta,status->x_,status->y_,status->fire_);
/*
if (0==(porta&0x2)) // down
{
status->y_ =1;
}
else if (0==(porta&0x1)) // up
{
status->y_ =-1;
}
if (0==(porta&0x8)) // right
{
status->x_ = 1;
}
else if (0==(porta&0x4)) // left
{
status->x_ = -1;
}
if (0==(1&*atari_trig0)) // fire
{
status->fire_ = 1;
}
*/
}
void joystick_wait(struct joystick_status * status, enum JoyWait waitFor)
{
while (1)
{
joystick_poll(status);
switch (waitFor)
{
case WAIT_QUIET:
if (status->x_ == 0 && status->y_ == 0 && status->fire_ == 0) return;
break;
case WAIT_FIRE:
if (status->fire_ == 1) return;
break;
case WAIT_EITHER:
if (status->fire_ == 1) return;
// fall through
case WAIT_MOVE:
if (status->x_ !=0 || status->y_ != 0) return;
break;
}
}
}
firmware_5200/regs.c
#include "regs.h"
#define config_regbase 0x40000
int volatile * zpu_in1 = (int *)(0*4+config_regbase);
int volatile * zpu_in2 = (int *)(1*4+config_regbase);
int volatile * zpu_in3 = (int *)(2*4+config_regbase);
int volatile * zpu_in4 = (int *)(3*4+config_regbase);
int volatile * zpu_out1 = (int *)(4*4+config_regbase);
int volatile * zpu_out2 = (int *)(5*4+config_regbase);
int volatile * zpu_out3 = (int *)(6*4+config_regbase);
int volatile * zpu_out4 = (int *)(7*4+config_regbase);
int volatile * zpu_pause = (int *)(8*4+config_regbase);
int volatile * zpu_spi_data = (int *)(9*4+config_regbase);
int volatile * zpu_spi_state = (int *)(10*4+config_regbase);
int volatile * zpu_sio = (int *)(11*4+config_regbase);
int volatile * zpu_board = (int *)(12*4+config_regbase);
int volatile * zpu_spi_dma = (int *)(13*4+config_regbase);
unsigned char volatile * zpu_pokey_audf0 = (unsigned char *)(0x10*4+config_regbase);
unsigned char volatile * zpu_pokey_audc0 = (unsigned char *)(0x11*4+config_regbase);
unsigned char volatile * zpu_pokey_audf1 = (unsigned char *)(0x12*4+config_regbase);
unsigned char volatile * zpu_pokey_audc1 = (unsigned char *)(0x13*4+config_regbase);
unsigned char volatile * zpu_pokey_audf2 = (unsigned char *)(0x14*4+config_regbase);
unsigned char volatile * zpu_pokey_audc2 = (unsigned char *)(0x15*4+config_regbase);
unsigned char volatile * zpu_pokey_audf3 = (unsigned char *)(0x16*4+config_regbase);
unsigned char volatile * zpu_pokey_audc3 = (unsigned char *)(0x17*4+config_regbase);
unsigned char volatile * zpu_pokey_audctl = (unsigned char *)(0x18*4+config_regbase);
unsigned char volatile * zpu_pokey_skrest = (unsigned char *)(0x1a*4+config_regbase);
unsigned char volatile * zpu_pokey_serout = (unsigned char *)(0x1d*4+config_regbase);
unsigned char volatile * zpu_pokey_irqen = (unsigned char *)(0x1e*4+config_regbase);
unsigned char volatile * zpu_pokey_skctl = (unsigned char *)(0x1f*4+config_regbase);
unsigned char volatile * atari_colbk = (unsigned char *)(0xc01a + atari_regbase);
unsigned char volatile * atari_colpf1 = (unsigned char *)(0xc017 + atari_regbase);
unsigned char volatile * atari_colpf2 = (unsigned char *)(0xc018 + atari_regbase);
unsigned char volatile * atari_colpf3 = (unsigned char *)(0xc019 + atari_regbase);
unsigned char volatile * atari_colpf0 = (unsigned char *)(0xc016 + atari_regbase);
unsigned char volatile * atari_prior = (unsigned char *)(0xc01b + atari_regbase);
unsigned char volatile * atari_trig0 = (unsigned char *)(0xc010 + atari_regbase);
unsigned char volatile * atari_porta = (unsigned char *)(0xd300 + atari_regbase);
unsigned char volatile * atari_portb = (unsigned char *)(0xd301 + atari_regbase);
unsigned char volatile * atari_chbase = (unsigned char *)(0xd409 + atari_regbase);
unsigned char volatile * atari_chactl = (unsigned char *)(0xd401 + atari_regbase);
unsigned char volatile * atari_dmactl = (unsigned char *)(0xd400 + atari_regbase);
unsigned char volatile * atari_dlistl = (unsigned char *)(0xd402 + atari_regbase);
unsigned char volatile * atari_dlisth = (unsigned char *)(0xd403 + atari_regbase);
unsigned char volatile * atari_nmien = (unsigned char *)(0xd40e + atari_regbase);
unsigned char volatile * atari_skctl = (unsigned char *)(0xe80f + atari_regbase);
unsigned char volatile * atari_kbcode = (unsigned char *)(0xe809 + atari_regbase);
unsigned char volatile * atari_random = (unsigned char *)(0xe80a + atari_regbase);
firmware_5200/regs.h
#ifndef regs_h
#define regs_h
#define atari_regbase 0x10000
#define atari_regmirror 0x20000
extern int volatile * zpu_in1;
extern int volatile * zpu_in2;
extern int volatile * zpu_in3;
extern int volatile * zpu_in4;
extern int volatile * zpu_out1;
extern int volatile * zpu_out2;
extern int volatile * zpu_out3;
extern int volatile * zpu_out4;
extern int volatile * zpu_pause;
extern int volatile * zpu_spi_data;
extern int volatile * zpu_spi_state;
extern int volatile * zpu_sio;
extern int volatile * zpu_board;
extern int volatile * zpu_spi_dma;
extern unsigned char volatile * zpu_pokey_audf0;
extern unsigned char volatile * zpu_pokey_audc0;
extern unsigned char volatile * zpu_pokey_audf1;
extern unsigned char volatile * zpu_pokey_audc1;
extern unsigned char volatile * zpu_pokey_audf2;
extern unsigned char volatile * zpu_pokey_audc2;
extern unsigned char volatile * zpu_pokey_audf3;
extern unsigned char volatile * zpu_pokey_audc3;
extern unsigned char volatile * zpu_pokey_audctl;
extern unsigned char volatile * zpu_pokey_skrest;
extern unsigned char volatile * zpu_pokey_serout;
extern unsigned char volatile * zpu_pokey_irqen;
extern unsigned char volatile * zpu_pokey_skctl;
extern unsigned char volatile * atari_nmien;
extern unsigned char volatile * atari_dlistl;
extern unsigned char volatile * atari_dlisth;
extern unsigned char volatile * atari_colbk;
extern unsigned char volatile * atari_colpf1;
extern unsigned char volatile * atari_colpf2;
extern unsigned char volatile * atari_colpf3;
extern unsigned char volatile * atari_colpf0;
extern unsigned char volatile * atari_prior;
extern unsigned char volatile * atari_random;
extern unsigned char volatile * atari_porta;
extern unsigned char volatile * atari_portb;
extern unsigned char volatile * atari_trig0;
extern unsigned char volatile * atari_chbase;
extern unsigned char volatile * atari_chactl;
extern unsigned char volatile * atari_dmactl;
extern unsigned char volatile * atari_skctl;
extern unsigned char volatile * atari_kbcode;
#endif // regs_h
firmware_5200/freeze.c
#include "freeze.h"
#include "regs.h"
unsigned char store_portb;
unsigned volatile char * store_mem;
unsigned volatile char * custom_mirror;
unsigned volatile char * atari_base;
void freeze_init(void * memory)
{
store_mem = (unsigned volatile char *)memory;
custom_mirror = (unsigned volatile char *)atari_regmirror;
atari_base = (unsigned volatile char *)atari_regbase;
}
void freeze()
{
int i;
// store custom chips
//store_portb = *atari_portb;
{
//gtia
for (i=0xc000; i!=0xc020; i++)
{
store_mem[i] = custom_mirror[i];
atari_base[i] = 0;
}
//pokey1/2
for (i=0xe800; i!=0xe820; i++)
{
store_mem[i] = custom_mirror[i];
atari_base[i] = 0;
}
//antic
for (i=0xd400; i!=0xd410; i++)
{
store_mem[i] = custom_mirror[i];
atari_base[i] = 0;
}
}
//*atari_portb = 0xff;
// Copy 16k ram to sdram
// Atari screen memory...
for (i=0x0; i!=0x4000; ++i)
{
store_mem[i] = atari_base[i];
}
//Clear, except dl (first 0x40 bytes)
clearscreen();
// Put custom chips in a safe state
// write a display list at 0600
unsigned char dl[] = {
0x70,
0x70,
0x47,0x40,0x2c,
0x70,
0x42,0x68,0x2c,
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
};
int j = 0;
for (i=0x0600; j!=sizeof(dl); ++i,++j)
{
atari_base[i] = dl[j];
}
// point antic at my display list
*atari_dlisth = 0x06;
*atari_dlistl = 0x00;
*atari_colbk = 0x00;
*atari_colpf0 = 0x2f;
*atari_colpf1 = 0x3f;
*atari_colpf2 = 0x00;
*atari_colpf3 = 0x1f;
*atari_prior = 0x00;
*atari_chbase = 0xf8;
*atari_dmactl = 0x22;
*atari_skctl = 0x2;
*atari_chactl = 0x2;
}
void restore()
{
int i;
// Restore memory
for (i=0x0; i!=0x4000; ++i)
{
atari_base[i] = store_mem[i];
}
// Restore custom chips
{
//gtia
for (i=0xc000; i!=0xc020; i++)
{
atari_base[i] = store_mem[i];
}
//pokey1/2
for (i=0xe800; i!=0xe820; i++)
{
atari_base[i] = store_mem[i];
}
//antic
for (i=0xd400; i!=0xd410; i++)
{
atari_base[i] = store_mem[i];
}
}
//*atari_portb = store_portb;
}
firmware_5200/freeze.h
#pragma once
// Allow us to take over the system
// NB: CPU should be frozen before calling these!
// Provide 128K of RAM...
void freeze_init(void * memory);
// Set hardware registers to 'neutral'
// Back up system ram
void freeze();
// Restore system ram
// Restore hardware registers
void restore();
firmware/5200/freeze.c
#include "freeze.h"
#include "regs.h"
#include "memory.h"
unsigned char store_portb;
unsigned volatile char * store_mem;
unsigned volatile char * custom_mirror;
unsigned volatile char * atari_base;
void freeze_init(void * memory)
{
store_mem = (unsigned volatile char *)memory;
custom_mirror = (unsigned volatile char *)atari_regmirror;
atari_base = (unsigned volatile char *)atari_regbase;
}
void freeze()
{
int i;
// store custom chips
//store_portb = *atari_portb;
{
//gtia
for (i=0xc000; i!=0xc020; i++)
{
store_mem[i] = custom_mirror[i];
atari_base[i] = 0;
}
//pokey1/2
for (i=0xe800; i!=0xe820; i++)
{
store_mem[i] = custom_mirror[i];
atari_base[i] = 0;
}
//antic
for (i=0xd400; i!=0xd410; i++)
{
store_mem[i] = custom_mirror[i];
atari_base[i] = 0;
}
}
//*atari_portb = 0xff;
// Copy 16k ram to sdram
// Atari screen memory...
for (i=0x0; i!=0x4000; ++i)
{
store_mem[i] = atari_base[i];
}
//Clear, except dl (first 0x40 bytes)
clearscreen();
// Put custom chips in a safe state
// write a display list at 0600
unsigned char dl[] = {
0x70,
0x70,
0x47,0x40,0x2c,
0x70,
0x42,0x68,0x2c,
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
};
int j = 0;
for (i=0x0600; j!=sizeof(dl); ++i,++j)
{
atari_base[i] = dl[j];
}
// point antic at my display list
*atari_dlisth = 0x06;
*atari_dlistl = 0x00;
*atari_colbk = 0x00;
*atari_colpf0 = 0x2f;
*atari_colpf1 = 0x3f;
*atari_colpf2 = 0x00;
*atari_colpf3 = 0x1f;
*atari_prior = 0x00;
*atari_chbase = 0xf8;
*atari_dmactl = 0x22;
*atari_skctl = 0x2;
*atari_chactl = 0x2;
}
void restore()
{
int i;
// Restore memory
for (i=0x0; i!=0x4000; ++i)
{
atari_base[i] = store_mem[i];
}
// Restore custom chips
{
//gtia
for (i=0xc000; i!=0xc020; i++)
{
atari_base[i] = store_mem[i];
}
//pokey1/2
for (i=0xe800; i!=0xe820; i++)
{
atari_base[i] = store_mem[i];
}
//antic
for (i=0xd400; i!=0xd410; i++)
{
atari_base[i] = store_mem[i];
}
}
//*atari_portb = store_portb;
}
firmware/5200/joystick.c
#include "joystick.h"
#include "regs.h"
//#include <stdio.h>
void joystick_poll(struct joystick_status * status)
{
status->x_ = 0;
status->y_ = 0;
status->fire_ = 0;
unsigned char kbcode = *atari_kbcode;
kbcode &= 0x1e;
unsigned char key_held = *atari_skctl;
if ((key_held&0x4) != 0)
{
kbcode = 0x0;
}
status->y_ = (0x8==(kbcode&0x18)) -((unsigned int)(0x18==(kbcode&0x18)));
status->x_ = (0x2==(kbcode&0x6)) -((unsigned int)(0x6==(kbcode&0x6)));
//status->fire_ = !(1&*atari_trig0);
status->fire_ = kbcode==0x14;
//if (porta != 0xff)
//printf("%02x %x %x %x\n",porta,status->x_,status->y_,status->fire_);
/*
if (0==(porta&0x2)) // down
{
status->y_ =1;
}
else if (0==(porta&0x1)) // up
{
status->y_ =-1;
}
if (0==(porta&0x8)) // right
{
status->x_ = 1;
}
else if (0==(porta&0x4)) // left
{
status->x_ = -1;
}
if (0==(1&*atari_trig0)) // fire
{
status->fire_ = 1;
}
*/
}
void joystick_wait(struct joystick_status * status, enum JoyWait waitFor)
{
while (1)
{
joystick_poll(status);
switch (waitFor)
{
case WAIT_QUIET:
if (status->x_ == 0 && status->y_ == 0 && status->fire_ == 0) return;
break;
case WAIT_FIRE:
if (status->fire_ == 1) return;
break;
case WAIT_EITHER:
if (status->fire_ == 1) return;
// fall through
case WAIT_MOVE:
if (status->x_ !=0 || status->y_ != 0) return;
break;
}
}
}
firmware/5200/regs.c
#include "regs.h"
#include "memory.h"
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff