Skip to content

Commit

Permalink
Added EEPROM library and DecimalDisplay. Updated README.
Browse files Browse the repository at this point in the history
  • Loading branch information
Troy committed Sep 24, 2019
1 parent 7dc9bde commit e6da878
Show file tree
Hide file tree
Showing 17 changed files with 297 additions and 62 deletions.
176 changes: 176 additions & 0 deletions Arduino/DecimalDisplay/DecimalDisplay.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* Troy's 8-bit computer - Arduino DecimalDisplay EEPROM programmer
*
* Copyright (c) 2019 Troy Schrapel
*
* This code is licensed under the MIT license
*
* The dicimal display can operate in three modes controlled by the
* EEPROM's 8 and 9 address pins.
*
* 9 | 8
* --+--
* 0 | 0 Unsigned decimal
* 0 | 1 Signed decimal
* 1 | X Hexadecimal
*
* https://github.com/visrealm/vrcpu
*
*/

#include "vrEEPROM.h"


#define EEPROM_D0 5 // data LSB

#define SHIFT_DATA 2 // data to shift into shift register
#define SHIFT_CLK 3 // pos-edge clock for shift register
#define DFF_CLK 4 // pos-edge clock for DFF to set after filling shift register

#define EEPROM_READ_EN A0 // active-low EEPROM read enable
#define EEPROM_WRITE_EN 13 // active-low EEPROM write enable


EEPROM eeprom(EEPROM_D0, EEPROM_READ_EN, EEPROM_WRITE_EN, SHIFT_DATA, SHIFT_CLK, DFF_CLK);


#define DP_HOR_TOP (1 << 5)
#define DP_HOR_MID (1 << 4)
#define DP_HOR_BOTTOM (1 << 1)
#define DP_VER_LTOP (1 << 6)
#define DP_VER_LBOTTOM (1 << 0)
#define DP_VER_RTOP (1 << 7)
#define DP_VER_RBOTTOM (1 << 3)
#define DP_POINT (1 << 2)

uint8_t digits[] = {
/* 0 */ DP_HOR_TOP | DP_HOR_BOTTOM | DP_VER_LTOP | DP_VER_RTOP | DP_VER_LBOTTOM | DP_VER_RBOTTOM,
/* 1 */ DP_VER_RTOP | DP_VER_RBOTTOM,
/* 2 */ DP_HOR_TOP | DP_VER_RTOP | DP_HOR_MID | DP_VER_LBOTTOM | DP_HOR_BOTTOM,
/* 3 */ DP_HOR_TOP | DP_VER_RTOP | DP_HOR_MID | DP_VER_RBOTTOM | DP_HOR_BOTTOM,
/* 4 */ DP_VER_LTOP | DP_VER_RTOP | DP_HOR_MID | DP_VER_RBOTTOM,
/* 5 */ DP_HOR_TOP | DP_VER_LTOP | DP_HOR_MID | DP_VER_RBOTTOM | DP_HOR_BOTTOM,
/* 6 */ DP_HOR_TOP | DP_VER_LTOP | DP_HOR_MID | DP_VER_LBOTTOM | DP_VER_RBOTTOM | DP_HOR_BOTTOM,
/* 7 */ DP_HOR_TOP | DP_VER_RTOP | DP_VER_RBOTTOM,
/* 8 */ DP_HOR_TOP | DP_HOR_MID | DP_HOR_BOTTOM | DP_VER_LTOP | DP_VER_RTOP | DP_VER_LBOTTOM | DP_VER_RBOTTOM,
/* 9 */ DP_HOR_TOP | DP_HOR_MID | DP_HOR_BOTTOM | DP_VER_LTOP | DP_VER_RTOP | DP_VER_RBOTTOM,
/* A */ DP_HOR_TOP | DP_HOR_MID | DP_VER_LTOP | DP_VER_RTOP | DP_VER_LBOTTOM | DP_VER_RBOTTOM,
/* b */ DP_HOR_MID | DP_VER_LTOP | DP_VER_LBOTTOM | DP_VER_RBOTTOM | DP_HOR_BOTTOM,
/* C */ DP_HOR_TOP | DP_VER_LTOP | DP_VER_LBOTTOM | DP_HOR_BOTTOM,
/* d */ DP_HOR_MID | DP_VER_RTOP | DP_VER_LBOTTOM | DP_VER_RBOTTOM | DP_HOR_BOTTOM,
/* E */ DP_HOR_TOP | DP_HOR_MID | DP_HOR_BOTTOM | DP_VER_LBOTTOM | DP_VER_LTOP,
/* F */ DP_HOR_TOP | DP_HOR_MID | DP_VER_LBOTTOM | DP_VER_LTOP,
/* H */ DP_HOR_MID | DP_VER_LTOP | DP_VER_RTOP | DP_VER_LBOTTOM | DP_VER_RBOTTOM,
};



byte valueForAddress(uint16_t address)
{
uint8_t number = address & 0xff;
bool isSigned = (address & 0x400) != 0;
bool isHex = (address & 0x800) != 0;

// negative
if (isHex)
{
address -= 2048;
if (isSigned)
{
address -= 1024;
}

if (address < 256)
{
return 0x00;
}
else if (address < 512)
{
return digits[16];
}
else if (address < 768)
{
return digits[(address >> 4) & 0x0f];
}
else
{
return digits[address & 0x0f];
}

return 0xff;
}
else if (isSigned)
{
if ((address & 0x080) != 0)
{
number = ~number + 1;
}
else
{
isSigned = false;
}
address -= 1024;
}


if (address < 256) // 00 display mode, 00 digit (0 - 255)
{
return isSigned ? DP_HOR_MID : 0x00;
}
else if (address < 512) // 00 display mode, 01 digit (256 - 511)
{
return digits[(number / 100) % 10];
}
else if (address < 768) // 00 display mode, 10 digit (512 - 767)
{
return digits[(number / 10) % 10];
}
else if (address < 1024) // 00 display mode, 11 digit (512 - 767)
{
return digits[number % 10];
}

return 0x00;
}

