Pinecone Computer
Docs · Programmer's reference

Programmer's reference

The daisy module and the rest of PyCone's library: screen, pixels, characters, sound, keys, expansion, network and system.

Everything a PyCone program can ask of the Daisy: the screen and its colours, pixels and characters, the sound board, the keys, the expansion bus, the network and the system. Most of it is in the daisy module:

import daisy

Each topic is also in PyCone's built-in help: help('pline') at the prompt shows the one for daisy.pline. For the prompt, the editor and files, see the PyCone help; for how the boards behind these calls fit together, the architecture.

The screen is 40 columns by 25 rows of characters (or 80 columns, see daisy.columns), and 80 by 50 pixels for the pixel calls, each pixel a quarter of a character cell.

The screen#

daisy — The daisy Module#

import daisy brings the Daisy's own features: the screen of 40 by 25 character cells and 80 by 50 pixels, the character set, sound, the keyboard and joystick, the network and the clock. Each has a topic of its own, named for the function: help('pline'), or help(daisy.pline).

A cell of the screen is normal or reversed.

daisy.cls — Clear the Screen#

daisy.cls()

Clears the screen and puts the cursor at the top left.

daisy.reset_screen — Standard Screen#

daisy.reset_screen()

Puts the screen back as at power-on and clears it: no border or double buffer, scrolling on, normal video, the cursor advancing, every row text, and the font's own characters in place of any redefined; the colours PyCone's, white on blue with a light blue border. The editor does this when it opens.

daisy.locate / daisy.cursor — The Cursor#

daisy.locate(col, row)  # print here
daisy.cursor()          # (col, row)

Columns are 0 to 39 and rows 0 to 24.

daisy.reverse / daisy.normal — Reverse Video#

daisy.reverse()      # text printed
daisy.normal()       # and back
daisy.reverse(True)  # the screen
daisy.normal(True)   # and back

daisy.plotchar / daisy.charat — One Cell#

daisy.plotchar(col, row, code)
daisy.charat(col, row)  # its code

plotchar sets one cell's character without moving the cursor or changing the cell's reverse video.

daisy.setattrib / daisy.attribat — Reversed Cells#

daisy.setattrib(col, row, 1)
daisy.attribat(col, row)  # 1 or 0

setattrib reverses one cell, its colours the pen's swapped, or with 0 gives it the pen's; attribat says whether it holds the pen's colours swapped.

daisy.fillcells / daisy.hline / daisy.vline — Runs of Cells#

daisy.fillcells(col, row, code, n)
daisy.hline(x1, x2, y, code)
daisy.vline(x, y1, y2, code)

fillcells fills n cells from (col, row), running on into the rows below. hline and vline fill a row or a column between two places.

daisy.box — Text Box#

daisy.box(x1, y1, x2, y2)     # frame
daisy.box(x1, y1, x2, y2, 0)  # erase

A frame of box-drawing characters, its corners at the cells given.

daisy.line — Character Line#

daisy.line(x1, y1, x2, y2, code)

A straight line of one character from cell to cell, either way. Its cells off the screen are left out, so it may start or end off the screen, up to 32,767 cells off. As DaisyBASIC's LINE.

daisy.fillblock / daisy.checkblock — Blocks of Cells#

daisy.fillblock(x, y, w, h, code)
daisy.fillblock(x, y, w, h, a, b)
daisy.checkblock(x, y, w, h)

fillblock fills the w by h cells at (x, y) with one character, or with the characters from a to b in turn, over and over, a row at a time. b one less than a goes through every character. The corner is on the screen; the block may run off the right or the bottom. checkblock is True if any cell of the block holds a character other than a space or 0, to see whether there is room for a sprite. As DaisyBASIC's FILLBLOCK and CHECKBLOCK.

daisy.scroll — Stop Scrolling#

daisy.scroll(False)  # stays put
daisy.scroll(True)   # scrolls
daisy.scroll()       # which

When printing passes the bottom row the screen scrolls up a row. With scroll(False) it does not, and the cursor stays on the bottom row, so a program can print there without moving the rest. reset_screen turns scrolling back on. DaisyBASIC's SCROLL ON is scroll(False).

daisy.moveblock — Move a Block#

daisy.moveblock(x1, y1, x2, y2, w, h)

Copies the w by h cells at (x1, y1) to (x2, y2), overlapping or not, in one message to the video board. A seventh argument fills the cells the block left with that character: 32, a space, clears them. It moves a sprite fast.

daisy.saveblock / daisy.restoreblock — Keep a Block#

b = daisy.saveblock(x, y, w, h)
daisy.restoreblock(x, y, w, h, b)

