Prototype simulator for the DM42

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This commit is contained in:
Christophe de Dinechin 2022-10-12 23:44:22 +02:00
parent 7d556893fe
commit 6399a1556a
28 changed files with 2694 additions and 30 deletions

9
.gitignore vendored
View file

@ -3,3 +3,12 @@
/build/
/cscope.files
/cscope.out
/sim/.qmake.stash
/sim/simulator.app/
/sim/simulator.mak
/sim/*.o
/sim/ui_sim-window.h
/sim/moc_predefs.h
/sim/moc_sim-screen.cpp
/sim/moc_sim-window.cpp
/sim/qrc_sim.cpp

View file

@ -133,6 +133,10 @@ LDFLAGS = $(CPUFLAGS) -T$(LDSCRIPT) $(LIBDIR) $(LIBS) \
all: $(TARGET).pgm help/$(TARGET).html
install: all
(tar cf - $(TARGET).pgm help/$(TARGET).html | (cd $(MOUNTPOINT) && tar xvf -)) && $(EJECT)
sim: sim/simulator.mak .ALWAYS
cd sim; make -f $(<F)
sim/simulator.mak: sim/simulator.pro
cd sim; qmake $(<F) -o $(@F)
debug-%:
$(MAKE) $@ OPT=debug
@ -198,5 +202,6 @@ clean:
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
.PHONY: clean all
.ALWAYS:
# *** EOF ***

200
sim/dmcp.cpp Normal file
View file

@ -0,0 +1,200 @@
// ****************************************************************************
// dmcp.cpp DB48X project
// ****************************************************************************
//
// File Description:
//
// A fake DMCP implementation with the functions we use in the simulator
//
//
//
//
//
//
//
//
// ****************************************************************************
// (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 <dmcp.h>
#include <target.h>
#include <types.h>
int lcd_needsupdate = 0;
uint8_t lcd_buffer[LCD_SCANLINE * LCD_H / 8];
void LCD_power_off(int clear)
{
UNUSED(clear);
}
void LCD_power_on()
{
}
int create_screenshot(int report_error)
{
}
void draw_power_off_image(int allow_errors)
{
}
int handle_menu(const smenu_t * menu_id, int action, int cur_line)
{
}
int key = -1;
int key_empty()
{
return key == -1;
}
int key_pop()
{
int k = key;
key = -1;
return k;
}
int key_pop_last()
{
return key_pop();
}
void key_pop_all()
{
key = -1;
}
int key_push(int k1)
{
key = k1;
}
void lcd_clear_buf()
{
for (int i = 0; i < sizeof(lcd_buffer); i++)
lcd_buffer[i] = 0xFF;
}
void lcd_draw_menu_keys(const char *keys[])
{
}
void lcd_fill_rect(uint32_t x, uint32_t y, uint32_t dx, uint32_t dy, int val)
{
}
int lcd_fontWidth(disp_stat_t * ds)
{
}
int lcd_for_calc(int what)
{
}
void lcd_forced_refresh()
{
}
int lcd_get_buf_cleared()
{
}
int lcd_lineHeight(disp_stat_t * ds)
{
}
uint8_t * lcd_line_addr(int y)
{
}
int lcd_nextFontNr(int nr)
{
}
int lcd_prevFontNr(int nr)
{
}
void lcd_prevLn(disp_stat_t * ds)
{
}
void lcd_print(disp_stat_t * ds, const char* fmt, ...)
{
}
void lcd_refresh()
{
}
void lcd_refresh_dma()
{
}
void lcd_refresh_wait()
{
}
void lcd_refresh_lines(int ln, int cnt)
{
}
void lcd_setLine(disp_stat_t * ds, int ln_nr)
{
}
void lcd_setXY(disp_stat_t * ds, int x, int y)
{
}
void lcd_set_buf_cleared(int val)
{
}
void lcd_switchFont(disp_stat_t * ds, int nr)
{
}
int lcd_textWidth(disp_stat_t * ds, const char* text)
{
}
void lcd_writeClr(disp_stat_t * ds)
{
}
void lcd_writeText(disp_stat_t * ds, const char* text)
{
}
void lcd_writeTextWidth(disp_stat_t * ds, const char* text)
{
}
int read_key(int *k1, int *k2)
{
}
void reset_auto_off()
{
}
void rtc_wakeup_delay()
{
}
void run_help_file(const char * help_file)
{
}
void run_help_file_style(const char * help_file, user_style_fn_t *user_style_fn)
{
}
void start_buzzer_freq(uint32_t freq)
{
}
void stop_buzzer()
{
}
void sys_delay(uint32_t ms_delay)
{
}
void sys_sleep()
{
}
void wait_for_key_press()
{
}
void wait_for_key_release(int tout)
{
}

1022
sim/dmcp.h Normal file

File diff suppressed because it is too large Load diff

154
sim/ff_ifc.h Normal file
View file

@ -0,0 +1,154 @@
/*
BSD 3-Clause License
Copyright (c) 2015-2022, SwissMicros
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The software and related material is released as NOMAS (NOt MAnufacturer Supported).
1. Info is released to assist customers using, exploring and extending the product
2. Do NOT contact the manufacturer with questions, seeking support, etc. regarding
NOMAS material as no support is implied or committed-to by the Manufacturer
3. The Manufacturer may reply and/or update materials if and when needed solely
at their discretion
*/
#ifndef __FF_IFC_H__
#define __FF_IFC_H__
/* These types MUST be 16-bit or 32-bit */
typedef int INT;
typedef unsigned int UINT;
/* This type MUST be 8-bit */
typedef unsigned char BYTE;
/* These types MUST be 16-bit */
typedef short SHORT;
typedef unsigned short WORD;
typedef unsigned short WCHAR;
/* These types MUST be 32-bit */
typedef long LONG;
typedef unsigned long DWORD;
/* This type MUST be 64-bit (Remove this for ANSI C (C89) compatibility) */
typedef unsigned long long QWORD;
typedef char TCHAR;
#define _T(x) x
#define _TEXT(x) x
typedef DWORD FSIZE_t;
typedef struct __FATFS FATFS;
typedef struct {
FATFS* fs;
WORD id;
BYTE attr;
BYTE stat;
DWORD sclust;
FSIZE_t objsize;
UINT lockid;
} _FDID;
typedef struct {
_FDID obj;
BYTE flag;
BYTE err;
FSIZE_t fptr;
DWORD clust;
DWORD sect;
DWORD dir_sect;
BYTE* dir_ptr;
DWORD* cltbl;
BYTE buf[512];
} FIL;
/* File access mode and open method flags (3rd argument of f_open) */
#define FA_READ 0x01
#define FA_WRITE 0x02
#define FA_OPEN_EXISTING 0x00
#define FA_CREATE_NEW 0x04
#define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10
#define FA_OPEN_APPEND 0x30
/* File function return code (FRESULT) */
typedef enum {
FR_OK = 0, /* (0) Succeeded */
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
FR_INT_ERR, /* (2) Assertion failed */
FR_NOT_READY, /* (3) The physical drive cannot work */
FR_NO_FILE, /* (4) Could not find the file */
FR_NO_PATH, /* (5) Could not find the path */
FR_INVALID_NAME, /* (6) The path name format is invalid */
FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
FR_EXIST, /* (8) Access denied due to prohibited access */
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
FR_NOT_ENABLED, /* (12) The volume has no work area */
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_LOCK */
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
} FRESULT;
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
FRESULT f_close (FIL* fp); /* Close an open file object */
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to the file */
FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
#define f_size(fp) ((fp)->obj.objsize)
#define f_tell(fp) ((fp)->fptr)
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
#ifndef EOF
#define EOF (-1)
#endif
#endif

