Exemplo n.º 1
0
void read_sector_n(const unsigned int cylinder, 
		   const unsigned int sector, 
		   unsigned char* buffer, 
		   const size_t n){

  int i;  


  if( !seek_sector(cylinder, sector) ){
    buffer = NULL;
    return;
  }


  /* Mettre dans MASTERBUFFER les donnees a cette emplacement */
  _out(HDA_DATAREGS, 1);
  _out(HDA_CMDREG, CMD_READ);
  _sleep(HDA_IRQ);


  /* exploiter les donnees de MASTERBUFFER */
  for(i=0; i<HDA_SECTORSIZE && i<n; i++){
    buffer[i] = (unsigned char)MASTERBUFFER[i];
  }
}
Exemplo n.º 2
0
void CSystemTestDlg::_locateWindowInfo(CCgxWindow* wind, PTSTR winName)
{
	TCHAR buff[MAX_PATH] = {0};
	RECT rect;
	if(wind->locate())
	{
		CHWNDScreen::flashRECT(&(wind->rect));
		swprintf(buff, sizeof(TCHAR)*MAX_PATH, TEXT("Window [%s] x: %d y: %d"), winName, wind->rect.left, wind->rect.top);
		_out(buff);
		for(int i = 0; i < MAX_COMMAND; ++i)
		{
			if(wind->getCommand(i, &rect))
			{
				CHWNDScreen::flashRECT(&rect);
				if(wind->isCommandEnable(i))
					TRACE("Command[%d] is enabled.\n", i);
				else
					TRACE("Command[%d] is diabled.\n", i);
			}
		}
		
	}
	else
	{
		swprintf(buff, sizeof(TCHAR)*MAX_PATH, TEXT("Can not locate [%s] window"), winName);
		_out(buff);
	}
}
Exemplo n.º 3
0
void read_sector(unsigned int cylinder, unsigned int sector, unsigned char* buffer){

  int secteur_size;
  int tmp, i;  


  if( !seek_sector(cylinder, sector) ){
    buffer = NULL;
    return;
  }


  /* Mettre dans MASTERBUFFER les donnees a cette emplacement */
  _out(HDA_DATAREGS, 1);
  _out(HDA_CMDREG, CMD_READ);
  _sleep(HDA_IRQ);


  /* exploiter les donnees de MASTERBUFFER */
  _out(HDA_CMDREG, CMD_DSKINFO);

  tmp = _in(HDA_DATAREGS+4);
  tmp = tmp<<8;
  secteur_size = tmp + _in(HDA_DATAREGS+5);

  for(i=0; i<secteur_size; i++){
    buffer[i] = (unsigned char)MASTERBUFFER[i];
  }

  buffer[++i] = EOF;
}
Exemplo n.º 4
0
int
main (int argc, char **argv)
{
  unsigned int i;

  /* init hardware */
  if (init_hardware (HARDWARE_INI) == 0)
    {
      fprintf (stderr, "Error in hardware initialization\n");
      exit (EXIT_FAILURE);
    }

  /* dummy interrupt handlers */
  for (i = 0; i < 16; i++)
    IRQVECTOR[i] = empty_it;

  /* program timer */
  IRQVECTOR[TIMER_IRQ] = timer_it;
  _out (TIMER_PARAM, 128 + 64 + 32 + 8);	/* reset + alarm on + 8 tick / alarm */
  _out (TIMER_ALARM, 0xFFFFFFFE);	/* alarm at next tick (at 0xFFFFFFFF) */

  /* allows all IT */
  _mask (1);

  /* count for a while... */
  for (i = 0; i < (1 << 28); i++)
    ;

  /* and exit! */
  exit (EXIT_SUCCESS);
}
Exemplo n.º 5
0
Arquivo: drive.c Projeto: ymah/TP5-2
void deplacerTete(unsigned int piste,unsigned int secteur){

  int i;
  if(piste < 0 || piste > HDA_SECTORSIZE){
    printf("numero de piste incorrect");
    exit(EXIT_FAILURE);
  }
  if(secteur < 0 || piste > HDA_MAXSECTOR){
    printf("numero de secteur incorrect");
    exit(EXIT_FAILURE);
  }

  for(i=0;i<16;i++)
    IRQVECTOR[i]= empty_it;

  /* chargement des donnée concernant la piste */
  _out(HDA_DATAREGS,piste>>8);
  _out(HDA_DATAREGS+1,piste & 0x00FF);

  /* chargement des donnée concernant le secteur  */
  _out(HDA_DATAREGS+2,secteur>>8);
  _out(HDA_DATAREGS+3,secteur & 0x00FF);
  _out(HDA_CMDREG,CMD_SEEK);

  _sleep(HDA_IRQ);
}
Exemplo n.º 6
0
// Set up a memory regions to access GPIO
void setup_io()
{
	_out(DDB0, DDRB); // CSN
	_out(DDB1, DDRB); // SCK
	_out(DDB2, DDRB); // MOSI
	 _in(DDB3, DDRB); // MISO
	_out(DDB4, DDRB); // CE
} // setup_io
Exemplo n.º 7
0
Arquivo: drive.c Projeto: ymah/TP5-2
void write_sector_t(unsigned int piste,unsigned int secteur, unsigned char *buffer,unsigned int size){
  int i;
  deplacerTete(piste,secteur);
  for(i=0;i<size;i++)
    MASTERBUFFER[i]=buffer[i];
  _out(HDA_DATAREGS,0);
  _out(HDA_DATAREGS+1,1);
  _out(HDA_CMDREG,CMD_WRITE);
  _sleep(HDA_IRQ);
}
Exemplo n.º 8
0
static void goto_sector(unsigned int cylinder, unsigned int sector) {
	check_hda();
	check_hda_bounds(cylinder, sector);

	_out(HDA_DATAREGS, (cylinder >> 8) & 0xFF);
	_out(HDA_DATAREGS + 1, cylinder & 0xFF);
	_out(HDA_DATAREGS + 2, (sector >> 8) & 0xFF);
	_out(HDA_DATAREGS + 3, sector & 0xFF);
	_out(HDA_CMDREG, CMD_SEEK);
	_sleep(HDA_IRQ);
}
// Set up a memory regions to access GPIO
void setup_io()
{
	_out(SPI_CSN, DDRD); // CSN
    _out(SPI_CE, DDRD); // CE
	_out(DDB5, DDRB); // SCK
	 _in(DDB4, DDRB); // MISO
	_out(DDB3, DDRB); // MOSI
	// SS pin of AVR must be configured as output.
	// If it is input and it happens to be ever low, the AVR SPI hardware will drop out of master mode into slave mode,
	// and it will not resume until you put it back into master mode. So basically you cannot use AVR SS pin as input when you want to be the SPI master.
	_out(DDB2, DDRB); // SS
} // setup_io
Exemplo n.º 10
0
void read_sector_n(unsigned int cylinder, unsigned int sector,
		unsigned int size, unsigned char* buffer) {

	goto_sector(cylinder, sector);

	_out(HDA_DATAREGS, 1);
	_out(HDA_DATAREGS + 1, 1);
	_out(HDA_CMDREG, CMD_READ);
	_sleep(HDA_IRQ);

	memcpy(buffer, MASTERBUFFER, size);
}
Exemplo n.º 11
0
void soundOn(){
	
	char value;
	
	_out(43h,B6h);
	_out(42h,54);
	_out(42h,124);
	
	value = _in(61h);
	value = value | 3;	/*(Turn on bits 1 and 2)*/
	_out 61h, value;
}
Exemplo n.º 12
0
void write_sector_n(unsigned int cylinder, unsigned int sector,
		unsigned int size, unsigned char* buffer) {

	memcpy(MASTERBUFFER, buffer, size);

	goto_sector(cylinder, sector);

	_out(HDA_DATAREGS, 1);
	_out(HDA_DATAREGS + 1, 1);

	_out(HDA_CMDREG, CMD_WRITE);
	_sleep(HDA_IRQ);
}
Exemplo n.º 13
0
static void
timer_it ()
{
  static int tick = 0;
  fprintf (stderr, "hello from IT %d\n", ++tick);
  _out (TIMER_ALARM, 0xFFFFFFFE);
}
Exemplo n.º 14
0
void ReadAndWriteXML::save(const QString namefile, const QDomDocument * doc) {
    QFile _file(namefile,this);
    _file.open(QFile::ReadWrite);
    QTextStream _out(&_file);
    doc->save(_out, indentation);
    _file.close();
}
Exemplo n.º 15
0
int 
main() 
{

    unsigned int i;

    if(init_hardware("etc/hardware.ini") == 0) {
	fprintf(stderr, "Error in hardware initialization\n");
        exit(EXIT_FAILURE);
    }
    
    printf("ATTENTION !\nSi l'on donne une taille de matrice très grande, le processus peut prendre un certain temps\n\n");
    printf("MATRIX_SIZE : %d\n\n", MATRIX_SIZE);
    for(i=0;i<16;i++){
	IRQVECTOR[i] = ignore;
    }

    _out(MMU_PROCESS,1);


    IRQVECTOR[MMU_IRQ] = mmuhandler;
    IRQVECTOR[SYSCALL_SWTCH_0] = switch_to_process0;
    IRQVECTOR[SYSCALL_SWTCH_1] = switch_to_process1;
    _mask(0x1001);

    if(init_swap("./swap_file")==-1){
	printf("erreur\n");
    }
    init();
    return 0;
}
Exemplo n.º 16
0
static void mmuhandler() 
{
    int fault = _in(MMU_FAULT_ADDR);
    struct tlb_entry_s tlb_entry;
    
    assert(fault >= (int)virtual_memory && fault <= (int)virtual_memory + VM_SIZE - 1);
    
    tlb_entry.tlbe_cfu = 0;
    tlb_entry.tlbe_x_access = 1;
    tlb_entry.tlbe_w_access = 1;
    tlb_entry.tlbe_r_access = 1;
    tlb_entry.tlbe_used = 1;
    
    if(vm_mapping[vpage_of_vaddr(fault)].mapped)
    {
        tlb_entry.tlbe_physical_page = vm_mapping[vpage_of_vaddr(fault)].ppage;
        tlb_entry.tlbe_virtual_page = vpage_of_vaddr(fault);
        _out(TLB_ADD_ENTRY, *((int*)&tlb_entry));
        return;
    }

    if(pm_mapping[victime_rr].mapped)
    {
        store_to_swap(pm_mapping[victime_rr].vpage, victime_rr);
        pm_mapping[victime_rr].mapped = 0;
        vm_mapping[pm_mapping[victime_rr].vpage].mapped = 0;
        tlb_entry.tlbe_physical_page = victime_rr;
        _out(TLB_DEL_ENTRY, *((int*)&tlb_entry));
    }

    fetch_from_swap(vpage_of_vaddr(fault), victime_rr);
    
    pm_mapping[victime_rr].mapped = 1;
    pm_mapping[victime_rr].vpage = vpage_of_vaddr(fault);
    
    vm_mapping[vpage_of_vaddr(fault)].mapped = 1;
    vm_mapping[vpage_of_vaddr(fault)].ppage = victime_rr;
    
    tlb_entry.tlbe_physical_page = victime_rr;
    tlb_entry.tlbe_virtual_page = vpage_of_vaddr(fault);
    
    _out(TLB_ADD_ENTRY, *((int*)&tlb_entry));
    
    victime_rr = (victime_rr % 255) + 1;
    
    return;
}
Exemplo n.º 17
0
/********************************************************************************
	Functions
********************************************************************************/
void initGPIO() {
    _in(DDD2, DDRD); // INT0 input

    // GPIO Interrupt INT0
    // The falling edge of INT0 generates an interrupt request.
    EICRA = (0<<ISC11)|(0<<ISC10)|(1<<ISC01)|(0<<ISC00);
    // Enable INT0
    EIMSK = (1<<INT0);

	_out(DDD3, DDRD); // OC2B
	_out(DDD5, DDRD); // OC0B
	_out(DDD6, DDRD); // OC0A

	_on(PD3, PORTD); // OC2B
	_on(PD5, PORTD); // OC0B
	_on(PD6, PORTD); // OC0A
}
Exemplo n.º 18
0
void format_sector(unsigned int cylinder, unsigned int sector,
		unsigned int nsector, unsigned int value) {
	check_hda_bounds(cylinder, sector);

	goto_sector(cylinder, sector);

	_out(HDA_DATAREGS, (nsector >> 8) && 0xFF);
	_out(HDA_DATAREGS + 1, nsector & 0xFF);

	_out(HDA_DATAREGS + 2, (value >> 24) && 0xFF);
	_out(HDA_DATAREGS + 3, (value >> 16) && 0xFF);
	_out(HDA_DATAREGS + 4, (value >> 8) && 0xFF);
	_out(HDA_DATAREGS + 5, value & 0xFF);

	_out(HDA_CMDREG, CMD_FORMAT);

	_sleep(HDA_IRQ);
}
Exemplo n.º 19
0
/* Fonction du fichier drive.c
 *
 * Change la position de la tete de lecteur du disque
 */
