Skip to content

Commit 9d6706d

Browse files
committed
Performance, bug fixes, debug options, documentation updates.
Performance stats., refactoring, bug fixes, documentation updates, cosmetic changes, debug options.
1 parent 3cd0bc3 commit 9d6706d

22 files changed

+1925
-324
lines changed

ConsoleIO.cpp

+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/*
2+
*--------------------------------------------------------------------
3+
* Project: VM65 - Virtual Machine/CPU emulator programming
4+
* framework.
5+
*
6+
* File: ConsoleIO.cpp
7+
*
8+
* Purpose: Implementation of ConsoleIO class.
9+
* The ConsoleIO class has methods helpful when
10+
* UI is utilizing STDIO (DOS) console.
11+
*
12+
* Date: 8/26/2016
13+
*
14+
* Copyright: (C) by Marek Karcz 2016. All rights reserved.
15+
*
16+
* Contact: [email protected]
17+
*
18+
* License Agreement and Warranty:
19+
20+
This software is provided with No Warranty.
21+
I (Marek Karcz) will not be held responsible for any damage to
22+
computer systems, data or user's health resulting from use.
23+
Please proceed responsibly and apply common sense.
24+
This software is provided in hope that it will be useful.
25+
It is free of charge for non-commercial and educational use.
26+
Distribution of this software in non-commercial and educational
27+
derivative work is permitted under condition that original
28+
copyright notices and comments are preserved. Some 3-rd party work
29+
included with this project may require separate application for
30+
permission from their respective authors/copyright owners.
31+
32+
*--------------------------------------------------------------------
33+
*/
34+
#include <stdio.h>
35+
#include <iostream>
36+
#include <sstream>
37+
#include <string.h>
38+
#include "system.h"
39+
#include "ConsoleIO.h"
40+
41+
#include "MKGenException.h"
42+
43+
#if defined(WINDOWS)
44+
#include <conio.h>
45+
#endif
46+
47+
using namespace std;
48+
49+
namespace MKBasic {
50+
51+
/*
52+
*--------------------------------------------------------------------
53+
* Method:
54+
* Purpose:
55+
* Arguments:
56+
* Returns:
57+
*--------------------------------------------------------------------
58+
*/
59+
ConsoleIO::ConsoleIO()
60+
{
61+
62+
}
63+
64+
/*
65+
*--------------------------------------------------------------------
66+
* Method:
67+
* Purpose:
68+
* Arguments:
69+
* Returns:
70+
*--------------------------------------------------------------------
71+
*/
72+
ConsoleIO::~ConsoleIO()
73+
{
74+
75+
}
76+
77+
#if defined(WINDOWS)
78+
79+
/*
80+
*--------------------------------------------------------------------
81+
* Method: ClearScreen()
82+
* Purpose: Clear the console screen.
83+
* Arguments: n/a
84+
* Returns: n/a
85+
*--------------------------------------------------------------------
86+
*/
87+
void ConsoleIO::ClearScreen()
88+
{
89+
HANDLE hStdOut;
90+
CONSOLE_SCREEN_BUFFER_INFO csbi;
91+
DWORD count;
92+
DWORD cellCount;
93+
COORD homeCoords = { 0, 0 };
94+
95+
hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
96+
if (hStdOut == INVALID_HANDLE_VALUE) return;
97+
98+
/* Get the number of cells in the current buffer */
99+
if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
100+
cellCount = csbi.dwSize.X *csbi.dwSize.Y;
101+
102+
/* Fill the entire buffer with spaces */
103+
if (!FillConsoleOutputCharacter(
104+
hStdOut,
105+
(TCHAR) ' ',
106+
cellCount,
107+
homeCoords,
108+
&count
109+
)) return;
110+
111+
/* Fill the entire buffer with the current colors and attributes */
112+
if (!FillConsoleOutputAttribute(
113+
hStdOut,
114+
csbi.wAttributes,
115+
cellCount,
116+
homeCoords,
117+
&count
118+
)) return;
119+
120+
/* Move the cursor home */
121+
SetConsoleCursorPosition( hStdOut, homeCoords );
122+
}
123+
124+
/*
125+
*--------------------------------------------------------------------
126+
* Method: ScrHome()
127+
* Purpose: Bring the console cursor to home position.
128+
* Arguments: n/a
129+
* Returns: n/a
130+
*--------------------------------------------------------------------
131+
*/
132+
void ConsoleIO::ScrHome()
133+
{
134+
HANDLE hStdOut;
135+
COORD homeCoords = { 0, 0 };
136+
137+
hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
138+
if (hStdOut == INVALID_HANDLE_VALUE) return;
139+
140+
/* Move the cursor home */
141+
SetConsoleCursorPosition( hStdOut, homeCoords );
142+
}
143+
144+
#endif
145+
146+
#if defined(LINUX)
147+
148+
/*
149+
*--------------------------------------------------------------------
150+
* Method: ClearScreen()
151+
* Purpose: Clear the console screen.
152+
* Arguments: n/a
153+
* Returns: n/a
154+
*--------------------------------------------------------------------
155+
*/
156+
void ConsoleIO::ClearScreen()
157+
{
158+
system("clear");
159+
}
160+
161+
/*
162+
*--------------------------------------------------------------------
163+
* Method: ScrHome()
164+
* Purpose: Bring the console cursor to home position.
165+
* Arguments: n/a
166+
* Returns: n/a
167+
*--------------------------------------------------------------------
168+
*/
169+
void ConsoleIO::ScrHome()
170+
{
171+
cout << "\033[1;1H";
172+
}
173+
174+
#endif // #devine LINUX
175+
176+
} // END namespace MKBasic

