Fixes. Debugger improved.

This commit is contained in:
2017-02-01 19:49:26 +01:00
parent ad4b15514d
commit 0864cdcf89
9 changed files with 132 additions and 58 deletions

View File

@@ -14,5 +14,5 @@ data/*
*.dll *.dll
.DS_Store .DS_Store
trick.ini trick.ini
*.bin test.bin

View File

@@ -35,4 +35,13 @@ void register_constants() {
parser_register_constant("paper_teal", 0xD0); parser_register_constant("paper_teal", 0xD0);
parser_register_constant("paper_gray", 0xE0); parser_register_constant("paper_gray", 0xE0);
parser_register_constant("paper_black2", 0xF0); parser_register_constant("paper_black2", 0xF0);
parser_register_constant("btn_any", 0x00);
parser_register_constant("btn_up", 0x01);
parser_register_constant("btn_down", 0x02);
parser_register_constant("btn_left", 0x03);
parser_register_constant("btn_right", 0x04);
parser_register_constant("btn_a", 0x05);
parser_register_constant("btn_b", 0x06);
parser_register_constant("btn_menu", 0x07);
} }

View File

@@ -8,6 +8,7 @@ typedef unsigned char byte;
typedef unsigned short word; typedef unsigned short word;
static SDL_Window* debug_window = nullptr; static SDL_Window* debug_window = nullptr;
static Uint32 debug_window_id;
static SDL_Renderer* debug_renderer = nullptr; static SDL_Renderer* debug_renderer = nullptr;
static SDL_Texture* debug_texture = nullptr; static SDL_Texture* debug_texture = nullptr;
static SDL_Rect src, dst; static SDL_Rect src, dst;
@@ -15,6 +16,8 @@ static Uint8 ink[4];
static Uint8 paper[4]; static Uint8 paper[4];
static unsigned char* debug_mem = nullptr; static unsigned char* debug_mem = nullptr;
static bool breakpoints[65536] {false};
static unsigned short* rX; static unsigned short* rX;
static unsigned char* rY; static unsigned char* rY;
static unsigned char* rZ; static unsigned char* rZ;
@@ -144,21 +147,25 @@ static void debug_print_basic(byte offset) {
return; return;
} }
int line = offset; int line = offset;
int l = 0;
if (lines[*pc] >= 35) line = lines[*pc] + 30;
int row = 0; int row = 0;
char* prog = program; char* prog = program;
if (lines[*pc] == line) { debug_set_ink(0, 0, 0); debug_fill_rect(1, 2 + line, 70, 1); debug_set_ink(255, 255, 0); } if (lines[*pc] == line) { debug_set_ink(0, 0, 0); debug_fill_rect(1, 2 + l, 70, 1); debug_set_ink(255, 255, 0); }
else debug_set_ink(255, 255, 255); else debug_set_ink(255, 255, 255);
while (line < 35 && *prog != 0) { while (line < 35 && *prog != 0) {
if (*prog == '\t') { if (*prog == '\t') {
row += 4; row += 4;
} else if (*prog == '\n') { } else if (*prog == '\n') {
row = 0; line++; row = 0; line++; l++;
if (lines[*pc] == line) { debug_set_ink(0, 0, 0); debug_fill_rect(1, 2 + line, 70, 1); debug_set_ink(255, 255, 0); } int bm = 0; while (lines[bm] < line) { bm++; }
if (breakpoints[bm]) { debug_set_ink(64, 0, 0); debug_fill_rect(1, 2 + l, 70, 1); }
if (lines[*pc] == line) { debug_set_ink(0, 0, 0); debug_fill_rect(1, 2 + l, 70, 1); debug_set_ink(255, 255, 0); }
else debug_set_ink(255, 255, 255); else debug_set_ink(255, 255, 255);
} else if (*prog == 13) { } else if (*prog == 13) {
// row++; // row++;
} else { } else {
if (row < 70) debug_draw_char(1 + row, 2 + line, *prog); if (row < 70) debug_draw_char(1 + row, 2 + l, *prog);
row++; row++;
} }
prog++; prog++;
@@ -293,7 +300,7 @@ void debug_init(unsigned char* mem) {
debug_window = SDL_CreateWindow("Definitely PaCo Debugger", 1120, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN); debug_window = SDL_CreateWindow("Definitely PaCo Debugger", 1120, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
debug_renderer = SDL_CreateRenderer(debug_window, -1, SDL_RENDERER_PRESENTVSYNC); debug_renderer = SDL_CreateRenderer(debug_window, -1, SDL_RENDERER_PRESENTVSYNC);
//SDL_RenderSetLogicalSize(debug_renderer, 152, 120); debug_window_id = SDL_GetWindowID(debug_window);
SDL_SetRenderDrawColor(debug_renderer, 128, 128, 128, 255); SDL_SetRenderDrawColor(debug_renderer, 128, 128, 128, 255);
FILE* f = fopen("font.png", "rb"); FILE* f = fopen("font.png", "rb");
@@ -321,13 +328,6 @@ void debug_update() {
debug_set_paper(128, 128, 128); debug_set_paper(128, 128, 128);
debug_clear(); debug_clear();
/* debug_set_ink(64, 64, 64);
debug_fill_rect(39, 39, 40, 20);
debug_draw_inset(39, 39, 40, 20);
debug_set_ink(0, 0, 0);
debug_print(39, 38, "DISASSEMBLY:");*/
debug_print_memory(0); debug_print_memory(0);
debug_print_asm(0); debug_print_asm(0);
debug_print_datastack(0); debug_print_datastack(0);
@@ -337,3 +337,28 @@ void debug_update() {
SDL_RenderPresent(debug_renderer); SDL_RenderPresent(debug_renderer);
} }
void debug_hide() {
debug_set_paper(128, 128, 128);
debug_clear();
SDL_RenderPresent(debug_renderer);
}
void debug_mouse_event(SDL_Event& event) {
if (event.window.windowID != debug_window_id) return;
if (event.type == SDL_MOUSEBUTTONDOWN) {
int x, y;
Uint32 buttons = SDL_GetMouseState(&x, &y);
if (x >= 8 && x <= 568 && y >= 16 && y <= 296) {
int l = (y - 16) >> 3;
int bm = 0; while (lines[bm] < l) { bm++; }
breakpoints[bm] = !breakpoints[bm];
}
debug_update();
}
}
const bool* debug_get_breakpoints() {
return breakpoints;
}

