ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/Display_Be.h
(Generate patch)

Comparing Frodo4/Src/Display_Be.h (file contents):
Revision 1.1 by cebix, 2003-07-01T17:32:13Z vs.
Revision 1.8 by cebix, 2009-01-11T11:32:38Z

# Line 2 | Line 2
2   *  Display_Be.h - C64 graphics display, emulator window handling,
3   *                 Be specific stuff
4   *
5 < *  Frodo (C) 1994-1997,2002 Christian Bauer
5 > *  Frodo (C) 1994-1997,2002-2009 Christian Bauer
6   *
7   *  This program is free software; you can redistribute it and/or modify
8   *  it under the terms of the GNU General Public License as published by
# Line 28 | Line 28
28   #include "main.h"
29  
30  
31 + #ifndef BIT_BANG
32 + #define BIT_BANG 0
33 + #endif
34 + #ifndef MGA_HACK
35 + #define MGA_HACK 0
36 + #endif
37 +
38 +
39   // Window thread messages
40   const uint32 MSG_REDRAW = 1;
41  
# Line 84 | Line 92 | const int key_byte[128] = {
92             3,   4,   4,  5,   5,  6,  6, 8+0,
93          0x26,0x22,0x2a,  0,   7, -1,  7,  -1,
94  
95 <           7, 8+0,   0,  0,0x30, -1,  7,   7,
95 >        0x30, 8+0,   0,  0,0x30, -1,  7,   7,
96            -1,  -1,  -1, -1,  -1, -1, -1,  -1,
97  
98            -1,  -1,  -1, -1,  -1, -1, -1,  -1,
# Line 141 | Line 149 | private:
149   class SpeedoView;
150   class LEDView;
151  
152 < class C64Window : public BWindow {
152 > class C64Window : public BDirectWindow {
153   public:
154          C64Window();
155  
156          virtual bool QuitRequested(void);
157          virtual void MessageReceived(BMessage *msg);
158 +        virtual void DirectConnected(direct_buffer_info *info);
159  
160          BBitmap *TheBitmap[2];
161          SpeedoView *Speedometer;
162          LEDView *LED[4];
163  
164 + #if BIT_BANG
165 +        uint8 *bits;
166 +        int bytes_per_row;
167 + #endif
168 +
169   private:
170          BitmapView *main_view;
171   };
# Line 166 | Line 180 | public:
180          C64Screen(C64Display *display) : BWindowScreen("Frodo", B_8_BIT_640x480, &error), the_display(display)
181          {
182                  Lock();
183 <                BitmapView *main_view = new BitmapView(Bounds(), NULL);
183 >                TheBitmap = new BBitmap(DisplayFrame, B_COLOR_8_BIT);
184 >                main_view = new BitmapView(Bounds(), TheBitmap);
185                  AddChild(main_view);
186                  main_view->MakeFocus();
187                  Connected = false;
188 +                first_connected = true;
189 + #if MGA_HACK
190 +                mga_ready = false;
191 + #endif
192                  Unlock();
193          }
194 +        ~C64Screen()
195 +        {
196 +                delete TheBitmap;
197 +        }
198  
199          virtual void ScreenConnected(bool active);
200          virtual void DispatchMessage(BMessage *msg, BHandler *handler);
# Line 182 | Line 205 | public:
205          bool Connected;                 // Flag: screen connected
206          int Speed;
207          char SpeedoStr[16];             // Speedometer value converted to a string
208 +        BBitmap *TheBitmap;
209  
210   private:
211          C64Display *the_display;
212 +        BitmapView *main_view;
213 +        bool first_connected;
214          status_t error;
215 +
216 + #if MGA_HACK
217 +        area_id mga_clone_area;
218 +        volatile uint8 *isa_io;
219 +        bool mga_ready;
220 +
221 +        void CRTC_out(int reg, uint8 val) {isa_io[0x3d4] = reg; __eieio(); isa_io[0x3d5] = val; __eieio();}
222 +        uint8 CRTC_in(int reg) {isa_io[0x3d4] = reg; __eieio(); return isa_io[0x3d5];}
223 +        void SEQ_out(int reg, uint8 val) {isa_io[0x3c4] = reg; __eieio(); isa_io[0x3c5] = val; __eieio();}
224 +        uint8 SEQ_in(int reg) {isa_io[0x3c4] = reg; __eieio(); return isa_io[0x3c5];}
225 +        void GDC_out(int reg, uint8 val) {isa_io[0x3ce] = reg; __eieio(); isa_io[0x3cf] = val; __eieio();}
226 +        uint8 GDC_in(int reg) {isa_io[0x3ce] = reg; __eieio(); return isa_io[0x3cf];}
227 +        void ATC_out(int reg, uint8 val) {isa_io[0x3c0] = reg; __eieio(); isa_io[0x3c0] = val; __eieio();}
228 + #endif
229   };
230  
231  
# Line 313 | Line 353 | void C64Display::Update(void)
353                          the_screen->DrawLED(i, led_state[i]);
354                  the_screen->DrawSpeedometer();
355  
356 +                // Update C64 display in dobule scan mode
357 +                if (ThePrefs.DoubleScan) {
358 +                        uint8 *src = (uint8 *)the_screen->TheBitmap->Bits();
359 +                        uint32 src_xmod = the_screen->TheBitmap->BytesPerRow();
360 +                        src += src_xmod * 16 + 32;
361 +                        uint8 *dest = (uint8 *)the_screen->CardInfo()->frame_buffer;
362 +                        uint32 dest_xmod = the_screen->CardInfo()->bytes_per_row;
363 + #ifdef __POWERPC__
364 +                        double tmp[1];
365 +                        for (int y=0; y<240; y++) {
366 +                                uint32 *p = (uint32 *)src - 1;
367 +                                double *q1 = (double *)dest - 1;
368 +                                double *q2 = q1 + dest_xmod / sizeof(double);
369 +                                for (int x=0; x<80; x++) {
370 +                                        uint32 val = *(++p);
371 +                                        uint8 *r = (uint8 *)&tmp[1];
372 +                                        *(--r) = val;
373 +                                        *(--r) = val;
374 +                                        val >>= 8;
375 +                                        *(--r) = val;
376 +                                        *(--r) = val;
377 +                                        val >>= 8;
378 +                                        *(--r) = val;
379 +                                        *(--r) = val;
380 +                                        val >>= 8;
381 +                                        *(--r) = val;
382 +                                        *(--r) = val;
383 +                                        double tmp2 = tmp[0];
384 +                                        *(++q1) = tmp2;
385 +                                        *(++q2) = tmp2;
386 +                                }
387 +                                src += src_xmod;
388 +                                dest += dest_xmod * 2;
389 +                        }
390 + #else
391 +                        for (int y=0; y<240; y++) {
392 +                                uint32 *p = (uint32 *)src;
393 +                                uint32 *q1 = (uint32 *)dest;
394 +                                uint32 *q2 = q1 + dest_xmod / sizeof(uint32);
395 +                                for (int x=0; x<80; x++) {
396 +                                        uint32 val = *p++;
397 +                                        uint32 tmp = val & 0x000000ff;
398 +                                        tmp |= (val << 8) & 0x0000ff00;
399 +                                        tmp |= (val << 8) & 0x00ff0000;
400 +                                        tmp |= (val << 16) & 0xff000000;
401 +                                        *q1++ = tmp;
402 +                                        *q2++ = tmp;
403 +                                        tmp = (val >> 16) & 0x000000ff;
404 +                                        tmp |= (val >> 8) & 0x0000ff00;
405 +                                        tmp |= (val >> 8) & 0x00ff0000;
406 +                                        tmp |= val & 0xff000000;
407 +                                        *q1++ = tmp;
408 +                                        *q2++ = tmp;
409 +                                }
410 +                                src += src_xmod;
411 +                                dest += dest_xmod * 2;
412 +                        }
413 + #endif
414 +                }
415 +
416          } else {
417  
418 + #if !BIT_BANG
419                  // Update C64 display
420                  BMessage msg(MSG_REDRAW);
421                  msg.AddInt32("bitmap", draw_bitmap);
422                  the_window->PostMessage(&msg);
423                  draw_bitmap ^= 1;
424 + #endif
425  
426                  // Update LEDs
427                  for (int i=0; i<4; i++)
# Line 351 | Line 453 | void C64Display::Speedometer(int speed)
453  
454   uint8 *C64Display::BitmapBase(void)
455   {
456 <        if (using_screen)
457 <                return (uint8 *)the_screen->CardInfo()->frame_buffer;
458 <        else
456 >        if (using_screen) {
457 >                if (ThePrefs.DoubleScan)
458 >                        return (uint8 *)the_screen->TheBitmap->Bits();
459 >                else
460 >                        return (uint8 *)the_screen->CardInfo()->frame_buffer;
461 >        } else
462 > #if BIT_BANG
463 >                return (uint8 *)the_window->bits;
464 > #else
465                  return (uint8 *)the_window->TheBitmap[draw_bitmap]->Bits();
466 + #endif
467   }
468  
469  
# Line 364 | Line 473 | uint8 *C64Display::BitmapBase(void)
473  
474   int C64Display::BitmapXMod(void)
475   {
476 <        if (using_screen)
477 <                return the_screen->CardInfo()->bytes_per_row;
478 <        else
476 >        if (using_screen) {
477 >                if (ThePrefs.DoubleScan)
478 >                        return the_screen->TheBitmap->BytesPerRow();
479 >                else
480 >                        return the_screen->CardInfo()->bytes_per_row;
481 >        } else
482 > #if BIT_BANG
483 >                return the_window->bytes_per_row;
484 > #else
485                  return the_window->TheBitmap[draw_bitmap]->BytesPerRow();
486 + #endif
487   }
488  
489  
# Line 499 | Line 615 | void C64Display::Resume(void)
615   *  Window constructor
616   */
617  
618 < C64Window::C64Window() : BWindow(WindowFrame, "Frodo", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
618 > C64Window::C64Window() : BDirectWindow(WindowFrame, "Frodo", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
619   {
620          // Move window to right position
621          Lock();
# Line 524 | Line 640 | C64Window::C64Window() : BWindow(WindowF
640          bar->AddItem(menu);
641          AddChild(bar);
642          SetKeyMenuBar(bar);
643 <        int mbar_height = bar->Frame().bottom + 1;
643 >        int mbar_height = int(bar->Frame().bottom) + 1;
644  
645          // Resize window to fit menu bar
646          ResizeBy(0, mbar_height);
# Line 585 | Line 701 | void C64Window::MessageReceived(BMessage
701          switch (msg->what) {
702                  case MSG_REDRAW:  // Redraw bitmap
703                          MessageQueue()->Lock();
704 <                        while ((msg2 = MessageQueue()->FindMessage(MSG_REDRAW, 0)) != NULL)
704 >                        while ((msg2 = MessageQueue()->FindMessage(MSG_REDRAW, 0)) != NULL) {
705                                  MessageQueue()->RemoveMessage(msg2);
706 +                                delete msg2;
707 +                        }
708                          MessageQueue()->Unlock();
709                          main_view->ChangeBitmap(TheBitmap[msg->FindInt32("bitmap")]);
710                          Lock();
# Line 601 | Line 719 | void C64Window::MessageReceived(BMessage
719  
720  
721   /*
722 + *  Window connected/disconnected
723 + */
724 +
725 + void C64Window::DirectConnected(direct_buffer_info *info)
726 + {
727 + #if BIT_BANG
728 +        switch (info->buffer_state & B_DIRECT_MODE_MASK) {
729 +                case B_DIRECT_STOP:
730 + //                      acquire_sem(drawing_sem);
731 +                        break;
732 +                case B_DIRECT_MODIFY:
733 + //                      acquire_sem(drawing_sem);
734 +                case B_DIRECT_START:
735 +                        bits = ((uint8 *)info->bits + info->window_bounds.top * info->bytes_per_row + info->window_bounds.left * info->bits_per_pixel / 8);
736 +                        bytes_per_row = info->bytes_per_row;
737 + //                      release_sem(drawing_sem);
738 +                        break;
739 +        }
740 + #endif
741 + }
742 +
743 +
744 + /*
745   *  Workspace activated/deactivated
746   */
747  
748   void C64Screen::ScreenConnected(bool active)
749   {
750          if (active) {
751 +                if (first_connected) {
752 +                        first_connected = false;
753 +
754 + #if MGA_HACK
755 +                        mga_clone_area = -1;
756 +
757 +                        // Construct register area name
758 +                        char mga_area_name[64];
759 +                        int bus = 0, device = 13, function = 0;
760 +                        sprintf(mga_area_name, "102B_0519_%02X%02X%02X regs", bus, device, function);
761 +
762 +                        // Find MGA register area
763 +                        area_id mga_area = find_area(mga_area_name);
764 +                        if (mga_area > 0) {
765 +
766 +                                // Clone area, remove write protection
767 +                                volatile uint8 *mga_io;
768 +                                mga_clone_area = clone_area("mga registers", (void **)&mga_io, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, mga_area);
769 +                                if (mga_clone_area > 0) {
770 +                                        isa_io = mga_io + 0x1c00;
771 +                                        mga_ready = true;
772 +                                }
773 +                        }
774 + #endif
775 +                }
776 +
777 + #if MGA_HACK
778 +                if (mga_ready) {
779 +                        CRTC_out(0x09, 1);                      // Enable double scan
780 +                        int a = 4 * 640;
781 +                        CRTC_out(0x0c, a >> 8);         // Center screen vertically
782 +                        CRTC_out(0x0d, a);
783 +                        // defaults:
784 +                        //  total               0x67
785 +                        //  display end 0x4f
786 +                        //  blank start 0x4f
787 +                        //  blank end     2b
788 +                        //  sync start  0x53
789 +                        //  sync end      1f
790 +                        CRTC_out(0x00, 0x3f);           // Horizontal timing
791 +                        CRTC_out(0x01, 0x2f);
792 +                        CRTC_out(0x02, 0x2f);
793 +                        CRTC_out(0x03, 0x83);
794 +                        CRTC_out(0x04, 0x32);
795 +                        CRTC_out(0x05, 0x1a);
796 +                }
797 + #endif
798 +
799                  FillRect(0, 0, 639, 479, 0);    // Clear screen
800                  the_display->TheC64->Resume();
801                  Connected = true;
# Line 657 | Line 846 | void C64Screen::DispatchMessage(BMessage
846  
847   void C64Screen::DrawLED(int i, int state)
848   {
849 +        int maxy;
850 +        if (ThePrefs.DoubleScan)
851 +                maxy = 480;
852 +        else
853 +                maxy = DISPLAY_Y;
854 +
855          switch (state) {
856                  case LED_ON:
857 <                        FillRect(10+i*20, DISPLAY_Y-20, 20+i*20, DISPLAY_Y-12, 54);
857 >                        FillRect(10+i*20, maxy-20, 20+i*20, maxy-12, 54);
858                          break;
859                  case LED_ERROR_ON:
860 <                        FillRect(10+i*20, DISPLAY_Y-20, 20+i*20, DISPLAY_Y-12, 44);
860 >                        FillRect(10+i*20, maxy-20, 20+i*20, maxy-12, 44);
861                          break;
862          }
863   }
# Line 689 | Line 884 | static const int8 Digits[11][8] = {    // D
884   void C64Screen::DrawSpeedometer()
885   {
886          // Don't display speedometer if we're running at about 100%
887 <        if (Speed >= 99 && Speed <= 101)
887 >        if (Speed >= 50 && Speed <= 101)
888                  return;
889  
890 +        int maxx, maxy;
891 +        if (ThePrefs.DoubleScan) {
892 +                maxx = 640;
893 +                maxy = 480;
894 +        } else {
895 +                maxx = DISPLAY_X;
896 +                maxy = DISPLAY_Y;
897 +        }
898 +
899          char *s = SpeedoStr;
900          char c;
901          long xmod = CardInfo()->bytes_per_row;
902 <        uint8 *p = (uint8 *)CardInfo()->frame_buffer + DISPLAY_X - 8*8 + (DISPLAY_Y-20) * xmod;
903 <        while (c = *s++) {
902 >        uint8 *p = (uint8 *)CardInfo()->frame_buffer + maxx - 8*8 + (maxy-20) * xmod;
903 >        while ((c = *s++) != 0) {
904                  if (c == ' ')
905                          continue;
906                  if (c == '%')
# Line 729 | Line 933 | void C64Screen::FillRect(int x1, int y1,
933          uint8 *p = (uint8 *)CardInfo()->frame_buffer + y1 * xmod + x1;
934          int n = x2 - x1 + 1;
935          for(int y=y1; y<=y2; y++) {
936 + #ifdef __POWERPC__
937                  memset_nc(p, color, n);
938 + #else
939 +                memset(p, color, n);
940 + #endif
941                  p += xmod;
942          }
943   }
# Line 817 | Line 1025 | SpeedoView::SpeedoView(BRect frame) : BV
1025          speedostr[0] = 0;
1026          bounds = Bounds();
1027          SetViewColor(fill_gray);
1028 +        SetLowColor(fill_gray);
1029          SetFont(be_plain_font);
1030   }
1031  
# Line 963 | Line 1172 | void LEDView::Pulse(void)
1172   *  Show a requester
1173   */
1174  
1175 < long ShowRequester(char *str, char *button1, char *button2)
1175 > long ShowRequester(const char *str, const char *button1, const char *button2)
1176   {
1177          BAlert *the_alert;
1178          

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines