Ejemplo n.º 1
0
int main(int argc, char **argv) {

	int i;

	for(i=0;i<100;i++) {
		printf("%d/10=%d\n",
			i,div32(i,10));
	}
	printf("88 %d\n",div32(16*1024,88*1000/64));
	printf("33 %d\n",div32(16*1024,33*1000/64));
	printf("1 %d\n",div32(16*1024,1*1000/64));

	return 0;

}
Ejemplo n.º 2
0
void print_long32 (struct long32 *input) {
   byte i;
   struct long32 divisor, digit, temp, value;

   divisor.hi = 0x3B9A;
   divisor.lo = 0xCA00;
   value.hi = input->hi;
   value.lo = input->lo;
   for(i=0;i<10;++i) {
      digit = value;
      div32 (&digit,&divisor);
      temp = digit;
      mul32 (&temp,&divisor);
      sub32 (&value, &temp);
      putc(digit.lo+'0');
      temp.hi = 0;
      temp.lo = 0x000A;
      div32 (&divisor, &temp);
   }
}
Ejemplo n.º 3
0
void main() {
   struct long32  first, second, working;
   char s[20];

   while (TRUE) {
      printf ("\r\n\r\nEnter the first number: ");
      get_string (s,20);
      atol32 (s,&first);

      printf ("\r\nEnter the second number: ");
      get_string (s,20);
      atol32 (s,&second);

      printf ("\r\n\r\nA: ");
      print_long32 (&first);

      printf ("\r\nB: ");
      print_long32 (&second);

      working.hi = first.hi;
      working.lo = first.lo;
      add32 (&working, &second);
      printf ("\r\na +  b = ");
      print_long32 (&working);

      working.hi = first.hi;
      working.lo = first.lo;
      sub32 (&working, &second);
      printf ("\r\na -  b = ");
      print_long32 (&working);

      working.hi = first.hi;
      working.lo = first.lo;
      mul32 (&working, &second);
      printf ("\r\na *  b = ");
      print_long32 (&working);

      working.hi = first.hi;
      working.lo = first.lo;
      div32 (&working, &second);
      printf ("\r\na /  b = ");
      print_long32 (&working);

      rem32 (&first, &second, &working);
      printf ("\r\na modulus  b = ");
      print_long32 (&working);

   }
}
Ejemplo n.º 4
0
void GLFont::PrintSineVertical(int x, int y, const char *text, int height_offset, int _width, int cycles, s32 start_angle)
{

	unsigned char font_char;
	unsigned int length = strlen(text);
	s32 angle_inc = div32(32768/2, length-1)*cycles;
	
	s32 _x;
	
	while(*text)
	{
		font_char = (*(unsigned char*)text++) - 32;
		
		_x = sinLerp(start_angle) * _width; 
		
		glSprite( x + (_x >> 12), y, GL_FLIP_NONE, &font_sprite[font_char] );

		
		y += font_sprite[font_char].height + height_offset; 
		start_angle += angle_inc;
	}


}
Ejemplo n.º 5
0
void GLFont::PrintSine(int x, int y, const char *text, int width_offset, int _height, int cycles, s32 start_angle)
{

	unsigned char font_char;
	unsigned int length = strlen(text);
	s32 angle_inc = div32(32768/2, length-1)*cycles;
	
	s32 _y;
	
	while(*text)
	{
		font_char = (*(unsigned char*)text++) - 32;
		
		_y = sinLerp(start_angle) * _height; 
		
		glSprite( x,y + (_y >> 12), GL_FLIP_NONE, &font_sprite[font_char] );

		
		x += font_sprite[font_char].width + width_offset; 
		start_angle += angle_inc;
	}


}
Ejemplo n.º 6
0
void audiocheck(void)
{
    char s[80];
    struct char_row r = { .s = s };
    static const uint8_t sine[] = { 0,19,39,57,74,89,102,113,120,125,127 };
    const unsigned int nr_500hz_samples = 40;
    const unsigned int nr_10khz_samples = 2;
    int8_t *aud_500hz = allocmem(nr_500hz_samples);
    int8_t *aud_10khz = allocmem(nr_10khz_samples);
    uint8_t key, channels = 0, lowfreq = 1;
    uint32_t period;
    unsigned int i;

    /* Low-pass filter activated by default. */
    ciaa->pra &= ~CIAAPRA_LED;

    /* Generate the 500Hz waveform. */
    for (i = 0; i < 10; i++) {
        aud_500hz[i] = sine[i];
        aud_500hz[10+i] = sine[10-i];
        aud_500hz[20+i] = -sine[i];
        aud_500hz[30+i] = -sine[10-i];
    }

    /* Generate the 10kHz waveform. */
    aud_10khz[0] = 127;
    aud_10khz[1] = -127;

    print_menu_nav_line();

    r.x = 12;
    sprintf(s, "-- Audio Test --");
    print_line(&r);
    r.y += 2;
    r.x = 8;

    sprintf(s, "$1 Channel 0/L$  -  OFF");
    print_line(&r);
    r.y++;
    sprintf(s, "$2 Channel 1/R$  -  OFF");
    print_line(&r);
    r.y++;
    sprintf(s, "$3 Channel 2/R$  -  OFF");
    print_line(&r);
    r.y++;
    sprintf(s, "$4 Channel 3/L$  -  OFF");
    print_line(&r);
    r.y++;
    sprintf(s, "$5 Frequency  $  -  500Hz Sine");
    print_line(&r);
    r.y++;
    sprintf(s, "$6 L.P. Filter$  -  ON");
    print_line(&r);
    r.y += 2;

    /* period = cpu_hz / (2 * nr_samples * frequency) */
    period = div32(div32(div32(cpu_hz, 2), nr_500hz_samples), 500/*Hz*/);

    for (i = 0; i < 4; i++) {
        cust->aud[i].lc.p = aud_500hz;
        cust->aud[i].len = nr_500hz_samples / 2;
        cust->aud[i].per = (uint16_t)period;
        cust->aud[i].vol = 0;
    }
    cust->dmacon = DMA_SETCLR | DMA_AUDxEN; /* dma on */

    for (;;) {
        while (!(key = keycode_buffer) && !do_exit)
            continue;
        keycode_buffer = 0;

        /* ESC also means exit */
        if (do_exit || (key == K_ESC))
            break;

        key -= K_F1;
        if (key < 4) {
            /* F1-F4: Switch channel 0-3 */
            channels ^= 1u << key;
            cust->aud[key].vol = (channels & (1u << key)) ? 64 : 0;
            print_text_box(29, 2+key, channels & (1u<<key) ? "N " : "FF");
        } else if (key == 4) {
            /* F5: Frequency */
            lowfreq ^= 1;
            cust->dmacon = DMA_AUDxEN; /* dma off */
            for (i = 0; i < 4; i++) {
                /* NB. programmed period does not change: sample lengths 
                 * determine the frequency. */
                if (lowfreq) {
                    cust->aud[i].lc.p = aud_500hz;
                    cust->aud[i].len = nr_500hz_samples / 2;
                } else {
                    cust->aud[i].lc.p = aud_10khz;
                    cust->aud[i].len = nr_10khz_samples / 2;
                }
            }
            cust->dmacon = DMA_SETCLR | DMA_AUDxEN; /* dma on */
            print_text_box(28, 6, lowfreq ? "500Hz Sine  " : "10kHz Square");
        } else if (key == 5) {
            /* F6: Low Pass Filter */
            ciaa->pra ^= CIAAPRA_LED;
            print_text_box(29, 7, (ciaa->pra & CIAAPRA_LED) ? "FF" : "N ");
        }
    }

    /* Clean up. */
    for (i = 0; i < 4; i++)
        cust->aud[i].vol = 0;
    cust->dmacon = DMA_AUDxEN; /* dma off */
    ciaa->pra &= ~CIAAPRA_LED;
}
Ejemplo n.º 7
0
void kernel_main(uint32_t r0, uint32_t r1, uint32_t *atags,
		uint32_t memory_kernel) {

	unsigned int memory_total;
	int init_process,idle_process;
	struct atag_info_t atag_info;
	uint32_t framebuffer_width=800,framebuffer_height=600;

	(void) r0;	/* Ignore boot method */

	/* Initialize Software Structures */
	processes_init();

	/* Detect Hardware */
	atags_detect(atags,&atag_info);
	hardware_type=atag_info.hardware_type;

	/* Initialize Hardware */

	/* Serial console is most important so do that first */
	uart_init();

	/* Enable Interrupts */
	enable_interrupts();

	/************************/
	/* Boot message!	*/
	/************************/

	printk("\r\nBooting VMWos...\r\n");

	/**************************/
	/* Device Drivers	  */
	/**************************/

	/* Set up ACT LED */
	led_init();

	/* Set up timer */
	timer_init();

	/* Set up keyboard */
	ps2_keyboard_init();

	/* Enable the Framebuffer */
	if (atag_info.framebuffer_x!=0) {
		framebuffer_width=atag_info.framebuffer_x;
	}
	if (atag_info.framebuffer_y!=0) {
		framebuffer_height=atag_info.framebuffer_y;
	}

	framebuffer_init(framebuffer_width,framebuffer_height,24);
	framebuffer_console_init();

	/* Delay to allow time for serial port to settle */
	/* So we can actually see the output on the terminal */
	delay(0x3f0000);

	printk("\r\nWaiting for serial port to be ready (press any key)\r\n");
	uart_getc();

	uart_enable_interrupts();


	/* Clear screen */
	printk("\n\r\033[2J\n\r\n\r");

	/* Print boot message */
	printk("\033[0;41m   \033[42m \033[44m   \033[42m \033[44m   \033[0m VMW OS\r\n");
	printk(" \033[0;41m \033[42m   \033[44m \033[42m   \033[44m \033[0m  Version 0.%d\r\n\r\n",VERSION);

	/* Print hardware version */
	printk("Hardware version: %x ",r1);
	if (r1==0xc42) printk("(Raspberry Pi)");
	else printk("(Unknown Hardware)");
	printk("\r\n");

	printk("Detected Model ");
	switch(hardware_type) {
		case RPI_MODEL_A:	printk("A"); break;
		case RPI_MODEL_APLUS:	printk("A+"); break;
		case RPI_MODEL_B:	printk("B"); break;
		case RPI_MODEL_BPLUS:	printk("B+"); break;
		case RPI_MODEL_B2:	printk("B2"); break;
		case RPI_COMPUTE_NODE:	printk("Compute Node"); break;
		default:		printk("Unknown %x",hardware_type); break;
	}
	printk("\r\n");

	/* Print ATAGS */
	atags_dump(atags);

	printk("\r\n");

	/* Get amount of RAM from ATAGs */
	memory_total=atag_info.ramsize;

	/* Init memory subsystem */
	memory_init(memory_total,memory_kernel);

	/* Init the MMU */
	printk("Initializing MMU and caches\r\n");
	//enable_mmu(0, memory_total);
	//l1_data_cache_clear();
	//l1_data_cache_enable();
	l1_instruction_cache_enable();




	/* Memory Benchmark */
#if 1
	{
		int i;
		uint32_t before,after;

		before=ticks_since_boot();

		for(i=0;i<16;i++) {
			memset(benchmark,0,BENCH_SIZE);
		}
		after=ticks_since_boot();

		printk("MEMSPEED: %d MB took %d ticks %dkB/s\r\n",
			16, (after-before),
			div32(16*1024,(((after-before)*1000)/64)));
	}
#endif

	/* Load the idle thread */
	idle_process=load_process("idle",PROCESS_FROM_RAM,
				(char *)&idle_task,8,4096);

	init_process=load_process("shell",PROCESS_FROM_DISK,
				NULL,0,8192);

	load_process("printa",PROCESS_FROM_DISK,
				NULL,0,8192);

	load_process("printb",PROCESS_FROM_DISK,
				NULL,0,8192);


	/* Enter our "init" process*/
	printk("\r\nEntering userspace by starting process %d!\r\n",
		init_process);

	process[idle_process].ready=1;
	process[init_process].ready=1;

	userspace_started=1;

	/* run init and restore stack as we won't return */
	run_process(init_process,0x8000);

	/* we should never get here */

	while(1) {

		/* Loop Forever */
		/* Should probably execute a wfi instruction */
	}

}
Ejemplo n.º 8
0
// ------------------------------------------------------------------------
IMPLEMENTATION[ia32 || amd64 || ux]:

