Previous 15994 Revisions Next

r7377 Tuesday 16th February, 2010 at 16:58:21 UTC by Fabio Priuli
[CBM] converted ted7360 to be a device and updated c16 to use the new code (+ small cleanups here and there)
[src/mess]mess.mak
[src/mess/audio]ted7360.c ted7360.h*
[src/mess/drivers]c128.c c16.c c64.c c65.c cbmb.c clcd.c pet.c vic20.c
[src/mess/includes]c16.h
[src/mess/machine]c16.c
[src/mess/video]ted7360.c ted7360.h vic4567.c vic6567.c

src/mess/audio/ted7360.c
r7376r7377
11/***************************************************************************
22
3  MOS ted 7360 (and sound interface)
4  PeT mess@utanet.at
3    TExt Display 7360
4    PeT mess@utanet.at
55
6  main part in video/
76
7    2010-02: Converted to be a device and merged video/audio emulation
8
9    TODO:
10      - Plenty of clean-ups
11
812***************************************************************************/
13/*
14Metal Oxid Semicontuctor MOS
15Commodore Business Machine CBM
16Textured Display Ted7360
17------------------------
918
197360/8360 (NTSC-M, PAL-B by same chip ?)
208365 PAL-N
218366 PAL-M
22
23Ted7360 used in Commodore C16
24Ted8360 used in Commodore C116/Plus4
25 should be 100% software compatible with Ted7360
26
27video unit (without sprites), dram controller seams to be much like vic6567
28
29PAL/NTSC variants
30
31functions of this chip:
32 memory controller
33 dram controller
34 cpu clock generation with single and double clock switching
35 3 timer
36 1 8bit latched input
37 2 channel sound/noise generator
38 video controller
39 interrupt controller for timer and video
40
41Reasons for this document:
42 document state in mess c16/plus4 emulator
43 base to discuss ted7360 with others (i have no c16 computer anymore)
44
45pal:
46 clock 17734470
47 divided by 5 for base clock (pixel clock changing edges?)
48 312 lines
49 50 hertz vertical refresh
50
51ntsc:
52 clock 14318180
53 divided by 4 for base clock (pixel clock changing edges?)
54 262 lines
55 60 hertz vertical refresh
56
57registers:
58 0xff00 timer 1 low byte
59 0xff01 timer 1 high byte
60 0xff02 timer 2 low byte
61 0xff03 timer 2 high byte
62 0xff04 timer 3 low byte
63 0xff05 timer 3 high byte
64 0xff06
65  bit 7 test?
66  bit 6 ecm on
67  bit 5 hires on
68  bit 4 screen on
69  bit 3 25 raws (0 24 raws)
70  bit 2-0 vertical position
71 0xff07
72  bit 7 reverse off (0 on)
73  bit 6 read only NTSC (0 PAL)
74  bit 5 freeze horicontal position?
75  bit 4 multicolor on
76  bit 3 40 columns (0 38 columns)
77  bit 2-0 horicontal pos
78 0xff08 input latch (0 input low), write reloads latch
79 0xff09 interrupt request
80  7: interrupt
81  6: timer 3
82  5: ?
83  4: timer 2
84  3: timer 1
85  2: lightpen
86  1: rasterline
87  0: 1 (asl quitting)
88 0xff0a interrupt enable
89  7: ?
90  6: timer 3
91  5: ?
92  4: timer 2
93  3: timer 1
94  2: lightpen
95  1: rasterline
96  0: irq rasterline bit 8
97 0xff0b
98  7-0: irq rasterline 7-0
99 0xff0c
100  7-2: 1?
101  1,0: cursorpos bit 9,8
102 0xff0d cursorpos bit 7-0
103 0xff0e tone channel 1: frequency 7-0
104 0xff0f tone channel 2: frequency 7-0
105 0xff10
106  7-2: ?
107  1,0: tone channel 2 bit 9,8
108 0xff11
109  7: sound reload
110  6: tone 2 noise on (tone 2 must be off for noise)
111  5: tone 2 tone on
112  4: tone 1 on
113  3-0: volume 8?-0
114 0xff12
115  7,6: ?
116  5-3: bitmap address bit 15-13
117  2: bitmapmemory?, charactermemory in rom (0 ram)
118  1,0: tone 1 frequency bit 9,8
119 0xff13
120  7-2: chargen address bit 15-11
121  2: chargen address bit 10 (only used when reverse is off)
122  1: single clock in overscan area (0 double clock)
123  0: ram (0)/rom status
124 0xff14
125  7-2: video address bit 15-10
126  1,0: ?
127 0xff15
128  7: ?
129  6-0: backgroundcolor
130 0xff16
131  7: ?
132  6-0: color1
133 0xff17
134  7: ?
135  6-0: color2
136 0xff18
137  7: ?
138  6-0: color3
139 0xff19
140  7: ?
141  6-0: framecolor
142 0xff1a
143  7-2: ?
144  1,0: bitmap reload(cursorpos2) bit 9-8
145 0xff1b bitmap reload bit 7-0
146 0xff1c
147  7-1: 1? (matrix expects this)
148  0: current rasterline bit 8
149 0xff1d current rasterline bit 7-0
150 0xff1e
151  7-0: current rastercolumn /2 (0 begin visible area?)
152 0xff1f cursorblink?
153  7: ?
154  6-3: blink counter
155  2-0: vsub
156 0xff3e write switches to rom
157 0xff3f write switches to dram
158
159memory controller
160 0x8000-0xfcff, 0xff20-0xffff
161  read selection between dram and rom
162 0xff3e-0xff3f write nothing (would change main memory in 16k ram c16)
163
164clock generator
165 in displayed area ted need 3 memory cycles to get data for video chip
166 memory system runs at approximately 4 megahertz
167 so only 1 megahertz is available for the cpu
168 in the other area the clock can be doubled for the cpu
169
170dram controller
171 generator of refresh cycles
172 when are these occuring?
173 vic6567 in each rasterline reads 5 refresh addresses
174
175sound generator
176 2 channels
177 channel 2 can be switched to generate noise
178 volume control (0-8?)
179 tone reload bit?
180 samples ton/noise?
181 frequency=(base clock/32)/(1024-value)
182
183timer
184 timer count down
185 when reaching 0
186  they restart from 0xffff
187  set the interrupt request flag
188 writing to low byte stops timer
189 writing to high byte restarts timer with current value
190
191interrupt controller
192 interrupt sources must be enabled in the enable register to generate
193 an interrupt
194 request flag are set also when not enabled
195 interrupt is generated when rising edge on request and enable
196 quitting of interrupt is done via writing 1 to the request bit
197 what happens with request interrupts when the are enabled?
198
199Video part
200 colors
201  bit 3-0 color
202   black, white, red, cyan
203   purple, green, blue, yellow
204   orange, light orange, pink, light cyan,
205   light violett, light green, light blue, light yellow
206  bit 6-4 luminance (0 dark)
207  r,g,b values from 0 to 127
208   taken from digitized tv screen shot
209   0x06,0x01,0x03, 0x2b,0x2b,0x2b, 0x67,0x0e,0x0f, 0x00,0x3f,0x42,
210   0x57,0x00,0x6d, 0x00,0x4e,0x00, 0x19,0x1c,0x94, 0x38,0x38,0x00,
211   0x56,0x20,0x00, 0x4b,0x28,0x00, 0x16,0x48,0x00, 0x69,0x07,0x2f,
212   0x00,0x46,0x26, 0x06,0x2a,0x80, 0x2a,0x14,0x9b, 0x0b,0x49,0x00,
213
214   0x00,0x03,0x02, 0x3d,0x3d,0x3d, 0x75,0x1e,0x20, 0x00,0x50,0x4f,
215   0x6a,0x10,0x78, 0x04,0x5c,0x00, 0x2a,0x2a,0xa3, 0x4c,0x47,0x00,
216   0x69,0x2f,0x00, 0x59,0x38,0x00, 0x26,0x56,0x00, 0x75,0x15,0x41,
217   0x00,0x58,0x3d, 0x15,0x3d,0x8f, 0x39,0x22,0xae, 0x19,0x59,0x00,
218
219   0x00,0x03,0x04, 0x42,0x42,0x42, 0x7b,0x28,0x20, 0x02,0x56,0x59,
220   0x6f,0x1a,0x82, 0x0a,0x65,0x09, 0x30,0x34,0xa7, 0x50,0x51,0x00,
221   0x6e,0x36,0x00, 0x65,0x40,0x00, 0x2c,0x5c,0x00, 0x7d,0x1e,0x45,
222   0x01,0x61,0x45, 0x1c,0x45,0x99, 0x42,0x2d,0xad, 0x1d,0x62,0x00,
223
224   0x05,0x00,0x02, 0x56,0x55,0x5a, 0x90,0x3c,0x3b, 0x17,0x6d,0x72,
225   0x87,0x2d,0x99, 0x1f,0x7b,0x15, 0x46,0x49,0xc1, 0x66,0x63,0x00,
226   0x84,0x4c,0x0d, 0x73,0x55,0x00, 0x40,0x72,0x00, 0x91,0x33,0x5e,
227   0x19,0x74,0x5c, 0x32,0x59,0xae, 0x59,0x3f,0xc3, 0x32,0x76,0x00,
228
229   0x02,0x01,0x06, 0x84,0x7e,0x85, 0xbb,0x67,0x68, 0x45,0x96,0x96,
230   0xaf,0x58,0xc3, 0x4a,0xa7,0x3e, 0x73,0x73,0xec, 0x92,0x8d,0x11,
231   0xaf,0x78,0x32, 0xa1,0x80,0x20, 0x6c,0x9e,0x12, 0xba,0x5f,0x89,
232   0x46,0x9f,0x83, 0x61,0x85,0xdd, 0x84,0x6c,0xef, 0x5d,0xa3,0x29,
233
234   0x02,0x00,0x0a, 0xb2,0xac,0xb3, 0xe9,0x92,0x92, 0x6c,0xc3,0xc1,
235   0xd9,0x86,0xf0, 0x79,0xd1,0x76, 0x9d,0xa1,0xff, 0xbd,0xbe,0x40,
236   0xdc,0xa2,0x61, 0xd1,0xa9,0x4c, 0x93,0xc8,0x3d, 0xe9,0x8a,0xb1,
237   0x6f,0xcd,0xab, 0x8a,0xb4,0xff, 0xb2,0x9a,0xff, 0x88,0xcb,0x59,
238
239   0x02,0x00,0x0a, 0xc7,0xca,0xc9, 0xff,0xac,0xac, 0x85,0xd8,0xe0,
240   0xf3,0x9c,0xff, 0x92,0xea,0x8a, 0xb7,0xba,0xff, 0xd6,0xd3,0x5b,
241   0xf3,0xbe,0x79, 0xe6,0xc5,0x65, 0xb0,0xe0,0x57, 0xff,0xa4,0xcf,
242   0x89,0xe5,0xc8, 0xa4,0xca,0xff, 0xca,0xb3,0xff, 0xa2,0xe5,0x7a,
243
244   0x01,0x01,0x01, 0xff,0xff,0xff, 0xff,0xf6,0xf2, 0xd1,0xff,0xff,
245   0xff,0xe9,0xff, 0xdb,0xff,0xd3, 0xfd,0xff,0xff, 0xff,0xff,0xa3,
246   0xff,0xff,0xc1, 0xff,0xff,0xb2, 0xfc,0xff,0xa2, 0xff,0xee,0xff,
247   0xd1,0xff,0xff, 0xeb,0xff,0xff, 0xff,0xf8,0xff, 0xed,0xff,0xbc
248
249 video generation
250  column counter from 0 to 39
251  line counter from 0 to 199
252
253  character pointer position/hires: color 0-15 position
254   videoaddr+0x400+(line/8)*40+column
255  color position/hires: color luminance position
256   videoaddr+(line/8)*40+column
257  character bitmap position
258   chargenaddr+(character pointer)+(line&7)
259  bitmap position
260   bitmapaddr+(line/8)*40+column+(line&7)
261
262 normal text mode (reverse off, ecm off, multicolor off, hires off)
263  character pointer based
264   fetch character pointer, fetch character bitmap, fetch color
265  pixel on color (color)&0x7f
266  pixel off color backgroundcolor
267  blinking (synchron to cursor) (color&0x80)
268 reverse text mode (reverse on, ecm off, multicolor off, hires off)
269  character pointer &0x7f
270  character pointer bit 7
271   set
272    pixel off color attribut &0x7f
273    pixel on color backgroundcolor
274   clear
275    like normal text mode
276  blinking (synchron to cursor) (color&0x80)
277 multicolor text mode (ecm off, multicolor on, hires off)
278  reverse ?
279  attribut bit 3 character in multicolor (else monocolor character)
280  pixel on color attribut 0x77
281  0 backgroundcolor
282  1 color1
283  2 color2
284  3 attribut &0x77
285  (color&0x80) ?
286 ecm text mode (ecm on)
287  reverse ?
288  multicolor ? (c64/vic6567 black display?)
289  hires ? (c64/vic6567 black display?)
290  character pointer &0x3f
291  character pointer bit 7,6 select pixel off color
292   0 backgroundcolor ?
293   1 color1?
294   2 color2?
295   3 color3?
296  (color&0x80)?
297 hires (ecm off, multicolor off, hires on)
298  bitmap based
299   fetch bitmap, fetch color, fetch color luminance
300  reverse ?
301  pixel on color
302   6-4: (color luminance) bit 2-0
303   3-0: (color) bit 7-4
304  pixel off color
305   6-4: (color luminance) bit 6-4
306   3-0: (color) bit 3-0
307  (color) bit 7?
308  (color luminance) bit 7?
309 hires multicolor (ecm off, multicolor on, hires on)
310  reverse ?
311  0 backgroundcolor
312  1
313   6-4: (color luminance) bit 2-0
314   3-0: (color) bit 7-4
315  2
316   6-4: (color luminance) bit 6-4
317   3-0: (color) bit 3-0
318  3 color1
319  (color) bit 7?
320  (color luminance) bit 7?
321 scrolling support
322  visible part of the display in fixed position
323  columns 38 mode left 7 and right 9 pixel less displayed
324   but line generation start at the same position as in columns 40 mode
325  lines25 flag top and bottom 4 pixel less displayed ?
326  horicontal scrolling support
327   in columns 38 mode
328    horicontal position 1-7: pixel later started line generation
329    horicontal position 0: 8 pixels later started line generation
330   in columns 40 mode ?
331  vertical scrolling support
332   in lines 24 mode
333    vertical position 1-7: lines later started line generation
334    vertical position 0: 8 lines later started line generation
335   in lines 25 mode?
336    vertial position 3: for correct display
337
338 hardware cursor
339  full 8x8 in (color) color
340  flashing when in multicolor, hires ?
341  flashes with about 1 hertz
342  bitmap reload?
343
344 rasterline/rastercolumn
345  values in registers begin visible area 0
346  vic 6567
347   pal line 0 beginning of vertical refresh
348   ntsc line 0 in bottom frame
349    beginning of 25 lines screen 0x33 (24 lines screen 0x37)
350    beginning of 40 columns line 0x18 (38 columns 0x1f)
351
352 lightpen
353  (where to store values?)
354  i found a lightpen hardware description with a demo and drawing program
355  lightpen must be connected to joy0 (button)
356  demo program:
357   disables interrupt, polles joy0 button (0xfd0d? plus 4 related???)
358   and reads the rasterline value!
359   so i no exact column value reachable!
360*/
10361#include "emu.h"
11362#include "streams.h"
12363
13#include "video/ted7360.h"
364#include "audio/ted7360.h"
14365
15366
367typedef struct _ted7360_state ted7360_state;
368struct _ted7360_state
369{
370   ted_type  type;
371
372   running_device *screen;         // screen which sets bitmap properties
373
374   UINT8 reg[0x20];
375
376   bitmap_t *bitmap;
377
378   int rom;
379
380   int frame_count;
381
382   int lines;
383   int timer1_active, timer2_active, timer3_active;
384   emu_timer *timer1, *timer2, *timer3;
385   int cursor1;
386
387   ted7360_dma_read         dma_read;
388   ted7360_dma_read_rom     dma_read_rom;
389   ted7360_irq              interrupt;      // c16_interrupt
390   ted7360_key_cb           keyboard_cb;   // c16_read_keyboard
391
392   int chargenaddr, bitmapaddr, videoaddr;
393
394   int x_begin, x_end;
395   int y_begin, y_end;
396
397   UINT16 c16_bitmap[2], bitmapmulti[4], mono[2], monoinversed[2], multi[4], ecmcolor[2], colors[5];
398
399   int rasterline, lastline;
400   double rastertime;
401
402
403   /* sound part */
404   int tone1pos, tone2pos,
405   tone1samples, tone2samples,
406   noisesize,        /* number of samples */
407   noisepos,         /* pos of tone */
408   noisesamples;     /* count of samples to give out per tone */
409
410   sound_stream *channel;
411   UINT8 *noise;
412};
413
414/*****************************************************************************
415    CONSTANTS
416*****************************************************************************/
417
418
16419#define VERBOSE_LEVEL 0
17420#define DBG_LOG(N,M,A) \
18421   do { \
19422      if(VERBOSE_LEVEL >= N) \
20423      { \
21424         if( M ) \
22            logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(machine)), (char*) M ); \
425            logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(device->machine)), (char*) M ); \
23426         logerror A; \
24427      } \
25   } while (0)
428   } while(0)
26429
27430
28/* noise channel: look into vic6560.c */
431#define VREFRESHINLINES 28
432
433#define TIMER1HELPER (ted7360->reg[0] | (ted7360->reg[1] << 8))
434#define TIMER2HELPER (ted7360->reg[2] | (ted7360->reg[3] << 8))
435#define TIMER3HELPER (ted7360->reg[4] | (ted7360->reg[5] << 8))
436#define TIMER1 (TIMER1HELPER ? TIMER1HELPER : 0x10000)
437#define TIMER2 (TIMER2HELPER ? TIMER2HELPER : 0x10000)
438#define TIMER3 (TIMER3HELPER ? TIMER3HELPER : 0x10000)
439
440#define TED7360_YPOS            40
441#define RASTERLINE_2_C16(a)    ((a + ted7360->lines - TED7360_YPOS - 5) % ted7360->lines)
442#define C16_2_RASTERLINE(a)    ((a + TED7360_YPOS + 5) % ted7360->lines)
443#define XPOS 8
444#define YPOS 8
445
446#define SCREENON               (ted7360->reg[6] & 0x10)
447#define TEST                   (ted7360->reg[6] & 0x80)
448#define VERTICALPOS            (ted7360->reg[6] & 0x07)
449#define HORICONTALPOS          (ted7360->reg[7] & 0x07)
450#define ECMON                  (ted7360->reg[6] & 0x40)
451#define HIRESON                (ted7360->reg[6] & 0x20)
452#define MULTICOLORON           (ted7360->reg[7] & 0x10)
453#define REVERSEON              (!(ted7360->reg[7] & 0x80))
454
455/* hardware inverts character when bit 7 set (character taken &0x7f) */
456/* instead of fetching character with higher number! */
457#define LINES25     (ted7360->reg[6] & 0x08)     /* else 24 Lines */
458#define LINES       (LINES25 ? 25 : 24)
459#define YSIZE       (LINES * 8)
460#define COLUMNS40   (ted7360->reg[7] & 0x08)     /* else 38 Columns */
461#define COLUMNS     (COLUMNS40 ? 40 : 38)
462#define XSIZE       (COLUMNS * 8)
463
464#define INROM       (ted7360->reg[0x12] & 0x04)
465#define CHARGENADDR (REVERSEON && !HIRESON && !MULTICOLORON ? ((ted7360->reg[0x13] & 0xfc) << 8) : ((ted7360->reg[0x13] & 0xf8) << 8))
466#define BITMAPADDR  ((ted7360->reg[0x12] & 0x38) << 10)
467#define VIDEOADDR   ((ted7360->reg[0x14] & 0xf8) << 8)
468
469#define RASTERLINE  (((ted7360->reg[0xa] & 0x01) << 8) | ted7360->reg[0xb])
470#define CURSOR1POS  (ted7360->reg[0xd] | ((ted7360->reg[0xc] & 0x03) << 8))
471#define CURSOR2POS  (ted7360->reg[0x1b] | ((ted7360->reg[0x1a] & 0x03) << 8))
472#define CURSORRATE  ((ted7360->reg[0x1f] & 0x7c) >> 2)
473
474#define BACKGROUNDCOLOR (ted7360->reg[0x15] & 0x7f)
475#define FOREGROUNDCOLOR (ted7360->reg[0x16] & 0x7f)
476#define MULTICOLOR1     (ted7360->reg[0x17] & 0x7f)
477#define MULTICOLOR2     (ted7360->reg[0x18] & 0x7f)
478#define FRAMECOLOR      (ted7360->reg[0x19] & 0x7f)
479
480#define TED7360_VRETRACERATE ((ted7360->type == TED7360_PAL) ? TED7360PAL_VRETRACERATE : TED7360NTSC_VRETRACERATE)
481#define TED7360_CLOCK        (((ted7360->type == TED7360_PAL) ? TED7360PAL_CLOCK : TED7360NTSC_CLOCK) / 4)
482#define TED7360_LINES        ((ted7360->type == TED7360_PAL) ? TED7360PAL_LINES : TED7360NTSC_LINES)
483
484static attotime TEDTIME_IN_CYCLES(int pal, int cycles)
485{
486   double d = (double)(cycles) / (pal ? TED7360PAL_CLOCK : TED7360NTSC_CLOCK);
487   return double_to_attotime(d);
488}
489
490static int TEDTIME_TO_CYCLES(int pal, attotime t)
491{
492   double d = attotime_to_double(t);
493   return (int)((d) * (pal ? TED7360PAL_CLOCK : TED7360NTSC_CLOCK));
494}
495
496/*****************************************************************************
497    INLINE FUNCTIONS
498*****************************************************************************/
499
500INLINE ted7360_state *get_safe_token( running_device *device )
501{
502   assert(device != NULL);
503   assert(device->token != NULL);
504   assert(device->type == TED7360);
505
506   return (ted7360_state *)device->token;
507}
508
509INLINE const ted7360_interface *get_interface( running_device *device )
510{
511   assert(device != NULL);
512   assert((device->type == TED7360));
513   return (const ted7360_interface *) device->baseconfig().static_config;
514}
515
516/*****************************************************************************
517    IMPLEMENTATION
518*****************************************************************************/
519
520static void ted7360_soundport_w( running_device *device, int offset, int data );
521
522static void ted7360_set_interrupt( running_machine *machine, int mask, ted7360_state *ted7360 )
523{
524   /* kernel itself polls for timer 2 shot (interrupt disabled!) when cassette loading */
525   ted7360->reg[9] |= mask;
526   if ((ted7360->reg[0xa] & ted7360->reg[9] & 0x5e))
527   {
528      if (!(ted7360->reg[9] & 0x80))
529      {
530         //DBG_LOG(1, "ted7360", ("irq start %.2x\n", mask));
531         ted7360->reg[9] |= 0x80;
532         ted7360->interrupt(machine, 1);
533      }
534   }
535   ted7360->reg[9] |= mask;
536}
537
538static void ted7360_clear_interrupt( running_device *device, int mask )
539{
540   ted7360_state *ted7360 = get_safe_token(device);
541
542   ted7360->reg[9] &= ~mask;
543   if ((ted7360->reg[9] & 0x80) && !(ted7360->reg[9] & ted7360->reg[0xa] & 0x5e))
544   {
545      DBG_LOG(1, "ted7360", ("irq end %.2x\n", mask));
546      ted7360->reg[9] &= ~0x80;
547      ted7360->interrupt(device->machine, 0);
548   }
549}
550
551static int ted7360_rastercolumn( running_device *device )
552{
553   ted7360_state *ted7360 = get_safe_token(device);
554   return (int) ((attotime_to_double(timer_get_time(device->machine)) - ted7360->rastertime) * TED7360_VRETRACERATE * ted7360->lines * 57 * 8 + 0.5);
555}
556
557static TIMER_CALLBACK(ted7360_timer_timeout)
558{
559   ted7360_state *ted7360 = (ted7360_state *)ptr;
560   int which = param;
561
562   //DBG_LOG(3, "ted7360 ", ("timer %d timeout\n", which));
563   switch (which)
564   {
565   case 1:
566      // proved by digisound of several intros like eoroidpro
567      timer_adjust_oneshot(ted7360->timer1, TEDTIME_IN_CYCLES((ted7360->type == TED7360_PAL), TIMER1), 1);
568      ted7360->timer1_active = 1;
569      ted7360_set_interrupt(machine, 0x08, ted7360);
570      break;
571   case 2:
572      timer_adjust_oneshot(ted7360->timer2, TEDTIME_IN_CYCLES((ted7360->type == TED7360_PAL), 0x10000), 2);
573      ted7360->timer2_active = 1;
574      ted7360_set_interrupt(machine, 0x10, ted7360);
575      break;
576   case 3:
577      timer_adjust_oneshot(ted7360->timer3, TEDTIME_IN_CYCLES((ted7360->type == TED7360_PAL), 0x10000), 3);
578      ted7360->timer3_active = 1;
579      ted7360_set_interrupt(machine, 0x40, ted7360);
580      break;
581   }
582}
583
584static void ted7360_draw_character( running_device *device, int ybegin, int yend, int ch, int yoff, int xoff, UINT16 *color )
585{
586   ted7360_state *ted7360 = get_safe_token(device);
587   int y, code;
588
589   for (y = ybegin; y <= yend; y++)
590   {
591      if (INROM)
592         code = ted7360->dma_read_rom(device->machine, ted7360->chargenaddr + ch * 8 + y);
593      else
594         code = ted7360->dma_read(device->machine, ted7360->chargenaddr + ch * 8 + y);
595
596      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 0 + xoff) = color[code >> 7];
597      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 1 + xoff) = color[(code >> 6) & 1];
598      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 2 + xoff) = color[(code >> 5) & 1];
599      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 3 + xoff) = color[(code >> 4) & 1];
600      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 4 + xoff) = color[(code >> 3) & 1];
601      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 5 + xoff) = color[(code >> 2) & 1];
602      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 6 + xoff) = color[(code >> 1) & 1];
603      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 7 + xoff) = color[code & 1];
604   }
605}
606
607static void ted7360_draw_character_multi( running_device *device, int ybegin, int yend, int ch, int yoff, int xoff )
608{
609   ted7360_state *ted7360 = get_safe_token(device);
610   int y, code;
611
612   for (y = ybegin; y <= yend; y++)
613   {
614      if (INROM)
615         code = ted7360->dma_read_rom(device->machine, ted7360->chargenaddr + ch * 8 + y);
616      else
617         code = ted7360->dma_read(device->machine, ted7360->chargenaddr + ch * 8 + y);
618
619      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 0 + xoff) =
620         *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 1 + xoff) = ted7360->multi[code >> 6];
621      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 2 + xoff) =
622         *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 3 + xoff) = ted7360->multi[(code >> 4) & 3];
623      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 4 + xoff) =
624         *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 5 + xoff) = ted7360->multi[(code >> 2) & 3];
625      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 6 + xoff) =
626         *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 7 + xoff) = ted7360->multi[code & 3];
627   }
628}
629
630static void ted7360_draw_bitmap( running_device *device, int ybegin, int yend, int ch, int yoff, int xoff )
631{
632   ted7360_state *ted7360 = get_safe_token(device);
633   int y, code;
634
635   for (y = ybegin; y <= yend; y++)
636   {
637      code = ted7360->dma_read(device->machine, ted7360->bitmapaddr + ch * 8 + y);
638      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 0 + xoff) = ted7360->c16_bitmap[code >> 7];
639      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 1 + xoff) = ted7360->c16_bitmap[(code >> 6) & 1];
640      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 2 + xoff) = ted7360->c16_bitmap[(code >> 5) & 1];
641      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 3 + xoff) = ted7360->c16_bitmap[(code >> 4) & 1];
642      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 4 + xoff) = ted7360->c16_bitmap[(code >> 3) & 1];
643      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 5 + xoff) = ted7360->c16_bitmap[(code >> 2) & 1];
644      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 6 + xoff) = ted7360->c16_bitmap[(code >> 1) & 1];
645      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 7 + xoff) = ted7360->c16_bitmap[code & 1];
646   }
647}
648
649static void ted7360_draw_bitmap_multi( running_device *device, int ybegin, int yend, int ch, int yoff, int xoff )
650{
651   ted7360_state *ted7360 = get_safe_token(device);
652   int y, code;
653
654   for (y = ybegin; y <= yend; y++)
655   {
656      code = ted7360->dma_read(device->machine, ted7360->bitmapaddr + ch * 8 + y);
657
658      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 0 + xoff) =
659         *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 1 + xoff) = ted7360->bitmapmulti[code >> 6];
660      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 2 + xoff) =
661         *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 3 + xoff) = ted7360->bitmapmulti[(code >> 4) & 3];
662      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 4 + xoff) =
663         *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 5 + xoff) = ted7360->bitmapmulti[(code >> 2) & 3];
664      *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 6 + xoff) =
665         *BITMAP_ADDR16(ted7360->bitmap, y + yoff, 7 + xoff) = ted7360->bitmapmulti[code & 3];
666   }
667}
668
669static void ted7360_draw_cursor( running_device *device, int ybegin, int yend, int yoff, int xoff, int color )
670{
671   ted7360_state *ted7360 = get_safe_token(device);
672   int y;
673
674   for (y = ybegin; y <= yend; y++)
675   {
676      memset16(BITMAP_ADDR16(ted7360->bitmap, yoff + y, xoff), color, 8);
677   }
678}
679
680static void ted7360_drawlines( running_device *device, int first, int last )
681{
682   ted7360_state *ted7360 = get_safe_token(device);
683   int line, vline, end;
684   int attr, ch, c1, c2, ecm;
685   int offs, yoff, xoff, ybegin, yend, xbegin, xend;
686   int i;
687
688   ted7360->lastline = last;
689
690   /* top part of display not rastered */
691   first -= TED7360_YPOS;
692   last -= TED7360_YPOS;
693   if ((first >= last) || (last <= 0))
694      return;
695   if (first < 0)
696      first = 0;
697
698   if (!SCREENON)
699   {
700      for (line = first; (line < last) && (line < ted7360->bitmap->height); line++)
701         memset16(BITMAP_ADDR16(ted7360->bitmap, line, 0), 0, ted7360->bitmap->width);
702      return;
703   }
704
705   if (COLUMNS40)
706      xbegin = XPOS, xend = xbegin + 320;
707   else
708      xbegin = XPOS + 7, xend = xbegin + 304;
709
710   if (last < ted7360->y_begin)
711      end = last;
712   else
713      end = ted7360->y_begin + YPOS;
714   {
715      for (line = first; line < end; line++)
716         memset16(BITMAP_ADDR16(ted7360->bitmap, line, 0), FRAMECOLOR, ted7360->bitmap->width);
717   }
718   if (LINES25)
719      vline = line - ted7360->y_begin - YPOS;
720   else
721      vline = line - ted7360->y_begin - YPOS + 8 - VERTICALPOS;
722
723   if (last < ted7360->y_end + YPOS)
724      end = last;
725   else
726      end = ted7360->y_end + YPOS;
727
728   for (; line < end; vline = (vline + 8) & ~7, line = line + 1 + yend - ybegin)
729   {
730      offs = (vline >> 3) * 40;
731      ybegin = vline & 7;
732      yoff = line - ybegin;
733      yend = (yoff + 7 < end) ? 7 : (end - yoff - 1);
734      /* rendering 39 characters */
735      /* left and right borders are overwritten later */
736
737      for (xoff = ted7360->x_begin + XPOS; xoff < ted7360->x_end + XPOS; xoff += 8, offs++)
738      {
739         if (HIRESON)
740         {
741            ch = ted7360->dma_read(device->machine, (ted7360->videoaddr | 0x400) + offs);
742            attr = ted7360->dma_read(device->machine, ted7360->videoaddr + offs);
743            c1 = ((ch >> 4) & 0xf) | (attr << 4);
744            c2 = (ch & 0xf) | (attr & 0x70);
745            ted7360->bitmapmulti[1] = ted7360->c16_bitmap[1] = c1 & 0x7f;
746            ted7360->bitmapmulti[2] = ted7360->c16_bitmap[0] = c2 & 0x7f;
747            if (MULTICOLORON)
748            {
749               ted7360_draw_bitmap_multi(device, ybegin, yend, offs, yoff, xoff);
750            }
751            else
752            {
753               ted7360_draw_bitmap(device, ybegin, yend, offs, yoff, xoff);
754            }
755         }
756         else
757         {
758            ch = ted7360->dma_read(device->machine, (ted7360->videoaddr | 0x400) + offs);
759            attr = ted7360->dma_read(device->machine, ted7360->videoaddr + offs);
760            // levente harsfalvi's docu says cursor off in ecm and multicolor
761            if (ECMON)
762            {
763               // hardware reverse off
764               ecm = ch >> 6;
765               ted7360->ecmcolor[0] = ted7360->colors[ecm];
766               ted7360->ecmcolor[1] = attr & 0x7f;
767               ted7360_draw_character(device, ybegin, yend, ch & ~0xc0, yoff, xoff, ted7360->ecmcolor);
768            }
769            else if (MULTICOLORON)
770            {
771               // hardware reverse off
772               if (attr & 8)
773               {
774                  ted7360->multi[3] = attr & 0x77;
775                  ted7360_draw_character_multi(device, ybegin, yend, ch, yoff, xoff);
776               }
777               else
778               {
779                  ted7360->mono[1] = attr & 0x7f;
780                  ted7360_draw_character(device, ybegin, yend, ch, yoff, xoff, ted7360->mono);
781               }
782            }
783            else if (ted7360->cursor1 && (offs == CURSOR1POS))
784            {
785               ted7360_draw_cursor(device, ybegin, yend, yoff, xoff, attr & 0x7f);
786            }
787            else if (REVERSEON && (ch & 0x80))
788            {
789               ted7360->monoinversed[0] = attr & 0x7f;
790               if (ted7360->cursor1 && (attr & 0x80))
791                  ted7360_draw_cursor(device, ybegin, yend, yoff, xoff, ted7360->monoinversed[0]);
792               else
793                  ted7360_draw_character(device, ybegin, yend, ch & ~0x80, yoff, xoff, ted7360->monoinversed);
794            }
795            else
796            {
797               ted7360->mono[1] = attr & 0x7f;
798               if (ted7360->cursor1 && (attr & 0x80))
799                  ted7360_draw_cursor(device, ybegin, yend, yoff, xoff, ted7360->mono[0]);
800               else
801                  ted7360_draw_character(device, ybegin, yend, ch, yoff, xoff, ted7360->mono);
802            }
803         }
804      }
805
806      for (i = ybegin; i <= yend; i++)
807      {
808         memset16(BITMAP_ADDR16(ted7360->bitmap, yoff + i, 0), FRAMECOLOR, xbegin);
809         memset16(BITMAP_ADDR16(ted7360->bitmap, yoff + i, xend), FRAMECOLOR, ted7360->bitmap->width - xend);
810      }
811   }
812
813   if (last < ted7360->bitmap->height)
814      end = last;
815   else
816      end = ted7360->bitmap->height;
817
818   for (; line < end; line++)
819   {
820      memset16(BITMAP_ADDR16(ted7360->bitmap, line, 0), FRAMECOLOR, ted7360->bitmap->width);
821   }
822}
823
824
825WRITE8_DEVICE_HANDLER( ted7360_port_w )
826{
827   ted7360_state *ted7360 = get_safe_token(device);
828   int old;
829
830   if ((offset != 8) && ((offset < 0x15) || (offset > 0x19)))
831   {
832      DBG_LOG(1, "ted7360_port_w", ("%.2x:%.2x\n", offset, data));
833   }
834
835   switch (offset)
836   {
837   case 0xe:
838   case 0xf:
839   case 0x10:
840   case 0x11:
841   case 0x12:
842      ted7360_soundport_w(device, offset, data);
843      break;
844   }
845   switch (offset)
846   {
847   case 0:                     /* stop timer 1 */
848      ted7360->reg[offset] = data;
849
850      if (ted7360->timer1_active)
851      {
852         ted7360->reg[1] = TEDTIME_TO_CYCLES((ted7360->type == TED7360_PAL), timer_timeleft(ted7360->timer1)) >> 8;
853         timer_reset(ted7360->timer1, attotime_never);
854         ted7360->timer1_active = 0;
855      }
856      break;
857   case 1:                     /* start timer 1 */
858      ted7360->reg[offset] = data;
859      timer_adjust_oneshot(ted7360->timer1, TEDTIME_IN_CYCLES((ted7360->type == TED7360_PAL), TIMER1), 1);
860      ted7360->timer1_active = 1;
861      break;
862   case 2:                     /* stop timer 2 */
863      ted7360->reg[offset] = data;
864      if (ted7360->timer2_active)
865      {
866         ted7360->reg[3] = TEDTIME_TO_CYCLES((ted7360->type == TED7360_PAL), timer_timeleft(ted7360->timer2)) >> 8;
867         timer_reset(ted7360->timer2, attotime_never);
868         ted7360->timer2_active = 0;
869      }
870      break;
871   case 3:                     /* start timer 2 */
872      ted7360->reg[offset] = data;
873      timer_adjust_oneshot(ted7360->timer2, TEDTIME_IN_CYCLES((ted7360->type == TED7360_PAL), TIMER2), 2);
874      ted7360->timer2_active = 1;
875      break;
876   case 4:                     /* stop timer 3 */
877      ted7360->reg[offset] = data;
878      if (ted7360->timer3_active)
879      {
880         ted7360->reg[5] = TEDTIME_TO_CYCLES((ted7360->type == TED7360_PAL), timer_timeleft(ted7360->timer3)) >> 8;
881         timer_reset(ted7360->timer3, attotime_never);
882         ted7360->timer3_active = 0;
883      }
884      break;
885   case 5:                     /* start timer 3 */
886      ted7360->reg[offset] = data;
887      timer_adjust_oneshot(ted7360->timer3, TEDTIME_IN_CYCLES((ted7360->type == TED7360_PAL), TIMER3), 3);
888      ted7360->timer3_active = 1;
889      break;
890   case 6:
891      if (ted7360->reg[offset] != data)
892      {
893         ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
894         ted7360->reg[offset] = data;
895         if (LINES25)
896         {
897            ted7360->y_begin = 0;
898            ted7360->y_end = ted7360->y_begin + 200;
899         }
900         else
901         {
902            ted7360->y_begin = 4;
903            ted7360->y_end = ted7360->y_begin + 192;
904         }
905         ted7360->chargenaddr = CHARGENADDR;
906      }
907      break;
908   case 7:
909      if (ted7360->reg[offset] != data)
910      {
911         ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
912         ted7360->reg[offset] = data;
913         if (COLUMNS40)
914         {
915            ted7360->x_begin = 0;
916            ted7360->x_end = ted7360->x_begin + 320;
917         }
918         else
919         {
920            ted7360->x_begin = HORICONTALPOS;
921            ted7360->x_end = ted7360->x_begin + 320;
922         }
923         DBG_LOG(3, "ted7360_port_w", ("%s %s\n", data & 0x40 ? "ntsc" : "pal", data & 0x20 ? "hori freeze" : ""));
924         ted7360->chargenaddr = CHARGENADDR;
925      }
926      break;
927   case 8:
928      ted7360->reg[offset] = ted7360->keyboard_cb(device->machine, data);
929      break;
930   case 9:
931      if (data & 0x08)
932         ted7360_clear_interrupt(device, 8);
933      if (data & 0x10)
934         ted7360_clear_interrupt(device, 0x10);
935      if (data & 0x40)
936         ted7360_clear_interrupt(device, 0x40);
937      if (data & 0x02)
938         ted7360_clear_interrupt(device, 2);
939      break;
940   case 0xa:
941      old = data;
942      ted7360->reg[offset] = data | 0xa0;
943#if 0
944      ted7360->reg[9] = (ted7360->reg[9] & 0xa1) | (ted7360->reg[9] & data & 0x5e);
945      if (ted7360->reg[9] & 0x80)
946         ted7360_clear_interrupt(device, 0);
947#endif
948      if ((data ^ old) & 1)
949      {
950         /* DBG_LOG(1,"set rasterline hi",("soll:%d\n",RASTERLINE)); */
951      }
952      break;
953   case 0xb:
954      if (data != ted7360->reg[offset])
955      {
956         ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
957         ted7360->reg[offset] = data;
958         /*  DBG_LOG(1,"set rasterline lo",("soll:%d\n",RASTERLINE)); */
959      }
960      break;
961   case 0xc:
962   case 0xd:
963      if (ted7360->reg[offset] != data)
964      {
965         ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
966         ted7360->reg[offset] = data;
967      }
968      break;
969   case 0x12:
970      if (ted7360->reg[offset] != data)
971      {
972         ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
973         ted7360->reg[offset] = data;
974         ted7360->bitmapaddr = BITMAPADDR;
975         ted7360->chargenaddr = CHARGENADDR;
976         DBG_LOG(3, "ted7360_port_w", ("bitmap %.4x %s\n",  BITMAPADDR, INROM ? "rom" : "ram"));
977      }
978      break;
979   case 0x13:
980      if (ted7360->reg[offset] != data)
981      {
982         ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
983         ted7360->reg[offset] = data;
984         ted7360->chargenaddr = CHARGENADDR;
985         DBG_LOG(3, "ted7360_port_w", ("chargen %.4x %s %d\n", CHARGENADDR, data & 2 ? "" : "doubleclock", data & 1));
986      }
987      break;
988   case 0x14:
989      if (ted7360->reg[offset] != data)
990      {
991         ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
992         ted7360->reg[offset] = data;
993         ted7360->videoaddr = VIDEOADDR;
994         DBG_LOG(3, "ted7360_port_w", ("videoram %.4x\n", VIDEOADDR));
995      }
996      break;
997   case 0x15:                     /* backgroundcolor */
998      if (ted7360->reg[offset] != data)
999      {
1000         ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
1001         ted7360->reg[offset] = data;
1002         ted7360->monoinversed[1] = ted7360->mono[0] = ted7360->bitmapmulti[0] = ted7360->multi[0] = ted7360->colors[0] = BACKGROUNDCOLOR;
1003      }
1004      break;
1005   case 0x16:                     /* foregroundcolor */
1006      if (ted7360->reg[offset] != data)
1007      {
1008         ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
1009         ted7360->reg[offset] = data;
1010         ted7360->bitmapmulti[3] = ted7360->multi[1] = ted7360->colors[1] = FOREGROUNDCOLOR;
1011      }
1012      break;
1013   case 0x17:                     /* multicolor 1 */
1014      if (ted7360->reg[offset] != data)
1015      {
1016         ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
1017         ted7360->reg[offset] = data;
1018         ted7360->multi[2] = ted7360->colors[2] = MULTICOLOR1;
1019      }
1020      break;
1021   case 0x18:                     /* multicolor 2 */
1022      if (ted7360->reg[offset] != data)
1023      {
1024         ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
1025         ted7360->reg[offset] = data;
1026         ted7360->colors[3] = MULTICOLOR2;
1027      }
1028      break;
1029   case 0x19:                     /* framecolor */
1030      if (ted7360->reg[offset] != data)
1031      {
1032         ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
1033         ted7360->reg[offset] = data;
1034         ted7360->colors[4] = FRAMECOLOR;
1035      }
1036      break;
1037   case 0x1c:
1038      ted7360->reg[offset] = data;         /*? */
1039      DBG_LOG(1, "ted7360_port_w", ("write to rasterline high %.2x\n",
1040                              data));
1041      break;
1042   case 0x1f:
1043      ted7360->reg[offset] = data;
1044      DBG_LOG(1, "ted7360_port_w", ("write to cursorblink %.2x\n", data));
1045      break;
1046   default:
1047      ted7360->reg[offset] = data;
1048      break;
1049   }
1050}
1051
1052READ8_DEVICE_HANDLER( ted7360_port_r )
1053{
1054   ted7360_state *ted7360 = get_safe_token(device);
1055   int val = 0;
1056
1057   switch (offset)
1058   {
1059   case 0:
1060      if (ted7360->timer1)
1061         val = TEDTIME_TO_CYCLES((ted7360->type == TED7360_PAL), timer_timeleft(ted7360->timer1)) & 0xff;
1062      else
1063         val = ted7360->reg[offset];
1064      break;
1065   case 1:
1066      if (ted7360->timer1)
1067         val = TEDTIME_TO_CYCLES((ted7360->type == TED7360_PAL), timer_timeleft(ted7360->timer1)) >> 8;
1068      else
1069         val = ted7360->reg[offset];
1070      break;
1071   case 2:
1072      if (ted7360->timer2)
1073         val = TEDTIME_TO_CYCLES((ted7360->type == TED7360_PAL), timer_timeleft(ted7360->timer2)) & 0xff;
1074      else
1075         val = ted7360->reg[offset];
1076      break;
1077   case 3:
1078      if (ted7360->timer2)
1079         val = TEDTIME_TO_CYCLES((ted7360->type == TED7360_PAL), timer_timeleft(ted7360->timer2)) >> 8;
1080      else
1081         val = ted7360->reg[offset];
1082      break;
1083   case 4:
1084      if (ted7360->timer3)
1085         val = TEDTIME_TO_CYCLES((ted7360->type == TED7360_PAL), timer_timeleft(ted7360->timer3)) & 0xff;
1086      else
1087         val = ted7360->reg[offset];
1088      break;
1089   case 5:
1090      if (ted7360->timer3)
1091         val = TEDTIME_TO_CYCLES((ted7360->type == TED7360_PAL), timer_timeleft(ted7360->timer3)) >> 8;
1092      else
1093         val = ted7360->reg[offset];
1094      break;
1095   case 7:
1096      val = (ted7360->reg[offset] & ~0x40);
1097      if (ted7360->type == TED7360_NTSC)
1098         val |= 0x40;
1099      break;
1100   case 9:
1101      val = ted7360->reg[offset] | 1;
1102      break;
1103   case 0xa:
1104      val = ted7360->reg[offset];
1105      break;
1106   case 0xb:
1107      val = ted7360->reg[offset];
1108      break;
1109   case 0x0c:
1110      val = ted7360->reg[offset] |= 0xfc;
1111      break;
1112   case 0x13:
1113      val = ted7360->reg[offset] & ~1;
1114      if (ted7360->rom)
1115         val |= 1;
1116      break;
1117   case 0x1c:                     /*rasterline */
1118      ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
1119      val = ((RASTERLINE_2_C16(ted7360->rasterline) & 0x100) >> 8) | 0xfe;   /* expected by matrix */
1120      break;
1121   case 0x1d:                     /*rasterline */
1122      ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
1123      val = RASTERLINE_2_C16(ted7360->rasterline) & 0xff;
1124      break;
1125   case 0x1e:                     /*rastercolumn */
1126      val = ted7360_rastercolumn(device) / 2;   /* pengo >=0x99 */
1127      break;
1128   case 0x1f:
1129      val = ((ted7360->rasterline & 7) << 4) | (ted7360->reg[offset] & 0x0f);
1130      DBG_LOG(1, "ted7360_port_w", ("read from cursorblink %.2x\n", val));
1131      break;
1132   default:
1133      val = ted7360->reg[offset];
1134      break;
1135   }
1136
1137   if ((offset != 8) && (offset >= 6) && (offset != 0x1c) && (offset != 0x1d) && (offset != 9) && ((offset < 0x15) || (offset > 0x19)))
1138   {
1139      DBG_LOG(1, "ted7360_port_r", ("%.2x:%.2x\n", offset, val));
1140   }
1141
1142   return val;
1143}
1144
1145WRITE_LINE_DEVICE_HANDLER( ted7360_rom_switch_w )
1146{
1147   ted7360_state *ted7360 = get_safe_token(device);
1148   ted7360->rom = state;
1149}
1150
1151READ_LINE_DEVICE_HANDLER( ted7360_rom_switch_r )
1152{
1153   ted7360_state *ted7360 = get_safe_token(device);
1154   return ted7360->rom;
1155}
1156
1157void ted7360_frame_interrupt_gen( running_device *device )
1158{
1159   ted7360_state *ted7360 = get_safe_token(device);
1160
1161   if ((ted7360->reg[0x1f] & 0xf) >= 0x0f)
1162   {
1163      /*  if (ted7360->frame_count >= CURSORRATE) */
1164      ted7360->cursor1 ^= 1;
1165      ted7360->reg[0x1f] &= ~0xf;
1166      ted7360->frame_count = 0;
1167   }
1168   else
1169      ted7360->reg[0x1f]++;
1170}
1171
1172void ted7360_raster_interrupt_gen( running_device *device )
1173{
1174   ted7360_state *ted7360 = get_safe_token(device);
1175
1176   ted7360->rasterline++;
1177   ted7360->rastertime = attotime_to_double(timer_get_time(device->machine));
1178   if (ted7360->rasterline >= ted7360->lines)
1179   {
1180      ted7360->rasterline = 0;
1181      ted7360_drawlines(device, ted7360->lastline, TED7360_LINES);
1182      ted7360->lastline = 0;
1183   }
1184
1185   if (ted7360->rasterline == C16_2_RASTERLINE(RASTERLINE))
1186   {
1187      ted7360_drawlines(device, ted7360->lastline, ted7360->rasterline);
1188      ted7360_set_interrupt(device->machine, 2, ted7360);
1189   }
1190}
1191
1192UINT32 ted7360_video_update( running_device *device, bitmap_t *bitmap, const rectangle *cliprect )
1193{
1194   ted7360_state *ted7360 = get_safe_token(device);
1195
1196   copybitmap(bitmap, ted7360->bitmap, 0, 0, 0, 0, cliprect);
1197   return 0;
1198}
1199
1200
1201/* Sound emulation */
1202
291203#define NOISE_BUFFER_SIZE_SEC 5
301204
31#define TONE_ON (!(ted7360[0x11]&0x80))      /* or tone update!? */
32#define TONE1_ON ((ted7360[0x11]&0x10))
33#define TONE1_VALUE (ted7360[0xe]|((ted7360[0x12]&3)<<8))
34#define TONE2_ON ((ted7360[0x11]&0x20))
35#define TONE2_VALUE (ted7360[0xf]|((ted7360[0x10]&3)<<8))
36#define VOLUME (ted7360[0x11]&0x0f)
37#define NOISE_ON (ted7360[0x11]&0x40)
1205#define TONE_ON         (!(ted7360->reg[0x11] & 0x80))      /* or tone update!? */
1206#define TONE1_ON        ((ted7360->reg[0x11] & 0x10))
1207#define TONE1_VALUE     (ted7360->reg[0x0e] | ((ted7360->reg[0x12] & 3) << 8))
1208#define TONE2_ON        ((ted7360->reg[0x11] & 0x20))
1209#define TONE2_VALUE     (ted7360->reg[0x0f] | ((ted7360->reg[0x10] & 3) << 8))
1210#define VOLUME          (ted7360->reg[0x11] & 0x0f)
1211#define NOISE_ON        (ted7360->reg[0x11] & 0x40)
381212
391213/*
401214 * pal 111860.781
411215 * ntsc 111840.45
421216 */
43#define TONE_FREQUENCY(reg) ((TED7360_CLOCK>>3)/(1024-reg))
44#define TONE_FREQUENCY_MIN (TONE_FREQUENCY(0))
45#define NOISE_FREQUENCY (TED7360_CLOCK/8/(1024-TONE2_VALUE))
46#define NOISE_FREQUENCY_MAX (TED7360_CLOCK/8)
1217#define TONE_FREQUENCY(reg)         ((TED7360_CLOCK >> 3) / (1024 - reg))
1218#define TONE_FREQUENCY_MIN          (TONE_FREQUENCY(0))
1219#define NOISE_FREQUENCY             (TED7360_CLOCK / 8 / (1024 - TONE2_VALUE))
1220#define NOISE_FREQUENCY_MAX         (TED7360_CLOCK / 8)
471221
48static int noisesize,   /* number of samples */
49   tone1pos = 0, tone2pos = 0,         /* pos of tone */
50   tone1samples = 1, tone2samples = 1,   /* count of samples to give out per tone */
51   noisepos = 0, noisesamples = 1;
521222
53static sound_stream *channel;
54static UINT8 *noise;
1223static void ted7360_soundport_w( running_device *device, int offset, int data )
1224{
1225   ted7360_state *ted7360 = get_safe_token(device);
551226
56void ted7360_soundport_w (running_machine *machine, int offset, int data)
57{
58   stream_update(channel);
59   /*    int old=ted7360[offset]; */
1227   // int old = ted7360->reg[offset];
1228   stream_update(ted7360->channel);
1229
601230   switch (offset)
611231   {
62   case 0xe:
1232   case 0x0e:
631233   case 0x12:
641234      if (offset == 0x12)
65         ted7360[offset] = (ted7360[offset] & ~3) | (data & 3);
1235         ted7360->reg[offset] = (ted7360->reg[offset] & ~3) | (data & 3);
661236      else
67         ted7360[offset] = data;
68      tone1samples = machine->sample_rate / TONE_FREQUENCY (TONE1_VALUE);
69      DBG_LOG (1, "ted7360", ("tone1 %d %d sample:%d\n",
70               TONE1_VALUE, TONE_FREQUENCY(TONE1_VALUE), tone1samples));
1237         ted7360->reg[offset] = data;
711238
1239      ted7360->tone1samples = device->machine->sample_rate / TONE_FREQUENCY (TONE1_VALUE);
1240      DBG_LOG(1, "ted7360", ("tone1 %d %d sample:%d\n", TONE1_VALUE, TONE_FREQUENCY(TONE1_VALUE), ted7360->tone1samples));
721241      break;
1242
731243   case 0xf:
741244   case 0x10:
75      ted7360[offset] = data;
76      tone2samples = machine->sample_rate / TONE_FREQUENCY (TONE2_VALUE);
77      DBG_LOG (1, "ted7360", ("tone2 %d %d sample:%d\n",
78               TONE2_VALUE, TONE_FREQUENCY(TONE2_VALUE), tone2samples));
1245      ted7360->reg[offset] = data;
791246
80      noisesamples = (int) ((double) NOISE_FREQUENCY_MAX * machine->sample_rate
81                       * NOISE_BUFFER_SIZE_SEC / NOISE_FREQUENCY);
82      DBG_LOG (1, "ted7360", ("noise %d sample:%d\n",
83               NOISE_FREQUENCY, noisesamples));
84      if (!NOISE_ON || ((double) noisepos / noisesamples >= 1.0))
85      {
86         noisepos = 0;
87      }
1247      ted7360->tone2samples = device->machine->sample_rate / TONE_FREQUENCY (TONE2_VALUE);
1248      DBG_LOG (1, "ted7360", ("tone2 %d %d sample:%d\n", TONE2_VALUE, TONE_FREQUENCY(TONE2_VALUE), ted7360->tone2samples));
1249
1250      ted7360->noisesamples = (int) ((double) NOISE_FREQUENCY_MAX * device->machine->sample_rate * NOISE_BUFFER_SIZE_SEC / NOISE_FREQUENCY);
1251      DBG_LOG (1, "ted7360", ("noise %d sample:%d\n", NOISE_FREQUENCY, ted7360->noisesamples));
1252
1253      if (!NOISE_ON || ((double) ted7360->noisepos / ted7360->noisesamples >= 1.0))
1254         ted7360->noisepos = 0;
881255      break;
1256
891257   case 0x11:
90      ted7360[offset] = data;
91      DBG_LOG(1, "ted7360", ("%s volume %d, %s %s %s\n",
92                   TONE_ON?"on":"off",
93                   VOLUME, TONE1_ON?"tone1":"", TONE2_ON?"tone2":"",
94                   NOISE_ON?"noise":""));
95      if (!TONE_ON||!TONE1_ON) tone1pos=0;
96      if (!TONE_ON||!TONE2_ON) tone2pos=0;
97      if (!TONE_ON||!NOISE_ON) noisepos=0;
1258      ted7360->reg[offset] = data;
1259      DBG_LOG(1, "ted7360", ("%s volume %d, %s %s %s\n", TONE_ON?"on":"off",
1260                   VOLUME, TONE1_ON?"tone1":"", TONE2_ON?"tone2":"", NOISE_ON?"noise":""));
1261
1262      if (!TONE_ON||!TONE1_ON) ted7360->tone1pos = 0;
1263      if (!TONE_ON||!TONE2_ON) ted7360->tone2pos = 0;
1264      if (!TONE_ON||!NOISE_ON) ted7360->noisepos = 0;
981265      break;
991266   }
1001267}
1011268
1021269
103
1041270/************************************/
1051271/* Sound handler update             */
1061272/************************************/
1273
1071274static STREAM_UPDATE( ted7360_update )
1081275{
1276   ted7360_state *ted7360 = get_safe_token(device);
1091277   int i, v, a;
1101278   stream_sample_t *buffer = outputs[0];
1111279
1121280   for (i = 0; i < samples; i++)
1131281   {
1141282      v = 0;
1283
1151284      if (TONE1_ON)
1161285      {
117         if (tone1pos<=tone1samples/2 || !TONE_ON) {
118         v += 0x2ff; // depends on the volume between sound and noise
119         }
120         tone1pos++;
121         if (tone1pos>tone1samples) tone1pos=0;
1286         if (ted7360->tone1pos <= ted7360->tone1samples / 2 || !TONE_ON)
1287            v += 0x2ff; // depends on the volume between sound and noise
1288
1289         ted7360->tone1pos++;
1290
1291         if (ted7360->tone1pos > ted7360->tone1samples)
1292            ted7360->tone1pos = 0;
1221293      }
1294
1231295      if (TONE2_ON || NOISE_ON )
1241296      {
1251297         if (TONE2_ON)
1261298         {                     /*higher priority ?! */
127         if (tone2pos<=tone2samples/2 || !TONE_ON) {
128            v += 0x2ff;
1299            if (ted7360->tone2pos <= ted7360->tone2samples / 2 || !TONE_ON)
1300               v += 0x2ff;
1301
1302            ted7360->tone2pos++;
1303
1304            if (ted7360->tone2pos > ted7360->tone2samples)
1305               ted7360->tone2pos = 0;
1291306         }
130         tone2pos++;
131         if (tone2pos>tone2samples) tone2pos=0;
132         }
1331307         else
1341308         {
135         v += noise[(int) ((double) noisepos * noisesize / noisesamples)];
136         noisepos++;
137         if ((double) noisepos / noisesamples >= 1.0)
138         {
139            noisepos = 0;
1309            v += ted7360->noise[(int) ((double) ted7360->noisepos * ted7360->noisesize / ted7360->noisesamples)];
1310            ted7360->noisepos++;
1311
1312            if ((double) ted7360->noisepos / ted7360->noisesamples >= 1.0)
1313               ted7360->noisepos = 0;
1401314         }
141         }
1421315      }
1431316
1441317      a = VOLUME;
145      if (a>8)
146         a=8;
1318      if (a > 8)
1319         a = 8;
1320
1471321      v = v * a;
1322
1481323      buffer[i] = v;
1491324   }
1501325}
1511326
1327/*****************************************************************************
1328    DEVICE INTERFACE
1329*****************************************************************************/
1330
1521331/************************************/
1531332/* Sound handler start              */
1541333/************************************/
1551334
156static DEVICE_START(ted7360_sound)
1335static void ted7360_sound_start( running_device *device )
1571336{
1337   ted7360_state *ted7360 = get_safe_token(device);
1581338   int i;
1591339
160   channel = stream_create(device, 0, 1, device->machine->sample_rate, 0, ted7360_update);
1340   ted7360->channel = stream_create(device, 0, 1, device->machine->sample_rate, 0, ted7360_update);
1611341
162   /* buffer for fastest played sample for 5 second
163     * so we have enough data for min 5 second */
164   noisesize = NOISE_FREQUENCY_MAX * NOISE_BUFFER_SIZE_SEC;
165   noise = auto_alloc_array(device->machine, UINT8, noisesize);
1342   /* buffer for fastest played sample for 5 second so we have enough data for min 5 second */
1343   ted7360->noisesize = NOISE_FREQUENCY_MAX * NOISE_BUFFER_SIZE_SEC;
1344   ted7360->noise = auto_alloc_array(device->machine, UINT8, ted7360->noisesize);
1661345
1671346   {
1681347      int noiseshift = 0x7ffff8;
1691348      UINT8 data;
1701349
171      for (i = 0; i < noisesize; i++)
1350      for (i = 0; i < ted7360->noisesize; i++)
1721351      {
1731352         data = 0;
1741353         if (noiseshift & 0x400000)
r7376r7377
1871366            data |= 0x02;
1881367         if (noiseshift & 0x000004)
1891368            data |= 0x01;
190         noise[i] = data;
1369         ted7360->noise[i] = data;
1911370         if (((noiseshift & 0x400000) == 0) != ((noiseshift & 0x002000) == 0))
1921371            noiseshift = (noiseshift << 1) | 1;
1931372         else
r7376r7377
1961375   }
1971376}
1981377
1378static DEVICE_START( ted7360 )
1379{
1380   ted7360_state *ted7360 = get_safe_token(device);
1381   const ted7360_interface *intf = (ted7360_interface *)device->baseconfig().static_config;
1382   int width, height;
1991383
200DEVICE_GET_INFO( ted7360_sound )
1384   ted7360->screen = devtag_get_device(device->machine, intf->screen);
1385   width = video_screen_get_width(ted7360->screen);
1386   height = video_screen_get_height(ted7360->screen);
1387
1388   ted7360->bitmap = auto_bitmap_alloc(device->machine, width, height, BITMAP_FORMAT_INDEXED16);
1389
1390   ted7360->type = intf->type;
1391
1392   ted7360->dma_read = intf->dma_read;
1393   ted7360->dma_read_rom = intf->dma_read_rom;
1394   ted7360->interrupt = intf->irq;
1395
1396   ted7360->keyboard_cb = intf->keyb_cb;
1397
1398   ted7360->timer1 = timer_alloc(device->machine, ted7360_timer_timeout, ted7360);
1399   ted7360->timer2 = timer_alloc(device->machine, ted7360_timer_timeout, ted7360);
1400   ted7360->timer3 = timer_alloc(device->machine, ted7360_timer_timeout, ted7360);
1401
1402   ted7360_sound_start(device);
1403
1404   state_save_register_device_item_array(device, 0, ted7360->reg);
1405
1406   state_save_register_device_item_bitmap(device, 0, ted7360->bitmap);
1407
1408   state_save_register_device_item(device, 0, ted7360->rom);
1409   state_save_register_device_item(device, 0, ted7360->lines);
1410   state_save_register_device_item(device, 0, ted7360->chargenaddr);
1411   state_save_register_device_item(device, 0, ted7360->bitmapaddr);
1412   state_save_register_device_item(device, 0, ted7360->videoaddr);
1413   state_save_register_device_item(device, 0, ted7360->timer1_active);
1414   state_save_register_device_item(device, 0, ted7360->timer2_active);
1415   state_save_register_device_item(device, 0, ted7360->timer3_active);
1416   state_save_register_device_item(device, 0, ted7360->cursor1);
1417   state_save_register_device_item(device, 0, ted7360->rasterline);
1418   state_save_register_device_item(device, 0, ted7360->lastline);
1419   state_save_register_device_item(device, 0, ted7360->rastertime);
1420   state_save_register_device_item(device, 0, ted7360->frame_count);
1421   state_save_register_device_item(device, 0, ted7360->x_begin);
1422   state_save_register_device_item(device, 0, ted7360->x_end);
1423   state_save_register_device_item(device, 0, ted7360->y_begin);
1424   state_save_register_device_item(device, 0, ted7360->y_end);
1425
1426   state_save_register_device_item_array(device, 0, ted7360->c16_bitmap);
1427   state_save_register_device_item_array(device, 0, ted7360->bitmapmulti);
1428   state_save_register_device_item_array(device, 0, ted7360->mono);
1429   state_save_register_device_item_array(device, 0, ted7360->monoinversed);
1430   state_save_register_device_item_array(device, 0, ted7360->multi);
1431   state_save_register_device_item_array(device, 0, ted7360->ecmcolor);
1432   state_save_register_device_item_array(device, 0, ted7360->colors);
1433
1434   state_save_register_device_item(device, 0, ted7360->tone1pos);
1435   state_save_register_device_item(device, 0, ted7360->tone2pos);
1436   state_save_register_device_item(device, 0, ted7360->tone1samples);
1437   state_save_register_device_item(device, 0, ted7360->tone2samples);
1438   state_save_register_device_item(device, 0, ted7360->noisepos);
1439   state_save_register_device_item(device, 0, ted7360->noisesamples);
1440}
1441
1442static DEVICE_RESET( ted7360 )
2011443{
202   switch (state)
203   {
204      /* --- the following bits of info are returned as pointers to data or functions --- */
205      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(ted7360_sound);   break;
1444   ted7360_state *ted7360 = get_safe_token(device);
2061445
207      /* --- the following bits of info are returned as NULL-terminated strings --- */
208      case DEVINFO_STR_NAME:                     strcpy(info->s, "7360 TED");            break;
209      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                  break;
210   }
1446   memset(ted7360->reg, 0, ARRAY_LENGTH(ted7360->reg));
1447
1448   ted7360->rom = 1;   // FIXME: at start should be RAM or ROM?
1449
1450   ted7360->lines = TED7360_LINES;
1451   ted7360->chargenaddr = ted7360->bitmapaddr = ted7360->videoaddr = 0;
1452   ted7360->timer1_active = ted7360->timer2_active = ted7360->timer3_active = 0;
1453   ted7360->cursor1 = 0;
1454
1455   ted7360->rasterline = 0;
1456   ted7360->lastline = 0;
1457
1458   ted7360->rastertime = 0.0;
1459
1460   ted7360->frame_count = 0;
1461
1462   ted7360->x_begin = 0;
1463   ted7360->x_end = 0;
1464   ted7360->y_begin = 0;
1465   ted7360->y_end = 0;
1466
1467   memset(ted7360->c16_bitmap, 0, ARRAY_LENGTH(ted7360->c16_bitmap));
1468   memset(ted7360->bitmapmulti, 0, ARRAY_LENGTH(ted7360->bitmapmulti));
1469   memset(ted7360->mono, 0, ARRAY_LENGTH(ted7360->mono));
1470   memset(ted7360->monoinversed, 0, ARRAY_LENGTH(ted7360->monoinversed));
1471   memset(ted7360->multi, 0, ARRAY_LENGTH(ted7360->multi));
1472   memset(ted7360->ecmcolor, 0, ARRAY_LENGTH(ted7360->ecmcolor));
1473   memset(ted7360->colors, 0, ARRAY_LENGTH(ted7360->colors));
1474
1475   ted7360->tone1pos = 0;
1476   ted7360->tone2pos = 0;
1477   ted7360->tone1samples = 1;
1478   ted7360->tone2samples = 1;
1479   ted7360->noisepos = 0;
1480   ted7360->noisesamples = 1;
2111481}
1482
1483
1484/*-------------------------------------------------
1485    device definition
1486-------------------------------------------------*/
1487
1488static const char DEVTEMPLATE_SOURCE[] = __FILE__;
1489
1490#define DEVTEMPLATE_ID(p,s)            p##ted7360##s
1491#define DEVTEMPLATE_FEATURES         DT_HAS_START | DT_HAS_RESET
1492#define DEVTEMPLATE_NAME            "CBM TED 7360"
1493#define DEVTEMPLATE_FAMILY            "CBM Text Display Video Chip"
1494#include "devtempl.h"
src/mess/audio/ted7360.h
r0r7377
1/*****************************************************************************
2 *
3 * audio/ted7360.h
4 *
5 *
6 ****************************************************************************/
7
8#ifndef __TED7360_H__
9#define __TED7360_H__
10
11#include "devcb.h"
12
13
14/***************************************************************************
15    TYPE DEFINITIONS
16***************************************************************************/
17
18typedef int (*ted7360_dma_read)(running_machine *machine, int);
19typedef int (*ted7360_dma_read_rom)(running_machine *machine, int);
20typedef void (*ted7360_irq) (running_machine *, int);
21typedef UINT8 (*ted7360_key_cb) (running_machine *, int);
22
23typedef enum
24{
25   TED7360_NTSC,
26   TED7360_PAL
27} ted_type;
28
29typedef struct _ted7360_interface ted7360_interface;
30struct _ted7360_interface
31{
32   const char             *screen;
33
34   ted_type               type;
35
36   ted7360_dma_read       dma_read;
37   ted7360_dma_read_rom   dma_read_rom;
38
39   ted7360_irq            irq;
40
41   ted7360_key_cb         keyb_cb;
42};
43
44/***************************************************************************
45    CONSTANTS
46***************************************************************************/
47
48
49#define TED7360NTSC_VRETRACERATE 60
50#define TED7360PAL_VRETRACERATE 50
51#define TED7360_HRETRACERATE 15625
52
53/* the following values depend on the VIC clock,
54 * but to achieve TV-frequency the clock must have a fix frequency */
55#define TED7360_HSIZE   320
56#define TED7360_VSIZE   200
57
58/* of course you clock select an other clock, but for accurate */
59/* video timing (these are used in c16/c116/plus4) */
60#define TED7360NTSC_CLOCK   (14318180/4)
61#define TED7360PAL_CLOCK   (17734470/5)
62
63/* pal 50 Hz vertical screen refresh, screen consists of 312 lines
64 * ntsc 60 Hz vertical screen refresh, screen consists of 262 lines */
65#define TED7360NTSC_LINES 261
66#define TED7360PAL_LINES 312
67
68
69/***************************************************************************
70    FUNCTION PROTOTYPES
71***************************************************************************/
72
73DEVICE_GET_INFO( ted7360 );
74
75/***************************************************************************
76    DEVICE CONFIGURATION MACROS
77***************************************************************************/
78
79#define TED7360 DEVICE_GET_INFO_NAME( ted7360 )
80#define SOUND_TED7360 TED7360
81
82#define MDRV_TED7360_ADD(_tag, _interface) \
83   MDRV_DEVICE_ADD(_tag, SOUND, 0) \
84   MDRV_DEVICE_CONFIG_DATAPTR(sound_config, type, SOUND_TED7360) \
85   MDRV_DEVICE_CONFIG(_interface)
86
87
88/*----------- defined in audio/ted7360.c -----------*/
89
90WRITE8_DEVICE_HANDLER( ted7360_port_w );
91READ8_DEVICE_HANDLER( ted7360_port_r );
92
93WRITE_LINE_DEVICE_HANDLER( ted7360_rom_switch_w );
94READ_LINE_DEVICE_HANDLER( ted7360_rom_switch_r );
95
96void ted7360_frame_interrupt_gen(running_device *device);
97void ted7360_raster_interrupt_gen(running_device *device);
98UINT32 ted7360_video_update(running_device *device, bitmap_t *bitmap, const rectangle *cliprect);
99
100
101#endif /* __TED7360_H__ */
src/mess/video/ted7360.c
r7376r7377
1/***************************************************************************
2
3    TExt Display 7360
4    PeT mess@utanet.at
5
6***************************************************************************/
7/*
8Metal Oxid Semicontuctor MOS
9Commodore Business Machine CBM
10Textured Display Ted7360
11------------------------
12
137360/8360 (NTSC-M, PAL-B by same chip ?)
148365 PAL-N
158366 PAL-M
16
17Ted7360 used in Commodore C16
18Ted8360 used in Commodore C116/Plus4
19 should be 100% software kompatible with Ted7360
20
21video unit (without sprites), dram controller seams to be much like vic6567
22
23PAL/NTSC variants
24
25functions of this chip:
26 memory controller
27 dram controller
28 cpu clock generation with single and double clock switching
29 3 timer
30 1 8bit latched input
31 2 channel sound/noise generator
32 video controller
33 interrupt controller for timer and video
34
35Reasons for this document:
36 document state in mess c16/plus4 emulator
37 base to discuss ted7360 with others (i have no c16 computer anymore)
38
39pal:
40 clock 17734470
41 divided by 5 for base clock (pixel clock changing edges?)
42 312 lines
43 50 hertz vertical refresh
44
45ntsc:
46 clock 14318180
47 divided by 4 for base clock (pixel clock changing edges?)
48 262 lines
49 60 hertz vertical refresh
50
51registers:
52 0xff00 timer 1 low byte
53 0xff01 timer 1 high byte
54 0xff02 timer 2 low byte
55 0xff03 timer 2 high byte
56 0xff04 timer 3 low byte
57 0xff05 timer 3 high byte
58 0xff06
59  bit 7 test?
60  bit 6 ecm on
61  bit 5 hires on
62  bit 4 screen on
63  bit 3 25 raws (0 24 raws)
64  bit 2-0 vertical position
65 0xff07
66  bit 7 reverse off (0 on)
67  bit 6 read only NTSC (0 PAL)
68  bit 5 freeze horicontal position?
69  bit 4 multicolor on
70  bit 3 40 columns (0 38 columns)
71  bit 2-0 horicontal pos
72 0xff08 input latch (0 input low), write reloads latch
73 0xff09 interrupt request
74  7: interrupt
75  6: timer 3
76  5: ?
77  4: timer 2
78  3: timer 1
79  2: lightpen
80  1: rasterline
81  0: 1 (asl quitting)
82 0xff0a interrupt enable
83  7: ?
84  6: timer 3
85  5: ?
86  4: timer 2
87  3: timer 1
88  2: lightpen
89  1: rasterline
90  0: irq rasterline bit 8
91 0xff0b
92  7-0: irq rasterline 7-0
93 0xff0c
94  7-2: 1?
95  1,0: cursorpos bit 9,8
96 0xff0d cursorpos bit 7-0
97 0xff0e tone channel 1: frequency 7-0
98 0xff0f tone channel 2: frequency 7-0
99 0xff10
100  7-2: ?
101  1,0: tone channel 2 bit 9,8
102 0xff11
103  7: sound reload
104  6: tone 2 noise on (tone 2 must be off for noise)
105  5: tone 2 tone on
106  4: tone 1 on
107  3-0: volume 8?-0
108 0xff12
109  7,6: ?
110  5-3: bitmap address bit 15-13
111  2: bitmapmemory?, charactermemory in rom (0 ram)
112  1,0: tone 1 frequency bit 9,8
113 0xff13
114  7-2: chargen address bit 15-11
115  2: chargen address bit 10 (only used when reverse is off)
116  1: single clock in overscan area (0 double clock)
117  0: ram (0)/rom status
118 0xff14
119  7-2: video address bit 15-10
120  1,0: ?
121 0xff15
122  7: ?
123  6-0: backgroundcolor
124 0xff16
125  7: ?
126  6-0: color1
127 0xff17
128  7: ?
129  6-0: color2
130 0xff18
131  7: ?
132  6-0: color3
133 0xff19
134  7: ?
135  6-0: framecolor
136 0xff1a
137  7-2: ?
138  1,0: bitmap reload(cursorpos2) bit 9-8
139 0xff1b bitmap reload bit 7-0
140 0xff1c
141  7-1: 1? (matrix expects this)
142  0: current rasterline bit 8
143 0xff1d current rasterline bit 7-0
144 0xff1e
145  7-0: current rastercolumn /2 (0 begin visible area?)
146 0xff1f cursorblink?
147  7: ?
148  6-3: blink counter
149  2-0: vsub
150 0xff3e write switches to rom
151 0xff3f write switches to dram
152
153memory controller
154 0x8000-0xfcff, 0xff20-0xffff
155  read selection between dram and rom
156 0xff3e-0xff3f write nothing (would change main memory in 16k ram c16)
157
158clock generator
159 in displayed area ted need 3 memory cycles to get data for video chip
160 memory system runs at approximately 4 megahertz
161 so only 1 megahertz is available for the cpu
162 in the other area the clock can be doubled for the cpu
163
164dram controller
165 generator of refresh cycles
166 when are these occuring?
167 vic6567 in each rasterline reads 5 refresh addresses
168
169sound generator
170 2 channels
171 channel 2 can be switched to generate noise
172 volume control (0-8?)
173 tone reload bit?
174 samples ton/noise?
175 frequency=(base clock/32)/(1024-value)
176
177timer
178 timer count down
179 when reaching 0
180  they restart from 0xffff
181  set the interrupt request flag
182 writing to low byte stops timer
183 writing to high byte restarts timer with current value
184
185interrupt controller
186 interrupt sources must be enabled in the enable register to generate
187 an interrupt
188 request flag are set also when not enabled
189 interrupt is generated when rising edge on request and enable
190 quitting of interrupt is done via writing 1 to the request bit
191 what happens with request interrupts when the are enabled?
192
193Video part
194 colors
195  bit 3-0 color
196   black, white, red, cyan
197   purple, green, blue, yellow
198   orange, light orange, pink, light cyan,
199   light violett, light green, light blue, light yellow
200  bit 6-4 luminance (0 dark)
201  r,g,b values from 0 to 127
202   taken from digitized tv screen shot
203   0x06,0x01,0x03, 0x2b,0x2b,0x2b, 0x67,0x0e,0x0f, 0x00,0x3f,0x42,
204   0x57,0x00,0x6d, 0x00,0x4e,0x00, 0x19,0x1c,0x94, 0x38,0x38,0x00,
205   0x56,0x20,0x00, 0x4b,0x28,0x00, 0x16,0x48,0x00, 0x69,0x07,0x2f,
206   0x00,0x46,0x26, 0x06,0x2a,0x80, 0x2a,0x14,0x9b, 0x0b,0x49,0x00,
207
208   0x00,0x03,0x02, 0x3d,0x3d,0x3d, 0x75,0x1e,0x20, 0x00,0x50,0x4f,
209   0x6a,0x10,0x78, 0x04,0x5c,0x00, 0x2a,0x2a,0xa3, 0x4c,0x47,0x00,
210   0x69,0x2f,0x00, 0x59,0x38,0x00, 0x26,0x56,0x00, 0x75,0x15,0x41,
211   0x00,0x58,0x3d, 0x15,0x3d,0x8f, 0x39,0x22,0xae, 0x19,0x59,0x00,
212
213   0x00,0x03,0x04, 0x42,0x42,0x42, 0x7b,0x28,0x20, 0x02,0x56,0x59,
214   0x6f,0x1a,0x82, 0x0a,0x65,0x09, 0x30,0x34,0xa7, 0x50,0x51,0x00,
215   0x6e,0x36,0x00, 0x65,0x40,0x00, 0x2c,0x5c,0x00, 0x7d,0x1e,0x45,
216   0x01,0x61,0x45, 0x1c,0x45,0x99, 0x42,0x2d,0xad, 0x1d,0x62,0x00,
217
218   0x05,0x00,0x02, 0x56,0x55,0x5a, 0x90,0x3c,0x3b, 0x17,0x6d,0x72,
219   0x87,0x2d,0x99, 0x1f,0x7b,0x15, 0x46,0x49,0xc1, 0x66,0x63,0x00,
220   0x84,0x4c,0x0d, 0x73,0x55,0x00, 0x40,0x72,0x00, 0x91,0x33,0x5e,
221   0x19,0x74,0x5c, 0x32,0x59,0xae, 0x59,0x3f,0xc3, 0x32,0x76,0x00,
222
223   0x02,0x01,0x06, 0x84,0x7e,0x85, 0xbb,0x67,0x68, 0x45,0x96,0x96,
224   0xaf,0x58,0xc3, 0x4a,0xa7,0x3e, 0x73,0x73,0xec, 0x92,0x8d,0x11,
225   0xaf,0x78,0x32, 0xa1,0x80,0x20, 0x6c,0x9e,0x12, 0xba,0x5f,0x89,
226   0x46,0x9f,0x83, 0x61,0x85,0xdd, 0x84,0x6c,0xef, 0x5d,0xa3,0x29,
227
228   0x02,0x00,0x0a, 0xb2,0xac,0xb3, 0xe9,0x92,0x92, 0x6c,0xc3,0xc1,
229   0xd9,0x86,0xf0, 0x79,0xd1,0x76, 0x9d,0xa1,0xff, 0xbd,0xbe,0x40,
230   0xdc,0xa2,0x61, 0xd1,0xa9,0x4c, 0x93,0xc8,0x3d, 0xe9,0x8a,0xb1,
231   0x6f,0xcd,0xab, 0x8a,0xb4,0xff, 0xb2,0x9a,0xff, 0x88,0xcb,0x59,
232
233   0x02,0x00,0x0a, 0xc7,0xca,0xc9, 0xff,0xac,0xac, 0x85,0xd8,0xe0,
234   0xf3,0x9c,0xff, 0x92,0xea,0x8a, 0xb7,0xba,0xff, 0xd6,0xd3,0x5b,
235   0xf3,0xbe,0x79, 0xe6,0xc5,0x65, 0xb0,0xe0,0x57, 0xff,0xa4,0xcf,
236   0x89,0xe5,0xc8, 0xa4,0xca,0xff, 0xca,0xb3,0xff, 0xa2,0xe5,0x7a,
237
238   0x01,0x01,0x01, 0xff,0xff,0xff, 0xff,0xf6,0xf2, 0xd1,0xff,0xff,
239   0xff,0xe9,0xff, 0xdb,0xff,0xd3, 0xfd,0xff,0xff, 0xff,0xff,0xa3,
240   0xff,0xff,0xc1, 0xff,0xff,0xb2, 0xfc,0xff,0xa2, 0xff,0xee,0xff,
241   0xd1,0xff,0xff, 0xeb,0xff,0xff, 0xff,0xf8,0xff, 0xed,0xff,0xbc
242
243 video generation
244  column counter from 0 to 39
245  line counter from 0 to 199
246
247  character pointer position/hires: color 0-15 position
248   videoaddr+0x400+(line/8)*40+column
249  color position/hires: color luminance position
250   videoaddr+(line/8)*40+column
251  character bitmap position
252   chargenaddr+(character pointer)+(line&7)
253  bitmap position
254   bitmapaddr+(line/8)*40+column+(line&7)
255
256 normal text mode (reverse off, ecm off, multicolor off, hires off)
257  character pointer based
258   fetch character pointer, fetch character bitmap, fetch color
259  pixel on color (color)&0x7f
260  pixel off color backgroundcolor
261  blinking (synchron to cursor) (color&0x80)
262 reverse text mode (reverse on, ecm off, multicolor off, hires off)
263  character pointer &0x7f
264  character pointer bit 7
265   set
266    pixel off color attribut &0x7f
267    pixel on color backgroundcolor
268   clear
269    like normal text mode
270  blinking (synchron to cursor) (color&0x80)
271 multicolor text mode (ecm off, multicolor on, hires off)
272  reverse ?
273  attribut bit 3 character in multicolor (else monocolor character)
274  pixel on color attribut 0x77
275  0 backgroundcolor
276  1 color1
277  2 color2
278  3 attribut &0x77
279  (color&0x80) ?
280 ecm text mode (ecm on)
281  reverse ?
282  multicolor ? (c64/vic6567 black display?)
283  hires ? (c64/vic6567 black display?)
284  character pointer &0x3f
285  character pointer bit 7,6 select pixel off color
286   0 backgroundcolor ?
287   1 color1?
288   2 color2?
289   3 color3?
290  (color&0x80)?
291 hires (ecm off, multicolor off, hires on)
292  bitmap based
293   fetch bitmap, fetch color, fetch color luminance
294  reverse ?
295  pixel on color
296   6-4: (color luminance) bit 2-0
297   3-0: (color) bit 7-4
298  pixel off color
299   6-4: (color luminance) bit 6-4
300   3-0: (color) bit 3-0
301  (color) bit 7?
302  (color luminance) bit 7?
303 hires multicolor (ecm off, multicolor on, hires on)
304  reverse ?
305  0 backgroundcolor
306  1
307   6-4: (color luminance) bit 2-0
308   3-0: (color) bit 7-4
309  2
310   6-4: (color luminance) bit 6-4
311   3-0: (color) bit 3-0
312  3 color1
313  (color) bit 7?
314  (color luminance) bit 7?
315 scrolling support
316  visible part of the display in fixed position
317  columns 38 mode left 7 and right 9 pixel less displayed
318   but line generation start at the same position as in columns 40 mode
319  lines25 flag top and bottom 4 pixel less displayed ?
320  horicontal scrolling support
321   in columns 38 mode
322    horicontal position 1-7: pixel later started line generation
323    horicontal position 0: 8 pixels later started line generation
324   in columns 40 mode ?
325  vertical scrolling support
326   in lines 24 mode
327    vertical position 1-7: lines later started line generation
328    vertical position 0: 8 lines later started line generation
329   in lines 25 mode?
330    vertial position 3: for correct display
331
332 hardware cursor
333  full 8x8 in (color) color
334  flashing when in multicolor, hires ?
335  flashes with about 1 hertz
336  bitmap reload?
337
338 rasterline/rastercolumn
339  values in registers begin visible area 0
340  vic 6567
341   pal line 0 beginning of vertical refresh
342   ntsc line 0 in bottom frame
343    beginning of 25 lines screen 0x33 (24 lines screen 0x37)
344    beginning of 40 columns line 0x18 (38 columns 0x1f)
345
346 lightpen
347  (where to store values?)
348  i found a lightpen hardware description with a demo and drawing program
349  lightpen must be connected to joy0 (button)
350  demo program:
351   disables interrupt, polles joy0 button (0xfd0d? plus 4 related???)
352   and reads the rasterline value!
353   so i no exact column value reachable!
354*/
355#include "emu.h"
356#include "utils.h"
357
358#include "includes/c16.h"
359
360#include "video/ted7360.h"
361
362
363#define VERBOSE_LEVEL 0
364#define DBG_LOG(N,M,A) \
365   do { \
366      if(VERBOSE_LEVEL >= N) \
367      { \
368         if( M ) \
369            logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(machine)), (char*) M ); \
370         logerror A; \
371      } \
372   } while (0)
373
374
375/*#define GFX */
376
377#define VREFRESHINLINES 28
378
379#define TIMER1HELPER (ted7360[0]|(ted7360[1]<<8))
380#define TIMER2HELPER (ted7360[2]|(ted7360[3]<<8))
381#define TIMER3HELPER (ted7360[4]|(ted7360[5]<<8))
382#define TIMER1 (TIMER1HELPER?TIMER1HELPER:0x10000)
383#define TIMER2 (TIMER2HELPER?TIMER2HELPER:0x10000)
384#define TIMER3 (TIMER3HELPER?TIMER3HELPER:0x10000)
385
386static attotime TEDTIME_IN_CYCLES(int cycles)
387{
388   double d = (double)(cycles)/TED7360_CLOCK;
389   return double_to_attotime(d);
390}
391
392static int TEDTIME_TO_CYCLES(attotime t)
393{
394   double d = attotime_to_double(t);
395   return (int)((d)*TED7360_CLOCK);
396}
397
398#define TED7360_YPOS 40
399#define RASTERLINE_2_C16(a) ((a+lines-TED7360_YPOS-5)%lines)
400#define C16_2_RASTERLINE(a) ((a+TED7360_YPOS+5)%lines)
401#define XPOS 8
402#define YPOS 8
403
404#define SCREENON (ted7360[6]&0x10)
405#define TEST (ted7360[6]&0x80)
406#define VERTICALPOS (ted7360[6]&7)
407#define HORICONTALPOS (ted7360[7]&7)
408#define ECMON (ted7360[6]&0x40)
409#define HIRESON (ted7360[6]&0x20)
410#define MULTICOLORON (ted7360[7]&0x10)
411#define REVERSEON (!(ted7360[7]&0x80))
412/* hardware inverts character when bit 7 set (character taken &0x7f) */
413/* instead of fetching character with higher number! */
414#define LINES25 (ted7360[6]&8)         /* else 24 Lines */
415#define LINES (LINES25?25:24)
416#define YSIZE (LINES*8)
417#define COLUMNS40 (ted7360[7]&8)      /* else 38 Columns */
418#define COLUMNS (COLUMNS40?40:38)
419#define XSIZE (COLUMNS*8)
420
421#define INROM (ted7360[0x12]&4)
422#define CHARGENADDR (REVERSEON&&!HIRESON&&!MULTICOLORON?\
423           ((ted7360[0x13]&0xfc)<<8):\
424           ((ted7360[0x13]&0xf8)<<8) )
425#define BITMAPADDR ((ted7360[0x12]&0x38)<<10)
426#define VIDEOADDR ((ted7360[0x14]&0xf8)<<8)
427
428#define RASTERLINE ( ((ted7360[0xa]&1)<<8)|ted7360[0xb])
429#define CURSOR1POS ( ted7360[0xd]|((ted7360[0xc]&3)<<8) )
430#define CURSOR2POS ( ted7360[0x1b]|((ted7360[0x1a]&3)<<8) )
431#define CURSORRATE ( (ted7360[0x1f]&0x7c)>>2 )
432
433#define BACKGROUNDCOLOR (ted7360[0x15]&0x7f)
434#define FOREGROUNDCOLOR (ted7360[0x16]&0x7f)
435#define MULTICOLOR1 (ted7360[0x17]&0x7f)
436#define MULTICOLOR2 (ted7360[0x18]&0x7f)
437#define FRAMECOLOR (ted7360[0x19]&0x7f)
438
439const unsigned char ted7360_palette[] =
440{
441/* black, white, red, cyan */
442/* purple, green, blue, yellow */
443/* orange, light orange, pink, light cyan, */
444/* light violett, light green, light blue, light yellow */
445/* these 16 colors are 8 times here in different luminance (dark..light) */
446/* taken from digitized tv screenshot */
447   0x06, 0x01, 0x03, 0x2b, 0x2b, 0x2b, 0x67, 0x0e, 0x0f, 0x00, 0x3f, 0x42,
448   0x57, 0x00, 0x6d, 0x00, 0x4e, 0x00, 0x19, 0x1c, 0x94, 0x38, 0x38, 0x00,
449   0x56, 0x20, 0x00, 0x4b, 0x28, 0x00, 0x16, 0x48, 0x00, 0x69, 0x07, 0x2f,
450   0x00, 0x46, 0x26, 0x06, 0x2a, 0x80, 0x2a, 0x14, 0x9b, 0x0b, 0x49, 0x00,
451
452   0x00, 0x03, 0x02, 0x3d, 0x3d, 0x3d, 0x75, 0x1e, 0x20, 0x00, 0x50, 0x4f,
453   0x6a, 0x10, 0x78, 0x04, 0x5c, 0x00, 0x2a, 0x2a, 0xa3, 0x4c, 0x47, 0x00,
454   0x69, 0x2f, 0x00, 0x59, 0x38, 0x00, 0x26, 0x56, 0x00, 0x75, 0x15, 0x41,
455   0x00, 0x58, 0x3d, 0x15, 0x3d, 0x8f, 0x39, 0x22, 0xae, 0x19, 0x59, 0x00,
456
457   0x00, 0x03, 0x04, 0x42, 0x42, 0x42, 0x7b, 0x28, 0x20, 0x02, 0x56, 0x59,
458   0x6f, 0x1a, 0x82, 0x0a, 0x65, 0x09, 0x30, 0x34, 0xa7, 0x50, 0x51, 0x00,
459   0x6e, 0x36, 0x00, 0x65, 0x40, 0x00, 0x2c, 0x5c, 0x00, 0x7d, 0x1e, 0x45,
460   0x01, 0x61, 0x45, 0x1c, 0x45, 0x99, 0x42, 0x2d, 0xad, 0x1d, 0x62, 0x00,
461
462   0x05, 0x00, 0x02, 0x56, 0x55, 0x5a, 0x90, 0x3c, 0x3b, 0x17, 0x6d, 0x72,
463   0x87, 0x2d, 0x99, 0x1f, 0x7b, 0x15, 0x46, 0x49, 0xc1, 0x66, 0x63, 0x00,
464   0x84, 0x4c, 0x0d, 0x73, 0x55, 0x00, 0x40, 0x72, 0x00, 0x91, 0x33, 0x5e,
465   0x19, 0x74, 0x5c, 0x32, 0x59, 0xae, 0x59, 0x3f, 0xc3, 0x32, 0x76, 0x00,
466
467   0x02, 0x01, 0x06, 0x84, 0x7e, 0x85, 0xbb, 0x67, 0x68, 0x45, 0x96, 0x96,
468   0xaf, 0x58, 0xc3, 0x4a, 0xa7, 0x3e, 0x73, 0x73, 0xec, 0x92, 0x8d, 0x11,
469   0xaf, 0x78, 0x32, 0xa1, 0x80, 0x20, 0x6c, 0x9e, 0x12, 0xba, 0x5f, 0x89,
470   0x46, 0x9f, 0x83, 0x61, 0x85, 0xdd, 0x84, 0x6c, 0xef, 0x5d, 0xa3, 0x29,
471
472   0x02, 0x00, 0x0a, 0xb2, 0xac, 0xb3, 0xe9, 0x92, 0x92, 0x6c, 0xc3, 0xc1,
473   0xd9, 0x86, 0xf0, 0x79, 0xd1, 0x76, 0x9d, 0xa1, 0xff, 0xbd, 0xbe, 0x40,
474   0xdc, 0xa2, 0x61, 0xd1, 0xa9, 0x4c, 0x93, 0xc8, 0x3d, 0xe9, 0x8a, 0xb1,
475   0x6f, 0xcd, 0xab, 0x8a, 0xb4, 0xff, 0xb2, 0x9a, 0xff, 0x88, 0xcb, 0x59,
476
477   0x02, 0x00, 0x0a, 0xc7, 0xca, 0xc9, 0xff, 0xac, 0xac, 0x85, 0xd8, 0xe0,
478   0xf3, 0x9c, 0xff, 0x92, 0xea, 0x8a, 0xb7, 0xba, 0xff, 0xd6, 0xd3, 0x5b,
479   0xf3, 0xbe, 0x79, 0xe6, 0xc5, 0x65, 0xb0, 0xe0, 0x57, 0xff, 0xa4, 0xcf,
480   0x89, 0xe5, 0xc8, 0xa4, 0xca, 0xff, 0xca, 0xb3, 0xff, 0xa2, 0xe5, 0x7a,
481
482   0x01, 0x01, 0x01, 0xff, 0xff, 0xff, 0xff, 0xf6, 0xf2, 0xd1, 0xff, 0xff,
483   0xff, 0xe9, 0xff, 0xdb, 0xff, 0xd3, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xa3,
484   0xff, 0xff, 0xc1, 0xff, 0xff, 0xb2, 0xfc, 0xff, 0xa2, 0xff, 0xee, 0xff,
485   0xd1, 0xff, 0xff, 0xeb, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xed, 0xff, 0xbc
486};
487
488UINT8 ted7360[0x20];
489int ted7360_pal;
490int ted7360_rom;
491
492static int lines;
493static int timer1_active, timer2_active, timer3_active;
494static emu_timer *timer1, *timer2, *timer3;
495static int cursor1;
496static read8_space_func vic_dma_read;
497static read8_space_func vic_dma_read_rom;
498static int chargenaddr, bitmapaddr, videoaddr;
499
500static int x_begin, x_end;
501static int y_begin, y_end;
502
503static UINT16 c16_bitmap[2], bitmapmulti[4], mono[2], monoinversed[2], multi[4], ecmcolor[2], colors[5];
504
505static bitmap_t *ted7360_bitmap;
506static int rasterline = 0, lastline = 0;
507static double rastertime;
508static void ted7360_drawlines (running_machine *machine, int first, int last);
509
510static UINT32 cursorcolortable[2] =
511{0};
512static const gfx_layout cursorlayout =
513{
514   8, 8,
515   1,
516   1,
517   {0},
518   {0, 1, 2, 3, 4, 5, 6, 7},
519   {0 * 8, 1 * 8, 2 * 8, 3 * 8, 4 * 8, 5 * 8, 6 * 8, 7 * 8},
520   8 * 8
521};
522
523static const UINT8 cursormask[] =
524{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
525static gfx_element *cursorelement;
526
527static TIMER_CALLBACK(ted7360_timer_timeout);
528
529void ted7360_init( running_machine *machine, int pal )
530{
531   ted7360_pal = pal;
532   lines = TED7360_LINES;
533   chargenaddr = bitmapaddr = videoaddr = 0;
534   timer1_active = timer2_active = timer3_active = 0;
535   timer1 = timer_alloc(machine, ted7360_timer_timeout, NULL);
536   timer2 = timer_alloc(machine, ted7360_timer_timeout, NULL);
537   timer3 = timer_alloc(machine, ted7360_timer_timeout, NULL);
538}
539
540void ted7360_set_dma (read8_space_func dma_read,
541                 read8_space_func dma_read_rom)
542{
543   vic_dma_read = dma_read;
544   vic_dma_read_rom = dma_read_rom;
545}
546
547static void ted7360_set_interrupt (running_machine *machine, int mask)
548{
549   /* kernel itself polls for timer 2 shot (interrupt disabled!)
550     * when cassette loading */
551   ted7360[9] |= mask;
552   if ((ted7360[0xa] & ted7360[9] & 0x5e))
553   {
554      if (!(ted7360[9] & 0x80))
555      {
556         DBG_LOG (1, "ted7360", ("irq start %.2x\n", mask));
557         ted7360[9] |= 0x80;
558         c16_interrupt (machine, 1);
559      }
560   }
561   ted7360[9] |= mask;
562}
563
564static void ted7360_clear_interrupt (running_machine *machine, int mask)
565{
566   ted7360[9] &= ~mask;
567   if ((ted7360[9] & 0x80) && !(ted7360[9] & ted7360[0xa] & 0x5e))
568   {
569      DBG_LOG (1, "ted7360", ("irq end %.2x\n", mask));
570      ted7360[9] &= ~0x80;
571      c16_interrupt (machine, 0);
572   }
573}
574
575static int ted7360_rastercolumn (running_machine *machine)
576{
577   return (int) ((attotime_to_double(timer_get_time(machine)) - rastertime)
578              * TED7360_VRETRACERATE * lines * 57 * 8 + 0.5);
579}
580
581static TIMER_CALLBACK(ted7360_timer_timeout)
582{
583   int which = param;
584   DBG_LOG (3, "ted7360 ", ("timer %d timeout\n", which));
585   switch (which)
586   {
587   case 1:
588       // prooved by digisound of several intros like eoroidpro
589      timer_adjust_oneshot(timer1, TEDTIME_IN_CYCLES (TIMER1), 1);
590      timer1_active = 1;
591      ted7360_set_interrupt (machine, 8);
592      break;
593   case 2:
594      timer_adjust_oneshot(timer2, TEDTIME_IN_CYCLES (0x10000), 2);
595      timer2_active = 1;
596      ted7360_set_interrupt (machine, 0x10);
597      break;
598   case 3:
599      timer_adjust_oneshot(timer3, TEDTIME_IN_CYCLES (0x10000), 3);
600      timer3_active = 1;
601      ted7360_set_interrupt (machine, 0x40);
602      break;
603   }
604}
605
606INTERRUPT_GEN( ted7360_frame_interrupt )
607{
608   static int count;
609
610   if ((ted7360[0x1f] & 0xf) >= 0x0f)
611   {
612/*  if (count>=CURSORRATE) { */
613      cursor1 ^= TRUE;
614      ted7360[0x1f] &= ~0xf;
615      count = 0;
616   }
617   else
618      ted7360[0x1f]++;
619}
620
621WRITE8_HANDLER ( ted7360_port_w )
622{
623   running_machine *machine = space->machine;
624   int old;
625
626   if ((offset != 8) && ((offset < 0x15) || (offset > 0x19)))
627   {
628      DBG_LOG (1, "ted7360_port_w", ("%.2x:%.2x\n", offset, data));
629   }
630   switch (offset)
631   {
632   case 0xe:
633   case 0xf:
634   case 0x10:
635   case 0x11:
636   case 0x12:
637      ted7360_soundport_w (space->machine, offset, data);
638      break;
639   }
640   switch (offset)
641   {
642   case 0:                     /* stop timer 1 */
643      ted7360[offset] = data;
644      if (timer1_active)
645      {
646         ted7360[1] = TEDTIME_TO_CYCLES (timer_timeleft (timer1)) >> 8;
647         timer_reset(timer1, attotime_never);
648         timer1_active = 0;
649      }
650      break;
651   case 1:                     /* start timer 1 */
652      ted7360[offset] = data;
653      timer_adjust_oneshot(timer1, TEDTIME_IN_CYCLES (TIMER1), 1);
654      timer1_active = 1;
655      break;
656   case 2:                     /* stop timer 2 */
657      ted7360[offset] = data;
658      if (timer2_active)
659      {
660         ted7360[3] = TEDTIME_TO_CYCLES (timer_timeleft (timer2)) >> 8;
661         timer_reset(timer2, attotime_never);
662         timer2_active = 0;
663      }
664      break;
665   case 3:                     /* start timer 2 */
666      ted7360[offset] = data;
667      timer_adjust_oneshot(timer2, TEDTIME_IN_CYCLES (TIMER2), 2);
668      timer2_active = 1;
669      break;
670   case 4:                     /* stop timer 3 */
671      ted7360[offset] = data;
672      if (timer3_active)
673      {
674         ted7360[5] = TEDTIME_TO_CYCLES (timer_timeleft (timer3)) >> 8;
675         timer_reset(timer3, attotime_never);
676         timer3_active = 0;
677      }
678      break;
679   case 5:                     /* start timer 3 */
680      ted7360[offset] = data;
681      timer_adjust_oneshot(timer3, TEDTIME_IN_CYCLES (TIMER3), 3);
682      timer3_active = 1;
683      break;
684   case 6:
685      if (ted7360[offset] != data)
686      {
687         ted7360_drawlines (space->machine, lastline, rasterline);
688         ted7360[offset] = data;
689         if (LINES25)
690         {
691            y_begin = 0;
692            y_end = y_begin + 200;
693         }
694         else
695         {
696            y_begin = 4;
697            y_end = y_begin + 192;
698         }
699         chargenaddr = CHARGENADDR;
700      }
701      break;
702   case 7:
703      if (ted7360[offset] != data)
704      {
705         ted7360_drawlines (space->machine, lastline, rasterline);
706         ted7360[offset] = data;
707         if (COLUMNS40)
708         {
709            x_begin = 0;
710            x_end = x_begin + 320;
711         }
712         else
713         {
714            x_begin = HORICONTALPOS;
715            x_end = x_begin + 320;
716         }
717         DBG_LOG (3, "ted7360_port_w", ("%s %s\n", data & 0x40 ? "ntsc" : "pal",
718                                 data & 0x20 ? "hori freeze" : ""));
719         chargenaddr = CHARGENADDR;
720      }
721      break;
722   case 8:
723      ted7360[offset] = c16_read_keyboard (data);
724      break;
725   case 9:
726      if (data & 8)
727         ted7360_clear_interrupt (space->machine, 8);
728      if (data & 0x10)
729         ted7360_clear_interrupt (space->machine, 0x10);
730      if (data & 0x40)
731         ted7360_clear_interrupt (space->machine, 0x40);
732      if (data & 2)
733         ted7360_clear_interrupt (space->machine, 2);
734      break;
735   case 0xa:
736      old = data;
737      ted7360[offset] = data | 0xa0;
738#if 0
739      ted7360[9] = (ted7360[9] & 0xa1) | (ted7360[9] & data & 0x5e);
740      if (ted7360[9] & 0x80)
741         ted7360_clear_interrupt (space->machine, 0);
742#endif
743      if ((data ^ old) & 1)
744      {
745/*    DBG_LOG(1,"set rasterline hi",("soll:%d\n",RASTERLINE)); */
746      }
747      break;
748   case 0xb:
749      if (data != ted7360[offset])
750      {
751         ted7360_drawlines (space->machine, lastline, rasterline);
752         ted7360[offset] = data;
753         /*  DBG_LOG(1,"set rasterline lo",("soll:%d\n",RASTERLINE)); */
754      }
755      break;
756   case 0xc:
757   case 0xd:
758      if (ted7360[offset] != data)
759      {
760         ted7360_drawlines (space->machine, lastline, rasterline);
761         ted7360[offset] = data;
762      }
763      break;
764   case 0x12:
765      if (ted7360[offset] != data)
766      {
767         ted7360_drawlines (space->machine, lastline, rasterline);
768         ted7360[offset] = data;
769         bitmapaddr = BITMAPADDR;
770         chargenaddr = CHARGENADDR;
771         DBG_LOG (3, "ted7360_port_w", ("bitmap %.4x %s\n",
772                                 BITMAPADDR, INROM ? "rom" : "ram"));
773      }
774      break;
775   case 0x13:
776      if (ted7360[offset] != data)
777      {
778         ted7360_drawlines (space->machine, lastline, rasterline);
779         ted7360[offset] = data;
780         chargenaddr = CHARGENADDR;
781         DBG_LOG (3, "ted7360_port_w", ("chargen %.4x %s %d\n",
782                                 CHARGENADDR, data & 2 ? "" : "doubleclock",
783                                 data & 1));
784      }
785      break;
786   case 0x14:
787      if (ted7360[offset] != data)
788      {
789         ted7360_drawlines (space->machine, lastline, rasterline);
790         ted7360[offset] = data;
791         videoaddr = VIDEOADDR;
792         DBG_LOG (3, "ted7360_port_w", ("videoram %.4x\n",
793                                 VIDEOADDR));
794      }
795      break;
796   case 0x15:                     /* backgroundcolor */
797      if (ted7360[offset] != data)
798      {
799         ted7360_drawlines (space->machine, lastline, rasterline);
800         ted7360[offset] = data;
801         monoinversed[1] = mono[0] = bitmapmulti[0] = multi[0] = colors[0] =
802            BACKGROUNDCOLOR;
803      }
804      break;
805   case 0x16:                     /* foregroundcolor */
806      if (ted7360[offset] != data)
807      {
808         ted7360_drawlines (space->machine, lastline, rasterline);
809         ted7360[offset] = data;
810         bitmapmulti[3] = multi[1] = colors[1] = FOREGROUNDCOLOR;
811      }
812      break;
813   case 0x17:                     /* multicolor 1 */
814      if (ted7360[offset] != data)
815      {
816         ted7360_drawlines (space->machine, lastline, rasterline);
817         ted7360[offset] = data;
818         multi[2] = colors[2] = MULTICOLOR1;
819      }
820      break;
821   case 0x18:                     /* multicolor 2 */
822      if (ted7360[offset] != data)
823      {
824         ted7360_drawlines (space->machine, lastline, rasterline);
825         ted7360[offset] = data;
826         colors[3] = MULTICOLOR2;
827      }
828      break;
829   case 0x19:                     /* framecolor */
830      if (ted7360[offset] != data)
831      {
832         ted7360_drawlines (space->machine, lastline, rasterline);
833         ted7360[offset] = data;
834         colors[4] = FRAMECOLOR;
835      }
836      break;
837   case 0x1c:
838      ted7360[offset] = data;         /*? */
839      DBG_LOG (1, "ted7360_port_w", ("write to rasterline high %.2x\n",
840                              data));
841      break;
842   case 0x1f:
843      ted7360[offset] = data;
844      DBG_LOG (1, "ted7360_port_w", ("write to cursorblink %.2x\n", data));
845      break;
846   default:
847      ted7360[offset] = data;
848      break;
849   }
850}
851
852READ8_HANDLER ( ted7360_port_r )
853{
854   running_machine *machine = space->machine;
855   int val = 0;
856
857   switch (offset)
858   {
859   case 0:
860      if (timer1)
861         val = TEDTIME_TO_CYCLES (timer_timeleft (timer1)) & 0xff;
862      else
863         val = ted7360[offset];
864      break;
865   case 1:
866      if (timer1)
867         val = TEDTIME_TO_CYCLES (timer_timeleft (timer1)) >> 8;
868      else
869         val = ted7360[offset];
870      break;
871   case 2:
872      if (timer2)
873         val = TEDTIME_TO_CYCLES (timer_timeleft (timer2)) & 0xff;
874      else
875         val = ted7360[offset];
876      break;
877   case 3:
878      if (timer2)
879         val = TEDTIME_TO_CYCLES (timer_timeleft (timer2)) >> 8;
880      else
881         val = ted7360[offset];
882      break;
883   case 4:
884      if (timer3)
885         val = TEDTIME_TO_CYCLES (timer_timeleft (timer3)) & 0xff;
886      else
887         val = ted7360[offset];
888      break;
889   case 5:
890      if (timer3)
891         val = TEDTIME_TO_CYCLES (timer_timeleft (timer3)) >> 8;
892      else
893         val = ted7360[offset];
894      break;
895   case 7:
896      val = (ted7360[offset] & ~0x40);
897      if (!ted7360_pal)
898         val |= 0x40;
899      break;
900   case 9:
901      val = ted7360[offset] | 1;
902      break;
903   case 0xa:
904      val = ted7360[offset];
905      break;
906   case 0xb:
907      val = ted7360[offset];
908      break;
909   case 0x0c:
910      val = ted7360[offset] |= 0xfc;
911      break;
912   case 0x13:
913      val = ted7360[offset] & ~1;
914      if (ted7360_rom)
915         val |= 1;
916      break;
917   case 0x1c:                     /*rasterline */
918      ted7360_drawlines (space->machine, lastline, rasterline);
919      val = ((RASTERLINE_2_C16 (rasterline) & 0x100) >> 8) | 0xfe;   /* expected by matrix */
920      break;
921   case 0x1d:                     /*rasterline */
922      ted7360_drawlines (space->machine, lastline, rasterline);
923      val = RASTERLINE_2_C16 (rasterline) & 0xff;
924      break;
925   case 0x1e:                     /*rastercolumn */
926      val = ted7360_rastercolumn(space->machine) / 2;   /* pengo >=0x99 */
927      break;
928   case 0x1f:
929      val = ((rasterline & 7) << 4) | (ted7360[offset] & 0x0f);
930      DBG_LOG (1, "ted7360_port_w", ("read from cursorblink %.2x\n", val));
931      break;
932   default:
933      val = ted7360[offset];
934      break;
935   }
936   if ((offset != 8) && (offset >= 6) && (offset != 0x1c) && (offset != 0x1d) && (offset != 9)
937      && ((offset < 0x15) || (offset > 0x19)))
938   {
939      DBG_LOG (1, "ted7360_port_r", ("%.2x:%.2x\n", offset, val));
940   }
941   return val;
942}
943
944VIDEO_START( ted7360 )
945{
946   running_device *screen = video_screen_first(machine);
947   int width = video_screen_get_width(screen);
948   int height = video_screen_get_height(screen);
949
950   // FIXME: this element needs to be placed in machine->gfx[], so it will be free'd
951   cursorelement = gfx_element_alloc(machine, &cursorlayout, cursormask, machine->config->total_colors / 16, 0);
952   /* 7-Sep-2007 - After 0.118u5, you cannot revector the color table */
953   /* cursorelement->colortable = cursorcolortable; */
954   cursorcolortable[1] = 1;
955   cursorelement->total_colors = 2;
956   cursor1 = FALSE;
957   ted7360_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16);
958}
959
960static void ted7360_draw_character (running_machine *machine, int ybegin, int yend, int ch, int yoff, int xoff,
961                           UINT16 *color)
962{
963   int y, code;
964
965   for (y = ybegin; y <= yend; y++)
966   {
967      if (INROM)
968         code = vic_dma_read_rom (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), chargenaddr + ch * 8 + y);
969      else
970         code = vic_dma_read (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), chargenaddr + ch * 8 + y);
971      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 0 + xoff) = color[code >> 7];
972      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 1 + xoff) = color[(code >> 6) & 1];
973      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 2 + xoff) = color[(code >> 5) & 1];
974      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 3 + xoff) = color[(code >> 4) & 1];
975      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 4 + xoff) = color[(code >> 3) & 1];
976      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 5 + xoff) = color[(code >> 2) & 1];
977      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 6 + xoff) = color[(code >> 1) & 1];
978      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 7 + xoff) = color[code & 1];
979   }
980}
981
982static void ted7360_draw_character_multi (running_machine *machine, int ybegin, int yend, int ch, int yoff,
983                                int xoff)
984{
985   int y, code;
986
987   for (y = ybegin; y <= yend; y++)
988   {
989      if (INROM)
990         code = vic_dma_read_rom (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), chargenaddr + ch * 8 + y);
991      else
992         code = vic_dma_read (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), chargenaddr + ch * 8 + y);
993      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 0 + xoff) =
994         *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 1 + xoff) = multi[code >> 6];
995      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 2 + xoff) =
996         *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 3 + xoff) = multi[(code >> 4) & 3];
997      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 4 + xoff) =
998         *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 5 + xoff) = multi[(code >> 2) & 3];
999      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 6 + xoff) =
1000         *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 7 + xoff) = multi[code & 3];
1001   }
1002}
1003
1004static void ted7360_draw_bitmap (running_machine *machine, int ybegin, int yend,
1005                         int ch, int yoff, int xoff)
1006{
1007   int y, code;
1008
1009   for (y = ybegin; y <= yend; y++)
1010   {
1011      code = vic_dma_read (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), bitmapaddr + ch * 8 + y);
1012      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 0 + xoff) = c16_bitmap[code >> 7];
1013      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 1 + xoff) = c16_bitmap[(code >> 6) & 1];
1014      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 2 + xoff) = c16_bitmap[(code >> 5) & 1];
1015      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 3 + xoff) = c16_bitmap[(code >> 4) & 1];
1016      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 4 + xoff) = c16_bitmap[(code >> 3) & 1];
1017      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 5 + xoff) = c16_bitmap[(code >> 2) & 1];
1018      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 6 + xoff) = c16_bitmap[(code >> 1) & 1];
1019      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 7 + xoff) = c16_bitmap[code & 1];
1020   }
1021}
1022
1023static void ted7360_draw_bitmap_multi (running_machine *machine, int ybegin, int yend,
1024                              int ch, int yoff, int xoff)
1025{
1026   int y, code;
1027
1028   for (y = ybegin; y <= yend; y++)
1029   {
1030      code = vic_dma_read (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), bitmapaddr + ch * 8 + y);
1031      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 0 + xoff) =
1032         *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 1 + xoff) = bitmapmulti[code >> 6];
1033      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 2 + xoff) =
1034         *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 3 + xoff) = bitmapmulti[(code >> 4) & 3];
1035      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 4 + xoff) =
1036         *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 5 + xoff) = bitmapmulti[(code >> 2) & 3];
1037      *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 6 + xoff) =
1038         *BITMAP_ADDR16(ted7360_bitmap, y + yoff, 7 + xoff) = bitmapmulti[code & 3];
1039   }
1040}
1041
1042static void ted7360_draw_cursor (int ybegin, int yend, int yoff, int xoff,
1043                         int color)
1044{
1045   int y;
1046
1047   for (y = ybegin; y <= yend; y++)
1048   {
1049      memset16 (BITMAP_ADDR16(ted7360_bitmap, yoff + y, xoff), color, 8);
1050   }
1051}
1052
1053static void ted7360_drawlines (running_machine *machine, int first, int last)
1054{
1055   int line, vline, end;
1056   int attr, ch, c1, c2, ecm;
1057   int offs, yoff, xoff, ybegin, yend, xbegin, xend;
1058   int i;
1059
1060   lastline = last;
1061
1062   if (video_skip_this_frame ())
1063      return;
1064
1065   /* top part of display not rastered */
1066   first -= TED7360_YPOS;
1067   last -= TED7360_YPOS;
1068   if ((first >= last) || (last <= 0))
1069      return;
1070   if (first < 0)
1071      first = 0;
1072
1073   if (!SCREENON)
1074   {
1075      for (line = first; (line < last) && (line < ted7360_bitmap->height); line++)
1076         memset16 (BITMAP_ADDR16(ted7360_bitmap, line, 0), 0, ted7360_bitmap->width);
1077      return;
1078   }
1079
1080   if (COLUMNS40)
1081      xbegin = XPOS, xend = xbegin + 320;
1082   else
1083      xbegin = XPOS + 7, xend = xbegin + 304;
1084
1085   if (last < y_begin)
1086      end = last;
1087   else
1088      end = y_begin + YPOS;
1089   {
1090      for (line = first; line < end; line++)
1091         memset16 (BITMAP_ADDR16(ted7360_bitmap, line, 0), FRAMECOLOR,
1092            ted7360_bitmap->width);
1093   }
1094   if (LINES25)
1095   {
1096      vline = line - y_begin - YPOS;
1097   }
1098   else
1099   {
1100      vline = line - y_begin - YPOS + 8 - VERTICALPOS;
1101   }
1102   if (last < y_end + YPOS)
1103      end = last;
1104   else
1105      end = y_end + YPOS;
1106   for (; line < end; vline = (vline + 8) & ~7, line = line + 1 + yend - ybegin)
1107   {
1108      offs = (vline >> 3) * 40;
1109      ybegin = vline & 7;
1110      yoff = line - ybegin;
1111      yend = (yoff + 7 < end) ? 7 : (end - yoff - 1);
1112      /* rendering 39 characters */
1113      /* left and right borders are overwritten later */
1114
1115      for (xoff = x_begin + XPOS; xoff < x_end + XPOS; xoff += 8, offs++)
1116      {
1117         if (HIRESON)
1118         {
1119            ch = vic_dma_read (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), (videoaddr | 0x400) + offs);
1120            attr = vic_dma_read (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), ((videoaddr) + offs));
1121            c1 = ((ch >> 4) & 0xf) | (attr << 4);
1122            c2 = (ch & 0xf) | (attr & 0x70);
1123            bitmapmulti[1] = c16_bitmap[1] = c1 & 0x7f;
1124            bitmapmulti[2] = c16_bitmap[0] = c2 & 0x7f;
1125            if (MULTICOLORON)
1126            {
1127               ted7360_draw_bitmap_multi (machine, ybegin, yend, offs, yoff, xoff);
1128            }
1129            else
1130            {
1131               ted7360_draw_bitmap (machine, ybegin, yend, offs, yoff, xoff);
1132            }
1133         }
1134         else
1135         {
1136            ch = vic_dma_read (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), (videoaddr | 0x400) + offs);
1137            attr = vic_dma_read (cputag_get_address_space(machine,"maincpu",ADDRESS_SPACE_PROGRAM), ((videoaddr) + offs));
1138            // levente harsfalvi's docu says cursor off in ecm and multicolor
1139            if (ECMON)
1140            {
1141               // hardware reverse off
1142               ecm = ch >> 6;
1143               ecmcolor[0] = colors[ecm];
1144               ecmcolor[1] = attr & 0x7f;
1145               ted7360_draw_character (machine, ybegin, yend, ch & ~0xC0, yoff, xoff, ecmcolor);
1146            }
1147            else if (MULTICOLORON)
1148            {
1149               // hardware reverse off
1150               if (attr & 8)
1151               {
1152                  multi[3] = attr & 0x77;
1153                  ted7360_draw_character_multi (machine, ybegin, yend, ch, yoff, xoff);
1154               }
1155               else
1156               {
1157                  mono[1] = attr & 0x7f;
1158                  ted7360_draw_character (machine, ybegin, yend, ch, yoff, xoff, mono);
1159               }
1160            }
1161            else if (cursor1 && (offs == CURSOR1POS))
1162            {
1163#ifndef GFX
1164               ted7360_draw_cursor (ybegin, yend, yoff, xoff,
1165                     attr & 0x7f);
1166#else
1167               drawgfx_opaque (ted7360_bitmap, 0, cursorelement, 0, attr & 0x7f, 0, 0,
1168                  xoff, yoff);
1169#endif
1170            }
1171            else if (REVERSEON && (ch & 0x80))
1172            {
1173               monoinversed[0] = attr & 0x7f;
1174               if (cursor1 && (attr & 0x80))
1175                  ted7360_draw_cursor (ybegin, yend, yoff, xoff, monoinversed[0]);
1176               else
1177                  ted7360_draw_character (machine, ybegin, yend, ch & ~0x80, yoff, xoff,
1178                     monoinversed);
1179            }
1180            else
1181            {
1182               mono[1] = attr & 0x7f;
1183               if (cursor1 && (attr & 0x80))
1184                  ted7360_draw_cursor (ybegin, yend, yoff, xoff, mono[0]);
1185               else
1186                  ted7360_draw_character (machine, ybegin, yend, ch, yoff, xoff, mono);
1187            }
1188         }
1189      }
1190
1191      for (i = ybegin; i <= yend; i++)
1192      {
1193         memset16 (BITMAP_ADDR16(ted7360_bitmap, yoff + i, 0), FRAMECOLOR, xbegin);
1194         memset16 (BITMAP_ADDR16(ted7360_bitmap, yoff + i, xend), FRAMECOLOR, ted7360_bitmap->width - xend);
1195      }
1196   }
1197
1198    if (last < ted7360_bitmap->height)
1199      end = last;
1200    else
1201      end = ted7360_bitmap->height;
1202
1203   for (; line < end; line++)
1204   {
1205      memset16 (BITMAP_ADDR16(ted7360_bitmap, line, 0), FRAMECOLOR, ted7360_bitmap->width);
1206   }
1207}
1208
1209INTERRUPT_GEN( ted7360_raster_interrupt )
1210{
1211   rasterline++;
1212   rastertime = attotime_to_double(timer_get_time(device->machine));
1213   if (rasterline >= lines)
1214   {
1215      rasterline = 0;
1216      ted7360_drawlines (device->machine, lastline, TED7360_LINES);
1217      lastline = 0;
1218   }
1219   if (rasterline == C16_2_RASTERLINE (RASTERLINE))
1220   {
1221      ted7360_drawlines (device->machine, lastline, rasterline);
1222      ted7360_set_interrupt (device->machine, 2);
1223   }
1224}
1225
1226VIDEO_UPDATE( ted7360 )
1227{
1228   copybitmap(bitmap, ted7360_bitmap, 0, 0, 0, 0, cliprect);
1229   return 0;
1230}
src/mess/video/ted7360.h
r7376r7377
1/*****************************************************************************
2 *
3 * video/ted7360.h
4 *
5 * If you need this chip in another mame/mess emulation than let it me know.
6 * I will split this from the c16 driver.
7 *
8 * peter.trauner@jk.uni-linz.ac.at, 16. november 1999
9 * Look at mess/drivers/c16.c and mess/machine/c16.c on how to use it
10 *
11 ****************************************************************************/
12
13#ifndef TED7360_H_
14#define TED7360_H_
15
16
17/*----------- defined in video/ted7360.c -----------*/
18
19/* call to init videodriver */
20/* pal version */
21/* dma_read: videochip fetched 1 byte data from system bus */
22extern void ted7360_init (running_machine *machine, int pal);
23extern void ted7360_set_dma (read8_space_func dma_read,
24                      read8_space_func dma_read_rom);
25
26#define TED7360NTSC_VRETRACERATE 60
27#define TED7360PAL_VRETRACERATE 50
28#define TED7360_VRETRACERATE (ted7360_pal?TED7360PAL_VRETRACERATE:TED7360NTSC_VRETRACERATE)
29#define TED7360_HRETRACERATE 15625
30
31/* to be inserted in MachineDriver-Structure */
32/* the following values depend on the VIC clock,
33 * but to achieve TV-frequency the clock must have a fix frequency */
34#define TED7360_HSIZE   320
35#define TED7360_VSIZE   200
36/* of course you clock select an other clock, but for accurate */
37/* video timing (these are used in c16/c116/plus4) */
38#define TED7360NTSC_CLOCK   (14318180/4)
39#define TED7360PAL_CLOCK   (17734470/5)
40/* pixel clock 8 MHz */
41/* accesses to memory with 4 megahertz */
42/* needs 3 memory accesses for 8 pixel */
43/* but system clock 1 megahertz */
44/* cpu driven with one (visible screen area) or two cycles (when configured) */
45#define TED7360_CLOCK ((ted7360_pal?TED7360PAL_CLOCK:TED7360NTSC_CLOCK)/4)
46
47/* pal 50 Hz vertical screen refresh, screen consists of 312 lines
48 * ntsc 60 Hz vertical screen refresh, screen consists of 262 lines */
49#define TED7360NTSC_LINES 261
50#define TED7360PAL_LINES 312
51#define TED7360_LINES (ted7360_pal?TED7360PAL_LINES:TED7360NTSC_LINES)
52
53extern VIDEO_START( ted7360 );
54extern VIDEO_UPDATE( ted7360 );
55extern const unsigned char ted7360_palette[16 * 8 * 3];
56
57/* to be called when writting to port */
58extern WRITE8_HANDLER ( ted7360_port_w );
59
60/* to be called when reading from port */
61extern  READ8_HANDLER  ( ted7360_port_r );
62
63/* to be called each vertical retrace */
64INTERRUPT_GEN( ted7360_frame_interrupt );
65INTERRUPT_GEN( ted7360_raster_interrupt );
66
67/* private area */
68extern UINT8 ted7360[0x20];
69extern int ted7360_pal;
70extern int ted7360_rom;
71
72
73/*----------- defined in audio/ted7360.c -----------*/
74
75#define SOUND_TED7360      DEVICE_GET_INFO_NAME( ted7360_sound )
76
77DEVICE_GET_INFO( ted7360_sound );
78void ted7360_soundport_w (running_machine *machine, int mode, int data);
79
80
81#endif /* TED7360_H_ */
src/mess/video/vic4567.c
r7376r7377
19801980   vic3->lightpen_x_cb = intf->x_cb;
19811981   vic3->lightpen_y_cb = intf->y_cb;
19821982
1983   vic3->bitmap = auto_bitmap_alloc(device->machine, width, height, BITMAP_FORMAT_INDEXED16);
1984
19851983   vic3->screen[0] = auto_alloc_array(device->machine, UINT8, 216 * 656 / 8);
19861984
19871985   for (i = 1; i < 216; i++)
src/mess/video/vic6567.c
r7376r7377
25492549   vic2->lightpen_x_cb = intf->x_cb;
25502550   vic2->lightpen_y_cb = intf->y_cb;
25512551
2552   vic2->bitmap = auto_bitmap_alloc(device->machine, width, height, BITMAP_FORMAT_INDEXED16);
2553
25542552   // immediately call the timer to handle the first line
25552553   if (vic2->type == VIC6569 || vic2->type == VIC8566)
25562554      timer_set(device->machine, cpu_clocks_to_attotime(vic2->cpu, 0), vic2, 0, pal_timer_callback);
src/mess/includes/c16.h
r7376r7377
44 *
55 ****************************************************************************/
66
7#ifndef C16_H_
8#define C16_H_
7#ifndef __C16_H__
8#define __C16_H__
99
1010#include "devices/cartslot.h"
1111
r7376r7377
2828extern WRITE8_HANDLER(c16_switch_to_rom);
2929extern WRITE8_HANDLER(c16_switch_to_ram);
3030
31/* ted reads */
32extern int c16_read_keyboard (int databus);
33extern void c16_interrupt (running_machine *machine, int);
31/* ted reads (passed to the device interface) */
32extern UINT8 c16_read_keyboard(running_machine *machine, int databus);
33extern void c16_interrupt(running_machine *machine, int level);
34extern int c16_dma_read(running_machine *machine, int offset);
35extern int c16_dma_read_rom(running_machine *machine, int offset);
3436
3537extern DRIVER_INIT( c16 );
36extern DRIVER_INIT( c16c );
37extern DRIVER_INIT( c16v );
3838extern MACHINE_RESET( c16 );
3939extern MACHINE_START( c16 );
4040extern INTERRUPT_GEN( c16_frame_interrupt );
r7376r7377
5151extern void c364_speech_reset(running_machine *machine);
5252
5353
54#endif /* C16_H_ */
54#endif /* __C16_H__ */
src/mess/machine/c16.c
r7376r7377
1313#include "cpu/m6502/m6502.h"
1414#include "sound/sid6581.h"
1515
16#include "video/ted7360.h"
16#include "audio/ted7360.h"
1717#include "machine/cbmiec.h"
1818
1919#include "includes/c16.h"
r7376r7377
187187
188188WRITE8_HANDLER( c16_switch_to_rom )
189189{
190   ted7360_rom = 1;
190   running_device *ted7360 = devtag_get_device(space->machine, "ted7360");
191
192   ted7360_rom_switch_w(ted7360, 1);
191193   c16_bankswitch(space->machine);
192194}
193195
r7376r7377
206208 * 1  1  c2 high */
207209WRITE8_HANDLER( c16_select_roms )
208210{
211   running_device *ted7360 = devtag_get_device(space->machine, "ted7360");
212
209213   lowrom = offset & 0x03;
210214   highrom = (offset & 0x0c) >> 2;
211   if (ted7360_rom)
215   if (ted7360_rom_switch_r(ted7360))
212216      c16_bankswitch(space->machine);
213217}
214218
215219WRITE8_HANDLER( c16_switch_to_ram )
216220{
217   ted7360_rom = 0;
221   running_device *ted7360 = devtag_get_device(space->machine, "ted7360");
222
223   ted7360_rom_switch_w(ted7360, 0);
224
218225   memory_set_bankptr(space->machine, "bank2", messram_get_ptr(devtag_get_device(space->machine, "messram")) + (0x8000 % messram_get_size(devtag_get_device(space->machine, "messram"))));
219226   memory_set_bankptr(space->machine, "bank3", messram_get_ptr(devtag_get_device(space->machine, "messram")) + (0xc000 % messram_get_size(devtag_get_device(space->machine, "messram"))));
220227   memory_set_bankptr(space->machine, "bank4", messram_get_ptr(devtag_get_device(space->machine, "messram")) + (0xfc00 % messram_get_size(devtag_get_device(space->machine, "messram"))));
221228   memory_set_bankptr(space->machine, "bank8", messram_get_ptr(devtag_get_device(space->machine, "messram")) + (0xff20 % messram_get_size(devtag_get_device(space->machine, "messram"))));
222229}
223230
224int c16_read_keyboard( int databus )
231UINT8 c16_read_keyboard( running_machine *machine, int databus )
225232{
226   int value = 0xff;
233   UINT8 value = 0xff;
227234
228235   if (!(port6529 & 0x01))
229236      value &= keyline[0];
r7376r7377
279286
280287READ8_HANDLER( c16_6529_port_r )
281288{
282   return port6529 & (c16_read_keyboard (0xff /*databus */ ) | (port6529 ^ 0xff));
289   return port6529 & (c16_read_keyboard (space->machine, 0xff /*databus */ ) | (port6529 ^ 0xff));
283290}
284291
285292/*
r7376r7377
373380   return data;
374381}
375382
376static READ8_HANDLER( ted7360_dma_read )
383int c16_dma_read( running_machine *machine, int offset )
377384{
378   return messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset % messram_get_size(devtag_get_device(space->machine, "messram"))];
385   return messram_get_ptr(devtag_get_device(machine, "messram"))[offset % messram_get_size(devtag_get_device(machine, "messram"))];
379386}
380387
381static  READ8_HANDLER( ted7360_dma_read_rom )
388int c16_dma_read_rom( running_machine *machine, int offset )
382389{
383390   /* should read real c16 system bus from 0xfd00 -ff1f */
384391   if (offset >= 0xc000)
r7376r7377
398405            return c16_memory_28000[offset & 0x7fff];
399406      }
400407   }
408
401409   if (offset >= 0x8000)
402410   {                           /* rom address in rom */
403411      switch (lowrom)
r7376r7377
413421      }
414422   }
415423
416   return messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset % messram_get_size(devtag_get_device(space->machine, "messram"))];
424   return messram_get_ptr(devtag_get_device(machine, "messram"))[offset % messram_get_size(devtag_get_device(machine, "messram"))];
417425}
418426
419427void c16_interrupt( running_machine *machine, int level )
r7376r7377
450458   c16_memory_2c000 = rom + 0x2c000;
451459}
452460
453static void c16_driver_init( running_machine *machine )
461DRIVER_INIT( c16 )
454462{
455   int i;
456
457463   c16_common_driver_init(machine);
458
459   /* not sure this is the right place for this. ATM ted7360[] is shared by video and audio TED */
460   for(i = 0; i < 0x20; i++)
461      ted7360[i] = 0x00;
462   ted7360_rom = 1;   // FIX-ME: at start should be RAM or ROM?
463
464   ted7360_init(machine, (read_cfg1(machine) & 0x10) == 0x00);      /* is it PAL? */
465   ted7360_set_dma(ted7360_dma_read, ted7360_dma_read_rom);
466464}
467465
468
469DRIVER_INIT( c16 )
470{
471   c16_driver_init(machine);
472}
473
474DRIVER_INIT( c16c )
475{
476   c16_driver_init(machine);
477}
478
479DRIVER_INIT( c16v )
480{
481   c16_driver_init(machine);
482}
483
484466MACHINE_START( c16 )
485467{
486468   c364_speech_init(machine);
r7376r7377
522504      memory_install_write_bank(space, 0xff40, 0xffff, 0, 0, "bank11");
523505      memory_set_bankptr(machine, "bank10", messram_get_ptr(devtag_get_device(machine, "messram")) + (0xff20 % messram_get_size(devtag_get_device(machine, "messram"))));
524506      memory_set_bankptr(machine, "bank11", messram_get_ptr(devtag_get_device(machine, "messram")) + (0xff40 % messram_get_size(devtag_get_device(machine, "messram"))));
525
526      ted7360_set_dma (ted7360_dma_read, ted7360_dma_read_rom);
527507   }
528508   else
529509   {
530510      memory_install_write_bank(space, 0x4000, 0xfcff, 0, 0, "bank10");
531511      memory_set_bankptr(machine, "bank10", messram_get_ptr(devtag_get_device(machine, "messram")) + (0x4000 % messram_get_size(devtag_get_device(machine, "messram"))));
532
533      ted7360_set_dma (ted7360_dma_read, ted7360_dma_read_rom);
534512   }
535513}
536514
537515
538516INTERRUPT_GEN( c16_frame_interrupt )
539517{
518   running_device *ted7360 = devtag_get_device(device->machine, "ted7360");
540519   int value, i;
541520   static const char *const c16ports[] = { "ROW0", "ROW1", "ROW2", "ROW3", "ROW4", "ROW5", "ROW6", "ROW7" };
542521
r7376r7377
591570         keyline[9] = value;
592571   }
593572
594   ted7360_frame_interrupt (device);
573   ted7360_frame_interrupt_gen(ted7360);
595574
596575   set_led_status(device->machine, 1, input_port_read(device->machine, "SPECIAL") & 0x80 ? 1 : 0);      /* Shift Lock */
597576   set_led_status(device->machine, 0, input_port_read(device->machine, "SPECIAL") & 0x40 ? 1 : 0);      /* Joystick Swap */
src/mess/mess.mak
r7376r7377
711711   $(MESS_VIDEO)/cbmb.o      \
712712   $(MESS_DRIVERS)/c65.o      \
713713   $(MESS_DRIVERS)/c128.o      \
714   $(MESS_VIDEO)/ted7360.o      \
715714   $(MESS_MACHINE)/cbmiec.o   \
716715   $(MESS_MACHINE)/c1541.o      \
717716   $(MESS_MACHINE)/c1551.o      \
src/mess/drivers/c65.c
r7376r7377
390390
391391/*    YEAR  NAME    PARENT  COMPAT  MACHINE INPUT   INIT    COMPANY                         FULLNAME                                              FLAGS */
392392
393COMP( 1991, c65,    0,      0,      c65,    c65,    c65,    "Commodore Electronics, Ltd.",  "Commodore 65 Development System (Prototype, NTSC)", GAME_NOT_WORKING )
394COMP( 1991, c64dx,  c65,    0,      c65pal, c65ger, c65pal, "Commodore Electronics, Ltd.",  "Commodore 64DX Development System (Prototype, PAL, German)", GAME_NOT_WORKING )
393COMP( 1991, c65,    0,      0,      c65,    c65,    c65,    "Commodore Business Machines",  "Commodore 65 Development System (Prototype, NTSC)", GAME_NOT_WORKING )
394COMP( 1991, c64dx,  c65,    0,      c65pal, c65ger, c65pal, "Commodore Business Machines",  "Commodore 64DX Development System (Prototype, PAL, German)", GAME_NOT_WORKING )
src/mess/drivers/cbmb.c
r7376r7377
695695***************************************************************************/
696696
697697/*    YEAR  NAME      PARENT  COMPAT  MACHINE    INPUT      INIT       COMPANY                             FULLNAME                                  FLAGS */
698COMP( 1983,   b500,     cbm610, 0,      cbm600,    cbm600,    cbm600,    "Commodore Business Machines Co.",  "B500 (proto, 60Hz)",                     GAME_NOT_WORKING )
699COMP( 1983,   b128,     cbm610, 0,      cbm600pal, cbm600pal, cbm600pal, "Commodore Business Machines Co.",  "B128 (60Hz)",                            GAME_NOT_WORKING )
700COMP( 1983,   b256,     cbm610, 0,      cbm600pal, cbm600pal, cbm600hu,  "Commodore Business Machines Co.",  "B256 (60Hz)",                            GAME_NOT_WORKING )
701COMP( 1983,   cbm610,   0,      0,      cbm600,    cbm600,    cbm600,    "Commodore Business Machines Co.",  "CBM 610 (50Hz)",                         GAME_NOT_WORKING )
702COMP( 1983,   cbm620,   cbm610, 0,      cbm600pal, cbm600pal, cbm600pal, "Commodore Business Machines Co.",  "CBM 620 (50Hz)",                         GAME_NOT_WORKING )
703COMP( 1983,   cbm620hu, cbm610, 0,      cbm600pal, cbm600pal, cbm600hu,  "Commodore Business Machines Co.",  "CBM 620 (Hungary, 50Hz)",                GAME_NOT_WORKING )
698COMP( 1983,   b500,     cbm610, 0,      cbm600,    cbm600,    cbm600,    "Commodore Business Machines",  "B500 (proto, 60Hz)",                     GAME_NOT_WORKING )
699COMP( 1983,   b128,     cbm610, 0,      cbm600pal, cbm600pal, cbm600pal, "Commodore Business Machines",  "B128 (60Hz)",                            GAME_NOT_WORKING )
700COMP( 1983,   b256,     cbm610, 0,      cbm600pal, cbm600pal, cbm600hu,  "Commodore Business Machines",  "B256 (60Hz)",                            GAME_NOT_WORKING )
701COMP( 1983,   cbm610,   0,      0,      cbm600,    cbm600,    cbm600,    "Commodore Business Machines",  "CBM 610 (50Hz)",                         GAME_NOT_WORKING )
702COMP( 1983,   cbm620,   cbm610, 0,      cbm600pal, cbm600pal, cbm600pal, "Commodore Business Machines",  "CBM 620 (50Hz)",                         GAME_NOT_WORKING )
703COMP( 1983,   cbm620hu, cbm610, 0,      cbm600pal, cbm600pal, cbm600hu,  "Commodore Business Machines",  "CBM 620 (Hungary, 50Hz)",                GAME_NOT_WORKING )
704704
705COMP( 1983, b128hp,   cbm610, 0,      cbm700,    cbm700,    cbm700,    "Commodore Business Machines Co.",  "B128-80HP (60Hz)",                       GAME_NOT_WORKING )
706COMP( 1983, b256hp,   cbm610, 0,      cbm700,    cbm700,    cbm700,    "Commodore Business Machines Co.",  "B256-80HP (60Hz)",                       GAME_NOT_WORKING )
707COMP( 1983, cbm710,   cbm610, 0,      cbm700pal, cbm700,    cbm700,    "Commodore Business Machines Co.",  "CBM 710 (50Hz)",                         GAME_NOT_WORKING )
708COMP( 1983, cbm720,   cbm610, 0,      cbm700pal, cbm700,    cbm700,    "Commodore Business Machines Co.",  "CBM 720 (50Hz)",                         GAME_NOT_WORKING )
709COMP( 1983, cbm720se, cbm610, 0,      cbm700pal, cbm700,    cbm700,    "Commodore Business Machines Co.",  "CBM 720 (Sweden/Finland, 50Hz)",         GAME_NOT_WORKING )
705COMP( 1983, b128hp,   cbm610, 0,      cbm700,    cbm700,    cbm700,    "Commodore Business Machines",  "B128-80HP (60Hz)",                       GAME_NOT_WORKING )
706COMP( 1983, b256hp,   cbm610, 0,      cbm700,    cbm700,    cbm700,    "Commodore Business Machines",  "B256-80HP (60Hz)",                       GAME_NOT_WORKING )
707COMP( 1983, cbm710,   cbm610, 0,      cbm700pal, cbm700,    cbm700,    "Commodore Business Machines",  "CBM 710 (50Hz)",                         GAME_NOT_WORKING )
708COMP( 1983, cbm720,   cbm610, 0,      cbm700pal, cbm700,    cbm700,    "Commodore Business Machines",  "CBM 720 (50Hz)",                         GAME_NOT_WORKING )
709COMP( 1983, cbm720se, cbm610, 0,      cbm700pal, cbm700,    cbm700,    "Commodore Business Machines",  "CBM 720 (Sweden/Finland, 50Hz)",         GAME_NOT_WORKING )
710710
711COMP( 1983,   bx256hp,  cbm610, 0,      bx256hp,   cbm700,    cbm700,    "Commodore Business Machines Co.",  "BX256-80HP (60Hz)",                      GAME_NOT_WORKING )
711COMP( 1983,   bx256hp,  cbm610, 0,      bx256hp,   cbm700,    cbm700,    "Commodore Business Machines",  "BX256-80HP (60Hz)",                      GAME_NOT_WORKING )
712712
713COMP( 1983,   p500,     0,      0,      p500,      p500,      p500,      "Commodore Business Machines Co.",  "P500 (proto, a.k.a. B128-40 or Pet-II)", GAME_NOT_WORKING )
713COMP( 1983,   p500,     0,      0,      p500,      p500,      p500,      "Commodore Business Machines",  "P500 (proto, a.k.a. B128-40 or Pet-II)", GAME_NOT_WORKING )
src/mess/drivers/vic20.c
r7376r7377
629629 
630630/* Machine Driver */
631631 
632INTERRUPT_GEN( vic20_raster_interrupt )
632static INTERRUPT_GEN( vic20_raster_interrupt )
633633{
634634   vic20_state *state = (vic20_state *)device->machine->driver_data;
635635   vic656x_raster_interrupt_gen(state->vic6560);
src/mess/drivers/c128.c
r7376r7377
10831083
10841084/*    YEAR  NAME     PARENT COMPAT MACHINE   INPUT    INIT      COMPANY                             FULLNAME            FLAGS */
10851085
1086COMP( 1985, c128,      0,     0,   c128,     c128,    c128,     "Commodore Business Machines Co.", "Commodore 128 (NTSC)", 0)
1087COMP( 1985, c128cr,    c128,  0,   c128,     c128,    c128,     "Commodore Business Machines Co.", "Commodore 128CR (NTSC, proto?)", 0)
1086COMP( 1985, c128,      0,     0,   c128,     c128,    c128,     "Commodore Business Machines", "Commodore 128 (NTSC)", 0)
1087COMP( 1985, c128cr,    c128,  0,   c128,     c128,    c128,     "Commodore Business Machines", "Commodore 128CR (NTSC, proto?)", 0)
10881088
1089COMP( 1985, c128sfi,   c128,  0,   c128pal,  c128fra, c128pal,  "Commodore Business Machines Co.", "Commodore 128 (PAL, Swedish / Finnish)", 0)
1090COMP( 1985, c128fino,  c128,  0,   c128pal,  c128swe, c128pal,  "Commodore Business Machines Co.", "Commodore 128 (PAL, Finland, Unconfirmed Dumps)", 0)
1091COMP( 1985, c128fra,   c128,  0,   c128pal,  c128fra, c128pal,  "Commodore Business Machines Co.", "Commodore 128 (PAL, France)", 0)
1092COMP( 1985, c128ger,   c128,  0,   c128pal,  c128ger, c128pal,  "Commodore Business Machines Co.", "Commodore 128 (PAL, Germany)", 0)
1093COMP( 1985, c128nor,   c128,  0,   c128pal,  c128ita, c128pal,  "Commodore Business Machines Co.", "Commodore 128 (PAL, Norway)", 0)
1089COMP( 1985, c128sfi,   c128,  0,   c128pal,  c128fra, c128pal,  "Commodore Business Machines", "Commodore 128 (PAL, Swedish / Finnish)", 0)
1090COMP( 1985, c128fino,  c128,  0,   c128pal,  c128swe, c128pal,  "Commodore Business Machines", "Commodore 128 (PAL, Finland, Unconfirmed Dumps)", 0)
1091COMP( 1985, c128fra,   c128,  0,   c128pal,  c128fra, c128pal,  "Commodore Business Machines", "Commodore 128 (PAL, France)", 0)
1092COMP( 1985, c128ger,   c128,  0,   c128pal,  c128ger, c128pal,  "Commodore Business Machines", "Commodore 128 (PAL, Germany)", 0)
1093COMP( 1985, c128nor,   c128,  0,   c128pal,  c128ita, c128pal,  "Commodore Business Machines", "Commodore 128 (PAL, Norway)", 0)
10941094// we miss other countries: Spain, Belgium, etc.
10951095
10961096// the following drivers use a 1571 floppy drive
1097COMP( 1985, c128dpr,   c128,  0,   c128d,    c128,    c128d,   "Commodore Business Machines Co.", "Commodore 128D (NTSC, proto)", GAME_NOT_WORKING )
1098COMP( 1985, c128d,     c128,  0,   c128dpal, c128,    c128dpal,"Commodore Business Machines Co.", "Commodore 128D (PAL)", GAME_NOT_WORKING )
1097COMP( 1985, c128dpr,   c128,  0,   c128d,    c128,    c128d,   "Commodore Business Machines", "Commodore 128D (NTSC, proto)", GAME_NOT_WORKING )
1098COMP( 1985, c128d,     c128,  0,   c128dpal, c128,    c128dpal,"Commodore Business Machines", "Commodore 128D (PAL)", GAME_NOT_WORKING )
10991099
11001100// the following drivers use a 1571CR floppy drive
1101COMP( 1986, c128dcr,   c128,  0,   c128dcr,  c128,    c128dcr, "Commodore Business Machines Co.", "Commodore 128DCR (NTSC)", GAME_NOT_WORKING)
1102COMP( 1986, c128drde,  c128,  0,   c128dcrp, c128ger, c128dcrp,"Commodore Business Machines Co.", "Commodore 128DCR (PAL, Germany)", GAME_NOT_WORKING)
1103COMP( 1986, c128drit,  c128,  0,   c128dcrp, c128ita, c128dcrp,"Commodore Business Machines Co.", "Commodore 128DCR (PAL, Italy)", GAME_NOT_WORKING)
1104COMP( 1986, c128drsw,  c128,  0,   c128dcrp, c128swe, c128dcrp,"Commodore Business Machines Co.", "Commodore 128DCR (PAL, Sweden)", GAME_NOT_WORKING)
1101COMP( 1986, c128dcr,   c128,  0,   c128dcr,  c128,    c128dcr, "Commodore Business Machines", "Commodore 128DCR (NTSC)", GAME_NOT_WORKING)
1102COMP( 1986, c128drde,  c128,  0,   c128dcrp, c128ger, c128dcrp,"Commodore Business Machines", "Commodore 128DCR (PAL, Germany)", GAME_NOT_WORKING)
1103COMP( 1986, c128drit,  c128,  0,   c128dcrp, c128ita, c128dcrp,"Commodore Business Machines", "Commodore 128DCR (PAL, Italy)", GAME_NOT_WORKING)
1104COMP( 1986, c128drsw,  c128,  0,   c128dcrp, c128swe, c128dcrp,"Commodore Business Machines", "Commodore 128DCR (PAL, Sweden)", GAME_NOT_WORKING)
11051105
11061106// the following driver is a c128 with 1581 floppy drive. it allows us to document 1581 firmware dumps, but it does not do much more
1107COMP( 1986, c128d81,   c128,  0,   c128d81,  c128,    c128d81, "Commodore Business Machines Co.", "Commodore 128D/81 (NTSC, proto)", GAME_NOT_WORKING)
1107COMP( 1986, c128d81,   c128,  0,   c128d81,  c128,    c128d81, "Commodore Business Machines", "Commodore 128D/81 (NTSC, proto)", GAME_NOT_WORKING)
src/mess/drivers/pet.c
r7376r7377
11461146
11471147/* YEAR    NAME      PARENT    COMPAT    MACHINE   INPUT     INIT      COMPANY                             FULLNAME */
11481148
1149COMP(1977, pet2001,  0,        0,        pet2001,  pet,      pet2001, "Commodore Business Machines Co.",  "PET 2001", GAME_NO_SOUND)
1150COMP(1979, pet2001n, pet2001,  0,        pet,      pet,      pet,     "Commodore Business Machines Co.",  "PET 2001-N", GAME_NO_SOUND)
1151COMP(1979, pet2001b, pet2001,  0,        petb,     petb,     pet,     "Commodore Business Machines Co.",  "PET 2001-B", GAME_NO_SOUND)
1152COMP(1979, cbm30,    pet2001,  0,        pet,      pet,      pet,     "Commodore Business Machines Co.",  "CBM 30xx", GAME_NO_SOUND)
1153COMP(1979, cbm30b,   pet2001,  0,        petb,     petb,     pet,     "Commodore Business Machines Co.",  "CBM 30xx (Business keyboard)", GAME_NO_SOUND)
1154COMP(1979, cbm30nor, pet2001,  0,        petb,     petb,     pet,     "Commodore Business Machines Co.",  "CBM 30xx (Norway, Business keyboard)", GAME_NO_SOUND)
1149COMP(1977, pet2001,  0,        0,        pet2001,  pet,      pet2001, "Commodore Business Machines",  "PET 2001", GAME_NO_SOUND)
1150COMP(1979, pet2001n, pet2001,  0,        pet,      pet,      pet,     "Commodore Business Machines",  "PET 2001-N", GAME_NO_SOUND)
1151COMP(1979, pet2001b, pet2001,  0,        petb,     petb,     pet,     "Commodore Business Machines",  "PET 2001-B", GAME_NO_SOUND)
1152COMP(1979, cbm30,    pet2001,  0,        pet,      pet,      pet,     "Commodore Business Machines",  "CBM 30xx", GAME_NO_SOUND)
1153COMP(1979, cbm30b,   pet2001,  0,        petb,     petb,     pet,     "Commodore Business Machines",  "CBM 30xx (Business keyboard)", GAME_NO_SOUND)
1154COMP(1979, cbm30nor, pet2001,  0,        petb,     petb,     pet,     "Commodore Business Machines",  "CBM 30xx (Norway, Business keyboard)", GAME_NO_SOUND)
11551155
11561156/* So called, THIN-40 */
1157COMP(1980, pet40on,  pet2001,  0,        pet,      pet,      pet,     "Commodore Business Machines Co.",  "PET 40xx (Basic 4, no CRTC, Normal keyboard)", GAME_NO_SOUND)
1158COMP(1980, pet40ob,  pet2001,  0,        petb,     petb,     pet,     "Commodore Business Machines Co.",  "PET 40xx (Basic 4, no CRTC, Business keyboard)", GAME_NO_SOUND)
1159COMP(1980, cbm40o,   pet2001,  0,        pet,      pet,      pet,     "Commodore Business Machines Co.",  "CBM 40xx (Basic 4, no CRTC, Normal keyboard)", GAME_NO_SOUND)
1160COMP(1980, cbm40ob,  pet2001,  0,        petb,     petb,     pet,     "Commodore Business Machines Co.",  "CBM 40xx (Basic 4, no CRTC, Business keyboard)", GAME_NO_SOUND)
1157COMP(1980, pet40on,  pet2001,  0,        pet,      pet,      pet,     "Commodore Business Machines",  "PET 40xx (Basic 4, no CRTC, Normal keyboard)", GAME_NO_SOUND)
1158COMP(1980, pet40ob,  pet2001,  0,        petb,     petb,     pet,     "Commodore Business Machines",  "PET 40xx (Basic 4, no CRTC, Business keyboard)", GAME_NO_SOUND)
1159COMP(1980, cbm40o,   pet2001,  0,        pet,      pet,      pet,     "Commodore Business Machines",  "CBM 40xx (Basic 4, no CRTC, Normal keyboard)", GAME_NO_SOUND)
1160COMP(1980, cbm40ob,  pet2001,  0,        petb,     petb,     pet,     "Commodore Business Machines",  "CBM 40xx (Basic 4, no CRTC, Business keyboard)", GAME_NO_SOUND)
11611161
1162COMP(1981, pet80,    0,        0,        pet80,    cbm8096,  pet80,   "Commodore Business Machines Co.",  "PET 80xx (Basic 4, CRTC 60Hz, 80 columns)", GAME_NO_SOUND)
1163COMP(1981, cbm80,    pet80,    0,        pet80pal, cbm8096,  pet80,   "Commodore Business Machines Co.",  "CBM 80xx (Basic 4, CRTC 50Hz, 80 columns)", GAME_NO_SOUND)
1164COMP(1981, cbm80ger, pet80,    0,        pet80pal, cbm8096,  pet80,   "Commodore Business Machines Co.",  "CBM 80xx (Germany, Basic 4, CRTC 50Hz, 80 columns)", GAME_NO_SOUND)
1165COMP(1981, cbm80hun, pet80,    0,        pet80pal, cbm8096,  pet80,   "Commodore Business Machines Co.",  "CBM 80xx (Hungary, Basic 4, CRTC 50Hz, 80 columns)", GAME_NO_SOUND)
1166COMP(1981, cbm80swe, pet80,    0,        pet80pal, cbm8096,  pet80,   "Commodore Business Machines Co.",  "CBM 80xx (Sweden, Basic 4, CRTC 50Hz, 80 columns)", GAME_NO_SOUND)
1162COMP(1981, pet80,    0,        0,        pet80,    cbm8096,  pet80,   "Commodore Business Machines",  "PET 80xx (Basic 4, CRTC 60Hz, 80 columns)", GAME_NO_SOUND)
1163COMP(1981, cbm80,    pet80,    0,        pet80pal, cbm8096,  pet80,   "Commodore Business Machines",  "CBM 80xx (Basic 4, CRTC 50Hz, 80 columns)", GAME_NO_SOUND)
1164COMP(1981, cbm80ger, pet80,    0,        pet80pal, cbm8096,  pet80,   "Commodore Business Machines",  "CBM 80xx (Germany, Basic 4, CRTC 50Hz, 80 columns)", GAME_NO_SOUND)
1165COMP(1981, cbm80hun, pet80,    0,        pet80pal, cbm8096,  pet80,   "Commodore Business Machines",  "CBM 80xx (Hungary, Basic 4, CRTC 50Hz, 80 columns)", GAME_NO_SOUND)
1166COMP(1981, cbm80swe, pet80,    0,        pet80pal, cbm8096,  pet80,   "Commodore Business Machines",  "CBM 80xx (Sweden, Basic 4, CRTC 50Hz, 80 columns)", GAME_NO_SOUND)
11671167
11681168/* So called, FAT-40 */
1169COMP(1981, pet40b,   pet80,    0,        pet80,    cbm8096,  pet80,   "Commodore Business Machines Co.",  "PET 40xx (Basic 4, CRTC 60Hz, 80 columns)", GAME_NO_SOUND)
1170COMP(1981, pet40n,   pet2001,  0,        pet40,    pet,      pet,     "Commodore Business Machines Co.",  "PET 40xx (Basic 4, CRTC 60Hz, 40 columns)", GAME_NO_SOUND)
1171COMP(1981, cbm40b,   pet80,    0,        pet80pal, cbm8096,  pet80,   "Commodore Business Machines Co.",  "CBM 40xx (Basic 4, CRTC 50Hz, 80 columns)", GAME_NO_SOUND)
1172COMP(1981, cbm40n,   pet2001,  0,        pet40pal, pet,      pet,     "Commodore Business Machines Co.",  "CBM 40xx (Basic 4, CRTC 50Hz, 40 columns)", GAME_NO_SOUND)
1169COMP(1981, pet40b,   pet80,    0,        pet80,    cbm8096,  pet80,   "Commodore Business Machines",  "PET 40xx (Basic 4, CRTC 60Hz, 80 columns)", GAME_NO_SOUND)
1170COMP(1981, pet40n,   pet2001,  0,        pet40,    pet,      pet,     "Commodore Business Machines",  "PET 40xx (Basic 4, CRTC 60Hz, 40 columns)", GAME_NO_SOUND)
1171COMP(1981, cbm40b,   pet80,    0,        pet80pal, cbm8096,  pet80,   "Commodore Business Machines",  "CBM 40xx (Basic 4, CRTC 50Hz, 80 columns)", GAME_NO_SOUND)
1172COMP(1981, cbm40n,   pet2001,  0,        pet40pal, pet,      pet,     "Commodore Business Machines",  "CBM 40xx (Basic 4, CRTC 50Hz, 40 columns)", GAME_NO_SOUND)
11731173
1174COMP(1981, superpet, 0,        0,        superpet, superpet, superpet,"Commodore Business Machines Co.",  "SuperPET (CRTC 50Hz)", GAME_NO_SOUND | GAME_NOT_WORKING)
1175COMP(1981, sp9000,   superpet, 0,        superpet, superpet, superpet,"Commodore Business Machines Co.",  "CBM SP9000 / MicroMainFrame 9000 (CRTC 50Hz)", GAME_NO_SOUND | GAME_NOT_WORKING)
1176COMP(198?, mmf9000s, superpet, 0,        superpet, superpet, superpet,"Commodore Business Machines Co.",  "MicroMainFrame 9000 (Sweden, CRTC 50Hz)", GAME_NO_SOUND | GAME_NOT_WORKING)
1174COMP(1981, superpet, 0,        0,        superpet, superpet, superpet,"Commodore Business Machines",  "SuperPET (CRTC 50Hz)", GAME_NO_SOUND | GAME_NOT_WORKING)
1175COMP(1981, sp9000,   superpet, 0,        superpet, superpet, superpet,"Commodore Business Machines",  "CBM SP9000 / MicroMainFrame 9000 (CRTC 50Hz)", GAME_NO_SOUND | GAME_NOT_WORKING)
1176COMP(198?, mmf9000s, superpet, 0,        superpet, superpet, superpet,"Commodore Business Machines",  "MicroMainFrame 9000 (Sweden, CRTC 50Hz)", GAME_NO_SOUND | GAME_NOT_WORKING)
11771177
1178COMP(1984, cbm8296,  pet80,    0,        pet80pal, cbm8096,  pet80,   "Commodore Business Machines Co.",  "CBM 8296 (Basic 4, CRTC 50Hz, 80 columns)", GAME_NO_SOUND)
1179COMP(1984, cbm8296d, pet80,    0,        pet80pal, cbm8096,  pet80,   "Commodore Business Machines Co.",  "CBM 8296D", GAME_NO_SOUND)
1178COMP(1984, cbm8296,  pet80,    0,        pet80pal, cbm8096,  pet80,   "Commodore Business Machines",  "CBM 8296 (Basic 4, CRTC 50Hz, 80 columns)", GAME_NO_SOUND)
1179COMP(1984, cbm8296d, pet80,    0,        pet80pal, cbm8096,  pet80,   "Commodore Business Machines",  "CBM 8296D", GAME_NO_SOUND)
src/mess/drivers/c16.c
r7376r7377
117117#include "sound/sid6581.h"
118118
119119#include "machine/cbmipt.h"
120#include "video/ted7360.h"
120#include "audio/ted7360.h"
121121#include "devices/messram.h"
122122#include "machine/c1541.h"
123123#include "machine/c1551.h"
r7376r7377
180180   AM_RANGE(0xfd10, 0xfd1f) AM_READ(c16_fd1x_r)
181181   AM_RANGE(0xfd30, 0xfd3f) AM_READWRITE(c16_6529_port_r, c16_6529_port_w)      /* 6529 keyboard matrix */
182182   AM_RANGE(0xfdd0, 0xfddf) AM_WRITE(c16_select_roms) /* rom chips selection */
183   AM_RANGE(0xff00, 0xff1f) AM_READWRITE(ted7360_port_r, ted7360_port_w)
183   AM_RANGE(0xff00, 0xff1f) AM_DEVREADWRITE("ted7360", ted7360_port_r, ted7360_port_w)
184184   AM_RANGE(0xff20, 0xffff) AM_READ_BANK("bank8")
185185   AM_RANGE(0xff3e, 0xff3e) AM_WRITE(c16_switch_to_rom)
186186   AM_RANGE(0xff3f, 0xff3f) AM_WRITE(c16_switch_to_ram)
r7376r7377
207207#if 0
208208   AM_RANGE(0xfd40, 0xfd5f) AM_DEVREADWRITE("sid6581", sid6581_r, sid6581_w)   /* sidcard, eoroidpro ... */
209209#endif
210   AM_RANGE(0xff00, 0xff1f) AM_READWRITE(ted7360_port_r, ted7360_port_w)
210   AM_RANGE(0xff00, 0xff1f) AM_DEVREADWRITE("ted7360", ted7360_port_r, ted7360_port_w)
211211   AM_RANGE(0xff20, 0xffff) AM_READ_BANK("bank8")
212212   AM_RANGE(0xff20, 0xff3d) AM_WRITEONLY
213213   AM_RANGE(0xff3e, 0xff3e) AM_WRITE(c16_switch_to_rom)
r7376r7377
229229#if 0
230230   AM_RANGE(0xfd40, 0xfd5f) AM_DEVREADWRITE("sid6581", sid6581_r, sid6581_w)   /* sidcard, eoroidpro ... */
231231#endif
232   AM_RANGE(0xff00, 0xff1f) AM_READWRITE(ted7360_port_r, ted7360_port_w)
232   AM_RANGE(0xff00, 0xff1f) AM_DEVREADWRITE("ted7360", ted7360_port_r, ted7360_port_w)
233233   AM_RANGE(0xff20, 0xffff) AM_READ_BANK("bank8")
234234   AM_RANGE(0xff20, 0xff3d) AM_WRITEONLY
235235   AM_RANGE(0xff3e, 0xff3e) AM_WRITE(c16_switch_to_rom)
r7376r7377
328328 *
329329 *************************************/
330330
331static const unsigned char ted7360_palette[] =
332{
333/* black, white, red, cyan */
334/* purple, green, blue, yellow */
335/* orange, light orange, pink, light cyan, */
336/* light violett, light green, light blue, light yellow */
337/* these 16 colors are 8 times here in different luminance (dark..light) */
338/* taken from digitized tv screenshot */
339   0x06, 0x01, 0x03, 0x2b, 0x2b, 0x2b, 0x67, 0x0e, 0x0f, 0x00, 0x3f, 0x42,
340   0x57, 0x00, 0x6d, 0x00, 0x4e, 0x00, 0x19, 0x1c, 0x94, 0x38, 0x38, 0x00,
341   0x56, 0x20, 0x00, 0x4b, 0x28, 0x00, 0x16, 0x48, 0x00, 0x69, 0x07, 0x2f,
342   0x00, 0x46, 0x26, 0x06, 0x2a, 0x80, 0x2a, 0x14, 0x9b, 0x0b, 0x49, 0x00,
331343
344   0x00, 0x03, 0x02, 0x3d, 0x3d, 0x3d, 0x75, 0x1e, 0x20, 0x00, 0x50, 0x4f,
345   0x6a, 0x10, 0x78, 0x04, 0x5c, 0x00, 0x2a, 0x2a, 0xa3, 0x4c, 0x47, 0x00,
346   0x69, 0x2f, 0x00, 0x59, 0x38, 0x00, 0x26, 0x56, 0x00, 0x75, 0x15, 0x41,
347   0x00, 0x58, 0x3d, 0x15, 0x3d, 0x8f, 0x39, 0x22, 0xae, 0x19, 0x59, 0x00,
348
349   0x00, 0x03, 0x04, 0x42, 0x42, 0x42, 0x7b, 0x28, 0x20, 0x02, 0x56, 0x59,
350   0x6f, 0x1a, 0x82, 0x0a, 0x65, 0x09, 0x30, 0x34, 0xa7, 0x50, 0x51, 0x00,
351   0x6e, 0x36, 0x00, 0x65, 0x40, 0x00, 0x2c, 0x5c, 0x00, 0x7d, 0x1e, 0x45,
352   0x01, 0x61, 0x45, 0x1c, 0x45, 0x99, 0x42, 0x2d, 0xad, 0x1d, 0x62, 0x00,
353
354   0x05, 0x00, 0x02, 0x56, 0x55, 0x5a, 0x90, 0x3c, 0x3b, 0x17, 0x6d, 0x72,
355   0x87, 0x2d, 0x99, 0x1f, 0x7b, 0x15, 0x46, 0x49, 0xc1, 0x66, 0x63, 0x00,
356   0x84, 0x4c, 0x0d, 0x73, 0x55, 0x00, 0x40, 0x72, 0x00, 0x91, 0x33, 0x5e,
357   0x19, 0x74, 0x5c, 0x32, 0x59, 0xae, 0x59, 0x3f, 0xc3, 0x32, 0x76, 0x00,
358
359   0x02, 0x01, 0x06, 0x84, 0x7e, 0x85, 0xbb, 0x67, 0x68, 0x45, 0x96, 0x96,
360   0xaf, 0x58, 0xc3, 0x4a, 0xa7, 0x3e, 0x73, 0x73, 0xec, 0x92, 0x8d, 0x11,
361   0xaf, 0x78, 0x32, 0xa1, 0x80, 0x20, 0x6c, 0x9e, 0x12, 0xba, 0x5f, 0x89,
362   0x46, 0x9f, 0x83, 0x61, 0x85, 0xdd, 0x84, 0x6c, 0xef, 0x5d, 0xa3, 0x29,
363
364   0x02, 0x00, 0x0a, 0xb2, 0xac, 0xb3, 0xe9, 0x92, 0x92, 0x6c, 0xc3, 0xc1,
365   0xd9, 0x86, 0xf0, 0x79, 0xd1, 0x76, 0x9d, 0xa1, 0xff, 0xbd, 0xbe, 0x40,
366   0xdc, 0xa2, 0x61, 0xd1, 0xa9, 0x4c, 0x93, 0xc8, 0x3d, 0xe9, 0x8a, 0xb1,
367   0x6f, 0xcd, 0xab, 0x8a, 0xb4, 0xff, 0xb2, 0x9a, 0xff, 0x88, 0xcb, 0x59,
368
369   0x02, 0x00, 0x0a, 0xc7, 0xca, 0xc9, 0xff, 0xac, 0xac, 0x85, 0xd8, 0xe0,
370   0xf3, 0x9c, 0xff, 0x92, 0xea, 0x8a, 0xb7, 0xba, 0xff, 0xd6, 0xd3, 0x5b,
371   0xf3, 0xbe, 0x79, 0xe6, 0xc5, 0x65, 0xb0, 0xe0, 0x57, 0xff, 0xa4, 0xcf,
372   0x89, 0xe5, 0xc8, 0xa4, 0xca, 0xff, 0xca, 0xb3, 0xff, 0xa2, 0xe5, 0x7a,
373
374   0x01, 0x01, 0x01, 0xff, 0xff, 0xff, 0xff, 0xf6, 0xf2, 0xd1, 0xff, 0xff,
375   0xff, 0xe9, 0xff, 0xdb, 0xff, 0xd3, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xa3,
376   0xff, 0xff, 0xc1, 0xff, 0xff, 0xb2, 0xfc, 0xff, 0xa2, 0xff, 0xee, 0xff,
377   0xd1, 0xff, 0xff, 0xeb, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xed, 0xff, 0xbc
378};
379
332380static PALETTE_INIT( c16 )
333381{
334382   int i;
335383
336   for ( i = 0; i < sizeof(ted7360_palette) / 3; i++ ) {
337      palette_set_color_rgb(machine, i, ted7360_palette[i*3], ted7360_palette[i*3+1], ted7360_palette[i*3+2]);
338   }
384   for (i = 0; i < sizeof(ted7360_palette) / 3; i++)
385      palette_set_color_rgb(machine, i, ted7360_palette[i * 3], ted7360_palette[i * 3 + 1], ted7360_palette[i * 3 + 2]);
339386}
340387
388/*************************************
389 *
390 *  TED7360 interfaces
391 *
392 *************************************/
341393
394static const ted7360_interface c16_ted7360_intf = {
395   "screen",
396   TED7360_PAL,
397   c16_dma_read,
398   c16_dma_read_rom,
399   c16_interrupt,
400   c16_read_keyboard
401};
342402
403static const ted7360_interface plus4_ted7360_intf = {
404   "screen",
405   TED7360_NTSC,
406   c16_dma_read,
407   c16_dma_read_rom,
408   c16_interrupt,
409   c16_read_keyboard
410};
343411
412
344413/*************************************
345414 *
346415 *  Machine driver
r7376r7377
368437   { NULL}
369438};
370439
440static VIDEO_UPDATE( c16 )
441{
442   running_device *ted7360 = devtag_get_device(screen->machine, "ted7360");
443   ted7360_video_update(ted7360, bitmap, cliprect);
444   return 0;
445}
446
447static INTERRUPT_GEN( c16_raster_interrupt )
448{
449   running_device *ted7360 = devtag_get_device(device->machine, "ted7360");
450   ted7360_raster_interrupt_gen(ted7360);
451}
452
453
371454static MACHINE_DRIVER_START( c16 )
372455   /* basic machine hardware */
373456   MDRV_CPU_ADD("maincpu", M7501, XTAL_17_73447MHz/20)
374457   MDRV_CPU_PROGRAM_MAP(c16_map)
375458   MDRV_CPU_CONFIG( c16_m7501_interface )
376459   MDRV_CPU_VBLANK_INT("screen", c16_frame_interrupt)
377   MDRV_CPU_PERIODIC_INT(ted7360_raster_interrupt, TED7360_HRETRACERATE)
460   MDRV_CPU_PERIODIC_INT(c16_raster_interrupt, TED7360_HRETRACERATE)
378461   MDRV_QUANTUM_TIME(HZ(60))
379462
380463   MDRV_MACHINE_RESET( c16 )
381464
382    /* video hardware */
465   /* video hardware */
383466   MDRV_SCREEN_ADD("screen", RASTER)
384467   MDRV_SCREEN_REFRESH_RATE(TED7360PAL_VRETRACERATE)
385468   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
r7376r7377
389472   MDRV_PALETTE_LENGTH(ARRAY_LENGTH(ted7360_palette) / 3)
390473   MDRV_PALETTE_INIT(c16)
391474
392   MDRV_VIDEO_START( ted7360 )
393   MDRV_VIDEO_UPDATE( ted7360 )
475   MDRV_VIDEO_UPDATE( c16 )
394476
395477   /* sound hardware */
396478   MDRV_SPEAKER_STANDARD_MONO("mono")
397   MDRV_SOUND_ADD("ted7360", TED7360, 0)
479   MDRV_TED7360_ADD("ted7360", c16_ted7360_intf)
398480   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
399481   MDRV_SOUND_ADD("sid", SID8580, TED7360PAL_CLOCK/4)
400482   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
r7376r7377
455537
456538   MDRV_SOUND_REPLACE("sid", SID8580, TED7360NTSC_CLOCK/4)
457539
540   MDRV_DEVICE_REMOVE("ted7360")
541   MDRV_TED7360_ADD("ted7360", plus4_ted7360_intf)
542   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
543
458544   /* internal ram */
459545   MDRV_RAM_MODIFY("messram")
460546   MDRV_RAM_DEFAULT_SIZE("64K")
r7376r7377
617703
618704/*    YEAR  NAME  PARENT COMPAT MACHINE INPUT   INIT      COMPANY                             FULLNAME            FLAGS */
619705
620COMP( 1984, c16,     0,     0,  c16,    c16,    c16,   "Commodore Business Machines Co.",  "Commodore 16 (PAL)", 0)
621COMP( 1984, c16c,    c16,   0,  c16c,   c16,    c16c,  "Commodore Business Machines Co.",  "Commodore 16 (PAL, 1551)", 0 )
622COMP( 1984, c16v,    c16,   0,  c16v,   c16,    c16v,  "Commodore Business Machines Co.",  "Commodore 16 (PAL, VC1541)", 0)
623COMP( 1984, c16hun,  c16,   0,  c16,    c16,    c16,   "Commodore Business Machines Co.",  "Commodore 16 Novotrade (PAL, Hungary)", 0)
706COMP( 1984, c16,     0,     0,  c16,    c16,    c16,   "Commodore Business Machines",  "Commodore 16 (PAL)", 0)
707COMP( 1984, c16c,    c16,   0,  c16c,   c16,    c16,   "Commodore Business Machines",  "Commodore 16 (PAL, 1551)", 0 )
708COMP( 1984, c16v,    c16,   0,  c16v,   c16,    c16,   "Commodore Business Machines",  "Commodore 16 (PAL, VC1541)", 0)
709COMP( 1984, c16hun,  c16,   0,  c16,    c16,    c16,   "Commodore Business Machines",  "Commodore 16 Novotrade (PAL, Hungary)", 0)
624710
625COMP( 1984, c116,    c16,   0,  c16,    c16,    c16,   "Commodore Business Machines Co.",  "Commodore 116 (PAL)", 0)
626COMP( 1984, c116c,    c16,   0,  c16c,   c16,    c16c,  "Commodore Business Machines Co.",  "Commodore 116 (PAL, 1551)", 0 )
627COMP( 1984, c116v,   c16,   0,  c16v,   c16,    c16v,  "Commodore Business Machines Co.",  "Commodore 116 (PAL, VC1541)", 0 )
711COMP( 1984, c116,    c16,   0,  c16,    c16,    c16,   "Commodore Business Machines",  "Commodore 116 (PAL)", 0)
712COMP( 1984, c116c,   c16,   0,  c16c,   c16,    c16,   "Commodore Business Machines",  "Commodore 116 (PAL, 1551)", 0 )
713COMP( 1984, c116v,   c16,   0,  c16v,   c16,    c16,   "Commodore Business Machines",  "Commodore 116 (PAL, VC1541)", 0 )
628714
629COMP( 1984, plus4,   c16,   0,  plus4,  plus4,  c16,   "Commodore Business Machines Co.",  "Commodore Plus/4 (NTSC)", 0)
630COMP( 1984, plus4c,  c16,   0,  plus4c, plus4,  c16c,  "Commodore Business Machines Co.",  "Commodore Plus/4 (NTSC, 1551)", 0 )
631COMP( 1984, plus4v,  c16,   0,  plus4v, plus4,  c16v,  "Commodore Business Machines Co.",  "Commodore Plus/4 (NTSC, VC1541)", 0)
715COMP( 1984, plus4,   c16,   0,  plus4,  plus4,  c16,   "Commodore Business Machines",  "Commodore Plus/4 (NTSC)", 0)
716COMP( 1984, plus4c,  c16,   0,  plus4c, plus4,  c16,   "Commodore Business Machines",  "Commodore Plus/4 (NTSC, 1551)", 0 )
717COMP( 1984, plus4v,  c16,   0,  plus4v, plus4,  c16,   "Commodore Business Machines",  "Commodore Plus/4 (NTSC, VC1541)", 0)
632718
633COMP( 1984, c232,    c16,   0,  c16,    c16,    c16,   "Commodore Business Machines Co.",  "Commodore 232 (Prototype)", 0)
634COMP( 1984, c264,    c16,   0,  c264,   plus4,  c16,   "Commodore Business Machines Co.",  "Commodore 264 (Prototype)", 0)
635COMP( 1984, c364,    c16,   0,  c364,   plus4,  c16,   "Commodore Business Machines Co.",  "Commodore V364 (Prototype)", GAME_IMPERFECT_SOUND)
719COMP( 1984, c232,    c16,   0,  c16,    c16,    c16,   "Commodore Business Machines",  "Commodore 232 (Prototype)", 0)
720COMP( 1984, c264,    c16,   0,  c264,   plus4,  c16,   "Commodore Business Machines",  "Commodore 264 (Prototype)", 0)
721COMP( 1984, c364,    c16,   0,  c364,   plus4,  c16,   "Commodore Business Machines",  "Commodore V364 (Prototype)", GAME_IMPERFECT_SOUND)
src/mess/drivers/c64.c
r7376r7377
962962
963963/*   YEAR  NAME   PARENT COMPAT MACHINE  INPUT    INIT     COMPANY                            FULLNAME */
964964
965COMP(1982, max,     0,    0,    ultimax, c64,     ultimax, "Commodore Business Machines Co.", "Commodore Max Machine", 0)
965COMP(1982, max,     0,    0,    ultimax, c64,     ultimax, "Commodore Business Machines", "Commodore Max Machine", 0)
966966
967COMP(1982, c64,     0,    0,    c64,     c64,     c64,     "Commodore Business Machines Co.", "Commodore 64 (NTSC)", 0)
968COMP(1982, c64pal,  c64,  0,    c64pal,  c64,     c64pal,  "Commodore Business Machines Co.", "Commodore 64 (PAL)",  0)
969COMP(1982, c64jpn,  c64,  0,    c64,     c64,     c64,     "Commodore Business Machines Co.", "Commodore 64 (Japan)", 0)
970COMP(1982, vic64s,  c64,  0,    c64pal,  vic64s,  c64pal,  "Commodore Business Machines Co.", "VIC 64S", 0)
971COMP(1982, c64swe,  c64,  0,    c64pal,  vic64s,  c64pal,  "Commodore Business Machines Co.", "Commodore 64 (Sweden/Finland)", 0)
967COMP(1982, c64,     0,    0,    c64,     c64,     c64,     "Commodore Business Machines", "Commodore 64 (NTSC)", 0)
968COMP(1982, c64pal,  c64,  0,    c64pal,  c64,     c64pal,  "Commodore Business Machines", "Commodore 64 (PAL)",  0)
969COMP(1982, c64jpn,  c64,  0,    c64,     c64,     c64,     "Commodore Business Machines", "Commodore 64 (Japan)", 0)
970COMP(1982, vic64s,  c64,  0,    c64pal,  vic64s,  c64pal,  "Commodore Business Machines", "VIC 64S", 0)
971COMP(1982, c64swe,  c64,  0,    c64pal,  vic64s,  c64pal,  "Commodore Business Machines", "Commodore 64 (Sweden/Finland)", 0)
972972
973COMP(1983, pet64,     c64,  0,    pet64,   c64,     c64,     "Commodore Business Machines Co.", "PET 64 (NTSC)", 0)
974COMP(1983, cbm4064, c64,  0,    pet64,   c64,     c64,     "Commodore Business Machines Co.", "CBM 4064 (NTSC)", 0)
975COMP(1983, edu64,   c64,  0,    pet64,   c64,     c64,     "Commodore Business Machines Co.", "Educator 64 (NTSC)", 0) // maybe different palette?
973COMP(1983, pet64,     c64,  0,    pet64,   c64,     c64,     "Commodore Business Machines", "PET 64 (NTSC)", 0)
974COMP(1983, cbm4064, c64,  0,    pet64,   c64,     c64,     "Commodore Business Machines", "CBM 4064 (NTSC)", 0)
975COMP(1983, edu64,   c64,  0,    pet64,   c64,     c64,     "Commodore Business Machines", "Educator 64 (NTSC)", 0) // maybe different palette?
976976
977COMP(1984, sx64,    c64,  0,    sx64,    c64,     sx64,    "Commodore Business Machines Co.", "SX-64 Executive Computer (PAL)", GAME_NOT_WORKING)
978COMP(1984, vip64,   c64,  0,    sx64,    vip64,   sx64,    "Commodore Business Machines Co.", "VIP64 (SX64 PAL), Swedish Expansion Kit", GAME_NOT_WORKING)
979COMP(198?, dx64,    c64,  0,    sx64,    c64,     sx64,    "Commodore Business Machines Co.", "DX-64 (Prototype, PAL)", GAME_NOT_WORKING)
977COMP(1984, sx64,    c64,  0,    sx64,    c64,     sx64,    "Commodore Business Machines", "SX-64 Executive Computer (PAL)", GAME_NOT_WORKING)
978COMP(1984, vip64,   c64,  0,    sx64,    vip64,   sx64,    "Commodore Business Machines", "VIP64 (SX64 PAL), Swedish Expansion Kit", GAME_NOT_WORKING)
979COMP(198?, dx64,    c64,  0,    sx64,    c64,     sx64,    "Commodore Business Machines", "DX-64 (Prototype, PAL)", GAME_NOT_WORKING)
980980
981COMP(1986, c64c,    c64,  0,    c64,     c64,     c64,     "Commodore Business Machines Co.", "Commodore 64C (NTSC)", 0)
982COMP(1986, c64cpal, c64,  0,    c64pal,  c64,     c64pal,  "Commodore Business Machines Co.", "Commodore 64C (PAL)", 0)
983COMP(1986, c64g,    c64,  0,    c64pal,  c64,     c64pal,  "Commodore Business Machines Co.", "Commodore 64G (PAL)", 0)
981COMP(1986, c64c,    c64,  0,    c64,     c64,     c64,     "Commodore Business Machines", "Commodore 64C (NTSC)", 0)
982COMP(1986, c64cpal, c64,  0,    c64pal,  c64,     c64pal,  "Commodore Business Machines", "Commodore 64C (PAL)", 0)
983COMP(1986, c64g,    c64,  0,    c64pal,  c64,     c64pal,  "Commodore Business Machines", "Commodore 64G (PAL)", 0)
984984
985CONS(1990, c64gs,   c64,  0,    c64gs,   c64gs,   c64gs,   "Commodore Business Machines Co.", "Commodore 64 Games System (PAL)", 0)
985CONS(1990, c64gs,   c64,  0,    c64gs,   c64gs,   c64gs,   "Commodore Business Machines", "Commodore 64 Games System (PAL)", 0)
986986
987987CONS(2005, c64dtv,  c64,  0,    c64,     c64,     c64,     "The Toy:Lobster Company", "Commodore 64 Direct-to-TV (Version 2 050711)", GAME_NOT_WORKING)
src/mess/drivers/clcd.c
r7376r7377
7373/* Driver */
7474
7575/*    YEAR  NAME    PARENT  COMPAT   MACHINE    INPUT    INIT    COMPANY   FULLNAME       FLAGS */
76COMP( 1985, clcd,  0,       0,   clcd,   clcd,    0,          "Commodore",   "LCD (Prototype)",      GAME_NOT_WORKING | GAME_NO_SOUND )
76COMP( 1985, clcd,  0,       0,   clcd,   clcd,    0,          "Commodore Business Machines",   "LCD (Prototype)",      GAME_NOT_WORKING | GAME_NO_SOUND )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team