Previous 15994 Revisions Next

r9723 Saturday 4th December, 2010 at 20:46:00 UTC by Nathan Woods
More driver state. [Atari Ace]
[src/mess/drivers]coco.c dgn_beta.c
[src/mess/includes]coco.h
[src/mess/machine]coco.c dgn_beta.c
[src/mess/video]coco3.c

src/mess/machine/dgn_beta.c
r9722r9723
6262#include "debug/debugcon.h"
6363#include "cpu/m6809/m6809.h"
6464#include "machine/6821pia.h"
65#include "includes/coco.h"
6665#include "includes/dgn_beta.h"
6766#include "machine/6551.h"
6867#include "image.h"
src/mess/machine/coco.c
r9722r9723
122122***************************************************************************/
123123
124124/*common vars/calls */
125static UINT8 *coco_rom;
126static int dclg_state, dclg_output_h, dclg_output_v, dclg_timer;
127static UINT8 (*update_keyboard)(running_machine *machine);
128static emu_timer *update_keyboard_timer;
129static emu_timer *mux_sel1_timer;
130static emu_timer *mux_sel2_timer;
131static UINT8 mux_sel1, mux_sel2;
132static UINT8 bitbanger_output_value;
133static UINT8 bitbanger_input_value;
134static UINT8 dac_value;
135125
136126static WRITE8_DEVICE_HANDLER( d_pia1_pb_w );
137127static WRITE8_DEVICE_HANDLER( d_pia1_pa_w );
r9722r9723
158148static READ8_DEVICE_HANDLER ( d_pia1_pb_r_coco2 );
159149
160150/* CoCo 3 specific */
161UINT8 coco3_gimereg[16];
162static int coco3_enable_64k;
163static UINT8 coco3_mmu[16];
164static UINT8 coco3_interupt_line;
165static UINT8 gime_firq, gime_irq;
166151
167152static WRITE_LINE_DEVICE_HANDLER( coco3_pia0_irq_a );
168153static WRITE_LINE_DEVICE_HANDLER( coco3_pia0_irq_b );
r9722r9723
185170static WRITE8_DEVICE_HANDLER ( dgnalpha_pia2_pa_w );
186171static WRITE_LINE_DEVICE_HANDLER( d_pia2_firq_a );
187172static WRITE_LINE_DEVICE_HANDLER( d_pia2_firq_b );
188static int dgnalpha_just_reset;      /* Reset flag used to ignore first NMI after reset */
189173
190/* Dragon Plus specific */
191static int dragon_plus_reg;         /* Dragon plus control reg */
192
193174/* Memory map related CoCo 1/2 and Dragons only */
194static UINT8 *bas_rom_bank;         /* Dragon 64 / Alpha rom bank in use, basic rom bank on coco */
195static UINT8 *bottom_32k;         /* ram to be mapped into bottom 32K */
196175static void setup_memory_map(running_machine *machine);
197176
198177
r9722r9723
942921
943922static void coco3_recalc_irq(running_machine *machine)
944923{
945   if ((coco3_gimereg[0] & 0x20) && gime_irq)
924   coco3_state *state = machine->driver_data<coco3_state>();
925   if ((state->gimereg[0] & 0x20) && state->gime_irq)
946926      cputag_set_input_line(machine, "maincpu", M6809_IRQ_LINE, ASSERT_LINE);
947927   else
948928      d_recalc_irq(machine);
r9722r9723
950930
951931static void coco3_recalc_firq(running_machine *machine)
952932{
953   if ((coco3_gimereg[0] & 0x10) && gime_firq)
933   coco3_state *state = machine->driver_data<coco3_state>();
934   if ((state->gimereg[0] & 0x10) && state->gime_firq)
954935      cputag_set_input_line(machine, "maincpu", M6809_FIRQ_LINE, ASSERT_LINE);
955936   else
956937      d_recalc_firq(machine);
r9722r9723
1009990
1010991static void coco3_raise_interrupt(running_machine *machine, UINT8 mask, int state)
1011992{
993   coco3_state *drvstate = machine->driver_data<coco3_state>();
1012994   int lowtohigh;
1013995
1014   lowtohigh = state && ((coco3_interupt_line & mask) == 0);
996   lowtohigh = state && ((drvstate->interupt_line & mask) == 0);
1015997
1016998   if (state)
1017      coco3_interupt_line |= mask;
999      drvstate->interupt_line |= mask;
10181000   else
1019      coco3_interupt_line &= ~mask;
1001      drvstate->interupt_line &= ~mask;
10201002
10211003   if (lowtohigh)
10221004   {
1023      if ((coco3_gimereg[0] & 0x20) && (coco3_gimereg[2] & mask))
1005      if ((drvstate->gimereg[0] & 0x20) && (drvstate->gimereg[2] & mask))
10241006      {
1025         gime_irq |= (coco3_gimereg[2] & mask);
1007         drvstate->gime_irq |= (drvstate->gimereg[2] & mask);
10261008         coco3_recalc_irq(machine);
10271009
10281010         if (LOG_INT_COCO3)
10291011            logerror("CoCo3 Interrupt: Raising IRQ; scanline=%i\n", machine->primary_screen->vpos());
10301012      }
1031      if ((coco3_gimereg[0] & 0x10) && (coco3_gimereg[3] & mask))
1013      if ((drvstate->gimereg[0] & 0x10) && (drvstate->gimereg[3] & mask))
10321014      {
1033         gime_firq |= (coco3_gimereg[3] & mask);
1015         drvstate->gime_firq |= (drvstate->gimereg[3] & mask);
10341016         coco3_recalc_firq(machine);
10351017
10361018         if (LOG_INT_COCO3)
r9722r9723
10811063   coco3_recalc_irq(machine);
10821064}
10831065
1084static timer_fired_func recalc_interrupts;
10851066
10861067#ifdef UNUSED_FUNCTION
10871068void coco_set_halt_line(running_machine *machine, int halt_line)
10881069{
1070   coco_state *state = machine->driver_data<coco_state>();
10891071   cpunum_set_input_line(machine, 0, INPUT_LINE_HALT, halt_line);
10901072   if (halt_line == CLEAR_LINE)
1091      timer_set(machine, machine->device<cpu_device>("maincpu")->cycles_to_attotime(1), NULL, 0, recalc_interrupts);
1073      timer_set(machine, machine->device<cpu_device>("maincpu")->cycles_to_attotime(1), NULL, 0, state->recalc_interrupts);
10921074}
10931075#endif
10941076
r9722r9723
10971079  Hires Joystick
10981080***************************************************************************/
10991081
1100static int coco_hiresjoy_ca = 1;
1101static attotime coco_hiresjoy_xtransitiontime;
1102static attotime coco_hiresjoy_ytransitiontime;
11031082
11041083static attotime coco_hiresjoy_computetransitiontime( running_machine *machine, UINT8 port, UINT8 axis )
11051084{
r9722r9723
11291108
11301109static void coco_hiresjoy_w( running_machine *machine, int data, UINT8 port )
11311110{
1132   if (!data && coco_hiresjoy_ca)
1111   coco_state *state = machine->driver_data<coco_state>();
1112   if (!data && state->hiresjoy_ca)
11331113   {
11341114      /* Hi to lo */
1135      coco_hiresjoy_xtransitiontime = coco_hiresjoy_computetransitiontime(machine, port, 0);
1136      coco_hiresjoy_ytransitiontime = coco_hiresjoy_computetransitiontime(machine, port, 1);
1115      state->hiresjoy_xtransitiontime = coco_hiresjoy_computetransitiontime(machine, port, 0);
1116      state->hiresjoy_ytransitiontime = coco_hiresjoy_computetransitiontime(machine, port, 1);
11371117   }
1138   else if (data && !coco_hiresjoy_ca)
1118   else if (data && !state->hiresjoy_ca)
11391119   {
11401120      /* Lo to hi */
1141      coco_hiresjoy_xtransitiontime = attotime_zero;
1142      coco_hiresjoy_ytransitiontime = attotime_zero;
1121      state->hiresjoy_xtransitiontime = attotime_zero;
1122      state->hiresjoy_ytransitiontime = attotime_zero;
11431123   }
1144   coco_hiresjoy_ca = data;
1145   (*update_keyboard)(machine);
1124   state->hiresjoy_ca = data;
1125   (*state->update_keyboard)(machine);
11461126}
11471127
11481128static int coco_hiresjoy_readone( running_machine *machine, attotime transitiontime )
r9722r9723
11521132
11531133static int coco_hiresjoy_rx( running_machine *machine )
11541134{
1155   return coco_hiresjoy_readone(machine, coco_hiresjoy_xtransitiontime);
1135   coco_state *state = machine->driver_data<coco_state>();
1136   return coco_hiresjoy_readone(machine, state->hiresjoy_xtransitiontime);
11561137}
11571138
11581139static int coco_hiresjoy_ry( running_machine *machine )
11591140{
1160   return coco_hiresjoy_readone(machine, coco_hiresjoy_ytransitiontime);
1141   coco_state *state = machine->driver_data<coco_state>();
1142   return coco_hiresjoy_readone(machine, state->hiresjoy_ytransitiontime);
11611143}
11621144
11631145/***************************************************************************
r9722r9723
12111193   int soundmux_status = 0;
12121194   if (pia6821_get_output_cb2(state->pia_1))
12131195      soundmux_status |= SOUNDMUX_STATUS_ENABLE;
1214   if (mux_sel1)
1196   if (state->mux_sel1)
12151197      soundmux_status |= SOUNDMUX_STATUS_SEL1;
1216   if (mux_sel2)
1198   if (state->mux_sel2)
12171199      soundmux_status |= SOUNDMUX_STATUS_SEL2;
12181200   return soundmux_status;
12191201}
r9722r9723
13241306
13251307static WRITE8_DEVICE_HANDLER( d_pia0_ca2_w )
13261308{
1327   timer_adjust_oneshot(mux_sel1_timer, JOYSTICK_MUX_DELAY, data);
1309   coco_state *state = device->machine->driver_data<coco_state>();
1310   timer_adjust_oneshot(state->mux_sel1_timer, JOYSTICK_MUX_DELAY, data);
13281311}
13291312
13301313static TIMER_CALLBACK( coco_update_sel1_timerproc )
13311314{
1332   mux_sel1 = param;
1333   (*update_keyboard)(machine);
1315   coco_state *state = machine->driver_data<coco_state>();
1316   state->mux_sel1 = param;
1317   (*state->update_keyboard)(machine);
13341318   soundmux_update(machine);
13351319}
13361320
13371321static WRITE8_DEVICE_HANDLER( d_pia0_cb2_w )
13381322{
1339   timer_adjust_oneshot(mux_sel2_timer, JOYSTICK_MUX_DELAY, data);
1323   coco_state *state = device->machine->driver_data<coco_state>();
1324   timer_adjust_oneshot(state->mux_sel2_timer, JOYSTICK_MUX_DELAY, data);
13401325}
13411326
13421327static TIMER_CALLBACK( coco_update_sel2_timerproc )
13431328{
1344   mux_sel2 = param;
1345   (*update_keyboard)(machine);
1329   coco_state *state = machine->driver_data<coco_state>();
1330   state->mux_sel2 = param;
1331   (*state->update_keyboard)(machine);
13461332   soundmux_update(machine);
13471333}
13481334
r9722r9723
13841370
13851371
13861372   pia0_pb = pia6821_get_output_b(state->pia_0);
1387   joystick_axis = mux_sel1;
1388   joystick = mux_sel2;
1373   joystick_axis = state->mux_sel1;
1374   joystick = state->mux_sel2;
13891375
13901376   /* which kind of controller is selected? */
13911377   joy_mask = joystick ? 0xf0 : 0x0f;
r9722r9723
14401426         if ((machine->primary_screen->vpos() == input_port_read_safe(machine, portnames[joystick][ctrl][1], 0)))
14411427         {
14421428            /* If gun is pointing at the current scan line, set hit bit and cache horizontal timer value */
1443            dclg_output_h |= 0x02;
1444            dclg_timer = input_port_read_safe(machine, portnames[joystick][ctrl][0], 0) << 1;
1429            state->dclg_output_h |= 0x02;
1430            state->dclg_timer = input_port_read_safe(machine, portnames[joystick][ctrl][0], 0) << 1;
14451431         }
14461432
1447         if ((dac >> 2) <= dclg_table[(joystick_axis ? dclg_output_h : dclg_output_v) & 0x03])
1433         if ((dac >> 2) <= dclg_table[(joystick_axis ? state->dclg_output_h : state->dclg_output_v) & 0x03])
14481434            porta |= 0x80;
14491435
1450         if ((dclg_state == 7))
1436         if ((state->dclg_state == 7))
14511437         {
14521438            /* While in state 7, prepare to chech next video frame for a hit */
14531439            dclg_time = machine->primary_screen->time_until_pos(input_port_read_safe(machine, portnames[joystick][ctrl][1], 0), 0);
r9722r9723
14621448   if (attotime_compare(dclg_time, attotime_zero))
14631449   {
14641450      /* schedule lightgun events */
1465      timer_reset(update_keyboard_timer, dclg_time);
1451      timer_reset(state->update_keyboard_timer, dclg_time);
14661452   }
14671453   else
14681454   {
14691455      /* schedule hires joystick events */
1470      attotime xtrans = get_relative_time(machine, coco_hiresjoy_xtransitiontime);
1471      attotime ytrans = get_relative_time(machine, coco_hiresjoy_ytransitiontime);
1456      attotime xtrans = get_relative_time(machine, state->hiresjoy_xtransitiontime);
1457      attotime ytrans = get_relative_time(machine, state->hiresjoy_ytransitiontime);
14721458
1473      timer_reset(update_keyboard_timer,
1459      timer_reset(state->update_keyboard_timer,
14741460         (attotime_compare(xtrans, ytrans) > 0) ? ytrans : xtrans);
14751461   }
14761462
r9722r9723
14951481
14961482
14971483/* three functions that update the keyboard in varying ways */
1498static WRITE8_DEVICE_HANDLER( d_pia0_pb_w )             { (*update_keyboard)(device->machine); }
1499INPUT_CHANGED( coco_keyboard_changed )                  { (*update_keyboard)(field->port->machine); }
1500static TIMER_CALLBACK( coco_update_keyboard_timerproc ) { (*update_keyboard)(machine); }
1484static WRITE8_DEVICE_HANDLER( d_pia0_pb_w )
1485{
1486   coco_state *state = device->machine->driver_data<coco_state>();
1487   (*state->update_keyboard)(device->machine);
1488}
15011489
1490INPUT_CHANGED( coco_keyboard_changed )
1491{
1492   coco_state *state = field->port->machine->driver_data<coco_state>();
1493   (*state->update_keyboard)(field->port->machine);
1494}
1495
1496static TIMER_CALLBACK( coco_update_keyboard_timerproc )
1497{
1498   coco_state *state = machine->driver_data<coco_state>();
1499   (*state->update_keyboard)(machine);
1500}
1501
15021502static WRITE8_DEVICE_HANDLER( d_pia0_pa_w )
15031503{
15041504   UINT8 ctrl = input_port_read_safe(device->machine, "ctrl_sel", 0x00);
r9722r9723
15381538}
15391539
15401540/* Printer output functions used by d_pia1_pa_w */
1541static void (*printer_out)(running_machine *machine, int data);
15421541
15431542/* Printer output for the CoCo, output to bitbanger port */
15441543static void printer_out_coco(running_machine *machine, int data)
15451544{
1546   bitbanger_output_value = (data & 2) >> 1;
1547   bitbanger_output(bitbanger_image(machine), bitbanger_output_value);
1545   coco_state *state = machine->driver_data<coco_state>();
1546   state->bitbanger_output_value = (data & 2) >> 1;
1547   bitbanger_output(bitbanger_image(machine), state->bitbanger_output_value);
15481548}
15491549
15501550/* Printer output for the Dragon, output to Paralel port */
r9722r9723
15611561
15621562static WRITE8_DEVICE_HANDLER ( d_pia1_pa_w )
15631563{
1564   coco_state *state = device->machine->driver_data<coco_state>();
15641565   /*
15651566     *  This port appears at $FF20
15661567     *
r9722r9723
15691570     *    1:    Serial out (CoCo), Printer strobe (Dragon)
15701571     */
15711572   UINT8 dac = pia6821_get_output_a(device) & 0xfc;
1572   static int dclg_previous_bit;
15731573   UINT8 ctrl = input_port_read_safe(device->machine, "ctrl_sel", 0x00);
15741574   UINT8 hires = input_port_read_safe(device->machine, "hires_intf", 0x00);
1575   dac_value = dac >> 2;
1575   state->dac_value = dac >> 2;
15761576
15771577   coco_sound_update(device->machine);
15781578
r9722r9723
15811581   {
15821582      int dclg_this_bit = ((data & 2) >> 1);
15831583
1584      if (dclg_previous_bit == 1)
1584      if (state->dclg_previous_bit == 1)
15851585      {
15861586         if (dclg_this_bit == 0)
15871587         {
15881588            /* Clock Diecom Light gun interface on a high to low transistion */
1589            dclg_state++;
1590            dclg_state &= 0x0f;
1589            state->dclg_state++;
1590            state->dclg_state &= 0x0f;
15911591
15921592            /* Clear hit bit for every transistion */
1593            dclg_output_h &= ~0x02;
1593            state->dclg_output_h &= ~0x02;
15941594
1595            if (dclg_state > 7)
1595            if (state->dclg_state > 7)
15961596            {
15971597               /* Bit shift timer data on state 8 thru 15 */
1598               if (((dclg_timer >> (dclg_state - 8 + 1)) & 0x01) == 1)
1599                  dclg_output_v |= 0x01;
1598               if (((state->dclg_timer >> (state->dclg_state - 8 + 1)) & 0x01) == 1)
1599                  state->dclg_output_v |= 0x01;
16001600               else
1601                  dclg_output_v &= ~0x01;
1601                  state->dclg_output_v &= ~0x01;
16021602
16031603               /* Bit 9 of timer is only avaiable if state == 8*/
1604               if (dclg_state == 8 && (((dclg_timer >> 9) & 0x01) == 1))
1605                  dclg_output_v |= 0x02;
1604               if (state->dclg_state == 8 && (((state->dclg_timer >> 9) & 0x01) == 1))
1605                  state->dclg_output_v |= 0x02;
16061606               else
1607                  dclg_output_v &= ~0x02;
1607                  state->dclg_output_v &= ~0x02;
16081608            }
16091609
16101610            /* During state 15, this bit is high. */
1611            if (dclg_state == 15)
1612               dclg_output_h |= 0x01;
1611            if (state->dclg_state == 15)
1612               state->dclg_output_h |= 0x01;
16131613            else
1614               dclg_output_h &= ~0x01;
1614               state->dclg_output_h &= ~0x01;
16151615         }
16161616      }
16171617
1618      dclg_previous_bit = dclg_this_bit;
1618      state->dclg_previous_bit = dclg_this_bit;
16191619
16201620   }
16211621   else
r9722r9723
16231623      cassette_output(cassette_device_image(device->machine), ((int) dac - 0x80) / 128.0);
16241624   }
16251625
1626   (*update_keyboard)(device->machine);
1626   (*state->update_keyboard)(device->machine);
16271627
16281628   /* Hi-Res Joystick (either in Left or in Right Port) writes here */
16291629   if ((ctrl & 0x0f) == 0x01 && hires == 0x01)
r9722r9723
16321632      coco_hiresjoy_w(device->machine, dac >= 0x80, 1);
16331633
16341634   /* Handle printer output, serial for CoCos, parallel for Dragons */
1635   printer_out(device->machine, data);
1635   (*state->printer_out)(device->machine, data);
16361636}
16371637
16381638/*
r9722r9723
17241724/* on the alpha switches between the Boot/Diagnostic rom and the basic rom */
17251725static void dragon_page_rom(running_machine *machine, int romswitch)
17261726{
1727   coco_state *state = machine->driver_data<coco_state>();
17271728   UINT8 *bank;
17281729
17291730   if (romswitch)
1730      bank = coco_rom;      /* This is the 32k mode basic(64)/boot rom(alpha)  */
1731      bank = state->rom;      /* This is the 32k mode basic(64)/boot rom(alpha)  */
17311732   else
1732      bank = coco_rom + 0x8000;   /* This is the 64k mode basic(64)/basic rom(alpha) */
1733      bank = state->rom + 0x8000;   /* This is the 64k mode basic(64)/basic rom(alpha) */
17331734
1734   bas_rom_bank = bank;         /* Record which rom we are using so that the irq routine */
1735   state->bas_rom_bank = bank;         /* Record which rom we are using so that the irq routine */
17351736                  /* uses the vectors from the correct rom ! (alpha) */
17361737
17371738   setup_memory_map(machine);         /* Setup memory map as needed */
r9722r9723
17481749
17491750   if (state)
17501751   {
1751      if(dgnalpha_just_reset)
1752      if(cstate->dgnalpha_just_reset)
17521753      {
1753         dgnalpha_just_reset = 0;
1754         cstate->dgnalpha_just_reset = 0;
17541755      }
17551756      else
17561757      {
r9722r9723
18391840
18401841static READ8_DEVICE_HANDLER ( d_pia1_pa_r )
18411842{
1843   coco_state *state = device->machine->driver_data<coco_state>();
18421844   UINT8 result;
18431845
18441846   result = cassette_input(cassette_device_image(device->machine)) >= 0 ? 1 : 0;
1845   result |= bitbanger_output_value << 1;
1846   result |= dac_value << 2;
1847   result |= state->bitbanger_output_value << 1;
1848   result |= state->dac_value << 2;
18471849
18481850   return result;
18491851}
18501852
18511853void coco_bitbanger_callback(running_machine *machine, UINT8 bit)
18521854{
1853      bitbanger_input_value = bit;
1855   coco_state *state = machine->driver_data<coco_state>();
1856      state->bitbanger_input_value = bit;
18541857}
18551858
18561859void coco3_bitbanger_callback(running_machine *machine, UINT8 bit)
18571860{
1861   coco_state *state = machine->driver_data<coco_state>();
18581862   /* rant: this interrupt is next to useless. It would be useful information to know when a
18591863            start bit (high to low) occurs, but this interrupt activates in the opposite situation.
18601864   */
18611865
1862   if( bitbanger_input_value == 0 && bit == 1)
1866   if( state->bitbanger_input_value == 0 && bit == 1)
18631867   {
1864      bitbanger_input_value = bit;
1868      state->bitbanger_input_value = bit;
18651869      coco3_raise_interrupt(machine, COCO3_INT_EI2, 0);
18661870      coco3_raise_interrupt(machine, COCO3_INT_EI2, 1);
18671871   }
18681872   else
18691873   {
1870      bitbanger_input_value = bit;
1874      state->bitbanger_input_value = bit;
18711875   }
18721876}
18731877
r9722r9723
18931897   else
18941898      result = 0x00;         /* 4K Rams */
18951899
1896   result += bitbanger_input_value;
1900   result += state->bitbanger_input_value;
18971901
18981902   return result;
18991903}
r9722r9723
19331937   else
19341938      result = (pia6821_get_output_b(state->pia_0) & 0x40) >> 4;      /* 32/64K: wire output of pia0_pb6 to input pia1_pb2  */
19351939
1936   result += bitbanger_input_value;
1940   result += state->bitbanger_input_value;
19371941
19381942   return result;
19391943}
r9722r9723
19641968*/
19651969WRITE8_HANDLER ( dgnplus_reg_w )
19661970{
1971   coco_state *state = space->machine->driver_data<coco_state>();
19671972   int map;
19681973
1969   dragon_plus_reg = data;
1970
19711974   map = (data & 0x06)>>1;
19721975
19731976   switch (map)
19741977   {
1975      case 0x00   : bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x00000]; break;
1976      case 0x01   : bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x10000]; break;
1977      case 0x02   : bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x18000]; break;
1978      case 0x03   : bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x00000]; break;
1979      default   : bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x00000]; break; // Just to shut the compiler up !
1978      case 0x00   : state->bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x00000]; break;
1979      case 0x01   : state->bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x10000]; break;
1980      case 0x02   : state->bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x18000]; break;
1981      case 0x03   : state->bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x00000]; break;
1982      default   : state->bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x00000]; break; // Just to shut the compiler up !
19801983   }
19811984
19821985   setup_memory_map(space->machine);
r9722r9723
20172020
20182021READ8_HANDLER(dgnalpha_mapped_irq_r)
20192022{
2020   return bas_rom_bank[0x3ff0 + offset];
2023   coco_state *state = space->machine->driver_data<coco_state>();
2024   return state->bas_rom_bank[0x3ff0 + offset];
20212025}
20222026
20232027static void setup_memory_map(running_machine *machine)
r9722r9723
21102114      {
21112115         /* This deals with the bottom 32K page switch and the Dragon Plus paged ram */
21122116         if(block_index<8)
2113            memory_set_bankptr(machine, bank, &bottom_32k[memmap[wbank-1].start]);
2117            memory_set_bankptr(machine, bank, &state->bottom_32k[memmap[wbank-1].start]);
21142118         else
21152119            memory_set_bankptr(machine, bank,&messram_get_ptr(machine->device("messram"))[memmap[wbank-1].start]);
21162120
r9722r9723
21352139         /* as this may be in a different block of coco_rom, in the Dragon 64 and Alpha */
21362140         /* as these machines have mutiple bios roms that can ocupy this area */
21372141         if (block_index < 4)
2138            offset = &bas_rom_bank[0x1000*block_index];
2142            offset = &state->bas_rom_bank[0x1000*block_index];
21392143         else
21402144            offset = &cart_rom[(0x1000*(block_index-4)) % cart_length];
21412145
r9722r9723
21482152
21492153static SAM6883_SET_PAGE_ONE_MODE( d_sam_set_pageonemode )
21502154{
2155   coco_state *state = device->machine->driver_data<coco_state>();
21512156   /* Page mode - allowed switching between the low 32k and the high 32k,
21522157     * assuming that 64k wasn't enabled
21532158     *
r9722r9723
21582163   if (!sam6883_maptype(device))      // Ignored in maptype 1
21592164   {
21602165      if((messram_get_size(device->machine->device("messram"))>0x8000) && val)
2161         bottom_32k=&messram_get_ptr(device->machine->device("messram"))[0x8000];
2166         state->bottom_32k=&messram_get_ptr(device->machine->device("messram"))[0x8000];
21622167      else
2163         bottom_32k=messram_get_ptr(device->machine->device("messram"));
2168         state->bottom_32k=messram_get_ptr(device->machine->device("messram"));
21642169
21652170      setup_memory_map(device->machine);
21662171   }
r9722r9723
22172222  FAQ agrees with this
22182223***************************************************************************/
22192224
2220static emu_timer *coco3_gime_timer;
22212225
22222226static void coco3_timer_reset(running_machine *machine)
22232227{
2228   coco3_state *state = machine->driver_data<coco3_state>();
22242229   /* reset the timer; take the value stored in $FF94-5 and start the timer ticking */
22252230   UINT16 timer_value;
22262231   m6847_timing_type timing;
22272232   attotime delay_time;
22282233
22292234   /* value is from 0-4095 */
2230   timer_value = ((coco3_gimereg[4] & 0x0F) * 0x100) | coco3_gimereg[5];
2235   timer_value = ((state->gimereg[4] & 0x0F) * 0x100) | state->gimereg[5];
22312236
22322237   if (timer_value > 0)
22332238   {
r9722r9723
22382243         timer_value += 2;   /* the 1986 GIME reset to the value plus two */
22392244
22402245      /* choose which timing clock source */
2241      timing = (coco3_gimereg[1] & 0x20) ? M6847_CLOCK : M6847_HSYNC;
2246      timing = (state->gimereg[1] & 0x20) ? M6847_CLOCK : M6847_HSYNC;
22422247
22432248      /* determine the delay time */
22442249      delay_time = coco6847_time_delay(machine, timing, timer_value);
r9722r9723
22462251         logerror("coco3_reset_timer(): delay_time=%g\n", attotime_to_double(delay_time));
22472252
22482253      /* and adjust the timer */
2249      timer_adjust_oneshot(coco3_gime_timer, delay_time, 0);
2254      timer_adjust_oneshot(state->gime_timer, delay_time, 0);
22502255   }
22512256   else
22522257   {
22532258      /* timer is shut off */
2254      timer_reset(coco3_gime_timer, attotime_never);
2259      timer_reset(state->gime_timer, attotime_never);
22552260      if (LOG_TIMER)
22562261         logerror("coco3_reset_timer(): timer is off\n");
22572262   }
r9722r9723
22622267static TIMER_CALLBACK(coco3_timer_proc)
22632268{
22642269   coco3_timer_reset(machine);
2265   coco3_vh_blink();
2270   coco3_vh_blink(machine);
22662271   coco3_raise_interrupt(machine, COCO3_INT_TMR, 1);
22672272   coco3_raise_interrupt(machine, COCO3_INT_TMR, 0);
22682273}
r9722r9723
22712276
22722277static void coco3_timer_init(running_machine *machine)
22732278{
2274   coco3_gime_timer = timer_alloc(machine, coco3_timer_proc, NULL);
2279   coco3_state *state = machine->driver_data<coco3_state>();
2280   state->gime_timer = timer_alloc(machine, coco3_timer_proc, NULL);
22752281}
22762282
22772283
r9722r9723
22862292
22872293static SAM6883_SET_MAP_TYPE( d_sam_set_maptype )
22882294{
2295   coco_state *state = device->machine->driver_data<coco_state>();
22892296   if(val)
2290      bottom_32k=messram_get_ptr(device->machine->device("messram"));   // Always reset, when in maptype 1
2297      state->bottom_32k=messram_get_ptr(device->machine->device("messram"));   // Always reset, when in maptype 1
22912298
22922299   setup_memory_map(device->machine);
22932300}
r9722r9723
23232330 */
23242331offs_t coco3_mmu_translate(running_machine *machine,int bank, int offset)
23252332{
2333   coco3_state *state = machine->driver_data<coco3_state>();
23262334   int forceram;
23272335   UINT32 block;
23282336   offs_t result;
r9722r9723
23302338   /* Bank 8 is the 0xfe00 block; and it is treated differently */
23312339   if (bank == 8)
23322340   {
2333      if (coco3_gimereg[0] & 8)
2341      if (state->gimereg[0] & 8)
23342342      {
23352343         /* this GIME register fixes logical addresses $FExx to physical
23362344             * addresses $7FExx ($1FExx if 128k */
r9722r9723
23472355   }
23482356
23492357   /* Perform the MMU lookup */
2350   if (coco3_gimereg[0] & 0x40)
2358   if (state->gimereg[0] & 0x40)
23512359   {
2352      if (coco3_gimereg[1] & 1)
2360      if (state->gimereg[1] & 1)
23532361         bank += 8;
2354      block = coco3_mmu[bank];
2355      block |= ((UINT32) ((coco3_gimereg[11] >> 4) & 0x03)) << 8;
2362      block = state->mmu[bank];
2363      block |= ((UINT32) ((state->gimereg[11] >> 4) & 0x03)) << 8;
23562364   }
23572365   else
23582366   {
r9722r9723
23712379     *
23722380     * This is the level where ROM is mapped, according to Tepolt (p21)
23732381     */
2374   if (((block & 0x3f) >= 0x3c) && !coco3_enable_64k && !forceram)
2382   if (((block & 0x3f) >= 0x3c) && !state->enable_64k && !forceram)
23752383   {
23762384      static const UINT8 rommap[4][4] =
23772385      {
r9722r9723
23802388         { 0, 1, 2, 3 },
23812389         { 4, 5, 6, 7 }
23822390      };
2383      block = rommap[coco3_gimereg[0] & 3][(block & 0x3f) - 0x3c];
2391      block = rommap[state->gimereg[0] & 3][(block & 0x3f) - 0x3c];
23842392      result = (block * 0x2000 + offset) | 0x80000000;
23852393   }
23862394   else
r9722r9723
23942402
23952403static void coco3_mmu_update(running_machine *machine, int lowblock, int hiblock)
23962404{
2405   coco_state *state = machine->driver_data<coco_state>();
23972406   static const struct
23982407   {
23992408      offs_t start;
r9722r9723
24292438         if (offset & 0x8000)
24302439            readbank = &cart_rom[offset & ~0x80008000];
24312440         else
2432            readbank = &coco_rom[offset & ~0x80000000];
2441            readbank = &state->rom[offset & ~0x80000000];
24332442         memory_unmap_write(space, bank_info[i].start, bank_info[i].end, 0, 0);
24342443      }
24352444      else
r9722r9723
24552464
24562465READ8_HANDLER(coco3_mmu_r)
24572466{
2467   coco3_state *state = space->machine->driver_data<coco3_state>();
24582468   /* The high two bits are floating (high resistance).  Therefore their
24592469     * value is undefined.  But we are exposing them anyways here
24602470     */
2461   return coco3_mmu[offset];
2471   return state->mmu[offset];
24622472}
24632473
24642474
24652475
24662476WRITE8_HANDLER(coco3_mmu_w)
24672477{
2468   coco3_mmu[offset] = data;
2478   coco3_state *state = space->machine->driver_data<coco3_state>();
2479   state->mmu[offset] = data;
24692480
24702481   /* Did we modify the live MMU bank? */
2471   if ((offset >> 3) == (coco3_gimereg[1] & 1))
2482   if ((offset >> 3) == (state->gimereg[1] & 1))
24722483   {
24732484      offset &= 7;
24742485      coco3_mmu_update(space->machine, offset, (offset == 7) ? 8 : offset);
r9722r9723
24832494
24842495READ8_HANDLER(coco3_gime_r)
24852496{
2497   coco3_state *state = space->machine->driver_data<coco3_state>();
24862498   UINT8 result = 0;
24872499
24882500   switch(offset) {
24892501   case 2:   /* Read pending IRQs */
2490      result = gime_irq;
2502      result = state->gime_irq;
24912503      if (result) {
2492         gime_irq = 0;
2504         state->gime_irq = 0;
24932505         coco3_recalc_irq(space->machine);
24942506      }
24952507      break;
24962508
24972509   case 3:   /* Read pending FIRQs */
2498      result = gime_firq;
2510      result = state->gime_firq;
24992511      if (result) {
2500         gime_firq = 0;
2512         state->gime_firq = 0;
25012513         coco3_recalc_firq(space->machine);
25022514      }
25032515      break;
r9722r9723
25112523      break;
25122524
25132525   default:
2514      result = coco3_gimereg[offset];
2526      result = state->gimereg[offset];
25152527      break;
25162528   }
25172529   return result;
r9722r9723
25212533
25222534WRITE8_HANDLER(coco3_gime_w)
25232535{
2536   coco3_state *state = space->machine->driver_data<coco3_state>();
25242537   /* take note if timer was $0000; see $FF95 for details */
2525   int timer_was_off = (coco3_gimereg[4] == 0x00) && (coco3_gimereg[5] == 0x00);
2526   coco3_gimereg[offset] = data;
2538   int timer_was_off = (state->gimereg[4] == 0x00) && (state->gimereg[5] == 0x00);
2539   state->gimereg[offset] = data;
25272540
25282541   if (LOG_GIME)
25292542      logerror("CoCo3 GIME: $%04x <== $%02x pc=$%04x\n", offset + 0xff90, data, cpu_get_pc(space->cpu));
r9722r9723
25442557            */
25452558         coco3_mmu_update(space->machine, 0, 8);
25462559         {
2547            if (coco3_gimereg[0] & 0x04)
2560            if (state->gimereg[0] & 0x04)
25482561            {
25492562               running_device *device = cococart_device(space->machine);
25502563               memory_install_read8_device_handler(space, device, 0xFF40, 0xFF5F, 0, 0, coco_cartridge_r);
r9722r9723
26322645         /*  $FF95 Timer register LSB
26332646            *         Bits 0-7 Low order eight bits of the timer
26342647            */
2635         if (timer_was_off && (coco3_gimereg[5] != 0x00))
2648         if (timer_was_off && (state->gimereg[5] != 0x00))
26362649                   {
26372650                           /* Writes to $FF95 do not cause the timer to reset, but MESS
26382651                            * will invoke coco3_timer_reset() if $FF94/5 was previously
r9722r9723
27132726static SAM6883_GET_RAMBASE( coco3_sam_get_rambase )
27142727{
27152728   UINT32 video_base;
2716   video_base = coco3_get_video_base(0xE0, 0x3F);
2729   video_base = coco3_get_video_base(device->machine, 0xE0, 0x3F);
27172730   return &messram_get_ptr(device->machine->device("messram"))[video_base % messram_get_size(device->machine->device("messram"))];
27182731}
27192732
r9722r9723
27222735
27232736static SAM6883_SET_MAP_TYPE( coco3_sam_set_maptype )
27242737{
2725   coco3_enable_64k = val;
2738   coco3_state *state = device->machine->driver_data<coco3_state>();
2739   state->enable_64k = val;
27262740   coco3_mmu_update(device->machine, 4, 8);
27272741}
27282742
r9722r9723
28362850   state->pia_2         = machine->device("pia_2");
28372851
28382852   /* clear static variables */
2839   coco_hiresjoy_ca = 1;
2840   coco_hiresjoy_xtransitiontime = attotime_zero;
2841   coco_hiresjoy_ytransitiontime = attotime_zero;
2853   state->hiresjoy_ca = 1;
2854   state->hiresjoy_xtransitiontime = attotime_zero;
2855   state->hiresjoy_ytransitiontime = attotime_zero;
28422856
28432857   /* set up function pointers */
2844   update_keyboard = coco_update_keyboard;
2845   recalc_interrupts = init->recalc_interrupts_;
2858   state->update_keyboard = coco_update_keyboard;
2859   state->recalc_interrupts = init->recalc_interrupts_;
28462860
28472861   /* this timer is used to schedule keyboard updating */
2848   update_keyboard_timer = timer_alloc(machine, coco_update_keyboard_timerproc, NULL);
2862   state->update_keyboard_timer = timer_alloc(machine, coco_update_keyboard_timerproc, NULL);
28492863
28502864   /* these are the timers to delay the MUX switching */
2851   mux_sel1_timer = timer_alloc(machine, coco_update_sel1_timerproc, NULL);
2852   mux_sel2_timer = timer_alloc(machine, coco_update_sel2_timerproc, NULL);
2865   state->mux_sel1_timer = timer_alloc(machine, coco_update_sel1_timerproc, NULL);
2866   state->mux_sel2_timer = timer_alloc(machine, coco_update_sel2_timerproc, NULL);
28532867
28542868   /* setup ROM */
2855   coco_rom = memory_region(machine, "maincpu");
2869   state->rom = memory_region(machine, "maincpu");
28562870
28572871   /* setup default rom bank */
2858   bas_rom_bank = coco_rom;
2872   state->bas_rom_bank = state->rom;
28592873
28602874   /* setup default pointer for botom 32K of ram */
2861   bottom_32k = messram_get_ptr(machine->device("messram"));
2875   state->bottom_32k = messram_get_ptr(machine->device("messram"));
28622876
28632877   /* setup printer output callback */
2864   printer_out = init->printer_out_;
2878   state->printer_out = init->printer_out_;
28652879   if (machine->device<cpu_device>("maincpu")->debug()) {
28662880      machine->device<cpu_device>("maincpu")->debug()->set_dasm_override(coco_dasm_override);
28672881   }
28682882
28692883   /* setup printer input line to "space", this is what a Tandy printer would do */
2870   bitbanger_output_value = 1;
2871   bitbanger_input_value = 0;
2872   dac_value = 0;
2884   state->bitbanger_output_value = 1;
2885   state->bitbanger_input_value = 0;
2886   state->dac_value = 0;
28732887
2874   state_save_register_global(machine, mux_sel1);
2875   state_save_register_global(machine, mux_sel2);
2888   state_save_register_global(machine, state->mux_sel1);
2889   state_save_register_global(machine, state->mux_sel2);
28762890}
28772891
28782892/* Setup for hardware common to CoCo 1/2 & Dragon machines, calls genertic_init_machine, to process */
r9722r9723
29712985
29722986MACHINE_RESET( dgnalpha )
29732987{
2988   coco_state *state = machine->driver_data<coco_state>();
29742989   running_device *fdc = machine->device("wd2797");
29752990   wd17xx_set_complete_command_delay(fdc,20);
29762991
2977   /* dgnalpha_just_reset, is here to flag that we should ignore the first irq generated */
2992   /* state->dgnalpha_just_reset, is here to flag that we should ignore the first irq generated */
29782993   /* by the WD2797, it is reset to 0 after the first inurrupt */
2979   dgnalpha_just_reset=1;
2994   state->dgnalpha_just_reset=1;
29802995
29812996   /* need to specify lightgun crosshairs */
29822997   timer_set(machine, attotime_zero, NULL, 0, update_lightgun_timer_callback);
r9722r9723
30243039
30253040MACHINE_RESET( coco3 )
30263041{
3042   coco3_state *state = machine->driver_data<coco3_state>();
30273043   int i;
30283044
30293045   /* Tepolt verifies that the GIME registers are all cleared on initialization */
3030   coco3_enable_64k = 0;
3031   gime_irq = 0;
3032   gime_firq = 0;
3046   state->enable_64k = 0;
3047   state->gime_irq = 0;
3048   state->gime_firq = 0;
30333049   for (i = 0; i < 8; i++)
30343050   {
3035      coco3_mmu[i] = coco3_mmu[i + 8] = 56 + i;
3036      coco3_gimereg[i] = 0;
3051      state->mmu[i] = state->mmu[i + 8] = 56 + i;
3052      state->gimereg[i] = 0;
30373053   }
30383054   coco3_mmu_update(machine, 0, 8);
30393055}
r9722r9723
30453061
30463062MACHINE_START( coco3 )
30473063{
3064   coco3_state *state = machine->driver_data<coco3_state>();
30483065   machine_init_interface init;
30493066
30503067   /* Setup machine initialization */
r9722r9723
30553072   generic_init_machine(machine, &init);
30563073
30573074   /* CoCo 3 specific function pointers */
3058   update_keyboard = coco3_update_keyboard;
3075   state->update_keyboard = coco3_update_keyboard;
30593076
30603077   coco3_timer_init(machine);
30613078
3062   coco3_interupt_line = 0;
3079   state->interupt_line = 0;
30633080
30643081   /* set up state save variables */
3065   state_save_register_global_array(machine, coco3_mmu);
3066   state_save_register_global_array(machine, coco3_gimereg);
3067   state_save_register_global(machine, coco3_interupt_line);
3068   state_save_register_global(machine, gime_irq);
3069   state_save_register_global(machine, gime_firq);
3082   state_save_register_global_array(machine, state->mmu);
3083   state_save_register_global_array(machine, state->gimereg);
3084   state_save_register_global(machine, state->interupt_line);
3085   state_save_register_global(machine, state->gime_irq);
3086   state_save_register_global(machine, state->gime_firq);
30703087   state_save_register_postload(machine, coco3_state_postload, NULL);
30713088
30723089   /* need to specify lightgun crosshairs */
src/mess/video/coco3.c
r9722r9723
4545 *
4646 *************************************/
4747
48typedef struct _coco3_scanline_record coco3_scanline_record;
49struct _coco3_scanline_record
50{
51   UINT8 ff98;
52   UINT8 ff99;
53   UINT8 ff9a;
54   UINT8 index;
5548
56   UINT8 palette[16];
5749
58   UINT8 data[160];
59};
60
61typedef struct _coco3_video coco3_video;
62struct _coco3_video
63{
64   /* Info set up on initialization */
65   UINT32 composite_palette[64];
66   UINT32 rgb_palette[64];
67   UINT8 fontdata[128][8];
68   emu_timer *gime_fs_timer;
69
70   /* CoCo 3 palette status */
71   UINT8 palette_ram[16];
72   UINT32 palette_colors[16];
73
74   /* Incidentals */
75   UINT32 legacy_video;
76   UINT32 top_border_scanlines;
77   UINT32 display_scanlines;
78   UINT32 video_position;
79   UINT8 line_in_row;
80   UINT8 blink;
81   UINT8 dirty[2];
82   UINT8 video_type;
83
84   /* video state; every scanline the video state for the scanline is copied
85     * here and only rendered in VIDEO_UPDATE */
86   coco3_scanline_record scanlines[384];
87};
88
89static coco3_video *video;
90
91
92
9350/*************************************
9451 *
9552 *  Parameters
r9722r9723
10764 *
10865 *************************************/
10966
110static void color_batch(UINT32 *results, const UINT8 *indexes, int count)
67static void color_batch(coco3_state *state, UINT32 *results, const UINT8 *indexes, int count)
11168{
69   coco3_video *video = state->video;
11270   UINT32 c;
11371   const UINT32 *current_palette;
11472   int is_black_white;
r9722r9723
12482   {
12583      /* Composite/TV */
12684      current_palette = video->composite_palette;
127      is_black_white = (coco3_gimereg[8] & 0x10) ? TRUE : FALSE;
85      is_black_white = (state->gimereg[8] & 0x10) ? TRUE : FALSE;
12886   }
12987
13088   for (i = 0; i < count; i++)
r9722r9723
149107
150108
151109
152static UINT32 color(UINT8 index)
110static UINT32 color(coco3_state *state, UINT8 index)
153111{
154112   UINT32 c;
155   color_batch(&c, &index, 1);
113   color_batch(state, &c, &index, 1);
156114   return c;
157115}
158116
159117
160118
161INLINE UINT8 get_char_info(const coco3_scanline_record *scanline_record,
119INLINE UINT8 get_char_info(coco3_video *video, const coco3_scanline_record *scanline_record,
162120   int i, int has_attrs, UINT32 *bg, UINT32 *fg)
163121{
164122   UINT8 byte, attr, char_data = 0x00;
r9722r9723
225183
226184
227185
228static void wide_text_mode(UINT32 *line, const coco3_scanline_record *scanline_record,
186static void wide_text_mode(coco3_video *video, UINT32 *line, const coco3_scanline_record *scanline_record,
229187   int char_count, int has_attrs)
230188{
231189   int i;
r9722r9723
234192
235193   for (i = 0; i < char_count; i++)
236194   {
237      char_data = get_char_info(scanline_record, i, has_attrs, &bg, &fg);
195      char_data = get_char_info(video, scanline_record, i, has_attrs, &bg, &fg);
238196
239197      line[i * 16 +  0] = line[i * 16 +  1] = (char_data & 0x80) ? fg : bg;
240198      line[i * 16 +  2] = line[i * 16 +  3] = (char_data & 0x40) ? fg : bg;
r9722r9723
249207
250208
251209
252static void narrow_text_mode(UINT32 *line, const coco3_scanline_record *scanline_record,
210static void narrow_text_mode(coco3_video *video, UINT32 *line, const coco3_scanline_record *scanline_record,
253211   int char_count, int has_attrs)
254212{
255213   int i;
r9722r9723
258216
259217   for (i = 0; i < char_count; i++)
260218   {
261      char_data = get_char_info(scanline_record, i, has_attrs, &bg, &fg);
219      char_data = get_char_info(video, scanline_record, i, has_attrs, &bg, &fg);
262220
263221      line[i * 8 + 0] = (char_data & 0x80) ? fg : bg;
264222      line[i * 8 + 1] = (char_data & 0x40) ? fg : bg;
r9722r9723
273231
274232
275233
276INLINE void graphics_mode(UINT32 *RESTRICT line, const coco3_scanline_record *scanline_record,
234INLINE void graphics_mode(coco3_state *state, UINT32 *RESTRICT line, const coco3_scanline_record *scanline_record,
277235   int byte_count, int bpp, int pixel_width)
278236{
279237   int i, j, k;
r9722r9723
281239   UINT32 c;
282240   UINT32 colors[16];
283241
284   color_batch(colors, scanline_record->palette, 1 << bpp);
242   color_batch(state, colors, scanline_record->palette, 1 << bpp);
285243
286244   for (i = 0; i < byte_count; i++)
287245   {
r9722r9723
305263
306264
307265
308static void coco3_render_scanline(bitmap_t *bitmap, int scanline)
266static void coco3_render_scanline(running_machine *machine, bitmap_t *bitmap, int scanline)
309267{
268   coco3_state *state = machine->driver_data<coco3_state>();
269   coco3_video *video = state->video;
310270   const coco3_scanline_record *scanline_record;
311271   UINT32 *line;
312272   UINT32 border_color;
r9722r9723
315275   /* get the basics */
316276   line = BITMAP_ADDR32(bitmap, scanline, 0);
317277   scanline_record = &video->scanlines[scanline];
318   border_color = color(scanline_record->ff9a);
278   border_color = color(state, scanline_record->ff9a);
319279
320280   scanline -= video->top_border_scanlines;
321281   if ((scanline >= 0) && (scanline < video->display_scanlines))
r9722r9723
326286         /* graphics */
327287         switch(scanline_record->ff99 & 0x1F)
328288         {
329            case 0x00:   graphics_mode(&line[64], scanline_record,  16, 1,  4);      break;
330            case 0x01:   graphics_mode(&line[64], scanline_record,  16, 2,  8);      break;
331            case 0x02:   graphics_mode(&line[64], scanline_record,  16, 4, 16);      break;
289            case 0x00:   graphics_mode(state, &line[64], scanline_record,  16, 1,  4);      break;
290            case 0x01:   graphics_mode(state, &line[64], scanline_record,  16, 2,  8);      break;
291            case 0x02:   graphics_mode(state, &line[64], scanline_record,  16, 4, 16);      break;
332292            case 0x03:   graphics_none(&line[64], 512);                        break;
333            case 0x04:   graphics_mode(&line[ 0], scanline_record,  20, 1,  4);      break;
334            case 0x05:   graphics_mode(&line[ 0], scanline_record,  20, 2,  8);      break;
335            case 0x06:   graphics_mode(&line[ 0], scanline_record,  20, 4, 16);      break;
293            case 0x04:   graphics_mode(state, &line[ 0], scanline_record,  20, 1,  4);      break;
294            case 0x05:   graphics_mode(state, &line[ 0], scanline_record,  20, 2,  8);      break;
295            case 0x06:   graphics_mode(state, &line[ 0], scanline_record,  20, 4, 16);      break;
336296            case 0x07:   graphics_none(&line[ 0], 640);                        break;
337            case 0x08:   graphics_mode(&line[64], scanline_record,  32, 1,  2);      break;
338            case 0x09:   graphics_mode(&line[64], scanline_record,  32, 2,  4);      break;
339            case 0x0A:   graphics_mode(&line[64], scanline_record,  32, 4,  8);      break;
297            case 0x08:   graphics_mode(state, &line[64], scanline_record,  32, 1,  2);      break;
298            case 0x09:   graphics_mode(state, &line[64], scanline_record,  32, 2,  4);      break;
299            case 0x0A:   graphics_mode(state, &line[64], scanline_record,  32, 4,  8);      break;
340300            case 0x0B:   graphics_none(&line[64], 512);                        break;
341            case 0x0C:   graphics_mode(&line[ 0], scanline_record,  40, 1,  2);      break;
342            case 0x0D:   graphics_mode(&line[ 0], scanline_record,  40, 2,  4);      break;
343            case 0x0E:   graphics_mode(&line[ 0], scanline_record,  40, 4,  8);      break;
301            case 0x0C:   graphics_mode(state, &line[ 0], scanline_record,  40, 1,  2);      break;
302            case 0x0D:   graphics_mode(state, &line[ 0], scanline_record,  40, 2,  4);      break;
303            case 0x0E:   graphics_mode(state, &line[ 0], scanline_record,  40, 4,  8);      break;
344304            case 0x0F:   graphics_none(&line[ 0], 640);                        break;
345            case 0x10:   graphics_mode(&line[64], scanline_record,  64, 1,  1);      break;
346            case 0x11:   graphics_mode(&line[64], scanline_record,  64, 2,  2);      break;
347            case 0x12:   graphics_mode(&line[64], scanline_record,  64, 4,  4);      break;
305            case 0x10:   graphics_mode(state, &line[64], scanline_record,  64, 1,  1);      break;
306            case 0x11:   graphics_mode(state, &line[64], scanline_record,  64, 2,  2);      break;
307            case 0x12:   graphics_mode(state, &line[64], scanline_record,  64, 4,  4);      break;
348308            case 0x13:   graphics_none(&line[64], 512);                        break;
349            case 0x14:   graphics_mode(&line[ 0], scanline_record,  80, 1,  1);      break;
350            case 0x15:   graphics_mode(&line[ 0], scanline_record,  80, 2,  2);      break;
351            case 0x16:   graphics_mode(&line[ 0], scanline_record,  80, 4,  4);      break;
309            case 0x14:   graphics_mode(state, &line[ 0], scanline_record,  80, 1,  1);      break;
310            case 0x15:   graphics_mode(state, &line[ 0], scanline_record,  80, 2,  2);      break;
311            case 0x16:   graphics_mode(state, &line[ 0], scanline_record,  80, 4,  4);      break;
352312            case 0x17:   graphics_none(&line[ 0], 640);                        break;
353313            case 0x18:   graphics_none(&line[64], 512);                        break;
354            case 0x19:   graphics_mode(&line[64], scanline_record, 128, 2,  1);      break;
355            case 0x1A:   graphics_mode(&line[64], scanline_record, 128, 4,  2);      break;
314            case 0x19:   graphics_mode(state, &line[64], scanline_record, 128, 2,  1);      break;
315            case 0x1A:   graphics_mode(state, &line[64], scanline_record, 128, 4,  2);      break;
356316            case 0x1B:   graphics_none(&line[64], 512);                        break;
357317            case 0x1C:   graphics_none(&line[ 0], 640);                        break;
358            case 0x1D:   graphics_mode(&line[ 0], scanline_record, 160, 2,  1);      break;
359            case 0x1E:   graphics_mode(&line[ 0], scanline_record, 160, 4,  2);      break;
318            case 0x1D:   graphics_mode(state, &line[ 0], scanline_record, 160, 2,  1);      break;
319            case 0x1E:   graphics_mode(state, &line[ 0], scanline_record, 160, 4,  2);      break;
360320            case 0x1F:   graphics_none(&line[ 0], 640);                        break;
361321         }
362322      }
r9722r9723
365325         /* text */
366326         switch(scanline_record->ff99 & 0x15)
367327         {
368            case 0x00:   wide_text_mode(&line[64], scanline_record, 32, FALSE);      break;
369            case 0x01:   wide_text_mode(&line[64], scanline_record, 32, TRUE);      break;
370            case 0x04:   wide_text_mode(&line[ 0], scanline_record, 40, FALSE);      break;
371            case 0x05:   wide_text_mode(&line[ 0], scanline_record, 40, TRUE);      break;
372            case 0x10:   narrow_text_mode(&line[64], scanline_record, 64, FALSE);   break;
373            case 0x11:   narrow_text_mode(&line[64], scanline_record, 64, TRUE);      break;
374            case 0x14:   narrow_text_mode(&line[ 0], scanline_record, 80, FALSE);   break;
375            case 0x15:   narrow_text_mode(&line[ 0], scanline_record, 80, TRUE);      break;
328            case 0x00:   wide_text_mode(video, &line[64], scanline_record, 32, FALSE);      break;
329            case 0x01:   wide_text_mode(video, &line[64], scanline_record, 32, TRUE);      break;
330            case 0x04:   wide_text_mode(video, &line[ 0], scanline_record, 40, FALSE);      break;
331            case 0x05:   wide_text_mode(video, &line[ 0], scanline_record, 40, TRUE);      break;
332            case 0x10:   narrow_text_mode(video, &line[64], scanline_record, 64, FALSE);   break;
333            case 0x11:   narrow_text_mode(video, &line[64], scanline_record, 64, TRUE);      break;
334            case 0x14:   narrow_text_mode(video, &line[ 0], scanline_record, 80, FALSE);   break;
335            case 0x15:   narrow_text_mode(video, &line[ 0], scanline_record, 80, TRUE);      break;
376336         }
377337      }
378338
r9722r9723
397357
398358VIDEO_UPDATE( coco3 )
399359{
360   coco3_state *state = screen->machine->driver_data<coco3_state>();
361   coco3_video *video = state->video;
400362   int i, row;
401363   UINT32 *line;
402364   UINT32 rc = 0;
r9722r9723
417379
418380   /* set all of the palette colors */
419381   for (i = 0; i < 16; i++)
420      video->palette_colors[i] = color(video->palette_ram[i]);
382      video->palette_colors[i] = color(state, video->palette_ram[i]);
421383
422384   if (video->legacy_video)
423385   {
r9722r9723
441403      if (video->dirty[video->video_type])
442404      {
443405         for (row = cliprect->min_y; row <= cliprect->max_y; row++)
444            coco3_render_scanline(bitmap, row);
406            coco3_render_scanline(screen->machine, bitmap, row);
445407         video->dirty[video->video_type] = FALSE;
446408      }
447409      else
r9722r9723
460422 *
461423 *************************************/
462424
463static void coco3_set_dirty(void)
425static void coco3_set_dirty(running_machine *machine)
464426{
427   coco3_state *state = machine->driver_data<coco3_state>();
428   coco3_video *video = state->video;
465429   int i;
466430   for (i = 0; i < ARRAY_LENGTH(video->dirty); i++)
467431      video->dirty[i] = TRUE;
r9722r9723
471435
472436static int coco3_new_frame(running_machine *machine)
473437{
438   coco3_state *state = machine->driver_data<coco3_state>();
439   coco3_video *video = state->video;
474440   int gime_field_sync = 0;
475441
476442   /* changing from non-legacy to legacy video? */
477   if (!video->legacy_video && (coco3_gimereg[0] & 0x80))
478      coco3_set_dirty();
443   if (!video->legacy_video && (state->gimereg[0] & 0x80))
444      coco3_set_dirty(machine);
479445
480   video->legacy_video = (coco3_gimereg[0] & 0x80) ? TRUE : FALSE;
481   video->line_in_row = (coco3_gimereg[12] & 0x0F);
446   video->legacy_video = (state->gimereg[0] & 0x80) ? TRUE : FALSE;
447   video->line_in_row = (state->gimereg[12] & 0x0F);
482448
483449   if (!video->legacy_video)
484450   {
485451      /* CoCo 3 video */
486      switch(coco3_gimereg[9] & 0x60)
452      switch(state->gimereg[9] & 0x60)
487453      {
488454         case 0x00:      /* 192 lines */
489455            video->top_border_scanlines = 26;
r9722r9723
509475            gime_field_sync = video->top_border_scanlines + video->display_scanlines;
510476            break;
511477      }
512      video->video_position = coco3_get_video_base(0xFF, 0xFF);
478      video->video_position = coco3_get_video_base(machine, 0xFF, 0xFF);
513479   }
514480   else
515481   {
r9722r9723
540506
541507static void coco3_prepare_scanline(running_machine *machine, int scanline)
542508{
509   coco3_state *state = machine->driver_data<coco3_state>();
510   coco3_video *video = state->video;
543511   static const UINT32 lines_per_row[] = { 1, 1, 2, 8, 9, 10, 11, ~0 };
544512   static const UINT32 gfx_bytes_per_row[] = { 16, 20, 32, 40, 64, 80, 128, 160 };
545513   UINT32 video_offset, video_data_size;
r9722r9723
554522
555523   /* copy the basics */
556524   scanline_record = &video->scanlines[scanline];
557   memcpy_dirty(&dirty, &scanline_record->ff98, &coco3_gimereg[8], 1);
558   memcpy_dirty(&dirty, &scanline_record->ff99, &coco3_gimereg[9], 1);
559   memcpy_dirty(&dirty, &scanline_record->ff9a, &coco3_gimereg[10], 1);
525   memcpy_dirty(&dirty, &scanline_record->ff98, &state->gimereg[8], 1);
526   memcpy_dirty(&dirty, &scanline_record->ff99, &state->gimereg[9], 1);
527   memcpy_dirty(&dirty, &scanline_record->ff9a, &state->gimereg[10], 1);
560528
561529   /* is this a display scanline? */
562530   scanline -= video->top_border_scanlines;
r9722r9723
567535
568536      /* get ready to copy the video memory; get position and offsets */
569537      video_data = &messram_get_ptr(machine->device("messram"))[video->video_position % messram_get_size(machine->device("messram"))];
570      video_offset = (coco3_gimereg[15] & 0x7F) * 2;
538      video_offset = (state->gimereg[15] & 0x7F) * 2;
571539      video_data_size = sizeof(scanline_record->data);
572540
573541      /* FF9F offsets wrap around every 256 bytes, even if bit 7 is not set.
r9722r9723
581549      video->line_in_row++;
582550
583551      /* do we have to advance to the next row? */
584      if (video->line_in_row >= lines_per_row[coco3_gimereg[8] & 0x07])
552      if (video->line_in_row >= lines_per_row[state->gimereg[8] & 0x07])
585553      {
586554         /* on to the next row */
587555         video->line_in_row = 0;
588556
589         if (coco3_gimereg[15] & 0x80)
557         if (state->gimereg[15] & 0x80)
590558         {
591559            /* FF9F scrolling mode */
592560            bytes_per_row = 256;
593561         }
594         else if (coco3_gimereg[8] & 0x80)
562         else if (state->gimereg[8] & 0x80)
595563         {
596564            /* calc bytes per row for graphics */
597            bytes_per_row = gfx_bytes_per_row[(coco3_gimereg[9] & 0x1C) >> 2];
565            bytes_per_row = gfx_bytes_per_row[(state->gimereg[9] & 0x1C) >> 2];
598566         }
599567         else
600568         {
601569            /* calc bytes per row for text */
602570            bytes_per_row = 32;
603            if (coco3_gimereg[9] & 0x04)
571            if (state->gimereg[9] & 0x04)
604572               bytes_per_row += 8;
605            if (coco3_gimereg[9] & 0x10)
573            if (state->gimereg[9] & 0x10)
606574               bytes_per_row *= 2;
607            if (coco3_gimereg[9] & 0x01)
575            if (state->gimereg[9] & 0x01)
608576               bytes_per_row *= 2;
609577         }
610578
r9722r9723
620588      }
621589   }
622590   if (dirty)
623      coco3_set_dirty();
591      coco3_set_dirty(machine);
624592}
625593
626594
r9722r9723
639607
640608
641609
642UINT32 coco3_get_video_base(UINT8 ff9d_mask, UINT8 ff9e_mask)
610UINT32 coco3_get_video_base(running_machine *machine, UINT8 ff9d_mask, UINT8 ff9e_mask)
643611{
612   coco3_state *state = machine->driver_data<coco3_state>();
644613   /* The purpose of the ff9d_mask and ff9e_mask is to mask out bits that are
645614     * ignored in lo-res mode.  Specifically, $FF9D is masked with $E0, and
646615     * $FF9E is masked with $3F
647616     *
648617     * John Kowalski confirms this behavior
649618     */
650   return   ((offs_t) (coco3_gimereg[14] & ff9e_mask)   * 0x00008)
651      |   ((offs_t) (coco3_gimereg[13] & ff9d_mask)   * 0x00800)
652      |   ((offs_t) (coco3_gimereg[11] & 0x0F)      * 0x80000);
619   return   ((offs_t) (state->gimereg[14] & ff9e_mask)   * 0x00008)
620      |   ((offs_t) (state->gimereg[13] & ff9d_mask)   * 0x00800)
621      |   ((offs_t) (state->gimereg[11] & 0x0F)      * 0x80000);
653622}
654623
655624
r9722r9723
785754
786755static STATE_POSTLOAD( coco3_video_postload )
787756{
788   coco3_set_dirty();
757   coco3_set_dirty(machine);
789758}
790759
791760
r9722r9723
797766
798767static void internal_video_start_coco3(running_machine *machine, m6847_type type)
799768{
769   coco3_state *state = machine->driver_data<coco3_state>();
770   coco3_video *video;
800771   int i;
801772   m6847_config cfg;
802773   const UINT8 *rom;
803774
804775   /* allocate video */
805   video = auto_alloc_clear(machine, coco3_video);
806   coco3_set_dirty();
776   state->video = video = auto_alloc_clear(machine, coco3_video);
777   coco3_set_dirty(machine);
807778
808779   /* initialize palette */
809780   for (i = 0; i < 64; i++)
r9722r9723
867838
868839
869840
870void coco3_vh_blink(void)
841void coco3_vh_blink(running_machine *machine)
871842{
843   coco3_state *state = machine->driver_data<coco3_state>();
844   coco3_video *video = state->video;
872845   video->blink = !video->blink;
873   coco3_set_dirty();
846   coco3_set_dirty(machine);
874847}
src/mess/includes/coco.h
r9722r9723
2929    TYPE DEFINITIONS
3030***************************************************************************/
3131
32typedef struct _coco3_scanline_record coco3_scanline_record;
33struct _coco3_scanline_record
34{
35   UINT8 ff98;
36   UINT8 ff99;
37   UINT8 ff9a;
38   UINT8 index;
39
40   UINT8 palette[16];
41
42   UINT8 data[160];
43};
44
45typedef struct _coco3_video coco3_video;
46struct _coco3_video
47{
48   /* Info set up on initialization */
49   UINT32 composite_palette[64];
50   UINT32 rgb_palette[64];
51   UINT8 fontdata[128][8];
52   emu_timer *gime_fs_timer;
53
54   /* CoCo 3 palette status */
55   UINT8 palette_ram[16];
56   UINT32 palette_colors[16];
57
58   /* Incidentals */
59   UINT32 legacy_video;
60   UINT32 top_border_scanlines;
61   UINT32 display_scanlines;
62   UINT32 video_position;
63   UINT8 line_in_row;
64   UINT8 blink;
65   UINT8 dirty[2];
66   UINT8 video_type;
67
68   /* video state; every scanline the video state for the scanline is copied
69     * here and only rendered in VIDEO_UPDATE */
70   coco3_scanline_record scanlines[384];
71};
72
73
3274class coco_state : public driver_device
3375{
3476public:
r9722r9723
4486   running_device *pia_0;
4587   running_device *pia_1;
4688   running_device *pia_2;
89   UINT8 *rom;
90   int dclg_state;
91   int dclg_output_h;
92   int dclg_output_v;
93   int dclg_timer;
94   UINT8 (*update_keyboard)(running_machine *machine);
95   emu_timer *update_keyboard_timer;
96   emu_timer *mux_sel1_timer;
97   emu_timer *mux_sel2_timer;
98   UINT8 mux_sel1;
99   UINT8 mux_sel2;
100   UINT8 bitbanger_output_value;
101   UINT8 bitbanger_input_value;
102   UINT8 dac_value;
103   int dgnalpha_just_reset;
104   UINT8 *bas_rom_bank;
105   UINT8 *bottom_32k;
106   timer_fired_func recalc_interrupts;
107   int hiresjoy_ca;
108   attotime hiresjoy_xtransitiontime;
109   attotime hiresjoy_ytransitiontime;
110   int dclg_previous_bit;
111   void (*printer_out)(running_machine *machine, int data);
47112};
48113
114class coco3_state : public coco_state
115{
116public:
117   coco3_state(running_machine &machine, const driver_device_config_base &config)
118      : coco_state(machine, config) { }
49119
120   int enable_64k;
121   UINT8 mmu[16];
122   UINT8 interupt_line;
123   emu_timer *gime_timer;
124   UINT8 gimereg[16];
125   UINT8 gime_firq;
126   UINT8 gime_irq;
127   coco3_video *video;
128};
129
130
50131/***************************************************************************
51132    PROTOTYPES
52133***************************************************************************/
r9722r9723
66147VIDEO_START( coco3p );
67148VIDEO_UPDATE( coco3 );
68149WRITE8_HANDLER ( coco3_palette_w );
69UINT32 coco3_get_video_base(UINT8 ff9d_mask, UINT8 ff9e_mask);
70void coco3_vh_blink(void);
150UINT32 coco3_get_video_base(running_machine *machine, UINT8 ff9d_mask, UINT8 ff9e_mask);
151void coco3_vh_blink(running_machine *machine);
71152
72153
73154/*----------- defined in machine/coco.c -----------*/
r9722r9723
87168extern const pia6821_interface dgnalpha_pia_intf_2;
88169extern const sam6883_interface coco_sam_intf;
89170extern const sam6883_interface coco3_sam_intf;
90extern UINT8 coco3_gimereg[16];
91171
92172MACHINE_START( dragon32 );
93173MACHINE_START( dragon64 );
src/mess/drivers/dgn_beta.c
r9722r9723
4141#include "emu.h"
4242#include "cpu/m6809/m6809.h"
4343#include "machine/6821pia.h"
44#include "includes/coco.h"
4544#include "includes/dgn_beta.h"
4645#include "machine/6551.h"
4746#include "formats/coco_dsk.h"
src/mess/drivers/coco.c
r9722r9723
11441144   MDRV_FLOPPY_4_DRIVES_ADD(coco_floppy_config)
11451145MACHINE_CONFIG_END
11461146
1147static MACHINE_CONFIG_START( coco3, coco_state )
1147static MACHINE_CONFIG_START( coco3, coco3_state )
11481148   /* basic machine hardware */
11491149   MDRV_CPU_ADD("maincpu", M6809E, COCO_CPU_SPEED_HZ * 4)        /* 0,894886 MHz */
11501150   MDRV_CPU_PROGRAM_MAP(coco3_map)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team