Monitor

Monitor is a regular ColdFire application that runs with supervisor priviledges and provides services to programs written in CF Studio. Programs assembled and run in CF Studio can call monitor routines.

All monitor routines are invoked through the TRAP #15 instruction with routine number pushed on the stack and parameters in the data/address registers.

Monitor is automatically loaded when CF Studio starts. It resides in "Monitor/monitor.cfp" file (sources are available in "Monitor/CFMonitor.cfs). It can be modified in CF Studio too.

Monitor Routines

This is a list of all monitor functions. They provide access to a simple terminal window and some general-purpose functionality, like real-time timer, date/time, random number generator, etc.

Monitor preserves registers D3-D7/A3-A7 during function calls. Registers D0-D2/A0-A2 may contain input parameters. Their content will NOT in general be preserved. Registers D0/D1 may contain return values, if any.

RoutineNumberParametersReturnDescription
Terminate0NoneNoneTerminates program execution.
Clear1NoneNoneClears terminal window.
PutC2Char in D0.wNoneOutputs single character in terminal window.
GetC3NoneChar in D0.wReads single character from terminal; returns null if none is available. Note that terminal window has to be active to accept keyboard input.
PutS4String address in A0NoneOutputs null-terminated string in terminal window. Each character is expected to be 1 byte in size.
GetS5Buffer in A0, size in D0NoneReads line of up to D0 characters into provided buffer. Returns null-terminated string. Blocking call.
PutInt6Number in D0NoneOutputs signed integer number in terminal window.
PutUInt7Number in D0NoneOutputs unsigned integer number in terminal window.
PutHex8Number in D0, size in D1NoneOutputs unsigned hexadecimal number in terminal window. D1 denotes size of number as byte (1), word (2), or long word (4).
GetCursorX9NoneNumber in D0.wReads cursor X location in terminal window.
GetCursorY10NoneNumber in D0.wReads cursor Y location in terminal window.
SetCursorX11Number in D0.wNoneSets cursor X location in terminal window.
SetCursorY12Number in D0.wNoneSets cursor Y location in terminal window.
GetTerminalWidth13NoneNumber in D0.wReads terminal window width (in number of characters).
GetTerminalHeight14NoneNumber in D0.wReads terminal window height (in number of characters).
SetTerminalWidth15Number in D0.wNoneSets terminal window width (in number of characters).
SetTerminalHeight16Number in D0.wNoneSets terminal window height (in number of characters).
GetRTTimer17NoneNumber in D0Reads real-time 1 kHz frequency timer with resolution equal or better than 16 ms.
GetDateTime18NoneNumber in D0Reads date and time encoded as a number of seconds since January 1, 1970 divided by two.
GetRandomNumber19NoneNumber in D0.wReturns pseudo-random 15-bit number in lower 16 bits of D0.
RunAsSuper20Program address in A0Program specificRuns user routine with supervisor priviledges.
Sleep21Number in D0NoneSleeps for D0 milliseconds. Blocking call.

Examples

All routine numbers must be pushed onto the stack as words, and removed afterward.

	; clear terminal window
	MOVE.W #1, -(SP)
	TRAP #15
	ADDQ.L #2, SP

Monitor calls can be simplified with macros. Include "Monitor.cfs" file to be able to write:

	MOVEQ #'A', d0
	M_PutC

In this case routine number is pushed and removed as needed by a macro.

Blocking execution until key is pressed in terminal window:

.loop
	M_GetC
	TST.W d0
	BEQ .loop