Example #1
0
/* ---------------------------------------------------------------------------
 * load PCB into buffer
 * parse the file with enabled 'PCB mode' (see parser)
 * if successful, update some other stuff
 */
bool
LoadLayoutToBuffer (BufferType *Buffer, char *Filename)
{
  PCBType *newPCB = CreateNewPCB (false);

  /* new data isn't added to the undo list */
  if (!ParsePCB (newPCB, Filename))
    {
      /* clear data area and replace pointer */
      ClearBuffer (Buffer);
      free (Buffer->Data);
      Buffer->Data = newPCB->Data;
      newPCB->Data = NULL;
      Buffer->X = newPCB->CursorX;
      Buffer->Y = newPCB->CursorY;
      RemovePCB (newPCB);
      Buffer->Data->pcb = PCB;
      return (true);
    }

  /* release unused memory */
  RemovePCB (newPCB);
      Buffer->Data->pcb = PCB;
  return (false);
}
Example #2
0
/* ---------------------------------------------------------------------------
 * load PCB
 * parse the file with enabled 'PCB mode' (see parser)
 * if successful, update some other stuff
 *
 * If revert is true, we pass "revert" as a parameter
 * to the HID's PCBChanged action.
 */
static int
real_load_pcb (char *Filename, bool revert)
{
  const char *unit_suffix, *grid_size;
  char *new_filename;
  PCBType *newPCB = CreateNewPCB (false);
  PCBType *oldPCB;
#ifdef DEBUG
  double elapsed;
  clock_t start, end;

  start = clock ();
#endif

  new_filename = strdup (Filename);

  oldPCB = PCB;
  PCB = newPCB;

  /* mark the default font invalid to know if the file has one */
  newPCB->Font.Valid = false;

  /* new data isn't added to the undo list */
  if (!ParsePCB (PCB, new_filename))
    {
      RemovePCB (oldPCB);

      CreateNewPCBPost (PCB, 0);
      ResetStackAndVisibility ();

      /* update cursor location */
      Crosshair.X = CLAMP (PCB->CursorX, 0, PCB->MaxWidth);
      Crosshair.Y = CLAMP (PCB->CursorY, 0, PCB->MaxHeight);

      /* update cursor confinement and output area (scrollbars) */
      ChangePCBSize (PCB->MaxWidth, PCB->MaxHeight);

      /* enable default font if necessary */
      if (!PCB->Font.Valid)
	{
	  Message (_
		   ("File '%s' has no font information, using default font\n"),
		   new_filename);
	  PCB->Font.Valid = true;
	}

      /* clear 'changed flag' */
      SetChangedFlag (false);
      PCB->Filename = new_filename;
      /* just in case a bad file saved file is loaded */

      /* Use attribute PCB::grid::unit as unit, if we can */
      unit_suffix = AttributeGet (PCB, "PCB::grid::unit");
      if (unit_suffix && *unit_suffix)
        {
          const Unit *new_unit = get_unit_struct (unit_suffix);
          if (new_unit)
            Settings.grid_unit = new_unit;
        }
      AttributePut (PCB, "PCB::grid::unit", Settings.grid_unit->suffix);
      /* Use attribute PCB::grid::size as size, if we can */
      grid_size = AttributeGet (PCB, "PCB::grid::size");
      if (grid_size)
        {
          PCB->Grid = GetValue (grid_size, NULL, NULL);
        }
 
      sort_netlist ();

      set_some_route_style ();

      if (revert)
        hid_actionl ("PCBChanged", "revert", NULL);
      else
        hid_action ("PCBChanged");

#ifdef DEBUG
      end = clock ();
      elapsed = ((double) (end - start)) / CLOCKS_PER_SEC;
      gui->log ("Loading file %s took %f seconds of CPU time\n",
		new_filename, elapsed);
#endif

      return (0);
    }
  PCB = oldPCB;
  hid_action ("PCBChanged");

  /* release unused memory */
  RemovePCB (newPCB);
  return (1);
}
Example #3
0
File: file.c Project: thequux/pcb
/* ---------------------------------------------------------------------------
 * load PCB
 * parse the file with enabled 'PCB mode' (see parser)
 * if successful, update some other stuff
 */