Keeps the characters, colours and sets of a block of cells, and puts them back. A dialog keeps what it covers this way.

daisy.scrollx / daisy.scrollxp — Sideways Scrolling#

daisy.scrollx(y, height, -1)  # left
daisy.scrollx(y, height, 1)   # right
daisy.scrollxp(y, height, px)

scrollx moves rows a cell, the cell falling off one end coming round at the other. scrollxp slides the picture of the rows by -7 to 7 pixels, seen with the border on; a fourth argument moves them whole cells too. scrollxp(y, height, 0) puts the rows back.

daisy.border — The Border#

daisy.border(True)
daisy.border(False)

The border shows the column hidden at each side, for smooth sideways scrolling. Turning it off puts scrolled rows back.

daisy.pen — Colours#

daisy.pen(2, 6)   # red on blue
print('RED ON BLUE')
daisy.pen(1, 0)   # white on black
daisy.pen()       # (1, 0)

PyCone starts white on blue (1, 6), as the editor does. What is written from now on is drawn in a foreground and a background, each 0 to 15, from its row's bank of the palette. Clearing the screen and scrolling use the pen too. At first every bank holds the Commodore 64's colours: 0 black, 1 white, 2 red, 3 cyan, 4 purple, 5 green, 6 blue, 7 yellow, 8 orange, 9 brown, 10 light red, 11 dark grey, 12 grey, 13 light green, 14 light blue, 15 light grey. reverse() swaps the pen's two colours, and setattrib a cell's.

daisy.palette / daisy.rowbank — The Palette#

daisy.palette(2, 1, 0xFFFF00)
daisy.rowbank(5, 2)  # row 5: bank 2
daisy.palette(2, 1)  # its colour

The palette is four banks of 16 colours, each given as 0xRRGGBB and kept as the board keeps it (5, 6 and 5 bits). Each of the 25 rows draws from one bank, 0 to begin with, so up to 64 colours show at once. rowbank(row) gives a row's bank.

daisy.multipen / daisy.fillmulti — Multicolour#

daisy.multipen(2)      # red third
daisy.plotchar(3, 5, 128)
daisy.multipen(None)   # plain again
daisy.fillmulti(0, 10, 40, 2, 4)
daisy.fillmulti(0, 10, 40, 2, None)

A multicolour cell draws its character as four wide pixels a row, two bits each, the leftmost first: 00 the cell's background, 01 its third colour, 10 its row's shared colour (rowcolours), 11 its foreground, each 0 to 15 from the row's bank, as the C64's multicolour characters. multipen(c) makes what is written from now on multicolour with third colour c, and multipen(None) plain; multipen() gives it. fillmulti makes a block's cells multicolour, or plain, keeping their characters and colours. Pixels drawn in a cell make it plain.

daisy.rowcolours / daisy.rowcolour — Shared Colours#

daisy.rowcolours(10, [5, 13])
daisy.rowcolour(10)      # 5
daisy.rowcolour(10, 7)

Each row's shared multicolour colour, 0 to 15 from its bank, the pair 10 of its multicolour cells. All 0 at first.

daisy.setcycle / daisy.cycle — Colour Cycling#

daisy.setcycle(0, 2, 5, 30)
daisy.cycle(0, 'on')
daisy.cycle([0, 1], 'off')
daisy.cycle(0, 'reset')
daisy.cycle(0)  # (2, 5, 30, 0, True)

Eight channels, 0 to 7, each turning a run of palette entries, first to last (0 to 63, bank * 16 + colour), one place every speed frames (60 a second), upward, or downward with a fifth argument of 1. What is drawn in those colours moves without being drawn again: water, fire, lights. cycle starts the channels named together, stops them where they are, or puts their colours back; setcycle leaves a channel on or off. reset_screen stops them all.

daisy.bordercolour — The Border's Colour#

daisy.bordercolour(5)   # green
daisy.bordercolour()

The colour, 0 to 63 (bank * 16 + colour), of the border, the edges a sideways scroll slides in from, and the bars above and below the picture. Light blue (14) at PyCone's prompt and in the editor.

daisy.charset — The Set Written#

daisy.charset(daisy.GFX)
daisy.plotchar(4, 10, 66)  # graphics
daisy.charset(daisy.CHAR)

The set, daisy.CHAR or daisy.GFX, characters are drawn from as they are written: print, plotchar, fillcells and the rest. Each cell keeps its own set, as it keeps its colours; charmode changes the cells already on rows. The text set to begin with.

daisy.doublebuffer / daisy.flip — Drawing Unseen#

daisy.doublebuffer(x, y, w, h)
daisy.flip()  # show what was drawn

