amiga-bootcamp/08_graphics/rastport.md
Ilia Sharin 21751c0025 docs(amiga): complete AmigaOS 3.1/3.2 developer reference — 172 files across 17 sections
Comprehensive technical documentation covering:
- Hardware: OCS/ECS/AGA custom chip registers, Copper & Blitter deep dives
- Boot sequence: cold boot through startup-sequence
- Binary format: HUNK executable spec, relocation, debug info
- Linking & ABI: .fd files, LVO tables, register calling conventions
- Exec kernel: tasks, interrupts, memory, signals, semaphores
- AmigaDOS: file I/O, FFS/OFS layout, CLI/Shell scripting
- Graphics: planar bitmaps, Copper programming, HAM/EHB modes
- Intuition: screens, windows, IDCMP, BOOPSI
- Devices: trackdisk, SCSI, serial, timer, audio, keyboard
- Libraries: utility, expansion, IFFParse, locale, ARexx
- Networking: bsdsocket API, SANA-II, TCP/IP stack comparison
- Toolchain: GCC, vasm/vlink, SAS/C, NDK, debugging
- Reverse engineering: IDA/Ghidra setup, compiler fingerprints, case studies
- CPU & MMU: 68040/060 emulation libs, PMMU, cache management
- Driver development: SANA-II, Picasso96/RTG, AHI audio

All files include breadcrumb navigation. No local paths or proprietary content.
2026-04-23 12:17:35 -04:00

112 lines
3.3 KiB
Markdown

[← Home](../README.md) · [Graphics](README.md)
# RastPort — Drawing Primitives and Layers
## Overview
`RastPort` is the primary drawing context in AmigaOS. All graphics primitives (pixel, line, rectangle, polygon, text) operate through a `RastPort`, which links a `BitMap`, drawing pen colours, pattern, font, and optional `Layer` for clipping.
---
## struct RastPort
```c
/* graphics/rastport.h — NDK39 */
struct RastPort {
struct Layer *Layer; /* associated layer (NULL = no clipping) */
struct BitMap *BitMap; /* target bitmap */
UWORD *AreaPtrn; /* area fill pattern */
struct TmpRas *TmpRas; /* temp raster for area fills/floods */
struct AreaInfo *AreaInfo; /* area fill vertex buffer */
struct GelsInfo *GelsInfo; /* GEL (BOB/VSprite) list */
UBYTE Mask; /* plane mask (which planes to draw to) */
BYTE FgPen; /* foreground pen colour index */
BYTE BgPen; /* background pen colour index */
BYTE AOlPen; /* area outline pen */
BYTE DrawMode; /* JAM1, JAM2, COMPLEMENT, INVERSVID */
BYTE AreaPtSz; /* area pattern size (log2) */
BYTE linpatcnt; /* line pattern counter */
BYTE dummy;
UWORD Flags; /* FRST_DOT etc. */
UWORD LinePtrn; /* 16-bit line dash pattern */
WORD cp_x, cp_y; /* current pen position */
UWORD minterms[8];
WORD PenWidth;
WORD PenHeight;
struct TextFont *Font; /* current text font */
UBYTE AlgoStyle; /* algorithmic style flags */
UBYTE TxFlags;
UWORD TxHeight;
UWORD TxWidth;
UWORD TxBaseline;
WORD TxSpacing;
APTR *RP_User;
/* ... */
};
```
---
## Draw Modes
```c
#define JAM1 0 /* draw FgPen only; background transparent */
#define JAM2 1 /* draw FgPen and BgPen (opaque) */
#define COMPLEMENT 2 /* XOR with existing pixels */
#define INVERSVID 4 /* invert video (swap fg/bg for text) */
```
---
## Drawing Primitives
```c
/* Set pen colour: */
SetAPen(rp, 1); /* foreground = colour 1 */
SetBPen(rp, 0); /* background = colour 0 */
SetDrMd(rp, JAM1); /* transparent background */
/* Move to position: */
Move(rp, 100, 50);
/* Draw line from current position to (x,y): */
Draw(rp, 200, 100);
/* Write pixel: */
WritePixel(rp, 160, 120);
/* Read pixel: */
LONG colour = ReadPixel(rp, 160, 120);
/* Filled rectangle: */
RectFill(rp, 10, 10, 100, 50);
/* Draw text at current position: */
Move(rp, 20, 30);
Text(rp, "Hello", 5);
/* Blitter copy between RastPorts: */
ClipBlit(srcRP, sx, sy, dstRP, dx, dy, w, h, minterm);
```
---
## Layers
When `rp->Layer != NULL`, all drawing is clipped to the layer's bounds and damage regions. Layers are managed by `layers.library`:
```c
struct Layer_Info *li = NewLayerInfo();
struct Layer *layer = CreateUpfrontLayer(li, bm, x1, y1, x2, y2, flags, NULL);
rp = layer->rp; /* use this RastPort for drawing */
/* ... draw ... */
DeleteLayer(0, layer);
DisposeLayerInfo(li);
```
---
## References
- NDK39: `graphics/rastport.h`, `graphics/gfxmacros.h`
- ADCD 2.1: `SetAPen`, `Move`, `Draw`, `Text`, `RectFill`, `ClipBlit`