Compare commits
3 Commits
415f9b72f7
...
42246deb35
Author | SHA1 | Date | |
---|---|---|---|
42246deb35 | |||
ab55a9ff16 | |||
db6e20b4b1 |
117
Session.vim
117
Session.vim
@ -13,12 +13,13 @@ if &shortmess =~ 'A'
|
||||
else
|
||||
set shortmess=aoO
|
||||
endif
|
||||
badd +397 vm/main.c
|
||||
badd +1 Makefile
|
||||
badd +30 vm/vm.h
|
||||
badd +225 vm/vm.c
|
||||
badd +53 vm/asm.h
|
||||
badd +178 vm/asm.c
|
||||
badd +437 vm/main.c
|
||||
badd +48 Makefile
|
||||
badd +10 vm/vm.h
|
||||
badd +181 vm/vm.c
|
||||
badd +14 vm/asm.h
|
||||
badd +263 vm/asm.c
|
||||
badd +747 ~/.config/nvim/init.lua
|
||||
argglobal
|
||||
%argdel
|
||||
$argadd vm/main.c
|
||||
@ -44,8 +45,8 @@ set winminheight=0
|
||||
set winheight=1
|
||||
set winminwidth=0
|
||||
set winwidth=1
|
||||
exe 'vert 1resize ' . ((&columns * 127 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 128 + 128) / 256)
|
||||
exe 'vert 1resize ' . ((&columns * 123 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 132 + 128) / 256)
|
||||
argglobal
|
||||
setlocal fdm=manual
|
||||
setlocal fde=0
|
||||
@ -57,11 +58,11 @@ setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let &fdl = &fdl
|
||||
let s:l = 397 - ((1 * winheight(0) + 32) / 65)
|
||||
let s:l = 437 - ((37 * winheight(0) + 32) / 65)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
keepjumps exe s:l
|
||||
normal! zt
|
||||
keepjumps 397
|
||||
keepjumps 437
|
||||
normal! 012|
|
||||
wincmd w
|
||||
argglobal
|
||||
@ -80,15 +81,15 @@ setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let &fdl = &fdl
|
||||
let s:l = 1 - ((0 * winheight(0) + 32) / 65)
|
||||
let s:l = 15 - ((14 * winheight(0) + 32) / 65)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
keepjumps exe s:l
|
||||
normal! zt
|
||||
keepjumps 1
|
||||
keepjumps 15
|
||||
normal! 0
|
||||
wincmd w
|
||||
exe 'vert 1resize ' . ((&columns * 127 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 128 + 128) / 256)
|
||||
exe 'vert 1resize ' . ((&columns * 123 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 132 + 128) / 256)
|
||||
tabnext
|
||||
edit vm/vm.h
|
||||
let s:save_splitbelow = &splitbelow
|
||||
@ -107,8 +108,8 @@ set winminheight=0
|
||||
set winheight=1
|
||||
set winminwidth=0
|
||||
set winwidth=1
|
||||
exe 'vert 1resize ' . ((&columns * 127 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 128 + 128) / 256)
|
||||
exe 'vert 1resize ' . ((&columns * 93 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 162 + 128) / 256)
|
||||
argglobal
|
||||
balt Makefile
|
||||
setlocal fdm=manual
|
||||
@ -121,12 +122,12 @@ setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let &fdl = &fdl
|
||||
let s:l = 26 - ((25 * winheight(0) + 32) / 65)
|
||||
let s:l = 10 - ((9 * winheight(0) + 32) / 65)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
keepjumps exe s:l
|
||||
normal! zt
|
||||
keepjumps 26
|
||||
normal! 0
|
||||
keepjumps 10
|
||||
normal! 011|
|
||||
wincmd w
|
||||
argglobal
|
||||
if bufexists(fnamemodify("vm/vm.c", ":p")) | buffer vm/vm.c | else | edit vm/vm.c | endif
|
||||
@ -144,15 +145,15 @@ setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let &fdl = &fdl
|
||||
let s:l = 70 - ((18 * winheight(0) + 32) / 65)
|
||||
let s:l = 83 - ((7 * winheight(0) + 32) / 65)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
keepjumps exe s:l
|
||||
normal! zt
|
||||
keepjumps 70
|
||||
normal! 026|
|
||||
keepjumps 83
|
||||
normal! 021|
|
||||
wincmd w
|
||||
exe 'vert 1resize ' . ((&columns * 127 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 128 + 128) / 256)
|
||||
exe 'vert 1resize ' . ((&columns * 93 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 162 + 128) / 256)
|
||||
tabnext
|
||||
edit vm/asm.h
|
||||
let s:save_splitbelow = &splitbelow
|
||||
@ -160,10 +161,7 @@ let s:save_splitright = &splitright
|
||||
set splitbelow splitright
|
||||
wincmd _ | wincmd |
|
||||
vsplit
|
||||
wincmd _ | wincmd |
|
||||
vsplit
|
||||
2wincmd h
|
||||
wincmd w
|
||||
1wincmd h
|
||||
wincmd w
|
||||
let &splitbelow = s:save_splitbelow
|
||||
let &splitright = s:save_splitright
|
||||
@ -174,9 +172,8 @@ set winminheight=0
|
||||
set winheight=1
|
||||
set winminwidth=0
|
||||
set winwidth=1
|
||||
exe 'vert 1resize ' . ((&columns * 73 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 86 + 128) / 256)
|
||||
exe 'vert 3resize ' . ((&columns * 95 + 128) / 256)
|
||||
exe 'vert 1resize ' . ((&columns * 87 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 168 + 128) / 256)
|
||||
argglobal
|
||||
balt vm/vm.c
|
||||
setlocal fdm=manual
|
||||
@ -189,12 +186,12 @@ setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let &fdl = &fdl
|
||||
let s:l = 53 - ((52 * winheight(0) + 32) / 65)
|
||||
let s:l = 53 - ((34 * winheight(0) + 32) / 65)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
keepjumps exe s:l
|
||||
normal! zt
|
||||
keepjumps 53
|
||||
normal! 026|
|
||||
normal! 0
|
||||
wincmd w
|
||||
argglobal
|
||||
if bufexists(fnamemodify("vm/asm.c", ":p")) | buffer vm/asm.c | else | edit vm/asm.c | endif
|
||||
@ -212,40 +209,15 @@ setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let &fdl = &fdl
|
||||
let s:l = 178 - ((18 * winheight(0) + 32) / 65)
|
||||
let s:l = 265 - ((36 * winheight(0) + 32) / 65)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
keepjumps exe s:l
|
||||
normal! zt
|
||||
keepjumps 178
|
||||
normal! 013|
|
||||
keepjumps 265
|
||||
normal! 032|
|
||||
wincmd w
|
||||
argglobal
|
||||
if bufexists(fnamemodify("vm/vm.c", ":p")) | buffer vm/vm.c | else | edit vm/vm.c | endif
|
||||
if &buftype ==# 'terminal'
|
||||
silent file vm/vm.c
|
||||
endif
|
||||
balt vm/asm.c
|
||||
setlocal fdm=manual
|
||||
setlocal fde=0
|
||||
setlocal fmr={{{,}}}
|
||||
setlocal fdi=#
|
||||
setlocal fdl=0
|
||||
setlocal fml=1
|
||||
setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let &fdl = &fdl
|
||||
let s:l = 104 - ((1 * winheight(0) + 32) / 65)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
keepjumps exe s:l
|
||||
normal! zt
|
||||
keepjumps 104
|
||||
normal! 043|
|
||||
wincmd w
|
||||
2wincmd w
|
||||
exe 'vert 1resize ' . ((&columns * 73 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 86 + 128) / 256)
|
||||
exe 'vert 3resize ' . ((&columns * 95 + 128) / 256)
|
||||
exe 'vert 1resize ' . ((&columns * 87 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 168 + 128) / 256)
|
||||
tabnext
|
||||
edit vm/asm.c
|
||||
let s:save_splitbelow = &splitbelow
|
||||
@ -264,9 +236,10 @@ set winminheight=0
|
||||
set winheight=1
|
||||
set winminwidth=0
|
||||
set winwidth=1
|
||||
exe 'vert 1resize ' . ((&columns * 119 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 136 + 128) / 256)
|
||||
exe 'vert 1resize ' . ((&columns * 127 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 128 + 128) / 256)
|
||||
argglobal
|
||||
balt vm/asm.h
|
||||
setlocal fdm=manual
|
||||
setlocal fde=0
|
||||
setlocal fmr={{{,}}}
|
||||
@ -277,11 +250,11 @@ setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let &fdl = &fdl
|
||||
let s:l = 354 - ((61 * winheight(0) + 32) / 65)
|
||||
let s:l = 265 - ((35 * winheight(0) + 32) / 65)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
keepjumps exe s:l
|
||||
normal! zt
|
||||
keepjumps 354
|
||||
keepjumps 265
|
||||
normal! 031|
|
||||
wincmd w
|
||||
argglobal
|
||||
@ -300,15 +273,15 @@ setlocal fdn=20
|
||||
setlocal fen
|
||||
silent! normal! zE
|
||||
let &fdl = &fdl
|
||||
let s:l = 423 - ((31 * winheight(0) + 32) / 65)
|
||||
let s:l = 123 - ((48 * winheight(0) + 32) / 65)
|
||||
if s:l < 1 | let s:l = 1 | endif
|
||||
keepjumps exe s:l
|
||||
normal! zt
|
||||
keepjumps 423
|
||||
normal! 019|
|
||||
keepjumps 123
|
||||
normal! 0
|
||||
wincmd w
|
||||
exe 'vert 1resize ' . ((&columns * 119 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 136 + 128) / 256)
|
||||
exe 'vert 1resize ' . ((&columns * 127 + 128) / 256)
|
||||
exe 'vert 2resize ' . ((&columns * 128 + 128) / 256)
|
||||
tabnext 3
|
||||
set stal=1
|
||||
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
|
||||
|
111
vm/asm.c
111
vm/asm.c
@ -43,6 +43,22 @@ Line s_jmp_l(int op1_label)
|
||||
.op1 = (Ex) { .label = op1_label },
|
||||
};
|
||||
}
|
||||
Line s_jnz_l(Reg op1_reg, int op2_label)
|
||||
{
|
||||
return (Line) {
|
||||
.ty = LineTy_Jnz_Label,
|
||||
.op1 = (Ex) { .reg = (uint16_t)op1_reg },
|
||||
.op2 = (Ex) { .label = op2_label },
|
||||
};
|
||||
}
|
||||
Line s_cmp_i(Reg op1_reg, uint16_t op2_imm)
|
||||
{
|
||||
return (Line) {
|
||||
.ty = LineTy_Cmp_Imm,
|
||||
.op1 = (Ex) { .reg = (uint16_t)op1_reg },
|
||||
.op2 = (Ex) { .imm = op2_imm },
|
||||
};
|
||||
}
|
||||
Line s_mov8_mr_r(Reg dst_reg, Reg op2_reg)
|
||||
{
|
||||
return (Line) {
|
||||
@ -179,6 +195,8 @@ static inline uint16_t linety_arithm_ins(LineTy ty);
|
||||
|
||||
void assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
|
||||
{
|
||||
bool debug = false;
|
||||
|
||||
uint16_t ip = 0;
|
||||
|
||||
typedef struct {
|
||||
@ -202,8 +220,11 @@ void assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
|
||||
out[ip++] = 0; \
|
||||
}
|
||||
|
||||
printf("assembling...\n");
|
||||
printf("ip op n data...\n");
|
||||
if (debug) {
|
||||
printf("assembling...\n");
|
||||
printf("ip op n data...\n");
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < lines_size; ++i) {
|
||||
bool is_label = false;
|
||||
bool is_data = false;
|
||||
@ -239,10 +260,37 @@ void assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
|
||||
break;
|
||||
}
|
||||
case LineTy_Jmp_Label: {
|
||||
int op1 = line->op1.label;
|
||||
|
||||
uint32_t ins = Op_Jmp;
|
||||
set_is_imm(&ins);
|
||||
out[ip++] = (uint16_t)ins;
|
||||
ADD_LABEL(line->op1.label);
|
||||
ADD_LABEL(op1);
|
||||
break;
|
||||
}
|
||||
case LineTy_Jnz_Label: {
|
||||
uint16_t op1 = line->op1.reg;
|
||||
int op2 = line->op2.label;
|
||||
|
||||
uint32_t ins = Op_Jnz;
|
||||
set_is_imm(&ins);
|
||||
add_op1_reg(&ins, op1);
|
||||
|
||||
out[ip++] = (uint16_t)ins;
|
||||
ADD_LABEL(op2);
|
||||
break;
|
||||
}
|
||||
case LineTy_Cmp_Imm: {
|
||||
uint16_t op1 = line->op1.reg;
|
||||
uint16_t op2 = line->op2.imm;
|
||||
|
||||
uint32_t ins = Op_Cmp;
|
||||
set_is_imm(&ins);
|
||||
add_op1_reg(&ins, op1);
|
||||
|
||||
out[ip++] = (uint16_t)ins;
|
||||
out[ip++] = op2;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
case LineTy_Mov8_MemReg_Reg: {
|
||||
@ -431,24 +479,28 @@ void assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_label) {
|
||||
printf("%02x %-5s %d",
|
||||
ins_ip * 2,
|
||||
is_data ? "data" : op_str(out[ins_ip] & 0x3f),
|
||||
ip - ins_ip);
|
||||
for (uint16_t i = 0; i < ip - ins_ip; ++i) {
|
||||
printf(" %02x %c%c%c%c %c%c%c%c %02x %c%c%c%c %c%c%c%c ",
|
||||
out[ins_ip + i] & 0xff,
|
||||
fmt_binary(out[ins_ip + i] & 0xff),
|
||||
out[ins_ip + i] >> 8,
|
||||
fmt_binary(out[ins_ip + i] >> 8));
|
||||
if (debug) {
|
||||
if (!is_label) {
|
||||
printf("%02x %-5s %d",
|
||||
ins_ip * 2,
|
||||
is_data ? "data" : op_str(out[ins_ip] & 0x3f),
|
||||
ip - ins_ip);
|
||||
for (uint16_t i = 0; i < ip - ins_ip; ++i) {
|
||||
printf(" %02x %c%c%c%c %c%c%c%c %02x %c%c%c%c %c%c%c%c ",
|
||||
out[ins_ip + i] & 0xff,
|
||||
fmt_binary(out[ins_ip + i] & 0xff),
|
||||
out[ins_ip + i] >> 8,
|
||||
fmt_binary(out[ins_ip + i] >> 8));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf("resolving...\n");
|
||||
printf(" l ip v data\n");
|
||||
if (debug) {
|
||||
printf("resolving...\n");
|
||||
printf(" l ip v data\n");
|
||||
}
|
||||
for (size_t i = 0; i < unres_labels_size; ++i) {
|
||||
bool found = false;
|
||||
for (size_t j = 0; j < res_labels_size; ++j) {
|
||||
@ -456,15 +508,18 @@ void assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
|
||||
out[unres_labels[i].ptr] = res_labels[j].ip;
|
||||
found = true;
|
||||
|
||||
printf("%2d %02x %02x %02x %c%c%c%c %c%c%c%c %02x %c%c%c%c "
|
||||
"%c%c%c%c\n",
|
||||
res_labels[j].label,
|
||||
unres_labels[i].ptr * 2,
|
||||
res_labels[j].ip,
|
||||
out[unres_labels[i].ptr] & 0xff,
|
||||
fmt_binary(out[unres_labels[i].ptr] & 0xff),
|
||||
out[unres_labels[i].ptr] >> 8,
|
||||
fmt_binary(out[unres_labels[i].ptr] >> 8));
|
||||
if (debug) {
|
||||
printf(
|
||||
"%2d %02x %02x %02x %c%c%c%c %c%c%c%c %02x %c%c%c%c "
|
||||
"%c%c%c%c\n",
|
||||
res_labels[j].label,
|
||||
unres_labels[i].ptr * 2,
|
||||
res_labels[j].ip,
|
||||
out[unres_labels[i].ptr] & 0xff,
|
||||
fmt_binary(out[unres_labels[i].ptr] & 0xff),
|
||||
out[unres_labels[i].ptr] >> 8,
|
||||
fmt_binary(out[unres_labels[i].ptr] >> 8));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -474,7 +529,9 @@ void assemble_to_binary(uint16_t* out, const Line* lines, size_t lines_size)
|
||||
unres_labels[i].label);
|
||||
}
|
||||
}
|
||||
printf("done!\n");
|
||||
if (debug) {
|
||||
printf("done!\n");
|
||||
}
|
||||
}
|
||||
|
||||
static inline void add_dst_reg(uint32_t* ins, uint16_t reg)
|
||||
|
4
vm/asm.h
4
vm/asm.h
@ -11,6 +11,8 @@ typedef enum {
|
||||
LineTy_Nop,
|
||||
LineTy_Hlt,
|
||||
LineTy_Jmp_Label,
|
||||
LineTy_Jnz_Label,
|
||||
LineTy_Cmp_Imm,
|
||||
LineTy_Mov8_MemReg_Reg,
|
||||
LineTy_Mov8_MemImm_Imm,
|
||||
LineTy_Mov8_MemImm_Reg,
|
||||
@ -55,6 +57,8 @@ Line s_data_l(int label);
|
||||
Line s_nop(void);
|
||||
Line s_hlt(void);
|
||||
Line s_jmp_l(int op1_label);
|
||||
Line s_jnz_l(Reg op1_reg, int op2_label);
|
||||
Line s_cmp_i(Reg op1_reg, uint16_t op2_imm);
|
||||
Line s_mov8_mr_r(Reg dst_reg, Reg op2_reg);
|
||||
Line s_mov8_mi_i(uint16_t dst_imm, uint16_t op2_imm);
|
||||
Line s_mov8_mi_r(uint16_t dst_imm, Reg op2_reg);
|
||||
|
326
vm/main.c
326
vm/main.c
@ -183,13 +183,14 @@ void sdldevice_destroy(SdlDevice* device)
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
extern const bool charset[][ch_height][ch_width];
|
||||
extern const uint64_t charset[];
|
||||
|
||||
void sdldevice_set_char(IODevice* io_device, uint16_t offset, uint8_t value)
|
||||
{
|
||||
// printf("value = %d '%c', offset = %d\n", value, value, offset);
|
||||
if (!((value >= 'A' && value <= 'Z') || value == ' '))
|
||||
if (!((value >= 'A' && value <= 'Z') || value == ' ')) {
|
||||
printf("sdldevice: invalid char value = %d\n", value);
|
||||
return;
|
||||
}
|
||||
|
||||
SdlDevice* device = io_device->self;
|
||||
pthread_mutex_lock(&device->mutex);
|
||||
@ -206,7 +207,9 @@ void sdldevice_set_char(IODevice* io_device, uint16_t offset, uint8_t value)
|
||||
|
||||
for (int ch_y = 0; ch_y < ch_height; ++ch_y) {
|
||||
for (int ch_x = 0; ch_x < ch_width; ++ch_x) {
|
||||
bool ch = charset[value][ch_y][ch_x];
|
||||
bool ch
|
||||
= charset[value] >> (ch_y * ch_width + (ch_width - ch_x - 1))
|
||||
& 1;
|
||||
|
||||
for (int px_y = 0; px_y < px_height; ++px_y) {
|
||||
for (int px_x = 0; px_x < px_width; ++px_x) {
|
||||
@ -385,6 +388,10 @@ int main(void)
|
||||
int main_loop = label_ids++;
|
||||
int interrupt_table = label_ids++;
|
||||
int keyboard_interrupt = label_ids++;
|
||||
int keyboard_interrupt_0 = label_ids++;
|
||||
int keyboard_interrupt_1 = label_ids++;
|
||||
int keyboard_interrupt_2 = label_ids++;
|
||||
int keyboard_interrupt_3 = label_ids++;
|
||||
int screen_x = label_ids++;
|
||||
int screen_y = label_ids++;
|
||||
|
||||
@ -426,6 +433,15 @@ int main(void)
|
||||
s_in_i(R0, 0),
|
||||
s_add_i(R0, R0, 'A' - 4),
|
||||
|
||||
s_cmp_i(R0, 105),
|
||||
s_mov16_r_r(R1, Rfl),
|
||||
s_and_i(R1, R1, 1 << Fl_Eq),
|
||||
s_jnz_l(R1, keyboard_interrupt_0),
|
||||
s_jmp_l(keyboard_interrupt_1),
|
||||
L(keyboard_interrupt_0),
|
||||
s_mov16_r_i(R0, ' '),
|
||||
s_jmp_l(keyboard_interrupt_1),
|
||||
L(keyboard_interrupt_1),
|
||||
s_mov16_r_ml(R1, screen_x),
|
||||
s_add_i(R1, R1, 0x0c00),
|
||||
s_mov8_mr_r(R1, R0),
|
||||
@ -477,278 +493,32 @@ const char* __asan_default_options(void)
|
||||
return "detect_leaks=0";
|
||||
}
|
||||
|
||||
#define _ false,
|
||||
#define t true,
|
||||
|
||||
const bool charset[][ch_height][ch_width] = {
|
||||
[' '] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
},
|
||||
['A'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
},
|
||||
['B'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t t t _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t t t t _ _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t _ _ },
|
||||
},
|
||||
['C'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ _ t t t t _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ _ t t t t _ _ },
|
||||
},
|
||||
['D'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t t t t _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t _ _ },
|
||||
},
|
||||
['E'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
},
|
||||
['F'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ t t t t _ _ _ },
|
||||
{ _ t t t t _ _ _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
},
|
||||
['G'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ t t _ t t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
},
|
||||
['H'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
},
|
||||
['I'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
},
|
||||
['J'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ _ _ _ _ t t _ },
|
||||
{ _ _ _ _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ _ t t t t _ _ },
|
||||
},
|
||||
['K'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ t t t _ },
|
||||
{ _ t t t t t _ _ },
|
||||
{ _ t t t t t _ _ },
|
||||
{ _ t t _ t t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
},
|
||||
['L'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
},
|
||||
['M'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ t t t _ _ t t t },
|
||||
{ t t t t t t t t },
|
||||
{ t t _ t t _ t t },
|
||||
{ t t _ _ _ _ t t },
|
||||
{ t t _ _ _ _ t t },
|
||||
{ t t _ _ _ _ t t },
|
||||
{ t t _ _ _ _ t t },
|
||||
},
|
||||
['N'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t t _ t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t _ t t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
},
|
||||
['O'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ _ t t t t _ _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ _ t t t t _ _ },
|
||||
},
|
||||
['P'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t t t t _ _ },
|
||||
{ _ t t t t t _ _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t _ _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
},
|
||||
['Q'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ _ t t t t _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ t t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ _ t t t t t t },
|
||||
},
|
||||
['R'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t t t t _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t _ _ },
|
||||
{ _ t t _ t t _ _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
},
|
||||
['S'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ _ t t t t _ _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ _ _ _ },
|
||||
{ _ _ t t t t _ _ },
|
||||
{ _ _ _ _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ _ t t t t _ _ },
|
||||
},
|
||||
['T'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
},
|
||||
['U'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ _ t t t t _ _ },
|
||||
},
|
||||
['V'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ _ t t t t _ _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
},
|
||||
['W'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ t t _ _ _ _ t t },
|
||||
{ t t _ _ _ _ t t },
|
||||
{ t t _ _ _ _ t t },
|
||||
{ t t _ t t _ t t },
|
||||
{ t t _ t t _ t t },
|
||||
{ t t t t t t t t },
|
||||
{ t t t _ _ t t t },
|
||||
},
|
||||
['X'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ _ t t t t _ _ },
|
||||
{ _ _ t t t t _ _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
},
|
||||
['Y'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ t t _ _ t t _ },
|
||||
{ _ _ t t t t _ _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
},
|
||||
['Z'] = {
|
||||
{ _ _ _ _ _ _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ _ _ _ t t _ _ },
|
||||
{ _ _ _ t t _ _ _ },
|
||||
{ _ _ t t _ _ _ _ },
|
||||
{ _ t t t t t t _ },
|
||||
{ _ t t t t t t _ },
|
||||
},
|
||||
const uint64_t charset[] = {
|
||||
[' '] = 0x0000000000000000,
|
||||
['A'] = 0x66667E66667E1800,
|
||||
['B'] = 0x7C7E667C667E7800,
|
||||
['C'] = 0x3C7E6060607E3C00,
|
||||
['D'] = 0x7C7E6666667E7C00,
|
||||
['E'] = 0x7E7E607E607E7E00,
|
||||
['F'] = 0x60607878607E7E00,
|
||||
['G'] = 0x7E7E666E607E7E00,
|
||||
['H'] = 0x6666667E7E666600,
|
||||
['I'] = 0x7E7E1818187E7E00,
|
||||
['J'] = 0x3C7E6606067E7E00,
|
||||
['K'] = 0x666E7C7C6E666600,
|
||||
['L'] = 0x7E7E606060606000,
|
||||
['M'] = 0xC3C3C3C3DBFFE700,
|
||||
['N'] = 0x6666666E7E766600,
|
||||
['O'] = 0x3C66666666663C00,
|
||||
['P'] = 0x60607C7E667C7C00,
|
||||
['Q'] = 0x3F7E6E66667E3C00,
|
||||
['R'] = 0x666C7C7E667E7C00,
|
||||
['S'] = 0x3C66063C60663C00,
|
||||
['T'] = 0x18181818187E7E00,
|
||||
['U'] = 0x3C7E666666666600,
|
||||
['V'] = 0x183C7E6666666600,
|
||||
['W'] = 0xE7FFDBDBC3C3C300,
|
||||
['X'] = 0x6666663C3C666600,
|
||||
['Y'] = 0x181818183C666600,
|
||||
['Z'] = 0x7E7E30180C7E7E00,
|
||||
};
|
||||
|
27
vm/vm.c
27
vm/vm.c
@ -96,6 +96,7 @@ void vm_start(Drive* boot_drive, IODevice* io_device)
|
||||
case Op_Jnz: {
|
||||
uint16_t op1 = ins_op1(vm, ins);
|
||||
uint16_t op2 = ins_op2_or_imm(vm, ins);
|
||||
|
||||
if (op1 != 0) {
|
||||
*rip = op2;
|
||||
}
|
||||
@ -103,15 +104,33 @@ void vm_start(Drive* boot_drive, IODevice* io_device)
|
||||
}
|
||||
case Op_Test: {
|
||||
uint16_t op1 = ins_op1(vm, ins);
|
||||
*rfl &= (uint16_t)~((op1 == 0 ? 1 : 0) << Fl_Zero);
|
||||
|
||||
if (op1 == 0) {
|
||||
*rfl |= 1u << Fl_Zero;
|
||||
} else {
|
||||
*rfl &= (uint16_t)~(1u << Fl_Zero);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Op_Cmp: {
|
||||
uint16_t op1 = ins_op1(vm, ins);
|
||||
uint16_t op2 = ins_op2_or_imm(vm, ins);
|
||||
*rfl &= (uint16_t)~((op1 == op2 ? 1 : 0) << Fl_Eq
|
||||
& (op1 < op2 ? 1 : 0) << Fl_Be
|
||||
& ((int16_t)op1 < (int16_t)op2 ? 1 : 0) << Fl_Lt);
|
||||
|
||||
if (op1 == op2) {
|
||||
*rfl |= 1u << Fl_Eq;
|
||||
} else {
|
||||
*rfl &= (uint16_t)~(1u << Fl_Eq);
|
||||
}
|
||||
if (op1 < op2) {
|
||||
*rfl |= 1u << Fl_Be;
|
||||
} else {
|
||||
*rfl &= (uint16_t)~(1u << Fl_Be);
|
||||
}
|
||||
if ((int16_t)op1 < (int16_t)op2) {
|
||||
*rfl |= 1u << Fl_Lt;
|
||||
} else {
|
||||
*rfl &= (uint16_t)~(1u << Fl_Lt);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Op_Mov8: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user