diff --git a/app/src/test/java/org/dmodem/app/android/terminal/ProfileRenderTest.kt b/app/src/test/java/org/dmodem/app/android/terminal/ProfileRenderTest.kt new file mode 100644 index 0000000..1f52409 --- /dev/null +++ b/app/src/test/java/org/dmodem/app/android/terminal/ProfileRenderTest.kt @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// Copyright (C) 2026 Neo-Desktop +package org.dmodem.app.android.terminal + +import android.content.Context +import android.graphics.Bitmap +import android.graphics.Canvas +import android.view.View +import androidx.test.core.app.ApplicationProvider +import org.dmodem.app.android.modem.DteHub +import org.dmodem.app.android.settings.TerminalSettings +import org.dmodem.app.terminal.TerminalProfile +import org.dmodem.app.terminal.TerminalProfiles +import org.junit.Assert.assertTrue +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import org.robolectric.annotation.GraphicsMode +import java.io.File + +/** + * Every terminal type drawn for real with a screen of its own codes, each + * kept as build/profiles/.png to look at, and checked to have drawn + * something (text, glyphs, mosaics, a picture) over its background. + */ +@RunWith(RobolectricTestRunner::class) +@GraphicsMode(GraphicsMode.Mode.NATIVE) +@Config(sdk = [35]) +class ProfileRenderTest { + + private val w = 960 + private val h = 600 + + /** [octets] drawn by a view on a terminal of [profile]: the picture */ + private fun render(profile: TerminalProfile, octets: String): Bitmap { + val ctx = ApplicationProvider.getApplicationContext() + val session = TerminalSession(DteHub()) { null } + val v = TerminalView(ctx) + v.session = session + v.applySettings(TerminalSettings(cursorBlink = false)) + session.profile = profile + v.measure(View.MeasureSpec.makeMeasureSpec(w, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(h, View.MeasureSpec.EXACTLY)) + v.layout(0, 0, w, h) + val b = ByteArray(octets.length) { octets[it].code.toByte() } + synchronized(session.emulator) { session.emulator.append(b) } + val bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888) + v.draw(Canvas(bmp)) + return bmp + } + + /** a 4010 address (10-bit [x], [y]) as its four bytes */ + private fun tek(x: Int, y: Int): String = + "${(0x20 or (y shr 5)).toChar()}${(0x60 or (y and 31)).toChar()}${(0x20 or (x shr 5)).toChar()}${(0x40 or (x and 31)).toChar()}" + + /** a screen in [p]'s own codes: text, its colours or attributes, its graphics */ + private fun sample(p: TerminalProfile): String { + val e = "\u001b" + return when (p.id) { + "c64", "c128", "c128-80", "plus4", "vic20", "pet", "pet80" -> + // clear, red, HELLO, reverse, a row of graphics + "\u0093\u001cHELLO \u0012\u0005D-MODEM\u0092\r¦¦¦°®" + "atari", "atari-intl" -> "}HELLO ÄÍÏÄÅÍ\u009b\u0011\u0012\u0012\u0005\u009b" + "viewdata" -> "\u000c${e}AHELLO ${e}W\u007f\u007f#5 ${e}FPRESTEL" + "minitel" -> "\u000c${e}ABONJOUR ${e}F\u000e\u007f\u007f#\u000f MINITEL" + "tek4014" -> "\u001d${tek(100, 100)}${tek(900, 100)}${tek(500, 700)}${tek(100, 100)}\u001fTEKTRONIX" + "vt340" -> "Hello VT340 $e[7mInverse$e[0m\r\n" + + "${e}PpS(M2(H120L50S100))W(I2)P[400,240]C[+100]P[100,300]F(V[+100][+0,+100][-100])$e\\" + "vt52" -> "${e}H${e}JHello VT52 ${e}F" + "abcdefg" + "${e}G" + else -> "$e[2J$e[HHello ${p.label} $e[1mBold$e[0m $e[7mInverse$e[0m $e[4mUnder$e[0m\r\n" + + "$e(0lqqqqk$e(B $e[31mRed$e[0m" + } + } + + /** each profile's screen drawn: more than the background, and (graphics) the picture's own pixels */ + @Test + fun everyProfile() { + val dir = File("build/profiles").apply { mkdirs() } + for (p in TerminalProfiles.all) { + val bmp = render(p, sample(p)) + File(dir, "${p.id}.png").outputStream().use { bmp.compress(Bitmap.CompressFormat.PNG, 100, it) } + val bg = bmp.getPixel(w - 1, h - 1) + var drawn = 0 + for (y in 0 until h step 2) for (x in 0 until w step 2) if (bmp.getPixel(x, y) != bg) drawn++ + assertTrue("${p.id}: nothing drawn", drawn > 50) + } + } +} diff --git a/docs/README.md b/docs/README.md index faa68b0..39393dd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,6 +4,7 @@ - [Fax](fax.md) - [Serial adapters and real phone lines](adapters.md): pico-serial, USB modems, a modem on a USB serial adapter, a Bluetooth modem - [The app, screen by screen](features.md) +- [Terminal types](terminals.md): the DEC line, PETSCII, ATASCII, videotex, ANSI-BBS and the graphics terminals, and how to test them - [Settings reference](settings.md): every setting, its key and default, made from the code (`tools/settings_ref.py`) - [Building the Android app](building.md) - [The iOS app](ios.md): building and running on iPhone and iPad diff --git a/docs/terminals.md b/docs/terminals.md new file mode 100644 index 0000000..d6198f1 --- /dev/null +++ b/docs/terminals.md @@ -0,0 +1,119 @@ +# Terminal types + +The terminal (Android and iOS) can be any of the terminals below. Pick one +in Settings, or give a directory entry its own. The choice sets what the +screen understands, how it answers the remote's identity requests, what +SSH sends as `TERM` and Telnet as TERMINAL-TYPE, the screen's size, its +character set and glyphs, and the key bar. + +All of them live in `shared/src/commonMain/kotlin/org/dmodem/app/terminal/`: +a `TerminalProfile` subclass for each type (`TerminalProfile.kt`, +`Commodore.kt`, `Atari.kt`, `Videotex.kt`, `Minitel.kt`, `Tektronix.kt`) +and the interpreter it makes (`VtInterpreter`, `Vt420Interpreter`, +`AnsiBbsInterpreter`, `ByteControlInterpreter` and its subclasses, +`TektronixInterpreter`). ReGIS is `Regis.kt`, sixel `Sixel.kt`, and both +graphics terminals draw through `Raster.kt`. + +| Type | Id | TERM / Telnet type | Screen | What it is | +|---|---|---|---|---| +| xterm | `xterm` | `xterm-256color` / `XTERM-256COLOR` | any | The default: a VT220 with 256 and 24-bit colour, sixel, the mouse, titles, and Tek mode | +| ANSI-BBS (PC) | `ansi-bbs` | `ansi` / `ANSI` | 80x25 | A PC's BBS terminal, as SyncTERM is: CP437 in a VGA font, iCE colours, ANSI music, doorway mode | +| DEC VT52 | `vt52` | `vt52` / `DEC-VT52` | 80x24 | The VT52's own escape codes and graphics | +| DEC VT100 | `vt100` | `vt100` / `DEC-VT100` | 80/132x24 | ANSI codes at level 1: no colour; double-size lines; VT52 mode | +| DEC VT102 | `vt102` | `vt102` / `DEC-VT102` | 80/132x24 | Adds character and line insert and delete, and a printer port | +| DEC VT220 | `vt220` | `vt220` / `DEC-VT220` | 80/132x24 | Level 2: G0-G3 character sets, 8-bit controls, soft fonts, user-defined keys, selective erase | +| DEC VT320 | `vt320` | `vt320` / `DEC-VT320` | 80/132x24 | Level 3: DEC Technical, the state reports, a status line | +| DEC VT340 | `vt340` | `vt340` / `DEC-VT340` | 80/132x24 | A VT320 with graphics: sixel and ReGIS in 16 shared colour registers, and Tek mode | +| DEC VT420 | `vt420` | `vt420` / `DEC-VT420` | 80/132x24+ | Level 4: left and right margins, rectangle operations, six pages | +| DEC VT510, VT520 | `vt510`, `vt520` | `vt510` / `DEC-VT510`, … | 80/132x24+ | Level 5: the display extent report, bell volumes | +| DEC VT525 | `vt525` | `vt525` / `DEC-VT525` | 80/132x24+ | A VT520 in colour, with its colour table | +| Commodore 64, 128 (40 and 80), Plus/4, VIC-20, PET (40 and 80) | `c64`, `c128`, `c128-80`, `plus4`, `vic20`, `pet`, `pet80` | `petscii` / `PETSCII` | 40x25 (VIC-20: 22x23; 80 for the C128's VDC and the 8032) | PETSCII as CCGMS and Novaterm do it, each in its machine's palette | +| Atari 8-bit | `atari`, `atari-intl` | `atascii` / `ATASCII` | 40x24 | ATASCII and the screen editor's controls; the XL's international set as a second type | +| Viewdata (Prestel) | `viewdata` | `viewdata` / `VIEWDATA` | 40x24 | Teletext Level 1 attributes and mosaics; # sends | +| Minitel | `minitel` | `minitel` / `MINITEL` | 40x25 | Teletel videotex with the status row, the protocol commands, Mixte (80 columns) and Téléinformatique (a VT100) | +| Tektronix 4014 | `tek4014` | `tek4014` / `TEK4014` | 4096x3120 tube | Vectors, points, incremental plots and alpha text on a storage tube | + +A VT510's and later screen size can change at the host's request +(DECSNLS, DECSLPP, DECSCPP). xterm and ANSI-BBS fit the view. + +## Graphics + +Sixel images are cells of an image that scroll with the text. ReGIS and +the Tektronix draw a picture over the whole screen instead. It is kept +the screen's size in pixels, and only the cells it has drawn in show it. +Resizing the screen starts the picture again, as on a storage tube. + +- **Sixel**: xterm, ANSI-BBS and the VT340. On the VT340 the images + share ReGIS's 16 colour registers. +- **ReGIS** (`ESC P p … ESC \`, VT340 only): + - The screen is 800x480. Positions can be absolute or relative, and + use the position stack and pixel vectors. + - Commands: P, V, C (circles, arcs, closed and open curves), F, T, W, + S, R, L and macrographs (@). + - Commands are run as they become whole, so a drawing sent over many + reads shows as it comes. `ESC P 1 p` starts afresh, and `ESC P p` + carries on from where the last one left off. +- **Tektronix 4014**: its own terminal type, and Tek mode on xterm and + the VT340. + - `ESC [ ? 38 h` switches to the alternate screen, and `ESC ETX` goes + back to the text. + +## Testing + +Each sequence has unit tests in `shared/src/commonTest`. Run them with +`./gradlew :shared:jvmTest :shared:linuxX64Test`. + +`ProfileRenderTest` in `app/src/test` draws a screen on every terminal +type through the real Android view and keeps it as +`app/build/profiles/.png`. Run it with +`./gradlew :app:testDebugUnitTest --tests '*ProfileRenderTest*'` and look +at the pictures after a change to drawing. + +### vttest + +To run vttest, open the app's Linux shell and install it +(`apk add vttest`, or the distro's equivalent). Set the terminal type in +Settings, then run `vttest`. + +What to expect, menu by menu, from the unit tests and the code. These +haven't yet been checked against a vttest run on a device: update the +table when they are. + +| vttest menu | Profiles | Expect | +|---|---|---| +| 1 Cursor movements | all DEC, xterm | passes | +| 2 Screen features (132 columns, scrolling regions, origin mode) | all DEC, xterm | passes. Smooth scrolling (DECSCLM) is drawn as jump scrolling | +| 3 Character sets | VT100 and later | passes. NRCS needs a VT220 or later | +| 4 Double-sized characters | VT100 and later | passes | +| 5 Keyboard | all | the LEDs and auto-repeat can't be checked on a phone. Use the key bar for the keypad and function keys | +| 6 Terminal reports | all | passes. The answerback message is empty | +| 7 VT52 mode | VT100 and later | passes | +| 8 VT102 features | VT102 and later | passes | +| 9 Known bugs | all | n/a | +| 10 Reset and self-test | all | the self-test (DECTST) does nothing | +| 11 Non-VT100 terminals | by level | VT220: passes. VT320: passes. VT420: passes except the locator (no mouse reports on a DEC type). VT520: passes except the keyboard's own settings (bell volumes and key click are accepted and ignored). xterm: its own menus | + +## What isn't done + +**ReGIS** +- Text is drawn upright in any direction: the string moves the way it's + told, but the glyphs don't turn. +- Italics (T(I)) and the hard copy and scrolling of S are accepted and + ignored. +- R(M) (macrograph storage) isn't answered. +- A colour register changed after drawing doesn't recolour what's + already drawn. + +**Tektronix** +- No graphic input (GIN) cross-hair. +- No write-through or defocused modes. + +**Viewdata and Minitel** +- Double height and double size are drawn single. + +**DEC** +- No locator (DECELR), and no answerback message. + +**iOS** +- The picture and image drawing is built but not yet compiled in Xcode + (the bridge's `imageRuns` and `imagePixels`). diff --git a/shared/src/commonMain/kotlin/org/dmodem/app/terminal/Raster.kt b/shared/src/commonMain/kotlin/org/dmodem/app/terminal/Raster.kt index bf89f28..63c5afa 100644 --- a/shared/src/commonMain/kotlin/org/dmodem/app/terminal/Raster.kt +++ b/shared/src/commonMain/kotlin/org/dmodem/app/terminal/Raster.kt @@ -182,24 +182,32 @@ class PictureLayer( private val logicalHeight: Int, private val setUp: (Raster) -> Unit = {}, ) { - var raster: Raster = make() - private set + private var current: Raster = make() + + /** the raster to draw in: a new one first if the screen's size changed (what's drawn can't be redrawn: the picture starts again) */ + val raster: Raster + get() { + if (pixelWidth() != current.width || pixelHeight() != current.height) reset() + return current + } + + /** the screen's width in pixels */ + private fun pixelWidth() = maxOf(1, t.cols * t.cellPixelWidth) + + /** the screen's height in pixels */ + private fun pixelHeight() = maxOf(1, t.rows * t.cellPixelHeight) /** a raster the screen's size, blank */ - private fun make() = Raster( - maxOf(1, t.cols * t.cellPixelWidth), maxOf(1, t.rows * t.cellPixelHeight), logicalWidth, logicalHeight, - ).also(setUp) + private fun make() = Raster(pixelWidth(), pixelHeight(), logicalWidth, logicalHeight).also(setUp) /** the picture started again, blank (what it showed taken off the screen at the next [flush]) */ fun reset() { - raster = make().also { it.clear() } + current = make().also { it.clear() } } - /** what was drawn put on the screen (if the screen's size changed, the picture started again at the new one: what's drawn can't be redrawn) */ + /** what was drawn put on the screen */ fun flush() { - if (maxOf(1, t.cols * t.cellPixelWidth) != raster.width || maxOf(1, t.rows * t.cellPixelHeight) != raster.height) { - reset() - } - if (raster.dirty) t.showPicture(raster.take(t.cellPixelWidth, t.cellPixelHeight)) + val r = raster + if (r.dirty) t.showPicture(r.take(t.cellPixelWidth, t.cellPixelHeight)) } }