M68K Trap Tasks

The M68K has one system call: trap #15. The task number goes in D0.B, its arguments in the other registers, and the answer comes back in the registers the task names. The interface is EASy68K's, so a program written for that simulator runs here unchanged as far as its I/O goes.

Text and graphics share one image, as they do in EASy68K's output window: what a program prints is drawn on the screen at the text cursor and appended to the terminal transcript, which is what testcases assert on. Click the screen panel to give the program the keyboard; the ring around it says the editor's own shortcuts are off while it has focus.

Text I/O tasks 0 to 20

Printing and reading. Everything printed is appended to the terminal transcript and drawn on the screen at the text cursor, because EASy68K has one output window where text and graphics share the image; the transcript is what testcases assert on. Typed input is echoed to both.

0 Display string with CR, LF

in A1 = string address, D1.W = length

Displays up to D1.W characters of the string at (A1), stopping at a NULL, then a new line. See task 13 for the NULL terminated form.

1 Display string

in A1 = string address, D1.W = length

Displays up to D1.W characters of the string at (A1) without a new line. See task 14 for the NULL terminated form.

2 Read string

in A1 = buffer address
out The NULL terminated string at (A1), D1.W = its length

Reads a line of input. With a screen keyboard the line is typed on the screen and ends with Enter; otherwise the editor asks for it, and a testcase answers it from its scripted input.

3 Display signed number

in D1.L = number

Displays D1.L in decimal, in the smallest field it fits. See tasks 15 and 20.

4 Read number

out D1.L = number

Reads a line and parses it as a decimal number.

5 Read character

out D1.B = ASCII code

Reads one character. With a screen keyboard it is taken as soon as it is typed, without waiting for Enter; check task 7 first to poll instead of waiting.

6 Display character

in D1.B = ASCII code

Displays one character.

9 Terminate

Ends the program.

11 Set or get the text cursor, or clear the screen

in D1.W = $FF00 to clear, $00FF to get, otherwise column in the high byte and row in the low byte
out For $00FF, D1.W = column in the high byte, row in the low byte

The text cursor is where printed text lands, in character cells counted from the top left. Clearing with $FF00 clears text and graphics together, since they share one image, and homes the cursor. Positions outside the screen are clamped to it.

13 Display NULL terminated string with CR, LF

in A1 = string address

Displays the NULL terminated string at (A1), then a new line.

14 Display NULL terminated string

in A1 = string address

Displays the NULL terminated string at (A1) without a new line.

15 Display unsigned number in a base

in D1.L = number, D2.B = base (2 to 36)

Displays D1.L as an unsigned number in the base in D2.B.

17 Display string and number

in A1 = string address, D1.L = number

Task 14 then task 3: the NULL terminated string, then the signed number.

18 Display string and read number

in A1 = string address
out D1.L = number

Task 14 then task 4: the NULL terminated string as a prompt, then a number.

20 Display signed number in a field

in D1.L = number, D2.B = field width

Task 3 right justified in a field D2.B columns wide. A number too long for the field is displayed in full.

Graphics tasks 33 to 96

Drawing on the screen. The origin is the top left, coordinates are pixels, and drawing outside the screen is ignored. Colors are $00BBGGRR longs, the same encoding EASy68K uses, so its color equates are unchanged. Rectangles and ellipses exclude their right and bottom edges, as they do in EASy68K, which draws them through the Windows GDI.

Colors

A color is a long written $00BBGGRR: blue in bits 23-16, green in bits 15-8 and red in bits 7-0. These are EASy68K's own equates, and a program that defines them by name needs no change.

$00000000 black
$00000080 maroon
$00008000 green
$00008080 olive
$00800000 navy
$00800080 purple
$00808000 teal
$00808080 gray
$000000FF red
$0000FF00 lime
$0000FFFF yellow
$00FF0000 blue
$00FF00FF fuchsia
$00FFFF00 aqua
$00C0C0C0 ltgray
$00FFFFFF white

33 Set or get the screen size

in D1.L = width in the high word and height in the low word, or 0 to get, 1 for windowed, 2 for full screen
out For D1.L = 0, D1.L = width in the high word, height in the low word

