Skip to content

Commit

Permalink
Added config parser, device factories, BigInt, reference resolution, …
Browse files Browse the repository at this point in the history
…Graphics handlers, easy computer interrupts, read-only bypass for programming the computer, ASSEMBLE and file loading macros

Sophisticated config format should allow users to configure the computer however they want, to better suit programs and games. New macros for compiling other assembly files, and injecting file contents into memory; line by line or a straight dump
  • Loading branch information
DDunda committed Feb 6, 2024
1 parent a648d3e commit c27d206
Show file tree
Hide file tree
Showing 63 changed files with 7,657 additions and 1,110 deletions.
32 changes: 32 additions & 0 deletions Little32/Little32.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,31 @@ copy "$(SDL_ttf)\lib\$(PlatformShortName)\*.dll" "$(OutDir)";</Command>
<ClCompile Include="$(SDLpp)\src\input.cpp" />
<ClCompile Include="$(SDLpp)\src\mouse.cpp" />
<ClCompile Include="$(SDLpp)\src\rect.cpp" />
<ClCompile Include="src\L32_BigInt.cpp" />
<ClCompile Include="src\L32_VarValue.cpp" />
<ClCompile Include="src\L32_ConfigObject.cpp" />
<ClCompile Include="src\L32_CharDisplay.cpp" />
<ClCompile Include="src\L32_ColourCharDisplay.cpp" />
<ClCompile Include="src\L32_Computer.cpp" />
<ClCompile Include="src\L32_ComputerInfo.cpp" />
<ClCompile Include="src\L32_ConfigParser.cpp" />
<ClCompile Include="src\L32_DebugCore.cpp" />
<ClCompile Include="src\L32_IDeviceSettings.cpp" />
<ClCompile Include="src\L32_KeyboardDevice.cpp" />
<ClCompile Include="src\L32_L32Assembler.cpp" />
<ClCompile Include="src\L32_L32Core.cpp" />
<ClCompile Include="src\L32_String.cpp" />
<ClCompile Include="src\L32_IO.cpp" />
<ClCompile Include="src\L32_RAM.cpp" />
<ClCompile Include="src\L32_ROM.cpp" />
<ClCompile Include="src\L32_VarReference.cpp" />
<ClCompile Include="src\Source.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\L32_BigInt.h" />
<ClInclude Include="include\L32_ConfigObject.h" />
<ClInclude Include="include\L32_EmptyDeviceFactory.h" />
<ClInclude Include="include\L32_IDeviceSettings.h" />
<ClInclude Include="include\L32_CharDisplay.h" />
<ClInclude Include="include\L32_ColourCharDisplay.h" />
<ClInclude Include="include\L32_Computer.h" />
Expand All @@ -189,6 +198,7 @@ copy "$(SDL_ttf)\lib\$(PlatformShortName)\*.dll" "$(OutDir)";</Command>
<ClInclude Include="include\L32_DebugCore.h" />
<ClInclude Include="include\L32_IDevice.h" />
<ClInclude Include="include\L32_GUIButton.h" />
<ClInclude Include="include\L32_ImageLoader.h" />
<ClInclude Include="include\L32_KeyboardDevice.h" />
<ClInclude Include="include\L32_L32Assembler.h" />
<ClInclude Include="include\L32_L32Core.h" />
Expand All @@ -201,8 +211,11 @@ copy "$(SDL_ttf)\lib\$(PlatformShortName)\*.dll" "$(OutDir)";</Command>
<ClInclude Include="include\L32_RAM.h" />
<ClInclude Include="include\L32_ROM.h" />
<ClInclude Include="include\L32_Sprite.h" />
<ClInclude Include="include\L32_VarReference.h" />
<ClInclude Include="include\Little32.h" />
<ClInclude Include="include\L32_ConfigParser.h" />
<ClInclude Include="include\L32_IDeviceFactory.h" />
<ClInclude Include="include\L32_VarValue.h" />
</ItemGroup>
<ItemGroup>
<Text Include="scripts\ascii.asm">
Expand Down Expand Up @@ -295,14 +308,33 @@ copy "$(SDL_ttf)\lib\$(PlatformShortName)\*.dll" "$(OutDir)";</Command>
<None Include="computer.cfg">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="scripts\blue_wave.cfg">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="scripts\bounce.cfg">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="scripts\expression.asm">
<FileType>Script</FileType>
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="scripts\gravity.cfg">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="scripts\overflow.asm">
<DeploymentContent>true</DeploymentContent>
<FileType>Script</FileType>
</None>
<CopyFileToFolders Include="scripts\random.cfg">
<FileType>Document</FileType>
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<None Include="scripts\pipes.cfg">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="scripts\program.cfg">
<DeploymentContent>true</DeploymentContent>
</None>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
61 changes: 60 additions & 1 deletion Little32/Little32.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@
<ClCompile Include="src\L32_ConfigParser.cpp">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="src\L32_BigInt.cpp">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="src\L32_ConfigObject.cpp">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="src\L32_IDeviceSettings.cpp">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="src\L32_VarReference.cpp">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="src\L32_VarValue.cpp">
<Filter>Source</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="SDL++">
Expand Down Expand Up @@ -140,6 +155,30 @@
<ClInclude Include="include\L32_ConfigParser.h">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="include\L32_IDeviceFactory.h">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="include\L32_BigInt.h">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="include\L32_ConfigObject.h">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="include\L32_EmptyDeviceFactory.h">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="include\L32_IDeviceSettings.h">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="include\L32_ImageLoader.h">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="include\L32_VarReference.h">
<Filter>Headers</Filter>
</ClInclude>
<ClInclude Include="include\L32_VarValue.h">
<Filter>Headers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="assets\char set.png">
Expand Down Expand Up @@ -206,9 +245,29 @@
<None Include="scripts\expression.asm">
<Filter>Assembly</Filter>
</None>
<None Include="computer.cfg" />
<None Include="scripts\overflow.asm">
<Filter>Assembly</Filter>
</None>
<None Include="scripts\gravity.cfg">
<Filter>Assembly</Filter>
</None>
<None Include="computer.cfg" />
<None Include="scripts\program.cfg">
<Filter>Assembly</Filter>
</None>
<None Include="scripts\pipes.cfg">
<Filter>Assembly</Filter>
</None>
<None Include="scripts\bounce.cfg">
<Filter>Assembly</Filter>
</None>
<None Include="scripts\blue_wave.cfg">
<Filter>Assembly</Filter>
</None>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="scripts\random.cfg">
<Filter>Assembly</Filter>
</CopyFileToFolders>
</ItemGroup>
</Project>
87 changes: 63 additions & 24 deletions Little32/computer.cfg
Original file line number Diff line number Diff line change
@@ -1,42 +1,81 @@
!! The address to start placing components at
start_address = 0

