Skip to content

Commit 5981f30

Browse files
committed
core: also use model to determine which revs are appropriate.
This is needed for proper 82AEP support which is M+ only (pre-A there). The model info is stored in the asic state, hence the IMAGE_VERSION inc.
1 parent 8e63527 commit 5981f30

File tree

11 files changed

+62
-31
lines changed

11 files changed

+62
-31
lines changed

core/asic.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static void plug_devices(void) {
8888
gui_console_printf("[CEmu] Initialized Advanced Peripheral Bus...\n");
8989
}
9090

91-
static asic_rev_t report_reset(asic_rev_t loaded_rev, bool* python) {
91+
static asic_rev_t report_reset(asic_rev_t loaded_rev, ti_model_t model, bool* python) {
9292
/* Parse boot code routines to determine version. */
9393
asic_rev_t default_rev = ASIC_REV_A;
9494
boot_ver_t boot_ver;
@@ -99,7 +99,7 @@ static asic_rev_t report_reset(asic_rev_t loaded_rev, bool* python) {
9999

100100
/* Determine the newest ASIC revision that is compatible */
101101
for (int rev = ASIC_REV_A; rev <= ASIC_REV_M; rev++) {
102-
if (bootver_check_rev(&boot_ver, (asic_rev_t)rev)) {
102+
if (bootver_check_rev(&boot_ver, (asic_rev_t)rev, model)) {
103103
default_rev = rev;
104104
}
105105
}
@@ -114,13 +114,14 @@ static asic_rev_t report_reset(asic_rev_t loaded_rev, bool* python) {
114114
}
115115
gui_console_printf("[CEmu] Default ASIC revision is Rev %c.\n", "AIM"[(int)default_rev - 1]);
116116

117-
loaded_rev = gui_handle_reset((gotVer ? &boot_ver : NULL), loaded_rev, default_rev, python);
117+
loaded_rev = gui_handle_reset((gotVer ? &boot_ver : NULL), loaded_rev, default_rev, model, python);
118118
return (loaded_rev != ASIC_REV_AUTO) ? loaded_rev : default_rev;
119119
}
120120

121121
static void set_features() {
122122
asic.im2 = (asic.revision < ASIC_REV_I);
123123
asic.serFlash = (asic.revision >= ASIC_REV_M);
124+
asic.hasWorkingSPIReads = (asic.model == TIMODEL_82AEP && asic.revision >= ASIC_REV_M);
124125
}
125126

126127
void asic_init(void) {
@@ -148,14 +149,22 @@ void asic_reset(void) {
148149
/* Update the Python state first, so it can be read by the reset handler if needed */
149150
static const uint16_t path[] = { 0x0330, 0x0430 };
150151
asic.python = !cert_field_find_path(mem.flash.block + 0x3B0001, SIZE_FLASH_SECTOR_64K, path, 2, NULL, NULL);
151-
asic.revision = report_reset(ASIC_REV_AUTO, &asic.python);
152+
asic.revision = report_reset(ASIC_REV_AUTO, asic.model, &asic.python);
152153
set_features();
153154

154155
for (unsigned int i = 0; i < reset_proc_count; i++) {
155156
reset_procs[i]();
156157
}
157158
}
158159

160+
void set_model_type(ti_model_t model) {
161+
asic.model = model;
162+
}
163+
164+
ti_model_t EMSCRIPTEN_KEEPALIVE get_model_type(void) {
165+
return asic.model;
166+
}
167+
159168
void set_device_type(ti_device_t device) {
160169
asic.device = device;
161170
}
@@ -203,7 +212,7 @@ bool asic_restore(FILE *image) {
203212
&& fgetc(image) == EOF)
204213
{
205214
bool python = asic.python;
206-
(void)report_reset(asic.revision, &python);
215+
(void)report_reset(asic.revision, asic.model, &python);
207216
return true;
208217
}
209218
return false;

core/asic.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern "C" {
1111

1212
typedef enum {
1313
TI84PCE = 0,
14-
TI83PCE = 1
14+
TI83PCE = 1 /* also in use by the TI-82AEP model */
1515
} ti_device_t;
1616

1717
typedef enum {
@@ -27,13 +27,15 @@ typedef enum {
2727
} asic_rev_t;
2828

2929
typedef struct asic_state {
30+
ti_model_t model;
3031
ti_device_t device;
3132
/* Only updated on reset */
3233
asic_rev_t revision;
3334
bool python;
3435
/* Populated based on revision */
3536
bool im2;
3637
bool serFlash;
38+
bool hasWorkingSPIReads;
3739
} asic_state_t;
3840

3941
extern asic_state_t asic;
@@ -44,6 +46,8 @@ void asic_reset(void);
4446
bool asic_restore(FILE *image);
4547
bool asic_save(FILE *image);
4648
void set_cpu_clock(uint32_t new_rate);
49+
void set_model_type(ti_model_t model);
50+
ti_model_t get_model_type(void);
4751
void set_device_type(ti_device_t device);
4852
ti_device_t get_device_type(void);
4953
asic_rev_t get_asic_revision(void);

core/bootver.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#include "bootver.h"
22

3-
static const boot_ver_t asic_min_ver[] = {
4-
{ 5, 0, 0, 0 }, /* Rev A */
5-
{ 5, 0, 0, 0 }, /* Rev I */
6-
{ 5, 3, 6, 0 }, /* Rev M */
7-
};
8-
9-
static const boot_ver_t asic_max_ver[] = {
10-
{ 5, 3, 5, 65535 }, /* Rev A */
11-
{ 5, 3, 5, 65535 }, /* Rev I */
12-
{ 255, 255, 255, 65535 }, /* Rev M */
13-
};
3+
static const boot_ver_t minRevA_CE = { 5, 0, 0, 0 }; /* Rev A */
4+
static const boot_ver_t minRevI_CE = { 5, 0, 0, 0 }; /* Rev I */
5+
static const boot_ver_t minRevM_CE = { 5, 3, 6, 0 }; /* Rev M */
6+
static const boot_ver_t minRevM_82 = { 5, 6, 3, 0 }; /* Rev pre-A of 82AEP, but otherwise the same JB-007 ASIC as M on CE */
7+
static const boot_ver_t maxRevA_CE = { 5, 3, 5, 65535 }; /* Rev A */
8+
static const boot_ver_t maxRevI_CE = { 5, 3, 5, 65535 }; /* Rev I */
9+
static const boot_ver_t maxRev = { 255, 255, 255, 65535 }; /* Rev M */
10+
11+
/* NULL means unsupported */
12+
static const boot_ver_t* asic_min_ver_8384CE[] = { &minRevA_CE, &minRevI_CE, &minRevM_CE };
13+
static const boot_ver_t* asic_max_ver_8384CE[] = { &maxRevA_CE, &maxRevI_CE, &maxRev };
14+
static const boot_ver_t* asic_min_ver_82AEP[] = { NULL, NULL, &minRevM_82 };
15+
static const boot_ver_t* asic_max_ver_82AEP[] = { NULL, NULL, &maxRev };
1416

1517
static bool parse_entry(const uint8_t* data, uint32_t entry, uint32_t* addr) {
1618
if (entry + 4 >= SIZE_BOOTCODE) {
@@ -98,6 +100,9 @@ bool bootver_parse(const uint8_t* data, boot_ver_t* boot_ver) {
98100
}
99101

100102
bool bootver_check_ver(const boot_ver_t* ver, const boot_ver_t* check) {
103+
if (!ver || !check) {
104+
return false;
105+
}
101106
if (ver->major != check->major) {
102107
return ver->major > check->major;
103108
}
@@ -110,16 +115,19 @@ bool bootver_check_ver(const boot_ver_t* ver, const boot_ver_t* check) {
110115
return ver->build >= check->build;
111116
}
112117

113-
bool bootver_check_rev(const boot_ver_t* ver, asic_rev_t rev) {
118+
bool bootver_check_rev(const boot_ver_t* ver, asic_rev_t rev, ti_model_t model) {
114119
unsigned int index = (unsigned int)rev - 1;
115-
if (index >= sizeof(asic_min_ver) / sizeof(boot_ver_t)) {
120+
if ((model == TIMODEL_8384CE && index >= sizeof(asic_min_ver_8384CE) / sizeof(boot_ver_t*)) ||
121+
(model == TIMODEL_82AEP && index >= sizeof(asic_min_ver_82AEP) / sizeof(boot_ver_t*))) {
116122
return false;
117123
}
118124

119125
if (!ver) {
120126
return true;
121127
}
122128

123-
return bootver_check_ver(ver, asic_min_ver + index)
124-
&& bootver_check_ver(asic_max_ver + index, ver);
129+
const boot_ver_t** asic_min_ver = (model == TIMODEL_8384CE) ? asic_min_ver_8384CE : asic_min_ver_82AEP;
130+
const boot_ver_t** asic_max_ver = (model == TIMODEL_8384CE) ? asic_max_ver_8384CE : asic_max_ver_82AEP;
131+
return bootver_check_ver(ver, asic_min_ver[index])
132+
&& bootver_check_ver(asic_max_ver[index], ver);
125133
}

core/bootver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern "C" {
2424

2525
bool bootver_check_ver(const boot_ver_t* ver, const boot_ver_t* check);
2626

27-
bool bootver_check_rev(const boot_ver_t* ver, asic_rev_t rev);
27+
bool bootver_check_rev(const boot_ver_t* ver, asic_rev_t rev, ti_model_t model);
2828

2929
#ifdef __cplusplus
3030
}

core/emu.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <emscripten.h>
1919
#endif
2020

21-
#define IMAGE_VERSION 0xCECE001A
21+
#define IMAGE_VERSION 0xCECE001B
2222

2323
void EMSCRIPTEN_KEEPALIVE emu_exit(void) {
2424
cpu_set_signal(CPU_SIGNAL_EXIT);
@@ -192,15 +192,21 @@ emu_state_t emu_load(emu_data_t type, const char *path) {
192192
isPython ? "Yes" : "No");
193193
}
194194

195+
if ((model_id == TIMODEL_82AEP && device_type != TI83PCE) ||
196+
(model_id == TIMODEL_8384CE && device_type != TI84PCE)) {
197+
gui_console_err_printf("[CEmu] Got model<->device discrepency !?\n");
198+
}
195199

196200
break;
197201
}
198202

199203
state = EMU_STATE_VALID;
200204

201205
if (gotType) {
206+
set_model_type(model_id);
202207
set_device_type(device_type);
203208
} else {
209+
set_model_type(TIMODEL_8384CE);
204210
set_device_type(TI84PCE);
205211
gui_console_err_printf("[CEmu] Could not determine device device_type.\n");
206212
state = EMU_STATE_NOT_A_CE;

core/emu.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ void gui_console_err_printf(const char *format, ...); /* printf from the cor
4545
* boot_ver: boot code version if found, else NULL
4646
* loaded_rev: ASIC_REV_AUTO on reset, or loaded revision on state load
4747
* default_rev: default revision to use when returning ASIC_REV_AUTO
48+
* model: which model (83CE/84CE or 82AEP) we're actually emulating
4849
* python: determined edition based on certificate, can be overridden by updating its value
4950
* returns:
5051
* hardware revision to use; ignored when loading state */
51-
asic_rev_t gui_handle_reset(const boot_ver_t* boot_ver, asic_rev_t loaded_rev, asic_rev_t default_rev, bool* python);
52+
asic_rev_t gui_handle_reset(const boot_ver_t* boot_ver, asic_rev_t loaded_rev, asic_rev_t default_rev, ti_model_t model, bool* python);
5253

5354
#ifdef DEBUG_SUPPORT
5455
void gui_debug_open(int reason, uint32_t data); /* open the gui debugger */

core/spi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ static void spi_update(void) {
160160
}
161161

162162
/* Read from the SPI range of ports */
163+
/* TODO: something with asic.hasWorkingSPIReads probably */
163164
static uint8_t spi_read(uint16_t addr, bool peek) {
164165
static const uint16_t cr0_masks[16] = {
165166
0xF18C, 0xF8EF, 0xF0AC, 0xF3FC, 0xF18C, 0xF4C0, 0xF3AC, 0xF3AC,

gui/qt/emuthread.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ void gui_debug_close(void) {
4848
emu->debugDisable();
4949
}
5050

51-
asic_rev_t gui_handle_reset(const boot_ver_t* boot_ver, asic_rev_t loaded_rev, asic_rev_t default_rev, bool* python) {
52-
return emu->handleReset(boot_ver, loaded_rev, default_rev, python);
51+
asic_rev_t gui_handle_reset(const boot_ver_t* boot_ver, asic_rev_t loaded_rev, asic_rev_t default_rev, ti_model_t model, bool* python) {
52+
return emu->handleReset(boot_ver, loaded_rev, default_rev, model, python);
5353
}
5454

5555
namespace {
@@ -279,12 +279,12 @@ void EmuThread::unblock() {
279279
m_mutex.unlock();
280280
}
281281

282-
asic_rev_t EmuThread::handleReset(const boot_ver_t* bootVer, asic_rev_t loadedRev, asic_rev_t defaultRev, bool* python) {
282+
asic_rev_t EmuThread::handleReset(const boot_ver_t* bootVer, asic_rev_t loadedRev, asic_rev_t defaultRev, ti_model_t model, bool* python) {
283283
// Build a list of supported revisions
284284
QList<int> supportedRevs;
285285
supportedRevs.reserve(ASIC_REV_M - ASIC_REV_A + 1);
286286
for (int rev = ASIC_REV_A; rev <= ASIC_REV_M; rev++) {
287-
if (bootver_check_rev(bootVer, (asic_rev_t)rev)) {
287+
if (bootver_check_rev(bootVer, (asic_rev_t)rev, model)) {
288288
supportedRevs.push_back(rev);
289289
}
290290
}

gui/qt/emuthread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class EmuThread : public QThread {
3838
void setAsicRev(int rev);
3939
void setAllowAnyRev(bool allow);
4040
void setForcePython(Qt::CheckState state);
41-
asic_rev_t handleReset(const boot_ver_t* bootVer, asic_rev_t loadedRev, asic_rev_t defaultRev, bool* python);
41+
asic_rev_t handleReset(const boot_ver_t* bootVer, asic_rev_t loadedRev, asic_rev_t defaultRev, ti_model_t model, bool* python);
4242
void writeConsole(int console, const char *format, va_list args);
4343
void debugOpen(int reason, uint32_t addr);
4444
void save(emu_data_t fileType, const QString &filePath);

gui/sdl/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ static int8_t python_rev = -1;
2929
void gui_console_clear() {}
3030
void gui_console_printf(const char *format, ...) { (void)format; }
3131
void gui_console_err_printf(const char *format, ...) { (void)format; }
32-
asic_rev_t gui_handle_reset(const boot_ver_t* boot_ver, asic_rev_t loaded_rev, asic_rev_t default_rev, bool* python) {
32+
asic_rev_t gui_handle_reset(const boot_ver_t* boot_ver, asic_rev_t loaded_rev, asic_rev_t default_rev, ti_model_t model, bool* python) {
3333
(void)boot_ver;
3434
(void)loaded_rev;
3535
(void)default_rev;
36+
(void)model;
3637
if (python_rev >= 0) {
3738
*python = python_rev;
3839
}

0 commit comments

Comments
 (0)