Architecture and programming Philips Videopac (Magnavox Odyssey 2)

    “Hardware is just software crystallized early”
    - Alan Kay


    The Magnavox Odyssey 2 (Videopac) computer appeared in 1978 and was positioned as a gaming one, but with the possibility of more serious use (for which it had a built-in membrane keyboard). There were very few serious applications, given the assigned amount of memory, so, in fact, it is more correct to consider Videopac as a game console.

    As for the titles, the Magnavox Odyssey 2 was sold in the US and produced NTSC video (via RF output). Philips Videopac G7000 (aka C52) was sold in Europe, respectively, with PAL video. In addition to this difference (which, of course, affected 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 ascetic.

    CPU and memory


    The processor is an Intel 8048 microcontroller . At one time, it was quite famous, as it was installed (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 everyone - 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 microcontroller 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 as a result is less than 160 bytes, and even then to use it in its entirety is very difficult.

    There are separate instructions for accessing each type of memory (MOVP, MOV, MOVX). The clock frequency of 8048 in Videopac is often indicated as 5.37 MHz, but actually (in the sense of following instructions) it is only 0.358 MHz. In this case, however, most of the instructions are completed in 1-2 cycles. There are nine general purpose registers - A, R0-R7.

    The 8048 also has a timer, two I / O ports, and an interrupt control circuit. Through ports, two joysticks and a keyboard are polled.

    An unpleasant feature of 8048 is the division of memory into pages of 256 bytes (you can not access the memory location located on another page) and banks of 2kb (to access a neighboring bank, you need to switch with SEL RB commands), which must be constantly taken into account.

    There is a domestic analogue of 8048 - 1816BE48.

    Video and sound


    Another important component of the system is the Intel 8245 chip (aka 8244 for NTSC). This is a video-based audio controller with a masked ROM, which was produced specifically for Videopac (i.e., apparently there are no other versions or firmware).


    The video controller is rather strange even by the standards of home computers of the 1980s. For example, it does not, as such, have either graphic or text modes. All entities that it supports (sprites, chars, quads, grids) are sprites with one or another limitation. In this regard, such “ordinary” operations as drawing points in a certain place on the screen or filling the screen with text are impossible. Because of this, you can’t even definitely talk about the screen resolution (very conditionally you can talk about numbers like 228 x 262).

    In fact, this video controller is not universal and is tuned for typical (very simple) games. It can form:

    Sprites- traditional hardware sprites 8x8 pixels. At the same time, there may be 4 sprites on the screen. Their contents, coordinates, color can be changed by writing to the registers of the video controller. Each sprite can be any of eight (bright) colors.

    There is also a rather strange (albeit useful) feature that allows you to shift the sprite by half (!) Pixels, or the odd lines of the sprite by half the pixel relative to even ones.

    Chars are symbols. Letters, numbers and some characters (63 in total), the images of which are stored in the ROM BIOS and cannot be changed. At the same time, a maximum of 12 characters can be displayed on the screen. Like sprites, they are displayed anywhere on the screen (accurate to a pixel) but, unlike them, cannot overlap each other. Each character can be any of 8 (bright) colors.

    The address where the symbol image comes from depends on the Y coordinate to which the symbol is displayed and the symbol code (!). Therefore, to display the characters, you either need to calculate this address using a clever formula (especially if you want to get parts of the characters), or use the BIOS routine.


    Quads - groups of characters combined in 4 pieces.

    Grid - a grid of 9 x 8 segments. Used to display mazes, 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 all grid one of eight (dark) colors is set.

    The grid is in the background (on top of the background, which can be any of 8 colors), symbols are displayed on top of the grid, and sprites in the foreground.

    It is possible to track the fact of a collision of objects with each other (one bit flag for each type of object - without indicating a specific one).

    In addition, the video controller allows, with a number of limitations, to track the position of the beam not only by frame, but also by line. 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. To do this, there is a 24-bit cyclic shift register, which can be clocked with one of two frequencies to choose from and switch to noise generation mode. Thus, the generation of an arbitrary note is virtually impossible, although with some tricks you can get an acceptable approximation.

    The output volume is general, one of 16 levels can be set. BIOS routines allow you to make several sounds that can be heard in most games (squeak, shot, explosion).

    Game cartridges are simple ROM sizes from 2kb (most typically) to 8kb. In addition to cartridges, there are two peripheral devices for Videopac - a speech synthesizer (LPC compression, 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 gives a black screen or the wrong colors on a real Videopac is pretty typical. The 1816BE48 emulator (“SCM - Single Chip Machine by DCA Laboratory”) may also be useful. As 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 verify the code on a real device, Mateos Videopac Multigame Cartridge and Mateos Burner / Dumper (i.e. ROM emulator and programmer for it, with a 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 correct and clear colors.

    When you turn on the computer (if any working cartridge is inserted), the color message “SELECT GAME” appears on the screen (if there is no cartridge, the screen will display garbage at best).
    After pressing the key, a transition occurs to the address 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


    Based on the results of studying Videopac, I wrote (for the competition for Chaos Constructions ) a 256 byte intro ( video , source ).


    Three types of graphic primitives are used in the work (of the four implemented in the i8245 video controller) - grid, sprites and chars. Only quads (representing a kind of chars) are not used.

    Men falling from top to bottom are not sprites, as it may seem, but symbols (chars) of 8x8 size. However, in 8245 chars and sprites are related concepts. The maximum allowable number of simultaneously displayed chars is used - 12 pieces. All of them are taken from a standard character generator (there are symbols of men), which saves at least 24 bytes. This is an important point, since the i8048 architecture and the 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 few “extra” instructions are generated that drive the data from register to register.

    A background of changing orange squares is implemented through a grid. This is a hardware-generated 9x8 grid (in a special “chess” field mode), in which, according to some algorithm, certain segments are switched on. Grid priority is always the smallest, so little men fly over it.

    An unlucky but cheerful cat represents two sprites (8x8 each). At the same time, data for sprites during movement periodically changes to others (only two frames)) to simulate moving paws.

    The collision of chars and sprites is recorded by the video controller, and according to a certain algorithm, the color of the sprites of the cat changes, and a special bit is reset or a special bit is shifted that shifts the even lines of the sprite by half a pixel relative to the odd ones.

    The collision sound uses one of the sounds available through the BIOS routine (which saves a few more bytes).

    Moreover


    In addition to games, there were several more serious applications for Videopac - a program for displaying titles in the form of a running line and a program for teaching programming, which is worth mentioning separately.

    The cartridge is called "Computer Programmer" and allows you to enter the program in machine code (that is, not even in assembler) and run it. A book was attached to the cartridge with a description of the architecture and instructions of 8048.

    Let me remind you that this was a completely commercial product, designed for buyers of a game (!) Game console.

    On the video you can see how it works.

    References



    Here you can see my works under different retro platforms, and here their sources on github.

    ps Thanks tnt23 for remaking the Videopac video output from RF to composite.

    Also popular now: