Created simple upload tool to upload file contents to the Apple 1 over serial.

Improved firmware code.
This commit is contained in:
Ruud van Falier 2017-08-02 07:59:39 +02:00
parent ea2f82f56e
commit e76f98fe05
11 changed files with 403 additions and 94 deletions

63
.gitattributes vendored Normal file
View File

@ -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

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
tmp/ tmp/
design/DesignSpark/gbrl design/DesignSpark/gbrl
obj
bin
.vs

View File

@ -5,3 +5,8 @@ This is my take on an Apple 1 replica.
Also lot's of lessons were learned and resources taken from The Ben Heck Show: https://github.com/thebenheckshow/158-tbhs-apple-1-replica Also lot's of lessons were learned and resources taken from The Ben Heck Show: https://github.com/thebenheckshow/158-tbhs-apple-1-replica
*This build is currently in progress* *This build is currently in progress*
Pictures of the current state (revision 0):
![First board revision](https://github.com/DutchMaker/Apple-1-Replica/raw/master/docs/revision0.jpg "First board revision")
![Firmware screenshot](https://github.com/DutchMaker/Apple-1-Replica/raw/master/docs/screenshot.png "Firmware screenshot")

View File

@ -1,104 +1,139 @@
// ----------------------------------------------------------------------------- // ---------------------------------------------------------------------------------- //
// Apple 1 Replica firmware for Arduino // Apple 1 Replica firmware for Arduino //
// // //
// Version 1.0 // Version 1.0 //
// By Ruud van Falier // By Ruud van Falier //
// // //
// Enables serial communication between an Arduino and the Apple 1 PIA. // Enables serial communication between an Arduino and the Apple 1 PIA. //
// Heavily based on Propeller source code from Briel Computers Apple 1 replica. // Also implements a blinking cursor and green text using VT100 escape codes //
// ----------------------------------------------------------------------------- // (VT100 codes only tested with PuTTY client!) //
// //
// Heavily based on Propeller source code from Briel Computers' Apple 1 replica. //
// ---------------------------------------------------------------------------------- //
// Port definitions (Arduino pins connected to the PIA) // Port definitions (Arduino pins connected to the PIA)
#define DA A0 #define PIN_DA A0
#define RDA A1 #define PIN_RDA A1
#define PB0 2 #define PIN_PB0 2
#define PB1 3 #define PIN_PB1 3
#define PB2 4 #define PIN_PB2 4
#define PB3 A5 #define PIN_PB3 A5
#define PB4 A4 #define PIN_PB4 A4
#define PB5 A3 #define PIN_PB5 A3
#define PB6 A2 #define PIN_PB6 A2
#define PA0 5 #define PIN_PA0 5
#define PA1 6 #define PIN_PA1 6
#define PA2 7 #define PIN_PA2 7
#define PA3 8 #define PIN_PA3 8
#define PA4 9 #define PIN_PA4 9
#define PA5 10 #define PIN_PA5 10
#define PA6 11 #define PIN_PA6 11
#define STROBE 12 #define PIN_STROBE 12
// VT100 codes (u)sed for cursor implementation) #define DELAY_VIDEO 1
#define OFF "\033[0m" #define DELAY_ASCII 1
#define BLINK "\033[5m"
#define COLOR "\033[35m" // VT100 codes (used for cursor and text color implementation)
#define BLINK_COLOR "\033[5;35m" #define VT100_OFF "\033[0m" // Disable formatting
#define BOLD_COLOR "\033[1;35m" #define VT100_DEFAULT "\033[32m" // Color green
#define CLS "\033[2J" #define VT100_BLINK "\033[5;32m" // Blink color green
#define BACKSPACE "\010" #define VT100_BOLD "\033[1;32m" // Bold color green
#define VT100_CLS "\033[2J" // Clear screen
#define VT100_RESET_CURSOR "\033[H" // Position cursor in top left corner
#define VT100_CURSOR_LEFT "\033[1D" // Move cursor one column to the left
#define VT100_ERASE_EOL "\033[K" // Erase from cursor until end of line
#define CURSOR_CHAR "@" #define CURSOR_CHAR "@"
// Global variables
uint8_t video_data = 0; uint8_t video_data = 0;
uint8_t video_data_pins[] = { PB0, PB1, PB2, PB3, PB4, PB5, PB6 }; uint8_t video_data_pins[] = { PIN_PB0, PIN_PB1, PIN_PB2, PIN_PB3, PIN_PB4, PIN_PB5, PIN_PB6 };
uint8_t serial_data; uint8_t serial_data;
bool cursor_visible = false; bool cursor_visible = false;
/*
* Program initialization
*/
void setup() void setup()
{ {
// Setup video data pins (output from the PIA) // Setup video data pins (output from the PIA)
pinMode(RDA, OUTPUT); pinMode(PIN_RDA, OUTPUT);
pinMode(DA, INPUT); pinMode(PIN_DA, INPUT);
pinMode(PB0, INPUT); pinMode(PIN_PB0, INPUT);
pinMode(PB1, INPUT); pinMode(PIN_PB1, INPUT);
pinMode(PB2, INPUT); pinMode(PIN_PB2, INPUT);
pinMode(PB3, INPUT); pinMode(PIN_PB3, INPUT);
pinMode(PB4, INPUT); pinMode(PIN_PB4, INPUT);
pinMode(PB5, INPUT); pinMode(PIN_PB5, INPUT);
pinMode(PB6, INPUT); pinMode(PIN_PB6, INPUT);
// Setup ASCII data pins (input for the PIA) // Setup ASCII data pins (input for the PIA)
pinMode(STROBE, OUTPUT); pinMode(PIN_STROBE, OUTPUT);
pinMode(PA0, OUTPUT); pinMode(PIN_PA0, OUTPUT);
pinMode(PA1, OUTPUT); pinMode(PIN_PA1, OUTPUT);
pinMode(PA2, OUTPUT); pinMode(PIN_PA2, OUTPUT);
pinMode(PA3, OUTPUT); pinMode(PIN_PA3, OUTPUT);
pinMode(PA4, OUTPUT); pinMode(PIN_PA4, OUTPUT);
pinMode(PA5, OUTPUT); pinMode(PIN_PA5, OUTPUT);
pinMode(PA6, OUTPUT); pinMode(PIN_PA6, OUTPUT);
Serial.begin(9600); Serial.begin(9600);
cursor_visible = false; display_boot_message();
Serial.print(CLS);
Serial.print(BOLD_COLOR);
Serial.println("Apple 1 Replica");
Serial.print(OFF);
Serial.print(COLOR);
Serial.println("Firmware version 1.0");
Serial.println("Ruud van Falier, 2017");
Serial.println("---------------------------------");
Serial.println();
Serial.println("Ready...");
Serial.print(OFF);
show_cursor();
} }
/*
* Program loop
*/
void loop() void loop()
{ {
process_video_data(); process_video_data();
process_serial_data(); process_serial_data();
} }
/*
* Displays the Apple 1 Replica firmware boot message and enables the blinking cursor
*/
void display_boot_message()
{
cursor_visible = false;
Serial.print(VT100_CLS);
Serial.print(VT100_RESET_CURSOR);
Serial.print(VT100_OFF);
Serial.print(VT100_DEFAULT);
Serial.println("+-----------------------+");
Serial.print("| ");
Serial.print(VT100_OFF);
Serial.print(VT100_BOLD);
Serial.print("APPLE 1 REPLICA");
Serial.print(VT100_OFF);
Serial.print(VT100_DEFAULT);
Serial.println(" |");
Serial.print(VT100_OFF);
Serial.print(VT100_DEFAULT);
Serial.println("|-----------------------|");
Serial.println("| FIRMWARE VERSION 1.0 |");
Serial.println("| RUUD VAN FALIER, 2017 |");
Serial.println("+-----------------------+");
Serial.println();
Serial.println("READY...");
Serial.println();
Serial.print(VT100_OFF);
show_cursor();
}
/* /*
* Retrieves video (character) data from the PIA and sends it to the user over the serial connection. * Retrieves video (character) data from the PIA and sends it to the user over the serial connection.
*/ */
void process_video_data() void process_video_data()
{ {
// Tell the PIA we are ready to receive data. // Tell the PIA we are ready to receive data.
digitalWrite(RDA, HIGH); digitalWrite(PIN_RDA, HIGH);
delay(10); delay(DELAY_VIDEO);
if (digitalRead(DA)) while (digitalRead(PIN_DA))
{ {
// Data is available. // Data is available.
video_data = 0; video_data = 0;
@ -112,6 +147,7 @@ void process_video_data()
} }
} }
// Send video data over serial connection.
if (video_data == 13) if (video_data == 13)
{ {
// Carrage return. // Carrage return.
@ -122,18 +158,21 @@ void process_video_data()
{ {
// Display-compatible character. // Display-compatible character.
hide_cursor(); hide_cursor();
Serial.print(COLOR); Serial.print(VT100_DEFAULT);
Serial.print((char)video_data); Serial.print((char)video_data);
Serial.print(OFF); Serial.print(VT100_OFF);
} }
digitalWrite(RDA, LOW); // Done receiving this byte.
delay(10); digitalWrite(PIN_RDA, LOW);
delay(DELAY_VIDEO);
// Tell the PIA we are ready to receive more data.
digitalWrite(PIN_RDA, HIGH);
delay(DELAY_VIDEO);
} }
else
{
show_cursor(); show_cursor();
}
} }
/* /*
@ -143,7 +182,7 @@ void process_video_data()
void process_serial_data() void process_serial_data()
{ {
// Wait for serial data coming in. // Wait for serial data coming in.
if (Serial.available() > 0) while (Serial.available() > 0)
{ {
serial_data = Serial.read(); serial_data = Serial.read();
@ -162,19 +201,21 @@ void process_serial_data()
if (serial_data < 96) if (serial_data < 96)
{ {
// Encode any Apple 1 compatible character to data bits. // Encode any Apple 1 compatible character to data bits.
digitalWrite(PA6, bitRead(serial_data, 6)); digitalWrite(PIN_PA6, bitRead(serial_data, 6));
digitalWrite(PA5, bitRead(serial_data, 5)); digitalWrite(PIN_PA5, bitRead(serial_data, 5));
digitalWrite(PA4, bitRead(serial_data, 4)); digitalWrite(PIN_PA4, bitRead(serial_data, 4));
digitalWrite(PA3, bitRead(serial_data, 3)); digitalWrite(PIN_PA3, bitRead(serial_data, 3));
digitalWrite(PA2, bitRead(serial_data, 2)); digitalWrite(PIN_PA2, bitRead(serial_data, 2));
digitalWrite(PA1, bitRead(serial_data, 1)); digitalWrite(PIN_PA1, bitRead(serial_data, 1));
digitalWrite(PA0, bitRead(serial_data, 0)); digitalWrite(PIN_PA0, bitRead(serial_data, 0));
// Pulse the STROBE bit so the PIA will process the input. // Pulse the STROBE bit so the PIA will process the input.
digitalWrite(STROBE, HIGH); digitalWrite(PIN_STROBE, HIGH);
delay(20); delay(DELAY_ASCII);
digitalWrite(STROBE, LOW); digitalWrite(PIN_STROBE, LOW);
} }
process_video_data();
} }
} }
@ -185,7 +226,8 @@ void hide_cursor()
{ {
if (cursor_visible) if (cursor_visible)
{ {
Serial.print(BACKSPACE); Serial.print(VT100_CURSOR_LEFT);
Serial.print(VT100_ERASE_EOL);
cursor_visible = false; cursor_visible = false;
} }
} }
@ -197,9 +239,9 @@ void show_cursor()
{ {
if (!cursor_visible) if (!cursor_visible)
{ {
Serial.print(BLINK_COLOR); Serial.print(VT100_BLINK);
Serial.print(CURSOR_CHAR); Serial.print(CURSOR_CHAR);
Serial.print(OFF); Serial.print(VT100_OFF);
cursor_visible = true; cursor_visible = true;
} }
} }

View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Uploader", "Uploader\Uploader.csproj", "{A6D02388-9408-492F-A165-B6D4EA110558}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A6D02388-9408-492F-A165-B6D4EA110558}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A6D02388-9408-492F-A165-B6D4EA110558}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6D02388-9408-492F-A165-B6D4EA110558}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6D02388-9408-492F-A165-B6D4EA110558}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View File

@ -0,0 +1,79 @@
using System;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace Uploader
{
class Program
{
private const string PORT = "COM7";
private static SerialPort serial = new SerialPort(PORT, 9600, Parity.None, 8, StopBits.One);
[STAThread]
static void Main(string[] args)
{
var dialog = new OpenFileDialog();
dialog.Title = "Select file to upload...";
if (dialog.ShowDialog() == DialogResult.OK)
{
serial.DataReceived += Serial_DataReceived;
serial.Open();
Console.WriteLine("Connected...");
Console.WriteLine($"Uploading {dialog.FileName}");
using (var reader = new StreamReader(dialog.FileName, Encoding.ASCII))
{
int progress = 0;
long total = reader.BaseStream.Length;
while (reader.Peek() >= 0)
{
int data = reader.Read();
if (data < 96)
{
serial.Write(new byte[] { (byte)data }, 0, 1);
Thread.Sleep(50);
if (data == 13)
{
Thread.Sleep(150);
}
Console.Write((char)data);
}
Progress(++progress, total);
}
}
serial.WriteLine("");
serial.Close();
Console.Title = "Upload succeeded!";
Console.WriteLine("\r\nDone! Connection closed.");
}
Console.ReadKey();
}
private static void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
serial.ReadExisting();
}
private static void Progress(int progress, long total)
{
decimal percentage = progress / ((decimal)total / 100);
Console.Title = $"Uploading... ({progress:N0} of {total:N0} bytes - {percentage:N2}%)";
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Uploader")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Uploader")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a6d02388-9408-492f-a165-b6d4ea110558")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A6D02388-9408-492F-A165-B6D4EA110558}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Uploader</RootNamespace>
<AssemblyName>Uploader</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

BIN
docs/revision0.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

BIN
docs/screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB