mirror of
https://github.com/garrettsworkshop/GWRAM.SYSTEM.git
synced 2025-10-31 11:56:44 -07:00
Fixed up Altera support
This commit is contained in:
75
ram2gs.c
75
ram2gs.c
@@ -11,9 +11,13 @@
|
||||
|
||||
static void ram2gs_erase() { ram2gs_cmd(0x28); }
|
||||
static void ram2gs_program() { ram2gs_cmd(0x24); }
|
||||
static void ram2gs_set4mb() { ram2gs_cmd(0x10); }
|
||||
static void ram2gs_set8mb() { ram2gs_cmd(0x11); }
|
||||
static void ram2gs_setnvm(char en8meg) {
|
||||
static void ram2gs_set(char en8meg, char enled) {
|
||||
char cmd = 0x10;
|
||||
if (en8meg) { cmd |= 0x01; }
|
||||
if (enled) { cmd |= 0x02; }
|
||||
ram2gs_cmd(cmd);
|
||||
}
|
||||
static void ram2gs_set_nvm(char en8meg, char enled) {
|
||||
char i;
|
||||
// Clock in 0 to enable this setting entry
|
||||
ram2gs_cmd(0x20);
|
||||
@@ -29,8 +33,18 @@ static void ram2gs_setnvm(char en8meg) {
|
||||
ram2gs_cmd(0x22);
|
||||
}
|
||||
|
||||
// Clock in 14 dummy "1"s
|
||||
for (i = 0; i < 14; i++) {
|
||||
if (enled) {
|
||||
// Clock in 0 to enable LED
|
||||
ram2gs_cmd(0x20);
|
||||
ram2gs_cmd(0x22);
|
||||
} else {
|
||||
// Clock in 1 to disable LED
|
||||
ram2gs_cmd(0x21);
|
||||
ram2gs_cmd(0x23);
|
||||
}
|
||||
|
||||
// Clock in 13 dummy "1"s
|
||||
for (i = 0; i < 13; i++) {
|
||||
ram2gs_cmd(0x21);
|
||||
ram2gs_cmd(0x23);
|
||||
}
|
||||
@@ -38,7 +52,15 @@ static void ram2gs_setnvm(char en8meg) {
|
||||
ram2gs_program();
|
||||
}
|
||||
|
||||
static void menu(void)
|
||||
static void menu_led(char enled) {
|
||||
if (enled) {
|
||||
gwcputsxy(1, 15, "LED enabled. Press [L] to disable LED.");
|
||||
} else {
|
||||
gwcputsxy(1, 15, "LED disabled. Press [L] to enable LED.");
|
||||
}
|
||||
}
|
||||
|
||||
static void menu()
|
||||
{
|
||||
uint8_t bankcount = ram2gs_getsize();
|
||||
gwcputsxy(5, 1, "-- RAM2GS Capacity Settings --");
|
||||
@@ -63,28 +85,32 @@ static void menu(void)
|
||||
|
||||
int ram2gs_main(void)
|
||||
{
|
||||
char en8meg;
|
||||
char nvm;
|
||||
int reset_count;
|
||||
char hasled = 1;
|
||||
char typecode = 0;
|
||||
char enled = 0;
|
||||
char en8meg = 1;
|
||||
char nvm = 0;
|
||||
int reset_count = 0;
|
||||
|
||||
// Check for RAM2GS
|
||||
#ifndef SKIP_RAM2GS_DETECT
|
||||
if(!ram2gs_detect()) {
|
||||
if (ram2gs_detect(0 << 2)) {
|
||||
hasled = !ram2gs_detect(0x04);
|
||||
typecode = 0x0;
|
||||
} else {
|
||||
#ifndef SKIP_RAM2GS_DETECT
|
||||
// If no RAM2GS, show an error message and quit
|
||||
gwcputsxy(0, 8, " No RAM2GS II detected.");
|
||||
gwcputsxy(0, 10, " Press any key to quit.");
|
||||
cgetc(); // Wait for key
|
||||
clrscr(); // Clear screen before quitting
|
||||
return EXIT_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
menu(); // Print menu
|
||||
if (hasled) { enled = !ram2gs_detect(typecode | 0x02); }
|
||||
menu();
|
||||
if (hasled) { menu_led(enled); }
|
||||
|
||||
// Get user choice from menu
|
||||
en8meg = 0;
|
||||
nvm = 0;
|
||||
reset_count = 0;
|
||||
while (true) {
|
||||
// Set capacity or quit according to keypress.
|
||||
switch (toupper(cgetc() & 0x7F)) {
|
||||
@@ -92,9 +118,14 @@ int ram2gs_main(void)
|
||||
clrscr();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
case '1': en8meg = 0; ram2gs_set4mb(); break;
|
||||
case '2': en8meg = 1; ram2gs_set8mb(); break;
|
||||
case 'R': {
|
||||
case '1': en8meg = 0; ram2gs_set(0, enled); break;
|
||||
case '2': en8meg = 1; ram2gs_set(1, enled); break;
|
||||
case 'L': {
|
||||
if (enled == 0) { enled = 1; }
|
||||
else { enled = 0; }
|
||||
if (hasled) { menu_led(enled); };
|
||||
continue;
|
||||
} case 'R': {
|
||||
reset_count++;
|
||||
if (reset_count >= 25) {
|
||||
// Show message about resetting.
|
||||
@@ -103,7 +134,7 @@ int ram2gs_main(void)
|
||||
gwcputsxy(1, 9, "Do not turn off your Apple.");
|
||||
|
||||
ram2gs_erase(); // Erase RAM2GS settings memory
|
||||
ram2gs_set8mb(); // Enable 8 megabytes now
|
||||
ram2gs_set(1, 0); // Enable 8 megabytes and disable LED
|
||||
|
||||
// Wait for >= 500ms on even the fastest systems.
|
||||
spin(32, 8);
|
||||
@@ -130,7 +161,7 @@ int ram2gs_main(void)
|
||||
gwcputsxy(1, 8, "Saving RAM2GS capacity setting.");
|
||||
gwcputsxy(1, 9, "Do not turn off your Apple.");
|
||||
// Save capacity in nonvolatile memory.
|
||||
ram2gs_setnvm(en8meg);
|
||||
ram2gs_set_nvm(en8meg, enled);
|
||||
// Wait for >= 500ms on even the fastest systems.
|
||||
spin(33, 8);
|
||||
// Print success message
|
||||
|
||||
Reference in New Issue
Block a user