A clone of the famous Tetris, written in assembler. It fits entirely into 512 bytes of boot sector (it only needs 446 bytes of space, which is just maximum size bootloader in MBR).

MBR - a section containing the code and data necessary for the subsequent boot of the operating system and located in the first physical sectors. The very first 446 bytes of the disk are given to the bootloader code. It is in this place that TetrOS is recorded.

Naturally, due to such properties, it is loaded before any operating system- it does not require any OS, it works by itself. Yes, you heard right, TetrOS is its own bootloader.

This is how it looks on the screen:

And the source on the boot sector looks like this:

And yes it is the whole source. Do you remember that it weighs only 446 bytes?

It is possible to run this "wonder operating system" under qemu or even install it for real on boot partition disk or flash drive.

launch

Just install qemu:

sudo apt-get install qemu

and run:

Download to flash drive

Copy the image to a flash drive. Let's say if the flash drive is mounted as /dev/sde , you need to run the following command to write to it boot sector TetrOS:

sudo dd if=tetros.img of=/dev/sde

Game description

The developer managed to cram not the most boring design into just 512 bytes of memory. Each brick in the game has its own color, control is performed by buttons, in case of defeat the game ends, the bricks are generated randomly... BolgenOS was not even close!

Unfortunately, due to the size, some features had to be abandoned. There is no scoring in the game, restarting the game without reloading and displaying what the next brick will be.

INTRODUCTION Microcontrollers, their occurrence and application
History of microcontrollers
Electronics in the Greek style
Why AVR?
What's next?

PART I. GENERAL PRINCIPLES OF DESIGN AND FUNCTIONING OF ATMEL AVR

Chapter 1 Overview of Atmel AVR Microcontrollers

AVR families
Features of the practical use of MK AVR

Chapter 2. General arrangement, memory organization, clocking, reset

Program memory
Data memory (RAM, SRAM)
Non-volatile data memory (EEPROM)
Clocking methods
Reset
Features of connecting additional external data memory

Chapter 3. Introduction to Peripherals

I/O ports
Timers-Counters
Analog to digital converter
Serial ports
UART
SPI interface
TWI interface (12C)
Universal serial interface USI

Chapter 4 Interrupts and Power Save Modes

Interrupts
Types of interrupts
Power saving modes
Consumption MK AVR
MK AYR consumption and power saving modes

PART II. PROGRAMMING ATMEL AVR MICROCONTROLLERS

Chapter 5. General principles of programming MK family AVR

Assembler or C?
Ways and means of programming AVR
Code editor
About AVR Studio
Arrangement of the assembler
programmers
About hex files
Commands, Instructions, and AVR Assembly Notation
Numbers and Expressions
Directives and Functions
General Structure of an AVR Program
Interrupt handling
RESET
The simplest program
Delay
Counter program
Using interrupts
Timer delay
Interrupt Counter Program
About configuration bits

Chapter 6 AVR Command System

Control Transfer Commands and the SREG Register
Check-pass commands
Logic Commands
Shift Instructions and Bit Operations
Commands for Arithmetic Operations
Data transfer commands
System Control Commands
Execution of typical procedures in assembler
About the stack, local and global variables

Chapter 7 Arithmetic Operations

Standard arithmetic operations
Multiplication of multidigit numbers
Multi-digit division
Operations with fractional numbers
Random number generator
Operations with numbers in BCD format
Negative numbers in MK

Chapter 8 Programming Timers

8 and 16 bit timers
Formation of the frequency setpoint
Countdown
Accurate time correction
Frequency meter and period meter
Frequency meter
Periodometer
Dynamic indication control
LED indicators and their connection
Programming dynamic indication
Timers in PWM mode

Chapter 9 Using EEPROM

Once again about the safety of data in EEPROM
Write and read EEPROM
Storing constants in EEPROM

Chapter 10 Analog Comparator and ADC

Analog-to-digital operations and their errors
Working with an analog comparator
Integrating ADC on a comparator
Principle of operation and calculation formulas
Integrating ADC program
Built-in ADC
ADC example
Program

Chapter 11 SPI Programming

Basic operations via SPI
Hardware option
Software option
About varieties of non-volatile memory
Write and read flash memory via SPI
Memory exchange program 45DB011B via SPI
Writing and reading flash cards
Connecting MMS cards
Issuing commands and initializing MMC
Writing and reading MMS

