From 19733ba72b9b0ab36715250cf2ad6f2bc0c4765f Mon Sep 17 00:00:00 2001 From: Daniel Loffgren Date: Mon, 14 Sep 2015 00:24:03 +0000 Subject: [PATCH] Some very basic PIA functionality git-svn-id: svn+ssh://svn.phoenixbox.net/svn/apple1/trunk@5 64f78de7-aa59-e511-a0e8-0002a5492df0 --- apple1.xcodeproj/project.pbxproj | 6 ++++++ apple1/pia.c | 30 ++++++++++++++++++++++++++++++ apple1/pia.h | 22 ++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 apple1/pia.c create mode 100644 apple1/pia.h diff --git a/apple1.xcodeproj/project.pbxproj b/apple1.xcodeproj/project.pbxproj index 14e2a05..442b703 100644 --- a/apple1.xcodeproj/project.pbxproj +++ b/apple1.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ E668389E1BA4F51E008F0F06 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = E668389D1BA4F51E008F0F06 /* main.c */; }; E66839001BA4F75C008F0F06 /* liblibv6502.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E66838F61BA4F705008F0F06 /* liblibv6502.a */; }; + E66839061BA53A82008F0F06 /* pia.c in Sources */ = {isa = PBXBuildFile; fileRef = E66839041BA53A82008F0F06 /* pia.c */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -114,6 +115,8 @@ E668389A1BA4F51E008F0F06 /* apple1 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = apple1; sourceTree = BUILT_PRODUCTS_DIR; }; E668389D1BA4F51E008F0F06 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; E66838D31BA4F705008F0F06 /* v6502.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = v6502.xcodeproj; path = v6502/v6502.xcodeproj; sourceTree = SOURCE_ROOT; }; + E66839041BA53A82008F0F06 /* pia.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pia.c; sourceTree = ""; }; + E66839051BA53A82008F0F06 /* pia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pia.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -149,6 +152,8 @@ isa = PBXGroup; children = ( E668389D1BA4F51E008F0F06 /* main.c */, + E66839041BA53A82008F0F06 /* pia.c */, + E66839051BA53A82008F0F06 /* pia.h */, ); path = apple1; sourceTree = ""; @@ -322,6 +327,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + E66839061BA53A82008F0F06 /* pia.c in Sources */, E668389E1BA4F51E008F0F06 /* main.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/apple1/pia.c b/apple1/pia.c new file mode 100644 index 0000000..1ac78ac --- /dev/null +++ b/apple1/pia.c @@ -0,0 +1,30 @@ +// +// pia.c +// apple1 +// +// Created by Daniel Loffgren on 9/12/15. +// Copyright (c) 2015 Daniel Loffgren. All rights reserved. +// + +#include "pia.h" +#include +#include + +#define FIXME_I_SHOULDNT_BE_NULL NULL + +void videoWriteCharCallback(struct _v6502_memory *memory, uint16_t offset, uint8_t value, void *context) { + fprintf(stdout, ANSI_COLOR_BRIGHT_GREEN "%c" ANSI_COLOR_RESET, value); + fflush(stdout); +} + +void videoWriteNewlineCallback(struct _v6502_memory *memory, uint16_t offset, uint8_t value, void *context) { + fprintf(stdout, ANSI_COLOR_BRIGHT_GREEN "\n" ANSI_COLOR_RESET); + fflush(stdout); +} + +void pia_map(v6502_memory *mem) { + v6502_map(mem, A1PIA_KEYBOARD_INPUT, 1, FIXME_I_SHOULDNT_BE_NULL, NULL, NULL); + v6502_map(mem, A1PIA_KEYBOARD_CRLF_REG, 1, FIXME_I_SHOULDNT_BE_NULL, NULL, NULL); + v6502_map(mem, A1PIA_VIDEO_OUTPUT, 1, FIXME_I_SHOULDNT_BE_NULL, videoWriteCharCallback, NULL); + v6502_map(mem, A1PIA_VIDEO_CRLF_REG, 1, FIXME_I_SHOULDNT_BE_NULL, videoWriteNewlineCallback, NULL); +} \ No newline at end of file diff --git a/apple1/pia.h b/apple1/pia.h new file mode 100644 index 0000000..fc43e4e --- /dev/null +++ b/apple1/pia.h @@ -0,0 +1,22 @@ +// +// pia.h +// apple1 +// +// Created by Daniel Loffgren on 9/12/15. +// Copyright (c) 2015 Daniel Loffgren. All rights reserved. +// + +#ifndef __apple1__pia__ +#define __apple1__pia__ + +#include + +#define A1PIA_KEYBOARD_INPUT 0xD010 +#define A1PIA_KEYBOARD_CRLF_REG 0xD011 +#define A1PIA_VIDEO_OUTPUT 0xD012 +#define A1PIA_VIDEO_CRLF_REG 0xD013 + +// Assumes stdin/stdout +void pia_map(v6502_memory *mem); + +#endif /* defined(__apple1__pia__) */