BIN
sim/icon-dm42.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
sim/keyboard-dm42.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

32
sim/lft_ifc.h Normal file
View file

@ -0,0 +1,32 @@
#ifndef LFT_IFC_H
#define LFT_IFC_H
// ****************************************************************************
// lft_ifc.h<sim> DB48X project
// ****************************************************************************
//
// File Description:
//
// This file intentionally empty, overriding file of the same name
// in dmcp/
//
//
//
//
//
//
//
// ****************************************************************************
// (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.
// ****************************************************************************
#endif

BIN
sim/libbid.a Normal file

Binary file not shown.

48
sim/sim-main.cpp Normal file
View file

@ -0,0 +1,48 @@
// ****************************************************************************
// main.cpp DB48X project
// ****************************************************************************
//
// File Description:
//
// DM42 simulator for the DB48 project
//
//
//
//
//
//
//
//
// ****************************************************************************
// (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-window.h"
#include "sim-rpl.h"
#include <QApplication>
#include <QWindow>
int main(int argc, char *argv[])
// ----------------------------------------------------------------------------
// Main entry point for the simulator
// ----------------------------------------------------------------------------
{
#if QT_VERSION < 0x060000
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif // QT version 6
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

58
sim/sim-rpl.cpp Normal file
View file

@ -0,0 +1,58 @@
// ****************************************************************************
// sim-rpl.cpp DB48X project
// ****************************************************************************
//
// File Description:
//
// The thread running the simulator
//
//
//
//
//
//
//
//
// ****************************************************************************
// (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-rpl.h"
#include <dmcp.h>
RPLThread::RPLThread(QObject *parent) : QThread(parent)
// ----------------------------------------------------------------------------
// Constructor
// ----------------------------------------------------------------------------
{}
RPLThread::~RPLThread()
// ----------------------------------------------------------------------------
// Destructor
// ----------------------------------------------------------------------------
{}
void RPLThread::run()
// ----------------------------------------------------------------------------
// Thread entry point
// ----------------------------------------------------------------------------
{
program_main();
}
extern "C" void thread_yield()
{
QThread::msleep(1);
}

47
sim/sim-rpl.h Normal file
View file

@ -0,0 +1,47 @@
#ifndef SIM_RPL_H
#define SIM_RPL_H
// ****************************************************************************
// sim-rpl.h DB48X project
// ****************************************************************************
//
// File Description:
//
// The thread running the RPL program
//
//
//
//
//
//
//
//
// ****************************************************************************
// (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 <QThread>
class RPLThread:public QThread
// ----------------------------------------------------------------------------
// Thread running the RPL program
// ----------------------------------------------------------------------------
{
public:
RPLThread(QObject * parent);
~RPLThread();
void run();
};
#endif // RPLTHREAD_H

145
sim/sim-screen.cpp Normal file
View file

@ -0,0 +1,145 @@
// ****************************************************************************
// 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>
Screen::Screen(QWidget *parent)
// ----------------------------------------------------------------------------
// Initialize the screen
// ----------------------------------------------------------------------------
: QGraphicsView(parent),
screen_width(LCD_W),
screen_height(LCD_H),
scale(1),
bgColor(230, 230, 230),
fgColor(0, 0, 0),
screenTimer(new QTimer(this)),
mainPixmap(LCD_W, LCD_H)
{
connect(&screenTimer, SIGNAL(timeout()), this, SLOT(update()));
bgPen.setColor(bgColor);
bgPen.setStyle(Qt::NoPen);
bgPen.setWidthF(0.05);
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();
}
Screen::~Screen()
// ----------------------------------------------------------------------------
// Screen destructor
// ----------------------------------------------------------------------------
{
}
void Screen::setPixel(int x, int y, int on)
// ----------------------------------------------------------------------------
// Set the given screen
// ----------------------------------------------------------------------------
{
// Pixels[offset]->setBrush(GrayBrush[color & 15]);
QPainter pt(&mainPixmap);
pt.setPen(on ? fgPen : bgPen);
pt.drawPoint(LCD_W - x, y);
}
void Screen::setScale(qreal sf)
// ----------------------------------------------------------------------------
// 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);
}
void Screen::update()
// ----------------------------------------------------------------------------
// Refresh the screen
// ----------------------------------------------------------------------------
{
if (lcd_needsupdate)
{
lcd_needsupdate = 0;
}
else
{
screenTimer.setSingleShot(true);
screenTimer.start(20);
return;
}
// Monochrome screen
screen.setBackgroundBrush(QBrush(bgColor));
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;
setPixel(x, y, on);
}
}
pt.end();
mainScreen->setPixmap(mainPixmap);
QGraphicsView::update();
screenTimer.setSingleShot(true);
screenTimer.start(20);
}