Chapter 12. TWI Interface (12C) and Its Practical Use

Basic protocol 12C
Software emulation of the 12C protocol
Writing data to external non-volatile memory
Exchange modes with AT24 memory
Program
Clock with 12C interface
Data recording
Reading data

Chapter 13 UART/USART Programming

UART initialization
Sending and receiving data
Example of setting the DS1307 clock using UART
Techniques for protection against communication failures
Even parity
How to organize the correct exchange
Additional features USART
Implementation of RS-232 and RS-485 interfaces
Level converters for RS-232
RS-485

Chapter 14 Power Saving Modes and Watchdog Timer

Energy Saving Programming
Example of a battery powered instrument
Refinement of the program
Using the watchdog timer

APPS

Attachment 1. Main parameters of Atmel AVR microcontrollers

Appendix 2 Atmel AVR Commands
Arithmetic and Logic Instructions
Bit operations commands
Comparison Commands
Control Transfer Commands
Unconditional Jump and Subroutine Call Instructions
Skip Check and Conditional Branch Instructions
Data transfer commands
System Control Commands

Appendix 3 Program texts
45DB011B flash-memory communication demo program via SPI interface
Exchange procedures on the 12C interface

Appendix 4 Communication with personal computer and debugging programs via UART
Working with COM port in Delphi
COM port and Windows API
Working with COM through ready-made components
Installing the RTS line in DOS and Windows
COM2000 program
Debugging Programs with a Terminal Program

Appendix 5 Glossary of common abbreviations and terms
Correspondence of terms in Russian with their translation into English
Correspondence of terms in English with their translation into Russian

Literature
Subject index

Somehow I saw an interesting video on the net, it showed a snake game implemented on a microcontroller and an 8x8 LED matrix, then I found a few more similar videos that interested me. Among them was also a video where a Tetris game was assembled on a “powerful” microcontroller. After watching, I decided to develop my own version of the device, in which both games are combined, using the PIC16F688 microcontroller and two LED matrices that display the playing field with a resolution of 8x16 pixels.

The device diagram is shown below. The output of information on the matrix H1, H2 in dynamic mode is carried out by means of shift registers DD2, DD3, DD4. The outputs of the microcircuits DD2, DD3 are connected to the anodes of the matrices. The cathodes of both matrices are connected to the collectors of transistors VT1-VT8, the control signals for which are generated by the DD4 chip. The microcontroller loads data into the DD4 register, when it overflows, information from the 9th output is transferred to the input of the DD3 register, then in the same way the data is transferred to the DD2 register. Resistors R1-R16 limit the current through the matrix LEDs. Resistors R17-R23 set the base current of transistors VT1-VT8. The microcontroller operates at a frequency of 8 MHz from an internal oscillator. The image refresh rate is 100Hz.


After power is applied, the screen saver of the game “Snake” is displayed on the playing field. In the upper part of the field, the number 1 is displayed, in the lower part there is an image of a fragment of the game. When you press the SB5 “Start / Pause” button, you go to the game menu, at the top of which the game level is displayed in the form of numbers from 1 to 9. The game level is set with the SB1 “Up” button, each time you press the level number increases sequentially by unit. After the number 9, the number 1 is displayed again. From established level The game depends on the initial length of the snake, so for the 1st level the length is 3 points, for the 9th 11 points. At the bottom of the menu, information about the speed of the snake is displayed. The number 1 corresponds to the minimum speed, and the number 9 corresponds to the maximum. The speed value is set by the SB4 “Down” button, similar to setting the game level. The glow of the LEDs along the perimeter of the field in the menu means that the game mode with the presence of borders along the perimeter of the field is selected. In this mode, when the snake leaves the playing field, a loss occurs. If in the menu, the LEDs around the perimeter of the field are off, then the mode without borders is selected. In this case, when leaving the playing field, the snake's head appears on the opposite side of the field. Buttons SB2 “Right” and SB3 “Left” set the required game mode. When you first enter the game menu, the value of the length and speed are set to one, the mode with the presence of borders is selected.

