libsidplayfp  2.1.0
c64cpu.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright (C) 2012-2020 Leandro Nini
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef C64CPU_H
22 #define C64CPU_H
23 
24 #include "c64/c64env.h"
25 #include "CPU/mos6510.h"
26 
27 #ifdef VICE_TESTSUITE
28 # include <iostream>
29 # include <cstdlib>
30 //#define PRINTSCREENCODES
31 #endif
32 
33 #include "sidcxx11.h"
34 
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38 
39 namespace libsidplayfp
40 {
41 #ifdef PRINTSCREENCODES
45 static const char CHRtab[256] =
46 {
47  0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
48  0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b, 0x1, 0x1, 0x1, 0x1,
49  0x20,0x21, 0x1,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
50  0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
51  0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
52  0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x5b,0x24,0x5d,0x20,0x20,
53  // alternative: CHR$(92=0x5c) => ISO Latin-1(0xa3)
54  0x2d,0x23,0x7c,0x2d,0x2d,0x2d,0x2d,0x7c,0x7c,0x5c,0x5c,0x2f,0x5c,0x5c,0x2f,0x2f,
55  0x5c,0x23,0x5f,0x23,0x7c,0x2f,0x58,0x4f,0x23,0x7c,0x23,0x2b,0x7c,0x7c,0x26,0x5c,
56  // 0x80-0xFF
57  0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
58  0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
59  0x20,0x7c,0x23,0x2d,0x2d,0x7c,0x23,0x7c,0x23,0x2f,0x7c,0x7c,0x2f,0x5c,0x5c,0x2d,
60  0x2f,0x2d,0x2d,0x7c,0x7c,0x7c,0x7c,0x2d,0x2d,0x2d,0x2f,0x5c,0x5c,0x2f,0x2f,0x23,
61  0x20,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
62  0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x2b,0x7c,0x7c,0x26,0x5c,
63  0x20,0x7c,0x23,0x2d,0x2d,0x7c,0x23,0x7c,0x23,0x2f,0x7c,0x7c,0x2f,0x5c,0x5c,0x2d,
64  0x2f,0x2d,0x2d,0x7c,0x7c,0x7c,0x7c,0x2d,0x2d,0x2d,0x2f,0x5c,0x5c,0x2f,0x2f,0x23
65 };
66 #endif
67 class c64cpu final : public MOS6510
68 {
69 private:
70  c64env &m_env;
71 
72 protected:
73  uint8_t cpuRead(uint_least16_t addr) override { return m_env.cpuRead(addr); }
74 
75  void cpuWrite(uint_least16_t addr, uint8_t data) override
76  {
77 #ifdef PRINTSCREENCODES
78  if (addr >= 1024 && addr <= 2047)
79  {
80  std::cout << CHRtab[data];
81  }
82 #endif
83 #ifdef VICE_TESTSUITE
84  // for VICE tests
85  if (addr == 0xd7ff)
86  {
87  if (data == 0)
88  {
89  std::cout << std::endl << "OK" << std::endl;
90  exit(EXIT_SUCCESS);
91  }
92  else if (data == 0xff)
93  {
94  std::cout << std::endl << "KO" << std::endl;
95  exit(EXIT_FAILURE);
96  }
97  }
98 #endif
99  m_env.cpuWrite(addr, data);
100  }
101 
102 public:
103  c64cpu (c64env &env) :
104  MOS6510(env.scheduler()),
105  m_env(env) {}
106 };
107 
108 }
109 
110 #endif // C64CPU_H
Definition: mos6510.h:72
Definition: c64cpu.h:68
void cpuWrite(uint_least16_t addr, uint8_t data) override
Definition: c64cpu.h:75
uint8_t cpuRead(uint_least16_t addr) override
Definition: c64cpu.h:73
Definition: c64env.h:41