74
sim/sim-screen.h Normal file
View file

@ -0,0 +1,74 @@
#ifndef SIM_SCREEN_H
#define SIM_SCREEN_H
// ****************************************************************************
// screen.h DB48X project
// ****************************************************************************
//
// File Description:
//
// Simulate the screen of the DM42
//
//
//
//
//
//
//
//
// ****************************************************************************
// (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 <QGraphicsView>
#include <QGraphicsPixmapItem>
#include <QTimer>
extern int lcd_needsupdate;
extern uint8_t lcd_buffer[];
class Screen : public QGraphicsView
// ----------------------------------------------------------------------------
// Screen emulation
// ----------------------------------------------------------------------------
{
Q_OBJECT;
public:
int screen_width;
int screen_height;
qreal scale;
QColor bgColor;
QColor fgColor;
QPen bgPen;
QPen fgPen;
QTimer screenTimer;
QGraphicsScene screen;
QGraphicsPixmapItem *mainScreen;
QPixmap mainPixmap;
public:
explicit Screen(QWidget *parent = 0);
~Screen();
public:
void setPixel(int x, int y, int on);
void setScale(qreal _scale);
public slots:
void update();
};
#endif // SIMSCREEN_H

389
sim/sim-window.cpp Normal file
View file

@ -0,0 +1,389 @@
// ****************************************************************************
// mainwindow.cpp DB48X project
// ****************************************************************************
//
// File Description:
//
// Main window for the DM42 simulator
//
//
//
//
//
//
//
//
// ****************************************************************************
// (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 <QtGui>
#include <QtCore>
#include <QFileDialog>
#include <QFile>
#include <QFileInfo>
#include <QMessageBox>
#include <QKeyEvent>
#include <QStandardPaths>
#include <dmcp.h>
#include <target.h>
#include "sim-window.h"
#include "sim-rpl.h"
#include "ui_sim-window.h"
MainWindow::MainWindow(QWidget *parent)
// ----------------------------------------------------------------------------
// The main window of the simulator
// ----------------------------------------------------------------------------
: QMainWindow(parent), ui(), rpl(this)
{
QCoreApplication::setOrganizationName("DB48X");
QCoreApplication::setApplicationName("DB48X");
ui.setupUi(this);
ui.keyboard->setAttribute(Qt::WA_AcceptTouchEvents);
ui.keyboard->installEventFilter(this);
ui.screen->setAttribute(Qt::WA_AcceptTouchEvents);
ui.screen->installEventFilter(this);
setWindowTitle("DB48X");
qreal dpratio = qApp->primaryScreen()->devicePixelRatio();
resize(210 * dpratio, 390 * dpratio);
// rpl.start();
}
MainWindow::~MainWindow()
// ----------------------------------------------------------------------------
// Destroy the main window
// ----------------------------------------------------------------------------
{
}
void MainWindow::resizeEvent(QResizeEvent * event)
// ----------------------------------------------------------------------------
// Resizing the window
// ----------------------------------------------------------------------------
{
qreal dpratio = qApp->primaryScreen()->devicePixelRatio();
int w = ui.screen->screen_width;
int h = ui.screen->screen_height + 5;
if(!h)
h = LCD_H+5;
if(!w)
w = LCD_W;
qreal dpwidth = event->size().width();
qreal realwidth = dpwidth * dpratio;
qreal scale = realwidth / w;
if((int)scale < 1)
scale = 1.0;
else
scale = (int)scale;
if (event->size().height() * 0.38 * dpratio < scale * h)
{
scale = event->size().height() * 0.38 * dpratio / h;
if ((int) scale < 1)
scale = 1.0;
else
scale = (int) scale;
}
ui.screen->setScale(scale / dpratio);
}
const int keyMap[] =
// ----------------------------------------------------------------------------
// Key map for the DM42
// ----------------------------------------------------------------------------
{
// Actual key mappings are in the relevant platform's target.h
Qt::Key_Tab, KB_ALPHA,
Qt::Key_SysReq, KB_ON,
Qt::Key_Escape, KB_ESC,
Qt::Key_Period, KB_DOT,
Qt::Key_Space, KB_SPC,
Qt::Key_Question, KB_QUESTION,
Qt::Key_Control, KB_SHIFT,
Qt::Key_Alt, KB_LSHIFT,
Qt::Key_Meta, KB_RSHIFT,
Qt::Key_Plus, KB_ADD,
Qt::Key_Minus, KB_SUB,
Qt::Key_Asterisk, KB_MUL,
Qt::Key_Slash, KB_DIV,
Qt::Key_Enter, KB_ENT,
Qt::Key_Return, KB_ENT,
Qt::Key_Backspace, KB_BKS,
Qt::Key_Up, KB_UP,
Qt::Key_Down, KB_DN,
Qt::Key_Left, KB_LF,
Qt::Key_Right, KB_RT,
Qt::Key_F1, KB_F1,
Qt::Key_F2, KB_F2,
Qt::Key_F3, KB_F3,
Qt::Key_F4, KB_F4,
Qt::Key_F5, KB_F5,
Qt::Key_F6, KB_F6,
Qt::Key_0, KB_0,
Qt::Key_1, KB_1,
Qt::Key_2, KB_2,
Qt::Key_3, KB_3,
Qt::Key_4, KB_4,
Qt::Key_5, KB_5,
Qt::Key_6, KB_6,
Qt::Key_7, KB_7,
Qt::Key_8, KB_8,
Qt::Key_9, KB_9,
Qt::Key_A, KB_A,
Qt::Key_B, KB_B,
Qt::Key_C, KB_C,
Qt::Key_D, KB_D,
Qt::Key_E, KB_E,
Qt::Key_F, KB_F,
Qt::Key_G, KB_G,
Qt::Key_H, KB_H,
Qt::Key_I, KB_I,
Qt::Key_J, KB_J,
Qt::Key_K, KB_K,
Qt::Key_L, KB_L,
Qt::Key_M, KB_M,
Qt::Key_N, KB_N,
Qt::Key_O, KB_O,
Qt::Key_P, KB_P,
Qt::Key_Q, KB_Q,
Qt::Key_R, KB_R,
Qt::Key_S, KB_S,
Qt::Key_T, KB_T,
Qt::Key_U, KB_U,
Qt::Key_V, KB_V,
Qt::Key_W, KB_W,
Qt::Key_X, KB_X,
Qt::Key_Y, KB_Y,
Qt::Key_Z, KB_Z,
#ifdef KB_HOME
Qt::Key_Home, KB_HOME,
#endif // KB_HOME
#ifdef KB_HELP
Qt::Key_F11, KB_HELP,
#endif // KB_HELP
0,0
};
struct mousemap
{
int key, keynum;
qreal left, right, top, bot;
} mouseMap[] = {
{ Qt::Key_F1, 38, 0.04, 0.15, 0.03, 0.10 },
{ Qt::Key_F2, 39, 0.20, 0.30, 0.03, 0.10 },
{ Qt::Key_F3, 40, 0.34, 0.46, 0.03, 0.10 },
{ Qt::Key_F4, 41, 0.52, 0.63, 0.03, 0.10 },
{ Qt::Key_F5, 42, 0.68, 0.79, 0.03, 0.10 },
{ Qt::Key_F6, 43, 0.83, 0.94, 0.03, 0.10 },
{ Qt::Key_A, 1, 0.04, 0.15, 0.15, 0.22 },
{ Qt::Key_B, 2, 0.20, 0.30, 0.15, 0.22 },
{ Qt::Key_C, 3, 0.34, 0.46, 0.15, 0.22 },
{ Qt::Key_D, 4, 0.52, 0.63, 0.15, 0.22 },
{ Qt::Key_E, 5, 0.68, 0.79, 0.15, 0.22 },
{ Qt::Key_F, 6, 0.83, 0.94, 0.15, 0.22 },
{ Qt::Key_G, 7, 0.04, 0.15, 0.28, 0.35 },
{ Qt::Key_H, 8, 0.20, 0.30, 0.28, 0.35 },
{ Qt::Key_I, 9, 0.34, 0.46, 0.28, 0.35 },
{ Qt::Key_J, 10, 0.52, 0.63, 0.28, 0.35 },
{ Qt::Key_K, 11, 0.68, 0.79, 0.28, 0.35 },
{ Qt::Key_L, 12, 0.83, 0.94, 0.28, 0.35 },
{ Qt::Key_Return, 13, 0.04, 0.30, 0.40, 0.48 },
{ Qt::Key_M, 14, 0.34, 0.46, 0.40, 0.48 },
{ Qt::Key_N, 15, 0.52, 0.63, 0.40, 0.48 },
{ Qt::Key_O, 16, 0.68, 0.79, 0.40, 0.48 },
{ Qt::Key_Backspace, 17, 0.83, 0.94, 0.40, 0.48 },
{ Qt::Key_Up, 18, 0.04, 0.15, 0.53, 0.59 },
{ Qt::Key_7, 19, 0.23, 0.36, 0.53, 0.59 },
{ Qt::Key_8, 20, 0.42, 0.55, 0.53, 0.59 },
{ Qt::Key_9, 21, 0.62, 0.74, 0.53, 0.59 },
{ Qt::Key_Slash, 22, 0.81, 0.94, 0.53, 0.59 },
{ Qt::Key_Down, 23, 0.04, 0.15, 0.65, 0.72 },
{ Qt::Key_4, 24, 0.23, 0.36, 0.65, 0.72 },
{ Qt::Key_5, 25, 0.42, 0.55, 0.65, 0.72 },
{ Qt::Key_6, 26, 0.62, 0.74, 0.65, 0.72 },
{ Qt::Key_Asterisk, 27, 0.81, 0.94, 0.65, 0.72 },
{ Qt::Key_Control, 28, 0.04, 0.15, 0.77, 0.84 },
{ Qt::Key_1, 29, 0.23, 0.36, 0.77, 0.84 },
{ Qt::Key_2, 30, 0.42, 0.55, 0.77, 0.84 },
{ Qt::Key_3, 31, 0.62, 0.74, 0.77, 0.84 },
{ Qt::Key_Minus, 32, 0.81, 0.94, 0.77, 0.84 },
{ Qt::Key_Escape, 33, 0.04, 0.15, 0.89, 0.97 },
{ Qt::Key_0, 34, 0.23, 0.36, 0.89, 0.97 },
{ Qt::Key_Period, 35, 0.42, 0.55, 0.89, 0.97 },
{ Qt::Key_Question, 36, 0.62, 0.74, 0.89, 0.97 },
{ Qt::Key_Plus, 37, 0.81, 0.94, 0.89, 0.97 },
{ 0, 0, 0.0, 0.0, 0.0, 0.0}
};
void MainWindow::keyPressEvent(QKeyEvent * ev)
// ----------------------------------------------------------------------------
// Got a key - Push it to the simulator
// ----------------------------------------------------------------------------
{
if (ev->isAutoRepeat())
{
ev->accept();
return;
}
for (int i = 0; keyMap[i] != 0; i += 2)
{
if (ev->key() == keyMap[i])
{
key_push(keyMap[i+1]);
ev->accept();
return;
}
}
QMainWindow::keyPressEvent(ev);
}
void MainWindow::keyReleaseEvent(QKeyEvent * ev)
// ----------------------------------------------------------------------------
// Released a key - Send a 0 to the simulator
// ----------------------------------------------------------------------------
{
if(ev->isAutoRepeat()) {
ev->accept();
return;
}
int mykey = ev->key();
for (int i = 0; keyMap[i] != 0; i += 2)
{
if (mykey == keyMap[i])
{
key_push(0);
ev->accept();
return;
}
}
QMainWindow::keyReleaseEvent(ev);
}
bool MainWindow::eventFilter(QObject * obj, QEvent * ev)
// ----------------------------------------------------------------------------
// Filter mouse / keyboard events
// ----------------------------------------------------------------------------
{
if(obj == ui.keyboard) {
if ((ev->type() == QEvent::TouchBegin) ||
(ev->type() == QEvent::TouchUpdate) ||
(ev->type() == QEvent::TouchEnd) ||
(ev->type() == QEvent::TouchCancel))
{
QTouchEvent *me = static_cast < QTouchEvent * >(ev);
int k, pressed;
#if QT_VERSION < 0x060000
auto &touchPoints = me->touchPoints();
#else
auto &touchPoints = me->points();
#endif // Qt version 6
qsizetype npoints = touchPoints.count();
for(k = 0; k < npoints; ++k) {
#if QT_VERSION < 0x060000
QPointF coordinates = touchPoints.at(k).startPos();
#else
QPointF coordinates = touchPoints.at(k).pressPosition();
#endif // Qt version 6
qreal relx, rely;
if(touchPoints.at(k).state() & Qt::TouchPointPressed)
pressed = 1;
else if(touchPoints.at(k).
state() & Qt::TouchPointReleased)
pressed = 0;
else
continue; // NOT INTERESTED IN DRAGGING
relx = coordinates.x() / (qreal) ui.keyboard->width();
rely = coordinates.y() / (qreal) ui.keyboard->height();
if (!pressed)
key_push(0);
else
for (mousemap *ptr = mouseMap; ptr->key; ptr++)
if ((relx >= ptr->left) && (relx <= ptr->right) &&
(rely >= ptr->top) && (rely <= ptr->bot))
key_push(ptr->keynum);
}
return true;
}
if (ev->type() == QEvent::MouseButtonPress)
{
QMouseEvent *me = static_cast < QMouseEvent * >(ev);
#if QT_VERSION < 0x060000
qreal relx = (qreal) me->x() / (qreal) ui.keyboard->width();
qreal rely = (qreal) me->y() / (qreal) ui.keyboard->height();
#else
qreal relx =
(qreal) me->position().x() / (qreal) ui.keyboard->width();
qreal rely =
(qreal) me->position().y() / (qreal) ui.keyboard->height();
#endif // Qt vertsion 6
for (mousemap *ptr = mouseMap; ptr->key; ptr++)
if ((relx >= ptr->left) && (relx <= ptr->right) &&
(rely >= ptr->top) && (rely <= ptr->bot))
key_push(ptr->keynum);
return true;
}
if(ev->type() == QEvent::MouseButtonRelease)
{
key_push(0);
return true;
}
return false;
}
return false;
}

