/* GEMDBG.C from greg rossi */ /* * Copyright 1999, Caldera Thin Clients, Inc. * This software is licenced under the GNU Public License. * Please see LICENSE.TXT for further information. * */ #include #include #define MAXSTR 140 EXTERN WORD bio_kb(); EXTERN WORD dos_write(); #if HIGH_C VOID dbg_putc(); VOID dbg(); VOID _dprintf(); VOID _prt10(); VOID _prtl10(); VOID _prt16(); VOID _prtl16(); #endif GLOBAL WORD gl_int = 0; GLOBAL WORD gl_dbgprt = 0; #if 0 EXTERN WORD DOS_AX; EXTERN WORD DOS_BX; EXTERN WORD DOS_CX; WORD dos_write(handle, cnt, pbuffer) WORD handle; WORD cnt; LONG pbuffer; { DOS_CX = cnt; DOS_BX = handle; dos_func(0x4000, pbuffer); return(DOS_AX); } #endif #if 1 dbg_setport() { switch(bio_kb(0) & 0x00ff) { case '0': gl_dbgprt = -1; break; case '1': gl_dbgprt = 0; break; case '2': gl_dbgprt = 1; break; default : gl_dbgprt = 2; } } #endif dbg_wait() { dbg("PRESS ANY KEY TO CONTINUE....\r\n"); bio_kb(0); } #if 0 WORD dbg_chkint() { WORD old; dbg_putc(0); old = gl_int; gl_int = 0; return(old); } #endif #if 1 BYTE dbg_chpoll() { BYTE temp; temp = 0; bio_com(gl_dbgprt, 0x0100); if (bio_com(gl_dbgprt, 0x0300) & 0x0100) temp = bio_com(gl_dbgprt, 0x0200); return(temp); } #endif VOID dbg_putc(ch) BYTE ch; /* output character to the commo port */ { BYTE temp; if (gl_dbgprt == -1) /* output to stdout */ { dos_write(1,1,ADDR(&ch)); return; } temp = 0; temp = dbg_chpoll(); if (temp == 's') /* if the char = 's' */ while (temp != 'q') /* look for 'q' */ { temp = dbg_chpoll(); if (temp == 'i') gl_int = 1; /* interrupt key pressed */ } if (temp == 'i') gl_int = 1; /* interrupt key pressed */ bio_com(gl_dbgprt,0x0100 + ch); /* send the input char */ } static BYTE outbuf[ MAXSTR ]; static WORD idx; /****************************************************************/ VOID dbg( fmt, args) BYTE *fmt; WORD args; { static BYTE *p; if (gl_dbgprt==2) return; for(idx=0;idxMAXSTR || fmin < 0) fmin = 0; if (fmax >MAXSTR || fmax < 0) fmax = 0; leading = 0; if (fmax != 0 || fmin != 0) { if (fmax != 0) if (length > fmax) length = fmax; if (fmin != 0) leading = fmin - length; if (sign == '-') --leading; } if (sign == '-' && fill == '0' ) outbuf[idx++] = sign; if (leftjust == 0) for (i=0;i= 0) *str++ = temp[i--]; } #if HIGH_C WORD _dwreml(num, div) LONG num; WORD div; { return(num - (div * (num / div))); } #endif VOID _prtl10(num,str) LONG num; BYTE *str; { WORD i; BYTE c,temp[11]; temp[0] = '\0'; for(i=1;i<=10;i++) { #if HIGH_C temp[i] = _dwreml(num,10) + '0'; #else temp[i] = num % 10 + '0'; #endif num = num / 10; } for(i=10;temp[i] == '0'; i--); if (i == 0) i++; while (i >= 0) *str++ = temp[i--]; } VOID _prt16(num,str) UWORD num; BYTE *str; { WORD i; BYTE c,temp[5]; temp[0] = '\0'; for(i=1;i<=4;i++) { temp[i] = "0123456789abcdef"[num & 0x0f]; num = num >> 4; } for(i=4;temp[i] == '0'; i--); if (i == 0) i++; while ( i >= 0 ) *str++ = temp[i--]; } VOID _prtl16(num,str) LONG num; BYTE *str; { WORD i; BYTE c,temp[9]; temp[0] = '\0'; for(i=1;i<=8;i++) { temp[i] = "0123456789abcdef"[num & 0x0f]; num = num >> 4; } for(i=8;temp[i] == '0';i--); if (i == 0) i++; while(i >= 0) *str++ = temp[i--]; } dump(addr,len) LONG addr; WORD len; { LONG p; WORD i, j; BYTE c; BYTE st[17]; for (p=addr; p 126)) c = '.'; st[i+j] = c; } i += 2; if (i > 15) { i = 0; st[16] = 0; dbg(" %s", &st[0]); } } dbg("\r\n"); } #if 0 /* WORD dbglen( p ) BYTE *p; { WORD ilen; ilen = 0; while(*p++) ilen++; return( ilen ); } */ #endif