65816-llvm-mos/demos/frame.c
2026-05-18 14:43:35 -05:00

97 lines
2.4 KiB
C

// frame.c - full port of ORCA-C's Frame.cc sample.
//
// Mike Westerfield's "Frame" desktop demo (Byte Works, 1989).
// Original at tools/orca-c/C.Samples/Desktop.Samples/Frame.cc.
//
// Uses the real ROM Menu Manager — startdesk's QD-DP allocation now
// reserves the full 512 bytes QD needs (own DP + cursor mgr at +$100),
// plus calls InitCursor. See feedback_drawmenubar_hang.md.
#include "iigs/toolbox.h"
#include "iigs/desktop.h"
#define apple_About 257
#define file_Quit 256
typedef struct { short v1, h1, v2, h2; } Rect;
// Menu definition strings — verbatim from Frame.cc.
static unsigned char appleMenuStr[] =
">>@\\XN1\r"
"--About Frame\\N257V\r"
".\r";
static unsigned char fileMenuStr[] =
">> File \\N2\r"
"--Close\\N255V\r"
"--Quit\\N256*Qq\r"
".\r";
static unsigned char editMenuStr[] =
">> Edit \\N3\r"
"--Undo\\N250V*Zz\r"
"--Cut\\N251*Xx\r"
"--Copy\\N252*Cc\r"
"--Paste\\N253*Vv\r"
"--Clear\\N254\r"
".\r";
// About-box message lines.
static const unsigned char line1[] = "\x09" "Frame 1.0";
static const unsigned char line2[] = "\x0e" "Copyright 1989";
static const unsigned char line3[] = "\x10" "Byte Works, Inc.";
static const unsigned char line4[] = "\x13" "By Mike Westerfield";
static const unsigned char btnOk[] = "\x02" "OK";
static void drawAbout(void) {
Rect outer;
outer.h1 = 180; outer.v1 = 50;
outer.h2 = 460; outer.v2 = 107;
SetSolidPenPat(15);
PaintRect(&outer);
SetSolidPenPat(0);
FrameRect(&outer);
MoveTo(195, 64); DrawString((void *)line1);
MoveTo(195, 74); DrawString((void *)line2);
MoveTo(195, 84); DrawString((void *)line3);
MoveTo(195, 94); DrawString((void *)line4);
Rect ok;
ok.h1 = 395; ok.v1 = 88;
ok.h2 = 445; ok.v2 = 102;
FrameRect(&ok);
MoveTo(412, 98);
DrawString((void *)btnOk);
}
static void initMenus(void) {
InsertMenu(NewMenu(editMenuStr), 0);
InsertMenu(NewMenu(fileMenuStr), 0);
InsertMenu(NewMenu(appleMenuStr), 0);
FixAppleMenu(1);
FixMenuBar();
DrawMenuBar();
}
int main(void) {
unsigned short userId = startdesk(640);
(void)userId;
initMenus();
ShowCursor();
for (volatile unsigned long s = 0; s < 100000UL; s++) { }
drawAbout();
for (volatile unsigned long s = 0; s < 200000UL; s++) { }
*(volatile unsigned char *)0x70 = 0x99;
return 0;
}