/*
clock.c original C code by Thomas Rapp
clock.e by ghh 2022
*/
OPT PREPROCESS
/*--------------------------------------------------------------------------*/
/* System Includes */
/*--------------------------------------------------------------------------*/
MODULE 'intuition/intuition','intuition/screens'
MODULE 'utility/tagitem','dos/dos','dos/datetime'
MODULE 'graphics/rastport'
MODULE 'devices/timer'
MODULE 'exec/io','exec/ports'
/*--------------------------------------------------------------------------*/
/* Open timer.device */
/*--------------------------------------------------------------------------*/
PROC open_timer(unit)
DEF port:PTR TO mp /* struct MsgPort */
DEF req:PTR TO timerequest
IF (port:= CreateMsgPort())
IF (req:= CreateIORequest(port,SIZEOF timerequest))
IF (OpenDevice('timer.device',unit,req,0)) = NIL
RETURN (req)
ENDIF
DeleteIORequest (req)
ENDIF
DeleteMsgPort (port)
ENDIF
ENDPROC NIL
/*--------------------------------------------------------------------------*/
/* Close timer.device */
/*--------------------------------------------------------------------------*/
PROC close_timer(req:PTR TO timerequest)
DEF port:PTR TO mp /* struct MsgPort */
IF (req)
CloseDevice(req)
port:= req.io.mn.replyport
DeleteIORequest(req)
DeleteMsgPort(port)
ENDIF
ENDPROC
/*--------------------------------------------------------------------------*/
/* Start timer */
/*--------------------------------------------------------------------------*/
PROC start_timer(req:PTR TO timerequest,secs,micro)
IF (req)
req.io.command:= TR_ADDREQUEST
req.time.secs:= secs
req.time.micro:= micro
SendIO(req)
ENDIF
ENDPROC
/*--------------------------------------------------------------------------*/
/* Abort timer */
/*--------------------------------------------------------------------------*/
PROC stop_timer(req:PTR TO timerequest)
IF (req)
IF (CheckIO(req)) = NIL THEN
AbortIO(req)
WaitIO (req)
ENDIF
ENDPROC
/*--------------------------------------------------------------------------*/
/* Wait for timer (also used to clean up an async request which has ended) */
/*--------------------------------------------------------------------------*/
#define wait_timer(req) WaitIO(req)
/*----------------------------------------------------------------------------*/
/* Main program */
/*----------------------------------------------------------------------------*/
PROC main()
DEF scr:PTR TO screen
DEF win:PTR TO window
DEF imsg:PTR TO intuimessage
DEF timereq:PTR TO timerequest
DEF winsig,timersig,sigs
DEF cont
DEF dt:datetime
DEF text[LEN_DATSTRING]:STRING
IF (timereq:= open_timer(UNIT_VBLANK))
start_timer(timereq,0,100000)
IF (scr:= LockPubScreen(NIL))
IF (win:= OpenWindowTagList(NIL,
[WA_Width, scr.rastport.txwidth * 10 + 64,
WA_Height,scr.wbortop + scr.rastport.txheight + 1,
WA_PubScreen,scr,
WA_Flags,WFLG_CLOSEGADGET OR WFLG_DRAGBAR OR WFLG_DEPTHGADGET OR WFLG_NOCAREREFRESH,
WA_IDCMP,IDCMP_CLOSEWINDOW OR IDCMP_VANILLAKEY,
TAG_END]))
winsig:= 1 << win.userport.sigbit
timersig:= 1 << timereq.io.mn.replyport.sigbit
cont:= TRUE
REPEAT
sigs:= Wait(winsig OR timersig OR SIGBREAKF_CTRL_C)
IF (sigs AND SIGBREAKF_CTRL_C) THEN cont:= FALSE
IF (sigs AND timersig)
wait_timer(timereq)
start_timer(timereq,1,0)
DateStamp(dt.stamp)
dt.format:= FORMAT_DOS
dt.flags:= 0
dt.strday:= NIL
dt.strdate:= NIL
dt.strtime:= text
DateToStr(dt)
SetWindowTitles(win,text,-1)
ENDIF
IF (sigs AND winsig)
WHILE ((imsg:= GetMsg(win.userport)))
SELECT (imsg.class)
CASE IDCMP_VANILLAKEY
IF (imsg.code = $1b) THEN cont:= FALSE
CASE IDCMP_CLOSEWINDOW
cont:= FALSE
ENDSELECT
ReplyMsg(imsg)
ENDWHILE
ENDIF
UNTIL (cont = FALSE)
CloseWindow(win)
ENDIF
UnlockPubScreen(NIL,scr)
ENDIF
stop_timer(timereq)
close_timer(timereq)
ENDIF
ENDPROC 0
/*----------------------------------------------------------------------------*/
/* End of source text */
/*----------------------------------------------------------------------------*/
|