Skip to content

Commit 463112a

Browse files
committed
display for Windows
1 parent abd1def commit 463112a

File tree

6 files changed

+176
-23
lines changed

6 files changed

+176
-23
lines changed

Windows/NASM/macro.o

10 KB
Binary file not shown.

Windows/include/io.inc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,42 @@ CEXTERN puts
5858
CEXTERN fputs
5959
CEXTERN fflush
6060

61+
CEXTERN update
62+
%macro updateDisplay 1.nolist
63+
sasmMacroFunc
64+
push eax
65+
push ecx
66+
push edx
67+
ALIGN_STACK 4
68+
push %1
69+
call update
70+
UNALIGN_STACK
71+
pop edx
72+
pop ecx
73+
pop eax
74+
sasmMacroFuncE
75+
%endmacro
76+
77+
CEXTERN setup
78+
%macro setupDisplay 4.nolist
79+
sasmMacroFunc
80+
push eax
81+
push ecx
82+
push edx
83+
ALIGN_STACK 16
84+
push %4
85+
push %3
86+
push %2
87+
push %1
88+
call setup
89+
UNALIGN_STACK
90+
pop edx
91+
pop ecx
92+
pop eax
93+
sasmMacroFuncE
94+
%endmacro
95+
96+
6197
CEXTERN get_stdin
6298
CEXTERN get_stdout
6399

displayWindow.cpp

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,13 @@ DisplayWindow::DisplayWindow(QWidget *parent) :
6565
this->setFixedSize(500,525);
6666
}
6767

