The 6502 processor has been around for over 40 years and is still used in a number of embedded systems. WDC continues to manufacture 65C02 and 65Cxx series peripheral chips. The author has found that they are now available in PLCC and QFP packages, but these options for microcircuits are rarely used. Chips in the DIP-packages are no longer available, since the demand from the home-builders alone is too small. The author decided to make the smallest single-board on 6502, which only can. It is possible that the smallest known homemade single-board on this processor (there are less non-homemade ones, for example, Tamagotchi). The result is a device to which you can optionally develop a wrist case with a strap. The display is taken from the Nokia 5110, the shell is written with a beautiful interface, and it turned out, perhaps, the only smart watch on 6502.
The clock contains: a 65C02 processor with a clock frequency of 8 MHz, a 65C22 chip, control LCD and interrogating buttons on the board and an external keyboard, a display from Nokia 5110 (84x48 pixels), 32 KB of static RAM, 16 KB of ROM in the address space. Power supply - 3.3 V.
And most importantly: as a docking station, you can connect a keyboard matrix from Commodore 64 to the connector on the board, getting something similar to the Seiko UC-2000 ( overview on Habré ): ')
The layout and topology of the printed circuit board are compiled in KiCad. The dimensions of the double-sided board are 3x1.5 inches. All components are SMD, except for the PLCC panel, as well as connectors for the keyboard and LCD.
The topology in the illustration is not to scale. Board appearance before assembly:
On the clock you can run several built-in applications. One of them, G'Mon (Generic Monitor), is the main development and debugging tool. It allows you to view and edit the contents of the memory with individual cells and fragments, go to the programs, fill in the sections of RAM with a given byte, move the fragments to the address space. The version of the monitor used in the watch is simplified, so that besides it, the EhBasic fits in the ROM. He barely got there, only ~ 100 free bytes remained. The interpreter is altered in such a way that it was possible to combine it with the kernel. It, in turn, contains all the initialization routines, working with external interfaces, as well as the relationship of all existing software. And one more application - the main menu.
A significant amount of the core is occupied by the code that interacts with the LCD from Nokia 5110 using the software-implemented SPI protocol over 6522. The WriteBYTE and Command subroutines send graphic data and commands to the LCD, respectively. Since there is no hardware text mode, procedures for sending characters to the screen are written. The symbol generator is stored in the ROM and is represented by two lookup tables: one for the high byte and the other for the low byte. Together they indicate the absolute position of the initial byte of the character in the ROM. Write subroutine should be run after the ASCII code is written to the processor battery, and is also used as the X coordinate for lookup tables. The subroutine first writes the ASCII code to the screen buffer in memory. Then it searches for the corresponding tile data and sets a pointer to it. After displaying 8 consecutive bytes from the pointer, it calls the CCheck subroutine. That programmatically checks the position of the cursor, and if the screen is full, calls the Scroll subroutine that shifts the image one text line. Since the author did not implement reading from the LCD controller, the text is indexed according to the position of the cursor and is written to the buffer in memory. The Scroll subroutine displays the three bottom lines from the buffer to the top three lines on the LCD, then fills the bottom line with spaces. The remaining subroutine for working with LCD - CReturn. It searches the search table for the starting position of the next line, and if the current line is not the bottom, it increases the position of the cursor by one. If the line is lower, it calls the Scroll procedure, and only then it ends.
The keyboard is polled via the 6522 GetKey subroutine. It reads the keyboard matrix line by line and writes bytes to memory. If any bits turn out to be zero, it determines the ASCII code of the key pressed through the lookup table. Basically the code does not contain loops to work as fast as possible. Subroutines for converting specified bits to indexes do not use lookup tables, but as a result, the code is rather large and inefficient.
Video:
The author no longer works on this firmware, he switched to other projects. He hopes that the code will come in handy for those wishing to control the Nokia 5110 LCD from a 6502 single-board device. The corresponding subroutines are easily transferable to other software. The most important of them are Write, Write_NS, Command, WriteBYTE, LCDInit, LCDClear, CCheck, CCheck_NS, CReturn, Scroll and SETCursor. Other useful routines are LCDHome and WriteBMP. In memory, you need to place the variables LCDCursor, GTmp, GTmp5 and GTmp6, as well as the Screen table with a length of 84 bytes. In addition to these, you need CRTbl, CTableX and CTableY lookup tables, as well as Char and Char2 raster images with all tiles.
If you want to create other tile sets, use the templates from the Assets folder. In GIMP, export a bitmap image to a .data file in RGB (not RGBX) format. Do not pay attention to the .pal file, but place the .data file in the BitConvert folder from the archive. Run Convert.sh filename.data to get the file FONT.bin, which will be a set of tiles.