Architecture and programming Mattel Intellivision
Mattel Intellivision is the world's first 16-bit gaming console. The computer was developed by the American company Mattel in 1979 and was produced until 1984 (more than 3 million units were produced). Intellivision is widely known in the United States, but little known in Europe and completely unknown in Russia.
Unlike its main competitor, the Atari VCS (2600) set-top box with a very simple architecture and an 8-bit 6502 processor, Mattel went the hard way by choosing the General Instrument CP1610 processor (CP1600) . In principle, at that time everyone was impressed by the PDP-11 architecture , so it is not so surprising that the CP1610 resembles it (the functionality of the registers and fewer addressing modes are cut).
As in the case of the TI-99 / 4a computer and the TMS9900 processor , 16-bit in fact did not give the machine a performance advantage over 8-bit computers with 6502 or z80 processors , but in terms of programming, the machine is quite interesting.
Like other game consoles, the programs here are stored on cartridges, which are ROMs from 4 to 24 kb in size. In addition, the computer itself also has a small 6Kb Executive ROM, which stores basic routines and a set of characters and a tiny RAM with a total size of 1.5kb.
Despite the fact that the bus is also 16-bit, this does not give much gain, since RAM (with the exception of 240 words System RAM) is 8-bit.
The 16-bit General Instrument CP-1610 processor (developed around 1975) operates at a frequency of about 1 MHz and has 8 registers, of which only four are general-purpose - R0-R3. The remaining registers have special properties:
After accessing R4, R5 (as storing the address), their contents automatically increase by one. The content of R6 decreases by one when reading from it and increases by one when writing.
Another name for the R6 register is SP (stack pointer). Strictly speaking, there is no hardware stack in this processor, but it can be organized quite easily, because when writing to the memory with an instruction in which the address is stored in R6, this register is automatically increased by one, and when reading the other way, it decreases.
And finally, there is a register R7 - this is a PC (instruction pointer), which can be written to as a regular register.
There are also several flags (Z, S, O, C) that do not have a special register of flags, but are accessible through the GSWD / RSWD commands.
The set of commands for moving data between memory and registers is quite traditional (unlike, say, TMS9900 , registers are not mapped to memory, so memory-memory operations are not supported by a single instruction).
Subprogram calls look typical for processors of that generation:
Parameter passing:
A useful feature of the processor is the ability to perform operations not only on general registers, but also on the rest. This can be seen above with the MOVR R5, PC. There are tons of more or less tricky tricks based on PC operations. For example, DECR PC implements an infinite loop. INCR PC skips the following command.
The following aliases are used to implement the stack:
It is curious that, although the processor has all the features to fully work with 16-bit data, all its instructions fit in 10 bits (6 are reserved for future extensions) and the early cartridge ROMs were also ten-bit, to make it cheaper. Later, all ROMs became 16-bit, so now all this is no longer important.
Nevertheless, in assembler, the concept of “DECLE”, a ten-digit word, still remains. In more or less modern programs, it is functionally equivalent to DW (WORD). An analogue of DD (DWORD) is BIDECLE.
The memory card includes the addresses to which RAM, ROM, video controllers and peripherals are available (STIC, PSG, Intellivoice).
RAM refers to:
ROM refers to:
A video controller called STIC (AY-3-8900) for those times is pretty good. It provides a resolution of 160x96 pixels (20x12 characters in size 8x8 pixels) with 16 colors and 8 simultaneously displayed sprites. There is also hardware horizontal and vertical scrolling (shift by 1-8 points).
Strictly speaking, there is no graphic mode here, but in text mode you can reprogram characters (blocks of 8x8 points, called CARDS), indicating in the BACKTAB table from which addresses in GROM or GRAM they are defined, as well as their colors (background and image). GROM stores 2kb of standard letters, numbers, and pseudographics. Just like, say, in Magnavox Odyssey (Videopac)
, STIC implements interruption in the reverse direction of the beam in the frame. But, unfortunately, it is also not allowed to change the registers of the video controller at this time, which excludes various raster effects that are usual for later systems - such as Commodore 64 or Atari XE / XL.
There are two video modes - FGBG (Foreground Background) and CS (Color Stack). They differ in the interpretation of the bits in BACKTAB - how many and which bits there are responsible for the address in GRAM / GROM, how many and which are for colors.
In FGBG mode, colors are stored directly in BACKTAB and there can be 8 for the image (bits 0,1,2) and 16 for the background (bits 9,10,13,12). In this case, the block numbers to which you can refer are limited to 0-63 for GRAM and GROM (bits 3-8).
In CS mode, there can be 16 colors for the image and background, but they are set cleverly - in BACKTAB bits 0, 1, 2 and 12 directly determine the color of the image (similar to FGBG, only two times less colors), but for the background everything is trickier - colors are taken from the STIC registers cs0..cs3 ($ 28- $ 2B). If bit 13 for all blocks is reset, then the background color for the entire screen is taken from cs0. If a block is found for which this bit is set, then the background color of this and subsequent blocks is taken from cs1. If there is still such a block where it is installed, then from cs2, and then from cs3 - cyclically. Thus, you can select any color from the "palette" with just one bit. Available block numbers in this mode: 0-63 for GRAM and 0-255 for GROM
Apparently, this mode is designed for most games where the screen is divided into color bars (sky, water, earth, etc.).
In addition, separately in all modes, you can set the frame color and narrow the frame to the left and / or top (necessary when using scrolling registers).
Sprites (called MOBs) can be 8x8 and 8x16 in size. For each in the STIC registers, you can specify the color, priority relative to the background image and the number (not the address!) Of the block in GRAM from which the contents will be taken, by analogy with BACKTAB. In addition, any sprite can be stretched 2, 4 or 8 times in hardware and mirrored horizontally or vertically.
Interestingly, the vertical vertical resolution of the sprite is twice as high as the resolution of the image (the points from which, for example, the symbols are made up of). Those. an 8x8 sprite actually consists of 8 pixels horizontally and 8 half pixels vertically.
8x16 sprites display two 8x8 blocks in sequence.
Writing to the STIC and GRAM registers is possible only during the VBLANK beam retrace (more precisely, there are two periods there - VBLANK1 and VBLANK2, but we will not go deep).
There is a standard approach to changing the image on the screen. It consists in setting the STIC interrupt vector to a handler that starts to be called at the beginning of VBLANK every 1/60 of a second. The handler writes to the STIC registers (the screen turns on, the frame colors are set, the coordinates of the sprites, etc.) and the record is made in GRAM (image rendering).
In order to have time to do all these operations, the so-called shadowing is used - first everything that needs to be written to GRAM is prepared in a buffer in RAM, and in the processor, it is copied from RAM to GRAM.
As for the sound, it’s enough to name the chip - AY-3-8914 (by the way, the development of the same company as the processor and video controller - General Instrument). This is, in fact, the same chip as in the well-known ZX Spectrum, with the same capabilities - three channels, a noise generator, limited envelope formation capabilities. The chip is addressed at addresses $ 01F0 - $ 01FF.
In addition, a fairly popular peripheral device is the IntelliVoice speech synthesizer built, like similar modules for other computers of those times (Magnavox Odyssey, TI-99 / 4a), based on the General Instrument SP0256 chip. You can play with LPC coefficients using the Voice Tinkerer program.
There were a number of peripherals for Mattel Intellivision. As in the case with other game consoles, Mattel tried to give her typewriter the properties of a home computer - a keyboard module was released. He had his own 6502 processor, 16k RAM, ROM with BASIC, a built-in tape recorder and, as a result, was comparable in power and cost to the console itself. The release of the module was promised but was delayed for a very long time (it came to the lawsuits of buyers against the company) and, as a result, only 4 thousand pieces were released.
Competition with Atari VCS (2600)led to the creation of a weird device called System Changer. In fact, it was a copy of Atari VCS, but developed and released by Mattel, inserted into the Intellivision slot and allowing, respectively, to run games for Atari VCS.
In 1982, the IntelliVoice speech synthesizer, already mentioned above, appeared.
An interesting peripheral was PlayCable. Mattel periodically aired games on television. Owners of PlayCable could download them from TV broadcast to the internal memory of the module and then play. Periodically, the set of broadcast games has changed.
It is also worth mentioning about standard control panels with a disk and buttons. These are the most common joysticks in two directions, for closing / opening, designed in the form of disks (you need to click on the edges). A large number of additional buttons, however, are quite unusual for game consoles.
In the years when Intellivision was sold, developing games for it was not an easy task. Technically, for this, PDP-11 was used with a ROM emulator and corresponding software.
Nowadays, of course, everything is much simpler. At least for Win32, there is a good emulator with a debugger - there is an SDK that includes an assembler with code examples and libraries that implement the most common graphics and sound functions.
Of the emulators, jzintv, which includes a debugger, currently works best.
Assembling and starting is done like this:
In addition, the so-called IntyBasic is popular . This is a cross-compiler of the Basic language into assembler source code. In a sense, it can be called a macro assembler that mimics the basic syntax. It is quite good - it turns out to be quite high-quality code, not to mention the mass of examples and documentation.
Sources look something like this:
Translation to assembler is as follows:
To transfer the ROM image to the computer, I personally purchased an LTO Flash cartridge (the images are uploaded via USB, the cartridge is inserted into Intellivision, where a menu with a list appears after switching on).
In order to penetrate the spirit of the platform, I wrote a small (6kb) New Year's intro - Yolka :
For graphics, the Color Stack mode is used here. Fir-trees and month are sprites (for a fir-tree the same sprite is used, stretched 2-4 times).
To simulate snow, the middle part of the screen is periodically filled with one and the same symbol that sequentially increases its code, each of which represents another “frame” of flight of two snowflakes in an 8x8 block. The frames are selected so that they are joined with the same neighboring ones.
Horizontal stripes, a snowdrift, icicles and the inscription "HAPPY NEW YEAR" are all the usual standard characters.
To move up and down, the vertical scrolling register STIC is used with the frame narrowed from above (this is not visible, since it is the same color as the background). Those. everything that is on the screen moves entirely.
Unfortunately, taking pictures from the screen is very color-distorting and interfering. In reality, everything looks much more decent. As for sound, speech (poems from a song about a Christmas tree) is pronounced by the Intellivoice synthesizer module. Moreover, Russian words are composed of English phonemes ( allophones ). The source can be viewed on github
Of course, these are almost exclusively games - more than a hundred have been released, including several homebrew games that were already released in the 2000s. With a demoscene sparse. There are several intros that are worth a look at Arnauld Chevallier Spirit . The same author in 2003-2004 wrote for Intellivision an operating system called IntyOS . Although for obvious reasons (at least due to the lack of a drive) it is problematic to put it into practice, nevertheless, it is a fully-fledged OS with a window graphical interface, proportional fonts, real multitasking and API for application developers.
Arnauld Chevallier himself implemented several simple applications for his OS: a music player, a clock, a system loading indicator, and Hello World.
PS Thanks tnt23 for composite output
As in the case of the TI-99 / 4a computer and the TMS9900 processor , 16-bit in fact did not give the machine a performance advantage over 8-bit computers with 6502 or z80 processors , but in terms of programming, the machine is quite interesting.
Like other game consoles, the programs here are stored on cartridges, which are ROMs from 4 to 24 kb in size. In addition, the computer itself also has a small 6Kb Executive ROM, which stores basic routines and a set of characters and a tiny RAM with a total size of 1.5kb.
Despite the fact that the bus is also 16-bit, this does not give much gain, since RAM (with the exception of 240 words System RAM) is 8-bit.
CPU
The 16-bit General Instrument CP-1610 processor (developed around 1975) operates at a frequency of about 1 MHz and has 8 registers, of which only four are general-purpose - R0-R3. The remaining registers have special properties:
After accessing R4, R5 (as storing the address), their contents automatically increase by one. The content of R6 decreases by one when reading from it and increases by one when writing.
Another name for the R6 register is SP (stack pointer). Strictly speaking, there is no hardware stack in this processor, but it can be organized quite easily, because when writing to the memory with an instruction in which the address is stored in R6, this register is automatically increased by one, and when reading the other way, it decreases.
And finally, there is a register R7 - this is a PC (instruction pointer), which can be written to as a regular register.
There are also several flags (Z, S, O, C) that do not have a special register of flags, but are accessible through the GSWD / RSWD commands.
The set of commands for moving data between memory and registers is quite traditional (unlike, say, TMS9900 , registers are not mapped to memory, so memory-memory operations are not supported by a single instruction).
MVII #$4000, R1 ; помещает значение $4000 в регистр R1
MVI $200, R0 ; помещает значение из памяти по адресу $200 в регистр R0
MVI@ R3, R1 ; помещает значение из памяти по адресу из R3 в R1
MVO@ R1, R3 ; помещает значение из R1 в память по адресу из R3
Subprogram calls look typical for processors of that generation:
JSR R5, SUBR ; переход к подпрограмме по адресу SUBR. При этом в R5 помещается текущее значение PC.
...
; сама подпрограмма
SUBR:
...
MOVR R5,PC ; помещаем сохранённое значение в PC. Поскольку при чтении из регистра R5 его содержимое автоматически увеличивается, в PC оказывается адрес следующей за JSR инструкции - произойдёт возврат из подпрограммы.
Parameter passing:
JSR R5, SUBR
WORD 6 ; первый параметр
WORD 2 ; второй параметр
...
SUBR:
MVI@ R5, R0 ; помещаем значение 6 (находящееся в памяти по адресу хранящемуся в R5) в регистр R0.
MVI@ R5, R1 ; Поскольку R5 при чтении автоматически увеличивается, в R1 здесь окажется значение по следующему адресу, т.е. 2
...
JR R5 ; это алиас для команды MOVR R5,PC. Опять же - поскольку R5 снова увеличился, здесь произойдет переход по адреса следующему за WORD 2. Т.е. произойдёт возврат из подпрограммы.
A useful feature of the processor is the ability to perform operations not only on general registers, but also on the rest. This can be seen above with the MOVR R5, PC. There are tons of more or less tricky tricks based on PC operations. For example, DECR PC implements an infinite loop. INCR PC skips the following command.
The following aliases are used to implement the stack:
PSHR R0 = MVO@ R0, R6
PULR R0 = MVI@ R6, R0
It is curious that, although the processor has all the features to fully work with 16-bit data, all its instructions fit in 10 bits (6 are reserved for future extensions) and the early cartridge ROMs were also ten-bit, to make it cheaper. Later, all ROMs became 16-bit, so now all this is no longer important.
Nevertheless, in assembler, the concept of “DECLE”, a ten-digit word, still remains. In more or less modern programs, it is functionally equivalent to DW (WORD). An analogue of DD (DWORD) is BIDECLE.
Memory
The memory card includes the addresses to which RAM, ROM, video controllers and peripherals are available (STIC, PSG, Intellivoice).
RAM refers to:
- 256b 8-bit ScratchPad RAM at addresses $ 0100 - $ 01EF (used for variables, including BIOS)
- 352b 16-bit System RAM at addresses $ 0200- $ 035F (here is the BACKTAB screen area, the processor stack, etc.
- 512b 8-bit GRAM for custom character images and sprites at $ 3800 - $ 39FF
ROM refers to:
- 2k 8-bit ROM with characters and pseudographics at addresses $ 4000 - $ FFFF (as well as $ 3000 - $ 37FF, $ 2000 - $ 2FFF)
- 4k 10-bit Executive ROM (BIOS) at $ 1000- $ 1fff
- 4 ... 24k 10- or 16-bit cartridge ROMs at addresses $ 0400- $ 0fff
Graphics
A video controller called STIC (AY-3-8900) for those times is pretty good. It provides a resolution of 160x96 pixels (20x12 characters in size 8x8 pixels) with 16 colors and 8 simultaneously displayed sprites. There is also hardware horizontal and vertical scrolling (shift by 1-8 points).
Strictly speaking, there is no graphic mode here, but in text mode you can reprogram characters (blocks of 8x8 points, called CARDS), indicating in the BACKTAB table from which addresses in GROM or GRAM they are defined, as well as their colors (background and image). GROM stores 2kb of standard letters, numbers, and pseudographics. Just like, say, in Magnavox Odyssey (Videopac)
, STIC implements interruption in the reverse direction of the beam in the frame. But, unfortunately, it is also not allowed to change the registers of the video controller at this time, which excludes various raster effects that are usual for later systems - such as Commodore 64 or Atari XE / XL.
There are two video modes - FGBG (Foreground Background) and CS (Color Stack). They differ in the interpretation of the bits in BACKTAB - how many and which bits there are responsible for the address in GRAM / GROM, how many and which are for colors.
In FGBG mode, colors are stored directly in BACKTAB and there can be 8 for the image (bits 0,1,2) and 16 for the background (bits 9,10,13,12). In this case, the block numbers to which you can refer are limited to 0-63 for GRAM and GROM (bits 3-8).
In CS mode, there can be 16 colors for the image and background, but they are set cleverly - in BACKTAB bits 0, 1, 2 and 12 directly determine the color of the image (similar to FGBG, only two times less colors), but for the background everything is trickier - colors are taken from the STIC registers cs0..cs3 ($ 28- $ 2B). If bit 13 for all blocks is reset, then the background color for the entire screen is taken from cs0. If a block is found for which this bit is set, then the background color of this and subsequent blocks is taken from cs1. If there is still such a block where it is installed, then from cs2, and then from cs3 - cyclically. Thus, you can select any color from the "palette" with just one bit. Available block numbers in this mode: 0-63 for GRAM and 0-255 for GROM
Apparently, this mode is designed for most games where the screen is divided into color bars (sky, water, earth, etc.).
In addition, separately in all modes, you can set the frame color and narrow the frame to the left and / or top (necessary when using scrolling registers).
Sprites (called MOBs) can be 8x8 and 8x16 in size. For each in the STIC registers, you can specify the color, priority relative to the background image and the number (not the address!) Of the block in GRAM from which the contents will be taken, by analogy with BACKTAB. In addition, any sprite can be stretched 2, 4 or 8 times in hardware and mirrored horizontally or vertically.
Interestingly, the vertical vertical resolution of the sprite is twice as high as the resolution of the image (the points from which, for example, the symbols are made up of). Those. an 8x8 sprite actually consists of 8 pixels horizontally and 8 half pixels vertically.
8x16 sprites display two 8x8 blocks in sequence.
Writing to the STIC and GRAM registers is possible only during the VBLANK beam retrace (more precisely, there are two periods there - VBLANK1 and VBLANK2, but we will not go deep).
There is a standard approach to changing the image on the screen. It consists in setting the STIC interrupt vector to a handler that starts to be called at the beginning of VBLANK every 1/60 of a second. The handler writes to the STIC registers (the screen turns on, the frame colors are set, the coordinates of the sprites, etc.) and the record is made in GRAM (image rendering).
In order to have time to do all these operations, the so-called shadowing is used - first everything that needs to be written to GRAM is prepared in a buffer in RAM, and in the processor, it is copied from RAM to GRAM.
Sound
As for the sound, it’s enough to name the chip - AY-3-8914 (by the way, the development of the same company as the processor and video controller - General Instrument). This is, in fact, the same chip as in the well-known ZX Spectrum, with the same capabilities - three channels, a noise generator, limited envelope formation capabilities. The chip is addressed at addresses $ 01F0 - $ 01FF.
In addition, a fairly popular peripheral device is the IntelliVoice speech synthesizer built, like similar modules for other computers of those times (Magnavox Odyssey, TI-99 / 4a), based on the General Instrument SP0256 chip. You can play with LPC coefficients using the Voice Tinkerer program.
Periphery
There were a number of peripherals for Mattel Intellivision. As in the case with other game consoles, Mattel tried to give her typewriter the properties of a home computer - a keyboard module was released. He had his own 6502 processor, 16k RAM, ROM with BASIC, a built-in tape recorder and, as a result, was comparable in power and cost to the console itself. The release of the module was promised but was delayed for a very long time (it came to the lawsuits of buyers against the company) and, as a result, only 4 thousand pieces were released.
Competition with Atari VCS (2600)led to the creation of a weird device called System Changer. In fact, it was a copy of Atari VCS, but developed and released by Mattel, inserted into the Intellivision slot and allowing, respectively, to run games for Atari VCS.
In 1982, the IntelliVoice speech synthesizer, already mentioned above, appeared.
An interesting peripheral was PlayCable. Mattel periodically aired games on television. Owners of PlayCable could download them from TV broadcast to the internal memory of the module and then play. Periodically, the set of broadcast games has changed.
It is also worth mentioning about standard control panels with a disk and buttons. These are the most common joysticks in two directions, for closing / opening, designed in the form of disks (you need to click on the edges). A large number of additional buttons, however, are quite unusual for game consoles.
Development and emulation tools
In the years when Intellivision was sold, developing games for it was not an easy task. Technically, for this, PDP-11 was used with a ROM emulator and corresponding software.
Nowadays, of course, everything is much simpler. At least for Win32, there is a good emulator with a debugger - there is an SDK that includes an assembler with code examples and libraries that implement the most common graphics and sound functions.
Of the emulators, jzintv, which includes a debugger, currently works best.
Assembling and starting is done like this:
as1600.exe -i C:\work\inty\sdk\examples\library -o %1.rom %1.asm
jzintv.exe -v1 -p C:\work\inty\sdk\rom %1.rom
In addition, the so-called IntyBasic is popular . This is a cross-compiler of the Basic language into assembler source code. In a sense, it can be called a macro assembler that mimics the basic syntax. It is quite good - it turns out to be quite high-quality code, not to mention the mass of examples and documentation.
Sources look something like this:
SPRITE 1,0
WHILE COL0 AND $0004
#Y = #Y - 256
SPRITE 0,X+8,SPR63
WAIT
WEND
GOSUB update_score
#Y = #Y + 256
PLAY music_victory
FOR c = 0 to 100
WAIT
NEXT c
Translation to assembler is as follows:
IntyBASIC.exe %1.bas %1.asm C:\work\inty\intybasic
To transfer the ROM image to the computer, I personally purchased an LTO Flash cartridge (the images are uploaded via USB, the cartridge is inserted into Intellivision, where a menu with a list appears after switching on).
Intro "Yolka"
In order to penetrate the spirit of the platform, I wrote a small (6kb) New Year's intro - Yolka :
For graphics, the Color Stack mode is used here. Fir-trees and month are sprites (for a fir-tree the same sprite is used, stretched 2-4 times).
To simulate snow, the middle part of the screen is periodically filled with one and the same symbol that sequentially increases its code, each of which represents another “frame” of flight of two snowflakes in an 8x8 block. The frames are selected so that they are joined with the same neighboring ones.
Horizontal stripes, a snowdrift, icicles and the inscription "HAPPY NEW YEAR" are all the usual standard characters.
To move up and down, the vertical scrolling register STIC is used with the frame narrowed from above (this is not visible, since it is the same color as the background). Those. everything that is on the screen moves entirely.
Unfortunately, taking pictures from the screen is very color-distorting and interfering. In reality, everything looks much more decent. As for sound, speech (poems from a song about a Christmas tree) is pronounced by the Intellivoice synthesizer module. Moreover, Russian words are composed of English phonemes ( allophones ). The source can be viewed on github
Software
Of course, these are almost exclusively games - more than a hundred have been released, including several homebrew games that were already released in the 2000s. With a demoscene sparse. There are several intros that are worth a look at Arnauld Chevallier Spirit . The same author in 2003-2004 wrote for Intellivision an operating system called IntyOS . Although for obvious reasons (at least due to the lack of a drive) it is problematic to put it into practice, nevertheless, it is a fully-fledged OS with a window graphical interface, proportional fonts, real multitasking and API for application developers.
Arnauld Chevallier himself implemented several simple applications for his OS: a music player, a clock, a system loading indicator, and Hello World.
PS Thanks tnt23 for composite output