x, y, w and h are in pixels. What is drawn in the region shows only at flip, so an animation does not flicker. A fifth argument, False, shows it and ends it.

Pixels#

daisy.pplot / daisy.point — One Pixel#

daisy.pplot(x, y)     # on
daisy.pplot(x, y, 0)  # off
daisy.pplot(x, y, 2)  # dithered
daisy.point(x, y)     # 0, 1 or 2

Pixels are 0 to 79 across and 0 to 49 down: each character cell holds two by two of them.

daisy.pline — Lines and Boxes#

daisy.pline(x0, y0, x1, y1)
daisy.pline(x0, y0, x1, y1, 0)
daisy.pline(x0, y0, x1, y1, 1, 'B')

A line, on or, with 0, off. With 'B' it draws the outline of the rectangle between the corners, and with 'BF' all of it.

daisy.pcircle — Circles and Arcs#

daisy.pcircle(x, y, 10, 10)
daisy.pcircle(x, y, 9, 6, 1, 0, 90)
daisy.pcircle(x, y, 8, 8, fill=True)

An ellipse around (x, y) with radii across and down, the pixels' value next. Two angles more, in degrees, draw only the arc between them.

daisy.pfill — Flood Fill#

daisy.pfill(x, y)
daisy.pfill(x, y, 2)  # dithered

Fills the area around (x, y) that is not already that value.

daisy.ppoly — Polygons#

daisy.ppoly([(10, 10), (40, 30),
             (10, 40)])
daisy.ppoly(old, new)

With two lists of points, it erases the first shape and draws the second in one message, so a moving shape does not flicker.

Characters#

daisy.defchar / daisy.defgfx — Define Characters#

daisy.defchar(128, [0x18, 0x3C,
    0x7E, 0xFF, 0x18, 0x18])

Redefines a character: up to eight rows, the top first, each a number whose top bit is the leftmost pixel. Rows not given stay as they were. defgfx redefines one of the graphics set. Codes from 128 suit a program's own characters; game.glyph draws one from strings.

daisy.resetchar / daisy.resetgfx — Restore Characters#

daisy.resetchar(128)  # one
daisy.resetchar()     # all of them

resetgfx blanks one of the graphics set, or all: it has no ROM font.

daisy.charmode — Rows from a Set#

G = daisy.GFX
daisy.charmode(G, 10)      # row 10
daisy.charmode(G, 10, 12)  # 10 to 12
daisy.charmode(daisy.CHAR, 10)

The Daisy has two character sets: daisy.CHAR, the text set, and daisy.GFX, the graphics set, which defgfx fills. Each cell is drawn from one of them. charmode draws the cells now on rows first to last from the set given; a last below first means first alone, and one past the bottom the bottom row. What is written later takes the set charset chose. cls() puts every cell in the current set.

daisy.copychar — Copy Characters#

C, G = daisy.CHAR, daisy.GFX
daisy.copychar(C, G, 65, 90)  # A-Z
daisy.copychar(G, G, 128, 129)

From one set to the other, characters start to end (or start alone) are copied onto the same codes there. Within one set, character start is copied onto character end. As DaisyBASIC's COPYCHAR.

daisy.loadc / daisy.savec — Font Files#

G = daisy.GFX
daisy.savec('/sd/my.chr', G)
n = daisy.loadc('/sd/my.chr', G)
daisy.loadc('/rom/demos/bach.chr',
            G, 128)

A font file is the characters' rows, eight bytes each, as savec writes them: a set from character first (0 unless given) to 255, onto a file on /sd or /net, replacing one there. loadc puts a file's characters into a set from first on, as many as the file holds and fit, and gives how many; it reads files in /rom too. The set is daisy.CHAR unless given. As DaisyBASIC's LOADC and SAVEC. A file named CHARROM.CHR or GFXROM.CHR at the top of the card, a whole set, is loaded at power-on.

Sound#

daisy.beep / daisy.click — Beeps#

daisy.beep()        # a short beep
daisy.click(True)   # a key click
daisy.click(False)  # none

daisy.sound — A Tone#

daisy.sound(voice, freq, ms)
daisy.sound(0, 440, 500, True)

voice is 0, 1 or 2 (any other is a ValueError); freq is in hertz and ms in milliseconds. With a fourth argument, True, it waits for the tone to end.

daisy.soundpwm — Pulse Width#

daisy.soundpwm(0, 64)    # thin
daisy.soundpwm(0, 128)   # square
daisy.soundpwm(1, 128, 4)  # sweep

The shape of voice 0 or 1's tone: how much of each cycle, 0 to 255, its pulse is high; 128 is a square wave, and nearer 0 or 255 is thinner and brighter. With a third number, 0.01 to 655.35 hertz, a slow sweep moves the width on its own, from 64 to 191 and back, for a moving, chorused sound; 0 stops it. As DaisyBASIC's SOUNDPWM.