View File

@@ -1,4 +1,8 @@
#pragma once #pragma once
#include <SDL.h>
void debug_init(unsigned char* mem); void debug_init(unsigned char* mem);
void debug_update(); void debug_update();
void debug_hide();
void debug_mouse_event(SDL_Event& event);
const bool* debug_get_breakpoints();

View File

@@ -45,6 +45,7 @@ int main(int argc, char** argv) {
vm_register_in_port(21, input_data_out); vm_register_in_port(21, input_data_out);
debug_init(vm_get_memory()); debug_init(vm_get_memory());
const bool* breakpoints = debug_get_breakpoints();
bool running = false; bool running = false;
@@ -56,19 +57,36 @@ int main(int argc, char** argv) {
while (!should_quit) { while (!should_quit) {
just_pressed = SDL_SCANCODE_UNKNOWN; just_pressed = SDL_SCANCODE_UNKNOWN;
while (SDL_PollEvent(&sdlEvent)) { while (SDL_PollEvent(&sdlEvent)) {
if (sdlEvent.type == SDL_WINDOWEVENT_CLOSE) { should_quit = true; break; } switch (sdlEvent.type) {
if (sdlEvent.type == SDL_QUIT) { should_quit = true; break; } case SDL_WINDOWEVENT:
else if (sdlEvent.type == SDL_KEYDOWN) { switch (sdlEvent.window.event) {
case SDL_WINDOWEVENT_CLOSE:
should_quit = true; break;
}
break;
case SDL_QUIT:
should_quit = true; break;
case SDL_KEYDOWN:
//anykey = true; //anykey = true;
just_pressed = sdlEvent.key.keysym.scancode; just_pressed = sdlEvent.key.keysym.scancode;
if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_SPACE) { anykey = true; } if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_SPACE) { anykey = true; }
if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_ESCAPE) { should_quit = true; } if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_ESCAPE) { should_quit = true; }
if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_F10) { vm_big_step(); debug_update(); } if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_F10) { vm_big_step(); debug_update(); }
if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_F11) { vm_step(); debug_update(); } if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_F11) { vm_step(); debug_update(); }
if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_F5) { running = !running; if (!running) debug_update(); } if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_F5) { running = !running; if (!running) debug_update(); else debug_hide(); }
break;
case SDL_KEYUP:
if (sdlEvent.key.keysym.scancode == SDL_SCANCODE_SPACE) { anykey = false; }
case SDL_MOUSEBUTTONDOWN:
debug_mouse_event(sdlEvent);
break;
} }
} }
if (running) vm_step();
if (running) {
unsigned short pc = vm_step();
if (breakpoints[pc]) { running = false; debug_update(); }
}
//if (SDL_GetTicks() - ticks >= 15) { vdp_flip(); ticks = SDL_GetTicks(); } //if (SDL_GetTicks() - ticks >= 15) { vdp_flip(); ticks = SDL_GetTicks(); }
} }

