]> Shamusworld >> Repos - virtualjaguar/blob - src/objectp.cpp
ee2418c976fec9c50f158b12a282e677ca35e39b
[virtualjaguar] / src / objectp.cpp
1
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include "jaguar.h"
6
7
8 //#define OP_DEBUG
9 //#define OP_DEBUG_BMP
10 static int cnt = 0;
11 extern uint32 jaguar_mainRom_crc32;
12
13 static uint8 * op_blend_y;
14 static uint8 * op_blend_cc;
15
16 #define BLEND_Y(dst,src) op_blend_y[(((uint16)dst)<<8) | ((uint16)(src))]
17 #define BLEND_CC(dst,src) op_blend_cc[(((uint16)dst)<<8) | ((uint16)(src))]
18
19
20 static uint8 objectp_ram[0x40];
21 uint8 objectp_running;
22
23 uint8 objectp_stop_reading_list;
24
25 #define OBJECT_TYPE_BITMAP      0
26 #define OBJECT_TYPE_SCALE       1
27 #define OBJECT_TYPE_GPU         2
28 #define OBJECT_TYPE_BRANCH      3
29 #define OBJECT_TYPE_STOP        4
30
31 #define CONDITION_EQUAL                 0
32 #define CONDITION_LESS_THAN             1
33 #define CONDITION_GREATER_THAN  2
34 #define CONDITION_OP_FLAG_SET   3
35 #define CONDITION_SECOND_HALF_LINE      4
36
37 #define FLAGS_RELEASE           8
38 #define FLAGS_TRANSPARENT       4
39 #define FLAGS_READMODIFY        2
40 #define FLAGS_HFLIP                     1
41
42
43 static char * condition_to_str[8] = {"==","<",">","(opflag set)","(second half line)","?","?","?"};
44
45 static uint8 op_bitmap_bit_depth[8]={1,           2,          4,         8,       16,      24,      32,      0      };
46 static uint32 op_bitmap_bit_size[8]={0.125*65536, 0.25*65536, 0.5*65536, 1*65536, 2*65536, 1*65536, 1*65536, 1*65536};
47 static uint32 op_pointer;
48 static int cnt_bitmap = 0;
49
50 //////////////////////////////////////////////////////////////////////////////
51 //
52 //////////////////////////////////////////////////////////////////////////////
53 //
54 //
55 //
56 //////////////////////////////////////////////////////////////////////////////
57 void op_process_bitmap(int16 *backbuffer, int scanline, uint64 p0, uint64 p1, int render)
58 {
59         uint8   bitdepth=(p1>>12)&0x07;
60         
61         int16   ypos=(((p0>>3)&0x3ff)/2);
62         int32   xpos=(((int32)((p1<<20)&0xffffffff))>>20)-tom_getHBlankWidthInPixels();
63         int32   iwidth=((p1>>28)&0x3ff)*4;
64         uint32  dwidth=((p1>>18)&0x3ff)*4;
65         int16   height=((p0>>14)&0x3ff)-1;
66         uint32  link=((p0>>24)&0x7ffff)<<3;
67         uint32  ptr=(((p0>>43)&0x1fffff)<<3);
68         uint32  firstPix=(p1>>49)&0x3f;
69         uint8   flags=(p1>>45)&0x0f;
70         uint8   idx=(p1>>38)&0x7f;
71         uint32  pitch=(p1>>15)&0x07;
72         int16   scanline_width=tom_getVideoModeWidth();
73         uint8   *tom_ram_8=tom_get_ram_pointer();
74         uint8   *current_line_buffer=&tom_ram_8[0x1800];
75         uint8   *paletteRam=&tom_ram_8[0x400];
76         uint8    doom_hack=0;
77
78         op_pointer=link;
79
80         if ((!render)||(op_pointer==0)||(height<0)||(dwidth<0)||(ptr==0)||(pitch==0))
81         {
82                 return;
83         }
84         if (iwidth==0)
85         {
86                 dwidth=iwidth=height;
87         }
88         if (jaguar_mainRom_crc32==0x5e705756) // doom
89         {
90                 if ((iwidth==160)&&(height==179)&&(xpos==-9)&&(ypos==24))
91                 {
92                         doom_hack=1;
93                         xpos=0;
94                 }
95         }
96         // il y a un offset vertical de 20 pour un des bitmaps
97         // dans dinon olympics pour une raison encore inconnue
98         if (jaguar_mainRom_crc32==0x3c7bfda8)
99         {
100                 if ((iwidth==220)&&(height==184)&&(ypos==0))
101                 {
102                         ypos=20;
103                 }
104         }
105         else
106         if (jaguar_mainRom_crc32==0x2f032271)
107         {
108                 ypos+=8;
109         }
110         if (op_bitmap_bit_depth[bitdepth]==24)
111         {
112                 iwidth*=2;
113                 dwidth*=2;
114         }
115         if (op_bitmap_bit_depth[bitdepth]==8)
116         {
117                 iwidth*=2;
118                 dwidth*=2;
119         }
120         if (op_bitmap_bit_depth[bitdepth]==4)
121         {
122                 iwidth*=2;
123                 dwidth*=2;
124         }
125         if (op_bitmap_bit_depth[bitdepth]==2)
126         {
127                 iwidth*=2;
128                 dwidth*=2;
129         }
130         if (op_bitmap_bit_depth[bitdepth]==1)
131         {
132                 iwidth*=2;
133                 dwidth*=2;
134         }
135         // Power Drive Rally (fixed size bitmaps have a 240 lines vertical offset)
136         // but could well be a modulo 240
137         if (jaguar_mainRom_crc32==0x0ab88d90)
138                 ypos%=240;
139
140
141 #ifdef OP_DEBUG_BMP
142         fprintf(log_get(),"bitmap %ix%i %ibpp at %i,%i firstpix=%i ptr=0x%.8x pitch %i hflipped=%s dwidth=%i (linked to 0x%.8x) Transluency=%s\n",iwidth,height,op_bitmap_bit_depth[bitdepth],xpos,ypos,firstPix,ptr,pitch,flags&FLAGS_HFLIP?"yes":"no",dwidth,op_pointer,(flags&FLAGS_READMODIFY)?"yes":"no");
143 #endif
144
145         if ((scanline<ypos)||(scanline>(ypos+height)))
146         {
147                 return;
148         }
149         // seek to the good bitmap scanline
150         // not sure for palettized modes
151         if (op_bitmap_bit_depth[bitdepth] > 8)
152         {
153                 ptr += ((dwidth * op_bitmap_bit_size[bitdepth]) >> 16) * (scanline - ypos);
154         }
155         else
156                 ptr += dwidth * (scanline - ypos);
157
158         if (xpos < 0)
159         {
160                 iwidth += xpos;
161                 ptr += (pitch * op_bitmap_bit_size[bitdepth] * (-xpos)) >> 16;
162                 xpos = 0;
163         }
164
165         if (iwidth <= 0)
166         {
167 #ifdef OP_DEBUG 
168         fprintf(log_get(),"not rendering because iwidth<0\n");
169 #endif
170                 return;
171         }
172         
173         if (flags&FLAGS_HFLIP)
174         {
175                 if ((xpos<0)||((xpos-iwidth)>=scanline_width))
176                         return;
177
178                 if ((xpos-iwidth)<0)
179                         iwidth=xpos;
180         }
181         else
182         {
183                 if (((xpos+iwidth)<0)||(xpos>=scanline_width))
184                         return;
185
186                 if ((xpos+iwidth)>scanline_width)
187                         iwidth=scanline_width-xpos;
188         }
189
190
191         current_line_buffer+=(xpos*2); // 2 in 16 bpp modes (need to take the mode into account)
192
193         // doom switches the resolution from 320 to 160 to double the display width
194         // this is not yet supported
195         if (doom_hack)
196         {
197                 while (iwidth)
198                 {
199                         uint8 d0=jaguar_byte_read(ptr+0);
200                         uint8 d1=jaguar_byte_read(ptr+1);
201                         *current_line_buffer++=d0;
202                         *current_line_buffer++=d1;
203                         *current_line_buffer++=d0;
204                         *current_line_buffer++=d1;
205                         ptr+=2;
206                         iwidth--;
207                 }
208                 return;
209         }
210         if (op_bitmap_bit_depth[bitdepth]==1)
211         {
212                 if (pitch==1)
213                 {
214                         #include "include/fbmpop1.h"
215                 }
216                 else
217                 {
218                         #include "include/fbmpop1p.h"
219                 }
220         }
221         else
222         if (op_bitmap_bit_depth[bitdepth]==2)
223         {
224                 if (pitch==1)
225                 {
226                         #include "include/fbmpop2.h"
227                 }
228                 else
229                 {
230                         #include "include/fbmpop2p.h"
231                 }
232         }
233         else
234         if (op_bitmap_bit_depth[bitdepth]==4)
235         {
236                 if (pitch==1)
237                 {
238                         #include "include/fbmpop4.h"
239                 }
240                 else
241                 {
242                         #include "include/fbmpop4p.h"
243                 }
244         }
245         else
246         if (op_bitmap_bit_depth[bitdepth]==8)
247         {
248                 if (pitch==1)
249                 {
250                         #include "include/fbmpop8.h"
251                 }
252                 else
253                 {
254                         #include "include/fbmpop8p.h"
255                 }
256         }
257         else
258         if (op_bitmap_bit_depth[bitdepth]==16)
259         {
260                 if (pitch==1)
261                 {
262                         #include "include/fbmpop16.h"
263                 }
264                 else
265                 {
266                         #include "include/fbmpop16p.h"
267                 }
268         }
269         else
270         if (op_bitmap_bit_depth[bitdepth]==24)
271         {
272                 if (pitch==1)
273                 {
274                         #include "include/fbmpop24.h"
275                 }
276                 else
277                 {
278                         #include "include/fbmpop24p.h"
279                 }
280         }
281 }
282 //////////////////////////////////////////////////////////////////////////////
283 //
284 //////////////////////////////////////////////////////////////////////////////
285 //
286 //
287 //
288 //////////////////////////////////////////////////////////////////////////////
289 void op_process_scaled_bitmap(int16 *backbuffer, int scanline, uint64 p0, uint64 p1, uint64 p2, int render)
290 {
291         int32   xpos=(((int32)((p1<<20)&0xffffffff))>>20)-tom_getHBlankWidthInPixels();
292         int16   ypos=(((p0&0x3ff8)>>3)/2);
293         uint16  iwidth=((p1>>28)&0x3ff)*4;
294         uint16  dwidth=((p1>>18)&0x3ff)*4;
295         uint16  height=(p0>>14)&0x3ff;
296         uint32  link=((p0>>24)&0x7ffff)<<3;
297         uint32  ptr=((p0>>43)&0x1fffff)<<3;
298         uint32  firstPix=(p1>>49)&0x3f;
299         uint8   flags=(p1>>45)&0x0f;
300         uint8   idx=(p1>>38)&0x7f; 
301         uint8   pitch=(p1>>15)&0x07;
302         uint8   bitdepth=(p1>>12)&0x07;
303         int16   scanline_width=tom_getVideoModeWidth();
304         uint8   *tom_ram_8=tom_get_ram_pointer();
305         uint8   *current_line_buffer=&tom_ram_8[0x1800];
306         float   vscale;
307         float   hscale;
308         
309         uint32  vscale_fixed3p5=((p2>>8)&0xff);
310         uint32  hscale_fixed3p5=(p2&0xff);
311         vscale=((float)vscale_fixed3p5)/32;
312         hscale=((float)hscale_fixed3p5)/32;
313
314         op_pointer=link;
315
316         if (jaguar_mainRom_crc32==0x5a5b9c68) // atari karts
317         {
318                 if (vscale == 0.0f) 
319                         vscale = 1.0f;
320
321                 if (ypos == 0)
322                         ypos = scanline;
323         }
324 #ifdef OP_DEBUG_BMP
325         if (xpos == -3)
326                 fprintf(log_get(),"[scanline %i] %ix%i scaled to %ix%i scale (%f, %f)%i bpp pitch %i at (%i,%i) @ 0x%.8x Transluency=%s\n",
327                                                                                                                                                           scanline,
328                                                                                                                                                           iwidth,height,
329                                                                                                                                                           (int)(iwidth*hscale),
330                                                                                                                                                           (int)(height*vscale),
331                                                                                                                                                           hscale, vscale,
332                                                                                                                                                           op_bitmap_bit_depth[bitdepth],pitch,xpos,ypos,ptr,(flags&FLAGS_READMODIFY)?"yes":"no");
333 #endif
334         if (jaguar_mainRom_crc32==0x2f032271)
335         {
336                 ypos+=8;
337         }
338
339         if ((render==0)||(op_pointer==0)||(height<0)||(dwidth<0)||(ptr==0)||(pitch==0))
340         {
341                 return;
342         }
343
344         if (op_bitmap_bit_depth[bitdepth]==8)
345         {
346                 iwidth*=2;
347                 dwidth*=2;
348         }
349         if (op_bitmap_bit_depth[bitdepth]==4)
350         {
351                 iwidth*=2;
352                 dwidth*=2;
353         }
354         if (op_bitmap_bit_depth[bitdepth]==2)
355         {
356                 iwidth*=2;
357                 dwidth*=2;
358         }
359         if (op_bitmap_bit_depth[bitdepth]==1)
360         {
361                 iwidth*=2;
362                 dwidth*=2;
363         }
364
365         uint16  scaled_width=iwidth*hscale;
366         uint16  scaled_height=height*vscale;
367
368         if (op_bitmap_bit_depth[bitdepth]==4)   // why ?
369                 scaled_width*=2;
370
371         if (op_bitmap_bit_depth[bitdepth]==2)   // why ?
372                 scaled_width*=4;
373
374         if (op_bitmap_bit_depth[bitdepth]==1)   // why ?
375                 scaled_width*=8;
376
377         // seek to the good bitmap scanline
378         // not sure for palettized modes
379         if (op_bitmap_bit_depth[bitdepth]>8)
380                 ptr+=((dwidth*op_bitmap_bit_size[bitdepth])>>16)*((uint32)((scanline-ypos)/vscale));
381         else
382                 ptr+=dwidth*((uint32)((scanline-ypos)/vscale));
383
384         // visible ?
385         if ((scanline<ypos)||(scanline>(ypos+scaled_height))||((xpos+scaled_width)<0)||(xpos>=scanline_width))
386                 return;
387
388         
389         if (xpos<0)
390         {
391                 scaled_width+=xpos;
392                 ptr+=(pitch*op_bitmap_bit_size[bitdepth]*((uint32)((-xpos)/hscale)))>>16;
393                 xpos=0;
394         }
395
396         if (iwidth<=0)
397                 return;
398
399         if (flags&FLAGS_HFLIP)
400         {
401                 if ((xpos<0)||((xpos-scaled_width)>=scanline_width))
402                         return;
403
404                 if ((xpos-scaled_width)<0)
405                         scaled_width=xpos;
406         }
407         else
408         {
409                 if (((xpos+scaled_width)<0)||(xpos>=scanline_width))
410                         return;
411
412                 if ((xpos+scaled_width)>scanline_width)
413                         scaled_width=scanline_width-xpos;
414         }
415         
416         current_line_buffer+=(xpos*2);
417
418         int32 hscale_fixed=(int32)(65536.0f/hscale);
419         int32 cnt=0;
420
421         if (op_bitmap_bit_depth[bitdepth]==1)
422         {
423                 if (pitch==1)
424                 {
425                         #include "include/zbmpop1.h"
426                 }
427                 else
428                 {
429                         #include "include/zbmpop1p.h"
430                 }
431         }
432         else
433         if (op_bitmap_bit_depth[bitdepth]==2)
434         {
435                 if (pitch==1)
436                 {
437                         #include "include/zbmpop2.h"
438                 }
439                 else
440                 {
441                         #include "include/zbmpop2p.h"
442                 }
443         }
444         else
445         if (op_bitmap_bit_depth[bitdepth]==4)
446         {
447                 if (pitch==1)
448                 {
449                         #include "include/zbmpop4.h"
450                 }
451                 else
452                 {
453                         #include "include/zbmpop4p.h"
454                 }
455         }
456         else
457         if (op_bitmap_bit_depth[bitdepth]==8)
458         {
459                 if (pitch==1)
460                 {
461                         #include "include/zbmpop8.h"
462                 }
463                 else
464                 {
465                         #include "include/zbmpop8p.h"
466                 }
467         }
468         else
469         if (op_bitmap_bit_depth[bitdepth]==16)
470         {
471                 if (pitch==1)
472                 {
473                         #include "include/zbmpop16.h"
474                 }
475                 else
476                 {
477                         #include "include/zbmpop16p.h"
478                 }
479         }
480         else
481                 fprintf(log_get(),"(unimplemented) %i bpp scaled bitmap\n",op_bitmap_bit_depth[bitdepth]);
482 }
483 //////////////////////////////////////////////////////////////////////////////
484 //
485 //////////////////////////////////////////////////////////////////////////////
486 //
487 //
488 //
489 //////////////////////////////////////////////////////////////////////////////
490 uint64 op_load_phrase(uint32 offset)
491 {
492         offset &= (~0x07);                                              // 8 byte alignment
493
494         uint64 data = jaguar_byte_read(offset++);
495         data <<= 8;
496         data |= jaguar_byte_read(offset++);
497         data <<= 8;
498         data |= jaguar_byte_read(offset++);
499         data <<= 8;
500         data |= jaguar_byte_read(offset++);
501         data <<= 8;
502         data |= jaguar_byte_read(offset++);
503         data <<= 8;
504         data |= jaguar_byte_read(offset++);
505         data <<= 8;
506         data |= jaguar_byte_read(offset++);
507         data <<= 8;
508         data |= jaguar_byte_read(offset++);
509
510         return data;
511 }
512 //////////////////////////////////////////////////////////////////////////////
513 //
514 //////////////////////////////////////////////////////////////////////////////
515 //
516 //
517 //
518 //////////////////////////////////////////////////////////////////////////////
519 void op_process_list(int16 * backbuffer, int scanline, int render)
520 {
521         uint64 p0;      
522
523         cnt_bitmap = 0;
524
525         if (scanline < tom_get_vdb())
526                 return;
527
528         if (scanline >= 525)//tom_getVideoModeHeight()+tom_get_vdb())
529                 return;
530
531         op_pointer = op_get_list_pointer();
532
533         objectp_stop_reading_list = 0;
534         cnt = 0;
535
536 //      if (op_pointer) fprintf(log_get()," new op list at 0x%.8x scanline %i\n",op_pointer,scanline);
537         while (op_pointer)
538         {
539                 if (objectp_stop_reading_list)
540                         return;
541                         
542                 p0 = op_load_phrase(op_pointer);
543                 op_pointer += 8;
544                 
545
546 //              fprintf(log_get(),"0x%.8x type %i\n",op_pointer,((uint8)p0&0x07));              
547                 switch ((uint8)p0&0x07)
548                 {
549                 case OBJECT_TYPE_BITMAP:
550                 {
551                         uint64 p1 = op_load_phrase(op_pointer);
552                         op_pointer += 8;
553                         op_process_bitmap(backbuffer, scanline, p0, p1, render);
554                         break;
555                 }
556                 case OBJECT_TYPE_SCALE:
557                 {
558                         uint64 p1 = op_load_phrase(op_pointer);
559                         op_pointer += 8;
560                         uint64 p2 = op_load_phrase(op_pointer);
561                         op_pointer += 8;
562                         op_process_scaled_bitmap(backbuffer, scanline, p0, p1, p2, render);
563                         break;
564                 }
565                 case OBJECT_TYPE_GPU:
566                 {
567                         uint64 data = p0 >> 3;
568                         op_set_current_object(p0);
569                         gpu_set_irq_line(3, 1); 
570                         break;
571                 }
572                 case OBJECT_TYPE_BRANCH:
573                 {
574                         uint16 vcnt = (p0>>3) & 0x7FF;
575                         uint8  cc   = (p0>>14) & 0x03;
576                         uint32 link = ((p0>>24) & 0x1FFFFF) << 3;
577                         
578 //                      if ((vcnt!=507)&&(vcnt!=25))
579 //                              fprintf(log_get(),"\t%i%s%i link=0x%.8x\n",scanline,condition_to_str[cc],vcnt>>1,link);
580                         switch (cc)
581                         {
582                         case CONDITION_EQUAL:
583                                 if ((vcnt != 0x7FF) && (vcnt & 0x01))
584                                         vcnt ^= 0x01;
585                                 if (((2*tom_get_scanline()) == vcnt) || (vcnt == 0x7FF))
586                                         op_pointer=link;
587                                 break;
588                         case CONDITION_LESS_THAN:
589                                 if ((2*tom_get_scanline()) < vcnt)
590                                         op_pointer=link;
591                                 break;
592                         case CONDITION_GREATER_THAN:
593                                 if ((2*tom_get_scanline()) > vcnt)
594                                         op_pointer=link;
595                                 break;
596                         case CONDITION_OP_FLAG_SET:
597                                 if (op_get_status_register() & 0x01)
598                                         op_pointer=link;
599                                 break;
600                         case CONDITION_SECOND_HALF_LINE:
601                                 fprintf(log_get(), "op: unexpected CONDITION_SECOND_HALF_LINE in BRANCH object\nop: shuting down\n");
602                                 fclose(log_get());
603                                 exit(0);
604                                 break;
605                         default:
606                                 fprintf(log_get(),"op: unimplemented branch condition %i\n", cc);
607                         }
608                         break;
609                 }
610                 case OBJECT_TYPE_STOP:
611                 {
612                         // unsure
613                         op_set_status_register(((p0>>3) & 0xFFFFFFFF));
614                         
615                         if (p0 & 0x8)
616                         {
617                                 tom_set_pending_object_int();
618                                 if ((tom_irq_enabled(2)) && (jaguar_interrupt_handler_is_valid(64)))
619                                 {
620 //                                      s68000interrupt(7,64);
621 //                                      s68000flushInterrupts();
622                                         m68k_set_irq(7);                                // Cause an NMI to occur...
623                                 }
624                         }
625
626                         return;
627                         break;
628                 }
629                 default:
630                 {
631                         fprintf(log_get(),"op: unknown object type %i\n", ((uint8)p0 & 0x07)); 
632                         return;
633                 }
634                 }
635         }
636 }
637 //////////////////////////////////////////////////////////////////////////////
638 //
639 //////////////////////////////////////////////////////////////////////////////
640 //
641 //
642 //
643 //////////////////////////////////////////////////////////////////////////////
644 void op_init(void)
645 {
646         memory_malloc_secure((void **)&op_blend_y, 0x10000, "Jaguar Object processor Y blend lookup table");
647         memory_malloc_secure((void **)&op_blend_cc, 0x10000, "Jaguar Object processor C blend lookup table");
648
649         for(int i=0; i<256*256; i++)
650         {
651                 int y = (i >> 8) & 0xFF;
652                 int dy = (int8)(i & 0xFF);
653                 y += dy;
654                 if (y < 0)
655                         y = 0;
656                 else if (y > 0xFF)
657                         y = 0xFF;
658                 op_blend_y[i] = y;
659         }
660
661         for(int i=0; i<256*256; i++)
662         {
663                 int cl = (i >> 8) & 0xFF;
664                 int dcl = (int8)(i & 0xFF);
665                 cl += dcl;
666                 if (cl < 0)
667                         cl = 0;
668                 else if (cl > 0xFF)
669                         cl = 0xFF;
670                 op_blend_cc[i] = cl;
671         }
672         op_reset();
673 }
674 //////////////////////////////////////////////////////////////////////////////
675 //
676 //////////////////////////////////////////////////////////////////////////////
677 //
678 //
679 //
680 //////////////////////////////////////////////////////////////////////////////
681 void op_reset(void)
682 {
683         memset(objectp_ram, 0x00, 0x18);
684         objectp_running = 0;
685 }
686 //////////////////////////////////////////////////////////////////////////////
687 //
688 //////////////////////////////////////////////////////////////////////////////
689 //
690 //
691 //
692 //////////////////////////////////////////////////////////////////////////////
693 void op_done(void)
694 {
695 }
696 //////////////////////////////////////////////////////////////////////////////
697 //
698 //////////////////////////////////////////////////////////////////////////////
699 //
700 //
701 //
702 //////////////////////////////////////////////////////////////////////////////
703 void op_byte_write(uint32 offset, uint8 data)
704 {
705         offset &= 0x3F;
706         objectp_ram[offset] = data;
707 }
708 //////////////////////////////////////////////////////////////////////////////
709 //
710 //////////////////////////////////////////////////////////////////////////////
711 //
712 //
713 //
714 //////////////////////////////////////////////////////////////////////////////
715 void op_word_write(uint32 offset, uint16 data)
716 {
717         offset &= 0x3F;
718         objectp_ram[offset] = (data >> 8) & 0xFF;
719         objectp_ram[offset+1] = data & 0xFF;
720
721 }
722 //////////////////////////////////////////////////////////////////////////////
723 //
724 //////////////////////////////////////////////////////////////////////////////
725 //
726 //
727 //
728 //////////////////////////////////////////////////////////////////////////////
729 uint8 op_byte_read(uint32 offset)
730 {
731         offset &= 0x3F;
732         return objectp_ram[offset];
733 }
734 //////////////////////////////////////////////////////////////////////////////
735 //
736 //////////////////////////////////////////////////////////////////////////////
737 //
738 //
739 //
740 //////////////////////////////////////////////////////////////////////////////
741 uint16 op_word_read(uint32 offset)
742 {
743         return (objectp_ram[offset & 0x3F] << 8) | objectp_ram[(offset+1) & 0x3F];
744 }
745 //////////////////////////////////////////////////////////////////////////////
746 //
747 //////////////////////////////////////////////////////////////////////////////
748 //
749 //
750 //
751 //////////////////////////////////////////////////////////////////////////////
752 uint32 op_get_list_pointer(void)
753 {
754         uint32 ptr = objectp_ram[0x22];
755         ptr <<= 8;
756         ptr |= objectp_ram[0x23];
757         ptr <<= 8;
758         ptr |= objectp_ram[0x20];
759         ptr <<= 8;
760         ptr |= objectp_ram[0x21];
761         ptr &= ~0x07;
762
763         return ptr;//*/
764 //      return (objectp_ram[0x20] << 24) | (objectp_ram[0x21] << 16) | (objectp_ram[0x22] << 8) | objectp_ram[0x23];
765 }
766 //////////////////////////////////////////////////////////////////////////////
767 //
768 //////////////////////////////////////////////////////////////////////////////
769 //
770 //
771 //
772 //////////////////////////////////////////////////////////////////////////////
773 uint32 op_get_status_register(void)
774 {
775         uint32 ptr = objectp_ram[0x26];
776         ptr <<= 8;
777         ptr |= objectp_ram[0x27];
778         ptr <<= 8;
779         ptr |= objectp_ram[0x28];
780         ptr <<= 8;
781         ptr |= objectp_ram[0x29];
782
783         return ptr;
784 }
785 //////////////////////////////////////////////////////////////////////////////
786 //
787 //////////////////////////////////////////////////////////////////////////////
788 //
789 //
790 //
791 //////////////////////////////////////////////////////////////////////////////
792 void op_set_status_register(uint32 data)
793 {
794         objectp_ram[0x26] = (data & 0xFF000000) >> 24;
795         objectp_ram[0x27] = (data & 0x00FF0000) >> 16;
796         objectp_ram[0x28] = (data & 0x0000FF00) >> 8;
797         objectp_ram[0x29] |= (data & 0xFE);
798 }
799 //////////////////////////////////////////////////////////////////////////////
800 //
801 //////////////////////////////////////////////////////////////////////////////
802 //
803 //
804 //
805 //////////////////////////////////////////////////////////////////////////////
806 void op_set_current_object(uint64 object)
807 {
808         // less significant 32 bits first
809         objectp_ram[0x13] = object&0xff; object>>=8;
810         objectp_ram[0x12] = object&0xff; object>>=8;
811         objectp_ram[0x11] = object&0xff; object>>=8;
812         objectp_ram[0x10] = object&0xff; object>>=8;
813
814         objectp_ram[0x17] = object&0xff; object>>=8;
815         objectp_ram[0x16] = object&0xff; object>>=8;
816         objectp_ram[0x15] = object&0xff; object>>=8;
817         objectp_ram[0x14] = object&0xff; 
818 }
819