6 Commits
Author SHA1 Message Date
Godzil ab502de562 Update TODO 2023-03-23 10:34:31 +00:00
Godzil 37b24667fd Fix type lenght -> length 2023-03-22 18:20:16 +00:00
Godzil 768515710c Update Readme and Todo 2023-03-22 18:19:52 +00:00
Godzil 827e920909 Now use CMake to build and compile/run with Allegro 4.4 2023-03-22 18:09:57 +00:00
Godzil 8999fa051f Code cleanup / reformat
Add changes from official 0.3 release
Add examples
Add missing data.dat
2023-03-22 16:43:36 +00:00
Manoël Trapier dbb86f410a Rename index.html to index.htm 2018-11-01 00:13:10 +00:00
34 changed files with 5699 additions and 3297 deletions
+23
View 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)
+20
View File
@@ -0,0 +1,20 @@
EMU51
-----
Emu51 is a 80c51 emulator
![Emu51 v0.0.1 screenshort](docs/emu51.gif)
### Informations
(from the original Readme file)
Emulator accepts `*.bin`, `*.hex` files.
You can also compile source file by using external compiler, emu51 is compatible with free 8051 compiler by
MetaLink Corporation (http://www.metaice.com/ASM51/Files/ASM51.zip).
Just put asm51.exe into this directory and use Shift+F9 key combination to compile and load source file
(only windows :-( ).
I'm still searching multiplatform 8051 assembler compiler for emu51, because I want to add full compilation
support for all supported platforms.
The original version from Mariusz Kasolik and can be found here: https://emu51.sourceforge.net/
+7
View File
@@ -0,0 +1,7 @@
TODO List
=========
* [ ] Remove Allegro and use GL/glfw3 instead for window creation and framebuffer-ish
* [ ] Replace GUI using docked Dear ImGui
* [ ] Add frame buffer device
* [ ] Refactor code/classes there are lots of function that should be part of a class
+2050
View File
File diff suppressed because it is too large Load Diff
+532
View 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--;
}
}
BIN
View File
Binary file not shown.
+106
View 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]].length ; 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]].length;
}
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)
{
}
View File
+787 -2482
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -0,0 +1,2 @@
:0600000074FF240180FCE6
:00000001FF
+303
View File
@@ -0,0 +1,303 @@
$mod851
state EQU 7fh
tmp EQU 7eh
org 0000h
ljmp start
org 000bh
t0int: ljmp task_switch
org 0060h
start: mov A,TMOD
anl A,#11111000b
orl A,#1
mov TMOD,A ; T0 mode = 1
mov TL0,#0
mov TH0,#0ffh
mov state,#00h
setb TR0 ; T0 enable
setb ET0 ; T0 int enable
setb EA ; enable int
task1: xrl P1,#0fh
mov A,#080h
lcall delay
sjmp task1
task2: xrl P1,#0f0h
mov A,#0ffh
lcall delay
sjmp task2
delay: djnz Acc,delay
ret
;========================================
task_switch:
push DPH
push DPL
push Acc
mov A,state
jz ts_go
ljmp rev
ts_go: pop Acc ; Acc
mov DPTR,#t1inf
movx @DPTR,A
pop Acc ; DPL
inc DPTR
movx @DPTR,A
pop Acc ; DPH
inc DPTR
movx @DPTR,A
inc DPTR ; B
mov A,B
movx @DPTR,A
inc DPTR ; PSW
mov A,PSW
movx @DPTR,A
pop Acc ; PC
inc DPTR
movx @DPTR,A
pop Acc
inc DPTR
movx @DPTR,A
inc DPTR ; SP
mov A,SP
movx @DPTR,A
inc DPTR ; adr: 00h
mov A,R0
movx @DPTR,A
mov B,#6fh ; adr: 01h-6fh
mov R0,#01h
ts_l1: inc DPTR
mov A,@R0
movx @DPTR,A
inc R0
djnz B,ts_l1
;------------
mov DPTR,#(t2inf_end-1)
mov B,#6fh ; adr: 01-6f
mov R0,#6fh
ts_l2: movx A,@DPTR
mov @R0,A
dec R0
mov tmp,A
lcall dec_dptr
mov A,tmp
djnz B,ts_l2
movx A,@DPTR
mov R0,A ; adr: 00
lcall dec_dptr ; SP
movx A,@DPTR
mov SP,A
lcall dec_dptr ; PC
movx A,@DPTR
push Acc
lcall dec_dptr
movx A,@DPTR
push Acc
lcall dec_dptr ; PSW
movx A,@DPTR
mov PSW,A
lcall dec_dptr ; B
movx A,@DPTR
mov B,A
lcall dec_dptr ; DPH
movx A,@DPTR
push Acc
lcall dec_dptr ; DPL
movx A,@DPTR
push Acc
lcall dec_dptr ; Acc
movx A,@DPTR
pop DPL
pop DPH
mov state,#0ffh
mov TL0,#0
mov TH0,#0ffh
reti
;-=-=-=-=-=-=-=-=-
rev:
pop Acc ; Acc
mov DPTR,#t2inf
movx @DPTR,A
pop Acc ; DPL
inc DPTR
movx @DPTR,A
pop Acc ; DPH
inc DPTR
movx @DPTR,A
inc DPTR ; B
mov A,B
movx @DPTR,A
inc DPTR ; PSW
mov A,PSW
movx @DPTR,A
pop Acc ; PC
inc DPTR
movx @DPTR,A
pop Acc
inc DPTR
movx @DPTR,A
inc DPTR ; SP
mov A,SP
movx @DPTR,A
inc DPTR ; adr: 00h
mov A,R0
movx @DPTR,A
mov B,#6fh ; adr: 01h-6fh
mov R0,#01h
ts_l3: inc DPTR
mov A,@R0
movx @DPTR,A
inc R0
djnz B,ts_l3
;------------
mov DPTR,#(t1inf_end-1)
mov B,#6fh ; adr: 01-6f
mov R0,#6fh
ts_l4: movx A,@DPTR
mov @R0,A
dec R0
mov tmp,A
lcall dec_dptr
mov A,tmp
djnz B,ts_l4
movx A,@DPTR
mov R0,A ; adr: 00
lcall dec_dptr ; SP
movx A,@DPTR
mov SP,A
lcall dec_dptr ; PC
movx A,@DPTR
push Acc
lcall dec_dptr
movx A,@DPTR
push Acc
lcall dec_dptr ; PSW
movx A,@DPTR
mov PSW,A
lcall dec_dptr ; B
movx A,@DPTR
mov B,A
lcall dec_dptr ; DPH
movx A,@DPTR
push Acc
lcall dec_dptr ; DPL
movx A,@DPTR
push Acc
lcall dec_dptr ; Acc
movx A,@DPTR
pop DPL
pop DPH
mov state,#00h
mov TL0,#0
mov TH0,#0ffh
reti
;========================================
dec_dptr:
dec DPL
mov A,DPL
cjne A,#0ffh,decdp_lab1
dec DPH
decdp_lab1:
ret
;========================================
org 8000h
t1inf:
db 00 ; Acc
db 00 ; DPL
db 00 ; DPH
db 00 ; B
db 00 ; PSW
dw 00 ; PC
db 07 ; SP
db 0,0,0,0,0,0,0,0 ; R0-R7 (from adress: 00h)
db 0,0,0,0,0,0,0,0 ; Stack
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0 ; (to adress: 6fh)
t1inf_end:
t2inf:
db 00 ; Acc
db 00 ; DPL
db 00 ; DPH
db 00 ; B
db 00 ; PSW
dw task2 ; PC
db 07 ; SP
db 0,0,0,0,0,0,0,0 ; R0-R7 (from adress: 00h)
db 0,0,0,0,0,0,0,0 ; Stack
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0 ; (to adress: 6fh)
t2inf_end:
END
+308
View File
@@ -0,0 +1,308 @@
$mod851
state EQU 7fh
tmp EQU 7eh
org 0000h
ljmp start
org 000bh
t0int: ljmp task_switch
org 0060h
start: clr EA
mov A,TMOD
anl A,#11111000b
orl A,#1
mov TMOD,A ; T0 mode = 1
mov TL0,#0
mov TH0,#0f0h
mov state,#00h
setb TR0 ; T0 enable
setb ET0 ; T0 int enable
setb EA ; enable int
task1: xrl P1,#0fh
mov B,#070h
t1l2: mov A,#0ffh
t1l1: djnz Acc,t1l1
djnz B,t1l2
sjmp task1
task2: xrl P1,#0f0h
mov B,#030h
t2l2: mov A,#0ffh
t2l1: djnz Acc,t2l1
djnz B,t2l2
sjmp task2
;========================================
task_switch:
push DPH
push DPL
push Acc
mov A,state
jz ts_go
ljmp rev
ts_go: pop Acc ; Acc
mov DPTR,#t1inf
movx @DPTR,A
pop Acc ; DPL
inc DPTR
movx @DPTR,A
pop Acc ; DPH
inc DPTR
movx @DPTR,A
inc DPTR ; B
mov A,B
movx @DPTR,A
inc DPTR ; PSW
mov A,PSW
movx @DPTR,A
pop Acc ; PC
inc DPTR
movx @DPTR,A
pop Acc
inc DPTR
movx @DPTR,A
inc DPTR ; SP
mov A,SP
movx @DPTR,A
inc DPTR ; adr: 00h
mov A,R0
movx @DPTR,A
mov B,#6fh ; adr: 01h-6fh
mov R0,#01h
ts_l1: inc DPTR
mov A,@R0
movx @DPTR,A
inc R0
djnz B,ts_l1
;------------
mov DPTR,#(t2inf_end-1)
mov B,#6fh ; adr: 01-6f
mov R0,#6fh
ts_l2: movx A,@DPTR
mov @R0,A
dec R0
lcall dec_dptr
djnz B,ts_l2
movx A,@DPTR
mov R0,A ; adr: 00
lcall dec_dptr ; SP
movx A,@DPTR
mov SP,A
lcall dec_dptr ; PC
movx A,@DPTR
push Acc
lcall dec_dptr
movx A,@DPTR
push Acc
lcall dec_dptr ; PSW
movx A,@DPTR
mov PSW,A
lcall dec_dptr ; B
movx A,@DPTR
mov B,A
lcall dec_dptr ; DPH
movx A,@DPTR
push Acc
lcall dec_dptr ; DPL
movx A,@DPTR
push Acc
lcall dec_dptr ; Acc
movx A,@DPTR
pop DPL
pop DPH
mov state,#0ffh
mov TL0,#0
mov TH0,#0f0h
reti
;-=-=-=-=-=-=-=-=-
rev:
pop Acc ; Acc
mov DPTR,#t2inf
movx @DPTR,A
pop Acc ; DPL
inc DPTR
movx @DPTR,A
pop Acc ; DPH
inc DPTR
movx @DPTR,A
inc DPTR ; B
mov A,B
movx @DPTR,A
inc DPTR ; PSW
mov A,PSW
movx @DPTR,A
pop Acc ; PC
inc DPTR
movx @DPTR,A
pop Acc
inc DPTR
movx @DPTR,A
inc DPTR ; SP
mov A,SP
movx @DPTR,A
inc DPTR ; adr: 00h
mov A,R0
movx @DPTR,A
mov B,#6fh ; adr: 01h-6fh
mov R0,#01h
ts_l3: inc DPTR
mov A,@R0
movx @DPTR,A
inc R0
djnz B,ts_l3
;------------
mov DPTR,#(t1inf_end-1)
mov B,#6fh ; adr: 01-6f
mov R0,#6fh
ts_l4: movx A,@DPTR
mov @R0,A
dec R0
lcall dec_dptr
djnz B,ts_l4
movx A,@DPTR
mov R0,A ; adr: 00
lcall dec_dptr ; SP
movx A,@DPTR
mov SP,A
lcall dec_dptr ; PC
movx A,@DPTR
push Acc
lcall dec_dptr
movx A,@DPTR
push Acc
lcall dec_dptr ; PSW
movx A,@DPTR
mov PSW,A
lcall dec_dptr ; B
movx A,@DPTR
mov B,A
lcall dec_dptr ; DPH
movx A,@DPTR
push Acc
lcall dec_dptr ; DPL
movx A,@DPTR
push Acc
lcall dec_dptr ; Acc
movx A,@DPTR
pop DPL
pop DPH
mov state,#00h
mov TL0,#0
mov TH0,#0f0h
reti
;========================================
dec_dptr:
xch A,DPL
dec A
cjne A,#0ffh,decdp_lab1
dec DPH
decdp_lab1:
xch A,DPL
ret
;========================================
org 8000h
t1inf:
db 00 ; Acc
db 00 ; DPL
db 00 ; DPH
db 00 ; B
db 00 ; PSW
dw 00 ; PC
db 07 ; SP
db 0,0,0,0,0,0,0,0 ; R0-R7 (from adress: 00h)
db 0,0,0,0,0,0,0,0 ; Stack
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0 ; (to adress: 6fh)
t1inf_end:
t2inf:
db 00 ; Acc
db 00 ; DPL
db 00 ; DPH
db 00 ; B
db 00 ; PSW
dw task2 ; PC
db 07 ; SP
db 0,0,0,0,0,0,0,0 ; R0-R7 (from adress: 00h)
db 0,0,0,0,0,0,0,0 ; Stack
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0 ; (to adress: 6fh)
t2inf_end:
END
+40
View File
@@ -0,0 +1,40 @@
:030000000200609B
:03000B0002009957
:10006000C2AFE58954F84401F589758A00758CF0B2
:10007000757F00D28CD2A9D2AF63900F75F07074E7
:10008000FFD5E0FDD5F0F880F06390F075F03074A6
:10009000FFD5E0FDD5F0F880F0C083C082C0E0E578
:1000A0007F6003020126D0E0908000F0D0E0A3F052
:1000B000D0E0A3F0A3E5F0F0A3E5D0F0D0E0A3F00A
:1000C000D0E0A3F0A3E581F0A3E8F075F06F78012C
:1000D000A3E6F008D5F0F99080EF75F06F786FE047
:1000E000F6181201A6D5F0F7E0F81201A6E0F581A6
:1000F0001201A6E0C0E01201A6E0C0E01201A6E0F5
:10010000F5D01201A6E0F5F01201A6E0C0E0120160
:10011000A6E0C0E01201A6E0D082D083757FFF7513
:100120008A00758CF032D0E0908078F0D0E0A3F0B7
:10013000D0E0A3F0A3E5F0F0A3E5D0F0D0E0A3F089
:10014000D0E0A3F0A3E581F0A3E8F075F06F7801AB
:10015000A3E6F008D5F0F990807775F06F786FE03E
:10016000F6181201A6D5F0F7E0F81201A6E0F58125
:100170001201A6E0C0E01201A6E0C0E01201A6E074
:10018000F5D01201A6E0F5F01201A6E0C0E01201E0
:10019000A6E0C0E01201A6E0D082D083757F007592
:1001A0008A00758CF032C58214B4FF021583C582B3
:0101B000222C
:108000000000000000000007000000000000000069
:108010000000000000000000000000000000000060
:108020000000000000000000000000000000000050
:108030000000000000000000000000000000000040
:108040000000000000000000000000000000000030
:108050000000000000000000000000000000000020
:108060000000000000000000000000000000000010
:108070000000000000000000000000000000890770
:1080800000000000000000000000000000000000F0
:1080900000000000000000000000000000000000E0
:1080A00000000000000000000000000000000000D0
:1080B00000000000000000000000000000000000C0
:1080C00000000000000000000000000000000000B0
:1080D00000000000000000000000000000000000A0
:1080E0000000000000000000000000000000000090
:00000001FF
+352
View File
@@ -0,0 +1,352 @@
$mod851
$include (bios.inc)
$include (const.inc)
state EQU 7fh
tmp EQU 7eh
org 8000h
ljmp start
org 800bh
t0int: ljmp task_switch
org 8060h
start: clr EA
mov intvec,#80h
mov A,TMOD
anl A,#11111000b
orl A,#1
mov TMOD,A ; T0 mode = 1
mov TL0,#0
mov TH0,#0ffh
mov state,#00h
setb TR0 ; T0 enable
setb ET0 ; T0 int enable
setb EA ; enable int
task1: xrl P1,#0fh
mov A,#0ffh
t1l1: djnz Acc,t1l1
mov A,#0ffh
t1l2: djnz Acc,t1l2
mov A,#0ffh
t1l3: djnz Acc,t1l3
mov A,#0ffh
t1l4: djnz Acc,t1l4
mov A,#0ffh
t1l5: djnz Acc,t1l5
mov A,#0ffh
t1l6: djnz Acc,t1l6
mov A,#0ffh
t1l7: djnz Acc,t1l7
mov A,#0ffh
t1l8: djnz Acc,t1l8
mov A,#0ffh
t1l9: djnz Acc,t1l9
mov A,#0ffh
t1l10: djnz Acc,t1l10
mov A,#0ffh
t1l11: djnz Acc,t1l11
mov A,#0ffh
t1l12: djnz Acc,t1l12
mov A,#0ffh
t1l13: djnz Acc,t1l13
mov A,#0ffh
t1l14: djnz Acc,t1l14
mov A,#0ffh
t1l15: djnz Acc,t1l15
mov A,#0ffh
t1l16: djnz Acc,t1l16
mov A,#0ffh
t1l17: djnz Acc,t1l17
sjmp task1
task2: xrl P1,#0f0h
mov A,#0ffh
t2l1: djnz Acc,t2l1
mov A,#0ffh
t2l2: djnz Acc,t2l2
mov A,#0ffh
t2l3: djnz Acc,t2l3
mov A,#0ffh
t2l4: djnz Acc,t2l4
mov A,#0ffh
t2l5: djnz Acc,t2l5
mov A,#0ffh
t2l6: djnz Acc,t2l6
sjmp task2
delay: djnz Acc,delay
ret
;========================================
task_switch:
push DPH
push DPL
push Acc
mov A,state
jz ts_go
ljmp rev
ts_go: pop Acc ; Acc
mov DPTR,#t1inf
movx @DPTR,A
pop Acc ; DPL
inc DPTR
movx @DPTR,A
pop Acc ; DPH
inc DPTR
movx @DPTR,A
inc DPTR ; B
mov A,B
movx @DPTR,A
inc DPTR ; PSW
mov A,PSW
movx @DPTR,A
pop Acc ; PC
inc DPTR
movx @DPTR,A
pop Acc
inc DPTR
movx @DPTR,A
inc DPTR ; SP
mov A,SP
movx @DPTR,A
inc DPTR ; adr: 00h
mov A,R0
movx @DPTR,A
mov B,#6fh ; adr: 01h-6fh
mov R0,#01h
ts_l1: inc DPTR
mov A,@R0
movx @DPTR,A
inc R0
djnz B,ts_l1
;------------
mov DPTR,#(t2inf_end-1)
mov B,#6fh ; adr: 01-6f
mov R0,#6fh
ts_l2: movx A,@DPTR
mov @R0,A
dec R0
lcall dec_dptr
djnz B,ts_l2
movx A,@DPTR
mov R0,A ; adr: 00
lcall dec_dptr ; SP
movx A,@DPTR
mov SP,A
lcall dec_dptr ; PC
movx A,@DPTR
push Acc
lcall dec_dptr
movx A,@DPTR
push Acc
lcall dec_dptr ; PSW
movx A,@DPTR
mov PSW,A
lcall dec_dptr ; B
movx A,@DPTR
mov B,A
lcall dec_dptr ; DPH
movx A,@DPTR
push Acc
lcall dec_dptr ; DPL
movx A,@DPTR
push Acc
lcall dec_dptr ; Acc
movx A,@DPTR
pop DPL
pop DPH
mov state,#0ffh
mov TL0,#0
mov TH0,#0ffh
reti
;-=-=-=-=-=-=-=-=-
rev:
pop Acc ; Acc
mov DPTR,#t2inf
movx @DPTR,A
pop Acc ; DPL
inc DPTR
movx @DPTR,A
pop Acc ; DPH
inc DPTR
movx @DPTR,A
inc DPTR ; B
mov A,B
movx @DPTR,A
inc DPTR ; PSW
mov A,PSW
movx @DPTR,A
pop Acc ; PC
inc DPTR
movx @DPTR,A
pop Acc
inc DPTR
movx @DPTR,A
inc DPTR ; SP
mov A,SP
movx @DPTR,A
inc DPTR ; adr: 00h
mov A,R0
movx @DPTR,A
mov B,#6fh ; adr: 01h-6fh
mov R0,#01h
ts_l3: inc DPTR
mov A,@R0
movx @DPTR,A
inc R0
djnz B,ts_l3
;------------
mov DPTR,#(t1inf_end-1)
mov B,#6fh ; adr: 01-6f
mov R0,#6fh
ts_l4: movx A,@DPTR
mov @R0,A
dec R0
lcall dec_dptr
djnz B,ts_l4
movx A,@DPTR
mov R0,A ; adr: 00
lcall dec_dptr ; SP
movx A,@DPTR
mov SP,A
lcall dec_dptr ; PC
movx A,@DPTR
push Acc
lcall dec_dptr
movx A,@DPTR
push Acc
lcall dec_dptr ; PSW
movx A,@DPTR
mov PSW,A
lcall dec_dptr ; B
movx A,@DPTR
mov B,A
lcall dec_dptr ; DPH
movx A,@DPTR
push Acc
lcall dec_dptr ; DPL
movx A,@DPTR
push Acc
lcall dec_dptr ; Acc
movx A,@DPTR
pop DPL
pop DPH
mov state,#00h
mov TL0,#0
mov TH0,#0ffh
reti
;========================================
dec_dptr:
xch A,DPL
dec A
cjne A,#0ffh,decdp_lab1
dec DPH
decdp_lab1:
xch A,DPL
ret
;========================================
org 9000h
t1inf:
db 00 ; Acc
db 00 ; DPL
db 00 ; DPH
db 00 ; B
db 00 ; PSW
dw 00 ; PC
db 07 ; SP
db 0,0,0,0,0,0,0,0 ; R0-R7 (from adress: 00h)
db 0,0,0,0,0,0,0,0 ; Stack
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0 ; (to adress: 6fh)
t1inf_end:
t2inf:
db 00 ; Acc
db 00 ; DPL
db 00 ; DPH
db 00 ; B
db 00 ; PSW
dw task2 ; PC
db 07 ; SP
db 0,0,0,0,0,0,0,0 ; R0-R7 (from adress: 00h)
db 0,0,0,0,0,0,0,0 ; Stack
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0 ; (to adress: 6fh)
t2inf_end:
END
+4
View File
@@ -0,0 +1,4 @@
:100000007401120016F59023B480F7120016F590D3
:1000100003B401F780ECC0E0C0F0748075F0FFD548
:0A002000F0FDD5E0F7D0F0D0E022AB
:00000001FF
+4
View File
@@ -0,0 +1,4 @@
:10000000020010544F4D454B53414C555441542020
:100010007580217580217580217580217580210270
:020020000010CE
:00000001FF
+168
View 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
View 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
View 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
View 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 length)
{
for ( int c = length ; c > pos ; c-- )
{
string[c - 1] = string[c - 2];
}
string[pos - 1] = ch;
}
void cut_char(char *string, int pos, int length)
{
for ( int c = pos ; c < length ; c++ )
{
string[c - 1] = string[c];
}
string[length - 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 length, 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 <= length - 1 ; c++ )
{
text[c] = 32;
}
text[length - 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, length);
text[length - 2] = 32;
text[length - 1] = 0;
}
flag = true;
break;
case KEY_DEL:
cut_char(text, pos, length);
text[length - 2] = 32;
text[length - 1] = 0;
flag = true;
break;
case KEY_LEFT:
if ( pos > 1 )
{ pos--; }
flag = true;
break;
case KEY_RIGHT:
if ( pos < length )
{ pos++; }
flag = true;
break;
}
if ( !key[KEY_ENTER] && key_ch != 0 && pos < length && !flag )
{
insert_char(text, key_ch, pos, length);
pos++;
text[length - 1] = 0;
}
}
text[length - 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);
}
-792
View File
@@ -1,792 +0,0 @@
#ifndef __MARIO_GUI
#define __MARIO_GUI
#include <allegro.h>
#include <stdio.h>
#include <stdlib.h>
bool checkBit (BYTE tmp_b,int pos) // Returns state of a single bit
{ // which is on 'pos' position
if ( tmp_b&(1<<pos) ) // in tmp_b byte
{
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
View 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 length; // 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
View 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
View 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
View 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
View 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 */
Executable
+24
View 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 length);
void cut_char(char *string, int pos, int length);
void change_ext(char *s);
void GetText(char *text, BITMAP *buf, int x, int y, int w, int h, int length, 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
View 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
View 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
View 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");
}
}
-17
View File
@@ -1,17 +0,0 @@
EMU51 (Mariusz Kasolik) - Modifications done by TRAPIER Manoel (godzil@free.fr)
-------------------------------------------------------------------------------
Source file (platform independed)
---------------------------------
Emulator accepts *.bin, *.hex files.
You can also compile source file by using external compiler, emu51 is compatible with
free 8051 compiler by MetaLink Corporation (http://www.metaice.com/ASM51/Files/ASM51.zip).
Just put asm51.exe into this directory and use Shift+F9 key combination to compile and load source file (only windows :-( ).
I'm still searching multiplatform 8051 assembler compiler for emu51, because i want to add full compilation support for all supported platforms.
You can find history in the file of the same name.
- Compilation has been tested with VisualStudio 6 using latest (4.1.9) allegro library.
- Compilation tested too with DJGPP with GCC 3.2.1 and allegro 4.1.9
-1
View File
@@ -1 +0,0 @@
readme.txt
+73
View 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");
}
}
-5
View File
@@ -1,5 +0,0 @@
-> Correct timer0 issue
-> Find invalids opcodes
-> Expand GUI
-> make pure win32 gui ??
-> Compile with full version of VC6...