int seek_sector(const unsigned int cylinder, const unsigned int sector){

  if(!is_valid_cylinder(cylinder) || !is_valid_sector(sector)){
    return 0;
  }


  /* On se position sur le disque dur */
  _out(HDA_DATAREGS, (cylinder>>8 & 0xFF) );
  _out(HDA_DATAREGS+1, (cylinder & 0xFF) );
  _out(HDA_DATAREGS+2, (sector>>8 & 0xFF) );
  _out(HDA_DATAREGS+3, (sector & 0xFF) );

  _out(HDA_CMDREG, CMD_SEEK);
  _sleep(HDA_IRQ);

  return 1;

}
Exemplo n.º 20
0
void CSystemTestDlg::OnLbnDblclkImageList()
{
	CString str;
	TCHAR buff[MAX_PATH] = {0};
	CListBox* listBox = (CListBox *)GetDlgItem(IDC_IMAGE_LIST);
	int idx = listBox->GetCurSel();
	if(idx > -1)
	{
		int len = listBox->GetTextLen(idx);
		listBox->GetText(idx, str);
		swprintf(buff, sizeof(TCHAR)*MAX_PATH, TEXT("img\\screenshot\\%s"), str.GetBuffer(0));

		_out(TEXT("Loading file:"));
		_out(buff);
		_initScreen(buff);
		
	}
	
}
Exemplo n.º 21
0
void init()
{
	uint ncyl = 0, nsec = 0, sector_size = 0, status=0;
	uint i;
    char* hw_config;

    hw_config = getenv("HW_CONFIG");
    hw_config = hw_config ? hw_config : DEFAULT_HW_CONFIG;

	/* Met le microprocesseur en mode maitre */
	puts("Initialisation du matériel ...");
	status = init_hardware(hw_config);
	if (!status)
		{printf("error in hardware initialization with %s\n", hw_config);}

	/*init_hardware("etc/hardware.ini");*/

	/* Prépare les interruptions */
	puts("Préparation des interruptions...");
	for(i = 0; i < IRQ_VECTOR_SIZE; i++)
	{
		IRQVECTOR[i] = empty_it;
	}

	/* Vérifie la géométrie du disque */
	puts("Vérification du disque ...");
	/* Retourne la géométrie du disque dans HDA_DATAREGS */
	_out(HDA_CMDREG, CMD_DSKINFO);

	/* Lit la géométrie du disque octet par octet */
	ncyl		= (_in(HDA_DATAREGS + 0) << 8) + _in(HDA_DATAREGS + 1);
	nsec		= (_in(HDA_DATAREGS + 2) << 8) + _in(HDA_DATAREGS + 3);
	sector_size	= (_in(HDA_DATAREGS + 4) << 8) + _in(HDA_DATAREGS + 5);

	if (HDA_MAXCYLINDER != ncyl)
	{
		puts("Nombre de cylindres invalide à l'initialisation");
		exit(INVALID_GEOMETRY);
	}
	
	if (HDA_MAXSECTOR != nsec)
	{
		puts("Nombre de secteurs invalide à l'initialisation");
		exit(INVALID_GEOMETRY);
	}
	
	if (HDA_SECTORSIZE != sector_size)
	{
		puts("Taille des secteurs invalide à l'initialisation");
		exit(INVALID_GEOMETRY);
	}

	puts("Initialisation terminée\n");
}
Exemplo n.º 22
0
void format_sector(const unsigned int cylinder, 
		   const unsigned int sector, 
		   const unsigned int nsector, 
		   const unsigned int value){
  
  if( !seek_sector(cylinder, sector) ){
    return;
  }

  _out(HDA_DATAREGS, (nsector>>8 & 0xFF) );
  _out(HDA_DATAREGS+1, (nsector & 0xFF) );
  _out(HDA_DATAREGS+2, (value>>24 & 0xFF) );
  _out(HDA_DATAREGS+3, (value>>16 & 0xFF) );
  _out(HDA_DATAREGS+4, (value>>8 & 0xFF) );
  _out(HDA_DATAREGS+5, (value & 0xFF) );

  _out(HDA_CMDREG, CMD_FORMAT);
  _sleep(HDA_IRQ);

}
Exemplo n.º 23
0
void CSystemTestDlg::OnBnClickedLocateMonster()
{
	TCHAR buff[MAX_PATH] = {0};
	if(pScreen)
	{
		CCgxMonster monster(pScreen);
		int alive = monster.countAlive();
		swprintf(buff, sizeof(TCHAR)* MAX_PATH, TEXT("Found number of monster is: %d"), alive);
		_out(buff);
		for(int i = 0; i < NUMBER_OF_MONSTER; ++i)
		{
			if(monster.isAlive(i))
			{
				swprintf(buff, sizeof(TCHAR)*MAX_PATH, TEXT("Alive index: %d"), i);
				_out(buff);
				CHWNDScreen::flashRECT(&monster.monsterRECTs[i]);
			}
		}
	}
}
Exemplo n.º 24
0
void CSystemTestDlg::OnBnClickedRefreshImageList()
{
	CFileFind finder;
	CListBox* list = (CListBox*)GetDlgItem(IDC_IMAGE_LIST);
	list->ResetContent();
	BOOL bWorking = finder.FindFile(TEXT("img\\screenshot\\*.bmp"));
	while(bWorking) {
		bWorking = finder.FindNextFile();
		list->AddString(finder.GetFileName());
	}
	_out(TEXT("Refresh done."));
}
Exemplo n.º 25
0
void CSystemTestDlg::OnBnClickedRefreshMatchList()
{
	CFileFind finder;
	CListBox* list = (CListBox*)GetDlgItem(IDC_MATCH_LIST);
	list->ResetContent();
	BOOL bWorking = finder.FindFile(TEXT("img\\match\\*.bmp"));
	while(bWorking) {
		bWorking = finder.FindNextFile();
		list->AddString(finder.GetFileName());
	}
	_out(TEXT("Refresh Match list done."));
}
Exemplo n.º 26
0
Arquivo: drive.c Projeto: ymah/TP5-2
void dmps(int piste,int secteur){
  int i;
  for(i=0;i<16;i++)
    IRQVECTOR[i]= empty_it;


  /* chargement des donnée concernant la piste */
  _out(HDA_DATAREGS,piste>>8);
  _out(HDA_DATAREGS+1,piste & 0x00FF);

  /* chargement des donnée concernant le secteur  */
  _out(HDA_DATAREGS+2,secteur>>8);
  _out(HDA_DATAREGS+3,secteur & 0x00FF);

  /*commande pour positionner la tete de lecture */
  _out(HDA_CMDREG,CMD_SEEK);
  _sleep(HDA_IRQ);

  _out(HDA_DATAREGS,0);
  _out(HDA_DATAREGS+1,1);
  _out(HDA_CMDREG,CMD_READ);
  _sleep(HDA_IRQ);


  for(i=0;i<HDA_SECTORSIZE;i++)
    printf("%x ",MASTERBUFFER[i]);

  return ;
}
Exemplo n.º 27
0
void CSystemTestDlg::OnBnClickedMatch()
{
	RECT rect = {200, 200, 400, 400};
	CImage image;
	if(pScreen)
	{	
		CHWNDScreen::loadInToCImage(TEXT("img\\rect-tmp.bmp"), &image);
		if(pScreen->match(&image, &rect))
		{
			_out(TEXT("MATCH"));
		}
	}
}
Exemplo n.º 28
0
void write_sector(unsigned int cylinder, unsigned int sector, unsigned char* buffer){
    
  int i;
  int length;  

  if( !seek_sector(cylinder, sector) ){
    buffer = NULL;
    return;
  }

  /* ecrire les donnees dans MASTERBUFFER */
  length = strlen((char*)buffer);

  for(i=0; i<length || i< HDA_SECTORSIZE; i++){
    MASTERBUFFER[i] = buffer[i];
  }

  /* Mettre dans le disque les donnees de MASTERBUFFER */
  _out(HDA_DATAREGS, 0);
  _out(HDA_DATAREGS, 1);
  _out(HDA_CMDREG, CMD_WRITE);
  _sleep(HDA_IRQ);
}
Exemplo n.º 29
0
void write_sector_n(const unsigned int cylinder, 
		    const unsigned int sector, 
		    const unsigned char* buffer,
		    const size_t n){
  
  int i;

  if( !seek_sector(cylinder, sector) ){
    buffer = NULL;
    return;
  }

  /* ecrire les donnees dans MASTERBUFFER */
  for(i=0; i<HDA_SECTORSIZE && i<n; i++){
    MASTERBUFFER[i] = buffer[i];
  }

  /* Mettre dans le disque les donnees de MASTERBUFFER */
  _out(HDA_DATAREGS, 0);
  _out(HDA_DATAREGS, 1);
  _out(HDA_CMDREG, CMD_WRITE);
  _sleep(HDA_IRQ);

}
Exemplo n.º 30
0
void CSystemTestDlg::OnLbnDblclkMatchList()
{
	CString str;
	TCHAR buff[MAX_PATH] = {0};
	CListBox* listBox = (CListBox *)GetDlgItem(IDC_MATCH_LIST);
	int idx = listBox->GetCurSel();
	CImage image;
	RECT rect;
	if(idx > -1)
	{
		int len = listBox->GetTextLen(idx);
		listBox->GetText(idx, str);
		swprintf(buff, sizeof(TCHAR)*MAX_PATH, TEXT("img\\match\\%s"), str.GetBuffer(0));
		CHWNDScreen::loadInToCImage(buff, &image);
		_out(TEXT("Load match image done."));
		if(pScreen->locate(&image, &rect))
		{
			swprintf(buff, sizeof(TCHAR)*MAX_PATH, TEXT("Locate left: %d, right: %d, top: %d, bottom: %d")
				, rect.left, rect.right, rect.top, rect.bottom);
			_out(buff);
			CHWNDScreen::flashRECT(&rect);
		}
	}
}