-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathhost_mega.h
111 lines (89 loc) · 4.69 KB
/
host_mega.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
// -----------------------------------------------------------------------------
// Altair 8800 Simulator
// Copyright (C) 2017 David Hansel
// -----------------------------------------------------------------------------
#ifndef HOST_MEGA_H
#define HOST_MEGA_H
#include <EEPROM.h>
#include <avr/pgmspace.h>
// Mega2650: 8k SRAM, use 6k for emulated RAM
// NOTE: Using too much emulated RAM can cause stability issues when
// running the emulator. Modify settings in config.h and the MEMSIZE
// setting here to make sure Arduino IDE says (after compiling) that
// AT LEAST 310 bytes of RAM are left for local variables!
// If you run into weird emulation issues, consider (temporarily)
// using only 5K MEMSIZE here to see if that resolves the problem.
#define MEMSIZE (4096+2048)
#define HOST_STORAGESIZE 4096 // have 4k EEPROM
#define HOST_BUFFERSIZE 0 // have little SRAM so don't buffer
#define HOST_PERFORMANCE_FACTOR 0.25
#define HOST_NUM_SERIAL_PORTS 1
#define PROF_DISPLAY_INTERVAL 100000
inline void host_set_addr_leds(uint16_t v) { PORTA=(v & 0xff); PORTC=(v / 256); }
#define host_read_addr_leds(v) (PORTA | (PORTC * 256))
#define host_set_data_leds(v) PORTL=(v)
#define host_read_data_leds() PORTL
#define host_set_status_led_INT() PORTB |= 0x01
#define host_set_status_led_WO() PORTB &= ~0x02
#define host_set_status_led_STACK() PORTB |= 0x04
#define host_set_status_led_HLTA() PORTB |= 0x08
#define host_set_status_led_M1() PORTB |= 0x20
#define host_set_status_led_MEMR() PORTB |= 0x80
#define host_set_status_led_INTE() digitalWrite(38, HIGH);
#define host_set_status_led_PROT() digitalWrite(39, HIGH)
#define host_set_status_led_WAIT() { digitalWrite(40, HIGH); status_wait = true; }
#define host_set_status_led_HLDA() digitalWrite(41, HIGH)
#define host_clr_status_led_INT() PORTB &= ~0x01
#define host_clr_status_led_WO() PORTB |= 0x02
#define host_clr_status_led_STACK() PORTB &= ~0x04
#define host_clr_status_led_HLTA() PORTB &= ~0x08
#define host_clr_status_led_M1() PORTB &= ~0x20
#define host_clr_status_led_MEMR() PORTB &= ~0x80
#define host_clr_status_led_INTE() digitalWrite(38, LOW);
#define host_clr_status_led_PROT() digitalWrite(39, LOW)
#define host_clr_status_led_WAIT() { digitalWrite(40, LOW); status_wait = false; }
#define host_clr_status_led_HLDA() digitalWrite(41, LOW)
#define host_read_status_led_WAIT() status_wait
#define host_read_status_led_M1() PORTB&0x20
#define host_read_status_led_INTE() PORTD&0x80
#define host_read_status_led_HLTA() PORTB&0x08
#define host_set_status_leds_READMEM() PORTB |= 0x82
#define host_set_status_leds_READMEM_M1() PORTB |= 0xA2;
#define host_set_status_leds_READMEM_STACK() PORTB |= 0x86;
#define host_set_status_leds_WRITEMEM() PORTB &= ~0x82
#if USE_IO_BUS>0
// switch WAIT and DATA LEDs to inputs and turn on INP LED
#define host_set_status_led_INP() { DDRL = 0x00; DDRG &= ~0x02; PORTB |= 0x40; }
#define host_clr_status_led_INP() { PORTB &= ~0x40; DDRG |= 0x02; DDRL = 0xFF; }
// switch WAIT LED to input and turn on OUT LED
#define host_set_status_led_OUT() { DDRG &= 0xFE; PORTB |= 0x10; }
#define host_clr_status_led_OUT() { PORTB &= ~0x10; DDRG |= 0x01; }
// read input from pins connected to DATA and WAIT LEDs
#define host_read_data_bus() PINL
#define host_read_status_WAIT() (PING & 0x02)
#else
#define host_set_status_led_INP() PORTB |= 0x40
#define host_clr_status_led_INP() PORTB &= ~0x40
#define host_set_status_led_OUT() PORTB |= 0x10
#define host_clr_status_led_OUT() PORTB &= ~0x10
#endif
uint16_t host_read_status_leds();
inline byte host_mega_read_switches(byte highlow)
{
byte b = 0;
ADCSRB = highlow ? 0x08 : 0x00; // MUX5
ADMUX = 0x40; ADCSRA = 0xD4; while( ADCSRA&0x40 ); if( ADCH != 0 ) b |= 0x01;
ADMUX = 0x41; ADCSRA = 0xD4; while( ADCSRA&0x40 ); if( ADCH != 0 ) b |= 0x02;
ADMUX = 0x42; ADCSRA = 0xD4; while( ADCSRA&0x40 ); if( ADCH != 0 ) b |= 0x04;
ADMUX = 0x43; ADCSRA = 0xD4; while( ADCSRA&0x40 ); if( ADCH != 0 ) b |= 0x08;
ADMUX = 0x44; ADCSRA = 0xD4; while( ADCSRA&0x40 ); if( ADCH != 0 ) b |= 0x10;
ADMUX = 0x45; ADCSRA = 0xD4; while( ADCSRA&0x40 ); if( ADCH != 0 ) b |= 0x20;
ADMUX = 0x46; ADCSRA = 0xD4; while( ADCSRA&0x40 ); if( ADCH != 0 ) b |= 0x40;
ADMUX = 0x47; ADCSRA = 0xD4; while( ADCSRA&0x40 ); if( ADCH != 0 ) b |= 0x80;
return b;
}
#define host_read_sense_switches() host_mega_read_switches(true)
#define host_read_addr_switches() (host_mega_read_switches(true) * 256 | host_mega_read_switches(false))
bool host_read_function_switch(byte inputNum);
#define host_check_interrupts() { if( Serial.available() ) serial_receive_host_data(0, Serial.read()); }
#endif