コード例 #1
0
ファイル: 8390.c プロジェクト: andreasbock/minix
/*
**  Name:	void dp_pio16_nic2user(dpeth_t *dep, int pageno, int pktsize)
**  Function:	Copies a packet from board to user area (Prog. I/O, 16bits).
*/
static void dp_pio16_nic2user(dpeth_t * dep, int nic_addr, int count)
{
  phys_bytes phys_user;
  vir_bytes ecount;
  int bytes, i;
  u8_t two_bytes[2];
  phys_bytes phys_2bytes;
  int odd_byte;

  ecount = (count + 1) & ~1;
  phys_2bytes = vir2phys(two_bytes);
  odd_byte = 0;

  dp_read_setup(dep, ecount, nic_addr);

  i = 0;
  while (count > 0) {
	if (i >= IOVEC_NR) {
		dp_next_iovec(iovp);
		i = 0;
		continue;
	}
	bytes = iovp->iod_iovec[i].iov_size;
	if (bytes > count) bytes = count;

	phys_user = numap(iovp->iod_proc_nr,
			  iovp->iod_iovec[i].iov_addr, bytes);
	if (!phys_user) panic(UmapErrMsg);
	if (odd_byte) {
		phys_copy(phys_2bytes + 1, phys_user, (phys_bytes) 1);
		count--;
		bytes--;
		phys_user++;
		odd_byte = 0;
		if (!bytes) continue;
	}
	ecount = bytes & ~1;
	if (ecount != 0) {
		phys_insw(dep->de_data_port, phys_user, ecount);
		count -= ecount;
		bytes -= ecount;
		phys_user += ecount;
	}
	if (bytes) {
		*(u16_t *) two_bytes = in_word(dep->de_data_port);
		phys_copy(phys_2bytes, phys_user, (phys_bytes) 1);
		count--;
		bytes--;
		phys_user++;
		odd_byte = 1;
	}
  }
  return;
}
コード例 #2
0
void ide_read_data(int deviceIndex, unsigned char* buffer)
{
	int index = 0;
	unsigned short *b = (unsigned short *)buffer;
	unsigned short d;
	while (index < 256)
	{
		d = in_word(devices[deviceIndex].base + ATA_REG_DATA);
		b[index] = d;
		index++;
	}
} 
コード例 #3
0
ファイル: pci_ia32.c プロジェクト: J-F-Sebastian/DiegOS
void pci_read_config_reg16(bdf_addr_t address,
                           unsigned offset,
                           uint16_t *value)
{
    if (!value) {
        return;
    }

    pci_config_space_set_addr(address, offset);

    *value = in_word(PCI_CONFIG_DATA+(offset & 2));
}
コード例 #4
0
ファイル: vbe.c プロジェクト: MadHacker217/VirtualBox-OSE
static uint16_t mode_info_find_mode(uint16_t mode, Boolean using_lfb)
{
    uint16_t    sig, vmode, attrs;
    uint16_t    cur_info_ofs;   /* Current offset in mode list. */
    
    /* Read and check the VBE Extra Data signature. */
    sig = in_word(VBE_EXTRA_PORT, 0);
    if (sig != VBEHEADER_MAGIC) {
#ifdef DEBUG_VGA
        printf("Signature NOT found! %x\n", sig);
#endif
        return 0;
    }
    
    cur_info_ofs = sizeof(VBEHeader);
    
    vmode = in_word(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, mode)/*&cur_info->mode*/);
    while (vmode != VBE_VESA_MODE_END_OF_LIST)
    {
        attrs = in_word(VBE_EXTRA_PORT, /*&cur_info->info.ModeAttributes*/cur_info_ofs + offsetof(ModeInfoListItem, info.ModeAttributes) );
        
        if (vmode == mode)
        {
            if (!using_lfb)
                return cur_info_ofs;
            else if (attrs & VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE)
                return cur_info_ofs;
            else {
                cur_info_ofs += sizeof(ModeInfoListItem);
                vmode = in_word(VBE_EXTRA_PORT, /*&cur_info->mode*/cur_info_ofs + offsetof(ModeInfoListItem, mode));
            }
        } else {
            cur_info_ofs += sizeof(ModeInfoListItem);
            vmode = in_word(VBE_EXTRA_PORT, /*&cur_info->mode*/cur_info_ofs + offsetof(ModeInfoListItem, mode));
        }
    }
    return 0;
}
コード例 #5
0
ファイル: ne2100.c プロジェクト: yeonsh/Amoeba
/*
 * Stop ethernet board
 */
