Previous 199869 Revisions Next

r32761 Wednesday 15th October, 2014 at 07:19:47 UTC by Miodrag Milanović
Cleanups and version bump
[hash]a7800.xml amiga_a3000.xml amiga_hardware.xml coleco.xml fm7_disk.xml fmtowns_cd.xml gamegear.xml gameking.xml gbcolor.xml intvecs.xml msx1_cart.xml nes.xml pencil2.xml psx.xml timex_dock.xml
[src]version.c
[src/emu]devcpu.c diimage.c machine.c webengine.c
[src/emu/bus/a2bus]a2corvus.c a2lang.c corvfdc01.c corvfdc02.c corvfdc02.h laser128.c mouse.c timemasterho.c
[src/emu/bus/a7800]a78_carts.h a78_slot.c a78_slot.h cpuwiz.c cpuwiz.h hiscore.c hiscore.h rom.c rom.h xboard.c xboard.h
[src/emu/bus/a800]a800_carts.h a800_slot.c a800_slot.h oss.c oss.h rom.c rom.h sparta.c sparta.h
[src/emu/bus/apf]rom.h slot.c slot.h
[src/emu/bus/arcadia]slot.c slot.h
[src/emu/bus/c64]dela_ep256.c rex_ep256.h
[src/emu/bus/centronics]digiblst.h
[src/emu/bus/chanf]rom.c rom.h slot.c slot.h
[src/emu/bus/cpc]amdrum.h symbfac2.c symbfac2.h
[src/emu/bus/crvision]rom.c rom.h slot.c slot.h
[src/emu/bus/gameboy]gb_slot.h mbc.h
[src/emu/bus/gba]gba_slot.h
[src/emu/bus/generic]carts.c ram.c ram.h rom.c rom.h slot.c slot.h
[src/emu/bus/intv]ecs.c ecs.h rom.c rom.h slot.c slot.h voice.h
[src/emu/bus/isa]sb16.c svga_trident.c trident.c
[src/emu/bus/megadrive]ggenie.c
[src/emu/bus/msx_cart]disk.c
[src/emu/bus/msx_slot]disk.c
[src/emu/bus/nes]disksys.c nes_slot.c nes_slot.h
[src/emu/bus/odyssey2]chess.h rom.c rom.h slot.c slot.h voice.c voice.h
[src/emu/bus/pet]cb2snd.c
[src/emu/bus/rs232]xvd701.c
[src/emu/bus/saturn]sat_slot.c
[src/emu/bus/scv]rom.h slot.c slot.h
[src/emu/bus/sega8]ccatch.c mgear.h rom.c sega8_slot.c sega8_slot.h
[src/emu/bus/sms_ctrl]graphic.c
[src/emu/bus/snes]snes_slot.h
[src/emu/bus/vboy]rom.h slot.c slot.h
[src/emu/bus/vc4000]rom.c rom.h slot.c slot.h
[src/emu/bus/vcs]compumat.c compumat.h dpc.c dpc.h rom.c rom.h scharger.c scharger.h vcs_slot.c vcs_slot.h
[src/emu/bus/vectrex]rom.h slot.c slot.h
[src/emu/bus/vic20]fe3.c fe3.h
[src/emu/bus/wswan]rom.c rom.h slot.c slot.h
[src/emu/cpu/dsp56k]dsp56k.c
[src/emu/cpu/hd61700]hd61700.c hd61700.h
[src/emu/cpu/i86]i186.c
[src/emu/cpu/mcs96]mcs96.c
[src/emu/cpu/mips]mips3drc.c
[src/emu/cpu/rsp]rsp.c rspdrc.c
[src/emu/cpu/sh4]sh4.c
[src/emu/cpu/tlcs90]tlcs90.c
[src/emu/cpu/tms32031]tms32031.h
[src/emu/cpu/tms32051]tms32051.c tms32051.h
[src/emu/cpu/tms34010]tms34010.c tms34010.h
[src/emu/cpu/tms7000]tms7000.c tms7000.h
[src/emu/debug]debugcpu.c
[src/emu/imagedev]floppy.c
[src/emu/machine]mb8421.c pit8253.c rp5h01.c smpc.c wozfdc.c
[src/emu/sound]flt_rc.h k053260.c k053260.h samples.c samples.h speaker.h ymf278b.c zsg2.c
[src/emu/ui]swlist.c ui.c
[src/emu/video]315_5124.c epic12.c upd7220.c vooddefs.h voodoo.c
[src/lib/formats]ap2_dsk.c dmk_dsk.c dmk_dsk.h mfi_dsk.c
[src/lib/web]mongoose.c mongoose.h
[src/mame]mame.lst mame.mak
[src/mame/audio]cclimber.h leland.c mario.c
[src/mame/drivers]20pacgal.c 4enraya.c 8080bw.c aces1.c alg.c aristmk4.c arkanoid.c atarisy4.c bartop52.c battlera.c bfm_sc1.c bfm_sc2.c bmcpokr.c btoads.c bublbobl.c calchase.c capr1.c caprcyc.c centiped.c chqflag.c coinmvga.c coolpool.c cops.c cps1.c cv1k.c dkong.c dlair.c dlair2.c dragrace.c fcrash.c foodf.c fuukifg2.c gaiden.c galaxian.c galpani3.c galpanic.c hikaru.c igs011.c igs017.c iqblock.c itech32.c jchan.c jclub2.c jeutel.c karnov.c legionna.c ltd.c macs.c mario.c maxaflex.c mazerbla.c megatech.c metro.c mgavegas.c midtunit.c midwunit.c midxunit.c midyunit.c model1.c model3.c mpu5hw.c namcops2.c namcos21.c naomi.c nmk16.c pacman.c peplus.c potgoldu.c punchout.c r2dx_v33.c raiden2.c rainbow.c rastersp.c redclash.c segac2.c segas18.c segas32.c segaybd.c simple_st0016.c skimaxx.c snesb.c snk6502.c snowbros.c speedbal.c speglsht.c splash.c srmp5.c st_mp100.c stv.c system16.c taito_z.c tatsumi.c tickee.c travrusa.c twinkle.c vamphalf.c vectrex.c warpsped.c xtheball.c
[src/mame/includes]8080bw.h artmagic.h bfm_sc45.h cinemat.h coolpool.h cosmic.h exterm.h fuukifg2.h fuukifg3.h harddriv.h jpmimpct.h konamigx.h legionna.h meadows.h micro3d.h midtunit.h midyunit.h model1.h model3.h namcos2.h polyplay.h raiden2.h simple_st0016.h snk.h splash.h sslam.h stv.h suna8.h suprnova.h taito_f3.h tatsumi.h thepit.h tnzs.h vectrex.h
[src/mame/layout]mgavegas.lay s11a.lay
[src/mame/machine]315_5296.c amiga.c asic65.c atari.c awboard.h inder_vid.c inder_vid.h kaneko_calc3.h kaneko_toybox.h konppc.c model1.c nmk004.c raiden2cop.c raiden2cop.h seicop.c seicop.h st0016.c st0016.h vectrex.c
[src/mame/video]antic.c antic.h battlera.c decmxc06.h dooyong.c fuukifg.c fuukifg.h fuukifg3.c gtia.c gtia.h k054156_k054157_k056832.c legionna.c mario.c model3.c seibuspi.c sknsspr.h skyfox.c snk.c taito_f3.c tc0480scp.c
[src/mess]mess.mak tiny.lst
[src/mess/audio]vc4000snd.h wswan_snd.h
[src/mess/drivers]a2600.c a7800.c aim65.c apf.c apple2.c apple2gs.c apple3.c atari400.c atarist.c atom.c bbcbc.c beta.c casloopy.c cc40.c cgenie.c channelf.c concept.c crvision.c electron.c ep64.c exelv.c fc100.c fm7.c gameking.c gamepock.c gba.c geniusiq.c gmaster.c ibmpcjr.c intv.c itt3030.c kyocera.c laser3k.c m5.c msx.c myvision.c nc.c nes.c ngp.c pc2000.c pc6001.c pc8401a.c pc9801.c pegasus.c pencil2.c pet.c pockstat.c pokemini.c pt68k4.c pv1000.c pv2000.c rx78.c scv.c socrates.c sorcerer.c spc1000.c specpls3.c spectrum.c studio2.c supracan.c sv8000.c svision.c thomson.c ti74.c timex.c tsispch.c tutor.c tvc.c uzebox.c vboy.c vc4000.c vii.c x07.c
[src/mess/includes]apple2.h atom.h concept.h electron.h intv.h radio86.h svi318.h
[src/mess/machine]aim65.c amigakbd.c amstrad.c apple2.c apple3.c bbc.c concept.c electron.c gamecom.c gamepock.c intv.c lynx.c nc.c nes.c primo.c svi318.c thomson.c vtech2.c wswan.c
[src/mess/tools/imgtool/modules]amiga.c
[src/mess/video]advision.c apple2.c apple3.c maria.c maria.h nes.c thomson.c
[src/osd/sdl]osdsdl.h sdlfile.c sdlptty_win32.c sdlsocket.c sdlsync_win32.c video.c
[src/osd/windows]vconv.c video.c video.h window.c window.h winos.c winos.h winsync.c winsync.h

trunk/hash/gameking.xml
r32760r32761
44<!-- dumps are not yet verified as good, the 3-in-1 internal ROM is not yet dumped -->
55
66<softwarelist name="gameking" description="TimeTop GameKing cartridges">
7 
7
88   <software name="2004">
99      <description>2004</description>
1010      <year>200?</year>
r32760r32761
2525            <rom name="adventure legend carlo.bin" size="0x20000" crc="7d61d215" sha1="741684b5379d4be732a98beace5d09f37ff19bbf" offset="0x00000" />
2626         </dataarea>
2727      </part>
28   </software> 
28   </software>
2929
3030   <software name="aries">
3131      <description>Aries</description>
r32760r32761
3636            <rom name="aries.bin" size="0x20000" crc="b854f1f2" sha1="1ad7a325aba2cf3593165b53e7ae3973388335f7" offset="0x00000" />
3737         </dataarea>
3838      </part>
39   </software> 
39   </software>
4040
4141   <software name="dinoadv">
4242      <description>Dino Adventure Legend</description>
r32760r32761
4747            <rom name="dino adventure legend.bin" size="0x20000" crc="2df0c1e6" sha1="df4b5dc80a758d9e3c9b00384e3099ad8331faad" offset="0x00000" />
4848         </dataarea>
4949      </part>
50   </software> 
50   </software>
5151
5252   <software name="duckman">
5353      <description>Duck Man</description>
r32760r32761
5858            <rom name="duck man.bin" size="0x20000" crc="9d12950a" sha1="376606097f66105d1a9e97e9793362f6f1e3b1a7" offset="0x00000" />
5959         </dataarea>
6060      </part>
61   </software> 
61   </software>
6262
6363   <software name="happybal">
6464      <description>Happy Ball</description>
r32760r32761
6969            <rom name="happy ball.bin" size="0x20000" crc="79d4e738" sha1="fc14712260ed6e3d6313055046546d37b7c838d2" offset="0x00000" />
7070         </dataarea>
7171      </part>
72   </software> 
72   </software>
7373
7474   <software name="happykil">
7575      <description>Happy Killer</description>
r32760r32761
8080            <rom name="happy killer.bin" size="0x20000" crc="9fd7ec65" sha1="705309829ee87689793c15be1f781d52471908d6" offset="0x00000" />
8181         </dataarea>
8282      </part>
83   </software> 
83   </software>
8484
8585   <software name="lanner">
8686      <description>Lanneret</description>
r32760r32761
9191            <rom name="lanneret.bin" size="0x20000" crc="249df6a5" sha1="bcf92ab85cc97ffe94d6a363a87b0b5de62c3c66" offset="0x00000" />
9292         </dataarea>
9393      </part>
94   </software>
94   </software>
9595
9696   <software name="penguin">
9797      <description>Penguin</description>
r32760r32761
102102            <rom name="penguin.bin" size="0x20000" crc="8c7b81c9" sha1="2f253b6ab6f6b9fc114ffca120d13df2e1e5f860" offset="0x00000" />
103103         </dataarea>
104104      </part>
105   </software>
106 
105   </software>
106
107107   <software name="popper">
108108      <description>Popper</description>
109109      <year>200?</year>
r32760r32761
113113            <rom name="popper.bin" size="0x20000" crc="a704617b" sha1="314931548578303e5e80a2bcb03c92472cb014d9" offset="0x00000" />
114114         </dataarea>
115115      </part>
116   </software>
116   </software>
117117
118118   <software name="sthero">
119119      <description>Street Hero</description>
r32760r32761
124124            <rom name="street hero.bin" size="0x20000" crc="9e0fe489" sha1="2c442126999e4b112a48e42a82dfa9ad9d6efa22" offset="0x00000" />
125125         </dataarea>
126126      </part>
127   </software>
128 
127   </software>
128
129129   <software name="smotor">
130130      <description>Supermotor</description>
131131      <year>200?</year>
r32760r32761
135135            <rom name="supermotor.bin" size="0x20000" crc="6290b94b" sha1="0c3011da35170241637907bb23d79355db38f343" offset="0x00000" />
136136         </dataarea>
137137      </part>
138   </software>
138   </software>
139139
140140   <software name="trojanl">
141141      <description>Trojan Legend</description>
r32760r32761
146146            <rom name="trojan legend.bin" size="0x20000" crc="7ce3975e" sha1="e925e4f28efc85ce69fb504b85a98a60883aa30d" offset="0x00000" />
147147         </dataarea>
148148      </part>
149   </software>
149   </software>
150150
151 
152151
152
153153</softwarelist>
trunk/hash/timex_dock.xml
r32760r32761
235235      </part>
236236   </software>
237237
238    <!-- TODO: add support for RAM in this cart (0xa000-0xffff) -->
238   <!-- TODO: add support for RAM in this cart (0xa000-0xffff) -->
239239   <software name="rwp32" supported="no">
240240      <description>rWP32</description>
241241      <year>19??</year>
trunk/hash/nes.xml
r32760r32761
3560135601         <feature name="pcb_model" value="NR8OV2-1" />
3560235602         <feature name="u1" value="U1 PRG" />
3560335603         <feature name="u2" value="U2 CHR" />
35604         <feature name="u3" value="CME-01" />   <!-- CIC clone? -->
35604         <feature name="u3" value="CME-01" />    <!-- CIC clone? -->
3560535605         <feature name="mirroring" value="vertical" />
3560635606         <dataarea name="prg" size="262144">
3560735607            <rom name="sup.adv.quest.u1" size="262144" crc="6a7bf037" sha1="22b430d7d4167f16751facd3515f7c8e1133a3d9" offset="00000" />
trunk/hash/gbcolor.xml
r32760r32761
2363923639  * CBA078 Shuma Baolong - Diannao Pian 数码暴龙-电脑篇
2364023640  * CBA079 Yingxiong Tianxia 英雄天下
2364123641  * CBA080 Sanguozhi Wudai 三国志五代
23642  * CBA083 Tai Kong Bao Bei 太空宝贝
23642  * CBA083 Tai Kong Bao Bei 太空宝贝
2364323643  * CBA085 Shu Ma Bao Bei - Huojian Bingtuan 数码宝贝-火箭兵团
2364423644  * CBA086 Shu Ma Bao Bei - Chao Mengmeng Fanji Zhan 数码宝贝-超梦梦反击战
2364523645  * CBA087 Shu Ma Bao Bei - Hai Zhi Shen 数码宝贝-海之神
trunk/hash/gamegear.xml
r32760r32761
768768   </software>
769769
770770<!-- some disassembling performed by Paul Baker suggests that this version is a prototype
771e.g.  the mapper control register at $fffc gets set to $80, you cannot switch characters
772on the pause screen, some messages are not displayed ("Sorry boys, no tickets, no show!"
773to explain why it is not possible to progress beyond a certain point in the game without
771e.g.  the mapper control register at $fffc gets set to $80, you cannot switch characters
772on the pause screen, some messages are not displayed ("Sorry boys, no tickets, no show!"
773to explain why it is not possible to progress beyond a certain point in the game without
774774a certain item) -->
775775   <software name="beavisp" cloneof="beavis">
776776      <description>Beavis and Butt-head (Prototype?)</description>
r32760r32761
72857285   </software>
72867286
72877287   <software name="soniclab">
7288    <!-- A final pre-release version of this same dump was found on a proto board with 4x128K sockets and no labels -->
7288   <!-- A final pre-release version of this same dump was found on a proto board with 4x128K sockets and no labels -->
72897289      <description>Sonic Labyrinth (World)</description>
72907290      <year>1995</year>
72917291      <publisher>Sega</publisher>
r32760r32761
75947594   </software>
75957595
75967596   <software name="sonic2d" cloneof="sonic2">
7597    <!-- This predates the final release and contains some different tiles & sprites compared to the final game -->
7597   <!-- This predates the final release and contains some different tiles & sprites compared to the final game -->
75987598      <description>Sonic The Hedgehog 2 (Rolling Demo)</description>
75997599      <year>1992</year>
76007600      <publisher>Sega</publisher>
r32760r32761
76097609         <feature name="batt" value="" />
76107610         <feature name="sw" value="ON = 1M / OFF = 256" />
76117611         <dataarea name="rom" size="262144">
7612            <!-- The ROM should be split in two halves -->
7612         <!-- The ROM should be split in two halves -->
76137613            <rom name="sonic_2_auto_demo_prototype_(1991-12-05)_tmr_sega_cb06_ffff.bin" size="262144" crc="15ad37a5" sha1="b780c6f059b48d1bb48ee2ad521552dab1487c88" offset="000000" />
76147614         </dataarea>
76157615      </part>
r32760r32761
86348634   </software>
86358635
86368636   <software name="tailsadv">
8637    <!-- A final pre-release version of this same dump was found on a proto board with 4x128K sockets and no labels -->
8637   <!-- A final pre-release version of this same dump was found on a proto board with 4x128K sockets and no labels -->
86388638      <description>Tails Adventures (World)</description>
86398639      <year>1995</year>
86408640      <publisher>Sega</publisher>
trunk/hash/a7800.xml
r32760r32761
13181318   </software>
13191319
13201320<!--
1321The code has some race conditions for NMIs (related to input readings)
1322and often fails to boot on real systems too. To successfully start the
1321The code has some race conditions for NMIs (related to input readings)
1322and often fails to boot on real systems too. To successfully start the
13231323game, you can keep pressed Button 1 during Atari logo (thanks to Mike
13241324Saarna for debugging the problem)
13251325-->
r32760r32761
23692369
23702370<!-- This version features a lot *LESS* sounds than the newer version:
23712371     e.g. no sound in bobsled ans ski jump games!
2372     Dump is confirmed from multiple carts, and it was probably used in
2372     Dump is confirmed from multiple carts, and it was probably used in
23732373     some erlier production run, until they found out the mistake and
23742374     replaced it with the complete version  -->
23752375   <software name="wingameso" cloneof="wingames">
trunk/hash/amiga_hardware.xml
r32760r32761
1212         <dataarea name="flop" size="901120">
1313            <rom name="370132_a570_utilities.adf" size="901120" crc="30097474" sha1="958b97674e3e99fb9b0e3117009f27d4e7a9220b" offset="0"/>
1414         </dataarea>
15      </part>   
15      </part>
1616   </software>
1717
1818   <software name="a590">
r32760r32761
2525         <dataarea name="flop" size="901120">
2626            <rom name="317734-01_a590_scsi.adf" size="901120" crc="a560a938" sha1="9c6136c6580779a948cd1c0b50cb229512af415c" offset="0"/>
2727         </dataarea>
28      </part>   
28      </part>
2929   </software>
3030
3131   <software name="a590_wd" cloneof="a590">
r32760r32761
4040         <dataarea name="flop" size="901120">
4141            <rom name="317734-03_a590_wd.adf" size="901120" crc="a88fda41" sha1="7424f8645e1903e3e4ec8bb824186868319be1f3" offset="0"/>
4242         </dataarea>
43      </part>   
43      </part>
4444   </software>
4545
4646   <software name="a590_seagate" cloneof="a590">
r32760r32761
5252         <dataarea name="flop" size="901120">
5353            <rom name="317734-04_a590_seagate.adf" size="901120" status="nodump" offset="0"/>
5454         </dataarea>
55      </part>   
55      </part>
5656   </software>
5757
5858   <software name="a590_ram">
r32760r32761
6464         <dataarea name="flop" size="901120">
6565            <rom name="317830-01_a590_ram_test.adf" size="901120" crc="6583d1d0" sha1="7779b825b8555956d341ff7e909ab71d89e2321c" offset="0"/>
6666         </dataarea>
67      </part>   
67      </part>
6868   </software>
6969
7070   <software name="a2024">
r32760r32761
7676         <dataarea name="flop" size="901120">
7777            <rom name="317809-01_a2024_jumpstart.adf" size="901120" crc="dad46588" sha1="30c2c1f1d98bd008b2c67f3b23480181935d4b01" offset="0"/>
7878         </dataarea>
79      </part>   
79      </part>
8080   </software>
8181
8282   <software name="a2091">
r32760r32761
9090         <dataarea name="flop" size="901120">
9191            <rom name="317806-04_a2091_setup.adf" size="901120" crc="122c8f93" sha1="603e106c1a44a209171610af8d48bc35ad31c9bc" offset="0"/>
9292         </dataarea>
93      </part>   
93      </part>
9494   </software>
9595
9696   <software name="a2058">
r32760r32761
102102         <dataarea name="flop" size="901120">
103103            <rom name="317719-01_a2058_ram_test.adf" size="901120" crc="5dba7fc3" sha1="76fbce4bef7df0f6042c85376d9bdfd4d4911e74" offset="0"/>
104104         </dataarea>
105      </part>   
105      </part>
106106   </software>
107107
108108   <software name="a2232">
r32760r32761
114114         <dataarea name="flop" size="901120">
115115            <rom name="317769-01_a2232_install.adf" size="901120" crc="3caa21b7" sha1="24f47f6f88712f046303b8812a598043440a5e6d" offset="0"/>
116116         </dataarea>
117      </part>   
117      </part>
118118   </software>
119119
120120   <software name="a2300">
r32760r32761
126126         <dataarea name="flop" size="901120">
127127            <rom name="317718-02_a2300_genlock_demo.adf" size="901120" crc="464ff0f6" sha1="26b94e8d52d35e2746b74610bb9b65eb2f899297" offset="0"/>
128128         </dataarea>
129      </part>   
129      </part>
130130   </software>
131131
132132   <software name="a2320">
r32760r32761
138138         <dataarea name="flop" size="901120">
139139            <rom name="317210-01_a2320_test_demo.adf" size="901120" crc="cff98aae" sha1="f46f7de0d908ed68abfd784d84b964cbce7dc503" offset="0"/>
140140         </dataarea>
141      </part>   
141      </part>
142142   </software>
143143
144144</softwarelist>
trunk/hash/fmtowns_cd.xml
r32760r32761
22<!DOCTYPE softwarelist SYSTEM "softwarelist.dtd">
33<softwarelist name="fmtowns" description="FM Towns CD-ROMs">
44<!-- skeleton test list -->
5 
6  <!-- works well on fmtmarty, keyboard seems to interfere with movements on fmtowns -->
5
6   <!-- works well on fmtmarty, keyboard seems to interfere with movements on fmtowns -->
77   <software name="raiden">
88      <description>Raiden Densetsu / Raiden Trad</description>
99      <year>1991</year>
trunk/hash/pencil2.xml
r32760r32761
22<!DOCTYPE softwarelist SYSTEM "softwarelist.dtd">
33<softwarelist name="pencil2" description="Hanimex Pencil II cartridges">
44
5<!--
5<!--
66
77Undumped known carts
88
r32760r32761
1616-->
1717
1818
19<!--
19<!--
2020
2121BASIC CART PEN-700 11-50332-31 Rev.0
2222SD-BASIC VERSION 2.0 FOR PENCIL II
trunk/hash/coleco.xml
r32760r32761
437437
438438   <software name="choplift">
439439      <!-- Choplifter (1984)(Coleco)[a].bin -->
440        <!-- Other available dump has corrupted gfx -->
440      <!-- Other available dump has corrupted gfx -->
441441      <description>Choplifter!</description>
442442      <year>1984</year>
443443      <publisher>Coleco / CBS</publisher>
r32760r32761
699699      <part name="cart" interface="coleco_cart">
700700         <dataarea name="rom" size="16384">
701701            <rom name="apshai.1" size="8192" crc="aa3ec181" sha1="7f79628c298ad6e410af82eeb33871869ad23de8" offset="0x0000" />
702                <!-- 2nd 8K chunk containes two copies of the same 4K data -->
702            <!-- 2nd 8K chunk containes two copies of the same 4K data -->
703703            <rom name="apshai.2" size="8192" crc="0e440f8f" sha1="09ffaeb79cdd8173882b77a8398a4e00ba826de1" offset="0x2000" />
704704         </dataarea>
705705      </part>
r32760r32761
22622262         <dataarea name="rom" size="24576">
22632263            <rom name="subroc.1" size="8192" crc="ff56b769" sha1="612a0abd13c4c7790890cbcb265a7fd786c7ec5c" offset="0x0000" />
22642264            <rom name="subroc.2" size="8192" crc="e9e60d4c" sha1="bfc94db65985b7a906099465a47d900f7a9a9106" offset="0x2000" />
2265                <!-- 3rd 8K chunk containes two copies of the same 4K data -->
2265            <!-- 3rd 8K chunk containes two copies of the same 4K data -->
22662266            <rom name="subroc.3" size="8192" crc="abe18f08" sha1="6ebdc68397c7b20dceba12ff754f88c955d5f98a" offset="0x4000" />
22672267         </dataarea>
22682268      </part>
r32760r32761
23692369   </software>
23702370
23712371   <software name="zaxxont" cloneof="zaxxon">
2372      <!-- The Taiwan Cooper cart contains a 32K ROM, the last 8K of which was found to
2373             contain 0x4000-0x4fff from Super Action Baseball followed by 0x1000-0x1fff
2374             from Meteoric Shower! -->
2372      <!-- The Taiwan Cooper cart contains a 32K ROM, the last 8K of which was found to
2373           contain 0x4000-0x4fff from Super Action Baseball followed by 0x1000-0x1fff
2374           from Meteoric Shower! -->
23752375      <description>Zaxxon (Taiwan Cooper)</description>
23762376      <year>198?</year>
23772377      <publisher>Taiwan Cooper</publisher>
trunk/hash/psx.xml
r32760r32761
704704      </part>
705705   </software>
706706
707  <!-- Redump.org sets -->
708 
709    <software name="raidendx" supported="yes"> <!-- Hamster re-release) -->
707   <!-- Redump.org sets -->
708
709   <software name="raidendx" supported="yes"> <!-- Hamster re-release) -->
710710      <description>Raiden DX (Japan, V1.1)</description>
711711      <year>199?</year>
712712      <publisher>Seibu / Hamster</publisher>
r32760r32761
717717         </diskarea>
718718      </part>
719719   </software>
720       
721    <software name="raidendxo" cloneof="raidendx" supported="yes"> <!-- original release) -->
720
721   <software name="raidendxo" cloneof="raidendx" supported="yes"> <!-- original release) -->
722722      <description>Raiden DX (Japan, V1.0)</description>
723723      <year>199?</year>
724724      <publisher>Seibu</publisher>
r32760r32761
729729         </diskarea>
730730      </part>
731731   </software>
732
732
733733   <software name="raidenpr" supported="yes">
734734      <description>Raiden Project (USA)</description>
735735      <year>199?</year>
r32760r32761
740740            <disk name="raiden project, the (usa)" sha1="cb1e4fae25d42e70fcb3eec5e1c1afcbdc5c2af3"/>
741741         </diskarea>
742742      </part>
743   </software> 
744 
745  <!-- this image doesn't boot, some kind of copy protection? could be bad -->
743   </software>
744
745   <!-- this image doesn't boot, some kind of copy protection? could be bad -->
746746   <software name="raidenprj" cloneof="raidenpr" supported="no">
747747      <description>Raiden Project (Japan)</description>
748748      <year>1995</year>
r32760r32761
753753            <disk name="raiden project (japan)" sha1="12ec8ee3117df1f95752dc65155a611f43725251"/>
754754         </diskarea>
755755      </part>
756   </software>
757 
756   </software>
757
758758   <!-- Images below are 'low-grade' ie not dumped to any specific standard, or verified to be of any specific quality, they could have bad gaps or audio tracks etc. -->
759759   <!-- They should be replaced with better quality images once said images are available (and verified to be the same versions) -->
760760
trunk/hash/amiga_a3000.xml
r32760r32761
3131         </dataarea>
3232      </part>
3333   </software>
34   
34
3535   <!-- A3000 Installation disks -->
36   
36
3737   <software name="a3kin203">
3838      <description>A3000 Install Disk 2.03</description>
3939      <year>1991</year>
r32760r32761
4444            <rom name="335603-04_install.adf" size="901120" crc="9a3cc466" sha1="b12a225890a3957bb01dcbfba44c046c19e19c8f" offset="0"/>
4545         </dataarea>
4646      </part>
47   </software>   
47   </software>
4848
4949   <!-- Amiga UNIX System V Release 4 -->
5050   <!-- TODO: Part numbers -->
51   
51
5252   <software name="amix11">
5353      <description>UNIX System V Release 4 Amiga Version 1.1</description>
5454      <year>1990</year>
trunk/hash/fm7_disk.xml
r32760r32761
16571657         </dataarea>
16581658      </part>
16591659   </software>
1660   
1660
16611661   <software name="mdos7_09">
16621662      <description>M-DOS7 Volume 9</description>
16631663      <year>19??</year>
trunk/hash/intvecs.xml
r32760r32761
100100         <dataarea name="D000" size="0x4000">
101101            <rom name="world series major league baseball.d0" size="0x4000" crc="839fa5c7" sha1="1ef12665079d1ce50bd2419b668344a08c9a872f" offset="0x0000"/>
102102         </dataarea>
103            <!-- two ROM pages -->
103         <!-- two ROM pages -->
104104         <dataarea name="F000" size="0x4000">
105105            <rom name="world series major league baseball (page 0).f0" size="0x2000" crc="a0f2fe49" sha1="fab397b49c5a7db53a501caea42fce169da5a31a" offset="0x0000"/>
106106            <rom name="world series major league baseball (page 1).f0" size="0x2000" crc="94d6b056" sha1="df2a8c950dd1c398db901a624c04322d2b4f2782" offset="0x2000"/>
trunk/hash/msx1_cart.xml
r32760r32761
1453614536         <feature name="mapper" value="NOMAPPER" />
1453714537         <dataarea name="rom" size="131072">
1453814538            <!--
14539               20140725:
14540               There are 3 versions of this rom floating around:
14541               930eae7057af1652abae794072b296a59decd61b - a "dirty" dump; it seems to be a direct memory copy made on an MSX and contains RAM contents at 3000-3FFF and 7000-7FFF
14542               a45692849acf29ddb653707a62747985439f6d4f - RAM areas are set to FFs
14543               36d47cf70618fdb460f97a8ceb75013ec4529063 - A dump made using an eeprom reader. This dump differs one bit with the dump above (offset 8a49, bit 3)
14544               By looking the code it is not yet possible to say which one is 100% correct, so marking it as baddump for the moment.
14539                20140725:
14540                There are 3 versions of this rom floating around:
14541                930eae7057af1652abae794072b296a59decd61b - a "dirty" dump; it seems to be a direct memory copy made on an MSX and contains RAM contents at 3000-3FFF and 7000-7FFF
14542                a45692849acf29ddb653707a62747985439f6d4f - RAM areas are set to FFs
14543                36d47cf70618fdb460f97a8ceb75013ec4529063 - A dump made using an eeprom reader. This dump differs one bit with the dump above (offset 8a49, bit 3)
14544                By looking the code it is not yet possible to say which one is 100% correct, so marking it as baddump for the moment.
1454514545            -->
1454614546            <rom name="msx audio (japan) (fs-ca1) (program).rom" size="131072" crc="78584d2e" sha1="a45692849acf29ddb653707a62747985439f6d4f" status="baddump" offset="0" />
1454714547         </dataarea>
r32760r32761
1710917109      </part>
1711017110      <!-- The package came with a copy of MSX-DOS -->
1711117111<!--
17112      <part name="flop1" interface="floppy_3_5">
17113      </part>
17112        <part name="flop1" interface="floppy_3_5">
17113        </part>
1711417114-->
1711517115   </software>
1711617116
r32760r32761
1712617126         </dataarea>
1712717127      </part>
1712817128<!--
17129      The floppy drive was most likely bundled with a copy of MSX-DOS, but we are not 100% sure yet
17130      <part name="flop1" interface="floppy_3_5">
17131      </part>
17129        The floppy drive was most likely bundled with a copy of MSX-DOS, but we are not 100% sure yet
17130        <part name="flop1" interface="floppy_3_5">
17131        </part>
1713217132-->
1713317133   </software>
1713417134
trunk/src/osd/windows/video.h
r32760r32761
3838   void refresh();
3939   float get_aspect();
4040   void set_aspect(float a) { aspect = a; }
41   
41
4242   win_monitor_info  * next;                   // pointer to next monitor in list
4343   HMONITOR            handle;                 // handle to the monitor
44   MONITORINFOEX       info;                   // most recently retrieved info   
45private:   
44   MONITORINFOEX       info;                   // most recently retrieved info
45private:
4646   float               aspect;                 // computed/configured aspect ratio of the physical device
4747   int                 reqwidth;               // requested width for this monitor
4848   int                 reqheight;              // requested height for this monitor
trunk/src/osd/windows/winos.c
r32760r32761
3232char *osd_getenv(const char *name)
3333{
3434   return getenv(name);
35}
No newline at end of file
35}
trunk/src/osd/windows/winos.h
r32760r32761
2929
3030        pointer to value
3131-----------------------------------------------------------------------------*/
32char *osd_getenv(const char *name);
No newline at end of file
32char *osd_getenv(const char *name);
trunk/src/osd/windows/window.c
r32760r32761
245245
246246   // set up the window list
247247   last_window_ptr = &win_window_list;
248   
248
249249   return true;
250250}
251251
r32760r32761
313313      m_target(NULL),
314314      m_targetview(0),
315315      m_targetorient(0),
316      m_primlist(NULL),       
316      m_primlist(NULL),
317317      m_lastclicktime(0),
318318      m_lastclickx(0),
319319      m_lastclicky(0),
r32760r32761
321321      m_machine(machine)
322322{
323323   memset(m_title,0,sizeof(m_title));
324   m_non_fullscreen_bounds.left = 0; 
325   m_non_fullscreen_bounds.top = 0; 
326   m_non_fullscreen_bounds.right  = 0; 
324   m_non_fullscreen_bounds.left = 0;
325   m_non_fullscreen_bounds.top = 0;
326   m_non_fullscreen_bounds.right  = 0;
327327   m_non_fullscreen_bounds.bottom = 0;
328328}
329329
r32760r32761
331331{
332332}
333333
334   
334
335335//============================================================
336336//  winwindow_process_events_periodic
337337//  (main thread)
trunk/src/osd/windows/window.h
r32760r32761
3636{
3737public:
3838   win_window_info(running_machine &machine);
39   virtual ~win_window_info();     
39   virtual ~win_window_info();
4040
4141   running_machine &machine() const { return m_machine; }
4242
4343   void update();
44   
44
4545   win_window_info *   m_next;
4646   volatile int        m_init_state;
4747
trunk/src/osd/windows/winsync.c
r32760r32761
373373   DeleteCriticalSection(&lock->section);
374374#endif
375375   free(lock);
376}
No newline at end of file
376}
trunk/src/osd/windows/vconv.c
r32760r32761
9999   { 0,        "c++",                      "" },
100100   { 0,        "-flto",                    "/GL" },
101101   { 0,        "-fno-optimize-sibling-calls", "" },
102   { VS2005,   "-fopenmp",                "/openmp" },
102   { VS2005,   "-fopenmp",                     "/openmp" },
103103   { 0 }
104104};
105105
trunk/src/osd/windows/winsync.h
r32760r32761
197197
198198void osd_scalable_lock_free(osd_scalable_lock *lock);
199199
200#endif  /* __WINSYNC__ */
No newline at end of file
200#endif  /* __WINSYNC__ */
trunk/src/osd/windows/video.c
r32760r32761
9797void windows_osd_interface::video_exit()
9898{
9999   window_exit();
100   
100
101101   // free all of our monitor information
102102   while (win_monitor_list != NULL)
103103   {
r32760r32761
111111
112112win_monitor_info::win_monitor_info()
113113   : next(NULL),
114     handle(NULL),
115     aspect(0.0f),
116     reqwidth(0),
117     reqheight(0)
114      handle(NULL),
115      aspect(0.0f),
116      reqwidth(0),
117      reqheight(0)
118118{
119119}
120120
trunk/src/osd/sdl/sdlsync_win32.c
r32760r32761
99//
1010//============================================================
1111
12#include "../windows/winsync.c"
No newline at end of file
12#include "../windows/winsync.c"
trunk/src/osd/sdl/sdlsocket.c
r32760r32761
192192   osd_free(file);
193193   return FILERR_NONE;
194194}
195#endif
No newline at end of file
195#endif
trunk/src/osd/sdl/osdsdl.h
r32760r32761
8383
8484#define SDLOPTVAL_OPENGL                "opengl"
8585#define SDLOPTVAL_SOFT                  "soft"
86#define SDLOPTVAL_SDL2ACCEL            "accel"
86#define SDLOPTVAL_SDL2ACCEL             "accel"
8787
8888#define SDLMAME_LED(x)                  "led" #x
8989
trunk/src/osd/sdl/video.c
r32760r32761
134134void sdl_osd_interface::video_exit()
135135{
136136   window_exit();
137   
137
138138   // free all of our monitor information
139139   while (sdl_monitor_list != NULL)
140140   {
trunk/src/osd/sdl/sdlfile.c
r32760r32761
499499
500500   return result;
501501}
502#endif
No newline at end of file
502#endif
trunk/src/osd/sdl/sdlptty_win32.c
r32760r32761
1111//============================================================
1212
1313#include "../windows/winptty.c"
14
trunk/src/emu/debug/debugcpu.c
r32760r32761
19311931         machine.debug_view().flush_osd_updates();
19321932
19331933         machine.manager().web()->serve();
1934         
1934
19351935         // clear the memory modified flag and wait
19361936         global->memory_modified = false;
19371937         if (machine.debug_flags & DEBUG_FLAG_OSD_ENABLED)
trunk/src/emu/cpu/tms7000/tms7000.c
r32760r32761
899899{
900900   // init/zerofill
901901   m_control = 0;
902   
902
903903   // register for savestates
904904   save_item(NAME(m_control));
905905
r32760r32761
910910{
911911   m_control = 0;
912912   m_io->write_byte(TMS7000_PORTE, 0xff);
913   
913
914914   tms7000_device::device_reset();
915915}
916916
trunk/src/emu/cpu/tms7000/tms7000.h
r32760r32761
313313
314314   DECLARE_READ8_MEMBER(control_r);
315315   DECLARE_WRITE8_MEMBER(control_w);
316   
316
317317   DECLARE_READ8_MEMBER(dockbus_status_r);
318318   DECLARE_WRITE8_MEMBER(dockbus_status_w);
319319   DECLARE_READ8_MEMBER(dockbus_data_r);
trunk/src/emu/cpu/hd61700/hd61700.c
r32760r32761
138138   m_kb_write_cb.resolve_safe();
139139   m_port_read_cb.resolve_safe(0xff);
140140   m_port_write_cb.resolve_safe();
141   
141
142142   // save state
143143   save_item(NAME(m_ppc));
144144   save_item(NAME(m_curpc));
trunk/src/emu/cpu/hd61700/hd61700.h
r32760r32761
7676   template<class _Object> static devcb_base &set_kb_read_callback(device_t &device, _Object object) { return downcast<hd61700_cpu_device &>(device).m_kb_read_cb.set_callback(object); }
7777   template<class _Object> static devcb_base &set_port_write_callback(device_t &device, _Object object) { return downcast<hd61700_cpu_device &>(device).m_port_write_cb.set_callback(object); }
7878   template<class _Object> static devcb_base &set_port_read_callback(device_t &device, _Object object) { return downcast<hd61700_cpu_device &>(device).m_port_read_cb.set_callback(object); }
79   
79
8080protected:
8181   // device-level overrides
8282   virtual void device_start();
r32760r32761
155155   devcb_write8    m_kb_write_cb;      //keyboard matrix write
156156   devcb_read8     m_port_read_cb;     //8 bit port read
157157   devcb_write8    m_port_write_cb;    //8 bit port write
158   
158
159159   // flag definitions
160160   static const int FLAG_Z     = 0x80;
161161   static const int FLAG_C     = 0x40;
trunk/src/emu/cpu/tms32051/tms32051.c
r32760r32761
4545 **************************************************************************/
4646
4747static ADDRESS_MAP_START( internal_pgm, AS_PROGRAM, 16, tms32051_device )
48//   AM_RANGE(0x0000, 0x1fff) AM_ROM                         // ROM          TODO: is off-chip if MP/_MC = 0
48//  AM_RANGE(0x0000, 0x1fff) AM_ROM                         // ROM          TODO: is off-chip if MP/_MC = 0
4949   AM_RANGE(0x2000, 0x23ff) AM_RAM AM_SHARE("saram")       // SARAM        TODO: is off-chip if RAM bit = 0
5050   AM_RANGE(0xfe00, 0xffff) AM_RAM AM_SHARE("daram_b0")    // DARAM B0     TODO: is off-chip if CNF = 0
5151ADDRESS_MAP_END
r32760r32761
406406      case 0x1d: return m_cber2;
407407      case 0x1e: return m_cbcr;
408408      case 0x1f: return m_bmar;
409     
409
410410      case 0x20: return m_serial.drr;
411411      case 0x21: return m_serial.dxr;
412412
trunk/src/emu/cpu/tms32051/tms32051.h
r32760r32761
134134      UINT16 tim;
135135      UINT16 prd;
136136   } m_timer;
137   
137
138138   struct
139139   {
140140      UINT16 drr;
trunk/src/emu/cpu/mcs96/mcs96.c
r32760r32761
112112{
113113   internal_update(total_cycles());
114114
115   //   if(inst_substate)
116   //      do_exec_partial();
115   //  if(inst_substate)
116   //      do_exec_partial();
117117
118118   while(icount > 0) {
119119      while(icount > bcount) {
r32760r32761
125125      }
126126      while(bcount && icount <= bcount)
127127         internal_update(total_cycles() + icount - bcount);
128      //      if(inst_substate)
129      //         do_exec_partial();
128      //      if(inst_substate)
129      //          do_exec_partial();
130130   }
131131}
132132
trunk/src/emu/cpu/mips/mips3drc.c
r32760r32761
24832483void mips3_device::generate_badcop(drcuml_block *block, const int cop)
24842484{
24852485   UML_TEST(block, CPR032(COP0_Status), SR_COP0 << cop);               // test    [Status], SR_COP0 << cop
2486   UML_EXHc(block, COND_Z, *m_exception[EXCEPTION_BADCOP], cop);      // exh     badcop,cop,Z
2486   UML_EXHc(block, COND_Z, *m_exception[EXCEPTION_BADCOP], cop);       // exh     badcop,cop,Z
24872487}
24882488
24892489/*-------------------------------------------------------------------------
trunk/src/emu/cpu/dsp56k/dsp56k.c
r32760r32761
106106 *  Internal Memory Maps
107107 ****************************************************************************/
108108static ADDRESS_MAP_START( dsp56156_program_map, AS_PROGRAM, 16, dsp56k_device )
109    AM_RANGE(0x0000,0x07ff) AM_READWRITE(program_r, program_w)   /* 1-5 */
109   AM_RANGE(0x0000,0x07ff) AM_READWRITE(program_r, program_w)   /* 1-5 */
110110//  AM_RANGE(0x2f00,0x2fff) AM_ROM                              /* 1-5 PROM reserved memory.  Is this the right spot for it? */
111111ADDRESS_MAP_END
112112
113113static ADDRESS_MAP_START( dsp56156_x_data_map, AS_DATA, 16, dsp56k_device )
114    AM_RANGE(0x0000,0x07ff) AM_RAM                              /* 1-5 */
115    AM_RANGE(0xffc0,0xffff) AM_READWRITE(peripheral_register_r, peripheral_register_w)   /* 1-5 On-chip peripheral registers memory mapped in data space */
114   AM_RANGE(0x0000,0x07ff) AM_RAM                              /* 1-5 */
115   AM_RANGE(0xffc0,0xffff) AM_READWRITE(peripheral_register_r, peripheral_register_w)   /* 1-5 On-chip peripheral registers memory mapped in data space */
116116ADDRESS_MAP_END
117117
118118
r32760r32761
288288   save_item(NAME(m_dsp56k_core.HI.trxh));
289289   save_item(NAME(m_dsp56k_core.HI.trxl));
290290   save_item(NAME(m_dsp56k_core.HI.bootstrap_offset));
291   
291
292292   save_item(NAME(m_dsp56k_core.peripheral_ram));
293293   save_item(NAME(m_dsp56k_core.program_ram));
294294
r32760r32761
514514   extern CPU_DISASSEMBLE( dsp56k );
515515   return CPU_DISASSEMBLE_NAME(dsp56k)(this, buffer, pc, oprom, opram, options);
516516}
517
trunk/src/emu/cpu/tlcs90/tlcs90.c
r32760r32761
24152415   if ( (m_internal_registers[ T90_TRUN - T90_IOBASE ] & (1 << i)) == 0 )
24162416      return;
24172417
2418  timer_fired = 0;
2418   timer_fired = 0;
24192419
24202420   mode = (m_internal_registers[ T90_TMOD - T90_IOBASE ] >> ((i & ~1) + 2)) & 0x03;
24212421   // Match
2422  switch (mode)
2423  {
2424    case 0x02: // 8bit PPG
2425    case 0x03: // 8bit PWM
2426      logerror("CPU Timer %d expired with unhandled mode %d\n", i, mode);
2427      // TODO: hmm...
2428    case 0x00: // 8bit
2429      m_timer_value[i]++;
2430      if ( m_timer_value[i] == m_internal_registers[ T90_TREG0+i - T90_IOBASE ] )
2431        timer_fired = 1;
2432      break;
2422   switch (mode)
2423   {
2424   case 0x02: // 8bit PPG
2425   case 0x03: // 8bit PWM
2426      logerror("CPU Timer %d expired with unhandled mode %d\n", i, mode);
2427      // TODO: hmm...
2428   case 0x00: // 8bit
2429      m_timer_value[i]++;
2430      if ( m_timer_value[i] == m_internal_registers[ T90_TREG0+i - T90_IOBASE ] )
2431      timer_fired = 1;
2432      break;
24332433
2434    case 0x01: // 16bit
2435      if(i & 1)
2436        break;
2437      m_timer_value[i]++;
2438      if(m_timer_value[i] == 0) m_timer_value[i+1]++;
2439      if(m_timer_value[i+1] == m_internal_registers[ T90_TREG0+i+1 - T90_IOBASE ])
2440        if(m_timer_value[i] == m_internal_registers[ T90_TREG0+i - T90_IOBASE ])
2441          timer_fired = 1;
2442      break;
2443  }
2434   case 0x01: // 16bit
2435      if(i & 1)
2436      break;
2437      m_timer_value[i]++;
2438      if(m_timer_value[i] == 0) m_timer_value[i+1]++;
2439      if(m_timer_value[i+1] == m_internal_registers[ T90_TREG0+i+1 - T90_IOBASE ])
2440      if(m_timer_value[i] == m_internal_registers[ T90_TREG0+i - T90_IOBASE ])
2441         timer_fired = 1;
2442      break;
2443   }
24442444
2445  if(timer_fired) {
2446    // special stuff handling
2447    switch(mode) {
2448      case 0x02: // 8bit PPG
2449      case 0x03: // 8bit PWM
2450        // TODO: hmm...
2451      case 0x00: // 8bit
2452        if(i & 1)
2453          break;
2454        if ( (m_internal_registers[ T90_TCLK - T90_IOBASE ] & (0x0C << (i * 2))) == 0 ) // T0/T1 match signal clocks T1/T3
2455          t90_timer_callback(ptr, i+1);
2456        break;
2457      case 0x01: // 16bit, only can happen for i=0,2
2458        m_timer_value[i+1] = 0;
2459        set_irq_line(INTT0 + i+1, 1);
2460        break;
2461    }
2462    // regular handling
2463    m_timer_value[i] = 0;
2464    set_irq_line(INTT0 + i, 1);
2465  }
2445   if(timer_fired) {
2446   // special stuff handling
2447   switch(mode) {
2448      case 0x02: // 8bit PPG
2449      case 0x03: // 8bit PWM
2450      // TODO: hmm...
2451      case 0x00: // 8bit
2452      if(i & 1)
2453         break;
2454      if ( (m_internal_registers[ T90_TCLK - T90_IOBASE ] & (0x0C << (i * 2))) == 0 ) // T0/T1 match signal clocks T1/T3
2455         t90_timer_callback(ptr, i+1);
2456      break;
2457      case 0x01: // 16bit, only can happen for i=0,2
2458      m_timer_value[i+1] = 0;
2459      set_irq_line(INTT0 + i+1, 1);
2460      break;
2461   }
2462   // regular handling
2463   m_timer_value[i] = 0;
2464   set_irq_line(INTT0 + i, 1);
2465   }
24662466}
24672467
24682468TIMER_CALLBACK_MEMBER( tlcs90_device::t90_timer4_callback )
trunk/src/emu/cpu/i86/i186.c
r32760r32761
594594   save_item(NAME(m_mem.middle_size));
595595   save_item(NAME(m_mem.peripheral));
596596   save_item(NAME(m_reloc));
597   
597
598598   // zerofill
599599   memset(m_timer, 0, sizeof(m_timer));
600600   memset(m_dma, 0, sizeof(m_dma));
601601   memset(&m_intr, 0, sizeof(intr_state));
602602   memset(&m_mem, 0, sizeof(mem_state));
603603   m_reloc = 0;
604   
604
605605   m_timer[0].int_timer = timer_alloc(TIMER_INT0);
606606   m_timer[1].int_timer = timer_alloc(TIMER_INT1);
607607   m_timer[2].int_timer = timer_alloc(TIMER_INT2);
r32760r32761
633633   m_intr.poll_status      = 0x0000;
634634   m_intr.ext_state        = 0x00;
635635   m_reloc = 0x20ff;
636   
636
637637   for (int i = 0; i < ARRAY_LENGTH(m_dma); i++)
638638   {
639639      m_dma[i].drq_state = false;
r32760r32761
14771477WRITE16_MEMBER(i80186_cpu_device::internal_port_w)
14781478{
14791479   int which;
1480   
1480
14811481   switch (offset)
14821482   {
14831483      case 0x11:
trunk/src/emu/cpu/tms34010/tms34010.c
r32760r32761
3737   , m_program_config("program", ENDIANNESS_LITTLE, 16, 32, 3)
3838   , m_reset_deferred(FALSE)
3939   , m_pixclock(0)
40   , m_pixperclock(0)     
40   , m_pixperclock(0)
4141   , m_output_int_cb(*this)
4242{
4343}
r32760r32761
574574   m_output_int_cb.resolve();
575575   m_to_shiftreg_cb.bind_relative_to(*owner());
576576   m_from_shiftreg_cb.bind_relative_to(*owner());
577   
577
578578   m_external_host_access = FALSE;
579579
580580   m_program = &space(AS_PROGRAM);
trunk/src/emu/cpu/tms34010/tms34010.h
r32760r32761
190190
191191#define MCFG_TMS340X0_HALT_ON_RESET(_value) \
192192   tms340x0_device::set_halt_on_reset(*device, _value);
193   
193
194194#define MCFG_TMS340X0_PIXEL_CLOCK(_value) \
195195   tms340x0_device::set_pixel_clock(*device, _value);
196   
196
197197#define MCFG_TMS340X0_PIXELS_PER_CLOCK(_value) \
198198   tms340x0_device::set_pixels_per_clock(*device, _value);
199   
199
200200typedef device_delegate<void (screen_device &screen, bitmap_ind16 &bitmap, int scanline, const tms34010_display_params *params)> scanline_ind16_cb_delegate;
201201
202202#define TMS340X0_SCANLINE_IND16_CB_MEMBER(_name) void _name(screen_device &screen, bitmap_ind16 &bitmap, int scanline, const tms34010_display_params *params)
203   
203
204204#define MCFG_TMS340X0_SCANLINE_IND16_CB(_class, _method) \
205    tms340x0_device::set_scanline_ind16_callback(*device, scanline_ind16_cb_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
206   
205      tms340x0_device::set_scanline_ind16_callback(*device, scanline_ind16_cb_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
207206
207
208208typedef device_delegate<void (screen_device &screen, bitmap_rgb32 &bitmap, int scanline, const tms34010_display_params *params)> scanline_rgb32_cb_delegate;
209209
210210#define TMS340X0_SCANLINE_RGB32_CB_MEMBER(_name) void _name(screen_device &screen, bitmap_rgb32 &bitmap, int scanline, const tms34010_display_params *params)
211211
212212#define MCFG_TMS340X0_SCANLINE_RGB32_CB(_class, _method) \
213    tms340x0_device::set_scanline_rgb32_callback(*device, scanline_rgb32_cb_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
213      tms340x0_device::set_scanline_rgb32_callback(*device, scanline_rgb32_cb_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
214214
215   
215
216216#define MCFG_TMS340X0_OUTPUT_INT_CB(_devcb) \
217217   devcb = &tms340x0_device::set_output_int_callback(*device, DEVCB_##_devcb);
218218
r32760r32761
220220typedef device_delegate<void (address_space &space, offs_t address, UINT16 *shiftreg)> to_shiftreg_cb_delegate;
221221
222222#define TMS340X0_TO_SHIFTREG_CB_MEMBER(_name) void _name(address_space &space, offs_t address, UINT16 *shiftreg)
223   
223
224224#define MCFG_TMS340X0_TO_SHIFTREG_CB(_class, _method) \
225    tms340x0_device::set_to_shiftreg_callback(*device, to_shiftreg_cb_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
226   
225      tms340x0_device::set_to_shiftreg_callback(*device, to_shiftreg_cb_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
227226
227
228228typedef device_delegate<void (address_space &space, offs_t address, UINT16 *shiftreg)> from_shiftreg_cb_delegate;
229229
230230#define TMS340X0_FROM_SHIFTREG_CB_MEMBER(_name) void _name(address_space &space, offs_t address, UINT16 *shiftreg)
231231
232232#define MCFG_TMS340X0_FROM_SHIFTREG_CB(_class, _method) \
233    tms340x0_device::set_from_shiftreg_callback(*device, from_shiftreg_cb_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
233      tms340x0_device::set_from_shiftreg_callback(*device, from_shiftreg_cb_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
234234
235   
235
236236class tms340x0_device : public cpu_device,
237                  public device_video_interface         
237                  public device_video_interface
238238{
239239public:
240240   // construction/destruction
r32760r32761
337337   int     m_pixperclock;                        /* pixels per clock */
338338   emu_timer *m_scantimer;
339339   int m_icount;
340   
341   scanline_ind16_cb_delegate m_scanline_ind16_cb;
342   scanline_rgb32_cb_delegate m_scanline_rgb32_cb;
340
341   scanline_ind16_cb_delegate m_scanline_ind16_cb;
342   scanline_rgb32_cb_delegate m_scanline_rgb32_cb;
343343   devcb_write_line m_output_int_cb; /* output interrupt callback */
344344   to_shiftreg_cb_delegate m_to_shiftreg_cb;  /* shift register write */
345345   from_shiftreg_cb_delegate m_from_shiftreg_cb; /* shift register read */
trunk/src/emu/cpu/tms32031/tms32031.h
r32760r32761
775775   devcb_write8        m_xf0_cb;
776776   devcb_write8        m_xf1_cb;
777777   devcb_write8        m_iack_cb;
778   
778
779779   // tables
780780   static void (tms3203x_device::*const s_tms32031ops[])(UINT32 op);
781781   static UINT32 (tms3203x_device::*const s_indirect_d[0x20])(UINT32, UINT8);
trunk/src/emu/cpu/rsp/rspdrc.c
r32760r32761
90299029   block->append_comment("%08X: %s", pc, buffer);                                  // comment
90309030#endif
90319031}
9032
trunk/src/emu/cpu/rsp/rsp.c
r32760r32761
466466      m_regmap[regnum] = (regnum == 0) ? uml::parameter(0) : uml::parameter::make_memory(&m_rsp_state->r[regnum]);
467467   }
468468
469    /*
470    drcbe_info beinfo;
471    m_drcuml->get_backend_info(beinfo);
472    if (beinfo.direct_iregs > 2)
473    {
474        m_regmap[30] = I2;
475    }
476    if (beinfo.direct_iregs > 3)
477    {
478        m_regmap[31] = I3;
479    }
480    if (beinfo.direct_iregs > 4)
481    {
482        m_regmap[2] = I4;
483    }
484    if (beinfo.direct_iregs > 5)
485    {
486        m_regmap[3] = I5;
487    }
488    if (beinfo.direct_iregs > 6)
489    {
490        m_regmap[4] = I6;
491    }
492    */
469   /*
470   drcbe_info beinfo;
471   m_drcuml->get_backend_info(beinfo);
472   if (beinfo.direct_iregs > 2)
473   {
474       m_regmap[30] = I2;
475   }
476   if (beinfo.direct_iregs > 3)
477   {
478       m_regmap[31] = I3;
479   }
480   if (beinfo.direct_iregs > 4)
481   {
482       m_regmap[2] = I4;
483   }
484   if (beinfo.direct_iregs > 5)
485   {
486       m_regmap[3] = I5;
487   }
488   if (beinfo.direct_iregs > 6)
489   {
490       m_regmap[4] = I6;
491   }
492   */
493493
494494   /* mark the cache dirty so it is updated on next execute */
495495   m_cache_dirty = TRUE;
r32760r32761
870870   }
871871   if (m_drcfe )
872872   {
873       auto_free(machine(), m_drcfe);
873      auto_free(machine(), m_drcfe);
874874   }
875875}
876876
r32760r32761
35653565
35663566   }
35673567}
3568
3569
trunk/src/emu/cpu/sh4/sh4.c
r32760r32761
30803080
30813081inline void sh34_base_device::execute_one_0000(const UINT16 opcode)
30823082{
3083    switch(opcode & 0xff)
3084    {
3083   switch(opcode & 0xff)
3084   {
30853085      // 0x00
30863086      case 0x00:  NOP(opcode); break;
30873087      case 0x10:  NOP(opcode); break;
trunk/src/emu/video/vooddefs.h
r32760r32761
17261726   raster_info         rasterizer[MAX_RASTERIZERS]; /* array of rasterizers */
17271727   raster_info *       raster_hash[RASTER_HASH_SIZE]; /* hash table of rasterizers */
17281728
1729   bool            send_config;
1730   UINT32            tmu_config;
1729   bool                send_config;
1730   UINT32              tmu_config;
17311731};
17321732
17331733
r32760r32761
36463646      /* result in texel */                                                   \
36473647      /* note that they set LOD min to 8 to "disable" a TMU */                \
36483648      if (TMUS >= 1 && v->tmu[0].lodmin < (8 << 8))                           \
3649                {                                                                   \
3649            {                                                                   \
36503650         if (!v->send_config)                                                \
3651                        {                                                                   \
3651                  {                                                                   \
36523652            TEXTURE_PIPELINE(&v->tmu[0], x, dither4, TEXMODE0, texel,           \
36533653                           v->tmu[0].lookup, extra->lodbase0,              \
36543654                           iters0, itert0, iterw0, texel);                 \
3655                        }                                                                   \
3656                        else                                                                \
3657                        {                                                                   \
3655                  }                                                                   \
3656                  else                                                                \
3657                  {                                                                   \
36583658            texel.u=v->tmu_config;                                              \
3659                        }                                                                   \
3660                }                                                                   \
3659                  }                                                                   \
3660            }                                                                   \
36613661                                                            \
36623662      /* colorpath pipeline selects source colors and does blending */        \
36633663      CLAMPED_ARGB(iterr, iterg, iterb, itera, FBZCOLORPATH, iterargb);       \
trunk/src/emu/video/upd7220.c
r32760r32761
764764   UINT8 data = readbyte(addr);
765765   UINT8 new_pixel = (xi & 8 ? tile_data >> 8 : tile_data & 0xff) & (0x80 >> (xi & 7));
766766   new_pixel = new_pixel ? (0xff & (0x80 >> (x & 7))) : 0;
767   
767
768768   switch(m_bitmap_mod)
769769   {
770770      case 0: //replace
trunk/src/emu/video/epic12.c
r32760r32761
4141   m_bitmaps = auto_bitmap_rgb32_alloc(machine(), 0x2000, 0x1000);
4242   m_clip = m_bitmaps->cliprect();
4343   m_clip.set(0, 0x2000-1, 0, 0x1000-1);
44   
44
4545   m_ram16_copy = auto_alloc_array(machine(), UINT16, m_main_ramsize/2);
4646
4747   m_blitter_delay_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(epic12_device::blitter_delay_callback),this));
trunk/src/emu/video/voodoo.c
r32760r32761
49154915      }
49164916   }
49174917
4918   v->tmu_config = 0x11;   // revision 1
4918   v->tmu_config = 0x11;   // revision 1
49194919
49204920   /* configure type-specific values */
49214921   switch (v->type)
r32760r32761
49694969   assert_always(v->cpu != NULL, "Unable to find CPU attached to voodoo");
49704970
49714971   if (m_tmumem1 != 0)
4972      v->tmu_config |= 0xc0;   // two TMUs
4972      v->tmu_config |= 0xc0;  // two TMUs
49734973
49744974   v->chipmask = 0x01;
49754975   v->attoseconds_per_cycle = ATTOSECONDS_PER_SECOND / v->freq;
trunk/src/emu/video/315_5124.c
r32760r32761
677677         reg_num = data & 0x0f;
678678         m_reg[reg_num] = m_addr & 0xff;
679679         //logerror("%s: %s: setting register %x to %02x\n", machine().describe_context(), tag(), reg_num, m_addr & 0xf );
680         
680
681681         switch (reg_num)
682682         {
683683         case 0:
trunk/src/emu/diimage.c
r32760r32761
12291229
12301230      if (swinfo_name == swlistdev->list_name())
12311231      {
1232         // ad hoc handling for the case path = swlist_name:swinfo_name (e.g.
1233         // gameboy:sml) which is not handled properly by software_name_split
1234         // since the function cannot distinguish between this and the case
1232         // ad hoc handling for the case path = swlist_name:swinfo_name (e.g.
1233         // gameboy:sml) which is not handled properly by software_name_split
1234         // since the function cannot distinguish between this and the case
12351235         // path = swinfo_name:swpart_name
12361236         software_info *info = swlistdev->find(swpart_name);
12371237         if (info != NULL)
trunk/src/emu/machine.c
r32760r32761
379379         #endif
380380
381381         manager().web()->serve();
382         
382
383383         // execute CPUs if not paused
384384         if (!m_paused)
385385            m_scheduler.timeslice();
trunk/src/emu/sound/samples.c
r32760r32761
264264
265265   // initialize any custom handlers
266266   m_samples_start_cb.bind_relative_to(*owner());
267   
267
268268   if (!m_samples_start_cb.isnull())
269269      m_samples_start_cb();
270270}
trunk/src/emu/sound/samples.h
r32760r32761
2323
2424#define MCFG_SAMPLES_NAMES(_names) \
2525   samples_device::static_set_samples_names(*device, _names);
26   
26
2727typedef device_delegate<void ()> samples_start_cb_delegate;
2828
2929#define SAMPLES_START_CB_MEMBER(_name) void _name()
30   
30
3131#define MCFG_SAMPLES_START_CB(_class, _method) \
3232   samples_device::set_samples_start_callback(*device, samples_start_cb_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
3333
r32760r32761
7474      dynamic_array<INT16> data;      // 16-bit signed data
7575   };
7676   static bool read_sample(emu_file &file, sample_t &sample);
77   
77
7878   // interface
7979   UINT8       m_channels;         // number of discrete audio channels needed
8080   const char *const *m_names;     // array of sample names
trunk/src/emu/sound/ymf278b.c
r32760r32761
7575
7676// default address map
7777static ADDRESS_MAP_START( ymf278b, AS_0, 8, ymf278b_device )
78        AM_RANGE(0x000000, 0x3fffff) AM_ROM
78      AM_RANGE(0x000000, 0x3fffff) AM_ROM
7979ADDRESS_MAP_END
8080
8181
trunk/src/emu/sound/k053260.c
r32760r32761
385385
386386   else if (m_start + m_length >= m_device->m_rom_size)
387387      logerror("K053260: Attempting to play past the end of the ROM ( start = %06x, length = %06x )\n",
388            m_start, m_length);
388               m_start, m_length);
389389
390390   else
391391   {
r32760r32761
464464   if (offs >= m_device->m_rom_size)
465465   {
466466      logerror("%s: K053260: Attempting to read past the end of the ROM (offs = %06x, size = %06x)\n",
467            m_device->machine().describe_context(), offs, m_device->m_rom_size);
467               m_device->machine().describe_context(), offs, m_device->m_rom_size);
468468      return 0;
469469   }
470470
trunk/src/emu/sound/k053260.h
r32760r32761
6060   UINT32          m_rom_size;
6161
6262   // live state
63    UINT8           m_portdata[4];
63   UINT8           m_portdata[4];
6464   UINT8           m_keyon;
6565   UINT8           m_mode;
6666
trunk/src/emu/sound/speaker.h
r32760r32761
2626public:
2727   speaker_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
2828   ~speaker_sound_device() {}
29   
29
3030   // static configuration
3131   static void static_set_levels(device_t &device, int num_levels, const INT16 *levels) { downcast<speaker_sound_device &>(device).m_num_levels = num_levels; downcast<speaker_sound_device &>(device).m_levels = levels;}
3232
r32760r32761
8080
8181   // DC blocker state
8282   double  m_prevx, m_prevy;
83   
83
8484   int          m_num_levels;  /* optional: number of levels (if not two) */
8585   const INT16  *m_levels;     /* optional: pointer to level lookup table */
8686};
trunk/src/emu/sound/flt_rc.h
r32760r32761
7373
7474   // static configuration
7575   static void static_set_rc(device_t &device, int type, double R1, double R2, double R3, double C);
76   
76
7777   void filter_rc_set_RC(int type, double R1, double R2, double R3, double C);
7878
7979protected:
r32760r32761
9191   int            m_k;
9292   int            m_memory;
9393   int            m_type;
94   double         m_R1;
95   double         m_R2;
96   double         m_R3;
97   double         m_C;
94   double         m_R1;
95   double         m_R2;
96   double         m_R3;
97   double         m_C;
9898};
9999
100100extern const device_type FILTER_RC;
trunk/src/emu/sound/zsg2.c
r32760r32761
142142      prepare_samples(i);
143143
144144   FILE* f;
145   
145
146146   f = fopen("zoom_samples.bin","wb");
147147   fwrite(m_mem_copy,1,m_mem_blocks*4,f);
148148   fclose(f);
trunk/src/emu/bus/chanf/rom.c
r32760r32761
164164         m_data0 = m_ram[m_addr] & 1;
165165         return (m_latch[0] & 0x7f) | (m_data0 << 7);
166166      }
167     
167
168168      return m_latch[0];
169169   }
170170   else
r32760r32761
176176   if (offset == 0)
177177   {
178178      m_latch[0] = data;
179     
179
180180      m_read_write = BIT(data, 0);
181181
182      m_addr_latch = (m_addr_latch & 0x3f3) | (BIT(data, 2) << 2) | (BIT(data, 1) << 3);   // bits 2,3 come from this write!
182      m_addr_latch = (m_addr_latch & 0x3f3) | (BIT(data, 2) << 2) | (BIT(data, 1) << 3);  // bits 2,3 come from this write!
183183      m_addr = m_addr_latch;
184184
185185      m_data0 = BIT(data, 3);
r32760r32761
199199
200200// These are shared among Schach & Multigame cart types (not directly used by base chanf_rom_device)
201201UINT8 chanf_rom_device::common_read_3853(UINT32 offset)
202{
202{
203203   if (offset < m_ram.count())
204204      return m_ram[offset];
205205   else
r32760r32761
207207}
208208
209209void chanf_rom_device::common_write_3853(UINT32 offset, UINT8 data)
210{
210{
211211   if (offset < m_ram.count())
212212      m_ram[offset] = data;
213213}
r32760r32761
240240   m_base_bank = data & 0x1f;
241241   m_half_bank = BIT(data, 5);
242242}
243
trunk/src/emu/bus/chanf/slot.c
r32760r32761
178178         // we default to "chess" slot because some homebrew programs have been written to run
179179         // on PCBs with RAM at $2000-$2800 as Saba Schach!
180180         if (len == 0x40000)
181            m_type = CF_MULTI;   // TODO1: differentiate multicart final and earlier from fullpath
181            m_type = CF_MULTI;  // TODO1: differentiate multicart final and earlier from fullpath
182182         else
183            m_type = CF_CHESS;   // TODO2: is there any way to detect Maze and Hangman from fullpath?
183            m_type = CF_CHESS;  // TODO2: is there any way to detect Maze and Hangman from fullpath?
184184
185185         m_cart->ram_alloc(0x800);
186186      }
r32760r32761
226226      const char *slot_string = "chess";
227227      UINT32 len = core_fsize(m_file);
228228      int type;
229     
229
230230      if (len == 0x40000)
231231         type = CF_MULTI;
232232      else
233         type = CF_CHESS;   // is there any way to detect the other carts from fullpath?
234     
233         type = CF_CHESS;    // is there any way to detect the other carts from fullpath?
234
235235      slot_string = chanf_get_slot(type);
236     
236
237237      //printf("type: %s\n", slot_string);
238238      clear();
239     
239
240240      result.cpy(slot_string);
241241      return;
242242   }
trunk/src/emu/bus/chanf/rom.h
r32760r32761
2424   UINT8 common_read_3853(UINT32 offset);
2525   void common_write_2102(UINT32 offset, UINT8 data);
2626   void common_write_3853(UINT32 offset, UINT8 data);
27   
27
2828   // reading and writing
2929   virtual DECLARE_READ8_MEMBER(read_rom);
3030
31   
31
3232protected:
3333   // used for RAM chip in Hangman & Maze
34   UINT8 m_latch[2];      // PORT A & PORT B
34   UINT8 m_latch[2];       // PORT A & PORT B
3535   UINT16 m_addr_latch, m_addr;
3636   int m_read_write, m_data0;
3737};
r32760r32761
4343public:
4444   // construction/destruction
4545   chanf_maze_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
46   
46
4747   // device-level overrides
4848   virtual void device_start();
4949   virtual void device_reset();
50   
50
5151   // reading and writing
5252   virtual DECLARE_READ8_MEMBER(read_ram) { return common_read_2102(offset); }
5353   virtual DECLARE_WRITE8_MEMBER(write_ram) { common_write_2102(offset, data); }
r32760r32761
6161public:
6262   // construction/destruction
6363   chanf_hangman_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
64   
64
6565   // device-level overrides
6666   virtual void device_start();
6767   virtual void device_reset();
68   
68
6969   // reading and writing
7070   virtual DECLARE_READ8_MEMBER(read_ram) { return common_read_2102(offset); }
7171   virtual DECLARE_WRITE8_MEMBER(write_ram) { common_write_2102(offset, data); }
r32760r32761
7979public:
8080   // construction/destruction
8181   chanf_chess_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
82   
82
8383   // reading and writing
8484   virtual DECLARE_READ8_MEMBER(read_ram) { return common_read_3853(offset); }
8585   virtual DECLARE_WRITE8_MEMBER(write_ram) { common_write_3853(offset, data); }
r32760r32761
9393public:
9494   // construction/destruction
9595   chanf_multi_old_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
96   
96
9797   // device-level overrides
9898   virtual void device_start();
9999   virtual void device_reset();
100   
100
101101   // reading and writing
102102   virtual DECLARE_READ8_MEMBER(read_rom);
103103   virtual DECLARE_READ8_MEMBER(read_ram) { return common_read_3853(offset); }
r32760r32761
116116public:
117117   // construction/destruction
118118   chanf_multi_final_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
119   
119
120120   // device-level overrides
121121   virtual void device_start();
122122   virtual void device_reset();
123   
123
124124   // reading and writing
125125   virtual DECLARE_READ8_MEMBER(read_rom);
126126   virtual DECLARE_READ8_MEMBER(read_ram) { return common_read_3853(offset); }
127127   virtual DECLARE_WRITE8_MEMBER(write_ram) { common_write_3853(offset, data); }
128128   virtual DECLARE_WRITE8_MEMBER(write_bank);
129   
129
130130private:
131131   int m_base_bank, m_half_bank;
132132};
trunk/src/emu/bus/chanf/slot.h
r32760r32761
4242   UINT32 get_rom_size() { return m_rom_size; }
4343   UINT32 get_ram_size() { return m_ram.count(); }
4444
45   void save_ram()   { device().save_item(NAME(m_ram)); }
45   void save_ram() { device().save_item(NAME(m_ram)); }
4646
4747protected:
4848   // internal state
r32760r32761
7474
7575   int get_type() { return m_type; }
7676
77   void save_ram()   { if (m_cart && m_cart->get_ram_size()) m_cart->save_ram(); }
77   void save_ram() { if (m_cart && m_cart->get_ram_size()) m_cart->save_ram(); }
7878
7979   virtual iodevice_t image_type() const { return IO_CARTSLOT; }
8080   virtual bool is_readable()  const { return 1; }
r32760r32761
115115
116116#define MCFG_CHANNELF_CARTRIDGE_ADD(_tag,_slot_intf,_def_slot) \
117117   MCFG_DEVICE_ADD(_tag, CHANF_CART_SLOT, 0) \
118   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false) \
119
118   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false)
120119#endif
trunk/src/emu/bus/vic20/fe3.c
r32760r32761
1111
1212/*
1313
14   TODO:
14    TODO:
1515
16   - fe3diag register error#2 hp=5592 (same error in VICE)
17   - SD card
18   - RTC
16    - fe3diag register error#2 hp=5592 (same error in VICE)
17    - SD card
18    - RTC
1919
2020*/
2121
r32760r32761
3232#define ATF1504AS_TAG   "ic4"
3333
3434#define REG1_BANK \
35    ((m_reg1 & 0x7f) << 15)
35   ((m_reg1 & 0x7f) << 15)
3636
3737#define LORAM_HIDDEN \
38    (m_reg2 & REG2_BLK0)
38   (m_reg2 & REG2_BLK0)
3939
4040#define BLK1_HIDDEN \
41    (m_reg2 & REG2_BLK1)
41   (m_reg2 & REG2_BLK1)
4242
4343#define BLK2_HIDDEN \
44    (m_reg2 & REG2_BLK2)
44   (m_reg2 & REG2_BLK2)
4545
4646#define BLK3_HIDDEN \
47    (m_reg2 & REG2_BLK3)
47   (m_reg2 & REG2_BLK3)
4848
4949#define BLK5_HIDDEN \
50    (m_reg2 & REG2_BLK5)
50   (m_reg2 & REG2_BLK5)
5151
5252#define REGISTERS_HIDDEN \
53    ((m_lockbit && ((m_reg1 & REG1_MODE_MASK) == REG1_START)) || (m_reg2 & REG2_IO3))
53   ((m_lockbit && ((m_reg1 & REG1_MODE_MASK) == REG1_START)) || (m_reg2 & REG2_IO3))
5454
5555
5656
r32760r32761
178178      {
179179         data = m_ram[get_address(0, 0, offset)];
180180      }
181     
181
182182      // read from ROM
183183      if (!blk1 && !BLK1_HIDDEN)
184184      {
r32760r32761
203203         data = read_register(BIT(offset, 0));
204204      }
205205      break;
206     
206
207207   case REG1_RAM_1:
208208      // read from RAM bank 0
209209      if ((!ram1 || !ram2 || !ram3) && !LORAM_HIDDEN)
r32760r32761
235235         data = read_register(BIT(offset, 0));
236236      }
237237      break;
238     
238
239239   case REG1_RAM_2:
240240      // read from RAM bank 0
241241      if ((!ram1 || !ram2 || !ram3) && !LORAM_HIDDEN)
r32760r32761
267267         data = read_register(BIT(offset, 0));
268268      }
269269      break;
270     
270
271271   case REG1_SUPER_RAM:
272272      // read from RAM bank 0
273273      if ((!ram1 || !ram2 || !ram3) && !LORAM_HIDDEN)
r32760r32761
299299         data = read_register(BIT(offset, 0));
300300      }
301301      break;
302     
302
303303   case REG1_RAM_ROM:
304304      // read from RAM bank 0
305305      if ((!ram1 || !ram2 || !ram3) && !LORAM_HIDDEN)
306306      {
307307         data = m_ram[get_address(0, 0, offset)];
308308      }
309     
309
310310      // read from ROM bank 0 or RAM bank 1
311311      if (!blk1 && !BLK1_HIDDEN)
312312      {
r32760r32761
331331         data = read_register(BIT(offset, 0));
332332      }
333333      break;
334     
334
335335   case REG1_FLASH:
336336      // read from RAM bank 0
337337      if ((!ram1 || !ram2 || !ram3) && !LORAM_HIDDEN)
r32760r32761
392392         write_register(BIT(offset, 0), data);
393393      }
394394      break;
395     
395
396396   case REG1_SUPER_ROM:
397397      // write to RAM bank 0
398398      if ((!ram1 || !ram2 || !ram3) && !LORAM_HIDDEN)
r32760r32761
424424         write_register(BIT(offset, 0), data);
425425      }
426426      break;
427     
427
428428   case REG1_RAM_1:
429429      // write to RAM bank 0
430430      if ((!ram1 || !ram2 || !ram3) && !LORAM_HIDDEN && REG1_BLK0)
r32760r32761
456456         write_register(BIT(offset, 0), data);
457457      }
458458      break;
459     
459
460460   case REG1_RAM_2:
461461      // write to RAM bank 0
462462      if ((!ram1 || !ram2 || !ram3) && !LORAM_HIDDEN && REG1_BLK0)
r32760r32761
488488         write_register(BIT(offset, 0), data);
489489      }
490490      break;
491     
491
492492   case REG1_SUPER_RAM:
493493      // write to RAM bank 0
494494      if ((!ram1 || !ram2 || !ram3) && !LORAM_HIDDEN)
r32760r32761
520520         write_register(BIT(offset, 0), data);
521521      }
522522      break;
523     
523
524524   case REG1_RAM_ROM:
525525      // write to RAM bank 0
526526      if ((!ram1 || !ram2 || !ram3) && !LORAM_HIDDEN && REG1_BLK0)
r32760r32761
552552         write_register(BIT(offset, 0), data);
553553      }
554554      break;
555     
555
556556   case REG1_FLASH:
557557      // write to RAM bank 0
558558      if ((!ram1 || !ram2 || !ram3) && !LORAM_HIDDEN)
trunk/src/emu/bus/vic20/fe3.h
r32760r32761
2727// ======================> vic20_final_expansion_3_t
2828
2929class vic20_final_expansion_3_t :  public device_t,
30                           public device_vic20_expansion_card_interface
30                           public device_vic20_expansion_card_interface
3131{
3232public:
3333   // construction/destruction
trunk/src/emu/bus/gameboy/mbc.h
r32760r32761
183183public:
184184   // construction/destruction
185185   gb_rom_188in1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
186   
186
187187   // device-level overrides
188188   virtual void device_start() { shared_start(); save_item(NAME(m_game_base)); };
189189   virtual void device_reset() { shared_reset(); m_game_base = 0; };
190   
190
191191   // reading and writing
192192   virtual DECLARE_READ8_MEMBER(read_rom);
193193   virtual DECLARE_WRITE8_MEMBER(write_bank);
trunk/src/emu/bus/gameboy/gb_slot.h
r32760r32761
7171   void set_has_battery(bool val) { has_battery = val; }
7272   bool get_has_battery() { return has_battery; }
7373
74   void save_ram()   { device().save_item(NAME(m_ram)); }
75     
74   void save_ram() { device().save_item(NAME(m_ram)); }
75
7676   // internal state
7777   UINT8 *m_rom;
7878   UINT32 m_rom_size;
r32760r32761
122122
123123   void setup_ram(UINT8 banks);
124124   void internal_header_logging(UINT8 *ROM, UINT32 len);
125   void save_ram()   { if (m_cart && m_cart->get_ram_size()) m_cart->save_ram(); }
126   
125   void save_ram() { if (m_cart && m_cart->get_ram_size()) m_cart->save_ram(); }
126
127127   virtual iodevice_t image_type() const { return IO_CARTSLOT; }
128128   virtual bool is_readable()  const { return 1; }
129129   virtual bool is_writeable() const { return 0; }
trunk/src/emu/bus/sega8/sega8_slot.c
r32760r32761
873873   SLOT_INTERFACE_INTERNAL("codemasters",  SEGA8_ROM_CODEMASTERS)
874874   SLOT_INTERFACE_INTERNAL("mgear",  SEGA8_ROM_MGEAR)
875875SLOT_INTERFACE_END
876
trunk/src/emu/bus/sega8/rom.c
r32760r32761
752752{
753753   int bank = offset / 0x4000;
754754
755    return m_rom[m_rom_bank_base[bank] * 0x4000 + (offset & 0x3fff)];
755   return m_rom[m_rom_bank_base[bank] * 0x4000 + (offset & 0x3fff)];
756756}
757757
758758
trunk/src/emu/bus/sega8/sega8_slot.h
r32760r32761
121121   int verify_cart(UINT8 *magic, int size);
122122   void set_lphaser_xoffset(UINT8 *rom, int size);
123123
124   void save_ram()   { if (m_cart && m_cart->get_ram_size()) m_cart->save_ram(); }
124   void save_ram() { if (m_cart && m_cart->get_ram_size()) m_cart->save_ram(); }
125125
126126   void set_mandatory(bool val) { m_must_be_loaded = val; }
127127   void set_intf(const char * interface) { m_interface = interface; }
trunk/src/emu/bus/sega8/mgear.h
r32760r32761
1212public:
1313   // construction/destruction
1414   sega8_mgear_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
15   
15
1616   // device-level overrides
1717   virtual void device_start();
1818   virtual void device_reset();
19   
19
2020   // reading and writing
2121   virtual DECLARE_READ8_MEMBER(read_cart) { return m_subslot->read_cart(space, offset); }
2222   virtual DECLARE_WRITE8_MEMBER(write_cart) { m_subslot->write_cart(space, offset, data); }
trunk/src/emu/bus/sega8/ccatch.c
r32760r32761
11/***********************************************************************************************************
22
33 SG-1000 Card Catcher emulation
4
4
55 Sega Card Catcher is a passthrough adapter for
66 SG-1000 to load games in MyCard format into the
7 main cartslot
7 main cartslot
88
99 ***********************************************************************************************************/
1010
trunk/src/emu/bus/a800/a800_slot.h
r32760r32761
2020   A800_OSSM091,
2121   A800_OSS8K,
2222   A800_PHOENIX,
23   A800_XEGS,   
24   A800_BBSB,   
23   A800_XEGS,
24   A800_BBSB,
2525   A800_DIAMOND,
2626   A800_WILLIAMS,
27   A800_EXPRESS,
27   A800_EXPRESS,
2828   A800_SPARTADOS,
2929   A800_BLIZZARD,
3030   A800_TURBO64,
r32760r32761
7171   UINT8 *m_rom;
7272   UINT32 m_rom_size;
7373   dynamic_buffer m_ram;
74   dynamic_buffer m_nvram;   // HiScore cart can save scores!
74   dynamic_buffer m_nvram; // HiScore cart can save scores!
7575   // helpers
7676   int m_bank_mask;
7777};
r32760r32761
101101   int get_cart_type() { return m_type; };
102102   int identify_cart_type(UINT8 *header);
103103   bool has_cart() { return m_cart != NULL; }
104   
104
105105   virtual iodevice_t image_type() const { return IO_CARTSLOT; }
106106   virtual bool is_readable()  const { return 1; }
107107   virtual bool is_writeable() const { return 0; }
r32760r32761
120120   virtual DECLARE_READ8_MEMBER(read_d5xx);
121121   virtual DECLARE_WRITE8_MEMBER(write_80xx);
122122   virtual DECLARE_WRITE8_MEMBER(write_d5xx);
123   
123
124124private:
125125   device_a800_cart_interface*       m_cart;
126126   int m_type;
r32760r32761
138138   // construction/destruction
139139   a5200_cart_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
140140   virtual ~a5200_cart_slot_device();
141   
141
142142   virtual const char *file_extensions() const { return "bin,rom,car,a52"; }
143   
143
144144   // slot interface overrides
145145   virtual void get_default_card_software(astring &result);
146146};
r32760r32761
155155   virtual ~xegs_cart_slot_device();
156156
157157   virtual const char *file_extensions() const { return "bin,rom,car"; }
158   
158
159159   // slot interface overrides
160160   virtual void get_default_card_software(astring &result);
161161};
trunk/src/emu/bus/a800/sparta.h
r32760r32761
1313public:
1414   // construction/destruction
1515   a800_rom_spartados_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
16   
16
1717   // device-level overrides
1818   virtual void device_start();
1919   virtual void device_reset();
20   
20
2121   virtual DECLARE_READ8_MEMBER(read_80xx);
2222   virtual DECLARE_WRITE8_MEMBER(write_d5xx);
23   
23
2424protected:
2525   int m_bank, m_subslot_enabled;
2626};
trunk/src/emu/bus/a800/rom.h
r32760r32761
3131public:
3232   // construction/destruction
3333   a800_rom_bbsb_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
34   
34
3535   // device-level overrides
3636   virtual void device_start();
3737   virtual void device_reset();
38   
38
3939   virtual DECLARE_READ8_MEMBER(read_80xx);
4040   virtual DECLARE_WRITE8_MEMBER(write_80xx);
41   
41
4242protected:
4343   int m_banks[2];
4444};
r32760r32761
5151public:
5252   // construction/destruction
5353   a800_rom_williams_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
54   
54
5555   // device-level overrides
5656   virtual void device_start();
5757   virtual void device_reset();
58   
58
5959   virtual DECLARE_READ8_MEMBER(read_80xx);
6060   virtual DECLARE_WRITE8_MEMBER(write_d5xx);
61   
61
6262protected:
6363   int m_bank;
6464};
r32760r32761
7171public:
7272   // construction/destruction
7373   a800_rom_express_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
74   
74
7575   // device-level overrides
7676   virtual void device_start();
7777   virtual void device_reset();
78   
78
7979   virtual DECLARE_READ8_MEMBER(read_80xx);
8080   virtual DECLARE_WRITE8_MEMBER(write_d5xx);
81   
81
8282protected:
8383   int m_bank;
8484};
r32760r32761
9191public:
9292   // construction/destruction
9393   a800_rom_blizzard_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
94   
94
9595   // device-level overrides
9696   virtual void device_start();
9797   virtual void device_reset();
98   
98
9999   virtual DECLARE_READ8_MEMBER(read_80xx);
100100};
101101
r32760r32761
107107public:
108108   // construction/destruction
109109   a800_rom_turbo_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
110   
110
111111   // device-level overrides
112112   virtual void device_start();
113113   virtual void device_reset();
114   
114
115115   virtual DECLARE_READ8_MEMBER(read_80xx);
116116   virtual DECLARE_WRITE8_MEMBER(write_d5xx);
117   
117
118118protected:
119119   int m_bank;
120120};
r32760r32761
127127public:
128128   // construction/destruction
129129   a800_rom_telelink2_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
130   
130
131131   virtual DECLARE_READ8_MEMBER(read_80xx);
132132   virtual DECLARE_WRITE8_MEMBER(write_80xx);
133133   virtual DECLARE_READ8_MEMBER(read_d5xx);
r32760r32761
142142public:
143143   // construction/destruction
144144   a800_rom_microcalc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
145   
145
146146   // device-level overrides
147147   virtual void device_start();
148148   virtual void device_reset();
149   
149
150150   virtual DECLARE_READ8_MEMBER(read_80xx);
151151   virtual DECLARE_WRITE8_MEMBER(write_d5xx);
152   
152
153153protected:
154154   int m_bank;
155155};
r32760r32761
162162public:
163163   // construction/destruction
164164   xegs_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
165   
165
166166   // device-level overrides
167167   virtual void device_start();
168168   virtual void device_reset();
169   
169
170170   virtual DECLARE_READ8_MEMBER(read_80xx);
171171   virtual DECLARE_WRITE8_MEMBER(write_d5xx);
172   
172
173173protected:
174174   int m_bank;
175175};
r32760r32761
182182public:
183183   // construction/destruction
184184   a5200_rom_2chips_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
185   
185
186186   virtual DECLARE_READ8_MEMBER(read_80xx);
187187};
188188
r32760r32761
194194public:
195195   // construction/destruction
196196   a5200_rom_bbsb_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
197   
197
198198   // device-level overrides
199199   virtual void device_start();
200200   virtual void device_reset();
201   
201
202202   virtual DECLARE_READ8_MEMBER(read_80xx);
203203   virtual DECLARE_WRITE8_MEMBER(write_80xx);
204   
204
205205protected:
206206   int m_banks[2];
207207};
trunk/src/emu/bus/a800/oss.c
r32760r32761
9595 -------------------------------------------------*/
9696
9797/*-------------------------------------------------
98
98
9999 OSS 8K
100
100
101101 This is used by The Writer's Tool only.
102
102
103103 -------------------------------------------------*/
104104
105105READ8_MEMBER(a800_rom_oss8k_device::read_80xx)
r32760r32761
128128
129129
130130/*-------------------------------------------------
131
131
132132 OSS 034M
133
133
134134 This apparently comes from a dump with the wrong bank order...
135135 investigate whether we should remove it!
136
136
137137 -------------------------------------------------*/
138138
139139READ8_MEMBER(a800_rom_oss34_device::read_80xx)
r32760r32761
156156         break;
157157      case 2:
158158      case 6:
159         m_bank = 3;   // in this case the ROM gets disabled and 0xff is returned in 0xa000-0xafff
159         m_bank = 3; // in this case the ROM gets disabled and 0xff is returned in 0xa000-0xafff
160160         break;
161161      case 3:
162162      case 7:
r32760r32761
173173
174174
175175/*-------------------------------------------------
176
176
177177 OSS 043M
178
178
179179 Same as above but with correct bank order
180
180
181181 -------------------------------------------------*/
182182
183183READ8_MEMBER(a800_rom_oss43_device::read_80xx)
r32760r32761
200200         break;
201201      case 2:
202202      case 6:
203         m_bank = 3;   // in this case the ROM gets disabled and 0xff is returned in 0xa000-0xafff
203         m_bank = 3; // in this case the ROM gets disabled and 0xff is returned in 0xa000-0xafff
204204         break;
205205      case 3:
206206      case 7:
r32760r32761
217217
218218
219219/*-------------------------------------------------
220
220
221221 OSS M091
222 
223 Simplified banking system which only uses two
222
223 Simplified banking system which only uses two
224224 address lines (A0 & A3)
225
225
226226 -------------------------------------------------*/
227227
228228READ8_MEMBER(a800_rom_oss91_device::read_80xx)
r32760r32761
250250         break;
251251   }
252252}
253
trunk/src/emu/bus/a800/a800_carts.h
r32760r32761
1414   SLOT_INTERFACE_INTERNAL("a800_8k",       A800_ROM)
1515   SLOT_INTERFACE_INTERNAL("a800_8k_right", A800_ROM)
1616   SLOT_INTERFACE_INTERNAL("a800_16k",      A800_ROM)
17   SLOT_INTERFACE_INTERNAL("a800_phoenix",  A800_ROM)   // not really emulated at this stage
17   SLOT_INTERFACE_INTERNAL("a800_phoenix",  A800_ROM)  // not really emulated at this stage
1818   SLOT_INTERFACE_INTERNAL("a800_bbsb",     A800_ROM_BBSB)
1919   SLOT_INTERFACE_INTERNAL("a800_oss8k",    A800_ROM_OSS8K)
2020   SLOT_INTERFACE_INTERNAL("a800_oss034m",  A800_ROM_OSS34)
r32760r32761
2323   SLOT_INTERFACE_INTERNAL("a800_williams", A800_ROM_WILLIAMS)
2424   SLOT_INTERFACE_INTERNAL("a800_diamond",  A800_ROM_EXPRESS)
2525   SLOT_INTERFACE_INTERNAL("a800_express",  A800_ROM_EXPRESS)
26   SLOT_INTERFACE_INTERNAL("a800_sparta",   A800_ROM_SPARTADOS)   // this is a passthru cart with unemulated (atm) subslot
26   SLOT_INTERFACE_INTERNAL("a800_sparta",   A800_ROM_SPARTADOS)    // this is a passthru cart with unemulated (atm) subslot
2727   SLOT_INTERFACE_INTERNAL("a800_blizzard", A800_ROM)
2828   SLOT_INTERFACE_INTERNAL("a800_turbo64",  A800_ROM_TURBO)
2929   SLOT_INTERFACE_INTERNAL("a800_turbo128", A800_ROM_TURBO)
3030   SLOT_INTERFACE_INTERNAL("a800_tlink2",   A800_ROM_TELELINK2)
3131   SLOT_INTERFACE_INTERNAL("a800_sitsa",    A800_ROM_MICROCALC)
32   SLOT_INTERFACE_INTERNAL("a800_corina",   A800_ROM)   // NOT SUPPORTED YET!
32   SLOT_INTERFACE_INTERNAL("a800_corina",   A800_ROM)  // NOT SUPPORTED YET!
3333   SLOT_INTERFACE_INTERNAL("xegs",          XEGS_ROM)
3434SLOT_INTERFACE_END
3535
trunk/src/emu/bus/a800/a800_slot.c
r32760r32761
66    Atari 8 bit cart emulation
77    (through slot devices)
88
9    Emulation of the cartslot(s) for Atari 8bit series of home computers
10 
9    Emulation of the cartslot(s) for Atari 8bit series of home computers
10
1111    Accessors to ROM are typically given in the area 0xa000-0xbfff, but some
1212    carts (and the right slot in A800) maps ROM to 0x8000-0x9fff too
1313    Bankswitch typically happens by accessing addresses in 0xd500-0xd5ff
14
14
1515    Accordingly, this device offers the following handlers
1616    - read_80xx/write_80xx
1717    - read_d5xx/write_d5xx
r32760r32761
6767      tempstring.cat(A800SLOT_ROM_REGION_TAG);
6868      m_rom = device().machine().memory().region_alloc(tempstring, size, 1, ENDIANNESS_LITTLE)->base();
6969      m_rom_size = size;
70     
70
7171      // setup other helpers
72      m_bank_mask = (size / 0x2000) - 1;   // code for XEGS carts makes use of this to simplify banking
72      m_bank_mask = (size / 0x2000) - 1;  // code for XEGS carts makes use of this to simplify banking
7373   }
7474}
7575
r32760r32761
243243   if (m_cart)
244244   {
245245      UINT32 len;
246     
246
247247      if (software_entry() != NULL)
248248      {
249249         const char *pcb_name;
250250         len = get_software_region_length("rom");
251         
251
252252         m_cart->rom_alloc(len, tag());
253253         memcpy(m_cart->get_rom_base(), get_software_region("rom"), len);
254         
254
255255         if ((pcb_name = get_feature("slot")) != NULL)
256256            m_type = a800_get_pcb_id(pcb_name);
257257         else
r32760r32761
267267            UINT8 header[16];
268268            fread(header, 0x10);
269269            m_type = identify_cart_type(header);
270            len -= 0x10;   // in identify_cart_type the first 0x10 bytes are read, so we need to adjust here
270            len -= 0x10;    // in identify_cart_type the first 0x10 bytes are read, so we need to adjust here
271271         }
272         else   // otherwise try to guess based on size
272         else    // otherwise try to guess based on size
273273         {
274274            if (len == 0x8000)
275275               m_type = A5200_32K;
r32760r32761
323323   // check CART format
324324   if (strncmp((const char *)header, "CART", 4))
325325      fatalerror("Invalid header detected!\n");
326   
326
327327   switch ((header[4] << 24) + (header[5] << 16) +  (header[6] << 8) + (header[7] << 0))
328328   {
329329      case 1:
r32760r32761
400400         osd_printf_info("Cart type \"%d\" is currently unsupported.\n", (header[4] << 24) + (header[5] << 16) +  (header[6] << 8) + (header[7] << 0));
401401         break;
402402   }
403   
403
404404   return type;
405405}
406406
r32760r32761
420420      // check whether there is an header, to identify the cart type
421421      if ((len % 0x1000) == 0x10)
422422      {
423         core_fread(m_file, head, 0x10);     
423         core_fread(m_file, head, 0x10);
424424         type = identify_cart_type(head);
425425      }
426      else   // otherwise try to guess based on size
426      else    // otherwise try to guess based on size
427427      {
428428         if (len == 0x4000)
429429            type = A800_16K;
r32760r32761
435435         osd_printf_info("This game is not designed for A800. You might want to run it in A5200.\n");
436436
437437      slot_string = a800_get_slot(type);
438     
438
439439      clear();
440     
440
441441      result.cpy(slot_string);
442442   }
443443   else
r32760r32761
453453      dynamic_buffer head(0x10);
454454      UINT32 len = core_fsize(m_file);
455455      int type = A5200_8K;
456     
456
457457      // check whether there is an header, to identify the cart type
458458      if ((len % 0x1000) == 0x10)
459459      {
460         core_fread(m_file, head, 0x10);     
460         core_fread(m_file, head, 0x10);
461461         type = identify_cart_type(head);
462462
463463         astring info;
r32760r32761
466466      }
467467      if (type < A5200_4K)
468468         osd_printf_info("This game is not designed for A5200. You might want to run it in A800 or A800XL.\n");
469     
469
470470      slot_string = a800_get_slot(type);
471     
471
472472      clear();
473     
473
474474      result.cpy(slot_string);
475475   }
476476   else
r32760r32761
486486      dynamic_buffer head(0x10);
487487      UINT32 len = core_fsize(m_file);
488488      int type = A800_8K;
489     
489
490490      // check whether there is an header, to identify the cart type
491491      if ((len % 0x1000) == 0x10)
492492      {
493         core_fread(m_file, head, 0x10);     
493         core_fread(m_file, head, 0x10);
494494         type = identify_cart_type(head);
495495      }
496496      if (type != A800_XEGS)
r32760r32761
501501         else
502502            osd_printf_info("You might want to run it in A800 or A800XL.\n");
503503      }
504     
504
505505      slot_string = a800_get_slot(type);
506     
506
507507      clear();
508     
508
509509      result.cpy(slot_string);
510510   }
511511   else
r32760r32761
549549   if (m_cart)
550550      m_cart->write_d5xx(space, offset, data, mem_mask);
551551}
552
trunk/src/emu/bus/a800/oss.h
r32760r32761
1313public:
1414   // construction/destruction
1515   a800_rom_oss8k_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
16   
16
1717   // device-level overrides
1818   virtual void device_start();
1919   virtual void device_reset();
20   
20
2121   virtual DECLARE_READ8_MEMBER(read_80xx);
2222   virtual DECLARE_WRITE8_MEMBER(write_d5xx);
23   
23
2424protected:
2525   int m_bank;
2626};
r32760r32761
5353public:
5454   // construction/destruction
5555   a800_rom_oss43_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
56   
56
5757   // device-level overrides
5858   virtual void device_start();
5959   virtual void device_reset();
60   
60
6161   virtual DECLARE_READ8_MEMBER(read_80xx);
6262   virtual DECLARE_WRITE8_MEMBER(write_d5xx);
63   
63
6464protected:
6565   int m_bank;
6666};
r32760r32761
7373public:
7474   // construction/destruction
7575   a800_rom_oss91_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
76   
76
7777   // device-level overrides
7878   virtual void device_start();
7979   virtual void device_reset();
8080
8181   virtual DECLARE_READ8_MEMBER(read_80xx);
8282   virtual DECLARE_WRITE8_MEMBER(write_d5xx);
83   
83
8484protected:
8585   int m_bank;
8686};
trunk/src/emu/bus/a800/sparta.c
r32760r32761
4343 -------------------------------------------------*/
4444
4545/*-------------------------------------------------
46
46
4747 SpartaDOS 64K carts
48 
49 Similar to Express / Diamond carts, because
50 bankswitch is controlled by writing to 7 diff
51 offsets in reverse order, but writes to offsets
48
49 Similar to Express / Diamond carts, because
50 bankswitch is controlled by writing to 7 diff
51 offsets in reverse order, but writes to offsets
5252 0x8-0xf also enable/disable subslot
53
53
5454 -------------------------------------------------*/
5555
5656READ8_MEMBER(a800_rom_spartados_device::read_80xx)
r32760r32761
5858   if (!m_subslot_enabled)
5959      return m_rom[(offset & 0x1fff) + (m_bank * 0x2000)];
6060   else
61      return 0xff;   // subslot, currently not implemented
61      return 0xff;    // subslot, currently not implemented
6262}
6363
6464WRITE8_MEMBER(a800_rom_spartados_device::write_d5xx)
r32760r32761
6969      m_bank = (offset ^ 0x07) & 0x0f;
7070
7171}
72
trunk/src/emu/bus/a800/rom.c
r32760r32761
33/***********************************************************************************************************
44
55 A800/A5200/XEGS ROM cart emulation
6
6
77 Basic carts work the same (in addition of being mostly compatible) for all these systems
88 and thus we deal with them in a single file
99
r32760r32761
196196/*-------------------------------------------------
197197
198198 Carts with no bankswitch (8K, 16K)
199
199
200200 The cart accessors are mapped in the correct
201201 range at driver start
202202
r32760r32761
210210
211211
212212/*-------------------------------------------------
213
213
214214 Bounty Bob Strikes Back! cart (40K)
215
215
216216 Area 0xa000-0xbfff always point to last 8K bank
217 Areas 0x8000-0x8fff and 0x9000-0x9fff are
217 Areas 0x8000-0x8fff and 0x9000-0x9fff are
218218 separate banks of 4K mapped either in the first
219219 16K chunk or in the second 16K chunk
220 Bankswitch is controlled by data written in
220 Bankswitch is controlled by data written in
221221 0x8000-0x8fff and 0x9000-0x9fff respectively
222222
223223 -------------------------------------------------*/
r32760r32761
240240}
241241
242242/*-------------------------------------------------
243
243
244244 XEGS carts (32K, 64K or 128K)
245 
246 Bankswitch is controlled by data written in
245
246 Bankswitch is controlled by data written in
247247 0xd500-0xd5ff
248
248
249249 -------------------------------------------------*/
250250
251251READ8_MEMBER(xegs_rom_device::read_80xx)
r32760r32761
253253   if (offset < 0x2000)
254254      return m_rom[(offset & 0x1fff) + (m_bank * 0x2000)];
255255   else
256      return m_rom[(offset & 0x1fff) + (m_bank_mask * 0x2000)];   // always last 8K bank
257     
256      return m_rom[(offset & 0x1fff) + (m_bank_mask * 0x2000)];   // always last 8K bank
257
258258}
259259
260260WRITE8_MEMBER(xegs_rom_device::write_d5xx)
r32760r32761
264264
265265
266266/*-------------------------------------------------
267
267
268268 Williams 64K
269
269
270270 The rom is accessed in 8K chunks at 0xa000-0xbfff
271271 Bankswitch is controlled by writing to 7 diff
272 offsets (their location varies with the cart type):
273 offs 0 points to bank 0, offs 1 points to bank 1,
274 and so on... the rom can be disabled by writing to
272 offsets (their location varies with the cart type):
273 offs 0 points to bank 0, offs 1 points to bank 1,
274 and so on... the rom can be disabled by writing to
275275 the offsets 0x8-0xf of the same range as the bankswitch
276
276
277277 -------------------------------------------------*/
278278
279279READ8_MEMBER(a800_rom_williams_device::read_80xx)
r32760r32761
287287}
288288
289289/*-------------------------------------------------
290
290
291291 Express 64K / Diamond 64K carts
292
292
293293 The rom is accessed in 8K chunks at 0xa000-0xbfff
294 Bankswitch is the same as above, but writes trigger
295 banks in reverse order: offs 7 points to bank 0, offs 6
294 Bankswitch is the same as above, but writes trigger
295 banks in reverse order: offs 7 points to bank 0, offs 6
296296 points to bank 1, and so on... the rom can be disabled
297297 by writing to the offsets 0x8-0xf of the same range
298298 as the bankswitch
299
299
300300 -------------------------------------------------*/
301301
302302READ8_MEMBER(a800_rom_express_device::read_80xx)
r32760r32761
311311
312312
313313/*-------------------------------------------------
314
314
315315 Turbosoft 64K / 128K
316 
317 
316
317
318318 -------------------------------------------------*/
319319
320320READ8_MEMBER(a800_rom_turbo_device::read_80xx)
r32760r32761
329329
330330
331331/*-------------------------------------------------
332
332
333333 Telelink II
334 
335 
334
335
336336 -------------------------------------------------*/
337337
338338READ8_MEMBER(a800_rom_telelink2_device::read_80xx)
r32760r32761
347347
348348WRITE8_MEMBER(a800_rom_telelink2_device::write_80xx)
349349{
350   m_nvram[offset & 0xff] = data | 0xf0;   // low 4bits only
350   m_nvram[offset & 0xff] = data | 0xf0;   // low 4bits only
351351}
352352
353353READ8_MEMBER(a800_rom_telelink2_device::read_d5xx)
r32760r32761
364364
365365
366366/*-------------------------------------------------
367
367
368368 SITSA Microcalc
369 
370 
369
370
371371 -------------------------------------------------*/
372372
373373READ8_MEMBER(a800_rom_microcalc_device::read_80xx)
r32760r32761
386386
387387
388388/*-------------------------------------------------
389
389
390390 Carts with no bankswitch (4K, 8K, 16K, 32K)
391
391
392392 Same as base carts above
393
393
394394 -------------------------------------------------*/
395395
396396/*-------------------------------------------------
397
397
398398 Carts with 2x8K (16K) with A13 line not connected
399
399
400400 Range 0x4000-0x7fff contains two copies of the low
401401 8K, range 0x8000-0xbfff contains two copies of the
402402 high 8K
403
403
404404 -------------------------------------------------*/
405405
406406READ8_MEMBER(a5200_rom_2chips_device::read_80xx)
r32760r32761
413413
414414
415415/*-------------------------------------------------
416
416
417417 Bounty Bob Strikes Back! cart (40K)
418
418
419419 Similar to the A800 version, but:
420420 Area 0x8000-0xbfff always point to last 8K bank
421421 (repeated twice)
422 Areas 0x4000-0x4fff and 0x5000-0x5fff are
422 Areas 0x4000-0x4fff and 0x5000-0x5fff are
423423 separate banks of 4K mapped either in the first
424424 16K chunk or in the second 16K chunk
425 Bankswitch is controlled by data written in
425 Bankswitch is controlled by data written in
426426 0x4000-0x4fff and 0x5000-0x5fff respectively
427
427
428428 -------------------------------------------------*/
429429
430430READ8_MEMBER(a5200_rom_bbsb_device::read_80xx)
r32760r32761
445445   if (addr >= 0xff6 && addr <= 0xff9)
446446      m_banks[BIT(offset, 12)] = (addr - 0xff6);
447447}
448
trunk/src/emu/bus/vc4000/rom.c
r32760r32761
1010
1111
1212/*  Game List and Emulation Status
13
13
1414 When you load a game it will normally appear to be unresponsive. Most carts contain a number of variants
1515 of each game (e.g. Difficulty, Player1 vs Player2 or Player1 vs Computer, etc).
16
16
1717 Press F2 (if needed) to select which game variant you would like to play. The variant number will increment
1818 on-screen. When you've made your choice, press F1 to start. The main keys are unlabelled, because an overlay
1919 is provided with each cart. See below for a guide. You need to read the instructions that come with each game.
20
20
2121 In some games, the joystick is used like 4 buttons, and other games like a paddle. The two modes are
2222 incompatible when using a keyboard. Therefore (in the emulation) a config dipswitch is used. The preferred
2323 setting is listed below.
24
24
2525 (AC = Auto-centre, NAC = no auto-centre, 90 = turn controller 90 degrees).
26
26
2727 The list is rather incomplete, information will be added as it becomes available.
28
28
2929 The game names and numbers were obtained from the Amigan Software site.
30
30
3131 Cart Num    Name
3232 ----------------------------------------------
3333 1.      Grand Prix / Car Races / Autosport / Motor Racing / Road Race
3434 Config: Paddle, NAC
3535 Status: Working
3636 Controls: Left-Right: Steer; Up: Accelerate
37
37
3838 2.      Black Jack
3939 Status: Not working (some digits missing; indicator missing; dealer's cards missing)
4040 Controls: set bet with S and D; A to deal; 1 to hit, 2 to stay; Q accept insurance, E to decline; double-up (unknown key)
4141 Indicator: E make a bet then deal; I choose insurance; - you lost; + you won; X hit or stay
42
42
4343 3.      Olympics / Paddle Games / Bat & Ball / Pro Sport 60 / Sportsworld
4444 Config: Paddle, NAC
4545 Status: Working
46
46
4747 4.      Tank Battle / Combat
4848 Config: Button, 90
4949 Status: Working
5050 Controls: Left-Right: Steer; Up: Accelerate; Fire: Shoot
51
51
5252 5.      Maths 1
5353 Status: Working
5454 Controls: Z difficulty; X = addition or subtraction; C ask question; A=1;S=2;D=3;Q=4;W=5;E=6;1=7;2=8;3=9;0=0; C enter
55
55
5656 6.      Maths 2
5757 Status: Not working
5858 Controls: Same as above.
59
59
6060 7.      Air Sea Attack / Air Sea Battle
6161 Config: Button, 90
6262 Status: Working
6363 Controls: Left-Right: Move; Fire: Shoot
64
64
6565 8.      Treasure Hunt / Capture the Flag / Concentration / Memory Match
6666 Config: Buttons
6767 Status: Working
68
68
6969 9.      Labyrinth / Maze / Intelligence 1
7070 Config: Buttons
7171 Status: Working
72
72
7373 10.     Winter Sports
7474 Notes: Background colours should be Cyan and White instead of Red and Black
75
75
7676 11.     Hippodrome / Horse Race
77
77
7878 12.     Hunting / Shooting Gallery
79
79
8080 13.     Chess 1
8181 Status: Can't see what you're typing, wrong colours
82
82
8383 14.     Moto-cros
84
84
8585 15.     Four in a row / Intelligence 2
8686 Config: Buttons
8787 Status: Working
8888 Notes: Seems the unused squares should be black. The screen jumps about while the computer is "thinking".
89
89
9090 16.     Code Breaker / Master Mind / Intelligence 3 / Challenge
91
91
9292 17.     Circus
9393 STatus: severe gfx issues
94
94
9595 18.     Boxing / Prize Fight
96
96
9797 19.     Outer Space / Spacewar / Space Attack / Outer Space Combat
98
98
9999 20.     Melody Simon / Musical Memory / Follow the Leader / Musical Games / Electronic Music / Face the Music
100
100
101101 21.     Capture / Othello / Reversi / Attack / Intelligence 4
102102 Config: Buttons
103103 Status: Working
104104 Notes: Seems the unused squares should be black
105
105
106106 22.     Chess 2
107107 Status: Can't see what you're typing, wrong colours
108
108
109109 23.     Pinball / Flipper / Arcade
110110 Status: gfx issues
111
111
112112 24.     Soccer
113
113
114114 25.     Bowling / NinePins
115115 Config: Paddle, rotated 90 degrees, up/down autocentre, left-right does not
116116 Status: Working
117
117
118118 26.     Draughts
119
119
120120 27.     Golf
121121 Status: gfx issues
122
122
123123 28.     Cockpit
124124 Status: gfx issues
125
125
126126 29.     Metropolis / Hangman
127127 Status: gfx issues
128
128
129129 30.     Solitaire
130
130
131131 31.     Casino
132132 Status: gfx issues, items missing and unplayable
133133 Controls: 1 or 3=START; q=GO; E=STOP; D=$; Z=^; X=tens; C=units
134
134
135135 32.     Invaders / Alien Invasion / Earth Invasion
136136 Status: Works
137137 Config: Buttons
138
138
139139 33.     Super Invaders
140140 Status: Stars are missing, colours are wrong
141141 Config: Buttons (90)
142
142
143143 36.     BackGammon
144144 Status: Not all counters are visible, Dice & game number not visible.
145145 Controls: Fire=Exec; 1=D+; 3=D-; Q,W,E=4,5,6; A,S,D=1,2,3; Z=CL; X=STOP; C=SET
146
146
147147 37.     Monster Man / Spider's Web
148148 Status: Works
149149 Config: Buttons
150
150
151151 38.     Hyperspace
152152 Status: Works
153153 Config: Buttons (90)
154154 Controls: 3 - status button; Q,W,E,A,S,D,Z,X,C selects which galaxy to visit
155 
156 
155
156
157157 40.     Super Space
158158 Status: Works, some small gfx issues near the bottom
159159 Config: Buttons
160 
161 
162 
160
161
162
163163 Acetronic: (dumps are compatible)
164164 ------------
165
165
166166 * Shooting Gallery
167167 Status: works but screen flickers
168168 Config: Buttons
169
169
170170 * Planet Defender
171171 Status: Works
172172 Config: Paddle (NAC)
173
173
174174 * Laser Attack
175175 Status: Works
176176 Config: Buttons
177 
178 
179 
177
178
179
180180 Public Domain: (written for emulators, may not work on real hardware)
181181 ---------------
182182 * Picture (no controls) - works
trunk/src/emu/bus/vc4000/slot.c
r32760r32761
169169         seterror(IMAGE_ERROR_UNSPECIFIED, "Image extends beyond the expected size for a VC4000 cart");
170170         return IMAGE_INIT_FAIL;
171171      }
172     
172
173173      m_cart->rom_alloc(size, tag());
174         
174
175175      if (software_entry() == NULL)
176176         fread(m_cart->get_rom_base(), size);
177177      else
r32760r32761
236236         type = VC4000_CHESS2;
237237      else if (size > 0x0800) // some 4k roms have 1k of mirrored ram
238238         type = VC4000_RAM1K;
239     
239
240240      slot_string = vc4000_get_slot(type);
241241
242242      //printf("type: %s\n", slot_string);
r32760r32761
294294   if (m_cart)
295295      m_cart->write_ram(space, offset, data);
296296}
297
298
trunk/src/emu/bus/vc4000/rom.h
r32760r32761
3131public:
3232   // construction/destruction
3333   vc4000_ram1k_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
34   
34
3535   // reading and writing
3636   virtual DECLARE_READ8_MEMBER(read_ram);
3737   virtual DECLARE_WRITE8_MEMBER(write_ram);
r32760r32761
4444public:
4545   // construction/destruction
4646   vc4000_chess2_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
47   
47
4848   // reading and writing
4949   virtual DECLARE_READ8_MEMBER(extra_rom);
5050   virtual DECLARE_READ8_MEMBER(read_ram);
trunk/src/emu/bus/vc4000/slot.h
r32760r32761
3939   UINT32 get_rom_size() { return m_rom_size; }
4040   UINT32 get_ram_size() { return m_ram.count(); }
4141
42   void save_ram()   { device().save_item(NAME(m_ram)); }
42   void save_ram() { device().save_item(NAME(m_ram)); }
4343
4444protected:
4545   // internal state
r32760r32761
7171
7272   int get_type() { return m_type; }
7373
74   void save_ram()   { if (m_cart && m_cart->get_ram_size()) m_cart->save_ram(); }
74   void save_ram() { if (m_cart && m_cart->get_ram_size()) m_cart->save_ram(); }
7575
7676   virtual iodevice_t image_type() const { return IO_CARTSLOT; }
7777   virtual bool is_readable()  const { return 1; }
r32760r32761
112112
113113#define MCFG_VC4000_CARTRIDGE_ADD(_tag,_slot_intf,_def_slot) \
114114   MCFG_DEVICE_ADD(_tag, VC4000_CART_SLOT, 0) \
115   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false) \
116
115   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false)
117116#endif
trunk/src/emu/bus/vboy/slot.c
r32760r32761
151151      if (slot_list[i].pcb_id == type)
152152         return slot_list[i].slot_option;
153153   }
154   
154
155155   return "vb_rom";
156156}
157157#endif
r32760r32761
179179      m_cart->rom_alloc(0x200000, tag());
180180      if (has_eeprom)
181181         m_cart->eeprom_alloc(get_software_region_length("eeprom"));
182         
182
183183      ROM = (UINT8 *)m_cart->get_rom_base();
184184
185185      if (software_entry() == NULL)
r32760r32761
190190      if (len < 0x080000) { memcpy(ROM + 0x040000, ROM, 0x040000); }
191191      if (len < 0x100000) { memcpy(ROM + 0x080000, ROM, 0x080000); }
192192      if (len < 0x200000) { memcpy(ROM + 0x100000, ROM, 0x100000); }
193     
193
194194      if (software_entry() == NULL)
195195         m_type = vboy_get_pcb_id("vb_rom");
196196      else
trunk/src/emu/bus/vboy/rom.h
r32760r32761
1515   // construction/destruction
1616   vboy_rom_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
1717   vboy_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
18   
18
1919   // device-level overrides
2020   virtual void device_start() {}
21   
21
2222   // reading and writing
2323   virtual DECLARE_READ32_MEMBER(read_cart);
2424};
trunk/src/emu/bus/vboy/slot.h
r32760r32761
3737   UINT32 get_rom_size() { return m_rom_size; }
3838   UINT32 get_eeprom_size() { return m_eeprom.count(); }
3939
40   void save_eeprom()   { device().save_item(NAME(m_eeprom)); }
40   void save_eeprom()  { device().save_item(NAME(m_eeprom)); }
4141
4242protected:
4343   // internal state
r32760r32761
7171   int get_type() { return m_type; }
7272   int get_cart_type(UINT8 *ROM, UINT32 len);
7373
74   void save_eeprom()   { if (m_cart && m_cart->get_eeprom_size()) m_cart->save_eeprom(); }
74   void save_eeprom()  { if (m_cart && m_cart->get_eeprom_size()) m_cart->save_eeprom(); }
7575
7676   virtual iodevice_t image_type() const { return IO_CARTSLOT; }
7777   virtual bool is_readable()  const { return 1; }
r32760r32761
111111
112112#define MCFG_VBOY_CARTRIDGE_ADD(_tag,_slot_intf,_def_slot) \
113113   MCFG_DEVICE_ADD(_tag, VBOY_CART_SLOT, 0) \
114   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false) \
115
114   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false)
116115#endif
trunk/src/emu/bus/gba/gba_slot.h
r32760r32761
4242   UINT32 get_nvram_size() { return m_nvram.bytes(); }
4343   void set_rom_size(UINT32 val) { m_rom_size = val; }
4444
45   void save_nvram()   { device().save_item(NAME(m_nvram)); }
45   void save_nvram()   { device().save_item(NAME(m_nvram)); }
4646
4747   // internal state
4848   UINT32 *m_rom;  // this points to the cart rom region
r32760r32761
7777   void setup_ram(UINT8 banks);
7878   void internal_header_logging(UINT8 *ROM, UINT32 len);
7979
80   void save_nvram()   { if (m_cart && m_cart->get_nvram_size()) m_cart->save_nvram(); }
80   void save_nvram()   { if (m_cart && m_cart->get_nvram_size()) m_cart->save_nvram(); }
8181
8282   virtual iodevice_t image_type() const { return IO_CARTSLOT; }
8383   virtual bool is_readable()  const { return 1; }
r32760r32761
175175   { "BR4J", GBA_CHIP_FLASH      }, // 1586 - Rockman EXE 4.5 - Real Operation (JPN)
176176   { "BG8J", GBA_CHIP_EEPROM_64K }, // 1853 - Ganbare! Dodge Fighters (JPN)
177177   { "AROP", GBA_CHIP_EEPROM_4K  }, // 1862 - Rocky (EUR)
178//   "A2YE" - 1906 - Top Gun - Combat Zones (USA) - multiple NVRAM chips detected, but none present (protection against emu?)
178//  "A2YE" - 1906 - Top Gun - Combat Zones (USA) - multiple NVRAM chips detected, but none present (protection against emu?)
179179   { "BKMJ", GBA_CHIP_EEPROM_4K  }, // 2039 - Kim Possible (JPN)
180180   { "BKEJ", GBA_CHIP_EEPROM_64K }, // 2047 - Konjiki no Gashbell - The Card Battle for GBA (JPN)
181181   { "BKMP", GBA_CHIP_EEPROM_4K  }, // 2297 - Kim Possible 2 - Drakken's Demise (EUR)
trunk/src/emu/bus/vcs/vcs_slot.h
r32760r32761
1818   A26_F8SW,
1919   A26_FA,
2020   A26_FE,
21   A26_3E,      // to test
21   A26_3E,     // to test
2222   A26_3F,
2323   A26_E0,
2424   A26_E7,
r32760r32761
2626   A26_DC,
2727   A26_CV,
2828   A26_FV,
29   A26_JVP,   // to test
29   A26_JVP,    // to test
3030   A26_32IN1,
3131   A26_8IN1,
3232   A26_4IN1,
r32760r32761
4949   virtual DECLARE_READ8_MEMBER(read_rom) { return 0xff; }
5050   // writing to RAM chips (sometimes it is in a different range than write_bank!)
5151   virtual DECLARE_WRITE8_MEMBER(write_ram) {}
52   
52
5353   // read/write to bankswitch address
5454   virtual DECLARE_READ8_MEMBER(read_bank) { return 0xff; }
5555   virtual DECLARE_WRITE8_MEMBER(write_bank) {}
trunk/src/emu/bus/vcs/rom.h
r32760r32761
3030public:
3131   // construction/destruction
3232   a26_rom_4k_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
33   
33
3434   // reading and writing
3535
3636   // accesses just use the 2K ones, since it is just direct access to ROM/RAM
r32760r32761
4646   // construction/destruction
4747   a26_rom_f6_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
4848   a26_rom_f6_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
49   
49
5050   // device-level overrides
5151   virtual void device_start();
5252   virtual void device_reset();
53   
53
5454   // reading and writing
5555   virtual DECLARE_READ8_MEMBER(read_rom);
5656   virtual DECLARE_WRITE8_MEMBER(write_bank);
5757   virtual DECLARE_DIRECT_UPDATE_MEMBER(cart_opbase);
58   
58
5959protected:
6060   int m_base_bank;
6161};
r32760r32761
6868public:
6969   // construction/destruction
7070   a26_rom_f4_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
71   
71
7272   // device-level overrides
7373   virtual void device_reset();
74   
74
7575   // reading and writing
7676   virtual DECLARE_READ8_MEMBER(read_rom);
7777   virtual DECLARE_WRITE8_MEMBER(write_bank);
r32760r32761
8686   // construction/destruction
8787   a26_rom_f8_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
8888   a26_rom_f8_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
89   
89
9090   // reading and writing
9191   virtual DECLARE_READ8_MEMBER(read_rom);
9292   virtual DECLARE_WRITE8_MEMBER(write_bank);
r32760r32761
100100public:
101101   // construction/destruction
102102   a26_rom_f8_sw_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
103   
103
104104   // device-level overrides
105105   virtual void device_reset();
106106};
r32760r32761
113113public:
114114   // construction/destruction
115115   a26_rom_fa_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
116   
116
117117   // reading and writing
118118   virtual DECLARE_READ8_MEMBER(read_rom);
119119   virtual DECLARE_WRITE8_MEMBER(write_bank);
r32760r32761
127127public:
128128   // construction/destruction
129129   a26_rom_fe_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
130   
130
131131   // device-level overrides
132132   virtual void device_start();
133133   virtual void device_reset();
134   
134
135135   // reading and writing
136136   virtual DECLARE_READ8_MEMBER(read_rom);
137137   virtual DECLARE_READ8_MEMBER(read_bank);
138138   virtual DECLARE_WRITE8_MEMBER(write_ram);
139139   virtual DECLARE_WRITE8_MEMBER(write_bank);
140   
140
141141protected:
142142   int m_base_bank;
143143   int m_trigger_on_next_access;
r32760r32761
151151public:
152152   // construction/destruction
153153   a26_rom_3e_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
154   
154
155155   // device-level overrides
156156   virtual void device_start();
157157   virtual void device_reset();
158   
158
159159   // reading and writing
160160   virtual DECLARE_READ8_MEMBER(read_rom);
161161   virtual DECLARE_WRITE8_MEMBER(write_bank);
162162   virtual DECLARE_WRITE8_MEMBER(write_ram);
163   
163
164164protected:
165165   int m_num_bank;
166166   int m_ram_bank;
r32760r32761
175175public:
176176   // construction/destruction
177177   a26_rom_3f_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
178   
178
179179   // device-level overrides
180180   virtual void device_reset();
181   
181
182182   // reading and writing
183183   virtual DECLARE_READ8_MEMBER(read_rom);
184184   virtual DECLARE_WRITE8_MEMBER(write_bank);
185   
185
186186protected:
187187   int m_num_bank;
188188};
r32760r32761
195195public:
196196   // construction/destruction
197197   a26_rom_e0_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
198   
198
199199   // device-level overrides
200200   virtual void device_start();
201201   virtual void device_reset();
202   
202
203203   // reading and writing
204204   virtual DECLARE_READ8_MEMBER(read_rom);
205205   virtual DECLARE_WRITE8_MEMBER(write_bank);
206   
206
207207protected:
208208   int m_base_banks[4];
209209};
r32760r32761
216216public:
217217   // construction/destruction
218218   a26_rom_e7_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
219   
219
220220   // device-level overrides
221221   virtual void device_start();
222222   virtual void device_reset();
223   
223
224224   // reading and writing
225225   virtual DECLARE_READ8_MEMBER(read_rom);
226226   virtual DECLARE_WRITE8_MEMBER(write_bank);
227   
227
228228protected:
229229   int m_ram_bank;
230230};
r32760r32761
237237public:
238238   // construction/destruction
239239   a26_rom_ua_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
240   
240
241241   // device-level overrides
242242   virtual void device_reset();
243   
243
244244   // reading and writing
245245   virtual DECLARE_READ8_MEMBER(read_rom);
246246   virtual DECLARE_READ8_MEMBER(read_bank);
r32760r32761
255255public:
256256   // construction/destruction
257257   a26_rom_cv_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
258   
258
259259   // reading and writing
260260   virtual DECLARE_READ8_MEMBER(read_rom);
261261   virtual DECLARE_WRITE8_MEMBER(write_bank);
r32760r32761
269269public:
270270   // construction/destruction
271271   a26_rom_dc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
272   
272
273273   // reading and writing
274274   virtual DECLARE_READ8_MEMBER(read_rom);
275275   virtual DECLARE_WRITE8_MEMBER(write_bank);
r32760r32761
283283public:
284284   // construction/destruction
285285   a26_rom_fv_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
286   
286
287287   // device-level overrides
288288   virtual void device_start();
289289   virtual void device_reset();
290   
290
291291   // reading and writing
292292   virtual DECLARE_READ8_MEMBER(read_rom);
293293   virtual DECLARE_WRITE8_MEMBER(write_bank);
294   
294
295295protected:
296296   int m_locked;
297297};
r32760r32761
304304public:
305305   // construction/destruction
306306   a26_rom_jvp_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
307   
307
308308   // reading and writing
309309   virtual DECLARE_READ8_MEMBER(read_rom);
310310   virtual DECLARE_WRITE8_MEMBER(write_bank);
r32760r32761
318318public:
319319   // construction/destruction
320320   a26_rom_4in1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
321   
321
322322   // device-level overrides
323323   virtual void device_reset();
324   
324
325325   // reading and writing
326326   virtual DECLARE_READ8_MEMBER(read_rom);
327327};
r32760r32761
334334public:
335335   // construction/destruction
336336   a26_rom_8in1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
337   
337
338338   // device-level overrides
339339   virtual void device_start();
340340   virtual void device_reset();
341   
341
342342   // reading and writing
343343   virtual DECLARE_READ8_MEMBER(read_rom);
344344
r32760r32761
354354public:
355355   // construction/destruction
356356   a26_rom_32in1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
357   
357
358358   // device-level overrides
359359   virtual void device_reset();
360   
360
361361   // reading and writing
362362   virtual DECLARE_READ8_MEMBER(read_rom);
363363};
trunk/src/emu/bus/vcs/scharger.h
r32760r32761
2222   virtual void device_reset();
2323
2424   required_device<cassette_image_device> m_cassette;
25   
25
2626   // reading and writing
2727   virtual DECLARE_READ8_MEMBER(read_rom);
28   
28
2929private:
3030   cpu_device   *m_maincpu;
3131   inline UINT8 read_byte(UINT32 offset);
32   
32
3333   int m_base_banks[2];
3434   UINT8 m_reg;
3535   UINT8 m_write_delay, m_ram_write_enabled, m_rom_enabled;
trunk/src/emu/bus/vcs/compumat.c
r32760r32761
11/***************************************************************************
22
3 Atari 2600 cart Spectravideo Compumate (Cart + keyboard!)
3 Atari 2600 cart Spectravideo Compumate (Cart + keyboard!)
44
55 This is tricky to implement and it is only a skeleton ATM.
66 The device needs to interface with both the TIA and the RIOT.
7
7
88***************************************************************************/
99
1010
trunk/src/emu/bus/vcs/dpc.c
r32760r32761
3737      m_df[data_fetcher].music_mode = 0;
3838   }
3939   m_oscillator->adjust(attotime::from_hz(18400), 0, attotime::from_hz(18400));
40   
40
4141}
4242
4343void dpc_device::check_flag(UINT8 data_fetcher)
r32760r32761
6060      if (data_fetcher > 4 && m_df[data_fetcher].music_mode)
6161         m_df[data_fetcher].low = m_df[data_fetcher].top;
6262   }
63   
63
6464   check_flag(data_fetcher);
6565}
6666
r32760r32761
149149            data = m_df[data_fetcher].flag ? 0xff : 0x00;
150150            break;
151151      }
152     
152
153153      if (data_fetcher < 5 || !m_df[data_fetcher].osc_clk)
154154      {
155155         decrement_counter(data_fetcher);
r32760r32761
161161WRITE8_MEMBER(dpc_device::write)
162162{
163163   UINT8 data_fetcher = offset & 0x07;
164   
164
165165   switch (offset & 0x38)
166166   {
167167      case 0x00:          // Top count
r32760r32761
235235   m_base_bank = 0;
236236}
237237
238void a26_rom_dpc_device::setup_addon_ptr(UINT8 *ptr)
238void a26_rom_dpc_device::setup_addon_ptr(UINT8 *ptr)
239239{
240240   m_dpc->set_display_data(ptr);
241241}
r32760r32761
279279   }
280280   return address;
281281}
282
trunk/src/emu/bus/vcs/compumat.h
r32760r32761
1919   virtual void device_start();
2020   virtual ioport_constructor device_input_ports() const;
2121   virtual void device_reset();
22   
22
2323   // reading and writing
2424   virtual DECLARE_READ8_MEMBER(read_rom);
25   
25
2626private:
2727};
2828
trunk/src/emu/bus/vcs/dpc.h
r32760r32761
1919   UINT8   osc_clk;        /* Only used by data fetchers 5,6, and 7 */
2020};
2121
22//   m_dpc.oscillator = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(a2600_state::modeDPC_timer_callback),this));
22//  m_dpc.oscillator = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(a2600_state::modeDPC_timer_callback),this));
2323
2424class dpc_device : public device_t
2525{
r32760r32761
7474   virtual void device_reset();
7575
7676   required_device<dpc_device> m_dpc;
77   
77
7878   // reading and writing
7979   virtual DECLARE_READ8_MEMBER(read_rom);
8080   virtual DECLARE_WRITE8_MEMBER(write_bank);
8181   virtual DECLARE_DIRECT_UPDATE_MEMBER(cart_opbase);
8282
8383   virtual void setup_addon_ptr(UINT8 *ptr);
84   
84
8585protected:
86//   int m_reset_bank;
86//  int m_reset_bank;
8787};
8888
8989
trunk/src/emu/bus/vcs/vcs_slot.c
r32760r32761
186186   {
187187      UINT8 *ROM;
188188      UINT32 len;
189     
189
190190      if (software_entry() != NULL)
191191         len = get_software_region_length("rom");
192192      else
193193         len = length();
194     
194
195195      //printf("Size: 0x%X\n", len);
196     
196
197197      // check that filesize is among the supported ones
198198      switch (len)
199199      {
r32760r32761
208208         case 0x10000:
209209         case 0x80000:
210210            break;
211           
211
212212         default:
213213            seterror(IMAGE_ERROR_UNSUPPORTED, "Invalid rom file size" );
214214            return IMAGE_INIT_FAIL;
215215      }
216     
216
217217      m_cart->rom_alloc(len, tag());
218218      ROM = m_cart->get_rom_base();
219     
219
220220      if (software_entry() != NULL)
221221      {
222222         const char *pcb_name;
223223         bool has_ram = get_software_region("ram") ? TRUE : FALSE;
224224         memcpy(ROM, get_software_region("rom"), len);
225         
225
226226         if ((pcb_name = get_feature("slot")) != NULL)
227227            m_type = vcs_get_pcb_id(pcb_name);
228228         else
r32760r32761
272272      {
273273         fread(ROM, len);
274274         m_type = identify_cart_type(ROM, len);
275         
275
276276         // check for Special Chip (128bytes of RAM)
277277         if (len == 0x2000 || len == 0x4000 || len == 0x8000)
278278            if (detect_super_chip(ROM, len))
r32760r32761
284284         // dig dig, crystal castles, millipede, stargate, defender ii, jr. Pac Man,
285285         // desert falcon, dark chambers, super football, sprintmaster, fatal run,
286286         // off the wall, shooting arcade, secret quest, radar lock, save mary, klax
287         
287
288288         // add CBS RAM+ (256bytes of RAM)
289289         if (m_type == A26_FA)
290290            m_cart->ram_alloc(0x100);
r32760r32761
301301         else if (m_type == A26_3E)
302302            m_cart->ram_alloc(0x8000);
303303      }
304     
304
305305      //printf("Type: %s\n", vcs_get_slot(m_type));
306     
306
307307      // pass a pointer to the now allocated ROM for the DPC chip
308308      if (m_type == A26_DPC)
309309         m_cart->setup_addon_ptr((UINT8 *)m_cart->get_rom_base() + 0x2000);
310     
310
311311      return IMAGE_INIT_PASS;
312312   }
313   
313
314314   return IMAGE_INIT_PASS;
315315}
316316
r32760r32761
356356         }
357357      }
358358   }
359   if (numfound)
359   if (numfound)
360360      return 1;
361361   return 0;
362362}
r32760r32761
376376         }
377377      }
378378   }
379   if (numfound)
379   if (numfound)
380380      return 1;
381381   return 0;
382382}
r32760r32761
408408         }
409409      }
410410   }
411   if (numfound)
411   if (numfound)
412412      return 1;
413413   return 0;
414414}
r32760r32761
428428         }
429429      }
430430   }
431   if (numfound)
431   if (numfound)
432432      return 1;
433433   return 0;
434434}
r32760r32761
456456         }
457457      }
458458   }
459   if (numfound)
459   if (numfound)
460460      return 1;
461461   return 0;
462462}
r32760r32761
486486         }
487487      }
488488   }
489   if (numfound)
489   if (numfound)
490490      return 1;
491491   return 0;
492492}
r32760r32761
512512         }
513513      }
514514   }
515   if (numfound)
515   if (numfound)
516516      return 1;
517517   return 0;
518518}
r32760r32761
535535         }
536536      }
537537   }
538   if (numfound)
538   if (numfound)
539539      return 1;
540540   return 0;
541541}
r32760r32761
561561         }
562562      }
563563   }
564   if (numfound)
564   if (numfound)
565565      return 1;
566566   return 0;
567567}
r32760r32761
587587         }
588588      }
589589   }
590   if (numfound)
590   if (numfound)
591591      return 1;
592592   return 0;
593593}
r32760r32761
607607         }
608608      }
609609   }
610   if (numfound)
610   if (numfound)
611611      return 1;
612612   return 0;
613613}
r32760r32761
633633         }
634634      }
635635   }
636   if (numfound == 0x03)
636   if (numfound == 0x03)
637637      return 1;
638638   return 0;
639639}
r32760r32761
653653         }
654654      }
655655   }
656   if (numfound > 1)
656   if (numfound > 1)
657657      return 1;
658658   return 0;
659659}
r32760r32761
705705   int type = 0xff;
706706
707707   // auto-detect bank mode
708   if (detect_modeDC(ROM, len))
708   if (detect_modeDC(ROM, len))
709709      type = A26_DC;
710   else if (detect_mode3E(ROM, len))
710   else if (detect_mode3E(ROM, len))
711711      type = A26_3E;
712   else if (detect_modeFE(ROM, len))
712   else if (detect_modeFE(ROM, len))
713713      type = A26_FE;
714   else if (detect_modeSS(ROM, len))
714   else if (detect_modeSS(ROM, len))
715715      type = A26_SS;
716   else if (detect_modeE0(ROM, len))
716   else if (detect_modeE0(ROM, len))
717717      type = A26_E0;
718718   else if (detect_modeCV(ROM, len))
719719      type = A26_CV;
720   else if (detect_modeFV(ROM, len))
720   else if (detect_modeFV(ROM, len))
721721      type = A26_FV;
722   else if (detect_modeJVP(ROM, len))
722   else if (detect_modeJVP(ROM, len))
723723      type = A26_JVP;
724   else if (detect_modeUA(ROM, len))
724   else if (detect_modeUA(ROM, len))
725725      type = A26_UA;
726   else if (detect_8K_mode3F(ROM, len))
726   else if (detect_8K_mode3F(ROM, len))
727727      type = A26_3F;
728   else if (detect_32K_mode3F(ROM, len))
728   else if (detect_32K_mode3F(ROM, len))
729729      type = A26_3F;
730   else if (detect_modeE7(ROM, len))
730   else if (detect_modeE7(ROM, len))
731731      type = A26_E7;
732732   else if (detect_snowhite(ROM, len))
733733      type = A26_F8SW;
734   
734
735735   // otherwise, choose based on size
736736   if (type == 0xff)
737737   {
r32760r32761
771771            break;
772772      }
773773   }
774   
774
775775   return type;
776776}
777777
r32760r32761
787787      UINT32 len = core_fsize(m_file);
788788      dynamic_buffer rom(len);
789789      int type;
790     
790
791791      core_fread(m_file, rom, len);
792     
792
793793      type = identify_cart_type(rom, len);
794794      slot_string = vcs_get_slot(type);
795     
795
796796      clear();
797     
797
798798      result.cpy(slot_string);
799799   }
800800   else
trunk/src/emu/bus/vcs/rom.c
r32760r32761
6262
6363a26_rom_f6_device::a26_rom_f6_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source)
6464               : a26_rom_2k_device(mconfig, type, name, tag, owner, clock, shortname, source),
65                  m_base_bank(-1)   // set to -1 to help the Xin1 multicart...
65                  m_base_bank(-1) // set to -1 to help the Xin1 multicart...
6666{
6767}
6868
6969a26_rom_f6_device::a26_rom_f6_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
7070               : a26_rom_2k_device(mconfig, A26_ROM_F6, "Atari VCS 2600 ROM Carts w/F6 bankswitch", tag, owner, clock, "vcs_f6", __FILE__),
71                  m_base_bank(-1)   // set to -1 to help the Xin1 multicart...
71                  m_base_bank(-1) // set to -1 to help the Xin1 multicart...
7272{
7373}
7474
r32760r32761
337337
338338/*-------------------------------------------------
339339 "F4 Bankswitch" Carts:
340 read/write access to 0x1ff4-0x1ffb determines the
340 read/write access to 0x1ff4-0x1ffb determines the
341341 4K ROM bank to be read
342342
343343 GAMES: Fatal Run
r32760r32761
350350   {
351351      return m_ram[offset & (m_ram.count() - 1)];
352352   }
353   
353
354354   // update banks
355355   if (!space.debugger_access())
356356   {
r32760r32761
368368            break;
369369      }
370370   }
371   
371
372372   return m_rom[offset + (m_base_bank * 0x1000)];
373373}
374374
r32760r32761
380380      m_ram[offset & (m_ram.count() - 1)] = data;
381381      return;
382382   }
383   
383
384384   switch (offset)
385385   {
386386      case 0x0ff4:
r32760r32761
401401
402402/*-------------------------------------------------
403403 "F6 Bankswitch" Carts:
404 read/write access to 0x1ff6-0x1ff9 determines the
404 read/write access to 0x1ff6-0x1ff9 determines the
405405 4K ROM bank to be read
406406
407 GAMES: Atari 16K games, like Crossbow, Crystal
407 GAMES: Atari 16K games, like Crossbow, Crystal
408408 Castles and the 2-in-1 carts
409409
410410 -------------------------------------------------*/
r32760r32761
469469
470470/*-------------------------------------------------
471471 "F8 Bankswitch" Carts:
472 read/write access to 0x1ff8-0x1ff9 determines the
472 read/write access to 0x1ff8-0x1ff9 determines the
473473 4K ROM bank to be read
474474
475475 GAMES: Atari 8K games, like Asteroids, Battlezone
r32760r32761
484484   {
485485      return m_ram[offset & (m_ram.count() - 1)];
486486   }
487   
487
488488   // update banks
489489   if (!space.debugger_access())
490490   {
r32760r32761
496496            break;
497497      }
498498   }
499   
499
500500   return m_rom[offset + (m_base_bank * 0x1000)];
501501}
502502
r32760r32761
508508      m_ram[offset & (m_ram.count() - 1)] = data;
509509      return;
510510   }
511   
511
512512   switch (offset)
513513   {
514514      case 0x0ff8:
r32760r32761
523523
524524/*-------------------------------------------------
525525 "FA Bankswitch" Carts:
526 read/write access to 0x1ff8-0x1ffa determines the
526 read/write access to 0x1ff8-0x1ffa determines the
527527 4K ROM bank to be read
528 These games contained the CBS RAM+ chip (256bytes
528 These games contained the CBS RAM+ chip (256bytes
529529 of RAM)
530 
531 GAMES: CBS RAM Plus games like Omega Race and Tunnel
530
531 GAMES: CBS RAM Plus games like Omega Race and Tunnel
532532 Runner
533533
534534 -------------------------------------------------*/
r32760r32761
540540   {
541541      return m_ram[offset & (m_ram.count() - 1)];
542542   }
543   
543
544544   // update banks
545545   if (!space.debugger_access())
546546   {
r32760r32761
553553            break;
554554      }
555555   }
556   
556
557557   return m_rom[offset + (m_base_bank * 0x1000)];
558558}
559559
r32760r32761
563563   if (m_ram && offset < 0x100)
564564   {
565565      m_ram[offset & (m_ram.count() - 1)] = data;
566   }   
567   
566   }
567
568568   switch (offset)
569569   {
570570      case 0x0ff8:
r32760r32761
580580
581581/*-------------------------------------------------
582582 "FE Bankswitch" Carts:
583 read/write access to 0x01fe-0x1ff determines the
583 read/write access to 0x01fe-0x1ff determines the
584584 4K ROM bank to be read
585
585
586586 GAMES: Activision 8K games like Decathlon
587587
588588 -------------------------------------------------*/
589589/*
590
590
591591 There seems to be a kind of lag between the writing to address 0x1FE and the
592592 Activision switcher springing into action. It waits for the next byte to arrive
593593 on the data bus, which is the new PCH in the case of a JSR, and the PCH of the
594594 stored PC on the stack in the case of an RTS.
595
595
596596 depending on last byte & 0x20 -> 0x00 -> switch to bank #1
597597 -> 0x20 -> switch to bank #0
598
598
599599 */
600600
601601READ8_MEMBER(a26_rom_fe_device::read_rom)
r32760r32761
607607   {
608608      return m_ram[offset & (m_ram.count() - 1)];
609609   }
610   
610
611611   data = m_rom[offset + (m_base_bank * 0x1000)];
612   
612
613613   if (!space.debugger_access())
614614   {
615615      if (m_trigger_on_next_access)
r32760r32761
618618         m_trigger_on_next_access = 0;
619619      }
620620   }
621   
621
622622   return data;
623623}
624624
r32760r32761
634634READ8_MEMBER(a26_rom_fe_device::read_bank)
635635{
636636   UINT8 data = space.read_byte(0xfe + offset);
637   
637
638638   if (!space.debugger_access())
639639   {
640640      switch (offset & 1)
r32760r32761
643643            // The next byte on the data bus determines which bank to switch to
644644            m_trigger_on_next_access = 1;
645645            break;
646           
646
647647         case 1:
648648            if (m_trigger_on_next_access)
649649            {
r32760r32761
667667}
668668
669669/*-------------------------------------------------
670 "3E Bankswitch" Carts:
671 write access to 0x3e determines the 2K ROM bank to
672 be read, write access to 0x3f determines the RAM bank
670 "3E Bankswitch" Carts:
671 write access to 0x3e determines the 2K ROM bank to
672 be read, write access to 0x3f determines the RAM bank
673673 to be read
674
674
675675 GAMES: Boulder Dash (Homebrew)
676676
677677 -------------------------------------------------*/
r32760r32761
680680{
681681   if (m_ram && m_ram_enable && offset < 0x400)
682682      return m_ram[offset + (m_ram_bank * 0x400)];
683   
683
684684   if (offset >= 0x800)
685685      return m_rom[(offset & 0x7ff) + (m_num_bank - 1) * 0x800];
686686   else
r32760r32761
709709
710710
711711/*-------------------------------------------------
712 "3F Bankswitch" Carts:
713 write access to 0x00-0x3f determines the 2K ROM bank
712 "3F Bankswitch" Carts:
713 write access to 0x00-0x3f determines the 2K ROM bank
714714 to be read
715715
716 GAMES: Tigervision 8K games like Espial and Miner
716 GAMES: Tigervision 8K games like Espial and Miner
717717 2049er. Extended version with bankswitch up to 512K
718718 shall be supported as well (but we lack a test case)
719719
r32760r32761
733733}
734734
735735/*-------------------------------------------------
736 "E0 Bankswitch" Carts:
737 read/write access to 0x1fe0-0x1ff8 determines the
736 "E0 Bankswitch" Carts:
737 read/write access to 0x1fe0-0x1ff8 determines the
738738 1K ROM bank to be read in each 1K chunk (0x1c00-0x1fff
739739 always points to the last 1K of the ROM)
740740
r32760r32761
769769 1800-19ff is RAM
770770 1a00-1fff is fixed to the last 0x600 of ROM
771771
772 The selectable bank can be ROM (if selected by
773 0x1fe0-0x1fe6 access) or a first 1K of RAM (if
772 The selectable bank can be ROM (if selected by
773 0x1fe0-0x1fe6 access) or a first 1K of RAM (if
774774 selected by 0x1fe7 access).
775 The other 256byte RAM bank can be one of the
775 The other 256byte RAM bank can be one of the
776776 four different chunks forming the other 1K of RAM
777777 (the bank is selected by accessing 0x1fe8-0x1feb)
778778
779 GAMES: M Network 16K games like Burgertime and
779 GAMES: M Network 16K games like Burgertime and
780780 Bump'n Jump
781
781
782782 -------------------------------------------------*/
783783
784784READ8_MEMBER(a26_rom_e7_device::read_rom)
r32760r32761
833833}
834834
835835/*-------------------------------------------------
836 "UA Bankswitch" Carts:
837 read/write access to 0x200-0x27f determines the
836 "UA Bankswitch" Carts:
837 read/write access to 0x200-0x27f determines the
838838 4K ROM bank to be read (0x220-0x23f for low 4K,
839839 0x240-0x27f for high 4K)
840840
841 GAMES: UA Ltd. 8K games like Funky Flash and
841 GAMES: UA Ltd. 8K games like Funky Flash and
842842 Pleaides
843843
844844 -------------------------------------------------*/
r32760r32761
863863
864864
865865/*-------------------------------------------------
866 Commavid Carts:
866 Commavid Carts:
867867 It allows for both ROM and RAM on the cartridge,
868 without using bankswitching.  There's 2K of ROM
868 without using bankswitching.  There's 2K of ROM
869869 and 1K of RAM.
870870
871871 GAMES: Magicard and Video Life by Commavid
r32760r32761
894894
895895
896896/*-------------------------------------------------
897 Dynacom Megaboy Carts (aka "F0 Banswitch"):
898 read/write access to 0x1ff0 determines the 4K ROM
897 Dynacom Megaboy Carts (aka "F0 Banswitch"):
898 read/write access to 0x1ff0 determines the 4K ROM
899899 bank to be read (each access increases the bank index
900900 up to 16, since the cart was 64K wide)
901901
r32760r32761
925925
926926
927927/*-------------------------------------------------
928 "FV Bankswitch" Carts:
929 The first access to 0x1fd0 switch the bank, but
928 "FV Bankswitch" Carts:
929 The first access to 0x1fd0 switch the bank, but
930930 only if pc() & 0x1f00 == 0x1f00!
931931
932932 GAMES: Challenge by HES
r32760r32761
964964
965965
966966/*-------------------------------------------------
967 "JVP Bankswitch" Carts:
968 read/write access to 0x0fa0-0x0fc0 determines the
967 "JVP Bankswitch" Carts:
968 read/write access to 0x0fa0-0x0fc0 determines the
969969 4K ROM bank to be read (notice that this overlaps
970970 the RIOT, currently handled in the main driver until
971971 I can better investigate the behavior)
972
972
973973 GAMES: No test case!?!
974
974
975975 -------------------------------------------------*/
976976
977977READ8_MEMBER(a26_rom_jvp_device::read_rom)
r32760r32761
997997/*-------------------------------------------------
998998 4 in 1 Carts (Reset based):
999999 the 4K bank changes at each reset
1000
1000
10011001 GAMES: 4 in 1 carts
1002
1002
10031003 -------------------------------------------------*/
10041004
10051005READ8_MEMBER(a26_rom_4in1_device::read_rom)
r32760r32761
10121012 8 in 1 Carts (Reset based):
10131013 the 8K banks change at each reset, and internally
10141014 each game runs as a F8-bankswitched cart
1015
1015
10161016 GAMES: 8 in 1 cart
1017
1017
10181018 -------------------------------------------------*/
10191019
10201020READ8_MEMBER(a26_rom_8in1_device::read_rom)
r32760r32761
10291029            break;
10301030      }
10311031   }
1032   
1032
10331033   return m_rom[offset + (m_base_bank * 0x1000) + (m_reset_bank * 0x2000)];
10341034}
10351035
r32760r32761
10371037/*-------------------------------------------------
10381038 32 in 1 Carts (Reset based):
10391039 the 2K banks change at each reset
1040
1040
10411041 GAMES: 32 in 1 cart
1042
1042
10431043 -------------------------------------------------*/
10441044
10451045READ8_MEMBER(a26_rom_32in1_device::read_rom)
10461046{
10471047   return m_rom[(offset & 0x7ff) + (m_base_bank * 0x800)];
10481048}
1049
trunk/src/emu/bus/vcs/scharger.c
r32760r32761
22
33 Atari 2600 cart Starpath Supercharger (Cart + Tape drive!)
44
5 
6 
5
6
77 From kevtris notes ( http://blog.kevtris.org/blogfiles/Atari%202600%20Mappers.txt ):
88
9
9
1010 - Control register [0x1ff8]
11
11
1212       7       0
1313       ---------
1414 1FF8: DDDB BBWE
15
15
1616 D: write delay (see below)
1717 B: bankswitching mode (see below)
1818 W: RAM write enable (1 = enabled, 0 = disabled)
1919 E: ROM power enable (0 = enabled, 1 = turn off ROM)
20
20
2121 - Audio input register [0x1ff9]
22
22
2323        7       0
24      ---------
24        ---------
2525 1FF9:  0000 000A
26
26
2727 A: Supercharger audio data.  0 = low input, 1 = high input.
28 
29 
28
29
3030***************************************************************************/
3131
3232
r32760r32761
8383   MCFG_CASSETTE_DEFAULT_STATE(CASSETTE_STOPPED | CASSETTE_MOTOR_ENABLED | CASSETTE_SPEAKER_ENABLED)
8484   MCFG_CASSETTE_INTERFACE("a2600_cass")
8585
86//   MCFG_SOUND_WAVE_ADD(WAVE_TAG, "cassette")
87//   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
86//  MCFG_SOUND_WAVE_ADD(WAVE_TAG, "cassette")
87//  MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
8888MACHINE_CONFIG_END
8989
9090machine_config_constructor a26_rom_ss_device::device_mconfig_additions() const
r32760r32761
109109   if (space.debugger_access())
110110      return read_byte(offset);
111111
112   // Bankswitch
112   // Bankswitch
113113   if (offset == 0xff8)
114114   {
115115      //logerror("%04X: Access to control register data = %02X\n", m_maincpu->pc(), m_modeSS_byte);
116116      m_write_delay = m_reg >> 5;
117117      m_ram_write_enabled = BIT(m_reg, 1);
118118      m_rom_enabled = !BIT(m_reg, 0);
119     
119
120120      // compensate time spent in this access to avoid spurious RAM write
121121      m_byte_started -= 5;
122     
122
123123      // handle bankswitch
124124      switch (m_reg & 0x1c)
125125      {
r32760r32761
164164   {
165165      //logerror("%04X: Cassette port read, tap_val = %f\n", m_maincpu->pc(), tap_val);
166166      double tap_val = m_cassette->input();
167     
167
168168      // compensate time spent in this access to avoid spurious RAM write
169169      m_byte_started -= 5;
170     
170
171171      if (tap_val < 0)
172172         return 0x00;
173173      else
r32760r32761
181181         /* Check for dummy read from same address */
182182         if (m_last_address == offset)
183183            m_diff_adjust++;
184         
184
185185         int diff = m_maincpu->total_cycles() - m_byte_started;
186186         //logerror("%04X: offset = %04X, %d\n", m_maincpu->pc(), offset, diff);
187187
trunk/src/emu/bus/wswan/slot.h
r32760r32761
4040   UINT32 get_rom_size() { return m_rom_size; }
4141   UINT32 get_nvram_size() { return m_nvram.count(); }
4242
43   void save_nvram()   { device().save_item(NAME(m_nvram)); }
43   void save_nvram()   { device().save_item(NAME(m_nvram)); }
4444   void set_has_rtc(bool val) { m_has_rtc = val; }
4545   void set_is_rotated(bool val) { m_is_rotated = val; }
4646   int get_is_rotated() { return m_is_rotated ? 1 : 0; }
r32760r32761
8181   int get_cart_type(UINT8 *ROM, UINT32 len, UINT32 &nvram_len);
8282   void internal_header_logging(UINT8 *ROM, UINT32 offs, UINT32 len);
8383
84   void save_nvram()   { if (m_cart && m_cart->get_nvram_size()) m_cart->save_nvram(); }
84   void save_nvram()   { if (m_cart && m_cart->get_nvram_size()) m_cart->save_nvram(); }
8585
8686   virtual iodevice_t image_type() const { return IO_CARTSLOT; }
8787   virtual bool is_readable()  const { return 1; }
r32760r32761
125125
126126#define MCFG_WSWAN_CARTRIDGE_ADD(_tag,_slot_intf,_def_slot) \
127127   MCFG_DEVICE_ADD(_tag, WS_CART_SLOT, 0) \
128   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false) \
129
128   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false)
130129#endif
trunk/src/emu/bus/wswan/rom.c
r32760r32761
154154      m_rtc_second++;
155155      if ((m_rtc_second & 0x0f) > 9)
156156         m_rtc_second = (m_rtc_second & 0xf0) + 0x10;
157     
157
158158      // check for minute passed
159159      if (m_rtc_second >= 0x60)
160160      {
r32760r32761
163163         if ((m_rtc_minute & 0x0f) > 9)
164164            m_rtc_minute = (m_rtc_minute & 0xf0) + 0x10;
165165      }
166     
166
167167      // check for hour passed
168168      if (m_rtc_minute >= 0x60)
169169      {
r32760r32761
174174         if (m_rtc_hour == 0x12)
175175            m_rtc_hour |= 0x80;
176176      }
177     
177
178178      // check for day passed
179179      if (m_rtc_hour >= 0x24)
180180      {
r32760r32761
217217      case 0x0b:      // RTC data
218218         if (!m_has_rtc)
219219            break;
220         
220
221221         if (m_io_regs[0x0a] == 0x95 && (m_rtc_index < 7))
222222         {
223223            switch (m_rtc_index)
r32760r32761
307307      case 0x0b:  // RTC Data
308308         if (!m_has_rtc)
309309            break;
310         
310
311311         if (m_io_regs[0x0a] == 0x94 && m_rtc_index < 7)
312312         {
313313            switch (m_rtc_index)
r32760r32761
339339}
340340
341341WRITE8_MEMBER(ws_rom_sram_device::write_io)
342{   
342{
343343   switch (offset)
344344   {
345345      case 0x01:  // SRAM bank to select
r32760r32761
354354READ8_MEMBER(ws_rom_eeprom_device::read_io)
355355{
356356   UINT8 value = m_io_regs[offset];
357   
357
358358   switch (offset)
359359   {
360360      case 0x04:
r32760r32761
368368         value = ws_rom_device::read_io(space, offset);
369369         break;
370370   }
371   
371
372372   return value;
373373}
374374
375375WRITE8_MEMBER(ws_rom_eeprom_device::write_io)
376{   
376{
377377   switch (offset)
378378   {
379379      case 0x06:  /* EEPROM address lower bits port/EEPROM address and command port
380                1KBit EEPROM:
381                Bit 0-5 - EEPROM address bit 1-6
382                Bit 6-7 - Command
383                00 - Extended command address bit 4-5:
384                00 - Write disable
385                01 - Write all
386                10 - Erase all
387                11 - Write enable
388                01 - Write
389                10 - Read
390                11 - Erase
391                16KBit EEPROM:
392                Bit 0-7 - EEPROM address bit 1-8
393                */
380                     1KBit EEPROM:
381                     Bit 0-5 - EEPROM address bit 1-6
382                     Bit 6-7 - Command
383                     00 - Extended command address bit 4-5:
384                     00 - Write disable
385                     01 - Write all
386                     10 - Erase all
387                     11 - Write enable
388                     01 - Write
389                     10 - Read
390                     11 - Erase
391                     16KBit EEPROM:
392                     Bit 0-7 - EEPROM address bit 1-8
393                     */
394394         switch (m_eeprom_mode)
395395         {
396396            case EEPROM_1K:
r32760r32761
412412         break;
413413
414414      case 0x07:  /* EEPROM higher bits/command bits port
415                1KBit EEPROM:
416                Bit 0   - Start
417                Bit 1-7 - Unknown
418                16KBit EEPROM:
419                Bit 0-1 - EEPROM address bit 9-10
420                Bit 2-3 - Command
421                00 - Extended command address bit 0-1:
422                00 - Write disable
423                01 - Write all
424                10 - Erase all
425                11 - Write enable
426                01 - Write
427                10 - Read
428                11 - Erase
429                Bit 4   - Start
430                Bit 5-7 - Unknown
431                */
415                     1KBit EEPROM:
416                     Bit 0   - Start
417                     Bit 1-7 - Unknown
418                     16KBit EEPROM:
419                     Bit 0-1 - EEPROM address bit 9-10
420                     Bit 2-3 - Command
421                     00 - Extended command address bit 0-1:
422                     00 - Write disable
423                     01 - Write all
424                     10 - Erase all
425                     11 - Write enable
426                     01 - Write
427                     10 - Read
428                     11 - Erase
429                     Bit 4   - Start
430                     Bit 5-7 - Unknown
431                     */
432432         switch (m_eeprom_mode)
433433         {
434434            case EEPROM_1K:
r32760r32761
450450                  m_eeprom_command = m_eeprom_command & 0x0c;
451451               m_eeprom_start = (data >> 4) & 0x01;
452452               break;
453               
453
454454            default:
455455               logerror( "Write EEPROM address/command register C7 for unsupported EEPROM type\n" );
456456            break;
r32760r32761
458458         break;
459459
460460      case 0x08:  /* EEPROM command
461                Bit 0   - Read complete (read only)
462                Bit 1   - Write complete (read only)
463                Bit 2-3 - Unknown
464                Bit 4   - Read
465                Bit 5   - Write
466                Bit 6   - Protect
467                Bit 7   - Initialize
468                */
469         if (data & 0x80)   // Initialize
461                     Bit 0   - Read complete (read only)
462                     Bit 1   - Write complete (read only)
463                     Bit 2-3 - Unknown
464                     Bit 4   - Read
465                     Bit 5   - Write
466                     Bit 6   - Protect
467                     Bit 7   - Initialize
468                     */
469         if (data & 0x80)    // Initialize
470470            logerror("Unsupported EEPROM command 'Initialize'\n");
471471
472         if (data & 0x40)   // Protect
473         {   
472         if (data & 0x40)    // Protect
473         {
474474            switch (m_eeprom_command)
475475            {
476476               case 0x00:
r32760r32761
487487            }
488488         }
489489
490         if (data & 0x20)   // Write
490         if (data & 0x20)    // Write
491491         {
492492            if (m_eeprom_write_enabled)
493493            {
r32760r32761
505505            }
506506         }
507507
508         if (data & 0x10)   // Read
508         if (data & 0x10)    // Read
509509         {
510510            m_io_regs[0x04] = m_nvram[(m_eeprom_address << 1) + 1];
511511            m_io_regs[0x05] = m_nvram[m_eeprom_address << 1];
trunk/src/emu/bus/wswan/slot.c
r32760r32761
167167      UINT8 *ROM;
168168      UINT32 size = (software_entry() == NULL) ? length() : get_software_region_length("rom");
169169      UINT32 nvram_size = 0;
170     
170
171171      m_cart->rom_alloc(size, tag());
172172      ROM = m_cart->get_rom_base();
173         
173
174174      if (software_entry() == NULL)
175175         fread(ROM, size);
176176      else
r32760r32761
261261   {
262262      case 0x00:
263263         break;
264      case 0x01:   // SRAM 64Kbit
264      case 0x01:  // SRAM 64Kbit
265265         type = WS_SRAM;
266266         nvram_len = 0x2000;
267267         break;
268      case 0x02:   // SRAM 256Kbit
268      case 0x02:  // SRAM 256Kbit
269269         type = WS_SRAM;
270270         nvram_len = 0x8000;
271271         break;
272      case 0x05:   // SRAM 512Kbit
272      case 0x05:  // SRAM 512Kbit
273273         type = WS_SRAM;
274274         nvram_len = 0x10000;
275275         break;
276      case 0x03:   // SRAM 1Mbit
276      case 0x03:  // SRAM 1Mbit
277277         type = WS_SRAM;
278278         nvram_len = 0x20000;
279279         break;
280      case 0x04:   // SRAM 2Mbit
280      case 0x04:  // SRAM 2Mbit
281281         type = WS_SRAM;
282282         nvram_len = 0x40000;
283283         break;
284      case 0x10:   // EEPROM 1Kbit
284      case 0x10:  // EEPROM 1Kbit
285285         type = WS_EEPROM;
286286         nvram_len = 0x80;
287287         break;
288      case 0x50:   // EEPROM 8Kbit
288      case 0x50:  // EEPROM 8Kbit
289289         type = WS_EEPROM;
290290         nvram_len = 0x400;
291291         break;
292      case 0x20:   // EEPROM 16Kbit
292      case 0x20:  // EEPROM 16Kbit
293293         type = WS_EEPROM;
294294         nvram_len = 0x800;
295295         break;
r32760r32761
298298         logerror("Unknown RAM size [0x%X]\n", ROM[(chunks - 1) * 0x10000 + 0xfffb]);
299299         break;
300300   }
301   
301
302302   return type;
303303}
304304
r32760r32761
315315      dynamic_buffer rom(size);
316316      int type;
317317      UINT32 nvram;
318     
318
319319      core_fread(m_file, rom, size);
320320
321321      // nvram size is not really used here, but we set it up nevertheless
r32760r32761
427427   int sum = 0, banks = len / 0x10000;
428428   UINT8 romsize, ramtype, ramsize;
429429   romsize = ROM[offs + 0xfffa];
430   ramtype = (ROM[offs + 0xfffb] & 0xf0) ? 1 : 0;   // 1 = EEPROM, 0 = SRAM
430   ramtype = (ROM[offs + 0xfffb] & 0xf0) ? 1 : 0;  // 1 = EEPROM, 0 = SRAM
431431   ramsize = ramtype ? ((ROM[offs + 0xfffb] & 0xf0) >> 4) : (ROM[offs + 0xfffb] & 0x0f);
432   
433432
433
434434   logerror( "ROM DETAILS\n" );
435435   logerror( "===========\n\n" );
436436   logerror("\tDeveloper ID: %X\n", ROM[offs + 0xfff6]);
trunk/src/emu/bus/wswan/rom.h
r32760r32761
5353public:
5454   // construction/destruction
5555   ws_rom_sram_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
56   
56
5757   // device-level overrides
5858   virtual void device_start();
5959   virtual void device_reset();
60   
60
6161   // reading and writing
6262   virtual DECLARE_READ8_MEMBER(read_ram);
6363   virtual DECLARE_WRITE8_MEMBER(write_ram);
r32760r32761
7575public:
7676   // construction/destruction
7777   ws_rom_eeprom_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
78   
78
7979   // device-level overrides
8080   virtual void device_start();
8181   virtual void device_reset();
82   
82
8383   // reading and writing
8484   virtual DECLARE_READ8_MEMBER(read_io);
8585   virtual DECLARE_WRITE8_MEMBER(write_io);
trunk/src/emu/bus/megadrive/ggenie.c
r32760r32761
55
66
77 based on Charles MacDonald's docs: http://cgfm2.emuviews.com/txt/genie.txt
8 
98
9
1010 There is an interesting difference between Rev.0 and Rev.A
11 After the codes has been entered, the former just performs
12 a last write to the MODE register (m_gg_regs[0]) which both
13 sets the enable bits for the 6 available cheats (in the low
14 8 bits) and locks the GG so that later reads goes to the
11 After the codes has been entered, the former just performs
12 a last write to the MODE register (m_gg_regs[0]) which both
13 sets the enable bits for the 6 available cheats (in the low
14 8 bits) and locks the GG so that later reads goes to the
1515 piggyback cart. The latter revision, instead, performs the
16 same operations in two subsequent 8bit writes, accessing
16 same operations in two subsequent 8bit writes, accessing
1717 separately the low and high bits of the register.
18
18
1919 ***********************************************************************************************************/
2020
2121#include "emu.h"
r32760r32761
8686         return m_gg_data[5];
8787      else
8888         return m_exp->m_cart->read(space, offset);
89   }   
89   }
9090   else
9191      return 0xffff;
9292}
r32760r32761
114114      else
115115      {
116116         m_gg_bypass = 0;
117         
117
118118         // bit9 set = read goes to ASIC registers
119119         if (data & 0x200)
120120            m_reg_enable = 1;
r32760r32761
122122         else
123123            m_reg_enable = 0;
124124      }
125     
125
126126      // LOCK bit
127127      if (data & 0x100)
128128      {
r32760r32761
133133         m_gg_addr[3] = ((m_gg_regs[11]  & 0x3f) << 16) | m_gg_regs[12];
134134         m_gg_addr[4] = ((m_gg_regs[14]  & 0x3f) << 16) | m_gg_regs[15];
135135         m_gg_addr[5] = ((m_gg_regs[17]  & 0x3f) << 16) | m_gg_regs[18];
136         
136
137137         // data
138138         m_gg_data[0] = m_gg_regs[4];
139139         m_gg_data[1] = m_gg_regs[7];
r32760r32761
144144
145145         //printf("mode %X\n", data);
146146         //for (int i = 0; i < 6; i++)
147         //   printf("addr %d = 0x%X - data 0x%X\n", i, m_gg_addr[i], m_gg_data[i]);
147         //  printf("addr %d = 0x%X - data 0x%X\n", i, m_gg_addr[i], m_gg_data[i]);
148148      }
149   }   
149   }
150150   else if (offset == 1)
151151   {
152152      // RESET
trunk/src/emu/bus/centronics/digiblst.h
r32760r32761
11/*
22 * digiblst.h
33 *
4 *   Digiblaster - a DIY printer port DAC for the Amstrad CPC
5 *   Printed in the German magazine CPC Amstrad International issue 8-9/1991
6 *   Uses Strobe (inverted on the CPC) for the 8th bit (CPCs only have 7-bit printer ports)
4 *  Digiblaster - a DIY printer port DAC for the Amstrad CPC
5 *  Printed in the German magazine CPC Amstrad International issue 8-9/1991
6 *  Uses Strobe (inverted on the CPC) for the 8th bit (CPCs only have 7-bit printer ports)
77 *
8 *   Code borrows from the Covox Speech Thing device.
8 *  Code borrows from the Covox Speech Thing device.
99 *
1010 *  Created on: 23/08/2014
1111 */
trunk/src/emu/bus/snes/snes_slot.h
r32760r32761
125125   UINT32 get_rtc_ram_size() { return m_rtc_ram.count(); };
126126
127127   void rom_map_setup(UINT32 size);
128   void save_nvram()   { device().save_item(NAME(m_nvram)); }
129   void save_rtc_ram()   { device().save_item(NAME(m_rtc_ram)); }
128   void save_nvram()   { device().save_item(NAME(m_nvram)); }
129   void save_rtc_ram() { device().save_item(NAME(m_rtc_ram)); }
130130
131131   // internal state
132132   UINT8 *m_rom;
r32760r32761
166166   void setup_nvram();
167167   void internal_header_logging(UINT8 *ROM, UINT32 len);
168168
169   void save_ram()   { if (m_cart && m_cart->get_nvram_size()) m_cart->save_nvram();
169   void save_ram() { if (m_cart && m_cart->get_nvram_size()) m_cart->save_nvram();
170170               if (m_cart && m_cart->get_rtc_ram_size()) m_cart->save_rtc_ram(); }
171171
172172   virtual iodevice_t image_type() const { return IO_CARTSLOT; }
trunk/src/emu/bus/a2bus/mouse.c
r32760r32761
33    mouse.c
44
55    Implemention of the Apple II Mouse Card
6
6
77    Apple II Mouse Interface PCB
8   Apple 1983
8    Apple 1983
99
10   This is a mouse interface for the Apple II
10    This is a mouse interface for the Apple II
1111
12   PCB Layout
13   ----------
14   apple computer
15   MOUSE INTERFACE
16   670-0030-C (C) 1983
17   Printed on back side - MOUSE INTERFACE 820-0104-B (C) 1983 APPLE COMPUTER
12    PCB Layout
13    ----------
14    apple computer
15    MOUSE INTERFACE
16    670-0030-C (C) 1983
17    Printed on back side - MOUSE INTERFACE 820-0104-B (C) 1983 APPLE COMPUTER
1818    |-----------------------------------|
1919    |            PAL16R4       6821     |
2020    |                                   |
r32760r32761
2525    |-------------------|             |-|
2626                        |-------------|
2727
28   Notes:
29        J1      - 9 pin flat cable with female DB9 connector
30        68705P3 - Motorola MC68705P3 microcontroller (DIP28) labelled '341-0269 (C) APPLE'
31               PCB printed '(C) APPLE 1983 341-0269 or 342-0285'
32        8516    - Fujitsu MB8516 2k x8-bit EPROM (DIP24) labelled '341-0270-C (C) APPLE 1983'
33               PCB printed '(C) APPLE 1983 342-0270'
34        PAL16R4 - MMI PAL16R4ACN (DIP20) marked '341-0268-A'
35               PCB printed '(C) APPLE 1983 342-0268'
36        6821    - AMI 6821 Peripheral Interface Adapter (DIP40)
37        X1/X2   - Jumper pads. X1 is open, X2 is closed.
38 
39 
28    Notes:
29          J1      - 9 pin flat cable with female DB9 connector
30          68705P3 - Motorola MC68705P3 microcontroller (DIP28) labelled '341-0269 (C) APPLE'
31                    PCB printed '(C) APPLE 1983 341-0269 or 342-0285'
32          8516    - Fujitsu MB8516 2k x8-bit EPROM (DIP24) labelled '341-0270-C (C) APPLE 1983'
33                    PCB printed '(C) APPLE 1983 342-0270'
34          PAL16R4 - MMI PAL16R4ACN (DIP20) marked '341-0268-A'
35                    PCB printed '(C) APPLE 1983 342-0268'
36          6821    - AMI 6821 Peripheral Interface Adapter (DIP40)
37          X1/X2   - Jumper pads. X1 is open, X2 is closed.
38
39
4040    Hookup notes:
41      PIA port A connects to 68705 port A in its entirety (bi-directional)
42      PIA PB4-PB7 connects to 68705 PC0-3 (bi-directional)
43      PIA PB0 is 'sync latch'
44      PIA PB1 is A8 on the EPROM
45      PIA PB2 is A9 on the EPROM
46      PIA PB3 is A10 on the EPROM
47 
48      68705 PB0 is mouse X1
49      68705 PB1 is mouse X0
50      68705 PB2 is mouse Y0
51      68705 PB3 is mouse Y1
52      68705 PB4 and 5 are N/C
53      68705 PB6 is IRQ for the slot
54      68705 PB7 is the mouse button
55 
56      68705 is clocked at 2M
57       PIA is clocked at 1M
58 
41        PIA port A connects to 68705 port A in its entirety (bi-directional)
42        PIA PB4-PB7 connects to 68705 PC0-3 (bi-directional)
43        PIA PB0 is 'sync latch'
44        PIA PB1 is A8 on the EPROM
45        PIA PB2 is A9 on the EPROM
46        PIA PB3 is A10 on the EPROM
47
48        68705 PB0 is mouse X1
49        68705 PB1 is mouse X0
50        68705 PB2 is mouse Y0
51        68705 PB3 is mouse Y1
52        68705 PB4 and 5 are N/C
53        68705 PB6 is IRQ for the slot
54        68705 PB7 is the mouse button
55
56        68705 is clocked at 2M
57        PIA is clocked at 1M
58
5959    See the schematic at:
60   http://mirrors.apple2.org.za/Apple%20II%20Documentation%20Project/Interface%20Cards/Digitizers/Apple%20Mouse%20Interface%20Card/Schematics/
61 
60    http://mirrors.apple2.org.za/Apple%20II%20Documentation%20Project/Interface%20Cards/Digitizers/Apple%20Mouse%20Interface%20Card/Schematics/
61
6262*********************************************************************/
6363
6464#include "mouse.h"
r32760r32761
7373
7474const device_type A2BUS_MOUSE = &device_creator<a2bus_mouse_device>;
7575
76#define MOUSE_ROM_REGION   "a2mse_rom"
77#define MOUSE_PIA_TAG      "a2mse_pia"
78#define MOUSE_MCU_TAG      "a2mse_mcu"
79#define MOUSE_MCU_ROM      "a2mse_mcurom"
76#define MOUSE_ROM_REGION    "a2mse_rom"
77#define MOUSE_PIA_TAG       "a2mse_pia"
78#define MOUSE_MCU_TAG       "a2mse_mcu"
79#define MOUSE_MCU_ROM       "a2mse_mcurom"
8080
81#define MOUSE_BUTTON_TAG   "a2mse_button"
82#define MOUSE_XAXIS_TAG      "a2mse_x"
83#define MOUSE_YAXIS_TAG      "a2mse_y"
81#define MOUSE_BUTTON_TAG    "a2mse_button"
82#define MOUSE_XAXIS_TAG     "a2mse_x"
83#define MOUSE_YAXIS_TAG     "a2mse_y"
8484
85#define TIMER_68705         0
86#define TIMER_QUADRATURE   1
85#define TIMER_68705         0
86#define TIMER_QUADRATURE    1
8787
8888static ADDRESS_MAP_START( mcu_mem, AS_PROGRAM, 8, a2bus_mouse_device )
8989   ADDRESS_MAP_GLOBAL_MASK(0x7ff)
r32760r32761
113113
114114ROM_START( mouse )
115115   ROM_REGION(0x800, MOUSE_ROM_REGION, 0)
116   ROM_LOAD( "341-0270-c.4b", 0x000000, 0x000800, CRC(0bcd1e8e) SHA1(3a9d881a8a8d30f55b9719aceebbcf717f829d6f) )
116   ROM_LOAD( "341-0270-c.4b", 0x000000, 0x000800, CRC(0bcd1e8e) SHA1(3a9d881a8a8d30f55b9719aceebbcf717f829d6f) )
117117
118118   ROM_REGION(0x800, MOUSE_MCU_ROM, 0)
119   ROM_LOAD( "341-0269.2b",  0x000000, 0x000800, CRC(94067f16) SHA1(3a2baa6648efe4456d3ec3721216e57c64f7acfc) )
119   ROM_LOAD( "341-0269.2b",  0x000000, 0x000800, CRC(94067f16) SHA1(3a2baa6648efe4456d3ec3721216e57c64f7acfc) )
120120
121121   ROM_REGION(0xc00, "pal", 0)
122   ROM_LOAD( "mmi_pal16r4a(jedec).2a", 0x000000, 0x000b04, CRC(1d620ee5) SHA1(5aa9a515c919ff7a18878649cac5d44f0c2abf28) )
123   ROM_LOAD( "mmi_pal16r4a(binary).2a", 0x000000, 0x000100, CRC(1da5c745) SHA1(ba267b69a2fda2a2348b140979ece562411bb37b) )
122   ROM_LOAD( "mmi_pal16r4a(jedec).2a", 0x000000, 0x000b04, CRC(1d620ee5) SHA1(5aa9a515c919ff7a18878649cac5d44f0c2abf28) )
123   ROM_LOAD( "mmi_pal16r4a(binary).2a", 0x000000, 0x000100, CRC(1da5c745) SHA1(ba267b69a2fda2a2348b140979ece562411bb37b) )
124124ROM_END
125125
126126static INPUT_PORTS_START( mouse )
r32760r32761
241241   m_rom_bank = 0;
242242   last_mx = last_my = count_x = count_y = 0;
243243   m_timer_cnt = 0xff;
244   m_timer_ctl = 0x40;   // disable interrupt, everything else clear
244   m_timer_ctl = 0x40; // disable interrupt, everything else clear
245245   m_port_a_in = 0;
246246   m_port_b_in = 0x80;
247247   m_port_c_in = 0;
r32760r32761
261261
262262UINT8 a2bus_mouse_device::read_c0nx(address_space &space, UINT8 offset)
263263{
264   return m_pia->read(space, offset & 3);
264   return m_pia->read(space, offset & 3);
265265}
266266
267267
r32760r32761
394394      m_timer_cnt = data;
395395      recalc = true;
396396   }
397    // offset 1 = timer control:  b7 = IRQ, b6 = IRQ mask (1=suppress),
398   //                            b5 = input select (0=CPU clk, 1=ext),
399    //                            b4 = enable external timer input,
400    //                            b3 = clear, b2-b0 = scaler (1/2/4/8/16/32/64/128)
397   // offset 1 = timer control:  b7 = IRQ, b6 = IRQ mask (1=suppress),
398   //                            b5 = input select (0=CPU clk, 1=ext),
399   //                            b4 = enable external timer input,
400   //                            b3 = clear, b2-b0 = scaler (1/2/4/8/16/32/64/128)
401401   else
402402   {
403403      // clearing the interrupt?
r32760r32761
425425            recalc = true;
426426         }
427427
428         m_timer_ctl = data;
428         m_timer_ctl = data;
429429      }
430430
431431   }
r32760r32761
445445    X1 = gate, must go 0/1 for each pixel moved
446446    Y0 = direction, 0 = up, 1 = down
447447    Y1 = gate, must go 0/1 for each pixel moved
448
448
449449    The direction must stay constant for a given train of gate pulses or the MCU will get confused.
450450*/
451451void a2bus_mouse_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
452452{
453   if (id == TIMER_68705)   // 68705's built-in timer
453   if (id == TIMER_68705)  // 68705's built-in timer
454454   {
455455      m_timer_ctl |= 0x80;    // indicate timer expired
456      if (!(m_timer_ctl & 0x40))   // if interrupt not suppressed, fire!
456      if (!(m_timer_ctl & 0x40))  // if interrupt not suppressed, fire!
457457      {
458458         m_mcu->set_input_line(M68705_INT_TIMER, ASSERT_LINE);
459459      }
r32760r32761
509509         else
510510         {
511511            count_x--;
512            m_port_b_in |= 0x01;   // X1
512            m_port_b_in |= 0x01;    // X1
513513         }
514         m_port_b_in |= 0x02;   // X0
514         m_port_b_in |= 0x02;    // X0
515515      }
516516      else if (count_y)
517517      {
r32760r32761
522522         else
523523         {
524524            count_y--;
525            m_port_b_in |= 0x04;   // Y0
525            m_port_b_in |= 0x04;    // Y0
526526         }
527         m_port_b_in |= 0x08;   // Y1
527         m_port_b_in |= 0x08;    // Y1
528528      }
529529   }
530530}
trunk/src/emu/bus/a2bus/corvfdc02.c
r32760r32761
44
55    Implemention of the Corvus Systems CORVUS02 floppy controller
66    aka the "Buffered Floppy Controller"
7
7
88    Boot PROM 0.8 says 8" SSDD or 5.25" DSDD; we stick with 5.25" here
99    and let the FDC01 handle 8".
10
10
1111*********************************************************************/
1212
1313#include "corvfdc02.h"
r32760r32761
2323
2424const device_type A2BUS_CORVFDC02 = &device_creator<a2bus_corvfdc02_device>;
2525
26#define FDC02_ROM_REGION   "fdc02_rom"
27#define FDC02_FDC_TAG      "fdc02_fdc"
26#define FDC02_ROM_REGION    "fdc02_rom"
27#define FDC02_FDC_TAG       "fdc02_fdc"
2828
2929FLOPPY_FORMATS_MEMBER( a2bus_corvfdc02_device::corv_floppy_formats )
3030   FLOPPY_CONCEPT_525DSDD_FORMAT,
r32760r32761
8686   m_con3(*this, FDC02_FDC_TAG":2"),
8787   m_con4(*this, FDC02_FDC_TAG":3")
8888{
89   
9089}
9190
9291a2bus_corvfdc02_device::a2bus_corvfdc02_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
r32760r32761
143142{
144143   switch (offset)
145144   {
146      case 0:   // 765 FIFO
145      case 0: // 765 FIFO
147146         return m_fdc->fifo_r(space, 0);
148147
149      case 1:   // 765 MSR
148      case 1: // 765 MSR
150149         return m_fdc->msr_r(space, 0);
151150
152      case 2:   // buffer address
151      case 2: // buffer address
153152         return (m_bufptr>>1) & 0xff;
154153
155      case 3:
156//         printf("Read buffer @ %x = %02x\n", m_bufptr, m_buffer[m_bufptr]);
154      case 3:
155//          printf("Read buffer @ %x = %02x\n", m_bufptr, m_buffer[m_bufptr]);
157156         return m_buffer[m_bufptr--];
158157
159      case 4:   // local status
158      case 4: // local status
160159         if (m_curfloppy)
161160         {
162161            m_fdc_local_status &= ~(1 | 0x40);
r32760r32761
188187      case 1:    // FDC ???
189188         break;
190189
191      case 2:   // buffer address
190      case 2: // buffer address
192191         m_bufptr = (data << 1) | (data & 1);
193//         printf("%02x to buffer address yields %x\n", data, m_bufptr);
192//          printf("%02x to buffer address yields %x\n", data, m_bufptr);
194193         break;
195194
196      case 3:   // buffer write
197//         printf("%02x to buffer[%x]\n", data, m_bufptr);
195      case 3: // buffer write
196//          printf("%02x to buffer[%x]\n", data, m_bufptr);
198197         m_buffer[m_bufptr--] = data;
199198         break;
200199
r32760r32761
233232         {
234233            // motor control (active low)
235234            m_curfloppy->mon_w((data & 8) ? 1 : 0);
236//            printf("Cur drive %p motor %s\n", m_curfloppy, (data & 8) ? "OFF" : "ON");
235//              printf("Cur drive %p motor %s\n", m_curfloppy, (data & 8) ? "OFF" : "ON");
237236         }
238237
239238         if (data & 0x80)
240239         {
241//            printf("Reset NEC765\n");
240//              printf("Reset NEC765\n");
242241            m_fdc->reset();
243242         }
244243         break;
r32760r32761
266265   }
267266   else
268267   {
269      m_fdc_local_status |= 2;   // clear IRQ
268      m_fdc_local_status |= 2;    // clear IRQ
270269      lower_slot_irq();
271270   }
272271}
r32760r32761
279278      if (m_fdc_local_command & 0x40)
280279      {
281280         m_buffer[m_bufptr] = m_fdc->dma_r();
282//         printf("DMA %02x to buffer[%x]\n", m_buffer[m_bufptr], m_bufptr);
281//          printf("DMA %02x to buffer[%x]\n", m_buffer[m_bufptr], m_bufptr);
283282
284283         if (!m_bufptr)
285284         {
r32760r32761
296295      }
297296   }
298297}
299
trunk/src/emu/bus/a2bus/corvfdc02.h
r32760r32761
5656   UINT8 *m_rom;
5757   UINT8 m_fdc_local_status, m_fdc_local_command;
5858   UINT16 m_bufptr;
59   UINT8 m_buffer[2048];   // 1x6116 SRAM
59   UINT8 m_buffer[2048];   // 1x6116 SRAM
6060   floppy_image_device *m_curfloppy;
6161   bool m_in_drq;
6262   emu_timer *m_timer;
trunk/src/emu/bus/a2bus/timemasterho.c
r32760r32761
2020    |____________________________                        _|
2121                                 |                      |
2222                                 |______________________|
23 
24 
23
24
2525    DIPS: 1:SET  2:MODE 3:NMI 4:IRQ
2626    1 & 4 are on by default.
27
27
2828    J1: 8 pins for X10 home control functions (top to bottom)
2929       1: ADJ  2: 5V  3: MODE  4: GND
3030       5: A    6: 5V  7: B     8: GND
31
31
3232    X10 functions not supported.
33
33
3434*********************************************************************/
3535
3636#include "timemasterho.h"
r32760r32761
4545
4646const device_type A2BUS_TIMEMASTERHO = &device_creator<a2bus_timemasterho_device>;
4747
48#define TIMEMASTER_ROM_REGION   "timemst_rom"
49#define TIMEMASTER_PIA_TAG      "timemst_pia"
50#define TIMEMASTER_M5832_TAG   "timemst_msm"
48#define TIMEMASTER_ROM_REGION   "timemst_rom"
49#define TIMEMASTER_PIA_TAG      "timemst_pia"
50#define TIMEMASTER_M5832_TAG    "timemst_msm"
5151
5252MACHINE_CONFIG_FRAGMENT( timemaster )
5353   MCFG_DEVICE_ADD(TIMEMASTER_PIA_TAG, PIA6821, 1021800)
r32760r32761
6161
6262ROM_START( timemaster )
6363   ROM_REGION(0x1000, TIMEMASTER_ROM_REGION, 0)
64   ROM_LOAD( "ae timemaster ii h.o. rom rev. 5.bin", 0x000000, 0x001000, CRC(ff5bd644) SHA1(ae0173da61581a06188c1bee89e95a0aa536c411) )
64   ROM_LOAD( "ae timemaster ii h.o. rom rev. 5.bin", 0x000000, 0x001000, CRC(ff5bd644) SHA1(ae0173da61581a06188c1bee89e95a0aa536c411) )
6565ROM_END
6666
6767static INPUT_PORTS_START( tmho )
6868   PORT_START("DSW1")
6969   PORT_DIPNAME( 0x01, 0x01, "Set")
70   PORT_DIPSETTING(   0x00, "Apple can't set clock")
71   PORT_DIPSETTING(   0x01, "Apple can set clock")
70   PORT_DIPSETTING(    0x00, "Apple can't set clock")
71   PORT_DIPSETTING(    0x01, "Apple can set clock")
7272
7373   PORT_DIPNAME( 0x02, 0x00, "Mode")
74   PORT_DIPSETTING(   0x00, "TimeMaster")
75   PORT_DIPSETTING(   0x02, "Mountain AppleClock")
74   PORT_DIPSETTING(    0x00, "TimeMaster")
75   PORT_DIPSETTING(    0x02, "Mountain AppleClock")
7676
7777   PORT_DIPNAME( 0x04, 0x00, "NMI")
78   PORT_DIPSETTING(   0x00,  DEF_STR(Off))
79   PORT_DIPSETTING(   0x04,  DEF_STR(On))
78   PORT_DIPSETTING(    0x00,  DEF_STR(Off))
79   PORT_DIPSETTING(    0x04,  DEF_STR(On))
8080
8181   PORT_DIPNAME( 0x08, 0x08, "IRQ")
82   PORT_DIPSETTING(   0x00,  DEF_STR(Off))
83   PORT_DIPSETTING(   0x08,  DEF_STR(On))
82   PORT_DIPSETTING(    0x00,  DEF_STR(Off))
83   PORT_DIPSETTING(    0x08,  DEF_STR(On))
8484INPUT_PORTS_END
8585
8686/***************************************************************************
r32760r32761
154154
155155void a2bus_timemasterho_device::device_reset()
156156{
157   m_msm5832->cs_w(ASSERT_LINE);   // CS is tied to Vcc
157   m_msm5832->cs_w(ASSERT_LINE);   // CS is tied to Vcc
158158   m_started = true;
159159}
160160
r32760r32761
167167{
168168   if (offset <= 3)
169169   {
170      return m_pia->read(space, offset);
170      return m_pia->read(space, offset);
171171   }
172172
173173   return 0xff;
r32760r32761
194194{
195195   if (m_started)
196196   {
197      if (!(m_dsw1->read() & 2))   // TimeMaster native
197      if (!(m_dsw1->read() & 2))  // TimeMaster native
198198      {
199199         return m_rom[offset+0xc00];
200200      }
r32760r32761
228228   {
229229      if (m_dsw1->read() & 1)
230230      {
231         m_msm5832->write_w((data >> 6) & 1 ? ASSERT_LINE : CLEAR_LINE);
231         m_msm5832->write_w((data >> 6) & 1 ? ASSERT_LINE : CLEAR_LINE);
232232      }
233233   }
234234
r32760r32761
277277   m_irqb = state;
278278   update_irqs();
279279}
280
trunk/src/emu/bus/a2bus/a2lang.c
r32760r32761
112112   // likely to be interrupt-safe.
113113   if (state->m_machinetype == APPLE_II)
114114   {
115      switch (offset & 0x03)
115      switch (offset & 0x03)
116116      {
117117         case 1:
118118         case 3:
trunk/src/emu/bus/a2bus/corvfdc01.c
r32760r32761
33    corvfdc01.c
44
55    Implemention of the Corvus Systems CORVUS01 floppy controller
6
6
77    Boot PROM 0.8 fixes this at: 8", 500 blocks total, 128 bytes/block,
8                          26 sectors/track, 77 tracks.
9 
8                                 26 sectors/track, 77 tracks.
9
1010*********************************************************************/
1111
1212#include "corvfdc01.h"
r32760r32761
2121
2222const device_type A2BUS_CORVFDC01 = &device_creator<a2bus_corvfdc01_device>;
2323
24#define FDC01_ROM_REGION   "fdc01_rom"
25#define FDC01_FDC_TAG      "fdc01_fdc"
24#define FDC01_ROM_REGION    "fdc01_rom"
25#define FDC01_FDC_TAG       "fdc01_fdc"
2626
2727FLOPPY_FORMATS_MEMBER( a2bus_corvfdc01_device::corv_floppy_formats )
2828   FLOPPY_IMD_FORMAT
r32760r32761
161161{
162162   switch (offset)
163163   {
164      case 0:   // local status
164      case 0: // local status
165165         if (m_curfloppy)
166166         {
167167            m_fdc_local_status &= ~LS_DSKCHG_mask;
r32760r32761
169169         }
170170         return m_fdc_local_status | LS_8IN_mask;
171171
172      case  8:   // WD1793 at 8-11
172      case  8:    // WD1793 at 8-11
173173         return m_wdfdc->status_r(space, offset);
174174
175175      case  9:
r32760r32761
225225         if (m_curfloppy != NULL)
226226         {
227227            // side select
228            m_curfloppy->ss_w((data & LC_FLPSD1_mask) != 0);
228            m_curfloppy->ss_w((data & LC_FLPSD1_mask) != 0);
229229
230230            // motor control (active low)
231231            m_curfloppy->mon_w((data & LC_MOTOROF_mask) ? 1 : 0);
r32760r32761
278278   else
279279      m_fdc_local_status &= ~LS_DRQ_mask;
280280}
281
trunk/src/emu/bus/a2bus/laser128.c
r32760r32761
108108         {
109109            return m_slot7_ram[offset];
110110         }
111         return m_rom[(offset & 0x3ff) + 0x6000 + m_slot7_bank];
111         return m_rom[(offset & 0x3ff) + 0x6000 + m_slot7_bank];
112112   }
113113
114114   return 0xff;
r32760r32761
124124   // UDCREG
125125   if ((m_slot == 7) && (offset == 0x7f8))
126126   {
127//      printf("%02x to UDCREG\n", data);
127//      printf("%02x to UDCREG\n", data);
128128
129129      m_slot7_ram_bank = (data & 0x8) ? 0x400 : 0;
130130      m_slot7_bank = (((data >> 4) & 0x7) * 0x400);
131131
132//      printf("\tRAM bank %x, ROM bank %x\n", m_slot7_ram_bank, m_slot7_bank);
132//      printf("\tRAM bank %x, ROM bank %x\n", m_slot7_ram_bank, m_slot7_bank);
133133   }
134134}
135135
trunk/src/emu/bus/a2bus/a2corvus.c
r32760r32761
3232    7) When the format completes, type "RUN APPLESOFT BOOT PREP" and press Enter.
3333    8) Once it finishes, quit MESS.  Remove the diskii(ng) from slot 7 and
3434       the system will boot into DOS 3.3 from the Corvus HD.
35
35
3636    TODO: but there are no Corvus drivers present after that, only
3737    Disk II?
3838
trunk/src/emu/bus/generic/carts.c
r32760r32761
11// license:BSD-3-Clause
22// copyright-holders:etabeta
33/**********************************************************************
4
4
55 Generic ROM / RAM socket slots
6
6
77 **********************************************************************/
88
99
trunk/src/emu/bus/generic/rom.c
r32760r32761
44
55
66 Generic ROM emulation (for carts and ROM sockets)
7
7
88 This offers generic access to a ROM
9
9
1010 generic_rom_plain  : returns 0xff when the system reads beyond the end of the ROM
1111 generic_rom_linear : maps linearly the ROM in the accessed area (i.e., read offset is masked with (ROM size - 1) )
1212
1313 generic_romram_plain  : allows support for carts always containing ROM + RAM (e.g. X07)
1414
15
15
1616 TODO:
1717   - possibly support linear mapping when non-power of 2 ROMs are mapped
18
18
1919 ***********************************************************************************************************/
2020
2121
r32760r32761
120120   if (offset < m_ram.bytes())
121121      m_ram[offset] = data;
122122}
123
trunk/src/emu/bus/generic/ram.c
r32760r32761
11// license:BSD-3-Clause
22// copyright-holders:etabeta
33/***********************************************************************************************************
4 
5 
4
5
66 Generic RAM socket emulation
7
7
88 This offers generic access to RAM
9
9
1010 generic_ram_plain  : returns 0xff when the system reads beyond the end of the RAM
11 generic_ram_linear : maps linearly the RAM in the accessed area (i.e., read/write offset is masked with
11 generic_ram_linear : maps linearly the RAM in the accessed area (i.e., read/write offset is masked with
1212 (RAM size - 1) )
13
13
1414 TODO:
1515   - support variable RAM size
1616   - possibly support linear mapping when non-power of 2 RAMs are mapped
1717   - add support for 16bit & 32bit RAM access
18
18
1919 ***********************************************************************************************************/
2020
2121
r32760r32761
121121{
122122   m_ram[offset % m_ram.bytes()] = data;
123123}
124
trunk/src/emu/bus/generic/slot.c
r32760r32761
33/***********************************************************************************************************
44
55   Generic ROM / RAM Socket and Cartslot device
6
6
77   This device offers basic RAM / ROM allocation and access
88
99   The available handlers are suited for any situation where a system opens a
r32760r32761
1212   This device is not suited whenever the system exposes additional lines to
1313   the socket/slot: e.g. whenever input/output lines are present, whenever
1414   there are lines controlling bankswitch / paging, and whenever different
15   cart configurations have to be supported (like some PCBs containing ROM
15   cart configurations have to be supported (like some PCBs containing ROM
1616   only, and other containing both ROM and RAM)
1717   In the latter situations, per-system slot devices have to be created (see
1818   e.g. APF cart slot device for an example of a simple device with multiple
1919   pcbs supported)
20
20
2121 ***********************************************************************************************************/
2222
2323
r32760r32761
136136bool generic_slot_device::call_load()
137137{
138138   if (m_cart)
139   {     
139   {
140140      if (!m_device_image_load.isnull())
141141         return m_device_image_load(*this);
142142      else
143143      {
144144         UINT32 len = common_get_size("rom");
145         
145
146146         rom_alloc(len, m_width, m_endianness);
147         common_load_rom(get_rom_base(), len, "rom");         
147         common_load_rom(get_rom_base(), len, "rom");
148148
149149         return IMAGE_INIT_PASS;
150150      }
r32760r32761
189189
190190/**************************************************
191191
192 Implementation
193 
192 Implementation
193
194194 **************************************************/
195195
196196
197197/*-------------------------------------------------
198 common_get_size - it gets image file size both
198 common_get_size - it gets image file size both
199199 for fullpath and for softlist
200200 -------------------------------------------------*/
201201
r32760r32761
208208}
209209
210210/*-------------------------------------------------
211 common_load_rom - it loads from image file both
211 common_load_rom - it loads from image file both
212212 for fullpath and for softlist
213213 -------------------------------------------------*/
214214
r32760r32761
283283   if (m_cart)
284284      m_cart->write_ram(space, offset, data);
285285}
286
trunk/src/emu/bus/generic/rom.h
r32760r32761
1414public:
1515   // construction/destruction
1616   generic_rom_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
17   
17
1818   // device-level overrides
1919   virtual void device_start() {}
2020};
r32760r32761
2828   // construction/destruction
2929   generic_rom_plain_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
3030   generic_rom_plain_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
31   
31
3232   // reading and writing
3333   virtual DECLARE_READ8_MEMBER(read_rom);
3434   virtual DECLARE_READ16_MEMBER(read16_rom);
r32760r32761
4343public:
4444   // construction/destruction
4545   generic_romram_plain_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
46   
46
4747   // reading and writing
4848   virtual DECLARE_READ8_MEMBER(read_ram);
4949   virtual DECLARE_WRITE8_MEMBER(write_ram);
r32760r32761
5757public:
5858   // construction/destruction
5959   generic_rom_linear_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
60   
60
6161   // reading and writing
6262   virtual DECLARE_READ8_MEMBER(read_rom);
6363   virtual DECLARE_READ16_MEMBER(read16_rom);
trunk/src/emu/bus/generic/ram.h
r32760r32761
1414public:
1515   // construction/destruction
1616   generic_ram_plain_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, UINT32 size, const char *shortname, const char *source);
17   
17
1818   // device-level overrides
1919   virtual void device_start();
20   
20
2121   // reading and writing
2222   virtual DECLARE_READ8_MEMBER(read_ram);
2323   virtual DECLARE_WRITE8_MEMBER(write_ram);
24   
24
2525private:
2626   UINT32 m_size;
2727};
r32760r32761
3535public:
3636   // construction/destruction
3737   generic_ram_linear_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, UINT32 size, const char *shortname, const char *source);
38   
38
3939   // device-level overrides
4040   virtual void device_start();
41   
41
4242   // reading and writing
4343   virtual DECLARE_READ8_MEMBER(read_ram);
4444   virtual DECLARE_WRITE8_MEMBER(write_ram);
45   
45
4646private:
4747   UINT32 m_size;
4848};
trunk/src/emu/bus/generic/slot.h
r32760r32761
9393
9494   static void static_set_device_load(device_t &device, device_image_load_delegate callback) { downcast<generic_slot_device &>(device).m_device_image_load = callback; }
9595   static void static_set_device_unload(device_t &device, device_image_func_delegate callback) { downcast<generic_slot_device &>(device).m_device_image_unload = callback; }
96   
96
9797   void set_interface(const char * interface) { m_interface = interface; }
9898   void set_default_card(const char * def) { m_default_card = def; }
9999   void set_extensions(const char * exts) { m_extensions = exts; }
100100   void set_must_be_loaded(bool mandatory) { m_must_be_loaded = mandatory; }
101101   void set_width(int width) { m_width = width; }
102102   void set_endian(endianness_t end) { m_endianness = end; }
103   
103
104104   // device-level overrides
105105   virtual void device_start();
106106   virtual void device_config_complete();
r32760r32761
168168#define MCFG_GENERIC_CARTSLOT_ADD(_tag, _slot_intf, _dev_intf) \
169169   MCFG_DEVICE_ADD(_tag, GENERIC_SOCKET, 0) \
170170   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, NULL, false) \
171   MCFG_GENERIC_INTERFACE(_dev_intf) \
172
171   MCFG_GENERIC_INTERFACE(_dev_intf)
173172#define MCFG_GENERIC_SOCKET_ADD(_tag, _slot_intf, _dev_intf) \
174173   MCFG_DEVICE_ADD(_tag, GENERIC_SOCKET, 0) \
175174   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, NULL, false) \
176   MCFG_GENERIC_INTERFACE(_dev_intf) \
177
175   MCFG_GENERIC_INTERFACE(_dev_intf)
178176#endif
trunk/src/emu/bus/saturn/sat_slot.c
r32760r32761
156156         // from fullpath, only ROM carts
157157         UINT32 len = (software_entry() != NULL) ? get_software_region_length("rom") : length();
158158         UINT32 *ROM;
159         
159
160160         m_cart->rom_alloc(len, tag());
161161         ROM = m_cart->get_rom_base();
162         
162
163163         if (software_entry() != NULL)
164164            memcpy(ROM, get_software_region("rom"), len);
165165         else
166166            fread(ROM, len);
167         
167
168168         // fix endianness....
169169         for (int i = 0; i < len/4; i ++)
170170            ROM[i] = BITSWAP32(ROM[i],7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8,23,22,21,20,19,18,17,16,31,30,29,28,27,26,25,24);
trunk/src/emu/bus/vectrex/slot.c
r32760r32761
156156   {
157157      UINT32 size = (software_entry() == NULL) ? length() : get_software_region_length("rom");
158158      UINT8 *ROM;
159     
159
160160      if (size > 0x10000)
161161      {
162162         seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
163163         return IMAGE_INIT_FAIL;
164164      }
165     
165
166166      m_cart->rom_alloc((size < 0x1000) ? 0x1000 : size, tag());
167167      ROM = m_cart->get_rom_base();
168     
168
169169      if (software_entry() == NULL)
170170         fread(ROM, size);
171171      else
172172         memcpy(ROM, get_software_region("rom"), size);
173     
173
174174      // Verify the file is accepted by the Vectrex bios
175175      if (memcmp(ROM, "g GCE", 5))
176176      {
177177         seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid image");
178178         return IMAGE_INIT_FAIL;
179179      }
180     
180
181181      // determine type
182182      m_type = VECTREX_STD;
183183      if (!memcmp(ROM + 0x06, "SRAM", 4))
184         m_type = VECTREX_SRAM;     
184         m_type = VECTREX_SRAM;
185185      if (size > 0x8000)
186186         m_type = VECTREX_64K;
187     
187
188188      //printf("Type: %s\n", vectrex_get_slot(m_type));
189189
190190      // determine 3D setup (to help video setup at machine_start)
191191      if (!memcmp(ROM + 0x11, "NARROW", 6) && (ROM[0x39] == 0x0c))
192192         m_vec3d = VEC3D_NARROW;
193     
193
194194      if (!memcmp(ROM + 0x11, "CRAZY COASTER", 13))
195195         m_vec3d = VEC3D_CCOAST;
196     
196
197197      if (!memcmp(ROM + 0x11, "3D MINE STORM", 13))
198198         m_vec3d = VEC3D_MINEST;
199199
r32760r32761
229229      int type = VECTREX_STD;
230230
231231      core_fread(m_file, rom, size);
232     
232
233233      if (!memcmp(rom + 0x06, "SRAM", 4))
234         type = VECTREX_SRAM;     
234         type = VECTREX_SRAM;
235235      if (size > 0x8000)
236236         type = VECTREX_64K;
237237
r32760r32761
278278   if (m_cart)
279279      m_cart->write_bank(space, offset, data);
280280}
281
282
trunk/src/emu/bus/vectrex/rom.h
r32760r32761
3131public:
3232   // construction/destruction
3333   vectrex_rom64k_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
34   
34
3535   // device-level overrides
3636   virtual void device_start();
3737   virtual void device_reset();
38   
38
3939   // reading and writing
4040   virtual DECLARE_READ8_MEMBER(read_rom);
4141   virtual DECLARE_WRITE8_MEMBER(write_bank);
r32760r32761
5151public:
5252   // construction/destruction
5353   vectrex_sram_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
54   
54
5555   // reading and writing
5656   virtual DECLARE_WRITE8_MEMBER(write_ram);
5757};
trunk/src/emu/bus/vectrex/slot.h
r32760r32761
111111
112112#define MCFG_VECTREX_CARTRIDGE_ADD(_tag,_slot_intf,_def_slot) \
113113   MCFG_DEVICE_ADD(_tag, VECTREX_CART_SLOT, 0) \
114   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false) \
115
114   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false)
116115#endif
trunk/src/emu/bus/odyssey2/voice.c
r32760r32761
3333
3434
3535void o2_voice_device::device_start()
36{   
36{
3737   save_item(NAME(m_lrq_state));
3838}
3939
trunk/src/emu/bus/odyssey2/slot.h
r32760r32761
9292   virtual DECLARE_WRITE8_MEMBER(io_write);
9393   virtual DECLARE_READ8_MEMBER(t0_read) { if (m_cart) return m_cart->t0_read(space, offset); else return 0; }
9494
95   virtual void write_bank(int bank)    { if (m_cart) m_cart->write_bank(bank); }
95   virtual void write_bank(int bank)   { if (m_cart) m_cart->write_bank(bank); }
9696
9797protected:
9898
r32760r32761
114114
115115#define MCFG_O2_CARTRIDGE_ADD(_tag,_slot_intf,_def_slot) \
116116   MCFG_DEVICE_ADD(_tag, O2_CART_SLOT, 0) \
117   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false) \
117   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false)
118118
119
120119SLOT_INTERFACE_EXTERN(o2_cart);
121120
122121#endif
trunk/src/emu/bus/odyssey2/chess.h
r32760r32761
1212
1313class o2_chess_device : public o2_rom_device
1414{
15   
1615   virtual machine_config_constructor device_mconfig_additions() const;
17//   virtual const rom_entry *device_rom_region() const;
18   
16//  virtual const rom_entry *device_rom_region() const;
17
1918public:
2019   // construction/destruction
2120   o2_chess_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
trunk/src/emu/bus/odyssey2/voice.h
r32760r32761
2727   virtual DECLARE_READ8_MEMBER(read_rom04) { if (m_subslot->exists()) return m_subslot->read_rom04(space, offset); else return 0xff; }
2828   virtual DECLARE_READ8_MEMBER(read_rom0c) { if (m_subslot->exists()) return m_subslot->read_rom0c(space, offset); else return 0xff; }
2929
30   virtual void write_bank(int bank)    { if (m_subslot->exists()) m_subslot->write_bank(bank); }
30   virtual void write_bank(int bank)   { if (m_subslot->exists()) m_subslot->write_bank(bank); }
3131
3232   DECLARE_WRITE_LINE_MEMBER(lrq_callback);
3333   DECLARE_WRITE8_MEMBER(io_write);
trunk/src/emu/bus/odyssey2/rom.c
r32760r32761
5050//-------------------------------------------------
5151
5252void o2_rom_device::device_start()
53{   
53{
5454   save_item(NAME(m_bank_base));
5555}
5656
5757void o2_rom_device::device_reset()
58{   
58{
5959   m_bank_base = 0;
6060}
6161
r32760r32761
9494{
9595   return m_rom[offset + 0xc00 + (m_bank_base & 0x03) * 0x1000];
9696}
97
trunk/src/emu/bus/odyssey2/slot.c
r32760r32761
166166   {
167167      UINT32 size = (software_entry() == NULL) ? length() : get_software_region_length("rom");
168168      m_cart->rom_alloc(size, tag());
169         
169
170170      if (software_entry() == NULL)
171171         fread(m_cart->get_rom_base(), size);
172172      else
r32760r32761
223223         type = O2_ROM12;
224224      if (size == 16384)
225225         type = O2_ROM16;
226     
226
227227      slot_string = o2_get_slot(type);
228228
229229      //printf("type: %s\n", slot_string);
r32760r32761
278278   SLOT_INTERFACE_INTERNAL("o2_chess",  O2_ROM_CHESS)
279279   SLOT_INTERFACE_INTERNAL("o2_voice",  O2_ROM_VOICE)
280280SLOT_INTERFACE_END
281
trunk/src/emu/bus/odyssey2/rom.h
r32760r32761
1515   // construction/destruction
1616   o2_rom_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
1717   o2_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
18   
18
1919   // device-level overrides
2020   virtual void device_start();
2121   virtual void device_reset();
22   
22
2323   // reading and writing
2424   virtual DECLARE_READ8_MEMBER(read_rom04);
2525   virtual DECLARE_READ8_MEMBER(read_rom0c);
26   
26
2727   virtual void write_bank(int bank);
28   
28
2929protected:
3030   int m_bank_base;
3131};
r32760r32761
3737public:
3838   // construction/destruction
3939   o2_rom12_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
40   
40
4141   // reading and writing
4242   virtual DECLARE_READ8_MEMBER(read_rom04);
4343   virtual DECLARE_READ8_MEMBER(read_rom0c);
r32760r32761
5050public:
5151   // construction/destruction
5252   o2_rom16_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
53   
53
5454   // reading and writing
5555   virtual DECLARE_READ8_MEMBER(read_rom04);
5656   virtual DECLARE_READ8_MEMBER(read_rom0c);
trunk/src/emu/bus/arcadia/slot.h
r32760r32761
9999
100100#define MCFG_ARCADIA_CARTRIDGE_ADD(_tag,_slot_intf,_def_slot) \
101101   MCFG_DEVICE_ADD(_tag, EA2001_CART_SLOT, 0) \
102   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false) \
103
102   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false)
104103#endif
trunk/src/emu/bus/arcadia/slot.c
r32760r32761
155155      UINT32 len = (software_entry() == NULL) ? length() : get_software_region_length("rom");
156156
157157      m_cart->rom_alloc(len, tag());
158         
158
159159      if (software_entry() == NULL)
160160         fread(m_cart->get_rom_base(), len);
161161      else
r32760r32761
260260   else
261261      return 0xff;
262262}
263
trunk/src/emu/bus/sms_ctrl/graphic.c
r32760r32761
99        0x20 | 0x7f
1010        0x00 | 0x3f
1111        0x30 | 0xff
12   
12
1313Typical sequence:
1414- 3f write 0x20
1515- read dc
1616- 3f write 0x00
17- read dc   
17- read dc
1818- 3f write 0x20
1919- read dc
2020- 3f write 0x30
2121Suspect from kind of counter that is reset by a 0x30 write to I/O port 0x3f.
2222Once reset reads from i/O port dc expect to see 0xE0.
23And then any write with differing bits goes through several internal I/O ports
23And then any write with differing bits goes through several internal I/O ports
2424with the first port being the one with the buttons
2525
2626In the reset/start state the lower four/five bits are 0.
r32760r32761
4545
4646
4747static INPUT_PORTS_START( sms_graphic )
48    PORT_START("BUTTONS")
49    PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) // MENU
50    PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) // DO
51    PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) // PEN
52    PORT_BIT( 0xf8, IP_ACTIVE_LOW, IPT_UNUSED )
48   PORT_START("BUTTONS")
49   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) // MENU
50   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) // DO
51   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) // PEN
52   PORT_BIT( 0xf8, IP_ACTIVE_LOW, IPT_UNUSED )
5353
5454   PORT_START("X")
5555   PORT_BIT( 0xff, 0x00, IPT_LIGHTGUN_X) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(50) PORT_KEYDELTA(15)
r32760r32761
110110   {
111111      case 0:     // Initial state / "I am a board"
112112         // If any regular button is pressed raise/lower TL ?
113//         if ((m_buttons->read() & 0x07) != 0x07)
114//            return 0xf0;
113//          if ((m_buttons->read() & 0x07) != 0x07)
114//              return 0xf0;
115115         return 0xd0;
116116
117117      case 1:    // Read buttons (active low)
r32760r32761
155155
156156   m_previous_write = data;
157157}
158
trunk/src/emu/bus/crvision/rom.h
r32760r32761
4343public:
4444   // construction/destruction
4545   crvision_rom8k_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
46   
46
4747   // reading and writing
4848   virtual DECLARE_READ8_MEMBER(read_rom80);
4949};
r32760r32761
5555public:
5656   // construction/destruction
5757   crvision_rom10k_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
58   
58
5959   // reading and writing
6060   virtual DECLARE_READ8_MEMBER(read_rom40);
6161   virtual DECLARE_READ8_MEMBER(read_rom80);
r32760r32761
6868public:
6969   // construction/destruction
7070   crvision_rom12k_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
71   
71
7272   // reading and writing
7373   virtual DECLARE_READ8_MEMBER(read_rom40);
7474   virtual DECLARE_READ8_MEMBER(read_rom80);
r32760r32761
8181public:
8282   // construction/destruction
8383   crvision_rom16k_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
84   
84
8585   // reading and writing
8686   virtual DECLARE_READ8_MEMBER(read_rom80);
8787};
r32760r32761
9393public:
9494   // construction/destruction
9595   crvision_rom18k_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
96   
96
9797   // reading and writing
9898   virtual DECLARE_READ8_MEMBER(read_rom40);
9999   virtual DECLARE_READ8_MEMBER(read_rom80);
trunk/src/emu/bus/crvision/slot.h
r32760r32761
104104
105105#define MCFG_CRVISION_CARTRIDGE_ADD(_tag,_slot_intf,_def_slot) \
106106   MCFG_DEVICE_ADD(_tag, CRVISION_CART_SLOT, 0) \
107   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false) \
108
107   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false)
109108#endif
trunk/src/emu/bus/crvision/rom.c
r32760r32761
8888   offset &= 0x1fff;
8989   if (offset < 0x1000)
9090      return m_rom[0x1000 + (offset & 0x7ff)];
91   
91
9292   return m_rom[offset & 0xfff];
9393}
9494
trunk/src/emu/bus/crvision/slot.c
r32760r32761
163163         seterror(IMAGE_ERROR_UNSPECIFIED, "Image extends beyond the expected size for an APF cart");
164164         return IMAGE_INIT_FAIL;
165165      }
166     
166
167167      m_cart->rom_alloc(size, tag());
168         
168
169169      if (software_entry() == NULL)
170170         fread(m_cart->get_rom_base(), size);
171171      else
r32760r32761
295295   else
296296      return 0xff;
297297}
298
trunk/src/emu/bus/c64/rex_ep256.h
r32760r32761
4949
5050private:
5151   generic_slot_device *m_eproms[8];
52   
52
5353   UINT8 m_bank, m_socket;
5454   int m_reset;
5555};
trunk/src/emu/bus/c64/dela_ep256.c
r32760r32761
7373      char str[6];
7474      sprintf(str, "rom%i", i + 1);
7575      m_eproms[i] = subdevice<generic_slot_device>(str);
76   }   
76   }
7777}
7878
7979
trunk/src/emu/bus/a7800/xboard.h
r32760r32761
1717   // construction/destruction
1818   a78_xboard_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
1919   a78_xboard_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
20   
20
2121   // device-level overrides
2222   virtual void device_start();
2323   virtual machine_config_constructor device_mconfig_additions() const;
2424   virtual void device_reset();
25   
25
2626   // reading and writing
2727   virtual DECLARE_READ8_MEMBER(read_04xx);
2828   virtual DECLARE_WRITE8_MEMBER(write_04xx);
r32760r32761
4343public:
4444   // construction/destruction
4545   a78_xm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
46   
46
4747   // device-level overrides
4848   virtual void device_start();
4949   virtual machine_config_constructor device_mconfig_additions() const;
5050   virtual void device_reset();
51   
51
5252   // reading and writing
5353   virtual DECLARE_READ8_MEMBER(read_04xx);
5454   virtual DECLARE_WRITE8_MEMBER(write_04xx);
5555   virtual DECLARE_READ8_MEMBER(read_10xx);
5656   virtual DECLARE_WRITE8_MEMBER(write_10xx);
5757   virtual DECLARE_READ8_MEMBER(read_30xx);
58   
58
5959protected:
6060   required_device<ym2151_device> m_ym;
6161   int m_ym_enabled;
trunk/src/emu/bus/a7800/a78_slot.h
r32760r32761
1212/* PCB */
1313enum
1414{
15   A78_TYPE0 = 0,      // standard 8K/16K/32K games, no bankswitch
16   A78_TYPE1,         // as TYPE0 + POKEY chip on the PCB
17   A78_TYPE2,         // Atari SuperGame pcb (8x16K banks with bankswitch)
18   A78_TYPE3,         // as TYPE1 + POKEY chip on the PCB
19   A78_TYPE6,         // as TYPE1 + RAM IC on the PCB
20   A78_TYPEA,         // Alien Brigade, Crossbow (9x16K banks with diff bankswitch)
21   A78_ABSOLUTE,      // F18 Hornet
22   A78_ACTIVISION,      // Double Dragon, Rampage
23   A78_HSC,         // Atari HighScore cart
24   A78_XB_BOARD,      // A7800 Expansion Board (it shall more or less apply to the Expansion Module too, but this is not officially released yet)
25   A78_XM_BOARD,      // A7800 XM Expansion Module (theoretical specs only, since this is not officially released yet)
26   A78_MEGACART,            // Homebrew by CPUWIZ, consists of SuperGame bank up to 512K + 32K RAM banked
27   A78_VERSABOARD = 0x10,      // Homebrew by CPUWIZ, consists of SuperGame bank up to 256K + 32K RAM banked
15   A78_TYPE0 = 0,      // standard 8K/16K/32K games, no bankswitch
16   A78_TYPE1,          // as TYPE0 + POKEY chip on the PCB
17   A78_TYPE2,          // Atari SuperGame pcb (8x16K banks with bankswitch)
18   A78_TYPE3,          // as TYPE1 + POKEY chip on the PCB
19   A78_TYPE6,          // as TYPE1 + RAM IC on the PCB
20   A78_TYPEA,          // Alien Brigade, Crossbow (9x16K banks with diff bankswitch)
21   A78_ABSOLUTE,       // F18 Hornet
22   A78_ACTIVISION,     // Double Dragon, Rampage
23   A78_HSC,            // Atari HighScore cart
24   A78_XB_BOARD,       // A7800 Expansion Board (it shall more or less apply to the Expansion Module too, but this is not officially released yet)
25   A78_XM_BOARD,       // A7800 XM Expansion Module (theoretical specs only, since this is not officially released yet)
26   A78_MEGACART,               // Homebrew by CPUWIZ, consists of SuperGame bank up to 512K + 32K RAM banked
27   A78_VERSABOARD = 0x10,      // Homebrew by CPUWIZ, consists of SuperGame bank up to 256K + 32K RAM banked
2828   // VersaBoard variants configured as Type 1/3/A or VersaBoard + POKEY at $0450
2929   A78_TYPE0_POK450 = 0x20,
3030   A78_TYPE1_POK450 = 0x21,
r32760r32761
6868   UINT8 *m_rom;
6969   UINT32 m_rom_size;
7070   dynamic_buffer m_ram;
71   dynamic_buffer m_nvram;   // HiScore cart can save scores!
71   dynamic_buffer m_nvram; // HiScore cart can save scores!
7272   // helpers
7373   UINT32 m_base_rom;
7474   int m_bank_mask;
r32760r32761
101101   int get_cart_type() { return m_type; };
102102   int identify_cart_type(UINT8 *ROM, UINT32 len);
103103   bool has_cart() { return m_cart != NULL; }
104   
104
105105   virtual iodevice_t image_type() const { return IO_CARTSLOT; }
106106   virtual bool is_readable()  const { return 1; }
107107   virtual bool is_writeable() const { return 0; }
r32760r32761
125125   virtual DECLARE_WRITE8_MEMBER(write_10xx);
126126   virtual DECLARE_WRITE8_MEMBER(write_30xx);
127127   virtual DECLARE_WRITE8_MEMBER(write_40xx);
128   
128
129129private:
130130   device_a78_cart_interface*       m_cart;
131131   int m_type;
trunk/src/emu/bus/a7800/cpuwiz.h
r32760r32761
1515   // construction/destruction
1616   a78_versaboard_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
1717   a78_versaboard_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
18   
18
1919   // device-level overrides
2020   virtual void device_start();
2121   virtual void device_reset();
22   
22
2323   // reading and writing
2424   virtual DECLARE_READ8_MEMBER(read_40xx);
2525   virtual DECLARE_WRITE8_MEMBER(write_40xx);
26   
26
2727protected:
2828   int m_ram_bank;
2929};
r32760r32761
3636public:
3737   // construction/destruction
3838   a78_megacart_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
39   
39
4040   // reading and writing
4141   virtual DECLARE_WRITE8_MEMBER(write_40xx);
4242};
r32760r32761
5151public:
5252   // construction/destruction
5353   a78_rom_p450_vb_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
54   
54
5555   // device-level overrides
5656   virtual machine_config_constructor device_mconfig_additions() const;
57   
57
5858   // reading and writing
5959   virtual DECLARE_READ8_MEMBER(read_04xx) { if (offset >= 0x50 && offset < 0x60) return m_pokey450->read(space, offset & 0x0f); else return 0xff; }
6060   virtual DECLARE_WRITE8_MEMBER(write_04xx) { if (offset >= 0x50 && offset < 0x60) m_pokey450->write(space, offset & 0x0f, data); }
61   
61
6262protected:
6363   required_device<pokey_device> m_pokey450;
6464};
trunk/src/emu/bus/a7800/hiscore.c
r32760r32761
33/***********************************************************************************************************
44
55 A7800 HighScore passthrough cart emulation
6 
76
7
88***********************************************************************************************************/
99
1010
r32760r32761
7575{
7676   m_hscslot->write_40xx(space, offset, data);
7777}
78
trunk/src/emu/bus/a7800/rom.c
r32760r32761
1010 - 9 banks or not
1111 etc...
1212 But we might merge many of these if they become too many
13
13
1414 TODO:
1515 - Are POKEY regs readable somewhere in SG 144K + POKEY homebrew? How do they detect
1616   the POKEY otherwise?!?
r32760r32761
232232/*-------------------------------------------------
233233
234234 Carts with no bankswitch + POKEY chip
235 The Pokey chips is accessed by writing at
235 The Pokey chips is accessed by writing at
236236 0x4000-0x7fff.
237
237
238238 GAMES: Ballblazer, Beef Drop (homebrew)
239
239
240240 -------------------------------------------------*/
241241
242242READ8_MEMBER(a78_rom_pokey_device::read_40xx)
r32760r32761
274274 some test is run)
275275 Note that the code is written so that also
276276 homebrew games with larger ROMs work!
277
277
278278 GAMES: Crack'd, Fatal Run, Ikari Warriors...
279
279
280280 -------------------------------------------------*/
281281
282282READ8_MEMBER(a78_rom_sg_device::read_40xx)
283283{
284284   if (offset < 0x4000)
285      return m_rom[(offset & 0x3fff) + ((m_bank_mask - 1) * 0x4000)];   // second to last bank (is this always ok?!?)
285      return m_rom[(offset & 0x3fff) + ((m_bank_mask - 1) * 0x4000)]; // second to last bank (is this always ok?!?)
286286   else if (offset < 0x8000)
287287      return m_rom[(offset & 0x3fff) + (m_bank * 0x4000)];
288288   else
289      return m_rom[(offset & 0x3fff) + (m_bank_mask * 0x4000)];   // last bank
289      return m_rom[(offset & 0x3fff) + (m_bank_mask * 0x4000)];   // last bank
290290}
291291
292292WRITE8_MEMBER(a78_rom_sg_device::write_40xx)
r32760r32761
300300
301301 Carts with SuperGame bankswitch + POKEY chip
302302 As above + Pokey chip access
303
303
304304 GAMES: Commando
305
305
306306 -------------------------------------------------*/
307307
308308READ8_MEMBER(a78_rom_sg_pokey_device::read_40xx)
r32760r32761
312312   else if (offset < 0x8000)
313313      return m_rom[(offset & 0x3fff) + (m_bank * 0x4000)];
314314   else
315      return m_rom[(offset & 0x3fff) + (m_bank_mask * 0x4000)];   // last bank
315      return m_rom[(offset & 0x3fff) + (m_bank_mask * 0x4000)];   // last bank
316316}
317317
318318WRITE8_MEMBER(a78_rom_sg_pokey_device::write_40xx)
r32760r32761
332332/*-------------------------------------------------
333333
334334 Carts with SuperGame bankswitch + 16K RAM
335 FIXME: Some games contained only 8K of RAM, but
335 FIXME: Some games contained only 8K of RAM, but
336336 for the moment we treat all as 16K of RAM even if
337337 from softlist we shall differentiate between them.
338
338
339339 GAMES: Impossible Mission, Jinks and some protos
340
340
341341 -------------------------------------------------*/
342342
343343READ8_MEMBER(a78_rom_sg_ram_device::read_40xx)
r32760r32761
347347   else if (offset < 0x8000)
348348      return m_rom[(offset & 0x3fff) + (m_bank * 0x4000)];
349349   else
350      return m_rom[(offset & 0x3fff) + (m_bank_mask * 0x4000)];   // last bank
350      return m_rom[(offset & 0x3fff) + (m_bank_mask * 0x4000)];   // last bank
351351}
352352
353353WRITE8_MEMBER(a78_rom_sg_ram_device::write_40xx)
r32760r32761
364364 Carts with SuperGame bankswitch 9banks:
365365 9 x 16K banks mappable in 0x8000-0xbfff
366366 bank 7 is always mapped in 0xc000-0xffff
367 
368 GAMES: Alien Brigade & Crossbow + some homebrew
369 like Donkey Kong XM demo, Bentley Bear's Crystal
367
368 GAMES: Alien Brigade & Crossbow + some homebrew
369 like Donkey Kong XM demo, Bentley Bear's Crystal
370370 Quest
371
371
372372 -------------------------------------------------*/
373373
374374READ8_MEMBER(a78_rom_sg9_device::read_40xx)
r32760r32761
378378   else if (offset < 0x8000)
379379      return m_rom[(offset & 0x3fff) + (m_bank * 0x4000)];
380380   else
381      return m_rom[(offset & 0x3fff) + ((m_bank_mask + 1) * 0x4000)];   // last bank
381      return m_rom[(offset & 0x3fff) + ((m_bank_mask + 1) * 0x4000)]; // last bank
382382}
383383
384384WRITE8_MEMBER(a78_rom_sg9_device::write_40xx)
r32760r32761
388388}
389389
390390/*-------------------------------------------------
391
391
392392 Carts with Absolute bankswitch:
393393 64K games. Lower 32K are 2 banks of 16K to be mapped
394394 in 0x4000-0x7fff, depending on the value written
395395 at 0x8000. Higher 32K are fixed in 0x8000-0xffff
396
396
397397 GAMES: F-18 Hornet
398
398
399399 -------------------------------------------------*/
400400
401401READ8_MEMBER(a78_rom_abs_device::read_40xx)
r32760r32761
431431 0x6000-0x7fff first 8kb of bank 6
432432 0x8000-0x9fff second 8kb of bank 7
433433 0xe000-0xffff first 8kb of bank 7
434
434
435435 GAMES: Double Dragon, Rampage.
436
436
437437 -------------------------------------------------*/
438438
439439READ8_MEMBER(a78_rom_act_device::read_40xx)
r32760r32761
495495{
496496   return MACHINE_CONFIG_NAME( a78_pokey450 );
497497}
498
trunk/src/emu/bus/a7800/xboard.c
r32760r32761
33/***********************************************************************************************************
44
55 A7800 XBoarD & XM expansions emulation
6
6
77 The XBoarD should be socketed in the A7800 pcb in place of the Maria chip.
88 It adds to the system additional 128K of RAM and an onboard pokey.
99 The XM seems to work the same as XBoarD, but it also features HighScore savings
r32760r32761
1212
1313 Currently, we emulate both of these as a passthru cart, even if not 100% accurate for the XBoarD
1414
15
15
1616 Memory map:
1717
1818 POKEY1            $0450    $045F     16 bytes
1919 POKEY2*           $0460    $046F     16 bytes
2020 XCTRL             $0470    $047F     1 byte
2121 RAM               $4000    $7FFF     16384 bytes
22
22
2323 XCTRL Bit Description
24
24
2525 +-------------------------------+
2626 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
2727 +-------------------------------+
2828   |   |   |   |   |   |   |   |
2929   |   |   |   |   |   |   |   +-- Bank select bit 0 \
3030   |   |   |   |   |   |   +------ Bank select bit 1  | Totally 128 KByte in 16 KByte banks
31   |   |   |   |   |   +---------- Bank select bit 2 /
31   |   |   |   |   |   +---------- Bank select bit 2 /
3232   |   |   |   |   +-------------- Enable memory bit (1 = Memory enabled, 0 after power on)
3333   |   |   |   +------------------ Enable POKEY bit** (1 = POKEY enabled, 0 after power on)
3434   |   |   |
3535   NA  NA  NA = Not Available or Not Used
36
36
3737 * = Can be mounted piggy back on the first POKEY. Description how to do this will come when i have tried it out.
3838 ** This bit controls both POKEY chip select signals.
39
39
4040 TODO:
4141  - verify what happens when 2 POKEYs are present
4242
r32760r32761
142142 -------------------------------------------------*/
143143
144144/*-------------------------------------------------
145
145
146146 XBoarD: passthru + 128K RAM + POKEY
147
147
148148 -------------------------------------------------*/
149149
150150READ8_MEMBER(a78_xboard_device::read_40xx)
r32760r32761
168168   if (BIT(m_reg, 4) && offset >= 0x50 && offset < 0x60)
169169      return m_pokey->read(space, offset & 0x0f);
170170   else if (BIT(m_reg, 4) && offset >= 0x60 && offset < 0x70)
171      return m_xbslot->read_04xx(space, offset - 0x10);   // access second POKEY
171      return m_xbslot->read_04xx(space, offset - 0x10);   // access second POKEY
172172   else
173173      return 0xff;
174174}
r32760r32761
178178   if (BIT(m_reg, 4) && offset >= 0x50 && offset < 0x60)
179179      m_pokey->write(space, offset & 0x0f, data);
180180   else if (BIT(m_reg, 4) && offset >= 0x60 && offset < 0x70)
181      m_xbslot->write_04xx(space, offset - 0x10, data);   // access second POKEY
181      m_xbslot->write_04xx(space, offset - 0x10, data);   // access second POKEY
182182   else if (offset >= 0x70 && offset < 0x80)
183183   {
184184      m_reg = data;
r32760r32761
188188
189189
190190/*-------------------------------------------------
191
191
192192 XM: Same as above but also featuring High Score savings
193
193
194194 -------------------------------------------------*/
195195
196196READ8_MEMBER(a78_xm_device::read_10xx)
r32760r32761
215215   else if (m_ym_enabled && offset >= 0x60 && offset <= 0x61)
216216      return m_ym->read(space, offset & 1);
217217   else if (BIT(m_reg, 4) && offset >= 0x60 && offset < 0x70)
218      return m_xbslot->read_04xx(space, offset - 0x10);   // access second POKEY
218      return m_xbslot->read_04xx(space, offset - 0x10);   // access second POKEY
219219   else
220220      return 0xff;
221221}
r32760r32761
227227   else if (m_ym_enabled && offset >= 0x60 && offset <= 0x61)
228228      m_ym->write(space, offset & 1, data);
229229   else if (BIT(m_reg, 4) && offset >= 0x60 && offset < 0x70)
230      m_xbslot->write_04xx(space, offset - 0x10, data);   // access second POKEY
230      m_xbslot->write_04xx(space, offset - 0x10, data);   // access second POKEY
231231   else if (offset >= 0x70 && offset < 0x80)
232232   {
233233      //printf("regs 0x%X\n", data);
trunk/src/emu/bus/a7800/a78_carts.h
r32760r32761
2020   SLOT_INTERFACE_INTERNAL("a78_abs",      A78_ROM_ABSOLUTE)
2121   SLOT_INTERFACE_INTERNAL("a78_act",      A78_ROM_ACTIVISION)
2222   SLOT_INTERFACE_INTERNAL("a78_hsc",      A78_HISCORE)
23   SLOT_INTERFACE_INTERNAL("a78_xboard",   A78_XBOARD)   // the actual XBoarD expansion (as passthru)
24   SLOT_INTERFACE_INTERNAL("a78_xm",       A78_XM)       // the actual XM expansion (as passthru)
25   SLOT_INTERFACE_INTERNAL("a78_megacart", A78_ROM_MEGACART)   
26   SLOT_INTERFACE_INTERNAL("a78_versa",    A78_ROM_VERSABOARD)   
23   SLOT_INTERFACE_INTERNAL("a78_xboard",   A78_XBOARD) // the actual XBoarD expansion (as passthru)
24   SLOT_INTERFACE_INTERNAL("a78_xm",       A78_XM)     // the actual XM expansion (as passthru)
25   SLOT_INTERFACE_INTERNAL("a78_megacart", A78_ROM_MEGACART)
26   SLOT_INTERFACE_INTERNAL("a78_versa",    A78_ROM_VERSABOARD)
2727   // cart variants with a POKEY at 0x0450 (typically a VersaBoard variant, or an homebrew pcb)
2828   SLOT_INTERFACE_INTERNAL("a78_p450_t0",  A78_ROM_P450)
2929   SLOT_INTERFACE_INTERNAL("a78_p450_t1",  A78_ROM_P450_POKEY)
trunk/src/emu/bus/a7800/a78_slot.c
r32760r32761
2121    - read_40xx/write_40xx for accesses in the $4000 to $ffff range
2222    even if not all carts use all of them (in particular no cart type
2323    seems to use access to the ranges $0500 to $0fff and $2800 to $2fff)
24 
2524
25
2626 ***********************************************************************************************************/
2727
2828
r32760r32761
7070      tempstring.cat(A78SLOT_ROM_REGION_TAG);
7171      m_rom = device().machine().memory().region_alloc(tempstring, size, 1, ENDIANNESS_LITTLE)->base();
7272      m_rom_size = size;
73     
73
7474      // setup other helpers
7575      if ((size / 0x4000) & 1) // compensate for SuperGame carts with 9 x 16K banks (to my knowledge no other cart has m_bank_mask != power of 2)
7676         m_bank_mask = (size / 0x4000) - 2;
7777      else
7878         m_bank_mask = (size / 0x4000) - 1;
79     
79
8080      // the rom is mapped to the top of the memory area
81      // so we store the starting point of data to simplify
81      // so we store the starting point of data to simplify
8282      // the access handling
8383      m_base_rom = 0x10000 - size;
8484   }
r32760r32761
272272      }
273273      head &= 0xff00;
274274   }
275   
275
276276   if ((head & 0xff00) > 0x300)
277277   {
278278      if (log)
r32760r32761
282282      }
283283      head &= 0x00ff;
284284   }
285   
285
286286   return head;
287287}
288288
r32760r32761
329329      if (!core_stricmp(slot_list[i].slot_option, slot))
330330         return slot_list[i].pcb_id;
331331   }
332   
332
333333   return 0;
334334}
335335
r32760r32761
340340      if (slot_list[i].pcb_id == type)
341341         return slot_list[i].slot_option;
342342   }
343   
343
344344   return "a78_rom";
345345}
346346
r32760r32761
349349   if (m_cart)
350350   {
351351      UINT32 len;
352     
352
353353      if (software_entry() != NULL)
354354      {
355355         const char *pcb_name;
356356         bool has_ram = get_software_region("ram") ? TRUE : FALSE;
357357         bool has_nvram = get_software_region("nvram") ? TRUE : FALSE;
358358         len = get_software_region_length("rom");
359         
359
360360         m_cart->rom_alloc(len, tag());
361361         memcpy(m_cart->get_rom_base(), get_software_region("rom"), len);
362         
362
363363         if ((pcb_name = get_feature("slot")) != NULL)
364364            m_type = a78_get_pcb_id(pcb_name);
365365         else
r32760r32761
377377      {
378378         // Load and check the header
379379         int mapper;
380         char head[128];     
380         char head[128];
381381         fread(head, 128);
382         
382
383383         if (verify_header((char *)head) == IMAGE_VERIFY_FAIL)
384384            return IMAGE_INIT_FAIL;
385         
385
386386         len = (head[49] << 24) | (head[50] << 16) | (head[51] << 8) | head[52];
387387         if (len + 128 > length())
388388         {
389389            logerror("Invalid length in the header. The game might be corrupted.\n");
390390            len = length() - 128;
391391         }
392         
392
393393         // let's try to auto-fix some common errors in the header
394394         mapper = validate_header((head[53] << 8) | head[54], TRUE);
395395
r32760r32761
415415                  m_type = A78_VERSABOARD;
416416               break;
417417         }
418         
418
419419         // check if cart has a POKEY at $0450 (typically a VersaBoard variant)!
420420         if (mapper & 0x40)
421421         {
r32760r32761
425425               m_type += A78_POKEY0450;
426426            }
427427         }
428         
428
429429         // check special bits, which override the previous
430430         if ((mapper & 0xff00) == 0x0100)
431431            m_type = A78_ACTIVISION;
r32760r32761
452452         }
453453
454454         internal_header_logging((UINT8 *)head, length());
455         
455
456456         m_cart->rom_alloc(len, tag());
457457         fread(m_cart->get_rom_base(), len);
458         
458
459459         if (m_type == A78_TYPE6)
460460            m_cart->ram_alloc(0x4000);
461461         if (m_type == A78_MEGACART || (m_type >= A78_VERSABOARD && m_type <= A78_VERSA_POK450))
r32760r32761
468468            battery_load(m_cart->get_nvram_base(), 0x800, 0xff);
469469         }
470470      }
471     
471
472472      //printf("Type: %s\n", a78_get_slot(m_type));
473473   }
474474   return IMAGE_INIT_PASS;
r32760r32761
476476
477477
478478void a78_partialhash(hash_collection &dest, const unsigned char *data,
479                unsigned long length, const char *functions)
479                  unsigned long length, const char *functions)
480480{
481481   if (length <= 128)
482482      return;
r32760r32761
537537      const char *slot_string = "a78_rom";
538538      dynamic_buffer head(128);
539539      int type = A78_TYPE0, mapper;
540     
540
541541      // Load and check the header
542      core_fread(m_file, head, 128);     
542      core_fread(m_file, head, 128);
543543
544544      // let's try to auto-fix some common errors in the header
545545      mapper = validate_header((head[53] << 8) | head[54], FALSE);
546     
546
547547      switch (mapper & 0x2e)
548548      {
549549         case 0x0000:
r32760r32761
566566               type = A78_VERSABOARD;
567567            break;
568568      }
569     
569
570570      // check if cart has a POKEY at $0450 (typically a VersaBoard variant)!
571571      if (mapper & 0x40)
572572      {
r32760r32761
576576            type += A78_POKEY0450;
577577         }
578578      }
579     
579
580580      // check special bits, which override the previous
581581      if ((mapper & 0xff00) == 0x0100)
582582         type = A78_ACTIVISION;
583583      else if ((mapper & 0xff00) == 0x0200)
584584         type = A78_ABSOLUTE;
585     
585
586586      logerror("Cart type: %x\n", type);
587587      slot_string = a78_get_slot(type);
588     
588
589589      clear();
590     
590
591591      result.cpy(slot_string);
592592   }
593593   else
r32760r32761
663663
664664/*-------------------------------------------------
665665 A78 header logging
666
666
667667 A78 HEADER FORMAT
668
668
669669 Bytes  | Content           | Length
670670 ========================================
671671 0      | Header version    |  1 byte
r32760r32761
679679 53..54 | Cart type [*]     |  2 bytes
680680 -------|-------------------|------------
681681 55     | Controller 1 type |  1 byte
682      |                   |
682        |                   |
683683        | 0 = None          |
684684        | 1 = Joystick      |
685685        | 2 = Light Gun     |
r32760r32761
690690 -------|-------------------|------------
691691 57     | TV System         |  1 byte
692692        |                   |
693      | 0 = NTSC/1 = PAL  |
693        | 0 = NTSC/1 = PAL  |
694694 -------|-------------------|------------
695695 58     | Save data         |  1 byte
696696        |                   |  (only v2)
697697        | 0 = None / Unk    |
698698        | 1 = High Score    |
699699        | 2 = Savekey       |
700 -------|-------------------|-----------
700 -------|-------------------|-----------
701701 63     | Expansion module  |  1 byte
702702        |                   |
703703        | 0 = No expansion  |
704704        |     module        |
705705        | 1 = Expansion     |
706706        |     required      |
707 -------|-------------------|-----------
708 
709 
707 -------|-------------------|-----------
708
709
710710 [*] Cart type:
711711
712712 bit 0-7 - Hardware "flags"
r32760r32761
716716 bit 3 [0x08] - bank 0 of 144K ROM at $4000
717717 bit 4 [0x10] - bank 6 at $4000
718718 bit 5 [0x20] - banked RAM at $4000
719
719
720720 bit 8-15 - Special values
721721 0 = Normal cart
722722 1 = Absolute (F18 Hornet)
723723 2 = Activision (Double Dragon & Rampage)
724724 3 = POKEY at $0450
725
725
726726 -------------------------------------------------*/
727727
728728void a78_cart_slot_device::internal_header_logging(UINT8 *header, UINT32 len)
r32760r32761
788788         ctrl1.cpy("Unknown controller");
789789         break;
790790   }
791   
791
792792   switch (head_ctrl2)
793793   {
794794      case 0x00:
r32760r32761
804804         ctrl2.cpy("Unknown controller");
805805         break;
806806   }
807   
807
808808   logerror( "ROM DETAILS\n" );
809809   logerror( "===========\n\n" );
810   logerror( "\tTotal length (with header):  0x%x (%dK + 128b header)\n\n", len, len/0x400);   
810   logerror( "\tTotal length (with header):  0x%x (%dK + 128b header)\n\n", len, len/0x400);
811811   logerror( "HEADER DETAILS\n" );
812812   logerror( "==============\n\n" );
813813   logerror( "\tTitle:           %.32s\n", head_title);
r32760r32761
829829      logerror( "\n");
830830   logerror( "\tController 1:    0x%.2X [%s]\n", head_ctrl1, ctrl1.cstr());
831831   logerror( "\tController 2:    0x%.2X [%s]\n", head_ctrl2, ctrl2.cstr());
832   logerror( "\tVideo:           %s\n", (head_ispal) ? "PAL" : "NTSC");   
832   logerror( "\tVideo:           %s\n", (head_ispal) ? "PAL" : "NTSC");
833833}
trunk/src/emu/bus/a7800/cpuwiz.c
r32760r32761
33/***********************************************************************************************************
44
55 A7800 CPUWIZ's homebrew boards (MegaCart+ and VersaBoard)
6
6
77 Here we emulate the base configurations of these two boards:
88
99 MegaCart+ = up to 512K (31 banks at $8000, 1 at $C000) of ROM and 2 x 16K RAM @ $4000
1010 VersaBoard = up to 256K of ROM and 2 x 16K RAM
11 
12 Plus, for the moment, a VersaBoard with POKEY mapped at 0x0450 and support for 144K ROM,
13 since a few demo homebrew programs seems to use this to combine compatibility with
11
12 Plus, for the moment, a VersaBoard with POKEY mapped at 0x0450 and support for 144K ROM,
13 since a few demo homebrew programs seems to use this to combine compatibility with
1414 XBoarD & XM expansions
1515
1616 Note that the VersaBoard can be configured to work with different banking hardware
1717 e.g. with SG 9bank games or with SG + RAM (so to allow reproduction of games which
18 could have worked on old carts without sacrifying original carts), but games running
18 could have worked on old carts without sacrifying original carts), but games running
1919 on those "standard" variants can be emulated with the standard code from rom.c ;-)
20 
21 
20
21
2222 TO DO:
2323 - investigate whether the POKEY detection routines in homebrew do fail due to emulation
2424   issues or not
25
25
2626***********************************************************************************************************/
2727
2828
r32760r32761
8686   else if (offset < 0x8000)
8787      return m_rom[(offset & 0x3fff) + (m_bank * 0x4000)];
8888   else
89      return m_rom[(offset & 0x3fff) + (m_bank_mask * 0x4000)];   // last bank
89      return m_rom[(offset & 0x3fff) + (m_bank_mask * 0x4000)];   // last bank
9090}
9191
9292WRITE8_MEMBER(a78_versaboard_device::write_40xx)
r32760r32761
130130{
131131   return MACHINE_CONFIG_NAME( a78_pokeyvb );
132132}
133
134
trunk/src/emu/bus/a7800/hiscore.h
r32760r32761
1414public:
1515   // construction/destruction
1616   a78_hiscore_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
17   
17
1818   // device-level overrides
1919   virtual machine_config_constructor device_mconfig_additions() const;
20   
20
2121   // reading and writing
2222   virtual DECLARE_READ8_MEMBER(read_04xx);
2323   virtual DECLARE_WRITE8_MEMBER(write_04xx);
trunk/src/emu/bus/a7800/rom.h
r32760r32761
3434   // construction/destruction
3535   a78_rom_pokey_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
3636   a78_rom_pokey_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
37   
37
3838   // device-level overrides
3939   virtual machine_config_constructor device_mconfig_additions() const;
40   
40
4141   // reading and writing
4242   virtual DECLARE_READ8_MEMBER(read_40xx);
4343   virtual DECLARE_WRITE8_MEMBER(write_40xx);
44   
44
4545protected:
4646   required_device<pokey_device> m_pokey;
4747};
r32760r32761
5555   // construction/destruction
5656   a78_rom_sg_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
5757   a78_rom_sg_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
58   
58
5959   // device-level overrides
6060   virtual void device_start();
6161   virtual void device_reset();
62   
62
6363   // reading and writing
6464   virtual DECLARE_READ8_MEMBER(read_40xx);
6565   virtual DECLARE_WRITE8_MEMBER(write_40xx);
r32760r32761
7676public:
7777   // construction/destruction
7878   a78_rom_sg_pokey_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
79   
79
8080   // device-level overrides
8181   virtual machine_config_constructor device_mconfig_additions() const;
82   
82
8383   // reading and writing
8484   virtual DECLARE_READ8_MEMBER(read_40xx);
8585   virtual DECLARE_WRITE8_MEMBER(write_40xx);
86   
86
8787protected:
8888   required_device<pokey_device> m_pokey;
8989};
r32760r32761
9797   // construction/destruction
9898   a78_rom_sg_ram_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
9999   a78_rom_sg_ram_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
100   
100
101101   // reading and writing
102102   virtual DECLARE_READ8_MEMBER(read_40xx);
103103   virtual DECLARE_WRITE8_MEMBER(write_40xx);
r32760r32761
112112   // construction/destruction
113113   a78_rom_sg9_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
114114   a78_rom_sg9_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
115   
115
116116   // reading and writing
117117   virtual DECLARE_READ8_MEMBER(read_40xx);
118118   virtual DECLARE_WRITE8_MEMBER(write_40xx);
r32760r32761
126126public:
127127   // construction/destruction
128128   a78_rom_abs_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
129   
129
130130   // device-level overrides
131131   virtual void device_start();
132132   virtual void device_reset();
133   
133
134134   // reading and writing
135135   virtual DECLARE_READ8_MEMBER(read_40xx);
136136   virtual DECLARE_WRITE8_MEMBER(write_40xx);
137   
137
138138protected:
139139   int m_bank;
140140};
r32760r32761
147147public:
148148   // construction/destruction
149149   a78_rom_act_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
150   
150
151151   // device-level overrides
152152   virtual void device_start();
153153   virtual void device_reset();
154   
154
155155   // reading and writing
156156   virtual DECLARE_READ8_MEMBER(read_40xx);
157157   virtual DECLARE_WRITE8_MEMBER(write_40xx);
158   
158
159159protected:
160160   int m_bank;
161161};
r32760r32761
170170public:
171171   // construction/destruction
172172   a78_rom_p450_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
173   
173
174174   virtual machine_config_constructor device_mconfig_additions() const;
175   
175
176176   // reading and writing
177177   virtual DECLARE_READ8_MEMBER(read_04xx) { if (offset >= 0x50 && offset < 0x60) return m_pokey450->read(space, offset & 0x0f); else return 0xff; }
178178   virtual DECLARE_WRITE8_MEMBER(write_04xx) { if (offset >= 0x50 && offset < 0x60) m_pokey450->write(space, offset & 0x0f, data); }
179   
179
180180protected:
181181   required_device<pokey_device> m_pokey450;
182182};
r32760r32761
189189public:
190190   // construction/destruction
191191   a78_rom_p450_pokey_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
192   
192
193193   virtual machine_config_constructor device_mconfig_additions() const;
194   
194
195195   // reading and writing
196196   virtual DECLARE_READ8_MEMBER(read_04xx) { if (offset >= 0x50 && offset < 0x60) return m_pokey450->read(space, offset & 0x0f); else return 0xff; }
197197   virtual DECLARE_WRITE8_MEMBER(write_04xx) { if (offset >= 0x50 && offset < 0x60) m_pokey450->write(space, offset & 0x0f, data); }
198   
198
199199protected:
200200   required_device<pokey_device> m_pokey450;
201201};
r32760r32761
208208public:
209209   // construction/destruction
210210   a78_rom_p450_sg_ram_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
211   
211
212212   virtual machine_config_constructor device_mconfig_additions() const;
213   
213
214214   // reading and writing
215215   virtual DECLARE_READ8_MEMBER(read_04xx) { if (offset >= 0x50 && offset < 0x60) return m_pokey450->read(space, offset & 0x0f); else return 0xff; }
216216   virtual DECLARE_WRITE8_MEMBER(write_04xx) { if (offset >= 0x50 && offset < 0x60) m_pokey450->write(space, offset & 0x0f, data); }
217   
217
218218protected:
219219   required_device<pokey_device> m_pokey450;
220220};
r32760r32761
227227public:
228228   // construction/destruction
229229   a78_rom_p450_sg9_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
230   
230
231231   virtual machine_config_constructor device_mconfig_additions() const;
232232
233233   // reading and writing
234234   virtual DECLARE_READ8_MEMBER(read_04xx) { if (offset >= 0x50 && offset < 0x60) return m_pokey450->read(space, offset & 0x0f); else return 0xff; }
235235   virtual DECLARE_WRITE8_MEMBER(write_04xx) { if (offset >= 0x50 && offset < 0x60) m_pokey450->write(space, offset & 0x0f, data); }
236   
236
237237protected:
238238   required_device<pokey_device> m_pokey450;
239239};
trunk/src/emu/bus/msx_slot/disk.c
r32760r32761
677677
678678void msx_slot_disk6_device::select_drive()
679679{
680   if (m_drive_select1)   
680   if (m_drive_select1)
681681   {
682682      m_floppy = m_floppy1 ? m_floppy1->get_device() : NULL;
683683      if (!m_floppy)
r32760r32761
809809         break;
810810   }
811811}
812
trunk/src/emu/bus/isa/trident.c
r32760r32761
4545UINT16 trident_vga_device::READPIXEL15(INT16 x, INT16 y)
4646{
4747   return (vga.memory[((y & 0xfff)*offset() + (x & 0xfff)*2) % vga.svga_intf.vram_size] |
48           (vga.memory[((y & 0xfff)*offset() + ((x & 0xfff)*2)+1) % vga.svga_intf.vram_size] << 8));
48         (vga.memory[((y & 0xfff)*offset() + ((x & 0xfff)*2)+1) % vga.svga_intf.vram_size] << 8));
4949}
5050
5151UINT16 trident_vga_device::READPIXEL16(INT16 x, INT16 y)
5252{
5353   return (vga.memory[((y & 0xfff)*offset() + (x & 0xfff)*2) % vga.svga_intf.vram_size] |
54           (vga.memory[((y & 0xfff)*offset() + ((x & 0xfff)*2)+1) % vga.svga_intf.vram_size] << 8));
54         (vga.memory[((y & 0xfff)*offset() + ((x & 0xfff)*2)+1) % vga.svga_intf.vram_size] << 8));
5555}
5656
5757UINT32 trident_vga_device::READPIXEL32(INT16 x, INT16 y)
5858{
5959   return (vga.memory[((y & 0xfff)*offset() + (x & 0xfff)*4) % vga.svga_intf.vram_size] |
60         (vga.memory[((y & 0xfff)*offset() + ((x & 0xfff)*4)+1) % vga.svga_intf.vram_size] << 8) |
61         (vga.memory[((y & 0xfff)*offset() + ((x & 0xfff)*4)+2) % vga.svga_intf.vram_size] << 16) |
62         (vga.memory[((y & 0xfff)*offset() + ((x & 0xfff)*4)+3) % vga.svga_intf.vram_size] << 24));
60         (vga.memory[((y & 0xfff)*offset() + ((x & 0xfff)*4)+1) % vga.svga_intf.vram_size] << 8) |
61         (vga.memory[((y & 0xfff)*offset() + ((x & 0xfff)*4)+2) % vga.svga_intf.vram_size] << 16) |
62         (vga.memory[((y & 0xfff)*offset() + ((x & 0xfff)*4)+3) % vga.svga_intf.vram_size] << 24));
6363}
6464
6565void trident_vga_device::WRITEPIXEL8(INT16 x, INT16 y, UINT8 data)
r32760r32761
249249         for(x=0;x<cursor_size;x++)
250250         {
251251            UINT32 bitb = (vga.memory[(src+3) % vga.svga_intf.vram_size]
252                        | ((vga.memory[(src+2) % vga.svga_intf.vram_size]) << 8)
253                        | ((vga.memory[(src+1) % vga.svga_intf.vram_size]) << 16)
254                        | ((vga.memory[(src+0) % vga.svga_intf.vram_size]) << 24));
252                     | ((vga.memory[(src+2) % vga.svga_intf.vram_size]) << 8)
253                     | ((vga.memory[(src+1) % vga.svga_intf.vram_size]) << 16)
254                     | ((vga.memory[(src+0) % vga.svga_intf.vram_size]) << 24));
255255            UINT32 bita = (vga.memory[(src+7) % vga.svga_intf.vram_size]
256256                     | ((vga.memory[(src+6) % vga.svga_intf.vram_size]) << 8)
257257                     | ((vga.memory[(src+5) % vga.svga_intf.vram_size]) << 16)
r32760r32761
11311131/*
11321132Graphics Engine for 9440/9660/9680
11331133
1134#define GER_STATUS   0x2120
1135#define      GE_BUSY   0x80
1136#define GER_OPERMODE   0x2122       Byte for 9440, Word for 96xx
1137#define      DST_ENABLE   0x200   // Destination Transparency
1138#define GER_COMMAND   0x2124
1139#define      GE_NOP      0x00   // No Operation
1140#define      GE_BLT      0x01   // BitBLT ROP3 only
1141#define      GE_BLT_ROP4   0x02   // BitBLT ROP4 (96xx only)
1142#define      GE_SCANLINE   0x03   // Scan Line
1143#define      GE_BRESLINE   0x04   // Bresenham Line
1144#define      GE_SHVECTOR   0x05   // Short Vector
1145#define      GE_FASTLINE   0x06   // Fast Line (96xx only)
1146#define      GE_TRAPEZ   0x07   // Trapezoidal fill (96xx only)
1147#define      GE_ELLIPSE   0x08   // Ellipse (96xx only) (RES)
1148#define      GE_ELLIP_FILL   0x09   // Ellipse Fill (96xx only) (RES)
1149#define   GER_FMIX   0x2127
1150#define GER_DRAWFLAG   0x2128      // long
1151#define      FASTMODE   1<<28
1152#define      STENCIL      0x8000
1153#define      SOLIDFILL   0x4000
1154#define      TRANS_ENABLE   0x1000
1155#define    TRANS_REVERSE   0x2000
1156#define      YMAJ      0x0400
1157#define      XNEG      0x0200
1158#define      YNEG      0x0100
1159#define      SRCMONO      0x0040
1160#define      PATMONO      0x0020
1161#define      SCR2SCR      0x0004
1162#define      PAT2SCR      0x0002
1163#define GER_FCOLOUR   0x212C      // Word for 9440, long for 96xx
1164#define GER_BCOLOUR   0x2130      // Word for 9440, long for 96xx
1165#define GER_PATLOC   0x2134      // Word
1166#define GER_DEST_XY   0x2138
1167#define GER_DEST_X   0x2138      // Word
1168#define GER_DEST_Y   0x213A      // Word
1169#define GER_SRC_XY   0x213C
1170#define GER_SRC_X   0x213C      // Word
1171#define GER_SRC_Y   0x213E      // Word
1172#define GER_DIM_XY   0x2140
1173#define GER_DIM_X   0x2140      // Word
1174#define GER_DIM_Y   0x2142      // Word
1175#define GER_STYLE   0x2144      // Long
1176#define GER_CKEY   0x2168      // Long
1177#define GER_FPATCOL   0x2178
1178#define GER_BPATCOL   0x217C
1179#define GER_PATTERN   0x2180      // from 0x2180 to 0x21FF
1134#define GER_STATUS  0x2120
1135#define     GE_BUSY 0x80
1136#define GER_OPERMODE    0x2122       Byte for 9440, Word for 96xx
1137#define     DST_ENABLE  0x200   // Destination Transparency
1138#define GER_COMMAND 0x2124
1139#define     GE_NOP      0x00    // No Operation
1140#define     GE_BLT      0x01    // BitBLT ROP3 only
1141#define     GE_BLT_ROP4 0x02    // BitBLT ROP4 (96xx only)
1142#define     GE_SCANLINE 0x03    // Scan Line
1143#define     GE_BRESLINE 0x04    // Bresenham Line
1144#define     GE_SHVECTOR 0x05    // Short Vector
1145#define     GE_FASTLINE 0x06    // Fast Line (96xx only)
1146#define     GE_TRAPEZ   0x07    // Trapezoidal fill (96xx only)
1147#define     GE_ELLIPSE  0x08    // Ellipse (96xx only) (RES)
1148#define     GE_ELLIP_FILL   0x09    // Ellipse Fill (96xx only) (RES)
1149#define GER_FMIX    0x2127
1150#define GER_DRAWFLAG    0x2128      // long
1151#define     FASTMODE    1<<28
1152#define     STENCIL     0x8000
1153#define     SOLIDFILL   0x4000
1154#define     TRANS_ENABLE    0x1000
1155#define     TRANS_REVERSE   0x2000
1156#define     YMAJ        0x0400
1157#define     XNEG        0x0200
1158#define     YNEG        0x0100
1159#define     SRCMONO     0x0040
1160#define     PATMONO     0x0020
1161#define     SCR2SCR     0x0004
1162#define     PAT2SCR     0x0002
1163#define GER_FCOLOUR 0x212C      // Word for 9440, long for 96xx
1164#define GER_BCOLOUR 0x2130      // Word for 9440, long for 96xx
1165#define GER_PATLOC  0x2134      // Word
1166#define GER_DEST_XY 0x2138
1167#define GER_DEST_X  0x2138      // Word
1168#define GER_DEST_Y  0x213A      // Word
1169#define GER_SRC_XY  0x213C
1170#define GER_SRC_X   0x213C      // Word
1171#define GER_SRC_Y   0x213E      // Word
1172#define GER_DIM_XY  0x2140
1173#define GER_DIM_X   0x2140      // Word
1174#define GER_DIM_Y   0x2142      // Word
1175#define GER_STYLE   0x2144      // Long
1176#define GER_CKEY    0x2168      // Long
1177#define GER_FPATCOL 0x2178
1178#define GER_BPATCOL 0x217C
1179#define GER_PATTERN 0x2180      // from 0x2180 to 0x21FF
11801180
11811181 Additional - Graphics Engine for 96xx
1182#define GER_SRCCLIP_XY   0x2148
1183#define GER_SRCCLIP_X   0x2148      // Word
1184#define GER_SRCCLIP_Y   0x214A      // Word
1185#define GER_DSTCLIP_XY   0x214C
1186#define GER_DSTCLIP_X   0x214C      // Word
1187#define GER_DSTCLIP_Y   0x214E      // Word
1182#define GER_SRCCLIP_XY  0x2148
1183#define GER_SRCCLIP_X   0x2148      // Word
1184#define GER_SRCCLIP_Y   0x214A      // Word
1185#define GER_DSTCLIP_XY  0x214C
1186#define GER_DSTCLIP_X   0x214C      // Word
1187#define GER_DSTCLIP_Y   0x214E      // Word
11881188*/
11891189
11901190READ8_MEMBER(trident_vga_device::accel_r)
trunk/src/emu/bus/isa/svga_trident.c
r32760r32761
8787   m_isa->install_memory(0xa0000, 0xbffff, 0, 0, read8_delegate(FUNC(trident_vga_device::mem_r),m_vga), write8_delegate(FUNC(trident_vga_device::mem_w),m_vga));
8888
8989   // uncomment to test Windows 3.1 TGUI9440AGi driver
90//   m_isa->install_memory(0x4400000, 0x45fffff, 0, 0, read8_delegate(FUNC(trident_vga_device::vram_r),m_vga), write8_delegate(FUNC(trident_vga_device::vram_w),m_vga));
90//  m_isa->install_memory(0x4400000, 0x45fffff, 0, 0, read8_delegate(FUNC(trident_vga_device::vram_r),m_vga), write8_delegate(FUNC(trident_vga_device::vram_w),m_vga));
9191
9292   // win95 drivers
93//   m_isa->install_memory(0x4000000, 0x41fffff, 0, 0, read8_delegate(FUNC(trident_vga_device::vram_r),m_vga), write8_delegate(FUNC(trident_vga_device::vram_w),m_vga));
93//  m_isa->install_memory(0x4000000, 0x41fffff, 0, 0, read8_delegate(FUNC(trident_vga_device::vram_r),m_vga), write8_delegate(FUNC(trident_vga_device::vram_w),m_vga));
9494
9595   // acceleration ports
9696   m_isa->install_device(0x2120, 0x21ff, 0, 0, read8_delegate(FUNC(trident_vga_device::accel_r),m_vga), write8_delegate(FUNC(trident_vga_device::accel_w),m_vga));
trunk/src/emu/bus/isa/sb16.c
r32760r32761
370370
371371static ADDRESS_MAP_START(sb16_io, AS_IO, 8, sb16_lle_device)
372372   AM_RANGE(0x0000, 0x0000) AM_MIRROR(0xff00) AM_READWRITE(dsp_data_r, dsp_data_w)
373//   AM_RANGE(0x0001, 0x0001) // MIDI related?
374//   AM_RANGE(0x0002, 0x0002)
373//  AM_RANGE(0x0001, 0x0001) // MIDI related?
374//  AM_RANGE(0x0002, 0x0002)
375375   AM_RANGE(0x0004, 0x0004) AM_MIRROR(0xff00) AM_READWRITE(mode_r, mode_w)
376376   AM_RANGE(0x0005, 0x0005) AM_MIRROR(0xff00) AM_READWRITE(dac_ctrl_r, dac_ctrl_w)
377377   AM_RANGE(0x0006, 0x0006) AM_MIRROR(0xff00) AM_READ(dma_stat_r)
378//   AM_RANGE(0x0007, 0x0007) // unknown
378//  AM_RANGE(0x0007, 0x0007) // unknown
379379   AM_RANGE(0x0008, 0x0008) AM_MIRROR(0xff00) AM_READWRITE(ctrl8_r, ctrl8_w)
380380   AM_RANGE(0x0009, 0x0009) AM_MIRROR(0xff00) AM_WRITE(rate_w)
381381   AM_RANGE(0x000A, 0x000A) AM_MIRROR(0xff00) AM_READ(dma8_cnt_lo_r)
r32760r32761
393393   AM_RANGE(0x001B, 0x001B) AM_MIRROR(0xff00) AM_READ(adc_data_r)
394394   AM_RANGE(0x001D, 0x001D) AM_MIRROR(0xff00) AM_WRITE(dma8_w)
395395   AM_RANGE(0x001F, 0x001F) AM_MIRROR(0xff00) AM_READ(dma8_r)
396//   AM_RANGE(0x0080, 0x0080) // ASP comms
397//   AM_RANGE(0x0081, 0x0081)
398//   AM_RANGE(0x0082, 0x0082)
396//  AM_RANGE(0x0080, 0x0080) // ASP comms
397//  AM_RANGE(0x0081, 0x0081)
398//  AM_RANGE(0x0082, 0x0082)
399399   AM_RANGE(MCS51_PORT_P1, MCS51_PORT_P1) AM_READWRITE(p1_r, p1_w)
400400   AM_RANGE(MCS51_PORT_P2, MCS51_PORT_P2) AM_READWRITE(p2_r, p2_w)
401401ADDRESS_MAP_END
trunk/src/emu/bus/msx_cart/disk.c
r32760r32761
164164
165165
166166msx_cart_fscf351::msx_cart_fscf351(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
167    : msx_cart_disk_type2(mconfig, MSX_CART_FSCF351, "MSX Cartridge - FS-CF351", tag, owner, clock, "msx_cart_fscf351")
167   : msx_cart_disk_type2(mconfig, MSX_CART_FSCF351, "MSX Cartridge - FS-CF351", tag, owner, clock, "msx_cart_fscf351")
168168{
169169}
170170
r32760r32761
624624         break;
625625   }
626626}
627
trunk/src/emu/bus/intv/rom.c
r32760r32761
4747               : intv_rom_device(mconfig, INTV_ROM_WSMLB, "Intellivision World Series Baseball Cart", tag, owner, clock, "intv_wsmlb", __FILE__)
4848{
4949}
50
trunk/src/emu/bus/intv/ecs.h
r32760r32761
1414public:
1515   // construction/destruction
1616   intv_ecs_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
17   
17
1818   // device-level overrides
1919   virtual void device_start();
2020   virtual void device_reset();
2121   virtual machine_config_constructor device_mconfig_additions() const;
2222   virtual ioport_constructor device_input_ports() const;
2323   virtual const rom_entry *device_rom_region() const;
24   
24
2525   // reading and writing
2626
2727   // actual ECS accesses
r32760r32761
3232   virtual DECLARE_READ16_MEMBER(read_romf0);
3333   // RAM
3434   virtual DECLARE_READ16_MEMBER(read_ram) { return (int)m_ram[offset & (m_ram.count() - 1)]; }
35   virtual DECLARE_WRITE16_MEMBER(write_ram) { m_ram[offset & (m_ram.count() - 1)] = data & 0xff; }   
35   virtual DECLARE_WRITE16_MEMBER(write_ram) { m_ram[offset & (m_ram.count() - 1)] = data & 0xff; }
3636   // AY8914
3737   virtual DECLARE_READ16_MEMBER(read_ay);
3838   virtual DECLARE_WRITE16_MEMBER(write_ay);
3939   DECLARE_READ8_MEMBER(ay_porta_r);
4040   DECLARE_READ8_MEMBER(ay_portb_r);
4141   DECLARE_WRITE8_MEMBER(ay_porta_w);
42   
42
4343   // passthru accesses
4444   virtual DECLARE_READ16_MEMBER(read_rom04) { return m_subslot->read_rom04(space, offset, mem_mask); }
4545   virtual DECLARE_READ16_MEMBER(read_rom40) { return m_subslot->read_rom40(space, offset, mem_mask); }
r32760r32761
4747   virtual DECLARE_READ16_MEMBER(read_rom50) { return m_subslot->read_rom50(space, offset, mem_mask); }
4848   virtual DECLARE_READ16_MEMBER(read_rom60) { return m_subslot->read_rom60(space, offset, mem_mask); }
4949   virtual DECLARE_READ16_MEMBER(read_rom80)
50   {
50   {
5151      if (m_ram88_enabled && offset >= 0x800)
52         return m_subslot->read_ram(space, offset & 0x7ff, mem_mask);
52         return m_subslot->read_ram(space, offset & 0x7ff, mem_mask);
5353      else
54         return m_subslot->read_rom80(space, offset, mem_mask);
54         return m_subslot->read_rom80(space, offset, mem_mask);
5555   }
5656   virtual DECLARE_READ16_MEMBER(read_rom90) { return m_subslot->read_rom90(space, offset, mem_mask); }
5757   virtual DECLARE_READ16_MEMBER(read_roma0) { return m_subslot->read_roma0(space, offset, mem_mask); }
5858   virtual DECLARE_READ16_MEMBER(read_romb0) { return m_subslot->read_romb0(space, offset, mem_mask); }
5959   virtual DECLARE_READ16_MEMBER(read_romc0) { return m_subslot->read_romc0(space, offset, mem_mask); }
60   virtual DECLARE_READ16_MEMBER(read_romd0)
61   {
60   virtual DECLARE_READ16_MEMBER(read_romd0)
61   {
6262      if (m_ramd0_enabled && offset < 0x800)
63         return m_subslot->read_ram(space, offset, mem_mask);
63         return m_subslot->read_ram(space, offset, mem_mask);
6464      else
65         return m_subslot->read_romd0(space, offset, mem_mask);
65         return m_subslot->read_romd0(space, offset, mem_mask);
6666   }
6767
6868   // paged ROM banking
69   virtual DECLARE_WRITE16_MEMBER(write_rom20)
70   {
69   virtual DECLARE_WRITE16_MEMBER(write_rom20)
70   {
7171      if (offset == 0xfff)
7272      {
7373         if (data == 0x2a50)
r32760r32761
7676            m_bank_base[2] = 1;
7777      }
7878   }
79   virtual DECLARE_WRITE16_MEMBER(write_rom70)
80   {
79   virtual DECLARE_WRITE16_MEMBER(write_rom70)
80   {
8181      if (offset == 0xfff)
8282      {
8383         if (data == 0x7a50)
r32760r32761
8686            m_bank_base[7] = 1;
8787      }
8888   }
89   virtual DECLARE_WRITE16_MEMBER(write_rome0)
90   {
89   virtual DECLARE_WRITE16_MEMBER(write_rome0)
90   {
9191      if (offset == 0xfff)
9292      {
9393         if (data == 0xea50)
r32760r32761
9696            m_bank_base[14] = 1;
9797      }
9898   }
99   virtual DECLARE_WRITE16_MEMBER(write_romf0)
100   {
99   virtual DECLARE_WRITE16_MEMBER(write_romf0)
100   {
101101      if (offset == 0xfff)
102102      {
103103         if (data == 0xfa50)
r32760r32761
112112   // IntelliVoice passthru
113113   virtual DECLARE_READ16_MEMBER(read_speech) { if (m_voice_enabled) return m_subslot->read_speech(space, offset, mem_mask); else return 0xffff; }
114114   virtual DECLARE_WRITE16_MEMBER(write_speech) { if (m_voice_enabled) m_subslot->write_speech(space, offset, data, mem_mask); }
115   
115
116116   virtual void late_subslot_setup();
117117
118118   UINT8 intv_control_r(int hand);
119   
119
120120private:
121121
122122   required_device<ay8914_device> m_snd;
trunk/src/emu/bus/intv/slot.c
r32760r32761
33    Mattel Intellivision cart emulation
44    (through slot devices)
55
6
6
77    This is a strange beast, because INTV carts had potentially access to
88    a *LOT* of memory ranges!
99    Quoting Joe Zbiciak's documentation for his emu (jzIntv):
10 
11 
10
11
1212      The Intellivision leaves many addresses available to cartridges.  However,
1313      several address ranges come with caveats, such as interactions with other
14      devices in the system, or incompatibilities with various peripherals. 
15 
14      devices in the system, or incompatibilities with various peripherals.
15
1616      Below is a summary.
17
17
1818      ADDRESSES      NOTES
1919      -------------- --------------------------------------------------------------
2020      $0400 - $04FF  RAM/ROM ok on all but Intellivision 2.
r32760r32761
2626      $4800          ROM ok.  RAM ok only if boot ROM at $7000.
2727      $4801 - $4FFF  RAM/ROM ok.
2828      $5000 - $5014  ROM ok.  RAM ok only if boot ROM at $7000 or $4800.
29      $5015 - $6FFF  RAM/ROM ok. 
29      $5015 - $6FFF  RAM/ROM ok.
3030      $7000          ROM ok if no ECS.  RAM at $7000 confuses EXEC boot sequence.
3131      $7001 - $77FF  RAM/ROM ok if no ECS.
3232      $7800 - $7FFF  ROM ok if no ECS.  Do not map RAM here due to GRAM alias.
r32760r32761
3838      $E000 - $EFFF  RAM/ROM ok if no ECS.
3939      $F000 - $F7FF  RAM/ROM ok.
4040      $F800 - $FFFF  ROM ok.  Do not map RAM here due to GRAM alias.
41 
42 
41
42
4343    We handle this, by always creating a 0x10000 wide ROM region to load the
4444    cart image and exposing the following (long list of) read handlers:
4545      read_rom04
r32760r32761
5858      read_rome0
5959      read_romf0
6060    Each pcb types will then use the correct ones for its wiring setup.
61
61
6262    The BIN+CFG format introduced by INTVPC emulator includes metadata about where to
6363    load ROM into memory in the CFG file, but we don't support it (because we don't parse
6464    the CFG at all) and we rely instead on the intv.hsi metadata for fullpath loading of
r32760r32761
6969 TODO:
7070    - Convert also the keyboard component to be a passthru slot device
7171    - Merge some of the ROM accessor above, once it is clear which ones can be merged
72
72
7373 ***********************************************************************************************************/
7474
7575
r32760r32761
239239   UINT8 num_segments;
240240   UINT8 start_seg;
241241   UINT8 end_seg;
242   
242
243243   UINT32 current_address;
244244   UINT32 end_address;
245   
245
246246   UINT8 high_byte;
247247   UINT8 low_byte;
248   
248
249249   UINT8 *ROM;
250250   const char *file_type = filetype();
251   
251
252252   /* if it is in .rom format, we enter here */
253253   if (!core_stricmp (file_type, "rom"))
254254   {
r32760r32761
256256      fread(&temp, 1);
257257      if (temp != 0xa8)
258258         return IMAGE_INIT_FAIL;
259     
259
260260      fread(&num_segments, 1);
261     
261
262262      fread(&temp, 1);
263263      if (temp != (num_segments ^ 0xff))
264264         return IMAGE_INIT_FAIL;
r32760r32761
270270      {
271271         fread(&start_seg, 1);
272272         current_address = start_seg * 0x100;
273         
273
274274         fread(&end_seg, 1);
275275         end_address = end_seg * 0x100 + 0xff;
276         
276
277277         while (current_address <= end_address)
278278         {
279279            fread(&low_byte, 1);
r32760r32761
282282            ROM[current_address << 1] = high_byte;
283283            current_address++;
284284         }
285         
285
286286         // Here we should calculate and compare the CRC16...
287287         fread(&temp, 1);
288288         fread(&temp, 1);
289289      }
290     
290
291291      // Access tables and fine address restriction tables are not supported ATM
292292      for (int i = 0; i < (16 + 32 + 2); i++)
293293      {
r32760r32761
300300   {
301301      // This code is a blatant hack, due to impossibility to load a separate .cfg file in MESS.
302302      // It shall be eventually replaced by the .xml loading
303     
303
304304      // extrainfo format
305305      // 1. mapper number (to deal with bankswitch). no bankswitch is mapper 0 (most games).
306306      // 2.->5. current images have at most 4 chunks of data. we store here block size and location to load
r32760r32761
314314
315315      m_cart->rom_alloc(0x20000, tag());
316316      ROM = (UINT8 *)m_cart->get_rom_base();
317     
317
318318      if (!hashfile_extrainfo(*this, extrainfo))
319319      {
320320         // If no extrainfo, we assume a single 0x2000 chunk at 0x5000
r32760r32761
329329      else
330330      {
331331         sscanf(extrainfo.cstr() ,"%d %d %d %d %d %d %d", &mapper, &rom[0], &rom[1], &rom[2],
332               &rom[3], &ram, &extra);         
332               &rom[3], &ram, &extra);
333333         //printf("extrainfo: %d %d %d %d %d %d %d \n", mapper, rom[0], rom[1], rom[2], rom[3], ram, extra);
334         
334
335335         if (mapper)
336336            logerror("Bankswitch not yet implemented!\n");
337         
337
338338         if (ram)
339339         {
340340            start = ((ram & 0xf0) >> 4) * 0x1000;
r32760r32761
355355         }
356356         if (extra & INTELLIVOICE_MASK)
357357         {
358            printf("WARNING: This game requires emulation of the IntelliVoice module.\n");
358               printf("WARNING: This game requires emulation of the IntelliVoice module.\n");
359359         }
360         
360
361361         if (extra & ECS_MASK)
362362         {
363363            printf("WARNING: This game requires emulation of the ECS module.\n");
364364         }
365         
365
366366         for (int j = 0; j < 4; j++)
367367         {
368368            start = ((rom[j] & 0xf0) >> 4) * 0x1000;
369369            size = (rom[j] & 0x0f) * 0x800;
370370
371            // some cart has to be loaded to 0x4800, but none of the available ones goes to 0x4000.
371            // some cart has to be loaded to 0x4800, but none of the available ones goes to 0x4000.
372372            // Hence, we use 0x04 << 4 in extrainfo (to reduce the stored values) and fix the value here.
373373            if (start == 0x4000) start += 0x800;
374           
374
375375//              logerror("step %d: %d %d \n", j, start / 0x1000, size / 0x1000);
376           
376
377377            for (int i = 0; i < size; i++)
378378            {
379379               fread(&low_byte, 1);
r32760r32761
383383            }
384384         }
385385      }
386     
386
387387      return IMAGE_INIT_PASS;
388388   }
389389}
r32760r32761
408408         // so if we are loading one of these, we allocate additional 0x2000 bytes for the paged bank
409409         if (m_type == INTV_WSMLB)
410410            extra_bank = true;
411         
411
412412         UINT32 size = 0;
413413         UINT16 address = 0;
414414         UINT8 *ROM, *region;
r32760r32761
423423            if (size)
424424            {
425425               region = get_software_region(region_name[i]);
426               
426
427427               for (int j = 0; j < size / 2; j++)
428428               {
429429                  ROM[((address + j) << 1) + 1] = region[2 * j];
r32760r32761
467467      UINT32 len = core_fsize(m_file);
468468      dynamic_buffer rom(len);
469469      int type = INTV_STD;
470     
470
471471      core_fread(m_file, rom, len);
472472
473473      if (rom[0] == 0xa8 && (rom[1] == (rom[2] ^ 0xff)))
r32760r32761
480480         int start;
481481         int mapper, rom[5], ram, extra;
482482         astring extrainfo;
483         
483
484484         if (hashfile_extrainfo(*this, extrainfo))
485485         {
486486            sscanf(extrainfo.cstr() ,"%d %d %d %d %d %d %d", &mapper, &rom[0], &rom[1], &rom[2],
487                  &rom[3], &ram, &extra);         
488           
487                  &rom[3], &ram, &extra);
488
489489            if (ram)
490490            {
491491               start = ((ram & 0xf0) >> 4) * 0x1000;
r32760r32761
495495                  type = INTV_GFACT;
496496            }
497497         }
498           
498
499499      }
500500
501501      slot_string = intv_get_slot(type);
r32760r32761
567567   SLOT_INTERFACE_INTERNAL("intv_wsmlb",   INTV_ROM_WSMLB)
568568   SLOT_INTERFACE_INTERNAL("intv_voice",   INTV_ROM_VOICE)
569569   SLOT_INTERFACE_INTERNAL("intv_ecs",     INTV_ROM_ECS)
570//   SLOT_INTERFACE_INTERNAL("intv_keycomp", INTV_ROM_KEYCOMP)
570//  SLOT_INTERFACE_INTERNAL("intv_keycomp", INTV_ROM_KEYCOMP)
571571SLOT_INTERFACE_END
572
trunk/src/emu/bus/intv/rom.h
r32760r32761
1313   // construction/destruction
1414   intv_rom_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
1515   intv_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
16   
16
1717   // reading and writing
1818   virtual DECLARE_READ16_MEMBER(read_rom04) { return INTV_ROM16_READ(offset + 0x0400); }
1919   virtual DECLARE_READ16_MEMBER(read_rom20) { return INTV_ROM16_READ(offset + 0x2000); }
r32760r32761
3030   virtual DECLARE_READ16_MEMBER(read_romd0) { return INTV_ROM16_READ(offset + 0xd000); }
3131   virtual DECLARE_READ16_MEMBER(read_rome0) { return INTV_ROM16_READ(offset + 0xe000); }
3232   virtual DECLARE_READ16_MEMBER(read_romf0) { return INTV_ROM16_READ(offset + 0xf000); }
33   
33
3434   // device-level overrides
3535   virtual void device_start() {}
3636   virtual void device_reset() {}
r32760r32761
4343public:
4444   // construction/destruction
4545   intv_ram_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
46   
46
4747   // reading and writing
4848   virtual DECLARE_READ16_MEMBER(read_ram) { return (int)m_ram[offset & (m_ram.count() - 1)]; }
4949   virtual DECLARE_WRITE16_MEMBER(write_ram) { m_ram[offset & (m_ram.count() - 1)] = data & 0xff; }
r32760r32761
5656public:
5757   // construction/destruction
5858   intv_gfact_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
59   
59
6060   // reading and writing
6161   virtual DECLARE_READ16_MEMBER(read_ram) { return (int)m_ram[offset & (m_ram.count() - 1)]; }
6262   virtual DECLARE_WRITE16_MEMBER(write_ram) { m_ram[offset & (m_ram.count() - 1)] = data & 0xff; }
trunk/src/emu/bus/intv/slot.h
r32760r32761
1111{
1212   INTV_STD = 0,
1313   INTV_RAM,
14   INTV_GFACT,   // has RAM too but at diff offset
14   INTV_GFACT, // has RAM too but at diff offset
1515   INTV_WSMLB,
1616   INTV_VOICE,
1717   INTV_ECS,
r32760r32761
5151
5252   virtual DECLARE_READ16_MEMBER(read_ram) { return 0xffff; }
5353   virtual DECLARE_WRITE16_MEMBER(write_ram) {}
54   
54
5555   // Used by IntelliVoice & ECS
5656   virtual DECLARE_READ16_MEMBER(read_ay) { return 0xffff; }
5757   virtual DECLARE_WRITE16_MEMBER(write_ay) {}
r32760r32761
7171   UINT32 get_rom_size() { return m_rom_size; }
7272   UINT32 get_ram_size() { return m_ram.count(); }
7373
74   void save_ram()   { device().save_item(NAME(m_ram)); }
74   void save_ram() { device().save_item(NAME(m_ram)); }
7575   virtual void late_subslot_setup() {}
7676
7777protected:
r32760r32761
105105   int get_type() { return m_type; }
106106   int load_fullpath();
107107
108   void save_ram()   { if (m_cart && m_cart->get_ram_size()) m_cart->save_ram(); }
108   void save_ram() { if (m_cart && m_cart->get_ram_size()) m_cart->save_ram(); }
109109
110110   virtual iodevice_t image_type() const { return IO_CARTSLOT; }
111111   virtual bool is_readable()  const { return 1; }
r32760r32761
136136   virtual DECLARE_READ16_MEMBER(read_romd0) { if (m_cart) return m_cart->read_romd0(space, offset, mem_mask); else return 0xffff; }
137137   virtual DECLARE_READ16_MEMBER(read_rome0) { if (m_cart) return m_cart->read_rome0(space, offset, mem_mask); else return 0xffff; }
138138   virtual DECLARE_READ16_MEMBER(read_romf0) { if (m_cart) return m_cart->read_romf0(space, offset, mem_mask); else return 0xffff; }
139   
139
140140   virtual DECLARE_READ16_MEMBER(read_ay);
141141   virtual DECLARE_WRITE16_MEMBER(write_ay);
142142   virtual DECLARE_READ16_MEMBER(read_speech);
r32760r32761
176176
177177#define MCFG_INTV_CARTRIDGE_ADD(_tag,_slot_intf,_def_slot) \
178178   MCFG_DEVICE_ADD(_tag, INTV_CART_SLOT, 0) \
179   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false) \
179   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false)
180180
181
182181SLOT_INTERFACE_EXTERN(intv_cart);
183182
184183#endif
trunk/src/emu/bus/intv/ecs.c
r32760r32761
44 Mattel Intellivision Entertainment Computer System expansion emulation
55
66 TODO:
7   - Make paged rom emulation more accurate (according to
7   - Make paged rom emulation more accurate (according to
88   http://spatula-city.org/~im14u2c/intv/tech/ecs.html
9   writes to $xa5y should be available for every x and every y, i.e. we shall
10   have writes to every 4K chunk of the memory map, and there shall be 16 pages
9   writes to $xa5y should be available for every x and every y, i.e. we shall
10   have writes to every 4K chunk of the memory map, and there shall be 16 pages
1111   for each)
1212   Current emulation is instead tailored around the minimal usage necessary to
1313   make the main expansion and World Series Major League Baseball happy
r32760r32761
6767}
6868
6969void intv_ecs_device::device_reset()
70{   
70{
7171   memset(m_bank_base, 0, sizeof(m_bank_base));
7272}
7373
7474void intv_ecs_device::late_subslot_setup()
75{   
75{
7676   switch (m_subslot->get_type())
7777   {
7878      case INTV_RAM:
r32760r32761
107107      0xFF, 0x3F, 0x9F, 0x5F, 0xD7, 0xB7, 0x77, 0xDB,
108108      0xBB, 0x7B, 0xDD, 0xBD, 0x7D, 0xDE, 0xBE, 0x7E
109109   };
110   
110
111111   static const UINT8 disc_table[] =
112112   {
113113      0xF3, 0xE3, 0xE7, 0xF7, 0xF6, 0xE6, 0xEE, 0xFE,
114114      0xFC, 0xEC, 0xED, 0xFD, 0xF9, 0xE9, 0xEB, 0xFB
115115   };
116   
116
117117   static const UINT8 discyx_table[5][5] =
118118   {
119119      { 0xE3, 0xF3, 0xFB, 0xEB, 0xE9 },
r32760r32761
122122      { 0xF6, 0xE6, 0xFE, 0xEC, 0xED },
123123      { 0xE6, 0xEE, 0xFE, 0xFC, 0xEC }
124124   };
125   
125
126126   int x, y;
127127   UINT8 val = 0xff;
128   
128
129129   /* keypad */
130130   x = m_keypad[hand]->read();
131131   for (y = 0; y < 16; y++)
r32760r32761
135135         val &= keypad_table[y];
136136      }
137137   }
138   
138
139139   switch ((m_options->read() >> hand) & 4)
140140   {
141141      case 0: /* disc == digital */
142142      default:
143         
143
144144         x = m_disc[hand]->read();
145145         for (y = 0; y < 16; y++)
146146         {
r32760r32761
150150            }
151151         }
152152         break;
153         
153
154154      case 1: /* disc == _fake_ analog */
155         
155
156156         x = m_discx[hand]->read();
157157         y = m_discy[hand]->read();
158158         val &= discyx_table[y / 32][x / 32];
159159   }
160   
160
161161   return val;
162162}
163163
r32760r32761
252252 Bit 4  D       E       2       3       W       S       Z       X
253253 Bit 5  A       CTL     (right) 1       Q       (up)    (down)  (space)
254254 Bit 6  SHIFT   NC      NC      NC      NC      NC      NC      NC
255
255
256256 Shifted keys that differ from pc:
257257 Key        : 1 2 5 6 7 (left) (right) (up) (down)
258258 Shift + key: = " + - /  %      '       ^    ?
r32760r32761
530530 Paged ROM handling
531531 -------------------------------------------------*/
532532
533READ16_MEMBER(intv_ecs_device::read_rom20)
534{
533READ16_MEMBER(intv_ecs_device::read_rom20)
534{
535535   if (m_bank_base[2])
536      return INTV_ROM16_READ(offset + 0x2000);
536      return INTV_ROM16_READ(offset + 0x2000);
537537   else
538538      return 0xffff;
539539}
540540
541READ16_MEMBER(intv_ecs_device::read_rom70)
542{
541READ16_MEMBER(intv_ecs_device::read_rom70)
542{
543543   if (m_bank_base[7])
544544      return 0xffff;
545545   else
546      return INTV_ROM16_READ(offset + 0x7000);
546      return INTV_ROM16_READ(offset + 0x7000);
547547}
548548
549READ16_MEMBER(intv_ecs_device::read_rome0)
550{
549READ16_MEMBER(intv_ecs_device::read_rome0)
550{
551551   if (m_bank_base[14])
552      return INTV_ROM16_READ(offset + 0xe000);
553   else   // if WSMLB is loaded, it shall go here, otherwise 0xffff
552      return INTV_ROM16_READ(offset + 0xe000);
553   else    // if WSMLB is loaded, it shall go here, otherwise 0xffff
554554      return m_subslot->read_rome0(space, offset, mem_mask);
555555}
556556
557READ16_MEMBER(intv_ecs_device::read_romf0)
558{
557READ16_MEMBER(intv_ecs_device::read_romf0)
558{
559559   // only WSMLB should come here with bank_base = 1
560560   if (m_bank_base[15])
561561      return m_subslot->read_romf0(space, offset + 0x1000, mem_mask);
r32760r32761
585585   if (ACCESSING_BITS_0_7)
586586      return m_snd->write(space, offset, data, mem_mask);
587587}
588
trunk/src/emu/bus/intv/voice.h
r32760r32761
1313public:
1414   // construction/destruction
1515   intv_voice_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
16     
16
1717   // device-level overrides
1818   virtual void device_start();
1919   virtual machine_config_constructor device_mconfig_additions() const;
r32760r32761
2323   // actual IntelliVoice access
2424   virtual DECLARE_READ16_MEMBER(read_speech);
2525   virtual DECLARE_WRITE16_MEMBER(write_speech);
26   
26
2727   // passthru access
2828   virtual DECLARE_READ16_MEMBER(read_rom04) { return m_subslot->read_rom04(space, offset, mem_mask); }
2929   virtual DECLARE_READ16_MEMBER(read_rom20) { return m_subslot->read_rom20(space, offset, mem_mask); }
r32760r32761
3333   virtual DECLARE_READ16_MEMBER(read_rom60) { return m_subslot->read_rom60(space, offset, mem_mask); }
3434   virtual DECLARE_READ16_MEMBER(read_rom70) { return m_subslot->read_rom70(space, offset, mem_mask); }
3535   virtual DECLARE_READ16_MEMBER(read_rom80)
36   {
36   {
3737      if (m_ram88_enabled && offset >= 0x800)
38         return m_subslot->read_ram(space, offset & 0x7ff, mem_mask);
38         return m_subslot->read_ram(space, offset & 0x7ff, mem_mask);
3939      else
40         return m_subslot->read_rom80(space, offset, mem_mask);
40         return m_subslot->read_rom80(space, offset, mem_mask);
4141   }
4242   virtual DECLARE_READ16_MEMBER(read_rom90) { return m_subslot->read_rom90(space, offset, mem_mask); }
4343   virtual DECLARE_READ16_MEMBER(read_roma0) { return m_subslot->read_roma0(space, offset, mem_mask); }
4444   virtual DECLARE_READ16_MEMBER(read_romb0) { return m_subslot->read_romb0(space, offset, mem_mask); }
4545   virtual DECLARE_READ16_MEMBER(read_romc0) { return m_subslot->read_romc0(space, offset, mem_mask); }
46   virtual DECLARE_READ16_MEMBER(read_romd0)
47   {
46   virtual DECLARE_READ16_MEMBER(read_romd0)
47   {
4848      if (m_ramd0_enabled && offset < 0x800)
49         return m_subslot->read_ram(space, offset, mem_mask);
49         return m_subslot->read_ram(space, offset, mem_mask);
5050      else
51         return m_subslot->read_romd0(space, offset, mem_mask);
51         return m_subslot->read_romd0(space, offset, mem_mask);
5252   }
5353   virtual DECLARE_READ16_MEMBER(read_rome0) { return m_subslot->read_rome0(space, offset, mem_mask); }
5454   virtual DECLARE_READ16_MEMBER(read_romf0) { return m_subslot->read_romf0(space, offset, mem_mask); }
55   
55
5656   // RAM passthru write
5757   virtual DECLARE_WRITE16_MEMBER(write_88) { if (m_ram88_enabled) m_subslot->write_ram(space, offset, data, mem_mask); }
5858   virtual DECLARE_WRITE16_MEMBER(write_d0) { if (m_ramd0_enabled) m_subslot->write_ram(space, offset, data, mem_mask); }
5959   virtual DECLARE_READ16_MEMBER(read_ram) { return m_subslot->read_ram(space, offset, mem_mask); }
6060   virtual DECLARE_WRITE16_MEMBER(write_ram) { m_subslot->write_ram(space, offset, data, mem_mask); }
61   
61
6262   virtual void late_subslot_setup();
63   
63
6464private:
6565   required_device<sp0256_device> m_speech;
6666   required_device<intv_cart_slot_device> m_subslot;
trunk/src/emu/bus/nes/disksys.c
r32760r32761
1111 Famicom Disk System.
1212
1313 Based on info from NESDev wiki ( http://wiki.nesdev.com/w/index.php/Family_Computer_Disk_System )
14
14
1515 TODO:
1616   - convert floppy drive + fds format to modern code!
1717   - add sound bits
r32760r32761
124124
125125   irq_timer = timer_alloc(TIMER_IRQ);
126126   irq_timer->adjust(attotime::zero, 0, machine().device<cpu_device>("maincpu")->cycles_to_attotime(1));
127   
127
128128   save_item(NAME(m_fds_motor_on));
129129   save_item(NAME(m_fds_door_closed));
130130   save_item(NAME(m_fds_current_side));
131131   save_item(NAME(m_fds_head_position));
132132   save_item(NAME(m_fds_status0));
133133   save_item(NAME(m_read_mode));
134   save_item(NAME(m_drive_ready));   
134   save_item(NAME(m_drive_ready));
135135   save_item(NAME(m_irq_enable));
136136   save_item(NAME(m_irq_transfer));
137137   save_item(NAME(m_irq_count));
r32760r32761
173173
174174 RAM is in 0x6000-0xdfff (32K)
175175 ROM is in 0xe000-0xffff (8K)
176 
177 registers + disk drive are accessed in
176
177 registers + disk drive are accessed in
178178 0x4020-0x403f (read_ex/write_ex below)
179179
180180 -------------------------------------------------*/
r32760r32761
210210}
211211
212212void nes_disksys_device::hblank_irq(int scanline, int vblank, int blanked)
213{   
213{
214214   if (m_irq_transfer)
215215      m_maincpu->set_input_line(M6502_IRQ_LINE, HOLD_LINE);
216216}
r32760r32761
218218WRITE8_MEMBER(nes_disksys_device::write_ex)
219219{
220220   LOG_MMC(("Famicom Disk System write_ex, offset: %04x, data: %02x\n", offset, data));
221   
221
222222   if (offset >= 0x20 && offset < 0x60)
223223   {
224224      // wavetable
r32760r32761
255255         // bit4 - CRC control (set during CRC calculation of transfer)
256256         // bit5 - Always set to '1'
257257         // bit6 - Read/Write Start (Set to 1 when the drive becomes ready for read/write)
258         // bit7 - Interrupt Transfer (0: Transfer without using IRQ; 1: Enable IRQ when
258         // bit7 - Interrupt Transfer (0: Transfer without using IRQ; 1: Enable IRQ when
259259         //        the drive becomes ready)
260260         m_fds_motor_on = BIT(data, 0);
261         
261
262262         if (BIT(data, 1))
263263            m_fds_head_position = 0;
264         
264
265265         if (!(data & 0x40) && m_drive_ready && m_fds_head_position > 2)
266266            m_fds_head_position -= 2; // ??? is this some sort of compensation??
267         
267
268268         m_read_mode = BIT(data, 2);
269         set_nt_mirroring(BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);         
269         set_nt_mirroring(BIT(data, 3) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT);
270270         m_drive_ready = data & 0x40;
271271         m_irq_transfer = BIT(data, 7);
272272         break;
273273      case 0x06:
274274         // external connector
275275         break;
276      case 0x60:   // $4080 - Volume envelope - read through $4090
277      case 0x62:   // $4082 - Frequency low
278      case 0x63:   // $4083 - Frequency high
279      case 0x64:   // $4084 - Mod envelope - read through $4092
280      case 0x65:   // $4085 - Mod counter
281      case 0x66:   // $4086 - Mod frequency low
282      case 0x67:   // $4087 - Mod frequency high
283      case 0x68:   // $4088 - Mod table write
284      case 0x69:   // $4089 - Wave write / master volume
285      case 0x6a:   // $408a - Envelope speed
276      case 0x60:  // $4080 - Volume envelope - read through $4090
277      case 0x62:  // $4082 - Frequency low
278      case 0x63:  // $4083 - Frequency high
279      case 0x64:  // $4084 - Mod envelope - read through $4092
280      case 0x65:  // $4085 - Mod counter
281      case 0x66:  // $4086 - Mod frequency low
282      case 0x67:  // $4087 - Mod frequency high
283      case 0x68:  // $4088 - Mod table write
284      case 0x69:  // $4089 - Wave write / master volume
285      case 0x6a:  // $408a - Envelope speed
286286         break;
287287   }
288288}
r32760r32761
299299
300300   switch (offset)
301301   {
302      case 0x10:
302      case 0x10:
303303         // $4030 - disk status 0
304304         // bit0 - Timer Interrupt (1: an IRQ occurred)
305         // bit1 - Byte transfer flag (Set to 1 every time 8 bits have been transfered between
306         //        the RAM adaptor & disk drive through $4024/$4031; Reset to 0 when $4024,
305         // bit1 - Byte transfer flag (Set to 1 every time 8 bits have been transfered between
306         //        the RAM adaptor & disk drive through $4024/$4031; Reset to 0 when $4024,
307307         //        $4031, or $4030 has been serviced)
308308         // bit4 - CRC control (0: CRC passed; 1: CRC error)
309309         // bit6 - End of Head (1 when disk head is on the most inner track)
r32760r32761
312312         // clear the disk IRQ detect flag
313313         m_fds_status0 &= ~0x01;
314314         break;
315      case 0x11:
315      case 0x11:
316316         // $4031 - data latch
317317         // don't read data if disk is unloaded
318318         if (!m_fds_data)
r32760r32761
330330         else
331331            ret = 0;
332332         break;
333      case 0x12:
334         // $4032 - disk status 1:
333      case 0x12:
334         // $4032 - disk status 1:
335335         // bit0 - Disk flag  (0: Disk inserted; 1: Disk not inserted)
336336         // bit1 - Ready flag (0: Disk ready; 1: Disk not ready)
337337         // bit2 - Protect flag (0: Not write protected; 1: Write protected or disk ejected)
r32760r32761
351351         else
352352            ret = (m_fds_current_side == 0) ? 1 : 0; // 0 if a disk is inserted
353353         break;
354      case 0x13:
354      case 0x13:
355355         // $4033 - external connector (bits 0-6) + battery status (bit 7)
356356         ret = 0x80;
357357         break;
358      case 0x70:   // $4090 - Volume gain - write through $4080
359      case 0x72:    // $4092 - Mod gain - read through $4084
358      case 0x70:  // $4090 - Volume gain - write through $4080
359      case 0x72:  // $4092 - Mod gain - read through $4084
360360      default:
361361         ret = 0x00;
362362         break;
363363   }
364   
364
365365   return ret;
366366}
367367
r32760r32761
372372void nes_disksys_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
373373{
374374   if (id == TIMER_IRQ)
375   {     
375   {
376376      if (m_irq_enable && m_irq_count)
377377      {
378378         m_irq_count--;
r32760r32761
381381            m_maincpu->set_input_line(M6502_IRQ_LINE, HOLD_LINE);
382382            m_irq_enable = 0;
383383            m_fds_status0 |= 0x01;
384            m_irq_count_latch = 0;   // used in Kaettekita Mario Bros
384            m_irq_count_latch = 0;  // used in Kaettekita Mario Bros
385385         }
386386      }
387387   }
r32760r32761
399399   if (m_fds_current_side == 0)
400400      popmessage("No disk inserted.");
401401   else
402      popmessage("Disk set to side %d", m_fds_current_side);   
402      popmessage("Disk set to side %d", m_fds_current_side);
403403}
404404
405405
r32760r32761
410410{
411411   int header = 0;
412412   m_fds_sides = 0;
413   
413
414414   if (image.length() % 65500)
415415      header = 0x10;
416   
416
417417   m_fds_sides = (image.length() - header) / 65500;
418   
418
419419   if (!m_fds_data)
420420      m_fds_data = auto_alloc_array(machine(), UINT8, m_fds_sides * 65500);
421   
421
422422   // if there is an header, skip it
423423   image.fseek(header, SEEK_SET);
424424   image.fread(m_fds_data, 65500 * m_fds_sides);
r32760r32761
430430   /* TODO: should write out changes here as well */
431431   m_fds_sides =  0;
432432}
433
trunk/src/emu/bus/nes/nes_slot.c
r32760r32761
161161         printf("Warning! The loaded PRG has size not a multiple of 8KB (0x%X)\n", (UINT32)size);
162162         m_prg_chunks--;
163163      }
164     
164
165165      m_prg_mask = ((m_prg_chunks << 1) - 1);
166     
166
167167//      printf("first mask %x!\n", m_prg_mask);
168168      if ((m_prg_chunks << 1) & m_prg_mask)
169169      {
r32760r32761
172172         // only half a dozen of NES carts have PRG which is not a power of 2
173173         // so we use this bank_map only as an exception
174174//          printf("uneven rom!\n");
175         
175
176176         // 1. redefine mask as (next power of 2)-1
177177         for (; temp; )
178178         {
r32760r32761
182182         m_prg_mask = (1 << mask_bits) - 1;
183183//          printf("new mask %x!\n", m_prg_mask);
184184         mapsize = (1 << mask_bits)/2;
185         
185
186186         // 2. create a bank_map for banks in the range mask/2 -> mask
187187         m_prg_bank_map.resize(mapsize);
188         
188
189189         // 3. fill the bank_map accounting for mirrors
190190         int j;
191191         for (j = mapsize; j < (m_prg_chunks << 1); j++)
192192            m_prg_bank_map[j - mapsize] = j;
193         
193
194194         while (j % mapsize)
195195         {
196196            int k = 0, repeat_banks;
r32760r32761
201201               m_prg_bank_map[(j - mapsize) + l] = m_prg_bank_map[(j - mapsize) + l - repeat_banks];
202202            j += repeat_banks;
203203         }
204         
204
205205         // check bank map!
206206//          for (int i = 0; i < mapsize; i++)
207207//          {
r32760r32761
674674   // main NES CPU here, even if it does not belong to this device.
675675   m_maincpu = machine.device<cpu_device>("maincpu");
676676
677   if (cart_mounted)      // disksys expansion can arrive here without the memory banks!
677   if (cart_mounted)       // disksys expansion can arrive here without the memory banks!
678678   {
679679      // Setup PRG
680680      m_prg_bank_mem[0] = machine.root_device().membank("prg0");
r32760r32761
691691         }
692692      }
693693   }
694   
694
695695   // Setup CHR (VRAM can be present also without PRG rom)
696696   m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM;
697697   chr8(0, m_chr_source);
698   
698
699699   // Setup NT
700700   m_ciram = ciram_ptr;
701701
trunk/src/emu/bus/nes/nes_slot.h
r32760r32761
376376   virtual DECLARE_WRITE8_MEMBER(write_m);
377377   virtual DECLARE_WRITE8_MEMBER(write_h);
378378   virtual DECLARE_WRITE8_MEMBER(write_ex);
379   
379
380380   // hack until disk system is made modern!
381381   virtual void disk_flip_side() { if (m_cart) m_cart->disk_flip_side(); }
382   
382
383383   int get_pcb_id() { return m_pcb_id; };
384384
385385   void pcb_start(UINT8 *ciram_ptr);
trunk/src/emu/bus/pet/cb2snd.c
r32760r32761
6565{
6666   m_dac->write_unsigned8(state ? 0xff : 0x00);
6767}
68
trunk/src/emu/bus/scv/slot.c
r32760r32761
175175         seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
176176         return IMAGE_INIT_FAIL;
177177      }
178     
178
179179      m_cart->rom_alloc(len, tag());
180180      if (has_ram)
181181         m_cart->ram_alloc(get_software_region_length("ram"));
182         
182
183183      ROM = m_cart->get_rom_base();
184184
185185      if (software_entry() == NULL)
r32760r32761
317317   if (m_cart)
318318      m_cart->write_bank(space, offset, data);
319319}
320
trunk/src/emu/bus/scv/rom.h
r32760r32761
7979public:
8080   // construction/destruction
8181   scv_rom64_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
82   
82
8383   // device-level overrides
8484   virtual void device_start();
8585   virtual void device_reset();
86   
86
8787   // reading and writing
8888   virtual DECLARE_READ8_MEMBER(read_cart);
8989   virtual DECLARE_WRITE8_MEMBER(write_bank);
r32760r32761
100100public:
101101   // construction/destruction
102102   scv_rom128_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
103   
103
104104   // device-level overrides
105105   virtual void device_start();
106106   virtual void device_reset();
107   
107
108108   // reading and writing
109109   virtual DECLARE_READ8_MEMBER(read_cart);
110110   virtual DECLARE_WRITE8_MEMBER(write_bank);
111   
111
112112private:
113113   UINT8 m_bank_base;
114114};
r32760r32761
121121public:
122122   // construction/destruction
123123   scv_rom128ram4_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
124   
124
125125   // device-level overrides
126126   virtual void device_start();
127127   virtual void device_reset();
128   
128
129129   // reading and writing
130130   virtual DECLARE_READ8_MEMBER(read_cart);
131131   virtual DECLARE_WRITE8_MEMBER(write_cart);
132132   virtual DECLARE_WRITE8_MEMBER(write_bank);
133   
133
134134private:
135135   UINT8 m_bank_base, m_ram_enabled;
136136};
trunk/src/emu/bus/scv/slot.h
r32760r32761
4242   UINT32 get_rom_size() { return m_rom_size; }
4343   UINT32 get_ram_size() { return m_ram.count(); }
4444
45   void save_ram()   { device().save_item(NAME(m_ram)); }
45   void save_ram() { device().save_item(NAME(m_ram)); }
4646
4747protected:
4848   // internal state
r32760r32761
7575   int get_type() { return m_type; }
7676   int get_cart_type(UINT8 *ROM, UINT32 len);
7777
78   void save_ram()   { if (m_cart && m_cart->get_ram_size()) m_cart->save_ram(); }
78   void save_ram() { if (m_cart && m_cart->get_ram_size()) m_cart->save_ram(); }
7979
8080   virtual iodevice_t image_type() const { return IO_CARTSLOT; }
8181   virtual bool is_readable()  const { return 1; }
r32760r32761
115115
116116#define MCFG_SCV_CARTRIDGE_ADD(_tag,_slot_intf,_def_slot) \
117117   MCFG_DEVICE_ADD(_tag, SCV_CART_SLOT, 0) \
118   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false) \
119
118   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false)
120119#endif
trunk/src/emu/bus/cpc/symbfac2.c
r32760r32761
4747   PORT_BIT(0x00000010, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("PS/2 Mouse forward button") PORT_CODE(MOUSECODE_BUTTON5) PORT_CHANGED_MEMBER(DEVICE_SELF,cpc_symbiface2_device,mouse_change_x,NULL)
4848
4949   // TODO: mouse scroll wheel support
50//   PORT_START("sf2_mouse_scroll")
51//   PORT_BIT(0x1f , 0, IPT_TRACKBALL_Y)
52//   PORT_SENSITIVITY(100)
53//   PORT_KEYDELTA(10)
54//   PORT_PLAYER(1)
50//  PORT_START("sf2_mouse_scroll")
51//  PORT_BIT(0x1f , 0, IPT_TRACKBALL_Y)
52//  PORT_SENSITIVITY(100)
53//  PORT_KEYDELTA(10)
54//  PORT_PLAYER(1)
5555INPUT_PORTS_END
5656
5757
r32760r32761
189189// PS/2 Mouse connector
190190// #FD10 (read only) read mouse status
191191/*
192   Status byte
193   Bit 76543210
194   Use mmDDDDDD
192    Status byte
193    Bit 76543210
194    Use mmDDDDDD
195195
196   m: Mode
197   D: Use-Data
196    m: Mode
197    D: Use-Data
198198
199   If read and...
199    If read and...
200200
201   m = 00 -> no more data available, you can stop reading the status for a while
202   m = 01 -> D = X offset (signed); you will receive positive values, if the user
203                            is moving the mouse to the right
204   m = 10 -> D = Y offset (signed); you will receive positive values, if the user
205                            is moving the mouse upwards
206   m = 11 -> D[bit5] = 0 -> D[bit0]   = left button
207                      D[bit1]   = right button
208                      D[bit2]   = middle button
209                      D[bit3]   = forward button
210                      D[bit4]   = backward button
211           D[bit5] = 1 -> D[bit0-4] = scroll wheel offset (signed)
201    m = 00 -> no more data available, you can stop reading the status for a while
202    m = 01 -> D = X offset (signed); you will receive positive values, if the user
203                                     is moving the mouse to the right
204    m = 10 -> D = Y offset (signed); you will receive positive values, if the user
205                                     is moving the mouse upwards
206    m = 11 -> D[bit5] = 0 -> D[bit0]   = left button
207                             D[bit1]   = right button
208                             D[bit2]   = middle button
209                             D[bit3]   = forward button
210                             D[bit4]   = backward button
211              D[bit5] = 1 -> D[bit0-4] = scroll wheel offset (signed)
212212 */
213213READ8_MEMBER(cpc_symbiface2_device::mouse_r)
214214{
trunk/src/emu/bus/cpc/symbfac2.h
r32760r32761
1414#include "cpcexp.h"
1515
1616class cpc_symbiface2_device  : public device_t,
17                        public device_cpc_expansion_card_interface
17                        public device_cpc_expansion_card_interface
1818{
1919public:
2020   // construction/destruction
trunk/src/emu/bus/cpc/amdrum.h
r32760r32761
1818#include "sound/dac.h"
1919
2020class cpc_amdrum_device  : public device_t,
21                     public device_cpc_expansion_card_interface
21                     public device_cpc_expansion_card_interface
2222{
2323public:
2424   // construction/destruction
trunk/src/emu/bus/apf/slot.c
r32760r32761
169169         seterror(IMAGE_ERROR_UNSPECIFIED, "Image extends beyond the expected size for an APF cart");
170170         return IMAGE_INIT_FAIL;
171171      }
172     
172
173173      m_cart->rom_alloc(size, tag());
174         
174
175175      if (software_entry() == NULL)
176176         fread(m_cart->get_rom_base(), size);
177177      else
r32760r32761
294294   if (m_cart)
295295      m_cart->write_ram(space, offset, data);
296296}
297
298
trunk/src/emu/bus/apf/rom.h
r32760r32761
4343public:
4444   // construction/destruction
4545   apf_spacedst_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
46   
46
4747   // reading and writing
4848   virtual DECLARE_READ8_MEMBER(read_ram);
4949   virtual DECLARE_WRITE8_MEMBER(write_ram);
trunk/src/emu/bus/apf/slot.h
r32760r32761
3939   UINT32 get_rom_size() { return m_rom_size; }
4040   UINT32 get_ram_size() { return m_ram.count(); }
4141
42   void save_ram()   { device().save_item(NAME(m_ram)); }
42   void save_ram() { device().save_item(NAME(m_ram)); }
4343
4444protected:
4545   // internal state
r32760r32761
7171
7272   int get_type() { return m_type; }
7373
74   void save_ram()   { if (m_cart && m_cart->get_ram_size()) m_cart->save_ram(); }
74   void save_ram() { if (m_cart && m_cart->get_ram_size()) m_cart->save_ram(); }
7575
7676   virtual iodevice_t image_type() const { return IO_CARTSLOT; }
7777   virtual bool is_readable()  const { return 1; }
r32760r32761
112112
113113#define MCFG_APF_CARTRIDGE_ADD(_tag,_slot_intf,_def_slot) \
114114   MCFG_DEVICE_ADD(_tag, APF_CART_SLOT, 0) \
115   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false) \
116
115   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, false)
117116#endif
trunk/src/emu/bus/rs232/xvd701.c
r32760r32761
9393{
9494   if (m_response_index < sizeof(m_response) && is_transmit_register_empty())
9595   {
96//      printf("sending %02x\n", m_response[m_response_index]);
96//      printf("sending %02x\n", m_response[m_response_index]);
9797      transmit_register_setup(m_response[m_response_index++]);
9898   }
9999}
r32760r32761
115115      // printf("xvd701");
116116
117117      //for (int i = 0; i < sizeof(m_command); i++)
118      //   printf(" %02x", m_command[i]);
118      //  printf(" %02x", m_command[i]);
119119
120120      //printf("\n");
121121
trunk/src/emu/ui/ui.c
r32760r32761
15541554         machine.pause();
15551555      return machine.ui().set_handler(ui_gfx_ui_handler, is_paused);
15561556   }
1557   
1557
15581558   // handle a tape control key
15591559   if (ui_input_pressed(machine, IPT_UI_TAPE_START))
15601560   {
r32760r32761
15741574         return 0;
15751575      }
15761576   }
1577   
1577
15781578   // handle a save state request
15791579   if (ui_input_pressed(machine, IPT_UI_SAVE_STATE))
15801580   {
trunk/src/emu/ui/swlist.c
r32760r32761
6868      entry2->part = 0;
6969      item_append("[file manager]", 0, 0, entry2);
7070
71     
71
7272      software_part_menu_entry *entry3 = (software_part_menu_entry *) m_pool_alloc(sizeof(*entry3));
7373      entry3->type = T_SWLIST;
7474      entry3->part = 0;
trunk/src/emu/imagedev/floppy.c
r32760r32761
885885   input_filename = filename;
886886   input_format = static_cast<floppy_image_device *>(image)->identify(filename);
887887
888   if (!input_format)
888   if (!input_format)
889889   {
890890      popmessage("Error: %s\n", image->error());
891891      ui_menu::stack_pop(machine());
trunk/src/emu/devcpu.c
r32760r32761
3838cpu_device::~cpu_device()
3939{
4040}
41
trunk/src/emu/webengine.c
r32760r32761
133133}
134134
135135void reg_string(struct lua_State *L, const char *name, const char *val) {
136  lua_pushstring(L, name);
137  lua_pushstring(L, val);
138  lua_rawset(L, -3);
136   lua_pushstring(L, name);
137   lua_pushstring(L, val);
138   lua_rawset(L, -3);
139139}
140140
141141void reg_int(struct lua_State *L, const char *name, int val) {
142  lua_pushstring(L, name);
143  lua_pushinteger(L, val);
144  lua_rawset(L, -3);
142   lua_pushstring(L, name);
143   lua_pushinteger(L, val);
144   lua_rawset(L, -3);
145145}
146146
147147void reg_function(struct lua_State *L, const char *name,
148                         lua_CFunction func, struct mg_connection *conn) {
149  lua_pushstring(L, name);
150  lua_pushlightuserdata(L, conn);
151  lua_pushcclosure(L, func, 1);
152  lua_rawset(L, -3);
148                     lua_CFunction func, struct mg_connection *conn) {
149   lua_pushstring(L, name);
150   lua_pushlightuserdata(L, conn);
151   lua_pushcclosure(L, func, 1);
152   lua_rawset(L, -3);
153153}
154154
155155static int lua_write(lua_State *L) {
156  int i, num_args;
157  const char *str;
158  size_t size;
159  struct mg_connection *conn = (struct mg_connection *)
160    lua_touserdata(L, lua_upvalueindex(1));
156   int i, num_args;
157   const char *str;
158   size_t size;
159   struct mg_connection *conn = (struct mg_connection *)
160   lua_touserdata(L, lua_upvalueindex(1));
161161
162  num_args = lua_gettop(L);
163  for (i = 1; i <= num_args; i++) {
164    if (lua_isstring(L, i)) {
165      str = lua_tolstring(L, i, &size);
166      mg_send_data(conn, str, size);
167    }
168  }
162   num_args = lua_gettop(L);
163   for (i = 1; i <= num_args; i++) {
164   if (lua_isstring(L, i)) {
165      str = lua_tolstring(L, i, &size);
166      mg_send_data(conn, str, size);
167   }
168   }
169169
170  return 0;
170   return 0;
171171}
172172
173173static int lua_header(lua_State *L) {
174  struct mg_connection *conn = (struct mg_connection *)
175    lua_touserdata(L, lua_upvalueindex(1));
174   struct mg_connection *conn = (struct mg_connection *)
175   lua_touserdata(L, lua_upvalueindex(1));
176176
177  const char *header = luaL_checkstring(L,1);
178  const char *value  = luaL_checkstring(L,2);
179 
180  mg_send_header(conn, header, value);
177   const char *header = luaL_checkstring(L,1);
178   const char *value  = luaL_checkstring(L,2);
181179
182  return 0;
180   mg_send_header(conn, header, value);
181
182   return 0;
183183}
184184
185185
186186static void prepare_lua_environment(struct mg_connection *ri, lua_State *L) {
187  extern void luaL_openlibs(lua_State *);
188  int i;
187   extern void luaL_openlibs(lua_State *);
188   int i;
189189
190  luaL_openlibs(L);
190   luaL_openlibs(L);
191191
192  if (ri == NULL) return;
192   if (ri == NULL) return;
193193
194  // Register mg module
195  lua_newtable(L);
196  reg_function(L, "write", lua_write, ri);
197  reg_function(L, "header", lua_header, ri);
194   // Register mg module
195   lua_newtable(L);
196   reg_function(L, "write", lua_write, ri);
197   reg_function(L, "header", lua_header, ri);
198198
199  // Export request_info
200  lua_pushstring(L, "request_info");
201  lua_newtable(L);
202  reg_string(L, "request_method", ri->request_method);
203  reg_string(L, "uri", ri->uri);
204  reg_string(L, "http_version", ri->http_version);
205  reg_string(L, "query_string", ri->query_string);
206  reg_string(L, "remote_ip", ri->remote_ip);
207  reg_int(L, "remote_port", ri->remote_port);
208  reg_string(L, "local_ip", ri->local_ip);
209  reg_int(L, "local_port", ri->local_port);
210  lua_pushstring(L, "content");
211  lua_pushlstring(L, ri->content == NULL ? "" : ri->content, ri->content_len);
212  lua_rawset(L, -3);
213  reg_int(L, "num_headers", ri->num_headers);
214  lua_pushstring(L, "http_headers");
215  lua_newtable(L);
216  for (i = 0; i < ri->num_headers; i++) {
217    reg_string(L, ri->http_headers[i].name, ri->http_headers[i].value);
218  }
219  lua_rawset(L, -3);
220  lua_rawset(L, -3);
199   // Export request_info
200   lua_pushstring(L, "request_info");
201   lua_newtable(L);
202   reg_string(L, "request_method", ri->request_method);
203   reg_string(L, "uri", ri->uri);
204   reg_string(L, "http_version", ri->http_version);
205   reg_string(L, "query_string", ri->query_string);
206   reg_string(L, "remote_ip", ri->remote_ip);
207   reg_int(L, "remote_port", ri->remote_port);
208   reg_string(L, "local_ip", ri->local_ip);
209   reg_int(L, "local_port", ri->local_port);
210   lua_pushstring(L, "content");
211   lua_pushlstring(L, ri->content == NULL ? "" : ri->content, ri->content_len);
212   lua_rawset(L, -3);
213   reg_int(L, "num_headers", ri->num_headers);
214   lua_pushstring(L, "http_headers");
215   lua_newtable(L);
216   for (i = 0; i < ri->num_headers; i++) {
217   reg_string(L, ri->http_headers[i].name, ri->http_headers[i].value);
218   }
219   lua_rawset(L, -3);
220   lua_rawset(L, -3);
221221
222  lua_setglobal(L, "mg");
222   lua_setglobal(L, "mg");
223223
224224}
225225
226226
227227static void lsp(struct mg_connection *conn, const char *p, int len, lua_State *L) {
228  int i, j, pos = 0;
229  for (i = 0; i < len; i++) {
230    if (p[i] == '<' && p[i + 1] == '?') {
231      for (j = i + 1; j < len ; j++) {
232        if (p[j] == '?' && p[j + 1] == '>') {     
233        if (i-pos!=0) mg_send_data(conn, p + pos, i - pos);       
234          if (luaL_loadbuffer(L, p + (i + 2), j - (i + 2), "") == 0) {
235            lua_pcall(L, 0, LUA_MULTRET, 0);
236          }
237          pos = j + 2;
238          i = pos - 1;
239          break;
240        }
241      }
242    }
243  }
244  if (i > pos) {
228   int i, j, pos = 0;
229   for (i = 0; i < len; i++) {
230   if (p[i] == '<' && p[i + 1] == '?') {
231      for (j = i + 1; j < len ; j++) {
232      if (p[j] == '?' && p[j + 1] == '>') {
233         if (i-pos!=0) mg_send_data(conn, p + pos, i - pos);
234         if (luaL_loadbuffer(L, p + (i + 2), j - (i + 2), "") == 0) {
235         lua_pcall(L, 0, LUA_MULTRET, 0);
236         }
237         pos = j + 2;
238         i = pos - 1;
239         break;
240      }
241      }
242   }
243   }
244   if (i > pos) {
245245   mg_send_data(conn, p + pos, i - pos);
246 }
246   }
247247}
248248
249249static int filename_endswith(const char *str, const char *suffix)
250250{
251    if (!str || !suffix)
252        return 0;
253    size_t lenstr = strlen(str);
254    size_t lensuffix = strlen(suffix);
255    if (lensuffix >  lenstr)
256        return 0;
257    return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
251   if (!str || !suffix)
252      return 0;
253   size_t lenstr = strlen(str);
254   size_t lensuffix = strlen(suffix);
255   if (lensuffix >  lenstr)
256      return 0;
257   return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
258258}
259259
260260// This function will be called by mongoose on every new request.
r32760r32761
263263   astring file_path(mg_get_option(m_server, "document_root"), PATH_SEPARATOR, conn->uri);
264264   if (filename_endswith(file_path,".lp"))
265265   {
266     FILE *fp = NULL;
267     if ((fp = fopen(file_path, "rb")) != NULL) {
268      fseek (fp, 0, SEEK_END);   
266      FILE *fp = NULL;
267      if ((fp = fopen(file_path, "rb")) != NULL) {
268      fseek (fp, 0, SEEK_END);
269269      size_t size = ftell(fp);
270      fseek (fp, 0, SEEK_SET);   
270      fseek (fp, 0, SEEK_SET);
271271      char *data = (char*)mg_mmap(fp,size);
272272
273273      lua_State *L = luaL_newstate();
274       prepare_lua_environment(conn, L);
274      prepare_lua_environment(conn, L);
275275      lsp(conn, data, (int) size, L);
276276      if (L != NULL) lua_close(L);
277277      mg_munmap(data,size);
278      fclose(fp);     
279      return MG_TRUE;   
280      } else {
281        return MG_FALSE;     
282     }
283   }
278      fclose(fp);
279      return MG_TRUE;
280      } else {
281      return MG_FALSE;
282      }
283   }
284284   else if (!strncmp(conn->uri, "/json/",6))
285285   {
286286      if (!strcmp(conn->uri, "/json/game"))
r32760r32761
295295   else if (!strncmp(conn->uri, "/keypost",8))
296296   {
297297      // Is there any sane way to determine the length of the buffer before getting it?
298      // A request for a way was previously filed with the mongoose devs,
298      // A request for a way was previously filed with the mongoose devs,
299299      // but it looks like it was never implemented.
300     
301      // For now, we'll allow a paste buffer of 32k.
300
301      // For now, we'll allow a paste buffer of 32k.
302302      // To-do: Send an error if the paste is too big?
303303      char cmd_val[32768];
304               
304
305305      int pastelength = mg_get_var(conn, "val", cmd_val, sizeof(cmd_val));
306306      if (pastelength > 0) {
307307         machine().ioport().natkeyboard().post_utf8(cmd_val);
r32760r32761
326326      while ((ofs = mg_parse_multipart(conn->content + ofs, conn->content_len - ofs, var_name, sizeof(var_name), file_name, sizeof(file_name), (const char **)&upload_data, &data_length)) > 0) {
327327            mg_printf_data(conn, "File: %s, size: %d bytes", file_name, data_length);
328328      }
329     
329
330330      // That upload_data contains more than we need. It also has the headers.
331331      // We'll need to strip it down to just what we want.
332     
332
333333      if ((&data_length > 0) && (sizeof(file_name) > 0))
334334      {
335335         // MSVC doesn't yet support variable-length arrays, so chop the string the old-fashioned way
trunk/src/emu/machine/mb8421.c
r32760r32761
44
55    Fujitsu MB8421/22/31/32-90/-90L/-90LL/-12/-12L/-12LL
66    CMOS 16K-bit (2KB) dual-port SRAM
7   
7
88    MB84x2 lacks interrupt pins, it's basically as simple as AM_RAM AM_SHARE("x")
99    MB843x is same as MB842x, except that it supports slave mode. It makes
1010    sure there are no clashes, with the _BUSY pin.
r32760r32761
7070
7171   if (offset == 0x7fe && !space.debugger_access())
7272      m_intl_handler(0);
73   
73
7474   return m_ram[offset];
7575}
7676
r32760r32761
8989
9090   if (offset == 0x7ff && !space.debugger_access())
9191      m_intr_handler(0);
92   
92
9393   return m_ram[offset];
9494}
trunk/src/emu/machine/rp5h01.c
r32760r32761
77    with a mask of %1010111. For example if the 8 dummy bits are $7c,
88    bits 64 to 127 are read as $7c $7c $00 $00 $7c $7c $00 $00.
99    To simplify this, our emulation expects 'overdumps', 128bits total.
10   
10
1111    TODO:
1212    - not sure if the polarity of our PROM dumps (playch10) is correct,
1313      same goes for the bit order (note: does not require new dumps)
trunk/src/emu/machine/smpc.c
r32760r32761
172172         memcpy(memregion("abus")->base(), m_cart_reg[gameno]->base(), 0x3000000);
173173      else
174174         memset(memregion("abus")->base(), 0x00, 0x3000000);
175     
175
176176      m_prev_bankswitch = gameno;
177177   }
178178}
trunk/src/emu/machine/wozfdc.c
r32760r32761
8080   save_item(NAME(cur_lss.data_reg));
8181   save_item(NAME(cur_lss.address));
8282   save_item(NAME(cur_lss.write_start_time));
83//   save_item(NAME(cur_lss.write_buffer));
83//  save_item(NAME(cur_lss.write_buffer));
8484   save_item(NAME(cur_lss.write_position));
8585   save_item(NAME(cur_lss.write_line_active));
8686   save_item(NAME(predicted_lss.tm));
r32760r32761
8888   save_item(NAME(predicted_lss.data_reg));
8989   save_item(NAME(predicted_lss.address));
9090   save_item(NAME(predicted_lss.write_start_time));
91//   save_item(NAME(predicted_lss.write_buffer));
91//  save_item(NAME(predicted_lss.write_buffer));
9292   save_item(NAME(predicted_lss.write_position));
9393   save_item(NAME(predicted_lss.write_line_active));
9494   save_item(NAME(drvsel));
r32760r32761
582582
583583   if (offset < 8)
584584   {
585      a3_update_drive_sel();
585      a3_update_drive_sel();
586586   }
587587}
trunk/src/emu/machine/pit8253.c
r32760r32761
103103   for (int timerno = 0; timerno < PIT8253_MAX_TIMER; timerno++)
104104   {
105105      pit8253_timer *timer = get_timer(timerno);
106     
106
107107      /* initialize timer */
108108      timer->updatetimer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(pit8253_device::update_timer_cb),this));
109109      timer->updatetimer->adjust(attotime::never, timerno);
trunk/src/lib/formats/mfi_dsk.c
r32760r32761
9999
100100   io_generic_read(io, &h, 0, sizeof(header));
101101   if(memcmp( h.sign, sign, 16 ) == 0 &&
102      (h.cyl_count & CYLINDER_MASK) <= 84 &&
103      (h.cyl_count >> RESOLUTION_SHIFT) < 3 &&
102      (h.cyl_count & CYLINDER_MASK) <= 84 &&
103      (h.cyl_count >> RESOLUTION_SHIFT) < 3 &&
104104      h.head_count <= 2 &&
105105      (!form_factor || !h.form_factor || h.form_factor == form_factor))
106106      return 100;
trunk/src/lib/formats/dmk_dsk.c
r32760r32761
226226
227227
228228const floppy_format_type FLOPPY_DMK_FORMAT = &floppy_image_format_creator<dmk_format>;
229
trunk/src/lib/formats/dmk_dsk.h
r32760r32761
3131extern const floppy_format_type FLOPPY_DMK_FORMAT;
3232
3333#endif /* DMK_DSK_H */
34
trunk/src/lib/formats/ap2_dsk.c
r32760r32761
624624         if (!memcmp("PRODOS", &sector_data[0x103], 6))
625625         {
626626            m_prodos_order = true;
627         }   // check for alternate version ProDOS boot block
627         }   // check for alternate version ProDOS boot block
628628         if (!memcmp("PRODOS", &sector_data[0x121], 6))
629629         {
630630            m_prodos_order = true;
r32760r32761
654654         else if (!memcmp(dos33_block1, &sector_data[0x100], 4))
655655         {
656656            m_prodos_order = true;
657         }   // check for a later version of the Pascal boot block
657         }   // check for a later version of the Pascal boot block
658658         else if (!memcmp(pascal2_block1, &sector_data[0x100], 4))
659659         {
660660            m_prodos_order = true;
trunk/src/lib/web/mongoose.c
r32760r32761
128128
129129#ifdef NS_ENABLE_DEBUG
130130#define DBG(x) do { printf("%-20s ", __func__); printf x; putchar('\n'); \
131  fflush(stdout); } while(0)
131   fflush(stdout); } while(0)
132132#else
133133#define DBG(x)
134134#endif
r32760r32761
150150#endif // __cplusplus
151151
152152union socket_address {
153  struct sockaddr sa;
154  struct sockaddr_in sin;
153   struct sockaddr sa;
154   struct sockaddr_in sin;
155155#ifdef NS_ENABLE_IPV6
156  struct sockaddr_in6 sin6;
156   struct sockaddr_in6 sin6;
157157#else
158  struct sockaddr sin6;
158   struct sockaddr sin6;
159159#endif
160160};
161161
162162// IO buffers interface
163163struct iobuf {
164  char *buf;
165  size_t len;
166  size_t size;
164   char *buf;
165   size_t len;
166   size_t size;
167167};
168168
169169void iobuf_init(struct iobuf *, size_t initial_size);
r32760r32761
174174// Net skeleton interface
175175// Events. Meaning of event parameter (evp) is given in the comment.
176176enum ns_event {
177  NS_POLL,     // Sent to each connection on each call to ns_server_poll()
178  NS_ACCEPT,   // New connection accept()-ed. union socket_address *remote_addr
179  NS_CONNECT,  // connect() succeeded or failed. int *success_status
180  NS_RECV,     // Data has benn received. int *num_bytes
181  NS_SEND,     // Data has been written to a socket. int *num_bytes
182  NS_CLOSE     // Connection is closed. NULL
177   NS_POLL,     // Sent to each connection on each call to ns_server_poll()
178   NS_ACCEPT,   // New connection accept()-ed. union socket_address *remote_addr
179   NS_CONNECT,  // connect() succeeded or failed. int *success_status
180   NS_RECV,     // Data has benn received. int *num_bytes
181   NS_SEND,     // Data has been written to a socket. int *num_bytes
182   NS_CLOSE     // Connection is closed. NULL
183183};
184184
185185// Callback function (event handler) prototype, must be defined by user.
r32760r32761
188188typedef void (*ns_callback_t)(struct ns_connection *, enum ns_event, void *evp);
189189
190190struct ns_server {
191  void *server_data;
192  sock_t listening_sock;
193  struct ns_connection *active_connections;
194  ns_callback_t callback;
195  SSL_CTX *ssl_ctx;
196  SSL_CTX *client_ssl_ctx;
197  const char *hexdump_file;
198  sock_t ctl[2];
191   void *server_data;
192   sock_t listening_sock;
193   struct ns_connection *active_connections;
194   ns_callback_t callback;
195   SSL_CTX *ssl_ctx;
196   SSL_CTX *client_ssl_ctx;
197   const char *hexdump_file;
198   sock_t ctl[2];
199199};
200200
201201struct ns_connection {
202  struct ns_connection *prev, *next;
203  struct ns_server *server;
204  sock_t sock;
205  union socket_address sa;
206  struct iobuf recv_iobuf;
207  struct iobuf send_iobuf;
208  SSL *ssl;
209  void *connection_data;
210  time_t last_io_time;
211  unsigned int flags;
202   struct ns_connection *prev, *next;
203   struct ns_server *server;
204   sock_t sock;
205   union socket_address sa;
206   struct iobuf recv_iobuf;
207   struct iobuf send_iobuf;
208   SSL *ssl;
209   void *connection_data;
210   time_t last_io_time;
211   unsigned int flags;
212212#define NSF_FINISHED_SENDING_DATA   (1 << 0)
213213#define NSF_BUFFER_BUT_DONT_SEND    (1 << 1)
214214#define NSF_SSL_HANDSHAKE_DONE      (1 << 2)
r32760r32761
239239int ns_set_ssl_cert(struct ns_server *, const char *ssl_cert);
240240int ns_set_ssl_ca_cert(struct ns_server *, const char *ssl_ca_cert);
241241struct ns_connection *ns_connect(struct ns_server *, const char *host,
242                                 int port, int ssl, void *connection_param);
242                           int port, int ssl, void *connection_param);
243243
244244int ns_send(struct ns_connection *, const void *buf, int len);
245245int ns_printf(struct ns_connection *, const char *fmt, ...);
r32760r32761
289289#endif
290290
291291struct ctl_msg {
292  ns_callback_t callback;
293  char message[1024 * 8];
292   ns_callback_t callback;
293   char message[1024 * 8];
294294};
295295
296296void iobuf_init(struct iobuf *iobuf, size_t size) {
297  iobuf->len = iobuf->size = 0;
298  iobuf->buf = NULL;
297   iobuf->len = iobuf->size = 0;
298   iobuf->buf = NULL;
299299
300  if (size > 0 && (iobuf->buf = (char *) NS_MALLOC(size)) != NULL) {
301    iobuf->size = size;
302  }
300   if (size > 0 && (iobuf->buf = (char *) NS_MALLOC(size)) != NULL) {
301   iobuf->size = size;
302   }
303303}
304304
305305void iobuf_free(struct iobuf *iobuf) {
306  if (iobuf != NULL) {
307    if (iobuf->buf != NULL) NS_FREE(iobuf->buf);
308    iobuf_init(iobuf, 0);
309  }
306   if (iobuf != NULL) {
307   if (iobuf->buf != NULL) NS_FREE(iobuf->buf);
308   iobuf_init(iobuf, 0);
309   }
310310}
311311
312312size_t iobuf_append(struct iobuf *io, const void *buf, size_t len) {
313  char *p = NULL;
313   char *p = NULL;
314314
315  assert(io != NULL);
316  assert(io->len <= io->size);
315   assert(io != NULL);
316   assert(io->len <= io->size);
317317
318  if (len <= 0) {
319  } else if (io->len + len <= io->size) {
320    memcpy(io->buf + io->len, buf, len);
321    io->len += len;
322  } else if ((p = (char *) NS_REALLOC(io->buf, io->len + len)) != NULL) {
323    io->buf = p;
324    memcpy(io->buf + io->len, buf, len);
325    io->len += len;
326    io->size = io->len;
327  } else {
328    len = 0;
329  }
318   if (len <= 0) {
319   } else if (io->len + len <= io->size) {
320   memcpy(io->buf + io->len, buf, len);
321   io->len += len;
322   } else if ((p = (char *) NS_REALLOC(io->buf, io->len + len)) != NULL) {
323   io->buf = p;
324   memcpy(io->buf + io->len, buf, len);
325   io->len += len;
326   io->size = io->len;
327   } else {
328   len = 0;
329   }
330330
331  return len;
331   return len;
332332}
333333
334334void iobuf_remove(struct iobuf *io, size_t n) {
335  if (n > 0 && n <= io->len) {
336    memmove(io->buf, io->buf + n, io->len - n);
337    io->len -= n;
338  }
335   if (n > 0 && n <= io->len) {
336   memmove(io->buf, io->buf + n, io->len - n);
337   io->len -= n;
338   }
339339}
340340
341341#ifndef NS_DISABLE_THREADS
342342void *ns_start_thread(void *(*f)(void *), void *p) {
343343#ifdef _WIN32
344  return (void *) _beginthread((void (__cdecl *)(void *)) f, 0, p);
344   return (void *) _beginthread((void (__cdecl *)(void *)) f, 0, p);
345345#else
346  pthread_t thread_id = (pthread_t) 0;
347  pthread_attr_t attr;
346   pthread_t thread_id = (pthread_t) 0;
347   pthread_attr_t attr;
348348
349  (void) pthread_attr_init(&attr);
350  (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
349   (void) pthread_attr_init(&attr);
350   (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
351351
352352#if defined(NS_STACK_SIZE) && NS_STACK_SIZE > 1
353  (void) pthread_attr_setstacksize(&attr, NS_STACK_SIZE);
353   (void) pthread_attr_setstacksize(&attr, NS_STACK_SIZE);
354354#endif
355355
356  pthread_create(&thread_id, &attr, f, p);
357  pthread_attr_destroy(&attr);
356   pthread_create(&thread_id, &attr, f, p);
357   pthread_attr_destroy(&attr);
358358
359  return (void *) thread_id;
359   return (void *) thread_id;
360360#endif
361361}
362362#endif  // NS_DISABLE_THREADS
363363
364364static void ns_add_conn(struct ns_server *server, struct ns_connection *c) {
365  c->next = server->active_connections;
366  server->active_connections = c;
367  c->prev = NULL;
368  if (c->next != NULL) c->next->prev = c;
365   c->next = server->active_connections;
366   server->active_connections = c;
367   c->prev = NULL;
368   if (c->next != NULL) c->next->prev = c;
369369}
370370
371371static void ns_remove_conn(struct ns_connection *conn) {
372  if (conn->prev == NULL) conn->server->active_connections = conn->next;
373  if (conn->prev) conn->prev->next = conn->next;
374  if (conn->next) conn->next->prev = conn->prev;
372   if (conn->prev == NULL) conn->server->active_connections = conn->next;
373   if (conn->prev) conn->prev->next = conn->next;
374   if (conn->next) conn->next->prev = conn->prev;
375375}
376376
377377// Print message to buffer. If buffer is large enough to hold the message,
378378// return buffer. If buffer is to small, allocate large enough buffer on heap,
379379// and return allocated buffer.
380380int ns_avprintf(char **buf, size_t size, const char *fmt, va_list ap) {
381  va_list ap_copy;
382  int len;
381   va_list ap_copy;
382   int len;
383383
384  va_copy(ap_copy, ap);
385  len = vsnprintf(*buf, size, fmt, ap_copy);
386  va_end(ap_copy);
384   va_copy(ap_copy, ap);
385   len = vsnprintf(*buf, size, fmt, ap_copy);
386   va_end(ap_copy);
387387
388  if (len < 0) {
389    // eCos and Windows are not standard-compliant and return -1 when
390    // the buffer is too small. Keep allocating larger buffers until we
391    // succeed or out of memory.
392    *buf = NULL;
393    while (len < 0) {
394      if (*buf) free(*buf);
395      size *= 2;
396      if ((*buf = (char *) NS_MALLOC(size)) == NULL) break;
397      va_copy(ap_copy, ap);
398      len = vsnprintf(*buf, size, fmt, ap_copy);
399      va_end(ap_copy);
400    }
401  } else if (len > (int) size) {
402    // Standard-compliant code path. Allocate a buffer that is large enough.
403    if ((*buf = (char *) NS_MALLOC(len + 1)) == NULL) {
404      len = -1;
405    } else {
406      va_copy(ap_copy, ap);
407      len = vsnprintf(*buf, len + 1, fmt, ap_copy);
408      va_end(ap_copy);
409    }
410  }
388   if (len < 0) {
389   // eCos and Windows are not standard-compliant and return -1 when
390   // the buffer is too small. Keep allocating larger buffers until we
391   // succeed or out of memory.
392   *buf = NULL;
393   while (len < 0) {
394      if (*buf) free(*buf);
395      size *= 2;
396      if ((*buf = (char *) NS_MALLOC(size)) == NULL) break;
397      va_copy(ap_copy, ap);
398      len = vsnprintf(*buf, size, fmt, ap_copy);
399      va_end(ap_copy);
400   }
401   } else if (len > (int) size) {
402   // Standard-compliant code path. Allocate a buffer that is large enough.
403   if ((*buf = (char *) NS_MALLOC(len + 1)) == NULL) {
404      len = -1;
405   } else {
406      va_copy(ap_copy, ap);
407      len = vsnprintf(*buf, len + 1, fmt, ap_copy);
408      va_end(ap_copy);
409   }
410   }
411411
412  return len;
412   return len;
413413}
414414
415415int ns_vprintf(struct ns_connection *conn, const char *fmt, va_list ap) {
416  char mem[2000], *buf = mem;
417  int len;
416   char mem[2000], *buf = mem;
417   int len;
418418
419  if ((len = ns_avprintf(&buf, sizeof(mem), fmt, ap)) > 0) {
420    iobuf_append(&conn->send_iobuf, buf, len);
421  }
422  if (buf != mem && buf != NULL) {
423    free(buf);
424  }
419   if ((len = ns_avprintf(&buf, sizeof(mem), fmt, ap)) > 0) {
420   iobuf_append(&conn->send_iobuf, buf, len);
421   }
422   if (buf != mem && buf != NULL) {
423   free(buf);
424   }
425425
426  return len;
426   return len;
427427}
428428
429429int ns_printf(struct ns_connection *conn, const char *fmt, ...) {
430  int len;
431  va_list ap;
432  va_start(ap, fmt);
433  len = ns_vprintf(conn, fmt, ap);
434  va_end(ap);
435  return len;
430   int len;
431   va_list ap;
432   va_start(ap, fmt);
433   len = ns_vprintf(conn, fmt, ap);
434   va_end(ap);
435   return len;
436436}
437437
438438static void hexdump(struct ns_connection *nc, const char *path,
439                    int num_bytes, enum ns_event ev) {
440  const struct iobuf *io = ev == NS_SEND ? &nc->send_iobuf : &nc->recv_iobuf;
441  FILE *fp;
442  char *buf, src[60], dst[60];
443  int buf_size = num_bytes * 5 + 100;
439               int num_bytes, enum ns_event ev) {
440   const struct iobuf *io = ev == NS_SEND ? &nc->send_iobuf : &nc->recv_iobuf;
441   FILE *fp;
442   char *buf, src[60], dst[60];
443   int buf_size = num_bytes * 5 + 100;
444444
445  if ((fp = fopen(path, "a")) != NULL) {
446    ns_sock_to_str(nc->sock, src, sizeof(src), 3);
447    ns_sock_to_str(nc->sock, dst, sizeof(dst), 7);
448    fprintf(fp, "%lu %p %s %s %s %d\n", (unsigned long) time(NULL),
449            nc->connection_data, src,
450            ev == NS_RECV ? "<-" : ev == NS_SEND ? "->" :
451            ev == NS_ACCEPT ? "<A" : ev == NS_CONNECT ? "C>" : "XX",
452            dst, num_bytes);
453    if (num_bytes > 0 && (buf = (char *) malloc(buf_size)) != NULL) {
454      ns_hexdump(io->buf + (ev == NS_SEND ? 0 : io->len) -
455        (ev == NS_SEND ? 0 : num_bytes), num_bytes, buf, buf_size);
456      fprintf(fp, "%s", buf);
457      free(buf);
458    }
459    fclose(fp);
460  }
445   if ((fp = fopen(path, "a")) != NULL) {
446   ns_sock_to_str(nc->sock, src, sizeof(src), 3);
447   ns_sock_to_str(nc->sock, dst, sizeof(dst), 7);
448   fprintf(fp, "%lu %p %s %s %s %d\n", (unsigned long) time(NULL),
449         nc->connection_data, src,
450         ev == NS_RECV ? "<-" : ev == NS_SEND ? "->" :
451         ev == NS_ACCEPT ? "<A" : ev == NS_CONNECT ? "C>" : "XX",
452         dst, num_bytes);
453   if (num_bytes > 0 && (buf = (char *) malloc(buf_size)) != NULL) {
454      ns_hexdump(io->buf + (ev == NS_SEND ? 0 : io->len) -
455      (ev == NS_SEND ? 0 : num_bytes), num_bytes, buf, buf_size);
456      fprintf(fp, "%s", buf);
457      free(buf);
458   }
459   fclose(fp);
460   }
461461}
462462
463463static void ns_call(struct ns_connection *conn, enum ns_event ev, void *p) {
464  if (conn->server->hexdump_file != NULL && ev != NS_POLL) {
465    int len = (ev == NS_RECV || ev == NS_SEND) ? * (int *) p : 0;
466    hexdump(conn, conn->server->hexdump_file, len, ev);
467  }
468  if (conn->server->callback) conn->server->callback(conn, ev, p);
464   if (conn->server->hexdump_file != NULL && ev != NS_POLL) {
465   int len = (ev == NS_RECV || ev == NS_SEND) ? * (int *) p : 0;
466   hexdump(conn, conn->server->hexdump_file, len, ev);
467   }
468   if (conn->server->callback) conn->server->callback(conn, ev, p);
469469}
470470
471471static void ns_close_conn(struct ns_connection *conn) {
472  DBG(("%p %d", conn, conn->flags));
473  ns_call(conn, NS_CLOSE, NULL);
474  ns_remove_conn(conn);
475  closesocket(conn->sock);
476  iobuf_free(&conn->recv_iobuf);
477  iobuf_free(&conn->send_iobuf);
472   DBG(("%p %d", conn, conn->flags));
473   ns_call(conn, NS_CLOSE, NULL);
474   ns_remove_conn(conn);
475   closesocket(conn->sock);
476   iobuf_free(&conn->recv_iobuf);
477   iobuf_free(&conn->send_iobuf);
478478#ifdef NS_ENABLE_SSL
479  if (conn->ssl != NULL) {
480    SSL_free(conn->ssl);
481  }
479   if (conn->ssl != NULL) {
480   SSL_free(conn->ssl);
481   }
482482#endif
483  NS_FREE(conn);
483   NS_FREE(conn);
484484}
485485
486486void ns_set_close_on_exec(sock_t sock) {
487487#ifdef _WIN32
488  (void) SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0);
488   (void) SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0);
489489#else
490  fcntl(sock, F_SETFD, FD_CLOEXEC);
490   fcntl(sock, F_SETFD, FD_CLOEXEC);
491491#endif
492492}
493493
494494static void ns_set_non_blocking_mode(sock_t sock) {
495495#ifdef _WIN32
496  unsigned long on = 1;
497  ioctlsocket(sock, FIONBIO, &on);
496   unsigned long on = 1;
497   ioctlsocket(sock, FIONBIO, &on);
498498#else
499  int flags = fcntl(sock, F_GETFL, 0);
500  fcntl(sock, F_SETFL, flags | O_NONBLOCK);
499   int flags = fcntl(sock, F_GETFL, 0);
500   fcntl(sock, F_SETFL, flags | O_NONBLOCK);
501501#endif
502502}
503503
504504#ifndef NS_DISABLE_SOCKETPAIR
505505int ns_socketpair2(sock_t sp[2], int sock_type) {
506  union socket_address sa;
507  sock_t sock;
508  socklen_t len = sizeof(sa.sin);
509  int ret = 0;
506   union socket_address sa;
507   sock_t sock;
508   socklen_t len = sizeof(sa.sin);
509   int ret = 0;
510510
511  sp[0] = sp[1] = INVALID_SOCKET;
511   sp[0] = sp[1] = INVALID_SOCKET;
512512
513  (void) memset(&sa, 0, sizeof(sa));
514  sa.sin.sin_family = AF_INET;
515  sa.sin.sin_port = htons(0);
516  sa.sin.sin_addr.s_addr = htonl(0x7f000001);
513   (void) memset(&sa, 0, sizeof(sa));
514   sa.sin.sin_family = AF_INET;
515   sa.sin.sin_port = htons(0);
516   sa.sin.sin_addr.s_addr = htonl(0x7f000001);
517517
518  if ((sock = socket(AF_INET, sock_type, 0)) != INVALID_SOCKET &&
519      !bind(sock, &sa.sa, len) &&
520      (sock_type == SOCK_DGRAM || !listen(sock, 1)) &&
521      !getsockname(sock, &sa.sa, &len) &&
522      (sp[0] = socket(AF_INET, sock_type, 0)) != INVALID_SOCKET &&
523      !connect(sp[0], &sa.sa, len) &&
524      (sock_type == SOCK_STREAM ||
525       (!getsockname(sp[0], &sa.sa, &len) && !connect(sock, &sa.sa, len))) &&
526      (sp[1] = (sock_type == SOCK_DGRAM ? sock :
527                accept(sock, &sa.sa, &len))) != INVALID_SOCKET) {
528    ns_set_close_on_exec(sp[0]);
529    ns_set_close_on_exec(sp[1]);
530    ret = 1;
531  } else {
532    if (sp[0] != INVALID_SOCKET) closesocket(sp[0]);
533    if (sp[1] != INVALID_SOCKET) closesocket(sp[1]);
534    sp[0] = sp[1] = INVALID_SOCKET;
535  }
536  if (sock_type != SOCK_DGRAM) closesocket(sock);
518   if ((sock = socket(AF_INET, sock_type, 0)) != INVALID_SOCKET &&
519      !bind(sock, &sa.sa, len) &&
520      (sock_type == SOCK_DGRAM || !listen(sock, 1)) &&
521      !getsockname(sock, &sa.sa, &len) &&
522      (sp[0] = socket(AF_INET, sock_type, 0)) != INVALID_SOCKET &&
523      !connect(sp[0], &sa.sa, len) &&
524      (sock_type == SOCK_STREAM ||
525      (!getsockname(sp[0], &sa.sa, &len) && !connect(sock, &sa.sa, len))) &&
526      (sp[1] = (sock_type == SOCK_DGRAM ? sock :
527            accept(sock, &sa.sa, &len))) != INVALID_SOCKET) {
528   ns_set_close_on_exec(sp[0]);
529   ns_set_close_on_exec(sp[1]);
530   ret = 1;
531   } else {
532   if (sp[0] != INVALID_SOCKET) closesocket(sp[0]);
533   if (sp[1] != INVALID_SOCKET) closesocket(sp[1]);
534   sp[0] = sp[1] = INVALID_SOCKET;
535   }
536   if (sock_type != SOCK_DGRAM) closesocket(sock);
537537
538  return ret;
538   return ret;
539539}
540540
541541int ns_socketpair(sock_t sp[2]) {
542  return ns_socketpair2(sp, SOCK_STREAM);
542   return ns_socketpair2(sp, SOCK_STREAM);
543543}
544544#endif  // NS_DISABLE_SOCKETPAIR
545545
546546// Valid listening port spec is: [ip_address:]port, e.g. "80", "127.0.0.1:3128"
547547static int ns_parse_port_string(const char *str, union socket_address *sa) {
548  unsigned int a, b, c, d, port;
549  int len = 0;
548   unsigned int a, b, c, d, port;
549   int len = 0;
550550#ifdef NS_ENABLE_IPV6
551  char buf[100];
551   char buf[100];
552552#endif
553553
554  // MacOS needs that. If we do not zero it, subsequent bind() will fail.
555  // Also, all-zeroes in the socket address means binding to all addresses
556  // for both IPv4 and IPv6 (INADDR_ANY and IN6ADDR_ANY_INIT).
557  memset(sa, 0, sizeof(*sa));
558  sa->sin.sin_family = AF_INET;
554   // MacOS needs that. If we do not zero it, subsequent bind() will fail.
555   // Also, all-zeroes in the socket address means binding to all addresses
556   // for both IPv4 and IPv6 (INADDR_ANY and IN6ADDR_ANY_INIT).
557   memset(sa, 0, sizeof(*sa));
558   sa->sin.sin_family = AF_INET;
559559
560  if (sscanf(str, "%u.%u.%u.%u:%u%n", &a, &b, &c, &d, &port, &len) == 5) {
561    // Bind to a specific IPv4 address, e.g. 192.168.1.5:8080
562    sa->sin.sin_addr.s_addr = htonl((a << 24) | (b << 16) | (c << 8) | d);
563    sa->sin.sin_port = htons((uint16_t) port);
560   if (sscanf(str, "%u.%u.%u.%u:%u%n", &a, &b, &c, &d, &port, &len) == 5) {
561   // Bind to a specific IPv4 address, e.g. 192.168.1.5:8080
562   sa->sin.sin_addr.s_addr = htonl((a << 24) | (b << 16) | (c << 8) | d);
563   sa->sin.sin_port = htons((uint16_t) port);
564564#ifdef NS_ENABLE_IPV6
565  } else if (sscanf(str, "[%49[^]]]:%u%n", buf, &port, &len) == 2 &&
566             inet_pton(AF_INET6, buf, &sa->sin6.sin6_addr)) {
567    // IPv6 address, e.g. [3ffe:2a00:100:7031::1]:8080
568    sa->sin6.sin6_family = AF_INET6;
569    sa->sin6.sin6_port = htons((uint16_t) port);
565   } else if (sscanf(str, "[%49[^]]]:%u%n", buf, &port, &len) == 2 &&
566            inet_pton(AF_INET6, buf, &sa->sin6.sin6_addr)) {
567   // IPv6 address, e.g. [3ffe:2a00:100:7031::1]:8080
568   sa->sin6.sin6_family = AF_INET6;
569   sa->sin6.sin6_port = htons((uint16_t) port);
570570#endif
571  } else if (sscanf(str, "%u%n", &port, &len) == 1) {
572    // If only port is specified, bind to IPv4, INADDR_ANY
573    sa->sin.sin_port = htons((uint16_t) port);
574  } else {
575    port = 0;   // Parsing failure. Make port invalid.
576  }
571   } else if (sscanf(str, "%u%n", &port, &len) == 1) {
572   // If only port is specified, bind to IPv4, INADDR_ANY
573   sa->sin.sin_port = htons((uint16_t) port);
574   } else {
575   port = 0;   // Parsing failure. Make port invalid.
576   }
577577
578  return port <= 0xffff && str[len] == '\0';
578   return port <= 0xffff && str[len] == '\0';
579579}
580580
581581// 'sa' must be an initialized address to bind to
582582static sock_t ns_open_listening_socket(union socket_address *sa) {
583  socklen_t len = sizeof(*sa);
584  sock_t sock = INVALID_SOCKET;
583   socklen_t len = sizeof(*sa);
584   sock_t sock = INVALID_SOCKET;
585585#ifndef _WIN32
586  int on = 1;
586   int on = 1;
587587#endif
588588
589  if ((sock = socket(sa->sa.sa_family, SOCK_STREAM, 6)) != INVALID_SOCKET &&
589   if ((sock = socket(sa->sa.sa_family, SOCK_STREAM, 6)) != INVALID_SOCKET &&
590590#ifndef _WIN32
591      // SO_RESUSEADDR is not enabled on Windows because the semantics of
592      // SO_REUSEADDR on UNIX and Windows is different. On Windows,
593      // SO_REUSEADDR allows to bind a socket to a port without error even if
594      // the port is already open by another program. This is not the behavior
595      // SO_REUSEADDR was designed for, and leads to hard-to-track failure
596      // scenarios. Therefore, SO_REUSEADDR was disabled on Windows.
597      !setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on)) &&
591      // SO_RESUSEADDR is not enabled on Windows because the semantics of
592      // SO_REUSEADDR on UNIX and Windows is different. On Windows,
593      // SO_REUSEADDR allows to bind a socket to a port without error even if
594      // the port is already open by another program. This is not the behavior
595      // SO_REUSEADDR was designed for, and leads to hard-to-track failure
596      // scenarios. Therefore, SO_REUSEADDR was disabled on Windows.
597      !setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on)) &&
598598#endif
599      !bind(sock, &sa->sa, sa->sa.sa_family == AF_INET ?
600            sizeof(sa->sin) : sizeof(sa->sin6)) &&
601      !listen(sock, SOMAXCONN)) {
602    ns_set_non_blocking_mode(sock);
603    // In case port was set to 0, get the real port number
604    (void) getsockname(sock, &sa->sa, &len);
605  } else if (sock != INVALID_SOCKET) {
606    closesocket(sock);
607    sock = INVALID_SOCKET;
608  }
599      !bind(sock, &sa->sa, sa->sa.sa_family == AF_INET ?
600         sizeof(sa->sin) : sizeof(sa->sin6)) &&
601      !listen(sock, SOMAXCONN)) {
602   ns_set_non_blocking_mode(sock);
603   // In case port was set to 0, get the real port number
604   (void) getsockname(sock, &sa->sa, &len);
605   } else if (sock != INVALID_SOCKET) {
606   closesocket(sock);
607   sock = INVALID_SOCKET;
608   }
609609
610  return sock;
610   return sock;
611611}
612612
613613// Certificate generation script is at
614614// https://github.com/cesanta/net_skeleton/blob/master/examples/gen_certs.sh
615615int ns_set_ssl_ca_cert(struct ns_server *server, const char *cert) {
616616#ifdef NS_ENABLE_SSL
617  STACK_OF(X509_NAME) *list = SSL_load_client_CA_file(cert);
618  if (cert != NULL && server->ssl_ctx != NULL && list != NULL) {
619    SSL_CTX_set_client_CA_list(server->ssl_ctx, list);
620    SSL_CTX_set_verify(server->ssl_ctx, SSL_VERIFY_PEER |
621                       SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
622    return 0;
623  }
617   STACK_OF(X509_NAME) *list = SSL_load_client_CA_file(cert);
618   if (cert != NULL && server->ssl_ctx != NULL && list != NULL) {
619   SSL_CTX_set_client_CA_list(server->ssl_ctx, list);
620   SSL_CTX_set_verify(server->ssl_ctx, SSL_VERIFY_PEER |
621                  SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
622   return 0;
623   }
624624#endif
625  return server != NULL && cert == NULL ? 0 : -1;
625   return server != NULL && cert == NULL ? 0 : -1;
626626}
627627
628628int ns_set_ssl_cert(struct ns_server *server, const char *cert) {
629629#ifdef NS_ENABLE_SSL
630  if (cert != NULL &&
631      (server->ssl_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) {
632    return -1;
633  } else if (SSL_CTX_use_certificate_file(server->ssl_ctx, cert, 1) == 0 ||
634             SSL_CTX_use_PrivateKey_file(server->ssl_ctx, cert, 1) == 0) {
635    return -2;
636  } else {
637    SSL_CTX_set_mode(server->ssl_ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
638    SSL_CTX_use_certificate_chain_file(server->ssl_ctx, cert);
639    return 0;
640  }
630   if (cert != NULL &&
631      (server->ssl_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) {
632   return -1;
633   } else if (SSL_CTX_use_certificate_file(server->ssl_ctx, cert, 1) == 0 ||
634            SSL_CTX_use_PrivateKey_file(server->ssl_ctx, cert, 1) == 0) {
635   return -2;
636   } else {
637   SSL_CTX_set_mode(server->ssl_ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
638   SSL_CTX_use_certificate_chain_file(server->ssl_ctx, cert);
639   return 0;
640   }
641641#endif
642  return server != NULL && cert == NULL ? 0 : -3;
642   return server != NULL && cert == NULL ? 0 : -3;
643643}
644644
645645int ns_bind(struct ns_server *server, const char *str) {
646  union socket_address sa;
647  ns_parse_port_string(str, &sa);
648  if (server->listening_sock != INVALID_SOCKET) {
649    closesocket(server->listening_sock);
650  }
651  server->listening_sock = ns_open_listening_socket(&sa);
652  return server->listening_sock == INVALID_SOCKET ? -1 :
653  (int) ntohs(sa.sin.sin_port);
646   union socket_address sa;
647   ns_parse_port_string(str, &sa);
648   if (server->listening_sock != INVALID_SOCKET) {
649   closesocket(server->listening_sock);
650   }
651   server->listening_sock = ns_open_listening_socket(&sa);
652   return server->listening_sock == INVALID_SOCKET ? -1 :
653   (int) ntohs(sa.sin.sin_port);
654654}
655655
656656
657657static struct ns_connection *accept_conn(struct ns_server *server) {
658  struct ns_connection *c = NULL;
659  union socket_address sa;
660  socklen_t len = sizeof(sa);
661  sock_t sock = INVALID_SOCKET;
658   struct ns_connection *c = NULL;
659   union socket_address sa;
660   socklen_t len = sizeof(sa);
661   sock_t sock = INVALID_SOCKET;
662662
663  // NOTE(lsm): on Windows, sock is always > FD_SETSIZE
664  if ((sock = accept(server->listening_sock, &sa.sa, &len)) == INVALID_SOCKET) {
665  } else if ((c = (struct ns_connection *) NS_MALLOC(sizeof(*c))) == NULL ||
666             memset(c, 0, sizeof(*c)) == NULL) {
667    closesocket(sock);
663   // NOTE(lsm): on Windows, sock is always > FD_SETSIZE
664   if ((sock = accept(server->listening_sock, &sa.sa, &len)) == INVALID_SOCKET) {
665   } else if ((c = (struct ns_connection *) NS_MALLOC(sizeof(*c))) == NULL ||
666            memset(c, 0, sizeof(*c)) == NULL) {
667   closesocket(sock);
668668#ifdef NS_ENABLE_SSL
669  } else if (server->ssl_ctx != NULL &&
670             ((c->ssl = SSL_new(server->ssl_ctx)) == NULL ||
671              SSL_set_fd(c->ssl, sock) != 1)) {
672    DBG(("SSL error"));
673    closesocket(sock);
674    free(c);
675    c = NULL;
669   } else if (server->ssl_ctx != NULL &&
670            ((c->ssl = SSL_new(server->ssl_ctx)) == NULL ||
671            SSL_set_fd(c->ssl, sock) != 1)) {
672   DBG(("SSL error"));
673   closesocket(sock);
674   free(c);
675   c = NULL;
676676#endif
677  } else {
678    ns_set_close_on_exec(sock);
679    ns_set_non_blocking_mode(sock);
680    c->server = server;
681    c->sock = sock;
682    c->flags |= NSF_ACCEPTED;
677   } else {
678   ns_set_close_on_exec(sock);
679   ns_set_non_blocking_mode(sock);
680   c->server = server;
681   c->sock = sock;
682   c->flags |= NSF_ACCEPTED;
683683
684    ns_add_conn(server, c);
685    ns_call(c, NS_ACCEPT, &sa);
686    DBG(("%p %d %p %p", c, c->sock, c->ssl, server->ssl_ctx));
687  }
684   ns_add_conn(server, c);
685   ns_call(c, NS_ACCEPT, &sa);
686   DBG(("%p %d %p %p", c, c->sock, c->ssl, server->ssl_ctx));
687   }
688688
689  return c;
689   return c;
690690}
691691
692692static int ns_is_error(int n) {
693  return n == 0 ||
694    (n < 0 && errno != EINTR && errno != EINPROGRESS &&
695     errno != EAGAIN && errno != EWOULDBLOCK
693   return n == 0 ||
694   (n < 0 && errno != EINTR && errno != EINPROGRESS &&
695      errno != EAGAIN && errno != EWOULDBLOCK
696696#ifdef _WIN32
697     && WSAGetLastError() != WSAEINTR && WSAGetLastError() != WSAEWOULDBLOCK
697      && WSAGetLastError() != WSAEINTR && WSAGetLastError() != WSAEWOULDBLOCK
698698#endif
699    );
699   );
700700}
701701
702702void ns_sock_to_str(sock_t sock, char *buf, size_t len, int flags) {
703  union socket_address sa;
704  socklen_t slen = sizeof(sa);
703   union socket_address sa;
704   socklen_t slen = sizeof(sa);
705705
706  if (buf != NULL && len > 0) {
707    buf[0] = '\0';
708    memset(&sa, 0, sizeof(sa));
709    if (flags & 4) {
710      getpeername(sock, &sa.sa, &slen);
711    } else {
712      getsockname(sock, &sa.sa, &slen);
713    }
714    if (flags & 1) {
706   if (buf != NULL && len > 0) {
707   buf[0] = '\0';
708   memset(&sa, 0, sizeof(sa));
709   if (flags & 4) {
710      getpeername(sock, &sa.sa, &slen);
711   } else {
712      getsockname(sock, &sa.sa, &slen);
713   }
714   if (flags & 1) {
715715#if defined(NS_ENABLE_IPV6)
716      inet_ntop(sa.sa.sa_family, sa.sa.sa_family == AF_INET ?
717                (void *) &sa.sin.sin_addr :
718                (void *) &sa.sin6.sin6_addr, buf, len);
716      inet_ntop(sa.sa.sa_family, sa.sa.sa_family == AF_INET ?
717            (void *) &sa.sin.sin_addr :
718            (void *) &sa.sin6.sin6_addr, buf, len);
719719#elif defined(_WIN32)
720      // Only Windoze Vista (and newer) have inet_ntop()
721      strncpy(buf, inet_ntoa(sa.sin.sin_addr), len);
720      // Only Windoze Vista (and newer) have inet_ntop()
721      strncpy(buf, inet_ntoa(sa.sin.sin_addr), len);
722722#else
723      inet_ntop(sa.sa.sa_family, (void *) &sa.sin.sin_addr, buf, len);
723      inet_ntop(sa.sa.sa_family, (void *) &sa.sin.sin_addr, buf, len);
724724#endif
725    }
726    if (flags & 2) {
727      snprintf(buf + strlen(buf), len - (strlen(buf) + 1), "%s%d",
728               flags & 1 ? ":" : "", (int) ntohs(sa.sin.sin_port));
729    }
730  }
725   }
726   if (flags & 2) {
727      snprintf(buf + strlen(buf), len - (strlen(buf) + 1), "%s%d",
728            flags & 1 ? ":" : "", (int) ntohs(sa.sin.sin_port));
729   }
730   }
731731}
732732
733733int ns_hexdump(const void *buf, int len, char *dst, int dst_len) {
734  const unsigned char *p = (const unsigned char *) buf;
735  char ascii[17] = "";
736  int i, idx, n = 0;
734   const unsigned char *p = (const unsigned char *) buf;
735   char ascii[17] = "";
736   int i, idx, n = 0;
737737
738  for (i = 0; i < len; i++) {
739    idx = i % 16;
740    if (idx == 0) {
741      if (i > 0) n += snprintf(dst + n, dst_len - n, "  %s\n", ascii);
742      n += snprintf(dst + n, dst_len - n, "%04x ", i);
743    }
744    n += snprintf(dst + n, dst_len - n, " %02x", p[i]);
745    ascii[idx] = p[i] < 0x20 || p[i] > 0x7e ? '.' : p[i];
746    ascii[idx + 1] = '\0';
747  }
738   for (i = 0; i < len; i++) {
739   idx = i % 16;
740   if (idx == 0) {
741      if (i > 0) n += snprintf(dst + n, dst_len - n, "  %s\n", ascii);
742      n += snprintf(dst + n, dst_len - n, "%04x ", i);
743   }
744   n += snprintf(dst + n, dst_len - n, " %02x", p[i]);
745   ascii[idx] = p[i] < 0x20 || p[i] > 0x7e ? '.' : p[i];
746   ascii[idx + 1] = '\0';
747   }
748748
749  while (i++ % 16) n += snprintf(dst + n, dst_len - n, "%s", "   ");
750  n += snprintf(dst + n, dst_len - n, "  %s\n\n", ascii);
749   while (i++ % 16) n += snprintf(dst + n, dst_len - n, "%s", "   ");
750   n += snprintf(dst + n, dst_len - n, "  %s\n\n", ascii);
751751
752  return n;
752   return n;
753753}
754754
755755#ifdef NS_ENABLE_SSL
756756static int ns_ssl_err(struct ns_connection *conn, int res) {
757  int ssl_err = SSL_get_error(conn->ssl, res);
758  if (ssl_err == SSL_ERROR_WANT_READ) conn->flags |= NSF_WANT_READ;
759  if (ssl_err == SSL_ERROR_WANT_WRITE) conn->flags |= NSF_WANT_WRITE;
760  return ssl_err;
757   int ssl_err = SSL_get_error(conn->ssl, res);
758   if (ssl_err == SSL_ERROR_WANT_READ) conn->flags |= NSF_WANT_READ;
759   if (ssl_err == SSL_ERROR_WANT_WRITE) conn->flags |= NSF_WANT_WRITE;
760   return ssl_err;
761761}
762762#endif
763763
764764static void ns_read_from_socket(struct ns_connection *conn) {
765  char buf[2048];
766  int n = 0;
765   char buf[2048];
766   int n = 0;
767767
768  if (conn->flags & NSF_CONNECTING) {
769    int ok = 1, ret;
770    socklen_t len = sizeof(ok);
768   if (conn->flags & NSF_CONNECTING) {
769   int ok = 1, ret;
770   socklen_t len = sizeof(ok);
771771
772    ret = getsockopt(conn->sock, SOL_SOCKET, SO_ERROR, (char *) &ok, &len);
773    (void) ret;
772   ret = getsockopt(conn->sock, SOL_SOCKET, SO_ERROR, (char *) &ok, &len);
773   (void) ret;
774774#ifdef NS_ENABLE_SSL
775    if (ret == 0 && ok == 0 && conn->ssl != NULL) {
776      int res = SSL_connect(conn->ssl);
777      int ssl_err = ns_ssl_err(conn, res);
778      if (res == 1) {
779        conn->flags |= NSF_SSL_HANDSHAKE_DONE;
780      } else if (ssl_err == SSL_ERROR_WANT_READ ||
781                 ssl_err == SSL_ERROR_WANT_WRITE) {
782        return; // Call us again
783      } else {
784        ok = 1;
785      }
786    }
775   if (ret == 0 && ok == 0 && conn->ssl != NULL) {
776      int res = SSL_connect(conn->ssl);
777      int ssl_err = ns_ssl_err(conn, res);
778      if (res == 1) {
779      conn->flags |= NSF_SSL_HANDSHAKE_DONE;
780      } else if (ssl_err == SSL_ERROR_WANT_READ ||
781               ssl_err == SSL_ERROR_WANT_WRITE) {
782      return; // Call us again
783      } else {
784      ok = 1;
785      }
786   }
787787#endif
788    conn->flags &= ~NSF_CONNECTING;
789    DBG(("%p ok=%d", conn, ok));
790    if (ok != 0) {
791      conn->flags |= NSF_CLOSE_IMMEDIATELY;
792    }
793    ns_call(conn, NS_CONNECT, &ok);
794    return;
795  }
788   conn->flags &= ~NSF_CONNECTING;
789   DBG(("%p ok=%d", conn, ok));
790   if (ok != 0) {
791      conn->flags |= NSF_CLOSE_IMMEDIATELY;
792   }
793   ns_call(conn, NS_CONNECT, &ok);
794   return;
795   }
796796
797797#ifdef NS_ENABLE_SSL
798  if (conn->ssl != NULL) {
799    if (conn->flags & NSF_SSL_HANDSHAKE_DONE) {
800      // SSL library may have more bytes ready to read then we ask to read.
801      // Therefore, read in a loop until we read everything. Without the loop,
802      // we skip to the next select() cycle which can just timeout.
803      while ((n = SSL_read(conn->ssl, buf, sizeof(buf))) > 0) {
804        DBG(("%p %d <- %d bytes (SSL)", conn, conn->flags, n));
805        iobuf_append(&conn->recv_iobuf, buf, n);
806        ns_call(conn, NS_RECV, &n);
807      }
808      ns_ssl_err(conn, n);
809    } else {
810      int res = SSL_accept(conn->ssl);
811      int ssl_err = ns_ssl_err(conn, res);
812      if (res == 1) {
813        conn->flags |= NSF_SSL_HANDSHAKE_DONE;
814      } else if (ssl_err == SSL_ERROR_WANT_READ ||
815                 ssl_err == SSL_ERROR_WANT_WRITE) {
816        return; // Call us again
817      } else {
818        conn->flags |= NSF_CLOSE_IMMEDIATELY;
819      }
820      return;
821    }
822  } else
798   if (conn->ssl != NULL) {
799   if (conn->flags & NSF_SSL_HANDSHAKE_DONE) {
800      // SSL library may have more bytes ready to read then we ask to read.
801      // Therefore, read in a loop until we read everything. Without the loop,
802      // we skip to the next select() cycle which can just timeout.
803      while ((n = SSL_read(conn->ssl, buf, sizeof(buf))) > 0) {
804      DBG(("%p %d <- %d bytes (SSL)", conn, conn->flags, n));
805      iobuf_append(&conn->recv_iobuf, buf, n);
806      ns_call(conn, NS_RECV, &n);
807      }
808      ns_ssl_err(conn, n);
809   } else {
810      int res = SSL_accept(conn->ssl);
811      int ssl_err = ns_ssl_err(conn, res);
812      if (res == 1) {
813      conn->flags |= NSF_SSL_HANDSHAKE_DONE;
814      } else if (ssl_err == SSL_ERROR_WANT_READ ||
815               ssl_err == SSL_ERROR_WANT_WRITE) {
816      return; // Call us again
817      } else {
818      conn->flags |= NSF_CLOSE_IMMEDIATELY;
819      }
820      return;
821   }
822   } else
823823#endif
824  {
825    while ((n = recv(conn->sock, buf, sizeof(buf), 0)) > 0) {
826      DBG(("%p %d <- %d bytes (PLAIN)", conn, conn->flags, n));
827      iobuf_append(&conn->recv_iobuf, buf, n);
828      ns_call(conn, NS_RECV, &n);
829    }
830  }
824   {
825   while ((n = recv(conn->sock, buf, sizeof(buf), 0)) > 0) {
826      DBG(("%p %d <- %d bytes (PLAIN)", conn, conn->flags, n));
827      iobuf_append(&conn->recv_iobuf, buf, n);
828      ns_call(conn, NS_RECV, &n);
829   }
830   }
831831
832  if (ns_is_error(n)) {
833    conn->flags |= NSF_CLOSE_IMMEDIATELY;
834  }
832   if (ns_is_error(n)) {
833   conn->flags |= NSF_CLOSE_IMMEDIATELY;
834   }
835835}
836836
837837static void ns_write_to_socket(struct ns_connection *conn) {
838  struct iobuf *io = &conn->send_iobuf;
839  int n = 0;
838   struct iobuf *io = &conn->send_iobuf;
839   int n = 0;
840840
841841#ifdef NS_ENABLE_SSL
842  if (conn->ssl != NULL) {
843    n = SSL_write(conn->ssl, io->buf, io->len);
844    if (n <= 0) {
845      int ssl_err = ns_ssl_err(conn, n);
846      if (ssl_err == SSL_ERROR_WANT_READ || ssl_err == SSL_ERROR_WANT_WRITE) {
847        return; // Call us again
848      } else {
849        conn->flags |= NSF_CLOSE_IMMEDIATELY;
850      }
851    }
852  } else
842   if (conn->ssl != NULL) {
843   n = SSL_write(conn->ssl, io->buf, io->len);
844   if (n <= 0) {
845      int ssl_err = ns_ssl_err(conn, n);
846      if (ssl_err == SSL_ERROR_WANT_READ || ssl_err == SSL_ERROR_WANT_WRITE) {
847      return; // Call us again
848      } else {
849      conn->flags |= NSF_CLOSE_IMMEDIATELY;
850      }
851   }
852   } else
853853#endif
854  { n = send(conn->sock, io->buf, io->len, 0); }
854   { n = send(conn->sock, io->buf, io->len, 0); }
855855
856  DBG(("%p %d -> %d bytes", conn, conn->flags, n));
856   DBG(("%p %d -> %d bytes", conn, conn->flags, n));
857857
858  ns_call(conn, NS_SEND, &n);
859  if (ns_is_error(n)) {
860    conn->flags |= NSF_CLOSE_IMMEDIATELY;
861  } else if (n > 0) {
862    iobuf_remove(io, n);
863  }
858   ns_call(conn, NS_SEND, &n);
859   if (ns_is_error(n)) {
860   conn->flags |= NSF_CLOSE_IMMEDIATELY;
861   } else if (n > 0) {
862   iobuf_remove(io, n);
863   }
864864}
865865
866866int ns_send(struct ns_connection *conn, const void *buf, int len) {
867  return iobuf_append(&conn->send_iobuf, buf, len);
867   return iobuf_append(&conn->send_iobuf, buf, len);
868868}
869869
870870static void ns_add_to_set(sock_t sock, fd_set *set, sock_t *max_fd) {
871  if (sock != INVALID_SOCKET) {
872    FD_SET(sock, set);
873    if (*max_fd == INVALID_SOCKET || sock > *max_fd) {
874      *max_fd = sock;
875    }
876  }
871   if (sock != INVALID_SOCKET) {
872   FD_SET(sock, set);
873   if (*max_fd == INVALID_SOCKET || sock > *max_fd) {
874      *max_fd = sock;
875   }
876   }
877877}
878878
879879int ns_server_poll(struct ns_server *server, int milli) {
880  struct ns_connection *conn, *tmp_conn;
881  struct timeval tv;
882  fd_set read_set, write_set;
883  int num_active_connections = 0;
884  sock_t max_fd = INVALID_SOCKET;
885  time_t current_time = time(NULL);
880   struct ns_connection *conn, *tmp_conn;
881   struct timeval tv;
882   fd_set read_set, write_set;
883   int num_active_connections = 0;
884   sock_t max_fd = INVALID_SOCKET;
885   time_t current_time = time(NULL);
886886
887  if (server->listening_sock == INVALID_SOCKET &&
888      server->active_connections == NULL) return 0;
887   if (server->listening_sock == INVALID_SOCKET &&
888      server->active_connections == NULL) return 0;
889889
890  FD_ZERO(&read_set);
891  FD_ZERO(&write_set);
892  ns_add_to_set(server->listening_sock, &read_set, &max_fd);
893  ns_add_to_set(server->ctl[1], &read_set, &max_fd);
890   FD_ZERO(&read_set);
891   FD_ZERO(&write_set);
892   ns_add_to_set(server->listening_sock, &read_set, &max_fd);
893   ns_add_to_set(server->ctl[1], &read_set, &max_fd);
894894
895  for (conn = server->active_connections; conn != NULL; conn = tmp_conn) {
896    tmp_conn = conn->next;
897    ns_call(conn, NS_POLL, &current_time);
898    if (!(conn->flags & NSF_WANT_WRITE)) {
899      //DBG(("%p read_set", conn));
900      ns_add_to_set(conn->sock, &read_set, &max_fd);
901    }
902    if (((conn->flags & NSF_CONNECTING) && !(conn->flags & NSF_WANT_READ)) ||
903        (conn->send_iobuf.len > 0 && !(conn->flags & NSF_CONNECTING) &&
904         !(conn->flags & NSF_BUFFER_BUT_DONT_SEND))) {
905      //DBG(("%p write_set", conn));
906      ns_add_to_set(conn->sock, &write_set, &max_fd);
907    }
908    if (conn->flags & NSF_CLOSE_IMMEDIATELY) {
909      ns_close_conn(conn);
910    }
911  }
895   for (conn = server->active_connections; conn != NULL; conn = tmp_conn) {
896   tmp_conn = conn->next;
897   ns_call(conn, NS_POLL, &current_time);
898   if (!(conn->flags & NSF_WANT_WRITE)) {
899      //DBG(("%p read_set", conn));
900      ns_add_to_set(conn->sock, &read_set, &max_fd);
901   }
902   if (((conn->flags & NSF_CONNECTING) && !(conn->flags & NSF_WANT_READ)) ||
903      (conn->send_iobuf.len > 0 && !(conn->flags & NSF_CONNECTING) &&
904         !(conn->flags & NSF_BUFFER_BUT_DONT_SEND))) {
905      //DBG(("%p write_set", conn));
906      ns_add_to_set(conn->sock, &write_set, &max_fd);
907   }
908   if (conn->flags & NSF_CLOSE_IMMEDIATELY) {
909      ns_close_conn(conn);
910   }
911   }
912912
913  tv.tv_sec = milli / 1000;
914  tv.tv_usec = (milli % 1000) * 1000;
913   tv.tv_sec = milli / 1000;
914   tv.tv_usec = (milli % 1000) * 1000;
915915
916  if (select((int) max_fd + 1, &read_set, &write_set, NULL, &tv) > 0) {
917    // select() might have been waiting for a long time, reset current_time
918    // now to prevent last_io_time being set to the past.
919    current_time = time(NULL);
916   if (select((int) max_fd + 1, &read_set, &write_set, NULL, &tv) > 0) {
917   // select() might have been waiting for a long time, reset current_time
918   // now to prevent last_io_time being set to the past.
919   current_time = time(NULL);
920920
921    // Accept new connections
922    if (server->listening_sock != INVALID_SOCKET &&
923        FD_ISSET(server->listening_sock, &read_set)) {
924      // We're not looping here, and accepting just one connection at
925      // a time. The reason is that eCos does not respect non-blocking
926      // flag on a listening socket and hangs in a loop.
927      if ((conn = accept_conn(server)) != NULL) {
928        conn->last_io_time = current_time;
929      }
930    }
921   // Accept new connections
922   if (server->listening_sock != INVALID_SOCKET &&
923      FD_ISSET(server->listening_sock, &read_set)) {
924      // We're not looping here, and accepting just one connection at
925      // a time. The reason is that eCos does not respect non-blocking
926      // flag on a listening socket and hangs in a loop.
927      if ((conn = accept_conn(server)) != NULL) {
928      conn->last_io_time = current_time;
929      }
930   }
931931
932    // Read wakeup messages
933    if (server->ctl[1] != INVALID_SOCKET &&
934        FD_ISSET(server->ctl[1], &read_set)) {
935      struct ctl_msg ctl_msg;
936      int len = recv(server->ctl[1], (char *) &ctl_msg, sizeof(ctl_msg), 0);
937      send(server->ctl[1], ctl_msg.message, 1, 0);
938      if (len >= (int) sizeof(ctl_msg.callback) && ctl_msg.callback != NULL) {
939        ns_iterate(server, ctl_msg.callback, ctl_msg.message);
940      }
941    }
932   // Read wakeup messages
933   if (server->ctl[1] != INVALID_SOCKET &&
934      FD_ISSET(server->ctl[1], &read_set)) {
935      struct ctl_msg ctl_msg;
936      int len = recv(server->ctl[1], (char *) &ctl_msg, sizeof(ctl_msg), 0);
937      send(server->ctl[1], ctl_msg.message, 1, 0);
938      if (len >= (int) sizeof(ctl_msg.callback) && ctl_msg.callback != NULL) {
939      ns_iterate(server, ctl_msg.callback, ctl_msg.message);
940      }
941   }
942942
943    for (conn = server->active_connections; conn != NULL; conn = tmp_conn) {
944      tmp_conn = conn->next;
945      if (FD_ISSET(conn->sock, &read_set)) {
946        conn->last_io_time = current_time;
947        ns_read_from_socket(conn);
948      }
949      if (FD_ISSET(conn->sock, &write_set)) {
950        if (conn->flags & NSF_CONNECTING) {
951          ns_read_from_socket(conn);
952        } else if (!(conn->flags & NSF_BUFFER_BUT_DONT_SEND)) {
953          conn->last_io_time = current_time;
954          ns_write_to_socket(conn);
955        }
956      }
957    }
958  }
943   for (conn = server->active_connections; conn != NULL; conn = tmp_conn) {
944      tmp_conn = conn->next;
945      if (FD_ISSET(conn->sock, &read_set)) {
946      conn->last_io_time = current_time;
947      ns_read_from_socket(conn);
948      }
949      if (FD_ISSET(conn->sock, &write_set)) {
950      if (conn->flags & NSF_CONNECTING) {
951         ns_read_from_socket(conn);
952      } else if (!(conn->flags & NSF_BUFFER_BUT_DONT_SEND)) {
953         conn->last_io_time = current_time;
954         ns_write_to_socket(conn);
955      }
956      }
957   }
958   }
959959
960  for (conn = server->active_connections; conn != NULL; conn = tmp_conn) {
961    tmp_conn = conn->next;
962    num_active_connections++;
963    if ((conn->flags & NSF_CLOSE_IMMEDIATELY) ||
964        (conn->send_iobuf.len == 0 &&
965          (conn->flags & NSF_FINISHED_SENDING_DATA))) {
966      ns_close_conn(conn);
967    }
968  }
969  //DBG(("%d active connections", num_active_connections));
960   for (conn = server->active_connections; conn != NULL; conn = tmp_conn) {
961   tmp_conn = conn->next;
962   num_active_connections++;
963   if ((conn->flags & NSF_CLOSE_IMMEDIATELY) ||
964      (conn->send_iobuf.len == 0 &&
965         (conn->flags & NSF_FINISHED_SENDING_DATA))) {
966      ns_close_conn(conn);
967   }
968   }
969   //DBG(("%d active connections", num_active_connections));
970970
971  return num_active_connections;
971   return num_active_connections;
972972}
973973
974974struct ns_connection *ns_connect(struct ns_server *server, const char *host,
975                                 int port, int use_ssl, void *param) {
976  sock_t sock = INVALID_SOCKET;
977  struct sockaddr_in sin;
978  struct hostent *he = NULL;
979  struct ns_connection *conn = NULL;
980  int connect_ret_val;
975                           int port, int use_ssl, void *param) {
976   sock_t sock = INVALID_SOCKET;
977   struct sockaddr_in sin;
978   struct hostent *he = NULL;
979   struct ns_connection *conn = NULL;
980   int connect_ret_val;
981981
982  (void) use_ssl;
982   (void) use_ssl;
983983
984  if (host == NULL || (he = gethostbyname(host)) == NULL ||
985      (sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
986    DBG(("gethostbyname(%s) failed: %s", host, strerror(errno)));
987    return NULL;
988  }
984   if (host == NULL || (he = gethostbyname(host)) == NULL ||
985      (sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
986   DBG(("gethostbyname(%s) failed: %s", host, strerror(errno)));
987   return NULL;
988   }
989989
990  sin.sin_family = AF_INET;
991  sin.sin_port = htons((uint16_t) port);
992  sin.sin_addr = * (struct in_addr *) he->h_addr_list[0];
993  ns_set_non_blocking_mode(sock);
990   sin.sin_family = AF_INET;
991   sin.sin_port = htons((uint16_t) port);
992   sin.sin_addr = * (struct in_addr *) he->h_addr_list[0];
993   ns_set_non_blocking_mode(sock);
994994
995  connect_ret_val = connect(sock, (struct sockaddr *) &sin, sizeof(sin));
996  if (ns_is_error(connect_ret_val)) {
997    closesocket(sock);
998    return NULL;
999  } else if ((conn = (struct ns_connection *)
1000              NS_MALLOC(sizeof(*conn))) == NULL) {
1001    closesocket(sock);
1002    return NULL;
1003  }
995   connect_ret_val = connect(sock, (struct sockaddr *) &sin, sizeof(sin));
996   if (ns_is_error(connect_ret_val)) {
997   closesocket(sock);
998   return NULL;
999   } else if ((conn = (struct ns_connection *)
1000            NS_MALLOC(sizeof(*conn))) == NULL) {
1001   closesocket(sock);
1002   return NULL;
1003   }
10041004
1005  memset(conn, 0, sizeof(*conn));
1006  conn->server = server;
1007  conn->sock = sock;
1008  conn->connection_data = param;
1009  conn->flags = NSF_CONNECTING;
1010  conn->last_io_time = time(NULL);
1005   memset(conn, 0, sizeof(*conn));
1006   conn->server = server;
1007   conn->sock = sock;
1008   conn->connection_data = param;
1009   conn->flags = NSF_CONNECTING;
1010   conn->last_io_time = time(NULL);
10111011
10121012#ifdef NS_ENABLE_SSL
1013  if (use_ssl &&
1014      (conn->ssl = SSL_new(server->client_ssl_ctx)) != NULL) {
1015    SSL_set_fd(conn->ssl, sock);
1016  }
1013   if (use_ssl &&
1014      (conn->ssl = SSL_new(server->client_ssl_ctx)) != NULL) {
1015   SSL_set_fd(conn->ssl, sock);
1016   }
10171017#endif
10181018
1019  ns_add_conn(server, conn);
1020  DBG(("%p %s:%d %d %p", conn, host, port, conn->sock, conn->ssl));
1019   ns_add_conn(server, conn);
1020   DBG(("%p %s:%d %d %p", conn, host, port, conn->sock, conn->ssl));
10211021
1022  return conn;
1022   return conn;
10231023}
10241024
10251025struct ns_connection *ns_add_sock(struct ns_server *s, sock_t sock, void *p) {
1026  struct ns_connection *conn;
1027  if ((conn = (struct ns_connection *) NS_MALLOC(sizeof(*conn))) != NULL) {
1028    memset(conn, 0, sizeof(*conn));
1029    ns_set_non_blocking_mode(sock);
1030    conn->sock = sock;
1031    conn->connection_data = p;
1032    conn->server = s;
1033    conn->last_io_time = time(NULL);
1034    ns_add_conn(s, conn);
1035    DBG(("%p %d", conn, sock));
1036  }
1037  return conn;
1026   struct ns_connection *conn;
1027   if ((conn = (struct ns_connection *) NS_MALLOC(sizeof(*conn))) != NULL) {
1028   memset(conn, 0, sizeof(*conn));
1029   ns_set_non_blocking_mode(sock);
1030   conn->sock = sock;
1031   conn->connection_data = p;
1032   conn->server = s;
1033   conn->last_io_time = time(NULL);
1034   ns_add_conn(s, conn);
1035   DBG(("%p %d", conn, sock));
1036   }
1037   return conn;
10381038}
10391039
10401040struct ns_connection *ns_next(struct ns_server *s, struct ns_connection *conn) {
1041  return conn == NULL ? s->active_connections : conn->next;
1041   return conn == NULL ? s->active_connections : conn->next;
10421042}
10431043
10441044void ns_iterate(struct ns_server *server, ns_callback_t cb, void *param) {
1045  struct ns_connection *conn, *tmp_conn;
1045   struct ns_connection *conn, *tmp_conn;
10461046
1047  for (conn = server->active_connections; conn != NULL; conn = tmp_conn) {
1048    tmp_conn = conn->next;
1049    cb(conn, NS_POLL, param);
1050  }
1047   for (conn = server->active_connections; conn != NULL; conn = tmp_conn) {
1048   tmp_conn = conn->next;
1049   cb(conn, NS_POLL, param);
1050   }
10511051}
10521052
10531053void ns_server_wakeup_ex(struct ns_server *server, ns_callback_t cb,
1054                         void *data, size_t len) {
1055  struct ctl_msg ctl_msg;
1056  if (server->ctl[0] != INVALID_SOCKET && data != NULL &&
1057      len < sizeof(ctl_msg.message)) {
1058    ctl_msg.callback = cb;
1059    memcpy(ctl_msg.message, data, len);
1060    send(server->ctl[0], (char *) &ctl_msg,
1061         offsetof(struct ctl_msg, message) + len, 0);
1062    recv(server->ctl[0], (char *) &len, 1, 0);
1063  }
1054                     void *data, size_t len) {
1055   struct ctl_msg ctl_msg;
1056   if (server->ctl[0] != INVALID_SOCKET && data != NULL &&
1057      len < sizeof(ctl_msg.message)) {
1058   ctl_msg.callback = cb;
1059   memcpy(ctl_msg.message, data, len);
1060   send(server->ctl[0], (char *) &ctl_msg,
1061         offsetof(struct ctl_msg, message) + len, 0);
1062   recv(server->ctl[0], (char *) &len, 1, 0);
1063   }
10641064}
10651065
10661066void ns_server_wakeup(struct ns_server *server) {
1067  ns_server_wakeup_ex(server, NULL, (void *) "", 0);
1067   ns_server_wakeup_ex(server, NULL, (void *) "", 0);
10681068}
10691069
10701070void ns_server_init(struct ns_server *s, void *server_data, ns_callback_t cb) {
1071  memset(s, 0, sizeof(*s));
1072  s->listening_sock = s->ctl[0] = s->ctl[1] = INVALID_SOCKET;
1073  s->server_data = server_data;
1074  s->callback = cb;
1071   memset(s, 0, sizeof(*s));
1072   s->listening_sock = s->ctl[0] = s->ctl[1] = INVALID_SOCKET;
1073   s->server_data = server_data;
1074   s->callback = cb;
10751075
10761076#ifdef _WIN32
1077  { WSADATA data; WSAStartup(MAKEWORD(2, 2), &data); }
1077   { WSADATA data; WSAStartup(MAKEWORD(2, 2), &data); }
10781078#else
1079  // Ignore SIGPIPE signal, so if client cancels the request, it
1080  // won't kill the whole process.
1081  signal(SIGPIPE, SIG_IGN);
1079   // Ignore SIGPIPE signal, so if client cancels the request, it
1080   // won't kill the whole process.
1081   signal(SIGPIPE, SIG_IGN);
10821082#endif
10831083
10841084#ifndef NS_DISABLE_SOCKETPAIR
1085  do {
1086    ns_socketpair2(s->ctl, SOCK_DGRAM);
1087  } while (s->ctl[0] == INVALID_SOCKET);
1085   do {
1086   ns_socketpair2(s->ctl, SOCK_DGRAM);
1087   } while (s->ctl[0] == INVALID_SOCKET);
10881088#endif
10891089
10901090#ifdef NS_ENABLE_SSL
1091  {static int init_done; if (!init_done) { SSL_library_init(); init_done++; }}
1092  s->client_ssl_ctx = SSL_CTX_new(SSLv23_client_method());
1091   {static int init_done; if (!init_done) { SSL_library_init(); init_done++; }}
1092   s->client_ssl_ctx = SSL_CTX_new(SSLv23_client_method());
10931093#endif
10941094}
10951095
10961096void ns_server_free(struct ns_server *s) {
1097  struct ns_connection *conn, *tmp_conn;
1097   struct ns_connection *conn, *tmp_conn;
10981098
1099  DBG(("%p", s));
1100  if (s == NULL) return;
1101  // Do one last poll, see https://github.com/cesanta/mongoose/issues/286
1102  ns_server_poll(s, 0);
1099   DBG(("%p", s));
1100   if (s == NULL) return;
1101   // Do one last poll, see https://github.com/cesanta/mongoose/issues/286
1102   ns_server_poll(s, 0);
11031103
1104  if (s->listening_sock != INVALID_SOCKET) closesocket(s->listening_sock);
1105  if (s->ctl[0] != INVALID_SOCKET) closesocket(s->ctl[0]);
1106  if (s->ctl[1] != INVALID_SOCKET) closesocket(s->ctl[1]);
1107  s->listening_sock = s->ctl[0] = s->ctl[1] = INVALID_SOCKET;
1104   if (s->listening_sock != INVALID_SOCKET) closesocket(s->listening_sock);
1105   if (s->ctl[0] != INVALID_SOCKET) closesocket(s->ctl[0]);
1106   if (s->ctl[1] != INVALID_SOCKET) closesocket(s->ctl[1]);
1107   s->listening_sock = s->ctl[0] = s->ctl[1] = INVALID_SOCKET;
11081108
1109  for (conn = s->active_connections; conn != NULL; conn = tmp_conn) {
1110    tmp_conn = conn->next;
1111    ns_close_conn(conn);
1112  }
1109   for (conn = s->active_connections; conn != NULL; conn = tmp_conn) {
1110   tmp_conn = conn->next;
1111   ns_close_conn(conn);
1112   }
11131113
11141114#ifdef NS_ENABLE_SSL
1115  if (s->ssl_ctx != NULL) SSL_CTX_free(s->ssl_ctx);
1116  if (s->client_ssl_ctx != NULL) SSL_CTX_free(s->client_ssl_ctx);
1117  s->ssl_ctx = s->client_ssl_ctx = NULL;
1115   if (s->ssl_ctx != NULL) SSL_CTX_free(s->ssl_ctx);
1116   if (s->client_ssl_ctx != NULL) SSL_CTX_free(s->client_ssl_ctx);
1117   s->ssl_ctx = s->client_ssl_ctx = NULL;
11181118#endif
11191119}
11201120// net_skeleton end
r32760r32761
12191219#endif
12201220
12211221struct vec {
1222  const char *ptr;
1223  int len;
1222   const char *ptr;
1223   int len;
12241224};
12251225
12261226// For directory listing and WevDAV support
12271227struct dir_entry {
1228  struct connection *conn;
1229  char *file_name;
1230  file_stat_t st;
1228   struct connection *conn;
1229   char *file_name;
1230   file_stat_t st;
12311231};
12321232
12331233// NOTE(lsm): this enum shoulds be in sync with the config_options.
12341234enum {
1235  ACCESS_CONTROL_LIST,
1235   ACCESS_CONTROL_LIST,
12361236#ifndef MONGOOSE_NO_FILESYSTEM
1237  ACCESS_LOG_FILE,
1237   ACCESS_LOG_FILE,
12381238#ifndef MONGOOSE_NO_AUTH
1239  AUTH_DOMAIN,
1239   AUTH_DOMAIN,
12401240#endif
12411241#ifndef MONGOOSE_NO_CGI
1242  CGI_INTERPRETER,
1243  CGI_PATTERN,
1242   CGI_INTERPRETER,
1243   CGI_PATTERN,
12441244#endif
1245  DAV_AUTH_FILE,
1246  DOCUMENT_ROOT,
1245   DAV_AUTH_FILE,
1246   DOCUMENT_ROOT,
12471247#ifndef MONGOOSE_NO_DIRECTORY_LISTING
1248  ENABLE_DIRECTORY_LISTING,
1248   ENABLE_DIRECTORY_LISTING,
12491249#endif
12501250#endif
1251  ENABLE_PROXY,
1252  EXTRA_MIME_TYPES,
1251   ENABLE_PROXY,
1252   EXTRA_MIME_TYPES,
12531253#if !defined(MONGOOSE_NO_FILESYSTEM) && !defined(MONGOOSE_NO_AUTH)
1254  GLOBAL_AUTH_FILE,
1254   GLOBAL_AUTH_FILE,
12551255#endif
12561256#ifndef MONGOOSE_NO_FILESYSTEM
1257  HIDE_FILES_PATTERN,
1258  HEXDUMP_FILE,
1259  INDEX_FILES,
1257   HIDE_FILES_PATTERN,
1258   HEXDUMP_FILE,
1259   INDEX_FILES,
12601260#endif
1261  LISTENING_PORT,
1261   LISTENING_PORT,
12621262#ifndef _WIN32
1263  RUN_AS_USER,
1263   RUN_AS_USER,
12641264#endif
12651265#ifndef MONGOOSE_NO_SSI
1266  SSI_PATTERN,
1266   SSI_PATTERN,
12671267#endif
12681268#ifdef NS_ENABLE_SSL
1269  SSL_CERTIFICATE,
1270  SSL_CA_CERTIFICATE,
1271  SSL_MITM_CERTS,
1269   SSL_CERTIFICATE,
1270   SSL_CA_CERTIFICATE,
1271   SSL_MITM_CERTS,
12721272#endif
1273  URL_REWRITES,
1274  NUM_OPTIONS
1273   URL_REWRITES,
1274   NUM_OPTIONS
12751275};
12761276
12771277static const char *static_config_options[] = {
1278  "access_control_list", NULL,
1278   "access_control_list", NULL,
12791279#ifndef MONGOOSE_NO_FILESYSTEM
1280  "access_log_file", NULL,
1280   "access_log_file", NULL,
12811281#ifndef MONGOOSE_NO_AUTH
1282  "auth_domain", "mydomain.com",
1282   "auth_domain", "mydomain.com",
12831283#endif
12841284#ifndef MONGOOSE_NO_CGI
1285  "cgi_interpreter", NULL,
1286  "cgi_pattern", DEFAULT_CGI_PATTERN,
1285   "cgi_interpreter", NULL,
1286   "cgi_pattern", DEFAULT_CGI_PATTERN,
12871287#endif
1288  "dav_auth_file", NULL,
1289  "document_root",  NULL,
1288   "dav_auth_file", NULL,
1289   "document_root",  NULL,
12901290#ifndef MONGOOSE_NO_DIRECTORY_LISTING
1291  "enable_directory_listing", "yes",
1291   "enable_directory_listing", "yes",
12921292#endif
12931293#endif
1294  "enable_proxy", NULL,
1295  "extra_mime_types", NULL,
1294   "enable_proxy", NULL,
1295   "extra_mime_types", NULL,
12961296#if !defined(MONGOOSE_NO_FILESYSTEM) && !defined(MONGOOSE_NO_AUTH)
1297  "global_auth_file", NULL,
1297   "global_auth_file", NULL,
12981298#endif
12991299#ifndef MONGOOSE_NO_FILESYSTEM
1300  "hide_files_patterns", NULL,
1301  "hexdump_file", NULL,
1302  "index_files","index.html,index.htm,index.shtml,index.cgi,index.php,index.lp",
1300   "hide_files_patterns", NULL,
1301   "hexdump_file", NULL,
1302   "index_files","index.html,index.htm,index.shtml,index.cgi,index.php,index.lp",
13031303#endif
1304  "listening_port", NULL,
1304   "listening_port", NULL,
13051305#ifndef _WIN32
1306  "run_as_user", NULL,
1306   "run_as_user", NULL,
13071307#endif
13081308#ifndef MONGOOSE_NO_SSI
1309  "ssi_pattern", "**.shtml$|**.shtm$",
1309   "ssi_pattern", "**.shtml$|**.shtm$",
13101310#endif
13111311#ifdef NS_ENABLE_SSL
1312  "ssl_certificate", NULL,
1313  "ssl_ca_certificate", NULL,
1314  "ssl_mitm_certs", NULL,
1312   "ssl_certificate", NULL,
1313   "ssl_ca_certificate", NULL,
1314   "ssl_mitm_certs", NULL,
13151315#endif
1316  "url_rewrites", NULL,
1317  NULL
1316   "url_rewrites", NULL,
1317   NULL
13181318};
13191319
13201320struct mg_server {
1321  struct ns_server ns_server;
1322  union socket_address lsa;   // Listening socket address
1323  mg_handler_t event_handler;
1324  char *config_options[NUM_OPTIONS];
1321   struct ns_server ns_server;
1322   union socket_address lsa;   // Listening socket address
1323   mg_handler_t event_handler;
1324   char *config_options[NUM_OPTIONS];
13251325};
13261326
13271327// Local endpoint representation
13281328union endpoint {
1329  int fd;                     // Opened regular local file
1330  struct ns_connection *nc;   // CGI or proxy->target connection
1329   int fd;                     // Opened regular local file
1330   struct ns_connection *nc;   // CGI or proxy->target connection
13311331};
13321332
13331333enum endpoint_type {
1334 EP_NONE, EP_FILE, EP_CGI, EP_USER, EP_PUT, EP_CLIENT, EP_PROXY
1334   EP_NONE, EP_FILE, EP_CGI, EP_USER, EP_PUT, EP_CLIENT, EP_PROXY
13351335};
13361336
13371337#define MG_HEADERS_SENT NSF_USER_1
r32760r32761
13411341#define MG_PROXY_DONT_PARSE NSF_USER_5
13421342
13431343struct connection {
1344  struct ns_connection *ns_conn;  // NOTE(lsm): main.c depends on this order
1345  struct mg_connection mg_conn;
1346  struct mg_server *server;
1347  union endpoint endpoint;
1348  enum endpoint_type endpoint_type;
1349  char *path_info;
1350  char *request;
1351  int64_t num_bytes_recv; // Total number of bytes received
1352  int64_t cl;             // Reply content length, for Range support
1353  int request_len;  // Request length, including last \r\n after last header
1344   struct ns_connection *ns_conn;  // NOTE(lsm): main.c depends on this order
1345   struct mg_connection mg_conn;
1346   struct mg_server *server;
1347   union endpoint endpoint;
1348   enum endpoint_type endpoint_type;
1349   char *path_info;
1350   char *request;
1351   int64_t num_bytes_recv; // Total number of bytes received
1352   int64_t cl;             // Reply content length, for Range support
1353   int request_len;  // Request length, including last \r\n after last header
13541354};
13551355
13561356#define MG_CONN_2_CONN(c) ((struct connection *) ((char *) (c) - \
1357  offsetof(struct connection, mg_conn)))
1357   offsetof(struct connection, mg_conn)))
13581358
13591359static void open_local_endpoint(struct connection *conn, int skip_user);
13601360static void close_local_endpoint(struct connection *conn);
13611361
13621362static const struct {
1363  const char *extension;
1364  size_t ext_len;
1365  const char *mime_type;
1363   const char *extension;
1364   size_t ext_len;
1365   const char *mime_type;
13661366} static_builtin_mime_types[] = {
1367  {".html", 5, "text/html"},
1368  {".htm", 4, "text/html"},
1369  {".shtm", 5, "text/html"},
1370  {".shtml", 6, "text/html"},
1371  {".css", 4, "text/css"},
1372  {".js",  3, "application/x-javascript"},
1373  {".ico", 4, "image/x-icon"},
1374  {".gif", 4, "image/gif"},
1375  {".jpg", 4, "image/jpeg"},
1376  {".jpeg", 5, "image/jpeg"},
1377  {".png", 4, "image/png"},
1378  {".svg", 4, "image/svg+xml"},
1379  {".txt", 4, "text/plain"},
1380  {".torrent", 8, "application/x-bittorrent"},
1381  {".wav", 4, "audio/x-wav"},
1382  {".mp3", 4, "audio/x-mp3"},
1383  {".mid", 4, "audio/mid"},
1384  {".m3u", 4, "audio/x-mpegurl"},
1385  {".ogg", 4, "application/ogg"},
1386  {".ram", 4, "audio/x-pn-realaudio"},
1387  {".xml", 4, "text/xml"},
1388  {".json",  5, "application/json"},
1389  {".xslt", 5, "application/xml"},
1390  {".xsl", 4, "application/xml"},
1391  {".ra",  3, "audio/x-pn-realaudio"},
1392  {".doc", 4, "application/msword"},
1393  {".exe", 4, "application/octet-stream"},
1394  {".zip", 4, "application/x-zip-compressed"},
1395  {".xls", 4, "application/excel"},
1396  {".tgz", 4, "application/x-tar-gz"},
1397  {".tar", 4, "application/x-tar"},
1398  {".gz",  3, "application/x-gunzip"},
1399  {".arj", 4, "application/x-arj-compressed"},
1400  {".rar", 4, "application/x-rar-compressed"},
1401  {".rtf", 4, "application/rtf"},
1402  {".pdf", 4, "application/pdf"},
1403  {".swf", 4, "application/x-shockwave-flash"},
1404  {".mpg", 4, "video/mpeg"},
1405  {".webm", 5, "video/webm"},
1406  {".mpeg", 5, "video/mpeg"},
1407  {".mov", 4, "video/quicktime"},
1408  {".mp4", 4, "video/mp4"},
1409  {".m4v", 4, "video/x-m4v"},
1410  {".asf", 4, "video/x-ms-asf"},
1411  {".avi", 4, "video/x-msvideo"},
1412  {".bmp", 4, "image/bmp"},
1413  {".ttf", 4, "application/x-font-ttf"},
1414  {NULL,  0, NULL}
1367   {".html", 5, "text/html"},
1368   {".htm", 4, "text/html"},
1369   {".shtm", 5, "text/html"},
1370   {".shtml", 6, "text/html"},
1371   {".css", 4, "text/css"},
1372   {".js",  3, "application/x-javascript"},
1373   {".ico", 4, "image/x-icon"},
1374   {".gif", 4, "image/gif"},
1375   {".jpg", 4, "image/jpeg"},
1376   {".jpeg", 5, "image/jpeg"},
1377   {".png", 4, "image/png"},
1378   {".svg", 4, "image/svg+xml"},
1379   {".txt", 4, "text/plain"},
1380   {".torrent", 8, "application/x-bittorrent"},
1381   {".wav", 4, "audio/x-wav"},
1382   {".mp3", 4, "audio/x-mp3"},
1383   {".mid", 4, "audio/mid"},
1384   {".m3u", 4, "audio/x-mpegurl"},
1385   {".ogg", 4, "application/ogg"},
1386   {".ram", 4, "audio/x-pn-realaudio"},
1387   {".xml", 4, "text/xml"},
1388   {".json",  5, "application/json"},
1389   {".xslt", 5, "application/xml"},
1390   {".xsl", 4, "application/xml"},
1391   {".ra",  3, "audio/x-pn-realaudio"},
1392   {".doc", 4, "application/msword"},
1393   {".exe", 4, "application/octet-stream"},
1394   {".zip", 4, "application/x-zip-compressed"},
1395   {".xls", 4, "application/excel"},
1396   {".tgz", 4, "application/x-tar-gz"},
1397   {".tar", 4, "application/x-tar"},
1398   {".gz",  3, "application/x-gunzip"},
1399   {".arj", 4, "application/x-arj-compressed"},
1400   {".rar", 4, "application/x-rar-compressed"},
1401   {".rtf", 4, "application/rtf"},
1402   {".pdf", 4, "application/pdf"},
1403   {".swf", 4, "application/x-shockwave-flash"},
1404   {".mpg", 4, "video/mpeg"},
1405   {".webm", 5, "video/webm"},
1406   {".mpeg", 5, "video/mpeg"},
1407   {".mov", 4, "video/quicktime"},
1408   {".mp4", 4, "video/mp4"},
1409   {".m4v", 4, "video/x-m4v"},
1410   {".asf", 4, "video/x-ms-asf"},
1411   {".avi", 4, "video/x-msvideo"},
1412   {".bmp", 4, "image/bmp"},
1413   {".ttf", 4, "application/x-font-ttf"},
1414   {NULL,  0, NULL}
14151415};
14161416
14171417#ifndef MONGOOSE_NO_THREADS
14181418void *mg_start_thread(void *(*f)(void *), void *p) {
1419  return ns_start_thread(f, p);
1419   return ns_start_thread(f, p);
14201420}
14211421#endif  // MONGOOSE_NO_THREADS
14221422
r32760r32761
14241424// Encode 'path' which is assumed UTF-8 string, into UNICODE string.
14251425// wbuf and wbuf_len is a target buffer and its length.
14261426static void to_wchar(const char *path, wchar_t *wbuf, size_t wbuf_len) {
1427  char buf[MAX_PATH_SIZE * 2], buf2[MAX_PATH_SIZE * 2], *p;
1427   char buf[MAX_PATH_SIZE * 2], buf2[MAX_PATH_SIZE * 2], *p;
14281428
1429  strncpy(buf, path, sizeof(buf));
1430  buf[sizeof(buf) - 1] = '\0';
1429   strncpy(buf, path, sizeof(buf));
1430   buf[sizeof(buf) - 1] = '\0';
14311431
1432  // Trim trailing slashes. Leave backslash for paths like "X:\"
1433  p = buf + strlen(buf) - 1;
1434  while (p > buf && p[-1] != ':' && (p[0] == '\\' || p[0] == '/')) *p-- = '\0';
1432   // Trim trailing slashes. Leave backslash for paths like "X:\"
1433   p = buf + strlen(buf) - 1;
1434   while (p > buf && p[-1] != ':' && (p[0] == '\\' || p[0] == '/')) *p-- = '\0';
14351435
1436  // Convert to Unicode and back. If doubly-converted string does not
1437  // match the original, something is fishy, reject.
1438  memset(wbuf, 0, wbuf_len * sizeof(wchar_t));
1439  MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, (int) wbuf_len);
1440  WideCharToMultiByte(CP_UTF8, 0, wbuf, (int) wbuf_len, buf2, sizeof(buf2),
1441                      NULL, NULL);
1442  if (strcmp(buf, buf2) != 0) {
1443    wbuf[0] = L'\0';
1444  }
1436   // Convert to Unicode and back. If doubly-converted string does not
1437   // match the original, something is fishy, reject.
1438   memset(wbuf, 0, wbuf_len * sizeof(wchar_t));
1439   MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, (int) wbuf_len);
1440   WideCharToMultiByte(CP_UTF8, 0, wbuf, (int) wbuf_len, buf2, sizeof(buf2),
1441                  NULL, NULL);
1442   if (strcmp(buf, buf2) != 0) {
1443   wbuf[0] = L'\0';
1444   }
14451445}
14461446
14471447static int mg_stat(const char *path, file_stat_t *st) {
1448  wchar_t wpath[MAX_PATH_SIZE];
1449  to_wchar(path, wpath, ARRAY_SIZE(wpath));
1450  DBG(("[%ls] -> %d", wpath, _wstati64(wpath, st)));
1451  return _wstati64(wpath, st);
1448   wchar_t wpath[MAX_PATH_SIZE];
1449   to_wchar(path, wpath, ARRAY_SIZE(wpath));
1450   DBG(("[%ls] -> %d", wpath, _wstati64(wpath, st)));
1451   return _wstati64(wpath, st);
14521452}
14531453
14541454static FILE *mg_fopen(const char *path, const char *mode) {
1455  wchar_t wpath[MAX_PATH_SIZE], wmode[10];
1456  to_wchar(path, wpath, ARRAY_SIZE(wpath));
1457  to_wchar(mode, wmode, ARRAY_SIZE(wmode));
1458  return _wfopen(wpath, wmode);
1455   wchar_t wpath[MAX_PATH_SIZE], wmode[10];
1456   to_wchar(path, wpath, ARRAY_SIZE(wpath));
1457   to_wchar(mode, wmode, ARRAY_SIZE(wmode));
1458   return _wfopen(wpath, wmode);
14591459}
14601460
14611461static int mg_open(const char *path, int flag) {
1462  wchar_t wpath[MAX_PATH_SIZE];
1463  to_wchar(path, wpath, ARRAY_SIZE(wpath));
1464  return _wopen(wpath, flag);
1462   wchar_t wpath[MAX_PATH_SIZE];
1463   to_wchar(path, wpath, ARRAY_SIZE(wpath));
1464   return _wopen(wpath, flag);
14651465}
14661466#endif // _WIN32 && !MONGOOSE_NO_FILESYSTEM
14671467
r32760r32761
14721472// vector is initialized to point to the "y" part, and val vector length
14731473// is adjusted to point only to "x".
14741474static const char *next_option(const char *list, struct vec *val,
1475                               struct vec *eq_val) {
1476  if (list == NULL || *list == '\0') {
1477    // End of the list
1478    list = NULL;
1479  } else {
1480    val->ptr = list;
1481    if ((list = strchr(val->ptr, ',')) != NULL) {
1482      // Comma found. Store length and shift the list ptr
1483      val->len = list - val->ptr;
1484      list++;
1485    } else {
1486      // This value is the last one
1487      list = val->ptr + strlen(val->ptr);
1488      val->len = list - val->ptr;
1489    }
1475                        struct vec *eq_val) {
1476   if (list == NULL || *list == '\0') {
1477   // End of the list
1478   list = NULL;
1479   } else {
1480   val->ptr = list;
1481   if ((list = strchr(val->ptr, ',')) != NULL) {
1482      // Comma found. Store length and shift the list ptr
1483      val->len = list - val->ptr;
1484      list++;
1485   } else {
1486      // This value is the last one
1487      list = val->ptr + strlen(val->ptr);
1488      val->len = list - val->ptr;
1489   }
14901490
1491    if (eq_val != NULL) {
1492      // Value has form "x=y", adjust pointers and lengths
1493      // so that val points to "x", and eq_val points to "y".
1494      eq_val->len = 0;
1495      eq_val->ptr = (const char *) memchr(val->ptr, '=', val->len);
1496      if (eq_val->ptr != NULL) {
1497        eq_val->ptr++;  // Skip over '=' character
1498        eq_val->len = val->ptr + val->len - eq_val->ptr;
1499        val->len = (eq_val->ptr - val->ptr) - 1;
1500      }
1501    }
1502  }
1491   if (eq_val != NULL) {
1492      // Value has form "x=y", adjust pointers and lengths
1493      // so that val points to "x", and eq_val points to "y".
1494      eq_val->len = 0;
1495      eq_val->ptr = (const char *) memchr(val->ptr, '=', val->len);
1496      if (eq_val->ptr != NULL) {
1497      eq_val->ptr++;  // Skip over '=' character
1498      eq_val->len = val->ptr + val->len - eq_val->ptr;
1499      val->len = (eq_val->ptr - val->ptr) - 1;
1500      }
1501   }
1502   }
15031503
1504  return list;
1504   return list;
15051505}
15061506
15071507// Like snprintf(), but never returns negative value, or a value
15081508// that is larger than a supplied buffer.
15091509static int mg_vsnprintf(char *buf, size_t buflen, const char *fmt, va_list ap) {
1510  int n;
1511  if (buflen < 1) return 0;
1512  n = vsnprintf(buf, buflen, fmt, ap);
1513  if (n < 0) {
1514    n = 0;
1515  } else if (n >= (int) buflen) {
1516    n = (int) buflen - 1;
1517  }
1518  buf[n] = '\0';
1519  return n;
1510   int n;
1511   if (buflen < 1) return 0;
1512   n = vsnprintf(buf, buflen, fmt, ap);
1513   if (n < 0) {
1514   n = 0;
1515   } else if (n >= (int) buflen) {
1516   n = (int) buflen - 1;
1517   }
1518   buf[n] = '\0';
1519   return n;
15201520}
15211521
15221522static int mg_snprintf(char *buf, size_t buflen, const char *fmt, ...) {
1523  va_list ap;
1524  int n;
1525  va_start(ap, fmt);
1526  n = mg_vsnprintf(buf, buflen, fmt, ap);
1527  va_end(ap);
1528  return n;
1523   va_list ap;
1524   int n;
1525   va_start(ap, fmt);
1526   n = mg_vsnprintf(buf, buflen, fmt, ap);
1527   va_end(ap);
1528   return n;
15291529}
15301530
15311531// Check whether full request is buffered. Return:
r32760r32761
15331533//    0  if request is not yet fully buffered
15341534//   >0  actual request length, including last \r\n\r\n
15351535static int get_request_len(const char *s, int buf_len) {
1536  const unsigned char *buf = (unsigned char *) s;
1537  int i;
1536   const unsigned char *buf = (unsigned char *) s;
1537   int i;
15381538
1539  for (i = 0; i < buf_len; i++) {
1540    // Control characters are not allowed but >=128 are.
1541    // Abort scan as soon as one malformed character is found.
1542    if (!isprint(buf[i]) && buf[i] != '\r' && buf[i] != '\n' && buf[i] < 128) {
1543      return -1;
1544    } else if (buf[i] == '\n' && i + 1 < buf_len && buf[i + 1] == '\n') {
1545      return i + 2;
1546    } else if (buf[i] == '\n' && i + 2 < buf_len && buf[i + 1] == '\r' &&
1547               buf[i + 2] == '\n') {
1548      return i + 3;
1549    }
1550  }
1539   for (i = 0; i < buf_len; i++) {
1540   // Control characters are not allowed but >=128 are.
1541   // Abort scan as soon as one malformed character is found.
1542   if (!isprint(buf[i]) && buf[i] != '\r' && buf[i] != '\n' && buf[i] < 128) {
1543      return -1;
1544   } else if (buf[i] == '\n' && i + 1 < buf_len && buf[i + 1] == '\n') {
1545      return i + 2;
1546   } else if (buf[i] == '\n' && i + 2 < buf_len && buf[i + 1] == '\r' &&
1547            buf[i + 2] == '\n') {
1548      return i + 3;
1549   }
1550   }
15511551
1552  return 0;
1552   return 0;
15531553}
15541554
15551555// Skip the characters until one of the delimiters characters found.
15561556// 0-terminate resulting word. Skip the rest of the delimiters if any.
15571557// Advance pointer to buffer to the next word. Return found 0-terminated word.
15581558static char *skip(char **buf, const char *delimiters) {
1559  char *p, *begin_word, *end_word, *end_delimiters;
1559   char *p, *begin_word, *end_word, *end_delimiters;
15601560
1561  begin_word = *buf;
1562  end_word = begin_word + strcspn(begin_word, delimiters);
1563  end_delimiters = end_word + strspn(end_word, delimiters);
1561   begin_word = *buf;
1562   end_word = begin_word + strcspn(begin_word, delimiters);
1563   end_delimiters = end_word + strspn(end_word, delimiters);
15641564
1565  for (p = end_word; p < end_delimiters; p++) {
1566    *p = '\0';
1567  }
1565   for (p = end_word; p < end_delimiters; p++) {
1566   *p = '\0';
1567   }
15681568
1569  *buf = end_delimiters;
1569   *buf = end_delimiters;
15701570
1571  return begin_word;
1571   return begin_word;
15721572}
15731573
15741574// Parse HTTP headers from the given buffer, advance buffer to the point
15751575// where parsing stopped.
15761576static void parse_http_headers(char **buf, struct mg_connection *ri) {
1577  size_t i;
1577   size_t i;
15781578
1579  for (i = 0; i < ARRAY_SIZE(ri->http_headers); i++) {
1580    ri->http_headers[i].name = skip(buf, ": ");
1581    ri->http_headers[i].value = skip(buf, "\r\n");
1582    if (ri->http_headers[i].name[0] == '\0')
1583      break;
1584    ri->num_headers = i + 1;
1585  }
1579   for (i = 0; i < ARRAY_SIZE(ri->http_headers); i++) {
1580   ri->http_headers[i].name = skip(buf, ": ");
1581   ri->http_headers[i].value = skip(buf, "\r\n");
1582   if (ri->http_headers[i].name[0] == '\0')
1583      break;
1584   ri->num_headers = i + 1;
1585   }
15861586}
15871587
15881588static const char *status_code_to_str(int status_code) {
1589  switch (status_code) {
1589   switch (status_code) {
1590   case 100: return "Continue";
1591   case 101: return "Switching Protocols";
1592   case 102: return "Processing";
15901593
1591    case 100: return "Continue";
1592    case 101: return "Switching Protocols";
1593    case 102: return "Processing";
1594   case 200: return "OK";
1595   case 201: return "Created";
1596   case 202: return "Accepted";
1597   case 203: return "Non-Authoritative Information";
1598   case 204: return "No Content";
1599   case 205: return "Reset Content";
1600   case 206: return "Partial Content";
1601   case 207: return "Multi-Status";
1602   case 208: return "Already Reported";
1603   case 226: return "IM Used";
15941604
1595    case 200: return "OK";
1596    case 201: return "Created";
1597    case 202: return "Accepted";
1598    case 203: return "Non-Authoritative Information";
1599    case 204: return "No Content";
1600    case 205: return "Reset Content";
1601    case 206: return "Partial Content";
1602    case 207: return "Multi-Status";
1603    case 208: return "Already Reported";
1604    case 226: return "IM Used";
1605   case 300: return "Multiple Choices";
1606   case 301: return "Moved Permanently";
1607   case 302: return "Found";
1608   case 303: return "See Other";
1609   case 304: return "Not Modified";
1610   case 305: return "Use Proxy";
1611   case 306: return "Switch Proxy";
1612   case 307: return "Temporary Redirect";
1613   case 308: return "Permanent Redirect";
16051614
1606    case 300: return "Multiple Choices";
1607    case 301: return "Moved Permanently";
1608    case 302: return "Found";
1609    case 303: return "See Other";
1610    case 304: return "Not Modified";
1611    case 305: return "Use Proxy";
1612    case 306: return "Switch Proxy";
1613    case 307: return "Temporary Redirect";
1614    case 308: return "Permanent Redirect";
1615   case 400: return "Bad Request";
1616   case 401: return "Unauthorized";
1617   case 402: return "Payment Required";
1618   case 403: return "Forbidden";
1619   case 404: return "Not Found";
1620   case 405: return "Method Not Allowed";
1621   case 406: return "Not Acceptable";
1622   case 407: return "Proxy Authentication Required";
1623   case 408: return "Request Timeout";
1624   case 409: return "Conflict";
1625   case 410: return "Gone";
1626   case 411: return "Length Required";
1627   case 412: return "Precondition Failed";
1628   case 413: return "Payload Too Large";
1629   case 414: return "URI Too Long";
1630   case 415: return "Unsupported Media Type";
1631   case 416: return "Requested Range Not Satisfiable";
1632   case 417: return "Expectation Failed";
1633   case 418: return "I\'m a teapot";
1634   case 422: return "Unprocessable Entity";
1635   case 423: return "Locked";
1636   case 424: return "Failed Dependency";
1637   case 426: return "Upgrade Required";
1638   case 428: return "Precondition Required";
1639   case 429: return "Too Many Requests";
1640   case 431: return "Request Header Fields Too Large";
1641   case 451: return "Unavailable For Legal Reasons";
16151642
1616    case 400: return "Bad Request";
1617    case 401: return "Unauthorized";
1618    case 402: return "Payment Required";
1619    case 403: return "Forbidden";
1620    case 404: return "Not Found";
1621    case 405: return "Method Not Allowed";
1622    case 406: return "Not Acceptable";
1623    case 407: return "Proxy Authentication Required";
1624    case 408: return "Request Timeout";
1625    case 409: return "Conflict";
1626    case 410: return "Gone";
1627    case 411: return "Length Required";
1628    case 412: return "Precondition Failed";
1629    case 413: return "Payload Too Large";
1630    case 414: return "URI Too Long";
1631    case 415: return "Unsupported Media Type";
1632    case 416: return "Requested Range Not Satisfiable";
1633    case 417: return "Expectation Failed";
1634    case 418: return "I\'m a teapot";
1635    case 422: return "Unprocessable Entity";
1636    case 423: return "Locked";
1637    case 424: return "Failed Dependency";
1638    case 426: return "Upgrade Required";
1639    case 428: return "Precondition Required";
1640    case 429: return "Too Many Requests";
1641    case 431: return "Request Header Fields Too Large";
1642    case 451: return "Unavailable For Legal Reasons";
1643   case 500: return "Internal Server Error";
1644   case 501: return "Not Implemented";
1645   case 502: return "Bad Gateway";
1646   case 503: return "Service Unavailable";
1647   case 504: return "Gateway Timeout";
1648   case 505: return "HTTP Version Not Supported";
1649   case 506: return "Variant Also Negotiates";
1650   case 507: return "Insufficient Storage";
1651   case 508: return "Loop Detected";
1652   case 510: return "Not Extended";
1653   case 511: return "Network Authentication Required";
16431654
1644    case 500: return "Internal Server Error";
1645    case 501: return "Not Implemented";
1646    case 502: return "Bad Gateway";
1647    case 503: return "Service Unavailable";
1648    case 504: return "Gateway Timeout";
1649    case 505: return "HTTP Version Not Supported";
1650    case 506: return "Variant Also Negotiates";
1651    case 507: return "Insufficient Storage";
1652    case 508: return "Loop Detected";
1653    case 510: return "Not Extended";
1654    case 511: return "Network Authentication Required";
1655
1656    default:  return "Server Error";
1657  }
1655   default:  return "Server Error";
1656   }
16581657}
16591658
16601659static int call_user(struct connection *conn, enum mg_event ev) {
1661  return conn != NULL && conn->server != NULL &&
1662    conn->server->event_handler != NULL ?
1663    conn->server->event_handler(&conn->mg_conn, ev) : MG_FALSE;
1660   return conn != NULL && conn->server != NULL &&
1661   conn->server->event_handler != NULL ?
1662   conn->server->event_handler(&conn->mg_conn, ev) : MG_FALSE;
16641663}
16651664
16661665static void send_http_error(struct connection *conn, int code,
1667                            const char *fmt, ...) {
1668  const char *message = status_code_to_str(code);
1669  const char *rewrites = conn->server->config_options[URL_REWRITES];
1670  char headers[200], body[200];
1671  struct vec a, b;
1672  va_list ap;
1673  int body_len, headers_len, match_code;
1666                     const char *fmt, ...) {
1667   const char *message = status_code_to_str(code);
1668   const char *rewrites = conn->server->config_options[URL_REWRITES];
1669   char headers[200], body[200];
1670   struct vec a, b;
1671   va_list ap;
1672   int body_len, headers_len, match_code;
16741673
1675  conn->mg_conn.status_code = code;
1674   conn->mg_conn.status_code = code;
16761675
1677  // Invoke error handler if it is set
1678  if (call_user(conn, MG_HTTP_ERROR) == MG_TRUE) {
1679    close_local_endpoint(conn);
1680    return;
1681  }
1676   // Invoke error handler if it is set
1677   if (call_user(conn, MG_HTTP_ERROR) == MG_TRUE) {
1678   close_local_endpoint(conn);
1679   return;
1680   }
16821681
1683  // Handle error code rewrites
1684  while ((rewrites = next_option(rewrites, &a, &b)) != NULL) {
1685    if ((match_code = atoi(a.ptr)) > 0 && match_code == code) {
1686      struct mg_connection *c = &conn->mg_conn;
1687      c->status_code = 302;
1688      mg_printf(c, "HTTP/1.1 %d Moved\r\n"
1689                "Location: %.*s?code=%d&orig_uri=%s&query_string=%s\r\n\r\n",
1690                c->status_code, b.len, b.ptr, code, c->uri,
1691                c->query_string == NULL ? "" : c->query_string);
1692      close_local_endpoint(conn);
1693      return;
1694    }
1695  }
1682   // Handle error code rewrites
1683   while ((rewrites = next_option(rewrites, &a, &b)) != NULL) {
1684   if ((match_code = atoi(a.ptr)) > 0 && match_code == code) {
1685      struct mg_connection *c = &conn->mg_conn;
1686      c->status_code = 302;
1687      mg_printf(c, "HTTP/1.1 %d Moved\r\n"
1688            "Location: %.*s?code=%d&orig_uri=%s&query_string=%s\r\n\r\n",
1689            c->status_code, b.len, b.ptr, code, c->uri,
1690            c->query_string == NULL ? "" : c->query_string);
1691      close_local_endpoint(conn);
1692      return;
1693   }
1694   }
16961695
1697  body_len = mg_snprintf(body, sizeof(body), "%d %s\n", code, message);
1698  if (fmt != NULL) {
1699    va_start(ap, fmt);
1700    body_len += mg_vsnprintf(body + body_len, sizeof(body) - body_len, fmt, ap);
1701    va_end(ap);
1702  }
1703  if ((code >= 300 && code <= 399) || code == 204) {
1704    // 3xx errors do not have body
1705    body_len = 0;
1706  }
1707  headers_len = mg_snprintf(headers, sizeof(headers),
1708                            "HTTP/1.1 %d %s\r\nContent-Length: %d\r\n"
1709                            "Content-Type: text/plain\r\n\r\n",
1710                            code, message, body_len);
1711  ns_send(conn->ns_conn, headers, headers_len);
1712  ns_send(conn->ns_conn, body, body_len);
1713  close_local_endpoint(conn);  // This will write to the log file
1696   body_len = mg_snprintf(body, sizeof(body), "%d %s\n", code, message);
1697   if (fmt != NULL) {
1698   va_start(ap, fmt);
1699   body_len += mg_vsnprintf(body + body_len, sizeof(body) - body_len, fmt, ap);
1700   va_end(ap);
1701   }
1702   if ((code >= 300 && code <= 399) || code == 204) {
1703   // 3xx errors do not have body
1704   body_len = 0;
1705   }
1706   headers_len = mg_snprintf(headers, sizeof(headers),
1707                     "HTTP/1.1 %d %s\r\nContent-Length: %d\r\n"
1708                     "Content-Type: text/plain\r\n\r\n",
1709                     code, message, body_len);
1710   ns_send(conn->ns_conn, headers, headers_len);
1711   ns_send(conn->ns_conn, body, body_len);
1712   close_local_endpoint(conn);  // This will write to the log file
17141713}
17151714
17161715static void write_chunk(struct connection *conn, const char *buf, int len) {
1717  char chunk_size[50];
1718  int n = mg_snprintf(chunk_size, sizeof(chunk_size), "%X\r\n", len);
1719  ns_send(conn->ns_conn, chunk_size, n);
1720  ns_send(conn->ns_conn, buf, len);
1721  ns_send(conn->ns_conn, "\r\n", 2);
1716   char chunk_size[50];
1717   int n = mg_snprintf(chunk_size, sizeof(chunk_size), "%X\r\n", len);
1718   ns_send(conn->ns_conn, chunk_size, n);
1719   ns_send(conn->ns_conn, buf, len);
1720   ns_send(conn->ns_conn, "\r\n", 2);
17221721}
17231722
17241723size_t mg_printf(struct mg_connection *conn, const char *fmt, ...) {
1725  struct connection *c = MG_CONN_2_CONN(conn);
1726  va_list ap;
1724   struct connection *c = MG_CONN_2_CONN(conn);
1725   va_list ap;
17271726
1728  va_start(ap, fmt);
1729  ns_vprintf(c->ns_conn, fmt, ap);
1730  va_end(ap);
1727   va_start(ap, fmt);
1728   ns_vprintf(c->ns_conn, fmt, ap);
1729   va_end(ap);
17311730
1732  return c->ns_conn->send_iobuf.len;
1731   return c->ns_conn->send_iobuf.len;
17331732}
17341733
17351734static void ns_forward(struct ns_connection *from, struct ns_connection *to) {
1736  DBG(("%p -> %p %lu bytes", from, to, (unsigned long)from->recv_iobuf.len));
1737  ns_send(to, from->recv_iobuf.buf, from->recv_iobuf.len);
1738  iobuf_remove(&from->recv_iobuf, from->recv_iobuf.len);
1735   DBG(("%p -> %p %lu bytes", from, to, (unsigned long)from->recv_iobuf.len));
1736   ns_send(to, from->recv_iobuf.buf, from->recv_iobuf.len);
1737   iobuf_remove(&from->recv_iobuf, from->recv_iobuf.len);
17391738}
17401739
17411740#ifndef MONGOOSE_NO_CGI
17421741#ifdef _WIN32
17431742struct threadparam {
1744  sock_t s;
1745  HANDLE hPipe;
1743   sock_t s;
1744   HANDLE hPipe;
17461745};
17471746
17481747static int wait_until_ready(sock_t sock, int for_read) {
1749  fd_set set;
1750  FD_ZERO(&set);
1751  FD_SET(sock, &set);
1752  select(sock + 1, for_read ? &set : 0, for_read ? 0 : &set, 0, 0);
1753  return 1;
1748   fd_set set;
1749   FD_ZERO(&set);
1750   FD_SET(sock, &set);
1751   select(sock + 1, for_read ? &set : 0, for_read ? 0 : &set, 0, 0);
1752   return 1;
17541753}
17551754
17561755static void *push_to_stdin(void *arg) {
1757  struct threadparam *tp = (struct threadparam *)arg;
1758  int n, sent, stop = 0;
1759  DWORD k;
1760  char buf[IOBUF_SIZE];
1756   struct threadparam *tp = (struct threadparam *)arg;
1757   int n, sent, stop = 0;
1758   DWORD k;
1759   char buf[IOBUF_SIZE];
17611760
1762  while (!stop && wait_until_ready(tp->s, 1) &&
1763         (n = recv(tp->s, buf, sizeof(buf), 0)) > 0) {
1764    if (n == -1 && GetLastError() == WSAEWOULDBLOCK) continue;
1765    for (sent = 0; !stop && sent < n; sent += k) {
1766      if (!WriteFile(tp->hPipe, buf + sent, n - sent, &k, 0)) stop = 1;
1767    }
1768  }
1769  DBG(("%s", "FORWARED EVERYTHING TO CGI"));
1770  CloseHandle(tp->hPipe);
1771  free(tp);
1772  _endthread();
1773  return NULL;
1761   while (!stop && wait_until_ready(tp->s, 1) &&
1762         (n = recv(tp->s, buf, sizeof(buf), 0)) > 0) {
1763   if (n == -1 && GetLastError() == WSAEWOULDBLOCK) continue;
1764   for (sent = 0; !stop && sent < n; sent += k) {
1765      if (!WriteFile(tp->hPipe, buf + sent, n - sent, &k, 0)) stop = 1;
1766   }
1767   }
1768   DBG(("%s", "FORWARED EVERYTHING TO CGI"));
1769   CloseHandle(tp->hPipe);
1770   free(tp);
1771   _endthread();
1772   return NULL;
17741773}
17751774
17761775static void *pull_from_stdout(void *arg) {
1777  struct threadparam *tp = (struct threadparam *)arg;
1778  int k = 0, stop = 0;
1779  DWORD n, sent;
1780  char buf[IOBUF_SIZE];
1776   struct threadparam *tp = (struct threadparam *)arg;
1777   int k = 0, stop = 0;
1778   DWORD n, sent;
1779   char buf[IOBUF_SIZE];
17811780
1782  while (!stop && ReadFile(tp->hPipe, buf, sizeof(buf), &n, NULL)) {
1783    for (sent = 0; !stop && sent < n; sent += k) {
1784      if (wait_until_ready(tp->s, 0) &&
1785          (k = send(tp->s, buf + sent, n - sent, 0)) <= 0) stop = 1;
1786    }
1787  }
1788  DBG(("%s", "EOF FROM CGI"));
1789  CloseHandle(tp->hPipe);
1790  shutdown(tp->s, 2);  // Without this, IO thread may get truncated data
1791  closesocket(tp->s);
1792  free(tp);
1793  _endthread();
1794  return NULL;
1781   while (!stop && ReadFile(tp->hPipe, buf, sizeof(buf), &n, NULL)) {
1782   for (sent = 0; !stop && sent < n; sent += k) {
1783      if (wait_until_ready(tp->s, 0) &&
1784         (k = send(tp->s, buf + sent, n - sent, 0)) <= 0) stop = 1;
1785   }
1786   }
1787   DBG(("%s", "EOF FROM CGI"));
1788   CloseHandle(tp->hPipe);
1789   shutdown(tp->s, 2);  // Without this, IO thread may get truncated data
1790   closesocket(tp->s);
1791   free(tp);
1792   _endthread();
1793   return NULL;
17951794}
17961795
17971796static void spawn_stdio_thread(sock_t sock, HANDLE hPipe,
1798                               void *(*func)(void *)) {
1799  struct threadparam *tp = (struct threadparam *)malloc(sizeof(*tp));
1800  if (tp != NULL) {
1801    tp->s = sock;
1802    tp->hPipe = hPipe;
1803    mg_start_thread(func, tp);
1804  }
1797                        void *(*func)(void *)) {
1798   struct threadparam *tp = (struct threadparam *)malloc(sizeof(*tp));
1799   if (tp != NULL) {
1800   tp->s = sock;
1801   tp->hPipe = hPipe;
1802   mg_start_thread(func, tp);
1803   }
18051804}
18061805
18071806static void abs_path(const char *utf8_path, char *abs_path, size_t len) {
1808  wchar_t buf[MAX_PATH_SIZE], buf2[MAX_PATH_SIZE];
1809  to_wchar(utf8_path, buf, ARRAY_SIZE(buf));
1810  GetFullPathNameW(buf, ARRAY_SIZE(buf2), buf2, NULL);
1811  WideCharToMultiByte(CP_UTF8, 0, buf2, wcslen(buf2) + 1, abs_path, len, 0, 0);
1807   wchar_t buf[MAX_PATH_SIZE], buf2[MAX_PATH_SIZE];
1808   to_wchar(utf8_path, buf, ARRAY_SIZE(buf));
1809   GetFullPathNameW(buf, ARRAY_SIZE(buf2), buf2, NULL);
1810   WideCharToMultiByte(CP_UTF8, 0, buf2, wcslen(buf2) + 1, abs_path, len, 0, 0);
18121811}
18131812
18141813static process_id_t start_process(char *interp, const char *cmd,
1815                                  const char *env, const char *envp[],
1816                                  const char *dir, sock_t sock) {
1817  STARTUPINFOW si;
1818  PROCESS_INFORMATION pi;
1819  HANDLE a[2], b[2], me = GetCurrentProcess();
1820  wchar_t wcmd[MAX_PATH_SIZE], full_dir[MAX_PATH_SIZE];
1821  char buf[MAX_PATH_SIZE], buf4[MAX_PATH_SIZE], buf5[MAX_PATH_SIZE],
1822       cmdline[MAX_PATH_SIZE], *p;
1823  DWORD flags = DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS;
1824  FILE *fp;
1814                           const char *env, const char *envp[],
1815                           const char *dir, sock_t sock) {
1816   STARTUPINFOW si;
1817   PROCESS_INFORMATION pi;
1818   HANDLE a[2], b[2], me = GetCurrentProcess();
1819   wchar_t wcmd[MAX_PATH_SIZE], full_dir[MAX_PATH_SIZE];
1820   char buf[MAX_PATH_SIZE], buf4[MAX_PATH_SIZE], buf5[MAX_PATH_SIZE],
1821      cmdline[MAX_PATH_SIZE], *p;
1822   DWORD flags = DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS;
1823   FILE *fp;
18251824
1826  memset(&si, 0, sizeof(si));
1827  memset(&pi, 0, sizeof(pi));
1825   memset(&si, 0, sizeof(si));
1826   memset(&pi, 0, sizeof(pi));
18281827
1829  si.cb = sizeof(si);
1830  si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
1831  si.wShowWindow = SW_HIDE;
1832  si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
1828   si.cb = sizeof(si);
1829   si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
1830   si.wShowWindow = SW_HIDE;
1831   si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
18331832
1834  CreatePipe(&a[0], &a[1], NULL, 0);
1835  CreatePipe(&b[0], &b[1], NULL, 0);
1836  DuplicateHandle(me, a[0], me, &si.hStdInput, 0, TRUE, flags);
1837  DuplicateHandle(me, b[1], me, &si.hStdOutput, 0, TRUE, flags);
1833   CreatePipe(&a[0], &a[1], NULL, 0);
1834   CreatePipe(&b[0], &b[1], NULL, 0);
1835   DuplicateHandle(me, a[0], me, &si.hStdInput, 0, TRUE, flags);
1836   DuplicateHandle(me, b[1], me, &si.hStdOutput, 0, TRUE, flags);
18381837
1839  if (interp == NULL && (fp = fopen(cmd, "r")) != NULL) {
1840    buf[0] = buf[1] = '\0';
1841    fgets(buf, sizeof(buf), fp);
1842    buf[sizeof(buf) - 1] = '\0';
1843    if (buf[0] == '#' && buf[1] == '!') {
1844      interp = buf + 2;
1845      for (p = interp + strlen(interp);
1846           isspace(* (uint8_t *) p) && p > interp; p--) *p = '\0';
1847    }
1848    fclose(fp);
1849  }
1838   if (interp == NULL && (fp = fopen(cmd, "r")) != NULL) {
1839   buf[0] = buf[1] = '\0';
1840   fgets(buf, sizeof(buf), fp);
1841   buf[sizeof(buf) - 1] = '\0';
1842   if (buf[0] == '#' && buf[1] == '!') {
1843      interp = buf + 2;
1844      for (p = interp + strlen(interp);
1845         isspace(* (uint8_t *) p) && p > interp; p--) *p = '\0';
1846   }
1847   fclose(fp);
1848   }
18501849
1851  if (interp != NULL) {
1852    abs_path(interp, buf4, ARRAY_SIZE(buf4));
1853    interp = buf4;
1854  }
1855  abs_path(dir, buf5, ARRAY_SIZE(buf5));
1856  to_wchar(dir, full_dir, ARRAY_SIZE(full_dir));
1857  mg_snprintf(cmdline, sizeof(cmdline), "%s%s\"%s\"",
1858              interp ? interp : "", interp ? " " : "", cmd);
1859  to_wchar(cmdline, wcmd, ARRAY_SIZE(wcmd));
1850   if (interp != NULL) {
1851   abs_path(interp, buf4, ARRAY_SIZE(buf4));
1852   interp = buf4;
1853   }
1854   abs_path(dir, buf5, ARRAY_SIZE(buf5));
1855   to_wchar(dir, full_dir, ARRAY_SIZE(full_dir));
1856   mg_snprintf(cmdline, sizeof(cmdline), "%s%s\"%s\"",
1857            interp ? interp : "", interp ? " " : "", cmd);
1858   to_wchar(cmdline, wcmd, ARRAY_SIZE(wcmd));
18601859
1861  if (CreateProcessW(NULL, wcmd, NULL, NULL, TRUE, CREATE_NEW_PROCESS_GROUP,
1862                     (void *) env, full_dir, &si, &pi) != 0) {
1863    spawn_stdio_thread(sock, a[1], push_to_stdin);
1864    spawn_stdio_thread(sock, b[0], pull_from_stdout);
1865  } else {
1866    CloseHandle(a[1]);
1867    CloseHandle(b[0]);
1868    closesocket(sock);
1869  }
1870  DBG(("CGI command: [%ls] -> %p", wcmd, pi.hProcess));
1860   if (CreateProcessW(NULL, wcmd, NULL, NULL, TRUE, CREATE_NEW_PROCESS_GROUP,
1861                  (void *) env, full_dir, &si, &pi) != 0) {
1862   spawn_stdio_thread(sock, a[1], push_to_stdin);
1863   spawn_stdio_thread(sock, b[0], pull_from_stdout);
1864   } else {
1865   CloseHandle(a[1]);
1866   CloseHandle(b[0]);
1867   closesocket(sock);
1868   }
1869   DBG(("CGI command: [%ls] -> %p", wcmd, pi.hProcess));
18711870
1872  // Not closing a[0] and b[1] because we've used DUPLICATE_CLOSE_SOURCE
1873  CloseHandle(si.hStdOutput);
1874  CloseHandle(si.hStdInput);
1875  //CloseHandle(pi.hThread);
1876  //CloseHandle(pi.hProcess);
1871   // Not closing a[0] and b[1] because we've used DUPLICATE_CLOSE_SOURCE
1872   CloseHandle(si.hStdOutput);
1873   CloseHandle(si.hStdInput);
1874   //CloseHandle(pi.hThread);
1875   //CloseHandle(pi.hProcess);
18771876
1878  return pi.hProcess;
1877   return pi.hProcess;
18791878}
18801879#else
18811880static process_id_t start_process(const char *interp, const char *cmd,
1882                                  const char *env, const char *envp[],
1883                                  const char *dir, sock_t sock) {
1884  char buf[500];
1885  process_id_t pid = fork();
1886  (void) env;
1881                           const char *env, const char *envp[],
1882                           const char *dir, sock_t sock) {
1883   char buf[500];
1884   process_id_t pid = fork();
1885   (void) env;
18871886
1888  if (pid == 0) {
1889    (void) chdir(dir);
1890    (void) dup2(sock, 0);
1891    (void) dup2(sock, 1);
1892    closesocket(sock);
1887   if (pid == 0) {
1888   (void) chdir(dir);
1889   (void) dup2(sock, 0);
1890   (void) dup2(sock, 1);
1891   closesocket(sock);
18931892
1894    // After exec, all signal handlers are restored to their default values,
1895    // with one exception of SIGCHLD. According to POSIX.1-2001 and Linux's
1896    // implementation, SIGCHLD's handler will leave unchanged after exec
1897    // if it was set to be ignored. Restore it to default action.
1898    signal(SIGCHLD, SIG_DFL);
1893   // After exec, all signal handlers are restored to their default values,
1894   // with one exception of SIGCHLD. According to POSIX.1-2001 and Linux's
1895   // implementation, SIGCHLD's handler will leave unchanged after exec
1896   // if it was set to be ignored. Restore it to default action.
1897   signal(SIGCHLD, SIG_DFL);
18991898
1900    if (interp == NULL) {
1901      execle(cmd, cmd, (char *) 0, envp); // Using (char *) 0 to avoid warning
1902    } else {
1903      execle(interp, interp, cmd, (char *) 0, envp);
1904    }
1905    snprintf(buf, sizeof(buf), "Status: 500\r\n\r\n"
1906             "500 Server Error: %s%s%s: %s", interp == NULL ? "" : interp,
1907             interp == NULL ? "" : " ", cmd, strerror(errno));
1908    send(1, buf, strlen(buf), 0);
1909    exit(EXIT_FAILURE);  // exec call failed
1910  }
1899   if (interp == NULL) {
1900      execle(cmd, cmd, (char *) 0, envp); // Using (char *) 0 to avoid warning
1901   } else {
1902      execle(interp, interp, cmd, (char *) 0, envp);
1903   }
1904   snprintf(buf, sizeof(buf), "Status: 500\r\n\r\n"
1905            "500 Server Error: %s%s%s: %s", interp == NULL ? "" : interp,
1906            interp == NULL ? "" : " ", cmd, strerror(errno));
1907   send(1, buf, strlen(buf), 0);
1908   exit(EXIT_FAILURE);  // exec call failed
1909   }
19111910
1912  return pid;
1911   return pid;
19131912}
19141913#endif  // _WIN32
19151914
r32760r32761
19221921// We satisfy both worlds: we create an envp array (which is vars), all
19231922// entries are actually pointers inside buf.
19241923struct cgi_env_block {
1925  struct mg_connection *conn;
1926  char buf[CGI_ENVIRONMENT_SIZE];       // Environment buffer
1927  const char *vars[MAX_CGI_ENVIR_VARS]; // char *envp[]
1928  int len;                              // Space taken
1929  int nvars;                            // Number of variables in envp[]
1924   struct mg_connection *conn;
1925   char buf[CGI_ENVIRONMENT_SIZE];       // Environment buffer
1926   const char *vars[MAX_CGI_ENVIR_VARS]; // char *envp[]
1927   int len;                              // Space taken
1928   int nvars;                            // Number of variables in envp[]
19301929};
19311930
19321931// Append VARIABLE=VALUE\0 string to the buffer, and add a respective
19331932// pointer into the vars array.
19341933static char *addenv(struct cgi_env_block *block, const char *fmt, ...) {
1935  int n, space;
1936  char *added;
1937  va_list ap;
1934   int n, space;
1935   char *added;
1936   va_list ap;
19381937
1939  // Calculate how much space is left in the buffer
1940  space = sizeof(block->buf) - block->len - 2;
1941  assert(space >= 0);
1938   // Calculate how much space is left in the buffer
1939   space = sizeof(block->buf) - block->len - 2;
1940   assert(space >= 0);
19421941
1943  // Make a pointer to the free space int the buffer
1944  added = block->buf + block->len;
1942   // Make a pointer to the free space int the buffer
1943   added = block->buf + block->len;
19451944
1946  // Copy VARIABLE=VALUE\0 string into the free space
1947  va_start(ap, fmt);
1948  n = mg_vsnprintf(added, (size_t) space, fmt, ap);
1949  va_end(ap);
1945   // Copy VARIABLE=VALUE\0 string into the free space
1946   va_start(ap, fmt);
1947   n = mg_vsnprintf(added, (size_t) space, fmt, ap);
1948   va_end(ap);
19501949
1951  // Make sure we do not overflow buffer and the envp array
1952  if (n > 0 && n + 1 < space &&
1953      block->nvars < (int) ARRAY_SIZE(block->vars) - 2) {
1954    // Append a pointer to the added string into the envp array
1955    block->vars[block->nvars++] = added;
1956    // Bump up used length counter. Include \0 terminator
1957    block->len += n + 1;
1958  }
1950   // Make sure we do not overflow buffer and the envp array
1951   if (n > 0 && n + 1 < space &&
1952      block->nvars < (int) ARRAY_SIZE(block->vars) - 2) {
1953   // Append a pointer to the added string into the envp array
1954   block->vars[block->nvars++] = added;
1955   // Bump up used length counter. Include \0 terminator
1956   block->len += n + 1;
1957   }
19591958
1960  return added;
1959   return added;
19611960}
19621961
19631962static void addenv2(struct cgi_env_block *blk, const char *name) {
1964  const char *s;
1965  if ((s = getenv(name)) != NULL) addenv(blk, "%s=%s", name, s);
1963   const char *s;
1964   if ((s = getenv(name)) != NULL) addenv(blk, "%s=%s", name, s);
19661965}
19671966
19681967static void prepare_cgi_environment(struct connection *conn,
1969                                    const char *prog,
1970                                    struct cgi_env_block *blk) {
1971  struct mg_connection *ri = &conn->mg_conn;
1972  const char *s, *slash;
1973  char *p, **opts = conn->server->config_options;
1974  int  i;
1968                           const char *prog,
1969                           struct cgi_env_block *blk) {
1970   struct mg_connection *ri = &conn->mg_conn;
1971   const char *s, *slash;
1972   char *p, **opts = conn->server->config_options;
1973   int  i;
19751974
1976  blk->len = blk->nvars = 0;
1977  blk->conn = ri;
1975   blk->len = blk->nvars = 0;
1976   blk->conn = ri;
19781977
1979  if ((s = getenv("SERVER_NAME")) != NULL) {
1980    addenv(blk, "SERVER_NAME=%s", s);
1981  } else {
1982    addenv(blk, "SERVER_NAME=%s", ri->local_ip);
1983  }
1984  addenv(blk, "SERVER_ROOT=%s", opts[DOCUMENT_ROOT]);
1985  addenv(blk, "DOCUMENT_ROOT=%s", opts[DOCUMENT_ROOT]);
1986  addenv(blk, "SERVER_SOFTWARE=%s/%s", "Mongoose", MONGOOSE_VERSION);
1978   if ((s = getenv("SERVER_NAME")) != NULL) {
1979   addenv(blk, "SERVER_NAME=%s", s);
1980   } else {
1981   addenv(blk, "SERVER_NAME=%s", ri->local_ip);
1982   }
1983   addenv(blk, "SERVER_ROOT=%s", opts[DOCUMENT_ROOT]);
1984   addenv(blk, "DOCUMENT_ROOT=%s", opts[DOCUMENT_ROOT]);
1985   addenv(blk, "SERVER_SOFTWARE=%s/%s", "Mongoose", MONGOOSE_VERSION);
19871986
1988  // Prepare the environment block
1989  addenv(blk, "%s", "GATEWAY_INTERFACE=CGI/1.1");
1990  addenv(blk, "%s", "SERVER_PROTOCOL=HTTP/1.1");
1991  addenv(blk, "%s", "REDIRECT_STATUS=200"); // For PHP
1987   // Prepare the environment block
1988   addenv(blk, "%s", "GATEWAY_INTERFACE=CGI/1.1");
1989   addenv(blk, "%s", "SERVER_PROTOCOL=HTTP/1.1");
1990   addenv(blk, "%s", "REDIRECT_STATUS=200"); // For PHP
19921991
1993  // TODO(lsm): fix this for IPv6 case
1994  //addenv(blk, "SERVER_PORT=%d", ri->remote_port);
1992   // TODO(lsm): fix this for IPv6 case
1993   //addenv(blk, "SERVER_PORT=%d", ri->remote_port);
19951994
1996  addenv(blk, "REQUEST_METHOD=%s", ri->request_method);
1997  addenv(blk, "REMOTE_ADDR=%s", ri->remote_ip);
1998  addenv(blk, "REMOTE_PORT=%d", ri->remote_port);
1999  addenv(blk, "REQUEST_URI=%s%s%s", ri->uri,
2000         ri->query_string == NULL ? "" : "?",
2001         ri->query_string == NULL ? "" : ri->query_string);
1995   addenv(blk, "REQUEST_METHOD=%s", ri->request_method);
1996   addenv(blk, "REMOTE_ADDR=%s", ri->remote_ip);
1997   addenv(blk, "REMOTE_PORT=%d", ri->remote_port);
1998   addenv(blk, "REQUEST_URI=%s%s%s", ri->uri,
1999         ri->query_string == NULL ? "" : "?",
2000         ri->query_string == NULL ? "" : ri->query_string);
20022001
2003  // SCRIPT_NAME
2004  if (conn->path_info != NULL) {
2005    addenv(blk, "SCRIPT_NAME=%.*s",
2006           (int) (strlen(ri->uri) - strlen(conn->path_info)), ri->uri);
2007    addenv(blk, "PATH_INFO=%s", conn->path_info);
2008  } else {
2009    s = strrchr(prog, '/');
2010    slash = strrchr(ri->uri, '/');
2011    addenv(blk, "SCRIPT_NAME=%.*s%s",
2012           slash == NULL ? 0 : (int) (slash - ri->uri), ri->uri,
2013           s == NULL ? prog : s);
2014  }
2002   // SCRIPT_NAME
2003   if (conn->path_info != NULL) {
2004   addenv(blk, "SCRIPT_NAME=%.*s",
2005         (int) (strlen(ri->uri) - strlen(conn->path_info)), ri->uri);
2006   addenv(blk, "PATH_INFO=%s", conn->path_info);
2007   } else {
2008   s = strrchr(prog, '/');
2009   slash = strrchr(ri->uri, '/');
2010   addenv(blk, "SCRIPT_NAME=%.*s%s",
2011         slash == NULL ? 0 : (int) (slash - ri->uri), ri->uri,
2012         s == NULL ? prog : s);
2013   }
20152014
2016  addenv(blk, "SCRIPT_FILENAME=%s", prog);
2017  addenv(blk, "PATH_TRANSLATED=%s", prog);
2018  addenv(blk, "HTTPS=%s", conn->ns_conn->ssl != NULL ? "on" : "off");
2015   addenv(blk, "SCRIPT_FILENAME=%s", prog);
2016   addenv(blk, "PATH_TRANSLATED=%s", prog);
2017   addenv(blk, "HTTPS=%s", conn->ns_conn->ssl != NULL ? "on" : "off");
20192018
2020  if ((s = mg_get_header(ri, "Content-Type")) != NULL)
2021    addenv(blk, "CONTENT_TYPE=%s", s);
2019   if ((s = mg_get_header(ri, "Content-Type")) != NULL)
2020   addenv(blk, "CONTENT_TYPE=%s", s);
20222021
2023  if (ri->query_string != NULL)
2024    addenv(blk, "QUERY_STRING=%s", ri->query_string);
2022   if (ri->query_string != NULL)
2023   addenv(blk, "QUERY_STRING=%s", ri->query_string);
20252024
2026  if ((s = mg_get_header(ri, "Content-Length")) != NULL)
2027    addenv(blk, "CONTENT_LENGTH=%s", s);
2025   if ((s = mg_get_header(ri, "Content-Length")) != NULL)
2026   addenv(blk, "CONTENT_LENGTH=%s", s);
20282027
2029  addenv2(blk, "PATH");
2030  addenv2(blk, "TMP");
2031  addenv2(blk, "TEMP");
2032  addenv2(blk, "TMPDIR");
2033  addenv2(blk, "PERLLIB");
2034  addenv2(blk, ENV_EXPORT_TO_CGI);
2028   addenv2(blk, "PATH");
2029   addenv2(blk, "TMP");
2030   addenv2(blk, "TEMP");
2031   addenv2(blk, "TMPDIR");
2032   addenv2(blk, "PERLLIB");
2033   addenv2(blk, ENV_EXPORT_TO_CGI);
20352034
20362035#if defined(_WIN32)
2037  addenv2(blk, "COMSPEC");
2038  addenv2(blk, "SYSTEMROOT");
2039  addenv2(blk, "SystemDrive");
2040  addenv2(blk, "ProgramFiles");
2041  addenv2(blk, "ProgramFiles(x86)");
2042  addenv2(blk, "CommonProgramFiles(x86)");
2036   addenv2(blk, "COMSPEC");
2037   addenv2(blk, "SYSTEMROOT");
2038   addenv2(blk, "SystemDrive");
2039   addenv2(blk, "ProgramFiles");
2040   addenv2(blk, "ProgramFiles(x86)");
2041   addenv2(blk, "CommonProgramFiles(x86)");
20432042#else
2044  addenv2(blk, "LD_LIBRARY_PATH");
2043   addenv2(blk, "LD_LIBRARY_PATH");
20452044#endif // _WIN32
20462045
2047  // Add all headers as HTTP_* variables
2048  for (i = 0; i < ri->num_headers; i++) {
2049    p = addenv(blk, "HTTP_%s=%s",
2050        ri->http_headers[i].name, ri->http_headers[i].value);
2046   // Add all headers as HTTP_* variables
2047   for (i = 0; i < ri->num_headers; i++) {
2048   p = addenv(blk, "HTTP_%s=%s",
2049      ri->http_headers[i].name, ri->http_headers[i].value);
20512050
2052    // Convert variable name into uppercase, and change - to _
2053    for (; *p != '=' && *p != '\0'; p++) {
2054      if (*p == '-')
2055        *p = '_';
2056      *p = (char) toupper(* (unsigned char *) p);
2057    }
2058  }
2051   // Convert variable name into uppercase, and change - to _
2052   for (; *p != '=' && *p != '\0'; p++) {
2053      if (*p == '-')
2054      *p = '_';
2055      *p = (char) toupper(* (unsigned char *) p);
2056   }
2057   }
20592058
2060  blk->vars[blk->nvars++] = NULL;
2061  blk->buf[blk->len++] = '\0';
2059   blk->vars[blk->nvars++] = NULL;
2060   blk->buf[blk->len++] = '\0';
20622061
2063  assert(blk->nvars < (int) ARRAY_SIZE(blk->vars));
2064  assert(blk->len > 0);
2065  assert(blk->len < (int) sizeof(blk->buf));
2062   assert(blk->nvars < (int) ARRAY_SIZE(blk->vars));
2063   assert(blk->len > 0);
2064   assert(blk->len < (int) sizeof(blk->buf));
20662065}
20672066
20682067static const char cgi_status[] = "HTTP/1.1 200 OK\r\n";
20692068
20702069static void open_cgi_endpoint(struct connection *conn, const char *prog) {
2071  struct cgi_env_block blk;
2072  char dir[MAX_PATH_SIZE];
2073  const char *p;
2074  sock_t fds[2];
2070   struct cgi_env_block blk;
2071   char dir[MAX_PATH_SIZE];
2072   const char *p;
2073   sock_t fds[2];
20752074
2076  prepare_cgi_environment(conn, prog, &blk);
2077  // CGI must be executed in its own directory. 'dir' must point to the
2078  // directory containing executable program, 'p' must point to the
2079  // executable program name relative to 'dir'.
2080  if ((p = strrchr(prog, '/')) == NULL) {
2081    mg_snprintf(dir, sizeof(dir), "%s", ".");
2082  } else {
2083    mg_snprintf(dir, sizeof(dir), "%.*s", (int) (p - prog), prog);
2084  }
2075   prepare_cgi_environment(conn, prog, &blk);
2076   // CGI must be executed in its own directory. 'dir' must point to the
2077   // directory containing executable program, 'p' must point to the
2078   // executable program name relative to 'dir'.
2079   if ((p = strrchr(prog, '/')) == NULL) {
2080   mg_snprintf(dir, sizeof(dir), "%s", ".");
2081   } else {
2082   mg_snprintf(dir, sizeof(dir), "%.*s", (int) (p - prog), prog);
2083   }
20852084
2086  // Try to create socketpair in a loop until success. ns_socketpair()
2087  // can be interrupted by a signal and fail.
2088  // TODO(lsm): use sigaction to restart interrupted syscall
2089  do {
2090    ns_socketpair(fds);
2091  } while (fds[0] == INVALID_SOCKET);
2085   // Try to create socketpair in a loop until success. ns_socketpair()
2086   // can be interrupted by a signal and fail.
2087   // TODO(lsm): use sigaction to restart interrupted syscall
2088   do {
2089   ns_socketpair(fds);
2090   } while (fds[0] == INVALID_SOCKET);
20922091
2093  if (start_process(conn->server->config_options[CGI_INTERPRETER],
2094                    prog, blk.buf, blk.vars, dir, fds[1]) != 0) {
2095    conn->endpoint_type = EP_CGI;
2096    conn->endpoint.nc = ns_add_sock(&conn->server->ns_server, fds[0], conn);
2097    conn->endpoint.nc->flags |= MG_CGI_CONN;
2098    ns_send(conn->ns_conn, cgi_status, sizeof(cgi_status) - 1);
2099    conn->mg_conn.status_code = 200;
2100    conn->ns_conn->flags |= NSF_BUFFER_BUT_DONT_SEND;
2101    // Pass POST data to the CGI process
2102    conn->endpoint.nc->send_iobuf = conn->ns_conn->recv_iobuf;
2103    iobuf_init(&conn->ns_conn->recv_iobuf, 0);
2104  } else {
2105    closesocket(fds[0]);
2106    send_http_error(conn, 500, "start_process(%s) failed", prog);
2107  }
2092   if (start_process(conn->server->config_options[CGI_INTERPRETER],
2093               prog, blk.buf, blk.vars, dir, fds[1]) != 0) {
2094   conn->endpoint_type = EP_CGI;
2095   conn->endpoint.nc = ns_add_sock(&conn->server->ns_server, fds[0], conn);
2096   conn->endpoint.nc->flags |= MG_CGI_CONN;
2097   ns_send(conn->ns_conn, cgi_status, sizeof(cgi_status) - 1);
2098   conn->mg_conn.status_code = 200;
2099   conn->ns_conn->flags |= NSF_BUFFER_BUT_DONT_SEND;
2100   // Pass POST data to the CGI process
2101   conn->endpoint.nc->send_iobuf = conn->ns_conn->recv_iobuf;
2102   iobuf_init(&conn->ns_conn->recv_iobuf, 0);
2103   } else {
2104   closesocket(fds[0]);
2105   send_http_error(conn, 500, "start_process(%s) failed", prog);
2106   }
21082107
21092108#ifndef _WIN32
2110  closesocket(fds[1]);  // On Windows, CGI stdio thread closes that socket
2109   closesocket(fds[1]);  // On Windows, CGI stdio thread closes that socket
21112110#endif
21122111}
21132112
21142113static void on_cgi_data(struct ns_connection *nc) {
2115  struct connection *conn = (struct connection *) nc->connection_data;
2116  const char *status = "500";
2117  struct mg_connection c;
2114   struct connection *conn = (struct connection *) nc->connection_data;
2115   const char *status = "500";
2116   struct mg_connection c;
21182117
2119  if (!conn) return;
2118   if (!conn) return;
21202119
2121  // Copy CGI data from CGI socket to the client send buffer
2122  ns_forward(nc, conn->ns_conn);
2120   // Copy CGI data from CGI socket to the client send buffer
2121   ns_forward(nc, conn->ns_conn);
21232122
2124  // If reply has not been parsed yet, parse it
2125  if (conn->ns_conn->flags & NSF_BUFFER_BUT_DONT_SEND) {
2126    struct iobuf *io = &conn->ns_conn->send_iobuf;
2127    int s_len = sizeof(cgi_status) - 1;
2128    int len = get_request_len(io->buf + s_len, io->len - s_len);
2129    char buf[MAX_REQUEST_SIZE], *s = buf;
2123   // If reply has not been parsed yet, parse it
2124   if (conn->ns_conn->flags & NSF_BUFFER_BUT_DONT_SEND) {
2125   struct iobuf *io = &conn->ns_conn->send_iobuf;
2126   int s_len = sizeof(cgi_status) - 1;
2127   int len = get_request_len(io->buf + s_len, io->len - s_len);
2128   char buf[MAX_REQUEST_SIZE], *s = buf;
21302129
2131    if (len == 0) return;
2130   if (len == 0) return;
21322131
2133    if (len < 0 || len > (int) sizeof(buf)) {
2134      len = io->len;
2135      iobuf_remove(io, io->len);
2136      send_http_error(conn, 500, "CGI program sent malformed headers: [%.*s]",
2137        len, io->buf);
2138    } else {
2139      memset(&c, 0, sizeof(c));
2140      memcpy(buf, io->buf + s_len, len);
2141      buf[len - 1] = '\0';
2142      parse_http_headers(&s, &c);
2143      if (mg_get_header(&c, "Location") != NULL) {
2144        status = "302";
2145      } else if ((status = (char *) mg_get_header(&c, "Status")) == NULL) {
2146        status = "200";
2147      }
2148      memcpy(io->buf + 9, status, 3);
2149      conn->mg_conn.status_code = atoi(status);
2150    }
2151    conn->ns_conn->flags &= ~NSF_BUFFER_BUT_DONT_SEND;
2152  }
2132   if (len < 0 || len > (int) sizeof(buf)) {
2133      len = io->len;
2134      iobuf_remove(io, io->len);
2135      send_http_error(conn, 500, "CGI program sent malformed headers: [%.*s]",
2136      len, io->buf);
2137   } else {
2138      memset(&c, 0, sizeof(c));
2139      memcpy(buf, io->buf + s_len, len);
2140      buf[len - 1] = '\0';
2141      parse_http_headers(&s, &c);
2142      if (mg_get_header(&c, "Location") != NULL) {
2143      status = "302";
2144      } else if ((status = (char *) mg_get_header(&c, "Status")) == NULL) {
2145      status = "200";
2146      }
2147      memcpy(io->buf + 9, status, 3);
2148      conn->mg_conn.status_code = atoi(status);
2149   }
2150   conn->ns_conn->flags &= ~NSF_BUFFER_BUT_DONT_SEND;
2151   }
21532152}
21542153#endif  // !MONGOOSE_NO_CGI
21552154
21562155static char *mg_strdup(const char *str) {
2157  char *copy = (char *) malloc(strlen(str) + 1);
2158  if (copy != NULL) {
2159    strcpy(copy, str);
2160  }
2161  return copy;
2156   char *copy = (char *) malloc(strlen(str) + 1);
2157   if (copy != NULL) {
2158   strcpy(copy, str);
2159   }
2160   return copy;
21622161}
21632162
21642163static int isbyte(int n) {
2165  return n >= 0 && n <= 255;
2164   return n >= 0 && n <= 255;
21662165}
21672166
21682167static int parse_net(const char *spec, uint32_t *net, uint32_t *mask) {
2169  int n, a, b, c, d, slash = 32, len = 0;
2168   int n, a, b, c, d, slash = 32, len = 0;
21702169
2171  if ((sscanf(spec, "%d.%d.%d.%d/%d%n", &a, &b, &c, &d, &slash, &n) == 5 ||
2172      sscanf(spec, "%d.%d.%d.%d%n", &a, &b, &c, &d, &n) == 4) &&
2173      isbyte(a) && isbyte(b) && isbyte(c) && isbyte(d) &&
2174      slash >= 0 && slash < 33) {
2175    len = n;
2176    *net = ((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)c << 8) | d;
2177    *mask = slash ? 0xffffffffU << (32 - slash) : 0;
2178  }
2170   if ((sscanf(spec, "%d.%d.%d.%d/%d%n", &a, &b, &c, &d, &slash, &n) == 5 ||
2171      sscanf(spec, "%d.%d.%d.%d%n", &a, &b, &c, &d, &n) == 4) &&
2172      isbyte(a) && isbyte(b) && isbyte(c) && isbyte(d) &&
2173      slash >= 0 && slash < 33) {
2174   len = n;
2175   *net = ((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)c << 8) | d;
2176   *mask = slash ? 0xffffffffU << (32 - slash) : 0;
2177   }
21792178
2180  return len;
2179   return len;
21812180}
21822181
21832182// Verify given socket address against the ACL.
21842183// Return -1 if ACL is malformed, 0 if address is disallowed, 1 if allowed.
21852184static int check_acl(const char *acl, uint32_t remote_ip) {
2186  int allowed, flag;
2187  uint32_t net, mask;
2188  struct vec vec;
2185   int allowed, flag;
2186   uint32_t net, mask;
2187   struct vec vec;
21892188
2190  // If any ACL is set, deny by default
2191  allowed = acl == NULL ? '+' : '-';
2189   // If any ACL is set, deny by default
2190   allowed = acl == NULL ? '+' : '-';
21922191
2193  while ((acl = next_option(acl, &vec, NULL)) != NULL) {
2194    flag = vec.ptr[0];
2195    if ((flag != '+' && flag != '-') ||
2196        parse_net(&vec.ptr[1], &net, &mask) == 0) {
2197      return -1;
2198    }
2192   while ((acl = next_option(acl, &vec, NULL)) != NULL) {
2193   flag = vec.ptr[0];
2194   if ((flag != '+' && flag != '-') ||
2195      parse_net(&vec.ptr[1], &net, &mask) == 0) {
2196      return -1;
2197   }
21992198
2200    if (net == (remote_ip & mask)) {
2201      allowed = flag;
2202    }
2203  }
2199   if (net == (remote_ip & mask)) {
2200      allowed = flag;
2201   }
2202   }
22042203
2205  return allowed == '+';
2204   return allowed == '+';
22062205}
22072206
22082207// Protect against directory disclosure attack by removing '..',
22092208// excessive '/' and '\' characters
22102209static void remove_double_dots_and_double_slashes(char *s) {
2211  char *p = s;
2210   char *p = s;
22122211
2213  while (*s != '\0') {
2214    *p++ = *s++;
2215    if (s[-1] == '/' || s[-1] == '\\') {
2216      // Skip all following slashes, backslashes and double-dots
2217      while (s[0] != '\0') {
2218        if (s[0] == '/' || s[0] == '\\') { s++; }
2219        else if (s[0] == '.' && s[1] == '.') { s += 2; }
2220        else { break; }
2221      }
2222    }
2223  }
2224  *p = '\0';
2212   while (*s != '\0') {
2213   *p++ = *s++;
2214   if (s[-1] == '/' || s[-1] == '\\') {
2215      // Skip all following slashes, backslashes and double-dots
2216      while (s[0] != '\0') {
2217      if (s[0] == '/' || s[0] == '\\') { s++; }
2218      else if (s[0] == '.' && s[1] == '.') { s += 2; }
2219      else { break; }
2220      }
2221   }
2222   }
2223   *p = '\0';
22252224}
22262225
22272226int mg_url_decode(const char *src, int src_len, char *dst,
2228                  int dst_len, int is_form_url_encoded) {
2229  int i, j, a, b;
2227               int dst_len, int is_form_url_encoded) {
2228   int i, j, a, b;
22302229#define HEXTOI(x) (isdigit(x) ? x - '0' : x - 'W')
22312230
2232  for (i = j = 0; i < src_len && j < dst_len - 1; i++, j++) {
2233    if (src[i] == '%' && i < src_len - 2 &&
2234        isxdigit(* (const unsigned char *) (src + i + 1)) &&
2235        isxdigit(* (const unsigned char *) (src + i + 2))) {
2236      a = tolower(* (const unsigned char *) (src + i + 1));
2237      b = tolower(* (const unsigned char *) (src + i + 2));
2238      dst[j] = (char) ((HEXTOI(a) << 4) | HEXTOI(b));
2239      i += 2;
2240    } else if (is_form_url_encoded && src[i] == '+') {
2241      dst[j] = ' ';
2242    } else {
2243      dst[j] = src[i];
2244    }
2245  }
2231   for (i = j = 0; i < src_len && j < dst_len - 1; i++, j++) {
2232   if (src[i] == '%' && i < src_len - 2 &&
2233      isxdigit(* (const unsigned char *) (src + i + 1)) &&
2234      isxdigit(* (const unsigned char *) (src + i + 2))) {
2235      a = tolower(* (const unsigned char *) (src + i + 1));
2236      b = tolower(* (const unsigned char *) (src + i + 2));
2237      dst[j] = (char) ((HEXTOI(a) << 4) | HEXTOI(b));
2238      i += 2;
2239   } else if (is_form_url_encoded && src[i] == '+') {
2240      dst[j] = ' ';
2241   } else {
2242      dst[j] = src[i];
2243   }
2244   }
22462245
2247  dst[j] = '\0'; // Null-terminate the destination
2246   dst[j] = '\0'; // Null-terminate the destination
22482247
2249  return i >= src_len ? j : -1;
2248   return i >= src_len ? j : -1;
22502249}
22512250
22522251static int is_valid_http_method(const char *s) {
2253  return !strcmp(s, "GET") || !strcmp(s, "POST") || !strcmp(s, "HEAD") ||
2254    !strcmp(s, "CONNECT") || !strcmp(s, "PUT") || !strcmp(s, "DELETE") ||
2255    !strcmp(s, "OPTIONS") || !strcmp(s, "PROPFIND") || !strcmp(s, "MKCOL");
2252   return !strcmp(s, "GET") || !strcmp(s, "POST") || !strcmp(s, "HEAD") ||
2253   !strcmp(s, "CONNECT") || !strcmp(s, "PUT") || !strcmp(s, "DELETE") ||
2254   !strcmp(s, "OPTIONS") || !strcmp(s, "PROPFIND") || !strcmp(s, "MKCOL");
22562255}
22572256
22582257// Parse HTTP request, fill in mg_request structure.
r32760r32761
22602259// HTTP request components, header names and header values.
22612260// Note that len must point to the last \n of HTTP headers.
22622261static int parse_http_message(char *buf, int len, struct mg_connection *ri) {
2263  int is_request, n;
2262   int is_request, n;
22642263
2265  // Reset the connection. Make sure that we don't touch fields that are
2266  // set elsewhere: remote_ip, remote_port, server_param
2267  ri->request_method = ri->uri = ri->http_version = ri->query_string = NULL;
2268  ri->num_headers = ri->status_code = ri->is_websocket = ri->content_len = 0;
2264   // Reset the connection. Make sure that we don't touch fields that are
2265   // set elsewhere: remote_ip, remote_port, server_param
2266   ri->request_method = ri->uri = ri->http_version = ri->query_string = NULL;
2267   ri->num_headers = ri->status_code = ri->is_websocket = ri->content_len = 0;
22692268
2270  buf[len - 1] = '\0';
2269   buf[len - 1] = '\0';
22712270
2272  // RFC says that all initial whitespaces should be ingored
2273  while (*buf != '\0' && isspace(* (unsigned char *) buf)) {
2274    buf++;
2275  }
2276  ri->request_method = skip(&buf, " ");
2277  ri->uri = skip(&buf, " ");
2278  ri->http_version = skip(&buf, "\r\n");
2271   // RFC says that all initial whitespaces should be ingored
2272   while (*buf != '\0' && isspace(* (unsigned char *) buf)) {
2273   buf++;
2274   }
2275   ri->request_method = skip(&buf, " ");
2276   ri->uri = skip(&buf, " ");
2277   ri->http_version = skip(&buf, "\r\n");
22792278
2280  // HTTP message could be either HTTP request or HTTP response, e.g.
2281  // "GET / HTTP/1.0 ...." or  "HTTP/1.0 200 OK ..."
2282  is_request = is_valid_http_method(ri->request_method);
2283  if ((is_request && memcmp(ri->http_version, "HTTP/", 5) != 0) ||
2284      (!is_request && memcmp(ri->request_method, "HTTP/", 5) != 0)) {
2285    len = -1;
2286  } else {
2287    if (is_request) {
2288      ri->http_version += 5;
2289    }
2290    parse_http_headers(&buf, ri);
2279   // HTTP message could be either HTTP request or HTTP response, e.g.
2280   // "GET / HTTP/1.0 ...." or  "HTTP/1.0 200 OK ..."
2281   is_request = is_valid_http_method(ri->request_method);
2282   if ((is_request && memcmp(ri->http_version, "HTTP/", 5) != 0) ||
2283      (!is_request && memcmp(ri->request_method, "HTTP/", 5) != 0)) {
2284   len = -1;
2285   } else {
2286   if (is_request) {
2287      ri->http_version += 5;
2288   }
2289   parse_http_headers(&buf, ri);
22912290
2292    if ((ri->query_string = strchr(ri->uri, '?')) != NULL) {
2293      *(char *) ri->query_string++ = '\0';
2294    }
2295    n = (int) strlen(ri->uri);
2296    mg_url_decode(ri->uri, n, (char *) ri->uri, n + 1, 0);
2297    if (*ri->uri == '/' || *ri->uri == '.') {
2298      remove_double_dots_and_double_slashes((char *) ri->uri);
2299    }
2300  }
2291   if ((ri->query_string = strchr(ri->uri, '?')) != NULL) {
2292      *(char *) ri->query_string++ = '\0';
2293   }
2294   n = (int) strlen(ri->uri);
2295   mg_url_decode(ri->uri, n, (char *) ri->uri, n + 1, 0);
2296   if (*ri->uri == '/' || *ri->uri == '.') {
2297      remove_double_dots_and_double_slashes((char *) ri->uri);
2298   }
2299   }
23012300
2302  return len;
2301   return len;
23032302}
23042303
23052304static int lowercase(const char *s) {
2306  return tolower(* (const unsigned char *) s);
2305   return tolower(* (const unsigned char *) s);
23072306}
23082307
23092308static int mg_strcasecmp(const char *s1, const char *s2) {
2310  int diff;
2309   int diff;
23112310
2312  do {
2313    diff = lowercase(s1++) - lowercase(s2++);
2314  } while (diff == 0 && s1[-1] != '\0');
2311   do {
2312   diff = lowercase(s1++) - lowercase(s2++);
2313   } while (diff == 0 && s1[-1] != '\0');
23152314
2316  return diff;
2315   return diff;
23172316}
23182317
23192318static int mg_strncasecmp(const char *s1, const char *s2, size_t len) {
2320  int diff = 0;
2319   int diff = 0;
23212320
2322  if (len > 0)
2323    do {
2324      diff = lowercase(s1++) - lowercase(s2++);
2325    } while (diff == 0 && s1[-1] != '\0' && --len > 0);
2321   if (len > 0)
2322   do {
2323      diff = lowercase(s1++) - lowercase(s2++);
2324   } while (diff == 0 && s1[-1] != '\0' && --len > 0);
23262325
2327  return diff;
2326   return diff;
23282327}
23292328
23302329// Return HTTP header value, or NULL if not found.
23312330const char *mg_get_header(const struct mg_connection *ri, const char *s) {
2332  int i;
2331   int i;
23332332
2334  for (i = 0; i < ri->num_headers; i++)
2335    if (!mg_strcasecmp(s, ri->http_headers[i].name))
2336      return ri->http_headers[i].value;
2333   for (i = 0; i < ri->num_headers; i++)
2334   if (!mg_strcasecmp(s, ri->http_headers[i].name))
2335      return ri->http_headers[i].value;
23372336
2338  return NULL;
2337   return NULL;
23392338}
23402339
23412340// Perform case-insensitive match of string against pattern
23422341int mg_match_prefix(const char *pattern, int pattern_len, const char *str) {
2343  const char *or_str;
2344  int len, res, i = 0, j = 0;
2342   const char *or_str;
2343   int len, res, i = 0, j = 0;
23452344
2346  if ((or_str = (const char *) memchr(pattern, '|', pattern_len)) != NULL) {
2347    res = mg_match_prefix(pattern, or_str - pattern, str);
2348    return res > 0 ? res : mg_match_prefix(or_str + 1,
2349      (pattern + pattern_len) - (or_str + 1), str);
2350  }
2345   if ((or_str = (const char *) memchr(pattern, '|', pattern_len)) != NULL) {
2346   res = mg_match_prefix(pattern, or_str - pattern, str);
2347   return res > 0 ? res : mg_match_prefix(or_str + 1,
2348      (pattern + pattern_len) - (or_str + 1), str);
2349   }
23512350
2352  for (; i < pattern_len; i++, j++) {
2353    if (pattern[i] == '?' && str[j] != '\0') {
2354      continue;
2355    } else if (pattern[i] == '$') {
2356      return str[j] == '\0' ? j : -1;
2357    } else if (pattern[i] == '*') {
2358      i++;
2359      if (pattern[i] == '*') {
2360        i++;
2361        len = (int) strlen(str + j);
2362      } else {
2363        len = (int) strcspn(str + j, "/");
2364      }
2365      if (i == pattern_len) {
2366        return j + len;
2367      }
2368      do {
2369        res = mg_match_prefix(pattern + i, pattern_len - i, str + j + len);
2370      } while (res == -1 && len-- > 0);
2371      return res == -1 ? -1 : j + res + len;
2372    } else if (lowercase(&pattern[i]) != lowercase(&str[j])) {
2373      return -1;
2374    }
2375  }
2376  return j;
2351   for (; i < pattern_len; i++, j++) {
2352   if (pattern[i] == '?' && str[j] != '\0') {
2353      continue;
2354   } else if (pattern[i] == '$') {
2355      return str[j] == '\0' ? j : -1;
2356   } else if (pattern[i] == '*') {
2357      i++;
2358      if (pattern[i] == '*') {
2359      i++;
2360      len = (int) strlen(str + j);
2361      } else {
2362      len = (int) strcspn(str + j, "/");
2363      }
2364      if (i == pattern_len) {
2365      return j + len;
2366      }
2367      do {
2368      res = mg_match_prefix(pattern + i, pattern_len - i, str + j + len);
2369      } while (res == -1 && len-- > 0);
2370      return res == -1 ? -1 : j + res + len;
2371   } else if (lowercase(&pattern[i]) != lowercase(&str[j])) {
2372      return -1;
2373   }
2374   }
2375   return j;
23772376}
23782377
23792378// This function prints HTML pages, and expands "{{something}}" blocks
r32760r32761
23812380// Note that {{@path/to/file}} construct outputs embedded file's contents,
23822381// which provides SSI-like functionality.
23832382void mg_template(struct mg_connection *conn, const char *s,
2384                 struct mg_expansion *expansions) {
2385  int i, j, pos = 0, inside_marker = 0;
2383               struct mg_expansion *expansions) {
2384   int i, j, pos = 0, inside_marker = 0;
23862385
2387  for (i = 0; s[i] != '\0'; i++) {
2388    if (inside_marker == 0 && !memcmp(&s[i], "{{", 2)) {
2389      if (i > pos) {
2390        mg_send_data(conn, &s[pos], i - pos);
2391      }
2392      pos = i;
2393      inside_marker = 1;
2394    }
2395    if (inside_marker == 1 && !memcmp(&s[i], "}}", 2)) {
2396      for (j = 0; expansions[j].keyword != NULL; j++) {
2397        const char *kw = expansions[j].keyword;
2398        if ((int) strlen(kw) == i - (pos + 2) &&
2399            memcmp(kw, &s[pos + 2], i - (pos + 2)) == 0) {
2400          expansions[j].handler(conn);
2401          pos = i + 2;
2402          break;
2403        }
2404      }
2405      inside_marker = 0;
2406    }
2407  }
2408  if (i > pos) {
2409    mg_send_data(conn, &s[pos], i - pos);
2410  }
2386   for (i = 0; s[i] != '\0'; i++) {
2387   if (inside_marker == 0 && !memcmp(&s[i], "{{", 2)) {
2388      if (i > pos) {
2389      mg_send_data(conn, &s[pos], i - pos);
2390      }
2391      pos = i;
2392      inside_marker = 1;
2393   }
2394   if (inside_marker == 1 && !memcmp(&s[i], "}}", 2)) {
2395      for (j = 0; expansions[j].keyword != NULL; j++) {
2396      const char *kw = expansions[j].keyword;
2397      if ((int) strlen(kw) == i - (pos + 2) &&
2398         memcmp(kw, &s[pos + 2], i - (pos + 2)) == 0) {
2399         expansions[j].handler(conn);
2400         pos = i + 2;
2401         break;
2402      }
2403      }
2404      inside_marker = 0;
2405   }
2406   }
2407   if (i > pos) {
2408   mg_send_data(conn, &s[pos], i - pos);
2409   }
24112410}
24122411
24132412#ifndef MONGOOSE_NO_FILESYSTEM
24142413static int must_hide_file(struct connection *conn, const char *path) {
2415  const char *pw_pattern = "**" PASSWORDS_FILE_NAME "$";
2416  const char *pattern = conn->server->config_options[HIDE_FILES_PATTERN];
2417  return mg_match_prefix(pw_pattern, strlen(pw_pattern), path) > 0 ||
2418    (pattern != NULL && mg_match_prefix(pattern, strlen(pattern), path) > 0);
2414   const char *pw_pattern = "**" PASSWORDS_FILE_NAME "$";
2415   const char *pattern = conn->server->config_options[HIDE_FILES_PATTERN];
2416   return mg_match_prefix(pw_pattern, strlen(pw_pattern), path) > 0 ||
2417   (pattern != NULL && mg_match_prefix(pattern, strlen(pattern), path) > 0);
24192418}
24202419
24212420// Return 1 if real file has been found, 0 otherwise
24222421static int convert_uri_to_file_name(struct connection *conn, char *buf,
2423                                    size_t buf_len, file_stat_t *st) {
2424  struct vec a, b;
2425  const char *rewrites = conn->server->config_options[URL_REWRITES];
2426  const char *root = conn->server->config_options[DOCUMENT_ROOT];
2422                           size_t buf_len, file_stat_t *st) {
2423   struct vec a, b;
2424   const char *rewrites = conn->server->config_options[URL_REWRITES];
2425   const char *root = conn->server->config_options[DOCUMENT_ROOT];
24272426#ifndef MONGOOSE_NO_CGI
2428  const char *cgi_pat = conn->server->config_options[CGI_PATTERN];
2429  char *p;
2427   const char *cgi_pat = conn->server->config_options[CGI_PATTERN];
2428   char *p;
24302429#endif
2431  const char *uri = conn->mg_conn.uri;
2432  const char *domain = mg_get_header(&conn->mg_conn, "Host");
2433  int match_len, root_len = root == NULL ? 0 : strlen(root);
2430   const char *uri = conn->mg_conn.uri;
2431   const char *domain = mg_get_header(&conn->mg_conn, "Host");
2432   int match_len, root_len = root == NULL ? 0 : strlen(root);
24342433
2435  // Perform virtual hosting rewrites
2436  if (rewrites != NULL && domain != NULL) {
2437    const char *colon = strchr(domain, ':');
2438    int domain_len = colon == NULL ? (int) strlen(domain) : colon - domain;
2434   // Perform virtual hosting rewrites
2435   if (rewrites != NULL && domain != NULL) {
2436   const char *colon = strchr(domain, ':');
2437   int domain_len = colon == NULL ? (int) strlen(domain) : colon - domain;
24392438
2440    while ((rewrites = next_option(rewrites, &a, &b)) != NULL) {
2441      if (a.len > 1 && a.ptr[0] == '@' && a.len == domain_len + 1 &&
2442          mg_strncasecmp(a.ptr + 1, domain, domain_len) == 0) {
2443        root = b.ptr;
2444        root_len = b.len;
2445        break;
2446      }
2447    }
2448  }
2439   while ((rewrites = next_option(rewrites, &a, &b)) != NULL) {
2440      if (a.len > 1 && a.ptr[0] == '@' && a.len == domain_len + 1 &&
2441         mg_strncasecmp(a.ptr + 1, domain, domain_len) == 0) {
2442      root = b.ptr;
2443      root_len = b.len;
2444      break;
2445      }
2446   }
2447   }
24492448
2450  // No filesystem access
2451  if (root == NULL || root_len == 0) return 0;
2449   // No filesystem access
2450   if (root == NULL || root_len == 0) return 0;
24522451
2453  // Handle URL rewrites
2454  mg_snprintf(buf, buf_len, "%.*s%s", root_len, root, uri);
2455  rewrites = conn->server->config_options[URL_REWRITES];  // Re-initialize!
2456  while ((rewrites = next_option(rewrites, &a, &b)) != NULL) {
2457    if ((match_len = mg_match_prefix(a.ptr, a.len, uri)) > 0) {
2458      mg_snprintf(buf, buf_len, "%.*s%s", (int) b.len, b.ptr, uri + match_len);
2459      break;
2460    }
2461  }
2452   // Handle URL rewrites
2453   mg_snprintf(buf, buf_len, "%.*s%s", root_len, root, uri);
2454   rewrites = conn->server->config_options[URL_REWRITES];  // Re-initialize!
2455   while ((rewrites = next_option(rewrites, &a, &b)) != NULL) {
2456   if ((match_len = mg_match_prefix(a.ptr, a.len, uri)) > 0) {
2457      mg_snprintf(buf, buf_len, "%.*s%s", (int) b.len, b.ptr, uri + match_len);
2458      break;
2459   }
2460   }
24622461
2463  if (stat(buf, st) == 0) return 1;
2462   if (stat(buf, st) == 0) return 1;
24642463
24652464#ifndef MONGOOSE_NO_CGI
2466  // Support PATH_INFO for CGI scripts.
2467  for (p = buf + strlen(root) + 2; *p != '\0'; p++) {
2468    if (*p == '/') {
2469      *p = '\0';
2470      if (mg_match_prefix(cgi_pat, strlen(cgi_pat), buf) > 0 &&
2471          !stat(buf, st)) {
2472      DBG(("!!!! [%s]", buf));
2473        *p = '/';
2474        conn->path_info = mg_strdup(p);
2475        *p = '\0';
2476        return 1;
2477      }
2478      *p = '/';
2479    }
2480  }
2465   // Support PATH_INFO for CGI scripts.
2466   for (p = buf + strlen(root) + 2; *p != '\0'; p++) {
2467   if (*p == '/') {
2468      *p = '\0';
2469      if (mg_match_prefix(cgi_pat, strlen(cgi_pat), buf) > 0 &&
2470         !stat(buf, st)) {
2471      DBG(("!!!! [%s]", buf));
2472      *p = '/';
2473      conn->path_info = mg_strdup(p);
2474      *p = '\0';
2475      return 1;
2476      }
2477      *p = '/';
2478   }
2479   }
24812480#endif
24822481
2483  return 0;
2482   return 0;
24842483}
24852484#endif  // MONGOOSE_NO_FILESYSTEM
24862485
24872486static int should_keep_alive(const struct mg_connection *conn) {
2488  struct connection *c = MG_CONN_2_CONN(conn);
2489  const char *method = conn->request_method;
2490  const char *http_version = conn->http_version;
2491  const char *header = mg_get_header(conn, "Connection");
2492  return method != NULL &&
2493    (!strcmp(method, "GET") || c->endpoint_type == EP_USER) &&
2494    ((header != NULL && !mg_strcasecmp(header, "keep-alive")) ||
2495     (header == NULL && http_version && !strcmp(http_version, "1.1")));
2487   struct connection *c = MG_CONN_2_CONN(conn);
2488   const char *method = conn->request_method;
2489   const char *http_version = conn->http_version;
2490   const char *header = mg_get_header(conn, "Connection");
2491   return method != NULL &&
2492   (!strcmp(method, "GET") || c->endpoint_type == EP_USER) &&
2493   ((header != NULL && !mg_strcasecmp(header, "keep-alive")) ||
2494      (header == NULL && http_version && !strcmp(http_version, "1.1")));
24962495}
24972496
24982497size_t mg_write(struct mg_connection *c, const void *buf, int len) {
2499  struct connection *conn = MG_CONN_2_CONN(c);
2500  ns_send(conn->ns_conn, buf, len);
2501  return conn->ns_conn->send_iobuf.len;
2498   struct connection *conn = MG_CONN_2_CONN(c);
2499   ns_send(conn->ns_conn, buf, len);
2500   return conn->ns_conn->send_iobuf.len;
25022501}
25032502
25042503void mg_send_status(struct mg_connection *c, int status) {
2505  if (c->status_code == 0) {
2506    c->status_code = status;
2507    mg_printf(c, "HTTP/1.1 %d %s\r\n", status, status_code_to_str(status));
2508  }
2504   if (c->status_code == 0) {
2505   c->status_code = status;
2506   mg_printf(c, "HTTP/1.1 %d %s\r\n", status, status_code_to_str(status));
2507   }
25092508}
25102509
25112510void mg_send_header(struct mg_connection *c, const char *name, const char *v) {
2512  if (c->status_code == 0) {
2513    c->status_code = 200;
2514    mg_printf(c, "HTTP/1.1 %d %s\r\n", 200, status_code_to_str(200));
2515  }
2516  mg_printf(c, "%s: %s\r\n", name, v);
2511   if (c->status_code == 0) {
2512   c->status_code = 200;
2513   mg_printf(c, "HTTP/1.1 %d %s\r\n", 200, status_code_to_str(200));
2514   }
2515   mg_printf(c, "%s: %s\r\n", name, v);
25172516}
25182517
25192518static void terminate_headers(struct mg_connection *c) {
2520  struct connection *conn = MG_CONN_2_CONN(c);
2521  if (!(conn->ns_conn->flags & MG_HEADERS_SENT)) {
2522    mg_send_header(c, "Transfer-Encoding", "chunked");
2523    mg_write(c, "\r\n", 2);
2524    conn->ns_conn->flags |= MG_HEADERS_SENT;
2525  }
2519   struct connection *conn = MG_CONN_2_CONN(c);
2520   if (!(conn->ns_conn->flags & MG_HEADERS_SENT)) {
2521   mg_send_header(c, "Transfer-Encoding", "chunked");
2522   mg_write(c, "\r\n", 2);
2523   conn->ns_conn->flags |= MG_HEADERS_SENT;
2524   }
25262525}
25272526
25282527size_t mg_send_data(struct mg_connection *c, const void *data, int data_len) {
2529  struct connection *conn = MG_CONN_2_CONN(c);
2530  terminate_headers(c);
2531  write_chunk(MG_CONN_2_CONN(c), (const char *) data, data_len);
2532  return conn->ns_conn->send_iobuf.len;
2528   struct connection *conn = MG_CONN_2_CONN(c);
2529   terminate_headers(c);
2530   write_chunk(MG_CONN_2_CONN(c), (const char *) data, data_len);
2531   return conn->ns_conn->send_iobuf.len;
25332532}
25342533
25352534size_t mg_printf_data(struct mg_connection *c, const char *fmt, ...) {
2536  struct connection *conn = MG_CONN_2_CONN(c);
2537  va_list ap;
2538  int len;
2539  char mem[IOBUF_SIZE], *buf = mem;
2535   struct connection *conn = MG_CONN_2_CONN(c);
2536   va_list ap;
2537   int len;
2538   char mem[IOBUF_SIZE], *buf = mem;
25402539
2541  terminate_headers(c);
2540   terminate_headers(c);
25422541
2543  va_start(ap, fmt);
2544  len = ns_avprintf(&buf, sizeof(mem), fmt, ap);
2545  va_end(ap);
2542   va_start(ap, fmt);
2543   len = ns_avprintf(&buf, sizeof(mem), fmt, ap);
2544   va_end(ap);
25462545
2547  if (len >= 0) {
2548    write_chunk((struct connection *) conn, buf, len);
2549  }
2550  if (buf != mem && buf != NULL) {
2551    free(buf);
2552  }
2553  return conn->ns_conn->send_iobuf.len;
2546   if (len >= 0) {
2547   write_chunk((struct connection *) conn, buf, len);
2548   }
2549   if (buf != mem && buf != NULL) {
2550   free(buf);
2551   }
2552   return conn->ns_conn->send_iobuf.len;
25542553}
25552554
25562555#if !defined(MONGOOSE_NO_WEBSOCKET) || !defined(MONGOOSE_NO_AUTH)
25572556static int is_big_endian(void) {
2558  static const int n = 1;
2559  return ((char *) &n)[0] == 0;
2557   static const int n = 1;
2558   return ((char *) &n)[0] == 0;
25602559}
25612560#endif
25622561
r32760r32761
25732572#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
25742573
25752574static uint32_t blk0(union char64long16 *block, int i) {
2576  // Forrest: SHA expect BIG_ENDIAN, swap if LITTLE_ENDIAN
2577  if (!is_big_endian()) {
2578    block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) |
2579      (rol(block->l[i], 8) & 0x00FF00FF);
2580  }
2581  return block->l[i];
2575   // Forrest: SHA expect BIG_ENDIAN, swap if LITTLE_ENDIAN
2576   if (!is_big_endian()) {
2577   block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) |
2578      (rol(block->l[i], 8) & 0x00FF00FF);
2579   }
2580   return block->l[i];
25822581}
25832582
25842583#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
2585    ^block->l[(i+2)&15]^block->l[i&15],1))
2584   ^block->l[(i+2)&15]^block->l[i&15],1))
25862585#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(block, i)+0x5A827999+rol(v,5);w=rol(w,30);
25872586#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
25882587#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
r32760r32761
25902589#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
25912590
25922591typedef struct {
2593    uint32_t state[5];
2594    uint32_t count[2];
2595    unsigned char buffer[64];
2592   uint32_t state[5];
2593   uint32_t count[2];
2594   unsigned char buffer[64];
25962595} SHA1_CTX;
25972596
25982597static void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]) {
2599  uint32_t a, b, c, d, e;
2600  union char64long16 block[1];
2598   uint32_t a, b, c, d, e;
2599   union char64long16 block[1];
26012600
2602  memcpy(block, buffer, 64);
2603  a = state[0];
2604  b = state[1];
2605  c = state[2];
2606  d = state[3];
2607  e = state[4];
2608  R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
2609  R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
2610  R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
2611  R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
2612  R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
2613  R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
2614  R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
2615  R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
2616  R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
2617  R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
2618  R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
2619  R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
2620  R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
2621  R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
2622  R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
2623  R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
2624  R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
2625  R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
2626  R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
2627  R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
2628  state[0] += a;
2629  state[1] += b;
2630  state[2] += c;
2631  state[3] += d;
2632  state[4] += e;
2633  // Erase working structures. The order of operations is important,
2634  // used to ensure that compiler doesn't optimize those out.
2635  memset(block, 0, sizeof(block));
2636  a = b = c = d = e = 0;
2637  (void) a; (void) b; (void) c; (void) d; (void) e;
2601   memcpy(block, buffer, 64);
2602   a = state[0];
2603   b = state[1];
2604   c = state[2];
2605   d = state[3];
2606   e = state[4];
2607   R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
2608   R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
2609   R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
2610   R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
2611   R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
2612   R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
2613   R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
2614   R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
2615   R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
2616   R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
2617   R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
2618   R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
2619   R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
2620   R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
2621   R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
2622   R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
2623   R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
2624   R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
2625   R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
2626   R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
2627   state[0] += a;
2628   state[1] += b;
2629   state[2] += c;
2630   state[3] += d;
2631   state[4] += e;
2632   // Erase working structures. The order of operations is important,
2633   // used to ensure that compiler doesn't optimize those out.
2634   memset(block, 0, sizeof(block));
2635   a = b = c = d = e = 0;
2636   (void) a; (void) b; (void) c; (void) d; (void) e;
26382637}
26392638
26402639static void SHA1Init(SHA1_CTX *context) {
2641  context->state[0] = 0x67452301;
2642  context->state[1] = 0xEFCDAB89;
2643  context->state[2] = 0x98BADCFE;
2644  context->state[3] = 0x10325476;
2645  context->state[4] = 0xC3D2E1F0;
2646  context->count[0] = context->count[1] = 0;
2640   context->state[0] = 0x67452301;
2641   context->state[1] = 0xEFCDAB89;
2642   context->state[2] = 0x98BADCFE;
2643   context->state[3] = 0x10325476;
2644   context->state[4] = 0xC3D2E1F0;
2645   context->count[0] = context->count[1] = 0;
26472646}
26482647
26492648static void SHA1Update(SHA1_CTX *context, const unsigned char *data,
2650                       uint32_t len) {
2651  uint32_t i, j;
2649                  uint32_t len) {
2650   uint32_t i, j;
26522651
2653  j = context->count[0];
2654  if ((context->count[0] += len << 3) < j)
2655    context->count[1]++;
2656  context->count[1] += (len>>29);
2657  j = (j >> 3) & 63;
2658  if ((j + len) > 63) {
2659    memcpy(&context->buffer[j], data, (i = 64-j));
2660    SHA1Transform(context->state, context->buffer);
2661    for ( ; i + 63 < len; i += 64) {
2662      SHA1Transform(context->state, &data[i]);
2663    }
2664    j = 0;
2665  }
2666  else i = 0;
2667  memcpy(&context->buffer[j], &data[i], len - i);
2652   j = context->count[0];
2653   if ((context->count[0] += len << 3) < j)
2654   context->count[1]++;
2655   context->count[1] += (len>>29);
2656   j = (j >> 3) & 63;
2657   if ((j + len) > 63) {
2658   memcpy(&context->buffer[j], data, (i = 64-j));
2659   SHA1Transform(context->state, context->buffer);
2660   for ( ; i + 63 < len; i += 64) {
2661      SHA1Transform(context->state, &data[i]);
2662   }
2663   j = 0;
2664   }
2665   else i = 0;
2666   memcpy(&context->buffer[j], &data[i], len - i);
26682667}
26692668
26702669static void SHA1Final(unsigned char digest[20], SHA1_CTX *context) {
2671  unsigned i;
2672  unsigned char finalcount[8], c;
2670   unsigned i;
2671   unsigned char finalcount[8], c;
26732672
2674  for (i = 0; i < 8; i++) {
2675    finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
2676                                     >> ((3-(i & 3)) * 8) ) & 255);
2677  }
2678  c = 0200;
2679  SHA1Update(context, &c, 1);
2680  while ((context->count[0] & 504) != 448) {
2681    c = 0000;
2682    SHA1Update(context, &c, 1);
2683  }
2684  SHA1Update(context, finalcount, 8);
2685  for (i = 0; i < 20; i++) {
2686    digest[i] = (unsigned char)
2687      ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
2688  }
2689  memset(context, '\0', sizeof(*context));
2690  memset(&finalcount, '\0', sizeof(finalcount));
2673   for (i = 0; i < 8; i++) {
2674   finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
2675                              >> ((3-(i & 3)) * 8) ) & 255);
2676   }
2677   c = 0200;
2678   SHA1Update(context, &c, 1);
2679   while ((context->count[0] & 504) != 448) {
2680   c = 0000;
2681   SHA1Update(context, &c, 1);
2682   }
2683   SHA1Update(context, finalcount, 8);
2684   for (i = 0; i < 20; i++) {
2685   digest[i] = (unsigned char)
2686      ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
2687   }
2688   memset(context, '\0', sizeof(*context));
2689   memset(&finalcount, '\0', sizeof(finalcount));
26912690}
26922691// END OF SHA1 CODE
26932692
26942693static void base64_encode(const unsigned char *src, int src_len, char *dst) {
2695  static const char *b64 =
2696    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2697  int i, j, a, b, c;
2694   static const char *b64 =
2695   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2696   int i, j, a, b, c;
26982697
2699  for (i = j = 0; i < src_len; i += 3) {
2700    a = src[i];
2701    b = i + 1 >= src_len ? 0 : src[i + 1];
2702    c = i + 2 >= src_len ? 0 : src[i + 2];
2698   for (i = j = 0; i < src_len; i += 3) {
2699   a = src[i];
2700   b = i + 1 >= src_len ? 0 : src[i + 1];
2701   c = i + 2 >= src_len ? 0 : src[i + 2];
27032702
2704    dst[j++] = b64[a >> 2];
2705    dst[j++] = b64[((a & 3) << 4) | (b >> 4)];
2706    if (i + 1 < src_len) {
2707      dst[j++] = b64[(b & 15) << 2 | (c >> 6)];
2708    }
2709    if (i + 2 < src_len) {
2710      dst[j++] = b64[c & 63];
2711    }
2712  }
2713  while (j % 4 != 0) {
2714    dst[j++] = '=';
2715  }
2716  dst[j++] = '\0';
2703   dst[j++] = b64[a >> 2];
2704   dst[j++] = b64[((a & 3) << 4) | (b >> 4)];
2705   if (i + 1 < src_len) {
2706      dst[j++] = b64[(b & 15) << 2 | (c >> 6)];
2707   }
2708   if (i + 2 < src_len) {
2709      dst[j++] = b64[c & 63];
2710   }
2711   }
2712   while (j % 4 != 0) {
2713   dst[j++] = '=';
2714   }
2715   dst[j++] = '\0';
27172716}
27182717
27192718static void send_websocket_handshake(struct mg_connection *conn,
2720                                     const char *key) {
2721  static const char *magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
2722  char buf[500], sha[20], b64_sha[sizeof(sha) * 2];
2723  SHA1_CTX sha_ctx;
2719                              const char *key) {
2720   static const char *magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
2721   char buf[500], sha[20], b64_sha[sizeof(sha) * 2];
2722   SHA1_CTX sha_ctx;
27242723
2725  mg_snprintf(buf, sizeof(buf), "%s%s", key, magic);
2726  SHA1Init(&sha_ctx);
2727  SHA1Update(&sha_ctx, (unsigned char *) buf, strlen(buf));
2728  SHA1Final((unsigned char *) sha, &sha_ctx);
2729  base64_encode((unsigned char *) sha, sizeof(sha), b64_sha);
2730  mg_snprintf(buf, sizeof(buf), "%s%s%s",
2731              "HTTP/1.1 101 Switching Protocols\r\n"
2732              "Upgrade: websocket\r\n"
2733              "Connection: Upgrade\r\n"
2734              "Sec-WebSocket-Accept: ", b64_sha, "\r\n\r\n");
2724   mg_snprintf(buf, sizeof(buf), "%s%s", key, magic);
2725   SHA1Init(&sha_ctx);
2726   SHA1Update(&sha_ctx, (unsigned char *) buf, strlen(buf));
2727   SHA1Final((unsigned char *) sha, &sha_ctx);
2728   base64_encode((unsigned char *) sha, sizeof(sha), b64_sha);
2729   mg_snprintf(buf, sizeof(buf), "%s%s%s",
2730            "HTTP/1.1 101 Switching Protocols\r\n"
2731            "Upgrade: websocket\r\n"
2732            "Connection: Upgrade\r\n"
2733            "Sec-WebSocket-Accept: ", b64_sha, "\r\n\r\n");
27352734
2736  mg_write(conn, buf, strlen(buf));
2735   mg_write(conn, buf, strlen(buf));
27372736}
27382737
27392738static int deliver_websocket_frame(struct connection *conn) {
2740  // Having buf unsigned char * is important, as it is used below in arithmetic
2741  unsigned char *buf = (unsigned char *) conn->ns_conn->recv_iobuf.buf;
2742  int i, len, buf_len = conn->ns_conn->recv_iobuf.len, frame_len = 0,
2743      mask_len = 0, header_len = 0, data_len = 0, buffered = 0;
2739   // Having buf unsigned char * is important, as it is used below in arithmetic
2740   unsigned char *buf = (unsigned char *) conn->ns_conn->recv_iobuf.buf;
2741   int i, len, buf_len = conn->ns_conn->recv_iobuf.len, frame_len = 0,
2742      mask_len = 0, header_len = 0, data_len = 0, buffered = 0;
27442743
2745  if (buf_len >= 2) {
2746    len = buf[1] & 127;
2747    mask_len = buf[1] & 128 ? 4 : 0;
2748    if (len < 126 && buf_len >= mask_len) {
2749      data_len = len;
2750      header_len = 2 + mask_len;
2751    } else if (len == 126 && buf_len >= 4 + mask_len) {
2752      header_len = 4 + mask_len;
2753      data_len = ((((int) buf[2]) << 8) + buf[3]);
2754    } else if (buf_len >= 10 + mask_len) {
2755      header_len = 10 + mask_len;
2756      data_len = (int) (((uint64_t) htonl(* (uint32_t *) &buf[2])) << 32) +
2757        htonl(* (uint32_t *) &buf[6]);
2758    }
2759  }
2744   if (buf_len >= 2) {
2745   len = buf[1] & 127;
2746   mask_len = buf[1] & 128 ? 4 : 0;
2747   if (len < 126 && buf_len >= mask_len) {
2748      data_len = len;
2749      header_len = 2 + mask_len;
2750   } else if (len == 126 && buf_len >= 4 + mask_len) {
2751      header_len = 4 + mask_len;
2752      data_len = ((((int) buf[2]) << 8) + buf[3]);
2753   } else if (buf_len >= 10 + mask_len) {
2754      header_len = 10 + mask_len;
2755      data_len = (int) (((uint64_t) htonl(* (uint32_t *) &buf[2])) << 32) +
2756      htonl(* (uint32_t *) &buf[6]);
2757   }
2758   }
27602759
2761  frame_len = header_len + data_len;
2762  buffered = frame_len > 0 && frame_len <= buf_len;
2760   frame_len = header_len + data_len;
2761   buffered = frame_len > 0 && frame_len <= buf_len;
27632762
2764  if (buffered) {
2765    conn->mg_conn.content_len = data_len;
2766    conn->mg_conn.content = (char *) buf + header_len;
2767    conn->mg_conn.wsbits = buf[0];
2763   if (buffered) {
2764   conn->mg_conn.content_len = data_len;
2765   conn->mg_conn.content = (char *) buf + header_len;
2766   conn->mg_conn.wsbits = buf[0];
27682767
2769    // Apply mask if necessary
2770    if (mask_len > 0) {
2771      for (i = 0; i < data_len; i++) {
2772        buf[i + header_len] ^= (buf + header_len - mask_len)[i % 4];
2773      }
2774    }
2768   // Apply mask if necessary
2769   if (mask_len > 0) {
2770      for (i = 0; i < data_len; i++) {
2771      buf[i + header_len] ^= (buf + header_len - mask_len)[i % 4];
2772      }
2773   }
27752774
2776    // Call the handler and remove frame from the iobuf
2777    if (call_user(conn, MG_REQUEST) == MG_FALSE) {
2778      conn->ns_conn->flags |= NSF_FINISHED_SENDING_DATA;
2779    }
2780    iobuf_remove(&conn->ns_conn->recv_iobuf, frame_len);
2781  }
2775   // Call the handler and remove frame from the iobuf
2776   if (call_user(conn, MG_REQUEST) == MG_FALSE) {
2777      conn->ns_conn->flags |= NSF_FINISHED_SENDING_DATA;
2778   }
2779   iobuf_remove(&conn->ns_conn->recv_iobuf, frame_len);
2780   }
27822781
2783  return buffered;
2782   return buffered;
27842783}
27852784
27862785size_t mg_websocket_write(struct mg_connection *conn, int opcode,
2787                       const char *data, size_t data_len) {
2788    unsigned char mem[4192], *copy = mem;
2789    size_t copy_len = 0;
2786                  const char *data, size_t data_len) {
2787   unsigned char mem[4192], *copy = mem;
2788   size_t copy_len = 0;
27902789
2791    if (data_len + 10 > sizeof(mem) &&
2792        (copy = (unsigned char *) malloc(data_len + 10)) == NULL) {
2793      return 0;
2794    }
2790   if (data_len + 10 > sizeof(mem) &&
2791      (copy = (unsigned char *) malloc(data_len + 10)) == NULL) {
2792      return 0;
2793   }
27952794
2796    copy[0] = 0x80 + (opcode & 0x0f);
2795   copy[0] = 0x80 + (opcode & 0x0f);
27972796
2798    // Frame format: http://tools.ietf.org/html/rfc6455#section-5.2
2799    if (data_len < 126) {
2800      // Inline 7-bit length field
2801      copy[1] = data_len;
2802      memcpy(copy + 2, data, data_len);
2803      copy_len = 2 + data_len;
2804    } else if (data_len <= 0xFFFF) {
2805      // 16-bit length field
2806      copy[1] = 126;
2807      * (uint16_t *) (copy + 2) = (uint16_t) htons((uint16_t) data_len);
2808      memcpy(copy + 4, data, data_len);
2809      copy_len = 4 + data_len;
2810    } else {
2811      // 64-bit length field
2812      copy[1] = 127;
2813      * (uint32_t *) (copy + 2) = (uint32_t)
2814        htonl((uint32_t) ((uint64_t) data_len >> 32));
2815      * (uint32_t *) (copy + 6) = (uint32_t) htonl(data_len & 0xffffffff);
2816      memcpy(copy + 10, data, data_len);
2817      copy_len = 10 + data_len;
2818    }
2797   // Frame format: http://tools.ietf.org/html/rfc6455#section-5.2
2798   if (data_len < 126) {
2799      // Inline 7-bit length field
2800      copy[1] = data_len;
2801      memcpy(copy + 2, data, data_len);
2802      copy_len = 2 + data_len;
2803   } else if (data_len <= 0xFFFF) {
2804      // 16-bit length field
2805      copy[1] = 126;
2806      * (uint16_t *) (copy + 2) = (uint16_t) htons((uint16_t) data_len);
2807      memcpy(copy + 4, data, data_len);
2808      copy_len = 4 + data_len;
2809   } else {
2810      // 64-bit length field
2811      copy[1] = 127;
2812      * (uint32_t *) (copy + 2) = (uint32_t)
2813      htonl((uint32_t) ((uint64_t) data_len >> 32));
2814      * (uint32_t *) (copy + 6) = (uint32_t) htonl(data_len & 0xffffffff);
2815      memcpy(copy + 10, data, data_len);
2816      copy_len = 10 + data_len;
2817   }
28192818
2820    if (copy_len > 0) {
2821      mg_write(conn, copy, copy_len);
2822    }
2823    if (copy != mem) {
2824      free(copy);
2825    }
2819   if (copy_len > 0) {
2820      mg_write(conn, copy, copy_len);
2821   }
2822   if (copy != mem) {
2823      free(copy);
2824   }
28262825
2827    // If we send closing frame, schedule a connection to be closed after
2828    // data is drained to the client.
2829    if (opcode == WEBSOCKET_OPCODE_CONNECTION_CLOSE) {
2830      MG_CONN_2_CONN(conn)->ns_conn->flags |= NSF_FINISHED_SENDING_DATA;
2831    }
2826   // If we send closing frame, schedule a connection to be closed after
2827   // data is drained to the client.
2828   if (opcode == WEBSOCKET_OPCODE_CONNECTION_CLOSE) {
2829      MG_CONN_2_CONN(conn)->ns_conn->flags |= NSF_FINISHED_SENDING_DATA;
2830   }
28322831
2833    return MG_CONN_2_CONN(conn)->ns_conn->send_iobuf.len;
2832   return MG_CONN_2_CONN(conn)->ns_conn->send_iobuf.len;
28342833}
28352834
28362835size_t mg_websocket_printf(struct mg_connection *conn, int opcode,
2837                           const char *fmt, ...) {
2838  char mem[4192], *buf = mem;
2839  va_list ap;
2840  int len;
2836                     const char *fmt, ...) {
2837   char mem[4192], *buf = mem;
2838   va_list ap;
2839   int len;
28412840
2842  va_start(ap, fmt);
2843  if ((len = ns_avprintf(&buf, sizeof(mem), fmt, ap)) > 0) {
2844    mg_websocket_write(conn, opcode, buf, len);
2845  }
2846  va_end(ap);
2841   va_start(ap, fmt);
2842   if ((len = ns_avprintf(&buf, sizeof(mem), fmt, ap)) > 0) {
2843   mg_websocket_write(conn, opcode, buf, len);
2844   }
2845   va_end(ap);
28472846
2848  if (buf != mem && buf != NULL) {
2849    free(buf);
2850  }
2847   if (buf != mem && buf != NULL) {
2848   free(buf);
2849   }
28512850
2852  return MG_CONN_2_CONN(conn)->ns_conn->send_iobuf.len;
2851   return MG_CONN_2_CONN(conn)->ns_conn->send_iobuf.len;
28532852}
28542853
28552854static void send_websocket_handshake_if_requested(struct mg_connection *conn) {
2856  const char *ver = mg_get_header(conn, "Sec-WebSocket-Version"),
2857        *key = mg_get_header(conn, "Sec-WebSocket-Key");
2858  if (ver != NULL && key != NULL) {
2859    conn->is_websocket = 1;
2860    if (call_user(MG_CONN_2_CONN(conn), MG_WS_HANDSHAKE) == MG_FALSE) {
2861      send_websocket_handshake(conn, key);
2862    }
2863    call_user(MG_CONN_2_CONN(conn), MG_WS_CONNECT);
2864  }
2855   const char *ver = mg_get_header(conn, "Sec-WebSocket-Version"),
2856      *key = mg_get_header(conn, "Sec-WebSocket-Key");
2857   if (ver != NULL && key != NULL) {
2858   conn->is_websocket = 1;
2859   if (call_user(MG_CONN_2_CONN(conn), MG_WS_HANDSHAKE) == MG_FALSE) {
2860      send_websocket_handshake(conn, key);
2861   }
2862   call_user(MG_CONN_2_CONN(conn), MG_WS_CONNECT);
2863   }
28652864}
28662865
28672866static void ping_idle_websocket_connection(struct connection *conn, time_t t) {
2868  if (t - conn->ns_conn->last_io_time > MONGOOSE_USE_WEBSOCKET_PING_INTERVAL) {
2869    mg_websocket_write(&conn->mg_conn, WEBSOCKET_OPCODE_PING, "", 0);
2870  }
2867   if (t - conn->ns_conn->last_io_time > MONGOOSE_USE_WEBSOCKET_PING_INTERVAL) {
2868   mg_websocket_write(&conn->mg_conn, WEBSOCKET_OPCODE_PING, "", 0);
2869   }
28712870}
28722871#else
28732872#define ping_idle_websocket_connection(conn, t)
28742873#endif // !MONGOOSE_NO_WEBSOCKET
28752874
28762875static void write_terminating_chunk(struct connection *conn) {
2877  mg_write(&conn->mg_conn, "0\r\n\r\n", 5);
2876   mg_write(&conn->mg_conn, "0\r\n\r\n", 5);
28782877}
28792878
28802879static int call_request_handler(struct connection *conn) {
2881  int result;
2882  conn->mg_conn.content = conn->ns_conn->recv_iobuf.buf;
2883  if ((result = call_user(conn, MG_REQUEST)) == MG_TRUE) {
2884    if (conn->ns_conn->flags & MG_HEADERS_SENT) {
2885      write_terminating_chunk(conn);
2886    }
2887    close_local_endpoint(conn);
2888  }
2889  return result;
2880   int result;
2881   conn->mg_conn.content = conn->ns_conn->recv_iobuf.buf;
2882   if ((result = call_user(conn, MG_REQUEST)) == MG_TRUE) {
2883   if (conn->ns_conn->flags & MG_HEADERS_SENT) {
2884      write_terminating_chunk(conn);
2885   }
2886   close_local_endpoint(conn);
2887   }
2888   return result;
28902889}
28912890
28922891const char *mg_get_mime_type(const char *path, const char *default_mime_type) {
2893  const char *ext;
2894  size_t i, path_len;
2892   const char *ext;
2893   size_t i, path_len;
28952894
2896  path_len = strlen(path);
2895   path_len = strlen(path);
28972896
2898  for (i = 0; static_builtin_mime_types[i].extension != NULL; i++) {
2899    ext = path + (path_len - static_builtin_mime_types[i].ext_len);
2900    if (path_len > static_builtin_mime_types[i].ext_len &&
2901        mg_strcasecmp(ext, static_builtin_mime_types[i].extension) == 0) {
2902      return static_builtin_mime_types[i].mime_type;
2903    }
2904  }
2897   for (i = 0; static_builtin_mime_types[i].extension != NULL; i++) {
2898   ext = path + (path_len - static_builtin_mime_types[i].ext_len);
2899   if (path_len > static_builtin_mime_types[i].ext_len &&
2900      mg_strcasecmp(ext, static_builtin_mime_types[i].extension) == 0) {
2901      return static_builtin_mime_types[i].mime_type;
2902   }
2903   }
29052904
2906  return default_mime_type;
2905   return default_mime_type;
29072906}
29082907
29092908#ifndef MONGOOSE_NO_FILESYSTEM
29102909// Convert month to the month number. Return -1 on error, or month number
29112910static int get_month_index(const char *s) {
2912  static const char *month_names[] = {
2913    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
2914    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
2915  };
2916  int i;
2911   static const char *month_names[] = {
2912   "Jan", "Feb", "Mar", "Apr", "May", "Jun",
2913   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
2914   };
2915   int i;
29172916
2918  for (i = 0; i < (int) ARRAY_SIZE(month_names); i++)
2919    if (!strcmp(s, month_names[i]))
2920      return i;
2917   for (i = 0; i < (int) ARRAY_SIZE(month_names); i++)
2918   if (!strcmp(s, month_names[i]))
2919      return i;
29212920
2922  return -1;
2921   return -1;
29232922}
29242923
29252924static int num_leap_years(int year) {
2926  return year / 4 - year / 100 + year / 400;
2925   return year / 4 - year / 100 + year / 400;
29272926}
29282927
29292928// Parse UTC date-time string, and return the corresponding time_t value.
29302929static time_t parse_date_string(const char *datetime) {
2931  static const unsigned short days_before_month[] = {
2932    0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
2933  };
2934  char month_str[32];
2935  int second, minute, hour, day, month, year, leap_days, days;
2936  time_t result = (time_t) 0;
2930   static const unsigned short days_before_month[] = {
2931   0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
2932   };
2933   char month_str[32];
2934   int second, minute, hour, day, month, year, leap_days, days;
2935   time_t result = (time_t) 0;
29372936
2938  if (((sscanf(datetime, "%d/%3s/%d %d:%d:%d",
2939               &day, month_str, &year, &hour, &minute, &second) == 6) ||
2940       (sscanf(datetime, "%d %3s %d %d:%d:%d",
2941               &day, month_str, &year, &hour, &minute, &second) == 6) ||
2942       (sscanf(datetime, "%*3s, %d %3s %d %d:%d:%d",
2943               &day, month_str, &year, &hour, &minute, &second) == 6) ||
2944       (sscanf(datetime, "%d-%3s-%d %d:%d:%d",
2945               &day, month_str, &year, &hour, &minute, &second) == 6)) &&
2946      year > 1970 &&
2947      (month = get_month_index(month_str)) != -1) {
2948    leap_days = num_leap_years(year) - num_leap_years(1970);
2949    year -= 1970;
2950    days = year * 365 + days_before_month[month] + (day - 1) + leap_days;
2951    result = days * 24 * 3600 + hour * 3600 + minute * 60 + second;
2952  }
2937   if (((sscanf(datetime, "%d/%3s/%d %d:%d:%d",
2938            &day, month_str, &year, &hour, &minute, &second) == 6) ||
2939      (sscanf(datetime, "%d %3s %d %d:%d:%d",
2940            &day, month_str, &year, &hour, &minute, &second) == 6) ||
2941      (sscanf(datetime, "%*3s, %d %3s %d %d:%d:%d",
2942            &day, month_str, &year, &hour, &minute, &second) == 6) ||
2943      (sscanf(datetime, "%d-%3s-%d %d:%d:%d",
2944            &day, month_str, &year, &hour, &minute, &second) == 6)) &&
2945      year > 1970 &&
2946      (month = get_month_index(month_str)) != -1) {
2947   leap_days = num_leap_years(year) - num_leap_years(1970);
2948   year -= 1970;
2949   days = year * 365 + days_before_month[month] + (day - 1) + leap_days;
2950   result = days * 24 * 3600 + hour * 3600 + minute * 60 + second;
2951   }
29532952
2954  return result;
2953   return result;
29552954}
29562955
29572956// Look at the "path" extension and figure what mime type it has.
29582957// Store mime type in the vector.
29592958static void get_mime_type(const struct mg_server *server, const char *path,
2960                          struct vec *vec) {
2961  struct vec ext_vec, mime_vec;
2962  const char *list, *ext;
2963  size_t path_len;
2959                     struct vec *vec) {
2960   struct vec ext_vec, mime_vec;
2961   const char *list, *ext;
2962   size_t path_len;
29642963
2965  path_len = strlen(path);
2964   path_len = strlen(path);
29662965
2967  // Scan user-defined mime types first, in case user wants to
2968  // override default mime types.
2969  list = server->config_options[EXTRA_MIME_TYPES];
2970  while ((list = next_option(list, &ext_vec, &mime_vec)) != NULL) {
2971    // ext now points to the path suffix
2972    ext = path + path_len - ext_vec.len;
2973    if (mg_strncasecmp(ext, ext_vec.ptr, ext_vec.len) == 0) {
2974      *vec = mime_vec;
2975      return;
2976    }
2977  }
2966   // Scan user-defined mime types first, in case user wants to
2967   // override default mime types.
2968   list = server->config_options[EXTRA_MIME_TYPES];
2969   while ((list = next_option(list, &ext_vec, &mime_vec)) != NULL) {
2970   // ext now points to the path suffix
2971   ext = path + path_len - ext_vec.len;
2972   if (mg_strncasecmp(ext, ext_vec.ptr, ext_vec.len) == 0) {
2973      *vec = mime_vec;
2974      return;
2975   }
2976   }
29782977
2979  vec->ptr = mg_get_mime_type(path, "text/plain");
2980  vec->len = strlen(vec->ptr);
2978   vec->ptr = mg_get_mime_type(path, "text/plain");
2979   vec->len = strlen(vec->ptr);
29812980}
29822981
29832982static const char *suggest_connection_header(const struct mg_connection *conn) {
2984  return should_keep_alive(conn) ? "keep-alive" : "close";
2983   return should_keep_alive(conn) ? "keep-alive" : "close";
29852984}
29862985
29872986static void construct_etag(char *buf, size_t buf_len, const file_stat_t *st) {
2988  mg_snprintf(buf, buf_len, "\"%lx.%" INT64_FMT "\"",
2989              (unsigned long) st->st_mtime, (int64_t) st->st_size);
2987   mg_snprintf(buf, buf_len, "\"%lx.%" INT64_FMT "\"",
2988            (unsigned long) st->st_mtime, (int64_t) st->st_size);
29902989}
29912990
29922991// Return True if we should reply 304 Not Modified.
29932992static int is_not_modified(const struct connection *conn,
2994                           const file_stat_t *stp) {
2995  char etag[64];
2996  const char *ims = mg_get_header(&conn->mg_conn, "If-Modified-Since");
2997  const char *inm = mg_get_header(&conn->mg_conn, "If-None-Match");
2998  construct_etag(etag, sizeof(etag), stp);
2999  return (inm != NULL && !mg_strcasecmp(etag, inm)) ||
3000    (ims != NULL && stp->st_mtime <= parse_date_string(ims));
2993                     const file_stat_t *stp) {
2994   char etag[64];
2995   const char *ims = mg_get_header(&conn->mg_conn, "If-Modified-Since");
2996   const char *inm = mg_get_header(&conn->mg_conn, "If-None-Match");
2997   construct_etag(etag, sizeof(etag), stp);
2998   return (inm != NULL && !mg_strcasecmp(etag, inm)) ||
2999   (ims != NULL && stp->st_mtime <= parse_date_string(ims));
30013000}
30023001
30033002// For given directory path, substitute it to valid index file.
30043003// Return 0 if index file has been found, -1 if not found.
30053004// If the file is found, it's stats is returned in stp.
30063005static int find_index_file(struct connection *conn, char *path,
3007                           size_t path_len, file_stat_t *stp) {
3008  const char *list = conn->server->config_options[INDEX_FILES];
3009  file_stat_t st;
3010  struct vec filename_vec;
3011  size_t n = strlen(path), found = 0;
3006                     size_t path_len, file_stat_t *stp) {
3007   const char *list = conn->server->config_options[INDEX_FILES];
3008   file_stat_t st;
3009   struct vec filename_vec;
3010   size_t n = strlen(path), found = 0;
30123011
3013  // The 'path' given to us points to the directory. Remove all trailing
3014  // directory separator characters from the end of the path, and
3015  // then append single directory separator character.
3016  while (n > 0 && path[n - 1] == '/') {
3017    n--;
3018  }
3019  path[n] = '/';
3012   // The 'path' given to us points to the directory. Remove all trailing
3013   // directory separator characters from the end of the path, and
3014   // then append single directory separator character.
3015   while (n > 0 && path[n - 1] == '/') {
3016   n--;
3017   }
3018   path[n] = '/';
30203019
3021  // Traverse index files list. For each entry, append it to the given
3022  // path and see if the file exists. If it exists, break the loop
3023  while ((list = next_option(list, &filename_vec, NULL)) != NULL) {
3020   // Traverse index files list. For each entry, append it to the given
3021   // path and see if the file exists. If it exists, break the loop
3022   while ((list = next_option(list, &filename_vec, NULL)) != NULL) {
3023   // Ignore too long entries that may overflow path buffer
3024   if (filename_vec.len > (int) (path_len - (n + 2)))
3025      continue;
30243026
3025    // Ignore too long entries that may overflow path buffer
3026    if (filename_vec.len > (int) (path_len - (n + 2)))
3027      continue;
3027   // Prepare full path to the index file
3028   strncpy(path + n + 1, filename_vec.ptr, filename_vec.len);
3029   path[n + 1 + filename_vec.len] = '\0';
30283030
3029    // Prepare full path to the index file
3030    strncpy(path + n + 1, filename_vec.ptr, filename_vec.len);
3031    path[n + 1 + filename_vec.len] = '\0';
3031   //DBG(("[%s]", path));
30323032
3033    //DBG(("[%s]", path));
3033   // Does it exist?
3034   if (!stat(path, &st)) {
3035      // Yes it does, break the loop
3036      *stp = st;
3037      found = 1;
3038      break;
3039   }
3040   }
30343041
3035    // Does it exist?
3036    if (!stat(path, &st)) {
3037      // Yes it does, break the loop
3038      *stp = st;
3039      found = 1;
3040      break;
3041    }
3042  }
3042   // If no index file exists, restore directory path
3043   if (!found) {
3044   path[n] = '\0';
3045   }
30433046
3044  // If no index file exists, restore directory path
3045  if (!found) {
3046    path[n] = '\0';
3047  }
3048
3049  return found;
3047   return found;
30503048}
30513049
30523050static int parse_range_header(const char *header, int64_t *a, int64_t *b) {
3053  return sscanf(header, "bytes=%" INT64_FMT "-%" INT64_FMT, a, b);
3051   return sscanf(header, "bytes=%" INT64_FMT "-%" INT64_FMT, a, b);
30543052}
30553053
30563054static void gmt_time_string(char *buf, size_t buf_len, time_t *t) {
3057  strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S GMT", gmtime(t));
3055   strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S GMT", gmtime(t));
30583056}
30593057
30603058static void open_file_endpoint(struct connection *conn, const char *path,
3061                               file_stat_t *st) {
3062  char date[64], lm[64], etag[64], range[64], headers[500];
3063  const char *msg = "OK", *hdr;
3064  time_t curtime = time(NULL);
3065  int64_t r1, r2;
3066  struct vec mime_vec;
3067  int n;
3059                        file_stat_t *st) {
3060   char date[64], lm[64], etag[64], range[64], headers[500];
3061   const char *msg = "OK", *hdr;
3062   time_t curtime = time(NULL);
3063   int64_t r1, r2;
3064   struct vec mime_vec;
3065   int n;
30683066
3069  conn->endpoint_type = EP_FILE;
3070  ns_set_close_on_exec(conn->endpoint.fd);
3071  conn->mg_conn.status_code = 200;
3067   conn->endpoint_type = EP_FILE;
3068   ns_set_close_on_exec(conn->endpoint.fd);
3069   conn->mg_conn.status_code = 200;
30723070
3073  get_mime_type(conn->server, path, &mime_vec);
3074  conn->cl = st->st_size;
3075  range[0] = '\0';
3071   get_mime_type(conn->server, path, &mime_vec);
3072   conn->cl = st->st_size;
3073   range[0] = '\0';
30763074
3077  // If Range: header specified, act accordingly
3078  r1 = r2 = 0;
3079  hdr = mg_get_header(&conn->mg_conn, "Range");
3080  if (hdr != NULL && (n = parse_range_header(hdr, &r1, &r2)) > 0 &&
3081      r1 >= 0 && r2 >= 0) {
3082    conn->mg_conn.status_code = 206;
3083    conn->cl = n == 2 ? (r2 > conn->cl ? conn->cl : r2) - r1 + 1: conn->cl - r1;
3084    mg_snprintf(range, sizeof(range), "Content-Range: bytes "
3085                "%" INT64_FMT "-%" INT64_FMT "/%" INT64_FMT "\r\n",
3086                r1, r1 + conn->cl - 1, (int64_t) st->st_size);
3087    msg = "Partial Content";
3088    lseek(conn->endpoint.fd, r1, SEEK_SET);
3089  }
3075   // If Range: header specified, act accordingly
3076   r1 = r2 = 0;
3077   hdr = mg_get_header(&conn->mg_conn, "Range");
3078   if (hdr != NULL && (n = parse_range_header(hdr, &r1, &r2)) > 0 &&
3079      r1 >= 0 && r2 >= 0) {
3080   conn->mg_conn.status_code = 206;
3081   conn->cl = n == 2 ? (r2 > conn->cl ? conn->cl : r2) - r1 + 1: conn->cl - r1;
3082   mg_snprintf(range, sizeof(range), "Content-Range: bytes "
3083            "%" INT64_FMT "-%" INT64_FMT "/%" INT64_FMT "\r\n",
3084            r1, r1 + conn->cl - 1, (int64_t) st->st_size);
3085   msg = "Partial Content";
3086   lseek(conn->endpoint.fd, r1, SEEK_SET);
3087   }
30903088
3091  // Prepare Etag, Date, Last-Modified headers. Must be in UTC, according to
3092  // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3
3093  gmt_time_string(date, sizeof(date), &curtime);
3094  gmt_time_string(lm, sizeof(lm), &st->st_mtime);
3095  construct_etag(etag, sizeof(etag), st);
3089   // Prepare Etag, Date, Last-Modified headers. Must be in UTC, according to
3090   // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3
3091   gmt_time_string(date, sizeof(date), &curtime);
3092   gmt_time_string(lm, sizeof(lm), &st->st_mtime);
3093   construct_etag(etag, sizeof(etag), st);
30963094
3097  n = mg_snprintf(headers, sizeof(headers),
3098                  "HTTP/1.1 %d %s\r\n"
3099                  "Date: %s\r\n"
3100                  "Last-Modified: %s\r\n"
3101                  "Etag: %s\r\n"
3102                  "Content-Type: %.*s\r\n"
3103                  "Content-Length: %" INT64_FMT "\r\n"
3104                  "Connection: %s\r\n"
3105                  "Accept-Ranges: bytes\r\n"
3106                  "%s%s\r\n",
3107                  conn->mg_conn.status_code, msg, date, lm, etag,
3108                  (int) mime_vec.len, mime_vec.ptr, conn->cl,
3109                  suggest_connection_header(&conn->mg_conn),
3110                  range, MONGOOSE_USE_EXTRA_HTTP_HEADERS);
3111  ns_send(conn->ns_conn, headers, n);
3095   n = mg_snprintf(headers, sizeof(headers),
3096               "HTTP/1.1 %d %s\r\n"
3097               "Date: %s\r\n"
3098               "Last-Modified: %s\r\n"
3099               "Etag: %s\r\n"
3100               "Content-Type: %.*s\r\n"
3101               "Content-Length: %" INT64_FMT "\r\n"
3102               "Connection: %s\r\n"
3103               "Accept-Ranges: bytes\r\n"
3104               "%s%s\r\n",
3105               conn->mg_conn.status_code, msg, date, lm, etag,
3106               (int) mime_vec.len, mime_vec.ptr, conn->cl,
3107               suggest_connection_header(&conn->mg_conn),
3108               range, MONGOOSE_USE_EXTRA_HTTP_HEADERS);
3109   ns_send(conn->ns_conn, headers, n);
31123110
3113  if (!strcmp(conn->mg_conn.request_method, "HEAD")) {
3114    conn->ns_conn->flags |= NSF_FINISHED_SENDING_DATA;
3115    close(conn->endpoint.fd);
3116    conn->endpoint_type = EP_NONE;
3117  }
3111   if (!strcmp(conn->mg_conn.request_method, "HEAD")) {
3112   conn->ns_conn->flags |= NSF_FINISHED_SENDING_DATA;
3113   close(conn->endpoint.fd);
3114   conn->endpoint_type = EP_NONE;
3115   }
31183116}
31193117
31203118void mg_send_file_data(struct mg_connection *c, int fd) {
3121  struct connection *conn = MG_CONN_2_CONN(c);
3122  conn->endpoint_type = EP_FILE;
3123  conn->endpoint.fd = fd;
3124  ns_set_close_on_exec(conn->endpoint.fd);
3119   struct connection *conn = MG_CONN_2_CONN(c);
3120   conn->endpoint_type = EP_FILE;
3121   conn->endpoint.fd = fd;
3122   ns_set_close_on_exec(conn->endpoint.fd);
31253123}
31263124#endif  // MONGOOSE_NO_FILESYSTEM
31273125
31283126static void call_request_handler_if_data_is_buffered(struct connection *conn) {
31293127#ifndef MONGOOSE_NO_WEBSOCKET
3130  if (conn->mg_conn.is_websocket) {
3131    do { } while (deliver_websocket_frame(conn));
3132  } else
3128   if (conn->mg_conn.is_websocket) {
3129   do { } while (deliver_websocket_frame(conn));
3130   } else
31333131#endif
3134  if (conn->num_bytes_recv >= (conn->cl + conn->request_len) &&
3135      call_request_handler(conn) == MG_FALSE) {
3136    open_local_endpoint(conn, 1);
3137  }
3132   if (conn->num_bytes_recv >= (conn->cl + conn->request_len) &&
3133      call_request_handler(conn) == MG_FALSE) {
3134   open_local_endpoint(conn, 1);
3135   }
31383136}
31393137
31403138#if !defined(MONGOOSE_NO_DIRECTORY_LISTING) || !defined(MONGOOSE_NO_DAV)
31413139
31423140#ifdef _WIN32
31433141struct dirent {
3144  char d_name[MAX_PATH_SIZE];
3142   char d_name[MAX_PATH_SIZE];
31453143};
31463144
31473145typedef struct DIR {
3148  HANDLE   handle;
3149  WIN32_FIND_DATAW info;
3150  struct dirent result;
3146   HANDLE   handle;
3147   WIN32_FIND_DATAW info;
3148   struct dirent result;
31513149} DIR;
31523150
31533151// Implementation of POSIX opendir/closedir/readdir for Windows.
31543152static DIR *opendir(const char *name) {
3155  DIR *dir = NULL;
3156  wchar_t wpath[MAX_PATH_SIZE];
3157  DWORD attrs;
3153   DIR *dir = NULL;
3154   wchar_t wpath[MAX_PATH_SIZE];
3155   DWORD attrs;
31583156
3159  if (name == NULL) {
3160    SetLastError(ERROR_BAD_ARGUMENTS);
3161  } else if ((dir = (DIR *) malloc(sizeof(*dir))) == NULL) {
3162    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
3163  } else {
3164    to_wchar(name, wpath, ARRAY_SIZE(wpath));
3165    attrs = GetFileAttributesW(wpath);
3166    if (attrs != 0xFFFFFFFF &&
3167        ((attrs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)) {
3168      (void) wcscat(wpath, L"\\*");
3169      dir->handle = FindFirstFileW(wpath, &dir->info);
3170      dir->result.d_name[0] = '\0';
3171    } else {
3172      free(dir);
3173      dir = NULL;
3174    }
3175  }
3157   if (name == NULL) {
3158   SetLastError(ERROR_BAD_ARGUMENTS);
3159   } else if ((dir = (DIR *) malloc(sizeof(*dir))) == NULL) {
3160   SetLastError(ERROR_NOT_ENOUGH_MEMORY);
3161   } else {
3162   to_wchar(name, wpath, ARRAY_SIZE(wpath));
3163   attrs = GetFileAttributesW(wpath);
3164   if (attrs != 0xFFFFFFFF &&
3165      ((attrs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)) {
3166      (void) wcscat(wpath, L"\\*");
3167      dir->handle = FindFirstFileW(wpath, &dir->info);
3168      dir->result.d_name[0] = '\0';
3169   } else {
3170      free(dir);
3171      dir = NULL;
3172   }
3173   }
31763174
3177  return dir;
3175   return dir;
31783176}
31793177
31803178static int closedir(DIR *dir) {
3181  int result = 0;
3179   int result = 0;
31823180
3183  if (dir != NULL) {
3184    if (dir->handle != INVALID_HANDLE_VALUE)
3185      result = FindClose(dir->handle) ? 0 : -1;
3181   if (dir != NULL) {
3182   if (dir->handle != INVALID_HANDLE_VALUE)
3183      result = FindClose(dir->handle) ? 0 : -1;
31863184
3187    free(dir);
3188  } else {
3189    result = -1;
3190    SetLastError(ERROR_BAD_ARGUMENTS);
3191  }
3185   free(dir);
3186   } else {
3187   result = -1;
3188   SetLastError(ERROR_BAD_ARGUMENTS);
3189   }
31923190
3193  return result;
3191   return result;
31943192}
31953193
31963194static struct dirent *readdir(DIR *dir) {
3197  struct dirent *result = 0;
3195   struct dirent *result = 0;
31983196
3199  if (dir) {
3200    if (dir->handle != INVALID_HANDLE_VALUE) {
3201      result = &dir->result;
3202      (void) WideCharToMultiByte(CP_UTF8, 0,
3203          dir->info.cFileName, -1, result->d_name,
3204          sizeof(result->d_name), NULL, NULL);
3197   if (dir) {
3198   if (dir->handle != INVALID_HANDLE_VALUE) {
3199      result = &dir->result;
3200      (void) WideCharToMultiByte(CP_UTF8, 0,
3201         dir->info.cFileName, -1, result->d_name,
3202         sizeof(result->d_name), NULL, NULL);
32053203
3206      if (!FindNextFileW(dir->handle, &dir->info)) {
3207        (void) FindClose(dir->handle);
3208        dir->handle = INVALID_HANDLE_VALUE;
3209      }
3204      if (!FindNextFileW(dir->handle, &dir->info)) {
3205      (void) FindClose(dir->handle);
3206      dir->handle = INVALID_HANDLE_VALUE;
3207      }
32103208
3211    } else {
3212      SetLastError(ERROR_FILE_NOT_FOUND);
3213    }
3214  } else {
3215    SetLastError(ERROR_BAD_ARGUMENTS);
3216  }
3209   } else {
3210      SetLastError(ERROR_FILE_NOT_FOUND);
3211   }
3212   } else {
3213   SetLastError(ERROR_BAD_ARGUMENTS);
3214   }
32173215
3218  return result;
3216   return result;
32193217}
32203218#endif // _WIN32  POSIX opendir/closedir/readdir implementation
32213219
32223220static int scan_directory(struct connection *conn, const char *dir,
3223                          struct dir_entry **arr) {
3224  char path[MAX_PATH_SIZE];
3225  struct dir_entry *p;
3226  struct dirent *dp;
3227  int arr_size = 0, arr_ind = 0, inc = 100;
3228  DIR *dirp;
3221                     struct dir_entry **arr) {
3222   char path[MAX_PATH_SIZE];
3223   struct dir_entry *p;
3224   struct dirent *dp;
3225   int arr_size = 0, arr_ind = 0, inc = 100;
3226   DIR *dirp;
32293227
3230  *arr = NULL;
3231  if ((dirp = (opendir(dir))) == NULL) return 0;
3228   *arr = NULL;
3229   if ((dirp = (opendir(dir))) == NULL) return 0;
32323230
3233  while ((dp = readdir(dirp)) != NULL) {
3234    // Do not show current dir and hidden files
3235    if (!strcmp(dp->d_name, ".") ||
3236        !strcmp(dp->d_name, "..") ||
3237        must_hide_file(conn, dp->d_name)) {
3238      continue;
3239    }
3240    mg_snprintf(path, sizeof(path), "%s%c%s", dir, '/', dp->d_name);
3231   while ((dp = readdir(dirp)) != NULL) {
3232   // Do not show current dir and hidden files
3233   if (!strcmp(dp->d_name, ".") ||
3234      !strcmp(dp->d_name, "..") ||
3235      must_hide_file(conn, dp->d_name)) {
3236      continue;
3237   }
3238   mg_snprintf(path, sizeof(path), "%s%c%s", dir, '/', dp->d_name);
32413239
3242    // Resize the array if nesessary
3243    if (arr_ind >= arr_size) {
3244      if ((p = (struct dir_entry *)
3245           realloc(*arr, (inc + arr_size) * sizeof(**arr))) != NULL) {
3246        // Memset new chunk to zero, otherwize st_mtime will have garbage which
3247        // can make strftime() segfault, see
3248        // http://code.google.com/p/mongoose/issues/detail?id=79
3249        memset(p + arr_size, 0, sizeof(**arr) * inc);
3240   // Resize the array if nesessary
3241   if (arr_ind >= arr_size) {
3242      if ((p = (struct dir_entry *)
3243         realloc(*arr, (inc + arr_size) * sizeof(**arr))) != NULL) {
3244      // Memset new chunk to zero, otherwize st_mtime will have garbage which
3245      // can make strftime() segfault, see
3246      // http://code.google.com/p/mongoose/issues/detail?id=79
3247      memset(p + arr_size, 0, sizeof(**arr) * inc);
32503248
3251        *arr = p;
3252        arr_size += inc;
3253      }
3254    }
3249      *arr = p;
3250      arr_size += inc;
3251      }
3252   }
32553253
3256    if (arr_ind < arr_size) {
3257      (*arr)[arr_ind].conn = conn;
3258      (*arr)[arr_ind].file_name = strdup(dp->d_name);
3259      stat(path, &(*arr)[arr_ind].st);
3260      arr_ind++;
3261    }
3262  }
3263  closedir(dirp);
3254   if (arr_ind < arr_size) {
3255      (*arr)[arr_ind].conn = conn;
3256      (*arr)[arr_ind].file_name = strdup(dp->d_name);
3257      stat(path, &(*arr)[arr_ind].st);
3258      arr_ind++;
3259   }
3260   }
3261   closedir(dirp);
32643262
3265  return arr_ind;
3263   return arr_ind;
32663264}
32673265
32683266int mg_url_encode(const char *src, size_t s_len, char *dst, size_t dst_len) {
3269  static const char *dont_escape = "._-$,;~()";
3270  static const char *hex = "0123456789abcdef";
3271  size_t i = 0, j = 0;
3267   static const char *dont_escape = "._-$,;~()";
3268   static const char *hex = "0123456789abcdef";
3269   size_t i = 0, j = 0;
32723270
3273  for (i = j = 0; dst_len > 0 && i < s_len && j + 2 < dst_len - 1; i++, j++) {
3274    if (isalnum(* (const unsigned char *) (src + i)) ||
3275        strchr(dont_escape, * (const unsigned char *) (src + i)) != NULL) {
3276      dst[j] = src[i];
3277    } else if (j + 3 < dst_len) {
3278      dst[j] = '%';
3279      dst[j + 1] = hex[(* (const unsigned char *) (src + i)) >> 4];
3280      dst[j + 2] = hex[(* (const unsigned char *) (src + i)) & 0xf];
3281      j += 2;
3282    }
3283  }
3271   for (i = j = 0; dst_len > 0 && i < s_len && j + 2 < dst_len - 1; i++, j++) {
3272   if (isalnum(* (const unsigned char *) (src + i)) ||
3273      strchr(dont_escape, * (const unsigned char *) (src + i)) != NULL) {
3274      dst[j] = src[i];
3275   } else if (j + 3 < dst_len) {
3276      dst[j] = '%';
3277      dst[j + 1] = hex[(* (const unsigned char *) (src + i)) >> 4];
3278      dst[j + 2] = hex[(* (const unsigned char *) (src + i)) & 0xf];
3279      j += 2;
3280   }
3281   }
32843282
3285  dst[j] = '\0';
3286  return j;
3283   dst[j] = '\0';
3284   return j;
32873285}
32883286#endif  // !NO_DIRECTORY_LISTING || !MONGOOSE_NO_DAV
32893287
32903288#ifndef MONGOOSE_NO_DIRECTORY_LISTING
32913289
32923290static void print_dir_entry(const struct dir_entry *de) {
3293  char size[64], mod[64], href[MAX_PATH_SIZE * 3];
3294  int64_t fsize = de->st.st_size;
3295  int is_dir = S_ISDIR(de->st.st_mode);
3296  const char *slash = is_dir ? "/" : "";
3291   char size[64], mod[64], href[MAX_PATH_SIZE * 3];
3292   int64_t fsize = de->st.st_size;
3293   int is_dir = S_ISDIR(de->st.st_mode);
3294   const char *slash = is_dir ? "/" : "";
32973295
3298  if (is_dir) {
3299    mg_snprintf(size, sizeof(size), "%s", "[DIRECTORY]");
3300  } else {
3301     // We use (signed) cast below because MSVC 6 compiler cannot
3302     // convert unsigned __int64 to double.
3303    if (fsize < 1024) {
3304      mg_snprintf(size, sizeof(size), "%d", (int) fsize);
3305    } else if (fsize < 0x100000) {
3306      mg_snprintf(size, sizeof(size), "%.1fk", (double) fsize / 1024.0);
3307    } else if (fsize < 0x40000000) {
3308      mg_snprintf(size, sizeof(size), "%.1fM", (double) fsize / 1048576);
3309    } else {
3310      mg_snprintf(size, sizeof(size), "%.1fG", (double) fsize / 1073741824);
3311    }
3312  }
3313  strftime(mod, sizeof(mod), "%d-%b-%Y %H:%M", localtime(&de->st.st_mtime));
3314  mg_url_encode(de->file_name, strlen(de->file_name), href, sizeof(href));
3315  mg_printf_data(&de->conn->mg_conn,
3316                  "<tr><td><a href=\"%s%s\">%s%s</a></td>"
3317                  "<td>&nbsp;%s</td><td>&nbsp;&nbsp;%s</td></tr>\n",
3318                  href, slash, de->file_name, slash, mod, size);
3296   if (is_dir) {
3297   mg_snprintf(size, sizeof(size), "%s", "[DIRECTORY]");
3298   } else {
3299      // We use (signed) cast below because MSVC 6 compiler cannot
3300      // convert unsigned __int64 to double.
3301   if (fsize < 1024) {
3302      mg_snprintf(size, sizeof(size), "%d", (int) fsize);
3303   } else if (fsize < 0x100000) {
3304      mg_snprintf(size, sizeof(size), "%.1fk", (double) fsize / 1024.0);
3305   } else if (fsize < 0x40000000) {
3306      mg_snprintf(size, sizeof(size), "%.1fM", (double) fsize / 1048576);
3307   } else {
3308      mg_snprintf(size, sizeof(size), "%.1fG", (double) fsize / 1073741824);
3309   }
3310   }
3311   strftime(mod, sizeof(mod), "%d-%b-%Y %H:%M", localtime(&de->st.st_mtime));
3312   mg_url_encode(de->file_name, strlen(de->file_name), href, sizeof(href));
3313   mg_printf_data(&de->conn->mg_conn,
3314               "<tr><td><a href=\"%s%s\">%s%s</a></td>"
3315               "<td>&nbsp;%s</td><td>&nbsp;&nbsp;%s</td></tr>\n",
3316               href, slash, de->file_name, slash, mod, size);
33193317}
33203318
33213319// Sort directory entries by size, or name, or modification time.
33223320// On windows, __cdecl specification is needed in case if project is built
33233321// with __stdcall convention. qsort always requires __cdels callback.
33243322static int __cdecl compare_dir_entries(const void *p1, const void *p2) {
3325  const struct dir_entry *a = (const struct dir_entry *) p1,
3326        *b = (const struct dir_entry *) p2;
3327  const char *qs = a->conn->mg_conn.query_string ?
3328    a->conn->mg_conn.query_string : "na";
3329  int cmp_result = 0;
3323   const struct dir_entry *a = (const struct dir_entry *) p1,
3324      *b = (const struct dir_entry *) p2;
3325   const char *qs = a->conn->mg_conn.query_string ?
3326   a->conn->mg_conn.query_string : "na";
3327   int cmp_result = 0;
33303328
3331  if (S_ISDIR(a->st.st_mode) && !S_ISDIR(b->st.st_mode)) {
3332    return -1;  // Always put directories on top
3333  } else if (!S_ISDIR(a->st.st_mode) && S_ISDIR(b->st.st_mode)) {
3334    return 1;   // Always put directories on top
3335  } else if (*qs == 'n') {
3336    cmp_result = strcmp(a->file_name, b->file_name);
3337  } else if (*qs == 's') {
3338    cmp_result = a->st.st_size == b->st.st_size ? 0 :
3339      a->st.st_size > b->st.st_size ? 1 : -1;
3340  } else if (*qs == 'd') {
3341    cmp_result = a->st.st_mtime == b->st.st_mtime ? 0 :
3342      a->st.st_mtime > b->st.st_mtime ? 1 : -1;
3343  }
3329   if (S_ISDIR(a->st.st_mode) && !S_ISDIR(b->st.st_mode)) {
3330   return -1;  // Always put directories on top
3331   } else if (!S_ISDIR(a->st.st_mode) && S_ISDIR(b->st.st_mode)) {
3332   return 1;   // Always put directories on top
3333   } else if (*qs == 'n') {
3334   cmp_result = strcmp(a->file_name, b->file_name);
3335   } else if (*qs == 's') {
3336   cmp_result = a->st.st_size == b->st.st_size ? 0 :
3337      a->st.st_size > b->st.st_size ? 1 : -1;
3338   } else if (*qs == 'd') {
3339   cmp_result = a->st.st_mtime == b->st.st_mtime ? 0 :
3340      a->st.st_mtime > b->st.st_mtime ? 1 : -1;
3341   }
33443342
3345  return qs[1] == 'd' ? -cmp_result : cmp_result;
3343   return qs[1] == 'd' ? -cmp_result : cmp_result;
33463344}
33473345
33483346static void send_directory_listing(struct connection *conn, const char *dir) {
3349  struct dir_entry *arr = NULL;
3350  int i, num_entries, sort_direction = conn->mg_conn.query_string != NULL &&
3351    conn->mg_conn.query_string[1] == 'd' ? 'a' : 'd';
3347   struct dir_entry *arr = NULL;
3348   int i, num_entries, sort_direction = conn->mg_conn.query_string != NULL &&
3349   conn->mg_conn.query_string[1] == 'd' ? 'a' : 'd';
33523350
3353  mg_send_header(&conn->mg_conn, "Transfer-Encoding", "chunked");
3354  mg_send_header(&conn->mg_conn, "Content-Type", "text/html; charset=utf-8");
3351   mg_send_header(&conn->mg_conn, "Transfer-Encoding", "chunked");
3352   mg_send_header(&conn->mg_conn, "Content-Type", "text/html; charset=utf-8");
33553353
3356  mg_printf_data(&conn->mg_conn,
3357              "<html><head><title>Index of %s</title>"
3358              "<style>th {text-align: left;}</style></head>"
3359              "<body><h1>Index of %s</h1><pre><table cellpadding=\"0\">"
3360              "<tr><th><a href=\"?n%c\">Name</a></th>"
3361              "<th><a href=\"?d%c\">Modified</a></th>"
3362              "<th><a href=\"?s%c\">Size</a></th></tr>"
3363              "<tr><td colspan=\"3\"><hr></td></tr>",
3364              conn->mg_conn.uri, conn->mg_conn.uri,
3365              sort_direction, sort_direction, sort_direction);
3354   mg_printf_data(&conn->mg_conn,
3355            "<html><head><title>Index of %s</title>"
3356            "<style>th {text-align: left;}</style></head>"
3357            "<body><h1>Index of %s</h1><pre><table cellpadding=\"0\">"
3358            "<tr><th><a href=\"?n%c\">Name</a></th>"
3359            "<th><a href=\"?d%c\">Modified</a></th>"
3360            "<th><a href=\"?s%c\">Size</a></th></tr>"
3361            "<tr><td colspan=\"3\"><hr></td></tr>",
3362            conn->mg_conn.uri, conn->mg_conn.uri,
3363            sort_direction, sort_direction, sort_direction);
33663364
3367  num_entries = scan_directory(conn, dir, &arr);
3368  qsort(arr, num_entries, sizeof(arr[0]), compare_dir_entries);
3369  for (i = 0; i < num_entries; i++) {
3370    print_dir_entry(&arr[i]);
3371    free(arr[i].file_name);
3372  }
3373  free(arr);
3365   num_entries = scan_directory(conn, dir, &arr);
3366   qsort(arr, num_entries, sizeof(arr[0]), compare_dir_entries);
3367   for (i = 0; i < num_entries; i++) {
3368   print_dir_entry(&arr[i]);
3369   free(arr[i].file_name);
3370   }
3371   free(arr);
33743372
3375  write_terminating_chunk(conn);
3376  close_local_endpoint(conn);
3373   write_terminating_chunk(conn);
3374   close_local_endpoint(conn);
33773375}
33783376#endif  // MONGOOSE_NO_DIRECTORY_LISTING
33793377
33803378#ifndef MONGOOSE_NO_DAV
33813379static void print_props(struct connection *conn, const char *uri,
3382                        file_stat_t *stp) {
3383  char mtime[64];
3380                  file_stat_t *stp) {
3381   char mtime[64];
33843382
3385  gmt_time_string(mtime, sizeof(mtime), &stp->st_mtime);
3386  mg_printf(&conn->mg_conn,
3387      "<d:response>"
3388       "<d:href>%s</d:href>"
3389       "<d:propstat>"
3390        "<d:prop>"
3391         "<d:resourcetype>%s</d:resourcetype>"
3392         "<d:getcontentlength>%" INT64_FMT "</d:getcontentlength>"
3393         "<d:getlastmodified>%s</d:getlastmodified>"
3394        "</d:prop>"
3395        "<d:status>HTTP/1.1 200 OK</d:status>"
3396       "</d:propstat>"
3397      "</d:response>\n",
3398      uri, S_ISDIR(stp->st_mode) ? "<d:collection/>" : "",
3399      (int64_t) stp->st_size, mtime);
3383   gmt_time_string(mtime, sizeof(mtime), &stp->st_mtime);
3384   mg_printf(&conn->mg_conn,
3385      "<d:response>"
3386      "<d:href>%s</d:href>"
3387      "<d:propstat>"
3388      "<d:prop>"
3389         "<d:resourcetype>%s</d:resourcetype>"
3390         "<d:getcontentlength>%" INT64_FMT "</d:getcontentlength>"
3391         "<d:getlastmodified>%s</d:getlastmodified>"
3392      "</d:prop>"
3393      "<d:status>HTTP/1.1 200 OK</d:status>"
3394      "</d:propstat>"
3395      "</d:response>\n",
3396      uri, S_ISDIR(stp->st_mode) ? "<d:collection/>" : "",
3397      (int64_t) stp->st_size, mtime);
34003398}
34013399
34023400static void handle_propfind(struct connection *conn, const char *path,
3403                            file_stat_t *stp, int exists) {
3404  static const char header[] = "HTTP/1.1 207 Multi-Status\r\n"
3405    "Connection: close\r\n"
3406    "Content-Type: text/xml; charset=utf-8\r\n\r\n"
3407    "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
3408    "<d:multistatus xmlns:d='DAV:'>\n";
3409  static const char footer[] = "</d:multistatus>";
3410  const char *depth = mg_get_header(&conn->mg_conn, "Depth"),
3411        *list_dir = conn->server->config_options[ENABLE_DIRECTORY_LISTING];
3401                     file_stat_t *stp, int exists) {
3402   static const char header[] = "HTTP/1.1 207 Multi-Status\r\n"
3403   "Connection: close\r\n"
3404   "Content-Type: text/xml; charset=utf-8\r\n\r\n"
3405   "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
3406   "<d:multistatus xmlns:d='DAV:'>\n";
3407   static const char footer[] = "</d:multistatus>";
3408   const char *depth = mg_get_header(&conn->mg_conn, "Depth"),
3409      *list_dir = conn->server->config_options[ENABLE_DIRECTORY_LISTING];
34123410
3413  conn->mg_conn.status_code = 207;
3411   conn->mg_conn.status_code = 207;
34143412
3415  // Print properties for the requested resource itself
3416  if (!exists) {
3417    conn->mg_conn.status_code = 404;
3418    mg_printf(&conn->mg_conn, "%s", "HTTP/1.1 404 Not Found\r\n\r\n");
3419  } else if (S_ISDIR(stp->st_mode) && mg_strcasecmp(list_dir, "yes") != 0) {
3420    conn->mg_conn.status_code = 403;
3421    mg_printf(&conn->mg_conn, "%s",
3422              "HTTP/1.1 403 Directory Listing Denied\r\n\r\n");
3423  } else {
3424    ns_send(conn->ns_conn, header, sizeof(header) - 1);
3425    print_props(conn, conn->mg_conn.uri, stp);
3413   // Print properties for the requested resource itself
3414   if (!exists) {
3415   conn->mg_conn.status_code = 404;
3416   mg_printf(&conn->mg_conn, "%s", "HTTP/1.1 404 Not Found\r\n\r\n");
3417   } else if (S_ISDIR(stp->st_mode) && mg_strcasecmp(list_dir, "yes") != 0) {
3418   conn->mg_conn.status_code = 403;
3419   mg_printf(&conn->mg_conn, "%s",
3420            "HTTP/1.1 403 Directory Listing Denied\r\n\r\n");
3421   } else {
3422   ns_send(conn->ns_conn, header, sizeof(header) - 1);
3423   print_props(conn, conn->mg_conn.uri, stp);
34263424
3427    if (S_ISDIR(stp->st_mode) &&
3428             (depth == NULL || strcmp(depth, "0") != 0)) {
3429      struct dir_entry *arr = NULL;
3430      int i, num_entries = scan_directory(conn, path, &arr);
3425   if (S_ISDIR(stp->st_mode) &&
3426            (depth == NULL || strcmp(depth, "0") != 0)) {
3427      struct dir_entry *arr = NULL;
3428      int i, num_entries = scan_directory(conn, path, &arr);
34313429
3432      for (i = 0; i < num_entries; i++) {
3433        char buf[MAX_PATH_SIZE * 3];
3434        struct dir_entry *de = &arr[i];
3435        mg_url_encode(de->file_name, strlen(de->file_name), buf, sizeof(buf));
3436        print_props(conn, buf, &de->st);
3437        free(de->file_name);
3438      }
3439      free(arr);
3440    }
3441    ns_send(conn->ns_conn, footer, sizeof(footer) - 1);
3442  }
3430      for (i = 0; i < num_entries; i++) {
3431      char buf[MAX_PATH_SIZE * 3];
3432      struct dir_entry *de = &arr[i];
3433      mg_url_encode(de->file_name, strlen(de->file_name), buf, sizeof(buf));
3434      print_props(conn, buf, &de->st);
3435      free(de->file_name);
3436      }
3437      free(arr);
3438   }
3439   ns_send(conn->ns_conn, footer, sizeof(footer) - 1);
3440   }
34433441
3444  close_local_endpoint(conn);
3442   close_local_endpoint(conn);
34453443}
34463444
34473445static void handle_mkcol(struct connection *conn, const char *path) {
3448  int status_code = 500;
3446   int status_code = 500;
34493447
3450  if (conn->mg_conn.content_len > 0) {
3451    status_code = 415;
3452  } else if (!mkdir(path, 0755)) {
3453    status_code = 201;
3454  } else if (errno == EEXIST) {
3455    status_code = 405;
3456  } else if (errno == EACCES) {
3457    status_code = 403;
3458  } else if (errno == ENOENT) {
3459    status_code = 409;
3460  }
3461  send_http_error(conn, status_code, NULL);
3448   if (conn->mg_conn.content_len > 0) {
3449   status_code = 415;
3450   } else if (!mkdir(path, 0755)) {
3451   status_code = 201;
3452   } else if (errno == EEXIST) {
3453   status_code = 405;
3454   } else if (errno == EACCES) {
3455   status_code = 403;
3456   } else if (errno == ENOENT) {
3457   status_code = 409;
3458   }
3459   send_http_error(conn, status_code, NULL);
34623460}
34633461
34643462static int remove_directory(const char *dir) {
3465  char path[MAX_PATH_SIZE];
3466  struct dirent *dp;
3467  file_stat_t st;
3468  DIR *dirp;
3463   char path[MAX_PATH_SIZE];
3464   struct dirent *dp;
3465   file_stat_t st;
3466   DIR *dirp;
34693467
3470  if ((dirp = opendir(dir)) == NULL) return 0;
3468   if ((dirp = opendir(dir)) == NULL) return 0;
34713469
3472  while ((dp = readdir(dirp)) != NULL) {
3473    if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue;
3474    mg_snprintf(path, sizeof(path), "%s%c%s", dir, '/', dp->d_name);
3475    stat(path, &st);
3476    if (S_ISDIR(st.st_mode)) {
3477      remove_directory(path);
3478    } else {
3479      remove(path);
3480    }
3481  }
3482  closedir(dirp);
3483  rmdir(dir);
3470   while ((dp = readdir(dirp)) != NULL) {
3471   if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue;
3472   mg_snprintf(path, sizeof(path), "%s%c%s", dir, '/', dp->d_name);
3473   stat(path, &st);
3474   if (S_ISDIR(st.st_mode)) {
3475      remove_directory(path);
3476   } else {
3477      remove(path);
3478   }
3479   }
3480   closedir(dirp);
3481   rmdir(dir);
34843482
3485  return 1;
3483   return 1;
34863484}
34873485
34883486static void handle_delete(struct connection *conn, const char *path) {
3489  file_stat_t st;
3487   file_stat_t st;
34903488
3491  if (stat(path, &st) != 0) {
3492    send_http_error(conn, 404, NULL);
3493  } else if (S_ISDIR(st.st_mode)) {
3494    remove_directory(path);
3495    send_http_error(conn, 204, NULL);
3496  } else if (remove(path) == 0) {
3497    send_http_error(conn, 204, NULL);
3498  } else {
3499    send_http_error(conn, 423, NULL);
3500  }
3489   if (stat(path, &st) != 0) {
3490   send_http_error(conn, 404, NULL);
3491   } else if (S_ISDIR(st.st_mode)) {
3492   remove_directory(path);
3493   send_http_error(conn, 204, NULL);
3494   } else if (remove(path) == 0) {
3495   send_http_error(conn, 204, NULL);
3496   } else {
3497   send_http_error(conn, 423, NULL);
3498   }
35013499}
35023500
35033501// For a given PUT path, create all intermediate subdirectories
35043502// for given path. Return 0 if the path itself is a directory,
35053503// or -1 on error, 1 if OK.
35063504static int put_dir(const char *path) {
3507  char buf[MAX_PATH_SIZE];
3508  const char *s, *p;
3509  file_stat_t st;
3505   char buf[MAX_PATH_SIZE];
3506   const char *s, *p;
3507   file_stat_t st;
35103508
3511  // Create intermediate directories if they do not exist
3512  for (s = p = path + 1; (p = strchr(s, '/')) != NULL; s = ++p) {
3513    if (p - path >= (int) sizeof(buf)) return -1; // Buffer overflow
3514    memcpy(buf, path, p - path);
3515    buf[p - path] = '\0';
3516    if (stat(buf, &st) != 0 && mkdir(buf, 0755) != 0) return -1;
3517    if (p[1] == '\0') return 0;  // Path is a directory itself
3518  }
3509   // Create intermediate directories if they do not exist
3510   for (s = p = path + 1; (p = strchr(s, '/')) != NULL; s = ++p) {
3511   if (p - path >= (int) sizeof(buf)) return -1; // Buffer overflow
3512   memcpy(buf, path, p - path);
3513   buf[p - path] = '\0';
3514   if (stat(buf, &st) != 0 && mkdir(buf, 0755) != 0) return -1;
3515   if (p[1] == '\0') return 0;  // Path is a directory itself
3516   }
35193517
3520  return 1;
3518   return 1;
35213519}
35223520
35233521static void handle_put(struct connection *conn, const char *path) {
3524  file_stat_t st;
3525  const char *range, *cl_hdr = mg_get_header(&conn->mg_conn, "Content-Length");
3526  int64_t r1, r2;
3527  int rc;
3522   file_stat_t st;
3523   const char *range, *cl_hdr = mg_get_header(&conn->mg_conn, "Content-Length");
3524   int64_t r1, r2;
3525   int rc;
35283526
3529  conn->mg_conn.status_code = !stat(path, &st) ? 200 : 201;
3530  if ((rc = put_dir(path)) == 0) {
3531    mg_printf(&conn->mg_conn, "HTTP/1.1 %d OK\r\n\r\n",
3532              conn->mg_conn.status_code);
3533    close_local_endpoint(conn);
3534  } else if (rc == -1) {
3535    send_http_error(conn, 500, "put_dir: %s", strerror(errno));
3536  } else if (cl_hdr == NULL) {
3537    send_http_error(conn, 411, NULL);
3527   conn->mg_conn.status_code = !stat(path, &st) ? 200 : 201;
3528   if ((rc = put_dir(path)) == 0) {
3529   mg_printf(&conn->mg_conn, "HTTP/1.1 %d OK\r\n\r\n",
3530            conn->mg_conn.status_code);
3531   close_local_endpoint(conn);
3532   } else if (rc == -1) {
3533   send_http_error(conn, 500, "put_dir: %s", strerror(errno));
3534   } else if (cl_hdr == NULL) {
3535   send_http_error(conn, 411, NULL);
35383536#ifdef _WIN32
3539    //On Windows, open() is a macro with 2 params
3540  } else if ((conn->endpoint.fd =
3541              open(path, O_RDWR | O_CREAT | O_TRUNC)) < 0) {
3537   //On Windows, open() is a macro with 2 params
3538   } else if ((conn->endpoint.fd =
3539            open(path, O_RDWR | O_CREAT | O_TRUNC)) < 0) {
35423540#else
3543  } else if ((conn->endpoint.fd =
3544              open(path, O_RDWR | O_CREAT | O_TRUNC, 0644)) < 0) {
3541   } else if ((conn->endpoint.fd =
3542            open(path, O_RDWR | O_CREAT | O_TRUNC, 0644)) < 0) {
35453543#endif
3546    send_http_error(conn, 500, "open(%s): %s", path, strerror(errno));
3547  } else {
3548    DBG(("PUT [%s] %lu", path, (unsigned long) conn->ns_conn->recv_iobuf.len));
3549    conn->endpoint_type = EP_PUT;
3550    ns_set_close_on_exec(conn->endpoint.fd);
3551    range = mg_get_header(&conn->mg_conn, "Content-Range");
3552    conn->cl = to64(cl_hdr);
3553    r1 = r2 = 0;
3554    if (range != NULL && parse_range_header(range, &r1, &r2) > 0) {
3555      conn->mg_conn.status_code = 206;
3556      lseek(conn->endpoint.fd, r1, SEEK_SET);
3557      conn->cl = r2 > r1 ? r2 - r1 + 1: conn->cl - r1;
3558    }
3559    mg_printf(&conn->mg_conn, "HTTP/1.1 %d OK\r\nContent-Length: 0\r\n\r\n",
3560              conn->mg_conn.status_code);
3561  }
3544   send_http_error(conn, 500, "open(%s): %s", path, strerror(errno));
3545   } else {
3546   DBG(("PUT [%s] %lu", path, (unsigned long) conn->ns_conn->recv_iobuf.len));
3547   conn->endpoint_type = EP_PUT;
3548   ns_set_close_on_exec(conn->endpoint.fd);
3549   range = mg_get_header(&conn->mg_conn, "Content-Range");
3550   conn->cl = to64(cl_hdr);
3551   r1 = r2 = 0;
3552   if (range != NULL && parse_range_header(range, &r1, &r2) > 0) {
3553      conn->mg_conn.status_code = 206;
3554      lseek(conn->endpoint.fd, r1, SEEK_SET);
3555      conn->cl = r2 > r1 ? r2 - r1 + 1: conn->cl - r1;
3556   }
3557   mg_printf(&conn->mg_conn, "HTTP/1.1 %d OK\r\nContent-Length: 0\r\n\r\n",
3558            conn->mg_conn.status_code);
3559   }
35623560}
35633561
35643562static void forward_put_data(struct connection *conn) {
3565  struct iobuf *io = &conn->ns_conn->recv_iobuf;
3566  size_t k = conn->cl < (int64_t) io->len ? conn->cl : (int64_t) io->len;   // To write
3567  int n = write(conn->endpoint.fd, io->buf, k);   // Write them!
3568  if (n > 0) {
3569    iobuf_remove(io, n);
3570    conn->cl -= n;
3571  }
3572  if (conn->cl <= 0) {
3573    close_local_endpoint(conn);
3574  }
3563   struct iobuf *io = &conn->ns_conn->recv_iobuf;
3564   size_t k = conn->cl < (int64_t) io->len ? conn->cl : (int64_t) io->len;   // To write
3565   int n = write(conn->endpoint.fd, io->buf, k);   // Write them!
3566   if (n > 0) {
3567   iobuf_remove(io, n);
3568   conn->cl -= n;
3569   }
3570   if (conn->cl <= 0) {
3571   close_local_endpoint(conn);
3572   }
35753573}
35763574#endif //  MONGOOSE_NO_DAV
35773575
35783576static void send_options(struct connection *conn) {
3579  conn->mg_conn.status_code = 200;
3580  mg_printf(&conn->mg_conn, "%s",
3581            "HTTP/1.1 200 OK\r\nAllow: GET, POST, HEAD, CONNECT, PUT, "
3582            "DELETE, OPTIONS, PROPFIND, MKCOL\r\nDAV: 1\r\n\r\n");
3583  close_local_endpoint(conn);
3577   conn->mg_conn.status_code = 200;
3578   mg_printf(&conn->mg_conn, "%s",
3579         "HTTP/1.1 200 OK\r\nAllow: GET, POST, HEAD, CONNECT, PUT, "
3580         "DELETE, OPTIONS, PROPFIND, MKCOL\r\nDAV: 1\r\n\r\n");
3581   close_local_endpoint(conn);
35843582}
35853583
35863584#ifndef MONGOOSE_NO_AUTH
35873585void mg_send_digest_auth_request(struct mg_connection *c) {
3588  struct connection *conn = MG_CONN_2_CONN(c);
3589  c->status_code = 401;
3590  mg_printf(c,
3591            "HTTP/1.1 401 Unauthorized\r\n"
3592            "WWW-Authenticate: Digest qop=\"auth\", "
3593            "realm=\"%s\", nonce=\"%lu\"\r\n\r\n",
3594            conn->server->config_options[AUTH_DOMAIN],
3595            (unsigned long) time(NULL));
3596  close_local_endpoint(conn);
3586   struct connection *conn = MG_CONN_2_CONN(c);
3587   c->status_code = 401;
3588   mg_printf(c,
3589         "HTTP/1.1 401 Unauthorized\r\n"
3590         "WWW-Authenticate: Digest qop=\"auth\", "
3591         "realm=\"%s\", nonce=\"%lu\"\r\n\r\n",
3592         conn->server->config_options[AUTH_DOMAIN],
3593         (unsigned long) time(NULL));
3594   close_local_endpoint(conn);
35973595}
35983596
35993597// Use the global passwords file, if specified by auth_gpass option,
36003598// or search for .htpasswd in the requested directory.
36013599static FILE *open_auth_file(struct connection *conn, const char *path,
3602                            int is_directory) {
3603  char name[MAX_PATH_SIZE];
3604  const char *p, *gpass = conn->server->config_options[GLOBAL_AUTH_FILE];
3605  FILE *fp = NULL;
3600                     int is_directory) {
3601   char name[MAX_PATH_SIZE];
3602   const char *p, *gpass = conn->server->config_options[GLOBAL_AUTH_FILE];
3603   FILE *fp = NULL;
36063604
3607  if (gpass != NULL) {
3608    // Use global passwords file
3609    fp = fopen(gpass, "r");
3610  } else if (is_directory) {
3611    mg_snprintf(name, sizeof(name), "%s%c%s", path, '/', PASSWORDS_FILE_NAME);
3612    fp = fopen(name, "r");
3613  } else {
3614    // Try to find .htpasswd in requested directory.
3615    if ((p = strrchr(path, '/')) == NULL) p = path;
3616    mg_snprintf(name, sizeof(name), "%.*s%c%s",
3617                (int) (p - path), path, '/', PASSWORDS_FILE_NAME);
3618    fp = fopen(name, "r");
3619  }
3605   if (gpass != NULL) {
3606   // Use global passwords file
3607   fp = fopen(gpass, "r");
3608   } else if (is_directory) {
3609   mg_snprintf(name, sizeof(name), "%s%c%s", path, '/', PASSWORDS_FILE_NAME);
3610   fp = fopen(name, "r");
3611   } else {
3612   // Try to find .htpasswd in requested directory.
3613   if ((p = strrchr(path, '/')) == NULL) p = path;
3614   mg_snprintf(name, sizeof(name), "%.*s%c%s",
3615            (int) (p - path), path, '/', PASSWORDS_FILE_NAME);
3616   fp = fopen(name, "r");
3617   }
36203618
3621  return fp;
3619   return fp;
36223620}
36233621
36243622#if !defined(HAVE_MD5) && !defined(MONGOOSE_NO_AUTH)
36253623typedef struct MD5Context {
3626  uint32_t buf[4];
3627  uint32_t bits[2];
3628  unsigned char in[64];
3624   uint32_t buf[4];
3625   uint32_t bits[2];
3626   unsigned char in[64];
36293627} MD5_CTX;
36303628
36313629static void byteReverse(unsigned char *buf, unsigned longs) {
3632  uint32_t t;
3630   uint32_t t;
36333631
3634  // Forrest: MD5 expect LITTLE_ENDIAN, swap if BIG_ENDIAN
3635  if (is_big_endian()) {
3636    do {
3637      t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
3638        ((unsigned) buf[1] << 8 | buf[0]);
3639      * (uint32_t *) buf = t;
3640      buf += 4;
3641    } while (--longs);
3642  }
3632   // Forrest: MD5 expect LITTLE_ENDIAN, swap if BIG_ENDIAN
3633   if (is_big_endian()) {
3634   do {
3635      t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
3636      ((unsigned) buf[1] << 8 | buf[0]);
3637      * (uint32_t *) buf = t;
3638      buf += 4;
3639   } while (--longs);
3640   }
36433641}
36443642
36453643#define F1(x, y, z) (z ^ (x & (y ^ z)))
r32760r32761
36483646#define F4(x, y, z) (y ^ (x | ~z))
36493647
36503648#define MD5STEP(f, w, x, y, z, data, s) \
3651  ( w += f(x, y, z) + data,  w = w<<s | w>>(32-s),  w += x )
3649   ( w += f(x, y, z) + data,  w = w<<s | w>>(32-s),  w += x )
36523650
36533651// Start MD5 accumulation.  Set bit count to 0 and buffer to mysterious
36543652// initialization constants.
36553653static void MD5Init(MD5_CTX *ctx) {
3656  ctx->buf[0] = 0x67452301;
3657  ctx->buf[1] = 0xefcdab89;
3658  ctx->buf[2] = 0x98badcfe;
3659  ctx->buf[3] = 0x10325476;
3654   ctx->buf[0] = 0x67452301;
3655   ctx->buf[1] = 0xefcdab89;
3656   ctx->buf[2] = 0x98badcfe;
3657   ctx->buf[3] = 0x10325476;
36603658
3661  ctx->bits[0] = 0;
3662  ctx->bits[1] = 0;
3659   ctx->bits[0] = 0;
3660   ctx->bits[1] = 0;
36633661}
36643662
36653663static void MD5Transform(uint32_t buf[4], uint32_t const in[16]) {
3666  register uint32_t a, b, c, d;
3664   register uint32_t a, b, c, d;
36673665
3668  a = buf[0];
3669  b = buf[1];
3670  c = buf[2];
3671  d = buf[3];
3666   a = buf[0];
3667   b = buf[1];
3668   c = buf[2];
3669   d = buf[3];
36723670
3673  MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
3674  MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
3675  MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
3676  MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
3677  MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
3678  MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
3679  MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
3680  MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
3681  MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
3682  MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
3683  MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
3684  MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
3685  MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
3686  MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
3687  MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
3688  MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
3671   MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
3672   MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
3673   MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
3674   MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
3675   MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
3676   MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
3677   MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
3678   MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
3679   MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
3680   MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
3681   MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
3682   MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
3683   MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
3684   MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
3685   MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
3686   MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
36893687
3690  MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
3691  MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
3692  MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
3693  MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
3694  MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
3695  MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
3696  MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
3697  MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
3698  MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
3699  MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
3700  MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
3701  MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
3702  MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
3703  MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
3704  MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
3705  MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
3688   MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
3689   MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
3690   MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
3691   MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
3692   MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
3693   MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
3694   MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
3695   MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
3696   MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
3697   MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
3698   MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
3699   MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
3700   MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
3701   MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
3702   MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
3703   MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
37063704
3707  MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
3708  MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
3709  MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
3710  MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
3711  MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
3712  MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
3713  MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
3714  MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
3715  MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
3716  MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
3717  MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
3718  MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
3719  MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
3720  MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
3721  MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
3722  MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
3705   MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
3706   MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
3707   MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
3708   MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
3709   MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
3710   MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
3711   MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
3712   MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
3713   MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
3714   MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
3715   MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
3716   MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
3717   MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
3718   MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
3719   MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
3720   MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
37233721
3724  MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
3725  MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
3726  MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
3727  MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
3728  MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
3729  MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
3730  MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
3731  MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
3732  MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
3733  MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
3734  MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
3735  MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
3736  MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
3737  MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
3738  MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
3739  MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
3722   MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
3723   MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
3724   MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
3725   MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
3726   MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
3727   MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
3728   MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
3729   MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
3730   MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
3731   MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
3732   MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
3733   MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
3734   MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
3735   MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
3736   MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
3737   MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
37403738
3741  buf[0] += a;
3742  buf[1] += b;
3743  buf[2] += c;
3744  buf[3] += d;
3739   buf[0] += a;
3740   buf[1] += b;
3741   buf[2] += c;
3742   buf[3] += d;
37453743}
37463744
37473745static void MD5Update(MD5_CTX *ctx, unsigned char const *buf, unsigned len) {
3748  uint32_t t;
3746   uint32_t t;
37493747
3750  t = ctx->bits[0];
3751  if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t)
3752    ctx->bits[1]++;
3753  ctx->bits[1] += len >> 29;
3748   t = ctx->bits[0];
3749   if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t)
3750   ctx->bits[1]++;
3751   ctx->bits[1] += len >> 29;
37543752
3755  t = (t >> 3) & 0x3f;
3753   t = (t >> 3) & 0x3f;
37563754
3757  if (t) {
3758    unsigned char *p = (unsigned char *) ctx->in + t;
3755   if (t) {
3756   unsigned char *p = (unsigned char *) ctx->in + t;
37593757
3760    t = 64 - t;
3761    if (len < t) {
3762      memcpy(p, buf, len);
3763      return;
3764    }
3765    memcpy(p, buf, t);
3766    byteReverse(ctx->in, 16);
3767    MD5Transform(ctx->buf, (uint32_t *) ctx->in);
3768    buf += t;
3769    len -= t;
3770  }
3758   t = 64 - t;
3759   if (len < t) {
3760      memcpy(p, buf, len);
3761      return;
3762   }
3763   memcpy(p, buf, t);
3764   byteReverse(ctx->in, 16);
3765   MD5Transform(ctx->buf, (uint32_t *) ctx->in);
3766   buf += t;
3767   len -= t;
3768   }
37713769
3772  while (len >= 64) {
3773    memcpy(ctx->in, buf, 64);
3774    byteReverse(ctx->in, 16);
3775    MD5Transform(ctx->buf, (uint32_t *) ctx->in);
3776    buf += 64;
3777    len -= 64;
3778  }
3770   while (len >= 64) {
3771   memcpy(ctx->in, buf, 64);
3772   byteReverse(ctx->in, 16);
3773   MD5Transform(ctx->buf, (uint32_t *) ctx->in);
3774   buf += 64;
3775   len -= 64;
3776   }
37793777
3780  memcpy(ctx->in, buf, len);
3778   memcpy(ctx->in, buf, len);
37813779}
37823780
37833781static void MD5Final(unsigned char digest[16], MD5_CTX *ctx) {
3784  unsigned count;
3785  unsigned char *p;
3786  uint32_t *a;
3782   unsigned count;
3783   unsigned char *p;
3784   uint32_t *a;
37873785
3788  count = (ctx->bits[0] >> 3) & 0x3F;
3786   count = (ctx->bits[0] >> 3) & 0x3F;
37893787
3790  p = ctx->in + count;
3791  *p++ = 0x80;
3792  count = 64 - 1 - count;
3793  if (count < 8) {
3794    memset(p, 0, count);
3795    byteReverse(ctx->in, 16);
3796    MD5Transform(ctx->buf, (uint32_t *) ctx->in);
3797    memset(ctx->in, 0, 56);
3798  } else {
3799    memset(p, 0, count - 8);
3800  }
3801  byteReverse(ctx->in, 14);
3788   p = ctx->in + count;
3789   *p++ = 0x80;
3790   count = 64 - 1 - count;
3791   if (count < 8) {
3792   memset(p, 0, count);
3793   byteReverse(ctx->in, 16);
3794   MD5Transform(ctx->buf, (uint32_t *) ctx->in);
3795   memset(ctx->in, 0, 56);
3796   } else {
3797   memset(p, 0, count - 8);
3798   }
3799   byteReverse(ctx->in, 14);
38023800
3803  a = (uint32_t *)ctx->in;
3804  a[14] = ctx->bits[0];
3805  a[15] = ctx->bits[1];
3801   a = (uint32_t *)ctx->in;
3802   a[14] = ctx->bits[0];
3803   a[15] = ctx->bits[1];
38063804
3807  MD5Transform(ctx->buf, (uint32_t *) ctx->in);
3808  byteReverse((unsigned char *) ctx->buf, 4);
3809  memcpy(digest, ctx->buf, 16);
3810  memset((char *) ctx, 0, sizeof(*ctx));
3805   MD5Transform(ctx->buf, (uint32_t *) ctx->in);
3806   byteReverse((unsigned char *) ctx->buf, 4);
3807   memcpy(digest, ctx->buf, 16);
3808   memset((char *) ctx, 0, sizeof(*ctx));
38113809}
38123810#endif // !HAVE_MD5
38133811
r32760r32761
38163814// Stringify binary data. Output buffer must be twice as big as input,
38173815// because each byte takes 2 bytes in string representation
38183816static void bin2str(char *to, const unsigned char *p, size_t len) {
3819  static const char *hex = "0123456789abcdef";
3817   static const char *hex = "0123456789abcdef";
38203818
3821  for (; len--; p++) {
3822    *to++ = hex[p[0] >> 4];
3823    *to++ = hex[p[0] & 0x0f];
3824  }
3825  *to = '\0';
3819   for (; len--; p++) {
3820   *to++ = hex[p[0] >> 4];
3821   *to++ = hex[p[0] & 0x0f];
3822   }
3823   *to = '\0';
38263824}
38273825
38283826// Return stringified MD5 hash for list of strings. Buffer must be 33 bytes.
38293827char *mg_md5(char buf[33], ...) {
3830  unsigned char hash[16];
3831  const char *p;
3832  va_list ap;
3833  MD5_CTX ctx;
3828   unsigned char hash[16];
3829   const char *p;
3830   va_list ap;
3831   MD5_CTX ctx;
38343832
3835  MD5Init(&ctx);
3833   MD5Init(&ctx);
38363834
3837  va_start(ap, buf);
3838  while ((p = va_arg(ap, const char *)) != NULL) {
3839    MD5Update(&ctx, (const unsigned char *) p, (unsigned) strlen(p));
3840  }
3841  va_end(ap);
3835   va_start(ap, buf);
3836   while ((p = va_arg(ap, const char *)) != NULL) {
3837   MD5Update(&ctx, (const unsigned char *) p, (unsigned) strlen(p));
3838   }
3839   va_end(ap);
38423840
3843  MD5Final(hash, &ctx);
3844  bin2str(buf, hash, sizeof(hash));
3845  return buf;
3841   MD5Final(hash, &ctx);
3842   bin2str(buf, hash, sizeof(hash));
3843   return buf;
38463844}
38473845
38483846// Check the user's password, return 1 if OK
38493847static int check_password(const char *method, const char *ha1, const char *uri,
3850                          const char *nonce, const char *nc, const char *cnonce,
3851                          const char *qop, const char *response) {
3852  char ha2[32 + 1], expected_response[32 + 1];
3848                     const char *nonce, const char *nc, const char *cnonce,
3849                     const char *qop, const char *response) {
3850   char ha2[32 + 1], expected_response[32 + 1];
38533851
38543852#if 0
3855  // Check for authentication timeout
3856  if ((unsigned long) time(NULL) - (unsigned long) to64(nonce) > 3600 * 2) {
3857    return 0;
3858  }
3853   // Check for authentication timeout
3854   if ((unsigned long) time(NULL) - (unsigned long) to64(nonce) > 3600 * 2) {
3855   return 0;
3856   }
38593857#endif
38603858
3861  mg_md5(ha2, method, ":", uri, NULL);
3862  mg_md5(expected_response, ha1, ":", nonce, ":", nc,
3863      ":", cnonce, ":", qop, ":", ha2, NULL);
3859   mg_md5(ha2, method, ":", uri, NULL);
3860   mg_md5(expected_response, ha1, ":", nonce, ":", nc,
3861      ":", cnonce, ":", qop, ":", ha2, NULL);
38643862
3865  return mg_strcasecmp(response, expected_response) == 0 ? MG_TRUE : MG_FALSE;
3863   return mg_strcasecmp(response, expected_response) == 0 ? MG_TRUE : MG_FALSE;
38663864}
38673865
38683866
38693867// Authorize against the opened passwords file. Return 1 if authorized.
38703868int mg_authorize_digest(struct mg_connection *c, FILE *fp) {
3871  struct connection *conn = MG_CONN_2_CONN(c);
3872  const char *hdr;
3873  char line[256], f_user[256], ha1[256], f_domain[256], user[100], nonce[100],
3874       uri[MAX_REQUEST_SIZE], cnonce[100], resp[100], qop[100], nc[100];
3869   struct connection *conn = MG_CONN_2_CONN(c);
3870   const char *hdr;
3871   char line[256], f_user[256], ha1[256], f_domain[256], user[100], nonce[100],
3872      uri[MAX_REQUEST_SIZE], cnonce[100], resp[100], qop[100], nc[100];
38753873
3876  if (c == NULL || fp == NULL) return 0;
3877  if ((hdr = mg_get_header(c, "Authorization")) == NULL ||
3878      mg_strncasecmp(hdr, "Digest ", 7) != 0) return 0;
3879  if (!mg_parse_header(hdr, "username", user, sizeof(user))) return 0;
3880  if (!mg_parse_header(hdr, "cnonce", cnonce, sizeof(cnonce))) return 0;
3881  if (!mg_parse_header(hdr, "response", resp, sizeof(resp))) return 0;
3882  if (!mg_parse_header(hdr, "uri", uri, sizeof(uri))) return 0;
3883  if (!mg_parse_header(hdr, "qop", qop, sizeof(qop))) return 0;
3884  if (!mg_parse_header(hdr, "nc", nc, sizeof(nc))) return 0;
3885  if (!mg_parse_header(hdr, "nonce", nonce, sizeof(nonce))) return 0;
3874   if (c == NULL || fp == NULL) return 0;
3875   if ((hdr = mg_get_header(c, "Authorization")) == NULL ||
3876      mg_strncasecmp(hdr, "Digest ", 7) != 0) return 0;
3877   if (!mg_parse_header(hdr, "username", user, sizeof(user))) return 0;
3878   if (!mg_parse_header(hdr, "cnonce", cnonce, sizeof(cnonce))) return 0;
3879   if (!mg_parse_header(hdr, "response", resp, sizeof(resp))) return 0;
3880   if (!mg_parse_header(hdr, "uri", uri, sizeof(uri))) return 0;
3881   if (!mg_parse_header(hdr, "qop", qop, sizeof(qop))) return 0;
3882   if (!mg_parse_header(hdr, "nc", nc, sizeof(nc))) return 0;
3883   if (!mg_parse_header(hdr, "nonce", nonce, sizeof(nonce))) return 0;
38863884
3887  while (fgets(line, sizeof(line), fp) != NULL) {
3888    if (sscanf(line, "%[^:]:%[^:]:%s", f_user, f_domain, ha1) == 3 &&
3889        !strcmp(user, f_user) &&
3890        // NOTE(lsm): due to a bug in MSIE, we do not compare URIs
3891        !strcmp(conn->server->config_options[AUTH_DOMAIN], f_domain))
3892      return check_password(c->request_method, ha1, uri,
3893                            nonce, nc, cnonce, qop, resp);
3894  }
3895  return MG_FALSE;
3885   while (fgets(line, sizeof(line), fp) != NULL) {
3886   if (sscanf(line, "%[^:]:%[^:]:%s", f_user, f_domain, ha1) == 3 &&
3887      !strcmp(user, f_user) &&
3888      // NOTE(lsm): due to a bug in MSIE, we do not compare URIs
3889      !strcmp(conn->server->config_options[AUTH_DOMAIN], f_domain))
3890      return check_password(c->request_method, ha1, uri,
3891                     nonce, nc, cnonce, qop, resp);
3892   }
3893   return MG_FALSE;
38963894}
38973895
38983896
38993897// Return 1 if request is authorised, 0 otherwise.
39003898static int is_authorized(struct connection *conn, const char *path,
3901                         int is_directory) {
3902  FILE *fp;
3903  int authorized = MG_TRUE;
3899                     int is_directory) {
3900   FILE *fp;
3901   int authorized = MG_TRUE;
39043902
3905  if ((fp = open_auth_file(conn, path, is_directory)) != NULL) {
3906    authorized = mg_authorize_digest(&conn->mg_conn, fp);
3907    fclose(fp);
3908  }
3903   if ((fp = open_auth_file(conn, path, is_directory)) != NULL) {
3904   authorized = mg_authorize_digest(&conn->mg_conn, fp);
3905   fclose(fp);
3906   }
39093907
3910  return authorized;
3908   return authorized;
39113909}
39123910
39133911static int is_authorized_for_dav(struct connection *conn) {
3914  const char *auth_file = conn->server->config_options[DAV_AUTH_FILE];
3915  const char *method = conn->mg_conn.request_method;
3916  FILE *fp;
3917  int authorized = MG_FALSE;
3912   const char *auth_file = conn->server->config_options[DAV_AUTH_FILE];
3913   const char *method = conn->mg_conn.request_method;
3914   FILE *fp;
3915   int authorized = MG_FALSE;
39183916
3919  // If dav_auth_file is not set, allow non-authorized PROPFIND
3920  if (method != NULL && !strcmp(method, "PROPFIND") && auth_file == NULL) {
3921    authorized = MG_TRUE;
3922  } else if (auth_file != NULL && (fp = fopen(auth_file, "r")) != NULL) {
3923    authorized = mg_authorize_digest(&conn->mg_conn, fp);
3924    fclose(fp);
3925  }
3917   // If dav_auth_file is not set, allow non-authorized PROPFIND
3918   if (method != NULL && !strcmp(method, "PROPFIND") && auth_file == NULL) {
3919   authorized = MG_TRUE;
3920   } else if (auth_file != NULL && (fp = fopen(auth_file, "r")) != NULL) {
3921   authorized = mg_authorize_digest(&conn->mg_conn, fp);
3922   fclose(fp);
3923   }
39263924
3927  return authorized;
3925   return authorized;
39283926}
39293927
39303928static int is_dav_request(const struct connection *conn) {
3931  const char *s = conn->mg_conn.request_method;
3932  return !strcmp(s, "PUT") || !strcmp(s, "DELETE") ||
3933    !strcmp(s, "MKCOL") || !strcmp(s, "PROPFIND");
3929   const char *s = conn->mg_conn.request_method;
3930   return !strcmp(s, "PUT") || !strcmp(s, "DELETE") ||
3931   !strcmp(s, "MKCOL") || !strcmp(s, "PROPFIND");
39343932}
39353933#endif // MONGOOSE_NO_AUTH
39363934
39373935static int parse_header(const char *str, int str_len, const char *var_name,
3938                        char *buf, size_t buf_size) {
3939  int ch = ' ', len = 0, n = strlen(var_name);
3940  const char *p, *end = str + str_len, *s = NULL;
3936                  char *buf, size_t buf_size) {
3937   int ch = ' ', len = 0, n = strlen(var_name);
3938   const char *p, *end = str + str_len, *s = NULL;
39413939
3942  if (buf != NULL && buf_size > 0) buf[0] = '\0';
3940   if (buf != NULL && buf_size > 0) buf[0] = '\0';
39433941
3944  // Find where variable starts
3945  for (s = str; s != NULL && s + n < end; s++) {
3946    if ((s == str || s[-1] == ' ' || s[-1] == ',') && s[n] == '=' &&
3947        !memcmp(s, var_name, n)) break;
3948  }
3942   // Find where variable starts
3943   for (s = str; s != NULL && s + n < end; s++) {
3944   if ((s == str || s[-1] == ' ' || s[-1] == ',') && s[n] == '=' &&
3945      !memcmp(s, var_name, n)) break;
3946   }
39493947
3950  if (s != NULL && &s[n + 1] < end) {
3951    s += n + 1;
3952    if (*s == '"' || *s == '\'') ch = *s++;
3953    p = s;
3954    while (p < end && p[0] != ch && p[0] != ',' && len < (int) buf_size) {
3955      if (p[0] == '\\' && p[1] == ch) p++;
3956      buf[len++] = *p++;
3957    }
3958    if (len >= (int) buf_size || (ch != ' ' && *p != ch)) {
3959      len = 0;
3960    } else {
3961      if (len > 0 && s[len - 1] == ',') len--;
3962      if (len > 0 && s[len - 1] == ';') len--;
3963      buf[len] = '\0';
3964    }
3965  }
3948   if (s != NULL && &s[n + 1] < end) {
3949   s += n + 1;
3950   if (*s == '"' || *s == '\'') ch = *s++;
3951   p = s;
3952   while (p < end && p[0] != ch && p[0] != ',' && len < (int) buf_size) {
3953      if (p[0] == '\\' && p[1] == ch) p++;
3954      buf[len++] = *p++;
3955   }
3956   if (len >= (int) buf_size || (ch != ' ' && *p != ch)) {
3957      len = 0;
3958   } else {
3959      if (len > 0 && s[len - 1] == ',') len--;
3960      if (len > 0 && s[len - 1] == ';') len--;
3961      buf[len] = '\0';
3962   }
3963   }
39663964
3967  return len;
3965   return len;
39683966}
39693967
39703968int mg_parse_header(const char *s, const char *var_name, char *buf,
3971                    size_t buf_size) {
3972  return parse_header(s, s == NULL ? 0 : strlen(s), var_name, buf, buf_size);
3969               size_t buf_size) {
3970   return parse_header(s, s == NULL ? 0 : strlen(s), var_name, buf, buf_size);
39733971}
39743972
39753973#ifndef MONGOOSE_NO_SSI
39763974static void send_ssi_file(struct mg_connection *, const char *, FILE *, int);
39773975
39783976static void send_file_data(struct mg_connection *conn, FILE *fp) {
3979  char buf[IOBUF_SIZE];
3980  int n;
3981  while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) {
3982    mg_write(conn, buf, n);
3983  }
3977   char buf[IOBUF_SIZE];
3978   int n;
3979   while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) {
3980   mg_write(conn, buf, n);
3981   }
39843982}
39853983
39863984static void do_ssi_include(struct mg_connection *conn, const char *ssi,
3987                           char *tag, int include_level) {
3988  char file_name[IOBUF_SIZE], path[MAX_PATH_SIZE], *p;
3989  char **opts = (MG_CONN_2_CONN(conn))->server->config_options;
3990  FILE *fp;
3985                     char *tag, int include_level) {
3986   char file_name[IOBUF_SIZE], path[MAX_PATH_SIZE], *p;
3987   char **opts = (MG_CONN_2_CONN(conn))->server->config_options;
3988   FILE *fp;
39913989
3992  // sscanf() is safe here, since send_ssi_file() also uses buffer
3993  // of size MG_BUF_LEN to get the tag. So strlen(tag) is always < MG_BUF_LEN.
3994  if (sscanf(tag, " virtual=\"%[^\"]\"", file_name) == 1) {
3995    // File name is relative to the webserver root
3996    mg_snprintf(path, sizeof(path), "%s%c%s",
3997                opts[DOCUMENT_ROOT], '/', file_name);
3998  } else if (sscanf(tag, " abspath=\"%[^\"]\"", file_name) == 1) {
3999    // File name is relative to the webserver working directory
4000    // or it is absolute system path
4001    mg_snprintf(path, sizeof(path), "%s", file_name);
4002  } else if (sscanf(tag, " file=\"%[^\"]\"", file_name) == 1 ||
4003             sscanf(tag, " \"%[^\"]\"", file_name) == 1) {
4004    // File name is relative to the currect document
4005    mg_snprintf(path, sizeof(path), "%s", ssi);
4006    if ((p = strrchr(path, '/')) != NULL) {
4007      p[1] = '\0';
4008    }
4009    mg_snprintf(path + strlen(path), sizeof(path) - strlen(path), "%s",
4010                file_name);
4011  } else {
4012    mg_printf(conn, "Bad SSI #include: [%s]", tag);
4013    return;
4014  }
3990   // sscanf() is safe here, since send_ssi_file() also uses buffer
3991   // of size MG_BUF_LEN to get the tag. So strlen(tag) is always < MG_BUF_LEN.
3992   if (sscanf(tag, " virtual=\"%[^\"]\"", file_name) == 1) {
3993   // File name is relative to the webserver root
3994   mg_snprintf(path, sizeof(path), "%s%c%s",
3995            opts[DOCUMENT_ROOT], '/', file_name);
3996   } else if (sscanf(tag, " abspath=\"%[^\"]\"", file_name) == 1) {
3997   // File name is relative to the webserver working directory
3998   // or it is absolute system path
3999   mg_snprintf(path, sizeof(path), "%s", file_name);
4000   } else if (sscanf(tag, " file=\"%[^\"]\"", file_name) == 1 ||
4001            sscanf(tag, " \"%[^\"]\"", file_name) == 1) {
4002   // File name is relative to the currect document
4003   mg_snprintf(path, sizeof(path), "%s", ssi);
4004   if ((p = strrchr(path, '/')) != NULL) {
4005      p[1] = '\0';
4006   }
4007   mg_snprintf(path + strlen(path), sizeof(path) - strlen(path), "%s",
4008            file_name);
4009   } else {
4010   mg_printf(conn, "Bad SSI #include: [%s]", tag);
4011   return;
4012   }
40154013
4016  if ((fp = fopen(path, "rb")) == NULL) {
4017    mg_printf(conn, "Cannot open SSI #include: [%s]: fopen(%s): %s",
4018              tag, path, strerror(errno));
4019  } else {
4020    ns_set_close_on_exec(fileno(fp));
4021    if (mg_match_prefix(opts[SSI_PATTERN], strlen(opts[SSI_PATTERN]),
4022        path) > 0) {
4023      send_ssi_file(conn, path, fp, include_level + 1);
4024    } else {
4025      send_file_data(conn, fp);
4026    }
4027    fclose(fp);
4028  }
4014   if ((fp = fopen(path, "rb")) == NULL) {
4015   mg_printf(conn, "Cannot open SSI #include: [%s]: fopen(%s): %s",
4016            tag, path, strerror(errno));
4017   } else {
4018   ns_set_close_on_exec(fileno(fp));
4019   if (mg_match_prefix(opts[SSI_PATTERN], strlen(opts[SSI_PATTERN]),
4020      path) > 0) {
4021      send_ssi_file(conn, path, fp, include_level + 1);
4022   } else {
4023      send_file_data(conn, fp);
4024   }
4025   fclose(fp);
4026   }
40294027}
40304028
40314029#ifndef MONGOOSE_NO_POPEN
40324030static void do_ssi_exec(struct mg_connection *conn, char *tag) {
4033  char cmd[IOBUF_SIZE];
4034  FILE *fp;
4031   char cmd[IOBUF_SIZE];
4032   FILE *fp;
40354033
4036  if (sscanf(tag, " \"%[^\"]\"", cmd) != 1) {
4037    mg_printf(conn, "Bad SSI #exec: [%s]", tag);
4038  } else if ((fp = popen(cmd, "r")) == NULL) {
4039    mg_printf(conn, "Cannot SSI #exec: [%s]: %s", cmd, strerror(errno));
4040  } else {
4041    send_file_data(conn, fp);
4042    pclose(fp);
4043  }
4034   if (sscanf(tag, " \"%[^\"]\"", cmd) != 1) {
4035   mg_printf(conn, "Bad SSI #exec: [%s]", tag);
4036   } else if ((fp = popen(cmd, "r")) == NULL) {
4037   mg_printf(conn, "Cannot SSI #exec: [%s]: %s", cmd, strerror(errno));
4038   } else {
4039   send_file_data(conn, fp);
4040   pclose(fp);
4041   }
40444042}
40454043#endif // !MONGOOSE_NO_POPEN
40464044
40474045static void send_ssi_file(struct mg_connection *conn, const char *path,
4048                          FILE *fp, int include_level) {
4049  char buf[IOBUF_SIZE];
4050  int ch, offset, len, in_ssi_tag;
4046                     FILE *fp, int include_level) {
4047   char buf[IOBUF_SIZE];
4048   int ch, offset, len, in_ssi_tag;
40514049
4052  if (include_level > 10) {
4053    mg_printf(conn, "SSI #include level is too deep (%s)", path);
4054    return;
4055  }
4050   if (include_level > 10) {
4051   mg_printf(conn, "SSI #include level is too deep (%s)", path);
4052   return;
4053   }
40564054
4057  in_ssi_tag = len = offset = 0;
4058  while ((ch = fgetc(fp)) != EOF) {
4059    if (in_ssi_tag && ch == '>') {
4060      in_ssi_tag = 0;
4061      buf[len++] = (char) ch;
4062      buf[len] = '\0';
4063      assert(len <= (int) sizeof(buf));
4064      if (len < 6 || memcmp(buf, "<!--#", 5) != 0) {
4065        // Not an SSI tag, pass it
4066        (void) mg_write(conn, buf, (size_t) len);
4067      } else {
4068        if (!memcmp(buf + 5, "include", 7)) {
4069          do_ssi_include(conn, path, buf + 12, include_level);
4055   in_ssi_tag = len = offset = 0;
4056   while ((ch = fgetc(fp)) != EOF) {
4057   if (in_ssi_tag && ch == '>') {
4058      in_ssi_tag = 0;
4059      buf[len++] = (char) ch;
4060      buf[len] = '\0';
4061      assert(len <= (int) sizeof(buf));
4062      if (len < 6 || memcmp(buf, "<!--#", 5) != 0) {
4063      // Not an SSI tag, pass it
4064      (void) mg_write(conn, buf, (size_t) len);
4065      } else {
4066      if (!memcmp(buf + 5, "include", 7)) {
4067         do_ssi_include(conn, path, buf + 12, include_level);
40704068#if !defined(MONGOOSE_NO_POPEN)
4071        } else if (!memcmp(buf + 5, "exec", 4)) {
4072          do_ssi_exec(conn, buf + 9);
4069      } else if (!memcmp(buf + 5, "exec", 4)) {
4070         do_ssi_exec(conn, buf + 9);
40734071#endif // !NO_POPEN
4074        } else {
4075          mg_printf(conn, "%s: unknown SSI " "command: \"%s\"", path, buf);
4076        }
4077      }
4078      len = 0;
4079    } else if (in_ssi_tag) {
4080      if (len == 5 && memcmp(buf, "<!--#", 5) != 0) {
4081        // Not an SSI tag
4082        in_ssi_tag = 0;
4083      } else if (len == (int) sizeof(buf) - 2) {
4084        mg_printf(conn, "%s: SSI tag is too large", path);
4085        len = 0;
4086      }
4087      buf[len++] = ch & 0xff;
4088    } else if (ch == '<') {
4089      in_ssi_tag = 1;
4090      if (len > 0) {
4091        mg_write(conn, buf, (size_t) len);
4092      }
4093      len = 0;
4094      buf[len++] = ch & 0xff;
4095    } else {
4096      buf[len++] = ch & 0xff;
4097      if (len == (int) sizeof(buf)) {
4098        mg_write(conn, buf, (size_t) len);
4099        len = 0;
4100      }
4101    }
4102  }
4072      } else {
4073         mg_printf(conn, "%s: unknown SSI " "command: \"%s\"", path, buf);
4074      }
4075      }
4076      len = 0;
4077   } else if (in_ssi_tag) {
4078      if (len == 5 && memcmp(buf, "<!--#", 5) != 0) {
4079      // Not an SSI tag
4080      in_ssi_tag = 0;
4081      } else if (len == (int) sizeof(buf) - 2) {
4082      mg_printf(conn, "%s: SSI tag is too large", path);
4083      len = 0;
4084      }
4085      buf[len++] = ch & 0xff;
4086   } else if (ch == '<') {
4087      in_ssi_tag = 1;
4088      if (len > 0) {
4089      mg_write(conn, buf, (size_t) len);
4090      }
4091      len = 0;
4092      buf[len++] = ch & 0xff;
4093   } else {
4094      buf[len++] = ch & 0xff;
4095      if (len == (int) sizeof(buf)) {
4096      mg_write(conn, buf, (size_t) len);
4097      len = 0;
4098      }
4099   }
4100   }
41034101
4104  // Send the rest of buffered data
4105  if (len > 0) {
4106    mg_write(conn, buf, (size_t) len);
4107  }
4102   // Send the rest of buffered data
4103   if (len > 0) {
4104   mg_write(conn, buf, (size_t) len);
4105   }
41084106}
41094107
41104108static void handle_ssi_request(struct connection *conn, const char *path) {
4111  FILE *fp;
4112  struct vec mime_vec;
4109   FILE *fp;
4110   struct vec mime_vec;
41134111
4114  if ((fp = fopen(path, "rb")) == NULL) {
4115    send_http_error(conn, 500, "fopen(%s): %s", path, strerror(errno));
4116  } else {
4117    ns_set_close_on_exec(fileno(fp));
4118    get_mime_type(conn->server, path, &mime_vec);
4119    conn->mg_conn.status_code = 200;
4120    mg_printf(&conn->mg_conn,
4121              "HTTP/1.1 %d OK\r\n"
4122              "Content-Type: %.*s\r\n"
4123              "Connection: close\r\n\r\n",
4124              conn->mg_conn.status_code, (int) mime_vec.len, mime_vec.ptr);
4125    send_ssi_file(&conn->mg_conn, path, fp, 0);
4126    fclose(fp);
4127    close_local_endpoint(conn);
4128  }
4112   if ((fp = fopen(path, "rb")) == NULL) {
4113   send_http_error(conn, 500, "fopen(%s): %s", path, strerror(errno));
4114   } else {
4115   ns_set_close_on_exec(fileno(fp));
4116   get_mime_type(conn->server, path, &mime_vec);
4117   conn->mg_conn.status_code = 200;
4118   mg_printf(&conn->mg_conn,
4119            "HTTP/1.1 %d OK\r\n"
4120            "Content-Type: %.*s\r\n"
4121            "Connection: close\r\n\r\n",
4122            conn->mg_conn.status_code, (int) mime_vec.len, mime_vec.ptr);
4123   send_ssi_file(&conn->mg_conn, path, fp, 0);
4124   fclose(fp);
4125   close_local_endpoint(conn);
4126   }
41294127}
41304128#endif
41314129
41324130static void proxy_request(struct ns_connection *pc, struct mg_connection *c) {
4133  int i, sent_close_header = 0;
4131   int i, sent_close_header = 0;
41344132
4135  ns_printf(pc, "%s %s HTTP/%s\r\n", c->request_method, c->uri,
4136            c->http_version);
4137  for (i = 0; i < c->num_headers; i++) {
4138    if (mg_strcasecmp(c->http_headers[i].name, "Connection") == 0) {
4139      // Force connection close, cause we don't parse proxy replies
4140      // therefore we don't know message boundaries
4141      ns_printf(pc, "%s: %s\r\n", "Connection", "close");
4142      sent_close_header = 1;
4143    } else {
4144      ns_printf(pc, "%s: %s\r\n", c->http_headers[i].name,
4145                c->http_headers[i].value);
4146    }
4147  }
4148  if (!sent_close_header) {
4149    ns_printf(pc, "%s: %s\r\n", "Connection", "close");
4150  }
4151  ns_printf(pc, "%s", "\r\n");
4152  ns_send(pc, c->content, c->content_len);
4133   ns_printf(pc, "%s %s HTTP/%s\r\n", c->request_method, c->uri,
4134         c->http_version);
4135   for (i = 0; i < c->num_headers; i++) {
4136   if (mg_strcasecmp(c->http_headers[i].name, "Connection") == 0) {
4137      // Force connection close, cause we don't parse proxy replies
4138      // therefore we don't know message boundaries
4139      ns_printf(pc, "%s: %s\r\n", "Connection", "close");
4140      sent_close_header = 1;
4141   } else {
4142      ns_printf(pc, "%s: %s\r\n", c->http_headers[i].name,
4143            c->http_headers[i].value);
4144   }
4145   }
4146   if (!sent_close_header) {
4147   ns_printf(pc, "%s: %s\r\n", "Connection", "close");
4148   }
4149   ns_printf(pc, "%s", "\r\n");
4150   ns_send(pc, c->content, c->content_len);
41534151
41544152}
41554153
41564154#ifdef NS_ENABLE_SSL
41574155int mg_terminate_ssl(struct mg_connection *c, const char *cert) {
4158  static const char ok[] = "HTTP/1.0 200 OK\r\n\r\n";
4159  struct connection *conn = MG_CONN_2_CONN(c);
4160  SSL_CTX *ctx;
4156   static const char ok[] = "HTTP/1.0 200 OK\r\n\r\n";
4157   struct connection *conn = MG_CONN_2_CONN(c);
4158   SSL_CTX *ctx;
41614159
4162  DBG(("%p MITM", conn));
4163  SSL_library_init();
4164  if ((ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) return 0;
4160   DBG(("%p MITM", conn));
4161   SSL_library_init();
4162   if ((ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) return 0;
41654163
4166  SSL_CTX_use_certificate_file(ctx, cert, 1);
4167  SSL_CTX_use_PrivateKey_file(ctx, cert, 1);
4168  SSL_CTX_use_certificate_chain_file(ctx, cert);
4164   SSL_CTX_use_certificate_file(ctx, cert, 1);
4165   SSL_CTX_use_PrivateKey_file(ctx, cert, 1);
4166   SSL_CTX_use_certificate_chain_file(ctx, cert);
41694167
4170  // When clear-text reply is pushed to client, switch to SSL mode.
4171  // TODO(lsm): check for send() failure
4172  send(conn->ns_conn->sock, ok, sizeof(ok) - 1, 0);
4173  DBG(("%p %lu %d SEND", c, (unsigned long)sizeof(ok) - 1, n));
4174  conn->ns_conn->send_iobuf.len = 0;
4175  conn->endpoint_type = EP_USER;  // To keep-alive in close_local_endpoint()
4176  close_local_endpoint(conn);     // Clean up current CONNECT request
4177  if ((conn->ns_conn->ssl = SSL_new(ctx)) != NULL) {
4178    SSL_set_fd(conn->ns_conn->ssl, conn->ns_conn->sock);
4179  }
4180  SSL_CTX_free(ctx);
4181  return 1;
4168   // When clear-text reply is pushed to client, switch to SSL mode.
4169   // TODO(lsm): check for send() failure
4170   send(conn->ns_conn->sock, ok, sizeof(ok) - 1, 0);
4171   DBG(("%p %lu %d SEND", c, (unsigned long)sizeof(ok) - 1, n));
4172   conn->ns_conn->send_iobuf.len = 0;
4173   conn->endpoint_type = EP_USER;  // To keep-alive in close_local_endpoint()
4174   close_local_endpoint(conn);     // Clean up current CONNECT request
4175   if ((conn->ns_conn->ssl = SSL_new(ctx)) != NULL) {
4176   SSL_set_fd(conn->ns_conn->ssl, conn->ns_conn->sock);
4177   }
4178   SSL_CTX_free(ctx);
4179   return 1;
41824180}
41834181#endif
41844182
41854183int mg_forward(struct mg_connection *c, const char *host, int port, int ssl) {
4186  struct connection *conn = MG_CONN_2_CONN(c);
4187  struct ns_server *server = &conn->server->ns_server;
4188  struct ns_connection *pc;
4184   struct connection *conn = MG_CONN_2_CONN(c);
4185   struct ns_server *server = &conn->server->ns_server;
4186   struct ns_connection *pc;
41894187
4190  if ((pc = ns_connect(server, host, port, ssl, conn)) == NULL) {
4191    conn->ns_conn->flags |= NSF_CLOSE_IMMEDIATELY;
4192    return 0;
4193  }
4188   if ((pc = ns_connect(server, host, port, ssl, conn)) == NULL) {
4189   conn->ns_conn->flags |= NSF_CLOSE_IMMEDIATELY;
4190   return 0;
4191   }
41944192
4195  // Interlink two connections
4196  pc->flags |= MG_PROXY_CONN;
4197  conn->endpoint_type = EP_PROXY;
4198  conn->endpoint.nc = pc;
4199  DBG(("%p [%s] [%s:%d] -> %p %p",
4200      conn, c->uri, host, port, pc, conn->ns_conn->ssl));
4193   // Interlink two connections
4194   pc->flags |= MG_PROXY_CONN;
4195   conn->endpoint_type = EP_PROXY;
4196   conn->endpoint.nc = pc;
4197   DBG(("%p [%s] [%s:%d] -> %p %p",
4198      conn, c->uri, host, port, pc, conn->ns_conn->ssl));
42014199
4202  if (strcmp(c->request_method, "CONNECT") == 0) {
4203    // For CONNECT request, reply with 200 OK. Tunnel is established.
4204    mg_printf(c, "%s", "HTTP/1.1 200 OK\r\n\r\n");
4205  } else {
4206    // Strip "http://host:port" part from the URI
4207    if (memcmp(c->uri, "http://", 7) == 0) c->uri += 7;
4208    while (*c->uri != '\0' && *c->uri != '/') c->uri++;
4209    proxy_request(pc, c);
4210  }
4211  return 1;
4200   if (strcmp(c->request_method, "CONNECT") == 0) {
4201   // For CONNECT request, reply with 200 OK. Tunnel is established.
4202   mg_printf(c, "%s", "HTTP/1.1 200 OK\r\n\r\n");
4203   } else {
4204   // Strip "http://host:port" part from the URI
4205   if (memcmp(c->uri, "http://", 7) == 0) c->uri += 7;
4206   while (*c->uri != '\0' && *c->uri != '/') c->uri++;
4207   proxy_request(pc, c);
4208   }
4209   return 1;
42124210}
42134211
42144212static void proxify_connection(struct connection *conn) {
4215  char proto[10], host[500], cert[500];
4216  unsigned short port = 80;
4217  struct mg_connection *c = &conn->mg_conn;
4218  int n = 0;
4219  const char *url = c->uri;
4213   char proto[10], host[500], cert[500];
4214   unsigned short port = 80;
4215   struct mg_connection *c = &conn->mg_conn;
4216   int n = 0;
4217   const char *url = c->uri;
42204218
4221  proto[0] = host[0] = cert[0] = '\0';
4222  if (sscanf(url, "%499[^: ]:%hu%n", host, &port, &n) != 2 &&
4223      sscanf(url, "%9[a-z]://%499[^: ]:%hu%n", proto, host, &port, &n) != 3 &&
4224      sscanf(url, "%9[a-z]://%499[^/ ]%n", proto, host, &n) != 2) {
4225    n = 0;
4226  }
4219   proto[0] = host[0] = cert[0] = '\0';
4220   if (sscanf(url, "%499[^: ]:%hu%n", host, &port, &n) != 2 &&
4221      sscanf(url, "%9[a-z]://%499[^: ]:%hu%n", proto, host, &port, &n) != 3 &&
4222      sscanf(url, "%9[a-z]://%499[^/ ]%n", proto, host, &n) != 2) {
4223   n = 0;
4224   }
42274225
42284226#ifdef NS_ENABLE_SSL
4229  // Find out whether we should be in the MITM mode
4230  {
4231    const char *certs = conn->server->config_options[SSL_MITM_CERTS];
4232    int host_len = strlen(host);
4233    struct vec a, b;
4227   // Find out whether we should be in the MITM mode
4228   {
4229   const char *certs = conn->server->config_options[SSL_MITM_CERTS];
4230   int host_len = strlen(host);
4231   struct vec a, b;
42344232
4235    while (conn->ns_conn->ssl == NULL && port != 80 &&
4236           (certs = next_option(certs, &a, &b)) != NULL) {
4237      if (a.len != host_len || mg_strncasecmp(a.ptr, host, a.len)) continue;
4238      snprintf(cert, sizeof(cert), "%.*s", b.len, b.ptr);
4239      mg_terminate_ssl(&conn->mg_conn, cert);
4240      return;
4241    }
4242  }
4233   while (conn->ns_conn->ssl == NULL && port != 80 &&
4234         (certs = next_option(certs, &a, &b)) != NULL) {
4235      if (a.len != host_len || mg_strncasecmp(a.ptr, host, a.len)) continue;
4236      snprintf(cert, sizeof(cert), "%.*s", b.len, b.ptr);
4237      mg_terminate_ssl(&conn->mg_conn, cert);
4238      return;
4239   }
4240   }
42434241#endif
42444242
4245  if (n > 0 && mg_forward(c, host, port, conn->ns_conn->ssl != NULL)) {
4246  } else {
4247    conn->ns_conn->flags |= NSF_CLOSE_IMMEDIATELY;
4248  }
4243   if (n > 0 && mg_forward(c, host, port, conn->ns_conn->ssl != NULL)) {
4244   } else {
4245   conn->ns_conn->flags |= NSF_CLOSE_IMMEDIATELY;
4246   }
42494247}
42504248
42514249#ifndef MONGOOSE_NO_FILESYSTEM
42524250void mg_send_file_internal(struct mg_connection *c, const char *file_name,
4253                           file_stat_t *st, int exists) {
4254  struct connection *conn = MG_CONN_2_CONN(c);
4255  char path[MAX_PATH_SIZE];
4256  const int is_directory = S_ISDIR(st->st_mode);
4251                     file_stat_t *st, int exists) {
4252   struct connection *conn = MG_CONN_2_CONN(c);
4253   char path[MAX_PATH_SIZE];
4254   const int is_directory = S_ISDIR(st->st_mode);
42574255#ifndef MONGOOSE_NO_CGI
4258  const char *cgi_pat = conn->server->config_options[CGI_PATTERN];
4256   const char *cgi_pat = conn->server->config_options[CGI_PATTERN];
42594257#else
4260  const char *cgi_pat = DEFAULT_CGI_PATTERN;
4258   const char *cgi_pat = DEFAULT_CGI_PATTERN;
42614259#endif
42624260#ifndef MONGOOSE_NO_DIRECTORY_LISTING
4263  const char *dir_lst = conn->server->config_options[ENABLE_DIRECTORY_LISTING];
4261   const char *dir_lst = conn->server->config_options[ENABLE_DIRECTORY_LISTING];
42644262#else
4265  const char *dir_lst = "yes";
4263   const char *dir_lst = "yes";
42664264#endif
42674265
4268  mg_snprintf(path, sizeof(path), "%s", file_name);
4266   mg_snprintf(path, sizeof(path), "%s", file_name);
42694267
4270  if (!exists || must_hide_file(conn, path)) {
4271    send_http_error(conn, 404, NULL);
4272  } else if (is_directory &&
4273             conn->mg_conn.uri[strlen(conn->mg_conn.uri) - 1] != '/') {
4274    conn->mg_conn.status_code = 301;
4275    mg_printf(&conn->mg_conn, "HTTP/1.1 301 Moved Permanently\r\n"
4276              "Location: %s/\r\n\r\n", conn->mg_conn.uri);
4277    close_local_endpoint(conn);
4278  } else if (is_directory && !find_index_file(conn, path, sizeof(path), st)) {
4279    if (!mg_strcasecmp(dir_lst, "yes")) {
4268   if (!exists || must_hide_file(conn, path)) {
4269   send_http_error(conn, 404, NULL);
4270   } else if (is_directory &&
4271            conn->mg_conn.uri[strlen(conn->mg_conn.uri) - 1] != '/') {
4272   conn->mg_conn.status_code = 301;
4273   mg_printf(&conn->mg_conn, "HTTP/1.1 301 Moved Permanently\r\n"
4274            "Location: %s/\r\n\r\n", conn->mg_conn.uri);
4275   close_local_endpoint(conn);
4276   } else if (is_directory && !find_index_file(conn, path, sizeof(path), st)) {
4277   if (!mg_strcasecmp(dir_lst, "yes")) {
42804278#ifndef MONGOOSE_NO_DIRECTORY_LISTING
4281      send_directory_listing(conn, path);
4279      send_directory_listing(conn, path);
42824280#else
4283      send_http_error(conn, 501, NULL);
4281      send_http_error(conn, 501, NULL);
42844282#endif
4285    } else {
4286      send_http_error(conn, 403, NULL);
4287    }
4288  } else if (mg_match_prefix(cgi_pat, strlen(cgi_pat), path) > 0) {
4283   } else {
4284      send_http_error(conn, 403, NULL);
4285   }
4286   } else if (mg_match_prefix(cgi_pat, strlen(cgi_pat), path) > 0) {
42894287#if !defined(MONGOOSE_NO_CGI)
4290    open_cgi_endpoint(conn, path);
4288   open_cgi_endpoint(conn, path);
42914289#else
4292    send_http_error(conn, 501, NULL);
4290   send_http_error(conn, 501, NULL);
42934291#endif // !MONGOOSE_NO_CGI
42944292#ifndef MONGOOSE_NO_SSI
4295  } else if (mg_match_prefix(conn->server->config_options[SSI_PATTERN],
4296                             strlen(conn->server->config_options[SSI_PATTERN]),
4297                             path) > 0) {
4298    handle_ssi_request(conn, path);
4293   } else if (mg_match_prefix(conn->server->config_options[SSI_PATTERN],
4294                        strlen(conn->server->config_options[SSI_PATTERN]),
4295                        path) > 0) {
4296   handle_ssi_request(conn, path);
42994297#endif
4300  } else if (is_not_modified(conn, st)) {
4301    send_http_error(conn, 304, NULL);
4302  } else if ((conn->endpoint.fd = open(path, O_RDONLY | O_BINARY)) != -1) {
4303    // O_BINARY is required for Windows, otherwise in default text mode
4304    // two bytes \r\n will be read as one.
4305    open_file_endpoint(conn, path, st);
4306  } else {
4307    send_http_error(conn, 404, NULL);
4308  }
4298   } else if (is_not_modified(conn, st)) {
4299   send_http_error(conn, 304, NULL);
4300   } else if ((conn->endpoint.fd = open(path, O_RDONLY | O_BINARY)) != -1) {
4301   // O_BINARY is required for Windows, otherwise in default text mode
4302   // two bytes \r\n will be read as one.
4303   open_file_endpoint(conn, path, st);
4304   } else {
4305   send_http_error(conn, 404, NULL);
4306   }
43094307}
43104308void mg_send_file(struct mg_connection *c, const char *file_name) {
4311  file_stat_t st;
4312  const int exists = stat(file_name, &st) == 0;
4313  mg_send_file_internal(c, file_name, &st, exists);
4309   file_stat_t st;
4310   const int exists = stat(file_name, &st) == 0;
4311   mg_send_file_internal(c, file_name, &st, exists);
43144312}
43154313#endif  // !MONGOOSE_NO_FILESYSTEM
43164314
43174315static void open_local_endpoint(struct connection *conn, int skip_user) {
43184316#ifndef MONGOOSE_NO_FILESYSTEM
4319  char path[MAX_PATH_SIZE];
4320  file_stat_t st;
4321  int exists = 0;
4317   char path[MAX_PATH_SIZE];
4318   file_stat_t st;
4319   int exists = 0;
43224320#endif
43234321
4324  // If EP_USER was set in a prev call, reset it
4325  conn->endpoint_type = EP_NONE;
4322   // If EP_USER was set in a prev call, reset it
4323   conn->endpoint_type = EP_NONE;
43264324
43274325#ifndef MONGOOSE_NO_AUTH
4328  if (conn->server->event_handler && call_user(conn, MG_AUTH) == MG_FALSE) {
4329    mg_send_digest_auth_request(&conn->mg_conn);
4330    return;
4331  }
4326   if (conn->server->event_handler && call_user(conn, MG_AUTH) == MG_FALSE) {
4327   mg_send_digest_auth_request(&conn->mg_conn);
4328   return;
4329   }
43324330#endif
43334331
4334  // Call URI handler if one is registered for this URI
4335  if (skip_user == 0 && conn->server->event_handler != NULL) {
4336    conn->endpoint_type = EP_USER;
4332   // Call URI handler if one is registered for this URI
4333   if (skip_user == 0 && conn->server->event_handler != NULL) {
4334   conn->endpoint_type = EP_USER;
43374335#if MONGOOSE_POST_SIZE_LIMIT > 1
4338    {
4339      const char *cl = mg_get_header(&conn->mg_conn, "Content-Length");
4340      if ((strcmp(conn->mg_conn.request_method, "POST") == 0 ||
4341           strcmp(conn->mg_conn.request_method, "PUT") == 0) &&
4342          (cl == NULL || to64(cl) > MONGOOSE_POST_SIZE_LIMIT)) {
4343        send_http_error(conn, 500, "POST size > %lu",
4344                        (unsigned long) MONGOOSE_POST_SIZE_LIMIT);
4345      }
4346    }
4336   {
4337      const char *cl = mg_get_header(&conn->mg_conn, "Content-Length");
4338      if ((strcmp(conn->mg_conn.request_method, "POST") == 0 ||
4339         strcmp(conn->mg_conn.request_method, "PUT") == 0) &&
4340         (cl == NULL || to64(cl) > MONGOOSE_POST_SIZE_LIMIT)) {
4341      send_http_error(conn, 500, "POST size > %lu",
4342                  (unsigned long) MONGOOSE_POST_SIZE_LIMIT);
4343      }
4344   }
43474345#endif
4348    return;
4349  }
4346   return;
4347   }
43504348
4351  if (strcmp(conn->mg_conn.request_method, "CONNECT") == 0 ||
4352      mg_strncasecmp(conn->mg_conn.uri, "http", 4) == 0) {
4353    const char *enp = conn->server->config_options[ENABLE_PROXY];
4354    if (enp == NULL || strcmp(enp, "yes") != 0) {
4355      send_http_error(conn, 405, NULL);
4356    } else {
4357      proxify_connection(conn);
4358    }
4359    return;
4360  }
4349   if (strcmp(conn->mg_conn.request_method, "CONNECT") == 0 ||
4350      mg_strncasecmp(conn->mg_conn.uri, "http", 4) == 0) {
4351   const char *enp = conn->server->config_options[ENABLE_PROXY];
4352   if (enp == NULL || strcmp(enp, "yes") != 0) {
4353      send_http_error(conn, 405, NULL);
4354   } else {
4355      proxify_connection(conn);
4356   }
4357   return;
4358   }
43614359
4362  if (!strcmp(conn->mg_conn.request_method, "OPTIONS")) {
4363    send_options(conn);
4364    return;
4365  }
4360   if (!strcmp(conn->mg_conn.request_method, "OPTIONS")) {
4361   send_options(conn);
4362   return;
4363   }
43664364
43674365#ifdef MONGOOSE_NO_FILESYSTEM
4368  send_http_error(conn, 404, NULL);
4366   send_http_error(conn, 404, NULL);
43694367#else
4370  exists = convert_uri_to_file_name(conn, path, sizeof(path), &st);
4368   exists = convert_uri_to_file_name(conn, path, sizeof(path), &st);
43714369
4372  if (!strcmp(conn->mg_conn.request_method, "OPTIONS")) {
4373    send_options(conn);
4374  } else if (conn->server->config_options[DOCUMENT_ROOT] == NULL) {
4375    send_http_error(conn, 404, NULL);
4370   if (!strcmp(conn->mg_conn.request_method, "OPTIONS")) {
4371   send_options(conn);
4372   } else if (conn->server->config_options[DOCUMENT_ROOT] == NULL) {
4373   send_http_error(conn, 404, NULL);
43764374#ifndef MONGOOSE_NO_AUTH
4377  } else if ((!is_dav_request(conn) && !is_authorized(conn, path,
4378               exists && S_ISDIR(st.st_mode))) ||
4379             (is_dav_request(conn) && !is_authorized_for_dav(conn))) {
4380    mg_send_digest_auth_request(&conn->mg_conn);
4381    close_local_endpoint(conn);
4375   } else if ((!is_dav_request(conn) && !is_authorized(conn, path,
4376            exists && S_ISDIR(st.st_mode))) ||
4377            (is_dav_request(conn) && !is_authorized_for_dav(conn))) {
4378   mg_send_digest_auth_request(&conn->mg_conn);
4379   close_local_endpoint(conn);
43824380#endif
43834381#ifndef MONGOOSE_NO_DAV
4384  } else if (must_hide_file(conn, path)) {
4385    send_http_error(conn, 404, NULL);
4386  } else if (!strcmp(conn->mg_conn.request_method, "PROPFIND")) {
4387    handle_propfind(conn, path, &st, exists);
4388  } else if (!strcmp(conn->mg_conn.request_method, "MKCOL")) {
4389    handle_mkcol(conn, path);
4390  } else if (!strcmp(conn->mg_conn.request_method, "DELETE")) {
4391    handle_delete(conn, path);
4392  } else if (!strcmp(conn->mg_conn.request_method, "PUT")) {
4393    handle_put(conn, path);
4382   } else if (must_hide_file(conn, path)) {
4383   send_http_error(conn, 404, NULL);
4384   } else if (!strcmp(conn->mg_conn.request_method, "PROPFIND")) {
4385   handle_propfind(conn, path, &st, exists);
4386   } else if (!strcmp(conn->mg_conn.request_method, "MKCOL")) {
4387   handle_mkcol(conn, path);
4388   } else if (!strcmp(conn->mg_conn.request_method, "DELETE")) {
4389   handle_delete(conn, path);
4390   } else if (!strcmp(conn->mg_conn.request_method, "PUT")) {
4391   handle_put(conn, path);
43944392#endif
4395  } else {
4396    mg_send_file_internal(&conn->mg_conn, path, &st, exists);
4397  }
4393   } else {
4394   mg_send_file_internal(&conn->mg_conn, path, &st, exists);
4395   }
43984396#endif  // MONGOOSE_NO_FILESYSTEM
43994397}
44004398
44014399static void send_continue_if_expected(struct connection *conn) {
4402  static const char expect_response[] = "HTTP/1.1 100 Continue\r\n\r\n";
4403  const char *expect_hdr = mg_get_header(&conn->mg_conn, "Expect");
4400   static const char expect_response[] = "HTTP/1.1 100 Continue\r\n\r\n";
4401   const char *expect_hdr = mg_get_header(&conn->mg_conn, "Expect");
44044402
4405  if (expect_hdr != NULL && !mg_strcasecmp(expect_hdr, "100-continue")) {
4406    ns_send(conn->ns_conn, expect_response, sizeof(expect_response) - 1);
4407  }
4403   if (expect_hdr != NULL && !mg_strcasecmp(expect_hdr, "100-continue")) {
4404   ns_send(conn->ns_conn, expect_response, sizeof(expect_response) - 1);
4405   }
44084406}
44094407
44104408// Conform to http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.2
44114409static int is_valid_uri(const char *uri) {
4412  unsigned short n;
4413  return uri[0] == '/' ||
4414    strcmp(uri, "*") == 0 ||            // OPTIONS method can use asterisk URI
4415    mg_strncasecmp(uri, "http", 4) == 0 || // Naive check for the absolute URI
4416    sscanf(uri, "%*[^ :]:%hu", &n) > 0; // CONNECT method can use host:port
4410   unsigned short n;
4411   return uri[0] == '/' ||
4412   strcmp(uri, "*") == 0 ||            // OPTIONS method can use asterisk URI
4413   mg_strncasecmp(uri, "http", 4) == 0 || // Naive check for the absolute URI
4414   sscanf(uri, "%*[^ :]:%hu", &n) > 0; // CONNECT method can use host:port
44174415}
44184416
44194417static void try_parse(struct connection *conn) {
4420  struct iobuf *io = &conn->ns_conn->recv_iobuf;
4418   struct iobuf *io = &conn->ns_conn->recv_iobuf;
44214419
4422  if (conn->request_len == 0 &&
4423      (conn->request_len = get_request_len(io->buf, io->len)) > 0) {
4424    // If request is buffered in, remove it from the iobuf. This is because
4425    // iobuf could be reallocated, and pointers in parsed request could
4426    // become invalid.
4427    conn->request = (char *) malloc(conn->request_len);
4428    memcpy(conn->request, io->buf, conn->request_len);
4429    //DBG(("%p [%.*s]", conn, conn->request_len, conn->request));
4430    iobuf_remove(io, conn->request_len);
4431    conn->request_len = parse_http_message(conn->request, conn->request_len,
4432                                           &conn->mg_conn);
4433    if (conn->request_len > 0) {
4434      const char *cl_hdr = mg_get_header(&conn->mg_conn, "Content-Length");
4435      conn->cl = cl_hdr == NULL ? 0 : to64(cl_hdr);
4436      conn->mg_conn.content_len = (size_t) conn->cl;
4437    }
4438  }
4420   if (conn->request_len == 0 &&
4421      (conn->request_len = get_request_len(io->buf, io->len)) > 0) {
4422   // If request is buffered in, remove it from the iobuf. This is because
4423   // iobuf could be reallocated, and pointers in parsed request could
4424   // become invalid.
4425   conn->request = (char *) malloc(conn->request_len);
4426   memcpy(conn->request, io->buf, conn->request_len);
4427   //DBG(("%p [%.*s]", conn, conn->request_len, conn->request));
4428   iobuf_remove(io, conn->request_len);
4429   conn->request_len = parse_http_message(conn->request, conn->request_len,
4430                                 &conn->mg_conn);
4431   if (conn->request_len > 0) {
4432      const char *cl_hdr = mg_get_header(&conn->mg_conn, "Content-Length");
4433      conn->cl = cl_hdr == NULL ? 0 : to64(cl_hdr);
4434      conn->mg_conn.content_len = (size_t) conn->cl;
4435   }
4436   }
44394437}
44404438
44414439static void do_proxy(struct connection *conn) {
4442  if (0 && conn->request_len == 0) {
4443    try_parse(conn);
4444    DBG(("%p parsing -> %d", conn, conn->request_len));
4445    if (conn->request_len > 0 && call_user(conn, MG_REQUEST) == MG_FALSE) {
4446      proxy_request(conn->endpoint.nc, &conn->mg_conn);
4447    } else if (conn->request_len < 0) {
4448      ns_forward(conn->ns_conn, conn->endpoint.nc);
4449    }
4450  } else {
4451    DBG(("%p forwarding", conn));
4452    ns_forward(conn->ns_conn, conn->endpoint.nc);
4453  }
4440   if (0 && conn->request_len == 0) {
4441   try_parse(conn);
4442   DBG(("%p parsing -> %d", conn, conn->request_len));
4443   if (conn->request_len > 0 && call_user(conn, MG_REQUEST) == MG_FALSE) {
4444      proxy_request(conn->endpoint.nc, &conn->mg_conn);
4445   } else if (conn->request_len < 0) {
4446      ns_forward(conn->ns_conn, conn->endpoint.nc);
4447   }
4448   } else {
4449   DBG(("%p forwarding", conn));
4450   ns_forward(conn->ns_conn, conn->endpoint.nc);
4451   }
44544452}
44554453
44564454static void on_recv_data(struct connection *conn) {
4457  struct iobuf *io = &conn->ns_conn->recv_iobuf;
4458  int n;
4455   struct iobuf *io = &conn->ns_conn->recv_iobuf;
4456   int n;
44594457
4460  if (conn->endpoint_type == EP_PROXY) {
4461    if (conn->endpoint.nc != NULL) do_proxy(conn);
4462    return;
4463  }
4458   if (conn->endpoint_type == EP_PROXY) {
4459   if (conn->endpoint.nc != NULL) do_proxy(conn);
4460   return;
4461   }
44644462
4465  try_parse(conn);
4466  DBG(("%p %d %lu %d", conn, conn->request_len, (unsigned long)io->len,
4467       conn->ns_conn->flags));
4468  if (conn->request_len < 0 ||
4469      (conn->request_len > 0 && !is_valid_uri(conn->mg_conn.uri))) {
4470    send_http_error(conn, 400, NULL);
4471  } else if (conn->request_len == 0 && io->len > MAX_REQUEST_SIZE) {
4472    send_http_error(conn, 413, NULL);
4473  } else if (conn->request_len > 0 &&
4474             strcmp(conn->mg_conn.http_version, "1.0") != 0 &&
4475             strcmp(conn->mg_conn.http_version, "1.1") != 0) {
4476    send_http_error(conn, 505, NULL);
4477  } else if (conn->request_len > 0 && conn->endpoint_type == EP_NONE) {
4463   try_parse(conn);
4464   DBG(("%p %d %lu %d", conn, conn->request_len, (unsigned long)io->len,
4465      conn->ns_conn->flags));
4466   if (conn->request_len < 0 ||
4467      (conn->request_len > 0 && !is_valid_uri(conn->mg_conn.uri))) {
4468   send_http_error(conn, 400, NULL);
4469   } else if (conn->request_len == 0 && io->len > MAX_REQUEST_SIZE) {
4470   send_http_error(conn, 413, NULL);
4471   } else if (conn->request_len > 0 &&
4472            strcmp(conn->mg_conn.http_version, "1.0") != 0 &&
4473            strcmp(conn->mg_conn.http_version, "1.1") != 0) {
4474   send_http_error(conn, 505, NULL);
4475   } else if (conn->request_len > 0 && conn->endpoint_type == EP_NONE) {
44784476#ifndef MONGOOSE_NO_WEBSOCKET
4479    send_websocket_handshake_if_requested(&conn->mg_conn);
4477   send_websocket_handshake_if_requested(&conn->mg_conn);
44804478#endif
4481    send_continue_if_expected(conn);
4482    open_local_endpoint(conn, 0);
4483  }
4479   send_continue_if_expected(conn);
4480   open_local_endpoint(conn, 0);
4481   }
44844482
44854483#ifndef MONGOOSE_NO_CGI
4486  if (conn->endpoint_type == EP_CGI && conn->endpoint.nc != NULL) {
4487    ns_forward(conn->ns_conn, conn->endpoint.nc);
4488  }
4484   if (conn->endpoint_type == EP_CGI && conn->endpoint.nc != NULL) {
4485   ns_forward(conn->ns_conn, conn->endpoint.nc);
4486   }
44894487#endif
4490  if (conn->endpoint_type == EP_USER) {
4491    conn->mg_conn.content = io->buf;
4492    conn->mg_conn.content_len = io->len;
4493    n = call_user(conn, MG_RECV);
4494    if (n < 0) {
4495      conn->ns_conn->flags |= NSF_FINISHED_SENDING_DATA;
4496    } else if ((size_t) n <= io->len) {
4497      iobuf_remove(io, n);
4498    }
4499    call_request_handler_if_data_is_buffered(conn);
4500  }
4488   if (conn->endpoint_type == EP_USER) {
4489   conn->mg_conn.content = io->buf;
4490   conn->mg_conn.content_len = io->len;
4491   n = call_user(conn, MG_RECV);
4492   if (n < 0) {
4493      conn->ns_conn->flags |= NSF_FINISHED_SENDING_DATA;
4494   } else if ((size_t) n <= io->len) {
4495      iobuf_remove(io, n);
4496   }
4497   call_request_handler_if_data_is_buffered(conn);
4498   }
45014499#ifndef MONGOOSE_NO_DAV
4502  if (conn->endpoint_type == EP_PUT && io->len > 0) {
4503    forward_put_data(conn);
4504  }
4500   if (conn->endpoint_type == EP_PUT && io->len > 0) {
4501   forward_put_data(conn);
4502   }
45054503#endif
45064504}
45074505
45084506static void call_http_client_handler(struct connection *conn) {
4509  //conn->mg_conn.status_code = code;
4510  // For responses without Content-Lengh, use the whole buffer
4511  if (conn->cl == 0) {
4512    conn->mg_conn.content_len = conn->ns_conn->recv_iobuf.len;
4513  }
4514  conn->mg_conn.content = conn->ns_conn->recv_iobuf.buf;
4515  if (call_user(conn, MG_REPLY) == MG_FALSE) {
4516    conn->ns_conn->flags |= NSF_CLOSE_IMMEDIATELY;
4517  }
4518  iobuf_remove(&conn->ns_conn->recv_iobuf, conn->mg_conn.content_len);
4519  conn->mg_conn.status_code = 0;
4520  conn->cl = conn->num_bytes_recv = conn->request_len = 0;
4521  free(conn->request);
4522  conn->request = NULL;
4507   //conn->mg_conn.status_code = code;
4508   // For responses without Content-Lengh, use the whole buffer
4509   if (conn->cl == 0) {
4510   conn->mg_conn.content_len = conn->ns_conn->recv_iobuf.len;
4511   }
4512   conn->mg_conn.content = conn->ns_conn->recv_iobuf.buf;
4513   if (call_user(conn, MG_REPLY) == MG_FALSE) {
4514   conn->ns_conn->flags |= NSF_CLOSE_IMMEDIATELY;
4515   }
4516   iobuf_remove(&conn->ns_conn->recv_iobuf, conn->mg_conn.content_len);
4517   conn->mg_conn.status_code = 0;
4518   conn->cl = conn->num_bytes_recv = conn->request_len = 0;
4519   free(conn->request);
4520   conn->request = NULL;
45234521}
45244522
45254523static void process_response(struct connection *conn) {
4526  struct iobuf *io = &conn->ns_conn->recv_iobuf;
4524   struct iobuf *io = &conn->ns_conn->recv_iobuf;
45274525
4528  try_parse(conn);
4529  DBG(("%p %d %lu", conn, conn->request_len, (unsigned long)io->len));
4530  if (conn->request_len < 0 ||
4531      (conn->request_len == 0 && io->len > MAX_REQUEST_SIZE)) {
4532    call_http_client_handler(conn);
4533  } else if ((int64_t) io->len >= conn->cl) {
4534    call_http_client_handler(conn);
4535  }
4526   try_parse(conn);
4527   DBG(("%p %d %lu", conn, conn->request_len, (unsigned long)io->len));
4528   if (conn->request_len < 0 ||
4529      (conn->request_len == 0 && io->len > MAX_REQUEST_SIZE)) {
4530   call_http_client_handler(conn);
4531   } else if ((int64_t) io->len >= conn->cl) {
4532   call_http_client_handler(conn);
4533   }
45364534}
45374535
45384536struct mg_connection *mg_connect(struct mg_server *server, const char *host,
4539                                 int port, int use_ssl) {
4540  struct ns_connection *nsconn;
4541  struct connection *conn;
4537                           int port, int use_ssl) {
4538   struct ns_connection *nsconn;
4539   struct connection *conn;
45424540
4543  nsconn = ns_connect(&server->ns_server, host, port, use_ssl, NULL);
4544  if (nsconn == NULL) return 0;
4541   nsconn = ns_connect(&server->ns_server, host, port, use_ssl, NULL);
4542   if (nsconn == NULL) return 0;
45454543
4546  if ((conn = (struct connection *) calloc(1, sizeof(*conn))) == NULL) {
4547    nsconn->flags |= NSF_CLOSE_IMMEDIATELY;
4548    return 0;
4549  }
4544   if ((conn = (struct connection *) calloc(1, sizeof(*conn))) == NULL) {
4545   nsconn->flags |= NSF_CLOSE_IMMEDIATELY;
4546   return 0;
4547   }
45504548
4551  // Interlink two structs
4552  conn->ns_conn = nsconn;
4553  nsconn->connection_data = conn;
4549   // Interlink two structs
4550   conn->ns_conn = nsconn;
4551   nsconn->connection_data = conn;
45544552
4555  conn->server = server;
4556  conn->endpoint_type = EP_CLIENT;
4557  //conn->handler = handler;
4558  conn->mg_conn.server_param = server->ns_server.server_data;
4559  conn->ns_conn->flags = NSF_CONNECTING;
4553   conn->server = server;
4554   conn->endpoint_type = EP_CLIENT;
4555   //conn->handler = handler;
4556   conn->mg_conn.server_param = server->ns_server.server_data;
4557   conn->ns_conn->flags = NSF_CONNECTING;
45604558
4561  return &conn->mg_conn;
4559   return &conn->mg_conn;
45624560}
45634561
45644562#ifndef MONGOOSE_NO_LOGGING
45654563static void log_header(const struct mg_connection *conn, const char *header,
4566                       FILE *fp) {
4567  const char *header_value;
4564                  FILE *fp) {
4565   const char *header_value;
45684566
4569  if ((header_value = mg_get_header(conn, header)) == NULL) {
4570    (void) fprintf(fp, "%s", " -");
4571  } else {
4572    (void) fprintf(fp, " \"%s\"", header_value);
4573  }
4567   if ((header_value = mg_get_header(conn, header)) == NULL) {
4568   (void) fprintf(fp, "%s", " -");
4569   } else {
4570   (void) fprintf(fp, " \"%s\"", header_value);
4571   }
45744572}
45754573
45764574static void log_access(const struct connection *conn, const char *path) {
4577  const struct mg_connection *c = &conn->mg_conn;
4578  FILE *fp = (path == NULL) ?  NULL : fopen(path, "a+");
4579  char date[64], user[100];
4580  time_t now;
4575   const struct mg_connection *c = &conn->mg_conn;
4576   FILE *fp = (path == NULL) ?  NULL : fopen(path, "a+");
4577   char date[64], user[100];
4578   time_t now;
45814579
4582  if (fp == NULL) return;
4583  now = time(NULL);
4584  strftime(date, sizeof(date), "%d/%b/%Y:%H:%M:%S %z", localtime(&now));
4580   if (fp == NULL) return;
4581   now = time(NULL);
4582   strftime(date, sizeof(date), "%d/%b/%Y:%H:%M:%S %z", localtime(&now));
45854583
4586  flockfile(fp);
4587  mg_parse_header(mg_get_header(&conn->mg_conn, "Authorization"), "username",
4588                  user, sizeof(user));
4589  fprintf(fp, "%s - %s [%s] \"%s %s%s%s HTTP/%s\" %d 0",
4590          c->remote_ip, user[0] == '\0' ? "-" : user, date,
4591          c->request_method ? c->request_method : "-",
4592          c->uri ? c->uri : "-", c->query_string ? "?" : "",
4593          c->query_string ? c->query_string : "",
4594          c->http_version, c->status_code);
4595  log_header(c, "Referer", fp);
4596  log_header(c, "User-Agent", fp);
4597  fputc('\n', fp);
4598  fflush(fp);
4584   flockfile(fp);
4585   mg_parse_header(mg_get_header(&conn->mg_conn, "Authorization"), "username",
4586               user, sizeof(user));
4587   fprintf(fp, "%s - %s [%s] \"%s %s%s%s HTTP/%s\" %d 0",
4588         c->remote_ip, user[0] == '\0' ? "-" : user, date,
4589         c->request_method ? c->request_method : "-",
4590         c->uri ? c->uri : "-", c->query_string ? "?" : "",
4591         c->query_string ? c->query_string : "",
4592         c->http_version, c->status_code);
4593   log_header(c, "Referer", fp);
4594   log_header(c, "User-Agent", fp);
4595   fputc('\n', fp);
4596   fflush(fp);
45994597
4600  funlockfile(fp);
4601  fclose(fp);
4598   funlockfile(fp);
4599   fclose(fp);
46024600}
46034601#endif
46044602
46054603static void close_local_endpoint(struct connection *conn) {
4606  struct mg_connection *c = &conn->mg_conn;
4607  // Must be done before free()
4608  int keep_alive = should_keep_alive(&conn->mg_conn) &&
4609    (conn->endpoint_type == EP_FILE || conn->endpoint_type == EP_USER);
4610  DBG(("%p %d %d %d", conn, conn->endpoint_type, keep_alive,
4611       conn->ns_conn->flags));
4604   struct mg_connection *c = &conn->mg_conn;
4605   // Must be done before free()
4606   int keep_alive = should_keep_alive(&conn->mg_conn) &&
4607   (conn->endpoint_type == EP_FILE || conn->endpoint_type == EP_USER);
4608   DBG(("%p %d %d %d", conn, conn->endpoint_type, keep_alive,
4609      conn->ns_conn->flags));
46124610
4613  switch (conn->endpoint_type) {
4614    case EP_PUT:
4615    case EP_FILE:
4616      close(conn->endpoint.fd);
4617      break;
4618    case EP_CGI:
4619    case EP_PROXY:
4620      if (conn->endpoint.nc != NULL) {
4621        DBG(("%p %p %p :-)", conn, conn->ns_conn, conn->endpoint.nc));
4622        conn->endpoint.nc->flags |= NSF_CLOSE_IMMEDIATELY;
4623        conn->endpoint.nc->connection_data = NULL;
4624      }
4625      break;
4626    default: break;
4627  }
4611   switch (conn->endpoint_type) {
4612   case EP_PUT:
4613   case EP_FILE:
4614      close(conn->endpoint.fd);
4615      break;
4616   case EP_CGI:
4617   case EP_PROXY:
4618      if (conn->endpoint.nc != NULL) {
4619      DBG(("%p %p %p :-)", conn, conn->ns_conn, conn->endpoint.nc));
4620      conn->endpoint.nc->flags |= NSF_CLOSE_IMMEDIATELY;
4621      conn->endpoint.nc->connection_data = NULL;
4622      }
4623      break;
4624   default: break;
4625   }
46284626
46294627#ifndef MONGOOSE_NO_LOGGING
4630  if (c->status_code > 0 && conn->endpoint_type != EP_CLIENT &&
4631      c->status_code != 400) {
4632    log_access(conn, conn->server->config_options[ACCESS_LOG_FILE]);
4633  }
4628   if (c->status_code > 0 && conn->endpoint_type != EP_CLIENT &&
4629      c->status_code != 400) {
4630   log_access(conn, conn->server->config_options[ACCESS_LOG_FILE]);
4631   }
46344632#endif
46354633
4636  // Gobble possible POST data sent to the URI handler
4637  iobuf_free(&conn->ns_conn->recv_iobuf);
4638  free(conn->request);
4639  free(conn->path_info);
4640  conn->endpoint.nc = NULL;
4641  conn->request = conn->path_info = NULL;
4634   // Gobble possible POST data sent to the URI handler
4635   iobuf_free(&conn->ns_conn->recv_iobuf);
4636   free(conn->request);
4637   free(conn->path_info);
4638   conn->endpoint.nc = NULL;
4639   conn->request = conn->path_info = NULL;
46424640
4643  conn->endpoint_type = EP_NONE;
4644  conn->cl = conn->num_bytes_recv = conn->request_len = 0;
4645  conn->ns_conn->flags &= ~(NSF_FINISHED_SENDING_DATA |
4646                            NSF_BUFFER_BUT_DONT_SEND | NSF_CLOSE_IMMEDIATELY |
4647                            MG_HEADERS_SENT | MG_LONG_RUNNING);
4641   conn->endpoint_type = EP_NONE;
4642   conn->cl = conn->num_bytes_recv = conn->request_len = 0;
4643   conn->ns_conn->flags &= ~(NSF_FINISHED_SENDING_DATA |
4644                     NSF_BUFFER_BUT_DONT_SEND | NSF_CLOSE_IMMEDIATELY |
4645                     MG_HEADERS_SENT | MG_LONG_RUNNING);
46484646
4649  // Do not memset() the whole structure, as some of the fields
4650  // (IP addresses & ports, server_param) must survive. Nullify the rest.
4651  c->request_method = c->uri = c->http_version = c->query_string = NULL;
4652  c->num_headers = c->status_code = c->is_websocket = c->content_len = 0;
4653  c->connection_param = c->callback_param = NULL;
4647   // Do not memset() the whole structure, as some of the fields
4648   // (IP addresses & ports, server_param) must survive. Nullify the rest.
4649   c->request_method = c->uri = c->http_version = c->query_string = NULL;
4650   c->num_headers = c->status_code = c->is_websocket = c->content_len = 0;
4651   c->connection_param = c->callback_param = NULL;
46544652
4655  if (keep_alive) {
4656    on_recv_data(conn);  // Can call us recursively if pipelining is used
4657  } else {
4658    conn->ns_conn->flags |= conn->ns_conn->send_iobuf.len == 0 ?
4659      NSF_CLOSE_IMMEDIATELY : NSF_FINISHED_SENDING_DATA;
4660  }
4653   if (keep_alive) {
4654   on_recv_data(conn);  // Can call us recursively if pipelining is used
4655   } else {
4656   conn->ns_conn->flags |= conn->ns_conn->send_iobuf.len == 0 ?
4657      NSF_CLOSE_IMMEDIATELY : NSF_FINISHED_SENDING_DATA;
4658   }
46614659}
46624660
46634661static void transfer_file_data(struct connection *conn) {
4664  char buf[IOBUF_SIZE];
4665  int n;
4662   char buf[IOBUF_SIZE];
4663   int n;
46664664
4667  // If output buffer is too big, don't send anything. Wait until
4668  // mongoose drains already buffered data to the client.
4669  if (conn->ns_conn->send_iobuf.len > sizeof(buf) * 2) return;
4665   // If output buffer is too big, don't send anything. Wait until
4666   // mongoose drains already buffered data to the client.
4667   if (conn->ns_conn->send_iobuf.len > sizeof(buf) * 2) return;
46704668
4671  // Do not send anyt
4672  n = read(conn->endpoint.fd, buf, conn->cl < (int64_t) sizeof(buf) ?
4673           (int) conn->cl : (int) sizeof(buf));
4669   // Do not send anyt
4670   n = read(conn->endpoint.fd, buf, conn->cl < (int64_t) sizeof(buf) ?
4671         (int) conn->cl : (int) sizeof(buf));
46744672
4675  if (n <= 0) {
4676    close_local_endpoint(conn);
4677  } else if (n > 0) {
4678    conn->cl -= n;
4679    ns_send(conn->ns_conn, buf, n);
4680    if (conn->cl <= 0) {
4681      close_local_endpoint(conn);
4682    }
4683  }
4673   if (n <= 0) {
4674   close_local_endpoint(conn);
4675   } else if (n > 0) {
4676   conn->cl -= n;
4677   ns_send(conn->ns_conn, buf, n);
4678   if (conn->cl <= 0) {
4679      close_local_endpoint(conn);
4680   }
4681   }
46844682}
46854683
46864684int mg_poll_server(struct mg_server *server, int milliseconds) {
4687  return ns_server_poll(&server->ns_server, milliseconds);
4685   return ns_server_poll(&server->ns_server, milliseconds);
46884686}
46894687
46904688void mg_destroy_server(struct mg_server **server) {
4691  if (server != NULL && *server != NULL) {
4692    struct mg_server *s = *server;
4693    int i;
4689   if (server != NULL && *server != NULL) {
4690   struct mg_server *s = *server;
4691   int i;
46944692
4695    ns_server_free(&s->ns_server);
4696    for (i = 0; i < (int) ARRAY_SIZE(s->config_options); i++) {
4697      free(s->config_options[i]);  // It is OK to free(NULL)
4698    }
4699    free(s);
4700    *server = NULL;
4701  }
4693   ns_server_free(&s->ns_server);
4694   for (i = 0; i < (int) ARRAY_SIZE(s->config_options); i++) {
4695      free(s->config_options[i]);  // It is OK to free(NULL)
4696   }
4697   free(s);
4698   *server = NULL;
4699   }
47024700}
47034701
47044702struct mg_iterator {
4705  mg_handler_t cb;
4706  void *param;
4703   mg_handler_t cb;
4704   void *param;
47074705};
47084706
47094707static void iter(struct ns_connection *nsconn, enum ns_event ev, void *param) {
4710  if (ev == NS_POLL) {
4711    struct mg_iterator *it = (struct mg_iterator *) param;
4712    struct connection *c = (struct connection *) nsconn->connection_data;
4713    if (c != NULL) c->mg_conn.callback_param = it->param;
4714    it->cb(&c->mg_conn, MG_POLL);
4715  }
4708   if (ev == NS_POLL) {
4709   struct mg_iterator *it = (struct mg_iterator *) param;
4710   struct connection *c = (struct connection *) nsconn->connection_data;
4711   if (c != NULL) c->mg_conn.callback_param = it->param;
4712   it->cb(&c->mg_conn, MG_POLL);
4713   }
47164714}
47174715
47184716struct mg_connection *mg_next(struct mg_server *s, struct mg_connection *c) {
4719  struct connection *conn = MG_CONN_2_CONN(c);
4720  struct ns_connection *nc = ns_next(&s->ns_server,
4721                                     c == NULL ? NULL : conn->ns_conn);
4717   struct connection *conn = MG_CONN_2_CONN(c);
4718   struct ns_connection *nc = ns_next(&s->ns_server,
4719                              c == NULL ? NULL : conn->ns_conn);
47224720
4723  return nc == NULL ? NULL :
4724    & ((struct connection *) nc->connection_data)->mg_conn;
4721   return nc == NULL ? NULL :
4722   & ((struct connection *) nc->connection_data)->mg_conn;
47254723}
47264724
47274725// Apply function to all active connections.
47284726void mg_iterate_over_connections(struct mg_server *server, mg_handler_t cb,
4729  void *param) {
4730  struct mg_iterator it = { cb, param };
4731  ns_iterate(&server->ns_server, iter, &it);
4727   void *param) {
4728   struct mg_iterator it = { cb, param };
4729   ns_iterate(&server->ns_server, iter, &it);
47324730}
47334731
47344732static int get_var(const char *data, size_t data_len, const char *name,
4735                   char *dst, size_t dst_len) {
4736  const char *p, *e, *s;
4737  size_t name_len;
4738  int len;
4733               char *dst, size_t dst_len) {
4734   const char *p, *e, *s;
4735   size_t name_len;
4736   int len;
47394737
4740  if (dst == NULL || dst_len == 0) {
4741    len = -2;
4742  } else if (data == NULL || name == NULL || data_len == 0) {
4743    len = -1;
4744    dst[0] = '\0';
4745  } else {
4746    name_len = strlen(name);
4747    e = data + data_len;
4748    len = -1;
4749    dst[0] = '\0';
4738   if (dst == NULL || dst_len == 0) {
4739   len = -2;
4740   } else if (data == NULL || name == NULL || data_len == 0) {
4741   len = -1;
4742   dst[0] = '\0';
4743   } else {
4744   name_len = strlen(name);
4745   e = data + data_len;
4746   len = -1;
4747   dst[0] = '\0';
47504748
4751    // data is "var1=val1&var2=val2...". Find variable first
4752    for (p = data; p + name_len < e; p++) {
4753      if ((p == data || p[-1] == '&') && p[name_len] == '=' &&
4754          !mg_strncasecmp(name, p, name_len)) {
4749   // data is "var1=val1&var2=val2...". Find variable first
4750   for (p = data; p + name_len < e; p++) {
4751      if ((p == data || p[-1] == '&') && p[name_len] == '=' &&
4752         !mg_strncasecmp(name, p, name_len)) {
4753      // Point p to variable value
4754      p += name_len + 1;
47554755
4756        // Point p to variable value
4757        p += name_len + 1;
4756      // Point s to the end of the value
4757      s = (const char *) memchr(p, '&', (size_t)(e - p));
4758      if (s == NULL) {
4759         s = e;
4760      }
4761      assert(s >= p);
47584762
4759        // Point s to the end of the value
4760        s = (const char *) memchr(p, '&', (size_t)(e - p));
4761        if (s == NULL) {
4762          s = e;
4763        }
4764        assert(s >= p);
4763      // Decode variable into destination buffer
4764      len = mg_url_decode(p, (size_t)(s - p), dst, dst_len, 1);
47654765
4766        // Decode variable into destination buffer
4767        len = mg_url_decode(p, (size_t)(s - p), dst, dst_len, 1);
4766      // Redirect error code from -1 to -2 (destination buffer too small).
4767      if (len == -1) {
4768         len = -2;
4769      }
4770      break;
4771      }
4772   }
4773   }
47684774
4769        // Redirect error code from -1 to -2 (destination buffer too small).
4770        if (len == -1) {
4771          len = -2;
4772        }
4773        break;
4774      }
4775    }
4776  }
4777
4778  return len;
4775   return len;
47794776}
47804777
47814778int mg_get_var(const struct mg_connection *conn, const char *name,
4782               char *dst, size_t dst_len) {
4783  int len = get_var(conn->query_string, conn->query_string == NULL ? 0 :
4784                    strlen(conn->query_string), name, dst, dst_len);
4785  if (len < 0) {
4786    len = get_var(conn->content, conn->content_len, name, dst, dst_len);
4787  }
4788  return len;
4779            char *dst, size_t dst_len) {
4780   int len = get_var(conn->query_string, conn->query_string == NULL ? 0 :
4781               strlen(conn->query_string), name, dst, dst_len);
4782   if (len < 0) {
4783   len = get_var(conn->content, conn->content_len, name, dst, dst_len);
4784   }
4785   return len;
47894786}
47904787
47914788static int get_line_len(const char *buf, int buf_len) {
4792  int len = 0;
4793  while (len < buf_len && buf[len] != '\n') len++;
4794  return buf[len] == '\n' ? len + 1: -1;
4789   int len = 0;
4790   while (len < buf_len && buf[len] != '\n') len++;
4791   return buf[len] == '\n' ? len + 1: -1;
47954792}
47964793
47974794int mg_parse_multipart(const char *buf, int buf_len,
4798                       char *var_name, int var_name_len,
4799                       char *file_name, int file_name_len,
4800                       const char **data, int *data_len) {
4801  static const char cd[] = "Content-Disposition: ";
4802  //struct mg_connection c;
4803  int hl, bl, n, ll, pos, cdl = sizeof(cd) - 1;
4804  //char *p;
4795                  char *var_name, int var_name_len,
4796                  char *file_name, int file_name_len,
4797                  const char **data, int *data_len) {
4798   static const char cd[] = "Content-Disposition: ";
4799   //struct mg_connection c;
4800   int hl, bl, n, ll, pos, cdl = sizeof(cd) - 1;
4801   //char *p;
48054802
4806  if (buf == NULL || buf_len <= 0) return 0;
4807  if ((hl = get_request_len(buf, buf_len)) <= 0) return 0;
4808  if (buf[0] != '-' || buf[1] != '-' || buf[2] == '\n') return 0;
4803   if (buf == NULL || buf_len <= 0) return 0;
4804   if ((hl = get_request_len(buf, buf_len)) <= 0) return 0;
4805   if (buf[0] != '-' || buf[1] != '-' || buf[2] == '\n') return 0;
48094806
4810  // Get boundary length
4811  bl = get_line_len(buf, buf_len);
4807   // Get boundary length
4808   bl = get_line_len(buf, buf_len);
48124809
4813  // Loop through headers, fetch variable name and file name
4814  var_name[0] = file_name[0] = '\0';
4815  for (n = bl; (ll = get_line_len(buf + n, hl - n)) > 0; n += ll) {
4816    if (mg_strncasecmp(cd, buf + n, cdl) == 0) {
4817      parse_header(buf + n + cdl, ll - (cdl + 2), "name",
4818                   var_name, var_name_len);
4819      parse_header(buf + n + cdl, ll - (cdl + 2), "filename",
4820                   file_name, file_name_len);
4821    }
4822  }
4810   // Loop through headers, fetch variable name and file name
4811   var_name[0] = file_name[0] = '\0';
4812   for (n = bl; (ll = get_line_len(buf + n, hl - n)) > 0; n += ll) {
4813   if (mg_strncasecmp(cd, buf + n, cdl) == 0) {
4814      parse_header(buf + n + cdl, ll - (cdl + 2), "name",
4815               var_name, var_name_len);
4816      parse_header(buf + n + cdl, ll - (cdl + 2), "filename",
4817               file_name, file_name_len);
4818   }
4819   }
48234820
4824  // Scan body, search for terminating boundary
4825  for (pos = hl; pos + (bl - 2) < buf_len; pos++) {
4826    if (buf[pos] == '-' && !memcmp(buf, &buf[pos], bl - 2)) {
4827      if (data_len != NULL) *data_len = (pos - 2) - hl;
4828      if (data != NULL) *data = buf + hl;
4829      return pos;
4830    }
4831  }
4821   // Scan body, search for terminating boundary
4822   for (pos = hl; pos + (bl - 2) < buf_len; pos++) {
4823   if (buf[pos] == '-' && !memcmp(buf, &buf[pos], bl - 2)) {
4824      if (data_len != NULL) *data_len = (pos - 2) - hl;
4825      if (data != NULL) *data = buf + hl;
4826      return pos;
4827   }
4828   }
48324829
4833  return 0;
4830   return 0;
48344831}
48354832
48364833const char **mg_get_valid_option_names(void) {
4837  return static_config_options;
4834   return static_config_options;
48384835}
48394836
48404837static int get_option_index(const char *name) {
4841  int i;
4838   int i;
48424839
4843  for (i = 0; static_config_options[i * 2] != NULL; i++) {
4844    if (strcmp(static_config_options[i * 2], name) == 0) {
4845      return i;
4846    }
4847  }
4848  return -1;
4840   for (i = 0; static_config_options[i * 2] != NULL; i++) {
4841   if (strcmp(static_config_options[i * 2], name) == 0) {
4842      return i;
4843   }
4844   }
4845   return -1;
48494846}
48504847
48514848static void set_default_option_values(char **opts) {
4852  const char *value, **all_opts = mg_get_valid_option_names();
4853  int i;
4849   const char *value, **all_opts = mg_get_valid_option_names();
4850   int i;
48544851
4855  for (i = 0; all_opts[i * 2] != NULL; i++) {
4856    value = all_opts[i * 2 + 1];
4857    if (opts[i] == NULL && value != NULL) {
4858      opts[i] = mg_strdup(value);
4859    }
4860  }
4852   for (i = 0; all_opts[i * 2] != NULL; i++) {
4853   value = all_opts[i * 2 + 1];
4854   if (opts[i] == NULL && value != NULL) {
4855      opts[i] = mg_strdup(value);
4856   }
4857   }
48614858}
48624859
48634860const char *mg_set_option(struct mg_server *server, const char *name,
4864                          const char *value) {
4865  int ind = get_option_index(name);
4866  const char *error_msg = NULL;
4867  char **v = NULL;
4861                     const char *value) {
4862   int ind = get_option_index(name);
4863   const char *error_msg = NULL;
4864   char **v = NULL;
48684865
4869  if (ind < 0) return  "No such option";
4870  v = &server->config_options[ind];
4866   if (ind < 0) return  "No such option";
4867   v = &server->config_options[ind];
48714868
4872  // Return success immediately if setting to the same value
4873  if ((*v == NULL && value == NULL) ||
4874      (value != NULL && *v != NULL && !strcmp(value, *v))) {
4875    return NULL;
4876  }
4869   // Return success immediately if setting to the same value
4870   if ((*v == NULL && value == NULL) ||
4871      (value != NULL && *v != NULL && !strcmp(value, *v))) {
4872   return NULL;
4873   }
48774874
4878  if (*v != NULL) {
4879    free(*v);
4880    *v = NULL;
4881  }
4875   if (*v != NULL) {
4876   free(*v);
4877   *v = NULL;
4878   }
48824879
4883  if (value == NULL || value[0] == '\0') return NULL;
4880   if (value == NULL || value[0] == '\0') return NULL;
48844881
4885  *v = mg_strdup(value);
4886  DBG(("%s [%s]", name, *v));
4882   *v = mg_strdup(value);
4883   DBG(("%s [%s]", name, *v));
48874884
4888  if (ind == LISTENING_PORT) {
4889    int port = ns_bind(&server->ns_server, value);
4890    if (port < 0) {
4891      error_msg = "Cannot bind to port";
4892    } else {
4893      char buf[100];
4894      ns_sock_to_str(server->ns_server.listening_sock, buf, sizeof(buf), 2);
4895      free(*v);
4896      *v = mg_strdup(buf);
4897    }
4885   if (ind == LISTENING_PORT) {
4886   int port = ns_bind(&server->ns_server, value);
4887   if (port < 0) {
4888      error_msg = "Cannot bind to port";
4889   } else {
4890      char buf[100];
4891      ns_sock_to_str(server->ns_server.listening_sock, buf, sizeof(buf), 2);
4892      free(*v);
4893      *v = mg_strdup(buf);
4894   }
48984895#ifndef MONGOOSE_NO_FILESYSTEM
4899  } else if (ind == HEXDUMP_FILE) {
4900    server->ns_server.hexdump_file = *v;
4896   } else if (ind == HEXDUMP_FILE) {
4897   server->ns_server.hexdump_file = *v;
49014898#endif
49024899#ifndef _WIN32
4903  } else if (ind == RUN_AS_USER) {
4904    struct passwd *pw;
4905    if ((pw = getpwnam(value)) == NULL) {
4906      error_msg = "Unknown user";
4907    } else if (setgid(pw->pw_gid) != 0) {
4908      error_msg = "setgid() failed";
4909    } else if (setuid(pw->pw_uid) != 0) {
4910      error_msg = "setuid() failed";
4911    }
4900   } else if (ind == RUN_AS_USER) {
4901   struct passwd *pw;
4902   if ((pw = getpwnam(value)) == NULL) {
4903      error_msg = "Unknown user";
4904   } else if (setgid(pw->pw_gid) != 0) {
4905      error_msg = "setgid() failed";
4906   } else if (setuid(pw->pw_uid) != 0) {
4907      error_msg = "setuid() failed";
4908   }
49124909#endif
49134910#ifdef NS_ENABLE_SSL
4914  } else if (ind == SSL_CERTIFICATE) {
4915    int res = ns_set_ssl_cert(&server->ns_server, value);
4916    if (res == -2) {
4917      error_msg = "Cannot load PEM";
4918    } else if (res == -3) {
4919      error_msg = "SSL not enabled";
4920    } else if (res == -1) {
4921      error_msg = "SSL_CTX_new() failed";
4922    }
4923  } else if (ind == SSL_CA_CERTIFICATE) {
4924    if (ns_set_ssl_ca_cert(&server->ns_server, value) != 0) {
4925       error_msg = "Error setting CA cert";
4926     }
4911   } else if (ind == SSL_CERTIFICATE) {
4912   int res = ns_set_ssl_cert(&server->ns_server, value);
4913   if (res == -2) {
4914      error_msg = "Cannot load PEM";
4915   } else if (res == -3) {
4916      error_msg = "SSL not enabled";
4917   } else if (res == -1) {
4918      error_msg = "SSL_CTX_new() failed";
4919   }
4920   } else if (ind == SSL_CA_CERTIFICATE) {
4921   if (ns_set_ssl_ca_cert(&server->ns_server, value) != 0) {
4922      error_msg = "Error setting CA cert";
4923      }
49274924#endif
4928  }
4925   }
49294926
4930  return error_msg;
4927   return error_msg;
49314928}
49324929
49334930static void set_ips(struct ns_connection *nc, int is_rem) {
4934  struct connection *conn = (struct connection *) nc->connection_data;
4935  struct mg_connection *c = &conn->mg_conn;
4936  char buf[100];
4931   struct connection *conn = (struct connection *) nc->connection_data;
4932   struct mg_connection *c = &conn->mg_conn;
4933   char buf[100];
49374934
4938  ns_sock_to_str(nc->sock, buf, sizeof(buf), is_rem ? 7 : 3);
4939  sscanf(buf, "%47[^:]:%hu",
4940         is_rem ? c->remote_ip : c->local_ip,
4941         is_rem ? &c->remote_port : &c->local_port);
4942  //DBG(("%p %s %s", conn, is_rem ? "rem" : "loc", buf));
4935   ns_sock_to_str(nc->sock, buf, sizeof(buf), is_rem ? 7 : 3);
4936   sscanf(buf, "%47[^:]:%hu",
4937         is_rem ? c->remote_ip : c->local_ip,
4938         is_rem ? &c->remote_port : &c->local_port);
4939   //DBG(("%p %s %s", conn, is_rem ? "rem" : "loc", buf));
49434940}
49444941
49454942static void on_accept(struct ns_connection *nc, union socket_address *sa) {
4946  struct mg_server *server = (struct mg_server *) nc->server;
4947  struct connection *conn;
4943   struct mg_server *server = (struct mg_server *) nc->server;
4944   struct connection *conn;
49484945
4949  if (!check_acl(server->config_options[ACCESS_CONTROL_LIST],
4950                 ntohl(* (uint32_t *) &sa->sin.sin_addr)) ||
4951      (conn = (struct connection *) calloc(1, sizeof(*conn))) == NULL) {
4952    nc->flags |= NSF_CLOSE_IMMEDIATELY;
4953  } else {
4954    // Circularly link two connection structures
4955    nc->connection_data = conn;
4956    conn->ns_conn = nc;
4946   if (!check_acl(server->config_options[ACCESS_CONTROL_LIST],
4947               ntohl(* (uint32_t *) &sa->sin.sin_addr)) ||
4948      (conn = (struct connection *) calloc(1, sizeof(*conn))) == NULL) {
4949   nc->flags |= NSF_CLOSE_IMMEDIATELY;
4950   } else {
4951   // Circularly link two connection structures
4952   nc->connection_data = conn;
4953   conn->ns_conn = nc;
49574954
4958    // Initialize the rest of connection attributes
4959    conn->server = server;
4960    conn->mg_conn.server_param = nc->server->server_data;
4961    set_ips(nc, 1);
4962    set_ips(nc, 0);
4963  }
4955   // Initialize the rest of connection attributes
4956   conn->server = server;
4957   conn->mg_conn.server_param = nc->server->server_data;
4958   set_ips(nc, 1);
4959   set_ips(nc, 0);
4960   }
49644961}
49654962
49664963static void mg_ev_handler(struct ns_connection *nc, enum ns_event ev, void *p) {
4967  struct connection *conn = (struct connection *) nc->connection_data;
4964   struct connection *conn = (struct connection *) nc->connection_data;
49684965
4969  // Send NS event to the handler. Note that call_user won't send an event
4970  // if conn == NULL. Therefore, repeat this for NS_ACCEPT event as well.
4966   // Send NS event to the handler. Note that call_user won't send an event
4967   // if conn == NULL. Therefore, repeat this for NS_ACCEPT event as well.
49714968#ifdef MONGOOSE_SEND_NS_EVENTS
4972  {
4973    struct connection *conn = (struct connection *) nc->connection_data;
4974    void *param[2] = { nc, p };
4975    if (conn != NULL) conn->mg_conn.callback_param = param;
4976    call_user(conn, (enum mg_event) ev);
4977  }
4969   {
4970   struct connection *conn = (struct connection *) nc->connection_data;
4971   void *param[2] = { nc, p };
4972   if (conn != NULL) conn->mg_conn.callback_param = param;
4973   call_user(conn, (enum mg_event) ev);
4974   }
49784975#endif
49794976
4980  switch (ev) {
4981    case NS_ACCEPT:
4982      on_accept(nc, (union socket_address *) p);
4977   switch (ev) {
4978   case NS_ACCEPT:
4979      on_accept(nc, (union socket_address *) p);
49834980#ifdef MONGOOSE_SEND_NS_EVENTS
4984      {
4985        struct connection *conn = (struct connection *) nc->connection_data;
4986        void *param[2] = { nc, p };
4987        if (conn != NULL) conn->mg_conn.callback_param = param;
4988        call_user(conn, (enum mg_event) ev);
4989      }
4981      {
4982      struct connection *conn = (struct connection *) nc->connection_data;
4983      void *param[2] = { nc, p };
4984      if (conn != NULL) conn->mg_conn.callback_param = param;
4985      call_user(conn, (enum mg_event) ev);
4986      }
49904987#endif
4991      break;
4988      break;
49924989
4993    case NS_CONNECT:
4994      if (nc->connection_data != NULL) {
4995        set_ips(nc, 1);
4996        set_ips(nc, 0);
4997      }
4998      conn->mg_conn.status_code = * (int *) p;
4999      if (conn->mg_conn.status_code != 0 ||
5000          (!(nc->flags & MG_PROXY_CONN) &&
5001           call_user(conn, MG_CONNECT) == MG_FALSE)) {
5002        nc->flags |= NSF_CLOSE_IMMEDIATELY;
5003      }
5004      break;
4990   case NS_CONNECT:
4991      if (nc->connection_data != NULL) {
4992      set_ips(nc, 1);
4993      set_ips(nc, 0);
4994      }
4995      conn->mg_conn.status_code = * (int *) p;
4996      if (conn->mg_conn.status_code != 0 ||
4997         (!(nc->flags & MG_PROXY_CONN) &&
4998         call_user(conn, MG_CONNECT) == MG_FALSE)) {
4999      nc->flags |= NSF_CLOSE_IMMEDIATELY;
5000      }
5001      break;
50055002
5006    case NS_RECV:
5007      if (conn != NULL) {
5008        conn->num_bytes_recv += * (int *) p;
5009      }
5010      if (nc->flags & NSF_ACCEPTED) {
5011        on_recv_data(conn);
5003   case NS_RECV:
5004      if (conn != NULL) {
5005      conn->num_bytes_recv += * (int *) p;
5006      }
5007      if (nc->flags & NSF_ACCEPTED) {
5008      on_recv_data(conn);
50125009#ifndef MONGOOSE_NO_CGI
5013      } else if (nc->flags & MG_CGI_CONN) {
5014        on_cgi_data(nc);
5010      } else if (nc->flags & MG_CGI_CONN) {
5011      on_cgi_data(nc);
50155012#endif
5016      } else if (nc->flags & MG_PROXY_CONN) {
5017        if (conn != NULL) {
5018          ns_forward(nc, conn->ns_conn);
5019        }
5020      } else {
5021        process_response(conn);
5022      }
5023      break;
5013      } else if (nc->flags & MG_PROXY_CONN) {
5014      if (conn != NULL) {
5015         ns_forward(nc, conn->ns_conn);
5016      }
5017      } else {
5018      process_response(conn);
5019      }
5020      break;
50245021
5025    case NS_SEND:
5026      break;
5022   case NS_SEND:
5023      break;
50275024
5028    case NS_CLOSE:
5029      nc->connection_data = NULL;
5030      if (nc->flags & (MG_CGI_CONN | MG_PROXY_CONN)) {
5031        DBG(("%p %p closing cgi/proxy conn", conn, nc));
5032        if (conn && conn->ns_conn) {
5033          conn->ns_conn->flags &= ~NSF_BUFFER_BUT_DONT_SEND;
5034          conn->ns_conn->flags |= conn->ns_conn->send_iobuf.len > 0 ?
5035            NSF_FINISHED_SENDING_DATA : NSF_CLOSE_IMMEDIATELY;
5036          conn->endpoint.nc = NULL;
5037        }
5038      } else if (conn != NULL) {
5039        DBG(("%p %p %d closing", conn, nc, conn->endpoint_type));
5025   case NS_CLOSE:
5026      nc->connection_data = NULL;
5027      if (nc->flags & (MG_CGI_CONN | MG_PROXY_CONN)) {
5028      DBG(("%p %p closing cgi/proxy conn", conn, nc));
5029      if (conn && conn->ns_conn) {
5030         conn->ns_conn->flags &= ~NSF_BUFFER_BUT_DONT_SEND;
5031         conn->ns_conn->flags |= conn->ns_conn->send_iobuf.len > 0 ?
5032         NSF_FINISHED_SENDING_DATA : NSF_CLOSE_IMMEDIATELY;
5033         conn->endpoint.nc = NULL;
5034      }
5035      } else if (conn != NULL) {
5036      DBG(("%p %p %d closing", conn, nc, conn->endpoint_type));
50405037
5041        if (conn->endpoint_type == EP_CLIENT && nc->recv_iobuf.len > 0) {
5042          call_http_client_handler(conn);
5043        }
5038      if (conn->endpoint_type == EP_CLIENT && nc->recv_iobuf.len > 0) {
5039         call_http_client_handler(conn);
5040      }
50445041
5045        call_user(conn, MG_CLOSE);
5046        close_local_endpoint(conn);
5047        conn->ns_conn = NULL;
5048        free(conn);
5049      }
5050      break;
5042      call_user(conn, MG_CLOSE);
5043      close_local_endpoint(conn);
5044      conn->ns_conn = NULL;
5045      free(conn);
5046      }
5047      break;
50515048
5052    case NS_POLL:
5053      if (conn != NULL) {
5054        if (call_user(conn, MG_POLL) == MG_TRUE) {
5055          if (conn->ns_conn->flags & MG_HEADERS_SENT) {
5056            write_terminating_chunk(conn);
5057          }
5058          close_local_endpoint(conn);
5059        }
5049   case NS_POLL:
5050      if (conn != NULL) {
5051      if (call_user(conn, MG_POLL) == MG_TRUE) {
5052         if (conn->ns_conn->flags & MG_HEADERS_SENT) {
5053         write_terminating_chunk(conn);
5054         }
5055         close_local_endpoint(conn);
5056      }
50605057
5061        if (conn->endpoint_type == EP_FILE) {
5062          transfer_file_data(conn);
5063        }
5064      }
5058      if (conn->endpoint_type == EP_FILE) {
5059         transfer_file_data(conn);
5060      }
5061      }
50655062
5066      // Expire idle connections
5067      {
5068        time_t current_time = * (time_t *) p;
5063      // Expire idle connections
5064      {
5065      time_t current_time = * (time_t *) p;
50695066
5070        if (conn != NULL && conn->mg_conn.is_websocket) {
5071          ping_idle_websocket_connection(conn, current_time);
5072        }
5067      if (conn != NULL && conn->mg_conn.is_websocket) {
5068         ping_idle_websocket_connection(conn, current_time);
5069      }
50735070
5074        if (nc->last_io_time + MONGOOSE_IDLE_TIMEOUT_SECONDS < current_time) {
5075          mg_ev_handler(nc, NS_CLOSE, NULL);
5076          nc->flags |= NSF_CLOSE_IMMEDIATELY;
5077        }
5078      }
5079      break;
5071      if (nc->last_io_time + MONGOOSE_IDLE_TIMEOUT_SECONDS < current_time) {
5072         mg_ev_handler(nc, NS_CLOSE, NULL);
5073         nc->flags |= NSF_CLOSE_IMMEDIATELY;
5074      }
5075      }
5076      break;
50805077
5081    default:
5082      break;
5083  }
5078   default:
5079      break;
5080   }
50845081}
50855082
50865083static void iter2(struct ns_connection *nc, enum ns_event ev, void *param) {
5087  mg_handler_t func = NULL;
5088  struct connection *conn = (struct connection *) nc->connection_data;
5089  const char *msg = (const char *) param;
5090  int n;
5091  (void) ev;
5084   mg_handler_t func = NULL;
5085   struct connection *conn = (struct connection *) nc->connection_data;
5086   const char *msg = (const char *) param;
5087   int n;
5088   (void) ev;
50925089
5093  //DBG(("%p [%s]", conn, msg));
5094  if (sscanf(msg, "%p %n", &func, &n) && func != NULL) {
5095    conn->mg_conn.callback_param = (void *) (msg + n);
5096    func(&conn->mg_conn, MG_POLL);
5097  }
5090   //DBG(("%p [%s]", conn, msg));
5091   if (sscanf(msg, "%p %n", &func, &n) && func != NULL) {
5092   conn->mg_conn.callback_param = (void *) (msg + n);
5093   func(&conn->mg_conn, MG_POLL);
5094   }
50985095}
50995096
51005097void mg_wakeup_server_ex(struct mg_server *server, mg_handler_t cb,
5101                         const char *fmt, ...) {
5102  va_list ap;
5103  char buf[8 * 1024];
5104  int len;
5098                     const char *fmt, ...) {
5099   va_list ap;
5100   char buf[8 * 1024];
5101   int len;
51055102
5106  // Encode callback (cb) into a buffer
5107  len = snprintf(buf, sizeof(buf), "%p ", cb);
5108  va_start(ap, fmt);
5109  len += vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
5110  va_end(ap);
5103   // Encode callback (cb) into a buffer
5104   len = snprintf(buf, sizeof(buf), "%p ", cb);
5105   va_start(ap, fmt);
5106   len += vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
5107   va_end(ap);
51115108
5112  // "len + 1" is to include terminating \0 in the message
5113  ns_server_wakeup_ex(&server->ns_server, iter2, buf, len + 1);
5109   // "len + 1" is to include terminating \0 in the message
5110   ns_server_wakeup_ex(&server->ns_server, iter2, buf, len + 1);
51145111}
51155112
51165113void mg_wakeup_server(struct mg_server *server) {
5117  ns_server_wakeup_ex(&server->ns_server, NULL, (void *) "", 0);
5114   ns_server_wakeup_ex(&server->ns_server, NULL, (void *) "", 0);
51185115}
51195116
51205117void mg_set_listening_socket(struct mg_server *server, int sock) {
5121  if (server->ns_server.listening_sock != INVALID_SOCKET) {
5122    closesocket(server->ns_server.listening_sock);
5123  }
5124  server->ns_server.listening_sock = (sock_t) sock;
5118   if (server->ns_server.listening_sock != INVALID_SOCKET) {
5119   closesocket(server->ns_server.listening_sock);
5120   }
5121   server->ns_server.listening_sock = (sock_t) sock;
51255122}
51265123
51275124int mg_get_listening_socket(struct mg_server *server) {
5128  return server->ns_server.listening_sock;
5125   return server->ns_server.listening_sock;
51295126}
51305127
51315128const char *mg_get_option(const struct mg_server *server, const char *name) {
5132  const char **opts = (const char **) server->config_options;
5133  int i = get_option_index(name);
5134  return i == -1 ? NULL : opts[i] == NULL ? "" : opts[i];
5129   const char **opts = (const char **) server->config_options;
5130   int i = get_option_index(name);
5131   return i == -1 ? NULL : opts[i] == NULL ? "" : opts[i];
51355132}
51365133
51375134struct mg_server *mg_create_server(void *server_data, mg_handler_t handler) {
5138  struct mg_server *server = (struct mg_server *) calloc(1, sizeof(*server));
5139  ns_server_init(&server->ns_server, server_data, mg_ev_handler);
5140  set_default_option_values(server->config_options);
5141  server->event_handler = handler;
5142  return server;
5135   struct mg_server *server = (struct mg_server *) calloc(1, sizeof(*server));
5136   ns_server_init(&server->ns_server, server_data, mg_ev_handler);
5137   set_default_option_values(server->config_options);
5138   server->event_handler = handler;
5139   return server;
51435140}
51445141
51455142#ifdef _WIN32
51465143static void *mmap(void *addr, int64_t len, int prot, int flags, int fd,
5147                  int offset) {
5148  HANDLE fh = (HANDLE) _get_osfhandle(fd);
5149  HANDLE mh = CreateFileMapping(fh, 0, PAGE_READONLY, 0, 0, 0);
5150  void *p = MapViewOfFile(mh, FILE_MAP_READ, 0, 0, (size_t) len);
5151  CloseHandle(mh);
5152  return p;
5144               int offset) {
5145   HANDLE fh = (HANDLE) _get_osfhandle(fd);
5146   HANDLE mh = CreateFileMapping(fh, 0, PAGE_READONLY, 0, 0, 0);
5147   void *p = MapViewOfFile(mh, FILE_MAP_READ, 0, 0, (size_t) len);
5148   CloseHandle(mh);
5149   return p;
51535150}
51545151#define munmap(x, y)  UnmapViewOfFile(x)
51555152#define MAP_FAILED NULL
r32760r32761
51605157#endif
51615158
51625159void *mg_mmap(FILE *fp, size_t size) {
5163  return mmap(NULL, size, PROT_READ, MAP_PRIVATE, fileno(fp), 0);
5160   return mmap(NULL, size, PROT_READ, MAP_PRIVATE, fileno(fp), 0);
51645161}
51655162
51665163void mg_munmap(void *p, size_t size) {
5167  munmap(p, size);
5164   munmap(p, size);
51685165}
trunk/src/lib/web/mongoose.h
r32760r32761
3131
3232// This structure contains information about HTTP request.
3333struct mg_connection {
34  const char *request_method; // "GET", "POST", etc
35  const char *uri;            // URL-decoded URI
36  const char *http_version;   // E.g. "1.0", "1.1"
37  const char *query_string;   // URL part after '?', not including '?', or NULL
34   const char *request_method; // "GET", "POST", etc
35   const char *uri;            // URL-decoded URI
36   const char *http_version;   // E.g. "1.0", "1.1"
37   const char *query_string;   // URL part after '?', not including '?', or NULL
3838
39  char remote_ip[48];         // Max IPv6 string length is 45 characters
40  char local_ip[48];          // Local IP address
41  unsigned short remote_port; // Client's port
42  unsigned short local_port;  // Local port number
39   char remote_ip[48];         // Max IPv6 string length is 45 characters
40   char local_ip[48];          // Local IP address
41   unsigned short remote_port; // Client's port
42   unsigned short local_port;  // Local port number
4343
44  int num_headers;            // Number of HTTP headers
45  struct mg_header {
46    const char *name;         // HTTP header name
47    const char *value;        // HTTP header value
48  } http_headers[30];
44   int num_headers;            // Number of HTTP headers
45   struct mg_header {
46   const char *name;         // HTTP header name
47   const char *value;        // HTTP header value
48   } http_headers[30];
4949
50  char *content;              // POST (or websocket message) data, or NULL
51  size_t content_len;         // Data length
50   char *content;              // POST (or websocket message) data, or NULL
51   size_t content_len;         // Data length
5252
53  int is_websocket;           // Connection is a websocket connection
54  int status_code;            // HTTP status code for HTTP error handler
55  int wsbits;                 // First byte of the websocket frame
56  void *server_param;         // Parameter passed to mg_add_uri_handler()
57  void *connection_param;     // Placeholder for connection-specific data
58  void *callback_param;       // Needed by mg_iterate_over_connections()
53   int is_websocket;           // Connection is a websocket connection
54   int status_code;            // HTTP status code for HTTP error handler
55   int wsbits;                 // First byte of the websocket frame
56   void *server_param;         // Parameter passed to mg_add_uri_handler()
57   void *connection_param;     // Placeholder for connection-specific data
58   void *callback_param;       // Needed by mg_iterate_over_connections()
5959};
6060
6161struct mg_server; // Opaque structure describing server instance
6262enum mg_result { MG_FALSE, MG_TRUE, MG_MORE };
6363enum mg_event {
64  MG_POLL = 100,  // Callback return value is ignored
65  MG_CONNECT,     // If callback returns MG_FALSE, connect fails
66  MG_AUTH,        // If callback returns MG_FALSE, authentication fails
67  MG_REQUEST,     // If callback returns MG_FALSE, Mongoose continues with req
68  MG_REPLY,       // If callback returns MG_FALSE, Mongoose closes connection
69  MG_RECV,        // Mongoose has received POST data chunk.
70                  // Callback should return a number of bytes to discard from
71                  // the receive buffer, or -1 to close the connection.
72  MG_CLOSE,       // Connection is closed, callback return value is ignored
73  MG_WS_HANDSHAKE,  // New websocket connection, handshake request
74  MG_WS_CONNECT,  // New websocket connection established
75  MG_HTTP_ERROR   // If callback returns MG_FALSE, Mongoose continues with err
64   MG_POLL = 100,  // Callback return value is ignored
65   MG_CONNECT,     // If callback returns MG_FALSE, connect fails
66   MG_AUTH,        // If callback returns MG_FALSE, authentication fails
67   MG_REQUEST,     // If callback returns MG_FALSE, Mongoose continues with req
68   MG_REPLY,       // If callback returns MG_FALSE, Mongoose closes connection
69   MG_RECV,        // Mongoose has received POST data chunk.
70               // Callback should return a number of bytes to discard from
71               // the receive buffer, or -1 to close the connection.
72   MG_CLOSE,       // Connection is closed, callback return value is ignored
73   MG_WS_HANDSHAKE,  // New websocket connection, handshake request
74   MG_WS_CONNECT,  // New websocket connection established
75   MG_HTTP_ERROR   // If callback returns MG_FALSE, Mongoose continues with err
7676};
7777typedef int (*mg_handler_t)(struct mg_connection *, enum mg_event);
7878
7979// Websocket opcodes, from http://tools.ietf.org/html/rfc6455
8080enum {
81  WEBSOCKET_OPCODE_CONTINUATION = 0x0,
82  WEBSOCKET_OPCODE_TEXT = 0x1,
83  WEBSOCKET_OPCODE_BINARY = 0x2,
84  WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
85  WEBSOCKET_OPCODE_PING = 0x9,
86  WEBSOCKET_OPCODE_PONG = 0xa
81   WEBSOCKET_OPCODE_CONTINUATION = 0x0,
82   WEBSOCKET_OPCODE_TEXT = 0x1,
83   WEBSOCKET_OPCODE_BINARY = 0x2,
84   WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
85   WEBSOCKET_OPCODE_PING = 0x9,
86   WEBSOCKET_OPCODE_PONG = 0xa
8787};
8888
8989// Server management functions
r32760r32761
110110size_t mg_printf(struct mg_connection *conn, const char *fmt, ...);
111111
112112size_t mg_websocket_write(struct mg_connection *, int opcode,
113                          const char *data, size_t data_len);
113                     const char *data, size_t data_len);
114114size_t mg_websocket_printf(struct mg_connection* conn, int opcode,
115                           const char *fmt, ...);
115                     const char *fmt, ...);
116116
117117void mg_send_file(struct mg_connection *, const char *path);
118118void mg_send_file_data(struct mg_connection *, int fd);
r32760r32761
120120const char *mg_get_header(const struct mg_connection *, const char *name);
121121const char *mg_get_mime_type(const char *name, const char *default_mime_type);
122122int mg_get_var(const struct mg_connection *conn, const char *var_name,
123               char *buf, size_t buf_len);
123            char *buf, size_t buf_len);
124124int mg_parse_header(const char *hdr, const char *var_name, char *buf, size_t);
125125int mg_parse_multipart(const char *buf, int buf_len,
126                       char *var_name, int var_name_len,
127                       char *file_name, int file_name_len,
128                       const char **data, int *data_len);
126                  char *var_name, int var_name_len,
127                  char *file_name, int file_name_len,
128                  const char **data, int *data_len);
129129
130130// Utility functions
131131void *mg_start_thread(void *(*func)(void *), void *param);
r32760r32761
141141
142142// Templates support
143143struct mg_expansion {
144  const char *keyword;
145  void (*handler)(struct mg_connection *);
144   const char *keyword;
145   void (*handler)(struct mg_connection *);
146146};
147147void mg_template(struct mg_connection *, const char *text,
148                 struct mg_expansion *expansions);
148               struct mg_expansion *expansions);
149149
150150
151151#ifdef __cplusplus
trunk/src/version.c
r32760r32761
99***************************************************************************/
1010
1111extern const char build_version[];
12const char build_version[] = "0.154 (" __DATE__")";
12const char build_version[] = "0.155 (" __DATE__")";
trunk/src/mess/drivers/electron.c
r32760r32761
194194   /* 24000  9 keyboard mirror                              */
195195   /* 28000 10 Basic rom                                    */
196196   ROM_LOAD( "basic.rom", 0x28000, 0x4000, CRC(79434781) SHA1(4a7393f3a45ea309f744441c16723e2ef447a281) )
197   /* 2c000 11 Basic rom mirror                             */
197   /* 2c000 11 Basic rom mirror                             */
198198   ROM_COPY( "user1", 0x28000, 0x2c000, 0x4000 )
199199   /* 30000 12 available for cartridges with a language ROM */
200200   /* 34000 13 available for cartridges with a language ROM */
trunk/src/mess/drivers/vboy.c
r32760r32761
11121112   //AM_RANGE( 0x04000000, 0x04ffffff ) // Expansion area
11131113   AM_RANGE( 0x05000000, 0x0500ffff ) AM_MIRROR(0x0ff0000) AM_RAM AM_SHARE("wram")// Main RAM - 64K mask 0xffff
11141114   AM_RANGE( 0x06000000, 0x06003fff ) AM_DEVREADWRITE("cartslot", vboy_cart_slot_device, read_eeprom, write_eeprom) // Cart RAM - 8K NVRAM
1115//   AM_RANGE( 0x07000000, 0x071fffff ) AM_MIRROR(0x0e00000) AM_DEVREAD("cartslot", vboy_cart_slot_device, read_cart) /* ROM */
1115//  AM_RANGE( 0x07000000, 0x071fffff ) AM_MIRROR(0x0e00000) AM_DEVREAD("cartslot", vboy_cart_slot_device, read_cart) /* ROM */
11161116ADDRESS_MAP_END
11171117
11181118static ADDRESS_MAP_START( vboy_io, AS_IO, 32, vboy_state )
r32760r32761
11411141//  AM_RANGE( 0x04000000, 0x04ffffff ) // Expansion area
11421142   AM_RANGE( 0x05000000, 0x0500ffff ) AM_MIRROR(0x0ff0000) AM_RAM AM_SHARE("wram") // Main RAM - 64K mask 0xffff
11431143   AM_RANGE( 0x06000000, 0x06003fff ) AM_NOP // Cart RAM - 8K NVRAM ?
1144//   AM_RANGE( 0x07000000, 0x071fffff ) AM_MIRROR(0x0e00000) AM_DEVREAD("cartslot", vboy_cart_slot_device, read_cart) /* ROM */
1144//  AM_RANGE( 0x07000000, 0x071fffff ) AM_MIRROR(0x0e00000) AM_DEVREAD("cartslot", vboy_cart_slot_device, read_cart) /* ROM */
11451145ADDRESS_MAP_END
11461146
11471147/* Input ports */
trunk/src/mess/drivers/ngp.c
r32760r32761
136136      m_k1ge(*this, "k1ge"),
137137      m_io_controls(*this, "Controls"),
138138      m_io_power(*this, "Power") ,
139      m_maincpu(*this, "maincpu")
139      m_maincpu(*this, "maincpu")
140140      {
141141         m_flash_chip[0].present = 0;
142142         m_flash_chip[0].state = F_READ;
r32760r32761
651651      m_maincpu->space(AS_PROGRAM).install_read_bank(0x800000, 0x9fffff, "flash1");
652652      membank("flash0")->set_base(cart);
653653      membank("flash1")->set_base(cart + 0x200000);
654     
654
655655      m_flash_chip[0].data = cart;
656656      m_flash_chip[0].org_data[0] = m_flash_chip[0].data[0];
657657      m_flash_chip[0].org_data[1] = m_flash_chip[0].data[1];
r32760r32761
669669      m_flash_chip[0].org_data[13] = m_flash_chip[0].data[0x1fc001];
670670      m_flash_chip[0].org_data[14] = m_flash_chip[0].data[0x1fc002];
671671      m_flash_chip[0].org_data[15] = m_flash_chip[0].data[0x1fc003];
672     
672
673673      m_flash_chip[1].data = cart + 0x200000;
674674      m_flash_chip[1].org_data[0] = m_flash_chip[1].data[0];
675675      m_flash_chip[1].org_data[1] = m_flash_chip[1].data[1];
r32760r32761
739739DEVICE_IMAGE_LOAD_MEMBER( ngp_state, ngp_cart )
740740{
741741   UINT32 size = m_cart->common_get_size("rom");
742   
742
743743   if (size != 0x8000 && size != 0x80000 && size != 0x100000 && size != 0x200000 && size != 0x400000)
744744   {
745745      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
746746      return IMAGE_INIT_FAIL;
747747   }
748   
748
749749   // alloc 0x400000 ROM to simplify mapping in the address map
750750   m_cart->rom_alloc(0x400000, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
751   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
752   
751   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
752
753753   //printf("%2x%2x - %x - %x\n", (unsigned int) memregion("cart")->u8(0x20), (unsigned int) memregion("cart")->u8(0x21),
754754   //        (unsigned int) memregion("cart")->u8(0x22), (unsigned int) memregion("cart")->u8(0x23));
755755   m_flash_chip[0].manufacturer_id = 0x98;
trunk/src/mess/drivers/nes.c
r32760r32761
752752      space.install_write_handler(0x6000, 0x7fff, write8_delegate(FUNC(nes_disksys_device::write_m), (nes_disksys_device *)slot));
753753      space.install_read_handler(0x8000, 0xffff, read8_delegate(FUNC(nes_disksys_device::read_h), (nes_disksys_device *)slot));
754754      space.install_write_handler(0x8000, 0xffff, write8_delegate(FUNC(nes_disksys_device::write_h), (nes_disksys_device *)slot));
755     
755
756756      slot->vram_alloc(0x2000);
757757      slot->prgram_alloc(0x8000);
758     
758
759759      slot->pcb_start(machine(), m_ciram, FALSE);
760760      slot->pcb_reg_postload(machine());
761761      m_ppu->space(AS_PROGRAM).install_readwrite_handler(0, 0x1fff, read8_delegate(FUNC(device_nes_cart_interface::chr_r),(device_nes_cart_interface *)slot), write8_delegate(FUNC(device_nes_cart_interface::chr_w),(device_nes_cart_interface *)slot));
r32760r32761
768768
769769
770770MACHINE_START_MEMBER( nes_state, fds )
771{   
771{
772772   m_ciram = auto_alloc_array(machine(), UINT8, 0x800);
773773   setup_ioports();
774774   setup_disk(m_disk);
r32760r32761
778778{
779779   // Reset the mapper variables
780780   m_disk->pcb_reset();
781   
781
782782   // the rest is the same as for nes/famicom/dendy
783783   m_maincpu->reset();
784   
784
785785   memset(m_pad_latch, 0, sizeof(m_pad_latch));
786786   memset(m_zapper_latch, 0, sizeof(m_zapper_latch));
787787   m_paddle_latch = 0;
788   m_paddle_btn_latch = 0;   
788   m_paddle_btn_latch = 0;
789789}
790790
791791static MACHINE_CONFIG_DERIVED( fds, famicom )
r32760r32761
810810   if (!m_cartslot->exists())
811811   {
812812      setup_disk(m_disk);
813     
813
814814      // replace the famicom disk ROM with the famicom twin one (until we modernize the floppy drive)
815815      m_maincpu->space(AS_PROGRAM).install_read_bank(0xe000, 0xffff, "ftbios");
816816      membank("ftbios")->set_base(machine().root_device().memregion("maincpu")->base() + 0xe000);
r32760r32761
824824   // if there is no cart inserted, initialize the disk expansion instead
825825   if (!m_cartslot->exists())
826826      m_disk->pcb_reset();
827   
827
828828   // the rest is the same as for nes/famicom/dendy
829829   m_maincpu->reset();
830   
830
831831   memset(m_pad_latch, 0, sizeof(m_pad_latch));
832832   memset(m_zapper_latch, 0, sizeof(m_zapper_latch));
833833   m_paddle_latch = 0;
834   m_paddle_btn_latch = 0;   
834   m_paddle_btn_latch = 0;
835835}
836836
837837static MACHINE_CONFIG_DERIVED( famitwin, famicom )
trunk/src/mess/drivers/concept.c
r32760r32761
196196
197197SLOT_INTERFACE_START( concept_a2_cards )
198198   SLOT_INTERFACE("fchdd", A2BUS_CORVUS)  /* Corvus flat-cable HDD interface (see notes in a2corvus.c) */
199   SLOT_INTERFACE("fdc01", A2BUS_CORVFDC01)   /* Corvus WD1793 floppy controller */
200   SLOT_INTERFACE("fdc02", A2BUS_CORVFDC02)   /* Corvus NEC765 buffered floppy controller */
199   SLOT_INTERFACE("fdc01", A2BUS_CORVFDC01)    /* Corvus WD1793 floppy controller */
200   SLOT_INTERFACE("fdc02", A2BUS_CORVFDC02)    /* Corvus NEC765 buffered floppy controller */
201201SLOT_INTERFACE_END
202202
203203
trunk/src/mess/drivers/pencil2.c
r32760r32761
107107   AM_RANGE(0x0000, 0x1fff) AM_ROM
108108   AM_RANGE(0x2000, 0x5fff) AM_WRITENOP  // stop error log filling up
109109   AM_RANGE(0x6000, 0x67ff) AM_MIRROR(0x1800) AM_RAM
110   //AM_RANGE(0x8000, 0xffff)      // mapped by the cartslot
110   //AM_RANGE(0x8000, 0xffff)      // mapped by the cartslot
111111ADDRESS_MAP_END
112112
113113static ADDRESS_MAP_START(pencil2_io, AS_IO, 8, pencil2_state)
trunk/src/mess/drivers/pockstat.c
r32760r32761
961961
962962   if (size != 0x20f40)
963963      return IMAGE_INIT_FAIL;
964   
964
965965   image.fread(cart_id, 0xf40);
966966
967967   for (int i = 0; i < strlen(gme_id); i++)
trunk/src/mess/drivers/casloopy.c
r32760r32761
478478   UINT8 *SRC, *DST;
479479   dynamic_buffer temp;
480480   temp.resize(0x200000);
481   
481
482482   m_cart->rom_alloc(size, GENERIC_ROM32_WIDTH, ENDIANNESS_LITTLE);
483483
484484   SRC = temp;
485485   DST = m_cart->get_rom_base();
486   m_cart->common_load_rom(temp, size, "rom");         
487   
486   m_cart->common_load_rom(temp, size, "rom");
487
488488   // fix endianness
489489   for (int i = 0; i < 0x200000; i += 4)
490490   {
r32760r32761
495495      DST[i + 2] = tempa;
496496      DST[i + 3] = tempb;
497497   }
498   
498
499499   return IMAGE_INIT_PASS;
500500}
501501
trunk/src/mess/drivers/myvision.c
r32760r32761
6666
6767static ADDRESS_MAP_START(myvision_mem, AS_PROGRAM, 8, myvision_state)
6868   ADDRESS_MAP_UNMAP_HIGH
69   //AM_RANGE(0x0000, 0x5fff)      // mapped by the cartslot
69   //AM_RANGE(0x0000, 0x5fff)      // mapped by the cartslot
7070   AM_RANGE(0xa000, 0xa7ff) AM_RAM
7171   AM_RANGE(0xe000, 0xe000) AM_DEVREADWRITE("tms9918", tms9918a_device, vram_read, vram_write)
7272   AM_RANGE(0xe002, 0xe002) AM_DEVREADWRITE("tms9918", tms9918a_device, register_read, register_write)
r32760r32761
144144DEVICE_IMAGE_LOAD_MEMBER( myvision_state, cart )
145145{
146146   UINT32 size = m_cart->common_get_size("rom");
147   
147
148148   if (size != 0x4000 && size != 0x6000)
149149   {
150150      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
151151      return IMAGE_INIT_FAIL;
152152   }
153   
153
154154   m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
155   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
155   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
156156
157157   return IMAGE_INIT_PASS;
158158}
trunk/src/mess/drivers/a2600.c
r32760r32761
244244{
245245   m_cart->write_bank(space, offset, 0);
246246   m_riot_ram[0x20 + offset] = data;
247   
247
248248}
249249
250250WRITE8_MEMBER(a2600_state::cart_over_tia_w)
251251{
252252   // Both Cart & TIA see these addresses
253253   m_cart->write_bank(space, offset, data);
254   m_tia->write(space, offset, data);   
254   m_tia->write(space, offset, data);
255255}
256256
257257MACHINE_START_MEMBER(a2600_state,a2600)
r32760r32761
313313         m_maincpu->space(AS_PROGRAM).install_read_handler(0x1000, 0x1fff, read8_delegate(FUNC(vcs_cart_slot_device::read_rom),(vcs_cart_slot_device*)m_cart));
314314         break;
315315   }
316   
316
317317   /* Banks may have changed, reset the cpu so it uses the correct reset vector */
318318   m_maincpu->reset();
319319}
trunk/src/mess/drivers/fc100.c
r32760r32761
114114static ADDRESS_MAP_START( fc100_mem, AS_PROGRAM, 8, fc100_state )
115115   ADDRESS_MAP_UNMAP_HIGH
116116   AM_RANGE( 0x0000, 0x5fff ) AM_ROM AM_REGION("roms", 0)
117   //AM_RANGE(0x6000, 0x6fff)      // mapped by the cartslot
117   //AM_RANGE(0x6000, 0x6fff)      // mapped by the cartslot
118118   AM_RANGE( 0x7800, 0x7fff ) AM_READ_BANK("bankr") AM_WRITE_BANK("bankw") // Banked RAM/ROM
119119   AM_RANGE( 0x8000, 0xbfff ) AM_RAM // expansion ram pack - if omitted you get a 'Pages?' prompt at boot
120120   AM_RANGE( 0xc000, 0xffff ) AM_RAM AM_SHARE("videoram")
trunk/src/mess/drivers/apple2gs.c
r32760r32761
576576   ROM_LOAD ( "apple2gs.chr", 0x0000, 0x1000, CRC(91e53cd8) SHA1(34e2443e2ef960a36c047a09ed5a93f471797f89))
577577
578578   ROM_REGION(0x20000,"maincpu",0)
579   ROM_LOAD( "apple iigs alpha rom 2.0 19860310.bin", 0x000000, 0x020000, CRC(a47d275f) SHA1(c5836adcfc8be69c7351b84afa94c814e8d92b81) )
579   ROM_LOAD( "apple iigs alpha rom 2.0 19860310.bin", 0x000000, 0x020000, CRC(a47d275f) SHA1(c5836adcfc8be69c7351b84afa94c814e8d92b81) )
580580
581581   ROM_REGION(0x20000, "es5503", ROMREGION_ERASE00)
582582
trunk/src/mess/drivers/pc9801.c
r32760r32761
3838    - Dies on ARTIC check;
3939    - Presumably one ROM is undumped?
4040
41   TODO: (PC-9821AP)
42   - No way to exit the initial loop. Code looks broken/bad dump?
43   
41    TODO: (PC-9821AP)
42    - No way to exit the initial loop. Code looks broken/bad dump?
43
4444    floppy issues TODO (certain fail)
4545    - Unsupported disk types: *.nfd, *.fdd, *.nhd
4646    - 46 Okunen Monogatari - The Shinkaron
r32760r32761
553553   UINT8 m_joy_sel;
554554   UINT8 m_ext2_ff;
555555   UINT8 m_sys_type;
556   
556
557557   DECLARE_WRITE_LINE_MEMBER( keyboard_irq );
558558   DECLARE_WRITE_LINE_MEMBER( write_uart_clock );
559559   DECLARE_READ8_MEMBER(pc9801_xx_r);
r32760r32761
702702   DECLARE_MACHINE_START(pc9801bx2);
703703   DECLARE_MACHINE_START(pc9821);
704704   DECLARE_MACHINE_START(pc9821ap2);
705   
705
706706   DECLARE_MACHINE_RESET(pc9801_common);
707707   DECLARE_MACHINE_RESET(pc9801f);
708708   DECLARE_MACHINE_RESET(pc9801rs);
r32760r32761
19381938WRITE8_MEMBER(pc9801_state::pc9801rs_bank_w)
19391939{
19401940   if(offset == 1)
1941   {   
1941   {
19421942      if((data & 0xf0) == 0x00 || (data & 0xf0) == 0x10)
19431943      {
19441944         if((data & 0xed) == 0x00)
r32760r32761
33753375MACHINE_START_MEMBER(pc9801_state,pc9821ap2)
33763376{
33773377   MACHINE_START_CALL_MEMBER(pc9821);
3378   
3378
33793379   // ...
33803380}
33813381
r32760r32761
38913891   MCFG_CPU_IO_MAP(pc9821_io)
38923892   MCFG_CPU_VBLANK_INT_DRIVER("screen", pc9801_state, pc9801_vrtc_irq)
38933893   MCFG_CPU_IRQ_ACKNOWLEDGE_DEVICE("pic8259_master", pic8259_device, inta_cb)
3894   
3894
38953895   MCFG_MACHINE_START_OVERRIDE(pc9801_state,pc9821ap2)
38963896MACHINE_CONFIG_END
38973897
trunk/src/mess/drivers/a7800.c
r32760r32761
99    2002/05/13 kubecj   added more banks for bankswitching
1010                        added PAL machine description
1111                        changed clock to be precise
12                  improved cart emulation (in machine/)
12                        improved cart emulation (in machine/)
1313
1414    2012/10/25 Robert Tuccitto  NTSC Color Generator utilized for
1515                color palette with hue shift/start
r32760r32761
8888
8989    2014/05/06 Mike Saarna/Robert Tuccitto Brought initial Maria cycle counts
9090               inline from measurements taken with logic analyzer and tests.
91
91
9292    2014/08/25 Fabio Priuli Converted carts to be slot devices and cleaned
9393               up the driver (removed the pokey, cleaned up rom regions, etc.)
94
94
9595***************************************************************************/
9696
9797#include "emu.h"
r32760r32761
121121   m_io_console_buttons(*this, "console_buttons"),
122122   m_cart(*this, "cartslot"),
123123   m_screen(*this, "screen") { }
124   
124
125125   int m_lines;
126126   int m_ispal;
127   
127
128128   int m_ctrl_lock;
129129   int m_ctrl_reg;
130130   int m_maria_flag;
131131   int m_p1_one_button;
132132   int m_p2_one_button;
133133   int m_bios_enabled;
134   
134
135135   UINT8 *m_bios;
136   
136
137137   DECLARE_READ8_MEMBER(bios_or_cart_r);
138138   DECLARE_WRITE8_MEMBER(ram0_w);
139139   DECLARE_READ8_MEMBER(tia_r);
r32760r32761
151151   DECLARE_READ8_MEMBER(riot_joystick_r);
152152   DECLARE_READ8_MEMBER(riot_console_button_r);
153153   DECLARE_WRITE8_MEMBER(riot_button_pullup_w);
154   
154
155155protected:
156156   required_device<cpu_device> m_maincpu;
157157   required_device<tia_device> m_tia;
r32760r32761
223223            return 0x80;
224224      default:
225225         logerror("undefined TIA read %x\n",offset);
226         
226
227227   }
228228   return 0xff;
229229}
r32760r32761
231231// TIA
232232WRITE8_MEMBER(a7800_state::tia_w)
233233{
234   if (offset < 0x20)
234   if (offset < 0x20)
235235   { //INPTCTRL covers TIA registers 0x00-0x1F until locked
236236      if (data & 0x01)
237237      {
r32760r32761
291291   AM_RANGE(0x2040, 0x20ff) AM_RAMBANK("ram0")     // mirror (6116 block 0)
292292   AM_RANGE(0x2140, 0x21ff) AM_RAMBANK("ram1")     // mirror (6116 block 1)
293293
294   AM_RANGE(0x2800, 0x2fff) AM_RAMBANK("mirror")   // these should mirror "main_ram" (according to docs)
294   AM_RANGE(0x2800, 0x2fff) AM_RAMBANK("mirror")   // these should mirror "main_ram" (according to docs)
295295   AM_RANGE(0x3000, 0x37ff) AM_RAMBANK("mirror")   // but system have issues in such case...
296296   AM_RANGE(0x3800, 0x3fff) AM_RAMBANK("mirror")
297297   AM_RANGE(0x4000, 0xffff) AM_DEVWRITE("cartslot", a78_cart_slot_device, write_40xx)
298298   AM_RANGE(0x4000, 0xbfff) AM_DEVREAD("cartslot", a78_cart_slot_device, read_40xx)
299   AM_RANGE(0xc000, 0xffff) AM_READ(bios_or_cart_r)   // here also the BIOS can be accessed
299   AM_RANGE(0xc000, 0xffff) AM_READ(bios_or_cart_r)    // here also the BIOS can be accessed
300300ADDRESS_MAP_END
301301
302302
r32760r32761
13131313   save_item(NAME(m_ctrl_lock));
13141314   save_item(NAME(m_ctrl_reg));
13151315   save_item(NAME(m_maria_flag));
1316   
1316
13171317   // install additional handlers, if needed
13181318   if (m_cart->exists())
13191319   {
trunk/src/mess/drivers/sv8000.c
r32760r32761
9494
9595static ADDRESS_MAP_START(sv8000_mem, AS_PROGRAM, 8, sv8000_state)
9696   ADDRESS_MAP_UNMAP_HIGH
97   //AM_RANGE(0x0000, 0x0fff)      // mapped by the cartslot
97   //AM_RANGE(0x0000, 0x0fff)      // mapped by the cartslot
9898   AM_RANGE( 0x8000, 0x83ff ) AM_RAM // Work RAM??
9999   AM_RANGE( 0xc000, 0xcbff ) AM_RAM AM_SHARE("videoram")
100100ADDRESS_MAP_END
r32760r32761
197197DEVICE_IMAGE_LOAD_MEMBER( sv8000_state, cart )
198198{
199199   UINT32 size = m_cart->common_get_size("rom");
200   
200
201201   if (size != 0x1000)
202202   {
203203      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Incorrect or not support cartridge size");
204204      return IMAGE_INIT_FAIL;
205205   }
206   
206
207207   m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
208   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
209   
208   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
209
210210   return IMAGE_INIT_PASS;
211211}
212212
trunk/src/mess/drivers/tsispch.c
r32760r32761
482482   //      0 - to /CE of ROMs 12(U27) and 13(U50)
483483   //
484484   // Note U81 is optional; it can be replaced by a 74s138 instead of a prom,
485   // with A19, A18, A17 as inputs, for decoding the roms as:     
485   // with A19, A18, A17 as inputs, for decoding the roms as:
486486   //      7 - to /CE of ROMs 0(U21) and 1(U44)   (0xE0000-0xE3FFF)
487487   //      6 - to /CE of ROMs 2(U22) and 3(U45)   (0xE4000-0xE7FFF)
488488   //      5 - to /CE of ROMs 4(U23) and 5(U46)   (0xE8000-0xEBFFF)
r32760r32761
490490   //      3 - to /CE of ROMs 8(U25) and 9(U48)   (0xF0000-0xF3FFF)
491491   //      2 - to /CE of ROMs 10(U26) and 11(U49) (0xF4000-0xF7FFF)
492492   //      1 - to /CE of ROMs 12(U27) and 13(U50) (0xF8000-0xFBFFF)
493   //      0 - to /CE of ROMs 14(U28) and 15(U51) (0xFC000-0xFFFFF)                                               
494   
493   //      0 - to /CE of ROMs 14(U28) and 15(U51) (0xFC000-0xFFFFF)
494
495495   ROM_REGION(0x1000, "proms", 0)
496496   ROM_LOAD( "am27s19.u77", 0x0000, 0x0020, CRC(A88757FC) SHA1(9066D6DBC009D7A126D75B8461CA464DDF134412))
497497   ROM_LOAD( "am27s19.u79", 0x0020, 0x0020, CRC(A165B090) SHA1(BFC413C79915C68906033741318C070AD5DD0F6B))
trunk/src/mess/drivers/tutor.c
r32760r32761
196196   optional_device<cassette_image_device> m_cass;
197197   optional_device<centronics_device> m_centronics;
198198   optional_device<output_latch_device> m_cent_data_out;
199   required_memory_bank m_bank1;   
199   required_memory_bank m_bank1;
200200   memory_region *m_cart_rom;
201201
202202   DECLARE_READ8_MEMBER(key_r);
r32760r32761
223223{
224224   astring region_tag;
225225   m_cart_rom = memregion(region_tag.cpy(m_cart->tag()).cat(GENERIC_ROM_REGION_TAG));
226   
226
227227   m_tape_interrupt_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tutor_state::tape_interrupt_handler),this));
228   
228
229229   m_bank1->configure_entry(0, memregion("maincpu")->base() + 0x8000);
230230   m_bank1->set_entry(0);
231231
trunk/src/mess/drivers/svision.c
r32760r32761
452452DEVICE_IMAGE_LOAD_MEMBER( svision_state, svision_cart )
453453{
454454   UINT32 size = m_cart->common_get_size("rom");
455   
455
456456   if (size > 0x20000)
457457   {
458458      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
459459      return IMAGE_INIT_FAIL;
460460   }
461   
461
462462   m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
463   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
464   
463   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
464
465465   return IMAGE_INIT_PASS;
466466}
467467
trunk/src/mess/drivers/specpls3.c
r32760r32761
217217      int ram_page = m_port_7ffd_data & 0x07;
218218      unsigned char *ram_data = messram + (ram_page<<14);
219219      membank("bank4")->set_base(ram_data);
220     
220
221221      logerror("RAM at 0xc000: %02x\n", ram_page);
222     
222
223223      /* Reset memory between 0x4000 - 0xbfff in case extended paging was being used */
224224      /* Bank 5 in 0x4000 - 0x7fff */
225225      membank("bank2")->set_base(messram + (5 << 14));
226     
226
227227      /* Bank 2 in 0x8000 - 0xbfff */
228228      membank("bank3")->set_base(messram + (2 << 14));
229229
r32760r32761
231231      {
232232         /* ROM switching */
233233         int ROMSelection = BIT(m_port_7ffd_data, 4) | ((m_port_1ffd_data >> 1) & 0x02);
234         
234
235235         /* rom 0 is editor, rom 1 is syntax, rom 2 is DOS, rom 3 is 48 BASIC */
236236         unsigned char *ChosenROM = memregion("maincpu")->base() + 0x010000 + (ROMSelection << 14);
237         
237
238238         membank("bank1")->set_base(ChosenROM);
239239         space.unmap_write(0x0000, 0x3fff);
240         
240
241241         logerror("rom switch: %02x\n", ROMSelection);
242242      }
243243   }
r32760r32761
247247      int MemorySelection = (m_port_1ffd_data >> 1) & 0x03;
248248      const int *memory_selection = &spectrum_plus3_memory_selections[(MemorySelection << 2)];
249249      unsigned char *ram_data = messram + (memory_selection[0] << 14);
250     
250
251251      membank("bank1")->set_base(ram_data);
252252      /* allow writes to 0x0000-0x03fff */
253253      space.install_write_bank(0x0000, 0x3fff, "bank1");
254     
254
255255      ram_data = messram + (memory_selection[1] << 14);
256256      membank("bank2")->set_base(ram_data);
257     
257
258258      ram_data = messram + (memory_selection[2] << 14);
259259      membank("bank3")->set_base(ram_data);
260     
260
261261      ram_data = messram + (memory_selection[3] << 14);
262262      membank("bank4")->set_base(ram_data);
263     
263
264264      logerror("extended memory paging: %02x\n", MemorySelection);
265265   }
266266}
trunk/src/mess/drivers/beta.c
r32760r32761
6060      m_q8(*this, "Q8"),
6161      m_q9(*this, "Q9")
6262   { }
63   
63
6464   required_device<cpu_device> m_maincpu;
6565   required_device<speaker_sound_device> m_speaker;
6666   required_device<generic_slot_device> m_eprom;
r32760r32761
6868   required_ioport m_q7;
6969   required_ioport m_q8;
7070   required_ioport m_q9;
71   
71
7272   virtual void machine_start();
73   
73
7474   DECLARE_READ8_MEMBER( riot_pa_r );
7575   DECLARE_WRITE8_MEMBER( riot_pa_w );
7676   DECLARE_READ8_MEMBER( riot_pb_r );
7777   DECLARE_WRITE8_MEMBER( riot_pb_w );
7878   DECLARE_INPUT_CHANGED_MEMBER( trigger_reset );
79   
79
8080   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( beta_eprom );
8181   DECLARE_DEVICE_IMAGE_UNLOAD_MEMBER( beta_eprom );
82   
82
8383   /* EPROM state */
8484   int m_eprom_oe;
8585   int m_eprom_ce;
r32760r32761
8787   UINT8 m_eprom_data;
8888   UINT8 m_old_data;
8989   dynamic_buffer m_eprom_rom;
90   
90
9191   /* display state */
9292   UINT8 m_ls145_p;
9393   UINT8 m_segment;
94   
94
9595   emu_timer *m_led_refresh_timer;
9696   TIMER_CALLBACK_MEMBER(led_refresh);
9797};
r32760r32761
285285DEVICE_IMAGE_LOAD_MEMBER( beta_state, beta_eprom )
286286{
287287   UINT32 size = m_eprom->common_get_size("rom");
288   
288
289289   if (size != 0x800)
290290   {
291291      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
292292      return IMAGE_INIT_FAIL;
293293   }
294   
294
295295   m_eprom->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
296   m_eprom->common_load_rom(m_eprom->get_rom_base(), size, "rom");         
297   
296   m_eprom->common_load_rom(m_eprom->get_rom_base(), size, "rom");
297
298298   return IMAGE_INIT_PASS;
299299}
300300
trunk/src/mess/drivers/atom.c
r32760r32761
250250   AM_RANGE(0x0a05, 0x7fff) AM_RAM
251251   AM_RANGE(0x8000, 0x97ff) AM_RAM AM_SHARE("video_ram")
252252   AM_RANGE(0x9800, 0x9fff) AM_RAM
253//  AM_RANGE(0xa000, 0xafff)      // mapped by the cartslot
253//  AM_RANGE(0xa000, 0xafff)        // mapped by the cartslot
254254   AM_RANGE(0xb000, 0xb003) AM_MIRROR(0x3fc) AM_DEVREADWRITE(INS8255_TAG, i8255_device, read, write)
255255//  AM_RANGE(0xb400, 0xb403) AM_DEVREADWRITE(MC6854_TAG, mc6854_device, read, write)
256256//  AM_RANGE(0xb404, 0xb404) AM_READ_PORT("ECONET")
r32760r32761
680680   }
681681
682682   slot->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
683   slot->common_load_rom(slot->get_rom_base(), size, "rom");         
683   slot->common_load_rom(slot->get_rom_base(), size, "rom");
684684
685685   return IMAGE_INIT_PASS;
686686}
r32760r32761
882882DRIVER_INIT_MEMBER(atomeb_state, atomeb)
883883{
884884   // these have to be set here, so that we can pass m_ext[*] to device_image_load!
885   char str[8];   
885   char str[8];
886886   for (int i = 0; i < 16; i++)
887887   {
888888      sprintf(str,"rom_a%x", i);
889889      m_ext[i] = machine().device<generic_slot_device>(str);
890   }         
890   }
891891}
892892
893893
trunk/src/mess/drivers/uzebox.c
r32760r32761
273273DEVICE_IMAGE_LOAD_MEMBER(uzebox_state, uzebox_cart)
274274{
275275   UINT32 size = m_cart->common_get_size("rom");
276   
276
277277   m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
278278
279279   if (image.software_entry() == NULL)
trunk/src/mess/drivers/supracan.c
r32760r32761
11251125}
11261126
11271127static ADDRESS_MAP_START( supracan_mem, AS_PROGRAM, 16, supracan_state )
1128   //AM_RANGE( 0x000000, 0x3fffff )      // mapped by the cartslot
1128   //AM_RANGE( 0x000000, 0x3fffff )        // mapped by the cartslot
11291129   AM_RANGE( 0xe80200, 0xe80201 ) AM_READ_PORT("P1")
11301130   AM_RANGE( 0xe80202, 0xe80203 ) AM_READ_PORT("P2")
11311131   AM_RANGE( 0xe80208, 0xe80209 ) AM_READ_PORT("P3")
r32760r32761
17541754DEVICE_IMAGE_LOAD_MEMBER( supracan_state, supracan_cart )
17551755{
17561756   UINT32 size = m_cart->common_get_size("rom");
1757   
1757
17581758   if (size > 0x400000)
17591759   {
17601760      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
r32760r32761
17621762   }
17631763
17641764   m_cart->rom_alloc(size, GENERIC_ROM16_WIDTH, ENDIANNESS_BIG);
1765   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
1766   
1765   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
1766
17671767   return IMAGE_INIT_PASS;
17681768}
17691769
trunk/src/mess/drivers/channelf.c
r32760r32761
178178            m_maincpu->space(AS_PROGRAM).install_write_handler(0x3000, 0x3fff, write8_delegate(FUNC(channelf_cart_slot_device::write_bank),(channelf_cart_slot_device*)m_cart));
179179            break;
180180      }
181     
181
182182      m_cart->save_ram();
183183   }
184184}
trunk/src/mess/drivers/pc8401a.c
r32760r32761
521521
522522   /* bank switch */
523523   bankswitch(0);
524   
524
525525   /* register for state saving */
526526   save_item(NAME(m_mmr));
527527   save_item(NAME(m_io_addr));
trunk/src/mess/drivers/spc1000.c
r32760r32761
7070   DECLARE_READ8_MEMBER(fdc_8255_c_r);
7171   DECLARE_WRITE8_MEMBER(fdc_8255_c_w);
7272   DECLARE_READ8_MEMBER( upd765_tc_r );
73   DECLARE_WRITE8_MEMBER( fdc_control_w );   
73   DECLARE_WRITE8_MEMBER( fdc_control_w );
7474   MC6847_GET_CHARROM_MEMBER(get_char_rom)
7575   {
7676      return m_p_videoram[0x1000 + (ch & 0x7f) * 16 + line];
r32760r32761
8585   virtual void machine_reset();
8686   required_device<mc6847_base_device> m_vdg;
8787   required_device<cpu_device> m_maincpu;
88   required_device<cpu_device> m_fdccpu;   
89   required_device<upd765a_device> m_fdc;   
88   required_device<cpu_device> m_fdccpu;
89   required_device<upd765a_device> m_fdc;
9090   required_device<i8255_device> m_pio;
9191   required_device<ram_device> m_ram;
9292   required_device<cassette_image_device> m_cass;
9393
9494   floppy_image_device *m_fd0;
9595   floppy_image_device *m_fd1;
96   
97   emu_timer *m_timer_tc;   
98   
96
97   emu_timer *m_timer_tc;
98
9999   UINT8 m_i8255_0_pc;
100100   UINT8 m_i8255_1_pc;
101101   UINT8 m_i8255_portb;
102   
102
103103   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
104104};
105105
106106void spc1000_state::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
107107{
108   m_fdc->tc_w(false);   
108   m_fdc->tc_w(false);
109109}
110110
111111static ADDRESS_MAP_START(spc1000_mem, AS_PROGRAM, 8, spc1000_state )
r32760r32761
255255   AM_RANGE(0x8009, 0x8009) AM_READ_PORT("LINE9")
256256   AM_RANGE(0xA000, 0xA000) AM_READWRITE(spc1000_iplk_r, spc1000_iplk_w)
257257   AM_RANGE(0xC000, 0xC002) AM_READWRITE(spc1000_sd725_r, spc1000_sd725_w)
258//   AM_RANGE(0xC000, 0xC003) AM_DEVREADWRITE("d8255_master", i8255_device, read, write)
258//  AM_RANGE(0xC000, 0xC003) AM_DEVREADWRITE("d8255_master", i8255_device, read, write)
259259ADDRESS_MAP_END
260260
261261/* Input ports */
r32760r32761
342342      PORT_BIT(0x40, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("I") PORT_CODE(KEYCODE_I) PORT_CHAR('i') PORT_CHAR('I') PORT_CHAR(0x09)
343343      PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("8 (") PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('(')
344344   PORT_START("LINE9")
345      PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_START)   PORT_NAME("IPL") PORT_CODE(KEYCODE_END)
345      PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_START)    PORT_NAME("IPL") PORT_CODE(KEYCODE_END)
346346      PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("F5") PORT_CODE(KEYCODE_F5)
347347      PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("- =") PORT_CODE(KEYCODE_MINUS) PORT_CHAR('-') PORT_CHAR('=')
348348      PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("0") PORT_CODE(KEYCODE_0) PORT_CHAR('0')
r32760r32761
369369   membank("bank2")->set_base(ram);
370370   membank("bank3")->set_base(mem);
371371   membank("bank4")->set_base(ram + 0x8000);
372   
372
373373   m_work_ram = auto_alloc_array_clear(machine(), UINT8, 0x10000);
374374   m_fdccpu->set_input_line_vector(0, 0);
375   
375
376376   m_fd0 = machine().device<floppy_connector>("upd765:0")->get_device();
377377   m_fd1 = machine().device<floppy_connector>("upd765:1")->get_device();
378378
379   m_timer_tc = timer_alloc(1, NULL);   
379   m_timer_tc = timer_alloc(1, NULL);
380380   m_timer_tc->adjust(attotime::never);
381381
382382   // enable rom
383   m_fdccpu->space(AS_PROGRAM).install_rom(0x0000, 0xfff, 0, 0x2000, memregion("rom")->base());   
384   
385   m_IPLK = 1;
383   m_fdccpu->space(AS_PROGRAM).install_rom(0x0000, 0xfff, 0, 0x2000, memregion("rom")->base());
384
385   m_IPLK = 1;
386386}
387387
388388READ8_MEMBER(spc1000_state::mc6847_videoram_r)
r32760r32761
452452   MCFG_CPU_ADD("fdccpu", Z80, XTAL_4MHz)       /* 4 MHz */
453453   MCFG_CPU_PROGRAM_MAP(sd725_mem)
454454   MCFG_CPU_IO_MAP(sd725_io)
455   
455
456456   MCFG_DEVICE_ADD("d8255_master", I8255, 0)
457457   MCFG_I8255_IN_PORTA_CB(DEVREAD8("d8255_master", i8255_device, pb_r))
458458   MCFG_I8255_IN_PORTB_CB(DEVREAD8("d8255_master", i8255_device, pa_r))
459   MCFG_I8255_OUT_PORTB_CB(WRITE8(spc1000_state, fdc_8255_b_w))   
459   MCFG_I8255_OUT_PORTB_CB(WRITE8(spc1000_state, fdc_8255_b_w))
460460   MCFG_I8255_IN_PORTC_CB(READ8(spc1000_state, fdc_8255_c_r))
461   MCFG_I8255_OUT_PORTC_CB(WRITE8(spc1000_state, fdc_8255_c_w))   
461   MCFG_I8255_OUT_PORTC_CB(WRITE8(spc1000_state, fdc_8255_c_w))
462462
463463   // floppy disk controller
464464   MCFG_UPD765A_ADD("upd765", true, true)
465   MCFG_UPD765_INTRQ_CALLBACK(INPUTLINE("fdccpu", INPUT_LINE_IRQ0))   
465   MCFG_UPD765_INTRQ_CALLBACK(INPUTLINE("fdccpu", INPUT_LINE_IRQ0))
466466
467467   // floppy drives
468468   MCFG_FLOPPY_DRIVE_ADD("upd765:0", sd725_floppies, "sd320", floppy_image_device::default_floppy_formats)
469   MCFG_FLOPPY_DRIVE_ADD("upd765:1", sd725_floppies, "sd320", floppy_image_device::default_floppy_formats)   
469   MCFG_FLOPPY_DRIVE_ADD("upd765:1", sd725_floppies, "sd320", floppy_image_device::default_floppy_formats)
470470   //CFG_SOFTWARE_LIST_ADD("disk_list","spc1000_flop")
471   
471
472472   /* video hardware */
473473   MCFG_SCREEN_MC6847_NTSC_ADD("screen", "mc6847")
474474
r32760r32761
501501   ROM_REGION( 0x10000, "maincpu", ROMREGION_ERASEFF )
502502   ROM_LOAD( "spcall.rom", 0x0000, 0x8000, CRC(19638fc9) SHA1(489f1baa7aebf3c8c660325fb1fd790d84203284))
503503
504    ROM_REGION( 0x10000, "fdccpu", 0)
505    ROM_LOAD("sd725a.bin", 0x0000, 0x1000, CRC(96ac2eb8) SHA1(8e9d8f63a7fb87af417e95603e71cf537a6e83f1))
504   ROM_REGION( 0x10000, "fdccpu", 0)
505   ROM_LOAD("sd725a.bin", 0x0000, 0x1000, CRC(96ac2eb8) SHA1(8e9d8f63a7fb87af417e95603e71cf537a6e83f1))
506506ROM_END
507507
508508#if 0
trunk/src/mess/drivers/atarist.c
r32760r32761
12281228   AM_RANGE(0x000008, 0x1fffff) AM_RAM
12291229   AM_RANGE(0x200000, 0x3fffff) AM_RAM
12301230   AM_RANGE(0x400000, 0xf9ffff) AM_READWRITE(berr_r, berr_w)
1231   //AM_RANGE(0xfa0000, 0xfbffff)      // mapped by the cartslot
1231   //AM_RANGE(0xfa0000, 0xfbffff)      // mapped by the cartslot
12321232   AM_RANGE(0xfc0000, 0xfeffff) AM_ROM AM_REGION(M68000_TAG, 0) AM_WRITE(berr_w)
12331233   AM_RANGE(0xff8000, 0xff8001) AM_READWRITE8(mmu_r, mmu_w, 0x00ff)
12341234   AM_RANGE(0xff8200, 0xff8203) AM_READWRITE8(shifter_base_r, shifter_base_w, 0x00ff)
r32760r32761
12721272   AM_RANGE(0x000000, 0x000007) AM_ROM AM_REGION(M68000_TAG, 0)
12731273   AM_RANGE(0x000008, 0x1fffff) AM_RAM
12741274   AM_RANGE(0x200000, 0x3fffff) AM_RAM
1275   //AM_RANGE(0xfa0000, 0xfbffff)      // mapped by the cartslot
1275   //AM_RANGE(0xfa0000, 0xfbffff)      // mapped by the cartslot
12761276   AM_RANGE(0xfc0000, 0xfeffff) AM_ROM AM_REGION(M68000_TAG, 0)
12771277//  AM_RANGE(0xff7f30, 0xff7f31) AM_READWRITE(blitter_dst_inc_y_r, blitter_dst_inc_y_w) // for TOS 1.02
12781278   AM_RANGE(0xff8000, 0xff8001) AM_READWRITE8(mmu_r, mmu_w, 0x00ff)
trunk/src/mess/drivers/ep64.c
r32760r32761
320320
321321static ADDRESS_MAP_START( dave_64k_mem, AS_PROGRAM, 8, ep64_state )
322322   AM_RANGE(0x000000, 0x007fff) AM_ROM AM_REGION(Z80_TAG, 0)
323   //AM_RANGE(0x010000, 0x01ffff)      // mapped by the cartslot
323   //AM_RANGE(0x010000, 0x01ffff)      // mapped by the cartslot
324324   AM_RANGE(0x3f0000, 0x3fffff) AM_DEVICE(NICK_TAG, nick_device, vram_map)
325325ADDRESS_MAP_END
326326
trunk/src/mess/drivers/pet.c
r32760r32761
248248            data = m_rom->base()[offset - 0x9000];
249249      }
250250      break;
251         
251
252252   case SELB:
253253      if (norom)
254254      {
r32760r32761
258258            data = m_rom->base()[offset - 0x9000];
259259      }
260260      break;
261         
261
262262   case SELC: case SELD: case SELF:
263263      if (norom)
264264      {
trunk/src/mess/drivers/m5.c
r32760r32761
243243static ADDRESS_MAP_START( m5_mem, AS_PROGRAM, 8, m5_state )
244244   ADDRESS_MAP_UNMAP_HIGH
245245   AM_RANGE(0x0000, 0x1fff) AM_ROM
246   //AM_RANGE(0x2000, 0x6fff)      // mapped by the cartslot
246   //AM_RANGE(0x2000, 0x6fff)      // mapped by the cartslot
247247   AM_RANGE(0x7000, 0x7fff) AM_RAM
248248   AM_RANGE(0x8000, 0xffff) AM_RAM
249249ADDRESS_MAP_END
trunk/src/mess/drivers/atari400.c
r32760r32761
252252      m_8000(*this, "8000"),
253253      m_a000(*this, "a000"),
254254      m_cart(*this, "cartleft"),
255      m_cart2(*this, "cartright")   { }
255      m_cart2(*this, "cartright") { }
256256
257257   DECLARE_MACHINE_START(a400);
258258   DECLARE_MACHINE_START(a800);
r32760r32761
267267   DECLARE_WRITE8_MEMBER(a600xl_pia_pb_w);
268268   DECLARE_WRITE8_MEMBER(a800xl_pia_pb_w);
269269
270   DECLARE_READ8_MEMBER(read_d5xx);   // at least one cart type can enable/disable roms when reading
270   DECLARE_READ8_MEMBER(read_d5xx);    // at least one cart type can enable/disable roms when reading
271271   DECLARE_WRITE8_MEMBER(disable_cart);
272272
273273   // these are needed to handle carts which can disable ROM without
r32760r32761
290290   DECLARE_WRITE8_MEMBER(xegs_low_w);
291291   DECLARE_READ8_MEMBER(xegs_high_r);
292292   DECLARE_WRITE8_MEMBER(xegs_high_w);
293   
293
294294   TIMER_DEVICE_CALLBACK_MEMBER(a400_interrupt);
295295   TIMER_DEVICE_CALLBACK_MEMBER(a800xl_interrupt);
296296   TIMER_DEVICE_CALLBACK_MEMBER(a5200_interrupt);
297   
297
298298protected:
299   //required_device<cpu_device> m_maincpu;   // maincpu is already contained in atari_common_state
299   //required_device<cpu_device> m_maincpu;    // maincpu is already contained in atari_common_state
300300   required_device<ram_device> m_ram;
301301   required_device<pia6821_device> m_pia;
302302   optional_device<dac_device> m_dac;
r32760r32761
310310   int m_cart_disabled, m_cart_helper;
311311   int m_last_offs;
312312   UINT8 m_mmu, m_ext_bank;
313   
313
314314   void setup_ram(int bank,UINT32 size);
315315   void setup_cart(a800_cart_slot_device *slot);
316316};
r32760r32761
334334
335335READ8_MEMBER(a400_state::a1200xl_low_r)
336336{
337   if (offset < 0x5000)   // 0x0000-0x4fff
337   if (offset < 0x5000)    // 0x0000-0x4fff
338338      return m_ram->pointer()[offset];
339   else if (offset < 0x5800)   // 0x5000-0x57ff
339   else if (offset < 0x5800)   // 0x5000-0x57ff
340340   {
341341      if (m_mmu & 0x80)
342342         return m_ram->pointer()[offset];
343343      else
344344         return m_region_maincpu->base()[0xd000 + (offset & 0x7ff)];
345345   }
346   else if (offset < 0xc000)   // 0x5800-0xbfff
346   else if (offset < 0xc000)   // 0x5800-0xbfff
347347      return m_ram->pointer()[offset];
348   else   // 0xc000-0xcfff
348   else    // 0xc000-0xcfff
349349   {
350350      if (!(m_mmu & 0x01))
351351         return m_ram->pointer()[offset];
r32760r32761
356356
357357READ8_MEMBER(a400_state::a800xl_low_r)
358358{
359   if (offset < 0x5000)   // 0x0000-0x4fff
359   if (offset < 0x5000)    // 0x0000-0x4fff
360360      return m_ram->pointer()[offset];
361   else if (offset < 0x5800)   // 0x5000-0x57ff
361   else if (offset < 0x5800)   // 0x5000-0x57ff
362362   {
363363      if (m_mmu & 0x80)
364364         return m_ram->pointer()[offset];
365365      else
366366         return m_region_maincpu->base()[0xd000 + (offset & 0x7ff)];
367367   }
368   else if (offset < 0xa000)   // 0x5800-0x9fff
368   else if (offset < 0xa000)   // 0x5800-0x9fff
369369      return m_ram->pointer()[offset];
370   else if (offset < 0xc000)   // 0xa000-0xbfff
370   else if (offset < 0xc000)   // 0xa000-0xbfff
371371   {
372372      if (m_mmu & 0x02)
373373         return m_ram->pointer()[offset];
374374      else
375375         return m_region_maincpu->base()[(offset & 0x1fff) + 0xa000];
376376   }
377   else   // 0xc000-0xcfff
377   else    // 0xc000-0xcfff
378378   {
379379      if (!(m_mmu & 0x01))
380380         return m_ram->pointer()[offset];
r32760r32761
385385
386386WRITE8_MEMBER(a400_state::a800xl_low_w)
387387{
388   if (offset < 0x5000)   // 0x0000-0x4fff
388   if (offset < 0x5000)    // 0x0000-0x4fff
389389      m_ram->pointer()[offset] = data;
390   else if (offset < 0x5800)   // 0x5000-0x57ff
390   else if (offset < 0x5800)   // 0x5000-0x57ff
391391   {
392392      if (m_mmu & 0x80)
393393         m_ram->pointer()[offset] = data;
394394   }
395   else if (offset < 0xa000)   // 0x5800-0x7fff
395   else if (offset < 0xa000)   // 0x5800-0x7fff
396396      m_ram->pointer()[offset] = data;
397   else if (offset < 0xc000)   // 0xa000-0xbfff
397   else if (offset < 0xc000)   // 0xa000-0xbfff
398398   {
399399      if (m_mmu & 0x02)
400400         m_ram->pointer()[offset] = data;
401401   }
402   else   // 0xc000-0xcfff
402   else    // 0xc000-0xcfff
403403   {
404404      if (!(m_mmu & 0x01))
405405         m_ram->pointer()[offset] = data;
r32760r32761
422422
423423READ8_MEMBER(a400_state::a130xe_low_r)
424424{
425   if (offset < 0x4000)   // 0x0000-0x3fff
425   if (offset < 0x4000)    // 0x0000-0x3fff
426426      return m_ram->pointer()[offset];
427   else if (offset < 0x8000)   // 0x4000-0x7fff
427   else if (offset < 0x8000)   // 0x4000-0x7fff
428428   {
429429      // NOTE: ANTIC accesses to extra RAM are not supported yet!
430430      if (!(m_mmu & 0x80) && offset >= 0x5000 && offset < 0x5800)
r32760r32761
434434      else
435435         return m_ram->pointer()[offset];
436436   }
437   else if (offset < 0xa000)   // 0x8000-0x9fff
437   else if (offset < 0xa000)   // 0x8000-0x9fff
438438      return m_ram->pointer()[offset];
439   else if (offset < 0xc000)   // 0xa000-0xbfff
439   else if (offset < 0xc000)   // 0xa000-0xbfff
440440   {
441441      if (m_mmu & 0x02)
442442         return m_ram->pointer()[offset];
443443      else
444444         return m_region_maincpu->base()[(offset & 0x1fff) + 0xa000];
445445   }
446   else   // 0xc000-0xcfff
446   else    // 0xc000-0xcfff
447447   {
448448      if (!(m_mmu & 0x01))
449449         return m_ram->pointer()[offset];
r32760r32761
454454
455455WRITE8_MEMBER(a400_state::a130xe_low_w)
456456{
457   if (offset < 0x4000)   // 0x0000-0x3fff
457   if (offset < 0x4000)    // 0x0000-0x3fff
458458      m_ram->pointer()[offset] = data;
459   else if (offset < 0x8000)   // 0x4000-0x7fff
459   else if (offset < 0x8000)   // 0x4000-0x7fff
460460   {
461461      // NOTE: ANTIC accesses to extra RAM are not supported yet!
462462      if (!(m_mmu & 0x80) && offset >= 0x5000 && offset < 0x5800)
r32760r32761
466466      else
467467         m_ram->pointer()[offset] = data;
468468   }
469   else if (offset < 0xa000)   // 0x5800-0x7fff
469   else if (offset < 0xa000)   // 0x5800-0x7fff
470470      m_ram->pointer()[offset] = data;
471   else if (offset < 0xc000)   // 0xa000-0xbfff
471   else if (offset < 0xc000)   // 0xa000-0xbfff
472472   {
473473      if (m_mmu & 0x02)
474474         m_ram->pointer()[offset] = data;
475475   }
476   else   // 0xc000-0xcfff
476   else    // 0xc000-0xcfff
477477   {
478478      if (!(m_mmu & 0x01))
479479         m_ram->pointer()[offset] = data;
r32760r32761
482482
483483READ8_MEMBER(a400_state::xegs_low_r)
484484{
485   if (offset < 0x5000)   // 0x0000-0x4fff
485   if (offset < 0x5000)    // 0x0000-0x4fff
486486      return m_ram->pointer()[offset];
487   else if (offset < 0x5800)   // 0x5000-0x57ff
487   else if (offset < 0x5800)   // 0x5000-0x57ff
488488   {
489489      if (m_mmu & 0x80)
490490         return m_ram->pointer()[offset];
491491      else
492492         return m_region_maincpu->base()[0xd000 + (offset & 0x7ff)];
493493   }
494   else if (offset < 0x8000)   // 0x5800-0x7fff
494   else if (offset < 0x8000)   // 0x5800-0x7fff
495495      return m_ram->pointer()[offset];
496   else if (offset < 0xa000)   // 0x8000-0x9fff
496   else if (offset < 0xa000)   // 0x8000-0x9fff
497497      return m_region_maincpu->base()[0x8000 + (offset & 0x1fff)];
498   else if (offset < 0xc000)   // 0xa000-0xbfff
498   else if (offset < 0xc000)   // 0xa000-0xbfff
499499      return m_region_maincpu->base()[0x8000 + (offset & 0x1fff)];
500   else   // 0xc000-0xcfff
500   else    // 0xc000-0xcfff
501501   {
502502      if (!(m_mmu & 0x01))
503503         return m_ram->pointer()[offset];
r32760r32761
508508
509509WRITE8_MEMBER(a400_state::xegs_low_w)
510510{
511   if (offset < 0x5000)   // 0x0000-0x4fff
511   if (offset < 0x5000)    // 0x0000-0x4fff
512512      m_ram->pointer()[offset] = data;
513   else if (offset < 0x5800)   // 0x5000-0x57ff
513   else if (offset < 0x5800)   // 0x5000-0x57ff
514514   {
515515      if (m_mmu & 0x80)
516516         m_ram->pointer()[offset] = data;
517517   }
518   else if (offset < 0x8000)   // 0x5800-0x7fff
518   else if (offset < 0x8000)   // 0x5800-0x7fff
519519      m_ram->pointer()[offset] = data;
520   else if (offset < 0xc000)   // 0xa000-0xbfff
520   else if (offset < 0xc000)   // 0xa000-0xbfff
521521      return;
522   else   // 0xc000-0xcfff
522   else    // 0xc000-0xcfff
523523   {
524524      if (!(m_mmu & 0x01))
525525         m_ram->pointer()[offset] = data;
r32760r32761
17051705
17061706   switch (bank)
17071707   {
1708      case 0:   // 0x0000-0x7fff
1708      case 0: // 0x0000-0x7fff
17091709         ram_top = MIN(size, 0x8000) - 1;
17101710         m_maincpu->space(AS_PROGRAM).install_readwrite_bank(0x0000, ram_top, "0000");
17111711         if (m_0000 == NULL)
17121712            m_0000.findit();
17131713         m_0000->set_base(m_ram->pointer());
17141714         break;
1715      case 1:   // 0x8000-0x9fff
1715      case 1: // 0x8000-0x9fff
17161716         ram_top = MIN(size, 0xa000) - 1;
17171717         if (ram_top > 0x8000)
17181718         {
r32760r32761
17201720            if (m_8000 == NULL)
17211721               m_8000.findit();
17221722            m_8000->set_base(m_ram->pointer() + 0x8000);
1723         }   
1723         }
17241724         break;
1725      case 2:   // 0xa000-0xbfff
1725      case 2: // 0xa000-0xbfff
17261726         ram_top = MIN(size, 0xc000) - 1;
17271727         if (ram_top > 0xa000)
17281728         {
r32760r32761
17301730            if (m_a000 == NULL)
17311731               m_a000.findit();
17321732            m_a000->set_base(m_ram->pointer() + 0xa000);
1733         }   
1733         }
17341734         break;
17351735   }
17361736}
r32760r32761
17451745   {
17461746      offset += 0x8000;
17471747      if (m_ram->size() < offset)
1748         return 0;     
1748         return 0;
17491749      else
17501750         return m_ram->pointer()[offset];
17511751   }
r32760r32761
17691769   {
17701770      offset += 0xa000;
17711771      if (m_ram->size() < offset)
1772         return 0;     
1772         return 0;
17731773      else
17741774         return m_ram->pointer()[offset];
17751775   }
r32760r32761
18081808         case A800_EXPRESS:
18091809         case A800_DIAMOND:
18101810         case A800_WILLIAMS:
1811            // use m_cart_disabled & m_last_offs to avoid continuous remapping of
1811            // use m_cart_disabled & m_last_offs to avoid continuous remapping of
18121812            // the memory space in some games (e.g. dropzone)
18131813            if (offset & 0x8 && !m_cart_disabled)
18141814               m_cart_disabled = 1;
r32760r32761
18161816            {
18171817               if (m_cart_disabled)
18181818                  m_cart_disabled = 0;
1819               
1819
18201820               if ((offset & 0x7) != m_last_offs)
18211821               {
18221822                  // we enter here only if we are writing to a different offset than last time
r32760r32761
18331833            {
18341834               if (m_cart_disabled)
18351835                  m_cart_disabled = 0;
1836               
1836
18371837               if ((offset & 0x0f) != m_last_offs)
18381838               {
18391839                  // we enter here only if we are writing to a different offset than last time
r32760r32761
18451845         case A800_SPARTADOS:
18461846            // writes with offset & 8 are also used to enable/disable the subcart, so they go through!
18471847            m_cart->write_d5xx(space, offset, data);
1848            break;         
1848            break;
18491849         case A800_OSSM091:
18501850         case A800_OSS8K:
18511851            if ((offset & 0x9) == 0x08)
r32760r32761
18681868            break;
18691869         default:
18701870            break;
1871      }   
1871      }
18721872   }
18731873}
18741874
r32760r32761
19581958            m_maincpu->space(AS_PROGRAM).install_write_handler(0x4000, 0x5fff, write8_delegate(FUNC(a800_cart_slot_device::write_80xx),(a800_cart_slot_device*)slot));
19591959            m_maincpu->space(AS_PROGRAM).unmap_write(0x6000, 0xbfff);
19601960            break;
1961      }   
1961      }
19621962   }
19631963}
19641964
r32760r32761
20142014MACHINE_START_MEMBER( a400_state, a800xl )
20152015{
20162016   m_mmu = 0xfd;
2017   m_ext_bank = 0x03;   // only used by a130xe
2017   m_ext_bank = 0x03;  // only used by a130xe
20182018   setup_cart(m_cart);
20192019
20202020   save_item(NAME(m_cart_disabled));
r32760r32761
20562056 **************************************************************/
20572057
20582058WRITE8_MEMBER(a400_state::a600xl_pia_pb_w)
2059{
2060   m_mmu = data;
2059{
2060   m_mmu = data;
20612061}
20622062
20632063WRITE8_MEMBER(a400_state::a800xl_pia_pb_w)
trunk/src/mess/drivers/pv1000.c
r32760r32761
185185
186186
187187static ADDRESS_MAP_START( pv1000, AS_PROGRAM, 8, pv1000_state )
188   //AM_RANGE(0x0000, 0x7fff)      // mapped by the cartslot
188   //AM_RANGE(0x0000, 0x7fff)      // mapped by the cartslot
189189   AM_RANGE(0xb800, 0xbbff) AM_RAM AM_SHARE("p_videoram")
190190   AM_RANGE(0xbc00, 0xbfff) AM_RAM_WRITE(gfxram_w) AM_REGION("gfxram", 0)
191191ADDRESS_MAP_END
r32760r32761
312312DEVICE_IMAGE_LOAD_MEMBER( pv1000_state, pv1000_cart )
313313{
314314   UINT32 size = m_cart->common_get_size("rom");
315   
315
316316   if (size != 0x2000 && size != 0x4000)
317317   {
318318      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
319319      return IMAGE_INIT_FAIL;
320320   }
321   
321
322322   m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
323   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
324   
323   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
324
325325   return IMAGE_INIT_PASS;
326326}
327327
r32760r32761
407407      // FIXME: this is needed for gfx decoding, but there is probably a cleaner solution!
408408      astring region_tag;
409409      memcpy(memregion("gfxrom")->base(), memregion(region_tag.cpy(m_cart->tag()).cat(GENERIC_ROM_REGION_TAG))->base(), m_cart->get_rom_size());
410   }     
410   }
411411
412412   save_item(NAME(m_io_regs));
413413   save_item(NAME(m_fd_data));
trunk/src/mess/drivers/tvc.c
r32760r32761
4747   m_palette(*this, "palette"),
4848   m_keyboard(*this, "LINE")
4949   { }
50   
50
5151   required_device<cpu_device> m_maincpu;
5252   required_device<ram_device> m_ram;
5353   required_device<tvc_sound_device> m_sound;
r32760r32761
6565
6666   void machine_start();
6767   void machine_reset();
68   
68
6969   void set_mem_page(UINT8 data);
7070   DECLARE_WRITE8_MEMBER(bank_w);
7171   DECLARE_WRITE8_MEMBER(vram_bank_w);
r32760r32761
8080   DECLARE_READ8_MEMBER(_5b_r);
8181   DECLARE_WRITE_LINE_MEMBER(int_ff_set);
8282   DECLARE_WRITE_LINE_MEMBER(centronics_ack);
83   
83
8484   // expansions
8585   DECLARE_WRITE8_MEMBER(expansion_w);
8686   DECLARE_READ8_MEMBER(expansion_r);
8787   DECLARE_READ8_MEMBER(exp_id_r);
8888   DECLARE_WRITE8_MEMBER(expint_ack_w);
89   
89
9090   DECLARE_QUICKLOAD_LOAD_MEMBER( tvc64);
91   
91
9292   MC6845_UPDATE_ROW(crtc_update_row);
93   
93
9494   UINT8       m_video_mode;
9595   UINT8       m_keyline;
9696   UINT8       m_active_slot;
trunk/src/mess/drivers/nc.c
r32760r32761
801801      m_card_size = m_card_ram->bytes();
802802   else
803803      m_card_size = 0;
804   
804
805805   /* keyboard timer */
806806   m_keyboard_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(nc_state::nc_keyboard_timer_callback),this));
807807   m_keyboard_timer->adjust(attotime::from_msec(10));
r32760r32761
11381138MACHINE_START_MEMBER(nc_state, nc200)
11391139{
11401140   m_type = NC_TYPE_200;
1141   
1141
11421142   astring region_tag;
11431143   m_card_ram = memregion(region_tag.cpy(m_card->tag()).cat(GENERIC_ROM_REGION_TAG));
11441144   if (m_card_ram)
11451145      m_card_size = m_card_ram->bytes();
11461146   else
11471147      m_card_size = 0;
1148   
1148
11491149   /* keyboard timer */
11501150   m_keyboard_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(nc_state::nc_keyboard_timer_callback),this));
11511151   m_keyboard_timer->adjust(attotime::from_msec(10));
trunk/src/mess/drivers/gmaster.c
r32760r32761
182182static ADDRESS_MAP_START( gmaster_mem, AS_PROGRAM, 8, gmaster_state )
183183   AM_RANGE(0x0000, 0x3fff) AM_ROM
184184   AM_RANGE(0x4000, 0x7fff) AM_READWRITE(gmaster_io_r, gmaster_io_w)
185   //AM_RANGE(0x8000, 0xfeff)      // mapped by the cartslot
185   //AM_RANGE(0x8000, 0xfeff)      // mapped by the cartslot
186186   AM_RANGE(0xff00, 0xffff) AM_RAM
187187ADDRESS_MAP_END
188188
trunk/src/mess/drivers/kyocera.c
r32760r32761
11671167void kc85_state::machine_start()
11681168{
11691169   address_space &program = m_maincpu->space(AS_PROGRAM);
1170   
1170
11711171   astring region_tag;
11721172   m_opt_region = memregion(region_tag.cpy(m_opt_cart->tag()).cat(GENERIC_ROM_REGION_TAG));
1173   
1173
11741174   /* initialize RTC */
11751175   m_rtc->cs_w(1);
11761176   m_rtc->oe_w(1);
r32760r32761
12101210void pc8201_state::machine_start()
12111211{
12121212   UINT8 *ram = m_ram->pointer();
1213   
1213
12141214   astring region_tag;
12151215   m_opt_region = memregion(region_tag.cpy(m_opt_cart->tag()).cat(GENERIC_ROM_REGION_TAG));
1216   
1216
12171217   /* initialize RTC */
12181218   m_rtc->cs_w(1);
12191219   m_rtc->oe_w(1);
r32760r32761
12441244void trsm100_state::machine_start()
12451245{
12461246   address_space &program = m_maincpu->space(AS_PROGRAM);
1247   
1247
12481248   astring region_tag;
12491249   m_opt_region = memregion(region_tag.cpy(m_opt_cart->tag()).cat(GENERIC_ROM_REGION_TAG));
1250   
1250
12511251   /* initialize RTC */
12521252   m_rtc->cs_w(1);
12531253   m_rtc->oe_w(1);
trunk/src/mess/drivers/cgenie.c
r32760r32761
492492DEVICE_IMAGE_LOAD_MEMBER( cgenie_state, cgenie_cart )
493493{
494494   UINT32 size = m_cart->common_get_size("rom");
495   
495
496496   if (size > 0x1000)
497497   {
498498      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
499499      return IMAGE_INIT_FAIL;
500500   }
501   
501
502502   m_cart->rom_alloc(0x1000, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
503   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
504   
503   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
504
505505   return IMAGE_INIT_PASS;
506506}
507507
trunk/src/mess/drivers/spectrum.c
r32760r32761
654654DEVICE_IMAGE_LOAD_MEMBER(spectrum_state, spectrum_cart)
655655{
656656   UINT32 size = m_cart->common_get_size("rom");
657   
657
658658   if (size != 0x4000)
659659   {
660660      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
661661      return IMAGE_INIT_FAIL;
662662   }
663   
663
664664   m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
665   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
666   
665   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
666
667667   return IMAGE_INIT_PASS;
668668}
669669
trunk/src/mess/drivers/itt3030.c
r32760r32761
324324{
325325   if (offset)
326326   {
327//      printf("Read 8078 status\n");
327//      printf("Read 8078 status\n");
328328      if (!m_keyskip)
329329      {
330         return 0x10;
330         return 0x10;
331331      }
332332   }
333333   else
334334   {
335//      printf("Read 8078 data\n");
335//      printf("Read 8078 data\n");
336336      if (!m_keyskip)
337337      {
338         m_keyskip = true;   // don't keep reporting the 'b' key, just the once to trick the boot ROM
338         m_keyskip = true;   // don't keep reporting the 'b' key, just the once to trick the boot ROM
339339         return 0x0c;
340340      }
341341   }
r32760r32761
433433}
434434
435435/*
436   7 Data Request (DRQ - inverted 1791-Signal)
437   6 Interrupt Request (INTRQ - 1791-Signal)
438   5 Head Load (HLD - inverted 1791-Signal)
439   4 Ready 3 (Drive 3 ready)
440   3 Ready 2 (Drive 2 ready)
441   2 Ready l (Drive 1 ready)
442   1 Write protect (the disk in the selected drive is write protected)
443   0 HLT (Halt signal during head load and track change)
436    7 Data Request (DRQ - inverted 1791-Signal)
437    6 Interrupt Request (INTRQ - 1791-Signal)
438    5 Head Load (HLD - inverted 1791-Signal)
439    4 Ready 3 (Drive 3 ready)
440    3 Ready 2 (Drive 2 ready)
441    2 Ready l (Drive 1 ready)
442    1 Write protect (the disk in the selected drive is write protected)
443    0 HLT (Halt signal during head load and track change)
444444*/
445445READ8_MEMBER(itt3030_state::fdc_stat_r)
446446{
447447   UINT8 res = 0;
448   floppy_image_device *floppy1 = m_con1 ? m_con1->get_device() : 0;
449   floppy_image_device *floppy2 = m_con2 ? m_con2->get_device() : 0;
450   floppy_image_device *floppy3 = m_con3 ? m_con3->get_device() : 0;
448   floppy_image_device *floppy1 = m_con1 ? m_con1->get_device() : 0;
449   floppy_image_device *floppy2 = m_con2 ? m_con2->get_device() : 0;
450   floppy_image_device *floppy3 = m_con3 ? m_con3->get_device() : 0;
451451
452452   res = m_fdc_drq ? 0x80 : 0x00;
453453   res |= m_fdc_irq ? 0x40 : 0x00;
r32760r32761
472472}
473473
474474/*
475   7 SEL1 - Select drive 1
476   6 SEL2 - Select drive 2
477   5 SEL3 - Select drive 3
478   4 MOTOR - Motor on
479   3 DOOR - Drive door lock drives 1 + 2 (not possible with all drives)
480   2 SIDESEL - Select disk side
481   1 KOMP - write comp on/off
482   0 RG J - Change separator stage to read
475    7 SEL1 - Select drive 1
476    6 SEL2 - Select drive 2
477    5 SEL3 - Select drive 3
478    4 MOTOR - Motor on
479    3 DOOR - Drive door lock drives 1 + 2 (not possible with all drives)
480    2 SIDESEL - Select disk side
481    1 KOMP - write comp on/off
482    0 RG J - Change separator stage to read
483483*/
484484WRITE8_MEMBER(itt3030_state::fdc_cmd_w)
485485{
trunk/src/mess/drivers/x07.c
r32760r32761
10381038DEVICE_IMAGE_LOAD_MEMBER( x07_state, x07_card )
10391039{
10401040   UINT32 size = m_card->common_get_size("rom");
1041   
1041
10421042   // check card type
10431043   if (image.software_entry() != NULL)
10441044   {
10451045      const char *card_type = image.get_feature("card_type");
1046     
1046
10471047      if (strcmp(card_type, "xp140"))
10481048      {
10491049         image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported card type");
r32760r32761
10521052   }
10531053
10541054   m_card->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_BIG);
1055   m_card->common_load_rom(m_card->get_rom_base(), size, "rom");         
1055   m_card->common_load_rom(m_card->get_rom_base(), size, "rom");
10561056
10571057   m_card->ram_alloc(0x1000);
10581058
trunk/src/mess/drivers/bbcbc.c
r32760r32761
4242
4343static ADDRESS_MAP_START( bbcbc_prg, AS_PROGRAM, 8, bbcbc_state )
4444   AM_RANGE(0x0000, 0x3fff) AM_ROM
45   //AM_RANGE(0x4000, 0xbfff)   // mapped by the cartslot
45   //AM_RANGE(0x4000, 0xbfff)  // mapped by the cartslot
4646   AM_RANGE(0xe000, 0xe02f) AM_RAM
4747   AM_RANGE(0xe030, 0xe030) AM_READ_PORT("LINE01")
4848   AM_RANGE(0xe031, 0xe031) AM_READ_PORT("LINE02")
trunk/src/mess/drivers/sorcerer.c
r32760r32761
163163   ADDRESS_MAP_UNMAP_HIGH
164164   AM_RANGE(0x0000, 0x07ff) AM_RAMBANK("boot")
165165   AM_RANGE(0x0800, 0xbfff) AM_RAM
166   //AM_RANGE(0xc000, 0xdfff)      // mapped by the cartslot
166   //AM_RANGE(0xc000, 0xdfff)      // mapped by the cartslot
167167   AM_RANGE(0xe000, 0xefff) AM_ROM                     /* rom pac and bios */
168168   AM_RANGE(0xf000, 0xf7ff) AM_RAM AM_REGION("maincpu", 0xf000)        /* screen ram */
169169   AM_RANGE(0xf800, 0xfbff) AM_ROM                     /* char rom */
r32760r32761
176176   AM_RANGE(0x0800, 0xbbff) AM_RAM
177177   AM_RANGE(0xbc00, 0xbcff) AM_ROM
178178   AM_RANGE(0xbe00, 0xbe03) AM_DEVREADWRITE("fdc", micropolis_device, read, write)
179   //AM_RANGE(0xc000, 0xdfff)      // mapped by the cartslot
179   //AM_RANGE(0xc000, 0xdfff)      // mapped by the cartslot
180180   AM_RANGE(0xe000, 0xefff) AM_ROM                     /* rom pac and bios */
181181   AM_RANGE(0xf000, 0xf7ff) AM_RAM AM_REGION("maincpu", 0xf000)        /* screen ram */
182182   AM_RANGE(0xf800, 0xfbff) AM_ROM                     /* char rom */
trunk/src/mess/drivers/crvision.c
r32760r32761
712712   // state saving
713713   save_item(NAME(m_keylatch));
714714   save_item(NAME(m_joylatch));
715   
715
716716   if (m_cart->exists())
717717   {
718718      m_maincpu->space(AS_PROGRAM).install_read_handler(0x4000, 0x7fff, read8_delegate(FUNC(crvision_cart_slot_device::read_rom40),(crvision_cart_slot_device*)m_cart));
r32760r32761
729729   // state saving
730730   save_item(NAME(m_keylatch));
731731   save_item(NAME(m_joylatch));
732   
732
733733   if (m_cart->exists())
734734   {
735735      m_maincpu->space(AS_PROGRAM).install_read_handler(0x4000, 0x7fff, read8_delegate(FUNC(crvision_cart_slot_device::read_rom40),(crvision_cart_slot_device*)m_cart));
trunk/src/mess/drivers/pv2000.c
r32760r32761
179179
180180   AM_RANGE(0x7000, 0x7fff) AM_RAM
181181   //AM_RANGE(0x8000, 0xbfff) ext ram?
182   //AM_RANGE(0xc000, 0xffff)      // mapped by the cartslot
182   //AM_RANGE(0xc000, 0xffff)      // mapped by the cartslot
183183ADDRESS_MAP_END
184184
185185
r32760r32761
361361DEVICE_IMAGE_LOAD_MEMBER( pv2000_state, pv2000_cart )
362362{
363363   UINT32 size = m_cart->common_get_size("rom");
364   
364
365365   if (size != 0x2000 && size != 0x4000)
366366   {
367367      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
368368      return IMAGE_INIT_FAIL;
369369   }
370   
370
371371   m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
372   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
373   
372   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
373
374374   return IMAGE_INIT_PASS;
375375}
376376
trunk/src/mess/drivers/msx.c
r32760r32761
19261926   // 1? Cartridge slot
19271927   // No keyboard?
19281928   // No cassette port?
1929   // No printer port?
1930   
1929   // No printer port?
1930
19311931   MCFG_MSX_LAYOUT_ROM("bios", 0, 0, 0, 2, "maincpu", 0x0000)
19321932   MCFG_MSX_LAYOUT_CARTRIDGE("cartslot1", 1, 0)
19331933   MCFG_MSX_LAYOUT_RAM("ram", 2, 0, 3, 1)  /* 16KB RAM */
r32760r32761
21422142   MCFG_MSX_LAYOUT_CARTRIDGE("cartslot1", 1, 0)
21432143   MCFG_MSX_LAYOUT_RAM("ram", 2, 0, 0, 4) // 64KB RAM
21442144   MCFG_MSX_LAYOUT_CARTRIDGE("cartslot2", 3, 0)
2145   
2145
21462146   MCFG_FRAGMENT_ADD( msx1_cartlist )
21472147MACHINE_CONFIG_END
21482148
r32760r32761
40094009   // AY8910/YM2149?
40104010   // FDC: None, 0 drives,
40114011   // 2 Cartridge slots?
4012   
4012
40134013   MCFG_MSX_LAYOUT_ROM("bios", 0, 0, 0, 2, "maincpu", 0x0000)
40144014   MCFG_MSX_LAYOUT_CARTRIDGE("cartslot1", 1, 0)
40154015   MCFG_MSX_LAYOUT_RAM("ram", 2, 0, 2, 2) // 32KB RAM
r32760r32761
40294029   // AY8910/YM2149?
40304030   // FDC: None, 0 drives,
40314031   // 2 Cartridge slots?
4032   
4032
40334033   MCFG_MSX_LAYOUT_ROM("bios", 0, 0, 0, 2, "maincpu", 0x0000)
40344034   MCFG_MSX_LAYOUT_CARTRIDGE("cartslot1", 1, 0)
40354035   MCFG_MSX_LAYOUT_RAM("ram", 2, 0, 0, 4) // 64KB RAM
r32760r32761
40624062
40634063/* MSX - Yamaha CX5F (with SFG05) */
40644064
4065ROM_START (cx5f)   
4065ROM_START (cx5f)
40664066   ROM_REGION (0x8000, "maincpu", 0)
40674067   ROM_LOAD ("cx5fbios.rom", 0x0000, 0x8000, CRC(dc662057) SHA1(36d77d357a5fd15af2ab266ee66e5091ba4770a3))
40684068ROM_END
r32760r32761
60366036/* MSX2 - Sanyo MPC-2500FD */
60376037
60386038ROM_START (mpc2500f)
6039    ROM_REGION (0x10000, "maincpu", 0)
6040    ROM_LOAD ("mpc2500fdbios.rom", 0x0000, 0x8000, CRC(e7d08e29) SHA1(0f851ee7a1cf79819f61cc89e9948ee72a413802))
6041    ROM_LOAD ("mpc2500fdext.rom",  0x8000, 0x4000, CRC(3d7dc718) SHA1(e1f834b28c3ee7c9f79fe6fbf2b23c8a0617892b))
6039   ROM_REGION (0x10000, "maincpu", 0)
6040   ROM_LOAD ("mpc2500fdbios.rom", 0x0000, 0x8000, CRC(e7d08e29) SHA1(0f851ee7a1cf79819f61cc89e9948ee72a413802))
6041   ROM_LOAD ("mpc2500fdext.rom",  0x8000, 0x4000, CRC(3d7dc718) SHA1(e1f834b28c3ee7c9f79fe6fbf2b23c8a0617892b))
60426042   ROM_LOAD ("mpc2500fddisk.rom", 0xc000, 0x4000, CRC(38454059) SHA1(58ac78bba29a06645ca8d6a94ef2ac68b743ad32))
60436043ROM_END
60446044
60456045static MACHINE_CONFIG_DERIVED( mpc2500f, msx2 )
6046    // YM2149
6047    // FDC: wd2793?, 1? 3.5" DSDD drive?
6048    // 2 Cartridge slots?
6046   // YM2149
6047   // FDC: wd2793?, 1? 3.5" DSDD drive?
6048   // 2 Cartridge slots?
60496049   // S-3527 MSX Eninge
60506050
6051    MCFG_MSX_LAYOUT_ROM("bios", 0, 0, 0, 2, "maincpu", 0x0000)
6052    MCFG_MSX_LAYOUT_CARTRIDGE("cartslot1", 1, 0)
6053    MCFG_MSX_LAYOUT_CARTRIDGE("cartslot2", 2, 0)
6051   MCFG_MSX_LAYOUT_ROM("bios", 0, 0, 0, 2, "maincpu", 0x0000)
6052   MCFG_MSX_LAYOUT_CARTRIDGE("cartslot1", 1, 0)
6053   MCFG_MSX_LAYOUT_CARTRIDGE("cartslot2", 2, 0)
60546054   MCFG_MSX_LAYOUT_ROM("ext", 2, 3, 0, 1, "maincpu", 0x8000)
60556055   MCFG_MSX_LAYOUT_DISK1("disk", 3, 1, 1, 1, "maincpu", 0xC000)
6056    MCFG_MSX_LAYOUT_RAM_MM("ram_mm", 3, 2, 0x10000)   /* 64KB?? Mapper RAM */
6056   MCFG_MSX_LAYOUT_RAM_MM("ram_mm", 3, 2, 0x10000)   /* 64KB?? Mapper RAM */
60576057
60586058   MCFG_FRAGMENT_ADD( msx_wd2793_force_ready )
60596059   MCFG_FRAGMENT_ADD( msx_1_35_dd_drive )
60606060   MCFG_FRAGMENT_ADD( msx2_floplist )
60616061
6062    MCFG_FRAGMENT_ADD( msx2_cartlist )
6062   MCFG_FRAGMENT_ADD( msx2_cartlist )
60636063MACHINE_CONFIG_END
60646064
60656065/* MSX2 - Sanyo Wavy MPC-25FD */
r32760r32761
72027202   ROM_LOAD ("hc95aext.rom",   0x8000, 0x4000, CRC(4a48779c) SHA1(b8e30d604d319d511cbfbc61e5d8c38fbb9c5a33))
72037203   ROM_LOAD ("hc95adisk.rom",  0xc000, 0x4000, CRC(11bca2ed) SHA1(a7a34671bddb48fa6c74182e2977f9129558ec32))
72047204   ROM_LOAD ("hc95afirm.rom", 0x10000, 0x4000, CRC(53791d91) SHA1(caeffdd654394726c8c0824b21af7ff51c0b1031))
7205   
7205
72067206   ROM_REGION (0x20000, "kanji", 0)
72077207   ROM_LOAD ("hc95akfn.rom", 0x0000, 0x20000, CRC(d23d4d2d) SHA1(db03211b7db46899df41db2b1dfbec972109a967))
72087208ROM_END
r32760r32761
72157215   // 1 Cartridge slot (slot 1 or 2?)
72167216   // S-1985 MSX Engine
72177217   // V9958 VDP
7218   
7218
72197219   MCFG_MSX_LAYOUT_ROM("bios", 0, 0, 0, 2, "maincpu", 0x0000)
72207220   MCFG_MSX_LAYOUT_ROM("ext", 0, 1, 0, 1, "maincpu", 0x8000)
72217221   MCFG_MSX_LAYOUT_ROM("firm", 0, 1, 1, 1, "maincpu", 0x10000)
r32760r32761
73877387
73887388static MACHINE_CONFIG_DERIVED( yis604, msx2 )
73897389   // YM2149 (in S-3527)
7390   // FDC: None, 0 drives 
7390   // FDC: None, 0 drives
73917391   // 2 Cartridge slots
73927392   // S-3527 MSX Engine
73937393
r32760r32761
73987398   MCFG_MSX_LAYOUT_ROM("yrm502", 3, 1, 1, 1, "maincpu", 0xc000)
73997399   MCFG_MSX_LAYOUT_RAM_MM("ram_mm", 3, 2, 0x10000) // 64KB Mapper RAM
74007400   MCFG_MSX_LAYOUT_YAMAHA_EXPANSION("expansion", 3, 3, "sfg05")
7401   
7401
74027402   MCFG_FRAGMENT_ADD( msx2_cartlist )
74037403MACHINE_CONFIG_END
74047404
r32760r32761
84338433/* Temporary placeholders, Turbo-R hardware is not supported yet */
84348434COMP(19??, fsa1gt,     0,        0, fsa1gt,     msx2jp,   driver_device, 0, "Panasonic", "FS-A1GT (MSX Turbo-R)", GAME_NOT_WORKING)
84358435COMP(19??, fsa1st,     0,        0, fsa1st,     msx2jp,   driver_device, 0, "Panasonic", "FS-A1ST (MSX Turbo-R)", GAME_NOT_WORKING)
8436
trunk/src/mess/drivers/aim65.c
r32760r32761
158158   {
159159      astring errmsg;
160160      errmsg.printf("Attempted to load file with wrong extension\nSocket '%s' only accepts files with '.%s' extension",
161                 slot_tag, slot_tag);
161                  slot_tag, slot_tag);
162162      image.seterror(IMAGE_ERROR_UNSPECIFIED, errmsg.cstr());
163163      return IMAGE_INIT_FAIL;
164164   }
trunk/src/mess/drivers/apple2.c
r32760r32761
177177The external drive port supports not only 5.25 drives but also UniDisk and
178178Apple 3.5 drives, allowing via daisy-chaining any combination of UniDisk,
179179Apple 3.5 and Apple 5.25 drives - up to three devices
180 
181----------------------------------
182 
183TK3000 keyboard matrix
184 
185Data bus D0-D7 is X0-X7
186Address bus A0-A11 is Y0-Y11
187 
180
181----------------------------------
182
183TK3000 keyboard matrix
184
185Data bus D0-D7 is X0-X7
186Address bus A0-A11 is Y0-Y11
187
188188***************************************************************************/
189189
190190
r32760r32761
267267ADDRESS_MAP_END
268268
269269/*
270
270
271271    LS259 at H12
272
272
273273    A8  = D
274274    A9  = A
275275    A10 = B
276276    A11 = C
277 
278   374/259 outputs to 65C02 c000/c010 selected by Z80 WR OR Z80 IORQ? (schematic is not super legible)
279 
277
278    374/259 outputs to 65C02 c000/c010 selected by Z80 WR OR Z80 IORQ? (schematic is not super legible)
279
280280*/
281281
282282// RAM and ROM alternate in 8K blocks: ROM at 0/4/8/c, RAM at 2/6/a/e (RAM is only 1k and further mirrors inside those locations)
r32760r32761
10281028   SLOT_INTERFACE("mcms1", A2BUS_MCMS1)  /* Mountain Computer Music System, card 1 of 2 */
10291029   SLOT_INTERFACE("mcms2", A2BUS_MCMS2)  /* Mountain Computer Music System, card 2 of 2.  must be in card 1's slot + 1! */
10301030   SLOT_INTERFACE("dx1", A2BUS_DX1)    /* Decillonix DX-1 sampler card */
1031   SLOT_INTERFACE("tm2ho", A2BUS_TIMEMASTERHO)   /* Applied Engineering TimeMaster II H.O. */
1032   SLOT_INTERFACE("mouse", A2BUS_MOUSE)   /* Apple II Mouse Card */
1033//   SLOT_INTERFACE("magicmusician", A2BUS_MAGICMUSICIAN)   /* Magic Musician Card */
1031   SLOT_INTERFACE("tm2ho", A2BUS_TIMEMASTERHO) /* Applied Engineering TimeMaster II H.O. */
1032   SLOT_INTERFACE("mouse", A2BUS_MOUSE)    /* Apple II Mouse Card */
1033//  SLOT_INTERFACE("magicmusician", A2BUS_MAGICMUSICIAN)    /* Magic Musician Card */
10341034SLOT_INTERFACE_END
10351035
10361036static SLOT_INTERFACE_START(apple2eaux_cards)
r32760r32761
11971197static MACHINE_CONFIG_DERIVED( tk3000, apple2e )
11981198   MCFG_CPU_REPLACE("maincpu", M65C02, 1021800)        /* close to actual CPU frequency of 1.020484 MHz */
11991199
1200   MCFG_CPU_ADD("subcpu", Z80, 1021800)   // schematics are illegible on where the clock comes from, but it *seems* to be the same as the 65C02 clock
1200   MCFG_CPU_ADD("subcpu", Z80, 1021800)    // schematics are illegible on where the clock comes from, but it *seems* to be the same as the 65C02 clock
12011201   MCFG_CPU_PROGRAM_MAP(tk3000_kbd_map)
12021202MACHINE_CONFIG_END
12031203
r32760r32761
13301330   MCFG_A2BUS_ONBOARD_ADD("a2bus", "sl4", A2BUS_LASER128, NULL)
13311331   MCFG_A2BUS_ONBOARD_ADD("a2bus", "sl5", A2BUS_LASER128, NULL)
13321332   MCFG_A2BUS_ONBOARD_ADD("a2bus", "sl6", A2BUS_LASER128, NULL)
1333    MCFG_A2BUS_ONBOARD_ADD("a2bus", "sl7", A2BUS_LASER128, NULL)
1333   MCFG_A2BUS_ONBOARD_ADD("a2bus", "sl7", A2BUS_LASER128, NULL)
13341334MACHINE_CONFIG_END
13351335
13361336static MACHINE_CONFIG_DERIVED( space84, apple2p )
r32760r32761
16721672   ROM_LOAD ( "341-0265-a.chr", 0x1000, 0x1000, BAD_DUMP CRC(2651014d) SHA1(b2b5d87f52693817fc747df087a4aa1ddcdb1f10)) // need to dump real laser rom
16731673
16741674   ROM_REGION(0x8000,"maincpu",0)
1675   ROM_LOAD( "laser 128ex2 rom version 6.1.bin", 0x000000, 0x008000, CRC(7f911c90) SHA1(125754c1bd777d4c510f5239b96178c6f2e3236b) )
1675   ROM_LOAD( "laser 128ex2 rom version 6.1.bin", 0x000000, 0x008000, CRC(7f911c90) SHA1(125754c1bd777d4c510f5239b96178c6f2e3236b) )
16761676
16771677   ROM_REGION( 0x800, "keyboard", ROMREGION_ERASE00 )
16781678   ROM_LOAD( "342-0132-c.e12", 0x000, 0x800, BAD_DUMP CRC(e47045f4) SHA1(12a2e718f5f4acd69b6c33a45a4a940b1440a481) ) // need to dump real laser rom
trunk/src/mess/drivers/vc4000.c
r32760r32761
378378            m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x1800, 0x1bff, read8_delegate(FUNC(vc4000_cart_slot_device::read_ram),(vc4000_cart_slot_device*)m_cart), write8_delegate(FUNC(vc4000_cart_slot_device::write_ram),(vc4000_cart_slot_device*)m_cart));
379379            break;
380380         // undumped Radofin Hobby Module
381//         case VC4000_HOBBY:
382//            m_maincpu->space(AS_PROGRAM).install_read_handler(0x0000, 0x07ff, read8_delegate(FUNC(vc4000_cart_slot_device::read_rom),(vc4000_cart_slot_device*)m_cart));
383//            m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x0800, 0x0fff, read8_delegate(FUNC(vc4000_cart_slot_device::read_ram),(vc4000_cart_slot_device*)m_cart), write8_delegate(FUNC(vc4000_cart_slot_device::write_ram),(vc4000_cart_slot_device*)m_cart));
384//            break;
381//          case VC4000_HOBBY:
382//              m_maincpu->space(AS_PROGRAM).install_read_handler(0x0000, 0x07ff, read8_delegate(FUNC(vc4000_cart_slot_device::read_rom),(vc4000_cart_slot_device*)m_cart));
383//              m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x0800, 0x0fff, read8_delegate(FUNC(vc4000_cart_slot_device::read_ram),(vc4000_cart_slot_device*)m_cart), write8_delegate(FUNC(vc4000_cart_slot_device::write_ram),(vc4000_cart_slot_device*)m_cart));
384//              break;
385385      }
386     
386
387387      m_cart->save_ram();
388388   }
389389}
r32760r32761
398398   dynamic_buffer quick_data;
399399   int read_;
400400   int result = IMAGE_INIT_FAIL;
401   
401
402402   quick_length = image.length();
403403   quick_data.resize(quick_length);
404404   read_ = image.fread( quick_data, quick_length);
r32760r32761
420420         {
421421            int quick_addr = quick_data[1] * 256 + quick_data[2];
422422            exec_addr = quick_data[3] * 256 + quick_data[4];
423           
423
424424            if (quick_length < 0x5)
425425            {
426426               image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short");
r32760r32761
436436               {
437437                  space.write_byte(0x08be, quick_data[3]);
438438                  space.write_byte(0x08bf, quick_data[4]);
439                 
439
440440                  for (i = 5; i < quick_length; i++)
441441                     space.write_byte(i - 5 + quick_addr, quick_data[i]);
442                 
442
443443                  /* display a message about the loaded quickload */
444444                  image.message(" Quickload: size=%04X : start=%04X : end=%04X : exec=%04X",quick_length-5,quick_addr,quick_addr+quick_length-5,exec_addr);
445                 
445
446446                  // Start the quickload
447447                  m_maincpu->set_state_int(S2650_PC, exec_addr);
448448                  result = IMAGE_INIT_PASS;
r32760r32761
460460            else
461461            {
462462               exec_addr = quick_data[1] * 256 + quick_data[2];
463               
463
464464               if (exec_addr >= quick_length)
465465               {
466466                  image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file");
r32760r32761
482482                     {
483483                        space.write_byte(0x08be, quick_data[1]);
484484                        space.write_byte(0x08bf, quick_data[2]);
485                       
485
486486                        // load to 08C0-15FF (standard ram + extra)
487487                        int read_ = 0x1600;
488488                        if (quick_length < 0x1600)
489489                           read_ = quick_length;
490490                        for (i = 0x8c0; i < read_; i++)
491491                           space.write_byte(i, quick_data[i]);
492                       
492
493493                        // load to 1F50-1FAF (PVI regs)
494494                        read_ = 0x1FB0;
495495                        if (quick_length < 0x1FB0)
r32760r32761
497497                        if (quick_length > 0x1FC0)
498498                           for (i = 0x1F50; i < read_; i++)
499499                              vc4000_video_w(space, i-0x1f00, quick_data[i]);
500                       
500
501501                        /* display a message about the loaded quickload */
502502                        image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr);
503                       
503
504504                        // Start the quickload
505505                        m_maincpu->set_state_int(S2650_PC, exec_addr);
506506                        result = IMAGE_INIT_PASS;
trunk/src/mess/drivers/ibmpcjr.c
r32760r32761
464464      size -= header_size;
465465      image.fseek(header_size, SEEK_SET);
466466   }
467   
467
468468   slot->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
469469   slot->common_load_rom(slot->get_rom_base(), size, "rom");
470470
trunk/src/mess/drivers/gamepock.c
r32760r32761
1212   ADDRESS_MAP_UNMAP_HIGH
1313   AM_RANGE(0x0000,0x0fff) AM_ROM
1414   AM_RANGE(0x1000,0x3fff) AM_NOP
15   //AM_RANGE(0x4000,0xbfff) AM_ROM      // mapped by the cartslot
15   //AM_RANGE(0x4000,0xbfff) AM_ROM        // mapped by the cartslot
1616   AM_RANGE(0xc000,0xc7ff) AM_MIRROR(0x0800) AM_RAM
1717   AM_RANGE(0xff80,0xffff) AM_RAM              /* 128 bytes microcontroller RAM */
1818ADDRESS_MAP_END
trunk/src/mess/drivers/apf.c
r32760r32761
246246            m_has_cart_ram = true;
247247            break;
248248      }
249     
249
250250      m_cart->save_ram();
251251   }
252252}
r32760r32761
310310   AM_RANGE(0x0000, 0x03ff) AM_MIRROR(0x1c00) AM_RAM AM_SHARE("videoram")
311311   AM_RANGE(0x2000, 0x3fff) AM_MIRROR(0x1ffc) AM_DEVREADWRITE("pia0", pia6821_device, read, write)
312312   AM_RANGE(0x4000, 0x4fff) AM_MIRROR(0x1000) AM_ROM AM_REGION("roms", 0)
313   AM_RANGE(0x6800, 0x7fff) AM_NOP   // BASIC accesses ROM here too, but this is installed at machine_start
313   AM_RANGE(0x6800, 0x7fff) AM_NOP // BASIC accesses ROM here too, but this is installed at machine_start
314314   AM_RANGE(0x8000, 0x9fff) AM_DEVREAD("cartslot", apf_cart_slot_device, read_rom)
315315   AM_RANGE(0xe000, 0xefff) AM_MIRROR(0x1000) AM_ROM AM_REGION("roms", 0)
316316ADDRESS_MAP_END
trunk/src/mess/drivers/apple3.c
r32760r32761
3333   SLOT_INTERFACE("cffa2", A2BUS_CFFA2_6502)  /* CFFA2000 Compact Flash for Apple II (www.dreher.net), 6502 firmware */
3434   SLOT_INTERFACE("applicard", A2BUS_APPLICARD)    /* PCPI Applicard */
3535   SLOT_INTERFACE("thclock", A2BUS_THUNDERCLOCK)    /* ThunderWare ThunderClock Plus - driver assumes slot 2 by default */
36   SLOT_INTERFACE("mouse", A2BUS_MOUSE)   /* Apple II Mouse Card */
36   SLOT_INTERFACE("mouse", A2BUS_MOUSE)    /* Apple II Mouse Card */
3737SLOT_INTERFACE_END
3838
3939static SLOT_INTERFACE_START( a3_floppies )
trunk/src/mess/drivers/pt68k4.c
r32760r32761
99    2014-01-03 Connect real DUARTs, FDC, and TimeKeeper.  Settings now save properly, floppies can be read.
1010    2014-01-19 ISA bus and compatible cards, PC keyboard support, speaker support
1111    2014-09-20 Add PT68K2, add save states, we have a working SK*DOS disk!
12
12
1313This has the appearance of a PC, including pc power supply, slots, etc
1414on a conventional pc-like motherboard and case.
1515
1616Some pics: http://www.wormfood.net/old_computers/
17 
18Source code and manuals for the HUMBUG BIOS and SK*DOS are at:
19http://www.users.cloud9.net/~stark/sources.html
20 
21Usage:
17
18Source code and manuals for the HUMBUG BIOS and SK*DOS are at:
19http://www.users.cloud9.net/~stark/sources.html
20
21Usage:
2222    Start up and press Enter as prompted.  Type he to see a command list, or fd to boot from the
2323    first floppy drive.
24
24
2525    The stock NVRAM configures PT68k2 for 2 DSDD 5.25" drives, and PT68k4 for 2 DSHD 5.25" drives.
26
26
2727Chips:
2828    68230 Parallel Interface/Timer @ FE0081
2929    68681 DUART/Timer (x2) @ FE0001 and FE0041
r32760r32761
4848    5: DUART1
4949    6: PC FDC IRQ
5050
51TODO: 68230 device
52     This system and SK*DOS don't like our ISA WDXT-GEN emulation so HDD installs are not currently possible.
53 
51TODO: 68230 device
52      This system and SK*DOS don't like our ISA WDXT-GEN emulation so HDD installs are not currently possible.
53
5454****************************************************************************/
5555
5656#include "emu.h"
r32760r32761
7373#define ISABUS_TAG "isa"
7474#define KBDC_TAG "pc_kbdc"
7575#define SPEAKER_TAG "speaker"
76#define WDFDC_TAG   "wdfdc"
76#define WDFDC_TAG   "wdfdc"
7777
7878class pt68k4_state : public driver_device
7979{
r32760r32761
219219   switch (drive)
220220   {
221221      case 0:
222         floppy->ss_w((data & 0x40) ? 1 : 0);
222         floppy->ss_w((data & 0x40) ? 1 : 0);
223223         break;
224224
225225      case 1:
226         floppy2->ss_w((data & 0x40) ? 1 : 0);
226         floppy2->ss_w((data & 0x40) ? 1 : 0);
227227         break;
228228
229229      default:
r32760r32761
381381
382382static MACHINE_CONFIG_START( pt68k2, pt68k4_state )
383383   /* basic machine hardware */
384   MCFG_CPU_ADD(M68K_TAG, M68000, XTAL_16MHz/2)   // 68k2 came in 8, 10, and 12 MHz versions
384   MCFG_CPU_ADD(M68K_TAG, M68000, XTAL_16MHz/2)    // 68k2 came in 8, 10, and 12 MHz versions
385385   MCFG_CPU_PROGRAM_MAP(pt68k2_mem)
386386
387387   MCFG_MC68681_ADD("duart1", XTAL_3_6864MHz)
r32760r32761
459459/* ROM definition */
460460ROM_START( pt68k2 )
461461   ROM_REGION16_BE( 0x10000, "roms", 0 )
462   ROM_LOAD16_BYTE( "hum_u20.bin",  0x000000, 0x008000, CRC(69db483a) SHA1(9dfea73e4d7deef7c66a27cca92eb7c9ff767215) )
463   ROM_LOAD16_BYTE( "hum_u27.bin",  0x000001, 0x008000, CRC(54441b06) SHA1(0e2d63b1cd01f88f37fc4859c11c252c4fea220b) )
462   ROM_LOAD16_BYTE( "hum_u20.bin",  0x000000, 0x008000, CRC(69db483a) SHA1(9dfea73e4d7deef7c66a27cca92eb7c9ff767215) )
463   ROM_LOAD16_BYTE( "hum_u27.bin",  0x000001, 0x008000, CRC(54441b06) SHA1(0e2d63b1cd01f88f37fc4859c11c252c4fea220b) )
464464
465465   ROM_REGION(0x800, TIMEKEEPER_TAG, 0)
466466   ROM_LOAD( "u21_ds1220.bin", 0x000000, 0x000800, CRC(7a6b75ce) SHA1(07663860aa6cc21aed04a568ff9c05bc75d62e4f) )
trunk/src/mess/drivers/pegasus.c
r32760r32761
9595   DECLARE_DRIVER_INIT(pegasus);
9696   TIMER_DEVICE_CALLBACK_MEMBER(pegasus_firq);
9797   void pegasus_decrypt_rom(UINT8 *ROM, bool force_decrypt);
98   
98
9999   int load_cart(device_image_interface &image, generic_slot_device *slot, const char *reg_tag);
100100   DECLARE_DEVICE_IMAGE_LOAD_MEMBER(exp00_load) { return load_cart(image, m_exp_00, "0000"); }
101101   DECLARE_DEVICE_IMAGE_LOAD_MEMBER(exp01_load) { return load_cart(image, m_exp_01, "1000"); }
r32760r32761
183183
184184static ADDRESS_MAP_START(pegasus_mem, AS_PROGRAM, 8, pegasus_state)
185185   ADDRESS_MAP_UNMAP_HIGH
186   //AM_RANGE(0x0000, 0x2fff)      // mapped by the cartslots 1-3
186   //AM_RANGE(0x0000, 0x2fff)      // mapped by the cartslots 1-3
187187   AM_RANGE(0xb000, 0xbdff) AM_RAM
188188   AM_RANGE(0xbe00, 0xbfff) AM_RAM AM_SHARE("p_videoram")
189   //AM_RANGE(0xc000, 0xdfff)      // mapped by the cartslots 4-5
189   //AM_RANGE(0xc000, 0xdfff)      // mapped by the cartslots 4-5
190190   AM_RANGE(0xe000, 0xe1ff) AM_READ(pegasus_protection_r)
191191   AM_RANGE(0xe200, 0xe3ff) AM_READWRITE(pegasus_pcg_r,pegasus_pcg_w)
192192   AM_RANGE(0xe400, 0xe403) AM_MIRROR(0x1fc) AM_DEVREADWRITE("pia_u", pia6821_device, read, write)
r32760r32761
413413{
414414   UINT32 size = slot->common_get_size(reg_tag);
415415   bool any_socket = false;
416   
416
417417   if (size > 0x1000)
418418   {
419419      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
420420      return IMAGE_INIT_FAIL;
421421   }
422   
422
423423   if (image.software_entry() != NULL && size == 0)
424424   {
425425      // we might be loading a cart compatible with all sockets!
r32760r32761
436436      }
437437   }
438438
439   slot->rom_alloc(0x1000, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);   // we alloc 0x1000 also for smaller roms!
439   slot->rom_alloc(0x1000, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE); // we alloc 0x1000 also for smaller roms!
440440   slot->common_load_rom(slot->get_rom_base(), size, any_socket ? "rom" : reg_tag);
441   
441
442442   // raw images have to be decrypted (in particular the ones from softlist)
443443   pegasus_decrypt_rom(slot->get_rom_base(), image.software_entry() != NULL);
444   
444
445445   return IMAGE_INIT_PASS;
446446}
447447
trunk/src/mess/drivers/pc6001.c
r32760r32761
922922static ADDRESS_MAP_START(pc6001_map, AS_PROGRAM, 8, pc6001_state )
923923   ADDRESS_MAP_UNMAP_HIGH
924924   AM_RANGE(0x0000, 0x3fff) AM_ROM AM_WRITENOP
925   //AM_RANGE(0x4000, 0x5fff)      // mapped by the cartslot
925   //AM_RANGE(0x4000, 0x5fff)      // mapped by the cartslot
926926   AM_RANGE(0x6000, 0x7fff) AM_ROMBANK("bank1")
927927   AM_RANGE(0x8000, 0xffff) AM_RAM AM_SHARE("ram")
928928ADDRESS_MAP_END
r32760r32761
16391639      if(0)
16401640      {
16411641         //printf("%02x\n",data);
1642         
1642
16431643         if ((data & 0x0f) == 0x05 && m_cart_rom)
16441644            m_bank1->set_base(m_cart_rom->base() + 0x2000);
16451645         if ((data & 0x0f) == 0x04)
r32760r32761
20742074void pc6001_state::machine_reset()
20752075{
20762076   m_video_ram = m_region_maincpu->base() + 0xc000;
2077   
2077
20782078   if (m_cart->exists())
20792079      m_maincpu->space(AS_PROGRAM).install_read_handler(0x4000, 0x5fff, read8_delegate(FUNC(generic_slot_device::read_rom),(generic_slot_device*)m_cart));
20802080
20812081   astring region_tag;
20822082   m_cart_rom = memregion(region_tag.cpy(m_cart->tag()).cat(GENERIC_ROM_REGION_TAG));
2083   
2083
20842084   m_port_c_8255=0;
20852085
20862086   m_cas_switch = 0;
r32760r32761
20952095MACHINE_RESET_MEMBER(pc6001_state,pc6001m2)
20962096{
20972097   m_video_ram = m_region_maincpu->base() + 0xc000 + 0x28000;
2098   
2098
20992099   astring region_tag;
21002100   m_cart_rom = memregion(region_tag.cpy(m_cart->tag()).cat(GENERIC_ROM_REGION_TAG));
21012101   // hackish way to simplify bankswitch handling
21022102   if (m_cart_rom)
21032103      memcpy(m_region_maincpu->base() + 0x48000, m_cart_rom->base(), 0x4000);
2104   
2104
21052105   m_port_c_8255=0;
21062106
21072107   m_cas_switch = 0;
r32760r32761
21342134MACHINE_RESET_MEMBER(pc6001_state,pc6001sr)
21352135{
21362136   m_video_ram = m_region_maincpu->base() + 0x70000;
2137   
2137
21382138   astring region_tag;
21392139   m_cart_rom = memregion(region_tag.cpy(m_cart->tag()).cat(GENERIC_ROM_REGION_TAG));
21402140   // should this be mirrored into the EXROM regions? hard to tell without an actual cart dump...
2141   
2141
21422142   m_port_c_8255=0;
21432143
21442144   m_cas_switch = 0;
trunk/src/mess/drivers/scv.c
r32760r32761
6464
6565
6666static ADDRESS_MAP_START( scv_mem, AS_PROGRAM, 8, scv_state )
67   AM_RANGE( 0x0000, 0x0fff ) AM_ROM   // BIOS
67   AM_RANGE( 0x0000, 0x0fff ) AM_ROM   // BIOS
6868
6969   AM_RANGE( 0x2000, 0x3403 ) AM_RAM AM_SHARE("videoram")  // VRAM + 4 registers
7070   AM_RANGE( 0x3600, 0x3600 ) AM_DEVWRITE("upd1771c", upd1771c_device, write)
7171
72   AM_RANGE( 0x8000, 0xff7f ) AM_DEVREADWRITE("cartslot", scv_cart_slot_device, read_cart, write_cart)   // cartridge
73   AM_RANGE( 0xff80, 0xffff ) AM_RAM   // upd7801 internal RAM
72   AM_RANGE( 0x8000, 0xff7f ) AM_DEVREADWRITE("cartslot", scv_cart_slot_device, read_cart, write_cart) // cartridge
73   AM_RANGE( 0xff80, 0xffff ) AM_RAM   // upd7801 internal RAM
7474ADDRESS_MAP_END
7575
7676
trunk/src/mess/drivers/socrates.c
r32760r32761
319319{
320320   astring region_tag;
321321   m_cart_reg = memregion(region_tag.cpy(m_cart->tag()).cat(GENERIC_ROM_REGION_TAG));
322   
322
323323   m_rom_bank = 0xF3; // actually set semi-randomly on real console but we need to initialize it somewhere...
324324   socrates_set_rom_bank();
325325   m_ram_bank = 0;  // the actual console sets it semi randomly on power up, and the bios cleans it up.
r32760r32761
898898{
899899   astring region_tag;
900900   m_cart_reg = memregion(region_tag.cpy(m_cart->tag()).cat(GENERIC_ROM_REGION_TAG));
901   
901
902902   UINT8 *bios = m_bios_reg->base();
903903   UINT8 *cart = m_cart_reg ? m_cart_reg->base() : m_bios_reg->base();
904904   UINT8 *ram  = m_vram_reg->base();
trunk/src/mess/drivers/gba.c
r32760r32761
18961896
18971897   if (m_bios_protected != 0)
18981898      offset = (m_bios_last_address + 8) / 4;
1899   
1899
19001900   return rom[offset & 0x3fff];
19011901}
19021902
trunk/src/mess/drivers/rx78.c
r32760r32761
259259static ADDRESS_MAP_START(rx78_mem, AS_PROGRAM, 8, rx78_state)
260260   ADDRESS_MAP_UNMAP_HIGH
261261   AM_RANGE(0x0000, 0x1fff) AM_ROM
262   //AM_RANGE(0x2000, 0x5fff)      // mapped by the cartslot
262   //AM_RANGE(0x2000, 0x5fff)      // mapped by the cartslot
263263   AM_RANGE(0x6000, 0xafff) AM_RAM //ext RAM
264264   AM_RANGE(0xb000, 0xebff) AM_RAM
265265   AM_RANGE(0xec00, 0xffff) AM_READWRITE(rx78_vram_r, rx78_vram_w)
r32760r32761
409409
410410void rx78_state::machine_reset()
411411{
412   address_space &prg = m_maincpu->space(AS_PROGRAM);   
412   address_space &prg = m_maincpu->space(AS_PROGRAM);
413413   if (m_cart->exists())
414414      prg.install_read_handler(0x2000, 0x5fff, read8_delegate(FUNC(generic_slot_device::read_rom),(generic_slot_device*)m_cart));
415415}
r32760r32761
417417DEVICE_IMAGE_LOAD_MEMBER( rx78_state, rx78_cart )
418418{
419419   UINT32 size = m_cart->common_get_size("rom");
420   
420
421421   if (size != 0x2000 && size != 0x4000)
422422   {
423423      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
424424      return IMAGE_INIT_FAIL;
425425   }
426   
426
427427   m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
428   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
429   
428   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
429
430430   return IMAGE_INIT_PASS;
431431}
432432
trunk/src/mess/drivers/laser3k.c
r32760r32761
11/***************************************************************************
2
2
33  laser3k.c
44  Driver for VTech Laser 3000 / Dick Smith Electronics "The Cat"
5
5
66  This machine is somewhat similar to a 48K Apple II if you blur your eyes
77  a lot, but it generally fits in poorly with 100% compatible machines
88  (no chance of a compatible language card or auxmem) so it gets its own driver.
9
9
1010  An "emulation cartridge" is required to run Apple II software; it's unclear
1111  what that consists of.
12
12
1313  Banking theory:
1414  - 6502 has 4 banking windows, 0000-3FFF, 4000-7FFF, 8000-BFFF, C000-FFFF
1515  - Physical address space is 0x00000-0x3FFFF.  ROM and I/O at the top, RAM
1616    up to 0x2FFFF (192k max).
1717  - Each window has a bank number register at physical 3C07C/D/E/F
18
18
1919  Technical manual at:
2020  http://mirrors.apple2.org.za/Apple%20II%20Documentation%20Project/Computers/LASER/LASER%203000/Manuals/The%20Cat%20Technical%20Reference%20Manual.pdf
21
21
2222  TODO:
2323    - Finish keyboard
2424    - RGB graphics mode
2525    - FDC C800 page appears to be inside the FDC cartridge, need a dump :(  (can hack to use IWM in the meantime)
2626    - Centronics printer port (data at 3c090, read ack at 3c1c0, read busy at 3c1c2)
2727    - cassette
28
28
2929***************************************************************************/
3030
3131#include "emu.h"
r32760r32761
248248{
249249   switch (offset)
250250   {
251      case 0x08:   // set border color to black
251      case 0x08:  // set border color to black
252252         m_border_color = 0;
253253         break;
254      case 0x09:   // set border color to red
254      case 0x09:  // set border color to red
255255         m_border_color = 1;
256256         break;
257      case 0x0a:   // set border color to green
257      case 0x0a:  // set border color to green
258258         m_border_color = 12;
259259         break;
260      case 0x0b:   // set border color to yellow
260      case 0x0b:  // set border color to yellow
261261         m_border_color = 13;
262262         break;
263      case 0x0c:   // set border color to blue
263      case 0x0c:  // set border color to blue
264264         m_border_color = 6;
265265         break;
266      case 0x0d:   // set border color to magenta
266      case 0x0d:  // set border color to magenta
267267         m_border_color = 3;
268268         break;
269      case 0x0e:   // set border color to cyan
269      case 0x0e:  // set border color to cyan
270270         m_border_color = 14;
271271         break;
272      case 0x0f:   // set border color to white
272      case 0x0f:  // set border color to white
273273         m_border_color = 15;
274274         break;
275275
276      case 0x18:   // set bg color to black
276      case 0x18:  // set bg color to black
277277         m_bg_color = 0;
278278         break;
279      case 0x19:   // set bg color to red
279      case 0x19:  // set bg color to red
280280         m_bg_color = 1;
281281         break;
282      case 0x1a:   // set bg color to green
282      case 0x1a:  // set bg color to green
283283         m_bg_color = 12;
284284         break;
285      case 0x1b:   // set bg color to yellow
285      case 0x1b:  // set bg color to yellow
286286         m_bg_color = 13;
287287         break;
288      case 0x1c:   // set bg color to blue
288      case 0x1c:  // set bg color to blue
289289         m_bg_color = 6;
290290         break;
291      case 0x1d:   // set bg color to magenta
291      case 0x1d:  // set bg color to magenta
292292         m_bg_color = 3;
293293         break;
294      case 0x1e:   // set bg color to cyan
294      case 0x1e:  // set bg color to cyan
295295         m_bg_color = 14;
296296         break;
297      case 0x1f:   // set bg color to white
297      case 0x1f:  // set bg color to white
298298         m_bg_color = 15;
299299         break;
300300
301      case 0x28:   // set fg color to normal
301      case 0x28:  // set fg color to normal
302302         m_fg_color = 15;
303303         break;
304      case 0x29:   // set fg color to red
304      case 0x29:  // set fg color to red
305305         m_fg_color = 1;
306306         break;
307      case 0x2a:   // set fg color to green
307      case 0x2a:  // set fg color to green
308308         m_fg_color = 12;
309309         break;
310      case 0x2b:   // set fg color to yellow
310      case 0x2b:  // set fg color to yellow
311311         m_fg_color = 13;
312312         break;
313      case 0x2c:   // set fg color to blue
313      case 0x2c:  // set fg color to blue
314314         m_fg_color = 6;
315315         break;
316      case 0x2d:   // set fg color to magenta
316      case 0x2d:  // set fg color to magenta
317317         m_fg_color = 3;
318318         break;
319      case 0x2e:   // set fg color to cyan
319      case 0x2e:  // set fg color to cyan
320320         m_fg_color = 14;
321321         break;
322      case 0x2f:   // set fg color to white
322      case 0x2f:  // set fg color to white
323323         m_fg_color = 15;
324324         break;
325325
r32760r32761
328328         m_speaker->level_w(m_speaker_state);
329329         break;
330330
331      case 0x4c:   // low resolution (40 column)
331      case 0x4c:  // low resolution (40 column)
332332         m_80col = false;
333333         m_maincpu->set_unscaled_clock(1021800);
334334         break;
335335
336      case 0x4d:   // RGB mode
336      case 0x4d:  // RGB mode
337337         m_gfxmode = RGB;
338338         break;
339339
340      case 0x4e:   // double hi-res
340      case 0x4e:  // double hi-res
341341         m_80col = true;
342342         m_gfxmode = DHIRES;
343343         m_maincpu->set_unscaled_clock(1021800*2);
344344         break;
345         
346      case 0x4f:   // high resolution (80 column).  Yes, the CPU clock also doubles when the pixel clock does (!)
345
346      case 0x4f:  // high resolution (80 column).  Yes, the CPU clock also doubles when the pixel clock does (!)
347347         m_80col = true;
348348         m_maincpu->set_unscaled_clock(1021800*2);
349349         break;
350350
351      case 0x50:   // graphics mode
351      case 0x50:  // graphics mode
352352         m_gfxmode = HIRES;
353353         break;
354354
355      case 0x51:   // text mode
355      case 0x51:  // text mode
356356         m_gfxmode = TEXT;
357357         break;
358358
359      case 0x52:   // no mix
359      case 0x52:  // no mix
360360         m_mix = false;
361361         break;
362362
363      case 0x53:   // mixed mode
363      case 0x53:  // mixed mode
364364         m_mix = true;
365365         break;
366366
367      case 0x54:   // set page 1
367      case 0x54:  // set page 1
368368         m_disp_page = 0;
369369         break;
370370
371      case 0x55:   // set page 2
371      case 0x55:  // set page 2
372372         m_disp_page = 1;
373373         break;
374374
375      case 0x56:   // disable emulation (?)
375      case 0x56:  // disable emulation (?)
376376         break;
377377
378378      default:
r32760r32761
385385{
386386   switch (offset)
387387   {
388      case 0x00:   // keyboard latch
388      case 0x00:  // keyboard latch
389389         return m_transchar | m_strobe;
390390
391      case 0x10:   // keyboard strobe
391      case 0x10:  // keyboard strobe
392392         {
393393            UINT8 rv = m_transchar | m_strobe;
394394            m_strobe = 0;
r32760r32761
397397
398398      case 0x7c:
399399         return m_bank0val;
400         
400
401401      case 0x7d:
402402         return m_bank1val;
403         
403
404404      case 0x7e:
405405         return m_bank2val;
406         
406
407407      case 0x7f:
408408         return m_bank3val;
409         
409
410410      default:
411411         do_io(offset);
412412         break;
r32760r32761
419419{
420420   switch (offset)
421421   {
422      case 0x10:   // clear keyboard latch
422      case 0x10:  // clear keyboard latch
423423         m_strobe = 0;
424424         break;
425425
426      case 0x68:   // SN76489 sound
426      case 0x68:  // SN76489 sound
427427         m_sn->write(space, 0, data);
428428         break;
429429
430      case 0x78:   // called "SYSTEM" in the boot ROM listing, but unsure what it does
430      case 0x78:  // called "SYSTEM" in the boot ROM listing, but unsure what it does
431431         break;
432432
433      case 0x7c:   // bank 0
433      case 0x7c:  // bank 0
434434         m_bank0val = data & 0xf;
435435         m_bank0->set_bank(m_bank0val);
436436         break;
r32760r32761
440440         m_bank1->set_bank(m_bank1val);
441441         break;
442442
443      case 0x7e:   // bank 2
443      case 0x7e:  // bank 2
444444         m_bank2val = data & 0xf;
445445         m_bank2->set_bank(m_bank2val);
446446         break;
447447
448      case 0x7f:   // bank 3
448      case 0x7f:  // bank 3
449449         m_bank3val = data & 0xf;
450450         m_bank3->set_bank(m_bank3val);
451451         break;
r32760r32761
460460{
461461   switch (offset)
462462   {
463      case 0xc2:   // h-blank status
463      case 0xc2:  // h-blank status
464464         return space.machine().first_screen()->hblank() ? 0x80 : 0x00;
465465
466      case 0xc3:   // v-blank status
466      case 0xc3:  // v-blank status
467467         return space.machine().first_screen()->vblank() ? 0x80 : 0x00;
468468
469      case 0xc5:   // CPU 1/2 MHz status?
469      case 0xc5:  // CPU 1/2 MHz status?
470470         return 0x00;
471         
471
472472      default:
473473         printf("io2_r @ unknown %x\n", offset);
474474         break;
r32760r32761
505505
506506         for (i = 0; i < xscale; i++)
507507         {
508            bitmap.pix16(ypos + y, xpos + (x * xscale) + i) = color;
508            bitmap.pix16(ypos + y, xpos + (x * xscale) + i) = color;
509509         }
510510      }
511511   }
r32760r32761
520520
521521   if (m_80col)
522522   {
523      start_address = (m_disp_page == 0) ? 0x1000 : 0x1800;
523      start_address = (m_disp_page == 0) ? 0x1000 : 0x1800;
524524   }
525525   else
526526   {
527      start_address = (m_disp_page == 0) ? 0x400 : 0x800;
527      start_address = (m_disp_page == 0) ? 0x400 : 0x800;
528528   }
529529
530530   m_flash = ((machine().time() * 4).seconds & 1) ? 1 : 0;
r32760r32761
541541            /* calculate address */
542542            address = start_address + ((((row/8) & 0x07) << 7) | (((row/8) & 0x18) * 5 + col));
543543
544            plot_text_character(bitmap, col * 7, row, 1, m_a2_videoram[address],
544            plot_text_character(bitmap, col * 7, row, 1, m_a2_videoram[address],
545545               memregion("gfx1")->base(), memregion("gfx1")->bytes());
546            plot_text_character(bitmap, (col + 40) * 7, row, 1, m_a2_videoram[address+0x400],
546            plot_text_character(bitmap, (col + 40) * 7, row, 1, m_a2_videoram[address+0x400],
547547               memregion("gfx1")->base(), memregion("gfx1")->bytes());
548548         }
549549      }
r32760r32761
553553         {
554554            /* calculate address */
555555            address = start_address + ((((row/8) & 0x07) << 7) | (((row/8) & 0x18) * 5 + col));
556            plot_text_character(bitmap, col * 14, row, 2, m_a2_videoram[address],
556            plot_text_character(bitmap, col * 14, row, 2, m_a2_videoram[address],
557557               memregion("gfx1")->base(), memregion("gfx1")->bytes());
558558         }
559559      }
r32760r32761
565565   const UINT8 *vram;
566566   int row, col, b;
567567   int offset;
568   UINT8 vram_row[42]   ;
568   UINT8 vram_row[42]  ;
569569   UINT16 v;
570570   UINT16 *p;
571571   UINT32 w;
r32760r32761
601601            |   (((UINT32) vram_row[col+2] & 0x7f) << 14);
602602
603603         artifact_map_ptr = &m_hires_artifact_map[((vram_row[col+1] & 0x80) >> 7) * 16];
604         for (b = 0; b < 7; b++)
604         for (b = 0; b < 7; b++)
605605         {
606606            v = artifact_map_ptr[((w >> (b + 7-1)) & 0x07) | (((b ^ col) & 0x01) << 3)];
607607            *(p++) = v;
r32760r32761
629629   if (endrow < beginrow)
630630      return;
631631
632      vram = m_ram->pointer() + (m_disp_page ? 0x8000 : 0x4000);
632   vram = m_ram->pointer() + (m_disp_page ? 0x8000 : 0x4000);
633633
634634   vram_row[0] = 0;
635635   vram_row[81] = 0;
r32760r32761
641641         offset = ((((row/8) & 0x07) << 7) | (((row/8) & 0x18) * 5 + col)) | ((row & 7) << 10);
642642         if (col < 40)
643643         {
644            vram_row[1+(col*2)+0] = vram[offset];
644            vram_row[1+(col*2)+0] = vram[offset];
645645            vram_row[1+(col*2)+1] = vram[offset+1];
646646         }
647647         else
648648         {
649            vram_row[1+(col*2)+0] = vram[offset+0x2000];
649            vram_row[1+(col*2)+0] = vram[offset+0x2000];
650650            vram_row[1+(col*2)+1] = vram[offset+0x2001];
651651         }
652652      }
r32760r32761
659659            |   (((UINT32) vram_row[col+1] & 0x7f) <<  7)
660660            |   (((UINT32) vram_row[col+2] & 0x7f) << 14);
661661
662         for (b = 0; b < 7; b++)
662         for (b = 0; b < 7; b++)
663663         {
664664            v = m_dhires_artifact_map[((((w >> (b + 7-1)) & 0x0F) * 0x11) >> (((2-(col*7+b))) & 0x03)) & 0x0F];
665665            *(p++) = v;
r32760r32761
673673   switch (m_gfxmode)
674674   {
675675      case TEXT:
676         text_update(screen, bitmap, cliprect, 0, 191);
676         text_update(screen, bitmap, cliprect, 0, 191);
677677         break;
678678
679679      case HIRES:
680680         if (m_mix)
681681         {
682            hgr_update(screen, bitmap, cliprect, 0, 159);
683            text_update(screen, bitmap, cliprect, 160, 191);
682            hgr_update(screen, bitmap, cliprect, 0, 159);
683            text_update(screen, bitmap, cliprect, 160, 191);
684684         }
685685         else
686686         {
687            hgr_update(screen, bitmap, cliprect, 0, 191);
687            hgr_update(screen, bitmap, cliprect, 0, 191);
688688         }
689689         break;
690690
r32760r32761
694694      case DHIRES:
695695         if (m_mix)
696696         {
697            dhgr_update(screen, bitmap, cliprect, 0, 159);
698            text_update(screen, bitmap, cliprect, 160, 191);
697            dhgr_update(screen, bitmap, cliprect, 0, 159);
698            text_update(screen, bitmap, cliprect, 160, 191);
699699         }
700700         else
701701         {
702            dhgr_update(screen, bitmap, cliprect, 0, 191);
702            dhgr_update(screen, bitmap, cliprect, 0, 191);
703703         }
704704         break;
705705   }
r32760r32761
793793      mod = (m_kbspecial->read() & 0x06) ? 0x01 : 0x00;
794794      mod |= (m_kbspecial->read() & 0x08) ? 0x02 : 0x00;
795795
796//      printf("lastchar = %02x\n", m_lastchar & 0x3f);
796//      printf("lastchar = %02x\n", m_lastchar & 0x3f);
797797
798798      m_transchar = key_remap[m_lastchar&0x3f][mod];
799799
800800      if (m_transchar != 0)
801801      {
802802         m_strobe = 0x80;
803//         printf("new char = %04x (%02x)\n", m_lastchar&0x3f, m_transchar);
803//          printf("new char = %04x (%02x)\n", m_lastchar&0x3f, m_transchar);
804804      }
805805   }
806806}
r32760r32761
865865   PORT_BIT(0x008, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Esc")      PORT_CODE(KEYCODE_ESC)      PORT_CHAR(27)
866866   PORT_BIT(0x010, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_A)          PORT_CHAR('A') PORT_CHAR('a')
867867   PORT_BIT(0x020, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_SPACE)  PORT_CHAR(' ')
868   PORT_BIT(0x040, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE)  PORT_CHAR('\'') PORT_CHAR('\"')
868   PORT_BIT(0x040, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE)  PORT_CHAR('\'') PORT_CHAR('\"')
869869   PORT_BIT(0x080, IP_ACTIVE_HIGH, IPT_UNUSED)
870870   PORT_BIT(0x100, IP_ACTIVE_HIGH, IPT_UNUSED)
871871   PORT_BIT(0x200, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Return")   PORT_CODE(KEYCODE_ENTER)    PORT_CHAR(13)
trunk/src/mess/drivers/intv.c
r32760r32761
380380   AM_RANGE(0x01f0, 0x01ff) AM_DEVREADWRITE8("ay8914", ay8914_device, read, write, 0x00ff)
381381   AM_RANGE(0x0200, 0x035f) AM_READWRITE(intv_ram16_r, intv_ram16_w)
382382   AM_RANGE(0x0400, 0x04ff) AM_DEVREAD("cartslot", intv_cart_slot_device, read_rom04)
383   AM_RANGE(0x1000, 0x1fff) AM_ROM AM_REGION("maincpu", 0x1000 << 1)   // Exec ROM, 10-bits wide
383   AM_RANGE(0x1000, 0x1fff) AM_ROM AM_REGION("maincpu", 0x1000 << 1)   // Exec ROM, 10-bits wide
384384   AM_RANGE(0x2000, 0x2fff) AM_DEVREAD("cartslot", intv_cart_slot_device, read_rom20)
385385   AM_RANGE(0x3000, 0x37ff) AM_DEVREAD("stic", stic_device, grom_read) // GROM,     8-bits wide
386   AM_RANGE(0x3800, 0x39ff) AM_READWRITE(intv_gram_r, intv_gram_w)      // GRAM,     8-bits wide
387   AM_RANGE(0x3a00, 0x3bff) AM_READWRITE(intv_gram_r, intv_gram_w)      // GRAM Alias, 8-bits wide
386   AM_RANGE(0x3800, 0x39ff) AM_READWRITE(intv_gram_r, intv_gram_w)     // GRAM,     8-bits wide
387   AM_RANGE(0x3a00, 0x3bff) AM_READWRITE(intv_gram_r, intv_gram_w)     // GRAM Alias, 8-bits wide
388388   AM_RANGE(0x4000, 0x47ff) AM_DEVREAD("cartslot", intv_cart_slot_device, read_rom40)
389389   AM_RANGE(0x4800, 0x4fff) AM_DEVREAD("cartslot", intv_cart_slot_device, read_rom48)
390390   AM_RANGE(0x5000, 0x5fff) AM_DEVREAD("cartslot", intv_cart_slot_device, read_rom50)
r32760r32761
407407   AM_RANGE(0x01f0, 0x01ff) AM_DEVREADWRITE8("ay8914", ay8914_device, read, write, 0x00ff)
408408   AM_RANGE(0x0200, 0x035f) AM_READWRITE(intv_ram16_r, intv_ram16_w)
409409   AM_RANGE(0x0400, 0x04ff) AM_DEVREAD("voice", intv_voice_device, read_rom04)
410   AM_RANGE(0x1000, 0x1fff) AM_ROM AM_REGION("maincpu", 0x1000 << 1)   // Exec ROM, 10-bits wide
410   AM_RANGE(0x1000, 0x1fff) AM_ROM AM_REGION("maincpu", 0x1000 << 1)   // Exec ROM, 10-bits wide
411411   AM_RANGE(0x2000, 0x2fff) AM_DEVREAD("voice", intv_voice_device, read_rom20)
412412   AM_RANGE(0x3000, 0x37ff) AM_DEVREAD("stic", stic_device, grom_read) // GROM,     8-bits wide
413   AM_RANGE(0x3800, 0x39ff) AM_READWRITE(intv_gram_r, intv_gram_w)      // GRAM,     8-bits wide
414   AM_RANGE(0x3a00, 0x3bff) AM_READWRITE(intv_gram_r, intv_gram_w)      // GRAM Alias, 8-bits wide
413   AM_RANGE(0x3800, 0x39ff) AM_READWRITE(intv_gram_r, intv_gram_w)     // GRAM,     8-bits wide
414   AM_RANGE(0x3a00, 0x3bff) AM_READWRITE(intv_gram_r, intv_gram_w)     // GRAM Alias, 8-bits wide
415415   AM_RANGE(0x4000, 0x47ff) AM_DEVREAD("voice", intv_voice_device, read_rom40)
416416   AM_RANGE(0x4800, 0x4fff) AM_DEVREAD("voice", intv_voice_device, read_rom48)
417417   AM_RANGE(0x5000, 0x5fff) AM_DEVREAD("voice", intv_voice_device, read_rom50)
r32760r32761
432432   AM_RANGE(0x0100, 0x01ef) AM_READWRITE(intv_ram8_r, intv_ram8_w)
433433   AM_RANGE(0x01f0, 0x01ff) AM_DEVREADWRITE8("ay8914", ay8914_device, read, write, 0x00ff)
434434   AM_RANGE(0x0200, 0x035f) AM_READWRITE(intv_ram16_r, intv_ram16_w)
435   AM_RANGE(0x0400, 0x04ff) AM_ROM AM_REGION("maincpu", 0x400 << 1)   // Exec ROM, 10-bits wide
436   AM_RANGE(0x1000, 0x1fff) AM_ROM AM_REGION("maincpu", 0x1000 << 1)   // Exec ROM, 10-bits wide
435   AM_RANGE(0x0400, 0x04ff) AM_ROM AM_REGION("maincpu", 0x400 << 1)    // Exec ROM, 10-bits wide
436   AM_RANGE(0x1000, 0x1fff) AM_ROM AM_REGION("maincpu", 0x1000 << 1)   // Exec ROM, 10-bits wide
437437   AM_RANGE(0x2000, 0x2fff) AM_DEVREAD("cartslot", intv_cart_slot_device, read_rom20)
438   AM_RANGE(0x3000, 0x37ff) AM_DEVREAD("stic", stic_device, grom_read)   // GROM,     8-bits wide
439   AM_RANGE(0x3800, 0x39ff) AM_READWRITE(intv_gram_r, intv_gram_w)   // GRAM,     8-bits wide
440   AM_RANGE(0x3a00, 0x3bff) AM_READWRITE(intv_gram_r, intv_gram_w)   // GRAM Alias, 8-bits wide
438   AM_RANGE(0x3000, 0x37ff) AM_DEVREAD("stic", stic_device, grom_read) // GROM,     8-bits wide
439   AM_RANGE(0x3800, 0x39ff) AM_READWRITE(intv_gram_r, intv_gram_w) // GRAM,     8-bits wide
440   AM_RANGE(0x3a00, 0x3bff) AM_READWRITE(intv_gram_r, intv_gram_w) // GRAM Alias, 8-bits wide
441441   AM_RANGE(0x4000, 0x47ff) AM_DEVREAD("cartslot", intv_cart_slot_device, read_rom40)
442442   AM_RANGE(0x4800, 0x4fff) AM_DEVREAD("cartslot", intv_cart_slot_device, read_rom48)
443443   AM_RANGE(0x5000, 0x5fff) AM_DEVREAD("cartslot", intv_cart_slot_device, read_rom50)
trunk/src/mess/drivers/vii.c
r32760r32761
961961void vii_state::test_centered(UINT8 *ROM)
962962{
963963   if (ROM[0x3cd808] == 0x99 &&
964       ROM[0x3cd809] == 0x99 &&
965       ROM[0x3cd80a] == 0x83 &&
966       ROM[0x3cd80b] == 0x5e &&
967       ROM[0x3cd80c] == 0x52 &&
968       ROM[0x3cd80d] == 0x6b &&
969       ROM[0x3cd80e] == 0x78 &&
970       ROM[0x3cd80f] == 0x7f)
964      ROM[0x3cd809] == 0x99 &&
965      ROM[0x3cd80a] == 0x83 &&
966      ROM[0x3cd80b] == 0x5e &&
967      ROM[0x3cd80c] == 0x52 &&
968      ROM[0x3cd80d] == 0x6b &&
969      ROM[0x3cd80e] == 0x78 &&
970      ROM[0x3cd80f] == 0x7f)
971971   {
972972      m_centered_coordinates = 0;
973973   }
r32760r32761
982982      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
983983      return IMAGE_INIT_FAIL;
984984   }
985   
985
986986   m_cart->rom_alloc(size, GENERIC_ROM16_WIDTH, ENDIANNESS_LITTLE);
987   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
988   
987   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
988
989989   test_centered(m_cart->get_rom_base());
990990
991991   return IMAGE_INIT_PASS;
r32760r32761
994994DEVICE_IMAGE_LOAD_MEMBER( vii_state, vsmile_cart )
995995{
996996   UINT32 size = m_cart->common_get_size("rom");
997   
997
998998   m_cart->rom_alloc(size, GENERIC_ROM16_WIDTH, ENDIANNESS_LITTLE);
999   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
1000   
999   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
1000
10011001   return IMAGE_INIT_PASS;
10021002}
10031003
r32760r32761
10311031      m_cart_rom = memregion(region_tag.cpy(m_cart->tag()).cat(GENERIC_ROM_REGION_TAG));
10321032      memcpy(m_p_cart, m_cart_rom->base(), 0x400000 * 2);
10331033   }
1034   else if (m_spg243_mode == SPG243_VII)   // Vii bios is banked
1034   else if (m_spg243_mode == SPG243_VII)   // Vii bios is banked
10351035      memcpy(m_p_cart, m_bios_rom->base(), 0x400000 * 2);
10361036   else
10371037      memcpy(m_p_cart, memregion("maincpu")->base(), 0x400000 * 2);
1038   
1038
10391039   m_video_regs[0x36] = 0xffff;
10401040   m_video_regs[0x37] = 0xffff;
10411041
trunk/src/mess/drivers/geniusiq.c
r32760r32761
759759DEVICE_IMAGE_LOAD_MEMBER(geniusiq_state,iq128_cart)
760760{
761761   UINT32 size = m_cart->common_get_size("rom");
762   
762
763763   // we always a 0x100000 region, for easier mapping in the memory map
764764   m_cart->rom_alloc(0x100000, GENERIC_ROM16_WIDTH, ENDIANNESS_LITTLE);
765   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
765   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
766766
767767   m_cart_state = IQ128_ROM_CART;
768768
trunk/src/mess/drivers/thomson.c
r32760r32761
10931093
10941094   MCFG_DEVICE_REMOVE( "mc6846" )
10951095
1096       MCFG_PALETTE_MODIFY( "palette" )
1096      MCFG_PALETTE_MODIFY( "palette" )
10971097   MCFG_PALETTE_INIT_OWNER(thomson_state, mo5)
10981098
10991099   MCFG_DEVICE_MODIFY(THOM_PIA_SYS)
trunk/src/mess/drivers/gameking.c
r32760r32761
103103DEVICE_IMAGE_LOAD_MEMBER( gameking_state, gameking_cart )
104104{
105105   UINT32 size = m_cart->common_get_size("rom");
106   
106
107107   if (size > 0x20000)
108108   {
109109      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
110110      return IMAGE_INIT_FAIL;
111111   }
112   
112
113113   m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
114   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
115   
114   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
115
116116   return IMAGE_INIT_PASS;
117117}
118118
trunk/src/mess/drivers/timex.c
r32760r32761
598598      int chunks_in_file = 0;
599599      dynamic_buffer header;
600600      header.resize(9);
601     
601
602602      if (size % 0x2000 != 9)
603603      {
604604         image.seterror(IMAGE_ERROR_UNSPECIFIED, "File corrupted");
r32760r32761
609609         image.seterror(IMAGE_ERROR_UNSPECIFIED, "Loading from softlist is not supported yet");
610610         return IMAGE_INIT_FAIL;
611611      }
612     
612
613613      m_dock->rom_alloc(0x10000, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
614614      DOCK = m_dock->get_rom_base();
615     
615
616616      // check header
617617      image.fread(header, 9);
618     
618
619619      for (int i = 0; i < 8; i++)
620620         if (header[i + 1] & 0x02) chunks_in_file++;
621     
621
622622      if (chunks_in_file * 0x2000 + 0x09 != size)
623623      {
624624         image.seterror(IMAGE_ERROR_UNSPECIFIED, "File corrupted");
625625         return IMAGE_INIT_FAIL;
626626      }
627     
627
628628      switch (header[0])
629629      {
630630         case 0x00:  logerror ("DOCK cart\n");
r32760r32761
643643               }
644644            }
645645            break;
646           
646
647647         default:
648648            image.seterror(IMAGE_ERROR_UNSPECIFIED, "Cart type not supported");
649649            return IMAGE_INIT_FAIL;
trunk/src/mess/drivers/studio2.c
r32760r32761
201201class studio2_state : public driver_device
202202{
203203public:
204   
204
205205   studio2_state(const machine_config &mconfig, device_type type, const char *tag)
206206      : driver_device(mconfig, type, tag),
207207         m_maincpu(*this, CDP1802_TAG),
r32760r32761
213213         m_b(*this, "B"),
214214         m_screen(*this, "screen")
215215   { }
216   
216
217217   required_device<cosmac_device> m_maincpu;
218218   required_device<beep_device> m_beeper;
219219   optional_device<cdp1861_device> m_vdc;
r32760r32761
222222   required_ioport m_a;
223223   required_ioport m_b;
224224   required_device<screen_device> m_screen;
225   
225
226226   virtual void machine_start();
227227   virtual void machine_reset();
228   
228
229229   DECLARE_READ8_MEMBER( cart_400 );
230230   DECLARE_READ8_MEMBER( cart_a00 );
231231   DECLARE_READ8_MEMBER( cart_e00 );
r32760r32761
238238   DECLARE_WRITE_LINE_MEMBER( q_w );
239239   DECLARE_INPUT_CHANGED_MEMBER( reset_w );
240240   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( studio2_cart_load );
241   
241
242242   /* keyboard state */
243243   UINT8 m_keylatch;
244244   DECLARE_DRIVER_INIT(studio2);
r32760r32761
252252         m_color0_ram(*this, "color0_ram"),
253253         m_color1_ram(*this, "color1_ram")
254254   { }
255   
255
256256   virtual UINT32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
257   
257
258258   required_shared_ptr<UINT8> m_color0_ram;
259259   required_shared_ptr<UINT8> m_color1_ram;
260   
260
261261   DECLARE_WRITE8_MEMBER( dma_w );
262262};
263263
r32760r32761
269269         m_cti(*this, CDP1864_TAG),
270270         m_color_ram(*this, "color_ram")
271271   { }
272   
272
273273   required_device<cdp1864_device> m_cti;
274   
274
275275   virtual void machine_start();
276276   virtual void machine_reset();
277   
277
278278   DECLARE_READ8_MEMBER( cart_c00 );
279279   DECLARE_WRITE8_MEMBER( dma_w );
280280   DECLARE_READ_LINE_MEMBER( rdata_r );
281281   DECLARE_READ_LINE_MEMBER( bdata_r );
282282   DECLARE_READ_LINE_MEMBER( gdata_r );
283   
283
284284   /* video state */
285285   required_shared_ptr<UINT8> m_color_ram;
286286   UINT8 m_color;
r32760r32761
511511      m_maincpu->space(AS_PROGRAM).install_read_handler(0x0400, 0x07ff, read8_delegate(FUNC(studio2_state::cart_400), this));
512512      m_maincpu->space(AS_PROGRAM).install_read_handler(0x0c00, 0x0fff, read8_delegate(FUNC(mpt02_state::cart_c00), this));
513513   }
514   
514
515515   // register for state saving
516516   save_item(NAME(m_keylatch));
517517}
r32760r32761
529529DEVICE_IMAGE_LOAD_MEMBER( studio2_state, studio2_cart_load )
530530{
531531   UINT32 size;
532   
532
533533   // always alloc 3K, even if range $400-$600 is not read by the system (RAM is present there)
534534   m_cart->rom_alloc(0xc00, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
535   
535
536536   if (image.software_entry() == NULL)
537537   {
538538      if (!strcmp(image.filetype(), "st2"))
r32760r32761
540540         UINT8 header[0x100];
541541         UINT8 catalogue[10], title[32], pages[64];
542542         UINT8 blocks;
543     
544         if (image.length() <= 0x100)
543
544         if (image.length() <= 0x100)
545545         {
546546            image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid ROM file");
547547            return IMAGE_INIT_FAIL;
r32760r32761
560560         memcpy(&catalogue, &header[16], 10);
561561         memcpy(&title, &header[32], 32);
562562         memcpy(&pages, &header[64], 64);
563         
563
564564         /* read ST2 cartridge into memory */
565565         for (int block = 0; block < (blocks - 1); block++)
566566         {
trunk/src/mess/drivers/pokemini.c
r32760r32761
5656      m_speaker(*this, "speaker"),
5757      m_i2cmem(*this, "i2cmem"),
5858      m_cart(*this, "cartslot"),
59      m_inputs(*this, "INPUTS")
59      m_inputs(*this, "INPUTS")
6060   { }
6161
6262   UINT8 m_pm_reg[0x100];
r32760r32761
15061506      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid ROM image: ROM image is too small");
15071507      return IMAGE_INIT_FAIL;
15081508   }
1509   
1509
15101510   /* Verify that the image is not too big */
15111511   if (size > 0x1fffff)
15121512   {
r32760r32761
15151515   }
15161516
15171517   m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
1518   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
1518   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
15191519
15201520   return IMAGE_INIT_PASS;
15211521}
trunk/src/mess/drivers/exelv.c
r32760r32761
361361
362362
363363/*
364   CARTRIDGE ACCESS
364    CARTRIDGE ACCESS
365365*/
366366READ8_MEMBER(exelv_state::rom_r)
367367{
r32760r32761
466466/* Machine Initialization */
467467
468468MACHINE_START_MEMBER( exelv_state, exl100)
469{   
469{
470470   /* register for state saving */
471471   save_item(NAME(m_tms7020_portb));
472472   save_item(NAME(m_tms7041_portb));
r32760r32761
481481   UINT8 *rom = memregion("user1")->base() + 0x0200;
482482   membank("bank1")->configure_entry(0, rom);
483483   membank("bank1")->set_entry(0);
484   
484
485485   /* register for state saving */
486486   save_item(NAME(m_tms7020_portb));
487487   save_item(NAME(m_tms7041_portb));
trunk/src/mess/drivers/ti74.c
r32760r32761
55  Texas Instruments TI-74 BASICALC
66  Texas Instruments TI-95 PROCALC
77  hardware family: CC-40 -> TI-74 BASICALC -> TI-95 PROCALC
8 
8
99  TI-74 PCB layout:
1010  note: TI-95 PCB is nearly the same, just with a different size LCD screen,
1111  its CPU is labeled C70011, and the system ROM is labeled HN61256PC95.
12 
12
1313          DOCK-BUS
1414        --||||||||---
1515    C  ==           |
r32760r32761
4949
5050  *               - indicates that it's on the other side of the PCB
5151
52 
52
5353  Overall, the hardware is very similar to TI CC-40. A lot has been shuffled around
5454  to cut down on complexity (and probably for protection too). To reduce power usage
5555  even more, the OS often idles while waiting for any keypress that triggers an interrupt
5656  and wakes the processor up.
57 
57
5858  The machine is powered by 4 AAA batteries. These will also save internal RAM,
5959  provided that the machine is turned off properly.
60 
61 
60
61
6262  TODO:
6363  - it runs too fast due to missing clock divider emulation in TMS70C46
6464  - external ram cartridge
r32760r32761
131131      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid file size");
132132      return IMAGE_INIT_FAIL;
133133   }
134   
134
135135   m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
136   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
137   
136   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
137
138138   return IMAGE_INIT_PASS;
139139}
140140
r32760r32761
165165   // TI-95 ref._________________...
166166   // output#  |  40   43     41   44   42     12  11  10/13/14  0    1    2
167167   // above    | _LOW _ERROR  2nd  INV  ALPHA  LC  INS  DEGRAD  HEX  OCT  I/O
168    // screen-  | _P{70} <{71}                                             RUN{3}
168   // screen-  | _P{70} <{71}                                             RUN{3}
169169   //   area   .                                                          SYS{4}
170170   output_set_lamp_value(y * 10 + x, state);
171171}
r32760r32761
175175   // char size is 5x7 + cursor
176176   if (x > 4 || y > 7)
177177      return;
178   
178
179179   if (line == 1 && pos == 15)
180180   {
181181      // the last char is used to control the 14 lcd indicators
r32760r32761
236236      if (m_key_select >> i & 1)
237237         ret |= m_key_matrix[i]->read();
238238   }
239   
239
240240   return ret;
241241}
242242
r32760r32761
250250{
251251   // d0-d1: system rom bankswitch
252252   membank("sysbank")->set_entry(data & 3);
253   
253
254254   // d2: power-on latch
255255   if (~data & 4 && m_power)
256256   {
257257      m_power = 0;
258258      m_maincpu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE); // stop running
259259   }
260   
260
261261   // d3: N/C
262262}
263263
r32760r32761
265265   ADDRESS_MAP_UNMAP_HIGH
266266   AM_RANGE(0x1000, 0x1001) AM_DEVREADWRITE("hd44780", hd44780_device, read, write)
267267   AM_RANGE(0x2000, 0x3fff) AM_RAM AM_SHARE("sysram.ic3")
268   //AM_RANGE(0x4000, 0xbfff)      // mapped by the cartslot
268   //AM_RANGE(0x4000, 0xbfff)      // mapped by the cartslot
269269   AM_RANGE(0xc000, 0xdfff) AM_ROMBANK("sysbank")
270270ADDRESS_MAP_END
271271
r32760r32761
486486void ti74_state::machine_reset()
487487{
488488   m_power = 1;
489   
489
490490   update_battery_status(m_battery_inp->read());
491491}
492492
trunk/src/mess/drivers/cc40.c
r32760r32761
5151  provided that the machine is turned off properly. If a program is running,
5252  you may have to press [BREAK] before turning the CC-40 off. If RAM contents
5353  ends up dodgy somehow, just delete the nvram files.
54 
54
5555  Officially, minimum total RAM size is 6KB. The system will still boot with less,
5656  but don't expect all software to work properly.
5757
r32760r32761
114114   UINT8 m_clock_control;
115115   UINT8 m_clock_divider;
116116   UINT8 m_key_select;
117   
117
118118   UINT8 *m_sysram[2];
119119   UINT16 m_sysram_size[2];
120120   UINT16 m_sysram_end[2];
r32760r32761
165165      return IMAGE_INIT_FAIL;
166166   }
167167
168   m_cart->rom_alloc(0x20000, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);   // allocate a larger ROM region to have 4x32K banks
169   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
168   m_cart->rom_alloc(0x20000, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);  // allocate a larger ROM region to have 4x32K banks
169   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
170170
171171   return IMAGE_INIT_PASS;
172172}
r32760r32761
265265   m_sysram_mask[0] = d3 - 1;
266266   m_sysram_end[1] = d3 + d2;
267267   m_sysram_mask[1] = d2 - 1;
268   
268
269269   // d4,d5: cartridge memory addressing
270270   // 00: 2K @ $5000-$57ff & $5800-$5fff
271271   // 01: 8K @ $5000-$6fff & $7000-$8fff
r32760r32761
524524      // init to largest possible
525525      m_sysram[chip] = auto_alloc_array(machine(), UINT8, 0x2000);
526526      save_pointer(NAME(m_sysram[chip]), 0x2000, chip);
527     
527
528528      save_item(NAME(m_sysram_size[chip]), chip);
529529      save_item(NAME(m_sysram_end[chip]), chip);
530530      save_item(NAME(m_sysram_mask[chip]), chip);
531531   }
532   
532
533533   m_nvram[chip]->set_base(m_sysram[chip], size);
534534   m_sysram_size[chip] = size;
535535}
trunk/src/mess/drivers/pc2000.c
r32760r32761
759759   UINT8 *cart = memregion(region_tag.cpy(m_cart->tag()).cat(GENERIC_ROM_REGION_TAG))->base();
760760   if (!cart)
761761      cart = memregion("bios")->base();
762   
762
763763   m_bank0->configure_entries(0, 0x20, bios, 0x4000);
764764   m_bank1->configure_entries(0, 0x20, bios, 0x4000);
765765   m_bank2->configure_entries(0, 0x20, bios, 0x4000);
r32760r32761
814814   // we always allocate a 0x40000 region, even if most carts span only 0x20000,
815815   // because the bankswitch code accesses up to 16 x 16K banks...
816816   m_cart->rom_alloc(0x40000, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
817   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
818   
817   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
818
819819   return IMAGE_INIT_PASS;
820820}
821821
trunk/src/mess/drivers/fm7.c
r32760r32761
10011001         , m_avbank8, m_avbank9, m_avbank10, m_avbank11, m_avbank12, m_avbank13, m_avbank14, m_avbank15, m_avbank16 };
10021002
10031003   avbank[bank]->set_bank(physical);
1004/*   UINT8* RAM = memregion("maincpu")->base();
1005   UINT16 size = 0xfff;
1006   char bank_name[10];
1004/*  UINT8* RAM = memregion("maincpu")->base();
1005    UINT16 size = 0xfff;
1006    char bank_name[10];
10071007
1008   if(bank == 15)
1009      size = 0xbff;
1008    if(bank == 15)
1009        size = 0xbff;
10101010
1011   sprintf(bank_name,"bank%d",bank+1);
1011    sprintf(bank_name,"bank%d",bank+1);
10121012
1013   if(physical >= 0x10 && physical <= 0x1b)
1014   {
1015      switch(physical)
1016      {
1017         case 0x10:
1018            space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram0_r),this),write8_delegate(FUNC(fm7_state::fm7_vram0_w),this));
1019            break;
1020         case 0x11:
1021            space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram1_r),this),write8_delegate(FUNC(fm7_state::fm7_vram1_w),this));
1022            break;
1023         case 0x12:
1024            space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram2_r),this),write8_delegate(FUNC(fm7_state::fm7_vram2_w),this));
1025            break;
1026         case 0x13:
1027            space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram3_r),this),write8_delegate(FUNC(fm7_state::fm7_vram3_w),this));
1028            break;
1029         case 0x14:
1030            space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram4_r),this),write8_delegate(FUNC(fm7_state::fm7_vram4_w),this));
1031            break;
1032         case 0x15:
1033            space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram5_r),this),write8_delegate(FUNC(fm7_state::fm7_vram5_w),this));
1034            break;
1035         case 0x16:
1036            space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram6_r),this),write8_delegate(FUNC(fm7_state::fm7_vram6_w),this));
1037            break;
1038         case 0x17:
1039            space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram7_r),this),write8_delegate(FUNC(fm7_state::fm7_vram7_w),this));
1040            break;
1041         case 0x18:
1042            space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram8_r),this),write8_delegate(FUNC(fm7_state::fm7_vram8_w),this));
1043            break;
1044         case 0x19:
1045            space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram9_r),this),write8_delegate(FUNC(fm7_state::fm7_vram9_w),this));
1046            break;
1047         case 0x1a:
1048            space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vramA_r),this),write8_delegate(FUNC(fm7_state::fm7_vramA_w),this));
1049            break;
1050         case 0x1b:
1051            space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vramB_r),this),write8_delegate(FUNC(fm7_state::fm7_vramB_w),this));
1052            break;
1053      }
1013    if(physical >= 0x10 && physical <= 0x1b)
1014    {
1015        switch(physical)
1016        {
1017            case 0x10:
1018                space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram0_r),this),write8_delegate(FUNC(fm7_state::fm7_vram0_w),this));
1019                break;
1020            case 0x11:
1021                space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram1_r),this),write8_delegate(FUNC(fm7_state::fm7_vram1_w),this));
1022                break;
1023            case 0x12:
1024                space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram2_r),this),write8_delegate(FUNC(fm7_state::fm7_vram2_w),this));
1025                break;
1026            case 0x13:
1027                space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram3_r),this),write8_delegate(FUNC(fm7_state::fm7_vram3_w),this));
1028                break;
1029            case 0x14:
1030                space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram4_r),this),write8_delegate(FUNC(fm7_state::fm7_vram4_w),this));
1031                break;
1032            case 0x15:
1033                space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram5_r),this),write8_delegate(FUNC(fm7_state::fm7_vram5_w),this));
1034                break;
1035            case 0x16:
1036                space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram6_r),this),write8_delegate(FUNC(fm7_state::fm7_vram6_w),this));
1037                break;
1038            case 0x17:
1039                space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram7_r),this),write8_delegate(FUNC(fm7_state::fm7_vram7_w),this));
1040                break;
1041            case 0x18:
1042                space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram8_r),this),write8_delegate(FUNC(fm7_state::fm7_vram8_w),this));
1043                break;
1044            case 0x19:
1045                space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vram9_r),this),write8_delegate(FUNC(fm7_state::fm7_vram9_w),this));
1046                break;
1047            case 0x1a:
1048                space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vramA_r),this),write8_delegate(FUNC(fm7_state::fm7_vramA_w),this));
1049                break;
1050            case 0x1b:
1051                space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_vramB_r),this),write8_delegate(FUNC(fm7_state::fm7_vramB_w),this));
1052                break;
1053        }
10541054//      membank(bank+1)->set_base(RAM+(physical<<12)-0x10000);
1055      return;
1056   }
1057   if(physical == 0x1c)
1058   {
1059      space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_console_ram_banked_r),this),write8_delegate(FUNC(fm7_state::fm7_console_ram_banked_w),this));
1060      return;
1061   }
1062   if(physical == 0x1d)
1063   {
1064      space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_sub_ram_ports_banked_r),this),write8_delegate(FUNC(fm7_state::fm7_sub_ram_ports_banked_w),this));
1065      return;
1066   }
1067   if(physical == 0x35)
1068   {
1069      if(m_init_rom_en && (m_type == SYS_FM11 || m_type == SYS_FM16))
1070      {
1071         RAM = memregion("init")->base();
1072         space.install_read_bank(bank*0x1000,(bank*0x1000)+size,bank_name);
1073         space.nop_write(bank*0x1000,(bank*0x1000)+size);
1074         membank(bank_name)->set_base(RAM+(physical<<12)-0x35000);
1075         return;
1076      }
1077   }
1078   if(physical == 0x36 || physical == 0x37)
1079   {
1080      if(m_init_rom_en && (m_type != SYS_FM11 && m_type != SYS_FM16))
1081      {
1082         RAM = memregion("init")->base();
1083         space.install_read_bank(bank*0x1000,(bank*0x1000)+size,bank_name);
1084         space.nop_write(bank*0x1000,(bank*0x1000)+size);
1085         membank(bank_name)->set_base(RAM+(physical<<12)-0x36000);
1086         return;
1087      }
1088   }
1089   if(physical > 0x37 && physical <= 0x3f)
1090   {
1091      if(m_basic_rom_en && (m_type != SYS_FM11 && m_type != SYS_FM16))
1092      {
1093         RAM = memregion("fbasic")->base();
1094         space.install_read_bank(bank*0x1000,(bank*0x1000)+size,bank_name);
1095         space.nop_write(bank*0x1000,(bank*0x1000)+size);
1096         membank(bank_name)->set_base(RAM+(physical<<12)-0x38000);
1097         return;
1098      }
1099   }
1100   space.install_readwrite_bank(bank*0x1000,(bank*0x1000)+size,bank_name);
1101   membank(bank_name)->set_base(RAM+(physical<<12));
1102   */
1055        return;
1056    }
1057    if(physical == 0x1c)
1058    {
1059        space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_console_ram_banked_r),this),write8_delegate(FUNC(fm7_state::fm7_console_ram_banked_w),this));
1060        return;
1061    }
1062    if(physical == 0x1d)
1063    {
1064        space.install_readwrite_handler(bank*0x1000,(bank*0x1000)+size,read8_delegate(FUNC(fm7_state::fm7_sub_ram_ports_banked_r),this),write8_delegate(FUNC(fm7_state::fm7_sub_ram_ports_banked_w),this));
1065        return;
1066    }
1067    if(physical == 0x35)
1068    {
1069        if(m_init_rom_en && (m_type == SYS_FM11 || m_type == SYS_FM16))
1070        {
1071            RAM = memregion("init")->base();
1072            space.install_read_bank(bank*0x1000,(bank*0x1000)+size,bank_name);
1073            space.nop_write(bank*0x1000,(bank*0x1000)+size);
1074            membank(bank_name)->set_base(RAM+(physical<<12)-0x35000);
1075            return;
1076        }
1077    }
1078    if(physical == 0x36 || physical == 0x37)
1079    {
1080        if(m_init_rom_en && (m_type != SYS_FM11 && m_type != SYS_FM16))
1081        {
1082            RAM = memregion("init")->base();
1083            space.install_read_bank(bank*0x1000,(bank*0x1000)+size,bank_name);
1084            space.nop_write(bank*0x1000,(bank*0x1000)+size);
1085            membank(bank_name)->set_base(RAM+(physical<<12)-0x36000);
1086            return;
1087        }
1088    }
1089    if(physical > 0x37 && physical <= 0x3f)
1090    {
1091        if(m_basic_rom_en && (m_type != SYS_FM11 && m_type != SYS_FM16))
1092        {
1093            RAM = memregion("fbasic")->base();
1094            space.install_read_bank(bank*0x1000,(bank*0x1000)+size,bank_name);
1095            space.nop_write(bank*0x1000,(bank*0x1000)+size);
1096            membank(bank_name)->set_base(RAM+(physical<<12)-0x38000);
1097            return;
1098        }
1099    }
1100    space.install_readwrite_bank(bank*0x1000,(bank*0x1000)+size,bank_name);
1101    membank(bank_name)->set_base(RAM+(physical<<12));
1102    */
11031103}
11041104
11051105void fm7_state::fm7_mmr_refresh(address_space& space)
trunk/src/mess/mess.mak
r32760r32761
963963   $(MESS_DRIVERS)/superslave.o\
964964
965965$(MESSOBJ)/alesis.a:            \
966   $(MESS_DRIVERS)/alesis.o $(MESS_AUDIO)/alesis.o   $(MESS_VIDEO)/alesis.o \
966   $(MESS_DRIVERS)/alesis.o $(MESS_AUDIO)/alesis.o $(MESS_VIDEO)/alesis.o \
967967
968968$(MESSOBJ)/altos.a:             \
969969   $(MESS_DRIVERS)/altos5.o    \
r32760r32761
989989$(MESSOBJ)/apple.a:             \
990990   $(MESS_DRIVERS)/apple1.o $(MESS_MACHINE)/apple1.o $(MESS_VIDEO)/apple1.o \
991991   $(MESS_DRIVERS)/apple2.o $(MESS_MACHINE)/apple2.o $(MESS_VIDEO)/apple2.o \
992        $(MESS_DRIVERS)/apple2gs.o $(MESS_MACHINE)/apple2gs.o $(MESS_VIDEO)/apple2gs.o \
992      $(MESS_DRIVERS)/apple2gs.o $(MESS_MACHINE)/apple2gs.o $(MESS_VIDEO)/apple2gs.o \
993993   $(MESS_DRIVERS)/apple3.o $(MESS_MACHINE)/apple3.o $(MESS_VIDEO)/apple3.o \
994994   $(MESS_DRIVERS)/lisa.o $(MESS_MACHINE)/lisa.o \
995995   $(MESS_DRIVERS)/mac.o $(MESS_AUDIO)/mac.o $(MESS_MACHINE)/egret.o $(MESS_MACHINE)/mac.o $(MESS_MACHINE)/macadb.o $(MESS_MACHINE)/macrtc.o $(MESS_MACHINE)/mackbd.o $(MESS_MACHINE)/swim.o $(MESS_VIDEO)/mac.o \
r32760r32761
10291029   $(MESS_DRIVERS)/wswan.o $(MESS_AUDIO)/wswan_snd.o $(MESS_MACHINE)/wswan.o $(MESS_VIDEO)/wswan.o \
10301030
10311031$(MESSOBJ)/be.a:                \
1032   $(MESS_DRIVERS)/bebox.o   $(MESS_MACHINE)/bebox.o \
1032   $(MESS_DRIVERS)/bebox.o $(MESS_MACHINE)/bebox.o \
10331033
10341034$(MESSOBJ)/bnpo.a:              \
10351035   $(MESS_DRIVERS)/b2m.o $(MESS_MACHINE)/b2m.o $(MESS_VIDEO)/b2m.o \
r32760r32761
13591359   $(MESS_DRIVERS)/irisha.o    \
13601360
13611361$(MESSOBJ)/microkey.a:          \
1362   $(MESS_DRIVERS)/primo.o $(MESS_MACHINE)/primo.o   $(MESS_VIDEO)/primo.o \
1362   $(MESS_DRIVERS)/primo.o $(MESS_MACHINE)/primo.o $(MESS_VIDEO)/primo.o \
13631363
13641364$(MESSOBJ)/mit.a:               \
13651365   $(MESS_DRIVERS)/tx0.o $(MESS_VIDEO)/crt.o $(MESS_VIDEO)/tx0.o \
r32760r32761
14691469$(MESSOBJ)/pc.a:                \
14701470   $(MESS_DRIVERS)/asst128.o   \
14711471   $(MESS_DRIVERS)/europc.o    \
1472   $(MESS_DRIVERS)/genpc.o   $(MESS_MACHINE)/genpc.o \
1472   $(MESS_DRIVERS)/genpc.o $(MESS_MACHINE)/genpc.o \
14731473   $(MESS_DRIVERS)/ibmpc.o     \
14741474   $(MESS_DRIVERS)/ibmpcjr.o   \
14751475   $(MESS_DRIVERS)/pc.o        \
r32760r32761
14801480
14811481$(MESSOBJ)/pel.a:               \
14821482   $(MESS_DRIVERS)/galeb.o $(MESS_VIDEO)/galeb.o \
1483        $(MESS_DRIVERS)/orao.o $(MESS_MACHINE)/orao.o $(MESS_VIDEO)/orao.o \
1483      $(MESS_DRIVERS)/orao.o $(MESS_MACHINE)/orao.o $(MESS_VIDEO)/orao.o \
14841484
14851485$(MESSOBJ)/philips.a:           \
14861486   $(MESS_DRIVERS)/p2000t.o $(MESS_MACHINE)/p2000t.o $(MESS_VIDEO)/p2000m.o \
r32760r32761
16861686   $(MESS_DRIVERS)/tec1.o      \
16871687
16881688$(MESSOBJ)/tesla.a:             \
1689   $(MESS_DRIVERS)/ondra.o $(MESS_MACHINE)/ondra.o   $(MESS_VIDEO)/ondra.o \
1689   $(MESS_DRIVERS)/ondra.o $(MESS_MACHINE)/ondra.o $(MESS_VIDEO)/ondra.o \
16901690   $(MESS_DRIVERS)/pmd85.o $(MESS_MACHINE)/pmd85.o $(MESS_VIDEO)/pmd85.o \
16911691   $(MESS_DRIVERS)/pmi80.o     \
16921692   $(MESS_DRIVERS)/sapi1.o     \
r32760r32761
16991699   $(MESS_DRIVERS)/thomson.o $(MESS_MACHINE)/thomson.o $(MESS_MACHINE)/thomflop.o $(MESS_VIDEO)/thomson.o \
17001700
17011701$(MESSOBJ)/ti.a:                \
1702   $(MESS_DRIVERS)/avigo.o   $(MESS_VIDEO)/avigo.o \
1702   $(MESS_DRIVERS)/avigo.o $(MESS_VIDEO)/avigo.o \
17031703   $(MESS_DRIVERS)/cc40.o      \
17041704   $(MESS_DRIVERS)/evmbug.o    \
17051705   $(MESS_DRIVERS)/exelv.o     \
trunk/src/mess/tools/imgtool/modules/amiga.c
r32760r32761
17761776   t_v = amiga_crack_time(&root.v);
17771777   t_r = amiga_crack_time(&root.r);
17781778
1779   strftime(c, sizeof(c), "%d-%b-%y %H:%M:%S",   localtime(&t_c));
1780   strftime(v, sizeof(v), "%d-%b-%y %H:%M:%S",   localtime(&t_v));
1781   strftime(r, sizeof(r), "%d-%b-%y %H:%M:%S",   localtime(&t_r));
1779   strftime(c, sizeof(c), "%d-%b-%y %H:%M:%S", localtime(&t_c));
1780   strftime(v, sizeof(v), "%d-%b-%y %H:%M:%S", localtime(&t_v));
1781   strftime(r, sizeof(r), "%d-%b-%y %H:%M:%S", localtime(&t_r));
17821782
17831783   strcpy(info, "Volume     name: ");
17841784   strncat(info, (char *)root.diskname, root.name_len);
trunk/src/mess/audio/wswan_snd.h
r32760r32761
2525   vol_right(0),
2626   on(0),
2727   signal(0) { }
28   
28
2929   UINT16  freq;           /* frequency */
3030   UINT32  period;         /* period */
3131   UINT32  pos;            /* position */
r32760r32761
4444public:
4545   wswan_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
4646   ~wswan_sound_device() { }
47   
47
4848protected:
4949   // device-level overrides
5050   virtual void device_start();
5151   virtual void device_reset();
52   
52
5353   // sound stream update overrides
5454   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
55   
55
5656public:
5757   DECLARE_WRITE8_MEMBER( port_w );
58   
58
5959private:
6060   void wswan_ch_set_freq( CHAN *ch, UINT16 freq );
61   
61
6262private:
6363   sound_stream *m_channel;
6464   CHAN m_audio1;     /* Audio channel 1 */
trunk/src/mess/audio/vc4000snd.h
r32760r32761
2121public:
2222   vc4000_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
2323   ~vc4000_sound_device() { }
24   
24
2525protected:
2626   // device-level overrides
2727   virtual void device_start();
28   
28
2929   // sound stream update overrides
3030   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
31   
31
3232public:
3333   void soundport_w(int mode, int data);
34   
34
3535private:
3636   sound_stream *m_channel;
3737   UINT8 m_reg[1];
trunk/src/mess/machine/lynx.c
r32760r32761
10191019      case RCART:
10201020         if (m_cart->exists())
10211021            value = m_cart->read_rom(space, (m_suzy.high * m_granularity) + m_suzy.low);
1022         else
1022         else
10231023            value = 0;
10241024         m_suzy.low = (m_suzy.low + 1) & (m_granularity - 1);
10251025         break;
r32760r32761
20782078         // 22 chars manufacturer
20792079         UINT8 header[0x40];
20802080         image.fread(header, 0x40);
2081         
2081
20822082         // Check the image
20832083         if (lynx_verify_cart((char*)header, LYNX_CART) == IMAGE_VERIFY_FAIL)
20842084            return IMAGE_INIT_FAIL;
2085         
2085
20862086         /* 2008-10 FP: According to Handy source these should be page_size_bank0. Are we using
20872087          it correctly in MESS? Moreover, the next two values should be page_size_bank1. We should
20882088          implement this as well */
20892089         gran = header[4] | (header[5] << 8);
2090         
2090
20912091         logerror ("%s %dkb cartridge with %dbyte granularity from %s\n", header + 10, size / 1024, gran, header + 42);
20922092         size -= 0x40;
20932093      }
2094   }   
2094   }
20952095
20962096   m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
2097   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
2097   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
20982098
20992099   // set-up granularity
21002100   if (image.software_entry() == NULL)
21012101   {
21022102      const char *filetype = image.filetype();
2103      if (!core_stricmp(filetype, "lnx"))      // from header
2103      if (!core_stricmp(filetype, "lnx"))     // from header
21042104         m_granularity = gran;
21052105      else if (!core_stricmp(filetype, "lyx"))
21062106      {
r32760r32761
21222122      else
21232123         m_granularity = 0x400; // Homebrew roms not using all 256 banks (T-Tris) (none currently in softlist)
21242124   }
2125   
2125
21262126   // set-up rotation from softlist
21272127   if (image.software_entry() != NULL)
21282128   {
r32760r32761
21402140
21412141   return IMAGE_INIT_PASS;
21422142}
2143
trunk/src/mess/machine/gamepock.c
r32760r32761
139139
140140   if (m_cart->exists())
141141      m_maincpu->space(AS_PROGRAM).install_read_handler(0x4000,0xbfff, read8_delegate(FUNC(generic_slot_device::read_rom),(generic_slot_device*)m_cart));
142   
142
143143}
144144
145145UINT32 gamepock_state::screen_update_gamepock(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
trunk/src/mess/machine/concept.c
r32760r32761
154154
155155WRITE_LINE_MEMBER(concept_state::via_out_cb2)
156156{
157//   LOG(("via_out_cb2: Sound control written: data=0x%2.2x\n", state));
157//  LOG(("via_out_cb2: Sound control written: data=0x%2.2x\n", state));
158158   m_speaker->level_w(state);
159159}
160160
r32760r32761
210210
211211         if (card)
212212         {
213            return card->read_cnxx(space, offset & 0xff);
213            return card->read_cnxx(space, offset & 0xff);
214214         }
215215      }
216216      break;
r32760r32761
245245
246246      case 3:
247247         /* NVIA versatile system interface */
248//   LOG(("concept_io_r: VIA read at address 0x03%4.4x\n", offset << 1));
248//  LOG(("concept_io_r: VIA read at address 0x03%4.4x\n", offset << 1));
249249         {
250250            via6522_device *via_0 = machine().device<via6522_device>("via6522_0");
251251            return via_0->read(space, offset & 0xf);
r32760r32761
301301
302302               if (card)
303303               {
304                  return card->write_c0nx(space, offset & 0x0f, data);
304                  return card->write_c0nx(space, offset & 0x0f, data);
305305               }
306306            }
307307            break;
trunk/src/mess/machine/intv.c
r32760r32761
351351   save_item(NAME(m_ram16));
352352   save_item(NAME(m_sr1_int_pending));
353353   save_item(NAME(m_ram8));
354   
354
355355   // intvkbd
356356   if (m_is_keybd)
357357   {
r32760r32761
388388         case INTV_VOICE:
389389            m_cart->late_subslot_setup();
390390            m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x0080, 0x0081, read16_delegate(FUNC(intv_cart_slot_device::read_speech),(intv_cart_slot_device*)m_cart), write16_delegate(FUNC(intv_cart_slot_device::write_speech),(intv_cart_slot_device*)m_cart));
391           
391
392392            // passthru for RAM-equipped carts
393393            m_maincpu->space(AS_PROGRAM).install_write_handler(0x8800, 0x8fff, write16_delegate(FUNC(intv_cart_slot_device::write_88),(intv_cart_slot_device*)m_cart));
394394            m_maincpu->space(AS_PROGRAM).install_write_handler(0xd000, 0xd7ff, write16_delegate(FUNC(intv_cart_slot_device::write_d0),(intv_cart_slot_device*)m_cart));
r32760r32761
402402            m_maincpu->space(AS_PROGRAM).install_write_handler(0x7000, 0x7fff, write16_delegate(FUNC(intv_cart_slot_device::write_rom70),(intv_cart_slot_device*)m_cart));
403403            m_maincpu->space(AS_PROGRAM).install_write_handler(0xe000, 0xefff, write16_delegate(FUNC(intv_cart_slot_device::write_rome0),(intv_cart_slot_device*)m_cart));
404404            m_maincpu->space(AS_PROGRAM).install_write_handler(0xf000, 0xffff, write16_delegate(FUNC(intv_cart_slot_device::write_romf0),(intv_cart_slot_device*)m_cart));
405           
405
406406            // passthru for Intellivoice expansion
407407            m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x0080, 0x0081, read16_delegate(FUNC(intv_cart_slot_device::read_speech),(intv_cart_slot_device*)m_cart), write16_delegate(FUNC(intv_cart_slot_device::write_speech),(intv_cart_slot_device*)m_cart));
408           
408
409409            // passthru for RAM-equipped carts
410410            m_maincpu->space(AS_PROGRAM).install_write_handler(0x8800, 0x8fff, write16_delegate(FUNC(intv_cart_slot_device::write_88),(intv_cart_slot_device*)m_cart));
411411            m_maincpu->space(AS_PROGRAM).install_write_handler(0xd000, 0xd7ff, write16_delegate(FUNC(intv_cart_slot_device::write_d0),(intv_cart_slot_device*)m_cart));
trunk/src/mess/machine/bbc.c
r32760r32761
19411941int bbc_state::bbc_load_cart(device_image_interface &image, generic_slot_device *slot)
19421942{
19431943   UINT32 size = slot->common_get_size("rom");
1944   
1944
19451945   if (size != 0x2000 && size != 0x4000)
19461946   {
19471947      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
19481948      return IMAGE_INIT_FAIL;
19491949   }
1950   
1950
19511951   slot->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
19521952   slot->common_load_rom(slot->get_rom_base(), size, "rom");
1953   
1953
19541954   return IMAGE_INIT_PASS;
19551955}
19561956
r32760r32761
19691969         image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
19701970         return IMAGE_INIT_FAIL;
19711971      }
1972     
1972
19731973      slot->rom_alloc(filesize, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
19741974      image.fread(slot->get_rom_base(), filesize);
19751975      return IMAGE_INIT_PASS;
r32760r32761
19781978   {
19791979      UINT32 size_lo = image.get_software_region_length("lorom");
19801980      UINT32 size_hi = image.get_software_region_length("uprom");
1981     
1981
19821982      if (size_lo + size_hi != 0x8000)
19831983      {
19841984         image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
19851985         return IMAGE_INIT_FAIL;
19861986      }
1987     
1987
19881988      slot->rom_alloc(size_lo + size_hi, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
19891989      memcpy(slot->get_rom_base() + 0,       image.get_software_region("uprom"), size_hi);
19901990      memcpy(slot->get_rom_base() + size_hi, image.get_software_region("lorom"), size_lo);
19911991   }
1992   
1992
19931993   return IMAGE_INIT_PASS;
19941994}
19951995
r32760r32761
20522052      eprom[3] = tmp_reg->base() + shift;
20532053   else
20542054      eprom[3] = m_region_opt->base() + 0xc000 + shift;
2055   
2055
20562056   membank->configure_entries(0, 1,  eprom[0], size);
20572057   membank->configure_entries(1, 1,  eprom[1], size);
20582058   membank->configure_entries(2, 1,  eprom[2], size);
r32760r32761
20782078      eprom[1] = tmp_reg->base() + shift;
20792079   else
20802080      eprom[1] = m_region_opt->base() + 0x8000 + shift;
2081   
2081
20822082   membank->configure_entries(0, 1,  eprom[0], size);
20832083   membank->configure_entries(1, 1,  eprom[0] + 0x4000, size);
20842084   membank->configure_entries(2, 1,  eprom[1], size);
20852085   membank->configure_entries(3, 1,  eprom[1] + 0x4000, size);
2086   
2086
20872087   if (banks > 4)
20882088   {
20892089      for (int i = 0; i < banks - 4; i++)
r32760r32761
21272127   m_previous_wd177x_int_state=1;
21282128   bbc_setup_banks(m_bank4, 16, 0, 0x4000);
21292129   if (m_region_dfs)
2130      m_bank4->configure_entries(16, 8, m_region_dfs->base(), 0x4000);   // additional bank for paged ram
2130      m_bank4->configure_entries(16, 8, m_region_dfs->base(), 0x4000);    // additional bank for paged ram
21312131}
21322132
21332133MACHINE_RESET_MEMBER(bbc_state, bbcb)
r32760r32761
21552155   m_maincpu->space(AS_PROGRAM).set_direct_update_handler(direct_update_delegate(FUNC(bbc_state::bbcbp_direct_handler), this));
21562156
21572157   bbc_setup_banks(m_bank4, 16, 0, 0x3000);
2158   m_bank4->configure_entries(16, 1, m_region_maincpu->base() + 0x8000, 0x3000);   // additional bank for paged ram
2158   m_bank4->configure_entries(16, 1, m_region_maincpu->base() + 0x8000, 0x3000);   // additional bank for paged ram
21592159   bbc_setup_banks(m_bank6, 16, 0x3000, 0x1000);
21602160}
21612161
r32760r32761
21802180   m_maincpu->space(AS_PROGRAM).set_direct_update_handler(direct_update_delegate(FUNC(bbc_state::bbcm_direct_handler), this));
21812181
21822182   bbcm_setup_banks(m_bank4, 16, 0, 0x1000);
2183   m_bank4->configure_entries(16, 1, m_region_maincpu->base() + 0x8000, 0x1000);   // additional bank for paged ram
2183   m_bank4->configure_entries(16, 1, m_region_maincpu->base() + 0x8000, 0x1000);   // additional bank for paged ram
21842184   bbcm_setup_banks(m_bank5, 16, 0x1000, 0x3000);
21852185
21862186   /* Set ROM/IO bank to point to rom */
trunk/src/mess/machine/apple2.c
r32760r32761
366366            }
367367         }
368368      }
369     
369
370370      if ((m_machinetype == APPLE_IICPLUS) && (slot == 6))
371371      {
372372         offset &= 0xf;
r32760r32761
377377      {
378378         offset &= 0xf;
379379         UINT8 retval = m_exp_regs[offset];
380                     
380
381381         if (offset == 3)
382382         {
383383            retval = m_exp_ram[m_exp_liveptr&m_exp_addrmask];
r32760r32761
22872287
22882288MACHINE_START_MEMBER(apple2_state,tk3000)
22892289{
2290   m_machinetype = TK3000;   // enhanced IIe clone with Z80 keyboard scanner subcpu
2290   m_machinetype = TK3000; // enhanced IIe clone with Z80 keyboard scanner subcpu
22912291
22922292   apple2eplus_init_common((void *)NULL);
22932293}
r32760r32761
23352335   apple2_init_common();
23362336
23372337   // 1 MB of expansion RAM in slot 5
2338   m_exp_ram = auto_alloc_array(machine(), UINT8, 1024*1024);
2338   m_exp_ram = auto_alloc_array(machine(), UINT8, 1024*1024);
23392339   memset(m_exp_ram, 0xff, 1024*1024);
23402340
23412341   m_exp_bankhior = 0xf0;
trunk/src/mess/machine/apple3.c
r32760r32761
12751275      m_maincpu->set_input_line(INPUT_LINE_NMI, state);
12761276   }
12771277}
1278
trunk/src/mess/machine/aim65.c
r32760r32761
149149      space.install_read_handler(0xc000, 0xcfff, read8_delegate(FUNC(generic_slot_device::read_rom),(generic_slot_device*)m_z25));
150150   if (m_z26->exists())
151151      space.install_read_handler(0xb000, 0xbfff, read8_delegate(FUNC(generic_slot_device::read_rom),(generic_slot_device*)m_z26));
152   
152
153153   // Init RAM
154154   space.install_ram(0x0000, ram->size() - 1, ram->pointer());
155155
trunk/src/mess/machine/gamecom.c
r32760r32761
640640   UINT32 load_offset = 0;
641641
642642   if (size != 0x008000 && size != 0x040000 && size != 0x080000
643      && size != 0x100000 && size != 0x1c0000 && size != 0x200000)
643         && size != 0x100000 && size != 0x1c0000 && size != 0x200000)
644644   {
645645      image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported cartridge size");
646646      return IMAGE_INIT_FAIL;
647647   }
648   
648
649649   if (size == 0x1c0000)
650650      load_offset = 0x40000;
651   
651
652652   // in order to simplify banked access from the driver, we always allocate 0x200000,
653653   slot->rom_alloc(0x200000, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
654654   // we load what we have
r32760r32761
661661   if (size < 0x080000) { memcpy(crt + 0x040000, crt, 0x040000); } /* ->512KB */
662662   if (size < 0x100000) { memcpy(crt + 0x080000, crt, 0x080000); } /* ->1MB */
663663   if (size < 0x1c0000) { memcpy(crt + 0x100000, crt, 0x100000); } /* -> >=1.8MB */
664   
664
665665   return IMAGE_INIT_PASS;
666666}
667667
trunk/src/mess/machine/thomson.c
r32760r32761
18411841         thom_set_video_mode( THOM_VMODE_TO9 );
18421842      break;
18431843
1844        // undocumented, but tested on a real TO8D
1845        case 0x20: thom_set_video_mode( THOM_VMODE_MO5_ALT );     break;
1844      // undocumented, but tested on a real TO8D
1845      case 0x20: thom_set_video_mode( THOM_VMODE_MO5_ALT );     break;
18461846
18471847   case 0x21: thom_set_video_mode( THOM_VMODE_BITMAP4 );     break;
18481848
18491849   case 0x41: thom_set_video_mode( THOM_VMODE_BITMAP4_ALT ); break;
18501850
1851        // also undocumented but tested
1851      // also undocumented but tested
18521852   case 0x59: thom_set_video_mode( THOM_VMODE_BITMAP4_ALT_HALF ); break;
18531853
18541854   case 0x2a:
r32760r32761
18661866
18671867   case 0x26: thom_set_video_mode( THOM_VMODE_OVERLAY );     break;
18681868
1869        // undocumented 160x200 variant of overlay
1869      // undocumented 160x200 variant of overlay
18701870   case 0x3e: thom_set_video_mode( THOM_VMODE_OVERLAY_HALF );     break;
18711871
18721872   case 0x3f: thom_set_video_mode( THOM_VMODE_OVERLAY3 );    break;
trunk/src/mess/machine/nc.c
r32760r32761
4949   UINT32 size = m_card->common_get_size("rom");
5050
5151   m_card->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
52   m_card->common_load_rom(m_card->get_rom_base(), size, "rom");         
52   m_card->common_load_rom(m_card->get_rom_base(), size, "rom");
5353
5454   set_card_present_state(1);
5555   m_membank_card_ram_mask = card_calculate_mask(size);
r32760r32761
6464   // if there is no data to write, quit
6565   if (!m_card_size)
6666      return;
67   
67
6868   logerror("attempting card save\n");
69   
69
7070   // write data
7171   image.fwrite(m_card_ram, m_card_size);
72   
72
7373   logerror("write succeeded!\r\n");
74   
74
7575   // set card not present state
7676   set_card_present_state(0);
7777   m_card_size = 0;
r32760r32761
8383   set_card_present_state(0);
8484   m_card_size = 0;
8585}
86
trunk/src/mess/machine/primo.c
r32760r32761
244244{
245245   astring region_tag;
246246   m_cart1_rom = memregion(region_tag.cpy(m_cart1->tag()).cat(GENERIC_ROM_REGION_TAG));
247   m_cart2_rom = memregion(region_tag.cpy(m_cart2->tag()).cat(GENERIC_ROM_REGION_TAG));   
247   m_cart2_rom = memregion(region_tag.cpy(m_cart2->tag()).cat(GENERIC_ROM_REGION_TAG));
248248}
249249
250250void primo_state::machine_reset()
trunk/src/mess/machine/electron.c
r32760r32761
344344}
345345
346346void electron_state::machine_start()
347{   
347{
348348   UINT8 *lo_rom, *up_rom;
349349   astring region_tag;
350350   memory_region *cart_rom = memregion(region_tag.cpy(m_cart->tag()).cat(GENERIC_ROM_REGION_TAG));
r32760r32761
357357      lo_rom = cart_rom->base() + 0x4000;
358358   else
359359      lo_rom = memregion("user1")->base();
360   
360
361361   membank("bank2")->configure_entries(0,  1, lo_rom, 0x4000);
362362   membank("bank2")->configure_entries(1, 11, memregion("user1")->base() + 0x04000, 0x4000);
363363   membank("bank2")->configure_entries(12, 1, up_rom, 0x4000);
r32760r32761
389389   {
390390      int upsize = image.get_software_region_length("uprom");
391391      int losize = image.get_software_region_length("lorom");
392     
392
393393      if (upsize != 16384 && upsize != 0)
394394      {
395395         image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid size for uprom");
396396         return IMAGE_INIT_FAIL;
397397      }
398     
398
399399      if (losize != 16384 && losize != 0)
400400      {
401401         image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid size for lorom");
r32760r32761
406406
407407      if (upsize)
408408         memcpy(m_cart->get_rom_base(), image.get_software_region("uprom"), upsize);
409     
409
410410      if (losize)
411411         memcpy(m_cart->get_rom_base() + upsize, image.get_software_region("lorom"), losize);
412412
trunk/src/mess/machine/nes.c
r32760r32761
9797      sprintf(str, "FT_COL%i", i);
9898      m_io_ftrainer[i] = ioport(str);
9999   }
100   
100
101101   m_io_ctrlsel        = ioport("CTRLSEL");
102102   m_io_exp            = ioport("EXP");
103103   m_io_paddle         = ioport("PADDLE");
trunk/src/mess/machine/amstrad.c
r32760r32761
30313031   m_asic.ram = m_region_user1->base();  // 16kB RAM for ASIC, memory-mapped registers.
30323032   m_system_type = SYSTEM_PLUS;
30333033   m_centronics->write_data7(0);
3034   
3034
30353035   astring region_tag;
30363036   m_region_cart = memregion(region_tag.cpy(m_cart->tag()).cat(GENERIC_ROM_REGION_TAG));
30373037}
r32760r32761
30733073{
30743074   m_asic.ram = m_region_user1->base();  // 16kB RAM for ASIC, memory-mapped registers.
30753075   m_system_type = SYSTEM_GX4000;
3076   
3076
30773077   astring region_tag;
30783078   m_region_cart = memregion(region_tag.cpy(m_cart->tag()).cat(GENERIC_ROM_REGION_TAG));
30793079}
r32760r32761
31873187   // check for .CPR header
31883188   if (image.software_entry() == NULL)
31893189   {
3190      image.fread(header, 12);   
3190      image.fread(header, 12);
31913191      if (strncmp((char *)header, "RIFF", 4) != 0)
31923192      {
31933193         // not a CPR file, so rewind the image at start
r32760r32761
32193219         return IMAGE_INIT_FAIL;
32203220      }
32213221      else
3222         image.fread(m_cart->get_rom_base(), size);   
3222         image.fread(m_cart->get_rom_base(), size);
32233223   }
32243224   else
32253225   {
r32760r32761
32293229      // Chunks labeled 'cb00' represent Cartridge block 0, and is loaded to &0000-&3fff
32303230      //                'cb01' represent Cartridge block 1, and is loaded to &4000-&7fff
32313231      //                ... and so on.
3232     
3232
32333233      UINT32 offset = 0;
32343234      UINT8 *crt = m_cart->get_rom_base();
32353235      dynamic_buffer temp_copy;
r32760r32761
32413241      char chunklen[4];             // chunk length (always little-endian)
32423242      int chunksize;                // chunk length, calcaulated from the above
32433243      int ramblock;                 // 16k RAM block chunk is to be loaded into
3244      unsigned int bytes_to_read;   // total bytes to read, as mame_feof doesn't react to EOF without trying to go past it.     
3244      unsigned int bytes_to_read;   // total bytes to read, as mame_feof doesn't react to EOF without trying to go past it.
32453245
32463246      // Is RIFF format (*.cpr)
32473247      if (strncmp((char*)(header + 8), "AMS!", 4) != 0)
trunk/src/mess/machine/svi318.c
r32760r32761
6060   }
6161
6262   m_cart->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
63   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");         
63   m_cart->common_load_rom(m_cart->get_rom_base(), size, "rom");
6464
6565   if (image.software_entry() == NULL && !cart_verify(m_cart->get_rom_base()))
6666      return IMAGE_INIT_FAIL;
r32760r32761
407407   /* memory */
408408   m_empty_bank = auto_alloc_array(machine(), UINT8, 0x8000);
409409   memset(m_empty_bank, 0xff, 0x8000);
410   
410
411411   m_bank_low_ptr = m_empty_bank;
412412   m_bank_high1_ptr = m_empty_bank;
413   m_bank_high2_ptr = m_empty_bank;   
413   m_bank_high2_ptr = m_empty_bank;
414414}
415415
416416DRIVER_INIT_MEMBER(svi318_state, svi328_806)
r32760r32761
434434      save_item(NAME(m_svi806_ram));
435435      memset(m_svi806_ram, 0x00, 0x800);
436436      memset(m_svi806_ram + 0x800, 0xff, 0x800);
437     
437
438438      m_svi806_gfx = memregion("gfx1")->base();
439     
439
440440      // Set SVI-806 80 column card palette
441441      m_palette->set_pen_color(TMS9928A_PALETTE_SIZE, 0, 0, 0);     /* Monochrome black */
442442      m_palette->set_pen_color(TMS9928A_PALETTE_SIZE+1, 0, 224, 0); /* Monochrome green */
r32760r32761
459459
460460   save_item(NAME(m_svi806_present));
461461   save_item(NAME(m_svi806_ram_enabled));
462   
462
463463   machine().save().register_postload(save_prepost_delegate(FUNC(svi318_state::postload), this));
464464}
465465
r32760r32761
485485}
486486
487487void svi318_state::machine_reset()
488{   
488{
489489   m_keyboard_row = 0;
490490   m_centronics_busy = 0;
491491   m_svi806_present = 0;
r32760r32761
587587   }
588588
589589   m_bank_high1_ptr = m_empty_bank;
590   m_bank_high1_read_only = 1;
590   m_bank_high1_read_only = 1;
591591   m_bank_high2_ptr = m_empty_bank;
592592   m_bank_high2_read_only = 1;
593593
trunk/src/mess/machine/amigakbd.c
r32760r32761
88    We currently emulate the Amiga 500 keyboard controller, which was
99    also used in later Amiga 2000 keyboards.
1010
11   TODO: - Natural keyboard mode doesn't work with shifted characters,
12           they get sent in the wrong order (core bug?)
13         - Move 6500/1 to its own CPU core so that it can be shared with
14           other systems
15         - Add support for more keyboard controllers (pending on them
16           getting dumped)
11    TODO: - Natural keyboard mode doesn't work with shifted characters,
12            they get sent in the wrong order (core bug?)
13          - Move 6500/1 to its own CPU core so that it can be shared with
14            other systems
15          - Add support for more keyboard controllers (pending on them
16            getting dumped)
1717
18   Amiga 1000 keyboard part numbers (manufactured by Mitsumi):
18    Amiga 1000 keyboard part numbers (manufactured by Mitsumi):
1919
20   - 327063-01  R56-2144  English
21   - 327063-02            British
22   - 327063-03  R56-2153  German
23   - 327063-04  R56-2152  French
24   - 327063-05  R56-2154  Italian
20    - 327063-01  R56-2144  English
21    - 327063-02            British
22    - 327063-03  R56-2153  German
23    - 327063-04  R56-2152  French
24    - 327063-05  R56-2154  Italian
2525
2626***************************************************************************/
2727
r32760r32761
335335   m_kclk = 1;
336336   m_port_c = 0xff;
337337   m_port_d = 0xff;
338   m_latch = 0xffff;   // not initialized by hardware
339   m_counter = 0xffff;   // not initialized by hardware
338   m_latch = 0xffff;   // not initialized by hardware
339   m_counter = 0xffff; // not initialized by hardware
340340   m_control = 0x00;
341341
342342   m_timer->adjust(attotime::zero, 0, attotime::from_hz(XTAL_3MHz / 2));
trunk/src/mess/machine/wswan.c
r32760r32761
201201{
202202   m_ws_bios_bank = auto_alloc_array(machine(), UINT8, 0x10000);
203203   memcpy(m_ws_bios_bank + 0xffc0, ws_fake_bios_code, 0x40);
204   
204
205205   m_vdp.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(wswan_state::wswan_scanline_interrupt),this), &m_vdp);
206206   m_vdp.timer->adjust(attotime::from_ticks(256, 3072000), 0, attotime::from_ticks(256, 3072000));
207   
207
208208   wswan_register_save();
209   
209
210210   machine().device<nvram_device>("nvram")->set_base(m_internal_eeprom, INTERNAL_EEPROM_SIZE);
211   
211
212212   if (m_cart->exists())
213   {     
213   {
214214      // ROM
215215      m_maincpu->space(AS_PROGRAM).install_read_handler(0x20000, 0x2ffff, read8_delegate(FUNC(ws_cart_slot_device::read_rom20),(ws_cart_slot_device*)m_cart));
216216      m_maincpu->space(AS_PROGRAM).install_read_handler(0x30000, 0x3ffff, read8_delegate(FUNC(ws_cart_slot_device::read_rom30),(ws_cart_slot_device*)m_cart));
217217      m_maincpu->space(AS_PROGRAM).install_read_handler(0x40000, 0xeffff, read8_delegate(FUNC(ws_cart_slot_device::read_rom40),(ws_cart_slot_device*)m_cart));
218     
218
219219      // SRAM
220220      if (m_cart->get_type() == WS_SRAM)
221221      {
r32760r32761
249249   if (m_cart->exists())
250250      m_rotate = m_cart->get_is_rotated();
251251   else
252      m_rotate = 0;     
252      m_rotate = 0;
253253
254254   /* Intialize ports */
255255   memcpy(m_ws_portram, ws_portram_init, 256);
r32760r32761
332332      case 0xc1:
333333      case 0xc2:
334334      case 0xc3:
335      case 0xc4:   // EEPROM data
336      case 0xc5:   // EEPROM data
335      case 0xc4:  // EEPROM data
336      case 0xc5:  // EEPROM data
337337      case 0xc6:
338338      case 0xc7:
339339      case 0xc8:
340340      case 0xc9:
341341      case 0xca:
342      case 0xcb:   // RTC data
342      case 0xcb:  // RTC data
343343      case 0xcc:
344344      case 0xcd:
345345      case 0xce:
r32760r32761
10341034            logerror( "Unsupported internal EEPROM command: %X\n", data );
10351035         }
10361036         break;
1037      case 0xc0:   // ROM bank $40000-$fffff
1038      case 0xc1:   // SRAM bank
1039      case 0xc2:   // ROM bank $20000-$2ffff
1040      case 0xc3:   // ROM bank $30000-$3ffff
1037      case 0xc0:  // ROM bank $40000-$fffff
1038      case 0xc1:  // SRAM bank
1039      case 0xc2:  // ROM bank $20000-$2ffff
1040      case 0xc3:  // ROM bank $30000-$3ffff
10411041      case 0xc4:
10421042      case 0xc5:
1043      case 0xc6:   // EEPROM address / command
1044      case 0xc7:   // EEPROM address / command
1045      case 0xc8:   // EEPROM command
1043      case 0xc6:  // EEPROM address / command
1044      case 0xc7:  // EEPROM address / command
1045      case 0xc8:  // EEPROM command
10461046      case 0xc9:
1047      case 0xca:   // RTC command
1048      case 0xcb:   // RTC data
1047      case 0xca:  // RTC command
1048      case 0xcb:  // RTC data
10491049      case 0xcc:
10501050      case 0xcd:
10511051      case 0xce:
trunk/src/mess/machine/vtech2.c
r32760r32761
7171
7272   m_laser_latch = -1;
7373   m_mem = memregion("maincpu")->base();
74   
74
7575   // check ROM expansion
7676   astring region_tag;
7777   m_cart_rom = memregion(region_tag.cpy(m_cart->tag()).cat(GENERIC_ROM_REGION_TAG));
78   
78
7979   for (i = 0; i < ARRAY_LENGTH(m_laser_bank); i++)
8080      m_laser_bank[i] = -1;
8181}
r32760r32761
8888   m_laser_video_bank = video_mask;
8989   m_videoram = m_mem + m_laser_video_bank * 0x04000;
9090   logerror("laser_machine_init(): bank mask $%04X, video %d [$%05X]\n", m_laser_bank_mask, m_laser_video_bank, m_laser_video_bank * 0x04000);
91   
91
9292   for (int i = 0; i < ARRAY_LENGTH(m_laser_bank); i++)
9393      laser_bank_select_w(m_maincpu->space(AS_PROGRAM), i, 0);
9494}
r32760r32761
153153      else
154154      {
155155         sprintf(bank, "bank%d", offset + 1);
156         if (data >= 12 && m_cart_rom && (m_cart_rom->bytes() > (data % 12) * 0x4000))   // Expansion ROM banks
156         if (data >= 12 && m_cart_rom && (m_cart_rom->bytes() > (data % 12) * 0x4000))   // Expansion ROM banks
157157         {
158158            membank(bank)->set_base(m_cart_rom->base()+ (data % 12) * 0x4000);
159159            m_maincpu->space(AS_PROGRAM).install_read_bank(offset * 0x4000, offset * 0x4000 + 0x3fff, mra_bank_hard[offset]);
160160            m_maincpu->space(AS_PROGRAM).install_write_bank(offset * 0x4000, offset * 0x4000 + 0x3fff, mwa_bank_hard[offset]);
161161         }
162         else if (data < 12 && (m_laser_bank_mask & (1 << data)))   // ROM/RAM banks
162         else if (data < 12 && (m_laser_bank_mask & (1 << data)))    // ROM/RAM banks
163163         {
164164            // video RAM bank selected?
165165            if (data == m_laser_video_bank)
r32760r32761
175175            m_maincpu->space(AS_PROGRAM).nop_readwrite(offset * 0x4000, offset * 0x4000 + 0x3fff);
176176         }
177177      }
178     
178
179179   }
180180}
181181
trunk/src/mess/tiny.lst
r32760r32761
3939******************************************************************************/
4040
4141coleco      // NTSC ColecoVision
42colecop     // PAL Colecovision       
42colecop     // PAL Colecovision
trunk/src/mess/includes/svi318.h
r32760r32761
5252      m_bank3(*this, "bank3"),
5353      m_bank4(*this, "bank4")
5454   { }
55   
55
5656   // FDC
5757   UINT8 m_driveselect;
5858   int m_drq;
r32760r32761
9191   MC6845_UPDATE_ROW(crtc_update_row);
9292   memory_region *m_cart_rom;
9393   memory_region *m_bios_rom;
94   
94
9595protected:
9696   required_device<z80_device> m_maincpu;
9797   required_device<cassette_image_device> m_cassette;
r32760r32761
111111   optional_device<palette_device> m_palette;
112112
113113private:
114   
114
115115   void set_banks();
116116   void postload();
117   
117
118118   // memory banking
119119   UINT8   m_bank_switch;
120120   UINT8   m_bank_low;
121121   UINT8   m_bank_high;
122   
122
123123   UINT8   m_bank_low_read_only;
124124   UINT8   m_bank_high1_read_only;
125125   UINT8   m_bank_high2_read_only;
126   
126
127127   UINT8   *m_empty_bank;
128128   UINT8   *m_bank_low_ptr;
129129   UINT8   *m_bank_high1_ptr;
130130   UINT8   *m_bank_high2_ptr;
131   
131
132132   // keyboard
133133   UINT8   m_keyboard_row;
134   
134
135135   // centronics
136136   int m_centronics_busy;
137   
137
138138   // SVI-806 80 column card
139139   UINT8   m_svi806_present;
140140   UINT8   m_svi806_ram_enabled;
trunk/src/mess/includes/atom.h
r32760r32761
108108   /* devices */
109109   int m_previous_i8271_int_state;
110110   TIMER_DEVICE_CALLBACK_MEMBER(cassette_output_tick);
111   
111
112112   int load_cart(device_image_interface &image, generic_slot_device *slot);
113   DECLARE_DEVICE_IMAGE_LOAD_MEMBER(cart_load) { return load_cart(image, m_cart); }   
113   DECLARE_DEVICE_IMAGE_LOAD_MEMBER(cart_load) { return load_cart(image, m_cart); }
114114   DECLARE_QUICKLOAD_LOAD_MEMBER(atom_atm);
115115};
116116
r32760r32761
121121      : atom_state(mconfig, type, tag),
122122      m_e0(*this, "rom_e0"),
123123      m_e1(*this, "rom_e1")
124   {
124   {
125125   }
126126
127127   virtual void machine_start();
r32760r32761
132132   DECLARE_READ8_MEMBER(dos_r);
133133
134134   DECLARE_DRIVER_INIT(atomeb);
135   
135
136136   /* eprom state */
137137   int m_eprom;
138   
138
139139   generic_slot_device *m_ext[16];
140140   required_device<generic_slot_device> m_e0;
141141   required_device<generic_slot_device> m_e1;
trunk/src/mess/includes/electron.h
r32760r32761
7070      : driver_device(mconfig, type, tag),
7171      m_maincpu(*this, "maincpu"),
7272      m_cassette(*this, "cassette"),
73      m_beeper(*this, "beeper"),
73      m_beeper(*this, "beeper"),
7474      m_cart(*this, "cartslot"),
75      m_keybd(*this, "LINE")   
75      m_keybd(*this, "LINE")
7676   { }
7777
7878   ULA m_ula;
trunk/src/mess/includes/intv.h
r32760r32761
4444      m_io_options(*this, "OPTIONS"),
4545      m_io_test(*this, "TEST"),
4646      m_gfxdecode(*this, "gfxdecode"),
47      m_palette(*this, "palette") 
47      m_palette(*this, "palette")
4848   { }
4949
5050   required_device<cpu_device> m_maincpu;
r32760r32761
6666
6767   DECLARE_READ8_MEMBER(intv_right_control_r);
6868   DECLARE_READ8_MEMBER(intv_left_control_r);
69   
69
7070   UINT8 m_bus_copy_mode;
7171   UINT8 m_backtab_row;
7272   UINT16 m_ram16[0x160];
trunk/src/mess/includes/concept.h
r32760r32761
2121#define ACIA_0_TAG  "acia0"
2222#define ACIA_1_TAG  "acia1"
2323#define KBD_ACIA_TAG "kbacia"
24#define SPEAKER_TAG   "spkr"
24#define SPEAKER_TAG "spkr"
2525#define A2BUS_TAG "a2bus"
2626
2727class concept_state : public driver_device
trunk/src/mess/includes/radio86.h
r32760r32761
8888
8989protected:
9090   required_device<cassette_image_device> m_cassette;
91   optional_device<generic_slot_device> m_cart;   // for ROMDisk - only Radio86K & Orion?
91   optional_device<generic_slot_device> m_cart;    // for ROMDisk - only Radio86K & Orion?
9292   optional_device<i8257_device> m_dma8257;
9393   required_device<i8255_device> m_ppi8255_1;
9494   optional_device<i8255_device> m_ppi8255_2;
trunk/src/mess/includes/apple2.h
r32760r32761
2626
2727#define IIC_ACIA1_TAG "acia1"
2828#define IIC_ACIA2_TAG "acia2"
29#define IICP_IWM_TAG   "iwm"
29#define IICP_IWM_TAG    "iwm"
3030
3131#define LASER128_UDC_TAG "l128udc"
3232
r32760r32761
8383   APPLE_IIC,          // Apple IIc
8484   APPLE_IICPLUS,      // Apple IIc+
8585   TK2000,             // Microdigital TK2000
86   TK3000,            // Microdigital TK3000
86   TK3000,             // Microdigital TK3000
8787   LASER128,           // Laser 128/128EX/128EX2
8888   SPACE84,            // "Space 84" with flipped text mode
8989   LABA2P              // lab equipment (?) II Plus with flipped text mode
trunk/src/mess/video/maria.c
r32760r32761
22
33  Atari MARIA video emulation
44
5
5
66  - some history:
7    2014-10-05 Mike Saarna, Robert Tuccitto Last Line DMA value corrected
8                to 6. GCC and Atari docs both show a difference between
9                Other Line and Last Line as +6 at the lowest part of the
7    2014-10-05 Mike Saarna, Robert Tuccitto Last Line DMA value corrected
8                to 6. GCC and Atari docs both show a difference between
9                Other Line and Last Line as +6 at the lowest part of the
1010                range.
11                Blank scanlines are drawn when DMA is off, like real
11                Blank scanlines are drawn when DMA is off, like real
1212                hardware.
13                If MARIA hits the DMA limit, the CPU doesn't run until
13                If MARIA hits the DMA limit, the CPU doesn't run until
1414                the next scanline.
1515
16    2014-09-03 Mike Saarna, Robert Tuccitto reorganized DMA penalties to
16    2014-09-03 Mike Saarna, Robert Tuccitto reorganized DMA penalties to
1717                support new rendering timeout code.
1818
1919    2014-08-29 Mike Saarna Timeout rendering added.
20
20
2121    2014-08-26 Fabio Priuli Converted to device
2222
2323    2014-05-06 Mike Saarna Added interrupts to DMA cycle eating. Updates to
r32760r32761
6161
6262
6363void atari_maria_device::device_start()
64{   
64{
6565   m_cpu = machine().device<cpu_device>(m_cpu_tag);
6666   m_screen = machine().first_screen();
6767   m_screen->register_screen_bitmap(m_bitmap);
r32760r32761
181181      // All lines in a zone have the same initial DMA startup time. We'll adjust
182182      // cycles for the special last zone line later, as those penalties happen after
183183      // MARIA is done rendering, or after its hit the maximum rendering time.
184      maria_cycles = 16;
184      maria_cycles = 16;
185185
186186
187187      /* Process this DLL entry */
r32760r32761
232232               data_addr = (m_charbase | c) + (m_offset << 8);
233233               if (is_holey(data_addr))
234234                  continue;
235           
235
236236               maria_cycles += 3;
237237               if (m_cwidth) // two data bytes per map byte
238238               {
r32760r32761
260260            }
261261         }
262262      }
263   
263
264264      // Last Line post-render DMA cycle penalties...
265      if (m_offset == 0)
265      if (m_offset == 0)
266266      {
267267         maria_cycles += 6; // extra shutdown time
268268         if (READ_MEM(m_dll + 3) & 0x80)
r32760r32761
443443         m_color_kill = data & 0x80;
444444         switch ((data >> 5) & 3)
445445         {
446            case 0x00:
446            case 0x00:
447447            case 01:
448448               logerror("dma test mode, do not use.\n");
449449               break;
trunk/src/mess/video/maria.h
r32760r32761
1212   atari_maria_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
1313
1414   static void set_cpu_tag(device_t &device, const char *tag) { downcast<atari_maria_device &>(device).m_cpu_tag = tag; }
15   
15
1616   void interrupt(int lines);
1717   void startdma(int lines);
18   
18
1919   DECLARE_READ8_MEMBER(read);
2020   DECLARE_WRITE8_MEMBER(write);
2121
2222   UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
23   
23
2424protected:
2525   // device-level overrides
2626   virtual void device_start();
2727   virtual void device_reset();
2828
2929private:
30   
30
3131   int m_maria_palette[32];
3232   int m_line_ram[2][160];
3333   int m_active_buffer;
r32760r32761
5454   int write_line_ram(int addr, UINT8 offset, int pal);
5555
5656   const char *m_cpu_tag;
57   cpu_device *m_cpu;   // CPU whose space(AS_PROGRAM) serves as DMA source
57   cpu_device *m_cpu;  // CPU whose space(AS_PROGRAM) serves as DMA source
5858   screen_device *m_screen;
5959};
6060
trunk/src/mess/video/advision.c
r32760r32761
6565
6666      for (int i = 0; i < 8; i++)
6767      {
68         if (!BIT(data, 7 - i))
68         if (!BIT(data, 7 - i))
6969            dst[i * 256] = 8;
7070      }
7171
trunk/src/mess/video/apple3.c
r32760r32761
412412
413413UINT32 apple3_state::screen_update_apple3(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
414414{
415//   printf("gfx mode %x\n", m_flags & (VAR_VM3|VAR_VM1|VAR_VM0));
415//  printf("gfx mode %x\n", m_flags & (VAR_VM3|VAR_VM1|VAR_VM0));
416416
417417   switch(m_flags & (VAR_VM3|VAR_VM1|VAR_VM0))
418418   {
trunk/src/mess/video/nes.c
r32760r32761
3737   m_ppu->render(bitmap, 0, 0, 0, 0);
3838
3939   // if this is a disk system game, check for the flip-disk key
40   if ((m_cartslot && m_cartslot->exists() && (m_cartslot->get_pcb_id() == STD_DISKSYS))   // first scenario = disksys in m_cartslot (= famicom)
41         || m_disk)   // second scenario = disk via fixed internal disk option (fds & famitwin)
40   if ((m_cartslot && m_cartslot->exists() && (m_cartslot->get_pcb_id() == STD_DISKSYS))   // first scenario = disksys in m_cartslot (= famicom)
41         || m_disk)  // second scenario = disk via fixed internal disk option (fds & famitwin)
4242   {
4343      // latch this input so it doesn't go at warp speed
4444      if ((m_io_disksel->read_safe(0) & 0x01) && (!m_last_frame_flip))
trunk/src/mess/video/thomson.c
r32760r32761
412412   int i;
413413   pen_t c[2];
414414   c[0] = pal[ (ramb & 15) ^ 8 ];
415        c[1] = pal[ (ramb >> 4) ^ 8 ];
415      c[1] = pal[ (ramb >> 4) ^ 8 ];
416416   for ( i = 0; i < 16; i += 2, rama >>= 1 )
417417      dst[ 15 - i ] = dst[ 14 - i ] = c[ rama & 1 ];
418418}
r32760r32761
715715   c[0][0] = pal[ 0 ];
716716   c[0][1] = c[1][1] = pal[ 1 ];
717717   c[1][0] = pal[ 2 ];
718        rama >>= 4;
719        ramb >>= 4;
718      rama >>= 4;
719      ramb >>= 4;
720720   for ( i = 0; i < 16; i += 4, rama >>= 1, ramb >>= 1 )
721      dst[ 15 - i ] =  dst[ 14 - i ] = dst[ 13 - i ] =  dst[ 12 - i ] =
722                        c[ ramb & 1 ] [ rama & 1 ];
721      dst[ 15 - i ] =  dst[ 14 - i ] = dst[ 13 - i ] =  dst[ 12 - i ] =
722                  c[ ramb & 1 ] [ rama & 1 ];
723723}
724724END_UPDATE
725725
r32760r32761
730730   c[0][0] = pal[ 0 ];
731731   c[0][1] = c[1][1] = pal[ 1 ];
732732   c[1][0] = pal[ 2 ];
733        rama >>= 4;
734        ramb >>= 4;
733      rama >>= 4;
734      ramb >>= 4;
735735   for ( i = 0; i < 8; i += 2, rama >>= 1, ramb >>= 1 )
736736      dst[ 7 - i ] = dst[ 6 - i ] = c[ ramb & 1 ] [ rama & 1 ];
737737}
r32760r32761
782782   FUN(to770),    FUN(mo5),    FUN(bitmap4), FUN(bitmap4alt),  FUN(mode80),
783783   FUN(bitmap16), FUN(page1),  FUN(page2),   FUN(overlay),     FUN(overlay3),
784784   FUN(to9), FUN(mode80_to9),
785        FUN(bitmap4althalf), FUN(mo5alt), FUN(overlayhalf),
785      FUN(bitmap4althalf), FUN(mo5alt), FUN(overlayhalf),
786786};
787787
788788
r32760r32761
11991199{
12001200   LOG (( "thom: palette init called\n" ));
12011201
1202        /* TO8 and later use an EF9369 color palette chip
1203           The spec shows a built-in gamma correction for gamma=2.8
1204           i.e., output is out = in ^ (1/2.8)
1202      /* TO8 and later use an EF9369 color palette chip
1203         The spec shows a built-in gamma correction for gamma=2.8
1204         i.e., output is out = in ^ (1/2.8)
12051205
1206           For the TO7, the gamma correction is irrelevant.
1207           
1208           For the TO7/70, we use the same palette and gamma has the TO8,
1209           which gives good results (but is not verified).
1210         */
1211        thom_configure_palette(1.0 / 2.8, thom_pal_init, palette);
1206         For the TO7, the gamma correction is irrelevant.
1207
1208         For the TO7/70, we use the same palette and gamma has the TO8,
1209         which gives good results (but is not verified).
1210       */
1211      thom_configure_palette(1.0 / 2.8, thom_pal_init, palette);
12121212}
12131213
12141214PALETTE_INIT_MEMBER(thomson_state, mo5)
12151215{
12161216   LOG (( "thom: MO5 palette init called\n" ));
12171217
1218        /* The MO5 has a different fixed palette than the TO7/70.
1219           We use a smaller gamma correction which gives intutively better
1220           results (but is not verified).
1221         */
1222        thom_configure_palette(1.0, mo5_pal_init, palette);
1218      /* The MO5 has a different fixed palette than the TO7/70.
1219         We use a smaller gamma correction which gives intutively better
1220         results (but is not verified).
1221       */
1222      thom_configure_palette(1.0, mo5_pal_init, palette);
12231223}
12241224
12251225
trunk/src/mess/video/apple2.c
r32760r32761
102102      switch (m_sysconfig->read() & 0x03)
103103      {
104104         case 0:
105            break;   // leave alone
105            break;  // leave alone
106106
107107         case 1:
108108            if ((m_machinetype == APPLE_II) || (m_machinetype == LABA2P) || (m_machinetype == SPACE84))
r32760r32761
182182
183183            for (i = 0; i < xscale; i++)
184184            {
185               bitmap.pix16(ypos + y, xpos + (x * xscale) + i) = color;
185               bitmap.pix16(ypos + y, xpos + (x * xscale) + i) = color;
186186            }
187187         }
188188      }
r32760r32761
352352               {
353353                  case 0:
354354                     artifact_map_ptr = &m_hires_artifact_map[((vram_row[col+1] & 0x80) >> 7) * 16];
355                     for (b = 0; b < 7; b++)
355                     for (b = 0; b < 7; b++)
356356                     {
357357                        v = artifact_map_ptr[((w >> (b + 7-1)) & 0x07) | (((b ^ col) & 0x01) << 3)];
358358                        *(p++) = v;
r32760r32761
362362
363363                  case 1:
364364                     w >>= 7;
365                     for (b = 0; b < 7; b++)
365                     for (b = 0; b < 7; b++)
366366                     {
367367                        v = (w & 1);
368368                        w >>= 1;
r32760r32761
373373
374374                  case 2:
375375                     w >>= 7;
376                     for (b = 0; b < 7; b++)
376                     for (b = 0; b < 7; b++)
377377                     {
378378                        v = (w & 1);
379379                        w >>= 1;
r32760r32761
384384
385385                  case 3:
386386                     w >>= 7;
387                     for (b = 0; b < 7; b++)
387                     for (b = 0; b < 7; b++)
388388                     {
389389                        v = (w & 1);
390390                        w >>= 1;
r32760r32761
411411                  switch (mon_type)
412412                  {
413413                     case 0:
414                        for (b = 0; b < 7; b++)
414                        for (b = 0; b < 7; b++)
415415                        {
416416                           v = m_dhires_artifact_map[((((w >> (b + 7-1)) & 0x0F) * 0x11) >> (((2-(col*7+b))) & 0x03)) & 0x0F];
417417                           *(p++) = v;
trunk/src/mame/includes/cinemat.h
r32760r32761
3030   optional_shared_ptr<UINT16> m_rambase;
3131
3232   typedef void (cinemat_state::*sound_func)(UINT8 sound_val, UINT8 bits_changed);
33   
33
3434   sound_func m_sound_handler;
35   UINT8 m_sound_control;   
35   UINT8 m_sound_control;
3636   UINT32 m_current_shift;
3737   UINT32 m_last_shift;
3838   UINT32 m_last_shift2;
trunk/src/mame/includes/stv.h
r32760r32761
766766   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( stv_cart2 ) { return load_cart(image, m_cart2); }
767767   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( stv_cart3 ) { return load_cart(image, m_cart3); }
768768   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( stv_cart4 ) { return load_cart(image, m_cart4); }
769   
769
770770   void install_stvbios_speedups( void );
771771
772772   DECLARE_MACHINE_START(stv);
trunk/src/mame/includes/fuukifg2.h
r32760r32761
2323      m_gfxdecode(*this, "gfxdecode"),
2424      m_screen(*this, "screen"),
2525      m_palette(*this, "palette"),
26      m_fuukivid(*this, "fuukivid")
26      m_fuukivid(*this, "fuukivid")
2727      { }
2828
2929   /* memory pointers */
trunk/src/mame/includes/thepit.h
r32760r32761
1414   required_device<cpu_device> m_maincpu;
1515   required_device<gfxdecode_device> m_gfxdecode;
1616   required_device<palette_device> m_palette;
17   
17
1818   required_shared_ptr<UINT8> m_videoram;
1919   required_shared_ptr<UINT8> m_colorram;
2020   required_shared_ptr<UINT8> m_attributesram;
2121   required_shared_ptr<UINT8> m_spriteram;
22   
22
2323   int m_question_address;
2424   int m_question_rom;
2525   int m_remap_address[16];
trunk/src/mame/includes/taito_f3.h
r32760r32761
6767   required_device<gfxdecode_device> m_gfxdecode;
6868   required_device<screen_device> m_screen;
6969   required_device<palette_device> m_palette;
70   
70
7171   optional_shared_ptr<UINT32> m_f3_ram;
7272   optional_shared_ptr<UINT32> m_paletteram32;
73   
73
7474   UINT16 *m_videoram;
7575   UINT16 *m_spriteram;
7676   UINT16 *m_f3_vram;
r32760r32761
364364   inline void dpix_bg(UINT32 bgcolor);
365365   void init_alpha_blend_func();
366366   inline void draw_scanlines(bitmap_rgb32 &bitmap, int xsize, INT16 *draw_line_num, const struct f3_playfield_line_inf **line_t, const int *sprite, UINT32 orient, int skip_layer_num);
367   void visible_tile_check(struct f3_playfield_line_inf *line_t, int line,   UINT32 x_index_fx,UINT32 y_index, UINT16 *f3_pf_data_n);
367   void visible_tile_check(struct f3_playfield_line_inf *line_t, int line, UINT32 x_index_fx,UINT32 y_index, UINT16 *f3_pf_data_n);
368368   void calculate_clip(int y, UINT16 pri, UINT32* clip0, UINT32* clip1, int* line_enable);
369369   void get_spritealphaclip_info();
370370   void get_line_ram_info(tilemap_t *tmap, int sx, int sy, int pos, UINT16 *f3_pf_data_n);
trunk/src/mame/includes/fuukifg3.h
r32760r32761
3030      m_gfxdecode(*this, "gfxdecode"),
3131      m_screen(*this, "screen"),
3232      m_palette(*this, "palette"),
33      m_fuukivid(*this, "fuukivid")
33      m_fuukivid(*this, "fuukivid")
3434      { }
3535
3636   /* memory pointers */
trunk/src/mame/includes/exterm.h
r32760r32761
2424   required_device<cpu_device> m_audioslave;
2525   required_device<tms34010_device> m_slave;
2626   required_device<dac_device> m_dac;
27   
27
2828   required_shared_ptr<UINT16> m_master_videoram;
2929   required_shared_ptr<UINT16> m_slave_videoram;
30   
30
3131   UINT8 m_aimpos[2];
3232   UINT8 m_trackball_old[2];
3333   UINT8 m_master_sound_latch;
trunk/src/mame/includes/simple_st0016.h
r32760r32761
1212   { }
1313
1414   int mux_port;
15//   UINT32 m_st0016_rom_bank;
15//  UINT32 m_st0016_rom_bank;
1616
1717   optional_device<st0016_cpu_device> m_maincpu;
1818   DECLARE_READ8_MEMBER(mux_r);
trunk/src/mame/includes/midyunit.h
r32760r32761
5757   optional_device<williams_narc_sound_device> m_narc_sound;
5858   optional_device<williams_cvsd_sound_device> m_cvsd_sound;
5959   optional_device<williams_adpcm_sound_device> m_adpcm_sound;
60   
60
6161   required_shared_ptr<UINT16> m_generic_paletteram_16;
6262   optional_shared_ptr<UINT8> m_gfx_rom;
6363
r32760r32761
130130   DECLARE_VIDEO_START(common);
131131   TIMER_CALLBACK_MEMBER(dma_callback);
132132   TIMER_CALLBACK_MEMBER(autoerase_line);
133   
133
134134protected:
135135   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
136136   void dma_draw(UINT16 command);
trunk/src/mame/includes/artmagic.h
r32760r32761
3030   required_device<okim6295_device> m_oki;
3131   required_device<tms34010_device> m_tms;
3232   required_device<tlc34076_device> m_tlc34076;
33   
33
3434   required_shared_ptr<UINT16> m_control;
3535   required_shared_ptr<UINT16> m_vram0;
3636   required_shared_ptr<UINT16> m_vram1;
37   
37
3838   UINT8 m_tms_irq;
3939   UINT8 m_hack_irq;
4040   UINT8 m_prot_input[16];
r32760r32761
4949   void ultennis_protection();
5050   void cheesech_protection();
5151   void stonebal_protection();
52   
52
5353   int m_xor[16];
5454   int m_is_stoneball;
5555   UINT16 *m_blitter_base;
r32760r32761
8080   void execute_blit();
8181   void update_irq_state();
8282   inline UINT16 *address_to_vram(offs_t *address);
83   
83
8484protected:
8585   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
8686};
trunk/src/mame/includes/coolpool.h
r32760r32761
1919   required_device<cpu_device> m_dsp;
2020   required_device<dac_device> m_dac;
2121   optional_device<tlc34076_device> m_tlc34076;
22   
22
2323   required_shared_ptr<UINT16> m_vram_base;
2424   required_shared_ptr<UINT16> m_nvram;
2525
r32760r32761
3737
3838   UINT16 m_result;
3939   UINT16 m_lastresult;
40   
40
4141   UINT16 m_nvram_write_seq[NVRAM_UNLOCK_SEQ_LEN];
4242   UINT8 m_nvram_write_enable;
4343   UINT8 m_old_cmd;
trunk/src/mame/includes/midtunit.h
r32760r32761
104104   const UINT8 *jdredd_prot_table;
105105   UINT8    jdredd_prot_index;
106106   UINT8    jdredd_prot_max;
107   
107
108108   UINT8 m_gfx_rom_large;
109109
110110protected:
trunk/src/mame/includes/suprnova.h
r32760r32761
4343   required_device<sknsspr_device> m_spritegen;
4444   required_device<gfxdecode_device> m_gfxdecode;
4545   required_device<palette_device> m_palette;
46   
46
4747   required_shared_ptr<UINT32> m_spriteram;
4848   required_shared_ptr<UINT32> m_spc_regs;
4949   required_shared_ptr<UINT32> m_v3_regs;
r32760r32761
5555   required_shared_ptr<UINT32> m_v3t_ram;
5656   required_shared_ptr<UINT32> m_main_ram;
5757   required_shared_ptr<UINT32> m_cache_ram;
58   
58
5959   hit_t m_hit;
6060   UINT32 m_timer_0_temp[4];
6161   bitmap_ind16 m_sprite_bitmap;
trunk/src/mame/includes/namcos2.h
r32760r32761
120120   // game type helpers
121121   bool is_system21();
122122   int m_gametype;
123   
123
124124   emu_timer *m_posirq_timer;
125125   int m_mcu_analog_ctrl;
126126   int m_mcu_analog_data;
trunk/src/mame/includes/tatsumi.h
r32760r32761
3939   required_device<okim6295_device> m_oki;
4040   required_device<gfxdecode_device> m_gfxdecode;
4141   required_device<palette_device> m_palette;
42   
42
4343   optional_shared_ptr<UINT16> m_videoram;
4444   optional_shared_ptr<UINT16> m_cyclwarr_cpua_ram;
4545   optional_shared_ptr<UINT16> m_cyclwarr_cpub_ram;
r32760r32761
5858   optional_shared_ptr<UINT16> m_roundup_p_ram;
5959   optional_shared_ptr<UINT16> m_roundup_l_ram;
6060   required_shared_ptr<UINT16> m_spriteram;
61   
61
6262   UINT16 m_bigfight_a20000[8];
6363   UINT16 m_bigfight_a60000[2];
6464   UINT16 m_bigfight_a40000[2];
trunk/src/mame/includes/meadows.h
r32760r32761
2424      m_videoram(*this, "videoram")
2525   {
2626   }
27   
27
2828   required_device<s2650_device> m_maincpu;
2929   optional_device<s2650_device> m_audiocpu;
3030   optional_device<dac_device> m_dac;
r32760r32761
3535
3636   optional_shared_ptr<UINT8> m_spriteram;
3737   required_shared_ptr<UINT8> m_videoram;
38   
38
3939   UINT8 m_dac_data;
4040   int m_dac_enable;
4141   int m_channel;
trunk/src/mame/includes/model1.h
r32760r32761
3636   required_shared_ptr<UINT16> m_display_list0;
3737   required_shared_ptr<UINT16> m_display_list1;
3838   required_shared_ptr<UINT16> m_color_xlat;
39   
39
4040   struct view *m_view;
4141   struct point *m_pointdb;
4242   struct point *m_pointpt;
r32760r32761
274274   void sort_quads();
275275   void unsort_quads();
276276   void draw_quads(bitmap_rgb32 &bitmap, const rectangle &cliprect);
277   void fclip_push_quad_next(int level, struct quad_m1 *q,   struct point *p1, struct point *p2, struct point *p3, struct point *p4);
277   void fclip_push_quad_next(int level, struct quad_m1 *q, struct point *p1, struct point *p2, struct point *p3, struct point *p4);
278278   void fclip_push_quad(int level, struct quad_m1 *q);
279279   void push_object(UINT32 tex_adr, UINT32 poly_adr, UINT32 size);
280280   UINT16 *push_direct(UINT16 *list);
trunk/src/mame/includes/micro3d.h
r32760r32761
5252      m_shared_ram(*this, "shared_ram"),
5353      m_mac_sram(*this, "mac_sram"),
5454      m_sprite_vram(*this, "sprite_vram") { }
55     
55
5656   required_device<cpu_device> m_maincpu;
5757   required_device<i8051_device> m_audiocpu;
5858   required_device<upd7759_device> m_upd7759;
r32760r32761
172172   void rasterise_spans(UINT32 min_y, UINT32 max_y, UINT32 attr);
173173   int clip_triangle(micro3d_vtx *v, micro3d_vtx *vout, int num_vertices, enum planes plane);
174174   void draw_triangles(UINT32 attr);
175   
176175
176
177177protected:
178178   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
179179};
trunk/src/mame/includes/cosmic.h
r32760r32761
3131
3232   /* video-related */
3333   typedef pen_t (cosmic_state::*color_func)(UINT8 x, UINT8 y);
34   color_func       m_map_color;
34   color_func    m_map_color;
3535   int            m_color_registers[3];
3636   int            m_background_enable;
3737   int            m_magspot_pen_mask;
r32760r32761
5454   optional_device<gfxdecode_device> m_gfxdecode;
5555   required_device<screen_device> m_screen;
5656   required_device<palette_device> m_palette;
57   
57
5858   DECLARE_WRITE8_MEMBER(panic_sound_output_w);
5959   DECLARE_WRITE8_MEMBER(panic_sound_output2_w);
6060   DECLARE_WRITE8_MEMBER(cosmicg_output_w);
trunk/src/mame/includes/vectrex.h
r32760r32761
5757      m_io_lpenx(*this, "LPENX"),
5858      m_io_lpeny(*this, "LPENY"),
5959      m_io_coin(*this, "COIN"),
60      m_screen(*this, "screen")
60      m_screen(*this, "screen")
6161   { }
6262
6363   required_shared_ptr<UINT8> m_gce_vectorram;
trunk/src/mame/includes/model3.h
r32760r32761
9494   required_shared_ptr<UINT64> m_work_ram;
9595   required_shared_ptr<UINT64> m_paletteram64;
9696   optional_device<dsbz80_device> m_dsbz80;    // Z80-based MPEG Digital Sound Board
97   required_shared_ptr<UINT16> m_soundram;   
97   required_shared_ptr<UINT16> m_soundram;
9898
9999   required_device<gfxdecode_device> m_gfxdecode;
100100   required_device<palette_device> m_palette;
r32760r32761
261261   DECLARE_DRIVER_INIT(spikeout);
262262   DECLARE_DRIVER_INIT(magtruck);
263263   DECLARE_DRIVER_INIT(lamachin);
264   DECLARE_DRIVER_INIT(model3_15);   
264   DECLARE_DRIVER_INIT(model3_15);
265265   DECLARE_MACHINE_START(model3_10);
266266   DECLARE_MACHINE_RESET(model3_10);
267267   DECLARE_MACHINE_START(model3_15);
trunk/src/mame/includes/jpmimpct.h
r32760r32761
106106   DECLARE_READ8_MEMBER(hopper_c_r);
107107   DECLARE_WRITE8_MEMBER(payen_a_w);
108108   DECLARE_WRITE8_MEMBER(display_c_w);
109   
109
110110   DECLARE_WRITE_LINE_MEMBER(tms_irq);
111111   TMS340X0_TO_SHIFTREG_CB_MEMBER(to_shiftreg);
112112   TMS340X0_FROM_SHIFTREG_CB_MEMBER(from_shiftreg);
113113   TMS340X0_SCANLINE_RGB32_CB_MEMBER(scanline_update);
114   
114
115115   DECLARE_MACHINE_START(jpmimpct);
116116   DECLARE_MACHINE_RESET(jpmimpct);
117117   DECLARE_VIDEO_START(jpmimpct);
trunk/src/mame/includes/tnzs.h
r32760r32761
8585   DECLARE_WRITE8_MEMBER(kageki_csport_w);
8686   DECLARE_WRITE8_MEMBER(kabukiz_sound_bank_w);
8787   DECLARE_WRITE8_MEMBER(kabukiz_sample_w);
88   
88
8989   DECLARE_READ8_MEMBER(tnzs_ramrom_bank_r);
9090   DECLARE_WRITE8_MEMBER(tnzs_ramrom_bank_w);
91   
91
9292   SAMPLES_START_CB_MEMBER(kageki_init_samples);
9393
9494   DECLARE_DRIVER_INIT(arknoid2);
trunk/src/mame/includes/sslam.h
r32760r32761
1616      m_regs(*this, "regs"),
1717      m_spriteram(*this, "spriteram") { }
1818
19   
19
2020   required_device<cpu_device> m_maincpu;
2121   required_device<cpu_device> m_audiocpu;
2222   required_device<okim6295_device> m_oki;
r32760r32761
2828   optional_shared_ptr<UINT16> m_tx_tileram;
2929   required_shared_ptr<UINT16> m_regs;
3030   required_shared_ptr<UINT16> m_spriteram;
31   
31
3232   emu_timer *m_music_timer;
3333
3434   int m_sound;
trunk/src/mame/includes/bfm_sc45.h
r32760r32761
585585   void bfm_sc4_68307_portb_w(address_space &space, bool dedicated, UINT16 data, UINT16 line_mask);
586586   UINT8 bfm_sc4_68307_porta_r(address_space &space, bool dedicated, UINT8 line_mask);
587587   UINT16 bfm_sc4_68307_portb_r(address_space &space, bool dedicated, UINT16 line_mask);
588   
588
589589   void find_mbus(UINT16* rom);
590590
591591
trunk/src/mame/includes/8080bw.h
r32760r32761
5252   UINT8 m_schaser_background_disable;
5353   UINT8 m_schaser_background_select;
5454   UINT16 m_claybust_gun_pos;
55   
55
5656   int m_invmulti_bank;
5757
5858
trunk/src/mame/includes/splash.h
r32760r32761
1818      m_msm2(*this, "msm2"),
1919      m_gfxdecode(*this, "gfxdecode"),
2020      m_palette(*this, "palette"),
21     
21
2222      funystrp_val(0),
2323      funystrp_ff3cc7_val(0),
2424      funystrp_ff3cc8_val(0)
trunk/src/mame/includes/snk.h
r32760r32761
2626   required_device<gfxdecode_device> m_gfxdecode;
2727   required_device<screen_device> m_screen;
2828   required_device<palette_device> m_palette;
29   
29
3030   required_shared_ptr<UINT8> m_spriteram;
3131   optional_shared_ptr<UINT8> m_fg_videoram;
3232   required_shared_ptr<UINT8> m_bg_videoram;
r32760r32761
3939   int m_marvins_sound_busy_flag;
4040   // FIXME this should be initialised on machine reset
4141   int m_sound_status;
42   
42
4343   tilemap_t *m_tx_tilemap;
4444   tilemap_t *m_fg_tilemap;
4545   tilemap_t *m_bg_tilemap;
r32760r32761
181181   UINT32 screen_update_tnk3(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
182182   UINT32 screen_update_ikari(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
183183   UINT32 screen_update_gwar(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
184   UINT32 screen_update_tdfever(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);   
184   UINT32 screen_update_tdfever(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
185185   TIMER_CALLBACK_MEMBER(sgladiat_sndirq_update_callback);
186186   TIMER_CALLBACK_MEMBER(sndirq_update_callback);
187187   DECLARE_WRITE_LINE_MEMBER(ymirq_callback_2);
188188   void marvins_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, const int scrollx, const int scrolly, const int from, const int to);
189189   void tnk3_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, const int xscroll, const int yscroll);
190190   void ikari_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, const int start, const int xscroll, const int yscroll, const UINT8 *source, const int gfxnum );
191   void tdfever_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect,   const int xscroll, const int yscroll, const UINT8 *source, const int gfxnum, const int hw_xflip, const int from, const int to);
191   void tdfever_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect,  const int xscroll, const int yscroll, const UINT8 *source, const int gfxnum, const int hw_xflip, const int from, const int to);
192192   int hardflags_check(int num);
193193   int hardflags_check8(int num);
194194   int turbofront_check(int small, int num);
trunk/src/mame/includes/suna8.h
r32760r32761
148148   DECLARE_WRITE8_MEMBER(suna8_samples_number_w);
149149   void play_sample(int index);
150150   SAMPLES_START_CB_MEMBER(sh_start);
151   
151
152152   void draw_normal_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect, int which);
153153   void draw_text_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect);
154154   UINT8 *brickzn_decrypt();
trunk/src/mame/includes/polyplay.h
r32760r32761
1616
1717   required_shared_ptr<UINT8> m_videoram;
1818   required_shared_ptr<UINT8> m_characterram;
19   
19
2020   required_device<cpu_device> m_maincpu;
2121   required_device<samples_device> m_samples;
2222   required_device<gfxdecode_device> m_gfxdecode;
2323   required_device<palette_device> m_palette;
24   
24
2525   int m_freq1;
2626   int m_freq2;
2727   int m_channel_playing1;
r32760r32761
3535   int m_channel2_const;
3636   timer_device* m_timer;
3737   int m_last;
38   
38
3939   DECLARE_WRITE8_MEMBER(polyplay_sound_channel);
4040   DECLARE_WRITE8_MEMBER(polyplay_start_timer2);
4141   DECLARE_READ8_MEMBER(polyplay_random_read);
trunk/src/mame/includes/harddriv.h
r32760r32761
331331   DECLARE_WRITE16_MEMBER( hdgsp_io_w );
332332
333333   DECLARE_WRITE16_MEMBER( hdgsp_protection_w );
334   
334
335335   DECLARE_WRITE_LINE_MEMBER( hdgsp_irq_gen );
336336   DECLARE_WRITE_LINE_MEMBER( hdmsp_irq_gen );
337337
r32760r32761
385385
386386   void hdds3sdsp_reset_timer();
387387   void hdds3xdsp_reset_timer();
388   
388
389389   TIMER_CALLBACK_MEMBER( xsdp_sport1_irq_off_callback );
390390
391391   /* DSK board */
r32760r32761
441441   /*----------- defined in video/harddriv.c -----------*/
442442   TMS340X0_TO_SHIFTREG_CB_MEMBER(hdgsp_write_to_shiftreg);
443443   TMS340X0_FROM_SHIFTREG_CB_MEMBER(hdgsp_read_from_shiftreg);
444   
444
445445   void update_palette_bank(int newbank);
446   
446
447447   DECLARE_READ16_MEMBER( hdgsp_control_lo_r );
448448   DECLARE_WRITE16_MEMBER( hdgsp_control_lo_w );
449449   DECLARE_READ16_MEMBER( hdgsp_control_hi_r );
r32760r32761
454454   DECLARE_WRITE16_MEMBER( hdgsp_vram_2bpp_w );
455455
456456   inline void gsp_palette_change(int offset);
457   
457
458458   DECLARE_READ16_MEMBER( hdgsp_paletteram_lo_r );
459459   DECLARE_WRITE16_MEMBER( hdgsp_paletteram_lo_w );
460460   DECLARE_READ16_MEMBER( hdgsp_paletteram_hi_r );
r32760r32761
466466   /* DS III/IV board */
467467   TIMER_DEVICE_CALLBACK_MEMBER( ds3sdsp_internal_timer_callback );
468468   TIMER_DEVICE_CALLBACK_MEMBER( ds3xdsp_internal_timer_callback );
469   
469
470470   TMS340X0_SCANLINE_IND16_CB_MEMBER(scanline_driver);
471471   TMS340X0_SCANLINE_IND16_CB_MEMBER(scanline_multisync);
472472};
trunk/src/mame/includes/legionna.h
r32760r32761
2121      m_palette(*this, "palette"),
2222      m_wordswapram(*this, "wordswapram"),
2323      m_raiden2cop(*this, "raiden2cop")
24   {
24   {
2525      memset(scrollvals, 0, sizeof(UINT16)*6);
2626   }
2727
r32760r32761
9191   optional_device<raiden2cop_device> m_raiden2cop;
9292
9393};
94
95
trunk/src/mame/includes/raiden2.h
r32760r32761
1313        mid_data(*this, "mid_data"),
1414        text_data(*this, "text_data"),
1515        */
16        sprites(*this, "sprites") ,
17        m_maincpu(*this, "maincpu"),
18        m_seibu_sound(*this, "seibu_sound"),
19        m_gfxdecode(*this, "gfxdecode"),
20        m_palette(*this, "palette"),
21     
22        bg_bank(0),
23        fg_bank(0),
24        mid_bank(0),
25        tx_bank(0),
26        raiden2_tilemap_enable(0),
27        prg_bank(0),
28        cop_bank(0),
16         sprites(*this, "sprites") ,
17         m_maincpu(*this, "maincpu"),
18         m_seibu_sound(*this, "seibu_sound"),
19         m_gfxdecode(*this, "gfxdecode"),
20         m_palette(*this, "palette"),
2921
30        sprite_prot_x(0),
31        sprite_prot_y(0),
32        dst1(0),
33        cop_spr_maxx(0),
34        cop_spr_off(0),
35   
36        tile_buffer(320, 256),
37        sprite_buffer(320, 256),
38        m_raiden2cop(*this, "raiden2cop")
22         bg_bank(0),
23         fg_bank(0),
24         mid_bank(0),
25         tx_bank(0),
26         raiden2_tilemap_enable(0),
27         prg_bank(0),
28         cop_bank(0),
29
30         sprite_prot_x(0),
31         sprite_prot_y(0),
32         dst1(0),
33         cop_spr_maxx(0),
34         cop_spr_off(0),
35
36         tile_buffer(320, 256),
37         sprite_buffer(320, 256),
38         m_raiden2cop(*this, "raiden2cop")
3939   {
4040      memset(scrollvals, 0, sizeof(UINT16)*6);
4141      memset(sprite_prot_src_addr, 0, sizeof(UINT16)*2);
r32760r32761
8787   bool blend_active[0x800]; // cfg
8888
8989   tilemap_t *background_layer,*midground_layer,*foreground_layer,*text_layer;
90   
91   
90
91
9292   int bg_bank, fg_bank, mid_bank, tx_bank;
9393   UINT16 raiden2_tilemap_enable;
9494   UINT8 prg_bank;
trunk/src/mame/includes/konamigx.h
r32760r32761
155155
156156   void konamigx_esc_alert(UINT32 *srcbase, int srcoffs, int count, int mode);
157157   void konamigx_precache_registers(void);
158   
158
159159   void wipezbuf(int noshadow);
160160
161161   void dmastart_callback(int data);
trunk/src/mame/mame.mak
r32760r32761
12101210   $(DRIVERS)/igs_m036.o \
12111211   $(DRIVERS)/iqblock.o $(VIDEO)/iqblock.o \
12121212   $(DRIVERS)/lordgun.o $(VIDEO)/lordgun.o \
1213   $(DRIVERS)/pgm.o $(VIDEO)/pgm.o   $(MACHINE)/pgmprot_igs027a_type1.o $(MACHINE)/pgmprot_igs027a_type2.o $(MACHINE)/pgmprot_igs027a_type3.o $(MACHINE)/pgmprot_igs025_igs012.o $(MACHINE)/pgmprot_igs025_igs022.o $(MACHINE)/pgmprot_igs025_igs028.o $(MACHINE)/pgmprot_orlegend.o \
1213   $(DRIVERS)/pgm.o $(VIDEO)/pgm.o $(MACHINE)/pgmprot_igs027a_type1.o $(MACHINE)/pgmprot_igs027a_type2.o $(MACHINE)/pgmprot_igs027a_type3.o $(MACHINE)/pgmprot_igs025_igs012.o $(MACHINE)/pgmprot_igs025_igs022.o $(MACHINE)/pgmprot_igs025_igs028.o $(MACHINE)/pgmprot_orlegend.o \
12141214   $(DRIVERS)/pgm2.o \
12151215   $(DRIVERS)/spoker.o \
12161216   $(MACHINE)/igs036crypt.o \
trunk/src/mame/video/dooyong.c
r32760r32761
224224      flags = ((attr & 0x02) ? TILE_FLIPX : 0) | ((attr & 0x04) ? TILE_FLIPY : 0);
225225   }
226226   else
227   {   
228
227   {
229228      /* primella */
230229      /* Tiles take two bytes in ROM:
231230                       MSB   LSB
r32760r32761
237236         Y = y flip */
238237      int codemask = 0x03;
239238      int palmask  = 0x3c;
240     
239
241240      if (m_gfxdecode->gfx(1)->depth() == 256) // pop bingo has an 8bpp layer and uses what would be the low palette bit to address more tiles (girls 4,5,6 in bonus game)
242241      {
243242         codemask = 0x07;
trunk/src/mame/video/snk.c
r32760r32761
835835    -xx-x--- (bank number)
836836    x------- (x offset bit8)
837837*/
838void snk_state::tdfever_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect,   const int xscroll, const int yscroll, const UINT8 *source, const int gfxnum,
838void snk_state::tdfever_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect,   const int xscroll, const int yscroll, const UINT8 *source, const int gfxnum,
839839                              const int hw_xflip, const int from, const int to)
840840{
841841   gfx_element *gfx = m_gfxdecode->gfx(gfxnum);
trunk/src/mame/video/sknsspr.h
r32760r32761
44{
55public:
66   sknsspr_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
7   
7
88   void skns_draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, UINT32* spriteram_source, size_t spriteram_size, UINT8* gfx_source, size_t gfx_length, UINT32* sprite_regs);
99   void skns_sprite_kludge(int x, int y);
1010
trunk/src/mame/video/battlera.c
r32760r32761
11// delete me
2
trunk/src/mame/video/fuukifg.c
r32760r32761
1/*
1/*
22*/
33
44#include "emu.h"
r32760r32761
6565
6666        6.w                             Tile Code
6767
68      for FG3 hardware
68        for FG3 hardware
6969
7070        6.w     fe-- ---- ---- ----     Tile Bank
7171                --dc ba98 7654 3210     Tile Code
r32760r32761
180180{
181181   memcpy(m_sprram_old2, m_sprram_old, 0x2000);
182182   memcpy(m_sprram_old, m_sprram, 0x2000);
183}
No newline at end of file
183}
trunk/src/mame/video/fuukifg.h
r32760r32761
99
1010   // static configuration
1111   static void static_set_gfxdecode_tag(device_t &device, const char *tag);
12   
12
1313   void draw_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int flip_screen, UINT32* tilebank);
1414   UINT16* m_sprram;
15   UINT16*   m_sprram_old;
15   UINT16* m_sprram_old;
1616   UINT16* m_sprram_old2;
1717
1818
r32760r32761
2525   {
2626      return m_sprram[offset];
2727   }
28   
28
2929   void buffer_sprites(void);
3030
3131protected:
r32760r32761
4040
4141#define MCFG_FUUKI_VIDEO_GFXDECODE(_gfxtag) \
4242   fuukivid_device::static_set_gfxdecode_tag(*device, "^" _gfxtag);
43
trunk/src/mame/video/legionna.c
r32760r32761
6363
6464WRITE16_MEMBER(legionna_state::videowrite_cb_w)
6565{
66   //   AM_RANGE(0x101000, 0x1017ff) AM_RAM // _WRITE(legionna_background_w) AM_SHARE("back_data")
67   //   AM_RANGE(0x101800, 0x101fff) AM_RAM // _WRITE(legionna_foreground_w) AM_SHARE("fore_data")
68   //   AM_RANGE(0x102000, 0x1027ff) AM_RAM // _WRITE(legionna_midground_w) AM_SHARE("mid_data")
69   //   AM_RANGE(0x102800, 0x1037ff) AM_RAM // _WRITE(legionna_text_w) AM_SHARE("textram")
66   //  AM_RANGE(0x101000, 0x1017ff) AM_RAM // _WRITE(legionna_background_w) AM_SHARE("back_data")
67   //  AM_RANGE(0x101800, 0x101fff) AM_RAM // _WRITE(legionna_foreground_w) AM_SHARE("fore_data")
68   //  AM_RANGE(0x102000, 0x1027ff) AM_RAM // _WRITE(legionna_midground_w) AM_SHARE("mid_data")
69   //  AM_RANGE(0x102800, 0x1037ff) AM_RAM // _WRITE(legionna_text_w) AM_SHARE("textram")
7070
7171   if (offset < 0x800 / 2)
7272   {
r32760r32761
194194
195195VIDEO_START_MEMBER(legionna_state,legionna)
196196{
197
198197   m_back_data = auto_alloc_array_clear(machine(), UINT16, 0x800/2);
199198   m_fore_data =  auto_alloc_array_clear(machine(), UINT16, 0x800/2);
200199   m_mid_data =  auto_alloc_array_clear(machine(), UINT16, 0x800/2);
r32760r32761
220219
221220VIDEO_START_MEMBER(legionna_state,denjinmk)
222221{
223
224222   m_back_data = auto_alloc_array_clear(machine(), UINT16, 0x800/2);
225223   m_fore_data =  auto_alloc_array_clear(machine(), UINT16, 0x800/2);
226224   m_mid_data =  auto_alloc_array_clear(machine(), UINT16, 0x800/2);
r32760r32761
499497
500498UINT32 legionna_state::screen_update_godzilla(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
501499{
502
503
504
505500   bitmap.fill(0x0200, cliprect);
506501   screen.priority().fill(0, cliprect);
507502
r32760r32761
521516
522517UINT32 legionna_state::screen_update_grainbow(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
523518{
524
525
526519   bitmap.fill(m_palette->black_pen(), cliprect);
527520   screen.priority().fill(0, cliprect);
528521
trunk/src/mame/video/decmxc06.h
r32760r32761
1616   void draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect, UINT16* spriteram16, int pri_mask, int pri_val, int col_mask );
1717   void draw_sprites_bootleg( bitmap_ind16 &bitmap, const rectangle &cliprect, UINT16* spriteram, int pri_mask, int pri_val, int col_mask );
1818   void set_pri_type( int type ) { m_priority_type = type; }
19   
19
2020protected:
2121   virtual void device_start();
2222   virtual void device_reset();
trunk/src/mame/video/skyfox.c
r32760r32761
173173         for (dx = xstart; dx != xend; dx += xinc, code++)
174174         {
175175            gfx->transpen(bitmap, cliprect, code, 0, flipx, flipy, dx*8 + x, dy*8 + y, 0xff);
176           
176
177177            // wraparound y - BTANB: large sprites exiting the screen sometimes reappear on the other edge
178178            gfx->transpen(bitmap, cliprect, code, 0, flipx, flipy, dx*8 + x, dy*8 + y - 256, 0xff);
179179         }
trunk/src/mame/video/taito_f3.c
r32760r32761
13981398
13991399/*============================================================================*/
14001400
1401inline void taito_f3_state::draw_scanlines(   
1401inline void taito_f3_state::draw_scanlines(
14021402                     bitmap_rgb32 &bitmap,int xsize,INT16 *draw_line_num,
14031403                     const struct f3_playfield_line_inf **line_t,
14041404                     const int *sprite,
trunk/src/mame/video/fuukifg3.c
r32760r32761
9090
9191void fuuki32_state::video_start()
9292{
93//   m_buf_spriteram = auto_alloc_array(machine(), UINT32, m_spriteram.bytes() / 4);
94//   m_buf_spriteram2 = auto_alloc_array(machine(), UINT32, m_spriteram.bytes() / 4);
93//  m_buf_spriteram = auto_alloc_array(machine(), UINT32, m_spriteram.bytes() / 4);
94//  m_buf_spriteram2 = auto_alloc_array(machine(), UINT32, m_spriteram.bytes() / 4);
9595
9696
9797
trunk/src/mame/video/tc0480scp.c
r32760r32761
156156   m_palette(*this)
157157{
158158   memset(m_ctrl, 0, sizeof(m_ctrl));
159   
159
160160   for (int i = 0; i < 4; i++)
161161   {
162162      m_bg_ram[i] = NULL;
trunk/src/mame/video/k054156_k054157_k056832.c
r32760r32761
12691269        */
12701270      {
12711271         bitmap_ind16 *pixmap;
1272         
1272
12731273         UINT8 code_transparent, code_opaque;
12741274         const pen_t *pal_ptr;
12751275         const UINT8  *src_ptr;
trunk/src/mame/video/mario.c
r32760r32761
193193
194194            y = y ^ (m_flip ? 0xFF : 0x00); /* physical screen location */
195195            x = x ^ (m_flip ? 0xFF : 0x00); /* physical screen location */
196           
196
197197            code = m_spriteram[offs + 2];
198198            color = (m_spriteram[offs + 1] & 0x0f) + 16 * m_palette_bank + 32 * m_monitor;
199199            flipx = (m_spriteram[offs + 1] & 0x80);
r32760r32761
216216            x = m_spriteram[offs + 0];
217217            y = 240 - y; /* logical screen position */
218218
219         //   y = y ^ (m_flip ? 0xFF : 0x00); /* physical screen location */
220         //   x = x ^ (m_flip ? 0xFF : 0x00); /* physical screen location */
219         //  y = y ^ (m_flip ? 0xFF : 0x00); /* physical screen location */
220         //  x = x ^ (m_flip ? 0xFF : 0x00); /* physical screen location */
221221
222222            code = (m_spriteram[offs + 2] & 0x7f) | ((m_spriteram[offs + 1] & 0x40) << 1); // upper tile bit is where the flipy bit goes on mario
223223            color = (m_spriteram[offs + 1] & 0x0f) + 16 * m_palette_bank + 32 * m_monitor;
r32760r32761
237237         }
238238         else
239239         {
240
241240            m_gfxdecode->gfx(1)->transpen(bitmap, cliprect,
242241               code,
243242               color,
trunk/src/mame/video/seibuspi.c
r32760r32761
2626      m_midl_layer_offset = 0x2000 / 4 / 2;
2727      m_text_layer_offset = 0x3000 / 4 / 2;
2828   }
29   
29
3030   m_fore_layer_d13 = m_layer_bank >> 14 & 0x2000;
3131   m_back_layer_d14 = m_rf2_layer_bank << 14 & 0x4000;
3232   m_midl_layer_d14 = m_rf2_layer_bank << 13 & 0x4000;
r32760r32761
657657   m_rf2_layer_bank = 0;
658658   m_rowscroll_enable = 0;
659659   set_layer_offsets();
660   
660
661661   m_tilemap_ram_size = 0;
662662   m_palette_ram_size = 0x4000;
663663   m_sprite_ram_size = 0x2000;
trunk/src/mame/video/model3.c
r32760r32761
33#include "video/rgbutil.h"
44#include "includes/model3.h"
55
6#define ENABLE_BILINEAR      1
6#define ENABLE_BILINEAR     1
77
88#define TRI_PARAM_TEXTURE_PAGE          0x1
99#define TRI_PARAM_TEXTURE_MIRROR_U      0x2
r32760r32761
2727      : poly_manager<float, model3_polydata, 6, 50000>(state.machine())//, m_state(state)
2828   {
2929      m_fb = auto_bitmap_rgb32_alloc(state.machine(), width, height);
30      m_zb = auto_bitmap_ind32_alloc(state.machine(), width, height);     
30      m_zb = auto_bitmap_ind32_alloc(state.machine(), width, height);
3131   }
3232
3333   void draw(bitmap_rgb32 &bitmap, const rectangle &cliprect);
r32760r32761
6767   FILE* file;
6868   int i;
6969   file = fopen("m3_texture_ram.bin","wb");
70    for (i=0; i < 0x200000; i++)
71    {
72        fputc((UINT8)(m_texture_ram[0][i] >> 8), file);
73        fputc((UINT8)(m_texture_ram[0][i] >> 0), file);
74    }
7570   for (i=0; i < 0x200000; i++)
76    {
77        fputc((UINT8)(m_texture_ram[1][i] >> 8), file);
78        fputc((UINT8)(m_texture_ram[1][i] >> 0), file);
79    }
80    fclose(file);
71   {
72      fputc((UINT8)(m_texture_ram[0][i] >> 8), file);
73      fputc((UINT8)(m_texture_ram[0][i] >> 0), file);
74   }
75   for (i=0; i < 0x200000; i++)
76   {
77      fputc((UINT8)(m_texture_ram[1][i] >> 8), file);
78      fputc((UINT8)(m_texture_ram[1][i] >> 0), file);
79   }
80   fclose(file);
8181
82    file = fopen("m3_displist.bin","wb");
83    for (i=0; i < 0x40000; i++)
84    {
85        fputc((UINT8)(m_display_list_ram[i] >> 24), file);
86        fputc((UINT8)(m_display_list_ram[i] >> 16), file);
87        fputc((UINT8)(m_display_list_ram[i] >> 8), file);
88        fputc((UINT8)(m_display_list_ram[i] >> 0), file);
89    }
90    fclose(file);
82   file = fopen("m3_displist.bin","wb");
83   for (i=0; i < 0x40000; i++)
84   {
85      fputc((UINT8)(m_display_list_ram[i] >> 24), file);
86      fputc((UINT8)(m_display_list_ram[i] >> 16), file);
87      fputc((UINT8)(m_display_list_ram[i] >> 8), file);
88      fputc((UINT8)(m_display_list_ram[i] >> 0), file);
89   }
90   fclose(file);
9191
9292   file = fopen("m3_culling_ram.bin","wb");
93    for (i=0; i < 0x100000; i++)
94    {
95        fputc((UINT8)(m_culling_ram[i] >> 24), file);
96        fputc((UINT8)(m_culling_ram[i] >> 16), file);
97        fputc((UINT8)(m_culling_ram[i] >> 8), file);
98        fputc((UINT8)(m_culling_ram[i] >> 0), file);
99    }
100    fclose(file);
93   for (i=0; i < 0x100000; i++)
94   {
95      fputc((UINT8)(m_culling_ram[i] >> 24), file);
96      fputc((UINT8)(m_culling_ram[i] >> 16), file);
97      fputc((UINT8)(m_culling_ram[i] >> 8), file);
98      fputc((UINT8)(m_culling_ram[i] >> 0), file);
99   }
100   fclose(file);
101101
102102   file = fopen("m3_polygon_ram.bin","wb");
103    for (i=0; i < 0x100000; i++)
104    {
105        fputc((UINT8)(m_polygon_ram[i] >> 24), file);
106        fputc((UINT8)(m_polygon_ram[i] >> 16), file);
107        fputc((UINT8)(m_polygon_ram[i] >> 8), file);
108        fputc((UINT8)(m_polygon_ram[i] >> 0), file);
109    }
110    fclose(file);
103   for (i=0; i < 0x100000; i++)
104   {
105      fputc((UINT8)(m_polygon_ram[i] >> 24), file);
106      fputc((UINT8)(m_polygon_ram[i] >> 16), file);
107      fputc((UINT8)(m_polygon_ram[i] >> 8), file);
108      fputc((UINT8)(m_polygon_ram[i] >> 0), file);
109   }
110   fclose(file);
111111
112112   file = fopen("m3_vrom.bin","wb");
113    for (i=0; i < 0x1000000; i++)
114    {
115        fputc((UINT8)(m_vrom[i] >> 24), file);
116        fputc((UINT8)(m_vrom[i] >> 16), file);
117        fputc((UINT8)(m_vrom[i] >> 8), file);
118        fputc((UINT8)(m_vrom[i] >> 0), file);
119    }
120    fclose(file);
113   for (i=0; i < 0x1000000; i++)
114   {
115      fputc((UINT8)(m_vrom[i] >> 24), file);
116      fputc((UINT8)(m_vrom[i] >> 16), file);
117      fputc((UINT8)(m_vrom[i] >> 8), file);
118      fputc((UINT8)(m_vrom[i] >> 0), file);
119   }
120   fclose(file);
121121#endif
122122
123//   invalidate_texture(0, 0, 0, 6, 5);
124//   invalidate_texture(1, 0, 0, 6, 5);
123//  invalidate_texture(0, 0, 0, 6, 5);
124//  invalidate_texture(1, 0, 0, 6, 5);
125125}
126126
127127void model3_state::video_start()
r32760r32761
197197   init_matrix_stack();
198198}
199199
200#define MODEL3_TILE_INFO4(address)   \
200#define MODEL3_TILE_INFO4(address)  \
201201do { \
202   UINT16 *tiles = (UINT16*)&m_m3_tile_ram[address + (tile_index / 4)];   \
202   UINT16 *tiles = (UINT16*)&m_m3_tile_ram[address + (tile_index / 4)];    \
203203   UINT16 t = BYTE_REVERSE16(tiles[(tile_index & 3) ^ NATIVE_ENDIAN_VALUE_LE_BE(2,0)]); \
204204   int tile = ((t << 1) & 0x7ffe) | ((t >> 15) & 0x1); \
205205   int color = (t & 0x7ff0) >> 4; \
206206   SET_TILE_INFO_MEMBER(0, tile, color, 0); \
207207} while (0)
208208
209#define MODEL3_TILE_INFO8(address)   \
209#define MODEL3_TILE_INFO8(address)  \
210210do { \
211   UINT16 *tiles = (UINT16*)&m_m3_tile_ram[address + (tile_index / 4)];   \
211   UINT16 *tiles = (UINT16*)&m_m3_tile_ram[address + (tile_index / 4)];    \
212212   UINT16 t = BYTE_REVERSE16(tiles[(tile_index & 3) ^ NATIVE_ENDIAN_VALUE_LE_BE(2,0)]); \
213213   int tile = ((t << 1) & 0x7ffe) | ((t >> 15) & 0x1); \
214214   int color = (t & 0x7f00) >> 8; \
r32760r32761
400400}
401401
402402/*
403   Video registers:
403    Video registers:
404404
405   0xF1180000:         ?
406   0xF1180004:         ?
407   0xF1180008:         ?
405    0xF1180000:         ?
406    0xF1180004:         ?
407    0xF1180008:         ?
408408
409   0xF1180010:                                    VBL IRQ acknowledge
409    0xF1180010:                                             VBL IRQ acknowledge
410410
411   0xF1180020:         -------- x------- -------- -------- Layer 3 bitdepth (0 = 8-bit, 1 = 4-bit)
412                  -------- -x------ -------- -------- Layer 2 bitdepth (0 = 8-bit, 1 = 4-bit)
413                  -------- --x----- -------- -------- Layer 1 bitdepth (0 = 8-bit, 1 = 4-bit)
414                  -------- ---x---- -------- -------- Layer 0 bitdepth (0 = 8-bit, 1 = 4-bit)
415                  -------- ----x--- -------- -------- Layer 3 priority (0 = below 3D, 1 = above 3D)
416                  -------- -----x-- -------- -------- Layer 2 priority (0 = below 3D, 1 = above 3D)
417                  -------- ------x- -------- -------- Layer 1 priority (0 = below 3D, 1 = above 3D)
418                  -------- -------x -------- -------- Layer 0 priority (0 = below 3D, 1 = above 3D)
411    0xF1180020:         -------- x------- -------- -------- Layer 3 bitdepth (0 = 8-bit, 1 = 4-bit)
412                        -------- -x------ -------- -------- Layer 2 bitdepth (0 = 8-bit, 1 = 4-bit)
413                        -------- --x----- -------- -------- Layer 1 bitdepth (0 = 8-bit, 1 = 4-bit)
414                        -------- ---x---- -------- -------- Layer 0 bitdepth (0 = 8-bit, 1 = 4-bit)
415                        -------- ----x--- -------- -------- Layer 3 priority (0 = below 3D, 1 = above 3D)
416                        -------- -----x-- -------- -------- Layer 2 priority (0 = below 3D, 1 = above 3D)
417                        -------- ------x- -------- -------- Layer 1 priority (0 = below 3D, 1 = above 3D)
418                        -------- -------x -------- -------- Layer 0 priority (0 = below 3D, 1 = above 3D)
419419
420   0xF1180040:                                    Foreground layer color modulation?
421                  -------- xxxxxxxx -------- -------- Red component
422                  -------- -------- xxxxxxxx -------- Green component
423                  -------- -------- -------- xxxxxxxx Blue component
420    0xF1180040:                                             Foreground layer color modulation?
421                        -------- xxxxxxxx -------- -------- Red component
422                        -------- -------- xxxxxxxx -------- Green component
423                        -------- -------- -------- xxxxxxxx Blue component
424424
425   0xF1180044:                                    Background layer color modulation?
426                  -------- xxxxxxxx -------- -------- Red component
427                  -------- -------- xxxxxxxx -------- Green component
428                  -------- -------- -------- xxxxxxxx Blue component
425    0xF1180044:                                             Background layer color modulation?
426                        -------- xxxxxxxx -------- -------- Red component
427                        -------- -------- xxxxxxxx -------- Green component
428                        -------- -------- -------- xxxxxxxx Blue component
429429
430   0xF1180060:         x------- -------- -------- -------- Layer 0 enable
431                  -------x xxxxxxxx -------- -------- Layer 0 Y scroll position
432                  -------- -------- -------x xxxxxxxx Layer 0 X scroll position
430    0xF1180060:         x------- -------- -------- -------- Layer 0 enable
431                        -------x xxxxxxxx -------- -------- Layer 0 Y scroll position
432                        -------- -------- -------x xxxxxxxx Layer 0 X scroll position
433433
434   0xF1180064:         x------- -------- -------- -------- Layer 1 enable
435                  -------x xxxxxxxx -------- -------- Layer 1 Y scroll position
436                  -------- -------- -------x xxxxxxxx Layer 1 X scroll position
434    0xF1180064:         x------- -------- -------- -------- Layer 1 enable
435                        -------x xxxxxxxx -------- -------- Layer 1 Y scroll position
436                        -------- -------- -------x xxxxxxxx Layer 1 X scroll position
437437
438   0xF1180068:         x------- -------- -------- -------- Layer 2 enable
439                  -------x xxxxxxxx -------- -------- Layer 2 Y scroll position
440                  -------- -------- -------x xxxxxxxx Layer 2 X scroll position
438    0xF1180068:         x------- -------- -------- -------- Layer 2 enable
439                        -------x xxxxxxxx -------- -------- Layer 2 Y scroll position
440                        -------- -------- -------x xxxxxxxx Layer 2 X scroll position
441441
442   0xF118006C:         x------- -------- -------- -------- Layer 3 enable
443                  -------x xxxxxxxx -------- -------- Layer 3 Y scroll position
444                  -------- -------- -------x xxxxxxxx Layer 3 X scroll position
442    0xF118006C:         x------- -------- -------- -------- Layer 3 enable
443                        -------x xxxxxxxx -------- -------- Layer 3 Y scroll position
444                        -------- -------- -------x xxxxxxxx Layer 3 X scroll position
445445*/
446446
447447
r32760r32761
634634/* Real3D Graphics stuff */
635635
636636/*
637   Real3D Pro-1000 capabilities:
637    Real3D Pro-1000 capabilities:
638638
639   Coordinate sets
640   - 4096 matrices (matrix base pointer in viewport node)
639    Coordinate sets
640    - 4096 matrices (matrix base pointer in viewport node)
641641
642   Polygons
643   - 32MB max polygon memory. VROM in Model 3, the low 4MB of VROM is overlaid by Polygon RAM for runtime generated content.
642    Polygons
643    - 32MB max polygon memory. VROM in Model 3, the low 4MB of VROM is overlaid by Polygon RAM for runtime generated content.
644644
645   Texture
646   - 2 texture sheets of 2048x1024
647   - Mipmaps located in the bottom right corner
648   - Texture size 32x32 to 1024x1024
649   - Microtextures (is this featured in Model 3?)
645    Texture
646    - 2 texture sheets of 2048x1024
647    - Mipmaps located in the bottom right corner
648    - Texture size 32x32 to 1024x1024
649    - Microtextures (is this featured in Model 3?)
650650
651   LODs
652   - 127 blend types per viewport with 4 sets of min/max angle or range (where is this in the viewport node?)
651    LODs
652    - 127 blend types per viewport with 4 sets of min/max angle or range (where is this in the viewport node?)
653653
654   Lighting
655   - Self-luminous lighting (enable and luminosity parameter in polygon structure)
656   - Fixed polygon shading, fixed shading weight per vertex (not found in Model 3, yet)
657   - Flat sun shading (lighting parameters in viewport node) needs a separate enable?
658   - Smooth polygon shading (lighting parameters in viewport, use vertex normals)
654    Lighting
655    - Self-luminous lighting (enable and luminosity parameter in polygon structure)
656    - Fixed polygon shading, fixed shading weight per vertex (not found in Model 3, yet)
657    - Flat sun shading (lighting parameters in viewport node) needs a separate enable?
658    - Smooth polygon shading (lighting parameters in viewport, use vertex normals)
659659
660   Gamma table
661   - 256 entry 8-bit table, possibly in Polygon RAM
660    Gamma table
661    - 256 entry 8-bit table, possibly in Polygon RAM
662662*/
663663
664664/*
665   Real3D Memory Structures:
666   
667   Culling Nodes:
668   - Located in Culling RAM (0x8E000000)
669   - Limit of 15 child nodes (nesting), not including polygon nodes
670   - Color table (is this featured in Model 3?)
665    Real3D Memory Structures:
671666
672   0x00:   -------- -------- ------xx -------- Viewport number 0-3
673         -------- -------- -------- ---xx--- Viewport priority
667    Culling Nodes:
668    - Located in Culling RAM (0x8E000000)
669    - Limit of 15 child nodes (nesting), not including polygon nodes
670    - Color table (is this featured in Model 3?)
674671
675   0x01:   Child node pointer (inherits parameters from this node)
676   0x02:   Sibling node pointer
677   0x03:   Unknown (float)
678   0x04:   Sun light vector Z-component (float)
679   0x05:   Sun light vector X-component (float)
680   0x06:   Sun light vector Y-component (float)
681   0x07:   Sun light intensity (float)
682   0x08:   Far Clip plane Z
683   0x09:   Far Clip plane Distance
684   0x0a:   Near Clip plane Z
685   0x0b:   Near Clip plane Distance
686   0x0c:   Left Clip plane Z
687   0x0d:   Left Clip plane X
688   0x0e:   Top Clip plane Z
689   0x0f:   Top Clip plane Y
690   0x10:   Right Clip plane Z
691   0x11:   Right Clip plane X
692   0x12:   Bottom Clip plane Z
693   0x13:   Bottom Clip plane Y
672    0x00:   -------- -------- ------xx -------- Viewport number 0-3
673            -------- -------- -------- ---xx--- Viewport priority
694674
695   0x14:   xxxxxxxx xxxxxxxx -------- -------- Viewport height (14.2 fixed-point)
696         -------- -------- xxxxxxxx xxxxxxxx Viewport width (14.2 fixed-point)
675    0x01:   Child node pointer (inherits parameters from this node)
676    0x02:   Sibling node pointer
677    0x03:   Unknown (float)
678    0x04:   Sun light vector Z-component (float)
679    0x05:   Sun light vector X-component (float)
680    0x06:   Sun light vector Y-component (float)
681    0x07:   Sun light intensity (float)
682    0x08:   Far Clip plane Z
683    0x09:   Far Clip plane Distance
684    0x0a:   Near Clip plane Z
685    0x0b:   Near Clip plane Distance
686    0x0c:   Left Clip plane Z
687    0x0d:   Left Clip plane X
688    0x0e:   Top Clip plane Z
689    0x0f:   Top Clip plane Y
690    0x10:   Right Clip plane Z
691    0x11:   Right Clip plane X
692    0x12:   Bottom Clip plane Z
693    0x13:   Bottom Clip plane Y
697694
698   0x15:   ?
699   0x16:   Matrix base pointer
700   0x17:   LOD blend type table pointer?      (seems to be 8x float per entry)
701   0x18:   ?
702   0x19:   ?
695    0x14:   xxxxxxxx xxxxxxxx -------- -------- Viewport height (14.2 fixed-point)
696            -------- -------- xxxxxxxx xxxxxxxx Viewport width (14.2 fixed-point)
703697
704   0x1a:   xxxxxxxx xxxxxxxx -------- -------- Viewport Y coordinate (12.4 fixed-point)
705         -------- -------- xxxxxxxx xxxxxxxx Viewport X coordinate (12.4 fixed-point)
698    0x15:   ?
699    0x16:   Matrix base pointer
700    0x17:   LOD blend type table pointer?       (seems to be 8x float per entry)
701    0x18:   ?
702    0x19:   ?
706703
707   0x1b:   Copy of word 0x00
708   0x1c:   ?
704    0x1a:   xxxxxxxx xxxxxxxx -------- -------- Viewport Y coordinate (12.4 fixed-point)
705            -------- -------- xxxxxxxx xxxxxxxx Viewport X coordinate (12.4 fixed-point)
709706
710   0x1d:   xxxxxxxx xxxxxxxx -------- -------- Spotlight Y size
711         -------- -------- xxxxxxxx xxxxxxxx Spotlight Y position (13.3 fixed-point?)
707    0x1b:   Copy of word 0x00
708    0x1c:   ?
712709
713   0x1e:   xxxxxxxx xxxxxxxx -------- -------- Spotlight X size
714         -------- -------- xxxxxxxx xxxxxxxx Spotlight X position (13.3 fixed-point?)
710    0x1d:   xxxxxxxx xxxxxxxx -------- -------- Spotlight Y size
711            -------- -------- xxxxxxxx xxxxxxxx Spotlight Y position (13.3 fixed-point?)
715712
716   0x1f:   Light extent (float)
713    0x1e:   xxxxxxxx xxxxxxxx -------- -------- Spotlight X size
714            -------- -------- xxxxxxxx xxxxxxxx Spotlight X position (13.3 fixed-point?)
717715
718   0x20:   xxxxxxxx -------- -------- -------- ?
719         -------- xxxxxxxx -------- -------- ?
720         -------- -------- --xxx--- -------- Light RGB (RGB111?)
721         -------- -------- -----xxx -------- Light RGB Fog (RGB111?)
722         -------- -------- -------- xxxxxxxx Scroll Fog (0.8 fixed-point?) What is this???
716    0x1f:   Light extent (float)
723717
724   0x21:   ?
725   0x22:   Fog Color (RGB888)
726   0x23:   Fog Density (float)
718    0x20:   xxxxxxxx -------- -------- -------- ?
719            -------- xxxxxxxx -------- -------- ?
720            -------- -------- --xxx--- -------- Light RGB (RGB111?)
721            -------- -------- -----xxx -------- Light RGB Fog (RGB111?)
722            -------- -------- -------- xxxxxxxx Scroll Fog (0.8 fixed-point?) What is this???
727723
728   0x24:   xxxxxxxx xxxxxxxx -------- -------- ?
729         -------- -------- xxxxxxxx -------- Sun light ambient (0.8 fixed-point)
730         -------- -------- -------- xxxxxxxx Scroll attenuation (0.8 fixed-point) What is this???
724    0x21:   ?
725    0x22:   Fog Color (RGB888)
726    0x23:   Fog Density (float)
731727
732   0x25:   Fog offset
733   0x26:   ?
734   0x27:   ?
735   0x28:   ?
736   0x29:   ?
737   0x2a:   ?
738   0x2b:   ?
739   0x2c:   ?
740   0x2d:   ?
741   0x2e:   ?
742   0x2f:   ?
728    0x24:   xxxxxxxx xxxxxxxx -------- -------- ?
729            -------- -------- xxxxxxxx -------- Sun light ambient (0.8 fixed-point)
730            -------- -------- -------- xxxxxxxx Scroll attenuation (0.8 fixed-point) What is this???
743731
732    0x25:   Fog offset
733    0x26:   ?
734    0x27:   ?
735    0x28:   ?
736    0x29:   ?
737    0x2a:   ?
738    0x2b:   ?
739    0x2c:   ?
740    0x2d:   ?
741    0x2e:   ?
742    0x2f:   ?
744743
745   Sub types:
746   LOD Culling Node. Up to 4 LODs.
747744
748   Articulated Part Culling Node (is this used by Model 3?)
749   - An Articulated Part culling node, or six degree–of–freedom node, is used to define
745    Sub types:
746    LOD Culling Node. Up to 4 LODs.
747
748    Articulated Part Culling Node (is this used by Model 3?)
749    - An Articulated Part culling node, or six degree?of?freedom node, is used to define
750750      geometry that can move relative to the parent coordinate set to which it is attached.
751751      Fifteen levels of coordinate set nesting (levels of articulation) are supported.
752   
753   Animation Culling Node
754   - Animation culling nodes are used to build a culling hierarchy for an object with different
752
753    Animation Culling Node
754    - Animation culling nodes are used to build a culling hierarchy for an object with different
755755      representations, or animation frames. which can be turned on and off by the
756756      application. Each child (culling node or polygon) added to an Animation culling node
757757      specifies the frame for which the child is valid.
758   
759   Instance Culling Node
760   - Instance culling nodes define the top of a shared display list segment that can be
761     referenced from other parts of the scene display list.
762758
763   Instance Reference Culling Node
764   - An Instance Reference node is considered a leaf node; its
765     "child" is the shared geometry segment. An Instance Reference may be attached to
766     a parent node and may not have any other children, but may have siblings.
759    Instance Culling Node
760    - Instance culling nodes define the top of a shared display list segment that can be
761      referenced from other parts of the scene display list.
767762
768   Point Light
769   - A Point Light is used to create an instance of a point luminous feature. The size,
763    Instance Reference Culling Node
764    - An Instance Reference node is considered a leaf node; its
765      "child" is the shared geometry segment. An Instance Reference may be attached to
766      a parent node and may not have any other children, but may have siblings.
767
768    Point Light
769    - A Point Light is used to create an instance of a point luminous feature. The size,
770770      feature type, and number of sides of the point light model may be customized.
771771
772   Instance Set
773   - An Instance Set is a culling node which defines a set of point features. Each feature
772    Instance Set
773    - An Instance Set is a culling node which defines a set of point features. Each feature
774774      is positioned individually. This type of culling node can be used to simulate particles.
775775
776776
777777
778   Instance Node?
778    Instance Node?
779779
780   0x00:   xxxxxxxx xxxxxxxx xxxxxx-- -------- Node number/ID?, num of bits unknown
781         -------- -------- -------- ---x---- This node applies translation, else matrix
782         -------- -------- -------- ----x--- LOD enable?
783         -------- -------- -------- -----x-- ?
784         -------- -------- -------- ------x- ?
785         -------- -------- -------- -------x ?
780    0x00:   xxxxxxxx xxxxxxxx xxxxxx-- -------- Node number/ID?, num of bits unknown
781            -------- -------- -------- ---x---- This node applies translation, else matrix
782            -------- -------- -------- ----x--- LOD enable?
783            -------- -------- -------- -----x-- ?
784            -------- -------- -------- ------x- ?
785            -------- -------- -------- -------x ?
786786
787   
788   0x01:   ? (not present on Step 1.0)
789   0x02:   ? (not present on Step 1.0)         Scud Race has 0x00000101
790787
791   0x03:   --x----- -------- -------- -------- ?
792         -------- -xxxxxxx xxxx---- -------- LOD?
793         -------- -------- ----xxxx xxxxxxxx Node matrix
794   
795   0x04:   Translation X coordinate
796   0x05:   Translation Y coordinate
797   0x06:   Translation Z coordinate
798   0x07:   Child node pointer
799   0x08:   Sibling node pointer
788    0x01:   ? (not present on Step 1.0)
789    0x02:   ? (not present on Step 1.0)         Scud Race has 0x00000101
800790
801   0x09:   xxxxxxxx xxxxxxxx -------- -------- Culling or sorting related?
802         -------- -------- xxxxxxxx xxxxxxxx Culling or sorting related?
791    0x03:   --x----- -------- -------- -------- ?
792            -------- -xxxxxxx xxxx---- -------- LOD?
793            -------- -------- ----xxxx xxxxxxxx Node matrix
803794
795    0x04:   Translation X coordinate
796    0x05:   Translation Y coordinate
797    0x06:   Translation Z coordinate
798    0x07:   Child node pointer
799    0x08:   Sibling node pointer
804800
805   Polygon Data
801    0x09:   xxxxxxxx xxxxxxxx -------- -------- Culling or sorting related?
802            -------- -------- xxxxxxxx xxxxxxxx Culling or sorting related?
806803
807   0x00:   -------- xxxxxxxx xxxxxx-- -------- Polygon ID
808         -------- -------- -------- -x------ 0 = Triangle, 1 = Quad
809         -------- -------- -------- ----x--- Vertex 3 shared from previous polygon
810         -------- -------- -------- -----x-- Vertex 2 shared from previous polygon
811         -------- -------- -------- ------x- Vertex 1 shared from previous polygon
812         -------- -------- -------- -------x Vertex 0 shared from previous polygon
813         xxxxxxxx -------- -------- x-xx---- ?
814         -------- -------- ------xx -------- Broken polygons in srally2 set these (a way to mark them for HW to not render?)
815804
816   0x01:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Polygon normal X coordinate (2.22 fixed point)
817         -------- -------- -------- -x------ UV format (0 = 13.3, 1 = 16.0)
818         -------- -------- -------- -----x-- If set, this is the last polygon
819         -------- -------- -------- x-xxx-xx ?
805    Polygon Data
820806
821   0x02:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Polygon normal Y coordinate (2.22 fixed point)
822         -------- -------- -------- ------x- Texture U mirror enable
823         -------- -------- -------- -------x Texture V mirror enable
824         -------- -------- -------- xxxxxx-- ?
807    0x00:   -------- xxxxxxxx xxxxxx-- -------- Polygon ID
808            -------- -------- -------- -x------ 0 = Triangle, 1 = Quad
809            -------- -------- -------- ----x--- Vertex 3 shared from previous polygon
810            -------- -------- -------- -----x-- Vertex 2 shared from previous polygon
811            -------- -------- -------- ------x- Vertex 1 shared from previous polygon
812            -------- -------- -------- -------x Vertex 0 shared from previous polygon
813            xxxxxxxx -------- -------- x-xx---- ?
814            -------- -------- ------xx -------- Broken polygons in srally2 set these (a way to mark them for HW to not render?)
825815
826   0x03:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Polygon normal Z coordinate (2.22 fixed point)
827         -------- -------- -------- --xxx--- Texture width (in 8-pixel tiles)
828         -------- -------- -------- -----xxx Texture height (in 8-pixel tiles)
816    0x01:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Polygon normal X coordinate (2.22 fixed point)
817            -------- -------- -------- -x------ UV format (0 = 13.3, 1 = 16.0)
818            -------- -------- -------- -----x-- If set, this is the last polygon
819            -------- -------- -------- x-xxx-xx ?
829820
830   0x04:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Color (RGB888)
831         -------- -------- -------- -x------ Texture page
832         -------- -------- -------- ---xxxxx Upper 5 bits of texture U coordinate
833         -------- -------- -------- x-x----- ?
821    0x02:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Polygon normal Y coordinate (2.22 fixed point)
822            -------- -------- -------- ------x- Texture U mirror enable
823            -------- -------- -------- -------x Texture V mirror enable
824            -------- -------- -------- xxxxxx-- ?
834825
835   0x05:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Specular color?
836         -------- -------- -------- x------- Low bit of texture U coordinate
837         -------- -------- -------- ---xxxxx Low 5 bits of texture V coordinate
838         -------- -------- -------- -xx----- ?
826    0x03:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Polygon normal Z coordinate (2.22 fixed point)
827            -------- -------- -------- --xxx--- Texture width (in 8-pixel tiles)
828            -------- -------- -------- -----xxx Texture height (in 8-pixel tiles)
839829
840   0x06:   x------- -------- -------- -------- Texture contour enable
841         -----x-- -------- -------- -------- Texture enable
842         -------- x------- -------- -------- 1 = disable transparency?
843         -------- -xxxxx-- -------- -------- Polygon transparency (0 = fully transparent)
844         -------- -------x -------- -------- 1 = disable lighting
845         -------- -------- xxxxx--- -------- Polygon luminosity
846         -------- -------- ------xx x------- Texture format
847         -------- -------- -------- -------x Alpha enable?
848         -xxxx-xx ------x- -----x-- -xxxxxx- ?
830    0x04:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Color (RGB888)
831            -------- -------- -------- -x------ Texture page
832            -------- -------- -------- ---xxxxx Upper 5 bits of texture U coordinate
833            -------- -------- -------- x-x----- ?
849834
835    0x05:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Specular color?
836            -------- -------- -------- x------- Low bit of texture U coordinate
837            -------- -------- -------- ---xxxxx Low 5 bits of texture V coordinate
838            -------- -------- -------- -xx----- ?
850839
851   Vertex entry
840    0x06:   x------- -------- -------- -------- Texture contour enable
841            -----x-- -------- -------- -------- Texture enable
842            -------- x------- -------- -------- 1 = disable transparency?
843            -------- -xxxxx-- -------- -------- Polygon transparency (0 = fully transparent)
844            -------- -------x -------- -------- 1 = disable lighting
845            -------- -------- xxxxx--- -------- Polygon luminosity
846            -------- -------- ------xx x------- Texture format
847            -------- -------- -------- -------x Alpha enable?
848            -xxxx-xx ------x- -----x-- -xxxxxx- ?
852849
853   0x00:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Vertex X coordinate (17.7 fixed-point in Step 1.0, 13.11 otherwise)
854         -------- -------- -------- xxxxxxxx Vertex normal X (offset from polygon normal)
855850
856   0x01:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Vertex Y coordinate
857         -------- -------- -------- xxxxxxxx Vertex normal Y
851    Vertex entry
858852
859   0x02:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Vertex Z coordinate
860         -------- -------- -------- xxxxxxxx Vertex normal Z
853    0x00:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Vertex X coordinate (17.7 fixed-point in Step 1.0, 13.11 otherwise)
854            -------- -------- -------- xxxxxxxx Vertex normal X (offset from polygon normal)
861855
862   0x03:   xxxxxxxx xxxxxxxx -------- -------- Vertex U coordinate
863         -------- -------- xxxxxxxx xxxxxxxx Vertex V coordinate
856    0x01:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Vertex Y coordinate
857            -------- -------- -------- xxxxxxxx Vertex normal Y
864858
859    0x02:   xxxxxxxx xxxxxxxx xxxxxxxx -------- Vertex Z coordinate
860            -------- -------- -------- xxxxxxxx Vertex normal Z
861
862    0x03:   xxxxxxxx xxxxxxxx -------- -------- Vertex U coordinate
863            -------- -------- xxxxxxxx xxxxxxxx Vertex V coordinate
864
865865*/
866866
867867
r32760r32761
891891
892892static const UINT8 texture_decode[64] =
893893{
894    0,  1,  4,  5,  8,  9, 12, 13,
895    2,  3,  6,  7, 10, 11, 14, 15,
894      0,  1,  4,  5,  8,  9, 12, 13,
895      2,  3,  6,  7, 10, 11, 14, 15,
896896   16, 17, 20, 21, 24, 25, 28, 29,
897897   18, 19, 22, 23, 26, 27, 30, 31,
898898   32, 33, 36, 37, 40, 41, 44, 45,
r32760r32761
10031003   m_texture_fifo_pos = 0;
10041004
10051005   m_renderer->clear_buffers();
1006   
1007   real3d_traverse_display_list();   
1006
1007   real3d_traverse_display_list();
10081008}
10091009
10101010void model3_state::real3d_display_list1_dma(UINT32 src, UINT32 dst, int length, int byteswap)
r32760r32761
10411041
10421042void model3_state::real3d_vrom_texture_dma(UINT32 src, UINT32 dst, int length, int byteswap)
10431043{
1044   address_space &space = m_maincpu->space(AS_PROGRAM);   
1044   address_space &space = m_maincpu->space(AS_PROGRAM);
10451045   if ((dst & 0xff) == 0)
10461046   {
10471047      for (int i=0; i < length; i+=12)
r32760r32761
12861286   MATRIX transform_matrix;
12871287   float center_x, center_y;
12881288
1289   if (m_step < 0x15)      // position coordinates are 17.7 fixed-point in Step 1.0
1289   if (m_step < 0x15)      // position coordinates are 17.7 fixed-point in Step 1.0
12901290      fixed_point_fraction = 1.0f / 128.0f;
1291   else               // 13.11 fixed-point in other Steps
1291   else                    // 13.11 fixed-point in other Steps
12921292      fixed_point_fraction = 1.0f / 2048.0f;
1293   
1293
12941294   get_top_matrix(&transform_matrix);
12951295
12961296   /* current viewport center coordinates on screen */
r32760r32761
13231323      if (header[1] & 0x4)
13241324         last_polygon = TRUE;
13251325
1326      if ((header[0] & 0x300) == 0x300)      // TODO: broken polygons in srally2 have these bits set
1326      if ((header[0] & 0x300) == 0x300)       // TODO: broken polygons in srally2 have these bits set
13271327         return;
13281328
13291329      num_vertices = (header[0] & 0x40) ? 4 : 3;
r32760r32761
13541354         vertex[vi].z = (float)((INT32)(zw) >> 8) * fixed_point_fraction;
13551355         vertex[vi].u = (UINT16)(model[index] >> 16);
13561356         vertex[vi].v = (UINT16)(model[index++]);
1357//         vertex[vi].nx = normal[0] + ((float)((INT8)(xw)) / 127.0f);
1358//         vertex[vi].ny = normal[1] + ((float)((INT8)(yw)) / 127.0f);
1359//         vertex[vi].nz = normal[2] + ((float)((INT8)(zw)) / 127.0f);
1357//          vertex[vi].nx = normal[0] + ((float)((INT8)(xw)) / 127.0f);
1358//          vertex[vi].ny = normal[1] + ((float)((INT8)(yw)) / 127.0f);
1359//          vertex[vi].nz = normal[2] + ((float)((INT8)(zw)) / 127.0f);
13601360
13611361         vertex[vi].nx = ((float)((INT8)(xw)) / 127.0f);
13621362         vertex[vi].ny = ((float)((INT8)(yw)) / 127.0f);
r32760r32761
14081408         // transform vertex normal
14091409         VECTOR3 n;
14101410         n[0] = (vertex[i].nx * transform_matrix[0][0]) +
1411               (vertex[i].ny * transform_matrix[1][0]) +
1412               (vertex[i].nz * transform_matrix[2][0]);
1411               (vertex[i].ny * transform_matrix[1][0]) +
1412               (vertex[i].nz * transform_matrix[2][0]);
14131413         n[0] *= m_coordinate_system[0][1];
14141414         n[1] = (vertex[i].nx * transform_matrix[0][1]) +
1415               (vertex[i].ny * transform_matrix[1][1]) +
1416               (vertex[i].nz * transform_matrix[2][1]);
1415               (vertex[i].ny * transform_matrix[1][1]) +
1416               (vertex[i].nz * transform_matrix[2][1]);
14171417         n[1] *= m_coordinate_system[1][2];
14181418         n[2] = (vertex[i].nx * transform_matrix[0][2]) +
1419               (vertex[i].ny * transform_matrix[1][2]) +
1420               (vertex[i].nz * transform_matrix[2][2]);
1419               (vertex[i].ny * transform_matrix[1][2]) +
1420               (vertex[i].nz * transform_matrix[2][2]);
14211421         n[2] *= m_coordinate_system[2][0];
14221422
14231423         // lighting
r32760r32761
14841484            int tex_height = (header[3] & 0x7);
14851485            int tex_format = (header[6] >> 7) & 0x7;
14861486
1487            if (tex_width >= 6 || tex_height >= 6)      // srally2 poly ram has degenerate polys with 2k tex size (cpu bug or intended?)
1487            if (tex_width >= 6 || tex_height >= 6)      // srally2 poly ram has degenerate polys with 2k tex size (cpu bug or intended?)
14881488               return;
14891489
14901490            texture = get_texture((header[4] & 0x40) ? 1 : 0, tex_x, tex_y, tex_width, tex_height, tex_format);
r32760r32761
17611761   cliprect.max_y = 383;
17621762
17631763   m_fb->fill(0x00000000, cliprect);
1764   
1764
17651765   float zvalue = 10000000000.0f;
17661766   m_zb->fill(*(int*)&zvalue, cliprect);
17671767}
r32760r32761
17791779   if (tri->param & TRI_PARAM_TEXTURE_ENABLE)
17801780   {
17811781      for (int i=0; i < 3; i++)
1782      {
1782      {
17831783         v[i].x = tri->v[i].x;
17841784         v[i].y = tri->v[i].y;
17851785         v[i].p[0] = tri->v[i].z;
17861786         v[i].p[1] = 1.0f / tri->v[i].z;
1787         v[i].p[2] = tri->v[i].u * 256.0f;      // 8 bits of subtexel precision for bilinear filtering
1787         v[i].p[2] = tri->v[i].u * 256.0f;       // 8 bits of subtexel precision for bilinear filtering
17881788         v[i].p[3] = tri->v[i].v * 256.0f;
1789         v[i].p[4] =   tri->v[i].i;
1789         v[i].p[4] = tri->v[i].i;
17901790      }
17911791
17921792      model3_polydata &extra = object_data_alloc();
r32760r32761
18211821         v[i].x = tri->v[i].x;
18221822         v[i].y = tri->v[i].y;
18231823         v[i].p[0] = tri->v[i].z;
1824         v[i].p[1] =   tri->v[i].i;
1824         v[i].p[1] = tri->v[i].i;
18251825      }
18261826
18271827      model3_polydata &extra = object_data_alloc();
r32760r32761
18811881   }
18821882}
18831883
1884#define TEX_FETCH_NOFILTER()                        \
1885do {                                          \
1886   float intz = 1.0f / ooz;                        \
1887   UINT32 u = uoz * intz;                           \
1888   UINT32 v = voz * intz;                           \
1889   UINT32 u1 = (u >> 8) & umask;                     \
1890   UINT32 v1 = (v >> 8) & vmask;                     \
1891   texel = texture->data[(v1 << width) + u1];            \
1884#define TEX_FETCH_NOFILTER()                                \
1885do {                                                        \
1886   float intz = 1.0f / ooz;                                \
1887   UINT32 u = uoz * intz;                                  \
1888   UINT32 v = voz * intz;                                  \
1889   UINT32 u1 = (u >> 8) & umask;                           \
1890   UINT32 v1 = (v >> 8) & vmask;                           \
1891   texel = texture->data[(v1 << width) + u1];              \
18921892} while(0);
18931893
1894#define TEX_FETCH_BILINEAR()                                       \
1895do {                                                         \
1896   float intz = 1.0f / ooz;                                       \
1897   UINT32 u = uoz * intz;                                          \
1898   UINT32 v = voz * intz;                                          \
1899   UINT32 u1 = (u >> 8) & umask;                                    \
1900   UINT32 v1 = (v >> 8) & vmask;                                    \
1901   UINT32 u2 = (u1 + 1) & umask;                                    \
1902   UINT32 v2 = (v1 + 1) & vmask;                                    \
1903   UINT32 pix00 = texture->data[(v1 << width) + u1];                     \
1904   UINT32 pix01 = texture->data[(v1 << width) + u2];                     \
1905   UINT32 pix10 = texture->data[(v2 << width) + u1];                     \
1906   UINT32 pix11 = texture->data[(v2 << width) + u2];                     \
1907   texel = rgba_bilinear_filter(pix00, pix01, pix10, pix11, u, v);            \
1894#define TEX_FETCH_BILINEAR()                                                    \
1895do {                                                                            \
1896   float intz = 1.0f / ooz;                                                    \
1897   UINT32 u = uoz * intz;                                                      \
1898   UINT32 v = voz * intz;                                                      \
1899   UINT32 u1 = (u >> 8) & umask;                                               \
1900   UINT32 v1 = (v >> 8) & vmask;                                               \
1901   UINT32 u2 = (u1 + 1) & umask;                                               \
1902   UINT32 v2 = (v1 + 1) & vmask;                                               \
1903   UINT32 pix00 = texture->data[(v1 << width) + u1];                           \
1904   UINT32 pix01 = texture->data[(v1 << width) + u2];                           \
1905   UINT32 pix10 = texture->data[(v2 << width) + u1];                           \
1906   UINT32 pix11 = texture->data[(v2 << width) + u2];                           \
1907   texel = rgba_bilinear_filter(pix00, pix01, pix10, pix11, u, v);             \
19081908} while(0);
19091909
19101910#if ENABLE_BILINEAR
r32760r32761
19891989
19901990         UINT32 fa = texel >> 24;
19911991         if (fa >= 0xf8)
1992         {           
1992         {
19931993            UINT32 r = ((texel & 0x00ff0000) * fa) >> 8;
19941994            UINT32 g = ((texel & 0x0000ff00) * fa) >> 8;
19951995            UINT32 b = ((texel & 0x000000ff) * fa) >> 8;
1996           
1996
19971997            UINT32 orig = fb[x];
1998           
1998
19991999            int minalpha = 255 - fa;
2000           
2000
20012001            r += ((orig & 0x00ff0000) * minalpha) >> 8;
20022002            g += ((orig & 0x0000ff00) * minalpha) >> 8;
20032003            b += ((orig & 0x000000ff) * minalpha) >> 8;
2004           
2004
20052005            fb[x] = 0xff000000 | (r & 0xff0000) | (g & 0xff00) | (b & 0xff);
20062006            zb[x] = z;
20072007         }
r32760r32761
20552055         r = (r * srctrans) >> 5;
20562056         g = (g * srctrans) >> 5;
20572057         b = (b * srctrans) >> 5;
2058         
2058
20592059         UINT32 orig = fb[x];
2060         
2060
20612061         r += ((orig & 0x00ff0000) * desttrans) >> 5;
20622062         g += ((orig & 0x0000ff00) * desttrans) >> 5;
20632063         b += ((orig & 0x000000ff) * desttrans) >> 5;
r32760r32761
20912091   float in = extent.param[4].start;
20922092   float inz = extent.param[4].dpdx;
20932093
2094//   int srctrans = polydata.transparency;
2095//   int desttrans = 32 - polydata.transparency;
2094//  int srctrans = polydata.transparency;
2095//  int desttrans = 32 - polydata.transparency;
20962096
20972097   UINT32 umask = (((polydata.texture_param & TRI_PARAM_TEXTURE_MIRROR_U) ? 64 : 32) << texture->width) - 1;
20982098   UINT32 vmask = (((polydata.texture_param & TRI_PARAM_TEXTURE_MIRROR_V) ? 64 : 32) << texture->height) - 1;
r32760r32761
21362136      in += inz;
21372137      z += dz;
21382138   }
2139}
No newline at end of file
2139}
trunk/src/mame/video/gtia.c
r32760r32761
131131{
132132   m_read_cb.resolve();
133133   m_write_cb.resolve();
134   
134
135135   save_item(NAME(m_r.m0pf));
136136   save_item(NAME(m_r.m1pf));
137137   save_item(NAME(m_r.m2pf));
r32760r32761
218218   save_item(NAME(m_h.vdelay_p1));
219219   save_item(NAME(m_h.vdelay_p2));
220220   save_item(NAME(m_h.vdelay_p3));
221   
221
222222   save_item(NAME(m_lumpf1));
223223   save_item(NAME(m_huepm0));
224224   save_item(NAME(m_huepm1));
r32760r32761
226226   save_item(NAME(m_huepm3));
227227   save_item(NAME(m_huepm4));
228228   save_item(NAME(m_huepf2));
229   save_item(NAME(m_huebk));   
229   save_item(NAME(m_huebk));
230230
231   save_item(NAME(m_color_lookup));   
231   save_item(NAME(m_color_lookup));
232232
233233   machine().save().register_postload(save_prepost_delegate(FUNC(gtia_device::gtia_postload), this));
234234}
r32760r32761
291291         m_r.but[i] = 1;
292292      m_r.but[i] &= BIT(button_port, i);
293293   }
294   
294
295295   /* button registers for xl/xe */
296296   if (button_count == 2)
297297   {
298298      m_r.but[2] = 1;  /* not used on xl/xe */
299299      m_r.but[3] = 0;  /* 1 if external cartridge is inserted */
300300   }
301   
301
302302}
303303
304304
r32760r32761
967967      player_render(m_h.grafp2, m_w.sizep2 + 1, GTIA_P2, &pmbits[m_w.hposp2]);
968968   if (m_h.grafp3)
969969      player_render(m_h.grafp3, m_w.sizep3 + 1, GTIA_P3, &pmbits[m_w.hposp3]);
970   
970
971971   if (m_h.grafm0)
972972      missile_render(m_h.grafm0, m_w.sizem + 1, GTIA_M0, &pmbits[m_w.hposm0]);
973973   if (m_h.grafm1)
trunk/src/mame/video/gtia.h
r32760r32761
127127public:
128128   // construction/destruction
129129   gtia_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
130   
130
131131   template<class _Object> static devcb_base &set_read_callback(device_t &device, _Object object) { return downcast<gtia_device &>(device).m_read_cb.set_callback(object); }
132132   template<class _Object> static devcb_base &set_write_callback(device_t &device, _Object object) { return downcast<gtia_device &>(device).m_write_cb.set_callback(object); }
133   
133
134134   DECLARE_READ8_MEMBER( read );
135135   DECLARE_WRITE8_MEMBER( write );
136136
r32760r32761
143143   UINT8 get_w_prior() { return m_w.prior; }
144144   void count_hitclr_frames() { m_h.hitclr_frames++; }
145145   void button_interrupt(int button_count, UINT8 button_port);
146   
146
147147   void render(UINT8 *src, UINT8 *dst, UINT8 *pmbits, UINT8 *prio);
148   
148
149149protected:
150150   // device-level overrides
151151   virtual void device_start();
152152   virtual void device_reset();
153   
153
154154   void gtia_postload();
155   
155
156156   int is_ntsc();
157157   void recalc_p0();
158158   void recalc_p1();
r32760r32761
162162   void recalc_m1();
163163   void recalc_m2();
164164   void recalc_m3();
165   
165
166166   inline void player_render(UINT8 gfx, int size, UINT8 color, UINT8 *dst);
167167   inline void missile_render(UINT8 gfx, int size, UINT8 color, UINT8 *dst);
168   
168
169169private:
170170   gtia_readregs   m_r;          /* read registers */
171171   gtia_writeregs  m_w;          /* write registers */
172172   gtia_helpervars m_h;          /* helper variables */
173   
173
174174   UINT8 m_lumpf1;
175175   UINT8 m_huepm0, m_huepm1, m_huepm2, m_huepm3, m_huepm4;
176176   UINT8 m_huepf2, m_huebk;
177   
178   UINT16 m_color_lookup[256];  /* color lookup table */   // probably better fit to ANTIC, but it remains here for the moment...
179   
177
178   UINT16 m_color_lookup[256];  /* color lookup table */   // probably better fit to ANTIC, but it remains here for the moment...
179
180180   devcb_read8 m_read_cb;
181181   devcb_write8 m_write_cb;
182182};
trunk/src/mame/video/antic.c
r32760r32761
5858{
5959   m_gtia = machine().device<gtia_device>(m_gtia_tag);
6060   assert(m_gtia);
61   
61
6262   m_bitmap = auto_bitmap_ind16_alloc(machine(), machine().first_screen()->width(), machine().first_screen()->height());
63   
63
6464   m_cclk_expand = auto_alloc_array_clear(machine(), UINT32, 21 * 256);
65   
65
6666   m_pf_21       = &m_cclk_expand[ 0 * 256];
6767   m_pf_x10b     = &m_cclk_expand[ 1 * 256];
6868   m_pf_3210b2   = &m_cclk_expand[ 3 * 256];
r32760r32761
7272   m_pf_gtia1    = &m_cclk_expand[18 * 256];
7373   m_pf_gtia2    = &m_cclk_expand[19 * 256];
7474   m_pf_gtia3    = &m_cclk_expand[20 * 256];
75   
75
7676   m_used_colors = auto_alloc_array(machine(), UINT8, 21 * 256);
77   
77
7878   memset(m_used_colors, 0, 21 * 256 * sizeof(UINT8));
79   
79
8080   m_uc_21       = &m_used_colors[ 0 * 256];
8181   m_uc_x10b     = &m_used_colors[ 1 * 256];
8282   m_uc_3210b2   = &m_used_colors[ 3 * 256];
r32760r32761
8686   m_uc_g1       = &m_used_colors[18 * 256];
8787   m_uc_g2       = &m_used_colors[19 * 256];
8888   m_uc_g3       = &m_used_colors[20 * 256];
89   
89
9090   LOG(("atari cclk_init\n"));
9191   cclk_init();
92   
92
9393   for (int i = 0; i < 64; i++)
9494      m_prio_table[i] = auto_alloc_array_clear(machine(), UINT8, 8*256);
95   
95
9696   LOG(("atari prio_init\n"));
9797   prio_init();
98   
98
9999   for (int i = 0; i < machine().first_screen()->height(); i++)
100100      m_video[i] = auto_alloc_clear(machine(), VIDEO);
101   
101
102102   /* save states */
103103   save_pointer(NAME((UINT8 *) &m_r), sizeof(m_r));
104104   save_pointer(NAME((UINT8 *) &m_w), sizeof(m_w));
105105   // TODO: save VIDEO items
106   
106
107107   save_item(NAME(m_tv_artifacts));
108108   save_item(NAME(m_render1));
109109   save_item(NAME(m_render2));
r32760r32761
556556{
557557   int i, j, pm, p, c;
558558   const UINT8 * prio;
559   
559
560560   /* 32 priority bit combinations */
561561   for( i = 0; i < 32; i++ )
562562   {
r32760r32761
575575            }
576576            m_prio_table[i][(j << 8) + pm] = c;
577577            if( (c==PL0 || c==P000 || c==P001 || c==P010 || c==P011) &&
578               (pm & (P0+P1))==(P0+P1))
578               (pm & (P0+P1))==(P0+P1))
579579               c = EOR;
580580            if( (c==PL2 || c==P200 || c==P201 || c==P210 || c==P211) &&
581               (pm & (P2+P3))==(P2+P3))
581               (pm & (P2+P3))==(P2+P3))
582582               c = EOR;
583583            m_prio_table[32 + i][(j << 8) + pm] = c;
584584         }
r32760r32761
598598   static const UINT8 _pf_310b[4] = {PBK,PF0,PF1,PF3};
599599   int i;
600600   UINT8 * dst;
601   
601
602602   /* setup color translation for the ANTIC modes */
603603   for( i = 0; i < 256; i++ )
604604   {
r32760r32761
608608      *dst++ = _pf_21[(i>>4)&3];
609609      *dst++ = _pf_21[(i>>2)&3];
610610      *dst++ = _pf_21[(i>>0)&3];
611     
611
612612      /****** 4 color text (4,5) with pf2, D, E **********/
613613      dst = (UINT8 *)&m_pf_x10b[0x000+i];
614614      *dst++ = _pf_210b[(i>>6)&3];
r32760r32761
620620      *dst++ = _pf_310b[(i>>4)&3];
621621      *dst++ = _pf_310b[(i>>2)&3];
622622      *dst++ = _pf_310b[(i>>0)&3];
623     
623
624624      /****** pf0 color text (6,7), 9, B, C **********/
625625      dst = (UINT8 *)&m_pf_3210b2[0x000+i*2];
626626      *dst++ = (i&0x80)?PF0:PBK;
r32760r32761
631631      *dst++ = (i&0x04)?PF0:PBK;
632632      *dst++ = (i&0x02)?PF0:PBK;
633633      *dst++ = (i&0x01)?PF0:PBK;
634     
634
635635      /****** pf1 color text (6,7), 9, B, C **********/
636636      dst = (UINT8 *)&m_pf_3210b2[0x200+i*2];
637637      *dst++ = (i&0x80)?PF1:PBK;
r32760r32761
642642      *dst++ = (i&0x04)?PF1:PBK;
643643      *dst++ = (i&0x02)?PF1:PBK;
644644      *dst++ = (i&0x01)?PF1:PBK;
645     
645
646646      /****** pf2 color text (6,7), 9, B, C **********/
647647      dst = (UINT8 *)&m_pf_3210b2[0x400+i*2];
648648      *dst++ = (i&0x80)?PF2:PBK;
r32760r32761
653653      *dst++ = (i&0x04)?PF2:PBK;
654654      *dst++ = (i&0x02)?PF2:PBK;
655655      *dst++ = (i&0x01)?PF2:PBK;
656     
656
657657      /****** pf3 color text (6,7), 9, B, C **********/
658658      dst = (UINT8 *)&m_pf_3210b2[0x600+i*2];
659659      *dst++ = (i&0x80)?PF3:PBK;
r32760r32761
664664      *dst++ = (i&0x04)?PF3:PBK;
665665      *dst++ = (i&0x02)?PF3:PBK;
666666      *dst++ = (i&0x01)?PF3:PBK;
667     
667
668668      /****** 4 color graphics 4 cclks (8) **********/
669669      dst = (UINT8 *)&m_pf_210b4[i*4];
670670      *dst++ = _pf_210b[(i>>6)&3];
r32760r32761
683683      *dst++ = _pf_210b[(i>>0)&3];
684684      *dst++ = _pf_210b[(i>>0)&3];
685685      *dst++ = _pf_210b[(i>>0)&3];
686     
686
687687      /****** 4 color graphics 2 cclks (A) **********/
688688      dst = (UINT8 *)&m_pf_210b2[i*2];
689689      *dst++ = _pf_210b[(i>>6)&3];
r32760r32761
694694      *dst++ = _pf_210b[(i>>2)&3];
695695      *dst++ = _pf_210b[(i>>0)&3];
696696      *dst++ = _pf_210b[(i>>0)&3];
697     
697
698698      /****** high resolution graphics (F) **********/
699699      dst = (UINT8 *)&m_pf_1b[i];
700700      *dst++ = _pf_1b[(i>>6)&3];
701701      *dst++ = _pf_1b[(i>>4)&3];
702702      *dst++ = _pf_1b[(i>>2)&3];
703703      *dst++ = _pf_1b[(i>>0)&3];
704     
704
705705      /****** gtia mode 1 **********/
706706      dst = (UINT8 *)&m_pf_gtia1[i];
707707      *dst++ = GT1+((i>>4)&15);
708708      *dst++ = GT1+((i>>4)&15);
709709      *dst++ = GT1+(i&15);
710710      *dst++ = GT1+(i&15);
711     
711
712712      /****** gtia mode 2 **********/
713713      dst = (UINT8 *)&m_pf_gtia2[i];
714714      *dst++ = GT2+((i>>4)&15);
715715      *dst++ = GT2+((i>>4)&15);
716716      *dst++ = GT2+(i&15);
717717      *dst++ = GT2+(i&15);
718     
718
719719      /****** gtia mode 3 **********/
720720      dst = (UINT8 *)&m_pf_gtia3[i];
721721      *dst++ = GT3+((i>>4)&15);
722722      *dst++ = GT3+((i>>4)&15);
723723      *dst++ = GT3+(i&15);
724724      *dst++ = GT3+(i&15);
725     
725
726726   }
727   
727
728728   /* setup used color tables */
729729   for( i = 0; i < 256; i++ )
730730   {
731731      /* used colors in text modes 2,3 */
732732      m_uc_21[i] = (i) ? PF2 | PF1 : PF2;
733     
733
734734      /* used colors in text modes 4,5 and graphics modes D,E */
735735      switch( i & 0x03 )
736736      {
r32760r32761
756756         case 0x80: m_uc_x10b[0x000+i] |= PF1; m_uc_x10b[0x100+i] |= PF1; break;
757757         case 0xc0: m_uc_x10b[0x000+i] |= PF2; m_uc_x10b[0x100+i] |= PF3; break;
758758      }
759     
759
760760      /* used colors in text modes 6,7 and graphics modes 9,B,C */
761761      if( i )
762762      {
r32760r32761
765765         m_uc_3210b2[0x400+i*2] |= PF2;
766766         m_uc_3210b2[0x600+i*2] |= PF3;
767767      }
768     
768
769769      /* used colors in graphics mode 8 */
770770      switch( i & 0x03 )
771771      {
r32760r32761
791791         case 0x80: m_uc_210b4[i*4] |= PF1; break;
792792         case 0xc0: m_uc_210b4[i*4] |= PF2; break;
793793      }
794     
794
795795      /* used colors in graphics mode A */
796796      switch( i & 0x03 )
797797      {
r32760r32761
817817         case 0x80: m_uc_210b2[i*2] |= PF1; break;
818818         case 0xc0: m_uc_210b2[i*2] |= PF2; break;
819819      }
820     
820
821821      /* used colors in graphics mode F */
822822      if( i )
823823         m_uc_1b[i] |= PF1;
824     
824
825825      /* used colors in GTIA graphics modes */
826826      /* GTIA 1 is 16 different luminances with hue of colbk */
827827      m_uc_g1[i] = 0x00;
r32760r32761
838838         case 0x07: m_uc_g2[i] = 0x08; break;
839839         default:   m_uc_g2[i] = 0x00;
840840      }
841     
841
842842      /* GTIA 3 is 16 different hues with luminance of colbk */
843843      m_uc_g3[i] = 0x00;
844844   }
r32760r32761
12931293{
12941294   VIDEO *video = m_video[m_scanline];
12951295   int add_bytes = 0, erase = 0;
1296   
1296
12971297   if (param3 == 0 || param2 <= 1)
12981298   {
12991299      mode_0(space, video);
13001300      return;
13011301   }
1302   
1302
13031303   if ((param3 == 1 || param3 == 2) && param1)
13041304      param3++;
1305   
1305
13061306   switch (param3)
13071307   {
13081308      case 1:
r32760r32761
13181318         erase = 0;
13191319         break;
13201320   }
1321   
1321
13221322   switch (param2)
13231323   {
13241324      case 0x02:
r32760r32761
13871387{
13881388   UINT32 new_tv_artifacts = screen.ioport("artifacts")->read_safe(0);
13891389   copybitmap(bitmap, *m_bitmap, 0, 0, 0, 0, cliprect);
1390   
1390
13911391   if (m_tv_artifacts != new_tv_artifacts)
13921392      m_tv_artifacts = new_tv_artifacts;
1393   
1393
13941394   return 0;
13951395}
13961396
r32760r32761
14041404   UINT8 atari_C = b + c;
14051405   UINT8 atari_D = m_gtia->get_w_colbk();
14061406   UINT16 *color_lookup = m_gtia->get_color_lookup();
1407   
1407
14081408   for (int x = 0; x < width * 4; x++)
14091409   {
14101410      n = *src++;
r32760r32761
14781478   UINT8 atari_C = b+c;
14791479   UINT8 atari_D = m_gtia->get_w_colpf2();
14801480   UINT16 *color_lookup = m_gtia->get_color_lookup();
1481   
1481
14821482   for (int x = 0; x < width * 4; x++)
14831483   {
14841484      n = *src++;
r32760r32761
15501550   UINT32 *dst;
15511551   UINT32 scanline[4 + (HCHARS * 2) + 4];
15521552   UINT16 *color_lookup = m_gtia->get_color_lookup();
1553   
1553
15541554   /* increment the scanline */
15551555   if( ++m_scanline == machine().first_screen()->height() )
15561556   {
r32760r32761
15601560      /* count frames gone since last write to hitclr */
15611561      m_gtia->count_hitclr_frames();
15621562   }
1563   
1563
15641564   if( m_scanline < MIN_Y || m_scanline > MAX_Y )
15651565      return;
1566   
1566
15671567   y = m_scanline - MIN_Y;
15681568   src = &m_cclock[PMOFFSET - m_hscrol_old + 12];
15691569   dst = scanline;
1570   
1570
15711571   if( m_tv_artifacts )
15721572   {
15731573      if( (m_cmd & 0x0f) == 2 || (m_cmd & 0x0f) == 3 )
r32760r32761
16481648   dst[1] = color_lookup[PBK] | color_lookup[PBK] << 16;
16491649   dst[2] = color_lookup[PBK] | color_lookup[PBK] << 16;
16501650   dst[3] = color_lookup[PBK] | color_lookup[PBK] << 16;
1651   
1651
16521652   draw_scanline8(*m_bitmap, 12, y, MIN(m_bitmap->width() - 12, sizeof(scanline)), (const UINT8 *) scanline, NULL);
16531653}
16541654
16551655
1656#define ANTIC_TIME_FROM_CYCLES(cycles)   \
1656#define ANTIC_TIME_FROM_CYCLES(cycles)  \
16571657(attotime)(machine().first_screen()->scan_period() * (cycles) / CYCLES_PER_LINE)
16581658
16591659void antic_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
r32760r32761
17141714   LOG(("           @cycle #%3d release CPU\n", cycle()));
17151715   /* release the CPU (held for emulating cycles stolen by ANTIC DMA) */
17161716   machine().scheduler().trigger(TRIGGER_STEAL);
1717   
1717
17181718   /* refresh the display (translate color clocks to pixels) */
17191719   linerefresh();
17201720}
r32760r32761
17481748TIMER_CALLBACK_MEMBER( antic_device::scanline_render )
17491749{
17501750   address_space &space = machine().device("maincpu")->memory().space(AS_PROGRAM);
1751   
1751
17521752   LOG(("           @cycle #%3d render mode $%X lines to go #%d\n", cycle(), (m_cmd & 0x0f), m_modelines));
1753   
1753
17541754   render(space, m_render1, m_render2, m_render3);
1755   
1755
17561756   /* if player/missile graphics is enabled */
17571757   if( m_scanline < 256 && (m_w.dmactl & (DMA_PLAYER|DMA_MISSILE)) )
17581758   {
r32760r32761
17961796         }
17971797      }
17981798   }
1799   
1799
18001800   if (m_scanline >= VBL_END && m_scanline < 256)
18011801      m_gtia->render((UINT8 *)m_pmbits + PMOFFSET, (UINT8 *)m_cclock + PMOFFSET - m_hscrol_old, (UINT8 *)m_prio_table[m_gtia->get_w_prior() & 0x3f], (UINT8 *)&m_pmbits);
1802   
1802
18031803   m_steal_cycles += CYCLES_REFRESH;
18041804   LOG(("           run CPU for %d cycles\n", CYCLES_HSYNC - CYCLES_HSTART - m_steal_cycles));
18051805   timer_set(ANTIC_TIME_FROM_CYCLES(CYCLES_HSYNC - CYCLES_HSTART - m_steal_cycles), TIMER_CYCLE_STEAL);
r32760r32761
18561856            m_render3 = m_w.dmactl & 3;
18571857            UINT8 vscrol_subtract = 0;
18581858            UINT8 new_cmd;
1859           
1859
18601860            new_cmd = RDANTIC(space);
18611861            m_doffs = (m_doffs + 1) & DOFFS;
18621862            /* steal at one clock cycle from the CPU for fetching the command */
r32760r32761
18941894            }
18951895            /* Set the ANTIC mode renderer function */
18961896            m_render2 = new_cmd & ANTIC_MODE;
1897           
1897
18981898            switch( new_cmd & ANTIC_MODE )
18991899            {
19001900               case 0x00:
r32760r32761
20482048      m_render2 = 0;
20492049      m_render3 = 0;
20502050   }
2051   
2051
20522052   m_r.nmist &= ~DLI_NMI;
20532053   if (m_modelines == 1 && (m_cmd & m_w.nmien & DLI_NMI))
20542054      timer_set(ANTIC_TIME_FROM_CYCLES(CYCLES_DLI_NMI), TIMER_ISSUE_DLI);
2055   
2055
20562056   timer_set(ANTIC_TIME_FROM_CYCLES(CYCLES_HSTART), TIMER_LINE_REND);
20572057}
20582058
r32760r32761
20682068void antic_device::generic_interrupt(int button_count)
20692069{
20702070   LOG(("ANTIC #%3d @cycle #%d scanline interrupt\n", m_scanline, cycle()));
2071   
2071
20722072   if( m_scanline < VBL_START )
20732073   {
20742074      scanline_dma(0);
20752075      return;
20762076   }
2077   
2077
20782078   if( m_scanline == VBL_START )
20792079   {
20802080      /* specify buttons relevant to this Atari variant */
20812081      m_gtia->button_interrupt(button_count, machine().root_device().ioport("djoy_b")->read_safe(0));
2082     
2082
20832083      /* do nothing new for the rest of the frame */
20842084      m_modelines = machine().first_screen()->height() - VBL_START;
20852085      m_render1 = 0;
20862086      m_render2 = 0;
20872087      m_render3 = 0;
2088     
2088
20892089      /* if the CPU want's to be interrupted at vertical blank... */
20902090      if( m_w.nmien & VBL_NMI )
20912091      {
r32760r32761
20952095         machine().device("maincpu")->execute().set_input_line(INPUT_LINE_NMI, PULSE_LINE);
20962096      }
20972097   }
2098   
2098
20992099   /* refresh the display (translate color clocks to pixels) */
21002100   linerefresh();
21012101}
2102
trunk/src/mame/video/antic.h
r32760r32761
33    Atari 400/800
44
55    ANTIC video controller
6
6
77    Juergen Buchmueller, June 1998
88
99***************************************************************************/
r32760r32761
293293      m_w.chbasl++
294294
295295/* erase a number of color clocks to background color PBK */
296#define ERASE(size)                     \
297   for (int i = 0; i < size; i++)         \
298   {                              \
296#define ERASE(size)                         \
297   for (int i = 0; i < size; i++)          \
298   {                                       \
299299      *dst++ = (PBK << 24) | (PBK << 16) | (PBK << 8) | PBK;  \
300   }                              \
301
300   }
302301#define ZAP48()                                                 \
303302   dst = (UINT32 *)&antic.cclock[PMOFFSET];                    \
304303   dst[ 0] = (PBK << 24) | (PBK << 16) | (PBK << 8) | PBK;     \
r32760r32761
309308   dst[47] = (PBK << 24) | (PBK << 16) | (PBK << 8) | PBK
310309
311310#define REP(FUNC, size)                     \
312   for (int i = 0; i < size; i++)         \
313   {                              \
314      FUNC(i);                     \
315   }                              \
311   for (int i = 0; i < size; i++)          \
312   {                                       \
313      FUNC(i);                            \
314   }
316315
317316
318
319317struct ANTIC_R {
320318   UINT8   antic00;    /* 00 nothing */
321319   UINT8   antic01;    /* 01 nothing */
r32760r32761
379377
380378   UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
381379   void generic_interrupt(int button_count);
382   
380
383381private:
384382   static const device_timer_id TIMER_CYCLE_STEAL = 0;
385383   static const device_timer_id TIMER_ISSUE_DLI = 1;
r32760r32761
454452   UINT8   *m_uc_g2;             /* used colors for gfx GTIA 2 */
455453   UINT8   *m_uc_g3;             /* used colors for gfx GTIA 3 */
456454   bitmap_ind16 *m_bitmap;
457   
455
458456   void prio_init();
459457   void cclk_init();
460458
trunk/src/mame/layout/s11a.lay
r32760r32761
11<!-- s11a.lay -->
22
33<!-- 2012-11-04: Initial version.  [Robbbert]
4     2012-12-19: Rearranged layout, replaced diagnostic 7-digit LED with 3 single LEDs  [Barry Rodewald]-->
4      2012-12-19: Rearranged layout, replaced diagnostic 7-digit LED with 3 single LEDs  [Barry Rodewald]-->
55
66<mamelayout version="2">
77
trunk/src/mame/layout/mgavegas.lay
r32760r32761
3535
3636   <element name="P12"><text string="500"><color red="1.0" green="1.0" blue="1.0" /></text></element>
3737   <element name="P13"><text string="300"><color red="1.0" green="1.0" blue="1.0" /></text></element>
38   <element name="P14"><text string="200"><color red="1.0" green="1.0" blue="1.0" /></text></element>   
38   <element name="P14"><text string="200"><color red="1.0" green="1.0" blue="1.0" /></text></element>
3939   <element name="P15"><text string="100"><color red="1.0" green="1.0" blue="1.0" /></text></element>
40   
40
4141   <element name="P16"><text string="INSERT COIN"><color red="1.0" green="1.0" blue="1.0" /></text></element>
42   <element name="P17"><text string="NO CAMBIO"><color red="1.0" green="1.0" blue="1.0" /></text></element>   
42   <element name="P17"><text string="NO CAMBIO"><color red="1.0" green="1.0" blue="1.0" /></text></element>
4343   <element name="P18"><text string="FUSE"><color red="1.0" green="1.0" blue="1.0" /></text></element>
4444   <element name="P19"><text string="FALTA"><color red="1.0" green="1.0" blue="1.0" /></text></element>
45   
46   <element name="P20"><text string="MGA"><color red="1.0" green="1.0" blue="1.0" /></text></element>   
45
46   <element name="P20"><text string="MGA"><color red="1.0" green="1.0" blue="1.0" /></text></element>
4747   <element name="P21"><text string="50"><color red="1.0" green="1.0" blue="1.0" /></text></element>
4848   <element name="P22"><text string="MGA"><color red="1.0" green="1.0" blue="1.0" /></text></element>
4949   <element name="P23"><text string="25"><color red="1.0" green="1.0" blue="1.0" /></text></element>
50   <element name="P24"><text string="250"><color red="1.0" green="1.0" blue="1.0" /></text></element>   
50   <element name="P24"><text string="250"><color red="1.0" green="1.0" blue="1.0" /></text></element>
5151   <element name="P25"><text string="MGA"><color red="1.0" green="1.0" blue="1.0" /></text></element>
5252   <element name="P26"><text string="100"><color red="1.0" green="1.0" blue="1.0" /></text></element>
5353   <element name="P27"><text string="MGA"><color red="1.0" green="1.0" blue="1.0" /></text></element>
5454   <element name="P28"><text string="25"><color red="1.0" green="1.0" blue="1.0" /></text></element>
55   
55
5656   <element name="P29"><text string="Premio Sorpresa"><color red="1.0" green="1.0" blue="1.0" /></text></element>
5757
58   
58
5959   <view name="Default Layout">
6060
6161      <!-- Background -->
r32760r32761
7474      <bezel name="MR" element="red_led">
7575         <bounds x="360" y="50" width="5" height="5" />
7676      </bezel>
77     
77
7878      <bezel name="CL" element="red_led">
7979         <bounds x="280" y="100" width="5" height="5" />
8080      </bezel>
r32760r32761
103103      </bezel>
104104      <bezel name="PR" element="red_led">
105105         <bounds x="360" y="200" width="5" height="5" />
106      </bezel>     
107     
106      </bezel>
107
108108      <bezel name="500" element="red_led">
109109         <bounds x="410" y="50" width="5" height="5" />
110110      </bezel>
r32760r32761
113113      </bezel>
114114      <bezel name="200" element="red_led">
115115         <bounds x="410" y="150" width="5" height="5" />
116      </bezel>     
116      </bezel>
117117      <bezel name="100" element="red_led">
118118         <bounds x="410" y="200" width="5" height="5" />
119      </bezel>     
120     
119      </bezel>
120
121121      <bezel name="INSERTCOIN" element="red_led">
122122         <bounds x="270" y="250" width="5" height="5" />
123123      </bezel>
r32760r32761
126126      </bezel>
127127      <bezel name="FUSE" element="red_led">
128128         <bounds x="350" y="250" width="5" height="5" />
129      </bezel>     
129      </bezel>
130130      <bezel name="FALTA" element="red_led">
131131         <bounds x="400" y="250" width="5" height="5" />
132132      </bezel>
r32760r32761
139139      </bezel>
140140      <bezel name="MGA3" element="red_led">
141141         <bounds x="125" y="350" width="30" height="30" />
142      </bezel>     
142      </bezel>
143143      <bezel name="252" element="red_led">
144144         <bounds x="170" y="350" width="30" height="30" />
145145      </bezel>
r32760r32761
151151      </bezel>
152152      <bezel name="1002" element="red_led">
153153         <bounds x="305" y="350" width="30" height="30" />
154      </bezel>     
154      </bezel>
155155      <bezel name="MGA" element="red_led">
156156         <bounds x="350" y="350" width="30" height="30" />
157157      </bezel>
r32760r32761
159159         <bounds x="395" y="350" width="30" height="30" />
160160      </bezel>
161161
162     
162
163163      <bezel name="MGA4" element="red_led">
164164         <bounds x="40" y="50" width="5" height="5" />
165165      </bezel>
r32760r32761
168168      </bezel>
169169      <bezel name="MGA3" element="red_led">
170170         <bounds x="80" y="150" width="5" height="5" />
171      </bezel>     
171      </bezel>
172172      <bezel name="252" element="red_led">
173173         <bounds x="100" y="200" width="5" height="5" />
174174      </bezel>
r32760r32761
180180      </bezel>
181181      <bezel name="1002" element="red_led">
182182         <bounds x="160" y="150" width="5" height="5" />
183      </bezel>     
183      </bezel>
184184      <bezel name="MGA" element="red_led">
185185         <bounds x="180" y="100" width="5" height="5" />
186186      </bezel>
r32760r32761
191191      <bezel name="PREMIOS" element="red_led">
192192         <bounds x="220" y="150" width="10" height="10" />
193193      </bezel>
194     
195         
196     
194
195
196
197197      <bezel element="P0"><bounds left="350" right="370" top="20" bottom="40" /></bezel>
198198      <bezel element="P1"><bounds left="310" right="330" top="20" bottom="40" /></bezel>
199199      <bezel element="P2"><bounds left="270" right="290" top="20" bottom="40" /></bezel>
r32760r32761
219219      <bezel element="P17"><bounds left="310" right="330" top="220" bottom="240" /></bezel>
220220      <bezel element="P18"><bounds left="350" right="370" top="220" bottom="240" /></bezel>
221221      <bezel element="P19"><bounds left="400" right="420" top="220" bottom="240" /></bezel>
222     
222
223223      <bezel element="P20"><bounds left="35" right="55" top="320" bottom="340" /></bezel>
224224      <bezel element="P21"><bounds left="80" right="100" top="320" bottom="340" /></bezel>
225225      <bezel element="P22"><bounds left="125" right="145" top="320" bottom="340" /></bezel>
226      <bezel element="P23"><bounds left="170" right="190" top="320" bottom="340" /></bezel>     
226      <bezel element="P23"><bounds left="170" right="190" top="320" bottom="340" /></bezel>
227227      <bezel element="P24"><bounds left="215" right="235" top="320" bottom="340" /></bezel>
228228      <bezel element="P25"><bounds left="260" right="280" top="320" bottom="340" /></bezel>
229229      <bezel element="P26"><bounds left="305" right="325" top="320" bottom="340" /></bezel>
230      <bezel element="P27"><bounds left="350" right="370" top="320" bottom="340" /></bezel>   
231      <bezel element="P28"><bounds left="395" right="415" top="320" bottom="340" /></bezel>   
230      <bezel element="P27"><bounds left="350" right="370" top="320" bottom="340" /></bezel>
231      <bezel element="P28"><bounds left="395" right="415" top="320" bottom="340" /></bezel>
232232
233233
234234      <bezel element="P20"><bounds left="40" right="60" top="35" bottom="45" /></bezel>
235235      <bezel element="P21"><bounds left="60" right="80" top="85" bottom="95" /></bezel>
236236      <bezel element="P22"><bounds left="80" right="100" top="135" bottom="145" /></bezel>
237      <bezel element="P23"><bounds left="100" right="120" top="185" bottom="195" /></bezel>     
237      <bezel element="P23"><bounds left="100" right="120" top="185" bottom="195" /></bezel>
238238      <bezel element="P24"><bounds left="120" right="140" top="235" bottom="245" /></bezel>
239239      <bezel element="P25"><bounds left="140" right="160" top="185" bottom="195" /></bezel>
240240      <bezel element="P26"><bounds left="160" right="180" top="135" bottom="145" /></bezel>
241      <bezel element="P27"><bounds left="180" right="200" top="85" bottom="95" /></bezel>   
242      <bezel element="P28"><bounds left="200" right="220" top="35" bottom="45" /></bezel>         
241      <bezel element="P27"><bounds left="180" right="200" top="85" bottom="95" /></bezel>
242      <bezel element="P28"><bounds left="200" right="220" top="35" bottom="45" /></bezel>
243243
244      <bezel element="P29"><bounds left="190" right="260" top="130" bottom="150" /></bezel>     
245     
244      <bezel element="P29"><bounds left="190" right="260" top="130" bottom="150" /></bezel>
245
246246   </view>
247247</mamelayout>
trunk/src/mame/drivers/itech32.c
r32760r32761
44054405
44064406   /* The protection code is:
44074407
4408        addq #1,    1132.w
4409        clr.l       d0
4410        clr.l       d1
4411        move.b      680002,d0       ; Read protection result
4412        move.b      112f.w,d1
4413        andi.b      #$01,d0
4408       addq #1,    1132.w
4409       clr.l       d0
4410       clr.l       d1
4411       move.b      680002,d0       ; Read protection result
4412       move.b      112f.w,d1
4413       andi.b      #$01,d0
44144414Label1  bne.s       Label1          ; Infinite loop if result isn't 0x01
4415        nop                         ; Otherwise just return to the game :-)
4415       nop                         ; Otherwise just return to the game :-)
44164416
44174417   */
44184418}
r32760r32761
44264426
44274427   /* The protection code is:
44284428
4429        addq #1,    1132.w
4430        clr.l       d0
4431        clr.l       d1
4432        move.b      680002,d0       ; Read protection result
4433        andi.b      #$C0,d0
4434        cmpi.b      #$80,d0
4429       addq #1,    1132.w
4430       clr.l       d0
4431       clr.l       d1
4432       move.b      680002,d0       ; Read protection result
4433       andi.b      #$C0,d0
4434       cmpi.b      #$80,d0
44354435Label1  bne.s       Label1          ; Infinite loop if result isn't 0x80
4436        rts                         ; Otherwise just return to the game :-)
4436       rts                         ; Otherwise just return to the game :-)
44374437
44384438   */
44394439}
trunk/src/mame/drivers/travrusa.c
r32760r32761
617617GAME( 1985, shtrider, 0,        shtrider, shtrider, driver_device, 0,         ROT270|ORIENTATION_FLIP_X, "Seibu Kaihatsu",                 "Shot Rider", GAME_SUPPORTS_SAVE ) // possible bootleg
618618GAME( 1984, shtridera,shtrider, shtrider, shtrider, travrusa_state, shtridra, ROT270|ORIENTATION_FLIP_X, "Seibu Kaihatsu (Sigma license)", "Shot Rider (Sigma license)", GAME_SUPPORTS_SAVE )
619619GAME( 1985, shtriderb,shtrider, shtriderb,shtrider, travrusa_state, shtridrb, ROT270|ORIENTATION_FLIP_X, "bootleg",                        "Shot Rider (bootleg)", GAME_SUPPORTS_SAVE ) // resets when you attempt to start a game?
620
trunk/src/mame/drivers/20pacgal.c
r32760r32761
363363   save_item(NAME(m_sprite_ram));
364364   save_item(NAME(m_sprite_color_lookup));
365365}
366
366
367367void _20pacgal_state::machine_start()
368368{
369369   common_save_state();
trunk/src/mame/drivers/system16.c
r32760r32761
11151115   AM_RANGE(0x440000, 0x440fff) AM_RAM AM_SHARE("sprites")
11161116   AM_RANGE(0x840000, 0x840fff) AM_RAM_WRITE(paletteram_w) AM_SHARE("paletteram")
11171117
1118   // moved from C4xxxx to E4xxxx
1118   // moved from C4xxxx to E4xxxx
11191119   AM_RANGE(0xe40000, 0xe40001) AM_READ_PORT("COINAGE")
11201120   AM_RANGE(0xe40002, 0xe40003) AM_READ_PORT("DSW1")
11211121   AM_RANGE(0xe40006, 0xe40007) AM_WRITE(sound_command_irq_w)
r32760r32761
25212521   ROM_LOAD16_BYTE( "epr12097.b8", 0x60000, 0x010000, CRC(e645902c) SHA1(497cfcf6c25cc2e042e16dbcb1963d2223def15a) ) // 16- ic103
25222522
25232523   ROM_REGION( 0x10000, "soundcpu", 0 ) /* sound CPU */
2524   ROM_LOAD( "a-1 ic68", 0x0000, 0x8000, CRC(8321eb0b) SHA1(61cf95833c0aa38e35fc18db39d4ec74e4aaf01e) )
2524   ROM_LOAD( "a-1 ic68", 0x0000, 0x8000, CRC(8321eb0b) SHA1(61cf95833c0aa38e35fc18db39d4ec74e4aaf01e) )
25252525
25262526   ROM_REGION( 0x1000, "mcu", 0 ) /* MCU code */
25272527   ROM_LOAD( "d8749h.mcu", 0x0000, 0x1000, NO_DUMP )
trunk/src/mame/drivers/mpu5hw.c
r32760r32761
1717
1818     -- Much of the communication is done via a 68681 DUART.
1919
20    -- The ASIC acts as the main I/O control, including an interface to a Z89321 DSP and a 16bit DAC.
21   
20     -- The ASIC acts as the main I/O control, including an interface to a Z89321 DSP and a 16bit DAC.
21
2222     -- Help wanted, the MFME sources (which are based on MAME anyway) should be of some help here, if somebody
2323        in the FM emu community wants to adopt this driver they're welcome to it.
2424
r32760r32761
6868   UINT8 m_pic_stored_input;
6969   UINT8 m_pic_output_bit;
7070   UINT8 m_input_strobe;
71   
71
7272   DECLARE_READ32_MEMBER(mpu5_mem_r);
7373   DECLARE_WRITE32_MEMBER(mpu5_mem_w);
7474
r32760r32761
101101         //send init and ready for now - need to work on full DSP
102102         return 0x85;
103103      }
104   
104
105105      case 0x0b:
106106      {
107107         return 0;
r32760r32761
148148               logerror("%08x DUART read\n", pc);
149149               break;
150150            }
151           
151
152152            case 0xf0:
153153            {
154154               return asic_r32(space, offset&3,mem_mask);
155155            }
156           
156
157157            default:
158158            logerror("%08x maincpu read access offset %08x mem_mask %08x cs %d\n", pc, offset*4, mem_mask, cs);
159159            break;
160160         }
161161      }
162162      break;
163     
163
164164      case 3:
165165      case 4:
166166         offset &=0x3fff;
r32760r32761
188188         if (m_led_strobe_temp != data)
189189         {
190190            m_led_strobe_temp = data;
191           
191
192192            switch (m_led_strobe_temp)
193193            {
194194               case 0x00:
r32760r32761
222222         }
223223         break;
224224      }
225           
225
226226      case 0x09:
227227      {
228228         //Assume SEC fitted for now
r32760r32761
233233      case 0x0b:
234234      {
235235         output_set_value("statuslamp1", ((data&0x10) != 0));
236         
236
237237         output_set_value("statuslamp2", ((data&0x20) != 0));
238         
238
239239         if (data & 0x40)
240240         {
241//            m_dsp_pin =1;
241//              m_dsp_pin =1;
242242         }
243243      }
244244      break;
r32760r32761
280280         m_pic_bit1 = (data & 0x01);
281281         break;
282282      }
283     
283
284284      case 0x06:
285285      case 0x07:
286286      {
r32760r32761
291291            m_pic_data |= m_pic_bit1;
292292            m_pic_stored_input <<= 1;
293293            m_pic_clocked_bits ++;
294           
294
295295            if (m_pic_clocked_bits >=8)
296296            {
297297               m_pic_data =0;
298298               m_pic_clocked_bits =0;
299               
299
300300               if (m_input_strobe <4)
301301               {
302302                  m_input_strobe +=1;
303303               }
304               
304
305305            }
306306         }
307307         else
r32760r32761
319319         break;
320320      }
321321   }
322   
322
323323}
324324
325325WRITE32_MEMBER(mpu5_state::mpu5_mem_w)
r32760r32761
344344               logerror("%08x DUART write\n", pc);
345345               break;
346346            }
347           
347
348348            case 0xf0:
349349            {
350350               asic_w32(space, offset&3,data,mem_mask);
351351               break;
352352            }
353           
353
354354            default:
355355               logerror("%08x maincpu write access offset %08x data %08x mem_mask %08x cs %d\n", pc, offset*4, data, mem_mask, cs);
356356            break;
trunk/src/mame/drivers/bartop52.c
r32760r32761
3333   TIMER_DEVICE_CALLBACK_MEMBER( bartop_interrupt );
3434
3535   virtual void machine_reset();
36   //required_device<cpu_device> m_maincpu;   // maincpu is already contained in atari_common_state
36   //required_device<cpu_device> m_maincpu;    // maincpu is already contained in atari_common_state
3737};
3838
3939
trunk/src/mame/drivers/galaxian.c
r32760r32761
16971697   AM_RANGE(0xb801, 0xb801) AM_WRITE(irq_enable_w)
16981698   AM_RANGE(0xb806, 0xb806) AM_WRITE(galaxian_flip_screen_x_w)
16991699   AM_RANGE(0xb807, 0xb807) AM_WRITE(galaxian_flip_screen_y_w)
1700//   AM_RANGE(0xb818, 0xb818) AM_WRITE(coin_count_0_w) /* IOPC7 */
1701//   AM_RANGE(0xb81c, 0xb81c) AM_WRITE(coin_count_1_w) /* POUT1 */
1700//  AM_RANGE(0xb818, 0xb818) AM_WRITE(coin_count_0_w) /* IOPC7 */
1701//  AM_RANGE(0xb81c, 0xb81c) AM_WRITE(coin_count_1_w) /* POUT1 */
17021702   // todo, map inputs properly for this version
17031703ADDRESS_MAP_END
17041704
r32760r32761
65786578//  space.nop_write(0x6803, 0x6803);
65796579
65806580   m_audiocpu->space(AS_PROGRAM).install_read_handler(0x3000, 0x3000, read8_delegate(FUNC(galaxian_state::scorpion_digitalker_intr_r),this));
6581   
6581
65826582   save_item(NAME(m_protection_state));
65836583/*
65846584{
r32760r32761
66976697/* ROMCMP reports "BADADDR            xxxxxx-xxxxx".  Observed data sequence repeated every 32 bytes */
66986698   ROM_LOAD( "swarpt7m.bin", 0x2000, 0x1000, BAD_DUMP CRC(a2dff6c8) SHA1(d1c72848450dc5ff386dc94a26e4bf704ccc7121) )
66996699/* Stripped "repaired" rom.  Was original rom supposed to be 0x1000 or 0x800? */
6700//   ROM_LOAD( "swarpt7m-repair.bin", 0x2000, 0x0800, CRC(109f95cf) SHA1(d99171ffd6639fec28966edaf7cce3a4df5e948d) )
6700//  ROM_LOAD( "swarpt7m-repair.bin", 0x2000, 0x0800, CRC(109f95cf) SHA1(d99171ffd6639fec28966edaf7cce3a4df5e948d) )
67016701
67026702   ROM_REGION( 0x1000, "gfx1", 0 )
67036703   ROM_LOAD( "swarpb1h.bin", 0x0000, 0x0800, CRC(6ee3b5f7) SHA1(8150f2ecd59d3a165c0541b550664c56d049edd5) )
trunk/src/mame/drivers/gaiden.c
r32760r32761
11601160ROM_START( ryukendna )
11611161   ROM_REGION( 0x40000, "maincpu", 0 ) /* 2*128k for 68000 code */
11621162   ROM_LOAD16_BYTE( "1.3s",  0x00000, 0x20000, CRC(5532e302) SHA1(8ce48963ba737890d1a46c42a113d9419a3c174c) ) // found on 2 pcbs
1163//   ROM_LOAD16_BYTE( "1.3s",  0x00000, 0x20000, CRC(0ed5464c) SHA1(2eab6650ad1c38cd560ec3d084f47156756c97a4) ) 2 bytes different ( 022a : 50 instead of 51, 12f9 : 6b instead of 6a) - possible bad rom
1163//  ROM_LOAD16_BYTE( "1.3s",  0x00000, 0x20000, CRC(0ed5464c) SHA1(2eab6650ad1c38cd560ec3d084f47156756c97a4) ) 2 bytes different ( 022a : 50 instead of 51, 12f9 : 6b instead of 6a) - possible bad rom
11641164   ROM_LOAD16_BYTE( "2.4s",  0x00001, 0x20000, CRC(a93a8256) SHA1(6bf6c189f82cb9341d3427a822de83cbaed27bc0) )
11651165
11661166   ROM_REGION( 0x10000, "audiocpu", 0 )
trunk/src/mame/drivers/aces1.c
r32760r32761
136136   {
137137      //There needs to be some way of connecting these values to stepper coils, or doing the MCU properly
138138      // We should be able to see an enable clock, a sense and a full/half step selector, we don't have the half step visible it seems.
139     
139
140140      //3 1 16 14
141141      int phases[] = {0x05,0x01,0x09,0x08,0x0a,0x02,0x06,0x04,};
142142      for (int reel=0; reel <4; reel++)
r32760r32761
165165               logerror("Reel %x Enable %x \n",reel, clock  );
166166            }
167167         }
168//         logerror("Reel %x Enable %x Sense %i \n",reel, (data & (1<<reel)), (data & (4 + (1<<reel))) ? 1:-1  );
168//          logerror("Reel %x Enable %x Sense %i \n",reel, (data & (1<<reel)), (data & (4 + (1<<reel))) ? 1:-1  );
169169      }
170     
171     
172//     printf("reels, extender strobe %02x\n", data);
170
171
172//    printf("reels, extender strobe %02x\n", data);
173173   }
174174
175175   DECLARE_READ8_MEMBER( ic37_read_a )
r32760r32761
194194         if (stepper_optic_state(reel)) pattern |= 1<<reel;
195195         if (m_reel_count[reel]) action |= 1<<reel;
196196      }
197     
197
198198      return ((pattern << 4) | action);
199199   }
200200
r32760r32761
313313   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
314314   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED )
315315   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
316   
316
317317   PORT_START("IO4")
318318   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
319319   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
r32760r32761
353353   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
354354   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED )
355355   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
356   
356
357357   PORT_START("IO8")
358358   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
359359   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
r32760r32761
363363   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
364364   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED )
365365   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
366   
366
367367   PORT_START("DSWA")
368368   PORT_DIPNAME( 0x01, 0x01, "DSWA" )
369369   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
trunk/src/mame/drivers/model1.c
r32760r32761
783783   COMBINE_DATA(m_display_list1+offset);
784784   // never executed
785785   //if(0 && offset)
786   //   return;
786   //  return;
787787   if(1 && m_dump)
788788      logerror("TGP: md1_w %x, %04x @ %04x (%x)\n", offset, data, mem_mask, space.device().safe_pc());
789789}
r32760r32761
793793   COMBINE_DATA(m_display_list0+offset);
794794   // never executed
795795   //if(0 && offset)
796   //   return;
796   //  return;
797797   if(1 && m_dump)
798798      logerror("TGP: md0_w %x, %04x @ %04x (%x)\n", offset, data, mem_mask, space.device().safe_pc());
799799}
trunk/src/mame/drivers/dkong.c
r32760r32761
10001000
10011001static INPUT_PORTS_START( dkongx )
10021002   /* Supposedly the physical DIPS are read as defaults for the NVRAM when it's initially created.
1003      The settings here match those from the default DSW0 settings.  Beyond the initial NVRAM
1004      creation, DIPS (other than CABINET) can only be adjusted from the Service Mode */
1003       The settings here match those from the default DSW0 settings.  Beyond the initial NVRAM
1004       creation, DIPS (other than CABINET) can only be adjusted from the Service Mode */
10051005   PORT_INCLUDE( dkong )
10061006
10071007   PORT_MODIFY("DSW0")
trunk/src/mame/drivers/raiden2.c
r32760r32761
134134
135135 High Priority
136136
137 Protection
137 Protection
138138 - zeroteam has bogus collision detection;
139139 - raiden2 has a weird movement after that the ship completes animation from the aircraft. Probably 42c2 should be floating point rounded ...
140140 - (and probably more)
141
141
142142 Unemulated 0-0x3ffff ROM banking for raidendx, but it's unknown if/where it's used (hopefully NOT on getting perfect on Alpha course).
143143
144144 zeroteam - sort-DMA doesn't seem to work too well, sprite-sprite priorities are broken as per now
145
145
146146 xsedae - do an "8-liner"-style scroll during attract, doesn't work too well.
147
147
148148 sprite chip is the same as seibuspi.c and feversoc.c, needs device-ification and merging.
149 
150 sprite chip also uses first entry for "something" that isn't sprite, some of them looks clipping
149
150 sprite chip also uses first entry for "something" that isn't sprite, some of them looks clipping
151151 regions (150 - ff in zeroteam, 150 - 0 and 150 - 80 in raiden2). Latter probably do double buffering
152152 on odd/even frames, by updating only top or bottom part of screen.
153153
r32760r32761
180180   save_item(NAME(cop_spr_maxx));
181181   save_item(NAME(cop_spr_off));
182182
183   
183
184184   save_item(NAME(scrollvals));
185185
186186   save_item(NAME(sprite_prot_src_addr));
r32760r32761
190190/*
191191UINT16 raiden2_state::rps()
192192{
193   return m_maincpu->state_int(NEC_CS);
193    return m_maincpu->state_int(NEC_CS);
194194}
195195
196196UINT16 raiden2_state::rpc()
197197{
198   return m_maincpu->state_int(NEC_IP);
198    return m_maincpu->state_int(NEC_IP);
199199}
200200*/
201201
r32760r32761
843843      dst1 += 8;
844844   }
845845   //printf("[%08x] %08x %08x %04x %04x\n",src,dx,dy,dst1,dst2);
846   //   debugger_break(machine());
846   //  debugger_break(machine());
847847}
848848
849849READ16_MEMBER(raiden2_state::sprite_prot_dst1_r)
trunk/src/mame/drivers/iqblock.c
r32760r32761
214214   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
215215   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
216216   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 )
217   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON2 )
217   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON2 )
218218
219219   PORT_START("P2")
220220   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN2 )
r32760r32761
227227   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
228228
229229   PORT_START("EXTRA")
230   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON3 )               
231   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON4 )               
230   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON3 )
231   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON4 )
232232   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_COCKTAIL
233233   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_COCKTAIL
234234   PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED )
trunk/src/mame/drivers/jeutel.c
r32760r32761
1111
1212ToDo:
1313- Everything!
14- Each machine has 4 players, 7-digit, 12-segment florescent display 
14- Each machine has 4 players, 7-digit, 12-segment florescent display
1515
1616********************************************************************************/
1717
trunk/src/mame/drivers/rastersp.c
r32760r32761
855855
856856   MCFG_CPU_ADD("dsp", TMS32031, 33330000)
857857   MCFG_CPU_PROGRAM_MAP(dsp_map)
858   MCFG_TMS3203X_MCBL(true)   // Boot-loader mode
858   MCFG_TMS3203X_MCBL(true)    // Boot-loader mode
859859
860860   /* Devices */
861861   MCFG_TIMER_DRIVER_ADD("tms_timer1", rastersp_state, tms_timer1)
trunk/src/mame/drivers/model3.c
r32760r32761
3232    von2/von254g - works
3333    fvipers2 - waiting for decrementer (same code as eca)
3434    vs298 - works, hangs with an onscreen error code
35   vs299/vs2v991 - works
36   oceanhun - same as daytona2
37   lamachin - works
35    vs299/vs2v991 - works
36    oceanhun - same as daytona2
37    lamachin - works
3838
3939    dayto2pe - bug in DRC MMU page-fault handling, causes infinite loop at PC:0x2270 (or debug assert)
4040    daytona2 - As above.
4141    spikeout/spikeofe - As above.
4242    dirtdvls/dirtdvla - works
43    swtrilgy -
44    swtrilga -
43    swtrilgy -
44    swtrilga -
4545    magtruck - works, broken FPU values in matrices during 2nd part of attract mode (cpu core bug?)
4646    eca/ecax - cabinet network error
4747
r32760r32761
16151615      {
16161616         UINT8 res = 0;
16171617         res |= 1;
1618         res |= 0x2;      // magtruck country check
1618         res |= 0x2;     // magtruck country check
16191619         return res;
16201620      }
16211621   }
r32760r32761
54015401    0x02: Video (VBLANK start?)
54025402    0x01: Video (unused?)
54035403
5404   IRQ 0x08 and 0x04 directly affect the game speed in magtruck, once per scanline seems fast enough
5405   Un-syncing the interrupts breaks the progress bar in magtruck
5404    IRQ 0x08 and 0x04 directly affect the game speed in magtruck, once per scanline seems fast enough
5405    Un-syncing the interrupts breaks the progress bar in magtruck
54065406*/
54075407TIMER_DEVICE_CALLBACK_MEMBER(model3_state::model3_interrupt)
54085408{
r32760r32761
56945694   DRIVER_INIT_CALL(model3_15);
56955695
56965696   m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0xc1000000, 0xc10000ff, read64_delegate(FUNC(model3_state::scsi_r),this), write64_delegate(FUNC(model3_state::scsi_w),this));
5697   
5698//   rom[(0x73fe38^4)/4] = 0x38840004;       /* This seems to be an actual bug in the original code */
5697
5698//  rom[(0x73fe38^4)/4] = 0x38840004;       /* This seems to be an actual bug in the original code */
56995699}
57005700
57015701DRIVER_INIT_MEMBER(model3_state,vf3)
r32760r32761
58265826
58275827
58285828DRIVER_INIT_MEMBER(model3_state,srally2)
5829{   
5829{
58305830   DRIVER_INIT_CALL(model3_20);
58315831
58325832
5833   UINT32 *rom = (UINT32*)memregion("user1")->base();   
5833   UINT32 *rom = (UINT32*)memregion("user1")->base();
58345834   rom[(0x7c0c4^4)/4] = 0x60000000;
58355835   rom[(0x7c0c8^4)/4] = 0x60000000;
58365836   rom[(0x7c0cc^4)/4] = 0x60000000;
r32760r32761
58505850   rom[(0xf7770^4)/4] = 0x60000000;
58515851   rom[(0xf7774^4)/4] = 0x60000000;
58525852
5853   rom[(0x043dc^4)/4] = 0x48000090;      // skip force feedback setup
5853   rom[(0x043dc^4)/4] = 0x48000090;        // skip force feedback setup
58545854   rom[(0xf6e44^4)/4] = 0x60000000;
58555855}
58565856
r32760r32761
58655865DRIVER_INIT_MEMBER(model3_state,von2)
58665866{
58675867   m_step20_with_old_real3d = true;
5868   
5868
58695869   DRIVER_INIT_CALL(model3_20);
58705870}
58715871
trunk/src/mame/drivers/cps1.c
r32760r32761
68346834   ROM_CONTINUE(       0x000006, 0x80000)
68356835   ROMX_LOAD( "b-se194.bin", 0x200000, 0x80000, CRC(5726cab8) SHA1(0b2243a9a7184d53d42ddab7a8c51b63001c2f56) , ROM_GROUPWORD | ROM_SKIP(6) )
68366836   ROM_CONTINUE(       0x200004, 0x80000)
6837   ROMX_LOAD( "d-se064.bin", 0x200002, 0x80000, CRC(4dd24197) SHA1(548beaa0a6f1c3c88f4fc83169d1a3c86e0755d4) , ROM_GROUPWORD | ROM_SKIP(6) )   //sf2-8m.6c 99.999809%
6837   ROMX_LOAD( "d-se064.bin", 0x200002, 0x80000, CRC(4dd24197) SHA1(548beaa0a6f1c3c88f4fc83169d1a3c86e0755d4) , ROM_GROUPWORD | ROM_SKIP(6) )   //sf2-8m.6c 99.999809%
68386838   ROM_CONTINUE(       0x200006, 0x80000)
68396839   ROMX_LOAD( "e-sf004.bin", 0x400000, 0x80000, CRC(187667cc) SHA1(fae65bf23f49a32903fda8080659ccf8d42b911f) , ROM_GROUPWORD | ROM_SKIP(6) )
68406840   ROM_CONTINUE(       0x400004, 0x80000)
68416841   ROMX_LOAD( "f-sf001.bin", 0x400002, 0x80000, CRC(5b585071) SHA1(ad3371b1ba0441c67d9fcbb23b09464710e4e28a) , ROM_GROUPWORD | ROM_SKIP(6) )
68426842   ROM_CONTINUE(       0x400006, 0x80000)
6843     
6843
68446844   // These map over the MASK roms on this bootleg why? isn't it a waste of eprom?
68456845   ROMX_LOAD( "27c1024.10", 0x400000, 0x20000, CRC(84427d1b) SHA1(f988a2b53c8cc46eeb8032084f24966a539b3734) , ROM_GROUPWORD | ROM_SKIP(6) )//e-sf004.bin [1/8]      IDENTICAL
68466846   ROMX_LOAD( "27c1024.12", 0x400002, 0x20000, CRC(55bc790c) SHA1(a1114b89f6fa4487210477676984c77ad94b5ef8) , ROM_GROUPWORD | ROM_SKIP(6) )//f-sf001.bin [1/8]      IDENTICAL
r32760r32761
68676867
68686868   ROM_REGION( 0x600000, "gfx", 0 )
68696869   /* There are 8 mask  and 8 otp eprom on this board, data match sf2 set in the end */
6870   ROMX_LOAD( "1-b-yf197.07",    0x000000, 0x80000, CRC(22c9cc8e) SHA1(b9194fb337b30502c1c9501cd6c64ae4035544d4) , ROM_GROUPWORD | ROM_SKIP(6) )
6871   ROMX_LOAD( "1-d-yf207.12",    0x000002, 0x80000, CRC(57213be8) SHA1(3759b851ac0904ec79cbb67a2264d384b6f2f9f9) , ROM_GROUPWORD | ROM_SKIP(6) )
6872   ROMX_LOAD( "27020.1",      0x000004, 0x40000, CRC(84afb959) SHA1(ff8f3fb39203d229552649b09046a509aa399b7d) , ROM_SKIP(7) )
6873   ROMX_LOAD( "27020.3",      0x000005, 0x40000, CRC(ab21635d) SHA1(c6294b06c482a43cc1736674b0c1bc790da8cc8c) , ROM_SKIP(7) )
6874   ROMX_LOAD( "27020.5",      0x000006, 0x40000, CRC(2ce56f9f) SHA1(5bd23823df52aeff8e84a6eb3199a5e75f38cd42) , ROM_SKIP(7) )
6875   ROMX_LOAD( "27020.7",      0x000007, 0x40000, CRC(0ad7fb2b) SHA1(51265b331cbbe9d133274bafdbf043151240a20d) , ROM_SKIP(7) )
6876   
6877   ROMX_LOAD( "27020.2",      0x200000, 0x40000, CRC(031525cc) SHA1(65e280607c058cf9c005a6fc809ed375d379c0bf) , ROM_SKIP(7) )
6878   ROMX_LOAD( "27020.4",      0x200001, 0x40000, CRC(c97046a5) SHA1(88c7becaa2713c85e22ddd3e2305770525a9132b) , ROM_SKIP(7) )
6879   ROMX_LOAD( "1-h-yg010.10",    0x200002, 0x80000, CRC(b5548f17) SHA1(baa92b91cf616bc9e2a8a66adc777ffbf962a51b) , ROM_GROUPWORD | ROM_SKIP(6) )
6880   ROMX_LOAD( "1-e-yg003.02",   0x200004, 0x80000, CRC(14b84312) SHA1(2eea16673e60ba7a10bd4d8f6c217bb2441a5b0e) , ROM_GROUPWORD | ROM_SKIP(6) )
6881   ROMX_LOAD( "27020.6",      0x200006, 0x40000, CRC(dbbfd400) SHA1(fc25928b6ed025fa2397d924bae93fd28a4e728f) , ROM_SKIP(7) )
6882   ROMX_LOAD( "27020.8",      0x200007, 0x40000, CRC(37635e97) SHA1(b4e5dd6e93174af76aaeeb47471ded0d0bc253e2) , ROM_SKIP(7) )
6883   
6884   ROMX_LOAD( "1-j-yf213.09",       0x400000, 0x80000, CRC(994bfa58) SHA1(5669b845f624b10e7be56bfc89b76592258ce48b) , ROM_GROUPWORD | ROM_SKIP(6) )
6870   ROMX_LOAD( "1-b-yf197.07",  0x000000, 0x80000, CRC(22c9cc8e) SHA1(b9194fb337b30502c1c9501cd6c64ae4035544d4) , ROM_GROUPWORD | ROM_SKIP(6) )
6871   ROMX_LOAD( "1-d-yf207.12",  0x000002, 0x80000, CRC(57213be8) SHA1(3759b851ac0904ec79cbb67a2264d384b6f2f9f9) , ROM_GROUPWORD | ROM_SKIP(6) )
6872   ROMX_LOAD( "27020.1",       0x000004, 0x40000, CRC(84afb959) SHA1(ff8f3fb39203d229552649b09046a509aa399b7d) , ROM_SKIP(7) )
6873   ROMX_LOAD( "27020.3",       0x000005, 0x40000, CRC(ab21635d) SHA1(c6294b06c482a43cc1736674b0c1bc790da8cc8c) , ROM_SKIP(7) )
6874   ROMX_LOAD( "27020.5",       0x000006, 0x40000, CRC(2ce56f9f) SHA1(5bd23823df52aeff8e84a6eb3199a5e75f38cd42) , ROM_SKIP(7) )
6875   ROMX_LOAD( "27020.7",       0x000007, 0x40000, CRC(0ad7fb2b) SHA1(51265b331cbbe9d133274bafdbf043151240a20d) , ROM_SKIP(7) )
6876
6877   ROMX_LOAD( "27020.2",       0x200000, 0x40000, CRC(031525cc) SHA1(65e280607c058cf9c005a6fc809ed375d379c0bf) , ROM_SKIP(7) )
6878   ROMX_LOAD( "27020.4",       0x200001, 0x40000, CRC(c97046a5) SHA1(88c7becaa2713c85e22ddd3e2305770525a9132b) , ROM_SKIP(7) )
6879   ROMX_LOAD( "1-h-yg010.10",  0x200002, 0x80000, CRC(b5548f17) SHA1(baa92b91cf616bc9e2a8a66adc777ffbf962a51b) , ROM_GROUPWORD | ROM_SKIP(6) )
6880   ROMX_LOAD( "1-e-yg003.02",  0x200004, 0x80000, CRC(14b84312) SHA1(2eea16673e60ba7a10bd4d8f6c217bb2441a5b0e) , ROM_GROUPWORD | ROM_SKIP(6) )
6881   ROMX_LOAD( "27020.6",       0x200006, 0x40000, CRC(dbbfd400) SHA1(fc25928b6ed025fa2397d924bae93fd28a4e728f) , ROM_SKIP(7) )
6882   ROMX_LOAD( "27020.8",       0x200007, 0x40000, CRC(37635e97) SHA1(b4e5dd6e93174af76aaeeb47471ded0d0bc253e2) , ROM_SKIP(7) )
6883
6884   ROMX_LOAD( "1-j-yf213.09",      0x400000, 0x80000, CRC(994bfa58) SHA1(5669b845f624b10e7be56bfc89b76592258ce48b) , ROM_GROUPWORD | ROM_SKIP(6) )
68856885   ROMX_LOAD( "wm91m-11-yd025.11", 0x400002, 0x80000, CRC(3e66ad9d) SHA1(9af9df0826988872662753e9717c48d46f2974b0) , ROM_GROUPWORD | ROM_SKIP(6) )
6886   ROMX_LOAD( "1-i-yf224.03",       0x400004, 0x80000, CRC(c1befaa8) SHA1(a6a7f4725e52678cbd8d557285c01cdccb2c2602) , ROM_GROUPWORD | ROM_SKIP(6) )
6887   ROMX_LOAD( "1-k-yf036.06",       0x400006, 0x80000, CRC(0627c831) SHA1(f9a92d614e8877d648449de2612fc8b43c85e4c2) , ROM_GROUPWORD | ROM_SKIP(6) )
6888   
6886   ROMX_LOAD( "1-i-yf224.03",      0x400004, 0x80000, CRC(c1befaa8) SHA1(a6a7f4725e52678cbd8d557285c01cdccb2c2602) , ROM_GROUPWORD | ROM_SKIP(6) )
6887   ROMX_LOAD( "1-k-yf036.06",      0x400006, 0x80000, CRC(0627c831) SHA1(f9a92d614e8877d648449de2612fc8b43c85e4c2) , ROM_GROUPWORD | ROM_SKIP(6) )
6888
68896889   /* These map over the MASK roms on this bootleg to get rid of the CAPCOM logo (wasteful, but correct) */
68906890   ROMX_LOAD( "27010.09hi", 0x400000, 0x10000, CRC(a505621e) SHA1(8ffa8cedad54948870bbd8f629d927332dc9fcf6) , ROM_SKIP(7) )
68916891   ROM_CONTINUE(        0x400004, 0x10000 )
r32760r32761
1161311613GAME( 1991, sf2jl,       sf2,      cps1_10MHz, sf2j,     cps_state,   cps1,     ROT0,   "Capcom", "Street Fighter II: The World Warrior (Japan 920312)", GAME_SUPPORTS_SAVE )
1161411614GAME( 1992, sf2ebbl,     sf2,      cps1_10MHz, sf2hack,  cps_state,   sf2hack,  ROT0,   "bootleg", "Street Fighter II: The World Warrior (TAB Austria, bootleg, set 1)", GAME_SUPPORTS_SAVE )       // 910214 - based on World version
1161511615GAME( 1992, sf2ebbl2,    sf2,      cps1_10MHz, sf2hack,  cps_state,   sf2hack,  ROT0,   "bootleg", "Street Fighter II: The World Warrior (TAB Austria, bootleg, set 3)", GAME_SUPPORTS_SAVE )       // 910214 - based on World version
11616GAME( 1992, sf2ebbl3,    sf2,      cps1_10MHz, sf2hack,  cps_state,   sf2hack,  ROT0,   "bootleg", "Street Fighter II: The World Warrior (TAB Austria, bootleg, set 4)", GAME_SUPPORTS_SAVE )       // 910214 - based on World version
11616GAME( 1992, sf2ebbl3,    sf2,      cps1_10MHz, sf2hack,  cps_state,   sf2hack,  ROT0,   "bootleg", "Street Fighter II: The World Warrior (TAB Austria, bootleg, set 4)", GAME_SUPPORTS_SAVE )       // 910214 - based on World version
1161711617GAME( 1992, sf2stt,      sf2,      cps1_10MHz, sf2hack,  cps_state,   sf2hack,  ROT0,   "bootleg", "Street Fighter II: The World Warrior (TAB Austria, bootleg, set 2)", GAME_NOT_WORKING | GAME_SUPPORTS_SAVE )    // 910214 - based on World version
1161811618GAME( 1992, sf2rk,       sf2,      cps1_10MHz, sf2hack,  cps_state,   sf2hack,  ROT0,   "bootleg", "Street Fighter II: The World Warrior (RK, bootleg)", GAME_NOT_WORKING | GAME_SUPPORTS_SAVE )    // 920211 (pcb)
1161911619GAME( 1991, sf2qp1,      sf2,      cps1_10MHz, sf2,      cps_state,   cps1,     ROT0,   "bootleg", "Street Fighter II: The World Warrior (Quicken Pt-I, bootleg)", GAME_SUPPORTS_SAVE )     // 910214 - based on World version
trunk/src/mame/drivers/jchan.c
r32760r32761
201201   required_device<sknsspr_device> m_spritegen1;
202202   required_device<sknsspr_device> m_spritegen2;
203203   required_device<kaneko_view2_tilemap_device> m_view2_0;
204   
204
205205   required_shared_ptr<UINT16> m_spriteram_1;
206206   required_shared_ptr<UINT16> m_sprregs_1;
207207   required_shared_ptr<UINT16> m_spriteram_2;
trunk/src/mame/drivers/hikaru.c
r32760r32761
622622
623623   /* ROM board using 64M SOP44 MASKROM */
624624   ROM_REGION( 0x10000000, "user2", 0)
625   ROM_LOAD("mpr-23086.ic37" , 0x0000000, 0x0800000, CRC(ef6f20f1) SHA1(11fb66bf71223b4c6650d3adaea21e8709b8d67b)) 
626   ROM_LOAD("mpr-23087.ic38" , 0x0800000, 0x0800000, CRC(54389822) SHA1(6357f0aa77ef0a5a08a751e085fa026d26ba47d1)) 
627   ROM_LOAD("mpr-23088.ic39" , 0x1000000, 0x0800000, CRC(9f1a382e) SHA1(b846c3a091d04e49cc1e731237c9326ccac39a64)) 
628   ROM_LOAD("mpr-23089.ic40" , 0x1800000, 0x0800000, CRC(6aae64fc) SHA1(392b6fba25d20bb41fd72be3a3a9ce95b2374065)) 
629   ROM_LOAD("mpr-23090.ic41" , 0x2000000, 0x0800000, CRC(ba857872) SHA1(c07ff7955d3d07f2a60d9761b4bd692c0a9c9353)) 
630   ROM_LOAD("mpr-23091.ic42" , 0x2800000, 0x0800000, CRC(66a73e27) SHA1(c4e7d190a80499225a78b7f788c2abc7ec4ebdca)) 
631   ROM_LOAD("mpr-23092.ic43" , 0x3000000, 0x0800000, CRC(4f20a0f5) SHA1(0580feba6a6dd01a21d09ec2503ccf77030f8d2a)) 
632   ROM_LOAD("mpr-23093.ic44" , 0x3800000, 0x0800000, CRC(e74d7d64) SHA1(c28e44319bf08aedd9aed625a12834ec76f1e5e0)) 
633   ROM_LOAD("mpr-23094.ic45" , 0x4000000, 0x0800000, CRC(90f04c14) SHA1(b55846ea1edd920fd527e3257b13fea8df1f713f)) 
634   ROM_LOAD("mpr-23095.ic46" , 0x4800000, 0x0800000, CRC(cc67cb5b) SHA1(85e99ec22d1c65139685a94f1ba0c52a0eb33a2e)) 
635   ROM_LOAD("mpr-23096.ic47" , 0x5000000, 0x0800000, CRC(799ab79e) SHA1(c0ac85ad7f4cf46ff162f1ec2e85a3f22817de5e)) 
636   ROM_LOAD("mpr-23097.ic48" , 0x5800000, 0x0800000, CRC(f68439de) SHA1(475d0f22e78e3c86431b742e37cbfd764ca8acee)) 
637   ROM_LOAD("mpr-23098.ic49" , 0x6000000, 0x0800000, CRC(a1e2009c) SHA1(c6a600d47fd2a96d28c637631862150e6f303c3d)) 
638   ROM_LOAD("mpr-23099.ic50" , 0x6800000, 0x0800000, CRC(ce36f642) SHA1(6cb2e69095efc7969255ebc637e2597c56442751)) 
639   ROM_LOAD("mpr-23100.ic51" , 0x7000000, 0x0800000, CRC(0f966653) SHA1(1544af662188ea734e0a2e559e05e5f782fb292d)) 
640   ROM_LOAD("mpr-23101.ic52" , 0x7800000, 0x0800000, CRC(2640fbaa) SHA1(59e9bd143734c71968beb9953122680d3350e69c)) 
641   ROM_LOAD("mpr-23102.ic53" , 0x8000000, 0x0800000, CRC(080c5bcb) SHA1(0cf54348420ae9866edd64422cb82464990f1f2f)) 
642   ROM_LOAD("mpr-23103.ic54" , 0x8800000, 0x0800000, CRC(19c7758f) SHA1(fed7f45dd91e1cb6bba7d8e80ed17dca27d92e43)) 
643   ROM_LOAD("mpr-23104.ic55" , 0x9000000, 0x0800000, CRC(4ca74216) SHA1(0e65971359ba0e2b4fc032a26d1c10d8efadc205)) 
644   ROM_LOAD("mpr-23105.ic56" , 0x9800000, 0x0800000, CRC(e2dd35ba) SHA1(2213e3195a49532a177086de8134ce8b753fc7ce)) 
645   ROM_LOAD("mpr-23106.ic57" , 0xa000000, 0x0800000, CRC(dd325515) SHA1(8144e1a87f7d72a18791d1d452123a91cfb354dd)) 
646   ROM_LOAD("mpr-23107.ic58" , 0xa800000, 0x0800000, CRC(a527a22a) SHA1(54c105b21797c9b0a2a6b2c7091de726c49a55e8)) 
647   ROM_LOAD("mpr-23108.ic59" , 0xb000000, 0x0800000, CRC(47817d9a) SHA1(d2c6f1b2e800448eaf694d550733bba2280b6746)) 
648   ROM_LOAD("mpr-23109.ic60" , 0xb800000, 0x0800000, CRC(8c61dec4) SHA1(25a1a5b236b3aed013fc94bd9695906ae5d7f305)) 
649   ROM_LOAD("mpr-23110.ic61" , 0xc000000, 0x0800000, CRC(4ddae9f1) SHA1(d1c5e3f18932af806f166779cf14909ab17d052c)) 
650   ROM_LOAD("mpr-23111.ic62" , 0xc800000, 0x0800000, CRC(c404cb1c) SHA1(e14855ec8a5a5ba243a2339c571928fdcc187157)) 
651   ROM_LOAD("mpr-23112.ic63" , 0xd000000, 0x0800000, CRC(d001fe59) SHA1(ab395d2933b5d691259221168dfaa063cf9a4d1c)) 
652   ROM_LOAD("mpr-23113.ic64" , 0xd800000, 0x0800000, CRC(f241cfd5) SHA1(5b85e8b50559becff7a76565c95487825bbd9351)) 
653   ROM_LOAD("mpr-23114.ic65" , 0xe000000, 0x0800000, CRC(80049d7c) SHA1(56aab53e9317b1b5d10bd2af78fd83e7422d8939)) 
654   ROM_LOAD("mpr-23115.ic66" , 0xe800000, 0x0800000, CRC(4fc540fe) SHA1(df580421d856566e067c2b319c8ac4671629682f)) 
655   ROM_LOAD("mpr-23116.ic67" , 0xf000000, 0x0800000, CRC(9f567fce) SHA1(c35bcf968f139557e50ceafa9c6bad4deb87154f)) 
656   ROM_LOAD("mpr-23117.ic68" , 0xf800000, 0x0800000, CRC(9d4d3529) SHA1(66008445629681ebf2f26b3f181d8524a8576d2f)) 
625   ROM_LOAD("mpr-23086.ic37" , 0x0000000, 0x0800000, CRC(ef6f20f1) SHA1(11fb66bf71223b4c6650d3adaea21e8709b8d67b))
626   ROM_LOAD("mpr-23087.ic38" , 0x0800000, 0x0800000, CRC(54389822) SHA1(6357f0aa77ef0a5a08a751e085fa026d26ba47d1))
627   ROM_LOAD("mpr-23088.ic39" , 0x1000000, 0x0800000, CRC(9f1a382e) SHA1(b846c3a091d04e49cc1e731237c9326ccac39a64))
628   ROM_LOAD("mpr-23089.ic40" , 0x1800000, 0x0800000, CRC(6aae64fc) SHA1(392b6fba25d20bb41fd72be3a3a9ce95b2374065))
629   ROM_LOAD("mpr-23090.ic41" , 0x2000000, 0x0800000, CRC(ba857872) SHA1(c07ff7955d3d07f2a60d9761b4bd692c0a9c9353))
630   ROM_LOAD("mpr-23091.ic42" , 0x2800000, 0x0800000, CRC(66a73e27) SHA1(c4e7d190a80499225a78b7f788c2abc7ec4ebdca))
631   ROM_LOAD("mpr-23092.ic43" , 0x3000000, 0x0800000, CRC(4f20a0f5) SHA1(0580feba6a6dd01a21d09ec2503ccf77030f8d2a))
632   ROM_LOAD("mpr-23093.ic44" , 0x3800000, 0x0800000, CRC(e74d7d64) SHA1(c28e44319bf08aedd9aed625a12834ec76f1e5e0))
633   ROM_LOAD("mpr-23094.ic45" , 0x4000000, 0x0800000, CRC(90f04c14) SHA1(b55846ea1edd920fd527e3257b13fea8df1f713f))
634   ROM_LOAD("mpr-23095.ic46" , 0x4800000, 0x0800000, CRC(cc67cb5b) SHA1(85e99ec22d1c65139685a94f1ba0c52a0eb33a2e))
635   ROM_LOAD("mpr-23096.ic47" , 0x5000000, 0x0800000, CRC(799ab79e) SHA1(c0ac85ad7f4cf46ff162f1ec2e85a3f22817de5e))
636   ROM_LOAD("mpr-23097.ic48" , 0x5800000, 0x0800000, CRC(f68439de) SHA1(475d0f22e78e3c86431b742e37cbfd764ca8acee))
637   ROM_LOAD("mpr-23098.ic49" , 0x6000000, 0x0800000, CRC(a1e2009c) SHA1(c6a600d47fd2a96d28c637631862150e6f303c3d))
638   ROM_LOAD("mpr-23099.ic50" , 0x6800000, 0x0800000, CRC(ce36f642) SHA1(6cb2e69095efc7969255ebc637e2597c56442751))
639   ROM_LOAD("mpr-23100.ic51" , 0x7000000, 0x0800000, CRC(0f966653) SHA1(1544af662188ea734e0a2e559e05e5f782fb292d))
640   ROM_LOAD("mpr-23101.ic52" , 0x7800000, 0x0800000, CRC(2640fbaa) SHA1(59e9bd143734c71968beb9953122680d3350e69c))
641   ROM_LOAD("mpr-23102.ic53" , 0x8000000, 0x0800000, CRC(080c5bcb) SHA1(0cf54348420ae9866edd64422cb82464990f1f2f))
642   ROM_LOAD("mpr-23103.ic54" , 0x8800000, 0x0800000, CRC(19c7758f) SHA1(fed7f45dd91e1cb6bba7d8e80ed17dca27d92e43))
643   ROM_LOAD("mpr-23104.ic55" , 0x9000000, 0x0800000, CRC(4ca74216) SHA1(0e65971359ba0e2b4fc032a26d1c10d8efadc205))
644   ROM_LOAD("mpr-23105.ic56" , 0x9800000, 0x0800000, CRC(e2dd35ba) SHA1(2213e3195a49532a177086de8134ce8b753fc7ce))
645   ROM_LOAD("mpr-23106.ic57" , 0xa000000, 0x0800000, CRC(dd325515) SHA1(8144e1a87f7d72a18791d1d452123a91cfb354dd))
646   ROM_LOAD("mpr-23107.ic58" , 0xa800000, 0x0800000, CRC(a527a22a) SHA1(54c105b21797c9b0a2a6b2c7091de726c49a55e8))
647   ROM_LOAD("mpr-23108.ic59" , 0xb000000, 0x0800000, CRC(47817d9a) SHA1(d2c6f1b2e800448eaf694d550733bba2280b6746))
648   ROM_LOAD("mpr-23109.ic60" , 0xb800000, 0x0800000, CRC(8c61dec4) SHA1(25a1a5b236b3aed013fc94bd9695906ae5d7f305))
649   ROM_LOAD("mpr-23110.ic61" , 0xc000000, 0x0800000, CRC(4ddae9f1) SHA1(d1c5e3f18932af806f166779cf14909ab17d052c))
650   ROM_LOAD("mpr-23111.ic62" , 0xc800000, 0x0800000, CRC(c404cb1c) SHA1(e14855ec8a5a5ba243a2339c571928fdcc187157))
651   ROM_LOAD("mpr-23112.ic63" , 0xd000000, 0x0800000, CRC(d001fe59) SHA1(ab395d2933b5d691259221168dfaa063cf9a4d1c))
652   ROM_LOAD("mpr-23113.ic64" , 0xd800000, 0x0800000, CRC(f241cfd5) SHA1(5b85e8b50559becff7a76565c95487825bbd9351))
653   ROM_LOAD("mpr-23114.ic65" , 0xe000000, 0x0800000, CRC(80049d7c) SHA1(56aab53e9317b1b5d10bd2af78fd83e7422d8939))
654   ROM_LOAD("mpr-23115.ic66" , 0xe800000, 0x0800000, CRC(4fc540fe) SHA1(df580421d856566e067c2b319c8ac4671629682f))
655   ROM_LOAD("mpr-23116.ic67" , 0xf000000, 0x0800000, CRC(9f567fce) SHA1(c35bcf968f139557e50ceafa9c6bad4deb87154f))
656   ROM_LOAD("mpr-23117.ic68" , 0xf800000, 0x0800000, CRC(9d4d3529) SHA1(66008445629681ebf2f26b3f181d8524a8576d2f))
657657ROM_END
658658
659659ROM_START( braveff )
trunk/src/mame/drivers/cv1k.c
r32760r32761
514514   ROM_RELOAD(0x200000,0x200000)
515515
516516   ROM_REGION( 0x8400000, "game", ROMREGION_ERASEFF)
517//   ROM_LOAD("mushisama_u2", 0x000000, 0x8400000, CRC(f1e0cf65) SHA1(d00d950422309fdf08efe1e2d5f040beb45ee6fb) ) // bad rom, one corrupt asset vs. below
517//  ROM_LOAD("mushisama_u2", 0x000000, 0x8400000, CRC(f1e0cf65) SHA1(d00d950422309fdf08efe1e2d5f040beb45ee6fb) ) // bad rom, one corrupt asset vs. below
518518   ROM_LOAD("mushisam_u2", 0x000000, 0x8400000, CRC(4f0a842a) SHA1(33f3550ec676a7088b6348cd72c16cc6594afb84) ) /* (2004/10/12.MASTER VER.) */
519519
520520   ROM_REGION( 0x800000, "ymz770", ROMREGION_ERASEFF)
r32760r32761
528528   ROM_RELOAD(0x200000,0x200000)
529529
530530   ROM_REGION( 0x8400000, "game", ROMREGION_ERASEFF)
531//   ROM_LOAD("mushisamb_u2", 0x000000, 0x8400000, CRC(6cc9d1a9) SHA1(17907798dce1defadd10354cec6c8d364e045570) ) // bad rom, one corrupt asset vs. below
531//  ROM_LOAD("mushisamb_u2", 0x000000, 0x8400000, CRC(6cc9d1a9) SHA1(17907798dce1defadd10354cec6c8d364e045570) ) // bad rom, one corrupt asset vs. below
532532   ROM_LOAD("mushisam_u2", 0x000000, 0x8400000, CRC(4f0a842a) SHA1(33f3550ec676a7088b6348cd72c16cc6594afb84) ) /* (2004/10/12.MASTER VER.) */
533533
534534   ROM_REGION( 0x800000, "ymz770", ROMREGION_ERASEFF)
r32760r32761
568568   ROM_RELOAD(0x200000,0x200000)
569569
570570   ROM_REGION( 0x8400000, "game", ROMREGION_ERASEFF)
571//   ROM_LOAD("mushitama_u2", 0x000000, 0x8400000, CRC(3f93ff82) SHA1(6f6c250aa7134016ffb288d056bc937ea311f538) ) // recycled ROM - only unused areas differ
571//  ROM_LOAD("mushitama_u2", 0x000000, 0x8400000, CRC(3f93ff82) SHA1(6f6c250aa7134016ffb288d056bc937ea311f538) ) // recycled ROM - only unused areas differ
572572   ROM_LOAD("mushitam_u2", 0x000000, 0x8400000, CRC(8ba498ab) SHA1(459c0b4ab831bbe019bdd5b0ac56955948b9e3a6) ) /* (2005/09/09.MASTER VER) */
573573
574574   ROM_REGION( 0x800000, "ymz770", ROMREGION_ERASEFF)
r32760r32761
595595   ROM_RELOAD(0x200000,0x200000)
596596
597597   ROM_REGION( 0x8400000, "game", ROMREGION_ERASEFF)
598//   ROM_LOAD("futari15a_u2", 0x000000, 0x8400000, CRC(b9d815f9) SHA1(6b6f668b0bbb087ffac65e4f0d8bd9d5b28eeb28) )  // recycled ROM - only unused areas differ
598//  ROM_LOAD("futari15a_u2", 0x000000, 0x8400000, CRC(b9d815f9) SHA1(6b6f668b0bbb087ffac65e4f0d8bd9d5b28eeb28) )  // recycled ROM - only unused areas differ
599599   ROM_LOAD("futari15_u2", 0x000000, 0x8400000, CRC(b9eae1fc) SHA1(410f8e7cfcbfd271b41fb4f8d049a13a3191a1f9) ) /* (2006/12/8.MAST VER. 1.54.) */
600600
601601   ROM_REGION( 0x800000, "ymz770", ROMREGION_ERASEFF)
trunk/src/mame/drivers/capr1.c
r32760r32761
33/***************************************************************************
44
55  Taito Capriccio Z80 crane hardware (let's call it 1st generation)
6 
6
77  These are presumed to be on similar hardware:
88  - Capriccio         1991
99  - New Capriccio     1992
r32760r32761
1111  - New Capriccio 2   1993
1212  - Capriccio Spin    1994
1313  - Capriccio Spin 2  1996
14 
14
1515  The next released game of this series is Capriccio Cyclone, see caprcyc.c
1616  More games were released after this.
17 
17
1818TODO:
1919- get cspin2 working a bit:
2020  * unknown reads and writes
r32760r32761
5656static ADDRESS_MAP_START( cspin2_map, AS_PROGRAM, 8, capr1_state )
5757   AM_RANGE(0x0000, 0x7fff) AM_ROM
5858   AM_RANGE(0x8000, 0x9fff) AM_RAM
59//   AM_RANGE(0xa000, 0xa01f) AM_RAM // wrong
59//  AM_RANGE(0xa000, 0xa01f) AM_RAM // wrong
6060   AM_RANGE(0xc000, 0xc001) AM_DEVREADWRITE("ym", ym2203_device, read, write)
61//   AM_RANGE(0xc004, 0xc005) AM_WRITENOP
62//   AM_RANGE(0xc008, 0xc009) AM_WRITENOP
63//   AM_RANGE(0xc00c, 0xc00d) AM_WRITENOP
64//   AM_RANGE(0xc00d, 0xc00d) AM_DEVREADWRITE("oki", okim6295_device, read, write)
61//  AM_RANGE(0xc004, 0xc005) AM_WRITENOP
62//  AM_RANGE(0xc008, 0xc009) AM_WRITENOP
63//  AM_RANGE(0xc00c, 0xc00d) AM_WRITENOP
64//  AM_RANGE(0xc00d, 0xc00d) AM_DEVREADWRITE("oki", okim6295_device, read, write)
6565ADDRESS_MAP_END
6666
6767
r32760r32761
8383   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
8484   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON3 )
8585   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON4 )
86   
86
8787   PORT_START("IN1")
8888   PORT_DIPUNKNOWN_DIPLOC( 0x01, 0x01, "SW1:1" )
8989   PORT_DIPUNKNOWN_DIPLOC( 0x02, 0x02, "SW1:2" )
trunk/src/mame/drivers/8080bw.c
r32760r32761
31933193WRITE8_MEMBER(_8080bw_state::invmulti_bank_w)
31943194{
31953195   m_invmulti_bank = data; //needed to restore the bankswitch post load
3196   
3196
31973197   // d0, d4, d6: bank
31983198   int bank = (data & 1) | (data >> 3 & 2) | (data >> 4 & 4);
31993199   membank("bank1")->set_base(memregion("maincpu")->base() + bank * 0x4000 + 0x0000);
r32760r32761
32083208MACHINE_RESET_MEMBER(_8080bw_state,invmulti)
32093209{
32103210   m_invmulti_bank = 0;
3211   
3211
32123212   invmulti_bank_w(m_maincpu->space(AS_PROGRAM), 0, 0);
32133213
32143214   MACHINE_RESET_CALL_MEMBER(mw8080bw);
r32760r32761
32343234   // decrypt rom
32353235   for (int i = 0; i < len; i++)
32363236      dest[i] = BITSWAP8(src[(i & 0x100ff) | (BITSWAP8(i >> 8 & 0xff, 7,3,4,5,0,6,1,2) << 8)],0,6,5,7,4,3,1,2);
3237     
3237
32383238   save_item(NAME(m_invmulti_bank));
32393239   machine().save().register_postload(save_prepost_delegate(FUNC(_8080bw_state::invmulti_bankswitch_restore), this));
32403240}
trunk/src/mame/drivers/taito_z.c
r32760r32761
30433043   MCFG_TC0100SCN_PALETTE("palette")
30443044
30453045   MCFG_DEVICE_ADD("tc0150rod", TC0150ROD, 0)
3046   
3046
30473047   MCFG_TC0110PCR_ADD("tc0110pcr")
30483048   MCFG_TC0110PCR_PALETTE("palette")
30493049
r32760r32761
31213121   MCFG_TC0100SCN_PALETTE("palette")
31223122
31233123   MCFG_DEVICE_ADD("tc0150rod", TC0150ROD, 0)
3124   
3124
31253125   MCFG_TC0110PCR_ADD("tc0110pcr")
31263126   MCFG_TC0110PCR_PALETTE("palette")
31273127
r32760r32761
32013201   MCFG_TC0100SCN_PALETTE("palette")
32023202
32033203   MCFG_DEVICE_ADD("tc0150rod", TC0150ROD, 0)
3204   
3204
32053205   MCFG_TC0110PCR_ADD("tc0110pcr")
32063206   MCFG_TC0110PCR_PALETTE("palette")
32073207
r32760r32761
32773277   MCFG_TC0100SCN_PALETTE("palette")
32783278
32793279   MCFG_DEVICE_ADD("tc0150rod", TC0150ROD, 0)
3280   
3280
32813281   /* sound hardware */
32823282   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
32833283
r32760r32761
33583358   MCFG_TC0100SCN_PALETTE("palette")
33593359
33603360   MCFG_DEVICE_ADD("tc0150rod", TC0150ROD, 0)
3361   
3361
33623362   /* sound hardware */
33633363   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
33643364
r32760r32761
34343434   MCFG_TC0100SCN_PALETTE("palette")
34353435
34363436   MCFG_DEVICE_ADD("tc0150rod", TC0150ROD, 0)
3437   
3437
34383438   MCFG_TC0110PCR_ADD("tc0110pcr")
34393439   MCFG_TC0110PCR_PALETTE("palette")
34403440
r32760r32761
35143514   MCFG_TC0100SCN_PALETTE("palette")
35153515
35163516   MCFG_DEVICE_ADD("tc0150rod", TC0150ROD, 0)
3517   
3517
35183518   MCFG_TC0110PCR_ADD("tc0110pcr")
35193519   MCFG_TC0110PCR_PALETTE("palette")
35203520
r32760r32761
36643664   MCFG_TC0480SCP_PALETTE("palette")
36653665
36663666   MCFG_DEVICE_ADD("tc0150rod", TC0150ROD, 0)
3667   
3667
36683668   /* sound hardware */
36693669   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
36703670
r32760r32761
37403740   MCFG_TC0480SCP_PALETTE("palette")
37413741
37423742   MCFG_DEVICE_ADD("tc0150rod", TC0150ROD, 0)
3743   
3743
37443744   /* sound hardware */
37453745   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
37463746
trunk/src/mame/drivers/midxunit.c
r32760r32761
245245   MCFG_CPU_PROGRAM_MAP(main_map)
246246   MCFG_TMS340X0_HALT_ON_RESET(FALSE) /* halt on reset */
247247   MCFG_TMS340X0_PIXEL_CLOCK(PIXEL_CLOCK) /* pixel clock */
248   MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */   
248   MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */
249249   MCFG_TMS340X0_SCANLINE_IND16_CB(midxunit_state, scanline_update)       /* scanline updater (indexed16) */
250250   MCFG_TMS340X0_TO_SHIFTREG_CB(midtunit_state, to_shiftreg)           /* write to shiftreg function */
251251   MCFG_TMS340X0_FROM_SHIFTREG_CB(midtunit_state, from_shiftreg)          /* read from shiftreg function */
trunk/src/mame/drivers/macs.c
r32760r32761
8282   DECLARE_DRIVER_INIT(kisekaem);
8383   DECLARE_DRIVER_INIT(macs2);
8484   DECLARE_MACHINE_RESET(macs);
85   
85
8686   UINT32 screen_update_macs(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
8787
8888   optional_device<st0016_cpu_device> m_maincpu;
r32760r32761
149149{
150150   membank("bank1")->set_base(memregion("maincpu")->base() + (data* 0x4000) + macs_cart_slot*0x400000 );
151151
152//   m_st0016_rom_bank=data;
152//  m_st0016_rom_bank=data;
153153}
154154
155155WRITE8_MEMBER(macs_state::macs_output_w)
trunk/src/mame/drivers/alg.c
r32760r32761
769769 *************************************/
770770
771771/* BIOS */
772GAME( 199?, alg_bios,    0,          alg_r1,   alg, alg_state,    ntsc,     ROT0,  "American Laser Games", "American Laser Games BIOS", GAME_IS_BIOS_ROOT )
772GAME( 199?, alg_bios,   0,         alg_r1,   alg, alg_state,    ntsc,     ROT0,  "American Laser Games", "American Laser Games BIOS", GAME_IS_BIOS_ROOT )
773773
774774/* Rev. A board */
775775/* PAL R1 */
776GAME( 1990, maddoga,      maddog,   alg_r1,   alg, alg_state,    palr1,    ROT0,  "American Laser Games", "Mad Dog McCree v1C board rev.A", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
776GAME( 1990, maddoga,    maddog,   alg_r1,   alg, alg_state,    palr1,    ROT0,  "American Laser Games", "Mad Dog McCree v1C board rev.A", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
777777
778778/* PAL R3 */
779GAME( 1991, wsjr,         alg_bios, alg_r1,   alg, alg_state,    palr3,    ROT0,  "American Laser Games", "Who Shot Johnny Rock? v1.6", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
780GAME( 1991, wsjr_15,     wsjr,       alg_r1,   alg, alg_state,    palr3,    ROT0,  "American Laser Games", "Who Shot Johnny Rock? v1.5", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
779GAME( 1991, wsjr,        alg_bios, alg_r1,   alg, alg_state,    palr3,    ROT0,  "American Laser Games", "Who Shot Johnny Rock? v1.6", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
780GAME( 1991, wsjr_15,     wsjr,     alg_r1,   alg, alg_state,    palr3,    ROT0,  "American Laser Games", "Who Shot Johnny Rock? v1.5", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
781781
782782/* Rev. B board */
783783/* PAL R6 */
784784
785GAME( 1990, maddog,       alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Mad Dog McCree v2.03 board rev.B", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
785GAME( 1990, maddog,     alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Mad Dog McCree v2.03 board rev.B", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
786786GAME( 1990, maddog_202,  maddog, alg_r2,   alg_2p, alg_state, palr6,      ROT0,  "American Laser Games", "Mad Dog McCree v2.02 board rev.B", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
787787
788788   /* works ok but uses right player (2) controls only for trigger and holster */
789GAME( 1992, maddog2,      alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Mad Dog II: The Lost Gold v2.04", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
789GAME( 1992, maddog2,    alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Mad Dog II: The Lost Gold v2.04", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
790790GAME( 1992, maddog2_202, maddog2, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Mad Dog II: The Lost Gold v2.02", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
791791GAME( 1992, maddog2_110, maddog2,  alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Mad Dog II: The Lost Gold v1.10", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
792792GAME( 1992, maddog2_100, maddog2,  alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Mad Dog II: The Lost Gold v1.00", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
793793   /* works ok but uses right player (2) controls only for trigger and holster */
794GAME( 1992, spacepir,     alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Space Pirates v2.2", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
794GAME( 1992, spacepir,   alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Space Pirates v2.2", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
795795GAME( 1992, spacepir_14, spacepir, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Space Pirates v1.4", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
796796
797GAME( 1992, gallgall,     alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Gallagher's Gallery v2.2", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
797GAME( 1992, gallgall,   alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Gallagher's Gallery v2.2", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
798798GAME( 1992, gallgall_21, gallgall, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Gallagher's Gallery v2.1", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
799799   /* all good, but no holster */
800GAME( 1993, crimepat,     alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Crime Patrol v1.51", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
800GAME( 1993, crimepat,   alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Crime Patrol v1.51", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
801801GAME( 1993, crimepat_14, crimepat, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Crime Patrol v1.4", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
802802GAME( 1993, crimepat_12, crimepat, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Crime Patrol v1.2", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
803803
804GAME( 1993, crimep2,      alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Crime Patrol 2: Drug Wars v1.3", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
804GAME( 1993, crimep2,    alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Crime Patrol 2: Drug Wars v1.3", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
805805GAME( 1993, crimep2_11,  crimep2,  alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "Crime Patrol 2: Drug Wars v1.1", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
806GAME( 1994, lastbh,         alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "The Last Bounty Hunter v1.01", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
806GAME( 1994, lastbh,      alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "The Last Bounty Hunter v1.01", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
807807GAME( 1994, lastbh_006,  lastbh, alg_r2,   alg_2p, alg_state, palr6,    ROT0,  "American Laser Games", "The Last Bounty Hunter v0.06", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
808GAME( 1995, fastdraw,     alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT90, "American Laser Games", "Fast Draw Showdown v1.31", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
808GAME( 1995, fastdraw,   alg_bios, alg_r2,   alg_2p, alg_state, palr6,    ROT90, "American Laser Games", "Fast Draw Showdown v1.31", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
809809GAME( 1995, fastdraw_130,fastdraw, alg_r2,   alg_2p, alg_state, palr6,    ROT90, "American Laser Games", "Fast Draw Showdown v1.30", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
810810   /* works ok but uses right player (2) controls only for trigger and holster */
811811
trunk/src/mame/drivers/potgoldu.c
r32760r32761
2727   potgold_state(const machine_config &mconfig, device_type type, const char *tag)
2828      : driver_device(mconfig, type, tag),
2929      m_maincpu(*this, "maincpu") { }
30   
30
3131      required_device<cpu_device> m_maincpu;
32   
32
3333   virtual void machine_reset();
3434   virtual void video_start();
35   
35
3636   TMS340X0_SCANLINE_RGB32_CB_MEMBER(scanline_update);
3737};
3838
trunk/src/mame/drivers/mario.c
r32760r32761
186186   //AM_RANGE(0xa000, 0xa000) AM_READ_PORT("IN1")
187187   AM_RANGE(0xa000, 0xa000) AM_READNOP   /* watchdog? */
188188   AM_RANGE(0xa100, 0xa100) AM_READ_PORT("DSW")    /* DSW */
189   AM_RANGE(0xa206, 0xa206) AM_WRITE(mario_gfxbank_w)
189   AM_RANGE(0xa206, 0xa206) AM_WRITE(mario_gfxbank_w)
190190
191191   AM_RANGE(0x8000, 0x9fff) AM_ROM
192192   AM_RANGE(0xb000, 0xbfff) AM_ROM
r32760r32761
457457   16,16,  /* 16*16 sprites */
458458   RGN_FRAC(1,3),    /* 256 sprites */
459459   3,  /* 3 bits per pixel */
460   { RGN_FRAC(2,3),RGN_FRAC(1,3),RGN_FRAC(0,3) },
461   { 0, 1, 2, 3, 4, 5, 6, 7,     
460   { RGN_FRAC(2,3),RGN_FRAC(1,3),RGN_FRAC(0,3) },
461   { 0, 1, 2, 3, 4, 5, 6, 7,
462462         64,65,66,67,68,69,70,71 },
463463   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
464464         16*8, 17*8, 18*8, 19*8, 20*8, 21*8, 22*8, 23*8 },
465   16*16
465   16*16
466466};
467467
468468static GFXDECODE_START( mariobl )
r32760r32761
475475   16,16,  /* 16*16 sprites */
476476   RGN_FRAC(1,2),    /* 256 sprites */
477477   2,  /* 3 bits per pixel */
478   { RGN_FRAC(1,2),RGN_FRAC(0,2) },
479   { 0, 1, 2, 3, 4, 5, 6, 7,     
478   { RGN_FRAC(1,2),RGN_FRAC(0,2) },
479   { 0, 1, 2, 3, 4, 5, 6, 7,
480480         64,65,66,67,68,69,70,71 },
481481   { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
482482         16*8, 17*8, 18*8, 19*8, 20*8, 21*8, 22*8, 23*8 },
483   16*16
483   16*16
484484};
485485
486486static GFXDECODE_START( dkong3abl )
r32760r32761
548548MACHINE_CONFIG_END
549549
550550/*
551Mario Bros japan bootleg on Ambush hardware
551Mario Bros japan bootleg on Ambush hardware
552552
553553This romset (japanese version) comes from a faulty bootleg pcb.Game differences are none.
554554Note:it runs on a modified (extended) Tecfri's Ambush hardware.
r32760r32761
582582
583583   /* sound hardware */
584584   MCFG_SPEAKER_STANDARD_MONO("mono")
585   
585
586586   MCFG_SOUND_ADD("ay1", AY8910, XTAL_18_432MHz/6/2)   /* XTAL confirmed, divisor guessed */
587587   MCFG_AY8910_PORT_A_READ_CB(IOPORT("SYSTEM"))
588//   MCFG_AY8910_PORT_B_WRITE_CB(WRITE8(mario_state, ay1_outputb_w))
588//  MCFG_AY8910_PORT_B_WRITE_CB(WRITE8(mario_state, ay1_outputb_w))
589589
590590   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.33)
591591
592592   MCFG_SOUND_ADD("ay2", AY8910, XTAL_18_432MHz/6/2)   /* XTAL confirmed, divisor guessed */
593593   MCFG_AY8910_PORT_A_READ_CB(IOPORT("INPUTS"))
594//   MCFG_AY8910_PORT_B_WRITE_CB(WRITE8(mario_state, ay2_outputb_w))
594//  MCFG_AY8910_PORT_B_WRITE_CB(WRITE8(mario_state, ay2_outputb_w))
595595
596596   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.33)
597597
trunk/src/mame/drivers/arkanoid.c
r32760r32761
1616                The 68705 code for this one was not available; I made it up from
1717                the current A75-06.IC16 changing the level data pointer table.
1818    arkanoidj   Japanese version.  Final revision, MCU code not dumped.
19   arkanoidja  Japanese version. A later revision with level selector.
19    arkanoidja  Japanese version. A later revision with level selector.
2020                The 68705 code for this one was not available; I made it up from
2121                the current A75-06.IC16 changing the level data pointer table.
2222    arkanoidjbl Bootleg of the early Japanese version. The only difference is
r32760r32761
809809
810810READ8_MEMBER(arkanoid_state::hexaa_f000_r)
811811{
812//   return hexaa_from_sub;
812//  return hexaa_from_sub;
813813   return rand();
814814}
815815
r32760r32761
844844READ8_MEMBER(arkanoid_state::hexaa_sub_90_r)
845845{
846846   return hexaa_from_main;
847//   return rand();
847//  return rand();
848848}
849849
850850static ADDRESS_MAP_START( hexaa_sub_iomap, AS_IO, 8, arkanoid_state )
r32760r32761
853853   AM_RANGE(0x80, 0x80) AM_WRITE(hexaa_sub_80_w)
854854   AM_RANGE(0x90, 0x90) AM_READ(hexaa_sub_90_r)
855855ADDRESS_MAP_END
856   
857856
858857
858
859859static ADDRESS_MAP_START( brixian_map, AS_PROGRAM, 8, arkanoid_state )
860860   AM_RANGE(0x0000, 0xbfff) AM_ROM
861861   AM_RANGE(0xc000, 0xc7ff) AM_RAM AM_SHARE("protram")
r32760r32761
18321832   ROM_LOAD( "sub1.bin",      0x00000, 0x8000, CRC(82c091fa) SHA1(e509ab4d9372f93d81df70772a4632100081ffd7) )
18331833   ROM_LOAD( "main4.bin",     0x10000, 0x8000, CRC(3d5d006c) SHA1(ad4eadab82024b122182eacb5a322cfd6e476a70) )
18341834
1835   ROM_REGION( 0x18000, "subcpu", 0 ) 
1835   ROM_REGION( 0x18000, "subcpu", 0 )
18361836   ROM_LOAD( "sub2.bin",      0x00000, 0x2000, CRC(c3bb9661) SHA1(e4bccb822d6eba77bb9cba75125cddb740775a2c)) // 1ST AND 2ND HALF IDENTICAL (contains just 0x55 bytes of code)
18371837
18381838
trunk/src/mame/drivers/st_mp100.c
r32760r32761
500500   if (!state)
501501      m_counter = 0;
502502}
503     
503
504504WRITE_LINE_MEMBER( st_mp100_state::u10_cb2_w )
505505{
506506}
trunk/src/mame/drivers/peplus.c
r32760r32761
12261226   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Card Cage") PORT_CODE(KEYCODE_M) PORT_TOGGLE
12271227
12281228   PORT_MODIFY("SW1")
1229   PORT_DIPNAME( 0x02, 0x02, "Credit" )      PORT_DIPLOCATION("SW1:2")
1229   PORT_DIPNAME( 0x02, 0x02, "Credit" )        PORT_DIPLOCATION("SW1:2")
12301230   PORT_DIPSETTING(    0x02, "Coin Play" )
12311231   PORT_DIPSETTING(    0x00, "Credit Play" )
1232   PORT_DIPNAME( 0x04, 0x00, "Coin Acceptor" )   PORT_DIPLOCATION("SW1:3")
1232   PORT_DIPNAME( 0x04, 0x00, "Coin Acceptor" ) PORT_DIPLOCATION("SW1:3")
12331233   PORT_DIPSETTING(    0x04, "Mechanical" )
12341234   PORT_DIPSETTING(    0x00, "Optical" )
1235   PORT_DIPNAME( 0x08, 0x08, "Double Up" )      PORT_DIPLOCATION("SW1:4")
1235   PORT_DIPNAME( 0x08, 0x08, "Double Up" )     PORT_DIPLOCATION("SW1:4")
12361236   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
12371237   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1238   PORT_DIPNAME( 0x10, 0x10, "Progressive" )   PORT_DIPLOCATION("SW1:5")
1238   PORT_DIPNAME( 0x10, 0x10, "Progressive" )   PORT_DIPLOCATION("SW1:5")
12391239   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
12401240   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1241   PORT_DIPNAME( 0x60, 0x40, "Max Hopper Pay" )   PORT_DIPLOCATION("SW1:6,7")
1241   PORT_DIPNAME( 0x60, 0x40, "Max Hopper Pay" )    PORT_DIPLOCATION("SW1:6,7")
12421242   PORT_DIPSETTING(    0x60, "300 Coins" )
12431243   PORT_DIPSETTING(    0x40, "400 Coins" )
12441244   PORT_DIPSETTING(    0x20, "600 Coins" )
12451245   PORT_DIPSETTING(    0x00, "1000 Coins" )
1246   PORT_DIPNAME( 0x80, 0x00, "Show Pay Table" )   PORT_DIPLOCATION("SW1:8")
1246   PORT_DIPNAME( 0x80, 0x00, "Show Pay Table" )    PORT_DIPLOCATION("SW1:8")
12471247   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
12481248   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
12491249INPUT_PORTS_END
trunk/src/mame/drivers/segac2.c
r32760r32761
432432    D0 : To CN1 pin 8. (Coin meter 1)
433433   */
434434   //coin_lockout_w(space.machine(), 1, data & 0x08);
435    //coin_lockout_w(space.machine(), 0, data & 0x04);
435   //coin_lockout_w(space.machine(), 0, data & 0x04);
436436   coin_counter_w(space.machine(), 1, data & 0x02);
437437   coin_counter_w(space.machine(), 0, data & 0x01);
438438}
trunk/src/mame/drivers/dlair.c
r32760r32761
769769   DISK_IMAGE_READONLY( "dlair", 0, NO_DUMP )
770770ROM_END
771771
772ROM_START( dlair_2 )     
772ROM_START( dlair_2 )
773773   ROM_REGION( 0xa000, "maincpu", 0 )
774774   ROM_LOAD( "dlu1.bin", 0x0000, 0x2000,  CRC(ea6d5498) SHA1(1d854c04e0074e693e791e22a4c9cc21d5175d95) )
775775   ROM_LOAD( "dlu2.bin", 0x2000, 0x2000,  CRC(ffe84a95) SHA1(675ce2e68e43beb1f389bc6ab1a55bee862a1440) )
trunk/src/mame/drivers/bublbobl.c
r32760r32761
573573
574574static INPUT_PORTS_START( sboblbobl )
575575   PORT_INCLUDE( sboblboblb )
576   
576
577577   PORT_MODIFY( "IN0" )
578578   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_IMPULSE(1)
579579   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_IMPULSE(1)
trunk/src/mame/drivers/simple_st0016.c
r32760r32761
7777WRITE8_MEMBER(st0016_state::st0016_rom_bank_w)
7878{
7979   membank("bank1")->set_base(memregion("maincpu")->base() + (data* 0x4000));
80//   st0016_rom_bank=data;
80//  st0016_rom_bank=data;
8181}
8282
8383static ADDRESS_MAP_START( st0016_io, AS_IO, 8, st0016_state )
r32760r32761
472472   MCFG_SCREEN_PALETTE("maincpu:palette")
473473
474474
475//   MCFG_VIDEO_START_OVERRIDE(st0016_state,st0016)
475//  MCFG_VIDEO_START_OVERRIDE(st0016_state,st0016)
476476
477477MACHINE_CONFIG_END
478478
trunk/src/mame/drivers/snowbros.c
r32760r32761
23682368   ROM_LOAD( "87c52.mcu", 0x00000, 0x10000 , NO_DUMP ) /* can't be dumped */
23692369
23702370   ROM_REGION16_BE( 0x200, "user1", ROMREGION_ERASE00 ) /* Data from Shared RAM */
2371//   ROM_LOAD16_WORD( "protdata.bin", 0x00000, 0x200 , CRC(1) SHA1(1) )
2371//  ROM_LOAD16_WORD( "protdata.bin", 0x00000, 0x200 , CRC(1) SHA1(1) )
23722372
23732373   ROM_REGION( 0x040000, "oki", 0 ) /* Samples */
23742374   ROM_LOAD( "su_ho_sung.uj15", 0x00000, 0x40000, CRC(266fcae8) SHA1(0f15f880bde0c12b5c663ed387f9353c13b731b6) )
trunk/src/mame/drivers/caprcyc.c
r32760r32761
33/***************************************************************************
44
55  Taito Capriccio Cyclone crane hardware
6 
6
77  Main PCB: NEC uPD30200GD-100-MBB VR4300, Galileo GT-64111 (system controller?), ...
88  Sound PCB: Panasonic MN1020819 (has internal ROM), Zoom ZSG-2. No effects DSP!
9 
9
1010  Like most other Taito Capriccio cabinets, it has two cranes. There are
1111  no 7seg leds on the cranes this time, some colour lamps instead.
12 
12
1313TODO:
1414- everything
1515
trunk/src/mame/drivers/pacman.c
r32760r32761
13251325   AM_RANGE(0x8400, 0x87ff) AM_RAM_WRITE(pacman_colorram_w) AM_SHARE("colorram")
13261326
13271327   AM_RANGE(0x8800, 0x8bff) AM_RAM
1328//   AM_RANGE(0x8800, 0x8bff) AM_READ(pacman_read_nop) AM_WRITENOP
1328//  AM_RANGE(0x8800, 0x8bff) AM_READ(pacman_read_nop) AM_WRITENOP
13291329   AM_RANGE(0x8c00, 0x8fef) AM_RAM
13301330   AM_RANGE(0x8ff0, 0x8fff) AM_RAM AM_SHARE("spriteram")
13311331   AM_RANGE(0x9000, 0x9000) AM_WRITE(irq_mask_w)
r32760r32761
29352935   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN1 )
29362936   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START1 )
29372937
2938   PORT_MODIFY("DSW1")
2938   PORT_MODIFY("DSW1")
29392939   PORT_DIPNAME( 0x03, 0x00, DEF_STR( Coinage ) )
29402940   PORT_DIPSETTING(    0x03, DEF_STR( 4C_1C ) )
29412941   PORT_DIPSETTING(    0x02, DEF_STR( 3C_1C ) )
r32760r32761
39523952   ROM_CONTINUE(0x1800,0x800)
39533953
39543954   ROM_REGION( 0x0120, "proms", 0 )
3955   ROM_LOAD( "82s123.h7",    0x0000, 0x0020, CRC(3545e7e9) SHA1(b866b02579438afb11296e5c53a32c6425bd044d) )
3955   ROM_LOAD( "82s123.h7",    0x0000, 0x0020, CRC(3545e7e9) SHA1(b866b02579438afb11296e5c53a32c6425bd044d) )
39563956   ROM_LOAD( "82s129-3.d1",  0x0020, 0x0100, CRC(3eb3a8e4) SHA1(19097b5f60d1030f8b82d9f1d3a241f93e5c75d6) )
39573957
39583958   ROM_REGION( 0x0200, "namco", 0 )    /* sound PROMs */
r32760r32761
42344234   ROM_LOAD( "pengopac.4",      0x4000, 0x1000, CRC(1519d59b) SHA1(13b99780fcccac61b16201500e309c9b442406c8) )
42354235   ROM_LOAD( "pengopac.5",      0x5000, 0x1000, CRC(1b90c32c) SHA1(1761add93d71d29840b1462b9747a3d463b7148d) )
42364236   ROM_LOAD( "pengopac.6",      0x6000, 0x2000, CRC(8d2994ee) SHA1(1f16b32c4574107a4a15d40113b966581b374a81) )
4237   
4237
42384238   ROM_REGION( 0x2000, "gfx1", 0 )
42394239   ROM_LOAD( "pengopac.5e",      0x0000, 0x0800, CRC(ad88978a) SHA1(a568baf751753660223958b722980f031310eba1) )
42404240   ROM_LOAD( "pengopac.5f",      0x0800, 0x0800, CRC(cb208b9f) SHA1(63b64b52c9c3e18b2d2823e79095160fb1a71f00) )
r32760r32761
65446544
65456545   ROM[0x7ffe] = 0xa7;
65466546   ROM[0x7fee] = 0x6d;
6547   
6547
65486548   save_item(NAME(m_rocktrv2_question_bank));
65496549}
65506550
trunk/src/mame/drivers/igs011.c
r32760r32761
9696   optional_device<okim6295_device> m_oki;
9797   required_device<screen_device> m_screen;
9898   required_device<palette_device> m_palette;
99   
99
100100   /* memory pointers */
101101   required_shared_ptr<UINT16> m_priority_ram;
102102   optional_shared_ptr<UINT16> m_vbowl_trackball;
103103   required_shared_ptr<UINT16> m_generic_paletteram_16;
104     
104
105105   UINT8 *m_layer[8];
106106   UINT16 m_priority;
107107   UINT8 m_lhb2_pen_hi;
r32760r32761
277277   }
278278
279279   m_lhb2_pen_hi = 0;
280   
280
281281   save_item(NAME(m_priority));
282282   save_item(NAME(m_lhb2_pen_hi));
283283   save_item(NAME(m_blitter.x));
trunk/src/mame/drivers/mgavegas.c
r32760r32761
22
33    mgavegas.c
44
5    Coin pusher
5    Coin pusher
66
77    TODO
88    -better analog audio out/mixer
9   -some output (mostly not used)
9    -some output (mostly not used)
1010
1111Ver. 1.33 have no speech and no change funcion implemented in software
1212Ver. 2.1 and 2.3 have change function working and speech
1313Ver. 2.2 should exist
14   
14
1515************************************************************************************/
1616
1717#include "emu.h"
r32760r32761
2828*    LOG defines            *
2929****************************/
3030
31#define LOG_AY8910    0
31#define LOG_AY8910 0
3232#define LOG_MSM5205 0
33#define LOG_CSO1   0
34#define LOG_CSO2   0
33#define LOG_CSO1    0
34#define LOG_CSO2    0
3535
3636
3737/****************************
3838*    Clock defines          *
3939****************************/
40#define MAIN_XTAL XTAL_8MHz
40#define MAIN_XTAL XTAL_8MHz
4141#define CPU_CLK MAIN_XTAL/2
4242#define AY_CLK  CPU_CLK/2
4343#define MSM_CLK   384000
r32760r32761
5454      m_ticket(*this, "hopper"),
5555      m_filter1(*this, "filter1"),
5656      m_filter2(*this, "filter2")
57     
58     
57
58
5959   { }
6060   UINT8 m_int;
61   
61
6262   //OUT1
6363   UINT8 m_ckmod;
6464   UINT8 m_dmod;
r32760r32761
6868   UINT8 m_seg;
6969   UINT8 m_printer;
7070   UINT8 m_auxp;
71   
71
7272   //helper...
7373   UINT8 m_old_ckmod;
7474   UINT8 m_old_emod;
r32760r32761
8282   UINT8 m_cont_ent;
8383   UINT8 m_cont_sal;
8484   UINT8 m_cont_caj;
85   
85
8686   //lamps out
8787   UINT64 m_custom_data;
8888   UINT8 m_auxs;
r32760r32761
117117   UINT8 m_ml;
118118   UINT8 m_mc;
119119   UINT8 m_mr;
120   
120
121121   DECLARE_READ8_MEMBER(start_read);
122122
123123   DECLARE_WRITE8_MEMBER(w_a0);
r32760r32761
125125   DECLARE_WRITE8_MEMBER(cso1_w);
126126   DECLARE_WRITE8_MEMBER(cso2_w);
127127   DECLARE_WRITE8_MEMBER(csoki_w);
128   DECLARE_READ8_MEMBER(csoki_r);   
129   
128   DECLARE_READ8_MEMBER(csoki_r);
129
130130   DECLARE_READ8_MEMBER(ay8910_a_r);
131131   DECLARE_READ8_MEMBER(ay8910_b_r);
132   
132
133133   DECLARE_DRIVER_INIT(mgavegas);
134134   DECLARE_DRIVER_INIT(mgavegas21);
135135   DECLARE_DRIVER_INIT(mgavegas133);
136     
136
137137   TIMER_DEVICE_CALLBACK_MEMBER(int_0);
138   
139   
138
139
140140protected:
141141
142142   // devices
r32760r32761
158158
159159
160160void mgavegas_state::update_lamp(){
161
162   //output_set_value("AUXS", m_auxs);   //unused
161   //output_set_value("AUXS", m_auxs); //unused
163162   output_set_value("MGA4", m_anal&0x01);
164163   output_set_value("MGA3", m_anacl&0x01);
165164   output_set_value("MGA2", m_anacr&0x01);
r32760r32761
171170   output_set_value("1002", m_luz_100_rul&0x01);
172171   output_set_value("50", m_luz_50_rlul&0x01);
173172   output_set_value("252", m_luz_25_lrul&0x01);
174   output_set_value("25", m_luz_25_rrul&0x01);   
173   output_set_value("25", m_luz_25_rrul&0x01);
175174   output_set_value("FL", m_fl&0x01);
176175   output_set_value("FC", m_fc&0x01);
177176   output_set_value("FR", m_fr&0x01);
r32760r32761
179178   output_set_value("NOCAMBIO", m_no_cambio&0x01);
180179   output_set_value("FUSE", m_fuse&0x01);
181180   output_set_value("FALTA", m_falta&0x01);
182   //output_set_value("ANAG", m_anag&0x01);   //unused
181   //output_set_value("ANAG", m_anag&0x01);    //unused
183182   output_set_value("CL", m_cl&0x01);
184183   output_set_value("CC", m_cc&0x01);
185184   output_set_value("CR", m_cr&0x01);
r32760r32761
192191   output_set_value("MC", m_mc&0x01);
193192   output_set_value("MR", m_mr&0x01);
194193/*
195   m_inh=BIT(data, 3);
196   m_printer=BIT(data, 6);   //not_used
197   m_auxp=BIT(data, 7);   //not_used
198   
199   m_bobina_ctrl=BIT(data, 0);
200   m_timbre=BIT(data, 1);
201   m_coil_1=BIT(data, 2);
202   m_coil_2=BIT(data, 3);
203   m_coil_3=BIT(data, 4);
204   m_cont_ent=BIT(data, 5);
205   m_cont_sal=BIT(data, 6);
206   m_cont_caj=BIT(data, 7);   
194    m_inh=BIT(data, 3);
195    m_printer=BIT(data, 6); //not_used
196    m_auxp=BIT(data, 7);    //not_used
197
198    m_bobina_ctrl=BIT(data, 0);
199    m_timbre=BIT(data, 1);
200    m_coil_1=BIT(data, 2);
201    m_coil_2=BIT(data, 3);
202    m_coil_3=BIT(data, 4);
203    m_cont_ent=BIT(data, 5);
204    m_cont_sal=BIT(data, 6);
205    m_cont_caj=BIT(data, 7);
207206*/
208207}
209208
r32760r32761
217216   }
218217
219218   if( (m_emod==0) & (m_old_emod==1) ){
220      //valid emod, check for valid data and updatae custom status   this is how the hw works
219      //valid emod, check for valid data and updatae custom status    this is how the hw works
221220      if( (BIT(m_custom_data, 32)==0) && (BIT(m_custom_data, 33)==0) && (BIT(m_custom_data, 34)==0) && (BIT(m_custom_data, 35)==0) ){
222221            tmp=~m_custom_data;
223            m_auxs=         tmp&0x00000001;
224//            m_anal=         (tmp&0x00000002)>>1;   //schematics error!!!
225//            m_anacl=      (tmp&0x00000004)>>2;   //schematics error!!!
226            m_luz_50_rlul=   (tmp&0x00000002)>>1;
227            m_luz_25_lrul=   (tmp&0x00000004)>>2;
228            m_anacr=      (tmp&0x00000008)>>3;   
229            m_anar=         (tmp&0x00000010)>>4;
230            m_pl=         (tmp&0x00000020)>>5;
231            m_pc=         (tmp&0x00000040)>>6;
232            m_pr=         (tmp&0x00000080)>>7;
233            m_luz_250_rul=   (tmp&0x00000100)>>8;
234            m_luz_100_rul=   (tmp&0x00000200)>>9;
235//            m_luz_50_rlul=   (tmp&0x00000400)>>10;   //schematics error!!!
236//            m_luz_25_lrul=   (tmp&0x00000800)>>11;   //schematics error!!!
237            m_anacl=      (tmp&0x00000400)>>10;
238            m_anal=         (tmp&0x00000800)>>11;
239            m_luz_25_rrul=   (tmp&0x00001000)>>12;
240            m_fl=         (tmp&0x00002000)>>13;
241            m_fc=         (tmp&0x00004000)>>14;
242            m_fr=         (tmp&0x00008000)>>15;
243            m_insert_coin=   (tmp&0x00010000)>>16;
244            m_no_cambio=   (tmp&0x00020000)>>17;
245            m_fuse=         (tmp&0x00040000)>>18;
246            m_falta=      (tmp&0x00080000)>>19;
247            m_anag=         (tmp&0x00100000)>>20;
248            m_cl=         (tmp&0x00200000)>>21;
249            m_cc=         (tmp&0x00400000)>>22;
250            m_cr=         (tmp&0x00800000)>>23;
251            m_premio_s=      (tmp&0x01000000)>>24;
252            m_100=         (tmp&0x02000000)>>25;
253            m_200=         (tmp&0x04000000)>>26;
254            m_300=         (tmp&0x08000000)>>27;
255            m_500=         (tmp&0x10000000)>>28;
256            m_ml=         (tmp&0x20000000)>>29;
257            m_mc=         (tmp&0x40000000)>>30;
258            m_mr=         (tmp&0x80000000)>>31;
222            m_auxs=         tmp&0x00000001;
223//              m_anal=         (tmp&0x00000002)>>1;    //schematics error!!!
224//              m_anacl=        (tmp&0x00000004)>>2;    //schematics error!!!
225            m_luz_50_rlul=  (tmp&0x00000002)>>1;
226            m_luz_25_lrul=  (tmp&0x00000004)>>2;
227            m_anacr=        (tmp&0x00000008)>>3;
228            m_anar=         (tmp&0x00000010)>>4;
229            m_pl=           (tmp&0x00000020)>>5;
230            m_pc=           (tmp&0x00000040)>>6;
231            m_pr=           (tmp&0x00000080)>>7;
232            m_luz_250_rul=  (tmp&0x00000100)>>8;
233            m_luz_100_rul=  (tmp&0x00000200)>>9;
234//              m_luz_50_rlul=  (tmp&0x00000400)>>10;   //schematics error!!!
235//              m_luz_25_lrul=  (tmp&0x00000800)>>11;   //schematics error!!!
236            m_anacl=        (tmp&0x00000400)>>10;
237            m_anal=         (tmp&0x00000800)>>11;
238            m_luz_25_rrul=  (tmp&0x00001000)>>12;
239            m_fl=           (tmp&0x00002000)>>13;
240            m_fc=           (tmp&0x00004000)>>14;
241            m_fr=           (tmp&0x00008000)>>15;
242            m_insert_coin=  (tmp&0x00010000)>>16;
243            m_no_cambio=    (tmp&0x00020000)>>17;
244            m_fuse=         (tmp&0x00040000)>>18;
245            m_falta=        (tmp&0x00080000)>>19;
246            m_anag=         (tmp&0x00100000)>>20;
247            m_cl=           (tmp&0x00200000)>>21;
248            m_cc=           (tmp&0x00400000)>>22;
249            m_cr=           (tmp&0x00800000)>>23;
250            m_premio_s=     (tmp&0x01000000)>>24;
251            m_100=          (tmp&0x02000000)>>25;
252            m_200=          (tmp&0x04000000)>>26;
253            m_300=          (tmp&0x08000000)>>27;
254            m_500=          (tmp&0x10000000)>>28;
255            m_ml=           (tmp&0x20000000)>>29;
256            m_mc=           (tmp&0x40000000)>>30;
257            m_mr=           (tmp&0x80000000)>>31;
259258
260259            update_lamp();
261260      }
262261   }
263   
262
264263   m_old_ckmod=m_ckmod;
265264   m_old_emod=m_emod;
266265}
r32760r32761
268267
269268READ8_MEMBER( mgavegas_state::start_read )
270269{
271//   in HW it look for /IOREQ going down to clear the IRQ line
270//  in HW it look for /IOREQ going down to clear the IRQ line
272271   if (m_int){
273272      m_maincpu->set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
274273      m_int=0;
r32760r32761
285284{
286285UINT8 ret=0;
287286
288     
287
289288   switch (offset&0x03)
290289   {
291      case 1: //bdir=0   BC1=1
290      case 1: //bdir=0    BC1=1
292291            ret=m_ay->data_r(space,0);
293292            break;
294      default:
293      default:
295294            if (LOG_AY8910)
296295               logerror("AY 3-8910 area unknow read!!!\n");
297296            break;
298297   }
299   
298
300299   if (LOG_AY8910)
301      logerror("read from %04X return %02X\n",offset+0xa000,ret);   
300      logerror("read from %04X return %02X\n",offset+0xa000,ret);
302301   return ret;
303302}
304303
305304WRITE8_MEMBER(mgavegas_state::w_a0)
306305{
307
308306   if (LOG_AY8910)
309307      logerror("write to %04X data = %02X \n",offset+0xa000,data);
310308
311309   switch (offset&0x03)
312310   {
313      case 0: //bdir=1   bc1=1
311      case 0: //bdir=1    bc1=1
314312            m_ay->address_w(space,0,data );
315313            break;
316      case 2: //bdir=1   bc1=0
314      case 2: //bdir=1    bc1=0
317315            m_ay->data_w(space,0,data );
318316            break;
319317/*
320      case 1: //bdir=0   bc1=1
321            break;
322      case 3: //bdir=0   bc1=0
323            break;
318        case 1: //bdir=0    bc1=1
319                break;
320        case 3: //bdir=0    bc1=0
321                break;
324322*/
325      default:
323      default:
326324            if (LOG_AY8910)
327325               logerror("AY 3-8910 area unknow write!!!\n");
328326            break;
r32760r32761
338336UINT8 ret=0;
339337
340338   if (LOG_MSM5205)
341      logerror("read from %04X return %02X\n",offset+0xc800,ret);   
339      logerror("read from %04X return %02X\n",offset+0xc800,ret);
342340   return ret;
343341}
344342
345343WRITE8_MEMBER(mgavegas_state::csoki_w)
346344{
347
348345   if (LOG_MSM5205)
349346      logerror("MSM5205 write to %04X data = %02X \n",offset+0xc800,data);
350347   m_msm->reset_w(data&0x10>>4);
r32760r32761
357354   int hopper_data = 0x00;
358355   if (LOG_CSO1)
359356      logerror("write to CSO1 data = %02X\n",data);
360     
357
361358   m_ckmod=BIT(data, 0);
362359   m_dmod=BIT(data, 1);
363360   m_emod=BIT(data, 2);
364361   m_inh=BIT(data, 3);
365362   m_hop=BIT(data, 4);
366363   m_seg=BIT(data, 5);
367   m_printer=BIT(data, 6);   //not_used
368   m_auxp=BIT(data, 7);   //not_used
364   m_printer=BIT(data, 6); //not_used
365   m_auxp=BIT(data, 7);    //not_used
369366
370367   update_custom();
371368
r32760r32761
377374{
378375   if (LOG_CSO2)
379376      logerror("write to CSO2 data = %02X\n",data);
380     
377
381378   m_bobina_ctrl=BIT(data, 0);
382379   m_timbre=BIT(data, 1);
383380   m_coil_1=BIT(data, 2);
r32760r32761
411408
412409   if (LOG_AY8910)
413410      logerror("read from port B return %02X\n",ret);
414     
411
415412   return ret;
416413}
417414
r32760r32761
422419static ADDRESS_MAP_START( mgavegas_map, AS_PROGRAM, 8, mgavegas_state )
423420   AM_RANGE(0x0000, 0x7fff) AM_ROM
424421   AM_RANGE(0x8000, 0x9fff) AM_RAM AM_SHARE("nvram")
425   AM_RANGE(0xa000, 0xa003) AM_READWRITE(r_a0,w_a0)         // AY-3-8910
426   AM_RANGE(0xc000, 0xc001) AM_WRITE(cso1_w)               // /CSout1
427   AM_RANGE(0xc400, 0xc401) AM_WRITE(cso2_w)               // /CSout2
428   AM_RANGE(0xc800, 0xc801) AM_READWRITE(csoki_r,csoki_w)      // /CSoki
429   //AM_RANGE(0xcc00, 0xcc01) AM_READWRITE(cso3_r,cso3_w)      // /CSout3 unused
430   //AM_RANGE(0xe000, 0xe003) AM_READWRITE(r_e0,w_e0)         // /CSaux unused
422   AM_RANGE(0xa000, 0xa003) AM_READWRITE(r_a0,w_a0)            // AY-3-8910
423   AM_RANGE(0xc000, 0xc001) AM_WRITE(cso1_w)                   // /CSout1
424   AM_RANGE(0xc400, 0xc401) AM_WRITE(cso2_w)                   // /CSout2
425   AM_RANGE(0xc800, 0xc801) AM_READWRITE(csoki_r,csoki_w)      // /CSoki
426   //AM_RANGE(0xcc00, 0xcc01) AM_READWRITE(cso3_r,cso3_w)      // /CSout3 unused
427   //AM_RANGE(0xe000, 0xe003) AM_READWRITE(r_e0,w_e0)          // /CSaux unused
431428ADDRESS_MAP_END
432429
433430
r32760r32761
443440   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 ) //200ptas in for change with 8 25 ptas coins
444441   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 ) //25 ptas in to play
445442   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN3 ) //100ptas in for change with 4 25 ptas coins
446   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_OTHER )
443   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_OTHER )
447444   PORT_BIT( 0x10, IP_ACTIVE_LOW,IPT_SPECIAL ) PORT_READ_LINE_DEVICE_MEMBER("hopper", ticket_dispenser_device, line_r)
448   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_CODE(KEYCODE_Y) PORT_NAME("25 ptas level")      //"hack" hopper always full
449   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_U) PORT_NAME("Door")     
445   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_CODE(KEYCODE_Y) PORT_NAME("25 ptas level")     //"hack" hopper always full
446   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_U) PORT_NAME("Door")
450447   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_OTHER ) PORT_CODE(KEYCODE_I) PORT_NAME("Channel")
451448
452449   PORT_START("DSW1")
453450   PORT_DIPNAME( 0x07, 0x02, "Percentage" )
454   PORT_DIPSETTING(    0x00, "70%" )   
451   PORT_DIPSETTING(    0x00, "70%" )
455452   PORT_DIPSETTING(    0x01, "70%" )
456453   PORT_DIPSETTING(    0x02, "72%" )
457454   PORT_DIPSETTING(    0x03, "74%" )
r32760r32761
459456   PORT_DIPSETTING(    0x05, "78%" )
460457   PORT_DIPSETTING(    0x06, "80%" )
461458   PORT_DIPSETTING(    0x07, "82%" )
462   
459
463460   PORT_DIPNAME( 0x08, 0x08, "Sound" )
464461   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
465462   PORT_DIPSETTING(    0x00, DEF_STR( On )  )
466   
463
467464   PORT_DIPNAME( 0x10, 0x10, "Speech" )
468465   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
469466   PORT_DIPSETTING(    0x00, DEF_STR( On )  )
470   
467
471468   PORT_DIPNAME( 0x60, 0x00, "Jackpot" )
472469   PORT_DIPSETTING(    0x40, "Jackpot 1%" )
473470   PORT_DIPSETTING(    0x60, "Jackpot 2,5%" )
474471   PORT_DIPSETTING(    0x00, "Jackpot 5%" )
475   //PORT_DIPSETTING(    0x20, DEF_STR( On ) )   //unlisted
476   
472   //PORT_DIPSETTING(    0x20, DEF_STR( On ) ) //unlisted
473
477474   PORT_DIPNAME( 0x80, 0x80, "Reset" )
478475   PORT_DIPSETTING(    0x80, "Normal Gameplay" )
479476   PORT_DIPSETTING(    0x00, "Reset" )
480   
477
481478INPUT_PORTS_END
482479
483480/******************************
r32760r32761
486483
487484void mgavegas_state::machine_reset()
488485{
489
490486   m_int=1;
491487   m_custom_data=U64(0xffffffffffffffff);
492   
488
493489   m_old_ckmod=1;
494490   m_old_emod=0;
495491
r32760r32761
501497   m_seg=0;
502498   m_printer=0;
503499   m_auxp=0;
504   
505   
500
501
506502   m_bobina_ctrl=0;
507503   m_timbre=0;
508504   m_coil_1=0;
r32760r32761
511507   m_cont_ent=0;
512508   m_cont_sal=0;
513509   m_cont_caj=0;
514   
510
515511   m_auxs=0;
516512   m_anal=0;
517513   m_anacl=0;
r32760r32761
543539   m_500=0;
544540   m_ml=0;
545541   m_mc=0;
546   m_mr=0;   
542   m_mr=0;
547543
548   m_filter1->filter_rc_set_RC(FLT_RC_LOWPASS, 1000, 0, 0, CAP_N(1) );    /* RC out of MSM5205 R=1K C=1nF */
549   m_filter2->filter_rc_set_RC(FLT_RC_HIGHPASS, 3846, 0, 0, CAP_N(100 ));   /*ALP3B active-hybrid filter fc=2.6Khz 2poles???*/
544   m_filter1->filter_rc_set_RC(FLT_RC_LOWPASS, 1000, 0, 0, CAP_N(1) );     /* RC out of MSM5205 R=1K C=1nF */
545   m_filter2->filter_rc_set_RC(FLT_RC_HIGHPASS, 3846, 0, 0, CAP_N(100 ));  /*ALP3B active-hybrid filter fc=2.6Khz 2poles???*/
550546}
551547
552548
r32760r32761
578574DRIVER_INIT_MEMBER(mgavegas_state,mgavegas133)
579575{
580576   //hack to clear the irq on reti instruction
581   m_maincpu->space(AS_PROGRAM).install_read_handler(0x00dd, 0x00dd, read8_delegate(FUNC(mgavegas_state::start_read), this));   
577   m_maincpu->space(AS_PROGRAM).install_read_handler(0x00dd, 0x00dd, read8_delegate(FUNC(mgavegas_state::start_read), this));
582578}
583579
584580/*************************
r32760r32761
588584
589585static MACHINE_CONFIG_START( mgavegas, mgavegas_state )
590586   /* basic machine hardware */
591   MCFG_CPU_ADD("maincpu", Z80, CPU_CLK)
587   MCFG_CPU_ADD("maincpu", Z80, CPU_CLK)
592588   MCFG_CPU_PROGRAM_MAP(mgavegas_map)
593   
589
594590   MCFG_TIMER_DRIVER_ADD_PERIODIC("int_0", mgavegas_state, int_0, attotime::from_hz(6000))  //6KHz from MSM5205 /VCK
595   
591
596592   MCFG_NVRAM_ADD_1FILL("nvram")
597   
593
598594   MCFG_TICKET_DISPENSER_ADD("hopper",attotime::from_msec(200),TICKET_MOTOR_ACTIVE_HIGH,TICKET_STATUS_ACTIVE_LOW);
599595
600596   /* sound hardware */
601   
597
602598   MCFG_SPEAKER_STANDARD_MONO("mono")
603599   MCFG_SOUND_ADD("aysnd", AY8910, AY_CLK)
604600   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.3)
605601   MCFG_AY8910_PORT_A_READ_CB(READ8(mgavegas_state, ay8910_a_r))
606602   MCFG_AY8910_PORT_B_READ_CB(READ8(mgavegas_state, ay8910_b_r))
607   
608   MCFG_SOUND_ADD("5205", MSM5205, MSM_CLK) 
609   MCFG_MSM5205_PRESCALER_SELECTOR(MSM5205_S64_4B)
603
604   MCFG_SOUND_ADD("5205", MSM5205, MSM_CLK)
605   MCFG_MSM5205_PRESCALER_SELECTOR(MSM5205_S64_4B)
610606   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "filter1", 2.0)
611   
612607
608
613609   MCFG_FILTER_RC_ADD("filter1", 0)
614610   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "filter2",2.0)
615611   MCFG_FILTER_RC_ADD("filter2", 0)
616612   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 2.0)
617613
618   
614
619615   /* Video */
620616   MCFG_DEFAULT_LAYOUT(layout_mgavegas)
621   
617
622618MACHINE_CONFIG_END
623619
624620
r32760r32761
630626ROM_START(mgavegas)
631627   ROM_REGION(0x8000, "maincpu", 0)
632628   ROM_LOAD("vegas1-k2.3.bin", 0x0000, 0x8000, CRC(418b1d04) SHA1(27669a85ed52d5dab25d6ebea6ef3d9b01a4795d) )
633   
634   ROM_REGION( 0x2000, "nvram", 0 )
629
630   ROM_REGION( 0x2000, "nvram", 0 )
635631   ROM_LOAD( "mgavegas23.nv", 0x0000, 0x2000, CRC(d0a175b0) SHA1(7698135dbc020f459fdaa660bf488595b67b77d0) )  //default setting
636632ROM_END
637633
638634ROM_START(mgavegas21)
639635   ROM_REGION(0x8000, "maincpu", 0)
640636   ROM_LOAD("vegas1-2.1.bin", 0x0000, 0x8000, CRC(a7e988a4) SHA1(32fa1684c79f4a132553fa41006f243d4b51cef6) )
641   
642   ROM_REGION( 0x2000, "nvram", 0 )
637
638   ROM_REGION( 0x2000, "nvram", 0 )
643639   ROM_LOAD( "mgavegas21.nv", 0x0000, 0x2000, CRC(a4471550) SHA1(b8527e9158b5563460febd1009b44c8d74dbae4e) )  //default setting
644640ROM_END
645641
646642ROM_START(mgavegas133)
647643   ROM_REGION(0x8000, "maincpu", 0)
648644   ROM_LOAD("vegas1-1.33.bin", 0x0000, 0x8000, CRC(1eea7f0f) SHA1(6fb54b8e2ab19e5378a95192e5007175ad76bc7a) )
649   
650   ROM_REGION( 0x2000, "nvram", 0 )
645
646   ROM_REGION( 0x2000, "nvram", 0 )
651647   ROM_LOAD( "mgavegas133.nv", 0x0000, 0x2000, CRC(20fe4db7) SHA1(887b69468ac7e6490827a06cd1f0ff15228a9c73) )  //default setting
652648ROM_END
653649
r32760r32761
655651/*************************
656652*      Game Drivers      *
657653*************************/
658/*    YEAR  NAME            PARENT        MACHINE   INPUT     STATE          INIT          ROT     COMPANY     FULLNAME    FLAGS*/
659GAME( 1985, mgavegas,       0,         mgavegas, mgavegas, mgavegas_state, mgavegas,    ROT0,   "MGA",    "Vegas 1 (Ver 2.3 dual coin pulse, shorter)", GAME_MECHANICAL )
660GAME( 1985, mgavegas21,      mgavegas,     mgavegas, mgavegas, mgavegas_state, mgavegas21, ROT0,   "MGA",    "Vegas 1 (Ver 2.1 dual coin pulse, longer)", GAME_MECHANICAL )
661GAME( 1985, mgavegas133,    mgavegas,     mgavegas, mgavegas, mgavegas_state, mgavegas133,ROT0,   "MGA",    "Vegas 1 (Ver 1.33 single coin pulse)", GAME_MECHANICAL )
654/*    YEAR  NAME            PARENT      MACHINE   INPUT     STATE          INIT         ROT     COMPANY     FULLNAME    FLAGS*/
655GAME( 1985, mgavegas,       0,          mgavegas, mgavegas, mgavegas_state, mgavegas,   ROT0,   "MGA",    "Vegas 1 (Ver 2.3 dual coin pulse, shorter)", GAME_MECHANICAL )
656GAME( 1985, mgavegas21,     mgavegas,   mgavegas, mgavegas, mgavegas_state, mgavegas21, ROT0,   "MGA",    "Vegas 1 (Ver 2.1 dual coin pulse, longer)", GAME_MECHANICAL )
657GAME( 1985, mgavegas133,    mgavegas,   mgavegas, mgavegas, mgavegas_state, mgavegas133,ROT0,   "MGA",    "Vegas 1 (Ver 1.33 single coin pulse)", GAME_MECHANICAL )
trunk/src/mame/drivers/coinmvga.c
r32760r32761
187187
188188  - Added Colorama (P521 V13, Spanish).
189189  - Changed the Colorama parent set description to Colorama (P521, English).
190  - Added technical notes.         
190  - Added technical notes.
191191
192192
193193  [2009-08-18]
trunk/src/mame/drivers/bfm_sc1.c
r32760r32761
10541054   MCFG_CPU_PERIODIC_INT_DRIVER(bfm_sc1_state, timer_irq,  1000)               // generate 1000 IRQ's per second
10551055   MCFG_WATCHDOG_TIME_INIT(PERIOD_OF_555_MONOSTABLE(120000,100e-9))
10561056
1057   
1057
10581058   MCFG_BFMBD1_ADD("vfd0",0)
10591059   MCFG_SPEAKER_STANDARD_MONO("mono")
10601060   MCFG_SOUND_ADD("aysnd",AY8912, MASTER_CLOCK/4)
trunk/src/mame/drivers/galpani3.c
r32760r32761
8585      m_priority_buffer(*this, "priority_buffer"),
8686      m_sprregs(*this, "sprregs"),
8787      m_sprite_bitmap_1(1024, 1024)
88     
88
8989   { }
9090
9191   required_device<cpu_device> m_maincpu;
r32760r32761
9494   required_device<kaneko_grap2_device> m_grap2_2;
9595   required_device<palette_device> m_palette;
9696   required_device<sknsspr_device> m_spritegen;
97   
97
9898   required_shared_ptr<UINT16> m_paletteram;
9999   optional_shared_ptr<UINT16> m_spriteram;
100100   required_shared_ptr<UINT16> m_priority_buffer;
101101   required_shared_ptr<UINT16> m_sprregs;
102102
103103   bitmap_ind16 m_sprite_bitmap_1;
104   
104
105105   UINT16 m_priority_buffer_scrollx;
106106   UINT16 m_priority_buffer_scrolly;
107107
trunk/src/mame/drivers/skimaxx.c
r32760r32761
5555   required_device<cpu_device> m_maincpu;
5656   required_device<cpu_device> m_subcpu;
5757   required_device<tms34010_device> m_tms;
58   
58
5959   required_shared_ptr<UINT32> m_blitter_regs;
6060   required_shared_ptr<UINT32> m_fpga_ctrl;
6161   required_shared_ptr<UINT16> m_fg_buffer;
62   
62
6363   UINT32 *m_bg_buffer;
6464   UINT32 *m_bg_buffer_front;
6565   UINT32 *m_bg_buffer_back;
r32760r32761
6969   UINT32 m_blitter_src_dx;
7070   UINT32 m_blitter_src_y;
7171   UINT32 m_blitter_src_dy;
72   
72
7373   DECLARE_WRITE32_MEMBER(skimaxx_blitter_w);
7474   DECLARE_READ32_MEMBER(skimaxx_blitter_r);
7575   DECLARE_WRITE32_MEMBER(skimaxx_fpga_ctrl_w);
r32760r32761
7979   DECLARE_WRITE32_MEMBER(skimaxx_sub_ctrl_w);
8080   DECLARE_READ32_MEMBER(skimaxx_analog_r);
8181   DECLARE_WRITE_LINE_MEMBER(tms_irq);
82   
82
8383   TMS340X0_TO_SHIFTREG_CB_MEMBER(to_shiftreg);
8484   TMS340X0_FROM_SHIFTREG_CB_MEMBER(from_shiftreg);
8585   TMS340X0_SCANLINE_IND16_CB_MEMBER(scanline_update);
86   
86
8787   virtual void machine_reset();
8888   virtual void video_start();
8989};
trunk/src/mame/drivers/xtheball.c
r32760r32761
327327   MCFG_CPU_PROGRAM_MAP(main_map)
328328   MCFG_TMS340X0_HALT_ON_RESET(FALSE) /* halt on reset */
329329   MCFG_TMS340X0_PIXEL_CLOCK(10000000) /* pixel clock */
330   MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */   
330   MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */
331331   MCFG_TMS340X0_SCANLINE_RGB32_CB(xtheball_state, scanline_update)     /* scanline updater (rgb32) */
332332   MCFG_TMS340X0_TO_SHIFTREG_CB(xtheball_state, to_shiftreg)  /* write to shiftreg function */
333333   MCFG_TMS340X0_FROM_SHIFTREG_CB(xtheball_state, from_shiftreg) /* read from shiftreg function */
trunk/src/mame/drivers/punchout.c
r32760r32761
234234{
235235   // d0-d3: D0-D3 to RP5C01
236236   m_rtc->write(space, offset >> 4 & 0xf, data & 0xf);
237   
237
238238   // d0: 74LS74 1D + 74LS74 2D
239239   // 74LS74 1Q -> RP5H01 DATA CLOCK + TEST
240240   // 74LS74 2Q -> RP5H01 RESET
r32760r32761
516516   1110 1xxx  20 20 0*
517517
518518   1111 xxxx  "Freeplay"
519   
519
520520   0*: Not a "Freeplay": you MUST insert a coin!
521521
522522   */
r32760r32761
682682   MCFG_DEVICE_ADD("rtc", RP5C01, 0) // OSCIN -> Vcc
683683   MCFG_RP5C01_REMOVE_BATTERY()
684684   MCFG_RP5H01_ADD("rp5h01")
685   
685
686686   MCFG_MACHINE_RESET_OVERRIDE(punchout_state, spnchout)
687687MACHINE_CONFIG_END
688688
r32760r32761
743743   ROM_CONTINUE(             0x03800, 0x0800 )
744744
745745   ROM_REGION( 0x30000, "gfx3", ROMREGION_ERASEFF )
746   ROM_LOAD( "chp1-v.2r",    0x00000, 0x4000, CRC(bd1d4b2e) SHA1(492ae301a9890c2603d564c9048b1b67895052dd) )   /* chars #3 */ /* Labeled Rev B, but same as Rev A */
746   ROM_LOAD( "chp1-v.2r",    0x00000, 0x4000, CRC(bd1d4b2e) SHA1(492ae301a9890c2603d564c9048b1b67895052dd) )   /* chars #3 */ /* Labeled Rev B, but same as Rev A */
747747   ROM_LOAD( "chp1-v.2t",    0x04000, 0x4000, CRC(dd9a688a) SHA1(fbb98eebfbaab445928da939846a2d07a8046afb) )
748748   ROM_LOAD( "chp1-v.2u",    0x08000, 0x2000, CRC(da6a3c4b) SHA1(e03469fb6f552f41a9b7f4b3e51c15a52b61cf84) )
749749   /* 0a000-0bfff empty (space for 16k ROM) */
r32760r32761
762762   /* 2c000-2ffff empty (4v doesn't exist, it is seen as a 0xff fill) */
763763
764764   ROM_REGION( 0x10000, "gfx4", ROMREGION_ERASEFF )
765   ROM_LOAD( "chp1-v.6p",    0x00000, 0x0800, CRC(75be7aae) SHA1(396bc1d301b99e064de4dad699882618b1b9c958) )   /* chars #4 */ /* Revision B */
765   ROM_LOAD( "chp1-v.6p",    0x00000, 0x0800, CRC(75be7aae) SHA1(396bc1d301b99e064de4dad699882618b1b9c958) )   /* chars #4 */ /* Revision B */
766766   ROM_CONTINUE(             0x01000, 0x0800 )
767767   ROM_CONTINUE(             0x00800, 0x0800 )
768768   ROM_CONTINUE(             0x01800, 0x0800 )
769   ROM_LOAD( "chp1-v.6n",    0x02000, 0x0800, CRC(daf74de0) SHA1(9373d4527b675b3128a5a830f42e1dc5dcb85307) )   /* Revision B */
769   ROM_LOAD( "chp1-v.6n",    0x02000, 0x0800, CRC(daf74de0) SHA1(9373d4527b675b3128a5a830f42e1dc5dcb85307) )   /* Revision B */
770770   ROM_CONTINUE(             0x03000, 0x0800 )
771771   ROM_CONTINUE(             0x02800, 0x0800 )
772772   ROM_CONTINUE(             0x03800, 0x0800 )
773773   /* 04000-07fff empty (space for 6l and 6k) */
774   ROM_LOAD( "chp1-v.8p",    0x08000, 0x0800, CRC(4cb7ea82) SHA1(213b7c1431f4c92e5519a8771035bda28b3bab8a) )   /* Revision B */
774   ROM_LOAD( "chp1-v.8p",    0x08000, 0x0800, CRC(4cb7ea82) SHA1(213b7c1431f4c92e5519a8771035bda28b3bab8a) )   /* Revision B */
775775   ROM_CONTINUE(             0x09000, 0x0800 )
776776   ROM_CONTINUE(             0x08800, 0x0800 )
777777   ROM_CONTINUE(             0x09800, 0x0800 )
778   ROM_LOAD( "chp1-v.8n",    0x0a000, 0x0800, CRC(1c0d09aa) SHA1(3276bae7400453f3612f53d7b47fb199cbe53e6d) )   /* Revision B */
778   ROM_LOAD( "chp1-v.8n",    0x0a000, 0x0800, CRC(1c0d09aa) SHA1(3276bae7400453f3612f53d7b47fb199cbe53e6d) )   /* Revision B */
779779   ROM_CONTINUE(             0x0b000, 0x0800 )
780780   ROM_CONTINUE(             0x0a800, 0x0800 )
781781   ROM_CONTINUE(             0x0b800, 0x0800 )
r32760r32761
798798   ROM_LOAD( "chp1-b-8f_white.8f", 0x1a00, 0x0200, CRC(1ffd894a) SHA1(9e8c1c28b4c12acf42f814bc109d353729a25652) )  /* B */
799799   ROM_LOAD( "chp1-v-2d.2d",       0x2000, 0x0100, CRC(71dc0d48) SHA1(dd6609f547d74887f520d7e71a1a00317ff181d0) )  /* timing - not used */
800800
801   ROM_REGION( 0x4000, "vlm", 0 )   /* 16k for the VLM5030 data */
801   ROM_REGION( 0x4000, "vlm", 0 )  /* 16k for the VLM5030 data */
802802   ROM_LOAD( "chp1-c.6p",    0x0000, 0x4000, CRC(ea0bbb31) SHA1(b1da024cb688341d39791a78d1144fe09acb00cf) )
803803ROM_END
804804
r32760r32761
11841184   ROM_LOAD( "chs1-b-8f_white.8f", 0x1a00, 0x0200, CRC(1663eed7) SHA1(90ff876a6b885f8a80c17531cde8b91864f1a6a5) )  /* B */
11851185   ROM_LOAD( "chs1-v.2d",          0x2000, 0x0100, CRC(71dc0d48) SHA1(dd6609f547d74887f520d7e71a1a00317ff181d0) )  /* timing - not used */
11861186
1187   ROM_REGION( 0x4000, "vlm", 0 )   /* 16k for the VLM5030 data */
1187   ROM_REGION( 0x4000, "vlm", 0 )  /* 16k for the VLM5030 data */
11881188   ROM_LOAD( "chs1-c.6p",    0x0000, 0x4000, CRC(ad8b64b8) SHA1(0f1232a10faf71b782f9f6653cca8570243c17e0) )
11891189ROM_END
11901190
trunk/src/mame/drivers/maxaflex.c
r32760r32761
7373   TIMER_DEVICE_CALLBACK_MEMBER(mcu_timer_proc);
7474   int atari_input_disabled();
7575   virtual void machine_reset();
76   //required_device<cpu_device> m_maincpu;   // maincpu is already contained in atari_common_state
76   //required_device<cpu_device> m_maincpu;    // maincpu is already contained in atari_common_state
7777   required_device<cpu_device> m_mcu;
7878   required_device<speaker_sound_device> m_speaker;
7979   required_memory_region m_region_maincpu;
r32760r32761
408408   m_portC_in = m_portC_out = m_ddrC = 0;
409409   m_tdr = m_tcr = 0;
410410   m_mcu_timer = machine().device<timer_device>("mcu_timer");
411   
411
412412   output_set_lamp_value(0, 0);
413413   output_set_lamp_value(1, 0);
414414   output_set_lamp_value(2, 0);
trunk/src/mame/drivers/nmk16.c
r32760r32761
7272- Vandyke: Many enemies make very strange sounds because they seem to have no
7373  rate limit for making their sound effect. This is normal, it's like this on all
7474  PCB recordings.
75 
7675
76
7777----
7878
7979tdragon and hachamf test mode:
r32760r32761
354354   AM_RANGE(0x080002, 0x080003) AM_READ_PORT("IN1")
355355   AM_RANGE(0x080008, 0x080009) AM_READ_PORT("DSW1")
356356   AM_RANGE(0x08000a, 0x08000b) AM_READ_PORT("DSW2")
357//   AM_RANGE(0x08000e, 0x08000f) AM_DEVREAD8("nmk004", nmk004_device, read, 0x00ff)
357//  AM_RANGE(0x08000e, 0x08000f) AM_DEVREAD8("nmk004", nmk004_device, read, 0x00ff)
358358   AM_RANGE(0x080016, 0x080017) AM_WRITENOP    /* IRQ enable? */
359359   AM_RANGE(0x080018, 0x080019) AM_WRITE(nmk_tilebank_w)
360360   AM_RANGE(0x080010, 0x08001d) AM_WRITE(vandykeb_scroll_w) /* 10, 12, 1a, 1c */
361//   AM_RANGE(0x08001e, 0x08001f) AM_DEVWRITE8("nmk004", nmk004_device, write, 0x00ff)
361//  AM_RANGE(0x08001e, 0x08001f) AM_DEVWRITE8("nmk004", nmk004_device, write, 0x00ff)
362362   AM_RANGE(0x088000, 0x0887ff) AM_RAM_DEVWRITE("palette", palette_device, write) AM_SHARE("palette")
363363   AM_RANGE(0x08c000, 0x08c007) AM_WRITENOP    /* just in case... */
364364   AM_RANGE(0x090000, 0x093fff) AM_RAM_WRITE(nmk_bgvideoram0_w) AM_SHARE("nmk_bgvideoram0")
r32760r32761
625625      case 0xe51e/2: PROT_INPUT(0xe51e/2,0x0f82,0xe008/2,0x00080008); break;
626626      case 0xe6b4/2: PROT_INPUT(0xe6b4/2,0x79be,0xe00c/2,0x0008000a); break;
627627      case 0xe10e/2: PROT_JSR(0xe10e,0x8007,0x870a);//870a not 9d66
628                  PROT_JSR(0xe10e,0x8000,0xd9c6); break;
628                  PROT_JSR(0xe10e,0x8000,0xd9c6); break;
629629      case 0xe11e/2: PROT_JSR(0xe11e,0x8038,DUMMYA);//972a - (unused)
630                  PROT_JSR(0xe11e,0x8031,0x7a54); break;
630                  PROT_JSR(0xe11e,0x8031,0x7a54); break;
631631      case 0xe12e/2: PROT_JSR(0xe12e,0x8019,0x9642);//OK-9642
632                   PROT_JSR(0xe12e,0x8022,0xda06); break;
632                  PROT_JSR(0xe12e,0x8022,0xda06); break;
633633      case 0xe13e/2: PROT_JSR(0xe13e,0x802a,0x9d66);//9d66 not 9400 - OK
634                  PROT_JSR(0xe13e,0x8013,0x81aa); break;
634                  PROT_JSR(0xe13e,0x8013,0x81aa); break;
635635      case 0xe14e/2: PROT_JSR(0xe14e,0x800b,0xb3f2);//b3f2 - OK
636                  PROT_JSR(0xe14e,0x8004,0x8994); break;
636                  PROT_JSR(0xe14e,0x8004,0x8994); break;
637637      case 0xe15e/2: PROT_JSR(0xe15e,0x803c,0xb59e);//b59e - OK
638                  PROT_JSR(0xe15e,0x8035,0x8c36); break;
638                  PROT_JSR(0xe15e,0x8035,0x8c36); break;
639639      case 0xe16e/2: PROT_JSR(0xe16e,0x801d,0x9ac2);//9ac2 - OK
640                   PROT_JSR(0xe16e,0x8026,0x8d0c); break;
640                  PROT_JSR(0xe16e,0x8026,0x8d0c); break;
641641      case 0xe17e/2: PROT_JSR(0xe17e,0x802e,0xc366);//c366 - OK
642                  PROT_JSR(0xe17e,0x8017,0x870a); break;
642                  PROT_JSR(0xe17e,0x8017,0x870a); break;
643643      case 0xe18e/2: PROT_JSR(0xe18e,0x8004,DUMMYA);        //unused
644                  PROT_JSR(0xe18e,0x8008,DUMMYA); break; //unused
644                  PROT_JSR(0xe18e,0x8008,DUMMYA); break; //unused
645645      case 0xe19e/2: PROT_JSR(0xe19e,0x8030,0xd9c6);//OK-d9c6
646                  PROT_JSR(0xe19e,0x8039,0x9642); break;
646                  PROT_JSR(0xe19e,0x8039,0x9642); break;
647647      case 0xe1ae/2: PROT_JSR(0xe1ae,0x8011,0x7a54);//d1f8 not c67e
648                  PROT_JSR(0xe1ae,0x802a,0x9d66); break;
648                  PROT_JSR(0xe1ae,0x802a,0x9d66); break;
649649      case 0xe1be/2: PROT_JSR(0xe1be,0x8022,0xda06);//da06
650                  PROT_JSR(0xe1be,0x801b,0xb3f2); break;
650                  PROT_JSR(0xe1be,0x801b,0xb3f2); break;
651651      case 0xe1ce/2: PROT_JSR(0xe1ce,0x8003,0x81aa);//81aa
652                  PROT_JSR(0xe1ce,0x800c,0xb59e); break;
652                  PROT_JSR(0xe1ce,0x800c,0xb59e); break;
653653      case 0xe1de/2: PROT_JSR(0xe1de,0x8034,0x8994);//8994 - OK
654                  PROT_JSR(0xe1de,0x803d,0x9ac2); break;
654                  PROT_JSR(0xe1de,0x803d,0x9ac2); break;
655655      case 0xe1ee/2: PROT_JSR(0xe1ee,0x8015,0x8c36);//8d0c not 82f6
656                  PROT_JSR(0xe1ee,0x802e,0xc366); break;
656                  PROT_JSR(0xe1ee,0x802e,0xc366); break;
657657      case 0xe1fe/2: PROT_JSR(0xe1fe,0x8026,0x8d0c);//8c36
658                  PROT_JSR(0xe1fe,0x8016,DUMMYA); break;  //unused
658                  PROT_JSR(0xe1fe,0x8016,DUMMYA); break;  //unused
659659      case 0xef00/2:
660660         if(m_mainram[0xef00/2] == 0x60fe)
661661         {
r32760r32761
667667         }
668668         break;
669669   }
670#undef DUMMYA   
670#undef DUMMYA
671671}
672672
673673
r32760r32761
38093809 |   | DMA | |
38103810
38113811 CPU is stopped during DMA
3812
3812
38133813 */
38143814
38153815// todo:total scanlines is 263, adjust according to that!
r32760r32761
38203820   const int IRQ1_SCANLINE = 25; // guess
38213821   const int VBIN_SCANLINE = 0;
38223822   const int VBOUT_sCANLINE = 240;
3823   const int SPRDMA_SCANLINE = 241; // 256 USEC after VBOUT
3823   const int SPRDMA_SCANLINE = 241; // 256 USEC after VBOUT
38243824
38253825   int scanline = param;
38263826
3827   if(scanline == VBOUT_sCANLINE) // vblank-out irq
3828      m_maincpu->set_input_line(4, HOLD_LINE);
3827   if(scanline == VBOUT_sCANLINE) // vblank-out irq
3828      m_maincpu->set_input_line(4, HOLD_LINE);
38293829
3830   if (scanline == SPRDMA_SCANLINE)
3831   {
3832      // 2 buffers confirmed on PCB
3833      memcpy(m_spriteram_old2,m_spriteram_old, 0x1000);
3834      memcpy(m_spriteram_old, m_mainram + m_sprdma_base / 2, 0x1000);
3835   }
3830   if (scanline == SPRDMA_SCANLINE)
3831   {
3832      // 2 buffers confirmed on PCB
3833      memcpy(m_spriteram_old2,m_spriteram_old, 0x1000);
3834      memcpy(m_spriteram_old, m_mainram + m_sprdma_base / 2, 0x1000);
3835   }
38363836
3837   /* Vblank-in irq, Vandyke definitely relies that irq fires at scanline ~0 instead of 112 (as per previous
3838      cpu_getiloops function implementation), mostly noticeable with sword collisions and related attract mode behaviour. */
3839   if(scanline == VBIN_SCANLINE)
3840      m_maincpu->set_input_line(2, HOLD_LINE);
3837   /* Vblank-in irq, Vandyke definitely relies that irq fires at scanline ~0 instead of 112 (as per previous
3838     cpu_getiloops function implementation), mostly noticeable with sword collisions and related attract mode behaviour. */
3839   if(scanline == VBIN_SCANLINE)
3840      m_maincpu->set_input_line(2, HOLD_LINE);
38413841
3842  /* time from IRQ2 to first IRQ1 fire. is not stated, 25 is a guess */
3843   if(scanline == IRQ1_SCANLINE)
3844      m_maincpu->set_input_line(1, HOLD_LINE);
3842   /* time from IRQ2 to first IRQ1 fire. is not stated, 25 is a guess */
3843   if(scanline == IRQ1_SCANLINE)
3844      m_maincpu->set_input_line(1, HOLD_LINE);
38453845
3846  /* 8.9ms from first IRQ1 to second IRQ1 fire. approx 128 lines (half frame time) */
3847   if(scanline == IRQ1_SCANLINE+(NUM_SCANLINES/2)) // if this happens too late bioship sprites will glitch on the left edge
3848      m_maincpu->set_input_line(1, HOLD_LINE);
3846   /* 8.9ms from first IRQ1 to second IRQ1 fire. approx 128 lines (half frame time) */
3847   if(scanline == IRQ1_SCANLINE+(NUM_SCANLINES/2)) // if this happens too late bioship sprites will glitch on the left edge
3848      m_maincpu->set_input_line(1, HOLD_LINE);
38493849}
38503850
38513851#define NMK_HACKY_INTERRUPT_TIMING \
3852   MCFG_TIMER_DRIVER_ADD_SCANLINE("scantimer", nmk16_state, nmk16_scanline, "screen", 0, 1) \
3853
3852   MCFG_TIMER_DRIVER_ADD_SCANLINE("scantimer", nmk16_state, nmk16_scanline, "screen", 0, 1)
38543853#define NMK_HACKY_SCREEN_LOWRES \
38553854   MCFG_SCREEN_ADD("screen", RASTER) \
38563855   MCFG_SCREEN_REFRESH_RATE(56.18) \
r32760r32761
38843883   /* video hardware */
38853884   NMK_HACKY_SCREEN_LOWRES
38863885   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_tharrier)
3887   
38883886
3887
38893888   MCFG_GFXDECODE_ADD("gfxdecode", "palette", tharrier)
38903889   MCFG_PALETTE_ADD("palette", 512)
38913890   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
39183917   /* video hardware */
39193918   NMK_HACKY_SCREEN_LOWRES
39203919   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_macross)
3921   
39223920
3921
39233922   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross)
39243923   MCFG_PALETTE_ADD("palette", 1024)
39253924   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
39573956   /* video hardware */
39583957   NMK_HACKY_SCREEN_LOWRES
39593958   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_macross)
3960   
39613959
3960
39623961   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross)
39633962   MCFG_PALETTE_ADD("palette", 1024)
39643963   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
39833982   /* video hardware */
39843983   NMK_HACKY_SCREEN_LOWRES
39853984   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_bioship)
3986   
39873985
3986
39883987   MCFG_GFXDECODE_ADD("gfxdecode", "palette", bioship)
39893988   MCFG_PALETTE_ADD("palette", 1024)
39903989   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
40204019   /* video hardware */
40214020   NMK_HACKY_SCREEN_LOWRES
40224021   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_macross)
4023   
40244022
4023
40254024   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross)
40264025   MCFG_PALETTE_ADD("palette", 1024)
40274026   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
40604059   /* video hardware */
40614060   NMK_HACKY_SCREEN_LOWRES
40624061   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_macross)
4063   
40644062
4063
40654064   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross)
40664065   MCFG_PALETTE_ADD("palette", 1024)
40674066   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
40854084   /* video hardware */
40864085   NMK_HACKY_SCREEN_LOWRES
40874086   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_macross)
4088   
40894087
4088
40904089   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross)
40914090   MCFG_PALETTE_ADD("palette", 1024)
40924091   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBxxxx)
r32760r32761
41254124   /* video hardware */
41264125   NMK_HACKY_SCREEN_LOWRES
41274126   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_macross)
4128   
41294127
4128
41304129   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross)
41314130   MCFG_PALETTE_ADD("palette", 1024)
41324131   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
41474146   /* video hardware */
41484147   NMK_HACKY_SCREEN_LOWRES
41494148   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_macross)
4150   
41514149
4150
41524151   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross)
41534152   MCFG_PALETTE_ADD("palette", 1024)
41544153   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
41904189   /* video hardware */
41914190   NMK_HACKY_SCREEN_LOWRES
41924191   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_macross)
4193   
41944192
4193
41954194   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross)
41964195   MCFG_PALETTE_ADD("palette", 1024)
41974196   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
42164215   /* video hardware */
42174216   NMK_HACKY_SCREEN_LOWRES
42184217   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_strahl)
4219   
4218
42204219   MCFG_GFXDECODE_ADD("gfxdecode", "palette", strahl)
42214220   MCFG_PALETTE_ADD("palette", 1024)
42224221   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBxxxx)
r32760r32761
42524251   /* video hardware */
42534252   NMK_HACKY_SCREEN_LOWRES
42544253   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_macross)
4255   
42564254
4255
42574256   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross)
42584257   MCFG_PALETTE_ADD("palette", 1024)
42594258   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
42934292   /* video hardware */
42944293   NMK_HACKY_SCREEN_LOWRES
42954294   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_macross)
4296   
42974295
4296
42984297   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross)
42994298   MCFG_PALETTE_ADD("palette", 1024)
43004299   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
43304329   /* video hardware */
43314330   NMK_HACKY_SCREEN_LOWRES
43324331   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_macross)
4333   
43344332
4333
43354334   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross)
43364335   MCFG_PALETTE_ADD("palette", 1024)
43374336   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
43674366   /* video hardware */
43684367   NMK_HACKY_SCREEN_HIRES
43694368   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_gunnail)
4370   
43714369
43724370
43734371
4372
43744373   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross)
43754374   MCFG_PALETTE_ADD("palette", 1024)
43764375   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
44104409   /* video hardware */
44114410   NMK_HACKY_SCREEN_HIRES
44124411   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_gunnail)
4413   
44144412
4413
44154414   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross2)
44164415   MCFG_PALETTE_ADD("palette", 1024)
44174416   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
44534452   /* video hardware */
44544453   NMK_HACKY_SCREEN_HIRES
44554454   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_tdragon2)
4456   
44574455
4456
44584457   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross2)
44594458   MCFG_PALETTE_ADD("palette", 1024)
44604459   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
44954494   /* video hardware */
44964495   NMK_HACKY_SCREEN_HIRES
44974496   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_tdragon2)
4498   
44994497
4498
45004499   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross2)
45014500   MCFG_PALETTE_ADD("palette", 1024)
45024501   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
45344533   /* video hardware */
45354534   NMK_HACKY_SCREEN_HIRES
45364535   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_bjtwin)
4537   
45384536
4537
45394538   MCFG_GFXDECODE_ADD("gfxdecode", "palette", bjtwin)
45404539   MCFG_PALETTE_ADD("palette", 1024)
45414540   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
45684567   /* video hardware */
45694568   NMK_HACKY_SCREEN_HIRES
45704569   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_bjtwin)
4571   
45724570
4571
45734572   MCFG_GFXDECODE_ADD("gfxdecode", "palette", atombjt)
45744573   MCFG_PALETTE_ADD("palette", 1024)
45754574   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
46244623   MCFG_SCREEN_SIZE(256, 256)
46254624   MCFG_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 1*8, 31*8-1)
46264625   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_manybloc)
4627   
4626
46284627   MCFG_SCREEN_PALETTE("palette")
46294628
46304629   MCFG_GFXDECODE_ADD("gfxdecode", "palette", tharrier)
r32760r32761
50955094   /* video hardware */
50965095   NMK_HACKY_SCREEN_LOWRES
50975096   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_afega)
5098   
50995097
5098
51005099   MCFG_GFXDECODE_ADD("gfxdecode", "palette", stagger1)
51015100   MCFG_PALETTE_ADD("palette", 768)
51025101   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
51775176   /* video hardware */
51785177   NMK_HACKY_SCREEN_LOWRES
51795178   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_firehawk)
5180   
51815179
5180
51825181   MCFG_GFXDECODE_ADD("gfxdecode", "palette", grdnstrm)
51835182   MCFG_PALETTE_ADD("palette", 768)
51845183   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
52085207   /* video hardware */
52095208   NMK_HACKY_SCREEN_LOWRES
52105209   MCFG_SCREEN_UPDATE_DRIVER(nmk16_state, screen_update_macross)
5211   
52125210
5211
52135212   MCFG_GFXDECODE_ADD("gfxdecode", "palette", macross)
52145213   MCFG_PALETTE_ADD("palette", 1024)
52155214   MCFG_PALETTE_FORMAT(RRRRGGGGBBBBRGBx)
r32760r32761
60016000
60026001   ROM_REGION( 0xa0000, "oki1", 0 )    /* Oki sample data */
60036002   ROM_LOAD( "str8pmw1.540", 0x00000, 0x20000, CRC(01d6bb6a) SHA1(b157f6f921483ed8067a7e13e370f73fdb60d136) )
6004  /* this is a mess */
6003   /* this is a mess */
60056004   ROM_CONTINUE(             0x80000, 0x20000 )    /* banked */
60066005   ROM_CONTINUE(             0x60000, 0x20000 )    /* banked */
60076006   ROM_CONTINUE(             0x40000, 0x20000 )    /* banked */
60086007
60096008   ROM_REGION( 0xa0000, "oki2", 0 )    /* Oki sample data */
60106009   ROM_LOAD( "str9pew1.639", 0x00000, 0x20000, CRC(6bb3eb9f) SHA1(9c1394df4f8a08f9098c85eb3d38fb862d6eabbb) )
6011  /* this is a mess */
6010   /* this is a mess */
60126011   ROM_CONTINUE(             0x80000, 0x20000 )    /* banked */
60136012   ROM_CONTINUE(             0x60000, 0x20000 )    /* banked */
60146013   ROM_CONTINUE(             0x40000, 0x20000 )    /* banked */
r32760r32761
60386037
60396038   ROM_REGION( 0xa0000, "oki1", 0 )    /* Oki sample data */
60406039   ROM_LOAD( "str8pmw1.540", 0x00000, 0x20000, CRC(01d6bb6a) SHA1(b157f6f921483ed8067a7e13e370f73fdb60d136) )
6041  /* this is a mess */
6040   /* this is a mess */
60426041   ROM_CONTINUE(             0x80000, 0x20000 )    /* banked */
60436042   ROM_CONTINUE(             0x60000, 0x20000 )    /* banked */
60446043   ROM_CONTINUE(             0x40000, 0x20000 )    /* banked */
60456044
60466045   ROM_REGION( 0xa0000, "oki2", 0 )    /* Oki sample data */
60476046   ROM_LOAD( "str9pew1.639", 0x00000, 0x20000, CRC(6bb3eb9f) SHA1(9c1394df4f8a08f9098c85eb3d38fb862d6eabbb) )
6048  /* this is a mess */
6047   /* this is a mess */
60496048   ROM_CONTINUE(             0x80000, 0x20000 )    /* banked */
60506049   ROM_CONTINUE(             0x60000, 0x20000 )    /* banked */
60516050   ROM_CONTINUE(             0x40000, 0x20000 )    /* banked */
trunk/src/mame/drivers/namcops2.c
r32760r32761
208208   SYSTEM256_BIOS
209209
210210   ROM_REGION(0x840000, "key", ROMREGION_ERASE00)
211   ROM_LOAD( "kn2vera.ic002", 0x000000, 0x800000, CRC(fb2f71f7) SHA1(29a331cc171d395ad10b352b9b30a61a455a50fe) )
212   ROM_LOAD( "kn2vera_spr.ic002", 0x800000, 0x040000, CRC(9c18fa50) SHA1(1f75052cf264c3f2e5b332a755d30544d6e5f45c) )
211   ROM_LOAD( "kn2vera.ic002", 0x000000, 0x800000, CRC(fb2f71f7) SHA1(29a331cc171d395ad10b352b9b30a61a455a50fe) )
212   ROM_LOAD( "kn2vera_spr.ic002", 0x800000, 0x040000, CRC(9c18fa50) SHA1(1f75052cf264c3f2e5b332a755d30544d6e5f45c) )
213213
214214   DISK_REGION("dvd")
215215   DISK_IMAGE_READONLY( "kn2", 0, SHA1(3e1b773cc584911b673d46f9296a5b1a2cef9a45) )
r32760r32761
526526   ROM_LOAD( "fud1vera.ic002", 0x000000, 0x800000, CRC(892ffdd1) SHA1(4a444ed49e5c89dd0af4f026626a164b9eec61d1) )
527527   ROM_LOAD( "fud1vera_spr.ic002", 0x800000, 0x040000, CRC(0fca4e99) SHA1(0bd74de26f10089ee848f03093229abfa8c84663) )
528528
529   DISK_REGION("dvd")   // actually HDD for this game
529   DISK_REGION("dvd")  // actually HDD for this game
530530   DISK_IMAGE_READONLY( "fud-hdd0-a", 0, SHA1(1189863ae0e339e11708b9660521f86b3b97bc9e) )
531531ROM_END
532532
r32760r32761
558558   SYSTEM256_BIOS
559559
560560   ROM_REGION(0x840000, "key", ROMREGION_ERASE00)
561   ROM_LOAD( "gnx1001-na-a.ic002", 0x000000, 0x800000, CRC(1d6d2f54) SHA1(17f6e7278e61b5b81605175d3f2df7b747ca7246) )
562   ROM_LOAD( "gnx1001-na-a_spr.ic002", 0x800000, 0x040000, CRC(a999ba5c) SHA1(009a56f7be50b57bf435fb8c8b41cf14086b1d1a) )
561   ROM_LOAD( "gnx1001-na-a.ic002", 0x000000, 0x800000, CRC(1d6d2f54) SHA1(17f6e7278e61b5b81605175d3f2df7b747ca7246) )
562   ROM_LOAD( "gnx1001-na-a_spr.ic002", 0x800000, 0x040000, CRC(a999ba5c) SHA1(009a56f7be50b57bf435fb8c8b41cf14086b1d1a) )
563563
564   DISK_REGION("dvd")   // actually HDD for this game
564   DISK_REGION("dvd")  // actually HDD for this game
565565   DISK_IMAGE_READONLY( "gnx100-1na-a", 0, SHA1(a2344f533895793a2e13198c7de0c759f0dbf817) )
566566ROM_END
567567
r32760r32761
581581   SYSTEM246_BIOS
582582
583583   ROM_REGION(0x840000, "key", ROMREGION_ERASE00)
584   ROM_LOAD( "bax1vera.ic002", 0x000000, 0x800000, CRC(18a6f424) SHA1(027a8d371fb6782c906434b86db9779057eaa954) )
585   ROM_LOAD( "bax1vera_spr.ic002", 0x800000, 0x040000, CRC(abfb749b) SHA1(b45f8c79dd0cc0359f27c33f55626d6cad82127c) )
584   ROM_LOAD( "bax1vera.ic002", 0x000000, 0x800000, CRC(18a6f424) SHA1(027a8d371fb6782c906434b86db9779057eaa954) )
585   ROM_LOAD( "bax1vera_spr.ic002", 0x800000, 0x040000, CRC(abfb749b) SHA1(b45f8c79dd0cc0359f27c33f55626d6cad82127c) )
586586
587587   DISK_REGION("dvd")
588588   DISK_IMAGE_READONLY( "bax1_dvd0", 0, SHA1(56d58e66eeaa57ff07668000491360853b064936) )
trunk/src/mame/drivers/segaybd.c
r32760r32761
809809   ADDRESS_MAP_UNMAP_HIGH
810810   ADDRESS_MAP_GLOBAL_MASK(0xff)
811811
812//   AM_RANGE(0x40, 0x40) AM_READ_PORT("LinkDSW")
812//  AM_RANGE(0x40, 0x40) AM_READ_PORT("LinkDSW")
813813   AM_RANGE(0xc0, 0xc0) AM_READ(link_portc0_r)
814814ADDRESS_MAP_END
815815
r32760r32761
18091809   ROM_LOAD16_BYTE( "epr-11791.14",  0x000001, 0x20000, CRC(36b2910a) SHA1(9948b91837f944a7a606542fa685525e74bbe398) )
18101810   ROM_LOAD16_BYTE( "epr-11790.17",  0x040000, 0x20000, CRC(2a564e66) SHA1(5f30fc15bfd017d75cfffe1e9e62ed0bcf32a98e) )
18111811   ROM_LOAD16_BYTE( "epr-11792.15",  0x040001, 0x20000, CRC(c85caf6e) SHA1(2411ea99ec7f6e2b0b4f219e86ff2172539ad2c4) )
1812   
1812
18131813   ROM_REGION64_BE( 0x400000, "ysprites", 0)
18141814   ROMX_LOAD( "epr-11757.67",  0x000000, 0x20000, CRC(e46dc478) SHA1(baf79e230aef3d63fb50373b2b1626f7c56ee94f), ROM_SKIP(7) )
18151815   ROMX_LOAD( "epr-11758.75",  0x000001, 0x20000, CRC(5b435c87) SHA1(6b42b08e73957c36cd8faa896ca14461d00afd29), ROM_SKIP(7) )
trunk/src/mame/drivers/karnov.c
r32760r32761
832832
833833static ADDRESS_MAP_START( chelnovjbl_mcu_io_map, AS_IO, 8, karnov_state )
834834   //internal port
835//   AM_RANGE(MCS51_PORT_P1, MCS51_PORT_P1) AM_READWRITE(p1_r, p1_w)
836//   AM_RANGE(MCS51_PORT_P3, MCS51_PORT_P3) AM_READWRITE(p3_r, p3_w)
835//  AM_RANGE(MCS51_PORT_P1, MCS51_PORT_P1) AM_READWRITE(p1_r, p1_w)
836//  AM_RANGE(MCS51_PORT_P3, MCS51_PORT_P3) AM_READWRITE(p3_r, p3_w)
837837ADDRESS_MAP_END
838838
839839
r32760r32761
11811181   ROM_LOAD( "a-c5.bin",     0x00000, 0x08000, CRC(1abf2c6d) SHA1(86d625ae94cd9ea69e4e613895410640efb175b3) )  /* Characters */
11821182
11831183   ROM_REGION( 0x40000, "gfx2", 0 ) /* Backgrounds */ // same content split into more roms
1184   ROM_LOAD( "8.bin",    0x00000, 0x08000, CRC(a78b174a) SHA1(e0d82b600a154b81d7e1a787f0e20eb1a341894f) ) 
1184   ROM_LOAD( "8.bin",    0x00000, 0x08000, CRC(a78b174a) SHA1(e0d82b600a154b81d7e1a787f0e20eb1a341894f) )
11851185   ROM_LOAD( "9.bin",    0x08000, 0x08000, CRC(97d2c146) SHA1(075bb9afc4f0623cd413883ec2bca574d7ff88d4) )
11861186   ROM_LOAD( "2.bin",    0x10000, 0x08000, CRC(8c45e7de) SHA1(d843b7dcc64ed3a5b8717af172a1f22c4c599480) )
11871187   ROM_LOAD( "3.bin",    0x18000, 0x08000, CRC(504cc95c) SHA1(97e5e9f8cd8ebf5e0c18f27f2988a45c4d3809b3) )
r32760r32761
12331233   ROM_LOAD( "a-c5.bin",     0x00000, 0x08000, CRC(1abf2c6d) SHA1(86d625ae94cd9ea69e4e613895410640efb175b3) )  /* Characters */
12341234
12351235   ROM_REGION( 0x40000, "gfx2", 0 ) /* Backgrounds */ // same content split into more roms
1236   ROM_LOAD( "8.bin",    0x00000, 0x08000, CRC(a78b174a) SHA1(e0d82b600a154b81d7e1a787f0e20eb1a341894f) ) 
1236   ROM_LOAD( "8.bin",    0x00000, 0x08000, CRC(a78b174a) SHA1(e0d82b600a154b81d7e1a787f0e20eb1a341894f) )
12371237   ROM_LOAD( "9.bin",    0x08000, 0x08000, CRC(97d2c146) SHA1(075bb9afc4f0623cd413883ec2bca574d7ff88d4) )
12381238   ROM_LOAD( "2.bin",    0x10000, 0x08000, CRC(8c45e7de) SHA1(d843b7dcc64ed3a5b8717af172a1f22c4c599480) )
12391239   ROM_LOAD( "3.bin",    0x18000, 0x08000, CRC(504cc95c) SHA1(97e5e9f8cd8ebf5e0c18f27f2988a45c4d3809b3) )
trunk/src/mame/drivers/cops.c
r32760r32761
44    (hardware developed by Nova Productions Limited)
55    Preliminary driver by Mariusz Wojcieszek, James Wallace
66
7   Cops uses a Sony CD-ROM in addition to the regular setup, purely to play
8   Bad Boys by Inner Circle, so there is muscial accompaniment to areas
9   where the laserdisc audio is muted.
7    Cops uses a Sony CD-ROM in addition to the regular setup, purely to play
8    Bad Boys by Inner Circle, so there is muscial accompaniment to areas
9    where the laserdisc audio is muted.
1010
11   NOTES: To boot up Revelations, turn the refill key (R) and press button A.
11    NOTES: To boot up Revelations, turn the refill key (R) and press button A.
1212    TODO: There are probably more ROMs for Revelations, the disc contains
13    full data for a picture based memory game called 'Vision Quest'.   
14   
15   LaserMax memory map needs sorting out, Cops uses a subset of what's
16   actually available
13    full data for a picture based memory game called 'Vision Quest'.
1714
15    LaserMax memory map needs sorting out, Cops uses a subset of what's
16    actually available
17
1818    The UK version COPS appears to want to communicate with the LDP in a
19   different way.
19    different way.
2020***************************************************************************/
2121
2222
r32760r32761
355355 *
356356 *************************************/
357357
358 void cops_state::update_dacia_irq()
358   void cops_state::update_dacia_irq()
359359{
360360   UINT8 isr = generate_isr();
361361   //remove bits
r32760r32761
390390UINT8 cops_state::generate_isr()
391391{
392392   UINT8 isr =0;
393   
393
394394   isr |= m_dacia_receiver_full;
395395   isr |= (m_dacia_cmp1 << 1);
396   isr |= (m_dacia_trans <<4);
397         
396   isr |= (m_dacia_trans <<4);
397
398398   if (isr)
399399   {
400400      isr |= 0x40;
r32760r32761
413413         m_maincpu->set_input_line(INPUT_LINE_NMI, CLEAR_LINE);
414414         return isr;
415415      }
416         
416
417417      case 1: /* CSR1: Control Status Register */
418418      {
419419         UINT8 csr =0;
420420         csr |= m_dacia_rts1;
421421         csr |= (m_dacia_dtr1 << 1);
422         csr |= (m_dacia_cts <<4);
423         csr |= (m_dacia_fe1 <<7);
422         csr |= (m_dacia_cts <<4);
423         csr |= (m_dacia_fe1 <<7);
424424         if (LOG_DACIA) logerror("CSR1 %02x\n",csr);
425425         return csr;
426      }     
426      }
427427
428428      case 3: /* RDR1: Receive data register */
429429         m_dacia_receiver_full = 0;
r32760r32761
463463         {
464464            m_dacia_rts1 = (data & 0x01);
465465            m_dacia_dtr1 = (data & 0x02 ? 1:0);
466            m_parity_1 = (data & 0x04);           
467            m_parity_mode_1 = ((data & 0x18) >> 3);           
466            m_parity_1 = (data & 0x04);
467            m_parity_mode_1 = ((data & 0x18) >> 3);
468468            m_bpc_1 = ((data & 0x60) >> 5) +5;
469469            if (LOG_DACIA) logerror("DACIA Format Register: %02x\n", data);
470470         }
r32760r32761
479479            }
480480            else
481481            {
482               m_dacia_reg1 = CMP_REGISTER;           
482               m_dacia_reg1 = CMP_REGISTER;
483483            }
484484            if (LOG_DACIA) logerror("DACIA TIME %02d\n", XTAL_3_6864MHz / m_dacia_ic_div_1);
485           
485
486486            m_ld_timer->adjust(attotime::from_hz(XTAL_3_6864MHz / m_dacia_ic_div_1), 0, attotime::from_hz(XTAL_3_6864MHz / m_dacia_ic_div_1));
487487
488488            if (LOG_DACIA) logerror("DACIA Ctrl Register: %02x\n", data);
489         
489
490490         }
491491         break;
492      }     
492      }
493493      case 2: /* Compare / Aux Ctrl Register 1 */
494494      {
495         if (m_dacia_reg1 == CMP_REGISTER)           
495         if (m_dacia_reg1 == CMP_REGISTER)
496496         {
497497            m_dacia_cmp1 =1;
498498            m_dacia_cmpval1=data;
499            if (LOG_DACIA) logerror("DACIA Compare mode: %02x \n", data);           
500//            update_dacia_irq();
499            if (LOG_DACIA) logerror("DACIA Compare mode: %02x \n", data);
500//              update_dacia_irq();
501501         }
502502         else
503503         {
504            if (LOG_DACIA) logerror("DACIA Aux ctrl: %02x \n", data);         
504            if (LOG_DACIA) logerror("DACIA Aux ctrl: %02x \n", data);
505505         }
506506      }
507507      case 3: /* Transmit Data Register 1 */
r32760r32761
869869
870870   /* sound hardware */
871871   MCFG_SPEAKER_STANDARD_MONO("mono")
872   
872
873873      /* TODO: Verify clock */
874874   MCFG_SOUND_ADD("snsnd", SN76489, MAIN_CLOCK/2)
875875   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
r32760r32761
908908ROM_END
909909
910910
911GAMEL( 1994, cops,     0,   cops,  cops,        cops_state, cops,       ROT0, "Atari Games",                  "Cops (USA)",   GAME_NOT_WORKING | GAME_NO_SOUND, layout_cops )
912GAMEL( 1994, copsuk,     cops,cops,  cops,       cops_state, cops,       ROT0, "Nova Productions / Deith Leisure","Cops (UK)",   GAME_NOT_WORKING | GAME_NO_SOUND, layout_cops )
913GAMEL( 1994, revlatns,  0,   cops,  revlatns,  cops_state, cops,       ROT0, "Nova Productions",               "Revelations",    GAME_NOT_WORKING | GAME_NO_SOUND, layout_cops )
911GAMEL( 1994, cops,      0,   cops,  cops,      cops_state, cops,       ROT0, "Atari Games",                     "Cops (USA)",   GAME_NOT_WORKING | GAME_NO_SOUND, layout_cops )
912GAMEL( 1994, copsuk,    cops,cops,  cops,      cops_state, cops,       ROT0, "Nova Productions / Deith Leisure","Cops (UK)",    GAME_NOT_WORKING | GAME_NO_SOUND, layout_cops )
913GAMEL( 1994, revlatns,  0,   cops,  revlatns,  cops_state, cops,       ROT0, "Nova Productions",                "Revelations",  GAME_NOT_WORKING | GAME_NO_SOUND, layout_cops )
trunk/src/mame/drivers/namcos21.c
r32760r32761
490490void namcos21_kickstart(running_machine &machine, int internal)
491491{
492492   namcos21_state *state = machine.driver_data<namcos21_state>();
493   
493
494494   /* patch dsp watchdog */
495495   switch( state->m_gametype )
496496   {
trunk/src/mame/drivers/foodf.c
r32760r32761
411411
412412   ROM_REGION( 0x100, "proms", 0 )
413413   ROM_LOAD( "136020-112.2p",   0x000000, 0x000100, CRC(0aa962d6) SHA1(efb51e4c95efb1b85206c416c1d6d35c6f4ff35c) )
414   
414
415415   ROM_REGION( 0x100, "nvram", 0 ) // default initialized nvram
416416   ROM_LOAD( "foodf.nv", 0x000000, 0x000100, CRC(a4186b13) SHA1(7633ceb6f61403a46e36cc2172839e6c3f31bac2) )
417417ROM_END
r32760r32761
437437
438438   ROM_REGION( 0x100, "proms", 0 )
439439   ROM_LOAD( "136020-112.2p",   0x000000, 0x000100, CRC(0aa962d6) SHA1(efb51e4c95efb1b85206c416c1d6d35c6f4ff35c) )
440   
440
441441   ROM_REGION( 0x100, "nvram", 0 ) // default initialized nvram
442442   ROM_LOAD( "foodf.nv", 0x000000, 0x000100, CRC(a4186b13) SHA1(7633ceb6f61403a46e36cc2172839e6c3f31bac2) )
443443ROM_END
r32760r32761
463463
464464   ROM_REGION( 0x100, "proms", 0 )
465465   ROM_LOAD( "136020-112.2p",   0x000000, 0x000100, CRC(0aa962d6) SHA1(efb51e4c95efb1b85206c416c1d6d35c6f4ff35c) )
466   
466
467467   ROM_REGION( 0x100, "nvram", 0 ) // default initialized nvram
468468   ROM_LOAD( "foodf.nv", 0x000000, 0x000100, CRC(a4186b13) SHA1(7633ceb6f61403a46e36cc2172839e6c3f31bac2) )
469469ROM_END
r32760r32761
489489
490490   ROM_REGION( 0x100, "proms", 0 )
491491   ROM_LOAD( "136020-112.2p",   0x000000, 0x000100, CRC(0aa962d6) SHA1(efb51e4c95efb1b85206c416c1d6d35c6f4ff35c) )
492   
492
493493   ROM_REGION( 0x100, "nvram", 0 ) // default initialized nvram, differs from the other sets
494494   ROM_LOAD( "foodfc.nv", 0x000000, 0x000100, CRC(c1385dab) SHA1(52f4dc772e5da0f7c9bcef6c6ef3a655dcd3d59d) )
495495ROM_END
trunk/src/mame/drivers/4enraya.c
r32760r32761
6565***************************************************************************
6666
6767  Unknown Pac-Man gambling game.
68 
68
6969  It's a basic Pac-Man front game, that has a gambling game hidden inside.
7070  The purpose of this "stealth" game, is just to be a "camouflage" for the
7171  real gambling game, for locations where the gambling games are forbidden.
r32760r32761
8989  discard and press START to eliminate the number and place the representative
9090  ghost again in the original place outside the center.
9191
92  Once done, just press UP (deal) again, and pacman will re-eat the new placed
92  Once done, just press UP (deal) again, and pacman will re-eat the new placed
9393  ghosts, revealing the new numbers (as a new deal).
9494
9595  If you have a winning hand, you can press DOWN (double-up) to get a Double-Up,
r32760r32761
241241   AM_RANGE(0x00, 0x00) AM_READ_PORT("DSW1")
242242   AM_RANGE(0x01, 0x01) AM_READ_PORT("IN1")
243243   AM_RANGE(0x02, 0x02) AM_READ_PORT("IN2")
244//   AM_RANGE(0x03, 0x03) AM_WRITE("out_w")   // to investigate...
244//  AM_RANGE(0x03, 0x03) AM_WRITE("out_w")  // to investigate...
245245   AM_RANGE(0x17, 0x17) AM_DEVWRITE("aysnd", ay8910_device, data_w)
246246   AM_RANGE(0x27, 0x27) AM_DEVREAD("aysnd", ay8910_device, data_r)
247247   AM_RANGE(0x37, 0x37) AM_DEVWRITE("aysnd", ay8910_device, address_w)
r32760r32761
300300
301301static INPUT_PORTS_START( unkpacg )
302302   PORT_START("IN1")
303   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_NAME("Front Game Coin A")      //  1 credits / initiate minigame
304   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN3 ) PORT_NAME("Gambling Game Coin In")   //  5 credits / initiate gambling
305   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_NAME("Front Game Coin B")      // 10 credits
303   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_NAME("Front Game Coin A")       //  1 credits / initiate minigame
304   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN3 ) PORT_NAME("Gambling Game Coin In")   //  5 credits / initiate gambling
305   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_NAME("Front Game Coin B")       // 10 credits
306306   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
307307   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
308308   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
r32760r32761
459459   MCFG_NVRAM_ADD_0FILL("nvram")
460460
461461   /* sound hardware */
462//   MCFG_SPEAKER_STANDARD_MONO("mono")
462//  MCFG_SPEAKER_STANDARD_MONO("mono")
463463   MCFG_SOUND_REPLACE("aysnd", AY8910, MAIN_CLOCK/4) /* guess */
464464   MCFG_AY8910_PORT_A_READ_CB(IOPORT("DSW2"))
465465   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
trunk/src/mame/drivers/fcrash.c
r32760r32761
25322532   mem16[0x64E/2] = 0x6046; // fix priorities
25332533
25342534   DRIVER_INIT_CALL(dinopic);
2535   
2535
25362536}
25372537
25382538
r32760r32761
26642664   ROM_LOAD16_BYTE( "27040.5",              0x000001, 0x80000, CRC(137d5f2e) SHA1(835e9b767e6499f161c5c4fd9a31a9f54b3ee68f) )
26652665   ROM_LOAD16_BYTE( "27010.4",              0x100000, 0x20000, CRC(8226c11c) SHA1(9588bd64e338901394805aca8a234f880674dc60) )
26662666   ROM_LOAD16_BYTE( "27010.3",              0x100001, 0x20000, CRC(924c6ce2) SHA1(676a912652bd75da5087f0c7eae047b7681a993c) )
2667   
26682667
2668
26692669   ROM_REGION( 0x600000, "gfx", 0 )
26702670   ROMX_LOAD( "tat-01.bin",    0x000000, 0x40000, CRC(a887f7d4) SHA1(d7e0c46b3ab1c6352f45033cb9e610d9c34d51fb), ROM_SKIP(7) )
26712671   ROM_CONTINUE(          0x000004, 0x40000)
r32760r32761
26752675   ROM_CONTINUE(          0x000006, 0x40000)
26762676   ROMX_LOAD( "tat-06.bin",    0x000003, 0x40000, CRC(90f2053e) SHA1(a78710421e702b410650c45c3dec21bf16799fb4), ROM_SKIP(7) )
26772677   ROM_CONTINUE(          0x000007, 0x40000)
2678   
2678
26792679   ROMX_LOAD( "tat-03.bin",    0x200000, 0x40000, CRC(79fa8bf0) SHA1(9f8f7b8dc54a75226beb017b9ca9fd62a9e42f6b), ROM_SKIP(7) )
26802680   ROM_CONTINUE(          0x200004, 0x40000)
26812681   ROMX_LOAD( "tat-07.bin",    0x200001, 0x40000, CRC(6a5f153c) SHA1(f3d82ad01e2e4bdb2039815747fa14399c69753a), ROM_SKIP(7) )
r32760r32761
26932693   ROM_CONTINUE(          0x400006, 0x40000)
26942694   ROMX_LOAD( "tat-12.bin",    0x400003, 0x40000, CRC(6ee19b94) SHA1(c45119d04879b6ca23a3f7749175c56b381b43f2), ROM_SKIP(7) )
26952695   ROM_CONTINUE(          0x400007, 0x40000)
2696   
2696
26972697   ROM_REGION( 0x18000, "audiocpu", 0 ) /* 64k for the audio CPU (+banks) */
26982698   ROM_LOAD( "27512.1",    0x00000, 0x08000, CRC(08f6b60e) SHA1(8258fcaca4ac419312531eec67079b97f471179c) )
26992699   ROM_CONTINUE(              0x10000, 0x08000 )
27002700
27012701   ROM_REGION( 0x40000, "oki", 0 ) /* Samples */
27022702   ROM_LOAD( "27020.2",    0x00000, 0x40000, CRC(6cfffb11) SHA1(995526183ffd35f92e9096500a3fe6237faaa2dd) )
2703   
2703
27042704   ROM_REGION( 0x00c8d, "pld", 0 ) /* pal/gal */
27052705   ROM_LOAD( "gal20v8.68kadd",    0x00000, 0x00c8d, CRC(27cdd376) SHA1(9fb5844b33002bec80fb92d3e5d1bbc779087300) )//68k address decoder
2706   
2706
27072707ROM_END
27082708
27092709DRIVER_INIT_MEMBER(cps_state, sf2mdt)
trunk/src/mame/drivers/redclash.c
r32760r32761
470470   ROM_LOAD( "zhi.c7", 0x0800, 0x0800, CRC(dcfefb4c) SHA1(9d8f57f5f09368225bae06a64971b82a848b1a7e) )
471471   ROM_LOAD( "zhi.c6", 0x1000, 0x0800, CRC(ddc66d36) SHA1(1cbf6e27e7b2ccd39199c1a26783d53d6d90d195) )
472472   ROM_LOAD( "zhi.c5", 0x1800, 0x0800, CRC(25c5872d) SHA1(df008db607b72a92c4284d6a8127eafec2432ca4) ) // == ze4_4.c5
473//   ROM_LOAD( "zhi.c4", 0x2000, 0x0800, CRC(9b70464b) SHA1(ccd173e12630ba044fe659915dfce21f2b5e0e39) ) // corrupt
473//  ROM_LOAD( "zhi.c4", 0x2000, 0x0800, CRC(9b70464b) SHA1(ccd173e12630ba044fe659915dfce21f2b5e0e39) ) // corrupt
474474   ROM_LOAD( "zhi.c4", 0x2000, 0x0800, CRC(d7ce3add) SHA1(d8dd7ad98e7a0a4f35de181549b2e88a9e0a73d6) ) // use rom from above sets instead
475475   ROM_LOAD( "zhi.c3", 0x2800, 0x0800, CRC(29dee5e4) SHA1(13c1778d427a11f5c24ce8116fe55d60e98e3d83) )
476476
trunk/src/mame/drivers/speglsht.c
r32760r32761
344344VIDEO_START_MEMBER(speglsht_state,speglsht)
345345{
346346   m_bitmap = auto_bitmap_ind16_alloc(machine(), 512, 5122 );
347//   VIDEO_START_CALL_MEMBER(st0016);
347//  VIDEO_START_CALL_MEMBER(st0016);
348348}
349349
350350#define PLOT_PIXEL_RGB(x,y,r,g,b)   if(y>=0 && x>=0 && x<512 && y<512) \
trunk/src/mame/drivers/centiped.c
r32760r32761
18761876 *************************************/
18771877
18781878/*
1879   Alt. part numbers for mask ROMs:
1879    Alt. part numbers for mask ROMs:
18801880
1881   136001-*03 = 136001-*07
1882   136001-*04 = 136001-*08
1883   136001-*05 = 136001-*09
1884   136001-*06 = 136001-*10
1885   136001-*01 = 136001-*11
1886   136001-*02 = 136001-*12
1881    136001-*03 = 136001-*07
1882    136001-*04 = 136001-*08
1883    136001-*05 = 136001-*09
1884    136001-*06 = 136001-*10
1885    136001-*01 = 136001-*11
1886    136001-*02 = 136001-*12
18871887*/
18881888
18891889ROM_START( centiped )
trunk/src/mame/drivers/igs017.c
r32760r32761
720720
721721void igs017_state::mgcs_patch_rom()
722722{
723//   UINT16 *rom = (UINT16 *)memregion("maincpu")->base();
723//  UINT16 *rom = (UINT16 *)memregion("maincpu")->base();
724724
725//   rom[0x20666/2] = 0x601e;    // 020666: 671E    beq $20686 (rom check)
725//  rom[0x20666/2] = 0x601e;    // 020666: 671E    beq $20686 (rom check)
726726
727727   // IGS029 send command
728//   rom[0x4dfce/2] = 0x6010;    // 04DFCE: 6610    bne $4dfe0
729//   rom[0x4e00e/2] = 0x4e75;
730//   rom[0x4e036/2] = 0x6006;   // 04E036: 6306    bls     $4e03e
728//  rom[0x4dfce/2] = 0x6010;    // 04DFCE: 6610    bne $4dfe0
729//  rom[0x4e00e/2] = 0x4e75;
730//  rom[0x4e036/2] = 0x6006;    // 04E036: 6306    bls     $4e03e
731731}
732732
733733DRIVER_INIT_MEMBER(igs017_state,mgcs)
r32760r32761
14571457            coin_counter_w(machine(), 0, (~data) & 0x20);   // coin in
14581458            coin_counter_w(machine(), 1, (~data) & 0x40);   // coin out
14591459
1460//            popmessage("PORT1 %02X", data);
1460//              popmessage("PORT1 %02X", data);
14611461
14621462            if ( data & ~0x70 )
14631463               logerror("%s: warning, unknown bits written in port %02x = %02x\n", machine().describe_context(), port, data);
r32760r32761
14671467         case 0x03:
14681468            m_dsw_select = data;
14691469
1470//            popmessage("PORT3 %02X", data);
1470//              popmessage("PORT3 %02X", data);
14711471
14721472            if ( data & ~0x03 )
14731473               logerror("%s: warning, unknown bits written in port %02x = %02x\n", machine().describe_context(), port, data);
r32760r32761
15011501      logerror("READ DSW\n");
15021502
15031503      UINT8 ret;
1504      if      (~m_dsw_select & 0x01)   ret = ioport("DSW1")->read();
1505      else if (~m_dsw_select & 0x02)   ret = ioport("DSW2")->read();
1504      if      (~m_dsw_select & 0x01)  ret = ioport("DSW1")->read();
1505      else if (~m_dsw_select & 0x02)  ret = ioport("DSW2")->read();
15061506      else
15071507      {
15081508         logerror("%s: warning, reading dsw with dsw_select = %02x\n", machine().describe_context(), m_dsw_select);
r32760r32761
15151515   }
15161516   else if (m_igs029_send_buf[0] == 0x07 && m_igs029_send_buf[1] == 0x2c)
15171517   {
1518      logerror("?? (2C)\n");   // ??
1518      logerror("?? (2C)\n");  // ??
15191519
15201520      // 4 inputs. Returns 1 long
15211521
r32760r32761
15251525      m_igs029_recv_buf[m_igs029_recv_len++] = 0x00;
15261526      m_igs029_recv_buf[m_igs029_recv_len++] = 0x00;
15271527      m_igs029_recv_buf[m_igs029_recv_len++] = 0x00;
1528      m_igs029_recv_buf[m_igs029_recv_len++] = 0x01;   // ??
1528      m_igs029_recv_buf[m_igs029_recv_len++] = 0x01;  // ??
15291529      m_igs029_recv_buf[m_igs029_recv_len++] = 0x05;
15301530   }
15311531   else if (m_igs029_send_buf[0] == 0x07 && m_igs029_send_buf[1] == 0x15)
r32760r32761
15711571      case 0x00:
15721572         if (ACCESSING_BITS_0_7)
15731573         {
1574            bool igs029_irq = !(m_input_select & 0x04) &&  (data & 0x04);   // 0->1
1574            bool igs029_irq = !(m_input_select & 0x04) &&  (data & 0x04);   // 0->1
15751575
15761576            // 7654 3--- Keys
15771577            // ---- -2-- IRQ on IGS029
r32760r32761
16231623         if (ACCESSING_BITS_0_7)
16241624         {
16251625            m_scramble_data = data & 0xff;
1626//            logerror("%s: writing %02x to igs_magic = %02x\n", machine().describe_context(), data & 0xff, m_igs_magic[0]);
1626//              logerror("%s: writing %02x to igs_magic = %02x\n", machine().describe_context(), data & 0xff, m_igs_magic[0]);
16271627         }
16281628         break;
16291629
r32760r32761
16331633         if (ACCESSING_BITS_0_7)
16341634         {
16351635            m_igs029_send_data = data & 0xff;
1636//            logerror("%s: writing %02x to igs_magic = %02x\n", machine().describe_context(), data & 0xff, m_igs_magic[0]);
1636//              logerror("%s: writing %02x to igs_magic = %02x\n", machine().describe_context(), data & 0xff, m_igs_magic[0]);
16371637         }
16381638         break;
16391639
r32760r32761
16661666         return ret;
16671667      }
16681668
1669//      case 0x05: ???
1669//      case 0x05: ???
16701670
16711671      default:
16721672         logerror("%s: warning, reading with igs_magic = %02x\n", machine().describe_context(), m_igs_magic[0]);
r32760r32761
29472947
29482948   // DSWs are read through a protection device (IGS029). See code at 1CF16
29492949
2950   PORT_START("DSW1")   // $3009e2
2950   PORT_START("DSW1")  // $3009e2
29512951   PORT_DIPNAME( 0x03, 0x03, DEF_STR( Coinage ) )
29522952   PORT_DIPSETTING(    0x03, DEF_STR( 1C_1C ) )
29532953   PORT_DIPSETTING(    0x02, DEF_STR( 1C_2C ) )
r32760r32761
29712971   PORT_DIPSETTING(    0x80, "1000" )
29722972   PORT_DIPSETTING(    0x00, "2000" )
29732973
2974   PORT_START("DSW2")   // $3009e3
2974   PORT_START("DSW2")  // $3009e3
29752975   PORT_DIPNAME( 0x03, 0x03, "Min Bet" )
29762976   PORT_DIPSETTING(    0x03, "1" )
29772977   PORT_DIPSETTING(    0x02, "2" )
trunk/src/mame/drivers/dlair2.c
r32760r32761
268268
269269   ROM_REGION( 0x2000, "bios", 0 ) /* BIOS for proto board */
270270   ROM_LOAD( "dl2_amoa_proto_bios_mod_56ee.bin",0x00000, 0x2000, CRC(1fc21576) SHA1(dc5443f6a8d80ec8148314244f05ac0290e380ea) )
271   
271
272272ROM_END
273273
274274ROM_START( spacea91 )
trunk/src/mame/drivers/speedbal.c
r32760r32761
351351DRIVER_INIT_MEMBER(speedbal_state,musicbal)
352352{
353353   UINT8* rom = memregion("maincpu")->base();
354   
355    const UINT8 xorTable[8] = {0x05, 0x06, 0x84, 0x84, 0x00, 0x87, 0x84, 0x84};     // XORs affecting bits #0, #1, #2 & #7
356    const int swapTable[4][4] = {                                                   // 4 possible swaps affecting bits #0, #1, #2 & #7
357        {1,0,7,2},
358        {2,7,0,1},
359        {7,2,1,0},
360        {0,2,1,7}
361    };
362   
354
355   const UINT8 xorTable[8] = {0x05, 0x06, 0x84, 0x84, 0x00, 0x87, 0x84, 0x84};     // XORs affecting bits #0, #1, #2 & #7
356   const int swapTable[4][4] = {                                                   // 4 possible swaps affecting bits #0, #1, #2 & #7
357      {1,0,7,2},
358      {2,7,0,1},
359      {7,2,1,0},
360      {0,2,1,7}
361   };
362
363363   for (int i=0;i<0x8000;i++)
364364   {
365        int addIdx = BIT(i,3)^(BIT(i,5)<<1)^(BIT(i,9)<<2);  // 3 bits of address...
366        int xorMask = xorTable[addIdx];                     // ... control the xor...
367        int bswIdx = xorMask & 3;                           // ... and the bitswap
365      int addIdx = BIT(i,3)^(BIT(i,5)<<1)^(BIT(i,9)<<2);  // 3 bits of address...
366      int xorMask = xorTable[addIdx];                     // ... control the xor...
367      int bswIdx = xorMask & 3;                           // ... and the bitswap
368368
369        // only bits #0, #1, #2 & #7 are affected
370        rom[i] = BITSWAP8(rom[i], swapTable[bswIdx][3], 6,5,4,3, swapTable[bswIdx][2], swapTable[bswIdx][1], swapTable[bswIdx][0]) ^ xorTable[addIdx];
371    }
369      // only bits #0, #1, #2 & #7 are affected
370      rom[i] = BITSWAP8(rom[i], swapTable[bswIdx][3], 6,5,4,3, swapTable[bswIdx][2], swapTable[bswIdx][1], swapTable[bswIdx][0]) ^ xorTable[addIdx];
371   }
372372
373373   DRIVER_INIT_CALL(speedbal);
374374}
trunk/src/mame/drivers/btoads.c
r32760r32761
304304   MCFG_CPU_PROGRAM_MAP(main_map)
305305   MCFG_TMS340X0_HALT_ON_RESET(FALSE) /* halt on reset */
306306   MCFG_TMS340X0_PIXEL_CLOCK(VIDEO_CLOCK/2) /* pixel clock */
307   MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */   
307   MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */
308308   MCFG_TMS340X0_SCANLINE_RGB32_CB(btoads_state, scanline_update)     /* scanline updater (RGB32) */
309309   MCFG_TMS340X0_TO_SHIFTREG_CB(btoads_state, to_shiftreg)  /* write to shiftreg function */
310310   MCFG_TMS340X0_FROM_SHIFTREG_CB(btoads_state, from_shiftreg) /* read from shiftreg function */
trunk/src/mame/drivers/megatech.c
r32760r32761
131131   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( mt_cart6 ) { return load_cart(image, m_cart6, 5); }
132132   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( mt_cart7 ) { return load_cart(image, m_cart7, 6); }
133133   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( mt_cart8 ) { return load_cart(image, m_cart8, 7); }
134   
134
135135   UINT32 screen_update_main(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
136136   UINT32 screen_update_menu(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
137137   void screen_eof_main(screen_device &screen, bool state);
r32760r32761
424424   if (m_cart_reg[gameno])
425425   {
426426      memcpy(memregion("maincpu")->base(), m_cart_reg[gameno]->base(), 0x400000);
427     
427
428428      if (!m_cart_is_genesis[gameno])
429429      {
430430         logerror("enabling SMS Z80\n");
r32760r32761
442442         //m_maincpu->set_input_line(INPUT_LINE_HALT, CLEAR_LINE);
443443      }
444444   }
445   else   /* else, no cart.. */
445   else    /* else, no cart.. */
446446   {
447447      memset(memregion("mtbios")->base() + 0x8000, 0x00, 0x8000);
448448      memset(memregion("maincpu")->base(), 0x00, 0x400000);
r32760r32761
594594   m_banked_ram = auto_alloc_array(machine(), UINT8, 0x1000*8);
595595
596596   DRIVER_INIT_CALL(megadriv);
597   
597
598598   // this gets set in DEVICE_IMAGE_LOAD
599599   memset(m_cart_is_genesis, 0, sizeof(m_cart_is_genesis));
600600}
r32760r32761
641641{
642642   m_mt_bank_addr = 0;
643643   MACHINE_RESET_CALL_MEMBER(megadriv);
644   
644
645645   astring region_tag;
646646   if (m_cart1)
647647      m_cart_reg[0] = memregion(region_tag.cpy(m_cart1->tag()).cat(GENERIC_ROM_REGION_TAG));
r32760r32761
730730   UINT8 *ROM;
731731   const char  *pcb_name;
732732   UINT32 size = slot->common_get_size("rom");
733   
733
734734   if (image.software_entry() == NULL)
735735      return IMAGE_INIT_FAIL;
736   
736
737737   slot->rom_alloc(size, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
738738   ROM = slot->get_rom_base();
739739   memcpy(ROM, image.get_software_region("rom"), size);
r32760r32761
753753         m_cart_is_genesis[gameno] = 0;
754754      }
755755      else
756         osd_printf_debug("cart%d is invalid\n", gameno + 1);     
756         osd_printf_debug("cart%d is invalid\n", gameno + 1);
757757   }
758   
758
759759   return IMAGE_INIT_PASS;
760760}
761761
trunk/src/mame/drivers/vamphalf.c
r32760r32761
383383}
384384READ32_MEMBER(vamphalf_state::yorizori_1c_r)
385385{
386//   printf("yorizori_1c_r %08x\n", space.device().safe_pc());
386//  printf("yorizori_1c_r %08x\n", space.device().safe_pc());
387387   return 0x00;// 0xaa;
388388}
389389WRITE32_MEMBER(vamphalf_state::yorizori_1c_w)
390390{
391//   printf("yorizori_1c_w %08x %08x\n", space.device().safe_pc(), data);
391//  printf("yorizori_1c_w %08x %08x\n", space.device().safe_pc(), data);
392392}
393393
394394WRITE32_MEMBER( vamphalf_state::wyvernwg_snd_w )
r32760r32761
20782078ROM_START( yorizori )
20792079   ROM_REGION32_BE( 0x200000, "user1", ROMREGION_ERASE00 ) /* Hyperstone CPU Code */
20802080   ROM_LOAD( "prg1", 0x000000, 0x200000, CRC(0e04eb40) SHA1(0cec9dc91aaf9cf7c459c7baac200cf0fcfddc18) )
2081   
2081
20822082   ROM_REGION( 0x080000, "qs1000:cpu", 0 ) /* QDSP (8052) Code */
20832083   ROM_LOAD( "snd5", 0x00000, 0x20000, CRC(79067367) SHA1(a8f0c02dd616ff8c5fb49dea1a116fea2aced19c) )
20842084   ROM_RELOAD(      0x20000, 0x20000 )
trunk/src/mame/drivers/snesb.c
r32760r32761
638638static INPUT_PORTS_START( endless )
639639   PORT_INCLUDE(snes_common)
640640
641    PORT_START("DSW1")
642    PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coinage ) )
643    PORT_DIPSETTING(    0x01, DEF_STR( 4C_1C ) )
644    PORT_DIPSETTING(    0x02, DEF_STR( 3C_1C ) )
645    PORT_DIPSETTING(    0x03, DEF_STR( 2C_1C ) )
646    PORT_DIPSETTING(    0x07, DEF_STR( 1C_1C ) )
641   PORT_START("DSW1")
642   PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coinage ) )
643   PORT_DIPSETTING(    0x01, DEF_STR( 4C_1C ) )
644   PORT_DIPSETTING(    0x02, DEF_STR( 3C_1C ) )
645   PORT_DIPSETTING(    0x03, DEF_STR( 2C_1C ) )
646   PORT_DIPSETTING(    0x07, DEF_STR( 1C_1C ) )
647647//  PORT_DIPSETTING(    0x00, DEF_STR( 1C_1C ) )            /* duplicate setting */
648    PORT_DIPSETTING(    0x06, DEF_STR( 1C_2C ) )
649    PORT_DIPSETTING(    0x05, DEF_STR( 1C_3C ) )
650    PORT_DIPSETTING(    0x04, DEF_STR( 1C_4C ) )
651    PORT_DIPNAME( 0x38, 0x38, DEF_STR( Difficulty ) )       /* "LEVEL" */
652    PORT_DIPSETTING(    0x38, "0 (Easiest)" )               /* "EASY" */
653    PORT_DIPSETTING(    0x30, "1" )                         /* "NORMAL" */
654    PORT_DIPSETTING(    0x28, "2" )                         /* "HARD" */
655    PORT_DIPSETTING(    0x20, "3" )                         /* undefined */
656    PORT_DIPSETTING(    0x18, "4" )                         /* undefined */
657    PORT_DIPSETTING(    0x10, "5" )                         /* undefined */
658    PORT_DIPSETTING(    0x08, "6" )                         /* undefined */
659    PORT_DIPSETTING(    0x00, "7 (Hardest)" )               /* undefined */
660    PORT_DIPNAME( 0xc0, 0xc0, "Time" )                      /* "TIME" */
661    PORT_DIPSETTING(    0xc0, "99" )                        /* "LIMIT" */
662    PORT_DIPSETTING(    0x80, "60" )                        /* undefined */
663    PORT_DIPSETTING(    0x40, "30" )                        /* undefined */
664    PORT_DIPSETTING(    0x00, "Infinite" )                  /* "NO LIMIT" */
648   PORT_DIPSETTING(    0x06, DEF_STR( 1C_2C ) )
649   PORT_DIPSETTING(    0x05, DEF_STR( 1C_3C ) )
650   PORT_DIPSETTING(    0x04, DEF_STR( 1C_4C ) )
651   PORT_DIPNAME( 0x38, 0x38, DEF_STR( Difficulty ) )       /* "LEVEL" */
652   PORT_DIPSETTING(    0x38, "0 (Easiest)" )               /* "EASY" */
653   PORT_DIPSETTING(    0x30, "1" )                         /* "NORMAL" */
654   PORT_DIPSETTING(    0x28, "2" )                         /* "HARD" */
655   PORT_DIPSETTING(    0x20, "3" )                         /* undefined */
656   PORT_DIPSETTING(    0x18, "4" )                         /* undefined */
657   PORT_DIPSETTING(    0x10, "5" )                         /* undefined */
658   PORT_DIPSETTING(    0x08, "6" )                         /* undefined */
659   PORT_DIPSETTING(    0x00, "7 (Hardest)" )               /* undefined */
660   PORT_DIPNAME( 0xc0, 0xc0, "Time" )                      /* "TIME" */
661   PORT_DIPSETTING(    0xc0, "99" )                        /* "LIMIT" */
662   PORT_DIPSETTING(    0x80, "60" )                        /* undefined */
663   PORT_DIPSETTING(    0x40, "30" )                        /* undefined */
664   PORT_DIPSETTING(    0x00, "Infinite" )                  /* "NO LIMIT" */
665665
666    PORT_START("DSW2")
667    PORT_DIPUNUSED( 0x01, IP_ACTIVE_LOW )
668    PORT_DIPUNUSED( 0x02, IP_ACTIVE_LOW )
669    PORT_DIPUNUSED( 0x04, IP_ACTIVE_LOW )
670    PORT_DIPUNUSED( 0x08, IP_ACTIVE_LOW )
671    PORT_DIPUNUSED( 0x10, IP_ACTIVE_LOW )
672    PORT_DIPUNUSED( 0x20, IP_ACTIVE_LOW )
673    PORT_DIPUNUSED( 0x40, IP_ACTIVE_LOW )
674    PORT_DIPUNUSED( 0x80, IP_ACTIVE_LOW )
666   PORT_START("DSW2")
667   PORT_DIPUNUSED( 0x01, IP_ACTIVE_LOW )
668   PORT_DIPUNUSED( 0x02, IP_ACTIVE_LOW )
669   PORT_DIPUNUSED( 0x04, IP_ACTIVE_LOW )
670   PORT_DIPUNUSED( 0x08, IP_ACTIVE_LOW )
671   PORT_DIPUNUSED( 0x10, IP_ACTIVE_LOW )
672   PORT_DIPUNUSED( 0x20, IP_ACTIVE_LOW )
673   PORT_DIPUNUSED( 0x40, IP_ACTIVE_LOW )
674   PORT_DIPUNUSED( 0x80, IP_ACTIVE_LOW )
675675
676676   PORT_START("COIN")
677677   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
trunk/src/mame/drivers/battlera.c
r32760r32761
7272   AM_RANGE( 0x1FE400, 0x1FE7FF) AM_DEVREADWRITE( "huc6260", huc6260_device, read, write )
7373   AM_RANGE( 0x1FEC00, 0x1FEFFF) AM_DEVREADWRITE( "maincpu", h6280_device, timer_r, timer_w )
7474   AM_RANGE( 0x1FF400, 0x1FF7FF) AM_DEVREADWRITE( "maincpu", h6280_device, irq_status_r, irq_status_w )
75   
75
7676ADDRESS_MAP_END
7777
7878static ADDRESS_MAP_START( battlera_portmap, AS_IO, 8, battlera_state )
trunk/src/mame/drivers/atarisy4.c
r32760r32761
3333public:
3434   atarisy4_renderer(atarisy4_state &state, screen_device &screen);
3535   ~atarisy4_renderer() {}
36   
36
3737   void draw_scanline(INT32 scanline, const extent_t &extent, const atarisy4_polydata &extradata, int threadid);
3838   void draw_polygon(UINT16 color);
39   
39
4040   atarisy4_state &m_state;
4141};
4242
r32760r32761
5454      m_screen_ram(*this, "screen_ram"),
5555      m_dsp0_bank1(*this, "dsp0_bank1"),
5656      m_dsp1_bank1(*this, "dsp1_bank1") { }
57     
57
5858   required_device<cpu_device> m_maincpu;
5959   required_device<cpu_device> m_dsp0;
6060   optional_device<cpu_device> m_dsp1;
6161   required_device<palette_device> m_palette;
6262   required_device<screen_device> m_screen;
63   
63
6464   required_shared_ptr<UINT16> m_m68k_ram;
6565   required_shared_ptr<UINT16> m_screen_ram;
66   
66
6767   required_memory_bank m_dsp0_bank1;
6868   optional_memory_bank m_dsp1_bank1;
6969
7070   atarisy4_renderer *m_renderer;
71   
71
7272   UINT8 m_r_color_table[256];
7373   UINT8 m_g_color_table[256];
7474   UINT8 m_b_color_table[256];
7575   UINT16 m_dsp_bank[2];
7676   UINT8 m_csr[2];
7777   UINT16 *m_shared_ram[2];
78   
78
7979   DECLARE_WRITE16_MEMBER(gpu_w);
8080   DECLARE_READ16_MEMBER(gpu_r);
8181   DECLARE_READ16_MEMBER(m68k_shared_0_r);
r32760r32761
177177{
178178}
179179
180 void atarisy4_state::video_start()
180   void atarisy4_state::video_start()
181181{
182182   m_renderer = auto_alloc(machine(), atarisy4_renderer(*this, *m_screen));
183183}
trunk/src/mame/drivers/metro.c
r32760r32761
34653465
34663466   PORT_START("DSW0")
34673467   // DSW1, stored at 0xff0085.b (cpl'ed)
3468   PORT_DIPNAME( 0x0007, 0x0007, DEF_STR( Coinage ) )   PORT_DIPLOCATION("SW1:1,2,3")
3468   PORT_DIPNAME( 0x0007, 0x0007, DEF_STR( Coinage ) )  PORT_DIPLOCATION("SW1:1,2,3")
34693469   PORT_DIPSETTING(      0x0005, DEF_STR( 3C_1C )  )
34703470   PORT_DIPSETTING(      0x0006, DEF_STR( 2C_1C )  )
34713471   PORT_DIPSETTING(      0x0007, DEF_STR( 1C_1C )  )
r32760r32761
34753475   PORT_DIPSETTING(      0x0001, DEF_STR( 1C_5C )  )
34763476   PORT_DIPSETTING(      0x0000, DEF_STR( 1C_6C )  )
34773477   PORT_DIPUNUSED_DIPLOC( 0x0008, IP_ACTIVE_LOW, "SW1:4" ) /* 0x01 (OFF) or 0x02 (ON) written to 0xff0112.b but NEVER read back - old credits for 2 players game ? */
3478   PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Flip_Screen ) )   PORT_DIPLOCATION("SW1:5")  /* 0x07c1 written to 0x1788ac.w (screen control ?) at first (code at 0x0001b8) */
3478   PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Flip_Screen ) )  PORT_DIPLOCATION("SW1:5")  /* 0x07c1 written to 0x1788ac.w (screen control ?) at first (code at 0x0001b8) */
34793479   PORT_DIPSETTING(      0x0010, DEF_STR( Off ) )          /* 0x07c1 written to 0xff0114.w (then 0x1788ac.w) during initialisation (code at 0x000436) */
34803480   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )           /* 0x07c0 written to 0xff0114.w (then 0x1788ac.w) during initialisation (code at 0x000436) */
3481   PORT_DIPNAME( 0x0020, 0x0020, DEF_STR( Demo_Sounds ) )   PORT_DIPLOCATION("SW1:6")
3481   PORT_DIPNAME( 0x0020, 0x0020, DEF_STR( Demo_Sounds ) )  PORT_DIPLOCATION("SW1:6")
34823482   PORT_DIPSETTING(      0x0000, DEF_STR( Off ) )
34833483   PORT_DIPSETTING(      0x0020, DEF_STR( On ) )
34843484   PORT_DIPUNUSED_DIPLOC( 0x0040, IP_ACTIVE_LOW, "SW1:7" )
r32760r32761
34863486
34873487   PORT_START("IN2")
34883488   // DSW2, stored at 0xff0084.b (cpl'ed)
3489   PORT_DIPNAME( 0x0003, 0x0003, DEF_STR( Difficulty ) )   PORT_DIPLOCATION("SW2:1,2")
3489   PORT_DIPNAME( 0x0003, 0x0003, DEF_STR( Difficulty ) )   PORT_DIPLOCATION("SW2:1,2")
34903490   PORT_DIPSETTING(      0x0002, DEF_STR( Easy ) )
34913491   PORT_DIPSETTING(      0x0003, DEF_STR( Normal ) )
34923492   PORT_DIPSETTING(      0x0001, DEF_STR( Hard ) )
34933493   PORT_DIPSETTING(      0x0000, DEF_STR( Hardest ) )
3494   PORT_DIPNAME( 0x000c, 0x000c, DEF_STR( Lives ) )   PORT_DIPLOCATION("SW2:3,4")
3494   PORT_DIPNAME( 0x000c, 0x000c, DEF_STR( Lives ) )    PORT_DIPLOCATION("SW2:3,4")
34953495   PORT_DIPSETTING(      0x0008, "1"  )
34963496   PORT_DIPSETTING(      0x0004, "2"  )
34973497   PORT_DIPSETTING(      0x000c, "3"  )
34983498   PORT_DIPSETTING(      0x0000, "4"  )
3499   PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Bonus_Life ) )   PORT_DIPLOCATION("SW2:5")   /* code at 0x0004a4 */
3499   PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Bonus_Life ) )   PORT_DIPLOCATION("SW2:5")   /* code at 0x0004a4 */
35003500   PORT_DIPSETTING(      0x0010, "Every 30000" )
35013501   PORT_DIPSETTING(      0x0000, "Every 60000" )
35023502   PORT_DIPUNUSED_DIPLOC( 0x0020, IP_ACTIVE_LOW, "SW2:6" )
trunk/src/mame/drivers/midwunit.c
r32760r32761
621621   MCFG_CPU_PROGRAM_MAP(main_map)
622622   MCFG_TMS340X0_HALT_ON_RESET(FALSE) /* halt on reset */
623623   MCFG_TMS340X0_PIXEL_CLOCK(PIXEL_CLOCK) /* pixel clock */
624   MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */   
624   MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */
625625   MCFG_TMS340X0_SCANLINE_IND16_CB(midtunit_state, scanline_update)       /* scanline updater (indexed16) */
626626   MCFG_TMS340X0_TO_SHIFTREG_CB(midtunit_state, to_shiftreg)           /* write to shiftreg function */
627627   MCFG_TMS340X0_FROM_SHIFTREG_CB(midtunit_state, from_shiftreg)          /* read from shiftreg function */
trunk/src/mame/drivers/legionna.c
r32760r32761
106106   AM_RANGE(0x100428, 0x100429) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_dma_v1_w)
107107   AM_RANGE(0x10042a, 0x10042b) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_dma_v2_w)
108108   AM_RANGE(0x10042c, 0x10042d) AM_DEVREADWRITE("raiden2cop", raiden2cop_device, cop_prng_maxvalue_r, cop_prng_maxvalue_w)
109   
109
110110   AM_RANGE(0x100432, 0x100433) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_data_w)
111111   AM_RANGE(0x100434, 0x100435) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_addr_w)
112112   AM_RANGE(0x100436, 0x100437) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_hitbox_baseadr_w)
113113   AM_RANGE(0x100438, 0x100439) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_value_w)
114114   AM_RANGE(0x10043a, 0x10043b) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_mask_w)
115115   AM_RANGE(0x10043c, 0x10043d) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_trigger_w)
116   //AM_RANGE(0x10043e, 0x10043f) AM_DEVWRITE("raiden2cop", raiden2cop_device,)   /*   0 in all 68k based games,    0xffff in raiden2 / raidendx,    0x2000 in zeroteam / xsedae , it's always set up just before the 0x474 register */
116   //AM_RANGE(0x10043e, 0x10043f) AM_DEVWRITE("raiden2cop", raiden2cop_device,)    /*  0 in all 68k based games,   0xffff in raiden2 / raidendx,   0x2000 in zeroteam / xsedae , it's always set up just before the 0x474 register */
117117
118118   AM_RANGE(0x100444, 0x100445) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_scale_w)
119119   AM_RANGE(0x100446, 0x100447) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_rom_addr_unk_w) // 68k
120120   AM_RANGE(0x100448, 0x100449) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_rom_addr_lo_w) // 68k
121121   AM_RANGE(0x10044a, 0x10044b) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_rom_addr_hi_w) // 68k
122   
122
123123   AM_RANGE(0x100450, 0x100451) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_sort_ram_addr_hi_w)
124124   AM_RANGE(0x100452, 0x100453) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_sort_ram_addr_lo_w)
125125   AM_RANGE(0x100454, 0x100455) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_sort_lookup_hi_w)
r32760r32761
128128   AM_RANGE(0x10045a, 0x10045b) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pal_brightness_val_w) //palette DMA brightness val, used by X Se Dae / Zero Team
129129   AM_RANGE(0x10045c, 0x10045d) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pal_brightness_mode_w)  //palette DMA brightness mode, used by X Se Dae / Zero Team (sets to 5)
130130
131//   AM_RANGE(0x100470, 0x100471) AM_READWRITE(cop_tile_bank_2_r,cop_tile_bank_2_w)
132//   AM_RANGE(0x100474, 0x100475) AM_DEVWRITE("raiden2cop", raiden2cop_device,) // this gets set to a pointer to spriteram (relative to start of ram) on all games excecpt raiden 2, where it isn't set
131//  AM_RANGE(0x100470, 0x100471) AM_READWRITE(cop_tile_bank_2_r,cop_tile_bank_2_w)
132//  AM_RANGE(0x100474, 0x100475) AM_DEVWRITE("raiden2cop", raiden2cop_device,) // this gets set to a pointer to spriteram (relative to start of ram) on all games excecpt raiden 2, where it isn't set
133133   AM_RANGE(0x100476, 0x100477) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_dma_adr_rel_w)
134134   AM_RANGE(0x100478, 0x100479) AM_DEVWRITE("raiden2cop", raiden2cop_device,cop_dma_src_w)
135135   AM_RANGE(0x10047a, 0x10047b) AM_DEVWRITE("raiden2cop", raiden2cop_device,cop_dma_size_w)
r32760r32761
142142   AM_RANGE(0x1004a0, 0x1004ad) AM_DEVREADWRITE("raiden2cop", raiden2cop_device, cop_reg_high_r, cop_reg_high_w)
143143   AM_RANGE(0x1004c0, 0x1004cd) AM_DEVREADWRITE("raiden2cop", raiden2cop_device, cop_reg_low_r, cop_reg_low_w)
144144
145//   AM_RANGE(0x100500, 0x100505) AM_WRITE(cop_cmd_w) // ADD ME
145//  AM_RANGE(0x100500, 0x100505) AM_WRITE(cop_cmd_w) // ADD ME
146146   AM_RANGE(0x100500, 0x100505) AM_DEVWRITE("raiden2cop", raiden2cop_device,LEGACY_cop_cmd_w) // REMOVE ME
147147
148148   AM_RANGE(0x100580, 0x100581) AM_DEVREAD("raiden2cop", raiden2cop_device, cop_collision_status_r)
r32760r32761
222222   AM_RANGE(0x101800, 0x101fff) AM_RAM // _WRITE(legionna_foreground_w) AM_SHARE("fore_data")
223223   AM_RANGE(0x102000, 0x1027ff) AM_RAM // _WRITE(legionna_midground_w) AM_SHARE("mid_data")
224224   AM_RANGE(0x102800, 0x1037ff) AM_RAM // _WRITE(legionna_text_w) AM_SHARE("textram")
225   AM_RANGE(0x103800, 0x103fff) AM_RAM // check?
225   AM_RANGE(0x103800, 0x103fff) AM_RAM // check?
226226   AM_RANGE(0x104000, 0x104fff) AM_RAM // _DEVWRITE("palette", palette_device, write) AM_SHARE("palette")
227227   AM_RANGE(0x105000, 0x105fff) AM_RAM AM_SHARE("spriteram")
228228   AM_RANGE(0x106000, 0x1067ff) AM_RAM
trunk/src/mame/drivers/aristmk4.c
r32760r32761
17031703
17041704   MCFG_SOUND_ADD("samples", SAMPLES, 0)
17051705   MCFG_SAMPLES_CHANNELS(5)  /* one for each meter - can pulse simultaneously */
1706   MCFG_SAMPLES_NAMES(meter_sample_names)   
1706   MCFG_SAMPLES_NAMES(meter_sample_names)
17071707   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.05)
17081708
17091709MACHINE_CONFIG_END
trunk/src/mame/drivers/naomi.c
r32760r32761
17831783   } else
17841784      if (reg == 0x284/4)
17851785         return U64(0xffffffffffffff00) | aw_ctrl_type;
1786   
17871786
1787
17881788   osd_printf_verbose("MODEM:  Unmapped read %08x\n", 0x600000+reg*4);
17891789   return 0;
17901790}
r32760r32761
18001800   if (reg == 0x284/4)
18011801   {
18021802   /*
1803      0x00600284 rw ddccbbaa
1803       0x00600284 rw ddccbbaa
18041804           aa/bb/cc/dd - set type of Maple devices at ports 0/1/2/3
1805      0 - regular DC controller, but with 4 analogue channels (default)
1806      1 - DC lightgun
1807      2 - DC mouse/trackball
1808      TODO: hook this then MAME have such devices emulated
1805       0 - regular DC controller, but with 4 analogue channels (default)
1806       1 - DC lightgun
1807       2 - DC mouse/trackball
1808       TODO: hook this then MAME have such devices emulated
18091809   */
18101810      aw_ctrl_type = dat & 0xFF;
18111811   }
r32760r32761
41094109   NAOMI_DEFAULT_EEPROM
41104110
41114111   ROM_REGION( 0x7800000, "rom_board", ROMREGION_ERASEFF)
4112   ROM_LOAD( "epr-24286.ic22", 0x0000000, 0x0400000, CRC(9d26e2fc) SHA1(74bcd7daf994a5c97c836b6f060c73d31a9c06d8) )
4113   ROM_LOAD( "mpr-24276.ic1",  0x0800000, 0x1000000, CRC(35ac9283) SHA1(74af0e3f294fc76d44c8c6b54042186dec8b9f8a) )
4114   ROM_LOAD( "mpr-24277.ic2",  0x1800000, 0x1000000, CRC(16111394) SHA1(7ca20de07cfa3fa248b472819bc893f00689e3a1) )
4115   ROM_LOAD( "mpr-24278.ic3",  0x2800000, 0x1000000, CRC(bf0ec0bc) SHA1(7de72decf97999e74b510e9655a57ad6d1def1c8) )
4116   ROM_LOAD( "mpr-24279.ic4",  0x3800000, 0x1000000, CRC(f7d0ab5b) SHA1(10188a22a1918b18008973135ef2e00dd26dd6cb) )
4117   ROM_LOAD( "mpr-24280.ic5",  0x4800000, 0x1000000, CRC(61d5c470) SHA1(c2b3dc71706a5c8a237efc2fe5c35061abb99173) )
4118   ROM_LOAD( "mpr-24281.ic6",  0x5800000, 0x1000000, CRC(39133c32) SHA1(09ea8c1a98ba0fac36e18ae14ed5302feaeb89ca) )
4119   ROM_LOAD( "mpr-24282.ic7",  0x6800000, 0x1000000, CRC(9aa4ad5a) SHA1(2d81f99a579477c5db725f71c51f18afc15abce7) )
4112   ROM_LOAD( "epr-24286.ic22", 0x0000000, 0x0400000, CRC(9d26e2fc) SHA1(74bcd7daf994a5c97c836b6f060c73d31a9c06d8) )
4113   ROM_LOAD( "mpr-24276.ic1",  0x0800000, 0x1000000, CRC(35ac9283) SHA1(74af0e3f294fc76d44c8c6b54042186dec8b9f8a) )
4114   ROM_LOAD( "mpr-24277.ic2",  0x1800000, 0x1000000, CRC(16111394) SHA1(7ca20de07cfa3fa248b472819bc893f00689e3a1) )
4115   ROM_LOAD( "mpr-24278.ic3",  0x2800000, 0x1000000, CRC(bf0ec0bc) SHA1(7de72decf97999e74b510e9655a57ad6d1def1c8) )
4116   ROM_LOAD( "mpr-24279.ic4",  0x3800000, 0x1000000, CRC(f7d0ab5b) SHA1(10188a22a1918b18008973135ef2e00dd26dd6cb) )
4117   ROM_LOAD( "mpr-24280.ic5",  0x4800000, 0x1000000, CRC(61d5c470) SHA1(c2b3dc71706a5c8a237efc2fe5c35061abb99173) )
4118   ROM_LOAD( "mpr-24281.ic6",  0x5800000, 0x1000000, CRC(39133c32) SHA1(09ea8c1a98ba0fac36e18ae14ed5302feaeb89ca) )
4119   ROM_LOAD( "mpr-24282.ic7",  0x6800000, 0x1000000, CRC(9aa4ad5a) SHA1(2d81f99a579477c5db725f71c51f18afc15abce7) )
41204120
41214121   ROM_REGION( 4, "rom_key", ROMREGION_ERASE00 )
41224122ROM_END
r32760r32761
90149014/* 0018  */ GAME( 2001, lupinsho, naomigd, naomigd,  hotd2,   naomi_state, naomigd, ROT0, "Sega / Eighting", "Lupin The Third - The Shooting (GDS-0018)", GAME_FLAGS )
90159015// 0018A Lupin The Third - The Shooting (Rev A)
90169016/* 0019  */ GAME( 2002, vathlete, naomigd, naomigd,  naomi,   naomi_state, naomigd, ROT0, "Sega", "Virtua Athletics / Virtua Athlete (GDS-0019)", GAME_FLAGS )
9017/* 0020  */ GAME( 2002, initdo,   initd,   naomi2gd, naomi,   naomi_state, naomi2,  ROT0, "Sega", "Initial D Arcade Stage (Japan) (GDS-0020)", GAME_FLAGS )
9017/* 0020  */ GAME( 2002, initdo,   initd,   naomi2gd, naomi,   naomi_state, naomi2,  ROT0, "Sega", "Initial D Arcade Stage (Japan) (GDS-0020)", GAME_FLAGS )
90189018// 0020A Initial D Arcade Stage (Rev A)
90199019/* 0020B */ GAME( 2002, initd,    naomi2,  naomi2gd, naomi,   naomi_state, naomi2,  ROT0, "Sega", "Initial D Arcade Stage (Rev B) (Japan) (GDS-0020B)", GAME_FLAGS )
90209020// 0021  Lupin The Third - The Typing
trunk/src/mame/drivers/snk6502.c
r32760r32761
827827   MCFG_SOUND_ADD("snk6502", SNK6502, 0)
828828   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
829829
830   
830
831831   MCFG_SOUND_ADD("samples", SAMPLES, 0)
832832   MCFG_SAMPLES_CHANNELS(4)
833833   MCFG_SAMPLES_NAMES(sasuke_sample_names)
trunk/src/mame/drivers/tatsumi.c
r32760r32761
13971397   int len1 = memregion("gfx2")->bytes();
13981398   UINT8 *src2 = memregion("gfx3")->base();
13991399   int len2 = memregion("gfx3")->bytes();
1400   
1400
14011401   for (int i=0; i<len1; i+=32)
14021402   {
14031403      memcpy(dst,src1,32);
trunk/src/mame/drivers/r2dx_v33.c
r32760r32761
55Raiden 2 / DX checks if there's the string "RAIDEN" at start-up inside the eeprom, otherwise it dies.
66Then it puts settings at 0x9e08 and 0x9e0a (bp 91acb)
77
8   the 333 ROM is a 0x10000 byte table (bytes values?)
9   followed by a 0x400 bytes (word values)?
10   the remaining space is 0xff
8    the 333 ROM is a 0x10000 byte table (bytes values?)
9    followed by a 0x400 bytes (word values)?
10    the remaining space is 0xff
1111
12   Notes:
12    Notes:
1313
14   Zero Team 2000
15    - EEPROM contains high scores, but they don't get restored? (original bug?)
14    Zero Team 2000
15     - EEPROM contains high scores, but they don't get restored? (original bug?)
1616
17   New Zero Team
18    - 2 Player only? Service mode only shows 2 Players and I don't see a switch
19    - Stages 3 and 1 are swapped, this is correct.
17    New Zero Team
18     - 2 Player only? Service mode only shows 2 Players and I don't see a switch
19     - Stages 3 and 1 are swapped, this is correct.
2020
21   Raiden 2 New / Raiden DX
22    - This is a 2-in-1 board.  The current game to boot is stored in the EEPROM.
23      If you wish to change game then on powerup you must hold down all 4 (P1) joystick
24      directions simultaneously along with either button 1 or button 2.
25      Obviously this is impossible with a real joystck!
21    Raiden 2 New / Raiden DX
22     - This is a 2-in-1 board.  The current game to boot is stored in the EEPROM.
23       If you wish to change game then on powerup you must hold down all 4 (P1) joystick
24       directions simultaneously along with either button 1 or button 2.
25       Obviously this is impossible with a real joystck!
2626
27      It is also impossible in MAME unless you enable -joystick_contradictory
28      to disable MAME from preventing opposing joystick directions being pressed
29      and you'll most likely have to remap some keys too because 5 buttons at the
30      same time is beyond the limits of most keyboards.
27       It is also impossible in MAME unless you enable -joystick_contradictory
28       to disable MAME from preventing opposing joystick directions being pressed
29       and you'll most likely have to remap some keys too because 5 buttons at the
30       same time is beyond the limits of most keyboards.
3131
32      We currently use a default EEPROM for each game as this is most likely how
33      it shipped, the game changing is an undocumented secret.
32       We currently use a default EEPROM for each game as this is most likely how
33       it shipped, the game changing is an undocumented secret.
3434
35    - The sound is awful, this is just how it is.
36   
37    - In Raiden 2 New stages 5 and 1 are swapped, and the intro is missing, this is
38      correct.
35     - The sound is awful, this is just how it is.
3936
37     - In Raiden 2 New stages 5 and 1 are swapped, and the intro is missing, this is
38       correct.
39
4040*/
4141
42/* Rom structure notes
42/* Rom structure notes
4343
4444 Raiden 2 New/DX (hardware can bank upper/lower half of rom to switch fixed areas)
4545
r32760r32761
192192      // 0x04 is active in Raiden DX mode, it could be part of the rom bank (which half of the rom to use) or the FG tile bank (or both?)
193193      // the bit gets set if it reads RAIDENDX from the EEPROM
194194      m_r2dxgameselect = (data & 0x04) >> 2;
195     
195
196196      tx_bank = m_r2dxgameselect;
197197      text_layer->mark_all_dirty();
198198
r32760r32761
277277
278278WRITE16_MEMBER(r2dx_v33_state::mcu_table2_w)
279279{
280//   printf("mcu_table2_w %04x %04x\n", data, mem_mask);
280//  printf("mcu_table2_w %04x %04x\n", data, mem_mask);
281281
282282   mcu_data[offset+4] = data;
283283
r32760r32761
356356{
357357   int src = 0x1f000;
358358
359   for (int i = 0; i < 0x1000 / 2; i++)
359   for (int i = 0; i < 0x1000 / 2; i++)
360360   {
361361      UINT16 palval = space.read_word(src);
362362      src += 2;
r32760r32761
392392   AM_RANGE(0x00436, 0x00437) AM_READ(r2dx_cos_r)
393393
394394   AM_RANGE(0x00600, 0x0064f) AM_DEVREADWRITE("crtc", seibu_crtc_device, read, write)
395//   AM_RANGE(0x00650, 0x0068f) AM_RAM //???
395//  AM_RANGE(0x00650, 0x0068f) AM_RAM //???
396396
397397   AM_RANGE(0x0068e, 0x0068f) AM_WRITENOP // maybe a watchdog?
398398   AM_RANGE(0x006b0, 0x006b1) AM_WRITE(mcu_prog_w) // could be encryption key uploads just like raiden2.c ?
r32760r32761
400400//  AM_RANGE(0x006b4, 0x006b5) AM_WRITENOP
401401//  AM_RANGE(0x006b6, 0x006b7) AM_WRITENOP
402402   AM_RANGE(0x006bc, 0x006bd) AM_WRITE(mcu_prog_offs_w)
403//   AM_RANGE(0x006be, 0x006bf) AM_WRITENOP
403//  AM_RANGE(0x006be, 0x006bf) AM_WRITENOP
404404
405405   // sprite protection not 100% verified as the same
406406   AM_RANGE(0x006c0, 0x006c1) AM_READWRITE(sprite_prot_off_r, sprite_prot_off_w)
r32760r32761
411411   AM_RANGE(0x006da, 0x006db) AM_WRITE(sprite_prot_y_w)
412412   AM_RANGE(0x006dc, 0x006dd) AM_READWRITE(sprite_prot_maxx_r, sprite_prot_maxx_w)
413413   AM_RANGE(0x006de, 0x006df) AM_WRITE(sprite_prot_src_w)
414   
415414
415
416416   AM_RANGE(0x00700, 0x00701) AM_WRITE(rdx_v33_eeprom_w)
417417   AM_RANGE(0x00740, 0x00741) AM_READ(r2dx_debug_r)
418418   AM_RANGE(0x00744, 0x00745) AM_READ_PORT("INPUT")
r32760r32761
502502
503503WRITE16_MEMBER(r2dx_v33_state::zerotm2k_eeprom_w)
504504{
505//   printf("zerotm2k_eeprom_w %04x %04x\n", data, mem_mask);
505//  printf("zerotm2k_eeprom_w %04x %04x\n", data, mem_mask);
506506
507507   m_eeprom->clk_write((data & 0x02) ? ASSERT_LINE : CLEAR_LINE);
508508   m_eeprom->di_write((data & 0x04) >> 2);
r32760r32761
962962   ROM_LOAD("prg.223", 0x000000, 0x400000, CRC(b3dbcf98) SHA1(30d6ec2090531c8c579dff74c4898889902d7d87) )
963963
964964   ROM_REGION( 0x400000, "maincpu", ROMREGION_ERASEFF ) /* v33 main cpu */
965   
965
966966   ROM_REGION( 0x040000, "gfx1", 0 ) /* chars */
967967   ROM_LOAD( "fix.613", 0x000000, 0x040000, CRC(3da27e39) SHA1(3d446990bf36dd0a3f8fadb68b15bed54904c8b5) )
968968
r32760r32761
10111011ROM_END
10121012
10131013// uses dipswitches
1014ROM_START( nzeroteam ) /* V33 SYSTEM TYPE_B hardware, uses SEI333 (AKA COPX-D3) for protection  */
1014ROM_START( nzeroteam ) /* V33 SYSTEM TYPE_B hardware, uses SEI333 (AKA COPX-D3) for protection  */
10151015   ROM_REGION( 0x100000, "mainprg", 0 ) /* v30 main cpu */
10161016   ROM_LOAD16_BYTE("prg1", 0x000000, 0x80000, CRC(3c7d9410) SHA1(25f2121b6c2be73f11263934266901ed5d64d2ee) )
10171017   ROM_LOAD16_BYTE("prg2", 0x000001, 0x80000, CRC(6cba032d) SHA1(bf5d488cd578fff09e62e3650efdee7658033e3f) )
trunk/src/mame/drivers/warpsped.c
r32760r32761
9898
9999   required_device<cpu_device> m_maincpu;
100100   required_device<gfxdecode_device> m_gfxdecode;
101   
101
102102   required_shared_ptr<UINT8> m_videoram;
103103   required_shared_ptr<UINT8> m_workram;
104   
104
105105   tilemap_t   *m_text_tilemap;
106106   tilemap_t   *m_starfield_tilemap;
107107   UINT8       m_regs[0x28];
trunk/src/mame/drivers/splash.c
r32760r32761
10231023
10241024   int ofst = offset+(0x100000/2);
10251025
1026//   logerror ("PROTR: %5.5x, pc: %5.5x\n", ofst*2, pc);
1026//  logerror ("PROTR: %5.5x, pc: %5.5x\n", ofst*2, pc);
10271027
10281028   // don't interfere with ram check.
10291029   if (pc == 0x04770) return 0x00;
r32760r32761
10711071
10721072      //-----------------------------------------------------------------
10731073      // sub $7F70, $8038, $116E2, no subtractions, straight compare!, original value from 68k
1074      // increase ff3cc8 value in sub $116e2
1075   
1074      // increase ff3cc8 value in sub $116e2
1075
10761076      case ((0x100001 / 2) + 0x0010): // $7F72
10771077         funystrp_val = funystrp_ff3cc8_val;
10781078         return 0;
r32760r32761
11021102         return (funystrp_val + 0x12) & 0xff;
11031103
11041104      // first case... weird?
1105   //   case ((0x104801 / 2) + 0x013A): // $857E
1106   //      return (funystrp_val + 0x00) & 0xff;
1105   //  case ((0x104801 / 2) + 0x013A): // $857E
1106   //      return (funystrp_val + 0x00) & 0xff;
11071107
11081108      case ((0x104801 / 2) + 0x0277): // $85A4
11091109         return (funystrp_val + 0x04) & 0xff;
r32760r32761
11361136
11371137      //-----------------------------------------------------------------
11381138      // sub $9DD2, subtractions, original value from protection device
1139   
1139
11401140      case ((0x170001 / 2) + 0x006B): // $9DD4
11411141         funystrp_val = 0;
11421142         return 0;
r32760r32761
11761176      //-----------------------------------------------------------------
11771177      // sub $C5E4, subtractions, original value from 68k
11781178
1179   //   these cases are already in sub $7ACC, last one is new!!
1180   //   case ((0x107001 / 2) + 0x0030): // $7ACE
1181   //      funystrp_val = funystrp_ff3cc7_val & 0x7f;
1182   //      return 0;
1179   //  these cases are already in sub $7ACC, last one is new!!
1180   //  case ((0x107001 / 2) + 0x0030): // $7ACE
1181   //      funystrp_val = funystrp_ff3cc7_val & 0x7f;
1182   //      return 0;
11831183
1184   //   case ((0x107001 / 2) + 0x013e): // $7AFC
1185   //      return (funystrp_val + 0x13) & 0xff;
1184   //  case ((0x107001 / 2) + 0x013e): // $7AFC
1185   //      return (funystrp_val + 0x13) & 0xff;
11861186
1187   //   case ((0x107001 / 2) + 0x0279): // $7B38
1188   //      return (funystrp_val + 0x22) & 0xff;
1187   //  case ((0x107001 / 2) + 0x0279): // $7B38
1188   //      return (funystrp_val + 0x22) & 0xff;
11891189
1190   //   case ((0x107001 / 2) + 0x0357): // $7B6E
1191   //      return (funystrp_val + 0x44) & 0xff;
1190   //  case ((0x107001 / 2) + 0x0357): // $7B6E
1191   //      return (funystrp_val + 0x44) & 0xff;
11921192
11931193      case ((0x107001 / 2) + 0x0381): // $7BA4
11941194         return (funystrp_val + 0x6a) & 0xff;
r32760r32761
12151215      //-----------------------------------------------------------------
12161216      // sub $F72C, subtractions, original value from protection device,
12171217      // routine verified working!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1218   
1218
12191219      case ((0x100001 / 2) + 0x0017): // $F72E
12201220         funystrp_val = 0;
12211221         return 0;
r32760r32761
12331233         return (funystrp_val + 0x70) & 0xff;
12341234
12351235      //-----------------------------------------------------------------
1236      // sub $F82E, subtractions, original value from protection device,
1237   
1236      // sub $F82E, subtractions, original value from protection device,
1237
12381238      case ((0x100001 / 2) + 0x0013): // $F830
12391239         funystrp_val = 0;
12401240         return 0;
r32760r32761
12421242      case ((0x100001 / 2) + 0x0125): // $F84E
12431243         return (funystrp_val + 0x17) & 0xff;
12441244
1245   //   used in sub $7E76
1246   //   case ((0x110001 / 2) + 0x0261): // $F88A
1247   //      return (funystrp_val + 0x0f) & 0xff;
1245   //  used in sub $7E76
1246   //  case ((0x110001 / 2) + 0x0261): // $F88A
1247   //      return (funystrp_val + 0x0f) & 0xff;
12481248
1249   //   case ((0x110001 / 2) + 0x0322): // $F8C0
1250   //      return (funystrp_val + 0x12) & 0xff;
1249   //  case ((0x110001 / 2) + 0x0322): // $F8C0
1250   //      return (funystrp_val + 0x12) & 0xff;
12511251
1252   //   case ((0x110001 / 2) + 0x039B): // $F8F6
1253   //      return (funystrp_val + 0x70) & 0xff;
1252   //  case ((0x110001 / 2) + 0x039B): // $F8F6
1253   //      return (funystrp_val + 0x70) & 0xff;
12541254
12551255      //-----------------------------------------------------------------
12561256      // sub $10FE2, subtractions, original value from protection device
12571257      // routine is different from rest, unoptimized or just poorly coded?
12581258      // examine later to verify this is right
1259   
1259
12601260      case ((0x105001 / 2) + 0x0021): // $10FF6
12611261         funystrp_val = 0;
12621262         return 0;
r32760r32761
12741274         return (funystrp_val + 0x03) & 0xff;
12751275
12761276      //-----------------------------------------------------------------
1277      // sub $11F2C, subtractions, original value from protection device,
1277      // sub $11F2C, subtractions, original value from protection device,
12781278      // routine is different from rest, unoptimized or just poorly coded?
12791279      // examine later to verify this is right
1280   
1280
12811281      case ((0x183001 / 2) + 0x0088): // $11F3C
12821282         funystrp_val = 0;
12831283         return 0;
r32760r32761
13021302{
13031303   int ofst = (0x100000/2)+offset;
13041304
1305//   logerror ("PROTW: %5.5x, %4.4x, PC: %5.5x m: %4.4x\n", ofst*2, data, space.device().safe_pc(), mem_mask);
1305//  logerror ("PROTW: %5.5x, %4.4x, PC: %5.5x m: %4.4x\n", ofst*2, data, space.device().safe_pc(), mem_mask);
13061306
1307//   if (ACCESSING_BITS_0_7) // ??
1307//  if (ACCESSING_BITS_0_7) // ??
13081308   {
13091309      switch (ofst)
13101310      {
r32760r32761
13201320         case (0x1007e5/2):
13211321            funystrp_ff3cc8_val = data;
13221322         return;
1323   
1323
13241324         case (0x1007e7/2):
13251325            funystrp_ff3cc7_val = data;
13261326         return;
trunk/src/mame/drivers/bmcpokr.c
r32760r32761
232232
233233   switch (layer)
234234   {
235      case 1:      tmap = m_tilemap_1;   scroll = m_scrollram_1;   ctrl = (m_layerctrl[0] >> 8) & 0xff; break;
236      case 2:      tmap = m_tilemap_2;   scroll = m_scrollram_2; ctrl = (m_layerctrl[0] >> 0) & 0xff; break;
237      default:   tmap = 0;         scroll = m_scrollram_3; ctrl = (m_layerctrl[1] >> 8) & 0xff; break;
235      case 1:     tmap = m_tilemap_1; scroll = m_scrollram_1; ctrl = (m_layerctrl[0] >> 8) & 0xff; break;
236      case 2:     tmap = m_tilemap_2; scroll = m_scrollram_2; ctrl = (m_layerctrl[0] >> 0) & 0xff; break;
237      default:    tmap = 0;           scroll = m_scrollram_3; ctrl = (m_layerctrl[1] >> 8) & 0xff; break;
238238   }
239239
240240   if (ctrl == 0x00)
r32760r32761
292292
293293   bitmap.fill(m_palette->black_pen(), cliprect);
294294
295   if (layers_ctrl & 2)   draw_layer(screen, bitmap, cliprect, 2);
295   if (layers_ctrl & 2)    draw_layer(screen, bitmap, cliprect, 2);
296296/*
297   title:      17, 13/17
298   dogs:      1b, 13, 17
299   service:   17
300   game:      17
297    title:      17, 13/17
298    dogs:       1b, 13, 17
299    service:    17
300    game:       17
301301*/
302302   if (*m_priority & 0x0008)
303303   {
304      if (layers_ctrl & 4)   draw_layer(screen, bitmap, cliprect, 3);
305      if (layers_ctrl & 1)   draw_layer(screen, bitmap, cliprect, 1);
304      if (layers_ctrl & 4)    draw_layer(screen, bitmap, cliprect, 3);
305      if (layers_ctrl & 1)    draw_layer(screen, bitmap, cliprect, 1);
306306   }
307307   else
308308   {
309      if (layers_ctrl & 1)   draw_layer(screen, bitmap, cliprect, 1);
310      if (layers_ctrl & 4)   draw_layer(screen, bitmap, cliprect, 3);
309      if (layers_ctrl & 1)    draw_layer(screen, bitmap, cliprect, 1);
310      if (layers_ctrl & 4)    draw_layer(screen, bitmap, cliprect, 3);
311311   }
312312   return 0;
313313}
r32760r32761
326326{
327327   switch (m_prot_val >> 8)
328328   {
329      case 0x00:   return 0x1d << 8;
330      case 0x94:   return 0x81 << 8;
329      case 0x00:  return 0x1d << 8;
330      case 0x94:  return 0x81 << 8;
331331   }
332332   return 0x00 << 8;
333333}
334334WRITE16_MEMBER(bmcpokr_state::prot_w)
335335{
336336   COMBINE_DATA(&m_prot_val);
337//   logerror("%s: prot val = %04x\n", machine().describe_context(), m_prot_val);
337//  logerror("%s: prot val = %04x\n", machine().describe_context(), m_prot_val);
338338}
339339
340340/***************************************************************************
r32760r32761
346346   COMBINE_DATA(&m_mux);
347347   if (ACCESSING_BITS_0_7)
348348   {
349      m_hopper->write(space, 0,   (data & 0x0001) ? 0x80 : 0x00);   // hopper motor
350      coin_counter_w(machine(), 1, data & 0x0002);            // coin-in / key-in
351      coin_counter_w(machine(), 2, data & 0x0004);            // pay-out
352      //                           data & 0x0060               // DSW mux
353      //                           data & 0x0080               // ? always on
349      m_hopper->write(space, 0,   (data & 0x0001) ? 0x80 : 0x00); // hopper motor
350      coin_counter_w(machine(), 1, data & 0x0002);                // coin-in / key-in
351      coin_counter_w(machine(), 2, data & 0x0004);                // pay-out
352      //                           data & 0x0060                  // DSW mux
353      //                           data & 0x0080                  // ? always on
354354   }
355355
356//   popmessage("mux %04x", m_mux);
356//  popmessage("mux %04x", m_mux);
357357}
358358READ16_MEMBER(bmcpokr_state::dsw_r)
359359{
r32760r32761
402402
403403   AM_RANGE(0x2a0000, 0x2dffff) AM_RAM_WRITE(pixram_w) AM_SHARE("pixram")
404404
405   AM_RANGE(0x2ff800, 0x2ff9ff) AM_RAM   AM_SHARE("scrollram_1")
406   AM_RANGE(0x2ffa00, 0x2ffbff) AM_RAM   AM_SHARE("scrollram_2")
407   AM_RANGE(0x2ffc00, 0x2ffdff) AM_RAM   AM_SHARE("scrollram_3")
405   AM_RANGE(0x2ff800, 0x2ff9ff) AM_RAM AM_SHARE("scrollram_1")
406   AM_RANGE(0x2ffa00, 0x2ffbff) AM_RAM AM_SHARE("scrollram_2")
407   AM_RANGE(0x2ffc00, 0x2ffdff) AM_RAM AM_SHARE("scrollram_3")
408408   AM_RANGE(0x2ffe00, 0x2fffff) AM_RAM
409409
410410   AM_RANGE(0x320000, 0x320003) AM_RAM AM_SHARE("layerctrl")
411411
412412   AM_RANGE(0x330000, 0x330001) AM_READWRITE(prot_r, prot_w)
413413
414   AM_RANGE(0x340000, 0x340001) AM_RAM   // 340001.b, rw
415   AM_RANGE(0x340002, 0x340003) AM_RAM   // 340003.b, w(9d)
414   AM_RANGE(0x340000, 0x340001) AM_RAM // 340001.b, rw
415   AM_RANGE(0x340002, 0x340003) AM_RAM // 340003.b, w(9d)
416416   AM_RANGE(0x340006, 0x340007) AM_WRITE(irq_ack_w)
417417   AM_RANGE(0x340008, 0x340009) AM_WRITE(irq_enable_w)
418   AM_RANGE(0x34000e, 0x34000f) AM_RAM AM_SHARE("priority")   // 34000f.b, w (priority?)
418   AM_RANGE(0x34000e, 0x34000f) AM_RAM AM_SHARE("priority")    // 34000f.b, w (priority?)
419419   AM_RANGE(0x340016, 0x340017) AM_WRITE(pixpal_w)
420   AM_RANGE(0x340018, 0x340019) AM_RAM   // 340019.b, w
421   AM_RANGE(0x34001a, 0x34001b) AM_READ(unk_r)   AM_WRITENOP
422   AM_RANGE(0x34001c, 0x34001d) AM_RAM   // 34001d.b, w(0)
420   AM_RANGE(0x340018, 0x340019) AM_RAM // 340019.b, w
421   AM_RANGE(0x34001a, 0x34001b) AM_READ(unk_r) AM_WRITENOP
422   AM_RANGE(0x34001c, 0x34001d) AM_RAM // 34001d.b, w(0)
423423
424424   AM_RANGE(0x350000, 0x350001) AM_DEVWRITE8("ramdac",ramdac_device, index_w, 0x00ff )
425425   AM_RANGE(0x350002, 0x350003) AM_DEVWRITE8("ramdac",ramdac_device, pal_w,   0x00ff )
r32760r32761
453453   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_GAMBLE_DEAL   ) PORT_CONDITION("DSW4",0x80,EQUALS,0x80) // n.a.            [START, ESC in service mode]
454454   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_GAMBLE_TAKE   ) PORT_CONDITION("DSW4",0x80,EQUALS,0x80) // SCORE
455455   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_POKER_BET     ) PORT_CONDITION("DSW4",0x80,EQUALS,0x80) // BET             [BET, credit -1]
456   PORT_BIT( 0x0200, IP_ACTIVE_HIGH,IPT_SPECIAL       ) PORT_CUSTOM_MEMBER(DEVICE_SELF, bmcpokr_state,hopper_r, NULL)   // HP [HOPPER, credit -100]
456   PORT_BIT( 0x0200, IP_ACTIVE_HIGH,IPT_SPECIAL       ) PORT_CUSTOM_MEMBER(DEVICE_SELF, bmcpokr_state,hopper_r, NULL)  // HP [HOPPER, credit -100]
457457   PORT_SERVICE_NO_TOGGLE( 0x0400, IP_ACTIVE_LOW      ) PORT_CONDITION("DSW4",0x80,EQUALS,0x80) // ACCOUNT         [SERVICE MODE]
458458   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_GAMBLE_KEYOUT ) PORT_CONDITION("DSW4",0x80,EQUALS,0x80) // KEY-OUT         [KEY-OUT, no hopper]
459459   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_GAMBLE_D_UP   ) PORT_CONDITION("DSW4",0x80,EQUALS,0x80) // DOUBLE-UP
r32760r32761
471471   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_GAMBLE_DEAL   )                PORT_CONDITION("DSW4",0x80,EQUALS,0x00) // n.a.            [START, ESC in service mode]
472472   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) PORT_CONDITION("DSW4",0x80,EQUALS,0x00) // <Left>2 (3rd)
473473   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_POKER_BET     )                PORT_CONDITION("DSW4",0x80,EQUALS,0x00) // <Down>1 (2nd)   [BET, credit -1]
474//   PORT_BIT( 0x0200, IP_ACTIVE_HIGH,IPT_SPECIAL       ) PORT_CUSTOM_MEMBER(DEVICE_SELF, bmcpokr_state,hopper_r, NULL)   // HP [HOPPER, credit -100]
474//  PORT_BIT( 0x0200, IP_ACTIVE_HIGH,IPT_SPECIAL       ) PORT_CUSTOM_MEMBER(DEVICE_SELF, bmcpokr_state,hopper_r, NULL)  // HP [HOPPER, credit -100]
475475   PORT_SERVICE_NO_TOGGLE( 0x0400, IP_ACTIVE_LOW      )                PORT_CONDITION("DSW4",0x80,EQUALS,0x00) // A2              [SERVICE MODE]
476476   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_GAMBLE_KEYOUT )                PORT_CONDITION("DSW4",0x80,EQUALS,0x00) // C2              [KEY-OUT, no hopper]
477477   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_GAMBLE_D_UP   )                PORT_CONDITION("DSW4",0x80,EQUALS,0x00) // S1              [START, ESC in service mode]
r32760r32761
480480   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_COIN1         )                PORT_CONDITION("DSW4",0x80,EQUALS,0x00) PORT_IMPULSE(5) // <coin-in> (1st) [COIN-IN, credit +100, coin-jam]
481481
482482   PORT_START("INPUTS2")
483   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_GAMBLE_PAYOUT ) // <coin-out> (2nd)   [COIN-OUT, hopper (otherwise pay-error)]
483   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_GAMBLE_PAYOUT ) // <coin-out> (2nd)    [COIN-OUT, hopper (otherwise pay-error)]
484484
485485   PORT_START("DSW1")
486486   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("DIP1:1")
r32760r32761
602602ADDRESS_MAP_END
603603
604604static MACHINE_CONFIG_START( bmcpokr, bmcpokr_state )
605   MCFG_CPU_ADD("maincpu", M68000, XTAL_42MHz / 4)   // 68000 @10.50MHz (42/4)
605   MCFG_CPU_ADD("maincpu", M68000, XTAL_42MHz / 4) // 68000 @10.50MHz (42/4)
606606   MCFG_CPU_PROGRAM_MAP(bmcpokr_mem)
607607   MCFG_TIMER_DRIVER_ADD_SCANLINE("scantimer", bmcpokr_state, interrupt, "screen", 0, 1)
608608
609609   MCFG_SCREEN_ADD("screen", RASTER)
610   MCFG_SCREEN_REFRESH_RATE(58.935)   // HSync - 15.440kHz, VSync - 58.935Hz
610   MCFG_SCREEN_REFRESH_RATE(58.935)    // HSync - 15.440kHz, VSync - 58.935Hz
611611
612612   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
613613   MCFG_SCREEN_UPDATE_DRIVER(bmcpokr_state, screen_update_bmcpokr)
r32760r32761
621621
622622   MCFG_NVRAM_ADD_0FILL("nvram")
623623
624   MCFG_TICKET_DISPENSER_ADD("hopper", attotime::from_msec(10), TICKET_MOTOR_ACTIVE_HIGH, TICKET_STATUS_ACTIVE_LOW)   // hopper stuck low if too slow
624   MCFG_TICKET_DISPENSER_ADD("hopper", attotime::from_msec(10), TICKET_MOTOR_ACTIVE_HIGH, TICKET_STATUS_ACTIVE_LOW)    // hopper stuck low if too slow
625625
626626   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
627627
628   MCFG_SOUND_ADD("ymsnd", YM2413, XTAL_42MHz / 12)   // UM3567 @3.50MHz (42/12)
628   MCFG_SOUND_ADD("ymsnd", YM2413, XTAL_42MHz / 12)    // UM3567 @3.50MHz (42/12)
629629   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.50)
630630   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.50)
631631
632   MCFG_OKIM6295_ADD("oki", XTAL_42MHz / 40, OKIM6295_PIN7_HIGH)   // M6295 @1.05MHz (42/40), pin 7 not verified
632   MCFG_OKIM6295_ADD("oki", XTAL_42MHz / 40, OKIM6295_PIN7_HIGH)   // M6295 @1.05MHz (42/40), pin 7 not verified
633633   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.50)
634634   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.50)
635635MACHINE_CONFIG_END
trunk/src/mame/drivers/jclub2.c
r32760r32761
114114      m_gamecpu(*this, "gamecpu"),
115115      m_eeprom(*this, "eeprom"),
116116      m_palette(*this, "palette"),
117       m_gfxdecode(*this, "gfxdecode")
117      m_gfxdecode(*this, "gfxdecode")
118118   { }
119119
120120   tilemap_t *m_tmap;
trunk/src/mame/drivers/ltd.c
r32760r32761
387387TIMER_DEVICE_CALLBACK_MEMBER( ltd_state::timer_r )
388388{
389389   m_timer_r ^= 1;
390   m_maincpu->set_input_line(M6800_IRQ_LINE, (m_timer_r) ? CLEAR_LINE : ASSERT_LINE);   
390   m_maincpu->set_input_line(M6800_IRQ_LINE, (m_timer_r) ? CLEAR_LINE : ASSERT_LINE);
391391   static const UINT8 patterns[16] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7c, 0x07, 0x7f, 0x67, 0x58, 0x4c, 0x62, 0x69, 0x78, 0 }; // 7447
392392   m_out_offs++;
393393   if (m_out_offs > 0x7f) m_out_offs = 0x60;
trunk/src/mame/drivers/segas32.c
r32760r32761
25032503    requires 2 linked system32 pcbs
25042504    requires additional math DSP to be emulated
25052505
2506   The link PCB attaches 2 System 32 mainboards together, then ROM boards for each mainboard attaches to the link PCB.
2507   This provides a direct connection between the PCBs (NOT a network link) so they effectively operate as a single boardset
2508   sharing RAM (we should emulate it as such)
2506    The link PCB attaches 2 System 32 mainboards together, then ROM boards for each mainboard attaches to the link PCB.
2507    This provides a direct connection between the PCBs (NOT a network link) so they effectively operate as a single boardset
2508    sharing RAM (we should emulate it as such)
25092509
2510   Link PCB is a single sparsely populated romless PCB but contains
2511   
2512   Left side
2513   1x MB8431-12LP (IC2)
2514   2x HD74LS74AP (IC6, IC7)
2515   2x GAL16V8A-25LP (stamped 315-5545) (IC3)
2510    Link PCB is a single sparsely populated romless PCB but contains
25162511
2517   Right side
2518   1x MB8421-12LP (IC1)
2519   1x GAL16V8A-25LP (stamped xxx-xxxx) (IC5)
2520   1x HD74LS74AP (IC8)
2521   1x GAL16V8A-25LP (stamped 315-5545) (IC4)
2512    Left side
2513    1x MB8431-12LP (IC2)
2514    2x HD74LS74AP (IC6, IC7)
2515    2x GAL16V8A-25LP (stamped 315-5545) (IC3)
25222516
2523   (todo, full layout)
2517    Right side
2518    1x MB8421-12LP (IC1)
2519    1x GAL16V8A-25LP (stamped xxx-xxxx) (IC5)
2520    1x HD74LS74AP (IC8)
2521    1x GAL16V8A-25LP (stamped 315-5545) (IC4)
25242522
2525   The left Rom PCB (master?) contains a sub-board on the ROM board with the math DSP, the right Rom PCB does not have this.
2523    (todo, full layout)
25262524
2525    The left Rom PCB (master?) contains a sub-board on the ROM board with the math DSP, the right Rom PCB does not have this.
2526
25272527*/
25282528ROM_START( arescue )
25292529   ROM_REGION( 0x200000, "maincpu", 0 ) /* v60 code + data */
trunk/src/mame/drivers/stv.c
r32760r32761
12511251{
12521252   UINT8 *ROM;
12531253   UINT32 size = slot->common_get_size("rom");
1254   
1254
12551255   if (image.software_entry() == NULL)
12561256      return IMAGE_INIT_FAIL;
1257   
1257
12581258   slot->rom_alloc(size, GENERIC_ROM32_WIDTH, ENDIANNESS_BIG);
12591259   ROM = slot->get_rom_base();
12601260   memcpy(ROM, image.get_software_region("rom"), size);
1261   
1261
12621262   /* fix endianess */
12631263   {
12641264      UINT8 j[4];
1265     
1265
12661266      for (int i = 0; i < size; i += 4)
12671267      {
12681268         j[0] = ROM[i + 0];
r32760r32761
12751275         ROM[i + 3] = j[0];
12761276      }
12771277   }
1278   
1278
12791279   return IMAGE_INIT_PASS;
12801280}
12811281
trunk/src/mame/drivers/vectrex.c
r32760r32761
1919
2020
2121static ADDRESS_MAP_START(vectrex_map, AS_PROGRAM, 8, vectrex_state )
22   AM_RANGE(0x0000, 0x7fff) AM_NOP   // cart area, handled at machine_start
22   AM_RANGE(0x0000, 0x7fff) AM_NOP // cart area, handled at machine_start
2323   AM_RANGE(0xc800, 0xcbff) AM_RAM AM_MIRROR(0x0400) AM_SHARE("gce_vectorram")
2424   AM_RANGE(0xd000, 0xd7ff) AM_READWRITE(vectrex_via_r, vectrex_via_w)
2525   AM_RANGE(0xe000, 0xffff) AM_ROM AM_REGION("maincpu", 0)
trunk/src/mame/drivers/fuukifg2.c
r32760r32761
238238INPUT_PORTS_END
239239
240240
241static INPUT_PORTS_START( gogomileo )   /* The ealier version has different coinage settings. */
241static INPUT_PORTS_START( gogomileo )   /* The ealier version has different coinage settings. */
242242   PORT_INCLUDE( gogomile )
243243
244244   PORT_MODIFY("DSW")      // $880000.w
trunk/src/mame/drivers/tickee.c
r32760r32761
5353   optional_device<okim6295_device> m_oki;
5454   required_device<screen_device> m_screen;
5555   required_device<tlc34076_device> m_tlc34076;
56   
56
5757   required_shared_ptr<UINT16> m_vram;
5858   optional_shared_ptr<UINT16> m_control;
59   
59
6060   emu_timer *m_setup_gun_timer;
6161   int m_beamxadd;
6262   int m_beamyadd;
6363   int m_palette_bank;
6464   UINT8 m_gunx[2];
6565   void get_crosshair_xy(int player, int &x, int &y);
66   
66
6767   DECLARE_WRITE16_MEMBER(rapidfir_transparent_w);
6868   DECLARE_READ16_MEMBER(rapidfir_transparent_r);
6969   DECLARE_WRITE16_MEMBER(tickee_control_w);
r32760r32761
8080   TIMER_CALLBACK_MEMBER(trigger_gun_interrupt);
8181   TIMER_CALLBACK_MEMBER(clear_gun_interrupt);
8282   TIMER_CALLBACK_MEMBER(setup_gun_interrupts);
83   
83
8484   TMS340X0_TO_SHIFTREG_CB_MEMBER(rapidfir_to_shiftreg);
8585   TMS340X0_FROM_SHIFTREG_CB_MEMBER(rapidfir_from_shiftreg);
8686   TMS340X0_SCANLINE_RGB32_CB_MEMBER(scanline_update);
r32760r32761
746746   MCFG_CPU_PROGRAM_MAP(tickee_map)
747747   MCFG_TMS340X0_HALT_ON_RESET(FALSE) /* halt on reset */
748748   MCFG_TMS340X0_PIXEL_CLOCK(VIDEO_CLOCK/2) /* pixel clock */
749   MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */   
749   MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */
750750   MCFG_TMS340X0_SCANLINE_RGB32_CB(tickee_state, scanline_update) /* scanline callback (rgb32) */
751751
752752   MCFG_MACHINE_RESET_OVERRIDE(tickee_state,tickee)
r32760r32761
791791
792792   /* basic machine hardware */
793793   MCFG_CPU_ADD("maincpu", TMS34010, XTAL_50MHz)
794   MCFG_CPU_PROGRAM_MAP(rapidfir_map)         
794   MCFG_CPU_PROGRAM_MAP(rapidfir_map)
795795   MCFG_TMS340X0_HALT_ON_RESET(FALSE) /* halt on reset */
796796   MCFG_TMS340X0_PIXEL_CLOCK(VIDEO_CLOCK/2) /* pixel clock */
797   MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */   
797   MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */
798798   MCFG_TMS340X0_SCANLINE_RGB32_CB(tickee_state, rapidfir_scanline_update)       /* scanline callback (rgb32) */
799799   MCFG_TMS340X0_TO_SHIFTREG_CB(tickee_state, rapidfir_to_shiftreg)           /* write to shiftreg function */
800800   MCFG_TMS340X0_FROM_SHIFTREG_CB(tickee_state, rapidfir_from_shiftreg)          /* read from shiftreg function */
r32760r32761
826826   MCFG_CPU_PROGRAM_MAP(mouseatk_map)
827827   MCFG_TMS340X0_HALT_ON_RESET(FALSE) /* halt on reset */
828828   MCFG_TMS340X0_PIXEL_CLOCK(VIDEO_CLOCK/2) /* pixel clock */
829   MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */   
829   MCFG_TMS340X0_PIXELS_PER_CLOCK(1) /* pixels per clock */
830830   MCFG_TMS340X0_SCANLINE_RGB32_CB(tickee_state, scanline_update) /* scanline callback (rgb32) */
831831
832832   MCFG_MACHINE_RESET_OVERRIDE(tickee_state,tickee)
trunk/src/mame/drivers/chqflag.c
r32760r32761
178178   AM_RANGE(0x8000, 0x87ff) AM_RAM /* RAM */
179179   AM_RANGE(0x9000, 0x9000) AM_WRITE(k007232_bankswitch_w) /* 007232 bankswitch */
180180   AM_RANGE(0xa000, 0xa00d) AM_DEVREADWRITE("k007232_1", k007232_device, read, write)  /* 007232 (chip 1) */
181   AM_RANGE(0xa01c, 0xa01c) AM_WRITE(k007232_extvolume_w)   /* extra volume, goes to the 007232 w/ A4 */
181   AM_RANGE(0xa01c, 0xa01c) AM_WRITE(k007232_extvolume_w)  /* extra volume, goes to the 007232 w/ A4 */
182182                                             /* selecting a different latch for the external port */
183183   AM_RANGE(0xb000, 0xb00d) AM_DEVREADWRITE("k007232_2", k007232_device, read, write)  /* 007232 (chip 2) */
184184   AM_RANGE(0xc000, 0xc001) AM_DEVREADWRITE("ymsnd", ym2151_device, read, write)   /* YM2151 */
trunk/src/mame/drivers/midyunit.c
r32760r32761
10731073   MCFG_CPU_PROGRAM_MAP(main_map)
10741074   MCFG_TMS340X0_HALT_ON_RESET(FALSE) /* halt on reset */
10751075   MCFG_TMS340X0_PIXEL_CLOCK(MEDRES_PIXEL_CLOCK) /* pixel clock */
1076   MCFG_TMS340X0_PIXELS_PER_CLOCK(2) /* pixels per clock */   
1076   MCFG_TMS340X0_PIXELS_PER_CLOCK(2) /* pixels per clock */
10771077   MCFG_TMS340X0_SCANLINE_IND16_CB(midyunit_state, scanline_update)       /* scanline updater (indexed16) */
10781078   MCFG_TMS340X0_TO_SHIFTREG_CB(midyunit_state, to_shiftreg)           /* write to shiftreg function */
10791079   MCFG_TMS340X0_FROM_SHIFTREG_CB(midyunit_state, from_shiftreg)          /* read from shiftreg function */
r32760r32761
11151115   MCFG_CPU_PROGRAM_MAP(main_map)
11161116   MCFG_TMS340X0_HALT_ON_RESET(FALSE) /* halt on reset */
11171117   MCFG_TMS340X0_PIXEL_CLOCK(STDRES_PIXEL_CLOCK) /* pixel clock */
1118   MCFG_TMS340X0_PIXELS_PER_CLOCK(2) /* pixels per clock */   
1118   MCFG_TMS340X0_PIXELS_PER_CLOCK(2) /* pixels per clock */
11191119   MCFG_TMS340X0_SCANLINE_IND16_CB(midyunit_state, scanline_update)       /* scanline updater (indexed16) */
11201120   MCFG_TMS340X0_TO_SHIFTREG_CB(midyunit_state, to_shiftreg)           /* write to shiftreg function */
11211121   MCFG_TMS340X0_FROM_SHIFTREG_CB(midyunit_state, from_shiftreg)          /* read from shiftreg function */
trunk/src/mame/drivers/segas18.c
r32760r32761
908908
909909static INPUT_PORTS_START( ddcrew3p )
910910   PORT_INCLUDE( ddcrew2p )
911   
911
912912   PORT_MODIFY("PORTC")
913913   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(3)
914914   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(3)
trunk/src/mame/drivers/rainbow.c
r32760r32761
841841
842842   ROM_REGION( 0x200, "pals", 0 )
843843   ROM_LOAD( "jumping-pal16r6.bin",             0x000, 0x104, CRC(12e9a7b8) SHA1(a0ce8b6083c9adfcb4bdbca87f63a01f292525f3) )
844   ROM_LOAD( "jumping-pal20l8.bin",             0x000, 0x144, CRC(76944f81) SHA1(ab78e4e157ffdc13aea5dc360268b2640e60d19c) )   
844   ROM_LOAD( "jumping-pal20l8.bin",             0x000, 0x144, CRC(76944f81) SHA1(ab78e4e157ffdc13aea5dc360268b2640e60d19c) )
845845ROM_END
846846
847847ROM_START( jumpinga )
r32760r32761
887887
888888   ROM_REGION( 0x200, "pals", 0 )
889889   ROM_LOAD( "jumping-pal16r6.bin",             0x000, 0x104, CRC(12e9a7b8) SHA1(a0ce8b6083c9adfcb4bdbca87f63a01f292525f3) )
890   ROM_LOAD( "jumping-pal20l8.bin",             0x000, 0x144, CRC(76944f81) SHA1(ab78e4e157ffdc13aea5dc360268b2640e60d19c) )   
890   ROM_LOAD( "jumping-pal20l8.bin",             0x000, 0x144, CRC(76944f81) SHA1(ab78e4e157ffdc13aea5dc360268b2640e60d19c) )
891891ROM_END
892892
893893
trunk/src/mame/drivers/srmp5.c
r32760r32761
6666public:
6767   srmp5_state(const machine_config &mconfig, device_type type, const char *tag)
6868      : driver_device(mconfig, type, tag),
69       m_gfxdecode(*this, "gfxdecode"),
70       m_palette(*this, "palette"),
69         m_gfxdecode(*this, "gfxdecode"),
70         m_palette(*this, "palette"),
7171      m_maincpu(*this,"maincpu"),
72       m_subcpu(*this, "sub")
73   
72         m_subcpu(*this, "sub")
73
7474   { }
7575
7676   UINT32 m_databank;
trunk/src/mame/drivers/dragrace.c
r32760r32761
8484   m_discrete->write(space, DRAGRACE_ATTRACT_EN, (m_misc_flags & 0x00001000) ? 1: 0); // Attract enable
8585   m_discrete->write(space, DRAGRACE_LOTONE_EN, (m_misc_flags & 0x00002000) ? 1: 0);  // LoTone enable
8686   m_discrete->write(space, DRAGRACE_HITONE_EN, (m_misc_flags & 0x20000000) ? 1: 0);  // HiTone enable
87   
87
8888   // the tachometers are driven from the same frequency generator that creates the engine sound
8989   output_set_value("tachometer", ~m_misc_flags & 0x0000001f);
9090   output_set_value("tachometer2", (~m_misc_flags & 0x001f0000) >> 0x10);
trunk/src/mame/drivers/coolpool.c
r32760r32761
833833   MCFG_TMS340X0_SCANLINE_RGB32_CB(coolpool_state, coolpool_scanline) /* scanline callback (rgb32) */
834834   MCFG_TMS340X0_TO_SHIFTREG_CB(coolpool_state, to_shiftreg)  /* write to shiftreg function */
835835   MCFG_TMS340X0_FROM_SHIFTREG_CB(coolpool_state, from_shiftreg) /* read from shiftreg function */
836   
836
837837   MCFG_CPU_ADD("dsp", TMS32026,XTAL_40MHz)
838838   MCFG_CPU_PROGRAM_MAP(coolpool_dsp_pgm_map)
839839   MCFG_CPU_IO_MAP(coolpool_dsp_io_map)
trunk/src/mame/drivers/midtunit.c
r32760r32761
587587   MCFG_CPU_PROGRAM_MAP(main_map)
588588   MCFG_TMS340X0_HALT_ON_RESET(FALSE) /* halt on reset */
589589   MCFG_TMS340X0_PIXEL_CLOCK(PIXEL_CLOCK) /* pixel clock */
590   MCFG_TMS340X0_PIXELS_PER_CLOCK(2) /* pixels per clock */   
590   MCFG_TMS340X0_PIXELS_PER_CLOCK(2) /* pixels per clock */
591591   MCFG_TMS340X0_SCANLINE_IND16_CB(midtunit_state, scanline_update)       /* scanline updater (indexed16) */
592592   MCFG_TMS340X0_TO_SHIFTREG_CB(midtunit_state, to_shiftreg)           /* write to shiftreg function */
593593   MCFG_TMS340X0_FROM_SHIFTREG_CB(midtunit_state, from_shiftreg)          /* read from shiftreg function */
trunk/src/mame/drivers/twinkle.c
r32760r32761
66
77TODO:
88
9dvd check for bmiidx, bmiidxa, bmiidxc & bmiidxca
9dvd check for bmiidx, bmiidxa, bmiidxc & bmiidxca
1010finish sound board emulation and remove response hle
1111emulate dvd player and video mixing
121216seg led font
r32760r32761
10381038
10391039   MCFG_DEVICE_ADD("rs232", RS232_PORT, 0)
10401040   MCFG_SLOT_OPTION_ADD("xvd701", JVC_XVD701)
1041//   MCFG_SLOT_OPTION_ADD("xvs1100", JVC_XVS1100) // 8th mix only
1041//  MCFG_SLOT_OPTION_ADD("xvs1100", JVC_XVS1100) // 8th mix only
10421042   MCFG_SLOT_DEFAULT_OPTION("xvd701")
10431043   MCFG_RS232_RXD_HANDLER(DEVWRITELINE("fdc37c665gt:uart2", ins8250_uart_device, rx_w))
10441044   MCFG_RS232_DCD_HANDLER(DEVWRITELINE("fdc37c665gt:uart2", ins8250_uart_device, dcd_w))
trunk/src/mame/drivers/calchase.c
r32760r32761
44
55California Chase (c) 1999 The Game Room
66Host Invaders (c) 1998 The Game Room
7
7
88driver by Angelo Salese & Grull Osgo
99
1010TODO:
r32760r32761
5050connectors for COM1, COM2, LPT1, IDE0, IDE1, floppy etc
5151uses standard AT PSU
5252
53Video card is Trident TGUI9680 with 512k on-board VRAM
53Video card is Trident TGUI9680 with 512k on-board VRAM
5454Card is branded "Union UTD73" - these are all over eBay, for instance
5555RAM is AS4C256K16EO-50JC (x2)
5656Trident BIOS V5.5 (DIP28). Actual size unknown, dumped as 64k, 128k, 256k and 512k (can only be one of these sizes)
r32760r32761
7878The HDD is DOS-readable and in fact the OS is just Windows 98 DOS and can
7979be easily copied. Tested with another HDD.... formatted with DOS, copied
8080all files across to new HDD, boots up fine.
81 
82 
83Host Invaders is the same motherboard and video card as above, but instead of an HDD,
84there is a CD-ROM drive.
85 
81
82
83Host Invaders is the same motherboard and video card as above, but instead of an HDD,
84there is a CD-ROM drive.
85
8686************************************************************************************/
8787/*
8888Grull Osgo - Improvements
r32760r32761
744744
745745ROM_START( hostinv )
746746   ROM_REGION( 0x40000, "bios", 0 )
747   ROM_LOAD( "hostinv_bios.bin", 0x000000, 0x020000, CRC(5111e4b8) SHA1(20ab93150b61fd068f269368450734bba5dcb284) )
747   ROM_LOAD( "hostinv_bios.bin", 0x000000, 0x020000, CRC(5111e4b8) SHA1(20ab93150b61fd068f269368450734bba5dcb284) )
748748
749749   ROM_REGION( 0x8000, "video_bios", 0 )
750750   ROM_LOAD16_BYTE( "trident_tgui9680_bios.bin", 0x0000, 0x4000, CRC(1eebde64) SHA1(67896a854d43a575037613b3506aea6dae5d6a19) )
r32760r32761
759759
760760ROM_START( eggsplc )
761761   ROM_REGION( 0x40000, "bios", 0 )
762   ROM_LOAD( "hostinv_bios.bin", 0x000000, 0x020000, CRC(5111e4b8) SHA1(20ab93150b61fd068f269368450734bba5dcb284) )
762   ROM_LOAD( "hostinv_bios.bin", 0x000000, 0x020000, CRC(5111e4b8) SHA1(20ab93150b61fd068f269368450734bba5dcb284) )
763763
764764   ROM_REGION( 0x8000, "video_bios", 0 )
765765   ROM_LOAD16_BYTE( "trident_tgui9680_bios.bin", 0x0000, 0x4000, CRC(1eebde64) SHA1(67896a854d43a575037613b3506aea6dae5d6a19) )
r32760r32761
775775GAME( 1998, hostinv,   0,    hostinv,  calchase, calchase_state,  hostinv,  ROT0, "The Game Room", "Host Invaders", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
776776GAME( 1999, calchase,  0,    calchase, calchase, calchase_state,  calchase, ROT0, "The Game Room", "California Chase", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
777777GAME( 2002, eggsplc,   0,    calchase, calchase, calchase_state,  hostinv,  ROT0, "The Game Room", "Eggs Playing Chicken", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
778
trunk/src/mame/drivers/bfm_sc2.c
r32760r32761
185185         m_vfd0(*this, "vfd0"),
186186         m_vfd1(*this, "vfd1"),
187187         m_dm01(*this, "dm01") { }
188   
188
189189   required_device<cpu_device> m_maincpu;
190190   required_device<upd7759_device> m_upd7759;
191191   optional_device<bfm_bd1_t> m_vfd0;
r32760r32761
13891389void bfm_sc2_state::save_state()
13901390{
13911391   /* TODO: Split between the different machine types */
1392   
1392
13931393   save_item(NAME(m_key));
13941394   save_item(NAME(m_mmtr_latch));
13951395   save_item(NAME(m_irq_status));
r32760r32761
21472147   nvram_device *e2ram = subdevice<nvram_device>("e2ram");
21482148   if (e2ram != NULL)
21492149      e2ram->set_base(m_e2ram, sizeof(m_e2ram));
2150   
2150
21512151   save_state();
21522152}
21532153
trunk/src/mame/drivers/galpanic.c
r32760r32761
11231123
11241124GAME( 1994, supmodel, 0,        supmodel, fantasia,  driver_device, 0, ROT90, "Comad & New Japan System", "Super Model",GAME_NO_COCKTAIL )
11251125
1126GAME( 1994, fantasian,fantasia, comad,    fantasia,  driver_device, 0, ROT90, "Comad & New Japan System", "Fantasia (940803 PCB)", GAME_NO_COCKTAIL )
1126GAME( 1994, fantasian,fantasia, comad,    fantasia,  driver_device, 0, ROT90, "Comad & New Japan System", "Fantasia (940803 PCB)", GAME_NO_COCKTAIL )
11271127
11281128GAME( 1995, newfant,  0,        comad,    fantasia,  driver_device, 0, ROT90, "Comad & New Japan System", "New Fantasia (1995 copyright)", GAME_NO_COCKTAIL ) // the only difference between the two is the gfx rom containing the copyright
11291129GAME( 1994, newfanta, newfant,  comad,    fantasia,  driver_device, 0, ROT90, "Comad & New Japan System", "New Fantasia (1994 copyright)", GAME_NO_COCKTAIL )
trunk/src/mame/drivers/mazerbla.c
r32760r32761
14111411
14121412   save_item(NAME(m_vsb_ls273));
14131413   save_item(NAME(m_soundlatch));
1414   
1414
14151415   machine().save().register_postload(save_prepost_delegate(FUNC(mazerbla_state::rom_bank_select), this));
14161416}
14171417
trunk/src/mame/mame.lst
r32760r32761
4848pacmanf         // hack
4949puckmod         // (c) 1981 Namco
5050pacmod          // (c) 1981 Midway
51pacmanjpm      // bootleg
51pacmanjpm       // bootleg
5252newpuc2         // hack
5353newpuc2b        // hack
5454pacuman         // bootleg
r32760r32761
103103mspacmanbg      // bootleg
104104mspacmanbgd     // bootleg
105105mspacmanbcc     // bootleg
106mspacmanblt      // bootleg
106mspacmanblt     // bootleg
107107woodpeck        // (c) 1981 Amenip (Palcom Queen River)
108108woodpeca        // (c) 1981 Amenip Nova Games Ltd.
109109mspacmab        // bootleg
r32760r32761
136136cannonbp        // hack
137137superabc        // hack
138138superabco       // hack
139pengojpm      // bootleg
140pengopac      // bootleg
139pengojpm        // bootleg
140pengopac        // bootleg
141141
142142// S2650 Pacman Kits
143143drivfrcp        // (c) 1984 Shinkai Inc. (Magic Eletronics Inc. license)
r32760r32761
333333froggers        // bootleg
334334frogf           // bootleg
335335quaak           // bootleg
336froggeram      // bootleg
336froggeram       // bootleg
337337amidars         // GX337 (c) 1982 Konami
338338triplep         // (c) 1982 KKI / made by Sanritsu?
339339triplepa        // (c) 1982 KKI / made by Sanritsu?
r32760r32761
471471itaten          // (c) 1984 + Alice
472472friskyt         // (c) 1981
473473friskyta        // (c) 1981
474friskytb      // (c) 1981
474friskytb        // (c) 1981
475475radrad          // (c) 1982 Nichibutsu USA
476476seicross        // (c) 1984 + Alice
477477sectrzon        // (c) 1984 + Alice
r32760r32761
693693phoenixt        // (c) 1980 Taito
694694phoenixj        // (c) 1980 Taito
695695phoenix3        // bootleg
696phoenixdal   // bootleg D&L (No copyright/title)
696phoenixdal  // bootleg D&L (No copyright/title)
697697phoenixc        // bootleg
698698phoenixc2       // bootleg
699699phoenixc3       // bootleg
r32760r32761
810810gaplus          // (c) 1984
811811gaplusa         // (c) 1984
812812gaplusd         // (c) 1984
813gaplust       // (c) 1984
813gaplust         // (c) 1984
814814galaga3         // (c) 1984
815815galaga3a        // (c) 1984
816816galaga3b        // (c) 1984
r32760r32761
876876quester         // (c) 1987 (Japan)
877877questers        // (c) 1987 (Japan)
878878pacmania        // (c) 1987
879pacmaniao      // (c) 1987
879pacmaniao       // (c) 1987
880880pacmaniaj       // (c) 1987 (Japan)
881881galaga88        // (c) 1987
882882galaga88a       // (c) 1987
r32760r32761
11661166cheekyms        // 8004 (c) [1980?]
11671167zerohour        // 8011 (c) Universal
11681168zerohoura       // 8011 (c) Universal
1169zerohouri      //
1169zerohouri       //
11701170redclash        // (c) 1981 Tehkan
11711171redclasha       // (c) 1981 Tehkan
11721172redclashk       // (c) Kaneko (bootleg?)
r32760r32761
12441244marioo          // (c) 1983 Nintendo of America
12451245marioj          // (c) 1983 Nintendo
12461246masao           // bootleg
1247mariobl         // bootleg
1248dkong3abl      //
1247mariobl         // bootleg
1248dkong3abl       //
12491249pestplce        // bootleg on donkey kong hw
12501250spclforc        // (c) 1985 Senko Industries (Magic Eletronics Inc. license)
12511251spcfrcii        // (c) 1985 Senko Industries (Magic Eletronics Inc. license)
r32760r32761
17651765mototour        // (c) 1983 Tecfri
17661766shtrider        // (c) 1984 Seibu Kaihatsu
17671767shtridera       // (c) 1984 Seibu Kaihatsu
1768shtriderb      // bootleg
1768shtriderb       // bootleg
17691769wilytowr        // M63 (c) 1984
17701770atomboy         // M63 (c) 1985 Irem + Memetron license
17711771atomboya        // M63 (c) 1985 Irem + Memetron license
r32760r32761
21332133arkatour        // ??? (c) 1987 Taito America Corporation + Romstar license (US)
21342134tetrsark        // ??? (c) D.R.Korea
21352135hexa            // D. R. Korea
2136hexaa         //
2136hexaa           //
21372137brixian         // (c) 1993 Cheil Computer System
21382138sqix            // B03 1987
21392139sqixr1          // B03 1987
r32760r32761
267826783in1semi        // (c) 1998 SemiCom
26792679moremore        // (c) 1999 SemiCom + Exit
26802680moremorp        // (c) 1999 SemiCom + Exit
2681suhosong      // (c) 199? SemiCom
2681suhosong        // (c) 199? SemiCom
268226824in1boot        // (c) 2002 KISoft (includes hacks of Semicom games + Snowbros)
26832683
26842684// More Toaplan Games
r32760r32761
30393039tigeroadb       // bootleg
30403040f1dream         //  4/1988 (c) 1988 + Romstar
30413041f1dreamb        // bootleg
3042f1dreamba      // bootleg
3042f1dreamba       // bootleg
304330431943kai         //  6/1988 (c) 1987 (Japan)
30443044lastduel        //  7/1988 (c) 1988 (US)
30453045lastduelo       //  7/1988 (c) 1988 (US)
r32760r32761
33643364sfzb            // 09/11/1995 (c) 1995 (Brazil)
33653365sfzbr1          // 27/07/1995 (c) 1995 (Brazil)
33663366mmancp2u        // 06/10/1995 (c) 1995 (USA)
3367mmancp2ur1      // 26/09/1995 (c) 1995 (USA)
3367mmancp2ur1      // 26/09/1995 (c) 1995 (USA)
33683368rmancp2j        // 22/09/1995 (c) 1995 (Japan)
33693369msh             // 24/10/1995 (c) 1995 (Euro)
33703370mshu            // 24/10/1995 (c) 1995 (USA)
r32760r32761
46874687astormbl        // BOOTLEG
46884688astormb2        // BOOTLEG
46894689shdancbl        // BOOTLEG
4690shdancbla      // BOOTLEG
4690shdancbla       // BOOTLEG
46914691mwalkbl         // BOOTLEG
46924692
46934693
r32760r32761
48124812spidmanu        // 1991.09 Spiderman (US)
48134813spidmanj    // 1991.09 Spiderman (Japan)
48144814f1en            // 1991.?? F-1 Exhaust Note (World)
4815f1enu         // 1992.01 F-1 Exhaust Note (US)
4815f1enu           // 1992.01 F-1 Exhaust Note (US)
48164816            // 1991.11 F-1 Exhaust Note (Japan)
48174817arabfgt         // 1992.?? Arabian Fight (World)
48184818arabfgtu        // 1992.03 Arabian Fight (US)
r32760r32761
54235423mushik2e        // 2005.?? Mushiking The King Of Beetles II ENG (Ver. 1.001)
54245424mushi2ea        // 2005.?? Mushiking The King Of Beetles II ENG (Ver. 2.001)
54255425            // 2005.?? MushiKing The King Of Beetle III
5426mushi2k5      // 2005.?? MushiKing The King Of Beetle 2K5 1st
5426mushi2k5        // 2005.?? MushiKing The King Of Beetle 2K5 1st
54275427kurucham        // 2006.03 Kurukuru Chameleon
54285428trgheart        // 2006.05 Trigger Heart Exelica (Rev A)
54295429zunou           // 2006.07 Touch de Zunou
r32760r32761
54825482kingrt66        // 2002.02 The King of Route 66 (Rev A)
54835483            // 2002.02.14 Initial D Arcade Stage (Japan)
54845484initd           // 2002.03 Initial D Arcade Stage (Japan) (Rev B)
5485initdo         // 2002.03 Initial D Arcade Stage (Japan)
5485initdo          // 2002.03 Initial D Arcade Stage (Japan)
54865486            // 2002.06 World Club Champion Football Serie A 2001-2002
54875487soulsurf        // 2002.07 Soul Surfer
54885488initdexp        // 2002.07.18 Initial D Arcade Stage (Export) (Rev A)
r32760r32761
58935893chelnov         // (c) 1988 Data East USA (World)
58945894chelnovu        // (c) 1988 Data East USA (US)
58955895chelnovj        // (c) 1988 Data East Corporation (Japan)
5896chelnovjbl      // bootleg
5897chelnovjbla      // bootleg
5896chelnovjbl      // bootleg
5897chelnovjbla     // bootleg
58985898// the following ones all run on similar hardware
58995899hbarrel         // (c) 1987 Data East USA (US)
59005900hbarrelw        // (c) 1987 Data East Corporation (World)
r32760r32761
63566356simpsons4pa     // GX072 (c) 1991
63576357simpsons2p      // GX072 (c) 1991
63586358simpsons2p2     // GX072 (c) 1991
6359simpsons2p3      // GX072 (c) 1991
6359simpsons2p3     // GX072 (c) 1991
63606360simpsons2pa     // GX072 (c) 1991 (Asia)
63616361simpsons2pj     // GX072 (c) 1991 (Japan)
63626362esckids         // GX975 (c) 1991 (Asia)
r32760r32761
63646364vendetta        // GX081 (c) 1991 (World)
63656365vendettar       // GX081 (c) 1991 (World)
63666366vendetta2p      // GX081 (c) 1991 (World)
6367vendetta2peba   // GX081 (c) 1991 (World)
6367vendetta2peba   // GX081 (c) 1991 (World)
63686368vendetta2pu     // GX081 (c) 1991 (Asia)
63696369vendetta2pd     // GX081 (c) 1991 (Asia)
63706370vendettaj       // GX081 (c) 1991 (Japan)
r32760r32761
79367936tdragon         // (c) 1991 NMK / Tecmo
79377937tdragon1        // (c) 1991 NMK / Tecmo
79387938hachamf         // (c) 1991 NMK
7939hachamfb      // bootleg
7939hachamfb        // bootleg
79407940macross         // (c) 1992 Banpresto
79417941riot            // (c) 1992 NMK
79427942gunnail         // (c) 1993 NMK / Tecmo
r32760r32761
83458345goodejana       // (c) 1991 Seibu/Tecmo
83468346
83478347raiden2         // (c) 1993 Seibu Kaihatsu + Fabtek license
8348raiden2u      // (c) 1993 Seibu Kaihatsu + Fabtek license
8348raiden2u        // (c) 1993 Seibu Kaihatsu + Fabtek license
83498349raiden2hk       // (c) 1993 Seibu Kaihatsu + Metrotainment license
83508350raiden2j        // (c) 1993 Seibu Kaihatsu
83518351raiden2i        // (c) 1993 Seibu Kaihatsu
r32760r32761
83548354raiden2eu       // (c) 1993 Seibu Kaihatsu + Fabtek license
83558355raiden2eua      // (c) 1993 Seibu Kaihatsu + Fabtek license
83568356raiden2nl       // (c) 1993 Seibu Kaihatsu
8357raiden2g      // (c) 1993 Seibu Kaihatsu + Tuning license
8358raiden2dx      // (c) 1993 Seibu Kaihatsu
8357raiden2g        // (c) 1993 Seibu Kaihatsu + Tuning license
8358raiden2dx       // (c) 1993 Seibu Kaihatsu
83598359
83608360raidendx        // (c) 1994 Seibu Kaihatsu
83618361raidendxk       // (c) 1994 Seibu Kaihatsu
r32760r32761
83778377
83788378// Newer V33 PCB with COP3 protection
83798379r2dx_v33        // (c) 1996 Seibu Kaihatsu
8380r2dx_v33_r2      // (c) 1996 Seibu Kaihatsu
8380r2dx_v33_r2     // (c) 1996 Seibu Kaihatsu
83818381nzeroteam       // (c) 1997 Seibu Kaihatsu
83828382zerotm2k        // (c) 2000 Seibu Kaihatsu
83838383
r32760r32761
86878687tengaij         // (c) 1996
86888688// Semicom games on "Psikyo 68020"-like hardware
86898689baryon          // (c) 1997 SemiCom
8690baryona         // (c) 1997 SemiCom
8690baryona         // (c) 1997 SemiCom
86918691dreamwld        // (c) 2000 SemiCom
86928692rolcrush        // (c) 1999 Trust
86938693
r32760r32761
90619061nratechu        // (c) 1996 Seta
90629062dcrown          // 199? unknown
90639063dcrowna         // 199? unknown
9064gostop         // 2001 Visco
9064gostop          // 2001 Visco
90659065// R3000 + ST-0016
90669066srmp5           // (c) 199? Seta
90679067speglsht        // (c) 1994 Seta
r32760r32761
92239223fantasiaa       // (c) 1994 Comad & New Japan System
92249224fantasiab       // (c) 1994 Comad & New Japan System
92259225supmodel        // (c) 1994 Comad & New Japan System
9226fantasian      //
9226fantasian       //
92279227newfant         // (c) 1994 Comad & New Japan System
92289228newfanta        // (c) 1995 Comad & New Japan System
92299229fantsy95        // (c) 1995 Hi-max Technology Inc.
r32760r32761
97089708orlegendc       //
97099709orlegendca      //
97109710orlegend111c    //
9711orlegend111t   //
9711orlegend111t    //
97129712orlegend105k    //
97139713drgw2           // (c) 1997 Dragon World 2
97149714dw2v100x        //
r32760r32761
1031210312eggventr2       // (c) 1997 The Game Room
1031310313eggventra       // (c) 1997 The Game Room (Allied Leisure license)
1031410314eggventrd       // (c) 1997 The Game Room
10315hostinv         // (c) 1998 The Game Room
10315hostinv         // (c) 1998 The Game Room
1031610316calchase        // (c) 1999 The Game Room
10317eggsplc         // (c) 2002 The Game Room
10317eggsplc         // (c) 2002 The Game Room
1031810318ripribit        // (c) 1997 LAI Games
1031910319cfarm           // (c) 1999 LAI Games
1032010320cclownz         // (c) 1999 LAI Games
trunk/src/mame/audio/mario.c
r32760r32761
414414
415415void mario_state::sound_start()
416416{
417
418417   device_t *audiocpu = machine().device("audiocpu");
419418
420419   if (!audiocpu) return;
trunk/src/mame/audio/cclimber.h
r32760r32761
4141   DECLARE_WRITE8_MEMBER( sample_rate_w );
4242   DECLARE_WRITE8_MEMBER( sample_volume_w );
4343   DECLARE_WRITE8_MEMBER( sample_select_w );
44   
44
4545   SAMPLES_START_CB_MEMBER( sh_start );
4646
4747protected:
r32760r32761
5050   virtual machine_config_constructor device_mconfig_additions() const;
5151
5252   void play_sample(int start,int freq,int volume);
53   
53
5454private:
5555   INT16 *m_sample_buf;    /* buffer to decode samples at run time */
5656   int m_sample_num;
trunk/src/mame/audio/leland.c
r32760r32761
257257   save_item(NAME(m_ext_active));
258258   save_item(NAME(m_dac_sample));
259259   save_item(NAME(m_dac_volume));
260   
260
261261   // zerofill
262262   m_peripheral = 0;
263263   m_last_control = 0;
r32760r32761
566566         if (ACCESSING_BITS_0_7)
567567            dac_w(space, 1, data, mem_mask);
568568         return;
569     
569
570570      default:
571571         break;
572572   }
r32760r32761
599599            m_ext_stop <<= 4;
600600            if (LOG_EXTERN) logerror("External DAC stop = %05X\n", m_ext_stop);
601601            return;
602         
602
603603         default:
604604            break;
605605      }
trunk/src/mame/machine/st0016.c
r32760r32761
99
1010static ADDRESS_MAP_START(st0016_cpu_internal_map, AS_PROGRAM, 8, st0016_cpu_device)
1111   AM_RANGE(0xc000, 0xcfff) AM_READ(st0016_sprite_ram_r) AM_WRITE(st0016_sprite_ram_w)
12   AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w)   
12   AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w)
1313   AM_RANGE(0xea00, 0xebff) AM_READ(st0016_palette_ram_r) AM_WRITE(st0016_palette_ram_w)
1414   AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
1515   AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE("stsnd", st0016_device, st0016_snd_r, st0016_snd_w) /* sound regs 8 x $20 bytes, see notes */
r32760r32761
2929
3030st0016_cpu_device::st0016_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
3131   : z80_device(mconfig, ST0016_CPU, "ST0016", tag, owner, clock, "st0016_cpu", __FILE__),
32     st0016_game(-1),
33     st0016_spr_bank(0),
34     st0016_spr2_bank(0),
35     st0016_pal_bank(0),
36     st0016_char_bank(0),
37     spr_dx(0),
38     spr_dy(0),
39     st0016_ramgfx(0),
40   
41     m_io_space_config("io", ENDIANNESS_LITTLE, 8, 16, 0, ADDRESS_MAP_NAME(st0016_cpu_internal_io_map)),
42     m_space_config("regs", ENDIANNESS_LITTLE, 8, 16, 0, ADDRESS_MAP_NAME(st0016_cpu_internal_map)),
32      st0016_game(-1),
33      st0016_spr_bank(0),
34      st0016_spr2_bank(0),
35      st0016_pal_bank(0),
36      st0016_char_bank(0),
37      spr_dx(0),
38      spr_dy(0),
39      st0016_ramgfx(0),
4340
41      m_io_space_config("io", ENDIANNESS_LITTLE, 8, 16, 0, ADDRESS_MAP_NAME(st0016_cpu_internal_io_map)),
42      m_space_config("regs", ENDIANNESS_LITTLE, 8, 16, 0, ADDRESS_MAP_NAME(st0016_cpu_internal_map)),
4443
45     m_screen(*this, ":screen"),
46     m_gfxdecode(*this, "gfxdecode"),
47     m_palette(*this, "palette")
4844
45      m_screen(*this, ":screen"),
46      m_gfxdecode(*this, "gfxdecode"),
47      m_palette(*this, "palette")
48
4949{
5050   for (int i = 0; i < 0xc0; i++)
5151      st0016_vregs[i] = 0;
r32760r32761
302302      UINT32 srcadr=(st0016_vregs[0xa0]|(st0016_vregs[0xa1]<<8)|(st0016_vregs[0xa2]<<16))<<1;
303303      UINT32 dstadr=(st0016_vregs[0xa3]|(st0016_vregs[0xa4]<<8)|(st0016_vregs[0xa5]<<16))<<1;
304304      UINT32 length=((st0016_vregs[0xa6]|(st0016_vregs[0xa7]<<8)|((st0016_vregs[0xa8]&0x1f)<<16))+1)<<1;
305     
305
306306      // todo : dma callback so macs_cart_slot can be local to MACs driver?
307307
308308      UINT32 srclen = (memregion(":maincpu")->bytes());
r32760r32761
354354   o - sublist offset (*8 to get real offset)
355355   f - end of list  flag
356356   x,y - sprite coords
357   
357
358358   (complete guess)
359359   g - use tile sizes specified in list (global / fixed ones if not set?) (gostop)
360360   X = global X size?
r32760r32761
455455            sx += x;
456456            sy += y;
457457            color = st0016_spriteram[offset + 2] & 0x3f;
458           
458
459459            if (use_sizes)
460460            {
461461               lx = (st0016_spriteram[offset + 5] >> 2) & 3;
r32760r32761
469469            }
470470
471471            /*
472               if(plx |ply) //parent
473               {
474               lx=plx;
475               ly=ply;
476               }
477               */
472                if(plx |ply) //parent
473                {
474                lx=plx;
475                ly=ply;
476                }
477                */
478478
479479            flipx = st0016_spriteram[offset + 3] & 0x80;
480480            flipy = st0016_spriteram[offset + 3] & 0x40;
r32760r32761
737737   st0016_draw_screen(screen, bitmap, cliprect);
738738   return 0;
739739}
740
trunk/src/mame/machine/st0016.h
r32760r32761
5353   DECLARE_WRITE8_MEMBER(st0016_vregs_w);
5454   DECLARE_READ8_MEMBER(soundram_read);
5555
56   
56
5757   void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect);
5858   void st0016_save_init();
5959   void draw_bgmap(bitmap_ind16 &bitmap,const rectangle &cliprect, int priority);
trunk/src/mame/machine/atari.c
r32760r32761
167167   case pokey_device::POK_KEY_SHIFT:
168168      // button 2 from joypads
169169      ipt = m_djoy_b->read() & (0x10 << ((k543210 >> 3) & 0x03));
170      ret |= !ipt ? 0x02 : 0;
170      ret |= !ipt ? 0x02 : 0;
171171      break;
172172   }
173173
trunk/src/mame/machine/inder_vid.c
r32760r32761
9090   MCFG_CPU_PROGRAM_MAP(megaphx_tms_map)
9191   MCFG_TMS340X0_HALT_ON_RESET(TRUE) /* halt on reset */
9292   MCFG_TMS340X0_PIXEL_CLOCK(XTAL_40MHz/12) /* pixel clock */
93   MCFG_TMS340X0_PIXELS_PER_CLOCK(2) /* pixels per clock */   
93   MCFG_TMS340X0_PIXELS_PER_CLOCK(2) /* pixels per clock */
9494   MCFG_TMS340X0_SCANLINE_RGB32_CB(inder_vid_device, scanline)     /* scanline updater (RGB32) */
9595   MCFG_TMS340X0_OUTPUT_INT_CB(WRITELINE(inder_vid_device, m68k_gen_int))
9696   MCFG_TMS340X0_TO_SHIFTREG_CB(inder_vid_device, to_shiftreg)  /* write to shiftreg function */
trunk/src/mame/machine/inder_vid.h
r32760r32761
2929   required_shared_ptr<UINT16> m_vram;
3030   required_device<palette_device> m_palette;
3131   required_device<tms34010_device> m_tms;
32   
32
3333   DECLARE_WRITE_LINE_MEMBER(m68k_gen_int);
3434
3535   int m_shiftfull; // this might be a driver specific hack for a TMS bug.
r32760r32761
4141   virtual machine_config_constructor device_mconfig_additions() const;
4242   virtual void device_start();
4343   virtual void device_reset();
44   
44
4545private:
4646};
4747
trunk/src/mame/machine/315_5296.c
r32760r32761
11/**********************************************************************
22
33    Sega 315-5296 I/O chip
4   
4
55    Sega 100-pin QFP, with 8 bidirectional I/O ports, and 3 output pins.
66    It also has chip select(/FMCS) and clock(CKOT) for a peripheral device.
77    Commonly used from the late 80s up until Sega Model 2.
r32760r32761
6868   m_in_pf_cb.resolve_safe(0xff); m_in_port_cb[5] = &m_in_pf_cb;
6969   m_in_pg_cb.resolve_safe(0xff); m_in_port_cb[6] = &m_in_pg_cb;
7070   m_in_ph_cb.resolve_safe(0xff); m_in_port_cb[7] = &m_in_ph_cb;
71   
71
7272   m_out_pa_cb.resolve_safe(); m_out_port_cb[0] = &m_out_pa_cb;
7373   m_out_pb_cb.resolve_safe(); m_out_port_cb[1] = &m_out_pb_cb;
7474   m_out_pc_cb.resolve_safe(); m_out_port_cb[2] = &m_out_pc_cb;
r32760r32761
7777   m_out_pf_cb.resolve_safe(); m_out_port_cb[5] = &m_out_pf_cb;
7878   m_out_pg_cb.resolve_safe(); m_out_port_cb[6] = &m_out_pg_cb;
7979   m_out_ph_cb.resolve_safe(); m_out_port_cb[7] = &m_out_ph_cb;
80   
80
8181   m_out_cnt0_cb.resolve_safe(); m_out_cnt_cb[0] = &m_out_cnt0_cb;
8282   m_out_cnt1_cb.resolve_safe(); m_out_cnt_cb[1] = &m_out_cnt1_cb;
8383   m_out_cnt2_cb.resolve_safe(); m_out_cnt_cb[2] = &m_out_cnt2_cb;
84   
84
8585   // register for savestates
8686   save_item(NAME(m_output_latch));
8787   save_item(NAME(m_cnt));
r32760r32761
9696{
9797   // all ports are set to input
9898   m_dir = 0;
99   
99
100100   // clear output ports
101101   memset(m_output_latch, 0, sizeof(m_output_latch));
102102   m_cnt = 0;
r32760r32761
113113READ8_MEMBER( sega_315_5296_device::read )
114114{
115115   offset &= 0x3f;
116   
116
117117   switch (offset)
118118   {
119119      // port A to H
r32760r32761
121121         // if the port is configured as an output, return the last thing written
122122         if (m_dir & 1 << offset)
123123            return m_output_latch[offset];
124         
124
125125         // otherwise, return an input port
126126         return (*m_in_port_cb[offset])(offset);
127     
127
128128      // 'SEGA' protection
129129      case 0x8:
130130         return 'S';
r32760r32761
142142      // port direction register & mirror
143143      case 0xd: case 0xf:
144144         return m_dir;
145     
145
146146      default:
147147         break;
148148   }
149   
149
150150   return 0xff;
151151}
152152
r32760r32761
165165
166166         m_output_latch[offset] = data;
167167         break;
168     
168
169169      // CNT register
170170      case 0xe:
171171         // d0-2: CNT0-2 output pins
r32760r32761
173173         // no effect on the output level of CNT2.
174174         for (int i = 0; i < 3; i++)
175175            (*m_out_cnt_cb[i])(data >> i & 1);
176         
176
177177         // d3: CNT2 output mode (1= Clock output, 0= Programmable output)
178178         // d4,5: CNT2 clock divider (0= CLK/4, 1= CLK/8, 2= CLK/16, 3= CLK/2)
179179         // d6,7: CKOT clock divider (0= CLK/4, 1= CLK/8, 2= CLK/16, 3= CLK/2)
r32760r32761
189189            if ((m_dir ^ data) & (1 << i))
190190               (*m_out_port_cb[i])((offs_t)i, (data & 1 << i) ? m_output_latch[i] : 0);
191191         }
192         
192
193193         m_dir = data;
194194         break;
195     
195
196196      default:
197197         break;
198198   }
trunk/src/mame/machine/seicop.c
r32760r32761
33  OLD Seibu Cop simulation code.
44
55  this is currently only used by the Seibu Cup Soccer BOOTLEG
6
6
77*/
88
99/********************************************************************************************
r32760r32761
2525   m_cop_mcu_ram(NULL),
2626   m_raiden2cop(*this, ":raiden2cop")
2727{
28
29
3028}
3129
3230#define seibu_cop_log logerror
r32760r32761
10199         break;
102100      }
103101
104     
102
105103      case (0x500/2):
106104      case (0x502/2):
107105      case (0x504/2):
r32760r32761
152150
153151               space.write_dword(m_raiden2cop->cop_regs[0] + 4 + offs, npos);
154152               space.write_word(m_raiden2cop->cop_regs[0] + 0x1c + offs, space.read_word(m_raiden2cop->cop_regs[0] + 0x1c + offs) + delta);
155           
153
156154               break;
157155            }
158156            case 0x130e:
r32760r32761
199197               break;
200198         }
201199         break;
202     
200
203201      /*TODO: kludge on x-axis.*/
204202      case (0x660/2): { state->m_scrollram16[0] = m_cop_mcu_ram[offset] - 0x1f0; break; }
205203      case (0x662/2): { state->m_scrollram16[1] = m_cop_mcu_ram[offset]; break; }
r32760r32761
218216      }
219217   }
220218}
221
222
trunk/src/mame/machine/seicop.h
r32760r32761
3030
3131#define MCFG_SEIBU_COP_ADD(_tag) \
3232   MCFG_DEVICE_ADD(_tag, SEIBU_COP_BOOTLEG, 0)
33
trunk/src/mame/machine/nmk004.c
r32760r32761
2525{
2626   // bit 0x08 toggles frequently but is connected to nothing?
2727
28  // bit 0x01 is set to reset the 68k
28   // bit 0x01 is set to reset the 68k
2929   m_systemcpu->set_input_line(INPUT_LINE_RESET, (data & 1) ? ASSERT_LINE : CLEAR_LINE);
3030}
3131
trunk/src/mame/machine/asic65.c
r32760r32761
251251   }
252252
253253   int command = (m_command < MAX_COMMANDS) ? command_map[m_asic65_type][m_command] : OP_UNKNOWN;
254   
254
255255   /* update results */
256256   switch (command)
257257   {
trunk/src/mame/machine/vectrex.c
r32760r32761
328328         m_maincpu->space(AS_PROGRAM).install_read_handler(0x0000, 0x7fff, read8_delegate(FUNC(vectrex_cart_slot_device::read_rom),(vectrex_cart_slot_device*)m_cart));
329329
330330      // setup 3d imager and refresh timer
331     
331
332332      // If VIA T2 starts, reset refresh timer. This is the best strategy for most games.
333333      m_reset_refresh = 1;
334334      m_imager_angles = narrow_escape_angles;
335     
335
336336      // let's do this 3D detection
337337      switch (m_cart->get_vec3d())
338338      {
trunk/src/mame/machine/kaneko_toybox.h
r32760r32761
353353   UINT16 m_mcu_com[4];
354354   int m_gametype;
355355   int m_tabletype;
356   
356
357357   void mcu_com_w(offs_t offset, UINT16 data, UINT16 mem_mask, int _n_);
358358   void decrypt_rom();
359359   void handle_04_subcommand(UINT8 mcu_subcmd, UINT16 *mcu_ram);
r32760r32761
366366
367367#define MCFG_TOYBOX_TABLE_TYPE(_type) \
368368   kaneko_toybox_device::set_table(*device, _type);
369   
369
370370#define MCFG_TOYBOX_GAME_TYPE(_type) \
371371   kaneko_toybox_device::set_game_type(*device, _type);
trunk/src/mame/machine/awboard.h
r32760r32761
2222   DECLARE_WRITE16_MEMBER(mpr_first_file_index_w); // 5f7010
2323   DECLARE_WRITE16_MEMBER(mpr_file_offsetl_w);     // 5f7014
2424   DECLARE_WRITE16_MEMBER(mpr_file_offseth_w);     // 5f7018
25   DECLARE_READ16_MEMBER(adj_offset_r);         // 5f7080
26   DECLARE_WRITE16_MEMBER(adj_offset_w);         // 5f7080
25   DECLARE_READ16_MEMBER(adj_offset_r);            // 5f7080
26   DECLARE_WRITE16_MEMBER(adj_offset_w);           // 5f7080
2727
2828protected:
2929   virtual void device_start();
trunk/src/mame/machine/model1.c
r32760r32761
15841584   { &model1_state::fsub,            2 },
15851585   { &model1_state::fmul,            2 },
15861586   { &model1_state::fdiv,            2 },
1587   { NULL,                          0 },
1587   { NULL,                           0 },
15881588   { &model1_state::matrix_push,     0 },
15891589   { &model1_state::matrix_pop,      0 },
15901590   { &model1_state::matrix_write,   12 },
15911591   { &model1_state::clear_stack,     0 },
1592   { NULL,                         0 },
1592   { NULL,                           0 },
15931593   { &model1_state::anglev,          2 },
1594   { NULL,                         0 },
1595   { NULL,                         0 },
1594   { NULL,                           0 },
1595   { NULL,                           0 },
15961596   { &model1_state::track_select,    1 },
15971597   { &model1_state::f14,             4 },
15981598   { &model1_state::anglep,          4 },
r32760r32761
16041604   { &model1_state::matrix_rotx,     1 },
16051605   { &model1_state::matrix_roty,     1 },
16061606   { &model1_state::matrix_rotz,     1 },
1607   { NULL,                         0 },
1607   { NULL,                           0 },
16081608   { &model1_state::track_read_quad, 1 },
1609   { NULL,                         0 },
1609   { NULL,                           0 },
16101610   { &model1_state::transform_point, 3 },
16111611   { &model1_state::fsin_m1,         1 },
16121612   { &model1_state::fcos_m1,         1 },
r32760r32761
16141614   { &model1_state::fcosm_m1,        2 },
16151615   { &model1_state::distance3,       6 },
16161616
1617   { NULL,                         0 },  /* 0x20 */
1618   { NULL,                         0 },
1619   { NULL,                         0 },
1620   { NULL,                         0 },
1617   { NULL,                           0 },  /* 0x20 */
1618   { NULL,                           0 },
1619   { NULL,                           0 },
1620   { NULL,                           0 },
16211621   { &model1_state::acc_set,         1 },
16221622   { &model1_state::acc_get,         0 },
16231623   { &model1_state::acc_add,         1 },
r32760r32761
16291629   { &model1_state::f44,             1 },
16301630   { &model1_state::f45,             1 },
16311631   { &model1_state::vlength,         3 },
1632   { NULL,                     0 },
1632   { NULL,                           0 },
16331633
16341634   { &model1_state::track_read_info, 1 },  /* 0x30 */
16351635   { &model1_state::colbox_set,     12 },
16361636   { &model1_state::colbox_test,     3 },
1637   { NULL,                         0 },
1638   { NULL,                         0 },
1639   { NULL,                         0 },
1637   { NULL,                           0 },
1638   { NULL,                           0 },
1639   { NULL,                           0 },
16401640   { &model1_state::track_lookup,    4 },
1641   { NULL,                         0 },
1642   { NULL,                         0 },
1643   { NULL,                         0 },
1644   { NULL,                         0 },
1645   { NULL,                         0 },
1646   { NULL,                         0 },
1647   { NULL,                         0 },
1648   { NULL,                         0 },
1649   { NULL,                         0 },
1641   { NULL,                           0 },
1642   { NULL,                           0 },
1643   { NULL,                           0 },
1644   { NULL,                           0 },
1645   { NULL,                           0 },
1646   { NULL,                           0 },
1647   { NULL,                           0 },
1648   { NULL,                           0 },
1649   { NULL,                           0 },
16501650
16511651   { &model1_state::col_setcirc,     3 },  /* 0x40 */
16521652   { &model1_state::col_testpt,      2 },
1653   { NULL,                         0 },
1653   { NULL,                           0 },
16541654   { &model1_state::distance,        4 },
1655   { NULL,                         0 },
1656   { NULL,                         0 },
1657   { NULL,                         0 },
1655   { NULL,                           0 },
1656   { NULL,                           0 },
1657   { NULL,                           0 },
16581658   { &model1_state::car_move,        4 },
16591659   { &model1_state::cpa,            12 },
1660   { NULL,                         0 },
1660   { NULL,                           0 },
16611661   { &model1_state::vmat_store,      1 },
16621662   { &model1_state::vmat_restore,    1 },
1663   { NULL,                         0 },
1663   { NULL,                           0 },
16641664   { &model1_state::vmat_mul,        2 },
16651665   { &model1_state::vmat_read,       1 },
16661666   { &model1_state::matrix_unrot,    0 },
16671667
16681668   { &model1_state::f80,             0 },  /* 0x50 */
1669   { NULL,                         0 },
1669   { NULL,                           0 },
16701670   { &model1_state::matrix_rtrans,   0 },
1671   { NULL,                         0 },
1671   { NULL,                           0 },
16721672   { &model1_state::vmat_save,       1 },
16731673   { &model1_state::vmat_load,       1 },
16741674   { &model1_state::ram_setadr,      1 },
16751675   { &model1_state::groundbox_test,  3 },
1676   { NULL,                             0 },
1676   { NULL,                           0 },
16771677   { &model1_state::f89,             4 },
1678   { NULL,                         0 },
1679   { NULL,                         0 },
1678   { NULL,                           0 },
1679   { NULL,                           0 },
16801680   { &model1_state::f92,             4 },
16811681   { &model1_state::f93,             1 },
16821682   { &model1_state::f94,             1 },
r32760r32761
17021702   { &model1_state::fsub,            2 },
17031703   { &model1_state::fmul,            2 },
17041704   { &model1_state::fdiv,            2 },
1705   { NULL,                       0 },
1705   { NULL,                           0 },
17061706   { &model1_state::matrix_push,     0 },
17071707   { &model1_state::matrix_pop,      0 },
17081708   { &model1_state::matrix_write,   12 },
r32760r32761
17221722   { &model1_state::matrix_rotx,     1 },
17231723   { &model1_state::matrix_roty,     1 },
17241724   { &model1_state::matrix_rotz,     1 },
1725   { NULL,                        0 },
1725   { NULL,                           0 },
17261726   { &model1_state::f24_swa,         7 },
1727   { NULL,                          0 },
1727   { NULL,                           0 },
17281728   { &model1_state::transform_point, 3 },
17291729   { &model1_state::fsin_m1,         1 },
17301730   { &model1_state::fcos_m1,         1 },
r32760r32761
17321732   { &model1_state::fcosm_m1,        2 },
17331733   { &model1_state::distance3,       6 },
17341734
1735   { NULL,                          0 }, /* 0x20 */
1736   { NULL,                        0 },
1735   { NULL,                           0 }, /* 0x20 */
1736   { NULL,                           0 },
17371737   { &model1_state::ftoi,            1 },
17381738   { &model1_state::itof,            1 },
17391739   { &model1_state::acc_set,         1 },
r32760r32761
17491749   { &model1_state::vlength,         3 },
17501750   { &model1_state::f47,             3 },
17511751
1752   { NULL,                          0 }, /* 0x30 */
1752   { NULL,                           0 }, /* 0x30 */
17531753   { &model1_state::f49_swa,         6 },
17541754   { &model1_state::f50_swa,         4 },
1755   { NULL,                           0 },
1755   { NULL,                           0 },
17561756   { &model1_state::f52,             0 },
17571757   { &model1_state::matrix_rdir,     3 },
1758   { NULL,                          0 },
1759   { NULL,                          0 },
1758   { NULL,                           0 },
1759   { NULL,                           0 },
17601760   { &model1_state::f56,             7 },
17611761   { &model1_state::f57,             0 },
17621762   { &model1_state::matrix_readt,    0 },
17631763   { &model1_state::acc_geti,        0 },
17641764   { &model1_state::f60,             0 },
1765   { NULL,                          0 },
1766   { NULL,                          0 },
1767   { NULL,                         0 },
1768   { NULL,                         0 },
1765   { NULL,                           0 },
1766   { NULL,                           0 },
1767   { NULL,                           0 },
1768   { NULL,                           0 },
17691769
17701770   { &model1_state::push_and_ident,  0 }, /* 0x40 */
1771   { NULL,                         0 },
1771   { NULL,                           0 },
17721772   { &model1_state::catmull_rom,    13 }
17731773};
17741774
trunk/src/mame/machine/raiden2cop.c
r32760r32761
2727   cop_latch_addr(0),
2828   cop_latch_trigger(0),
2929   cop_latch_value(0),
30   cop_latch_mask(0),     
30   cop_latch_mask(0),
3131   cop_dma_v1(0),
3232   cop_dma_v2(0),
3333   cop_dma_mode(0),
r32760r32761
7878   memset(cop_func_value, 0, sizeof(UINT16)*(0x100/8));
7979   memset(cop_func_mask, 0, sizeof(UINT16)*(0x100/8));
8080   memset(cop_program, 0, sizeof(UINT16)*(0x100));
81   
81
8282   memset(cop_dma_src, 0, sizeof(UINT16)*(0x200));
8383   memset(cop_dma_dst, 0, sizeof(UINT16)*(0x200));
8484   memset(cop_dma_size, 0, sizeof(UINT16)*(0x200));
r32760r32761
362362   /* search the uploaded 'trigger' table for a matching trigger*/
363363   /* note, I don't know what the 'mask' or 'value' tables are... probably important, might determine what actually gets executed! */
364364   /* note: Zero Team triggers macro 0x904 instead of 0x905, Seibu Cup Soccer triggers 0xe30e instead of 0xe38e. I highly doubt that AT LEAST
365      it isn't supposed to do anything, especially in the former case (it definitely NEEDS that sprites have an arc movement when they are knocked down). */
365       it isn't supposed to do anything, especially in the former case (it definitely NEEDS that sprites have an arc movement when they are knocked down). */
366366   // we currently pass in mask 0xff00 to look at only match the top bits, but this is wrong, only specific bits are ignored (maybe depends on the 'mask' value uploaded with each trigger?)
367367   int matched = 0;
368368   int command = -1;
r32760r32761
374374      if ((triggerval & mask) == (cop_func_trigger[i] & mask) && cop_func_trigger[i] != 0) /* cop_func_trigger[i] != 0 is just being used to prevent matching against empty / unused slots */
375375      {
376376         int otherlog = 1;
377         
377
378378         // just some per-game debug code so that we have a record of exactly which triggers each game is known to use
379379
380380
r32760r32761
382382         {
383383            // enemies often walk on the spot, bosses often walk above / below playable game area (the >>16 in the sqrt commands seems responsible)
384384            // player doesn't walk off screen after end of level (walks on spot, different cause?)
385            if (triggerval == 0x0205 || triggerval == 0x0905 ||
385            if (triggerval == 0x0205 || triggerval == 0x0905 ||
386386               triggerval == 0x8100 || triggerval == 0x8900 || /* sin / cos */
387387               triggerval == 0x138e || // atan?
388388               triggerval == 0x3bb0 || // distance?
r32760r32761
413413
414414            if (triggerval == 0x0205 ||
415415               triggerval == 0x8100 || triggerval == 0x8900 || /* sin / cos */
416               triggerval == 0x138e ||
416               triggerval == 0x138e ||
417417               triggerval == 0x3bb0 ||
418418               triggerval == 0x42c2 ||
419419               triggerval == 0xa100 || triggerval == 0xa900 || triggerval == 0xb080 || triggerval == 0xb880) /* collisions */
r32760r32761
494494         {
495495            if (triggerval == 0x0205 || triggerval == 0x0905 ||
496496               triggerval == 0x8100 || triggerval == 0x8900 || /* sin / cos */
497               triggerval == 0x130e ||   triggerval == 0x138e ||
497               triggerval == 0x130e || triggerval == 0x138e ||
498498               triggerval == 0x2a05 ||
499               triggerval == 0x2208 ||   triggerval == 0x2288 ||   
499               triggerval == 0x2208 || triggerval == 0x2288 ||
500500               triggerval == 0x338e ||
501               triggerval == 0x39b0 || triggerval == 0x3bb0 ||   
502               triggerval == 0x4aa0 ||   
503               triggerval == 0x42c2 ||   
501               triggerval == 0x39b0 || triggerval == 0x3bb0 ||
502               triggerval == 0x4aa0 ||
503               triggerval == 0x42c2 ||
504504               triggerval == 0x5205 ||
505505               triggerval == 0x5a05 ||
506506               triggerval == 0x6200 ||
r32760r32761
508508               triggerval == 0xa100 || triggerval == 0xa900 || triggerval == 0xb100 || triggerval == 0xb900 /* collisions */
509509               )
510510               otherlog = 0;
511         }     
511         }
512512         else
513513         {
514514            otherlog = 0;
r32760r32761
525525
526526   if (matched == 1)
527527   {
528
529528      int j;
530529      seibu_cop_log("     Sequence: ");
531530      for (j=0;j<0x8;j++)
r32760r32761
554553   command *= 8;
555554
556555   if (cop_program[command+0] == seq0 && cop_program[command+1] == seq1 && cop_program[command+2] == seq2 && cop_program[command+3] == seq3 &&
557       cop_program[command+4] == seq4 && cop_program[command+5] == seq5 && cop_program[command+6] == seq6 && cop_program[command+7] == seq7 &&
558       cop_func_value[command/8] == _funcval_ &&
559       cop_func_mask[command/8] == _funcmask_)
556      cop_program[command+4] == seq4 && cop_program[command+5] == seq5 && cop_program[command+6] == seq6 && cop_program[command+7] == seq7 &&
557      cop_func_value[command/8] == _funcval_ &&
558      cop_func_mask[command/8] == _funcmask_)
560559      return 1;
561560   else
562561      return 0;
r32760r32761
877876
878877/* Number Conversion */
879878
880// according to score display in  https://www.youtube.com/watch?v=T1M8sxYgt9A
879// according to score display in  https://www.youtube.com/watch?v=T1M8sxYgt9A
881880// we should return 0x30 for unused digits? according to Raiden 2 and Zero
882881// Team the value should be 0x20, can this be configured?
883882// grainbow doesn't like this implementation at all (21 credits, 2 digit high scores etc.)
r32760r32761
890889
891890   if(digits > 9)
892891      digits = 9;
893   
892
894893   for (int i = 0; i < digits; i++)
895894   {
896895      if (!val && i)
r32760r32761
903902         val = val / 10;
904903      }
905904   }
906   
905
907906   cop_itoa_digits[9] = 0;
908907}
909908
r32760r32761
11061105
11071106/*
11081107## - trig (up5) (low11) :  (sq0, sq1, sq2, sq3, sq4, sq5, sq6, sq7)  valu  mask
110907 - 3bb0 ( 07) (  3b0) :  (f9c, b9c, b9c, b9c, b9c, b9c, b9c, 99c)  4     007f   (legionna, heatbrl, cupsoc, grainbow, godzilla, denjinmk, raiden2, raidendx,
110807 - 3bb0 ( 07) (  3b0) :  (f9c, b9c, b9c, b9c, b9c, b9c, b9c, 99c)  4     007f   (legionna, heatbrl, cupsoc, grainbow, godzilla, denjinmk, raiden2, raidendx,
1110110907 - 3b30 ( 07) (  330) :  (f9c, b9c, b9c, b9c, b9c, b9c, b9c, 99c)  4     007f   (zeroteam, xsedae)
11111110*/
11121111
r32760r32761
12621261      else
12631262         angle -= cop_angle_step;
12641263   }
1265   
1264
12661265   cop_write_word(space, cop_regs[primary_reg], flags);
12671266
12681267   if (!m_cpu_is_68k)
r32760r32761
13041303      else
13051304         angle -= cop_angle_step;
13061305   }
1307   
1306
13081307   cop_write_word(space, cop_regs[primary_reg], flags);
13091308
13101309   if (!m_cpu_is_68k)
r32760r32761
17161715   //printf("%02x %02x %02x %02x %02x %02x\n", (UINT8)size[i], (UINT8)dx[i], (UINT8)size[1], (UINT8)dx[1], (UINT8)size[2], (UINT8)dx[2]);
17171716
17181717   int j = slot;
1719   
1718
17201719   UINT8 res;
17211720
17221721   if (num_axis==3) res = 7;
r32760r32761
17911790   case 0x39b0:
17921791   case 0x3b30:
17931792   case 0x3bb0: { // 3bb0 0004 007f 0038 - 0f9c 0b9c 0b9c 0b9c 0b9c 0b9c 0b9c 099c
1794      execute_3b30(space, offset, data);
1793      execute_3b30(space, offset, data);
17951794
17961795      break;
17971796   }
r32760r32761
18291828   case 0x5a05:   // 5a05 0006 fff7 0058 - 0180 02e0 03a0 00a0 03a0 0000 0000 0000
18301829      //      fprintf(stderr, "sprcpt 5a05 %04x %04x %04x %08x %08x\n", cop_regs[0], cop_regs[1], cop_regs[3], space.read_dword(cop_regs[0]), space.read_dword(cop_regs[3]));
18311830      execute_5a05(space, offset, data);
1832   
1831
18331832      break;
18341833
18351834   case 0xf205:   // f205 0006 fff7 00f0 - 0182 02e0 03c0 00c0 03c0 0000 0000 0000
r32760r32761
20642063WRITE16_MEMBER(raiden2cop_device::LEGACY_cop_cmd_w)
20652064{
20662065   int command;
2067   
20682066
2067
20692068   seibu_cop_log("%06x: COPX execute table macro command %04x | regs %08x %08x %08x %08x %08x\n", space.device().safe_pc(), data,  cop_regs[0], cop_regs[1], cop_regs[2], cop_regs[3], cop_regs[4]);
20702069
20712070
r32760r32761
21172116
21182117   /* SINE math - 0x8100 */
21192118   /*
2120         00000-0ffff:
2121         amp = x/256
2122         ang = x & 255
2123         s = sin(ang*2*pi/256)
2124         val = trunc(s*amp)
2125         if(s<0)
2126         val--
2127         if(s == 192)
2128         val = -2*amp
2129         */
2119           00000-0ffff:
2120           amp = x/256
2121           ang = x & 255
2122           s = sin(ang*2*pi/256)
2123           val = trunc(s*amp)
2124           if(s<0)
2125           val--
2126           if(s == 192)
2127           val = -2*amp
2128           */
21302129   if (check_command_matches(command, 0xb9a, 0xb88, 0x888, 0x000, 0x000, 0x000, 0x000, 0x000, 7, 0xfdfb))
21312130   {
21322131      executed = 1;
r32760r32761
21362135
21372136   /* COSINE math - 0x8900 */
21382137   /*
2139      10000-1ffff:
2140      amp = x/256
2141      ang = x & 255
2142      s = cos(ang*2*pi/256)
2143      val = trunc(s*amp)
2144      if(s<0)
2145      val--
2146      if(s == 128)
2147      val = -2*amp
2148      */
2138       10000-1ffff:
2139       amp = x/256
2140       ang = x & 255
2141       s = cos(ang*2*pi/256)
2142       val = trunc(s*amp)
2143       if(s<0)
2144       val--
2145       if(s == 128)
2146       val = -2*amp
2147       */
21492148   if (check_command_matches(command, 0xb9a, 0xb8a, 0x88a, 0x000, 0x000, 0x000, 0x000, 0x000, 7, 0xfdfb))
21502149   {
21512150      executed = 1;
r32760r32761
21732172   /* Pythagorean theorem, hypotenuse length - 0x3bb0 */
21742173   //(grainbow) | 4 | 007f | 3bb0 | f9c b9c b9c b9c b9c b9c b9c 99c
21752174   /*
2176      40000-7ffff:
2177      v1 = (x / 32768)*64
2178      v2 = (x & 255)*32767/255
2179      val = sqrt(v1*v1+v2*v2) (unsigned)
2180      */
2175       40000-7ffff:
2176       v1 = (x / 32768)*64
2177       v2 = (x & 255)*32767/255
2178       val = sqrt(v1*v1+v2*v2) (unsigned)
2179       */
21812180   if (check_command_matches(command, 0xf9c, 0xb9c, 0xb9c, 0xb9c, 0xb9c, 0xb9c, 0xb9c, 0x99c, 4, 0x007f))
21822181   {
21832182      executed = 1;
r32760r32761
21872186
21882187   /* Division - 0x42c2 */
21892188   /*
2190      20000-2ffff:
2191      v1 = x / 1024
2192      v2 = x & 1023
2193      val = !v1 ? 32767 : trunc(v2/v1+0.5)
2194      30000-3ffff:
2195      v1 = x / 1024
2196      v2 = (x & 1023)*32
2197      val = !v1 ? 32767 : trunc(v2/v1+0.5)
2198      */
2189       20000-2ffff:
2190       v1 = x / 1024
2191       v2 = x & 1023
2192       val = !v1 ? 32767 : trunc(v2/v1+0.5)
2193       30000-3ffff:
2194       v1 = x / 1024
2195       v2 = (x & 1023)*32
2196       val = !v1 ? 32767 : trunc(v2/v1+0.5)
2197       */
21992198   if (check_command_matches(command, 0xf9a, 0xb9a, 0xb9c, 0xb9c, 0xb9c, 0x29c, 0x000, 0x000, 5, 0xfcdd))
22002199   {
22012200      executed = 1;
r32760r32761
22042203   }
22052204
22062205   /*
2207      collision detection:
2206       collision detection:
22082207
2209      int dy_0 = space.read_dword(cop_regs[0]+4);
2210      int dx_0 = space.read_dword(cop_regs[0]+8);
2211      int dy_1 = space.read_dword(cop_regs[1]+4);
2212      int dx_1 = space.read_dword(cop_regs[1]+8);
2213      int hitbox_param1 = space.read_dword(cop_regs[2]);
2214      int hitbox_param2 = space.read_dword(cop_regs[3]);
2208       int dy_0 = space.read_dword(cop_regs[0]+4);
2209       int dx_0 = space.read_dword(cop_regs[0]+8);
2210       int dy_1 = space.read_dword(cop_regs[1]+4);
2211       int dx_1 = space.read_dword(cop_regs[1]+8);
2212       int hitbox_param1 = space.read_dword(cop_regs[2]);
2213       int hitbox_param2 = space.read_dword(cop_regs[3]);
22152214
2216      TODO: we are ignoring the funcval / funcmask params for now
2217      */
2215       TODO: we are ignoring the funcval / funcmask params for now
2216       */
22182217
22192218   if (check_command_matches(command, 0xb80, 0xb82, 0xb84, 0xb86, 0x000, 0x000, 0x000, 0x000, funcval, funcmask))
22202219   {
r32760r32761
22872286   if (check_command_matches(command, 0x380, 0x39a, 0x380, 0xa80, 0x29a, 0x000, 0x000, 0x000, 8, 0xf3e7))
22882287   {
22892288      executed = 1;
2290      execute_6200(space, offset, data);   
2289      execute_6200(space, offset, data);
22912290      return;
22922291   }
22932292
r32760r32761
23112310   if (executed == 0)
23122311      printf("did not execute %04x\n", data); // cup soccer triggers this a lot (and others)
23132312}
2314
2315
2316
2317
trunk/src/mame/machine/raiden2cop.h
r32760r32761
8787   DECLARE_WRITE16_MEMBER( cop_itoa_high_w );
8888   DECLARE_WRITE16_MEMBER( cop_itoa_digit_count_w );
8989   DECLARE_READ16_MEMBER ( cop_itoa_digits_r );
90   
90
9191   UINT32 cop_itoa;
9292   UINT16 cop_itoa_digit_count;
9393   UINT8 cop_itoa_digits[10];
r32760r32761
122122
123123   UINT32 cop_regs[8];
124124   UINT16 cop_status, cop_scale, cop_angle, cop_dist;
125   
126125
126
127127   UINT16 cop_angle_target;
128128   UINT16 cop_angle_step;
129129
130130
131131   struct colinfo {
132
133132      colinfo()
134133      {
135134         pos[0] = pos[1] = pos[2] = 0;
r32760r32761
140139         spradr = 0;
141140         min[0] = min[1] = min[2] = 0;
142141         max[0] = max[1] = max[2] = 0;
143     
142
144143      }
145144
146145
trunk/src/mame/machine/amiga.c
r32760r32761
358358         m_pot1y += !(m_potgo_port->read() & 0x4000);
359359      }
360360   }
361   
361
362362   // render up to this scanline
363363   if (!m_screen->update_partial(scanline))
364364   {
trunk/src/mame/machine/konppc.c
r32760r32761
1818   : device_t(mconfig, KONPPC, "Konami PowerPC Common Functions", tag, owner, clock, "konppc", __FILE__),
1919   cgboard_type(0),
2020   num_cgboards(0)/*,
21   cgboard_id(MAX_CG_BOARDS)*/
21    cgboard_id(MAX_CG_BOARDS)*/
2222{
2323}
2424
trunk/src/mame/machine/kaneko_calc3.h
r32760r32761
1616
1717   void reset_run_timer();
1818   void mcu_run();
19   
19
2020protected:
2121   virtual void device_start();
2222   virtual void device_reset();
r32760r32761
4343   UINT16 m_poll_addr;
4444   UINT16 m_checksumaddress;
4545   emu_timer* m_runtimer;
46   
46
4747   enum
4848   {
4949      MCU_RUN_TIMER
5050   };
51   
51
5252   void mcu_init();
5353   void initial_scan_tables();
5454   void mcu_com_w(offs_t offset, UINT16 data, UINT16 mem_mask, int _n_);

Previous 199869 Revisions Next


© 1997-2024 The MAME Team