Drawing shapes on the screen

A house, a sun and a sky drawn out of a table of shapes, one record per command, with colours packed into a byte and the label at the text cursor.

A picture in six shapes: the sky, the ground, an ellipse for the sun, a rectangle with an outline for the house, three lines for its roof and one more rectangle for the door, with a line of text over the top. Press Run and watch the Screen panel next to the program.

Print a string asked the environment for a line of text by writing one byte to a port. The Screen is more ports, right next to the console ones, and drawing is always the same two steps: write the colours and the coordinates to their ports, then write one command to the command port, which runs one operation on whatever is currently set.

You need to know: the "The screen, keyboard and mouse through ports" lecture and the "Arrays, strings and ix" lecture. What is new here is that the picture is a table: one shape is a record of seven bytes, and the whole program is ix walking it.

Every coordinate is one byte, so the Screen is at most 256 by 256 pixels, and no coordinate can hold the number 256 itself. The first shape resizes it to 240 by 192, which is a size whose right and bottom edges a byte can name, and after that a rectangle can reach every pixel there is. A rectangle excludes its right and bottom edges, the way EASy68K's does, so the ground really does reach the last row of the Screen.

A colour is one byte in a 3-3-2 layout: three bits of red in bits 7 to 5, three of green in bits 4 to 2 and two of blue in bits 1 and 0. SKY equ 0x9B is 100 110 11, which is four of the seven reds, six of the seven greens and all three of the blues, and comes out a pale blue. Two bits of blue is what was left over, which is why the greys on this machine are not exactly neutral.

The seven fields of a shape are the seven ports a drawing operation reads, in the order the loop writes them, and equ gives each one its offset. (ix+FILL) is p->fill in C, add ix, de with SHAPE in de is p++, and adding an eighth field to every shape means changing SHAPE and one line in the loop. COUNT is worked out by the assembler from the two labels around the table, so adding a row to the picture is adding a row and nothing else.

The sky, the ground, the sun and the door have the same colour in both their fields, so those shapes have no rim. The house sets them apart, WALL inside and WHITE outside, and the three pixel pen set before the loop is what makes that outline thick.

The roof is three lines and no shape at all. Command 3 moves the drawing position without drawing anything, and each command 2 after it draws from wherever that position is to the new place and leaves it there, so a polyline costs one command per corner. Command 1 is the other line command, the one that takes both ends at once.

The label goes through the console character port, the same port Print a string used, because the Screen has no text command of its own. Text lands at the text cursor, which is counted in 8 by 8 character cells, so a 240 pixel Screen is 30 columns wide and the label can only start on a cell boundary. The M68K draws a string at any pixel it likes with task 95; here you get cells. The characters are painted in the pen colour on the background colour, and the background is whatever the last clear filled the Screen with, which is why white on the sky looks right.

Try changing the 115 in the C_LINE_TO row of the roof to 70. That row is the apex, so the roof stops being a triangle and leans over to the left, and nothing else in the program has to know.