57
sim/sim-window.h Normal file
View file

@ -0,0 +1,57 @@
#ifndef SIM_WINDOW_H
#define SIM_WINDOW_H
// ****************************************************************************
// sim-window.h DB48X project
// ****************************************************************************
//
// File Description:
//
// Main window of the simulator
//
//
//
//
//
//
//
//
// ****************************************************************************
// (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 <QMainWindow>
#include <QFile>
#include "sim-rpl.h"
#include "ui_sim-window.h"
class MainWindow : public QMainWindow
{
Q_OBJECT;
Ui::MainWindow ui;
RPLThread rpl;
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
virtual void keyPressEvent(QKeyEvent *ev);
virtual void keyReleaseEvent(QKeyEvent *ev);
bool eventFilter(QObject *obj, QEvent *ev);
void resizeEvent(QResizeEvent *event);
};
#endif // SIM_WINDOW_H

169
sim/sim-window.ui Normal file
View file

@ -0,0 +1,169 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>583</width>
<height>900</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>:icon.png</normaloff>:icon.png</iconset>
</property>
<widget class="QWidget" name="centralWidget">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background: black;</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="Screen" name="screen">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>66</width>
<height>46</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1056</width>
<height>728</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="keyboard">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>116</width>
<height>175</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="baseSize">
<size>
<width>464</width>
<height>700</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">border-image: url(:/bitmap/keyboard.png) 0 0 0 0 stretch stretch;
border-width: 0px;</string>
</property>
<property name="text">
<string>My Button</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="acceptButton">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QTreeView" name="fileList"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>Screen</class>
<extends>QGraphicsView</extends>
<header>sim-screen.h</header>
<slots>
<slot>setScreenSize(int,int)</slot>
</slots>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

