1 /* scld.h: Routines for handling the Timex SCLD
2    Copyright (c) 2002-2004 Fredrick Meunier, Witold Filipczyk
3 
4    $Id: scld.h 4724 2012-07-08 13:38:21Z fredm $
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 along
17    with this program; if not, write to the Free Software Foundation, Inc.,
18    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 
20    Author contact information:
21 
22    E-mail: fredm@spamcop.net
23 
24 */
25 
26 #ifndef FUSE_SCLD_H
27 #define FUSE_SCLD_H
28 
29 #ifndef FUSE_MEMORY_H
30 #include "../memory.h"
31 #endif				/* #ifndef FUSE_MEMORY_H */
32 
33 #define STANDARD        0x00 /* standard Spectrum */
34 #define ALTDFILE        0x01 /* the same in nature as above, but using second
35                                 display file */
36 #define EXTCOLOUR       0x02 /* extended colours (data taken from first screen,
37                                 attributes 1x8 taken from second display. */
38 #define EXTCOLALTD      0x03 /* similar to above, but data is taken from second
39                                 screen */
40 #define HIRESATTR       0x04 /* hires mode, data in odd columns is taken from
41                                 first screen in standard way, data in even
42                                 columns is made from attributes data (8x8) */
43 #define HIRESATTRALTD   0x05 /* similar to above, but data taken from second
44                                 display */
45 #define HIRES           0x06 /* true hires mode, odd columns from first screen,
46                                 even columns from second screen.  columns
47                                 numbered from 1. */
48 #define HIRESDOUBLECOL  0x07 /* data taken only from second screen, columns are
49                                 doubled */
50 #define HIRESCOLMASK    0x38
51 
52 #define WHITEBLACK      0x00
53 #define YELLOWBLUE      0x01
54 #define CYANRED         0x02
55 #define GREENMAGENTA    0x03
56 #define MAGENTAGREEN    0x04
57 #define REDCYAN         0x05
58 #define BLUEYELLOW      0x06
59 #define BLACKWHITE      0x07
60 
61 #define ALTDFILE_OFFSET 0x2000
62 
63 #ifdef WORDS_BIGENDIAN
64 
65 typedef struct
66 {
67   unsigned altmembank : 1;  /* ALTMEMBANK : 0 = cartridge, 1 = exrom */
68   unsigned intdisable : 1;  /* INTDISABLE */
69   unsigned b5  : 1;  /* */
70   unsigned b4  : 1;  /* */
71   unsigned b3  : 1;  /* */
72   unsigned hires  : 1;  /* SCLD HIRES mode */
73   unsigned b1     : 1;  /* */
74   unsigned altdfile : 1;  /* SCLD use ALTDFILE */
75 } scld_names;
76 
77 typedef struct
78 {
79   unsigned b7  : 1;  /* */
80   unsigned b6  : 1;  /* */
81   unsigned hirescol  : 3;  /* HIRESCOLMASK */
82   unsigned scrnmode  : 3;  /* SCRNMODEMASK */
83 } scld_masks;
84 
85 #else				/* #ifdef WORDS_BIGENDIAN */
86 
87 typedef struct
88 {
89   unsigned altdfile : 1;  /* SCLD use ALTDFILE */
90   unsigned b1     : 1;  /* */
91   unsigned hires  : 1;  /* SCLD HIRES mode */
92   unsigned b3  : 1;  /* */
93   unsigned b4  : 1;  /* */
94   unsigned b5  : 1;  /* */
95   unsigned intdisable : 1;  /* INTDISABLE */
96   unsigned altmembank : 1;  /* ALTMEMBANK : 0 = cartridge, 1 = exrom */
97 } scld_names;
98 
99 typedef struct
100 {
101   unsigned scrnmode  : 3;  /* SCRNMODEMASK */
102   unsigned hirescol  : 3;  /* HIRESCOLMASK */
103   unsigned b6  : 1;  /* */
104   unsigned b7  : 1;  /* */
105 } scld_masks;
106 
107 #endif				/* #ifdef WORDS_BIGENDIAN */
108 
109 typedef union
110 {
111   libspectrum_byte byte;
112   scld_masks mask;
113   scld_names name;
114 } scld;
115 
116 extern scld scld_last_dec;           /* The last byte sent to Timex DEC port */
117 
118 extern libspectrum_byte scld_last_hsr; /* Last byte sent to Timex HSR port */
119 
120 /* Home map has pointers to the related entries in the RAM array so that the
121    dck loading code can locate the associated pages when extracting data from
122    its files */
123 extern memory_page * timex_home[MEMORY_PAGES_IN_64K];
124 extern memory_page timex_exrom[MEMORY_PAGES_IN_64K];
125 extern memory_page timex_dock[MEMORY_PAGES_IN_64K];
126 
127 void scld_init( void );
128 
129 void scld_dec_write( libspectrum_word port, libspectrum_byte b );
130 void scld_hsr_write( libspectrum_word port, libspectrum_byte b );
131 
132 void scld_memory_map( void );
133 /* Initialise the memory map to point to the home bank */
134 void scld_memory_map_home( void );
135 
136 libspectrum_byte hires_get_attr( void );
137 libspectrum_byte hires_convert_dec( libspectrum_byte attr );
138 
139 void scld_home_map_16k( libspectrum_word address, memory_page source[],
140                         int page_num );
141 
142 #endif                  /* #ifndef FUSE_SCLD_H */
143