Commit 5127d488 authored by Felix Albrecht's avatar Felix Albrecht
Browse files

Added code version of 6/19/2013.

parent b826fea3
......@@ -5,6 +5,7 @@
#include "MMIX-Edit.h"
#include "SciLexer.h"
#include "Scintilla.h"
#include <Windows.h>
#include <stdio.h>
// For nice controls look
......@@ -19,6 +20,8 @@
#pragma comment(lib, "ComCtl32.lib")
#define MAX_LOADSTRING 100
#define ErrorMarker 3
#define BackgroundMarker 4
// Globale Variablen:
HINSTANCE hInst; // Aktuelle Instanz
......@@ -43,7 +46,7 @@ struct DMApp {
HWND currentDialog;
HWND wMain;
HWND wInner;
HWND wError;
HWND wErrorList;
HWND wEditor;
bool isDirty;
wchar_t fullPath[MAX_PATH];
......@@ -70,6 +73,7 @@ struct DMApp {
void EnableAMenuItem(int id, bool enable);
void CheckMenus();
void Notify(SCNotification *notification);
void positionCursor();
void SetAStyle(int style, COLORREF fore, COLORREF back=white, int size=-1, const char *face=0);
void InitialiseEditor();
......@@ -113,6 +117,9 @@ void DMApp::New() {
}
void DMApp::OpenFile(const wchar_t *fileName) {
SendMessage(app.wErrorList, LB_RESETCONTENT, 0, 0);
New();
SendEditor(SCI_CANCEL);
SendEditor(SCI_SETUNDOCOLLECTION, 0);
......@@ -144,6 +151,9 @@ void DMApp::OpenFile(const wchar_t *fileName) {
}
void DMApp::Open() {
SendMessage(app.wErrorList, LB_RESETCONTENT, 0, 0);
wchar_t openName[MAX_PATH] = L"\0";
OPENFILENAME ofn = {sizeof(OPENFILENAME)};
ofn.hwndOwner = wMain;
......@@ -230,6 +240,12 @@ int DMApp::SaveIfUnsure() {
void DMApp::Command(int id) {
switch (id) {
case 65536:
if(HIWORD(id) == LBN_DBLCLK)
positionCursor();
break;
case IDM_FILE_NEW:
if (SaveIfUnsure() != IDCANCEL) {
New();
......@@ -491,6 +507,68 @@ void DMApp::InitialiseEditor() {
}
SendEditor(SCI_STYLESETBACK, SCE_HJA_STRINGEOL, RGB(0x0,0xAF,0x5F));
SendEditor(SCI_STYLESETEOLFILLED, SCE_HJA_STRINGEOL, 1);
SendEditor(SCI_MARKERDEFINE, ErrorMarker, SC_MARK_CIRCLE);
SendEditor(SCI_MARKERSETFORE, ErrorMarker, 0|0|0);
SendEditor(SCI_MARKERSETBACK, ErrorMarker, 255|0|0);
SendEditor(SCI_MARKERSETBACKSELECTED, ErrorMarker, 128|0|0);
SendEditor(SCI_MARKERDEFINE, BackgroundMarker, SC_MARK_BACKGROUND);
SendEditor(SCI_MARKERSETFORE, BackgroundMarker, 0|0|0);
SendEditor(SCI_MARKERSETBACK, BackgroundMarker, 128|0|0);
SendEditor(SCI_MARKERSETBACKSELECTED, BackgroundMarker, 128|0|0);
}
void DMApp::positionCursor(){
// ERR: SendMessage
int selection = (int) SendMessage(wErrorList, LB_GETCURSEL, 0, 0);
int lineNumber = (int) SendMessage(wErrorList, LB_GETITEMDATA, selection, 0);
SetFocus(wEditor);
SendEditor(SCI_GOTOLINE, 0, lineNumber);
}
EXTERN_C char* mmixal(FILE* file, char* filename);
EXTERN_C char* mmixsim(FILE* file);
DWORD WINAPI ConsoleThread(LPVOID lpParam){
if(AllocConsole()){
printf("look at this:");
mmixsim((FILE*)lpParam);
}else{
LPTSTR lpMsgBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
MessageBox(app.wMain, lpMsgBuf, L"Could not start console", MB_OK);
}
return 0;
}
extern "C" void addListString(char* text, int lineNumber, bool isError){
wchar_t* wText = new wchar_t[strlen(text)+1];
mbstowcs(wText, text, strlen(text)+1);
SendMessage(app.wErrorList, LB_ADDSTRING, 0, (LPARAM) wText);
int index = (int)SendMessage(app.wErrorList, LB_FINDSTRING, -1, (LPARAM)wText);
SendMessage(app.wErrorList, LB_SETITEMDATA, index, lineNumber - 1);
app.SendEditor(SCI_MARKERADD, lineNumber - 1, ErrorMarker);
app.SendEditor(SCI_MARKERADD, lineNumber - 1, BackgroundMarker);
}
INT_PTR CALLBACK DialogProc( HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam ){
......@@ -600,18 +678,25 @@ int APIENTRY _tWinMain(HINSTANCE instance,
app.hInstance,
0);
app.wError = CreateWindow(
L"ListBox",
NULL,
WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_CLIPCHILDREN,
rc.left, rc.top + ((rc.bottom - rc.top) / 5) * 4,
rc.right - rc.left, (rc.bottom - rc.top) / 5,
app.wMain,
0,
app.hInstance,
0);
if(!app.wError){
//app.wError = CreateDialog(app.hInstance, MAKEINTRESOURCE(IDD_ERROR), app.wMain, NULL);
//app.wErrorList = GetDlgItem(app.wError, IDC_ERRORLIST);
app.wErrorList = CreateWindow(
L"ListBox",
NULL,
WS_CHILD | WS_VSCROLL | WS_CLIPCHILDREN | LBS_HASSTRINGS | LBS_NOTIFY,
rc.left, rc.top + ((rc.bottom - rc.top) / 5) * 4,
rc.right - rc.left, (rc.bottom - rc.top) / 5,
app.wMain,
0,
app.hInstance,
0);
//SetParent(app.wErrorList, app.wMain);
//SetWindowPos(app.wErrorList, 0, rc.left, rc.top + ((rc.bottom - rc.top) / 5) * 4, rc.right - rc.left, (rc.bottom - rc.top) / 5, 0);
if(!app.wErrorList){
LPTSTR lpMsgBuf;
DWORD dw = GetLastError();
......@@ -631,42 +716,15 @@ int APIENTRY _tWinMain(HINSTANCE instance,
app.InitialiseEditor();
ShowWindow(app.wEditor, SW_SHOWNORMAL);
ShowWindow(app.wError, SW_SHOWNORMAL);
ShowWindow(app.wErrorList, SW_SHOWNORMAL);
SetFocus(app.wEditor);
UpdateWindow(app.wEditor);
UpdateWindow(app.wError);
/*HRSRC hrsrc;
HGLOBAL hglobal;
hrsrc = FindResource(app.hInstance, MAKEINTRESOURCE(IDD_MAIN), RT_DIALOG);
hglobal = LoadResource(app.hInstance, hrsrc);
app.wInner = CreateDialogIndirect(app.hInstance, (LPCDLGTEMPLATE)hglobal, app.wMain, NULL);
SetWindowPos(app.wInner, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE);
if(!app.wInner){
LPTSTR lpMsgBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
MessageBox(app.wMain, lpMsgBuf, L"Inner Error", MB_OK);
return 0;
}
ShowWindow(app.wInner, SW_SHOW);*/
UpdateWindow(app.wErrorList);
// Hauptnachrichtenschleife:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
......@@ -677,11 +735,10 @@ int APIENTRY _tWinMain(HINSTANCE instance,
return (int) msg.wParam;
}
EXTERN_C char* mmixal(FILE* file, char* filename);
EXTERN_C char* mmixsim(FILE* file);
void assemble(){
SendMessage(app.wErrorList, LB_RESETCONTENT, 0, 0);
FILE* src_file = _wfopen(app.fullPath, L"rb");
if(!src_file){
MessageBox(app.wMain, app.fullPath, L"Can't open mms-file", MB_OK);
......@@ -705,17 +762,14 @@ void assemble(){
char *path = new char[wcslen(app.fullPath) + 1];
wcstombs(path, app.fullPath, wcslen(app.fullPath) + 1);
wchar_t* array_t = new wchar_t[strlen(path)+1];
mbstowcs(array_t, path, strlen(path)+1);
MessageBox(app.wMain, array_t, L"", MB_OK);
MessageBox(app.wMain, (LPCWSTR)mmixal(src_file, path), L"MMIXAL", MB_OK);
mmixal(src_file, path);
}
}
void run(){
wchar_t* filename = app.fullPath;
filename[wcslen(filename)] = 'o';
filename[wcslen(filename)-1] = 'o';
FILE* src_file = _wfopen(filename, L"rb");
if(!src_file){
MessageBox(app.wMain, app.fullPath, L"Can't open mmo-file", MB_OK);
......@@ -733,16 +787,10 @@ void run(){
(LPTSTR) &lpMsgBuf,
0, NULL );
MessageBox(app.wMain, lpMsgBuf, L"List Error", MB_OK);
MessageBox(app.wMain, lpMsgBuf, L"MMO Error", MB_OK);
} else {
char *path = new char[wcslen(app.fullPath) + 1];
wcstombs(path, app.fullPath, wcslen(app.fullPath) + 1);
wchar_t* array_t = new wchar_t[strlen(path)+1];
mbstowcs(array_t, path, strlen(path)+1);
MessageBox(app.wMain, array_t, L"", MB_OK);
MessageBox(app.wMain, (LPCWSTR)mmixsim(src_file), L"MMIXAL", MB_OK);
CreateThread(0, 1024, ConsoleThread, (LPVOID) src_file, 0, 0);
}
}
......@@ -790,13 +838,17 @@ ATOM MyRegisterClass(HINSTANCE hInstance)
// WM_DESTROY - Beenden-Meldung anzeigen und zurckgeben
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, UINT wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
HMENU menuBar, subMenu;
WORD word;
LPNMHDR hdr;
switch (message)
{
case WM_CREATE:
......@@ -807,7 +859,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (wParam != 1) {
RECT rc;
::GetClientRect(hWnd, &rc);
SetWindowPos(app.wError, 0, rc.left, rc.top + ((rc.bottom - rc.top) / 5) * 4, rc.right - rc.left, (rc.bottom - rc.top) / 5, 0);
//SetWindowPos(app.wError, 0, rc.left, rc.top + ((rc.bottom - rc.top) / 5) * 4, rc.right - rc.left, (rc.bottom - rc.top) / 5, 0);
SetWindowPos(app.wErrorList, 0, rc.left, rc.top + ((rc.bottom - rc.top) / 5) * 4, rc.right - rc.left, (rc.bottom - rc.top) / 5, 0);
SetWindowPos(app.wEditor, 0, rc.left, rc.top, rc.right - rc.left, ((rc.bottom - rc.top) / 5) * 4, 0);
}
return 0;
......@@ -818,17 +871,30 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
switch(LOWORD(wParam)){
case IDD_MENU_RUN:
case 0:
if(HIWORD(wParam) == LBN_DBLCLK){
app.positionCursor();
}
break;
case IDD_MENU_COMPILE:
app.SaveIfUnsure();
assemble();
break;
case IDD_MENU_COMPILE:
case IDD_MENU_RUN:
app.SaveIfUnsure();
assemble();
run();
break;
case IDC_ERRORLIST:
if(HIWORD(wParam) == LBN_DBLCLK){
app.positionCursor();
}
break;
case IDM_ABOUT:
HWND about = CreateDialog(app.hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), app.wMain, NULL);
......@@ -838,6 +904,23 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_NOTIFY:
hdr = (LPNMHDR)lParam;
switch(hdr->code){
case LBN_SETFOCUS:
app.positionCursor();
break;
case LBN_DBLCLK:
app.positionCursor();
break;
default:
break;
}
app.Notify(reinterpret_cast<SCNotification *>(lParam));
return 0;
......@@ -861,7 +944,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_CTLCOLORLISTBOX:
if((HWND)lParam == app.wError){
if((HWND)lParam == app.wErrorList){
SetBkColor((HDC)wParam, RGB(0, 0, 0));
SetTextColor((HDC)wParam, RGB(255, 255, 255));
......@@ -878,10 +961,22 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// Meldungshandler fr Infofeld.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND ErrorHandle;
HWND ErrorListHandle;
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
/*ErrorHandle = GetDlgItem(app.wMain, IDD_ERROR);
ErrorListHandle = GetDlgItem(app.wError, IDC_ERRORLIST);
RECT rc;
::GetClientRect(hDlg, &rc);
SetWindowPos(ErrorListHandle, 0, rc.left, rc.top + ((rc.bottom - rc.top) / 5) * 4, rc.right - rc.left, (rc.bottom - rc.top) / 5, 0);
SetWindowPos(ErrorHandle, 0, rc.left, rc.top + ((rc.bottom - rc.top) / 5) * 4, rc.right - rc.left, (rc.bottom - rc.top) / 5, 0);
*/
return (INT_PTR)TRUE;
case WM_COMMAND:
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -98,8 +98,14 @@
<ItemGroup>
<ClCompile Include="mmix-arith.c" />
<ClCompile Include="MMIX-Edit.cpp" />
<ClCompile Include="mmix-io.c" />
<ClCompile Include="mmix-sim.c" />
<ClCompile Include="mmix-io.c">
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsC</CompileAs>
</ClCompile>
<ClCompile Include="mmix-sim.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</ExcludedFromBuild>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsC</CompileAs>
</ClCompile>
<ClCompile Include="mmixal.c" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
......
========================================================================
WIN32-ANWENDUNG: MMIX-Edit-Projektübersicht
========================================================================
Diese MMIX-Edit-Anwendung wurde vom Anwendungs-Assistenten
für Sie erstellt.
Diese Datei bietet eine Übersicht über den Inhalt der einzelnen Dateien,
aus denen Ihre MMIX-Edit-Anwendung besteht.
MMIX-Edit.vcxproj
Dies ist die Hauptprojektdatei für VC++-Projekte, die mit dem
Anwendungs-Assistenten generiert werden.
Sie enthält Informationen zur Visual C++-Version, mit der die Datei
generiert wurde, sowie Informationen zu Plattformen, Konfigurationen und
Projektfunktionen, die mit dem Anwendungs-Assistenten ausgewählt wurden.
MMIX-Edit.vcxproj.filters
Dies ist die Filterdatei für VC++-Projekte, die mithilfe eines
Anwendungs-Assistenten erstellt werden.
Sie enthält Informationen über die Zuordnung zwischen den Dateien im
Projekt und den Filtern. Diese Zuordnung wird in der IDE zur Darstellung
der Gruppierung von Dateien mit ähnlichen Erweiterungen unter einem
bestimmten Knoten verwendet (z. B. sind CPP-Dateien dem Filter
"Quelldateien" zugeordnet).
MMIX-Edit.cpp
Dies ist die Hauptquelldatei der Anwendung.
/////////////////////////////////////////////////////////////////////////////
Der Anwendungs-Assistent hat folgende Ressourcen erstellt:
MMIX-Edit.rc
Dies ist eine Auflistung aller vom Programm verwendeten
Microsoft Windows-Ressourcen. Sie enthält die Symbole, Bitmaps und Cursor,
die im Unterverzeichnis "RES" gespeichert werden. Diese Datei kann direkt
in Microsoft Visual C++ bearbeitet werden.
Resource.h
Dies ist die Standardheaderdatei, die neue Ressourcen-IDs definiert.
Die Datei wird mit Microsoft Visual C++ gelesen und aktualisiert.
MMIX-Edit.ico
Dies ist eine Symboldatei, die als Anwendungssymbol (32x32) verwendet wird.
Dieses Symbol ist in der Hauptressourcendatei "MMIX-Edit.rc"
enthalten.
small.ico
Dies ist eine Symboldatei, die eine kleinere Version (16x16)
des Anwendungssymbols enthält. Dieses Symbol ist in der Hauptressourcendatei
"MMIX-Edit.rc" enthalten.
/////////////////////////////////////////////////////////////////////////////
Andere Standarddateien:
StdAfx.h, StdAfx.cpp
Diese Dateien werden verwendet, um eine vorkompilierte Headerdatei
(PCH-Datei) mit dem Namen "MMIX-Edit.pch und eine
vorkompilierte Typendatei mit dem Namen "StdAfx.obj" zu erstellen.
/////////////////////////////////////////////////////////////////////////////
Weitere Hinweise:
Der Anwendungs-Assistent weist Sie mit "TODO:"-Kommentaren auf Teile des
Quellcodes hin, die Sie ergänzen oder anpassen sollten.
/////////////////////////////////////////////////////////////////////////////
/*1:*/
#line 17 "abstime.w"
#include <stdio.h>
#include <time.h>
main()
{
printf("#define ABSTIME %ld\n",time(NULL));
return 0;
}
/*:1*/
This diff is collapsed.
#define sign_bit ((unsigned) 0x80000000) \
/*1:*/
#line 16 "mmix-io.w"
/*2:*/
#line 26 "mmix-io.w"
#include <stdio.h>
#include <stdlib.h>
#ifdef __STDC__
#define ARGS(list) list
#else
#define ARGS(list) ()
#endif
#ifndef FILENAME_MAX
#define FILENAME_MAX 256
#endif
#ifndef SEEK_SET
#define SEEK_SET 0
#endif
#ifndef SEEK_END
#define SEEK_END 2
#endif
/*:2*/
#line 17 "mmix-io.w"
/*3:*/
#line 47 "mmix-io.w"
typedef unsigned int tetra;
typedef struct{tetra h,l;}octa;
/*:3*//*5:*/
#line 68 "mmix-io.w"
typedef struct{
FILE*fp;
int mode;
}sim_file_info;
/*:5*/
#line 18 "mmix-io.w"
/*4:*/
#line 56 "mmix-io.w"
extern char stdin_chr ARGS((void));
extern int mmgetchars ARGS((char*buf,int size,octa addr,int stop));
extern void mmputchars ARGS((unsigned char*buf,int size,octa addr));
extern octa oplus ARGS((octa,octa));
extern octa ominus ARGS((octa,octa));
extern octa incr ARGS((octa,int));
extern octa zero_octa;
extern octa neg_one;
/*:4*/
#line 19 "mmix-io.w"
/*6:*/
#line 74 "mmix-io.w"
sim_file_info sfile[256];
/*:6*//*9:*/
#line 110 "mmix-io.w"
char*mode_string[]= {"r","w","rb","wb","w+b"};
int mode_code[]= {0x1,0x2,0x5,0x6,0xf};
/*:9*//*24:*/
#line 391 "mmix-io.w"
char*trip_warning[]= {
"TRIP",
"integer divide check",
"integer overflow",
"float-to-fix overflow",
"invalid floating point operation",
"floating point overflow",
"floating point underflow",
"floating point division by zero",
"floating point inexact"};
/*:24*/
#line 20 "mmix-io.w"
/*7:*/
#line 79 "mmix-io.w"
void mmix_io_init ARGS((void));
void mmix_io_init()
{
sfile[0].fp= stdin,sfile[0].mode= 1;
sfile[1].fp= stdout,sfile[1].mode= 2;
sfile[2].fp= stderr,sfile[2].mode= 2;
}
/*:7*//*8:*/
#line 92 "mmix-io.w"
octa mmix_fopen ARGS((unsigned int,octa,octa));
octa mmix_fopen(handle,name,mode)
unsigned int handle;
octa name,mode;
{
char name_buf[FILENAME_MAX];
if(mode.h||mode.l> 4)goto failure;
if(mmgetchars(name_buf,FILENAME_MAX,name,0)==FILENAME_MAX)goto failure;
if(sfile[handle].mode!=0&&handle> 2)fclose(sfile[handle].fp);
sfile[handle].fp= fopen(name_buf,mode_string[mode.l]);
if(!sfile[handle].fp)goto failure;
sfile[handle].mode= mode_code[mode.l];
return zero_octa;
failure:sfile[handle].mode= 0;
return neg_one;
}
/*:8*//*10:*/
#line 117 "mmix-io.w"
void mmix_fake_stdin ARGS((FILE*));