5
sim/sim.qrc Normal file
View file

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/bitmap">
<file alias="keyboard.png">keyboard-dm42.png</file>
</qresource>
</RCC>

67
sim/simulator.pro Normal file
View file

@ -0,0 +1,67 @@
#******************************************************************************
# simulator.pri DB48X project
#******************************************************************************
#
# File Description:
#
# Configurations specific to a simulator build
#
#
#
#
#
#
#
#
#******************************************************************************
# (C) 2022 Christophe de Dinechin <christophe@dinechin.org>
# (C) 2022 Claudio Lapilli and the newRPL team
# This software is licensed under the terms described in LICENSE.txt
#******************************************************************************
QT += core gui quick widgets quickcontrols2 quickwidgets
TEMPLATE = app
CONFIG += debug
# Qt support code
SOURCES += \
sim-main.cpp \
sim-window.cpp \
sim-screen.cpp \
sim-rpl.cpp \
dmcp.cpp \
../src/object.cc \
../src/integer.cc \
../src/runtime.cc \
../src/menu.cc \
../src/main.cc \
../src/rplstring.cc
HEADERS += \
sim-window.h \
sim-screen.h \
sim-rpl.h
# User interface forms
FORMS += sim-window.ui
RESOURCES += sim.qrc
DEFINES += __packed= _WCHAR_T_DEFINED
DEFINES += DECIMAL_CALL_BY_REFERENCE \
DECIMAL_GLOBAL_ROUNDING \
DECIMAL_GLOBAL_ROUNDING_ACCESS_FUNCTIONS \
DECIMAL_GLOBAL_EXCEPTION_FLAGS \
DECIMAL_GLOBAL_EXCEPTION_FLAGS_ACCESS_FUNCTIONS
# Additional external library HIDAPI linked statically into the code
INCLUDEPATH += ../src ../inc
LIBS += libbid.a
win32: LIBS += -lsetupapi
android: LIBS +=
freebsd: LIBS += -lthr -liconv
macx: LIBS += -framework CoreFoundation -framework IOKit

