Beispiel #1
0
static void
render_cooling_texture (void)
{
#define NOISEFN(X,Y) perlin_noise_2D ((float) (X) / 5, (float) (Y) / 5, 2)
  int x, y;
  float min_intens = 0.0, max_intens = 0.0;
  
  dbgio_printf ("Making cooling texture... ");
  
  cooltmp = malloc (COOL_X * COOL_Y * 2);
  
  for (y = 0; y < 256; y++)
    for (x = 0; x < 512; x++)
      {
        float intensity = NOISEFN (x, y);
	
	if (intensity < min_intens)
	  min_intens = intensity;
	
	if (intensity > max_intens)
	  max_intens = intensity;
      }
  
  for (y = 0; y < COOL_Y; y++)
    for (x = 0; x < COOL_X; x++)
      {
        float intensity = NOISEFN (x, y);
	int alpha;
	
	/* Re-scale to 0...1.  */
	intensity = (intensity - min_intens) / (max_intens - min_intens);
	
	alpha = (int) (intensity * 15 + drand48 ()) - 8;

	if (alpha < 0)
	  alpha = 0;
	if (alpha > 15)
	  alpha = 15;
	
	cooltmp[y * 512 + x] = alpha << 12;
      }

  
  dbgio_printf ("done.\n");
#undef NOISEFN
}
Beispiel #2
0
// Do a little debug dump of the current task.
void irq_dump_regs(int code, uint32 errcode) {
	irq_context_t * t = irq_srt_addr;

	dbgio_printf("Unhandled exception: EIP %08lx, code %d error %08lx\n", t->eip, code, errcode);
	if (code >= 0 && code <= 16) {
		dbgio_printf("%s\n", faultnames[code]);
	}
	dbgio_printf(" EAX %08lx  EBX %08lx  ECX %08lx  EDX %08lx\n", t->eax, t->ebx, t->ecx, t->edx);
	dbgio_printf(" ESI %08lx  EDI %08lx  EBP %08lx  ESP %08lx\n", t->esi, t->edi, t->ebp, t->esp);
	dbgio_printf(" EFLAGS %08lx\n", t->eflags);
	if (thd_current) {
		dbgio_printf("Died in thread %d\n", thd_current->tid);
		if (thd_current->pshell) {
			dbgio_printf("Which is in process %d (base %p)\n", thd_current->pshell->pid,
				thd_current->pshell->image.data);
		}
	}
	// arch_stk_trace_at(t->ebp, 0);
}
Beispiel #3
0
static void
parabolic_texcoords (float *texc, float vertex[3], float normal[3], int front)
{
  //float light[3] = { 0.2357, 0.2357, 0.9428 };
  float vertex4[4], x_vertex[4], x_normal[4];
  float eye_to_vertex[3], reflection[4], tmp[3];
  float temp[4], along;
  float eye_norm_dot;
  float incidence, normalized_normal[4];
  int r, g, b;
  GLfloat unrot[4], x, y, z;
  float x_f, y_f, z_f;
  float x_b, y_b, z_b;
  float c_eyepos[4];

  vec_normalize (normalized_normal, normal);

  /* Find the normal in eye space.  */
  normalized_normal[3] = 1.0;
  vec_transform_fipr (x_normal, (float *) &rotate[0][0], normalized_normal);

 /* incidence = vec_dot (&light[0], &x_normal[0]);
  
  if (incidence < 0)
    incidence = 0;*/
  
  /*r = 64 + 191 * incidence;
  g = 64 + 191 * incidence;
  b = 64 + 191 * incidence;
  
  glColor4ub (r, g, b, 0);
  glColor4ub (255, 255, 255, 0);*/
  
  /* We need the vertex in eye space.  This duplicates work!  */
  memcpy (vertex4, vertex, sizeof (float) * 3);
  vertex4[3] = 1.0;
  vec_transform_fipr (x_vertex, (float *) &transform[0][0], vertex4);

  vec_transform_fipr (&c_eyepos[0], &camera[0][0], &eye_pos[0]);
  vec_sub (eye_to_vertex, &c_eyepos[0], &x_vertex[0]);
  vec_normalize (eye_to_vertex, eye_to_vertex);
  
  eye_norm_dot = vec_dot (eye_to_vertex, &x_normal[0]);
  vec_scale (tmp, x_normal, 2.0 * eye_norm_dot);

  vec_sub (reflection, tmp, eye_to_vertex);
  
  //dbgio_printf ("ref length: %f\n", (double) vec_length (reflection));

#if 0
  if (draw_vectors > 0)
    {
     /* dbgio_printf ("%f %f %f\n", (double) eye_to_vertex[0],
				  (double) eye_to_vertex[1],
				  (double) eye_to_vertex[2]); */

      dbgio_printf ("e2v . norm = %f  norm . refl = %f\n",
        (double) eye_norm_dot, (double) vec_dot (x_normal, reflection));

      for (along = 0.0; along < 0.25; along += 0.005)
	{
	  int colour = 0x001f | ((int) (along * 255) << 5);
	  vec_scale (temp, x_normal, along);
	  vec_add (&temp[0], x_vertex, &temp[0]);
	  box (temp, colour);
	}

      for (along = 0.0; along < 0.25; along += 0.005)
	{
	  int colour = 0xf800 | ((int) (along * 255) << 5);

	  /*vec_scale (temp, eye_to_vertex, along);
	  vec_add (&temp[0], x_vertex, &temp[0]);
	  box (temp, colour);*/

	  colour &= ~0xf800;

	  vec_scale (temp, reflection, along);
	  vec_add (&temp[0], x_vertex, &temp[0]);
	  box (temp, colour);
	}
      draw_vectors--;
    }
#endif

  /*x = reflection[0];
  y = reflection[1];
  z = reflection[2];
  w = 1.0;
  mat_load ((matrix_t *) &unrotate[0][0]);
  mat_trans_nodiv (x, y, z, w);
  glKosMatrixDirty ();*/
  reflection[3] = 1.0;
  vec_transform_fipr (unrot, (float *) &invcamera[0][0], reflection);
  x = unrot[0];
  y = unrot[1];
  z = unrot[2];

  //glColor4ub (128 + 127 * x, 128 + 127 * y, 128 + 127 * z, 0);

  /*dbgio_printf ("x_norm len: %f  ref len: %f  unrot len: %f (%f, %f, %f)\n",
                (double) vec_length (x_normal),
                (double) vec_length (reflection),
		(double) vec_length (unrot),
		(double) unrot[0],
		(double) unrot[1],
		(double) unrot[2]);*/

  /* (x, y, z, w) should now be the reflection vector in object space (r_o).
    
    for the front face:
    
    d_o - r_o = [ k.x  k.y  k ]
    
    for the back face:
    
    -d_o - r_o = [ -k.x  -k.y  k ]
    
    for both, calculate lhs, then divide x, y by z.  */
    
  if (front)
    {
      x_f = x;
      y_f = -y;
      z_f = -1.0 - z;

      /*if (z_f >= 0.0)
        z_f = -0.0001;*/

      x_f = 0.5 + 0.5 * (x_f / z_f);
      y_f = 0.5 - 0.5 * (y_f / z_f);

      texc[0] = x_f;
      texc[1] = y_f;
      texc[2] = z;
    }
  else
    {
      x_b = x;
      y_b = y;
      z_b = 1.0 - z;

      /*if (z_b <= 0.0)
        z_b = 0.0001;*/

      x_b = 0.5 + 0.5 * (x_b / z_b);
      y_b = 0.5 - 0.5 * (y_b / z_b);

      texc[0] = x_b;
      texc[1] = y_b;
      texc[2] = z;
    }
}
		void DreamcastExceptionHandler(irq_t code, irq_context_t *context)
		{
			dbgio_printf("EXCEPTION\n");
			PrintCallstack();
			while (1) {}
		}
		void PrintCallstack()
		{
#if defined ION_PLATFORM_DREAMCAST
			dbgio_printf("CALLSTACK:\n");

			u32 framePtr = arch_get_fptr();

			while (framePtr != 0xffffffff)
			{
				if (!arch_valid_address(framePtr))
				{
					dbgio_printf("(Invalid frame pointer)\n");
					break;
				}

				printf("0x%08x\n", arch_fptr_ret_addr(framePtr));

				framePtr = arch_fptr_next(framePtr);
			}
#elif defined ION_PLATFORM_LINUX
            const int max_frames = 63;
            
            // storage array for stack trace address data
            void* addrlist[max_frames+1];

            // retrieve current stack addresses
            int addrlen = backtrace(addrlist, sizeof(addrlist) / sizeof(void*));

            if (addrlen == 0)
            {
                printf("  <empty, possibly corrupt>\n");
                return;
            }

            // resolve addresses into strings containing "filename(function+address)",
            // this array must be free()-ed
            char** symbollist = backtrace_symbols(addrlist, addrlen);

            // allocate string which will be filled with the demangled function name
            size_t funcnamesize = 256;
            char* funcname = (char*)malloc(funcnamesize);

            // iterate over the returned symbol lines. skip the first, it is the
            // address of this function.
            for (int i = 1; i < addrlen; i++)
            {
                char *begin_name = 0, *begin_offset = 0, *end_offset = 0;

                // find parentheses and +address offset surrounding the mangled name:
                // ./module(function+0x15c) [0x8048a6d]
                for (char *p = symbollist[i]; *p; ++p)
                {
                    if (*p == '(')
                        begin_name = p;
                    else if (*p == '+')
                        begin_offset = p;
                    else if (*p == ')' && begin_offset)
                    {
                        end_offset = p;
                        break;
                    }
                }

                if (begin_name && begin_offset && end_offset
                    && begin_name < begin_offset)
                {
                    *begin_name++ = '\0';
                    *begin_offset++ = '\0';
                    *end_offset = '\0';

                    // mangled name is now in [begin_name, begin_offset) and caller
                    // offset in [begin_offset, end_offset). now apply
                    // __cxa_demangle():

                    int status;
                    char* ret = abi::__cxa_demangle(begin_name,
                                    funcname, &funcnamesize, &status);
                    if (status == 0)
                    {
                        funcname = ret; // use possibly realloc()-ed string
                        printf("  %s : %s+%s\n",
                        symbollist[i], funcname, begin_offset);
                    }
                    else
                        {
                    // demangling failed. Output function name as a C function with
                        // no arguments.
                        printf("  %s : %s()+%s\n",
                        symbollist[i], begin_name, begin_offset);
                    }
                }
                else
                {
                    // couldn't parse the line? print the whole line.
                    printf("  %s\n", symbollist[i]);
                }
            }

            free(funcname);
            free(symbollist);
#endif
		}