rom_address = 0
rom_bytes = 8192

ram_address = 8192
ram_bytes = 8192

!! The address the stack starts at (fills backwards)
stack_address = 16384

clocks_per_frame = 1000

!! For each component create an object with a string variable 'component_type',
!! and whatever other information the component needs
components = [
components =
[
{
component_type = "RAM"
RAM_words = 16384
}
component_type = "ROM",
size_words = 2048
default_byte = 0
},
{
component_type = "ROM"
ROM_words = 16384
}
component_type = "RAM",
size_words = 2048
default_byte = 0
},
{
component_type = "Colour Character Display",

texture_file = "./assets/char set.png" ,
texture_position = (0,0),
texture_char_size = (8,8),
texture_columns = 16,

text_size = (16,16),

pixel_position = (0,0),
pixel_scale = (4,4),

!! Modes:
!! 0 - Locked to cpu cycles
!! 1 - Locked to FPS
!! 2 - Locked to time per frame
!! 3 - VSYNC?
framerate_mode = 0,

!! 0 - Cycles per frame
!! 1 - Target FPS
!! 2 - ms per frame
!! 3 - Ignored
framerate_lock = 3000,

labels =
{
CHAR_MEM = 0,
COLOUR_MEM = "colour_position",
RENDER_INT = "interrupt_position"
}
},
{
component_type = "ROM"
ROM_words = 16384
component_type = "Keyboard",
labels =
{
KEYBOARD = 0
}
}
]

