-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdisplay.c
More file actions
185 lines (170 loc) · 5.74 KB
/
display.c
File metadata and controls
185 lines (170 loc) · 5.74 KB
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
175
176
177
178
179
180
181
182
183
184
185
/*
* Copyright (C) 2024 by Matthieu CASTET <castet.matthieu@free.fr>
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <string.h>
#include "emu.h"
static struct {
char out[30]; /* segment output */
char out1[30]; /* final version of segment output */
int pos;
} disp;
char *display_debug(void)
{
return disp.out1;
}
static int display_process(void *priv, struct bus *bus)
{
/* alu update on S0W and clear at S14W */
if (bus->sstate == 0 && !bus->write) {
/* 13 digits display
* D13/D1 is - and .
* D12 ... D3 digit/. (mantisa)
* D2 is -
* D2 D1 is digit (exponent)
*
* - is connected to segH
*/
if (bus->dstate <= 13 && bus->dstate >= 1) {
if (bus->dstate == 1 && bus->display_segH)
disp.out[0] = '-';
if (bus->dstate == 2) {
if (bus->display_segH)
disp.out[disp.pos++] = '-';
else
disp.out[disp.pos++] = ' ';
}
if (bus->dstate != 13)
disp.out[disp.pos++] = bus->display_digit;
else
disp.out[disp.pos++] = ' ';
/* not really seen in rom, but hw allow it */
if (bus->dstate == 13 && bus->display_segH)
disp.out[0] = '-';
if (bus->display_dpt && bus->dstate >= 3)
disp.out[disp.pos++] = '.';
else if (bus->display_dpt && bus->dstate == 1)
LOG("???? dpt at D1 ");
//LOG("\nSEG.%d='%c' (%s)\n", bus->dstate, bus->display_digit, disp.out);
}
if (bus->dstate==0) {
disp.out[disp.pos + 2] = bus->idle ? ' ' : 'B';
if (memcmp(disp.out1, disp.out, sizeof(disp.out1))) {
LOG("\nDISP='%s'\n", disp.out);
printf(" \r%s", disp.out);
memcpy(disp.out1, disp.out, sizeof(disp.out1));
}
//memset(disp.out, '\0', sizeof(disp.out));
memset(disp.out, ' ', sizeof(disp.out)-1);
disp.pos = 0;
}
}
return 0;
}
static int display_process2(void *priv, struct bus *bus)
{
/* alu update on S0W and clear at S14W */
if (bus->sstate == 0 && !bus->write) {
/* 12 digit connected to D13-D2
* D13 is (C or -) and .
*/
if (bus->dstate <= 13 && bus->dstate >= 2) {
/* bus->display_segH is connected to C and D13
*/
if (bus->dstate != 13)
disp.out[disp.pos++] = bus->display_digit;
else {
if (bus->display_digit == '-') {
if (bus->display_segH)
disp.out[disp.pos++] = 'E';
else
disp.out[disp.pos++] = '-';
}
else {
if (bus->display_segH)
disp.out[disp.pos++] = 'C';
else
disp.out[disp.pos++] = ' ';
}
}
if (bus->display_dpt)
disp.out[disp.pos++] = '.';
//LOG("\nSEG.%d='%c' (%s)\n", bus->dstate, bus->display_digit, disp.out);
}
if (bus->dstate==0) {
disp.out[disp.pos + 2] = bus->idle ? ' ' : 'B';
if (memcmp(disp.out1, disp.out, sizeof(disp.out1))) {
LOG("\nDISP='%s'\n", disp.out);
printf(" \r%s", disp.out);
memcpy(disp.out1, disp.out, sizeof(disp.out1));
}
//memset(disp.out, '\0', sizeof(disp.out));
memset(disp.out, ' ', sizeof(disp.out)-1);
disp.pos = 0;
}
}
return 0;
}
static int displaysr60_process(void *priv, struct bus *bus)
{
/* TODO extact led
* DEG : pin 26
* TRACE : pin 25
* PREC pint 24
* use bus->display_segH or bus->display_dpt at a specific D state ????
*/
/* alu update on S0W and clear at S14W */
if (bus->sstate == 0 && !bus->write) {
if (log_flags & LOG_DEBUG)
LOG("\nDISP %d %d %d '%c'\n", bus->dstate, bus->display_segH, bus->display_dpt, bus->display_digit);
}
return 0;
}
void display_ext(const char *line)
{
strcpy(disp.out, line);
if (memcmp(disp.out1, disp.out, sizeof(disp.out1))) {
LOG("\nDISP='%s'\n", disp.out);
printf(" \r%s", disp.out);
memcpy(disp.out1, disp.out, sizeof(disp.out1));
}
}
void display_print(const char *line)
{
printf("| %.20s\n", line);
printf("\r%s", disp.out);
}
void display_dbgprint(const char *line)
{
printf("|d %.13s %s\n", disp.out1, line);
printf("\r%s", disp.out);
}
int display_init(struct chip *chip, const char *name)
{
if (name && !strcmp(name, "sr60")) {
chip->process = displaysr60_process;
}
else if (name && (!strcmp(name, "ti58") || !strcmp(name, "ti58c") ||
!strcmp(name, "ti59") || !strcmp(name, "sr51-II"))) {
chip->process = display_process2;
printf("new display\n");
}
else
chip->process = display_process;
return 0;
}