Resizes the screen and clears it. The minimum is EASy68K’s 640 by 480, which is also the size a program starts with. The windowed and full screen requests are accepted and ignored, since the screen is a panel in the editor.

80 Set pen color

in D1.L = color as $00BBGGRR

The color lines, outlines, pixels and text are drawn in.

81 Set fill color

in D1.L = color as $00BBGGRR

The color the insides of rectangles and ellipses and a flood fill are drawn in.

82 Draw pixel

in D1.W = X, D2.W = Y

One pixel in the pen color. The pen width does not apply and the drawing point does not move.

83 Get pixel color

in D1.W = X, D2.W = Y
out D0.L = color as $00BBGGRR

Reads the pixel of the image being drawn on, which with double buffering is the off screen one. Outside the screen it answers with the background color.

84 Draw line

in D1.W = X1, D2.W = Y1, D3.W = X2, D4.W = Y2

A line in the pen color, leaving the drawing point at X2, Y2.

85 Draw line to

in D1.W = X, D2.W = Y

A line in the pen color from the drawing point to X, Y, which becomes the new drawing point: a polyline is one task per point.

86 Move to

in D1.W = X, D2.W = Y

Moves the drawing point without drawing.

87 Draw rectangle

in D1.W = left X, D2.W = upper Y, D3.W = right X, D4.W = lower Y

Filled with the fill color and outlined with the pen. The right and bottom edges are excluded, so a rectangle whose edges meet draws nothing.

88 Draw ellipse

in D1.W = left X, D2.W = upper Y, D3.W = right X, D4.W = lower Y

The ellipse inscribed in that rectangle, filled with the fill color and outlined with the pen. A square bounding rectangle draws a circle.

89 Flood fill

in D1.W = X, D2.W = Y

Spreads the fill color from X, Y over every neighbouring pixel of the color that was there, four ways.

90 Draw unfilled rectangle

in D1.W = left X, D2.W = upper Y, D3.W = right X, D4.W = lower Y

The outline of task 87 in the pen color, with nothing inside.

91 Draw unfilled ellipse

in D1.W = left X, D2.W = upper Y, D3.W = right X, D4.W = lower Y

The outline of task 88 in the pen color, with nothing inside.

92 Set drawing mode

in D1.B = 2, 4, 16 or 17

Mode 4 draws normally and is the default; mode 2 moves the drawing point without changing any pixel; mode 16 turns double buffering off and mode 17 turns it on, so drawing goes to an off screen image until task 94 shows it.

note

EASy68K’s bitwise modes (0, 1, 3 and 5 to 15) stop the program with an error naming the mode. Double buffering covers the sprite erasing use of the XOR mode.

93 Set pen width

in D1.B = width in pixels

The width of lines and of the outlines of rectangles and ellipses. A single pixel (task 82) ignores it.

94 Repaint the screen

Shows the off screen image drawn under mode 17. With double buffering off it does nothing but ask for a repaint.

95 Draw text at a pixel position

in A1 = NULL terminated string, D1.W = X, D2.W = Y

Draws the string in the pen color with its top left corner at X, Y, over whatever is already there, so a label can sit on a drawing. Control characters are ignored. Text printed with the text tasks lands at the text cursor instead (task 11).

96 Get the drawing point

out D1.W = X, D2.W = Y

Where the next line-to would start.

Keyboard and mouse tasks 7 to 61

Polled input from the focused screen. Key codes are EASy68K’s, which every environment in this editor uses. There are no input interrupts: a program asks for the state it wants when it wants it (tasks 60 and 62 are therefore not supported).

Key codes

  • A letter key is the ASCII code of its capital, so A is $41 and Z is $5A. Shift, Alt and Ctrl do not change it.

  • A top row digit is its ASCII code, so 0 is $30 and 9 is $39.

  • The function keys are contiguous from F1, so F1 is $70 and F12 is $7B.

  • The keypad digits with Num Lock on are contiguous from $60.