void writeDisplayDigits()
{
for (uint16_t addr = 0; addr < 4096; ++addr)
{
eeprom.write(addr, valueForAddress(addr));

if ((addr % 128) == 0) {
Serial.print(".");
}
}
eeprom.endWrite();
return;
}



void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial) { delay(10); }

Serial.print("Programming EEPROM");
Serial.flush();

writeDisplayDigits();



Serial.println(" Done writing");
Serial.flush();

eeprom.dump(0, 4096);

Serial.println("Done reading");
Serial.flush();
}

void loop()
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
*
*/

#include "EEPROM.h"
#include "vrEEPROM.h"
#include "Arduino.h"

#define DEFAULT_PAGE_SIZE 128


EEPROM::EEPROM(
int dataPin0,
int readPin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*
*/

#ifndef _EEPROM_H
#define _EEPROM_H
#ifndef VR_EEPROM_H
#define VR_EEPROM_H

#include <stdint.h>

Expand Down
2 changes: 1 addition & 1 deletion Arduino/Microcode/Microcode.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
*/

#include "EEPROM.h"
#include "vrEEPROM.h"


// Output a report of unused op codes after each EEPROM is written ?
Expand Down
11 changes: 8 additions & 3 deletions Arduino/ProgramLoader/ProgramLoader.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/*
* Troy's 8-bit computer - esp8266 Wi-Fi program loader
*
* Copyright (c) 2019 Troy Schrapel
*
* This code is licensed under the MIT license
*
* Needs to control
* Bus
Expand All @@ -14,6 +19,9 @@
* - Disables the BUS_W 3->8
* - Enables PGM
* - Sets the mode of the 157
*
* https://github.com/visrealm/vrcpu
*
*/


Expand Down Expand Up @@ -79,9 +87,6 @@ void setup() {


wifiMulti.addAP(SSID1, PASS1);
wifiMulti.addAP("VisualRealmSoftware2", "jibbers182");
wifiMulti.addAP("VisualRealmSoftware5", "jibbers182");
wifiMulti.addAP("visrealmS9", "hem@cva182");

Serial.begin(115200); // Start the Serial communication to send messages to the computer
delay(10);
Expand Down
23 changes: 23 additions & 0 deletions Programs/Bit Rotate (Rc).asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; BIT ROTATE - Rotate the bit pattern in register Rc
;
; Feel free to change the bit pattern below

Pattern = 0b11001100

clra
data Rb, Pattern
.begin:
nop
nop
nop
nop
nop
nop
mvc Rb
lsr
jnc .begin
.addone:
inc Rb
jmp .begin
17 changes: 17 additions & 0 deletions Programs/Fibonacci.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; FIBONACCI SEQUENCE
;
; If you want to halt instead of repeat, look
; at the jc .begin line. You might want to create
; Another label with another action to end ;)

.begin:
clra
inc Rb
.loop:
add Rc, Rb
jc .begin
mov Rd, Rc
mov Rc, Rb
mov Rb, Rd
jmp .loop
15 changes: 12 additions & 3 deletions Programs/isprime.asm → Programs/Is Prime.asm
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
; IS THE NUMBER PRIME?
; If it's prime, the rersult will be 1 (largest number divisble)
;
; Terribly basic algorithm to find if a number is prime.
;
; The result shown will be its largest factor
; If it's prime, the result will be 1
;
; Change the number on the first line below - is it prime?

data Rd, #235
NUMBER = 57

.start:
data Rd, NUMBER

mov Rb, Rd
data Ra, #7
Expand Down Expand Up @@ -34,7 +43,7 @@
hlt
.test:
jc .next
jnc .next
jmp .sub
.noresult:
Expand Down
File renamed without changes.
12 changes: 7 additions & 5 deletions Programs/reversefib.asm → Programs/Reverse Fibonacci.asm
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
; REVERSE FIBONACCI
;
; Fibonnaci sequence - in reverse

begin:
.begin:
data Rb, #144
data Rd, #233
loop:
.loop:
mov Rc,Rd
sub Rc,Rb
mov Rd,Rb
mov Rb,Rc
jnz loop
jnz .loop
next:
.next:
mov Rd,Rb
jmp begin
jmp .begin
File renamed without changes.
17 changes: 0 additions & 17 deletions Programs/bitshift.asm

This file was deleted.

13 changes: 0 additions & 13 deletions Programs/fib.asm

This file was deleted.

10 changes: 5 additions & 5 deletions Programs/powers.asm
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
; Show all power series (n^1, n^2, n^3, ...) up to base 15. Limited
; to results <= 255
; Adapted from the program by James Bates at https://github.com/jamesbates/jcpu

.begin:
clra
data Ra, #1
sto 0x00, Ra
data Rb, #1
sto 0x01, Rb
sto 0x01, Rb
.next:
data Rc, .dopow
data Rc, .dopow
call
lod Rb, 0x01
tst Rb
jz .begin
jmp .next
jnz .next
jmz
.dopow:
lod Ra, 0x00
Expand Down
Loading

0 comments on commit e6da878

Please sign in to comment.