Advertisement
Astranome

CPM9

Jul 28th, 2020
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.12 KB | None | 0 0
  1. /*
  2.   Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - www.fabgl.com
  3.   Copyright (c) 2019-2020 Fabrizio Di Vittorio.
  4.   All rights reserved.
  5.  
  6.   This file is part of FabGL Library.
  7.  
  8.   FabGL is free software: you can redistribute it and/or modify
  9.   it under the terms of the GNU General Public License as published by
  10.   the Free Software Foundation, either version 3 of the License, or
  11.   (at your option) any later version.
  12.  
  13.   FabGL is distributed in the hope that it will be useful,
  14.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.   GNU General Public License for more details.
  17.  
  18.   You should have received a copy of the GNU General Public License
  19.   along with FabGL.  If not, see <http://www.gnu.org/licenses/>.
  20.  */
  21.  
  22.  
  23. /*
  24.  * Optional SD Card connections:
  25.  *   MISO => GPIO 16
  26.  *   MOSI => GPIO 17
  27.  *   CLK  => GPIO 14
  28.  *   CS   => GPIO 13
  29.  *
  30.  * To change above assignment fill other paramaters of FileBrowser::mountSDCard().
  31.  */
  32.  
  33.  
  34.  
  35.  
  36.  
  37. #include "fabgl.h"
  38. #include "src/supervisor.h"
  39. #include "src/programs.h"
  40.  
  41.  
  42.  
  43. // Flash and SDCard configuration
  44. #define FORMAT_ON_FAIL     true
  45. #define SPIFFS_MOUNT_PATH  "/flash"
  46. #define SDCARD_MOUNT_PATH  "/SD"
  47. #define MAXFILES           6     // SDCARD: each file takes about 4K of RAM!
  48.  
  49. #define TFT_SCK    18
  50. #define TFT_MOSI   23
  51. #define TFT_CS     5
  52. #define TFT_DC     22
  53. #define TFT_RESET  21
  54. #define TFT_SPIBUS VSPI_HOST
  55.  
  56.  
  57.  
  58. // globals
  59. fabgl::ILI9341Controller DisplayController;
  60. //fabgl::VGATextController DisplayController;
  61. fabgl::PS2Controller     PS2Controller;
  62.  
  63. Supervisor supervisor(&DisplayController);
  64.  
  65.  
  66.  
  67. // base path (can be SPIFFS_MOUNT_PATH or SDCARD_MOUNT_PATH depending from what was successfully mounted first)
  68. char const * basepath = nullptr;
  69.  
  70.  
  71. String driveA_path;
  72. String driveB_path;
  73.  
  74.  
  75.  
  76. void setup()
  77. {
  78.   //Serial.begin(115200); delay(500); Serial.write("\r\nReset\r\n");
  79.  
  80.   disableCore0WDT();
  81.   disableCore1WDT();
  82.  
  83.   // Reduces some defaults to save RAM...
  84.   //fabgl::VGAController::queueSize                    = 128;
  85.   fabgl::Terminal::inputQueueSize                    = 32;
  86.   fabgl::Terminal::inputConsumerTaskStackSize        = 1024;
  87.   fabgl::Terminal::keyboardReaderTaskStackSize       = 800;
  88.   fabgl::Keyboard::scancodeToVirtualKeyTaskStackSize = 1500;
  89.  
  90.   // setup Keyboard (default configuration)
  91.   PS2Controller.begin(PS2Preset::KeyboardPort0);
  92.  
  93.   // setup VGA (default configuration with 64 colors)
  94.   DisplayController.begin(TFT_SCK, TFT_MOSI, TFT_DC, TFT_RESET, TFT_CS, TFT_SPIBUS);
  95.   DisplayController.setResolution(TFT_240x320);
  96.   DisplayController.setOrientation(fabgl::TFTOrientation::Rotate90);
  97.   //DisplayController.begin();
  98.   //DisplayController.setResolution(VGA_640x200_70Hz);
  99.   //DisplayController.setResolution(VGA_640x480_60Hz, 640, 200);
  100.  
  101.   auto term = new fabgl::Terminal;
  102.   term->begin(&DisplayController);
  103.   term->connectLocally();      // to use Terminal.read(), available(), etc..
  104.  
  105.   term->loadFont(&fabgl::FONT_10x20);
  106.   term->clear();
  107.   term->write("Initializing...\r");
  108.   term->flush();
  109.  
  110.   if (FileBrowser::mountSDCard(FORMAT_ON_FAIL, SDCARD_MOUNT_PATH, MAXFILES))
  111.     basepath = SDCARD_MOUNT_PATH;
  112.   else if (FileBrowser::mountSPIFFS(FORMAT_ON_FAIL, SPIFFS_MOUNT_PATH, MAXFILES))
  113.     basepath = SPIFFS_MOUNT_PATH;
  114.  
  115.   // uncomment to format SPIFFS or SD card
  116.   //FileBrowser::format(fabgl::DriveType::SPIFFS, 0);
  117.   //FileBrowser::format(fabgl::DriveType::SDCard, 0);
  118.  
  119.   driveA_path = String(basepath) + String("/driveA");
  120.   driveB_path = String(basepath) + String("/driveB");
  121.  
  122.   FileBrowser fb;
  123.  
  124.   fb.setDirectory(basepath);
  125.   if (!fb.exists("driveA")) {
  126.  
  127.     fb.makeDirectory("driveA");
  128.  
  129.     // create default programs
  130.     for (int i = 0; i < sizeof(programs) / sizeof(Program); ++i) {
  131.       term->printf("Creating %s\\%s\r\n", programs[i].path, programs[i].filename);
  132.       term->flush();
  133.       // check directory
  134.       fb.setDirectory(driveA_path.c_str());
  135.       if (!fb.exists(programs[i].path))
  136.         fb.makeDirectory(programs[i].path);
  137.       fb.changeDirectory(programs[i].path);
  138.       // copy file
  139.       AutoSuspendInterrupts autoInt;
  140.       FILE * f = fb.openFile(programs[i].filename, "wb");
  141.       if (f) {
  142.         fwrite(programs[i].data, 1, programs[i].size, f);
  143.         fclose(f);
  144.       } else {
  145.         term->write("  FAILED!\r\n");
  146.       }
  147.     }
  148.  
  149.   }
  150.  
  151.   fb.setDirectory(basepath);
  152.   if (!fb.exists("driveB"))
  153.     fb.makeDirectory("driveB");
  154.  
  155.   delete term;
  156.  
  157.   supervisor.onNewSession = [&](HAL * hal) {
  158.  
  159.     hal->mountDrive(0, driveA_path.c_str());
  160.     hal->mountDrive(1, driveB_path.c_str());
  161.  
  162.     // Serial (USB) ->  CP/M AUX1
  163.     hal->setSerial(0, &Serial);
  164.   };
  165.  
  166.   // change terminal when pressing F1..F12
  167.   PS2Controller.keyboard()->onVirtualKey = [&](VirtualKey * vk, bool keyDown) {
  168.     if (*vk >= VirtualKey::VK_F1 && *vk <= VirtualKey::VK_F12) {
  169.       if (keyDown) {
  170.         supervisor.activateSession((int)*vk - VirtualKey::VK_F1);
  171.       }
  172.       *vk = VirtualKey::VK_NONE;
  173.     }
  174.   };
  175.  
  176.  
  177.  
  178. }
  179.  
  180.  
  181. void loop()
  182. {
  183.   supervisor.activateSession(0);
  184.   vTaskDelete(NULL);
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement