Previous 15994 Revisions Next

r12048 Saturday 25th June, 2011 at 08:07:58 UTC by Miodrag Milanović
Sync with MAME (r12962) (no whatsnew)
[ROOT]makefile
[src/emu]cothread.c* cothread.h* diexec.c diexec.h emu.h emu.mak schedule.c schedule.h
[src/emu/cpu/i386]i386.c
[src/emu/cpu/sh4]sh4.c sh4comn.c sh4comn.h sh4regs.h
[src/emu/machine]eeprom.c
[src/lib]lib.mak
[src/lib/cothread]amd64.c* fiber.c* libco.c* libco.h* ppc.c* sjlj.c* ucontext.c* x86.c*
[src/lib/cothread/doc]amd64.asm* style.css* targets.html* usage.html* x86.asm*
[src/lib/cothread/test]cc.bat* cc.sh* test.h* test_args.cpp* test_timing.cpp*
[src/mame]mame.lst
[src/mame/drivers]armedf.c midvunit.c vp101.c warpsped.c

src/mame/mame.lst
r12047r12048
438438legion         // (c) 1986
439439legiono         // (c) 1986
440440terraf         // (c) 1987
441terrafu         // (c) 1987 Nichibutsu USA
442terrafj         // (c) 1987 Nichibutsu Japan
443terrafjb      // (c) 1987
441444terrafb         // (c) 1987
442terrafa         // (c) 1987
443terrafu         // (c) 1987 Nichibutsu USA
444445kozure         // (c) 1987 (Japan)
445446armedf         // (c) 1988
446447armedff         // (c) 1988 Fillmore license
src/mame/drivers/vp101.c
r12047r12048
9999    ROM_LOAD( "specialforces_boot34.u4", 0x000000, 0x100000, CRC(db4862ac) SHA1(a1e886d424cf7d26605e29d972d48e8d44ae2d58) )
100100
101101   DISK_REGION( "ide" )
102   DISK_IMAGE_READONLY("sf010101", 0, SHA1(2fc4e02d08163d8ed28b00f590240d550eaa6015) )
102   DISK_IMAGE_READONLY("sf010101", 0, SHA1(59b5e3d8e1d5537204233598830be2066aad0556) )
103103ROM_END
104104
105105GAME( 2002, specfrce, 0, vp101, vp101, 0, ROT0, "ICE/Play Mechanix", "Special Forces Elite Training", GAME_NOT_WORKING|GAME_NO_SOUND )
src/mame/drivers/warpsped.c
r12047r12048
22
33Meadows Warp Speed
44
5Preliminary driver by Mariusz Wojcieszek
5Driver by Mariusz Wojcieszek
66
7Notes:
8- Circles drawing does not follow the hardware. Roms which come in pairs four times
9  on the board are used by circle generators. These roms are thought to contain cosine tables,
10  16 bits wide, with g17 being the MSB and g18 being the LSB
11- Circles colors are probably not correct
12- Starfield is wrong. It is done with tilemap fixed in rom, but rom mapping is not correct.
13  Starfield scrolling is missing too
14- What are unknown roms used for?
15
716Hardware registers:
80x00 - 0x1f control register for discs generator (8 bytes each)
9            0x00, 0x01  disc radius (?)
10            0x02, 0x03  disc middle point
11            0x04, 0x05  disc middle point
12            0x06        disc colour (0-7)
13            0x07        unused
140x20        ?
150x21        sound (intro screens have bit 1 toggled for click effect)
160x22        ?
170x23        ?
180x24        ?
190x25        ?
200x26        ?
210x27        ?
170x00 - 0x1f control register for circles generator (8 bytes each)         
18         0x00, 0x01   circle radius         
19         0x02, 0x03   circle middle point         
20         0x04, 0x05   circle middle point         
21         0x06      circle colour (0-7)         
22         0x07      unused
230x20      ?
240x21      sound (intro screens have bit 1 toggled for click effect)
250x22      ?
260x23      ?
270x24      ?
280x25      ?
290x26      ?
300x27      ?
2231
23
2432Board etched...
25    MEADOWS 024-0084
26    MADE IN USA
33   MEADOWS 024-0084
34   MADE IN USA
2735
2836Empty socket at .E3
2937Z80 processor
r12047r12048
32405Mhz crystal
3341All PROMS are SN74s474
3442
35.L18    no sticker
36.L17    stickered       L9, L13
37                L17, G17
38.L15    stickered       L10, L15
39                L18, G18
40.L13    stickered       L9, L13
41                L17, G17
42.L10    stickered       L10, L15
43                L18, G18
44.L9 stickered (damaged) xxx, L13
45                xxx, G1y
46.K1 stickered       K1
47.G2 no sticker      K1
48.E4 no sticker
49.E5 stickered       M16
50                PRO
51                1
52.E6 stickered       M16
53                PRO
54                3
55.C3 can't read
56.C4 stickered       M16
57                PRO
58                4
59.C5 stickered       M16
60                PRO
61                0
62.C6 stickered       M16
63                PRO
64                2
65.E8 stickered       E8
66.E10    stickered       E10
67.C12    stickered       C12
68.G17    stickered       L9, L13
69                L17, G17
70.G18    stickered       L10, L15
71                L18, G18
43.L18    no sticker
44.L17   stickered      L9, L13
45            L17, G17
46.L15   stickered      L10, L15
47            L18, G18
48.L13   stickered      L9, L13
49            L17, G17
50.L10   stickered      L10, L15
51            L18, G18
52.L9   stickered (damaged)   xxx, L13
53            xxx, G1y
54.K1   stickered      K1
55.G2   no sticker      K1
56.E4   no sticker     
57.E5   stickered      M16
58            PRO
59            1
60.E6   stickered      M16
61            PRO
62            3
63.C3   can't read
64.C4   stickered      M16
65            PRO
66            4
67.C5   stickered      M16
68            PRO
69            0
70.C6   stickered      M16
71            PRO
72            2
73.E8   stickered      E8
74.E10   stickered      E10
75.C12   stickered      C12
76.G17   stickered      L9, L13
77            L17, G17
78.G18   stickered      L10, L15
79            L18, G18
7280
7381L9, L13, L17 and G17 all read the same
7482L10, L15, L18 and G18 all read the same
r12047r12048
9199   UINT8      m_regs[0x28];
92100};
93101
94static READ8_HANDLER( warpspeed_hardware_r )
95{
96//  warpspeed_state *state = space->machine().driver_data<warpspeed_state>();
97
98   switch( offset )
99   {
100      case 0: return input_port_read(space->machine(), "IN1" );
101      /* dipswitches? bit 6 when set causes jump to $e01 during vblank (rom missing) is this test mode? */
102      case 2: return 0;
103      case 3: return input_port_read(space->machine(), "IN0" );
104   }
105   return 0;
106}
107
108102static WRITE8_HANDLER( warpspeed_hardware_w )
109103{
110104   warpspeed_state *state = space->machine().driver_data<warpspeed_state>();
r12047r12048
146140   tilemap_mark_all_tiles_dirty(state->m_starfield_tilemap);
147141}
148142
143static void draw_circle_line(bitmap_t *bitmap, int x, int y, int l, int color)
144{
145   if (y >= 0 && y <= bitmap->height - 1)
146   {
147      UINT16* pLine = BITMAP_ADDR16(bitmap, y, 0);
148
149      int h1 = x - l;
150      int h2 = x + l;
151
152      if (h1 < 0)
153         h1 = 0;
154      if (h2 > bitmap->width - 1)
155         h2 = bitmap->width - 1;
156
157      for (x = h1; x <= h2; x++)
158         pLine[x] = color;
159   }
160}
161
162static void warpspeed_draw_circle(bitmap_t *bitmap, INT16 cx, INT16 cy, UINT16 radius, UINT8 color )
163{
164   /* Bresenham's circle algorithm */
165
166   int x = 0;
167   int y = radius;
168
169   int d = 3 - 2 * radius;
170
171   while (x <= y)
172   {
173      draw_circle_line(bitmap, cx, cy - x, y, color);
174      draw_circle_line(bitmap, cx, cy + x, y, color);
175      draw_circle_line(bitmap, cx, cy - y, x, color);
176      draw_circle_line(bitmap, cx, cy + y, x, color);
177
178      x++;
179
180      if (d < 0)
181         d += 4 * x + 6;
182      else
183         d += 4 * (x - y--) + 10;
184   }
185}
186
187static void warpspeed_draw_circles(bitmap_t *bitmap, warpspeed_state *state)
188{
189   for (int i = 0; i < 4; i++)
190   {
191      UINT16 radius = state->m_regs[i*8] + state->m_regs[i*8 + 1]*256;
192      radius = 0xffff - radius;
193      radius = sqrt((float)radius);
194      INT16 midx = state->m_regs[i*8 + 2] + state->m_regs[i*8 + 3]*256;
195      midx -= 0xe70;
196      INT16 midy = state->m_regs[i*8 + 4] + state->m_regs[i*8 + 5]*256;
197      midy -= 0xe70;
198      if ( radius == 0 || radius == 0xffff )
199      {
200         continue;
201      }
202      warpspeed_draw_circle(bitmap, midx + 128 + 16, midy + 128 + 16, radius, (state->m_regs[i*8 + 6] & 0x07) + 2);
203   }
204}
205
149206static SCREEN_UPDATE( warpspeed )
150207{
151208   warpspeed_state *state = screen->machine().driver_data<warpspeed_state>();
152209
153210   tilemap_draw(bitmap, cliprect, state->m_starfield_tilemap, 0, 0);
211   warpspeed_draw_circles(bitmap, state);
154212   tilemap_draw(bitmap, cliprect, state->m_text_tilemap, 0, 0);
155213   return 0;
156214}
r12047r12048
163221
164222static ADDRESS_MAP_START ( warpspeed_io_map, AS_IO, 8)
165223   ADDRESS_MAP_GLOBAL_MASK(0xff)
166   AM_RANGE(0x00, 0x03) AM_READ( warpspeed_hardware_r )
224   AM_RANGE(0x00, 0x00) AM_READ_PORT("IN0")
225   AM_RANGE(0x01, 0x01) AM_READ_PORT("IN1")
226   AM_RANGE(0x02, 0x02) AM_READ_PORT("DSW")
227   AM_RANGE(0x03, 0x03) AM_READ_PORT("IN2")
167228   AM_RANGE(0x00, 0x27) AM_WRITE( warpspeed_hardware_w )
168229ADDRESS_MAP_END
169230
170231static INPUT_PORTS_START( warpspeed )
171232   PORT_START("IN0")
233   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME( "Accelerate" )
234   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME( "Brake" )
235   PORT_BIT( 0x3f, 0x20, IPT_AD_STICK_X ) PORT_MINMAX(0x00,0x3f) PORT_SENSITIVITY(20) PORT_KEYDELTA(5) PORT_CENTERDELTA(0) PORT_REVERSE
236
237   PORT_START("IN1")
238   PORT_BIT( 0xc0, IP_ACTIVE_HIGH, IPT_UNUSED )
239   PORT_BIT( 0x3f, 0x20, IPT_AD_STICK_Y ) PORT_MINMAX(0x00,0x3f) PORT_SENSITIVITY(20) PORT_KEYDELTA(5) PORT_CENTERDELTA(0) PORT_REVERSE
240
241   PORT_START("IN2")
172242   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_COIN1 )
173243   PORT_BIT( 0x7e, IP_ACTIVE_HIGH, IPT_UNUSED )
174244   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_VBLANK )
175245
176   PORT_START("IN1")
177   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME( "Accelerate" )
178   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME( "Brake" )
179   PORT_BIT( 0x3f, IP_ACTIVE_LOW, IPT_UNKNOWN )
246   PORT_START("DSW")
247   PORT_DIPNAME( 0x07, 0x00, "Coin/Time" )
248   PORT_DIPSETTING(    0x00, "50 sec" )
249   PORT_DIPSETTING(    0x01, "75 sec" )
250   PORT_DIPSETTING(    0x02, "100 sec" )
251   PORT_DIPSETTING(    0x03, "125 sec" )
252   PORT_DIPSETTING(    0x04, "150 sec" )
253   PORT_DIPSETTING(    0x05, "175 sec" )
254   PORT_DIPSETTING(    0x06, "200 sec" )
255   PORT_DIPSETTING(    0x07, "225 sec" )
256
257   PORT_DIPUNKNOWN( 0x08, 0x00 )
258
259   PORT_DIPUNKNOWN( 0x10, 0x00 )
260
261   PORT_DIPNAME( 0x20, 0x00, DEF_STR( Coinage ) )
262   PORT_DIPSETTING(    0x20, DEF_STR( 2C_1C ) )
263   PORT_DIPSETTING(    0x00, DEF_STR( 1C_1C ) )
264
265   PORT_DIPNAME( 0x40, 0x00, DEF_STR( Service_Mode ) )
266   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
267   PORT_DIPSETTING(    0x40, DEF_STR( On ) )
268
269   PORT_DIPUNUSED( 0x80, 0x00 )
180270INPUT_PORTS_END
181271
182272static const gfx_layout warpspeed_charlayout =
r12047r12048
195285   GFXDECODE_ENTRY( "gfx2", 0, warpspeed_charlayout,   0, 1  )
196286GFXDECODE_END
197287
288static PALETTE_INIT( warpspeed )
289{
290   // tilemaps
291   palette_set_color(machine,0,RGB_BLACK); /* black */
292   palette_set_color(machine,1,RGB_WHITE); /* white */
293
294   // circles
295   for ( int i = 0; i < 8; i++ )
296   {
297      palette_set_color_rgb(machine, 2 + i, 0xff*BIT(i,0), 0xff*BIT(i,1), 0xff*BIT(i,2));
298   }
299}
300
198301static MACHINE_CONFIG_START( warpspeed, warpspeed_state )
199302   /* basic machine hardware */
200303   MCFG_CPU_ADD("maincpu", Z80, XTAL_5MHz/2)
r12047r12048
207310   MCFG_SCREEN_ADD("screen", RASTER)
208311   MCFG_SCREEN_REFRESH_RATE(60)
209312   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500))
210   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
313   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
211314   MCFG_SCREEN_SIZE((32)*8, (32)*8)
212315   MCFG_SCREEN_VISIBLE_AREA(4*8, 32*8-1, 8*8, 32*8-1)
213316
r12047r12048
215318   MCFG_SCREEN_UPDATE(warpspeed)
216319
217320   MCFG_GFXDECODE(warpspeed)
218   MCFG_PALETTE_LENGTH(2)
219   MCFG_PALETTE_INIT(black_and_white)
321   MCFG_PALETTE_LENGTH(2+8)
322   MCFG_PALETTE_INIT(warpspeed)
220323
221324MACHINE_CONFIG_END
222325
r12047r12048
259362{
260363}
261364
262GAME( 197?, warpsped,  0,      warpspeed, warpspeed, warpspeed, ROT0, "Meadows Games, Inc.", "Warp Speed (prototype)", GAME_NO_SOUND | GAME_NOT_WORKING )
365GAME( 197?, warpsped,  0,      warpspeed, warpspeed, warpspeed, ROT0, "Meadows Games, Inc.", "Warp Speed (prototype)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_COLORS | GAME_NO_SOUND )
src/mame/drivers/armedf.c
r12047r12048
16311631
16321632ROM_START( terraf )
16331633   ROM_REGION( 0x60000, "maincpu", ROMREGION_ERASEFF )   /* 64K*8 for 68000 code */
1634   ROM_LOAD16_BYTE( "tf-014.6e", 0x00000, 0x10000, CRC(8e5f557f) SHA1(3462a58146c3f33bf8686adbd2ead25dae3804a8) )
1635   ROM_LOAD16_BYTE( "tf-011.6h", 0x00001, 0x10000, CRC(5320162a) SHA1(eaffafcaf146cdddb03f40f92ce23dfd096eb89e) )
1636   ROM_LOAD16_BYTE( "tf-013.4e", 0x20000, 0x10000, CRC(a86951e0) SHA1(804cc6f143993f5a9d5f3798e971d7abfe94c3a8) )
1637   ROM_LOAD16_BYTE( "tf-010.4h", 0x20001, 0x10000, CRC(58b5f43b) SHA1(9df77235c0b7ac5af4258c04bd90d0a86ccc86b0) )
1638   ROM_LOAD16_BYTE( "tf-012.3e", 0x40000, 0x08000, CRC(4f0e1d76) SHA1(b8636acde7547358663b94bdc8d49b5cc6b596eb) )
1639   ROM_LOAD16_BYTE( "tf-009.3h", 0x40001, 0x08000, CRC(d1014280) SHA1(5ee8d71d77b31b25cce2bf1953c0a5166313a857) )
1634   ROM_LOAD16_BYTE( "8.6e", 0x00000, 0x10000, CRC(fd58fa06) SHA1(f1f5fbd153be5fd5669aada66134baedfeac5d32) )
1635   ROM_LOAD16_BYTE( "3.6h", 0x00001, 0x10000, CRC(54823a7d) SHA1(bdf67890428710470a622ea48383b3fae8de8cbd) )
1636   ROM_LOAD16_BYTE( "7.4e", 0x20000, 0x10000, CRC(fde8de7e) SHA1(6b0d27ec49c8c0609c110ad97938bec8c077ad18) )
1637   ROM_LOAD16_BYTE( "2.4h", 0x20001, 0x10000, CRC(db987414) SHA1(0a1734794c626cf9083d7854c9000c5daadfc3fd) )
1638   ROM_LOAD16_BYTE( "6.3e", 0x40000, 0x10000, CRC(a5bb8c3b) SHA1(36730b1a4a686de7251b80eb084a00f64bd7b40d) )
1639   ROM_LOAD16_BYTE( "1.3h", 0x40001, 0x10000, CRC(d2de6d28) SHA1(0371b5bf8e6105aaf8847c4b6d0d2d7d105079c1) )
16401640
16411641   ROM_REGION( 0x10000, "audiocpu", 0 )   /* Z80 code (sound) */
1642   ROM_LOAD( "11.17k", 0x00000, 0x10000,  CRC(4407d475) SHA1(96e86c7ef4dc997812436f7d0ddea332b4e6cb2b) )
1643
1644   ROM_REGION( 0x08000, "gfx1", 0 )
1645   ROM_LOAD( "9.11e", 0x00000, 0x08000, CRC(bc6f7cbc) SHA1(20b8a34de4bfa0c2fdcd2f7743a0ab35141f4bf9) ) /* characters */
1646
1647   ROM_REGION( 0x20000, "gfx2", 0 )
1648   ROM_LOAD( "5.15h", 0x00000, 0x10000, CRC(25d23dfd) SHA1(da32895c1aca403209b7fb181fa4fa23a8e74d32) ) /* foreground tiles */
1649   ROM_LOAD( "4.13h", 0x10000, 0x10000, CRC(b9b0fe27) SHA1(983c48239ba1524b517f89f281f2b70564bea1e9) )
1650
1651   ROM_REGION( 0x20000, "gfx3", 0 )
1652   ROM_LOAD( "15.8a", 0x00000, 0x10000, CRC(2144d8e0) SHA1(ed89da11abf3d79753b478603009970c2600ab60) ) /* background tiles */
1653   ROM_LOAD( "14.6a", 0x10000, 0x10000, CRC(744f5c9e) SHA1(696223a087bb575c7cfaba11e682b221ada461e4) )
1654
1655   ROM_REGION( 0x20000, "gfx4", 0 )
1656   ROM_LOAD( "12.7d", 0x00000, 0x10000, CRC(2d1f2ceb) SHA1(77544e1c4bda06feac135a96bb76af7c79278dc0) ) /* sprites */
1657   ROM_LOAD( "13.9d", 0x10000, 0x10000, CRC(1d2f92d6) SHA1(e842c6bf95a5958a6ca2c85e68b9bc3cc15211a4) )
1658
1659   ROM_REGION( 0x4000, "blit_data", 0 )   /* data for mcu/blitter */
1660   ROM_LOAD( "10.11c", 0x0000, 0x4000, CRC(ac705812) SHA1(65be46ee959d8478cb6dffb25e61f7742276997b) )
1661
1662   ROM_REGION( 0x0100, "proms", 0 )   /* Unknown use */
1663   ROM_LOAD( "n82s129an.11j", 0x0000, 0x0100, CRC(81244757) SHA1(6324f63e571f0f7a0bb9eb97f9994809db79493f) ) /* N82S129AN or compatible labled "TF" */
1664ROM_END
1665
1666ROM_START( terrafu ) /* Bootleg of the USA version?, uses some roms common to bootlegs that differ to the orginal board sets */
1667   ROM_REGION( 0x60000, "maincpu", ROMREGION_ERASEFF )   /* 64K*8 for 68000 code */
1668   ROM_LOAD16_BYTE( "tf-8.6e", 0x00000, 0x10000, CRC(fea6dd64) SHA1(682eae338ce14808f134897f594fae1c69e75a1a) )
1669   ROM_LOAD16_BYTE( "tf-3.6h", 0x00001, 0x10000, CRC(02f9d05a) SHA1(88985373bc3cffbc838e0b701ecd732a417975a1) )
1670   ROM_LOAD16_BYTE( "tf-7.4e", 0x20000, 0x10000, CRC(fde8de7e) SHA1(6b0d27ec49c8c0609c110ad97938bec8c077ad18) )
1671   ROM_LOAD16_BYTE( "tf-2.4h", 0x20001, 0x10000, CRC(db987414) SHA1(0a1734794c626cf9083d7854c9000c5daadfc3fd) )
1672   ROM_LOAD16_BYTE( "tf-6.3e", 0x40000, 0x08000, CRC(b91e9ba3) SHA1(33e5272d1691859a2bb1f340eb4bdfdd5d73a5d4) ) /* Half the size of World & Japan sets?? */
1673   ROM_LOAD16_BYTE( "tf-1.3h", 0x40001, 0x08000, CRC(d6e22375) SHA1(c84fc19700b65ee36b0c7d75cd7c97f86c7f719d) ) /* bootlegs use this size rom for 1 & 6  */
1674
1675   ROM_REGION( 0x10000, "audiocpu", 0 )   /* Z80 code (sound) */
16421676   ROM_LOAD( "tf-001.17k", 0x00000, 0x10000, CRC(eb6b4138) SHA1(04c53bf46d87a156d3fad86f051985d0df79bd20) )
16431677
16441678   ROM_REGION( 0x08000, "gfx1", 0 )
r12047r12048
16561690   ROM_LOAD( "tf-003.7d", 0x00000, 0x10000, CRC(d74085a1) SHA1(3f6ba85dbd6e48a502c115b2d322a586fc4f56c9) ) /* sprites */
16571691   ROM_LOAD( "tf-002.9d", 0x10000, 0x10000, CRC(148aa0c5) SHA1(8d8a565540e91b384a9c154522501921b7da4d4e) )
16581692
1659   ROM_REGION( 0x4000, "blit_data", 0 )   /* data for mcu/blitter, shouldn't be loaded? */
1693   ROM_REGION( 0x4000, "blit_data", 0 )   /* data for mcu/blitter */
16601694   ROM_LOAD( "tf-10.11c", 0x0000, 0x4000, CRC(ac705812) SHA1(65be46ee959d8478cb6dffb25e61f7742276997b) )
16611695
16621696   ROM_REGION( 0x0100, "proms", 0 )   /* Unknown use */
16631697   ROM_LOAD( "n82s129an.11j", 0x0000, 0x0100, CRC(81244757) SHA1(6324f63e571f0f7a0bb9eb97f9994809db79493f) ) /* N82S129AN or compatible labled "TF" */
16641698ROM_END
16651699
1700ROM_START( terrafj )
1701   ROM_REGION( 0x60000, "maincpu", ROMREGION_ERASEFF )   /* 64K*8 for 68000 code */
1702   ROM_LOAD16_BYTE( "tfj-8.bin", 0x00000, 0x10000, CRC(b11a6fa7) SHA1(7bb2b98be02d8913796a6d4fa20eed16226ce6b9) )
1703   ROM_LOAD16_BYTE( "tfj-3.bin", 0x00001, 0x10000, CRC(6c6aa7ed) SHA1(ee5fdeb5411034ce0fd1c883ee25bf1fe9a3ec52) )
1704   ROM_LOAD16_BYTE( "tfj-7.bin", 0x20000, 0x10000, CRC(fde8de7e) SHA1(6b0d27ec49c8c0609c110ad97938bec8c077ad18) )
1705   ROM_LOAD16_BYTE( "tfj-2.bin", 0x20001, 0x10000, CRC(db987414) SHA1(0a1734794c626cf9083d7854c9000c5daadfc3fd) )
1706   ROM_LOAD16_BYTE( "tfj-6.bin", 0x40000, 0x10000, CRC(4911dfbf) SHA1(91d3607e98e2e746cebddd20a10a033a5557c017) )
1707   ROM_LOAD16_BYTE( "tfj-1.bin", 0x40001, 0x10000, CRC(93063d9a) SHA1(58321e18865a0a72b74beab969b7ea5e010be16a) )
1708
1709   ROM_REGION( 0x10000, "audiocpu", 0 )   /* Z80 code (sound) */
1710   ROM_LOAD( "11.17k", 0x00000, 0x10000,  CRC(4407d475) SHA1(96e86c7ef4dc997812436f7d0ddea332b4e6cb2b) )
1711
1712   ROM_REGION( 0x08000, "gfx1", 0 )
1713   ROM_LOAD( "9.11e", 0x00000, 0x08000, CRC(bc6f7cbc) SHA1(20b8a34de4bfa0c2fdcd2f7743a0ab35141f4bf9) ) /* characters */
1714
1715   ROM_REGION( 0x20000, "gfx2", 0 )
1716   ROM_LOAD( "5.15h", 0x00000, 0x10000, CRC(25d23dfd) SHA1(da32895c1aca403209b7fb181fa4fa23a8e74d32) ) /* foreground tiles */
1717   ROM_LOAD( "4.13h", 0x10000, 0x10000, CRC(b9b0fe27) SHA1(983c48239ba1524b517f89f281f2b70564bea1e9) )
1718
1719   ROM_REGION( 0x20000, "gfx3", 0 )
1720   ROM_LOAD( "15.8a", 0x00000, 0x10000, CRC(2144d8e0) SHA1(ed89da11abf3d79753b478603009970c2600ab60) ) /* background tiles */
1721   ROM_LOAD( "14.6a", 0x10000, 0x10000, CRC(744f5c9e) SHA1(696223a087bb575c7cfaba11e682b221ada461e4) )
1722
1723   ROM_REGION( 0x20000, "gfx4", 0 )
1724   ROM_LOAD( "12.7d", 0x00000, 0x10000, CRC(2d1f2ceb) SHA1(77544e1c4bda06feac135a96bb76af7c79278dc0) ) /* sprites */
1725   ROM_LOAD( "13.9d", 0x10000, 0x10000, CRC(1d2f92d6) SHA1(e842c6bf95a5958a6ca2c85e68b9bc3cc15211a4) )
1726
1727   ROM_REGION( 0x4000, "blit_data", 0 )   /* data for mcu/blitter */
1728   ROM_LOAD( "10.11c", 0x0000, 0x4000, CRC(ac705812) SHA1(65be46ee959d8478cb6dffb25e61f7742276997b) )
1729
1730   ROM_REGION( 0x0100, "proms", 0 )   /* Unknown use */
1731   ROM_LOAD( "n82s129an.11j", 0x0000, 0x0100, CRC(81244757) SHA1(6324f63e571f0f7a0bb9eb97f9994809db79493f) ) /* N82S129AN or compatible labled "TF" */
1732ROM_END
1733
16661734/*
16671735
16681736CPU
r12047r12048
16931761*/
16941762
16951763
1696ROM_START( terrafb )
1764ROM_START( terrafjb )
16971765   ROM_REGION( 0x60000, "maincpu", ROMREGION_ERASEFF )   /* 64K*8 for 68000 code */
1698   ROM_LOAD16_BYTE( "tfb-8.bin", 0x00000, 0x10000, CRC(b11a6fa7) SHA1(7bb2b98be02d8913796a6d4fa20eed16226ce6b9) )
1699   ROM_LOAD16_BYTE( "tfb-3.bin", 0x00001, 0x10000, CRC(6c6aa7ed) SHA1(ee5fdeb5411034ce0fd1c883ee25bf1fe9a3ec52) )
1700   ROM_LOAD16_BYTE( "tfb-7.bin", 0x20000, 0x10000, CRC(fde8de7e) SHA1(6b0d27ec49c8c0609c110ad97938bec8c077ad18) )
1701   ROM_LOAD16_BYTE( "tfb-2.bin", 0x20001, 0x10000, CRC(db987414) SHA1(0a1734794c626cf9083d7854c9000c5daadfc3fd) )
1766   ROM_LOAD16_BYTE( "tfj-8.bin", 0x00000, 0x10000, CRC(b11a6fa7) SHA1(7bb2b98be02d8913796a6d4fa20eed16226ce6b9) )
1767   ROM_LOAD16_BYTE( "tfj-3.bin", 0x00001, 0x10000, CRC(6c6aa7ed) SHA1(ee5fdeb5411034ce0fd1c883ee25bf1fe9a3ec52) )
1768   ROM_LOAD16_BYTE( "tfj-7.bin", 0x20000, 0x10000, CRC(fde8de7e) SHA1(6b0d27ec49c8c0609c110ad97938bec8c077ad18) )
1769   ROM_LOAD16_BYTE( "tfj-2.bin", 0x20001, 0x10000, CRC(db987414) SHA1(0a1734794c626cf9083d7854c9000c5daadfc3fd) )
17021770   ROM_LOAD16_BYTE( "tfb-6.bin", 0x40000, 0x08000, CRC(552c3c63) SHA1(82d930b7fcdf4879c4644c47ecce58fd2645f10f) )
17031771   ROM_LOAD16_BYTE( "tfb-1.bin", 0x40001, 0x08000, CRC(6a0b94c7) SHA1(55fb32ab859bf51a1c79bf962bb677fa557216ed) )
17041772
r12047r12048
17281796   ROM_LOAD( "n82s129an.11j", 0x0000, 0x0100, CRC(81244757) SHA1(6324f63e571f0f7a0bb9eb97f9994809db79493f) ) /* N82S129AN or compatible labled "TF" */
17291797ROM_END
17301798
1731
1732ROM_START( terrafu )
1799ROM_START( terrafb ) /* Seems to be a bootleg of the Japanese version with the region warning screen hacked to just say "WAIT" */
17331800   ROM_REGION( 0x60000, "maincpu", ROMREGION_ERASEFF )   /* 64K*8 for 68000 code */
1734   ROM_LOAD16_BYTE( "tf-8.6e", 0x00000, 0x10000, CRC(fea6dd64) SHA1(682eae338ce14808f134897f594fae1c69e75a1a) )
1735   ROM_LOAD16_BYTE( "tf-3.6h", 0x00001, 0x10000, CRC(02f9d05a) SHA1(88985373bc3cffbc838e0b701ecd732a417975a1) )
1736   ROM_LOAD16_BYTE( "tf-7.4e", 0x20000, 0x10000, CRC(fde8de7e) SHA1(6b0d27ec49c8c0609c110ad97938bec8c077ad18) )
1737   ROM_LOAD16_BYTE( "tf-2.4h", 0x20001, 0x10000, CRC(db987414) SHA1(0a1734794c626cf9083d7854c9000c5daadfc3fd) )
1738   ROM_LOAD16_BYTE( "tf-6.3e", 0x40000, 0x08000, CRC(b91e9ba3) SHA1(33e5272d1691859a2bb1f340eb4bdfdd5d73a5d4) )
1739   ROM_LOAD16_BYTE( "tf-1.3h", 0x40001, 0x08000, CRC(d6e22375) SHA1(c84fc19700b65ee36b0c7d75cd7c97f86c7f719d) )
1801   ROM_LOAD16_BYTE( "tf-014.6e", 0x00000, 0x10000, CRC(8e5f557f) SHA1(3462a58146c3f33bf8686adbd2ead25dae3804a8) )
1802   ROM_LOAD16_BYTE( "tf-011.6h", 0x00001, 0x10000, CRC(5320162a) SHA1(eaffafcaf146cdddb03f40f92ce23dfd096eb89e) )
1803   ROM_LOAD16_BYTE( "tf-013.4e", 0x20000, 0x10000, CRC(a86951e0) SHA1(804cc6f143993f5a9d5f3798e971d7abfe94c3a8) )
1804   ROM_LOAD16_BYTE( "tf-010.4h", 0x20001, 0x10000, CRC(58b5f43b) SHA1(9df77235c0b7ac5af4258c04bd90d0a86ccc86b0) )
1805   ROM_LOAD16_BYTE( "tf-012.3e", 0x40000, 0x08000, CRC(4f0e1d76) SHA1(b8636acde7547358663b94bdc8d49b5cc6b596eb) )
1806   ROM_LOAD16_BYTE( "tf-009.3h", 0x40001, 0x08000, CRC(d1014280) SHA1(5ee8d71d77b31b25cce2bf1953c0a5166313a857) )
17401807
17411808   ROM_REGION( 0x10000, "audiocpu", 0 )   /* Z80 code (sound) */
17421809   ROM_LOAD( "tf-001.17k", 0x00000, 0x10000, CRC(eb6b4138) SHA1(04c53bf46d87a156d3fad86f051985d0df79bd20) )
r12047r12048
17561823   ROM_LOAD( "tf-003.7d", 0x00000, 0x10000, CRC(d74085a1) SHA1(3f6ba85dbd6e48a502c115b2d322a586fc4f56c9) ) /* sprites */
17571824   ROM_LOAD( "tf-002.9d", 0x10000, 0x10000, CRC(148aa0c5) SHA1(8d8a565540e91b384a9c154522501921b7da4d4e) )
17581825
1759   ROM_REGION( 0x4000, "blit_data", 0 )   /* data for mcu/blitter */
1826   ROM_REGION( 0x4000, "blit_data", 0 )   /* data for mcu/blitter, shouldn't be loaded? */
17601827   ROM_LOAD( "tf-10.11c", 0x0000, 0x4000, CRC(ac705812) SHA1(65be46ee959d8478cb6dffb25e61f7742276997b) )
17611828
17621829   ROM_REGION( 0x0100, "proms", 0 )   /* Unknown use */
17631830   ROM_LOAD( "n82s129an.11j", 0x0000, 0x0100, CRC(81244757) SHA1(6324f63e571f0f7a0bb9eb97f9994809db79493f) ) /* N82S129AN or compatible labled "TF" */
17641831ROM_END
17651832
1766ROM_START( terrafa )
1767   ROM_REGION( 0x60000, "maincpu", ROMREGION_ERASEFF )   /* 64K*8 for 68000 code */
1768   ROM_LOAD16_BYTE( "8.6e", 0x00000, 0x10000, CRC(fd58fa06) SHA1(f1f5fbd153be5fd5669aada66134baedfeac5d32) )
1769   ROM_LOAD16_BYTE( "3.6h", 0x00001, 0x10000, CRC(54823a7d) SHA1(bdf67890428710470a622ea48383b3fae8de8cbd) )
1770   ROM_LOAD16_BYTE( "7.4e", 0x20000, 0x10000, CRC(fde8de7e) SHA1(6b0d27ec49c8c0609c110ad97938bec8c077ad18) )
1771   ROM_LOAD16_BYTE( "2.4h", 0x20001, 0x10000, CRC(db987414) SHA1(0a1734794c626cf9083d7854c9000c5daadfc3fd) )
1772   ROM_LOAD16_BYTE( "6.3e", 0x40000, 0x10000, CRC(a5bb8c3b) SHA1(36730b1a4a686de7251b80eb084a00f64bd7b40d) )
1773   ROM_LOAD16_BYTE( "1.3h", 0x40001, 0x10000, CRC(d2de6d28) SHA1(0371b5bf8e6105aaf8847c4b6d0d2d7d105079c1) )
1774
1775   ROM_REGION( 0x10000, "audiocpu", 0 )   /* Z80 code (sound) */
1776   ROM_LOAD( "11.17k", 0x00000, 0x10000,  CRC(4407d475) SHA1(96e86c7ef4dc997812436f7d0ddea332b4e6cb2b) )
1777
1778   ROM_REGION( 0x08000, "gfx1", 0 )
1779   ROM_LOAD( "9.11e", 0x00000, 0x08000, CRC(bc6f7cbc) SHA1(20b8a34de4bfa0c2fdcd2f7743a0ab35141f4bf9) ) /* characters */
1780
1781   ROM_REGION( 0x20000, "gfx2", 0 )
1782   ROM_LOAD( "5.15h", 0x00000, 0x10000, CRC(25d23dfd) SHA1(da32895c1aca403209b7fb181fa4fa23a8e74d32) ) /* foreground tiles */
1783   ROM_LOAD( "4.13h", 0x10000, 0x10000, CRC(b9b0fe27) SHA1(983c48239ba1524b517f89f281f2b70564bea1e9) )
1784
1785   ROM_REGION( 0x20000, "gfx3", 0 )
1786   ROM_LOAD( "15.8a", 0x00000, 0x10000, CRC(2144d8e0) SHA1(ed89da11abf3d79753b478603009970c2600ab60) ) /* background tiles */
1787   ROM_LOAD( "14.6a", 0x10000, 0x10000, CRC(744f5c9e) SHA1(696223a087bb575c7cfaba11e682b221ada461e4) )
1788
1789   ROM_REGION( 0x20000, "gfx4", 0 )
1790   ROM_LOAD( "12.7d", 0x00000, 0x10000, CRC(2d1f2ceb) SHA1(77544e1c4bda06feac135a96bb76af7c79278dc0) ) /* sprites */
1791   ROM_LOAD( "13.9d", 0x10000, 0x10000, CRC(1d2f92d6) SHA1(e842c6bf95a5958a6ca2c85e68b9bc3cc15211a4) )
1792
1793   ROM_REGION( 0x4000, "blit_data", 0 )   /* data for mcu/blitter */
1794   ROM_LOAD( "tf-10.11c", 0x0000, 0x4000, CRC(ac705812) SHA1(65be46ee959d8478cb6dffb25e61f7742276997b) )
1795
1796   ROM_REGION( 0x0100, "proms", 0 )   /* Unknown use */
1797   ROM_LOAD( "n82s129an.11j", 0x0000, 0x0100, CRC(81244757) SHA1(6324f63e571f0f7a0bb9eb97f9994809db79493f) ) /* N82S129AN or compatible labled "TF" */
1798ROM_END
1799
18001833ROM_START( kozure )
18011834   ROM_REGION( 0x60000, "maincpu", 0 )   /* 64K*8 for 68000 code */
18021835   ROM_LOAD16_BYTE( "kozure8.6e", 0x00000, 0x10000, CRC(6bbfb1e6) SHA1(ffc8f835e28ff5f5b11f826b74ac2712c3018178) )
r12047r12048
21212154 *
21222155 *************************************/
21232156
2124/*     YEAR, NAME,    PARENT,   MACHINE,  INPUT,    INIT,     MONITOR, COMPANY,         FULLNAME,                          FLAGS */
2125GAME( 1987, legion,   0,        legion,   legion,   legion,   ROT270, "Nichibutsu",     "Legion - Spinner-87 (World ver 2.03)", GAME_SUPPORTS_SAVE )
2126GAME( 1987, legiono,  legion,   legiono,  legion,   legiono,  ROT270, "Nichibutsu",     "Chouji Meikyuu Legion (Japan bootleg ver 1.05)", GAME_SUPPORTS_SAVE ) /* bootleg? */
2127GAME( 1987, terraf,   0,        terraf,   terraf,   terraf,   ROT0,   "bootleg",        "Terra Force (bootleg)", GAME_SUPPORTS_SAVE ) //world bootleg?
2128GAME( 1987, terrafb,  terraf,   terrafb,  terraf,   terrafb,  ROT0,   "bootleg",        "Terra Force (Japan bootleg with additional Z80)", GAME_SUPPORTS_SAVE )
2129GAME( 1987, terrafu,  terraf,   terraf,   terraf,   terrafu,  ROT0,   "Nichibutsu USA", "Terra Force (US set 1)", GAME_SUPPORTS_SAVE )
2130GAME( 1987, terrafa,  terraf,   terraf,   terraf,   terrafu,  ROT0,   "Nichibutsu USA", "Terra Force (US set 2)", GAME_SUPPORTS_SAVE ) //world?
2131GAME( 1987, kozure,   0,        kozure,   kozure,   kozure,   ROT0,   "Nichibutsu",     "Kozure Ookami (Japan)", GAME_SUPPORTS_SAVE | GAME_NOT_WORKING )
2132GAME( 1988, cclimbr2, 0,        cclimbr2, cclimbr2, cclimbr2, ROT0,   "Nichibutsu",     "Crazy Climber 2 (Japan)", GAME_SUPPORTS_SAVE )
2133GAME( 1988, cclimbr2a,cclimbr2, cclimbr2, cclimbr2, cclimbr2, ROT0,   "Nichibutsu",     "Crazy Climber 2 (Japan, Harder)", GAME_SUPPORTS_SAVE  )
2134GAME( 1988, armedf,   0,        armedf,   armedf,   armedf,   ROT270, "Nichibutsu",     "Armed Formation", GAME_SUPPORTS_SAVE )
2157/*     YEAR, NAME,    PARENT,   MACHINE,  INPUT,    INIT,     MONITOR, COMPANY,                        FULLNAME,                          FLAGS */
2158GAME( 1987, legion,   0,        legion,   legion,   legion,   ROT270, "Nichibutsu",                    "Legion - Spinner-87 (World ver 2.03)", GAME_SUPPORTS_SAVE )
2159GAME( 1987, legiono,  legion,   legiono,  legion,   legiono,  ROT270, "Nichibutsu",                    "Chouji Meikyuu Legion (Japan bootleg ver 1.05)", GAME_SUPPORTS_SAVE ) /* bootleg? */
2160GAME( 1987, terraf,   0,        terraf,   terraf,   terrafu,  ROT0,   "Nichibutsu",                    "Terra Force", GAME_SUPPORTS_SAVE )
2161GAME( 1987, terrafu,  terraf,   terraf,   terraf,   terrafu,  ROT0,   "Nichibutsu USA",                "Terra Force (US)", GAME_SUPPORTS_SAVE )
2162GAME( 1987, terrafj,  terraf,   terraf,   terraf,   terrafu,  ROT0,   "Nichibutsu Japan",              "Terra Force (Japan)", GAME_SUPPORTS_SAVE )
2163GAME( 1987, terrafjb, terraf,   terrafb,  terraf,   terrafb,  ROT0,   "bootleg",                       "Terra Force (Japan bootleg with additional Z80)", GAME_SUPPORTS_SAVE )
2164GAME( 1987, terrafb,  terraf,   terraf,   terraf,   terraf,   ROT0,   "bootleg",                       "Terra Force (bootleg)", GAME_SUPPORTS_SAVE ) //bootleg of Japan with warning screen hacked
2165GAME( 1987, kozure,   0,        kozure,   kozure,   kozure,   ROT0,   "Nichibutsu",                    "Kozure Ookami (Japan)", GAME_SUPPORTS_SAVE | GAME_NOT_WORKING )
2166GAME( 1988, cclimbr2, 0,        cclimbr2, cclimbr2, cclimbr2, ROT0,   "Nichibutsu",                    "Crazy Climber 2 (Japan)", GAME_SUPPORTS_SAVE )
2167GAME( 1988, cclimbr2a,cclimbr2, cclimbr2, cclimbr2, cclimbr2, ROT0,   "Nichibutsu",                    "Crazy Climber 2 (Japan, Harder)", GAME_SUPPORTS_SAVE  )
2168GAME( 1988, armedf,   0,        armedf,   armedf,   armedf,   ROT270, "Nichibutsu",                    "Armed Formation", GAME_SUPPORTS_SAVE )
21352169GAME( 1988, armedff,  armedf,   armedf,   armedf,   armedf,   ROT270, "Nichibutsu (Fillmore license)", "Armed Formation (Fillmore license)", GAME_SUPPORTS_SAVE )
2136GAME( 1989, skyrobo,  0,        bigfghtr, bigfghtr, bigfghtr, ROT0, "Nichibutsu", "Sky Robo", GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_SUPPORTS_SAVE )
2137GAME( 1989, bigfghtr, skyrobo,  bigfghtr, bigfghtr, bigfghtr, ROT0, "Nichibutsu", "Tatakae! Big Fighter (Japan)", GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_SUPPORTS_SAVE )
2170GAME( 1989, skyrobo,  0,        bigfghtr, bigfghtr, bigfghtr, ROT0,   "Nichibutsu",                    "Sky Robo", GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_SUPPORTS_SAVE )
2171GAME( 1989, bigfghtr, skyrobo,  bigfghtr, bigfghtr, bigfghtr, ROT0,   "Nichibutsu",                    "Tatakae! Big Fighter (Japan)", GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_SUPPORTS_SAVE )
src/mame/drivers/midvunit.c
r12047r12048
10731073 *************************************/
10741074
10751075/*
1076Cruis'n USA
1076Cruis'n USA & Offroad Challenge (Midway V-Unit)
10771077Midway, 1994
10781078
10791079PCB Layout
10801080----------
10811081
10825770-14365-02 (C) 1994 NINTENDO
10825770-14365-02 (C) 1994 NINTENDO (for Cruisin USA)
10835770-14365-05 WILLIAMS ELECTRONICS GAMES INC. (for Offroad Challenge)
10831084|-------------------------------------------------------------------------------|
1084|  SOUND.U5  SOUND.U9   BATTERY          GAME.U26  GAME.U27  GAME.U28  GAME.U29 |
1085|  SOUND.U5  SOUND.U9   BATTERY  MAX691  GAME.U26  GAME.U27  GAME.U28  GAME.U29 |
10851086|  SOUND.U4  SOUND.U8                    GAME.U22  GAME.U23  GAME.U24  GAME.U25 |
10861087|  SOUND.U3  SOUND.U7   6264  RESET_SW   GAME.U18  GAME.U19  GAME.U20  GAME.U21 |
1087|  SOUND.U2  SOUND.U6                    GAME.U14  GAME.U15  GAME.U16  GAME.U17 |
1088|  SOUND.U2  SOUND.U6         PIC16C57   GAME.U14  GAME.U15  GAME.U16  GAME.U17 |
10881089|                                        GAME.U10  GAME.U11  GAME.U12  GAME.U13 |
10891090|            6116            PAL2              IDT7204      IDT7204             |
10901091|                                          LH521007 LH521007   LH521007 LH521007|
r12047r12048
11131114      6264      - 8k x8 SRAM (battery-backed)
11141115      6116      - 2k x8 SRAM
11151116      AD1851    - Analog Devices AD1851 16 bit PCM Audio DAC
1117      MAX691    - Maxim MAX691 Master Reset IC (DIP16)
11161118      TDA2030   - ST TDA2030 Audio AMP
11171119      TL084     - Texas Instruments TL084 JFET-Input Operational Amplifier
11181120      ADC0844   - National Semiconductor ADC0844 8-Bit Microprocessor Compatible A/D Converter with Multiplexer Option
1121      PIC16C57  - Microchip PIC16C57
1122                    - not populated for Cruis'n USA
1123                    - labelled 'Offroad 25" U904' for Offroad Challenge
11191124      PAL1      - GAL20V8 labelled 'A-19668'
1120      PAL2      - PALC22V10 (no label)
1121      PAL3      - TIBPAL20L8 labelled 'A-19670'
1122      PAL4      - TIBPAL22V10 labelled 'A-19671'
1123      PAL5      - TIBPAL22V10 labelled 'A-19672'
1124      PAL6      - TIBPAL22V10 labelled 'A-19673'
1125      PAL2      - PALC22V10
1126                    - no label for Cruisin USA
1127                    - labelled 'A-21883 U38' for Offroad Challenge
1128      PAL3      - TIBPAL20L8
1129                    - labelled 'A-19670' for Cruis'n USA
1130                    - labelled 'A-21170 U43' for Offroad Challenge
1131      PAL4      - TIBPAL22V10
1132                    - labelled 'A-19671' for Cruis'n USA
1133                    - labelled 'A-21171 U54' for Offroad Challenge
1134      PAL5      - TIBPAL22V10
1135                    - labelled 'A-19672' for Cruis'n USA
1136                    - labelled 'A-21884 U114' for Offroad Challenge
1137      PAL6      - TIBPAL22V10
1138                    - labelled 'A-19673' for Cruis'n USA
1139                    - no label for Offroad Challenge
11251140      P3 - P11  - various connectors for controls
11261141      VSync     - 57.7090Hz  \
1127      HSync     - 15.3544kHz / measured via EL4583
1128      ROMs      - All ROMs 27C040
1142      HSync     - 24.807kHz  / measured via EL4583
1143      ROMs      - All ROMs 27C040 or 27C801
11291144                  SOUND.Uxx - Sound ROMs
11301145                  GAME.Uxx  - PROGRAM ROMs (including GFX)
11311146*/
r12047r12048
14291444ROM_END
14301445
14311446
1447ROM_START( offroadc5 ) /* Version 1.50, Tue 10-21-97 */
1448   ROM_REGION16_LE( 0x1000000, "dcs", ROMREGION_ERASEFF )   /* sound data */
1449   ROM_LOAD16_BYTE( "offroadc.u2",  0x000000, 0x80000, CRC(69976e9d) SHA1(63c886ac2563c43a10840f49f929f8613cd94de2) )
1450   ROM_LOAD16_BYTE( "offroadc.u3",  0x200000, 0x80000, CRC(2db9b548) SHA1(4f454a3e6a8851b0ef5d325dd28102d57ea11a11) )
1451   ROM_LOAD16_BYTE( "offroadc.u4",  0x400000, 0x80000, CRC(42bdf9d0) SHA1(04add0f0ee7fa61de1913cc0b988345d3d430cde) )
1452   ROM_LOAD16_BYTE( "offroadc.u5",  0x600000, 0x80000, CRC(569cc84b) SHA1(08b917cc41fae6b6a3e9d9461a783d3d2865e72a) )
1453   ROM_LOAD16_BYTE( "offroadc.u6",  0x800000, 0x80000, CRC(0896f679) SHA1(dde39ef17834256909ef2c9fcd5b5fb9939d5178) )
1454   ROM_LOAD16_BYTE( "offroadc.u7",  0xa00000, 0x80000, CRC(fe242d6a) SHA1(8fbac22ed23044841f309ce58c5b1affcdd5d114) )
1455   ROM_LOAD16_BYTE( "offroadc.u8",  0xc00000, 0x80000, CRC(5da13f12) SHA1(2bb5e929e8bc6c70cb4475024a6b0bb07ac25244) )
1456   ROM_LOAD16_BYTE( "offroadc.u9",  0xe00000, 0x80000, CRC(7ad27f69) SHA1(b33665d0593a95b58d529720aae49e90449bf714) )
1457
1458   ROM_REGION32_LE( 0x1000000, "user1", 0 )
1459   ROM_LOAD32_BYTE( "orc-1_5.u10",  0x0000000, 0x100000, CRC(f464be4f) SHA1(da6c04ae49d033f92cdd62f997841365c4a08616) ) /* Version 1.50 program roms */
1460   ROM_LOAD32_BYTE( "orc-1_5.u11",  0x0000001, 0x100000, CRC(eaddc9ac) SHA1(a6b810bf7460e3257bf6acdc3b79c532fb71ad68) )
1461   ROM_LOAD32_BYTE( "orc-1_5.u12",  0x0000002, 0x100000, CRC(a2da68da) SHA1(b8dcc042b9926055bff9020599c1c218f08b1727) )
1462   ROM_LOAD32_BYTE( "orc-1_5.u13",  0x0000003, 0x100000, CRC(b4755ee2) SHA1(1c4cde7ca60a6e8bff12aed348e7148e20a8caba) )
1463   ROM_LOAD32_BYTE( "offroadc.u14", 0x0400000, 0x100000, CRC(1e41d14b) SHA1(3f7c5fae1f8b82ddd811720837fa298785a8dd27) )
1464   ROM_LOAD32_BYTE( "offroadc.u15", 0x0400001, 0x100000, CRC(654d623d) SHA1(a944b8f8d71b099d7b5bbd7df6effb90afc3aec8) )
1465   ROM_LOAD32_BYTE( "offroadc.u16", 0x0400002, 0x100000, CRC(259774d8) SHA1(90cdf659324b84b3c2c59497cc5611e8f12629a6) )
1466   ROM_LOAD32_BYTE( "offroadc.u17", 0x0400003, 0x100000, CRC(50c61434) SHA1(52bc603101b4f88b7d892af683b7c8358cabbf4a) )
1467   ROM_LOAD32_BYTE( "offroadc.u18", 0x0800000, 0x100000, CRC(015be91c) SHA1(1624537068c6bc5fa6235bf0b0343347c337e8d8) )
1468   ROM_LOAD32_BYTE( "offroadc.u19", 0x0800001, 0x100000, CRC(cfc6b70e) SHA1(8c5ad84c50ca142726db0595153cf04caaabec9c) )
1469   ROM_LOAD32_BYTE( "offroadc.u20", 0x0800002, 0x100000, CRC(f48d6e33) SHA1(8b9c205e24f217ac110cdd82388c056ebbbb09b0) )
1470   ROM_LOAD32_BYTE( "offroadc.u21", 0x0800003, 0x100000, CRC(17794b56) SHA1(8bfd8f5b43056bfe7f62524bb8c3a8564a3a9413) )
1471   ROM_LOAD32_BYTE( "offroadc.u22", 0x0c00000, 0x100000, CRC(f2a6e622) SHA1(a7d7004e95b058124cc02e8073dab8fbed8813c5) )
1472   ROM_LOAD32_BYTE( "offroadc.u23", 0x0c00001, 0x100000, CRC(1cba6e20) SHA1(a7c9c58bfc4d26decb08979d83cccedb27528eb6) )
1473   ROM_LOAD32_BYTE( "offroadc.u24", 0x0c00002, 0x100000, CRC(fd3ce11f) SHA1(78c65267712488784bc6dc14eef98a90494a9553) )
1474   ROM_LOAD32_BYTE( "offroadc.u25", 0x0c00003, 0x100000, CRC(78f8e5db) SHA1(7ec2a5add27d66c43ba5cb7182554321007f5798) )
1475ROM_END
1476
1477
14321478ROM_START( offroadc4 ) /* Version 1.40, Mon 10-06-97 */
14331479   ROM_REGION16_LE( 0x1000000, "dcs", ROMREGION_ERASEFF )   /* sound data */
14341480   ROM_LOAD16_BYTE( "offroadc.u2",  0x000000, 0x80000, CRC(69976e9d) SHA1(63c886ac2563c43a10840f49f929f8613cd94de2) )
r12047r12048
16991745GAME( 1996, crusnwld13, crusnwld, midvunit, crusnwld, crusnwld, ROT0, "Midway", "Cruis'n World (rev L1.3)", GAME_SUPPORTS_SAVE )
17001746
17011747GAME( 1997, offroadc,  0,        midvunit, offroadc, offroadc, ROT0, "Midway", "Off Road Challenge (v1.63)", GAME_NOT_WORKING | GAME_SUPPORTS_SAVE )
1748GAME( 1997, offroadc5, offroadc, midvunit, offroadc, offroadc, ROT0, "Midway", "Off Road Challenge (v1.50)", GAME_NOT_WORKING | GAME_SUPPORTS_SAVE )
17021749GAME( 1997, offroadc4, offroadc, midvunit, offroadc, offroadc, ROT0, "Midway", "Off Road Challenge (v1.40)", GAME_NOT_WORKING | GAME_SUPPORTS_SAVE )
17031750GAME( 1997, offroadc3, offroadc, midvunit, offroadc, offroadc, ROT0, "Midway", "Off Road Challenge (v1.30)", GAME_NOT_WORKING | GAME_SUPPORTS_SAVE )
17041751GAME( 1997, offroadc1, offroadc, midvunit, offroadc, offroadc, ROT0, "Midway", "Off Road Challenge (v1.10)", GAME_NOT_WORKING | GAME_SUPPORTS_SAVE )
src/emu/cpu/i386/i386.c
r12047r12048
519519         i386_load_protected_mode_segment(cpustate,&desc);
520520         CPL = cpustate->CPL;  // current privilege level
521521         DPL = (desc.flags >> 5) & 0x03;  // descriptor privilege level
522//          RPL = segment & 0x03;  // requested privilege level
522//         RPL = segment & 0x03;  // requested privilege level
523523
524524         if((segment & ~0x07) == 0)
525525         {
r12047r12048
828828   }
829829
830830   /* For nested tasks, we write the outgoing task's selector to the back-link field of the new TSS,
831       and set the NT flag in the EFLAGS register */
831      and set the NT flag in the EFLAGS register */
832832   if(nested != 0)
833833   {
834834      WRITE16(cpustate,tss+0,old_task);
r12047r12048
943943   }
944944
945945   /* For nested tasks, we write the outgoing task's selector to the back-link field of the new TSS,
946       and set the NT flag in the EFLAGS register */
946      and set the NT flag in the EFLAGS register */
947947   if(nested != 0)
948948   {
949949      WRITE32(cpustate,tss+0,old_task);
src/emu/cpu/sh4/sh4.c
r12047r12048
2828#include "sh4regs.h"
2929#include "sh4comn.h"
3030
31//#define SHOW_AARON_BUG
32
3331#ifndef USE_SH4DRC
3432
3533CPU_DISASSEMBLE( sh4 );
r12047r12048
119117
120118INLINE UINT8 RB(sh4_state *sh4, offs_t A)
121119{
122   if (A >= 0xfe000000)
123      return sh4_internal_r(sh4->internal, ((A & 0x0fc) >> 2) | ((A & 0x1fe0000) >> 11), 0xff << ((A & 3)*8)) >> ((A & 3)*8);
124
125120   if (A >= 0xe0000000)
126121      return sh4->program->read_byte(A);
127122
r12047r12048
130125
131126INLINE UINT16 RW(sh4_state *sh4, offs_t A)
132127{
133   if (A >= 0xfe000000)
134      return sh4_internal_r(sh4->internal, ((A & 0x0fc) >> 2) | ((A & 0x1fe0000) >> 11), 0xffff << ((A & 2)*8)) >> ((A & 2)*8);
135
136128   if (A >= 0xe0000000)
137129      return sh4->program->read_word(A);
138130
r12047r12048
141133
142134INLINE UINT32 RL(sh4_state *sh4, offs_t A)
143135{
144   if (A >= 0xfe000000)
145      return sh4_internal_r(sh4->internal, ((A & 0x0fc) >> 2) | ((A & 0x1fe0000) >> 11), 0xffffffff);
146
147136   if (A >= 0xe0000000)
148137      return sh4->program->read_dword(A);
149138
150  return sh4->program->read_dword(A & AM);
139   return sh4->program->read_dword(A & AM);
151140}
152141
153142INLINE void WB(sh4_state *sh4, offs_t A, UINT8 V)
154143{
155   #ifndef SHOW_AARON_BUG
156   if (A >= 0xfe000000)
157   {
158      sh4_internal_w(sh4->internal, ((A & 0x0fc) >> 2) | ((A & 0x1fe0000) >> 11), V << ((A & 3)*8), 0xff << ((A & 3)*8));
159      return;
160   }
161   #endif
162
163144   if (A >= 0xe0000000)
164145   {
165146      sh4->program->write_byte(A,V);
r12047r12048
171152
172153INLINE void WW(sh4_state *sh4, offs_t A, UINT16 V)
173154{
174   #ifndef SHOW_AARON_BUG
175   if (A >= 0xfe000000)
176   {
177      sh4_internal_w(sh4->internal, ((A & 0x0fc) >> 2) | ((A & 0x1fe0000) >> 11), V << ((A & 2)*8), 0xffff << ((A & 2)*8));
178      return;
179   }
180   #endif
181
182155   if (A >= 0xe0000000)
183156   {
184157      sh4->program->write_word(A,V);
r12047r12048
190163
191164INLINE void WL(sh4_state *sh4, offs_t A, UINT32 V)
192165{
193   #ifndef SHOW_AARON_BUG
194   if (A >= 0xfe000000)
195   {
196      sh4_internal_w(sh4->internal, ((A & 0x0fc) >> 2) | ((A & 0x1fe0000) >> 11), V, 0xffffffff);
197      return;
198   }
199   #endif
200
201166   if (A >= 0xe0000000)
202167   {
203168      sh4->program->write_dword(A,V);
204169      return;
205170   }
206171
207/*  if (A >= 0x40000000)
208        return;*/
209
210172   sh4->program->write_dword(A & AM,V);
211173}
212174
r12047r12048
36163578ADDRESS_MAP_END
36173579#endif
36183580
3619#ifdef SHOW_AARON_BUG
3620static WRITE32_HANDLER(sh4_test_w)
3621{
3622   printf("offset = %08x, data = %08x, mask = %08x\n", offset, data, mem_mask);
3623}
3624#endif
3625
36263581/*When OC index mode is on (CCR.OIX = 1)*/
36273582static ADDRESS_MAP_START( sh4_internal_map, AS_PROGRAM, 64 )
36283583   AM_RANGE(0x1C000000, 0x1C000FFF) AM_RAM AM_MIRROR(0x01FFF000)
36293584   AM_RANGE(0x1E000000, 0x1E000FFF) AM_RAM AM_MIRROR(0x01FFF000)
36303585   AM_RANGE(0xE0000000, 0xE000003F) AM_RAM AM_MIRROR(0x03FFFFC0) // todo: store queues should be write only on DC's SH4, executing PREFM shouldn't cause an actual memory read access!
36313586   AM_RANGE(0xF6000000, 0xF7FFFFFF) AM_READWRITE(sh4_tlb_r,sh4_tlb_w)
3632#ifdef SHOW_AARON_BUG
3633   AM_RANGE(0xFE000000, 0xFFFFFFFF) AM_WRITE32(sh4_test_w, U64(0xffffffffffffffff))
3634#endif
3587   AM_RANGE(0xFE000000, 0xFFFFFFFF) AM_READWRITE32(sh4_internal_r, sh4_internal_w, U64(0xffffffffffffffff))
36353588ADDRESS_MAP_END
36363589
36373590
src/emu/cpu/sh4/sh4comn.h
r12047r12048
134134   UINT32            irq;            /* irq we're taking */
135135
136136   /* register mappings */
137   drcuml_parameter   regmap[16];                /* parameter to register mappings for all 16 integer registers */
137   uml::parameter   regmap[16];                /* parameter to register mappings for all 16 integer registers */
138138
139   drcuml_codehandle *   entry;                   /* entry point */
140   drcuml_codehandle *   read8;               /* read byte */
141   drcuml_codehandle *   write8;               /* write byte */
142   drcuml_codehandle *   read16;               /* read half */
143   drcuml_codehandle *   write16;                /* write half */
144   drcuml_codehandle *   read32;               /* read word */
145   drcuml_codehandle *   write32;                /* write word */
139   uml::code_handle *   entry;                   /* entry point */
140   uml::code_handle *   read8;               /* read byte */
141   uml::code_handle *   write8;               /* write byte */
142   uml::code_handle *   read16;               /* read half */
143   uml::code_handle *   write16;                /* write half */
144   uml::code_handle *   read32;               /* read word */
145   uml::code_handle *   write32;                /* write word */
146146
147   drcuml_codehandle *   interrupt;            /* interrupt */
148   drcuml_codehandle *   nocode;               /* nocode */
149   drcuml_codehandle *   out_of_cycles;            /* out of cycles exception handler */
147   uml::code_handle *   interrupt;            /* interrupt */
148   uml::code_handle *   nocode;               /* nocode */
149   uml::code_handle *   out_of_cycles;            /* out of cycles exception handler */
150150
151151   UINT32 prefadr;
152152   UINT32 target;
src/emu/cpu/sh4/sh4regs.h
r12047r12048
1515#define TRA    0x2008   /* FF000020 */
1616#define EXPEVT   0x2009   /* FF000024 */
1717#define INTEVT   0x200A   /* FF000028 */
18#define VERSION   0x200C   /* FF000030 */
1819#define PTEA   0x200D   /* FF000034 */
1920#define QACR0   0x200E   /* FF000038 */
2021#define QACR1   0x200F   /* FF00003C */
src/emu/cpu/sh4/sh4comn.c
r12047r12048
627627{
628628   sh4_state *sh4 = get_safe_token(&space->device());
629629   int a;
630   UINT32 addr = (offset << 2) + 0xfe000000;
631   offset = ((addr & 0xfc) >> 2) | ((addr & 0x1fe0000) >> 11);
632
630633   UINT32 old = sh4->m[offset];
631634   COMBINE_DATA(sh4->m+offset);
632635
633   //  logerror("sh4_internal_w:  Write %08x (%x), %08x @ %08x\n", 0xfe000000+((offset & 0x3fc0) << 11)+((offset & 0x3f) << 2), offset, data, mem_mask);
636//   printf("sh4_internal_w:  Write %08x (%x), %08x @ %08x\n", 0xfe000000+((offset & 0x3fc0) << 11)+((offset & 0x3f) << 2), offset, data, mem_mask);
634637
635638   switch( offset )
636639   {
r12047r12048
938941READ32_HANDLER( sh4_internal_r )
939942{
940943   sh4_state *sh4 = get_safe_token(&space->device());
941   //  logerror("sh4_internal_r:  Read %08x (%x) @ %08x\n", 0xfe000000+((offset & 0x3fc0) << 11)+((offset & 0x3f) << 2), offset, mem_mask);
944
945   UINT32 addr = (offset << 2) + 0xfe000000;
946   offset = ((addr & 0xfc) >> 2) | ((addr & 0x1fe0000) >> 11);
947
948//   printf("sh4_internal_r:  Read %08x (%x) @ %08x\n", 0xfe000000+((offset & 0x3fc0) << 11)+((offset & 0x3f) << 2), offset, mem_mask);
949
942950   switch( offset )
943951   {
952   case VERSION:
953      return 0x040205c1;   // this is what a real SH7750 in a Dreamcast returns - the later Naomi BIOSes check and care!
954      break;
955   case IPRD:
956      return 0x00000000;   // SH7750 ignores writes here and always returns zero
957      break;
944958   case RTCNT:
945959      if ((sh4->m[RTCSR] >> 3) & 7)
946960      { // activated
src/emu/emu.h
r12047r12048
6565#include "hash.h"
6666#include "fileio.h" // remove me once NVRAM is implemented as device
6767#include "delegate.h"
68#include "cothread.h"
6869
6970// memory and address spaces
7071#include "memory.h"
src/emu/schedule.c
r12047r12048
341341   m_executing_device(NULL),
342342   m_execute_list(NULL),
343343   m_basetime(attotime::zero),
344   m_cothread(co_active()),
344345   m_timer_list(NULL),
345346   m_timer_allocator(machine.respool()),
346347   m_callback_timer(NULL),
r12047r12048
483484                  m_executing_device = exec;
484485                  *exec->m_icountptr = exec->m_cycles_running;
485486                  if (!call_debugger)
486                     exec->execute_run();
487                     exec->run();
487488                  else
488489                  {
489490                     debugger_start_cpu_hook(&exec->device(), target);
490                     exec->execute_run();
491                     exec->run();
491492                     debugger_stop_cpu_hook(&exec->device());
492493                  }
493494
src/emu/schedule.h
r12047r12048
165165   void abort_timeslice();
166166   void trigger(int trigid, attotime after = attotime::zero);
167167   void boost_interleave(attotime timeslice_time, attotime boost_duration);
168   void make_active() { m_cothread.make_active(); }
168169
169170   // timers, specified by callback/name
170171   emu_timer *timer_alloc(timer_expired_delegate callback, void *ptr = NULL);
r12047r12048
209210   device_execute_interface *   m_executing_device;         // pointer to currently executing device
210211   device_execute_interface *   m_execute_list;            // list of devices to be executed
211212   attotime               m_basetime;               // global basetime; everything moves forward from here
213   cothread               m_cothread;               // core scheduler thread
212214
213215   // list of active timers
214216   emu_timer *               m_timer_list;            // head of the active list
src/emu/cothread.c
r0r12048
1/***************************************************************************
2
3    cothread.c
4
5    Class wrapper around buyy's cothread library.
6
7****************************************************************************
8
9    Copyright Aaron Giles
10    All rights reserved.
11
12    Redistribution and use in source and binary forms, with or without
13    modification, are permitted provided that the following conditions are
14    met:
15
16        * Redistributions of source code must retain the above copyright
17          notice, this list of conditions and the following disclaimer.
18        * Redistributions in binary form must reproduce the above copyright
19          notice, this list of conditions and the following disclaimer in
20          the documentation and/or other materials provided with the
21          distribution.
22        * Neither the name 'MAME' nor the names of its contributors may be
23          used to endorse or promote products derived from this software
24          without specific prior written permission.
25
26    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36    POSSIBILITY OF SUCH DAMAGE.
37
38***************************************************************************/
39
40#include "emu.h"
41#include "cothread/libco.h"
42
43
44//**************************************************************************
45//  GLOBAL VARIABLES
46//**************************************************************************
47
48// static members of the cothread class
49osd_lock *cothread::s_create_lock = osd_lock_alloc();
50cothread *cothread::s_create_cothread;
51
52
53
54//**************************************************************************
55//  COTHREAD
56//**************************************************************************
57
58//-------------------------------------------------
59//  cothread - constructor
60//-------------------------------------------------
61
62cothread::cothread(cothread_t existing_thread)
63   : m_cothread(existing_thread),
64     m_creator_cothread(NULL)
65{
66}
67
68cothread::cothread(cothread_entry_delegate entry, size_t stack)
69   : m_cothread(NULL),
70     m_creator_cothread(co_active()),
71     m_entry(entry)
72{
73   // due to the lack of input parameter to the entry function,
74   // all cothread creation is explicitly serialized
75   osd_lock_acquire(s_create_lock);
76   s_create_cothread = this;
77   m_cothread = co_create(stack, &cothread_entry);
78   co_switch(m_cothread);
79   osd_lock_release(s_create_lock);
80}
81
82
83//-------------------------------------------------
84//  cothread_entry - static entry point
85//-------------------------------------------------
86
87void cothread::cothread_entry()
88{
89   // on first call, retrieve the static pointer and return
90   cothread *thread = s_create_cothread;
91   co_switch(thread->m_creator_cothread);
92
93   // when actually swapped in later, call the entry point
94   thread->m_entry();
95}
src/emu/cothread.h
r0r12048
1/***************************************************************************
2
3    cothread.h
4
5    Class wrapper around byuu's cothread library.
6
7****************************************************************************
8
9    Copyright Aaron Giles
10    All rights reserved.
11
12    Redistribution and use in source and binary forms, with or without
13    modification, are permitted provided that the following conditions are
14    met:
15
16        * Redistributions of source code must retain the above copyright
17          notice, this list of conditions and the following disclaimer.
18        * Redistributions in binary form must reproduce the above copyright
19          notice, this list of conditions and the following disclaimer in
20          the documentation and/or other materials provided with the
21          distribution.
22        * Neither the name 'MAME' nor the names of its contributors may be
23          used to endorse or promote products derived from this software
24          without specific prior written permission.
25
26    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36    POSSIBILITY OF SUCH DAMAGE.
37
38***************************************************************************/
39
40#pragma once
41
42#ifndef __EMU_H__
43#error Dont include this file directly; include emu.h instead.
44#endif
45
46#ifndef __COTHREAD_H__
47#define __COTHREAD_H__
48
49#include "cothread/libco.h"
50
51
52//**************************************************************************
53//  TYPE DEFINITIONS
54//**************************************************************************
55
56// delegate that points to a thread's entry
57typedef delegate<void ()> cothread_entry_delegate;
58
59
60// ======================> cothread
61
62class cothread
63{
64public:
65   // construction/destruction
66   cothread(cothread_t existing_thread);
67   cothread(cothread_entry_delegate entry, size_t stack = 16384);
68   ~cothread() { if (m_creator_cothread != NULL) co_delete(m_cothread); }
69   
70   // switching
71   void make_active() { co_switch(m_cothread); }
72   
73private:
74   // internal helpers
75   static void cothread_entry();
76
77   // internal state
78   cothread_t          m_cothread;
79   cothread_t         m_creator_cothread;
80   cothread_entry_delegate m_entry;
81   
82   // static state
83   static osd_lock *    s_create_lock;
84   static cothread *    s_create_cothread;
85};
86
87
88#endif   // __COTHREAD_H__
src/emu/emu.mak
r12047r12048
5151   $(EMUOBJ)/cheat.o \
5252   $(EMUOBJ)/clifront.o \
5353   $(EMUOBJ)/config.o \
54   $(EMUOBJ)/cothread.o \
5455   $(EMUOBJ)/crsshair.o \
5556   $(EMUOBJ)/debugger.o \
5657   $(EMUOBJ)/delegate.o \
src/emu/machine/eeprom.c
r12047r12048
358358   if (m_reset_line != CLEAR_LINE)
359359   {
360360      if (m_serial_count)
361         logerror("EEPROM reset, buffer = %s\n",m_serial_buffer);
361         logerror("EEPROM %s reset, buffer = %s\n", tag(), m_serial_buffer);
362362
363363      m_serial_count = 0;
364364      m_sending = 0;
r12047r12048
385385               else
386386                  m_data_buffer = m_addrspace[0]->read_byte(m_read_address);
387387               m_clock_count = 0;
388logerror("EEPROM read %04x from address %02x\n",m_data_buffer,m_read_address);
388               logerror("EEPROM %s read %04x from address %02x\n", tag(), m_data_buffer, m_read_address);
389389            }
390390            m_data_buffer = (m_data_buffer << 1) | 1;
391391            m_clock_count++;
r12047r12048
406406
407407void eeprom_device::write(int bit)
408408{
409   LOG(("EEPROM write bit %d\n",bit));
409   LOG(("EEPROM %s write bit %d\n", tag(), bit));
410410
411411   if (m_serial_count >= SERIAL_BUFFER_LENGTH-1)
412412   {
413      logerror("error: EEPROM serial buffer overflow\n");
413      logerror("error: EEPROM %s serial buffer overflow\n", tag());
414414      return;
415415   }
416416
r12047r12048
436436      m_clock_count = 0;
437437      m_sending = 1;
438438      m_serial_count = 0;
439logerror("EEPROM read %04x from address %02x\n",m_data_buffer,address);
439      logerror("EEPROM %s read %04x from address %02x\n", tag(), m_data_buffer,address);
440440   }
441441   else if ( (m_serial_count > m_address_bits) &&
442442              command_match((char*)(m_serial_buffer),m_cmd_erase,strlen((char*)(m_serial_buffer))-m_address_bits) )
r12047r12048
449449         address <<= 1;
450450         if (m_serial_buffer[i] == '1') address |= 1;
451451      }
452logerror("EEPROM erase address %02x\n",address);
452      logerror("EEPROM %s erase address %02x\n", tag(), address);
453453      if (m_locked == 0)
454454      {
455455         if (m_data_bits == 16)
r12047r12048
458458            m_addrspace[0]->write_byte(address, 0x00);
459459      }
460460      else
461logerror("Error: EEPROM is m_locked\n");
461         logerror("Error: EEPROM %s is locked\n", tag());
462462      m_serial_count = 0;
463463   }
464464   else if ( (m_serial_count > (m_address_bits + m_data_bits)) &&
r12047r12048
478478         data <<= 1;
479479         if (m_serial_buffer[i] == '1') data |= 1;
480480      }
481logerror("EEPROM write %04x to address %02x\n",data,address);
481      logerror("EEPROM %s write %04x to address %02x\n", tag(), data, address);
482482      if (m_locked == 0)
483483      {
484484         if (m_data_bits == 16)
r12047r12048
487487            m_addrspace[0]->write_byte(address, data);
488488      }
489489      else
490logerror("Error: EEPROM is m_locked\n");
490         logerror("Error: EEPROM %s is locked\n", tag());
491491      m_serial_count = 0;
492492   }
493493   else if ( command_match((char*)(m_serial_buffer),m_cmd_lock,strlen((char*)(m_serial_buffer))) )
494494   {
495logerror("EEPROM lock\n");
495      logerror("EEPROM %s lock\n", tag());
496496      m_locked = 1;
497497      m_serial_count = 0;
498498   }
499499   else if ( command_match((char*)(m_serial_buffer),m_cmd_unlock,strlen((char*)(m_serial_buffer))) )
500500   {
501logerror("EEPROM unlock\n");
501      logerror("EEPROM %s unlock\n", tag());
502502      m_locked = 0;
503503      m_serial_count = 0;
504504   }
src/emu/diexec.c
r12047r12048
7373
7474device_execute_interface::device_execute_interface(const machine_config &mconfig, device_t &device)
7575   : device_interface(device),
76     m_cothread(cothread_entry_delegate(FUNC(device_execute_interface::run_thread_wrapper), this)),
7677     m_disabled(false),
7778     m_vblank_interrupt(NULL),
7879     m_vblank_interrupts_per_frame(0),
r12047r12048
371372
372373
373374//-------------------------------------------------
375//  run_thread_wrapper - wrapper for our cothread
376//  which just calls run and then returns to the
377//  scheduler thread, over and over
378//-------------------------------------------------
379
380void device_execute_interface::run_thread_wrapper()
381{
382   // loop infinitely
383   device_scheduler &scheduler = device().machine().scheduler();
384   while (1)
385    {
386       // call the classic run function, then swap back to the scheduler's thread
387       execute_run();
388        scheduler.make_active();
389    }   
390}
391
392
393//-------------------------------------------------
374394//  execute_clocks_to_cycles - convert the number
375395//  of clocks to cycles, rounding down if necessary
376396//-------------------------------------------------
src/emu/diexec.h
r12047r12048
199199   UINT64 total_cycles() const;
200200
201201   // required operation overrides
202   void run() { execute_run(); }
202   void run() { m_cothread.make_active(); }
203203
204204protected:
205   // internal helpers
206   void run_thread_wrapper();
207
205208   // clock and cycle information getters
206209   virtual UINT64 execute_clocks_to_cycles(UINT64 clocks) const;
207210   virtual UINT64 execute_cycles_to_clocks(UINT64 cycles) const;
r12047r12048
258261      static void static_empty_event_queue(running_machine &machine, void *ptr, int param);
259262      void empty_event_queue();
260263   };
264   
265   // internal state
266   cothread            m_cothread;               // thread used for execution
261267
262268   // configuration
263269   bool               m_disabled;               // disabled from executing?
src/lib/cothread/test/test.h
r0r12048
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <time.h>
5
6#include "../libco.h"
src/lib/cothread/test/test_timing.cpp
r0r12048
1#include "test.h"
2enum { Iterations = 500000000 };
3 
4namespace thread {
5  cothread_t x;
6  cothread_t y;
7  volatile int counter;
8}
9 
10void co_timingtest() {
11  for(;;) {
12    thread::counter++;
13    co_switch(thread::x);
14  }
15}
16 
17void sub_timingtest() {
18  thread::counter++;
19}
20 
21int main() {
22  printf("context-switching timing test\n\n");
23  time_t start, end;
24  int i, t1, t2;
25 
26  start = clock();
27  for(thread::counter = 0, i = 0; i < Iterations; i++) {
28    sub_timingtest();
29  }
30  end = clock();
31 
32  t1 = (int)difftime(end, start);
33  printf("%2.3f seconds per  50 million subroutine calls (%d iterations)\n", (float)t1 / CLOCKS_PER_SEC, thread::counter);
34 
35  thread::x = co_active();
36  thread::y = co_create(65536, co_timingtest);
37 
38  start = clock();
39  for(thread::counter = 0, i = 0; i < Iterations; i++) {
40    co_switch(thread::y);
41  }
42  end = clock();
43 
44  co_delete(thread::y);
45 
46  t2 = (int)difftime(end, start);
47  printf("%2.3f seconds per 100 million co_switch  calls (%d iterations)\n", (float)t2 / CLOCKS_PER_SEC, thread::counter);
48 
49  printf("co_switch skew = %fx\n\n", (double)t2 / (double)t1);
50  return 0;
51}
52 
src/lib/cothread/test/cc.bat
r0r12048
1mingw32-gcc -O3 -fomit-frame-pointer -o libco.o -c ../libco.c
2mingw32-g++ -O3 -fomit-frame-pointer -c test_timing.cpp
3mingw32-g++ -O3 -fomit-frame-pointer test_timing.o libco.o -o test_timing.exe
4@del *.o
src/lib/cothread/test/test_args.cpp
r0r12048
1/*****
2 * cothread parameterized function example
3 *****
4 * entry point to cothreads cannot take arguments.
5 * this is due to portability issues: each processor,
6 * operating system, programming language and compiler
7 * can use different parameter passing methods, so
8 * arguments to the cothread entry points were omitted.
9 *
10 * however, the behavior can easily be simulated by use
11 * of a specialized co_switch to set global parameters to
12 * be used as function arguments.
13 *
14 * in this way, with a bit of extra red tape, one gains
15 * even more flexibility than would be possible with a
16 * fixed argument list entry point, such as void (*)(void*),
17 * as any number of arguments can be used.
18 *
19 * this also eliminates race conditions where a pointer
20 * passed to co_create may have changed or become invalidated
21 * before call to co_switch, as said pointer would now be set
22 * when calling co_switch, instead.
23 *****/
24 
25#include "test.h"
26 
27cothread_t thread[3];
28 
29namespace co_arg {
30  int param_x;
31  int param_y;
32};
33 
34//one could also call this co_init or somesuch if they preferred ...
35void co_switch(cothread_t thread, int param_x, int param_y) {
36  co_arg::param_x = param_x;
37  co_arg::param_y = param_y;
38  co_switch(thread);
39}
40 
41void co_entrypoint() {
42int param_x = co_arg::param_x;
43int param_y = co_arg::param_y;
44  printf("co_entrypoint(%d, %d)\n", param_x, param_y);
45  co_switch(thread[0]);
46 
47//co_arg::param_x will change here (due to co_switch(cothread_t, int, int) call changing values),
48//however, param_x and param_y will persist as they are thread local
49 
50  printf("co_entrypoint(%d, %d)\n", param_x, param_y);
51  co_switch(thread[0]);
52  throw;
53}
54 
55int main() {
56  printf("cothread parameterized function example\n\n");
57 
58  thread[0] = co_active();
59  thread[1] = co_create(65536, co_entrypoint);
60  thread[2] = co_create(65536, co_entrypoint);
61 
62//use specialized co_switch(cothread_t, int, int) for initial co_switch call
63  co_switch(thread[1], 1, 2);
64  co_switch(thread[2], 4, 8);
65 
66//after first call, entry point arguments have been initialized, standard
67//co_switch(cothread_t) can be used from now on
68  co_switch(thread[2]);
69  co_switch(thread[1]);
70 
71  printf("\ndone\n");
72#if defined(_MSC_VER) || defined(__DJGPP__)
73  getch();
74#endif
75  return 0;
76}
src/lib/cothread/test/cc.sh
r0r12048
1clear
2g++ -O3 -fomit-frame-pointer -c test_timing.cpp
3gcc -O3 -fomit-frame-pointer -o libco.o -c ../libco.c
4g++ -O3 -fomit-frame-pointer test_timing.o libco.o -o test_timing
5rm -f *.o
src/lib/cothread/ppc.c
r0r12048
1/*
2  libco.ppc (2010-10-17)
3  author: blargg
4  license: public domain
5*/
6
7/* PowerPC 32/64 using embedded or external asm, with optional
8floating-point and AltiVec save/restore */
9
10#define LIBCO_C
11#include "libco.h"
12#include <stdlib.h>
13#include <stdint.h>
14#include <string.h>
15
16#define LIBCO_MPROTECT (__unix__ && !LIBCO_PPC_ASM)
17
18#if LIBCO_MPROTECT
19   #include <unistd.h>
20   #include <sys/mman.h>
21#endif
22
23/* State format (offsets in 32-bit words)
24
25+0   Pointer to swap code
26   Rest of function descriptor for entry function
27+8   PC
28+10   SP
29   Special regs
30   GPRs
31   FPRs
32   VRs
33   stack
34*/
35
36enum { state_size  = 1024 };
37enum { above_stack = 2048 };
38enum { stack_align = 256  };
39
40static thread_local cothread_t co_active_handle = 0;
41
42/**** Determine environment ****/
43
44#define LIBCO_PPC64 (_ARCH_PPC64 || __PPC64__ || __ppc64__ || __powerpc64__)
45
46/* Whether function calls are indirect through a descriptor,
47or are directly to function */
48#ifndef LIBCO_PPCDESC
49   #if !_CALL_SYSV && (_CALL_AIX || _CALL_AIXDESC || LIBCO_PPC64)
50      #define LIBCO_PPCDESC 1
51   #endif
52#endif
53
54#ifdef LIBCO_PPC_ASM
55
56   #ifdef __cplusplus
57      extern "C"
58   #endif
59   
60   /* Swap code is in ppc.S */
61   void co_swap_asm( cothread_t, cothread_t );
62   #define CO_SWAP_ASM( x, y ) co_swap_asm( x, y )
63
64#else
65
66/* Swap code is here in array. Please leave dieassembly comments,
67as they make it easy to see what it does, and reorder instructions
68if one wants to see whether that improves performance. */
69static const uint32_t libco_ppc_code [] = {
70#if LIBCO_PPC64
71    0x7d000026, /* mfcr    r8 */
72    0xf8240028, /* std     r1,40(r4) */
73    0x7d2802a6, /* mflr    r9 */
74    0xf9c40048, /* std     r14,72(r4) */
75    0xf9e40050, /* std     r15,80(r4) */
76    0xfa040058, /* std     r16,88(r4) */
77    0xfa240060, /* std     r17,96(r4) */
78    0xfa440068, /* std     r18,104(r4) */
79    0xfa640070, /* std     r19,112(r4) */
80    0xfa840078, /* std     r20,120(r4) */
81    0xfaa40080, /* std     r21,128(r4) */
82    0xfac40088, /* std     r22,136(r4) */
83    0xfae40090, /* std     r23,144(r4) */
84    0xfb040098, /* std     r24,152(r4) */
85    0xfb2400a0, /* std     r25,160(r4) */
86    0xfb4400a8, /* std     r26,168(r4) */
87    0xfb6400b0, /* std     r27,176(r4) */
88    0xfb8400b8, /* std     r28,184(r4) */
89    0xfba400c0, /* std     r29,192(r4) */
90    0xfbc400c8, /* std     r30,200(r4) */
91    0xfbe400d0, /* std     r31,208(r4) */
92    0xf9240020, /* std     r9,32(r4) */
93    0xe8e30020, /* ld      r7,32(r3) */
94    0xe8230028, /* ld      r1,40(r3) */
95    0x48000009, /* bl      1 */
96   0x7fe00008, /* trap */
97    0x91040030,/*1:stw     r8,48(r4) */
98    0x80c30030, /* lwz     r6,48(r3) */
99    0x7ce903a6, /* mtctr   r7 */
100    0xe9c30048, /* ld      r14,72(r3) */
101    0xe9e30050, /* ld      r15,80(r3) */
102    0xea030058, /* ld      r16,88(r3) */
103    0xea230060, /* ld      r17,96(r3) */
104    0xea430068, /* ld      r18,104(r3) */
105    0xea630070, /* ld      r19,112(r3) */
106    0xea830078, /* ld      r20,120(r3) */
107    0xeaa30080, /* ld      r21,128(r3) */
108    0xeac30088, /* ld      r22,136(r3) */
109    0xeae30090, /* ld      r23,144(r3) */
110    0xeb030098, /* ld      r24,152(r3) */
111    0xeb2300a0, /* ld      r25,160(r3) */
112    0xeb4300a8, /* ld      r26,168(r3) */
113    0xeb6300b0, /* ld      r27,176(r3) */
114    0xeb8300b8, /* ld      r28,184(r3) */
115    0xeba300c0, /* ld      r29,192(r3) */
116    0xebc300c8, /* ld      r30,200(r3) */
117    0xebe300d0, /* ld      r31,208(r3) */
118    0x7ccff120, /* mtcr    r6 */
119#else
120   0x7d000026, /* mfcr    r8 */
121   0x90240028, /* stw     r1,40(r4) */
122   0x7d2802a6, /* mflr    r9 */
123   0x91a4003c, /* stw     r13,60(r4) */
124   0x91c40040, /* stw     r14,64(r4) */
125   0x91e40044, /* stw     r15,68(r4) */
126   0x92040048, /* stw     r16,72(r4) */
127   0x9224004c, /* stw     r17,76(r4) */
128   0x92440050, /* stw     r18,80(r4) */
129   0x92640054, /* stw     r19,84(r4) */
130   0x92840058, /* stw     r20,88(r4) */
131   0x92a4005c, /* stw     r21,92(r4) */
132   0x92c40060, /* stw     r22,96(r4) */
133   0x92e40064, /* stw     r23,100(r4) */
134   0x93040068, /* stw     r24,104(r4) */
135   0x9324006c, /* stw     r25,108(r4) */
136   0x93440070, /* stw     r26,112(r4) */
137   0x93640074, /* stw     r27,116(r4) */
138   0x93840078, /* stw     r28,120(r4) */
139   0x93a4007c, /* stw     r29,124(r4) */
140   0x93c40080, /* stw     r30,128(r4) */
141   0x93e40084, /* stw     r31,132(r4) */
142   0x91240020, /* stw     r9,32(r4) */
143   0x80e30020, /* lwz     r7,32(r3) */
144   0x80230028, /* lwz     r1,40(r3) */
145   0x48000009, /* bl      1 */
146   0x7fe00008, /* trap */
147   0x91040030,/*1:stw     r8,48(r4) */
148   0x80c30030, /* lwz     r6,48(r3) */
149   0x7ce903a6, /* mtctr   r7 */
150   0x81a3003c, /* lwz     r13,60(r3) */
151   0x81c30040, /* lwz     r14,64(r3) */
152   0x81e30044, /* lwz     r15,68(r3) */
153   0x82030048, /* lwz     r16,72(r3) */
154   0x8223004c, /* lwz     r17,76(r3) */
155   0x82430050, /* lwz     r18,80(r3) */
156   0x82630054, /* lwz     r19,84(r3) */
157   0x82830058, /* lwz     r20,88(r3) */
158   0x82a3005c, /* lwz     r21,92(r3) */
159   0x82c30060, /* lwz     r22,96(r3) */
160   0x82e30064, /* lwz     r23,100(r3) */
161   0x83030068, /* lwz     r24,104(r3) */
162   0x8323006c, /* lwz     r25,108(r3) */
163   0x83430070, /* lwz     r26,112(r3) */
164   0x83630074, /* lwz     r27,116(r3) */
165   0x83830078, /* lwz     r28,120(r3) */
166   0x83a3007c, /* lwz     r29,124(r3) */
167   0x83c30080, /* lwz     r30,128(r3) */
168   0x83e30084, /* lwz     r31,132(r3) */
169   0x7ccff120, /* mtcr    r6 */
170#endif
171
172#ifndef LIBCO_PPC_NOFP
173   0xd9c400e0, /* stfd    f14,224(r4) */
174   0xd9e400e8, /* stfd    f15,232(r4) */
175   0xda0400f0, /* stfd    f16,240(r4) */
176   0xda2400f8, /* stfd    f17,248(r4) */
177   0xda440100, /* stfd    f18,256(r4) */
178   0xda640108, /* stfd    f19,264(r4) */
179   0xda840110, /* stfd    f20,272(r4) */
180   0xdaa40118, /* stfd    f21,280(r4) */
181   0xdac40120, /* stfd    f22,288(r4) */
182   0xdae40128, /* stfd    f23,296(r4) */
183   0xdb040130, /* stfd    f24,304(r4) */
184   0xdb240138, /* stfd    f25,312(r4) */
185   0xdb440140, /* stfd    f26,320(r4) */
186   0xdb640148, /* stfd    f27,328(r4) */
187   0xdb840150, /* stfd    f28,336(r4) */
188   0xdba40158, /* stfd    f29,344(r4) */
189   0xdbc40160, /* stfd    f30,352(r4) */
190   0xdbe40168, /* stfd    f31,360(r4) */
191   0xc9c300e0, /* lfd     f14,224(r3) */
192   0xc9e300e8, /* lfd     f15,232(r3) */
193   0xca0300f0, /* lfd     f16,240(r3) */
194   0xca2300f8, /* lfd     f17,248(r3) */
195   0xca430100, /* lfd     f18,256(r3) */
196   0xca630108, /* lfd     f19,264(r3) */
197   0xca830110, /* lfd     f20,272(r3) */
198   0xcaa30118, /* lfd     f21,280(r3) */
199   0xcac30120, /* lfd     f22,288(r3) */
200   0xcae30128, /* lfd     f23,296(r3) */
201   0xcb030130, /* lfd     f24,304(r3) */
202   0xcb230138, /* lfd     f25,312(r3) */
203   0xcb430140, /* lfd     f26,320(r3) */
204   0xcb630148, /* lfd     f27,328(r3) */
205   0xcb830150, /* lfd     f28,336(r3) */
206   0xcba30158, /* lfd     f29,344(r3) */
207   0xcbc30160, /* lfd     f30,352(r3) */
208   0xcbe30168, /* lfd     f31,360(r3) */
209#endif
210
211#ifdef __ALTIVEC__
212   0x7ca042a6, /* mfvrsave r5 */
213   0x39040180, /* addi    r8,r4,384 */
214   0x39240190, /* addi    r9,r4,400 */
215   0x70a00fff, /* andi.   r0,r5,4095 */
216   0x90a40034, /* stw     r5,52(r4) */
217   0x4182005c, /* beq-    2 */
218   0x7e8041ce, /* stvx    v20,r0,r8 */
219   0x39080020, /* addi    r8,r8,32 */
220   0x7ea049ce, /* stvx    v21,r0,r9 */
221   0x39290020, /* addi    r9,r9,32 */
222   0x7ec041ce, /* stvx    v22,r0,r8 */
223   0x39080020, /* addi    r8,r8,32 */
224   0x7ee049ce, /* stvx    v23,r0,r9 */
225   0x39290020, /* addi    r9,r9,32 */
226   0x7f0041ce, /* stvx    v24,r0,r8 */
227   0x39080020, /* addi    r8,r8,32 */
228   0x7f2049ce, /* stvx    v25,r0,r9 */
229   0x39290020, /* addi    r9,r9,32 */
230   0x7f4041ce, /* stvx    v26,r0,r8 */
231   0x39080020, /* addi    r8,r8,32 */
232   0x7f6049ce, /* stvx    v27,r0,r9 */
233   0x39290020, /* addi    r9,r9,32 */
234   0x7f8041ce, /* stvx    v28,r0,r8 */
235   0x39080020, /* addi    r8,r8,32 */
236   0x7fa049ce, /* stvx    v29,r0,r9 */
237   0x39290020, /* addi    r9,r9,32 */
238   0x7fc041ce, /* stvx    v30,r0,r8 */
239   0x7fe049ce, /* stvx    v31,r0,r9 */
240   0x80a30034,/*2:lwz     r5,52(r3) */
241   0x39030180, /* addi    r8,r3,384 */
242   0x39230190, /* addi    r9,r3,400 */
243   0x70a00fff, /* andi.   r0,r5,4095 */
244   0x7ca043a6, /* mtvrsave r5 */
245   0x4d820420, /* beqctr   */
246   0x7e8040ce, /* lvx     v20,r0,r8 */
247   0x39080020, /* addi    r8,r8,32 */
248   0x7ea048ce, /* lvx     v21,r0,r9 */
249   0x39290020, /* addi    r9,r9,32 */
250   0x7ec040ce, /* lvx     v22,r0,r8 */
251   0x39080020, /* addi    r8,r8,32 */
252   0x7ee048ce, /* lvx     v23,r0,r9 */
253   0x39290020, /* addi    r9,r9,32 */
254   0x7f0040ce, /* lvx     v24,r0,r8 */
255   0x39080020, /* addi    r8,r8,32 */
256   0x7f2048ce, /* lvx     v25,r0,r9 */
257   0x39290020, /* addi    r9,r9,32 */
258   0x7f4040ce, /* lvx     v26,r0,r8 */
259   0x39080020, /* addi    r8,r8,32 */
260   0x7f6048ce, /* lvx     v27,r0,r9 */
261   0x39290020, /* addi    r9,r9,32 */
262   0x7f8040ce, /* lvx     v28,r0,r8 */
263   0x39080020, /* addi    r8,r8,32 */
264   0x7fa048ce, /* lvx     v29,r0,r9 */
265   0x39290020, /* addi    r9,r9,32 */
266   0x7fc040ce, /* lvx     v30,r0,r8 */
267   0x7fe048ce, /* lvx     v31,r0,r9 */
268#endif
269
270   0x4e800420, /* bctr */
271};
272
273   #if LIBCO_PPCDESC
274      /* Function call goes through indirect descriptor */
275      #define CO_SWAP_ASM( x, y ) \
276         ((void (*)( cothread_t, cothread_t )) (uintptr_t) x)( x, y )
277   #else
278      /* Function call goes directly to code */
279      #define CO_SWAP_ASM( x, y ) \
280         ((void (*)( cothread_t, cothread_t )) (uintptr_t) libco_ppc_code)( x, y )
281   #endif
282
283#endif
284
285static uint32_t* co_create_( unsigned size, uintptr_t entry )
286{
287   uint32_t* t = (uint32_t*) malloc( size );
288   
289   (void) entry;
290   
291   #if LIBCO_PPCDESC
292      if ( t )
293      {
294         /* Copy entry's descriptor */
295         memcpy( t, (void*) entry, sizeof (void*) * 3 );
296         
297         /* Set function pointer to swap routine */
298         #ifdef LIBCO_PPC_ASM
299            *(const void**) t = *(void**) &co_swap_asm;
300         #else
301            *(const void**) t = libco_ppc_code;
302         #endif
303      }
304   #endif
305   
306   return t;
307}
308
309cothread_t co_create( unsigned int size, void (*entry_)( void ) )
310{
311   uintptr_t entry = (uintptr_t) entry_;
312   uint32_t* t = NULL;
313   
314   /* Be sure main thread was successfully allocated */
315   if ( co_active() )
316   {
317      size += state_size + above_stack + stack_align;
318      t = co_create_( size, entry );
319   }
320   
321   if ( t )
322   {
323      uintptr_t sp;
324      int shift;
325     
326      /* Save current registers into new thread, so that any special ones will
327      have proper values when thread is begun */
328      CO_SWAP_ASM( t, t );
329     
330      #if LIBCO_PPCDESC
331         /* Get real address */
332         entry = (uintptr_t) *(void**) entry;
333      #endif
334     
335      /* Put stack near end of block, and align */
336      sp = (uintptr_t) t + size - above_stack;
337      sp -= sp % stack_align;
338     
339      /* On PPC32, we save and restore GPRs as 32 bits. For PPC64, we
340      save and restore them as 64 bits, regardless of the size the ABI
341      uses. So, we manually write pointers at the proper size. We always
342      save and restore at the same address, and since PPC is big-endian,
343      we must put the low byte first on PPC32. */
344     
345      /* If uintptr_t is 32 bits, >>32 is undefined behavior, so we do two shifts
346      and don't have to care how many bits uintptr_t is. */
347      #if LIBCO_PPC64
348         shift = 16;
349      #else
350         shift = 0;
351      #endif
352     
353      /* Set up so entry will be called on next swap */
354      t [8] = (uint32_t) (entry >> shift >> shift);
355      t [9] = (uint32_t) entry;
356     
357      t [10] = (uint32_t) (sp >> shift >> shift);
358      t [11] = (uint32_t) sp;
359   }
360   
361   return t;
362}
363
364void co_delete( cothread_t t )
365{
366   free( t );
367}
368
369static void co_init_( void )
370{
371   #if LIBCO_MPROTECT
372      /* TODO: pre- and post-pad PPC code so that this doesn't make other
373      data executable and writable */
374      long page_size = sysconf( _SC_PAGESIZE );
375      if ( page_size > 0 )
376      {
377         uintptr_t align = page_size;
378         uintptr_t begin = (uintptr_t) libco_ppc_code;
379         uintptr_t end   = begin + sizeof libco_ppc_code;
380         
381         /* Align beginning and end */
382         end   += align - 1;
383         end   -= end   % align;
384         begin -= begin % align;
385         
386         mprotect( (void*) begin, end - begin, PROT_READ | PROT_WRITE | PROT_EXEC );
387      }
388   #endif
389   
390   co_active_handle = co_create_( state_size, (uintptr_t) &co_switch );
391}
392
393cothread_t co_active()
394{
395   if ( !co_active_handle )
396      co_init_();
397   
398   return co_active_handle;
399}
400
401void co_switch( cothread_t t )
402{
403   cothread_t old = co_active_handle;
404   co_active_handle = t;
405   
406   CO_SWAP_ASM( t, old );
407}
src/lib/cothread/sjlj.c
r0r12048
1/*
2  libco.sjlj (2008-01-28)
3  author: Nach
4  license: public domain
5*/
6
7/*
8 * Note this was designed for UNIX systems. Based on ideas expressed in a paper
9 * by Ralf Engelschall.
10 * For SJLJ on other systems, one would want to rewrite springboard() and
11 * co_create() and hack the jmb_buf stack pointer.
12 */
13
14#define LIBCO_C
15#include "libco.h"
16#include <stdlib.h>
17#include <signal.h>
18#include <setjmp.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24typedef struct {
25  sigjmp_buf context;
26  void (*coentry)(void);
27  void *stack;
28} cothread_struct;
29
30static thread_local cothread_struct co_primary;
31static thread_local cothread_struct *creating, *co_running = 0;
32
33static void springboard(int ignored) {
34  if(sigsetjmp(creating->context, 0)) {
35    co_running->coentry();
36  }
37}
38
39cothread_t co_active() {
40  if(!co_running) co_running = &co_primary;
41  return (cothread_t)co_running;
42}
43
44cothread_t co_create(unsigned int size, void (*coentry)(void)) {
45  if(!co_running) co_running = &co_primary;
46
47  cothread_struct *thread = (cothread_struct*)malloc(sizeof(cothread_struct));
48  if(thread) {
49    struct sigaction handler;
50    struct sigaction old_handler;
51
52    stack_t stack;
53    stack_t old_stack;
54
55    thread->coentry = thread->stack = 0;
56
57    stack.ss_flags = 0;
58    stack.ss_size = size;
59    thread->stack = stack.ss_sp = malloc(size);
60    if(stack.ss_sp && !sigaltstack(&stack, &old_stack)) {
61      handler.sa_handler = springboard;
62      handler.sa_flags = SA_ONSTACK;
63      sigemptyset(&handler.sa_mask);
64      creating = thread;
65
66      if(!sigaction(SIGUSR1, &handler, &old_handler)) {
67        if(!raise(SIGUSR1)) {
68          thread->coentry = coentry;
69        }
70        sigaltstack(&old_stack, 0);
71        sigaction(SIGUSR1, &old_handler, 0);
72      }
73    }
74
75    if(thread->coentry != coentry) {
76      co_delete(thread);
77      thread = 0;
78    }
79  }
80
81  return (cothread_t)thread;
82}
83
84void co_delete(cothread_t cothread) {
85  if(cothread) {
86    if(((cothread_struct*)cothread)->stack) {
87      free(((cothread_struct*)cothread)->stack);
88    }
89    free(cothread);
90  }
91}
92
93void co_switch(cothread_t cothread) {
94  if(!sigsetjmp(co_running->context, 0)) {
95    co_running = (cothread_struct*)cothread;
96    siglongjmp(co_running->context, 1);
97  }
98}
99
100#ifdef __cplusplus
101}
102#endif
src/lib/cothread/doc/x86.asm
r0r12048
1; fastcall ABI:
2; return = eax
3; arguments = ecx,edx
4; non-volatile registers = ebp,esi,edi,ebx
5 
6co_swap_fastcall(to = ecx, from = edx):
7  mov [edx],esp
8  mov esp,[ecx]
9  pop eax
10 
11  mov [edx+ 4],ebp
12  mov [edx+ 8],esi
13  mov [edx+12],edi
14  mov [edx+16],ebx
15 
16  mov ebp,[ecx+ 4]
17  mov esi,[ecx+ 8]
18  mov edi,[ecx+12]
19  mov ebx,[ecx+16]
20 
21  jmp eax
src/lib/cothread/doc/style.css
r0r12048
1body {
2  background: #333;
3  color: #fff;
4}
5 
6code {
7  background: #444;
8}
src/lib/cothread/doc/usage.html
r0r12048
1<html>
2<head>
3  <title></title>
4  <link href="style.css" rel="stylesheet" type="text/css">
5</head>
6<body>
7 
8<b>License:</b><br/><br/>
9libco is released to the public domain.
10<hr/>
11 
12<b>Contact:</b><br/><br/>
13At present, you may contact me at setsunakun0 at hotmail dot com.<br/>
14I am interested in knowing of any projects that make use of this library,
15though this is only a courtesy.
16<hr/>
17 
18<b>Foreword:</b><br/><br/>
19libco is a cross-platform, public domain implementation of
20cooperative-multithreading; a feature that is sorely lacking
21from the ISO C/C++ standard.<br/>
22The library is designed for maximum speed and portability, and
23not for safety or features. If safety or extra functionality is desired,
24a wrapper API can easily be written to encapsulate all library functions.<br/>
25Behavior of executing operations that are listed as not permitted
26below result in undefined behavior. They may work anyway, they
27may cause undesired / unknown behavior, or they may crash the
28program entirely.<br/>
29The goal of this library was to simplify the base API as much as possible,
30implementing only that which cannot be implemented using pure C. Additional
31functionality after this would only complicate ports of this library to new
32platforms.
33<hr/>
34 
35<b>Porting:</b><br/><br/>
36This document is included as a reference for porting libco. Please submit any
37ports you create to me, so that libco can become more useful. Please note that
38since libco is public domain, you must submit your code as a work of the
39public domain in order for it to be included in the official distribution.
40Full credit will be given in the source code of the official release. Please
41do not bother submitting code to me under any other license -- including GPL,
42LGPL, BSD or CC -- I am not interested in creating a library with multiple
43different licenses depending on which targets are used.
44<hr/>
45 
46<b>Synopsis:</b><br/><br/>
47<code>
48typedef void* cothread_t;<br/>
49<br/>
50cothread_t co_active();<br/>
51cothread_t co_create(unsigned int heapsize, void (*coentry)(void));<br/>
52void &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;co_delete(cothread_t cothread);<br/>
53void &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;co_switch(cothread_t cothread);<br/>
54</code>
55<hr/>
56 
57<b>Usage:</b>
58<hr/>
59 
60<code>typedef void* cothread_t;</code><br/><br/>
61Handle to cothread.<br/>
62Handle must be of type void*.<br/>
63A value of null (0) indicates an uninitialized or invalid
64handle, whereas a non-zero value indicates a valid handle.
65<hr/>
66 
67<code>cothread_t co_active();</code><br/><br/>
68Return handle to current cothread. Always returns a valid handle, even when
69called from the main program thread.
70<hr/>
71 
72<code>cothread_t co_create(unsigned int heapsize, void (*coentry)(void));</code><br/><br/>
73Create new cothread.<br/>
74Heapsize is the amount of memory allocated for the cothread stack, specified
75in bytes. This is unfortunately impossible to make fully portable. It is
76recommended to specify sizes using `n * sizeof(void*)'. It is better to err
77on the side of caution and allocate more memory than will be needed to ensure
78compatibility with other platforms, within reason. A typical heapsize for a
7932-bit architecture is ~1MB.<br/>
80When the new cothread is first called, program execution jumps to coentry.
81This function does not take any arguments, due to portability issues with
82passing function arguments. However, arguments can be simulated by the use
83of global variables, which can be set before the first call to each cothread.<br/>
84coentry() must not return, and should end with an appropriate co_switch()
85statement. Behavior is undefined if entry point returns normally.<br/>
86Library is responsible for allocating cothread stack memory, to free
87the user from needing to allocate special memory capable of being used
88as program stack memory on platforms where this is required.<br/>
89User is always responsible for deleting cothreads with co_delete().<br/>
90Return value of null (0) indicates cothread creation failed.
91<hr/>
92 
93<code>void co_delete(cothread_t cothread);</code><br/><br/>
94Delete specified cothread.<br/>
95Null (0) or invalid cothread handle is not allowed.<br/>
96Passing handle of active cothread to this function is not allowed.<br/>
97Passing handle of primary cothread is not allowed.
98<hr/>
99 
100<code>void co_switch(cothread_t cothread);</code><br/><br/>
101Switch to specified cothread.<br/>
102Null (0) or invalid cothread handle is not allowed.<br/>
103Passing handle of active cothread to this function is not allowed.
104<hr/>
105 
106</body>
107</html>
src/lib/cothread/doc/amd64.asm
r0r12048
1; SystemV ABI:
2; return = rax
3; arguments = rdi,rsi,rdx,rcx,r8,r9
4; non-volatile registers = rbp,rbx,r12-r15
5 
6co_swap_systemV(to = rdi, from = rsi):
7  mov [rsi],rsp
8  mov rsp,[rdi]
9  pop rax
10 
11  mov [rsi+ 8],rbp
12  mov [rsi+16],rbx
13  mov [rsi+24],r12
14  mov [rsi+32],r13
15  mov [rsi+40],r14
16  mov [rsi+48],r15
17 
18  mov rbp,[rdi+ 8]
19  mov rbx,[rdi+16]
20  mov r12,[rdi+24]
21  mov r13,[rdi+32]
22  mov r14,[rdi+40]
23  mov r15,[rdi+48]
24 
25  jmp rax
26 
27; Win64 ABI:
28; return = rax
29; arguments = rcx,rdx,r8,r9
30; non-volatile registers = rbp,rsi,rdi,rbx,r12-r15
31; non-volatile FPU registers = xmm6-xmm15
32 
33co_swap_win64(to = rcx, from = rdx):
34  mov [rdx],rsp
35  mov rsp,[rcx]
36  pop rax
37 
38  mov [rdx+  8],rbp
39  mov [rdx+ 16],rsi
40  mov [rdx+ 24],rdi
41  mov [rdx+ 32],rbx
42  mov [rdx+ 40],r12
43  mov [rdx+ 48],r13
44  mov [rdx+ 56],r14
45  mov [rdx+ 64],r15
46 
47  add rdx,128
48  and rdx,~15
49 
50  movaps [rdx+  0],xmm6
51  movaps [rdx+ 16],xmm7
52  movaps [rdx+ 32],xmm8
53  movaps [rdx+ 48],xmm9
54  movaps [rdx+ 64],xmm10
55  movaps [rdx+ 80],xmm11
56  movaps [rdx+ 96],xmm12
57  movaps [rdx+112],xmm13
58  movaps [rdx+128],xmm14
59  movaps [rdx+144],xmm15
60 
61  mov rbp,[rcx+  8]
62  mov rsi,[rcx+ 16]
63  mov rdi,[rcx+ 24]
64  mov rbx,[rcx+ 32]
65  mov r12,[rcx+ 40]
66  mov r13,[rcx+ 48]
67  mov r14,[rcx+ 56]
68  mov r15,[rcx+ 64]
69 
70  add rcx,128
71  and rcx,~15
72 
73  movaps [rcx+  0],xmm6
74  movaps [rcx+ 16],xmm7
75  movaps [rcx+ 32],xmm8
76  movaps [rcx+ 48],xmm9
77  movaps [rcx+ 64],xmm10
78  movaps [rcx+ 80],xmm11
79  movaps [rcx+ 96],xmm12
80  movaps [rcx+112],xmm13
81  movaps [rcx+128],xmm14
82  movaps [rcx+144],xmm15
83 
84  jmp rax
85 
src/lib/cothread/doc/targets.html
r0r12048
1<html>
2<head>
3  <title></title>
4  <link href="style.css" rel="stylesheet" type="text/css">
5</head>
6<body>
7 
8<b>Supported targets:</b><br/><br/>
9 
10Note that supported targets are only those that have been tested and confirmed
11working. It is quite possible that libco will work on more processors, compilers
12and operating systems than those listed below.
13<hr/>
14 
15<b>libco.x86</b><br/>
16Overhead: ~5x<br/>
17Supported processor(s): 32-bit x86<br/>
18Supported compiler(s): any<br/>
19Supported operating system(s):<ul>
20<li>Windows</li>
21<li>Mac OS X</li>
22<li>Linux</li>
23<li>BSD</li>
24</ul>
25<hr/>
26 
27<b>libco.amd64</b><br/>
28Overhead: ~10x (Windows), ~6x (all other platforms)<br/>
29Supported processor(s): 64-bit amd64<br/>
30Supported compiler(s): any<br/>
31Supported operating system(s):<ul>
32<li>Windows</li>
33<li>Mac OS X</li>
34<li>Linux</li>
35<li>BSD</li>
36</ul>
37<hr/>
38 
39<b>libco.ppc</b><br/>
40Overhead: ~20x<br/>
41Supported processor(s): 32-bit PowerPC, 64-bit PowerPC<br/>
42Supported compiler(s): GNU GCC<br/>
43Supported operating system(s):<ul>
44</ul>
45<li>Mac OS X</li>
46<li>Linux</li>
47<li>BSD</li>
48<li>Playstation 3</li>
49</ul>
50<br/>
51 
52Note: this module contains compiler flags to enable/disable FPU and Altivec
53support.
54 
55<hr/>
56 
57<b>libco.fiber</b><br/>
58Overhead: ~15x<br/>
59Supported processor(s): Processor independent<br/>
60Supported compiler(s): any<br/>
61Supported operating system(s):<ul>
62<li>Windows</li>
63</ul>
64<hr/>
65 
66<b>libco.sjlj</b><br/>
67Overhead: ~30x<br/>
68Supported processor(s): Processor independent<br/>
69Supported compiler(s): any<br/>
70Supported operating system(s):<ul>
71<li>Mac OS X</li>
72<li>Linux</li>
73<li>BSD</li>
74<li>Solaris</li>
75</ul>
76<hr/>
77 
78<b>libco.ucontext</b><br/>
79Overhead: <b><font color="#ff0000">~300x</font></b><br/>
80Supported processor(s): Processor independent<br/>
81Supported compiler(s): any<br/>
82Supported operating system(s):<ul>
83<li>Linux</li>
84<li>BSD</li>
85</ul>
86<hr/>
87 
88</body>
89</html>
src/lib/cothread/x86.c
r0r12048
1/*
2  libco.x86 (2009-10-12)
3  author: byuu
4  license: public domain
5*/
6
7#define LIBCO_C
8#include "libco.h"
9#include <assert.h>
10#include <stdlib.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#if defined(_MSC_VER)
17  #define fastcall __fastcall
18#elif defined(__GNUC__)
19  #define fastcall __attribute__((fastcall))
20#else
21  #error "libco: please define fastcall macro"
22#endif
23
24static thread_local long co_active_buffer[64];
25static thread_local cothread_t co_active_handle = 0;
26static void (fastcall *co_swap)(cothread_t, cothread_t) = 0;
27
28//ABI: fastcall
29static unsigned char co_swap_function[] = {
30  0x89, 0x22, 0x8B, 0x21, 0x58, 0x89, 0x6A, 0x04, 0x89, 0x72, 0x08, 0x89, 0x7A, 0x0C, 0x89, 0x5A,
31  0x10, 0x8B, 0x69, 0x04, 0x8B, 0x71, 0x08, 0x8B, 0x79, 0x0C, 0x8B, 0x59, 0x10, 0xFF, 0xE0,
32};
33
34#ifdef _WIN32
35  #include <windows.h>
36
37  void co_init() {
38    DWORD old_privileges;
39    VirtualProtect(co_swap_function, sizeof co_swap_function, PAGE_EXECUTE_READWRITE, &old_privileges);
40  }
41#else
42  #include <unistd.h>
43  #include <sys/mman.h>
44
45  void co_init() {
46    unsigned long addr = (unsigned long)co_swap_function;
47    unsigned long base = addr - (addr % sysconf(_SC_PAGESIZE));
48    unsigned long size = (addr - base) + sizeof co_swap_function;
49    mprotect((void*)base, size, PROT_READ | PROT_WRITE | PROT_EXEC);
50  }
51#endif
52
53static void crash() {
54  assert(0); /* called only if cothread_t entrypoint returns */
55}
56
57cothread_t co_active() {
58  if(!co_active_handle) co_active_handle = &co_active_buffer;
59  return co_active_handle;
60}
61
62cothread_t co_create(unsigned int size, void (*entrypoint)(void)) {
63  cothread_t handle;
64  if(!co_swap) {
65    co_init();
66    co_swap = (void (fastcall*)(cothread_t, cothread_t))co_swap_function;
67  }
68  if(!co_active_handle) co_active_handle = &co_active_buffer;
69  size += 256; /* allocate additional space for storage */
70  size &= ~15; /* align stack to 16-byte boundary */
71
72  if(handle = (cothread_t)malloc(size)) {
73    long *p = (long*)((char*)handle + size); /* seek to top of stack */
74    *--p = (long)crash;                      /* crash if entrypoint returns */
75    *--p = (long)entrypoint;                 /* start of function */
76    *(long*)handle = (long)p;                /* stack pointer */
77  }
78
79  return handle;
80}
81
82void co_delete(cothread_t handle) {
83  free(handle);
84}
85
86void co_switch(cothread_t handle) {
87  register cothread_t co_previous_handle = co_active_handle;
88  co_swap(co_active_handle = handle, co_previous_handle);
89}
90
91#ifdef __cplusplus
92}
93#endif
src/lib/cothread/fiber.c
r0r12048
1/*
2  libco.win (2008-01-28)
3  authors: Nach, byuu
4  license: public domain
5*/
6
7#define LIBCO_C
8#include "libco.h"
9#define WINVER 0x0400
10#define _WIN32_WINNT 0x0400
11#define WIN32_LEAN_AND_MEAN
12#include <windows.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18static thread_local cothread_t co_active_ = 0;
19
20static void __stdcall co_thunk(void *coentry) {
21  ((void (*)(void))coentry)();
22}
23
24cothread_t co_active() {
25  if(!co_active_) {
26    ConvertThreadToFiber(0);
27    co_active_ = GetCurrentFiber();
28  }
29  return co_active_;
30}
31
32cothread_t co_create(unsigned int heapsize, void (*coentry)(void)) {
33  if(!co_active_) {
34    ConvertThreadToFiber(0);
35    co_active_ = GetCurrentFiber();
36  }
37  return (cothread_t)CreateFiber(heapsize, co_thunk, (void*)coentry);
38}
39
40void co_delete(cothread_t cothread) {
41  DeleteFiber(cothread);
42}
43
44void co_switch(cothread_t cothread) {
45  co_active_ = cothread;
46  SwitchToFiber(cothread);
47}
48
49#ifdef __cplusplus
50}
51#endif
src/lib/cothread/libco.c
r0r12048
1/*
2  libco
3  auto-selection module
4  license: public domain
5*/
6
7#if defined(__GNUC__) && defined(__i386__)
8  #include "x86.c"
9#elif defined(__GNUC__) && defined(__amd64__)
10  #include "amd64.c"
11#elif defined(__GNUC__) && defined(_ARCH_PPC)
12  #include "ppc.c"
13#elif defined(__GNUC__)
14  #include "sjlj.c"
15#elif defined(_MSC_VER) && defined(_M_IX86)
16  #include "x86.c"
17#elif defined(_MSC_VER) && defined(_M_AMD64)
18  #include "amd64.c"
19#elif defined(_MSC_VER)
20  #include "fiber.c"
21#else
22  #error "libco: unsupported processor, compiler or operating system"
23#endif
src/lib/cothread/ucontext.c
r0r12048
1/*
2  libco.ucontext (2008-01-28)
3  author: Nach
4  license: public domain
5*/
6
7/*
8 * WARNING: the overhead of POSIX ucontext is very high,
9 * assembly versions of libco or libco_sjlj should be much faster
10 *
11 * This library only exists for two reasons:
12 * 1 - as an initial test for the viability of a ucontext implementation
13 * 2 - to demonstrate the power and speed of libco over existing implementations,
14 *     such as pth (which defaults to wrapping ucontext on unix targets)
15 *
16 * Use this library only as a *last resort*
17 */
18
19#define LIBCO_C
20#include "libco.h"
21#include <stdlib.h>
22#include <ucontext.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28static thread_local ucontext_t co_primary;
29static thread_local ucontext_t *co_running = 0;
30
31cothread_t co_active() {
32  if(!co_running) co_running = &co_primary;
33  return (cothread_t)co_running;
34}
35
36cothread_t co_create(unsigned int heapsize, void (*coentry)(void)) {
37  if(!co_running) co_running = &co_primary;
38  ucontext_t *thread = (ucontext_t*)malloc(sizeof(ucontext_t));
39  if(thread) {
40    if((!getcontext(thread) && !(thread->uc_stack.ss_sp = 0)) && (thread->uc_stack.ss_sp = malloc(heapsize))) {
41      thread->uc_link = co_running;
42      thread->uc_stack.ss_size = heapsize;
43      makecontext(thread, coentry, 0);
44    } else {
45      co_delete((cothread_t)thread);
46      thread = 0;
47    }
48  }
49  return (cothread_t)thread;
50}
51
52void co_delete(cothread_t cothread) {
53  if(cothread) {
54    if(((ucontext_t*)cothread)->uc_stack.ss_sp) { free(((ucontext_t*)cothread)->uc_stack.ss_sp); }
55    free(cothread);
56  }
57}
58
59void co_switch(cothread_t cothread) {
60  ucontext_t *old_thread = co_running;
61  co_running = (ucontext_t*)cothread;
62  swapcontext(old_thread, co_running);
63}
64
65#ifdef __cplusplus
66}
67#endif
src/lib/cothread/amd64.c
r0r12048
1/*
2  libco.amd64 (2009-10-12)
3  author: byuu
4  license: public domain
5*/
6
7#define LIBCO_C
8#include "libco.h"
9#include <assert.h>
10#include <stdlib.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16static thread_local long long co_active_buffer[64];
17static thread_local cothread_t co_active_handle = 0;
18static void (*co_swap)(cothread_t, cothread_t) = 0;
19
20#ifdef _WIN32
21  //ABI: Win64
22  static unsigned char co_swap_function[] = {
23    0x48, 0x89, 0x22, 0x48, 0x8B, 0x21, 0x58, 0x48, 0x89, 0x6A, 0x08, 0x48, 0x89, 0x72, 0x10, 0x48,
24    0x89, 0x7A, 0x18, 0x48, 0x89, 0x5A, 0x20, 0x4C, 0x89, 0x62, 0x28, 0x4C, 0x89, 0x6A, 0x30, 0x4C,
25    0x89, 0x72, 0x38, 0x4C, 0x89, 0x7A, 0x40, 0x48, 0x81, 0xC2, 0x80, 0x00, 0x00, 0x00, 0x48, 0x83,
26    0xE2, 0xF0, 0x0F, 0x29, 0x32, 0x0F, 0x29, 0x7A, 0x10, 0x44, 0x0F, 0x29, 0x42, 0x20, 0x44, 0x0F,
27    0x29, 0x4A, 0x30, 0x44, 0x0F, 0x29, 0x52, 0x40, 0x44, 0x0F, 0x29, 0x5A, 0x50, 0x44, 0x0F, 0x29,
28    0x62, 0x60, 0x44, 0x0F, 0x29, 0x6A, 0x70, 0x44, 0x0F, 0x29, 0xB2, 0x80, 0x00, 0x00, 0x00, 0x44,
29    0x0F, 0x29, 0xBA, 0x90, 0x00, 0x00, 0x00, 0x48, 0x8B, 0x69, 0x08, 0x48, 0x8B, 0x71, 0x10, 0x48,
30    0x8B, 0x79, 0x18, 0x48, 0x8B, 0x59, 0x20, 0x4C, 0x8B, 0x61, 0x28, 0x4C, 0x8B, 0x69, 0x30, 0x4C,
31    0x8B, 0x71, 0x38, 0x4C, 0x8B, 0x79, 0x40, 0x48, 0x81, 0xC1, 0x80, 0x00, 0x00, 0x00, 0x48, 0x83,
32    0xE1, 0xF0, 0x0F, 0x29, 0x31, 0x0F, 0x29, 0x79, 0x10, 0x44, 0x0F, 0x29, 0x41, 0x20, 0x44, 0x0F,
33    0x29, 0x49, 0x30, 0x44, 0x0F, 0x29, 0x51, 0x40, 0x44, 0x0F, 0x29, 0x59, 0x50, 0x44, 0x0F, 0x29,
34    0x61, 0x60, 0x44, 0x0F, 0x29, 0x69, 0x70, 0x44, 0x0F, 0x29, 0xB1, 0x80, 0x00, 0x00, 0x00, 0x44,
35    0x0F, 0x29, 0xB9, 0x90, 0x00, 0x00, 0x00, 0xFF, 0xE0,
36  };
37
38  #include <windows.h>
39
40  void co_init() {
41    DWORD old_privileges;
42    VirtualProtect(co_swap_function, sizeof co_swap_function, PAGE_EXECUTE_READWRITE, &old_privileges);
43  }
44#else
45  //ABI: SystemV
46  static unsigned char co_swap_function[] = {
47    0x48, 0x89, 0x26, 0x48, 0x8B, 0x27, 0x58, 0x48, 0x89, 0x6E, 0x08, 0x48, 0x89, 0x5E, 0x10, 0x4C,
48    0x89, 0x66, 0x18, 0x4C, 0x89, 0x6E, 0x20, 0x4C, 0x89, 0x76, 0x28, 0x4C, 0x89, 0x7E, 0x30, 0x48,
49    0x8B, 0x6F, 0x08, 0x48, 0x8B, 0x5F, 0x10, 0x4C, 0x8B, 0x67, 0x18, 0x4C, 0x8B, 0x6F, 0x20, 0x4C,
50    0x8B, 0x77, 0x28, 0x4C, 0x8B, 0x7F, 0x30, 0xFF, 0xE0,
51  };
52
53  #include <unistd.h>
54  #include <sys/mman.h>
55
56  void co_init() {
57    unsigned long long addr = (unsigned long long)co_swap_function;
58    unsigned long long base = addr - (addr % sysconf(_SC_PAGESIZE));
59    unsigned long long size = (addr - base) + sizeof co_swap_function;
60    mprotect((void*)base, size, PROT_READ | PROT_WRITE | PROT_EXEC);
61  }
62#endif
63
64static void crash() {
65  assert(0); /* called only if cothread_t entrypoint returns */
66}
67
68cothread_t co_active() {
69  if(!co_active_handle) co_active_handle = &co_active_buffer;
70  return co_active_handle;
71}
72
73cothread_t co_create(unsigned int size, void (*entrypoint)(void)) {
74  cothread_t handle;
75  if(!co_swap) {
76    co_init();
77    co_swap = (void (*)(cothread_t, cothread_t))co_swap_function;
78  }
79  if(!co_active_handle) co_active_handle = &co_active_buffer;
80  size += 512; /* allocate additional space for storage */
81  size &= ~15; /* align stack to 16-byte boundary */
82
83  if(handle = (cothread_t)malloc(size)) {
84    long long *p = (long long*)((char*)handle + size); /* seek to top of stack */
85    *--p = (long long)crash;                           /* crash if entrypoint returns */
86    *--p = (long long)entrypoint;                      /* start of function */
87    *(long long*)handle = (long long)p;                /* stack pointer */
88  }
89
90  return handle;
91}
92
93void co_delete(cothread_t handle) {
94  free(handle);
95}
96
97void co_switch(cothread_t handle) {
98  register cothread_t co_previous_handle = co_active_handle;
99  co_swap(co_active_handle = handle, co_previous_handle);
100}
101
102#ifdef __cplusplus
103}
104#endif
src/lib/cothread/libco.h
r0r12048
1/*
2  libco
3  version: 0.16 (2010-12-24)
4  license: public domain
5*/
6
7#ifndef LIBCO_H
8#define LIBCO_H
9
10#ifdef LIBCO_C
11  #ifdef LIBCO_MP
12    #define thread_local __thread
13  #else
14    #define thread_local
15  #endif
16#endif
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22typedef void* cothread_t;
23
24cothread_t co_active();
25cothread_t co_create(unsigned int, void (*)(void));
26void co_delete(cothread_t);
27void co_switch(cothread_t);
28
29#ifdef __cplusplus
30}
31#endif
32
33/* ifndef LIBCO_H */
34#endif
src/lib/lib.mak
r12047r12048
1919   $(LIBOBJ)/formats \
2020   $(LIBOBJ)/zlib \
2121   $(LIBOBJ)/softfloat \
22   $(LIBOBJ)/cothread \
2223
2324
2425
r12047r12048
7879# formats library objects
7980#-------------------------------------------------
8081
81EXPATOBJS = \
82FORMATSOBJS = \
8283   $(LIBOBJ)/formats/cassimg.o    \
8384   $(LIBOBJ)/formats/flopimg.o      \
8485   $(LIBOBJ)/formats/imageutl.o   \
r12047r12048
152153   $(LIBOBJ)/formats/z80ne_dsk.o   \
153154   $(LIBOBJ)/formats/zx81_p.o      \
154155
156$(OBJ)/libformats.a: $(FORMATSOBJS)
155157
156$(OBJ)/libformats.a: $(EXPATOBJS)
157158
158159
159160#-------------------------------------------------
r12047r12048
180181   @echo Compiling $<...
181182   $(CC) $(CDEFS) $(CCOMFLAGS) $(CONLYFLAGS) -c $< -o $@
182183
184
185
183186#-------------------------------------------------
184187# SoftFloat library objects
185188#-------------------------------------------------
r12047r12048
194197
195198$(LIBOBJ)/softfloat/softfloat.o: $(LIBSRC)/softfloat/softfloat.c $(LIBSRC)/softfloat/softfloat.h $(LIBSRC)/softfloat/softfloat-macros $(LIBSRC)/softfloat/softfloat-specialize
196199
200
201
202#-------------------------------------------------
203# cothread library objects
204#-------------------------------------------------
205
206COTHREADOBJS = \
207   $(LIBOBJ)/cothread/libco.o
208
209$(OBJ)/libco.a: $(COTHREADOBJS)
210
211$(LIBOBJ)/cothread/%.o: $(LIBSRC)/cothread/%.c | $(OSPREBUILD)
212   @echo Compiling $<...
213   $(CC) -c -fomit-frame-pointer $< -o $@
makefile
r12047r12048
615615# add formats emulation library
616616FORMATS_LIB = $(OBJ)/libformats.a
617617
618# add cothread library
619COTHREAD = $(OBJ)/libco.a
618620
621
622
619623#-------------------------------------------------
620624# 'default' target needs to go here, before the
621625# include files which define additional targets
r12047r12048
715719ifndef EXECUTABLE_DEFINED
716720
717721# always recompile the version string
718$(VERSIONOBJ): $(DRVLIBS) $(LIBOSD) $(LIBCPU) $(LIBEMU) $(LIBSOUND) $(LIBUTIL) $(EXPAT) $(ZLIB) $(SOFTFLOAT) $(FORMATS_LIB) $(LIBOCORE) $(RESFILE)
722$(VERSIONOBJ): $(DRVLIBS) $(LIBOSD) $(LIBCPU) $(LIBEMU) $(LIBSOUND) $(LIBUTIL) $(EXPAT) $(ZLIB) $(SOFTFLOAT) $(FORMATS_LIB) $(COTHREAD) $(LIBOCORE) $(RESFILE)
719723
720$(EMULATOR): $(VERSIONOBJ) $(DRIVLISTOBJ) $(DRVLIBS) $(LIBOSD) $(LIBCPU) $(LIBEMU) $(LIBDASM) $(LIBSOUND) $(LIBUTIL) $(EXPAT) $(SOFTFLOAT) $(FORMATS_LIB) $(ZLIB) $(LIBOCORE) $(RESFILE)
724$(EMULATOR): $(VERSIONOBJ) $(DRIVLISTOBJ) $(DRVLIBS) $(LIBOSD) $(LIBCPU) $(LIBEMU) $(LIBDASM) $(LIBSOUND) $(LIBUTIL) $(EXPAT) $(SOFTFLOAT) $(FORMATS_LIB) $(COTHREAD) $(ZLIB) $(LIBOCORE) $(RESFILE)
721725   @echo Linking $@...
722726   $(LD) $(LDFLAGS) $(LDFLAGSEMULATOR) $^ $(LIBS) -o $@
723727ifeq ($(TARGETOS),win32)
r12047r12048
781785#-------------------------------------------------
782786
783787-include depend.mak
784

Previous 15994 Revisions Next


© 1998-2018 The MESS Team