169
sim/target.h Normal file
View file

@ -0,0 +1,169 @@
#ifndef TARGET_DM42_H
#define TARGET_DM42_H
// ****************************************************************************
// target.h BD48X project
// ****************************************************************************
//
// File Description:
//
// DM42 parameters
//
//
//
//
//
//
//
//
// ****************************************************************************
// (C) 2022 Christophe de Dinechin <christophe@dinechin.org>
// (C) 2014-2020 Claudio Lapilli and the newRPL Team
// This software is licensed under the terms outlined in LICENSE.txt
// ****************************************************************************
#include <stdint.h>
// Screen size
#define LCD_W 400
#define LCD_H 240
#define LCD_SCANLINE 416
#define LCD_H 240
#define SCREEN_BUFFERS 2
// Soft menu tab size
#define MENU_TAB_SPACE 1
#define MENU_TAB_INSET 2
#define MENU_TAB_WIDTH ((LCD_W - 5 * MENU_TAB_SPACE) / 6)
#define MENU_TAB_HEIGHT (FONT_HEIGHT(FONT_MENU) + 2 * MENU_TAB_INSET)
/*
KEYBOARD BIT MAP
----------------
This is the bit number in the 64-bit keymatrix.
Bit set means key is pressed.
Note that DMCP does not define keys as bitmaps,
but rather using keycodes.
+--------+--------+--------+--------+--------+--------+
| F1 | F2 | F3 | F4 | F5 | F6 |
| 38 | 39 | 40 | 41 | 42 | 43 |
+--------+--------+--------+--------+--------+--------+
S | Sum- | y^x | x^2 | 10^x | e^x | GTO |
| Sum+ | 1/x | Sqrt | Log | Ln | XEQ |
| 1 | 2 | 3 | 4 | 5 | 6 |
A | A | B | C | D | E | F |
+--------+--------+--------+--------+--------+--------+
S | Complx | % | Pi | ASIN | ACOS | ATAN |
| STO | RCL | R_dwn | SIN | COS | TAN |
| 7 | 8 | 9 | 10 | 11 | 12 |
A | G | H | I | J | K | L |
+--------+--------+--------+--------+--------+--------+
S | Alpha | Last x | MODES | DISP | CLEAR |
| ENTER | x<>y | +/- | E | <-- |
| 13 | 14 | 15 | 16 | 17 |
A | | M | N | O | |
+--------+--------+-+------+----+---+-------++--------+
S | BST | Solver | Int f(x) | Matrix | STAT |
| Up | 7 | 8 | 9 | / |
| 18 | 19 | 20 | 21 | 22 |
A | | P | Q | R | S |
+--------+----------+-----------+-----------+---------+
S | SST | BASE | CONVERT | FLAGS | PROB |
| Down | 4 | 5 | 6 | x |
| 23 | 24 | 25 | 26 | 27 |
A | | T | U | V | W |
+--------+----------+-----------+-----------+---------+
S | | ASSIGN | CUSTOM | PGM.FCN | PRINT |
| SHIFT | 1 | 2 | 3 | - |
| 28 | 29 | 30 | 31 | 32 |
A | | X | Y | Z | - |
+--------+----------+-----------+-----------+---------+
S | OFF | TOP.FCN | SHOW | PRGM | CATALOG |
| EXIT | 0 | . | R/S | + |
| 33 | 34 | 35 | 36 | 37 |
A | | : | . | ? | ' ' |
+--------+----------+-----------+-----------+---------+
*/
#define KB_ALPHA 28 //! Alpha
#define KB_ON 33 //! ON
#define KB_ESC 33 //! Exit
#define KB_DOT 53 //! Dot
#define KB_SPC 36 //! Space
#define KB_RUNSTOP 36 //! R/S
#define KB_QUESTION 36 //! ?
#define KB_SHIFT 28 //! Shift
#define KB_LSHIFT 28 //! Left shift
#define KB_RSHIFT 28 //! Right shift
#define KB_ADD 37 //! +
#define KB_SUB 32 //! -
#define KB_MUL 27 //! *
#define KB_DIV 22 //! /
#define KB_ENT 13 //! ENTER
#define KB_BKS 17 //! backspace
#define KB_UP 18 //! up arrow
#define KB_DN 23 //! down arrow
#define KB_LF 18 //! left arrow
#define KB_RT 23 //! right arrow
#define KB_F1 38 //! Function key 1
#define KB_F2 39 //! Function key 2
#define KB_F3 40 //! Function key 3
#define KB_F4 41 //! Function key 4
#define KB_F5 42 //! Function key 5
#define KB_F6 43 //! Function key 6
#define KB_0 34 //! 0
#define KB_1 29 //! 1
#define KB_2 30 //! 2
#define KB_3 31 //! 3
#define KB_4 24 //! 4
#define KB_5 25 //! 5
#define KB_6 26 //! 6
#define KB_7 19 //! 7
#define KB_8 20 //! 8
#define KB_9 21 //! 9
#define KB_A 1 //! A
#define KB_B 2 //! B
#define KB_C 3 //! C
#define KB_D 4 //! D
#define KB_E 5 //! E
#define KB_F 6 //! F
#define KB_G 7 //! G
#define KB_H 8 //! H
#define KB_I 9 //! I
#define KB_J 10 //! J
#define KB_K 11 //! K
#define KB_L 12 //! L
#define KB_M 14 //! M
#define KB_N 15 //! N
#define KB_O 16 //! O
#define KB_P 19 //! P
#define KB_Q 20 //! Q
#define KB_R 21 //! R
#define KB_S 22 //! S
#define KB_T 24 //! T
#define KB_U 25 //! U
#define KB_V 26 //! V
#define KB_W 27 //! W
#define KB_X 29 //! X
#define KB_Y 30 //! Y
#define KB_Z 31 //! Z
// Prime-specific keys (using their names) all map to 'RCL'
#define KB_APPS 8 //! APPS key (prime only)
#define KB_SYMB 8 //! SYMB key (prime only)
#define KB_HELP 8 //! HELP key (prime only)
#define KB_HOME 8 //! HOME key (prime only)
#define KB_PLOT 8 //! PLOT key (prime only)
#define KB_VIEW 8 //! VIEW key (prime only)
#define KB_CAS 8 //! CAS key (prime only)
#define KB_NUM 8 //! NUM key (prime only)
#define KB_MENU 8 //! MENU key (prime only)
#endif // TARGET_DM42_H