daisy.soundport — Glide#

daisy.soundport(0, 300)  # glide
daisy.sound(0, 440, 2000)
daisy.sound(0, 880, 2000)
daisy.soundport(0, 0)    # no glide

Voice 0 or 1 slides from one note's pitch to the next's over ms milliseconds, 0 to 65535, instead of jumping (portamento); 0 turns it off. As DaisyBASIC's SOUNDPRT. shush() with no voice puts both back: a square wave and no glide.

daisy.play — Tunes#

daisy.play('T180 L8 CDEFGAB>C')

Plays music written as notes, in the background:

daisy.shush — Stop Sound#

daisy.shush()   # every voice
daisy.shush(1)  # voice 1

The voice is 0, 1 or 2; any other is a ValueError.

daisy.envelope / daisy.volume — Shaping Sound#

daisy.envelope(0, 10, 200, 128, 300)
daisy.volume(0, 160)  # voice 0
daisy.volume(200)     # everything

envelope shapes each note a voice plays, given the voice, then attack, decay, sustain and release: the note rises over the attack, in milliseconds, falls over the decay to the sustain (0 to 255), holds while it lasts, and fades over the release when it ends. 0, 0, 255, 0, the start, is no shaping at all. volume(voice, level) sets one voice's loudness, 0 to 255, and volume(level) the whole sound board's, songs included.

daisy.say / daisy.speaking — Speech#

daisy.say('Welcome to Daisy!')
daisy.say('/P AY1 N K OW2 N .')
daisy.speaking()
daisy.say()

The sound board reads English aloud, in a woman's voice, over any music, while the program goes on: up to 255 characters, about 200 of them said. Numbers are read as words, short capitals spelled (CPU), and , . ? ! give its pauses, a question rising at the end. Text after a "/" is speech sounds, for a word English spelling gets wrong (the second line says "Pinecone"): ARPAbet, the CMU dictionary's spelling, a digit on each vowel, 1 stressed, 0 not. speaking() is True while it talks, and raises if the board could not read the text; say() stops it. On the Pico Daisy only.

daisy.vgm — Songs from a File#

daisy.vgm('/sd/tune.vgm')
daisy.vgm('/sd/tune.vgm', 255)

Plays a VGM song (a recording of a Sega or BBC sound chip, the SN76489 the sound board copies) from /sd or /net, sent to the board as it plays, while the program goes on. A second number plays its looped part that many more times, 255 for ever. vgmstop() stops it; while a song plays, the voices are silent.

daisy.vgmload / daisy.vgmplay — Kept Songs#

daisy.vgmload(1, '/sd/tune.vgz')
daisy.vgmplay(1)       # once
daisy.vgmplay(1, 255)  # for ever

vgmload(id, path) sends a VGM song, or a gzipped one (.vgz), to the sound board, from any drive, and keeps it there as song id, 0 to 254; it gives the song's length and the point its loop starts from, in milliseconds (None for no loop). The board holds 160 KB of songs, at most 25. vgmplay(id, loops, start) plays one, from start ms.

daisy.vgmseek / daisy.vgmpos / daisy.vgmstop — Song Control#

daisy.vgmseek(30000)  # 30 s in
daisy.vgmpos()        # (1, 30012)
daisy.vgmstop()

vgmseek(ms) jumps the song playing; vgmpos() gives its id and where it is, or None. vgmstop() stops it, a song streamed or kept; one kept stays loaded.

daisy.vgmlist / daisy.vgmdelete — The Board's Songs#

daisy.vgmlist()      # (free, [...])
daisy.vgmdelete(1)   # song 1
daisy.vgmdelete()    # all of them

vgmlist() gives the bytes free and, for each song kept, its id, size and length in ms.

daisy.voices — What Is Playing#

daisy.voices()

The sound board's voices as it plays them: (source, list), source 0 for the three voices and 1 for a song's four channels; for each, flags (1 sounding), its period, its pitch in hertz, its gain (0 to 255) and its pulse width.

Keys and joystick#

daisy.get / daisy.getkey — Reading Keys#

k = daisy.get()     # 0 if none
k = daisy.getkey()  # waits for one

The code of the next key typed. BREAK raises KeyboardInterrupt in either. The cursor keys give UP 1, RIGHT 2, DOWN 3 and LEFT 4; RETURN gives 13.

input — Typing a Line#

name = input('Your name? ')

Python's own input reads a line from the Daisy's keyboard. BREAK raises KeyboardInterrupt.

