Version 0 not fully working

This commit is contained in:
2025-06-21 17:23:02 -04:00
commit 32d70aa657
21 changed files with 1307 additions and 0 deletions

15
.gitignore vendored Normal file
View File

@@ -0,0 +1,15 @@
### CMake template
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
cmake-build-debug

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "vendor/SDL"]
path = vendor/SDL
url = git@github.com:libsdl-org/SDL.git

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

2
.idea/chip8.iml generated Normal file
View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

262
.idea/editor.xml generated Normal file
View File

@@ -0,0 +1,262 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BackendCodeEditorSettings">
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CDeclarationWithImplicitIntType/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CommentTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConstevalIfIsAlwaysConstant/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractClassWithoutSpecifier/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractFinalClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractVirtualFunctionCallInCtor/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAccessSpecifierWithNoDeclarations/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAwaiterTypeIsNotClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBooleanIncrementExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatBadCode/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatLegacyCode/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatMixedArgs/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooFewArgs/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooManyArgs/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCStyleCast/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCVQualifierCanNotBeAppliedToReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassCanBeFinal/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassIsIncomplete/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeedsConstructorBecauseOfUninitializedMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCompileTimeConstantCanBeReplacedWithBooleanConstant/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConceptNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConditionalExpressionCanBeSimplified/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConstParameterInDeclaration/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConstValueFunctionReturnType/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCoroutineCallResolveError/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAArrayIndexOutOfBounds/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantConditions/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantFunctionResult/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantParameter/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFADeletedPointer/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAEndlessLoop/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAInfiniteRecursion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAInvalidatedMemory/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALocalValueEscapesFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALocalValueEscapesScope/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALoopConditionNotUpdated/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAMemoryLeak/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFANotInitializedField/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFANullDereference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFATimeOver/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreachableCode/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreachableFunctionCall/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreadVariable/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnusedValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationHidesLocal/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationHidesUncapturedLocal/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationSpecifierWithoutDeclarators/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorDisambiguatedAsFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorUsedBeforeInitialization/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultCaseNotHandledInSwitchStatement/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultInitializationWithNoUserConstructor/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultIsUsedAsIdentifier/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultedSpecialMemberFunctionIsImplicitlyDeleted/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeletingVoidPointer/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTemplateWithoutTemplateKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTypeWithoutTypenameKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedEntity/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedOverridenMethod/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedRegisterStorageClassSpecifier/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDereferenceOperatorLimitExceeded/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDiscardedPostfixOperatorResult/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenSyntaxError/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenUndocumentedParameter/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenUnresolvedReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEmptyDeclaration/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceCVQualifiersOrder/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceCVQualifiersPlacement/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceDoStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceForStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceFunctionDeclarationStyle/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceIfStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceNestedNamespacesStyle/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceOverridingDestructorStyle/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceOverridingFunctionStyle/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceTypeAliasCodeStyle/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceWhileStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEntityAssignedButNoRead/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEntityUsedOnlyInUnevaluatedContext/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnumeratorNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEqualOperandsInBinaryExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEvaluationFailure/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppExplicitSpecializationInNonNamespaceScope/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppExpressionWithoutSideEffects/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFinalFunctionInFinalClass/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFinalNonOverridingVirtualFunction/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppForLoopCanBeReplacedWithWhile/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppForwardEnumDeclarationWithoutUnderlyingType/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionDoesntReturnValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionIsNotImplemented/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionResultShouldBeUsed/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionalStyleCast/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHeaderHasBeenAlreadyIncluded/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHiddenFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHidingFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIdenticalOperandsInBinaryExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIfCanBeReplacedByConstexprIf/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppImplicitDefaultConstructorNotAvailable/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompatiblePointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompleteSwitchStatement/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInconsistentNaming/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIntegralToPointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInvalidLineContinuation/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppJoinDeclarationAndAssignment/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLambdaCaptureNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMayBeConst/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMightNotBeInitialized/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableWithNonTrivialDtorIsNeverUsed/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLongFloat/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeConst/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeStatic/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberInitializersOrder/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMismatchedClassTags/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMissingIncludeGuard/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMissingKeywordThrow/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtAddressOfClassRValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtBindingRValueToLvalueReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtCopyElisionInCopyInitDeclarator/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtDoubleUserConversionInCopyInit/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtNotInitializedStaticConstLocalVar/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtReinterpretCastFromNullptr/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMultiCharacterLiteral/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMultiCharacterWideLiteral/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMustBePublicVirtualToImplementInterface/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMutableSpecifierOnReferenceMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNoDiscardExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNodiscardFunctionWithoutReturnValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExceptionSafeResourceAcquisition/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExplicitConversionOperator/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExplicitConvertingConstructor/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonInlineFunctionDefinitionInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonInlineVariableDefinitionInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNotAllPathsReturnValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppObjectMemberMightNotBeInitialized/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppOutParameterMustBeWritten/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterMayBeConst/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterMayBeConstPtrOrRef/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterNamesMismatch/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterNeverUsed/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPassValueParameterByConstReference/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPointerConversionDropsQualifiers/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPointerToIntegralConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPolymorphicClassWithNonVirtualPublicDestructor/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyErroneousEmptyStatements/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyUninitializedMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyUnintendedObjectSlicing/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrecompiledHeaderIsNotIncluded/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrecompiledHeaderNotFound/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfBadFormat/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfExtraArg/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfMissedArg/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfRiskyFormat/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrivateSpecialMemberFunctionIsNotImplemented/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRangeBasedForIncompatibleReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedefinitionOfDefaultArgumentInOverrideFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantAccessSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBaseClassAccessSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBaseClassInitializer/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBooleanExpressionArgument/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantCastExpression/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantComplexityInComparison/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantConditionalExpression/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantConstSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantControlFlowJump/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantDereferencingAndTakingAddress/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElaboratedTypeSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElseKeyword/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElseKeywordInsideCompoundStatement/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantEmptyDeclaration/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantEmptyStatement/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantExportKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantFwdClassOrEnumSpecifier/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantInlineSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantLambdaParameterList/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantMemberInitializer/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantNamespaceDefinition/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantParentheses/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantQualifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantQualifierADL/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantStaticSpecifierOnMemberAllocationFunction/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantStaticSpecifierOnThreadLocalLocalVariable/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTemplateArguments/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTemplateKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTypenameKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantVoidArgumentList/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantZeroInitializerInAggregateInitialization/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReinterpretCastFromVoidPtr/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRemoveRedundantBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReplaceMemsetWithZeroInitialization/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReplaceTieWithStructuredBinding/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReturnNoValueInNonVoidFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSmartPointerVsMakeFunction/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSomeObjectMembersMightNotBeInitialized/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSpecialFunctionWithoutNoexceptSpecification/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticAssertFailure/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticDataMemberInUnnamedStruct/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticSpecifierOnAnonymousNamespaceMember/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStringLiteralToCharPointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTabsAreDisallowed/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateArgumentsCanBeDeduced/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterNeverUsed/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterShadowing/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppThrowExpressionCanBeReplacedWithRethrow/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTooWideScope/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTooWideScopeInitStatement/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTypeAliasNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUninitializedDependentBaseClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUninitializedNonStaticDataMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnionMemberOfReferenceType/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaEndRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnamedNamespaceInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnecessaryWhitespace/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnsignedZeroComparison/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnusedIncludeDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAlgorithmWithCount/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAssociativeContains/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAuto/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAutoForNumeric/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseElementsView/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseEraseAlgorithm/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseFamiliarTemplateSyntaxForGenericLambdas/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseRangeAlgorithm/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseStdSize/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseStructuredBinding/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseTypeTraitAlias/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUserDefinedLiteralSuffixDoesNotStartWithUnderscore/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUsingResultOfAssignmentAsCondition/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVariableCanBeMadeConstexpr/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVirtualFunctionCallInsideCtor/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVirtualFunctionInFinalClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVolatileParameterInDeclaration/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWarningDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWrongIncludesOrder/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWrongSlashesInIncludeDirective/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppZeroConstantCanBeReplacedWithNullptr/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppZeroValuedExpressionUsedAsNullPointer/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IdentifierTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IfStdIsConstantEvaluatedCanBeReplaced/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StdIsConstantEvaluatedWillAlwaysEvaluateToConstant/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALLOW_COMMENT_AFTER_LBRACE/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/EMPTY_BLOCK_STYLE/@EntryValue" value="TOGETHER" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/EXPORT_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CASE_FROM_SWITCH/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INVOCABLE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_CATCH_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_ELSE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_WHILE_ON_NEW_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/REQUIRES_EXPRESSION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CppIncludeDirective/SortIncludeDirectives/@EntryValue" value="true" type="bool" />
</component>
</project>