palettes = "assets/palette.png"

character_set = {
file = "assets/char set.png"
character_size = (8,8)
characters_per_row = 16
}

display = {
size_chars = (16,16)
position = (0,0)
scale = (4,4)
}

viewport_size = (512,512)

!! Used for the debug bar at the bottom of the window
gui_colours = {
neutral = #FF6A00
hover = #F26000
gui_colours =
{
neutral = #FF6A00,
hover = #F26000,
click = #D85600
}
101 changes: 101 additions & 0 deletions Little32/include/L32_BigInt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#pragma once

#ifndef L32_BigInt_h_
#define L32_BigInt_h_

#include <cassert>
#include <string_view>
#include <vector>

namespace Little32
{
struct BigInt
{
bool negative = false;
std::vector<uint64_t> bits = {};

BigInt();

BigInt(uint64_t value);

BigInt(int64_t value);

BigInt(std::string_view value);

inline constexpr bool operator==(const BigInt& other) const
{
if (negative != other.negative) return false;

if (bits.size() != other.bits.size()) return false;

for (size_t i = bits.size(); i--;)
{
if (bits[i] != other.bits[i]) return false;
}

return true;
}

inline constexpr bool operator!=(const BigInt& other) const
{
if (negative != other.negative) return true;

if (bits.size() != other.bits.size()) return true;

for (size_t i = bits.size(); i--;)
{
if (bits[i] != other.bits[i]) return true;
}

return false;
}

BigInt& operator-=(BigInt other);

BigInt& operator+=(BigInt other);

BigInt& operator+=(uint64_t other);

BigInt& operator=(uint64_t other);

BigInt& operator=(int64_t other);

BigInt& shift_left();

BigInt& shift_right();

BigInt& operator>>=(uint16_t shift);

BigInt& operator<<=(uint16_t shift);

BigInt& operator*=(BigInt other);

BigInt& operator*=(int64_t other);

std::string ToStringCheap() const;

size_t NumBits() const noexcept;

bool TryToUInt64(uint64_t& out) const noexcept;

bool TryToUInt32(uint32_t& out) const noexcept;

bool TryToUInt16(uint16_t& out) const noexcept;

bool TryToUInt8(uint8_t& out) const noexcept;

bool TryToUIntX(BigInt& out, size_t bits) const noexcept;

bool TryToInt64(int64_t& out) const noexcept;

bool TryToInt32(int32_t& out) const noexcept;

bool TryToInt16(int16_t& out) const noexcept;

bool TryToInt8(int8_t& out) const noexcept;

bool TryToIntX(BigInt& out, size_t bits) const noexcept;
};
}

#endif
5 changes: 3 additions & 2 deletions Little32/include/L32_CharDisplay.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#ifndef L32_CharDisplay_h_
#define L32_CharDisplay_h_
#pragma once

#include <rect.hpp>

Expand Down Expand Up @@ -58,7 +59,7 @@ namespace Little32
inline word GetAddress() const { return address_start; }
inline word GetRange() const { return address_size + sizeof(word); }

constexpr const Device_ID GetID() const { return Device_ID::CharDisplay; }
constexpr const Device_ID GetID() const { return CHARDISPLAY_DEVICE; }

void Render(bool do_interrupt = true);

Expand Down
Loading

0 comments on commit c27d206

Please sign in to comment.