After pressing the “Start / Pause” button from the game menu, a snake in the base position and a random free point are displayed on the playing field. Pressing any of the buttons "Up", "Left", "Right" causes the snake to move in the corresponding direction. After the start of the movement, the “Down” button also becomes available to control the snake. When hitting a luminous point, the length of the snake increases. After collecting 14 points, the player moves on to the next level of the game. After the 9th level, there is a transition to the first level. If the snake hits its own body, or goes out of the playing field in the boundary mode, a loss occurs. After 3 losses, you return to the game menu, where the current game level and speed are indicated. After the snake starts moving, by pressing the “Start / Pause” buttons, you can pause and resume the game.

To exit the game menu, hold down the “Start / Pause” button for 1 second, after which the splash screen of the game will appear on the playing field. Switching between games is carried out by pressing any of the buttons “Up”, “Down”, “Left”, “Right”. At the same time, the splash screen of the corresponding game is displayed.

The number 2 is displayed in the upper part of the splash screen of the Tetris game, and the image of a fragment of the game is shown in the lower part. Switching to the game menu is carried out by pressing the “Start/Pause” button. At the top of the menu, the number of points scored by the player is displayed. Points are awarded for each deleted line. The score counter counts up to 99, then resets to zero and the score starts again. At the start of each new game, the counter is also reset. The lower part of the menu displays information about the movement speed of the pieces, which is set using the “Up” and “Down” buttons, respectively. After pressing the “Start / Pause” button from the menu, the game starts, random figures appear in the upper part of the field, which can be moved with the “Left” and “Right” buttons in the appropriate direction. The Up button rotates the shape 90 degrees clockwise each time it is pressed. By holding down the “Down” button, you can speed up the movement of the figure. The “Start/Pause” button allows you to pause and resume the game. The game ends when a new figure cannot fit on the playing field, after which there is a transition to the menu where you can view the number of points scored by the player. The exit from the menu is performed in the same way as in the game “Snake”.

If none of the buttons is pressed within 4 minutes, the device goes into low power mode, the microcontroller turns off the LED matrices, and goes into sleep mode. The device “wakes up” after pressing the “Start” button, and returns to its previous state.

The device uses resistors - size 1206 for surface mounting. Capacitors C2, C3 - ceramic size 1206. LED Matrices H1, H2 - TOM-1088BG-B green glow with a diameter of 3mm LEDs, and a resolution of 8x8 pixels. The buttons are standard clock.

The power source is a stabilized power supply with a voltage of 3.7-5V, you can also use galvanic cells or batteries, for example, 3 1.5V AA or AAA batteries connected in series, for example, I use 3 AA batteries. The device remains operational when the supply voltage drops to 3.3V, while the brightness of the LED matrixes decreases.

Name: Practical programming of Atmel AVR microcontrollers in assembly language 2 edition

Publisher:"BHV-Petersburg"

The year of publishing: 2011

Pages: 354

Language: Russian

Format: DjVu

The size: 12.2 MB

The principles of functioning, architecture features and programming techniques of Atmel AVR microcontrollers are superimposed.

Ready-made recipes for programming the main functions of modern microelectronic equipment are given: from the reaction to pressing a button or building a dynamic indication to complex protocols for recording data in external memory or connection features of the real time clock. Particular attention is paid to the data exchange of microelectronic devices with a personal computer, examples of programs are given. The book takes into account the features of modern AVR models and related chips. recent years release.
The application contains the main parameters of AVR microcontrollers, a list of commands and texts The applications contain the main parameters of AVR microcontrollers, a list of commands and program texts for them, as well as a list of terms and abbreviations used.
For students, engineers and radio amateurs