#include "config.h"
#include "div32.h"
#include "kernel_console.h"
#include "paging.h"
#include "jdb_screen.h"

PUBLIC static
void
Jdb::write_tsc_s(String_buffer *buf, Signed64 tsc, bool sign)
{
  Unsigned64 uns = Cpu::boot_cpu()->tsc_to_ns(tsc < 0 ? -tsc : tsc);
  Unsigned32 ums = div32(uns, 1000000);

  if (tsc < 0)
    uns = -uns;

  if (ums >= 3600000000U)
    {
      buf->printf(">999 h ");
      return;
    }

  if (sign)
    buf->printf("%c", (tsc < 0) ? '-' : (tsc == 0) ? ' ' : '+');

  if (ums >= 60000000)
    {
      // 1:00...999:00 h
      Mword _h  = ums / 3600000;
      Mword _m  = (ums - 3600000 * _h) / 60000;
      buf->printf("%3lu:%02lu     h ", _h, _m);
      return;
    }

  if (ums >= 1000000)
    {
      // 1:00...999:00 min
      Mword _m  = ums / 60000;
      Mword _s  = (ums - 60000 * _m) / 1000;
      buf->printf("%3lu:%02lu    min", _m, _s);
      return;
    }

  if (ums >= 1000)
    {
      // 1.000000...999.000000 s
      Mword _s  = ums / 1000;
      Mword _us = div32(uns, 1000) - 1000000 * _s;
      buf->printf("%3lu.%06lu s ", _s, _us);
      return;
    }

  if (uns == 0)
    {
      buf->printf("  0          ");
      return;
    }

  // 1.000000...999.000000 ms
  Mword _ms = ums;
  Mword _ns = ((Mword)uns - 1000000 * _ms);
  buf->printf("%3lu.%06lu ms", _ms, _ns);
}
Ejemplo n.º 9
0
void SampleDisplay::draw(void)
{
	if(!isExposed())
		return;

	//
	// Border and background
	//
	//drawFullBox(0, 0, width, height, theme->col_dark_bg);
	u32 colcol = theme->col_dark_bg | theme->col_dark_bg << 16;
	for(int j=y;j<y+height;++j) dmaFillWordsDamnFast(colcol, *vram+256*j+x, width*2);

	if(active==false) {
		drawBorder();
	} else {
		drawBorder(RGB15(31,0,0)|BIT(15));
	}

	// Now comes sample-dependant stuff, so return if we have no sample
	if((smp==0)||(smp->getNSamples()==0)) return;

	//
	// Selection
	//
	s32 selleft = sampleToPixel(MIN(selstart, selend));
	s32 selwidth = sampleToPixel(MAX(selstart, selend)) - selleft;
	bool dontdraw = false;

	if( (selleft >= 0) && (selleft < width-2) && (selleft + selwidth > width - 2) ) {
		selwidth = (width-2) - selleft;
	} else if( (selleft < 0) && (selleft + selwidth > 0) && (selleft + selwidth < width-2) ) {
		selwidth += selleft;
		selleft = 0;
	} else if( (selleft < 0) && (selleft + selwidth > width-2) ) {
		selwidth = width-2;
		selleft = 0;
	} else if( (selleft + selwidth < 0) || (selleft > width-2) ) {
		dontdraw = true;
	}

	if(selection_exists && !dontdraw) {
		drawFullBox(selleft+1, 1, selwidth, DRAW_HEIGHT+1, RGB15(31,31,0)|BIT(15));
	}

	//
	// Scrollbar
	//

	// Right Button
	if(pen_on_scroll_right) {
		drawGradient(theme->col_dark_ctrl, theme->col_light_ctrl, width-9, height-SCROLLBAR_WIDTH+1, 8, 8);
	} else {
		drawGradient(theme->col_light_ctrl, theme->col_dark_ctrl, width-9, height-SCROLLBAR_WIDTH+1, 8, 8);
	}

	// This draws the right-arrow
	s8 j, p;
	for(j=0;j<3;j++) {
		for(p=-j;p<=j;++p) {
			*(*vram+SCREEN_WIDTH*(y+height-SCROLLBAR_WIDTH+4+p)+x+width-j-3) = RGB15(0,0,0) | BIT(15);
		}
	}

	drawBox(width-SCROLLBAR_WIDTH, height-SCROLLBUTTON_HEIGHT, 9, 9);

	// Left Button
	if(pen_on_scroll_left) {
		drawGradient(theme->col_dark_ctrl, theme->col_light_ctrl, 1, height-9, 8, 8);
	} else {
		drawGradient(theme->col_light_ctrl, theme->col_dark_ctrl, 1, height-9, 8, 8);
	}

	// This draws the down-arrow
	for(j=2;j>=0;j--) {
		for(p=-j;p<=j;++p) {
			*(*vram+SCREEN_WIDTH*(y+height-SCROLLBAR_WIDTH+4+p)+x+j+3) = theme->col_icon;
		}
	}

	drawBox(0, height-9, 9, 9);


	drawBox(0, height-SCROLLBAR_WIDTH, width, SCROLLBAR_WIDTH);

	// Clear Scrollbar
	drawGradient(theme->col_medium_bg, theme->col_light_bg, SCROLLBUTTON_HEIGHT, height-SCROLLBAR_WIDTH+1, width-2*SCROLLBUTTON_HEIGHT, SCROLLBAR_WIDTH-2);

	// The scroll thingy
	if(pen_on_scrollthingy) {
		drawFullBox(SCROLLBUTTON_HEIGHT+scrollthingypos, height-SCROLLBAR_WIDTH+1, scrollthingywidth-2, SCROLLBAR_WIDTH-2, theme->col_light_ctrl);
	} else {
		drawFullBox(SCROLLBUTTON_HEIGHT+scrollthingypos, height-SCROLLBAR_WIDTH+1, scrollthingywidth-2, SCROLLBAR_WIDTH-2, theme->col_dark_ctrl);
	}

	drawBox(SCROLLBUTTON_HEIGHT-1+scrollthingypos, height-SCROLLBAR_WIDTH, scrollthingywidth, SCROLLBAR_WIDTH);

	//
	// Sample
	//

	u16 colortable[DRAW_HEIGHT+2];
	for(u8 i=0; i<DRAW_HEIGHT+2; ++i)
		colortable[i] = interpolateColor(theme->col_light_ctrl, theme->col_dark_ctrl, i);

	// TODO; Eliminate floats here!!

	/*
	float step = (float)(smp->getNSamples() >> zoom_level) / (float)(width-2);
	float pos = 0.0f;

	u32 renderwindow = (u32)MAX(1, MIN(100, ceil(step)));
	*/

#define _fix(x) ((x)<<12)

	int step = divf32(_fix(smp->getNSamples() >> zoom_level), _fix(width-2));
	int pos = 0;

	int ceil_step = step;
	if (ceil_step & 0xFFF)
	{
		ceil_step &= ~0xFFF;
		ceil_step ++;
	}

	u32 renderwindow = MAX(1, MIN(100, ceil_step>>12));

	u16 middle = (DRAW_HEIGHT+2)/2;//-1;

	s32 lastmax=0, lastmin=0;
	if(smp->is16bit() == true) {

		s16 *data;
		s16 *base = (s16*)smp->getData() + pixelToSample(0);

		for(u32 i=1; i<u32(width-1); ++i)
		{
			data = &(base[pos>>12]);

			s32 maxsmp = -32767, minsmp = 32767;

			for(u32 j=0;j<renderwindow;++j) {
				if(*data > maxsmp) maxsmp = *data;
				if(*data < minsmp) minsmp = *data;
				data++;
			}

			s32 maxy = div32((DRAW_HEIGHT+2) * maxsmp, 2 * 32767);
			s32 miny = div32((DRAW_HEIGHT+2) * minsmp, 2 * 32767);

			if(i>1) {
				if(lastmin > maxy) maxy = lastmin;
				if(lastmax < miny) miny = lastmax;
			}

			for(s16 j=miny; j<=maxy; ++j) (*vram)[SCREEN_WIDTH*(y+middle-j)+x+i] = colortable[middle-j];

			lastmax = maxy;
			lastmin = miny;

			*(*vram+SCREEN_WIDTH*(y+middle)+x+i) = colortable[middle];

			pos += step;
		}

	} else {