Add some basic infrastructure and test receiving and sending key events. Need to add a state machine for the network code next.

This commit is contained in:
Jeremy Rand 2021-07-19 00:01:10 -04:00
parent 41862eaeb1
commit 11bb312be8
2 changed files with 59 additions and 6 deletions

View File

@ -8,7 +8,7 @@
*/ */
#pragma nda NDAOpen NDAClose NDAAction NDAInit -1 0x03FF " Listener\\H**" #pragma nda NDAOpen NDAClose NDAAction NDAInit 5 0x03FF " Listener\\H**"
#include <orca.h> #include <orca.h>
@ -21,14 +21,21 @@
#include <MiscTool.h> #include <MiscTool.h>
#include <Memory.h> #include <Memory.h>
#include <Loader.h> #include <Loader.h>
#include <tcpip.h>
#include <string.h>
#include "main.h" #include "main.h"
static BOOLEAN ndaActive; static BOOLEAN ndaActive = FALSE;
static GrafPortPtr winPtr; static GrafPortPtr winPtr = NULL;
static unsigned int userId; static unsigned int userId;
static char line1[50];
static char line2[50];
static char line3[50];
void NDAClose(void) void NDAClose(void)
{ {
@ -47,7 +54,9 @@ void NDAInit(int code)
/* When code is 1, this is tool startup, otherwise tool /* When code is 1, this is tool startup, otherwise tool
* shutdown. * shutdown.
*/ */
strcpy(line1, "Hello, world!");
strcpy(line2, "Hello, world!");
strcpy(line3, "Hello, world!");
if (code) { if (code) {
ndaActive = FALSE; ndaActive = FALSE;
userId = MMStartUp(); userId = MMStartUp();
@ -61,9 +70,21 @@ void NDAInit(int code)
#pragma databank 1 #pragma databank 1
void DrawContents(void) void DrawContents(void)
{ {
Rect frame;
GetPortRect(&frame);
frame.v2 -= frame.v1;
frame.h2 -= frame.h1;
frame.h1 = 0;
frame.v1 = 0;
EraseRect(&frame);
PenNormal(); PenNormal();
MoveTo(7,10); MoveTo(7,10);
DrawCString("Hello, world!"); DrawCString(line1);
MoveTo(7,20);
DrawCString(line2);
MoveTo(7,30);
DrawCString(line3);
} }
#pragma databank 0 #pragma databank 0
@ -115,6 +136,19 @@ GrafPortPtr NDAOpen(void)
void HandleRun(void) void HandleRun(void)
{ {
static BOOLEAN keySent = FALSE;
if (winPtr == NULL)
return;
if (winPtr == FrontWindow())
return;
if (keySent)
return;
PostEvent(keyDownEvt, 0x00C0004A);
keySent = TRUE;
} }
@ -123,8 +157,27 @@ void HandleControl(EventRecord *event)
} }
void InvalidateWindow(void)
{
Rect frame;
SetPort(winPtr);
GetPortRect(&frame);
frame.v2 -= frame.v1;
frame.h2 -= frame.h1;
frame.h1 = 0;
frame.v1 = 0;
InvalRect(&frame);
}
void HandleKey(EventRecord *event) void HandleKey(EventRecord *event)
{ {
if (winPtr != NULL) {
sprintf(line1, "what = $%X", event->what);
sprintf(line2, "message = $%lX", event->message);
sprintf(line3, "modifiers = $%X", event->modifiers);
InvalidateWindow();
}
} }

View File

@ -39,7 +39,7 @@ resource rWindParam1 (windowRes) {
{0,0}, /* page ver horiz */ {0,0}, /* page ver horiz */
0, /* winfoRefcon */ 0, /* winfoRefcon */
0, /* wInfoHeight */ 0, /* wInfoHeight */
{50,50,62,200}, /* wposition */ {50,10,86,310}, /* wposition */
infront, /* wPlane */ infront, /* wPlane */
nil, /* wStorage */ nil, /* wStorage */
$0800 /* wInVerb */ $0800 /* wInVerb */