2020-03-04 13:09:40 +00:00
|
|
|
int fence;
|
2020-03-22 13:03:34 +00:00
|
|
|
|
2020-02-29 15:40:55 +00:00
|
|
|
#include <AutoreleasePool.h>
|
2020-03-22 13:03:34 +00:00
|
|
|
#include <key.h>
|
2020-02-29 15:40:55 +00:00
|
|
|
|
2020-03-29 17:34:08 +00:00
|
|
|
#include "ui/color.h"
|
|
|
|
#include "ui/curses.h"
|
|
|
|
#include "ui/group.h"
|
|
|
|
#include "ui/view.h"
|
|
|
|
#include "debugger/debugger.h"
|
2020-02-29 15:40:55 +00:00
|
|
|
#include "qwaq-app.h"
|
|
|
|
|
2020-03-26 00:01:39 +00:00
|
|
|
int color_palette[64];
|
|
|
|
|
2020-02-29 15:40:55 +00:00
|
|
|
static AutoreleasePool *autorelease_pool;
|
|
|
|
static void
|
|
|
|
arp_start (void)
|
|
|
|
{
|
|
|
|
autorelease_pool = [[AutoreleasePool alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
arp_end (void)
|
|
|
|
{
|
|
|
|
[autorelease_pool release];
|
|
|
|
autorelease_pool = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@implementation QwaqApplication
|
|
|
|
+app
|
|
|
|
{
|
|
|
|
return [[[self alloc] init] autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
-init
|
|
|
|
{
|
|
|
|
if (!(self = [super init])) {
|
|
|
|
return nil;
|
|
|
|
}
|
2020-03-05 15:32:09 +00:00
|
|
|
|
2020-02-29 15:40:55 +00:00
|
|
|
initialize ();
|
2020-03-26 00:01:39 +00:00
|
|
|
for (int i = 1; i < 64; i++) {
|
|
|
|
init_pair (i, i & 0x7, i >> 3);
|
|
|
|
color_palette[i] = COLOR_PAIR (i);
|
|
|
|
}
|
2020-03-05 15:32:09 +00:00
|
|
|
|
2020-03-19 09:41:53 +00:00
|
|
|
screen = [TextContext screen];
|
2020-03-23 11:14:32 +00:00
|
|
|
screenSize = [screen size];
|
2020-03-30 07:30:58 +00:00
|
|
|
objects = [[Group withContext: screen owner: nil] retain];
|
2020-03-14 10:45:07 +00:00
|
|
|
|
2020-03-26 00:01:39 +00:00
|
|
|
[screen bkgd: color_palette[047]];
|
2020-03-22 13:03:34 +00:00
|
|
|
[screen scrollok: 1];
|
2020-03-24 16:06:20 +00:00
|
|
|
[screen clear];
|
|
|
|
wrefresh (stdscr);//FIXME
|
2020-03-24 16:32:52 +00:00
|
|
|
|
|
|
|
debuggers = [[Array array] retain];
|
2020-02-29 15:40:55 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-24 16:06:20 +00:00
|
|
|
-(Extent)size
|
2020-02-29 15:40:55 +00:00
|
|
|
{
|
2020-03-24 16:06:20 +00:00
|
|
|
return screenSize;
|
|
|
|
}
|
2020-02-27 12:01:09 +00:00
|
|
|
|
2020-03-24 16:06:20 +00:00
|
|
|
-(TextContext *)screen
|
|
|
|
{
|
|
|
|
return screen;
|
2020-02-29 15:40:55 +00:00
|
|
|
}
|
|
|
|
|
2020-03-12 17:43:01 +00:00
|
|
|
-draw
|
|
|
|
{
|
2020-03-14 10:45:07 +00:00
|
|
|
[objects draw];
|
2020-03-12 17:43:01 +00:00
|
|
|
[TextContext refresh];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-24 16:32:52 +00:00
|
|
|
-(Debugger *)find_debugger:(qdb_target_t) target
|
2020-02-29 15:40:55 +00:00
|
|
|
{
|
2020-03-24 16:32:52 +00:00
|
|
|
Debugger *debugger;
|
|
|
|
|
|
|
|
for (int i = [debuggers count]; i-- > 0; ) {
|
|
|
|
debugger = [debuggers objectAtIndex: i];
|
2020-03-30 03:43:02 +00:00
|
|
|
if ([debugger target].handle == target.handle) {
|
2020-03-24 16:32:52 +00:00
|
|
|
return debugger;
|
|
|
|
}
|
2020-03-23 11:14:32 +00:00
|
|
|
}
|
2020-03-30 07:30:58 +00:00
|
|
|
debugger = [Debugger withTarget: target];
|
2020-03-24 16:32:52 +00:00
|
|
|
[debuggers addObject: debugger];
|
|
|
|
return debugger;
|
|
|
|
}
|
|
|
|
|
|
|
|
-handleEvent: (qwaq_event_t *) event
|
|
|
|
{
|
|
|
|
switch (event.what) {
|
|
|
|
case qe_resize:
|
|
|
|
Extent delta;
|
|
|
|
delta.width = event.resize.width - screenSize.width;
|
|
|
|
delta.height = event.resize.height - screenSize.height;
|
|
|
|
|
|
|
|
resizeterm (event.resize.width, event.resize.height);
|
|
|
|
[screen resizeTo: {event.resize.width, event.resize.height}];
|
|
|
|
screenSize = [screen size];
|
|
|
|
[objects resize: delta];
|
|
|
|
[screen refresh];
|
|
|
|
event.what = qe_none;
|
|
|
|
break;
|
|
|
|
case qe_key:
|
|
|
|
if (event.key.code == '\x18' || event.key.code == '\x11') {
|
|
|
|
endState = event.message.int_val;
|
|
|
|
event.what = qe_none;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case qe_debug_event:
|
|
|
|
[[self find_debugger:{event.message.int_val}] handleDebugEvent];
|
|
|
|
event.what = qe_none;
|
|
|
|
break;
|
2020-02-29 15:40:55 +00:00
|
|
|
}
|
2020-03-24 16:32:52 +00:00
|
|
|
if (event.what != qe_none) {
|
|
|
|
[objects handleEvent: event];
|
2020-02-29 15:40:55 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
2020-03-24 16:06:20 +00:00
|
|
|
|
|
|
|
-run
|
|
|
|
{
|
|
|
|
[objects takeFocus];
|
|
|
|
[self draw];
|
|
|
|
do {
|
|
|
|
arp_start ();
|
|
|
|
|
|
|
|
get_event (&event);
|
|
|
|
if (event.what != qe_none) {
|
|
|
|
[self handleEvent: &event];
|
|
|
|
}
|
|
|
|
|
|
|
|
arp_end ();
|
|
|
|
} while (!endState);
|
|
|
|
return self;
|
|
|
|
}
|
2020-03-24 16:32:52 +00:00
|
|
|
|
|
|
|
-addView:(View *)view
|
|
|
|
{
|
|
|
|
[objects insertSelected: view];
|
|
|
|
[screen refresh];
|
|
|
|
return self;
|
|
|
|
}
|
2020-02-29 15:40:55 +00:00
|
|
|
@end
|
|
|
|
|
2020-03-24 16:06:20 +00:00
|
|
|
QwaqApplication *application;
|
|
|
|
|
2020-02-29 15:40:55 +00:00
|
|
|
int main (int argc, string *argv)
|
|
|
|
{
|
2020-03-04 13:09:40 +00:00
|
|
|
fence = 0;
|
|
|
|
//while (!fence) {}
|
|
|
|
|
2020-03-30 07:30:58 +00:00
|
|
|
arp_start ();
|
2020-03-24 16:06:20 +00:00
|
|
|
application = [[QwaqApplication app] retain];
|
2020-03-30 07:30:58 +00:00
|
|
|
arp_end ();
|
2020-02-29 15:40:55 +00:00
|
|
|
|
2020-03-24 16:06:20 +00:00
|
|
|
[application run];
|
|
|
|
[application release];
|
2020-02-29 15:40:55 +00:00
|
|
|
qwaq_event_t event;
|
|
|
|
get_event (&event); // XXX need a "wait for queue idle"
|
2020-03-30 07:30:58 +00:00
|
|
|
|
2020-02-29 15:40:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|