void
eth_stop()
{
    register long l;

    /* stop chip and disable DMA access */
    out_word(LA_RAP, RDP_CSR0);
    out_word(LA_CSR, CSR_STOP);
    for (l = 0; (in_word(LA_CSR) & CSR_STOP) == 0; l++) {
	if (l >= MAXLOOP) {
	    printf("Lance failed to stop\n");
	    break;
	}
    }
    dma_done(NE_DMACHANNEL);
}
コード例 #6
0
ファイル: vbe.c プロジェクト: MadHacker217/VirtualBox-OSE
/** Function 01h - Return VBE Mode Information
 *
 * Input:
 *              AX      = 4F01h
 *              CX      = Mode Number
 *              ES:DI   = Pointer to buffer in which to place ModeInfoBlock structure
 * Output:
 *              AX      = VBE Return Status
 *
 */
void vbe_biosfn_return_mode_information(uint16_t STACK_BASED *AX, uint16_t CX, uint16_t ES, uint16_t DI)
{
    uint16_t            result = 0x0100;
#ifdef VBE_NEW_DYN_LIST
    uint16_t            cur_info_ofs;
#else
    ModeInfoListItem    *cur_info;
#endif
    Boolean             using_lfb;
    uint8_t             win_attr;

#ifdef VGA_DEBUG
    printf("VBE vbe_biosfn_return_mode_information ES%x DI%x CX%x\n",ES,DI,CX);
#endif

    using_lfb = ((CX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER);
    CX = (CX & 0x1ff);

#ifdef VBE_NEW_DYN_LIST
    cur_info_ofs = mode_info_find_mode(CX, using_lfb);

    if (cur_info_ofs) {
        uint16_t    i;
#else
    cur_info = mode_info_find_mode(CX, using_lfb);

    if (cur_info != 0) {
#endif
#ifdef VGA_DEBUG
        printf("VBE found mode %x\n",CX);
#endif
        memsetb(ES, DI, 0, 256);    // The mode info size is fixed
#ifdef VBE_NEW_DYN_LIST
        for (i = 0; i < sizeof(ModeInfoBlockCompact); i++) {
            uint8_t b;

            b = in_byte(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info) + i/*(char *)(&(cur_info->info)) + i*/);
            write_byte(ES, DI + i, b);
        }
#else
        memcpyb(ES, DI, 0xc000, &(cur_info->info), sizeof(ModeInfoBlockCompact));
#endif
        win_attr = read_byte(ES, DI + offsetof(ModeInfoBlock, WinAAttributes));
        if (win_attr & VBE_WINDOW_ATTRIBUTE_RELOCATABLE) {
            write_word(ES, DI + offsetof(ModeInfoBlock, WinFuncPtr), (uint16_t)(dispi_set_bank_farcall));
            // If BIOS not at 0xC000 -> boom
            write_word(ES, DI + offsetof(ModeInfoBlock, WinFuncPtr) + 2, 0xC000);
        }
        // Update the LFB physical address which may change at runtime
        out_w(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_FB_BASE_HI);
        write_word(ES, DI + offsetof(ModeInfoBlock, PhysBasePtr) + 2, in_w(VBE_DISPI_IOPORT_DATA));

        result = 0x4f;
    } else {
#ifdef VGA_DEBUG
        printf("VBE *NOT* found mode %x\n",CX);
#endif
        result = 0x100;
    }

    *AX = result;
}

/** Function 02h - Set VBE Mode
 *
 * Input:
 *              AX      = 4F02h
 *              BX      = Desired Mode to set
 *              ES:DI   = Pointer to CRTCInfoBlock structure
 * Output:
 *              AX      = VBE Return Status
 *
 */
void vbe_biosfn_set_mode(uint16_t STACK_BASED *AX, uint16_t BX, uint16_t ES, uint16_t DI)
{
    uint16_t            result;
#ifdef VBE_NEW_DYN_LIST
    uint16_t            cur_info_ofs;
#else
    ModeInfoListItem    *cur_info;
#endif
    Boolean             using_lfb;
    uint8_t             no_clear;
    uint8_t             lfb_flag;

    using_lfb = ((BX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER);
    lfb_flag  = using_lfb ? VBE_DISPI_LFB_ENABLED : 0;
    no_clear  = ((BX & VBE_MODE_PRESERVE_DISPLAY_MEMORY) == VBE_MODE_PRESERVE_DISPLAY_MEMORY) ? VBE_DISPI_NOCLEARMEM : 0;

    BX = (BX & 0x1ff);

    // check for non vesa mode
    if (BX < VBE_MODE_VESA_DEFINED)
    {
        uint8_t mode;

        dispi_set_enable(VBE_DISPI_DISABLED);
        // call the vgabios in order to set the video mode
        // this allows for going back to textmode with a VBE call (some applications expect that to work)
        mode = (BX & 0xff);
        biosfn_set_video_mode(mode);
        result = 0x4f;
        goto leave;
    }

#ifdef VBE_NEW_DYN_LIST
    cur_info_ofs = mode_info_find_mode(BX, using_lfb);

    if (cur_info_ofs != 0)
    {
        uint16_t    xres, yres;
        uint8_t     bpp;

        xres = in_word(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info.XResolution) /*&cur_info->info.XResolution*/);
        yres = in_word(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info.YResolution) /*&cur_info->info.YResolution*/);
        bpp  = in_byte(VBE_EXTRA_PORT, cur_info_ofs + offsetof(ModeInfoListItem, info.BitsPerPixel) /*&cur_info->info.BitsPerPixel*/);

#ifdef VGA_DEBUG
        printf("VBE found mode %x, setting:\n", BX);
        printf("\txres%x yres%x bpp%x\n", xres, yres, bpp);
#endif
#else
    cur_info = mode_info_find_mode(BX, using_lfb);

    if (cur_info != 0)
    {
#ifdef VGA_DEBUG
        printf("VBE found mode %x, setting:\n", BX);
        printf("\txres%x yres%x bpp%x\n",
                cur_info->info.XResolution,
                cur_info->info.YResolution,
                cur_info->info.BitsPerPixel);
#endif
#endif // VBE_NEW_DYN_LIST

        // first disable current mode (when switching between vesa modi)
        dispi_set_enable(VBE_DISPI_DISABLED);

#ifdef VBE_NEW_DYN_LIST
        if (bpp == 4)
#else
        if (cur_info->info.BitsPerPixel == 4)
#endif
        {
            biosfn_set_video_mode(0x6a);
        }

#ifdef VBE_NEW_DYN_LIST
        dispi_set_bpp(bpp);
        dispi_set_xres(xres);
        dispi_set_yres(yres);
#else
        dispi_set_bpp(cur_info->info.BitsPerPixel);
        dispi_set_xres(cur_info->info.XResolution);
        dispi_set_yres(cur_info->info.YResolution);
#endif
        dispi_set_bank(0);
        dispi_set_enable(VBE_DISPI_ENABLED | no_clear | lfb_flag);
        vga_compat_setup();

        write_word(BIOSMEM_SEG,BIOSMEM_VBE_MODE,BX);
        write_byte(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL,(0x60 | no_clear));

        result = 0x4f;
    }
    else
    {
#ifdef VGA_DEBUG
        printf("VBE *NOT* found mode %x\n" , BX);
#endif
        result = 0x100;
    }

leave:
    *AX = result;
}

uint16_t vbe_biosfn_read_video_state_size(void)
{
    return 9 * 2;
}

void vbe_biosfn_save_video_state(uint16_t ES, uint16_t BX)
{
    uint16_t    enable, i;

    outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
    enable = inw(VBE_DISPI_IOPORT_DATA);
    write_word(ES, BX, enable);
    BX += 2;
    if (!(enable & VBE_DISPI_ENABLED))
        return;
    for(i = VBE_DISPI_INDEX_XRES; i <= VBE_DISPI_INDEX_Y_OFFSET; i++) {
        if (i != VBE_DISPI_INDEX_ENABLE) {
            outw(VBE_DISPI_IOPORT_INDEX, i);
            write_word(ES, BX, inw(VBE_DISPI_IOPORT_DATA));
            BX += 2;
        }
    }
}
コード例 #7
0
ファイル: tif.cpp プロジェクト: Andrew-cn/FVC
// Load a 256 gray-scale uncompressed TIF image into the global array IMAGE
int Load_gray256tif(BOOL Upright) {
    /* Load a tif imagefile.
       The image is loaded by rows into the global array IMAGE:
       - IMAGE_X and IMAGE_Y are the width and the height of the image respectively.
       - The generic pixel [x,y], where x=0..IMAGE_X-1 and y=0..IMAGE_Y-1,
         can be accessed as IMAGE[y*IMAGE_X+x]
    */
    FILE* fp = imagefile;
    DWORD ifd_offset;
    WORD directory_entry_count;
    WORD offset;
    DWORD strip_offset, data_offset;
    BOOL strip_based = FALSE;
    BYTE* pimage;
    int i;

    if (fread(buffer,8,1,fp)!=1) return 1;
    if (in_word(0)!=0x4949) return 2;
    if (in_word(2)!=0x002a) return 3;
    ifd_offset = in_dword(4);

    if (fseek(fp,ifd_offset,SEEK_SET)) return 1;
    if (fread(buffer,2,1,fp)!=1) return 1;
    directory_entry_count=in_word(0);

    if (fread(buffer,directory_entry_count*12,1,fp)!=1) return 1;

    offset = 0;
    while (directory_entry_count > 0) {
        switch (in_word(offset)) {
        case 0x00fe: if (in_word(offset+8) != 0) return 4; break;
        case 0x0100: IMAGE_X = in_word(offset+8); break;
        case 0x0101: IMAGE_Y = in_word(offset+8); break;
        case 0x0102: if (in_word(offset+8) != 8) return 5; break;
        case 0x0103: if (in_word(offset+8) != 1) return 6; break;
        case 0x0106: if (in_word(offset+8) != 1) return 7; break;
        case 0x0111: strip_offset = in_word(offset+8); break;
        case 0x0115: if (in_word(offset+8) != 1) return 8; break;
        case 0x0116: if (in_word(offset+8) != IMAGE_Y) strip_based=TRUE; break;
        case 0x011c: if (in_word(offset+8) != 1) return 11; break;
        }
        offset += 12;
        -- directory_entry_count;
    }

    if (strip_based) {
        if (fseek(fp, strip_offset, SEEK_SET)) return 1;
        if (fread(buffer, 4, 1, fp) != 1) return 1;
        data_offset = in_dword(0);
    } else data_offset = strip_offset;
    HEAD_SIZE = data_offset;

    if( fseek(fp, 0, SEEK_SET) ) return 1;
    if( fread(FILE_HEAD, HEAD_SIZE, 1, fp) != 1 ) return 1;

    if( fseek(fp, data_offset, SEEK_SET) ) return 1;
    if (Upright) {
        pimage = IMAGE;
        for (i=0; i<IMAGE_Y; ++i) {
            if( fread(pimage, IMAGE_X, 1, fp) != 1 ) return 1;
            pimage += IMAGE_X;
        }
    } else {
        pimage = IMAGE + IMAGE_X*(IMAGE_Y-1);
        for (i=0; i<IMAGE_Y; ++i) {
            if( fread(pimage, IMAGE_X, 1, fp) != 1 ) return 1;
            pimage -= IMAGE_X;
        }
    }

    return 0;
}
コード例 #8
0
ファイル: hangman.c プロジェクト: davidtoulmin/Games
int
main(int argc, char *argv[]){
	int tries=0, length=0, found=0, instances, failures=0, i;
	/*char character;*/
	char word[arbitrary_word_length], blank_word[arbitrary_word_length],
		whole_word[arbitrary_word_length], guess[arbitrary_word_length];
	char c;
	char skip_ch;
	printf("Input a word to play:");
	/*scanf("%s", word);
	while(word[length]!='\0'){
		length++;
	}*/
	while((c=getchar())!='\n'){
		if(!isalpha(c)){
			do{
				skip_ch=fgetc(stdin);
			}while(skip_ch != '\n');
			break;
		}
		word[length]=c;
		blank_word[length]='_';
		whole_word[length]=c;
		length++;
		if(length>=arbitrary_word_length){
			printf("Word is too long, watcha doing making a word over 100 characters long?");
			exit(EXIT_FAILURE);
		}
	}
	if(length<1){
		printf("Input is not a word!");
		exit(EXIT_FAILURE);
	}
	word[length]='\0';
	blank_word[length]='\0';
	whole_word[length]='\0';
	printf("You chose %s, with length %d",word, length);
	/*for(i=0; i<100; i++){
		printf("\n");
	}*/
	printf("\n");
	while(found<length){
		tries++;
		printf("Input a character or whole word guess: ");
		/*if(scanf("%c", &character)!=1){
			printf("Invalid input");
			exit(EXIT_FAILURE);
		}
		do{
			skip_ch=fgetc(stdin);
		}while(skip_ch != '\n');*/
		i=0;
		guess[0]='\0';
		while((c=getchar())!='\n'){
			if(!isalpha(c)){
				do{
					skip_ch=fgetc(stdin);
				}while(skip_ch != '\n');
				break;
			}
			guess[i]=c;
			i++;
		}
		if(guess[0]=='\0') {
			continue;
		}
		guess[i]='\0';
		if(i>1) {
			if(!strcmp(guess, whole_word)) {
				printf("You correctly guessed the word!");
				exit(EXIT_SUCCESS);
			} else {
				failures++;
				printf("'%s' is not the word.\n", guess);
				print_man(failures);
			}
		} else {
			/*if(in_word(blank_word, length, guess[0], &found,blank_word) {
					printf("You've already found that letter");
					continue;
			}*/
			instances=in_word(word, length, guess[0], &found, blank_word);
			if(instances){
				printf("'%c' is in the word: %s\n", guess[0], blank_word);
			} else {
				failures++;
				printf("'%c' is not in the word.\n", guess[0]);
				print_man(failures);
			}
		}
	}
	printf("You got the word!");
	return 0;
}
コード例 #9
0
ファイル: ne2100.c プロジェクト: yeonsh/Amoeba
/*
 * Reset ethernet board (i.e. after a timeout)
 */
void
eth_reset()
{
    register long l;
    uint32 addr;
    int i;

    /* program DMA chip */
    dma_cascade(NE_DMACHANNEL);

    /* stop the chip, and make sure it did */
    out_word(LA_RAP, RDP_CSR0);
    out_word(LA_CSR, CSR_STOP);
    for (l = 0; (in_word(LA_CSR) & CSR_STOP) == 0; l++) {
	if (l >= MAXLOOP) {
	    printf("Lance failed to stop\n");
	    return;
	}
    }

    /* fill lance initialization block */
    bzero(initblock, sizeof(initblock_t));

    /* set my ethernet address */
    initblock->ib_padr[0] = eth_myaddr[0];
    initblock->ib_padr[1] = eth_myaddr[1];
    initblock->ib_padr[2] = eth_myaddr[2];
    initblock->ib_padr[3] = eth_myaddr[3];
    initblock->ib_padr[4] = eth_myaddr[4];
    initblock->ib_padr[5] = eth_myaddr[5];

    /* receive ring pointer */
    addr = (dsseg() << 4) + (uint32)rmd;
    initblock->ib_rdralow = (uint16)addr;
    initblock->ib_rdrahigh = (uint8)(addr >> 16);
    initblock->ib_rlen = LOG2NRCVRING << 5;

    /* transmit ring with one element */
    addr = (dsseg() << 4) + (uint32)tmd;
    initblock->ib_tdralow = (uint16)addr;
    initblock->ib_tdrahigh = (uint8)(addr >> 16);
    initblock->ib_tlen = 0 << 5;

    /* setup the receive ring entries */
    for (next_rmd = 0, i = 0; i < NRCVRING; i++) {
	addr = (dsseg() << 4) + (uint32)&rbuffer[i];
	rmd[i].rmd_ladr = (uint16)addr;
	rmd[i].rmd_hadr = (uint8)(addr >> 16);
	rmd[i].rmd_mcnt = 0;
	rmd[i].rmd_bcnt = -LANCEBUFSIZE;
	rmd[i].rmd_flags = RMD_OWN;
    }

    /* zero transmit ring */
    bzero(tmd, sizeof(tmde_t));

    /* give lance the init block */
    addr = (dsseg() << 4) + (uint32)initblock;
    out_word(LA_RAP, RDP_CSR1);
    out_word(LA_CSR1, (uint16)addr);
    out_word(LA_RAP, RDP_CSR2);
    out_word(LA_CSR2, (int8)(addr >> 16));
    out_word(LA_RAP, RDP_CSR3);
    out_word(LA_CSR3, 0);

    /* and initialize it */
    out_word(LA_RAP, RDP_CSR0);
    out_word(LA_CSR, CSR_INIT|CSR_STRT);

    /* wait for the lance to complete initialization and fire it up */
    for (l = 0; (in_word(LA_CSR) & CSR_IDON) == 0; l++) {
	if (l >= MAXLOOP) {
	    printf("Lance failed to initialize\n");
	    break;
	}
    }
    for (l=0; (in_word(LA_CSR)&(CSR_TXON|CSR_RXON))!=(CSR_TXON|CSR_RXON); l++) {
	if (l >= MAXLOOP) {
	    printf("Lance not started\n");
	    break;
	}
    }
}