"Hardware is just software crystallized early"
- Alan Kay
Computer
Magnavox Odyssey 2 (Videopac) appeared in 1978 and was positioned as a game, but with the possibility of a more serious use (for which he had a built-in membrane keyboard). Serious applications, given the designative amount of memory, were very few, so, in fact, it is more correct to assume that Videopac is a game console.
As for the titles, Magnavox Odyssey 2 was sold in the USA and provided an NTSC video signal (via RF output). Philips Videopac G7000 (aka C52) was sold in Europe, respectively, with a PAL video. In addition to this difference (which, of course, influenced the performance of some games) computers are exactly the same.
')
Videopac was one of the first game consoles, for which games were released in the form of cartridges with programs. Therefore, it is not surprising that, technically, this device is very austere.
CPU and memory
The processor is an
Intel 8048 microcontroller. At one time he was quite famous, because he was put (in different versions) in all PC XT and AT keyboards.
The 8048 has a fairly simple set of instructions and few addressing modes.
Harvard architecture (as opposed to the more familiar to all - von Neumann).
All memory is divided into three types - software ROM (1kb BIOS on a chip and up to 8kb ROM in cartridges), internal RAM (64 bytes in the micro-controller itself, 32 bytes of which are reserved for registers and stack) and external RAM (128 bytes of static RAM, partially located at the same addresses as the video controller).
The total amount of RAM available to the programmer in the end is less than 160 bytes, and even then use it as a whole is very difficult.
For access to each of the types of memory there are separate instructions (MOVP, MOV, MOVX). The clock frequency of 8048 in Videopac is often indicated as 5.37 MHz, but in fact (in terms of executing instructions) it is only 0.358 MHz. At the same time, however, most instructions are executed in 1-2 clocks. There are nine general-purpose registers - A, R0-R7.
Also on the 8048 chip there is a timer, two I / O ports and an interrupt control circuit. Through the ports are polling two joysticks and a keyboard.
The unpleasant feature of the 8048 is the division of memory into pages of 256 bytes (you cannot access the memory location on another page) and 2kb banks (to access the adjacent bank, you need to switch using SEL RB commands), which has to be constantly taken into account.
There is a domestic analogue 8048 - 1816BE48.
Video and sound
Another important component of the system is the Intel 8245 chip (aka 8244 for NTSC). This is a video audio controller with a masked ROM, which was produced specifically for Videopac (i.e., there are apparently no other versions or firmware).
The video controller is rather strange even by the standards of 1980s home computers. For example, it does not, as such, neither graphic nor text modes. All the entities that it supports (sprites, chars, quads, grids) are sprites with certain restrictions. In this regard, such “ordinary” operations like drawing points in a certain place on the screen or filling the screen with text are impossible. Because of this, it is even impossible to say for certain about the resolution of the screen (it’s very conditional to talk about numbers like 228 x 262).
In fact, this video controller is not universal and is designed for typical (very simple) games. It can form:
Sprites - traditional hardware sprites of 8x8 pixels. At the same time on the screen can be 4 sprites. Their contents, coordinates, color can be changed by writing to the video controller registers. Each sprite can be any of eight (bright) colors.
There is also a rather strange (albeit useful) feature that allows you to move the sprite by half (!) Pixels, or odd lines of the sprite by half pixels relative to even ones.
Chars are symbols. Letters, numbers and some characters (63 in total) whose images are stored in ROM BIOS and cannot be changed. Up to 12 characters can be displayed on the screen at the same time. Like the sprites, they are displayed in any place on the screen (up to a pixel), but, unlike them, they cannot overlap each other. Each character can be any of 8 (bright) colors.
The address from which the image of the character is taken depends on the Y coordinate to which the character is output and the code of the character itself (!). Therefore, to output characters, either you need to calculate this address using a clever formula (especially if you want to get parts of characters), or use the BIOS subroutine.
Quads - groups of characters combined in 4 pieces.
Grid - grid 9 x 8 segments. Used to display labyrinths, floors, stairs, etc. There is a mode that allows you to display solid blocks instead of a grid, for example, to simulate a chessboard. The whole grid is the same color. Those. for the whole grid, one of eight (dark) colors is given.
The Grid is in the background (over the background, which can be any of 8 colors), over the grid the characters are displayed and, in the foreground, sprites.
It is possible to track the fact of collision of objects between themselves (one bit-flag for each type of object - without specifying a specific one).
In addition, the video controller allows, with a number of restrictions, to track the position of the beam, not only by frame, but also by rows. In the simplest case, this is used to draw horizontal stripes (earth and sky, for example) by changing the background color at the right moments.
In addition to video, 8245 also allows you to generate primitive sounds. For this, there is a 24-bit cyclic shift register, which can be clocked in one of two frequencies to choose from and switch to the noise generation mode. Thus, the generation of an arbitrary note is virtually impossible, although with some tricks you can get a reasonable approximation.
Total output volume, one of 16 levels can be set. BIOS routines allow you to make several sounds that can be heard in most games (squeak, shot, blast).
Cartridges with games represent a simple ROM in the size from 2kb (most typically) to 8kb. In addition to cartridges, for Videopac there are two peripheral devices - a speech synthesizer (LPC compression, a ROM with words) and a chess computer module (with its own z80 processor).
Development
The best emulator is o2em, and there is a version with a built-in debugger. Although this is really a very decent emulator, nevertheless the situation when a fairly simple code works in it, but it gives a black screen or not those colors on a real Videopac - quite typical. It can also be useful emulator 1816BE48 ("SCM - Single Chip Machine by DCA Laboratory"). As an assembler, it is best to use AS (ASW).
Build and run look like this:
asw.exe -L -x %1.a48 p2bin.exe %1.p %1.bin -r 1024-3071 o2em.exe %1.bin -euro
To check the code on a real device,
Mateos Videopac Multigame Cartridge and Mateos Burner / Dumper (i.e., ROM emulator and programmer for it, with USB port) were purchased.
It also makes sense to modify Videopac by making a composite or RGB output (there are many
schemes on the Internet). Compared to standard RF, this will give a better image and more regular and pure colors.
When the computer is turned on (if any working cartridge is inserted) a colored “SELECT GAME” appears on the screen (if there is no cartridge, there is rubbish on the screen at best).
After pressing the key, a transition occurs at 0400h - the first address in the cartridge ROM.
A typical program is as follows:
; Hello World for Philips Videopac (Magnavox Odyssey 2), 8048 CPU ; by Frog ( https://github.com/petersobolev ) cpu 8048 org 400h include "g7000.h" ; Videopac ; jmp selectgame ; RESET. VDC, . "SELECT GAME" . 0408h, .. jmp start ( A). jmp irq ; jmp timer ; jmp vsyncirq ; jmp start ; selectgame jmp soundirq ; timer: ret ; start: call gfxoff ; VDC mov r0,#010h ; VDC ( 12) mov r3,#40 ; x mov r4,#100 ; y mov r1,#hellostr & 0ffh ; ( 255 ) mov r2,#11 ; 11 nextchar: mov a,r1 movp a,@a ; A r1 mov r5,a inc r1 ; mov r6,#0eh ; call printchar ; ( r0 r3) djnz r2,nextchar call gfxon ; , VDC loop: jmp loop ; ; 'HELLO WORLD' (ASCII ) hellostr: db 01dh, 012h, 00eh, 00eh, 017h, 00ch, 011h, 017h, 013h, 00eh, 01ah
Application - Intro Rash
According to the results of the Videopac study, I wrote (for the
Chaos Constructions competition) a 256 byte intro (
video ,
source ).
We use three types of graphic primitives (of the four implemented in the video controller i8245) - grid, sprites and chars. Only quads (representing a type of chars) are not used.
Falling down men - not sprites, as it may seem, but the characters (chars) size 8x8. However, in 8245 chars and sprites are related concepts. The maximum number of simultaneously displayed chars is used - 12 pieces. All of them are taken from the standard character generator (there are characters of men), which saves at least 24 bytes. This is an important point, because the i8048 architecture and Videopac cartridge format do not contribute to the compactness of the code at all. In particular, despite the large number of registers (a, r0-r7), in some cases only some (a, r0, r1) can be used, so quite a lot of “redundant” instructions are generated that drive data from the register to the register.
The background of the changing orange squares is implemented through the grid. This is a hardware-generated 9x8 grid (in a special “chess” field mode), in which, according to a certain algorithm, certain segments are included. The priority of the grid is always the smallest, so people fly over it.
Unlucky, but resilient cat consists of two sprites (8x8 each). At the same time, the data for the sprites during the movement periodically change to others (only two frames)) in order to imitate the moving legs.
The collision of chars and sprites is fixed by the video controller, while the color of the sprites of the cat changes according to a certain algorithm, and the special bit is reset or set, shifting the even lines of the sprite by half a pixel relatively odd.
As a collision sound, one of the sounds available through the BIOS routine (which saves a few more bytes) is used.
Besides
In addition to games, there were also several more serious applications for Videopac - a program for captioning in the form of a running line and a program for teaching programming, which needs special mention.
The cartridge is called
“Computer Programmer” and allows you to enter the program in machine codes (that is, not even in assembler) and run it. The cartridge included a
book with a description of the architecture and 8048 instructions.
Let me remind you that it was quite a commercial product, designed for buyers of gaming (!) Consoles.
In the
video you can see how it works.
Links
Here you can see my works for different retro platforms, and
here their sources are on github.
ps Thanks
tnt23 for remaking video output Videopac with RF to composite.