Writing a Human68k Program for High-Resolution Plotting
A sine curve can look deceptively simple on paper yet expose every weakness of a plotting program: coordinate mapping, rounding, clipping, speed and display timing. On the Sharp X68000, high-resolution plotting is especially rewarding because its monochrome graphics mode can hold a dense 512 by 512 image without the blur of a low-resolution bitmap. The goal is a clean curve, not merely a filled rectangle.
The key is to treat Human68k as the operating environment rather than a graphics library. A Human68k program can be written in C or assembly, talk to the machine’s BIOS and CRTC hardware, and write directly into video RAM. That combination makes pixel-level control practical while still allowing a readable source file, a plot function separated from its display adapter, and the option to preserve the result for later use.
High resolution should describe the final image rather than the arithmetic alone. Horizontal width, vertical height, line thickness and font size all contribute to perceived detail. For a first experiment, the native 512 by 512 monochrome page is an excellent target: it offers room for axes, labels and several curves, while its one-bit pixels keep memory use modest and edge decisions unambiguous.
The following workflow moves from mode selection to fixed-point evaluation, then to line drawing, testing and preservation. It applies to a real X68000 rather than an emulator alone, although an emulator is useful for checking calculations and timing. Each stage can be kept small enough to debug, which matters when a page address, bit order or CRTC register differs between board revisions.
Choosing a Practical Graphics Target
Choose the display target before writing the function evaluator. The 512 by 512 monochrome page is the best balance for a first plot because a logical page needs only 32 KiB and every horizontal run of 16 pixels fits into one 16-bit word. That layout makes a one-pixel curve predictable, provided the program uses the correct page and bit order for the machine in front of it.
Native colour modes offer attractive alternatives, but they solve a different problem. A 512 by 342, 16-colour bitmap is useful for presentation with coloured curves and grid lines, while a 256 by 342, 256-colour bitmap suits gradients and palette experiments. Both have less horizontal or vertical detail than monochrome. Check the diagram for the exact X68000 model before changing registers; the SMB research notes can be used alongside the machine’s manuals when confirming original hardware behaviour.
Power deserves attention before any display test. Original Japanese X68000 power supplies are normally specified for 100 V, whereas Australian mains supply 240 V at 50 Hz. A travel plug changes the pin shape, not the voltage. Use correctly rated, electrically isolated step-down equipment, and have any mains-side alteration checked by a qualified electrician rather than relying on a reversible adaptor sold for travel.
Preparing the Human68k Graphics Environment
Human68k supplies the process environment, command facilities and common services, while X-BIOS or direct CRTC access supplies the graphics controls. On some systems the practical path is a short assembly shim; on others it is a C function that sets the mode and returns a video-memory pointer. Either way, hide those details behind a small interface such as select_512_mono(), mono_page(0) and present_page().
These names are design examples, not claims about a universal Human68k API. The mode routine must set the horizontal and vertical counters, pixel clock, display origin and page arrangement, then wait for a safe display interval. The page routine must return the actual write address, while the presentation routine can flip pages or copy a completed image into the visible plane. Clear documentation is more valuable than a clever startup sequence.
Keep the mathematics independent of those adapters. The evaluator should return a scaled value, and the renderer should accept ordinary screen coordinates. This split allows the same sine routine to feed a monochrome plot, a 16-colour graph or an ASCII test. It also makes arithmetic mistakes easier to isolate: feed known values to the evaluator first, then connect pixels only after the numbers are correct.
Converting Formulas into Pixel Coordinates
Map the graph into a signed coordinate system before plotting. One convenient choice is Q12 fixed point, where 4096 represents 1.0. Integer angles use 12868 for pi, and a sine value can be held as a signed 32-bit long. Because the 68000 has no built-in floating-point unit, fixed point avoids a software floating-point library and gives consistent speed across the useful mathematical functions.
The native display choices determine how much of that precision can be seen:
| Display choice | Logical bitmap size | Effect on a mathematical plot |
|---|---|---|
| 512×512 monochrome | 32 KiB at 1 bit per pixel | Finest native detail and simple curve pixels |
| 512×342, 16 colour | About 85.5 KiB at 4 bits per pixel | Good colour separation with reduced vertical resolution |
| 256×342, 256 colour | About 85.5 KiB at 8 bits per pixel | Rich palette effects but fewer horizontal pixels |
For a dense black-and-white graph, monochrome leaves every pixel available for the curve. A colour mode can improve annotation, but palette selection and plane handling become additional tasks. The following core uses the common monochrome arrangement of 16 pixels per 16-bit word; verify the row order and left-hand bit against the target machine before enabling it.
Here is the evaluator and plotting core. put_pixel() assumes 32 words per 512-pixel row, and the adapter must supply the correctly configured page. sine_q12() range-reduces its input and uses a short Taylor series, while draw_line() joins successive samples with Bresenham’s algorithm. All products remain within signed 32-bit range for the stated domain.
#define WIDTH 512
#define ONE_Q 4096L
#define PI_Q 12868L
static long mul_q12(long a, long b)
{
return (a * b) >> 12;
}
static long sine_q12(long x)
{
long x2, term, sum;
x %= 2L * PI_Q;
if (x > PI_Q)
x -= 2L * PI_Q;
else if (x < -PI_Q)
x += 2L * PI_Q;
if (x > PI_Q / 2L)
x = PI_Q - x;
else if (x < -PI_Q / 2L)
x = -PI_Q - x;
x2 = mul_q12(x, x);
term = x;
sum = x;
term = mul_q12(term, x2);
sum -= term / 6L;
term = mul_q12(term, x2);
sum += term / 120L;
term = mul_q12(term, x2);
sum -= term / 5040L;
return sum;
}
static void put_pixel(volatile unsigned short *page,
int x, int y)
{
unsigned short mask;
mask = (unsigned short)(0x8000UL >> (x & 15));
page[(y * 32) + (x >> 4)] |= mask;
}
static void draw_line(volatile unsigned short *page,
int x0, int y0, int x1, int y1)
{
int dx = x1 > x0 ? x1 - x0 : x0 - x1;
int dy = y1 > y0 ? y1 - y0 : y0 - y1;
int sx = x0 < x1 ? 1 : -1;
int sy = y0 < y1 ? 1 : -1;
int err = dx - dy;
int e2;
for (;;) {
put_pixel(page, x0, y0);
if (x0 == x1 && y0 == y1)
break;
e2 = 2 * err;
if (e2 > -dy) {
err -= dy;
x0 += sx;
}
if (e2 < dx) {
err += dx;
y0 += sy;
}
}
}
static void draw_sine(volatile unsigned short *page)
{
int i, px, previous_y = -1;
long angle, value;
int py;
for (i = 0; i < WIDTH * 32; i++)
page[i] = 0;
for (px = 0; px < WIDTH; px++) {
angle = -2L * PI_Q
+ (2L * PI_Q * px) / (WIDTH - 1);
value = sine_q12(angle);
py = WIDTH - 1
- (int)(((value + ONE_Q) * (WIDTH - 1))
/ (2L * ONE_Q));
if (py < 0)
py = 0;
if (py >= WIDTH)
py = WIDTH - 1;
if (previous_y < 0)
put_pixel(page, px, py);
else
draw_line(page, px - 1, previous_y, px, py);
previous_y = py;
}
}
Refining Axes, Curves and Readability
Drawing the curve is only half the job. Reserve a few pixels at the edges, place the zero axis at the computed centre line, and draw ticks whose spacing corresponds to round numbers in the function’s domain. Labels are easier to read when the character cell and the 512-pixel width share a simple relationship. A one-pixel grid can provide scale without competing with a thin curve, while deliberate gaps prevent lines joining across discontinuities.
Another X68000 technique worth understanding is how objects are moved independently of the background. The site’s sprite engine animation notes show how timing and layered drawing work in practice. They are not needed for a static graph, but sprite hardware or a second graphics page can provide a cursor, moving reference line or animated parameter marker without redrawing the entire plot.
Use colour sparingly if a colour mode is chosen, and do not assume that more colours automatically mean a better graph. In Australian hobby-room language, a plot is “properly sorted” when its purpose remains obvious on the original screen: axis labels legible, curves distinct and clipping handled. Test with a timer as well as a stopwatch; drawing every sample separately may look fine but waste the X68000’s capability.
Testing and Preserving the Results
Verification should proceed from known landmarks. Clear the page and place dots at all four corners to confirm orientation; plot zero, one half and one on the vertical scale; then compare the curve with a calculator or another implementation. Watch for clipped peaks, a flat zero line caused by poor rounding, and axes drawn one pixel off. Repeated output is often faster than an occasional correct frame.
Test on each model and revision that matters, because memory organisation and timing can differ. Record the CRTC settings, CRTC register values, page base, bit order and any palette values beside the source. If the program uses page flipping, test both page parity and the vertical blanking interval. A small text file containing these values can save hours when the machine is later switched on again.
Preservation is part of the project. Save the C source, build instructions, a screenshot and a disk image or executable under clear filenames, then publish them with the hardware notes. This matters in the Australian market, where collectors in Melbourne, Sydney and Brisbane often encounter scarce Japanese parts through eBay Australia or Gumtree. International freight, GST and local repair prices can change quickly, so a documented working program is valuable even when the original machine stays in storage.
Build the smallest complete version now: one sine curve in 512 by 512 monochrome, one saved image and a written record of the display settings. Once that version runs reliably on real hardware, add axes, a second function, a title and interactive controls one at a time. A measured, documented first result is easier to preserve and share than a large program that has never been tested.
Package the source and documentation for the X68K hobby community, then demonstrate it at a local retro-computing meet-up. Share failures as well as screenshots, because a documented CRTC mismatch or safe power-supply solution may save another Australian collector the same expense. Publish the working plot and its source so the next collector can reproduce it.
Nereid-X Expansion Board
A personally-produced LAN+USB+Memory expansion board for Sharp X68000 series computers. Multiple production runs were offered, including a final batch and a later revival reproduction run.
Power Supply Repair
X68 power supply repair and modification services were offered by the site owner, with documentation shared through diary entries spanning 2001–2006.
Server & Networking
Notes on FreeBSD administration, ISP changes, server migration, and networking topics. The site itself ran on FreeBSD with the hns diary system and Namazu search integration.
Get in touch
X68K.NET connects Sharp X68000 enthusiasts through community links and shared projects. Reach out with questions about the Nereid project or X68 resources.