BIN
rom.bin Normal file

Binary file not shown.

View File

@@ -1,24 +1,40 @@
border INK_BLACK BORDER INK_BLACK
color INK_WHITE + PAPER_BLACK COLOR INK_WHITE + PAPER_BLACK
clrscr CLRSCR
locate 4 2 print chr &h87, chr &h85, chr &h87, chr &h85, chr &h87, chr &h85, chr &h87, chr &h81 LOCATE 4 2 PRINT CHR &h87, CHR &h85, CHR &h87, CHR &h85, CHR &h87, CHR &h85, CHR &h87, CHR &h81
locate 4 3 print chr &h85, chr &h85, chr &h85, chr &h85, chr &h85, chr &h85, chr &h85, chr &h84 LOCATE 4 3 PRINT CHR &h85, CHR &h85, CHR &h85, CHR &h85, CHR &h85, CHR &h85, CHR &h85, CHR &h84
locate 4 4 print chr &h87, chr &h81, chr &h8D, chr &h85, chr &h85, chr &h85, chr &h8D, chr &h85 LOCATE 4 4 PRINT CHR &h87, CHR &h81, CHR &h8D, CHR &h85, CHR &h85, CHR &h85, CHR &h8D, CHR &h85
locate 3 8 print "PRESS SPACE" W = 0
updatescr MENU_BLINK:
x = 8 LOCATE 3 8 PRINT "PRESS CTRL"
dx = 1 LOCATE 4 9 PRINT "TO PLAY"
setsprite 0 &HF9 INK_RED UPDATESCR
peiv: INC W
putsprite 0 x 10 IF KEYPRESSED BTN_A THEN GOTO MAIN_GAME END
updatescr IF W < 25 THEN
x = x + dx GOTO MENU_BLINK
if x = 8 or x = 128 then dx = -dx end END
if anykey then goto continuar end MENU_BLINK2:
goto peiv LOCATE 3 8 PRINT " "
continuar: LOCATE 4 9 PRINT " "
clrscr UPDATESCR
locate 0 0 print "Ok" INC W
updatescr IF KEYPRESSED BTN_A THEN GOTO MAIN_GAME END
ttt: IF W < 50 THEN GOTO MENU_BLINK2 END
goto ttt W = 0
GOTO MENU_BLINK
MAIN_GAME:
CLRSCR
GOSUB PINTA_RED
LOCATE 6 1 PRINT "0"
LOCATE 9 1 PRINT "0"
UPDATESCR
GOTO MAIN_GAME
PINTA_RED:
PUTCHAR 7 0 &HD1 INK_WHITE + PAPER_BLACK
PUTCHAR 7 2 &HD1 INK_WHITE + PAPER_BLACK
PUTCHAR 7 4 &HD1 INK_WHITE + PAPER_BLACK
PUTCHAR 7 6 &HD1 INK_WHITE + PAPER_BLACK
PUTCHAR 7 8 &HD1 INK_WHITE + PAPER_BLACK
PUTCHAR 7 10 &HD1 INK_WHITE + PAPER_BLACK
RETURN

30
vm.cpp
View File

