Improved thread termination on PC target.

This commit is contained in:
user 2015-08-18 10:02:33 -04:00
parent 9620c5420e
commit 6553ecd1a7
11 changed files with 103 additions and 11 deletions

View file

@ -197,6 +197,13 @@ void ggl_monohbltoper(int *dest,int destoff,unsigned char *src,int srcoff, int n
dstart=dest+(destoff>>3);
dend=dest+((destoff+npixels-1)>>3);
#ifndef NDEBUG
if( (dstart<dest)||(dend>dest+2048)) {
return;
}
#endif
if(dstart==dend) {
// single word operation
ml|=mr;

View file

@ -11,12 +11,29 @@ void ggl_hline(gglsurface *srf,int y,int xl,int xr, int color)
// RESTRICTIONS: xr>=xl
// y MUST BE VALID
int loff=(y*srf->width+xl);
int roff=(y*srf->width+xr);
register int *left=(int *)srf->addr+ (loff>>3);
register int *right=(int *)srf->addr+ (roff>>3);
int ml=ggl_leftmask(loff),mr=ggl_rightmask(roff);
#ifndef NDEBUG
if( (left<srf->addr)||(right>srf->addr+2048)) {
// BAD EXCEPTION
return;
}
#endif
if(left==right) {
// single word operation
ml|=mr;

View file

@ -1709,6 +1709,7 @@ void halOuterLoop()
ggl_initscr(&scr);
do {
halRedrawAll(&scr);
if(halExitOuterLoop()) break;
keymsg=halWaitForKey();
halSetBusyHandler();
} while(!halProcessKey(keymsg));

View file

@ -1097,6 +1097,9 @@ extern HEVENT halBusyEvent;
void halSetBusyHandler();
void halEnterPowerOff();
// IF THIS FUNCTION RETURNS TRUE, TERMINATE THE OUTER LOOP
int halExitOuterLoop();
// TIMER FUNCTIONS
BINT64 halTicks();

View file

@ -1,6 +1,10 @@
#include <newrpl.h>
#include <ui.h>
extern int __pc_terminate;
void setup_hardware()
{
// SETUP HARDWARE
@ -61,7 +65,6 @@ void clear_globals()
// TODO: DO THIS MANUALLY ON THE PC
}
@ -71,6 +74,10 @@ void startup()
// BOOTLOADER LEAVES STACK ON MAIN RAM, MOVE TO SRAM
// ALSO WE ENTER IN SUPERVISOR MODE
// CLEAR THE REQUEST TO TERMINATE THE THREAD
__pc_terminate=0;
setup_hardware(); // SETUP ACCESS TO OUT-OF-CHIP RAM MEMORY AMONG OTHER THINGS, THIS IS DONE BY THE BOOTLOADER BUT JUST TO BE SURE
clear_globals(); // CLEAR TO ZERO ALL NON-PERSISTENT GLOBALS
@ -137,3 +144,8 @@ void halEnterPowerOff()
exit(0);
}
int halExitOuterLoop()
{
return __pc_terminate;
}

View file

@ -26,7 +26,8 @@ extern int __keyb_repeattime,__keyb_longpresstime __SYSTEM_GLOBAL__,__keyb_debou
// QT-BASED KEYBOARD MESSAGES MUST UPDATE THIS MATRIX;
volatile keymatrix __pckeymatrix;
// QT-BASED TERMINATE MESSAGE COMES IN THIS VARIABLE
volatile int __pc_terminate;

View file

@ -73,10 +73,10 @@ int lcd_setmode(int mode, unsigned int *physbuf)
int /*height=(lcdreg[3])>>8,*/ pagewidth=LCD_W>>(4-mode);
__lcd_mode=mode;
__lcd_buffer=physbuf;
// TODO: POINT THE QT SCREEN INTO THE GIVEN BUFFER
lcd_setcontrast(__lcd_contrast);
__lcd_mode=mode;
return pagewidth<<1;
}

View file

@ -1,10 +1,19 @@
#include <QtGui>
#include <QtCore>
#include <QFileDialog>
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow *myMainWindow;
extern unsigned long long __pckeymatrix;
extern int __pc_terminate;
extern "C" void __keyb_update();
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
rpl(this),
@ -15,22 +24,40 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this);
screentmr=new QTimer(this);
ui->EmuScreen->connect(screentmr,SIGNAL(timeout()),ui->EmuScreen,SLOT(update()));
screentmr->start(50);
maintmr=new QTimer(this);
connect(maintmr,SIGNAL(timeout()),this,SLOT(domaintimer()));
maintmr->start(1);
rpl.start();
maintmr->start(1);
screentmr->start(50);
}
MainWindow::~MainWindow()
{
screentmr->stop();
delete maintmr;
delete screentmr;
delete ui;
}
void MainWindow::closeEvent(QCloseEvent *event)
{
maintmr->stop();
screentmr->stop();
if(rpl.isRunning()) {
__pc_terminate=1;
__pckeymatrix^=(1ULL<<63);
__keyb_update();
while(rpl.isRunning());
}
event->accept();
}
void MainWindow::on_EmuScreen_destroyed()
{
if(rpl.isRunning()) rpl.terminate();
@ -193,9 +220,6 @@ const int keyMap[] = {
extern unsigned long long __pckeymatrix;
extern "C" void __keyb_update();
void MainWindow::keyPressEvent(QKeyEvent *ev)
{
@ -256,3 +280,26 @@ extern "C" void thread_processevents()
{
QCoreApplication::processEvents();
}
void MainWindow::on_actionExit_triggered()
{
maintmr->stop();
screentmr->stop();
if(rpl.isRunning()) {
__pc_terminate=1;
__pckeymatrix^=(1ULL<<63);
__keyb_update();
while(rpl.isRunning());
}
}
void MainWindow::on_actionSave_triggered()
{
// STOP THE RPL ENGINE AND SAVE ITS CONTENTS
QString fname=QFileDialog::getSaveFileName(this,"Select File Name",QString(),"*.nrpl");
}

View file

@ -19,9 +19,14 @@ public:
protected:
virtual void keyPressEvent(QKeyEvent *ev);
virtual void keyReleaseEvent(QKeyEvent *ev);
void closeEvent(QCloseEvent *event);
private slots:
void on_EmuScreen_destroyed();
void on_actionExit_triggered();
void on_actionSave_triggered();
public slots:
void domaintimer();
private:

View file

@ -30,7 +30,7 @@
<x>0</x>
<y>0</y>
<width>659</width>
<height>21</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">

View file

@ -20,5 +20,4 @@ void RPLThread::run()
extern "C" void thread_yield()
{
QThread::msleep(1);
QThread::yieldCurrentThread();
}