ConsoleIO.h

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
*--------------------------------------------------------------------
3+
* Project: VM65 - Virtual Machine/CPU emulator programming
4+
* framework.
5+
*
6+
* File: ConsoleIO.h
7+
*
8+
* Purpose: Prototype of ConsoleIO class.
9+
*
10+
* Date: 8/26/2016
11+
*
12+
* Copyright: (C) by Marek Karcz 2016. All rights reserved.
13+
*
14+
* Contact: [email protected]
15+
*
16+
* License Agreement and Warranty:
17+
18+
This software is provided with No Warranty.
19+
I (Marek Karcz) will not be held responsible for any damage to
20+
computer systems, data or user's health resulting from use.
21+
Please proceed responsibly and apply common sense.
22+
This software is provided in hope that it will be useful.
23+
It is free of charge for non-commercial and educational use.
24+
Distribution of this software in non-commercial and educational
25+
derivative work is permitted under condition that original
26+
copyright notices and comments are preserved. Some 3-rd party work
27+
included with this project may require separate application for
28+
permission from their respective authors/copyright owners.
29+
30+
*--------------------------------------------------------------------
31+
*/
32+
#ifndef CONSOLEIO_H
33+
#define CONSOLEIO_H
34+
35+
#include <string>
36+
#include <queue>
37+
#include <chrono>
38+
#include "system.h"
39+
40+
//#define WINDOWS 1
41+
#if defined (WINDOWS)
42+
#include <windows.h>
43+
#endif
44+
45+
namespace MKBasic {
46+
47+
class ConsoleIO
48+
{
49+
public:
50+
51+
ConsoleIO();
52+
~ConsoleIO();
53+
54+
void ClearScreen();
55+
void ScrHome();
56+
57+
};
58+
59+
} // namespace MKBasic
60+
61+
#endif // #ifndef CONSOLEIO_H

Display.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
/*
2+
*--------------------------------------------------------------------
3+
* Project: VM65 - Virtual Machine/CPU emulator programming
4+
* framework.
5+
*
6+
* File: Display.cpp
7+
*
8+
* Purpose: Implementation of Display class.
9+
* The Display class emulates the character I/O device.
10+
* It defines the abstract device. The actual
11+
* input/output to the screen of the platform on which
12+
* the emulator runs is defined in MemMapDev class
13+
* or on higher level of abstraction.
14+
*
15+
* Date: 8/25/2016
16+
*
17+
* Copyright: (C) by Marek Karcz 2016. All rights reserved.
18+
*
19+
* Contact: [email protected]
20+
*
21+
* License Agreement and Warranty:
22+
23+
This software is provided with No Warranty.
24+
I (Marek Karcz) will not be held responsible for any damage to
25+
computer systems, data or user's health resulting from use.
26+
Please proceed responsibly and apply common sense.
27+
This software is provided in hope that it will be useful.
28+
It is free of charge for non-commercial and educational use.
29+
Distribution of this software in non-commercial and educational
30+
derivative work is permitted under condition that original
31+
copyright notices and comments are preserved. Some 3-rd party work
32+
included with this project may require separate application for
33+
permission from their respective authors/copyright owners.
34+
35+
*--------------------------------------------------------------------
36+
*/
137
#include "Display.h"
238
#include <ctype.h>
339
#include <cstdlib>

