-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
152 lines (124 loc) · 3.3 KB
/
main.c
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
#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include "mos6502_controller.h"
#include "host_functions.h"
#include "led.h"
#define LED_ROWS 1
#define LED_COLS 2
#define F_CPU 16000000
uint8_t ram[BLANK1_SEGMENT - RAM_SEGMENT];
uint8_t stack[RAM_SEGMENT - STACK_SEGMENT];
enum LED_ELEMENT {
STATUS = 0, // Current LED status
R, // Red
G, // Green
B, // Blue
HL, // Hue lower 8 bits
HI, // Hue higher 8 bits
S, // Saturation
V // Vue
};
uint8_t text_read_handler(uint16_t address) {
return eeprom_read_byte((uint8_t*)address);
}
void text_write_handler(uint16_t address, uint8_t value) {
exit(1);
}
uint8_t host_functions_read_handler(uint16_t address) {
switch(address) {
case DELAY_DATA_CTRL_ADDR:
return get_delay_data_ctrl();
case DELAY_DATA_LSB_ADDR:
return get_delay_data_lsb();
case DELAY_DATA_MSB_ADDR:
return get_delay_data_msb();
default:
return 0x00;
}
}
void host_functions_write_handler(uint16_t address, uint8_t value) {
switch(address) {
case DELAY_DATA_CTRL_ADDR:
set_delay_data_ctrl(value);
break;
case DELAY_DATA_LSB_ADDR:
set_delay_data_lsb(value);
break;
case DELAY_DATA_MSB_ADDR:
set_delay_data_msb(value);
break;
default:
break;
}
}
uint8_t key_read_handler(uint16_t address) {
// TODO: Unimplemented
return 0x00;
}
void key_write_handler(uint16_t address, uint8_t value) {
// TODO: Unimplemented
}
uint8_t led_read_manipulator(uint16_t status_address, uint8_t element) {
//TODO: Unimplemented
return 0x00;
}
uint8_t led_read_handler(uint16_t address) {
uint16_t status_address = address / 8;
uint8_t element = address % 8;
return led_read_manipulator(status_address, element);
}
void led_write_manipulator(uint16_t status_address, uint8_t element, uint8_t value) {
switch(element) {
case STATUS:
if(value == 1) {
softpwm_led_enable_all();
} else if(value == 0) {
softpwm_led_disable_all();
}
break;
case R:
softpwm_led_set_all(value);
break;
}
}
void led_write_handler(uint16_t address, uint8_t value) {
uint16_t status_address = address / 8;
uint8_t element = address % 8;
led_write_manipulator(status_address, element, value);
}
uint8_t blank1_read_handler(uint16_t address) {
exit(1);
}
void blank1_write_handler(uint16_t address, uint8_t value) {
exit(1);
}
uint8_t ram_read_handler(uint16_t address) {
return ram[address];
}
void ram_write_handler(uint16_t address, uint8_t value) {
ram[address] = value;
}
uint8_t stack_read_handler(uint16_t address) {
return stack[address];
}
void stack_write_handler(uint16_t address, uint8_t value) {
stack[address] = value;
}
uint8_t reserved_read_handler(uint16_t address) {
exit(1);
}
void reserved_write_handler(uint16_t address, uint8_t value) {
exit(1);
}
void init() {
softpwm_init();
softpwm_enable();
delay_init();
sei();
}
int main() {
init();
start_up();
}