7
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/chip8.iml" filepath="$PROJECT_DIR$/.idea/chip8.iml" />
</modules>
</component>
</project>

7
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/vendor/SDL" vcs="Git" />
</component>
</project>

8
CMakeLists.txt Normal file
View File

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.31)
project(chip8)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_subdirectory(vendor)
add_subdirectory(src)

BIN
roms/1-ibm-logo.ch8 Normal file

Binary file not shown.

10
src/CMakeLists.txt Normal file
View File

@@ -0,0 +1,10 @@
add_executable(${PROJECT_NAME}
Chip8.cpp
Chip8.h
Interpreter.cpp
Interpreter.h)
target_sources(${PROJECT_NAME} PRIVATE main.cpp
Graphics.cpp
Graphics.h
)
target_link_libraries(${PROJECT_NAME} PRIVATE vendor)

95
src/Chip8.cpp Normal file
View File

@@ -0,0 +1,95 @@
#include "Chip8.h"
#include <filesystem>
#include <format>
#include <fstream>
#include <iostream>
#include "bitops.h"
Chip8::Chip8(): target_cycle_time(1.0 / 700.0), last_update_time(0), accumulator(0) {}
bool Chip8::init() {
if (!graphics.init()) {
return false;
}
last_update_time = SDL_GetTicks();
accumulator = 0;
const auto rom = read_rom("roms/1-ibm-logo.ch8");
interpreter.load_rom(rom);
interpreter.display.set();
return true;
}
void Chip8::set_keyboard_state(std::span<const bool> keyboard_state) {
this->keyboard_state = keyboard_state;
}
std::vector<uint8_t> Chip8::read_rom(const std::string& path) {
std::ifstream rom_file(path, std::ios::binary);
rom_file.seekg(0, std::ios::end);
const std::streampos file_size = rom_file.tellg();
rom_file.seekg(0, std::ios::beg);
std::cout << "ROM size: " << file_size << std::endl;
std::vector<std::uint8_t> rom(file_size);
rom.insert(
rom.begin(),
std::istreambuf_iterator<char>(rom_file),
std::istreambuf_iterator<char>()
);
return rom;
}
void Chip8::load_keyboard() {
interpreter.keyboard = keyboard_state[SDL_SCANCODE_X] ? bit_set(interpreter.keyboard, 0x0) : bit_clear(interpreter.keyboard, 0x0);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_1] ? bit_set(interpreter.keyboard, 0x1) : bit_clear(interpreter.keyboard, 0x1);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_2] ? bit_set(interpreter.keyboard, 0x2) : bit_clear(interpreter.keyboard, 0x2);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_3] ? bit_set(interpreter.keyboard, 0x3) : bit_clear(interpreter.keyboard, 0x3);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_Q] ? bit_set(interpreter.keyboard, 0x4) : bit_clear(interpreter.keyboard, 0x4);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_W] ? bit_set(interpreter.keyboard, 0x5) : bit_clear(interpreter.keyboard, 0x5);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_E] ? bit_set(interpreter.keyboard, 0x6) : bit_clear(interpreter.keyboard, 0x6);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_A] ? bit_set(interpreter.keyboard, 0x7) : bit_clear(interpreter.keyboard, 0x7);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_S] ? bit_set(interpreter.keyboard, 0x8) : bit_clear(interpreter.keyboard, 0x8);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_D] ? bit_set(interpreter.keyboard, 0x9) : bit_clear(interpreter.keyboard, 0x9);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_Z] ? bit_set(interpreter.keyboard, 0xA) : bit_clear(interpreter.keyboard, 0xA);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_C] ? bit_set(interpreter.keyboard, 0xB) : bit_clear(interpreter.keyboard, 0xB);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_4] ? bit_set(interpreter.keyboard, 0xC) : bit_clear(interpreter.keyboard, 0xC);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_R] ? bit_set(interpreter.keyboard, 0xD) : bit_clear(interpreter.keyboard, 0xD);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_F] ? bit_set(interpreter.keyboard, 0xE) : bit_clear(interpreter.keyboard, 0xE);
interpreter.keyboard = keyboard_state[SDL_SCANCODE_V] ? bit_set(interpreter.keyboard, 0xF) : bit_clear(interpreter.keyboard, 0xF);
}
void Chip8::update() {
auto current_time = SDL_GetTicks();
double delta_time = static_cast<double>(current_time - last_update_time) / 1000.0;
last_update_time = current_time;
accumulator += delta_time;
load_keyboard();
while (accumulator >= target_cycle_time) {
interpreter.run();
accumulator -= target_cycle_time;
}
std::stringstream buffer;
buffer << std::format("PC: {:03X} | SP: {:02X} | V0-VF: ", interpreter.pc, interpreter.sp);
for (int i = 0; i < 16; ++i) {
buffer << std::format("{:02X}", interpreter.v[i]);
if (i < 15) buffer << ",";
}
buffer << " |";
graphics.draw(interpreter.display, buffer.str());
}

