Revision 47
Added by markw over 11 years ago
| firmware/Makefile | ||
|---|---|---|
| 
     MINSTARTUP_OBJ = $(patsubst $(STARTUP_DIR)/%.s,$(BUILD_DIR)/%.o,$(MINSTARTUP_SRC))
 
   | 
||
| 
     | 
||
| 
     MAIN_PRJ = JustStartAtari
 
   | 
||
| 
     MAIN_SRC = main.c regs.c atari_drive_emulator.c pokey/uart.c hexdump.c printf/printf.c fat/pff_file.c fat/pff.c common/utils.c sd_direct/diskio_mmc.c sd_direct/spi.c sd_direct/mmc.c
 
   | 
||
| 
     MAIN_SRC = main.c regs.c freeze.c atari_drive_emulator.c pokey/uart.c hexdump.c printf/printf.c fat/pff_file.c fat/pff.c common/utils.c sd_direct/diskio_mmc.c sd_direct/spi.c sd_direct/mmc.c
 
   | 
||
| 
     #gcc -g -O0 -DLITTLE_ENDIAN test_drive.c atari_drive_emulator.c native/uart.c hexdump.c printf/printf.c fat/pff_file.c fat/pff.c common/utils.c native/diskio_image.c -I. -Iprintf -Ifat -Icommon
 
   | 
||
| 
     #MAIN_SRC = stuff.c
 
   | 
||
| 
     MAIN_OBJ = $(COMMON_OBJ) $(patsubst %.c,$(BUILD_DIR)/%.o,$(MAIN_SRC))
 
   | 
||
| firmware/freeze.c | ||
|---|---|---|
| 
     #include "freeze.h"
 
   | 
||
| 
     | 
||
| 
     void freeze()
 
   | 
||
| 
     #include "regs.h"
 
   | 
||
| 
     | 
||
| 
     unsigned char store_portb;
 
   | 
||
| 
     unsigned volatile int * store_mem;
 
   | 
||
| 
     unsigned volatile char * store_custom;
 
   | 
||
| 
     unsigned volatile char * custom_mirror;
 
   | 
||
| 
     unsigned volatile char * atari_base;
 
   | 
||
| 
     | 
||
| 
     void freeze_init(void * memory)
 
   | 
||
| 
     {
 
   | 
||
| 
     	// Copy base 64k to ...
 
   | 
||
| 
     	store_mem  = memory;
 
   | 
||
| 
     	store_custom = memory;
 
   | 
||
| 
     | 
||
| 
     	unsigned volatile char * store  = 0xf80000; // SRAM...
 
   | 
||
| 
     	unsigned volatile char * store2 = 0xfc0000; // custom chips...
 
   | 
||
| 
     	custom_mirror = (unsigned volatile char *)atari_regmirror;
 
   | 
||
| 
     	atari_base = (unsigned volatile char *)atari_regbase;
 
   | 
||
| 
     }
 
   | 
||
| 
     | 
||
| 
     	mem = 0x9c00 + 0x10000;
 
   | 
||
| 
     	// Copy 1k from 0x$9c00 to sdram
 
   | 
||
| 
     	// 0x200000; sram
 
   | 
||
| 
     	// 0x800000; sdram (always use...)
 
   | 
||
| 
     	for (i=0x0; i!=1024; i++)
 
   | 
||
| 
     	{
 
   | 
||
| 
     		store[i] = mem[i];
 
   | 
||
| 
     	}
 
   | 
||
| 
     	for (i=0x40; i!=1024; i++)
 
   | 
||
| 
     	{
 
   | 
||
| 
     		mem[i] = 0;
 
   | 
||
| 
     	}
 
   | 
||
| 
     | 
||
| 
     void freeze()
 
   | 
