-
Notifications
You must be signed in to change notification settings - Fork 48
/
host_due.h
162 lines (113 loc) · 5.84 KB
/
host_due.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// -----------------------------------------------------------------------------
// Altair 8800 Simulator
// Copyright (C) 2017 David Hansel
// -----------------------------------------------------------------------------
#ifndef HOST_DUE_H
#define HOST_DUE_H
#include "config.h"
#include "switch_serial.h"
#include <SdFat.h>
// If the PROTECT switch is not used (USE_PROTECT set to 0 in config.h) then those pins
// can be used to provide an additional serial interface. Set USE_SERIAL_ON_A6A7 to 1
// here. The A6 pin is RX and A7 is TX.
// WARNING: It is highly recommended to physically disable the PROTECT switch by
// disconnecting the GND wire from the switch before enabling this. The serial
// lines idle HIGH and the PROTECT switch will connect them to GND when pressed,
// creating a direct short and likely killing the A7 pin on the Arduino and/or
// your connected serial device.
#define USE_SERIAL_ON_A6A7 0
// The pins driving the RX and TX LEDs located next to the Native USB port on the
// Arduino Due can be controlled as digital I/O pins 72 and 73. They do not serve
// any other purpose on the Due so we can use them for an additional serial port.
// See the documentation for where exactly to solder the wires onto the Due.
#define USE_SERIAL_ON_RXLTXL 0
// Arduino Due provides a file system (via SD card)
#define HOST_HAS_FILESYS
#define HOST_FILESYS_FILE_TYPE File
#define HOST_FILESYS_DIR_TYPE File
#define MEMSIZE 0x10000
#define HOST_STORAGESIZE due_storagesize
#define HOST_BUFFERSIZE 0x100
#define HOST_PERFORMANCE_FACTOR 1.0
#define HOST_NUM_SERIAL_PORTS (3+USE_SERIAL_ON_A6A7+USE_SERIAL_ON_RXLTXL)
extern uint32_t due_storagesize;
// ------------------------------------------ switches
inline byte host_read_sense_switches()
{
// SW8...15 => PIOA, bits 12-15,17-20 (negative logic)
word w = ~REG_PIOA_PDSR;
return ((w & 0xF000) / (1<<12)) | ((w & 0x1E0000) / (1<<13));
}
uint16_t host_read_addr_switches();
// ------------------------------------------ status LEDs
/* reading global variables is faster than reading back the i/o register
=> INTE and WAIT are read often so we keep their state in a global variable */
#define host_set_status_led_INT() REG_PIOB_SODR = 1<<25
#define host_set_status_led_WO() REG_PIOC_CODR = 1<<28
#define host_set_status_led_STACK() REG_PIOC_SODR = 1<<26
#define host_set_status_led_HLTA() REG_PIOC_SODR = 1<<25
#define host_set_status_led_M1() REG_PIOC_SODR = 1<<23
#define host_set_status_led_MEMR() REG_PIOC_SODR = 1<<21
#define host_set_status_led_INTE() REG_PIOD_SODR = 1<<8;
#define host_set_status_led_PROT() REG_PIOB_SODR = 1<<27
#define host_set_status_led_WAIT() { REG_PIOC_SODR = 1<<29; status_wait = true; }
#define host_set_status_led_HLDA() REG_PIOB_SODR = 1<<26
#define host_clr_status_led_INT() REG_PIOB_CODR = 1<<25
#define host_clr_status_led_WO() REG_PIOC_SODR = 1<<28
#define host_clr_status_led_STACK() REG_PIOC_CODR = 1<<26
#define host_clr_status_led_HLTA() REG_PIOC_CODR = 1<<25
#define host_clr_status_led_M1() REG_PIOC_CODR = 1<<23
#define host_clr_status_led_MEMR() REG_PIOC_CODR = 1<<21
#define host_clr_status_led_INTE() REG_PIOD_CODR = 1<<8;
#define host_clr_status_led_PROT() REG_PIOB_CODR = 1<<27
#define host_clr_status_led_WAIT() { REG_PIOC_CODR = 1<<29; status_wait = false; }
#define host_clr_status_led_HLDA() REG_PIOB_CODR = 1<<26
#define host_read_status_led_WAIT() status_wait
#define host_read_status_led_M1() (REG_PIOC_PDSR & (1<<23))
#define host_read_status_led_HLTA() (REG_PIOC_PDSR & (1<<25))
#define host_read_status_led_INTE() status_inte
#if USE_IO_BUS>0
// switch WAIT and DATA LEDs to inputs and turn on INP LED
#define host_set_status_led_INP() { REG_PIOD_ODR = 0xFF; REG_PIOC_ODR = 1<<29; REG_PIOC_SODR = 1<<22; }
#define host_clr_status_led_INP() { REG_PIOC_OER = 1<<29; REG_PIOD_OER = 0xFF; REG_PIOC_CODR = 1<<22; }
// switch WAIT LED to input and turn on OUT LED
#define host_set_status_led_OUT() { REG_PIOC_ODR = 1<<29; REG_PIOC_SODR = 1<<24; }
#define host_clr_status_led_OUT() { REG_PIOC_CODR = 1<<24; REG_PIOC_OER = 1<<29; }
// read input from pins connected to DATA and WAIT LEDs
#define host_read_data_bus host_read_data_leds
#define host_read_status_WAIT() (REG_PIOC_PDSR & (1<<29))
#else
#define host_set_status_led_INP() REG_PIOC_SODR = 1<<22;
#define host_clr_status_led_INP() REG_PIOC_CODR = 1<<22;
#define host_set_status_led_OUT() REG_PIOC_SODR = 1<<24
#define host_clr_status_led_OUT() REG_PIOC_CODR = 1<<24
#endif
// reading from memory (MEMR on, WO on)
#define host_set_status_leds_READMEM() REG_PIOC_SODR = 0x10200000
// reading opcode from memory (MEMR on, M1 on, WO on)
#define host_set_status_leds_READMEM_M1() REG_PIOC_SODR = 0x10A00000
// reading from stack (MEMR on, WO on, STACK on)
#define host_set_status_leds_READMEM_STACK() REG_PIOC_SODR = 0x14200000
// writing to memory (MEMR off, WO off)
#define host_set_status_leds_WRITEMEM() REG_PIOC_CODR = 0x10200000
uint16_t host_read_status_leds();
#define HOST_HAS_LAMP_TEST
void host_lamp_test();
// ----------------------------------------------------- address bus
inline void host_set_addr_leds(uint16_t v)
{
// A0..7 => 34, 35, ..., 41 (PIOC, bits 2-9)
// A8..15 => 51, 50, ..., 44 (PIOC, bits 12-19)
REG_PIOC_ODSR = (v & 0x00ff) * 4 + (v & 0xff00) * 16;
}
uint16_t host_read_addr_leds();
// ---------------------------------------------------- data bus
// D0..8 => 25,26,27,28,14,15,29,11 (PIOD, bits 0-7)
#define host_set_data_leds(v) REG_PIOD_ODSR = v
byte host_read_data_leds();
// ---------------------------------------------------- interrupts
// On the Due we are using real interrupts so nothing needs o be done here
#define host_check_interrupts() while(0)
void host_serial_interrupts_pause();
void host_serial_interrupts_resume();
#endif