Project

General

Profile

« Previous | Next » 

Revision 318

Added by markw over 10 years ago

Fix some timing issues on faster CPUs - e.g. ARM on SOCKIT

View differences:

firmware/atari_drive_emulator.c
#include "hexdump.h"
//#include "printf.h"
//#include <stdio.h>
#include "integer.h"
extern int debug_pos; // ARG!
......
unsigned char drive_info[MAX_DRIVES];
enum DriveInfo {DI_XD=0,DI_SD=1,DI_MD=2,DI_DD=3,DI_BITS=3,DI_RO=4};
//#ifdef SOCKIT
//double when()
//{
// struct timeval tv;
// gettimeofday(&tv,0);
// double now = tv.tv_sec;
// now += tv.tv_usec/1e6;
// return now;
//}
//#endif
struct ATRHeader
{
u16 wMagic;
......
int expchk;
int i;
//printf("\n%f:WaitCMD\n",when());
while (0 == USART_Command_Line());
//printf("%f:CMDHigh\n",when());
USART_Init(speed+6);
//printf("%f:Clear:%d\n",when(),*zpu_siocommand_ready);
*zpu_siocommand_ready = 1; // clear
while (1)
......
unsigned char x = *zpu_siocommand_ready;
if (x != 0) break;
actions();
//#ifdef SOCKIT
// double a = when();
// while ((when()-a)<3e-6);
//#endif
wait_us(3);
} // usb poll can take some ms, but we have 16 ms to reply. We have hardware now to capture the command frame.
for (i=0;i!=5;++i)
((unsigned char *)cmd)[i] = zpu_siocommand_data[i<<2];
......
/*unsigned char * temp = baseaddr;
baseaddr = (unsigned char volatile *)(40000 + atari_regbase);
debug_pos=160;
printf("CMD:%02x %02x %02x %02x %02x/%02x ",cmd->deviceId,cmd->command,cmd->aux1,cmd->aux2,cmd->chksum,expchk);
*/
//printf("%f:CMD: %02x %02x %02x %02x %02x/%02x %s\n",when(),cmd->deviceId,cmd->command,cmd->aux1,cmd->aux2,cmd->chksum,expchk, cmd->chksum!=expchk ? "BAD":"");
/*
baseaddr = temp;*/
//printf("Device id:");
......
int sectorSize = 0;
int location =0;
//printf("WACK:");
USART_Transmit_Mode();
if (file_readonly(file))
{
......
USART_Receive_Mode();
return;
}
//printf("%f:WACK\n",when());
send_ACK();
USART_Wait_Transmit_Complete();
USART_Receive_Mode();
......
}
// Receive the data
//printf("%f:Getting data\n",when());
int i;
for (i=0;i!=sectorSize;++i)
{
......
//hexdump_pure(atari_sector_buffer,sectorSize); // Somehow with this...
unsigned char expchk = get_checksum(&atari_sector_buffer[0],sectorSize);
//printf("DATA:%d:",sectorSize);
//printf("CHK:%02x EXP:%02x", checksum, expchk);
//printf("%f:CHK:%02x EXP:%02x %s\n", when(), checksum, expchk, checksum!=expchk ? "BAD" : "");
//printf(" %d",atari_sector_buffer[0]); // and this... The wrong checksum is sent!!
//printf(":done\n");
if (checksum==expchk)
{
//DELAY_T2_MIN
wait_us(20);
USART_Transmit_Mode();
//printf(":WACK2:");
//printf("%f:WACK data\n",when());
send_ACK();
USART_Wait_Transmit_Complete();
......
DELAY_T5_MIN;
if (ok)
{
//printf(":CMPL:");
//printf("%f:CMPL\n",when());
send_CMPL();
}
else
{
//printf(":NACK:");
//printf("%f:NACK(verify failed)\n",when());
send_NACK();
}
......
}
else
{
//printf(":NACK:");
//printf("%f:NACK(bad checksum)\n",when());
send_NACK();
USART_Wait_Transmit_Complete();
......
int read = 0;
int location =0;
DELAY_T2_MIN
USART_Transmit_Mode();
//printf("%f:ACK\n",when());
send_ACK();
//printf("Sector:");
//printf("%d",sector);
......
}
//printf("%d",location);
//printf("\n");
//printf("%f:Read\n",when());
file_seek(file,location);
file_read(file,&atari_sector_buffer[0], sectorSize, &read);
//printf("%f:Read done\n",when());
}
//topofscreen();
......
//printf("%d",len);
DELAY_T5_MIN;
//printf("%f:CMPL\n",when());
send_CMPL();
// Hias: changed to 100us so that Qmeg3 works again with the
......
DELAY_T3_PERIPH;
check_sum = 0;
//printf("%f:SendBuffer\n",when());
USART_Send_Buffer(atari_sector_buffer,len);
// tx_checksum is updated by bit-banging USART_Transmit_Byte,
// so we can skip separate calculation
check_sum = get_checksum(atari_sector_buffer,len);
USART_Transmit_Byte(check_sum);
//printf("%f:Done\n",when());
//hexdump_pure(atari_sector_buffer,len);
/*printf(":chk:");
printf("%d",check_sum);
firmware/sockit/memory.c
zpu_base = (unsigned char *)virtual_base + 0x1000000;
//pokey_regbase = (unsigned char *)virtual_base + 0x1000400;
//struct sched_param param;
//param.sched_priority = 50;
//sched_setscheduler(0,SCHED_RR,&param);
struct sched_param param;
param.sched_priority = 50;
sched_setscheduler(0,SCHED_RR,&param);
}

Also available in: Unified diff