libsidplayfp  2.2.2
c64cpu.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright (C) 2012-2021 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 #endif
31 
32 //#define PRINTSCREENCODES
33 
34 #include "sidcxx11.h"
35 
36 #ifdef HAVE_CONFIG_H
37 # include "config.h"
38 #endif
39 
40 namespace libsidplayfp
41 {
42 #ifdef PRINTSCREENCODES
46 static const char CHRtab[256] =
47 {
48  0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
49  0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x01,0x01,0x01,0x01,
50  0x20,0x21,0x01,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
51  0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
52  0x40,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
53  0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x5b,0x24,0x5d,0x20,0x20,
54  // alternative: CHR$(92=0x5c) => ISO Latin-1(0xa3)
55  0x2d,0x23,0x7c,0x2d,0x2d,0x2d,0x2d,0x7c,0x7c,0x5c,0x5c,0x2f,0x5c,0x5c,0x2f,0x2f,
56  0x5c,0x23,0x5f,0x23,0x7c,0x2f,0x58,0x4f,0x23,0x7c,0x23,0x2b,0x7c,0x7c,0x26,0x5c,
57  // 0x80-0xFF
58  0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
59  0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
60  0x20,0x7c,0x23,0x2d,0x2d,0x7c,0x23,0x7c,0x23,0x2f,0x7c,0x7c,0x2f,0x5c,0x5c,0x2d,
61  0x2f,0x2d,0x2d,0x7c,0x7c,0x7c,0x7c,0x2d,0x2d,0x2d,0x2f,0x5c,0x5c,0x2f,0x2f,0x23,
62  0x20,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
63  0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x2b,0x7c,0x7c,0x26,0x5c,
64  0x20,0x7c,0x23,0x2d,0x2d,0x7c,0x23,0x7c,0x23,0x2f,0x7c,0x7c,0x2f,0x5c,0x5c,0x2d,
65  0x2f,0x2d,0x2d,0x7c,0x7c,0x7c,0x7c,0x2d,0x2d,0x2d,0x2f,0x5c,0x5c,0x2f,0x2f,0x23
66 };
67 #endif
68 class c64cpu final : public MOS6510
69 {
70 private:
71  c64env &m_env;
72 
73 protected:
74  uint8_t cpuRead(uint_least16_t addr) override { return m_env.cpuRead(addr); }
75 
76  void cpuWrite(uint_least16_t addr, uint8_t data) override
77  {
78 #ifdef PRINTSCREENCODES
79  if (addr >= 1024 && addr <= 2047)
80  {
81  std::cout << CHRtab[data];
82  }
83 #endif
84 #ifdef VICE_TESTSUITE
85  // for VICE tests
86  if (addr == 0xd7ff)
87  {
88  if (data == 0)
89  {
90  std::cout << std::endl << "OK" << std::endl;
91  exit(EXIT_SUCCESS);
92  }
93  else if (data == 0xff)
94  {
95  std::cout << std::endl << "KO" << std::endl;
96  exit(EXIT_FAILURE);
97  }
98  }
99 #endif
100  m_env.cpuWrite(addr, data);
101  }
102 
103 public:
104  c64cpu (c64env &env) :
105  MOS6510(env.scheduler()),
106  m_env(env) {}
107 };
108 
109 }
110 
111 #endif // C64CPU_H
Definition: mos6510.h:62
Definition: c64cpu.h:69
void cpuWrite(uint_least16_t addr, uint8_t data) override
Definition: c64cpu.h:76
uint8_t cpuRead(uint_least16_t addr) override
Definition: c64cpu.h:74
Definition: c64env.h:41