7. Microcontrollers, their occurrence and application
8. Prehistory of microcontrollers
10. Electronics in the Greek style
12. Why AVR?
14. What's next?
17. PART L GENERAL PRINCIPLES OF DESIGN AND FUNCTIONING OF ATMEL AVR
19. Chapter 1. Overview of Atmel AVR microcontrollers
21. AVR families
23. Features of the practical use of MK AVR
23. Consumption
25. Some features of the use of AVR in circuits
27. Chapter 2 General device, memory organization, clocking, reset
27. Program memory
29. Data memory (RAM, SRAM)
31. Non-volatile data memory (EEPROM)
32. Timing methods
34. Reset
37. Chapter 3. Introduction to Peripherals
38. I/O ports
39. Timers-counters
41. Analog to digital converter
42. Serial ports
43. UART
46. ​​SPI interface
50. TWI interface (I2C)
50. USI universal serial interface
53. Chapter 4. Interrupts and power saving modes
53. Interrupts
57. Varieties of interruptions
58. Power saving modes
61. PART II. PROGRAMMING ATMELAVR MICROCONTROLLERS
63. Chapter 5 General principles programming MK family AVR
63. Assembler or C?
67. Ways and means of programming AVR
67. Code editor
68. About AVR Studio
70. Arrangement of the assembler
71. Programmers
75. About hex files
78. Commands, instructions and notation of AVR assembler
79. Numbers and expressions
80. Directives and Functions
84. General structure of an AVR program
85. Interrupt Handling
89. RESET
90. The simplest program
92. Delay
94. Counter program
96. Using interrupts
97. Delay timer
98. Counter program using interrupts
101. About configuration bits
105. Chapter 6, AVR Command System
105. Control transfer commands and register SREG
111. Check-pass commands
113. Commands of logical operations
114. Shift Instructions and Bit Operations
116. Commands of arithmetic operations
118. Data transfer commands
122. System control commands
123. Execution of typical procedures in assembler
125. About the stack, local and global variables
127. Chapter 7. Arithmetic operations
128. Standard arithmetic operations
129. Multiplication of multidigit numbers
131. Division of multidigit numbers
134. Operations with fractional numbers
136. Random number generator
138. Operations with numbers in BCD format
143. Negative numbers in MK
147. Chapter 8. Programming timers
147. 8 and 16 bit timers
149. Formation of the set frequency value
153. Countdown
158. Accurate time correction
160. Frequency counter and period meter
160. Frequency meter
164. Periodometer
167. Dynamic indication control
168. LED indicators and their connection
171. Programming dynamic indication
174. Timers in PWM mode
179. Chapter 9. Using EEPROM
179. Once again about the safety of data in EEPROM
181. Write and read EEPROM
183. Storing constants in EEPROM
187. Chapter 10. Analog comparator and ADC
187. Analog-to-digital operations and their errors
190. Working with an analog comparator
193. Integrating ADC on a comparator
194. Principle of operation and calculation formulas
198. Integrating ADC program
201. Built-in ADC
204. An example of using ADC
206. Program
215. Chapter 11 SPI Programming
215. Basic operations via SPI
216. Hardware variant
218. Program option
219. About varieties of non-volatile memory
221. Writing and reading flash-memory via SP!
224. Program for exchange with memory 45DB011B via SPI
225. Writing and reading flash cards
225. Connecting MMS cards
228. Issuing commands and initializing MMC
232. Writing and reading MMC
237. Chapter 12. TW1 (I2C) interface and its practical use
237. Basic Protocol 1 2 C
240. Software emulation of the I 2 C protocol
241. Writing data to external non-volatile memory
241. Modes of exchange with AT24 memory
243. Program
247. Clock with I 2 C interface
255. Recording data
259. Reading data
261. Chapter 13. UART/USART Programming
262. UART initialization
263. Sending and receiving data
266. Example of setting the DS1307 clock using UART
271. Techniques for protection against communication failures
271. Parity check
273. How to organize a correct exchange
274. Additional features of USART
276. Implementation of interfaces RS-232 and RS-485
280. Level converters for RS-232
283.RS-485
285. Chapter 14. Power Saving Modes and Watchdog Timer
286. Programming the power saving mode
287. Example of a battery powered instrument
289. Refinement of the program
293. Using the watchdog timer
299. APPENDICES
301. Appendix 1. Main parameters of Atmel AVR microcontrollers
309 Appendix 2 Atmel AVR Commands
310. Arithmetic and logical commands
311. Bit operation commands
312. Comparison Commands
313. Control Transfer Commands
313. Instructions for an unconditional jump and calling subroutines
314. Check-skip commands and conditional jump commands
315. Data transfer commands
316. System control commands
317. Appendix 3. Texts of programs
317. Demonstration program for data exchange with flash-memory 45DB011B via SPI interface
321. Exchange procedures over the I2C interface
329. Appendix 4. Data exchange with a personal computer and debugging programs via UART
329. Working with COM port in Delphi
335. Installing the RTS line in DOS and Windows
337. COM2000 program
339. Debugging programs with a terminal emulator
341. Appendix 5. Glossary of common abbreviations and terms
347. Literature
349. Subject index