Display.h

+32
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
/*
2+
*--------------------------------------------------------------------
3+
* Project: VM65 - Virtual Machine/CPU emulator programming
4+
* framework.
5+
*
6+
* File: Display.h
7+
*
8+
* Purpose: Prototype of Display class and all supportig data
9+
* structures, enumerations, constants and macros.
10+
*
11+
* Date: 8/25/2016
12+
*
13+
* Copyright: (C) by Marek Karcz 2016. All rights reserved.
14+
*
15+
* Contact: [email protected]
16+
*
17+
* License Agreement and Warranty:
18+
19+
This software is provided with No Warranty.
20+
I (Marek Karcz) will not be held responsible for any damage to
21+
computer systems, data or user's health resulting from use.
22+
Please proceed responsibly and apply common sense.
23+
This software is provided in hope that it will be useful.
24+
It is free of charge for non-commercial and educational use.
25+
Distribution of this software in non-commercial and educational
26+
derivative work is permitted under condition that original
27+
copyright notices and comments are preserved. Some 3-rd party work
28+
included with this project may require separate application for
29+
permission from their respective authors/copyright owners.
30+
31+
*--------------------------------------------------------------------
32+
*/
133
#ifndef DISPLAY_H
234
#define DISPLAY_H
335

GraphDisp.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
1+
/*
2+
*--------------------------------------------------------------------
3+
* Project: VM65 - Virtual Machine/CPU emulator programming
4+
* framework.
5+
*
6+
* File: GraphDisp.cpp
7+
*
8+
* Purpose: Implementation of GraphDisp class.
9+
* The GraphDisp class emulates the graphics raster
10+
* device. It handles displaying of the graphics, the
11+
* events loop and the 'hardware' API to the device.
12+
* The higher level abstraction layer - MemMapDev
13+
* defines the actual behavior/response of the emulated
14+
* device in the emulated system.
15+
*
16+
* Date: 8/25/2016
17+
*
18+
* Copyright: (C) by Marek Karcz 2016. All rights reserved.
19+
*
20+
* Contact: [email protected]
21+
*
22+
* License Agreement and Warranty:
23+
24+
This software is provided with No Warranty.
25+
I (Marek Karcz) will not be held responsible for any damage to
26+
computer systems, data or user's health resulting from use.
27+
Please proceed responsibly and apply common sense.
28+
This software is provided in hope that it will be useful.
29+
It is free of charge for non-commercial and educational use.
30+
Distribution of this software in non-commercial and educational
31+
derivative work is permitted under condition that original
32+
copyright notices and comments are preserved. Some 3-rd party work
33+
included with this project may require separate application for
34+
permission from their respective authors/copyright owners.
135
36+
*--------------------------------------------------------------------
37+
*/
238
#include "GraphDisp.h"
339
#include "MKGenException.h"
440
#include "system.h"
@@ -75,6 +111,8 @@ void GraphDisp::Initialize()
75111
{
76112
int desk_w, desk_h, winbd_top = 5, winbd_right = 5;
77113

114+
mPixelSizeX = GRAPHDISP_MAXW / mWidth;
115+
mPixelSizeY = GRAPHDISP_MAXH / mHeight;
78116
GetDesktopResolution(desk_w, desk_h);
79117
// Available in version > 2.0.4
80118
//SDL_GetWindowBordersSize(mpWindow, &winbd_top, NULL, NULL, &winbd_right);

0 commit comments

Comments
 (0)