Esempio n. 1
0
int main(void) {
    int key;
    adc_setup();
    draw_text();
    char temp[5];
    while (1) {
        for (i = 0; i < 4; i++) {
            if (adc_isdone(adcchannels[i]) == 1)
                adc_sample(adcchannels[i], 128);
            tsample = adc_getsample(adcchannels[i]);
            if (! tsample == 0) {
                sprintf(temp, "%d", adcchannels[i]);
                term_puts(1, i + 4, temp);
                sprintf(temp, "%d", adcsmoothing[i]);
                term_puts(5, i + 4, temp);
                sprintf(temp, "%d", tsample);
                term_puts(11, i + 4, temp);
            }
        }
        key = term_getchar(NOWAIT);
        if (key != -1) {
            if (handle_kbd((int)key))
                break;
        }
    }
    term_clrscr();
    term_moveto(1, 1);
    return 0;
}
Esempio n. 2
0
void init_ata()
{
	// First, check for a floating bus (no drives attached)
	uint8_t pri_status = inb(PRIMARY_BASE   + COM_STAT);
	uint8_t sec_status = inb(SECONDARY_BASE + COM_STAT);
	bool    primary_floating   = false;
	bool    secondary_floating = false;
	if (pri_status == 0xFF)
		primary_floating = true;
	if (sec_status == 0xFF)
		secondary_floating = true;

	// Both buses are floating
	if (primary_floating && secondary_floating) {
		term_puts("No drives attached! What's going on?");
		return;
	}

	// Non-0xFF values are not definitive; we need to do some more checks
	check_drive(PRIMARY_BASE,   SEL_MASTER);
	check_drive(PRIMARY_BASE,   SEL_SLAVE);
	check_drive(SECONDARY_BASE, SEL_MASTER);
	check_drive(SECONDARY_BASE, SEL_SLAVE);

	if (sel_base_port == 0) // We didn't find a (PATA) drive
		term_puts("No drives attached! What's going on?");
	else {
		term_printf("Found a drive!\nSelected drive is the %s on the %s bus\n",
				sel_master_or_slave == SEL_MASTER ? "master"  : "slave",
				sel_base_port == PRIMARY_BASE     ? "primary" : "secondary");
		term_printf("Max LBA value is %d\n", max_sector);
	}
}
Esempio n. 3
0
void ext2_init_fs()
{
	load_superblock();
	load_bgdt();

	// Read the root inode, just for fun
	Ext2_inode root_inode;
	read_inode(&root_inode, ROOT_INODE);
	term_printf(" / creation time = %d\n",   root_inode.creation_time);
	term_printf(" / uid           = %d\n",   root_inode.uid);
	term_printf(" / type & perms  = 0x%X\n", root_inode.type_and_permissions);
	term_printf(" / size          = %d\n",   root_inode.size);

	// Enumerate the files in it
	term_puts(" / files:");

	Ext2_file file;
	ext2_open_inode(ROOT_INODE, &file);
	Ext2_dirent dirent;

	while (ext2_next_dirent(&file, &dirent)) {
		term_printf("  inode %d, name `%s'\n", dirent.inode_num, dirent.name);
	}

	kfree(file.buf);

	// Look for a file
	term_putsn(" looking for file `/bar/baz/quux'...");
	uint32_t inode = ext2_look_up_path("/bar/baz/quux");
	if (inode == 0)
		term_puts(" not found");
	else
		term_printf(" found: inode = %d\n", inode);
}
Esempio n. 4
0
void readline_print_status()
{
	char str_prompt[STR_SIZE];

#if 0
	term_puts("myshell");
	term_putc(get_prompt());
	term_putc(' ');
#endif

	sprintf(str_prompt, "%s@%s:%s%c ", get_username(), get_nodename(), get_current_short_dir(), get_prompt());
	term_puts(str_prompt);
}
Esempio n. 5
0
int main_srt()
{
	struct terminal t[1];
	t->w = 80;
	t->h = 25;
	t->kerning = 0;
	t->spacing = 0;
	t->font[0] = reformat_font(*xfont_10x20, UNPACKED);
	fprintf(stderr, "NUMBER_OF_GLYPHS = %d\n", t->font->number_of_glyphs);
	t->letters    = calloc(t->w * t->h, sizeof*t->letters);
	t->attributes = calloc(t->w * t->h, sizeof*t->attributes);
	t->cursorx = t->cursory = 0;
	int w = (t->w + t->kerning) * t->font->width;
	int h = (t->h + t->spacing) * t->font->height;

	term_puts(t, "abc");

	struct FTR f = ftr_new_window(w, h);
	f.userdata = t;
	f.changed = 1;

	ftr_set_handler(&f, "expose", term_exposer);
	ftr_set_handler(&f, "key", term_key_handler);
	return ftr_loop_run(&f);
}
Esempio n. 6
0
static void term_key_handler(struct FTR *f, int k, int m, int x, int y)
{
	fprintf(stderr, "TERM_KEY_HANDLER  %d '%c' (%d) at %d %d\n",
			k, isalpha(k)?k:' ', m, x, y);
	if  (k == '\033')
		ftr_notify_the_desire_to_stop_this_loop(f, 1);

	if (k >= 0x2000) {
		fprintf(stderr, "WARNING: rejected key %d\n", k);
		return;
	}

	// 1. prepare a buffer representing this key
	char buf[0x10] = {0};

	// TODO: build a table of keys and strings (about 2000 entries)
	char *tk = global_table_of_keycodes_to_consolecodes[k];
	if (k < 0x2000 && tk && tk[0] == 0x1b)
		strcpy(buf, tk);

	if (isprint(k) || k==' ' || k=='\n')
	{
		if (m & FTR_MASK_SHIFT && isalpha(k))
			k = toupper(k);
		buf[0] = k;
	}


	// 2. dump this buffer into the state machine
	struct terminal *t = f->userdata;
	term_puts(t, buf);

	f->changed = 1;
}
Esempio n. 7
0
// ----------------------------------------------------------------------------
void term_put_int(const int num)
{
	char buffer[8 * sizeof (int) + 1];
	
	itoa(num,buffer,10);
	
	term_puts(buffer);
}
Esempio n. 8
0
File: isr.c Progetto: ItsHertz/gamma
void isr_handler(struct registers_t regs) // high-level handler for interrupts
{
  if(handlers[regs.interrupt_number]==0)
    { 
#ifndef NDEBUG
      term_puts("received unhandled interrupt\n");
      term_puts("interrupt number in decimal: ");
      term_putn_dec(regs.interrupt_number);
      term_puts("\n");
#endif
      if(panic_on_unhandled==true)
	panic("unhandled interrupt");
    }
  else
    {
      handlers[regs.interrupt_number](regs);
    }
}
Esempio n. 9
0
int printf(const char* fmt, ...)
{
  va_list va;
  va_start(va, fmt);
  for(unsigned int i=0;fmt[i];++i)
    {
      char c=fmt[i];
      if(c=='%')
	{
	  ++i; // skip the % sign
	  switch(fmt[i])
	    {
	    case 'd': // signed integer
	    case 'i':
	      term_putn_dec(va_arg(va, int));
	      break;
	    case 'u':
	      term_putn_udec(va_arg(va, uint32_t));
	      break;
	    case 's': // string
	      term_puts(va_arg(va, const char*));
	      break;
	    case 'c':
	      term_putchar(va_arg(va, int));
	      break;
	    case 'X':
	      term_putn_hex_ucase(va_arg(va, uint32_t));
	      break;
	    case 'x':
	      term_putn_hex_lcase(va_arg(va, uint32_t));
	      break;
	    case 'p': // pointer
	      term_puts("0x");
	      term_putn_hex_ucase(va_arg(va, uint32_t));
	      break;
	    case '%':
	      term_putchar('%');
	      break;
	    }
	}
      else
	term_putchar(c);
    }
  va_end(va);
  return 0;
}
Esempio n. 10
0
int main()
{
	struct terminal t[1];
	t->w = 80;
	t->h = 25;
	t->kerning = 0;
	t->spacing = 0;
	t->font[0] = reformat_font(*xfont9x15, UNPACKED);
	t->letters = malloc(sizeof(int) * t->w * t->h);
	t->attributes = malloc(sizeof(int) * t->w * t->h);
	t->cursorx = t->cursory = 0;
	int w = (t->w + t->kerning) * t->font->width;
	int h = (t->h + t->spacing) * t->font->height;

	term_puts(t, "");

	struct FTR f = ftr_new_window(w, h);
	f.userdata = t;
	f.changed = 1;

	ftr_set_handler(&f, "expose", term_exposer);
	ftr_set_handler(&f, "key", term_key_handler);
	return ftr_loop_run(&f);
}
Esempio n. 11
0
void cpu_state_dump(struct cpu_state * cpu) 
{
	char buf[32];
	uint8_t * p;
	int i;
	term_puts("eax=0x");	itoa(buf, cpu->eax, 16, 8);	term_puts(buf);
	term_puts("  ebx=0x");	itoa(buf, cpu->ebx, 16, 8);	term_puts(buf);
	term_puts("  ecx=0x");	itoa(buf, cpu->ecx, 16, 8);	term_puts(buf);
	term_puts("  edx=0x");	itoa(buf, cpu->edx, 16, 8);	term_puts(buf);

	term_puts("\nesi=0x");	itoa(buf, cpu->esi, 16, 8);	term_puts(buf);
	term_puts("  edi=0x");	itoa(buf, cpu->edi, 16, 8);	term_puts(buf);

	term_puts("\nesp=0x");	itoa(buf, cpu->esp, 16, 8);	term_puts(buf);
	term_puts("  ebp=0x");	itoa(buf, cpu->ebp, 16, 8);	term_puts(buf);
	term_puts("  eip=0x");	itoa(buf, cpu->eip, 16, 8);	term_puts(buf);

	term_puts("\neflags=0x");	itoa(buf, cpu->eflags, 16, 8);	term_puts(buf);
	term_puts("  cs=0x");	itoa(buf, cpu->cs, 16, 4);	term_puts(buf);
	term_puts("  ss=0x");	itoa(buf, cpu->ss, 16, 4);	term_puts(buf);
	
	term_puts("\n\ncode @ eip: ");
	p = (uint8_t *)cpu->eip;

	for (i=0; i<32; i++) {
		itoa(buf, *p++, 16, 2);
		term_puts(buf);
		term_putc(' ');
	}
	
}
Esempio n. 12
0
/* draw static text on terminal */
void draw_text(void) {
    term_clrscr();
    term_puts(1, 1, "ADC Status:");
    term_puts(1, 3, "CH  SLEN  RES");
    term_puts(1, 9, "Press ESC to exit.");
}
Esempio n. 13
0
void test(char *test_name, int (*f)(void)) {
    term_puts(test_name);
    term_puts(": ");
    term_puts((*f)() ? "OK\n" : "FAIL\n");
}