This repository has been archived by the owner on May 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
cmd.c
174 lines (159 loc) · 4.43 KB
/
cmd.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <stdio.h>
#include "hardware/pio.h"
#include "pico/stdlib.h"
#include "main.pio.h"
#include "utils.h"
#include "values.h"
#include "cmd.h"
extern volatile uint latched;
extern volatile uint count_track;
extern volatile uint soct_offset;
extern volatile uint subq_offset;
extern volatile bool soct;
extern volatile uint sled_move_direction;
extern volatile uint track;
extern volatile uint original_track;
extern volatile uint sector;
extern volatile uint sector_for_track_update;
extern volatile int subq_start;
extern volatile int mode;
extern bool SENS_data[16];
volatile uint jump_track = 0;
void autosequence() {
int subcommand = (latched & 0x0F0000) >> 16;
SENS_data[SENS_AUTOSEQ] = (subcommand != 0);
switch (subcommand) {
case 0xC:
track = track + 2*jump_track;
sector = track_to_sector(track);
sector_for_track_update = sector;
break;
case 0xD:
track = track - 2*jump_track;
sector = track_to_sector(track);
sector_for_track_update = sector;
break;
case 0x8:
track = track + 1;
sector = track_to_sector(track);
sector_for_track_update = sector;
break;
case 0x9:
track = track - 1;
sector = track_to_sector(track);
sector_for_track_update = sector;
break;
case 0xA:
track = track + 10;
sector = track_to_sector(track);
sector_for_track_update = sector;
break;
case 0xB:
track = track - 10;
sector = track_to_sector(track);
sector_for_track_update = sector;
break;
case 0xE:
track = track + jump_track;
sector = track_to_sector(track);
sector_for_track_update = sector;
break;
case 0xF:
track = track - jump_track;
sector = track_to_sector(track);
sector_for_track_update = sector;
break;
case 0x4:
track = track + jump_track;
sector = track_to_sector(track);
sector_for_track_update = sector;
break;
case 0x5:
track = track - jump_track;
sector = track_to_sector(track);
sector_for_track_update = sector;
break;
}
}
void sled_move() {
int subcommand_move = (latched & 0x030000) >> 16;
int subcommand_track = (latched & 0x0C0000) >> 16;
switch (subcommand_move) {
case 2:
sled_move_direction = SLED_MOVE_FORWARD;
original_track = track;
break;
case 3:
sled_move_direction = SLED_MOVE_REVERSE;
original_track = track;
break;
default:
if (sled_move_direction != SLED_MOVE_STOP) {
sector = track_to_sector(track);
sector_for_track_update = sector;
}
sled_move_direction = SLED_MOVE_STOP;
break;
}
switch (subcommand_track) {
case 8:
track++;
sector = track_to_sector(track);
sector_for_track_update = sector;
break;
case 0xC:
track--;
sector = track_to_sector(track);
sector_for_track_update = sector;
break;
}
}
void spindle() {
int subcommand = (latched & 0x0F0000) >> 16;
SENS_data[SENS_GFS] = (subcommand == 6);
}
void interrupt_xlat(uint gpio, uint32_t events) {
int command = (latched & 0xF00000) >> 20;
switch (command) {
case CMD_AUTOSEQ:
autosequence();
break;
case CMD_SOCT:
soct = 1;
pio_sm_set_enabled(pio1, SUBQ_SM, false);
soct_program_init(pio1, SOCT_SM, soct_offset, SQSO, SQCK);
pio_sm_set_enabled(pio1, SOCT_SM, true);
pio_sm_put_blocking(pio1, SOCT_SM, 0xFFFFFFF);
break;
case CMD_JUMP_TRACK:
jump_track = (latched & 0xFFFF0) >> 4;
//printf("%d\n", jump_track);
break;
case CMD_COUNT_TRACK:
count_track = (latched & 0xFFFF0) >> 4;
//printf("%d\n", count_track);
break;
case CMD_SPINDLE:
spindle();
break;
case CMD_SLED:
sled_move();
break;
case CMD_SPEED:
if ((latched & 0xF40000) == 0x940000 && mode == 1) {
mode = 2;
} else if ((latched & 0xF40000) == 0x900000 && mode == 2) {
mode = 1;
}
break;
}
/*
if (command == CMD_SLED || command == CMD_AUTOSEQ ||
command == CMD_JUMP_TRACK || command == CMD_SPEED ||
command == CMD_COUNT_TRACK || command == CMD_SPINDLE
) {
printf("%06X\n", latched);
}
*/
latched = 0;
}