libsidplayfp  1.0.3
mos656x.h
00001 /*
00002  * This file is part of libsidplayfp, a SID player engine.
00003  *
00004  * Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net>
00005  * Copyright 2007-2010 Antti Lankila
00006  * Copyright 2001 Simon White
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021  */
00022 
00023 #ifndef MOS656X_H
00024 #define MOS656X_H
00025 
00026 #include "sidplayfp/component.h"
00027 #include "sidplayfp/EventScheduler.h"
00028 
00029 
00030 class MOS656X: public component, private Event
00031 {
00032 public:
00033     typedef enum
00034     {
00035         MOS6567R56A = 0  /* OLD NTSC CHIP */
00036         ,MOS6567R8       /* NTSC-M */
00037         ,MOS6569         /* PAL-B */
00038         ,MOS6572         /* PAL-N */
00039     } model_t;
00040 
00041 private:
00042     static const char *credit;
00043 
00044 private:
00046     static const int IRQ_RASTER = 1 << 0;
00047 
00049     static const int IRQ_LIGHTPEN = 1 << 3;
00050 
00051 protected:
00053     static const int FIRST_DMA_LINE = 0x30;
00054 
00056     static const int LAST_DMA_LINE = 0xf7;
00057 
00058 protected:
00059     event_clock_t m_rasterClk;
00060 
00062     EventContext &event_context;
00063 
00065     uint_least16_t cyclesPerLine;
00066 
00067     uint_least16_t maxRasters;
00068 
00069     uint_least16_t raster_irq;
00070 
00072     uint_least16_t lineCycle;
00073 
00075     uint_least16_t rasterY;
00076 
00078     uint_least16_t yscroll;
00079 
00081     bool areBadLinesEnabled;
00082 
00084     bool isBadLine;
00085 
00087     bool vblanking;
00088 
00090     bool lp_triggered;
00091 
00093     uint8_t irqFlags;
00094 
00096     uint8_t irqMask;
00097 
00099     uint8_t lpx, lpy;
00100 
00103     uint8_t &sprite_enable, &sprite_y_expansion;
00104     uint8_t sprite_dma, sprite_expand_y;
00105     uint8_t sprite_mc_base[8];
00107 
00109     uint8_t regs[0x40];
00110 
00111 private:
00112     event_clock_t clock();
00113 
00115     void handleIrqState();
00116 
00117 protected:
00118     MOS656X(EventContext *context);
00119     ~MOS656X() {}
00120 
00121     void event();
00122 
00123     EventCallback<MOS656X> badLineStateChangeEvent;
00124 
00126     void badLineStateChange() { setBA(false); }
00127 
00132     void activateIRQFlag(int flag)
00133     {
00134         irqFlags |= flag;
00135         handleIrqState();
00136     }
00137 
00143     bool readDEN() const { return (regs[0x11] & 0x10) != 0; }
00144 
00145     bool evaluateIsBadLine() const
00146     {
00147         return areBadLinesEnabled
00148             && rasterY >= FIRST_DMA_LINE
00149             && rasterY <= LAST_DMA_LINE
00150             && (rasterY & 7) == yscroll;
00151     }
00152 
00153     // Environment Interface
00154     virtual void interrupt (bool state) = 0;
00155     virtual void setBA     (bool state) = 0;
00156 
00163     uint8_t read(uint_least8_t addr);
00164 
00173     void write(uint_least8_t addr, uint8_t data);
00174 
00175 public:
00176     void chip(model_t model);
00177     void lightpen();
00178 
00179     // Component Standard Calls
00180     void reset();
00181 
00182     const char *credits() const { return credit; }
00183 
00184     uint_least16_t getCyclesPerLine() const { return cyclesPerLine; }
00185 
00186     uint_least16_t getRasterLines() const { return maxRasters; }
00187 };
00188 
00189 #endif // MOS656X_H