Skip to content

Commit 12a2b82

Browse files
committed
Merge branch 'master' of git.olimp-nw.ru:cschool/Gamebox
2 parents 70d0ac3 + 6eb1dd2 commit 12a2b82

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

VirtualGameBox/AVR.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,11 @@ unsigned int AVR::popStack24() {
218218
return res;
219219
}
220220

221-
AVR::AVR(Display &display) : rbank(), io(rbank, display), display(display) {
221+
AVR::AVR(Display &display, QObject *parent)
222+
: QThread(parent), rbank(), io(rbank, display), display(display)
223+
{
222224
do_log = false;
225+
exit = false;
223226
reset();
224227
}
225228

@@ -1370,7 +1373,7 @@ void AVR::run() {
13701373
clock_t start = clock();
13711374
unsigned long long last_burst = 0;
13721375

1373-
while (true) {
1376+
while (!exit) {
13741377
tick();
13751378
if (rbank.getCycles() - last_burst >= FREQ / BURSTS_PER_SECOND) {
13761379
clock_t end = clock();
@@ -1384,3 +1387,8 @@ void AVR::run() {
13841387
}
13851388
}
13861389
}
1390+
1391+
void AVR::stop()
1392+
{
1393+
exit = true;
1394+
}

VirtualGameBox/AVR.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
#include "atmega2560.h"
88
#include "periph/Display.h"
99
#include <cstdint>
10+
#include <QWidget>
11+
12+
class AVR : public QThread
13+
{
14+
Q_OBJECT
1015

11-
class AVR {
1216
public:
1317
std::array<uint16_t, FLASH_SIZE> flash;
1418
std::array<uint8_t, SRAM_SIZE> sram;
@@ -19,6 +23,7 @@ class AVR {
1923
AVRIO io;
2024
Display &display;
2125
bool do_log;
26+
bool exit;
2227

2328
uint8_t getData(uint16_t addr);
2429

@@ -84,13 +89,14 @@ class AVR {
8489
unsigned int popStack24();
8590

8691
public:
87-
AVR(Display &display);
92+
AVR(Display &display, QObject *parent = 0);
8893

8994
void reset();
9095

9196
unsigned int tick();
9297

9398
void run();
99+
void stop();
94100
};
95101

96102
#endif // AVR_H

VirtualGameBox/Window.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ Window::Window(std::vector<uint8_t> &buf)
6161
(((uint8_t)buf[i + 1]) << 8) | (uint8_t)buf[i];
6262
}
6363

64-
new std::thread(&AVR::run, &avr);
64+
avr.start();
65+
}
66+
67+
Window::~Window()
68+
{
69+
avr.stop();
6570
}
6671

6772
void Window::updateScreen()

VirtualGameBox/Window.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Window : public QWidget
2828

2929
public:
3030
Window(std::vector<uint8_t> &buf);
31+
virtual ~Window();
3132

3233
private slots:
3334
void updateScreen();

game/Snail.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static void Snail_prepare()
316316
data->y = 0;
317317
data->btn_timeout = 0;
318318
data->state = GS_MENU;
319-
data->menu = menu_setup(level_menu, 0, 0, BLUE_DARK);
319+
data->menu = menu_setup(level_menu);
320320
}
321321

322322
void Snail_move(int dx, int dy)
@@ -397,6 +397,7 @@ static void Snail_update(unsigned long delta)
397397
data->btn_timeout = 0;
398398
if (game_is_button_pressed(MENU))
399399
{
400+
game_draw_rect(0, 0, WIDTH, HEIGHT, BLACK);
400401
data->state = GS_MENU;
401402
return;
402403
}

0 commit comments

Comments
 (0)