View file

@ -132,7 +132,7 @@ OBJECT_PARSER_BODY(integer)
// Array of values for digits
static byte value[256] = { 0 };
if (!value['A'])
if (!value[(byte) 'A'])
{
// Initialize value array on first use
for (int c = 0; c < 256; c++)
@ -187,6 +187,7 @@ OBJECT_RENDERER_BODY(integer)
// Render the integer into the given string buffer
// ----------------------------------------------------------------------------
{
UNUSED(rt);
return snprintf(begin, end - begin, "%llu", value<ularge>());
}
@ -197,6 +198,7 @@ OBJECT_RENDERER_BODY(neg_integer)
// Render the negative integer value into the given string buffer
// ----------------------------------------------------------------------------
{
UNUSED(rt);
return snprintf(begin, end - begin, "-%llu", value<ularge>());
}
@ -207,6 +209,7 @@ OBJECT_RENDERER_BODY(hex_integer)
// Render the hexadecimal integer value into the given string buffer
// ----------------------------------------------------------------------------
{
UNUSED(rt);
return snprintf(begin, end - begin, "#%llXh", value<ularge>());
}
@ -216,6 +219,7 @@ OBJECT_RENDERER_BODY(oct_integer)
// Render the octal integer value into the given string buffer
// ----------------------------------------------------------------------------
{
UNUSED(rt);
return snprintf(begin, end - begin, "#%lloo", value<ularge>());
}
@ -225,6 +229,7 @@ OBJECT_RENDERER_BODY(dec_integer)
// Render the negative integer value into the given string buffer
// ----------------------------------------------------------------------------
{
UNUSED(rt);
return snprintf(begin, end - begin, "#%llud", value<ularge>());
}
@ -234,6 +239,8 @@ OBJECT_RENDERER_BODY(bin_integer)
// Render the binary integer value into the given string buffer
// ----------------------------------------------------------------------------
{
UNUSED(rt);
// Why is there no printf format for binary?
ularge num = value<ularge>();
char *p = begin;

View file

@ -1,5 +1,5 @@
#ifndef INTEGER_H
#define INTEGER_JH
#define INTEGER_H
// ****************************************************************************
// integer.h DB48X project
// ****************************************************************************

View file

@ -39,13 +39,13 @@
#include <rpl.h>
template <typename T>
inline T max(T x, T y)
template <typename T, typename U>
inline T max(T x, U y)
{
return x > y ? x : y;
}
template <typename T>
inline T min(T x, T y)
template <typename T, typename U>
inline T min(T x, U y)
{
return x < y ? x : y;
}
@ -379,7 +379,8 @@ void disp_annun(int xpos, const char *txt)
const char *ang_mode_ann[ANG_MODE_CNT] = { "[DEG]", "[RAD]", "[GRAD]" };
int lastkey = 0;
int k1 = 0;
int k2 = 0;
static int counter = 0;
@ -407,7 +408,7 @@ void redraw_lcd()
}
char buffer[40];
snprintf(buffer, sizeof(buffer), "Key: %d Cnt=%d", lastkey, counter++);
snprintf(buffer, sizeof(buffer), "Key: %d %d Cnt=%d", k1, k2, counter++);
disp_annun(60, buffer);
t20->newln = 1; // Revert to default
@ -1060,8 +1061,10 @@ extern "C" void program_main()
if (!key_empty())
reset_auto_off();
lastkey = key_tail();
#ifndef __sysfn_read_key
#define __sysfn_read_key read_key
#endif
__sysfn_read_key(&k1, &k2);
redraw_lcd();
sys_delay(200);
@ -1070,11 +1073,6 @@ extern "C" void program_main()
// > 0 -> Key pressed
// == 0 -> Key released
key = key_pop();
lastkey = key;
redraw_lcd();
sys_delay(200);
if (key >= 0)
handle_key(key);

View file

@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <menu.h>
#include <stdio.h>
#include <types.h>
const uint8_t mid_menu[] = {
@ -136,18 +137,19 @@ int run_menu_item(uint8_t line_id) {
}
const char * menu_line_str(uint8_t line_id, char * s, const int slen) {
const char * ln;
const char *menu_line_str(uint8_t line_id, char *s, const int slen)
{
UNUSED(s);
UNUSED(slen);
const char *ln;
switch(line_id) {
switch (line_id)
{
case MI_SETTINGS: ln = "Settings >"; break;
case MI_ABOUT_PGM: ln = "About >"; break;
case MI_SETTINGS: ln = "Settings >"; break;
case MI_ABOUT_PGM: ln = "About >"; break;
default: ln = NULL; break;
}
default:
ln = NULL;
break;
}
return ln;
return ln;
}

View file

@ -102,6 +102,7 @@ OBJECT_RENDERER_BODY(string)
// Render the string into the given string buffer
// ----------------------------------------------------------------------------
{
UNUSED(rt);
size_t len = 0;
cstring txt = text(&len);
return snprintf(begin, end - begin, "%.*s", (int) len, txt);

View file

@ -1,5 +1,5 @@
#ifndef RPLSTRING_H
#define RPLSTRING_JH
#define RPLSTRING_H
// ****************************************************************************
// rplstring.h DB48X project
// ****************************************************************************
@ -46,6 +46,7 @@ struct string : object
static size_t required_memory(id i, utf8 str, size_t len)
{
UNUSED(str);
return leb128size(i) + leb128size(len) + len;
}

View file

@ -56,7 +56,7 @@ struct runtime
// Everything below Temporaries is byte-aligned
// Stack elements point to temporaries, globals or robjects (read-only)
{
runtime(byte *memory = nullptr, size_t size = 0)
runtime(byte *mem = nullptr, size_t size = 0)
: Error(nullptr),
ErrorSource(nullptr),
Code(nullptr),
@ -68,7 +68,9 @@ struct runtime
Returns(),
HighMem(),
GCSafe(nullptr)
{}
{
memory(mem, size);
}
~runtime() {}
void memory(byte *memory, size_t size)
@ -327,7 +329,7 @@ struct runtime
object *safe;
gcptr *next;
friend class runtime;
friend struct runtime;
};
@ -412,6 +414,7 @@ inline void *operator new(size_t size, Obj *where)
// Placement new for objects
// ----------------------------------------------------------------------------
{
UNUSED(size);
return where;
}

View file

@ -47,4 +47,6 @@ typedef const char *cstring;
typedef const char *utf8;
typedef unsigned utf8code;
#define UNUSED(var) ((void *) &(var))
#endif // TYPES_H