From: Hugo Villeneuve Date: Sat, 20 Mar 2010 07:23:50 +0000 (+0000) Subject: Run checkpatch.pl on every source file X-Git-Tag: v1.1.0~2 X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=b23541495010180e3a69e3e1f64c934b28775878;p=emu8051.git Run checkpatch.pl on every source file --- diff --git a/src/common.h b/src/common.h index c9df126..cf4a634 100644 --- a/src/common.h +++ b/src/common.h @@ -43,13 +43,6 @@ # define EXIT_FAILURE 1 #endif -typedef int bool; -#ifndef FALSE -# define FALSE 0 -# define TRUE 1 -#endif - - /* Returns TRUE if the strings 'a' and 'b' are equal. */ #define STREQ(a, b) (strcasecmp((a), (b)) == 0) @@ -58,11 +51,9 @@ typedef int bool; inline void -ErrorLocation( const char *file, int line ); +ErrorLocation(const char *file, int line); -/*@out@*/ /*@only@*/ void * -xmalloc( size_t size, const char *filename, int line_number ); - +xmalloc(size_t size, const char *filename, int line_number); #endif /* COMMON_H */ diff --git a/src/cpu8051.c b/src/cpu8051.c index 65a79ed..2f22df4 100644 --- a/src/cpu8051.c +++ b/src/cpu8051.c @@ -23,6 +23,7 @@ #define CPU8051_M 1 #include +#include #include "reg8051.h" #include "cpu8051.h" @@ -30,81 +31,153 @@ #include "disasm.h" #include "instructions_8051.h" +/* Check if the address is a breakpoint */ +int +IsBreakpoint(unsigned int address) +{ + int k; + + for (k = 0; k < cpu8051.bp_count; k++) { + if (cpu8051.bp[k] == address) + return 1; + } + + /* The address was not found in the list of breakpoints */ + return 0; +} + +/* Show Breakpoints list */ +void +ShowBreakpoints(void) +{ + int k; + + for (k = 0; k < cpu8051.bp_count; k++) + printf("Breakpoint at address = %.4X\n", cpu8051.bp[k]); +} + +/* Set Breakpoint at address at the end of the breakpoint list */ +void +SetBreakpoint(unsigned int address) +{ + if (IsBreakpoint(address)) + return; /* Already a breakpoint */ + + if (cpu8051.bp_count < MAXBP) + cpu8051.bp[cpu8051.bp_count++] = address; +} + +/* Clear Breakpoint at Address from list */ +void +ClearBreakpoint(unsigned int address) +{ + int k; + + for (k = 0; k < cpu8051.bp_count; k++) { + if (cpu8051.bp[k] == address) { + /* Fill removed breakpoint slot with last entry */ + cpu8051.bp[k] = cpu8051.bp[cpu8051.bp_count - 1]; + cpu8051.bp_count--; + } + } +} + +/* Toggle the breakpoint at Address. */ +void +ToggleBreakpoint(unsigned int address) +{ + if (IsBreakpoint(address)) + ClearBreakpoint(address); + else + SetBreakpoint(address); +} + void cpu8051_init(void) { cpu8051.pc = 0; cpu8051.clock = 0; cpu8051.active_priority = -1; + cpu8051.bp_count = 0; } /* Reset the registers and CPU state */ void cpu8051_Reset(void) { + int i; + cpu8051.pc = 0; - cpu8051.clock= 0; + cpu8051.clock = 0; cpu8051.active_priority = -1; - // Reinitialisation des registres - int i; - for ( i = 0; i < 256; i++ ) { + /* Reset registers */ + + for (i = 0; i < 256; i++) { /* Clear IRAM nad SFR */ - memory_write8( INT_MEM_ID, i, 0 ); + memory_write8(INT_MEM_ID, i, 0); } - memory_write8( INT_MEM_ID, _P0_, 0xFF ); - memory_write8( INT_MEM_ID, _P1_, 0xFF ); - memory_write8( INT_MEM_ID, _P2_, 0xFF ); - memory_write8( INT_MEM_ID, _P3_, 0xFF ); - memory_write8( INT_MEM_ID, _SP_, 0x07 ); + memory_write8(INT_MEM_ID, _P0_, 0xFF); + memory_write8(INT_MEM_ID, _P1_, 0xFF); + memory_write8(INT_MEM_ID, _P2_, 0xFF); + memory_write8(INT_MEM_ID, _P3_, 0xFF); + memory_write8(INT_MEM_ID, _SP_, 0x07); +} + +static void +cpu8051_convert_bit_address(uint8_t bit_address, uint8_t *byte_address, + uint8_t *bit_number) +{ + if (bit_address > 0x7F) { + /* SFR 80-FF */ + *byte_address = bit_address & 0xF8; + *bit_number = bit_address & 0x07; + } else { + /* 20-2F */ + *byte_address = (bit_address >> 3) + 0x20; + *bit_number = bit_address & 0x07; + } } /* Write with a direct addressing mode at Address the new Value */ void -cpu8051_WriteD( unsigned int Address, unsigned char Value ) +cpu8051_WriteD(unsigned int Address, unsigned char Value) { - memory_write8( INT_MEM_ID, Address, Value ); + memory_write8(INT_MEM_ID, Address, Value); } -// Write with an indirect addressing mode at Address the new Value +/* Write with an indirect addressing mode at Address the new Value */ void -cpu8051_WriteI( unsigned int Address, unsigned char Value ) +cpu8051_WriteI(unsigned int Address, unsigned char Value) { - if ( Address > 0x7F ) { - memory_write8( EXT_MEM_ID, Address, Value ); + if (Address > 0x7F) { + memory_write8(EXT_MEM_ID, Address, Value); return; } - memory_write8( INT_MEM_ID, Address, Value ); + memory_write8(INT_MEM_ID, Address, Value); } -// Write with a bit addressing mode at BitAddress the new Value +/* Write with a bit addressing mode at BitAddress the new Value */ void -cpu8051_WriteB( unsigned int BitAddress, unsigned char Value ) +cpu8051_WriteB(uint8_t bit_address, uint8_t value) { - unsigned int ByteAddress, BitNumber; + uint8_t byte_address; + uint8_t bit_number; unsigned char ByteValue, ByteMask; - if ( BitAddress > 0x7F ) { - // SFR 80-FF - ByteAddress = BitAddress & 0xF8; - BitNumber = BitAddress & 0x07; - } - else { - // 20-2F - ByteAddress = ( BitAddress >> 3 ) + 0x20; - BitNumber = BitAddress & 0x07; - } - ByteMask = ( ( 1 << BitNumber ) ^ 0xFF ); - ByteValue = cpu8051_ReadD( ByteAddress ) & ByteMask; - ByteValue += Value << BitNumber; - cpu8051_WriteD( ByteAddress, ByteValue ); + cpu8051_convert_bit_address(bit_address, &byte_address, &bit_number); + + ByteMask = ((1 << bit_number) ^ 0xFF); + ByteValue = cpu8051_ReadD(byte_address) & ByteMask; + ByteValue += value << bit_number; + cpu8051_WriteD(byte_address, ByteValue); } -// Read with a direct addressing mode at Address +/* Read with a direct addressing mode at Address */ unsigned char -cpu8051_ReadD( unsigned int Address ) +cpu8051_ReadD(unsigned int Address) { if (Address > 0xFF) return memory_read8(EXT_MEM_ID, Address); @@ -112,227 +185,188 @@ cpu8051_ReadD( unsigned int Address ) return memory_read8(INT_MEM_ID, Address); } -// Read with a indirect addressing mode at Address +/* Read with a indirect addressing mode at Address */ unsigned char -cpu8051_ReadI( unsigned int Address ) +cpu8051_ReadI(unsigned int Address) { - if (Address > 0x7F) { + if (Address > 0x7F) return memory_read8(EXT_MEM_ID, Address); - } - else { + else return memory_read8(INT_MEM_ID, Address); - } } -// Read with a bit addressing mode at BitAddress +/* Read with a bit addressing mode at BitAddress */ unsigned char -cpu8051_ReadB( unsigned int BitAddress ) +cpu8051_ReadB(uint8_t bit_address) { - unsigned int ByteAddress, BitNumber; + uint8_t byte_address; + uint8_t bit_number; unsigned char BitValue; - if ( BitAddress > 0x7F ) { - // SFR 80-FF - ByteAddress = BitAddress & 0xF8; - BitNumber = BitAddress & 0x07; - } - else { - // 20-2F - ByteAddress = ( BitAddress >> 3 ) + 0x20; - BitNumber = BitAddress & 0x07; - } - BitValue = ( cpu8051_ReadD( ByteAddress ) >> BitNumber ); + cpu8051_convert_bit_address(bit_address, &byte_address, &bit_number); + + BitValue = (cpu8051_ReadD(byte_address) >> bit_number); BitValue &= 1; return BitValue; } -// Check interrupts state and process them as needed static void -cpu8051_CheckInterrupts() +cpu8051_process_interrupt(int pc, int pri) { unsigned char SP; + + SP = cpu8051_ReadD(_SP_); + cpu8051_WriteI(++SP, (cpu8051.pc & 0xFF)); + cpu8051_WriteI(++SP, (cpu8051.pc >> 8)); + cpu8051_WriteD(_SP_, SP); + cpu8051.pc = 0x0B; + cpu8051.active_priority = pri; +} + + +/* Check interrupts state and process them as needed */ +static void +cpu8051_CheckInterrupts(void) +{ int i; - if ( cpu8051_ReadD( _IE_ ) & 0x80 ) { - for ( i = 1; i >= 0; i-- ) - if ( cpu8051.active_priority < i ) { - //------------------------- External interrupt 0 ---------------------------- - // if ( ( cpu8051_ReadD( _IE_ ) & 0x01 ) && ( ( cpu8051_ReadD( _IP_ ) & 0x01 ) ? i : !i ) && pin0 ) - //-------------------------- Interrupt timer 0 ------------------------------- - if ( ( cpu8051_ReadD( _IE_ ) & 0x02 ) && ( ( cpu8051_ReadD( _IP_ & 0x02 ) ? i : !i ) && ( cpu8051_ReadD( _TCON_ ) & 0x20 ) ) ){ - cpu8051_WriteD( _TCON_, cpu8051_ReadD( _TCON_ ) & 0xDF ); - SP = cpu8051_ReadD( _SP_ ); - cpu8051_WriteI( ++SP, ( cpu8051.pc & 0xFF ) ); - cpu8051_WriteI( ++SP, ( cpu8051.pc >> 8 ) ); - cpu8051_WriteD( _SP_, SP ); - cpu8051.pc = 0x0B; - cpu8051.active_priority = i; - return; - } - //-------------------------- External interrupt 1 ---------------------------- - // if ( ( cpu8051_ReadD( _IE_ ) & 0x04 ) && ( ( cpu8051_ReadD( _IP_ ) & 0x04 ) ? i : !i ) && pin1 ) - //-------------------------- Interrupt timer 1 ------------------------------- - if ( ( cpu8051_ReadD( _IE_ ) & 0x08 ) && ( ( cpu8051_ReadD( _IP_ ) & 0x08 ) ? i : !i ) && ( cpu8051_ReadD( _TCON_ ) & 0x80 ) ) { - cpu8051_WriteD( _TCON_, cpu8051_ReadD( _TCON_ ) & 0x7F ); - SP = cpu8051_ReadD( _SP_ ); - cpu8051_WriteI( ++SP, ( cpu8051.pc & 0xFF ) ); - cpu8051_WriteI( ++SP, ( cpu8051.pc >> 8 ) ); - cpu8051_WriteD( _SP_, SP ); - cpu8051.pc = 0x1B; - cpu8051.active_priority = i; - return; - } - //-------------------------- Serial Interrupts ------------------------------- - if ( ( cpu8051_ReadD( _IE_ ) & 0x10 ) && ( ( cpu8051_ReadD( _IP_ ) & 0x10 ) ? i : !i ) && ( cpu8051_ReadD( _SCON_ ) & 0x03 ) ) { - SP = cpu8051_ReadD( _SP_ ); - cpu8051_WriteI( ++SP, ( cpu8051.pc & 0xFF ) ); - cpu8051_WriteI( ++SP, ( cpu8051.pc >> 8 ) ); - cpu8051_WriteD( _SP_, SP ); - cpu8051.pc = 0x23; - cpu8051.active_priority = i; - return; - } - //-------------------------- Interrupt timer 2 ------------------------------- - if ( ( cpu8051_ReadD( _IE_ ) & 0x20 ) && ( ( cpu8051_ReadD( _IP_ ) & 0x20 ) ? i : !i ) && ( cpu8051_ReadD( _T2CON_ ) & 0x80 ) ) { - SP = cpu8051_ReadD( _SP_ ); - cpu8051_WriteI( ++SP, ( cpu8051.pc & 0xFF ) ); - cpu8051_WriteI( ++SP, ( cpu8051.pc >> 8 ) ); - cpu8051_WriteD( _SP_, SP ); - cpu8051.pc = 0x2B; - cpu8051.active_priority = i; - return; - } + if ((cpu8051_ReadD(_IE_) & 0x80) == 0) + return; + + for (i = 1; i >= 0; i--) { + if (cpu8051.active_priority < i) { + /* Interrupt timer 0 */ + if ((cpu8051_ReadD(_IE_) & 0x02) && + ((cpu8051_ReadD(_IP_ & 0x02) ? i : !i) && + (cpu8051_ReadD(_TCON_) & 0x20))) { + cpu8051_WriteD(_TCON_, + cpu8051_ReadD(_TCON_) & 0xDF); + cpu8051_process_interrupt(0x0B, i); + return; + } + /* Interrupt timer 1 */ + if ((cpu8051_ReadD(_IE_) & 0x08) && + ((cpu8051_ReadD(_IP_) & 0x08) ? i : !i) && + (cpu8051_ReadD(_TCON_) & 0x80)) { + cpu8051_WriteD(_TCON_, + cpu8051_ReadD(_TCON_) & 0x7F); + cpu8051_process_interrupt(0x1B, i); + return; } + /* Serial Interrupts */ + if ((cpu8051_ReadD(_IE_) & 0x10) && + ((cpu8051_ReadD(_IP_) & 0x10) ? i : !i) && + (cpu8051_ReadD(_SCON_) & 0x03)) { + cpu8051_process_interrupt(0x23, i); + return; + } + /* Interrupt timer 2 */ + if ((cpu8051_ReadD(_IE_) & 0x20) && + ((cpu8051_ReadD(_IP_) & 0x20) ? i : !i) && + (cpu8051_ReadD(_T2CON_) & 0x80)) { + cpu8051_process_interrupt(0x2B, i); + return; + } + } } } -// Execute les timers static void -cpu8051_DoTimers( ) +process_timer(uint8_t tl, uint8_t th, uint8_t tf_mask, uint8_t TR, uint8_t mode, + uint8_t GATE, uint32_t TimerCounter) { unsigned int tmp; - unsigned int TR; - unsigned int MODE; - unsigned int GATE; - unsigned int TimerCounter; - // ----- Timer 0 - TR = cpu8051_ReadD( _TCON_ ) & 0x10; - MODE = cpu8051_ReadD( _TMOD_ ) & 0x03; - GATE = cpu8051_ReadD( _TMOD_ ) & 0x08; - TimerCounter = cpu8051_ReadD( _TMOD_ ) & 0x04; - - if ( ( TR && !GATE && !TimerCounter ) || ( MODE == 3 ) ) - switch( MODE ) { - // Mode 0, compteur de 13 bits. - case 0 : - tmp = cpu8051_ReadD( _TH0_ ) * 0x100 + cpu8051_ReadD( _TL0_ ); - - tmp++; - tmp &= 0x1FFF; // On ne garde que 13 bits. - - if ( tmp == 0 ) // If overflow set TF0 - cpu8051_WriteD( _TCON_, cpu8051_ReadD( _TCON_ ) | 0x20 ); - cpu8051_WriteD( _TH0_, tmp / 0x100 ); - cpu8051_WriteD( _TL0_, tmp & 0xFF ); - break; - - // Mode 1, compteur de 16 bits. - case 1 : - tmp = cpu8051_ReadD( _TH0_ ) * 0x100 + cpu8051_ReadD( _TL0_ ); - tmp++; - tmp &= 0xFFFF; // On ne garde que 16 bits. - if ( tmp == 0 ) // If overflow set TF0 - cpu8051_WriteD( _TCON_, cpu8051_ReadD( _TCON_ ) | 0x20 ); - cpu8051_WriteD( _TH0_, ( tmp / 0x100 ) ); - cpu8051_WriteD( _TL0_, ( tmp & 0xFF ) ); - break; - - // Mode 2, Compteur de 8 bits avec Auto-Reload - case 2 : - tmp = cpu8051_ReadD( _TL0_ ); - tmp++; - tmp &= 0xFF; - if ( tmp == 0 ) { // If overflow -> reload et set TF0 - cpu8051_WriteD( _TCON_, cpu8051_ReadD( _TCON_ ) | 0x20 ); - cpu8051_WriteD( _TL0_, cpu8051_ReadD( _TH0_ ) ); - } - else - cpu8051_WriteD( _TL0_, tmp ); - break; - - // Mode 3 : TL0 et TH0 sont 2 Timers independants de 8 bits chacuns. - case 3 : - if ( TR && !GATE && !TimerCounter ) { - tmp = cpu8051_ReadD( _TL0_ ); + switch (mode) { + case 0: + /* Mode 0, 13-bits counter. */ + tmp = cpu8051_ReadD(th) * 0x100 + cpu8051_ReadD(tl); + tmp++; + tmp &= 0x1FFF; /* We keep only 13 bits */ + + if (tmp == 0) /* If overflow set TF0 */ + cpu8051_WriteD(_TCON_, cpu8051_ReadD(_TCON_) | tf_mask); + cpu8051_WriteD(_TH0_, tmp / 0x100); + cpu8051_WriteD(_TL0_, tmp & 0xFF); + break; + case 1: + /* Mode 1, 16-bits counter */ + tmp = cpu8051_ReadD(th) * 0x100 + cpu8051_ReadD(tl); + tmp++; + tmp &= 0xFFFF; /* We keep only 16 bits */ + if (tmp == 0) /* If overflow set TF0 */ + cpu8051_WriteD(_TCON_, cpu8051_ReadD(_TCON_) | tf_mask); + cpu8051_WriteD(_TH0_, (tmp / 0x100)); + cpu8051_WriteD(_TL0_, (tmp & 0xFF)); + break; + case 2: + /* Mode 2, 8-bits counter with Auto-Reload */ + tmp = cpu8051_ReadD(tl); + tmp++; + tmp &= 0xFF; + if (tmp == 0) { + /* If overflow -> reload and set TF0 */ + cpu8051_WriteD(_TCON_, cpu8051_ReadD(_TCON_) | tf_mask); + cpu8051_WriteD(tl, cpu8051_ReadD(th)); + } else + cpu8051_WriteD(tl, tmp); + break; + case 3: + /* Mode 3 : inactive mode for timer 1 */ + if (tl == _TL0_) { + /* TL0 and TH0 are 2 independents 8-bits timers. */ + if (TR && !GATE && !TimerCounter) { + tmp = cpu8051_ReadD(tl); tmp++; tmp &= 0xFF; - if ( tmp == 0 ) // If TL0 overflow set TF0 - cpu8051_WriteD( _TCON_, cpu8051_ReadD( _TCON_ ) | 0x20 ); - cpu8051_WriteD( _TL0_, tmp ); - } // TH0 utilise TR1 et TF1. - TR = cpu8051_ReadD( _TCON_ ) & 0x40; - if ( TR ) { - tmp = cpu8051_ReadD( _TH0_ ); + if (tmp == 0) /* If TL0 overflow set TF0 */ + cpu8051_WriteD(_TCON_, + cpu8051_ReadD(_TCON_) | + tf_mask); + cpu8051_WriteD(tl, tmp); + } /* TH0 utilise TR1 et TF1. */ + TR = cpu8051_ReadD(_TCON_) & 0x40; + if (TR) { + tmp = cpu8051_ReadD(th); tmp++; tmp &= 0xFF; - if ( tmp == 0 ) // If TH0 overflow set TF1 - cpu8051_WriteD( _TCON_, cpu8051_ReadD( _TCON_ ) | 0x80 ); // TF1 = 1. - cpu8051_WriteD( _TH0_, tmp ); + if (tmp == 0) /* If TH0 overflow set TF1 */ + cpu8051_WriteD(_TCON_, + cpu8051_ReadD(_TCON_) | + 0x80); + cpu8051_WriteD(_TH0_, tmp); } - break; - }; - - - // ----- Timer 1 - TR = cpu8051_ReadD( _TCON_ ) & 0x40; - MODE = ( cpu8051_ReadD( _TMOD_ ) & 0x30 ) >> 4 ; - GATE = cpu8051_ReadD( _TMOD_ ) & 0x80; - TimerCounter = cpu8051_ReadD( _TMOD_ ) & 0x40; - - if ( TR && !GATE && !TimerCounter ) - switch( MODE ) { - // Mode 0, compteur de 13 bits. - case 0 : - tmp = cpu8051_ReadD( _TH1_ ) * 0x100 + cpu8051_ReadD( _TL1_ ); - tmp++; - tmp &= 0x1FFF; // On ne garde que 13 bits. - if ( tmp == 0 ) // If overflow set TF1 - cpu8051_WriteD( _TCON_, cpu8051_ReadD( _TCON_ ) | 0x80 ); - cpu8051_WriteD( _TH1_, tmp / 0x100 ); - cpu8051_WriteD( _TL1_, tmp & 0xFF ); - break; - - // Mode 1, compteur de 16 bits. - case 1 : - tmp = cpu8051_ReadD( _TH1_ ) * 0x100 + cpu8051_ReadD( _TL1_ ); - tmp++; - tmp &= 0xFFFF; // On ne garde que 16 bits. - if ( tmp == 0 ) // If overflow set TF1 - cpu8051_WriteD( _TCON_, cpu8051_ReadD( _TCON_ ) | 0x80 ); - cpu8051_WriteD( _TH1_, ( tmp / 0x100 ) ); - cpu8051_WriteD( _TL1_, ( tmp & 0xFF ) ); - break; - - // Mode 2, Compteur de 8 bits avec Auto-Reload - case 2 : - tmp = cpu8051_ReadD( _TL1_ ); - tmp++; - tmp &= 0xFF; - if ( tmp == 0 ) { // If overflow -> reload et set TF1 - cpu8051_WriteD( _TCON_, cpu8051_ReadD( _TCON_ ) | 0x80 ); - cpu8051_WriteD( _TL1_, cpu8051_ReadD( _TH1_ ) ); - } - else - cpu8051_WriteD( _TL1_, tmp ); - break; - - // Mode 3 : mode inactif: retient la valeur de TH1 et TL1. - // Equivalent a TR1 = 0. - case 3 : - break; - - }; + } + break; + } +} + +/* Run timers */ +static void +cpu8051_DoTimers(void) +{ + unsigned int TR; + unsigned int MODE; + unsigned int GATE; + unsigned int TimerCounter; + + /* Timer 0 */ + TR = cpu8051_ReadD(_TCON_) & 0x10; + MODE = cpu8051_ReadD(_TMOD_) & 0x03; + GATE = cpu8051_ReadD(_TMOD_) & 0x08; + TimerCounter = cpu8051_ReadD(_TMOD_) & 0x04; + + if ((TR && !GATE && !TimerCounter) || (MODE == 3)) + process_timer(_TL0_, _TH0_, 0x20, TR, MODE, GATE, TimerCounter); + + /* Timer 1 */ + TR = cpu8051_ReadD(_TCON_) & 0x40; + MODE = (cpu8051_ReadD(_TMOD_) & 0x30) >> 4 ; + GATE = cpu8051_ReadD(_TMOD_) & 0x80; + TimerCounter = cpu8051_ReadD(_TMOD_) & 0x40; + + if (TR && !GATE && !TimerCounter) + process_timer(_TL1_, _TH1_, 0x80, TR, MODE, GATE, TimerCounter); } /* Execute at address cpu8051.pc from PGMMem */ @@ -343,19 +377,21 @@ cpu8051_Exec(void) unsigned char opcode; int insttiming; - opcode = memory_read8( PGM_MEM_ID, cpu8051.pc ); + opcode = memory_read8(PGM_MEM_ID, cpu8051.pc); cpu8051.pc++; insttiming = (*opcode_table[opcode])(); /* Function callback. */ - - for( i = 0; i < insttiming; i++ ) { + + for (i = 0; i < insttiming; i++) { cpu8051_CheckInterrupts(); cpu8051_DoTimers(); cpu8051.clock++; } } -// Addressing modes defined in the order as they appear in disasm.hpp -// from table argstext[] +/* + * Addressing modes defined in the order as they appear in disasm.hpp + * from table argstext[] + */ #define ADDR11 0 #define ADDR16 1 #define DIRECT 3 @@ -365,174 +401,195 @@ cpu8051_Exec(void) #define DATA16 22 #define CBITADDR 23 -// SFR Memory map [80h - FFh] -// --------------------------------------------------------------- -// F8 | | | | | | | | | FF -// F0 | B | | | | | | | | F7 -// E8 | | | | | | | | | EF -// E0 | ACC | | | | | | | | E7 -// D8 | | | | | | | | | DF -// D0 | PSW | | | | | | | | D7 -// C8 | T2CON| |RCAP2L|RCAP2H| TL2 | TH2 | | | CF -// C0 | | | | | | | | | C7 -// B8 | IP | | | | | | | | BF -// B0 | P3 | | | | | | | | B7 -// A8 | IE | | | | | | | | AF -// A0 | P2 | | | | | | | | A7 -// 98 | SCON | SBUF | | | | | | | 9F -// 90 | P1 | | | | | | | | 97 -// 88 | TCON | TMOD | TL0 | TL1 | TH0 | TH1 | | | 8F -// 80 | P0 | SP | DPL | DPH | | | | PCON | 87 -// --------------------------------------------------------------- - -// Return as Text the name of the SFR register at Address if any +/* + * SFR Memory map [80h - FFh] + * --------------------------------------------------------------- + * F8 | | | | | | | | | FF + * F0 | B | | | | | | | | F7 + * E8 | | | | | | | | | EF + * E0 | ACC | | | | | | | | E7 + * D8 | | | | | | | | | DF + * D0 | PSW | | | | | | | | D7 + * C8 | T2CON| |RCAP2L|RCAP2H| TL2 | TH2 | | | CF + * C0 | | | | | | | | | C7 + * B8 | IP | | | | | | | | BF + * B0 | P3 | | | | | | | | B7 + * A8 | IE | | | | | | | | AF + * A0 | P2 | | | | | | | | A7 + * 98 | SCON | SBUF | | | | | | | 9F + * 90 | P1 | | | | | | | | 97 + * 88 | TCON | TMOD | TL0 | TL1 | TH0 | TH1 | | | 8F + * 80 | P0 | SP | DPL | DPH | | | | PCON | 87 + * --------------------------------------------------------------- + */ + +/* Return as Text the name of the SFR register at Address if any */ static int -cpu8051_SFRMemInfo( unsigned int Address, char *Text ) +cpu8051_SFRMemInfo(unsigned int Address, char *Text) { - switch( Address ) { - case 0x80 : return sprintf( Text, "P0" ); - case 0x81 : return sprintf( Text, "SP" ); - case 0x82 : return sprintf( Text, "DPL" ); - case 0x83 : return sprintf( Text, "DPH" ); - case 0x87 : return sprintf( Text, "PCON" ); - case 0x88 : return sprintf( Text, "TCON" ); - case 0x89 : return sprintf( Text, "TMOD" ); - case 0x8A : return sprintf( Text, "TL0" ); - case 0x8B : return sprintf( Text, "TL1" ); - case 0x8C : return sprintf( Text, "TH0" ); - case 0x8D : return sprintf( Text, "TH1" ); - case 0x90 : return sprintf( Text, "P1" ); - case 0x98 : return sprintf( Text, "SCON" ); - case 0x99 : return sprintf( Text, "SBUF" ); - case 0xA0 : return sprintf( Text, "P2" ); - case 0xA8 : return sprintf( Text, "IE" ); - case 0xB0 : return sprintf( Text, "P3" ); - case 0xB8 : return sprintf( Text, "IP" ); - case 0xC8 : return sprintf( Text, "T2CON" ); - case 0xCA : return sprintf( Text, "RCAP2L" ); - case 0xCB : return sprintf( Text, "RCAP2H" ); - case 0xCC : return sprintf( Text, "TL2" ); - case 0xCD : return sprintf( Text, "TH2" ); - case 0xD0 : return sprintf( Text, "PSW" ); - case 0xE0 : return sprintf( Text, "ACC" ); - case 0xF0 : return sprintf( Text, "B" ); - default : return sprintf( Text, "%.2XH", Address ); + switch (Address) { + case 0x80: return sprintf(Text, "P0"); + case 0x81: return sprintf(Text, "SP"); + case 0x82: return sprintf(Text, "DPL"); + case 0x83: return sprintf(Text, "DPH"); + case 0x87: return sprintf(Text, "PCON"); + case 0x88: return sprintf(Text, "TCON"); + case 0x89: return sprintf(Text, "TMOD"); + case 0x8A: return sprintf(Text, "TL0"); + case 0x8B: return sprintf(Text, "TL1"); + case 0x8C: return sprintf(Text, "TH0"); + case 0x8D: return sprintf(Text, "TH1"); + case 0x90: return sprintf(Text, "P1"); + case 0x98: return sprintf(Text, "SCON"); + case 0x99: return sprintf(Text, "SBUF"); + case 0xA0: return sprintf(Text, "P2"); + case 0xA8: return sprintf(Text, "IE"); + case 0xB0: return sprintf(Text, "P3"); + case 0xB8: return sprintf(Text, "IP"); + case 0xC8: return sprintf(Text, "T2CON"); + case 0xCA: return sprintf(Text, "RCAP2L"); + case 0xCB: return sprintf(Text, "RCAP2H"); + case 0xCC: return sprintf(Text, "TL2"); + case 0xCD: return sprintf(Text, "TH2"); + case 0xD0: return sprintf(Text, "PSW"); + case 0xE0: return sprintf(Text, "ACC"); + case 0xF0: return sprintf(Text, "B"); + default: return sprintf(Text, "%.2XH", Address); } } -// Return as Text the decoded BitAddress +/* Return as Text the decoded BitAddress */ static void -cpu8051_IntMemBitInfo( unsigned int BitAddress, char *Text ) +cpu8051_IntMemBitInfo(uint8_t bit_address, char *text) { - unsigned int ByteAddress, BitNumber; - int TextLength; - - if ( BitAddress > 0x7F ) { - // SFR 80-FF - ByteAddress = BitAddress & 0xF8; - BitNumber = BitAddress & 0x07; - } - else { - // 20-2F - ByteAddress = ( BitAddress >> 3 ) + 0x20; - BitNumber = BitAddress & 0x07; - } - - TextLength = cpu8051_SFRMemInfo( ByteAddress, Text ); - // sprintf( &Text[ TextLength ], ".%X" ); - // Modified by Hugo Villeneuve to remove compilation warning - sprintf( &Text[ TextLength ], ".%X", BitAddress ); + uint8_t byte_address; + uint8_t bit_number; + int len; + + cpu8051_convert_bit_address(bit_address, &byte_address, &bit_number); + + len = cpu8051_SFRMemInfo(byte_address, text); + sprintf(&text[len], ".%X", bit_address); } -// Disasm one instruction at Address into a Text string +/* Disasm one instruction at Address into a Text string */ int -cpu8051_Disasm( unsigned int Address, char *Text ) +cpu8051_Disasm(unsigned int Address, char *Text) { - int TextLength=0; + int len = 0; char TextTmp[20]; unsigned char OpCode; int ArgTblOfs; int InstSize; int i; - - OpCode = memory_read8( PGM_MEM_ID, Address ); - InstSize = InstSizesTbl[ OpCode ]; - //printf("%.4X\n", Address); - - TextLength += sprintf( Text, " %.4X ", Address ); - - for (i = 0; i < InstSize; i++ ) - TextLength += sprintf( &Text[TextLength], " %.2X", memory_read8( PGM_MEM_ID, Address + i ) ); - + + OpCode = memory_read8(PGM_MEM_ID, Address); + InstSize = InstSizesTbl[OpCode]; + + len += sprintf(Text, " %.4X ", Address); + + for (i = 0; i < InstSize; i++) + len += sprintf(&Text[len], " %.2X", + memory_read8(PGM_MEM_ID, Address + i)); + Address++; - - for (; TextLength < 17; ) TextLength += sprintf( &Text[ TextLength ], " " ); - - TextLength += sprintf( &Text[ TextLength ], "%s ", InstTextTbl[ InstTypesTbl[ OpCode ] ] ); + + for (; len < 17;) + len += sprintf(&Text[len], " "); + + len += sprintf(&Text[len], "%s ", + InstTextTbl[InstTypesTbl[OpCode]]); ArgTblOfs = OpCode << 2; - - for (; TextLength < 25; ) TextLength += sprintf( &Text[ TextLength ], " " ); - - // MOV direct, direct (OpCode 85h) is peculiar, the operands are inverted - if ( OpCode == 0x85 ) { - cpu8051_SFRMemInfo( memory_read8( PGM_MEM_ID, Address + 1 ), TextTmp ); - TextLength += sprintf( &Text[ TextLength ], "%s,", TextTmp ); - cpu8051_SFRMemInfo( memory_read8( PGM_MEM_ID, Address ), TextTmp ); - TextLength += sprintf( &Text[ TextLength ], "%s", TextTmp ); + + for (; len < 25;) + len += sprintf(&Text[len], " "); + + /* + * MOV direct, direct (OpCode 85h) is peculiar, the operands + * are inverted + */ + if (OpCode == 0x85) { + cpu8051_SFRMemInfo(memory_read8(PGM_MEM_ID, Address + 1), + TextTmp); + len += sprintf(&Text[len], "%s,", TextTmp); + cpu8051_SFRMemInfo(memory_read8(PGM_MEM_ID, Address), + TextTmp); + len += sprintf(&Text[len], "%s", TextTmp); Address += 2; return InstSize; } - - for ( i = 1; i <= InstArgTbl[ ArgTblOfs ]; i++ ) { - switch( InstArgTbl[ ArgTblOfs + i ] ) { - case ADDR11 : { - TextLength += sprintf( &Text[ TextLength ], "%.4XH", ( ( OpCode << 3) & 0xF00 ) + ( memory_read8( PGM_MEM_ID, Address ) ) ); + + for (i = 1; i <= InstArgTbl[ArgTblOfs]; i++) { + switch (InstArgTbl[ArgTblOfs + i]) { + case ADDR11: { + len += sprintf(&Text[len], + "%.4XH", ((OpCode << 3) & 0xF00) + + (memory_read8(PGM_MEM_ID, Address))); Address++; break; } - case ADDR16 : { - TextLength += sprintf( &Text[ TextLength ], "%.4XH", ( ( memory_read8( PGM_MEM_ID, Address ) << 8 ) + memory_read8( PGM_MEM_ID, Address + 1 ) ) ); + case ADDR16: { + len += sprintf( + &Text[len], "%.4XH", + ((memory_read8(PGM_MEM_ID, Address) << 8) + + memory_read8(PGM_MEM_ID, Address + 1))); Address += 2; break; } - case DIRECT : { - cpu8051_SFRMemInfo( memory_read8( PGM_MEM_ID, Address ), TextTmp ); - TextLength += sprintf( &Text[ TextLength ], "%s", TextTmp ); + case DIRECT: { + cpu8051_SFRMemInfo(memory_read8(PGM_MEM_ID, Address), + TextTmp); + len += sprintf(&Text[len], "%s", TextTmp); Address++; break; } - case BITADDR : { - cpu8051_IntMemBitInfo( ( memory_read8( PGM_MEM_ID, Address ) & 0xF8 ), TextTmp ); - TextLength += sprintf( &Text[ TextLength ], "%s.%X" , TextTmp, ( memory_read8( PGM_MEM_ID, Address ) & 7 ) ); + case BITADDR: { + cpu8051_IntMemBitInfo( + (memory_read8(PGM_MEM_ID, Address) & 0xF8), + TextTmp); + len += sprintf(&Text[len], "%s.%X" , TextTmp, + (memory_read8(PGM_MEM_ID, Address) & 7)); Address++; break; } - case RELADDR : { + case RELADDR: { Address++; - TextLength += sprintf( &Text[ TextLength ], "%.4XH", ( Address & 0xFF00 ) + ( ( ( Address & 0xFF ) + memory_read8( PGM_MEM_ID, Address - 1 ) ) & 0xFF ) ); + len += sprintf(&Text[len], "%.4XH", (Address & 0xFF00) + + (((Address & 0xFF) + + memory_read8(PGM_MEM_ID, + Address - 1)) & 0xFF)); break; } - case DATAIMM : { - TextLength += sprintf( &Text[ TextLength ], "#%.2XH", memory_read8( PGM_MEM_ID, Address ) ); + case DATAIMM: { + len += sprintf(&Text[len], "#%.2XH", + memory_read8(PGM_MEM_ID, Address)); Address++; break; } - case DATA16 : { - TextLength += sprintf( &Text[ TextLength ],"#%.4XH", ( ( memory_read8( PGM_MEM_ID, Address ) << 8 ) + memory_read8( PGM_MEM_ID, Address+1 ) ) ); + case DATA16: { + len += sprintf(&Text[len], "#%.4XH", + ((memory_read8(PGM_MEM_ID, + Address) << 8) + + memory_read8(PGM_MEM_ID, Address+1))); Address += 2; break; } - case CBITADDR : { - cpu8051_IntMemBitInfo( ( memory_read8( PGM_MEM_ID, Address ) & 0xF8 ), TextTmp ); - TextLength += sprintf( &Text[ TextLength ], "/%s.%X", TextTmp, ( memory_read8( PGM_MEM_ID, Address ) & 7 ) ); + case CBITADDR: { + cpu8051_IntMemBitInfo((memory_read8(PGM_MEM_ID, + Address) & 0xF8), + TextTmp); + len += sprintf(&Text[len], "/%s.%X", TextTmp, + (memory_read8(PGM_MEM_ID, Address) & 7)); Address++; break; } - default : { - TextLength += sprintf( &Text[ TextLength ],"%s", ArgsTextTbl[ InstArgTbl[ ArgTblOfs + i ] ] ); + default: { + len += sprintf(&Text[len], "%s", + ArgsTextTbl[InstArgTbl[ArgTblOfs + i]]); } } - if (i < InstArgTbl[ ArgTblOfs ]) { TextLength += sprintf( &Text[ TextLength ], "," ); } + if (i < InstArgTbl[ArgTblOfs]) + len += sprintf(&Text[len], ","); } return InstSize; diff --git a/src/cpu8051.h b/src/cpu8051.h index 67e684f..f11122a 100644 --- a/src/cpu8051.h +++ b/src/cpu8051.h @@ -22,12 +22,18 @@ #ifndef CPU8051_H #define CPU8051_H 1 -typedef struct cpu8051_t -{ - unsigned int pc; - unsigned long clock; - int active_priority; -} cpu8051_t; +#include + +/* Maximum number of BreakPoints */ +#define MAXBP 32 + +struct cpu8051_t { + unsigned int pc; /* Program counter */ + unsigned long clock; + int active_priority; + int bp_count; + unsigned int bp[MAXBP]; /* List of breakpoints */ +}; /* Exported variables */ #undef _SCOPE_ @@ -37,36 +43,51 @@ typedef struct cpu8051_t # define _SCOPE_ extern #endif -_SCOPE_ cpu8051_t cpu8051; +_SCOPE_ struct cpu8051_t cpu8051; + +int +IsBreakpoint(unsigned int Address); + +void +ShowBreakpoints(void); + +void +SetBreakpoint(unsigned int Address); + +void +ClearBreakpoint(unsigned int Address); + +void +ToggleBreakpoint(unsigned int Address); void -cpu8051_init( void ); +cpu8051_init(void); void -cpu8051_Exec( void ); +cpu8051_Exec(void); void -cpu8051_Reset( void ); +cpu8051_Reset(void); void -cpu8051_WriteD( unsigned int Address, unsigned char Value ); +cpu8051_WriteD(unsigned int Address, unsigned char Value); void -cpu8051_WriteI( unsigned int Address, unsigned char Value ); +cpu8051_WriteI(unsigned int Address, unsigned char Value); void -cpu8051_WriteB( unsigned int BitAddress, unsigned char Value ); +cpu8051_WriteB(uint8_t bit_address, uint8_t value); unsigned char -cpu8051_ReadD( unsigned int Address ); +cpu8051_ReadD(unsigned int Address); unsigned char -cpu8051_ReadI( unsigned int Address ); +cpu8051_ReadI(unsigned int Address); unsigned char -cpu8051_ReadB( unsigned int BitAddress ); +cpu8051_ReadB(uint8_t bit_address); int -cpu8051_Disasm( unsigned int Address, char *Text ); +cpu8051_Disasm(unsigned int Address, char *Text); #endif /* CPU8051_H */ diff --git a/src/emuconsole.c b/src/emuconsole.c index 8073c56..e31d1b3 100644 --- a/src/emuconsole.c +++ b/src/emuconsole.c @@ -33,13 +33,6 @@ #include "hexfile.h" #include "keyboard.h" -/* Maximum number of BreakPoints */ -#define MAXBP 32 - -static int RunningState; -static int NbBreakpoints; -static unsigned int Breakpoints[MAXBP]; - /* Capitalize all letters in buffer */ static void Capitalize(char *buffer) @@ -63,50 +56,6 @@ RemoveSpaces(char *buffer) strcpy(buffer, &buffer[k]); } -/* Is the a breakpoint at Address */ -static int -IsBreakpoint(unsigned int Address) -{ - int Index = 0; - while (Index < NbBreakpoints && (Breakpoints[Index] != Address)) - Index++; - - return ((Breakpoints[Index] == Address) && (Index < NbBreakpoints)); -} - -/* Show Breakpoints list */ -static void -ShowBreakpoints(void) -{ - int Index; - - for (Index = 0; Index < NbBreakpoints ; Index++) - printf("Breakpoint at Address = %.4X\n", Breakpoints[Index]); -} - -/* Clear Breakpoint at Address from list */ -static void -ClearBreakpoint(unsigned int Address) -{ - int Index = 0; - while ((Index < NbBreakpoints) && (Breakpoints[Index] != Address)) - Index++; - if (Breakpoints[Index] != Address) - return; - Breakpoints[Index] = Breakpoints[NbBreakpoints - 1]; - NbBreakpoints--; -} - -/* Set Breakpoint at Address from list */ -static void -SetBreakpoint(unsigned int Address) -{ - if (IsBreakpoint(Address)) - return; - if (NbBreakpoints < MAXBP) - Breakpoints[NbBreakpoints++] = Address; -} - /* CPU exec and Console UI update */ static void console_exec(char *Address, char *NumberInst) @@ -375,10 +324,10 @@ console_main(void) } switch (Command[0]) { - case 'D': + case 'D': if (strlen(Parameter2) == 0) { char buf[1024]; - + if (STREQ(Command, "DB") && (strlen(Parameter1) == 0)) ShowBreakpoints(); @@ -518,9 +467,6 @@ main(int argc, char **argv) cpu8051_init(); - RunningState = 0; - NbBreakpoints = 0; - hex_file = get_hex_filename(); if (hex_file != NULL) diff --git a/src/emugtk.c b/src/emugtk.c index 45448a2..36171fe 100644 --- a/src/emugtk.c +++ b/src/emugtk.c @@ -47,383 +47,337 @@ static GtkWidget *mainwin; /* Signal DestroyEvent */ static void -WindowDestroyEvent( GtkWidget *widget, gpointer data ) +WindowDestroyEvent(GtkWidget *widget, gpointer data) { #ifdef EMU8051_DEBUG - g_print( "emugtk_DestroyEvent(...)\n" ); + g_print("emugtk_DestroyEvent(...)\n"); #endif - gtk_main_quit(); + gtk_main_quit(); } /* Taken from the Gxine source code. */ static GtkWidget * -AddPixButton( GtkWidget *box, gchar **pixmap_array ) +AddPixButton(GtkWidget *box, gchar **pixmap_array) { - GtkWidget *button, *icon; - GdkPixmap *image; - GdkBitmap *transparent; + GtkWidget *button, *icon; + GdkPixmap *image; + GdkBitmap *transparent; - button = gtk_button_new(); - gtk_button_set_relief (GTK_BUTTON(button), GTK_RELIEF_NORMAL ); - image = gdk_pixmap_colormap_create_from_xpm_d(NULL, gdk_colormap_get_system(), - &transparent, NULL, pixmap_array); - icon = gtk_pixmap_new( image, transparent ); - gtk_container_add( GTK_CONTAINER(button), icon ); + button = gtk_button_new(); + gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NORMAL); + image = gdk_pixmap_colormap_create_from_xpm_d( + NULL, gdk_colormap_get_system(), + &transparent, NULL, pixmap_array); + icon = gtk_pixmap_new(image, transparent); + gtk_container_add(GTK_CONTAINER(button), icon); - gtk_box_pack_start( GTK_BOX(box), button, FALSE, FALSE, 0 ); + gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0); - return button; + return button; } /* Creates the Reset, Run, Stop and Step buttons. */ static GtkWidget * -AddButtons( void ) +AddButtons(void) { - GtkWidget *button_hbox; - GtkWidget *button; - - /* The buttons of the hbox are NOT given equal space in the box. */ - button_hbox = gtk_hbox_new( FALSE, 0 ); - - /* Creating the RESET button. */ - button = AddPixButton( button_hbox, reset_xpm ); - gtk_signal_connect( GTK_OBJECT(button), "clicked", - GTK_SIGNAL_FUNC(emugtk_ResetEvent), - NULL ); - - /* Creating the RUN button. */ - button = AddPixButton( button_hbox, run_xpm ); - gtk_signal_connect( GTK_OBJECT(button), "clicked", - GTK_SIGNAL_FUNC(emugtk_RunEvent), - NULL ); - - /* Creating STOP button. */ - button = AddPixButton( button_hbox, stop_xpm ); - gtk_signal_connect( GTK_OBJECT(button), "clicked", - GTK_SIGNAL_FUNC(emugtk_StopEvent), - NULL ); - - /* Creating STEP button. */ - button = AddPixButton( button_hbox, step_xpm ); - gtk_signal_connect( GTK_OBJECT(button), "clicked", - GTK_SIGNAL_FUNC(emugtk_StepEvent), - NULL ); - - return button_hbox; + GtkWidget *button_hbox; + GtkWidget *button; + + /* The buttons of the hbox are NOT given equal space in the box. */ + button_hbox = gtk_hbox_new(FALSE, 0); + + /* Creating the RESET button. */ + button = AddPixButton(button_hbox, reset_xpm); + gtk_signal_connect(GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(emugtk_ResetEvent), + NULL); + + /* Creating the RUN button. */ + button = AddPixButton(button_hbox, run_xpm); + gtk_signal_connect(GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(emugtk_RunEvent), + NULL); + + /* Creating STOP button. */ + button = AddPixButton(button_hbox, stop_xpm); + gtk_signal_connect(GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(emugtk_StopEvent), + NULL); + + /* Creating STEP button. */ + button = AddPixButton(button_hbox, step_xpm); + gtk_signal_connect(GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(emugtk_StepEvent), + NULL); + + return button_hbox; } GtkWidget * -AddMenu( void ) +AddMenu(void) { - GtkWidget *menu_bar; + GtkWidget *menu_bar; - /* Creating menu item. */ - menu_bar = gtk_menu_bar_new(); + /* Creating menu item. */ + menu_bar = gtk_menu_bar_new(); - /* Adding the 'File' submenu */ - FileAddMenu( menu_bar ); + /* Adding the 'File' submenu */ + FileAddMenu(menu_bar); - /* Adding the 'View' submenu */ - ViewAddMenu( menu_bar ); - - /* Adding the 'Help' submenu */ - HelpAddMenu( menu_bar ); + /* Adding the 'View' submenu */ + ViewAddMenu(menu_bar); - gtk_widget_show_all( GTK_WIDGET( menu_bar ) ); - - return menu_bar; + /* Adding the 'Help' submenu */ + HelpAddMenu(menu_bar); + + gtk_widget_show_all(GTK_WIDGET(menu_bar)); + + return menu_bar; } static void -emugtk_window_init( void ) +emugtk_window_init(void) { - GtkWidget *main_vbox; - GtkWidget *menu_bar; - GtkWidget *buttons_bar; - GtkWidget *emufixed; - GtkWidget *fixed_frame; - - mainwin = gtk_window_new( GTK_WINDOW_TOPLEVEL ); - gtk_window_set_title( GTK_WINDOW(mainwin), PACKAGE ); - gtk_widget_set_usize( GTK_WIDGET(mainwin), MAIN_WIN_WIDTH, MAIN_WIN_HEIGHT ); - gtk_container_set_border_width( GTK_CONTAINER(mainwin), 0 ); - - /* Window DESTROY event. */ - gtk_signal_connect( GTK_OBJECT(mainwin), "destroy", GTK_SIGNAL_FUNC(WindowDestroyEvent), - NULL ); - - /* Setting main window geometry based on command line options (if specified). */ - /*MainWindowSetGeometry();*/ - - /* main_vbox contains the menu bar and body_vbox (for all remaining items). */ - main_vbox = gtk_vbox_new( FALSE, 1 ); - - /* Creating the menu bar. */ - menu_bar = AddMenu(); - /* Adding menu bar to main_vbox */ - gtk_box_pack_start( GTK_BOX(main_vbox), menu_bar, FALSE, FALSE, 1 ); - - /* Creating the buttons bar. */ - buttons_bar = AddButtons(); - /* Adding buttons bar to main_vbox */ - gtk_box_pack_start( GTK_BOX(main_vbox), buttons_bar, FALSE, FALSE, 1 ); - - /* Emulator fixed window. */ - emufixed = gtk_fixed_new(); - gtk_widget_set_usize( GTK_WIDGET( emufixed ), MAIN_WIN_WIDTH, - REG_WIN_HEIGHT + MEM_WIN_HEIGHT + 10 ); - - /* 8051 registers frame. */ - fixed_frame = regwin_init( REG_WIN_WIDTH, REG_WIN_HEIGHT ); - gtk_fixed_put( GTK_FIXED( emufixed ), fixed_frame, 0, 0 ); - - /* Program disassembly frame. */ - fixed_frame = pgmwin_init( PGM_WIN_WIDTH, PGM_WIN_HEIGHT ); - gtk_fixed_put( GTK_FIXED( emufixed ), fixed_frame, REG_WIN_WIDTH + 10, 0 ); - - /* Memory dump frame. */ - fixed_frame = memwin_init( MEM_WIN_WIDTH, MEM_WIN_HEIGHT ); - gtk_fixed_put( GTK_FIXED( emufixed ), fixed_frame, 0, REG_WIN_HEIGHT ); - - /* Adding fixed window to main_vbox */ - gtk_box_pack_start( GTK_BOX(main_vbox), emufixed, FALSE, FALSE, 1 ); - - /* Adding the main_vbox to the main window. */ - gtk_container_add( GTK_CONTAINER(mainwin), main_vbox ); - - gtk_widget_show_all( mainwin ); + GtkWidget *main_vbox; + GtkWidget *menu_bar; + GtkWidget *buttons_bar; + GtkWidget *emufixed; + GtkWidget *fixed_frame; + + mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(mainwin), PACKAGE); + gtk_widget_set_usize(GTK_WIDGET(mainwin), + MAIN_WIN_WIDTH, MAIN_WIN_HEIGHT); + gtk_container_set_border_width(GTK_CONTAINER(mainwin), 0); + + /* Window DESTROY event. */ + gtk_signal_connect(GTK_OBJECT(mainwin), "destroy", + GTK_SIGNAL_FUNC(WindowDestroyEvent), NULL); + + /* + * Setting main window geometry based on command line options + * (if specified). + */ + /*MainWindowSetGeometry();*/ + + /* + * main_vbox contains the menu bar and body_vbox (for all remaining + * items). + */ + main_vbox = gtk_vbox_new(FALSE, 1); + + /* Creating the menu bar. */ + menu_bar = AddMenu(); + /* Adding menu bar to main_vbox */ + gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar, FALSE, FALSE, 1); + + /* Creating the buttons bar. */ + buttons_bar = AddButtons(); + /* Adding buttons bar to main_vbox */ + gtk_box_pack_start(GTK_BOX(main_vbox), buttons_bar, FALSE, FALSE, 1); + + /* Emulator fixed window. */ + emufixed = gtk_fixed_new(); + gtk_widget_set_usize(GTK_WIDGET(emufixed), MAIN_WIN_WIDTH, + REG_WIN_HEIGHT + MEM_WIN_HEIGHT + 10); + + /* 8051 registers frame. */ + fixed_frame = regwin_init(REG_WIN_WIDTH, REG_WIN_HEIGHT); + gtk_fixed_put(GTK_FIXED(emufixed), fixed_frame, 0, 0); + + /* Program disassembly frame. */ + fixed_frame = pgmwin_init(PGM_WIN_WIDTH, PGM_WIN_HEIGHT); + gtk_fixed_put(GTK_FIXED(emufixed), fixed_frame, REG_WIN_WIDTH + 10, 0); + + /* Memory dump frame. */ + fixed_frame = memwin_init(MEM_WIN_WIDTH, MEM_WIN_HEIGHT); + gtk_fixed_put(GTK_FIXED(emufixed), fixed_frame, 0, REG_WIN_HEIGHT); + + /* Adding fixed window to main_vbox */ + gtk_box_pack_start(GTK_BOX(main_vbox), emufixed, FALSE, FALSE, 1); + + /* Adding the main_vbox to the main window. */ + gtk_container_add(GTK_CONTAINER(mainwin), main_vbox); + + gtk_widget_show_all(mainwin); } - -int -main( int argc, char **argv ) +void +emugtk_new_file(char *file) { - char *hex_file; + emugtk_StopRunning(); - ParseCommandLineOptions( argc, argv ); + LoadHexFile(file); - cpu8051_init(); + emugtk_Reset(); + emugtk_UpdateDisplay(); +} - RunningState = 0; - - gtk_init( &argc, &argv ); +int +main(int argc, char **argv) +{ + char *hex_file; - emugtk_window_init(); + ParseCommandLineOptions(argc, argv); - hex_file = get_hex_filename(); + cpu8051_init(); - if( hex_file != NULL ) { - emugtk_new_file( hex_file ); - } + RunningState = 0; - /*emugtk_Reset();*/ + gtk_init(&argc, &argv); - gtk_main(); + emugtk_window_init(); - printf( "End of program.\n" ); - - return EXIT_SUCCESS; -} + hex_file = get_hex_filename(); + if (hex_file != NULL) + emugtk_new_file(hex_file); -void -emugtk_new_file( char *file ) -{ - emugtk_StopRunning(); - - LoadHexFile( file ); - - emugtk_Reset(); - emugtk_UpdateDisplay(); -} - + gtk_main(); + printf("End of program.\n"); + return EXIT_SUCCESS; +} void -AddMenuSeparator( GtkWidget *menu ) +AddMenuSeparator(GtkWidget *menu) { - GtkWidget *item; - - item = gtk_menu_item_new(); - gtk_menu_append( GTK_MENU(menu), item ); -} + GtkWidget *item; + item = gtk_menu_item_new(); + gtk_menu_append(GTK_MENU(menu), item); +} void -emugtk_UpdateDisplay( void ) +emugtk_UpdateDisplay(void) { #ifdef EMU8051_DEBUG - g_print( "emugtk_UpdateDisplay()\n" ); + g_print("emugtk_UpdateDisplay()\n"); #endif - regwin_Show(); - pgmwin_Disasm(); - memwin_DumpD("0x00"); + regwin_Show(); + pgmwin_Disasm(); + memwin_DumpD("0x00"); } - - - - - - - - - - - - -////////////////////////////////////////////////////////////////////////////// -// CPU reset and Gtk UI update -////////////////////////////////////////////////////////////////////////////// +/* CPU reset and Gtk UI update */ void -emugtk_Reset( void ) +emugtk_Reset(void) { - cpu8051_Reset( ); - regwin_Show(); - pgmwin_Disasm(); - memwin_DumpD("0x00"); + cpu8051_Reset(); + regwin_Show(); + pgmwin_Disasm(); + memwin_DumpD("0x00"); } - -////////////////////////////////////////////////////////////////////////////// -// CPU Step and Gtk UI update -////////////////////////////////////////////////////////////////////////////// +/* CPU Step and Gtk UI update */ void -emugtk_Step( void ) +emugtk_Step(void) { - cpu8051_Exec(); - regwin_Show(); - pgmwin_Disasm(); - memwin_DumpD("0x00"); + cpu8051_Exec(); + regwin_Show(); + pgmwin_Disasm(); + memwin_DumpD("0x00"); } - -////////////////////////////////////////////////////////////////////////////// -// Signal ResetEvent ( ResetButton ) -////////////////////////////////////////////////////////////////////////////// +/* Signal ResetEvent (ResetButton) */ void -emugtk_ResetEvent( GtkWidget *widget, GdkEvent *event, gpointer data ) +emugtk_ResetEvent(GtkWidget *widget, GdkEvent *event, gpointer data) { #ifdef EMU8051_DEBUG - g_print( "emugtk_ResetEvent(...)\n" ); + g_print("emugtk_ResetEvent(...)\n"); #endif - emugtk_StopRunning( ); - emugtk_Reset( ); + emugtk_StopRunning(); + emugtk_Reset(); } - -////////////////////////////////////////////////////////////////////////////// -// Signal RunEvent ( RunButton ) -////////////////////////////////////////////////////////////////////////////// +/* Signal RunEvent (RunButton) */ void -emugtk_RunEvent( GtkWidget *widget, GdkEvent *event, gpointer data ) +emugtk_RunEvent(GtkWidget *widget, GdkEvent *event, gpointer data) { #ifdef EMU8051_DEBUG - g_print( "emugtk_RunEvent(...)\n" ); + g_print("emugtk_RunEvent(...)\n"); #endif - if ( RunningState ) { - // g_print( "Getting out of RunningState! \n" ); - emugtk_StopRunning( ); - } - else { - // g_print( "Going In RunningState! \n" ); - emugtk_StartRunning( ); - } + if (RunningState) + emugtk_StopRunning(); + else + emugtk_StartRunning(); } - -////////////////////////////////////////////////////////////////////////////// -// Signal StopEvent ( StopButton ) -////////////////////////////////////////////////////////////////////////////// +/* Signal StopEvent (StopButton) */ void -emugtk_StopEvent( GtkWidget *widget, GdkEvent *event, gpointer data ) +emugtk_StopEvent(GtkWidget *widget, GdkEvent *event, gpointer data) { #ifdef EMU8051_DEBUG - g_print( "emugtk_StopEvent(...)\n" ); + g_print("emugtk_StopEvent(...)\n"); #endif - emugtk_StopRunning( ); + emugtk_StopRunning(); } - -////////////////////////////////////////////////////////////////////////////// -// Signal StepEvent ( StepButton ) -////////////////////////////////////////////////////////////////////////////// +/* Signal StepEvent (StepButton) */ void -emugtk_StepEvent( GtkWidget *widget, GdkEvent *event, gpointer data ) +emugtk_StepEvent(GtkWidget *widget, GdkEvent *event, gpointer data) { #ifdef EMU8051_DEBUG - g_print( "emugtk_StepEvent(...)\n" ); + g_print("emugtk_StepEvent(...)\n"); #endif - emugtk_StopRunning( ); - emugtk_Step(); + emugtk_StopRunning(); + emugtk_Step(); } - -////////////////////////////////////////////////////////////////////////////// -// Running called by RunningFunction( ) -////////////////////////////////////////////////////////////////////////////// +/* Running called by RunningFunction() */ void -emugtk_Running( ) +emugtk_Running() { - cpu8051_Exec( ); - if( pgmwin_IsBreakpoint( cpu8051.pc ) ) { + cpu8051_Exec(); + if (IsBreakpoint(cpu8051.pc)) { #ifdef EMU8051_DEBUG - g_print( "Breakpoint Hit, stopping!\n" ); + g_print("Breakpoint Hit, stopping!\n"); #endif - emugtk_StopRunning( ); - } + emugtk_StopRunning(); + } } - -////////////////////////////////////////////////////////////////////////////// -// RunningFunction called when idle from gtk_main -////////////////////////////////////////////////////////////////////////////// +/* RunningFunction called when idle from gtk_main */ gboolean -RunningFunction( gpointer data ) +RunningFunction(gpointer data) { - emugtk_Running( ); - return TRUE; + emugtk_Running(); + return TRUE; } - -////////////////////////////////////////////////////////////////////////////// -// Get in the RunningState -////////////////////////////////////////////////////////////////////////////// +/* Get in the RunningState */ void -emugtk_StartRunning( void ) +emugtk_StartRunning(void) { - if ( !RunningState ) { + if (!RunningState) { #ifdef EMU8051_DEBUG - printf( "emugtk_StartRunning( )\n" ); + printf("emugtk_StartRunning()\n"); #endif - RunFuncTag = gtk_idle_add( RunningFunction, 0 ); + RunFuncTag = gtk_idle_add(RunningFunction, 0); - RunningState = 1; - } + RunningState = 1; + } } - -////////////////////////////////////////////////////////////////////////////// -// Step out of RunningState -////////////////////////////////////////////////////////////////////////////// +/* Step out of RunningState */ void -emugtk_StopRunning( ) +emugtk_StopRunning() { - if (RunningState) { + if (RunningState) { #ifdef EMU8051_DEBUG - printf( "emugtk_StopRunning( )\n" ); + printf("emugtk_StopRunning()\n"); #endif - gtk_idle_remove( RunFuncTag ); - RunningState = 0; - regwin_Show(); - pgmwin_Disasm(); - memwin_DumpD("0x00"); - } + gtk_idle_remove(RunFuncTag); + RunningState = 0; + regwin_Show(); + pgmwin_Disasm(); + memwin_DumpD("0x00"); + } } diff --git a/src/emugtk.h b/src/emugtk.h index b5c48c4..fe13a45 100644 --- a/src/emugtk.h +++ b/src/emugtk.h @@ -22,35 +22,42 @@ #ifndef EMUGTK_H #define EMUGTK_H 1 - #include #include "gtksizes.h" +void +AddMenuSeparator(GtkWidget *menu); void -AddMenuSeparator( GtkWidget *menu ); +emugtk_new_file(char *file); void -emugtk_new_file( char *file ); +emugtk_StopRunning(void); void -emugtk_StopRunning( void ); +emugtk_Reset(void); void -emugtk_Reset( void ); +emugtk_UpdateDisplay(void); + +void emugtk_Step(void); void -emugtk_UpdateDisplay( void ); +emugtk_ResetEvent(GtkWidget *widget, GdkEvent *event, gpointer data); -void emugtk_Step( ); +void +emugtk_RunEvent(GtkWidget *widget, GdkEvent *event, gpointer data); -void emugtk_ResetEvent( GtkWidget *widget, GdkEvent *event, gpointer data ); -void emugtk_RunEvent( GtkWidget *widget, GdkEvent *event, gpointer data ); -void emugtk_StopEvent( GtkWidget *widget, GdkEvent *event, gpointer data ); -void emugtk_StepEvent( GtkWidget *widget, GdkEvent *event, gpointer data ); +void +emugtk_StopEvent(GtkWidget *widget, GdkEvent *event, gpointer data); -void emugtk_StartRunning( ); +void +emugtk_StepEvent(GtkWidget *widget, GdkEvent *event, gpointer data); + +void +emugtk_StartRunning(void); -void emugtk_Running( ); +void +emugtk_Running(void); #endif /* EMUGTK_H */ diff --git a/src/filemenu.c b/src/filemenu.c index 96a977d..bb7489c 100644 --- a/src/filemenu.c +++ b/src/filemenu.c @@ -32,101 +32,105 @@ #include "messagebox.h" #include "filemenu.h" - #define FILENAME_DESCRIPTION "Open Intel Hex file" - static void -FileOpenDialog_OK( GtkWidget *widget, gpointer file_dialog ) +FileOpenDialog_OK(GtkWidget *widget, gpointer file_dialog) { - char *selected_file; + char *selected_file; #if defined(DEBUG) - g_print( "FileOpenDialog_OK()\n" ); + g_print("FileOpenDialog_OK()\n"); #endif - - /* The cast to (char *) is to remove a warning in GTK2, because the return value of the - gtk_file_selection_get_filename() function is 'G_CONST_RETURN gchar *'. */ - selected_file = - (char *) gtk_file_selection_get_filename( GTK_FILE_SELECTION(file_dialog) ); - g_print( "emugtk_File = %s\n", selected_file ); + /* + * The cast to (char *) is to remove a warning in GTK2, because the + * return value of the gtk_file_selection_get_filename() function is + * 'G_CONST_RETURN gchar *'. + */ + selected_file = (char *) gtk_file_selection_get_filename( + GTK_FILE_SELECTION(file_dialog)); - emugtk_new_file( selected_file ); + g_print("emugtk_File = %s\n", selected_file); - gtk_widget_destroy( GTK_WIDGET(file_dialog) ); -} + emugtk_new_file(selected_file); + gtk_widget_destroy(GTK_WIDGET(file_dialog)); +} void -FileOpenEvent( GtkObject *object, gpointer data ) +FileOpenEvent(GtkObject *object, gpointer data) { - GtkWidget *file_dialog; + GtkWidget *file_dialog; #if defined(DEBUG) - g_print( "FileOpenEvent()\n" ); + g_print("FileOpenEvent()\n"); #endif - /* Create a new file selection widget. */ - file_dialog = gtk_file_selection_new( FILENAME_DESCRIPTION ); - - /* Connect the file dialog's OK button up to a handler. */ - gtk_signal_connect( GTK_OBJECT( GTK_FILE_SELECTION(file_dialog)->ok_button ), "clicked", - GTK_SIGNAL_FUNC(FileOpenDialog_OK), file_dialog ); - - /* Ensure that the file selection dialog box is destroyed when the user clicks CANCEL. */ - gtk_signal_connect_object( GTK_OBJECT( GTK_FILE_SELECTION(file_dialog)->cancel_button), - "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), - (gpointer) file_dialog ); - - /* Set the 'File Open dialog' to show only Intel HEX files (.hex). */ - /* gtk_file_selection_complete( GTK_FILE_SELECTION( FileOpendialog ), "*.hex" ); */ - - /* Show the dialog. */ - gtk_widget_show( GTK_WIDGET(file_dialog) ); - - /* To have the main window of our application being unusable while using the dialog. */ - gtk_window_set_modal( GTK_WINDOW(file_dialog), TRUE ); + /* Create a new file selection widget. */ + file_dialog = gtk_file_selection_new(FILENAME_DESCRIPTION); + + /* Connect the file dialog's OK button up to a handler. */ + gtk_signal_connect( + GTK_OBJECT(GTK_FILE_SELECTION(file_dialog)->ok_button), + "clicked", GTK_SIGNAL_FUNC(FileOpenDialog_OK), file_dialog); + + /* + * Ensure that the file selection dialog box is destroyed when the user + * clicks CANCEL. + */ + gtk_signal_connect_object( + GTK_OBJECT(GTK_FILE_SELECTION(file_dialog)->cancel_button), + "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), + (gpointer) file_dialog); + + /* Show the dialog. */ + gtk_widget_show(GTK_WIDGET(file_dialog)); + + /* + * To have the main window of our application being unusable while + * using the dialog. + */ + gtk_window_set_modal(GTK_WINDOW(file_dialog), TRUE); } - static void -FileQuitEvent( gchar *string ) +FileQuitEvent(gchar *string) { #if defined(DEBUG) - g_print( "%s\n", string ); + g_print("%s\n", string); #endif - emugtk_StopRunning(); - gtk_main_quit(); + emugtk_StopRunning(); + gtk_main_quit(); } - void -FileAddMenu( GtkWidget *menu_bar ) +FileAddMenu(GtkWidget *menu_bar) { - GtkWidget *item; - GtkWidget *menu; - - menu = gtk_menu_new(); - - /* Create the 'open' item. */ - item = gtk_menu_item_new_with_label( FILENAME_DESCRIPTION ); - gtk_menu_append( GTK_MENU(menu), item ); - /* Attach the callback functions to the activate signal. */ - gtk_signal_connect_object( GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(FileOpenEvent), - NULL ); - - AddMenuSeparator(menu); - - item = gtk_menu_item_new_with_label("Exit"); - gtk_menu_append( GTK_MENU(menu), item ); - /* We can attach the Quit menu item to our exit function */ - gtk_signal_connect_object( GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(FileQuitEvent), - (gpointer) "file.quit" ); - - /* Adding submenu title. */ - item = gtk_menu_item_new_with_label( "File" ); - gtk_menu_item_set_submenu( GTK_MENU_ITEM(item), menu ); - gtk_menu_bar_append( GTK_MENU_BAR( menu_bar ), item ); + GtkWidget *item; + GtkWidget *menu; + + menu = gtk_menu_new(); + + /* Create the 'open' item. */ + item = gtk_menu_item_new_with_label(FILENAME_DESCRIPTION); + gtk_menu_append(GTK_MENU(menu), item); + /* Attach the callback functions to the activate signal. */ + gtk_signal_connect_object(GTK_OBJECT(item), "activate", + GTK_SIGNAL_FUNC(FileOpenEvent), NULL); + + AddMenuSeparator(menu); + + item = gtk_menu_item_new_with_label("Exit"); + gtk_menu_append(GTK_MENU(menu), item); + /* We can attach the Quit menu item to our exit function */ + gtk_signal_connect_object(GTK_OBJECT(item), "activate", + GTK_SIGNAL_FUNC(FileQuitEvent), + (gpointer) "file.quit"); + + /* Adding submenu title. */ + item = gtk_menu_item_new_with_label("File"); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu); + gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), item); } diff --git a/src/filemenu.h b/src/filemenu.h index 51023b8..fe9688a 100644 --- a/src/filemenu.h +++ b/src/filemenu.h @@ -22,18 +22,15 @@ #ifndef FILEMENU_H #define FILEMENU_H 1 - #include - void -FileOpenEvent( GtkObject *object, gpointer data ); +FileOpenEvent(GtkObject *object, gpointer data); void -FileResetEvent( GtkObject *object, gpointer data ); +FileResetEvent(GtkObject *object, gpointer data); void -FileAddMenu( GtkWidget *menu_bar ); - +FileAddMenu(GtkWidget *menu_bar); #endif /* FILEMENU_H */ diff --git a/src/helpmenu.c b/src/helpmenu.c index 850bfc8..bd3d4ec 100644 --- a/src/helpmenu.c +++ b/src/helpmenu.c @@ -37,50 +37,48 @@ #include "messagebox.h" #include "helpmenu.h" - static void -HelpCommandsEvent( gchar *string ) +HelpCommandsEvent(gchar *string) { - ShowMessage( "Command Line Options", COMMAND_LINE_OPTIONS, GTK_JUSTIFY_LEFT, - MESSAGE_DIALOG_FIXED_FONT ); + ShowMessage("Command Line Options", COMMAND_LINE_OPTIONS, + GTK_JUSTIFY_LEFT, MESSAGE_DIALOG_FIXED_FONT); } - static void -HelpAboutEvent( gchar *string ) +HelpAboutEvent(gchar *string) { - ShowMessage( "About", VERSION_STRING, GTK_JUSTIFY_CENTER, MESSAGE_DIALOG_NORMAL_FONT ); + ShowMessage("About", VERSION_STRING, GTK_JUSTIFY_CENTER, + MESSAGE_DIALOG_NORMAL_FONT); } - void -HelpAddMenu( GtkWidget *menu_bar ) +HelpAddMenu(GtkWidget *menu_bar) { - GtkWidget *item; - GtkWidget *menu; - - menu = gtk_menu_new(); + GtkWidget *item; + GtkWidget *menu; + + menu = gtk_menu_new(); + + /* Create the 'Help Command Line Options' item. */ + item = gtk_menu_item_new_with_label("Command Line Options"); + gtk_menu_append(GTK_MENU(menu), item); + /* Attach the callback functions to the activate signal. */ + gtk_signal_connect_object(GTK_OBJECT(item), "activate", + GTK_SIGNAL_FUNC(HelpCommandsEvent), + NULL); - /* Create the 'Help Command Line Options' item. */ - item = gtk_menu_item_new_with_label("Command Line Options"); - gtk_menu_append( GTK_MENU(menu), item ); - /* Attach the callback functions to the activate signal. */ - gtk_signal_connect_object( GTK_OBJECT(item), "activate", - GTK_SIGNAL_FUNC(HelpCommandsEvent), - NULL ); + AddMenuSeparator(menu); - AddMenuSeparator(menu); + /* Create the 'Help About' item. */ + item = gtk_menu_item_new_with_label("About " PACKAGE); + gtk_menu_append(GTK_MENU(menu), item); + /* Attach the callback functions to the activate signal. */ + gtk_signal_connect_object(GTK_OBJECT(item), "activate", + GTK_SIGNAL_FUNC(HelpAboutEvent), + NULL); - /* Create the 'Help About' item. */ - item = gtk_menu_item_new_with_label( "About " PACKAGE ); - gtk_menu_append( GTK_MENU(menu), item ); - /* Attach the callback functions to the activate signal. */ - gtk_signal_connect_object( GTK_OBJECT(item), "activate", - GTK_SIGNAL_FUNC(HelpAboutEvent), - NULL ); - - /* Adding submenu title. */ - item = gtk_menu_item_new_with_label( "Help" ); - gtk_menu_item_set_submenu( GTK_MENU_ITEM(item), menu ); - gtk_menu_bar_append( GTK_MENU_BAR( menu_bar ), item ); + /* Adding submenu title. */ + item = gtk_menu_item_new_with_label("Help"); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu); + gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), item); } diff --git a/src/helpmenu.h b/src/helpmenu.h index 0781539..63908dd 100644 --- a/src/helpmenu.h +++ b/src/helpmenu.h @@ -24,9 +24,7 @@ #include - void -HelpAddMenu( GtkWidget *menu_bar ); - +HelpAddMenu(GtkWidget *menu_bar); #endif /* HELPMENU_H */ diff --git a/src/hexfile.c b/src/hexfile.c index 0f473d4..9716aad 100644 --- a/src/hexfile.c +++ b/src/hexfile.c @@ -38,42 +38,38 @@ /* Convert an ascii string to an hexadecimal number. */ unsigned int -Ascii2Hex( char *istring, int length ) +Ascii2Hex(char *istring, int length) { unsigned int result = 0; int i, ascii_code; - if ( !length || ( length > (int) strlen(istring) ) ) { + if (!length || (length > (int) strlen(istring))) length = strlen(istring); - } - - for ( i = 0; i < length; i++ ) { - ascii_code = istring[ i ]; - if ( ascii_code > 0x39 ) { + + for (i = 0; i < length; i++) { + ascii_code = istring[i]; + if (ascii_code > 0x39) ascii_code &= 0xDF; - } - if ( ( ascii_code >= 0x30 && ascii_code <= 0x39 ) || - ( ascii_code >= 0x41 && ascii_code <= 0x46 ) ) { + + if ((ascii_code >= 0x30 && ascii_code <= 0x39) || + (ascii_code >= 0x41 && ascii_code <= 0x46)) { ascii_code -= 0x30; - if ( ascii_code > 9 ) { + if (ascii_code > 9) ascii_code -= 7; - } + result <<= 4; result += ascii_code; - } - else { - printf( "%s: In Ascii2Hex(), syntax error.\n", PACKAGE ); - } + } else + printf("%s: In Ascii2Hex(), syntax error.\n", PACKAGE); } return result; } - void -LoadHexFile( const char *filename ) +LoadHexFile(const char *filename) { int i, j, RecLength, LoadOffset, RecType, Data, Checksum; - + #define LINE_BUFFER_LEN 256 FILE *fp; int status; @@ -85,74 +81,79 @@ LoadHexFile( const char *filename ) } /* Trying to open the file. */ - fp = fopen( filename, "r" ); - if( fp == NULL ) { - perror( PACKAGE ); - /*ErrorLocation( __FILE__, __LINE__ );*/ - exit( EXIT_FAILURE ); + fp = fopen(filename, "r"); + if (fp == NULL) { + perror(PACKAGE); + /*ErrorLocation(__FILE__, __LINE__);*/ + exit(EXIT_FAILURE); } - + /* Reading one line of data from the hex file. */ /* char *fgets(char *s, int size, FILE *stream); - Reading stops after an EOF or a newline. If a newline is read, it is - stored into the buffer. A '\0' is stored after the last character in - the buffer. */ - while( fgets( line, LINE_BUFFER_LEN, fp ) != NULL ) { + Reading stops after an EOF or a newline. If a newline is read, it is + stored into the buffer. A '\0' is stored after the last character + in the buffer. + */ + while (fgets(line, LINE_BUFFER_LEN, fp) != NULL) { i = 0; Checksum = 0; - if ( line[ i++ ] != ':' ) { - printf( "%s: line not beginning with \":\"\n", PACKAGE ); + if (line[i++] != ':') { + printf("%s: line not beginning with \":\"\n", PACKAGE); goto close_file; } - - RecLength = Ascii2Hex( &line[ i ], 2 ); + + RecLength = Ascii2Hex(&line[i], 2); i += 2; Checksum += RecLength; - - LoadOffset = Ascii2Hex( &line[i], 4 ); + + LoadOffset = Ascii2Hex(&line[i], 4); Checksum += LoadOffset / 256; Checksum += LoadOffset % 256; i += 4; - - RecType = Ascii2Hex( &line[i],2); + + RecType = Ascii2Hex(&line[i], 2); i += 2; Checksum += RecType; - - if ( RecType == 1 ) { - Checksum += Ascii2Hex( &line[ i ], 2 ); - if ( Checksum &= 0x000000FF ) { + + if (RecType == 1) { + Checksum += Ascii2Hex(&line[i], 2); + Checksum &= 0x000000FF; + + if (Checksum) { /* Error. */ - printf( "%s: Invalid format\n", PACKAGE ); + printf("%s: Invalid format\n", PACKAGE); goto close_file; - } - else { + } else { /* OK */ goto close_file; } - } - - for ( j = 0; j < RecLength; j++ ) { - Data = Ascii2Hex( &line[ i ], 2 ); - memory_write8( PGM_MEM_ID, (unsigned int)(LoadOffset + j), (unsigned char)Data ); + } + + for (j = 0; j < RecLength; j++) { + Data = Ascii2Hex(&line[i], 2); + memory_write8(PGM_MEM_ID, + (unsigned int)(LoadOffset + j), + (unsigned char)Data); i += 2; Checksum += Data; } - - RecType = Ascii2Hex( &line[ i ], 2 ); - Checksum += RecType; - - if ( Checksum &= 0x000000FF ) { - printf( "%s: Invalid format\n", PACKAGE ); + + RecType = Ascii2Hex(&line[i], 2); + Checksum += RecType; + Checksum &= 0x000000FF; + + if (Checksum) { + printf("%s: Invalid format\n", PACKAGE); goto close_file; } } - + close_file: - status = fclose( fp ); - if( status != EXIT_SUCCESS ) { - fprintf( stderr, "%s: Error closing hex file.\n", PACKAGE ); - /*ErrorLocation( __FILE__, __LINE__ );*/ - exit( EXIT_FAILURE ); + status = fclose(fp); + if (status != EXIT_SUCCESS) { + fprintf(stderr, "%s: Error closing hex file.\n", PACKAGE); + /*ErrorLocation(__FILE__, __LINE__);*/ + exit(EXIT_FAILURE); } } diff --git a/src/hexfile.h b/src/hexfile.h index 4795bf8..ea27f1f 100644 --- a/src/hexfile.h +++ b/src/hexfile.h @@ -26,6 +26,6 @@ unsigned int Ascii2Hex(char *istring, int length); void -LoadHexFile( const char *filename ); +LoadHexFile(const char *filename); #endif /* HEXFILE_H */ diff --git a/src/keyboard.c b/src/keyboard.c index e46568a..654087e 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -30,13 +30,14 @@ kbhit(void) { char ch; int nread; - if(peek != -1) return 1; - newtio.c_cc[VMIN]=0; + if (peek != -1) + return 1; + newtio.c_cc[VMIN] = 0; tcsetattr(0, TCSANOW, &newtio); - nread = read(0,&ch,1); - newtio.c_cc[VMIN]=1; + nread = read(0, &ch, 1); + newtio.c_cc[VMIN] = 1; tcsetattr(0, TCSANOW, &newtio); - if(nread == 1) { + if (nread == 1) { peek = ch; return 1; } @@ -47,12 +48,12 @@ int getch(void) { char ch; - if(peek != -1) { + if (peek != -1) { ch = peek; peek = -1; return ch; } - read(0,&ch,1); + read(0, &ch, 1); return ch; } @@ -72,5 +73,5 @@ InitUnixKB(void) void ResetUnixKB(void) { - tcsetattr(0,TCSANOW, &orig); + tcsetattr(0, TCSANOW, &orig); } diff --git a/src/memory.c b/src/memory.c index 202d8d3..5e820ab 100644 --- a/src/memory.c +++ b/src/memory.c @@ -37,36 +37,30 @@ static u_int8_t int_mem[INT_MEM_SIZE]; static u_int8_t ext_mem[EXT_MEM_SIZE]; void -memory_write8( int memory_id, unsigned long address, u_int8_t value ) +memory_write8(int memory_id, unsigned long address, u_int8_t value) { - switch( memory_id ) { + switch (memory_id) { case PGM_MEM_ID: - if( address >= PGM_MEM_SIZE ) { + if (address >= PGM_MEM_SIZE) { printf("Address is greater than PGM_MEM_SIZE\n"); return; - } - else { + } else pgm_mem[address] = value; - } break; case INT_MEM_ID: - if( address >= INT_MEM_SIZE) { + if (address >= INT_MEM_SIZE) { printf("Address is greater than INT_MEM_SIZE\n"); return; - } - else { + } else int_mem[address] = value; - } break; case EXT_MEM_ID: - if( address >= EXT_MEM_SIZE ) { + if (address >= EXT_MEM_SIZE) { printf("Address is greater than EXT_MEM_SIZE\n"); return; - } - else { + } else ext_mem[address] = value; - } - break; + break; default: /* Error. */ break; @@ -74,36 +68,33 @@ memory_write8( int memory_id, unsigned long address, u_int8_t value ) } u_int8_t -memory_read8( int memory_id, unsigned long address ) +memory_read8(int memory_id, unsigned long address) { - switch( memory_id ) { + switch (memory_id) { case PGM_MEM_ID: - if( address < PGM_MEM_SIZE ) { + if (address < PGM_MEM_SIZE) return pgm_mem[address]; - } else { printf("Address is greater than PGM_MEM_SIZE\n"); return 0; } break; case INT_MEM_ID: - if( address < INT_MEM_SIZE ) { + if (address < INT_MEM_SIZE) return int_mem[address]; - } else { printf("Address is greater than INT_MEM_SIZE\n"); return 0; } break; case EXT_MEM_ID: - if( address < EXT_MEM_SIZE ) { + if (address < EXT_MEM_SIZE) return ext_mem[address]; - } else { printf("Address is greater than EXT_MEM_SIZE\n"); return 0; } - break; + break; default: /* Error. */ return 0; diff --git a/src/memory.h b/src/memory.h index 55a034a..892e17a 100644 --- a/src/memory.h +++ b/src/memory.h @@ -31,10 +31,10 @@ enum { }; void -memory_write8( int memory_id, unsigned long address, u_int8_t value ); +memory_write8(int memory_id, unsigned long address, u_int8_t value); u_int8_t -memory_read8( int memory_id, unsigned long address ); +memory_read8(int memory_id, unsigned long address); void DumpMem(char *buf, char *Address, int memory_id); diff --git a/src/memwin.c b/src/memwin.c index 4387f46..37cc8e0 100644 --- a/src/memwin.c +++ b/src/memwin.c @@ -34,98 +34,93 @@ static GtkWidget *memclist; GtkWidget * -memwin_init( int width, int height ) +memwin_init(int width, int height) { - int i; - GtkWidget *fixed_frame; - - fixed_frame = gtk_frame_new(0); - gtk_frame_set_shadow_type( GTK_FRAME( fixed_frame ), GTK_SHADOW_ETCHED_OUT ); - gtk_widget_set_usize( GTK_WIDGET( fixed_frame ), width, height ); - - memclist = gtk_clist_new( 18 ); - gtk_clist_set_selection_mode( GTK_CLIST( memclist ), GTK_SELECTION_SINGLE ); - gtk_widget_set_usize( GTK_WIDGET( memclist ), 620, 250 ); - - for( i = 0; i < 18; i++ ) { - gtk_clist_set_column_justification( GTK_CLIST( memclist ), i, GTK_JUSTIFY_LEFT ); - } - - gtk_clist_set_column_width( GTK_CLIST( memclist ), 0, 5*8 ); - - for( i = 1; i < 17; i++ ) { - gtk_clist_set_column_width( GTK_CLIST( memclist ), i, 2*8 ); - } - - gtk_clist_set_column_width( GTK_CLIST( memclist ), 17, 16*8 ); - -#if ( GTK_MAJOR_VERSION == 2) - PangoFontDescription *pango_font; - pango_font = pango_font_description_from_string( FIXED_FONT ); - gtk_widget_modify_font( memclist, pango_font ); -#else - { - GtkStyle *style; - /* Setting font for the widget. */ - style = gtk_style_new(); - gdk_font_unref( style->font ); - - /* Load a fixed font */ - style->font = gdk_font_load( FIXED_FONT ); - gtk_widget_set_style( GTK_WIDGET( memclist ), style ); - } -#endif + int i; + GtkWidget *fixed_frame; + PangoFontDescription *pango_font; + char *memdummy[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - char *memdummy[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; - for( i = 0; i < 16; i++ ) { - gtk_clist_append( GTK_CLIST( memclist ), memdummy ); - } + fixed_frame = gtk_frame_new(0); + gtk_frame_set_shadow_type(GTK_FRAME(fixed_frame), + GTK_SHADOW_ETCHED_OUT); + gtk_widget_set_usize(GTK_WIDGET(fixed_frame), width, height); - gtk_container_add( GTK_CONTAINER( fixed_frame ), memclist ); + memclist = gtk_clist_new(18); + gtk_clist_set_selection_mode(GTK_CLIST(memclist), GTK_SELECTION_SINGLE); + gtk_widget_set_usize(GTK_WIDGET(memclist), 620, 250); - return fixed_frame; -} + for (i = 0; i < 18; i++) { + gtk_clist_set_column_justification( + GTK_CLIST(memclist), i, GTK_JUSTIFY_LEFT); + } + + gtk_clist_set_column_width(GTK_CLIST(memclist), 0, 5*8); + + for (i = 1; i < 17; i++) + gtk_clist_set_column_width(GTK_CLIST(memclist), i, 2 * 8); + + gtk_clist_set_column_width(GTK_CLIST(memclist), 17, 16 * 8); + pango_font = pango_font_description_from_string(FIXED_FONT); + gtk_widget_modify_font(memclist, pango_font); + + for (i = 0; i < 16; i++) + gtk_clist_append(GTK_CLIST(memclist), memdummy); + + gtk_container_add(GTK_CONTAINER(fixed_frame), memclist); + + return fixed_frame; +} + /* Dump 16 rows of 16 bytes from Address in Memory (direct addressing) */ void memwin_DumpD(char *MemAddress) { - char TextTmp[1024]; - int row, column, TextLength; - unsigned int Address; - - if (strlen(MemAddress) != 0) { - if (STREQ(MemAddress, "PC")) - Address = cpu8051.pc; - else - Address = Ascii2Hex(MemAddress, strlen(MemAddress)); - } else { - Address = 0; - } - - gtk_clist_freeze( GTK_CLIST( memclist ) ); - - for ( row = 0; row < 16; row++ ) { - sprintf( TextTmp, "%.4X", Address ); - gtk_clist_set_text( GTK_CLIST( memclist ), row, 0, TextTmp ); - - for ( column = 0; column < 16; column++ ) { - sprintf( TextTmp, "%.2X", ( int ) cpu8051_ReadD( Address + column ) ); - gtk_clist_set_text( GTK_CLIST( memclist ), row, column + 1, TextTmp ); - } - - TextLength = 0; - for ( column = 0; column < 16; column++ ) { - if ( ( ( int ) cpu8051_ReadD( Address + column ) >= 32 ) && ( ( int ) cpu8051_ReadD( Address + column ) <= 126 ) ) - TextLength += sprintf( &TextTmp[ TextLength ], "%c", cpu8051_ReadD( Address + column ) ); - else TextLength += sprintf( &TextTmp[ TextLength ], "." ); - } - gtk_clist_set_text( GTK_CLIST( memclist ), row, 17, TextTmp ); - - Address += 16; - } - - gtk_clist_select_row( GTK_CLIST( memclist ), 0, 0 ); - gtk_clist_thaw( GTK_CLIST( memclist ) ); + char TextTmp[1024]; + int row, column, TextLength; + unsigned int Address; + + if (strlen(MemAddress) != 0) { + if (STREQ(MemAddress, "PC")) + Address = cpu8051.pc; + else + Address = Ascii2Hex(MemAddress, strlen(MemAddress)); + } else { + Address = 0; + } + + gtk_clist_freeze(GTK_CLIST(memclist)); + + for (row = 0; row < 16; row++) { + sprintf(TextTmp, "%.4X", Address); + gtk_clist_set_text(GTK_CLIST(memclist), row, 0, TextTmp); + + for (column = 0; column < 16; column++) { + sprintf(TextTmp, "%.2X", + (int) cpu8051_ReadD(Address + column)); + gtk_clist_set_text(GTK_CLIST(memclist), row, + column + 1, TextTmp); + } + + TextLength = 0; + for (column = 0; column < 16; column++) { + if (((int) cpu8051_ReadD(Address + column) >= 32) && + ((int) cpu8051_ReadD(Address + column) <= 126)) + TextLength += sprintf( + &TextTmp[TextLength], + "%c", cpu8051_ReadD(Address + column)); + else + TextLength += + sprintf(&TextTmp[TextLength], "."); + } + gtk_clist_set_text(GTK_CLIST(memclist), row, 17, TextTmp); + + Address += 16; + } + + gtk_clist_select_row(GTK_CLIST(memclist), 0, 0); + gtk_clist_thaw(GTK_CLIST(memclist)); } diff --git a/src/messagebox.c b/src/messagebox.c index 3debfeb..15019a7 100644 --- a/src/messagebox.c +++ b/src/messagebox.c @@ -28,124 +28,136 @@ #include "common.h" #include "messagebox.h" - #define MESSAGE_DIALOG_BORDER 25 #define BUTTON_TEXT_BORDER 3 - /* This function is used to adjust the border around the text in a button. */ static GtkWidget * -AddTextButton( gchar *button_text ) +AddTextButton(gchar *button_text) { - GtkWidget *button; - GtkWidget *label; - GtkWidget *label_window; - - /* The GtkLabel widget is one of a few GTK+ widgets that don't create their own window to - render themselves into. Instead, they draw themselves directly onto their parents - window. This means that in order to set a property for a GtkLabel widget, you need to - change the property of its parent, i.e. the object that you pack it into. - Another solution (short term workaround) is to put the label widget inside another - widget that does get its own window, like the 'ViewPort' or 'EventBox' widget. */ - - /* Using workaround described above to set the border width of 'label' widget. */ - label_window = gtk_event_box_new(); - - /* Creating our label. */ - label = gtk_label_new(button_text); - - /* Adding label widget to label_window widget. */ - gtk_container_add( GTK_CONTAINER(label_window), label ); - - /* Changing border width of the label widget by way of label_window widget. */ - gtk_container_set_border_width( GTK_CONTAINER(label_window), BUTTON_TEXT_BORDER ); - - /* Create the button. */ - button = gtk_button_new(); - - /* Adding label to button. */ - gtk_container_add( GTK_CONTAINER(button), label_window ); - - return button; + GtkWidget *button; + GtkWidget *label; + GtkWidget *label_window; + + /* + * The GtkLabel widget is one of a few GTK+ widgets that don't create + * their own window to render themselves into. Instead, they draw + * themselves directly onto their parents window. This means that in + * order to set a property for a GtkLabel widget, you need to change the + * property of its parent, i.e. the object that you pack it into. + * Another solution (short term workaround) is to put the label widget + * inside another widget that does get its own window, like the + * 'ViewPort' or 'EventBox' widget. + */ + + /* + * Using workaround described above to set the border width of 'label' + * widget. + */ + label_window = gtk_event_box_new(); + + /* Creating our label. */ + label = gtk_label_new(button_text); + + /* Adding label widget to label_window widget. */ + gtk_container_add(GTK_CONTAINER(label_window), label); + + /* + * Changing border width of the label widget by way of label_window + * widget. + */ + gtk_container_set_border_width(GTK_CONTAINER(label_window), + BUTTON_TEXT_BORDER); + + /* Create the button. */ + button = gtk_button_new(); + + /* Adding label to button. */ + gtk_container_add(GTK_CONTAINER(button), label_window); + + return button; } - void -ShowMessage( gchar *title, gchar *message, int justification, int font_style ) +ShowMessage(gchar *title, gchar *message, int justification, int font_style) { - GtkWidget *dialog; - GtkWidget *label; - GtkWidget *okay_button; - GtkWidget *label_window; - GtkWidget *center; - - /* Set-up a dialog window, centered on the screen. */ - dialog = gtk_dialog_new(); - gtk_window_set_title( GTK_WINDOW(dialog), title ); - gtk_window_set_position( GTK_WINDOW(dialog), GTK_WIN_POS_CENTER ); - - /* To have the main window of our application being unusable while using the dialog. */ - gtk_window_set_modal( GTK_WINDOW(dialog), TRUE ); - - /* The GtkLabel widget is one of a few GTK+ widgets that don't create their own window to - render themselves into. Instead, they draw themselves directly onto their parents - window. This means that in order to set a property for a GtkLabel widget, you need to - change the property of its parent, i.e. the object that you pack it into. - Another solution (short term workaround) is to put the label widget inside another - widget that does get its own window, like the 'ViewPort' or 'EventBox' widget. */ - - /* Using workaround described above to set the border width of 'label' widget. */ - label_window = gtk_event_box_new(); - - /* Creating our label. */ - label = gtk_label_new(message); - gtk_label_set_justify( GTK_LABEL(label), justification ); - - if( font_style == MESSAGE_DIALOG_FIXED_FONT ) { -#if ( GTK_MAJOR_VERSION == 2) - PangoFontDescription *pango_font; - - pango_font = pango_font_description_from_string( FIXED_FONT ); - - gtk_widget_modify_font( label, pango_font ); -#else - GtkStyle *style; - - /* Setting font for the label. */ - style = gtk_style_new(); - gdk_font_unref( style->font ); - - /* Load a fixed font */ - style->font = gdk_font_load( FIXED_FONT ); - gtk_widget_set_style( label, style ); -#endif - } - - /* Adding label widget to label_window widget. */ - gtk_container_add( GTK_CONTAINER(label_window), label ); - - /* Changing border width of the label widget by way of label_window widget. */ - gtk_container_set_border_width( GTK_CONTAINER(label_window), MESSAGE_DIALOG_BORDER ); - - /* xalign, yalign, xscale, yscale */ - center = gtk_alignment_new( 0.5, 0.5, 0.0, 0.0 ); - - /* Create the OK button. */ - okay_button = AddTextButton( "OK" ); - - /* Ensure that the dialog box is destroyed when the user clicks ok. */ - gtk_signal_connect_object( GTK_OBJECT(okay_button), "clicked", - GTK_SIGNAL_FUNC(gtk_widget_destroy), (gpointer) dialog ); - - /* Add the OK button to the alignment widget. */ - gtk_container_add( GTK_CONTAINER(center), okay_button ); - /* Add the alignment widget to the dialog window. */ - gtk_container_add( GTK_CONTAINER( GTK_DIALOG(dialog)->action_area ), center ); - - /* Add the label_window to the dialog window. */ - gtk_container_add( GTK_CONTAINER( GTK_DIALOG(dialog)->vbox ), label_window ); - - /* Show everything we've added to the dialog. */ - gtk_widget_show_all(dialog); + GtkWidget *dialog; + GtkWidget *label; + GtkWidget *okay_button; + GtkWidget *label_window; + GtkWidget *center; + + /* Set-up a dialog window, centered on the screen. */ + dialog = gtk_dialog_new(); + gtk_window_set_title(GTK_WINDOW(dialog), title); + gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); + + /* + * To have the main window of our application being unusable while using + * the dialog. + */ + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + + /* + * The GtkLabel widget is one of a few GTK+ widgets that don't create + * their own window to render themselves into. Instead, they draw + * themselves directly onto their parents window. This means that in + * order to set a property for a GtkLabel widget, you need to change the + * property of its parent, i.e. the object that you pack it into. + * Another solution (short term workaround) is to put the label widget + * inside another widget that does get its own window, like the + * 'ViewPort' or 'EventBox' widget. + */ + + /* + * Using workaround described above to set the border width of 'label' + * widget. + */ + label_window = gtk_event_box_new(); + + /* Creating our label. */ + label = gtk_label_new(message); + gtk_label_set_justify(GTK_LABEL(label), justification); + + if (font_style == MESSAGE_DIALOG_FIXED_FONT) { + PangoFontDescription *pango_font; + + pango_font = pango_font_description_from_string(FIXED_FONT); + gtk_widget_modify_font(label, pango_font); + } + + /* Adding label widget to label_window widget. */ + gtk_container_add(GTK_CONTAINER(label_window), label); + + /* + * Changing border width of the label widget by way of label_window + * widget. + */ + gtk_container_set_border_width(GTK_CONTAINER(label_window), + MESSAGE_DIALOG_BORDER); + + /* xalign, yalign, xscale, yscale */ + center = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); + + /* Create the OK button. */ + okay_button = AddTextButton("OK"); + + /* Ensure that the dialog box is destroyed when the user clicks ok. */ + gtk_signal_connect_object(GTK_OBJECT(okay_button), "clicked", + GTK_SIGNAL_FUNC(gtk_widget_destroy), + (gpointer) dialog); + + /* Add the OK button to the alignment widget. */ + gtk_container_add(GTK_CONTAINER(center), okay_button); + /* Add the alignment widget to the dialog window. */ + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), + center); + + /* Add the label_window to the dialog window. */ + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), + label_window); + + /* Show everything we've added to the dialog. */ + gtk_widget_show_all(dialog); } diff --git a/src/messagebox.h b/src/messagebox.h index 0853a31..991e758 100644 --- a/src/messagebox.h +++ b/src/messagebox.h @@ -24,13 +24,10 @@ #include - #define MESSAGE_DIALOG_NORMAL_FONT 0 #define MESSAGE_DIALOG_FIXED_FONT 1 - void -ShowMessage( gchar *title, gchar *message, int justification, int font_style ); - +ShowMessage(gchar *title, gchar *message, int justification, int font_style); #endif /* MESSAGEBOX_H */ diff --git a/src/opcode2c.pl b/src/opcode2c.pl index cf9aa60..9fcca45 100755 --- a/src/opcode2c.pl +++ b/src/opcode2c.pl @@ -78,7 +78,7 @@ print DISASM_H " * along with this program; if not, write to the Free Software\n print DISASM_H " * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.\n"; print DISASM_H "*/\n\n"; print DISASM_H "#ifndef DISASM_H\n"; -print DISASM_H "#define DISASM_H 1\n\n\n"; +print DISASM_H "#define DISASM_H 1\n\n"; $nbinst=0; $nbaddr=0; @@ -136,9 +136,12 @@ while($ligne=) { $instnumb++; } # ------------------------------------------------------------------------------ -print DISASM_H "// For all 256 opcodes, the value in this table gives the instruction type\n"; -print DISASM_H "// ex.: MOV, INC, CLR, CPL,...\n"; -print DISASM_H "// To know what is the instruction type, use the number as an offset in the InstTextTbl[]\n"; +print DISASM_H "/*\n"; +print DISASM_H " * For all 256 opcodes, the value in this table gives the instruction type\n"; +print DISASM_H " * ex.: MOV, INC, CLR, CPL,...\n"; +print DISASM_H " * To know what is the instruction type, use\n"; +print DISASM_H " * the number as an offset in the InstTextTbl[]\n"; +print DISASM_H " */\n"; print DISASM_H "static int InstTypesTbl[] = {\n"; for($i=0;$i<256;$i++) { print DISASM_H " $insttype[$i]"; @@ -146,9 +149,9 @@ for($i=0;$i<256;$i++) { if (($i+1) % 16 == 0) { print DISASM_H "\n"; } } print DISASM_H "};\n"; -print DISASM_H "\n\n"; +print DISASM_H "\n"; # ------------------------------------------------------------------------------ -print DISASM_H "// Size(in bytes) of each instruction (offset in table is instruction opcode)\n"; +print DISASM_H "/* Size(in bytes) of each instruction (offset in table is instruction opcode) */\n"; print DISASM_H "static int InstSizesTbl[] = {\n"; for($i=0;$i<256;$i++) { print DISASM_H " $nbbytes[$i]"; @@ -156,9 +159,9 @@ for($i=0;$i<256;$i++) { if (($i+1) % 16 == 0) { print DISASM_H "\n"; } } print DISASM_H "};\n"; -print DISASM_H "\n\n"; +print DISASM_H "\n"; # ------------------------------------------------------------------------------ -print DISASM_H "// List of instructions types referenced by InstTypesTbl[]\n"; +print DISASM_H "/* List of instructions types referenced by InstTypesTbl[] */\n"; $nbelement=@insttext; print DISASM_H "\#define InstTextTblLength $nbelement\n"; $elementnb=0; @@ -169,14 +172,16 @@ foreach $instruc (@insttext) { print DISASM_H "\n"; } print DISASM_H "};\n"; -print DISASM_H "\n\n"; +print DISASM_H "\n"; # ------------------------------------------------------------------------------ -print DISASM_H "// Table describing all arguments types of an instruction\n"; -print DISASM_H "// The table is indexed InstArgTbl[ opcode * 4]\n"; -print DISASM_H "// InstArgTbl[opcode*4 + 1] gives the number of arguments the instruction has\n"; -print DISASM_H "// InstArgTbl[opcode*4 + i] for i=1,2 and 3 give the type of each argument\n"; -print DISASM_H "// for most instructions, the 3rd argument isn't used\n"; -print DISASM_H "// the argument type is referecing to ArgsTextTbl[]\n"; +print DISASM_H "/*\n"; +print DISASM_H " * Table describing all arguments types of an instruction\n"; +print DISASM_H " * The table is indexed InstArgTbl[ opcode * 4]\n"; +print DISASM_H " * InstArgTbl[opcode*4 + 1] gives the number of arguments the instruction has\n"; +print DISASM_H " * InstArgTbl[opcode*4 + i] for i=1,2 and 3 give the type of each argument\n"; +print DISASM_H " * for most instructions, the 3rd argument isn't used\n"; +print DISASM_H " * the argument type is referecing to ArgsTextTbl[]\n"; +print DISASM_H " */\n"; print DISASM_H "\#define InstArgTblLength 256\n"; print DISASM_H "static int InstArgTbl[] = {\n"; for($i=0;$i<1024;$i++) { @@ -185,10 +190,12 @@ for($i=0;$i<1024;$i++) { if (($i+1) % 16 == 0) { print DISASM_H "\n"; } } print DISASM_H "};\n"; -print DISASM_H "\n\n"; +print DISASM_H "\n"; # ------------------------------------------------------------------------------ -print DISASM_H "// List all types of arguments available to instructions\n"; -print DISASM_H "// Referenced by InstArgsTbl[]\n"; +print DISASM_H "/*\n"; +print DISASM_H " * List all types of arguments available to instructions\n"; +print DISASM_H " * Referenced by InstArgsTbl[]\n"; +print DISASM_H " */\n"; $nbelement=@argstypes; print DISASM_H "\#define ArgsTextTblLength $nbelement\n"; $elementnb=0; @@ -199,7 +206,7 @@ foreach $args (@argstypes) { print DISASM_H "\n"; } print DISASM_H "};\n"; -print DISASM_H "\n\n"; +print DISASM_H "\n"; # ------------------------------------------------------------------------------ for ($i=0 ; $i< 256; $i++) { @@ -207,7 +214,7 @@ for ($i=0 ; $i< 256; $i++) { print INST_IMP " * Instruction \"$a_instruction[$i]\" takes $a_cycles[$i] cycle(s) and $a_bytes[$i] byte(s).\n"; print INST_IMP " ","*"x76,"/\n"; print INST_IMP "int\n"; - print INST_IMP "cpu8051_OP_$a_opcodehex[$i]( void )\n"; + print INST_IMP "cpu8051_OP_$a_opcodehex[$i](void)\n"; # TEST hugo new... # print INST_DEF "int OP_$a_opcodehex[$i]( );\n"; print INST_IMP "{\n"; @@ -841,11 +848,11 @@ print INST_DEF "*/\n\n"; print INST_DEF "#ifndef INSTRUCTIONS_8051_H\n"; print INST_DEF "#define INSTRUCTIONS_8051_H 1\n\n\n"; -print INST_DEF "#define BANKPSW ( cpu8051_ReadD( _PSW_ ) & 0x18 )\n\n"; -print INST_DEF "typedef int (*OPCODE_FP)( void );\n\n\n"; +print INST_DEF "#define BANKPSW (cpu8051_ReadD(_PSW_) & 0x18)\n\n"; +print INST_DEF "typedef int (*OPCODE_FP)(void);\n\n\n"; for( $i=0; $i<256; $i++ ) { print INST_DEF "int\n"; - print INST_DEF "cpu8051_OP_$a_opcodehex[$i]( void );\n\n"; + print INST_DEF "cpu8051_OP_$a_opcodehex[$i](void);\n\n"; } print INST_DEF "\n"; print INST_DEF "/* Exported variables. */\n"; @@ -868,12 +875,7 @@ print INST_DEF "#endif\n\n\n"; print INST_DEF "#endif /* INSTRUCTIONS_8051_H */\n"; - - - - - -print DISASM_H "\n\n#endif /* DISASM_H */\n"; +print DISASM_H "#endif /* DISASM_H */\n"; close DISASM_H; close OPCODELST; diff --git a/src/options.c b/src/options.c index 3caf9f6..6377a5d 100644 --- a/src/options.c +++ b/src/options.c @@ -50,37 +50,33 @@ get_hex_filename(void) * Display the help message and exit ******************************************************************************/ static void -DisplayUsage( void ) +DisplayUsage(void) { - printf( COMMAND_LINE_OPTIONS ); + printf(COMMAND_LINE_OPTIONS); } - /******************************************************************************* * Display version information and exit ******************************************************************************/ static void -DisplayVersion( void ) +DisplayVersion(void) { - printf( "\n" ); - printf( " %s, version %s\n", PACKAGE, VERSION ); - printf( " Written by Jonathan St-André, Pascal Fecteau and Hugo Villeneuve\n\n" ); + printf("\n"); + printf(" %s, version %s\n", PACKAGE, VERSION); + printf(" Written by Jonathan St-André, Pascal Fecteau and Hugo Villeneuve\n\n"); } - static void -InvalidOption( const char *message, /*@null@*/ const char *string ) +InvalidOption(const char *message, /*@null@*/ const char *string) { - if( string == NULL ) { - fprintf(stderr, "%s: %s\n", PACKAGE, message ); - } - else { - fprintf(stderr, "%s: %s %s\n", PACKAGE, message, string ); - } + if (string == NULL) + fprintf(stderr, "%s: %s\n", PACKAGE, message); + else + fprintf(stderr, "%s: %s %s\n", PACKAGE, message, string); - fprintf(stderr, "Try `%s -h' for more information.\n", PACKAGE ); + fprintf(stderr, "Try `%s -h' for more information.\n", PACKAGE); - exit( EXIT_FAILURE ); + exit(EXIT_FAILURE); } @@ -88,44 +84,41 @@ InvalidOption( const char *message, /*@null@*/ const char *string ) * Initializes the different options passed as arguments on the command line. ******************************************************************************/ void -ParseCommandLineOptions( int argc, char *argv[] ) +ParseCommandLineOptions(int argc, char *argv[]) { - int i; - char *token; - - for( i = 1; i < argc; i++ ) { - token = argv[i]; - switch( token[0] ) { - case '-': - /* Processing options names */ - switch( token[1] ) { - case 'h': - if( strlen( &token[1] ) == 1 ) { - DisplayUsage(); - exit( EXIT_SUCCESS ); - } - InvalidOption( "invalid option", token ); - break; - case 'v' : - if( STREQ( "version", &token[1] ) ) { - DisplayVersion(); - exit( EXIT_SUCCESS ); - } - else { - InvalidOption( "invalid option", token ); - } - break; - default: - InvalidOption( "invalid option", token ); - break; - } /* end switch( token[1] ) */ - break; - default: - /* Processing options arguments */ - /* Must be the filename... */ - hex_file = token; - break; - } /* end switch( token[0] ) */ - } /* end for */ - + int i; + char *token; + + for (i = 1; i < argc; i++) { + token = argv[i]; + switch (token[0]) { + case '-': + /* Processing options names */ + switch (token[1]) { + case 'h': + if (strlen(&token[1]) == 1) { + DisplayUsage(); + exit(EXIT_SUCCESS); + } + InvalidOption("invalid option", token); + break; + case 'v': + if (STREQ("version", &token[1])) { + DisplayVersion(); + exit(EXIT_SUCCESS); + } else + InvalidOption("invalid option", token); + break; + default: + InvalidOption("invalid option", token); + break; + } /* end switch(token[1]) */ + break; + default: + /* Processing options arguments */ + /* Must be the filename... */ + hex_file = token; + break; + } /* end switch(token[0]) */ + } /* end for */ } diff --git a/src/pgmwin.c b/src/pgmwin.c index 8360375..163042b 100644 --- a/src/pgmwin.c +++ b/src/pgmwin.c @@ -29,173 +29,86 @@ #include "cpu8051.h" #include "pgmwin.h" - static GtkWidget *pgmclist; -static int NbBreakpoints; -static unsigned int Breakpoints[ MAXBP ]; -static unsigned int DisasmAddresses[ 24 ]; - +static unsigned int DisasmAddresses[24]; /* Disasm 24 lines from CPU */ void -pgmwin_Disasm( ) -{ - char TextTmp[255]; - int row; - int InstSize; - unsigned int Address; - - Address = cpu8051.pc; - - gtk_clist_freeze( GTK_CLIST( pgmclist ) ); - for ( row = 0; row < 24; row++ ) { - InstSize = cpu8051_Disasm( Address, TextTmp ); - if ( pgmwin_IsBreakpoint( Address ) ) TextTmp[0] = '*'; - gtk_clist_set_text( GTK_CLIST( pgmclist ), row, 0, TextTmp ); - DisasmAddresses[ row ] = Address; - Address += InstSize; - } - gtk_clist_select_row( GTK_CLIST( pgmclist ), 0, 0 ); - gtk_clist_thaw( GTK_CLIST( pgmclist ) ); -} - - -/* Clear Breakpoint at Address from list */ -static void -pgmwin_ClearBreakpoint( unsigned int Address ) -{ - int Index = 0; - - while( Index < NbBreakpoints && Breakpoints[ Index ] != Address ) { - Index++; - } - if( Breakpoints[ Index ] != Address ) { - return; - } - Breakpoints[ Index ] = Breakpoints[ NbBreakpoints - 1 ]; - NbBreakpoints--; -} - - -/* Set Breakpoint at Address from list. */ -static void -pgmwin_SetBreakpoint( unsigned int Address ) -{ - if( pgmwin_IsBreakpoint( Address ) ) { - return; - } - if( NbBreakpoints < MAXBP ) { - Breakpoints[ NbBreakpoints++ ] = Address; - } -} - -/* Toggle the breakpoint at Address. */ -static void -pgmwin_ToggleBreakpoint( unsigned int Address ) -{ - if( pgmwin_IsBreakpoint( Address ) ) { - pgmwin_ClearBreakpoint( Address ); - } - else { - pgmwin_SetBreakpoint( Address ); - } -} - - -#ifdef dsfdsfs -/* Show Breakpoints list. */ -static void -pgmwin_ShowBreakpoints( ) -{ - int Index; - - for ( Index = 0; Index < NbBreakpoints ; Index++ ) { - printf( "Breakpoint at Address = %.4X\n", Breakpoints[ Index ] ); - } -} -#endif - - -/* Is the a breakpoint at Address. */ -int -pgmwin_IsBreakpoint( unsigned int Address ) +pgmwin_Disasm(void) { - int Index = 0; - while( Index < NbBreakpoints && Breakpoints[ Index ] != Address ) { - Index++; - } - - return ( Breakpoints[ Index ] == Address && Index < NbBreakpoints ); + char TextTmp[255]; + int row; + int InstSize; + unsigned int Address; + + Address = cpu8051.pc; + + gtk_clist_freeze(GTK_CLIST(pgmclist)); + for (row = 0; row < 24; row++) { + InstSize = cpu8051_Disasm(Address, TextTmp); + if (IsBreakpoint(Address)) + TextTmp[0] = '*'; + gtk_clist_set_text(GTK_CLIST(pgmclist), row, 0, TextTmp); + DisasmAddresses[row] = Address; + Address += InstSize; + } + gtk_clist_select_row(GTK_CLIST(pgmclist), 0, 0); + gtk_clist_thaw(GTK_CLIST(pgmclist)); } - /* Mouse button pressed in the window. */ static gint -pgmwin_ButtonPressEvent( GtkWidget *widget, GdkEvent *event, gpointer data ) +pgmwin_ButtonPressEvent(GtkWidget *widget, GdkEvent *event, gpointer data) { - gint row, column; - char TextTmp[ 255 ]; - - //g_print( "pgmwin_ButtonPressEvent(...)\n" ); - - gtk_clist_get_selection_info( GTK_CLIST( pgmclist ), ( int )event->button.x ,( int )event->button.y, &row, &column ); - if (row >= 24 || row < 0) - return TRUE; - if (column >= 1 || column < 0) - return TRUE; - sprintf( TextTmp, "pgmwin_ButtonPressEvent( ) at %d,%d\n", column, row ); - g_print( TextTmp ); - pgmwin_ToggleBreakpoint( DisasmAddresses[ row ] ); - pgmwin_Disasm(); - - return FALSE; + gint row, column; + char TextTmp[255]; + + gtk_clist_get_selection_info(GTK_CLIST(pgmclist), + (int) event->button.x, + (int) event->button.y, &row, &column); + if (row >= 24 || row < 0) + return TRUE; + if (column >= 1 || column < 0) + return TRUE; + sprintf(TextTmp, "pgmwin_ButtonPressEvent() at %d,%d\n", column, row); + g_print(TextTmp); + ToggleBreakpoint(DisasmAddresses[row]); + pgmwin_Disasm(); + + return FALSE; } GtkWidget * -pgmwin_init( int width, int height ) +pgmwin_init(int width, int height) { - int i; - GtkWidget *fixed_frame; - - fixed_frame = gtk_frame_new(0); - gtk_frame_set_shadow_type( GTK_FRAME( fixed_frame ), GTK_SHADOW_ETCHED_OUT ); - gtk_widget_set_usize( GTK_WIDGET( fixed_frame ), width, height ); - - pgmclist = gtk_clist_new( 1 ); - gtk_clist_set_selection_mode( GTK_CLIST( pgmclist ), GTK_SELECTION_SINGLE ); - gtk_widget_set_usize( GTK_WIDGET( pgmclist ), width, height ); - gtk_clist_set_column_justification( GTK_CLIST( pgmclist ), 0, GTK_JUSTIFY_LEFT ); - gtk_clist_set_column_width( GTK_CLIST( pgmclist ), 0, width-10 ); - -#if ( GTK_MAJOR_VERSION == 2) - PangoFontDescription *pango_font; - pango_font = pango_font_description_from_string( FIXED_FONT ); - gtk_widget_modify_font( pgmclist, pango_font ); -#else - { - GtkStyle *style; - /* Setting font for the widget. */ - style = gtk_style_new(); - gdk_font_unref( style->font ); - - /* Load a fixed font */ - style->font = gdk_font_load( FIXED_FONT ); - gtk_widget_set_style( GTK_WIDGET( pgmclist ), style ); - } -#endif + int i; + GtkWidget *fixed_frame; + + fixed_frame = gtk_frame_new(0); + gtk_frame_set_shadow_type(GTK_FRAME(fixed_frame), + GTK_SHADOW_ETCHED_OUT); + gtk_widget_set_usize(GTK_WIDGET(fixed_frame), width, height); + + pgmclist = gtk_clist_new(1); + gtk_clist_set_selection_mode(GTK_CLIST(pgmclist), GTK_SELECTION_SINGLE); + gtk_widget_set_usize(GTK_WIDGET(pgmclist), width, height); + gtk_clist_set_column_justification(GTK_CLIST(pgmclist), 0, + GTK_JUSTIFY_LEFT); + gtk_clist_set_column_width(GTK_CLIST(pgmclist), 0, width-10); - char *pgmdummy[] = { 0 }; - for( i = 0; i < 24; i++ ) { - gtk_clist_append( GTK_CLIST( pgmclist ), pgmdummy ); - } + PangoFontDescription *pango_font; + pango_font = pango_font_description_from_string(FIXED_FONT); + gtk_widget_modify_font(pgmclist, pango_font); - gtk_container_add( GTK_CONTAINER( fixed_frame ), pgmclist ); + char *pgmdummy[] = { 0 }; + for (i = 0; i < 24; i++) + gtk_clist_append(GTK_CLIST(pgmclist), pgmdummy); - NbBreakpoints = 0; + gtk_container_add(GTK_CONTAINER(fixed_frame), pgmclist); - gtk_signal_connect( GTK_OBJECT( pgmclist ), "button-press-event", - GTK_SIGNAL_FUNC( pgmwin_ButtonPressEvent ), NULL ); + gtk_signal_connect(GTK_OBJECT(pgmclist), "button-press-event", + GTK_SIGNAL_FUNC(pgmwin_ButtonPressEvent), NULL); - return fixed_frame; + return fixed_frame; } diff --git a/src/pgmwin.h b/src/pgmwin.h index f7fd1b1..dca55e7 100644 --- a/src/pgmwin.h +++ b/src/pgmwin.h @@ -22,22 +22,16 @@ #ifndef PGMWIN_H #define PGMWIN_H 1 - #include #include "gtksizes.h" - -#define MAXBP 32 - - GtkWidget * -pgmwin_init( int width, int height ); +pgmwin_init(int width, int height); void -pgmwin_Disasm( void ); +pgmwin_Disasm(void); int -pgmwin_IsBreakpoint( unsigned int Address ); - +pgmwin_IsBreakpoint(unsigned int address); #endif /* PGMWIN_H */ diff --git a/src/reg8051.h b/src/reg8051.h index 9fc3e48..1800be7 100644 --- a/src/reg8051.h +++ b/src/reg8051.h @@ -22,7 +22,6 @@ #ifndef REG8051_H #define REG8051_H 1 - /* SFR Registers ( $80 - $FF ) */ #define _ACC_ 0xE0 #define _B_ 0xF0 @@ -63,5 +62,4 @@ #define _BANK2_ 0x10 #define _BANK3_ 0x18 - #endif /* REG8051_H */ diff --git a/src/regwin.c b/src/regwin.c index 68b7593..a7a0f53 100644 --- a/src/regwin.c +++ b/src/regwin.c @@ -30,124 +30,112 @@ #include "cpu8051.h" #include "regwin.h" - static GtkWidget *regclist; - GtkWidget * -regwin_init( int width, int height ) +regwin_init(int width, int height) { - int i; - GtkWidget *fixed_frame; - - fixed_frame = gtk_frame_new(0); - gtk_frame_set_shadow_type( GTK_FRAME( fixed_frame ), GTK_SHADOW_ETCHED_OUT ); - gtk_widget_set_usize( GTK_WIDGET( fixed_frame ), width, height ); - - regclist = gtk_clist_new( 1 ); - gtk_clist_set_selection_mode( GTK_CLIST( regclist ), GTK_SELECTION_SINGLE ); - gtk_widget_set_usize( GTK_WIDGET( regclist ), width, height ); - gtk_clist_set_column_justification( GTK_CLIST( regclist ), 0, GTK_JUSTIFY_LEFT ); - gtk_clist_set_column_width( GTK_CLIST( regclist ), 0, width ); - -#if ( GTK_MAJOR_VERSION == 2) - PangoFontDescription *pango_font; - pango_font = pango_font_description_from_string( FIXED_FONT ); - gtk_widget_modify_font( regclist, pango_font ); -#else - { - GtkStyle *style; - /* Setting font for the widget. */ - style = gtk_style_new(); - gdk_font_unref( style->font ); - - /* Load a fixed font */ - style->font = gdk_font_load( FIXED_FONT ); - gtk_widget_set_style( GTK_WIDGET( regclist ), style ); - } -#endif + int i; + GtkWidget *fixed_frame; + PangoFontDescription *pango_font; + char *regdummy[] = { 0 }; + + fixed_frame = gtk_frame_new(0); + gtk_frame_set_shadow_type(GTK_FRAME(fixed_frame), + GTK_SHADOW_ETCHED_OUT); + gtk_widget_set_usize(GTK_WIDGET(fixed_frame), width, height); + + regclist = gtk_clist_new(1); + gtk_clist_set_selection_mode(GTK_CLIST(regclist), GTK_SELECTION_SINGLE); + gtk_widget_set_usize(GTK_WIDGET(regclist), width, height); + gtk_clist_set_column_justification(GTK_CLIST(regclist), 0, + GTK_JUSTIFY_LEFT); + gtk_clist_set_column_width(GTK_CLIST(regclist), 0, width); + + + pango_font = pango_font_description_from_string(FIXED_FONT); + gtk_widget_modify_font(regclist, pango_font); + + for (i = 0; i < 24; i++) + gtk_clist_append(GTK_CLIST(regclist), regdummy); - char *regdummy[] = { 0 }; - for ( i = 0; i < 24; i++ ) { - gtk_clist_append( GTK_CLIST( regclist ), regdummy ); - } - - gtk_container_add( GTK_CONTAINER( fixed_frame ), regclist ); + gtk_container_add(GTK_CONTAINER(fixed_frame), regclist); - return fixed_frame; + return fixed_frame; } /* Show registers. */ void -regwin_Show( void ) +regwin_Show(void) { - char TextTmp[255]; - int row = 0; - unsigned char PSW = cpu8051_ReadD( _PSW_ ); - unsigned char Rbank; - - gtk_clist_freeze( GTK_CLIST( regclist ) ); - - // Main registers - sprintf( TextTmp , "PC = %.4X", cpu8051.pc ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "SP = %.2X", cpu8051_ReadD( _SP_ ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "A = %.2X", cpu8051_ReadD( _ACC_ ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "B = %.2X", cpu8051_ReadD( _B_ ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "DPTR = %.4X", ( cpu8051_ReadD( _DPTRHIGH_ ) << 8 ) + cpu8051_ReadD( _DPTRLOW_ ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - - // Program Status Word - sprintf( TextTmp , "PSW = %.2X",PSW); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - - // Ports registers - sprintf( TextTmp , "P0 = %.2X", cpu8051_ReadD( _P0_ ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "P1 = %.2X", cpu8051_ReadD( _P1_ ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "P2 = %.2X", cpu8051_ReadD( _P2_ ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "P3 = %.2X", cpu8051_ReadD( _P3_ ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - - // Misc Registers - sprintf( TextTmp , "TCON = %.2X", cpu8051_ReadD( _TCON_ ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "TMOD = %.2X", cpu8051_ReadD( _TMOD_ ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "SCON = %.2X", cpu8051_ReadD( _SCON_ ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "IE = %.2X", cpu8051_ReadD( _IE_ ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "IP = %.2X", cpu8051_ReadD( _IP_ ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - - // R0-R7 Registers in current Bank - Rbank = cpu8051_ReadD( _PSW_ ) & 0x18; - sprintf( TextTmp , "Bank = %.2X", Rbank); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "R0 = %.2X", cpu8051_ReadD( _R0_ + Rbank ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "R1 = %.2X", cpu8051_ReadD( _R1_ + Rbank ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "R2 = %.2X", cpu8051_ReadD( _R2_ + Rbank ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "R3 = %.2X", cpu8051_ReadD( _R3_ + Rbank ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "R4 = %.2X", cpu8051_ReadD( _R4_ + Rbank ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "R5 = %.2X", cpu8051_ReadD( _R5_ + Rbank ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "R6 = %.2X", cpu8051_ReadD( _R6_ + Rbank ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - sprintf( TextTmp , "R7 = %.2X", cpu8051_ReadD( _R7_ + Rbank ) ); - gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp ); - - gtk_clist_select_row(GTK_CLIST(regclist),0,0); - gtk_clist_thaw( GTK_CLIST( regclist ) ); + char TextTmp[255]; + int row = 0; + unsigned char PSW = cpu8051_ReadD(_PSW_); + unsigned char Rbank; + + gtk_clist_freeze(GTK_CLIST(regclist)); + + /* Main registers */ + sprintf(TextTmp , "PC = %.4X", cpu8051.pc); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "SP = %.2X", cpu8051_ReadD(_SP_)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "A = %.2X", cpu8051_ReadD(_ACC_)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "B = %.2X", cpu8051_ReadD(_B_)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "DPTR = %.4X", (cpu8051_ReadD(_DPTRHIGH_) << 8) + + cpu8051_ReadD(_DPTRLOW_)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + + /* Program Status Word */ + sprintf(TextTmp, "PSW = %.2X", PSW); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + + /* Ports registers */ + sprintf(TextTmp , "P0 = %.2X", cpu8051_ReadD(_P0_)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "P1 = %.2X", cpu8051_ReadD(_P1_)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "P2 = %.2X", cpu8051_ReadD(_P2_)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "P3 = %.2X", cpu8051_ReadD(_P3_)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + + /* Misc Registers */ + sprintf(TextTmp , "TCON = %.2X", cpu8051_ReadD(_TCON_)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "TMOD = %.2X", cpu8051_ReadD(_TMOD_)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "SCON = %.2X", cpu8051_ReadD(_SCON_)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "IE = %.2X", cpu8051_ReadD(_IE_)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "IP = %.2X", cpu8051_ReadD(_IP_)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + + /* R0-R7 Registers in current Bank */ + Rbank = cpu8051_ReadD(_PSW_) & 0x18; + sprintf(TextTmp , "Bank = %.2X", Rbank); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "R0 = %.2X", cpu8051_ReadD(_R0_ + Rbank)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "R1 = %.2X", cpu8051_ReadD(_R1_ + Rbank)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "R2 = %.2X", cpu8051_ReadD(_R2_ + Rbank)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "R3 = %.2X", cpu8051_ReadD(_R3_ + Rbank)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "R4 = %.2X", cpu8051_ReadD(_R4_ + Rbank)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "R5 = %.2X", cpu8051_ReadD(_R5_ + Rbank)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "R6 = %.2X", cpu8051_ReadD(_R6_ + Rbank)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + sprintf(TextTmp , "R7 = %.2X", cpu8051_ReadD(_R7_ + Rbank)); + gtk_clist_set_text(GTK_CLIST(regclist), row++, 0, TextTmp); + + gtk_clist_select_row(GTK_CLIST(regclist), 0, 0); + gtk_clist_thaw(GTK_CLIST(regclist)); } diff --git a/src/regwin.h b/src/regwin.h index ff3bca3..1b24e10 100644 --- a/src/regwin.h +++ b/src/regwin.h @@ -22,16 +22,13 @@ #ifndef REGWIN_H #define REGWIN_H 1 - #include #include "gtksizes.h" - GtkWidget * -regwin_init( int width, int height ); +regwin_init(int width, int height); void -regwin_Show( void ); - +regwin_Show(void); #endif /* REGWIN_H */ diff --git a/src/viewmenu.c b/src/viewmenu.c index 5a1d3ab..6d2eca4 100644 --- a/src/viewmenu.c +++ b/src/viewmenu.c @@ -30,51 +30,48 @@ #include "messagebox.h" #include "viewmenu.h" - static void -ViewMenuExternalDump( gchar *string ) +ViewMenuExternalDump(gchar *string) { - ShowMessage( "External Memory Dump", "Not implemented yet!", GTK_JUSTIFY_CENTER, - MESSAGE_DIALOG_NORMAL_FONT ); + ShowMessage("External Memory Dump", "Not implemented yet!", + GTK_JUSTIFY_CENTER, MESSAGE_DIALOG_NORMAL_FONT); } - static void -ViewMenuInternalDump( gchar *string ) +ViewMenuInternalDump(gchar *string) { - ShowMessage( "Internal Memory Dump", "Not implemented yet!", GTK_JUSTIFY_CENTER, - MESSAGE_DIALOG_NORMAL_FONT ); + ShowMessage("Internal Memory Dump", "Not implemented yet!", + GTK_JUSTIFY_CENTER, MESSAGE_DIALOG_NORMAL_FONT); } - void -ViewAddMenu( GtkWidget *menu_bar ) +ViewAddMenu(GtkWidget *menu_bar) { - GtkWidget *item; - GtkWidget *menu; - - menu = gtk_menu_new(); + GtkWidget *item; + GtkWidget *menu; + + menu = gtk_menu_new(); + + /* Create the 'Viewmenu External Memory Dump' item. */ + item = gtk_menu_item_new_with_label("External Memory Dump"); + gtk_menu_append(GTK_MENU(menu), item); + /* Attach the callback functions to the activate signal. */ + gtk_signal_connect_object(GTK_OBJECT(item), "activate", + GTK_SIGNAL_FUNC(ViewMenuExternalDump), + NULL); - /* Create the 'Viewmenu External Memory Dump' item. */ - item = gtk_menu_item_new_with_label("External Memory Dump"); - gtk_menu_append( GTK_MENU(menu), item ); - /* Attach the callback functions to the activate signal. */ - gtk_signal_connect_object( GTK_OBJECT(item), "activate", - GTK_SIGNAL_FUNC(ViewMenuExternalDump), - NULL ); + AddMenuSeparator(menu); - AddMenuSeparator(menu); + /* Create the 'Viewmenu Internal Memory Dump' item. */ + item = gtk_menu_item_new_with_label("Internal Memory Dump"); + gtk_menu_append(GTK_MENU(menu), item); + /* Attach the callback functions to the activate signal. */ + gtk_signal_connect_object(GTK_OBJECT(item), "activate", + GTK_SIGNAL_FUNC(ViewMenuInternalDump), + NULL); - /* Create the 'Viewmenu Internal Memory Dump' item. */ - item = gtk_menu_item_new_with_label( "Internal Memory Dump" ); - gtk_menu_append( GTK_MENU(menu), item ); - /* Attach the callback functions to the activate signal. */ - gtk_signal_connect_object( GTK_OBJECT(item), "activate", - GTK_SIGNAL_FUNC(ViewMenuInternalDump), - NULL ); - - /* Adding submenu title. */ - item = gtk_menu_item_new_with_label( "View" ); - gtk_menu_item_set_submenu( GTK_MENU_ITEM(item), menu ); - gtk_menu_bar_append( GTK_MENU_BAR( menu_bar ), item ); + /* Adding submenu title. */ + item = gtk_menu_item_new_with_label("View"); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu); + gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), item); } diff --git a/src/viewmenu.h b/src/viewmenu.h index c79045c..bf78564 100644 --- a/src/viewmenu.h +++ b/src/viewmenu.h @@ -24,9 +24,7 @@ #include - void -ViewAddMenu( GtkWidget *menu_bar ); - +ViewAddMenu(GtkWidget *menu_bar); #endif /* VIEWMENU_H */