2022-10-12 23:44:22 +02:00
|
|
|
// ****************************************************************************
|
|
|
|
// screen.cpp DB48X project
|
|
|
|
// ****************************************************************************
|
|
|
|
//
|
|
|
|
// File Description:
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ****************************************************************************
|
|
|
|
// (C) 2022 Christophe de Dinechin <christophe@dinechin.org>
|
|
|
|
// This software is licensed under the terms outlined in LICENSE.txt
|
|
|
|
// ****************************************************************************
|
|
|
|
// This file is part of DB48X.
|
|
|
|
//
|
|
|
|
// DB48X is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms outlined in the LICENSE.txt file
|
|
|
|
//
|
|
|
|
// DB48X is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// ****************************************************************************
|
|
|
|
|
|
|
|
#include "sim-screen.h"
|
|
|
|
|
|
|
|
#include <QBitmap>
|
|
|
|
#include <QGraphicsPixmapItem>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <dmcp.h>
|
|
|
|
#include <target.h>
|
|
|
|
|
|
|
|
|
2022-10-22 13:02:24 +02:00
|
|
|
SimScreen::SimScreen(QWidget *parent)
|
2022-10-12 23:44:22 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Initialize the screen
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
: QGraphicsView(parent),
|
|
|
|
screen_width(LCD_W),
|
|
|
|
screen_height(LCD_H),
|
|
|
|
scale(1),
|
|
|
|
bgColor(230, 230, 230),
|
|
|
|
fgColor(0, 0, 0),
|
2022-10-13 22:36:25 +02:00
|
|
|
bgPen(bgColor),
|
|
|
|
fgPen(fgColor),
|
2022-10-12 23:44:22 +02:00
|
|
|
screenTimer(new QTimer(this)),
|
|
|
|
mainPixmap(LCD_W, LCD_H)
|
|
|
|
{
|
|
|
|
connect(&screenTimer, SIGNAL(timeout()), this, SLOT(update()));
|
2022-10-13 22:36:25 +02:00
|
|
|
screenTimer.setSingleShot(true);
|
|
|
|
screenTimer.start(20);
|
2022-10-12 23:44:22 +02:00
|
|
|
|
|
|
|
screen.clear();
|
|
|
|
screen.setBackgroundBrush(QBrush(Qt::black));
|
|
|
|
|
|
|
|
mainScreen = screen.addPixmap(mainPixmap);
|
|
|
|
mainScreen->setOffset(0.0, 0.0);
|
|
|
|
|
|
|
|
setScene(&screen);
|
|
|
|
setSceneRect(0, -5, screen_width, screen_height + 5);
|
|
|
|
centerOn(qreal(screen_width) / 2, qreal(screen_height) / 2);
|
|
|
|
scale = 1.0;
|
|
|
|
setScale(4.0);
|
|
|
|
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-22 13:02:24 +02:00
|
|
|
SimScreen::~SimScreen()
|
2022-10-12 23:44:22 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
2022-10-22 13:02:24 +02:00
|
|
|
// SimScreen destructor
|
2022-10-12 23:44:22 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-22 13:02:24 +02:00
|
|
|
void SimScreen::setPixel(int x, int y, int on)
|
2022-10-12 23:44:22 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Set the given screen
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
// Pixels[offset]->setBrush(GrayBrush[color & 15]);
|
|
|
|
QPainter pt(&mainPixmap);
|
|
|
|
pt.setPen(on ? fgPen : bgPen);
|
|
|
|
pt.drawPoint(LCD_W - x, y);
|
2022-10-13 22:36:25 +02:00
|
|
|
pt.end();
|
2022-10-12 23:44:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-22 13:02:24 +02:00
|
|
|
void SimScreen::setScale(qreal sf)
|
2022-10-12 23:44:22 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Adjust the scaling factor
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
{
|
|
|
|
QGraphicsView::scale(sf / scale, sf / scale);
|
|
|
|
this->scale = sf;
|
|
|
|
|
|
|
|
QSize s;
|
|
|
|
s.setWidth(0);
|
|
|
|
s.setHeight((screen_height + 5) * scale);
|
|
|
|
setMinimumSize(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-22 13:02:24 +02:00
|
|
|
void SimScreen::update()
|
2022-10-12 23:44:22 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Refresh the screen
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
{
|
2022-10-18 21:28:59 +02:00
|
|
|
if (lcd_needsupdate != lcd_update)
|
2022-10-12 23:44:22 +02:00
|
|
|
{
|
2022-10-18 21:28:59 +02:00
|
|
|
lcd_update = lcd_needsupdate;
|
2022-10-12 23:44:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
screenTimer.setSingleShot(true);
|
|
|
|
screenTimer.start(20);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Monochrome screen
|
2022-10-13 22:48:57 +02:00
|
|
|
screen.setBackgroundBrush(QBrush(fgColor));
|
2022-10-12 23:44:22 +02:00
|
|
|
QPainter pt(&mainPixmap);
|
|
|
|
|
|
|
|
for (int y = 0; y < LCD_H; y++)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < LCD_W; x++)
|
|
|
|
{
|
|
|
|
unsigned bo = y * LCD_SCANLINE + x;
|
|
|
|
int on = (lcd_buffer[bo/8] >> (bo % 8)) & 1;
|
2022-10-15 03:51:54 +02:00
|
|
|
pt.setPen(on ? bgPen : fgPen);
|
2022-10-13 22:36:25 +02:00
|
|
|
pt.drawPoint(LCD_W - x, y);
|
2022-10-12 23:44:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pt.end();
|
|
|
|
|
|
|
|
mainScreen->setPixmap(mainPixmap);
|
|
|
|
QGraphicsView::update();
|
|
|
|
screenTimer.setSingleShot(true);
|
|
|
|
screenTimer.start(20);
|
|
|
|
}
|