Skip to content

Commit

Permalink
Performance, bug fixes, debug options, documentation updates.
Browse files Browse the repository at this point in the history
Performance stats., refactoring, bug fixes, documentation updates,
cosmetic changes, debug options.
  • Loading branch information
makarcz committed Sep 8, 2016
1 parent 3cd0bc3 commit 9d6706d
Show file tree
Hide file tree
Showing 22 changed files with 1,925 additions and 324 deletions.
176 changes: 176 additions & 0 deletions ConsoleIO.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
*--------------------------------------------------------------------
* Project: VM65 - Virtual Machine/CPU emulator programming
* framework.
*
* File: ConsoleIO.cpp
*
* Purpose: Implementation of ConsoleIO class.
* The ConsoleIO class has methods helpful when
* UI is utilizing STDIO (DOS) console.
*
* Date: 8/26/2016
*
* Copyright: (C) by Marek Karcz 2016. All rights reserved.
*
* Contact: [email protected]
*
* License Agreement and Warranty:
This software is provided with No Warranty.
I (Marek Karcz) will not be held responsible for any damage to
computer systems, data or user's health resulting from use.
Please proceed responsibly and apply common sense.
This software is provided in hope that it will be useful.
It is free of charge for non-commercial and educational use.
Distribution of this software in non-commercial and educational
derivative work is permitted under condition that original
copyright notices and comments are preserved. Some 3-rd party work
included with this project may require separate application for
permission from their respective authors/copyright owners.
*--------------------------------------------------------------------
*/
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <string.h>
#include "system.h"
#include "ConsoleIO.h"

#include "MKGenException.h"

#if defined(WINDOWS)
#include <conio.h>
#endif

using namespace std;

namespace MKBasic {

/*
*--------------------------------------------------------------------
* Method:
* Purpose:
* Arguments:
* Returns:
*--------------------------------------------------------------------
*/
ConsoleIO::ConsoleIO()
{

}

/*
*--------------------------------------------------------------------
* Method:
* Purpose:
* Arguments:
* Returns:
*--------------------------------------------------------------------
*/
ConsoleIO::~ConsoleIO()
{

}

#if defined(WINDOWS)

/*
*--------------------------------------------------------------------
* Method: ClearScreen()
* Purpose: Clear the console screen.
* Arguments: n/a
* Returns: n/a
*--------------------------------------------------------------------
*/
void ConsoleIO::ClearScreen()
{
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };

hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if (hStdOut == INVALID_HANDLE_VALUE) return;

/* Get the number of cells in the current buffer */
if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;

/* Fill the entire buffer with spaces */
if (!FillConsoleOutputCharacter(
hStdOut,
(TCHAR) ' ',
cellCount,
homeCoords,
&count
)) return;

/* Fill the entire buffer with the current colors and attributes */
if (!FillConsoleOutputAttribute(
hStdOut,
csbi.wAttributes,
cellCount,
homeCoords,
&count
)) return;

/* Move the cursor home */
SetConsoleCursorPosition( hStdOut, homeCoords );
}

/*
*--------------------------------------------------------------------
* Method: ScrHome()
* Purpose: Bring the console cursor to home position.
* Arguments: n/a
* Returns: n/a
*--------------------------------------------------------------------
*/
void ConsoleIO::ScrHome()
{
HANDLE hStdOut;
COORD homeCoords = { 0, 0 };

hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if (hStdOut == INVALID_HANDLE_VALUE) return;

/* Move the cursor home */
SetConsoleCursorPosition( hStdOut, homeCoords );
}

#endif

#if defined(LINUX)

/*
*--------------------------------------------------------------------
* Method: ClearScreen()
* Purpose: Clear the console screen.
* Arguments: n/a
* Returns: n/a
*--------------------------------------------------------------------
*/
void ConsoleIO::ClearScreen()
{
system("clear");
}

/*
*--------------------------------------------------------------------
* Method: ScrHome()
* Purpose: Bring the console cursor to home position.
* Arguments: n/a
* Returns: n/a
*--------------------------------------------------------------------
*/
void ConsoleIO::ScrHome()
{
cout << "\033[1;1H";
}

#endif // #devine LINUX

} // END namespace MKBasic
61 changes: 61 additions & 0 deletions ConsoleIO.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
*--------------------------------------------------------------------
* Project: VM65 - Virtual Machine/CPU emulator programming
* framework.
*
* File: ConsoleIO.h
*
* Purpose: Prototype of ConsoleIO class.
*
* Date: 8/26/2016
*
* Copyright: (C) by Marek Karcz 2016. All rights reserved.
*
* Contact: [email protected]
*
* License Agreement and Warranty:
This software is provided with No Warranty.
I (Marek Karcz) will not be held responsible for any damage to
computer systems, data or user's health resulting from use.
Please proceed responsibly and apply common sense.
This software is provided in hope that it will be useful.
It is free of charge for non-commercial and educational use.
Distribution of this software in non-commercial and educational
derivative work is permitted under condition that original
copyright notices and comments are preserved. Some 3-rd party work
included with this project may require separate application for
permission from their respective authors/copyright owners.
*--------------------------------------------------------------------
*/
#ifndef CONSOLEIO_H
#define CONSOLEIO_H