||
| 
     {
 
   | 
||
| 
     	int i;
 
   | 
||
| 
     	// store custom chips
 
   | 
||
| 
     	store_portb = *atari_portb;
 
   | 
||
| 
     	{
 
   | 
||
| 
     		//gtia
 
   | 
||
| 
     		mem2 = 0x20000;
 
   | 
||
| 
     		mem3 = 0x10000;
 
   | 
||
| 
     		for (i=0xd000; i!=0xd01f; i++)
 
   | 
||
| 
     		{
 
   | 
||
| 
     			store2[i] = mem2[i];
 
   | 
||
| 
     			mem3[i] = 0;
 
   | 
||
| 
     			store_custom[i] = custom_mirror[i];
 
   | 
||
| 
     			atari_base[i] = 0;
 
   | 
||
| 
     		}
 
   | 
||
| 
     		//pokey1/2
 
   | 
||
| 
     		for (i=0xd200; i!=0xd21f; i++)
 
   | 
||
| 
     		{
 
   | 
||
| 
     			store2[i] = mem2[i];
 
   | 
||
| 
     			mem3[i] = 0;
 
   | 
||
| 
     			store_custom[i] = custom_mirror[i];
 
   | 
||
| 
     			atari_base[i] = 0;
 
   | 
||
| 
     		}
 
   | 
||
| 
     		//antic
 
   | 
||
| 
     		for (i=0xd400; i!=0xd40f; i++)
 
   | 
||
| 
     		{
 
   | 
||
| 
     			store2[i] = mem2[i];
 
   | 
||
| 
     			mem3[i] = 0;
 
   | 
||
| 
     			store_custom[i] = custom_mirror[i];
 
   | 
||
| 
     			atari_base[i] = 0;
 
   | 
||
| 
     		}
 
   | 
||
| 
     	}
 
   | 
||
| 
     | 
||
| 
     	*atari_portb = 0xff;
 
   | 
||
| 
     | 
||
| 
     	// Copy 64k ram to sdram
 
   | 
||
| 
     	// Atari screen memory...
 
   | 
||
| 
     	for (i=0x0; i!=0x3400; ++i)
 
   | 
||
| 
     	{
 
   | 
||
| 
     		store_mem[i] = atari_base[i];
 
   | 
||
| 
     	}
 
   | 
||
| 
     	for (i=0x3600; i!=0x4000; ++i)
 
   | 
||
| 
     	{
 
   | 
||
| 
     		store_mem[i] = atari_base[i];
 
   | 
||
| 
     	}
 
   | 
||
| 
     | 
||
| 
     	//Clear, except dl (first 0x40 bytes)
 
   | 
||
| 
     	for (i=0x40; i!=1024; i++)
 
   | 
||
| 
     	{
 
   | 
||
| 
     		atari_base[i] = 0;
 
   | 
||
| 
     	}
 
   | 
||
| 
     | 
||
| 
     	// Put custom chips in a safe state
 
   | 
||
| 
     	// write a display list at 9c00
 
   | 
||
| 
     	char dl[] = {
 
   | 
||
| ... | ... | |
| 
     		0x70,
 
   | 
||
| 
     		0x41,0x00,0x9c
 
   | 
||
| 
     	};
 
   | 
||
| 
     	for (i=0; i!=sizeof(dl); ++i)
 
   | 
||
| 
     	int end=0x9c00+sizeof(dl);
 
   | 
||
| 
     	for (i=0x9c00; i!=end; ++i)
 
   | 
||
| 
     	{
 
   | 
||
| 
     		mem[i] = dl[i];
 
   | 
||
| 
     		atari_base[i] = dl[i];
 
   | 
||
| 
     	}
 
   | 
||
| 
     | 
||
| 
     	// point antic at my display list
 
   | 
||
| ... | ... | |
| 
     	*atari_prior = 0x00;
 
   | 
||
| 
     	*atari_chbase = 0xe0;
 
   | 
||
| 
     	*atari_dmactl = 0x22;
 
   | 
||
| 
     	*atari_portb = 0xff;
 
   | 
||
| 
     	*atari_skctl = 0x3;
 
   | 
||
| 
     	*atari_chactl = 0x2;
 
   | 
||
| 
     }
 
   | 
||
| 
     | 
||
| 
     void restore()
 
   | 