35
src/Chip8.h Normal file
View File

@@ -0,0 +1,35 @@
#ifndef CHIP8_H
#define CHIP8_H
#include <span>
#include "Graphics.h"
#include "Interpreter.h"
class Chip8 {
Graphics graphics;
Interpreter interpreter;
double target_cycle_time;
Uint64 last_update_time;
double accumulator;
std::span<const bool> keyboard_state;
void load_keyboard();
public:
Chip8();
bool init();
void update();
std::vector<uint8_t> read_rom(const std::string& path);
void set_keyboard_state(std::span<const bool> keyboard_state);
};
#endif //CHIP8_H

111
src/Graphics.cpp Normal file
View File

@@ -0,0 +1,111 @@
//
// Created by ryuuji on 6/20/25.
//
#include "Graphics.h"
#include <iostream>
void SDLWindowDestroyer::operator()(SDL_Window* window) const {
std::cout << "Destroying window" << std::endl;
SDL_DestroyWindow(window);
}
void SDLRendererDestroyer::operator()(SDL_Renderer* renderer) const {
std::cout << "Destroying renderer" << std::endl;
SDL_DestroyRenderer(renderer);
}
void SDLTextureDestroyer::operator()(SDL_Texture* texture) const {
std::cout << "Destroying texture" << std::endl;
SDL_DestroyTexture(texture);
}
Graphics::Graphics(): width(64 * 30),
height(35 * 30),
scale(30) {}
bool Graphics::init() {
SDL_SetAppMetadata("CHIP-8 Emulator", "0.0.1", "fun.skrd.chip8");
if (!SDL_Init(SDL_INIT_VIDEO)) {
SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
return false;
}
SDL_Window* raw_window = nullptr;
SDL_Renderer* raw_renderer = nullptr;
if (!SDL_CreateWindowAndRenderer("CHIP-8 Emulator", width, height, 0, &raw_window, &raw_renderer)) {
SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
return false;
}
this->window = std::unique_ptr<SDL_Window, SDLWindowDestroyer>(raw_window);
this->renderer = std::unique_ptr<SDL_Renderer, SDLRendererDestroyer>(raw_renderer);
SDL_Texture* raw_texture = SDL_CreateTexture(renderer.get(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, 64 * scale, 32 * scale);
this->texture = std::unique_ptr<SDL_Texture, SDLTextureDestroyer>(raw_texture);
return true;
}
void Graphics::draw(std::bitset<2048> display, std::string info) {
SDL_SetRenderDrawColor(renderer.get(), 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer.get());
draw_display(display);
draw_info(info);
SDL_RenderPresent(renderer.get());
}
void Graphics::draw_display(std::bitset<2048> display) {
SDL_Surface* surface = nullptr;
if (SDL_LockTextureToSurface(texture.get(), nullptr, &surface)) {
SDL_FillSurfaceRect(surface, nullptr, SDL_MapRGB(SDL_GetPixelFormatDetails(surface->format), nullptr, 0, 0, 0));
for (int i = 0; i < display.size(); i++) {
if (display[i]) {
int x = (i % 64) * scale;
int y = (i / 64) * scale;
SDL_Rect rect = {x, y, scale, scale};
Uint32 color = SDL_MapRGB(
SDL_GetPixelFormatDetails(surface->format),
nullptr,
0,
255,
0
);
SDL_FillSurfaceRect(surface, &rect, color);
}
}
SDL_UnlockTexture(texture.get());
}
SDL_FRect destination_rect{0.0, 0.0, static_cast<float>(64 * scale), static_cast<float>(32 * scale)};
SDL_RenderTexture(renderer.get(), texture.get(), nullptr, &destination_rect);
}
void Graphics::draw_info(std::string info) {
const int charsize = SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE;
const float screen_scale = static_cast<float>(scale);
const float text_scale = 2.0f;
const float info_area_start = 32.0f * screen_scale;
const float info_area_height = (35.0f - 32.0f) * screen_scale;
const float info_area_center = info_area_start + (info_area_height / 2.0f);
const float text_line = info_area_center / text_scale - (static_cast<float>(charsize) / 2.0f);
SDL_SetRenderScale(renderer.get(), text_scale, text_scale);
SDL_SetRenderDrawColor(renderer.get(), 255, 255, 255, SDL_ALPHA_OPAQUE);
SDL_RenderDebugText(renderer.get(), 10 / text_scale, text_line, info.data());
SDL_SetRenderScale(renderer.get(), 1.0f, 1.0f);
}

41
src/Graphics.h Normal file
View File

@@ -0,0 +1,41 @@
//
// Created by ryuuji on 6/20/25.
//
#ifndef RENDERER_H
#define RENDERER_H
#include <bitset>
#include <memory>
#include "SDL3/SDL.h"
struct SDLWindowDestroyer {
void operator()(SDL_Window *window) const;
};
struct SDLRendererDestroyer {
void operator()(SDL_Renderer *renderer) const;
};
struct SDLTextureDestroyer {
void operator()(SDL_Texture *texture) const;
};
class Graphics {
std::shared_ptr<SDL_Window> window;
std::shared_ptr<SDL_Renderer> renderer;
std::shared_ptr<SDL_Texture> texture;
int width;
int height;
int scale;
void draw_display(std::bitset<2048> display);
void draw_info(std::string info);
public:
Graphics();
bool init();
void draw(std::bitset<2048> display, std::string info);
};
#endif //RENDERER_H

533
src/Interpreter.cpp Normal file
View File

@@ -0,0 +1,533 @@
#include "Interpreter.h"
#include <iomanip>
#include <ios>
#include <iostream>
#include <bits/ostream.tcc>
#include "SDL3/SDL_log.h"
Interpreter::Interpreter():
memory(4096, 0),
v(16, 0),
stack(16, 0),
pc(0x200),
sp(0),
i(0),
dt(0),
st(0),
keyboard(0),
quirks(0) {
this->random_generator = std::mt19937(std::random_device{}());
this->load_fonts();
}
void Interpreter::load_fonts() {
constexpr uint8_t font_set[] = {
0xF0, 0x90, 0x90, 0x90, 0xF0, // 0
0x20, 0x60, 0x20, 0x20, 0x70, // 1
0xF0, 0x10, 0xF0, 0x80, 0xF0, // 2
0xF0, 0x10, 0xF0, 0x10, 0xF0, // 3
0x90, 0x90, 0xF0, 0x10, 0x10, // 4
0xF0, 0x80, 0xF0, 0x10, 0xF0, // 5
0xF0, 0x80, 0xF0, 0x90, 0xF0, // 6
0xF0, 0x10, 0x20, 0x40, 0x40, // 7
0xF0, 0x90, 0xF0, 0x90, 0xF0, // 8
0xF0, 0x90, 0xF0, 0x10, 0xF0, // 9
0xF0, 0x90, 0xF0, 0x90, 0x90, // A
0xE0, 0x90, 0xE0, 0x90, 0xE0, // B
0xF0, 0x80, 0x80, 0x80, 0xF0, // C
0xE0, 0x90, 0x90, 0x90, 0xE0, // D
0xF0, 0x80, 0xF0, 0x80, 0xF0, // E
0xF0, 0x80, 0xF0, 0x80, 0x80 // F
};
std::copy(std::begin(font_set), std::end(font_set), memory.begin() + 0x050);
}
void Interpreter::set_quirks(uint8_t quirks) {
this->quirks = quirks;
}
void Interpreter::load_rom(const std::vector<uint8_t>& rom) {
std::copy(std::begin(rom), std::end(rom), memory.begin() + 0x200);
}
void Interpreter::run() {
const uint8_t high_instruction = memory[pc];
const uint8_t low_instruction = memory[pc + 1];
const uint16_t instruction = (high_instruction << 8) | low_instruction;
const uint8_t opcode = instruction & 0xF000 >> 12;
const uint8_t x = instruction & 0x0F00 >> 8;
const uint8_t y = instruction & 0x00F0 >> 4;
const uint8_t n = instruction & 0x000F;
const uint8_t kk = instruction & 0x00FF;
const uint16_t nnn = instruction & 0x0FFF;
pc += 2;
switch (opcode) {
case 0:
if (kk == 0xE0) {
clear_screen();
} else if (kk == 0xEE) {
return_from_subrutine();
}
break;
case 1:
jump(nnn);
break;
case 2: call_subrutine(nnn);
break;
case 3:
skip_if_vx_eq_val(x, kk);
break;
case 4:
skip_if_vx_neq_val(x, kk);
break;
case 5:
skip_if_vx_eq_vy(x, y);
break;
case 6:
load_vx_val(x, kk);
break;
case 7:
add_vx_val(x, kk);
break;
case 8:
switch (n) {
case 0:
load_vx_vy(x, y);
break;
case 1:
vx_or_vy(x, y);
break;
case 2:
vx_and_vy(x, y);
break;
case 3:
vx_xor_vy(x, y);
break;
case 4:
vx_add_vy(x, y);
break;
case 5:
vx_sub_vy(x, y);
break;
case 6:
if (quirks & static_cast<uint8_t>(InterpreterQuirks::COSMAC_SHIFT)) {
vx_shift_right_cosmac(x, y);
} else {
vx_shift_right(x);
}
break;
case 7:
vx_subn_vy(x, y);
break;
case 0xE:
if (quirks & static_cast<uint8_t>(InterpreterQuirks::COSMAC_SHIFT)) {
vx_shift_left_cosmac(x, y);
} else {
vx_shift_left(x);
}
break;
}
break;
case 9:
skip_if_vx_neq_vy(x, y);
break;
case 0xA:
set_index_val(nnn);
break;
case 0xB:
if (quirks & static_cast<int>(InterpreterQuirks::SUPER_CHIP_JUMP)) {
jump_with_offset_super_chip(x, nnn);
} else {
jump_with_offset(nnn);
}
break;
case 0XC:
set_random_value(x, kk);
break;
case 0xD:
display_sprite(x, y, n);
break;
case 0xE:
if (kk == 0x9E) {
skip_if_key_pressed(x);
} else if (kk == 0xA1) {
skip_if_key_not_pressed(x);
}
case 0xF:
switch (kk) {
case 0x07:
load_vx_dt(x);
break;
case 0x0A:
get_key(x);
break;
case 0x15:
load_dt_vx(x);
break;
case 0x18:
load_st_vx(x);
break;
case 0x1E:
add_i_vx(x);
break;
case 0x29:
font_sprite_location(x);
break;
case 0x33:
calculate_bcd(x);
break;
case 0x55:
store_registers_to_memory(x);
break;
case 0x65:
load_registers_from_memory(x);
break;
}
break;
}
if (pc >= 0xFFF) {
SDL_Log("PC Outside of memory, going back 0x200");
pc = 0x200;
}
}
void Interpreter::clear_screen() {
display.reset();
}
void Interpreter::return_from_subrutine() {
sp -= 1;
pc = stack[sp];
}
void Interpreter::jump(const uint16_t nnn) {
pc = nnn;
}
void Interpreter::call_subrutine(const uint16_t nnn) {
stack[sp] = pc;
sp += 1;
pc = nnn;
}
void Interpreter::skip_if_vx_eq_val(const uint8_t x, const uint8_t kk) {
if (v[x] == kk) {
pc += 2;
}
}
void Interpreter::skip_if_vx_neq_val(const uint8_t x, const uint8_t kk) {
if (v[x] != kk) {
pc += 2;
}
}
void Interpreter::skip_if_vx_eq_vy(const uint8_t x, const uint8_t y) {
if (v[x] == v[y]) {
pc += 2;
}
}
void Interpreter::load_vx_val(const uint8_t x, const uint8_t kk) {
v[x] = kk;
}
void Interpreter::add_vx_val(const uint8_t x, const uint8_t kk) {
v[x] += kk;
}
void Interpreter::load_vx_vy(const uint8_t x, const uint8_t y) {
v[x] = v[y];
}
void Interpreter::vx_or_vy(const uint8_t x, const uint8_t y) {
v[x] = v[x] | v[y];
}
void Interpreter::vx_and_vy(const uint8_t x, const uint8_t y) {
v[x] = v[x] & v[y];
}
void Interpreter::vx_xor_vy(const uint8_t x, const uint8_t y) {
v[x] = v[x] ^ v[y];
}
void Interpreter::vx_add_vy(const uint8_t x, const uint8_t y) {
if (v[x] + v[y] > 0xFF) {
v[0xF] = 1;
} else {
v[0xF] = 0;
}
v[x] = (v[x] + v[y]);
}
void Interpreter::vx_sub_vy(const uint8_t x, const uint8_t y) {
if (v[x] > v[y]) {
v[0xF] = 1;
} else {
v[0xF] = 0;
}
v[x] = v[x] - v[y];
}
void Interpreter::vx_shift_right(const uint8_t x) {
if (v[x] & 0x01) {
v[0xF] = 1;
} else {
v[0xF] = 0;
}
v[x] = v[x] >> 1;
}
void Interpreter::vx_shift_right_cosmac(const uint8_t x, const uint8_t y) {
v[x] = v[y];
if (v[x] & 0x01) {
v[0xF] = 1;
} else {
v[0xF] = 0;
}
v[x] = v[x] >> 1;
}
void Interpreter::vx_subn_vy(const uint8_t x, const uint8_t y) {
if (v[y] > v[x]) {
v[0xF] = 1;
} else {
v[0xF] = 0;
}
v[x] = v[y] - v[x];
}
void Interpreter::vx_shift_left(const uint8_t x) {
if (v[x] & 0x80) {
v[0xF] = 1;
} else {
v[0xF] = 0;
}
v[x] = v[x] << 1;
}
void Interpreter::vx_shift_left_cosmac(const uint8_t x, const uint8_t y) {
v[x] = v[y];
if (v[x] & 0x80) {
v[0xF] = 1;
} else {
v[0xF] = 0;
}
v[x] = v[x] << 1;
}
void Interpreter::skip_if_vx_neq_vy(const uint8_t x, const uint8_t y) {
if (v[x] != v[y]) {
pc += 2;
}
}
void Interpreter::set_index_val(const uint16_t nnn) {
i = nnn;
}
void Interpreter::jump_with_offset(const uint16_t nnn) {
pc = nnn + v[0];
}
void Interpreter::jump_with_offset_super_chip(const uint8_t x, const uint16_t nnn) {
pc = nnn + v[x];
}
void Interpreter::set_random_value(const uint8_t x, const uint8_t kk) {
auto random = std::uniform_int_distribution<uint8_t>(0, 0xFF);
const auto value = random(random_generator);
v[x] = value & kk;
}
void Interpreter::display_sprite(uint8_t x, uint8_t y, const uint8_t n) {
uint8_t start_x = v[x] & 63;
uint8_t start_y = v[y] & 31;
v[0xF] = 0;
for (auto row = 0; row < n; row++) {
auto current_y = start_y + row;
if (current_y > 31) {
break;
}
const auto sprite_byte = memory[i + row];
for (auto bit = 0; bit < 8; bit++) {
auto current_x = start_x + bit;
if (current_x > 63) {
break;
}
const auto pixel = (sprite_byte >> (7 - bit)) & 0x01;
const auto index = (start_y * 64) + current_x;
if (pixel) {
if (display[index]) {
display.set(index, false);
v[0xF] = 1;
} else {
display.set(index, true);
}
}
}
}
}
void Interpreter::skip_if_key_pressed(const uint8_t x) {
if (keyboard & (1 << x)) {
pc += 2;
}
}
void Interpreter::skip_if_key_not_pressed(const uint8_t x) {
if (!(keyboard & (1 << x))) {
pc += 2;
}
}
void Interpreter::load_vx_dt(const uint8_t x) {
v[x] = dt;
}
void Interpreter::get_key(const uint8_t x) {
if (keyboard == 0) {
pc -= 2;
return;
}
for (auto key = 0; key < 16; key++) {
if (keyboard & (1 << key)) {
v[x] = key;
break;
}
}
}
void Interpreter::load_dt_vx(const uint8_t x) {
dt = v[x];
}
void Interpreter::load_st_vx(const uint8_t x) {
st = v[x];
}
void Interpreter::add_i_vx(const uint8_t x) {
i = i + v[x];
}
void Interpreter::font_sprite_location(const uint8_t x) {
i = ((v[x] & 0xF) * 5) + 0x50;
}
void Interpreter::calculate_bcd(const uint8_t x) {
const auto number = v[x];
memory[i] = number / 100;
memory[i + 1] = (number - (memory[i] * 100)) / 10;
memory[i + 2] = number - (memory[i] * 100) - (memory[i + 1] * 10);
}
void Interpreter::store_registers_to_memory(const uint8_t x) {
bool use_quirk = quirks & static_cast<uint8_t>(InterpreterQuirks::COSMAC_STORE_AND_LOAD);
for (auto reg = 0; reg <= x; reg++) {
if (use_quirk) {
memory[i] = v[reg];
i++;
} else {
memory[i + reg] = v[reg];
}
}
}
void Interpreter::load_registers_from_memory(const uint8_t x) {
bool use_quirk = quirks & static_cast<uint8_t>(InterpreterQuirks::COSMAC_STORE_AND_LOAD);
for (auto reg = 0; reg <= x; reg++) {
if (use_quirk) {
v[reg] = memory[i];
i++;
} else {
v[reg] = memory[i + reg];
}
}
}
void Interpreter::debug_display_console() {
std::cout << "\n=== CHIP-8 Display Debug ===" << std::endl;
std::cout << "Resolution: 64x32 pixels" << std::endl;
std::cout << "Display buffer size: " << display.size() << std::endl;
// Contar píxeles activos
int active_pixels = 0;
for (int i = 0; i < display.size(); i++) {
if (display[i]) active_pixels++;
}
std::cout << "Active pixels: " << active_pixels << std::endl;
std::cout << "\nDisplay contents:" << std::endl;
std::cout << " ";
// Números de columna (cada 8 píxeles)
for (int x = 0; x < 64; x += 8) {
std::cout << std::setw(2) << std::setfill(' ') << x << " ";
}
std::cout << std::endl;
// Dibujar el display
for (int y = 0; y < 32; y++) {
std::cout << std::setw(2) << std::setfill(' ') << y << " ";
for (int x = 0; x < 64; x++) {
int index = (y * 64) + x;
if (display[index]) {
std::cout << ""; // Píxel activo
} else {
std::cout << "·"; // Píxel inactivo
}
// Separador cada 8 píxeles para mayor legibilidad
if ((x + 1) % 8 == 0 && x < 63) {
std::cout << "|";
}
}
std::cout << std::endl;
// Línea separadora cada 8 filas
if ((y + 1) % 8 == 0 && y < 31) {
std::cout << " ";
for (int x = 0; x < 64; x++) {
std::cout << "-";
if ((x + 1) % 8 == 0 && x < 63) {
std::cout << "+";
}
}
std::cout << std::endl;
}
}
std::cout << "=== End Display Debug ===" << std::endl << std::endl;
}

83
src/Interpreter.h Normal file
View File

@@ -0,0 +1,83 @@
#ifndef INTERPRETER_H
#define INTERPRETER_H
#include <bitset>
#include <cstdint>
#include <random>
#include <vector>
enum class InterpreterQuirks {
COSMAC_SHIFT = 1 << 0,
SUPER_CHIP_JUMP = 1 << 1,
COSMAC_STORE_AND_LOAD = 1 << 2,
};
class Interpreter {
std::mt19937 random_generator;
public:
std::vector<uint8_t> memory;
std::vector<uint16_t> v;
std::vector<uint16_t> stack;
uint16_t pc;
uint8_t sp;
uint16_t i;
uint8_t dt;
uint8_t st;
std::bitset<2048> display;
uint16_t keyboard;
private:
uint8_t quirks;
void load_fonts();
void clear_screen();
void return_from_subrutine();
void jump(uint16_t nnn);
void call_subrutine(uint16_t nnn);
void skip_if_vx_eq_val(uint8_t x, uint8_t kk);
void skip_if_vx_neq_val(uint8_t x, uint8_t kk);
void skip_if_vx_eq_vy(uint8_t x, uint8_t y);
void load_vx_val(uint8_t x, uint8_t kk);
void add_vx_val(uint8_t x, uint8_t kk);
void load_vx_vy(uint8_t x, uint8_t y);
void vx_or_vy(uint8_t x, uint8_t y);
void vx_and_vy(uint8_t x, uint8_t y);
void vx_xor_vy(uint8_t x, uint8_t y);
void vx_add_vy(uint8_t x, uint8_t y);
void vx_sub_vy(uint8_t x, uint8_t y);
void vx_shift_right(uint8_t x);
void vx_shift_right_cosmac(uint8_t x, uint8_t y);
void vx_subn_vy(uint8_t x, uint8_t y);
void vx_shift_left(uint8_t x);
void vx_shift_left_cosmac(uint8_t x, uint8_t y);
void skip_if_vx_neq_vy(uint8_t x, uint8_t y);
void set_index_val(uint16_t nnn);
void jump_with_offset(uint16_t nnn);
void jump_with_offset_super_chip(uint8_t x, uint16_t nnn);
void set_random_value(uint8_t x, uint8_t kk);
void display_sprite(uint8_t x, uint8_t y, uint8_t n);
void skip_if_key_pressed(uint8_t x);
void skip_if_key_not_pressed(uint8_t x);
void load_vx_dt(uint8_t x);
void get_key(uint8_t x);
void load_dt_vx(uint8_t x);
void load_st_vx(uint8_t x);
void add_i_vx(uint8_t x);
void font_sprite_location(uint8_t x);
void calculate_bcd(uint8_t x);
void store_registers_to_memory(uint8_t x);
void load_registers_from_memory(uint8_t x);
public:
Interpreter();
void set_quirks(uint8_t quirks);
void load_rom(const std::vector<uint8_t>& rom);
void run();
void debug_display_console();
};
#endif //INTERPRETER_H

33
src/bitops.h Normal file
View File

@@ -0,0 +1,33 @@
//
// Created by ryuuji on 6/21/25.
//
#ifndef BITOPS_H
#define BITOPS_H
#include <type_traits>
template <typename T>
T bit_set(const T number, const int bit) {
static_assert(std::is_unsigned_v<T>, "T must be an unsigned integral type");
return number | (1 << bit);
}
template <typename T>
T bit_clear(const T number, const int bit) {
static_assert(std::is_unsigned_v<T>, "T must be an unsigned integral type");
return number & ~(1 << bit);
}
template <typename T>
T bit_toggle(const T number, const int bit) {
static_assert(std::is_unsigned_v<T>, "T must be an unsigned integral type");
return number ^ (1 << bit);
}
template <typename T>
bool bit_check(const T number, const int bit) {
static_assert(std::is_unsigned_v<T>, "T must be an unsigned integral type");
return (number >> bit) & 1;
}
#endif //BITOPS_H

41
src/main.cpp Normal file
View File

@@ -0,0 +1,41 @@
#define SDL_MAIN_USE_CALLBACKS 1
#include <iostream>
#include <bits/ostream.tcc>
#include <SDL3/SDL_main.h>
#include "Chip8.h"
SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
const auto chip8 = new Chip8();
*appstate = chip8;
if (!chip8->init()) {
return SDL_APP_FAILURE;
}
int num_keys;
const bool* kb_state = SDL_GetKeyboardState(&num_keys);
const std::span kb_state_view(kb_state, num_keys);
chip8->set_keyboard_state(kb_state_view);
return SDL_APP_CONTINUE;
}
SDL_AppResult SDL_AppIterate(void* appstate) {
const auto chip8 = static_cast<Chip8*>(appstate);
chip8->update();
return SDL_APP_CONTINUE;
}
SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS;
}
return SDL_APP_CONTINUE;
}
void SDL_AppQuit(void* appstate, SDL_AppResult result) {
const auto chip8 = static_cast<Chip8*>(appstate);
delete chip8;
}

4
vendor/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,4 @@
add_subdirectory(SDL)
add_library(vendor INTERFACE)
target_link_libraries(vendor INTERFACE SDL3::SDL3)

1
vendor/SDL vendored Submodule

Submodule vendor/SDL added at c9a6709bd2