daisy.keydown / daisy.pressed — Keys Held#

daisy.keydown(32)    # SPACE held?
daisy.pressed(6, 7)  # J by its place

keydown is True while a key that types the code is held, counting a key whose AC or CTRL combination types it: - with CTRL is cursor up, so keydown(1) is True while - is held. pressed names a key by its place on the XEGS keyboard's matrix, whatever modifier is held: its Atari code with the six bits inverted, column code & 7 and row code >> 3, so A is (0, 0) and L (7, 7). Row 8 is BREAK (0, 8), SHIFT (2, 8) and CTRL (3, 8); the Atari key is (0, 3).

daisy.key — Function Keys#

daisy.key(1, 'run()\n')

Sets what CTRL+1 to CTRL+8 type: up to 16 characters, a newline giving RETURN. They are empty until set, and forgotten at a reset.

daisy.joy / daisy.joyhit — Joystick#

daisy.joy()      # all, as bits
daisy.joy(5)     # 1: trigger held
daisy.joyhit(5)  # 1: pressed since

Buttons are 1 up, 2 down, 3 left, 4 right and 5 the trigger. joy() gives them all as bits: 1 up, 2 down, 4 left, 8 right and 16 the trigger. joyhit says whether a button was pressed since it was last asked. The Pico Daisy has no joystick port yet: both give 0, and game.stick() reads the keys.

Expansion#

machine.I2C / i2c — Expansion Bus#

from machine import I2C
i2c = I2C(1)       # 400 kHz
i2c.scan()         # [80]: answering
i2c.readfrom_mem(0x50, 0, 4)
i2c.writeto_mem(0x50, 0, b'hi')
i2c.readfrom(0x50, 2)
i2c.writeto(0x50, b'\x00')

The Pico Daisy's expansion connector is an I2C bus: SDA on GP26, SCL on GP27, with 3V3 and ground, in Qwiic order, so ready-made sensor and controller boards plug in. I2C(1) is that bus, with MicroPython's own methods, so drivers written for MicroPython work unchanged: give them the I2C object. readfrom_mem(0x50, 0, 4) reads 4 bytes from register 0 of the device at 0x50; I2C(1, freq=100000, timeout=50000) sets the speed and how long, in microseconds, a transfer may wait. Also readfrom_into, readfrom_mem_into and, for 16-bit registers, addrsize=16. An address that does not answer raises OSError ENODEV, a bus held too long ETIMEDOUT.

daisy.srq — A Device Asking#

if daisy.srq():
    data = i2c.readfrom(0x20, 1)

The connector's fifth wire, SRQ, is pulled low by a device with something to report: srq() is True while it is, so a program asks the device only then, not over and over.

Network#

The Daisy's WiFi modem runs TCP/IP itself, so a program keeps its memory and speed while it uses the network. The modules are MicroPython's own, as on other boards, within what the modem can do: plain TCP only (no UDP, no https, no servers), and one connection at a time, which /net uses too.

network — Joining a Network#

import network
w = network.WLAN(network.WLAN.IF_STA)
w.connect('name', 'password')
w.isconnected()
w.ifconfig()
w.config('mac')
w.config('ssid')
w.scan()

connect joins and returns once joined, and the modem keeps the network over a power cycle. A name with a comma or a quote, or a password with a quote, cannot be joined. config('ssid') is the name the modem keeps in its settings: empty when it joined a network its WiFi chip remembers on its own (after its settings were reset, say), until connect is used once. ifconfig() gives (address, subnet, gateway, DNS), the last three "0.0.0.0" on DHCP, which the modem cannot report. scan() gives a tuple for each network in range: name, b'', 0, signal (dBm), 3 if secured or 0, and False.

ifconfig / ipconfig — Fixed Settings#

w.ifconfig(('192.168.1.50',
    '255.255.255.0', '192.168.1.1',
    '192.168.1.1'))
w.connect('name', 'password')
w.ifconfig('dhcp')

Fixed settings are kept for the next connect: address, subnet, gateway and DNS server, all four. ipconfig(addr4=(ip, mask), gw4=gw) and ipconfig('addr4'), 'gw4' and 'dhcp4' work too; ipconfig(dhcp4=True) goes back to DHCP.

socket — TCP#

import socket
ai = socket.getaddrinfo('host', 23)
s = socket.socket()
s.settimeout(5)
s.connect(ai[0][-1])
s.write(b'hello\r\n')
s.readline()
s.close()

The modem looks a name up as it dials, so getaddrinfo gives a stand-in address (0.0.x.y) that connect turns back into the name; one kept while several other names are looked up stops working (EHOSTUNREACH). A second connection, or /net while a socket is open, fails with EALREADY. UDP, bind and listen fail with EOPNOTSUPP. recv and readline wait as settimeout says, and BREAK stops them.

