1
0
Fork 0

way better timer handling logic and headers usage

This commit is contained in:
John Bintz 2022-11-25 09:22:57 -05:00
parent dc7982e71c
commit d9faf6bba4
7 changed files with 49 additions and 17 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
*.o
*.uaem

Binary file not shown.

View File

@ -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
);

BIN
justwindow.info Normal file

Binary file not shown.

BIN
main

Binary file not shown.

55
main.c
View File

@ -17,13 +17,11 @@
#include <proto/diskfont.h>
// handle images and sound
#include <clib/datatypes_protos.h>
#include <proto/datatypes.h>
#include <datatypes/datatypesclass.h>
#include <datatypes/soundclass.h>
// timer stuff. using proto/timer.h did not work well, likely
// because of how you have to open the device.
#include <clib/timer_protos.h>
#include <proto/timer.h>
// 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(&currentSystemTime);
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(&currentSystemTime);
// 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(&currentSystemTime);
// 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;

BIN
main.info Normal file

Binary file not shown.