WordPress.com



/* File: bus.h

Author: Douglas Jones, Dept. of Comp. Sci., U. of Iowa, Iowa City, IA 52242.

Date: July 26, 1995

Language: C (UNIX)

Purpose: Declarations of bus lines shared by PDP8/E and peripherals.

This is not, strictly speaking, either an omnibus or a positive

I/O bus, but rather, it is a set of declarations driven by the

needs of system emulation.

Constraints: When included in the main program, MAIN must be defined.

When included elsewhere, MAIN must not be defined.

Based on the description in the PDP-8/E Small Computer Handbook,

Digital Equipment Corporation, 1971.

*/

/***************************************************************

August 2013

heavily modified to be used un arduino mega 2560

Ricardo Das Neves Guerreiro

**************************************************************/

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

/* Includes needed by arduino */

#include //lcd library

#include //I2C library

/* creates lcd instance */

LiquidCrystal lcd_R(6,7,8,9,10,11,12);

byte i8; //because my lcd is only 40 wide

#define MAXMEM 4096

// de kk8e

int enab_del; /* secondary enable flipflop, used to delay enable operations */

long int c2; // to debug

int slow_Button = 15;

boolean slow = false;

/*****************************************************************************

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

*****************************************************************************/

/* Author = Ricardo Das Neves Guerreiro

to read focal from eeprom */

// LED TO GENERAL USE

int led_slow = 4;

byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {

byte rdata = 0xFF;

Wire.beginTransmission(deviceaddress);

Wire.write((int)(eeaddress >> 8)); // MSB

Wire.write((int)(eeaddress & 0xFF)); // LSB

Wire.endTransmission();

Wire.requestFrom(deviceaddress,1);

if (Wire.available()) rdata = Wire.read();

return rdata;

}

#define STARTADDR ((uint8_t *)0x2200)

void write_SR(byte data,word address)

{

uint8_t *addr;

addr= STARTADDR+address;

*addr = data;

}

byte read_SR(word address)

{

byte r_data;

uint8_t *addr;

addr= STARTADDR+address;

r_data = *addr;

return r_data;

}

int from_memory(int rmem)