#include <string>
#include <queue>
#include <chrono>
#include "system.h"

//#define WINDOWS 1
#if defined (WINDOWS)
#include <windows.h>
#endif

namespace MKBasic {

class ConsoleIO
{
public:

ConsoleIO();
~ConsoleIO();

void ClearScreen();
void ScrHome();

};

} // namespace MKBasic

#endif // #ifndef CONSOLEIO_H
36 changes: 36 additions & 0 deletions Display.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
/*
*--------------------------------------------------------------------
* Project: VM65 - Virtual Machine/CPU emulator programming
* framework.
*
* File: Display.cpp
*
* Purpose: Implementation of Display class.
* The Display class emulates the character I/O device.
* It defines the abstract device. The actual
* input/output to the screen of the platform on which
* the emulator runs is defined in MemMapDev class
* or on higher level of abstraction.
*
* Date: 8/25/2016
*
* Copyright: (C) by Marek Karcz 2016. All rights reserved.
*
* Contact: [email protected]
*
* License Agreement and Warranty:
This software is provided with No Warranty.
I (Marek Karcz) will not be held responsible for any damage to
computer systems, data or user's health resulting from use.
Please proceed responsibly and apply common sense.
This software is provided in hope that it will be useful.
It is free of charge for non-commercial and educational use.
Distribution of this software in non-commercial and educational
derivative work is permitted under condition that original
copyright notices and comments are preserved. Some 3-rd party work
included with this project may require separate application for
permission from their respective authors/copyright owners.
*--------------------------------------------------------------------
*/
#include "Display.h"
#include <ctype.h>
#include <cstdlib>
Expand Down
32 changes: 32 additions & 0 deletions Display.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
/*
*--------------------------------------------------------------------
* Project: VM65 - Virtual Machine/CPU emulator programming
* framework.
*
* File: Display.h
*
* Purpose: Prototype of Display class and all supportig data
* structures, enumerations, constants and macros.
*
* Date: 8/25/2016
*
* Copyright: (C) by Marek Karcz 2016. All rights reserved.
*
* Contact: [email protected]
*
* License Agreement and Warranty:
This software is provided with No Warranty.
I (Marek Karcz) will not be held responsible for any damage to
computer systems, data or user's health resulting from use.
Please proceed responsibly and apply common sense.
This software is provided in hope that it will be useful.
It is free of charge for non-commercial and educational use.
Distribution of this software in non-commercial and educational
derivative work is permitted under condition that original
copyright notices and comments are preserved. Some 3-rd party work
included with this project may require separate application for
permission from their respective authors/copyright owners.
*--------------------------------------------------------------------
*/
#ifndef DISPLAY_H
#define DISPLAY_H

Expand Down
38 changes: 38 additions & 0 deletions GraphDisp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
/*
*--------------------------------------------------------------------
* Project: VM65 - Virtual Machine/CPU emulator programming
* framework.
*
* File: GraphDisp.cpp
*
* Purpose: Implementation of GraphDisp class.
* The GraphDisp class emulates the graphics raster
* device. It handles displaying of the graphics, the
* events loop and the 'hardware' API to the device.
* The higher level abstraction layer - MemMapDev
* defines the actual behavior/response of the emulated
* device in the emulated system.
*
* Date: 8/25/2016
*
* Copyright: (C) by Marek Karcz 2016. All rights reserved.
*
* Contact: [email protected]
*
* License Agreement and Warranty:
This software is provided with No Warranty.
I (Marek Karcz) will not be held responsible for any damage to
computer systems, data or user's health resulting from use.
Please proceed responsibly and apply common sense.
This software is provided in hope that it will be useful.
It is free of charge for non-commercial and educational use.
Distribution of this software in non-commercial and educational
derivative work is permitted under condition that original
copyright notices and comments are preserved. Some 3-rd party work
included with this project may require separate application for
permission from their respective authors/copyright owners.
*--------------------------------------------------------------------
*/
#include "GraphDisp.h"
#include "MKGenException.h"
#include "system.h"
Expand Down Expand Up @@ -75,6 +111,8 @@ void GraphDisp::Initialize()
{
int desk_w, desk_h, winbd_top = 5, winbd_right = 5;

mPixelSizeX = GRAPHDISP_MAXW / mWidth;
mPixelSizeY = GRAPHDISP_MAXH / mHeight;
GetDesktopResolution(desk_w, desk_h);
// Available in version > 2.0.4
//SDL_GetWindowBordersSize(mpWindow, &winbd_top, NULL, NULL, &winbd_right);
Expand Down
Loading

0 comments on commit 9d6706d

Please sign in to comment.