Exemple #1
0
/**
 * main
 * This function initializes all graphical variables as well as opens the input
 * file and calls a function which populates a 2D array accordingly. It then
 * calls run(), which takes care of the actual running of the Game of Life.
 * Finally, it restores the video mode to the original state and releases
 * keyboard control.
 **/
int main(int argc, char *argv[]) {
	//this array stores the current life state
    int model[COLUMNS][ROWS] = {0}; 
    key_init(); //takes control of keyboard input
    init_graphics(); //switches to XGA
    my_video_ds = __dpmi_allocate_ldt_descriptors(1);
    __dpmi_set_segment_base_address(my_video_ds,ADDR);
    ADDR = 0;	/* basis now zero from selector */
    __dpmi_set_segment_limit(my_video_ds,(width*height)|0xfff);
    //the following reads in a file if one was given and populates the grid
    if (argc==2) {
	FILE *fp = fopen(argv[1], "r");
	if (fp == 0) {
            printf("Error - invalid filename\n" );
	    return 0;
        }
        else {
	    populate(model, fp);
	}
    }
    run(model); //runs the program
    close_graphics(); //restores video mode to original state
    key_delete(); //releases control over the keyboard
    return 0;
}
Exemple #2
0
static int
selector_for_phys_mem (uint32 base, uint32 num_bytes)
{
  int sel;
  uint32 seg_lim;
  __dpmi_meminfo minfo;

  /* Allocate a descriptor. */
  sel = __dpmi_allocate_ldt_descriptors (1);
  if (sel == -1)
    return -1;

  seg_lim = ((num_bytes + 4095) & ~4095) - 1;

  /* Map the physical memory into linear address space. */
  minfo.handle  = 0;		/* unused */
  minfo.size    = seg_lim + 1;
  minfo.address = base;
  if (__dpmi_physical_address_mapping (&minfo) != 0)
    return -1;

  if (__dpmi_set_segment_base_address (sel, minfo.address) == -1)
    return -1;
  if (__dpmi_set_segment_limit (sel, seg_lim) == -1)
    return -1;

  return sel;
}
Exemple #3
0
/**
 * drawText
 * Draws the specified string at the specified position in the specified color
 * using text blitting.
 **/
void drawText(int x, int y, char text[], char color, int font) {
    // defines segment for text
    int mytext = __dpmi_allocate_ldt_descriptors(1);
    __dpmi_set_segment_base_address(mytext, 0xffa6e);
    __dpmi_set_segment_limit(mytext, 8*128);
    char row;
    int i,j,k;
    for (i=0; text[i]!=0; i++) { //iterates through string
		for (j=0; j<8; j++) { //iterates through rows
			//gets jth row of char
			row = _farpeekb(mytext, text[i]*8+j);
			for (k=0; k<8; k++) { //iterates through pixels
				// decides if pixel should be drawn at position
				if (row & 0x80) {
					drawScaledPixel(x+(k+8*i)*font,y+j*font,font,color);
				}
				row <<= 1; //shifts bits to left by one
			}
		}
	}
}
Exemple #4
0
int
MPATH_Init ( void )
{
	int		i;
	struct hostent *local = NULL;
	char	buff[MAXHOSTNAMELEN];
	struct qsockaddr addr;
	char	*p;

	if (COM_CheckParm ("-mpath") == 0)
		return -1;

	flat_selector = __dpmi_allocate_ldt_descriptors(1);
	if (flat_selector == -1) {
		Con_Printf("MPATH_Init: Can't get flat selector\n");
		return -1;
	}
	if (__dpmi_set_segment_base_address(flat_selector, 0) == -1) {
		Con_Printf("MPATH_Init: Can't seg flat base!\n");
		return -1;
	}
	if (__dpmi_set_segment_limit(flat_selector, 0xffffffff) == -1) {
		Con_Printf("MPATH_Init: Can't set segment limit\n");
		return -1;
	}
	// determine my name & address
	if (gethostname(buff, MAXHOSTNAMELEN) == 0)
		local = gethostbyname(buff);
	if (local)
	{
		myAddr = *(int *)local->h_addr_list[0];

		// if the quake hostname isn't set, set it to the machine name
		if (Q_strcmp(hostname -> string, "UNNAMED") == 0)
		{
			// see if it's a text IP address (well, close enough)
			for (p = buff; *p; p++)
				if ((*p < '0' || *p > '9') && *p != '.')
					break;

			// if it is a real name, strip off the domain; we only want the host
			if (*p)
			{
				for (i = 0; i < 15; i++)
					if (buff[i] == '.')
						break;
				buff[i] = 0;
			}
			Cvar_Set (hostname, buff);
		}
	}

	if ((net_controlsocket = MPATH_OpenSocket (0)) == -1)
		Sys_Error("MPATH_Init: Unable to open control socket\n");

	((struct sockaddr_in *)&broadcastaddr)->sin_family = AF_INET;
	((struct sockaddr_in *)&broadcastaddr)->sin_addr.s_addr = INADDR_BROADCAST;
	((struct sockaddr_in *)&broadcastaddr)->sin_port = htons(net_hostport);

	MPATH_GetSocketAddr (net_controlsocket, &addr);
	Q_strcpy(my_tcpip_address, MPATH_AddrToString (&addr));
	p = Q_strrchr (my_tcpip_address, ':');
	if (p)
		*p = 0;

	Con_Printf("MPath Initialized\n");
	tcpipAvailable = true;

	return net_controlsocket;
}