||
| 
     {
 
   | 
||
| 
     	int i;
 
   | 
||
| 
     | 
||
| 
     	// Restore memory
 
   | 
||
| 
     	mem = 0x9c00 + 0x10000;
 
   | 
||
| 
     	for (i=0x040; i!=1024; i++)
 
   | 
||
| 
     	for (i=0x0; i!=0x3400; ++i)
 
   | 
||
| 
     	{
 
   | 
||
| 
     		mem[i] = store[i];
 
   | 
||
| 
     		atari_base[i] = store_mem[i];
 
   | 
||
| 
     	}
 
   | 
||
| 
     	for (i=0x3600; i!=0x4000; ++i)
 
   | 
||
| 
     	{
 
   | 
||
| 
     		atari_base[i] = store_mem[i];
 
   | 
||
| 
     	}
 
   | 
||
| 
     | 
||
| 
     	// Restore custom chips
 
   | 
||
| 
     	{
 
   | 
||
| 
     		//gtia
 
   | 
||
| 
     		mem3 = 0x10000;
 
   | 
||
| 
     		for (i=0xd000; i!=0xd01f; i++)
 
   | 
||
| 
     		{
 
   | 
||
| 
     			mem3[i] = store2[i];
 
   | 
||
| 
     			atari_base[i] = store_custom[i];
 
   | 
||
| 
     		}
 
   | 
||
| 
     		//pokey1/2
 
   | 
||
| 
     		for (i=0xd200; i!=0xd21f; i++)
 
   | 
||
| 
     		{
 
   | 
||
| 
     			mem3[i] = store2[i];
 
   | 
||
| 
     			atari_base[i] = store_custom[i];
 
   | 
||
| 
     		}
 
   | 
||
| 
     		//antic
 
   | 
||
| 
     		for (i=0xd400; i!=0xd40f; i++)
 
   | 
||
| 
     		{
 
   | 
||
| 
     			mem3[i] = store2[i];
 
   | 
||
| 
     			atari_base[i] = store_custom[i];
 
   | 
||
| 
     		}
 
   | 
||
| 
     	}
 
   | 
||
| 
     | 
||
| firmware/freeze.h | ||
|---|---|---|
| 
     // 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();
 
   | 
||
| firmware/main.c | ||
|---|---|---|
| 
     	*reg = val; \
 
   | 
||
| 
     }
 
   | 
||
| 
     | 
||
| 
     #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,0,hotkey_softboot,zpu_in1)
 
   | 
||
| 
     BIT_REG_RO(,0x1,1,hotkey_coldboot,zpu_in1)
 
   | 
||
| 
     BIT_REG_RO(,0x1,2,hotkey_fileselect,zpu_in1)
 
   | 
||
| 
     BIT_REG_RO(,0x1,3,hotkey_settings,zpu_in1)
 
   | 
||
| 
     | 
||
| 
     void
 
   | 
||
| 
     wait_us(int unsigned num)
 
   | 
||
| 
     {
 
   | 
||
| ... | ... | |
| 
     }
 
   | 
||
| 
     | 
||
| 
     void
 
   | 
||
| 
     coldstart(int clearram)
 
   | 
||
| 
     reboot(int cold)
 
   | 