@@ -161,10 +161,10 @@ void vm_init(const char* filename) {
inline unsigned short WORD() { vm_pc += 2; return vm_program[vm_pc - 2] + (vm_program[vm_pc - 1] << 8); } inline unsigned short WORD() { vm_pc += 2; return vm_program[vm_pc - 2] + (vm_program[vm_pc - 1] << 8); }
const bool vm_step() { const unsigned short vm_step() {
if (sleeping) return false; if (sleeping) return vm_pc;
char a, b, c; unsigned char a, b, c;
OPS opcode = (OPS)vm_program[vm_pc++]; OPS opcode = (OPS)vm_program[vm_pc++];
switch (opcode) { switch (opcode) {
@@ -214,8 +214,8 @@ const bool vm_step() {
case OP_ADD: GRAB(ds); PUSH(ds, a + b); vm_cycles++; break; case OP_ADD: GRAB(ds); PUSH(ds, a + b); vm_cycles++; break;
case OP_SUB: GRAB(ds); PUSH(ds, a - b); vm_cycles++; break; case OP_SUB: GRAB(ds); PUSH(ds, a - b); vm_cycles++; break;
case OP_MUL: GRAB(ds); PUSH(ds, a * b); vm_cycles++; break; case OP_MUL: GRAB(ds); PUSH(ds, a * b); vm_cycles++; break;
case OP_DIV: GRAB(ds); PUSH(ds, a / b); vm_cycles++; break; case OP_DIV: GRAB(ds); PUSH(ds, b / a); vm_cycles++; break;
case OP_MOD: GRAB(ds); PUSH(ds, a % b); vm_cycles++; break; case OP_MOD: GRAB(ds); PUSH(ds, b % a); vm_cycles++; break;
case OP_AND: GRAB(ds); PUSH(ds, a & b); vm_cycles++; break; case OP_AND: GRAB(ds); PUSH(ds, a & b); vm_cycles++; break;
case OP_OR: GRAB(ds); PUSH(ds, a | b); vm_cycles++; break; case OP_OR: GRAB(ds); PUSH(ds, a | b); vm_cycles++; break;
case OP_NOT: a = POP(ds); PUSH(ds, !a); vm_cycles++; break; case OP_NOT: a = POP(ds); PUSH(ds, !a); vm_cycles++; break;
@@ -231,22 +231,24 @@ const bool vm_step() {
vm_cycles++; break; vm_cycles++; break;
case OP_EQ: GRAB(ds); PUSH(ds, a == b); vm_cycles++; break; case OP_EQ: GRAB(ds); PUSH(ds, a == b); vm_cycles++; break;
case OP_NEQ: GRAB(ds); PUSH(ds, a != b); vm_cycles++; break; case OP_NEQ: GRAB(ds); PUSH(ds, a != b); vm_cycles++; break;
case OP_LT: GRAB(ds); PUSH(ds, a < b); vm_cycles++; break; case OP_LT:
case OP_GT: GRAB(ds); PUSH(ds, a > b); vm_cycles++; break; GRAB(ds);
case OP_LEQ: GRAB(ds); PUSH(ds, a <= b); vm_cycles++; break; PUSH(ds, b < a); vm_cycles++; break;
case OP_GEQ: GRAB(ds); PUSH(ds, a >= b); vm_cycles++; break; case OP_GT: GRAB(ds); PUSH(ds, b > a); vm_cycles++; break;
case OP_LEQ: GRAB(ds); PUSH(ds, b <= a); vm_cycles++; break;
case OP_GEQ: GRAB(ds); PUSH(ds, b >= a); vm_cycles++; break;
case OP_IN: PUSH(ds, in_ports[vm_program[vm_pc++]]()); vm_cycles++; break; case OP_IN: PUSH(ds, in_ports[vm_program[vm_pc++]]()); vm_cycles++; break;
case OP_OUT: out_ports[vm_program[vm_pc++]](POP(ds)); vm_cycles++; break; case OP_OUT: out_ports[vm_program[vm_pc++]](POP(ds)); vm_cycles++; break;
case OP_SLEEP: SDL_Delay(POP(ds) * 1000); vm_cycles++; break; case OP_SLEEP: SDL_Delay(POP(ds) * 1000); vm_cycles++; break;
} }
return false; return vm_pc;
} }
const int vm_big_step() { const unsigned short vm_big_step() {
word* lines = parser_get_lines(); word* lines = parser_get_lines();
word current_line = lines[vm_pc]-1; word current_line = lines[vm_pc];
while ((vm_pc > 32768) || (lines[vm_pc]-1 == current_line)) { vm_step(); } while ((vm_pc >= 32768) || (lines[vm_pc] == current_line)) { vm_step(); }
return false; return vm_pc;
} }
/*void vm_register_call(void(*callback)(t_stack&)) { /*void vm_register_call(void(*callback)(t_stack&)) {
external_calls[numcallbacks++] = callback; external_calls[numcallbacks++] = callback;

4
vm.h
View File

@@ -2,8 +2,8 @@
//#include "stack.h" //#include "stack.h"
void vm_init(const char* filename); void vm_init(const char* filename);
const bool vm_step(); const unsigned short vm_step();
const bool vm_big_step(); const unsigned short vm_big_step();
void vm_register_in_port(const unsigned char port, unsigned char(*callback)(void)); void vm_register_in_port(const unsigned char port, unsigned char(*callback)(void));
void vm_register_out_port(const unsigned char port, void(*callback)(const unsigned char&)); void vm_register_out_port(const unsigned char port, void(*callback)(const unsigned char&));
void vm_call_interrupt(const char num); void vm_call_interrupt(const char num);