start implementation for I/O in the machine

This commit is contained in:
Thiago Auler dos Santos 2017-11-17 20:54:19 -02:00
parent 6eb4aaa858
commit 152c6e15fa
11 changed files with 298 additions and 12 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
obj
apple1
.DS_Store

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<VariablesViewState
version = "1.0">
<ContextStates>
<ContextState
contextName = "decode:6502.c">
<PersistentStrings>
<PersistentString
value = "ir">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "run:6502.c">
<PersistentStrings>
<PersistentString
value = "address_mode">
</PersistentString>
<PersistentString
value = "display_buffer">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "bpl:opcodes.c">
<PersistentStrings>
<PersistentString
value = "pc">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "fetch:6502.c">
<PersistentStrings>
<PersistentString
value = "ir">
</PersistentString>
</PersistentStrings>
</ContextState>
</ContextStates>
</VariablesViewState>

View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "src/memory.c"
timestampString = "532651865.10765"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "111"
endingLineNumber = "111"
landmarkName = "write_mem"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "src/memory.c"
timestampString = "532651865.107738"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "55"
endingLineNumber = "55"
landmarkName = "read_byte"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "src/6502.c"
timestampString = "532651865.107805"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "150"
endingLineNumber = "150"
landmarkName = "display"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "src/6502.c"
timestampString = "532651865.108152"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "164"
endingLineNumber = "164"
landmarkName = "run"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>

View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AFF1A1DE1FBD2A490069B921"
BuildableName = "apple1"
BlueprintName = "apple1"
ReferencedContainer = "container:apple1.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AFF1A1DE1FBD2A490069B921"
BuildableName = "apple1"
BlueprintName = "apple1"
ReferencedContainer = "container:apple1.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AFF1A1DE1FBD2A490069B921"
BuildableName = "apple1"
BlueprintName = "apple1"
ReferencedContainer = "container:apple1.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AFF1A1DE1FBD2A490069B921"
BuildableName = "apple1"
BlueprintName = "apple1"
ReferencedContainer = "container:apple1.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>apple1.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>AFF1A1DE1FBD2A490069B921</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>

View File

@ -1,3 +1,5 @@
#include <stdio.h>
#include "inc/types.h"
#include "inc/memory.h"
#include "inc/opcodes.h"
@ -79,7 +81,7 @@ void execute()
case BMI: return bmi();
case BNE: return bne();
case BPL: return bpl();
case BRK: return brk();
case BRK: return bkk();
case BVC: return bvc();
case BVS: return bvs();
case CLC: return clc();
@ -137,6 +139,25 @@ void execute()
}
}
void display()
{
//if (display_control == 0xA7)
{
// display is ready to ouptup
if (display_buffer & 0x80)
{
// outputs the buffer character
display_buffer = display_buffer & 0x7F;
printf("%c", display_buffer);
}
}
}
void read_input()
{
// verifies if the keyboard is being pressed...
}
void run()
{
while (1)
@ -144,6 +165,9 @@ void run()
fetch();
decode();
execute();
display();
read_input();
}
}

View File

@ -2,8 +2,14 @@
#define _APPLE_I_MEMORY_H_
#include "types.h"
db read_byte(dw address);
dw read_word(dw address);
void write_mem(dw address, db data);
extern db keyboard_buffer; // 0xD010
extern db keyboard_control; // 0xD011
extern db display_buffer; // 0xD012
extern db display_control; // 0xD013
#endif

View File

@ -64,7 +64,7 @@ void bit(void); // test bits in memory with accumulator
void bmi(void); // branch on result minus
void bne(void); // branch on result not zero
void bpl(void); // branch on result plus
void brk(void); // force break
void bkk(void); // force break
void bvc(void); // branch on overflow clear
void bvs(void); // branch on overflow set
void clc(void); // clear carry flag

View File

@ -1,7 +1,6 @@
#include "inc/types.h"
#include "inc/rom.h"
#include "inc/memory.h"
#include <stdio.h>
/*
@ -33,7 +32,12 @@
*/
db ram_memory[4096]; // total memory: 4KB
db ram_memory[4096]; // total memory: 4KB
db keyboard_buffer; // 0xD010
db keyboard_control; // 0xD011
db display_buffer; // 0xD012
db display_control; // 0xD013
db read_byte(dw address)
{
@ -42,6 +46,22 @@ db read_byte(dw address)
// 4KB memory RAM
return ram_memory[address];
}
else if (address == 0xD010)
{
return keyboard_buffer;
}
else if (address == 0xD011)
{
return keyboard_control;
}
else if (address == 0xD012)
{
return display_buffer;
}
/*else if (address == 0xD013)
{
return display_control;
}*/
else if (address >= 0xFF00 && address <= 0xFFFF)
{
// wozmon ROM
@ -78,11 +98,22 @@ void write_mem(dw address, db data)
// 4KB memory RAM
ram_memory[address] = data;
}
/*else if (address == 0xD010)
{
keyboard_buffer = data;
}*/
/*else if (address == 0xD011)
{
keyboard_control = data;
}*/
else if (address == 0xD012)
{
// output character to video
printf("%c", data & 0x7F);
display_buffer = data;
}
/*else if (address == 0xD013)
{
display_control = data;
}*/
// any other addressed memory will be ignored on write
}

View File

@ -150,9 +150,9 @@ db pull_byte()
dw pull_word()
{
db high = pull_byte() << 8;
db high = pull_byte();
db low = pull_byte();
dw data = high | low;
dw data = high << 8 | low;
return data;
}
@ -261,7 +261,7 @@ void bpl()
}
}
void brk()
void bkk()
{
// force break
I_SET;
@ -583,7 +583,6 @@ void sta()
// store accumulator in memory
fetch_operand();
write_mem(address, ac);
//adjustNZ(y);
}
void stx()
@ -591,7 +590,6 @@ void stx()
// store index x in memory
fetch_operand();
write_mem(address, x);
//adjustNZ(x);
}
void sty()
@ -599,7 +597,6 @@ void sty()
// store index y in memory
fetch_operand();
write_mem(address, y);
//adjustNZ(y);
}
void tax()