1 /*
2  *  KCemu -- The emulator for the KC85 homecomputer series and much more.
3  *  Copyright (C) 1997-2010 Torsten Paul
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License along
16  *  with this program; if not, write to the Free Software Foundation, Inc.,
17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #include <cairo/cairo.h>
21 #include <cairo/cairo-pdf.h>
22 
23 #include "kc/system.h"
24 
25 #include "kc/kc.h"
26 #include "kc/z80.h"
27 #include "kc/pio1.h"
28 #include "kc/plotter.h"
29 #include "kc/mod_4131.h"
30 
31 #include "libdbg/dbg.h"
32 
33 using namespace std;
34 
ModuleXY4131(ModuleXY4131 & tmpl)35 ModuleXY4131::ModuleXY4131(ModuleXY4131 &tmpl) :
36   ModuleInterface(tmpl.get_name(), tmpl.get_id(), tmpl.get_type())
37 {
38   _master = false;
39   pio->register_callback_B_in(this);
40   pio->register_callback_B_out(this);
41 
42   pio->set_B_EXT(0xff, 0x00);
43 
44   _val = 0;
45   set_valid(true);
46 }
47 
ModuleXY4131(const char * name)48 ModuleXY4131::ModuleXY4131(const char *name) :
49   ModuleInterface(name, 0, KC_MODULE_KC_85_1)
50 {
51   _master = true;
52   set_valid(true);
53 }
54 
~ModuleXY4131(void)55 ModuleXY4131::~ModuleXY4131(void)
56 {
57   if (!_master)
58     plotter->close_pdf();
59 }
60 
61 void
m_out(word_t addr,byte_t val)62 ModuleXY4131::m_out(word_t addr, byte_t val)
63 {
64 }
65 
66 int
callback_A_in(void)67 ModuleXY4131::callback_A_in(void)
68 {
69   return -1;
70 }
71 
72 void
callback_A_out(byte_t val)73 ModuleXY4131::callback_A_out(byte_t val)
74 {
75 }
76 
77 int
callback_B_in(void)78 ModuleXY4131::callback_B_in(void)
79 {
80   return -1;
81 }
82 
83 /**
84  *    0,  0 - 100,  0           83/87/83/87/... => X V
85  *  100,  0 - 100,100           81/85/81/85/... => Y V
86  *  100,100 -   0,100           82/86/82/86/... => X R
87  *    0,100 -   0,  0           80/84/80/84/... => Y R
88  */
89 void
callback_B_out(byte_t val)90 ModuleXY4131::callback_B_out(byte_t val)
91 {
92   if ((_val & 0x80) ^ (val & 0x80))
93     {
94       if (val & 0x80)
95         plotter->pen_down();
96       else
97         plotter->pen_up();
98     }
99 
100   if (((_val & 4) == 0) && ((val & 4) == 4))
101     {
102       int direction = -1;
103       if (val & 0x01)
104         direction = 1;
105 
106       if (val & 0x02)
107         plotter->step(0, direction);
108       else
109         plotter->step(direction, 0);
110     }
111 
112   _val = val;
113 }
114 
115 ModuleInterface *
clone(void)116 ModuleXY4131::clone(void)
117 {
118   return new ModuleXY4131(*this);
119 }
120 
121 void
reset(bool power_on)122 ModuleXY4131::reset(bool power_on)
123 {
124 }
125