{

byte lw,hw;

if((rmem>=0) && (rmem=0) && (rmem> 8;

write_SR(hw,(word)(rval*2));

write_SR(lw,(word)(rval*2)+1);

}

else {

}

}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

void leeprom(void)

{

word i;

byte data1,data2;

boolean ok;

lcd_R.setCursor(0,0);

lcd_R.print("leo eeprom 8192 ");

lcd_R.setCursor(0,1);

lcd_R.print(" ");

for (i=0;iaction = a;

if (t->delay >= 0) { /* timer is already scheduled */

/* don't mess up the queue, schedule becomes no-op */

} else if (head == niltimer) { /* nothing is scheduled yet */

countdown = d;

t->delay = d;

t->next = niltimer;

head = t;

} else { /* there is an existing schedule */

if (countdown > d) { /* t goes before old head */

head->delay = countdown - d;

countdown = d; /* set timer until t */

t->next = head; /* link t ahead of old head */

t->delay = d; /* mark timer as queued */

head = t; /* reset list head */

} else { /* new event goes down into queue */

struct timer * i;

i = head;

d = d - countdown; /* delay relative to head */

while (i->next != niltimer) { /* scan list for place */

if (d < i->next->delay) {

i->next->delay = i->next->delay - d;

break;

}

i = i->next;

d = d - i->delay; /* adjust delay */

}

t->next = i->next; /* link new timer into queue */

t->delay = d;

i->next = t;

}

}

}

long int query_timer(struct timer * t) /* find how much time remains on t */

{

if (t->delay < 0) { /* timer is not in queue */

return -1;

} else {

long int query = countdown;

struct timer * i = head;

while (i != t) { /* scan list for t */

i = i->next;

query = query + i->delay; /* accumulate delays */

}

return query;

}

}

void fire_timer() /* cause timer to fire at current time */

{

if (head == niltimer) { /* no pending timer */

/* put off next firing as long as possible */

countdown = 0x7FFFFFFF;

} else {

void (* a)();

/* save action for use after dequeue */

a = head->action;

/* mark head timer as idle */

head->delay = -1;

/* schedule next event */

head = head->next;

if (head == niltimer) { /* no new timer */

/* put off next firing as long as possible */

countdown = 0x7FFFFFFF;

} else {

/* figure delay till next timer */

countdown = countdown + head->delay;

/* note: this could have been countdown = head->delay,

except that countdown could have gone slightly

negative, and we want to make delays add nicely

for such devices as line frequency clocks */

}

/* fire action on head timer */

(* a)();

}

}

/*****************************************************************************

/*****************************************************************************

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

*****************************************************************************/

/* File: kl8e.c

Author: Douglas Jones, Dept. of Comp. Sci., U. of Iowa, Iowa City, IA 52242.

Date: Feb. 29, 1996

Language: C (UNIX)

Purpose: DEC KL8/E console teletype emulator, for the console device only!

Emulators for other asynchronous interfaces must be constructed

separately.

Based on the description in the PDP-8/E Small Computer Handbook,

Digital Equipment Corporation, 1971.

Uses nonblocking polling to grab characters from the keyboard. This is

a bit too synchronous a style of reading, but until ttyaccess.c can be

made to use interrupts, it will do. As a result, this should look to

software as if it is reading from a synchronous data line interface

that automatically discards pad characters. Users who type too fast

will note that their input-overruns lead to lost data.

*/

/*********************************************************************/

/* options: The user may change the speed of the simulated teletype */

/* to any positive value. DEC sold the KL8E in the following */

/* standard versions with an RS232 interface: */

/* */

/* KL8E option: A B C D E F G */

/* M8650 version: - YA YA YA YA YA YA */

/* Transmit baud rate: 110 150 300 600 1200 1200 2400 */

/* Receive baud rate: 110 150 300 600 1200 150 150 */

/* Receive baud rate: 110 150 300 600 1200 150 150 */

/* */

/* In fact, the M8650 YA board could be jumpered to handle 2400, */

/* 4800 and 9600 baud on both input and output, but DEC didn't tell */

/* people about this, at least not in the manual. */

/*********************************************************************/

/* translations from baud rate to time per character */

#define baud110 (100 * millisecond)

#define baud150 ( 66667 * microsecond)

#define baud300 ( 33333 * microsecond)

#define baud600 ( 16667 * microsecond)

#define baud1200 ( 8333 * microsecond)

#define baud2400 ( 4166 * microsecond)

#define baud4800 ( 2083 * microsecond)

#define baud9600 ( 1041 * microsecond)

/* select the baud rate here (note: if the emulator runs at 1/10 the speed

of the real PDP-8, 1200 baud simulation will look like 110 to a person! */

#define IOFUDGE 1

#define print_time (baud2400 / IOFUDGE)

#define read_time (baud600 / IOFUDGE)

/****************************************************************/

/* restrictions: This version of the console has no low-speed */

/* paper-tape reader or punch -- call it a KSR teletype instead */

/* of the usual ASR teletype. */

/****************************************************************/

/*********************************************************/

/* Interface between device implementation and "console" */

/*********************************************************/

/* timers used to simulate delays between I/O initiation and completion */

/*

struct timer {

long int delay; the delay until the timer is to fire

void (* action)(); the function to call when the timer fires

int param; parameter to action

struct timer * next; the next timer to worry about after this

};

*/

static struct timer print_delay;

static struct timer read_delay;

/*************************************/

/* "officially visible" device state */

/*************************************/

static int keyboard_flag;

static int keyboard_buffer;

static int interrupt_enable;

static int print_flag;

static int print_buffer;

/*************************/

/* Device Implementation */

/*************************/

void ttyputc(char ch) /* put character to console */

{

Serial.write(ch);

}

static void keyboard_event() /* called to poll for keyboard input */

{

int poll;

if (Serial.available() > 0) {

keyboard_buffer = ( Serial.read() | 0200 );

/* report the keypress to the rest of the emulator */

/*RIC ver como keyboard_flag puede ser distinto a 1 */

if (keyboard_flag != 1) { /* no overrun condition */

keyboard_flag = 1;

if (interrupt_enable == 1) {

irq = irq + 1;

}

}

}

/*RIC regenera la llamada */

schedule( &read_delay, read_time, keyboard_event );

}

static void print_event()

{ /* called from timer when a byte has been successfully printed */

/* this code allows for the DEC convention of setting the high bit */

ttyputc( print_buffer & 0177 );

print_flag = 1;

if (interrupt_enable == 1) {

irq = irq + 1;

}

}

static void print_character()

{ /* schedule the completion of a print "print_time" in the future */

schedule( &print_delay, print_time, print_event);

}

/******************/

/* Initialization */

/******************/

void kl8epower() /* global initialize */

{

/* set up timers used to delay I/O activity */

init_timer(print_delay);

init_timer(read_delay);

/* the following makes the reader run forever (probably wrong) */

schedule( &read_delay, read_time, keyboard_event );

}

void kl8einit() /* console reset */

{

keyboard_flag = 0;

print_flag = 0;

interrupt_enable = 1;

}

/********************/

/* IOT Instructions */

/********************/

void kl8edev3(int op) /* keyboard*/

{

switch (op) {

/* (pdp8e) keyboard flag is cleared */

case 00: /* KCF */

if (interrupt_enable == 1) {

irq = irq - keyboard_flag;

}

keyboard_flag = 0;

break;

/* KSF skip next instruction when keyboard buffer register is loaded

with an ASCII symbol (causing keyboard flag raised) */

case 01: /* KSF */

if (keyboard_flag == 1) {

pc = (pc + 1) & 07777;

}

break;

/* clear AC, clear keyboard flag */

case 02: /* KCC */

if (interrupt_enable == 1) {

irq = irq - keyboard_flag;

}

keyboard_flag = 0;

ac = 00000;

break;

case 03: /* no operation! */

break;

/* transfer the content of keyboard buffer to AC */

case 04: /* KRS */

ac = ac | keyboard_buffer;

break;

/* (pdp8e) acumulator loaded into device control register */

case 05: /* KIE != KSF KRS */

if ((ac & 00001) == 0) { /* disable interrupts */

if (interrupt_enable == 1) {

interrupt_enable = 0;

irq = irq - (keyboard_flag + print_flag);

}

} else { /* enable interrupts */

if (interrupt_enable == 0) {

interrupt_enable = 1;

irq = irq + (keyboard_flag + print_flag);

}

}

break;

/* transfer contents keyboard buffer to AC and clear keyboard flag*/

case 06: /* KRB = KCC KRS */

if (interrupt_enable == 1) {

irq = irq - keyboard_flag;

}

keyboard_flag = 0;

ac = keyboard_buffer;

break;

case 07: /* no operation! */

break;

}

}

void kl8edev4(int op) /*printer*/

{

switch (op) {

/* (pdp8e) printer flag, signaling output completed is set */

case 00: /* TFL */

if (print_flag == 0) {

print_flag = 1;

if (interrupt_enable == 1) {

irq = irq + 1;

}

}

break;

/* skip next instruction if printer flag=1 */

case 01: /* TSF */

if (print_flag == 1) {

pc = (pc + 1) & 07777;

}

break;

/* clear printer flag */

case 02: /* TCF */

if (interrupt_enable == 1) {

irq = irq - print_flag;

}

print_flag = 0;

break;

case 03: /* no operation! */

break;

/* load printer buffer with contents AC, select and print character

flag is raised when action completed */

case 04: /* TPC */

print_buffer = ac & 00377;

print_character();

break;

/* (pdp8e) skip next instruction if if printer or keyboards flags are set */

case 05: /* TSK != TSF TPC */

if ((print_flag == 1) || (keyboard_flag == 1)) {

pc = (pc + 1) & 07777;

}

break;

/* clear printer flag, transfer contents AC to printer buffer register

select and print character. flag is raised when action completed */

case 06: /* TLS = TCF TPC */

if (interrupt_enable == 1) {

irq = irq - print_flag;

}

print_flag = 0;

print_buffer = ac & 00377;

print_character();

break;

case 07: /* no operation! */

break;

}

}

/*****************************************************************************

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

*****************************************************************************/

/* Some parts of File: kk8e.c

The ones that are not in the main loop

Modify: Ricardo Guerreiro 2011. Cleaning unused definitions (debug ke8e etc)

Preparing for pdp8r

basado en kk8er que esta testeado que anda ok

esta limpio para un straight

lee focal de debug.txt

no usa devices para nada

ANDA SIN front panel

Author: Douglas Jones, Dept. of Comp. Sci., U. of Iowa, Iowa City, IA 52242.

Date: Mar. 6, 1996

Language: C (UNIX)

Purpose: DEC PDP-8/e emulator

Based on the PDP-8/E Small Computer Handbook,

Digital Equipment Corporation, 1971, 1973,

and the PDP-8/E/F/M Maintenance Manual, volumes 1 and 2,

Digital Equipment Corporation, 1975.

*/

/******************/

/* Initialization */

/******************/

/* Both the reset key on the console and the CAF instruction call this */

void clearflags()

{

/* device specific effects of the reset operation */

kl8einit(); /* console TTY */

link = 000000;

ac = 00000;

irq = 0;

enab = 0;

enab_del = 0;

}

void powerup()

/* called only once for power on */

{

/* first, see if there is a specified core image save file,

since PDP-8/E machines usually have core memory and tend

to remember what was in them as of the previous shutdown

A parameter of the form with no leading dash

is interpreted as the name of the core file. If there is

no core file specified, core comes up uninitialized.

*/

run = 0; /* by default, the machine comes up halted */

/* initialize the real-time simulation mechanisms */

init_timers();

/* initialize all devices to their power-on state */

/* core must be registered first because it's going to be

on the console device window at console-power up */

kl8epower(); /* console TTY */

clearflags();

}

void powerdown()

/* called only once from the console to exit the emulator */

{

exit(0);

}

/************************/

/* Instruction decoding */

/************************/

/*

/ _____ _____ _____ _____

/ instruction word format: = |_|_|_|_|_|_|_|_|_|_|_|_|

/ | op |i|z| adr |

/

/ Instructions will be decoded using a 5 bit opcode-mode combination,

/ so the following opcode definitions are shifted 2 places left

*/

#define opAND (0 > 6)

| ((ac & 00077) 12);

link = ac & 010000;

ac = ac & 007777;

break;

case 03: /* RAL TWO */

ac = (ac > 11);

link = ac & 010000;

ac = ac & 007777;

break;

case 04: /* RAR */

ac = ((ac | link) >> 1) | (ac > 2) | (ac > 3) { /* SMA ... REV */

case 000: /* NOP */

break;

case 001: /* REV */

pc = (pc + 1) & 07777;

break;

case 002: /* SNL */

if (link) {

pc = (pc + 1) & 07777;

}

break;

case 003: /* SNL REV */

if (link == 0) {

pc = (pc + 1) & 07777;

}

break;

case 004: /* SZA */

if (ac == 0) {

pc = (pc + 1) & 07777;

}

break;

case 005: /* SZA REV */

if (ac) {

pc = (pc + 1) & 07777;

}

break;

case 006: /* SZA SNL */

if ((ac == 0) || link) {

pc = (pc + 1) & 07777;

}

break;

case 007: /* SZA SNL REV */

if (ac && (link == 0)) {

pc = (pc + 1) & 07777;

}

break;

case 010: /* SMA */

if (ac & 04000) {

pc = (pc + 1) & 07777;

}

break;

case 011: /* SMA REV */

if ((ac & 04000) == 0) {

pc = (pc + 1) & 07777;

}

break;

case 012: /* SMA SNL */

if ((ac | link) & 014000) {

pc = (pc + 1) & 07777;

}

break;

case 013: /* SMA SNL REV */

if (((ac | link) & 014000) == 0) {

pc = (pc + 1) & 07777;

}

break;

case 014: /* SMA SZA */

if ((ac & 04000) || (ac == 0)) {

pc = (pc + 1) & 07777;

}

break;

case 015: /* SMA SZA REV */

if (((ac & 004000) == 0) && ac) {

pc = (pc + 1) & 07777;

}

break;

case 016: /* SMA SZA SNL */

if (((ac | link) & 014000)

|| (ac == 0)) {

pc = (pc + 1) & 07777;

}

break;

case 017: /* SMA SZA SNL REV */

if ((((ac | link) & 014000) == 0)

&& (ac)) {

pc = (pc + 1) & 07777;

}

break;

}

if (mb & 00200) { /* CLA */

ac = 00000;

}

if (mb & 00004) { /* OSR */

ac = ac | sr;

}

if (mb & 00002) { /* HLT */

countdown = 0;

run = 0;

}

} else { /* GROUP 3 */

pc = (pc + 1) & 07777;

if (mb & 00200) { /* CLA */

ac = 00000;

}

if ((mb & 00120) == 00100) { /* MQA */

ac = mq | ac;

} else if ((mb & 00120) == 00020) { /* MQL */

mq = ac;

ac = 00000;

} else if ((mb & 00120) == 00120) { /*MQA,MQL*/

int temp;

temp = mq;

mq = ac;

ac = temp;

}

}

}

}

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download