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.
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.
Routine | Number | Parameters | Return | Description |
Terminate | 0 | None | None | Terminates program execution. |
Clear | 1 | None | None | Clears terminal window. |
PutC | 2 | Char in D0.w | None | Outputs single character in terminal window. |
GetC | 3 | None | Char in D0.w | Reads single character from terminal; returns null if none is available. Note that terminal window has to be active to accept keyboard input. |
PutS | 4 | String address in A0 | None | Outputs null-terminated string in terminal window. Each character is expected to be 1 byte in size. |
GetS | 5 | Buffer in A0, size in D0 | None | Reads line of up to D0 characters into provided buffer. Returns null-terminated string. Blocking call. |
PutInt | 6 | Number in D0 | None | Outputs signed integer number in terminal window. |
PutUInt | 7 | Number in D0 | None | Outputs unsigned integer number in terminal window. |
PutHex | 8 | Number in D0, size in D1 | None | Outputs unsigned hexadecimal number in terminal window. D1 denotes size of number as byte (1), word (2), or long word (4). |
GetCursorX | 9 | None | Number in D0.w | Reads cursor X location in terminal window. |
GetCursorY | 10 | None | Number in D0.w | Reads cursor Y location in terminal window. |
SetCursorX | 11 | Number in D0.w | None | Sets cursor X location in terminal window. |
SetCursorY | 12 | Number in D0.w | None | Sets cursor Y location in terminal window. |
GetTerminalWidth | 13 | None | Number in D0.w | Reads terminal window width (in number of characters). |
GetTerminalHeight | 14 | None | Number in D0.w | Reads terminal window height (in number of characters). |
SetTerminalWidth | 15 | Number in D0.w | None | Sets terminal window width (in number of characters). |
SetTerminalHeight | 16 | Number in D0.w | None | Sets terminal window height (in number of characters). |
GetRTTimer | 17 | None | Number in D0 | Reads real-time 1 kHz frequency timer with resolution equal or better than 16 ms. |
GetDateTime | 18 | None | Number in D0 | Reads date and time encoded as a number of seconds since January 1, 1970 divided by two. |
GetRandomNumber | 19 | None | Number in D0.w | Returns pseudo-random 15-bit number in lower 16 bits of D0. |
RunAsSuper | 20 | Program address in A0 | Program specific | Runs user routine with supervisor priviledges. |
Sleep | 21 | Number in D0 | None | Sleeps for D0 milliseconds. Blocking call. |
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