requests — Web Pages#

import requests
r = requests.get('http://a.com/')
r.status_code
r.text
r.json()
r.headers
r.save()

Plain http only: an https:// page, or a page that sends you to one, raises OSError. A new request closes the last response if it is still open. r.text is for UTF-8 pages; another charset is named in the error, and r.content has the bytes.

r.save — Big Pages#

name = r.save()
r.save('/sd/page.html')

A page is read into memory whole by content, text and json: one too big for it raises MemoryError saying so. r.save() writes a page of any size to a file, a little at a time, and returns its name: from the URL with none given (index.html for /), never over a file there (page-1.html), or the path given. A page comes at about 4 KB a second.

umqtt.simple — MQTT#

from umqtt.simple import MQTTClient
c = MQTTClient('daisy', 'broker')
c.connect()
c.publish(b'topic', b'hello')
c.disconnect()

MicroPython's MQTT client, to a broker on port 1883: no TLS.

ntptime — The Time#

import ntptime
ntptime.settime()
ntptime.time()

Sets the Daisy's clock to UTC. The time comes from the modem's own clock when the modem has heard from NTP, and otherwise from a web server's clock, ntptime.host ('google.com'; 'name:port' works too). time() gives seconds since 1970, as time.time() counts.

net — TCP in Lines#

import net
net.connect('bbs.a.com', 23)
print(net.readline(5000))
net.sendline('hello')
net.close()

For a telnet BBS or a server of your own. send sends bytes or a str as they are, and sendline a line with CR LF after it. readline(ms) waits up to that long for a line, None if none came, and recv(n, ms) up to that long for up to n bytes. connected() says whether the other end is still there.

tnfs — A TNFS Server#

tnfsd /home/me/daisy     # on the PC
daisy.netconnect('10.0.0.9', 16384)

/net is a folder on another computer, served by TNFS, the file server of FujiNet and the Spectranet. tnfsd is its server: from github.com/FujiNetWIFI/spectranet, in tnfs/tnfsd, make OS=LINUX (or BSD for a Mac, Windows_NT for Windows), then tnfsd FOLDER. It listens on port 16384, TCP as the Daisy uses it; the PC's firewall must let the Daisy in on that port. netconnect.ini on the card (host= and port= lines) names it, so daisy.netconnect() with nothing reaches it.

Files are read, written, appended to, sought in, renamed, copied and removed there as on the card; folders are made, listed and changed into. A name is at most 64 characters; a path, the current folder's with it,

  1. The Daisy keeps its own current folder, starting at the top on each connection. The modem's one connection is shared: while a socket or DaisyTerm holds it, /net has nothing.

daisy.netconnect / daisy.tnfsconnect / daisy.netconnected / daisy.netdisconnect — The File Server#

daisy.netconnect('10.0.0.9', 16384)
daisy.tnfsconnect(host, port)  # same
daisy.netconnect()  # netconnect.ini
daisy.netconnected()
daisy.netdisconnect()

