Project

General

Profile

« Previous | Next » 

Revision 69

Added by markw about 11 years ago

Mist read/write support added/debugged. Single OS ROM + file selector. Fix bug when using "move to drive 1" which reinstated empty drives! Never access Atari system while reset.

View differences:

firmware/diskio_sectorrequest.c
#include "diskio.h"
#include "regs.h"
void mmcReadCached(u32 sector);
u32 n_actual_mmc_sector;
unsigned char * mmc_sector_buffer;
void mmcReadCached(u32 sector)
{
//debug("mmcReadCached");
//plotnext(toatarichar(' '));
//plotnextnumber(sector);
//debug("\n");
if(sector==n_actual_mmc_sector) return;
//debug("mmcReadREAL");
//plotnext(toatarichar(' '));
//plotnextnumber(sector);
//debug("\n");
//u08 ret,retry;
//predtim nez nacte jiny, musi ulozit soucasny
// TODO mmcWriteCachedFlush();
//az ted nacte novy
//retry=0; //zkusi to maximalne 256x
/*do
{
ret = mmcRead(sector); //vraci 0 kdyz ok
retry--;
} while (ret && retry);
while(ret); //a pokud se vubec nepovedlo, tady zustane zablokovany cely SDrive!
*/
*zpu_out4 = (sector<<8)|0xa5;
while (*zpu_in4 != *zpu_out4)
{
// Wait until ready
}
n_actual_mmc_sector=sector;
}
/*-----------------------------------------------------------------------*/
/* Initialize Disk Drive */
/*-----------------------------------------------------------------------*/
DSTATUS disk_initialize (void)
{
DSTATUS stat;
n_actual_mmc_sector = 0xffffffff;
//do
//{
// mmcInit();
//}
//while(mmcReset()); //dokud nenulove, tak smycka (return 0 => ok!)
//set_spi_clock_freq();
// no longer in ram (yet!), misuse will break us...
mmc_sector_buffer = (unsigned char *)0x8000; // 512 bytes in the middle of memory space!
stat = RES_OK;
return stat;
}
/*-----------------------------------------------------------------------*/
/* Read Partial Sector */
/*-----------------------------------------------------------------------*/
DRESULT disk_readp (
BYTE* dest, /* Pointer to the destination object */
DWORD sector, /* Sector number (LBA) */
WORD sofs, /* Offset in the sector */
WORD count /* Byte count (bit15:destination) */
)
{
DRESULT res;
/*debug("readp:");
plotnextnumber(sector);
debug(" ");
plotnextnumber((int)dest);
debug(" ");
plotnextnumber(sofs);
debug(" ");
plotnextnumber(count);
debug(" ");
plotnextnumber(atari_sector_buffer);
debug(" ");
plotnextnumber(mmc_sector_buffer);
debug("\n");
*/
// Put your code here
mmcReadCached(sector);
for(;count>0;++sofs,--count)
{
unsigned char x = mmc_sector_buffer[sofs];
//printf("char:%02x loc:%d", x,sofs);
*dest++ = x;
}
res = RES_OK;
return res;
}
/*-----------------------------------------------------------------------*/
/* Write Partial Sector */
/*-----------------------------------------------------------------------*/
DRESULT disk_writep (const BYTE* buff, DWORD sc)
{
DRESULT res;
if (!buff) {
if (sc) {
// Initiate write process
} else {
// Finalize write process
}
} else {
// Send data to the disk
}
return res;
}
firmware/Makefile
MINSTARTUP_SRC = mycrt0.s
MINSTARTUP_OBJ = $(patsubst $(STARTUP_DIR)/%.s,$(BUILD_DIR)/%.o,$(MINSTARTUP_SRC))
MAIN_PRJ = JustStartAtari
MAIN_SRC = main.c regs.c freeze.c joystick.c fileutils.c fileselector.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))
MCC_PRJ = MCC216
MCC_SRC = main.c regs.c freeze.c joystick.c fileutils.c fileselector.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 mcc/dirs.c
MCC_OBJ = $(patsubst %.c,$(BUILD_DIR)/%.o,$(MCC_SRC))
MIST_PRJ = MIST
MIST_SRC = main.c regs.c freeze.c joystick.c fileutils.c fileselector.c atari_drive_emulator.c pokey/uart.c hexdump.c printf/printf.c fat/pff_file.c fat/pff.c common/utils.c mist/diskio_sectorrequest.c mist/dirs.c
MIST_OBJ = $(patsubst %.c,$(BUILD_DIR)/%.o,$(MIST_SRC))
LINKMAP = ./standalone_simple.ld
......
# Our target.
all: $(BUILD_DIR) $(MAIN_PRJ).bin $(MAIN_PRJ).rpt
all: mcc mist
install:
cd ../common/romgen && ./createall && cd ../../firmware
mcc: $(BUILD_DIR) $(MCC_PRJ).bin $(MCC_PRJ).rpt
mist: $(BUILD_DIR) $(MIST_PRJ).bin $(MIST_PRJ).rpt
clean:
rm -f $(BUILD_DIR)/*.o *.hex *.elf *.map *.lst *.srec $(MAIN_PRJ).rom *~ */*.o *.bin
rm -f $(BUILD_DIR)/*.o *.hex *.elf *.map *.lst *.srec $(MIST_PRJ).rom $(MCC_PRJ).rom *~ */*.o *.bin
# Convert ELF binary to bin file.
......
# Link - this produces an ELF binary.
$(MAIN_PRJ).elf: $(MINSTARTUP_OBJ) $(MAIN_OBJ)
$(MCC_PRJ).elf: $(MINSTARTUP_OBJ) $(MCC_OBJ)
$(LD) $(LFLAGS) -T $(LINKMAP) -o $@ $+ $(LIBS)
$(MIST_PRJ).elf: $(MINSTARTUP_OBJ) $(MIST_OBJ)
$(LD) $(LFLAGS) -T $(LINKMAP) -o $@ $+ $(LIBS)
$(BUILD_DIR)/%.o: %.c Makefile
mkdir -p `dirname $@`
$(CC) $(CFLAGS) -o $@ -c $<
firmware/atari_drive_emulator.c
//printf("appears valid\n");
}
struct SimpleFile * get_drive_status(int driveNumber)
{
return drives[driveNumber];
}
void init_drive_emulator()
{
int i;
firmware/atari_drive_emulator.h
// For a read-only disk, just have no write function!
struct SimpleFile;
void set_drive_status(int driveNumber, struct SimpleFile * file);
struct SimpleFile * get_drive_status(int driveNumber);
void describe_disk(int driveNumber, char * buffer);
firmware/fileselector.c
extern int debug_pos; // ARG!
extern int debug_adjust; // ARG!
extern char USER_DIR[];
// TODO!
#define MAX_PATH_LENGTH (9*5 + 8+3+1 + 1)
......
char dir[MAX_PATH_LENGTH];
if (file_name(file)[0] == '\0')
{
strcpy(&dir[0],"/atari800/user");
strcpy(&dir[0],USER_DIR);
}
else
{
firmware/main.c
#include "atari_drive_emulator.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
......
void
reboot(int cold)
{
set_reset_6502(1);
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);
}
......
// 0x410000-0x41FFFF (0xc10000 in zpu space) = directory cache - 64k
// 0x420000-0x43FFFF (0xc20000 in zpu space) = freeze backup
struct SimpleFile * files[5];
struct SimpleFile * files[6];
void loadromfile(struct SimpleFile * file, int size, void * ram_address)
{
ram_address += 0x800000;
......
}
}
void loadosrom()
{
if (file_size(files[5]) == 0x4000)
{
loadromfile(files[5],0x4000, (void *)0x704000);
}
else if (file_size(files[5]) ==0x2800)
{
loadromfile(files[5],0x2800, (void *)0x705800);
}
}
int main(void)
{
/* disk_initialize();
{
char buffer[512];
freeze_init((void*)0xc20000); // 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();*/
......
}*/
int i;
for (i=0; i!=5; ++i)
for (i=0; i!=6; ++i)
{
files[i] = (struct SimpleFile *)alloca(file_struct_size());
file_init(files[i]);
......
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(2);
set_rom_select(1);
set_ram_select(2);
init_printf(0, char_out);
......
init_drive_emulator();
struct SimpleDirEntry * entries = dir_entries("/system/rom/atari800");
struct SimpleDirEntry * entries = dir_entries(ROM_DIR);
loadrom_indir(entries,"xlorig.rom",0x4000, (void *)0x704000);
loadrom_indir(entries,"xlhias.rom",0x4000, (void *)0x708000);
//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,"osaorig.rom",0x2800, (void *)0x719800);*/
loadrom_indir(entries,"ataribas.rom",0x2000,(void *)0x700000);
......
printf("Ram:%s", get_ram());
debug_pos = 160;
debug_adjust = row==2 ? 128 : 0;
printf("Rom bank:%d", get_rom_select());
{
printf("Rom:%s", file_name(files[5]));
}
debug_pos = 240;
int i;
for (i=1;i!=5;++i)
......
break;
case 2:
{
int rom_select = get_rom_select();
rom_select+=joy.x_;
if (rom_select<1) rom_select = 1;
if (rom_select>6) rom_select = 6; // TODO
set_rom_select(rom_select);
if (joy.x_ || joy.fire_)
{
filter = filter_roms;
file_selector(files[5]);
loadosrom();
}
}
break;
case 3:
......
}
else if (joy.fire_)
{
struct SimpleFile * temp;
temp = files[0];
files[0] = files[row-3];
files[row-3] = temp;
set_drive_status(row-3,temp);
set_drive_status(0,files[0]);
{
// 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;
firmware/mcc/dirs.c
char USER_DIR[]="/atari800/user";
char ROM_DIR[]="/system/rom/atari800";
firmware/mist/dirs.c
char USER_DIR[]="/atari800/user";
char ROM_DIR[]="/atari800/rom";
firmware/mist/diskio_sectorrequest.c
#include "diskio.h"
#include "regs.h"
#include "printf.h"
extern int debug_pos;
void mmcReadCached(u32 sector);
u32 n_actual_mmc_sector;
unsigned char * mmc_sector_buffer;
void mmcReadCached(u32 sector)
{
//debug("mmcReadCached");
//plotnext(toatarichar(' '));
//plotnextnumber(sector);
//debug("\n");
if(sector==n_actual_mmc_sector) return;
//debug("mmcReadREAL");
//plotnext(toatarichar(' '));
//plotnextnumber(sector);
//debug("\n");
//u08 ret,retry;
//predtim nez nacte jiny, musi ulozit soucasny
// TODO mmcWriteCachedFlush();
//az ted nacte novy
//retry=0; //zkusi to maximalne 256x
/*do
{
ret = mmcRead(sector); //vraci 0 kdyz ok
retry--;
} while (ret && retry);
while(ret); //a pokud se vubec nepovedlo, tady zustane zablokovany cely SDrive!
*/
//printf("Reading sector:%d", sector);
*zpu_out4 = sector|0x01000000;
while (!*zpu_in4)
{
// Wait until ready
}
*zpu_out4 = 0;
//printf(" RD1 ");
while (*zpu_in4)
{
// Wait until ready cleared
}
//printf(" RD2 ");
n_actual_mmc_sector=sector;
}
/*-----------------------------------------------------------------------*/
/* Initialize Disk Drive */
/*-----------------------------------------------------------------------*/
DSTATUS disk_initialize (void)
{
DSTATUS stat;
n_actual_mmc_sector = 0xffffffff;
//do
//{
// mmcInit();
//}
//while(mmcReset()); //dokud nenulove, tak smycka (return 0 => ok!)
//set_spi_clock_freq();
// no longer in ram (yet!), misuse will break us...
mmc_sector_buffer = (unsigned char *)0x4000; // 512 bytes in the middle of memory space!
stat = RES_OK;
return stat;
}
/*-----------------------------------------------------------------------*/
/* Read Partial Sector */
/*-----------------------------------------------------------------------*/
DRESULT disk_readp (
BYTE* dest, /* Pointer to the destination object */
DWORD sector, /* Sector number (LBA) */
WORD sofs, /* Offset in the sector */
WORD count /* Byte count (bit15:destination) */
)
{
DRESULT res;
/*debug("readp:");
plotnextnumber(sector);
debug(" ");
plotnextnumber((int)dest);
debug(" ");
plotnextnumber(sofs);
debug(" ");
plotnextnumber(count);
debug(" ");
plotnextnumber(atari_sector_buffer);
debug(" ");
plotnextnumber(mmc_sector_buffer);
debug("\n");
*/
// Put your code here
mmcReadCached(sector);
for(;count>0;++sofs,--count)
{
unsigned char x = mmc_sector_buffer[sofs];
//printf("char:%02x loc:%d", x,sofs);
*dest++ = x;
}
res = RES_OK;
return res;
}
/*-----------------------------------------------------------------------*/
/* Write Partial Sector */
/*-----------------------------------------------------------------------*/
DRESULT disk_writep (const BYTE* buff, DWORD sofs, DWORD count)
{
DRESULT res;
int i=sofs;
int end=sofs+count;
int pos = 0;
/* debug_pos = 0;
printf("WP:%x %d %d"),buff,sofs,count;
debug_pos = -1;*/
for (;i!=end;++i,++pos)
{
unsigned char temp = buff[pos];
unsigned int volatile* addr = (unsigned int volatile *)&mmc_sector_buffer[i&~3];
unsigned int prev = *(unsigned int volatile*)addr;
((char unsigned *)&prev)[i&3] = temp;
*addr = prev;
//mmc_sector_buffer[i] = buff[pos];
//printf("char:%c loc:%d,", buff[pos],i);
}
/* debug_pos = 40;
printf("WP DONE:%x %d %d"),buff,sofs,count;
debug_pos = -1;*/
res = RES_OK;
return res;
}
void disk_writeflush()
{
/* // Finalize write process
int retry=16; //zkusi to maximalne 16x
int ret;
//printf(":WSECT:%d",n_actual_mmc_sector);
do
{
ret = mmcWrite(n_actual_mmc_sector); //vraci 0 kdyz ok
retry--;
} while (ret && retry);
//printf(":WD:");
*/
/*debug_pos = 0;
printf("WF");
debug_pos = -1;*/
//printf(" WTF:%d:%x ", n_actual_mmc_sector, ((unsigned int *)mmc_sector_buffer)[0]);
*zpu_out4 = n_actual_mmc_sector|0x02000000;
while (!*zpu_in4)
{
// Wait until ready
}
*zpu_out4 = 0;
//printf(" PT1 ");
while (*zpu_in4)
{
// Wait until ready cleared
}
//printf(" PT2 ");
/*debug_pos = 40;
printf("DONE");
debug_pos = -1;*/
}
firmware/native/screen.c
void clearscreen()
{
}
firmware/test_drive.c
putc(c, stderr);
}
struct SimpleFile * files[5];
int main(void)
{
init_printf(NULL, char_out);
......
entry = dir_entries("");
entry = dir_next(dir_next(dir_next(entry)));
fprintf(stderr, " Name:%s", dir_filename(entry));
struct SimpleFile * file = alloca(file_struct_size());
int i;
for (i=0;i!=5;++i)
{
struct SimpleFile * file = alloca(file_struct_size());
file_init(file);
files[i] = file;
}
//file_open_dir(entry,file);
file_open_name("GUNPOWDR.ATR",file);
if (SimpleFile_OK == file_open_name("GUNPOWDR.ATR",files[0]))
{
}
else
{
fprintf(stderr,"\nARG\n");
}
int read = 0;
char buffer[1024];
//file_seek(file,100);
file_read(file,&buffer[0],1024,&read);
int i;
file_read(files[0],&buffer[0],1024,&read);
for (i=0; i!=read; ++i)
{
fprintf(stderr,"|%02x", (unsigned char)buffer[i]);
......
init_drive_emulator();
set_drive_status(0,file);
//set_drive_status(0,files[0]);
for (i=1;i!=5;++i)
{
char buffer[20];
describe_disk(i-1,&buffer[0]);
fprintf(stderr, "Drive %d:%s %s\n", i, file_name(get_file_status(i-1)), &buffer[0]);
}
int row = 6;
{
// 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);
}
for (i=1;i!=5;++i)
{
char buffer[20];
describe_disk(i-1,&buffer[0]);
fprintf(stderr, "Drive %d:%s %s\n", i, file_name(get_file_status(i-1)), &buffer[0]);
}
start_time = now();
run_drive_emulator();

Also available in: Unified diff