Previous 15994 Revisions Next

r1079 Saturday 6th October, 2007 at 17:54:09 UTC by Firewave
removed obsolete files
[src/emu/cpu/tms9900]9900stat.h
[src/mame/includes]srmp6.h
[src/mame/video]srmp6.c

src/mame/includes/srmp6.h
r1078r1079
1
2
3
4/* vidhrdw/srmp6.c */
5
6extern UINT16 *sprite_ram;   // Sprite RAM 0x400000-0x47dfff
7extern UINT16 *dec_regs;   //Graphic decode register
8
9extern UINT16 *video_regs;
10extern gfx_layout srmp6_layout_8x8;
11
12READ16_HANDLER( video_regs_r );
13WRITE16_HANDLER( video_regs_w );
14
15WRITE16_HANDLER( gfx_decode_w );
16
17READ16_HANDLER( srmp6_sprite_r );
18WRITE16_HANDLER( srmp6_sprite_w );
19
20VIDEO_START(srmp6);
21VIDEO_UPDATE(srmp6);
src/mame/video/srmp6.c
r1078r1079
1/*
2    Super Real Mahjong P6 (JPN Ver.)
3    (c)1996 Seta
4
5WIP driver by Sebastien Volpe
6
7according prg ROM (offset $0fff80):
8
9    S12 SYSTEM
10    SUPER REAL MAJAN P6
11    SETA CO.,LTD
12    19960410
13    V1.00
14
15TODO:
16 - gfx decoding / emulation
17 - sound emulation (appears to be really close to st0016)
18
19Are there other games on this 'System S12' hardware ???
20
21---------------- dump infos ----------------
22
23[Jun/15/2000]
24
25Super Real Mahjong P6 (JPN Ver.)
26(c)1996 Seta
27
28SX011
29E47-REV01B
30
31CPU:    68000-16
32Sound:  NiLe
33OSC:    16.0000MHz
34        42.9545MHz
35        56.0000MHz
36
37Chips:  ST-0026 NiLe (video, sound)
38        ST-0017
39
40
41SX011-01.22  chr, samples (?)
42SX011-02.21
43SX011-03.20
44SX011-04.19
45SX011-05.18
46SX011-06.17
47SX011-07.16
48SX011-08.15
49
50SX011-09.10  68000 data
51
52SX011-10.4   68000 prg.
53SX011-11.5
54
55
56Dumped 06/15/2000
57*/
58
59#include "driver.h"
60#include "srmp6.h"
61
62/***************************************************************************
63    vidhrdw - VERY preliminary
64***************************************************************************/
65
66/* sprite RAM format: 8 words, 1st word = 0x8000 means end of list
67
68Offset:         Format:                     Value:
69
700000.w
71                    f--- ---- ---- ----     End of list
72                    -??? ???? ???? ???-
73                    ---- ---- ---- ---0     Sprite visible?
74
750002.w                                      Code
760004.w                                      X Position
770006.w                                      Y Position
78
790008.w                                      attributes/color?
80000a.w                                      attributes/color?
81
82000c.l                                      used ?
83
84cpu #0 (PC=00011B2A): unmapped program memory word write to 00400490 = 0001 & FFFF - sprite visible ?
85cpu #0 (PC=00011B2E): unmapped program memory word write to 00400492 = 0233 & FFFF - code
86cpu #0 (PC=00011B32): unmapped program memory word write to 00400494 = 00D8 & FFFF - x
87cpu #0 (PC=00011B36): unmapped program memory word write to 00400496 = 0080 & FFFF - y
88cpu #0 (PC=00011B3A): unmapped program memory word write to 00400498 = E000 & FFFF - attributes/color?
89cpu #0 (PC=00011B3E): unmapped program memory word write to 0040049A = 0000 & FFFF - attributes/color?
90cpu #0 (PC=00011B40): unmapped program memory word write to 0040049C = 0000 & FFFF -\
91cpu #0 (PC=00011B40): unmapped program memory word write to 0040049E = 0000 & FFFF -/ used ?
92
93cpu #0 (PC=00011B4E): unmapped program memory word write to 004004B0 = 8000 & FFFF - end of list
94*/
95
96/* tile RAM format: where's color ?
97
98cpu #0 (PC=000118E8): unmapped program memory word write to 00412002 = 0005 & FFFF - kind of init, interleaved with 'meaningful' words
99cpu #0 (PC=000118EE): unmapped program memory word write to 00412008 = 0000 & FFFF
100cpu #0 (PC=000118F4): unmapped program memory word write to 0041200A = 0000 & FFFF
101...
102cpu #0 (PC=000118E8): unmapped program memory word write to 00416EB2 = 0005 & FFFF
103cpu #0 (PC=000118EE): unmapped program memory word write to 00416EB8 = 0000 & FFFF
104cpu #0 (PC=000118F4): unmapped program memory word write to 00416EBA = 0000 & FFFF
105
106
107cpu #0 (PC=0001170A): unmapped program memory word write to 00412000 = 4004 & FFFF
108cpu #0 (PC=00011712): unmapped program memory word write to 00412004 = 0000 & FFFF
109cpu #0 (PC=0001171A): unmapped program memory word write to 00412006 = 0000 & FFFF
110...
111cpu #0 (PC=0001170A): unmapped program memory word write to 004133A0 = 4004 & FFFF - tile code [*]
112cpu #0 (PC=00011712): unmapped program memory word write to 004133A4 = 0140 & FFFF - x (00..140, step 16d) -> res = 320d
113cpu #0 (PC=0001171A): unmapped program memory word write to 004133A6 = 00E0 & FFFF - y (00..F0, step 16d)  -> res = 240d
114
115[*] tile code is 'incremented by 4', suggesting there are 4 8x8 tiles arranged to make a 16x16 one ???
116*/
117
118UINT16 *sprite_ram; // Sprite RAM 0x400000-0x47dfff
119UINT16 *sprite_ram_old; // Sprite RAM(previous frame)
120UINT16 *dec_regs;   //graphics decode register
121UINT16 *video_regs, *sound_regs;
122
123int brightness;       //fade in/out
124
125/***************************************************************************
126    Graphics definitions
127***************************************************************************/
128
129gfx_layout srmp6_layout_8x8 =
130{
131    8,8,
132    0x8000 / 4,
133    8,
134    { STEP8(0,1)},
135    { STEP8(0,8)},
136    { STEP8(0,8*8)},
137    8*8*8
138};
139
140//fade in/out
141void update_palette(void)
142{
143   char r, g ,b;
144   int brg = brightness - 0x60;
145   int i;
146
147   for(i = 0; i < 0x800; i++)
148   {
149      r = paletteram16[i] >>  0 & 0x1F;
150      g = paletteram16[i] >>  5 & 0x1F;
151      b = paletteram16[i] >> 10 & 0x1F;
152
153      if(brg < 0) {
154         r += (r * brg) >> 5;
155         if(r < 0) r = 0;
156         g += (g * brg) >> 5;
157         if(g < 0) g = 0;
158         b += (b * brg) >> 5;
159         if(b < 0) b = 0;
160      }
161      else if(brg > 0) {
162         r += ((0x1F - r) * brg) >> 5;
163         if(r > 0x1F) r = 0x1F;
164         g += ((0x1F - g) * brg) >> 5;
165         if(g > 0x1F) g = 0x1F;
166         b += ((0x1F - b) * brg) >> 5;
167         if(b > 0x1F) b = 0x1F;
168      }
169      palette_set_color(Machine, i, MAKE_RGB(r << 3, g << 3, b << 3));
170   }
171}
172
173VIDEO_START(srmp6)
174{
175   int i;
176
177   sprite_ram_old = auto_malloc(0x7E000);
178   memset(sprite_ram_old, 0x00, 0x7E000);
179
180   brightness = 0x60;
181
182   for(i=0;i<4;i++)
183   {
184      if(Machine->gfx[i])
185         freegfx(Machine->gfx[i]);
186      Machine->gfx[i] = allocgfx(&srmp6_layout_8x8);
187      if (!Machine->gfx[i])
188         return;
189      decodegfx(Machine->gfx[i], memory_region(REGION_GFX1) + (i << 19), 0, Machine->gfx[i]->total_elements);
190      Machine->gfx[i]->color_base = 0;
191      Machine->gfx[i]->total_colors = 0x800;
192   }
193}
194
195VIDEO_UPDATE(srmp6)
196{
197   int trans = TRANSPARENCY_PEN;
198   UINT16 *sprite_list = sprite_ram_old;
199   UINT16 *finish = sprite_list+0x1000;
200
201   fillbitmap(bitmap, get_black_pen(machine), cliprect);
202
203   // parse sprite list
204   while( sprite_list < finish && sprite_list[0] != 0x8000)
205   {
206      UINT16 *char_list = sprite_ram_old + sprite_list[1] * 0x8;
207      short char_count = sprite_list[0];
208      short xpos = sprite_list[2];
209      short ypos = sprite_list[3];
210      int color = sprite_list[4]&0x07;
211
212      if((sprite_list[5] & 0x700) == 0x700)
213      {
214         trans = TRANSPARENCY_ALPHA;
215         alpha_set_level((sprite_list[5] & 0x1F) << 3);
216      }
217      else
218      {
219         trans = TRANSPARENCY_PEN;
220         alpha_set_level(255);
221      }
222
223      while(char_count > 0)
224      {
225         int char_code, size_x, size_y, ax, ay;
226         int x_offset, y_offset, flipx, flipy;
227
228         char_code =  char_list[0];
229         size_x = 1 << (char_list[1] & 0x03);
230         size_y = 1 << (char_list[1] >> 2 & 0x03);
231         flipx = (char_list[1] >> 8) & 1;
232         flipy = (char_list[1] >> 9) & 1;
233
234         x_offset = char_list[2];
235         y_offset = char_list[3]-size_y*8;
236         for(ax=0;ax<size_x;ax++) {
237            for(ay=0;ay<size_y;ay++) {
238               int bx,by;
239
240               if(!flipx)
241                  bx = xpos + ax*8 + x_offset;
242               else
243                  bx = xpos + (size_x-ax-1)*8 + x_offset;
244               if(!flipy)
245                  by = ypos + ay*8 + y_offset;
246               else
247                  by = ypos + (size_y-ay-1)*8 + y_offset;
248
249               drawgfx(
250                  bitmap,
251                  Machine->gfx[char_code >> 13],
252                  char_code & 0x1fff,
253                  color,
254                  flipx,flipy,
255                  bx,by,
256                  cliprect,
257                  trans,0
258               );
259               char_code++;
260            }
261         }
262         char_list += 8;
263         char_count--;
264      }
265      sprite_list += 0x8;
266   }
267
268   memcpy(sprite_ram_old, sprite_ram, 0x7E000);
269   return 0;
270}
271
272WRITE16_HANDLER( video_regs_w )
273{
274   switch(offset)
275   {
276      case 0x5e/2: // bank switch, used by ROM check
277         logerror("Bankswitch %02X\n", data&0x0f);
278         memory_set_bankptr(1,(UINT16 *)(memory_region(REGION_USER2) + (data & 0x0f)*0x200000));
279         break;
280
281
282      // set by IT4
283      case 0x5c/2: // either 0x40 explicitely in many places, or according $2083b0 (IT4)
284         //fade in/out (0x40(dark)-0x60(normal)-0x7e?(bright) reset by 0x00?
285         data = (!data)?0x60:(data == 0x5e)?0x60:data;
286         if(brightness != data) {
287            brightness = data;
288            update_palette();
289         }
290         break;
291      /* unknown registers - there are others */
292
293      // set by IT4 (jsr $b3c), according flip screen dsw
294      case 0x48/2: //     0 /  0xb0 if flipscreen
295      case 0x52/2: //     0 / 0x2ef if flipscreen
296      case 0x54/2: // 0x152 / 0x15e if flipscreen
297
298      // set by IT4 ($82e-$846)
299      case 0x56/2: // written 8,9,8,9 successively
300         break;
301      case 0x5a/2:
302         // graphics decode register write enable/disable flag?
303         /* disable by 0x00, enable by 0x01 */
304         /* the game program writes 0x02 to 0x4c000c */
305         /* to disable register write while decoding*/
306         /* currently it's meaningless as we decode frame by frame */
307         video_regs[0x0c/2] = data <<1;
308         break;
309      default:
310//          logerror("video_regs_w (PC=%06X): %04x = %04x & %04x\n", activecpu_get_previouspc(), offset*2, data, mem_mask);
311         break;
312   }
313   COMBINE_DATA(&video_regs[offset]);
314}
315
316READ16_HANDLER( video_regs_r )
317{
318   return video_regs[offset];
319}
320
321//decode the graphic data
322void decode_gfx( UINT32 table_address, UINT32 data_address, UINT32 gfx_size, UINT32 mem_offset)
323{
324   UINT8  *src   = memory_region(REGION_USER3) , *dst = memory_region(REGION_GFX1) + mem_offset;
325   UINT16 *table = (UINT16 *)(src + table_address);
326   UINT8  *data  = src + data_address;
327   UINT8  *end   = dst + gfx_size;
328
329   UINT8 loop_count, block_size, block_count, block[0x10];
330   UINT32 pal, prev_pal=~0, table_flag, pal_flag=0;
331
332   while(1)
333   {
334      block_size=0;
335
336      table_flag = *(data++) | 0x100;
337      while(!(table_flag & 0x10000)) {
338         if(table_flag & 0x80) {
339            *((UINT16 *)&block[block_size]) = table[*(data++)];
340            block_size+=2;
341         }
342         else {
343            block[block_size++]= *(data++);
344         }
345         table_flag<<=1;
346      }
347
348      block_count = 0;
349      while(block_count != block_size) {
350         pal = block[block_count++];
351         if(pal_flag) {
352            loop_count = pal + 1;
353            pal = prev_pal;
354            while(loop_count) {
355               *(dst++) = pal; loop_count--;
356               if(dst == end) return;
357            }
358            pal_flag = 0;
359         }
360         else {
361            *(dst++) = pal;
362            if(dst == end) return;
363            if(pal == prev_pal) {
364               if(block_count < block_size) {
365                  loop_count = block[block_count++] + 1;
366                  while(loop_count) {
367                     *(dst++) = pal; loop_count--;
368                     if(dst == end) return;
369                  }
370               }
371               else
372                  pal_flag=1;
373            }
374            prev_pal = pal;
375         }
376      }
377   }
378}
379
380WRITE16_HANDLER( gfx_decode_w )
381{
382   int i;
383   int table_address, table_size, data_address, gfx_size, page_index;
384   COMBINE_DATA(&dec_regs[offset]);
385
386   // check if write protection of graphic decode memory is disabled
387   if(offset == 0x0d && video_regs[0x5a/2] == 0x0001) {
388      table_size    = dec_regs[0] + 1;
389      table_address = ((dec_regs[5] << 16) | dec_regs[4]) << 1;
390      gfx_size      = (((dec_regs[7] & 3) << 16) | (dec_regs[6]+1)) << 2;
391      page_index    = dec_regs[9] >> 1;
392      data_address  = ((dec_regs[11] << 16) | dec_regs[10]) << 1;
393
394      if(( table_address >= 0xc00000 && table_address < 0x2000000) &&
395         ( data_address  >= 0xc00000 && data_address  < 0x2000000) &&
396         ( table_size    >  0x000000 && table_size    < 0x81))
397      {
398/*
399            logerror("number of word table?@?@?@?@?@?@%08X\n",   table_size);
400            logerror("word table address?@?@?@%08X\n",   table_address);
401            logerror("decode data size?@?@?@?@%08X\n",   gfx_size);
402            logerror("decode page index?@%08X\n",   page_index);
403            logerror("decode data address?@?@?@%08X\n\n", data_address);
404*/
405         decode_gfx( table_address - 0xc00000, data_address - 0xc00000, gfx_size, page_index << 19);
406
407         for(i=0; gfx_size >= 0; gfx_size -= 0x80000, i++)
408         {
409            freegfx(Machine->gfx[page_index+i]);
410            Machine->gfx[page_index+i] = allocgfx(&srmp6_layout_8x8);
411            if (!Machine->gfx[page_index+i])
412               return;
413            decodegfx(Machine->gfx[page_index+i], memory_region(REGION_GFX1) + ((page_index+i) << 19), 0, Machine->gfx[page_index+i]->total_elements);
414            Machine->gfx[page_index+i]->color_base = 0;
415            Machine->gfx[page_index+i]->total_colors = 0x800;
416         }
417      }
418   }
419}
420
421READ16_HANDLER( srmp6_sprite_r )
422{
423   return sprite_ram[offset];
424}
425
426WRITE16_HANDLER( srmp6_sprite_w )
427{
428   COMBINE_DATA(&sprite_ram[offset]);
429}
430
431WRITE16_HANDLER(paletteram_w)
432{
433   char r, g, b;
434   int brg = brightness - 0x60;
435
436   paletteram16_xBBBBBGGGGGRRRRR_word_w(offset, data, mem_mask);
437
438   if(brg)
439   {
440      r = data >>  0 & 0x1F;
441      g = data >>  5 & 0x1F;
442      b = data >> 10 & 0x1F;
443
444      if(brg < 0) {
445         r += (r * brg) >> 5;
446         if(r < 0) r = 0;
447         g += (g * brg) >> 5;
448         if(g < 0) g = 0;
449         b += (b * brg) >> 5;
450         if(b < 0) b = 0;
451      }
452      else if(brg > 0) {
453         r += ((0x1F - r) * brg) >> 5;
454         if(r > 0x1F) r = 0x1F;
455         g += ((0x1F - g) * brg) >> 5;
456         if(g > 0x1F) g = 0x1F;
457         b += ((0x1F - b) * brg) >> 5;
458         if(b > 0x1F) b = 0x1F;
459      }
460
461      palette_set_color(Machine, offset, MAKE_RGB(r << 3, g << 3, b << 3));
462   }
463}
464
src/emu/cpu/tms9900/9900stat.h
r1078r1079
1/************************************************************************
2
3    ST register functions
4
5************************************************************************/
6
7/*
8    remember that P bit is maintained in lastparity
9*/
10
11/*
12    setstat sets the ST_P bit according to lastparity
13
14    It must be called before reading the ST register.
15*/
16
17void setstat(void)
18{
19   int i;
20   UINT8 a;
21
22   I.STATUS &= ~ ST_P;
23
24   /* We set the parity bit. */
25   a = lastparity;
26
27   for (i=0; i<8; i++)   /* 8 bits to test */
28   {
29      if (a & 1)  /* If current bit is set */
30         I.STATUS ^= ST_P; /* we change ST_P bit */
31
32      a >>= 1;    /* Next bit. */
33   }
34}
35
36/*
37    getstat sets emulator's lastparity variable according to 9900's STATUS bits.
38    It must be called on interrupt return, or when, for some reason,
39    the emulated program sets the STATUS register directly.
40*/
41void getstat(void)
42{
43   if (I.STATUS & ST_P)
44      lastparity = 1;
45   else
46      lastparity = 0;
47}
48
49/*
50    A few words about the following functions.
51
52    A big portability issue is the behavior of the ">>" instruction with the sign bit, which has
53    not been normalised.  Every compiler does whatever it thinks smartest.
54    My code assumed that when shifting right signed numbers, the operand is left-filled with a
55    copy of sign bit, and that when shifting unsigned variables, it is left-filled with 0s.
56    This is probably the most logical behaviour, and it is the behavior of CW PRO3 - most time
57    (the exception is that ">>=" instructions always copy the sign bit (!)).  But some compilers
58    are bound to disagree.
59
60    So, I had to create special functions with predefined tables included, so that this code work
61    on every compiler.  BUT this is a real slow-down.
62    So, you might have to include a few lines in assembly to make this work better.
63    Sorry about this, this problem is really unpleasant and absurd, but it is not my fault.
64*/
65
66
67static const UINT16 right_shift_mask_table[17] =
68{
69   0xFFFF,
70   0x7FFF,
71   0x3FFF,
72   0x1FFF,
73   0x0FFF,
74   0x07FF,
75   0x03FF,
76   0x01FF,
77   0x00FF,
78   0x007F,
79   0x003F,
80   0x001F,
81   0x000F,
82   0x0007,
83   0x0003,
84   0x0001,
85   0x0000
86};
87
88static const UINT16 inverted_right_shift_mask_table[17] =
89{
90   0x0000,
91   0x8000,
92   0xC000,
93   0xE000,
94   0xF000,
95   0xF800,
96   0xFC00,
97   0xFE00,
98   0xFF00,
99   0xFF80,
100   0xFFC0,
101   0xFFE0,
102   0xFFF0,
103   0xFFF8,
104   0xFFFC,
105   0xFFFE,
106   0xFFFF
107};
108
109INLINE UINT16 logical_right_shift(UINT16 val, int c)
110{
111   return((val>>c) & right_shift_mask_table[c]);
112}
113
114INLINE INT16 arithmetic_right_shift(INT16 val, int c)
115{
116   if (val < 0)
117      return((val>>c) | inverted_right_shift_mask_table[c]);
118   else
119      return((val>>c) & right_shift_mask_table[c]);
120}
121
122
123
124
125
126/*
127    Set lae
128*/
129INLINE void setst_lae(INT16 val)
130{
131   I.STATUS &= ~ (ST_L | ST_A | ST_E);
132
133   if (val > 0)
134      I.STATUS |= (ST_L | ST_A);
135   else if (val < 0)
136      I.STATUS |= ST_L;
137   else
138      I.STATUS |= ST_E;
139}
140
141
142/*
143    Set laep (BYTE)
144*/
145INLINE void setst_byte_laep(INT8 val)
146{
147   I.STATUS &= ~ (ST_L | ST_A | ST_E);
148
149   if (val > 0)
150      I.STATUS |= (ST_L | ST_A);
151   else if (val < 0)
152      I.STATUS |= ST_L;
153   else
154      I.STATUS |= ST_E;
155
156   lastparity = val;
157}
158
159/*
160    For COC, CZC, and TB
161*/
162INLINE void setst_e(UINT16 val, UINT16 to)
163{
164   if (val == to)
165      I.STATUS |= ST_E;
166   else
167      I.STATUS &= ~ ST_E;
168}
169
170/*
171    For CI, C, CB
172*/
173INLINE void setst_c_lae(UINT16 to, UINT16 val)
174{
175   I.STATUS &= ~ (ST_L | ST_A | ST_E);
176
177   if (val == to)
178      I.STATUS |= ST_E;
179   else
180   {
181      if ( ((INT16) val) > ((INT16) to) )
182         I.STATUS |= ST_A;
183      if ( ((UINT16) val) > ((UINT16) to) )
184      I.STATUS |= ST_L;
185   }
186}
187
188#define wadd(addr,expr) { int lval = setst_add_laeco(readword(addr), (expr)); writeword((addr),lval); }
189#define wsub(addr,expr) { int lval = setst_sub_laeco(readword(addr), (expr)); writeword((addr),lval); }
190
191/*
192    Set laeco for add
193*/
194INLINE INT16 setst_add_laeco(int a, int b)
195{
196   UINT32 res;
197   INT16 res2;
198
199   I.STATUS &= ~ (ST_L | ST_A | ST_E | ST_C | ST_O);
200
201   res = (a & 0xffff) + (b & 0xffff);
202
203   if (res & 0x10000)
204      I.STATUS |= ST_C;
205
206   if ((res ^ b) & (res ^ a) & 0x8000)
207      I.STATUS |= ST_O;
208
209   res2 = (INT16) res;
210
211   if (res2 > 0)
212      I.STATUS |= ST_L | ST_A;
213   else if (res2 < 0)
214      I.STATUS |= ST_L;
215   else
216      I.STATUS |= ST_E;
217
218   return res2;
219}
220
221
222/*
223    Set laeco for subtract
224*/
225INLINE INT16 setst_sub_laeco(int a, int b)
226{
227   UINT32 res;
228   INT16 res2;
229
230   I.STATUS &= ~ (ST_L | ST_A | ST_E | ST_C | ST_O);
231
232   res = (a & 0xffff) - (b & 0xffff);
233
234   if (! (res & 0x10000))
235      I.STATUS |= ST_C;
236
237   if ((a ^ b) & (a ^ res) & 0x8000)
238      I.STATUS |= ST_O;
239
240   res2 = (INT16) res;
241
242   if (res2 > 0)
243      I.STATUS |= ST_L | ST_A;
244   else if (res2 < 0)
245      I.STATUS |= ST_L;
246   else
247      I.STATUS |= ST_E;
248
249   return res2;
250}
251
252
253/*
254    Set laecop for add (BYTE)
255*/
256INLINE INT8 setst_addbyte_laecop(int a, int b)
257{
258   unsigned int res;
259   INT8 res2;
260
261   I.STATUS &= ~ (ST_L | ST_A | ST_E | ST_C | ST_O | ST_P);
262
263   res = (a & 0xff) + (b & 0xff);
264
265   if (res & 0x100)
266      I.STATUS |= ST_C;
267   if ((res ^ b) & (res ^ a) & 0x80)
268      I.STATUS |= ST_O;
269
270   res2 = (INT8) res;
271
272   if (res2 > 0)
273      I.STATUS |= ST_L | ST_A;
274   else if (res2 < 0)
275      I.STATUS |= ST_L;
276   else
277      I.STATUS |= ST_E;
278
279   lastparity = res2;
280
281   return res2;
282}
283
284
285/*
286    Set laecop for subtract (BYTE)
287*/
288INLINE INT8 setst_subbyte_laecop(int a, int b)
289{
290   unsigned int res;
291   INT8 res2;
292
293   I.STATUS &= ~ (ST_L | ST_A | ST_E | ST_C | ST_O | ST_P);
294
295   res = (a & 0xff) - (b & 0xff);
296
297   if (! (res & 0x100))
298      I.STATUS |= ST_C;
299   if ((a ^ b) & (a ^ res) & 0x80)
300      I.STATUS |= ST_O;
301
302   res2 = (INT8) res;
303
304   if (res2 > 0)
305      I.STATUS |= ST_L | ST_A;
306   else if (res2 < 0)
307      I.STATUS |= ST_L;
308   else
309      I.STATUS |= ST_E;
310
311   lastparity = res2;
312
313   return res2;
314}
315
316
317
318/*
319    For NEG
320*/
321INLINE void setst_laeo(INT16 val)
322{
323   I.STATUS &= ~ (ST_L | ST_A | ST_E | ST_O);
324
325   if (val > 0)
326      I.STATUS |= ST_L | ST_A;
327   else if (val < 0)
328   {
329   I.STATUS |= ST_L;
330   if (((UINT16) val) == 0x8000)
331      I.STATUS |= ST_O;
332   }
333   else
334      I.STATUS |= ST_E;
335}
336
337
338
339/*
340    Meat of SRA
341*/
342INLINE UINT16 setst_sra_laec(INT16 a, UINT16 c)
343{
344   I.STATUS &= ~ (ST_L | ST_A | ST_E | ST_C);
345
346   if (c != 0)
347   {
348      a = arithmetic_right_shift(a, c-1);
349      if (a & 1)  // The carry bit equals the last bit that is shifted out
350         I.STATUS |= ST_C;
351      a = arithmetic_right_shift(a, 1);
352   }
353
354   if (a > 0)
355      I.STATUS |= ST_L | ST_A;
356   else if (a < 0)
357      I.STATUS |= ST_L;
358   else
359      I.STATUS |= ST_E;
360
361   return a;
362}
363
364
365/*
366    Meat of SRL.  Same algorithm as SRA, except that we fills in with 0s.
367*/
368INLINE UINT16 setst_srl_laec(UINT16 a,UINT16 c)
369{
370   I.STATUS &= ~ (ST_L | ST_A | ST_E | ST_C);
371
372   if (c != 0)
373   {
374      a = logical_right_shift(a, c-1);
375      if (a & 1)
376         I.STATUS |= ST_C;
377      a = logical_right_shift(a, 1);
378   }
379
380   if (((INT16) a) > 0)
381      I.STATUS |= ST_L | ST_A;
382   else if (((INT16) a) < 0)
383      I.STATUS |= ST_L;
384   else
385      I.STATUS |= ST_E;
386
387   return a;
388}
389
390
391//
392// Meat of SRC
393//
394INLINE UINT16 setst_src_laec(UINT16 a,UINT16 c)
395{
396   I.STATUS &= ~ (ST_L | ST_A | ST_E | ST_C);
397
398   if (c != 0)
399   {
400      a = logical_right_shift(a, c) | (a << (16-c));
401      if (a & 0x8000) // The carry bit equals the last bit that is shifted out
402         I.STATUS |= ST_C;
403   }
404
405   if (((INT16) a) > 0)
406      I.STATUS |= ST_L | ST_A;
407   else if (((INT16) a) < 0)
408      I.STATUS |= ST_L;
409   else
410      I.STATUS |= ST_E;
411
412   return a;
413}
414
415
416//
417// Meat of SLA
418//
419INLINE UINT16 setst_sla_laeco(UINT16 a, UINT16 c)
420{
421   I.STATUS &= ~ (ST_L | ST_A | ST_E | ST_C | ST_O);
422
423   if (c != 0)
424   {
425      {
426         register UINT16 mask;
427         register UINT16 ousted_bits;
428
429         mask = 0xFFFF << (16-c-1);
430         ousted_bits = a & mask;
431
432         if (ousted_bits)        // If ousted_bits is neither all 0s
433            if (ousted_bits ^ mask)   // nor all 1s,
434               I.STATUS |= ST_O;   // we set overflow
435      }
436
437      a <<= c-1;
438      if (a & 0x8000) // The carry bit equals the last bit that is shifted out
439         I.STATUS |= ST_C;
440
441      a <<= 1;
442   }
443
444   if (((INT16) a) > 0)
445      I.STATUS |= ST_L | ST_A;
446   else if (((INT16) a) < 0)
447      I.STATUS |= ST_L;
448   else
449      I.STATUS |= ST_E;
450
451   return a;
452}
453
454
455/***********************************************************************/
456

Previous 15994 Revisions Next


© 1998-2018 The MESS Team