||
| 
     {
 
   | 
||
| 
     	set_reset_6502(1);
 
   | 
||
| 
     	if (clearram)
 
   | 
||
| 
     	if (cold)
 
   | 
||
| 
     	{
 
   | 
||
| 
     		clear_64k_ram();
 
   | 
||
| 
     	}
 
   | 
||
| ... | ... | |
| 
     void char_out ( void* p, char c)
 
   | 
||
| 
     {
 
   | 
||
| 
     	unsigned char val = toatarichar(c);
 
   | 
||
| 
     	//*(baseaddr+debug_pos) = val;
 
   | 
||
| 
     	//++debug_pos;
 
   | 
||
| 
     	if (debug_pos>0)
 
   | 
||
| 
     	{
 
   | 
||
| 
     		*(baseaddr+debug_pos) = val;
 
   | 
||
| 
     		++debug_pos;
 
   | 
||
| 
     	}
 
   | 
||
| 
     }
 
   | 
||
| 
     | 
||
| 
     // Memory usage...
 
   | 
||
| 
     // 0x410000-0x41FFFF (0xc10000 in zpu space) = directory cache - 64k
 
   | 
||
| 
     // 0x420000-0x43FFFF (0xc20000 in zpu space) = freeze backup
 
   | 
||
| 
     | 
||
| 
     int main(void)
 
   | 
||
| 
     {
 
   | 
||
| 
     	debug_pos = 0;
 
   | 
||
| 
     	freeze_init((void*)0xc20000); // 128k
 
   | 
||
| 
     | 
||
| 
     	debug_pos = -1;
 
   | 
||
| 
     	baseaddr = (unsigned char volatile *)(40000 + atari_regbase);
 
   | 
||
| 
     	set_reset_6502(1);
 
   | 
||
| 
     	set_turbo_6502(1);
 
   | 
||
| 
     | 
||
| 
     	init_printf(0, char_out);
 
   | 
||
| 
     | 
||
| 
     	debug_pos = 0;
 
   | 
||
| 
     | 
||
| 
     	// TODO...
 
   | 
||
| 
     | 
||
| 
     	printf("Hello World\n I am an Atari!\n");
 
   | 
||
| ... | ... | |
| 
     	if (SimpleFile_OK == dir_init((void *)0xc10000, 65536))
 
   | 
||
| 
     	{
 
   | 
||
| 
     		printf("DIR init ok\n");
 
   | 
||
| 
     		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");
 
   | 
||
| 
     			init_drive_emulator();
 
   | 
||
| 
     | 
||
| 
     			set_drive_status(0,file);
 
   | 
||
| 
     | 
||
| 
     			coldstart(1);
 
   | 
||
| 
     | 
||
| 
     			run_drive_emulator();
 
   | 
||
| 
     		}
 
   | 
||
| 
     		else
 
   | 
||
| 
     		{
 
   | 
||
| 
     			printf("FILE open failed\n");
 
   | 
||
| 
     		}
 
   | 
||
| 
     		init_drive_emulator();
 
   | 
||
| 
     		reboot(1);
 
   | 
||
| 
     		run_drive_emulator();
 
   | 
||
| 
     	}
 
   | 
||
| 
     	else
 
   | 
||
| 
     	{
 
   | 
||
| 
     		printf("DIR init failed\n");
 
   | 
||
| 
     	}
 
   | 
||
| 
     | 
||
| 
     	for(;;) actions();
 
   | 
||
| 
     	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");
 
   | 
||
| 
     //		}
 
   | 
||
| 
     | 
||
| 
     void actions()
 
   | 
||
| 
     {
 
   | 
||
| 
     	// NOP
 
   | 
||
| 
     	// 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;	
 
   | 
||
| 
     		printf("Hello world - settings");
 
   | 
||
| 
     		debug_pos = -1;
 
   | 
||
| 
     		wait_us(1000000);
 
   | 
||
| 
     		restore();
 
   | 
||
| 
     		set_pause_6502(0);
 
   | 
||
| 
     	}
 
   | 
||
| 
     	else if (get_hotkey_fileselect())
 
   | 
||
| 
     	{
 
   | 
||
| 
     		set_pause_6502(1);
 
   | 
||
| 
     		freeze();
 
   | 
||
| 
     		debug_pos = 0;	
 
   | 
||
| 
     		printf("Hello world - fileselect");
 
   | 
||
| 
     		debug_pos = -1;
 
   | 
||
| 
     		wait_us(1000000);
 
   | 
||
| 
     		restore();
 
   | 
||
| 
     		set_pause_6502(0);
 
   | 
||
| 
     	}
 
   | 
||
| 
     }
 
   | 
||
| 
     | 
||
| 
     | 
||
| firmware/regs.h | ||
|---|---|---|
| 
     #define regs_h
 
   | 
||
| 
     | 
||
| 
     #define atari_regbase  0x10000
 
   | 
||
| 
     #define atari_regmirror  0x20000
 
   | 
||
| 
     | 
||
| 
     extern int volatile * zpu_in1;
 
   | 
||
| 
     extern int volatile * zpu_in2;
 
   | 
||
Added hotkeys