Previous 15994 Revisions Next

r9431 Thursday 21st October, 2010 at 19:18:49 UTC by Justin Kerk
Fix svn:eol-style
[hash]apfm1000.xml casloopy.xml mz2500.xml
[src/mess/drivers]casloopy.c
[src/mess/layout]fidelz80.lay sc2.lay
[src/mess/tools/imgtool/modules]psion.c
[src/mess/video]hd44780.c hd44780.h

hash/mz2500.xml
r9430r9431
1<?xml version="1.0"?>
2<!DOCTYPE softwarelist SYSTEM "softwarelist.dtd">
3 
4<softwarelist name="mz2500" description="MZ-2500 disk images">
5 
6   <software name="okamishi">
7      <description>Aoki Ookami to Shiroki Mejika - Simulation War Game</description>
8      <year>1985</year>
9      <publisher>Koei</publisher>
10 
11      <part name="disk1" interface="mz2500_flop">
12         <dataarea name="flop" size="697008">
13            <rom name="disk a.d88" size="697008" crc="9cf82887" sha1="ba201051640682588124335d5c08a9a38c408061" offset="0" />
14         </dataarea>
15      </part>
16       
17      <part name="disk2" interface="mz2500_flop">
18         <dataarea name="flop" size="697008">
19            <rom name="disk b.d88" size="697008" crc="897257a1" sha1="916332d226a7e2fe60613b46d003c5de196bb8e4" offset="0" />
20         </dataarea>
21      </part>
22   </software>
23 
24   <software name="backfut">
25      <description>Back to the Future</description>
26      <year>1986</year>
27      <publisher>Pony / Data West</publisher>
28 
29      <part name="disk1" interface="mz2500_flop">
30         <dataarea name="flop" size="696736">
31            <rom name="back to the future.d88" size="696736" crc="f8f31c2c" sha1="544ca759503bbcea62b1574780ea40e90b234a11" offset="0" />
32         </dataarea>
33      </part>
34   </software>
35 
36   <software name="basicv1">
37      <description>BASIC-M25 V1(6Z002)</description>
38      <year>1985</year>
39      <publisher>Sharp</publisher>
40 
41      <part name="disk1" interface="mz2500_flop">
42         <dataarea name="flop" size="697008">
43            <rom name="basic-m25 v1(6z002).d88" size="697008" crc="f0f84164" sha1="6f4f57195299b4ba329fd4bb9eb733c8f791adf0" offset="0" />
44         </dataarea>
45      </part>
46   </software>
47 
48   <software name="basicv2">
49      <description>BASIC-M25 V2(6Z002)</description>
50      <year>1985</year>
51      <publisher>Sharp</publisher>
52 
53      <part name="disk1" interface="mz2500_flop">
54         <dataarea name="flop" size="697008">
55            <rom name="basic-m25 v2(6z002).d88" size="697008" crc="2e585759" sha1="c8ea6bb291be68d7b0186cd2117c7fe01dd21f55" offset="0" />
56         </dataarea>
57      </part>
58   </software>
59 
60   <software name="excitebk">
61      <description>Excite Bike</description>
62      <year>1985</year>
63      <publisher>Nintendo / Hudson Soft</publisher>
64 
65      <part name="disk1" interface="mz2500_flop">
66         <dataarea name="flop" size="98624">
67            <rom name="excite bike.d88" size="98624" crc="657367ed" sha1="1c15ffa591c0de997694da691a5f3acb301463c0" offset="0" />
68         </dataarea>
69      </part>
70   </software>
71 
72 
73</softwarelist>
1<?xml version="1.0"?>
2<!DOCTYPE softwarelist SYSTEM "softwarelist.dtd">
3
4<softwarelist name="mz2500" description="MZ-2500 disk images">
5
6   <software name="okamishi">
7      <description>Aoki Ookami to Shiroki Mejika - Simulation War Game</description>
8      <year>1985</year>
9      <publisher>Koei</publisher>
10
11      <part name="disk1" interface="mz2500_flop">
12         <dataarea name="flop" size="697008">
13            <rom name="disk a.d88" size="697008" crc="9cf82887" sha1="ba201051640682588124335d5c08a9a38c408061" offset="0" />
14         </dataarea>
15      </part>
16     
17      <part name="disk2" interface="mz2500_flop">
18         <dataarea name="flop" size="697008">
19            <rom name="disk b.d88" size="697008" crc="897257a1" sha1="916332d226a7e2fe60613b46d003c5de196bb8e4" offset="0" />
20         </dataarea>
21      </part>
22   </software>
23
24   <software name="backfut">
25      <description>Back to the Future</description>
26      <year>1986</year>
27      <publisher>Pony / Data West</publisher>
28
29      <part name="disk1" interface="mz2500_flop">
30         <dataarea name="flop" size="696736">
31            <rom name="back to the future.d88" size="696736" crc="f8f31c2c" sha1="544ca759503bbcea62b1574780ea40e90b234a11" offset="0" />
32         </dataarea>
33      </part>
34   </software>
35
36   <software name="basicv1">
37      <description>BASIC-M25 V1(6Z002)</description>
38      <year>1985</year>
39      <publisher>Sharp</publisher>
40
41      <part name="disk1" interface="mz2500_flop">
42         <dataarea name="flop" size="697008">
43            <rom name="basic-m25 v1(6z002).d88" size="697008" crc="f0f84164" sha1="6f4f57195299b4ba329fd4bb9eb733c8f791adf0" offset="0" />
44         </dataarea>
45      </part>
46   </software>
47
48   <software name="basicv2">
49      <description>BASIC-M25 V2(6Z002)</description>
50      <year>1985</year>
51      <publisher>Sharp</publisher>
52
53      <part name="disk1" interface="mz2500_flop">
54         <dataarea name="flop" size="697008">
55            <rom name="basic-m25 v2(6z002).d88" size="697008" crc="2e585759" sha1="c8ea6bb291be68d7b0186cd2117c7fe01dd21f55" offset="0" />
56         </dataarea>
57      </part>
58   </software>
59
60   <software name="excitebk">
61      <description>Excite Bike</description>
62      <year>1985</year>
63      <publisher>Nintendo / Hudson Soft</publisher>
64
65      <part name="disk1" interface="mz2500_flop">
66         <dataarea name="flop" size="98624">
67            <rom name="excite bike.d88" size="98624" crc="657367ed" sha1="1c15ffa591c0de997694da691a5f3acb301463c0" offset="0" />
68         </dataarea>
69      </part>
70   </software>
71
72
73</softwarelist>
hash/casloopy.xml
r9430r9431
1<?xml version="1.0"?>
2<!DOCTYPE softwarelist SYSTEM "softwarelist.dtd">
3<softwarelist name="casloopy" description="Casio Loopy cartridges">
4   <software name="animelnd">
5      <description>Anime Land</description>
6      <year>1994</year>
7      <publisher>Casio</publisher>
8      <!-- <serial>XK-401</serial> -->
9      <part name="cart" interface="casloopy_cart">
10         <dataarea name="rom" size="2097152">
11            <rom name="animelnd.bin" size="2097152" crc="665cd0a2" sha1="8d50867aba721185560fc92bed75c92263a1da39" offset="0" />
12         </dataarea>
13      </part>
14   </software>
15 
16   <software name="harihari">
17      <description>Hari Hari Seal Paradise</description>
18      <year>1995</year>
19      <publisher>Casio</publisher>
20      <!-- <serial>XK-402</serial> -->
21      <part name="cart" interface="casloopy_cart">
22         <dataarea name="rom" size="2097152">
23            <rom name="harihari.bin" size="2097152" crc="39a417d6" sha1="1adbd97181b61a1a65e21976b0146e9dd80fbdbf" offset="0" />
24         </dataarea>
25      </part>
26   </software>
27 
28   <software name="dreamchg">
29      <description>Dream Change</description>
30      <year>1995</year>
31      <publisher>Casio</publisher>
32      <!-- <serial>XK-403</serial> -->
33      <part name="cart" interface="casloopy_cart">
34         <dataarea name="rom" size="2097152">
35            <rom name="dreamchg.bin" size="2097152" crc="0b850185" sha1="b5d73661ea83167d2b07516c7c66a8a85b28415b" offset="0" />
36         </dataarea>
37      </part>
38   </software>
39 
40   <software name="nigaoart">
41      <description>Nigaoe Artist</description>
42      <year>1995</year>
43      <publisher>Casio</publisher>
44      <!-- <serial>XK-404</serial> -->
45      <part name="cart" interface="casloopy_cart">
46         <dataarea name="rom" size="2097152">
47            <rom name="nigaoart.bin" size="2097152" crc="63d59881" sha1="d2b830acf8440e4726e851514d609700375b27db" offset="0" />
48         </dataarea>
49      </part>
50   </software>
51 
52   <software name="wanwanam">
53      <description>Wanwan Aijou Monogatari</description>
54      <year>1995</year>
55      <publisher>Casio</publisher>
56      <!-- <serial>XK-501</serial> -->
57      <part name="cart" interface="casloopy_cart">
58         <dataarea name="rom" size="2097152">
59            <rom name="wanwanam.bin" size="2097152" crc="291ab2bc" sha1="77a63cf194c5b06633e25b43916629b6f3428870" offset="0" />
60         </dataarea>
61      </part>
62   </software>
63 
64   <software name="pccllect">
65      <description>PC Collection</description>
66      <year>1995</year>
67      <publisher>Casio</publisher>
68      <!-- <serial>XK-502</serial> -->
69      <part name="cart" interface="casloopy_cart">
70         <dataarea name="rom" size="2097152">
71            <rom name="pccllect.bin" size="2097152" crc="9cd4d282" sha1="15ac5a8e71fc8371505da8368d04c9634655d1d5" offset="0" />
72         </dataarea>
73      </part>
74   </software>
75</softwarelist>
1<?xml version="1.0"?>
2<!DOCTYPE softwarelist SYSTEM "softwarelist.dtd">
3<softwarelist name="casloopy" description="Casio Loopy cartridges">
4   <software name="animelnd">
5      <description>Anime Land</description>
6      <year>1994</year>
7      <publisher>Casio</publisher>
8      <!-- <serial>XK-401</serial> -->
9      <part name="cart" interface="casloopy_cart">
10         <dataarea name="rom" size="2097152">
11            <rom name="animelnd.bin" size="2097152" crc="665cd0a2" sha1="8d50867aba721185560fc92bed75c92263a1da39" offset="0" />
12         </dataarea>
13      </part>
14   </software>
15
16   <software name="harihari">
17      <description>Hari Hari Seal Paradise</description>
18      <year>1995</year>
19      <publisher>Casio</publisher>
20      <!-- <serial>XK-402</serial> -->
21      <part name="cart" interface="casloopy_cart">
22         <dataarea name="rom" size="2097152">
23            <rom name="harihari.bin" size="2097152" crc="39a417d6" sha1="1adbd97181b61a1a65e21976b0146e9dd80fbdbf" offset="0" />
24         </dataarea>
25      </part>
26   </software>
27
28   <software name="dreamchg">
29      <description>Dream Change</description>
30      <year>1995</year>
31      <publisher>Casio</publisher>
32      <!-- <serial>XK-403</serial> -->
33      <part name="cart" interface="casloopy_cart">
34         <dataarea name="rom" size="2097152">
35            <rom name="dreamchg.bin" size="2097152" crc="0b850185" sha1="b5d73661ea83167d2b07516c7c66a8a85b28415b" offset="0" />
36         </dataarea>
37      </part>
38   </software>
39
40   <software name="nigaoart">
41      <description>Nigaoe Artist</description>
42      <year>1995</year>
43      <publisher>Casio</publisher>
44      <!-- <serial>XK-404</serial> -->
45      <part name="cart" interface="casloopy_cart">
46         <dataarea name="rom" size="2097152">
47            <rom name="nigaoart.bin" size="2097152" crc="63d59881" sha1="d2b830acf8440e4726e851514d609700375b27db" offset="0" />
48         </dataarea>
49      </part>
50   </software>
51
52   <software name="wanwanam">
53      <description>Wanwan Aijou Monogatari</description>
54      <year>1995</year>
55      <publisher>Casio</publisher>
56      <!-- <serial>XK-501</serial> -->
57      <part name="cart" interface="casloopy_cart">
58         <dataarea name="rom" size="2097152">
59            <rom name="wanwanam.bin" size="2097152" crc="291ab2bc" sha1="77a63cf194c5b06633e25b43916629b6f3428870" offset="0" />
60         </dataarea>
61      </part>
62   </software>
63
64   <software name="pccllect">
65      <description>PC Collection</description>
66      <year>1995</year>
67      <publisher>Casio</publisher>
68      <!-- <serial>XK-502</serial> -->
69      <part name="cart" interface="casloopy_cart">
70         <dataarea name="rom" size="2097152">
71            <rom name="pccllect.bin" size="2097152" crc="9cd4d282" sha1="15ac5a8e71fc8371505da8368d04c9634655d1d5" offset="0" />
72         </dataarea>
73      </part>
74   </software>
75</softwarelist>
hash/apfm1000.xml
r9430r9431
1<?xml version="1.0"?>
2<!DOCTYPE softwarelist SYSTEM "softwarelist.dtd">
3<softwarelist name="apfm1000" description="APF M-1000 cartridges">
4   <software name="backgmmn">
5      <description>Backgammon</description>
6      <year>1979</year>
7      <publisher>APF</publisher>
8      <!-- <serial>MG1008</serial> -->
9      <part name="cart" interface="apfm1000_cart">
10         <dataarea name="rom" size="4096">
11            <rom name="backgmmn.bin" size="4096" crc="811c6269" sha1="f820334bb6df9b856f54f1957b60a5e70bdd6d7e" offset="0" />
12         </dataarea>
13      </part>
14   </software>
15 
16   <software name="baseball">
17      <description>Baseball</description>
18      <year>1979</year>
19      <publisher>APF</publisher>
20      <!-- <serial>MG1006</serial> -->
21      <part name="cart" interface="apfm1000_cart">
22         <dataarea name="rom" size="4096">
23            <rom name="baseball.bin" size="4096" crc="1fb354b7" sha1="2c93d8e764b1e1dfdc1bde7888b385cc28064f86" offset="0" />
24         </dataarea>
25      </part>
26   </software>
27 
28   <software name="blackjck">
29      <description>Blackjack</description>
30      <year>1979</year>
31      <publisher>APF</publisher>
32      <!-- <serial>MG1007</serial> -->
33      <part name="cart" interface="apfm1000_cart">
34         <dataarea name="rom" size="4096">
35            <rom name="blackjck.bin" size="4096" crc="38faa709" sha1="1a99f4781ce4604a550f4ec9d8559e3456303464" offset="0" />
36         </dataarea>
37      </part>
38   </software>
39 
40   <software name="bowling">
41      <description>Bowling / Micro Match</description>
42      <year>1979</year>
43      <publisher>APF</publisher>
44      <!-- <serial>MG1004</serial> -->
45      <part name="cart" interface="apfm1000_cart">
46         <dataarea name="rom" size="4096">
47            <rom name="bowling.bin" size="4096" crc="cca5836b" sha1="4ff1c4ffa46c543bbf48a519a4285b5d2c697ae3" offset="0" />
48         </dataarea>
49      </part>
50   </software>
51 
52   <software name="boxing">
53      <description>Boxing</description>
54      <year>1979</year>
55      <publisher>APF</publisher>
56      <!-- <serial>MG1012</serial> -->
57      <part name="cart" interface="apfm1000_cart">
58         <dataarea name="rom" size="4096">
59            <rom name="boxing.bin" size="4096" crc="7121f8b1" sha1="e7ae8571b496444ded77aaaa3c1d5f5ee97c651f" offset="0" />
60         </dataarea>
61      </part>
62   </software>
63 
64   <software name="brickdwn">
65      <description>Brickdown / Shooting Gallery</description>
66      <year>1979</year>
67      <publisher>APF</publisher>
68      <!-- <serial>MG1005</serial> -->
69      <part name="cart" interface="apfm1000_cart">
70         <dataarea name="rom" size="2048">
71            <rom name="brickdwn.bin" size="2048" crc="bc1f5b8b" sha1="3e2f1e93501cd0dd2c9b747c594b784360e5b175" offset="0" />
72         </dataarea>
73      </part>
74   </software>
75 
76   <software name="casino">
77      <description>Casino 1: Slots / Roulette / Keno</description>
78      <year>1979</year>
79      <publisher>APF</publisher>
80      <!-- <serial>MG1009</serial> -->
81      <part name="cart" interface="apfm1000_cart">
82         <dataarea name="rom" size="4096">
83            <rom name="casino.bin" size="4096" crc="21d5f63f" sha1="fa34ebdb799ccd2bff9f63ce4189a4ee690706fa" offset="0" />
84         </dataarea>
85      </part>
86   </software>
87 
88   <software name="catena">
89      <description>Catena</description>
90      <year>1979</year>
91      <publisher>APF</publisher>
92      <!-- <serial>MG1001</serial> -->
93      <part name="cart" interface="apfm1000_cart">
94         <dataarea name="rom" size="2048">
95            <rom name="catena.bin" size="2048" crc="6baad95f" sha1="b63ad3a60b59aad9b4605ff96f77839565144278" offset="0" />
96         </dataarea>
97      </part>
98   </software>
99 
100   <software name="catenaa">
101      <description>Catena (alt)</description>
102      <year>1979</year>
103      <publisher>APF</publisher>
104      <!-- <serial>MG1002</serial> -->
105      <part name="cart" interface="apfm1000_cart">
106         <dataarea name="rom" size="2048">
107            <rom name="catenaa.bin" size="2048" crc="5d03a812" sha1="29db4ca3c8b76c413b84b6d2bfd3499a70eccd3d" offset="0" />
108         </dataarea>
109      </part>
110   </software>
111 
112   <software name="hangman">
113      <description>Hangman / Tic Tac Toe / Doodle</description>
114      <year>1979</year>
115      <publisher>APF</publisher>
116      <!-- <serial>MG1003</serial> -->
117      <part name="cart" interface="apfm1000_cart">
118         <dataarea name="rom" size="4096">
119            <rom name="hangman.bin" size="4096" crc="e58a5d5b" sha1="205d659db0e0ab0292d33b5b4a9c2b46ca9d1dd5" offset="0" />
120         </dataarea>
121      </part>
122   </software>
123 
124   <software name="pinball">
125      <description>Pinball / Dungeon Hunt / Blockout</description>
126      <year>1979</year>
127      <publisher>APF</publisher>
128      <!-- <serial>MG1011</serial> -->
129      <part name="cart" interface="apfm1000_cart">
130         <dataarea name="rom" size="4096">
131            <rom name="pinball.bin" size="4096" crc="3f4b8c83" sha1="1f5bca6e96777ccbe830d1143a3549f51a3e386e" offset="0" />
132         </dataarea>
133      </part>
134   </software>
135 
136   <software name="spacedst">
137      <description>Space Destroyers</description>
138      <year>1979</year>
139      <publisher>APF</publisher>
140      <!-- <serial>MG1013</serial> -->
141<!-- 
142 
143Space Destroyers has a 2K ROM, a 4K ROM, and 1K RAM.  Here's the memory address:
144 
145Memory map of the chips inside Space Destroyers:
146------------ --------- --------- --------- ---------
147 
148$8000 to $87FF 2k ROM (32768 to 34815)
149 
150$8800 to $8FFF 2k ROM (34816 to 36863)
151 
152$9000 to $97FF 2k ROM (36864 to 38911)
153 
154$9800 to $9BFF 1k RAM (38912 to 39935)
155 
156$9C00 to $9FFF 1k empty space (39936 to 40959)
157 
158-->
159      <part name="cart" interface="apfm1000_cart">
160         <dataarea name="rom" size="4096">
161            <rom name="apf1013a.bin" size="4096" crc="f25215a0" sha1="72da492092b883eb31cffb41ea353e919c86d285" offset="0" />
162         </dataarea>
163         <dataarea name="rom" size="2048">
164            <rom name="apf1013b.bin" size="2048" crc="8c3a9faa" sha1="b3cfc23c65558ef7b67c9afa01a306c8123e227f" offset="0" />
165         </dataarea>
166      </part>
167   </software>
168 
169   <software name="ufo">
170      <description>Ufo / Sea Monsters / Break It Down / Rebuild / Shoot</description>
171      <year>1979</year>
172      <publisher>APF</publisher>
173      <!-- <serial>MG1010</serial> -->
174      <part name="cart" interface="apfm1000_cart">
175         <dataarea name="rom" size="4096">
176            <rom name="ufo.bin" size="4096" crc="0504d667" sha1="6e33593f9e7a4551bc31b347741d9ff87ce618ca" offset="0" />
177         </dataarea>
178      </part>
179   </software>
180</softwarelist>
1<?xml version="1.0"?>
2<!DOCTYPE softwarelist SYSTEM "softwarelist.dtd">
3<softwarelist name="apfm1000" description="APF M-1000 cartridges">
4   <software name="backgmmn">
5      <description>Backgammon</description>
6      <year>1979</year>
7      <publisher>APF</publisher>
8      <!-- <serial>MG1008</serial> -->
9      <part name="cart" interface="apfm1000_cart">
10         <dataarea name="rom" size="4096">
11            <rom name="backgmmn.bin" size="4096" crc="811c6269" sha1="f820334bb6df9b856f54f1957b60a5e70bdd6d7e" offset="0" />
12         </dataarea>
13      </part>
14   </software>
15
16   <software name="baseball">
17      <description>Baseball</description>
18      <year>1979</year>
19      <publisher>APF</publisher>
20      <!-- <serial>MG1006</serial> -->
21      <part name="cart" interface="apfm1000_cart">
22         <dataarea name="rom" size="4096">
23            <rom name="baseball.bin" size="4096" crc="1fb354b7" sha1="2c93d8e764b1e1dfdc1bde7888b385cc28064f86" offset="0" />
24         </dataarea>
25      </part>
26   </software>
27
28   <software name="blackjck">
29      <description>Blackjack</description>
30      <year>1979</year>
31      <publisher>APF</publisher>
32      <!-- <serial>MG1007</serial> -->
33      <part name="cart" interface="apfm1000_cart">
34         <dataarea name="rom" size="4096">
35            <rom name="blackjck.bin" size="4096" crc="38faa709" sha1="1a99f4781ce4604a550f4ec9d8559e3456303464" offset="0" />
36         </dataarea>
37      </part>
38   </software>
39
40   <software name="bowling">
41      <description>Bowling / Micro Match</description>
42      <year>1979</year>
43      <publisher>APF</publisher>
44      <!-- <serial>MG1004</serial> -->
45      <part name="cart" interface="apfm1000_cart">
46         <dataarea name="rom" size="4096">
47            <rom name="bowling.bin" size="4096" crc="cca5836b" sha1="4ff1c4ffa46c543bbf48a519a4285b5d2c697ae3" offset="0" />
48         </dataarea>
49      </part>
50   </software>
51
52   <software name="boxing">
53      <description>Boxing</description>
54      <year>1979</year>
55      <publisher>APF</publisher>
56      <!-- <serial>MG1012</serial> -->
57      <part name="cart" interface="apfm1000_cart">
58         <dataarea name="rom" size="4096">
59            <rom name="boxing.bin" size="4096" crc="7121f8b1" sha1="e7ae8571b496444ded77aaaa3c1d5f5ee97c651f" offset="0" />
60         </dataarea>
61      </part>
62   </software>
63
64   <software name="brickdwn">
65      <description>Brickdown / Shooting Gallery</description>
66      <year>1979</year>
67      <publisher>APF</publisher>
68      <!-- <serial>MG1005</serial> -->
69      <part name="cart" interface="apfm1000_cart">
70         <dataarea name="rom" size="2048">
71            <rom name="brickdwn.bin" size="2048" crc="bc1f5b8b" sha1="3e2f1e93501cd0dd2c9b747c594b784360e5b175" offset="0" />
72         </dataarea>
73      </part>
74   </software>
75
76   <software name="casino">
77      <description>Casino 1: Slots / Roulette / Keno</description>
78      <year>1979</year>
79      <publisher>APF</publisher>
80      <!-- <serial>MG1009</serial> -->
81      <part name="cart" interface="apfm1000_cart">
82         <dataarea name="rom" size="4096">
83            <rom name="casino.bin" size="4096" crc="21d5f63f" sha1="fa34ebdb799ccd2bff9f63ce4189a4ee690706fa" offset="0" />
84         </dataarea>
85      </part>
86   </software>
87
88   <software name="catena">
89      <description>Catena</description>
90      <year>1979</year>
91      <publisher>APF</publisher>
92      <!-- <serial>MG1001</serial> -->
93      <part name="cart" interface="apfm1000_cart">
94         <dataarea name="rom" size="2048">
95            <rom name="catena.bin" size="2048" crc="6baad95f" sha1="b63ad3a60b59aad9b4605ff96f77839565144278" offset="0" />
96         </dataarea>
97      </part>
98   </software>
99
100   <software name="catenaa">
101      <description>Catena (alt)</description>
102      <year>1979</year>
103      <publisher>APF</publisher>
104      <!-- <serial>MG1002</serial> -->
105      <part name="cart" interface="apfm1000_cart">
106         <dataarea name="rom" size="2048">
107            <rom name="catenaa.bin" size="2048" crc="5d03a812" sha1="29db4ca3c8b76c413b84b6d2bfd3499a70eccd3d" offset="0" />
108         </dataarea>
109      </part>
110   </software>
111
112   <software name="hangman">
113      <description>Hangman / Tic Tac Toe / Doodle</description>
114      <year>1979</year>
115      <publisher>APF</publisher>
116      <!-- <serial>MG1003</serial> -->
117      <part name="cart" interface="apfm1000_cart">
118         <dataarea name="rom" size="4096">
119            <rom name="hangman.bin" size="4096" crc="e58a5d5b" sha1="205d659db0e0ab0292d33b5b4a9c2b46ca9d1dd5" offset="0" />
120         </dataarea>
121      </part>
122   </software>
123
124   <software name="pinball">
125      <description>Pinball / Dungeon Hunt / Blockout</description>
126      <year>1979</year>
127      <publisher>APF</publisher>
128      <!-- <serial>MG1011</serial> -->
129      <part name="cart" interface="apfm1000_cart">
130         <dataarea name="rom" size="4096">
131            <rom name="pinball.bin" size="4096" crc="3f4b8c83" sha1="1f5bca6e96777ccbe830d1143a3549f51a3e386e" offset="0" />
132         </dataarea>
133      </part>
134   </software>
135
136   <software name="spacedst">
137      <description>Space Destroyers</description>
138      <year>1979</year>
139      <publisher>APF</publisher>
140      <!-- <serial>MG1013</serial> -->
141<!--
142
143Space Destroyers has a 2K ROM, a 4K ROM, and 1K RAM.  Here's the memory address:
144
145Memory map of the chips inside Space Destroyers:
146------------ --------- --------- --------- ---------
147
148$8000 to $87FF 2k ROM (32768 to 34815)
149
150$8800 to $8FFF 2k ROM (34816 to 36863)
151
152$9000 to $97FF 2k ROM (36864 to 38911)
153
154$9800 to $9BFF 1k RAM (38912 to 39935)
155
156$9C00 to $9FFF 1k empty space (39936 to 40959)
157
158-->
159      <part name="cart" interface="apfm1000_cart">
160         <dataarea name="rom" size="4096">
161            <rom name="apf1013a.bin" size="4096" crc="f25215a0" sha1="72da492092b883eb31cffb41ea353e919c86d285" offset="0" />
162         </dataarea>
163         <dataarea name="rom" size="2048">
164            <rom name="apf1013b.bin" size="2048" crc="8c3a9faa" sha1="b3cfc23c65558ef7b67c9afa01a306c8123e227f" offset="0" />
165         </dataarea>
166      </part>
167   </software>
168
169   <software name="ufo">
170      <description>Ufo / Sea Monsters / Break It Down / Rebuild / Shoot</description>
171      <year>1979</year>
172      <publisher>APF</publisher>
173      <!-- <serial>MG1010</serial> -->
174      <part name="cart" interface="apfm1000_cart">
175         <dataarea name="rom" size="4096">
176            <rom name="ufo.bin" size="4096" crc="0504d667" sha1="6e33593f9e7a4551bc31b347741d9ff87ce618ca" offset="0" />
177         </dataarea>
178      </part>
179   </software>
180</softwarelist>
src/mess/tools/imgtool/modules/psion.c
r9430r9431
1/***************************************************************************
2 
3        Psion Organiser II Datapack
4 
5        08/18/2010 Sandro Ronco
6 
7        Known file types:
8         0x00         invalid record
9         0x01 - 0x7e  deleted record
10         0x7f         invalid deleted record
11         0x80         long record
12         0x81         file name
13         0x82         diary
14         0x83         OPL/OB3 procedure
15         0x84         RS232 setup
16         0x85 - 0x8f  reserved
17         0x90         MAIN Record
18         0x91 - 0xfe  data records from files
19         0xff         invalid record
20 
21****************************************************************************/
22 
23#include "imgtool.h"
24 
25#define MAXFILES 256
26 
27struct psion_file
28{
29   char filename[9];
30   UINT8 type;
31   UINT8 id;
32 
33   UINT16 name_rec;
34   UINT16 data_rec;
35};
36 
37struct psion_pack
38{
39   imgtool_stream *stream;
40 
41   UINT16 eop;
42   struct psion_file pack_index[MAXFILES];
43};
44 
45struct psion_iter
46{
47   UINT16 index;
48};
49 
50UINT16 head_checksum(UINT8* data)
51{
52   UINT16 checksum = 0;
53 
54   for (int i=0; i<6; i+=2)
55      checksum += (data[i]<<8 | data[i+1]);
56 
57   return checksum;
58}
59 
60UINT16 get_long_rec_size(imgtool_stream *stream)
61{
62   UINT8 size_h, size_l;
63 
64   stream_read(stream, &size_h, 1);
65   stream_read(stream, &size_l, 1);
66 
67   return (size_h<<8) | size_l;
68}
69 
70UINT32 update_pack_index(psion_pack *pack)
71{
72   UINT8 data, type;
73   UINT16 size;
74   UINT16 index = 0;
75 
76   memset(pack->pack_index, 0, sizeof(psion_file) * MAXFILES);
77 
78   // start at the first record
79   stream_seek(pack->stream, 0x10, SEEK_SET);
80 
81   do
82   {
83      stream_read(pack->stream, &data, 1);
84 
85      if(data == 0xff)
86      {
87         pack->eop = stream_tell(pack->stream) - 1;
88         return TRUE;
89      }
90      else if (data == 0x02)
91      {
92         // long record without name are ignored
93         stream_read(pack->stream, &data, 1);
94         size = get_long_rec_size(pack->stream);
95         stream_seek(pack->stream, size, SEEK_CUR);
96      }
97      else
98      {
99         stream_read(pack->stream, &type, 1);
100 
101         // deleted record are not listed
102         if (type < 0x90 && (type & 0x80))
103         {
104            pack->pack_index[index].type = type;
105            stream_read(pack->stream, &pack->pack_index[index].filename, 8);
106            stream_read(pack->stream, &pack->pack_index[index].id, 1);
107            pack->pack_index[index].name_rec = stream_tell(pack->stream) - 11;
108 
109            //check for data record
110            stream_read(pack->stream, &data, 1);
111            if (data == 0x02)
112               pack->pack_index[index].data_rec = stream_tell(pack->stream) - 1;
113 
114            stream_seek(pack->stream, -1, SEEK_CUR);
115 
116            index++;
117         }
118         else
119            stream_seek(pack->stream, data, SEEK_CUR);
120      }
121 
122   } while (stream_size(pack->stream) > stream_tell(pack->stream));
123 
124   // corrupted image
125   return FALSE;
126}
127 
128int seek_next_record(imgtool_stream *stream, UINT8 id)
129{
130   UINT8 data, rec_id;
131   UINT16 size;
132 
133   do
134   {
135      stream_read(stream, &data, 1);
136 
137      if(data == 0xff)
138         break;
139 
140      if (data == 2)
141      {
142         stream_read(stream, &rec_id, 1);
143         size = get_long_rec_size(stream);
144 
145      }
146      else
147      {
148         stream_read(stream, &rec_id, 1);
149         if (id == rec_id)
150         {
151            stream_seek(stream, -2, SEEK_CUR);
152            return TRUE;
153         }
154         size = data;
155      }
156 
157      // next record
158      stream_seek(stream, size, SEEK_CUR);
159 
160   } while (stream_size(stream) > stream_tell(stream));
161 
162   return FALSE;
163}
164 
165// if there are multiple files with the same name, only the first is found
166int seek_file_name(psion_pack *pack, const char *filename)
167{
168   UINT16 index = 0;
169 
170   while (pack->pack_index[index].name_rec)
171   {
172      if (!strncmp(filename, pack->pack_index[index].filename, strlen(filename)))
173         return index;
174      index++;
175   }
176 
177   // filename not found
178   return -1;
179}
180 
181UINT8 get_free_file_id(psion_pack *pack)
182{
183   for (UINT8 file_id=0x91; file_id<0xff; file_id++)
184   {
185      int index = 0;
186 
187      while (pack->pack_index[index].id != file_id)
188         if (pack->pack_index[index++].name_rec == 0)
189            return file_id;
190   }
191 
192   return 0xff;
193}
194 
195void put_name_record(imgtool_stream *stream, const char* filename, UINT8 record_type, UINT8 record_id)
196{
197   char data[0x10];
198   int i = 0;
199 
200   data[i++] = 0x09;
201   data[i++] = record_type;
202 
203   // filename is 8 char long space filled
204   for (int j=0; j<8; j++)
205      if (j < strlen(filename))
206         data[i++] = filename[j];
207      else
208         data[i++] = 0x20;
209 
210   data[i++] = record_id;
211 
212   stream_write(stream, data, i);
213}
214 
215void update_opk_head(imgtool_stream *stream)
216{
217   UINT16 size = stream_size(stream) - 6;
218 
219   stream_seek(stream, 4, SEEK_SET);
220   stream_putc(stream, (size>>8) & 0xff);
221   stream_putc(stream, size & 0xff);
222}
223 
224char *stream_getline(imgtool_stream *source, UINT16 max_len)
225{
226   UINT16 pos = 0;
227   char data;
228   char *line = (char*)malloc(max_len);
229   memset(line, 0, max_len);
230 
231   while (pos < max_len && stream_size(source) > stream_tell(source))
232   {
233      stream_read(source, &data, 1);
234 
235      switch(data)
236      {
237         case '\r':
238            stream_read(source, &data, 1);
239            if (data != '\n')
240               stream_seek(source, -1, SEEK_CUR);
241         case '\n':
242            return line;
243            break;
244         default:
245            line[pos++] = data;
246            break;
247      }
248   }
249 
250   if (pos)
251      return line;
252 
253   free(line);
254   return NULL;
255}
256 
257UINT16 put_odb(imgtool_stream *instream, imgtool_stream *outstream, UINT8 file_id)
258{
259   char *line;
260   UINT16 out_size = 0;
261 
262   // reset stream
263   stream_seek(instream, 0, SEEK_SET);
264 
265   while ((line = stream_getline(instream, 256)))
266   {
267      UINT16 len = strlen(line);
268 
269      stream_putc(outstream, (UINT8)len);
270      stream_putc(outstream, file_id);
271      stream_write(outstream, line, len);
272 
273      out_size += (len + 1);
274 
275      free(line);
276   }
277 
278   // end of pack
279   stream_fill(outstream, 0xff, 2);
280 
281   return out_size + 4;
282}
283 
284UINT16 put_ob3(imgtool_stream *instream, imgtool_stream *outstream)
285{
286   UINT16 size = stream_size(instream) - 6;
287   UINT8 *buffer = (UINT8*)malloc(size);
288 
289   stream_seek(instream, 6, SEEK_SET);
290   stream_read(instream, buffer, size);
291 
292   stream_write(outstream, buffer, size);
293 
294   free(buffer);
295 
296   // end of pack
297   stream_fill(outstream, 0xff, 2);
298 
299   return size;
300}
301 
302UINT16 put_opl(imgtool_stream *instream, imgtool_stream *outstream)
303{
304   UINT16 out_size = 0;
305   UINT32 rec_start = stream_tell(outstream);
306   char *line;
307 
308   // reset stream
309   stream_seek(instream, 0, SEEK_SET);
310 
311   stream_fill(outstream, 0x00, 4);
312 
313   // replace all eol with 0x00
314   while ((line = stream_getline(instream, 256)))
315   {
316      // replace tab with space
317      for (int i=0; i<strlen(line); i++)
318         if (line[i] == '\t') line[i] = ' ';
319 
320      stream_write(outstream, line, strlen(line));
321      stream_putc(outstream, 0x00);
322      out_size += strlen(line) + 1;
323      free(line);
324   }
325 
326   // end of pack
327   stream_fill(outstream, 0xff, 2);
328 
329   // update the size in the head
330   stream_seek(outstream, rec_start + 2, SEEK_SET);
331   stream_putc(outstream, (out_size>>8) & 0xff);
332   stream_putc(outstream, out_size & 0xff);
333 
334   return out_size + 4;
335}
336 
337UINT16 get_odb(imgtool_stream *instream, imgtool_stream *outstream, UINT8 type, UINT8 file_id)
338{
339   UINT8 data, *buffer;
340   UINT16 out_size = 0;
341 
342   if (file_id >= 0x90)
343      while (seek_next_record(instream, file_id))
344      {
345         stream_read(instream, &data, 1);
346         stream_seek(instream, 1, SEEK_CUR);
347         buffer = (UINT8*)malloc(data);
348         stream_read(instream, buffer, data);
349         stream_write(outstream, buffer, data);
350         stream_putc(outstream, '\r');
351         stream_putc(outstream, '\n');
352         free (buffer);
353         out_size += data;
354      }
355 
356   return out_size;
357}
358 
359UINT16 get_ob3(imgtool_stream *instream, imgtool_stream *outstream, UINT8 type, UINT8 file_id)
360{
361   UINT8 data, *buffer = NULL;
362   UINT16 size = 0;
363   char ob3_magic[3] = {'O', 'R', 'G'};
364 
365   stream_read(instream, &data, 1);
366 
367   if (data == 0x02)
368   {
369      stream_seek(instream, 1, SEEK_CUR);
370      size = get_long_rec_size(instream);
371      buffer = (UINT8*)malloc(size);
372      stream_read(instream, buffer, size);
373   }
374 
375   stream_write(outstream, ob3_magic, 3);
376   stream_putc(outstream, (size>>8) & 0xff);
377   stream_putc(outstream, size & 0xff);
378   stream_putc(outstream, type | 0x80);
379 
380   if (buffer)
381   {
382      stream_write(outstream, buffer, size);
383      free (buffer);
384   }
385 
386   return size;
387}
388 
389static imgtoolerr_t datapack_open( imgtool_image *image, imgtool_stream *stream)
390{
391   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
392   char opk_magic[4];
393 
394   stream_read(stream, opk_magic, 4);
395 
396   if(strcmp(opk_magic, "OPK\0"))
397      return IMGTOOLERR_UNEXPECTED;
398 
399   pack->stream = stream;
400 
401   if (update_pack_index(pack))
402      return IMGTOOLERR_SUCCESS;
403   else
404      return IMGTOOLERR_CORRUPTIMAGE;
405}
406 
407static imgtoolerr_t datapack_create( imgtool_image *image, imgtool_stream *stream, option_resolution *opts)
408{
409   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
410   UINT8 opk_magic[4] = {'O', 'P', 'K', 0x00};
411   UINT8 pack_head[8] = {0x40, 0x00, 0x59, 0x01, 0x01, 0x01, 0x00, 0x00};
412   UINT16 checksum;
413 
414   pack_head[0] |= (option_resolution_lookup_int(opts, 'R')) ? 0x00 : 0x02;
415   pack_head[0] |= (option_resolution_lookup_int(opts, 'P')) ? 0x04 : 0x00;
416   pack_head[0] |= (option_resolution_lookup_int(opts, 'W')) ? 0x00 : 0x08;
417   pack_head[0] |= (option_resolution_lookup_int(opts, 'B')) ? 0x00 : 0x10;
418   pack_head[0] |= (option_resolution_lookup_int(opts, 'C')) ? 0x20 : 0x00;
419   pack_head[1] = option_resolution_lookup_int(opts, 'S');
420 
421   checksum = head_checksum(pack_head);
422 
423   stream_write(stream, opk_magic, 4);
424   stream_fill(stream, 0x00, 2);
425   stream_write(stream, pack_head, 8);
426 
427   stream_putc(stream, (checksum>>8) & 0xff);
428   stream_putc(stream, checksum & 0xff);
429 
430   put_name_record(stream, "MAIN", 0x81, 0x90);
431 
432   stream_fill(stream, 0xff, 2);
433 
434   update_opk_head(stream);
435 
436   pack->stream = stream;
437 
438   if (update_pack_index(pack))
439      return IMGTOOLERR_SUCCESS;
440   else
441      return IMGTOOLERR_CORRUPTIMAGE;
442}
443 
444static void datapack_close( imgtool_image *image)
445{
446   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
447 
448   stream_close( pack->stream );
449}
450 
451static imgtoolerr_t datapack_begin_enum(imgtool_directory *enumeration, const char *path)
452{
453   psion_iter *iter = (psion_iter*)imgtool_directory_extrabytes(enumeration);
454   iter->index = 0;
455 
456   return IMGTOOLERR_SUCCESS;
457}
458 
459static imgtoolerr_t datapack_next_enum(imgtool_directory *enumeration, imgtool_dirent *ent)
460{
461   imgtool_image *image = imgtool_directory_image(enumeration);
462   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
463   psion_iter *iter = (psion_iter*)imgtool_directory_extrabytes(enumeration);
464   UINT8 data = 0;
465 
466   if (!pack->pack_index[iter->index].name_rec)
467   {
468      ent->eof = 1;
469      return IMGTOOLERR_SUCCESS;
470   }
471   memcpy(ent->filename, pack->pack_index[iter->index].filename, 8);
472   sprintf(ent->attr, "Type: %02x ID: %02x", pack->pack_index[iter->index].type, pack->pack_index[iter->index].id);
473 
474   if (pack->pack_index[iter->index].data_rec)
475   {
476      stream_seek(pack->stream, pack->pack_index[iter->index].data_rec + 2, SEEK_SET);
477      ent->filesize = get_long_rec_size(pack->stream);
478   }
479 
480   // seek all file's records
481   if (pack->pack_index[iter->index].id >= 0x90)
482   {
483      stream_seek(pack->stream, 0x10, SEEK_SET);
484      while (seek_next_record(pack->stream, pack->pack_index[iter->index].id))
485      {
486         stream_read(pack->stream, &data, 1);
487         stream_seek(pack->stream, data + 1, SEEK_CUR);
488         ent->filesize +=data;
489      }
490   }
491 
492   iter->index++;
493   return IMGTOOLERR_SUCCESS;
494}
495 
496static void datapack_close_enum( imgtool_directory *enumeration)
497{
498}
499 
500static imgtoolerr_t datapack_free_space( imgtool_partition *partition, UINT64 *size)
501{
502   imgtool_image *image = imgtool_partition_image( partition);
503   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
504   UINT32 pack_size = 0;
505 
506   stream_seek(pack->stream, 0x07, SEEK_SET);
507   stream_read(pack->stream, &pack_size, 1);
508 
509   if (size)
510      *size = (pack_size * 0x2000) - pack->eop;
511 
512   return IMGTOOLERR_SUCCESS;
513}
514 
515static imgtoolerr_t datapack_read_file(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf)
516{
517   imgtool_image *image = imgtool_partition_image(partition);
518   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
519   int index = seek_file_name(pack, filename);
520 
521   if (index >= 0)
522   {
523      if ((pack->pack_index[index].type & 0x7f) == 0x01)
524      {
525         // ODB files
526         stream_seek(pack->stream, 0x10, SEEK_SET);
527         get_odb(pack->stream, destf, pack->pack_index[index].type, pack->pack_index[index].id);
528      }
529      else if ((pack->pack_index[index].type & 0x7f) == 0x03)
530      {
531         // OB3/OPL files
532         stream_seek(pack->stream, pack->pack_index[index].data_rec, SEEK_SET);
533         get_ob3(pack->stream, destf, pack->pack_index[index].type, pack->pack_index[index].id);
534      }
535      else
536      {
537         // Other files
538         return IMGTOOLERR_UNIMPLEMENTED;
539      }
540 
541      return IMGTOOLERR_SUCCESS;
542   }
543   else
544      return IMGTOOLERR_FILENOTFOUND;
545}
546 
547static imgtoolerr_t datapack_write_file( imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, option_resolution *opts)
548{
549   imgtool_image *image = imgtool_partition_image(partition);
550   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
551   UINT8 data_head[4] = {0x02, 0x80, 0x00, 0x00};
552   UINT8 head[3];
553   UINT16 size = 0;
554   UINT8 type = option_resolution_lookup_int(opts, 'T');
555   UINT8 file_id = option_resolution_lookup_int(opts, 'I');
556 
557   if (!pack->eop)
558      return IMGTOOLERR_CORRUPTIMAGE;
559 
560   // if not file_id is specified get the first free (for ODB only)
561   if (file_id == 0 && type == 3)
562   {
563      file_id = get_free_file_id(pack);
564 
565      if (file_id == 0xff)
566         return IMGTOOLERR_NOSPACE;
567   }
568 
569   stream_read(sourcef, head, 3);
570   stream_seek(pack->stream, pack->eop, SEEK_SET);
571 
572   if (type == 0)
573      type = (!strncmp((char*)head, "ORG", 3)) ? 1 : 2;
574 
575   switch (type)
576   {
577      case 1:      //OB3 file
578         put_name_record(pack->stream, filename, 0x83, file_id);
579         stream_write(pack->stream, data_head, 4);
580         size = put_ob3(sourcef, pack->stream);
581         break;
582      case 2:      //OPL file
583         put_name_record(pack->stream, filename, 0x83, file_id);
584         stream_write(pack->stream, data_head, 4);
585         size = put_opl(sourcef, pack->stream);
586         break;
587      case 3:      //ODB file
588         put_name_record(pack->stream, filename, 0x81, file_id);
589         size = put_odb(sourcef, pack->stream, file_id);
590         break;
591   }
592 
593   if (type != 3)
594   {
595      // update the OB3/OPL long record size
596      stream_seek(pack->stream, pack->eop + 13, SEEK_SET);
597      stream_putc(pack->stream, (size>>8) & 0xff);
598      stream_putc(pack->stream, size & 0xff);
599   }
600 
601   update_opk_head(pack->stream);
602 
603   if (update_pack_index(pack))
604      return IMGTOOLERR_SUCCESS;
605   else
606      return IMGTOOLERR_CORRUPTIMAGE;
607}
608 
609static imgtoolerr_t datapack_delete_file( imgtool_partition *partition, const char *filename)
610{
611   imgtool_image *image = imgtool_partition_image(partition);
612   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
613   int index = seek_file_name(pack, filename);
614 
615   if (index >= 0)
616   {
617      // clear the bit 7 of the file type to mark the file as deleted
618      stream_seek(pack->stream, pack->pack_index[index].name_rec + 1, SEEK_SET);
619      stream_putc(pack->stream, pack->pack_index[index].type & 0x7f);
620 
621      if (update_pack_index(pack))
622         return IMGTOOLERR_SUCCESS;
623      else
624         return IMGTOOLERR_CORRUPTIMAGE;
625   }
626   else
627      return IMGTOOLERR_FILENOTFOUND;
628}
629 
630static OPTION_GUIDE_START( psion_create_optguide )
631   OPTION_ENUM_START( 'S', "size", "datapack size" )
632      OPTION_ENUM( 1, "8k", "8 kbyte" )
633      OPTION_ENUM( 2, "16k", "16 kbyts" )
634      OPTION_ENUM( 4, "32k", "32 kbyte" )
635      OPTION_ENUM( 8, "64k", "64 kbyte" )
636      OPTION_ENUM( 16, "128k", "128 kbyte" ) // only paged datapacks can have this size
637   OPTION_ENUM_END
638   OPTION_INT('R', "ram", "EPROM/RAM datapack" )
639   OPTION_INT('P', "paged", "linear/paged datapack" )
640   OPTION_INT('W', "protect", "write-protected datapack" )
641   OPTION_INT('B', "boot", "bootable datapack" )
642   OPTION_INT('C', "copy", "copyable datapack" )
643OPTION_GUIDE_END
644 
645static OPTION_GUIDE_START( psion_write_optguide )
646   OPTION_ENUM_START( 'T', "type", "file type" )
647      OPTION_ENUM( 1, "OB3", "OB3 files" )
648      OPTION_ENUM( 2, "OPL", "OPL files" )
649      OPTION_ENUM( 3, "ODB", "ODB or text files" )
650   OPTION_ENUM_END
651   OPTION_INT( 'I', "id", "File ID" )
652OPTION_GUIDE_END
653 
654void psion_get_info( const imgtool_class *imgclass, UINT32 state, union imgtoolinfo *info)
655{
656   switch (state)
657   {
658      // --- the following bits of info are returned as 64-bit signed integers ---
659      case IMGTOOLINFO_INT_IMAGE_EXTRA_BYTES          : info->i = sizeof(psion_pack); break;
660      case IMGTOOLINFO_INT_DIRECTORY_EXTRA_BYTES      : info->i = sizeof(psion_iter); break;
661 
662      // --- the following bits of info are returned as pointers to data or functions ---
663      case IMGTOOLINFO_PTR_OPEN        : info->open        = datapack_open; break;
664      case IMGTOOLINFO_PTR_CREATE      : info->create      = datapack_create; break;
665      case IMGTOOLINFO_PTR_CLOSE       : info->close       = datapack_close; break;
666      case IMGTOOLINFO_PTR_BEGIN_ENUM  : info->begin_enum  = datapack_begin_enum; break;
667      case IMGTOOLINFO_PTR_NEXT_ENUM   : info->next_enum   = datapack_next_enum; break;
668      case IMGTOOLINFO_PTR_CLOSE_ENUM  : info->close_enum  = datapack_close_enum; break;
669      case IMGTOOLINFO_PTR_FREE_SPACE  : info->free_space  = datapack_free_space; break;
670      case IMGTOOLINFO_PTR_READ_FILE   : info->read_file   = datapack_read_file; break;
671      case IMGTOOLINFO_PTR_WRITE_FILE  : info->write_file  = datapack_write_file; break;
672      case IMGTOOLINFO_PTR_DELETE_FILE : info->delete_file = datapack_delete_file; break;
673      case IMGTOOLINFO_PTR_CREATEIMAGE_OPTGUIDE : info->createimage_optguide = psion_create_optguide; break;
674      case IMGTOOLINFO_PTR_WRITEFILE_OPTGUIDE : info->createimage_optguide = psion_write_optguide; break;
675 
676      // --- the following bits of info are returned as NULL-terminated strings ---
677      case IMGTOOLINFO_STR_NAME            : strcpy( info->s = imgtool_temp_str(), "psionpack"); break;
678      case IMGTOOLINFO_STR_DESCRIPTION     : strcpy( info->s = imgtool_temp_str(), "Psion Organiser II Datapack"); break;
679      case IMGTOOLINFO_STR_FILE            : strcpy( info->s = imgtool_temp_str(), __FILE__); break;
680      case IMGTOOLINFO_STR_FILE_EXTENSIONS : strcpy( info->s = imgtool_temp_str(), "opk"); break;
681      case IMGTOOLINFO_STR_CREATEIMAGE_OPTSPEC : strcpy( info->s = imgtool_temp_str(), "S1/2/[4]/8/16;R[0]/1;P[0]/1;W0/[1];B[0]/1;C0/[1]"); break;
682      case IMGTOOLINFO_STR_WRITEFILE_OPTSPEC : strcpy( info->s = imgtool_temp_str(), "T[1]/2/3;I[0]/145-255"); break;
683   }
684}
1/***************************************************************************
2
3        Psion Organiser II Datapack
4
5        08/18/2010 Sandro Ronco
6
7        Known file types:
8         0x00         invalid record
9         0x01 - 0x7e  deleted record
10         0x7f         invalid deleted record
11         0x80         long record
12         0x81         file name
13         0x82         diary
14         0x83         OPL/OB3 procedure
15         0x84         RS232 setup
16         0x85 - 0x8f  reserved
17         0x90         MAIN Record
18         0x91 - 0xfe  data records from files
19         0xff         invalid record
20
21****************************************************************************/
22
23#include "imgtool.h"
24
25#define MAXFILES 256
26
27struct psion_file
28{
29   char filename[9];
30   UINT8 type;
31   UINT8 id;
32
33   UINT16 name_rec;
34   UINT16 data_rec;
35};
36
37struct psion_pack
38{
39   imgtool_stream *stream;
40
41   UINT16 eop;
42   struct psion_file pack_index[MAXFILES];
43};
44
45struct psion_iter
46{
47   UINT16 index;
48};
49
50UINT16 head_checksum(UINT8* data)
51{
52   UINT16 checksum = 0;
53
54   for (int i=0; i<6; i+=2)
55      checksum += (data[i]<<8 | data[i+1]);
56
57   return checksum;
58}
59
60UINT16 get_long_rec_size(imgtool_stream *stream)
61{
62   UINT8 size_h, size_l;
63
64   stream_read(stream, &size_h, 1);
65   stream_read(stream, &size_l, 1);
66
67   return (size_h<<8) | size_l;
68}
69
70UINT32 update_pack_index(psion_pack *pack)
71{
72   UINT8 data, type;
73   UINT16 size;
74   UINT16 index = 0;
75
76   memset(pack->pack_index, 0, sizeof(psion_file) * MAXFILES);
77
78   // start at the first record
79   stream_seek(pack->stream, 0x10, SEEK_SET);
80
81   do
82   {
83      stream_read(pack->stream, &data, 1);
84
85      if(data == 0xff)
86      {
87         pack->eop = stream_tell(pack->stream) - 1;
88         return TRUE;
89      }
90      else if (data == 0x02)
91      {
92         // long record without name are ignored
93         stream_read(pack->stream, &data, 1);
94         size = get_long_rec_size(pack->stream);
95         stream_seek(pack->stream, size, SEEK_CUR);
96      }
97      else
98      {
99         stream_read(pack->stream, &type, 1);
100
101         // deleted record are not listed
102         if (type < 0x90 && (type & 0x80))
103         {
104            pack->pack_index[index].type = type;
105            stream_read(pack->stream, &pack->pack_index[index].filename, 8);
106            stream_read(pack->stream, &pack->pack_index[index].id, 1);
107            pack->pack_index[index].name_rec = stream_tell(pack->stream) - 11;
108
109            //check for data record
110            stream_read(pack->stream, &data, 1);
111            if (data == 0x02)
112               pack->pack_index[index].data_rec = stream_tell(pack->stream) - 1;
113
114            stream_seek(pack->stream, -1, SEEK_CUR);
115
116            index++;
117         }
118         else
119            stream_seek(pack->stream, data, SEEK_CUR);
120      }
121
122   } while (stream_size(pack->stream) > stream_tell(pack->stream));
123
124   // corrupted image
125   return FALSE;
126}
127
128int seek_next_record(imgtool_stream *stream, UINT8 id)
129{
130   UINT8 data, rec_id;
131   UINT16 size;
132
133   do
134   {
135      stream_read(stream, &data, 1);
136
137      if(data == 0xff)
138         break;
139
140      if (data == 2)
141      {
142         stream_read(stream, &rec_id, 1);
143         size = get_long_rec_size(stream);
144
145      }
146      else
147      {
148         stream_read(stream, &rec_id, 1);
149         if (id == rec_id)
150         {
151            stream_seek(stream, -2, SEEK_CUR);
152            return TRUE;
153         }
154         size = data;
155      }
156
157      // next record
158      stream_seek(stream, size, SEEK_CUR);
159
160   } while (stream_size(stream) > stream_tell(stream));
161
162   return FALSE;
163}
164
165// if there are multiple files with the same name, only the first is found
166int seek_file_name(psion_pack *pack, const char *filename)
167{
168   UINT16 index = 0;
169
170   while (pack->pack_index[index].name_rec)
171   {
172      if (!strncmp(filename, pack->pack_index[index].filename, strlen(filename)))
173         return index;
174      index++;
175   }
176
177   // filename not found
178   return -1;
179}
180
181UINT8 get_free_file_id(psion_pack *pack)
182{
183   for (UINT8 file_id=0x91; file_id<0xff; file_id++)
184   {
185      int index = 0;
186
187      while (pack->pack_index[index].id != file_id)
188         if (pack->pack_index[index++].name_rec == 0)
189            return file_id;
190   }
191
192   return 0xff;
193}
194
195void put_name_record(imgtool_stream *stream, const char* filename, UINT8 record_type, UINT8 record_id)
196{
197   char data[0x10];
198   int i = 0;
199
200   data[i++] = 0x09;
201   data[i++] = record_type;
202
203   // filename is 8 char long space filled
204   for (int j=0; j<8; j++)
205      if (j < strlen(filename))
206         data[i++] = filename[j];
207      else
208         data[i++] = 0x20;
209
210   data[i++] = record_id;
211
212   stream_write(stream, data, i);
213}
214
215void update_opk_head(imgtool_stream *stream)
216{
217   UINT16 size = stream_size(stream) - 6;
218
219   stream_seek(stream, 4, SEEK_SET);
220   stream_putc(stream, (size>>8) & 0xff);
221   stream_putc(stream, size & 0xff);
222}
223
224char *stream_getline(imgtool_stream *source, UINT16 max_len)
225{
226   UINT16 pos = 0;
227   char data;
228   char *line = (char*)malloc(max_len);
229   memset(line, 0, max_len);
230
231   while (pos < max_len && stream_size(source) > stream_tell(source))
232   {
233      stream_read(source, &data, 1);
234
235      switch(data)
236      {
237         case '\r':
238            stream_read(source, &data, 1);
239            if (data != '\n')
240               stream_seek(source, -1, SEEK_CUR);
241         case '\n':
242            return line;
243            break;
244         default:
245            line[pos++] = data;
246            break;
247      }
248   }
249
250   if (pos)
251      return line;
252
253   free(line);
254   return NULL;
255}
256
257UINT16 put_odb(imgtool_stream *instream, imgtool_stream *outstream, UINT8 file_id)
258{
259   char *line;
260   UINT16 out_size = 0;
261
262   // reset stream
263   stream_seek(instream, 0, SEEK_SET);
264
265   while ((line = stream_getline(instream, 256)))
266   {
267      UINT16 len = strlen(line);
268
269      stream_putc(outstream, (UINT8)len);
270      stream_putc(outstream, file_id);
271      stream_write(outstream, line, len);
272
273      out_size += (len + 1);
274
275      free(line);
276   }
277
278   // end of pack
279   stream_fill(outstream, 0xff, 2);
280
281   return out_size + 4;
282}
283
284UINT16 put_ob3(imgtool_stream *instream, imgtool_stream *outstream)
285{
286   UINT16 size = stream_size(instream) - 6;
287   UINT8 *buffer = (UINT8*)malloc(size);
288
289   stream_seek(instream, 6, SEEK_SET);
290   stream_read(instream, buffer, size);
291
292   stream_write(outstream, buffer, size);
293
294   free(buffer);
295
296   // end of pack
297   stream_fill(outstream, 0xff, 2);
298
299   return size;
300}
301
302UINT16 put_opl(imgtool_stream *instream, imgtool_stream *outstream)
303{
304   UINT16 out_size = 0;
305   UINT32 rec_start = stream_tell(outstream);
306   char *line;
307
308   // reset stream
309   stream_seek(instream, 0, SEEK_SET);
310
311   stream_fill(outstream, 0x00, 4);
312
313   // replace all eol with 0x00
314   while ((line = stream_getline(instream, 256)))
315   {
316      // replace tab with space
317      for (int i=0; i<strlen(line); i++)
318         if (line[i] == '\t') line[i] = ' ';
319
320      stream_write(outstream, line, strlen(line));
321      stream_putc(outstream, 0x00);
322      out_size += strlen(line) + 1;
323      free(line);
324   }
325
326   // end of pack
327   stream_fill(outstream, 0xff, 2);
328
329   // update the size in the head
330   stream_seek(outstream, rec_start + 2, SEEK_SET);
331   stream_putc(outstream, (out_size>>8) & 0xff);
332   stream_putc(outstream, out_size & 0xff);
333
334   return out_size + 4;
335}
336
337UINT16 get_odb(imgtool_stream *instream, imgtool_stream *outstream, UINT8 type, UINT8 file_id)
338{
339   UINT8 data, *buffer;
340   UINT16 out_size = 0;
341
342   if (file_id >= 0x90)
343      while (seek_next_record(instream, file_id))
344      {
345         stream_read(instream, &data, 1);
346         stream_seek(instream, 1, SEEK_CUR);
347         buffer = (UINT8*)malloc(data);
348         stream_read(instream, buffer, data);
349         stream_write(outstream, buffer, data);
350         stream_putc(outstream, '\r');
351         stream_putc(outstream, '\n');
352         free (buffer);
353         out_size += data;
354      }
355
356   return out_size;
357}
358
359UINT16 get_ob3(imgtool_stream *instream, imgtool_stream *outstream, UINT8 type, UINT8 file_id)
360{
361   UINT8 data, *buffer = NULL;
362   UINT16 size = 0;
363   char ob3_magic[3] = {'O', 'R', 'G'};
364
365   stream_read(instream, &data, 1);
366
367   if (data == 0x02)
368   {
369      stream_seek(instream, 1, SEEK_CUR);
370      size = get_long_rec_size(instream);
371      buffer = (UINT8*)malloc(size);
372      stream_read(instream, buffer, size);
373   }
374
375   stream_write(outstream, ob3_magic, 3);
376   stream_putc(outstream, (size>>8) & 0xff);
377   stream_putc(outstream, size & 0xff);
378   stream_putc(outstream, type | 0x80);
379
380   if (buffer)
381   {
382      stream_write(outstream, buffer, size);
383      free (buffer);
384   }
385
386   return size;
387}
388
389static imgtoolerr_t datapack_open( imgtool_image *image, imgtool_stream *stream)
390{
391   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
392   char opk_magic[4];
393
394   stream_read(stream, opk_magic, 4);
395
396   if(strcmp(opk_magic, "OPK\0"))
397      return IMGTOOLERR_UNEXPECTED;
398
399   pack->stream = stream;
400
401   if (update_pack_index(pack))
402      return IMGTOOLERR_SUCCESS;
403   else
404      return IMGTOOLERR_CORRUPTIMAGE;
405}
406
407static imgtoolerr_t datapack_create( imgtool_image *image, imgtool_stream *stream, option_resolution *opts)
408{
409   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
410   UINT8 opk_magic[4] = {'O', 'P', 'K', 0x00};
411   UINT8 pack_head[8] = {0x40, 0x00, 0x59, 0x01, 0x01, 0x01, 0x00, 0x00};
412   UINT16 checksum;
413
414   pack_head[0] |= (option_resolution_lookup_int(opts, 'R')) ? 0x00 : 0x02;
415   pack_head[0] |= (option_resolution_lookup_int(opts, 'P')) ? 0x04 : 0x00;
416   pack_head[0] |= (option_resolution_lookup_int(opts, 'W')) ? 0x00 : 0x08;
417   pack_head[0] |= (option_resolution_lookup_int(opts, 'B')) ? 0x00 : 0x10;
418   pack_head[0] |= (option_resolution_lookup_int(opts, 'C')) ? 0x20 : 0x00;
419   pack_head[1] = option_resolution_lookup_int(opts, 'S');
420
421   checksum = head_checksum(pack_head);
422
423   stream_write(stream, opk_magic, 4);
424   stream_fill(stream, 0x00, 2);
425   stream_write(stream, pack_head, 8);
426
427   stream_putc(stream, (checksum>>8) & 0xff);
428   stream_putc(stream, checksum & 0xff);
429
430   put_name_record(stream, "MAIN", 0x81, 0x90);
431
432   stream_fill(stream, 0xff, 2);
433
434   update_opk_head(stream);
435
436   pack->stream = stream;
437
438   if (update_pack_index(pack))
439      return IMGTOOLERR_SUCCESS;
440   else
441      return IMGTOOLERR_CORRUPTIMAGE;
442}
443
444static void datapack_close( imgtool_image *image)
445{
446   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
447
448   stream_close( pack->stream );
449}
450
451static imgtoolerr_t datapack_begin_enum(imgtool_directory *enumeration, const char *path)
452{
453   psion_iter *iter = (psion_iter*)imgtool_directory_extrabytes(enumeration);
454   iter->index = 0;
455
456   return IMGTOOLERR_SUCCESS;
457}
458
459static imgtoolerr_t datapack_next_enum(imgtool_directory *enumeration, imgtool_dirent *ent)
460{
461   imgtool_image *image = imgtool_directory_image(enumeration);
462   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
463   psion_iter *iter = (psion_iter*)imgtool_directory_extrabytes(enumeration);
464   UINT8 data = 0;
465
466   if (!pack->pack_index[iter->index].name_rec)
467   {
468      ent->eof = 1;
469      return IMGTOOLERR_SUCCESS;
470   }
471   memcpy(ent->filename, pack->pack_index[iter->index].filename, 8);
472   sprintf(ent->attr, "Type: %02x ID: %02x", pack->pack_index[iter->index].type, pack->pack_index[iter->index].id);
473
474   if (pack->pack_index[iter->index].data_rec)
475   {
476      stream_seek(pack->stream, pack->pack_index[iter->index].data_rec + 2, SEEK_SET);
477      ent->filesize = get_long_rec_size(pack->stream);
478   }
479
480   // seek all file's records
481   if (pack->pack_index[iter->index].id >= 0x90)
482   {
483      stream_seek(pack->stream, 0x10, SEEK_SET);
484      while (seek_next_record(pack->stream, pack->pack_index[iter->index].id))
485      {
486         stream_read(pack->stream, &data, 1);
487         stream_seek(pack->stream, data + 1, SEEK_CUR);
488         ent->filesize +=data;
489      }
490   }
491
492   iter->index++;
493   return IMGTOOLERR_SUCCESS;
494}
495
496static void datapack_close_enum( imgtool_directory *enumeration)
497{
498}
499
500static imgtoolerr_t datapack_free_space( imgtool_partition *partition, UINT64 *size)
501{
502   imgtool_image *image = imgtool_partition_image( partition);
503   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
504   UINT32 pack_size = 0;
505
506   stream_seek(pack->stream, 0x07, SEEK_SET);
507   stream_read(pack->stream, &pack_size, 1);
508
509   if (size)
510      *size = (pack_size * 0x2000) - pack->eop;
511
512   return IMGTOOLERR_SUCCESS;
513}
514
515static imgtoolerr_t datapack_read_file(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf)
516{
517   imgtool_image *image = imgtool_partition_image(partition);
518   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
519   int index = seek_file_name(pack, filename);
520
521   if (index >= 0)
522   {
523      if ((pack->pack_index[index].type & 0x7f) == 0x01)
524      {
525         // ODB files
526         stream_seek(pack->stream, 0x10, SEEK_SET);
527         get_odb(pack->stream, destf, pack->pack_index[index].type, pack->pack_index[index].id);
528      }
529      else if ((pack->pack_index[index].type & 0x7f) == 0x03)
530      {
531         // OB3/OPL files
532         stream_seek(pack->stream, pack->pack_index[index].data_rec, SEEK_SET);
533         get_ob3(pack->stream, destf, pack->pack_index[index].type, pack->pack_index[index].id);
534      }
535      else
536      {
537         // Other files
538         return IMGTOOLERR_UNIMPLEMENTED;
539      }
540
541      return IMGTOOLERR_SUCCESS;
542   }
543   else
544      return IMGTOOLERR_FILENOTFOUND;
545}
546
547static imgtoolerr_t datapack_write_file( imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, option_resolution *opts)
548{
549   imgtool_image *image = imgtool_partition_image(partition);
550   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
551   UINT8 data_head[4] = {0x02, 0x80, 0x00, 0x00};
552   UINT8 head[3];
553   UINT16 size = 0;
554   UINT8 type = option_resolution_lookup_int(opts, 'T');
555   UINT8 file_id = option_resolution_lookup_int(opts, 'I');
556
557   if (!pack->eop)
558      return IMGTOOLERR_CORRUPTIMAGE;
559
560   // if not file_id is specified get the first free (for ODB only)
561   if (file_id == 0 && type == 3)
562   {
563      file_id = get_free_file_id(pack);
564
565      if (file_id == 0xff)
566         return IMGTOOLERR_NOSPACE;
567   }
568
569   stream_read(sourcef, head, 3);
570   stream_seek(pack->stream, pack->eop, SEEK_SET);
571
572   if (type == 0)
573      type = (!strncmp((char*)head, "ORG", 3)) ? 1 : 2;
574
575   switch (type)
576   {
577      case 1:      //OB3 file
578         put_name_record(pack->stream, filename, 0x83, file_id);
579         stream_write(pack->stream, data_head, 4);
580         size = put_ob3(sourcef, pack->stream);
581         break;
582      case 2:      //OPL file
583         put_name_record(pack->stream, filename, 0x83, file_id);
584         stream_write(pack->stream, data_head, 4);
585         size = put_opl(sourcef, pack->stream);
586         break;
587      case 3:      //ODB file
588         put_name_record(pack->stream, filename, 0x81, file_id);
589         size = put_odb(sourcef, pack->stream, file_id);
590         break;
591   }
592
593   if (type != 3)
594   {
595      // update the OB3/OPL long record size
596      stream_seek(pack->stream, pack->eop + 13, SEEK_SET);
597      stream_putc(pack->stream, (size>>8) & 0xff);
598      stream_putc(pack->stream, size & 0xff);
599   }
600
601   update_opk_head(pack->stream);
602
603   if (update_pack_index(pack))
604      return IMGTOOLERR_SUCCESS;
605   else
606      return IMGTOOLERR_CORRUPTIMAGE;
607}
608
609static imgtoolerr_t datapack_delete_file( imgtool_partition *partition, const char *filename)
610{
611   imgtool_image *image = imgtool_partition_image(partition);
612   psion_pack *pack = (psion_pack*)imgtool_image_extra_bytes(image);
613   int index = seek_file_name(pack, filename);
614
615   if (index >= 0)
616   {
617      // clear the bit 7 of the file type to mark the file as deleted
618      stream_seek(pack->stream, pack->pack_index[index].name_rec + 1, SEEK_SET);
619      stream_putc(pack->stream, pack->pack_index[index].type & 0x7f);
620
621      if (update_pack_index(pack))
622         return IMGTOOLERR_SUCCESS;
623      else
624         return IMGTOOLERR_CORRUPTIMAGE;
625   }
626   else
627      return IMGTOOLERR_FILENOTFOUND;
628}
629
630static OPTION_GUIDE_START( psion_create_optguide )
631   OPTION_ENUM_START( 'S', "size", "datapack size" )
632      OPTION_ENUM( 1, "8k", "8 kbyte" )
633      OPTION_ENUM( 2, "16k", "16 kbyts" )
634      OPTION_ENUM( 4, "32k", "32 kbyte" )
635      OPTION_ENUM( 8, "64k", "64 kbyte" )
636      OPTION_ENUM( 16, "128k", "128 kbyte" ) // only paged datapacks can have this size
637   OPTION_ENUM_END
638   OPTION_INT('R', "ram", "EPROM/RAM datapack" )
639   OPTION_INT('P', "paged", "linear/paged datapack" )
640   OPTION_INT('W', "protect", "write-protected datapack" )
641   OPTION_INT('B', "boot", "bootable datapack" )
642   OPTION_INT('C', "copy", "copyable datapack" )
643OPTION_GUIDE_END
644
645static OPTION_GUIDE_START( psion_write_optguide )
646   OPTION_ENUM_START( 'T', "type", "file type" )
647      OPTION_ENUM( 1, "OB3", "OB3 files" )
648      OPTION_ENUM( 2, "OPL", "OPL files" )
649      OPTION_ENUM( 3, "ODB", "ODB or text files" )
650   OPTION_ENUM_END
651   OPTION_INT( 'I', "id", "File ID" )
652OPTION_GUIDE_END
653
654void psion_get_info( const imgtool_class *imgclass, UINT32 state, union imgtoolinfo *info)
655{
656   switch (state)
657   {
658      // --- the following bits of info are returned as 64-bit signed integers ---
659      case IMGTOOLINFO_INT_IMAGE_EXTRA_BYTES          : info->i = sizeof(psion_pack); break;
660      case IMGTOOLINFO_INT_DIRECTORY_EXTRA_BYTES      : info->i = sizeof(psion_iter); break;
661
662      // --- the following bits of info are returned as pointers to data or functions ---
663      case IMGTOOLINFO_PTR_OPEN        : info->open        = datapack_open; break;
664      case IMGTOOLINFO_PTR_CREATE      : info->create      = datapack_create; break;
665      case IMGTOOLINFO_PTR_CLOSE       : info->close       = datapack_close; break;
666      case IMGTOOLINFO_PTR_BEGIN_ENUM  : info->begin_enum  = datapack_begin_enum; break;
667      case IMGTOOLINFO_PTR_NEXT_ENUM   : info->next_enum   = datapack_next_enum; break;
668      case IMGTOOLINFO_PTR_CLOSE_ENUM  : info->close_enum  = datapack_close_enum; break;
669      case IMGTOOLINFO_PTR_FREE_SPACE  : info->free_space  = datapack_free_space; break;
670      case IMGTOOLINFO_PTR_READ_FILE   : info->read_file   = datapack_read_file; break;
671      case IMGTOOLINFO_PTR_WRITE_FILE  : info->write_file  = datapack_write_file; break;
672      case IMGTOOLINFO_PTR_DELETE_FILE : info->delete_file = datapack_delete_file; break;
673      case IMGTOOLINFO_PTR_CREATEIMAGE_OPTGUIDE : info->createimage_optguide = psion_create_optguide; break;
674      case IMGTOOLINFO_PTR_WRITEFILE_OPTGUIDE : info->createimage_optguide = psion_write_optguide; break;
675
676      // --- the following bits of info are returned as NULL-terminated strings ---
677      case IMGTOOLINFO_STR_NAME            : strcpy( info->s = imgtool_temp_str(), "psionpack"); break;
678      case IMGTOOLINFO_STR_DESCRIPTION     : strcpy( info->s = imgtool_temp_str(), "Psion Organiser II Datapack"); break;
679      case IMGTOOLINFO_STR_FILE            : strcpy( info->s = imgtool_temp_str(), __FILE__); break;
680      case IMGTOOLINFO_STR_FILE_EXTENSIONS : strcpy( info->s = imgtool_temp_str(), "opk"); break;
681      case IMGTOOLINFO_STR_CREATEIMAGE_OPTSPEC : strcpy( info->s = imgtool_temp_str(), "S1/2/[4]/8/16;R[0]/1;P[0]/1;W0/[1];B[0]/1;C0/[1]"); break;
682      case IMGTOOLINFO_STR_WRITEFILE_OPTSPEC : strcpy( info->s = imgtool_temp_str(), "T[1]/2/3;I[0]/145-255"); break;
683   }
684}
src/mess/video/hd44780.c
r9430r9431
1/***************************************************************************
2 
3        Hitachi HD44780 LCD controller
4 
5        TODO:
6        - 4-bit mode
7        - 5x10 chars
8        - dump internal CGROM
9 
10***************************************************************************/
11 
12#include "emu.h"
13#include "video/hd44780.h"
14 
15 
16//**************************************************************************
17//  device configuration
18//**************************************************************************
19 
20//-------------------------------------------------
21//  hd44780_device_config - constructor
22//-------------------------------------------------
23 
24hd44780_device_config::hd44780_device_config( const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock ):
25   device_config( mconfig, static_alloc_device_config, "HD44780", tag, owner, clock)
26{
27}
28 
29 
30//-------------------------------------------------
31//  static_alloc_device_config - allocate a new
32//  configuration object
33//-------------------------------------------------
34 
35device_config *hd44780_device_config::static_alloc_device_config( const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock )
36{
37   return global_alloc( hd44780_device_config( mconfig, tag, owner, clock ) );
38}
39 
40 
41//-------------------------------------------------
42//  alloc_device - allocate a new device object
43//-------------------------------------------------
44 
45device_t *hd44780_device_config::alloc_device( running_machine &machine ) const
46{
47   return auto_alloc( &machine, hd44780_device( machine, *this ) );
48}
49 
50//-------------------------------------------------
51//  device_config_complete - perform any
52//  operations now that the configuration is
53//  complete
54//-------------------------------------------------
55 
56void hd44780_device_config::device_config_complete()
57{
58   // inherit a copy of the static data
59   const hd44780_interface *intf = reinterpret_cast<const hd44780_interface *>(static_config());
60 
61   if (intf != NULL)
62      *static_cast<hd44780_interface *>(this) = *intf;
63 
64   // or initialize to defaults if none provided
65   else
66   {
67      height = width = 0;
68      custom_layout = NULL;
69   }
70}
71 
72//-------------------------------------------------
73//  device_validity_check - perform validity checks
74//  on this device
75//-------------------------------------------------
76 
77bool hd44780_device_config::device_validity_check( const game_driver &driver ) const
78{
79   bool error = false;
80 
81   // display with more than 2 lines requires a layout
82   if ((custom_layout == NULL && height > 2) || height == 0 || width == 0)
83   {
84      mame_printf_error("%s: %s device '%s' has invalid parameter\n", driver.source_file, driver.name, tag());
85      error = true;
86   }
87 
88   return error;
89}
90 
91//**************************************************************************
92//  live device
93//**************************************************************************
94 
95//-------------------------------------------------
96//  hd44780_device - constructor
97//-------------------------------------------------
98 
99hd44780_device::hd44780_device( running_machine &_machine, const hd44780_device_config &config ) :
100   device_t( _machine, config ),
101   m_config( config )
102{
103}
104 
105 
106//-------------------------------------------------
107//  device_start - device-specific startup
108//-------------------------------------------------
109 
110void hd44780_device::device_start()
111{
112   busy_timer = timer_alloc(&m_machine,  bf_clear, this);
113 
114   timer_pulse(&m_machine, ATTOTIME_IN_MSEC(500), this, 0, blink_timer);
115 
116   chargen = memory_region(&m_machine, "chargen");
117 
118   state_save_register_device_item( this, 0, ac);
119   state_save_register_device_item( this, 0, ac_mode);
120   state_save_register_device_item( this, 0, data_bus_flag);
121   state_save_register_device_item( this, 0, cursor_pos);
122   state_save_register_device_item( this, 0, display_on);
123   state_save_register_device_item( this, 0, cursor_on);
124   state_save_register_device_item( this, 0, shift_on);
125   state_save_register_device_item( this, 0, blink_on);
126   state_save_register_device_item( this, 0, direction);
127   state_save_register_device_item( this, 0, data_len);
128   state_save_register_device_item( this, 0, n_line);
129   state_save_register_device_item( this, 0, char_size);
130   state_save_register_device_item( this, 0, disp_shift);
131   state_save_register_device_item( this, 0, blink);
132   state_save_register_device_item_array( this, 0, ddram);
133   state_save_register_device_item_array( this, 0, cgram);
134}
135 
136 
137//-------------------------------------------------
138//  device_reset - device-specific reset
139//-------------------------------------------------
140 
141void hd44780_device::device_reset()
142{
143   busy_flag = 0;
144 
145   memset(ddram, 0, ARRAY_LENGTH(ddram));
146   memset(cgram, 0, ARRAY_LENGTH(cgram));
147   ac = 0;
148   ac_mode = 0;
149   data_bus_flag = 0;
150   cursor_pos = 0;
151   display_on = 0;
152   cursor_on = 0;
153   shift_on = 0;
154   blink_on = 0;
155   direction = 1;
156   data_len = 1;
157   n_line = 0;
158   char_size = 0;
159   disp_shift = 0;
160   blink = 0;
161 
162   set_busy_flag(1520);
163}
164 
165 
166//**************************************************************************
167//  device interface
168//**************************************************************************
169 
170int hd44780_device::video_update(bitmap_t *bitmap, const rectangle *cliprect)
171{
172   assert(m_config.height*9 <= bitmap->height && m_config.width*6 <= bitmap->width);
173 
174   bitmap_fill(bitmap, cliprect, 0);
175 
176   if (display_on)
177      for (int l=0; l<m_config.height; l++)
178         for (int i=0; i<m_config.width; i++)
179         {
180            UINT8 line_base = l * 0x40;
181            UINT8 line_size = (n_line) ? 40 : 80;
182            INT8 char_pos = line_base + i;
183 
184            // if specified uses the custom layout
185            if (m_config.custom_layout != NULL)
186               char_pos = m_config.custom_layout[l*m_config.width + i];
187            else
188            {
189               char_pos += disp_shift;
190 
191               while (char_pos < 0 || (char_pos - line_base) >= line_size)
192               {
193                  if (char_pos < 0)
194                     char_pos += line_size;
195                  else if (char_pos - line_base >= line_size)
196                     char_pos -= line_size;
197               }
198            }
199 
200            for (int y=0; y<8; y++)
201               for (int x=0; x<5; x++)
202                  if (ddram[char_pos] <= 0x10)
203                  {
204                     //draw CGRAM characters
205                     *BITMAP_ADDR16(bitmap, l*9 + y, i*6 + x) = BIT(cgram[(ddram[char_pos]&0x07)*8+y], 4-x);
206                  }
207                  else
208                  {
209                     //draw CGROM characters
210                     *BITMAP_ADDR16(bitmap, l*9 + y, i*6 + x) = BIT(chargen[(ddram[char_pos]-0x20)*8+y], 4-x);
211                  }
212 
213            // if is the correct position draw cursor and blink
214            if (char_pos == cursor_pos)
215            {
216               //draw the cursor
217               if (cursor_on)
218                  for (int x=0; x<5; x++)
219                     *BITMAP_ADDR16(bitmap, l*9 + 7, i * 6 + x) = 1;
220 
221               if (!blink && blink_on)
222                  for (int y=0; y<7; y++)
223                     for (int x=0; x<5; x++)
224                        *BITMAP_ADDR16(bitmap, l*9 + y, i * 6 + x) = 1;
225            }
226         }
227 
228   return 0;
229 
230}
231 
232void hd44780_device::control_write(offs_t offset, UINT8 data)
233{
234   if (BIT(data, 7))
235   {
236      ac_mode = 0;
237      ac = data & 0x7f;
238      if (data != 0x81)
239         cursor_pos = ac;
240      set_busy_flag(37);
241   }
242   else if (BIT(data, 6))
243   {
244      ac_mode = 1;
245      ac = data & 0x3f;
246      set_busy_flag(37);
247   }
248   else if (BIT(data, 5))
249   {
250      data_len = BIT(data, 4);
251      n_line = BIT(data, 3);
252      char_size = BIT(data, 2);
253      set_busy_flag(37);
254   }
255   else if (BIT(data, 4))
256   {
257      UINT8 direct = (BIT(data, 2)) ? +1 : -1;
258 
259      if (BIT(data, 3))
260         disp_shift += direct;
261      else
262      {
263         ac += direct;
264         cursor_pos += direct;
265      }
266 
267      set_busy_flag(37);
268   }
269   else if (BIT(data, 3))
270   {
271      display_on = BIT(data, 2);
272      cursor_on = BIT(data, 1);
273      blink_on = BIT(data, 0);
274 
275      set_busy_flag(37);
276   }
277   else if (BIT(data, 2))
278   {
279      direction = (BIT(data, 1)) ? +1 : -1;
280 
281      shift_on = BIT(data, 0);
282 
283      set_busy_flag(37);
284   }
285   else if (BIT(data, 1))
286   {
287      ac = 0;
288      cursor_pos = 0;
289      ac_mode = 0;
290      direction = 1;
291      disp_shift = 0;
292      set_busy_flag(1520);
293   }
294   else if (BIT(data, 0))
295   {
296      ac = 0;
297      cursor_pos = 0;
298      ac_mode = 0;
299      direction = 1;
300      disp_shift = 0;
301      memset(ddram, 0x20, ARRAY_LENGTH(ddram));
302      memset(cgram, 0x20, ARRAY_LENGTH(cgram));
303      set_busy_flag(1520);
304   }
305}
306 
307UINT8 hd44780_device::control_read(offs_t offset)
308{
309   return busy_flag<<7 || ac&0x7f;
310}
311 
312void hd44780_device::data_write(offs_t offset, UINT8 data)
313{
314   if (ac_mode == 0)
315      ddram[ac] = data;
316   else
317      cgram[ac] = data;
318 
319   data_bus_flag = 1;
320 
321   set_busy_flag(41);
322}
323 
324UINT8 hd44780_device::data_read(offs_t offset)
325{
326   UINT8 data;
327 
328   if (ac_mode == 0)
329      data = ddram[ac];
330   else
331      data = cgram[ac];
332 
333   data_bus_flag = 2;
334 
335   set_busy_flag(41);
336 
337   return data;
338}
339 
340 
341//**************************************************************************
342//  internal helpers
343//**************************************************************************
344 
345void hd44780_device::set_busy_flag(UINT16 usec)
346{
347   busy_flag = 1;
348 
349   timer_adjust_oneshot( busy_timer, ATTOTIME_IN_USEC( usec ), 0 );
350}
351 
352TIMER_CALLBACK( hd44780_device::bf_clear )
353{
354   hd44780_device *hd44780 = reinterpret_cast<hd44780_device *>(ptr);
355 
356   if (hd44780->data_bus_flag)
357   {
358      int new_ac = hd44780->ac + hd44780->direction;
359 
360      hd44780->ac = (new_ac < 0) ? 0 : ((new_ac > 0x7f) ? 0x7f : new_ac);
361 
362      if (hd44780->ac_mode == 0)
363      {
364         hd44780->cursor_pos = hd44780->ac;
365 
366         // display is shifted only after a write
367         if (hd44780->shift_on && hd44780->data_bus_flag == 1)
368            hd44780->disp_shift += hd44780->direction;
369      }
370 
371      hd44780->data_bus_flag = 0;
372   }
373 
374   hd44780->busy_flag = 0;
375}
376 
377TIMER_CALLBACK( hd44780_device::blink_timer )
378{
379   hd44780_device *hd44780 = reinterpret_cast<hd44780_device *>(ptr);
380 
381   hd44780->blink = ~hd44780->blink;
382}
383 
384//**************************************************************************
385//  READ/WRITE HANDLERS
386//**************************************************************************
387 
388WRITE8_DEVICE_HANDLER( hd44780_control_w )
389{
390   downcast<hd44780_device *>( device )->control_write( offset, data );
391}
392 
393WRITE8_DEVICE_HANDLER( hd44780_data_w )
394{
395   downcast<hd44780_device *>( device )->data_write( offset, data );
396}
397 
398READ8_DEVICE_HANDLER( hd44780_control_r )
399{
400   return downcast<hd44780_device *>( device )->control_read( offset );
401}
402 
403READ8_DEVICE_HANDLER( hd44780_data_r )
404{
405   return downcast<hd44780_device *>( device )->data_read( offset );
406}
407 
408const device_type HD44780 = hd44780_device_config::static_alloc_device_config;
1/***************************************************************************
2
3        Hitachi HD44780 LCD controller
4
5        TODO:
6        - 4-bit mode
7        - 5x10 chars
8        - dump internal CGROM
9
10***************************************************************************/
11
12#include "emu.h"
13#include "video/hd44780.h"
14
15
16//**************************************************************************
17//  device configuration
18//**************************************************************************
19
20//-------------------------------------------------
21//  hd44780_device_config - constructor
22//-------------------------------------------------
23
24hd44780_device_config::hd44780_device_config( const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock ):
25   device_config( mconfig, static_alloc_device_config, "HD44780", tag, owner, clock)
26{
27}
28
29
30//-------------------------------------------------
31//  static_alloc_device_config - allocate a new
32//  configuration object
33//-------------------------------------------------
34
35device_config *hd44780_device_config::static_alloc_device_config( const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock )
36{
37   return global_alloc( hd44780_device_config( mconfig, tag, owner, clock ) );
38}
39
40
41//-------------------------------------------------
42//  alloc_device - allocate a new device object
43//-------------------------------------------------
44
45device_t *hd44780_device_config::alloc_device( running_machine &machine ) const
46{
47   return auto_alloc( &machine, hd44780_device( machine, *this ) );
48}
49
50//-------------------------------------------------
51//  device_config_complete - perform any
52//  operations now that the configuration is
53//  complete
54//-------------------------------------------------
55
56void hd44780_device_config::device_config_complete()
57{
58   // inherit a copy of the static data
59   const hd44780_interface *intf = reinterpret_cast<const hd44780_interface *>(static_config());
60
61   if (intf != NULL)
62      *static_cast<hd44780_interface *>(this) = *intf;
63
64   // or initialize to defaults if none provided
65   else
66   {
67      height = width = 0;
68      custom_layout = NULL;
69   }
70}
71
72//-------------------------------------------------
73//  device_validity_check - perform validity checks
74//  on this device
75//-------------------------------------------------
76
77bool hd44780_device_config::device_validity_check( const game_driver &driver ) const
78{
79   bool error = false;
80
81   // display with more than 2 lines requires a layout
82   if ((custom_layout == NULL && height > 2) || height == 0 || width == 0)
83   {
84      mame_printf_error("%s: %s device '%s' has invalid parameter\n", driver.source_file, driver.name, tag());
85      error = true;
86   }
87
88   return error;
89}
90
91//**************************************************************************
92//  live device
93//**************************************************************************
94
95//-------------------------------------------------
96//  hd44780_device - constructor
97//-------------------------------------------------
98
99hd44780_device::hd44780_device( running_machine &_machine, const hd44780_device_config &config ) :
100   device_t( _machine, config ),
101   m_config( config )
102{
103}
104
105
106//-------------------------------------------------
107//  device_start - device-specific startup
108//-------------------------------------------------
109
110void hd44780_device::device_start()
111{
112   busy_timer = timer_alloc(&m_machine,  bf_clear, this);
113
114   timer_pulse(&m_machine, ATTOTIME_IN_MSEC(500), this, 0, blink_timer);
115
116   chargen = memory_region(&m_machine, "chargen");
117
118   state_save_register_device_item( this, 0, ac);
119   state_save_register_device_item( this, 0, ac_mode);
120   state_save_register_device_item( this, 0, data_bus_flag);
121   state_save_register_device_item( this, 0, cursor_pos);
122   state_save_register_device_item( this, 0, display_on);
123   state_save_register_device_item( this, 0, cursor_on);
124   state_save_register_device_item( this, 0, shift_on);
125   state_save_register_device_item( this, 0, blink_on);
126   state_save_register_device_item( this, 0, direction);
127   state_save_register_device_item( this, 0, data_len);
128   state_save_register_device_item( this, 0, n_line);
129   state_save_register_device_item( this, 0, char_size);
130   state_save_register_device_item( this, 0, disp_shift);
131   state_save_register_device_item( this, 0, blink);
132   state_save_register_device_item_array( this, 0, ddram);
133   state_save_register_device_item_array( this, 0, cgram);
134}
135
136
137//-------------------------------------------------
138//  device_reset - device-specific reset
139//-------------------------------------------------
140
141void hd44780_device::device_reset()
142{
143   busy_flag = 0;
144
145   memset(ddram, 0, ARRAY_LENGTH(ddram));
146   memset(cgram, 0, ARRAY_LENGTH(cgram));
147   ac = 0;
148   ac_mode = 0;
149   data_bus_flag = 0;
150   cursor_pos = 0;
151   display_on = 0;
152   cursor_on = 0;
153   shift_on = 0;
154   blink_on = 0;
155   direction = 1;
156   data_len = 1;
157   n_line = 0;
158   char_size = 0;
159   disp_shift = 0;
160   blink = 0;
161
162   set_busy_flag(1520);
163}
164
165
166//**************************************************************************
167//  device interface
168//**************************************************************************
169
170int hd44780_device::video_update(bitmap_t *bitmap, const rectangle *cliprect)
171{
172   assert(m_config.height*9 <= bitmap->height && m_config.width*6 <= bitmap->width);
173
174   bitmap_fill(bitmap, cliprect, 0);
175
176   if (display_on)
177      for (int l=0; l<m_config.height; l++)
178         for (int i=0; i<m_config.width; i++)
179         {
180            UINT8 line_base = l * 0x40;
181            UINT8 line_size = (n_line) ? 40 : 80;
182            INT8 char_pos = line_base + i;
183
184            // if specified uses the custom layout
185            if (m_config.custom_layout != NULL)
186               char_pos = m_config.custom_layout[l*m_config.width + i];
187            else
188            {
189               char_pos += disp_shift;
190
191               while (char_pos < 0 || (char_pos - line_base) >= line_size)
192               {
193                  if (char_pos < 0)
194                     char_pos += line_size;
195                  else if (char_pos - line_base >= line_size)
196                     char_pos -= line_size;
197               }
198            }
199
200            for (int y=0; y<8; y++)
201               for (int x=0; x<5; x++)
202                  if (ddram[char_pos] <= 0x10)
203                  {
204                     //draw CGRAM characters
205                     *BITMAP_ADDR16(bitmap, l*9 + y, i*6 + x) = BIT(cgram[(ddram[char_pos]&0x07)*8+y], 4-x);
206                  }
207                  else
208                  {
209                     //draw CGROM characters
210                     *BITMAP_ADDR16(bitmap, l*9 + y, i*6 + x) = BIT(chargen[(ddram[char_pos]-0x20)*8+y], 4-x);
211                  }
212
213            // if is the correct position draw cursor and blink
214            if (char_pos == cursor_pos)
215            {
216               //draw the cursor
217               if (cursor_on)
218                  for (int x=0; x<5; x++)
219                     *BITMAP_ADDR16(bitmap, l*9 + 7, i * 6 + x) = 1;
220
221               if (!blink && blink_on)
222                  for (int y=0; y<7; y++)
223                     for (int x=0; x<5; x++)
224                        *BITMAP_ADDR16(bitmap, l*9 + y, i * 6 + x) = 1;
225            }
226         }
227
228   return 0;
229
230}
231
232void hd44780_device::control_write(offs_t offset, UINT8 data)
233{
234   if (BIT(data, 7))
235   {
236      ac_mode = 0;
237      ac = data & 0x7f;
238      if (data != 0x81)
239         cursor_pos = ac;
240      set_busy_flag(37);
241   }
242   else if (BIT(data, 6))
243   {
244      ac_mode = 1;
245      ac = data & 0x3f;
246      set_busy_flag(37);
247   }
248   else if (BIT(data, 5))
249   {
250      data_len = BIT(data, 4);
251      n_line = BIT(data, 3);
252      char_size = BIT(data, 2);
253      set_busy_flag(37);
254   }
255   else if (BIT(data, 4))
256   {
257      UINT8 direct = (BIT(data, 2)) ? +1 : -1;
258
259      if (BIT(data, 3))
260         disp_shift += direct;
261      else
262      {
263         ac += direct;
264         cursor_pos += direct;
265      }
266
267      set_busy_flag(37);
268   }
269   else if (BIT(data, 3))
270   {
271      display_on = BIT(data, 2);
272      cursor_on = BIT(data, 1);
273      blink_on = BIT(data, 0);
274
275      set_busy_flag(37);
276   }
277   else if (BIT(data, 2))
278   {
279      direction = (BIT(data, 1)) ? +1 : -1;
280
281      shift_on = BIT(data, 0);
282
283      set_busy_flag(37);
284   }
285   else if (BIT(data, 1))
286   {
287      ac = 0;
288      cursor_pos = 0;
289      ac_mode = 0;
290      direction = 1;
291      disp_shift = 0;
292      set_busy_flag(1520);
293   }
294   else if (BIT(data, 0))
295   {
296      ac = 0;
297      cursor_pos = 0;
298      ac_mode = 0;
299      direction = 1;
300      disp_shift = 0;
301      memset(ddram, 0x20, ARRAY_LENGTH(ddram));
302      memset(cgram, 0x20, ARRAY_LENGTH(cgram));
303      set_busy_flag(1520);
304   }
305}
306
307UINT8 hd44780_device::control_read(offs_t offset)
308{
309   return busy_flag<<7 || ac&0x7f;
310}
311
312void hd44780_device::data_write(offs_t offset, UINT8 data)
313{
314   if (ac_mode == 0)
315      ddram[ac] = data;
316   else
317      cgram[ac] = data;
318
319   data_bus_flag = 1;
320
321   set_busy_flag(41);
322}
323
324UINT8 hd44780_device::data_read(offs_t offset)
325{
326   UINT8 data;
327
328   if (ac_mode == 0)
329      data = ddram[ac];
330   else
331      data = cgram[ac];
332
333   data_bus_flag = 2;
334
335   set_busy_flag(41);
336
337   return data;
338}
339
340
341//**************************************************************************
342//  internal helpers
343//**************************************************************************
344
345void hd44780_device::set_busy_flag(UINT16 usec)
346{
347   busy_flag = 1;
348
349   timer_adjust_oneshot( busy_timer, ATTOTIME_IN_USEC( usec ), 0 );
350}
351
352TIMER_CALLBACK( hd44780_device::bf_clear )
353{
354   hd44780_device *hd44780 = reinterpret_cast<hd44780_device *>(ptr);
355
356   if (hd44780->data_bus_flag)
357   {
358      int new_ac = hd44780->ac + hd44780->direction;
359
360      hd44780->ac = (new_ac < 0) ? 0 : ((new_ac > 0x7f) ? 0x7f : new_ac);
361
362      if (hd44780->ac_mode == 0)
363      {
364         hd44780->cursor_pos = hd44780->ac;
365
366         // display is shifted only after a write
367         if (hd44780->shift_on && hd44780->data_bus_flag == 1)
368            hd44780->disp_shift += hd44780->direction;
369      }
370
371      hd44780->data_bus_flag = 0;
372   }
373
374   hd44780->busy_flag = 0;
375}
376
377TIMER_CALLBACK( hd44780_device::blink_timer )
378{
379   hd44780_device *hd44780 = reinterpret_cast<hd44780_device *>(ptr);
380
381   hd44780->blink = ~hd44780->blink;
382}
383
384//**************************************************************************
385//  READ/WRITE HANDLERS
386//**************************************************************************
387
388WRITE8_DEVICE_HANDLER( hd44780_control_w )
389{
390   downcast<hd44780_device *>( device )->control_write( offset, data );
391}
392
393WRITE8_DEVICE_HANDLER( hd44780_data_w )
394{
395   downcast<hd44780_device *>( device )->data_write( offset, data );
396}
397
398READ8_DEVICE_HANDLER( hd44780_control_r )
399{
400   return downcast<hd44780_device *>( device )->control_read( offset );
401}
402
403READ8_DEVICE_HANDLER( hd44780_data_r )
404{
405   return downcast<hd44780_device *>( device )->data_read( offset );
406}
407
408const device_type HD44780 = hd44780_device_config::static_alloc_device_config;
src/mess/video/hd44780.h
r9430r9431
1/***************************************************************************
2 
3        Hitachi HD44780 LCD controller
4 
5***************************************************************************/
6 
7#pragma once
8 
9#ifndef __HD44780_H__
10#define __HD44780_H__
11 
12 
13#define MDRV_HD44780_ADD( _tag , _config) \
14   MDRV_DEVICE_ADD( _tag, HD44780, 0 ) \
15   MDRV_DEVICE_CONFIG(_config)
16 
17//**************************************************************************
18//  TYPE DEFINITIONS
19//**************************************************************************
20 
21// ======================> hd44780_interface
22 
23struct hd44780_interface
24{
25   UINT8 height;         // number of lines
26   UINT8 width;         // chars for line
27   UINT8 *custom_layout;   // custom display layout (NULL for default)
28};
29 
30 
31// ======================> hd44780_device_config
32 
33class hd44780_device_config :
34   public device_config,
35   public hd44780_interface
36{
37   friend class hd44780_device;
38 
39   // construction/destruction
40   hd44780_device_config( const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock );
41 
42public:
43   // allocators
44   static device_config *static_alloc_device_config( const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock );
45   virtual device_t *alloc_device( running_machine &machine ) const;
46 
47protected:
48   // device_config overrides
49   virtual void device_config_complete();
50   virtual bool device_validity_check( const game_driver &driver ) const;
51};
52 
53 
54// ======================> hd44780_device
55 
56class hd44780_device :
57   public device_t
58{
59   friend class hd44780_device_config;
60 
61   // construction/destruction
62   hd44780_device( running_machine &_machine, const hd44780_device_config &config );
63 
64public:
65   // device interface
66   void control_write(offs_t offset, UINT8 data);
67   UINT8 control_read(offs_t offset);
68   void data_write(offs_t offset, UINT8 data);
69   UINT8 data_read(offs_t offset);
70 
71   int video_update(bitmap_t *bitmap, const rectangle *cliprect);
72 
73protected:
74   // device-level overrides
75   virtual void device_start();
76   virtual void device_reset();
77 
78   // internal helper
79   static TIMER_CALLBACK( bf_clear );
80   static TIMER_CALLBACK( blink_timer );
81 
82   void set_busy_flag(UINT16 usec);
83 
84   // internal state
85   const hd44780_device_config &m_config;
86 
87   emu_timer *busy_timer;
88   UINT8 *chargen;
89   UINT8 busy_flag;
90 
91   UINT8 ddram[0x80];   //internal display data RAM
92   UINT8 cgram[0x40];   //internal chargen RAM
93 
94   INT8 ac;         //address counter
95   UINT8 ac_mode;      //0=DDRAM 1=CGRAM
96   UINT8 data_bus_flag;//0=none 1=write 2=read
97 
98   INT8 cursor_pos;   //cursor position
99   UINT8 display_on;   //display on/off
100   UINT8 cursor_on;   //cursor on/off
101   UINT8 blink_on;      //blink on/off
102   UINT8 shift_on;      //shift  on/off
103   INT8 disp_shift;   //display shift
104 
105   INT8 direction;      //auto increment/decrement
106   UINT8 data_len;      //interface data length 4 or 8 bit
107   UINT8 n_line;      //number of lines
108   UINT8 char_size;   //char size 5x8 or 5x10
109 
110   UINT8 blink;
111};
112 
113// device type definition
114extern const device_type HD44780;
115 
116 
117//**************************************************************************
118//  READ/WRITE HANDLERS
119//**************************************************************************
120 
121WRITE8_DEVICE_HANDLER( hd44780_control_w );
122WRITE8_DEVICE_HANDLER( hd44780_data_w );
123READ8_DEVICE_HANDLER( hd44780_control_r );
124READ8_DEVICE_HANDLER( hd44780_data_r );
125 
126#endif
1/***************************************************************************
2
3        Hitachi HD44780 LCD controller
4
5***************************************************************************/
6
7#pragma once
8
9#ifndef __HD44780_H__
10#define __HD44780_H__
11
12
13#define MDRV_HD44780_ADD( _tag , _config) \
14   MDRV_DEVICE_ADD( _tag, HD44780, 0 ) \
15   MDRV_DEVICE_CONFIG(_config)
16
17//**************************************************************************
18//  TYPE DEFINITIONS
19//**************************************************************************
20
21// ======================> hd44780_interface
22
23struct hd44780_interface
24{
25   UINT8 height;         // number of lines
26   UINT8 width;         // chars for line
27   UINT8 *custom_layout;   // custom display layout (NULL for default)
28};
29
30
31// ======================> hd44780_device_config
32
33class hd44780_device_config :
34   public device_config,
35   public hd44780_interface
36{
37   friend class hd44780_device;
38
39   // construction/destruction
40   hd44780_device_config( const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock );
41
42public:
43   // allocators
44   static device_config *static_alloc_device_config( const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock );
45   virtual device_t *alloc_device( running_machine &machine ) const;
46
47protected:
48   // device_config overrides
49   virtual void device_config_complete();
50   virtual bool device_validity_check( const game_driver &driver ) const;
51};
52
53
54// ======================> hd44780_device
55
56class hd44780_device :
57   public device_t
58{
59   friend class hd44780_device_config;
60
61   // construction/destruction
62   hd44780_device( running_machine &_machine, const hd44780_device_config &config );
63
64public:
65   // device interface
66   void control_write(offs_t offset, UINT8 data);
67   UINT8 control_read(offs_t offset);
68   void data_write(offs_t offset, UINT8 data);
69   UINT8 data_read(offs_t offset);
70
71   int video_update(bitmap_t *bitmap, const rectangle *cliprect);
72
73protected:
74   // device-level overrides
75   virtual void device_start();
76   virtual void device_reset();
77
78   // internal helper
79   static TIMER_CALLBACK( bf_clear );
80   static TIMER_CALLBACK( blink_timer );
81
82   void set_busy_flag(UINT16 usec);
83
84   // internal state
85   const hd44780_device_config &m_config;
86
87   emu_timer *busy_timer;
88   UINT8 *chargen;
89   UINT8 busy_flag;
90
91   UINT8 ddram[0x80];   //internal display data RAM
92   UINT8 cgram[0x40];   //internal chargen RAM
93
94   INT8 ac;         //address counter
95   UINT8 ac_mode;      //0=DDRAM 1=CGRAM
96   UINT8 data_bus_flag;//0=none 1=write 2=read
97
98   INT8 cursor_pos;   //cursor position
99   UINT8 display_on;   //display on/off
100   UINT8 cursor_on;   //cursor on/off
101   UINT8 blink_on;      //blink on/off
102   UINT8 shift_on;      //shift  on/off
103   INT8 disp_shift;   //display shift
104
105   INT8 direction;      //auto increment/decrement
106   UINT8 data_len;      //interface data length 4 or 8 bit
107   UINT8 n_line;      //number of lines
108   UINT8 char_size;   //char size 5x8 or 5x10
109
110   UINT8 blink;
111};
112
113// device type definition
114extern const device_type HD44780;
115
116
117//**************************************************************************
118//  READ/WRITE HANDLERS
119//**************************************************************************
120
121WRITE8_DEVICE_HANDLER( hd44780_control_w );
122WRITE8_DEVICE_HANDLER( hd44780_data_w );
123READ8_DEVICE_HANDLER( hd44780_control_r );
124READ8_DEVICE_HANDLER( hd44780_data_r );
125
126#endif
src/mess/layout/fidelz80.lay
r9430r9431
1<?xml version="1.0"?>
2<mamelayout version="2">
3   <element name="digit" defstate="0">
4      <led7seg>
5         <color red="0.75" green="0.0" blue="0.0" />
6      </led7seg>
7   </element>
8   <element name="led" defstate="0">
9      <disk state="1">
10         <color red="0.75" green="0.0" blue="0.0" />
11      </disk>
12      <disk state="0">
13         <color red="0.09375" green="0.0" blue="0.0" />
14      </disk>
15   </element>
16   <element name="background">
17      <rect>
18         <bounds left="0" top="0" right="1" bottom="1" />
19         <color red="0.0" green="0.0" blue="0.0" />
20      </rect>
21   </element>
22 
23   <view name="Simple LCD/LEDs">
24      <!-- Black background -->
25      <bezel element="background">
26         <bounds left="00" top="00" right="240" bottom="95" />
27      </bezel>
28 
29      <bezel name="digit0" element="digit">
30         <bounds x="10" y="15" width="50" height="80" />
31      </bezel>
32      <bezel name="digit1" element="digit">
33         <bounds x="70" y="15" width="50" height="80" />
34      </bezel>
35      <bezel name="digit2" element="digit">
36         <bounds x="130" y="15" width="50" height="80" />
37      </bezel>
38      <bezel name="digit3" element="digit">
39         <bounds x="190" y="15" width="50" height="80" />
40      </bezel>
41      <bezel name="led0" element="led">
42         <bounds x="10" y="00" width="10" height="10" />
43      </bezel>
44      <bezel name="led1" element="led">
45         <bounds x="130" y="00" width="10" height="10" />
46      </bezel>
47 
48   </view>
49</mamelayout>
1<?xml version="1.0"?>
2<mamelayout version="2">
3   <element name="digit" defstate="0">
4      <led7seg>
5         <color red="0.75" green="0.0" blue="0.0" />
6      </led7seg>
7   </element>
8   <element name="led" defstate="0">
9      <disk state="1">
10         <color red="0.75" green="0.0" blue="0.0" />
11      </disk>
12      <disk state="0">
13         <color red="0.09375" green="0.0" blue="0.0" />
14      </disk>
15   </element>
16   <element name="background">
17      <rect>
18         <bounds left="0" top="0" right="1" bottom="1" />
19         <color red="0.0" green="0.0" blue="0.0" />
20      </rect>
21   </element>
22
23   <view name="Simple LCD/LEDs">
24      <!-- Black background -->
25      <bezel element="background">
26         <bounds left="00" top="00" right="240" bottom="95" />
27      </bezel>
28
29      <bezel name="digit0" element="digit">
30         <bounds x="10" y="15" width="50" height="80" />
31      </bezel>
32      <bezel name="digit1" element="digit">
33         <bounds x="70" y="15" width="50" height="80" />
34      </bezel>
35      <bezel name="digit2" element="digit">
36         <bounds x="130" y="15" width="50" height="80" />
37      </bezel>
38      <bezel name="digit3" element="digit">
39         <bounds x="190" y="15" width="50" height="80" />
40      </bezel>
41      <bezel name="led0" element="led">
42         <bounds x="10" y="00" width="10" height="10" />
43      </bezel>
44      <bezel name="led1" element="led">
45         <bounds x="130" y="00" width="10" height="10" />
46      </bezel>
47
48   </view>
49</mamelayout>
src/mess/layout/sc2.lay
r9430r9431
1<?xml version="1.0"?>
2<mamelayout version="2">
3   <element name="digit" defstate="0">
4      <led7seg>
5         <color red="0.0" green="0.75" blue="0.0" />
6      </led7seg>
7   </element>
8   <element name="led" defstate="0">
9      <disk state="1">
10         <color red="0.0" green="0.8" blue="0.0" />
11      </disk>
12      <disk state="0">
13         <color red="0.0" green="0.2" blue="0.0" />
14      </disk>
15   </element>
16 
17   <element name="background">
18      <rect>
19         <bounds left="0" top="0" right="1" bottom="1" />
20         <color red="0.0" green="0.0" blue="0.0" />
21      </rect>
22   </element>
23 
24   <view name="Simple LCD/LEDs">
25      <!-- Black background -->
26      <bezel element="background">
27         <bounds left="00" top="00" right="240" bottom="95" />
28      </bezel>
29 
30      <bezel name="digit0" element="digit">
31         <bounds x="10" y="10" width="50" height="80" />
32      </bezel>
33      <bezel name="digit1" element="digit">
34         <bounds x="70" y="10" width="50" height="80" />
35      </bezel>
36      <bezel name="digit2" element="digit">
37         <bounds x="130" y="10" width="50" height="80" />
38      </bezel>
39      <bezel name="digit3" element="digit">
40         <bounds x="190" y="10" width="50" height="80" />
41      </bezel>
42      <bezel name="led0" element="led">
43         <bounds x="10" y="95" width="10" height="10" />
44      </bezel>
45      <bezel name="led1" element="led">
46         <bounds x="220" y="95" width="10" height="10" />
47      </bezel>
48 
49   </view>
50</mamelayout>
1<?xml version="1.0"?>
2<mamelayout version="2">
3   <element name="digit" defstate="0">
4      <led7seg>
5         <color red="0.0" green="0.75" blue="0.0" />
6      </led7seg>
7   </element>
8   <element name="led" defstate="0">
9      <disk state="1">
10         <color red="0.0" green="0.8" blue="0.0" />
11      </disk>
12      <disk state="0">
13         <color red="0.0" green="0.2" blue="0.0" />
14      </disk>
15   </element>
16
17   <element name="background">
18      <rect>
19         <bounds left="0" top="0" right="1" bottom="1" />
20         <color red="0.0" green="0.0" blue="0.0" />
21      </rect>
22   </element>
23
24   <view name="Simple LCD/LEDs">
25      <!-- Black background -->
26      <bezel element="background">
27         <bounds left="00" top="00" right="240" bottom="95" />
28      </bezel>
29
30      <bezel name="digit0" element="digit">
31         <bounds x="10" y="10" width="50" height="80" />
32      </bezel>
33      <bezel name="digit1" element="digit">
34         <bounds x="70" y="10" width="50" height="80" />
35      </bezel>
36      <bezel name="digit2" element="digit">
37         <bounds x="130" y="10" width="50" height="80" />
38      </bezel>
39      <bezel name="digit3" element="digit">
40         <bounds x="190" y="10" width="50" height="80" />
41      </bezel>
42      <bezel name="led0" element="led">
43         <bounds x="10" y="95" width="10" height="10" />
44      </bezel>
45      <bezel name="led1" element="led">
46         <bounds x="220" y="95" width="10" height="10" />
47      </bezel>
48
49   </view>
50</mamelayout>
src/mess/drivers/casloopy.c
r9430r9431
1/*****************************************************************************
2 
3   Casio Loopy (c) 1995 Casio
4 
5   skeleton driver
6 
7   TODO:
8   - Identify what actually is the NEC CDT-109 CPU, it should contain a program
9     controller for the thermal printer device
10 
11   Note:
12   - just a placeholder for any HW discovery, until we decap/trojan the BIOS,
13     the idea is to understand the HW enough to extract the SH-1 internal BIOS
14     data via a trojan;
15 
16===============================================================================
17 
18Casio Loopy PCB Layout
19----------------------
20 
21JCM631-MA1M C
22|---------------------------------------------------------|
23|    CB    CC              CD         CE       CF      CG |
24|--|                                                      |
25   |                                        BA10339F      |
26|--| 15218  |--|     CXA1645M                           CH|
27|           |  |                A1603C                    |
28|    15218  |  |                                          |
29|           |  |                                          |
30|BIOS.LSI352|  |                                          |
31|           |  |                      21MHz               |
32| |--------||  |   |------|                 SW1           |
33| |NEC     ||  |   |SH7021|      |----------|             |
34| |CDT109  ||CA|   |      |      |          |             |
35| |        ||  |   |------|      |CASIO     |             |
36| |--------||  |                 |RH-7500   |             |
37|           |  |                 |5C315     |          |--|
38| |-------| |  |                 |          |          |
39| |CASIO  | |  |                 |----------|          |--|
40| |RH-7501| |  |  HM514260                                |
41| |5C350  | |  |                               HM62256    |
42| |-------| |  |                                          |
43| 6379      |--|    SW301                      HM62256    /
44|--------|                        HM538123               /
45         |                                              /
46         |                                             /
47         |--------------------------------------------/
48 
49Notes:
50      Connectors
51      ----------
52      CA - Cartridge connector
53      CB - Power Input connector
54      CC - Composite Video and Audio Out connector
55      CD - Printer Cassette Motor connector
56      CE - Printer Data connector
57      CF - Printer Head connector
58      CG - Paper Sensor connector
59      CH - Joystick connector
60      Connectors on the back of the main unit include RCA audio (left/right), RCA composite video,
61      24V DC power input and contrast knob.
62      On top of the main unit, there is a reset button, on/off slide switch, a big eject button, a
63      button to cut off stickers after they're printed, a button to open the hatch where the sticker
64      cassette is located and a red LED for power.
65 
66      IC's
67      ----
68      BIOS2.LSI352- Hitachi HN62434 512k x8 (4MBit) maskROM (SOP40)
69      CDT-109     - NEC CDT109 (QFP120). This is some kind of CPU, the package looks a bit
70                    like a V60. The BIOS is tied directly to it.
71      RH-7500     - Casio RH-7500 5C315 (QFP208). This is the graphics generator chip.
72      RH-7501     - Casio RH-7501 5C350 (QFP64). This is probably the sound chip.
73      SH7021      - Hitachi HD6437021TE20 SuperH RISC Engine SH-2A CPU with 32k internal maskROM (TQFP100)
74                    The internal ROM (BIOS1) is not dumped. A SH-2A software programming manual is available here...
75                    http://documentation.renesas.com/eng/products/mpumcu/rej09b0051_sh2a.pdf
76      CXA1645M    - Sony CXA1645M RGB Encoder (RGB -> Composite Video) (SOIC24)
77      A1603C      - NEC uPA1603C Compound Field Effect Power Transistor Array (DIP16)
78      HM514260    - Hitachi HM514260 256k x 16 DRAM (SOJ40)
79      HM538123    - Hitachi HM538123 128k x8 multi-port Video DRAM with 256-word x8 serial access memory (SOJ40)
80      HM62256     - Hitachi HM62256 32k x8 SRAM (SOP28)
81      BA10339F    - Rohm BA10339F Quad Comparitor (SOIC14)
82      6379        - NEC uPD6379 2-channel 16-bit D/A convertor for digital audio signal demodulation (SOIC8)
83      15218       - Rohm BA15218 Dual High Slew Rate, Low Noise Operational Amplifier (SOIC8)
84 
85      Other
86      -----
87      SW1        - Reset Switch
88      SW301      - ON/OFF Slide Switch
89 
90 
91Carts
92-----
93There are reports of 11 existing carts.
94Only 6 are available so far.
95 
96XK-401: Anime Land
97XK-402: HARIHARI Seal Paradise
98XK-403: Dream Change
99XK-404: Nigaoe Artist
100XK-501: Wanwan Aijou Monogatari
101XK-502: PC Collection
102 
103The rest are not dumped yet.....
104 
105 
106Lupiton's Wonder Palette
107Magical Shop
108Chakra-kun no Omajinai Paradise
109XK-503: Little Romance
110XK-504: I want a room in Loopy Town
111 
112 
113 
114Inside the carts
115----------------
116 
117Carts 401 - 404:
118PCB 'JCM632-AN1M C'
1191x 16M maskROM (SOP44)
1201x 8k x8 SRAM (SOP28)
1211x 3V coin battery (CR2032)
122 
123Cart 501:
124PCB 'Z544-1 A240427-1'
1251x 16M maskROM (SOP44)
1261x 8k x8 SRAM (SOP28)
1271x OKI MSM6653A Voice Synthesis IC with 544Kbits internal maskROM (SOP24)
1281x Rohm BA15218 High Slew Rate, Low Noise, Dual Operational Amplifier (SOIC8)
1291x 74HC273 logic chip
1301x 3V coin battery (CR2032)
131 
132Cart 502:
133PCB 'Z545-1 A240570-1'
1341x 16M maskROM (SOP44)
1351x 32k x8 SRAM (SOP28)
1361x 74HC00 logic chip
1371x 3V coin battery (CR2032)
138 
139******************************************************************************/
140 
141#include "emu.h"
142#include "cpu/sh2/sh2.h"
143//#include "cpu/v60/v60.h"
144#include "devices/cartslot.h"
145 
146static UINT32 *bios_rom;
147 
148static VIDEO_START( casloopy )
149{
150 
151}
152 
153static VIDEO_UPDATE( casloopy )
154{
155   return 0;
156}
157 
158static ADDRESS_MAP_START( casloopy_map, ADDRESS_SPACE_PROGRAM, 32 )
159   AM_RANGE(0x00000000, 0x00000007) AM_RAM AM_BASE(&bios_rom)
160//   AM_RANGE(0x01000000, 0x017fffff) - i/o?
161   AM_RANGE(0x06000000, 0x061fffff) AM_ROM AM_REGION("cart",0) // wrong?
162   AM_RANGE(0x07fff000, 0x07ffffff) AM_RAM
163ADDRESS_MAP_END
164 
165#if 0
166static ADDRESS_MAP_START( casloopy_sub_map, ADDRESS_SPACE_PROGRAM, 16 )
167   AM_RANGE(0xf80000, 0xffffff) AM_ROM AM_REGION("subcpu",0)
168ADDRESS_MAP_END
169#endif
170 
171static INPUT_PORTS_START( casloopy )
172INPUT_PORTS_END
173 
174static MACHINE_RESET( casloopy )
175{
176   //cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, ASSERT_LINE); //halt the CPU until we find enough data to proceed
177 
178}
179 
180static MACHINE_CONFIG_START( casloopy, driver_device )
181 
182   /* basic machine hardware */
183   MDRV_CPU_ADD("maincpu",SH2,8000000)
184   MDRV_CPU_PROGRAM_MAP(casloopy_map)
185 
186//   MDRV_CPU_ADD("subcpu",V60,8000000)
187//   MDRV_CPU_PROGRAM_MAP(casloopy_sub_map)
188 
189   MDRV_MACHINE_RESET(casloopy)
190 
191   /* video hardware */
192   MDRV_SCREEN_ADD("screen", RASTER)
193   MDRV_SCREEN_REFRESH_RATE(60)
194   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
195   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
196   MDRV_SCREEN_SIZE(32*8, 32*8)
197   MDRV_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 2*8, 30*8-1)
198   MDRV_PALETTE_LENGTH(512)
199 
200   MDRV_VIDEO_START(casloopy)
201   MDRV_VIDEO_UPDATE(casloopy)
202 
203   MDRV_CARTSLOT_ADD("cart")
204   MDRV_CARTSLOT_EXTENSION_LIST("ic1")
205   MDRV_CARTSLOT_MANDATORY
206 
207   /* sound hardware */
208   MDRV_SPEAKER_STANDARD_MONO("mono")
209MACHINE_CONFIG_END
210 
211/***************************************************************************
212 
213  Game driver(s)
214 
215***************************************************************************/
216 
217ROM_START( casloopy )
218   ROM_REGION( 0x80000, "maincpu", ROMREGION_ERASEFF )
219   ROM_LOAD( "bios1", 0x0000, 0x4000, NO_DUMP )
220 
221   ROM_REGION( 0x80000, "subcpu", 0) //NEC CDT-109
222   ROM_LOAD( "bios2.lsi352", 0x0000, 0x80000, CRC(8f51fa17) SHA1(99f50be06b083fdb07e08f30b0b26d9037afc869) )
223 
224   ROM_REGION( 0x200000, "cart", 0 )
225   ROM_CART_LOAD("cart",    0x00000, 0x200000, ROM_NOMIRROR)
226ROM_END
227 
228static DRIVER_INIT( casloopy )
229{
230   /* load hand made bios data*/
231   bios_rom[0/4] = 0x6000964; //SPC
232   bios_rom[4/4] = 0xffffff0; //SSP
233}
234 
235GAME( 1995, casloopy,  0,   casloopy,  casloopy,  casloopy, ROT0, "Casio", "Loopy", GAME_NOT_WORKING | GAME_NO_SOUND )
1/*****************************************************************************
2
3   Casio Loopy (c) 1995 Casio
4
5   skeleton driver
6
7   TODO:
8   - Identify what actually is the NEC CDT-109 CPU, it should contain a program
9     controller for the thermal printer device
10
11   Note:
12   - just a placeholder for any HW discovery, until we decap/trojan the BIOS,
13     the idea is to understand the HW enough to extract the SH-1 internal BIOS
14     data via a trojan;
15
16===============================================================================
17
18Casio Loopy PCB Layout
19----------------------
20
21JCM631-MA1M C
22|---------------------------------------------------------|
23|    CB    CC              CD         CE       CF      CG |
24|--|                                                      |
25   |                                        BA10339F      |
26|--| 15218  |--|     CXA1645M                           CH|
27|           |  |                A1603C                    |
28|    15218  |  |                                          |
29|           |  |                                          |
30|BIOS.LSI352|  |                                          |
31|           |  |                      21MHz               |
32| |--------||  |   |------|                 SW1           |
33| |NEC     ||  |   |SH7021|      |----------|             |
34| |CDT109  ||CA|   |      |      |          |             |
35| |        ||  |   |------|      |CASIO     |             |
36| |--------||  |                 |RH-7500   |             |
37|           |  |                 |5C315     |          |--|
38| |-------| |  |                 |          |          |
39| |CASIO  | |  |                 |----------|          |--|
40| |RH-7501| |  |  HM514260                                |
41| |5C350  | |  |                               HM62256    |
42| |-------| |  |                                          |
43| 6379      |--|    SW301                      HM62256    /
44|--------|                        HM538123               /
45         |                                              /
46         |                                             /
47         |--------------------------------------------/
48
49Notes:
50      Connectors
51      ----------
52      CA - Cartridge connector
53      CB - Power Input connector
54      CC - Composite Video and Audio Out connector
55      CD - Printer Cassette Motor connector
56      CE - Printer Data connector
57      CF - Printer Head connector
58      CG - Paper Sensor connector
59      CH - Joystick connector
60      Connectors on the back of the main unit include RCA audio (left/right), RCA composite video,
61      24V DC power input and contrast knob.
62      On top of the main unit, there is a reset button, on/off slide switch, a big eject button, a
63      button to cut off stickers after they're printed, a button to open the hatch where the sticker
64      cassette is located and a red LED for power.
65
66      IC's
67      ----
68      BIOS2.LSI352- Hitachi HN62434 512k x8 (4MBit) maskROM (SOP40)
69      CDT-109     - NEC CDT109 (QFP120). This is some kind of CPU, the package looks a bit
70                    like a V60. The BIOS is tied directly to it.
71      RH-7500     - Casio RH-7500 5C315 (QFP208). This is the graphics generator chip.
72      RH-7501     - Casio RH-7501 5C350 (QFP64). This is probably the sound chip.
73      SH7021      - Hitachi HD6437021TE20 SuperH RISC Engine SH-2A CPU with 32k internal maskROM (TQFP100)
74                    The internal ROM (BIOS1) is not dumped. A SH-2A software programming manual is available here...
75                    http://documentation.renesas.com/eng/products/mpumcu/rej09b0051_sh2a.pdf
76      CXA1645M    - Sony CXA1645M RGB Encoder (RGB -> Composite Video) (SOIC24)
77      A1603C      - NEC uPA1603C Compound Field Effect Power Transistor Array (DIP16)
78      HM514260    - Hitachi HM514260 256k x 16 DRAM (SOJ40)
79      HM538123    - Hitachi HM538123 128k x8 multi-port Video DRAM with 256-word x8 serial access memory (SOJ40)
80      HM62256     - Hitachi HM62256 32k x8 SRAM (SOP28)
81      BA10339F    - Rohm BA10339F Quad Comparitor (SOIC14)
82      6379        - NEC uPD6379 2-channel 16-bit D/A convertor for digital audio signal demodulation (SOIC8)
83      15218       - Rohm BA15218 Dual High Slew Rate, Low Noise Operational Amplifier (SOIC8)
84
85      Other
86      -----
87      SW1        - Reset Switch
88      SW301      - ON/OFF Slide Switch
89
90
91Carts
92-----
93There are reports of 11 existing carts.
94Only 6 are available so far.
95
96XK-401: Anime Land
97XK-402: HARIHARI Seal Paradise
98XK-403: Dream Change
99XK-404: Nigaoe Artist
100XK-501: Wanwan Aijou Monogatari
101XK-502: PC Collection
102
103The rest are not dumped yet.....
104
105
106Lupiton's Wonder Palette
107Magical Shop
108Chakra-kun no Omajinai Paradise
109XK-503: Little Romance
110XK-504: I want a room in Loopy Town
111
112
113
114Inside the carts
115----------------
116
117Carts 401 - 404:
118PCB 'JCM632-AN1M C'
1191x 16M maskROM (SOP44)
1201x 8k x8 SRAM (SOP28)
1211x 3V coin battery (CR2032)
122
123Cart 501:
124PCB 'Z544-1 A240427-1'
1251x 16M maskROM (SOP44)
1261x 8k x8 SRAM (SOP28)
1271x OKI MSM6653A Voice Synthesis IC with 544Kbits internal maskROM (SOP24)
1281x Rohm BA15218 High Slew Rate, Low Noise, Dual Operational Amplifier (SOIC8)
1291x 74HC273 logic chip
1301x 3V coin battery (CR2032)
131
132Cart 502:
133PCB 'Z545-1 A240570-1'
1341x 16M maskROM (SOP44)
1351x 32k x8 SRAM (SOP28)
1361x 74HC00 logic chip
1371x 3V coin battery (CR2032)
138
139******************************************************************************/
140
141#include "emu.h"
142#include "cpu/sh2/sh2.h"
143//#include "cpu/v60/v60.h"
144#include "devices/cartslot.h"
145
146static UINT32 *bios_rom;
147
148static VIDEO_START( casloopy )
149{
150
151}
152
153static VIDEO_UPDATE( casloopy )
154{
155   return 0;
156}
157
158static ADDRESS_MAP_START( casloopy_map, ADDRESS_SPACE_PROGRAM, 32 )
159   AM_RANGE(0x00000000, 0x00000007) AM_RAM AM_BASE(&bios_rom)
160//   AM_RANGE(0x01000000, 0x017fffff) - i/o?
161   AM_RANGE(0x06000000, 0x061fffff) AM_ROM AM_REGION("cart",0) // wrong?
162   AM_RANGE(0x07fff000, 0x07ffffff) AM_RAM
163ADDRESS_MAP_END
164
165#if 0
166static ADDRESS_MAP_START( casloopy_sub_map, ADDRESS_SPACE_PROGRAM, 16 )
167   AM_RANGE(0xf80000, 0xffffff) AM_ROM AM_REGION("subcpu",0)
168ADDRESS_MAP_END
169#endif
170
171static INPUT_PORTS_START( casloopy )
172INPUT_PORTS_END
173
174static MACHINE_RESET( casloopy )
175{
176   //cputag_set_input_line(machine, "maincpu", INPUT_LINE_HALT, ASSERT_LINE); //halt the CPU until we find enough data to proceed
177
178}
179
180static MACHINE_CONFIG_START( casloopy, driver_device )
181
182   /* basic machine hardware */
183   MDRV_CPU_ADD("maincpu",SH2,8000000)
184   MDRV_CPU_PROGRAM_MAP(casloopy_map)
185
186//   MDRV_CPU_ADD("subcpu",V60,8000000)
187//   MDRV_CPU_PROGRAM_MAP(casloopy_sub_map)
188
189   MDRV_MACHINE_RESET(casloopy)
190
191   /* video hardware */
192   MDRV_SCREEN_ADD("screen", RASTER)
193   MDRV_SCREEN_REFRESH_RATE(60)
194   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
195   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
196   MDRV_SCREEN_SIZE(32*8, 32*8)
197   MDRV_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 2*8, 30*8-1)
198   MDRV_PALETTE_LENGTH(512)
199
200   MDRV_VIDEO_START(casloopy)
201   MDRV_VIDEO_UPDATE(casloopy)
202
203   MDRV_CARTSLOT_ADD("cart")
204   MDRV_CARTSLOT_EXTENSION_LIST("ic1")
205   MDRV_CARTSLOT_MANDATORY
206
207   /* sound hardware */
208   MDRV_SPEAKER_STANDARD_MONO("mono")
209MACHINE_CONFIG_END
210
211/***************************************************************************
212
213  Game driver(s)
214
215***************************************************************************/
216
217ROM_START( casloopy )
218   ROM_REGION( 0x80000, "maincpu", ROMREGION_ERASEFF )
219   ROM_LOAD( "bios1", 0x0000, 0x4000, NO_DUMP )
220
221   ROM_REGION( 0x80000, "subcpu", 0) //NEC CDT-109
222   ROM_LOAD( "bios2.lsi352", 0x0000, 0x80000, CRC(8f51fa17) SHA1(99f50be06b083fdb07e08f30b0b26d9037afc869) )
223
224   ROM_REGION( 0x200000, "cart", 0 )
225   ROM_CART_LOAD("cart",    0x00000, 0x200000, ROM_NOMIRROR)
226ROM_END
227
228static DRIVER_INIT( casloopy )
229{
230   /* load hand made bios data*/
231   bios_rom[0/4] = 0x6000964; //SPC
232   bios_rom[4/4] = 0xffffff0; //SSP
233}
234
235GAME( 1995, casloopy,  0,   casloopy,  casloopy,  casloopy, ROT0, "Casio", "Loopy", GAME_NOT_WORKING | GAME_NO_SOUND )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team