Now use CMake to build and compile/run with Allegro 4.4
This commit is contained in:
23
CMakeLists.txt
Normal file
23
CMakeLists.txt
Normal file
@@ -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
code_51.cpp
Normal file
2050
code_51.cpp
Normal file
File diff suppressed because it is too large
Load Diff
532
code_editor.cpp
Normal file
532
code_editor.cpp
Normal file
@@ -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
dis_asm.cpp
Normal file
106
dis_asm.cpp
Normal file
@@ -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)
|
||||
{
|
||||
}
|
||||
250
emu51.h
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
external/cmake/GetGitRevisionDescription.cmake
vendored
Normal file
168
external/cmake/GetGitRevisionDescription.cmake
vendored
Normal file
@@ -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
external/cmake/GetGitRevisionDescription.cmake.in
vendored
Normal file
41
external/cmake/GetGitRevisionDescription.cmake.in
vendored
Normal file
@@ -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
flags.cpp
Normal file
63
flags.cpp
Normal file
@@ -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
gui.cpp
Normal file
400
gui.cpp
Normal file
@@ -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);
|
||||
}
|
||||
905
gui.h
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
include/code_51.h
Normal file
38
include/code_51.h
Normal file
@@ -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
include/code_editor.h
Normal file
61
include/code_editor.h
Normal file
@@ -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
include/dis_asm.h
Normal file
32
include/dis_asm.h
Normal file
@@ -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
include/emu51.h
Normal file
56
include/emu51.h
Normal file
@@ -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
include/flags.h
Normal file
34
include/flags.h
Normal file
@@ -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
include/gui.h
Executable file
24
include/gui.h
Executable file
@@ -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
include/ramv.h
Normal file
35
include/ramv.h
Normal file
@@ -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
include/regs.h
Normal file
42
include/regs.h
Normal file
@@ -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
ramv.cpp
Normal file
94
ramv.cpp
Normal file
@@ -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
regs.cpp
Normal file
73
regs.cpp
Normal file
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user