2020-05-21 21:10:13 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <conio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2020-07-22 04:47:25 +00:00
|
|
|
#include "util.h"
|
2020-09-06 02:45:23 +00:00
|
|
|
#include "gwconio.h"
|
2023-09-21 08:25:33 +00:00
|
|
|
#include "ram2e_hal.h"
|
2023-09-30 00:55:19 +00:00
|
|
|
#include "ram2e_save.h"
|
2020-05-21 21:10:13 +00:00
|
|
|
|
2023-09-21 08:25:33 +00:00
|
|
|
static void menu()
|
|
|
|
{
|
|
|
|
clrscr(); // Clear screen
|
2020-06-01 07:00:31 +00:00
|
|
|
|
2023-09-21 08:25:33 +00:00
|
|
|
gwcputsxy(5, 1, "-- RAM2E Capacity Settings --");
|
2020-06-01 07:00:31 +00:00
|
|
|
|
2023-09-21 08:25:33 +00:00
|
|
|
gwcputsxy(1, 6, "Select desired memory capacity:");
|
2020-05-22 22:25:08 +00:00
|
|
|
|
2023-09-21 08:25:33 +00:00
|
|
|
gwcputsxy(4, 7, "1. 64 kilobytes");
|
|
|
|
gwcputsxy(4, 8, "2. 512 kilobytes");
|
|
|
|
gwcputsxy(4, 9, "3. 1 megabyte");
|
|
|
|
gwcputsxy(4, 10, "4. 4 megabytes");
|
|
|
|
gwcputsxy(4, 11, "5. 8 megabytes");
|
2020-05-21 21:10:13 +00:00
|
|
|
|
2023-09-21 08:25:33 +00:00
|
|
|
gwcputsxy(1, 17, "Capacity will be saved until power-off.");
|
2020-05-22 22:25:08 +00:00
|
|
|
|
2023-09-21 08:25:33 +00:00
|
|
|
gwcputsxy(1, 19, "To remember capacity setting in");
|
|
|
|
gwcputsxy(1, 20, "nonvolatile memory, press Apple+number.");
|
2020-05-22 22:25:08 +00:00
|
|
|
|
2023-09-21 08:25:33 +00:00
|
|
|
gwcputsxy(1, 22, "Press [Q] to quit without saving.");
|
2020-05-21 21:10:13 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 08:25:33 +00:00
|
|
|
static void menu_size(uint16_t bankcount, char has16m) {
|
2020-06-01 21:17:31 +00:00
|
|
|
if (bankcount < 2) { gotoxy(5, 3); }
|
|
|
|
else { gotoxy(4, 3); }
|
2020-09-06 02:45:23 +00:00
|
|
|
gwcputs("Current RAM2E capacity: ");
|
|
|
|
printf("%d", bankcount * 64);
|
|
|
|
gwcputs(" kB");
|
|
|
|
|
2023-09-21 08:25:33 +00:00
|
|
|
if(has16m) { gwcputsxy(4, 12, "6. 16 megabytes"); }
|
|
|
|
}
|
2020-09-06 02:45:23 +00:00
|
|
|
|
2023-09-21 08:25:33 +00:00
|
|
|
static void menu_led(char enled) {
|
|
|
|
if (enled) {
|
|
|
|
gwcputsxy(1, 14, "LED enabled. Press [L] to disable LED.");
|
|
|
|
} else {
|
|
|
|
gwcputsxy(1, 14, "LED disabled. Press [L] to enable LED.");
|
|
|
|
}
|
2020-05-21 21:10:13 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 04:47:25 +00:00
|
|
|
int ram2e_main(void)
|
2020-05-21 21:10:13 +00:00
|
|
|
{
|
2023-09-21 08:25:33 +00:00
|
|
|
char type;
|
2020-08-03 01:34:56 +00:00
|
|
|
uint16_t bankcount;
|
2023-09-21 08:25:33 +00:00
|
|
|
char mask = 0;
|
|
|
|
char has16m = false;
|
|
|
|
char hasled = false;
|
|
|
|
char enled = false;
|
|
|
|
|
|
|
|
char nvm = false;
|
|
|
|
int reset_count = 0;
|
2020-05-21 21:10:13 +00:00
|
|
|
|
2020-08-03 01:02:10 +00:00
|
|
|
ramworks_save(); // Save what will be clobbered
|
2023-09-21 08:25:33 +00:00
|
|
|
if (auxram_detect()) {
|
|
|
|
if (ram2e_detect(0xFF)) { // MAX
|
|
|
|
type = 0xFF;
|
|
|
|
/*} else if (ram2e_detect(0xFE)) { // SPI
|
|
|
|
type = 0xFE;*/
|
|
|
|
} else if (ram2e_detect(0xFD)) { // MachXO2
|
|
|
|
type = 0xFD;
|
|
|
|
} else { type = 0; }
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == 0) {
|
|
|
|
#ifndef SKIP_RAM2E_DETECT
|
2020-08-03 01:34:56 +00:00
|
|
|
ramworks_restore();
|
2020-06-01 07:00:31 +00:00
|
|
|
// If no RAM2E, show an error message and quit
|
2023-09-21 08:25:33 +00:00
|
|
|
gwcputsxy(0, 8, " No RAM2E II detected.");
|
2020-09-06 02:45:23 +00:00
|
|
|
gwcputsxy(0, 10, " Press any key to quit.");
|
2020-06-01 07:00:31 +00:00
|
|
|
cgetc(); // Wait for key
|
|
|
|
clrscr(); // Clear screen before quitting
|
|
|
|
return EXIT_SUCCESS;
|
2023-09-21 08:25:33 +00:00
|
|
|
#endif
|
2020-06-01 07:00:31 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 08:25:33 +00:00
|
|
|
// Set chip type
|
|
|
|
ram2e_hal_set_type(type);
|
|
|
|
|
|
|
|
// Print menu
|
|
|
|
menu();
|
|
|
|
|
|
|
|
// Detect and print current capacity plus 16 MB option
|
|
|
|
#ifndef SKIP_RAM2E_DETECT
|
2020-08-03 01:34:56 +00:00
|
|
|
bankcount = ramworks_getsize();
|
2023-09-21 08:25:33 +00:00
|
|
|
// If set for 8 MB, check for 16 MB capability
|
|
|
|
if (bankcount >= 128) {
|
|
|
|
ram2e_set_mask(0xFF);
|
|
|
|
has16m = ramworks_getsize() == 256;
|
|
|
|
ram2e_set_mask(0x7F);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
bankcount = 128;
|
|
|
|
#endif
|
|
|
|
menu_size(bankcount, has16m); // Print size
|
|
|
|
|
|
|
|
// Detect and print LED menu
|
|
|
|
#ifndef SKIP_RAM2E_DETECT
|
|
|
|
hasled = ram2e_detect(0xF0);
|
|
|
|
if (hasled) {
|
|
|
|
enled = ram2e_detect(0xE3);
|
|
|
|
menu_led(enled);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
hasled = true;
|
|
|
|
#endif
|
|
|
|
|
2020-08-03 01:34:56 +00:00
|
|
|
ramworks_restore(); // Restore RAMWorks contents
|
2020-05-21 21:10:13 +00:00
|
|
|
|
2020-05-22 22:25:08 +00:00
|
|
|
// Get user choice from menu
|
2020-05-21 21:10:13 +00:00
|
|
|
while (true) {
|
2020-05-22 22:25:08 +00:00
|
|
|
// Set capacity mask or quit according to keypress.
|
2020-07-22 04:47:25 +00:00
|
|
|
switch (toupper(cgetc() & 0x7F)) {
|
2020-05-22 22:25:08 +00:00
|
|
|
case 'Q' : {
|
|
|
|
clrscr();
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
case '1': mask = 0x00; break;
|
|
|
|
case '2': mask = 0x07; break;
|
|
|
|
case '3': mask = 0x0F; break;
|
|
|
|
case '4': mask = 0x3F; break;
|
|
|
|
case '5': mask = 0x7F; break;
|
2023-09-21 08:25:33 +00:00
|
|
|
case '6': {
|
|
|
|
if (has16m) { mask = 0xFF; break; }
|
|
|
|
else { continue; }
|
|
|
|
#ifdef SKIP_RAM2E_DETECT
|
|
|
|
} case '7': {
|
|
|
|
menu_size(bankcount, 1);
|
|
|
|
continue;
|
|
|
|
#endif
|
|
|
|
} case 'L': {
|
|
|
|
if (hasled) {
|
|
|
|
enled = !enled;
|
|
|
|
ram2e_set_led(enled);
|
|
|
|
menu_led(enled);
|
|
|
|
if (enled) {
|
|
|
|
wait(1);
|
|
|
|
ram2e_flashled(10);
|
|
|
|
wait(10);
|
|
|
|
ram2e_flashled(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
} case 'R': {
|
2020-06-01 21:17:31 +00:00
|
|
|
reset_count++;
|
2020-09-06 03:48:51 +00:00
|
|
|
if (reset_count >= 25) {
|
|
|
|
// Show message about resetting.
|
2020-06-01 08:02:40 +00:00
|
|
|
clrscr(); // Clear screen
|
2020-09-06 02:45:23 +00:00
|
|
|
gwcputsxy(1, 8, "Resetting RAM2E settings.");
|
|
|
|
gwcputsxy(1, 9, "Do not turn off your Apple.");
|
2020-06-01 08:02:40 +00:00
|
|
|
|
2023-09-21 08:25:33 +00:00
|
|
|
ram2e_erase(); // Erase RAM2E settings memory
|
|
|
|
ram2e_set_mask(0x7F); // Set mask to default (0x7F)
|
2020-06-01 08:02:40 +00:00
|
|
|
|
|
|
|
// Wait for >= 500ms on even the fastest systems.
|
|
|
|
spin(32, 8);
|
|
|
|
|
|
|
|
// Show success message and quit
|
|
|
|
clrscr(); // Clear screen
|
2020-09-06 02:45:23 +00:00
|
|
|
gwcputsxy(1, 8, "RAM2E settings reset successfully.");
|
2020-06-01 08:02:40 +00:00
|
|
|
goto end;
|
2020-06-01 21:17:31 +00:00
|
|
|
}
|
2020-09-06 04:00:30 +00:00
|
|
|
continue;
|
2020-09-06 03:48:51 +00:00
|
|
|
} default: reset_count = 0; continue;
|
2020-05-21 21:10:13 +00:00
|
|
|
}
|
2020-05-22 22:25:08 +00:00
|
|
|
|
2020-07-22 04:47:25 +00:00
|
|
|
// Check if pressed with apple key. If so, save to nonvolatile memory.
|
2020-05-21 21:10:13 +00:00
|
|
|
if (read_applekey()) { nvm = true; }
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-05-22 22:25:08 +00:00
|
|
|
// Set capacity in volatile memory.
|
2023-09-21 08:25:33 +00:00
|
|
|
ram2e_set_mask(mask);
|
2020-05-21 21:10:13 +00:00
|
|
|
|
2020-05-22 22:25:08 +00:00
|
|
|
// Clear screen in preparation to show saving or success message.
|
2020-05-21 21:10:13 +00:00
|
|
|
clrscr();
|
|
|
|
|
2020-05-22 22:25:08 +00:00
|
|
|
if (nvm) { // Save in NVM if requested.
|
|
|
|
// Show message about saving.
|
2020-09-06 02:45:23 +00:00
|
|
|
gwcputsxy(1, 8, "Saving RAM2E capacity setting.");
|
|
|
|
gwcputsxy(1, 9, "Do not turn off your Apple.");
|
2020-05-22 22:25:08 +00:00
|
|
|
// Save capacity in nonvolatile memory.
|
2023-09-21 08:25:33 +00:00
|
|
|
ram2e_save_start(mask, enled);
|
2020-05-22 22:25:08 +00:00
|
|
|
// Wait for >= 500ms on even the fastest systems.
|
2020-05-21 21:10:13 +00:00
|
|
|
spin(32, 8);
|
2023-09-21 08:25:33 +00:00
|
|
|
// Finish saving
|
|
|
|
ram2e_save_end(mask, enled);
|
2020-06-01 08:02:40 +00:00
|
|
|
// Print success message
|
|
|
|
clrscr(); // Clear screen
|
2020-09-06 02:45:23 +00:00
|
|
|
gwcputsxy(1, 8, "RAM2E capacity saved successfully.");
|
2020-05-22 22:25:08 +00:00
|
|
|
} else { // Print success message if not saving in NVM.
|
2020-09-06 02:45:23 +00:00
|
|
|
gwcputsxy(1, 8, "RAM2E capacity set successfully.");
|
2020-05-21 21:10:13 +00:00
|
|
|
}
|
2020-06-01 08:02:40 +00:00
|
|
|
|
|
|
|
end:
|
2020-08-03 01:01:57 +00:00
|
|
|
if (nvm) { // Show end message for nonvolatile save
|
2020-09-06 02:45:23 +00:00
|
|
|
gwcputsxy(1, 10, "You may now turn off your Apple.");
|
|
|
|
gwcputsxy(1, 12, "You may also reset your Apple for");
|
|
|
|
gwcputsxy(1, 13, "the setting change to take effect.");
|
2020-08-03 01:01:57 +00:00
|
|
|
} else { // Show end message for volatile save
|
2020-09-06 02:45:23 +00:00
|
|
|
gwcputsxy(1, 10, "Please reset your Apple for");
|
|
|
|
gwcputsxy(1, 11, "the setting change to take effect.");
|
2020-08-03 01:01:57 +00:00
|
|
|
}
|
|
|
|
// Don't quit. Instead leave prompt asking user to reset.
|
|
|
|
while(1) { cgetc(); }
|
2020-05-21 21:10:13 +00:00
|
|
|
}
|