Dials a TNFS server over TCP (tnfsd, on TNFS's port 16384), which makes /net its folder; tnfsconnect is another name for netconnect. With no host, it dials the server named in netconnect.ini on the card. Any connection open is hung up first, but one a socket holds is refused (EALREADY).

daisy.resetwifi — Restart the Modem#

daisy.resetwifi()  # True once ready

Restarts the WiFi modem, its reset line pulsed, and waits while it starts and joins its network, about 7 seconds, up to 20: True once it says it is ready, False if it did not. Every connection it held is gone. The Daisy never resets the modem itself, at power-on or CTRL+D: a connection left open is hung up instead.

daisy.carrier — A Connection Open#

daisy.carrier()  # True or False

True while the modem holds a connection open, to any server: TNFS, net, a socket, or a call DaisyTerm dialled. It is the modem's carrier line (its GPIO2, wired to the main board), so it is known at once, even in a call, without asking the modem anything.

System#

daisy.settime / daisy.setdate — The Clock#

daisy.settime(14, 30, 0)  # h m s
daisy.setdate(28, 10, 2026)

The clock keeps its time while the Daisy is off; time.localtime() reads it. setdate takes the day, the month and the year.

daisy.timer — Every So Often#

daisy.timer(0, 500, tick)  # 0.5 s
daisy.timer(0)    # stop timer 0
daisy.timer()     # stop all four

Four timers, 0 to 3, each calling a function with no arguments every so many milliseconds while the program runs: between its statements, in a sleep and while getkey waits. A function is not called again until it returns, so keep it short. The timers stop when the program or the line typed at the prompt ends, at BREAK, and at an error, one in the function too, which ends the program as any error does. They are DaisyBASIC's TIMER, kept by the same part of DaisyOS.

def tick():  # a spinner, top right
    global n
    n += 1
    c = '|/-\\'[n % 4]
    daisy.plotchar(39, 0, ord(c))
n = 0
daisy.timer(0, 250, tick)

builtins — Built-in Functions#

Python's own functions, always there without an import:

The errors they raise are in help('errors').

time — Time#

time.sleep(1)          # seconds
time.sleep_ms(500)
time.ticks_ms()        # a count
time.ticks_diff(b, a)  # b - a
time.localtime()
time.time()

localtime gives (year, month, day, hours, minutes, seconds, weekday, yearday), and time the seconds since 1970. gmtime is localtime, and mktime turns such a tuple back into seconds. time_ns counts in nanoseconds. sleep_us and ticks_us are in microseconds, ticks_cpu in the processor's own ticks, and ticks_add(t, ms) moves a count on. BREAK stops a sleep.

random — Random Numbers#

random.randint(1, 6)  # 1 to 6
random.random()       # 0 up to 1
random.choice(['a', 'b'])

Also randrange, uniform, getrandbits and seed.

math — Mathematics#

math has sqrt, sin, cos, tan, asin, acos, atan, atan2, pi, e, exp, log, pow, floor, ceil, trunc, fabs, fmod, modf, frexp, ldexp, copysign, degrees and radians, and isfinite, isinf and isnan to test a number. Angles are in radians.

gc / sys — The Interpreter#

gc.mem_free()  # bytes free
gc.collect()   # free the unused
sys.path       # where import looks
sys.version

gc.mem_alloc gives the bytes in use. gc.disable and gc.enable stop and start freeing memory when it runs short, gc.isenabled says which, and gc.threshold(n) frees it after n bytes more are taken.

micropython.heap_lock() stops any memory being taken: whatever needs some raises MemoryError until micropython.heap_unlock(). A statement, or a program run from the editor, that leaves it locked has it unlocked when it ends.

sys.exit() stops a program with SystemExit. sys.modules holds the modules imported from files. sys.print_exception(e) prints an error's traceback. sys.platform is 'daisy'; sys.argv, sys.byteorder, sys.implementation and sys.version_info are as in Python.

daisy.version — Version#

daisy.version()

DaisyOS's version, as the banner shows it.

daisy.frame / daisy.frames — Frames#

n = daisy.frame()   # None at first
time.sleep_ms(500)
daisy.frame() - n   # about 30

The count of frames the screen has shown, 60 a second, from DaisyVideo+. The first call turns the count on, and gives None until it has started; so does a board that does not count. It goes 0 to 65535 and round again, so take the difference of two, modulo 65536. game.tick waits on it. daisy.frames() gives the same count widened to 32 bits, which does not go round; game's sprites work out where they are from it.

petscii — Commodore Pictures#

import petscii
petscii.show('/sd/art.seq')
petscii.write(b'\x93\x05HI')
petscii.done()

show(path) shows a PETSCII file (a .seq, as BBS art is kept) as a Commodore 64 shows it, on a clear screen, then waits for a key and puts text back; show(path, False) leaves it showing. write(data) writes PETSCII bytes at its own cursor: the colour codes, reverse, clear, home, the cursor keys, delete and insert work as on a C64. Both load /rom/lib/petscii/petscii.chr, a clean-room C64 font, into the graphics set; font(False) chooses upper case and graphics, as the file's 0x8E does. done() puts the text set, the font and the pen back. 40 columns only. show(path, rate=2400) and write(data, rate=2400) draw no faster than a modem of that many bits a second, as the art was made to be seen.

ansi — PC Pictures#

import ansi
ansi.show('/sd/art.ans')
ansi.show('/sd/art.ans', rate=9600)
ansi.write(b'\x1b[1;33mHI')
ansi.done()

show(path) shows an ANSI file (a .ans, as BBS art is kept) as a PC shows it, on the 80-column screen in a PC's 16 colours, then waits for a key and puts everything back; show(path, False) leaves it showing. write(data) writes ANSI bytes at its own cursor: the cursor's moves, clearing, colours, bright and iCE backgrounds, CP437's characters; a file's end (0x1A, before its SAUCE record) stops it. Both load /rom/lib/ansi/cp437.chr, DaisyTerm's CP437 font, into the text set from 128. rate paces them as petscii does. done() puts the font, the colours, the pen and the width back.

daisy.columns — 80 Columns#

daisy.columns(80)   # 80 wide
print('x' * 80)     # one row
daisy.columns()     # 80
daisy.columns(40)   # back

columns(80) shows the 80-column screen, 80 by 25 characters in the 16 colours of bank 0, clear; columns(40) brings the 40-column screen back as it was left, and columns() says which shows. In 80, print, input, the prompt, the editor, help, more and daisyui's dialogs use the whole width; the line at the prompt is typed in place (LEFT and RIGHT, BACKSPACE, DEL, UP for the line before) but the cursor cannot go up the screen to an earlier line. cls, locate, cursor, pen, reverse, normal, plotchar, fillcells, fillblock, moveblock, setattrib, saveblock and restoreblock work there too (saveblock's block stays on the board, to put back last first). Reading cells (charat, attribat, checkblock), character lines and boxes, charset, charmode and the 40-column screen's reverse are "40 columns only" there. Pixels, sprites, multicolour and row banks belong to the 40-column screen, shown when it comes back; palette, glyphs, sound and the rest carry on. A soft reset (CTRL+D) comes back in 40; reset_screen stays in 80.

