void magic_button(s16 key) { switch (key) { case PGKEY_SLASH: /* CTRL-ALT-SLASH exits */ pgserver_mainloop_stop(); return; #ifdef DEBUG_KEYS /* The rest only work in debug mode */ case PGKEY_d: /* CTRL-ALT-d lists all debugging commands */ guru("Someone set up us the bomb!\n" "All your divnode are belong to us!\n" "\n" "Debugging keys:\n" " CTRL-ALT-H: [H]andle tree dump to stdout\n" " CTRL-ALT-S: [S]tring dump to stdout\n" " CTRL-ALT-T: Div[t]ree dump to stdout\n" " CTRL-ALT-M: [M]emory use profile\n" " CTRL-ALT-B: [B]lack screen\n" " CTRL-ALT-Y: Uns[y]nchronize screen buffers\n" " CTRL-ALT-U: Bl[u]e screen\n" " CTRL-ALT-P: Bitma[p] dump to video display\n" " CTRL-ALT-O: Divn[o]de outline\n" " CTRL-ALT-A: [A]pplication dump to stdout\n" " CTRL-ALT-R: Hotspot g[r]aph\n" " CTRL-ALT-I: Mode [I]nfo\n" ); return; case PGKEY_h: /* CTRL-ALT-h dumps the handle tree */ handle_dump(); return; case PGKEY_s: /* CTRL-ALT-s dumps all strings */ string_dump(); return; case PGKEY_n: /* CTRL-ALT-n dumps all gropnodes */ grop_dump(); return; case PGKEY_t: /* CTRL-ALT-t dumps all divnodes */ div_dump(); return; case PGKEY_g: /* Just for fun :) */ guru("GURU MEDITATION #3263827\n\nCongratulations!\n" " Either you have read the source code or\n" " you have very persistently banged your\n" " head on the keyboard ;-)"); return; case PGKEY_m: /* CTRL-ALT-m displays a memory profile */ guru("Memory Profile\n\n" "Total memory use: %d bytes in %d allocations\n\n" "%d bytes in %d gropnodes\n" "%d bytes in %d zombie gropnodes\n" "%d bytes in %d divnodes\n" "%d bytes in %d widgets\n" "%d bytes in %d handle nodes", memamt,memref, num_grops*sizeof(struct gropnode),num_grops, grop_zombie_count*sizeof(struct gropnode),grop_zombie_count, num_divs*sizeof(struct divnode),num_divs, num_widgets*sizeof(struct widget),num_widgets, num_handles*sizeof(struct handlenode),num_handles); return; case PGKEY_b: /* CTRL-ALT-b blanks the screen */ { s16 lxres,lyres; VID(bitmap_getsize)(magic_cursor_display(), &lxres, &lyres); VID(rect) (magic_cursor_display(), 0,0,lxres,lyres, VID(color_pgtohwr) (0),PG_LGOP_NONE); VID(update) (magic_cursor_display(),0,0,lxres,lyres); } return; case PGKEY_y: /* CTRL-ALT-y unsynchronizes the screen buffers */ { /* The buffers in PicoGUI normally like to be synchronized. * Data flows from the divtree to the backbuffer to the screen. * The purpose of this debugging key is to put a different * image on the screen (a black rectangle) than is in the rest * of the pipeline, so that by watching the data ooze out one * can tell if the correct update regions are being used and * in general prod at the video driver. * This would be very simple if not for the fact that only the video * driver has access to the screen's buffer. The procedure here is * to pump the black screen all the way through, then reinitializing * the backbuffer while being very carefull not to update right away * or mess up the sprites. */ struct divtree *p; s16 lxres,lyres; VID(bitmap_getsize)(magic_cursor_display(), &lxres, &lyres); /* Push through the black screen */ VID(rect) (magic_cursor_display(), 0,0,lxres,lyres, VID(color_pgtohwr) (0),PG_LGOP_NONE); VID(update) (magic_cursor_display(),0,0,lxres,lyres); /* Force redrawing everything to the backbuffer */ for (p=dts->top;p;p=p->next) p->flags |= DIVTREE_ALL_REDRAW; update(NULL,0); /* Note the zero flag! */ /* Clear the update rectangle, breaking the pipeline that usually works so well :) */ for (p=dts->top;p;p=p->next) p->update_rect.w = 0; /* The above zero flag left sprites off. With sprites off it's tough to use the mouse! */ VID(sprite_showall) (); } return; case PGKEY_u: /* CTRL-ALT-u makes a blue screen */ { s16 lxres,lyres; VID(bitmap_getsize)(magic_cursor_display(), &lxres, &lyres); VID(rect) (magic_cursor_display(),0,0,lxres,lyres, VID(color_pgtohwr) (0x0000FF), PG_LGOP_NONE); VID(update) (magic_cursor_display(),0,0,lxres,lyres); } return; case PGKEY_p: /* CTRL-ALT-p shows all loaded bitmaps */ { struct debug_bitmaps_data data; s16 lxres,lyres; VID(bitmap_getsize)(VID(window_debug)(), &lxres, &lyres); memset(&data,0,sizeof(data)); guru("Table of loaded bitmaps:"); handle_iterate(PG_TYPE_BITMAP,&debug_bitmaps,&data); VID(update) (VID(window_debug)(),0,0,lxres,lyres); } return; case PGKEY_o: /* CTRL-ALT-o traces all divnodes */ { s16 lxres,lyres; VID(bitmap_getsize)(magic_cursor_display(), &lxres, &lyres); r_divnode_trace(dts->top->head); VID(update) (magic_cursor_display(),0,0,lxres,lyres); } return; case PGKEY_a: /* CTRL-ALT-a shows application info */ { struct app_info *a; const struct pgstring *name; for (a=applist;a;a=a->next) { if (iserror(rdhandle((void**)&name,PG_TYPE_PGSTRING,-1,a->name))) name = pgstring_tmpwrap("(error reading handle)"); printf("app: '"); pgstring_print(name); printf("' type=%d owner=%d\n",a->type,a->owner); } } return; case PGKEY_r: /* CTRL-ALT-r draws the hotspot graph */ { struct hotspot *p; s16 lxres,lyres; VID(bitmap_getsize)(magic_cursor_display(), &lxres, &lyres); for (p=hotspotlist;p;p=p->next) hotspot_draw(p); VID(update) (magic_cursor_display(),0,0,lxres,lyres); } return; case PGKEY_i: /* CTRL-ALT-i gets video mode info */ { int x,y,celw,celh, pixelx,pixely; hwrcolor i, white, black, numcolors; s16 lxres,lyres; VID(bitmap_getsize)(VID(window_debug)(), &lxres, &lyres); guru("Video mode:\n" "Logical %dx%d, physical %dx%d, %d-bit color\n" "\n" "Color palette:\n", vid->lxres, vid->lyres, vid->xres, vid->yres, vid->bpp); if (vid->bpp <= 8) { /* Actual palette display */ i = 0; celw = (lxres-20) >> 4; celh = (lyres-70) >> 4; if (celw < celh) celh = celw; else celw = celh; white = VID(color_pgtohwr)(PGC_WHITE); black = VID(color_pgtohwr)(PGC_BLACK); numcolors = 1 << vid->bpp; for (y=0;y<16;y++) for (x=0;x<16 && i<numcolors;x++,i++) { pixelx = x*celw+10; pixely = y*celh+60; /* Display a rectangle of the color with black and white borders. * This is a lot like what the scribble app does, but we don't have * the convenience of a "frame" gropnode at this low level. */ VID(slab)(VID(window_debug)(),pixelx,pixely,celw,white,PG_LGOP_NONE); VID(slab)(VID(window_debug)(),pixelx,pixely+celh,celw,white,PG_LGOP_NONE); VID(bar)(VID(window_debug)(),pixelx,pixely,celh,white,PG_LGOP_NONE); VID(bar)(VID(window_debug)(),pixelx+celw,pixely,celh,white,PG_LGOP_NONE); VID(slab)(VID(window_debug)(),pixelx+1,pixely+1,celw-2, black, PG_LGOP_NONE); VID(slab)(VID(window_debug)(),pixelx+1,pixely-1+celh,celw-2, black, PG_LGOP_NONE); VID(bar)(VID(window_debug)(),pixelx+1,pixely+1,celh-2, black, PG_LGOP_NONE); VID(bar)(VID(window_debug)(),pixelx-1+celh,pixely+1,celh-2, black, PG_LGOP_NONE); VID(rect)(VID(window_debug)(),pixelx+2,pixely+2,celw-3,celh-3, i , PG_LGOP_NONE); } } else { /* Just some RGB gradients */ y = 60; VID(gradient)(VID(window_debug)(),10,y,lxres-20,20,0, 0x000000,0xFFFFFF, PG_LGOP_NONE); y += 30; VID(gradient)(VID(window_debug)(),10,y,lxres-20,20,0, 0x000000,0xFF0000, PG_LGOP_NONE); y += 30; VID(gradient)(VID(window_debug)(),10,y,lxres-20,20,0, 0x000000,0x00FF00, PG_LGOP_NONE); y += 30; VID(gradient)(VID(window_debug)(),10,y,lxres-20,20,0, 0x000000,0x0000FF, PG_LGOP_NONE); y += 30; } VID(update) (VID(window_debug)(),0,0,lxres,lyres); }
g_error g_dmalloc(void **p,size_t s,const char *where) { #else g_error g_malloc(void **p,size_t s) { #endif if (!p) return mkerror(PG_ERRT_INTERNAL,25); #ifdef DEBUG_ANY *p = malloc(s+sizeof(size_t)); #else *p = malloc(s); #endif if (!(*p)) return mkerror(PG_ERRT_MEMORY,25); memref++; #ifdef DEBUG_ANY *(((size_t *)(*p)++)) = s; memamt += s; #endif #ifdef DEBUG_MEMORY memtrack=realloc(memtrack, sizeof(*memtrack)*memref); if(memref && memtrack==NULL) { guru("Aieee! Memory tracker ran out of memory!"); exit(234); } memtrack[memref-1].mem=*p; memtrack[memref-1].size=s; memtrack[memref-1].where=where; fprintf(stderr, "+%d #%d (%ld) %p %s\n",s,memref,memamt,*p,where); #endif return success; } #ifndef DEBUG_MEMORY void g_free(const void *p) { #else void g_dfree(const void *p, const char *where) { int i; const char *adr = p; #endif #ifdef DEBUG_ANY size_t s; #endif if (!p) return; #ifdef DEBUG_ANY ((size_t*)p--); #endif memref--; #ifdef DEBUG_ANY memamt -= (s = *((size_t*)p)); #ifdef DEBUG_MEMORY for(i=0; i<memref+1; i++) { if(memtrack[i].mem==adr) { memmove(memtrack+i, memtrack+memref, sizeof(*memtrack)); break; } } /* Argh!! Electric Fence assumes it's a bug if we allocate * zero bytes, so to keep efence from aborting us, don't resize * this if it would be sizing to zero bytes. */ #ifdef CONFIG_EFENCE if (memref) { #endif memtrack=realloc(memtrack, sizeof(*memtrack)*memref); if(memref && memtrack==NULL) { guru("Aieee! Memory tracker ran out of memory!"); exit(234); } #ifdef CONFIG_EFENCE } #endif fprintf(stderr, "-%d #%d (%ld) %p %s\n",s,memref,memamt,adr,where); #endif #endif free((void*)p); }
void handlePanic(char *message, unsigned int address) { guru(address, "PANIC AT", message); }
g_error g_drealloc(void **p,size_t s,const char *where) { int pos; #else g_error g_realloc(void **p,size_t s) { #define where "Can't happen in g_realloc" #endif #ifdef DEBUG_ANY size_t from; #endif void *oldp; if (!p) return mkerror(PG_ERRT_BADPARAM,25); if(s) { if (!*p) return g_dmalloc(p,s,where); } else { oldp=*p; *p=NULL; g_dfree(oldp,where); return success; } #ifdef DEBUG_MEMORY for(pos=0; pos<memref; pos++) if(memtrack[pos].mem==*p) break; if(pos==memref) { guru("Attempt to g_realloc memory acquired elsewhere!\n" "! [%d] %p %s", s, p, where); return mkerror(PG_ERRT_MEMORY,25); } #endif #ifdef DEBUG_ANY ((size_t*)(*p)--); /* Get the _real_ pointer so realloc will like us */ oldp=*p; memamt -= (from = *((size_t*)(*p))); /* Store original size */ *p = realloc(*p,s+sizeof(size_t)); #else oldp=*p; *p = realloc(*p,s); #endif if (!(*p)) { if(oldp) /* FIXME */ { memref--; free(oldp); } return mkerror(PG_ERRT_MEMORY,25); } #ifdef DEBUG_ANY *(((size_t *)(*p)++)) = s; memamt += s; #endif #ifdef DEBUG_MEMORY memtrack[pos].mem=*p; memtrack[pos].size=s; memtrack[pos].where=where; fprintf(stderr, "* [%d -> %d] #%d (%ld) %p %s\n",from,s,memref,memamt,*p,where); #endif return success; }
void illegalSlot(unsigned int address) { guru(address, "ILLEGAL SLOT AT", ""); }