Browse Source

Now use CMake to build and compile/run with Allegro 4.4

Godzil 1 year ago
parent
commit
827e920909
21 changed files with 3931 additions and 3508 deletions
  1. 23 0
      CMakeLists.txt
  2. 2050 0
      code_51.cpp
  3. 532 0
      code_editor.cpp
  4. 106 0
      dis_asm.cpp
  5. 59 2353
      emu51.cpp
  6. 0 250
      emu51.h
  7. 168 0
      external/cmake/GetGitRevisionDescription.cmake
  8. 41 0
      external/cmake/GetGitRevisionDescription.cmake.in
  9. 63 0
      flags.cpp
  10. 400 0
      gui.cpp
  11. 0 905
      gui.h
  12. 38 0
      include/code_51.h
  13. 61 0
      include/code_editor.h
  14. 32 0
      include/dis_asm.h
  15. 56 0
      include/emu51.h
  16. 34 0
      include/flags.h
  17. 24 0
      include/gui.h
  18. 35 0
      include/ramv.h
  19. 42 0
      include/regs.h
  20. 94 0
      ramv.cpp
  21. 73 0
      regs.cpp

+ 23 - 0
CMakeLists.txt

@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 3.11)
+
+# External cmake modules
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/external/cmake ${CMAKE_MODULE_PATH})
+include(GetGitRevisionDescription)
+
+set(CMAKE_CXX_STANDARD 11)
+
+project(Emu51)
+
+git_describe(VERSION --tags --dirty=-dirty)
+message("-- Building version ${VERSION}")
+
+add_compile_definitions(VERSION="${VERSION}")
+
+file(GLOB EMU51_SOURCES *.cpp)
+file(GLOB EMU51_HEADERS include/*.h)
+
+add_executable(Emu51)
+
+target_sources(Emu51 PRIVATE ${EMU51_SOURCES} ${EMU51_HEADERS})
+target_include_directories(Emu51 PRIVATE include)
+target_link_libraries(Emu51 alleg)

+ 2050 - 0
code_51.cpp

@@ -0,0 +1,2050 @@
+/*******************************************************************************
+ * Emu51
+ * code_51.cpp:
+ * Created by mlt on 22/03/23.
+ ******************************************************************************/
+
+#include <emu51.h>
+#include <code_51.h>
+
+#include <stdio.h>
+
+unsigned long c_time = 0;
+code_51 asm51[256];
+
+// 1 or 0
+uint8_t check_C(void)
+{
+    if ( *PSW & bit7 )
+    {
+        return 1;
+    }
+    else
+    {
+        return 0;
+    }
+}
+
+// 1 or 0
+uint8_t check_AC(void)
+{
+    if ( *PSW & bit6 )
+    {
+        return 1;
+    }
+    else
+    {
+        return 0;
+    }
+}
+
+// 1 or 0
+uint8_t check_OV(void)
+{
+    if ( *PSW & bit2 )
+    {
+        return 1;
+    }
+    else
+    {
+        return 0;
+    }
+}
+
+// C <- 1
+void set_C(void)
+{
+    *PSW = *PSW | bit7;
+}
+
+// AC <- 1
+void set_AC(void)
+{
+    *PSW = *PSW | bit6;
+}
+
+// OV <- 1
+void set_OV(void)
+{
+    *PSW = *PSW | bit2;
+}
+
+// C <- 0
+void clr_C(void)
+{
+    *PSW = *PSW & 0x7f;
+}
+
+// AC <- 0
+void clr_AC(void)
+{
+    *PSW = *PSW & 0xbf;
+}
+
+// OV <- 0
+void clr_OV(void)
+{
+    *PSW = *PSW & 0xfb;
+}
+
+// 1 or 0
+uint8_t check_P(void)
+{
+    if ( *PSW & bit0 )
+    {
+        return 1;
+    }
+    else
+    {
+        return 0;
+    }
+}
+
+// P <- 1
+void set_P(void)
+{
+    *PSW = *PSW | bit0;
+}
+
+// P <- 0
+void clr_P(void)
+{
+    *PSW = *PSW & 0xfe;
+}
+
+// (bit) <- 1
+void set_Bit(uint8_t bit)
+{
+    uint8_t tmpB;
+    uint8_t tmpbit;
+    tmpbit = bit & 0x07;
+    tmpB = bit & 0xf8;
+    if ( bit >= 128 )
+    {
+        // bit set in SFR area
+        SFR[tmpB] = SFR[tmpB] | ( 1 << tmpbit );
+    }
+    else
+    {
+        // bit set in int. RAM
+        tmpB = ( tmpB >> 3 ) + 32;
+        SFR[tmpB] = SFR[tmpB] | ( 1 << tmpbit );
+    }
+}
+
+// (bit) <- 0
+void clr_Bit(uint8_t bit)
+{
+    uint8_t tmpB;
+    uint8_t tmpbit;
+    tmpbit = bit & 0x07;
+    tmpB = bit & 0xf8;
+    if ( bit >= 128 )
+    {
+        // bit clear in SFR area
+        SFR[tmpB] = SFR[tmpB] & ~( 1 << tmpbit );
+    }
+    else
+    {
+        // bit clear in int. RAM
+        tmpB = ( tmpB >> 3 ) + 32;
+        SFR[tmpB] = SFR[tmpB] & ~( 1 << tmpbit );
+    }
+}
+
+// returns (bit) 1 or 0
+uint8_t check_Bit(uint8_t bit)
+{
+    uint8_t tmpB;
+    uint8_t tmpbit;
+    tmpbit = bit & 0x07;
+    tmpB = bit & 0xf8;
+    if ( bit >= 128 )
+    {
+        // bit check in SFR area
+        if ( SFR[tmpB] & 1 << tmpbit )
+        {
+            return 1;
+        }
+        else
+        {
+            return 0;
+        }
+    }
+    else
+    {
+        // bit check in int. RAM
+        tmpB = ( tmpB >> 3 ) + 32;
+        if ( SFR[tmpB] & 1 << tmpbit )
+        {
+            return 1;
+        }
+        else
+        {
+            return 0;
+        }
+    }
+}
+
+uint8_t check_RS0(void)
+{
+    if ( *PSW & bit3 )
+    {
+        return 1;
+    }
+    else
+    {
+        return 0;
+    }
+}
+
+void set_RS0(void)
+{
+    *PSW = *PSW | bit3;
+}
+
+void clr_RS0(void)
+{
+    *PSW = *PSW & 0xf7;
+}
+
+uint8_t check_RS1(void)
+{
+    if ( *PSW & bit4 )
+    {
+        return 1;
+    }
+    else
+    {
+        return 0;
+    }
+}
+
+void set_RS1(void)
+{
+    *PSW = *PSW | bit4;
+}
+
+void clr_RS1(void)
+{
+    *PSW = *PSW & 0xef;
+}
+
+void _add(uint8_t &a, uint8_t &b)
+{
+    int tmp1, tmp2;
+    (( 0xf & a ) + ( 0xf & b )) > 0xf ? set_AC() : clr_AC();
+    tmp1 = (( 0x7f & a ) + ( 0x7f & b )) > 0x7f ? 1 : 0;
+    ( tmp2 = a + b ) > 0xff ? ( set_C(), tmp1 ? clr_OV() : set_OV()) : ( clr_C(), tmp1 ? set_OV() : clr_OV());
+    a = (uint8_t) tmp2 & 0xff;
+}
+
+void _addc(uint8_t &a, uint8_t &b)
+{
+    int tmp1, tmp2, c;
+    c = check_C();
+    (( 0xf & a ) + ( 0xf & b + c )) > 0xf ? set_AC() : clr_AC();
+    tmp1 = (( 0x7f & a ) + ( 0x7f & b ) + c ) > 0x7f ? 1 : 0;
+    ( tmp2 = a + b + c ) > 0xff ? ( set_C(), tmp1 ? clr_OV() : set_OV()) : ( clr_C(), tmp1 ? set_OV() : clr_OV());
+    a = (uint8_t) tmp2 & 0xff;
+}
+
+void _subb(uint8_t &a, uint8_t &b)
+{
+    int tmp1, tmp2, c;
+    c = check_C();
+    ((char) ( 0xf & a ) - (char) ( 0xf & b ) - c ) < 0 ? set_AC() : clr_AC();
+    tmp1 = ((char) ( 0x7f & a ) - (char) ( 0x7f & b ) - c ) < 0 ? 1 : 0;
+    (char) ( tmp2 = a - b - c ) < 0 ? ( set_C(), tmp1 ? clr_OV() : set_OV()) : ( clr_C(), tmp1 ? set_OV() : clr_OV());
+    a = (uint8_t) tmp2 & 0xff;
+}
+
+
+void code_51::make_ds(uint16_t ram_pl)
+{
+    int c, i;
+    char tmp[3], tmpW[5];
+    display_string[0] = mnem[0];
+    display_string[1] = mnem[1];
+    display_string[2] = ( mnem[2] >= 0x61 && mnem[2] <= 0x7a ) ? mnem[2] : (char) 32;
+    display_string[3] = ( mnem[3] >= 0x61 && mnem[3] <= 0x7a ) ? mnem[3] : (char) 32;
+    display_string[4] = ( mnem[4] >= 0x61 && mnem[4] <= 0x7a ) ? mnem[4] : (char) 32;
+    display_string[5] = (char) 32;
+
+    for ( c = 0 ; c <= 10 ; c++ )
+    {
+        if ( datas[c] != '%' )
+        {
+            if ( datas[c] == 'O' && datas[c + 1] == '%' )
+            {
+                if ( datas[c + 2] == '1' )
+                {
+                    sprintf(tmpW, "%4x", (signed char) prog[ram_pl + 1] + ram_pl + 2);
+                    for ( i = 0 ; i < 4 ; i++ )
+                    {
+                        display_string[c + 6 + i] = ( tmpW[i] == ' ' ) ? '0' : tmpW[i];
+                    }
+                }
+                if ( datas[c + 2] == '2' )
+                {
+                    sprintf(tmpW, "%4x", (signed char) prog[ram_pl + 2] + ram_pl + 3);
+                    for ( i = 0 ; i < 4 ; i++ )
+                    {
+                        display_string[c + 6 + i] = ( tmpW[i] == ' ' ) ? '0' : tmpW[i];
+                    }
+                }
+                c += 3;
+
+            }
+            else
+            {
+                display_string[c + 6] = datas[c];
+            }
+        }
+        else
+        {
+            if ( datas[c + 1] == '1' )
+            {
+                sprintf(tmp, "%2x", prog[ram_pl + 1]);
+                for ( i = 0 ; i < 2 ; i++ )
+                {
+                    display_string[c + 6 + i] = tmp[i] == ' ' ? '0' : tmp[i];
+                }
+            }
+            if ( datas[c + 1] == '2' )
+            {
+                sprintf(tmp, "%2x", prog[ram_pl + 2]);
+                for ( i = 0 ; i < 2 ; i++ )
+                {
+                    display_string[c + 6 + i] = tmp[i] == ' ' ? '0' : tmp[i];
+                }
+            }
+            c++;
+        }
+    }
+}
+
+void code_51::process(void)
+{
+    uint8_t tmpB;
+    uint16_t tmpW;
+    switch ( code )
+    {
+    case 0x00:  //nop                      00
+        PC++;
+        break;
+    case 0x74:  // mov a,#(byte)           74 xx
+        PC++;
+        *Acc = prog[PC];
+        PC++;
+        break;
+    case 0x75:  // mov (adress),#(byte)    75 xx yy
+        PC++;
+        SFR[prog[PC]] = prog[PC + 1];
+        PC += 2;
+        break;
+    case 0x02:  // ljmp 16bit_adres        02 xx yy
+        PC++;
+        PC = (uint16_t) prog[PC] << 8 | prog[PC + 1];
+        break;
+    case 0x80:  // sjmp offset             80 oo
+        PC++;
+        PC += (signed char) prog[PC] + 1;
+        break;
+    case 0x85:  // mov (adress1),(ardess2) 85 yy xx
+        PC++;
+        SFR[prog[PC + 1]] = SFR[prog[PC]];
+        PC += 2;
+        break;
+    case 0xe5:  // mov A,(adress)
+        PC++;
+        *Acc = SFR[prog[PC]];
+        PC++;
+        break;
+    case 0x92:  // mov (bit),C
+        PC++;
+        if ( check_C())
+        {
+            set_Bit(prog[PC]);
+        }
+        else
+        {
+            clr_Bit(prog[PC]);
+        }
+        PC++;
+        break;
+    case 0x04:  // inc a
+        ( *Acc )++;
+        PC++;
+        break;
+    case 0x05:  // inc (adress)
+        PC++;
+        SFR[prog[PC]]++;
+        PC++;
+        break;
+    case 0xa3:  // inc DPTR
+        *DPTR = *DPTR + 1;
+        PC++;
+        break;
+    case 0x06: //inc @R0
+        SFR[R[0]]++;
+        PC++;
+        break;
+    case 0x07: //inc @R1
+        SFR[R[1]]++;
+        PC++;
+        break;
+    case 0x08: //inc R0
+        R[0]++;
+        PC++;
+        break;
+    case 0x09: //inc R1
+        R[1]++;
+        PC++;
+        break;
+    case 0x0a: //inc R2
+        R[2]++;
+        PC++;
+        break;
+    case 0x0b: //inc R3
+        R[3]++;
+        PC++;
+        break;
+    case 0x0c: //inc R4
+        R[4]++;
+        PC++;
+        break;
+    case 0x0d: //inc R5
+        R[5]++;
+        PC++;
+        break;
+    case 0x0e: //inc R6
+        R[6]++;
+        PC++;
+        break;
+    case 0x0f: //inc R7
+        R[7]++;
+        PC++;
+        break;
+    case 0x14: //dec A
+        *Acc = *Acc - 1;
+        PC++;
+        break;
+    case 0x15: //dec (adress)
+        PC++;
+        SFR[prog[PC]]--;
+        PC++;
+        break;
+    case 0x16: //dec @R0
+        SFR[R[0]]--;
+        PC++;
+        break;
+    case 0x17: //dec @R1
+        SFR[R[1]]--;
+        PC++;
+        break;
+    case 0x18: // dec R0
+        R[0]--;
+        PC++;
+        break;
+    case 0x19: // dec R1
+        R[1]--;
+        PC++;
+        break;
+    case 0x1a: // dec R2
+        R[2]--;
+        PC++;
+        break;
+    case 0x1b: // dec R3
+        R[3]--;
+        PC++;
+        break;
+    case 0x1c: // dec R4
+        R[4]--;
+        PC++;
+        break;
+    case 0x1d: // dec R5
+        R[5]--;
+        PC++;
+        break;
+    case 0x1e: // dec R6
+        R[6]--;
+        PC++;
+        break;
+    case 0x1f: // dec R7
+        R[7]--;
+        PC++;
+        break;
+    case 0x84:  // div AB
+        clr_C();
+        if ( *B != 0 )
+        {
+            tmpB = *Acc;
+            *Acc = tmpB / *B;
+            *B = tmpB % *B;
+        }
+        else
+        {
+            set_OV();
+        }
+        PC++;
+        break;
+    case 0xa4:  // mul AB
+        tmpW = (uint16_t) *Acc * (uint16_t) *B;
+        if ( tmpW > 255 )
+        {
+            set_OV();
+        }
+        else
+        {
+            clr_OV();
+        }
+        *B = (uint8_t) tmpW >> 8;
+        *Acc = (uint8_t) ( tmpW & 0xff );
+        PC++;
+        break;
+    case 0x23:  // rl A
+        tmpB = *Acc;
+        *Acc = tmpB << 1 | tmpB >> 7;
+        PC++;
+        break;
+    case 0x03:  // rr A
+        tmpB = *Acc;
+        *Acc = tmpB >> 1 | tmpB << 7;
+        PC++;
+        break;
+    case 0x33:  // rlc A
+        tmpB = *Acc;
+        *Acc = tmpB << 1 | check_C();
+        if ( tmpB & 0x80 )
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        PC++;
+        break;
+    case 0x13:  // rrc A
+        tmpB = *Acc;
+        *Acc = tmpB >> 1 | check_C() << 7;
+        if ( tmpB & 0x01 )
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        PC++;
+        break;
+    case 0x90:  // mov DPTR,#(16-bit data)
+        PC++;
+        *DPH = prog[PC];
+        PC++;
+        *DPL = prog[PC];
+        PC++;
+        break;
+    case 0xf5:  // mov (adress),A
+        PC++;
+        SFR[prog[PC]] = *Acc;
+        PC++;
+        break;
+        // ADD (full functional)
+    case 0x24:  // add A,#(data)
+        PC++;
+        _add(*Acc, prog[PC]);
+        PC++;
+        break;
+    case 0x25:  // add A,(adres)
+        PC++;
+        _add(*Acc, SFR[prog[PC]]);
+        PC++;
+        break;
+    case 0x26:  // add A,@R0
+        _add(*Acc, SFR[R[0]]);
+        PC++;
+        break;
+    case 0x27:  // add A,@R1
+        _add(*Acc, SFR[R[1]]);
+        PC++;
+        break;
+    case 0x28: //add A,R0
+        _add(*Acc, R[0]);
+        PC++;
+        break;
+    case 0x29: //add A,R1
+        _add(*Acc, R[1]);
+        PC++;
+        break;
+    case 0x2a: //add A,R2
+        _add(*Acc, R[2]);
+        PC++;
+        break;
+    case 0x2b: //add A,R3
+        _add(*Acc, R[3]);
+        PC++;
+        break;
+    case 0x2c: //add A,R4
+        _add(*Acc, R[4]);
+        PC++;
+        break;
+    case 0x2d: //add A,R5
+        _add(*Acc, R[5]);
+        PC++;
+        break;
+    case 0x2e: //add A,R6
+        _add(*Acc, R[6]);
+        PC++;
+        break;
+    case 0x2f: //add A,R7
+        _add(*Acc, R[7]);
+        PC++;
+        break;
+        // ADDC
+    case 0x34:  // addc A,#(data)
+        PC++;
+        _addc(*Acc, prog[PC]);
+        PC++;
+        break;
+    case 0x35:  // addc A,(adres)
+        PC++;
+        _addc(*Acc, SFR[prog[PC]]);
+        PC++;
+        break;
+    case 0x36:  // addc A,@R0
+        _addc(*Acc, SFR[R[0]]);
+        PC++;
+        break;
+    case 0x37:  // addc A,@R1
+        _addc(*Acc, SFR[R[1]]);
+        PC++;
+        break;
+    case 0x38: //addc A,R0
+        _addc(*Acc, R[0]);
+        PC++;
+        break;
+    case 0x39: //addc A,R1
+        _addc(*Acc, R[1]);
+        PC++;
+        break;
+    case 0x3a: //addc A,R2
+        _addc(*Acc, R[2]);
+        PC++;
+        break;
+    case 0x3b: //addc A,R3
+        _addc(*Acc, R[3]);
+        PC++;
+        break;
+    case 0x3c: //addc A,R4
+        _addc(*Acc, R[4]);
+        PC++;
+        break;
+    case 0x3d: //addc A,R5
+        _addc(*Acc, R[5]);
+        PC++;
+        break;
+    case 0x3e: //addc A,R6
+        _addc(*Acc, R[6]);
+        PC++;
+        break;
+    case 0x3f: //addc A,R7
+        _addc(*Acc, R[7]);
+        PC++;
+        break;
+    case 0xe0:  // movx A,@DPTR
+        *Acc = ram[*DPTR];
+        PC++;
+        break;
+    case 0xf0:  // movx @DPTR,A
+        ram[*DPTR] = *Acc;
+        PC++;
+        break;
+    case 0xc0:  // push (adress)
+        *SP = *SP + 1;
+        PC++;
+        SFR[*SP] = SFR[prog[PC]];
+        PC++;
+        break;
+    case 0xd0:  // pop (adress)
+        PC++;
+        SFR[prog[PC]] = SFR[*SP];
+        *SP = *SP - 1;
+        PC++;
+        break;
+    case 0xc3:  // clr C
+        clr_C();
+        PC++;
+        break;
+    case 0xd3:  // setb C
+        set_C();
+        PC++;
+        break;
+    case 0xd2:  // setb (bit)
+        PC++;
+        set_Bit(prog[PC]);
+        PC++;
+        break;
+    case 0xc2:  // clr (bit)
+        PC++;
+        clr_Bit(prog[PC]);
+        PC++;
+        break;
+    case 0x62:  // xrl (adress),A
+        PC++;
+        SFR[prog[PC]] = SFR[prog[PC]] ^ ( *Acc );
+        PC++;
+        break;
+    case 0x63:  // xrl (adress),#(data)
+        PC++;
+        SFR[prog[PC]] ^= prog[PC + 1];
+        PC += 2;
+        break;
+    case 0x64:  // xrl A,#(data)
+        PC++;
+        *Acc = *Acc ^ prog[PC];
+        PC++;
+        break;
+    case 0x65:  // xrl A,(adress)
+        PC++;
+        *Acc = *Acc ^ SFR[prog[PC]];
+        PC++;
+        break;
+    case 0x66:  // xrl A,@R0
+        *Acc = *Acc ^ SFR[R[0]];
+        PC++;
+        break;
+    case 0x67:  // xrl A,@R1
+        *Acc = *Acc ^ SFR[R[1]];
+        PC++;
+        break;
+    case 0x68:  // xrl A,R0
+        *Acc = ( *Acc ) ^ R[0];
+        PC++;
+        break;
+    case 0x69:  // xrl A,R1
+        *Acc = ( *Acc ) ^ R[1];
+        PC++;
+        break;
+    case 0x6a:  // xrl A,R2
+        *Acc = ( *Acc ) ^ R[2];
+        PC++;
+        break;
+    case 0x6b:  // xrl A,R3
+        *Acc = ( *Acc ) ^ R[3];
+        PC++;
+        break;
+    case 0x6c:  // xrl A,R4
+        *Acc = ( *Acc ) ^ R[4];
+        PC++;
+        break;
+    case 0x6d:  // xrl A,R5
+        *Acc = ( *Acc ) ^ R[5];
+        PC++;
+        break;
+    case 0x6e:  // xrl A,R6
+        *Acc = ( *Acc ) ^ R[6];
+        PC++;
+        break;
+    case 0x6f:  // xrl A,R7
+        *Acc = ( *Acc ) ^ R[7];
+        PC++;
+        break;
+    case 0xc5:  // xch A,(adress)
+        PC++;
+        tmpB = *Acc;
+        *Acc = SFR[prog[PC]];
+        SFR[prog[PC]] = tmpB;
+        PC++;
+        break;
+    case 0xc6:  // xch A,@R0
+        tmpB = *Acc;
+        *Acc = SFR[R[0]];
+        SFR[R[0]] = tmpB;
+        PC++;
+        break;
+    case 0xc7:  // xch A,@R1
+        tmpB = *Acc;
+        *Acc = SFR[R[1]];
+        SFR[R[1]] = tmpB;
+        PC++;
+        break;
+    case 0xc8:  // xch A,R0
+        tmpB = *Acc;
+        *Acc = R[0];
+        R[0] = tmpB;
+        PC++;
+        break;
+    case 0xc9:  // xch A,R1
+        tmpB = *Acc;
+        *Acc = R[1];
+        R[1] = tmpB;
+        PC++;
+        break;
+    case 0xca:  // xch A,R2
+        tmpB = *Acc;
+        *Acc = R[2];
+        R[2] = tmpB;
+        PC++;
+        break;
+    case 0xcb:  // xch A,R3
+        tmpB = *Acc;
+        *Acc = R[3];
+        R[3] = tmpB;
+        PC++;
+        break;
+    case 0xcc:  // xch A,R4
+        tmpB = *Acc;
+        *Acc = R[4];
+        R[4] = tmpB;
+        PC++;
+        break;
+    case 0xcd:  // xch A,R5
+        tmpB = *Acc;
+        *Acc = R[5];
+        R[5] = tmpB;
+        PC++;
+        break;
+    case 0xce:  // xch A,R6
+        tmpB = *Acc;
+        *Acc = R[6];
+        R[6] = tmpB;
+        PC++;
+        break;
+    case 0xcf:  // xch A,R7
+        tmpB = *Acc;
+        *Acc = R[7];
+        R[7] = tmpB;
+        PC++;
+        break;
+    case 0x12:  // lcall 16bit_adres        02 xx yy
+        tmpW = PC + 3;
+        PC++;
+        PC = (uint16_t) prog[PC] << 8 | prog[PC + 1];
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW & 0x00ff );
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW >> 8 );
+        break;
+    case 0x22: // ret
+        PC = (uint16_t) SFR[*SP] << 8 | (uint16_t) SFR[*SP - 1];
+        *SP = *SP - 2;
+        break;
+    case 0x70: // jnz (offset)
+        PC++;
+        if ( *Acc != 0 )
+        {
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC++;
+        }
+        break;
+    case 0x60: // jz (offset)
+        PC++;
+        if ( *Acc == 0 )
+        {
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC++;
+        }
+        break;
+    case 0x40:  // jc (offset)
+        PC++;
+        if ( check_C())
+        {
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC++;
+        }
+        break;
+    case 0x50:  // jnc (offset)
+        PC++;
+        if ( !check_C())
+        {
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC++;
+        }
+        break;
+    case 0xc4:  // swap A
+        tmpB = *Acc;
+        tmpB = ( tmpB << 4 ) & 0xf0;
+        *Acc = ( *Acc >> 4 ) & 0x0f;
+        *Acc = *Acc | tmpB;
+        PC++;
+        break;
+    case 0x93:  // movc A,@DPTR+A
+        *Acc = ram[*Acc + *DPTR];
+        PC++;
+        break;
+    case 0x83:  // movc A,@PC+A
+        *Acc = ram[*Acc + PC];
+        PC++;
+        break;
+    case 0xe6:  // mov A,@R0
+        *Acc = SFR[R[0]];
+        PC++;
+        break;
+    case 0xe7:  // mov A,@R1
+        *Acc = SFR[R[1]];
+        PC++;
+        break;
+    case 0xf6:  // mov @R0,A
+        SFR[R[0]] = *Acc;
+        PC++;
+        break;
+    case 0xf7:  // mov @R1,a
+        SFR[R[1]] = *Acc;
+        PC++;
+        break;
+    case 0x78:  // mov R0,#(data)
+        PC++;
+        R[0] = prog[PC];
+        PC++;
+        break;
+    case 0x79: // mov R1,#(data)
+        PC++;
+        R[1] = prog[PC];
+        PC++;
+        break;
+    case 0x7a:  // mov R2,#(data)
+        PC++;
+        R[2] = prog[PC];
+        PC++;
+        break;
+    case 0x7b:  // mov R3,#(data)
+        PC++;
+        R[3] = prog[PC];
+        PC++;
+        break;
+    case 0x7c:   // mov R4,#(data)
+        PC++;
+        R[4] = prog[PC];
+        PC++;
+        break;
+    case 0x7d:  // mov R5,#(data)
+        PC++;
+        R[5] = prog[PC];
+        PC++;
+        break;
+    case 0x7e:  // mov R6,#(data)
+        PC++;
+        R[6] = prog[PC];
+        PC++;
+        break;
+    case 0x7f:   // mov R7,#(data)
+        PC++;
+        R[7] = prog[PC];
+        PC++;
+        break;
+    case 0xa8:   // mov R0,(adress)
+        PC++;
+        R[0] = SFR[prog[PC]];
+        PC++;
+        break;
+    case 0xa9:  // mov R1,(adress)
+        PC++;
+        R[1] = SFR[prog[PC]];
+        PC++;
+        break;
+    case 0xaa:  // mov R2,(adress)
+        PC++;
+        R[2] = SFR[prog[PC]];
+        PC++;
+        break;
+    case 0xab:  // mov R3,(adress)
+        PC++;
+        R[3] = SFR[prog[PC]];
+        PC++;
+        break;
+    case 0xac:  // mov R4,(adress)
+        PC++;
+        R[4] = SFR[prog[PC]];
+        PC++;
+        break;
+    case 0xad:  // mov R5,(adress)
+        PC++;
+        R[5] = SFR[prog[PC]];
+        PC++;
+        break;
+    case 0xae:  // mov R6,(adress)
+        PC++;
+        R[6] = SFR[prog[PC]];
+        PC++;
+        break;
+    case 0xaf: // mov R7,(adress)
+        PC++;
+        R[7] = SFR[prog[PC]];
+        PC++;
+        break;
+    case 0x88:   // mov (adress),R0
+        PC++;
+        SFR[prog[PC]] = R[0];
+        PC++;
+        break;
+    case 0x89:   // mov (adress),R1
+        PC++;
+        SFR[prog[PC]] = R[1];
+        PC++;
+        break;
+    case 0x8a:   // mov (adress),R2
+        PC++;
+        SFR[prog[PC]] = R[2];
+        PC++;
+        break;
+    case 0x8b:   // mov (adress),R3
+        PC++;
+        SFR[prog[PC]] = R[3];
+        PC++;
+        break;
+    case 0x8c:   // mov (adress),R4
+        PC++;
+        SFR[prog[PC]] = R[4];
+        PC++;
+        break;
+    case 0x8d:   // mov (adress),R5
+        PC++;
+        SFR[prog[PC]] = R[5];
+        PC++;
+        break;
+    case 0x8e:   // mov (adress),R6
+        PC++;
+        SFR[prog[PC]] = R[6];
+        PC++;
+        break;
+    case 0x8f:   // mov (adress),R7
+        PC++;
+        SFR[prog[PC]] = R[7];
+        PC++;
+        break;
+    case 0xf8:  // mov R0,A
+        PC++;
+        R[0] = *Acc;
+        break;
+    case 0xf9:  // mov R1,A
+        PC++;
+        R[1] = *Acc;
+        break;
+    case 0xfa:  // mov R2,A
+        PC++;
+        R[2] = *Acc;
+        break;
+    case 0xfb:  // mov R3,A
+        PC++;
+        R[3] = *Acc;
+        break;
+    case 0xfc:  // mov R4,A
+        PC++;
+        R[4] = *Acc;
+        break;
+    case 0xfd:  // mov R5,A
+        PC++;
+        R[5] = *Acc;
+        break;
+    case 0xfe:  // mov R6,A
+        PC++;
+        R[6] = *Acc;
+        break;
+    case 0xff:  // mov R7,A
+        PC++;
+        R[7] = *Acc;
+        break;
+    case 0xe8:  // mov A,R0
+        PC++;
+        *Acc = R[0];
+        break;
+    case 0xe9:  // mov A,R1
+        PC++;
+        *Acc = R[1];
+        break;
+    case 0xea:  // mov A,R2
+        PC++;
+        *Acc = R[2];
+        break;
+    case 0xeb:  // mov A,R3
+        PC++;
+        *Acc = R[3];
+        break;
+    case 0xec:  // mov A,R4
+        PC++;
+        *Acc = R[4];
+        break;
+    case 0xed:  // mov A,R5
+        PC++;
+        *Acc = R[5];
+        break;
+    case 0xee:  // mov A,R6
+        PC++;
+        *Acc = R[6];
+        break;
+    case 0xef:  // mov A,R7
+        PC++;
+        *Acc = R[7];
+        break;
+    case 0xe4: //clr A
+        PC++;
+        *Acc = 0;
+        break;
+    case 0x01: // ajmp 00xx
+        PC++;
+        PC = (uint16_t) prog[PC];
+        break;
+    case 0x21: // ajmp 01xx
+        PC++;
+        PC = 0x0100 | (uint16_t) prog[PC];
+        break;
+    case 0x41: // ajmp 02xx
+        PC++;
+        PC = 0x0200 | (uint16_t) prog[PC];
+        break;
+    case 0x61: // ajmp 03xx
+        PC++;
+        PC = 0x0300 | (uint16_t) prog[PC];
+        break;
+    case 0x81: // ajmp 04xx
+        PC++;
+        PC = 0x0400 | (uint16_t) prog[PC];
+        break;
+    case 0xa1: // ajmp 05xx
+        PC++;
+        PC = 0x0500 | (uint16_t) prog[PC];
+        break;
+    case 0xc1: // ajmp 06xx
+        PC++;
+        PC = 0x0600 | (uint16_t) prog[PC];
+        break;
+    case 0xe1: // ajmp 07xx
+        PC++;
+        PC = 0x0700 | (uint16_t) prog[PC];
+        break;
+    case 0x11: // acall 00xx
+        tmpW = PC + 2;
+        PC++;
+        PC = (uint16_t) prog[PC];
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW & 0x00ff );
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW >> 8 );
+        break;
+    case 0x31: // acall 01xx
+        tmpW = PC + 2;
+        PC++;
+        PC = 0x0100 | prog[PC];
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW & 0x00ff );
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW >> 8 );
+        break;
+    case 0x51: // acall 02xx
+        tmpW = PC + 2;
+        PC++;
+        PC = 0x0200 | prog[PC];
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW & 0x00ff );
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW >> 8 );
+        break;
+    case 0x71: // acall 03xx
+        tmpW = PC + 2;
+        PC++;
+        PC = 0x0300 | prog[PC];
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW & 0x00ff );
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW >> 8 );
+        break;
+    case 0x91: // acall 04xx
+        tmpW = PC + 2;
+        PC++;
+        PC = 0x0400 | prog[PC];
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW & 0x00ff );
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW >> 8 );
+        break;
+    case 0xb1: // acall 05xx
+        tmpW = PC + 2;
+        PC++;
+        PC = 0x0500 | prog[PC];
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW & 0x00ff );
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW >> 8 );
+        break;
+    case 0xd1: // acall 06xx
+        tmpW = PC + 2;
+        PC++;
+        PC = 0x0600 | prog[PC];
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW & 0x00ff );
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW >> 8 );
+        break;
+    case 0xf1: // acall 07xx
+        tmpW = PC + 2;
+        PC++;
+        PC = 0x0700 | prog[PC];
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW & 0x00ff );
+        *SP = *SP + 1;
+        SFR[*SP] = (uint8_t) ( tmpW >> 8 );
+        break;
+    case 0xd8: // djnz R0,(offset)
+        PC++;
+        R[0]--;
+        if ( R[0] != 0 )
+        {
+            PC += (signed char) prog[PC];
+        }
+        PC++;
+        break;
+    case 0xd9: // djnz R1,(offset)
+        PC++;
+        R[1]--;
+        if ( R[1] != 0 )
+        {
+            PC += (signed char) prog[PC];
+        }
+        PC++;
+        break;
+    case 0xda: // djnz R2,(offset)
+        PC++;
+        R[2]--;
+        if ( R[2] != 0 )
+        {
+            PC += (signed char) prog[PC];
+        }
+        PC++;
+        break;
+    case 0xdb: // djnz R3,(offset)
+        PC++;
+        R[3]--;
+        if ( R[3] != 0 )
+        {
+            PC += (signed char) prog[PC];
+        }
+        PC++;
+        break;
+    case 0xdc: // djnz R4,(offset)
+        PC++;
+        R[4]--;
+        if ( R[4] != 0 )
+        {
+            PC += (signed char) prog[PC];
+        }
+        PC++;
+        break;
+    case 0xdd: // djnz R5,(offset)
+        PC++;
+        R[5]--;
+        if ( R[5] != 0 )
+        {
+            PC += (signed char) prog[PC];
+        }
+        PC++;
+        break;
+    case 0xde: // djnz R6,(offset)
+        PC++;
+        R[6]--;
+        if ( R[6] != 0 )
+        {
+            PC += (signed char) prog[PC];
+        }
+        PC++;
+        break;
+    case 0xdf: // djnz R7,(offset)
+        PC++;
+        R[7]--;
+        if ( R[7] != 0 )
+        {
+            PC += (signed char) prog[PC];
+        }
+        PC++;
+        break;
+    case 0xd5: // djnz (adress),(offset)
+        PC++;
+        tmpB = prog[PC];
+        PC++;
+        SFR[tmpB]--;
+        if ( SFR[tmpB] != 0 )
+        {
+            PC += (signed char) prog[PC];
+        }
+        PC++;
+        break;
+    case 0x43: // orl (adress),#(data)
+        PC++;
+        SFR[prog[PC]] = SFR[prog[PC]] | prog[PC + 1];
+        PC += 2;
+        break;
+    case 0x44: // orl A,#(data)
+        PC++;
+        *Acc = prog[PC] | *Acc;
+        PC++;
+        break;
+    case 0x45: // orl A,(adress)
+        PC++;
+        *Acc = SFR[prog[PC]] | *Acc;
+        PC++;
+        break;
+    case 0x42: // orl (adress),A
+        PC++;
+        SFR[prog[PC]] = SFR[prog[PC]] | *Acc;
+        PC++;
+        break;
+    case 0x48: // orl A,R0
+        *Acc = *Acc | R[0];
+        PC++;
+        break;
+    case 0x49: // orl A,R1
+        *Acc = *Acc | R[1];
+        PC++;
+        break;
+    case 0x4a: // orl A,R2
+        *Acc = *Acc | R[2];
+        PC++;
+        break;
+    case 0x4b: // orl A,R3
+        *Acc = *Acc | R[3];
+        PC++;
+        break;
+    case 0x4c: // orl A,R4
+        *Acc = *Acc | R[4];
+        PC++;
+        break;
+    case 0x4d: // orl A,R5
+        *Acc = *Acc | R[5];
+        PC++;
+        break;
+    case 0x4e: // orl A,R6
+        *Acc = *Acc | R[6];
+        PC++;
+        break;
+    case 0x4f: // orl A,R7
+        *Acc = *Acc | R[7];
+        PC++;
+        break;
+    case 0x46: // orl A,@R0
+        *Acc = *Acc | SFR[R[0]];
+        PC++;
+        break;
+    case 0x47: // orl A,@R1
+        *Acc = *Acc | SFR[R[1]];
+        PC++;
+        break;
+    case 0x54:  // anl A,#(data)
+        PC++;
+        *Acc = *Acc & prog[PC];
+        PC++;
+        break;
+    case 0x55: // anl A,(adress)
+        PC++;
+        *Acc = SFR[prog[PC]] & *Acc;
+        PC++;
+        break;
+    case 0x52: // anl (adress),A
+        PC++;
+        SFR[prog[PC]] = SFR[prog[PC]] & *Acc;
+        PC++;
+        break;
+    case 0x53: // anl (adress),#(data)
+        PC++;
+        SFR[prog[PC]] = SFR[prog[PC]] & prog[PC + 1];
+        PC++;
+        break;
+    case 0x58: // anl A,R0
+        *Acc = *Acc & R[0];
+        PC++;
+        break;
+    case 0x59: // anl A,R1
+        *Acc = *Acc & R[1];
+        PC++;
+        break;
+    case 0x5a: // anl A,R2
+        *Acc = *Acc & R[2];
+        PC++;
+        break;
+    case 0x5b: // anl A,R3
+        *Acc = *Acc & R[3];
+        PC++;
+        break;
+    case 0x5c: // anl A,R4
+        *Acc = *Acc & R[4];
+        PC++;
+        break;
+    case 0x5d: // anl A,R5
+        *Acc = *Acc & R[5];
+        PC++;
+        break;
+    case 0x5e: // anl A,R6
+        *Acc = *Acc & R[6];
+        PC++;
+        break;
+    case 0x5f: // anl A,R7
+        *Acc = *Acc & R[7];
+        PC++;
+        break;
+    case 0x56: // anl A,@R0
+        *Acc = *Acc & SFR[R[0]];
+        PC++;
+        break;
+    case 0x57: // anl A,@R1
+        *Acc = *Acc & SFR[R[1]];
+        PC++;
+        break;
+    case 0xa2: // mov C,(bit)
+        PC++;
+        if ( check_Bit(prog[PC]))
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        PC++;
+        break;
+    case 0xb2: // cpl (bit)
+        PC++;
+        if ( check_Bit(prog[PC]))
+        {
+            clr_Bit(prog[PC]);
+        }
+        else
+        {
+            set_Bit(prog[PC]);
+        }
+        PC++;
+        break;
+    case 0xb3: // cpl C
+        PC++;
+        if ( check_C())
+        {
+            clr_C();
+        }
+        else
+        {
+            set_C();
+        }
+        break;
+    case 0x72: // orl C,(bit)
+        PC++;
+        if ( check_C() || check_Bit(prog[PC]))
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        PC++;
+        break;
+    case 0xa0: // orl C,/(bit)
+        PC++;
+        if ( check_C() || !check_Bit(prog[PC]))
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        PC++;
+        break;
+    case 0x82: // anl C,(bit)
+        PC++;
+        if ( check_C() && check_Bit(prog[PC]))
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        PC++;
+        break;
+    case 0xb0: // anl C,/(bit)
+        PC++;
+        if ( check_C() && !check_Bit(prog[PC]))
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        PC++;
+        break;
+    case 0xf4: // cpl A
+        *Acc = *Acc ^ 0xff;
+        PC++;
+        break;
+    case 0xa6: // mov @R0,(adress)
+        PC++;
+        SFR[R[0]] = SFR[prog[PC]];
+        PC++;
+        break;
+    case 0xa7: // mov @R1,(adress)
+        PC++;
+        SFR[R[1]] = SFR[prog[PC]];
+        PC++;
+        break;
+    case 0x76: // mov @R0,#(data)
+        PC++;
+        SFR[R[0]] = prog[PC];
+        PC++;
+        break;
+    case 0x77: // mov @R1,#(data)
+        PC++;
+        SFR[R[1]] = prog[PC];
+        PC++;
+        break;
+    case 0x86: // mov (adress),@R0
+        PC++;
+        SFR[prog[PC]] = SFR[R[0]];
+        PC++;
+        break;
+    case 0x87: // mov (adress),@R1
+        PC++;
+        SFR[prog[PC]] = SFR[R[1]];
+        PC++;
+        break;
+    case 0x73: // jmp @A+DPTR
+        PC = (uint16_t) ( *Acc + *DPTR );
+        break;
+    case 0xb4: // cjne A,#(byte),offset
+        PC++;
+        if ( *Acc < prog[PC] )
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        if ( *Acc != prog[PC] )
+        {
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0xb5: // cjne A,(adress),offset
+        PC++;
+        if ( *Acc < SFR[prog[PC]] )
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        if ( *Acc != SFR[prog[PC]] )
+        {
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0xb6: // cjne @R0,#(byte),offset
+        PC++;
+        if ( SFR[R[0]] < prog[PC] )
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        if ( SFR[R[0]] != prog[PC] )
+        {
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0xb7: // cjne @R1,#(byte),offset
+        PC++;
+        if ( SFR[R[1]] < prog[PC] )
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        if ( SFR[R[1]] != prog[PC] )
+        {
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0xb8: // cjne R0,#(byte),offset
+        PC++;
+        if ( R[0] < prog[PC] )
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        if ( R[0] != prog[PC] )
+        {
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0xb9: // cjne R1,#(byte),offset
+        PC++;
+        if ( R[1] < prog[PC] )
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        if ( R[1] != prog[PC] )
+        {
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0xba: // cjne R2,#(byte),offset
+        PC++;
+        if ( R[2] < prog[PC] )
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        if ( R[2] != prog[PC] )
+        {
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0xbb: // cjne R3,#(byte),offset
+        PC++;
+        if ( R[3] < prog[PC] )
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        if ( R[3] != prog[PC] )
+        {
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0xbc: // cjne R4,#(byte),offset
+        PC++;
+        if ( R[4] < prog[PC] )
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        if ( R[4] != prog[PC] )
+        {
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0xbd: // cjne R5,#(byte),offset
+        PC++;
+        if ( R[5] < prog[PC] )
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        if ( R[5] != prog[PC] )
+        {
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0xbe: // cjne R6,#(byte),offset
+        PC++;
+        if ( R[6] < prog[PC] )
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        if ( R[6] != prog[PC] )
+        {
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0xbf: // cjne R7,#(byte),offset
+        PC++;
+        if ( R[7] < prog[PC] )
+        {
+            set_C();
+        }
+        else
+        {
+            clr_C();
+        }
+        if ( R[7] != prog[PC] )
+        {
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0x32: // reti
+        PC = (uint16_t) SFR[*SP] << 8 | (uint16_t) SFR[*SP - 1];
+        *SP = *SP - 2;
+        break;
+    case 0x30: //jnb (bit),(offset)
+        PC++;
+        if ( !check_Bit(prog[PC]))
+        {
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0x20: //jb (bit),(offset)
+        PC++;
+        if ( check_Bit(prog[PC]))
+        {
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0x10: //jbc (bit),(offset)
+        PC++;
+        if ( check_Bit(prog[PC]))
+        {
+            clr_Bit(prog[PC]);
+            PC++;
+            PC += (signed char) prog[PC] + 1;
+        }
+        else
+        {
+            PC += 2;
+        }
+        break;
+    case 0x94: // subb A,#(data)
+        PC++;
+        _subb(*Acc, prog[PC]); //*Acc=*Acc-prog[PC];
+        PC++;
+        break;
+    case 0x95: // subb A,(adress)
+        PC++;
+        _subb(*Acc, SFR[prog[PC]]); //*Acc=*Acc-SFR[prog[PC]];
+        PC++;
+        break;
+    case 0x96: // subb A,@R0
+        PC++;
+        _subb(*Acc, SFR[R[0]]); //*Acc=*Acc-SFR[R[0]];
+        PC++;
+        break;
+    case 0x97: // subb A,@R1
+        PC++;
+        _subb(*Acc, SFR[R[1]]); //*Acc=*Acc-SFR[R[1]];
+        PC++;
+        break;
+    case 0x98: // subb A,R0
+        PC++;
+        _subb(*Acc, R[0]); //*Acc=*Acc-R[0];
+        PC++;
+        break;
+    case 0x99: // subb A,R1
+        PC++;
+        _subb(*Acc, R[1]); //*Acc=*Acc-R[1];
+        PC++;
+        break;
+    case 0x9a: // subb A,R2
+        PC++;
+        _subb(*Acc, R[2]); //*Acc=*Acc-R[2];
+        PC++;
+        break;
+    case 0x9b: // subb A,R3
+        PC++;
+        _subb(*Acc, R[3]); //*Acc=*Acc-R[3];
+        PC++;
+        break;
+    case 0x9c: // subb A,R4
+        PC++;
+        _subb(*Acc, R[4]); //*Acc=*Acc-R[4];
+        PC++;
+        break;
+    case 0x9d: // subb A,R5
+        PC++;
+        _subb(*Acc, R[5]); //*Acc=*Acc-R[5];
+        PC++;
+        break;
+    case 0x9e: // subb A,R6
+        PC++;
+        _subb(*Acc, R[6]); //*Acc=*Acc-R[6];
+        PC++;
+        break;
+    case 0x9f: // subb A,R7
+        PC++;
+        _subb(*Acc, R[7]); //*Acc=*Acc-R[7];
+        PC++;
+        break;
+    case 0xd4:  // da A
+        PC++;
+        tmpB = *Acc;
+        *Acc &= 0xf;
+        tmpB >>= 4;
+        if (( *Acc > 9 ) || check_AC())
+        {
+            *Acc += 9;
+        }
+        if (( tmpB > 9 ) || check_C())
+        {
+            tmpB += 9;
+        }
+        *Acc |= tmpB << 4;
+        break;
+    case 0xd6:  // xchd A,@R0
+        PC++;
+        tmpB = SFR[R[0]] & 0xf;
+        SFR[R[0]] &= 0xf;
+        SFR[R[0]] |= ( *Acc ) & 0xf;
+        ( *Acc ) &= 0xf;
+        ( *Acc ) |= tmpB;
+        break;
+    case 0xd7:  // xchd A,@R1
+        PC++;
+        tmpB = SFR[R[1]] & 0xf;
+        SFR[R[1]] &= 0xf;
+        SFR[R[1]] |= ( *Acc ) & 0xf;
+        ( *Acc ) &= 0xf;
+        ( *Acc ) |= tmpB;
+        break;
+    case 0xe2:  // movx A,@R0
+        *Acc = ram[R[0]];
+        PC++;
+        break;
+    case 0xe3:  // movx A,@R1
+        *Acc = ram[R[1]];
+        PC++;
+        break;
+    case 0xf2:  // movx @R0,A
+        ram[R[0]] = *Acc;
+        PC++;
+        break;
+    case 0xf3:  // movx @R1,A
+        ram[R[1]] = *Acc;
+        PC++;
+        break;
+    }
+
+    uint8_t cnt = 0;
+    // count cycles
+    c_time += cycles;
+
+    // count bits in Acc
+    for ( uint8_t c = 0 ; c <= 7 ; c++ )
+    {
+        if (( 1 << c ) & *Acc )
+        {
+            cnt++;
+        }
+    }
+    // parrity check
+    if ( cnt % 2 ) // if cnt parity isn't true
+    {
+        clr_P();
+    }
+    else
+    {
+        // if cnt parity is true
+        set_P();
+    }
+    // setup Rx bank
+    tmpB = check_RS1() << 1 | check_RS0();
+    R = &SFR[tmpB << 3];
+
+    uint8_t modeT0, modeT1;
+
+    // timers & interrupts
+    modeT0 = *TMOD & 0x03;
+    modeT1 = ( *TMOD & 0x30 ) >> 4;
+    // Timer 0
+    clr_Bit(0x8d); // clr bit TF0 - T0 overflow
+    if ( check_Bit(0x8c)) // if TR0
+    {
+        switch ( modeT0 )
+        {
+        case 0:
+            break;
+        case 1:
+            if ((int) ( *TL0 ) + (int) cycles <= 0xff )
+            {
+                *TL0 += cycles;
+            }
+            else
+            {
+                *TL0 = (uint8_t) ((int) *TL0 - (int) 0x100 + cycles );
+                if ((int) ( *TH0 ) < 0xff )
+                {
+                    *TH0 += 1;
+                }
+                else
+                {
+                    *TH0 = 0;
+                    set_Bit(0x8d); // set bit TF0 - T0 overflow
+                }
+            }
+            break;
+        case 2:
+            if ((int) ( *TL0 ) + (int) cycles <= 0xff )
+            {
+                *TL0 += cycles;
+            }
+            else
+            {
+                *TL0 = *TH0;
+                set_Bit(0x8d); // set bit TF0 - T0 overflow
+            }
+            break;
+        case 3:
+            break;
+        }
+    }
+    clr_Bit(0x8f); // clr bit TF1 - T1 overflow
+    if ( check_Bit(0x8e)) // if TR1
+    {
+        switch ( modeT1 )
+        {
+        case 0:
+            break;
+        case 1:
+            if ((int) ( *TL1 ) + (int) cycles <= 0xff )
+            {
+                *TL1 += cycles;
+            }
+            else
+            {
+                *TL1 = (uint8_t) ((int) *TL1 - (int) 0x100 + cycles );
+                if ((int) ( *TH1 ) < 0xff )
+                {
+                    *TH1 += 1;
+                }
+                else
+                {
+                    *TH1 = 0;
+                    set_Bit(0x8f); // set bit TF0 - T0 overflow
+                }
+            }
+            break;
+        case 2:
+            if ((int) ( *TL1 ) + (int) cycles <= 0xff )
+            {
+                *TL1 += cycles;
+            }
+            else
+            {
+                *TL1 = *TH1;
+                set_Bit(0x8f); // set bit TF0 - T0 overflow
+            }
+            break;
+        case 3:
+            break;
+        }
+    }
+    // Interrupts
+    if ( check_Bit(0xaf)) //if EA is 1
+    {
+        // T0 int
+        if ( check_Bit(0x8d) && check_Bit(0xa9)) // if TF0 and ET0
+        {
+            *SP = *SP + 1;
+            SFR[*SP] = (uint8_t) ( PC & 0x00ff );
+            *SP = *SP + 1;
+            SFR[*SP] = (uint8_t) ( PC >> 8 );
+            PC = 0x0000b;
+        }
+        // T1 int
+        if ( check_Bit(0x8f) && check_Bit(0xab)) // if TF1 and ET1
+        {
+            *SP = *SP + 1;
+            SFR[*SP] = (uint8_t) ( PC & 0x00ff );
+            *SP = *SP + 1;
+            SFR[*SP] = (uint8_t) ( PC >> 8 );
+            PC = 0x001b;
+        }
+    }
+}

+ 532 - 0
code_editor.cpp

@@ -0,0 +1,532 @@
+/*******************************************************************************
+ * Emu51
+ * code_editor.cpp:
+ * Created by mlt on 22/03/23.
+ ******************************************************************************/
+
+#include <stdio.h>
+
+#include <emu51.h>
+#include <code_editor.h>
+#include <gui.h>
+
+void code_editor::load_source(char *filename)
+{
+    FILE *strin;
+    int c, i, tp, j = 0;
+    strin = NULL;
+    strin = fopen(filename, "rb");
+    lines = 0;
+    if ( strin == NULL )
+    {
+        ShowMessage("Can't open the file", screen, 200, 200, 200, 60, "Message!");
+    }
+    else
+    {
+        //for (c=0;c<65535;c++)
+        //{
+        //	if (text_edit[c]!=NULL) delete[] text_edit[c];
+        //	else break;
+        //}
+
+        while ( !feof(strin))
+        {
+            alloc_new_line();
+            for ( i = 0 ; ( i < 256 ) && !feof(strin) ; i++ )
+            {
+                c = fgetc(strin);
+                if ( c == 9 ) //TAB
+                {
+                    tp = i / tab_size;
+                    tp++;
+                    tp *= 8;
+                    for ( i ; i <= tp ; i++ )
+                    {
+                        text_edit[j][i] = 32;
+                    }
+                    i--;
+                }
+                else
+                {
+                    if (( c == 10 ) || ( c == 13 ))
+                    {
+                        if ( c == 13 )
+                        {
+                            fgetc(strin);
+                        }
+                        for ( i ; i < 256 ; i++ )
+                        {
+                            text_edit[j][i] = 10;
+                        }
+                    }
+                    else
+                    {
+                        text_edit[j][i] = c == -1 ? 10 : c;
+                    }
+                }
+            }
+            j++;
+        }
+        lines = j;
+        fclose(strin);
+    }
+    cp = 0;
+    cl = 0;
+    scp = 0;
+    scl = 0;
+    disp();
+}
+
+void code_editor::disp(void)
+{
+    int i, j, cnti, cntj = 0;
+
+    for ( j = cl - scl ; j < cl - scl + _h + 1 && cntj < lines ; j++ )
+    {
+        cnti = 0;
+        bool endf = false;
+
+        for ( i = cp - scp ; i < cp - scp + _w && !endf ; i++ )
+        {
+            if ( text_edit[j][i] == 10 || text_edit[j][i] == 0 || text_edit[j][i] == 13 )
+            {
+                endf = true;
+            }
+            else
+            {
+                textprintf(surface, mainf, left + cnti * 8, top + cntj * 10, makecol(255, 255, 255), "%c",
+                           text_edit[j][i]);
+                cnti++;
+            }
+        }
+        for ( i ; i < cp - scp + _w + 1 ; i++ )
+        {
+            textprintf(surface, mainf, left + cnti * 8, top + cntj * 10, makecol(255, 255, 255), " ");
+            cnti++;
+        }
+        cntj++;
+    }
+    if ( cntj < _h )
+    {
+        rectfill(surface, left, top + cntj * 10, surface->w - left, surface->h - left, 0);
+    }
+}
+
+void code_editor::process(void)
+{
+    BITMAP *cache;
+    int c, i;
+    bool exit_ed = false;
+    char *filen;
+    filen = new char[256];
+
+    cache = create_bitmap(SCREEN_W, SCREEN_H);
+    blit(screen, cache, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
+
+    clear(surface);
+    hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
+    vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
+    vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
+    for ( c = 2 ; c <= 2 + 10 ; c += 2 )
+    {
+        hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
+    }
+    textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " Source editor ");
+    lines = 0;
+    alloc_new_line();
+    uint16_t key_p;
+    uint16_t key_ch;
+    while ( !exit_ed )
+    {
+        key_p = readkey();
+        key_ch = key_p & 0xff;
+        key_p = key_p >> 8;
+
+        switch ( key_p )
+        {
+        case KEY_BACKSPACE:
+            if ( cp > 0 )
+            {
+                clear_cr();
+                if ( scp > 0 )
+                {
+                    scp--;
+                }
+                cp--;
+                backspace();
+            }
+            else
+            {
+                if ( cl > 0 )
+                {
+                    clear_cr();
+                    for ( c = 0 ; ( c < 256 ) && ( text_edit[cl - 1][c] != 10 ) ; c++ )
+                    {
+                    }
+                    cp = c;
+                    scp = cp;
+                    if ( scp >= _w )
+                    {
+                        scp = _w - 1;
+                    }
+
+                    for ( c ; c < 256 ; c++ )
+                    {
+                        text_edit[cl - 1][c] = text_edit[cl][c - cp];
+                        if ( text_edit[cl][c - cp] == 10 )
+                        {
+                            break;
+                        }
+                    }
+                    delete[]text_edit[cl];
+                    for ( i = cl ; i < lines ; i++ )
+                    {
+                        text_edit[i] = text_edit[i + 1];
+                    }
+                    lines--;
+                    text_edit[lines] = NULL;
+                    cl--;
+                    if ( scl > 0 )
+                    {
+                        scl--;
+                    }
+                }
+            }
+            break;
+        case KEY_DEL:
+            backspace();
+            break;
+        case KEY_ENTER:
+            if ( cl < 65536 )
+            {
+                clear_cr();
+                cl++;
+                if ( scl < _h )
+                {
+                    scl++;
+                }
+                if ( !insert_new_line(cl))
+                {
+                    ShowMessage("Out of memory", surface, 200, 100, 200, 60, "Error!");
+                }
+                else
+                {
+                    for ( c = cp ; c < 256 ; c++ )
+                    {
+                        text_edit[cl][c - cp] = text_edit[cl - 1][c];
+                        text_edit[cl - 1][c] = 10;
+                    }
+                    cp = 0;
+                    scp = 0;
+                }
+
+            }
+            else
+            {
+                ShowMessage("Source can't has more then 65536 lines of code!!!", surface, 200, 100, 200, 60, "Error!");
+            }
+            break;
+        case KEY_END:
+            clear_cr();
+            for ( cp = 0 ; cp < 256 && text_edit[cl][cp] != 10 ; cp++ )
+            {
+            }
+            scp = cp;
+            if ( scp >= _w )
+            {
+                scp = _w - 1;
+            }
+            break;
+        case KEY_HOME:
+            clear_cr();
+            cp = 0;
+            scp = 0;
+            break;
+        case KEY_LEFT:
+            if ( cp > 0 )
+            {
+                clear_cr();
+                cp--;
+                if ( scp > 0 )
+                {
+                    scp--;
+                }
+            }
+            else
+            {
+                if ( cl > 0 )
+                {
+                    clear_cr();
+                    for ( c = 0 ; ( c < 256 ) && ( text_edit[cl - 1][c] != 10 ) ; c++ )
+                    {
+                    }
+                    cp = c;
+                    scp = cp;
+                    if ( scp >= _w )
+                    {
+                        scp = _w - 1;
+                    }
+
+                    cl--;
+                    if ( scl > 0 )
+                    {
+                        scl--;
+                    }
+                }
+            }
+            break;
+        case KEY_RIGHT:
+            if ( cp < 256 && text_edit[cl][cp] != 10 )
+            {
+                clear_cr();
+                cp++;
+                if ( scp < _w )
+                {
+                    scp++;
+                }
+            }
+            else
+            {
+                if ( cl + 1 < lines )
+                {
+                    clear_cr();
+                    cp = 0;
+                    scp = cp;
+                    if ( scp >= _w )
+                    {
+                        scp = _w - 1;
+                    }
+                    cl++;
+                    if ( scl < _h )
+                    {
+                        scl++;
+                    }
+                }
+            }
+            break;
+        case KEY_UP:
+            if ( cl > 0 )
+            {
+                clear_cr();
+                cl--;
+                if ( scl > 0 )
+                {
+                    scl--;
+                }
+                for ( c = 0 ; c < 256 && text_edit[cl][c] != 10 ; c++ )
+                {
+                }
+                if ( c - 1 < cp )
+                {
+                    cp = c;
+                    scp = cp;
+                    if ( scp >= _w )
+                    {
+                        scp = _w - 1;
+                    }
+                }
+            }
+            break;
+        case KEY_DOWN:
+            if ( cl < 65536 && cl < ( lines - 1 ))
+            {
+                clear_cr();
+                cl++;
+                if ( scl < _h )
+                {
+                    scl++;
+                }
+                for ( c = 0 ; c < 256 && text_edit[cl][c] != 10 ; c++ )
+                {
+                }
+                if ( c - 1 < cp )
+                {
+                    cp = c;
+                    scp = cp;
+                    if ( scp >= _w )
+                    {
+                        scp = _w - 1;
+                    }
+                }
+            }
+            break;
+        case KEY_ESC:
+            if ( QuestionBox("Are you sure want to EXIT?", screen, 200, 200, 400, 60, "Confirm!", makecol(255, 0, 0)))
+            {
+                exit_ed = true;
+                for ( c = 0 ; c < lines ; c++ )
+                {
+                    if ( text_edit[c] != NULL )
+                    {
+                        delete[] text_edit[c];
+                    }
+                }
+                lines = 0;
+            }
+            else
+            {
+                rest(500);
+                clear_keybuf();
+            }
+            break;
+        case KEY_F3:
+            GetText(filen, screen, 100, 200, 600, 60, 256, " Enter source code file name ");
+            for ( c = 254 ; filen[c] == ' ' || filen[c] == '\r' ; c-- )
+            {
+                filen[c] = 0;
+            }
+            load_source(filen);
+            break;
+        default:
+            if ( key_ch != 0 && cp < 256 )
+            {
+                insert_char(cl, key_ch);
+                clear_cr();
+                cp++;
+                if ( scp < _w )
+                {
+                    scp++;
+                }
+                key_ch = 0;
+            }
+            break;
+        }
+        if ( !exit_ed )
+        {
+            disp();
+            draw_cr();
+        }
+        textprintf(surface, mainf, 1, 1, makecol(255, 255, 255), " p%d l%d sp%d sl%d c%d ln%d", cp, cl, scp, scl,
+                   text_edit[cl][cp], lines);
+
+        blit(surface, screen, 0, 0, 0, 0, surface->w, surface->h);
+
+    }
+
+    blit(cache, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
+    destroy_bitmap(cache);
+    delete[] filen;
+    return;
+}
+
+void code_editor::insert_char(int ln, char ch)
+{
+    int i;
+    for ( i = 256 ; i > cp ; i-- )
+    {
+        text_edit[cl][i] = text_edit[cl][i - 1];
+    }
+    text_edit[cl][cp] = ch;
+}
+
+void code_editor::backspace(void)
+{
+    int i;
+    for ( i = cp ; i < 256 ; i++ )
+    {
+        text_edit[cl][i] = text_edit[cl][i + 1];
+    }
+}
+
+void code_editor::draw_cr(void)
+{
+    hline(surface, left + 8 * scp, top + 10 * scl + 9, left + 8 * scp + 8, makecol(255, 255, 255));
+}
+
+void code_editor::clear_cr(void)
+{
+    hline(surface, left + 8 * scp, top + 10 * scl + 9, left + 8 * scp + 8, 0);
+}
+
+code_editor::code_editor(void)
+{
+    int i;
+    for ( i = 0 ; i < 65536 ; i++ )
+    {
+        text_edit[i] = NULL;
+    }
+    lines = 0;
+    top = 24;
+    left = 11;
+    cl = 0;
+    cp = 0;
+    scl = 0;
+    scp = 0;
+    surface = create_bitmap(SCREEN_W, SCREEN_H - 100);
+    _w = ( surface->w - left * 2 ) / 8 - 1;
+    _h = ( surface->h - top - left ) / 10 - 1;
+    tab_size = 8;
+}
+
+code_editor::~code_editor(void)
+{
+}
+
+bool code_editor::alloc_new_line(void)
+{
+    int i;
+    if ( lines < 65536 )
+    {
+        text_edit[lines] = new char[256];
+        for ( i = 0 ; i < 256 ; i++ )
+        {
+            text_edit[lines][i] = 10;
+        }
+        lines++;
+        return text_edit[lines] == NULL ? false : true;
+    }
+    return false;
+}
+
+bool code_editor::insert_new_line(int ln)
+{
+    int i;
+    if ( lines < 65536 )
+    {
+        for ( i = lines ; i > ln ; i-- )
+        {
+            text_edit[i] = text_edit[i - 1];
+        }
+        text_edit[ln] = NULL;
+        text_edit[ln] = new char[256];
+        for ( i = 0 ; i < 256 ; i++ )
+        {
+            text_edit[ln][i] = 10;
+        }
+        lines++;
+        if ( text_edit[ln] == NULL )
+        {
+            for ( i = ln ; i < lines ; i++ )
+            {
+                text_edit[i] = text_edit[i + 1];
+            }
+            lines--;
+            return false;
+        }
+        else
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
+void code_editor::delete_last(void)
+{
+    lines--;
+    delete[] text_edit[lines];
+    text_edit[lines] = NULL;
+}
+
+void code_editor::cut_line(int ln)
+{
+    int i;
+    if ( text_edit[ln] != NULL )
+    {
+        for ( i = ln ; i < lines ; i++ )
+        {
+            text_edit[i] = text_edit[i + 1];
+        }
+        lines--;
+    }
+}

+ 106 - 0
dis_asm.cpp

@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Emu51
+ * dis_asm.cpp:
+ * Created by mlt on 22/03/23.
+ ******************************************************************************/
+
+#include <emu51.h>
+#include <code_51.h>
+#include <dis_asm.h>
+
+dis_asm::dis_asm(uint8_t *tmpB, BITMAP *tmp_buf)
+{
+    frame = 2;
+    left = 12;
+    changed = true;
+    ram = tmpB;
+    buf = tmp_buf;
+    surface = create_bitmap(300, 500);
+    clear(surface);
+}
+
+void dis_asm::hexoutB(int x, int y, int color, uint8_t numb)
+{
+    if ( numb > 0x10 )
+    {
+        textprintf(surface, mainf, x, y, color, "%2x", numb);
+    }
+    else
+    {
+        textprintf(surface, mainf, x, y, color, "%2x", numb);
+        textprintf(surface, mainf, x, y, color, "0");
+    }
+}
+
+void dis_asm::draw(uint16_t adress)
+{
+    int red = makecol(255, 0, 0);
+    int white = makecol(255, 255, 255);
+    int lblue = makecol(0, 128, 255);
+    int color = white;
+    int colPC = white;
+    int c, cnt;
+    clear(surface);
+    for ( c = 20 ; c < surface->h - 10 ; c += 10 )
+    {
+        if ( PC == adress )
+        {
+            color = red;
+        }
+        else
+        {
+            color = white;
+        }
+        asm51[ram[adress]].make_ds(adress);
+        if ( asm51[ram[adress]].code == ram[adress] )
+        {
+            textprintf(surface, mainf, left, c, color, "%4x:", adress);
+            for ( cnt = 0 ; cnt < asm51[ram[adress]].lenght ; cnt++ )
+            {
+                if ( PC == ( adress + cnt ))
+                {
+                    colPC = lblue;
+                }
+                else
+                {
+                    colPC = color;
+                }
+                hexoutB(left + 50 + cnt * 24, c, colPC, ram[adress + cnt]);
+            }
+            textprintf(surface, mainf, left + 144, c, color, "%s", asm51[ram[adress]].display_string);
+            adress += asm51[ram[adress]].lenght;
+        }
+        else
+        {
+            textprintf(surface, mainf, left, c, color, "%4x: ", adress);
+            if ( PC == adress )
+            {
+                colPC = lblue;
+            }
+            else
+            {
+                colPC = color;
+            }
+            hexoutB(left + 50, c, colPC, ram[adress]);
+            textprintf(surface, mainf, left + 144, c, color, "???");
+            adress++;
+        }
+    }
+    hline(surface, frame, surface->h - frame, surface->w - frame, white);
+    vline(surface, frame, frame, surface->h - frame, white);
+    vline(surface, surface->w - frame, frame, surface->h - frame, white);
+    for ( c = frame ; c <= frame + 10 ; c += 2 )
+    {
+        hline(surface, frame, c, surface->w - frame, white);
+    }
+    textprintf_centre(surface, mainf, surface->w / 2, frame + 2, white, " Disassembler ");
+}
+
+void dis_asm::blit_it(int x, int y)
+{
+    blit(surface, buf, 0, 0, x, y, surface->w, surface->h);
+}
+
+dis_asm::~dis_asm(void)
+{
+}

File diff suppressed because it is too large
+ 59 - 2353
emu51.cpp


+ 0 - 250
emu51.h

@@ -1,250 +0,0 @@
-#define bit0 0x01
-#define bit1 0x02
-#define bit2 0x04
-#define bit3 0x08
-#define bit4 0x10
-#define bit5 0x20
-#define bit6 0x40
-#define bit7 0x80
-
-typedef unsigned char BYTE;
-typedef unsigned short int WORD;
-
-BYTE SFR[0x100];                   // internal memory and sfr area 256 bytes
-BYTE EXT_RAM[0x10000];             // external memory 64kB
-BYTE *Acc = &SFR[0xe0];            // 8-bit accumlator
-WORD *DPTR = (WORD *) &SFR[0x82];  // 16-bit register
-BYTE *DPH = &SFR[0x83];            // high byte of DPTR
-BYTE *DPL = &SFR[0x82];            // low byte of DPTR
-BYTE *B = &SFR[0xf0];              // B register
-BYTE *SP = &SFR[0x81];             // Stack Pointer
-BYTE *PSW = &SFR[0xd0];            // Program Status Word
-BYTE *P0 = &SFR[0x80];             // Port one
-BYTE *P1 = &SFR[0x90];             //
-BYTE *P2 = &SFR[0xa0];             //
-BYTE *P3 = &SFR[0xb0];             //
-BYTE *SBUF = &SFR[0x99];           //
-BYTE *IE = &SFR[0xa8];             //
-BYTE *SCON = &SFR[0x98];           //
-BYTE *TH1 = &SFR[0x8d];            //
-BYTE *TH0 = &SFR[0x8c];            //
-BYTE *TL1 = &SFR[0x8b];            //
-BYTE *TL0 = &SFR[0x8a];            //
-BYTE *TMOD = &SFR[0x89];           //
-BYTE *TCON = &SFR[0x88];           //
-BYTE *PCON = &SFR[0x87];           //
-BYTE *R = &SFR[0x00];              //
-WORD PC = 0x0000;                  //
-
-// initialize emulator
-void init_8051(void)
-{
-    *Acc = 0;
-    *DPTR = 0;
-    *P1 = 0xff;
-    PC = 0x0000;
-    *SP = 0x07;
-}
-
-BYTE check_C(void)
-{
-    if ( *PSW & bit7 )
-    {
-        return 1;
-    }
-    else
-    {
-        return 0;
-    }
-}
-
-BYTE check_AC(void)
-{
-    if ( *PSW & bit6 )
-    {
-        return 1;
-    }
-    else
-    {
-        return 0;
-    }
-}
-
-BYTE check_OV(void)
-{
-    if ( *PSW & bit2 )
-    {
-        return 1;
-    }
-    else
-    {
-        return 0;
-    }
-}
-
-void set_C(void)
-{
-    *PSW = *PSW | bit7;
-}
-
-void set_AC(void)
-{
-    *PSW = *PSW | bit6;
-}
-
-void set_OV(void)
-{
-    *PSW = *PSW | bit2;
-}
-
-void clr_C(void)
-{
-    *PSW = *PSW & 0x7f;
-}
-
-void clr_AC(void)
-{
-    *PSW = *PSW & 0xbf;
-}
-
-void clr_OV(void)
-{
-    *PSW = *PSW & 0xfb;
-}
-
-BYTE check_P(void)
-{
-    if ( *PSW & bit0 )
-    {
-        return 1;
-    }
-    else
-    {
-        return 0;
-    }
-}
-
-void set_P(void)
-{
-    *PSW = *PSW | bit0;
-}
-
-void clr_P(void)
-{
-    *PSW = *PSW & 0xfe;
-}
-
-void setB(BYTE bit)
-{
-    BYTE tmpB;
-    BYTE tmpbit;
-    tmpbit = bit & 0xf8;
-    tmpB = bit & 0x07;
-    if ( bit >= 128 )
-    {
-        // bit set in SFR area
-        SFR[tmpB] = SFR[tmpB] | ( 1 << tmpbit );
-    }
-    else
-    {
-        // bit set in int. RAM
-        tmpB = ( tmpB >> 3 ) + 32;
-        SFR[tmpB] = SFR[tmpB] | ( 1 << tmpbit );
-    }
-}
-
-void clrB(BYTE bit)
-{
-    BYTE tmpB;
-    BYTE tmpbit;
-    tmpbit = bit & 0xf8;
-    tmpB = bit & 0x07;
-    if ( bit >= 128 )
-    {
-        // bit clear in SFR area
-        SFR[tmpB] = SFR[tmpB] & ~( 1 << tmpbit );
-    }
-    else
-    {
-        // bit clear in int. RAM
-        tmpB = ( tmpB >> 3 ) + 32;
-        SFR[tmpB] = SFR[tmpB] & ~( 1 << tmpbit );
-    }
-}
-
-BYTE checkB(BYTE bit)
-{
-    BYTE tmpB;
-    BYTE tmpbit;
-    tmpbit = bit & 0xf8;
-    tmpB = bit & 0x07;
-    if ( bit >= 128 )
-    {
-        // bit chack in SFR area
-        if ( SFR[tmpB] & ~( 1 << tmpbit ))
-        {
-            return 1;
-        }
-        else
-        {
-            return 0;
-        }
-    }
-    else
-    {
-        // bit check in int. RAM
-        tmpB = ( tmpB >> 3 ) + 32;
-        if ( SFR[tmpB] & ~( 1 << tmpbit ))
-        {
-            return true;
-        }
-        else
-        {
-            return false;
-        }
-    }
-}
-
-BYTE check_RS0(void)
-{
-    if ( *PSW & bit3 )
-    {
-        return 1;
-    }
-    else
-    {
-        return 0;
-    }
-}
-
-void set_RS0(void)
-{
-    *PSW = *PSW | bit3;
-}
-
-void clr_RS0(void)
-{
-    *PSW = *PSW & 0xf7;
-}
-
-BYTE check_RS1(void)
-{
-    if ( *PSW & bit4 )
-    {
-        return 1;
-    }
-    else
-    {
-        return 0;
-    }
-}
-
-void set_RS1(void)
-{
-    *PSW = *PSW | bit4;
-}
-
-void clr_RS1(void)
-{
-    *PSW = *PSW & 0xef;
-}

+ 168 - 0
external/cmake/GetGitRevisionDescription.cmake

@@ -0,0 +1,168 @@
+# - Returns a version string from Git
+#
+# These functions force a re-configure on each git commit so that you can
+# trust the values of the variables in your build system.
+#
+#  get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
+#
+# Returns the refspec and sha hash of the current head revision
+#
+#  git_describe(<var> [<additional arguments to git describe> ...])
+#
+# Returns the results of git describe on the source tree, and adjusting
+# the output so that it tests false if an error occurs.
+#
+#  git_get_exact_tag(<var> [<additional arguments to git describe> ...])
+#
+# Returns the results of git describe --exact-match on the source tree,
+# and adjusting the output so that it tests false if there was no exact
+# matching tag.
+#
+#  git_local_changes(<var>)
+#
+# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
+# Uses the return code of "git diff-index --quiet HEAD --".
+# Does not regard untracked files.
+#
+# Requires CMake 2.6 or newer (uses the 'function' command)
+#
+# Original Author:
+# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
+# http://academic.cleardefinition.com
+# Iowa State University HCI Graduate Program/VRAC
+#
+# Copyright Iowa State University 2009-2010.
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+if(__get_git_revision_description)
+    return()
+endif()
+set(__get_git_revision_description YES)
+
+# We must run the following at "include" time, not at function call time,
+# to find the path to this module rather than the path to a calling list file
+get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
+
+function(get_git_head_revision _refspecvar _hashvar)
+    set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+    set(GIT_DIR "${GIT_PARENT_DIR}/.git")
+    while(NOT EXISTS "${GIT_DIR}")	# .git dir not found, search parent directories
+        set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
+        get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
+        if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
+            # We have reached the root directory, we are not in git
+            set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
+            set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
+            return()
+        endif()
+        set(GIT_DIR "${GIT_PARENT_DIR}/.git")
+    endwhile()
+    # check if this is a submodule
+    if(NOT IS_DIRECTORY ${GIT_DIR})
+        file(READ ${GIT_DIR} submodule)
+        string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
+        get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
+        get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
+    endif()
+    set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
+    if(NOT EXISTS "${GIT_DATA}")
+        file(MAKE_DIRECTORY "${GIT_DATA}")
+    endif()
+
+    if(NOT EXISTS "${GIT_DIR}/HEAD")
+        return()
+    endif()
+    set(HEAD_FILE "${GIT_DATA}/HEAD")
+    configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
+
+    configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
+            "${GIT_DATA}/grabRef.cmake"
+            @ONLY)
+    include("${GIT_DATA}/grabRef.cmake")
+
+    set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
+    set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
+endfunction()
+
+function(git_describe _var)
+    if(NOT GIT_FOUND)
+        find_package(Git QUIET)
+    endif()
+    get_git_head_revision(refspec hash)
+    if(NOT GIT_FOUND)
+        set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
+        return()
+    endif()
+    if(NOT hash)
+        set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
+        return()
+    endif()
+
+    # TODO sanitize
+    #if((${ARGN}" MATCHES "&&") OR
+    #	(ARGN MATCHES "||") OR
+    #	(ARGN MATCHES "\\;"))
+    #	message("Please report the following error to the project!")
+    #	message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
+    #endif()
+
+    #message(STATUS "Arguments to execute_process: ${ARGN}")
+
+    execute_process(COMMAND
+            "${GIT_EXECUTABLE}"
+            describe
+            #${hash}
+            ${ARGN}
+            WORKING_DIRECTORY
+            "${CMAKE_CURRENT_SOURCE_DIR}"
+            RESULT_VARIABLE
+            res
+            OUTPUT_VARIABLE
+            out
+            ERROR_QUIET
+            OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if(NOT res EQUAL 0)
+        set(out "${out}-${res}-NOTFOUND")
+    endif()
+
+    set(${_var} "${out}" PARENT_SCOPE)
+endfunction()
+
+function(git_get_exact_tag _var)
+    git_describe(out --exact-match ${ARGN})
+    set(${_var} "${out}" PARENT_SCOPE)
+endfunction()
+
+function(git_local_changes _var)
+    if(NOT GIT_FOUND)
+        find_package(Git QUIET)
+    endif()
+    get_git_head_revision(refspec hash)
+    if(NOT GIT_FOUND)
+        set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
+        return()
+    endif()
+    if(NOT hash)
+        set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
+        return()
+    endif()
+
+    execute_process(COMMAND
+            "${GIT_EXECUTABLE}"
+            diff-index --quiet HEAD --
+            WORKING_DIRECTORY
+            "${CMAKE_CURRENT_SOURCE_DIR}"
+            RESULT_VARIABLE
+            res
+            OUTPUT_VARIABLE
+            out
+            ERROR_QUIET
+            OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if(res EQUAL 0)
+        set(${_var} "CLEAN" PARENT_SCOPE)
+    else()
+        set(${_var} "DIRTY" PARENT_SCOPE)
+    endif()
+endfunction()

+ 41 - 0
external/cmake/GetGitRevisionDescription.cmake.in

@@ -0,0 +1,41 @@
+#
+# Internal file for GetGitRevisionDescription.cmake
+#
+# Requires CMake 2.6 or newer (uses the 'function' command)
+#
+# Original Author:
+# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
+# http://academic.cleardefinition.com
+# Iowa State University HCI Graduate Program/VRAC
+#
+# Copyright Iowa State University 2009-2010.
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+set(HEAD_HASH)
+
+file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
+
+string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
+if(HEAD_CONTENTS MATCHES "ref")
+	# named branch
+	string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
+	if(EXISTS "@GIT_DIR@/${HEAD_REF}")
+		configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
+	else()
+		configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
+		file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
+		if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
+			set(HEAD_HASH "${CMAKE_MATCH_1}")
+		endif()
+	endif()
+else()
+	# detached HEAD
+	configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
+endif()
+
+if(NOT HEAD_HASH)
+	file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
+	string(STRIP "${HEAD_HASH}" HEAD_HASH)
+endif()

+ 63 - 0
flags.cpp

@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Emu51
+ * flags.cpp:
+ * Created by mlt on 22/03/23.
+ ******************************************************************************/
+
+#include <emu51.h>
+#include <flags.h>
+#include <code_51.h>
+
+flags::flags(BITMAP *tmp_buf)
+{
+    buf = tmp_buf;
+    surface = create_bitmap(100, 300);
+    frame = 2;
+    left = 12;
+    changed = false;
+}
+
+flags::~flags()
+{
+}
+
+void flags::draw()
+{
+    int red = makecol(255, 0, 0);
+    int white = makecol(255, 255, 255);
+    int lblue = makecol(0, 128, 255);
+    clear(surface);
+    textprintf(surface, mainf, left, frame + 20, white, "C  : %d", check_C());
+    textprintf(surface, mainf, left, frame + 30, white, "AC : %d", check_AC());
+    textprintf(surface, mainf, left, frame + 40, white, "OV : %d", check_OV());
+    textprintf(surface, mainf, left, frame + 50, white, "P  : %d", check_P());
+    textprintf(surface, mainf, left, frame + 60, red, "PC : %4x", PC);
+    textprintf(surface, mainf, left, frame + 70, lblue, "SP : %2x", *SP);
+    textprintf(surface, mainf, left, frame + 80, lblue, "Acc: %2x", *Acc);
+    textprintf(surface, mainf, left, frame + 90, lblue, "B  : %2x", *B);
+    textprintf(surface, mainf, left, frame + 100, lblue, "R0 : %2x", R[0]);
+    textprintf(surface, mainf, left, frame + 110, lblue, "R1 : %2x", R[1]);
+    textprintf(surface, mainf, left, frame + 120, lblue, "R2 : %2x", R[2]);
+    textprintf(surface, mainf, left, frame + 130, lblue, "R3 : %2x", R[3]);
+    textprintf(surface, mainf, left, frame + 140, lblue, "R4 : %2x", R[4]);
+    textprintf(surface, mainf, left, frame + 150, lblue, "R5 : %2x", R[5]);
+    textprintf(surface, mainf, left, frame + 160, lblue, "R6 : %2x", R[6]);
+    textprintf(surface, mainf, left, frame + 170, lblue, "R7 : %2x", R[7]);
+    textprintf(surface, mainf, left, frame + 180, lblue, "DPTR: %4x", *DPTR);
+    textprintf(surface, mainf, left, frame + 270, red, "cycles :");
+    textprintf(surface, mainf, left, frame + 280, red, "%lld", c_time);
+
+    hline(surface, frame, surface->h - frame, surface->w - frame, white);
+    vline(surface, frame, frame, surface->h - frame, white);
+    vline(surface, surface->w - frame, frame, surface->h - frame, white);
+    for ( int c = frame ; c <= frame + 10 ; c += 2 )
+    {
+        hline(surface, frame, c, surface->w - frame, white);
+    }
+    textprintf_centre(surface, mainf, surface->w / 2, frame + 2, white, " RegFlag ");
+}
+
+void flags::blit_it(int x, int y)
+{
+    blit(surface, buf, 0, 0, x, y, surface->w, surface->h);
+}

+ 400 - 0
gui.cpp

@@ -0,0 +1,400 @@
+/*******************************************************************************
+ * Emu51
+ * gui.cpp:
+ * Created by mlt on 22/03/23.
+ ******************************************************************************/
+
+#include <allegro.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <emu51.h>
+#include <gui.h>
+
+// Returns state of a single bit which is on 'pos' position in tmp_b byte
+bool checkBit(uint8_t tmp_b, int pos)
+{
+    if ( tmp_b & ( 1 << pos ))
+    {
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+}
+
+void draw_SEG_digit(BITMAP *buf, int x, int y, int color, int size, uint8_t segm_code)
+{
+    int darkc, normc;
+    normc = color;
+    darkc = makecol(getr(normc) / 4, getg(normc) / 4, getb(normc) / 4);
+
+    if ( checkBit(segm_code, 1))
+    {
+        color = normc;
+    }
+    else
+    {
+        color = darkc;
+    }
+    vline(buf, x + size, y, y + size, color);
+
+    if ( checkBit(segm_code, 2))
+    {
+        color = normc;
+    }
+    else
+    {
+        color = darkc;
+    }
+    vline(buf, x + size, y + size, y + 2 * size, color);
+
+    if ( checkBit(segm_code, 4))
+    {
+        color = normc;
+    }
+    else
+    {
+        color = darkc;
+    }
+    vline(buf, x, y + 2 * size, y + size, color);
+
+    if ( checkBit(segm_code, 5))
+    {
+        color = normc;
+    }
+    else
+    {
+        color = darkc;
+    }
+    vline(buf, x, y + size, y, color);
+
+    if ( checkBit(segm_code, 6))
+    {
+        color = normc;
+    }
+    else
+    {
+        color = darkc;
+    }
+    hline(buf, x, y + size, x + size, color);
+
+    if ( checkBit(segm_code, 0))
+    {
+        color = normc;
+    }
+    else
+    {
+        color = darkc;
+    }
+    hline(buf, x, y, x + size, color);
+
+    if ( checkBit(segm_code, 3))
+    {
+        color = normc;
+    }
+    else
+    {
+        color = darkc;
+    }
+    hline(buf, x + size, y + 2 * size, x, color);
+
+    if ( checkBit(segm_code, 7))
+    {
+        color = normc;
+    }
+    else
+    {
+        color = darkc;
+    }
+    putpixel(buf, x + size + 2, y + 2 * size, color);
+}
+
+void draw_LED_bin(BITMAP *buf, int x, int y, int color, uint8_t code)
+{
+    int darkc, normc;
+    int i;
+    normc = color;
+    darkc = makecol(getr(normc) / 4, getg(normc) / 4, getb(normc) / 4);
+    for ( i = 0 ; i < 8 ; i++ )
+    {
+        if ( checkBit(code, 7 - i))
+        {
+            color = normc;
+        }
+        else
+        {
+            color = darkc;
+        }
+        circlefill(buf, x + 7 * i, y, 2, color);
+    }
+}
+
+void change_char(char *string, char ch, int pos)
+{
+    string[pos - 1] = ch;
+}
+
+void insert_char(char *string, char ch, int pos, int lenght)
+{
+    for ( int c = lenght ; c > pos ; c-- )
+    {
+        string[c - 1] = string[c - 2];
+    }
+    string[pos - 1] = ch;
+}
+
+void cut_char(char *string, int pos, int lenght)
+{
+    for ( int c = pos ; c < lenght ; c++ )
+    {
+        string[c - 1] = string[c];
+    }
+    string[lenght - 1] = (char) ( 32 );
+}
+
+void change_ext(char *s)
+{
+    int c;
+    for ( c = 254 ; c >= 0 ; c-- )
+    {
+        if ( s[c] == '.' )
+        {
+            s[c + 1] = 'h';
+            s[c + 2] = 'e';
+            s[c + 3] = 'x';
+            break;
+        }
+    }
+    return;
+}
+
+void GetText(char *text, BITMAP *buf, int x, int y, int w, int h, int lenght, char *title)
+{
+    int c;
+    BITMAP *surface = create_bitmap(w, h);
+    BITMAP *cache = create_bitmap(w, h);
+    blit(buf, cache, x, y, 0, 0, w, h);
+    clear(surface);
+    hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
+    vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
+    vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
+
+    for ( c = 2 ; c <= 2 + 10 ; c += 2 )
+    {
+        hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
+    }
+    textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " %s ", title);
+    text[0] = 32;
+
+    for ( c = 1 ; c <= lenght - 1 ; c++ )
+    {
+        text[c] = 32;
+    }
+    text[lenght - 1] = 0;
+    clear_keybuf();
+    int pos = 1;
+    uint16_t key_p;
+    uint16_t key_ch;
+    bool flag;
+
+    while ( key[KEY_ENTER] )
+    {
+    }
+
+    while ( !key[KEY_ENTER] )
+    {
+        textprintf(surface, mainf, 15, surface->h / 2, makecol(255, 255, 255), "%s", text);
+        hline(surface, 15 + ( pos - 1 ) * 8, surface->h / 2 + 8, 15 + pos * 8, makecol(255, 255, 255));
+        blit(surface, buf, 0, 0, x, y, w, h);
+        hline(surface, 15 + ( pos - 1 ) * 8, surface->h / 2 + 8, 15 + pos * 8, makecol(0, 0, 0));
+        key_p = readkey();
+        key_ch = key_p & 0xff;
+        key_p = key_p >> 8;
+        flag = false;
+        switch ( key_p )
+        {
+        case KEY_BACKSPACE:
+            if ( pos > 1 )
+            {
+                pos--;
+                cut_char(text, pos, lenght);
+                text[lenght - 2] = 32;
+                text[lenght - 1] = 0;
+            }
+            flag = true;
+            break;
+        case KEY_DEL:
+            cut_char(text, pos, lenght);
+            text[lenght - 2] = 32;
+            text[lenght - 1] = 0;
+            flag = true;
+            break;
+        case KEY_LEFT:
+            if ( pos > 1 )
+            { pos--; }
+            flag = true;
+            break;
+        case KEY_RIGHT:
+            if ( pos < lenght )
+            { pos++; }
+            flag = true;
+            break;
+        }
+        if ( !key[KEY_ENTER] && key_ch != 0 && pos < lenght && !flag )
+        {
+            insert_char(text, key_ch, pos, lenght);
+            pos++;
+            text[lenght - 1] = 0;
+        }
+    }
+
+    text[lenght - 1] = 0;
+    blit(cache, buf, 0, 0, x, y, w, h);
+    destroy_bitmap(cache);
+    destroy_bitmap(surface);
+}
+
+void ShowMessage(char *text, BITMAP *buf, int x, int y, int w, int h, char *title)
+{
+    BITMAP *surface = create_bitmap(w, h);
+    BITMAP *cache = create_bitmap(w, h);
+    blit(buf, cache, x, y, 0, 0, w, h);
+    clear(surface);
+    hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
+    vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
+    vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
+    for ( int c = 2 ; c <= 2 + 10 ; c += 2 )
+    {
+        hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
+    }
+    textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " %s ", title);
+    textprintf(surface, mainf, 15, surface->h / 2, makecol(255, 255, 255), "%s", text);
+    textprintf_centre(surface, mainf, surface->w / 2, surface->h - 16, makecol(255, 0, 0), "Press ENTER");
+    blit(surface, buf, 0, 0, x, y, w, h);
+
+    while ( key[KEY_ENTER] )
+    {
+    }
+
+    while ( !key[KEY_ENTER] )
+    {
+    }
+
+    blit(cache, buf, 0, 0, x, y, w, h);
+    destroy_bitmap(cache);
+    destroy_bitmap(surface);
+}
+
+bool QuestionBox(char *text, BITMAP *buf, int x, int y, int w, int h, char *title, int _color)
+{
+    BITMAP *surface = create_bitmap(w, h);
+    BITMAP *cache = create_bitmap(w, h);
+    int len, c, line = 0, pos = 0;
+    blit(buf, cache, x, y, 0, 0, w, h);
+    clear(surface);
+    hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
+    vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
+    vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
+    for ( c = 2 ; c <= 2 + 10 ; c += 2 )
+    {
+        hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
+    }
+    textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " %s ", title);
+    textprintf_centre(surface, mainf, surface->w / 2, surface->h - 16, makecol(255, 0, 0),
+                      "Press ENTER (OK)  or  ESC (Cancel)");
+    len = (int) strlen(text);
+    for ( c = 0 ; c < len ; c++ )
+    {
+        if ( text[c] == 10 )
+        {
+            line++;
+            pos = 0;
+        }
+        else
+        {
+            if ( text[c] != 13 )
+            {
+                if ( text[c] > 126 || text[c] < 32 )
+                { break; }
+                textprintf(surface, mainf, 15 + pos * 8, 20 + line * 10, _color, "%c", text[c]);
+                pos++;
+            }
+        }
+    }
+    blit(surface, buf, 0, 0, x, y, w, h);
+
+    while ( key[KEY_ENTER] || key[KEY_ESC] )
+    {
+    }
+
+    while ( !( key[KEY_ENTER] || key[KEY_ESC] ))
+    {
+    }
+
+    if ( key[KEY_ENTER] )
+    {
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+
+    blit(cache, buf, 0, 0, x, y, w, h);
+    destroy_bitmap(cache);
+    destroy_bitmap(surface);
+}
+
+void ShowMsgEx(char *text, BITMAP *buf, int x, int y, int w, int h, char *title, int _color)
+{
+    BITMAP *surface = create_bitmap(w, h);
+    BITMAP *cache = create_bitmap(w, h);
+    int len, c, line = 0, pos = 0;
+    blit(buf, cache, x, y, 0, 0, w, h);
+    clear(surface);
+    hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
+    vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
+    vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
+
+    for ( c = 2 ; c <= 2 + 10 ; c += 2 )
+    {
+        hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
+    }
+    textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " %s ", title);
+    textprintf_centre(surface, mainf, surface->w / 2, surface->h - 16, makecol(255, 0, 0), "Press ENTER");
+    len = (int) strlen(text);
+
+    for ( c = 0 ; c < len ; c++ )
+    {
+        if ( text[c] == 10 )
+        {
+            line++;
+            pos = 0;
+        }
+        else
+        {
+            if ( text[c] != 13 )
+            {
+                if ( text[c] > 126 || text[c] < 32 )
+                { break; }
+                textprintf(surface, mainf, 15 + pos * 8, 20 + line * 10, _color, "%c", text[c]);
+                pos++;
+            }
+        }
+    }
+    blit(surface, buf, 0, 0, x, y, w, h);
+
+    while ( key[KEY_ENTER] )
+    {
+    }
+
+    while ( !key[KEY_ENTER] )
+    {
+    }
+
+    blit(cache, buf, 0, 0, x, y, w, h);
+    destroy_bitmap(cache);
+    destroy_bitmap(surface);
+}

+ 0 - 905
gui.h

@@ -1,905 +0,0 @@
-#ifndef __MARIO_GUI
-#define __MARIO_GUI
-
-#include <allegro.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-// Returns state of a single bit which is on 'pos' position in tmp_b byte
-bool checkBit(BYTE tmp_b, int pos)
-{
-    if ( tmp_b & ( 1 << pos ))
-    {
-        return true;
-    }
-    else
-    {
-        return false;
-    }
-}
-
-void draw_SEG_digit(BITMAP *buf, int x, int y, int color, int size, BYTE segm_code)
-{
-    int darkc, normc;
-    normc = color;
-    darkc = makecol(getr(normc) / 4, getg(normc) / 4, getb(normc) / 4);
-
-    if ( checkBit(segm_code, 1))
-    {
-        color = normc;
-    }
-    else
-    {
-        color = darkc;
-    }
-    vline(buf, x + size, y, y + size, color);
-
-    if ( checkBit(segm_code, 2))
-    {
-        color = normc;
-    }
-    else
-    {
-        color = darkc;
-    }
-    vline(buf, x + size, y + size, y + 2 * size, color);
-
-    if ( checkBit(segm_code, 4))
-    {
-        color = normc;
-    }
-    else
-    {
-        color = darkc;
-    }
-    vline(buf, x, y + 2 * size, y + size, color);
-
-    if ( checkBit(segm_code, 5))
-    {
-        color = normc;
-    }
-    else
-    {
-        color = darkc;
-    }
-    vline(buf, x, y + size, y, color);
-
-    if ( checkBit(segm_code, 6))
-    {
-        color = normc;
-    }
-    else
-    {
-        color = darkc;
-    }
-    hline(buf, x, y + size, x + size, color);
-
-    if ( checkBit(segm_code, 0))
-    {
-        color = normc;
-    }
-    else
-    {
-        color = darkc;
-    }
-    hline(buf, x, y, x + size, color);
-
-    if ( checkBit(segm_code, 3))
-    {
-        color = normc;
-    }
-    else
-    {
-        color = darkc;
-    }
-    hline(buf, x + size, y + 2 * size, x, color);
-
-    if ( checkBit(segm_code, 7))
-    {
-        color = normc;
-    }
-    else
-    {
-        color = darkc;
-    }
-    putpixel(buf, x + size + 2, y + 2 * size, color);
-}
-
-void draw_LED_bin(BITMAP *buf, int x, int y, int color, BYTE code)
-{
-    int darkc, normc;
-    int i;
-    normc = color;
-    darkc = makecol(getr(normc) / 4, getg(normc) / 4, getb(normc) / 4);
-    for ( i = 0 ; i < 8 ; i++ )
-    {
-        if ( checkBit(code, 7 - i))
-        {
-            color = normc;
-        }
-        else
-        {
-            color = darkc;
-        }
-        circlefill(buf, x + 7 * i, y, 2, color);
-    }
-}
-
-void change_char(char *string, char ch, int pos)
-{
-    string[pos - 1] = ch;
-}
-
-void insert_char(char *string, char ch, int pos, int lenght)
-{
-    for ( int c = lenght ; c > pos ; c-- )
-    {
-        string[c - 1] = string[c - 2];
-    }
-    string[pos - 1] = ch;
-}
-
-void cut_char(char *string, int pos, int lenght)
-{
-    for ( int c = pos ; c < lenght ; c++ )
-    {
-        string[c - 1] = string[c];
-    }
-    string[lenght - 1] = (char) ( 32 );
-}
-
-void change_ext(char *s)
-{
-    int c;
-    for ( c = 254 ; c >= 0 ; c-- )
-    {
-        if ( s[c] == '.' )
-        {
-            s[c + 1] = 'h';
-            s[c + 2] = 'e';
-            s[c + 3] = 'x';
-            break;
-        }
-    }
-    return;
-}
-
-void GetText(char *text, BITMAP *buf, int x, int y, int w, int h, int lenght, char *title)
-{
-    int c;
-    BITMAP *surface = create_bitmap(w, h);
-    BITMAP *cache = create_bitmap(w, h);
-    blit(buf, cache, x, y, 0, 0, w, h);
-    clear(surface);
-    hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
-    vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
-    vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
-
-    for ( c = 2 ; c <= 2 + 10 ; c += 2 )
-    {
-        hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
-    }
-    textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " %s ", title);
-    text[0] = 32;
-
-    for ( c = 1 ; c <= lenght - 1 ; c++ )
-    {
-        text[c] = 32;
-    }
-    text[lenght - 1] = 0;
-    clear_keybuf();
-    int pos = 1;
-    WORD key_p;
-    WORD key_ch;
-    bool flag;
-
-    while ( key[KEY_ENTER] )
-    {
-    }
-
-    while ( !key[KEY_ENTER] )
-    {
-        textprintf(surface, mainf, 15, surface->h / 2, makecol(255, 255, 255), "%s", text);
-        hline(surface, 15 + ( pos - 1 ) * 8, surface->h / 2 + 8, 15 + pos * 8, makecol(255, 255, 255));
-        blit(surface, buf, 0, 0, x, y, w, h);
-        hline(surface, 15 + ( pos - 1 ) * 8, surface->h / 2 + 8, 15 + pos * 8, makecol(0, 0, 0));
-        key_p = readkey();
-        key_ch = key_p & 0xff;
-        key_p = key_p >> 8;
-        flag = false;
-        switch ( key_p )
-        {
-        case KEY_BACKSPACE:
-            if ( pos > 1 )
-            {
-                pos--;
-                cut_char(text, pos, lenght);
-                text[lenght - 2] = 32;
-                text[lenght - 1] = 0;
-            }
-            flag = true;
-            break;
-        case KEY_DEL:
-            cut_char(text, pos, lenght);
-            text[lenght - 2] = 32;
-            text[lenght - 1] = 0;
-            flag = true;
-            break;
-        case KEY_LEFT:
-            if ( pos > 1 )
-            { pos--; }
-            flag = true;
-            break;
-        case KEY_RIGHT:
-            if ( pos < lenght )
-            { pos++; }
-            flag = true;
-            break;
-        }
-        if ( !key[KEY_ENTER] && key_ch != 0 && pos < lenght && !flag )
-        {
-            insert_char(text, key_ch, pos, lenght);
-            pos++;
-            text[lenght - 1] = 0;
-        }
-    }
-
-    text[lenght - 1] = 0;
-    blit(cache, buf, 0, 0, x, y, w, h);
-    destroy_bitmap(cache);
-    destroy_bitmap(surface);
-}
-
-void ShowMessage(char *text, BITMAP *buf, int x, int y, int w, int h, char *title)
-{
-    BITMAP *surface = create_bitmap(w, h);
-    BITMAP *cache = create_bitmap(w, h);
-    blit(buf, cache, x, y, 0, 0, w, h);
-    clear(surface);
-    hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
-    vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
-    vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
-    for ( int c = 2 ; c <= 2 + 10 ; c += 2 )
-    {
-        hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
-    }
-    textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " %s ", title);
-    textprintf(surface, mainf, 15, surface->h / 2, makecol(255, 255, 255), "%s", text);
-    textprintf_centre(surface, mainf, surface->w / 2, surface->h - 16, makecol(255, 0, 0), "Press ENTER");
-    blit(surface, buf, 0, 0, x, y, w, h);
-
-    while ( key[KEY_ENTER] )
-    {
-    }
-
-    while ( !key[KEY_ENTER] )
-    {
-    }
-
-    blit(cache, buf, 0, 0, x, y, w, h);
-    destroy_bitmap(cache);
-    destroy_bitmap(surface);
-}
-
-bool QuestionBox(char *text, BITMAP *buf, int x, int y, int w, int h, char *title, int _color)
-{
-    BITMAP *surface = create_bitmap(w, h);
-    BITMAP *cache = create_bitmap(w, h);
-    int len, c, line = 0, pos = 0;
-    blit(buf, cache, x, y, 0, 0, w, h);
-    clear(surface);
-    hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
-    vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
-    vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
-    for ( c = 2 ; c <= 2 + 10 ; c += 2 )
-    {
-        hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
-    }
-    textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " %s ", title);
-    textprintf_centre(surface, mainf, surface->w / 2, surface->h - 16, makecol(255, 0, 0),
-                      "Press ENTER (OK)  or  ESC (Cancel)");
-    len = (int) strlen(text);
-    for ( c = 0 ; c < len ; c++ )
-    {
-        if ( text[c] == 10 )
-        {
-            line++;
-            pos = 0;
-        }
-        else
-        {
-            if ( text[c] != 13 )
-            {
-                if ( text[c] > 126 || text[c] < 32 )
-                { break; }
-                textprintf(surface, mainf, 15 + pos * 8, 20 + line * 10, _color, "%c", text[c]);
-                pos++;
-            }
-        }
-    }
-    blit(surface, buf, 0, 0, x, y, w, h);
-
-    while ( key[KEY_ENTER] || key[KEY_ESC] )
-    {
-    }
-
-    while ( !( key[KEY_ENTER] || key[KEY_ESC] ))
-    {
-    }
-
-    if ( key[KEY_ENTER] )
-    {
-        return true;
-    }
-    else
-    {
-        return false;
-    }
-
-    blit(cache, buf, 0, 0, x, y, w, h);
-    destroy_bitmap(cache);
-    destroy_bitmap(surface);
-}
-
-void ShowMsgEx(char *text, BITMAP *buf, int x, int y, int w, int h, char *title, int _color)
-{
-    BITMAP *surface = create_bitmap(w, h);
-    BITMAP *cache = create_bitmap(w, h);
-    int len, c, line = 0, pos = 0;
-    blit(buf, cache, x, y, 0, 0, w, h);
-    clear(surface);
-    hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
-    vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
-    vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
-
-    for ( c = 2 ; c <= 2 + 10 ; c += 2 )
-    {
-        hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
-    }
-    textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " %s ", title);
-    textprintf_centre(surface, mainf, surface->w / 2, surface->h - 16, makecol(255, 0, 0), "Press ENTER");
-    len = (int) strlen(text);
-
-    for ( c = 0 ; c < len ; c++ )
-    {
-        if ( text[c] == 10 )
-        {
-            line++;
-            pos = 0;
-        }
-        else
-        {
-            if ( text[c] != 13 )
-            {
-                if ( text[c] > 126 || text[c] < 32 )
-                { break; }
-                textprintf(surface, mainf, 15 + pos * 8, 20 + line * 10, _color, "%c", text[c]);
-                pos++;
-            }
-        }
-    }
-    blit(surface, buf, 0, 0, x, y, w, h);
-
-    while ( key[KEY_ENTER] )
-    {
-    }
-
-    while ( !key[KEY_ENTER] )
-    {
-    }
-
-    blit(cache, buf, 0, 0, x, y, w, h);
-    destroy_bitmap(cache);
-    destroy_bitmap(surface);
-}
-
-
-class code_editor
-{
-private:
-    char *text_edit[65536];
-    int lines;
-    int cl, cp;
-    int scl, scp;
-    int _w, _h;
-
-public:
-    code_editor(void);
-
-    ~code_editor(void);
-
-    bool alloc_new_line(void); // ret. true on success
-    bool insert_new_line(int ln);
-
-    void delete_last(void);
-
-    void cut_line(int ln);
-
-    void insert_char(int ln, char ch);
-
-    void replace_char(int ln, char ch);
-
-    void backspace(void);
-
-    void del_ch(int ln);
-
-    void draw_cr(void);
-
-    void clear_cr(void);
-
-    void load_source(char *filename);
-
-    void save_source(char *filename);
-
-    int compile(int *err); // out-num errors, in-table of int's
-    // thet represtents lines with errors
-    // (automactly allocated)
-    int left, top;
-    int tab_size;
-    BITMAP *surface;
-
-    void process(void);
-
-    void disp(void);
-};
-
-void code_editor::load_source(char *filename)
-{
-    FILE *strin;
-    int c, i, tp, j = 0;
-    strin = NULL;
-    strin = fopen(filename, "rb");
-    lines = 0;
-    if ( strin == NULL )
-    { ShowMessage("Can't open the file", screen, 200, 200, 200, 60, "Message!"); }
-    else
-    {
-        //for (c=0;c<65535;c++)
-        //{
-        //	if (text_edit[c]!=NULL) delete[] text_edit[c];
-        //	else break;
-        //}
-
-        while ( !feof(strin))
-        {
-            alloc_new_line();
-            for ( i = 0 ; ( i < 256 ) && !feof(strin) ; i++ )
-            {
-                c = fgetc(strin);
-                if ( c == 9 ) //TAB
-                {
-                    tp = i / tab_size;
-                    tp++;
-                    tp *= 8;
-                    for ( i ; i <= tp ; i++ )
-                    { text_edit[j][i] = 32; }
-                    i--;
-                }
-                else
-                {
-                    if (( c == 10 ) || ( c == 13 ))
-                    {
-                        if ( c == 13 )
-                        { fgetc(strin); }
-                        for ( i ; i < 256 ; i++ )
-                        {
-                            text_edit[j][i] = 10;
-                        }
-                    }
-                    else
-                    { text_edit[j][i] = c == -1 ? 10 : c; }
-                }
-            }
-            j++;
-        }
-        lines = j;
-        fclose(strin);
-    }
-    cp = 0;
-    cl = 0;
-    scp = 0;
-    scl = 0;
-    disp();
-}
-
-void code_editor::disp(void)
-{
-    int i, j, cnti, cntj = 0;
-
-    for ( j = cl - scl ; j < cl - scl + _h + 1 && cntj < lines ; j++ )
-    {
-        cnti = 0;
-        bool endf = false;
-
-        for ( i = cp - scp ; i < cp - scp + _w && !endf ; i++ )
-        {
-            if ( text_edit[j][i] == 10 || text_edit[j][i] == 0 || text_edit[j][i] == 13 )
-            { endf = true; }
-            else
-            {
-                textprintf(surface, mainf, left + cnti * 8, top + cntj * 10, makecol(255, 255, 255), "%c",
-                           text_edit[j][i]);
-                cnti++;
-            }
-        }
-        for ( i ; i < cp - scp + _w + 1 ; i++ )
-        {
-            textprintf(surface, mainf, left + cnti * 8, top + cntj * 10, makecol(255, 255, 255), " ");
-            cnti++;
-        }
-        cntj++;
-    }
-    if ( cntj < _h )
-    { rectfill(surface, left, top + cntj * 10, surface->w - left, surface->h - left, 0); }
-}
-
-void code_editor::process(void)
-{
-    BITMAP *cache;
-    int c, i;
-    bool exit_ed = false;
-    char *filen;
-    filen = new char[256];
-
-    cache = create_bitmap(SCREEN_W, SCREEN_H);
-    blit(screen, cache, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
-
-    clear(surface);
-    hline(surface, 2, surface->h - 2, surface->w - 2, makecol(255, 255, 255));
-    vline(surface, 2, 2, surface->h - 2, makecol(255, 255, 255));
-    vline(surface, surface->w - 2, 2, surface->h - 2, makecol(255, 255, 255));
-    for ( c = 2 ; c <= 2 + 10 ; c += 2 )
-    {
-        hline(surface, 2, c, surface->w - 2, makecol(255, 255, 255));
-    }
-    textprintf_centre(surface, mainf, surface->w / 2, 4, makecol(255, 255, 255), " Source editor ");
-    lines = 0;
-    alloc_new_line();
-    WORD key_p;
-    WORD key_ch;
-    while ( !exit_ed )
-    {
-        key_p = readkey();
-        key_ch = key_p & 0xff;
-        key_p = key_p >> 8;
-
-        switch ( key_p )
-        {
-        case KEY_BACKSPACE:
-            if ( cp > 0 )
-            {
-                clear_cr();
-                if ( scp > 0 )
-                { scp--; }
-                cp--;
-                backspace();
-            }
-            else
-            {
-                if ( cl > 0 )
-                {
-                    clear_cr();
-                    for ( c = 0 ; ( c < 256 ) && ( text_edit[cl - 1][c] != 10 ) ; c++ )
-                    {
-                    }
-                    cp = c;
-                    scp = cp;
-                    if ( scp >= _w )
-                    { scp = _w - 1; }
-
-                    for ( c ; c < 256 ; c++ )
-                    {
-                        text_edit[cl - 1][c] = text_edit[cl][c - cp];
-                        if ( text_edit[cl][c - cp] == 10 )
-                        { break; }
-                    }
-                    delete[]text_edit[cl];
-                    for ( i = cl ; i < lines ; i++ )
-                    { text_edit[i] = text_edit[i + 1]; }
-                    lines--;
-                    text_edit[lines] = NULL;
-                    cl--;
-                    if ( scl > 0 )
-                    { scl--; }
-                }
-            }
-            break;
-        case KEY_DEL:
-            backspace();
-            break;
-        case KEY_ENTER:
-            if ( cl < 65536 )
-            {
-                clear_cr();
-                cl++;
-                if ( scl < _h )
-                { scl++; }
-                if ( !insert_new_line(cl))
-                {
-                    ShowMessage("Out of memory", surface, 200, 100, 200, 60, "Error!");
-                }
-                else
-                {
-                    for ( c = cp ; c < 256 ; c++ )
-                    {
-                        text_edit[cl][c - cp] = text_edit[cl - 1][c];
-                        text_edit[cl - 1][c] = 10;
-                    }
-                    cp = 0;
-                    scp = 0;
-                }
-
-            }
-            else
-            { ShowMessage("Source can't has more then 65536 lines of code!!!", surface, 200, 100, 200, 60, "Error!"); }
-            break;
-        case KEY_END:
-            clear_cr();
-            for ( cp = 0 ; cp < 256 && text_edit[cl][cp] != 10 ; cp++ )
-            {
-            }
-            scp = cp;
-            if ( scp >= _w )
-            { scp = _w - 1; }
-            break;
-        case KEY_HOME:
-            clear_cr();
-            cp = 0;
-            scp = 0;
-            break;
-        case KEY_LEFT:
-            if ( cp > 0 )
-            {
-                clear_cr();
-                cp--;
-                if ( scp > 0 )
-                { scp--; }
-            }
-            else
-            {
-                if ( cl > 0 )
-                {
-                    clear_cr();
-                    for ( c = 0 ; ( c < 256 ) && ( text_edit[cl - 1][c] != 10 ) ; c++ )
-                    {
-                    }
-                    cp = c;
-                    scp = cp;
-                    if ( scp >= _w )
-                    { scp = _w - 1; }
-
-                    cl--;
-                    if ( scl > 0 )
-                    { scl--; }
-                }
-            }
-            break;
-        case KEY_RIGHT:
-            if ( cp < 256 && text_edit[cl][cp] != 10 )
-            {
-                clear_cr();
-                cp++;
-                if ( scp < _w )
-                { scp++; }
-            }
-            else
-            {
-                if ( cl + 1 < lines )
-                {
-                    clear_cr();
-                    cp = 0;
-                    scp = cp;
-                    if ( scp >= _w )
-                    { scp = _w - 1; }
-                    cl++;
-                    if ( scl < _h )
-                    { scl++; }
-                }
-            }
-            break;
-        case KEY_UP:
-            if ( cl > 0 )
-            {
-                clear_cr();
-                cl--;
-                if ( scl > 0 )
-                { scl--; }
-                for ( c = 0 ; c < 256 && text_edit[cl][c] != 10 ; c++ )
-                {
-                }
-                if ( c - 1 < cp )
-                {
-                    cp = c;
-                    scp = cp;
-                    if ( scp >= _w )
-                    { scp = _w - 1; }
-                }
-            }
-            break;
-        case KEY_DOWN:
-            if ( cl < 65536 && cl < ( lines - 1 ))
-            {
-                clear_cr();
-                cl++;
-                if ( scl < _h )
-                { scl++; }
-                for ( c = 0 ; c < 256 && text_edit[cl][c] != 10 ; c++ )
-                {
-                }
-                if ( c - 1 < cp )
-                {
-                    cp = c;
-                    scp = cp;
-                    if ( scp >= _w )
-                    { scp = _w - 1; }
-                }
-            }
-            break;
-        case KEY_ESC:
-            if ( QuestionBox("Are you sure want to EXIT?", screen, 200, 200, 400, 60, "Confirm!", makecol(255, 0, 0)))
-            {
-                exit_ed = true;
-                for ( c = 0 ; c < lines ; c++ )
-                {
-                    if ( text_edit[c] != NULL )
-                    {
-                        delete[] text_edit[c];
-                    }
-                }
-                lines = 0;
-            }
-            else
-            {
-                rest(500);
-                clear_keybuf();
-            }
-            break;
-        case KEY_F3:
-            GetText(filen, screen, 100, 200, 600, 60, 256, " Enter source code file name ");
-            for ( c = 254 ; filen[c] == ' ' || filen[c] == '\r' ; c-- )
-            {
-                filen[c] = 0;
-            }
-            load_source(filen);
-            break;
-        default:
-            if ( key_ch != 0 && cp < 256 )
-            {
-                insert_char(cl, key_ch);
-                clear_cr();
-                cp++;
-                if ( scp < _w )
-                { scp++; }
-                key_ch = 0;
-            }
-            break;
-        }
-        if ( !exit_ed )
-        {
-            disp();
-            draw_cr();
-        }
-        textprintf(surface, mainf, 1, 1, makecol(255, 255, 255), " p%d l%d sp%d sl%d c%d ln%d", cp, cl, scp, scl,
-                   text_edit[cl][cp], lines);
-
-        blit(surface, screen, 0, 0, 0, 0, surface->w, surface->h);
-
-    }
-
-    blit(cache, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
-    destroy_bitmap(cache);
-    delete[] filen;
-    return;
-}
-
-void code_editor::insert_char(int ln, char ch)
-{
-    int i;
-    for ( i = 256 ; i > cp ; i-- )
-    {
-        text_edit[cl][i] = text_edit[cl][i - 1];
-    }
-    text_edit[cl][cp] = ch;
-}
-
-void code_editor::backspace(void)
-{
-    int i;
-    for ( i = cp ; i < 256 ; i++ )
-    {
-        text_edit[cl][i] = text_edit[cl][i + 1];
-    }
-}
-
-void code_editor::draw_cr(void)
-{
-    hline(surface, left + 8 * scp, top + 10 * scl + 9, left + 8 * scp + 8, makecol(255, 255, 255));
-}
-
-void code_editor::clear_cr(void)
-{
-    hline(surface, left + 8 * scp, top + 10 * scl + 9, left + 8 * scp + 8, 0);
-}
-
-code_editor::code_editor(void)
-{
-    int i;
-    for ( i = 0 ; i < 65536 ; i++ )
-    {
-        text_edit[i] = NULL;
-    }
-    lines = 0;
-    top = 24;
-    left = 11;
-    cl = 0;
-    cp = 0;
-    scl = 0;
-    scp = 0;
-    surface = create_bitmap(SCREEN_W, SCREEN_H - 100);
-    _w = ( surface->w - left * 2 ) / 8 - 1;
-    _h = ( surface->h - top - left ) / 10 - 1;
-    tab_size = 8;
-}
-
-code_editor::~code_editor(void)
-{
-}
-
-bool code_editor::alloc_new_line(void)
-{
-    int i;
-    if ( lines < 65536 )
-    {
-        text_edit[lines] = new char[256];
-        for ( i = 0 ; i < 256 ; i++ )
-        { text_edit[lines][i] = 10; }
-        lines++;
-        return text_edit[lines] == NULL ? false : true;
-    }
-    return false;
-}
-
-bool code_editor::insert_new_line(int ln)
-{
-    int i;
-    if ( lines < 65536 )
-    {
-        for ( i = lines ; i > ln ; i-- )
-        { text_edit[i] = text_edit[i - 1]; }
-        text_edit[ln] = NULL;
-        text_edit[ln] = new char[256];
-        for ( i = 0 ; i < 256 ; i++ )
-        { text_edit[ln][i] = 10; }
-        lines++;
-        if ( text_edit[ln] == NULL )
-        {
-            for ( i = ln ; i < lines ; i++ )
-            { text_edit[i] = text_edit[i + 1]; }
-            lines--;
-            return false;
-        }
-        else
-        { return true; }
-    }
-    return false;
-}
-
-void code_editor::delete_last(void)
-{
-    lines--;
-    delete[] text_edit[lines];
-    text_edit[lines] = NULL;
-}
-
-void code_editor::cut_line(int ln)
-{
-    int i;
-    if ( text_edit[ln] != NULL )
-    {
-        for ( i = ln ; i < lines ; i++ )
-        { text_edit[i] = text_edit[i + 1]; }
-        lines--;
-    }
-}
-
-#endif   // __MARIO_GUI

+ 38 - 0
include/code_51.h

@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Emu51
+ * code_51.h:
+ * Created by mlt on 22/03/23.
+ ******************************************************************************/
+
+#ifndef EMU51_CODE_51_H
+#define EMU51_CODE_51_H
+
+#include <stdint.h>
+
+class code_51
+{
+public:
+    char mnem[6];              // instruction mnemonic (2-4 characters)
+    uint8_t code;              // instruction code
+    uint8_t lenght;            // bytes which are needed to write this instruction into memory
+    uint8_t cycles;            // time unit
+    char display_string[20];   // string which is ready for displaying, it's made by make_ds(WORD) method
+    char datas[12];            // string which contains datas which will be displayed after mnemonic
+    void make_ds(uint16_t);    // make display string
+    void process();            // process the instruction
+};
+
+extern code_51 asm51[256];
+extern unsigned long c_time;
+
+uint8_t check_C(void);
+uint8_t check_AC(void);
+uint8_t check_OV(void);
+uint8_t check_P(void);
+
+void set_C(void);
+void clr_C(void);
+void set_Bit(uint8_t bit);
+void clr_Bit(uint8_t bit);
+
+#endif /* EMU51_CODE_51_H */

+ 61 - 0
include/code_editor.h

@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Emu51
+ * code_editor.h:
+ * Created by mlt on 22/03/23.
+ ******************************************************************************/
+
+#ifndef EMU51_CODE_EDITOR_H
+#define EMU51_CODE_EDITOR_H
+
+#include <allegro.h>
+
+class code_editor
+{
+private:
+    char *text_edit[65536];
+    int lines;
+    int cl, cp;
+    int scl, scp;
+    int _w, _h;
+
+public:
+    code_editor(void);
+
+    ~code_editor(void);
+
+    bool alloc_new_line(void); // ret. true on success
+    bool insert_new_line(int ln);
+
+    void delete_last(void);
+
+    void cut_line(int ln);
+
+    void insert_char(int ln, char ch);
+
+    void replace_char(int ln, char ch);
+
+    void backspace(void);
+
+    void del_ch(int ln);
+
+    void draw_cr(void);
+
+    void clear_cr(void);
+
+    void load_source(char *filename);
+
+    void save_source(char *filename);
+
+    int compile(int *err); // out-num errors, in-table of int's
+    // thet represtents lines with errors
+    // (automactly allocated)
+    int left, top;
+    int tab_size;
+    BITMAP *surface;
+
+    void process(void);
+
+    void disp(void);
+};
+
+#endif /* EMU51_CODE_EDITOR_H */

+ 32 - 0
include/dis_asm.h

@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Emu51
+ * dis_asm.h:
+ * Created by mlt on 22/03/23.
+ ******************************************************************************/
+
+#ifndef EMU51_DIS_ASM_H
+#define EMU51_DIS_ASM_H
+
+#include <stdint.h>
+#include <allegro.h>
+
+class dis_asm                     // display code class
+{
+private:
+    void hexoutB(int, int, int, uint8_t);
+
+public:
+    uint8_t *ram;                 // pointer to external ram table
+    BITMAP *buf, *surface;        // screen buffer, work surface
+    int frame;
+    int left;
+    bool changed;
+
+    dis_asm(uint8_t *, BITMAP *); // ext. ram, draw bitmap, constructor
+    void blit_it(int, int);
+
+    void draw(uint16_t);          // x,y,PC (PC is an adr. of register which string is displayed in the middle of the code monitor)
+    ~dis_asm();
+};
+
+#endif /* EMU51_DIS_ASM_H */

+ 56 - 0
include/emu51.h

@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Emu51
+ * code_51.h:
+ * Created by mlt on 22/03/23.
+ ******************************************************************************/
+
+#ifndef EMU51_EMU51_H
+#define EMU51_EMU51_H
+
+#include <stdint.h>
+#include <allegro.h>
+
+#define bit0 0x01
+#define bit1 0x02
+#define bit2 0x04
+#define bit3 0x08
+#define bit4 0x10
+#define bit5 0x20
+#define bit6 0x40
+#define bit7 0x80
+
+extern uint8_t *ram;
+extern uint8_t *prog;
+
+extern FONT *mainf;
+
+extern uint8_t SFR[0x100];                   // internal memory and sfr area 256 bytes
+extern uint8_t EXT_RAM[0x10000];             // external memory 64kB
+extern uint8_t EXT_PMEM[0x10000];            // external memory 64kB for program
+extern uint8_t *Acc;            // 8-bit accumlator
+extern uint16_t *DPTR;          // 16-bit register
+extern uint8_t *DPH;            // high byte of DPTR
+extern uint8_t *DPL;            // low byte of DPTR
+extern uint8_t *B;              // B register
+extern uint8_t *SP;             // Stack Pointer
+extern uint8_t *PSW;            // Program Status Word
+extern uint8_t *P0;             // 1st Port
+extern uint8_t *P1;             // 2nd Port
+extern uint8_t *P2;             // 3rd Port
+extern uint8_t *P3;             // 4th port
+extern uint8_t *SBUF;           // Serial transmission Buffer
+extern uint8_t *IE;             // Int Enable
+extern uint8_t *SCON;           // Serial Control
+extern uint8_t *TH1;            // Timer1 High
+extern uint8_t *TH0;            // Timer0 High
+extern uint8_t *TL1;            // Timer1 Low
+extern uint8_t *TL0;            // Timer0 Low
+extern uint8_t *TMOD;           // Timer Mode
+extern uint8_t *TCON;           // Timer Control
+extern uint8_t *PCON;           // Power Control
+extern uint8_t *R;              // Additional 8 Rx Registers
+extern uint16_t PC;                  // Progam Counter
+
+uint8_t check_Bit(uint8_t bit);
+
+#endif /* EMU51_EMU51_H */

+ 34 - 0
include/flags.h

@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Emu51
+ * flags.h:
+ * Created by mlt on 22/03/23.
+ ******************************************************************************/
+
+#ifndef EMU51_FLAGS_H
+#define EMU51_FLAGS_H
+
+#include <stdint.h>
+#include <allegro.h>
+
+class flags
+{
+private:
+    void hexoutB(int x, int y, int color, uint8_t numb);
+
+public:
+    int frame;
+    int left;
+    bool changed;
+    uint8_t *sfr;
+    BITMAP *surface, *buf;
+
+    void draw();
+
+    void blit_it(int, int);
+
+    flags(BITMAP *);
+
+    ~flags();
+};
+
+#endif /* EMU51_FLAGS_H */

+ 24 - 0
include/gui.h

@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Emu51
+ * gui.h:
+ ******************************************************************************/
+
+#ifndef EMU51_GUI_H
+#define EMU51_GUI_H
+
+#include <stdint.h>
+#include <allegro.h>
+
+bool checkBit(uint8_t tmp_b, int pos);
+void draw_SEG_digit(BITMAP *buf, int x, int y, int color, int size, uint8_t segm_code);
+void draw_LED_bin(BITMAP *buf, int x, int y, int color, uint8_t code);
+void change_char(char *string, char ch, int pos);
+void insert_char(char *string, char ch, int pos, int lenght);
+void cut_char(char *string, int pos, int lenght);
+void change_ext(char *s);
+void GetText(char *text, BITMAP *buf, int x, int y, int w, int h, int lenght, char *title);
+void ShowMessage(char *text, BITMAP *buf, int x, int y, int w, int h, char *title);
+bool QuestionBox(char *text, BITMAP *buf, int x, int y, int w, int h, char *title, int _color);
+void ShowMsgEx(char *text, BITMAP *buf, int x, int y, int w, int h, char *title, int _color);
+
+#endif   /* EMU51_GUI_H */

+ 35 - 0
include/ramv.h

@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Emu51
+ * ramv.h:
+ * Created by mlt on 22/03/23.
+ ******************************************************************************/
+
+#ifndef EMU51_RAMV_H
+#define EMU51_RAMV_H
+
+#include <stdint.h>
+#include <allegro.h>
+
+class ramv
+{
+private:
+    void hexoutB(int x, int y, int color, uint8_t numb);
+
+public:
+    int frame;
+    int left;
+    bool changed;
+    uint8_t reg[25];
+    char reg_label[25][10];
+    BITMAP *surface, *buf;
+
+    void draw(uint16_t);
+
+    void blit_it(int, int);
+
+    ramv(BITMAP *);
+
+    ~ramv();
+};
+
+#endif /* EMU51_RAMV_H */

+ 42 - 0
include/regs.h

@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Emu51
+ * regs.h:
+ * Created by mlt on 22/03/23.
+ ******************************************************************************/
+
+#ifndef EMU51_REGS_H
+#define EMU51_REGS_H
+
+#include <stdint.h>
+#include <allegro.h>
+
+class regs
+{
+private:
+    void hexoutB(int x, int y, int color, uint8_t numb);
+
+public:
+    int frame;
+    int left;
+    bool changed;
+    uint8_t *sfr;
+    uint8_t reg[25];
+    char reg_label[25][10];
+    BITMAP *surface, *buf;
+
+    void draw();
+
+    void blit_it(int, int);
+
+    int red;
+    int white;
+    int lblue;
+    int green;
+    int lred;
+
+    regs(uint8_t *, BITMAP *);
+
+    ~regs();
+};
+
+#endif /* EMU51_REGS_H */

+ 94 - 0
ramv.cpp

@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Emu51
+ * ramv.cpp:
+ * Created by mlt on 22/03/23.
+ ******************************************************************************/
+
+#include <emu51.h>
+#include <ramv.h>
+#include <gui.h>
+
+ramv::ramv(BITMAP *tmpBMP) // extram, screen
+{
+    frame = 2;
+    left = 12;
+    changed = true;
+    buf = tmpBMP;
+    surface = create_bitmap(500, 200);
+    clear(surface);
+}
+
+ramv::~ramv()
+{
+}
+
+void ramv::blit_it(int x, int y)
+{
+    blit(surface, buf, 0, 0, x, y, surface->w, surface->h);
+}
+
+void ramv::draw(uint16_t cur)
+{
+    int red = makecol(255, 0, 0);
+    int white = makecol(255, 255, 255);
+    int lgreen = makecol(128, 255, 128);
+    int green = makecol(0, 255, 0);
+    int lblue = makecol(0, 128, 255);
+    int yellow = makecol(255, 255, 0);
+    clear(surface);
+    int c2 = 0, c;
+    int y;
+    y = frame + 20;
+    int curcol = white;
+    for ( c = cur ; true ; c += 8 )
+    {
+        if ( !( y < surface->h - 10 ))
+        {
+            break;
+        }
+        textprintf(surface, mainf, left, y, lblue, "%4X: ", (uint16_t) ( c ));
+        for ( c2 = 0 ; c2 < 8 ; c2++ )
+        {
+            if ( PC == (uint16_t) ( c + c2 ))
+            {
+                curcol = red;
+                draw_SEG_digit(surface, left + 326 + c2 * 8, y, yellow, 3, ram[(uint16_t) ( c + c2 )]);
+            }
+            else if ( *DPTR == (uint16_t) ( c + c2 ))
+            {
+                curcol = lgreen;
+                draw_SEG_digit(surface, left + 326 + c2 * 8, y, yellow, 3, ram[(uint16_t) ( c + c2 )]);
+            }
+            else
+            {
+                curcol = white;
+                draw_SEG_digit(surface, left + 326 + c2 * 8, y, green, 3, ram[(uint16_t) ( c + c2 )]);
+            }
+            hexoutB(left + 48 + c2 * 24, y, curcol, ram[(uint16_t) ( c + c2 )]);
+            textprintf(surface, font, left + 252 + c2 * 8, y, curcol, "%c", ram[(uint16_t) ( c + c2 )]);
+
+        }
+        y += 10;
+    }
+    hline(surface, frame, surface->h - frame, surface->w - frame, white);
+    vline(surface, frame, frame, surface->h - frame, white);
+    vline(surface, surface->w - frame, frame, surface->h - frame, white);
+    for ( c = frame ; c <= frame + 10 ; c += 2 )
+    {
+        hline(surface, frame, c, surface->w - frame, white);
+    }
+    textprintf_centre(surface, mainf, surface->w / 2, frame + 2, white, " RAM Monitor ");
+}
+
+void ramv::hexoutB(int x, int y, int color, uint8_t numb)
+{
+    if ( numb > 0x10 )
+    {
+        textprintf(surface, mainf, x, y, color, "%2x", numb);
+    }
+    else
+    {
+        textprintf(surface, mainf, x, y, color, "%2x", numb);
+        textprintf(surface, mainf, x, y, color, "0");
+    }
+}

+ 73 - 0
regs.cpp

@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Emu51
+ * regs.cpp:
+ * Created by mlt on 22/03/23.
+ ******************************************************************************/
+
+#include <emu51.h>
+#include <regs.h>
+#include <gui.h>
+
+regs::regs(uint8_t *tmpB, BITMAP *tmpBMP)
+{
+    red = makecol(255, 0, 0);
+    white = makecol(255, 255, 255);
+    lblue = makecol(0, 128, 255);
+    green = makecol(0, 255, 0);
+    lred = makecol(255, 64, 0);
+    frame = 2;
+    left = 12;
+    changed = true;
+    sfr = tmpB;
+    buf = tmpBMP;
+    surface = create_bitmap(400, 300);
+    clear(surface);
+};
+
+regs::~regs()
+{};
+
+void regs::blit_it(int x, int y)
+{
+    blit(surface, buf, 0, 0, x, y, surface->w, surface->h);
+};
+
+void regs::draw()
+{
+    clear(surface);
+    int c2 = 0, c;
+    textprintf(surface, mainf, left, frame + 20, lblue, "nr  label    adress  hex dec ascii SEG LED(bin)");
+    for ( c = frame + 30 ; c < surface->h - 20 ; c += 10 )
+    {
+        textprintf(surface, mainf, left, c, white, "%2d: %9s (%2x) =  %2x %3d   %c", c2 + 1, reg_label[c2], reg[c2],
+                   sfr[reg[c2]], sfr[reg[c2]], sfr[reg[c2]]);
+        draw_SEG_digit(surface, left + 288, c, green, 4, sfr[reg[c2]]);
+        draw_LED_bin(surface, left + 314, c + 4, lred, sfr[reg[c2]]);
+        c2++;
+        if ( c2 == 25 )
+        {
+            break;
+        }
+    };
+    hline(surface, frame, surface->h - frame, surface->w - frame, white);
+    vline(surface, frame, frame, surface->h - frame, white);
+    vline(surface, surface->w - frame, frame, surface->h - frame, white);
+    for ( c = frame ; c <= frame + 10 ; c += 2 )
+    {
+        hline(surface, frame, c, surface->w - frame, white);
+    }
+    textprintf_centre(surface, mainf, surface->w / 2, frame + 2, white, " SFR Registers ");
+}
+
+void regs::hexoutB(int x, int y, int color, uint8_t numb)
+{
+    if ( numb > 0x10 )
+    {
+        textprintf(surface, mainf, x, y, color, "%2x", numb);
+    }
+    else
+    {
+        textprintf(surface, mainf, x, y, color, "%2x", numb);
+        textprintf(surface, mainf, x, y, color, "0");
+    }
+}

Some files were not shown because too many files changed in this diff