# Z80 Input/Output

[Z80 Documentation](https://asm-editor.specy.app/documentation/z80.md)

Web page: https://asm-editor.specy.app/documentation/z80/io

The ports that connect a program to the terminal, the Screen, the keyboard, the mouse, the clock and Audio.

65 entries, each with its own page of markdown:

- [Ports](https://asm-editor.specy.app/documentation/z80/io/ports.md): A Z80 has no system calls.
- [Console](https://asm-editor.specy.app/documentation/z80/io/console.md) `0x10 - 0x14`: One port per output format.
- [Character](https://asm-editor.specy.app/documentation/z80/io/char.md) `port 0x10`: Prints the byte as a Latin-1 character to the Terminal and, in drawing mode, at the Screen’s text cursor.
- [Unsigned number](https://asm-editor.specy.app/documentation/z80/io/number.md) `port 0x11`: Prints the byte as an unsigned decimal number, 0 to 255.
- [Signed number](https://asm-editor.specy.app/documentation/z80/io/signed.md) `port 0x12`: Prints the byte as a signed decimal number, -128 to 127.
- [Hexadecimal](https://asm-editor.specy.app/documentation/z80/io/hex.md) `port 0x13`: Prints the byte as two upper case hexadecimal digits.
- [16 bit number](https://asm-editor.specy.app/documentation/z80/io/word.md) `port 0x14`: Prints the 16 bit number made of the high byte of the port address (register B when using out (c),r) and the byte written, as an unsigned decimal number.
- [Screen](https://asm-editor.specy.app/documentation/z80/io/screen.md) `0x20 - 0x2A`: Drawing.
- [Screen commands](https://asm-editor.specy.app/documentation/z80/io/screen-commands.md): Written to the command port, 0x27.
- [Pixel](https://asm-editor.specy.app/documentation/z80/io/command-pixel.md) `command 0`: One pixel at (X, Y) in the pen color.
- [Line](https://asm-editor.specy.app/documentation/z80/io/command-line.md) `command 1`: A line from (X, Y) to (X2, Y2) in the pen color, leaving the drawing position at (X2, Y2).
- [Line to](https://asm-editor.specy.app/documentation/z80/io/command-line-to.md) `command 2`: A line from the drawing position to (X, Y), which becomes the new position: a polyline costs one command per point.
- [Move to](https://asm-editor.specy.app/documentation/z80/io/command-move-to.md) `command 3`: Moves the drawing position to (X, Y) without drawing.
- [Rectangle](https://asm-editor.specy.app/documentation/z80/io/command-rectangle.md) `command 4`: A rectangle from (X, Y) to (X2, Y2), filled with the fill color and outlined with the pen.
- [Rectangle outline](https://asm-editor.specy.app/documentation/z80/io/command-rectangle-outline.md) `command 5`: The same rectangle, outline only.
- [Ellipse](https://asm-editor.specy.app/documentation/z80/io/command-ellipse.md) `command 6`: The ellipse inscribed in that rectangle, filled and outlined like it.
- [Ellipse outline](https://asm-editor.specy.app/documentation/z80/io/command-ellipse-outline.md) `command 7`: The same ellipse, outline only.
- [Flood fill](https://asm-editor.specy.app/documentation/z80/io/command-flood-fill.md) `command 8`: Spreads the fill color from (X, Y) over every pixel of the color that was there, four ways.
- [Clear](https://asm-editor.specy.app/documentation/z80/io/command-clear.md) `command 9`: Fills the whole Screen with the fill color, homes the text cursor, and adopts that color as the background, so scrolled text rows and a later resize match what…
- [Resize](https://asm-editor.specy.app/documentation/z80/io/command-resize.md) `command 10`: Resizes the Screen to X by Y pixels and clears it; a coordinate of 0 means 256, the largest size a byte cannot hold.
- [Buffering on](https://asm-editor.specy.app/documentation/z80/io/command-buffering-on.md) `command 11`: Double buffering on: drawing goes to an off-screen copy of the visible image until PRESENT, so an animation never shows a half-drawn frame.
- [Buffering off](https://asm-editor.specy.app/documentation/z80/io/command-buffering-off.md) `command 12`: Double buffering off: drawing appears immediately.
- [Present](https://asm-editor.specy.app/documentation/z80/io/command-present.md) `command 13`: Shows the off-screen image.
- [Mode cells](https://asm-editor.specy.app/documentation/z80/io/command-mode-cells.md) `command 14`: Switches to the TRS-80 display.
- [Mode drawing](https://asm-editor.specy.app/documentation/z80/io/command-mode-drawing.md) `command 15`: Back to the drawing commands above.
- [The TRS-80 display](https://asm-editor.specy.app/documentation/z80/io/the-trs-80-display.md): Command 14 switches the Screen to the TRS-80 memory-mapped text display.
- [Colors](https://asm-editor.specy.app/documentation/z80/io/colors.md): A color is one byte: three bits of red in bits 7-5, three of green in bits 4-2 and two of blue in bits 1-0.
- [Pictures in files](https://asm-editor.specy.app/documentation/z80/io/pictures.md): A program can draw a picture kept in a file, such as a sprite sheet.
- [Pen color](https://asm-editor.specy.app/documentation/z80/io/screen_pen_color.md) `port 0x20`: Sets the color of pixels, lines, outlines and text, as one 3-3-2 byte (RRRGGGBB).
- [Fill color](https://asm-editor.specy.app/documentation/z80/io/screen_fill_color.md) `port 0x21`: Sets the color the inside of a filled shape, a flood fill and a clear use, as one 3-3-2 byte.
- [Pen width](https://asm-editor.specy.app/documentation/z80/io/screen_pen_width.md) `port 0x22`: Sets how many pixels wide lines and outlines are, at least 1.
- [X](https://asm-editor.specy.app/documentation/z80/io/screen_x.md) `port 0x23`: The first X coordinate: the pixel, the start of a line, the left edge of a shape, the width of a resize.
- [Y](https://asm-editor.specy.app/documentation/z80/io/screen_y.md) `port 0x24`: The first Y coordinate, the companion of the X port, and the height of a resize.
- [X2](https://asm-editor.specy.app/documentation/z80/io/screen_x2.md) `port 0x25`: The second X coordinate: the end of a line, the right edge of a shape.
- [Y2](https://asm-editor.specy.app/documentation/z80/io/screen_y2.md) `port 0x26`: The second Y coordinate, the companion of the X2 port.
- [Command](https://asm-editor.specy.app/documentation/z80/io/screen_command.md) `port 0x27`: Runs one drawing operation on the coordinates, colors and pen width already set.
- [Pixel color](https://asm-editor.specy.app/documentation/z80/io/screen_pixel.md) `port 0x28`: The color of the pixel at (X, Y) as a 3-3-2 byte, read from the image being drawn on — the off-screen one while double buffering.
- [Text cursor column](https://asm-editor.specy.app/documentation/z80/io/screen_cursor_column.md) `port 0x29`: Moves the text cursor to a column, in 8 by 8 character cells: 0 to 31 on the default Screen.
- [Text cursor row](https://asm-editor.specy.app/documentation/z80/io/screen_cursor_row.md) `port 0x2A`: Moves the text cursor to a row, in 8 by 8 character cells: 0 to 23 on the default Screen.
- [Keyboard](https://asm-editor.specy.app/documentation/z80/io/keyboard.md) `0x30 - 0x33`: Input from the focused Screen, polled: whether a typed character is waiting (read it from the character port), whether a given key is held, and the last key…
- [Typed input available](https://asm-editor.specy.app/documentation/z80/io/key_available.md) `port 0x30`: 1 when a character typed on the focused Screen is waiting to be read from the character port, else 0.
- [Key state](https://asm-editor.specy.app/documentation/z80/io/key_state.md) `port 0x31`: 1 while the key whose code is in B is held down, else 0.
- [Last key pressed](https://asm-editor.specy.app/documentation/z80/io/key_last_down.md) `port 0x32`: The code of the last key pressed on the Screen, 0 before the first press.
- [Last key released](https://asm-editor.specy.app/documentation/z80/io/key_last_up.md) `port 0x33`: The code of the last key released, 0 before the first release.
- [Mouse](https://asm-editor.specy.app/documentation/z80/io/mouse.md) `0x40 - 0x43`: Pointing input over the Screen, polled, in the same logical pixels drawing uses.
- [Mouse views](https://asm-editor.specy.app/documentation/z80/io/mouse-views.md): Put one of these in B before reading a mouse port.
- [Mouse X](https://asm-editor.specy.app/documentation/z80/io/mouse_x.md) `port 0x40`: The X of the view selected by B (0 current, 1 last release, 2 last press), in logical Screen pixels from the left edge, independently of how the panel is…
- [Mouse Y](https://asm-editor.specy.app/documentation/z80/io/mouse_y.md) `port 0x41`: The Y of the view selected by B, in logical Screen pixels from the top edge.
- [Mouse buttons](https://asm-editor.specy.app/documentation/z80/io/mouse_buttons.md) `port 0x42`: The buttons and modifiers of the view selected by B: bit 0 left, bit 1 right, bit 2 middle, bit 3 the double-click flag (only in the last-press view), bit 4…
- [Mouse event count](https://asm-editor.specy.app/documentation/z80/io/mouse_events.md) `port 0x43`: For the current view, how many mouse events have happened, as a byte that wraps around; for the two snapshot views, the count at the moment of the snapshot, 0…
- [Program time](https://asm-editor.specy.app/documentation/z80/io/time.md) `0x50 - 0x52`: Delay the program, synchronize animation frames, or read elapsed time.
- [Wait](https://asm-editor.specy.app/documentation/z80/io/time_wait.md) `port 0x50`: Waits B hundredths of a second, then answers 0.
- [Frame sync](https://asm-editor.specy.app/documentation/z80/io/time_frame.md) `port 0x51`: Waits for the next animation frame, then answers 0.
- [Elapsed time](https://asm-editor.specy.app/documentation/z80/io/time_now.md) `port 0x52`: One byte of the number of hundredths of a second since the run started, selected by B: 0 the lowest byte, 3 the highest.
- [Audio](https://asm-editor.specy.app/documentation/z80/io/audio.md) `0x60 - 0x64`: Play notes with a pitch, instrument sound, and volume, each numbered from 0 to 127, and a duration in milliseconds.
- [Sound](https://asm-editor.specy.app/documentation/z80/io/sound.md): The audio ports play notes with a pitch, instrument, volume, and duration.
- [Play a note](https://asm-editor.specy.app/documentation/z80/io/note_play.md) `port 0x60`: Writing a pitch starts a note and continues immediately, so notes can overlap.
- [Play a note and wait](https://asm-editor.specy.app/documentation/z80/io/note_play_wait.md) `port 0x61`: Read with in r,(c) and the pitch in B to play a note using the instrument, volume, and duration already set.
- [Instrument](https://asm-editor.specy.app/documentation/z80/io/note_instrument.md) `port 0x62`: Selects the instrument sound for later notes from the General MIDI list, numbered from 0 to 127: 0 is acoustic grand piano, 40 violin, 56 trumpet, and 73 flute.
- [Volume](https://asm-editor.specy.app/documentation/z80/io/note_volume.md) `port 0x63`: Sets the volume for later notes, from 0 (silent) to 127 (loudest).
- [Duration](https://asm-editor.specy.app/documentation/z80/io/note_duration.md) `port 0x64`: Sets the duration for later notes in milliseconds.
- [Sound chip](https://asm-editor.specy.app/documentation/z80/io/sound-chip.md) `0xA0 - 0xA2`: The AY-3-8910 is the sound chip used in the MSX, ZX Spectrum 128 and Amstrad CPC.
- [Select a Sound chip register](https://asm-editor.specy.app/documentation/z80/io/sound_chip_select.md) `port 0xA0`: Selects the register, 0 to 15, that the next writes to SOUND_CHIP_WRITE (0xA1) and reads from SOUND_CHIP_READ (0xA2) reach; it stays selected until the next…
- [Write a Sound chip register](https://asm-editor.specy.app/documentation/z80/io/sound_chip_write.md) `port 0xA1`: Writes the selected register.
- [Read a Sound chip register](https://asm-editor.specy.app/documentation/z80/io/sound_chip_read.md) `port 0xA2`: Returns the selected register as the chip holds it: what was last written, less the bits the register does not keep.