68-
void DisplayWindow::changeDisplay(int msgid){
68+
void DisplayWindow::changeDisplay(int msgid, HANDLE hCreateNamedPipe){
6969
this->setFixedSize(537,562);
7070
displayPicture = new QImage(512, 512, QImage::Format_RGB32);
7171
displayPicture->fill(qRgb(255, 255, 255));
7272
displayImageLabel->setPixmap(QPixmap::fromImage(*displayPicture));
7373
buffer.resize(512*512);
7474
memset(buffer.data(), 0xff, 512*512);
75-
#ifdef Q_OS_WIN32
76-
#else
7775
this->msgid = msgid;
7876
res_x = 512;
7977
res_y = 512;
@@ -84,7 +82,67 @@ void DisplayWindow::changeDisplay(int msgid){
8482
displayPicture->fill(qRgb(0, 0, 0));
8583
displayImageLabel->setPixmap(QPixmap::fromImage(*displayPicture));
8684
programExecutionTime.start();
87-
while(1){
85+
#ifdef Q_OS_WIN32
86+
if(!ConnectNamedPipe(hCreateNamedPipe, NULL))
87+
emit printLog(QString("Connection Failed with Error (")+QString::number(GetLastError())+")\n", Qt::red);
88+
while(1){
89+
DWORD dwNoBytesRead;
90+
BOOL readSuccess = ReadFile(
91+
hCreateNamedPipe,
92+
message.mesg_text,
93+
8184,
94+
&dwNoBytesRead,
95+
NULL);
96+
if(!readSuccess){
97+
if(GetLastError()!=109)
98+
emit printLog(QString("Read Failed with Error (")+QString::number(GetLastError())+")\n", Qt::red);
99+
break;
100+
}
101+
if(message.mesg_text[0]==3){
102+
res_x = message.mesg_text[1];
103+
res_y = message.mesg_text[5];
104+
for(int i = 1; i < 4; i++){
105+
res_x += message.mesg_text[1+i] << (8*i);
106+
res_y += message.mesg_text[5+i] << (8*i);
107+
}
108+
mode = message.mesg_text[9];
109+
fps = message.mesg_text[10];
110+
if(mode)
111+
buffer.resize(res_x*res_y*3);
112+
else
113+
buffer.resize(res_x*res_y);
114+
displayPicture = new QImage(res_x*zoom, res_y*zoom, QImage::Format_RGB32);
115+
displayPicture->fill(qRgb(0, 0, 0));
116+
displayImageLabel->setPixmap(QPixmap::fromImage(*displayPicture));
117+
this->setFixedSize(displayPicture->size()+QSize(25,50));
118+
continue;
119+
}
120+
// display the message and print on display
121+
int needed_bytes = (mode) ? res_x*res_y*3 : res_x*res_y;
122+
for(int i = 0; i < needed_bytes; i+=8184){
123+
dwNoBytesRead = 0;
124+
BOOL readSuccess = ReadFile(
125+
hCreateNamedPipe,
126+
message.mesg_text,
127+
8184,
128+
&dwNoBytesRead,
129+
NULL);
130+
if(!readSuccess){
131+
emit printLog(QString("Read Failed with Error (")+QString::number(GetLastError())+")\n", Qt::red);
132+
break;
133+
}
134+
memcpy(buffer.data()+i, &message.mesg_text[0], std::min(8184, needed_bytes-i));
135+
}
136+
updateDisplay();
137+
qint64 elapsed_time = programExecutionTime.elapsed();
138+
if(elapsed_time < 1000/fps)
139+
usleep(1000/fps - elapsed_time);
140+
displayImageLabel->setPixmap(QPixmap::fromImage(*displayPicture));
141+
programExecutionTime.start();
142+
}
143+
CloseHandle(hCreateNamedPipe);
144+
#else
145+
while(1){
88146
// msgrcv to receive message
89147
msgrcv(msgid, &message, sizeof(message), 0, 0);
90148

@@ -118,19 +176,46 @@ void DisplayWindow::changeDisplay(int msgid){
118176
memcpy(buffer.data()+i, &message.mesg_text[0], std::min(8184, needed_bytes-i));
119177
}
120178
updateDisplay();
121-
qint64 elapsed_time = programExecutionTime.elapsed();
179+
qint64 elapsed_time = programExecutionTime.elapsed();
122180
if(elapsed_time < 1000/fps)
123181
usleep(1000/fps - elapsed_time);
124182
displayImageLabel->setPixmap(QPixmap::fromImage(*displayPicture));
125183
programExecutionTime.start();
126184
}
127185
msgctl(msgid, IPC_RMID, NULL);
186+
#endif
128187
emit closeDisplay();
129-
#endif
130188
}
131189

132190
void DisplayWindow::finish(int msgid){
133191
#ifdef Q_OS_WIN32
192+
/*char c[8184];
193+
c[0] = 2;
194+
HANDLE hFile = CreateFileW(
195+
L"\\\\.\\pipe\\SASMPIPE",
196+
GENERIC_WRITE,
197+
FILE_SHARE_READ | FILE_SHARE_WRITE,
198+
NULL,
199+
OPEN_EXISTING,
200+
0,
201+
NULL);
202+
if(hFile == INVALID_HANDLE_VALUE){
203+
emit printLog(QString("Could not create file object (")+QString::number(GetLastError())+")\n", Qt::red);
204+
return;
205+
}
206+
DWORD dwNoBytesWrote = 0;
207+
BOOL writeSuccess = WriteFile(
208+
hFile,
209+
c,
210+
sizeof(c),
211+
&dwNoBytesWrote,
212+
NULL);
213+
if(!writeSuccess){
214+
emit printLog(QString("Could not write to file (")+QString::number(GetLastError())+")\n", Qt::red);
215+
}
216+
if(!FlushFileBuffers(hFile)){
217+
emit printLog(QString("Could not flush the file (")+QString::number(GetLastError())+")\n", Qt::red);
218+
}*/
134219
#else
135220
mesg_buffer end;
136221
end.mesg_type = 2;

displayWindow.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,27 @@
5252
#include <unistd.h>
5353
#include <vector>
5454
#ifdef Q_OS_WIN32
55+
#include <windows.h>
56+
#include <conio.h>
57+
#include <tchar.h>
5558
#else
5659
#include <sys/ipc.h>
5760
#include <sys/msg.h>
5861
#endif
62+
#define BUF_SIZE 256
5963

6064
class DisplayWindow : public QWidget
6165
{
6266
Q_OBJECT
6367
public:
6468
struct mesg_buffer {
6569
long mesg_type;
66-
uint8_t mesg_text[8184];
70+
char mesg_text[8184];
6771
} message;
6872

6973
explicit DisplayWindow(QWidget *parent = 0);
7074
~DisplayWindow();
71-
void changeDisplay(int msgid);
75+
void changeDisplay(int msgid, HANDLE hCreateNamedPipe);
7276
void finish(int msgid);
7377
void updateDisplay();
7478

@@ -94,6 +98,7 @@ void zoomSettingsChanged(int value);
9498
void displayChanged(void);
9599
void closeSignal();
96100
void closeDisplay();
101+
void printLog(QString msg, QColor color = QColor(Qt::black));
97102
};
98103

99104
#endif

mainwindow.cpp

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
** (at your option) any later version.
1313
**
1414
** SASM is distributed in the hope that it will be useful,
15-
** but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
** but WITHOUT ANY WARRANTY; without even the implieddwarranty of
1616
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1717
** GNU General Public License for more details.
1818
**
@@ -1058,19 +1058,34 @@ void MainWindow::runProgram()
10581058
runProcess->setStandardInputFile(input);
10591059

10601060
// start display
1061-
#ifdef Q_OS_WIN32
1062-
#else
10631061
if (!displayWindow) {
10641062
displayWindow = new DisplayWindow;
10651063
displayWindow->setWindowIcon(QIcon(":images/mainIcon.png"));
10661064
displayWindow->setWindowFlags(Qt::Widget | Qt::MSWindowsFixedSizeDialogHint);
10671065
displayWindow->activateWindow();
10681066
}
1069-
if (settings.value("display", false).toBool())
1070-
displayWindow->show();
1067+
if (settings.value("display", false).toBool()){
1068+
displayWindow->show();
1069+
}
1070+
#ifdef Q_OS_WIN32
1071+
// --- TODO ---
1072+
HANDLE hCreateNamedPipe = CreateNamedPipe(
1073+
TEXT("\\\\.\\pipe\\sasmpipe"),
1074+
PIPE_ACCESS_INBOUND,
1075+
PIPE_TYPE_BYTE|PIPE_READMODE_MESSAGE|PIPE_WAIT,
1076+
PIPE_UNLIMITED_INSTANCES,
1077+
8184,
1078+
8184,
1079+
0,
1080+
NULL);
1081+
if(hCreateNamedPipe == INVALID_HANDLE_VALUE){
1082+
printLog(QString("Couldnt create Pipe\n"), Qt::red);
1083+
}
1084+
consumer = new std::thread(&DisplayWindow::changeDisplay, displayWindow, -1, hCreateNamedPipe);
1085+
#else
10711086
key_t key = ftok("/tmp", 65);
10721087
msgid = msgget(key, 0666 | IPC_CREAT);
1073-
consumer = new std::thread(&DisplayWindow::changeDisplay, displayWindow, msgid);
1088+
consumer = new std::thread(&DisplayWindow::changeDisplay, displayWindow, msgid, nullptr);
10741089
#endif
10751090

10761091
//! Run program in code directory if it exists
@@ -1223,28 +1238,39 @@ void MainWindow::debug()
12231238
QString inputPath = Common::pathInTemp("input.txt");
12241239
inputPath.replace("\\", "/");
12251240

1226-
// start display Linux
1227-
#ifdef Q_OS_WIN32
1228-
#else
1229-
if (!displayWindow) {
1241+
// start display
1242+
if (!displayWindow) {
12301243
displayWindow = new DisplayWindow;
12311244
displayWindow->setWindowIcon(QIcon(":images/mainIcon.png"));
1232-
//displayWindow->setFixedSize(500,525);
1233-
//displayWindow->setFixedSize(600,625);
12341245
displayWindow->setWindowFlags(Qt::Widget | Qt::MSWindowsFixedSizeDialogHint);
12351246
displayWindow->activateWindow();
1236-
//displaywdg->setParent(this);
12371247
}
12381248
if (settings.value("display", false).toBool())
12391249
displayWindow->show();
1240-
key_t key = ftok("/tmp", 65); //returned -1
1250+
#ifdef Q_OS_WIN32
1251+
HANDLE hCreateNamedPipe = CreateNamedPipe(
1252+
L"\\\\.\\pipe\\sasmpipe",
1253+
PIPE_ACCESS_INBOUND,
1254+
PIPE_TYPE_MESSAGE|PIPE_READMODE_MESSAGE|PIPE_WAIT,
1255+
PIPE_UNLIMITED_INSTANCES,
1256+
8184,
1257+
8184,
1258+
0,
1259+
NULL);
1260+
if(hCreateNamedPipe == INVALID_HANDLE_VALUE){
1261+
printLog(QString("Couldnt create Pipe"+QString::number(GetLastError()))+"\n", Qt::red);
1262+
}
1263+
consumer = new std::thread(&DisplayWindow::changeDisplay, displayWindow, -1, hCreateNamedPipe);
1264+
#else
1265+
key_t key = ftok("/tmp", 65);
12411266
msgid = msgget(key, 0666 | IPC_CREAT);
1242-
consumer = new std::thread(&DisplayWindow::changeDisplay, displayWindow, msgid);
1267+
consumer = new std::thread(&DisplayWindow::changeDisplay, displayWindow, msgid, nullptr);
12431268
#endif
12441269

12451270
debugger = new Debugger(compilerOut, exePath, workingDirectoryPath, inputPath, assembler, 0, settings.value("sasmverbose", false).toBool(), settings.value("mi", false).toBool());
12461271
// connect print signals for output in Debugger
12471272
connect(debugger, SIGNAL(printLog(QString,QColor)), this, SLOT(printLog(QString,QColor)));
1273+
connect(displayWindow, SIGNAL(printLog(QString,QColor)), this, SLOT(printLog(QString,QColor))); // remove
12481274
connect(debugger, SIGNAL(printOutput(QString)), this, SLOT(printOutput(QString)));
12491275
connect(debugger, SIGNAL(highlightLine(int)), code, SLOT(updateDebugLine(int)));
12501276
connect(debugger, SIGNAL(finished()), this, SLOT(debugExit()), Qt::QueuedConnection);

mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#include "displayWindow.h"
8181
#include <unistd.h>
8282
#ifdef Q_OS_WIN32
83+
#include <Windows.h>
8384
#else
8485
#include <sys/ipc.h>
8586
#include <sys/msg.h>

0 commit comments

Comments
 (0)