?login_element?

Subversion Repositories NedoOS

Rev

Rev 539 | Blame | Compare with Previous | Last modification | View Log | Download

  1. /*
  2.  
  3.   SjASMPlus Z80 Cross Compiler
  4.  
  5.   Copyright (c) 2004-2006 Aprisobal
  6.  
  7.   This software is provided 'as-is', without any express or implied warranty.
  8.   In no event will the authors be held liable for any damages arising from the
  9.   use of this software.
  10.  
  11.   Permission is granted to anyone to use this software for any purpose,
  12.   including commercial applications, and to alter it and redistribute it freely,
  13.   subject to the following restrictions:
  14.  
  15.   1. The origin of this software must not be misrepresented; you must not claim
  16.          that you wrote the original software. If you use this software in a product,
  17.          an acknowledgment in the product documentation would be appreciated but is
  18.          not required.
  19.  
  20.   2. Altered source versions must be plainly marked as such, and must not be
  21.          misrepresented as being the original software.
  22.  
  23.   3. This notice may not be removed or altered from any source distribution.
  24.  
  25. */
  26.  
  27. // devices.h
  28.  
  29. bool IsZXSpectrumDevice(const char *name);
  30. bool IsAmstradCPCDevice(const char* name);
  31. bool SetDevice(const char *const_id, const aint ramtop = 0);
  32. const char* GetDeviceName();
  33.  
  34. class CDevicePage {
  35. public:
  36.         CDevicePage(byte* memory, int32_t size, int number);
  37.         int32_t Size;
  38.         int Number;
  39.         byte* RAM;
  40. private:
  41. };
  42.  
  43. class CDeviceSlot {
  44. public:
  45.         enum ESlotOptions { O_NONE, O_ERROR, O_WARNING, O_NEXT };
  46.  
  47.         CDeviceSlot(int32_t adr, int32_t size);
  48.         ~CDeviceSlot();
  49.         int32_t Address;
  50.         int32_t Size;
  51.         CDevicePage* Page;
  52.         int16_t InitialPage;
  53.         ESlotOptions Option;
  54. private:
  55. };
  56.  
  57. class CDeviceDef {
  58. public:
  59.  
  60.         constexpr static size_t MAX_SLOT_N = 256;       // minimum possible slot size is 256 bytes
  61.         constexpr static size_t MAX_PAGE_N = 1024;      // maximum possible total memory is 64MB with 64ki slot size
  62.  
  63.         CDeviceDef(const CDeviceDef&) = delete;
  64.         CDeviceDef(const char* name, aint slot_size, aint page_count);
  65.         ~CDeviceDef();
  66.  
  67.         const char* getID() const { return ID; }
  68.         const aint SlotSize;
  69.         const aint SlotsCount;
  70.         const aint PagesCount;
  71.         int initialPages[MAX_SLOT_N] = {};
  72.  
  73. private:
  74.         char* ID;
  75. };
  76.  
  77. class CDevice {
  78. public:
  79.         // reset will reinitialize checks, "no emit" will do wrap-only (no machine byte emitted)
  80.         // "emit" will also report error/warning upon boundary, as the machine byte emit is expected
  81.         enum ECheckPageLevel{ CHECK_RESET, CHECK_NO_EMIT, CHECK_EMIT };
  82.  
  83.         CDevice(const CDevice&) = delete;
  84.         CDevice(const char* name, CDevice* parent);
  85.         ~CDevice();
  86.         void AddSlot(int32_t adr, int32_t size);
  87.         void AddPage(byte* memory, int32_t size);
  88.         CDevicePage* GetPage(int);
  89.         CDeviceSlot* GetSlot(int);
  90.         int GetSlotOfA16(int32_t address);
  91.         int GetPageOfA16(int32_t address);
  92.         void CheckPage(const ECheckPageLevel level);
  93.         bool SetSlot(int slotNumber);           // sets "current/active" slot
  94.         CDeviceSlot* GetCurrentSlot();          // returns "current/active" slot
  95.         int GetCurrentSlotNum() const { return CurrentSlot; }   // returns "current/active" slot
  96.         int32_t GetMemoryOffset(int page, int32_t offset) const;
  97.         void Poke(aint z80adr, byte value);     // write byte into device memory with current page-mapping
  98.         aint SlotNumberFromPreciseAddress(aint address);
  99.         char* ID;
  100.         CDevice* Next;
  101.         int SlotsCount;
  102.         int PagesCount;
  103.         byte* Memory;
  104.         aint ZxRamTop;          // for ZX-like machines, the RAMTOP system variable
  105. private:
  106.         int CurrentSlot;
  107.         CDeviceSlot* Slots[CDeviceDef::MAX_SLOT_N];
  108.         CDevicePage* Pages[CDeviceDef::MAX_PAGE_N];
  109.  
  110.         // variables for CheckPage logic
  111.         int previousSlotI;                              // previous machine code write happened into this slot
  112.         CDeviceSlot::ESlotOptions previousSlotOpt;      // its option was
  113.         bool limitExceeded;                             // true if limit exceeded was already reported
  114. };
  115.  
  116. constexpr aint ZX_RAMTOP_DEFAULT = 0x5D5B;      // 0xFF57 is regular ROM default
  117.         // but 0x5D5B is minimum to keep "CLEAR 54321" still working if you return to BASIC (snapshot)
  118. constexpr aint ZX_SYSVARS_ADR = 0x5C00;
  119. constexpr aint ZX_UDG_ADR = 0xFF58;
  120.  
  121. extern const unsigned char ZX_SYSVARS_DATA[256];
  122. extern const unsigned char ZX_STACK_DATA[4];
  123. extern const unsigned char ZX_UDG_DATA[168];
  124.