diff --git a/.gitignore b/.gitignore index 5761abc..3b39e34 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.o +*.uaem diff --git a/justwindow b/justwindow index 18ec258..30531f5 100755 Binary files a/justwindow and b/justwindow differ diff --git a/justwindow.c b/justwindow.c index 090a826..4495665 100644 --- a/justwindow.c +++ b/justwindow.c @@ -5,7 +5,15 @@ int main(void) { struct Window *window; window = OpenWindowTags(NULL, - WA_Title, "Wow", + WA_Title, "Topaz's Pizza Timer", + WA_Width, 240, + WA_Height, 80, + WA_Top, 20, + WA_Left, 20, + WA_DragBar, TRUE, + WA_DepthGadget, TRUE, + WA_CloseGadget, TRUE, + WA_Activate, TRUE, TAG_END ); diff --git a/justwindow.info b/justwindow.info new file mode 100644 index 0000000..63a58a1 Binary files /dev/null and b/justwindow.info differ diff --git a/main b/main index 828f799..7af7bad 100755 Binary files a/main and b/main differ diff --git a/main.c b/main.c index d44cff4..7d96a78 100644 --- a/main.c +++ b/main.c @@ -17,13 +17,11 @@ #include // handle images and sound -#include +#include #include #include -// timer stuff. using proto/timer.h did not work well, likely -// because of how you have to open the device. -#include +#include // this is the manual for the original intuition stuff. // not much here is different: https://ia801905.us.archive.org/33/items/Amiga_Intuition_Reference_Manaual_1985_Adn-Wesley_Publishing_Company/Amiga_Intuition_Reference_Manaual_1985_Addison-Wesley_Publishing_Company.pdf @@ -80,8 +78,10 @@ struct MenuData { int id; }; -#define MENU_ABOUT_ID 0 -#define MENU_QUIT_ID 1 +// Start this at 1, otherwise not selecting a menu item is the same as +// opening the menu and picking the item with ID 0 +#define MENU_ABOUT_ID 1 +#define MENU_QUIT_ID 2 struct MenuData MENU_ABOUT = { MENU_ABOUT_ID }; struct MenuData MENU_QUIT = { MENU_QUIT_ID }; @@ -98,7 +98,6 @@ struct Menu *menu; // timer stuff #define TIMER_INTERVAL 200000 -struct Device *TimerBase; struct timerequest *TimerIO; struct timeval currentSystemTime; struct MsgPort *timerPort; @@ -176,10 +175,6 @@ int setup(void) { return 0; } - // this allows us to use GetSysTime, rather than performing an IO operation - // to get the current time. - TimerBase = TimerIO->tr_node.io_Device; - if (NULL == (DataTypesBase = OpenLibrary("datatypes.library", 40))) { // this is ok, we just won't play sound printf("no sound!"); @@ -200,7 +195,6 @@ void teardown(void) { FreeSignal(waitForSoundSignalNumber); } if (TimerIO) { - CloseDevice((struct IORequest *)TimerIO); DeleteExtIO((struct IORequest *)TimerIO); } if (timerPort) { @@ -390,13 +384,21 @@ void setTimerText(void) { * Ask the timer to send a message to our message port * after a defined number of milliseconds. */ -void startTimer(void) { +int startTimer(void) { + // TODO: handle timer.device not being available + if (0 != (OpenDevice(TIMERNAME, UNIT_MICROHZ, (struct IORequest *)TimerIO, 0L))) { + printf("Unable to open timer!"); + return 1; + } + TimerIO->tr_node.io_Command = TR_ADDREQUEST; TimerIO->tr_time.tv_secs = 0; TimerIO->tr_time.tv_micro = TIMER_INTERVAL; // SendIO is async, it doesn't wait for the IO to complete before continuing SendIO((struct IORequest *)TimerIO); + + CloseDevice((struct IORequest *)TimerIO); } /** @@ -422,6 +424,26 @@ void clearUI(void) { FreeGadgets(windowGadgets); } +/** + * Get the current system time. + */ +int getSysTime(void) { + struct Device* TimerBase; + + if (0 != (OpenDevice(TIMERNAME, UNIT_MICROHZ, (struct IORequest *)TimerIO, 0L))) { + printf("Unable to open timer!"); + return 1; + } + + TimerBase = TimerIO->tr_node.io_Device; + + GetSysTime(¤tSystemTime); + + CloseDevice((struct IORequest *)TimerIO); + + return 0; +} + /** * Toggle the timer between started and stopped. */ @@ -429,8 +451,8 @@ void handleToggleTimer(void) { timerIsRunning = !timerIsRunning; if (timerIsRunning) { - // http://amigadev.elowar.com/read/ADCD_2.1/Includes_and_Autodocs_2._guide/node04FA.html - GetSysTime(¤tSystemTime); + // TODO: handle timer.device not being available + getSysTime(); // timers are microsecond resolution timerStartTime = currentSystemTime.tv_secs * 1000000 + currentSystemTime.tv_micro; @@ -774,7 +796,8 @@ void endTimer(void) { } void handleTimerMessage(void) { - GetSysTime(¤tSystemTime); + // TODO: handle timer.device not being available + getSysTime(); timerDistance = ((currentSystemTime.tv_secs * 1000000 + currentSystemTime.tv_micro) - timerStartTime) / 1000000; timerBuild = (originalUiHours * 3600 + originalUiMinutes * 60 + originalUiSeconds) - timerDistance; diff --git a/main.info b/main.info new file mode 100644 index 0000000..35e5509 Binary files /dev/null and b/main.info differ