The prompt, the editor and programs each keep their own width. The prompt keeps the one it was left in (CTRL+8, or columns(80) typed there); the editor keeps its own, 40 until changed, with its place. A program, run with daisy.run or the editor's Compile and run, always starts in 40, on a clear screen if 80 showed, and is in 80 only if it calls columns(80). After it the editor, or the prompt, comes back in its own width; at the prompt, a program that left the other width waits for a key first, so what it showed, or its error, can be read. CTRL+8 and CTRL+4 do the same from the keyboard, at the prompt (a fresh prompt, and a clear screen in 40) or in the editor, unless daisy.key has set them to type text.

daisy.hold / daisy.waitvbl — Smooth Changes#

daisy.hold()        # keep showing
daisy.cls()         # ...redraw...
daisy.hold(False)   # show it all
daisy.waitvbl()     # the next frame

hold() keeps the screen showing its last frame while a program changes it, however much it changes, and hold(False) shows it all together, so a redraw never shows half done: on the next frame, or the one after if the board was just then showing the held one again (two waitvbl()s make sure). Time goes on while held: colours cycle, sprites move, the frame count counts. A hold lets go by itself after a second, or after limit frames (1-255) with hold(True, limit); reset_screen lets it go too. waitvbl() waits for the screen's next frame, for small changes and steady pacing; False if no frame came.

daisy.sprite / daisy.spriteread / daisy.spritepending — Sprites#

daisy.sprite(0x7B, bytes(5))
b = bytearray(45)
daisy.spriteread(0x35, b'\0\1', b)
daisy.spritepending()  # (hits, ...)

What game.Shape and game.Mob are made of: sprite(id, data) sends a sprite message to the video board as it is (DaisyVideo's docs/sprites.md lays each out), spriteread(id, args, out) asks the board and gathers its answer into out, giving (bytes, frame), and spritepending() gives (newly hit, newly touched text, signalled) as bit masks since it was last asked. DaisyOS keeps no copy of sprites.

daisy.run — Run a File#

daisy.run('/sd/game.py')

Runs the program in a file as if typed at the prompt: what it defines stays afterwards. It is read as it is compiled, so its text never sits in memory whole.

daisy.traceback — Where an Error Was#

try:
    daisy.run('/sd/game.py')
except Exception as e:
    print(daisy.traceback(e))

The files and lines an exception passed through, as (file, line) pairs, the line it was raised in last.

daisy.rom_import — Fresh From /rom#

ui = daisy.rom_import('daisyui')

A module as /rom has it, or the firmware for a built-in one, whatever a program changed in a copy already loaded or did to sys.path, and whatever the card holds by that name. sys.modules and sys.path are left as they were, so the module is not kept there: each call loads it again. AC+Z gets the editor, its dialogs and help this way.

daisy.menu — Back to the Menu#

daisy.menu()

Ends the statement or program, stops MicroPython and gives back all its memory, and shows the start menu at once: files are closed, a socket is hung up (a TNFS server stays connected), sprites, colours, fonts and the screen's modes are as at power-on, and every voice and song stops, the sound's settings as at power-on. No board restarts. Choosing Python starts PyCone afresh. The editor's Exit to Menu does the same. SHIFT+AC+SPACE+RETURN, held together, restarts the whole Daisy at any time.

daisy.rom_install — Replace /rom#

daisy.rom_install('/sd/my.rom')

Writes a ROMFS image from the card or /net into flash bank 1, then starts PyCone again with it at /rom. It replaces everything there, the editor and help among it, unless the image brings them. An image over 152 KB is refused: the rest of bank 1 holds the menu, DaisyTerm and MicroPython's compiler.

Updated 2026-12-04