$08 Backspace
$09 Tab
$0D Enter
$10 Shift
$11 Ctrl
$12 Alt
$14 Caps Lock
$1B Esc
$20 Space
$21 Page Up
$22 Page Down
$23 End
$24 Home
$25 Left arrow
$26 Up arrow
$27 Right arrow
$28 Down arrow
$2D Insert
$2E Delete
$BA Semicolon
$BB Equals
$BC Comma
$BD Minus
$BE Period
$BF Slash
$C0 Backquote
$DB Open bracket
$DC Backslash
$DD Close bracket
$DE Quote

7 Check for keyboard input

out D1.B = 1 when a character is waiting, 0 otherwise

Polls without consuming anything: the character it reports is the one task 5 or task 2 reads next. A testcase reports its remaining scripted input the same way.

19 Get key state

in D1.L = four key codes, or 0 for the last keys
out D1.L = four $FF/$00 bytes, or the last key up in the high word and the last key down in the low word

Reads whether up to four keys are held right now, one byte of the answer per key code in the same order; with D1.L = 0 it answers with the last key released and the last key pressed instead. A key held down is reported at least once however briefly it was tapped, so a polling loop never misses one.

24 Enable or disable the simulator shortcut keys

in D1.L = 0 to enable, 1 to disable

Accepted and ignored: the screen panel already hands every key it takes to the program, so there are no simulator shortcuts to give up.

61 Read the mouse

in D1.B = 0 for the current state, 1 for the last button release, 2 for the last button press
out D0.B = Ctrl, Alt, Shift, Double, Middle, Right, Left from bit 6 down; D1.L = Y in the high word, X in the low word

The pointer position is in screen pixels with the same origin drawing uses, whatever the panel’s zoom. The release and press states persist until the next one, so a program that polls slowly still sees every click; the double bit is only ever set on a press.

Program time tasks 8 to 23

Waiting and reading the clock. A delay suspends the program without blocking the editor, so Stop still answers and the screen still repaints while it runs. Testcases run on a virtual clock, where a delay completes at once and the clock starts at zero.

8 Get time

out D1.L = hundredths of a second

The time the program has been running, in hundredths of a second.

note

EASy68K counts from midnight; here the clock starts at zero when the run starts, and a testcase’s virtual clock does too. Programs measure elapsed time by subtracting two reads, which is unchanged.

23 Delay

in D1.L = hundredths of a second

Lets D1.L hundredths of a second of program time pass. The editor stays responsive throughout, and the screen is repainted, so this is how an animation paces itself.

note

A testcase runs on a virtual clock: the delay completes immediately and advances that clock instead of waiting.

Tasks that are not supported

These stop the program with an error naming the task, rather than doing something the program did not ask for. Everything they configure is either hardware this editor does not have or a decision the editor makes for itself.

10 print to the printer — the editor has no printer
12 keyboard echo — typed input is always echoed, the way a terminal does it
16 display properties — the editor’s input prompt is not a program setting
21 font properties — the screen draws text in one fixed cell font
22 read a character from the text screen — the screen holds pixels, not a grid of characters
25 scroll a text rectangle — the screen holds pixels, not a grid of characters
30 clear the cycle counter — no cycle counting is emulated
31 read the cycle counter — no cycle counting is emulated
32 hardware and simulator control — there is no hardware window and no automatic IRQ
60 enable the mouse IRQ — mouse input is polled with task 61, not delivered as an interrupt
62 enable the keyboard IRQ — keyboard input is polled with tasks 7 and 19, not delivered as an interrupt

Differences from EASy68K

  • Everything printed also reaches the terminal transcript, which EASy68K does not have. It is what keeps testcases and the non-graphical view working.
  • The screen draws text in one fixed 8 by 16 cell font, so task 21 (font properties) is not supported and the text screen cannot be read back (task 22) or scrolled (task 25).
  • Task 92's bitwise drawing modes (0, 1, 3 and 5 to 15) stop the program with an error naming the mode. Double buffering, modes 17 and 94, covers the sprite erasing the XOR mode is usually used for.
  • Task 8 counts from the start of the run rather than from midnight, and task 23 completes immediately during a testcase, which runs on a virtual clock.
  • Rectangles and ellipses exclude their right and bottom edges. That is what EASy68K does too, because it draws through the Windows GDI, but it surprises people often enough to be worth saying twice.