nitpic-0.1.orig/ 40775 10333 10333 0 6276533564 11721 5ustar kleekleenitpic-0.1.orig/16c84.cc100444 10333 10333 57455 5671607754 13127 0ustar kleeklee/* * 16c84.cc -- contains all 16c84-specific simulator routines */ #include "picsim.hh" #include info_reg pic16c84_info[]={ {"STATUS",{"IRP","RP1","RP0","TO","PD","Z","DC","C"},0,0}, {"OPTION",{"RBPU","INTE","RTS","RTE","PSA","PS2","PS1","PS0"},0,0}, {"INTCON",{"GIE","EEIE","RTIE","INTE","RBIE","RTIF","INTF","RBIF"},0,0}, {NULL,{NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL},0,0} }; pin_info pic16c84_pin[18] = { { "RA2", 0, 0 }, { "RA3", 0, 0 }, { "RA4", 0, 0 }, { "MCLR", 0, 0 }, { "Vss", 2, 0 }, { "RB0", 0, 0 }, { "RB1", 0, 0 }, { "RB2", 0, 0 }, { "RB3", 0, 0 }, { "RB4", 0, 0 }, { "RB5", 0, 0 }, { "RB6", 0, 0 }, { "RB7", 0, 0 }, { "Vdd", 2, 0 }, { "OSC2", 2, 0 }, { "OSC1", 2, 0 }, { "RA0", 0, 0 }, { "RA1", 0, 0 } } ; pins_info pic16c84_pins = { 18, pic16c84_pin } ; typedef struct { u_int mask, dont_care, discriminator; u_int literal; unsigned d : 1, f : 1, b : 1; char *name; void (*execute)( void ); } pic16c84_instr; #define C 0001 // Carry #define DC 0002 // Digit carry #define Z 0004 // Zero #define PD 0010 // Power Down #define TO 0020 // Time-out #define RP0 0040 // Page select bit 0 #define RP1 0100 // Page select bit 1 (not used) #define IRP 0200 // Indirect addressing page select (not used) static pic16c84_instr PIC16C84_INSTR[]; static int match_instr( u_int instr ); static void use_a_cycle( Boolean no_ints = False ); static void sleep_a_cycle( void ); static char get_f( u_int instr, int *p = NULL, int *r = NULL ); static char get_w( void ); static void set_f( int p, int r, char val, Boolean set_z ); static void set_w( char val, Boolean set_z ); static void set_status( int set, int clear ); static void init_pic16c84( void ); static void reset_pic16c84( void ); static char *disasm_pic16c84( u_int instr ); static char status_hook( reg *status, Boolean write, char v = 0 ); static char port_hook( reg *port, Boolean write, char v = 0 ); /* * This is the entry point to the Pic16C84 simulator. All calls from the * generic simulator come through here. */ SimAR pic16c84( SimFunc func, SimAR arg ) { SimAR result; int i; static char buf[64]; switch (func) { case Init: init_pic16c84( ); return result; case Reset: reset_pic16c84( ); return result; case GetPage: result.i = (Pic.reg_file[0][3].value >> 4) & 3; return result; case GetInfo: result.p = pic16c84_info; pic16c84_info[0].value = Pic.reg_file[0][3].value; pic16c84_info[1].value = Pic.reg_file[1][1].value; pic16c84_info[2].value = Pic.reg_file[0][11].value; return result; case GetPins: result.p = &pic16c84_pins; pic16c84_pin[0].io = !(Pic.reg_file[1][5].value & 4); pic16c84_pin[0].hi = (Pic.reg_file[0][5].value & 4) != 0; pic16c84_pin[1].io = !(Pic.reg_file[1][5].value & 8); pic16c84_pin[1].hi = (Pic.reg_file[0][5].value & 8) != 0; pic16c84_pin[2].io = !(Pic.reg_file[1][5].value & 16); pic16c84_pin[2].hi = (Pic.reg_file[0][5].value & 16) != 0; pic16c84_pin[16].io = !(Pic.reg_file[1][5].value & 1); pic16c84_pin[16].hi = (Pic.reg_file[0][5].value & 1) != 0; pic16c84_pin[17].io = !(Pic.reg_file[1][5].value & 2); pic16c84_pin[17].hi = (Pic.reg_file[0][5].value & 2) != 0; for (i = 0; i < 8; i++) { pic16c84_pin[i + 5].io = !(Pic.reg_file[1][6].value & (1 << i)); pic16c84_pin[i + 5].hi = (Pic.reg_file[0][6].value & (1 << i))!=0; } return result; case Disassemble: result.p = buf; sprintf( buf, "%04X %s", arg.i, disasm_pic16c84( Pic.uinfo.picmemmap[arg.i] ) ); return result; case Step: if (!Pic.sleeping) { if ((i = match_instr( Pic.uinfo.picmemmap[Pic.pc] )) == -1) { fprintf( stderr, "executed invalid opcode 0x%04X at PC 0x%04X as NOP\n", Pic.uinfo.picmemmap[Pic.pc], Pic.pc ); use_a_cycle( ); } else { PIC16C84_INSTR[i].execute( ); use_a_cycle( ); } } else { sleep_a_cycle( ); } return result; default: exit( 1 ); } } /* * PIC16C84 initialization */ static void init_pic16c84( void ) { int i, j; Pic.isize = 0x400; Pic.reg_pages = 2; Pic.nstack = 8; for (i = 0; i < Pic.reg_pages; i++) { for (j = 0; j < 128; j++) { Pic.reg_file[i][j].redirect_page = i; /* redirect to self */ Pic.reg_file[i][j].redirect_reg = j; Pic.reg_file[i][j].implemented = (j <= 0x2f) ? 0xff : 0; Pic.reg_file[i][j].modified = 0; Pic.reg_file[i][j].modified_last = 0; Pic.reg_file[i][j].value = 0; Pic.reg_file[i][j].hook = 0; switch (j) { case 0: Pic.reg_file[i][j].name = " W"; Pic.reg_file[i][j].redirect_page = 0; break; case 1: if (!i) Pic.reg_file[i][j].name = " RTCC"; else { Pic.reg_file[i][j].name = "OPTION"; Pic.reg_file[i][j].value = 0xff; } break; case 2: Pic.reg_file[i][j].name = " PCL"; Pic.reg_file[i][j].redirect_page = 0; break; case 3: Pic.reg_file[i][j].name = "STATUS"; Pic.reg_file[i][j].value = 0x18; Pic.reg_file[i][j].redirect_page = 0; Pic.reg_file[0][j].hook = status_hook; break; case 4: Pic.reg_file[i][j].name = " FSR"; Pic.reg_file[i][j].redirect_page = 0; break; case 5: Pic.reg_file[i][j].name = (!i) ? " PORTA" : " TRISA"; Pic.reg_file[i][j].implemented = 0x1f; if (i) Pic.reg_file[i][j].value = 0x1f; Pic.reg_file[i][j].hook = port_hook; break; case 6: Pic.reg_file[i][j].name = (!i) ? " PORTB" : " TRISB"; if (i) Pic.reg_file[i][j].value = 0xff; Pic.reg_file[i][j].hook = port_hook; break; case 7: Pic.reg_file[i][j].name = "------"; Pic.reg_file[i][j].implemented = 0; break; case 8: Pic.reg_file[i][j].name = (!i) ? "EEDATA" : "EECON1"; break; case 9: Pic.reg_file[i][j].name = (!i) ? " EEADR" : "EECON2"; break; case 10: Pic.reg_file[i][j].name = "PCLATH"; Pic.reg_file[i][j].implemented = 0x1f; Pic.reg_file[i][j].redirect_page = 0; break; case 11: Pic.reg_file[i][j].name = "INTCON"; break; default: Pic.reg_file[i][j].name = NULL; if (i) Pic.reg_file[i][j].redirect_page = 0; break; } } } Pic.wdt_left = (u_long)(Pic.uinfo.clock * Pic.wdt_max / 4.0); Pic.prescaler = 128; } static void reset_pic16c84( void ) { if (Pic.sleeping) { set_status( TO, IRP | RP1 | RP0 | PD ); set_f( 0, 11, 0, False ); // INTCON = 0 } else { set_f( 0, 11, get_f( 11, NULL, NULL ) & 1, False ); // INTCON = 0 set_status( 0, IRP | RP1 | RP0 ); } Pic.sleeping = 0; Pic.pc = 0; Pic.wdt_left = (u_long)(Pic.uinfo.clock * Pic.wdt_max / 4.0); Pic.prescaler = 128; set_f( 1, 1, ~0, False ); // OPTION = ~0 set_f( 1, 5, ~0, False ); // Set TRIS-A & TRIS-B to 1's set_f( 1, 6, ~0, False ); set_f( 0, 10, 0, False ); // PCLATH = 0 } static char status_hook( reg *status, Boolean write, char v ) { if (write) { Boolean switch_page = ((v ^ status->value) & RP0); status->value = v; if (switch_page) { String s = "next"; Cardinal n = 1; reg_switch( NULL, NULL, &s, &n ); instr_refresh( NULL, NULL, NULL, NULL ); } } return status->value; } static char port_hook( reg *port, Boolean write, char v ) { if (write) { Boolean twiddle_bits = (v ^ port->value); port->value = v & port->implemented; if (twiddle_bits) ic_update( ); } return port->value; } /* * Common stuff that must be done every time the processor executes a * cycle: * Increment the Ticks counter * Increment the PC & set the PCL register * Decrement the WDT, check for timeout * Decrement the RTCC, check for interrupt * * Functions that are going to diddle the PC and just want to call this * to get the necessary extra cycle delay pass no_ints == True to avoid * getting a WDT timeout or interrupt in the middle of the instruction. */ static void use_a_cycle( Boolean no_ints ) { Boolean wdt_tick = True; Boolean rtcc_tick = !(Pic.reg_file[1][1].value & 0x20); Pic.ticks += 4; if (--Pic.millisec_left <= 0) { Pic.millisec += 1; Pic.millisec_left = (int)(Pic.uinfo.clock / 4000.0); } Pic.pc += 1; if (Pic.pc >= Pic.isize) Pic.pc = 0; /* * The prescaler will tick if it's assigned to the WDT or if * the RTCC is running off the internal clock: */ if (Pic.reg_file[1][1].value & 0x28) { if (!no_ints || Pic.prescaler != 1) Pic.prescaler -= 1; if (Pic.prescaler > 0) { /* * Prescaler hasn't timed out yet ... no tick on whatever * it's connected to. */ if (Pic.reg_file[1][1].value & 8) wdt_tick = False; else rtcc_tick = False; } else { /* * Prescaler has timed out ... tick on whatever it's * connected to. */ if (Pic.reg_file[1][1].value & 8) wdt_tick = True; else rtcc_tick = True; /* * Also, the prescaler gets reset. */ Pic.prescaler = (((Pic.reg_file[1][1].value & 8) ? 1 : 2) << (Pic.reg_file[1][1].value & 7)); } } if (wdt_tick && (Pic.wdt_left || !no_ints)) { if (Pic.wdt_left) { Pic.wdt_left -= 1; } else { if (Pic.uinfo.wd_fuse) { Pic.pc = 0; // WDT timeout! Pic.sleeping = 0; Pic.wdt_left = (u_long)(Pic.uinfo.clock * Pic.wdt_max / 4.0); Pic.prescaler = 128; set_f( 1, 1, ~0, False ); // OPTION = ~0 set_f( 1, 5, ~0, False ); // Set TRIS-A & TRIS-B to 1's set_f( 1, 6, ~0, False ); set_f( 0, 10, 0, False ); // PCLATH = 0 set_status( PD, IRP | RP1 | RP0 | TO ); info_refresh( NULL, NULL, NULL, NULL ); if (Pic.running) sim_toggle_run( NULL, NULL, NULL, NULL ); } else { Pic.wdt_left = (u_long)(Pic.uinfo.clock * Pic.wdt_max / 4.0); if (Pic.reg_file[1][1].value & 8) { Pic.prescaler = 1 << (Pic.reg_file[1][1].value & 7); } } } } if (rtcc_tick && (!no_ints || Pic.reg_file[0][1].value != 1)) { Pic.reg_file[0][1].value -= 1; // RTCC decrements Pic.reg_file[0][1].modified = 1; // fixme: Check here for RTCC interrupt } set_f( 0, 2, Pic.pc & 0xff, False ); } /* * Common stuff that must be done every time the processor sleeps a cycle: * Decrement the WDT & check for wakeup */ static void sleep_a_cycle( void ) { if (--Pic.millisec_left <= 0) { Pic.millisec += 1; Pic.millisec_left = (int)(Pic.uinfo.clock / 4000.0); } if (Pic.reg_file[1][1].value & 8) { // Prescaler is assigned to WDT Pic.prescaler -= 1; if (Pic.prescaler > 0) return; Pic.prescaler = 1 << (Pic.reg_file[1][1].value & 7); } if (Pic.wdt_left) { Pic.wdt_left -= 1; } else { // WDT timeout during SLEEP Pic.sleeping = 0; Pic.wdt_left = (u_long)(Pic.uinfo.clock * Pic.wdt_max / 4.0); if (Pic.reg_file[1][1].value & 8) { Pic.prescaler = 1 << (Pic.reg_file[1][1].value & 7); } info_refresh( NULL, NULL, NULL, NULL ); set_status( 0, PD | TO ); Pic.pc += 1; set_f( 0, 2, Pic.pc & 0xff, False ); } } static char get_f( u_int instr, int *p, int *r ) { int a, b, c, d; a = (Pic.reg_file[0][3].value >> 5) & 1; b = instr & 0x7f; if (!b) { // use contents of FSR c = (Pic.reg_file[0][4].value >> 7) & 1; d = Pic.reg_file[0][4].value; } else { c = Pic.reg_file[a][b].redirect_page; d = Pic.reg_file[a][b].redirect_reg; } if (p != NULL) *p = c; if (r != NULL) *r = d; if (d) { if (Pic.reg_file[c][d].hook) { return Pic.reg_file[c][d].hook( &Pic.reg_file[c][d], False ); } else { return Pic.reg_file[c][d].value & 0xff; } } else { return 0; // indirect access of F0 returns 0 } return (!d) ? 0 : Pic.reg_file[c][d].value & 0xff; } static char get_w( void ) { return Pic.reg_file[0][0].value; } /* * Construct a 13-bit value from the low 11 bits of the instr and bits <4:3> * of PCLATH. This value is then truncated to fit within the address space. */ static int get_addr( u_int instr ) { return (((((int)Pic.reg_file[0][10].value << 8) & 0x1800) | instr & 0x7ff) - 1) & 0x3ff; } static void set_f( int p, int r, char val, Boolean set_z ) { if (r) { if (Pic.reg_file[p][r].hook) { val = Pic.reg_file[p][r].hook( &Pic.reg_file[p][r], True, val ); } else { val = Pic.reg_file[p][r].value = val & Pic.reg_file[p][r].implemented; Pic.reg_file[p][r].modified = 1; } } // fixme: execute any hooks on this register! if (set_z) set_status( (!val) ? Z : 0, (val) ? Z : 0 ); } static void set_w( char val, Boolean set_z ) { Pic.reg_file[0][0].value = val; Pic.reg_file[0][0].modified = 1; if (set_z) set_status( (!val) ? Z : 0, (val) ? Z : 0 ); } static void set_status( int set, int clear ) { Pic.reg_file[0][3].value |= set; Pic.reg_file[0][3].value &= ~clear; Pic.reg_file[0][3].modified = 1; } static char * disasm_pic16c84( u_int instr ) { static char dscr[32]; int i; pic16c84_instr *tmpl; if ((i = match_instr( instr )) == -1) return "??????"; tmpl = PIC16C84_INSTR + i; if (tmpl->f) { char reg[16]; int a; int b; int p; int r; a = (Pic.reg_file[0][3].value >> 5) & 1; b = instr & 0x7f; p = Pic.reg_file[a][b].redirect_page; r = Pic.reg_file[a][b].redirect_reg; if (!p && !r) { strcpy( reg, "@FSR" ); } else if (Pic.reg_file[p][r].name) { char *cp = Pic.reg_file[p][r].name; while (isspace(*cp)) ++cp; strcpy( reg, cp ); } else sprintf( reg, "F%02X", r ); if (tmpl->d) sprintf( dscr, "%s %s,%c", tmpl->name, reg, (instr & 0x80) ? 'F' : 'W' ); else if (tmpl->b) sprintf( dscr, "%s %s,%d", tmpl->name, reg, (instr & 0x380) >> 7 ); else sprintf( dscr, "%s %s", tmpl->name, reg ); } else if (tmpl->literal) sprintf( dscr, (tmpl->literal & 0xff00) ? "%s 0x%04x" : "%s 0x%02x", tmpl->name, instr & tmpl->literal ); else strcpy( dscr, tmpl->name ); if (instr & tmpl->dont_care) { char *cp; for (cp = dscr; *cp; cp++) if (isalpha( *cp )) *cp = tolower( *cp ); } return dscr; } /* * These routines simulate each individual instruction */ static void exADDWF( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; int w, f, sum; int c, dc; w = get_w( ) & 0xff; f = get_f( instr, &p, &r ) & 0xff; sum = w + f; if (instr & 0x80) set_f( p, r, sum, True ); else set_w( sum, True ); c = (sum & 0x100) ? C : 0; dc = (((w & 0x0f) + (f & 0x0f)) & 0x10) ? DC : 0; set_status( c | dc, (c^C) | (dc^DC) ); } static void exANDWF( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; int w, f, and; int d, dc; w = get_w( ); f = get_f( instr, &p, &r ); and = w & f; if (instr & 0x80) set_f( p, r, and, True ); else set_w( and, True ); } static void exCLRF( void ) { int p, r; get_f( Pic.uinfo.picmemmap[ Pic.pc ], &p, &r ); set_f( p, r, 0, True ); } static void exCLRW( void ) { set_w( 0, True ); } static void exCOMF( void ) { u_int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; char v; v = get_f( instr, &p, &r ); if (instr & 0x80) set_f( p, r, ~v, True ); else set_w( ~v, True ); } static void exDECF( void ) { u_int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; char v; v = get_f( instr, &p, &r ); v -= 1; if (instr & 0x80) set_f( p, r, v, True ); else set_w( v, True ); } static void exDECFSZ( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; char v; v = get_f( instr, &p, &r ); v -= 1; if (instr & 0x80) set_f( p, r, v, False ); else set_w( v, False ); if (v == 0) use_a_cycle( True ); } static void exINCF( void ) { u_int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; char v; v = get_f( instr, &p, &r ); v += 1; if (instr & 0x80) set_f( p, r, v, True ); else set_w( v, True ); } static void exINCFSZ( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; char v; v = get_f( instr, &p, &r ); v += 1; if (instr & 0x80) set_f( p, r, v, False ); else set_w( v, False ); if (v == 0) use_a_cycle( True ); } static void exIORWF( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; int w, f, or; int c, dc; w = get_w( ); f = get_f( instr, &p, &r ); or = w | f; if (instr & 0x80) set_f( p, r, or, True ); else set_w( or, True ); } static void exMOVF( void ) { u_int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; char v; v = get_f( instr, &p, &r ); if (instr & 0x80) set_f( p, r, v, True ); else set_w( v, True ); } static void exMOVWF( void ) { u_int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; get_f( instr, &p, &r ); set_f( p, r, get_w(), False ); } static void exNOP( void ) { } static void exRLF( void ) { u_int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; char v; int c; v = get_f( instr, &p, &r ); c = (v & 0x80) ? C : 0; v = (v << 1) | ((Pic.reg_file[0][3].value & C) ? 1 : 0); if (instr & 0x80) set_f( p, r, v, False ); else set_w( v, False ); set_status( c, c ^ C ); } static void exRRF( void ) { u_int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; char v; int c; v = get_f( instr, &p, &r ); c = (v & 1) ? C : 0; v = (v >> 1) | ((Pic.reg_file[0][3].value & C) ? 0x80 : 0); if (instr & 0x80) set_f( p, r, v, False ); else set_w( v, False ); set_status( c, c ^ C ); } static void exSUBWF( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; int w, f, dif; int c, dc; w = get_w( ) & 0xff; f = get_f( instr, &p, &r ) & 0xff; dif = f - w; if (instr & 0x80) set_f( p, r, dif, True ); else set_w( dif, True ); c = (dif & 0x100) ? C : 0; dc = (((f & 0x0f) - (w & 0x0f)) & 0x10) ? DC : 0; set_status( c | dc, (c^C) | (dc^DC) ); } static void exSWAPF( void ) { u_int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; char v; v = get_f( instr, &p, &r ); v = ((v >> 4) & 0x0f) | (v << 4); if (instr & 0x80) set_f( p, r, v, False ); else set_w( v, False ); } static void exXORWF( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int p, r; int w, f, xor; w = get_w( ); f = get_f( instr, &p, &r ); xor = w ^ f; if (instr & 0x80) set_f( p, r, xor, True ); else set_w( xor, True ); } static void exBCF( void ) { u_int instr = Pic.uinfo.picmemmap[Pic.pc]; int bit = (instr >> 7) & 7; int p, r; char v; v = get_f( instr, &p, &r ) & ~(1 << bit); set_f( p, r, v, False ); } static void exBSF( void ) { u_int instr = Pic.uinfo.picmemmap[Pic.pc]; int bit = (instr >> 7) & 7; int p, r; char v; v = get_f( instr, &p, &r ) | (1 << bit); set_f( p, r, v, False ); } static void exBTFSC( void ) { u_int instr = Pic.uinfo.picmemmap[Pic.pc]; int bit = (instr >> 7) & 7; if (!(get_f( instr ) & (1 << bit))) use_a_cycle( True ); } static void exBTFSS( void ) { u_int instr = Pic.uinfo.picmemmap[Pic.pc]; int bit = (instr >> 7) & 7; if (get_f( instr ) & (1 << bit)) use_a_cycle( True ); } static void exADDLW( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int w, l, sum; int c, dc; w = get_w( ) & 0xff; l = instr & 0xff; sum = w + l; set_w( sum, True ); c = (sum & 0x100) ? C : 0; dc = (((w & 0x0f) + (l & 0x0f)) & 0x10) ? DC : 0; set_status( c | dc, (c^C) | (dc^DC) ); } static void exANDLW( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int w, l, and; w = get_w( ); l = instr & 0xff; and = w & l; set_w( and, True ); } static void exCALL( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; Pic.stack[Pic.sp] = Pic.pc; Pic.sp += 1; if (Pic.sp >= Pic.nstack) Pic.sp = 0; use_a_cycle( True ); Pic.pc = get_addr( instr ); } static void exCLRWDT( void ) { Pic.wdt_left = (u_long)(Pic.uinfo.clock * Pic.wdt_max / 4.0); if (Pic.reg_file[1][1].value & 8) { Pic.prescaler = 1 << (Pic.reg_file[1][1].value & 7); } set_status( TO | PD, 0 ); info_refresh( NULL, NULL, NULL, NULL ); } static void exGOTO( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; use_a_cycle( True ); Pic.pc = get_addr( instr ); } static void exIORLW( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int w, l, or; w = get_w( ); l = instr & 0xff; or = w & l; set_w( or, True ); } static void exMOVLW( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; set_w( instr & 0xff, False ); } static void exRETFIE( void ) { int gie = get_f( 0x0b ); set_f( 0, 0x0b, gie | 0x80, False ); use_a_cycle( True ); Pic.sp -= 1; if (Pic.sp < 0) Pic.sp = Pic.nstack - 1; Pic.pc = Pic.stack[Pic.sp]; } static void exRETLW( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; set_w( instr & 0xff, False ); use_a_cycle( True ); Pic.sp -= 1; if (Pic.sp < 0) Pic.sp = Pic.nstack - 1; Pic.pc = Pic.stack[Pic.sp]; } static void exRETURN( void ) { use_a_cycle( True ); Pic.sp -= 1; if (Pic.sp < 0) Pic.sp = Pic.nstack - 1; Pic.pc = Pic.stack[Pic.sp]; } static void exSLEEP( void ) { exCLRWDT( ); set_status( TO, PD ); Pic.sleeping = 1; Pic.pc = Pic.pc - 1; } static void exSUBLW( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int w, l, dif; int c, dc; w = get_w( ) & 0xff; l = instr & 0xff; dif = l - w; set_w( dif, True ); c = (dif & 0x100) ? C : 0; dc = (((l & 0x0f) - (w & 0x0f)) & 0x10) ? DC : 0; set_status( c | dc, (c^C) | (dc^DC) ); } static void exXORLW( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; int w, l, xor; w = get_w( ); l = instr & 0xff; xor = w ^ l; set_w( xor, True ); } static void exOPTION( void ) { set_f( 1, 1, get_w(), False ); } static void exTRIS( void ) { int instr = Pic.uinfo.picmemmap[ Pic.pc ]; switch (instr & 7) { case 5: case 6: set_f( 1, instr & 7, get_w(), False ); break; default: // fixme! what does this do? break; } } static pic16c84_instr PIC16C84_INSTR[] = { { 0x3f00, 0x0000, 0x0700, 0x0000, 1, 1, 0, "ADDWF ", exADDWF }, { 0x3f00, 0x0000, 0x0500, 0x0000, 1, 1, 0, "ANDWF ", exANDWF }, { 0x3f80, 0x0000, 0x0180, 0x0000, 0, 1, 0, "CLRF ", exCLRF }, { 0x3f80, 0x007f, 0x0100, 0x0000, 0, 0, 0, "CLRW ", exCLRW }, { 0x3f00, 0x0000, 0x0900, 0x0000, 1, 1, 0, "COMF ", exCOMF }, { 0x3f00, 0x0000, 0x0300, 0x0000, 1, 1, 0, "DECF ", exDECF }, { 0x3f00, 0x0000, 0x0b00, 0x0000, 1, 1, 0, "DECFSZ", exDECFSZ }, { 0x3f00, 0x0000, 0x0a00, 0x0000, 1, 1, 0, "INCF ", exINCF }, { 0x3f00, 0x0000, 0x0f00, 0x0000, 1, 1, 0, "INCFSZ", exINCFSZ }, { 0x3f00, 0x0000, 0x0400, 0x0000, 1, 1, 0, "IORWF ", exIORWF }, { 0x3f00, 0x0000, 0x0800, 0x0000, 1, 1, 0, "MOVF ", exMOVF }, { 0x3f80, 0x0000, 0x0080, 0x0000, 0, 1, 0, "MOVWF ", exMOVWF }, { 0x3f9f, 0x0060, 0x0000, 0x0000, 0, 0, 0, "NOP ", exNOP }, { 0x3f00, 0x0000, 0x0d00, 0x0000, 1, 1, 0, "RLF ", exRLF }, { 0x3f00, 0x0000, 0x0c00, 0x0000, 1, 1, 0, "RRF ", exRRF }, { 0x3f00, 0x0000, 0x0200, 0x0000, 1, 1, 0, "SUBWF ", exSUBWF }, { 0x3f00, 0x0000, 0x0e00, 0x0000, 1, 1, 0, "SWAPF ", exSWAPF }, { 0x3f00, 0x0000, 0x0600, 0x0000, 1, 1, 0, "XORWF ", exXORWF }, { 0x3c00, 0x0000, 0x1000, 0x0000, 0, 1, 1, "BCF ", exBCF }, { 0x3c00, 0x0000, 0x1400, 0x0000, 0, 1, 1, "BSF ", exBSF }, { 0x3c00, 0x0000, 0x1800, 0x0000, 0, 1, 1, "BTFSC ", exBTFSC }, { 0x3c00, 0x0000, 0x1c00, 0x0000, 0, 1, 1, "BTFSS ", exBTFSS }, { 0x3e00, 0x0100, 0x3e00, 0x00ff, 0, 0, 0, "ADDLW ", exADDLW }, { 0x3F00, 0x0000, 0x3900, 0x00ff, 0, 0, 0, "ANDLW ", exANDLW }, { 0x3800, 0x0000, 0x2000, 0x07ff, 0, 0, 0, "CALL ", exCALL }, { 0x3fff, 0x0000, 0x0064, 0x0000, 0, 0, 0, "CLRWDT", exCLRWDT }, { 0x3800, 0x0000, 0x2800, 0x07ff, 0, 0, 0, "GOTO ", exGOTO }, { 0x3f00, 0x0000, 0x3800, 0x00ff, 0, 0, 0, "IORLW ", exIORLW }, { 0x3c00, 0x0300, 0x3000, 0x00ff, 0, 0, 0, "MOVLW ", exMOVLW }, { 0x3fff, 0x0000, 0x0009, 0x0000, 0, 0, 0, "RETFIE", exRETFIE }, { 0x3c00, 0x0300, 0x3400, 0x00ff, 0, 0, 0, "RETLW ", exRETLW }, { 0x3fff, 0x0000, 0x0008, 0x0000, 0, 0, 0, "RETURN", exRETURN }, { 0x3fff, 0x0000, 0x0063, 0x0000, 0, 0, 0, "SLEEP ", exSLEEP }, { 0x3e00, 0x0100, 0x3c00, 0x00ff, 0, 0, 0, "SUBLW ", exSUBLW }, { 0x3f00, 0x0000, 0x3a00, 0x00ff, 0, 0, 0, "XORLW ", exXORLW }, { 0x3fff, 0x0000, 0x0062, 0x0000, 0, 0, 0, "OPTION", exOPTION }, { 0x3ff8, 0x0000, 0x0060, 0x0007, 0, 0, 0, "TRIS ", exTRIS } } ; static int match_instr( u_int instr ) { const int ninstr = sizeof(PIC16C84_INSTR)/sizeof(PIC16C84_INSTR[0]); int i; pic16c84_instr *tmpl; for (i = 0; i < ninstr; i++) { tmpl = PIC16C84_INSTR + i; if ((instr & ~tmpl->dont_care & tmpl->mask) == tmpl->discriminator) break; } return ((i >= ninstr) ? -1 : i); } nitpic-0.1.orig/Imakefile100444 10333 10333 2027 5713616260 13612 0ustar kleeklee/* * Imakefile for picsim */ SRCS = main.cc \ ic.cc \ info.cc \ instr.cc \ pu_lib.c \ reg.cc \ sim.cc \ util.cc \ 16c84.cc OBJS = main.o \ ic.o \ info.o \ instr.o \ pu_lib.o \ reg.o \ sim.o \ util.o \ 16c84.o EXTRA_INCLUDES = -I./lib/X11 CDEBUGFLAGS = CCOPTIONS = C++FLAGS = $(CFLAGS) $(CDEBUGFLAGS) CXXFLAGS = $(C++FLAGS) LDFLAGS = $(CDEBUGFLAGS) INCLUDES = -I$(TOP) -I$(TOOLKITSRC) LOCAL_LIBRARIES = $(XAWLIB) $(XEXTLIB) $(XMULIB) $(XTOOLLIB) $(XLIB) SYS_LIBRARIES = -lm -lc GCC_INCLUDE = $(shell dirname `gcc -print-libgcc-file-name`)/include DEPENDFLAGS = -I/usr/local/lib/g++-include \ -I/usr/lib/g++-include \ -I$(GCC_INCLUDE) \ $(EXTRA_INCLUDES) all:: nitpic ComplexProgramTarget(nitpic) /* * The following is a matter of preference: * * InstallManPage(template,$(MANDIR)) * InstallProgram(template,$(BINDIR)) */ nitpic-0.1.orig/LICENSE100444 10333 10333 16727 5756405006 13043 0ustar kleeklee NITPIC GENERAL PUBLIC LICENSE (Clarified 11 Feb 1988) Copyright (C) 1994 Dave Madden Everyone is permitted to copy and distribute verbatim copies of this license, but changing it is not allowed. You can also use this wording to make the terms for other programs. The license agreements of most software companies keep you at the mercy of those companies. By contrast, our general public license is intended to give everyone the right to share nitpic. To make sure that you get the rights we want you to have, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. Hence this license agreement. Specifically, we want to make sure that you have the right to give away copies of nitpic, that you receive source code or else can get it if you want it, that you can change nitpic or use pieces of it in new free programs, and that you know you can do these things. To make sure that everyone has such rights, we have to forbid you to deprive anyone else of these rights. For example, if you distribute copies of nitpic, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. Also, for our own protection, we must make certain that everyone finds out that there is no warranty for nitpic. If nitpic is modified by someone else and passed on, we want its recipients to know that what they have is not what we distributed, so that any problems introduced by others will not reflect on our reputation. Therefore we (Dave Madden and Software Fools International) make the following terms which say what you must do to be allowed to distribute or change nitpic. COPYING POLICIES 1. You may copy and distribute verbatim copies of nitpic source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy a valid copyright notice "Copyright (C) 1994 Software Fools International" (or with whatever year is appropriate); keep intact the notices on all files that refer to this License Agreement and to the absence of any warranty; and give any other recipients of the nitpic program a copy of this License Agreement along with the program. You may charge a distribution fee for the physical act of transferring a copy. 2. You may modify your copy or copies of nitpic source code or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains or is a derivative of nitpic or any part thereof, to be licensed at no charge to all third parties on terms identical to those contained in this License Agreement (except that you may choose to grant more extensive warranty protection to some or all third parties, at your option). c) if the modified program serves as a text editor, cause it when started running in the simplest and usual way, to print an announcement including a valid copyright notice "Copyright (C) 1994 Software Fools International" (or with the year that is appropriate), saying that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License Agreement. d) You may charge a distribution fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another unrelated program with this program (or its derivative) on a volume of a storage or distribution medium does not bring the other program under the scope of these terms. 3. You may copy and distribute nitpic (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal shipping charge) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs. 4. You may not copy, sublicense, distribute or transfer nitpic except as expressly provided under this License Agreement. Any attempt otherwise to copy, sublicense, distribute or transfer nitpic is void and your rights to use nitpic under this License agreement shall be automatically terminated. However, parties who have received computer software programs from you with this License Agreement will not have their licenses terminated so long as such parties remain in full compliance. 5. If you wish to incorporate parts of nitpic into other free programs whose distribution conditions are different, write to Software Fools International. We have not yet worked out a simple rule that can be stated here, but we will often permit this. We will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software. Your comments and suggestions about our licensing policies and our software are welcome! Please contact Software Fools International at dhm@vheissu.iii.net or call [+1](508)872-9858. NO WARRANTY BECAUSE NITPIC IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING, SOFTWARE FOOLS INTERNATIONAL AND/OR OTHER PARTIES PROVIDE NITPIC "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE NITPIC PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL SOFTWARE FOOLS INTERNATIONAL AND/OR ANY OTHER PARTY WHO MAY MODIFY AND REDISTRIBUTE NITPIC AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH PROGRAMS NOT DISTRIBUTED BY SOFTWARE FOOLS INTERNATIONAL) THE PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. nitpic-0.1.orig/README100444 10333 10333 3436 5661134606 12667 0ustar kleeklee nitpic: a Microchip PIC simulator This program is an X Windows-based simulator for the Microchip PIC series of microcontrollers. It's written in C++ and is known to compile correctly with gcc-2.5.8 under Linux and SunOS4.1.3U. This is an alpha release, with many known incompletenesses and suspected bugs, as well as a great deal of cruft that I plan to clean up before beta. It currently supports the PIC16C84 only, but I have kept other processors in mind while coding, and I think it will be trivial to add support for the rest of the PIC family, and pretty easy even for unrelated CPUs. I'd appreciate hearing about problems you may have, as well as suggestions for improvements. I'll be away on business for the next two weeks, but plan to continue working on this when I return. dave madden 12-nov-94 Known shortcomings: * The 16C84 EEPROM data memory is not implemented * Writing PCL doesn't cause a jump * Interrupts, including RTCC rollover, don't work * The "File" button doesn't let you load a new object file * No warning on stack overflow * The I/O ports aren't handled properly (there's something screwy about read/modify/write instructions that I don't understand yet). * I'm not sure the ADD and SUB instructions set C and DC properly. Bugs: * Sometimes the instruction pointer gets screwed up (graphics only -- the simulator keeps working) Futures: * "LEDs" to indicate IC pin states * Logic traces of IC pin states * Breakpoints * Some method to provide input signals * Change 16C84 simulator to use an "instruction prefetch" cycle. Jumps will replace the prefetched instruction with a NOP, which will be executed while the jump target instruction is being fetched. (This is how the real thing works, isn't it?) * Add simulators for other PICs nitpic-0.1.orig/XPICsim100444 10333 10333 11325 5707743671 13233 0ustar kleeklee! ! App defaults file for X PIC simulator ! *XPICsim.nitpic-resources: true *XPICsim.synchronous: true *XPICsim*background: gray90 *XPICsim*Command.background: white *XPICsim*Toggle.background: white *XPICsim.main.background: gray50 *XPICsim.main.title.background: blue *XPICsim.main.title.foreground: white *XPICsim.main.copyright.background: blue *XPICsim.main.copyright.foreground: aquamarine *XPICsim.main.info.foreground: black *XPICsim.main.info.background: gray90 *XPICsim.main.instr.ipointer.background: gray90 *XPICsim.main.instr.ipointer.foreground: black *XPICsim.main.instr.itext.background: gray90 *XPICsim.main.instr.iscroll.background: gray90 *XPICsim.main.instr.iscroll.foreground: black *XPICsim.main.regs.rpage.background: white *XPICsim.led-on: green *XPICsim.led-off: black *XPICsim.wdt-color-1: green *XPICsim.wdt-color-2: yellow *XPICsim.wdt-color-3: red *XPICsim.wdt-min: 7e-3 *XPICsim.wdt-nominal: 18e-3 *XPICsim.wdt-max: 33e-3 *XPICsim*font: -adobe-helvetica-medium-r-*-*-11-* *XPICsim.info-bits: -misc-fixed-medium-r-normal--10-100-75-75-c-60-iso8859-1 *XPICsim*Label.font: -adobe-helvetica-bold-o-normal--12-120-75-75-p-69-iso8859-1 *XPICsim*Label.height: 22 *XPICsim*Label.width: 93 *XPICsim*Command.font: -adobe-helvetica-bold-o-normal--12-120-75-75-p-69-iso8859-1 *XPICsim*Command.height: 22 *XPICsim*Command.width: 93 *XPICsim*Toggle.font: -adobe-helvetica-bold-o-normal--12-120-75-75-p-69-iso8859-1 *XPICsim*Toggle.height: 22 *XPICsim*Toggle.width: 93 *XPICsim.main.title.height: 24 *XPICsim.main.title.width: 240 *XPICsim.main.title.font: -adobe-helvetica-bold-o-normal-*-*-180-* *XPICsim.main.copyright.height: 24 *XPICsim.main.copyright.width: 240 *XPICsim.main.copyright.font: -adobe-helvetica-medium-o-normal-*-*-100-* *XPICsim.main.info.height: 180 *XPICsim.main.info.width: 240 *XPICsim.main.info.font: -adobe-helvetica-*-r-*-*-14-*-*-*-*-*-*-* *XPICsim.main.info.translations: #override \n\ : info-refresh() *XPICsim.main.ic.height: 150 *XPICsim.main.ic.width: 240 *XPICsim.main.ic.font: -misc-fixed-medium-*-*-*-7-* *XPICsim.main.ic.translations: #override \n\ : ic-refresh() *XPICsim.main.instr.defaultDistance: 0 *XPICsim.main.instr.ipointer.height: 396 *XPICsim.main.instr.ipointer.width: 20 *XPICsim.main.instr.ipointer.borderWidth: 0 *XPICsim.main.instr.ipointer.bitmap: pointer.xbm *XPICsim.main.instr.ipointer.label: *XPICsim.main.instr.ipointer.translations: #replace \n\ : ipointer-refresh() \n\ ,: ipointer-seek() *XPICsim.main.instr.itext.height: 396 *XPICsim.main.instr.itext.width: 142 *XPICsim.main.instr.itext.borderWidth: 0 *XPICsim.main.instr.itext.translations: #override \n\ : instr-refresh() *XPICsim.main.instr.itext.font: -misc-fixed-medium-r-normal--10-100-75-75-c-60-iso8859-1 *XPICsim.main.instr.iscroll.orientation: vertical *XPICsim.main.instr.iscroll.height: 396 *XPICsim.main.instr.iscroll.width: 18 *XPICsim.main.instr.iscroll.borderWidth: 0 *XPICsim.main.regs.height: 118 *XPICsim.main.regs.width: 150 *XPICsim.main.regs.rprev.width: 22 *XPICsim.main.regs.rprev.height: 20 *XPICsim.main.regs.rprev.bitmap: larrow.xbm *XPICsim.main.regs.rprev.translations: #override \n\ : reg-switch( prev ) notify() unset() *XPICsim.main.regs.rpage.width: 90 *XPICsim.main.regs.rpage.height: 20 *XPICsim.main.regs.rnext.width: 22 *XPICsim.main.regs.rnext.height: 20 *XPICsim.main.regs.rnext.bitmap: rarrow.xbm *XPICsim.main.regs.rnext.translations: #override \n\ : reg-switch( next ) notify() unset() *XPICsim.main.regs.rdata.width: 146 *XPICsim.main.regs.rdata.height: 244 *XPICsim.main.regs.rdata.font: -misc-fixed-medium-r-normal--10-100-75-75-c-60-iso8859-1 *XPICsim.main.regs.rdata.translations: #override \n\ : reg-refresh() *XPICsim.main.data.height: 110 *XPICsim.main.data.width: 156 *XPICsim.main.reset.label: Reset *XPICsim.main.reset.translations: #override \n\ : notify() sim-reset() unset() *XPICsim.main.step.label: Step *XPICsim.main.step.translations: #override \n\ : notify() sim-step() unset() *XPICsim.main.run.label: Run *XPICsim.main.run.translations: #override \n\ ,: toggle() toggle-run() notify() *XPICsim.main.int.label: Interrupt *XPICsim.main.file.label: File *XPICsim.main.file.translations: #override \n\ : notify() load-file() unset() *XPICsim.main.quit.label: Quit *XPICsim.main.quit.translations: #override \n\ : notify() quit() unset() *XPICsim.main.translations: #replace \n\ q: quit() \n\ s: sim-step() \n\ r: toggle-run() nitpic-0.1.orig/ic.cc100444 10333 10333 7715 5661420542 12712 0ustar kleeklee/* * ic.cc -- functions to handle stuff in the IC window */ #include "picsim.hh" static GC ic_gc = None; static XFontStruct *ic_font; void ic_refresh( Widget w, XEvent *ev, String *prms, Cardinal *nprm ) { XGCValues xgcv; Dimension w_height, w_width; Dimension ic_height, ic_width, pin_len, pin_loc, pin_dv; int i, j, k; pins_info *p; SimAR a; if (ic_gc == None) { Pixel fg, bg; XtVaGetValues( W.ic, XtNforeground, &fg, XtNbackground, &bg, XtNfont, &ic_font, NULL ); xgcv.foreground = fg; xgcv.background = bg; xgcv.font = ic_font->fid; ic_gc = XCreateGC( XtDisplay(W.ic), XtWindow(W.ic), GCForeground | GCBackground | GCFont, &xgcv ); } a = Pic.simulate( GetPins, a ); p = (pins_info *)a.p; if (!p->npins) return; XtVaGetValues( W.ic, XtNheight, &w_height, XtNwidth, &w_width, NULL ); pin_dv = w_height / (p->npins / 2 + 2); if (pin_dv > 20) pin_dv = 20; ic_height = pin_dv * p->npins / 2; ic_width = ic_height * 2 / 3; if (ic_width < 8 || ic_width > w_width) ic_width = 4 * w_width / 5; XDrawRectangle( XtDisplay(W.ic), XtWindow(W.ic), ic_gc, (w_width - ic_width) / 2, (w_height - ic_height) / 2, ic_width, ic_height ); pin_len = (w_width - ic_width) / 4; if (pin_len >16) pin_len = 16; pin_loc = (w_height - ic_height + pin_dv) / 2; for (i = 0; i < p->npins / 2; i++) { XDrawLine( XtDisplay(W.ic), XtWindow(W.ic), ic_gc, (w_width - ic_width) / 2, pin_loc, (w_width - ic_width) / 2 - pin_len, pin_loc ); XDrawImageString( XtDisplay(W.ic), XtWindow(W.ic), ic_gc, (w_width - ic_width) / 2 + 2, pin_loc + ic_font->ascent / 2, p->pins[i].pin_name, strlen( p->pins[i].pin_name ) ); XDrawLine( XtDisplay(w), XtWindow(w), ic_gc, (w_width + ic_width) / 2, pin_loc, (w_width + ic_width) / 2 + pin_len, pin_loc ); j = strlen( p->pins[p->npins - i - 1].pin_name ); k = XTextWidth( ic_font, p->pins[p->npins - i - 1].pin_name, j ); XDrawImageString( XtDisplay(W.ic), XtWindow(W.ic), ic_gc, (w_width + ic_width) / 2 - k, pin_loc + ic_font->ascent / 2, p->pins[p->npins - i - 1].pin_name, j ); pin_loc += pin_dv; } ic_update( ); } void ic_update( void ) { XGCValues xgcv; Dimension w_height, w_width; Dimension ic_height, ic_width, pin_len, pin_loc, pin_dv; int i, j; pins_info *p; SimAR a; Pixmap arrow; a = Pic.simulate( GetPins, a ); p = (pins_info *)a.p; if (!p || !p->npins) return; XtVaGetValues( W.ic, XtNheight, &w_height, XtNwidth, &w_width, NULL ); pin_dv = w_height / (p->npins / 2 + 2); if (pin_dv > 20) pin_dv = 20; ic_height = pin_dv * p->npins / 2; ic_width = ic_height * 2 / 3; if (ic_width < 8 || ic_width > w_width) ic_width = 4 * w_width / 5; pin_len = (w_width - ic_width) / 4; if (pin_len >16) pin_len = 16; pin_loc = (w_height - ic_height + pin_dv) / 2; for (i = 0; i < p->npins / 2; i++) { if (p->pins[i].io == 0) arrow = Options.right_hollow; else if (p->pins[i].io == 1) arrow = Options.left_pointer; else arrow = None; if (arrow != None) { xgcv.foreground = ((p->pins[i].hi) ? Options.led_on : Options.led_off); XChangeGC( XtDisplay(W.ic), ic_gc, GCForeground, &xgcv ); XCopyPlane( XtDisplay(W.ic), arrow, XtWindow(W.ic), ic_gc, 0, 0, 8, 8, (w_width - ic_width) / 2 - pin_len - 2, pin_loc - 3, 1 ); } j = p->npins - i - 1; if (p->pins[j].io == 0) arrow = Options.left_hollow; else if (p->pins[j].io == 1) arrow = Options.right_pointer; else arrow = None; if (arrow != None) { xgcv.foreground = ((p->pins[j].hi) ? Options.led_on : Options.led_off); XChangeGC( XtDisplay(W.ic), ic_gc, GCForeground, &xgcv ); XCopyPlane( XtDisplay(W.ic), arrow, XtWindow(W.ic), ic_gc, 0, 0, 8, 8, (w_width + ic_width) / 2 + pin_len + 1, pin_loc - 3, 1 ); } pin_loc += pin_dv; } } nitpic-0.1.orig/info.cc100444 10333 10333 15553 5661107435 13274 0ustar kleeklee/* * info.cc -- handle the info window */ #include "picsim.hh" static GC info_text_gc = None; static GC info_wdt_gc = None; static GC info_bits_gc = None; static GC info_led_gc = None; static XFontStruct *info_big_font = None; static XFontStruct *info_little_font = None; /* * Refresh the Info window -- display all the static text strings. * Call info_update to draw the variable portions. */ void info_refresh( Widget w, XEvent *ev, String *prms, Cardinal *nprm ) { XGCValues xgcv; Dimension w_height, w_width; int i, j, k, bl, dv; if (info_text_gc == None) { // allocate GCs the first time around XtVaGetValues( W.info, XtNforeground, &xgcv.foreground, XtNbackground, &xgcv.background, XtNfont, &info_big_font, NULL ); xgcv.font = info_big_font->fid; info_text_gc = XtGetGC( W.info, GCForeground | GCBackground | GCFont, &xgcv ); info_wdt_gc = XCreateGC( XtDisplay(W.info), XtWindow(W.info), GCBackground, &xgcv ); info_little_font = Options.info_bits; xgcv.font = info_little_font->fid; info_bits_gc = XtGetGC( W.info, GCForeground | GCBackground | GCFont, &xgcv ); xgcv.line_width = ( info_big_font->ascent + info_big_font->descent - info_little_font->ascent - 2); if (xgcv.line_width < 0) xgcv.line_width = 0; info_led_gc = XCreateGC( XtDisplay(W.info), XtWindow(W.info), GCLineWidth, &xgcv ); } XtVaGetValues( W.info, XtNheight, &w_height, XtNwidth, &w_width, NULL ); bl = 2 + info_big_font->ascent; dv = info_big_font->ascent + info_big_font->descent; XDrawImageString( XtDisplay(W.info), XtWindow(W.info), info_text_gc, 2, bl, "Time", 4 ); bl += dv; XDrawImageString( XtDisplay(W.info), XtWindow(W.info), info_text_gc, 2, bl, "Ticks", 5 ); bl += dv; XDrawImageString( XtDisplay(W.info), XtWindow(W.info), info_text_gc, 2, bl, "WDT", 3 ); i = XTextWidth( info_big_font, "WDT", 3 ) + 2 + 10; // WDT bar start X j = w_width - i - 10; // wdt bar length XDrawRectangle( XtDisplay(W.info), XtWindow(W.info), info_text_gc, i, bl - info_big_font->ascent, j, info_big_font->ascent + 1 ); xgcv.foreground = Options.wdt_color_1; XChangeGC( XtDisplay(W.info), info_wdt_gc, GCForeground, &xgcv ); XFillRectangle( XtDisplay(W.info), XtWindow(W.info), info_wdt_gc, i + 1, bl - info_big_font->ascent + 1, j - 1, info_big_font->ascent ); k = (int)((float)j * (Pic.wdt_max - Pic.wdt_min) / Pic.wdt_max); if (k) { xgcv.foreground = Options.wdt_color_2; XChangeGC( XtDisplay(W.info), info_wdt_gc, GCForeground, &xgcv ); XFillRectangle( XtDisplay(W.info), XtWindow(W.info), info_wdt_gc, i + 1, bl - info_big_font->ascent + 1, k, info_big_font->ascent ); } k = (int)((float)j * (Pic.wdt_max - Pic.wdt_nominal) / Pic.wdt_max); if (k) { xgcv.foreground = Options.wdt_color_3; XChangeGC( XtDisplay(W.info), info_wdt_gc, GCForeground, &xgcv ); XFillRectangle( XtDisplay(W.info), XtWindow(W.info), info_wdt_gc, i + 1, bl - info_big_font->ascent + 1, k, info_big_font->ascent ); } bl += dv; if (Pic.simulate != NULL) { info_reg *regs; SimAR a = Pic.simulate( GetInfo, a ); if ((regs = (info_reg *)a.p) != NULL) { char *cp; while (cp = regs->reg_name) { regs->old_value = ~regs->value; XDrawImageString( XtDisplay(W.info), XtWindow(W.info), info_text_gc, 2, bl, cp, strlen( cp ) ); i = XTextWidth( info_big_font, cp, strlen( cp ) ); j = bl - info_big_font->ascent * 2 / 3; XDrawLine( XtDisplay(W.info), XtWindow(W.info), info_text_gc, i + 4, j, w_width - 10, j ); i = (w_width - 10) / 8; for (j = 0; j < 8; j++) { k = XTextWidth( info_little_font, regs->bit_names[j], strlen( regs->bit_names[j] ) ) / 2; XDrawImageString( XtDisplay(W.info), XtWindow(W.info), info_bits_gc, i / 2 + i * j - k + 5, ( bl + info_big_font->descent + info_little_font->ascent), regs->bit_names[j], strlen( regs->bit_names[j] ) ); } bl += dv << 1; regs += 1; } } } info_update( ); } void info_update( void ) { XGCValues xgcv; Dimension w_height, w_width; int i, j, k, bl, dv; info_quick( ); XtVaGetValues( W.info, XtNheight, &w_height, XtNwidth, &w_width, NULL ); dv = info_big_font->ascent + info_big_font->descent; bl = 2 + info_big_font->ascent + dv * 3; if (Pic.simulate != NULL) { info_reg *regs; SimAR a = Pic.simulate( GetInfo, a ); if ((regs = (info_reg *)a.p) != NULL) { char *cp; i = (w_width - 10) / 8; while (cp = regs->reg_name) { bl += dv; xgcv.foreground = Options.led_on; XChangeGC(XtDisplay(W.info),info_led_gc,GCForeground,&xgcv); for (j = 0; j < 8; j++) { k = 0x80 >> j; if (!(regs->value & k) || (regs->old_value & k)) continue; k = i * 8 / 10; XDrawLine( XtDisplay(W.info), XtWindow(W.info), info_led_gc, i/2 + i*j - k/2 + 5, bl, i/2 + i*j + k/2 + 5, bl ); } xgcv.foreground = Options.led_off; XChangeGC(XtDisplay(W.info),info_led_gc,GCForeground,&xgcv); for (j = 0; j < 8; j++) { k = 0x80 >> j; if ((regs->value & k) || !(regs->old_value & k)) continue; k = i * 8 / 10; XDrawLine( XtDisplay(W.info), XtWindow(W.info), info_led_gc, i/2 + i*j - k/2 + 5, bl, i/2 + i*j + k/2 + 5, bl ); } regs->old_value = regs->value; bl += dv; regs += 1; } } } } /* * Update the elapsed time, ticks, and WDT items */ void info_quick( void ) { XGCValues xgcv; Dimension w_height, w_width; int i, j, k, bl, dv; u_long ms, sec, min, hr; char buf[32]; XtVaGetValues( W.info, XtNheight, &w_height, XtNwidth, &w_width, NULL ); bl = 2 + info_big_font->ascent; dv = info_big_font->ascent + info_big_font->descent; ms = Pic.millisec; hr = ms / (1000 * 60 * 60); ms -= hr * 100 * 60 * 60; min = ms / (1000 * 60); ms -= min * 1000 * 60; sec = ms / (1000); ms -= sec * 1000; sprintf( buf, "%lu:%02lu:%02lu.%03lu", hr, min, sec, ms ); i = strlen( buf ); j = XTextWidth( info_big_font, buf, i ); XDrawImageString( XtDisplay(W.info), XtWindow(W.info), info_text_gc, w_width - j - 10, bl, buf, i ); bl += dv; sprintf( buf, "%lu", Pic.ticks ); i = strlen( buf ); j = XTextWidth( info_big_font, buf, i ); XDrawImageString( XtDisplay(W.info), XtWindow(W.info), info_text_gc, w_width - j - 10, bl, buf, i ); bl += dv; i = XTextWidth( info_big_font, "WDT", 3 ) + 2 + 10; // WDT bar start X j = w_width - i - 10; // wdt bar length k = (int)((float)j * ((float)Pic.wdt_left * 4.0 / Pic.uinfo.clock) / Pic.wdt_max) + 1; if (k < j) { XClearArea( XtDisplay(W.info), XtWindow(W.info), i + k, bl - info_big_font->ascent + 1, j - k, info_big_font->ascent, False ); } } nitpic-0.1.orig/instr.cc100444 10333 10333 12621 5661046160 13466 0ustar kleeklee/* * instr.cc -- routines to handle the instr window */ #include "picsim.hh" void instr_refresh( Widget w, XEvent *ev, String *prms, Cardinal *nprm ) { GC gc; XGCValues xgcv; XFontStruct *xfsp; Dimension w_height, w_width; Pixmap pointer_pixmap; char buf[32]; int i, j, k, p, dv; XtVaGetValues( W.itext, XtNforeground, &xgcv.foreground, XtNbackground, &xgcv.background, XtNheight, &w_height, XtNwidth, &w_width, XtNfont, &xfsp, NULL ); xgcv.font = xfsp->fid; gc = XCreateGC( XtDisplay(W.itext), XtWindow(W.itext), GCForeground | GCBackground | GCFont, &xgcv ); p = Pic.itop; dv = xfsp->ascent + xfsp->descent; for (i = dv; i < w_height; i += dv) { SimAR a; if (p > Pic.isize) { XClearArea( XtDisplay(W.itext), XtWindow(W.itext), 0, i, w_width, w_height, False ); break; } a.i = p++; a = Pic.simulate( Disassemble, a ); j = strlen( (char *)a.p ); k = XTextWidth( xfsp, (char *)a.p, j ); XDrawImageString( XtDisplay(W.itext), XtWindow(W.itext), gc, 2, i, (char *)(a.p), j ); XClearArea( XtDisplay(W.itext), XtWindow(W.itext), 2 + k, i - xfsp->ascent, w_width, dv, False ); } XFreeGC( XtDisplay(W.itext), gc ); } /* * Scroll the instruction area in response to a btn1 or btn3 click */ void instr_scroll( Widget w, XtPointer client_data, XtPointer position ) { Dimension w_width, w_height; XFontStruct *xfsp; int dv, top, lines; float thumb; XtVaGetValues( W.iscroll, XtNheight, &w_height, NULL ); XtVaGetValues( W.itext, XtNfont, &xfsp, NULL ); dv = xfsp->ascent + xfsp->descent; lines = w_height / dv; top = Pic.itop + lines * (int)position / w_height; if (top < 0) top = 0; else if (top + lines > Pic.isize) top = Pic.isize - lines; if (top == Pic.itop) return; /* nothing to do */ thumb = (float)top / (float)(Pic.isize - lines); XawScrollbarSetThumb( W.iscroll, thumb, -1.0 ); instr_jump( w, client_data, &thumb ); } /* * Scroll the instruction area in response to btn2 in scroll bar */ void instr_jump( Widget w, XtPointer client_data, XtPointer position ) { Dimension w_width, w_height; XFontStruct *xfsp; int dv, top, bottom, lines, dlines; float thumb; XtVaGetValues( W.iscroll, XtNheight, &w_height, NULL ); XtVaGetValues( W.itext, XtNfont, &xfsp, NULL ); dv = xfsp->ascent + xfsp->descent; lines = w_height / dv; top = (int)((float)(Pic.isize - lines) * *(float *)position); ipointer_erase( ); Pic.itop = top; ipointer_refresh( W.ipointer, NULL, NULL, NULL ); instr_refresh( W.itext, NULL, NULL, NULL ); } static unsigned ipointer_height = 16; /* * Erase the instruction pointer (if it's visible) * Return whether or not it was visible. */ Boolean ipointer_erase( void ) { Dimension w_width, w_height; XFontStruct *xfsp; int dv, top, bottom; XtVaGetValues( W.itext, XtNfont, &xfsp, NULL ); dv = xfsp->ascent + xfsp->descent; XtVaGetValues( W.ipointer, XtNwidth, &w_width, XtNheight, &w_height, NULL ); top = (Pic.pc - Pic.itop) * dv - 1; bottom = top + ipointer_height; if (bottom < 0 || top > w_height) return False; XClearArea( XtDisplay(W.ipointer), XtWindow(W.ipointer), 0, (Pic.pc - Pic.itop) * dv - 2, w_width, ipointer_height, False ); return True; } void ipointer_refresh( Widget w, XEvent *ev, String *prms, Cardinal *nprm ) { GC gc; XGCValues xgcv; Dimension w_height, w_width; static Pixmap pointer_pixmap = None; XFontStruct *xfsp; int dv; XtVaGetValues( W.itext, XtNfont, &xfsp, NULL ); dv = xfsp->ascent + xfsp->descent; XtVaGetValues( W.ipointer, XtNforeground, &xgcv.foreground, XtNbackground, &xgcv.background, NULL ); if (pointer_pixmap == None) { XtVaGetValues( W.ipointer, XtNbitmap, &pointer_pixmap, NULL ); XtVaSetValues( W.ipointer, XtNbitmap, (XtPointer)None, NULL ); if (pointer_pixmap != None) { Window who_cares_win; int who_cares_int; u_int who_cares_unsigned; XGetGeometry( XtDisplay(W.ipointer), pointer_pixmap, &who_cares_win, &who_cares_int, &who_cares_int, &who_cares_unsigned, &ipointer_height, &who_cares_unsigned, &who_cares_unsigned ); } } gc = XCreateGC( XtDisplay(W.ipointer), XtWindow(W.ipointer), GCForeground | GCBackground, &xgcv ); XCopyPlane( XtDisplay(W.ipointer), pointer_pixmap, XtWindow(W.ipointer), gc, 0, 0, 16, 16, 2, (Pic.pc - Pic.itop) * dv - 1, 1 ); XFreeGC( XtDisplay(W.ipointer), gc ); } /* * If the instruction pointer is off-screen, scroll so that it's about * 1/4 way down. */ void ipointer_seek( Widget w, XEvent *ev, String *prms, Cardinal *nprm ) { Dimension w_width, w_height; XFontStruct *xfsp; int dv, top, bottom, lines, dlines; float thumb; XtVaGetValues( W.iscroll, XtNheight, &w_height, NULL ); XtVaGetValues( W.itext, XtNfont, &xfsp, NULL ); dv = xfsp->ascent + xfsp->descent; lines = w_height / dv; if (Pic.pc >= Pic.itop && Pic.pc < Pic.itop + lines - 3) return; top = Pic.pc - lines / 4; if (top < 0) top = 0; else if (top + lines > Pic.isize) top = Pic.isize - lines; ipointer_erase( ); Pic.itop = top; ipointer_refresh( W.ipointer, NULL, NULL, NULL ); instr_refresh( W.itext, NULL, NULL, NULL ); XawScrollbarSetThumb( W.iscroll, (float)top / (float)(Pic.isize - lines), -1.0 ); } nitpic-0.1.orig/larrow.xbm100444 10333 10333 442 5660033323 13770 0ustar kleeklee#define larrow_width 16 #define larrow_height 16 static unsigned char larrow_bits[] = { 0x00, 0x00, 0x40, 0x00, 0x60, 0x00, 0x70, 0x00, 0xf8, 0x7f, 0xfc, 0x7f, 0xfe, 0x7f, 0xff, 0x7f, 0xfe, 0x7f, 0xfc, 0x7f, 0xf8, 0x7f, 0x70, 0x00, 0x60, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00}; nitpic-0.1.orig/lhollow.xbm100444 10333 10333 204 5661254536 14152 0ustar kleeklee#define lhollow_width 8 #define lhollow_height 8 static char lhollow_bits[] = { 0xc0, 0xb0, 0x8c, 0x83, 0x8c, 0xb0, 0xc0, 0x00}; nitpic-0.1.orig/lsolid.xbm100444 10333 10333 201 5661254567 13761 0ustar kleeklee#define lsolid_width 8 #define lsolid_height 8 static char lsolid_bits[] = { 0xc0, 0xf0, 0xfc, 0xff, 0xfc, 0xf0, 0xc0, 0x00}; nitpic-0.1.orig/main.cc100444 10333 10333 23021 5707744467 13267 0ustar kleeklee/* * main.cc -- PIC simulator main routine */ #define __main__ #include "picsim.hh" static String fallback_resources[] = { "*XPICsim*quit.translations: #override " " : notify() unset() quit()", NULL } ; static volatile void xusage( void ); static void copyright( Widget w, XtPointer closure, XtPointer call_data ); static void echo( Widget w, XEvent *ev, String *prms, Cardinal *nprm ); static void quit( Widget w, XEvent *ev, String *prms, Cardinal *nprm ); static XtActionsRec actions[] = { { "echo", echo }, { "ic-refresh", ic_refresh }, { "info-refresh", info_refresh }, { "ipointer-refresh", ipointer_refresh }, { "ipointer-seek", ipointer_seek }, { "instr-refresh", instr_refresh }, { "load-file", load_file }, { "quit", quit }, { "reg-refresh", reg_refresh }, { "reg-switch", reg_switch }, { "sim-step", sim_step }, { "sim-reset", sim_reset }, { "toggle-run", sim_toggle_run } } ; #define Offset(field) XtOffsetOf(OptionsRec, field) static XtResource resources[] = { { "nitpic-resources", "NitpicResources", XtRBoolean, sizeof(Boolean), Offset(nitpic_resources), XtRString, (XtPointer)"false"}, { "wdt-color-1", "WDT-Color", XtRPixel, sizeof(Pixel), Offset(wdt_color_1), XtRString, (XtPointer)"black"}, { "wdt-color-2", "WDT-Color", XtRPixel, sizeof(Pixel), Offset(wdt_color_2), XtRString, (XtPointer)"black"}, { "wdt-color-3", "WDT-Color", XtRPixel, sizeof(Pixel), Offset(wdt_color_3), XtRString, (XtPointer)"black"}, { "wdt-min", "WDT-Time", XtRFloat, sizeof(float), Offset(wdt_min), XtRString, (XtPointer)"7e-3"}, { "wdt-nominal", "WDT-Time", XtRFloat, sizeof(float), Offset(wdt_nom), XtRString, (XtPointer)"18e-3"}, { "wdt-max", "WDT-Time", XtRFloat, sizeof(float), Offset(wdt_max), XtRString, (XtPointer)"33e-3"}, { "info-bits", XtCFont, XtRFontStruct, sizeof(XFontStruct*), Offset(info_bits), XtRString, (XtPointer)XtDefaultFont }, { "led-on", "LED-Color", XtRPixel, sizeof(Pixel), Offset(led_on), XtRString, (XtPointer)"black" }, { "led-off", "LED-Color", XtRPixel, sizeof(Pixel), Offset(led_off), XtRString, (XtPointer)"white" }, { "left-pointer", "Bitmap", XtRBitmap, sizeof(Pixmap), Offset(left_pointer), XtRString, (XtPointer)"lsolid.xbm" }, { "left-hollow", "Bitmap", XtRBitmap, sizeof(Pixmap), Offset(left_hollow), XtRString, (XtPointer)"lhollow.xbm" }, { "right-pointer", "Bitmap", XtRBitmap, sizeof(Pixmap), Offset(right_pointer), XtRString, (XtPointer)"rsolid.xbm" }, { "right-hollow", "Bitmap", XtRBitmap, sizeof(Pixmap), Offset(right_hollow), XtRString, (XtPointer)"rhollow.xbm" }, }; #undef Offset int main( int argc, char **argv ) { W.toplevel = XtVaAppInitialize( &AppContext, "XPICsim", NULL, 0, &argc, argv, fallback_resources, NULL ); XtVaGetApplicationResources( W.toplevel, (XtPointer)(&Options), resources, XtNumber(resources), NULL ); if (!Options.nitpic_resources) xusage( ); W.main = XtVaCreateManagedWidget( "main", formWidgetClass, W.toplevel, NULL ); W.title = XtVaCreateManagedWidget( "title", labelWidgetClass, W.main, XtNtop, XawChainTop, XtNbottom, XawChainTop, NULL ); W.copyright = XtVaCreateManagedWidget( "copyright", commandWidgetClass, W.main, XtNtop, XawChainTop, XtNbottom, XawChainTop, XtNfromVert, W.title, XtNlabel, ((XtPointer) "copyright (c) 1994, 1995 dhm"), NULL ); XtAddCallback( W.copyright, "callback", copyright, NULL ); W.info = XtVaCreateManagedWidget( "info", labelWidgetClass, W.main, XtNlabel, (XtPointer)"", XtNfromVert, W.copyright, XtNtop, XawChainTop, NULL ); W.ic = XtVaCreateManagedWidget( "ic", labelWidgetClass, W.main, XtNfromVert, (XtPointer)W.info, XtNlabel, (XtPointer)"", XtNbottom, XawChainBottom, NULL ); W.instr = XtVaCreateManagedWidget( "instr", formWidgetClass, W.main, XtNfromHoriz, (XtPointer)W.info, XtNtop, XawChainTop, XtNbottom, XawChainBottom, NULL ); W.ipointer = XtVaCreateManagedWidget( "ipointer", labelWidgetClass, W.instr, XtNtop, XawChainTop, XtNbottom, XawChainBottom, XtNright, XawChainLeft, NULL ); W.itext = XtVaCreateManagedWidget( "itext", labelWidgetClass, W.instr, XtNlabel, (XtPointer)"", XtNfromHoriz, (XtPointer)W.ipointer, XtNtop, XawChainTop, XtNbottom, XawChainBottom, XtNright, XawChainRight, XtNleft, XawChainLeft, NULL ); W.iscroll = XtVaCreateManagedWidget( "iscroll", scrollbarWidgetClass, W.instr, XtNfromHoriz, (XtPointer)W.itext, XtNlabel, (XtPointer)"", XtNtop, XawChainTop, XtNbottom, XawChainBottom, XtNleft, XawChainRight, NULL ); XtAddCallback( W.iscroll, "scrollProc", instr_scroll, NULL ); XtAddCallback( W.iscroll, "jumpProc", instr_jump, NULL ); W.regs = XtVaCreateManagedWidget( "regs", formWidgetClass, W.main, XtNfromHoriz, (XtPointer)W.instr, XtNtop, XawChainTop, NULL ); W.rprev = XtVaCreateManagedWidget( "rprev", commandWidgetClass, W.regs, XtNtop, XawChainTop, XtNbottom, XawChainTop, XtNleft, XawChainLeft, XtNright, XawChainLeft, NULL ); W.rpage = XtVaCreateManagedWidget( "rpage", labelWidgetClass, W.regs, XtNlabel, (XtPointer)"Page 0", XtNfromHoriz, W.rprev, XtNtop, XawChainTop, XtNbottom, XawChainTop, XtNleft, XawChainLeft, XtNright, XawChainRight, NULL ); W.rnext = XtVaCreateManagedWidget( "rnext", commandWidgetClass, W.regs, XtNfromHoriz, W.rpage, XtNtop, XawChainTop, XtNbottom, XawChainTop, XtNleft, XawChainRight, XtNright, XawChainRight, NULL ); W.rdata = XtVaCreateManagedWidget( "rdata", labelWidgetClass, W.regs, XtNlabel, (XtPointer)"", XtNfromVert, W.rpage, XtNtop, XawChainTop, XtNbottom, XawChainBottom, XtNleft, XawChainLeft, XtNright, XawChainRight, NULL ); W.data = XtVaCreateManagedWidget( "data", labelWidgetClass, W.main, XtNfromHoriz, (XtPointer)W.instr, XtNfromVert, (XtPointer)W.regs, XtNlabel, (XtPointer)"", XtNbottom, XawChainBottom, NULL ); W.step = XtVaCreateManagedWidget( "step", commandWidgetClass, W.main, XtNfromVert, (XtPointer)W.ic, XtNtop, XawChainBottom, XtNbottom, XawChainBottom, NULL ); W.run = XtVaCreateManagedWidget( "run", toggleWidgetClass, W.main, XtNfromVert, (XtPointer)W.ic, XtNfromHoriz, (XtPointer)W.step, XtNtop, XawChainBottom, XtNbottom, XawChainBottom, NULL ); W.interrupt = XtVaCreateManagedWidget( "int", commandWidgetClass, W.main, XtNfromVert, (XtPointer)W.ic, XtNfromHoriz, (XtPointer)W.run, XtNtop, XawChainBottom, XtNbottom, XawChainBottom, NULL ); W.reset = XtVaCreateManagedWidget( "reset", commandWidgetClass, W.main, XtNfromVert, (XtPointer)W.ic, XtNfromHoriz,(XtPointer)W.interrupt, XtNtop, XawChainBottom, XtNbottom, XawChainBottom, NULL ); W.file = XtVaCreateManagedWidget( "file", commandWidgetClass, W.main, XtNfromVert, (XtPointer)W.ic, XtNfromHoriz,(XtPointer)W.reset, XtNtop, XawChainBottom, XtNbottom, XawChainBottom, NULL ); W.quit = XtVaCreateManagedWidget( "quit", commandWidgetClass, W.main, XtNfromVert, (XtPointer)W.ic, XtNfromHoriz, (XtPointer)W.file, XtNtop, XawChainBottom, XtNbottom, XawChainBottom, NULL ); XtAppAddActions( AppContext, actions, XtNumber( actions ) ); XtRealizeWidget( W.toplevel ); sim_init( (argc > 1) ? argv[1] : "" ); XtAppMainLoop( AppContext ); } static void xusage_ok( Widget w, XtPointer closure, XtPointer call_data ) { exit( 0 ); } static volatile void xusage( void ) { Widget w, msg, ok; w = XtVaCreateManagedWidget( "main", formWidgetClass, W.toplevel, NULL ); msg = XtVaCreateManagedWidget( "msg", labelWidgetClass, w, XtNlabel, (XtPointer)("Couldn't load resource file.\n" "Can't continue; sorry."), NULL ); ok = XtVaCreateManagedWidget( "ok", commandWidgetClass, w, XtNlabel, (XtPointer)"OK", XtNfromVert, (XtPointer)msg, NULL ); XtAddCallback( ok, "callback", xusage_ok, 0 ); XtRealizeWidget( W.toplevel ); XtAppMainLoop( AppContext ); exit( 0 ); } static void copyright( Widget w, XtPointer closure, XtPointer call_data ) { dialog("This program was written by Dave Madden, . " "Unauthorized Reproduction and Dissemination is encouraged.", 1, "OK" ); } static void echo( Widget w, XEvent *ev, String *prms, Cardinal *nprm ) { Cardinal i; fputs( "echo: ", stderr ); for (i = 0; i < *nprm; i++) fputs( *prms++, stderr ), fputc( ' ', stderr ); fputc( '\n', stderr ); } static void quit( Widget w, XEvent *ev, String *prms, Cardinal *nprm ) { fputs( "Goodbye.\n", stderr ); exit( 0 ); } nitpic-0.1.orig/patchlevel.h100444 10333 10333 30 5661124601 14224 0ustar kleeklee#define VERSION "v0.1" nitpic-0.1.orig/picsim.hh100444 10333 10333 11102 5707742036 13624 0ustar kleeklee/* -*- c++ -*- * picsim.hh -- X PIC simulator */ #include "patchlevel.h" #include #include #include #include #ifdef __cplusplus extern "C" { #endif #include #include #include #include #include #include #include #include #include #include #include #include "pu_defs.h" /* defines the PIC definition structure */ #ifdef __cplusplus } #endif typedef struct reg { /* Info about each register in register file */ char *name; unsigned modified : 1; unsigned modified_last : 1; char redirect_page; char redirect_reg; char implemented; char value; char (*hook)( struct reg *r, Boolean write, char v = 0 ); } reg; typedef struct { char *reg_name; char *bit_names[8]; char value; char old_value; } info_reg; typedef struct { char *pin_name; unsigned io : 2; unsigned hi : 1; } pin_info; typedef struct { int npins; pin_info *pins; } pins_info; /* * These are commands that the sim controller will send to the PIC execution * module. */ typedef enum { Init, // Power-on reset Reset, // MCLR reset GetPage, // Return reg file page select bits GetInfo, // Return current vals of regs that should // be displayed in the Info window GetPins, // Get info for IC window Disassemble, // Return a string for the Instr window Step // Run a cycle } SimFunc; typedef union { /* Simulator argument & return value */ int i; void *p; } SimAR; typedef struct { unsigned running:1; unsigned sleeping:1; u_long ticks; /* clock cycles @ uinfo.clock */ u_long millisec; /* ms of realtime elapsed in simulation */ int millisec_left; /* clock ticks left before another ms */ float wdt_min; /* WDT min, nominal, and max timeout */ float wdt_nominal; /* values */ float wdt_max; u_long wdt_left; /* ticks left until WDT(max) timeout */ int prescaler; int vreg; /* Page number of reg file in reg window */ int itop; /* PC of top line in instr window */ int pc; /* simulator PC */ int isize; /* words of instruction memory */ int nstack; int sp; int stack[32]; int instr; int prefetch; int reg_pages; reg reg_file[4][128]; int neeprom; char eeprom[128]; SimAR (*simulate)( SimFunc func, SimAR arg ); PICDEFN uinfo; /* User info (program, clock, etc) */ } PIC; typedef struct { Boolean nitpic_resources; Pixel wdt_color_1; Pixel wdt_color_2; Pixel wdt_color_3; float wdt_min; float wdt_nom; float wdt_max; XFontStruct *info_bits; Pixel led_on; Pixel led_off; Pixmap left_pointer; Pixmap left_hollow; Pixmap right_pointer; Pixmap right_hollow; } OptionsRec; /* * Function declarations */ extern void ic_update( void ); extern void info_update( void ); extern void info_quick( void ); extern Boolean ipointer_erase( void ); extern void sim_init( const char *fname ); extern void redraw( void ); extern void reg_update( void ); extern int dialog( const char *text, int n, ... ); /* * Simulators */ extern SimAR pic16c84( SimFunc func, SimAR arg ); /* * Action routines */ #define XtActionProcArgs Widget w, XEvent *ev, String *prms, Cardinal *nprm extern void ic_refresh( XtActionProcArgs ); extern void info_refresh( XtActionProcArgs ); extern void ipointer_refresh( XtActionProcArgs ); extern void ipointer_seek( XtActionProcArgs ); extern void instr_refresh( XtActionProcArgs ); extern void load_file( XtActionProcArgs ); extern void reg_refresh( XtActionProcArgs ); extern void reg_switch( XtActionProcArgs ); extern void sim_step( XtActionProcArgs ); extern void sim_reset( XtActionProcArgs ); extern void sim_toggle_run( XtActionProcArgs ); #undef XtActionProcArgs /* * Callbacks */ extern void instr_scroll( Widget w, XtPointer client_data, XtPointer pos ); extern void instr_jump( Widget w, XtPointer client_data, XtPointer percent ); #ifdef __main__ # define GLOBAL #else # define GLOBAL extern #endif GLOBAL struct { Widget toplevel; Widget main; Widget title; Widget copyright; Widget info; Widget ic; Widget instr; Widget ipointer; Widget itext; Widget iscroll; Widget regs; Widget rprev; Widget rpage; Widget rnext; Widget rdata; Widget data; Widget reset; Widget step; Widget run; Widget interrupt; Widget file; Widget quit; } W; GLOBAL OptionsRec Options; GLOBAL XtAppContext AppContext; GLOBAL PIC Pic; nitpic-0.1.orig/pointer.xbm100444 10333 10333 445 5660033202 14141 0ustar kleeklee#define pointer_width 16 #define pointer_height 16 static unsigned char pointer_bits[] = { 0x02, 0x00, 0x0e, 0x00, 0x3e, 0x00, 0xfe, 0x00, 0xfe, 0x03, 0xfe, 0x0f, 0xfe, 0x3f, 0xfe, 0x7f, 0xfe, 0x3f, 0xfe, 0x0f, 0xfe, 0x03, 0xfe, 0x00, 0x3e, 0x00, 0x0e, 0x00, 0x02, 0x00, 0x00, 0x00}; nitpic-0.1.orig/pu_defs.h100444 10333 10333 1044 5660415772 13603 0ustar kleeklee/* pu_defs.h */ /* definitions for the pic read/write routines */ /* I.King 1994 */ #define MAXPICSIZE 8192 typedef struct picdefn { unsigned short picmemmap[MAXPICSIZE]; int pictype; int picid[4]; float clock; int osctype; int cp_fuse; int wd_fuse; int pu_fuse; } PICDEFN; #define PU_OK 1 #define PU_FAIL 0 extern void PU_Clear(); extern int PU_WriteHeader(); extern int PU_WriteBlock(); extern int PU_WriteTrailer(); extern int PU_Read(const char *filename, PICDEFN *pic, int *top); /* ... The End ... */ nitpic-0.1.orig/pu_lib.c100444 10333 10333 12134 5661026717 13443 0ustar kleeklee/* pu_lib.c */ /* Routines to read and write pic structures to disk */ /* Ian King 1994 */ #include "pu_defs.h" #include #include void PU_Clear(PICDEFN *pic) { int i; for(i=0; ipicmemmap[i] = 0xffff; pic->pictype = 54; pic->picid[0] = 0xffff; pic->picid[1] = 0xffff; pic->picid[2] = 0xffff; pic->picid[3] = 0xffff; pic->osctype = 3; pic->clock = 1.0e6; pic->cp_fuse = 1; pic->wd_fuse = 1; pic->pu_fuse = 1; } int PU_Read(const char *filename, PICDEFN *pic, int *top) { FILE *filehandle; int ch; unsigned short checksum; int finalcheck; int address; int numberofwords; int i; int currentword; int check_provided; check_provided = 0; *top = 0; filehandle = fopen(filename, "r"); if (filehandle == NULL) { printf("Could not open file %s for reading\n",filename); return PU_FAIL; } PU_Clear(pic); while(!feof(filehandle)) { while(isspace(ch = fgetc(filehandle))) ; switch(ch) { case '#': /* comment */ while(fgetc(filehandle)!='\n') ; break; case 'T': fscanf(filehandle,"%d", &pic->pictype); break; case 'W': fscanf(filehandle,"%d", &pic->wd_fuse); break; case 'P': fscanf(filehandle,"%d", &pic->cp_fuse); break; case 'C': fscanf(filehandle,"%d %e", &pic->osctype, &pic->clock); break; case 'U': fscanf(filehandle,"%d", &pic->pu_fuse); break; case 'I': fscanf(filehandle,"%x %x %x %x", &pic->picid[0],&pic->picid[1],&pic->picid[2],&pic->picid[3]); break; case 'A': fscanf(filehandle,"%x", &address); break; case 'D': fscanf(filehandle,"%d", &numberofwords); for(i=0; ipicmemmap[address] = currentword; if (address > *top) *top = address; address++; if (address > MAXPICSIZE) { printf("Illegal address %04x\n", address); return PU_FAIL; } } break; case 'S': fscanf(filehandle,"%x", &finalcheck); check_provided = 1; break; case EOF: break; default: printf("Illegal character in %s (%c)\n", filename, ch); return PU_FAIL; } } fclose(filehandle); if (!check_provided) { printf("No checksum found, probably not a valid pic file\n"); return PU_OK; } checksum = 0; for(i=0; ipicmemmap[i]; if ((unsigned short)finalcheck != checksum) { printf("Fails checksum (want %04x got %04x)\n",finalcheck,checksum); /* * My version of PICASM doesn't give proper checksums (because * of an unrelated hack). But the file is really OK. -dhm */ return PU_OK; } return PU_OK; } int PU_WriteHeader(char *filename, PICDEFN *pic, char *comment) { FILE *filehandle; filehandle = fopen(filename, "w"); if (filehandle == NULL) { printf("Could not open file %s for writing\n",filename); return PU_FAIL; } fprintf(filehandle,"# File %s\n", filename); fprintf(filehandle,"# %s\n", comment); fprintf(filehandle,"T%d\n", pic->pictype); fprintf(filehandle,"W%d\n", pic->wd_fuse); fprintf(filehandle,"P%d\n", pic->cp_fuse); fprintf(filehandle,"C%d %e\n", pic->osctype, pic->clock); fprintf(filehandle,"U%d\n", pic->pu_fuse); fprintf(filehandle,"I%04x %04x %04x %04x\n",pic->picid[0],pic->picid[1], pic->picid[02],pic->picid[3]); fclose(filehandle); return PU_OK; } int PU_WriteBlock(char *filename, PICDEFN *pic, int from, int to) { FILE *filehandle; int length; int i; int numberleft; int current; int mask; length = (to-from) + 1; if (length<=0) { printf("Error stupid block size! from %04x to %04x (size %d)\n", from, to, length); return PU_FAIL; } if ((from>MAXPICSIZE) || (to>MAXPICSIZE)) { printf("Error from or to Out of Range from=%04x to=%04x\n",from, to); return PU_FAIL; } if ((from < 0) || (to < 0)) { printf("Error Negative address specified!\n"); return PU_FAIL; } filehandle = fopen(filename, "a"); if (filehandle == NULL) { printf("Could not open file %s for writing\n",filename); return PU_FAIL; } fprintf(filehandle,"A%04x\n", from); current = from; switch (pic->pictype) { case 54: mask = 0x0fff; break; case 84: mask = 0x3fff; break; default: mask = ~0; break; } while(current < to) { numberleft = to - current; if (numberleft > 8) numberleft = 8; fprintf(filehandle,"D%d", numberleft); for(i=0;ipicmemmap[current+i] & mask); fprintf(filehandle,"\n"); current += numberleft; } fclose(filehandle); return PU_OK; } int PU_WriteTrailer(char *filename, PICDEFN *pic, char *comment) { FILE *filehandle; int i; unsigned short checksum; filehandle = fopen(filename, "a"); if (filehandle == NULL) { printf("Could not open file %s for writing\n",filename); return PU_FAIL; } checksum = 0; for(i=0; ipicmemmap[i]; /* simple checksum */ /* easily fooled! */ fprintf(filehandle, "S%04x\n", checksum); fprintf(filehandle, "# %s\n", comment); fprintf(filehandle, "# ... The End ...\n"); fclose(filehandle); return PU_OK; } /* ... The End ... */ nitpic-0.1.orig/rarrow.xbm100444 10333 10333 442 5660034417 14003 0ustar kleeklee#define rarrow_width 16 #define rarrow_height 16 static unsigned char rarrow_bits[] = { 0x00, 0x00, 0x00, 0x02, 0x00, 0x06, 0x00, 0x0e, 0xfe, 0x1f, 0xfe, 0x3f, 0xfe, 0x7f, 0xfe, 0xff, 0xfe, 0x7f, 0xfe, 0x3f, 0xfe, 0x1f, 0x00, 0x0e, 0x00, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00}; nitpic-0.1.orig/reg.cc100444 10333 10333 12617 5661045525 13115 0ustar kleeklee/* * reg.cc -- handle events in the registers window */ #include "picsim.hh" void reg_refresh( Widget w, XEvent *ev, String *prms, Cardinal *nprm ) { GC gc; XGCValues xgcv; XFontStruct *xfsp; Dimension w_height, w_width; short c_width; int a, b, i, j, k, dv; u_char v; char buf[32]; XtVaGetValues( W.rdata, XtNforeground, &xgcv.foreground, XtNbackground, &xgcv.background, XtNheight, &w_height, XtNwidth, &w_width, XtNfont, &xfsp, NULL ); xgcv.font = xfsp->fid; gc = XCreateGC( XtDisplay(W.rdata), XtWindow(W.rdata), GCForeground | GCBackground | GCFont, &xgcv ); /* * count the implemented regsters in the page we're looking at */ k = 0; for (i = 0; i < 128; i++) { a = Pic.reg_file[Pic.vreg][i].redirect_page; b = Pic.reg_file[Pic.vreg][i].redirect_reg; if (Pic.reg_file[a][b].implemented) ++k; } k = (k + 1) >> 1; dv = xfsp->ascent + xfsp->descent; c_width = xfsp->max_bounds.width; for (i = j = 0; i < 128; i++) { a = Pic.reg_file[Pic.vreg][i].redirect_page; b = Pic.reg_file[Pic.vreg][i].redirect_reg; if (!Pic.reg_file[a][b].implemented) continue; v = Pic.reg_file[a][b].value & Pic.reg_file[a][b].implemented; if (c_width * 16 * 2 <= w_width) { if (Pic.reg_file[a][b].name) sprintf( buf, "%.6s:0x%02X '%c'", Pic.reg_file[a][b].name, v, ((v >= ' ' && v <= '~') ? v : '.')); else sprintf( buf, " F%02X:0x%02X '%c'", i, v, ((v >= ' ' && v <= '~') ? v : '.')); } else { if (Pic.reg_file[a][b].name) sprintf( buf, "%.6s:0x%02X", Pic.reg_file[a][b].name, v ); else sprintf( buf, " F%02X:0x%02X", i, v ); } if (Pic.reg_file[a][b].modified_last) { Pixel temp = xgcv.foreground; xgcv.foreground = xgcv.background; xgcv.background = temp; XChangeGC( XtDisplay(W.rdata), gc, GCForeground | GCBackground, &xgcv ); } XDrawImageString( XtDisplay(W.rdata), XtWindow(W.rdata), gc, (j < k) ? 2 : w_width / 2, (j % k + 1) * dv, buf, strlen( buf ) ); if (Pic.reg_file[a][b].modified_last) { Pixel temp = xgcv.foreground; xgcv.foreground = xgcv.background; xgcv.background = temp; XChangeGC( XtDisplay(W.rdata), gc, GCForeground | GCBackground, &xgcv ); } ++j; } XFreeGC( XtDisplay(W.rdata), gc ); } /* * Display changed registers in reverse video, and reset all previously- * reversed registers to normal video (if they weren't modified again) */ void reg_update( void ) { GC gc; XGCValues xgcv; XFontStruct *xfsp; Dimension w_height, w_width; short c_width; int a, b, i, j, k, dv; u_char v; char buf[32]; XtVaGetValues( W.rdata, XtNforeground, &xgcv.foreground, XtNbackground, &xgcv.background, XtNheight, &w_height, XtNwidth, &w_width, XtNfont, &xfsp, NULL ); xgcv.font = xfsp->fid; gc = XCreateGC( XtDisplay(W.rdata), XtWindow(W.rdata), GCForeground | GCBackground | GCFont, &xgcv ); /* * count the implemented regsters in the page we're looking at */ k = 0; for (i = 0; i < 128; i++) { a = Pic.reg_file[Pic.vreg][i].redirect_page; b = Pic.reg_file[Pic.vreg][i].redirect_reg; if (Pic.reg_file[a][b].implemented) ++k; } k = (k + 1) >> 1; dv = xfsp->ascent + xfsp->descent; c_width = xfsp->max_bounds.width; for (i = j = 0; i < 128; i++) { a = Pic.reg_file[Pic.vreg][i].redirect_page; b = Pic.reg_file[Pic.vreg][i].redirect_reg; if (!Pic.reg_file[a][b].implemented) continue; if (!(Pic.reg_file[a][b].modified||Pic.reg_file[a][b].modified_last)) { ++j; continue; } v = Pic.reg_file[a][b].value & Pic.reg_file[a][b].implemented; if (c_width * 16 * 2 <= w_width) { if (Pic.reg_file[a][b].name) sprintf( buf, "%.6s:0x%02X '%c'", Pic.reg_file[a][b].name, v, ((v >= ' ' && v <= '~') ? v : '.')); else sprintf( buf, " F%02X:0x%02X '%c'", i, v, ((v >= ' ' && v <= '~') ? v : '.')); } else { if (Pic.reg_file[a][b].name) sprintf( buf, "%.6s:0x%02X", Pic.reg_file[a][b].name, v ); else sprintf( buf, " F%02X:0x%02X", i, v ); } if (Pic.reg_file[a][b].modified) { Pixel temp = xgcv.foreground; xgcv.foreground = xgcv.background; xgcv.background = temp; XChangeGC( XtDisplay(W.rdata), gc, GCForeground | GCBackground, &xgcv ); } XDrawImageString( XtDisplay(W.rdata), XtWindow(W.rdata), gc, (j < k) ? 2 : w_width / 2, (j % k + 1) * dv, buf, strlen( buf ) ); if (Pic.reg_file[a][b].modified) { Pixel temp = xgcv.foreground; xgcv.foreground = xgcv.background; xgcv.background = temp; XChangeGC( XtDisplay(W.rdata), gc, GCForeground | GCBackground, &xgcv ); } Pic.reg_file[a][b].modified_last = Pic.reg_file[a][b].modified; Pic.reg_file[a][b].modified = 0; ++j; } XFreeGC( XtDisplay(W.rdata), gc ); } void reg_switch( Widget w, XEvent *ev, String *prms, Cardinal *nprm ) { char buf[32]; if (*nprm == 1) { if (!strcmp( *prms, "next" )) { Pic.vreg += 1; if (Pic.vreg >= Pic.reg_pages) Pic.vreg = 0; } else if (!strcmp( *prms, "prev" )) { Pic.vreg -= 1; if (Pic.vreg < 0) Pic.vreg = Pic.reg_pages - 1; } else goto reg_switch_usage; sprintf( buf, "Page %d", Pic.vreg ); XtVaSetValues( W.rpage, XtNlabel, (XtPointer)buf, NULL ); reg_refresh( W.rdata, ev, prms, nprm ); return; } reg_switch_usage: fputs( "usage: reg-switch( [ next | prev ] )\n", stderr ); } nitpic-0.1.orig/rhollow.xbm100444 10333 10333 204 5661254513 14153 0ustar kleeklee#define rhollow_width 8 #define rhollow_height 8 static char rhollow_bits[] = { 0x03, 0x0d, 0x31, 0xc1, 0x31, 0x0d, 0x03, 0x00}; nitpic-0.1.orig/rsolid.xbm100444 10333 10333 201 5661254613 13757 0ustar kleeklee#define rsolid_width 8 #define rsolid_height 8 static char rsolid_bits[] = { 0x03, 0x0f, 0x3f, 0xff, 0x3f, 0x0f, 0x03, 0x00}; nitpic-0.1.orig/sim.cc100444 10333 10333 6442 5707745302 13110 0ustar kleeklee/* * sim.cc -- do the simulation */ #include "picsim.hh" static SimAR sim_nil( SimFunc func, SimAR arg ); /* * Load the specified PicTools file & set the part info */ void sim_init( const char *fname ) { int i, j; SimAR a; char buf[64]; Pic.isize = 0; Pic.nstack = 0; Pic.reg_pages = 0; Pic.neeprom = 0; for (i = 0; i < 4; i++) { for (j = 0; j < 128; j++) { Pic.reg_file[i][j].redirect_page = i; Pic.reg_file[i][j].redirect_reg = j; Pic.reg_file[i][j].implemented = 0; } } Pic.simulate = sim_nil; Pic.wdt_min = Options.wdt_min; Pic.wdt_nominal = Options.wdt_nom; Pic.wdt_max = Options.wdt_max; Pic.uinfo.clock = 1; if (Pic.wdt_min > Pic.wdt_nominal || Pic.wdt_nominal > Pic.wdt_max) { fputs( "Watchdog timeout values must follow this relation:\n" "WDTmin <= WDTnominal <= WDTmax\n", stderr ); if (Pic.wdt_nominal < Pic.wdt_min) Pic.wdt_nominal = Pic.wdt_min * 1.1; if (Pic.wdt_max < Pic.wdt_nominal) Pic.wdt_max = Pic.wdt_nominal * 1.1; } if (PU_Read( fname, &Pic.uinfo, &i ) != PU_OK) { XtVaSetValues( W.title, XtNlabel, (XtPointer)"Nit-PIC", NULL ); return; } switch (Pic.uinfo.pictype) { case 84: Pic.simulate = pic16c84; XtVaSetValues( W.title, XtNlabel, (XtPointer)"Nit-PIC 16C84", NULL ); break; default: sprintf( buf, "PIC type %d not supported\n", Pic.uinfo.pictype ); dialog( buf, 1, "OK" ); break; } Pic.simulate( Init, a ); redraw( ); } /* * Reset the simulator */ void sim_reset( Widget w, XEvent *ev, String *prms, Cardinal *nprm ) { SimAR a; Pic.running = 0; ipointer_erase( ); Pic.simulate( Reset, a ); ipointer_seek( w, ev, prms, nprm ); redraw( ); } /* * Step the simulator */ void sim_step( Widget w, XEvent *ev, String *prms, Cardinal *nprm ) { Boolean ip_was_visible; SimAR a; if (Pic.running) ip_was_visible = False; else ip_was_visible = ipointer_erase( ); a = Pic.simulate( Step, a ); info_update( ); reg_update( ); if (ip_was_visible) { Cardinal bogus_nprm = 0; ipointer_seek( W.ipointer, ev, NULL, &bogus_nprm ); ipointer_refresh( W.itext, ev, prms, nprm ); } } static Boolean sim_run_proc( XtPointer p ) { if (Pic.running) { SimAR a; a = Pic.simulate( Step, a ); info_quick( ); return False; } else { ipointer_seek( W.ipointer, NULL, NULL, NULL ); ipointer_refresh( W.itext, NULL, NULL, NULL ); info_refresh( W.info, NULL, NULL, NULL ); reg_refresh( W.info, NULL, NULL, NULL ); return True; } } /* * Toggle Run mode on the simulator. If Run is on, start the * repeating stepper. */ void sim_toggle_run( Widget w, XEvent *ev, String *prms, Cardinal *nprm ) { Pic.running = !Pic.running; if (Pic.running) { XtVaSetValues( W.run, XtNlabel, (XtPointer)"Pause", NULL ); ipointer_erase( ); reg_update( ); XtAppAddWorkProc( AppContext, sim_run_proc, NULL ); } else { XtVaSetValues( W.run, XtNlabel, (XtPointer)"Run", NULL ); } } /* * simulator stub routine */ static SimAR sim_nil( SimFunc func, SimAR arg ) { SimAR a; static char buf[32]; switch (func) { case Init: return a; case Reset: return a; case GetPage: a.i = 0; return a; case GetInfo: a.p = NULL; return a; case Disassemble: sprintf( buf, "PICx%d unsupported", Pic.uinfo.pictype ); a.p = buf; return a; case Step: return a; default: return a; } } nitpic-0.1.orig/test.asm100444 10333 10333 4304 5707741072 13465 0ustar kleeklee; Test simulator program -*- asm -*- $processor 84 $watchdog on $pwrup on $protect off $clock rc, 400000 $idwords 1, 2, 3, 4 RTCC equ 1 Opt equ 1 Pcl equ 2 Status equ 3 Fsr equ 4 TrisA equ 5 PortA equ 5 TrisB equ 6 PortB equ 6 Intcon equ 0x0b SP equ 0x0c FP equ 0x0d GR0 equ 0x0e GR1 equ 0x0f C equ 0 ; STATUS bit numbers DC equ 1 Z equ 2 PD equ 3 TO equ 4 RP0 equ 5 RP1 equ 6 IRP equ 7 W equ 0 F equ 1 ;;; ;;;---------------------------------------------------------------------- ;;; org 0 goto Entry org 4 goto Interrupt Entry: btfss Status,TO goto WDTReset btfss Status,PD goto MCLRWakeup PowerUp:movlw 0x30 ; Set up SP movwf SP movwf FP bsf Status,RP0 clrw movwf TrisA movwf TrisB movlw 0b11001000 movwf Opt bcf Status,RP0 movlw 1 call push movlw 2 call push movlw 3 call push movlw 4 call push nop call add16 nop call pop call pop call pop call pop movlw 1 spin0: movwf PortA clrwdt spin1: rlf PortA,F btfss PortA,4 goto spin1 clrf PortA movwf PortB spin2: rlf PortB,F btfss PortB,7 goto spin2 clrf PortB goto spin0 sleep WDTReset: goto WDTReset MCLRWakeup: goto MCLRWakeup Interrupt: goto Interrupt add16: clrw call fentry movlw 4 call index movf 0,W movwf GR0 movlw 3 call index movf 0,W movwf GR1 movlw 2 call index movf 0,W addwf GR0,F btfsc STATUS,C incf GR1,F movlw 1 call index movf 0,W addwf GR1,F goto fexit push: movwf GR0 ; *--SP = W decf SP,F movf SP,W addlw -(GR1) btfsc Status,Z goto StackOverflow movf SP,W movwf Fsr movf GR0,W movwf 0 return StackOverflow: goto StackOverflow pop: movf SP,W ; return *SP++ movwf Fsr movf 0,W incf SP,F return fentry: movwf GR1 ; push FP, FP = SP, SP -= W movf FP,W ; This depends on push not using GR1! call push movf SP,W movwf FP _fent: movf GR1,F btfsc Status,Z return call push goto _fent fexit: movf FP,W movwf Fsr movf 0,W movwf FP movf Fsr,W movwf SP incf SP,F return index: addwf FP,W ; Set Fsr to point to FP[W] movwf Fsr return end nitpic-0.1.orig/test.pt100444 10333 10333 1335 5707741103 13324 0ustar kleeklee# File test.pt # Pic File generated by picasm Version 0.2 T84 W1 P1 C3 4.000000e+05 U1 I0001 0002 0003 0004 A0000 D8 2805 3fff 3fff 3fff 2832 1e03 2830 1d83 D8 2831 3030 008c 008d 1683 0100 0085 0086 D8 30c8 0081 1283 3001 2048 3002 2048 3003 D8 2048 3004 2048 0000 2033 0000 2054 2054 D8 2054 2054 3001 0085 0064 0d85 1e05 2825 D8 0185 0086 0d86 1f86 282a 0186 2823 0063 D8 2830 2831 2832 0100 2059 3004 206b 0800 D8 008e 3003 206b 0800 008f 3002 206b 0800 D8 078e 1803 0a8f 3001 206b 0800 078f 2863 D8 008e 038c 080c 3ef1 1903 2853 080c 0084 D8 080e 0080 0008 2853 080c 0084 0800 0a8c D8 0008 008f 080d 2048 080c 008d 088f 1903 D8 0008 2048 285e 080d 0084 0800 008d 0804 D6 008c 0a8c 0008 070d 0084 0008 Se980 # # ... The End ... nitpic-0.1.orig/test.sym100444 10333 10333 1030 5707741103 13501 0ustar kleeklee-------- Symbol Table Contains --------- rtcc 0001 opt 0001 pcl 0002 status 0003 fsr 0004 trisa 0005 porta 0005 trisb 0006 portb 0006 intcon 000b sp 000c fp 000d gr0 000e gr1 000f c 0000 dc 0001 z 0002 pd 0003 to 0004 rp0 0005 rp1 0006 irp 0007 w 0000 f 0001 entry 0005 interrupt 0032 wdtreset 0030 mclrwakeup 0031 powerup 0009 push 0048 add16 0033 pop 0054 spin0 0023 spin1 0025 spin2 002a fentry 0059 index 006b fexit 0063 stackoverflow 0053 _fent 005e ---------------------------------------- nitpic-0.1.orig/util.cc100444 10333 10333 12403 5707742340 13306 0ustar kleeklee/* * util.cc -- various utility routines */ #include "picsim.hh" void redraw( void ) { ic_refresh( W.ic, NULL, NULL, NULL ); info_refresh( W.info, NULL, NULL, NULL ); instr_refresh( W.instr, NULL, NULL, NULL ); reg_refresh( W.regs, NULL, NULL, NULL ); } void load_file( Widget w, XEvent *ev, String *prms, Cardinal *nprm ) { dialog( "Filename?", 1, "OK" ); } static void dialog_format(char*text, XFontStruct*finfo, Dimension width); static Widget dialog_box = None; static Widget dialog_form; static Widget dialog_text; static Widget *dialog_buttons = NULL; static int dialog_nbuttons = 0; static void dialog_ok( Widget w, XtPointer closure, XtPointer call_data ) { int i; XtPopdown( dialog_box ); XtUnrealizeWidget( dialog_box ); XtUnmanageChildren( dialog_buttons, dialog_nbuttons ); XtUnmanageChild( dialog_text ); XtUnmanageChild( dialog_form ); XtUnmanageChild( dialog_box ); for (i = 0; i < dialog_nbuttons; i++) XtDestroyWidget( dialog_buttons[i] ); XtFree( (char *)dialog_buttons ); dialog_buttons = NULL; fprintf( stderr, "button %d\n", closure ); } int dialog( const char *text, int n, ... ) { va_list buttons; int i, j; Dimension bwidth; Dimension bheight; Dimension twidth; Dimension theight; int fgap; Widget tsink; Dimension width; Dimension height; Window root; Window child; int root_x, root_y; int win_x, win_y; unsigned int mask; char *fmttext; XFontStruct *finfo; fmttext = (char *)XtMalloc( strlen( text ) + 1 ); strcpy( fmttext, text ); va_start( buttons, n ); if (dialog_box == None) { dialog_box = XtVaCreateWidget( "dialog", overrideShellWidgetClass, W.toplevel, NULL ); dialog_form = XtVaCreateWidget( "form", formWidgetClass, dialog_box, NULL ); dialog_text = XtVaCreateWidget( "text", asciiTextWidgetClass, dialog_form, XtNautoFill, (XtPointer)True, XtNscrollVertical, (XtPointer)XawtextScrollWhenNeeded, XtNeditType, (XtPointer)XawtextRead, XtNdisplayCaret, (XtPointer)False, XtNresizable, (XtPointer)True, NULL ); } XawFormDoLayout( dialog_form, False ); dialog_buttons = (Widget *)XtMalloc( n * sizeof(Widget) ); for (i = 0; i < n; i++) { Widget b; char *name; name = va_arg(buttons, char *); if (!i) b = XtVaCreateWidget( name, commandWidgetClass, dialog_form, XtNlabel, name, XtNfromVert, dialog_text, XtNresizable, (XtPointer)True, NULL ); else b = XtVaCreateWidget( name, commandWidgetClass, dialog_form, XtNlabel, name, XtNfromVert, dialog_text, XtNfromHoriz, (XtPointer)dialog_buttons[i-1], XtNresizable, (XtPointer)True, NULL ); XtAddCallback( b, "callback", dialog_ok, (XtPointer)i ); dialog_buttons[i] = b; } dialog_nbuttons = n; XtVaGetValues( dialog_buttons[0], XtNwidth, &bwidth, XtNheight, &bheight, NULL ); XtVaGetValues( dialog_form, XtNdefaultDistance, &fgap, NULL ); if (n == 1) { twidth = bwidth * 2; XtVaSetValues( dialog_buttons[0], XtNhorizDistance, twidth / 4 + fgap, NULL ); } else { twidth = (bwidth + 4) * n + 4; } theight = twidth * 2 / 3; XtVaGetValues( dialog_text, XtNtextSink, &tsink, XtNfont, &finfo, NULL ); dialog_format( fmttext, finfo, twidth ); for (i = 2, j = 0; fmttext[j]; j++) if (fmttext[j] == '\n') ++i; j = XawTextSinkMaxHeight( tsink, i ); if (j < theight) { theight = j; } else { strcpy( fmttext, text ); dialog_format( fmttext, finfo, twidth - 18 ); } XtVaSetValues( dialog_text, XtNwidth, twidth, XtNheight, theight, XtNstring, fmttext, NULL ); XtVaSetValues( dialog_form, XtNwidth, twidth + fgap * 2, XtNheight, theight + bheight + fgap * 3, NULL ); XawFormDoLayout( dialog_form, True ); XtVaGetValues( dialog_form, XtNwidth, &width, XtNheight, &height, NULL ); XQueryPointer( XtDisplay(W.toplevel), XtWindow(W.toplevel), &root, &child, &root_x, &root_y, &win_x, &win_y, &mask ); root_x = (root_x < width / 2) ? 0 : root_x - width / 2; root_y = (root_y < height - bheight / 2) ? 0 : root_y-height+bheight/2; XtVaSetValues( dialog_box, XtNwidth, width, XtNheight, height, XtNx, root_x, XtNy, root_y, NULL ); XtManageChild( dialog_text ); XtManageChildren( dialog_buttons, dialog_nbuttons ); XtManageChild( dialog_form ); XtManageChild( dialog_box ); XtRealizeWidget( dialog_box ); XtPopup( dialog_box, XtGrabExclusive ); XtFree( fmttext ); return 0; } /* * format the text -- put in newlines whenever the current line gets * too long. */ static void dialog_format( char *text, XFontStruct *finfo, Dimension width ) { int i, j, k; for (i = j = 0, k = 1; text[k]; ++k) { if (isspace(text[k])) { if (XTextWidth( finfo, text + i, k - i ) >= width) { if (isspace(text[j])) { text[j++] = '\n'; i = j; } else { text[k] = '\n'; } } else { j = k; } if (text[k] == '\n') i = j = k + 1; } } if (XTextWidth( finfo, text + i, k - i ) >= width && isspace(text[j])) text[j] = '\n'; }