int
LoadPCB (char *Filename)
{
  PCBTypePtr newPCB = CreateNewPCB (false);
  PCBTypePtr oldPCB;
  bool units_mm;
#ifdef DEBUG
  double elapsed;
  clock_t start, end;

  start = clock ();
#endif

  oldPCB = PCB;
  PCB = newPCB;

  /* new data isn't added to the undo list */
  if (!ParsePCB (PCB, Filename))
    {
      RemovePCB (oldPCB);

      CreateNewPCBPost (PCB, 0);
      ResetStackAndVisibility ();

      /* update cursor location */
      Crosshair.X = MAX (0, MIN (PCB->CursorX, (LocationType) PCB->MaxWidth));
      Crosshair.Y =
	MAX (0, MIN (PCB->CursorY, (LocationType) PCB->MaxHeight));

      Xorig = Crosshair.X - TO_PCB (Output.Width / 2);
      Yorig = Crosshair.Y - TO_PCB (Output.Height / 2);

      /* update cursor confinement and output area (scrollbars) */
      ChangePCBSize (PCB->MaxWidth, PCB->MaxHeight);

      /* create default font if necessary */
      if (!PCB->Font.Valid)
	{
	  Message (_
		   ("File '%s' has no font information, using default font\n"),
		   Filename);
	  CreateDefaultFont ();
	}

      /* clear 'changed flag' */
      SetChangedFlag (false);
      PCB->Filename = strdup (Filename);
      /* just in case a bad file saved file is loaded */

      units_mm = (PCB->Grid != (int) PCB->Grid) ? true : false;

      Settings.grid_units_mm = units_mm;

      sort_netlist ();

      set_some_route_style ();

      hid_action ("PCBChanged");

#ifdef DEBUG
      end = clock ();
      elapsed = ((double) (end - start)) / CLOCKS_PER_SEC;
      gui->log ("Loading file %s took %f seconds of CPU time\n",
		Filename, elapsed);
#endif

      return (0);
    }
  PCB = oldPCB;
  hid_action ("PCBChanged");

  /* release unused memory */
  RemovePCB (newPCB);
  return (1);
}
Example #4
0
void svc(SYSTEM_CALL_DATA *SystemCallData) {
	short call_type;
	static short do_print = 10;
	short i;
	INT32 Time;
	int Status;
	void *PageTable;
	char* processName;

	MEMORY_MAPPED_IO mmio;
	call_type = (short) SystemCallData->SystemCallNumber;

	if (do_print > 0) {
		printf("SVC handler: %s\n", call_names[call_type]);
		for (i = 0; i < SystemCallData->NumberOfArguments - 1; i++) {
			//Value = (long)*SystemCallData->Argument[i];
			printf("Arg %d: Contents = (Decimal) %8ld,  (Hex) %8lX\n", i,
					(unsigned long) SystemCallData->Argument[i],
					(unsigned long) SystemCallData->Argument[i]);
		}
		do_print--;
	}

//	printf((char *) SystemCallData->Argument[i]);
	switch (call_type) {
	//get time service call
	case SYSNUM_GET_TIME_OF_DAY:
		mmio.Mode = Z502ReturnValue;
		mmio.Field1 = mmio.Field2 = mmio.Field3 = 0;
		MEM_READ(Z502Clock, &mmio);
		*(long *) SystemCallData->Argument[0] = mmio.Field1;
		break;
		//system sleep call
	case SYSNUM_SLEEP:

		mmio.Mode = Z502ReturnValue;
		mmio.Field1 = mmio.Field2 = mmio.Field3 = 0;
		MEM_READ(Z502Clock, &mmio);

		Time = (long) SystemCallData->Argument[0];

		pcb = FindCurrent(runningProcessPid);
		pcb->wakeUpTimer = Time;
		EnTimerQueue(&pcb_timer_queue, pcb);

		//start timer

		headPCB = GetHead(&pcb_timer_queue)->data;
		if (pcb == headPCB) {
			mmio.Mode = Z502Start;
			mmio.Field1 = (long) SystemCallData->Argument[0];
			mmio.Field2 = mmio.Field3 = 0;
			MEM_WRITE(Z502Timer, &mmio);
		}

		Dispatcher();

		break;
		//system create process
	case SYSNUM_CREATE_PROCESS:
		if ((long) SystemCallData->Argument[2] < 0) {
			*SystemCallData->Argument[4] = ERR_BAD_PARAM;
		} else {
			PageTable = (void *) calloc(2, NUMBER_VIRTUAL_PAGES);
			mmio.Mode = Z502InitializeContext;
			mmio.Field1 = 0;
			mmio.Field2 = (long) SystemCallData->Argument[1];
			mmio.Field3 = (long) PageTable;
			MEM_WRITE(Z502Context, &mmio);
			pcb = OSCreateProcess((char*) SystemCallData->Argument[0],
					(long) mmio.Field1, (long) SystemCallData->Argument[2],
					(long) SystemCallData->Argument[3],
					(long) SystemCallData->Argument[4]);
			if (pcb != NULL) {
				EnQueue(&pcb_ready_queue, (void*) pcb);
				*SystemCallData->Argument[3] = pcb->pid;
				*SystemCallData->Argument[4] = ERR_SUCCESS;
			} else {
				*SystemCallData->Argument[4] = ERR_BAD_PARAM;
			}
		}
		break;
		//system get process id

	case SYSNUM_GET_PROCESS_ID:
		processName = (char*) SystemCallData->Argument[0];
		if (strlen(processName) == 0) {
			*SystemCallData->Argument[1] = runningProcessPid;
			*SystemCallData->Argument[2] = ERR_SUCCESS;
		} else {
			pcb = FindPCBByName(processName);

		}
		if (pcb != NULL) {
			*SystemCallData->Argument[1] = pcb->pid;
			*SystemCallData->Argument[2] = ERR_SUCCESS;
		} else {
			*SystemCallData->Argument[2] = ERR_BAD_PARAM;
		}
		break;

	case SYSNUM_PHYSICAL_DISK_READ:
		do {
			mmio.Mode = Z502Status;
			mmio.Field1 = (long) SystemCallData->Argument[0];
			mmio.Field2 = mmio.Field3 = 0;
			MEM_READ(Z502Disk, &mmio);
			CALL(WasteTime());
		} while (mmio.Field2 != DEVICE_FREE);

		pcb = FindCurrent(runningProcessPid);
		if (pcb != NULL) {
			pcb->diskID = (int) SystemCallData->Argument[0];
			pcb->sectorID = (int) SystemCallData->Argument[1];
			pcb->memoryBuffer = (void*) SystemCallData->Argument[2];
			EnQueue(&(pcb_disk_queue[pcb->diskID]), (void*) pcb);
		}

		mmio.Mode = Z502DiskRead;
		mmio.Field1 = (long) SystemCallData->Argument[0];
		mmio.Field2 = (long) SystemCallData->Argument[1];
		mmio.Field3 = (long) SystemCallData->Argument[2];
		mmio.Field4 = 0;
		MEM_READ(Z502Disk, &mmio);

		do {
			mmio.Mode = Z502Status;
			mmio.Field1 = (long) SystemCallData->Argument[0];
			mmio.Field2 = mmio.Field3 = 0;
			MEM_READ(Z502Disk, &mmio);
			CALL(WasteTime());
		} while (mmio.Field2 != DEVICE_FREE);

		Dispatcher();

		break;
	case SYSNUM_PHYSICAL_DISK_WRITE:
		do {
			mmio.Mode = Z502Status;
			mmio.Field1 = (long) SystemCallData->Argument[0];
			mmio.Field2 = mmio.Field3 = 0;
			MEM_READ(Z502Disk, &mmio);
			CALL(WasteTime());
		} while (mmio.Field2 != DEVICE_FREE);

		pcb = FindCurrent(runningProcessPid);
		if (pcb != NULL) {
			pcb->diskID = (int) SystemCallData->Argument[0];
			pcb->sectorID = (int) SystemCallData->Argument[1];
			pcb->memoryBuffer = (void*) SystemCallData->Argument[2];
			EnQueue(&(pcb_disk_queue[pcb->diskID]), (void*) pcb);
		}

		mmio.Mode = Z502DiskWrite;
		mmio.Field1 = (long) SystemCallData->Argument[0];
		mmio.Field2 = (long) SystemCallData->Argument[1];
		mmio.Field3 = (long) SystemCallData->Argument[2];
		MEM_WRITE(Z502Disk, &mmio);

//		mmio.Mode = Z502Action;
//		mmio.Field1 = mmio.Field2 = mmio.Field3 = 0;
//		MEM_WRITE(Z502Idle, &mmio);
		do {
			mmio.Mode = Z502Status;
			mmio.Field1 = (long) SystemCallData->Argument[0];
			mmio.Field2 = mmio.Field3 = 0;
			MEM_READ(Z502Disk, &mmio);
			CALL(WasteTime());
		} while (mmio.Field2 != DEVICE_FREE);
		Dispatcher();
		break;

		//system terminate call
	case SYSNUM_TERMINATE_PROCESS:
		//If ProcessID = -1, then terminate self
		if ((long) SystemCallData->Argument[0] == -1) {
			pcb = FindCurrent(runningProcessPid);
			if (pcb != NULL) {
//				ReleasePCB();
//				RemovePCB(&pcb_ready_queue,(void*)pcb);
//				RemovePCB(&pcb_timer_queue,(void*)pcb);
//				*SystemCallData->Argument[1] = ERR_SUCCESS;
				if (pcb_ready_queue.size == 0 && pcb_timer_queue.size == 0) {
					mmio.Mode = Z502ReturnValue;
					mmio.Field1 = mmio.Field2 = mmio.Field3 = mmio.Field4 = 0;
					MEM_WRITE(Z502Halt, &mmio);
					*SystemCallData->Argument[1] = ERR_SUCCESS;
				} else {
					Dispatcher();
				}
			} else {
				ReleasePCB();
				mmio.Mode = Z502ReturnValue;
				mmio.Field1 = mmio.Field2 = mmio.Field3 = mmio.Field4 = 0;
				MEM_WRITE(Z502Halt, &mmio);
				*SystemCallData->Argument[1] = ERR_SUCCESS;
			}

		} else if ((long) SystemCallData->Argument[0] == -2) {
			// terminite all halt
			ReleasePCB();
			mmio.Mode = Z502ReturnValue;
			mmio.Field1 = mmio.Field2 = mmio.Field3 = mmio.Field4 = 0;
			MEM_WRITE(Z502Halt, &mmio);
			*SystemCallData->Argument[1] = ERR_SUCCESS;
//			pcb = FindCurrent(runningProcessPid);
//			RemovePCB(&pcb_ready_queue, (void*) pcb);
//			RemovePCB(&pcb_timer_queue, (void*) pcb);
//			RemovePCB(&pcb_ready_queue, (void*) pcb->childProcesses);
//			RemovePCB(&pcb_timer_queue, (void*) pcb->childProcesses);

		} else {
			pcb = FindPCBByPID(SystemCallData->Argument[0]);
			RemovePCB(&pcb_ready_queue, (void*) pcb);
			*SystemCallData->Argument[1] = ERR_SUCCESS;

		}
		break;
		defaut: printf("ERROR! call_type not recognized!\n");
		printf("Call_type is %i\n", call_type);
	}
}                                               // End of svc