Beispiel #6
0
static float *
subdivide (float in_points[][3], int strips_in, int strip_length, int recur,
	   int *strips_out_p, int *strip_length_out_p)
{
  int strips_out = strips_in * 2;
  int quads_in = strip_length - 2;
  int strip_len_out = (quads_in * 2) + 2;
  int points_out = strips_out * strip_len_out;
  int a_idx = 0, b_idx = points_out / 2;
  float out_points[points_out][3];
  int i, j;
  float mid_last[3];
  
  for (j = 0; j < strips_in; j++)
    {
      int stripbase = j * strip_length;
      /*int c;*/

#if 0
      dbgio_printf ("recur %d, strip %d: input points\n", recur, j);
      for (c = 0; c < strip_length; c++)
        dbgio_printf ("[ %f %f %f ]\n", (double) in_points[stripbase + c][0],
					(double) in_points[stripbase + c][1],
					(double) in_points[stripbase + c][2]);
      dbgio_printf ("\n");
#endif

      for (i = 0; i < strip_length - 2; i++)
	{
	  float mid_01[3], mid_02[3];

	  midpoint (mid_01, in_points[stripbase + i],
		    in_points[stripbase + i + 1]);
	  midpoint (mid_02, in_points[stripbase + i],
		    in_points[stripbase + i + 2]);

	  if ((i & 1) == 0)
            {
	      /* A part.  */
	      memcpy (out_points[a_idx++], in_points[stripbase + i],
		      3 * sizeof (float));
	      memcpy (out_points[a_idx++], mid_01, 3 * sizeof (float));
	      memcpy (out_points[a_idx++], mid_02, 3 * sizeof (float));

	      /* B part.  */
	      memcpy (out_points[b_idx++], mid_01, 3 * sizeof (float));
	      memcpy (out_points[b_idx++], in_points[stripbase + i + 1],
		      3 * sizeof (float));
	    }
	  else
	    {
	      /* A part.  */
	      memcpy (out_points[a_idx++], mid_01, 3 * sizeof (float));

	      /* B part.  */
	      memcpy (out_points[b_idx++], mid_01, 3 * sizeof (float));
	      memcpy (out_points[b_idx++], mid_02, 3 * sizeof (float));
	    }
	}

      midpoint (mid_last, in_points[stripbase + strip_length - 2],
		in_points[stripbase + strip_length - 1]);

      /* Finish off A part.  */
      memcpy (out_points[a_idx++], in_points[stripbase + strip_length - 2],
	      3 * sizeof (float));
      memcpy (out_points[a_idx++], mid_last, 3 * sizeof (float));

      /* Finish off B part.  */
      memcpy (out_points[b_idx++], mid_last, 3 * sizeof (float));
      memcpy (out_points[b_idx++], in_points[stripbase + strip_length - 1],
	      3 * sizeof (float));
    }
  
  if (recur == 0)
    {
      float *out_pts_copy = malloc (points_out * sizeof (float) * 3);

      *strips_out_p = strips_out;
      *strip_length_out_p = strip_len_out;

      memcpy (out_pts_copy, out_points, points_out * sizeof (float) * 3);

      return out_pts_copy;
    }
  else
    return subdivide (out_points, strips_out, strip_len_out, recur - 1,
		      strips_out_p, strip_length_out_p);
}