1//============================================================================
2//
3// SSSS tt lll lll
4// SS SS tt ll ll
5// SS tttttt eeee ll ll aaaa
6// SSSS tt ee ee ll ll aa
7// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8// SS SS tt ee ll ll aa aa
9// SSSS ttt eeeee llll llll aaaaa
10//
11// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony
12// and the Stella Team
13//
14// See the file "License.txt" for information on usage and redistribution of
15// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16//============================================================================
17
18#ifndef KIDVID_HXX
19#define KIDVID_HXX
20
21#include <cstdio>
22
23class Event;
24
25#include "bspf.hxx"
26#include "Control.hxx"
27
28/**
29 The KidVid Voice Module, created by Coleco. This class emulates the
30 KVVM cassette player by mixing WAV data into the sound stream. The
31 WAV files are located at:
32
33 http://www.atariage.com/2600/archives/KidVidAudio/index.html
34
35 This code was heavily borrowed from z26.
36
37 @author Stephen Anthony & z26 team
38*/
39class KidVid : public Controller
40{
41 public:
42 /**
43 Create a new KidVid controller plugged into the specified jack
44
45 @param jack The jack the controller is plugged into
46 @param event The event object to use for events
47 @param system The system using this controller
48 @param romMd5 The md5 of the ROM using this controller
49 */
50 KidVid(Jack jack, const Event& event, const System& system,
51 const string& romMd5);
52 virtual ~KidVid();
53
54 public:
55 /**
56 Update the entire digital and analog pin state according to the
57 events currently set.
58 */
59 void update() override;
60
61 /**
62 Returns the name of this controller.
63 */
64 string name() const override { return "KidVid"; }
65
66 private:
67 // Open/close a WAV sample file
68 void openSampleFile();
69 void closeSampleFile();
70
71 // Jump to next song in the sequence
72 void setNextSong();
73
74 // Generate next sample byte
75 // TODO - rework this, perhaps send directly to sound class
76 void getNextSampleByte();
77
78 private:
79 enum {
80 KVSMURFS = 0x44,
81 KVBBEARS = 0x48,
82 KVBLOCKS = 6, /* number of bytes / block */
83 KVBLOCKBITS = KVBLOCKS*8 /* number of bits / block */
84 };
85
86 // Whether the KidVid device is enabled (only for games that it
87 // supports, and if it's plugged into the right port
88 bool myEnabled;
89
90 // The file handles for the WAV files
91 // FILE *mySampleFile, *mySharedSampleFile;
92
93 // Indicates if sample files have been successfully opened
94 bool myFileOpened;
95
96 // Is the tape currently 'busy' / in use?
97 bool myTapeBusy;
98
99 uInt32 myFilePointer, mySongCounter;
100 bool myBeep, mySharedData;
101 uInt8 mySampleByte;
102 uInt32 myGame, myTape;
103 uInt32 myIdx, myBlock, myBlockIdx;
104
105 // Number of blocks and data on tape
106 static const uInt8 ourKVBlocks[6];
107 static const uInt8 ourKVData[6*8];
108
109 static const uInt8 ourSongPositions[44+38+42+62+80+62];
110 static const uInt32 ourSongStart[104];
111
112 private:
113 // Following constructors and assignment operators not supported
114 KidVid() = delete;
115 KidVid(const KidVid&) = delete;
116 KidVid(KidVid&&) = delete;
117 KidVid& operator=(const KidVid&) = delete;
118 KidVid& operator=(KidVid&&) = delete;
119};
120
121#endif
122