-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
alpha #1 // Add .gitattributes, .gitignore, README.md, and LICENSE.txt.
- Loading branch information
0 parents
commit 64eab3b
Showing
41 changed files
with
843 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
############################################################################### | ||
# Set default behavior to automatically normalize line endings. | ||
############################################################################### | ||
* text=auto | ||
|
||
############################################################################### | ||
# Set default behavior for command prompt diff. | ||
# | ||
# This is need for earlier builds of msysgit that does not have it on by | ||
# default for csharp files. | ||
# Note: This is only used by command line | ||
############################################################################### | ||
#*.cs diff=csharp | ||
|
||
############################################################################### | ||
# Set the merge driver for project and solution files | ||
# | ||
# Merging from the command prompt will add diff markers to the files if there | ||
# are conflicts (Merging from VS is not affected by the settings below, in VS | ||
# the diff markers are never inserted). Diff markers may cause the following | ||
# file extensions to fail to load in VS. An alternative would be to treat | ||
# these files as binary and thus will always conflict and require user | ||
# intervention with every merge. To do so, just uncomment the entries below | ||
############################################################################### | ||
#*.sln merge=binary | ||
#*.csproj merge=binary | ||
#*.vbproj merge=binary | ||
#*.vcxproj merge=binary | ||
#*.vcproj merge=binary | ||
#*.dbproj merge=binary | ||
#*.fsproj merge=binary | ||
#*.lsproj merge=binary | ||
#*.wixproj merge=binary | ||
#*.modelproj merge=binary | ||
#*.sqlproj merge=binary | ||
#*.wwaproj merge=binary | ||
|
||
############################################################################### | ||
# behavior for image files | ||
# | ||
# image files are treated as binary by default. | ||
############################################################################### | ||
#*.jpg binary | ||
#*.png binary | ||
#*.gif binary | ||
|
||
############################################################################### | ||
# diff behavior for common document formats | ||
# | ||
# Convert binary document formats to text before diffing them. This feature | ||
# is only available from the command line. Turn it on by uncommenting the | ||
# entries below. | ||
############################################################################### | ||
#*.doc diff=astextplain | ||
#*.DOC diff=astextplain | ||
#*.docx diff=astextplain | ||
#*.DOCX diff=astextplain | ||
#*.dot diff=astextplain | ||
#*.DOT diff=astextplain | ||
#*.pdf diff=astextplain | ||
#*.PDF diff=astextplain | ||
#*.rtf diff=astextplain | ||
#*.RTF diff=astextplain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Prerequisites | ||
*.d | ||
|
||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
*.o | ||
*.obj | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Compiled Dynamic libraries | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Fortran module files | ||
*.mod | ||
*.smod | ||
|
||
# Compiled Static libraries | ||
*.lai | ||
*.la | ||
*.a | ||
*.lib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+896 KB
.vs/Simpletron/v17/ipch/AutoPCH/8315234563e1d72f/MEMORY_MANIPULATION.ipch
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+896 KB
.vs/Simpletron/v17/ipch/AutoPCH/87c44e12823fd9fb/S_INSTRUCTION_HANDLER.ipch
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) [year] [fullname] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Simpletron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/* ************************************************************ | ||
Simpletron v1.0 | ||
Author: Arthur Brenno, 2023 | ||
github: arthurbrenno | ||
public release date: 2023-05-09 | ||
Changes: | ||
2023-05-06: started the main code | ||
2023-05-09 alpha program DONE. no bugs found yet. | ||
************************************************************ */ | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include "s_operations.h" | ||
#include "s_instruction_handler.h" | ||
#include "s_specs.h" | ||
#if defined _WIN32 | ||
#define Clear() system("cls") | ||
#else | ||
#define Clear() system("clear") | ||
#endif | ||
|
||
void WelcomeMessage(); | ||
void LoadingComplete(); | ||
bool AskForInteger(const std::string& input, int& destination); | ||
|
||
int main() { | ||
|
||
WelcomeMessage(); | ||
int memory[mem_size]{}; //Memory of the machine | ||
|
||
//Fill the memory with instructions | ||
for (int i{ 0 }; i < mem_size; ++i) { | ||
int current_instruction{}; | ||
bool success{}; | ||
|
||
while ( | ||
(GetDigits(current_instruction) != qtd_digits | ||
&& current_instruction != stop_sentinel) | ||
|| !success) { | ||
|
||
printf("%02d ? ", i); | ||
std::string input{}; | ||
std::cin >> input; | ||
success = AskForInteger(input, current_instruction); | ||
} | ||
|
||
memory[i] = current_instruction; | ||
|
||
if (current_instruction == stop_sentinel | ||
|| ExtractOperation(current_instruction) == Simpletron::toc::halt) { break; } | ||
|
||
} | ||
|
||
Clear(); | ||
LoadingComplete(); | ||
|
||
int instruction_counter{}; | ||
int instruction_register{}; | ||
int operation_code{}; | ||
int operand{}; | ||
int eax{}; | ||
while (instruction_register != stop_sentinel | ||
&& ExtractOperation(instruction_register) != Simpletron::toc::halt) { | ||
|
||
instruction_register = memory[instruction_counter]; | ||
operation_code = ExtractOperation(instruction_register); | ||
operand = ExtractOperand(instruction_register); | ||
switch (operation_code) { | ||
case Simpletron::io::read: { | ||
bool success{}; | ||
int integer{}; | ||
while (!success) { | ||
std::cout << "Enter an Integer: "; | ||
std::string temp; | ||
std::cin >> temp; | ||
success = AskForInteger(temp, integer); | ||
} | ||
memory[operand] = integer; | ||
instruction_counter++; break; | ||
} | ||
case Simpletron::io::write: { | ||
std::cout << memory[operand] << std::endl; instruction_counter++; break; | ||
} | ||
case Simpletron::ls::load: { | ||
eax = memory[operand]; instruction_counter++; break; | ||
} | ||
case Simpletron::ls::store: { | ||
memory[operand] = eax; instruction_counter++; break; | ||
} | ||
case Simpletron::arithmetic::add: { | ||
eax += memory[operand]; instruction_counter++; break; | ||
} | ||
case Simpletron::arithmetic::sub: { | ||
eax -= memory[operand]; instruction_counter++; break; | ||
} | ||
case Simpletron::arithmetic::div: { | ||
eax /= memory[operand]; instruction_counter++; break; | ||
} | ||
case Simpletron::arithmetic::imul: { | ||
eax *= memory[operand]; instruction_counter++; break; | ||
} | ||
case Simpletron::arithmetic::mod: { | ||
eax %= memory[operand]; instruction_counter++; break; | ||
} | ||
case Simpletron::arithmetic::exp: { | ||
eax = std::pow(eax, memory[operand]); instruction_counter++; break; | ||
} | ||
case Simpletron::toc::branch: { | ||
instruction_counter = operand; break; | ||
} | ||
case Simpletron::toc::branchneg: { | ||
if (eax < 0) { instruction_counter = operand; break; } | ||
instruction_counter++; break; | ||
} | ||
case Simpletron::toc::branchzero: { | ||
if (eax == 0) { instruction_counter = operand; break; } | ||
instruction_counter++; break; | ||
} | ||
case Simpletron::toc::halt: { | ||
system("exit"); break; | ||
} | ||
default: | ||
instruction_counter++; | ||
} | ||
} | ||
|
||
Dump( | ||
memory, | ||
sizeof(memory) / sizeof(memory[0]), | ||
eax, instruction_counter, | ||
instruction_register, | ||
operation_code, | ||
operand); | ||
std::cout << std::endl; | ||
system("pause"); | ||
} | ||
|
||
//first program message | ||
void WelcomeMessage() { | ||
std::cout << "*** Welcome to Simpletron! ***" << '\n'; | ||
std::cout << "*** Please enter your program one instruction ***" << '\n'; | ||
std::cout << "*** (or data word) at a time. I will display ***" << '\n'; | ||
std::cout << "*** the location number and a question mark (?). *** ***" << '\n'; | ||
std::cout << "*** You then type the word for that location. ***" << '\n'; | ||
std::cout << "*** Type -99999 to stop entering your program. ***" << '\n'; | ||
} | ||
|
||
//instruction loading complete | ||
void LoadingComplete() { | ||
std::cout << "***Program loading completed ***" << '\n' | ||
<< "***Program execution begins***" << '\n'; | ||
} | ||
|
||
//Get a valid integer input | ||
bool AskForInteger(const std::string& input, int& destination) { | ||
try { | ||
int temp{ std::stoi(input) }; | ||
destination = temp; | ||
return true; | ||
} | ||
catch (const std::exception e) { return false; } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.5.33627.172 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Simpletron", "Simpletron.vcxproj", "{40794D47-D254-4A4C-9FD4-1A91129B4713}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{40794D47-D254-4A4C-9FD4-1A91129B4713}.Debug|x64.ActiveCfg = Debug|x64 | ||
{40794D47-D254-4A4C-9FD4-1A91129B4713}.Debug|x64.Build.0 = Debug|x64 | ||
{40794D47-D254-4A4C-9FD4-1A91129B4713}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{40794D47-D254-4A4C-9FD4-1A91129B4713}.Debug|x86.Build.0 = Debug|Win32 | ||
{40794D47-D254-4A4C-9FD4-1A91129B4713}.Release|x64.ActiveCfg = Release|x64 | ||
{40794D47-D254-4A4C-9FD4-1A91129B4713}.Release|x64.Build.0 = Release|x64 | ||
{40794D47-D254-4A4C-9FD4-1A91129B4713}.Release|x86.ActiveCfg = Release|Win32 | ||
{40794D47-D254-4A4C-9FD4-1A91129B4713}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {172BE9E7-5FA1-4B43-AFAC-969C93B3EA63} | ||
EndGlobalSection | ||
EndGlobal |
Oops, something went wrong.